diff --git a/PowerEditor/src/NppDarkMode.cpp b/PowerEditor/src/NppDarkMode.cpp index 13e216c5d..03b1ae1e4 100644 --- a/PowerEditor/src/NppDarkMode.cpp +++ b/PowerEditor/src/NppDarkMode.cpp @@ -1009,6 +1009,37 @@ namespace NppDarkMode HTHEME hTheme = nullptr; int iStateID = 0; + bool isSizeSet = false; + SIZE szBtn{}; + + ButtonData() {}; + + // Saves width and height from the resource file for use as restrictions. + ButtonData(HWND hWnd) + { + // Notepad++ doesn't use BS_3STATE, BS_AUTO3STATE and BS_PUSHLIKE buttons. + const auto nBtnStyle = ::GetWindowLongPtrW(hWnd, GWL_STYLE); + switch (nBtnStyle & BS_TYPEMASK) + { + case BS_CHECKBOX: + case BS_AUTOCHECKBOX: + case BS_RADIOBUTTON: + case BS_AUTORADIOBUTTON: + { + if ((nBtnStyle & BS_MULTILINE) != BS_MULTILINE) + { + RECT rcBtn{}; + ::GetClientRect(hWnd, &rcBtn); + szBtn = { rcBtn.right - rcBtn.left, rcBtn.bottom - rcBtn.top }; + isSizeSet = (szBtn.cx != 0 && szBtn.cy != 0); + } + break; + } + default: + break; + } + } + ~ButtonData() { closeTheme(); @@ -1207,16 +1238,34 @@ namespace NppDarkMode switch (uMsg) { + case WM_SETBUTTONIDEALSIZE: + { + if (pButtonData->isSizeSet) + { + SIZE szBtn{}; + if (Button_GetIdealSize(hWnd, &szBtn) == TRUE) + { + const int cx = std::min(szBtn.cx, pButtonData->szBtn.cx); + const int cy = std::min(szBtn.cy, pButtonData->szBtn.cy); + ::SetWindowPos(hWnd, nullptr, 0, 0, cx, cy, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOOWNERZORDER); + } + } + return 0; + } + case WM_UPDATEUISTATE: if (HIWORD(wParam) & (UISF_HIDEACCEL | UISF_HIDEFOCUS)) { InvalidateRect(hWnd, nullptr, FALSE); } break; + case WM_NCDESTROY: - RemoveWindowSubclass(hWnd, ButtonSubclass, g_buttonSubclassID); + { + ::RemoveWindowSubclass(hWnd, ButtonSubclass, g_buttonSubclassID); delete pButtonData; break; + } case WM_ERASEBKGND: { @@ -1283,8 +1332,29 @@ namespace NppDarkMode void subclassButtonControl(HWND hwnd) { - DWORD_PTR pButtonData = reinterpret_cast(new ButtonData()); + DWORD_PTR pButtonData = reinterpret_cast(new ButtonData(hwnd)); SetWindowSubclass(hwnd, ButtonSubclass, g_buttonSubclassID, pButtonData); + + // The following code handles default English localization during Notepad++ launch for button size. + // For other languages, NativeLangSpeaker::resizeCheckboxRadioBtn will adjust button dimensions. + const auto nBtnStyle = ::GetWindowLongPtrW(hwnd, GWL_STYLE); + switch (nBtnStyle & BS_TYPEMASK) + { + case BS_CHECKBOX: + case BS_AUTOCHECKBOX: + case BS_RADIOBUTTON: + case BS_AUTORADIOBUTTON: + { + if ((nBtnStyle & BS_MULTILINE) != BS_MULTILINE) + { + ::SendMessageW(hwnd, NppDarkMode::WM_SETBUTTONIDEALSIZE, 0, 0); + } + break; + } + + default: + break; + } } static void paintGroupbox(HWND hwnd, HDC hdc, ButtonData& buttonData) @@ -2322,7 +2392,7 @@ namespace NppDarkMode auto nButtonStyle = ::GetWindowLongPtr(hwnd, GWL_STYLE); switch (nButtonStyle & BS_TYPEMASK) { - // Plugin might use BS_3STATE and BS_AUTO3STATE button style + // Plugin might use BS_3STATE, BS_AUTO3STATE and BS_PUSHLIKE button style case BS_CHECKBOX: case BS_AUTOCHECKBOX: case BS_3STATE: diff --git a/PowerEditor/src/NppDarkMode.h b/PowerEditor/src/NppDarkMode.h index c9363eadd..8a983d736 100644 --- a/PowerEditor/src/NppDarkMode.h +++ b/PowerEditor/src/NppDarkMode.h @@ -95,6 +95,8 @@ namespace NppDarkMode NppDarkMode::AdvOptDefaults _lightDefaults{ L"", 4, 0, true }; }; + constexpr UINT WM_SETBUTTONIDEALSIZE = (WM_USER + 4200); + void initDarkMode(); // pulls options from NppParameters void refreshDarkMode(HWND hwnd, bool forceRefresh = false); // attempts to apply new options from NppParameters, sends NPPM_INTERNAL_REFRESHDARKMODE to hwnd's top level parent diff --git a/PowerEditor/src/WinControls/Preference/preference.rc b/PowerEditor/src/WinControls/Preference/preference.rc index bba89dcab..97fe767a8 100644 --- a/PowerEditor/src/WinControls/Preference/preference.rc +++ b/PowerEditor/src/WinControls/Preference/preference.rc @@ -66,7 +66,7 @@ BEGIN CONTROL "Exit on close the last tab",IDC_CHECK_TAB_LAST_EXIT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,229,143,164,10 GROUPBOX "Menu",IDC_MENU_GB_STATIC,27,160,373,34,BS_CENTER - CONTROL "Hide menu bar (use Alt or F10 key to toggle)",IDC_CHECK_HIDEMENUBAR,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,33,168,218,10 + CONTROL "Hide menu bar (use Alt or F10 key to toggle)",IDC_CHECK_HIDEMENUBAR,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,33,168,218,10 CONTROL "Hide right shortcuts + ▼ ✕ from the menu bar (Need to restart Notepad++)",IDC_CHECK_HIDERIGHTSHORTCUTSOFMENUBAR,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,33,181,350,10 END @@ -298,20 +298,23 @@ IDD_PREFERENCE_SUB_HIGHLIGHTING DIALOGEX 115, 10, 460, 205 STYLE DS_SETFONT | DS_FIXEDSYS | DS_CONTROL | WS_CHILD FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN - GROUPBOX "Style All Occurrences of Token",IDC_MARKALL_STATIC,62,29,155,45,BS_CENTER - CONTROL "Match case",IDC_CHECK_MARKALLCASESENSITIVE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,70,42,142,10 - CONTROL "Match whole word only",IDC_CHECK_MARKALLWHOLEWORDONLY,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,70,55,142,10 - GROUPBOX "Smart Highlighting",IDC_SMARTHILITING_STATIC,226,29,172,108,BS_CENTER - CONTROL "Enable",IDC_CHECK_ENABLSMARTHILITE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,234,39,142,10 - CONTROL "Highlight another view",IDC_CHECK_SMARTHILITEANOTHERRVIEW,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,234,55,142,10 - GROUPBOX "Matching", IDC_SMARTHILITEMATCHING_STATIC,233,74,155,55,BS_CENTER - CONTROL "Match case",IDC_CHECK_SMARTHILITECASESENSITIVE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,241,86,142,10 - CONTROL "Match whole word only",IDC_CHECK_SMARTHILITEWHOLEWORDONLY,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,241,99,142,10 - CONTROL "Use Find dialog settings",IDC_CHECK_SMARTHILITEUSEFINDSETTINGS,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,241,113,142,10 - GROUPBOX "Highlight Matching Tags",IDC_TAGMATCHEDHILITE_STATIC,62,82,155,55,BS_CENTER - CONTROL "Enable",IDC_CHECK_ENABLTAGSMATCHHILITE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,71,92,140,10 - CONTROL "Highlight tag attributes",IDC_CHECK_ENABLTAGATTRHILITE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,71,106,140,10 - CONTROL "Highlight comment/php/asp zone",IDC_CHECK_HIGHLITENONEHTMLZONE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,71,120,140,10 + GROUPBOX "Style All Occurrences of Token",IDC_MARKALL_STATIC,61,29,155,45,BS_CENTER + CONTROL "Match case",IDC_CHECK_MARKALLCASESENSITIVE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,67,42,142,10 + CONTROL "Match whole word only",IDC_CHECK_MARKALLWHOLEWORDONLY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,67,57,142,10 + + GROUPBOX "Highlight Matching Tags",IDC_TAGMATCHEDHILITE_STATIC,61,80,155,59,BS_CENTER + CONTROL "Enable",IDC_CHECK_ENABLTAGSMATCHHILITE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,67,93,140,10 + CONTROL "Highlight tag attributes",IDC_CHECK_ENABLTAGATTRHILITE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,67,108,140,10 + CONTROL "Highlight comment/php/asp zone",IDC_CHECK_HIGHLITENONEHTMLZONE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,67,123,140,10 + + GROUPBOX "Smart Highlighting",IDC_SMARTHILITING_STATIC,226,29,172,110,BS_CENTER + CONTROL "Enable",IDC_CHECK_ENABLSMARTHILITE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,232,42,142,10 + CONTROL "Highlight another view",IDC_CHECK_SMARTHILITEANOTHERRVIEW,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,232,57,142,10 + + GROUPBOX "Matching", IDC_SMARTHILITEMATCHING_STATIC,233,72,157,59,BS_CENTER + CONTROL "Match case",IDC_CHECK_SMARTHILITECASESENSITIVE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,239,85,142,10 + CONTROL "Match whole word only",IDC_CHECK_SMARTHILITEWHOLEWORDONLY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,239,100,142,10 + CONTROL "Use Find dialog settings",IDC_CHECK_SMARTHILITEUSEFINDSETTINGS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,239,115,142,10 END @@ -556,16 +559,16 @@ FONT 8, "MS Shell Dlg", 0, 0, 0x1 BEGIN GROUPBOX "Large File Restriction",IDC_GROUPSTATIC_PERFORMANCE_RESTRICTION,73,7,301,189,BS_CENTER PUSHBUTTON "?",IDD_PERFORMANCE_TIP_QUESTION_BUTTON,215,21,16,14 - CONTROL "Enable Large File Restriction (no syntax highlighting)",IDC_CHECK_PERFORMANCE_ENABLE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,78,41,290,10 + CONTROL "Enable Large File Restriction (no syntax highlighting)",IDC_CHECK_PERFORMANCE_ENABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,79,41,290,10 RTEXT "Define Large File Size:",IDC_STATIC_PERFORMANCE_FILESIZE,75,59,125,8 EDITTEXT IDC_EDIT_PERFORMANCE_FILESIZE,201,57,24,14,ES_RIGHT | ES_NUMBER LTEXT "MB (1 - 2046)",IDC_STATIC_PERFORMANCE_MB,228,59,90,8 - CONTROL "Deactivate Word Wrap globally", IDC_CHECK_PERFORMANCE_DEACTIVATEWORDWRAP, "Button", BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP, 127, 80, 200, 10 + CONTROL "Deactivate Word Wrap globally",IDC_CHECK_PERFORMANCE_DEACTIVATEWORDWRAP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,127,80,200,10 CONTROL "Allow Auto-Completion",IDC_CHECK_PERFORMANCE_ALLOWAUTOCOMPLETION,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,127,95,200,10 CONTROL "Allow Smart Highlighting",IDC_CHECK_PERFORMANCE_ALLOWSMARTHILITE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,127,110,200,10 - CONTROL "Allow Brace Match", IDC_CHECK_PERFORMANCE_ALLOWBRACEMATCH, "Button", BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP, 127, 125, 200, 10 - CONTROL "Allow URL Clickable Link", IDC_CHECK_PERFORMANCE_ALLOWCLICKABLELINK, "Button", BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP, 127, 140, 200, 10 - CONTROL "Suppress warning when opening ≥2GB files", IDC_CHECK_PERFORMANCE_SUPPRESS2GBWARNING, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 78, 178, 280, 10 + CONTROL "Allow Brace Match", IDC_CHECK_PERFORMANCE_ALLOWBRACEMATCH,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,127,125,200,10 + CONTROL "Allow URL Clickable Link",IDC_CHECK_PERFORMANCE_ALLOWCLICKABLELINK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,127,140,200,10 + CONTROL "Suppress warning when opening ≥2GB files",IDC_CHECK_PERFORMANCE_SUPPRESS2GBWARNING,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,79,178,280,10 END @@ -587,13 +590,13 @@ BEGIN CONTROL "Peek on document map",IDC_CHECK_ENABLEDOCPEEKONMAP,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,269,71,140,10 // "Enable Notepad++ auto-updater" should be always the 1st item, because it'll be hidden if GUP.exe is absent - CONTROL "Enable Notepad++ auto-updater",IDC_CHECK_AUTOUPDATE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP, 37, 94, 210, 10 - CONTROL "Mute all sounds", IDC_CHECK_MUTE_SOUNDS, "Button", BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP, 37, 109, 190, 10 + CONTROL "Enable Notepad++ auto-updater",IDC_CHECK_AUTOUPDATE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,94,210,10 + CONTROL "Mute all sounds",IDC_CHECK_MUTE_SOUNDS,"Button", BS_AUTOCHECKBOX | WS_TABSTOP,37,109,190,10 CONTROL "Autodetect character encoding",IDC_CHECK_DETECTENCODING,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,124,217,10 CONTROL "Minimize to system tray",IDC_CHECK_MIN2SYSTRAY,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,139,217,10 - CONTROL "Show only filename in title bar",IDC_CHECK_SHORTTITLE,"Button",BS_AUTOCHECKBOX | BS_MULTILINE | WS_TABSTOP,37,154,217,10 + CONTROL "Show only filename in title bar",IDC_CHECK_SHORTTITLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,154,217,10 CONTROL "Use DirectWrite (May improve rendering special characters, need to restart Notepad++)",IDC_CHECK_DIRECTWRITE_ENABLE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,169,377,10 - CONTROL "Enable Save All confirm dialog", IDC_CHECK_SAVEALLCONFIRM, "Button", BS_AUTOCHECKBOX | WS_TABSTOP, 37, 184, 217, 10 + CONTROL "Enable Save All confirm dialog",IDC_CHECK_SAVEALLCONFIRM,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,37,184,217,10 RTEXT "Session file ext.:",IDC_SESSIONFILEEXT_STATIC,270,130,108,8 EDITTEXT IDC_EDIT_SESSIONFILEEXT,380,127,34,14,ES_AUTOHSCROLL diff --git a/PowerEditor/src/localization.cpp b/PowerEditor/src/localization.cpp index 4844c7959..1d65fbba7 100644 --- a/PowerEditor/src/localization.cpp +++ b/PowerEditor/src/localization.cpp @@ -20,6 +20,7 @@ #include "EncodingMapper.h" #include "localization.h" #include "fileBrowser.h" +#include "NppDarkMode.h" using namespace std; @@ -678,6 +679,7 @@ void NativeLangSpeaker::changeConfigLang(HWND hDlg) { const wchar_t *nameW = wmc.char2wchar(name, _nativeLangEncoding); ::SetWindowText(hItem, nameW); + resizeCheckboxRadioBtn(hItem); } } } @@ -741,7 +743,7 @@ void NativeLangSpeaker::changeUserDefineLangPopupDlg(HWND hDlg) { const wchar_t *nameW = wmc.char2wchar(name, _nativeLangEncoding); ::SetWindowText(hItem, nameW); - + resizeCheckboxRadioBtn(hItem); } } } @@ -836,6 +838,7 @@ void NativeLangSpeaker::changeUserDefineLang(UserDefineDialog *userDefineDlg) { const wchar_t *nameW = wmc.char2wchar(name, _nativeLangEncoding); ::SetWindowText(hItem, nameW); + resizeCheckboxRadioBtn(hItem); } } } @@ -1308,6 +1311,7 @@ bool NativeLangSpeaker::changeDlgLang(HWND hDlg, const char *dlgTagName, char *t { const wchar_t *nameW = wmc.char2wchar(name, _nativeLangEncoding); ::SetWindowText(hItem, nameW); + resizeCheckboxRadioBtn(hItem); } } } @@ -1527,3 +1531,33 @@ int NativeLangSpeaker::messageBox(const char *msgBoxTagName, HWND hWnd, const TC } return ::MessageBox(hWnd, msg.c_str(), title.c_str(), msgBoxType); } + +// Default English localization during Notepad++ launch +// is handled in NppDarkMode::subclassButtonControl. +void NativeLangSpeaker::resizeCheckboxRadioBtn(HWND hWnd) +{ + constexpr size_t classNameLen = 32; + wchar_t className[classNameLen]{}; + ::GetClassNameW(hWnd, className, classNameLen); + if (wcscmp(className, WC_BUTTON) == 0) + { + const auto nBtnStyle = ::GetWindowLongPtrW(hWnd, GWL_STYLE); + switch (nBtnStyle & BS_TYPEMASK) + { + case BS_CHECKBOX: + case BS_AUTOCHECKBOX: + case BS_RADIOBUTTON: + case BS_AUTORADIOBUTTON: + { + if ((nBtnStyle & BS_MULTILINE) != BS_MULTILINE) + { + ::SendMessageW(hWnd, NppDarkMode::WM_SETBUTTONIDEALSIZE, 0, 0); + } + break; + } + + default: + break; + } + } +} diff --git a/PowerEditor/src/localization.h b/PowerEditor/src/localization.h index beea5e494..ef393dec6 100644 --- a/PowerEditor/src/localization.h +++ b/PowerEditor/src/localization.h @@ -101,6 +101,8 @@ private: bool _isEditZoneRTL = false; // for Scitilla const char *_fileName = nullptr; std::map _shortcutMenuEntryNameMap; + + static void resizeCheckboxRadioBtn(HWND hWnd); };