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 <windows.h>
#include <iso646.h>
#include <cstdint>
const bool dirUp = true;

View File

@ -362,7 +362,7 @@ LRESULT Notepad_plus::init(HWND hwnd)
bool isVertical = (nppGUI._splitterPos == POS_VERTICAL);
_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--//
bool willBeShown = nppGUI._statusBarShow;
@ -3240,7 +3240,7 @@ void Notepad_plus::dockUserDlg()
else
pWindow = _pDocTab;
_pMainSplitter->create(pWindow, ScintillaEditView::getUserDefineDlg(), 8, RIGHT_FIX, 45);
_pMainSplitter->create(pWindow, ScintillaEditView::getUserDefineDlg(), 8, SplitterMode::RIGHT_FIX, 45);
}
if (bothActive())

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

@ -24,12 +24,13 @@
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <iostream>
#include "ColourPicker.h"
#include "ColourPopup.h"
void ColourPicker::init(HINSTANCE hInst, HWND parent)
{
Window::init(hInst, parent);
@ -40,37 +41,30 @@ void ColourPicker::init(HINSTANCE hInst, HWND parent)
TEXT("F"),
WS_CHILD | WS_VISIBLE,
0, 0, 25, 25,
_hParent,
NULL,
_hInst,
(LPVOID)0);
if (!_hSelf)
{
throw std::runtime_error("ColourPicker::init : CreateWindowEx() function return null");
}
_hParent, NULL, _hInst, (LPVOID)0);
if (!_hSelf)
throw std::runtime_error("ColourPicker::init : CreateWindowEx() function return null");
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (LONG_PTR)this);
_buttonDefaultProc = reinterpret_cast<WNDPROC>(::SetWindowLongPtr(_hSelf, GWLP_WNDPROC, (LONG_PTR)staticWinProc));
}
void ColourPicker::destroy()
{
if (_pColourPopup)
{
delete _pColourPopup;
_pColourPopup = NULL;
}
::DestroyWindow(_hSelf);
}
void ColourPicker::drawBackground(HDC hDC)
{
RECT rc;
HBRUSH hbrush;
if(!hDC)
if (!hDC)
return;
getClientRect(rc);
@ -82,12 +76,13 @@ void ColourPicker::drawBackground(HDC hDC)
::DeleteObject(hbrush);
}
void ColourPicker::drawForeground(HDC hDC)
{
RECT rc;
HBRUSH hbrush = NULL;
if(!hDC || _isEnabled)
if (!hDC || _isEnabled)
return;
int oldMode = ::SetBkMode(hDC, TRANSPARENT);
@ -107,12 +102,13 @@ void ColourPicker::drawForeground(HDC hDC)
::SetBkMode(hDC, oldMode);
}
LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam)
{
switch (Message)
{
case WM_LBUTTONDBLCLK :
case WM_LBUTTONDOWN :
case WM_LBUTTONDBLCLK:
case WM_LBUTTONDOWN:
{
RECT rc;
POINT p;
@ -136,6 +132,7 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam)
}
return TRUE;
}
case WM_RBUTTONDOWN:
{
_isEnabled = !_isEnabled;
@ -152,7 +149,7 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam)
break;
}
case WM_PAINT :
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC dc = ::BeginPaint(_hSelf, &ps);
@ -161,7 +158,7 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam)
return TRUE;
}
case WM_PICKUP_COLOR :
case WM_PICKUP_COLOR:
{
_currentColour = (COLORREF)wParam;
redraw();
@ -171,7 +168,7 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam)
return TRUE;
}
case WM_ENABLE :
case WM_ENABLE:
{
if ((BOOL)wParam == FALSE)
{
@ -181,12 +178,15 @@ LRESULT ColourPicker::runProc(UINT Message, WPARAM wParam, LPARAM lParam)
return TRUE;
}
case WM_PICKUP_CANCEL :
case WM_PICKUP_CANCEL:
{
_pColourPopup->display(false);
return TRUE;
}
default :
default:
return ::CallWindowProc(_buttonDefaultProc, _hSelf, Message, wParam, lParam);
}
return FALSE;
}

View File

@ -24,62 +24,54 @@
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#ifndef COLOUR_POPUP_H
#define COLOUR_POPUP_H
#ifndef COLOUR_POPUP_RESOURCE_H
#pragma once
#include "ColourPopupResource.h"
#endif //COLOUR_POPUP_RESOURCE_H
#ifndef RESOURCE_H
#include "resource.h"
#endif //RESOURCE_H
#include "Window.h"
#define WM_PICKUP_COLOR (COLOURPOPUP_USER + 1)
#define WM_PICKUP_CANCEL (COLOURPOPUP_USER + 2)
class ColourPopup : public Window
{
public :
ColourPopup() : Window()/*, isColourChooserLaunched(false)*/ {};
ColourPopup(COLORREF defaultColor) : Window(), /* isColourChooserLaunched(false), */ _colour(defaultColor) {};
~ColourPopup(){};
ColourPopup() = default;
explicit ColourPopup(COLORREF defaultColor) : _colour(defaultColor) {}
virtual ~ColourPopup() {}
bool isCreated() const {
bool isCreated() const
{
return (_hSelf != NULL);
};
}
void create(int dialogID);
void doDialog(POINT p) {
void doDialog(POINT p)
{
if (!isCreated())
create(IDD_COLOUR_POPUP);
::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);
};
}
void setColour(COLORREF c) {
void setColour(COLORREF c)
{
_colour = c;
};
}
COLORREF getSelColour(){return _colour;};
private :
RECT _rc;
COLORREF _colour;
//bool isColourChooserLaunched;
//bool isColourChooserLaunched = false;
static INT_PTR CALLBACK dlgProc(HWND hwnd, 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
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#ifndef COLOUR_POPUP_RESOURCE_H
#pragma once
#define IDD_COLOUR_POPUP 2100
#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);
POINT p1, p2;
alignWith(_hFgColourStaticText, _pFgColour->getHSelf(), ALIGNPOS_RIGHT, p1);
alignWith(_hBgColourStaticText, _pBgColour->getHSelf(), ALIGNPOS_RIGHT, p2);
alignWith(_hFgColourStaticText, _pFgColour->getHSelf(), PosAlign::right, p1);
alignWith(_hBgColourStaticText, _pBgColour->getHSelf(), PosAlign::right, p2);
p1.x = p2.x = ((p1.x > p2.x)?p1.x:p2.x) + 10;
p1.y -= 4; p2.y -= 4;
@ -170,7 +169,6 @@ INT_PTR CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM l
goToCenter();
loadLangListFromNppParam();
return TRUE;
}
@ -827,6 +825,7 @@ void WordStyleDlg::setVisualFromStyleList()
const TCHAR *ckwStr = (style._keywords)?style._keywords->c_str():TEXT("");
::SendDlgItemMessage(_hSelf, IDC_USER_KEYWORDS_EDIT, WM_SETTEXT, 0, (LPARAM)(ckwStr));
}
int showOption = shouldBeDisplayed?SW_SHOW:SW_HIDE;
::ShowWindow(::GetDlgItem(_hSelf, IDC_DEF_KEYWORDS_EDIT), showOption);
::ShowWindow(::GetDlgItem(_hSelf, IDC_USER_KEYWORDS_EDIT),showOption);
@ -837,6 +836,7 @@ void WordStyleDlg::setVisualFromStyleList()
redraw();
}
void WordStyleDlg::create(int dialogID, bool isRTL)
{
StaticDialog::create(dialogID, isRTL);
@ -853,6 +853,7 @@ void WordStyleDlg::create(int dialogID, bool isRTL)
}
}
void WordStyleDlg::apply()
{
LexerStylerArray & lsa = (NppParameters::getInstance())->getLStylerArray();

View File

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

View File

@ -24,16 +24,11 @@
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#ifndef SPLITTER_H
#define SPLITTER_H
#ifndef RESOURCE_H
#pragma once
#include "resource.h"
#endif //RESOURCE_H
#include "Window.h"
#include "Common.h"
#define SV_HORIZONTAL 0x00000001
#define SV_VERTICAL 0x00000002
@ -50,43 +45,47 @@
const int HIEGHT_MINIMAL = 15;
enum Arrow {ARROW_LEFT, ARROW_UP, ARROW_RIGHT, ARROW_DOWN};
typedef bool WH;
const bool WIDTH = true;
const bool HEIGHT = false;
enum class Arrow { left, up, right, down };
typedef bool ZONE_TYPE;
const bool TOP_LEFT = true;
const bool BOTTOM_RIGHT = false;
enum class WH { height, width };
enum SplitterMode {
enum class ZONE_TYPE { bottomRight, topLeft };
enum class SplitterMode: std::uint8_t
{
DYNAMIC, LEFT_FIX, RIGHT_FIX
};
class Splitter : public Window
{
public:
Splitter();
~Splitter(){};
void destroy() {
::DestroyWindow(_hSelf);
};
virtual ~Splitter() = default;
virtual void destroy() override;
void resizeSpliter(RECT *pRect = NULL);
void init(HINSTANCE hInst, HWND hPere, int splitterSize,
double iSplitRatio, DWORD dwFlags);
void init(HINSTANCE hInst, HWND hPere, int splitterSize, double iSplitRatio, DWORD dwFlags);
void rotate();
int getPhisicalSize() const {
int getPhisicalSize() const
{
return _spiltterSize;
};
}
private:
RECT _rect;
double _splitPercent;
int _spiltterSize;
bool _isDraged;
DWORD _dwFlags;
bool _isFixed;
double _splitPercent = 0.;
int _spiltterSize = 0;
bool _isDraged = false;
DWORD _dwFlags = 0;
bool _isFixed = false;
static bool _isHorizontalRegistered;
static bool _isVerticalRegistered;
static bool _isHorizontalFixedRegistered;
@ -105,26 +104,31 @@ private:
void gotoTopLeft();
void gotoRightBouuom();
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));
};
bool isInLeftTopZone(const POINT& p) const
{
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 {
return (((p.x >= _clickZone2BR.left) &&
(p.x <= _clickZone2BR.left + _clickZone2BR.right)) &&
(p.y >= _clickZone2BR.top) &&
(p.y <= _clickZone2BR.top + _clickZone2BR.bottom));
};
bool isInRightBottomZone(const POINT& p) const
{
return ((p.x >= _clickZone2BR.left)
and (p.x <= _clickZone2BR.left + _clickZone2BR.right)
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));
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));
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
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#include <iostream>
#include <windows.h>
#include "SplitterContainer.h"
#include <cassert>
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);
_pWin0 = pWin0;
@ -42,7 +44,8 @@ void SplitterContainer::create(Window *pWin0, Window *pWin1, int splitterSize,
_splitterMode = mode;
_ratio = ratio;
_dwSplitterStyle |= isVertical?SV_VERTICAL:SV_HORIZONTAL;
if (_splitterMode != DYNAMIC)
if (_splitterMode != SplitterMode::DYNAMIC)
{
_dwSplitterStyle |= SV_FIXED;
_dwSplitterStyle &= ~SV_RESIZEWTHPERCNT;
@ -66,30 +69,63 @@ void SplitterContainer::create(Window *pWin0, Window *pWin1, int splitterSize,
splitterContainerClass.lpszClassName = SPC_CLASS_NAME;
if (!::RegisterClass(&splitterContainerClass))
{
throw std::runtime_error(" SplitterContainer::create : RegisterClass() function failed");
}
_isRegistered = true;
}
_hSelf = ::CreateWindowEx(
0,
SPC_CLASS_NAME,
TEXT("a koi sert?"),
0, SPC_CLASS_NAME, TEXT("a koi sert?"),
WS_CHILD | WS_CLIPCHILDREN,
CW_USEDEFAULT, CW_USEDEFAULT,
CW_USEDEFAULT, CW_USEDEFAULT,
_hParent,
NULL,
_hInst,
(LPVOID)this);
CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT,
_hParent, NULL, _hInst, this);
if (!_hSelf)
{
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)
{
bool doSwitchWindow = false;
@ -97,13 +133,13 @@ void SplitterContainer::rotateTo(DIRECTION direction)
{
_dwSplitterStyle ^= SV_VERTICAL;
_dwSplitterStyle |= SV_HORIZONTAL;
doSwitchWindow = (direction == LEFT);
doSwitchWindow = (direction == DIRECTION::LEFT);
}
else
{
_dwSplitterStyle ^= SV_HORIZONTAL;
_dwSplitterStyle |= SV_VERTICAL;
doSwitchWindow = (direction == RIGHT);
doSwitchWindow = (direction == DIRECTION::RIGHT);
}
if (doSwitchWindow)
{
@ -120,42 +156,54 @@ LRESULT CALLBACK SplitterContainer::staticWinProc(HWND hwnd, UINT message, WPARA
SplitterContainer *pSplitterContainer = NULL;
switch (message)
{
case WM_NCCREATE :
case WM_NCCREATE:
{
pSplitterContainer = (SplitterContainer *)(((LPCREATESTRUCT)lParam)->lpCreateParams);
pSplitterContainer->_hSelf = hwnd;
::SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)pSplitterContainer);
return TRUE;
}
default :
default:
{
pSplitterContainer = (SplitterContainer *)::GetWindowLongPtr(hwnd, GWLP_USERDATA);
if (!pSplitterContainer)
return ::DefWindowProc(hwnd, message, wParam, lParam);
return pSplitterContainer->runProc(message, wParam, lParam);
}
}
}
LRESULT SplitterContainer::runProc(UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_CREATE :
case WM_CREATE:
{
_splitter.init(_hInst, _hSelf, _splitterSize, _ratio, _dwSplitterStyle);
return TRUE;
}
case WM_COMMAND :
case WM_COMMAND:
{
switch (LOWORD(wParam))
{
case ROTATION_A_GAUCHE:
rotateTo(LEFT);
return TRUE;
{
rotateTo(DIRECTION::LEFT);
break;
}
case ROTATION_A_DROITE:
rotateTo(RIGHT);
return TRUE;
{
rotateTo(DIRECTION::RIGHT);
break;
}
}
return TRUE;
}
case WM_RESIZE_CONTAINER :
case WM_RESIZE_CONTAINER:
{
RECT rc0, rc1;
getClientRect(rc0);
@ -192,9 +240,9 @@ LRESULT SplitterContainer::runProc(UINT message, WPARAM wParam, LPARAM lParam)
return TRUE;
}
case WM_DOPOPUPMENU :
case WM_DOPOPUPMENU:
{
if ((_splitterMode != LEFT_FIX) && (_splitterMode != RIGHT_FIX) )
if ((_splitterMode != SplitterMode::LEFT_FIX) && (_splitterMode != SplitterMode::RIGHT_FIX) )
{
POINT p;
::GetCursorPos(&p);
@ -213,35 +261,47 @@ LRESULT SplitterContainer::runProc(UINT message, WPARAM wParam, LPARAM lParam)
return TRUE;
}
case WM_GETSPLITTER_X :
case WM_GETSPLITTER_X:
{
if (_splitterMode == LEFT_FIX)
return MAKELONG(_pWin0->getWidth(), LEFT_FIX);
else if (_splitterMode == RIGHT_FIX)
switch (_splitterMode)
{
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();
if (x < 0)
x = 0;
return MAKELONG(x, RIGHT_FIX);
return MAKELONG(x, static_cast<std::uint8_t>(SplitterMode::RIGHT_FIX));
}
else
return MAKELONG(0, DYNAMIC);
default:
break;
}
return MAKELONG(0, static_cast<std::uint8_t>(SplitterMode::DYNAMIC));
}
case WM_GETSPLITTER_Y :
case WM_GETSPLITTER_Y:
{
if (_splitterMode == LEFT_FIX)
return MAKELONG(_pWin0->getHeight(), LEFT_FIX);
else if (_splitterMode == RIGHT_FIX)
switch (_splitterMode)
{
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();
if (y < 0)
y = 0;
return MAKELONG(y, RIGHT_FIX);
return MAKELONG(y, static_cast<std::uint8_t>(SplitterMode::RIGHT_FIX));
}
else
return MAKELONG(0, DYNAMIC);
default:
break;
}
return MAKELONG(0, static_cast<std::uint8_t>(SplitterMode::DYNAMIC));
}
case WM_LBUTTONDBLCLK:
@ -250,21 +310,18 @@ LRESULT SplitterContainer::runProc(UINT message, WPARAM wParam, LPARAM lParam)
::GetCursorPos(&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());
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, WM_COMMAND, IDM_FILE_NEW, 0);
return TRUE;
}
default :
default:
return ::DefWindowProc(_hSelf, message, wParam, lParam);
}
}

View File

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

View File

@ -29,6 +29,43 @@
#include <windows.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()
{
RECT rc;
@ -47,7 +84,8 @@ void StaticDialog::goToCenter()
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
// displayed the dialog, then ensure that it's still visible on the single monitor.
RECT workAreaRect = {0};
@ -57,6 +95,7 @@ void StaticDialog::display(bool toShow) const
int newLeft = rc.left;
int newTop = rc.top;
int margin = ::GetSystemMetrics(SM_CYSMCAPTION);
if (newLeft > ::GetSystemMetrics(SM_CXVIRTUALSCREEN)-margin)
newLeft -= rc.right - workAreaRect.right;
if (newLeft + (rc.right - rc.left) < ::GetSystemMetrics(SM_XVIRTUALSCREEN)+margin)
@ -131,11 +170,12 @@ void StaticDialog::create(int dialogID, bool isRTL, bool msgDestParent)
::SendMessage(msgDestParent?_hParent:(::GetParent(_hParent)), NPPM_MODELESSDIALOG, MODELESSDIALOGADD, (WPARAM)_hSelf);
}
INT_PTR CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG :
case WM_INITDIALOG:
{
StaticDialog *pStaticDlg = (StaticDialog *)(lParam);
pStaticDlg->_hSelf = hwnd;
@ -146,7 +186,7 @@ INT_PTR CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, L
return TRUE;
}
default :
default:
{
StaticDialog *pStaticDlg = reinterpret_cast<StaticDialog *>(::GetWindowLongPtr(hwnd, GWLP_USERDATA));
if (!pStaticDlg)
@ -166,26 +206,31 @@ void StaticDialog::alignWith(HWND handle, HWND handle2Align, PosAlign pos, POINT
switch (pos)
{
case ALIGNPOS_LEFT :
case PosAlign::left:
{
::GetWindowRect(handle2Align, &rc2);
point.x -= rc2.right - rc2.left;
break;
case ALIGNPOS_RIGHT :
}
case PosAlign::right:
{
::GetWindowRect(handle, &rc2);
point.x += rc2.right - rc2.left;
break;
case ALIGNPOS_TOP :
}
case PosAlign::top:
{
::GetWindowRect(handle2Align, &rc2);
point.y -= rc2.bottom - rc2.top;
break;
default : //ALIGNPOS_BOTTOM
}
case PosAlign::bottom:
{
::GetWindowRect(handle, &rc2);
point.y += rc2.bottom - rc2.top;
break;
}
}
::ScreenToClient(_hSelf, &point);
}

View File

@ -24,19 +24,18 @@
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#ifndef STATIC_DIALOG_H
#define STATIC_DIALOG_H
#pragma once
#include "Notepad_plus_msgs.h"
#include "Window.h"
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 signature;
DWORD helpID;
@ -48,51 +47,37 @@ struct DLGTEMPLATEEX {
short cx;
short cy;
// The structure has more fields but are variable length
} ;
};
class StaticDialog : public Window
{
public :
StaticDialog() : Window() {};
~StaticDialog(){
if (isCreated()) {
::SetWindowLongPtr(_hSelf, GWLP_USERDATA, (LONG_PTR)NULL); //Prevent run_dlgProc from doing anything, since its virtual
destroy();
}
};
virtual ~StaticDialog();
virtual void create(int dialogID, bool isRTL = false, bool msgDestParent = true);
virtual bool isCreated() const {
virtual bool isCreated() const
{
return (_hSelf != NULL);
};
}
void goToCenter();
void display(bool toShow = 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;
};
POINT getTopPoint(HWND hwnd, bool isLeft = true) const;
bool isCheckedOrNot(int checkControlID) const {
bool isCheckedOrNot(int checkControlID) const
{
return (BST_CHECKED == ::SendMessage(::GetDlgItem(_hSelf, checkControlID), BM_GETCHECK, 0, 0));
};
}
void destroy() {
::SendMessage(_hParent, NPPM_MODELESSDIALOG, MODELESSDIALOGREMOVE, (WPARAM)_hSelf);
::DestroyWindow(_hSelf);
};
virtual void destroy() override;
protected :
protected:
RECT _rc;
static INT_PTR CALLBACK dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
virtual INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam) = 0;
@ -100,5 +85,3 @@ protected :
void alignWith(HWND handle, HWND handle2Align, PosAlign pos, POINT & point);
HGLOBAL makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplate);
};
#endif //STATIC_DIALOG_H

View File

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

View File

@ -24,13 +24,11 @@
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#ifndef RESOURCE_H
#define RESOURCE_H
#pragma once
#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
// ex : #define VERSION_VALUE TEXT("5.63\0")
#define VERSION_VALUE TEXT("6.8.1\0")
@ -456,7 +454,3 @@
#define MENUINDEX_MACRO 7
#define MENUINDEX_RUN 8
#define MENUINDEX_PLUGINS 9
#endif // RESOURCE_H