From e240ac8c6d0b249561c87e18d1d6b3b32c75794a Mon Sep 17 00:00:00 2001 From: donho Date: Mon, 4 Feb 2008 22:44:01 +0000 Subject: [PATCH] [NEW_FEATURE] Wrap position restore while switching back document. git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository@123 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 25 ++++++---- PowerEditor/src/Parameters.h | 1 + .../ScitillaComponent/ScintillaEditView.cpp | 49 +++++++++++-------- .../src/ScitillaComponent/ScintillaEditView.h | 7 +++ 4 files changed, 51 insertions(+), 31 deletions(-) diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 48aa5908..fbc45731 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -363,8 +363,10 @@ bool Notepad_plus::loadSession(Session & session) if (session._activeSubIndex < session.nbSubFiles()) _subDocTab.activate(session._activeSubIndex); - if (session._activeView == MAIN_VIEW || session._activeView == SUB_VIEW) + if ((session.nbSubFiles() > 0) && (session._activeView == MAIN_VIEW || session._activeView == SUB_VIEW)) switchEditViewTo(session._activeView); + else + switchEditViewTo(MAIN_VIEW); return allSessionFilesLoaded; } @@ -1170,7 +1172,7 @@ bool Notepad_plus::fileSaveAs() _pEditView->setCurrentDocReadOnly(false); _pDocTab->updateCurrentTabItem(PathFindFileName(pfn)); setTitleWith(pfn); - //setLangStatus(_pEditView->getCurrentDocType()); + setLangStatus(_pEditView->getCurrentDocType()); checkLangsMenu(-1); return true; } @@ -1935,15 +1937,15 @@ BOOL Notepad_plus::notify(SCNotification *notification) _macro.push_back(recordedMacroStep(notification->message, notification->wParam, notification->lParam)); break; -/* - case SCN_STYLENEEDED: - { - - } - break; -*/ case SCN_PAINTED: { + //Wrapping messes up visible lines, restore after SCN_PAINTED as doc. says + + if (_pEditView->needRestoreFromWrap()) + { + _pEditView->restoreFromWrap(); + } + if (_syncInfo.doSync()) doSynScorll(HWND(notification->nmhdr.hwndFrom)); @@ -7329,6 +7331,9 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa case NPPM_MAKECURRENTBUFFERDIRTY : { _pEditView->setCurrentDocState(true); + _pDocTab->updateCurrentTabItem(); + checkDocState(); + synchronise(); return TRUE; } @@ -7546,7 +7551,7 @@ void Notepad_plus::fullScreenToggle() ::ShowWindow(_hSelf, SW_HIDE); ::SetMenu(_hSelf, _mainMenuHandle); ::SetWindowLongPtr( _hSelf, GWL_STYLE, _prevStyles); - ::SetWindowPos(_hSelf, HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOREDRAW); + ::SetWindowPos(_hSelf, HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOREDRAW|SWP_NOZORDER); //Restore the toolbar to its previous state int cmdToSend = 0; diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 7501d67f..8b956f87 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -93,6 +93,7 @@ struct HeaderLineState { struct Position { int _firstVisibleLine; + int _wrapOffset; int _startPos; int _endPos; int _xOffset; diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp index 31e210e0..91e9d960 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.cpp @@ -143,7 +143,6 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa case WM_MOUSEHWHEEL : case WM_MOUSEWHEEL : - //case WM_RBUTTONDOWN : { if (LOWORD(wParam) & MK_RBUTTON) { @@ -158,12 +157,6 @@ LRESULT ScintillaEditView::scintillaNew_Proc(HWND hwnd, UINT Message, WPARAM wPa break; } -/* - { - ::CallWindowProc(_scintillaDefaultProc, hwnd, WM_HSCROLL, ((short)HIWORD(wParam))>0?SB_LINERIGHT:SB_LINELEFT, NULL); - break; - } -*/ case WM_VSCROLL : { if (LOWORD(wParam) == SB_ENDSCROLL) @@ -862,21 +855,16 @@ int ScintillaEditView::findDocIndexByName(const char *fn) const void ScintillaEditView::saveCurrentPos() { + //Save data so, that the current topline becomes visible again after restoring. int displayedLine = static_cast(execute(SCI_GETFIRSTVISIBLELINE)); - - int docLine = execute(SCI_DOCLINEFROMVISIBLE, displayedLine); + int docLine = execute(SCI_DOCLINEFROMVISIBLE, displayedLine); //linenumber of the line displayed in the top + int offset = displayedLine - execute(SCI_VISIBLEFROMDOCLINE, docLine); //use this to calc offset of wrap. If no wrap this should be zero - int nbInvisibleLine = 0; - - //Calculate nb of invisible line - for (int i = 0 ; i < docLine ; i++) - if (execute(SCI_GETLINEVISIBLE, i) == FALSE) - nbInvisibleLine++; - - Buffer & buf = _buffers[_currentIndex]; + Buffer & buf = _buffers[_currentIndex]; // the correct visible line number - buf._pos._firstVisibleLine = docLine - nbInvisibleLine; + buf._pos._firstVisibleLine = docLine;//docLine - nbInvisibleLine; + buf._pos._wrapOffset = offset; buf._pos._startPos = static_cast(execute(SCI_GETSELECTIONSTART)); buf._pos._endPos = static_cast(execute(SCI_GETSELECTIONEND)); buf._pos._xOffset = static_cast(execute(SCI_GETXOFFSET)); @@ -885,11 +873,17 @@ void ScintillaEditView::saveCurrentPos() void ScintillaEditView::restoreCurrentPos(const Position & prevPos) { - int scroll2Top = 0 - (int(execute(SCI_GETLINECOUNT)) + 1); - scroll(0, scroll2Top); + _wrapRestoreNeeded = isWrap(); + execute(SCI_GOTOPOS, 0); //make sure first line visible by setting caret there, will scroll to top of document + Buffer & buf = _buffers[_currentIndex]; - scroll(0, buf._pos._firstVisibleLine); + if (!_wrapRestoreNeeded) + { + int lineToShow = execute(SCI_VISIBLEFROMDOCLINE, buf._pos._firstVisibleLine); + scroll(0, lineToShow); + } + if (buf._pos._selMode == SC_SEL_RECTANGLE) { execute(SCI_SETSELECTIONMODE, buf._pos._selMode); @@ -899,6 +893,19 @@ void ScintillaEditView::restoreCurrentPos(const Position & prevPos) execute(SCI_SETXOFFSET, buf._pos._xOffset); } +void ScintillaEditView::restoreFromWrap() +{ + Buffer & buf = _buffers[_currentIndex]; + + int lineToShow = execute(SCI_VISIBLEFROMDOCLINE, buf._pos._firstVisibleLine); + + //Scroll to the line that corresponds to the stored docline and then some more for the wrapping offset. + //Should work with folding too. + scroll(0, lineToShow + buf._pos._wrapOffset); + _wrapRestoreNeeded = false; +} + + //! \brief this method activates the doc and the corresponding sub tab //! \brief return the index of previeus current doc char * ScintillaEditView::activateDocAt(int index) diff --git a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h index 5e3c5117..65c52052 100644 --- a/PowerEditor/src/ScitillaComponent/ScintillaEditView.h +++ b/PowerEditor/src/ScitillaComponent/ScintillaEditView.h @@ -234,6 +234,11 @@ public: void saveCurrentPos(); void restoreCurrentPos(const Position & prevPos); + bool needRestoreFromWrap() { + return _wrapRestoreNeeded; + } + void restoreFromWrap(); + Buffer & getBufferAt(size_t index) { if (index >= _buffers.size()) @@ -639,6 +644,8 @@ protected: int _maxNbDigit; // For Line Number Marge + bool _wrapRestoreNeeded; + void setStyle(int styleID, COLORREF fgColor, COLORREF bgColor = -1, const char *fontName = NULL, int fontStyle = -1, int fontSize = 0); void setSpecialStyle(int styleID, COLORREF fgColor, COLORREF bgColor = -1, const char *fontName = NULL, int fontStyle = -1, int fontSize = 0); void setCppLexer(LangType type);