Refactoring: Improve the code organization for color picker displaying

This commit is contained in:
Don Ho 2021-07-29 03:13:22 +02:00
parent 6894e96ad7
commit 7c9f4204ea
7 changed files with 42 additions and 87 deletions

View File

@ -1779,8 +1779,8 @@ INT_PTR CALLBACK StylerDlg::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPAR
dlg->_pBgColour->init(dlg->_hInst, hwnd);
dlg->_pBgColour->setColour(style._bgColor);
int w = nppParam._dpiManager.scaleX(30);
int h = nppParam._dpiManager.scaleY(30);
int w = nppParam._dpiManager.scaleX(25);
int h = nppParam._dpiManager.scaleY(25);
dlg->move2CtrlRight(hwnd, IDC_STYLER_FG_STATIC, dlg->_pFgColour->getHSelf(), w, h);
dlg->move2CtrlRight(hwnd, IDC_STYLER_BG_STATIC, dlg->_pBgColour->getHSelf(), w, h);

View File

@ -90,8 +90,6 @@ INT_PTR CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM l
_hFontSizeCombo = ::GetDlgItem(_hSelf, IDC_FONTSIZE_COMBO);
_hSwitch2ThemeCombo = ::GetDlgItem(_hSelf, IDC_SWITCH2THEME_COMBO);
_hFgColourStaticText = ::GetDlgItem(_hSelf, IDC_FG_STATIC);
_hBgColourStaticText = ::GetDlgItem(_hSelf, IDC_BG_STATIC);
_hFontNameStaticText = ::GetDlgItem(_hSelf, IDC_FONTNAME_STATIC);
_hFontSizeStaticText = ::GetDlgItem(_hSelf, IDC_FONTSIZE_STATIC);
_hStyleInfoStaticText = ::GetDlgItem(_hSelf, IDC_STYLEDESCRIPTION_STATIC);
@ -137,23 +135,15 @@ INT_PTR CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM l
_pFgColour->init(_hInst, _hSelf);
_pBgColour->init(_hInst, _hSelf);
POINT p1, 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;
int cpDynamicalWidth = NppParameters::getInstance()._dpiManager.scaleX(25);
int cpDynamicalHeight = NppParameters::getInstance()._dpiManager.scaleY(25);
::MoveWindow(reinterpret_cast<HWND>(_pFgColour->getHSelf()), p1.x, p1.y, cpDynamicalWidth, cpDynamicalHeight, TRUE);
::MoveWindow(reinterpret_cast<HWND>(_pBgColour->getHSelf()), p2.x, p2.y, cpDynamicalWidth, cpDynamicalHeight, TRUE);
move2CtrlRight(IDC_FG_STATIC, _pFgColour->getHSelf(), cpDynamicalWidth, cpDynamicalHeight);
move2CtrlRight(IDC_BG_STATIC, _pBgColour->getHSelf(), cpDynamicalWidth, cpDynamicalHeight);
_pFgColour->display();
_pBgColour->display();
::EnableWindow(::GetDlgItem(_hSelf, IDOK), _isDirty);
::EnableWindow(::GetDlgItem(_hSelf, IDC_SAVECLOSE_BUTTON), FALSE/*!_isSync*/);
@ -531,6 +521,19 @@ INT_PTR CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM l
return FALSE;
}
void WordStyleDlg::move2CtrlRight(int ctrlID, HWND handle2Move, int handle2MoveWidth, int handle2MoveHeight)
{
POINT p;
RECT rc;
::GetWindowRect(::GetDlgItem(_hSelf, ctrlID), &rc);
p.x = rc.right + NppParameters::getInstance()._dpiManager.scaleX(5);
p.y = rc.top + ((rc.bottom - rc.top) / 2) - handle2MoveHeight / 2;
::ScreenToClient(_hSelf, &p);
::MoveWindow(handle2Move, p.x, p.y, handle2MoveWidth, handle2MoveHeight, TRUE);
}
void WordStyleDlg::loadLangListFromNppParam()
{
NppParameters& nppParamInst = NppParameters::getInstance();

View File

@ -164,7 +164,7 @@ private :
};
int whichTabColourIndex();
void move2CtrlRight(int ctrlID, HWND handle2Move, int handle2MoveWidth, int handle2MoveHeight);
void updateColour(bool which);
void updateFontStyleStatus(fontStyleType whitchStyle);
void updateExtension();

View File

@ -931,6 +931,19 @@ void DarkModeSubDlg::enableCustomizedColorCtrls(bool doEnable)
}
}
void DarkModeSubDlg::move2CtrlLeft(int ctrlID, HWND handle2Move, int handle2MoveWidth, int handle2MoveHeight)
{
POINT p;
RECT rc;
::GetWindowRect(::GetDlgItem(_hSelf, ctrlID), &rc);
p.x = rc.left - NppParameters::getInstance()._dpiManager.scaleX(5) - handle2MoveWidth;
p.y = rc.top + ((rc.bottom - rc.top) / 2) - handle2MoveHeight / 2;
::ScreenToClient(_hSelf, &p);
::MoveWindow(handle2Move, p.x, p.y, handle2MoveWidth, handle2MoveHeight, TRUE);
}
INT_PTR CALLBACK DarkModeSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam)
{
UNREFERENCED_PARAMETER(lParam);
@ -993,42 +1006,19 @@ INT_PTR CALLBACK DarkModeSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
_pEdgeColorPicker->init(_hInst, _hSelf);
_pLinkColorPicker->init(_hInst, _hSelf);
POINT p1, p2, p3, p4, p5, p6, p7, p8, p9, p10;
alignWith(::GetDlgItem(_hSelf, IDD_CUSTOMIZED_COLOR1_STATIC), _pPureBackgroundColorPicker->getHSelf(), PosAlign::left, p1);
alignWith(::GetDlgItem(_hSelf, IDD_CUSTOMIZED_COLOR2_STATIC), _pHotBackgroundColorPicker->getHSelf(), PosAlign::left, p2);
alignWith(::GetDlgItem(_hSelf, IDD_CUSTOMIZED_COLOR3_STATIC), _pSofterBackgroundColorPicker->getHSelf(), PosAlign::left, p3);
alignWith(::GetDlgItem(_hSelf, IDD_CUSTOMIZED_COLOR4_STATIC), _pBackgroundColorPicker->getHSelf(), PosAlign::left, p4);
alignWith(::GetDlgItem(_hSelf, IDD_CUSTOMIZED_COLOR5_STATIC), _pErrorBackgroundColorPicker->getHSelf(), PosAlign::left, p5);
alignWith(::GetDlgItem(_hSelf, IDD_CUSTOMIZED_COLOR6_STATIC), _pTextColorPicker->getHSelf(), PosAlign::left, p6);
alignWith(::GetDlgItem(_hSelf, IDD_CUSTOMIZED_COLOR7_STATIC), _pDarkerTextColorPicker->getHSelf(), PosAlign::left, p7);
alignWith(::GetDlgItem(_hSelf, IDD_CUSTOMIZED_COLOR8_STATIC), _pDisabledTextColorPicker->getHSelf(), PosAlign::left, p8);
alignWith(::GetDlgItem(_hSelf, IDD_CUSTOMIZED_COLOR9_STATIC), _pEdgeColorPicker->getHSelf(), PosAlign::left, p9);
alignWith(::GetDlgItem(_hSelf, IDD_CUSTOMIZED_COLOR10_STATIC), _pLinkColorPicker->getHSelf(), PosAlign::left, p10);
int cpDynamicalWidth = NppParameters::getInstance()._dpiManager.scaleX(25);
int cpDynamicalHeight = NppParameters::getInstance()._dpiManager.scaleY(25);
p1.x -= cpDynamicalWidth ; p1.y -= cpDynamicalHeight / 6;
p2.x -= cpDynamicalWidth ; p2.y -= cpDynamicalHeight / 6;
p3.x -= cpDynamicalWidth ; p3.y -= cpDynamicalHeight / 6;
p4.x -= cpDynamicalWidth ; p4.y -= cpDynamicalHeight / 6;
p5.x -= cpDynamicalWidth ; p5.y -= cpDynamicalHeight / 6;
p6.x -= cpDynamicalWidth ; p6.y -= cpDynamicalHeight / 6;
p7.x -= cpDynamicalWidth ; p7.y -= cpDynamicalHeight / 6;
p8.x -= cpDynamicalWidth ; p8.y -= cpDynamicalHeight / 6;
p9.x -= cpDynamicalWidth ; p9.y -= cpDynamicalHeight / 6;
p10.x -= cpDynamicalWidth; p10.y -= cpDynamicalHeight / 6;
::MoveWindow(reinterpret_cast<HWND>(_pPureBackgroundColorPicker->getHSelf()), p1.x, p1.y, cpDynamicalWidth, cpDynamicalHeight, TRUE);
::MoveWindow(reinterpret_cast<HWND>(_pHotBackgroundColorPicker->getHSelf()), p2.x, p2.y, cpDynamicalWidth, cpDynamicalHeight, TRUE);
::MoveWindow(reinterpret_cast<HWND>(_pSofterBackgroundColorPicker->getHSelf()), p3.x, p3.y, cpDynamicalWidth, cpDynamicalHeight, TRUE);
::MoveWindow(reinterpret_cast<HWND>(_pBackgroundColorPicker->getHSelf()), p4.x, p4.y, cpDynamicalWidth, cpDynamicalHeight, TRUE);
::MoveWindow(reinterpret_cast<HWND>(_pErrorBackgroundColorPicker->getHSelf()), p5.x, p5.y, cpDynamicalWidth, cpDynamicalHeight, TRUE);
::MoveWindow(reinterpret_cast<HWND>(_pTextColorPicker->getHSelf()), p6.x, p6.y, cpDynamicalWidth, cpDynamicalHeight, TRUE);
::MoveWindow(reinterpret_cast<HWND>(_pDarkerTextColorPicker->getHSelf()), p7.x, p7.y, cpDynamicalWidth, cpDynamicalHeight, TRUE);
::MoveWindow(reinterpret_cast<HWND>(_pDisabledTextColorPicker->getHSelf()), p8.x, p8.y, cpDynamicalWidth, cpDynamicalHeight, TRUE);
::MoveWindow(reinterpret_cast<HWND>(_pEdgeColorPicker->getHSelf()), p9.x, p9.y, cpDynamicalWidth, cpDynamicalHeight, TRUE);
::MoveWindow(reinterpret_cast<HWND>(_pLinkColorPicker->getHSelf()), p10.x, p10.y, cpDynamicalWidth, cpDynamicalHeight, TRUE);
move2CtrlLeft(IDD_CUSTOMIZED_COLOR1_STATIC, _pPureBackgroundColorPicker->getHSelf(), cpDynamicalWidth, cpDynamicalHeight);
move2CtrlLeft(IDD_CUSTOMIZED_COLOR2_STATIC, _pHotBackgroundColorPicker->getHSelf(), cpDynamicalWidth, cpDynamicalHeight);
move2CtrlLeft(IDD_CUSTOMIZED_COLOR3_STATIC, _pSofterBackgroundColorPicker->getHSelf(), cpDynamicalWidth, cpDynamicalHeight);
move2CtrlLeft(IDD_CUSTOMIZED_COLOR4_STATIC, _pBackgroundColorPicker->getHSelf(), cpDynamicalWidth, cpDynamicalHeight);
move2CtrlLeft(IDD_CUSTOMIZED_COLOR5_STATIC, _pErrorBackgroundColorPicker->getHSelf(), cpDynamicalWidth, cpDynamicalHeight);
move2CtrlLeft(IDD_CUSTOMIZED_COLOR6_STATIC, _pTextColorPicker->getHSelf(), cpDynamicalWidth, cpDynamicalHeight);
move2CtrlLeft(IDD_CUSTOMIZED_COLOR7_STATIC, _pDarkerTextColorPicker->getHSelf(), cpDynamicalWidth, cpDynamicalHeight);
move2CtrlLeft(IDD_CUSTOMIZED_COLOR8_STATIC, _pDisabledTextColorPicker->getHSelf(), cpDynamicalWidth, cpDynamicalHeight);
move2CtrlLeft(IDD_CUSTOMIZED_COLOR9_STATIC, _pEdgeColorPicker->getHSelf(), cpDynamicalWidth, cpDynamicalHeight);
move2CtrlLeft(IDD_CUSTOMIZED_COLOR10_STATIC, _pLinkColorPicker->getHSelf(), cpDynamicalWidth, cpDynamicalHeight);
_pBackgroundColorPicker->display();
_pSofterBackgroundColorPicker->display();

View File

@ -73,6 +73,7 @@ private:
INT_PTR CALLBACK run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam);
void enableCustomizedColorCtrls(bool doEnable);
void move2CtrlLeft(int ctrlID, HWND handle2Move, int handle2MoveWidth, int handle2MoveHeight);
};
class MarginsBorderEdgeSubDlg : public StaticDialog

View File

@ -256,41 +256,3 @@ INT_PTR CALLBACK StaticDialog::dlgProc(HWND hwnd, UINT message, WPARAM wParam, L
}
}
void StaticDialog::alignWith(HWND handle, HWND handle2Align, PosAlign pos, POINT & point)
{
RECT rc, rc2;
::GetWindowRect(handle, &rc);
point.x = rc.left;
point.y = rc.top;
switch (pos)
{
case PosAlign::left:
{
::GetWindowRect(handle2Align, &rc2);
point.x -= rc2.right - rc2.left;
break;
}
case PosAlign::right:
{
::GetWindowRect(handle, &rc2);
point.x += rc2.right - rc2.left;
break;
}
case PosAlign::top:
{
::GetWindowRect(handle2Align, &rc2);
point.y -= rc2.bottom - rc2.top;
break;
}
case PosAlign::bottom:
{
::GetWindowRect(handle, &rc2);
point.y += rc2.bottom - rc2.top;
break;
}
}
::ScreenToClient(_hSelf, &point);
}

View File

@ -72,6 +72,5 @@ protected:
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;
void alignWith(HWND handle, HWND handle2Align, PosAlign pos, POINT & point);
HGLOBAL makeRTLResource(int dialogID, DLGTEMPLATE **ppMyDlgTemplate);
};