2012-04-15 16:54:38 +00:00
|
|
|
// This file is part of Notepad++ project
|
|
|
|
// Copyright (C)2003 Don HO <don.h@free.fr>
|
2010-03-26 00:22:14 +00:00
|
|
|
//
|
2012-04-15 16:54:38 +00:00
|
|
|
// 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.
|
2010-03-26 00:22:14 +00:00
|
|
|
//
|
2012-04-15 16:54:38 +00:00
|
|
|
// Note that the GPL places important restrictions on "derived works", yet
|
2015-08-04 11:36:22 +00:00
|
|
|
// it does not provide a detailed definition of that term. To avoid
|
|
|
|
// misunderstandings, we consider an application to constitute a
|
2012-04-15 16:54:38 +00:00
|
|
|
// "derivative work" for the purpose of this license if it does any of the
|
2015-08-04 11:36:22 +00:00
|
|
|
// following:
|
2012-04-15 16:54:38 +00:00
|
|
|
// 1. Integrates source code from Notepad++.
|
|
|
|
// 2. Integrates/includes/aggregates Notepad++ into a proprietary executable
|
|
|
|
// installer, such as those produced by InstallShield.
|
|
|
|
// 3. Links to a library or executes a program that does any of the above.
|
2010-03-26 00:22:14 +00:00
|
|
|
//
|
2012-04-15 16:54:38 +00:00
|
|
|
// 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.
|
|
|
|
|
2010-03-26 00:22:14 +00:00
|
|
|
|
2015-06-02 16:01:47 +00:00
|
|
|
#include <time.h>
|
|
|
|
#include <shlwapi.h>
|
2010-03-26 00:22:14 +00:00
|
|
|
#include "Notepad_plus_Window.h"
|
|
|
|
|
|
|
|
const TCHAR Notepad_plus_Window::_className[32] = TEXT("Notepad++");
|
|
|
|
HWND Notepad_plus_Window::gNppHWND = NULL;
|
|
|
|
|
2015-08-04 17:01:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace // anonymous
|
|
|
|
{
|
|
|
|
|
|
|
|
struct PaintLocker final
|
|
|
|
{
|
2016-07-18 00:08:29 +00:00
|
|
|
explicit PaintLocker(HWND handle)
|
2015-08-04 17:01:52 +00:00
|
|
|
: handle(handle)
|
|
|
|
{
|
|
|
|
// disallow drawing on the window
|
|
|
|
LockWindowUpdate(handle);
|
|
|
|
}
|
|
|
|
|
|
|
|
~PaintLocker()
|
|
|
|
{
|
|
|
|
// re-allow drawing for the window
|
|
|
|
LockWindowUpdate(NULL);
|
|
|
|
|
|
|
|
// force re-draw
|
|
|
|
InvalidateRect(handle, nullptr, TRUE);
|
|
|
|
RedrawWindow(handle, nullptr, NULL, RDW_ERASE | RDW_ALLCHILDREN | RDW_FRAME | RDW_INVALIDATE);
|
|
|
|
}
|
|
|
|
|
|
|
|
HWND handle;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // anonymous namespace
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2010-03-26 00:22:14 +00:00
|
|
|
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))
|
|
|
|
{
|
2010-05-25 23:41:58 +00:00
|
|
|
throw std::runtime_error("Notepad_plus_Window::init : RegisterClass() function failed");
|
2010-03-26 00:22:14 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NppParameters *pNppParams = NppParameters::getInstance();
|
2016-08-28 22:13:28 +00:00
|
|
|
NppGUI & nppGUI = const_cast<NppGUI &>(pNppParams->getNppGUI());
|
2010-03-26 00:22:14 +00:00
|
|
|
|
|
|
|
if (cmdLineParams->_isNoPlugin)
|
|
|
|
_notepad_plus_plus_core._pluginsManager.disable();
|
2015-08-04 11:36:22 +00:00
|
|
|
|
2010-03-26 00:22:14 +00:00
|
|
|
_hSelf = ::CreateWindowEx(
|
2015-08-04 17:01:52 +00:00
|
|
|
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, nullptr, _hInst,
|
|
|
|
(LPVOID) this); // pass the ptr of this instantiated object
|
|
|
|
// for retrieve it in Notepad_plus_Proc from
|
|
|
|
// the CREATESTRUCT.lpCreateParams afterward.
|
|
|
|
|
|
|
|
if (NULL == _hSelf)
|
2010-05-25 23:41:58 +00:00
|
|
|
throw std::runtime_error("Notepad_plus_Window::init : CreateWindowEx() function return null");
|
2015-08-04 17:01:52 +00:00
|
|
|
|
|
|
|
|
|
|
|
PaintLocker paintLocker{_hSelf};
|
2010-03-26 00:22:14 +00:00
|
|
|
|
2010-07-26 00:12:02 +00:00
|
|
|
_notepad_plus_plus_core.staticCheckMenuAndTB();
|
|
|
|
|
2010-03-26 00:22:14 +00:00
|
|
|
gNppHWND = _hSelf;
|
|
|
|
|
|
|
|
if (cmdLineParams->isPointValid())
|
2015-08-04 17:01:52 +00:00
|
|
|
{
|
2010-03-26 00:22:14 +00:00
|
|
|
::MoveWindow(_hSelf, cmdLineParams->_point.x, cmdLineParams->_point.y, nppGUI._appPos.right, nppGUI._appPos.bottom, TRUE);
|
2015-08-04 17:01:52 +00:00
|
|
|
}
|
2010-03-26 00:22:14 +00:00
|
|
|
else
|
2013-06-01 18:59:50 +00:00
|
|
|
{
|
|
|
|
WINDOWPLACEMENT posInfo;
|
|
|
|
posInfo.length = sizeof(WINDOWPLACEMENT);
|
|
|
|
posInfo.flags = 0;
|
2013-07-23 18:24:19 +00:00
|
|
|
if(_isPrelaunch)
|
|
|
|
posInfo.showCmd = SW_HIDE;
|
|
|
|
else
|
2015-08-04 17:01:52 +00:00
|
|
|
posInfo.showCmd = nppGUI._isMaximized ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
|
|
|
|
|
2013-06-01 18:59:50 +00:00
|
|
|
posInfo.ptMinPosition.x = (LONG)-1;
|
|
|
|
posInfo.ptMinPosition.y = (LONG)-1;
|
|
|
|
posInfo.ptMaxPosition.x = (LONG)-1;
|
|
|
|
posInfo.ptMaxPosition.y = (LONG)-1;
|
|
|
|
posInfo.rcNormalPosition.left = nppGUI._appPos.left;
|
|
|
|
posInfo.rcNormalPosition.top = nppGUI._appPos.top;
|
|
|
|
posInfo.rcNormalPosition.bottom = nppGUI._appPos.top + nppGUI._appPos.bottom;
|
|
|
|
posInfo.rcNormalPosition.right = nppGUI._appPos.left + nppGUI._appPos.right;
|
|
|
|
|
|
|
|
//SetWindowPlacement will take care of situations, where saved position was in no longer available monitor
|
|
|
|
::SetWindowPlacement(_hSelf,&posInfo);
|
|
|
|
}
|
2015-08-04 11:36:22 +00:00
|
|
|
|
2017-01-08 22:59:36 +00:00
|
|
|
if ((nppGUI._tabStatus & TAB_MULTILINE) != 0)
|
2010-03-26 00:22:14 +00:00
|
|
|
::SendMessage(_hSelf, WM_COMMAND, IDM_VIEW_DRAWTABBAR_MULTILINE, 0);
|
|
|
|
|
|
|
|
if (!nppGUI._menuBarShow)
|
|
|
|
::SetMenu(_hSelf, NULL);
|
2015-08-04 11:36:22 +00:00
|
|
|
|
2010-03-26 00:22:14 +00:00
|
|
|
if (cmdLineParams->_isNoTab || (nppGUI._tabStatus & TAB_HIDE))
|
|
|
|
{
|
2015-04-25 11:11:35 +00:00
|
|
|
const int tabStatusOld = nppGUI._tabStatus;
|
2010-03-26 00:22:14 +00:00
|
|
|
::SendMessage(_hSelf, NPPM_HIDETABBAR, 0, TRUE);
|
2015-04-25 11:11:35 +00:00
|
|
|
if (cmdLineParams->_isNoTab)
|
|
|
|
{
|
|
|
|
// Restore old settings when tab bar has been hidden from tab bar.
|
|
|
|
nppGUI._tabStatus = tabStatusOld;
|
|
|
|
}
|
2010-03-26 00:22:14 +00:00
|
|
|
}
|
|
|
|
|
2010-11-14 01:40:33 +00:00
|
|
|
if (cmdLineParams->_alwaysOnTop)
|
|
|
|
::SendMessage(_hSelf, WM_COMMAND, IDM_VIEW_ALWAYSONTOP, 0);
|
2014-05-17 15:35:09 +00:00
|
|
|
|
|
|
|
nppGUI._isCmdlineNosessionActivated = cmdLineParams->_isNoSession;
|
2010-03-26 00:22:14 +00:00
|
|
|
if (nppGUI._rememberLastSession && !cmdLineParams->_isNoSession)
|
|
|
|
_notepad_plus_plus_core.loadLastSession();
|
|
|
|
|
2015-08-04 17:01:52 +00:00
|
|
|
if (not cmdLineParams->_isPreLaunch)
|
2010-03-26 00:22:14 +00:00
|
|
|
{
|
|
|
|
if (cmdLineParams->isPointValid())
|
|
|
|
::ShowWindow(_hSelf, SW_SHOW);
|
|
|
|
else
|
2015-08-04 17:01:52 +00:00
|
|
|
::ShowWindow(_hSelf, nppGUI._isMaximized ? SW_MAXIMIZE : SW_SHOW);
|
2010-03-26 00:22:14 +00:00
|
|
|
}
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2015-08-04 17:01:52 +00:00
|
|
|
if (cmdLine)
|
2010-03-26 00:22:14 +00:00
|
|
|
_notepad_plus_plus_core.loadCommandlineParams(cmdLine, cmdLineParams);
|
|
|
|
|
2015-05-31 20:40:07 +00:00
|
|
|
std::vector<generic_string> fileNames;
|
|
|
|
std::vector<generic_string> patterns;
|
2010-03-26 00:22:14 +00:00
|
|
|
patterns.push_back(TEXT("*.xml"));
|
2015-08-04 11:36:22 +00:00
|
|
|
|
2010-03-26 00:22:14 +00:00
|
|
|
generic_string nppDir = pNppParams->getNppPath();
|
2014-12-27 00:32:51 +00:00
|
|
|
|
2010-03-26 00:22:14 +00:00
|
|
|
LocalizationSwitcher & localizationSwitcher = pNppParams->getLocalizationSwitcher();
|
2015-05-31 20:40:07 +00:00
|
|
|
std::wstring localizationDir = nppDir;
|
2010-03-26 00:22:14 +00:00
|
|
|
PathAppend(localizationDir, TEXT("localization\\"));
|
|
|
|
|
|
|
|
_notepad_plus_plus_core.getMatchedFileNames(localizationDir.c_str(), patterns, fileNames, false, false);
|
2015-08-04 17:01:52 +00:00
|
|
|
for (size_t i = 0, len = fileNames.size(); i < len; ++i)
|
2010-03-26 00:22:14 +00:00
|
|
|
localizationSwitcher.addLanguageFromXml(fileNames[i].c_str());
|
|
|
|
|
|
|
|
fileNames.clear();
|
|
|
|
ThemeSwitcher & themeSwitcher = pNppParams->getThemeSwitcher();
|
2015-08-04 11:36:22 +00:00
|
|
|
|
2010-03-26 00:22:14 +00:00
|
|
|
// Get themes from both npp install themes dir and app data themes dir with the per user
|
|
|
|
// overriding default themes of the same name.
|
|
|
|
|
2010-07-31 22:32:42 +00:00
|
|
|
generic_string themeDir;
|
|
|
|
if (pNppParams->getAppDataNppDir() && pNppParams->getAppDataNppDir()[0])
|
|
|
|
{
|
|
|
|
themeDir = pNppParams->getAppDataNppDir();
|
|
|
|
PathAppend(themeDir, TEXT("themes\\"));
|
|
|
|
_notepad_plus_plus_core.getMatchedFileNames(themeDir.c_str(), patterns, fileNames, false, false);
|
2013-07-08 00:12:50 +00:00
|
|
|
for (size_t i = 0, len = fileNames.size() ; i < len ; ++i)
|
2010-07-31 22:32:42 +00:00
|
|
|
{
|
|
|
|
themeSwitcher.addThemeFromXml(fileNames[i].c_str());
|
|
|
|
}
|
|
|
|
}
|
2015-08-04 17:01:52 +00:00
|
|
|
|
2010-03-26 00:22:14 +00:00
|
|
|
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);
|
2013-07-08 00:12:50 +00:00
|
|
|
for (size_t i = 0, len = fileNames.size(); i < len ; ++i)
|
2010-03-26 00:22:14 +00:00
|
|
|
{
|
|
|
|
generic_string themeName( themeSwitcher.getThemeFromXmlFileName(fileNames[i].c_str()) );
|
2015-08-04 11:36:22 +00:00
|
|
|
if (! themeSwitcher.themeNameExists(themeName.c_str()) )
|
2010-03-26 00:22:14 +00:00
|
|
|
{
|
|
|
|
themeSwitcher.addThemeFromXml(fileNames[i].c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-08 00:12:50 +00:00
|
|
|
for (size_t i = 0, len = _notepad_plus_plus_core._internalFuncIDs.size() ; i < len ; ++i)
|
2011-05-19 21:19:05 +00:00
|
|
|
::SendMessage(_hSelf, WM_COMMAND, _notepad_plus_plus_core._internalFuncIDs[i], 0);
|
|
|
|
|
2010-03-26 00:22:14 +00:00
|
|
|
// 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);
|
|
|
|
|
2015-08-04 17:01:52 +00:00
|
|
|
if (not cmdLineParams->_easterEggName.empty())
|
2015-01-10 23:41:49 +00:00
|
|
|
{
|
|
|
|
char dest[MAX_PATH];
|
|
|
|
wcstombs(dest, (cmdLineParams->_easterEggName).c_str(), sizeof(dest));
|
2015-02-01 12:16:12 +00:00
|
|
|
|
|
|
|
//::MessageBoxA(NULL, destStr.c_str(), "", MB_OK);
|
|
|
|
if (cmdLineParams->_quoteType == 0) // Easter Egg Name
|
|
|
|
{
|
|
|
|
int iQuote = _notepad_plus_plus_core.getQuoteIndexFrom(dest);
|
|
|
|
if (iQuote != -1)
|
|
|
|
{
|
|
|
|
_notepad_plus_plus_core.showQuoteFromIndex(iQuote);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (cmdLineParams->_quoteType == 1) // command line quote
|
|
|
|
{
|
|
|
|
_userQuote = dest;
|
|
|
|
_notepad_plus_plus_core.showQuote(_userQuote.c_str(), "Anonymous #999", false);
|
|
|
|
}
|
|
|
|
else if (cmdLineParams->_quoteType == 2) // content drom file
|
2015-01-10 23:41:49 +00:00
|
|
|
{
|
2015-02-01 12:16:12 +00:00
|
|
|
std::string destStr = dest;
|
|
|
|
generic_string fileName(destStr.begin(), destStr.end());
|
2015-02-02 08:20:52 +00:00
|
|
|
|
|
|
|
if (::PathFileExists(fileName.c_str()))
|
|
|
|
{
|
|
|
|
_userQuote = getFileContent(fileName.c_str());
|
|
|
|
if (_userQuote != "")
|
|
|
|
_notepad_plus_plus_core.showQuote(_userQuote.c_str(), "Anonymous #999", false);
|
|
|
|
}
|
2015-01-10 23:41:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-03-26 00:22:14 +00:00
|
|
|
if (cmdLineParams->_showLoadingTime)
|
|
|
|
{
|
|
|
|
time_t timestampEnd = time(NULL);
|
|
|
|
double loadTime = difftime(timestampEnd, timestampBegin);
|
|
|
|
|
|
|
|
char dest[256];
|
2013-06-27 21:57:23 +00:00
|
|
|
sprintf(dest, "Loading time : %.0lf seconds", loadTime);
|
2010-03-26 00:22:14 +00:00
|
|
|
::MessageBoxA(NULL, dest, "", MB_OK);
|
|
|
|
}
|
2014-03-27 01:30:31 +00:00
|
|
|
|
2014-05-08 20:48:03 +00:00
|
|
|
bool isSnapshotMode = nppGUI.isSnapshotMode();
|
2014-04-13 01:31:02 +00:00
|
|
|
if (isSnapshotMode)
|
2014-04-08 03:45:52 +00:00
|
|
|
{
|
|
|
|
_notepad_plus_plus_core.checkModifiedDocument();
|
|
|
|
// Lauch backup task
|
|
|
|
_notepad_plus_plus_core.launchDocumentBackupTask();
|
|
|
|
}
|
2017-02-04 12:17:40 +00:00
|
|
|
|
|
|
|
// Make this call later to take effect
|
|
|
|
::SendMessage(_hSelf, NPPM_INTERNAL_SETWORDCHARS, 0, 0);
|
2017-08-05 22:03:18 +00:00
|
|
|
|
|
|
|
if (pNppParams->doFunctionListExport())
|
|
|
|
::SendMessage(_hSelf, NPPM_INTERNAL_EXPORTFUNCLISTANDQUIT, 0, 0);
|
2017-08-06 22:01:12 +00:00
|
|
|
|
|
|
|
if (pNppParams->doPrintAndExit())
|
|
|
|
::SendMessage(_hSelf, NPPM_INTERNAL_PRNTANDQUIT, 0, 0);
|
2010-03-26 00:22:14 +00:00
|
|
|
}
|
|
|
|
|
2015-08-04 17:01:52 +00:00
|
|
|
|
2015-08-04 11:36:22 +00:00
|
|
|
bool Notepad_plus_Window::isDlgsMsg(MSG *msg) const
|
2010-03-26 00:22:14 +00:00
|
|
|
{
|
2013-07-08 00:12:50 +00:00
|
|
|
for (size_t i = 0, len = _notepad_plus_plus_core._hModelessDlgs.size(); i < len; ++i)
|
2010-03-26 00:22:14 +00:00
|
|
|
{
|
2015-02-09 08:33:01 +00:00
|
|
|
if (_notepad_plus_plus_core.processIncrFindAccel(msg))
|
2015-02-06 03:46:15 +00:00
|
|
|
return true;
|
|
|
|
|
2016-12-18 16:37:43 +00:00
|
|
|
if (_notepad_plus_plus_core.processFindAccel(msg))
|
|
|
|
return true;
|
|
|
|
|
2014-05-10 01:12:44 +00:00
|
|
|
if (::IsDialogMessageW(_notepad_plus_plus_core._hModelessDlgs[i], msg))
|
2010-03-26 00:22:14 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|