Add new DPI support to dialogs

- Run
- Run a Macro Multiple Times...
- Shortcut

- code enhancement
    - add override in shortcut.h
    - modify switches in WM_COMMAND
    - optimize dark mode for shortcut
    - avoid potential multiple subclassing for Run dialog

ref #14959

Close #15017
pull/15022/head
ozone10 7 months ago committed by Don Ho
parent 61083a4468
commit 34a6bf196e

@ -246,6 +246,13 @@ intptr_t CALLBACK RunDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam
{
switch (message)
{
case WM_INITDIALOG:
{
NppDarkMode::autoSubclassAndThemeChildControls(_hSelf);
return TRUE;
}
case NPPM_INTERNAL_FINDKEYCONFLICTS:
{
return ::SendMessage(_hParent, message, wParam, lParam);
@ -296,7 +303,7 @@ intptr_t CALLBACK RunDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam
case WM_CHANGEUISTATE:
{
if (NppDarkMode::isEnabled() && !NppDarkMode::isWindows11())
if (NppDarkMode::isEnabled())
{
redrawDlgItem(IDC_MAINTEXT_STATIC);
}
@ -304,9 +311,17 @@ intptr_t CALLBACK RunDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM lParam
return FALSE;
}
case WM_DPICHANGED:
{
DPIManagerV2::setDpiWP(wParam);
setPositionDpi(lParam);
return TRUE;
}
case WM_COMMAND:
{
switch (wParam)
switch (LOWORD(wParam))
{
case IDCANCEL :
display(false);
@ -430,9 +445,8 @@ void RunDlg::doDialog(bool isRTL)
if (!isCreated())
create(IDD_RUN_DLG, isRTL);
NppDarkMode::autoSubclassAndThemeChildControls(_hSelf);
// Adjust the position in the center
goToCenter(SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOACTIVATE);
goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE);
::SetFocus(::GetDlgItem(_hSelf, IDC_COMBO_RUN_PATH));
}

@ -105,7 +105,7 @@ intptr_t CALLBACK RunMacroDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
case WM_CHANGEUISTATE:
{
if (NppDarkMode::isEnabled() && !NppDarkMode::isWindows11())
if (NppDarkMode::isEnabled())
{
redrawDlgItem(IDC_MACRO2RUN_STATIC);
}
@ -113,9 +113,17 @@ intptr_t CALLBACK RunMacroDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
return FALSE;
}
case WM_DPICHANGED:
{
DPIManagerV2::setDpiWP(wParam);
setPositionDpi(lParam);
return TRUE;
}
case WM_COMMAND:
{
switch (wParam)
switch (LOWORD(wParam))
{
case IDC_M_RUN_MULTI:
case IDC_M_RUN_EOF:
@ -147,47 +155,36 @@ intptr_t CALLBACK RunMacroDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
return TRUE;
}
default:
case IDC_MACRO_COMBO:
{
switch (LOWORD(wParam))
if (HIWORD(wParam) == CBN_SELCHANGE)
{
case IDC_MACRO_COMBO:
_macroIndex = static_cast<int32_t>(::SendDlgItemMessage(_hSelf, IDC_MACRO_COMBO, CB_GETCURSEL, 0, 0));
return TRUE;
}
return FALSE;
}
case IDC_M_RUN_TIMES:
{
switch (HIWORD(wParam))
{
case EN_KILLFOCUS:
{
if (HIWORD(wParam) == CBN_SELCHANGE)
const int times = ::GetDlgItemInt(_hSelf, IDC_M_RUN_TIMES, nullptr, FALSE);
if (times < 1)
{
_macroIndex = static_cast<int32_t>(::SendDlgItemMessage(_hSelf, IDC_MACRO_COMBO, CB_GETCURSEL, 0, 0));
::SetDlgItemInt(_hSelf, IDC_M_RUN_TIMES, 1, FALSE);
return TRUE;
}
return FALSE;
}
case IDC_M_RUN_TIMES:
case EN_CHANGE:
{
switch (HIWORD(wParam))
{
case EN_KILLFOCUS:
{
const int times = ::GetDlgItemInt(_hSelf, IDC_M_RUN_TIMES, nullptr, FALSE);
if (times < 1)
{
::SetDlgItemInt(_hSelf, IDC_M_RUN_TIMES, 1, FALSE);
return TRUE;
}
return FALSE;
}
case EN_CHANGE:
{
_times = std::max<int>(::GetDlgItemInt(_hSelf, IDC_M_RUN_TIMES, nullptr, FALSE), 1);
return TRUE;
}
default:
{
return FALSE;
}
}
_times = std::max<int>(::GetDlgItemInt(_hSelf, IDC_M_RUN_TIMES, nullptr, FALSE), 1);
return TRUE;
}
default:
@ -196,6 +193,11 @@ intptr_t CALLBACK RunMacroDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
}
}
}
default:
{
return FALSE;
}
}
}
}

@ -370,7 +370,7 @@ intptr_t CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPar
{
switch (Message)
{
case WM_INITDIALOG :
case WM_INITDIALOG:
{
NppDarkMode::autoSubclassAndThemeChildControls(_hSelf);
@ -401,26 +401,18 @@ intptr_t CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPar
updateConflictState();
NativeLangSpeaker* nativeLangSpeaker = NppParameters::getInstance().getNativeLangSpeaker();
nativeLangSpeaker->changeDlgLang(_hSelf, "ShortcutMapperSubDialg");
goToCenter();
goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE);
return TRUE;
}
case WM_CTLCOLOREDIT:
{
if (NppDarkMode::isEnabled())
{
return NppDarkMode::onCtlColorSofter(reinterpret_cast<HDC>(wParam));
}
break;
return NppDarkMode::onCtlColorSofter(reinterpret_cast<HDC>(wParam));
}
case WM_CTLCOLORLISTBOX:
{
if (NppDarkMode::isEnabled())
{
return NppDarkMode::onCtlColor(reinterpret_cast<HDC>(wParam));
}
break;
return NppDarkMode::onCtlColor(reinterpret_cast<HDC>(wParam));
}
case WM_CTLCOLORDLG:
@ -434,7 +426,6 @@ intptr_t CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPar
return NppDarkMode::onCtlColor(reinterpret_cast<HDC>(wParam));
}
return NppDarkMode::onCtlColorDarker(reinterpret_cast<HDC>(wParam));
}
break;
}
@ -454,10 +445,18 @@ intptr_t CALLBACK Shortcut::run_dlgProc(UINT Message, WPARAM wParam, LPARAM lPar
return TRUE;
}
case WM_COMMAND :
case WM_DPICHANGED:
{
DPIManagerV2::setDpiWP(wParam);
setPositionDpi(lParam);
return TRUE;
}
case WM_COMMAND:
{
auto textlen = ::SendDlgItemMessage(_hSelf, IDC_NAME_EDIT, WM_GETTEXTLENGTH, 0, 0);
switch (wParam)
switch (LOWORD(wParam))
{
case IDC_CTRL_CHECK :
_keyCombo._isCtrl = BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast<int32_t>(wParam), BM_GETCHECK, 0, 0);
@ -915,7 +914,7 @@ void recordedMacroStep::PlayBack(Window* pNotepad, ScintillaEditView *pEditView)
|| (_message == SCI_INSERTTEXT)
|| (_message == SCI_APPENDTEXT) )
{
SCNotification scnN;
SCNotification scnN{};
scnN.nmhdr.code = SCN_CHARADDED;
scnN.nmhdr.hwndFrom = pEditView->getHSelf();
scnN.nmhdr.idFrom = 0;
@ -1057,7 +1056,7 @@ intptr_t CALLBACK ScintillaKeyMap::run_dlgProc(UINT Message, WPARAM wParam, LPAR
switch (Message)
{
case WM_INITDIALOG :
case WM_INITDIALOG:
{
NppDarkMode::autoSubclassAndThemeChildControls(_hSelf);
@ -1083,26 +1082,18 @@ intptr_t CALLBACK ScintillaKeyMap::run_dlgProc(UINT Message, WPARAM wParam, LPAR
NativeLangSpeaker* nativeLangSpeaker = NppParameters::getInstance().getNativeLangSpeaker();
nativeLangSpeaker->changeDlgLang(_hSelf, "ShortcutMapperSubDialg");
goToCenter();
goToCenter(SWP_SHOWWINDOW | SWP_NOSIZE);
return TRUE;
}
case WM_CTLCOLOREDIT:
{
if (NppDarkMode::isEnabled())
{
return NppDarkMode::onCtlColor(reinterpret_cast<HDC>(wParam));
}
break;
return NppDarkMode::onCtlColor(reinterpret_cast<HDC>(wParam));
}
case WM_CTLCOLORLISTBOX:
{
if (NppDarkMode::isEnabled())
{
return NppDarkMode::onCtlColorListbox(wParam, lParam);
}
break;
return NppDarkMode::onCtlColorListbox(wParam, lParam);
}
case WM_CTLCOLORDLG:
@ -1135,9 +1126,17 @@ intptr_t CALLBACK ScintillaKeyMap::run_dlgProc(UINT Message, WPARAM wParam, LPAR
return TRUE;
}
case WM_COMMAND :
case WM_DPICHANGED:
{
DPIManagerV2::setDpiWP(wParam);
setPositionDpi(lParam);
return TRUE;
}
case WM_COMMAND:
{
switch (wParam)
switch (LOWORD(wParam))
{
case IDC_CTRL_CHECK :
_keyCombo._isCtrl = BST_CHECKED == ::SendDlgItemMessage(_hSelf, static_cast<int32_t>(wParam), BM_GETCHECK, 0, 0);
@ -1165,7 +1164,7 @@ intptr_t CALLBACK ScintillaKeyMap::run_dlgProc(UINT Message, WPARAM wParam, LPAR
::EndDialog(_hSelf, -1);
return TRUE;
case IDC_BUTTON_ADD:
case IDC_BUTTON_ADD:
{
size_t oldsize = _size;
int res = addKeyCombo(_keyCombo);
@ -1209,7 +1208,7 @@ intptr_t CALLBACK ScintillaKeyMap::run_dlgProc(UINT Message, WPARAM wParam, LPAR
}
default:
if (HIWORD(wParam) == CBN_SELCHANGE || HIWORD(wParam) == LBN_SELCHANGE)
if (HIWORD(wParam) == CBN_SELCHANGE) // LBN_SELCHANGE has same value 1
{
switch(LOWORD(wParam))
{

@ -175,7 +175,7 @@ public:
protected :
KeyCombo _keyCombo;
virtual intptr_t CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam);
intptr_t CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) override;
bool _canModifyName = false;
char _name[menuItemStrLenMax] {}; //normal name is plain text (for display purposes)
char _menuName[menuItemStrLenMax] {}; //menu name has ampersands for quick keys
@ -232,13 +232,13 @@ public:
_size = 1;
};
int addKeyCombo(KeyCombo combo);
bool isEnabled() const;
bool isEnabled() const override;
size_t getSize() const;
std::string toString() const;
std::string toString() const override;
std::string toString(size_t index) const;
intptr_t doDialog()
intptr_t doDialog() override
{
return ::DialogBoxParam(_hInst, MAKEINTRESOURCE(IDD_SHORTCUTSCINT_DLG), _hParent, dlgProc, reinterpret_cast<LPARAM>(this));
};
@ -275,7 +275,7 @@ private:
void showCurrentSettings();
void updateListItem(int index);
protected :
intptr_t CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam);
intptr_t CALLBACK run_dlgProc(UINT Message, WPARAM wParam, LPARAM lParam) override;
};
@ -334,7 +334,7 @@ class PluginCmdShortcut : public CommandShortcut {
public:
PluginCmdShortcut(const Shortcut& sc, int id, const char*moduleName, unsigned short internalID) :\
CommandShortcut(sc, id), _id(id), _moduleName(moduleName), _internalID(internalID) {};
bool isValid() const {
bool isValid() const override {
if (!Shortcut::isValid())
return false;
if ((!_moduleName[0]) || (_internalID == -1))

Loading…
Cancel
Save