2010-03-26 00:22:14 +00:00
|
|
|
//this file is part of notepad++
|
|
|
|
//Copyright (C)2010 Don HO <don.h@free.fr>
|
|
|
|
//
|
|
|
|
//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))
|
|
|
|
{
|
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
|
|
|
}
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2010-05-25 23:41:58 +00:00
|
|
|
throw std::runtime_error("Notepad_plus_Window::init : CreateWindowEx() function return null");
|
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;
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
|
2010-11-14 01:40:33 +00:00
|
|
|
if (cmdLineParams->_alwaysOnTop)
|
|
|
|
{
|
|
|
|
::SendMessage(_hSelf, WM_COMMAND, IDM_VIEW_ALWAYSONTOP, 0);
|
|
|
|
}
|
2010-03-26 00:22:14 +00:00
|
|
|
_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<generic_string> fileNames;
|
|
|
|
vector<generic_string> 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.
|
|
|
|
|
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);
|
|
|
|
for (size_t i = 0 ; i < fileNames.size() ; i++)
|
|
|
|
{
|
|
|
|
themeSwitcher.addThemeFromXml(fileNames[i].c_str());
|
|
|
|
}
|
|
|
|
}
|
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);
|
|
|
|
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;
|
|
|
|
}
|