minor code cleanup for future refactoring

This commit is contained in:
Damien GERARD 2015-08-06 11:03:57 +02:00
parent ba5d36e2bf
commit 366a393f13
19 changed files with 2251 additions and 2152 deletions

View File

@ -29,6 +29,7 @@
#include <string> #include <string>
#include <windows.h> #include <windows.h>
#include <iso646.h> #include <iso646.h>
#include <cstdint>
const bool dirUp = true; const bool dirUp = true;

View File

@ -362,7 +362,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
bool isVertical = (nppGUI._splitterPos == POS_VERTICAL); bool isVertical = (nppGUI._splitterPos == POS_VERTICAL);
_subSplitter.init(_pPublicInterface->getHinst(), hwnd); _subSplitter.init(_pPublicInterface->getHinst(), hwnd);
_subSplitter.create(&_mainDocTab, &_subDocTab, 8, DYNAMIC, 50, isVertical); _subSplitter.create(&_mainDocTab, &_subDocTab, 8, SplitterMode::DYNAMIC, 50, isVertical);
//--Status Bar Section--// //--Status Bar Section--//
bool willBeShown = nppGUI._statusBarShow; bool willBeShown = nppGUI._statusBarShow;
@ -3240,7 +3240,7 @@ void Notepad_plus::dockUserDlg()
else else
pWindow = _pDocTab; pWindow = _pDocTab;
_pMainSplitter->create(pWindow, ScintillaEditView::getUserDefineDlg(), 8, RIGHT_FIX, 45); _pMainSplitter->create(pWindow, ScintillaEditView::getUserDefineDlg(), 8, SplitterMode::RIGHT_FIX, 45);
} }
if (bothActive()) if (bothActive())

View File

@ -24,13 +24,11 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#pragma once
#ifndef NOTEPAD_PLUS_WINDOW_H
#define NOTEPAD_PLUS_WINDOW_H
#include "Notepad_plus.h" #include "Notepad_plus.h"
const TCHAR COMMAND_ARG_HELP[] = TEXT("Usage :\r\ const TCHAR COMMAND_ARG_HELP[] = TEXT("Usage :\r\
\r\ \r\
notepad++ [--help] [-multiInst] [-noPlugin] [-lLanguage] [-LlangCode] [-nLineNumber] [-cColumnNumber] [-xLeftPos] [-yTopPos] [-nosession] [-notabbar] [-ro] [-systemtray] [-loadingTime] [-alwaysOnTop] [-openSession] [-r] [-qnEsterEggName | -qtText | -qfCntentFileName] [filePath]\r\ notepad++ [--help] [-multiInst] [-noPlugin] [-lLanguage] [-LlangCode] [-nLineNumber] [-cColumnNumber] [-xLeftPos] [-yTopPos] [-nosession] [-notabbar] [-ro] [-systemtray] [-loadingTime] [-alwaysOnTop] [-openSession] [-r] [-qnEsterEggName | -qtText | -qfCntentFileName] [filePath]\r\
@ -59,47 +57,57 @@ notepad++ [--help] [-multiInst] [-noPlugin] [-lLanguage] [-LlangCode] [-nLineNum
filePath : file or folder name to open (absolute or relative path name)\r\ filePath : file or folder name to open (absolute or relative path name)\r\
"); ");
class Notepad_plus_Window : public Window {
class Notepad_plus_Window : public Window
{
public: public:
Notepad_plus_Window() : _isPrelaunch(false), _disablePluginsManager(false) {};
void init(HINSTANCE, HWND, const TCHAR *cmdLine, CmdLineParams *cmdLineParams); void init(HINSTANCE, HWND, const TCHAR *cmdLine, CmdLineParams *cmdLineParams);
bool isDlgsMsg(MSG *msg) const; bool isDlgsMsg(MSG *msg) const;
HACCEL getAccTable() const { HACCEL getAccTable() const
{
return _notepad_plus_plus_core.getAccTable(); return _notepad_plus_plus_core.getAccTable();
}; }
bool emergency(generic_string emergencySavedDir) { bool emergency(generic_string emergencySavedDir)
{
return _notepad_plus_plus_core.emergency(emergencySavedDir); return _notepad_plus_plus_core.emergency(emergencySavedDir);
}; }
bool isPrelaunch() const { bool isPrelaunch() const
{
return _isPrelaunch; return _isPrelaunch;
}; }
void setIsPrelaunch(bool val) { void setIsPrelaunch(bool val)
{
_isPrelaunch = val; _isPrelaunch = val;
}; }
virtual void destroy(){ virtual void destroy()
{
::DestroyWindow(_hSelf); ::DestroyWindow(_hSelf);
}; }
static const TCHAR * getClassName() { static const TCHAR * getClassName()
{
return _className; return _className;
}; }
static HWND gNppHWND; //static handle to Notepad++ window, NULL if non-existant static HWND gNppHWND; //static handle to Notepad++ window, NULL if non-existant
private: private:
Notepad_plus _notepad_plus_plus_core; Notepad_plus _notepad_plus_plus_core;
static LRESULT CALLBACK Notepad_plus_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK Notepad_plus_Proc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); LRESULT runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
static const TCHAR _className[32]; static const TCHAR _className[32];
bool _isPrelaunch; bool _isPrelaunch = false;
bool _disablePluginsManager; bool _disablePluginsManager = false;
std::string _userQuote; // keep the availability of this string for thread using std::string _userQuote; // keep the availability of this string for thread using
}; };
#endif //NOTEPAD_PLUS_WINDOW_H

View File

@ -43,7 +43,10 @@ using namespace std;
#define WM_DPICHANGED 0x02E0 #define WM_DPICHANGED 0x02E0
struct SortTaskListPred
struct SortTaskListPred final
{ {
DocTabView *_views[2]; DocTabView *_views[2];
@ -70,13 +73,13 @@ LRESULT CALLBACK Notepad_plus_Window::Notepad_plus_Proc(HWND hwnd, UINT Message,
switch(Message) switch(Message)
{ {
case WM_NCCREATE : // First message we get the ptr of instantiated object case WM_NCCREATE:
// then stock it into GWLP_USERDATA index in order to retrieve afterward
{ {
// First message we get the ptr of instantiated object
// then stock it into GWLP_USERDATA index in order to retrieve afterward
Notepad_plus_Window *pM30ide = (Notepad_plus_Window *)(((LPCREATESTRUCT)lParam)->lpCreateParams); Notepad_plus_Window *pM30ide = (Notepad_plus_Window *)(((LPCREATESTRUCT)lParam)->lpCreateParams);
pM30ide->_hSelf = hwnd; pM30ide->_hSelf = hwnd;
::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pM30ide); ::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pM30ide);
return TRUE; return TRUE;
} }
@ -87,27 +90,32 @@ LRESULT CALLBACK Notepad_plus_Window::Notepad_plus_Proc(HWND hwnd, UINT Message,
} }
} }
LRESULT Notepad_plus_Window::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam) LRESULT Notepad_plus_Window::runProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam)
{ {
LRESULT result = FALSE;
switch (Message) switch (Message)
{ {
case WM_CREATE: case WM_CREATE:
{ {
try{ try
{
_notepad_plus_plus_core._pPublicInterface = this; _notepad_plus_plus_core._pPublicInterface = this;
result = _notepad_plus_plus_core.init(hwnd); return _notepad_plus_plus_core.init(hwnd);
} catch (std::exception ex) { }
catch (std::exception ex)
{
::MessageBoxA(_notepad_plus_plus_core._pPublicInterface->getHSelf(), ex.what(), "Exception On WM_CREATE", MB_OK); ::MessageBoxA(_notepad_plus_plus_core._pPublicInterface->getHSelf(), ex.what(), "Exception On WM_CREATE", MB_OK);
exit(-1); exit(-1);
} }
}
break; break;
}
default: default:
{
if (this) if (this)
return _notepad_plus_plus_core.process(hwnd, Message, wParam, lParam); return _notepad_plus_plus_core.process(hwnd, Message, wParam, lParam);
} }
return result; }
return FALSE;
} }
@ -129,9 +137,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
{ {
DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam; DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT *)lParam;
if (dis->CtlType == ODT_TAB) if (dis->CtlType == ODT_TAB)
{
return ::SendMessage(dis->hwndItem, WM_DRAWITEM, wParam, lParam); return ::SendMessage(dis->hwndItem, WM_DRAWITEM, wParam, lParam);
} break;
} }
case WM_DOCK_USERDEFINE_DLG: case WM_DOCK_USERDEFINE_DLG:
@ -151,13 +158,13 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
TCHAR *userLangName = (TCHAR *)lParam; TCHAR *userLangName = (TCHAR *)lParam;
if (!userLangName || !userLangName[0]) if (!userLangName || !userLangName[0])
return FALSE; return FALSE;
generic_string name(userLangName);
generic_string name{userLangName};
//loop through buffers and reset the language (L_USER, TEXT("")) if (L_USER, name) //loop through buffers and reset the language (L_USER, TEXT("")) if (L_USER, name)
Buffer * buf;
for (int i = 0; i < MainFileManager->getNrBuffers(); ++i) for (int i = 0; i < MainFileManager->getNrBuffers(); ++i)
{ {
buf = MainFileManager->getBufferByIndex(i); Buffer* buf = MainFileManager->getBufferByIndex(i);
if (buf->getLangType() == L_USER && name == buf->getUserDefineLangName()) if (buf->getLangType() == L_USER && name == buf->getUserDefineLangName())
buf->setLangType(L_USER, TEXT("")); buf->setLangType(L_USER, TEXT(""));
} }
@ -169,14 +176,13 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
if (!lParam || !(((TCHAR *)lParam)[0]) || !wParam || !(((TCHAR *)wParam)[0])) if (!lParam || !(((TCHAR *)lParam)[0]) || !wParam || !(((TCHAR *)wParam)[0]))
return FALSE; return FALSE;
generic_string oldName((TCHAR *)lParam); generic_string oldName{(TCHAR *)lParam};
generic_string newName((TCHAR *)wParam); generic_string newName{(TCHAR *)wParam};
//loop through buffers and reset the language (L_USER, newName) if (L_USER, oldName) //loop through buffers and reset the language (L_USER, newName) if (L_USER, oldName)
Buffer * buf;
for (int i = 0; i < MainFileManager->getNrBuffers(); ++i) for (int i = 0; i < MainFileManager->getNrBuffers(); ++i)
{ {
buf = MainFileManager->getBufferByIndex(i); Buffer* buf = MainFileManager->getBufferByIndex(i);
if (buf->getLangType() == L_USER && oldName == buf->getUserDefineLangName()) if (buf->getLangType() == L_USER && oldName == buf->getUserDefineLangName())
buf->setLangType(L_USER, newName.c_str()); buf->setLangType(L_USER, newName.c_str());
} }
@ -218,13 +224,14 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
replaceInFiles(); replaceInFiles();
return TRUE; return TRUE;
} }
case NPPM_LAUNCHFINDINFILESDLG: case NPPM_LAUNCHFINDINFILESDLG:
{ {
// Find in files function code should be here due to the number of parameters (2) cannot be passed via WM_COMMAND // Find in files function code should be here due to the number of parameters (2) cannot be passed via WM_COMMAND
const int strSize = FINDREPLACE_MAXLENGTH; const int strSize = FINDREPLACE_MAXLENGTH;
TCHAR str[strSize]; TCHAR str[strSize];
bool isFirstTime = !_findReplaceDlg.isCreated(); bool isFirstTime = not _findReplaceDlg.isCreated();
_findReplaceDlg.doDialog(FIND_DLG, _nativeLangSpeaker.isRTL()); _findReplaceDlg.doDialog(FIND_DLG, _nativeLangSpeaker.isRTL());
_pEditView->getGenericSelectedText(str, strSize); _pEditView->getGenericSelectedText(str, strSize);
@ -233,6 +240,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
_nativeLangSpeaker.changeDlgLang(_findReplaceDlg.getHSelf(), "Find"); _nativeLangSpeaker.changeDlgLang(_findReplaceDlg.getHSelf(), "Find");
_findReplaceDlg.launchFindInFilesDlg(); _findReplaceDlg.launchFindInFilesDlg();
setFindReplaceFolderFilter((const TCHAR*) wParam, (const TCHAR*) lParam); setFindReplaceFolderFilter((const TCHAR*) wParam, (const TCHAR*) lParam);
return TRUE; return TRUE;
} }
@ -241,11 +249,9 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
{ {
BufferID id = doOpen((const TCHAR *)lParam); BufferID id = doOpen((const TCHAR *)lParam);
if (id != BUFFER_INVALID) if (id != BUFFER_INVALID)
{
return switchToFile(id); return switchToFile(id);
}
}
break; break;
}
case NPPM_INTERNAL_SETFILENAME: case NPPM_INTERNAL_SETFILENAME:
{ {
@ -259,7 +265,6 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
} }
return FALSE; return FALSE;
} }
break;
case NPPM_GETBUFFERLANGTYPE: case NPPM_GETBUFFERLANGTYPE:
{ {
@ -269,7 +274,6 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
Buffer * b = MainFileManager->getBufferByID(id); Buffer * b = MainFileManager->getBufferByID(id);
return b->getLangType(); return b->getLangType();
} }
break;
case NPPM_SETBUFFERLANGTYPE: case NPPM_SETBUFFERLANGTYPE:
{ {
@ -283,7 +287,6 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
b->setLangType((LangType)lParam); b->setLangType((LangType)lParam);
return TRUE; return TRUE;
} }
break;
case NPPM_GETBUFFERENCODING: case NPPM_GETBUFFERENCODING:
{ {
@ -293,7 +296,6 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
Buffer * b = MainFileManager->getBufferByID(id); Buffer * b = MainFileManager->getBufferByID(id);
return b->getUnicodeMode(); return b->getUnicodeMode();
} }
break;
case NPPM_SETBUFFERENCODING: case NPPM_SETBUFFERENCODING:
{ {
@ -309,7 +311,6 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
b->setUnicodeMode((UniMode)lParam); b->setUnicodeMode((UniMode)lParam);
return TRUE; return TRUE;
} }
break;
case NPPM_GETBUFFERFORMAT: case NPPM_GETBUFFERFORMAT:
{ {
@ -319,7 +320,6 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
Buffer * b = MainFileManager->getBufferByID(id); Buffer * b = MainFileManager->getBufferByID(id);
return b->getFormat(); return b->getFormat();
} }
break;
case NPPM_SETBUFFERFORMAT: case NPPM_SETBUFFERFORMAT:
{ {
@ -333,30 +333,27 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
b->setFormat((formatType)lParam); b->setFormat((formatType)lParam);
return TRUE; return TRUE;
} }
break;
case NPPM_GETBUFFERIDFROMPOS: case NPPM_GETBUFFERIDFROMPOS:
{ {
DocTabView * pView = NULL; DocTabView* pView = nullptr;
if (lParam == MAIN_VIEW) { if (lParam == MAIN_VIEW)
pView = &_mainDocTab; pView = &_mainDocTab;
} else if (lParam == SUB_VIEW) { else if (lParam == SUB_VIEW)
pView = &_subDocTab; pView = &_subDocTab;
} else { else
return (LRESULT)BUFFER_INVALID; return (LRESULT)BUFFER_INVALID;
}
if ((int)wParam < pView->nbItem()) { if ((int)wParam < pView->nbItem())
return (LRESULT)(pView->getBufferByIndex((int)wParam)); return (LRESULT)(pView->getBufferByIndex((int)wParam));
}
return (LRESULT)BUFFER_INVALID; return (LRESULT)BUFFER_INVALID;
} }
break;
case NPPM_GETCURRENTBUFFERID: case NPPM_GETCURRENTBUFFERID:
{ {
return (LRESULT)(_pEditView->getCurrentBufferID()); return (LRESULT)(_pEditView->getCurrentBufferID());
} }
break;
case NPPM_RELOADBUFFERID: case NPPM_RELOADBUFFERID:
{ {
@ -364,15 +361,14 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
return FALSE; return FALSE;
return doReload((BufferID)wParam, lParam != 0); return doReload((BufferID)wParam, lParam != 0);
} }
break;
case NPPM_RELOADFILE: case NPPM_RELOADFILE:
{ {
BufferID id = MainFileManager->getBufferFromName((const TCHAR *)lParam); BufferID id = MainFileManager->getBufferFromName((const TCHAR *)lParam);
if (id != BUFFER_INVALID) if (id != BUFFER_INVALID)
doReload(id, wParam != 0); doReload(id, wParam != 0);
}
break; break;
}
case NPPM_SWITCHTOFILE : case NPPM_SWITCHTOFILE :
{ {
@ -386,7 +382,6 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
{ {
return fileSave(); return fileSave();
} }
break;
case NPPM_SAVECURRENTFILEAS: case NPPM_SAVECURRENTFILEAS:
{ {
@ -396,19 +391,16 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
if (!filename) return FALSE; if (!filename) return FALSE;
return doSave(currentBufferID, filename, asCopy); return doSave(currentBufferID, filename, asCopy);
} }
break;
case NPPM_SAVEALLFILES: case NPPM_SAVEALLFILES:
{ {
return fileSaveAll(); return fileSaveAll();
} }
break;
case NPPM_GETCURRENTNATIVELANGENCODING: case NPPM_GETCURRENTNATIVELANGENCODING:
{ {
return _nativeLangSpeaker.getLangEncoding(); return _nativeLangSpeaker.getLangEncoding();
} }
break;
case NPPM_INTERNAL_DOCORDERCHANGED : case NPPM_INTERNAL_DOCORDERCHANGED :
{ {
@ -422,15 +414,13 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
_pluginsManager.notify(&scnN); _pluginsManager.notify(&scnN);
return TRUE; return TRUE;
} }
break;
case WM_SIZE: case WM_SIZE:
{ {
RECT rc; RECT rc;
_pPublicInterface->getClientRect(rc); _pPublicInterface->getClientRect(rc);
if (lParam == 0) { if (lParam == 0)
lParam = MAKELPARAM(rc.right - rc.left, rc.bottom - rc.top); lParam = MAKELPARAM(rc.right - rc.left, rc.bottom - rc.top);
}
::MoveWindow(_rebarTop.getHSelf(), 0, 0, rc.right, _rebarTop.getHeight(), TRUE); ::MoveWindow(_rebarTop.getHSelf(), 0, 0, rc.right, _rebarTop.getHeight(), TRUE);
_statusBar.adjustParts(rc.right); _statusBar.adjustParts(rc.right);
@ -450,14 +440,14 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
} }
result = TRUE; result = TRUE;
}
break; break;
}
case WM_MOVE: case WM_MOVE:
{ {
result = TRUE; result = TRUE;
}
break; break;
}
case WM_MOVING: case WM_MOVING:
{ {
@ -466,14 +456,14 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
_pDocMap->doMove(); _pDocMap->doMove();
} }
result = FALSE; result = FALSE;
}
break; break;
}
case WM_SIZING: case WM_SIZING:
{ {
result = FALSE; result = FALSE;
}
break; break;
}
case WM_COPYDATA: case WM_COPYDATA:
{ {
@ -531,8 +521,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
{ {
command(LOWORD(wParam)); command(LOWORD(wParam));
} }
}
return TRUE; return TRUE;
}
case NPPM_INTERNAL_SAVECURRENTSESSION: case NPPM_INTERNAL_SAVECURRENTSESSION:
{ {
@ -545,20 +535,20 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
getCurrentOpenedFiles(currentSession, true); getCurrentOpenedFiles(currentSession, true);
nppParam->writeSession(currentSession); nppParam->writeSession(currentSession);
} }
}
return TRUE; return TRUE;
}
case NPPM_INTERNAL_RELOADNATIVELANG: case NPPM_INTERNAL_RELOADNATIVELANG:
{ {
reloadLang(); reloadLang();
}
return TRUE; return TRUE;
}
case NPPM_INTERNAL_RELOADSTYLERS: case NPPM_INTERNAL_RELOADSTYLERS:
{ {
loadStyles(); loadStyles();
}
return TRUE; return TRUE;
}
case NPPM_INTERNAL_PLUGINSHORTCUTMOTIFIED: case NPPM_INTERNAL_PLUGINSHORTCUTMOTIFIED:
{ {
@ -567,8 +557,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
scnN.nmhdr.hwndFrom = (void *)lParam; // ShortcutKey structure scnN.nmhdr.hwndFrom = (void *)lParam; // ShortcutKey structure
scnN.nmhdr.idFrom = (uptr_t)wParam; // cmdID scnN.nmhdr.idFrom = (uptr_t)wParam; // cmdID
_pluginsManager.notify(&scnN); _pluginsManager.notify(&scnN);
}
return TRUE; return TRUE;
}
case NPPM_GETSHORTCUTBYCMDID: case NPPM_GETSHORTCUTBYCMDID:
{ {
@ -579,8 +569,10 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
} }
case NPPM_MENUCOMMAND: case NPPM_MENUCOMMAND:
{
command(lParam); command(lParam);
return TRUE; return TRUE;
}
case NPPM_GETFULLCURRENTPATH: case NPPM_GETFULLCURRENTPATH:
case NPPM_GETCURRENTDIRECTORY: case NPPM_GETCURRENTDIRECTORY:
@ -717,13 +709,15 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
case NPPM_GETOPENFILENAMESSECOND: case NPPM_GETOPENFILENAMESSECOND:
case NPPM_GETOPENFILENAMES: case NPPM_GETOPENFILENAMES:
{ {
if (!wParam) return 0; if (!wParam)
return 0;
TCHAR** fileNames = (TCHAR**) wParam; TCHAR** fileNames = (TCHAR**) wParam;
int nbFileNames = lParam; int nbFileNames = lParam;
int j = 0; int j = 0;
if (Message != NPPM_GETOPENFILENAMESSECOND) { if (Message != NPPM_GETOPENFILENAMESSECOND)
{
for (int i = 0 ; i < _mainDocTab.nbItem() && j < nbFileNames ; ++i) for (int i = 0 ; i < _mainDocTab.nbItem() && j < nbFileNames ; ++i)
{ {
BufferID id = _mainDocTab.getBufferByIndex(i); BufferID id = _mainDocTab.getBufferByIndex(i);
@ -731,7 +725,9 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
lstrcpy(fileNames[j++], buf->getFullPathName()); lstrcpy(fileNames[j++], buf->getFullPathName());
} }
} }
if (Message != NPPM_GETOPENFILENAMESPRIMARY) {
if (Message != NPPM_GETOPENFILENAMESPRIMARY)
{
for (int i = 0 ; i < _subDocTab.nbItem() && j < nbFileNames ; ++i) for (int i = 0 ; i < _subDocTab.nbItem() && j < nbFileNames ; ++i)
{ {
BufferID id = _subDocTab.getBufferByIndex(i); BufferID id = _subDocTab.getBufferByIndex(i);
@ -744,7 +740,9 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
case WM_GETTASKLISTINFO: case WM_GETTASKLISTINFO:
{ {
if (!wParam) return 0; if (!wParam)
return 0;
TaskListInfo * tli = (TaskListInfo *)wParam; TaskListInfo * tli = (TaskListInfo *)wParam;
getTaskListInfo(tli); getTaskListInfo(tli);
@ -761,6 +759,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
} }
return TRUE; return TRUE;
} }
if (NppParameters::getInstance()->getNppGUI()._styleMRU) if (NppParameters::getInstance()->getNppGUI()._styleMRU)
{ {
tli->_currentIndex = 0; tli->_currentIndex = 0;
@ -783,7 +782,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
case WM_MOUSEWHEEL: case WM_MOUSEWHEEL:
{ {
if (LOWORD(wParam) & MK_RBUTTON) if (0 != (LOWORD(wParam) & MK_RBUTTON))
{ {
// redirect to the IDC_PREV_DOC or IDC_NEXT_DOC so that we have the unified process // redirect to the IDC_PREV_DOC or IDC_NEXT_DOC so that we have the unified process
@ -800,11 +799,14 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
{ {
case APPCOMMAND_BROWSER_BACKWARD: case APPCOMMAND_BROWSER_BACKWARD:
case APPCOMMAND_BROWSER_FORWARD: case APPCOMMAND_BROWSER_FORWARD:
{
int nbDoc = viewVisible(MAIN_VIEW)?_mainDocTab.nbItem():0; int nbDoc = viewVisible(MAIN_VIEW)?_mainDocTab.nbItem():0;
nbDoc += viewVisible(SUB_VIEW)?_subDocTab.nbItem():0; nbDoc += viewVisible(SUB_VIEW)?_subDocTab.nbItem():0;
if (nbDoc > 1) if (nbDoc > 1)
activateNextDoc((GET_APPCOMMAND_LPARAM(lParam) == APPCOMMAND_BROWSER_FORWARD)?dirDown:dirUp); activateNextDoc((GET_APPCOMMAND_LPARAM(lParam) == APPCOMMAND_BROWSER_FORWARD)?dirDown:dirUp);
_linkTriggered = true; _linkTriggered = true;
break;
}
} }
return ::DefWindowProc(hwnd, Message, wParam, lParam); return ::DefWindowProc(hwnd, Message, wParam, lParam);
} }
@ -812,12 +814,11 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
case NPPM_GETNBSESSIONFILES: case NPPM_GETNBSESSIONFILES:
{ {
const TCHAR *sessionFileName = (const TCHAR *)lParam; const TCHAR *sessionFileName = (const TCHAR *)lParam;
if ((!sessionFileName) || (sessionFileName[0] == '\0')) return 0; if ((!sessionFileName) || (sessionFileName[0] == '\0'))
return 0;
Session session2Load; Session session2Load;
if (pNppParam->loadSession(session2Load, sessionFileName)) if (pNppParam->loadSession(session2Load, sessionFileName))
{
return session2Load.nbMainFiles() + session2Load.nbSubFiles(); return session2Load.nbMainFiles() + session2Load.nbSubFiles();
}
return 0; return 0;
} }
@ -826,7 +827,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
const TCHAR *sessionFileName = (const TCHAR *)lParam; const TCHAR *sessionFileName = (const TCHAR *)lParam;
TCHAR **sessionFileArray = (TCHAR **)wParam; TCHAR **sessionFileArray = (TCHAR **)wParam;
if ((!sessionFileName) || (sessionFileName[0] == '\0')) return FALSE; if ((!sessionFileName) || (sessionFileName[0] == '\0'))
return FALSE;
Session session2Load; Session session2Load;
if (pNppParam->loadSession(session2Load, sessionFileName)) if (pNppParam->loadSession(session2Load, sessionFileName))
@ -851,11 +853,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
case NPPM_DECODESCI: case NPPM_DECODESCI:
{ {
// convert to ASCII // convert to ASCII
Utf8_16_Write UnicodeConvertor;
UINT length = 0;
char* buffer = NULL;
ScintillaEditView *pSci; ScintillaEditView *pSci;
if (wParam == MAIN_VIEW) if (wParam == MAIN_VIEW)
pSci = &_mainEditView; pSci = &_mainEditView;
else if (wParam == SUB_VIEW) else if (wParam == SUB_VIEW)
@ -863,14 +861,14 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
else else
return -1; return -1;
// get text of current scintilla // get text of current scintilla
length = pSci->execute(SCI_GETTEXTLENGTH, 0, 0) + 1; UINT length = pSci->execute(SCI_GETTEXTLENGTH, 0, 0) + 1;
buffer = new char[length]; char* buffer = new char[length];
pSci->execute(SCI_GETTEXT, length, (LPARAM)buffer); pSci->execute(SCI_GETTEXT, length, (LPARAM)buffer);
// convert here // convert here
UniMode unicodeMode = pSci->getCurrentBuffer()->getUnicodeMode(); UniMode unicodeMode = pSci->getCurrentBuffer()->getUnicodeMode();
Utf8_16_Write UnicodeConvertor;
UnicodeConvertor.setEncoding(unicodeMode); UnicodeConvertor.setEncoding(unicodeMode);
length = UnicodeConvertor.convert(buffer, length-1); length = UnicodeConvertor.convert(buffer, length-1);
@ -893,11 +891,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
case NPPM_ENCODESCI: case NPPM_ENCODESCI:
{ {
// convert // convert
Utf8_16_Read UnicodeConvertor;
UINT length = 0;
char* buffer = NULL;
ScintillaEditView *pSci; ScintillaEditView *pSci;
if (wParam == MAIN_VIEW) if (wParam == MAIN_VIEW)
pSci = &_mainEditView; pSci = &_mainEditView;
else if (wParam == SUB_VIEW) else if (wParam == SUB_VIEW)
@ -906,18 +900,17 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
return -1; return -1;
// get text of current scintilla // get text of current scintilla
length = pSci->execute(SCI_GETTEXTLENGTH, 0, 0) + 1; UINT length = pSci->execute(SCI_GETTEXTLENGTH, 0, 0) + 1;
buffer = new char[length]; char* buffer = new char[length];
pSci->execute(SCI_GETTEXT, length, (LPARAM)buffer); pSci->execute(SCI_GETTEXT, length, (LPARAM)buffer);
Utf8_16_Read UnicodeConvertor;
length = UnicodeConvertor.convert(buffer, length-1); length = UnicodeConvertor.convert(buffer, length-1);
// set text in target // set text in target
pSci->execute(SCI_CLEARALL); pSci->execute(SCI_CLEARALL);
pSci->addText(length, UnicodeConvertor.getNewBuf()); pSci->addText(length, UnicodeConvertor.getNewBuf());
pSci->execute(SCI_EMPTYUNDOBUFFER); pSci->execute(SCI_EMPTYUNDOBUFFER);
// set cursor position // set cursor position
@ -968,7 +961,9 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
for (int i = 0 ; verStr[i] ; ++i) for (int i = 0 ; verStr[i] ; ++i)
{ {
if (verStr[i] == '.') if (verStr[i] == '.')
{
isDot = true; isDot = true;
}
else else
{ {
if (!isDot) if (!isDot)
@ -977,6 +972,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
auxVerStr[k++] = verStr[i]; auxVerStr[k++] = verStr[i];
} }
} }
mainVerStr[j] = '\0'; mainVerStr[j] = '\0';
auxVerStr[k] = '\0'; auxVerStr[k] = '\0';
@ -991,16 +987,23 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
} }
case WM_GETCURRENTMACROSTATUS: case WM_GETCURRENTMACROSTATUS:
if (_recordingMacro) return MACRO_RECORDING_IN_PROGRESS; {
if (_recordingMacro)
return MACRO_RECORDING_IN_PROGRESS;
return (_macro.empty())?0:MACRO_RECORDING_HAS_STOPPED; return (_macro.empty())?0:MACRO_RECORDING_HAS_STOPPED;
}
case WM_FRSAVE_INT: case WM_FRSAVE_INT:
{
_macro.push_back(recordedMacroStep(wParam, 0, lParam, NULL, recordedMacroStep::mtSavedSnR)); _macro.push_back(recordedMacroStep(wParam, 0, lParam, NULL, recordedMacroStep::mtSavedSnR));
break; break;
}
case WM_FRSAVE_STR: case WM_FRSAVE_STR:
{
_macro.push_back(recordedMacroStep(wParam, 0, 0, (const TCHAR *)lParam, recordedMacroStep::mtSavedSnR)); _macro.push_back(recordedMacroStep(wParam, 0, 0, (const TCHAR *)lParam, recordedMacroStep::mtSavedSnR));
break; break;
}
case WM_MACRODLGRUNMACRO: case WM_MACRODLGRUNMACRO:
{ {
@ -1008,17 +1011,11 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
{ {
int times = 1; int times = 1;
if (_runMacroDlg.getMode() == RM_RUN_MULTI) if (_runMacroDlg.getMode() == RM_RUN_MULTI)
{
times = _runMacroDlg.getTimes(); times = _runMacroDlg.getTimes();
}
else if (_runMacroDlg.getMode() == RM_RUN_EOF) else if (_runMacroDlg.getMode() == RM_RUN_EOF)
{
times = -1; times = -1;
}
else else
{
break; break;
}
int counter = 0; int counter = 0;
int lastLine = int(_pEditView->execute(SCI_GETLINECOUNT)) - 1; int lastLine = int(_pEditView->execute(SCI_GETLINECOUNT)) - 1;
@ -1042,7 +1039,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
++counter; ++counter;
if ( times >= 0 ) if ( times >= 0 )
{ {
if ( counter >= times ) break; if ( counter >= times )
break;
} }
else // run until eof else // run until eof
{ {
@ -1065,13 +1063,15 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
// eof? // eof?
if ((currLine >= lastLine) || (currLine < 0) if ((currLine >= lastLine) || (currLine < 0)
|| ((deltaCurrLine == 0) && (currLine == 0) && ((deltaLastLine >= 0) || cursorMovedUp))) || ((deltaCurrLine == 0) && (currLine == 0) && ((deltaLastLine >= 0) || cursorMovedUp)))
{
break; break;
} }
} }
}
_pEditView->execute(SCI_ENDUNDOACTION); _pEditView->execute(SCI_ENDUNDOACTION);
} }
}
break; break;
}
case NPPM_CREATESCINTILLAHANDLE: case NPPM_CREATESCINTILLAHANDLE:
{ {
@ -1089,7 +1089,6 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
return TRUE; return TRUE;
} }
case NPPM_DESTROYSCINTILLAHANDLE: case NPPM_DESTROYSCINTILLAHANDLE:
{ {
return _scintillaCtrls4Plugins.destroyScintilla((HWND)lParam); return _scintillaCtrls4Plugins.destroyScintilla((HWND)lParam);
@ -1176,9 +1175,9 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
{ {
_mainEditView.execute(SCI_ASSIGNCMDKEY, wParam, lParam); _mainEditView.execute(SCI_ASSIGNCMDKEY, wParam, lParam);
_subEditView.execute(SCI_ASSIGNCMDKEY, wParam, lParam); _subEditView.execute(SCI_ASSIGNCMDKEY, wParam, lParam);
return TRUE; return TRUE;
} }
case NPPM_INTERNAL_CMDLIST_MODIFIED: case NPPM_INTERNAL_CMDLIST_MODIFIED:
{ {
//changeMenuShortcut(lParam, (const TCHAR *)wParam); //changeMenuShortcut(lParam, (const TCHAR *)wParam);
@ -1253,22 +1252,30 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
if (wParam == MODELESSDIALOGADD) if (wParam == MODELESSDIALOGADD)
{ {
for (size_t i = 0, len = _hModelessDlgs.size() ; i < len ; ++i) for (size_t i = 0, len = _hModelessDlgs.size() ; i < len ; ++i)
{
if (_hModelessDlgs[i] == (HWND)lParam) if (_hModelessDlgs[i] == (HWND)lParam)
return NULL; return NULL;
}
_hModelessDlgs.push_back((HWND)lParam); _hModelessDlgs.push_back((HWND)lParam);
return lParam; return lParam;
} }
else if (wParam == MODELESSDIALOGREMOVE) else
{
if (wParam == MODELESSDIALOGREMOVE)
{ {
for (size_t i = 0, len = _hModelessDlgs.size(); i < len ; ++i) for (size_t i = 0, len = _hModelessDlgs.size(); i < len ; ++i)
{
if (_hModelessDlgs[i] == (HWND)lParam) if (_hModelessDlgs[i] == (HWND)lParam)
{ {
vector<HWND>::iterator hDlg = _hModelessDlgs.begin() + i; vector<HWND>::iterator hDlg = _hModelessDlgs.begin() + i;
_hModelessDlgs.erase(hDlg); _hModelessDlgs.erase(hDlg);
return NULL; return NULL;
} }
}
return lParam; return lParam;
} }
}
return TRUE; return TRUE;
} }
@ -1282,15 +1289,15 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
{ {
if ((HWND(wParam) == _mainEditView.getHSelf()) || (HWND(wParam) == _subEditView.getHSelf())) if ((HWND(wParam) == _mainEditView.getHSelf()) || (HWND(wParam) == _subEditView.getHSelf()))
{ {
if ((HWND(wParam) == _mainEditView.getHSelf())) { if ((HWND(wParam) == _mainEditView.getHSelf()))
switchEditViewTo(MAIN_VIEW); switchEditViewTo(MAIN_VIEW);
} else { else
switchEditViewTo(SUB_VIEW); switchEditViewTo(SUB_VIEW);
}
POINT p; POINT p;
::GetCursorPos(&p); ::GetCursorPos(&p);
ContextMenu scintillaContextmenu; ContextMenu scintillaContextmenu;
vector<MenuItemUnit> & tmp = pNppParam->getContextMenuItems(); std::vector<MenuItemUnit>& tmp = pNppParam->getContextMenuItems();
scintillaContextmenu.create(_pPublicInterface->getHSelf(), tmp, _mainMenuHandle); scintillaContextmenu.create(_pPublicInterface->getHSelf(), tmp, _mainMenuHandle);
scintillaContextmenu.display(p); scintillaContextmenu.display(p);
return TRUE; return TRUE;
@ -1405,8 +1412,10 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
} }
case WM_ACTIVATE: case WM_ACTIVATE:
{
_pEditView->getFocus(); _pEditView->getFocus();
return TRUE; return TRUE;
}
case WM_DROPFILES: case WM_DROPFILES:
{ {
@ -1465,20 +1474,21 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
_pProjectPanel_1->setBackgroundColor(style._bgColor); _pProjectPanel_1->setBackgroundColor(style._bgColor);
_pProjectPanel_1->setForegroundColor(style._fgColor); _pProjectPanel_1->setForegroundColor(style._fgColor);
} }
if (_pProjectPanel_2) if (_pProjectPanel_2)
{ {
_pProjectPanel_2->setBackgroundColor(style._bgColor); _pProjectPanel_2->setBackgroundColor(style._bgColor);
_pProjectPanel_2->setForegroundColor(style._fgColor); _pProjectPanel_2->setForegroundColor(style._fgColor);
} }
if (_pProjectPanel_3) if (_pProjectPanel_3)
{ {
_pProjectPanel_3->setBackgroundColor(style._bgColor); _pProjectPanel_3->setBackgroundColor(style._bgColor);
_pProjectPanel_3->setForegroundColor(style._fgColor); _pProjectPanel_3->setForegroundColor(style._fgColor);
} }
if (_pDocMap) if (_pDocMap)
{
_pDocMap->setSyntaxHiliting(); _pDocMap->setSyntaxHiliting();
}
// Notify plugins of update to styles xml // Notify plugins of update to styles xml
SCNotification scnN; SCNotification scnN;
@ -1512,10 +1522,10 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
bool isSnapshotMode = nppgui.isSnapshotMode(); bool isSnapshotMode = nppgui.isSnapshotMode();
if (isSnapshotMode) if (isSnapshotMode)
{
::LockWindowUpdate(_pPublicInterface->getHSelf()); ::LockWindowUpdate(_pPublicInterface->getHSelf());
if (isSnapshotMode)
MainFileManager->backupCurrentBuffer(); MainFileManager->backupCurrentBuffer();
}
Session currentSession; Session currentSession;
if (nppgui._rememberLastSession) if (nppgui._rememberLastSession)
@ -1528,16 +1538,13 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
bool allClosed = fileCloseAll(false, isSnapshotMode); //try closing files before doing anything else bool allClosed = fileCloseAll(false, isSnapshotMode); //try closing files before doing anything else
if (nppgui._rememberLastSession) if (nppgui._rememberLastSession)
{
_lastRecentFileList.setLock(false); //only lock when the session is remembered _lastRecentFileList.setLock(false); //only lock when the session is remembered
}
if (!allClosed) if (!allClosed)
{ {
//User cancelled the shutdown //User cancelled the shutdown
scnN.nmhdr.code = NPPN_CANCELSHUTDOWN; scnN.nmhdr.code = NPPN_CANCELSHUTDOWN;
_pluginsManager.notify(&scnN); _pluginsManager.notify(&scnN);
return FALSE; return FALSE;
} }
@ -1600,6 +1607,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
if (Message == WM_CLOSE) if (Message == WM_CLOSE)
::DestroyWindow(hwnd); ::DestroyWindow(hwnd);
if (not isSnapshotMode)
::LockWindowUpdate(NULL); ::LockWindowUpdate(NULL);
} }
return TRUE; return TRUE;
@ -1625,7 +1633,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
NppGUI & nppgui = (NppGUI &)(pNppParam->getNppGUI()); NppGUI & nppgui = (NppGUI &)(pNppParam->getNppGUI());
if ((nppgui._isMinimizedToTray || _pPublicInterface->isPrelaunch()) && (wParam == SC_MINIMIZE)) if ((nppgui._isMinimizedToTray || _pPublicInterface->isPrelaunch()) && (wParam == SC_MINIMIZE))
{ {
if (!_pTrayIco) if (nullptr == _pTrayIco)
_pTrayIco = new trayIconControler(_pPublicInterface->getHSelf(), IDI_M30ICON, IDC_MINIMIZED_TRAY, ::LoadIcon(_pPublicInterface->getHinst(), MAKEINTRESOURCE(IDI_M30ICON)), TEXT("")); _pTrayIco = new trayIconControler(_pPublicInterface->getHSelf(), IDI_M30ICON, IDC_MINIMIZED_TRAY, ::LoadIcon(_pPublicInterface->getHinst(), MAKEINTRESOURCE(IDI_M30ICON)), TEXT(""));
_pTrayIco->doTrayIcon(ADD); _pTrayIco->doTrayIcon(ADD);
@ -1657,16 +1665,20 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
{ {
//case WM_LBUTTONDBLCLK: //case WM_LBUTTONDBLCLK:
case WM_LBUTTONUP : case WM_LBUTTONUP :
{
_pEditView->getFocus(); _pEditView->getFocus();
::ShowWindow(_pPublicInterface->getHSelf(), SW_SHOW); ::ShowWindow(_pPublicInterface->getHSelf(), SW_SHOW);
if (!_pPublicInterface->isPrelaunch()) if (!_pPublicInterface->isPrelaunch())
_pTrayIco->doTrayIcon(REMOVE); _pTrayIco->doTrayIcon(REMOVE);
::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); ::SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0);
return TRUE; return TRUE;
}
case WM_MBUTTONUP: case WM_MBUTTONUP:
{
command(IDM_SYSTRAYPOPUP_NEW_AND_PASTE); command(IDM_SYSTRAYPOPUP_NEW_AND_PASTE);
return TRUE; return TRUE;
}
case WM_RBUTTONUP: case WM_RBUTTONUP:
{ {
@ -1683,7 +1695,6 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
DestroyMenu(hmenu); DestroyMenu(hmenu);
return TRUE; return TRUE;
} }
} }
return TRUE; return TRUE;
} }
@ -1726,21 +1737,24 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
case NPPM_DMMGETPLUGINHWNDBYNAME : //(const TCHAR *windowName, const TCHAR *moduleName) case NPPM_DMMGETPLUGINHWNDBYNAME : //(const TCHAR *windowName, const TCHAR *moduleName)
{ {
if (!lParam) return NULL; if (!lParam)
return NULL;
TCHAR *moduleName = (TCHAR *)lParam; TCHAR *moduleName = (TCHAR *)lParam;
TCHAR *windowName = (TCHAR *)wParam; TCHAR *windowName = (TCHAR *)wParam;
vector<DockingCont *> dockContainer = _dockingManager.getContainerInfo(); std::vector<DockingCont *> dockContainer = _dockingManager.getContainerInfo();
for (size_t i = 0, len = dockContainer.size(); i < len ; ++i) for (size_t i = 0, len = dockContainer.size(); i < len ; ++i)
{ {
vector<tTbData *> tbData = dockContainer[i]->getDataOfAllTb(); std::vector<tTbData *> tbData = dockContainer[i]->getDataOfAllTb();
for (size_t j = 0, len2 = tbData.size() ; j < len2 ; ++j) for (size_t j = 0, len2 = tbData.size() ; j < len2 ; ++j)
{ {
if (generic_stricmp(moduleName, tbData[j]->pszModuleName) == 0) if (generic_stricmp(moduleName, tbData[j]->pszModuleName) == 0)
{ {
if (!windowName) if (!windowName)
return (LRESULT)tbData[j]->hClient; return (LRESULT)tbData[j]->hClient;
else if (generic_stricmp(windowName, tbData[j]->pszName) == 0)
if (generic_stricmp(windowName, tbData[j]->pszName) == 0)
return (LRESULT)tbData[j]->hClient; return (LRESULT)tbData[j]->hClient;
} }
} }
@ -1806,13 +1820,19 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
} }
case NPPM_ALLOCATESUPPORTED: case NPPM_ALLOCATESUPPORTED:
{
return TRUE; return TRUE;
}
case NPPM_ALLOCATECMDID: case NPPM_ALLOCATECMDID:
{
return _pluginsManager.allocateCmdID(wParam, reinterpret_cast<int *>(lParam)); return _pluginsManager.allocateCmdID(wParam, reinterpret_cast<int *>(lParam));
}
case NPPM_ALLOCATEMARKER: case NPPM_ALLOCATEMARKER:
{
return _pluginsManager.allocateMarker(wParam, reinterpret_cast<int *>(lParam)); return _pluginsManager.allocateMarker(wParam, reinterpret_cast<int *>(lParam));
}
case NPPM_HIDETABBAR: case NPPM_HIDETABBAR:
{ {
@ -1831,12 +1851,12 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
return oldVal; return oldVal;
} }
case NPPM_ISTABBARHIDDEN: case NPPM_ISTABBARHIDDEN:
{ {
return _mainDocTab.getHideTabBarStatus(); return _mainDocTab.getHideTabBarStatus();
} }
case NPPM_HIDETOOLBAR: case NPPM_HIDETOOLBAR:
{ {
bool show = (lParam != TRUE); bool show = (lParam != TRUE);
@ -1845,6 +1865,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
_rebarTop.setIDVisible(REBAR_BAR_TOOLBAR, show); _rebarTop.setIDVisible(REBAR_BAR_TOOLBAR, show);
return currentStatus; return currentStatus;
} }
case NPPM_ISTOOLBARHIDDEN : case NPPM_ISTOOLBARHIDDEN :
{ {
return !_rebarTop.getIDVisible(REBAR_BAR_TOOLBAR); return !_rebarTop.getIDVisible(REBAR_BAR_TOOLBAR);
@ -1866,6 +1887,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
return isHidden; return isHidden;
} }
case NPPM_ISMENUHIDDEN: case NPPM_ISMENUHIDDEN:
{ {
return (::GetMenu(_pPublicInterface->getHSelf()) == NULL); return (::GetMenu(_pPublicInterface->getHSelf()) == NULL);
@ -1877,9 +1899,8 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
NppGUI & nppGUI = (NppGUI &)pNppParam->getNppGUI(); NppGUI & nppGUI = (NppGUI &)pNppParam->getNppGUI();
bool oldVal = nppGUI._statusBarShow; bool oldVal = nppGUI._statusBarShow;
if (show == oldVal) if (show == oldVal)
{
return oldVal; return oldVal;
}
RECT rc; RECT rc;
_pPublicInterface->getClientRect(rc); _pPublicInterface->getClientRect(rc);
@ -1899,31 +1920,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
{ {
return _activeView; return _activeView;
} }
/*
case NPPM_ADDREBAR :
{
if (!lParam)
return FALSE;
_rebarTop.addBand((REBARBANDINFO*)lParam, false);
return TRUE;
}
case NPPM_UPDATEREBAR :
{
if (!lParam || wParam < REBAR_BAR_EXTERNAL)
return FALSE;
_rebarTop.reNew((int)wParam, (REBARBANDINFO*)lParam);
return TRUE;
}
case NPPM_REMOVEREBAR :
{
if (wParam < REBAR_BAR_EXTERNAL)
return FALSE;
_rebarTop.removeBand((int)wParam);
return TRUE;
}
*/
case NPPM_INTERNAL_ISFOCUSEDTAB: case NPPM_INTERNAL_ISFOCUSEDTAB:
{ {
HWND hTabToTest = (currentView() == MAIN_VIEW)?_mainDocTab.getHSelf():_subDocTab.getHSelf(); HWND hTabToTest = (currentView() == MAIN_VIEW)?_mainDocTab.getHSelf():_subDocTab.getHSelf();
@ -1940,12 +1937,14 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
_pEditView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_SMART); _pEditView->clearIndicator(SCE_UNIVERSAL_FOUND_STYLE_SMART);
return TRUE; return TRUE;
} }
case NPPM_INTERNAL_CLEARINDICATORTAGMATCH: case NPPM_INTERNAL_CLEARINDICATORTAGMATCH:
{ {
_pEditView->clearIndicator(SCE_UNIVERSAL_TAGMATCH); _pEditView->clearIndicator(SCE_UNIVERSAL_TAGMATCH);
_pEditView->clearIndicator(SCE_UNIVERSAL_TAGATTR); _pEditView->clearIndicator(SCE_UNIVERSAL_TAGATTR);
return TRUE; return TRUE;
} }
case NPPM_INTERNAL_CLEARINDICATORTAGATTR: case NPPM_INTERNAL_CLEARINDICATORTAGATTR:
{ {
_pEditView->clearIndicator(SCE_UNIVERSAL_TAGATTR); _pEditView->clearIndicator(SCE_UNIVERSAL_TAGATTR);
@ -2013,13 +2012,9 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
case NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR: case NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR:
case NPPM_GETEDITORDEFAULTBACKGROUNDCOLOR: case NPPM_GETEDITORDEFAULTBACKGROUNDCOLOR:
{ {
return (Message == NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR?(NppParameters::getInstance())->getCurrentDefaultFgColor():(NppParameters::getInstance())->getCurrentDefaultBgColor()); return (Message == NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR
/* ?(NppParameters::getInstance())->getCurrentDefaultFgColor()
StyleArray & globalStyles = (NppParameters::getInstance())->getGlobalStylers(); :(NppParameters::getInstance())->getCurrentDefaultBgColor());
int i = globalStyles.getStylerIndexByID(STYLE_DEFAULT);
Style & style = globalStyles.getStyler(i);
return (Message == NPPM_GETEDITORDEFAULTFOREGROUNDCOLOR?style._fgColor:style._bgColor);
*/
} }
case NPPM_SHOWDOCSWITCHER: case NPPM_SHOWDOCSWITCHER:
@ -2122,8 +2117,6 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
case WM_DPICHANGED: case WM_DPICHANGED:
{ {
//printInt(LOWORD(wParam));
//printInt(HIWORD(wParam));
return TRUE; return TRUE;
} }
@ -2135,9 +2128,12 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
switch (nmdlg->type) switch (nmdlg->type)
{ {
case WDT_ACTIVATE: case WDT_ACTIVATE:
{
activateDoc(nmdlg->curSel); activateDoc(nmdlg->curSel);
nmdlg->processed = TRUE; nmdlg->processed = TRUE;
break; break;
}
case WDT_SAVE: case WDT_SAVE:
{ {
//loop through nmdlg->nItems, get index and save it //loop through nmdlg->nItems, get index and save it
@ -2146,16 +2142,15 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
fileSave(_pDocTab->getBufferByIndex(i)); fileSave(_pDocTab->getBufferByIndex(i));
} }
nmdlg->processed = TRUE; nmdlg->processed = TRUE;
}
break; break;
}
case WDT_CLOSE: case WDT_CLOSE:
{ {
bool closed;
//loop through nmdlg->nItems, get index and close it //loop through nmdlg->nItems, get index and close it
for (int i = 0; i < (int)nmdlg->nItems; ++i) for (int i = 0; i < (int)nmdlg->nItems; ++i)
{ {
closed = fileClose(_pDocTab->getBufferByIndex(nmdlg->Items[i]), currentView()); bool closed = fileClose(_pDocTab->getBufferByIndex(nmdlg->Items[i]), currentView());
UINT pos = nmdlg->Items[i]; UINT pos = nmdlg->Items[i];
// The window list only needs to be rearranged when the file was actually closed // The window list only needs to be rearranged when the file was actually closed
if (closed) if (closed)
@ -2166,18 +2161,19 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
for (int j = i + 1; j < (int)nmdlg->nItems; ++j) for (int j = i + 1; j < (int)nmdlg->nItems; ++j)
{ {
if (nmdlg->Items[j] > pos) if (nmdlg->Items[j] > pos)
{
nmdlg->Items[j]--; nmdlg->Items[j]--;
} }
} }
} }
}
nmdlg->processed = TRUE; nmdlg->processed = TRUE;
}
break; break;
}
case WDT_SORT: case WDT_SORT:
{
if (nmdlg->nItems != (unsigned int)_pDocTab->nbItem()) //sanity check, if mismatch just abort if (nmdlg->nItems != (unsigned int)_pDocTab->nbItem()) //sanity check, if mismatch just abort
break; break;
//Collect all buffers //Collect all buffers
std::vector<BufferID> tempBufs; std::vector<BufferID> tempBufs;
for (int i = 0; i < (int)nmdlg->nItems; ++i) for (int i = 0; i < (int)nmdlg->nItems; ++i)
@ -2192,6 +2188,7 @@ LRESULT Notepad_plus::process(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lPa
activateBuffer(_pDocTab->getBufferByIndex(_pDocTab->getCurrentTabIndex()), currentView()); activateBuffer(_pDocTab->getBufferByIndex(_pDocTab->getCurrentTabIndex()), currentView());
break; break;
} }
}
return TRUE; return TRUE;
} }

View File

@ -1051,7 +1051,7 @@ void Notepad_plus::command(int id)
else else
pWindow = _pDocTab; pWindow = _pDocTab;
_pMainSplitter->create(pWindow, ScintillaEditView::getUserDefineDlg(), 8, RIGHT_FIX, 45); _pMainSplitter->create(pWindow, ScintillaEditView::getUserDefineDlg(), 8, SplitterMode::RIGHT_FIX, 45);
} }
_pMainWindow = _pMainSplitter; _pMainWindow = _pMainSplitter;

View File

@ -36,6 +36,10 @@
using namespace std; using namespace std;
BOOL Notepad_plus::notify(SCNotification *notification) BOOL Notepad_plus::notify(SCNotification *notification)
{ {
//Important, keep track of which element generated the message //Important, keep track of which element generated the message
@ -76,9 +80,8 @@ BOOL Notepad_plus::notify(SCNotification *notification)
prevWasEdit = false; prevWasEdit = false;
} }
}
break; break;
}
case SCN_SAVEPOINTREACHED: case SCN_SAVEPOINTREACHED:
case SCN_SAVEPOINTLEFT: case SCN_SAVEPOINTLEFT:
@ -105,19 +108,16 @@ BOOL Notepad_plus::notify(SCNotification *notification)
id = MainFileManager->getBufferFromDocument(_fileEditView.execute(SCI_GETDOCPOINTER)); id = MainFileManager->getBufferFromDocument(_fileEditView.execute(SCI_GETDOCPOINTER));
} }
else else
{
break; //wrong scintilla break; //wrong scintilla
}
if (id != BUFFER_INVALID) if (id != BUFFER_INVALID)
{ {
buf = MainFileManager->getBufferByID(id); buf = MainFileManager->getBufferByID(id);
} }
else else
{
break; break;
} }
}
bool isDirty = notification->nmhdr.code == SCN_SAVEPOINTLEFT; bool isDirty = notification->nmhdr.code == SCN_SAVEPOINTLEFT;
bool isSnapshotMode = NppParameters::getInstance()->getNppGUI().isSnapshotMode(); bool isSnapshotMode = NppParameters::getInstance()->getNppGUI().isSnapshotMode();
if (isSnapshotMode && !isDirty) if (isSnapshotMode && !isDirty)
@ -131,11 +131,15 @@ BOOL Notepad_plus::notify(SCNotification *notification)
} }
case SCN_MODIFYATTEMPTRO: case SCN_MODIFYATTEMPTRO:
// on fout rien {
// nothing to do
break; break;
}
case SCN_KEY: case SCN_KEY:
{
break; break;
}
case TCN_TABDROPPEDOUTSIDE: case TCN_TABDROPPEDOUTSIDE:
case TCN_TABDROPPED: case TCN_TABDROPPED:
@ -254,9 +258,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
iView = SUB_VIEW; iView = SUB_VIEW;
} }
else else
{
break; break;
}
switchEditViewTo(iView); switchEditViewTo(iView);
BufferID bufid = _pDocTab->getBufferByIndex(_pDocTab->getCurrentTabIndex()); BufferID bufid = _pDocTab->getBufferByIndex(_pDocTab->getCurrentTabIndex());
@ -407,7 +409,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
if (!_tabPopupMenu.isCreated()) if (!_tabPopupMenu.isCreated())
{ {
vector<MenuItemUnit> itemUnitArray; std::vector<MenuItemUnit> itemUnitArray;
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSE, TEXT("Close"))); itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSE, TEXT("Close")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_BUT_CURRENT, TEXT("Close All BUT This"))); itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_BUT_CURRENT, TEXT("Close All BUT This")));
itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_TOLEFT, TEXT("Close All to the Left"))); itemUnitArray.push_back(MenuItemUnit(IDM_FILE_CLOSEALL_TOLEFT, TEXT("Close All to the Left")));
@ -488,8 +490,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
case SCN_FOLDINGSTATECHANGED : case SCN_FOLDINGSTATECHANGED :
{ {
if ((notification->nmhdr.hwndFrom == _mainEditView.getHSelf()) if ((notification->nmhdr.hwndFrom == _mainEditView.getHSelf()) || (notification->nmhdr.hwndFrom == _subEditView.getHSelf()))
|| (notification->nmhdr.hwndFrom == _subEditView.getHSelf()))
{ {
int lineClicked = notification->line; int lineClicked = notification->line;
@ -676,8 +677,9 @@ BOOL Notepad_plus::notify(SCNotification *notification)
notifyView->execute(SCI_SETANCHOR, pos); notifyView->execute(SCI_SETANCHOR, pos);
_isHotspotDblClicked = false; _isHotspotDblClicked = false;
} }
}
break; break;
}
case SCN_UPDATEUI: case SCN_UPDATEUI:
{ {
@ -725,7 +727,8 @@ BOOL Notepad_plus::notify(SCNotification *notification)
case TTN_GETDISPINFO: case TTN_GETDISPINFO:
{ {
try { try
{
LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT)notification; LPTOOLTIPTEXT lpttt = (LPTOOLTIPTEXT)notification;
//Joce's fix //Joce's fix
@ -776,22 +779,26 @@ BOOL Notepad_plus::notify(SCNotification *notification)
return TRUE; return TRUE;
} }
else else
{
return FALSE; return FALSE;
} }
} catch (...) { catch (...)
{
//printStr(TEXT("ToolTip crash is caught!")); //printStr(TEXT("ToolTip crash is caught!"));
} }
}
break; break;
}
case SCN_ZOOM: case SCN_ZOOM:
{
break; break;
}
case SCN_MACRORECORD: case SCN_MACRORECORD:
{
_macro.push_back(recordedMacroStep(notification->message, notification->wParam, notification->lParam, _pEditView->execute(SCI_GETCODEPAGE))); _macro.push_back(recordedMacroStep(notification->message, notification->wParam, notification->lParam, _pEditView->execute(SCI_GETCODEPAGE)));
break; break;
}
case SCN_PAINTED: case SCN_PAINTED:
{ {
@ -876,10 +883,9 @@ BOOL Notepad_plus::notify(SCNotification *notification)
int end = notifyView->execute(SCI_LINEFROMPOSITION, notification->position + notification->length); int end = notifyView->execute(SCI_LINEFROMPOSITION, notification->position + notification->length);
int firstLine = begin < end ? begin : end; int firstLine = begin < end ? begin : end;
int lastLine = begin > end ? begin : end; int lastLine = begin > end ? begin : end;
for (int line = firstLine; line <= lastLine; ++line) for (int line = firstLine; line <= lastLine; ++line)
{
notifyView->execute(SCI_ENSUREVISIBLE, line, 0); notifyView->execute(SCI_ENSUREVISIBLE, line, 0);
}
break; break;
} }
@ -895,12 +901,14 @@ BOOL Notepad_plus::notify(SCNotification *notification)
SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0); SendMessage(_pPublicInterface->getHSelf(), WM_SIZE, 0, 0);
break; break;
} }
case RBN_CHEVRONPUSHED: case RBN_CHEVRONPUSHED:
{ {
NMREBARCHEVRON * lpnm = (NMREBARCHEVRON*) notification; NMREBARCHEVRON * lpnm = (NMREBARCHEVRON*) notification;
ReBar * notifRebar = &_rebarTop; ReBar * notifRebar = &_rebarTop;
if (_rebarBottom.getHSelf() == lpnm->hdr.hwndFrom) if (_rebarBottom.getHSelf() == lpnm->hdr.hwndFrom)
notifRebar = &_rebarBottom; notifRebar = &_rebarBottom;
//If N++ ID, use proper object //If N++ ID, use proper object
if (lpnm->wID == REBAR_BAR_TOOLBAR) if (lpnm->wID == REBAR_BAR_TOOLBAR)
{ {
@ -911,6 +919,7 @@ BOOL Notepad_plus::notify(SCNotification *notification)
_toolBar.doPopop(pt); _toolBar.doPopop(pt);
return TRUE; return TRUE;
} }
//Else forward notification to window of rebarband //Else forward notification to window of rebarband
REBARBANDINFO rbBand; REBARBANDINFO rbBand;
ZeroMemory(&rbBand, REBARBAND_SIZE); ZeroMemory(&rbBand, REBARBAND_SIZE);

View File

@ -24,12 +24,13 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <iostream> #include <iostream>
#include "ColourPicker.h" #include "ColourPicker.h"
#include "ColourPopup.h" #include "ColourPopup.h"
void ColourPicker::init(HINSTANCE hInst, HWND parent) void ColourPicker::init(HINSTANCE hInst, HWND parent)
{ {
Window::init(hInst, parent); Window::init(hInst, parent);
@ -40,31 +41,24 @@ void ColourPicker::init(HINSTANCE hInst, HWND parent)
TEXT("F"), TEXT("F"),
WS_CHILD | WS_VISIBLE, WS_CHILD | WS_VISIBLE,
0, 0, 25, 25, 0, 0, 25, 25,
_hParent, _hParent, NULL, _hInst, (LPVOID)0);
NULL,
_hInst,
(LPVOID)0);
if (!_hSelf)
{
throw std::runtime_error("ColourPicker::init : CreateWindowEx() function return null");
}
if (!_hSelf)
throw std::runtime_error("ColourPicker::init : CreateWindowEx() function return null");
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (LONG_PTR)this); ::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (LONG_PTR)this);
_buttonDefaultProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, (LONG_PTR)staticWinProc)); _buttonDefaultProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, (LONG_PTR)staticWinProc));
} }
void ColourPicker::destroy() void ColourPicker::destroy()
{
if (_pColourPopup)
{ {
delete _pColourPopup; delete _pColourPopup;
_pColourPopup = NULL; _pColourPopup = NULL;
}
::DestroyWindow(_hSelf); ::DestroyWindow(_hSelf);
} }
void ColourPicker::drawBackground(HDC hDC) void ColourPicker::drawBackground(HDC hDC)
{ {
RECT rc; RECT rc;
@ -82,6 +76,7 @@ void ColourPicker::drawBackground(HDC hDC)
::DeleteObject(hbrush); ::DeleteObject(hbrush);
} }
void ColourPicker::drawForeground(HDC hDC) void ColourPicker::drawForeground(HDC hDC)
{ {
RECT rc; RECT rc;
@ -107,6 +102,7 @@ void ColourPicker::drawForeground(HDC hDC)
::SetBkMode(hDC, oldMode); ::SetBkMode(hDC, oldMode);
} }
LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam) LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam)
{ {
switch (Message) switch (Message)
@ -136,6 +132,7 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam)
} }
return TRUE; return TRUE;
} }
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
{ {
_isEnabled = !_isEnabled; _isEnabled = !_isEnabled;
@ -182,11 +179,14 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam)
} }
case WM_PICKUP_CANCEL: case WM_PICKUP_CANCEL:
{
_pColourPopup->display(false); _pColourPopup->display(false);
return TRUE; return TRUE;
}
default: default:
return ::CallWindowProc(_buttonDefaultProc, _hSelf, Message, wParam, lParam); return ::CallWindowProc(_buttonDefaultProc, _hSelf, Message, wParam, lParam);
} }
return FALSE; return FALSE;
} }

View File

@ -24,62 +24,54 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#pragma once
#ifndef COLOUR_POPUP_H
#define COLOUR_POPUP_H
#ifndef COLOUR_POPUP_RESOURCE_H
#include "ColourPopupResource.h" #include "ColourPopupResource.h"
#endif //COLOUR_POPUP_RESOURCE_H
#ifndef RESOURCE_H
#include "resource.h" #include "resource.h"
#endif //RESOURCE_H
#include "Window.h" #include "Window.h"
#define WM_PICKUP_COLOR (COLOURPOPUP_USER + 1) #define WM_PICKUP_COLOR (COLOURPOPUP_USER + 1)
#define WM_PICKUP_CANCEL (COLOURPOPUP_USER + 2) #define WM_PICKUP_CANCEL (COLOURPOPUP_USER + 2)
class ColourPopup : public Window class ColourPopup : public Window
{ {
public : public :
ColourPopup() : Window()/*, isColourChooserLaunched(false)*/ {}; ColourPopup() = default;
ColourPopup(COLORREF defaultColor) : Window(), /* isColourChooserLaunched(false), */ _colour(defaultColor) {}; explicit ColourPopup(COLORREF defaultColor) : _colour(defaultColor) {}
~ColourPopup(){}; virtual ~ColourPopup() {}
bool isCreated() const { bool isCreated() const
{
return (_hSelf != NULL); return (_hSelf != NULL);
}; }
void create(int dialogID); void create(int dialogID);
void doDialog(POINT p) { void doDialog(POINT p)
{
if (!isCreated()) if (!isCreated())
create(IDD_COLOUR_POPUP); create(IDD_COLOUR_POPUP);
::SetWindowPos(_hSelf, HWND_TOP, p.x, p.y, _rc.right - _rc.left, _rc.bottom - _rc.top, SWP_SHOWWINDOW); ::SetWindowPos(_hSelf, HWND_TOP, p.x, p.y, _rc.right - _rc.left, _rc.bottom - _rc.top, SWP_SHOWWINDOW);
}; }
virtual void destroy() { virtual void destroy()
{
::DestroyWindow(_hSelf); ::DestroyWindow(_hSelf);
}; }
void setColour(COLORREF c) { void setColour(COLORREF c)
{
_colour = c; _colour = c;
}; }
COLORREF getSelColour(){return _colour;}; COLORREF getSelColour(){return _colour;};
private : private :
RECT _rc; RECT _rc;
COLORREF _colour; COLORREF _colour;
//bool isColourChooserLaunched; //bool isColourChooserLaunched = false;
static INT_PTR CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); static INT_PTR CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam); INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
}; };
#endif //COLOUR_POPUP_H

View File

@ -24,11 +24,7 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#pragma once
#ifndef COLOUR_POPUP_RESOURCE_H
#define IDD_COLOUR_POPUP 2100 #define IDD_COLOUR_POPUP 2100
#define IDC_COLOUR_LIST (IDD_COLOUR_POPUP + 1) #define IDC_COLOUR_LIST (IDD_COLOUR_POPUP + 1)
#endif //COLOUR_POPUP_RESOURCE_H

View File

@ -142,9 +142,8 @@ INT_PTR CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM l
_pBgColour->init(_hInst, _hSelf); _pBgColour->init(_hInst, _hSelf);
POINT p1, p2; POINT p1, p2;
alignWith(_hFgColourStaticText, _pFgColour->getHSelf(), PosAlign::right, p1);
alignWith(_hFgColourStaticText, _pFgColour->getHSelf(), ALIGNPOS_RIGHT, p1); alignWith(_hBgColourStaticText, _pBgColour->getHSelf(), PosAlign::right, p2);
alignWith(_hBgColourStaticText, _pBgColour->getHSelf(), ALIGNPOS_RIGHT, p2);
p1.x = p2.x = ((p1.x > p2.x)?p1.x:p2.x) + 10; p1.x = p2.x = ((p1.x > p2.x)?p1.x:p2.x) + 10;
p1.y -= 4; p2.y -= 4; p1.y -= 4; p2.y -= 4;
@ -170,7 +169,6 @@ INT_PTR CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM l
goToCenter(); goToCenter();
loadLangListFromNppParam(); loadLangListFromNppParam();
return TRUE; return TRUE;
} }
@ -827,6 +825,7 @@ void WordStyleDlg::setVisualFromStyleList()
const TCHAR *ckwStr = (style._keywords)?style._keywords->c_str():TEXT(""); const TCHAR *ckwStr = (style._keywords)?style._keywords->c_str():TEXT("");
::SendDlgItemMessage(_hSelf, IDC_USER_KEYWORDS_EDIT, WM_SETTEXT, 0, (LPARAM)(ckwStr)); ::SendDlgItemMessage(_hSelf, IDC_USER_KEYWORDS_EDIT, WM_SETTEXT, 0, (LPARAM)(ckwStr));
} }
int showOption = shouldBeDisplayed?SW_SHOW:SW_HIDE; int showOption = shouldBeDisplayed?SW_SHOW:SW_HIDE;
::ShowWindow(::GetDlgItem(_hSelf, IDC_DEF_KEYWORDS_EDIT), showOption); ::ShowWindow(::GetDlgItem(_hSelf, IDC_DEF_KEYWORDS_EDIT), showOption);
::ShowWindow(::GetDlgItem(_hSelf, IDC_USER_KEYWORDS_EDIT),showOption); ::ShowWindow(::GetDlgItem(_hSelf, IDC_USER_KEYWORDS_EDIT),showOption);
@ -837,6 +836,7 @@ void WordStyleDlg::setVisualFromStyleList()
redraw(); redraw();
} }
void WordStyleDlg::create(int dialogID, bool isRTL) void WordStyleDlg::create(int dialogID, bool isRTL)
{ {
StaticDialog::create(dialogID, isRTL); StaticDialog::create(dialogID, isRTL);
@ -853,6 +853,7 @@ void WordStyleDlg::create(int dialogID, bool isRTL)
} }
} }
void WordStyleDlg::apply() void WordStyleDlg::apply()
{ {
LexerStylerArray & lsa = (NppParameters::getInstance())->getLStylerArray(); LexerStylerArray & lsa = (NppParameters::getInstance())->getLStylerArray();

View File

@ -24,8 +24,6 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <iostream> #include <iostream>
#include <windows.h> #include <windows.h>
#include "Splitter.h" #include "Splitter.h"
@ -38,28 +36,24 @@ bool Splitter::_isVerticalFixedRegistered = false;
#define SPLITTER_SIZE 8 #define SPLITTER_SIZE 8
Splitter::Splitter() : Window()
Splitter::Splitter()
{ {
//hInstance = GetModuleHandle(NULL);
_rect.left = 0; // x axis _rect.left = 0; // x axis
_rect.top = 0; // y axis _rect.top = 0; // y axis
_rect.right = 0; // Width of the spliter. _rect.right = 0; // Width of the spliter.
_rect.bottom = 0; // Height of the spliter _rect.bottom = 0; // Height of the spliter
_isFixed = false;
} }
void Splitter::init( HINSTANCE hInst, HWND hPere, int splitterSize, void Splitter::init( HINSTANCE hInst, HWND hPere, int splitterSize, double iSplitRatio, DWORD dwFlags)
double iSplitRatio, DWORD dwFlags)
{ {
if (hPere == NULL) if (hPere == NULL)
{
throw std::runtime_error("Splitter::init : Parameter hPere is null"); throw std::runtime_error("Splitter::init : Parameter hPere is null");
}
if (iSplitRatio < 0) if (iSplitRatio < 0)
{
throw std::runtime_error("Splitter::init : Parameter iSplitRatio shoulds be 0 < ratio < 100"); throw std::runtime_error("Splitter::init : Parameter iSplitRatio shoulds be 0 < ratio < 100");
}
Window::init(hInst, hPere); Window::init(hInst, hPere);
_spiltterSize = splitterSize; _spiltterSize = splitterSize;
@ -183,24 +177,14 @@ void Splitter::init( HINSTANCE hInst, HWND hPere, int splitterSize,
_isVerticalFixedRegistered = true; _isVerticalFixedRegistered = true;
} }
_hSelf = CreateWindowEx( _hSelf = CreateWindowEx(dwExStyle, wcex.lpszClassName,
dwExStyle,
wcex.lpszClassName,
TEXT(""), TEXT(""),
dwStyle, dwStyle,
_rect.left, _rect.left, _rect.top, _rect.right, _rect.bottom,
_rect.top, _hParent, NULL, _hInst, this);
_rect.right,
_rect.bottom,
_hParent,
NULL,
_hInst,
(LPVOID)this);
if (!_hSelf) if (!_hSelf)
{
throw std::runtime_error("Splitter::init : CreateWindowEx() function return null"); throw std::runtime_error("Splitter::init : CreateWindowEx() function return null");
}
RECT rc; RECT rc;
getClientRect(rc); getClientRect(rc);
@ -209,8 +193,8 @@ void Splitter::init( HINSTANCE hInst, HWND hPere, int splitterSize,
_clickZone2TL.left = rc.left; _clickZone2TL.left = rc.left;
_clickZone2TL.top = rc.top; _clickZone2TL.top = rc.top;
int clickZoneWidth = getClickZone(WIDTH); int clickZoneWidth = getClickZone(WH::width);
int clickZoneHeight = getClickZone(HEIGHT); int clickZoneHeight = getClickZone(WH::height);
_clickZone2TL.right = clickZoneWidth; _clickZone2TL.right = clickZoneWidth;
_clickZone2TL.bottom = clickZoneHeight; _clickZone2TL.bottom = clickZoneHeight;
@ -221,23 +205,33 @@ void Splitter::init( HINSTANCE hInst, HWND hPere, int splitterSize,
display(); display();
::SendMessage(_hParent, WM_RESIZE_CONTAINER, _rect.left, _rect.top); ::SendMessage(_hParent, WM_RESIZE_CONTAINER, _rect.left, _rect.top);
} }
// determinated by (_dwFlags & SV_VERTICAL) && _splitterSize
void Splitter::destroy()
{
::DestroyWindow(_hSelf);
}
int Splitter::getClickZone(WH which) int Splitter::getClickZone(WH which)
{ {
// determinated by (_dwFlags & SV_VERTICAL) && _splitterSize
if (_spiltterSize <= 8) if (_spiltterSize <= 8)
{ {
return isVertical()?(which==WIDTH?_spiltterSize:HIEGHT_MINIMAL) return isVertical()
:(which==WIDTH?HIEGHT_MINIMAL:_spiltterSize); ? (which == WH::width ? _spiltterSize : HIEGHT_MINIMAL)
: (which == WH::width ? HIEGHT_MINIMAL : _spiltterSize);
} }
else // (_spiltterSize > 8) else // (_spiltterSize > 8)
{ {
return isVertical()?(which==WIDTH? 8:15) return isVertical()
:(which==WIDTH?15:8); ? ((which == WH::width) ? 8 : 15)
: ((which == WH::width) ? 15 : 8);
} }
} }
LRESULT CALLBACK Splitter::staticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK Splitter::staticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
switch(uMsg) switch(uMsg)
@ -260,23 +254,11 @@ LRESULT CALLBACK Splitter::staticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LP
} }
} }
LRESULT CALLBACK Splitter::spliterWndProc(UINT uMsg, WPARAM wParam, LPARAM lParam) LRESULT CALLBACK Splitter::spliterWndProc(UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
switch (uMsg) switch (uMsg)
{ {
/*
case WM_LBUTTONDBLCLK:
{
::MessageBox(NULL, TEXT(""), TEXT(""), MB_OK);
}
return 0;
case WM_RBUTTONDBLCLK:
{
}
return 0;
*/
case WM_LBUTTONDOWN: case WM_LBUTTONDOWN:
{ {
POINT p; POINT p;
@ -300,12 +282,15 @@ LRESULT CALLBACK Splitter::spliterWndProc(UINT uMsg, WPARAM wParam, LPARAM lPara
::SetCapture(_hSelf); ::SetCapture(_hSelf);
_isDraged = true; _isDraged = true;
} }
}
return 0; return 0;
}
case WM_RBUTTONDOWN: case WM_RBUTTONDOWN:
{
::SendMessage(_hParent, WM_DOPOPUPMENU, wParam, lParam); ::SendMessage(_hParent, WM_DOPOPUPMENU, wParam, lParam);
return TRUE; return TRUE;
}
case WM_MOUSEMOVE: case WM_MOUSEMOVE:
{ {
@ -386,6 +371,7 @@ LRESULT CALLBACK Splitter::spliterWndProc(UINT uMsg, WPARAM wParam, LPARAM lPara
} }
return 0; return 0;
} }
case WM_CAPTURECHANGED: case WM_CAPTURECHANGED:
{ {
if (_isDraged) if (_isDraged)
@ -398,16 +384,22 @@ LRESULT CALLBACK Splitter::spliterWndProc(UINT uMsg, WPARAM wParam, LPARAM lPara
} }
case WM_PAINT: case WM_PAINT:
{
drawSplitter(); drawSplitter();
return 0; return 0;
}
case WM_CLOSE: case WM_CLOSE:
{
destroy(); destroy();
return 0; return 0;
} }
}
return ::DefWindowProc(_hSelf, uMsg, wParam, lParam); return ::DefWindowProc(_hSelf, uMsg, wParam, lParam);
} }
void Splitter::resizeSpliter(RECT *pRect) void Splitter::resizeSpliter(RECT *pRect)
{ {
RECT rect; RECT rect;
@ -449,8 +441,8 @@ void Splitter::resizeSpliter(RECT *pRect)
RECT rc; RECT rc;
getClientRect(rc); getClientRect(rc);
_clickZone2BR.right = getClickZone(WIDTH); _clickZone2BR.right = getClickZone(WH::width);
_clickZone2BR.bottom = getClickZone(HEIGHT); _clickZone2BR.bottom = getClickZone(WH::height);
_clickZone2BR.left = rc.right - _clickZone2BR.right; _clickZone2BR.left = rc.right - _clickZone2BR.right;
_clickZone2BR.top = rc.bottom - _clickZone2BR.bottom; _clickZone2BR.top = rc.bottom - _clickZone2BR.bottom;
@ -460,6 +452,7 @@ void Splitter::resizeSpliter(RECT *pRect)
redraw(); redraw();
} }
void Splitter::gotoTopLeft() void Splitter::gotoTopLeft()
{ {
if ((_dwFlags & SV_ENABLELDBLCLK) && (!_isFixed) && (_splitPercent > 1)) if ((_dwFlags & SV_ENABLELDBLCLK) && (!_isFixed) && (_splitPercent > 1))
@ -468,6 +461,7 @@ void Splitter::gotoTopLeft()
_rect.top = 1; _rect.top = 1;
else else
_rect.left = 1; _rect.left = 1;
_splitPercent = 1; _splitPercent = 1;
::SendMessage(_hParent, WM_RESIZE_CONTAINER, _rect.left, _rect.top); ::SendMessage(_hParent, WM_RESIZE_CONTAINER, _rect.left, _rect.top);
@ -476,6 +470,7 @@ void Splitter::gotoTopLeft()
} }
} }
void Splitter::gotoRightBouuom() void Splitter::gotoRightBouuom()
{ {
if ((_dwFlags & SV_ENABLERDBLCLK) && (!_isFixed) && (_splitPercent < 99)) if ((_dwFlags & SV_ENABLERDBLCLK) && (!_isFixed) && (_splitPercent < 99))
@ -496,6 +491,7 @@ void Splitter::gotoRightBouuom()
} }
} }
void Splitter::drawSplitter() void Splitter::drawSplitter()
{ {
PAINTSTRUCT ps; PAINTSTRUCT ps;
@ -506,9 +502,9 @@ void Splitter::drawSplitter()
if ((_spiltterSize >= 4) && (_dwFlags & SV_RESIZEWTHPERCNT)) if ((_spiltterSize >= 4) && (_dwFlags & SV_RESIZEWTHPERCNT))
{ {
adjustZoneToDraw(TLrc, TOP_LEFT); adjustZoneToDraw(TLrc, ZONE_TYPE::topLeft);
adjustZoneToDraw(BRrc, BOTTOM_RIGHT); adjustZoneToDraw(BRrc, ZONE_TYPE::bottomRight);
paintArrow(hdc, TLrc, isVertical()?ARROW_LEFT:ARROW_UP); paintArrow(hdc, TLrc, isVertical() ? Arrow::left : Arrow::up);
} }
if (isVertical()) if (isVertical())
@ -563,6 +559,7 @@ void Splitter::drawSplitter()
rcToDraw1.left += 4; rcToDraw1.left += 4;
rcToDraw1.right += 4; rcToDraw1.right += 4;
} }
rcToDraw2.top += 4; rcToDraw2.top += 4;
rcToDraw2.bottom += 4; rcToDraw2.bottom += 4;
rcToDraw1.top += 4; rcToDraw1.top += 4;
@ -570,16 +567,18 @@ void Splitter::drawSplitter()
} }
if ((_spiltterSize >= 4) && (_dwFlags & SV_RESIZEWTHPERCNT)) if ((_spiltterSize >= 4) && (_dwFlags & SV_RESIZEWTHPERCNT))
paintArrow(hdc, BRrc, isVertical()?ARROW_RIGHT:ARROW_DOWN); paintArrow(hdc, BRrc, isVertical() ? Arrow::right : Arrow::down);
::EndPaint(_hSelf, &ps); ::EndPaint(_hSelf, &ps);
} }
void Splitter::rotate() void Splitter::rotate()
{ {
if (!_isFixed) if (!_isFixed)
{ {
destroy(); destroy();
if (_dwFlags & SV_HORIZONTAL) if (_dwFlags & SV_HORIZONTAL)
{ {
_dwFlags ^= SV_HORIZONTAL; _dwFlags ^= SV_HORIZONTAL;
@ -590,28 +589,35 @@ void Splitter::rotate()
_dwFlags ^= SV_VERTICAL; _dwFlags ^= SV_VERTICAL;
_dwFlags |= SV_HORIZONTAL; _dwFlags |= SV_HORIZONTAL;
} }
init(_hInst, _hParent, _spiltterSize, _splitPercent, _dwFlags); init(_hInst, _hParent, _spiltterSize, _splitPercent, _dwFlags);
} }
} }
void Splitter::paintArrow(HDC hdc, const RECT &rect, Arrow arrowDir) void Splitter::paintArrow(HDC hdc, const RECT &rect, Arrow arrowDir)
{ {
RECT rc; RECT rc;
rc.left = rect.left; rc.top = rect.top; rc.left = rect.left; rc.top = rect.top;
rc.right = rect.right; rc.bottom = rect.bottom; rc.right = rect.right; rc.bottom = rect.bottom;
if (arrowDir == ARROW_LEFT)
switch (arrowDir)
{
case Arrow::left:
{ {
int x = rc.right; int x = rc.right;
int y = rc.top; int y = rc.top;
//::MoveToEx(hdc, x, y, NULL); //::MoveToEx(hdc, x, y, NULL);
for (; (x > rc.left) && (y != rc.bottom) ; x--) for (; (x > rc.left) && (y != rc.bottom) ; --x)
{ {
::MoveToEx(hdc, x, y++, NULL); ::MoveToEx(hdc, x, y++, NULL);
::LineTo(hdc, x, rc.bottom--); ::LineTo(hdc, x, rc.bottom--);
} }
break;
} }
else if (arrowDir == ARROW_RIGHT)
case Arrow::right:
{ {
int x = rc.left; int x = rc.left;
int y = rc.top; int y = rc.top;
@ -622,20 +628,24 @@ void Splitter::paintArrow(HDC hdc, const RECT &rect, Arrow arrowDir)
::MoveToEx(hdc, x, y++, NULL); ::MoveToEx(hdc, x, y++, NULL);
::LineTo(hdc, x, rc.bottom--); ::LineTo(hdc, x, rc.bottom--);
} }
break;
} }
else if (arrowDir == ARROW_UP)
case Arrow::up:
{ {
int x = rc.left; int x = rc.left;
int y = rc.bottom; int y = rc.bottom;
//::MoveToEx(hdc, x, y, NULL); //::MoveToEx(hdc, x, y, NULL);
for (; (y > rc.top) && (x != rc.right) ; y--) for (; (y > rc.top) && (x != rc.right) ; --y)
{ {
::MoveToEx(hdc, x++, y, NULL); ::MoveToEx(hdc, x++, y, NULL);
::LineTo(hdc, rc.right--, y); ::LineTo(hdc, rc.right--, y);
} }
break;
} }
else if (arrowDir == ARROW_DOWN)
case Arrow::down:
{ {
int x = rc.left; int x = rc.left;
int y = rc.top; int y = rc.top;
@ -646,12 +656,19 @@ void Splitter::paintArrow(HDC hdc, const RECT &rect, Arrow arrowDir)
::MoveToEx(hdc, x++, y, NULL); ::MoveToEx(hdc, x++, y, NULL);
::LineTo(hdc, rc.right--, y); ::LineTo(hdc, rc.right--, y);
} }
break;
} }
} }
}
void Splitter::adjustZoneToDraw(RECT& rc2def, ZONE_TYPE whichZone) void Splitter::adjustZoneToDraw(RECT& rc2def, ZONE_TYPE whichZone)
{ {
if (_spiltterSize < 4) return; if (_spiltterSize < 4)
return;
int x0, y0, x1, y1, w, h; int x0, y0, x1, y1, w, h;
if ((4 <= _spiltterSize) && (_spiltterSize <= 8)) if ((4 <= _spiltterSize) && (_spiltterSize <= 8))
{ {
w = (isVertical() ? 4 : 7); w = (isVertical() ? 4 : 7);
@ -664,8 +681,9 @@ void Splitter::adjustZoneToDraw(RECT & rc2def, ZONE_TYPE whichZone)
} }
if (isVertical()) if (isVertical())
{//w=4 h=7 {
if (whichZone == TOP_LEFT) // w=4 h=7
if (whichZone == ZONE_TYPE::topLeft)
{ {
x0 = 0; x0 = 0;
y0 = (_clickZone2TL.bottom - h) / 2; y0 = (_clickZone2TL.bottom - h) / 2;
@ -675,12 +693,14 @@ void Splitter::adjustZoneToDraw(RECT & rc2def, ZONE_TYPE whichZone)
x0 = _clickZone2BR.left + _clickZone2BR.right - w; x0 = _clickZone2BR.left + _clickZone2BR.right - w;
y0 = (_clickZone2BR.bottom - h) / 2 + _clickZone2BR.top; y0 = (_clickZone2BR.bottom - h) / 2 + _clickZone2BR.top;
} }
x1 = x0 + w; x1 = x0 + w;
y1 = y0 + h; y1 = y0 + h;
} }
else // Horizontal else // Horizontal
{//w=7 h=4 {
if (whichZone == TOP_LEFT) //w=7 h=4
if (whichZone == ZONE_TYPE::topLeft)
{ {
x0 = (_clickZone2TL.right - w) / 2; x0 = (_clickZone2TL.right - w) / 2;
y0 = 0; y0 = 0;
@ -690,11 +710,14 @@ void Splitter::adjustZoneToDraw(RECT & rc2def, ZONE_TYPE whichZone)
x0 = ((_clickZone2BR.right - w) / 2) + _clickZone2BR.left; x0 = ((_clickZone2BR.right - w) / 2) + _clickZone2BR.left;
y0 = _clickZone2BR.top + _clickZone2BR.bottom - h; y0 = _clickZone2BR.top + _clickZone2BR.bottom - h;
} }
x1 = x0 + w; x1 = x0 + w;
y1 = y0 + h; y1 = y0 + h;
} }
rc2def.left = x0; rc2def.left = x0;
rc2def.top = y0; rc2def.top = y0;
rc2def.right = x1; rc2def.right = x1;
rc2def.bottom = y1; rc2def.bottom = y1;
} }

View File

@ -24,16 +24,11 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#pragma once
#ifndef SPLITTER_H
#define SPLITTER_H
#ifndef RESOURCE_H
#include "resource.h" #include "resource.h"
#endif //RESOURCE_H
#include "Window.h" #include "Window.h"
#include "Common.h"
#define SV_HORIZONTAL 0x00000001 #define SV_HORIZONTAL 0x00000001
#define SV_VERTICAL 0x00000002 #define SV_VERTICAL 0x00000002
@ -50,43 +45,47 @@
const int HIEGHT_MINIMAL = 15; const int HIEGHT_MINIMAL = 15;
enum Arrow {ARROW_LEFT, ARROW_UP, ARROW_RIGHT, ARROW_DOWN};
typedef bool WH; enum class Arrow { left, up, right, down };
const bool WIDTH = true;
const bool HEIGHT = false;
typedef bool ZONE_TYPE; enum class WH { height, width };
const bool TOP_LEFT = true;
const bool BOTTOM_RIGHT = false;
enum SplitterMode { enum class ZONE_TYPE { bottomRight, topLeft };
enum class SplitterMode: std::uint8_t
{
DYNAMIC, LEFT_FIX, RIGHT_FIX DYNAMIC, LEFT_FIX, RIGHT_FIX
}; };
class Splitter : public Window class Splitter : public Window
{ {
public: public:
Splitter(); Splitter();
~Splitter(){}; virtual ~Splitter() = default;
void destroy() {
::DestroyWindow(_hSelf); virtual void destroy() override;
};
void resizeSpliter(RECT *pRect = NULL); void resizeSpliter(RECT *pRect = NULL);
void init(HINSTANCE hInst, HWND hPere, int splitterSize, void init(HINSTANCE hInst, HWND hPere, int splitterSize, double iSplitRatio, DWORD dwFlags);
double iSplitRatio, DWORD dwFlags);
void rotate(); void rotate();
int getPhisicalSize() const {
int getPhisicalSize() const
{
return _spiltterSize; return _spiltterSize;
}; }
private: private:
RECT _rect; RECT _rect;
double _splitPercent; double _splitPercent = 0.;
int _spiltterSize; int _spiltterSize = 0;
bool _isDraged; bool _isDraged = false;
DWORD _dwFlags; DWORD _dwFlags = 0;
bool _isFixed; bool _isFixed = false;
static bool _isHorizontalRegistered; static bool _isHorizontalRegistered;
static bool _isVerticalRegistered; static bool _isVerticalRegistered;
static bool _isHorizontalFixedRegistered; static bool _isHorizontalFixedRegistered;
@ -105,26 +104,31 @@ private:
void gotoTopLeft(); void gotoTopLeft();
void gotoRightBouuom(); void gotoRightBouuom();
bool isInLeftTopZone(const POINT &p) const { bool isInLeftTopZone(const POINT& p) const
return (((p.x >= _clickZone2TL.left) && (p.x <= _clickZone2TL.left + _clickZone2TL.right)) && {
(p.y >= _clickZone2TL.top) && (p.y <= _clickZone2TL.top + _clickZone2TL.bottom)); return ((p.x >= _clickZone2TL.left)
}; and (p.x <= _clickZone2TL.left + _clickZone2TL.right)
and (p.y >= _clickZone2TL.top)
and (p.y <= _clickZone2TL.top + _clickZone2TL.bottom));
}
bool isInRightBottomZone(const POINT &p) const { bool isInRightBottomZone(const POINT& p) const
return (((p.x >= _clickZone2BR.left) && {
(p.x <= _clickZone2BR.left + _clickZone2BR.right)) && return ((p.x >= _clickZone2BR.left)
(p.y >= _clickZone2BR.top) && and (p.x <= _clickZone2BR.left + _clickZone2BR.right)
(p.y <= _clickZone2BR.top + _clickZone2BR.bottom)); and (p.y >= _clickZone2BR.top)
}; and (p.y <= _clickZone2BR.top + _clickZone2BR.bottom));
}
int getSplitterFixPosX() { int getSplitterFixPosX() const
{
long result = long(::SendMessage(_hParent, WM_GETSPLITTER_X, 0, 0)); long result = long(::SendMessage(_hParent, WM_GETSPLITTER_X, 0, 0));
return (LOWORD(result) - ((HIWORD(result) == RIGHT_FIX) ? _spiltterSize : 0)); return (LOWORD(result) - ((HIWORD(result) == static_cast<std::uint8_t>(SplitterMode::RIGHT_FIX)) ? _spiltterSize : 0));
}; }
int getSplitterFixPosY() { int getSplitterFixPosY() const
{
long result = long(::SendMessage(_hParent, WM_GETSPLITTER_Y, 0, 0)); long result = long(::SendMessage(_hParent, WM_GETSPLITTER_Y, 0, 0));
return (LOWORD(result) - ((HIWORD(result) == RIGHT_FIX) ? _spiltterSize : 0)); return (LOWORD(result) - ((HIWORD(result) == static_cast<std::uint8_t>(SplitterMode::RIGHT_FIX)) ? _spiltterSize : 0));
}
}; };
};
#endif //SPLITTER_H

View File

@ -24,16 +24,18 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <iostream> #include <iostream>
#include <windows.h> #include <windows.h>
#include "SplitterContainer.h" #include "SplitterContainer.h"
#include <cassert>
bool SplitterContainer::_isRegistered = false; bool SplitterContainer::_isRegistered = false;
void SplitterContainer::create(Window *pWin0, Window *pWin1, int splitterSize,
SplitterMode mode, int ratio, bool isVertical)
void SplitterContainer::create(Window *pWin0, Window *pWin1, int splitterSize, SplitterMode mode, int ratio, bool isVertical)
{ {
//Window::init(hInst, parent); //Window::init(hInst, parent);
_pWin0 = pWin0; _pWin0 = pWin0;
@ -42,7 +44,8 @@ void SplitterContainer::create(Window *pWin0, Window *pWin1, int splitterSize,
_splitterMode = mode; _splitterMode = mode;
_ratio = ratio; _ratio = ratio;
_dwSplitterStyle |= isVertical?SV_VERTICAL:SV_HORIZONTAL; _dwSplitterStyle |= isVertical?SV_VERTICAL:SV_HORIZONTAL;
if (_splitterMode != DYNAMIC)
if (_splitterMode != SplitterMode::DYNAMIC)
{ {
_dwSplitterStyle |= SV_FIXED; _dwSplitterStyle |= SV_FIXED;
_dwSplitterStyle &= ~SV_RESIZEWTHPERCNT; _dwSplitterStyle &= ~SV_RESIZEWTHPERCNT;
@ -66,30 +69,63 @@ void SplitterContainer::create(Window *pWin0, Window *pWin1, int splitterSize,
splitterContainerClass.lpszClassName = SPC_CLASS_NAME; splitterContainerClass.lpszClassName = SPC_CLASS_NAME;
if (!::RegisterClass(&splitterContainerClass)) if (!::RegisterClass(&splitterContainerClass))
{
throw std::runtime_error(" SplitterContainer::create : RegisterClass() function failed"); throw std::runtime_error(" SplitterContainer::create : RegisterClass() function failed");
}
_isRegistered = true; _isRegistered = true;
} }
_hSelf = ::CreateWindowEx( _hSelf = ::CreateWindowEx(
0, 0, SPC_CLASS_NAME, TEXT("a koi sert?"),
SPC_CLASS_NAME,
TEXT("a koi sert?"),
WS_CHILD | WS_CLIPCHILDREN, WS_CHILD | WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT, _hParent, NULL, _hInst, this);
_hParent,
NULL,
_hInst,
(LPVOID)this);
if (!_hSelf) if (!_hSelf)
{
throw std::runtime_error(" SplitterContainer::create : CreateWindowEx() function return null"); throw std::runtime_error(" SplitterContainer::create : CreateWindowEx() function return null");
} }
void SplitterContainer::destroy()
{
if (_hPopupMenu)
::DestroyMenu(_hPopupMenu);
_splitter.destroy();
::DestroyWindow(_hSelf);
} }
void SplitterContainer::reSizeTo(RECT & rc)
{
_x = rc.left;
_y = rc.top;
::MoveWindow(_hSelf, _x, _y, rc.right, rc.bottom, FALSE);
_splitter.resizeSpliter();
}
void SplitterContainer::display(bool toShow) const
{
Window::display(toShow);
assert(_pWin0 != nullptr);
assert(_pWin1 != nullptr);
_pWin0->display(toShow);
_pWin1->display(toShow);
_splitter.display(toShow);
}
void SplitterContainer::redraw() const
{
assert(_pWin0 != nullptr);
assert(_pWin1 != nullptr);
_pWin0->redraw(true);
_pWin1->redraw(true);
}
void SplitterContainer::rotateTo(DIRECTION direction) void SplitterContainer::rotateTo(DIRECTION direction)
{ {
bool doSwitchWindow = false; bool doSwitchWindow = false;
@ -97,13 +133,13 @@ void SplitterContainer::rotateTo(DIRECTION direction)
{ {
_dwSplitterStyle ^= SV_VERTICAL; _dwSplitterStyle ^= SV_VERTICAL;
_dwSplitterStyle |= SV_HORIZONTAL; _dwSplitterStyle |= SV_HORIZONTAL;
doSwitchWindow = (direction == LEFT); doSwitchWindow = (direction == DIRECTION::LEFT);
} }
else else
{ {
_dwSplitterStyle ^= SV_HORIZONTAL; _dwSplitterStyle ^= SV_HORIZONTAL;
_dwSplitterStyle |= SV_VERTICAL; _dwSplitterStyle |= SV_VERTICAL;
doSwitchWindow = (direction == RIGHT); doSwitchWindow = (direction == DIRECTION::RIGHT);
} }
if (doSwitchWindow) if (doSwitchWindow)
{ {
@ -121,40 +157,52 @@ LRESULT CALLBACK SplitterContainer::staticWinProc(HWND hwnd, UINT message, WPARA
switch (message) switch (message)
{ {
case WM_NCCREATE: case WM_NCCREATE:
{
pSplitterContainer = (SplitterContainer *)(((LPCREATESTRUCT)lParam)->lpCreateParams); pSplitterContainer = (SplitterContainer *)(((LPCREATESTRUCT)lParam)->lpCreateParams);
pSplitterContainer->_hSelf = hwnd; pSplitterContainer->_hSelf = hwnd;
::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pSplitterContainer); ::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pSplitterContainer);
return TRUE; return TRUE;
}
default: default:
{
pSplitterContainer = (SplitterContainer *)::GetWindowLongPtr(hwnd, GWLP_USERDATA); pSplitterContainer = (SplitterContainer *)::GetWindowLongPtr(hwnd, GWLP_USERDATA);
if (!pSplitterContainer) if (!pSplitterContainer)
return ::DefWindowProc(hwnd, message, wParam, lParam); return ::DefWindowProc(hwnd, message, wParam, lParam);
return pSplitterContainer->runProc(message, wParam, lParam); return pSplitterContainer->runProc(message, wParam, lParam);
} }
} }
}
LRESULT SplitterContainer::runProc(UINT message, WPARAM wParam, LPARAM lParam) LRESULT SplitterContainer::runProc(UINT message, WPARAM wParam, LPARAM lParam)
{ {
switch (message) switch (message)
{ {
case WM_CREATE: case WM_CREATE:
{
_splitter.init(_hInst, _hSelf, _splitterSize, _ratio, _dwSplitterStyle); _splitter.init(_hInst, _hSelf, _splitterSize, _ratio, _dwSplitterStyle);
return TRUE; return TRUE;
}
case WM_COMMAND: case WM_COMMAND:
{ {
switch (LOWORD(wParam)) switch (LOWORD(wParam))
{ {
case ROTATION_A_GAUCHE: case ROTATION_A_GAUCHE:
rotateTo(LEFT); {
return TRUE; rotateTo(DIRECTION::LEFT);
break;
}
case ROTATION_A_DROITE: case ROTATION_A_DROITE:
rotateTo(RIGHT); {
return TRUE; rotateTo(DIRECTION::RIGHT);
break;
}
} }
return TRUE; return TRUE;
} }
case WM_RESIZE_CONTAINER: case WM_RESIZE_CONTAINER:
{ {
RECT rc0, rc1; RECT rc0, rc1;
@ -194,7 +242,7 @@ LRESULT SplitterContainer::runProc(UINT message, WPARAM wParam, LPARAM lParam)
case WM_DOPOPUPMENU: case WM_DOPOPUPMENU:
{ {
if ((_splitterMode != LEFT_FIX) && (_splitterMode != RIGHT_FIX) ) if ((_splitterMode != SplitterMode::LEFT_FIX) && (_splitterMode != SplitterMode::RIGHT_FIX) )
{ {
POINT p; POINT p;
::GetCursorPos(&p); ::GetCursorPos(&p);
@ -215,33 +263,45 @@ LRESULT SplitterContainer::runProc(UINT message, WPARAM wParam, LPARAM lParam)
case WM_GETSPLITTER_X: case WM_GETSPLITTER_X:
{ {
if (_splitterMode == LEFT_FIX) switch (_splitterMode)
return MAKELONG(_pWin0->getWidth(), LEFT_FIX); {
else if (_splitterMode == RIGHT_FIX) case SplitterMode::LEFT_FIX:
{
return MAKELONG(_pWin0->getWidth(), static_cast<std::uint8_t>(SplitterMode::LEFT_FIX));
}
case SplitterMode::RIGHT_FIX:
{ {
int x = getWidth()-_pWin1->getWidth(); int x = getWidth()-_pWin1->getWidth();
if (x < 0) if (x < 0)
x = 0; x = 0;
return MAKELONG(x, RIGHT_FIX); return MAKELONG(x, static_cast<std::uint8_t>(SplitterMode::RIGHT_FIX));
} }
else default:
return MAKELONG(0, DYNAMIC); break;
}
return MAKELONG(0, static_cast<std::uint8_t>(SplitterMode::DYNAMIC));
} }
case WM_GETSPLITTER_Y: case WM_GETSPLITTER_Y:
{ {
if (_splitterMode == LEFT_FIX) switch (_splitterMode)
return MAKELONG(_pWin0->getHeight(), LEFT_FIX); {
else if (_splitterMode == RIGHT_FIX) case SplitterMode::LEFT_FIX:
{
return MAKELONG(_pWin0->getHeight(), static_cast<std::uint8_t>(SplitterMode::LEFT_FIX));
}
case SplitterMode::RIGHT_FIX:
{ {
int y = getHeight()-_pWin1->getHeight(); int y = getHeight()-_pWin1->getHeight();
if (y < 0) if (y < 0)
y = 0; y = 0;
return MAKELONG(y, RIGHT_FIX); return MAKELONG(y, static_cast<std::uint8_t>(SplitterMode::RIGHT_FIX));
} }
else default:
return MAKELONG(0, DYNAMIC); break;
}
return MAKELONG(0, static_cast<std::uint8_t>(SplitterMode::DYNAMIC));
} }
case WM_LBUTTONDBLCLK: case WM_LBUTTONDBLCLK:
@ -250,15 +310,12 @@ LRESULT SplitterContainer::runProc(UINT message, WPARAM wParam, LPARAM lParam)
::GetCursorPos(&pt); ::GetCursorPos(&pt);
::ScreenToClient(_splitter.getHSelf(), &pt); ::ScreenToClient(_splitter.getHSelf(), &pt);
Window* targetWindow;
if(this->isVertical())
targetWindow = pt.x < 0?_pWin0:_pWin1;
else
targetWindow = pt.y < 0?_pWin0:_pWin1;
HWND parent = ::GetParent(getHSelf()); HWND parent = ::GetParent(getHSelf());
Window* targetWindow = (this->isVertical())
? (pt.x < 0 ? _pWin0 : _pWin1)
: (pt.y < 0 ? _pWin0 : _pWin1);
::SendMessage(parent, NPPM_INTERNAL_SWITCHVIEWFROMHWND, 0, (LPARAM)targetWindow->getHSelf()); ::SendMessage(parent, NPPM_INTERNAL_SWITCHVIEWFROMHWND, 0, (LPARAM)targetWindow->getHSelf());
::SendMessage(parent, WM_COMMAND, IDM_FILE_NEW, 0); ::SendMessage(parent, WM_COMMAND, IDM_FILE_NEW, 0);
return TRUE; return TRUE;

View File

@ -24,94 +24,74 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#pragma once
#ifndef SPLITTER_CONTAINER_H
#define SPLITTER_CONTAINER_H
#ifndef SPLITTER_H
#include "Splitter.h" #include "Splitter.h"
#endif //SPLITTER_H
#ifndef MENUCMDID_H
#include "menuCmdID.h" #include "menuCmdID.h"
#endif //MENUCMDID_H
#define SPC_CLASS_NAME TEXT("splitterContainer") #define SPC_CLASS_NAME TEXT("splitterContainer")
#define ROTATION_A_GAUCHE 2000 #define ROTATION_A_GAUCHE 2000
#define ROTATION_A_DROITE 2001 #define ROTATION_A_DROITE 2001
typedef bool DIRECTION;
const bool LEFT = true; enum class DIRECTION
const bool RIGHT = false; {
RIGHT,
LEFT
};
class SplitterContainer : public Window class SplitterContainer : public Window
{ {
public : public :
SplitterContainer(): Window(), _x(0), _y(0), _hPopupMenu(NULL), virtual ~SplitterContainer() = default;
_dwSplitterStyle(SV_ENABLERDBLCLK | SV_ENABLELDBLCLK | SV_RESIZEWTHPERCNT){
};
~SplitterContainer(){};
void create(Window *pWin0, Window *pWin1, int splitterSize = 4, void create(Window *pWin0, Window *pWin1, int splitterSize = 4,
SplitterMode mode = DYNAMIC, int ratio = 50, bool _isVertical = true); SplitterMode mode = SplitterMode::DYNAMIC, int ratio = 50, bool _isVertical = true);
void destroy() { void destroy();
if (_hPopupMenu)
::DestroyMenu(_hPopupMenu);
_splitter.destroy();
::DestroyWindow(_hSelf);
};
void reSizeTo(RECT & rc) {
_x = rc.left;
_y = rc.top;
::MoveWindow(_hSelf, _x, _y, rc.right, rc.bottom, FALSE);
_splitter.resizeSpliter();
};
virtual void display(bool toShow = true) const {
Window::display(toShow);
_pWin0->display(toShow); void reSizeTo(RECT & rc);
_pWin1->display(toShow);
_splitter.display(toShow);
};
virtual void redraw() const {
_pWin0->redraw(true);
_pWin1->redraw(true);
};
void setWin0(Window *pWin) { virtual void display(bool toShow = true) const;
virtual void redraw() const;
void setWin0(Window* pWin)
{
_pWin0 = pWin; _pWin0 = pWin;
}
}; void setWin1(Window* pWin)
{
void setWin1(Window *pWin) {
_pWin1 = pWin; _pWin1 = pWin;
}; }
bool isVertical() const { bool isVertical() const
{
return ((_dwSplitterStyle & SV_VERTICAL) != 0); return ((_dwSplitterStyle & SV_VERTICAL) != 0);
}; }
private : private :
Window *_pWin0; // left or top window Window* _pWin0 = nullptr; // left or top window
Window *_pWin1; // right or bottom window Window* _pWin1 = nullptr; // right or bottom window
Splitter _splitter; Splitter _splitter;
int _splitterSize; int _splitterSize = 0;
int _ratio; int _ratio = 0;
int _x, _y; int _x = 0;
HMENU _hPopupMenu; int _y = 0;
DWORD _dwSplitterStyle; HMENU _hPopupMenu = NULL;
DWORD _dwSplitterStyle = (SV_ENABLERDBLCLK | SV_ENABLELDBLCLK | SV_RESIZEWTHPERCNT);
SplitterMode _splitterMode; SplitterMode _splitterMode = SplitterMode::DYNAMIC;
static bool _isRegistered; static bool _isRegistered;
static LRESULT CALLBACK staticWinProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam); static LRESULT CALLBACK staticWinProc(HWND hwnd, UINT Message, WPARAM wParam, LPARAM lParam);
LRESULT runProc(UINT Message, WPARAM wParam, LPARAM lParam); LRESULT runProc(UINT Message, WPARAM wParam, LPARAM lParam);
void rotateTo(DIRECTION direction); void rotateTo(DIRECTION direction);
}; };
#endif //SPLITTER_CONTAINER_H

View File

@ -29,6 +29,43 @@
#include <windows.h> #include <windows.h>
#include "StaticDialog.h" #include "StaticDialog.h"
StaticDialog::~StaticDialog()
{
if (isCreated())
{
// Prevent run_dlgProc from doing anything, since its virtual
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (LONG_PTR) NULL);
destroy();
}
}
void StaticDialog::destroy()
{
::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGREMOVE, (WPARAM)_hSelf);
::DestroyWindow(_hSelf);
}
POINT StaticDialog::getTopPoint(HWND hwnd, bool isLeft) const
{
RECT rc;
::GetWindowRect(hwnd, &rc);
POINT p;
if (isLeft)
p.x = rc.left;
else
p.x = rc.right;
p.y = rc.top;
::ScreenToClient(_hSelf, &p);
return p;
}
void StaticDialog::goToCenter() void StaticDialog::goToCenter()
{ {
RECT rc; RECT rc;
@ -47,7 +84,8 @@ void StaticDialog::goToCenter()
void StaticDialog::display(bool toShow) const void StaticDialog::display(bool toShow) const
{ {
if (toShow) { if (toShow)
{
// If the user has switched from a dual monitor to a single monitor since we last // If the user has switched from a dual monitor to a single monitor since we last
// displayed the dialog, then ensure that it's still visible on the single monitor. // displayed the dialog, then ensure that it's still visible on the single monitor.
RECT workAreaRect = {0}; RECT workAreaRect = {0};
@ -57,6 +95,7 @@ void StaticDialog::display(bool toShow) const
int newLeft = rc.left; int newLeft = rc.left;
int newTop = rc.top; int newTop = rc.top;
int margin = ::GetSystemMetrics(SM_CYSMCAPTION); int margin = ::GetSystemMetrics(SM_CYSMCAPTION);
if (newLeft > ::GetSystemMetrics(SM_CXVIRTUALSCREEN)-margin) if (newLeft > ::GetSystemMetrics(SM_CXVIRTUALSCREEN)-margin)
newLeft -= rc.right - workAreaRect.right; newLeft -= rc.right - workAreaRect.right;
if (newLeft + (rc.right - rc.left) < ::GetSystemMetrics(SM_XVIRTUALSCREEN)+margin) if (newLeft + (rc.right - rc.left) < ::GetSystemMetrics(SM_XVIRTUALSCREEN)+margin)
@ -131,6 +170,7 @@ void StaticDialog::create(int dialogID, bool isRTL, bool msgDestParent)
::SendMessage(msgDestParent?_hParent:(::GetParent(_hParent)), NPPM_MODELESSDIALOG, MODELESSDIALOGADD, (WPARAM)_hSelf); ::SendMessage(msgDestParent?_hParent:(::GetParent(_hParent)), NPPM_MODELESSDIALOG, MODELESSDIALOGADD, (WPARAM)_hSelf);
} }
INT_PTR CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) INT_PTR CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
switch (message) switch (message)
@ -166,26 +206,31 @@ void StaticDialog::alignWith(HWND handle, HWND handle2Align, PosAlign pos, POINT
switch (pos) switch (pos)
{ {
case ALIGNPOS_LEFT : case PosAlign::left:
{
::GetWindowRect(handle2Align, &rc2); ::GetWindowRect(handle2Align, &rc2);
point.x -= rc2.right - rc2.left; point.x -= rc2.right - rc2.left;
break; break;
}
case ALIGNPOS_RIGHT : case PosAlign::right:
{
::GetWindowRect(handle, &rc2); ::GetWindowRect(handle, &rc2);
point.x += rc2.right - rc2.left; point.x += rc2.right - rc2.left;
break; break;
}
case ALIGNPOS_TOP : case PosAlign::top:
{
::GetWindowRect(handle2Align, &rc2); ::GetWindowRect(handle2Align, &rc2);
point.y -= rc2.bottom - rc2.top; point.y -= rc2.bottom - rc2.top;
break; break;
}
default : //ALIGNPOS_BOTTOM case PosAlign::bottom:
{
::GetWindowRect(handle, &rc2); ::GetWindowRect(handle, &rc2);
point.y += rc2.bottom - rc2.top; point.y += rc2.bottom - rc2.top;
break; break;
} }
}
::ScreenToClient(_hSelf, &point); ::ScreenToClient(_hSelf, &point);
} }

View File

@ -24,19 +24,18 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#pragma once
#ifndef STATIC_DIALOG_H
#define STATIC_DIALOG_H
#include "Notepad_plus_msgs.h" #include "Notepad_plus_msgs.h"
#include "Window.h" #include "Window.h"
typedef HRESULT (WINAPI * ETDTProc) (HWND, DWORD); typedef HRESULT (WINAPI * ETDTProc) (HWND, DWORD);
enum PosAlign{ALIGNPOS_LEFT, ALIGNPOS_RIGHT, ALIGNPOS_TOP, ALIGNPOS_BOTTOM}; enum class PosAlign { left, right, top, bottom };
struct DLGTEMPLATEEX {
struct DLGTEMPLATEEX
{
WORD dlgVer; WORD dlgVer;
WORD signature; WORD signature;
DWORD helpID; DWORD helpID;
@ -50,47 +49,33 @@ struct DLGTEMPLATEEX {
// The structure has more fields but are variable length // The structure has more fields but are variable length
}; };
class StaticDialog : public Window class StaticDialog : public Window
{ {
public : public :
StaticDialog() : Window() {}; virtual ~StaticDialog();
~StaticDialog(){
if (isCreated()) {
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (LONG_PTR)NULL); //Prevent run_dlgProc from doing anything, since its virtual
destroy();
}
};
virtual void create(int dialogID, bool isRTL = false, bool msgDestParent = true); virtual void create(int dialogID, bool isRTL = false, bool msgDestParent = true);
virtual bool isCreated() const { virtual bool isCreated() const
{
return (_hSelf != NULL); return (_hSelf != NULL);
}; }
void goToCenter(); void goToCenter();
void display(bool toShow = true) const; void display(bool toShow = true) const;
POINT getTopPoint(HWND hwnd, bool isLeft = true) const { POINT getTopPoint(HWND hwnd, bool isLeft = true) const;
RECT rc;
::GetWindowRect(hwnd, &rc);
POINT p;
if (isLeft)
p.x = rc.left;
else
p.x = rc.right;
p.y = rc.top;
::ScreenToClient(_hSelf, &p);
return p;
};
bool isCheckedOrNot(int checkControlID) const { bool isCheckedOrNot(int checkControlID) const
{
return (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, checkControlID), BM_GETCHECK, 0, 0)); return (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, checkControlID), BM_GETCHECK, 0, 0));
}; }
virtual void destroy() override;
void destroy() {
::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGREMOVE, (WPARAM)_hSelf);
::DestroyWindow(_hSelf);
};
protected: protected:
RECT _rc; RECT _rc;
@ -100,5 +85,3 @@ protected :
void alignWith(HWND handle, HWND handle2Align, PosAlign pos, POINT & point); void alignWith(HWND handle, HWND handle2Align, PosAlign pos, POINT & point);
HGLOBAL makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplate); HGLOBAL makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplate);
}; };
#endif //STATIC_DIALOG_H

View File

@ -33,7 +33,13 @@
class Window class Window
{ {
public: public:
//! \name Constructors & Destructor
//@{
Window() = default;
Window(const Window&) = delete;
virtual ~Window() = default; virtual ~Window() = default;
//@}
virtual void init(HINSTANCE hInst, HWND parent) virtual void init(HINSTANCE hInst, HWND parent)
{ {
@ -123,6 +129,9 @@ public:
} }
Window& operator = (const Window&) = delete;
protected: protected:
HINSTANCE _hInst = NULL; HINSTANCE _hInst = NULL;
HWND _hParent = NULL; HWND _hParent = NULL;

View File

@ -24,13 +24,11 @@
// You should have received a copy of the GNU General Public License // You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#pragma once
#ifndef RESOURCE_H
#define RESOURCE_H
#define NOTEPAD_PLUS_VERSION TEXT("Notepad++ v6.8.1") #define NOTEPAD_PLUS_VERSION TEXT("Notepad++ v6.8.1")
// should be X.Y : ie. if VERSION_DIGITALVALUE == 4, 7, 1, 0 , then X = 4, Y = 71 // should be X.Y : ie. if VERSION_DIGITALVALUE == 4, 7, 1, 0 , then X = 4, Y = 71
// ex : #define VERSION_VALUE TEXT("5.63\0") // ex : #define VERSION_VALUE TEXT("5.63\0")
#define VERSION_VALUE TEXT("6.8.1\0") #define VERSION_VALUE TEXT("6.8.1\0")
@ -456,7 +454,3 @@
#define MENUINDEX_MACRO 7 #define MENUINDEX_MACRO 7
#define MENUINDEX_RUN 8 #define MENUINDEX_RUN 8
#define MENUINDEX_PLUGINS 9 #define MENUINDEX_PLUGINS 9
#endif // RESOURCE_H