From 9206fd252e01004b4bfb31dee8bc422b7ee1af7e Mon Sep 17 00:00:00 2001 From: Don Ho Date: Sat, 10 Mar 2012 02:43:17 +0000 Subject: [PATCH] [ENHANCEMENT] Doc map: Improve wrapping operation. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@877 f5eea248-9336-0410-98b8-ebc06183d4e3 --- .../WinControls/DocumentMap/documentMap.cpp | 51 ++++++++++++++----- .../src/WinControls/DocumentMap/documentMap.h | 7 +++ 2 files changed, 46 insertions(+), 12 deletions(-) diff --git a/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp b/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp index 75c831ca..99a692fb 100644 --- a/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp +++ b/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp @@ -39,14 +39,32 @@ void DocumentMap::reloadMap() _pScintillaEditView->syncFoldStateWith((*_ppEditView)->getCurrentFoldStates()); // Wrapping - initWrapMap(); - wrapMap(); - + 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() { diff --git a/PowerEditor/src/WinControls/DocumentMap/documentMap.h b/PowerEditor/src/WinControls/DocumentMap/documentMap.h index 7532102f..3f4919ee 100644 --- a/PowerEditor/src/WinControls/DocumentMap/documentMap.h +++ b/PowerEditor/src/WinControls/DocumentMap/documentMap.h @@ -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; };