From 20e669ff01c3ba2a9dd55af2824fca52a0477653 Mon Sep 17 00:00:00 2001 From: Don HO Date: Tue, 18 Apr 2017 01:31:41 +0200 Subject: [PATCH] Add document snapshot feature (in progress) --- PowerEditor/src/Notepad_plus.cpp | 1 + PowerEditor/src/Notepad_plus.h | 2 + PowerEditor/src/NppCommands.cpp | 2 + PowerEditor/src/NppIO.cpp | 10 +- PowerEditor/src/NppNotification.cpp | 54 +++++- PowerEditor/src/Parameters.cpp | 16 ++ PowerEditor/src/Parameters.h | 4 + PowerEditor/src/ScitillaComponent/Buffer.cpp | 23 +-- PowerEditor/src/ScitillaComponent/Buffer.h | 6 +- .../src/ScitillaComponent/DocTabView.cpp | 3 +- .../src/ScitillaComponent/DocTabView.h | 4 + .../src/ScitillaComponent/columnEditor.h | 9 +- .../WinControls/DocumentMap/documentMap.cpp | 14 +- .../src/WinControls/DocumentMap/documentMap.h | 3 +- .../DocumentMap/documentSnapshot.cpp | 183 ++++++++++++++++++ .../DocumentMap/documentSnapshot.h | 65 +++++++ .../DocumentMap/documentSnapshot.rc | 37 ++++ .../DocumentMap/documentSnapshot_rc.h | 32 +++ .../WinControls/StaticDialog/StaticDialog.cpp | 8 +- PowerEditor/src/WinControls/TabBar/TabBar.cpp | 17 +- PowerEditor/src/WinControls/TabBar/TabBar.h | 4 +- PowerEditor/visual.net/notepadPlus.vcxproj | 3 + .../visual.net/notepadPlus.vs2015.vcxproj | 4 + 23 files changed, 443 insertions(+), 61 deletions(-) create mode 100644 PowerEditor/src/WinControls/DocumentMap/documentSnapshot.cpp create mode 100644 PowerEditor/src/WinControls/DocumentMap/documentSnapshot.h create mode 100644 PowerEditor/src/WinControls/DocumentMap/documentSnapshot.rc create mode 100644 PowerEditor/src/WinControls/DocumentMap/documentSnapshot_rc.h diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index 629831dc..41e0edfc 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -634,6 +634,7 @@ LRESULT Notepad_plus::init(HWND hwnd) _md5FromFilesDlg.init(_pPublicInterface->getHinst(), hwnd); _md5FromTextDlg.init(_pPublicInterface->getHinst(), hwnd); _runMacroDlg.init(_pPublicInterface->getHinst(), hwnd); + _documentSnapshot.init(_pPublicInterface->getHinst(), hwnd); //--User Define Dialog Section--// int uddStatus = nppGUI._userDefineDlgStatus; diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index 1251c9bd..d857a8a6 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -52,6 +52,7 @@ #include "lesDlgs.h" #include "pluginsAdmin.h" #include "localization.h" +#include "documentSnapshot.h" #include "md5Dlgs.h" #include #include @@ -282,6 +283,7 @@ private: PreferenceDlg _preference; FindCharsInRangeDlg _findCharsInRangeDlg; PluginsAdminDlg _pluginsAdminDlg; + DocumentSnapshot _documentSnapshot; // a handle list of all the Notepad++ dialogs std::vector _hModelessDlgs; diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index cc9042d2..323a7b1a 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -70,6 +70,7 @@ void Notepad_plus::command(int id) case IDM_FILE_NEW: { fileNew(); + /* bool isFirstTime = not _pluginsAdminDlg.isCreated(); _pluginsAdminDlg.setPluginsManager(&_pluginsManager); @@ -2572,6 +2573,7 @@ void Notepad_plus::command(int id) return; } } + if (doAboutDlg) { bool isFirstTime = !_aboutDlg.isCreated(); diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 6233a8d9..e88fcb98 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -1601,7 +1601,7 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode) } buf->setPosition(session._mainViewFiles[i], &_mainEditView); - buf->setMapPosition(session._mainViewFiles[i]._mapPos._firstVisibleDocLine, session._mainViewFiles[i]._mapPos._lastVisibleDocLine, session._mainViewFiles[i]._mapPos._nbLine, session._mainViewFiles[i]._mapPos._higherPos); + buf->setMapPosition(session._mainViewFiles[i]._mapPos); buf->setLangType(typeToSet, pLn); if (session._mainViewFiles[i]._encoding != -1) buf->setEncoding(session._mainViewFiles[i]._encoding); @@ -1705,9 +1705,11 @@ bool Notepad_plus::loadSession(Session & session, bool isSnapshotMode) } buf->setPosition(session._subViewFiles[k], &_subEditView); - buf->setMapPosition(session._subViewFiles[k]._mapPos._firstVisibleDocLine, session._subViewFiles[k]._mapPos._lastVisibleDocLine, session._subViewFiles[k]._mapPos._nbLine, session._subViewFiles[k]._mapPos._higherPos); - if (typeToSet == L_USER) { - if (!lstrcmp(pLn, TEXT("User Defined"))) { + buf->setMapPosition(session._subViewFiles[k]._mapPos); + if (typeToSet == L_USER) + { + if (!lstrcmp(pLn, TEXT("User Defined"))) + { pLn = TEXT(""); //default user defined } } diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index 5f36e0d2..c18b75e1 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -158,7 +158,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) DocTabView *pTabDocView = isFromPrimary ? &_mainDocTab : (isFromSecondary ? &_subDocTab : nullptr); if (pTabDocView) { - BufferID id = pTabDocView->getBufferByIndex(tbHdr->tabOrigin); + BufferID id = pTabDocView->getBufferByIndex(tbHdr->_tabOrigin); Buffer *pBuf = MainFileManager->getBufferByID(id); Buffer *currentBuf = getCurrentBuffer(); @@ -177,12 +177,43 @@ BOOL Notepad_plus::notify(SCNotification *notification) } } */ + + /* + if (true) + { + TBHDR *tbHdr = reinterpret_cast(notification); + DocTabView *pTabDocView = isFromPrimary ? &_mainDocTab : (isFromSecondary ? &_subDocTab : nullptr); + if (pTabDocView) + { + BufferID id = pTabDocView->getBufferByIndex(tbHdr->_tabOrigin); + Buffer *pBuf = MainFileManager->getBufferByID(id); + + Buffer *currentBuf = getCurrentBuffer(); + + RECT rect; + TabCtrl_GetItemRect(pTabDocView->getHSelf(), tbHdr->_tabOrigin, &rect); + POINT p; + p.x = rect.left; + p.y = rect.bottom; + ::ClientToScreen(pTabDocView->getHSelf(), &p); + + if (pBuf != currentBuf) // if hover on other tab + { + _documentSnapshot.doDialog(p, pBuf, *(const_cast(pTabDocView->getScintillaEditView()))); + } + else // if hover on current active tab + { + _documentSnapshot.display(false); + } + } + } + */ break; } case TCN_MOUSELEAVING: { - /* + ///* if (_pDocMap && (!_pDocMap->isClosed()) && _pDocMap->isVisible()) { _pDocMap->reloadMap(); @@ -190,7 +221,13 @@ BOOL Notepad_plus::notify(SCNotification *notification) _pDocMap->setTemporarilyShowing(false); } - */ + //*/ + + + if (true) + { + _documentSnapshot.display(false); + } break; } @@ -287,7 +324,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) case TCN_TABDELETE: { - int index = tabNotification->tabOrigin; + int index = tabNotification->_tabOrigin; BufferID bufferToClose = notifyDocTab->getBufferByIndex(index); Buffer * buf = MainFileManager->getBufferByID(bufferToClose); int iView = isFromPrimary?MAIN_VIEW:SUB_VIEW; @@ -316,6 +353,9 @@ BOOL Notepad_plus::notify(SCNotification *notification) else break; + // save map position before switch to a new document + _documentSnapshot.saveCurrentSnapshot(*_pEditView); + switchEditViewTo(iView); BufferID bufid = _pDocTab->getBufferByIndex(_pDocTab->getCurrentTabIndex()); if (bufid != BUFFER_INVALID) @@ -324,6 +364,12 @@ BOOL Notepad_plus::notify(SCNotification *notification) activateBuffer(bufid, iView); _isFolding = false; } + + if (true) + { + _documentSnapshot.display(false); + } + break; } diff --git a/PowerEditor/src/Parameters.cpp b/PowerEditor/src/Parameters.cpp index 399daa58..853d8645 100644 --- a/PowerEditor/src/Parameters.cpp +++ b/PowerEditor/src/Parameters.cpp @@ -2016,6 +2016,18 @@ bool NppParameters::getSessionFromXmlTree(TiXmlDocument *pSessionDoc, Session *p mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapHigherPos"), &mapPosVal); if (mapPosStr) mapPosition._higherPos = mapPosVal; + mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapWidth"), &mapPosVal); + if (mapPosStr) + mapPosition._width = mapPosVal; + mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapHeight"), &mapPosVal); + if (mapPosStr) + mapPosition._height = mapPosVal; + mapPosStr = (childNode->ToElement())->Attribute(TEXT("mapWrapIndentMode"), &mapPosVal); + if (mapPosStr) + mapPosition._wrapIndentMode = mapPosVal; + const TCHAR *boolStr = (childNode->ToElement())->Attribute(TEXT("mapIsWrap")); + if (boolStr) + mapPosition._isWrap = (lstrcmp(TEXT("yes"), boolStr) == 0); const TCHAR *langName; langName = (childNode->ToElement())->Attribute(TEXT("lang")); @@ -2961,6 +2973,10 @@ void NppParameters::writeSession(const Session & session, const TCHAR *fileName) (fileNameNode->ToElement())->SetAttribute(TEXT("mapLastVisibleDocLine"), viewSessionFiles[i]._mapPos._lastVisibleDocLine); (fileNameNode->ToElement())->SetAttribute(TEXT("mapNbLine"), viewSessionFiles[i]._mapPos._nbLine); (fileNameNode->ToElement())->SetAttribute(TEXT("mapHigherPos"), viewSessionFiles[i]._mapPos._higherPos); + (fileNameNode->ToElement())->SetAttribute(TEXT("mapWidth"), viewSessionFiles[i]._mapPos._width); + (fileNameNode->ToElement())->SetAttribute(TEXT("mapHeight"), viewSessionFiles[i]._mapPos._height); + (fileNameNode->ToElement())->SetAttribute(TEXT("mapWrapIndentMode"), viewSessionFiles[i]._mapPos._wrapIndentMode); + fileNameNode->ToElement()->SetAttribute(TEXT("mapIsWrap"), viewSessionFiles[i]._mapPos._isWrap ? TEXT("yes") : TEXT("no")); for (size_t j = 0, len = viewSessionFiles[i]._marks.size() ; j < len ; ++j) { diff --git a/PowerEditor/src/Parameters.h b/PowerEditor/src/Parameters.h index 8af61a7a..e0d24f2d 100644 --- a/PowerEditor/src/Parameters.h +++ b/PowerEditor/src/Parameters.h @@ -144,6 +144,10 @@ struct MapPosition int32_t _lastVisibleDocLine = -1; int32_t _nbLine = -1; int32_t _higherPos = -1; + int32_t _width = -1; + int32_t _height = -1; + int32_t _wrapIndentMode = -1; + bool _isWrap = false; bool isValid() { return _firstVisibleDocLine != -1; }; }; diff --git a/PowerEditor/src/ScitillaComponent/Buffer.cpp b/PowerEditor/src/ScitillaComponent/Buffer.cpp index 7cd61d33..9433d2d9 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.cpp +++ b/PowerEditor/src/ScitillaComponent/Buffer.cpp @@ -46,14 +46,8 @@ static const int LF = 0x0A; long Buffer::_recentTagCtr = 0; - - - - - namespace // anonymous { - static EolType getEOLFormatForm(const char* const data, size_t length, EolType defvalue = EolType::osdefault) { assert(length == 0 or data != nullptr && "invalid buffer for getEOLFormatForm()"); @@ -74,19 +68,12 @@ namespace // anonymous return defvalue; // fallback unknown } - - } // anonymous namespace - - Buffer::Buffer(FileManager * pManager, BufferID id, Document doc, DocFileStatus type, const TCHAR *fileName) // type must be either DOC_REGULAR or DOC_UNNAMED - : _pManager(pManager) - , _id(id) - , _doc(doc) - , _lang(L_TEXT) + : _pManager(pManager) , _id(id), _doc(doc), _lang(L_TEXT) { NppParameters* pNppParamInst = NppParameters::getInstance(); const NewDocDefaultSettings& ndds = (pNppParamInst->getNppGUI()).getNewDocDefaultSettings(); @@ -468,14 +455,6 @@ void Buffer::setDeferredReload() // triggers a reload on the next Document acces } -void Buffer::setMapPosition(int32_t firstVisibleDocLine, int32_t lastVisibleDocLine, int32_t nbLine, int32_t higherPos) -{ - _mapPosition._firstVisibleDocLine = firstVisibleDocLine; - _mapPosition._lastVisibleDocLine = lastVisibleDocLine; - _mapPosition._nbLine = nbLine; - _mapPosition._higherPos = higherPos; -} - //filemanager FileManager::~FileManager() diff --git a/PowerEditor/src/ScitillaComponent/Buffer.h b/PowerEditor/src/ScitillaComponent/Buffer.h index b5268ade..f2a5ba6c 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.h +++ b/PowerEditor/src/ScitillaComponent/Buffer.h @@ -348,15 +348,13 @@ public: bool isMonitoringOn() const { return _isMonitoringOn; }; void updateTimeStamp(); void reload(); - - void setMapPosition(int32_t firstVisibleDocLine, int32_t lastVisibleDocLine, int32_t nbLine, int32_t higherPos); + void setMapPosition(const MapPosition & mapPosition) { _mapPosition = mapPosition; }; MapPosition getMapPosition() { return _mapPosition; }; private: int indexOfReference(const ScintillaEditView * identifier) const; - void setStatus(DocFileStatus status) - { + void setStatus(DocFileStatus status) { _currentStatus = status; doNotify(BufferChangeStatus); } diff --git a/PowerEditor/src/ScitillaComponent/DocTabView.cpp b/PowerEditor/src/ScitillaComponent/DocTabView.cpp index cdfc186e..47f77ed3 100644 --- a/PowerEditor/src/ScitillaComponent/DocTabView.cpp +++ b/PowerEditor/src/ScitillaComponent/DocTabView.cpp @@ -228,4 +228,5 @@ void DocTabView::reSizeTo(RECT & rc) rc.bottom -= (borderWidth * 2); _pView->reSizeTo(rc); } -} \ No newline at end of file +} + diff --git a/PowerEditor/src/ScitillaComponent/DocTabView.h b/PowerEditor/src/ScitillaComponent/DocTabView.h index 08172762..c73f6f67 100644 --- a/PowerEditor/src/ScitillaComponent/DocTabView.h +++ b/PowerEditor/src/ScitillaComponent/DocTabView.h @@ -80,6 +80,10 @@ public : virtual void reSizeTo(RECT & rc); + const ScintillaEditView* getScintillaEditView() const { + return _pView; + }; + private : ScintillaEditView *_pView; static bool _hideTabBarStatus; diff --git a/PowerEditor/src/ScitillaComponent/columnEditor.h b/PowerEditor/src/ScitillaComponent/columnEditor.h index 694a6c2a..9201443d 100644 --- a/PowerEditor/src/ScitillaComponent/columnEditor.h +++ b/PowerEditor/src/ScitillaComponent/columnEditor.h @@ -25,14 +25,9 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +#pragma once -#ifndef COLUMNEDITOR_H -#define COLUMNEDITOR_H - -#ifndef COLUMNEDITOR_RC_H #include "columnEditor_rc.h" -#endif //COLUMNEDITOR_RC_H - #include "StaticDialog.h" class ScintillaEditView; @@ -74,4 +69,4 @@ private : }; -#endif// COLUMNEDITOR_H + diff --git a/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp b/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp index 04f65869..352808ef 100644 --- a/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp +++ b/PowerEditor/src/WinControls/DocumentMap/documentMap.cpp @@ -257,9 +257,13 @@ void DocumentMap::scrollMap(ScintillaEditView *editView) lowerY = nbLine * lineHeight + higherY; } + char toto[256]; + sprintf(toto, "MAP : %d & %d\n\n", higherY, lowerY); + OutputDebugStringA(toto); + // set current map position in buffer - Buffer *buffer = pEditView->getCurrentBuffer(); - buffer->setMapPosition(static_cast(firstVisibleDocLine), static_cast(lastVisibleDocLine), static_cast(nbLine), static_cast(higherPos)); + //Buffer *buffer = pEditView->getCurrentBuffer(); + //buffer->setMapPosition(static_cast(firstVisibleDocLine), static_cast(lastVisibleDocLine), static_cast(nbLine), static_cast(higherPos)); // Update view zone in map _vzDlg.drawZone(static_cast(higherY), static_cast(lowerY)); @@ -272,6 +276,10 @@ void DocumentMap::scrollMapWith(const MapPosition & mapPos, ScintillaEditView & { // Visible document line for the map view auto firstVisibleDisplayLineMap = _pScintillaEditView->execute(SCI_GETFIRSTVISIBLELINE); + //char toto[256]; + //sprintf(toto, "MAP : highfirstVisibleDisplayLineerY: %d\n", firstVisibleDisplayLine); + //OutputDebugStringA(toto); + auto firstVisibleDocLineMap = _pScintillaEditView->execute(SCI_DOCLINEFROMVISIBLE, firstVisibleDisplayLineMap); auto nbLineMap = _pScintillaEditView->execute(SCI_LINESONSCREEN, firstVisibleDocLineMap); auto lastVisibleDocLineMap = editView.execute(SCI_DOCLINEFROMVISIBLE, firstVisibleDisplayLineMap + nbLineMap); @@ -303,6 +311,8 @@ void DocumentMap::scrollMapWith(const MapPosition & mapPos, ScintillaEditView & auto lineHeight = _pScintillaEditView->execute(SCI_TEXTHEIGHT, mapPos._firstVisibleDocLine); lowerY = mapPos._nbLine * lineHeight + higherY; } + //sprintf(toto, "MAP : %d & %d\n\n", higherY, lowerY); + //OutputDebugStringA(toto); // Update view zone in map _vzDlg.drawZone(static_cast(higherY), static_cast(lowerY)); diff --git a/PowerEditor/src/WinControls/DocumentMap/documentMap.h b/PowerEditor/src/WinControls/DocumentMap/documentMap.h index ec53ea79..046443bd 100644 --- a/PowerEditor/src/WinControls/DocumentMap/documentMap.h +++ b/PowerEditor/src/WinControls/DocumentMap/documentMap.h @@ -57,8 +57,7 @@ public : void doDialog(); - virtual void destroy() { - }; + virtual void destroy() {}; void drawZone(long hY, long lY) { _higherY = hY; diff --git a/PowerEditor/src/WinControls/DocumentMap/documentSnapshot.cpp b/PowerEditor/src/WinControls/DocumentMap/documentSnapshot.cpp new file mode 100644 index 00000000..dbc209b2 --- /dev/null +++ b/PowerEditor/src/WinControls/DocumentMap/documentSnapshot.cpp @@ -0,0 +1,183 @@ +// This file is part of Notepad++ project +// Copyright (C)2003-2017 Don HO +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// Note that the GPL places important restrictions on "derived works", yet +// it does not provide a detailed definition of that term. To avoid +// misunderstandings, we consider an application to constitute a +// "derivative work" for the purpose of this license if it does any of the +// following: +// 1. Integrates source code from Notepad++. +// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable +// installer, such as those produced by InstallShield. +// 3. Links to a library or executes a program that does any of the above. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#include "documentSnapshot.h" +#include "ScintillaEditView.h" + +INT_PTR CALLBACK DocumentSnapshot::run_dlgProc(UINT message, WPARAM /*wParam*/, LPARAM /*lParam*/) +{ + switch (message) + { + case WM_INITDIALOG : + { + HWND hwndScintilla = reinterpret_cast(::SendMessage(_hParent, NPPM_CREATESCINTILLAHANDLE, 0, reinterpret_cast(_hSelf))); + _pScintillaEditView = reinterpret_cast(::SendMessage(_hParent, NPPM_INTERNAL_GETSCINTEDTVIEW, 0, reinterpret_cast(hwndScintilla))); + _pScintillaEditView->execute(SCI_SETZOOM, static_cast(-10), 0); + _pScintillaEditView->execute(SCI_SETVSCROLLBAR, FALSE, 0); + _pScintillaEditView->execute(SCI_SETHSCROLLBAR, FALSE, 0); + + _pScintillaEditView->showIndentGuideLine(false); + + ::MoveWindow(_pScintillaEditView->getHSelf(), 0, 0, _rc.right - _rc.left, _rc.bottom - _rc.top, TRUE); + _pScintillaEditView->display(); + } + break; + } + return FALSE; +} + +void DocumentSnapshot::doDialog(POINT p, Buffer *pBuf, ScintillaEditView & scintSource) +{ + if (!isCreated()) + { + create(IDD_DOCUMENTSNAPSHOT); + } + + syncDisplay(pBuf, scintSource); + // Adjust the position of DocumentSnapshot + goTo(p); +} + +void DocumentSnapshot::goTo(POINT p) +{ + ::SetWindowPos(_hSelf, HWND_TOP, p.x, p.y + 10, _rc.right - _rc.left, _rc.bottom - _rc.top, SWP_SHOWWINDOW); +} + +void DocumentSnapshot::syncDisplay(Buffer *buf, ScintillaEditView & scintSource) +{ + if (_pScintillaEditView) + { + _pScintillaEditView->execute(SCI_SETDOCPOINTER, 0, static_cast(buf->getDocument())); + _pScintillaEditView->setCurrentBuffer(buf); + + // + // folding + // + const std::vector & lineStateVector = buf->getHeaderLineState(&scintSource); + _pScintillaEditView->syncFoldStateWith(lineStateVector); + + // + // Wraping & scrolling + // + MapPosition mp = buf->getMapPosition(); + if (mp.isValid()) + scrollSnapshotWith(mp); + + Buffer *buf = _pScintillaEditView->getCurrentBuffer(); + _pScintillaEditView->defineDocType(buf->getLangType()); + _pScintillaEditView->showMargin(ScintillaEditView::_SC_MARGE_FOLDER, false); + + _pScintillaEditView->showMargin(0, false); + _pScintillaEditView->showMargin(1, false); + _pScintillaEditView->showMargin(2, false); + _pScintillaEditView->showMargin(3, false); + + } + Window::display(); +} + + +void DocumentSnapshot::scrollSnapshotWith(const MapPosition & mapPos) +{ + if (_pScintillaEditView) + { + bool hasBeenChanged = false; + // + // if window size has been changed, resize windows + // + if (mapPos._height != -1 && _rc.bottom != _rc.top + mapPos._height) + { + _rc.bottom = _rc.top + mapPos._height; + hasBeenChanged = true; + } + if (mapPos._width != -1 && _rc.right != _rc.left + mapPos._width) + { + _rc.right = _rc.left + mapPos._width; + hasBeenChanged = true; + } + if (hasBeenChanged) + ::MoveWindow(_pScintillaEditView->getHSelf(), 0, 0, _rc.right - _rc.left, _rc.bottom - _rc.top, TRUE); + // + // Wrapping + // + _pScintillaEditView->wrap(mapPos._isWrap); + _pScintillaEditView->execute(SCI_SETWRAPINDENTMODE, mapPos._wrapIndentMode); + + // + // Reset to zero + // + _pScintillaEditView->execute(SCI_HOMEDISPLAY); + + // + // Visible line for the code view + // + + // Get the first visible display line from the first visible document line + auto firstVisibleDisplayLine = _pScintillaEditView->execute(SCI_VISIBLEFROMDOCLINE, mapPos._firstVisibleDocLine); + + // scroll to the first visible display line + _pScintillaEditView->execute(SCI_LINESCROLL, 0, firstVisibleDisplayLine); + + } +} + +void DocumentSnapshot::saveCurrentSnapshot(ScintillaEditView & editView) +{ + if (_pScintillaEditView) + { + MapPosition mapPos; + + // First visible document line for scrolling to this line + auto firstVisibleDisplayLine = editView.execute(SCI_GETFIRSTVISIBLELINE); + mapPos._firstVisibleDocLine = static_cast(editView.execute(SCI_DOCLINEFROMVISIBLE, firstVisibleDisplayLine)); + mapPos._nbLine = static_cast(editView.execute(SCI_LINESONSCREEN, firstVisibleDisplayLine)); + mapPos._lastVisibleDocLine = static_cast(editView.execute(SCI_DOCLINEFROMVISIBLE, firstVisibleDisplayLine + mapPos._nbLine)); + + int32_t lineHeight = static_cast(_pScintillaEditView->execute(SCI_TEXTHEIGHT, mapPos._firstVisibleDocLine)); + mapPos._height = mapPos._nbLine * lineHeight; + + // Width + RECT editorRect; + editView.getClientRect(editorRect); + int marginWidths = 0; + for (int m = 0; m < 4; ++m) + { + marginWidths += static_cast(editView.execute(SCI_GETMARGINWIDTHN, m)); + } + double editViewWidth = editorRect.right - editorRect.left - marginWidths; + double editViewHeight = editorRect.bottom - editorRect.top; + mapPos._width = static_cast((editViewWidth / editViewHeight) * static_cast(mapPos._height)); + + mapPos._wrapIndentMode = static_cast(editView.execute(SCI_GETWRAPINDENTMODE)); + mapPos._isWrap = static_cast(editView.isWrap()); + + // set current map position in buffer + Buffer *buffer = editView.getCurrentBuffer(); + buffer->setMapPosition(mapPos); + } +} diff --git a/PowerEditor/src/WinControls/DocumentMap/documentSnapshot.h b/PowerEditor/src/WinControls/DocumentMap/documentSnapshot.h new file mode 100644 index 00000000..2e801528 --- /dev/null +++ b/PowerEditor/src/WinControls/DocumentMap/documentSnapshot.h @@ -0,0 +1,65 @@ +// This file is part of Notepad++ project +// Copyright (C)2003-2017 Don HO +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// Note that the GPL places important restrictions on "derived works", yet +// it does not provide a detailed definition of that term. To avoid +// misunderstandings, we consider an application to constitute a +// "derivative work" for the purpose of this license if it does any of the +// following: +// 1. Integrates source code from Notepad++. +// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable +// installer, such as those produced by InstallShield. +// 3. Links to a library or executes a program that does any of the above. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#pragma once + +#include "documentSnapshot_rc.h" +#include "StaticDialog.h" + +class ScintillaEditView; +class Buffer; +struct MapPosition; + + +class DocumentSnapshot : public StaticDialog { +public: + DocumentSnapshot(): StaticDialog() {}; + + void init(HINSTANCE hInst, HWND hPere) { + Window::init(hInst, hPere); + }; + + void doDialog(POINT p, Buffer *buf, ScintillaEditView & scintSource); + + void syncDisplay(Buffer *buf, ScintillaEditView & scintSource); + + + void setParent(HWND parent2set){ + _hParent = parent2set; + }; + + void scrollSnapshotWith(const MapPosition & mapPos); + void saveCurrentSnapshot(ScintillaEditView & editView); + +protected: + virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); + void goTo(POINT p); + +private: + ScintillaEditView *_pScintillaEditView = nullptr; +}; diff --git a/PowerEditor/src/WinControls/DocumentMap/documentSnapshot.rc b/PowerEditor/src/WinControls/DocumentMap/documentSnapshot.rc new file mode 100644 index 00000000..4ab73845 --- /dev/null +++ b/PowerEditor/src/WinControls/DocumentMap/documentSnapshot.rc @@ -0,0 +1,37 @@ +// This file is part of Notepad++ project +// Copyright (C)2003 Don HO +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// Note that the GPL places important restrictions on "derived works", yet +// it does not provide a detailed definition of that term. To avoid +// misunderstandings, we consider an application to constitute a +// "derivative work" for the purpose of this license if it does any of the +// following: +// 1. Integrates source code from Notepad++. +// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable +// installer, such as those produced by InstallShield. +// 3. Links to a library or executes a program that does any of the above. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + +#include +#include "documentSnapshot_rc.h" + + +IDD_DOCUMENTSNAPSHOT DIALOGEX 26, 41, 140, 140 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_BORDER | WS_SYSMENU +FONT 8, "MS Sans Serif", 0, 0, 0x0 +BEGIN +END diff --git a/PowerEditor/src/WinControls/DocumentMap/documentSnapshot_rc.h b/PowerEditor/src/WinControls/DocumentMap/documentSnapshot_rc.h new file mode 100644 index 00000000..68dd55ee --- /dev/null +++ b/PowerEditor/src/WinControls/DocumentMap/documentSnapshot_rc.h @@ -0,0 +1,32 @@ +// This file is part of Notepad++ project +// Copyright (C)2003 Don HO +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// Note that the GPL places important restrictions on "derived works", yet +// it does not provide a detailed definition of that term. To avoid +// misunderstandings, we consider an application to constitute a +// "derivative work" for the purpose of this license if it does any of the +// following: +// 1. Integrates source code from Notepad++. +// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable +// installer, such as those produced by InstallShield. +// 3. Links to a library or executes a program that does any of the above. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +#pragma once + +#define IDD_DOCUMENTSNAPSHOT 3600 + + diff --git a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp index d939e4bf..ec889204 100644 --- a/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp +++ b/PowerEditor/src/WinControls/StaticDialog/StaticDialog.cpp @@ -28,6 +28,7 @@ #include #include #include "StaticDialog.h" +#include "Common.h" StaticDialog::~StaticDialog() { @@ -152,10 +153,9 @@ void StaticDialog::create(int dialogID, bool isRTL, bool msgDestParent) if (!_hSelf) { - DWORD err = ::GetLastError(); - char errMsg[256]; - sprintf(errMsg, "CreateDialogParam() return NULL.\rGetLastError() == %u", err); - ::MessageBoxA(NULL, errMsg, "In StaticDialog::create()", MB_OK); + generic_string errMsg = TEXT("CreateDialogParam() return NULL.\rGetLastError(): "); + errMsg += GetLastErrorAsString(); + ::MessageBox(NULL, errMsg.c_str(), TEXT("In StaticDialog::create()"), MB_OK); return; } diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.cpp b/PowerEditor/src/WinControls/TabBar/TabBar.cpp index 96e46b04..55cf5d2a 100644 --- a/PowerEditor/src/WinControls/TabBar/TabBar.cpp +++ b/PowerEditor/src/WinControls/TabBar/TabBar.cpp @@ -155,10 +155,10 @@ void TabBar::activateAt(int index) const ::SendMessage(_hSelf, TCM_SETCURSEL, index, 0); TBHDR nmhdr; - nmhdr.hdr.hwndFrom = _hSelf; - nmhdr.hdr.code = TCN_SELCHANGE; - nmhdr.hdr.idFrom = reinterpret_cast(this); - nmhdr.tabOrigin = index; + nmhdr._hdr.hwndFrom = _hSelf; + nmhdr._hdr.code = TCN_SELCHANGE; + nmhdr._hdr.idFrom = reinterpret_cast(this); + nmhdr._tabOrigin = index; } @@ -426,10 +426,10 @@ void TabBarPlus::doMultiLine() void TabBarPlus::notify(int notifyCode, int tabIndex) { TBHDR nmhdr; - nmhdr.hdr.hwndFrom = _hSelf; - nmhdr.hdr.code = notifyCode; - nmhdr.hdr.idFrom = reinterpret_cast(this); - nmhdr.tabOrigin = tabIndex; + nmhdr._hdr.hwndFrom = _hSelf; + nmhdr._hdr.code = notifyCode; + nmhdr._hdr.idFrom = reinterpret_cast(this); + nmhdr._tabOrigin = tabIndex; ::SendMessage(_hParent, WM_NOTIFY, 0, reinterpret_cast(&nmhdr)); } @@ -631,7 +631,6 @@ LRESULT TabBarPlus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPara return TRUE; } - //#define NPPM_INTERNAL_ISDRAGGING 40926 case WM_MOUSEMOVE : { if (_mightBeDragging && !_isDragging) diff --git a/PowerEditor/src/WinControls/TabBar/TabBar.h b/PowerEditor/src/WinControls/TabBar/TabBar.h index 2884c785..2ed4b006 100644 --- a/PowerEditor/src/WinControls/TabBar/TabBar.h +++ b/PowerEditor/src/WinControls/TabBar/TabBar.h @@ -59,8 +59,8 @@ const TCHAR TABBAR_INACTIVETEXT[64] = TEXT("Inactive tabs"); struct TBHDR { - NMHDR hdr; - int tabOrigin; + NMHDR _hdr; + int _tabOrigin; }; diff --git a/PowerEditor/visual.net/notepadPlus.vcxproj b/PowerEditor/visual.net/notepadPlus.vcxproj index 1ac60772..12d67c2e 100755 --- a/PowerEditor/visual.net/notepadPlus.vcxproj +++ b/PowerEditor/visual.net/notepadPlus.vcxproj @@ -285,6 +285,7 @@ copy ..\src\contextMenu.xml ..\bin64\contextMenu.xml + @@ -494,6 +495,7 @@ copy ..\src\contextMenu.xml ..\bin64\contextMenu.xml + @@ -556,6 +558,7 @@ copy ..\src\contextMenu.xml ..\bin64\contextMenu.xml + diff --git a/PowerEditor/visual.net/notepadPlus.vs2015.vcxproj b/PowerEditor/visual.net/notepadPlus.vs2015.vcxproj index b597a81f..ced027c5 100644 --- a/PowerEditor/visual.net/notepadPlus.vs2015.vcxproj +++ b/PowerEditor/visual.net/notepadPlus.vs2015.vcxproj @@ -274,6 +274,7 @@ copy ..\src\contextMenu.xml ..\bin64\contextMenu.xml + @@ -504,6 +505,7 @@ copy ..\src\contextMenu.xml ..\bin64\contextMenu.xml + @@ -539,6 +541,8 @@ copy ..\src\contextMenu.xml ..\bin64\contextMenu.xml + +