Modernize BabyGrid.cpp

1. Isolate the local variables.
2. Initialize the variables.
3. Prevent negative index in the tables.
4. Rename few variables.

Close #14893
pull/14894/head
Don Ho 2024-03-21 16:12:35 +01:00
parent 109600aa50
commit d7011c41bf
10 changed files with 1274 additions and 1374 deletions

View File

@ -5789,7 +5789,7 @@ void Notepad_plus::fullScreenToggle()
// show restore button
_restoreButton.doDialog(_nativeLangSpeaker.isRTL());
RECT rect;
RECT rect{};
GetWindowRect(_restoreButton.getHSelf(), &rect);
int w = rect.right - rect.left;
int h = rect.bottom - rect.top;
@ -5853,7 +5853,7 @@ void Notepad_plus::fullScreenToggle()
if (_beforeSpecialView._isPostIt)
{
// show restore button on the right position
RECT rect;
RECT rect{};
GetWindowRect(_restoreButton.getHSelf(), &rect);
int w = rect.right - rect.left;
int h = rect.bottom - rect.top;
@ -5923,7 +5923,7 @@ void Notepad_plus::postItToggle()
// show restore button
_restoreButton.doDialog(_nativeLangSpeaker.isRTL());
RECT rect;
RECT rect{};
GetWindowRect(_restoreButton.getHSelf(), &rect);
int w = rect.right - rect.left;
int h = rect.bottom - rect.top;

View File

@ -84,7 +84,7 @@ void Gripper::startGrip(DockingCont* pCont, DockingManager* pDockMgr)
if (!_isRegistered)
{
WNDCLASS clz;
WNDCLASS clz{};
clz.style = 0;
clz.lpfnWndProc = staticWinProc;

View File

@ -97,7 +97,7 @@ void DocumentMap::initWrapMap()
{
if (_pMapView && _ppEditView)
{
RECT rect;
RECT rect{};
getClientRect(rect);
::MoveWindow(_pMapView->getHSelf(), 0, 0, rect.right - rect.left, rect.bottom-rect.top, TRUE);
_pMapView->wrap(false);
@ -158,7 +158,7 @@ double zoomRatio[] = {1, 1, 1, 1, 1.5, 2, 2.5, 2.5, 3.5, 3.5,\
void DocumentMap::wrapMap(const ScintillaEditView *editView)
{
const ScintillaEditView *pEditView = editView ? editView : *_ppEditView;
RECT rect;
RECT rect{};
getClientRect(rect);
if (pEditView->isWrap())
{

File diff suppressed because it is too large Load Diff

View File

@ -14,101 +14,99 @@
#define WM_MOUSEWHEEL 0x020A
#endif //WM_MOUSEWHEEL
#define BGN_LBUTTONDOWN 0x0001
#define BGN_MOUSEMOVE 0x0002
#define BGN_OUTOFRANGE 0x0003
#define BGN_OWNERDRAW 0x0004
#define BGN_SELCHANGE 0x0005
#define BGN_ROWCHANGED 0x0006
#define BGN_COLCHANGED 0x0007
#define BGN_EDITBEGIN 0x0008
#define BGN_DELETECELL 0x0009
#define BGN_EDITEND 0x000A
#define BGN_F1 0x000B
#define BGN_F2 0x000C
#define BGN_F3 0x000D
#define BGN_F4 0x000E
#define BGN_F5 0x000F
#define BGN_F6 0x0010
#define BGN_F7 0x0011
#define BGN_F8 0x0012
#define BGN_F9 0x0013
#define BGN_F10 0x0014
#define BGN_F11 0x0015
#define BGN_F12 0x0016
#define BGN_GOTFOCUS 0x0017
#define BGN_LOSTFOCUS 0x0018
#define BGN_CELLCLICKED 0x0019
#define BGN_CELLDBCLICKED 0x001A
#define BGN_CELLRCLICKED 0x001B
#define BGN_LBUTTONDOWN 0x0001
#define BGN_MOUSEMOVE 0x0002
#define BGN_OUTOFRANGE 0x0003
#define BGN_OWNERDRAW 0x0004
#define BGN_SELCHANGE 0x0005
#define BGN_ROWCHANGED 0x0006
#define BGN_COLCHANGED 0x0007
#define BGN_EDITBEGIN 0x0008
#define BGN_DELETECELL 0x0009
#define BGN_EDITEND 0x000A
#define BGN_F1 0x000B
#define BGN_F2 0x000C
#define BGN_F3 0x000D
#define BGN_F4 0x000E
#define BGN_F5 0x000F
#define BGN_F6 0x0010
#define BGN_F7 0x0011
#define BGN_F8 0x0012
#define BGN_F9 0x0013
#define BGN_F10 0x0014
#define BGN_F11 0x0015
#define BGN_F12 0x0016
#define BGN_GOTFOCUS 0x0017
#define BGN_LOSTFOCUS 0x0018
#define BGN_CELLCLICKED 0x0019
#define BGN_CELLDBCLICKED 0x001A
#define BGN_CELLRCLICKED 0x001B
#define BGM_PROTECTCELL BABYGRID_USER + 1
#define BGM_SETPROTECT BABYGRID_USER + 2
#define BGM_SETCELLDATA BABYGRID_USER + 3
#define BGM_GETCELLDATA BABYGRID_USER + 4
#define BGM_CLEARGRID BABYGRID_USER + 5
#define BGM_SETGRIDDIM BABYGRID_USER + 6
#define BGM_DELETECELL BABYGRID_USER + 7
#define BGM_SETCURSORPOS BABYGRID_USER + 8
#define BGM_AUTOROW BABYGRID_USER + 9
#define BGM_GETOWNERDRAWITEM BABYGRID_USER + 10
#define BGM_SETCOLWIDTH BABYGRID_USER + 11
#define BGM_SETHEADERROWHEIGHT BABYGRID_USER + 12
#define BGM_GETTYPE BABYGRID_USER + 13
#define BGM_GETPROTECTION BABYGRID_USER + 14
#define BGM_DRAWCURSOR BABYGRID_USER + 15
#define BGM_SETROWHEIGHT BABYGRID_USER + 16
#define BGM_SETCURSORCOLOR BABYGRID_USER + 17
#define BGM_SETPROTECTCOLOR BABYGRID_USER + 18
#define BGM_SETUNPROTECTCOLOR BABYGRID_USER + 19
#define BGM_SETROWSNUMBERED BABYGRID_USER + 20
#define BGM_SETCOLSNUMBERED BABYGRID_USER + 21
#define BGM_SHOWHILIGHT BABYGRID_USER + 22
#define BGM_GETROWS BABYGRID_USER + 23
#define BGM_GETCOLS BABYGRID_USER + 24
#define BGM_NOTIFYROWCHANGED BABYGRID_USER + 25
#define BGM_NOTIFYCOLCHANGED BABYGRID_USER + 26
#define BGM_GETROW BABYGRID_USER + 27
#define BGM_GETCOL BABYGRID_USER + 28
#define BGM_PAINTGRID BABYGRID_USER + 29
#define BGM_GETCOLWIDTH BABYGRID_USER + 30
#define BGM_GETROWHEIGHT BABYGRID_USER + 31
#define BGM_GETHEADERROWHEIGHT BABYGRID_USER + 32
#define BGM_SETTITLEHEIGHT BABYGRID_USER + 33
#define BGM_PROTECTCELL BABYGRID_USER + 1
#define BGM_SETPROTECT BABYGRID_USER + 2
#define BGM_SETCELLDATA BABYGRID_USER + 3
#define BGM_GETCELLDATA BABYGRID_USER + 4
#define BGM_CLEARGRID BABYGRID_USER + 5
#define BGM_SETGRIDDIM BABYGRID_USER + 6
#define BGM_DELETECELL BABYGRID_USER + 7
#define BGM_SETCURSORPOS BABYGRID_USER + 8
#define BGM_AUTOROW BABYGRID_USER + 9
#define BGM_GETOWNERDRAWITEM BABYGRID_USER + 10
#define BGM_SETCOLWIDTH BABYGRID_USER + 11
#define BGM_SETHEADERROWHEIGHT BABYGRID_USER + 12
#define BGM_GETTYPE BABYGRID_USER + 13
#define BGM_GETPROTECTION BABYGRID_USER + 14
#define BGM_DRAWCURSOR BABYGRID_USER + 15
#define BGM_SETROWHEIGHT BABYGRID_USER + 16
#define BGM_SETCURSORCOLOR BABYGRID_USER + 17
#define BGM_SETPROTECTCOLOR BABYGRID_USER + 18
#define BGM_SETUNPROTECTCOLOR BABYGRID_USER + 19
#define BGM_SETROWSNUMBERED BABYGRID_USER + 20
#define BGM_SETCOLSNUMBERED BABYGRID_USER + 21
#define BGM_SHOWHILIGHT BABYGRID_USER + 22
#define BGM_GETROWS BABYGRID_USER + 23
#define BGM_GETCOLS BABYGRID_USER + 24
#define BGM_NOTIFYROWCHANGED BABYGRID_USER + 25
#define BGM_NOTIFYCOLCHANGED BABYGRID_USER + 26
#define BGM_GETROW BABYGRID_USER + 27
#define BGM_GETCOL BABYGRID_USER + 28
#define BGM_PAINTGRID BABYGRID_USER + 29
#define BGM_GETCOLWIDTH BABYGRID_USER + 30
#define BGM_GETROWHEIGHT BABYGRID_USER + 31
#define BGM_GETHEADERROWHEIGHT BABYGRID_USER + 32
#define BGM_SETTITLEHEIGHT BABYGRID_USER + 33
#define BGM_SETHILIGHTCOLOR BABYGRID_USER + 34
#define BGM_SETHILIGHTTEXTCOLOR BABYGRID_USER + 35
#define BGM_SETEDITABLE BABYGRID_USER + 36
#define BGM_SETGRIDLINECOLOR BABYGRID_USER + 37
#define BGM_EXTENDLASTCOLUMN BABYGRID_USER + 38
#define BGM_SHOWINTEGRALROWS BABYGRID_USER + 39
#define BGM_SETELLIPSIS BABYGRID_USER + 40
#define BGM_SETCOLAUTOWIDTH BABYGRID_USER + 41
#define BGM_SETALLOWCOLRESIZE BABYGRID_USER + 42
#define BGM_SETTITLEFONT BABYGRID_USER + 43
#define BGM_SETHEADINGFONT BABYGRID_USER + 44
#define BGM_GETHOMEROW BABYGRID_USER + 45
#define BGM_SETLASTVIEW BABYGRID_USER + 46
#define BGM_SETINITIALCONTENT BABYGRID_USER + 47
#define BGM_SETHILIGHTCOLOR_NOFOCUS BABYGRID_USER + 48
#define BGM_SETHILIGHTCOLOR_PROTECT BABYGRID_USER + 49
#define BGM_SETHILIGHTCOLOR_PROTECT_NOFOCUS BABYGRID_USER + 50
#define BGM_SETTEXTCOLOR BABYGRID_USER + 51
#define BGM_SETBACKGROUNDCOLOR BABYGRID_USER + 52
#define BGM_SETTITLETEXTCOLOR BABYGRID_USER + 53
#define BGM_SETTITLECOLOR BABYGRID_USER + 54
#define BGM_SETTITLEGRIDLINECOLOR BABYGRID_USER + 55
struct _BGCELL {
int row = 0;
int col = 0;
};
#define BGM_SETHILIGHTCOLOR BABYGRID_USER + 34
#define BGM_SETHILIGHTTEXTCOLOR BABYGRID_USER + 35
#define BGM_SETEDITABLE BABYGRID_USER + 36
#define BGM_SETGRIDLINECOLOR BABYGRID_USER + 37
#define BGM_EXTENDLASTCOLUMN BABYGRID_USER + 38
#define BGM_SHOWINTEGRALROWS BABYGRID_USER + 39
#define BGM_SETELLIPSIS BABYGRID_USER + 40
#define BGM_SETCOLAUTOWIDTH BABYGRID_USER + 41
#define BGM_SETALLOWCOLRESIZE BABYGRID_USER + 42
#define BGM_SETTITLEFONT BABYGRID_USER + 43
#define BGM_SETHEADINGFONT BABYGRID_USER + 44
#define BGM_GETHOMEROW BABYGRID_USER + 45
#define BGM_SETLASTVIEW BABYGRID_USER + 46
#define BGM_SETINITIALCONTENT BABYGRID_USER + 47
#define BGM_SETHILIGHTCOLOR_NOFOCUS BABYGRID_USER + 48
#define BGM_SETHILIGHTCOLOR_PROTECT BABYGRID_USER + 49
#define BGM_SETHILIGHTCOLOR_PROTECT_NOFOCUS BABYGRID_USER + 50
#define BGM_SETTEXTCOLOR BABYGRID_USER + 51
#define BGM_SETBACKGROUNDCOLOR BABYGRID_USER + 52
#define BGM_SETTITLETEXTCOLOR BABYGRID_USER + 53
#define BGM_SETTITLECOLOR BABYGRID_USER + 54
#define BGM_SETTITLEGRIDLINECOLOR BABYGRID_USER + 55
struct BGCELL {
int row = 0;
int col = 0;
};
//function forward declarations
ATOM RegisterGridClass(HINSTANCE);
LRESULT CALLBACK GridProc(HWND, UINT, WPARAM, LPARAM);
void SetCell(_BGCELL *cell,int row, int col);
void SetCell(BGCELL *cell,int row, int col);

View File

@ -29,12 +29,12 @@ void BabyGridWrapper::init(HINSTANCE hInst, HWND parent, int16_t id)
RegisterGridClass(_hInst);
_hSelf = ::CreateWindowEx(0,
babyGridClassName,\
TEXT(""),\
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER,\
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,\
_hParent,\
reinterpret_cast<HMENU>(id), \
_hInst,\
babyGridClassName,
TEXT(""),
WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER,
CW_USEDEFAULT, 0, CW_USEDEFAULT, 0,
_hParent,
reinterpret_cast<HMENU>(id),
_hInst,
NULL);
}

View File

@ -28,9 +28,11 @@ public:
~BabyGridWrapper() = default;
virtual void init(HINSTANCE hInst, HWND parent, int16_t id);
virtual void destroy() {
::DestroyWindow(_hSelf);
};
void setLineColNumber(size_t nbRow, size_t nbCol) {
::SendMessage(_hSelf, BGM_SETGRIDDIM, nbRow, nbCol);
};
@ -48,7 +50,7 @@ public:
}
void setText(size_t row, size_t col, const TCHAR* text) {
_BGCELL cell;
BGCELL cell;
cell.row = int(row);
cell.col = int(col);
::SendMessage(_hSelf, BGM_SETCELLDATA, reinterpret_cast<WPARAM>(&cell), reinterpret_cast<LPARAM>(text));
@ -63,7 +65,7 @@ public:
};
void deleteCell(int row, int col) {
_BGCELL cell;
BGCELL cell;
cell.row = row;
cell.col = col;
::SendMessage(_hSelf, BGM_DELETECELL, reinterpret_cast<WPARAM>(&cell), 0);

View File

@ -522,7 +522,7 @@ intptr_t CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARA
NppDarkMode::autoSubclassAndThemeChildControls(_hSelf);
RECT rect;
RECT rect{};
Window::getClientRect(rect);
_clientWidth = rect.right - rect.left;
_clientHeight = rect.bottom - rect.top;
@ -587,7 +587,7 @@ intptr_t CALLBACK ShortcutMapper::run_dlgProc(UINT message, WPARAM wParam, LPARA
{
LONG newWidth = LOWORD(lParam);
LONG newHeight = HIWORD(lParam);
RECT rect;
RECT rect{};
LONG addWidth = newWidth - _clientWidth;
LONG addHeight = newHeight - _clientHeight;

View File

@ -424,7 +424,7 @@ LRESULT CALLBACK Splitter::spliterWndProc(UINT uMsg, WPARAM wParam, LPARAM lPara
void Splitter::resizeSpliter(RECT *pRect)
{
RECT rect;
RECT rect{};
if (pRect)
rect = *pRect;

View File

@ -44,7 +44,7 @@ void SplitterContainer::create(Window *pWin0, Window *pWin1, int splitterSize, S
}
if (!_isRegistered)
{
WNDCLASS splitterContainerClass;
WNDCLASS splitterContainerClass{};
splitterContainerClass.style = CS_DBLCLKS;
splitterContainerClass.lpfnWndProc = staticWinProc;