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

@ -101,14 +101,12 @@
#define BGM_SETTITLECOLOR BABYGRID_USER + 54
#define BGM_SETTITLEGRIDLINECOLOR BABYGRID_USER + 55
struct _BGCELL {
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;