From dd2f32bb698726c68e09ac75a797c1215cdd3800 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Mon, 20 Feb 2012 01:23:07 +0000 Subject: [PATCH] [FIXED_BUG] doc map: Fix moving problem. doc map: Fix folding/unfolding problem. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@866 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/NppBigSwitch.cpp | 5 ++ PowerEditor/src/NppNotification.cpp | 25 +++++++--- .../ScitillaComponent/ScintillaEditView.cpp | 48 +++++++++++++------ .../src/ScitillaComponent/ScintillaEditView.h | 4 ++ .../WinControls/DocumentMap/documentMap.cpp | 15 ++++++ .../src/WinControls/DocumentMap/documentMap.h | 4 ++ scintilla/include/Scintilla.h | 2 + 7 files changed, 83 insertions(+), 20 deletions(-) diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 47d8293d1..9404c7bc0 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -21,6 +21,7 @@ #include "ImageListSet.h" #include "ShortcutMapper.h" #include "VerticalFileSwitcher.h" +#include "documentMap.h" struct SortTaskListPred { @@ -430,6 +431,10 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa case WM_MOVING: { + if (_pDocMap) + { + _pDocMap->doMove(); + } result = FALSE; } break; diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index 63f671ea3..ca5d64ede 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -45,7 +45,8 @@ BOOL Notepad_plus::notify(SCNotification *notification) if (notification->modificationType & SC_MOD_CHANGEFOLD) { - if (prevWasEdit) { + if (prevWasEdit) + { notifyView->foldChanged(notification->line, notification->foldLevelNow, notification->foldLevelPrev); prevWasEdit = false; @@ -355,24 +356,36 @@ BOOL Notepad_plus::notify(SCNotification *notification) { if (notification->nmhdr.hwndFrom == _mainEditView.getHSelf()) switchEditViewTo(MAIN_VIEW); - else if (notification->nmhdr.hwndFrom == _subEditView.getHSelf()) switchEditViewTo(SUB_VIEW); + + int lineClick = int(_pEditView->execute(SCI_LINEFROMPOSITION, notification->position)); - if (notification->margin == ScintillaEditView::_SC_MARGE_FOLDER) + if (notification->margin == ScintillaEditView::_SC_MARGE_FOLDER) { _pEditView->marginClick(notification->position, notification->modifiers); + if (_pDocMap) + _pDocMap->fold(lineClick, _pEditView->isFolded(lineClick)); } else if ((notification->margin == ScintillaEditView::_SC_MARGE_SYBOLE) && !notification->modifiers) { - - int lineClick = int(_pEditView->execute(SCI_LINEFROMPOSITION, notification->position)); if (!_pEditView->markerMarginClick(lineClick)) bookmarkToggle(lineClick); - } break; } + + case SCN_FOLDINGSTATECHANGED : + { + if ((notification->nmhdr.hwndFrom == _mainEditView.getHSelf()) + || (notification->nmhdr.hwndFrom == _subEditView.getHSelf())) + { + int lineClicked = notification->line; + if (_pDocMap) + _pDocMap->fold(lineClicked, _pEditView->isFolded(lineClicked)); + } + return TRUE; + } case SCN_CHARADDED: { diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 2fcdc070c..39aaec621 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -1484,10 +1484,12 @@ void ScintillaEditView::activateBuffer(BufferID buffer) for (int i = 0 ; i < nbLineState ; i++) { HeaderLineState & hls = lineStateVectorNew.at(i); - bool expanded = (execute(SCI_GETFOLDEXPANDED, hls._headerLineNumber) != 0); + bool expanded = isFolded(hls._headerLineNumber); // set line to state folded if (hls._isExpanded != expanded) - execute(SCI_TOGGLEFOLD, hls._headerLineNumber); + { + fold(hls._headerLineNumber, !expanded); + } } restoreCurrentPos(); @@ -1573,8 +1575,10 @@ void ScintillaEditView::collapse(int level2Collapse, bool mode) { level -= SC_FOLDLEVELBASE; if (level2Collapse == (level & SC_FOLDLEVELNUMBERMASK)) - if ((execute(SCI_GETFOLDEXPANDED, line) != 0) != mode) - execute(SCI_TOGGLEFOLD, line); + if (isFolded(line) != mode) + { + fold(line, mode); + } } } @@ -1582,6 +1586,12 @@ void ScintillaEditView::collapse(int level2Collapse, bool mode) } void ScintillaEditView::foldCurrentPos(bool mode) +{ + int currentLine = this->getCurrentLineNumber(); + fold(currentLine, mode); +} + +void ScintillaEditView::fold(int line, bool mode) { // The following code is needed : execute(SCI_COLOURISE, 0, -1); @@ -1591,22 +1601,31 @@ void ScintillaEditView::foldCurrentPos(bool mode) // If the "fold" property is set to "1" and your lexer or container supports folding, fold levels are also set. // This message causes a redraw. - int currentLine = this->getCurrentLineNumber(); - int headerLine; - int level = execute(SCI_GETFOLDLEVEL, currentLine); + int level = execute(SCI_GETFOLDLEVEL, line); if (level & SC_FOLDLEVELHEADERFLAG) - headerLine = currentLine; + headerLine = line; else { - headerLine = execute(SCI_GETFOLDPARENT, currentLine); + headerLine = execute(SCI_GETFOLDPARENT, line); if (headerLine == -1) return; } - if ((execute(SCI_GETFOLDEXPANDED, headerLine) != 0) != mode) - execute(SCI_TOGGLEFOLD, headerLine); + if (isFolded(headerLine) != mode) + { + execute(SCI_TOGGLEFOLD, headerLine); + + SCNotification scnN; + scnN.nmhdr.code = SCN_FOLDINGSTATECHANGED; + scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.idFrom = 0; + scnN.line = headerLine; + scnN.foldLevelNow = isFolded(headerLine)?1:0; //folded:1, unfolded:0 + + ::SendMessage(_hParent, WM_NOTIFY, 0, (LPARAM)&scnN); + } } void ScintillaEditView::foldAll(bool mode) @@ -1625,8 +1644,8 @@ void ScintillaEditView::foldAll(bool mode) { int level = execute(SCI_GETFOLDLEVEL, line); if (level & SC_FOLDLEVELHEADERFLAG) - if ((execute(SCI_GETFOLDEXPANDED, line) != 0) != mode) - execute(SCI_TOGGLEFOLD, line); + if (isFolded(line) != mode) + fold(line, mode); } } @@ -1942,7 +1961,8 @@ void ScintillaEditView::marginClick(int position, int modifiers) else { // Toggle this line - execute(SCI_TOGGLEFOLD, lineClick, 0); + bool mode = isFolded(lineClick); + fold(lineClick, !mode); runMarkers(true, lineClick, true, false); } } diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index ec58d6bd7..74a4fbdfc 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -531,6 +531,10 @@ public: void collapse(int level2Collapse, bool mode); void foldAll(bool mode); + void fold(int line, bool mode); + bool isFolded(int line){ + return (execute(SCI_GETFOLDEXPANDED, line) != 0); + }; void foldCurrentPos(bool mode); int getCodepage() const {return _codepage;}; diff --git a/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp b/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp index 72f2a8bc9..56ba20623 100644 --- a/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp +++ b/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp @@ -67,6 +67,21 @@ void DocumentMap::scrollMap() } } +void DocumentMap::doMove() +{ + RECT rc; + POINT pt = {0,0}; + ::ClientToScreen(_pScintillaEditView->getHSelf(), &pt); + _pScintillaEditView->getClientRect(rc); + ::MoveWindow(_vzDlg.getHSelf(), pt.x, pt.y, (rc.right - rc.left) -4, (rc.bottom - rc.top) - 4, TRUE); +} + +void DocumentMap::fold(int line, bool foldOrNot) +{ + //bool isExpanded = _pScintillaEditView->execute(SCI_GETFOLDEXPANDED, line) != 0; + _pScintillaEditView->fold(line, foldOrNot); +} + void DocumentMap::scrollMap(bool direction, moveMode whichMode) { // Visible line for the code view diff --git a/PowerEditor/src/WinControls/DocumentMap/documentMap.h b/PowerEditor/src/WinControls/DocumentMap/documentMap.h index 1d878f1a7..73a7b1b95 100644 --- a/PowerEditor/src/WinControls/DocumentMap/documentMap.h +++ b/PowerEditor/src/WinControls/DocumentMap/documentMap.h @@ -98,9 +98,13 @@ public: _hParent = parent2set; }; + //void wrapScintilla(bool doWrap); + void reloadMap(); void scrollMap(); void scrollMap(bool direction, moveMode whichMode); + void doMove(); + void fold(int line, bool foldOrNot); protected: virtual BOOL CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); diff --git a/scintilla/include/Scintilla.h b/scintilla/include/Scintilla.h index 5797940ab..334006ec4 100644 --- a/scintilla/include/Scintilla.h +++ b/scintilla/include/Scintilla.h @@ -919,6 +919,8 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam, #define SCN_AUTOCCHARDELETED 2026 #define SCN_HOTSPOTRELEASECLICK 2027 #define SCN_SCROLLED 2080 +#define SCN_FOLDINGSTATECHANGED 2081 + /* --Autogenerated -- end of section automatically generated from Scintilla.iface */ /* These structures are defined to be exactly the same shape as the Win32