From d7133d001111934179bedb65ffb9aaf823699e50 Mon Sep 17 00:00:00 2001 From: Don Ho Date: Fri, 26 Mar 2010 00:22:14 +0000 Subject: [PATCH] [UPDATE] (Author: Sin Thesis) Refactoring (in progress). git-svn-id: svn://svn.tuxfamily.org/svnroot/notepadplus/repository/trunk@628 f5eea248-9336-0410-98b8-ebc06183d4e3 --- PowerEditor/src/Notepad_plus.cpp | 789 ++++++++++++------ PowerEditor/src/Notepad_plus.h | 43 +- PowerEditor/src/Notepad_plus_Window.cpp | 215 +++++ PowerEditor/src/Notepad_plus_Window.h | 67 ++ PowerEditor/src/NppBigSwitch.cpp | 617 ++------------ PowerEditor/src/NppCommands.cpp | 78 +- PowerEditor/src/NppIO.cpp | 46 +- PowerEditor/src/NppNotification.cpp | 24 +- PowerEditor/src/ScitillaComponent/Buffer.h | 2 +- .../src/WinControls/shortcut/shortcut.cpp | 4 +- PowerEditor/src/winmain.cpp | 30 +- PowerEditor/visual.net/notepadPlus.vcproj | 8 + 12 files changed, 1014 insertions(+), 909 deletions(-) create mode 100644 PowerEditor/src/Notepad_plus_Window.cpp create mode 100644 PowerEditor/src/Notepad_plus_Window.h diff --git a/PowerEditor/src/Notepad_plus.cpp b/PowerEditor/src/Notepad_plus.cpp index b6563cc8..3625582e 100644 --- a/PowerEditor/src/Notepad_plus.cpp +++ b/PowerEditor/src/Notepad_plus.cpp @@ -17,6 +17,7 @@ #include "precompiledHeaders.h" #include "Notepad_plus.h" +#include "Notepad_plus_Window.h" #include "FileDialog.h" #include "printer.h" #include "FileNameStringSplitter.h" @@ -30,17 +31,77 @@ #include "xmlMatchedTagsHighlighter.h" #include "EncodingMapper.h" -const TCHAR Notepad_plus::_className[32] = TEXT("Notepad++"); -HWND Notepad_plus::gNppHWND = NULL; enum tb_stat {tb_saved, tb_unsaved, tb_ro}; - #define DIR_LEFT true #define DIR_RIGHT false +int docTabIconIDs[] = {IDI_SAVED_ICON, IDI_UNSAVED_ICON, IDI_READONLY_ICON}; +ToolBarButtonUnit toolBarIcons[] = { + {IDM_FILE_NEW, IDI_NEW_OFF_ICON, IDI_NEW_ON_ICON, IDI_NEW_OFF_ICON, IDR_FILENEW}, + {IDM_FILE_OPEN, IDI_OPEN_OFF_ICON, IDI_OPEN_ON_ICON, IDI_NEW_OFF_ICON, IDR_FILEOPEN}, + {IDM_FILE_SAVE, IDI_SAVE_OFF_ICON, IDI_SAVE_ON_ICON, IDI_SAVE_DISABLE_ICON, IDR_FILESAVE}, + {IDM_FILE_SAVEALL, IDI_SAVEALL_OFF_ICON, IDI_SAVEALL_ON_ICON, IDI_SAVEALL_DISABLE_ICON, IDR_SAVEALL}, + {IDM_FILE_CLOSE, IDI_CLOSE_OFF_ICON, IDI_CLOSE_ON_ICON, IDI_CLOSE_OFF_ICON, IDR_CLOSEFILE}, + {IDM_FILE_CLOSEALL, IDI_CLOSEALL_OFF_ICON, IDI_CLOSEALL_ON_ICON, IDI_CLOSEALL_OFF_ICON, IDR_CLOSEALL}, + {IDM_FILE_PRINTNOW, IDI_PRINT_OFF_ICON, IDI_PRINT_ON_ICON, IDI_PRINT_OFF_ICON, IDR_PRINT}, + + //-------------------------------------------------------------------------------------// + {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, + //-------------------------------------------------------------------------------------// + + {IDM_EDIT_CUT, IDI_CUT_OFF_ICON, IDI_CUT_ON_ICON, IDI_CUT_DISABLE_ICON, IDR_CUT}, + {IDM_EDIT_COPY, IDI_COPY_OFF_ICON, IDI_COPY_ON_ICON, IDI_COPY_DISABLE_ICON, IDR_COPY}, + {IDM_EDIT_PASTE, IDI_PASTE_OFF_ICON, IDI_PASTE_ON_ICON, IDI_PASTE_DISABLE_ICON, IDR_PASTE}, + + //-------------------------------------------------------------------------------------// + {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, + //-------------------------------------------------------------------------------------// + + {IDM_EDIT_UNDO, IDI_UNDO_OFF_ICON, IDI_UNDO_ON_ICON, IDI_UNDO_DISABLE_ICON, IDR_UNDO}, + {IDM_EDIT_REDO, IDI_REDO_OFF_ICON, IDI_REDO_ON_ICON, IDI_REDO_DISABLE_ICON, IDR_REDO}, + //-------------------------------------------------------------------------------------// + {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, + //-------------------------------------------------------------------------------------// + + {IDM_SEARCH_FIND, IDI_FIND_OFF_ICON, IDI_FIND_ON_ICON, IDI_FIND_OFF_ICON, IDR_FIND}, + {IDM_SEARCH_REPLACE, IDI_REPLACE_OFF_ICON, IDI_REPLACE_ON_ICON, IDI_REPLACE_OFF_ICON, IDR_REPLACE}, + + //-------------------------------------------------------------------------------------// + {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, + //-------------------------------------------------------------------------------------// + {IDM_VIEW_ZOOMIN, IDI_ZOOMIN_OFF_ICON, IDI_ZOOMIN_ON_ICON, IDI_ZOOMIN_OFF_ICON, IDR_ZOOMIN}, + {IDM_VIEW_ZOOMOUT, IDI_ZOOMOUT_OFF_ICON, IDI_ZOOMOUT_ON_ICON, IDI_ZOOMOUT_OFF_ICON, IDR_ZOOMOUT}, -Notepad_plus::Notepad_plus(): Window(), _mainWindowStatus(0), _pDocTab(NULL), _pEditView(NULL), + //-------------------------------------------------------------------------------------// + {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, + //-------------------------------------------------------------------------------------// + {IDM_VIEW_SYNSCROLLV, IDI_SYNCV_OFF_ICON, IDI_SYNCV_ON_ICON, IDI_SYNCV_DISABLE_ICON, IDR_SYNCV}, + {IDM_VIEW_SYNSCROLLH, IDI_SYNCH_OFF_ICON, IDI_SYNCH_ON_ICON, IDI_SYNCH_DISABLE_ICON, IDR_SYNCH}, + + //-------------------------------------------------------------------------------------// + {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, + //-------------------------------------------------------------------------------------// + {IDM_VIEW_WRAP, IDI_VIEW_WRAP_OFF_ICON, IDI_VIEW_WRAP_ON_ICON, IDI_VIEW_WRAP_OFF_ICON, IDR_WRAP}, + {IDM_VIEW_ALL_CHARACTERS, IDI_VIEW_ALL_CHAR_OFF_ICON, IDI_VIEW_ALL_CHAR_ON_ICON, IDI_VIEW_ALL_CHAR_OFF_ICON, IDR_INVISIBLECHAR}, + {IDM_VIEW_INDENT_GUIDE, IDI_VIEW_INDENT_OFF_ICON, IDI_VIEW_INDENT_ON_ICON, IDI_VIEW_INDENT_OFF_ICON, IDR_INDENTGUIDE}, + {IDM_VIEW_USER_DLG, IDI_VIEW_UD_DLG_OFF_ICON, IDI_VIEW_UD_DLG_ON_ICON, IDI_VIEW_UD_DLG_OFF_ICON, IDR_SHOWPANNEL}, + + //-------------------------------------------------------------------------------------// + {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, + //-------------------------------------------------------------------------------------// + + {IDM_MACRO_STARTRECORDINGMACRO, IDI_STARTRECORD_OFF_ICON, IDI_STARTRECORD_ON_ICON, IDI_STARTRECORD_DISABLE_ICON, IDR_STARTRECORD}, + {IDM_MACRO_STOPRECORDINGMACRO, IDI_STOPRECORD_OFF_ICON, IDI_STOPRECORD_ON_ICON, IDI_STOPRECORD_DISABLE_ICON, IDR_STOPRECORD}, + {IDM_MACRO_PLAYBACKRECORDEDMACRO, IDI_PLAYRECORD_OFF_ICON, IDI_PLAYRECORD_ON_ICON, IDI_PLAYRECORD_DISABLE_ICON, IDR_PLAYRECORD}, + {IDM_MACRO_RUNMULTIMACRODLG, IDI_MMPLAY_OFF_ICON, IDI_MMPLAY_ON_ICON, IDI_MMPLAY_DIS_ICON, IDR_M_PLAYRECORD}, + {IDM_MACRO_SAVECURRENTMACRO, IDI_SAVERECORD_OFF_ICON, IDI_SAVERECORD_ON_ICON, IDI_SAVERECORD_DISABLE_ICON, IDR_SAVERECORD} + +}; + + +Notepad_plus::Notepad_plus(): _mainWindowStatus(0), _pDocTab(NULL), _pEditView(NULL), _pMainSplitter(NULL), _recordingMacro(false), _pTrayIco(NULL), _isUDDocked(false), _linkTriggered(true), _isDocModifing(false), _isHotspotDblClicked(false), _sysMenuEntering(false), @@ -48,7 +109,7 @@ Notepad_plus::Notepad_plus(): Window(), _mainWindowStatus(0), _pDocTab(NULL), _p _isFileOpening(false), _rememberThisSession(true) { ZeroMemory(&_prevSelectedRange, sizeof(_prevSelectedRange)); - _winVersion = (NppParameters::getInstance())->getWinVersion(); + TiXmlDocumentA *nativeLangDocRootA = (NppParameters::getInstance())->getNativeLangA(); _nativeLangSpeaker.init(nativeLangDocRootA); @@ -82,186 +143,433 @@ Notepad_plus::~Notepad_plus() delete _pTrayIco; } -void Notepad_plus::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLine, CmdLineParams *cmdLineParams) +LRESULT Notepad_plus::init(HWND hwnd) { - time_t timestampBegin = 0; - if (cmdLineParams->_showLoadingTime) - timestampBegin = time(NULL); + NppParameters *pNppParam = NppParameters::getInstance(); + NppGUI & nppGUI = (NppGUI &)pNppParam->getNppGUI(); - Window::init(hInst, parent); - WNDCLASS nppClass; + // Menu + _mainMenuHandle = ::GetMenu(hwnd); + int langPos2BeRemoved = MENUINDEX_LANGUAGE+1; + if (nppGUI._isLangMenuCompact) + langPos2BeRemoved = MENUINDEX_LANGUAGE; + ::RemoveMenu(_mainMenuHandle, langPos2BeRemoved, MF_BYPOSITION); - nppClass.style = CS_BYTEALIGNWINDOW | CS_DBLCLKS; - nppClass.lpfnWndProc = Notepad_plus_Proc; - nppClass.cbClsExtra = 0; - nppClass.cbWndExtra = 0; - nppClass.hInstance = _hInst; - nppClass.hIcon = ::LoadIcon(hInst, MAKEINTRESOURCE(IDI_M30ICON)); - nppClass.hCursor = ::LoadCursor(NULL, IDC_ARROW); - nppClass.hbrBackground = ::CreateSolidBrush(::GetSysColor(COLOR_MENU)); - nppClass.lpszMenuName = MAKEINTRESOURCE(IDR_M30_MENU); - nppClass.lpszClassName = _className; + //Views + _pDocTab = &_mainDocTab; + _pEditView = &_mainEditView; + _pNonDocTab = &_subDocTab; + _pNonEditView = &_subEditView; - _isPrelaunch = cmdLineParams->_isPreLaunch; + _mainEditView.init(_pPublicInterface->getHinst(), hwnd); + _subEditView.init(_pPublicInterface->getHinst(), hwnd); - if (!::RegisterClass(&nppClass)) - { - systemMessage(TEXT("System Err")); - throw int(98); - } + _fileEditView.init(_pPublicInterface->getHinst(), hwnd); + MainFileManager->init(this, &_fileEditView); //get it up and running asap. - RECT workAreaRect; - ::SystemParametersInfo(SPI_GETWORKAREA, 0, &workAreaRect, 0); - - NppParameters *pNppParams = NppParameters::getInstance(); - const NppGUI & nppGUI = pNppParams->getNppGUI(); - - if (cmdLineParams->_isNoPlugin) - _pluginsManager.disable(); - - _hSelf = ::CreateWindowEx( - WS_EX_ACCEPTFILES | (_nativeLangSpeaker.isRTL()?WS_EX_LAYOUTRTL:0),\ - _className,\ - TEXT("Notepad++"),\ - WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,\ - // CreateWindowEx bug : set all 0 to walk around the pb - 0, 0, 0, 0,\ - _hParent,\ - NULL,\ - _hInst,\ - (LPVOID)this); // pass the ptr of this instantiated object - // for retrieve it in Notepad_plus_Proc from - // the CREATESTRUCT.lpCreateParams afterward. - - if (!_hSelf) - { - systemMessage(TEXT("System Err")); - throw int(777); - } - - gNppHWND = _hSelf; - - // In setting the startup window position, take into account that the last-saved - // position might have assumed a second monitor that's no longer available. - POINT newUpperLeft; - newUpperLeft.x = nppGUI._appPos.left + workAreaRect.left; - newUpperLeft.y = nppGUI._appPos.top + workAreaRect.top; - - // GetSystemMetrics does not support the multi-monitor values on Windows NT and Windows 95. - if ((_winVersion != WV_95) && (_winVersion != WV_NT)) - { - int margin = ::GetSystemMetrics(SM_CYSMCAPTION); - if (newUpperLeft.x > ::GetSystemMetrics(SM_CXVIRTUALSCREEN)-margin) - newUpperLeft.x = workAreaRect.right - nppGUI._appPos.right; - if (newUpperLeft.x + nppGUI._appPos.right < ::GetSystemMetrics(SM_XVIRTUALSCREEN)+margin) - newUpperLeft.x = workAreaRect.left; - if (newUpperLeft.y > ::GetSystemMetrics(SM_CYVIRTUALSCREEN)-margin) - newUpperLeft.y = workAreaRect.bottom - nppGUI._appPos.bottom; - if (newUpperLeft.y + nppGUI._appPos.bottom < ::GetSystemMetrics(SM_YVIRTUALSCREEN)+margin) - newUpperLeft.y = workAreaRect.top; - } - - if (cmdLineParams->isPointValid()) - ::MoveWindow(_hSelf, cmdLineParams->_point.x, cmdLineParams->_point.y, nppGUI._appPos.right, nppGUI._appPos.bottom, TRUE); - else - ::MoveWindow(_hSelf, newUpperLeft.x, newUpperLeft.y, nppGUI._appPos.right, nppGUI._appPos.bottom, TRUE); + pNppParam->setFontList(hwnd); - if (nppGUI._tabStatus & TAB_MULTILINE) - ::SendMessage(_hSelf, WM_COMMAND, IDM_VIEW_DRAWTABBAR_MULTILINE, 0); - if (!nppGUI._menuBarShow) - ::SetMenu(_hSelf, NULL); + _mainWindowStatus = WindowMainActive; + _activeView = MAIN_VIEW; + + const ScintillaViewParams & svp1 = pNppParam->getSVP(SCIV_PRIMARY); + const ScintillaViewParams & svp2 = pNppParam->getSVP(SCIV_SECOND); + + int tabBarStatus = nppGUI._tabStatus; + _toReduceTabBar = ((tabBarStatus & TAB_REDUCE) != 0); + _docTabIconList.create(_toReduceTabBar?13:20, _pPublicInterface->getHinst(), docTabIconIDs, sizeof(docTabIconIDs)/sizeof(int)); + + _mainDocTab.init(_pPublicInterface->getHinst(), hwnd, &_mainEditView, &_docTabIconList); + _subDocTab.init(_pPublicInterface->getHinst(), hwnd, &_subEditView, &_docTabIconList); + + _mainEditView.display(); + + _invisibleEditView.init(_pPublicInterface->getHinst(), hwnd); + _invisibleEditView.execute(SCI_SETUNDOCOLLECTION); + _invisibleEditView.execute(SCI_EMPTYUNDOBUFFER); + _invisibleEditView.wrap(false); // Make sure no slow down + + // Configuration of 2 scintilla views + _mainEditView.showMargin(ScintillaEditView::_SC_MARGE_LINENUMBER, svp1._lineNumberMarginShow); + _subEditView.showMargin(ScintillaEditView::_SC_MARGE_LINENUMBER, svp2._lineNumberMarginShow); + _mainEditView.showMargin(ScintillaEditView::_SC_MARGE_SYBOLE, svp1._bookMarkMarginShow); + _subEditView.showMargin(ScintillaEditView::_SC_MARGE_SYBOLE, svp2._bookMarkMarginShow); + + _mainEditView.showIndentGuideLine(svp1._indentGuideLineShow); + _subEditView.showIndentGuideLine(svp2._indentGuideLineShow); - if (cmdLineParams->_isNoTab || (nppGUI._tabStatus & TAB_HIDE)) - { - ::SendMessage(_hSelf, NPPM_HIDETABBAR, 0, TRUE); - } + ::SendMessage(hwnd, NPPM_INTERNAL_SETCARETWIDTH, 0, 0); + ::SendMessage(hwnd, NPPM_INTERNAL_SETCARETBLINKRATE, 0, 0); - _rememberThisSession = !cmdLineParams->_isNoSession; - if (nppGUI._rememberLastSession && !cmdLineParams->_isNoSession) - { - loadLastSession(); - } - - if (!cmdLineParams->_isPreLaunch) - { - if (cmdLineParams->isPointValid()) - ::ShowWindow(_hSelf, SW_SHOW); - else - ::ShowWindow(_hSelf, nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW); - } - else - { - _pTrayIco = new trayIconControler(_hSelf, IDI_M30ICON, IDC_MINIMIZED_TRAY, ::LoadIcon(_hInst, MAKEINTRESOURCE(IDI_M30ICON)), TEXT("")); - _pTrayIco->doTrayIcon(ADD); - } - - if (cmdLine) - { - loadCommandlineParams(cmdLine, cmdLineParams); - } - - vector fileNames; - vector patterns; - patterns.push_back(TEXT("*.xml")); + _configStyleDlg.init(_pPublicInterface->getHinst(), hwnd); + _preference.init(_pPublicInterface->getHinst(), hwnd); - generic_string nppDir = pNppParams->getNppPath(); -#ifdef UNICODE - LocalizationSwitcher & localizationSwitcher = pNppParams->getLocalizationSwitcher(); - wstring localizationDir = nppDir; - PathAppend(localizationDir, TEXT("localization\\")); + //Marker Margin config + _mainEditView.setMakerStyle(svp1._folderStyle); + _subEditView.setMakerStyle(svp2._folderStyle); - getMatchedFileNames(localizationDir.c_str(), patterns, fileNames, false, false); - for (size_t i = 0 ; i < fileNames.size() ; i++) - { - localizationSwitcher.addLanguageFromXml(fileNames[i].c_str()); - } -#endif - - fileNames.clear(); - ThemeSwitcher & themeSwitcher = pNppParams->getThemeSwitcher(); + _mainEditView.execute(SCI_SETCARETLINEVISIBLE, svp1._currentLineHilitingShow); + _subEditView.execute(SCI_SETCARETLINEVISIBLE, svp2._currentLineHilitingShow); - // Get themes from both npp install themes dir and app data themes dir with the per user - // overriding default themes of the same name. - generic_string themeDir(pNppParams->getAppDataNppDir()); - PathAppend(themeDir, TEXT("themes\\")); + _mainEditView.execute(SCI_SETCARETLINEVISIBLEALWAYS, true); + _subEditView.execute(SCI_SETCARETLINEVISIBLEALWAYS, true); - getMatchedFileNames(themeDir.c_str(), patterns, fileNames, false, false); - for (size_t i = 0 ; i < fileNames.size() ; i++) - { - themeSwitcher.addThemeFromXml(fileNames[i].c_str()); - } + _mainEditView.wrap(svp1._doWrap); + _subEditView.wrap(svp2._doWrap); - fileNames.clear(); - themeDir.clear(); - themeDir = nppDir.c_str(); // <- should use the pointer to avoid the constructor of copy - PathAppend(themeDir, TEXT("themes\\")); - getMatchedFileNames(themeDir.c_str(), patterns, fileNames, false, false); - for (size_t i = 0 ; i < fileNames.size() ; i++) + _mainEditView.execute(SCI_SETEDGECOLUMN, svp1._edgeNbColumn); + _mainEditView.execute(SCI_SETEDGEMODE, svp1._edgeMode); + _subEditView.execute(SCI_SETEDGECOLUMN, svp2._edgeNbColumn); + _subEditView.execute(SCI_SETEDGEMODE, svp2._edgeMode); + + _mainEditView.showEOL(svp1._eolShow); + _subEditView.showEOL(svp2._eolShow); + + _mainEditView.showWSAndTab(svp1._whiteSpaceShow); + _subEditView.showWSAndTab(svp2._whiteSpaceShow); + + _mainEditView.showWrapSymbol(svp1._wrapSymbolShow); + _subEditView.showWrapSymbol(svp2._wrapSymbolShow); + + _mainEditView.performGlobalStyles(); + _subEditView.performGlobalStyles(); + + _zoomOriginalValue = _pEditView->execute(SCI_GETZOOM); + _mainEditView.execute(SCI_SETZOOM, svp1._zoom); + _subEditView.execute(SCI_SETZOOM, svp2._zoom); + + ::SendMessage(hwnd, NPPM_INTERNAL_SETMULTISELCTION, 0, 0); + + _mainEditView.execute(SCI_SETADDITIONALSELECTIONTYPING, true); + _subEditView.execute(SCI_SETADDITIONALSELECTIONTYPING, true); + + _mainEditView.execute(SCI_SETVIRTUALSPACEOPTIONS, SCVS_RECTANGULARSELECTION); + _subEditView.execute(SCI_SETVIRTUALSPACEOPTIONS, SCVS_RECTANGULARSELECTION); + + TabBarPlus::doDragNDrop(true); + + if (_toReduceTabBar) { - generic_string themeName( themeSwitcher.getThemeFromXmlFileName(fileNames[i].c_str()) ); - if (! themeSwitcher.themeNameExists(themeName.c_str()) ) + HFONT hf = (HFONT)::GetStockObject(DEFAULT_GUI_FONT); + + if (hf) { - themeSwitcher.addThemeFromXml(fileNames[i].c_str()); + ::SendMessage(_mainDocTab.getHSelf(), WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE, 0)); + ::SendMessage(_subDocTab.getHSelf(), WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE, 0)); + } + TabCtrl_SetItemSize(_mainDocTab.getHSelf(), 45, 20); + TabCtrl_SetItemSize(_subDocTab.getHSelf(), 45, 20); + } + _mainDocTab.display(); + + + TabBarPlus::doDragNDrop((tabBarStatus & TAB_DRAGNDROP) != 0); + TabBarPlus::setDrawTopBar((tabBarStatus & TAB_DRAWTOPBAR) != 0); + TabBarPlus::setDrawInactiveTab((tabBarStatus & TAB_DRAWINACTIVETAB) != 0); + TabBarPlus::setDrawTabCloseButton((tabBarStatus & TAB_CLOSEBUTTON) != 0); + TabBarPlus::setDbClk2Close((tabBarStatus & TAB_DBCLK2CLOSE) != 0); + TabBarPlus::setVertical((tabBarStatus & TAB_VERTICAL) != 0); + drawTabbarColoursFromStylerArray(); + + //--Splitter Section--// + bool isVertical = (nppGUI._splitterPos == POS_VERTICAL); + + _subSplitter.init(_pPublicInterface->getHinst(), hwnd); + _subSplitter.create(&_mainDocTab, &_subDocTab, 8, DYNAMIC, 50, isVertical); + + //--Status Bar Section--// + bool willBeShown = nppGUI._statusBarShow; + _statusBar.init(_pPublicInterface->getHinst(), hwnd, 6); + _statusBar.setPartWidth(STATUSBAR_DOC_SIZE, 250); + _statusBar.setPartWidth(STATUSBAR_CUR_POS, 300); + _statusBar.setPartWidth(STATUSBAR_EOF_FORMAT, 80); + _statusBar.setPartWidth(STATUSBAR_UNICODE_TYPE, 100); + _statusBar.setPartWidth(STATUSBAR_TYPING_MODE, 30); + _statusBar.display(willBeShown); + + _pMainWindow = &_mainDocTab; + + _dockingManager.init(_pPublicInterface->getHinst(), hwnd, &_pMainWindow); + + if (nppGUI._isMinimizedToTray && _pTrayIco == NULL) + _pTrayIco = new trayIconControler(hwnd, IDI_M30ICON, IDC_MINIMIZED_TRAY, ::LoadIcon(_pPublicInterface->getHinst(), MAKEINTRESOURCE(IDI_M30ICON)), TEXT("")); + + checkSyncState(); + + // Plugin Manager + NppData nppData; + nppData._nppHandle = hwnd; + nppData._scintillaMainHandle = _mainEditView.getHSelf(); + nppData._scintillaSecondHandle = _subEditView.getHSelf(); + + _scintillaCtrls4Plugins.init(_pPublicInterface->getHinst(), hwnd); + _pluginsManager.init(nppData); + _pluginsManager.loadPlugins(); + const TCHAR *appDataNpp = pNppParam->getAppDataNppDir(); + if (appDataNpp[0]) + _pluginsManager.loadPlugins(appDataNpp); + + _restoreButton.init(_pPublicInterface->getHinst(), hwnd); + + + // ------------ // + // Menu Section // + // ------------ // + + // Macro Menu + std::vector & macros = pNppParam->getMacroList(); + HMENU hMacroMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_MACRO); + size_t const posBase = 6; + size_t nbMacro = macros.size(); + if (nbMacro >= 1) + ::InsertMenu(hMacroMenu, posBase - 1, MF_BYPOSITION, (unsigned int)-1, 0); + for (size_t i = 0 ; i < nbMacro ; i++) + { + ::InsertMenu(hMacroMenu, posBase + i, MF_BYPOSITION, ID_MACRO + i, macros[i].toMenuItemString().c_str()); + } + // Run Menu + std::vector & userCommands = pNppParam->getUserCommandList(); + HMENU hRunMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_RUN); + int const runPosBase = 2; + size_t nbUserCommand = userCommands.size(); + if (nbUserCommand >= 1) + ::InsertMenu(hRunMenu, runPosBase - 1, MF_BYPOSITION, (unsigned int)-1, 0); + for (size_t i = 0 ; i < nbUserCommand ; i++) + { + ::InsertMenu(hRunMenu, runPosBase + i, MF_BYPOSITION, ID_USER_CMD + i, userCommands[i].toMenuItemString().c_str()); + } + + // Updater menu item + if (!nppGUI._doesExistUpdater) + { + //::MessageBox(NULL, TEXT("pas de updater"), TEXT(""), MB_OK); + ::DeleteMenu(_mainMenuHandle, IDM_UPDATE_NPP, MF_BYCOMMAND); + ::DrawMenuBar(hwnd); + } + //Languages Menu + HMENU hLangMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_LANGUAGE); + + // Add external languages to menu + for (int i = 0 ; i < pNppParam->getNbExternalLang() ; i++) + { + ExternalLangContainer & externalLangContainer = pNppParam->getELCFromIndex(i); + + int numLangs = ::GetMenuItemCount(hLangMenu); + const int bufferSize = 100; + TCHAR buffer[bufferSize]; + + int x; + for(x = 0; (x == 0 || lstrcmp(externalLangContainer._name, buffer) > 0) && x < numLangs; x++) + { + ::GetMenuString(hLangMenu, x, buffer, bufferSize, MF_BYPOSITION); + } + + ::InsertMenu(hLangMenu, x-1, MF_BYPOSITION, IDM_LANG_EXTERNAL + i, externalLangContainer._name); + } + + if (nppGUI._excludedLangList.size() > 0) + { + for (size_t i = 0 ; i < nppGUI._excludedLangList.size() ; i++) + { + int cmdID = pNppParam->langTypeToCommandID(nppGUI._excludedLangList[i]._langType); + const int itemSize = 256; + TCHAR itemName[itemSize]; + ::GetMenuString(hLangMenu, cmdID, itemName, itemSize, MF_BYCOMMAND); + nppGUI._excludedLangList[i]._cmdID = cmdID; + nppGUI._excludedLangList[i]._langName = itemName; + ::DeleteMenu(hLangMenu, cmdID, MF_BYCOMMAND); + DrawMenuBar(hwnd); } } - // Notify plugins that Notepad++ is ready + // Add User Define Languages Entry + int udlpos = ::GetMenuItemCount(hLangMenu) - 1; + + for (int i = 0 ; i < pNppParam->getNbUserLang() ; i++) + { + UserLangContainer & userLangContainer = pNppParam->getULCFromIndex(i); + ::InsertMenu(hLangMenu, udlpos + i, MF_BYPOSITION, IDM_LANG_USER + i + 1, userLangContainer.getName()); + } + + //Add recent files + HMENU hFileMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_FILE); + int nbLRFile = pNppParam->getNbLRFile(); + int pos = IDM_FILEMENU_LASTONE - IDM_FILE + 2; + + _lastRecentFileList.initMenu(hFileMenu, IDM_FILEMENU_LASTONE + 1, pos); + _lastRecentFileList.setLangEncoding(_nativeLangSpeaker.getLangEncoding()); + for (int i = 0 ; i < nbLRFile ; i++) + { + generic_string * stdStr = pNppParam->getLRFile(i); + if (!nppGUI._checkHistoryFiles || PathFileExists(stdStr->c_str())) + { + _lastRecentFileList.add(stdStr->c_str()); + } + } + + //Plugin menu + _pluginsManager.setMenu(_mainMenuHandle, NULL); + + //Main menu is loaded, now load context menu items + pNppParam->getContextMenuFromXmlTree(_mainMenuHandle); + + if (pNppParam->hasCustomContextMenu()) + { + _mainEditView.execute(SCI_USEPOPUP, FALSE); + _subEditView.execute(SCI_USEPOPUP, FALSE); + } + + generic_string pluginsTrans, windowTrans; + _nativeLangSpeaker.changeMenuLang(_mainMenuHandle, pluginsTrans, windowTrans); + ::DrawMenuBar(hwnd); + + if (_pluginsManager.hasPlugins() && pluginsTrans != TEXT("")) + { + ::ModifyMenu(_mainMenuHandle, MENUINDEX_PLUGINS, MF_BYPOSITION, 0, pluginsTrans.c_str()); + } + //Windows menu + _windowsMenu.init(_pPublicInterface->getHinst(), _mainMenuHandle, windowTrans.c_str()); + + // Update context menu strings + vector & tmp = pNppParam->getContextMenuItems(); + size_t len = tmp.size(); + TCHAR menuName[64]; + for (size_t i = 0 ; i < len ; i++) + { + if (tmp[i]._itemName == TEXT("")) + { + ::GetMenuString(_mainMenuHandle, tmp[i]._cmdID, menuName, 64, MF_BYCOMMAND); + tmp[i]._itemName = purgeMenuItemString(menuName); + } + } + + //Input all the menu item names into shortcut list + //This will automatically do all translations, since menu translation has been done already + vector & shortcuts = pNppParam->getUserShortcuts(); + len = shortcuts.size(); + + for(size_t i = 0; i < len; i++) + { + CommandShortcut & csc = shortcuts[i]; + if (!csc.getName()[0]) + { //no predefined name, get name from menu and use that + ::GetMenuString(_mainMenuHandle, csc.getID(), menuName, 64, MF_BYCOMMAND); + csc.setName(purgeMenuItemString(menuName, true).c_str()); + } + } + //Translate non-menu shortcuts + _nativeLangSpeaker.changeShortcutLang(); + + //Update plugin shortcuts, all plugin commands should be available now + pNppParam->reloadPluginCmds(); + + // Shortcut Accelerator : should be the last one since it will capture all the shortcuts + _accelerator.init(_mainMenuHandle, hwnd); + pNppParam->setAccelerator(&_accelerator); + + // Scintilla key accelerator + vector scints; + scints.push_back(_mainEditView.getHSelf()); + scints.push_back(_subEditView.getHSelf()); + _scintaccelerator.init(&scints, _mainMenuHandle, hwnd); + + pNppParam->setScintillaAccelerator(&_scintaccelerator); + _scintaccelerator.updateKeys(); + + ::DrawMenuBar(hwnd); + + + //-- Tool Bar Section --// + toolBarStatusType tbStatus = nppGUI._toolBarStatus; + willBeShown = nppGUI._toolbarShow; + + // To notify plugins that toolbar icons can be registered SCNotification scnN; - scnN.nmhdr.code = NPPN_READY; - scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.code = NPPN_TBMODIFICATION; + scnN.nmhdr.hwndFrom = hwnd; scnN.nmhdr.idFrom = 0; _pluginsManager.notify(&scnN); - if (cmdLineParams->_showLoadingTime) - { - time_t timestampEnd = time(NULL); - double loadTime = difftime(timestampEnd, timestampBegin); + _toolBar.init(_pPublicInterface->getHinst(), hwnd, tbStatus, toolBarIcons, sizeof(toolBarIcons)/sizeof(ToolBarButtonUnit)); - char dest[256]; - sprintf(dest, "Loading time : %.2lf seconds", loadTime); - ::MessageBoxA(NULL, dest, "", MB_OK); + changeToolBarIcons(); + + _rebarTop.init(_pPublicInterface->getHinst(), hwnd); + _rebarBottom.init(_pPublicInterface->getHinst(), hwnd); + _toolBar.addToRebar(&_rebarTop); + _rebarTop.setIDVisible(REBAR_BAR_TOOLBAR, willBeShown); + + //--Init dialogs--// + _findReplaceDlg.init(_pPublicInterface->getHinst(), hwnd, &_pEditView); + _incrementFindDlg.init(_pPublicInterface->getHinst(), hwnd, &_findReplaceDlg, _nativeLangSpeaker.isRTL()); + _incrementFindDlg.addToRebar(&_rebarBottom); + _goToLineDlg.init(_pPublicInterface->getHinst(), hwnd, &_pEditView); + _colEditorDlg.init(_pPublicInterface->getHinst(), hwnd, &_pEditView); + _aboutDlg.init(_pPublicInterface->getHinst(), hwnd); + _runDlg.init(_pPublicInterface->getHinst(), hwnd); + _runMacroDlg.init(_pPublicInterface->getHinst(), hwnd); + + //--User Define Dialog Section--// + int uddStatus = nppGUI._userDefineDlgStatus; + UserDefineDialog *udd = _pEditView->getUserDefineDlg(); + + bool uddShow = false; + switch (uddStatus) + { + case UDD_SHOW : // show & undocked + udd->doDialog(true, _nativeLangSpeaker.isRTL()); + _nativeLangSpeaker.changeUserDefineLang(udd); + uddShow = true; + break; + case UDD_DOCKED : { // hide & docked + _isUDDocked = true; + break;} + case (UDD_SHOW | UDD_DOCKED) : // show & docked + udd->doDialog(true, _nativeLangSpeaker.isRTL()); + _nativeLangSpeaker.changeUserDefineLang(udd); + ::SendMessage(udd->getHSelf(), WM_COMMAND, IDC_DOCK_BUTTON, 0); + uddShow = true; + break; + + default : // hide & undocked + break; + } + // UserDefine Dialog + + checkMenuItem(IDM_VIEW_USER_DLG, uddShow); + _toolBar.setCheck(IDM_VIEW_USER_DLG, uddShow); + + //launch the plugin dlg memorized at the last session + DockingManagerData &dmd = nppGUI._dockingData; + + _dockingManager.setDockedContSize(CONT_LEFT , nppGUI._dockingData._leftWidth); + _dockingManager.setDockedContSize(CONT_RIGHT , nppGUI._dockingData._rightWidth); + _dockingManager.setDockedContSize(CONT_TOP , nppGUI._dockingData._topHeight); + _dockingManager.setDockedContSize(CONT_BOTTOM, nppGUI._dockingData._bottomHight); + + for (size_t i = 0 ; i < dmd._pluginDockInfo.size() ; i++) + { + PlugingDlgDockingInfo & pdi = dmd._pluginDockInfo[i]; + + if (pdi._isVisible) + _pluginsManager.runPluginCommand(pdi._name.c_str(), pdi._internalID); } + + for (size_t i = 0 ; i < dmd._containerTabInfo.size() ; i++) + { + ContainerTabInfo & cti = dmd._containerTabInfo[i]; + _dockingManager.setActiveTab(cti._cont, cti._activeTab); + } + //Load initial docs into doctab + loadBufferIntoView(_mainEditView.getCurrentBufferID(), MAIN_VIEW); + loadBufferIntoView(_subEditView.getCurrentBufferID(), SUB_VIEW); + activateBuffer(_mainEditView.getCurrentBufferID(), MAIN_VIEW); + activateBuffer(_subEditView.getCurrentBufferID(), SUB_VIEW); + MainFileManager->increaseDocNr(); //so next doc starts at 2 + + ::SetFocus(_mainEditView.getHSelf()); + return TRUE; } @@ -317,13 +625,13 @@ bool Notepad_plus::saveGUIParams() WINDOWPLACEMENT posInfo; posInfo.length = sizeof(WINDOWPLACEMENT); - ::GetWindowPlacement(_hSelf, &posInfo); + ::GetWindowPlacement(_pPublicInterface->getHSelf(), &posInfo); nppGUI._appPos.left = posInfo.rcNormalPosition.left; nppGUI._appPos.top = posInfo.rcNormalPosition.top; nppGUI._appPos.right = posInfo.rcNormalPosition.right - posInfo.rcNormalPosition.left; nppGUI._appPos.bottom = posInfo.rcNormalPosition.bottom - posInfo.rcNormalPosition.top; - nppGUI._isMaximized = (IsZoomed(_hSelf) || (posInfo.flags & WPF_RESTORETOMAXIMIZED)); + nppGUI._isMaximized = (IsZoomed(_pPublicInterface->getHSelf()) || (posInfo.flags & WPF_RESTORETOMAXIMIZED)); saveDockingParams(); @@ -743,13 +1051,13 @@ bool Notepad_plus::replaceInFiles() getMatchedFileNames(dir2Search, patterns2Match, fileNames, isRecursive, isInHiddenDir); if (fileNames.size() > 1) - CancelThreadHandle = ::CreateThread(NULL, 0, AsyncCancelFindInFiles, _hSelf, 0, NULL); + CancelThreadHandle = ::CreateThread(NULL, 0, AsyncCancelFindInFiles, _pPublicInterface->getHSelf(), 0, NULL); bool dontClose = false; for (size_t i = 0 ; i < fileNames.size() ; i++) { MSG msg; - if (PeekMessage(&msg, _hSelf, NPPM_INTERNAL_CANCEL_FIND_IN_FILES, NPPM_INTERNAL_CANCEL_FIND_IN_FILES, PM_REMOVE)) break; + if (PeekMessage(&msg, _pPublicInterface->getHSelf(), NPPM_INTERNAL_CANCEL_FIND_IN_FILES, NPPM_INTERNAL_CANCEL_FIND_IN_FILES, PM_REMOVE)) break; BufferID id = MainFileManager->getBufferFromName(fileNames.at(i).c_str()); if (id != BUFFER_INVALID) @@ -824,7 +1132,7 @@ bool Notepad_plus::findInFiles() getMatchedFileNames(dir2Search, patterns2Match, fileNames, isRecursive, isInHiddenDir); if (fileNames.size() > 1) - CancelThreadHandle = ::CreateThread(NULL, 0, AsyncCancelFindInFiles, _hSelf, 0, NULL); + CancelThreadHandle = ::CreateThread(NULL, 0, AsyncCancelFindInFiles, _pPublicInterface->getHSelf(), 0, NULL); _findReplaceDlg.beginNewFilesSearch(); @@ -832,7 +1140,7 @@ bool Notepad_plus::findInFiles() for (size_t i = 0 ; i < fileNames.size() ; i++) { MSG msg; - if (PeekMessage(&msg, _hSelf, NPPM_INTERNAL_CANCEL_FIND_IN_FILES, NPPM_INTERNAL_CANCEL_FIND_IN_FILES, PM_REMOVE)) break; + if (PeekMessage(&msg, _pPublicInterface->getHSelf(), NPPM_INTERNAL_CANCEL_FIND_IN_FILES, NPPM_INTERNAL_CANCEL_FIND_IN_FILES, PM_REMOVE)) break; BufferID id = MainFileManager->getBufferFromName(fileNames.at(i).c_str()); if (id != BUFFER_INVALID) @@ -963,7 +1271,7 @@ void Notepad_plus::filePrint(bool showDialog) int startPos = int(_pEditView->execute(SCI_GETSELECTIONSTART)); int endPos = int(_pEditView->execute(SCI_GETSELECTIONEND)); - printer.init(_hInst, _hSelf, _pEditView, showDialog, startPos, endPos); + printer.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), _pEditView, showDialog, startPos, endPos); printer.doPrint(); } @@ -1003,7 +1311,7 @@ int Notepad_plus::doDeleteOrNot(const TCHAR *fn) int Notepad_plus::doActionOrNot(const TCHAR *title, const TCHAR *displayText, int type) { - return ::MessageBox(_hSelf, displayText, title, type); + return ::MessageBox(_pPublicInterface->getHSelf(), displayText, title, type); } void Notepad_plus::enableMenu(int cmdID, bool doEnable) const @@ -1239,7 +1547,7 @@ void Notepad_plus::pasteToMarkedLines() return; int lastLine = _pEditView->lastZeroBasedLineNumber(); - ::OpenClipboard(_hSelf); + ::OpenClipboard(_pPublicInterface->getHSelf()); HANDLE clipboardData = ::GetClipboardData(clipFormat); ::GlobalSize(clipboardData); LPVOID clipboardDataPtr = ::GlobalLock(clipboardData); @@ -1693,12 +2001,12 @@ void Notepad_plus::specialCmd(int id, int param) { ValueDlg nbColumnEdgeDlg; ScintillaViewParams & svp = (ScintillaViewParams &)pNppParam->getSVP(param == 1?SCIV_PRIMARY:SCIV_SECOND); - nbColumnEdgeDlg.init(_hInst, _preference.getHSelf(), svp._edgeNbColumn, TEXT("Nb of column:")); + nbColumnEdgeDlg.init(_pPublicInterface->getHinst(), _preference.getHSelf(), svp._edgeNbColumn, TEXT("Nb of column:")); nbColumnEdgeDlg.setNBNumber(3); POINT p; ::GetCursorPos(&p); - ::ScreenToClient(_hParent, &p); + ::ScreenToClient(_pPublicInterface->getHParent(), &p); int size = nbColumnEdgeDlg.doDialog(p, _nativeLangSpeaker.isRTL()); if (size != -1) @@ -1883,10 +2191,9 @@ void Notepad_plus::setTitle() result += buf->getFullPathName(); } result += TEXT(" - "); - result += _className; - //::SetWindowText(_hSelf, title); - ::SendMessage(_hSelf, WM_SETTEXT, 0, (LPARAM)result.c_str()); - + result += _pPublicInterface->getClassName(); + + ::SendMessage(_pPublicInterface->getHSelf(), WM_SETTEXT, 0, (LPARAM)result.c_str()); } void Notepad_plus::activateNextDoc(bool direction) @@ -2076,7 +2383,7 @@ void Notepad_plus::dropFiles(HDROP hdrop) // Determinate in which view the file(s) is (are) dropped POINT p; ::DragQueryPoint(hdrop, &p); - HWND hWin = ::RealChildWindowFromPoint(_hSelf, p); + HWND hWin = ::RealChildWindowFromPoint(_pPublicInterface->getHSelf(), p); if (!hWin) return; if ((_mainEditView.getHSelf() == hWin) || (_mainDocTab.getHSelf() == hWin)) @@ -2108,11 +2415,11 @@ void Notepad_plus::dropFiles(HDROP hdrop) // May not work for Win2k, but OK for lower versions // Note: how to drop a file to an iconic window? // Actually, it is the Send To command that generates a drop. - if (::IsIconic(_hSelf)) + if (::IsIconic(_pPublicInterface->getHSelf())) { - ::ShowWindow(_hSelf, SW_RESTORE); + ::ShowWindow(_pPublicInterface->getHSelf(), SW_RESTORE); } - ::SetForegroundWindow(_hSelf); + ::SetForegroundWindow(_pPublicInterface->getHSelf()); } } @@ -2124,7 +2431,7 @@ void Notepad_plus::checkModifiedDocument() void Notepad_plus::getMainClientRect(RECT &rc) const { - getClientRect(rc); + _pPublicInterface->getClientRect(rc); rc.top += _rebarTop.getHeight(); rc.bottom -= rc.top + _rebarBottom.getHeight() + _statusBar.getHeight(); } @@ -2152,7 +2459,7 @@ void Notepad_plus::showView(int whichOne) { _mainWindowStatus |= (whichOne==MAIN_VIEW)?WindowMainActive:WindowSubActive; //Send sizing info to make windows fit - ::SendMessage(_hSelf, WM_SIZE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); } bool Notepad_plus::viewVisible(int whichOne) { @@ -2189,7 +2496,7 @@ void Notepad_plus::hideView(int whichOne) } // resize the main window - ::SendMessage(_hSelf, WM_SIZE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); switchEditViewTo(otherFromView(whichOne)); int viewToDisable = (whichOne == SUB_VIEW?WindowSubActive:WindowMainActive); @@ -2319,7 +2626,7 @@ void Notepad_plus::dockUserDlg() if (!_pMainSplitter) { _pMainSplitter = new SplitterContainer; - _pMainSplitter->init(_hInst, _hSelf); + _pMainSplitter->init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf()); Window *pWindow; if (_mainWindowStatus & (WindowMainActive | WindowSubActive)) @@ -2340,7 +2647,7 @@ void Notepad_plus::dockUserDlg() _mainWindowStatus |= WindowUserActive; _pMainWindow = _pMainSplitter; - ::SendMessage(_hSelf, WM_SIZE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); } void Notepad_plus::undockUserDlg() @@ -2353,7 +2660,7 @@ void Notepad_plus::undockUserDlg() else _pMainWindow = _pDocTab; - ::SendMessage(_hSelf, WM_SIZE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); _mainWindowStatus &= ~WindowUserActive; (ScintillaEditView::getUserDefineDlg())->display(); @@ -2382,12 +2689,12 @@ void Notepad_plus::docOpenInNewInstance(FileTransferMode mode, int x, int y) command += pY; Command cmd(command); - cmd.run(_hSelf); + cmd.run(_pPublicInterface->getHSelf()); if (mode == TransferMove) { doClose(bufferID, currentView()); if (noOpenedDoc()) - ::SendMessage(_hSelf, WM_CLOSE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_CLOSE, 0, 0); } } @@ -2447,7 +2754,7 @@ void Notepad_plus::docGotoAnotherEditView(FileTransferMode mode) //just close the activate document, since thats the one we moved (no search) doClose(_pEditView->getCurrentBufferID(), currentView()); if (noOpenedDoc()) - ::SendMessage(_hSelf, WM_CLOSE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_CLOSE, 0, 0); } // else it was cone, so leave it //Activate the other view since thats where the document went @@ -2905,7 +3212,7 @@ bool Notepad_plus::addCurrentMacro() int cmdID = ID_MACRO + nbMacro; MacroShortcut ms(Shortcut(), _macro, cmdID); - ms.init(_hInst, _hSelf); + ms.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf()); if (ms.doDialog() != -1) { @@ -2981,15 +3288,6 @@ void Notepad_plus::getTaskListInfo(TaskListInfo *tli) } } -bool Notepad_plus::isDlgsMsg(MSG *msg, bool unicodeSupported) const -{ - for (size_t i = 0; i < _hModelessDlgs.size(); i++) - { - if (unicodeSupported?(::IsDialogMessageW(_hModelessDlgs[i], msg)):(::IsDialogMessageA(_hModelessDlgs[i], msg))) - return true; - } - return false; -} bool Notepad_plus::goToPreviousIndicator(int indicID2Search, bool isWrap) const { @@ -3102,7 +3400,7 @@ void Notepad_plus::fullScreenToggle() if (!_beforeSpecialView.isFullScreen) //toggle fullscreen on { _beforeSpecialView._winPlace.length = sizeof(_beforeSpecialView._winPlace); - ::GetWindowPlacement(_hSelf, &_beforeSpecialView._winPlace); + ::GetWindowPlacement(_pPublicInterface->getHSelf(), &_beforeSpecialView._winPlace); RECT fullscreenArea; //RECT used to calculate window fullscreen size //Preset view area, in case something fails, primary monitor values @@ -3116,7 +3414,7 @@ void Notepad_plus::fullScreenToggle() HMONITOR currentMonitor; //Handle to monitor where fullscreen should go MONITORINFO mi; //Info of that monitor //Caution, this will not work on windows 95, so probably add some checking of some sorts like Unicode checks, IF 95 were to be supported - currentMonitor = ::MonitorFromWindow(_hSelf, MONITOR_DEFAULTTONEAREST); //should always be valid monitor handle + currentMonitor = ::MonitorFromWindow(_pPublicInterface->getHSelf(), MONITOR_DEFAULTTONEAREST); //should always be valid monitor handle mi.cbSize = sizeof(MONITORINFO); if (::GetMonitorInfo(currentMonitor, &mi) != FALSE) { @@ -3135,9 +3433,9 @@ void Notepad_plus::fullScreenToggle() else { //only change the GUI if not already done by postit - _beforeSpecialView.isMenuShown = ::SendMessage(_hSelf, NPPM_ISMENUHIDDEN, 0, 0) != TRUE; + _beforeSpecialView.isMenuShown = ::SendMessage(_pPublicInterface->getHSelf(), NPPM_ISMENUHIDDEN, 0, 0) != TRUE; if (_beforeSpecialView.isMenuShown) - ::SendMessage(_hSelf, NPPM_HIDEMENU, 0, TRUE); + ::SendMessage(_pPublicInterface->getHSelf(), NPPM_HIDEMENU, 0, TRUE); //Hide rebar _rebarTop.display(false); @@ -3146,21 +3444,21 @@ void Notepad_plus::fullScreenToggle() _restoreButton.setButtonStatus(bs); //Hide window so windows can properly update it - ::ShowWindow(_hSelf, SW_HIDE); + ::ShowWindow(_pPublicInterface->getHSelf(), SW_HIDE); //Set popup style for fullscreen window and store the old style if (!_beforeSpecialView.isPostIt) { - _beforeSpecialView.preStyle = ::SetWindowLongPtr(_hSelf, GWL_STYLE, WS_POPUP); + _beforeSpecialView.preStyle = ::SetWindowLongPtr(_pPublicInterface->getHSelf(), GWL_STYLE, WS_POPUP); if (!_beforeSpecialView.preStyle) { //something went wrong, use default settings _beforeSpecialView.preStyle = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN; } } //Set fullscreen window, highest non-top z-order, show the window and redraw it (refreshing the windowmanager cache aswell) - ::ShowWindow(_hSelf, SW_SHOW); - ::SetWindowPos(_hSelf, HWND_TOP, fullscreenArea.left, fullscreenArea.top, fullscreenArea.right, fullscreenArea.bottom, SWP_NOZORDER|SWP_DRAWFRAME|SWP_FRAMECHANGED); - ::SetForegroundWindow(_hSelf); + ::ShowWindow(_pPublicInterface->getHSelf(), SW_SHOW); + ::SetWindowPos(_pPublicInterface->getHSelf(), HWND_TOP, fullscreenArea.left, fullscreenArea.top, fullscreenArea.right, fullscreenArea.bottom, SWP_NOZORDER|SWP_DRAWFRAME|SWP_FRAMECHANGED); + ::SetForegroundWindow(_pPublicInterface->getHSelf()); // show restore button _restoreButton.doDialog(_nativeLangSpeaker.isRTL()); @@ -3171,7 +3469,7 @@ void Notepad_plus::fullScreenToggle() int h = rect.bottom - rect.top; RECT nppRect; - GetWindowRect(_hSelf, &nppRect); + GetWindowRect(_pPublicInterface->getHSelf(), &nppRect); int x = nppRect.right - w; int y = nppRect.top; ::MoveWindow(_restoreButton.getHSelf(), x, y, w, h, FALSE); @@ -3181,7 +3479,7 @@ void Notepad_plus::fullScreenToggle() else //toggle fullscreen off { //Hide window for updating, restore style and menu then restore position and Z-Order - ::ShowWindow(_hSelf, SW_HIDE); + ::ShowWindow(_pPublicInterface->getHSelf(), SW_HIDE); _restoreButton.setButtonStatus(buttonStatus_fullscreen ^ _restoreButton.getButtonStatus()); _restoreButton.display(false); @@ -3191,7 +3489,7 @@ void Notepad_plus::fullScreenToggle() { //only change the GUI if postit isnt active if (_beforeSpecialView.isMenuShown) - ::SendMessage(_hSelf, NPPM_HIDEMENU, 0, FALSE); + ::SendMessage(_pPublicInterface->getHSelf(), NPPM_HIDEMENU, 0, FALSE); //Show rebar _rebarTop.display(true); @@ -3201,32 +3499,31 @@ void Notepad_plus::fullScreenToggle() //Set old style if not fullscreen if (!_beforeSpecialView.isPostIt) { - ::SetWindowLongPtr( _hSelf, GWL_STYLE, _beforeSpecialView.preStyle); + ::SetWindowLongPtr( _pPublicInterface->getHSelf(), GWL_STYLE, _beforeSpecialView.preStyle); //Redraw the window and refresh windowmanager cache, dont do anything else, sizing is done later on - ::SetWindowPos(_hSelf, HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_DRAWFRAME|SWP_FRAMECHANGED); - ::ShowWindow(_hSelf, SW_SHOW); + ::SetWindowPos(_pPublicInterface->getHSelf(), HWND_TOP,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_DRAWFRAME|SWP_FRAMECHANGED); + ::ShowWindow(_pPublicInterface->getHSelf(), SW_SHOW); } if (_beforeSpecialView._winPlace.length) { if (_beforeSpecialView._winPlace.showCmd == SW_SHOWMAXIMIZED) { - //::ShowWindow(_hSelf, SW_RESTORE); - ::ShowWindow(_hSelf, SW_SHOWMAXIMIZED); + ::ShowWindow(_pPublicInterface->getHSelf(), SW_SHOWMAXIMIZED); } else { - ::SetWindowPlacement(_hSelf, &_beforeSpecialView._winPlace); + ::SetWindowPlacement(_pPublicInterface->getHSelf(), &_beforeSpecialView._winPlace); } } else //fallback { - ::ShowWindow(_hSelf, SW_SHOW); + ::ShowWindow(_pPublicInterface->getHSelf(), SW_SHOW); } } - //::SetForegroundWindow(_hSelf); + //::SetForegroundWindow(_pPublicInterface->getHSelf()); _beforeSpecialView.isFullScreen = !_beforeSpecialView.isFullScreen; - ::SendMessage(_hSelf, WM_SIZE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); if (_beforeSpecialView.isPostIt) { // show restore button on the right position @@ -3236,7 +3533,7 @@ void Notepad_plus::fullScreenToggle() int h = rect.bottom - rect.top; RECT nppRect; - GetWindowRect(_hSelf, &nppRect); + GetWindowRect(_pPublicInterface->getHSelf(), &nppRect); int x = nppRect.right - w - w; int y = nppRect.top + 1; ::MoveWindow(_restoreButton.getHSelf(), x, y, w, h, FALSE); @@ -3253,14 +3550,14 @@ void Notepad_plus::postItToggle() //check these always { _beforeSpecialView.isAlwaysOnTop = ::GetMenuState(_mainMenuHandle, IDM_VIEW_ALWAYSONTOP, MF_BYCOMMAND) == MF_CHECKED; - _beforeSpecialView.isTabbarShown = ::SendMessage(_hSelf, NPPM_ISTABBARHIDDEN, 0, 0) != TRUE; + _beforeSpecialView.isTabbarShown = ::SendMessage(_pPublicInterface->getHSelf(), NPPM_ISTABBARHIDDEN, 0, 0) != TRUE; _beforeSpecialView.isStatusbarShown = nppGUI._statusBarShow; if (nppGUI._statusBarShow) - ::SendMessage(_hSelf, NPPM_HIDESTATUSBAR, 0, TRUE); + ::SendMessage(_pPublicInterface->getHSelf(), NPPM_HIDESTATUSBAR, 0, TRUE); if (_beforeSpecialView.isTabbarShown) - ::SendMessage(_hSelf, NPPM_HIDETABBAR, 0, TRUE); + ::SendMessage(_pPublicInterface->getHSelf(), NPPM_HIDETABBAR, 0, TRUE); if (!_beforeSpecialView.isAlwaysOnTop) - ::SendMessage(_hSelf, WM_COMMAND, IDM_VIEW_ALWAYSONTOP, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_COMMAND, IDM_VIEW_ALWAYSONTOP, 0); } //Only check these if not fullscreen int bs = buttonStatus_postit; @@ -3270,9 +3567,9 @@ void Notepad_plus::postItToggle() } else { - _beforeSpecialView.isMenuShown = ::SendMessage(_hSelf, NPPM_ISMENUHIDDEN, 0, 0) != TRUE; + _beforeSpecialView.isMenuShown = ::SendMessage(_pPublicInterface->getHSelf(), NPPM_ISMENUHIDDEN, 0, 0) != TRUE; if (_beforeSpecialView.isMenuShown) - ::SendMessage(_hSelf, NPPM_HIDEMENU, 0, TRUE); + ::SendMessage(_pPublicInterface->getHSelf(), NPPM_HIDEMENU, 0, TRUE); //Hide rebar _rebarTop.display(false); @@ -3286,14 +3583,14 @@ void Notepad_plus::postItToggle() if (!_beforeSpecialView.isFullScreen) { //Hide window so windows can properly update it - ::ShowWindow(_hSelf, SW_HIDE); - _beforeSpecialView.preStyle = ::SetWindowLongPtr( _hSelf, GWL_STYLE, WS_POPUP ); + ::ShowWindow(_pPublicInterface->getHSelf(), SW_HIDE); + _beforeSpecialView.preStyle = ::SetWindowLongPtr( _pPublicInterface->getHSelf(), GWL_STYLE, WS_POPUP ); if (!_beforeSpecialView.preStyle) { //something went wrong, use default settings _beforeSpecialView.preStyle = WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN; } //Redraw the window and refresh windowmanager cache, dont do anything else, sizing is done later on - ::SetWindowPos(_hSelf, HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_DRAWFRAME|SWP_FRAMECHANGED); - ::ShowWindow(_hSelf, SW_SHOW); + ::SetWindowPos(_pPublicInterface->getHSelf(), HWND_TOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_DRAWFRAME|SWP_FRAMECHANGED); + ::ShowWindow(_pPublicInterface->getHSelf(), SW_SHOW); } // show restore button @@ -3305,7 +3602,7 @@ void Notepad_plus::postItToggle() int h = rect.bottom - rect.top; RECT nppRect; - GetWindowRect(_hSelf, &nppRect); + GetWindowRect(_pPublicInterface->getHSelf(), &nppRect); int x = nppRect.right - w - w; int y = nppRect.top + 1; ::MoveWindow(_restoreButton.getHSelf(), x, y, w, h, FALSE); @@ -3322,7 +3619,7 @@ void Notepad_plus::postItToggle() { //only change the these parts of GUI if not already done by fullscreen if (_beforeSpecialView.isMenuShown) - ::SendMessage(_hSelf, NPPM_HIDEMENU, 0, FALSE); + ::SendMessage(_pPublicInterface->getHSelf(), NPPM_HIDEMENU, 0, FALSE); //Show rebar _rebarTop.display(true); @@ -3330,27 +3627,27 @@ void Notepad_plus::postItToggle() } //Do this GUI config always if (_beforeSpecialView.isStatusbarShown) - ::SendMessage(_hSelf, NPPM_HIDESTATUSBAR, 0, FALSE); + ::SendMessage(_pPublicInterface->getHSelf(), NPPM_HIDESTATUSBAR, 0, FALSE); if (_beforeSpecialView.isTabbarShown) - ::SendMessage(_hSelf, NPPM_HIDETABBAR, 0, FALSE); + ::SendMessage(_pPublicInterface->getHSelf(), NPPM_HIDETABBAR, 0, FALSE); if (!_beforeSpecialView.isAlwaysOnTop) - ::SendMessage(_hSelf, WM_COMMAND, IDM_VIEW_ALWAYSONTOP, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_COMMAND, IDM_VIEW_ALWAYSONTOP, 0); //restore window style if not fullscreen if (!_beforeSpecialView.isFullScreen) { //dwStyle |= (WS_CAPTION | WS_SIZEBOX); - ::ShowWindow(_hSelf, SW_HIDE); - ::SetWindowLongPtr(_hSelf, GWL_STYLE, _beforeSpecialView.preStyle); + ::ShowWindow(_pPublicInterface->getHSelf(), SW_HIDE); + ::SetWindowLongPtr(_pPublicInterface->getHSelf(), GWL_STYLE, _beforeSpecialView.preStyle); //Redraw the window and refresh windowmanager cache, dont do anything else, sizing is done later on - ::SetWindowPos(_hSelf, HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_DRAWFRAME|SWP_FRAMECHANGED); - ::ShowWindow(_hSelf, SW_SHOW); + ::SetWindowPos(_pPublicInterface->getHSelf(), HWND_NOTOPMOST,0,0,0,0,SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_DRAWFRAME|SWP_FRAMECHANGED); + ::ShowWindow(_pPublicInterface->getHSelf(), SW_SHOW); } } _beforeSpecialView.isPostIt = !_beforeSpecialView.isPostIt; - ::SendMessage(_hSelf, WM_SIZE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); } void Notepad_plus::doSynScorll(HWND whichView) @@ -3530,7 +3827,7 @@ bool Notepad_plus::str2Cliboard(const TCHAR *str2cpy) return false; } - if (!::OpenClipboard(_hSelf)) + if (!::OpenClipboard(_pPublicInterface->getHSelf())) return false; ::EmptyClipboard(); @@ -3664,8 +3961,8 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask) { int curPos = _pEditView->execute(SCI_GETCURRENTPOS); ::PostMessage(_pEditView->getHSelf(), WM_LBUTTONUP, 0, 0); ::PostMessage(_pEditView->getHSelf(), SCI_SETSEL, curPos, curPos); - if (::IsIconic(_hSelf)) - ::ShowWindow(_hSelf, SW_RESTORE); + if (::IsIconic(_pPublicInterface->getHSelf())) + ::ShowWindow(_pPublicInterface->getHSelf(), SW_RESTORE); } } @@ -3725,7 +4022,7 @@ void Notepad_plus::notifyBufferChanged(Buffer * buffer, int mask) { SCNotification scnN; scnN.nmhdr.code = NPPN_LANGCHANGED; - scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf(); scnN.nmhdr.idFrom = (uptr_t)_pEditView->getCurrentBufferID(); _pluginsManager.notify(&scnN); } @@ -3772,7 +4069,7 @@ void Notepad_plus::notifyBufferActivated(BufferID bufid, int view) { SCNotification scnN; scnN.nmhdr.code = NPPN_BUFFERACTIVATED; - scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf(); scnN.nmhdr.idFrom = (uptr_t)bufid; _pluginsManager.notify(&scnN); @@ -3882,7 +4179,7 @@ void Notepad_plus::setFindReplaceFolderFilter(const TCHAR *dir, const TCHAR *fil vector Notepad_plus::addNppComponents(const TCHAR *destDir, const TCHAR *extFilterName, const TCHAR *extFilter) { - FileDialog fDlg(_hSelf, _hInst); + FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst()); fDlg.setExtFilter(extFilterName, extFilter, NULL); vector copiedFiles; @@ -4030,7 +4327,7 @@ bool Notepad_plus::reloadLang() generic_string pluginsTrans, windowTrans; _nativeLangSpeaker.changeMenuLang(_mainMenuHandle, pluginsTrans, windowTrans); - ::DrawMenuBar(_hSelf); + ::DrawMenuBar(_pPublicInterface->getHSelf()); int indexWindow = ::GetMenuItemCount(_mainMenuHandle) - 3; diff --git a/PowerEditor/src/Notepad_plus.h b/PowerEditor/src/Notepad_plus.h index b9b5987c..68d6ebf5 100644 --- a/PowerEditor/src/Notepad_plus.h +++ b/PowerEditor/src/Notepad_plus.h @@ -169,27 +169,26 @@ struct VisibleGUIConf { }; class FileDialog; +class Notepad_plus_Window; + + +class Notepad_plus { + +friend class Notepad_plus_Window; -class Notepad_plus : public Window { - enum comment_mode {cm_comment, cm_uncomment, cm_toggle}; public: Notepad_plus(); virtual ~Notepad_plus(); - void init(HINSTANCE, HWND, const TCHAR *cmdLine, CmdLineParams *cmdLineParams); + LRESULT init(HWND hwnd); + LRESULT process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); void killAllChildren(); - virtual void destroy(){ - ::DestroyWindow(_hSelf); - }; - static const TCHAR * Notepad_plus::getClassName() { - return _className; - }; - + enum comment_mode {cm_comment, cm_uncomment, cm_toggle}; + void setTitle(); void getTaskListInfo(TaskListInfo *tli); // For filtering the modeless Dialog message - bool isDlgsMsg(MSG *msg, bool unicodeSupported) const; // fileOperations //The doXXX functions apply to a single buffer and dont need to worry about views, with the excpetion of doClose, since closing one view doesnt have to mean the document is gone @@ -255,9 +254,7 @@ public: bool doStreamComment(); void doTrimTrailing(); - HACCEL getAccTable() const{ - return _accelerator.getAccTable(); - }; + bool addCurrentMacro(); @@ -267,9 +264,8 @@ public: }; bool loadSession(Session & session); - winVer getWinVersion() const {return _winVersion;}; - bool emergency(generic_string emergencySavedDir); + void notifyBufferChanged(Buffer * buffer, int mask); bool findInFiles(); @@ -277,10 +273,14 @@ public: void setFindReplaceFolderFilter(const TCHAR *dir, const TCHAR *filters); vector addNppComponents(const TCHAR *destDir, const TCHAR *extFilterName, const TCHAR *extFilter); int getHtmlXmlEncoding(const TCHAR *fileName) const; + HACCEL getAccTable() const{ + return _accelerator.getAccTable(); + }; + bool emergency(generic_string emergencySavedDir); - static HWND gNppHWND; //static handle to Notepad++ window, NULL if non-existant + private: - static const TCHAR _className[32]; + Notepad_plus_Window *_pPublicInterface; Window *_pMainWindow; DockingManager _dockingManager; @@ -336,7 +336,7 @@ private: HMENU _mainMenuHandle; bool _sysMenuEntering; - bool _isPrelaunch; + // For FullScreen/PostIt features VisibleGUIConf _beforeSpecialView; @@ -385,7 +385,6 @@ private: PluginsManager _pluginsManager; ButtonDlg _restoreButton; - winVer _winVersion; bool _isFileOpening; ScintillaCtrls _scintillaCtrls4Plugins; @@ -394,8 +393,7 @@ private: StyleArray _hotspotStyles; bool _rememberThisSession; // always true. except -nosession is indicated on the launch time - static LRESULT CALLBACK Notepad_plus_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); - LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); + BOOL notify(SCNotification *notification); void specialCmd(int id, int param); @@ -584,4 +582,5 @@ private: bool goToNextIndicator(int indicID2Search, bool isWrap = true) const; }; + #endif //NOTEPAD_PLUS_H diff --git a/PowerEditor/src/Notepad_plus_Window.cpp b/PowerEditor/src/Notepad_plus_Window.cpp new file mode 100644 index 00000000..81acbc04 --- /dev/null +++ b/PowerEditor/src/Notepad_plus_Window.cpp @@ -0,0 +1,215 @@ +//this file is part of notepad++ +//Copyright (C)2010 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. +// +//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 "precompiledHeaders.h" +#include "Notepad_plus_Window.h" + +const TCHAR Notepad_plus_Window::_className[32] = TEXT("Notepad++"); +HWND Notepad_plus_Window::gNppHWND = NULL; + +void Notepad_plus_Window::init(HINSTANCE hInst, HWND parent, const TCHAR *cmdLine, CmdLineParams *cmdLineParams) +{ + time_t timestampBegin = 0; + if (cmdLineParams->_showLoadingTime) + timestampBegin = time(NULL); + + Window::init(hInst, parent); + WNDCLASS nppClass; + + nppClass.style = CS_BYTEALIGNWINDOW | CS_DBLCLKS; + nppClass.lpfnWndProc = Notepad_plus_Proc; + nppClass.cbClsExtra = 0; + nppClass.cbWndExtra = 0; + nppClass.hInstance = _hInst; + nppClass.hIcon = ::LoadIcon(hInst, MAKEINTRESOURCE(IDI_M30ICON)); + nppClass.hCursor = ::LoadCursor(NULL, IDC_ARROW); + nppClass.hbrBackground = ::CreateSolidBrush(::GetSysColor(COLOR_MENU)); + nppClass.lpszMenuName = MAKEINTRESOURCE(IDR_M30_MENU); + nppClass.lpszClassName = _className; + + _isPrelaunch = cmdLineParams->_isPreLaunch; + + if (!::RegisterClass(&nppClass)) + { + systemMessage(TEXT("System Err")); + throw int(98); + } + + RECT workAreaRect; + ::SystemParametersInfo(SPI_GETWORKAREA, 0, &workAreaRect, 0); + + NppParameters *pNppParams = NppParameters::getInstance(); + const NppGUI & nppGUI = pNppParams->getNppGUI(); + + if (cmdLineParams->_isNoPlugin) + _notepad_plus_plus_core._pluginsManager.disable(); + + _hSelf = ::CreateWindowEx( + WS_EX_ACCEPTFILES | (_notepad_plus_plus_core._nativeLangSpeaker.isRTL()?WS_EX_LAYOUTRTL:0),\ + _className,\ + TEXT("Notepad++"),\ + WS_OVERLAPPEDWINDOW | WS_CLIPCHILDREN,\ + // CreateWindowEx bug : set all 0 to walk around the pb + 0, 0, 0, 0,\ + _hParent,\ + NULL,\ + _hInst,\ + (LPVOID)this); // pass the ptr of this instantiated object + // for retrieve it in Notepad_plus_Proc from + // the CREATESTRUCT.lpCreateParams afterward. + + if (!_hSelf) + { + systemMessage(TEXT("System Err")); + throw int(777); + } + + gNppHWND = _hSelf; + + // In setting the startup window position, take into account that the last-saved + // position might have assumed a second monitor that's no longer available. + POINT newUpperLeft; + newUpperLeft.x = nppGUI._appPos.left + workAreaRect.left; + newUpperLeft.y = nppGUI._appPos.top + workAreaRect.top; + + // GetSystemMetrics does not support the multi-monitor values on Windows NT and Windows 95. + winVer winVersion = pNppParams->getWinVersion(); + if ((winVersion != WV_95) && (winVersion != WV_NT)) + { + int margin = ::GetSystemMetrics(SM_CYSMCAPTION); + if (newUpperLeft.x > ::GetSystemMetrics(SM_CXVIRTUALSCREEN)-margin) + newUpperLeft.x = workAreaRect.right - nppGUI._appPos.right; + if (newUpperLeft.x + nppGUI._appPos.right < ::GetSystemMetrics(SM_XVIRTUALSCREEN)+margin) + newUpperLeft.x = workAreaRect.left; + if (newUpperLeft.y > ::GetSystemMetrics(SM_CYVIRTUALSCREEN)-margin) + newUpperLeft.y = workAreaRect.bottom - nppGUI._appPos.bottom; + if (newUpperLeft.y + nppGUI._appPos.bottom < ::GetSystemMetrics(SM_YVIRTUALSCREEN)+margin) + newUpperLeft.y = workAreaRect.top; + } + + if (cmdLineParams->isPointValid()) + ::MoveWindow(_hSelf, cmdLineParams->_point.x, cmdLineParams->_point.y, nppGUI._appPos.right, nppGUI._appPos.bottom, TRUE); + else + ::MoveWindow(_hSelf, newUpperLeft.x, newUpperLeft.y, nppGUI._appPos.right, nppGUI._appPos.bottom, TRUE); + + if (nppGUI._tabStatus & TAB_MULTILINE) + ::SendMessage(_hSelf, WM_COMMAND, IDM_VIEW_DRAWTABBAR_MULTILINE, 0); + + if (!nppGUI._menuBarShow) + ::SetMenu(_hSelf, NULL); + + if (cmdLineParams->_isNoTab || (nppGUI._tabStatus & TAB_HIDE)) + { + ::SendMessage(_hSelf, NPPM_HIDETABBAR, 0, TRUE); + } + + _notepad_plus_plus_core._rememberThisSession = !cmdLineParams->_isNoSession; + if (nppGUI._rememberLastSession && !cmdLineParams->_isNoSession) + { + _notepad_plus_plus_core.loadLastSession(); + } + + if (!cmdLineParams->_isPreLaunch) + { + if (cmdLineParams->isPointValid()) + ::ShowWindow(_hSelf, SW_SHOW); + else + ::ShowWindow(_hSelf, nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW); + } + else + { + _notepad_plus_plus_core._pTrayIco = new trayIconControler(_hSelf, IDI_M30ICON, IDC_MINIMIZED_TRAY, ::LoadIcon(_hInst, MAKEINTRESOURCE(IDI_M30ICON)), TEXT("")); + _notepad_plus_plus_core._pTrayIco->doTrayIcon(ADD); + } + + if (cmdLine) + { + _notepad_plus_plus_core.loadCommandlineParams(cmdLine, cmdLineParams); + } + + vector fileNames; + vector patterns; + patterns.push_back(TEXT("*.xml")); + + generic_string nppDir = pNppParams->getNppPath(); +#ifdef UNICODE + LocalizationSwitcher & localizationSwitcher = pNppParams->getLocalizationSwitcher(); + wstring localizationDir = nppDir; + PathAppend(localizationDir, TEXT("localization\\")); + + _notepad_plus_plus_core.getMatchedFileNames(localizationDir.c_str(), patterns, fileNames, false, false); + for (size_t i = 0 ; i < fileNames.size() ; i++) + { + localizationSwitcher.addLanguageFromXml(fileNames[i].c_str()); + } +#endif + + fileNames.clear(); + ThemeSwitcher & themeSwitcher = pNppParams->getThemeSwitcher(); + + // Get themes from both npp install themes dir and app data themes dir with the per user + // overriding default themes of the same name. + generic_string themeDir(pNppParams->getAppDataNppDir()); + PathAppend(themeDir, TEXT("themes\\")); + + _notepad_plus_plus_core.getMatchedFileNames(themeDir.c_str(), patterns, fileNames, false, false); + for (size_t i = 0 ; i < fileNames.size() ; i++) + { + themeSwitcher.addThemeFromXml(fileNames[i].c_str()); + } + + fileNames.clear(); + themeDir.clear(); + themeDir = nppDir.c_str(); // <- should use the pointer to avoid the constructor of copy + PathAppend(themeDir, TEXT("themes\\")); + _notepad_plus_plus_core.getMatchedFileNames(themeDir.c_str(), patterns, fileNames, false, false); + for (size_t i = 0 ; i < fileNames.size() ; i++) + { + generic_string themeName( themeSwitcher.getThemeFromXmlFileName(fileNames[i].c_str()) ); + if (! themeSwitcher.themeNameExists(themeName.c_str()) ) + { + themeSwitcher.addThemeFromXml(fileNames[i].c_str()); + } + } + + // Notify plugins that Notepad++ is ready + SCNotification scnN; + scnN.nmhdr.code = NPPN_READY; + scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.idFrom = 0; + _notepad_plus_plus_core._pluginsManager.notify(&scnN); + + if (cmdLineParams->_showLoadingTime) + { + time_t timestampEnd = time(NULL); + double loadTime = difftime(timestampEnd, timestampBegin); + + char dest[256]; + sprintf(dest, "Loading time : %.2lf seconds", loadTime); + ::MessageBoxA(NULL, dest, "", MB_OK); + } +} + +bool Notepad_plus_Window::isDlgsMsg(MSG *msg, bool unicodeSupported) const +{ + for (size_t i = 0; i < _notepad_plus_plus_core._hModelessDlgs.size(); i++) + { + if (unicodeSupported?(::IsDialogMessageW(_notepad_plus_plus_core._hModelessDlgs[i], msg)):(::IsDialogMessageA(_notepad_plus_plus_core._hModelessDlgs[i], msg))) + return true; + } + return false; +} diff --git a/PowerEditor/src/Notepad_plus_Window.h b/PowerEditor/src/Notepad_plus_Window.h new file mode 100644 index 00000000..76a5e72a --- /dev/null +++ b/PowerEditor/src/Notepad_plus_Window.h @@ -0,0 +1,67 @@ +//this file is part of notepad++ +//Copyright (C)2010 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. +// +//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. + +#ifndef NOTEPAD_PLUS_WINDOW_H +#define NOTEPAD_PLUS_WINDOW_H + +//#include "Window.h" +#include "Notepad_plus.h" + +class Notepad_plus_Window : public Window { +public: + Notepad_plus_Window() {}; + void init(HINSTANCE, HWND, const TCHAR *cmdLine, CmdLineParams *cmdLineParams); + + bool isDlgsMsg(MSG *msg, bool unicodeSupported) const; + + HACCEL getAccTable() const{ + return _notepad_plus_plus_core.getAccTable(); + }; + + bool emergency(generic_string emergencySavedDir) + { + return _notepad_plus_plus_core.emergency(emergencySavedDir); + }; + + bool isPrelaunch() const { + return _isPrelaunch; + }; + + void setIsPrelaunch(bool val) { + _isPrelaunch = val; + }; + + virtual void destroy(){ + ::DestroyWindow(_hSelf); + }; + + static const TCHAR * Notepad_plus_Window::getClassName() { + return _className; + }; + static HWND gNppHWND; //static handle to Notepad++ window, NULL if non-existant + +private: + Notepad_plus _notepad_plus_plus_core; + static LRESULT CALLBACK Notepad_plus_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); + LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); + + static const TCHAR _className[32]; + bool _isPrelaunch; + bool _disablePluginsManager; +}; + +#endif //NOTEPAD_PLUS_WINDOW_H diff --git a/PowerEditor/src/NppBigSwitch.cpp b/PowerEditor/src/NppBigSwitch.cpp index 76d522f6..1853d104 100644 --- a/PowerEditor/src/NppBigSwitch.cpp +++ b/PowerEditor/src/NppBigSwitch.cpp @@ -16,7 +16,7 @@ //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "precompiledHeaders.h" -#include "Notepad_plus.h" +#include "Notepad_plus_Window.h" #include "TaskListDlg.h" #include "ImageListSet.h" @@ -39,99 +39,48 @@ struct SortTaskListPred } }; -int docTabIconIDs[] = {IDI_SAVED_ICON, IDI_UNSAVED_ICON, IDI_READONLY_ICON}; -ToolBarButtonUnit toolBarIcons[] = { - {IDM_FILE_NEW, IDI_NEW_OFF_ICON, IDI_NEW_ON_ICON, IDI_NEW_OFF_ICON, IDR_FILENEW}, - {IDM_FILE_OPEN, IDI_OPEN_OFF_ICON, IDI_OPEN_ON_ICON, IDI_NEW_OFF_ICON, IDR_FILEOPEN}, - {IDM_FILE_SAVE, IDI_SAVE_OFF_ICON, IDI_SAVE_ON_ICON, IDI_SAVE_DISABLE_ICON, IDR_FILESAVE}, - {IDM_FILE_SAVEALL, IDI_SAVEALL_OFF_ICON, IDI_SAVEALL_ON_ICON, IDI_SAVEALL_DISABLE_ICON, IDR_SAVEALL}, - {IDM_FILE_CLOSE, IDI_CLOSE_OFF_ICON, IDI_CLOSE_ON_ICON, IDI_CLOSE_OFF_ICON, IDR_CLOSEFILE}, - {IDM_FILE_CLOSEALL, IDI_CLOSEALL_OFF_ICON, IDI_CLOSEALL_ON_ICON, IDI_CLOSEALL_OFF_ICON, IDR_CLOSEALL}, - {IDM_FILE_PRINTNOW, IDI_PRINT_OFF_ICON, IDI_PRINT_ON_ICON, IDI_PRINT_OFF_ICON, IDR_PRINT}, - - //-------------------------------------------------------------------------------------// - {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, - //-------------------------------------------------------------------------------------// - - {IDM_EDIT_CUT, IDI_CUT_OFF_ICON, IDI_CUT_ON_ICON, IDI_CUT_DISABLE_ICON, IDR_CUT}, - {IDM_EDIT_COPY, IDI_COPY_OFF_ICON, IDI_COPY_ON_ICON, IDI_COPY_DISABLE_ICON, IDR_COPY}, - {IDM_EDIT_PASTE, IDI_PASTE_OFF_ICON, IDI_PASTE_ON_ICON, IDI_PASTE_DISABLE_ICON, IDR_PASTE}, - - //-------------------------------------------------------------------------------------// - {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, - //-------------------------------------------------------------------------------------// - - {IDM_EDIT_UNDO, IDI_UNDO_OFF_ICON, IDI_UNDO_ON_ICON, IDI_UNDO_DISABLE_ICON, IDR_UNDO}, - {IDM_EDIT_REDO, IDI_REDO_OFF_ICON, IDI_REDO_ON_ICON, IDI_REDO_DISABLE_ICON, IDR_REDO}, - //-------------------------------------------------------------------------------------// - {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, - //-------------------------------------------------------------------------------------// - - {IDM_SEARCH_FIND, IDI_FIND_OFF_ICON, IDI_FIND_ON_ICON, IDI_FIND_OFF_ICON, IDR_FIND}, - {IDM_SEARCH_REPLACE, IDI_REPLACE_OFF_ICON, IDI_REPLACE_ON_ICON, IDI_REPLACE_OFF_ICON, IDR_REPLACE}, - - //-------------------------------------------------------------------------------------// - {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, - //-------------------------------------------------------------------------------------// - {IDM_VIEW_ZOOMIN, IDI_ZOOMIN_OFF_ICON, IDI_ZOOMIN_ON_ICON, IDI_ZOOMIN_OFF_ICON, IDR_ZOOMIN}, - {IDM_VIEW_ZOOMOUT, IDI_ZOOMOUT_OFF_ICON, IDI_ZOOMOUT_ON_ICON, IDI_ZOOMOUT_OFF_ICON, IDR_ZOOMOUT}, - - //-------------------------------------------------------------------------------------// - {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, - //-------------------------------------------------------------------------------------// - {IDM_VIEW_SYNSCROLLV, IDI_SYNCV_OFF_ICON, IDI_SYNCV_ON_ICON, IDI_SYNCV_DISABLE_ICON, IDR_SYNCV}, - {IDM_VIEW_SYNSCROLLH, IDI_SYNCH_OFF_ICON, IDI_SYNCH_ON_ICON, IDI_SYNCH_DISABLE_ICON, IDR_SYNCH}, - - //-------------------------------------------------------------------------------------// - {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, - //-------------------------------------------------------------------------------------// - {IDM_VIEW_WRAP, IDI_VIEW_WRAP_OFF_ICON, IDI_VIEW_WRAP_ON_ICON, IDI_VIEW_WRAP_OFF_ICON, IDR_WRAP}, - {IDM_VIEW_ALL_CHARACTERS, IDI_VIEW_ALL_CHAR_OFF_ICON, IDI_VIEW_ALL_CHAR_ON_ICON, IDI_VIEW_ALL_CHAR_OFF_ICON, IDR_INVISIBLECHAR}, - {IDM_VIEW_INDENT_GUIDE, IDI_VIEW_INDENT_OFF_ICON, IDI_VIEW_INDENT_ON_ICON, IDI_VIEW_INDENT_OFF_ICON, IDR_INDENTGUIDE}, - {IDM_VIEW_USER_DLG, IDI_VIEW_UD_DLG_OFF_ICON, IDI_VIEW_UD_DLG_ON_ICON, IDI_VIEW_UD_DLG_OFF_ICON, IDR_SHOWPANNEL}, - - //-------------------------------------------------------------------------------------// - {0, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON, IDI_SEPARATOR_ICON}, - //-------------------------------------------------------------------------------------// - - {IDM_MACRO_STARTRECORDINGMACRO, IDI_STARTRECORD_OFF_ICON, IDI_STARTRECORD_ON_ICON, IDI_STARTRECORD_DISABLE_ICON, IDR_STARTRECORD}, - {IDM_MACRO_STOPRECORDINGMACRO, IDI_STOPRECORD_OFF_ICON, IDI_STOPRECORD_ON_ICON, IDI_STOPRECORD_DISABLE_ICON, IDR_STOPRECORD}, - {IDM_MACRO_PLAYBACKRECORDEDMACRO, IDI_PLAYRECORD_OFF_ICON, IDI_PLAYRECORD_ON_ICON, IDI_PLAYRECORD_DISABLE_ICON, IDR_PLAYRECORD}, - {IDM_MACRO_RUNMULTIMACRODLG, IDI_MMPLAY_OFF_ICON, IDI_MMPLAY_ON_ICON, IDI_MMPLAY_DIS_ICON, IDR_M_PLAYRECORD}, - {IDM_MACRO_SAVECURRENTMACRO, IDI_SAVERECORD_OFF_ICON, IDI_SAVERECORD_ON_ICON, IDI_SAVERECORD_DISABLE_ICON, IDR_SAVERECORD} - -}; - - - -LRESULT CALLBACK Notepad_plus::Notepad_plus_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) +LRESULT CALLBACK Notepad_plus_Window::Notepad_plus_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { - - static bool isFirstGetMinMaxInfoMsg = true; - - switch(Message) - { - case WM_NCCREATE : // First message we get the ptr of instantiated object - // then stock it into GWL_USERDATA index in order to retrieve afterward + switch(Message) { - Notepad_plus *pM30ide = (Notepad_plus *)(((LPCREATESTRUCT)lParam)->lpCreateParams); - pM30ide->_hSelf = hwnd; - ::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pM30ide); + case WM_NCCREATE : // First message we get the ptr of instantiated object + // then stock it into GWL_USERDATA index in order to retrieve afterward + { + Notepad_plus_Window *pM30ide = (Notepad_plus_Window *)(((LPCREATESTRUCT)lParam)->lpCreateParams); + pM30ide->_hSelf = hwnd; + ::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pM30ide); - return TRUE; + return TRUE; + } + + default : + { + return ((Notepad_plus_Window *)::GetWindowLongPtr(hwnd, GWL_USERDATA))->runProc(hwnd, Message, wParam, lParam); + } } +} - default : - { - return ((Notepad_plus *)::GetWindowLongPtr(hwnd, GWL_USERDATA))->runProc(hwnd, Message, wParam, lParam); - } - } +LRESULT Notepad_plus_Window::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) +{ + LRESULT result = FALSE; + switch (Message) + { + case WM_CREATE: + { + _notepad_plus_plus_core._pPublicInterface = this; + result = _notepad_plus_plus_core.init(hwnd); + } + break; + default: + if (this) + return _notepad_plus_plus_core.process(hwnd, Message, wParam, lParam); + } + return result; } - -LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) +LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) { LRESULT result = FALSE; @@ -144,434 +93,6 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa ::SendMessage(_dockingManager.getHSelf(), WM_NCACTIVATE, wParam, (LPARAM)-1); return ::DefWindowProc(hwnd, Message, wParam, lParam); } - case WM_CREATE: - { - NppGUI & nppGUI = (NppGUI &)pNppParam->getNppGUI(); - - // Menu - _mainMenuHandle = ::GetMenu(hwnd); - int langPos2BeRemoved = MENUINDEX_LANGUAGE+1; - if (nppGUI._isLangMenuCompact) - langPos2BeRemoved = MENUINDEX_LANGUAGE; - ::RemoveMenu(_mainMenuHandle, langPos2BeRemoved, MF_BYPOSITION); - - //Views - _pDocTab = &_mainDocTab; - _pEditView = &_mainEditView; - _pNonDocTab = &_subDocTab; - _pNonEditView = &_subEditView; - - _mainEditView.init(_hInst, hwnd); - _subEditView.init(_hInst, hwnd); - - _fileEditView.init(_hInst, hwnd); - MainFileManager->init(this, &_fileEditView); //get it up and running asap. - - pNppParam->setFontList(hwnd); - - - _mainWindowStatus = WindowMainActive; - _activeView = MAIN_VIEW; - - const ScintillaViewParams & svp1 = pNppParam->getSVP(SCIV_PRIMARY); - const ScintillaViewParams & svp2 = pNppParam->getSVP(SCIV_SECOND); - - int tabBarStatus = nppGUI._tabStatus; - _toReduceTabBar = ((tabBarStatus & TAB_REDUCE) != 0); - _docTabIconList.create(_toReduceTabBar?13:20, _hInst, docTabIconIDs, sizeof(docTabIconIDs)/sizeof(int)); - - _mainDocTab.init(_hInst, hwnd, &_mainEditView, &_docTabIconList); - _subDocTab.init(_hInst, hwnd, &_subEditView, &_docTabIconList); - - _mainEditView.display(); - - _invisibleEditView.init(_hInst, hwnd); - _invisibleEditView.execute(SCI_SETUNDOCOLLECTION); - _invisibleEditView.execute(SCI_EMPTYUNDOBUFFER); - _invisibleEditView.wrap(false); // Make sure no slow down - - // Configuration of 2 scintilla views - _mainEditView.showMargin(ScintillaEditView::_SC_MARGE_LINENUMBER, svp1._lineNumberMarginShow); - _subEditView.showMargin(ScintillaEditView::_SC_MARGE_LINENUMBER, svp2._lineNumberMarginShow); - _mainEditView.showMargin(ScintillaEditView::_SC_MARGE_SYBOLE, svp1._bookMarkMarginShow); - _subEditView.showMargin(ScintillaEditView::_SC_MARGE_SYBOLE, svp2._bookMarkMarginShow); - - _mainEditView.showIndentGuideLine(svp1._indentGuideLineShow); - _subEditView.showIndentGuideLine(svp2._indentGuideLineShow); - - ::SendMessage(hwnd, NPPM_INTERNAL_SETCARETWIDTH, 0, 0); - ::SendMessage(hwnd, NPPM_INTERNAL_SETCARETBLINKRATE, 0, 0); - - _configStyleDlg.init(_hInst, hwnd); - _preference.init(_hInst, hwnd); - - //Marker Margin config - _mainEditView.setMakerStyle(svp1._folderStyle); - _subEditView.setMakerStyle(svp2._folderStyle); - - _mainEditView.execute(SCI_SETCARETLINEVISIBLE, svp1._currentLineHilitingShow); - _subEditView.execute(SCI_SETCARETLINEVISIBLE, svp2._currentLineHilitingShow); - - _mainEditView.execute(SCI_SETCARETLINEVISIBLEALWAYS, true); - _subEditView.execute(SCI_SETCARETLINEVISIBLEALWAYS, true); - - _mainEditView.wrap(svp1._doWrap); - _subEditView.wrap(svp2._doWrap); - - _mainEditView.execute(SCI_SETEDGECOLUMN, svp1._edgeNbColumn); - _mainEditView.execute(SCI_SETEDGEMODE, svp1._edgeMode); - _subEditView.execute(SCI_SETEDGECOLUMN, svp2._edgeNbColumn); - _subEditView.execute(SCI_SETEDGEMODE, svp2._edgeMode); - - _mainEditView.showEOL(svp1._eolShow); - _subEditView.showEOL(svp2._eolShow); - - _mainEditView.showWSAndTab(svp1._whiteSpaceShow); - _subEditView.showWSAndTab(svp2._whiteSpaceShow); - - _mainEditView.showWrapSymbol(svp1._wrapSymbolShow); - _subEditView.showWrapSymbol(svp2._wrapSymbolShow); - - _mainEditView.performGlobalStyles(); - _subEditView.performGlobalStyles(); - - _zoomOriginalValue = _pEditView->execute(SCI_GETZOOM); - _mainEditView.execute(SCI_SETZOOM, svp1._zoom); - _subEditView.execute(SCI_SETZOOM, svp2._zoom); - - ::SendMessage(hwnd, NPPM_INTERNAL_SETMULTISELCTION, 0, 0); - - _mainEditView.execute(SCI_SETADDITIONALSELECTIONTYPING, true); - _subEditView.execute(SCI_SETADDITIONALSELECTIONTYPING, true); - - _mainEditView.execute(SCI_SETVIRTUALSPACEOPTIONS, SCVS_RECTANGULARSELECTION); - _subEditView.execute(SCI_SETVIRTUALSPACEOPTIONS, SCVS_RECTANGULARSELECTION); - - TabBarPlus::doDragNDrop(true); - - if (_toReduceTabBar) - { - HFONT hf = (HFONT)::GetStockObject(DEFAULT_GUI_FONT); - - if (hf) - { - ::SendMessage(_mainDocTab.getHSelf(), WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE, 0)); - ::SendMessage(_subDocTab.getHSelf(), WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE, 0)); - } - TabCtrl_SetItemSize(_mainDocTab.getHSelf(), 45, 20); - TabCtrl_SetItemSize(_subDocTab.getHSelf(), 45, 20); - } - _mainDocTab.display(); - - - TabBarPlus::doDragNDrop((tabBarStatus & TAB_DRAGNDROP) != 0); - TabBarPlus::setDrawTopBar((tabBarStatus & TAB_DRAWTOPBAR) != 0); - TabBarPlus::setDrawInactiveTab((tabBarStatus & TAB_DRAWINACTIVETAB) != 0); - TabBarPlus::setDrawTabCloseButton((tabBarStatus & TAB_CLOSEBUTTON) != 0); - TabBarPlus::setDbClk2Close((tabBarStatus & TAB_DBCLK2CLOSE) != 0); - TabBarPlus::setVertical((tabBarStatus & TAB_VERTICAL) != 0); - drawTabbarColoursFromStylerArray(); - - //--Splitter Section--// - bool isVertical = (nppGUI._splitterPos == POS_VERTICAL); - - _subSplitter.init(_hInst, hwnd); - _subSplitter.create(&_mainDocTab, &_subDocTab, 8, DYNAMIC, 50, isVertical); - - //--Status Bar Section--// - bool willBeShown = nppGUI._statusBarShow; - _statusBar.init(_hInst, hwnd, 6); - _statusBar.setPartWidth(STATUSBAR_DOC_SIZE, 250); - _statusBar.setPartWidth(STATUSBAR_CUR_POS, 300); - _statusBar.setPartWidth(STATUSBAR_EOF_FORMAT, 80); - _statusBar.setPartWidth(STATUSBAR_UNICODE_TYPE, 100); - _statusBar.setPartWidth(STATUSBAR_TYPING_MODE, 30); - _statusBar.display(willBeShown); - - _pMainWindow = &_mainDocTab; - - _dockingManager.init(_hInst, hwnd, &_pMainWindow); - - if (nppGUI._isMinimizedToTray && _pTrayIco == NULL) - _pTrayIco = new trayIconControler(hwnd, IDI_M30ICON, IDC_MINIMIZED_TRAY, ::LoadIcon(_hInst, MAKEINTRESOURCE(IDI_M30ICON)), TEXT("")); - - checkSyncState(); - - // Plugin Manager - NppData nppData; - nppData._nppHandle = hwnd; - nppData._scintillaMainHandle = _mainEditView.getHSelf(); - nppData._scintillaSecondHandle = _subEditView.getHSelf(); - - _scintillaCtrls4Plugins.init(_hInst, hwnd); - _pluginsManager.init(nppData); - _pluginsManager.loadPlugins(); - const TCHAR *appDataNpp = pNppParam->getAppDataNppDir(); - if (appDataNpp[0]) - _pluginsManager.loadPlugins(appDataNpp); - - _restoreButton.init(_hInst, hwnd); - - - // ------------ // - // Menu Section // - // ------------ // - - // Macro Menu - std::vector & macros = pNppParam->getMacroList(); - HMENU hMacroMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_MACRO); - size_t const posBase = 6; - size_t nbMacro = macros.size(); - if (nbMacro >= 1) - ::InsertMenu(hMacroMenu, posBase - 1, MF_BYPOSITION, (unsigned int)-1, 0); - for (size_t i = 0 ; i < nbMacro ; i++) - { - ::InsertMenu(hMacroMenu, posBase + i, MF_BYPOSITION, ID_MACRO + i, macros[i].toMenuItemString().c_str()); - } - // Run Menu - std::vector & userCommands = pNppParam->getUserCommandList(); - HMENU hRunMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_RUN); - int const runPosBase = 2; - size_t nbUserCommand = userCommands.size(); - if (nbUserCommand >= 1) - ::InsertMenu(hRunMenu, runPosBase - 1, MF_BYPOSITION, (unsigned int)-1, 0); - for (size_t i = 0 ; i < nbUserCommand ; i++) - { - ::InsertMenu(hRunMenu, runPosBase + i, MF_BYPOSITION, ID_USER_CMD + i, userCommands[i].toMenuItemString().c_str()); - } - - // Updater menu item - if (!nppGUI._doesExistUpdater) - { - //::MessageBox(NULL, TEXT("pas de updater"), TEXT(""), MB_OK); - ::DeleteMenu(_mainMenuHandle, IDM_UPDATE_NPP, MF_BYCOMMAND); - ::DrawMenuBar(hwnd); - } - //Languages Menu - HMENU hLangMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_LANGUAGE); - - // Add external languages to menu - for (int i = 0 ; i < pNppParam->getNbExternalLang() ; i++) - { - ExternalLangContainer & externalLangContainer = pNppParam->getELCFromIndex(i); - - int numLangs = ::GetMenuItemCount(hLangMenu); - const int bufferSize = 100; - TCHAR buffer[bufferSize]; - - int x; - for(x = 0; (x == 0 || lstrcmp(externalLangContainer._name, buffer) > 0) && x < numLangs; x++) - { - ::GetMenuString(hLangMenu, x, buffer, bufferSize, MF_BYPOSITION); - } - - ::InsertMenu(hLangMenu, x-1, MF_BYPOSITION, IDM_LANG_EXTERNAL + i, externalLangContainer._name); - } - - if (nppGUI._excludedLangList.size() > 0) - { - for (size_t i = 0 ; i < nppGUI._excludedLangList.size() ; i++) - { - int cmdID = pNppParam->langTypeToCommandID(nppGUI._excludedLangList[i]._langType); - const int itemSize = 256; - TCHAR itemName[itemSize]; - ::GetMenuString(hLangMenu, cmdID, itemName, itemSize, MF_BYCOMMAND); - nppGUI._excludedLangList[i]._cmdID = cmdID; - nppGUI._excludedLangList[i]._langName = itemName; - ::DeleteMenu(hLangMenu, cmdID, MF_BYCOMMAND); - DrawMenuBar(hwnd); - } - } - - // Add User Define Languages Entry - int udlpos = ::GetMenuItemCount(hLangMenu) - 1; - - for (int i = 0 ; i < pNppParam->getNbUserLang() ; i++) - { - UserLangContainer & userLangContainer = pNppParam->getULCFromIndex(i); - ::InsertMenu(hLangMenu, udlpos + i, MF_BYPOSITION, IDM_LANG_USER + i + 1, userLangContainer.getName()); - } - - //Add recent files - HMENU hFileMenu = ::GetSubMenu(_mainMenuHandle, MENUINDEX_FILE); - int nbLRFile = pNppParam->getNbLRFile(); - int pos = IDM_FILEMENU_LASTONE - IDM_FILE + 2; - - _lastRecentFileList.initMenu(hFileMenu, IDM_FILEMENU_LASTONE + 1, pos); - _lastRecentFileList.setLangEncoding(_nativeLangSpeaker.getLangEncoding()); - for (int i = 0 ; i < nbLRFile ; i++) - { - generic_string * stdStr = pNppParam->getLRFile(i); - if (!nppGUI._checkHistoryFiles || PathFileExists(stdStr->c_str())) - { - _lastRecentFileList.add(stdStr->c_str()); - } - } - - //Plugin menu - _pluginsManager.setMenu(_mainMenuHandle, NULL); - - //Main menu is loaded, now load context menu items - pNppParam->getContextMenuFromXmlTree(_mainMenuHandle); - - if (pNppParam->hasCustomContextMenu()) - { - _mainEditView.execute(SCI_USEPOPUP, FALSE); - _subEditView.execute(SCI_USEPOPUP, FALSE); - } - - generic_string pluginsTrans, windowTrans; - _nativeLangSpeaker.changeMenuLang(_mainMenuHandle, pluginsTrans, windowTrans); - ::DrawMenuBar(_hSelf); - - if (_pluginsManager.hasPlugins() && pluginsTrans != TEXT("")) - { - ::ModifyMenu(_mainMenuHandle, MENUINDEX_PLUGINS, MF_BYPOSITION, 0, pluginsTrans.c_str()); - } - //Windows menu - _windowsMenu.init(_hInst, _mainMenuHandle, windowTrans.c_str()); - - // Update context menu strings - vector & tmp = pNppParam->getContextMenuItems(); - size_t len = tmp.size(); - TCHAR menuName[64]; - for (size_t i = 0 ; i < len ; i++) - { - if (tmp[i]._itemName == TEXT("")) - { - ::GetMenuString(_mainMenuHandle, tmp[i]._cmdID, menuName, 64, MF_BYCOMMAND); - tmp[i]._itemName = purgeMenuItemString(menuName); - } - } - - //Input all the menu item names into shortcut list - //This will automatically do all translations, since menu translation has been done already - vector & shortcuts = pNppParam->getUserShortcuts(); - len = shortcuts.size(); - - for(size_t i = 0; i < len; i++) - { - CommandShortcut & csc = shortcuts[i]; - if (!csc.getName()[0]) - { //no predefined name, get name from menu and use that - ::GetMenuString(_mainMenuHandle, csc.getID(), menuName, 64, MF_BYCOMMAND); - csc.setName(purgeMenuItemString(menuName, true).c_str()); - } - } - //Translate non-menu shortcuts - _nativeLangSpeaker.changeShortcutLang(); - - //Update plugin shortcuts, all plugin commands should be available now - pNppParam->reloadPluginCmds(); - - // Shortcut Accelerator : should be the last one since it will capture all the shortcuts - _accelerator.init(_mainMenuHandle, hwnd); - pNppParam->setAccelerator(&_accelerator); - - // Scintilla key accelerator - vector scints; - scints.push_back(_mainEditView.getHSelf()); - scints.push_back(_subEditView.getHSelf()); - _scintaccelerator.init(&scints, _mainMenuHandle, hwnd); - - pNppParam->setScintillaAccelerator(&_scintaccelerator); - _scintaccelerator.updateKeys(); - - ::DrawMenuBar(hwnd); - - - //-- Tool Bar Section --// - toolBarStatusType tbStatus = nppGUI._toolBarStatus; - willBeShown = nppGUI._toolbarShow; - - // To notify plugins that toolbar icons can be registered - SCNotification scnN; - scnN.nmhdr.code = NPPN_TBMODIFICATION; - scnN.nmhdr.hwndFrom = hwnd; - scnN.nmhdr.idFrom = 0; - _pluginsManager.notify(&scnN); - - _toolBar.init(_hInst, hwnd, tbStatus, toolBarIcons, sizeof(toolBarIcons)/sizeof(ToolBarButtonUnit)); - - changeToolBarIcons(); - - _rebarTop.init(_hInst, hwnd); - _rebarBottom.init(_hInst, hwnd); - _toolBar.addToRebar(&_rebarTop); - _rebarTop.setIDVisible(REBAR_BAR_TOOLBAR, willBeShown); - - //--Init dialogs--// - _findReplaceDlg.init(_hInst, hwnd, &_pEditView); - _incrementFindDlg.init(_hInst, hwnd, &_findReplaceDlg, _nativeLangSpeaker.isRTL()); - _incrementFindDlg.addToRebar(&_rebarBottom); - _goToLineDlg.init(_hInst, hwnd, &_pEditView); - _colEditorDlg.init(_hInst, hwnd, &_pEditView); - _aboutDlg.init(_hInst, hwnd); - _runDlg.init(_hInst, hwnd); - _runMacroDlg.init(_hInst, hwnd); - - //--User Define Dialog Section--// - int uddStatus = nppGUI._userDefineDlgStatus; - UserDefineDialog *udd = _pEditView->getUserDefineDlg(); - - bool uddShow = false; - switch (uddStatus) - { - case UDD_SHOW : // show & undocked - udd->doDialog(true, _nativeLangSpeaker.isRTL()); - _nativeLangSpeaker.changeUserDefineLang(udd); - uddShow = true; - break; - case UDD_DOCKED : { // hide & docked - _isUDDocked = true; - break;} - case (UDD_SHOW | UDD_DOCKED) : // show & docked - udd->doDialog(true, _nativeLangSpeaker.isRTL()); - _nativeLangSpeaker.changeUserDefineLang(udd); - ::SendMessage(udd->getHSelf(), WM_COMMAND, IDC_DOCK_BUTTON, 0); - uddShow = true; - break; - - default : // hide & undocked - break; - } - // UserDefine Dialog - - checkMenuItem(IDM_VIEW_USER_DLG, uddShow); - _toolBar.setCheck(IDM_VIEW_USER_DLG, uddShow); - - //launch the plugin dlg memorized at the last session - DockingManagerData &dmd = nppGUI._dockingData; - - _dockingManager.setDockedContSize(CONT_LEFT , nppGUI._dockingData._leftWidth); - _dockingManager.setDockedContSize(CONT_RIGHT , nppGUI._dockingData._rightWidth); - _dockingManager.setDockedContSize(CONT_TOP , nppGUI._dockingData._topHeight); - _dockingManager.setDockedContSize(CONT_BOTTOM, nppGUI._dockingData._bottomHight); - - for (size_t i = 0 ; i < dmd._pluginDockInfo.size() ; i++) - { - PlugingDlgDockingInfo & pdi = dmd._pluginDockInfo[i]; - - if (pdi._isVisible) - _pluginsManager.runPluginCommand(pdi._name.c_str(), pdi._internalID); - } - - for (size_t i = 0 ; i < dmd._containerTabInfo.size() ; i++) - { - ContainerTabInfo & cti = dmd._containerTabInfo[i]; - _dockingManager.setActiveTab(cti._cont, cti._activeTab); - } - //Load initial docs into doctab - loadBufferIntoView(_mainEditView.getCurrentBufferID(), MAIN_VIEW); - loadBufferIntoView(_subEditView.getCurrentBufferID(), SUB_VIEW); - activateBuffer(_mainEditView.getCurrentBufferID(), MAIN_VIEW); - activateBuffer(_subEditView.getCurrentBufferID(), SUB_VIEW); - MainFileManager->increaseDocNr(); //so next doc starts at 2 - - ::SetFocus(_mainEditView.getHSelf()); - result = TRUE; - } - break; case WM_DRAWITEM : { @@ -858,7 +379,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa case WM_SIZE: { RECT rc; - getClientRect(rc); + _pPublicInterface->getClientRect(rc); if (lParam == 0) { lParam = MAKELPARAM(rc.right - rc.left, rc.bottom - rc.top); } @@ -1030,7 +551,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa { if (lstrlen(fileStr) >= int(wParam)) { - ::MessageBox(_hSelf, TEXT("Allocated buffer size is not enough to copy the string."), TEXT("NPPM error"), MB_OK); + ::MessageBox(_pPublicInterface->getHSelf(), TEXT("Allocated buffer size is not enough to copy the string."), TEXT("NPPM error"), MB_OK); return FALSE; } } @@ -1051,7 +572,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa { if (lstrlen(str) >= int(wParam)) //buffer too small { - ::MessageBox(_hSelf, TEXT("Allocated buffer size is not enough to copy the string."), TEXT("NPPM_GETCURRENTWORD error"), MB_OK); + ::MessageBox(_pPublicInterface->getHSelf(), TEXT("Allocated buffer size is not enough to copy the string."), TEXT("NPPM_GETCURRENTWORD error"), MB_OK); return FALSE; } else //buffer large enough, perform safe copy @@ -1079,7 +600,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa { if (lstrlen(str) >= int(wParam)) { - ::MessageBox(_hSelf, TEXT("Allocated buffer size is not enough to copy the string."), TEXT("NPPM_GETNPPDIRECTORY error"), MB_OK); + ::MessageBox(_pPublicInterface->getHSelf(), TEXT("Allocated buffer size is not enough to copy the string."), TEXT("NPPM_GETNPPDIRECTORY error"), MB_OK); return FALSE; } } @@ -1196,7 +717,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa pNppParam->_isTaskListRBUTTONUP_Active = true; short zDelta = (short) HIWORD(wParam); - return ::SendMessage(_hSelf, WM_COMMAND, zDelta>0?IDC_PREV_DOC:IDC_NEXT_DOC, 0); + return ::SendMessage(_pPublicInterface->getHSelf(), WM_COMMAND, zDelta>0?IDC_PREV_DOC:IDC_NEXT_DOC, 0); } return TRUE; } @@ -1359,7 +880,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa nmhdr.hwndFrom = (whichView == MAIN_VIEW)?_mainDocTab.getHSelf():_subDocTab.getHSelf(); nmhdr.idFrom = ::GetDlgCtrlID(nmhdr.hwndFrom); - ::SendMessage(_hSelf, WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr); + ::SendMessage(_pPublicInterface->getHSelf(), WM_NOTIFY, nmhdr.idFrom, (LPARAM)&nmhdr); } return TRUE; } @@ -1436,7 +957,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa for(;;) { for (Macro::iterator step = m.begin(); step != m.end(); step++) - step->PlayBack(this, _pEditView); + step->PlayBack(this->_pPublicInterface, _pEditView); counter++; if ( times >= 0 ) @@ -1474,7 +995,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa case NPPM_CREATESCINTILLAHANDLE : { - return (LRESULT)_scintillaCtrls4Plugins.createSintilla((lParam == NULL?_hSelf:(HWND)lParam)); + return (LRESULT)_scintillaCtrls4Plugins.createSintilla((lParam == NULL?_pPublicInterface->getHSelf():(HWND)lParam)); } case NPPM_DESTROYSCINTILLAHANDLE : @@ -1567,7 +1088,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa case NPPM_INTERNAL_CMDLIST_MODIFIED : { //changeMenuShortcut(lParam, (const TCHAR *)wParam); - ::DrawMenuBar(_hSelf); + ::DrawMenuBar(_pPublicInterface->getHSelf()); return TRUE; } @@ -1673,7 +1194,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa { isEnable.push_back((::GetMenuState(_mainMenuHandle, tmp[i]._cmdID, MF_BYCOMMAND)&MF_DISABLED) == 0); } - scintillaContextmenu.create(_hSelf, tmp); + scintillaContextmenu.create(_pPublicInterface->getHSelf(), tmp); for (size_t i = 0 ; i < isEnable.size() ; i++) scintillaContextmenu.enableItem(tmp[i]._cmdID, isEnable[i]); @@ -1786,7 +1307,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa // Notify plugins of update to styles xml SCNotification scnN; scnN.nmhdr.code = NPPN_WORDSTYLESUPDATED; - scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf(); scnN.nmhdr.idFrom = (uptr_t) _pEditView->getCurrentBufferID(); _pluginsManager.notify(&scnN); return TRUE; @@ -1795,9 +1316,9 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa case WM_QUERYENDSESSION: case WM_CLOSE: { - if (_isPrelaunch) + if (_pPublicInterface->isPrelaunch()) { - SendMessage(_hSelf, WM_SYSCOMMAND, SC_MINIMIZE, 0); + SendMessage(_pPublicInterface->getHSelf(), WM_SYSCOMMAND, SC_MINIMIZE, 0); } else { @@ -1836,7 +1357,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa SCNotification scnN; scnN.nmhdr.code = NPPN_SHUTDOWN; - scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf(); scnN.nmhdr.idFrom = 0; _pluginsManager.notify(&scnN); @@ -1861,17 +1382,17 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa { killAllChildren(); ::PostQuitMessage(0); - gNppHWND = NULL; + _pPublicInterface->gNppHWND = NULL; return TRUE; } case WM_SYSCOMMAND: { NppGUI & nppgui = (NppGUI &)(pNppParam->getNppGUI()); - if ((nppgui._isMinimizedToTray || _isPrelaunch) && (wParam == SC_MINIMIZE)) + if ((nppgui._isMinimizedToTray || _pPublicInterface->isPrelaunch()) && (wParam == SC_MINIMIZE)) { if (!_pTrayIco) - _pTrayIco = new trayIconControler(_hSelf, IDI_M30ICON, IDC_MINIMIZED_TRAY, ::LoadIcon(_hInst, MAKEINTRESOURCE(IDI_M30ICON)), TEXT("")); + _pTrayIco = new trayIconControler(_pPublicInterface->getHSelf(), IDI_M30ICON, IDC_MINIMIZED_TRAY, ::LoadIcon(_pPublicInterface->getHinst(), MAKEINTRESOURCE(IDI_M30ICON)), TEXT("")); _pTrayIco->doTrayIcon(ADD); ::ShowWindow(hwnd, SW_HIDE); @@ -1892,7 +1413,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa case WM_LBUTTONDBLCLK: { - ::SendMessage(_hSelf, WM_COMMAND, IDM_FILE_NEW, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_COMMAND, IDM_FILE_NEW, 0); return TRUE; } @@ -1903,10 +1424,10 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa //case WM_LBUTTONDBLCLK: case WM_LBUTTONUP : _pEditView->getFocus(); - ::ShowWindow(_hSelf, SW_SHOW); - if (!_isPrelaunch) + ::ShowWindow(_pPublicInterface->getHSelf(), SW_SHOW); + if (!_pPublicInterface->isPrelaunch()) _pTrayIco->doTrayIcon(REMOVE); - ::SendMessage(_hSelf, WM_SIZE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); return TRUE; case WM_MBUTTONUP: @@ -1920,11 +1441,11 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa HMENU hmenu; // menu template HMENU hTrayIconMenu; // shortcut menu - hmenu = ::LoadMenu(_hInst, MAKEINTRESOURCE(IDR_SYSTRAYPOPUP_MENU)); + hmenu = ::LoadMenu(_pPublicInterface->getHinst(), MAKEINTRESOURCE(IDR_SYSTRAYPOPUP_MENU)); hTrayIconMenu = ::GetSubMenu(hmenu, 0); - SetForegroundWindow(_hSelf); - TrackPopupMenu(hTrayIconMenu, TPM_LEFTALIGN, p.x, p.y, 0, _hSelf, NULL); - PostMessage(_hSelf, WM_NULL, 0, 0); + SetForegroundWindow(_pPublicInterface->getHSelf()); + TrackPopupMenu(hTrayIconMenu, TPM_LEFTALIGN, p.x, p.y, 0, _pPublicInterface->getHSelf(), NULL); + PostMessage(_pPublicInterface->getHSelf(), WM_NULL, 0, 0); DestroyMenu(hmenu); return TRUE; } @@ -2008,7 +1529,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa case NPPM_GETWINDOWSVERSION: { - return _winVersion; + return (NppParameters::getInstance())->getWinVersion(); } case NPPM_MAKECURRENTBUFFERDIRTY : @@ -2057,7 +1578,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa if (hide == oldVal) return oldVal; DocTabView::setHideTabBarStatus(hide); - ::SendMessage(_hSelf, WM_SIZE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); NppGUI & nppGUI = (NppGUI &)((NppParameters::getInstance())->getNppGUI()); if (hide) @@ -2089,22 +1610,22 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa case NPPM_HIDEMENU : { bool hide = (lParam == TRUE); - bool isHidden = ::GetMenu(_hSelf) == NULL; + bool isHidden = ::GetMenu(_pPublicInterface->getHSelf()) == NULL; if (hide == isHidden) return isHidden; NppGUI & nppGUI = (NppGUI &)pNppParam->getNppGUI(); nppGUI._menuBarShow = !hide; if (nppGUI._menuBarShow) - ::SetMenu(_hSelf, _mainMenuHandle); + ::SetMenu(_pPublicInterface->getHSelf(), _mainMenuHandle); else - ::SetMenu(_hSelf, NULL); + ::SetMenu(_pPublicInterface->getHSelf(), NULL); return isHidden; } case NPPM_ISMENUHIDDEN : { - return (::GetMenu(_hSelf) == NULL); + return (::GetMenu(_pPublicInterface->getHSelf()) == NULL); } case NPPM_HIDESTATUSBAR: @@ -2117,11 +1638,11 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa return oldVal; } RECT rc; - getClientRect(rc); + _pPublicInterface->getClientRect(rc); nppGUI._statusBarShow = show; _statusBar.display(nppGUI._statusBarShow); - ::SendMessage(_hSelf, WM_SIZE, SIZE_RESTORED, MAKELONG(rc.bottom, rc.right)); + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, SIZE_RESTORED, MAKELONG(rc.bottom, rc.right)); return oldVal; } @@ -2222,7 +1743,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa { NppGUI & nppgui = (NppGUI &)(pNppParam->getNppGUI()); if (!nppgui._menuBarShow && !wParam && !_sysMenuEntering) - ::SetMenu(_hSelf, _mainMenuHandle); + ::SetMenu(_pPublicInterface->getHSelf(), _mainMenuHandle); return TRUE; } @@ -2231,7 +1752,7 @@ LRESULT Notepad_plus::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa { NppGUI & nppgui = (NppGUI &)(pNppParam->getNppGUI()); if (!nppgui._menuBarShow && !wParam && !_sysMenuEntering) - ::SetMenu(_hSelf, NULL); + ::SetMenu(_pPublicInterface->getHSelf(), NULL); _sysMenuEntering = false; return FALSE; } diff --git a/PowerEditor/src/NppCommands.cpp b/PowerEditor/src/NppCommands.cpp index 0faf27d9..952cbd13 100644 --- a/PowerEditor/src/NppCommands.cpp +++ b/PowerEditor/src/NppCommands.cpp @@ -16,7 +16,7 @@ //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "precompiledHeaders.h" -#include "Notepad_plus.h" +#include "Notepad_plus_Window.h" #include "EncodingMapper.h" #include "ShortcutMapper.h" #include "TaskListDlg.h" @@ -91,7 +91,7 @@ void Notepad_plus::command(int id) break; case IDM_FILE_EXIT: - ::SendMessage(_hSelf, WM_CLOSE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_CLOSE, 0, 0); break; case IDM_EDIT_UNDO: @@ -165,7 +165,7 @@ void Notepad_plus::command(int id) _pEditView->execute(SCI_BEGINUNDOACTION); for (Macro::iterator step = _macro.begin(); step != _macro.end(); step++) - step->PlayBack(this, _pEditView); + step->PlayBack(this->_pPublicInterface, _pEditView); _pEditView->execute(SCI_ENDUNDOACTION); } @@ -237,7 +237,7 @@ void Notepad_plus::command(int id) case IDM_SEARCH_FINDINFILES : { - ::SendMessage(_hSelf, NPPM_LAUNCHFINDINFILESDLG, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), NPPM_LAUNCHFINDINFILESDLG, 0, 0); break; } case IDM_SEARCH_FINDINCREMENT : @@ -509,7 +509,7 @@ void Notepad_plus::command(int id) else _pMainWindow = _pDocTab; - ::SendMessage(_hSelf, WM_SIZE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); udd->display(false); _mainWindowStatus &= ~WindowUserActive; @@ -519,7 +519,7 @@ void Notepad_plus::command(int id) if (!_pMainSplitter) { _pMainSplitter = new SplitterContainer; - _pMainSplitter->init(_hInst, _hSelf); + _pMainSplitter->init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf()); Window *pWindow; if (bothActive()) @@ -534,7 +534,7 @@ void Notepad_plus::command(int id) _pMainSplitter->setWin0((bothActive())?(Window *)&_subSplitter:(Window *)_pDocTab); - ::SendMessage(_hSelf, WM_SIZE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); _pMainWindow->display(); _mainWindowStatus |= WindowUserActive; @@ -659,7 +659,7 @@ void Notepad_plus::command(int id) { int check = (::GetMenuState(_mainMenuHandle, id, MF_BYCOMMAND) == MF_CHECKED)?MF_UNCHECKED:MF_CHECKED; ::CheckMenuItem(_mainMenuHandle, id, MF_BYCOMMAND | check); - SetWindowPos(_hSelf, check == MF_CHECKED?HWND_TOPMOST:HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); + SetWindowPos(_pPublicInterface->getHSelf(), check == MF_CHECKED?HWND_TOPMOST:HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE); } break; @@ -757,13 +757,13 @@ void Notepad_plus::command(int id) ::SendMessage(_subDocTab.getHSelf(), WM_SETFONT, (WPARAM)hf, MAKELPARAM(TRUE, 0)); } - ::SendMessage(_hSelf, WM_SIZE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); break; } case IDM_VIEW_REFRESHTABAR : { - ::SendMessage(_hSelf, WM_SIZE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); break; } case IDM_VIEW_LOCKTABBAR: @@ -797,7 +797,7 @@ void Notepad_plus::command(int id) TabCtrl_SetItemSize(_mainDocTab.getHSelf(), 45, tabHeight); TabCtrl_SetItemSize(_subDocTab.getHSelf(), 45, tabHeight); } - ::SendMessage(_hSelf, WM_SIZE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); break; } @@ -810,14 +810,14 @@ void Notepad_plus::command(int id) case IDM_VIEW_DRAWTABBAR_VERTICAL : { TabBarPlus::setVertical(!TabBarPlus::isVertical()); - ::SendMessage(_hSelf, WM_SIZE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); break; } case IDM_VIEW_DRAWTABBAR_MULTILINE : { TabBarPlus::setMultiLine(!TabBarPlus::isMultiLine()); - ::SendMessage(_hSelf, WM_SIZE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); break; } @@ -1185,7 +1185,7 @@ void Notepad_plus::command(int id) if (um != uni8Bit) { - ::SendMessage(_hSelf, WM_COMMAND, idEncoding, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_COMMAND, idEncoding, 0); _pEditView->execute(SCI_EMPTYUNDOBUFFER); return; } @@ -1208,7 +1208,7 @@ void Notepad_plus::command(int id) if (um != uni8Bit) { - ::SendMessage(_hSelf, WM_COMMAND, idEncoding, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_COMMAND, idEncoding, 0); _pEditView->execute(SCI_EMPTYUNDOBUFFER); return; } @@ -1231,7 +1231,7 @@ void Notepad_plus::command(int id) if (um != uni8Bit) { - ::SendMessage(_hSelf, WM_COMMAND, idEncoding, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_COMMAND, idEncoding, 0); _pEditView->execute(SCI_EMPTYUNDOBUFFER); return; } @@ -1253,7 +1253,7 @@ void Notepad_plus::command(int id) return; if (um != uni8Bit) { - ::SendMessage(_hSelf, WM_COMMAND, idEncoding, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_COMMAND, idEncoding, 0); _pEditView->execute(SCI_EMPTYUNDOBUFFER); return; } @@ -1264,7 +1264,7 @@ void Notepad_plus::command(int id) if (idEncoding != -1) { // Save the current clipboard content - ::OpenClipboard(_hSelf); + ::OpenClipboard(_pPublicInterface->getHSelf()); HANDLE clipboardData = ::GetClipboardData(CF_TEXT); int len = ::GlobalSize(clipboardData); LPVOID clipboardDataPtr = ::GlobalLock(clipboardData); @@ -1286,14 +1286,14 @@ void Notepad_plus::command(int id) // Change to the proper buffer, save buffer status - ::SendMessage(_hSelf, WM_COMMAND, idEncoding, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_COMMAND, idEncoding, 0); // Paste the texte, restore buffer status _pEditView->execute(SCI_PASTE); _pEditView->restoreCurrentPos(); // Restore the previous clipboard data - ::OpenClipboard(_hSelf); + ::OpenClipboard(_pPublicInterface->getHSelf()); ::EmptyClipboard(); ::SetClipboardData(CF_TEXT, clipboardData2); ::CloseClipboard(); @@ -1393,10 +1393,10 @@ void Notepad_plus::command(int id) ValueDlg valDlg; NppGUI & nppGUI = (NppGUI &)((NppParameters::getInstance())->getNppGUI()); - valDlg.init(_hInst, _preference.getHSelf(), nppGUI._autocFromLen, TEXT("Nb char : ")); + valDlg.init(_pPublicInterface->getHinst(), _preference.getHSelf(), nppGUI._autocFromLen, TEXT("Nb char : ")); POINT p; ::GetCursorPos(&p); - ::ScreenToClient(_hParent, &p); + ::ScreenToClient(_pPublicInterface->getHParent(), &p); int size = valDlg.doDialog(p, _nativeLangSpeaker.isRTL()); if (size != -1) @@ -1415,10 +1415,10 @@ void Notepad_plus::command(int id) { ValueDlg nbHistoryDlg; NppParameters *pNppParam = NppParameters::getInstance(); - nbHistoryDlg.init(_hInst, _preference.getHSelf(), pNppParam->getNbMaxFile(), TEXT("Max File : ")); + nbHistoryDlg.init(_pPublicInterface->getHinst(), _preference.getHSelf(), pNppParam->getNbMaxFile(), TEXT("Max File : ")); POINT p; ::GetCursorPos(&p); - ::ScreenToClient(_hParent, &p); + ::ScreenToClient(_pPublicInterface->getHParent(), &p); int size = nbHistoryDlg.doDialog(p, _nativeLangSpeaker.isRTL()); if (size != -1) @@ -1450,7 +1450,7 @@ void Notepad_plus::command(int id) } if (!_pluginsManager.getMenuHandle()) _pluginsManager.setMenu(_mainMenuHandle, NULL); - ::DrawMenuBar(_hSelf); + ::DrawMenuBar(_pPublicInterface->getHSelf()); break; } @@ -1484,7 +1484,7 @@ void Notepad_plus::command(int id) case IDM_SETTING_SHORTCUT_MAPPER : { ShortcutMapper shortcutMapper; - shortcutMapper.init(_hInst, _hSelf); + shortcutMapper.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf()); _nativeLangSpeaker.changeShortcutmapperLang(&shortcutMapper); shortcutMapper.doDialog(_nativeLangSpeaker.isRTL()); shortcutMapper.destroy(); @@ -1572,7 +1572,7 @@ void Notepad_plus::command(int id) { generic_string msg = nppHelpPath; msg += TEXT("\rdoesn't exist. Please download it on Notepad++ site."); - ::MessageBox(_hSelf, msg.c_str(), TEXT("File does not exist"), MB_OK); + ::MessageBox(_pPublicInterface->getHSelf(), msg.c_str(), TEXT("File does not exist"), MB_OK); } } break; @@ -1721,7 +1721,7 @@ void Notepad_plus::command(int id) { TaskListDlg tld; HIMAGELIST hImgLst = _docTabIconList.getHandle(); - tld.init(_hInst, _hSelf, hImgLst, direction); + tld.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), hImgLst, direction); tld.doDialog(); } } @@ -1760,7 +1760,7 @@ void Notepad_plus::command(int id) case IDM_WINDOW_WINDOWS : { WindowsDlg _windowsDlg; - _windowsDlg.init(_hInst, _hSelf, _pDocTab); + _windowsDlg.init(_pPublicInterface->getHinst(), _pPublicInterface->getHSelf(), _pDocTab); const TiXmlNodeA *nativeLangA = _nativeLangSpeaker.getNativeLangA(); TiXmlNodeA *dlgNode = NULL; @@ -1778,7 +1778,7 @@ void Notepad_plus::command(int id) case IDM_SYSTRAYPOPUP_NEWDOC: { NppGUI & nppGUI = (NppGUI &)((NppParameters::getInstance())->getNppGUI()); - ::ShowWindow(_hSelf, nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW); + ::ShowWindow(_pPublicInterface->getHSelf(), nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW); fileNew(); } break; @@ -1786,14 +1786,14 @@ void Notepad_plus::command(int id) case IDM_SYSTRAYPOPUP_ACTIVATE : { NppGUI & nppGUI = (NppGUI &)((NppParameters::getInstance())->getNppGUI()); - ::ShowWindow(_hSelf, nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW); + ::ShowWindow(_pPublicInterface->getHSelf(), nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW); } break; case IDM_SYSTRAYPOPUP_NEW_AND_PASTE: { NppGUI & nppGUI = (NppGUI &)((NppParameters::getInstance())->getNppGUI()); - ::ShowWindow(_hSelf, nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW); + ::ShowWindow(_pPublicInterface->getHSelf(), nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW); BufferID bufferID = _pEditView->getCurrentBufferID(); Buffer * buf = MainFileManager->getBufferByID(bufferID); if (!buf->isUntitled() || buf->docLength() != 0) @@ -1807,17 +1807,17 @@ void Notepad_plus::command(int id) case IDM_SYSTRAYPOPUP_OPENFILE: { NppGUI & nppGUI = (NppGUI &)((NppParameters::getInstance())->getNppGUI()); - ::ShowWindow(_hSelf, nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW); + ::ShowWindow(_pPublicInterface->getHSelf(), nppGUI._isMaximized?SW_MAXIMIZE:SW_SHOW); fileOpen(); } break; case IDM_SYSTRAYPOPUP_CLOSE: { - _isPrelaunch = false; + _pPublicInterface->setIsPrelaunch(false); _pTrayIco->doTrayIcon(REMOVE); - if (!::IsWindowVisible(_hSelf)) - ::SendMessage(_hSelf, WM_CLOSE, 0,0); + if (!::IsWindowVisible(_pPublicInterface->getHSelf())) + ::SendMessage(_pPublicInterface->getHSelf(), WM_CLOSE, 0,0); } break; @@ -1847,7 +1847,7 @@ void Notepad_plus::command(int id) _pEditView->execute(SCI_BEGINUNDOACTION); for (Macro::iterator step = macro.begin(); step != macro.end(); step++) - step->PlayBack(this, _pEditView); + step->PlayBack(this->_pPublicInterface, _pEditView); _pEditView->execute(SCI_ENDUNDOACTION); @@ -1859,7 +1859,7 @@ void Notepad_plus::command(int id) UserCommand ucmd = theUserCommands[i]; Command cmd(ucmd.getCmd()); - cmd.run(_hSelf); + cmd.run(_pPublicInterface->getHSelf()); } else if ((id >= ID_PLUGINS_CMD) && (id < ID_PLUGINS_CMD_LIMIT)) { @@ -1870,7 +1870,7 @@ void Notepad_plus::command(int id) else if ((id >= ID_PLUGINS_REMOVING) && (id < ID_PLUGINS_REMOVING_END)) { int i = id - ID_PLUGINS_REMOVING; - _pluginsManager.unloadPlugin(i, _hSelf); + _pluginsManager.unloadPlugin(i, _pPublicInterface->getHSelf()); } */ else if ((id >= IDM_WINDOW_MRU_FIRST) && (id <= IDM_WINDOW_MRU_LIMIT)) diff --git a/PowerEditor/src/NppIO.cpp b/PowerEditor/src/NppIO.cpp index 5141834e..7d207c3c 100644 --- a/PowerEditor/src/NppIO.cpp +++ b/PowerEditor/src/NppIO.cpp @@ -16,7 +16,7 @@ //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "precompiledHeaders.h" -#include "Notepad_plus.h" +#include "Notepad_plus_Window.h" #include "FileDialog.h" @@ -51,10 +51,10 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encodi { if (_pTrayIco->isInTray()) { - ::ShowWindow(_hSelf, SW_SHOW); - if (!_isPrelaunch) + ::ShowWindow(_pPublicInterface->getHSelf(), SW_SHOW); + if (!_pPublicInterface->isPrelaunch()) _pTrayIco->doTrayIcon(REMOVE); - ::SendMessage(_hSelf, WM_SIZE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); } } return test; @@ -78,13 +78,13 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encodi { wsprintf(str2display, TEXT("%s doesn't exist. Create it?"), longFileName); - if (::MessageBox(_hSelf, str2display, TEXT("Create new file"), MB_YESNO) == IDYES) + if (::MessageBox(_pPublicInterface->getHSelf(), str2display, TEXT("Create new file"), MB_YESNO) == IDYES) { bool res = MainFileManager->createEmptyFile(longFileName); if (!res) { wsprintf(str2display, TEXT("Cannot create the file \"%s\""), longFileName); - ::MessageBox(_hSelf, str2display, TEXT("Create new file"), MB_OK); + ::MessageBox(_pPublicInterface->getHSelf(), str2display, TEXT("Create new file"), MB_OK); return BUFFER_INVALID; } } @@ -103,7 +103,7 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encodi // Plugins can should use this notification to filter SCN_MODIFIED SCNotification scnN; scnN.nmhdr.code = NPPN_FILEBEFORELOAD; - scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf(); scnN.nmhdr.idFrom = NULL; _pluginsManager.notify(&scnN); @@ -134,10 +134,10 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encodi { if (_pTrayIco->isInTray()) { - ::ShowWindow(_hSelf, SW_SHOW); - if (!_isPrelaunch) + ::ShowWindow(_pPublicInterface->getHSelf(), SW_SHOW); + if (!_pPublicInterface->isPrelaunch()) _pTrayIco->doTrayIcon(REMOVE); - ::SendMessage(_hSelf, WM_SIZE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); } } PathRemoveFileSpec(longFileName); @@ -156,7 +156,6 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encodi { if (::PathIsDirectory(fileName)) { - //::MessageBox(_hSelf, fileName, TEXT("Dir"), MB_OK); vector fileNames; vector patterns; patterns.push_back(TEXT("*.*")); @@ -168,7 +167,6 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encodi getMatchedFileNames(fileNameStr.c_str(), patterns, fileNames, true, false); for (size_t i = 0 ; i < fileNames.size() ; i++) { - //::MessageBox(_hSelf, fileNames[i].c_str(), TEXT("Dir"), MB_OK); doOpen(fileNames[i].c_str()); } } @@ -177,7 +175,7 @@ BufferID Notepad_plus::doOpen(const TCHAR *fileName, bool isReadOnly, int encodi generic_string msg = TEXT("Can not open file \""); msg += longFileName; msg += TEXT("\"."); - ::MessageBox(_hSelf, msg.c_str(), TEXT("ERR"), MB_OK); + ::MessageBox(_pPublicInterface->getHSelf(), msg.c_str(), TEXT("ERR"), MB_OK); _isFileOpening = false; scnN.nmhdr.code = NPPN_FILELOADFAILED; @@ -198,7 +196,7 @@ bool Notepad_plus::doReload(BufferID id, bool alert) */ if (alert) { - if (::MessageBox(_hSelf, TEXT("Are you sure you want to reload the current file and lose the changes made in Notepad++?"), TEXT("Reload"), MB_YESNO | MB_ICONEXCLAMATION | MB_APPLMODAL) != IDYES) + if (::MessageBox(_pPublicInterface->getHSelf(), TEXT("Are you sure you want to reload the current file and lose the changes made in Notepad++?"), TEXT("Reload"), MB_YESNO | MB_ICONEXCLAMATION | MB_APPLMODAL) != IDYES) return false; } @@ -240,7 +238,7 @@ bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy) { scnN.nmhdr.code = NPPN_FILEBEFORESAVE; - scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf(); scnN.nmhdr.idFrom = (uptr_t)id; _pluginsManager.notify(&scnN); } @@ -254,7 +252,7 @@ bool Notepad_plus::doSave(BufferID id, const TCHAR * filename, bool isCopy) } if (!res) - ::MessageBox(_hSelf, TEXT("Please check whether if this file is opened in another program"), TEXT("Save failed"), MB_OK); + ::MessageBox(_pPublicInterface->getHSelf(), TEXT("Please check whether if this file is opened in another program"), TEXT("Save failed"), MB_OK); return res; } @@ -264,7 +262,7 @@ void Notepad_plus::doClose(BufferID id, int whichOne) { // Notify plugins that current file is about to be closed SCNotification scnN; scnN.nmhdr.code = NPPN_FILEBEFORECLOSE; - scnN.nmhdr.hwndFrom = _hSelf; + scnN.nmhdr.hwndFrom = _pPublicInterface->getHSelf(); scnN.nmhdr.idFrom = (uptr_t)id; _pluginsManager.notify(&scnN); @@ -728,7 +726,7 @@ bool Notepad_plus::fileSaveAs(BufferID id, bool isSaveCopy) bufferID = _pEditView->getCurrentBufferID(); Buffer * buf = MainFileManager->getBufferByID(bufferID); - FileDialog fDlg(_hSelf, _hInst); + FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst()); fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); int langTypeIndex = setFileOpenSaveDlgFilters(fDlg, buf->getLangType()); @@ -749,7 +747,7 @@ bool Notepad_plus::fileSaveAs(BufferID id, bool isSaveCopy) } else //cannot save, other view has buffer already open, activate it { - ::MessageBox(_hSelf, TEXT("The file is already opened in the Notepad++."), TEXT("ERROR"), MB_OK | MB_ICONSTOP); + ::MessageBox(_pPublicInterface->getHSelf(), TEXT("The file is already opened in the Notepad++."), TEXT("ERROR"), MB_OK | MB_ICONSTOP); switchToFile(other); return false; } @@ -768,7 +766,7 @@ bool Notepad_plus::fileRename(BufferID id) bufferID = _pEditView->getCurrentBufferID(); Buffer * buf = MainFileManager->getBufferByID(bufferID); - FileDialog fDlg(_hSelf, _hInst); + FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst()); fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); setFileOpenSaveDlgFilters(fDlg); @@ -797,7 +795,7 @@ bool Notepad_plus::fileDelete(BufferID id) { if (!MainFileManager->deleteFile(bufferID)) { - ::MessageBox(_hSelf, TEXT("Delete File failed"), TEXT("Delete File"), MB_OK); + ::MessageBox(_pPublicInterface->getHSelf(), TEXT("Delete File failed"), TEXT("Delete File"), MB_OK); return false; } doClose(bufferID, MAIN_VIEW); @@ -809,7 +807,7 @@ bool Notepad_plus::fileDelete(BufferID id) void Notepad_plus::fileOpen() { - FileDialog fDlg(_hSelf, _hInst); + FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst()); fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); setFileOpenSaveDlgFilters(fDlg); @@ -1004,7 +1002,7 @@ bool Notepad_plus::fileLoadSession(const TCHAR *fn) const TCHAR *sessionFileName = NULL; if (fn == NULL) { - FileDialog fDlg(_hSelf, _hInst); + FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst()); fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); const TCHAR *ext = NppParameters::getInstance()->getNppGUI()._definedSessionExt.c_str(); generic_string sessionExt = TEXT(""); @@ -1065,7 +1063,7 @@ const TCHAR * Notepad_plus::fileSaveSession(size_t nbFile, TCHAR ** fileNames) { const TCHAR *sessionFileName = NULL; - FileDialog fDlg(_hSelf, _hInst); + FileDialog fDlg(_pPublicInterface->getHSelf(), _pPublicInterface->getHinst()); const TCHAR *ext = NppParameters::getInstance()->getNppGUI()._definedSessionExt.c_str(); fDlg.setExtFilter(TEXT("All types"), TEXT(".*"), NULL); diff --git a/PowerEditor/src/NppNotification.cpp b/PowerEditor/src/NppNotification.cpp index d243433d..1f34960f 100644 --- a/PowerEditor/src/NppNotification.cpp +++ b/PowerEditor/src/NppNotification.cpp @@ -16,7 +16,7 @@ //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "precompiledHeaders.h" -#include "Notepad_plus.h" +#include "Notepad_plus_Window.h" #include "xmlMatchedTagsHighlighter.h" BOOL Notepad_plus::notify(SCNotification *notification) @@ -246,7 +246,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) vector itemUnitArray; itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_GOTO_ANOTHER_VIEW, goToView)); itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_CLONE_TO_ANOTHER_VIEW, cloneToView)); - _tabPopupDropMenu.create(_hSelf, itemUnitArray); + _tabPopupDropMenu.create(_pPublicInterface->getHSelf(), itemUnitArray); _nativeLangSpeaker.changeLangTabDrapContextMenu(_tabPopupDropMenu.getMenuHandle()); } _tabPopupDropMenu.display(p); @@ -260,7 +260,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) else { RECT nppZone; - ::GetWindowRect(_hSelf, &nppZone); + ::GetWindowRect(_pPublicInterface->getHSelf(), &nppZone); bool isInNppZone = (((p.x >= nppZone.left) && (p.x <= nppZone.right)) && (p.y >= nppZone.top) && (p.y <= nppZone.bottom)); if (isInNppZone) { @@ -278,7 +278,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) HWND hWinParent = ::GetParent(hWin); TCHAR className[MAX_PATH]; ::GetClassName(hWinParent,className, sizeof(className)); - if (lstrcmp(className, _className) == 0 && hWinParent != _hSelf) // another Notepad++ + if (lstrcmp(className, _pPublicInterface->getClassName()) == 0 && hWinParent != _pPublicInterface->getHSelf()) // another Notepad++ { int index = _pDocTab->getCurrentTabIndex(); BufferID bufferToClose = notifyDocTab->getBufferByIndex(index); @@ -286,17 +286,17 @@ BOOL Notepad_plus::notify(SCNotification *notification) int iView = isFromPrimary?MAIN_VIEW:SUB_VIEW; if (buf->isDirty()) { - ::MessageBox(_hSelf, TEXT("Document is modified, save it then try again."), TEXT("Move to new Notepad++ Instance"), MB_OK); + ::MessageBox(_pPublicInterface->getHSelf(), TEXT("Document is modified, save it then try again."), TEXT("Move to new Notepad++ Instance"), MB_OK); } else { ::SendMessage(hWinParent, NPPM_INTERNAL_SWITCHVIEWFROMHWND, 0, (LPARAM)hWin); - ::SendMessage(hWinParent, WM_COPYDATA, (WPARAM)_hInst, (LPARAM)&fileNamesData); + ::SendMessage(hWinParent, WM_COPYDATA, (WPARAM)_pPublicInterface->getHinst(), (LPARAM)&fileNamesData); if (!isInCtrlStat) { fileClose(bufferToClose, iView); if (noOpenedDoc()) - ::SendMessage(_hSelf, WM_CLOSE, 0, 0); + ::SendMessage(_pPublicInterface->getHSelf(), WM_CLOSE, 0, 0); } } } @@ -436,7 +436,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_GOTO_NEW_INSTANCE, TEXT("Move to New Instance"))); itemUnitArray.push_back(MenuItemUnit(IDM_VIEW_LOAD_IN_NEW_INSTANCE, TEXT("Open in New Instance"))); - _tabPopupMenu.create(_hSelf, itemUnitArray); + _tabPopupMenu.create(_pPublicInterface->getHSelf(), itemUnitArray); _nativeLangSpeaker.changeLangTabContextMenu(_tabPopupMenu.getMenuHandle()); } @@ -561,8 +561,8 @@ BOOL Notepad_plus::notify(SCNotification *notification) POINT p; ::GetCursorPos(&p); - ::ScreenToClient(_hSelf, &p); - HWND hWin = ::RealChildWindowFromPoint(_hSelf, p); + ::ScreenToClient(_pPublicInterface->getHSelf(), &p); + HWND hWin = ::RealChildWindowFromPoint(_pPublicInterface->getHSelf(), p); const int tipMaxLen = 1024; static TCHAR docTip[tipMaxLen]; docTip[0] = '\0'; @@ -662,7 +662,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) TCHAR currentWord[MAX_PATH*2]; notifyView->getGenericText(currentWord, startPos, endPos); - ::ShellExecute(_hSelf, TEXT("open"), currentWord, NULL, NULL, SW_SHOW); + ::ShellExecute(_pPublicInterface->getHSelf(), TEXT("open"), currentWord, NULL, NULL, SW_SHOW); _isHotspotDblClicked = true; notifyView->execute(SCI_SETCHARSDEFAULT); break; @@ -689,7 +689,7 @@ BOOL Notepad_plus::notify(SCNotification *notification) case RBN_HEIGHTCHANGE: { - SendMessage(_hSelf, WM_SIZE, 0, 0); + SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); break; } case RBN_CHEVRONPUSHED: diff --git a/PowerEditor/src/ScitillaComponent/Buffer.h b/PowerEditor/src/ScitillaComponent/Buffer.h index 0a89ac66..7b6cecc5 100644 --- a/PowerEditor/src/ScitillaComponent/Buffer.h +++ b/PowerEditor/src/ScitillaComponent/Buffer.h @@ -31,7 +31,7 @@ typedef sptr_t Document; enum DocFileStatus{ DOC_REGULAR = 0x01, //should not be combined with anything DOC_UNNAMED = 0x02, //not saved (new ##) - DOC_DELETED = 0x04, //doesnt exist in environment anymore, but not DOC_UNNAMED + DOC_DELETED = 0x04, //doesn't exist in environment anymore, but not DOC_UNNAMED DOC_MODIFIED = 0x08 //File in environment has changed }; diff --git a/PowerEditor/src/WinControls/shortcut/shortcut.cpp b/PowerEditor/src/WinControls/shortcut/shortcut.cpp index 7d73055f..b50da67c 100644 --- a/PowerEditor/src/WinControls/shortcut/shortcut.cpp +++ b/PowerEditor/src/WinControls/shortcut/shortcut.cpp @@ -21,7 +21,7 @@ #include "Parameters.h" #include "ScintillaEditView.h" #include "resource.h" -#include "Notepad_plus.h" +#include "Notepad_plus_Window.h" #include "keys.h" const int KEY_STR_LEN = 16; @@ -310,7 +310,7 @@ void getNameStrFromCmd(DWORD cmd, generic_string & str) } else { - HWND hNotepad_plus = ::FindWindow(Notepad_plus::getClassName(), NULL); + HWND hNotepad_plus = ::FindWindow(Notepad_plus_Window::getClassName(), NULL); const int commandSize = 64; TCHAR cmdName[commandSize]; int nbChar = ::GetMenuString((HMENU)::SendMessage(hNotepad_plus, NPPM_INTERNAL_GETMENU, 0, 0), cmd, cmdName, commandSize, MF_BYCOMMAND); diff --git a/PowerEditor/src/winmain.cpp b/PowerEditor/src/winmain.cpp index 62c00237..3862703e 100644 --- a/PowerEditor/src/winmain.cpp +++ b/PowerEditor/src/winmain.cpp @@ -16,7 +16,7 @@ //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #include "precompiledHeaders.h" -#include "Notepad_plus.h" +#include "Notepad_plus_Window.h" #include "Process.h" #include "Win32Exception.h" //Win32 exception @@ -174,7 +174,7 @@ notepad++ [--help] [-multiInst] [-noPlugins] [-lLanguage] [-nLineNumber] [-cColu fullFilePathName : file name to open (absolute or relative path name)\r\ "); -void doException(Notepad_plus & notepad_plus_plus); +void doException(Notepad_plus_Window & notepad_plus_plus); int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) { @@ -250,11 +250,11 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) if ((!isMultiInst) && (!TheFirstOne)) { - HWND hNotepad_plus = ::FindWindow(Notepad_plus::getClassName(), NULL); + HWND hNotepad_plus = ::FindWindow(Notepad_plus_Window::getClassName(), NULL); for (int i = 0 ;!hNotepad_plus && i < 5 ; i++) { Sleep(100); - hNotepad_plus = ::FindWindow(Notepad_plus::getClassName(), NULL); + hNotepad_plus = ::FindWindow(Notepad_plus_Window::getClassName(), NULL); } if (hNotepad_plus) @@ -297,7 +297,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) } pNppParameters->load(); - Notepad_plus notepad_plus_plus; + Notepad_plus_Window notepad_plus_plus; NppGUI & nppGui = (NppGUI &)pNppParameters->getNppGUI(); @@ -309,7 +309,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) generic_string version = TEXT("-v"); version += VERSION_VALUE; - winVer curWinVer = notepad_plus_plus.getWinVersion(); + winVer curWinVer = pNppParameters->getWinVersion(); bool isUpExist = nppGui._doesExistUpdater = (::PathFileExists(updaterFullPath.c_str()) == TRUE); bool winSupported = (curWinVer >= WV_W2K); @@ -345,7 +345,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) Win32Exception::installHandler(); try { notepad_plus_plus.init(hInstance, NULL, quotFileName.c_str(), &cmdLineParams); - bool unicodeSupported = notepad_plus_plus.getWinVersion() >= WV_NT; + bool unicodeSupported = pNppParameters->getWinVersion() >= WV_NT; bool going = true; while (going) { @@ -362,7 +362,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) ::DispatchMessageW(&msg); else ::DispatchMessage(&msg); - } + } } } } @@ -373,7 +373,7 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) TCHAR str[50] = TEXT("God Damned Exception : "); TCHAR code[10]; wsprintf(code, TEXT("%d"), i); - ::MessageBox(Notepad_plus::gNppHWND, lstrcat(str, code), TEXT("Notepad++ Exception"), MB_OK); + ::MessageBox(Notepad_plus_Window::gNppHWND, lstrcat(str, code), TEXT("Notepad++ Exception"), MB_OK); doException(notepad_plus_plus); } } catch (const Win32Exception & ex) { @@ -385,13 +385,13 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) TEXT("Code:\t0x%08X\r\nType:\t%s\r\nException address: 0x%08X"), #endif ex.code(), ex.what(), ex.where()); - ::MessageBox(Notepad_plus::gNppHWND, message, TEXT("Win32Exception"), MB_OK | MB_ICONERROR); + ::MessageBox(Notepad_plus_Window::gNppHWND, message, TEXT("Win32Exception"), MB_OK | MB_ICONERROR); mdump.writeDump(ex.info()); doException(notepad_plus_plus); } catch(std::exception ex) { #ifdef UNICODE const wchar_t * text = WcharMbcsConvertor::getInstance()->char2wchar(ex.what(), CP_ACP); - ::MessageBox(Notepad_plus::gNppHWND, text, TEXT("C++ Exception"), MB_OK); + ::MessageBox(Notepad_plus_Window::gNppHWND, text, TEXT("C++ Exception"), MB_OK); #else ::MessageBox(Notepad_plus::gNppHWND, ex.what(), TEXT("C++ Exception"), MB_OK); #endif @@ -403,9 +403,9 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int) return (UINT)msg.wParam; } -void doException(Notepad_plus & notepad_plus_plus) { +void doException(Notepad_plus_Window & notepad_plus_plus) { Win32Exception::removeHandler(); //disable exception handler after excpetion, we dont want corrupt data structurs to crash the exception handler - ::MessageBox(Notepad_plus::gNppHWND, TEXT("Notepad++ will attempt to save any unsaved data. However, dataloss is very likely."), TEXT("Recovery initiating"), MB_OK | MB_ICONINFORMATION); + ::MessageBox(Notepad_plus_Window::gNppHWND, TEXT("Notepad++ will attempt to save any unsaved data. However, dataloss is very likely."), TEXT("Recovery initiating"), MB_OK | MB_ICONINFORMATION); TCHAR tmpDir[1024]; GetTempPath(1024, tmpDir); @@ -416,8 +416,8 @@ void doException(Notepad_plus & notepad_plus_plus) { if (res) { generic_string displayText = TEXT("Notepad++ was able to successfully recover some unsaved documents, or nothing to be saved could be found.\r\nYou can find the results at :\r\n"); displayText += emergencySavedDir; - ::MessageBox(Notepad_plus::gNppHWND, displayText.c_str(), TEXT("Recovery success"), MB_OK | MB_ICONINFORMATION); + ::MessageBox(Notepad_plus_Window::gNppHWND, displayText.c_str(), TEXT("Recovery success"), MB_OK | MB_ICONINFORMATION); } else { - ::MessageBox(Notepad_plus::gNppHWND, TEXT("Unfortunatly, Notepad++ was not able to save your work. We are sorry for any lost data."), TEXT("Recovery failure"), MB_OK | MB_ICONERROR); + ::MessageBox(Notepad_plus_Window::gNppHWND, TEXT("Unfortunatly, Notepad++ was not able to save your work. We are sorry for any lost data."), TEXT("Recovery failure"), MB_OK | MB_ICONERROR); } } diff --git a/PowerEditor/visual.net/notepadPlus.vcproj b/PowerEditor/visual.net/notepadPlus.vcproj index 158f8f74..20d52b08 100644 --- a/PowerEditor/visual.net/notepadPlus.vcproj +++ b/PowerEditor/visual.net/notepadPlus.vcproj @@ -502,6 +502,10 @@ RelativePath="..\src\Notepad_plus.cpp" > + + @@ -839,6 +843,10 @@ RelativePath="..\src\Misc\PluginsManager\Notepad_plus_msgs.h" > + +