[ENHANCEMENT] Doc map: Improve wrapping operation.

git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@877 f5eea248-9336-0410-98b8-ebc06183d4e3
This commit is contained in:
Don Ho 2012-03-10 02:43:17 +00:00
parent 44a37232db
commit 9206fd252e
2 changed files with 46 additions and 12 deletions

View File

@ -39,14 +39,32 @@ void DocumentMap::reloadMap()
_pScintillaEditView->syncFoldStateWith((*_ppEditView)->getCurrentFoldStates());
// Wrapping
if ((*_ppEditView)->isWrap() && needToRecomputeWith())
{
initWrapMap();
wrapMap();
}
scrollMap();
}
}
bool DocumentMap::needToRecomputeWith()
{
int currentZoom = (*_ppEditView)->execute(SCI_GETZOOM);
if (_displayZoom != currentZoom)
return true;
int currentTextZoneWidth = getEditorTextZoneWidth();
if (_displayWidth != currentTextZoneWidth)
return true;
/*
if (_displayHeight != )
return true;
*/
return false;
}
void DocumentMap::initWrapMap()
{
if (_pScintillaEditView && _ppEditView)
@ -133,15 +151,7 @@ void DocumentMap::wrapMap()
int Xlength2 = xEnd2 - xBegin2;
// get current scintilla width W1
RECT editorRect;
(*_ppEditView)->getClientRect(editorRect);
int marginWidths = 0;
for (int m = 0; m < 4; m++)
{
marginWidths += (*_ppEditView)->execute(SCI_GETMARGINWIDTHN, m);
}
int w1 = editorRect.right - editorRect.left - marginWidths;
int w1 = getEditorTextZoneWidth();
// resize map width W2 according W1, Xlength1 and Xlength2
int w2 = (w1 * Xlength2)/Xlength1;
@ -151,9 +161,26 @@ void DocumentMap::wrapMap()
// sync wrapping indent mode
_pScintillaEditView->execute(SCI_SETWRAPINDENTMODE, (*_ppEditView)->execute(SCI_GETWRAPINDENTMODE));
// update the wrap needed data
_displayWidth = w1;
_displayZoom = (*_ppEditView)->execute(SCI_GETZOOM);
}
}
int DocumentMap::getEditorTextZoneWidth()
{
RECT editorRect;
(*_ppEditView)->getClientRect(editorRect);
int marginWidths = 0;
for (int m = 0; m < 4; m++)
{
marginWidths += (*_ppEditView)->execute(SCI_GETMARGINWIDTHN, m);
}
return editorRect.right - editorRect.left - marginWidths;
}
void DocumentMap::scrollMap()
{

View File

@ -123,6 +123,8 @@ public:
protected:
virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
bool needToRecomputeWith();
int getEditorTextZoneWidth();
private:
ScintillaEditView **_ppEditView;
@ -131,6 +133,11 @@ private:
ViewZoneDlg _vzDlg;
bool _isMainEditorWrap;
bool _wrapUnwrapTriggered;
// for needToRecomputeWith function
int _displayZoom;
int _displayWidth;
//int _displayHeight;
};