Add dpi support to Style Configurator dialog

- reorder controls for consistent tab switch
- make spacing and position more consistent
- use system aware or gdi scaling for Color dialog and Color popup

ref #14959

Close #15029
pull/15042/head
ozone10 2024-04-22 17:51:47 +02:00 committed by Don Ho
parent 2531b4d12c
commit 560f29fc8c
5 changed files with 117 additions and 51 deletions

View File

@ -19,6 +19,8 @@
#include <stdexcept> #include <stdexcept>
#include "ColourPopup.h" #include "ColourPopup.h"
#include "NppDarkMode.h" #include "NppDarkMode.h"
#include "dpiManagerV2.h"
DWORD colourItems[] = { DWORD colourItems[] = {
RGB( 0, 0, 0), RGB( 64, 0, 0), RGB(128, 0, 0), RGB(128, 64, 64), RGB(255, 0, 0), RGB(255, 128, 128), RGB( 0, 0, 0), RGB( 64, 0, 0), RGB(128, 0, 0), RGB(128, 64, 64), RGB(255, 0, 0), RGB(255, 128, 128),
@ -43,6 +45,17 @@ void ColourPopup::create(int dialogID)
display(); display();
} }
void ColourPopup::createForDpi(int dialogID)
{
const DPI_AWARENESS_CONTEXT dpiContextSystem = NppDarkMode::isWindows10() ? DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED : DPI_AWARENESS_CONTEXT_SYSTEM_AWARE;
const auto dpiContext = DPIManagerV2::setThreadDpiAwarenessContext(dpiContextSystem);
create(dialogID);
if (dpiContext != NULL)
{
DPIManagerV2::setThreadDpiAwarenessContext(dpiContext);
}
}
intptr_t CALLBACK ColourPopup::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) intptr_t CALLBACK ColourPopup::dlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{ {
switch (message) switch (message)
@ -228,8 +241,16 @@ intptr_t CALLBACK ColourPopup::run_dlgProc(UINT message, WPARAM wParam, LPARAM l
cc.Flags = CC_FULLOPEN | CC_RGBINIT | CC_ENABLEHOOK; cc.Flags = CC_FULLOPEN | CC_RGBINIT | CC_ENABLEHOOK;
display(false); display(false);
if (ChooseColor(&cc)==TRUE) const DPI_AWARENESS_CONTEXT dpiContextSystem = NppDarkMode::isWindows10() ? DPI_AWARENESS_CONTEXT_UNAWARE_GDISCALED : DPI_AWARENESS_CONTEXT_SYSTEM_AWARE;
const auto dpiContext = DPIManagerV2::setThreadDpiAwarenessContext(dpiContextSystem);
const bool isCreated = ChooseColor(&cc) == TRUE;
if (dpiContext != NULL)
{
DPIManagerV2::setThreadDpiAwarenessContext(dpiContext);
}
if (isCreated)
{ {
::SendMessage(_hParent, WM_PICKUP_COLOR, cc.rgbResult, 0); ::SendMessage(_hParent, WM_PICKUP_COLOR, cc.rgbResult, 0);
} }

View File

@ -37,12 +37,13 @@ public :
} }
void create(int dialogID); void create(int dialogID);
void createForDpi(int dialogID);
void doDialog(POINT p) void doDialog(POINT p)
{ {
if (!isCreated()) if (!isCreated())
create(IDD_COLOUR_POPUP); createForDpi(IDD_COLOUR_POPUP);
::SetWindowPos(_hSelf, HWND_TOP, p.x, p.y, _rc.right - _rc.left, _rc.bottom - _rc.top, SWP_SHOWWINDOW); ::SetWindowPos(_hSelf, HWND_TOP, p.x, p.y, 0, 0, SWP_NOSIZE | SWP_SHOWWINDOW);
} }
virtual void destroy() virtual void destroy()

View File

@ -136,6 +136,7 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
_pFgColour->init(_hInst, _hSelf); _pFgColour->init(_hInst, _hSelf);
_pBgColour->init(_hInst, _hSelf); _pBgColour->init(_hInst, _hSelf);
setDpi();
const int cpDynamicalSize = DPIManagerV2::scale(25); const int cpDynamicalSize = DPIManagerV2::scale(25);
move2CtrlRight(IDC_FG_STATIC, _pFgColour->getHSelf(), cpDynamicalSize, cpDynamicalSize); move2CtrlRight(IDC_FG_STATIC, _pFgColour->getHSelf(), cpDynamicalSize, cpDynamicalSize);
@ -251,14 +252,11 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
case WM_DESTROY: case WM_DESTROY:
{ {
_pFgColour->destroy(); destroy();
_pBgColour->destroy();
delete _pFgColour;
delete _pBgColour;
return TRUE; return TRUE;
} }
case WM_HSCROLL : case WM_HSCROLL:
{ {
if (reinterpret_cast<HWND>(lParam) == ::GetDlgItem(_hSelf, IDC_SC_PERCENTAGE_SLIDER)) if (reinterpret_cast<HWND>(lParam) == ::GetDlgItem(_hSelf, IDC_SC_PERCENTAGE_SLIDER))
{ {
@ -268,7 +266,22 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
return TRUE; return TRUE;
} }
case WM_COMMAND : case WM_DPICHANGED:
{
DPIManagerV2::setDpiWP(wParam);
_goToSettings.destroy();
const int cpDynamicalSize = DPIManagerV2::scale(25);
move2CtrlRight(IDC_FG_STATIC, _pFgColour->getHSelf(), cpDynamicalSize, cpDynamicalSize);
move2CtrlRight(IDC_BG_STATIC, _pBgColour->getHSelf(), cpDynamicalSize, cpDynamicalSize);
setPositionDpi(lParam);
return TRUE;
}
case WM_COMMAND:
{ {
if (HIWORD(wParam) == EN_CHANGE) if (HIWORD(wParam) == EN_CHANGE)
{ {
@ -278,13 +291,16 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
updateUserKeywords(); updateUserKeywords();
notifyDataModified(); notifyDataModified();
apply(); apply();
return TRUE;
} }
else if (editID == IDC_USER_EXT_EDIT) else if (editID == IDC_USER_EXT_EDIT)
{ {
updateExtension(); updateExtension();
notifyDataModified(); notifyDataModified();
apply(false); apply(false);
return TRUE;
} }
return FALSE;
} }
else else
{ {
@ -294,19 +310,19 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
updateFontStyleStatus(BOLD_STATUS); updateFontStyleStatus(BOLD_STATUS);
notifyDataModified(); notifyDataModified();
apply(); apply();
break; return TRUE;
case IDC_ITALIC_CHECK : case IDC_ITALIC_CHECK :
updateFontStyleStatus(ITALIC_STATUS); updateFontStyleStatus(ITALIC_STATUS);
notifyDataModified(); notifyDataModified();
apply(); apply();
break; return TRUE;
case IDC_UNDERLINE_CHECK : case IDC_UNDERLINE_CHECK :
updateFontStyleStatus(UNDERLINE_STATUS); updateFontStyleStatus(UNDERLINE_STATUS);
notifyDataModified(); notifyDataModified();
apply(); apply();
break; return TRUE;
case IDC_GLOBAL_GOTOSETTINGS_LINK : case IDC_GLOBAL_GOTOSETTINGS_LINK :
{ {
@ -315,7 +331,7 @@ intptr_t CALLBACK WordStyleDlg::run_dlgProc(UINT Message, WPARAM wParam, LPARAM
if (pageAndCtrlID.first != -1) if (pageAndCtrlID.first != -1)
::SendMessage(_hParent, NPPM_INTERNAL_LAUNCHPREFERENCES, pageAndCtrlID.first, pageAndCtrlID.second); ::SendMessage(_hParent, NPPM_INTERNAL_LAUNCHPREFERENCES, pageAndCtrlID.first, pageAndCtrlID.second);
} }
break; return TRUE;
case IDCANCEL : case IDCANCEL :
if (_isDirty) if (_isDirty)
@ -1202,6 +1218,25 @@ void WordStyleDlg::doDialog(bool isRTL)
display(); display();
} }
void WordStyleDlg::destroy()
{
_goToSettings.destroy();
if (_pFgColour != nullptr)
{
_pFgColour->destroy();
delete _pFgColour;
_pFgColour = nullptr;
}
if (_pBgColour != nullptr)
{
_pBgColour->destroy();
delete _pBgColour;
_pBgColour = nullptr;
}
}
void WordStyleDlg::prepare2Cancel() void WordStyleDlg::prepare2Cancel()
{ {
_styles2restored = (NppParameters::getInstance()).getLStylerArray(); _styles2restored = (NppParameters::getInstance()).getLStylerArray();

View File

@ -63,6 +63,7 @@ public :
void create(int dialogID, bool isRTL = false, bool msgDestParent = true) override; void create(int dialogID, bool isRTL = false, bool msgDestParent = true) override;
void doDialog(bool isRTL = false); void doDialog(bool isRTL = false);
void destroy() override;
void prepare2Cancel(); void prepare2Cancel();
void redraw(bool forceUpdate = false) const override; void redraw(bool forceUpdate = false) const override;
void restoreGlobalOverrideValues(); void restoreGlobalOverrideValues();

View File

@ -22,53 +22,61 @@
#define IDC_STATIC -1 #define IDC_STATIC -1
#endif #endif
IDD_STYLER_DLG DIALOGEX 36, 44, 500, 246 IDD_STYLER_DLG DIALOGEX 0, 0, 500, 246
STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU STYLE DS_SETFONT | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
EXSTYLE WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE EXSTYLE WS_EX_DLGMODALFRAME | WS_EX_WINDOWEDGE
CAPTION "Style Configurator" CAPTION "Style Configurator"
FONT 8, "MS Shell Dlg", 0, 0, 0x0 FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN BEGIN
LTEXT "Select theme : ",IDC_SWITCH2THEME_STATIC,6,9,83,8,0,WS_EX_RIGHT RTEXT "Select theme:",IDC_SWITCH2THEME_STATIC,6,9,83,8
COMBOBOX IDC_SWITCH2THEME_COMBO,95,7,104,78,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_SWITCH2THEME_COMBO,95,7,104,78,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP
LTEXT "Foreground colour",IDC_FG_STATIC,203,72,59,8,0,WS_EX_RIGHT
LTEXT "Background colour",IDC_BG_STATIC,203,99,59,8,0,WS_EX_RIGHT GROUPBOX "",IDC_STATIC,7,24,166,212
LTEXT "Language:",IDC_LANGDESC_STATIC,20,35,61,8
LISTBOX IDC_LANGUAGES_LIST,17,46,59,146,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
LTEXT "Style:",IDC_STYLEDESC_STATIC,89,35,68,8
LISTBOX IDC_STYLES_LIST,86,46,77,146,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP
LTEXT "Default ext.:",IDC_DEF_EXT_STATIC,20,203,61,8
EDITTEXT IDC_DEF_EXT_EDIT,17,214,59,12,ES_AUTOHSCROLL | ES_READONLY
LTEXT "+",IDC_PLUSSYMBOL2_STATIC,82,216,8,8
LTEXT "User ext.:",IDC_USER_EXT_STATIC,96,203,71,8
EDITTEXT IDC_USER_EXT_EDIT,93,214,70,12,ES_AUTOHSCROLL
GROUPBOX "",IDC_STATIC,181,24,312,184
LTEXT " ",IDC_STYLEDESCRIPTION_STATIC,190,30,295,22
GROUPBOX "Colour Style",IDC_COLOURGROUP_STATIC,191,52,111,77,BS_CENTER
RTEXT "Foreground colour",IDC_FG_STATIC,203,72,59,8
RTEXT "Background colour",IDC_BG_STATIC,203,99,59,8
GROUPBOX "Font Style",IDC_FONTGROUP_STATIC,312,52,171,77,BS_CENTER
RTEXT "Font name:",IDC_FONTNAME_STATIC,315,71,52,8
COMBOBOX IDC_FONT_COMBO,371,68,104,78,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_FONT_COMBO,371,68,104,78,CBS_DROPDOWNLIST | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP
RTEXT "Font size:",IDC_FONTSIZE_STATIC,388,97,51,8
COMBOBOX IDC_FONTSIZE_COMBO,442,95,33,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP COMBOBOX IDC_FONTSIZE_COMBO,442,95,33,82,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP
CONTROL "Bold",IDC_BOLD_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,327,88,63,10 CONTROL "Bold",IDC_BOLD_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,327,88,63,10
CONTROL "Italic",IDC_ITALIC_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,327,100,62,10 CONTROL "Italic",IDC_ITALIC_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,327,101,62,10
GROUPBOX "Font Style",IDC_FONTGROUP_STATIC,311,52,169,77,BS_CENTER CONTROL "Underline",IDC_UNDERLINE_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,327,114,80,10
GROUPBOX "Colour Style",IDC_COLOURGROUP_STATIC,191,52,111,77,BS_CENTER
LTEXT "Font name :",IDC_FONTNAME_STATIC,315,71,52,8,0,WS_EX_RIGHT LTEXT "Default keywords",IDC_DEF_KEYWORDS_STATIC,194,135,122,8
LTEXT "Font size :",IDC_FONTSIZE_STATIC,388,97,51,8,0,WS_EX_RIGHT EDITTEXT IDC_DEF_KEYWORDS_EDIT,191,146,136,52,ES_MULTILINE | ES_READONLY | WS_VSCROLL
LTEXT "Style :",IDC_STYLEDESC_STATIC,87,34,68,8 LTEXT "+",IDC_PLUSSYMBOL_STATIC,334,168,8,8
LTEXT " ",IDC_STYLEDESCRIPTION_STATIC,190,30,295,22 LTEXT "User-defined keywords",IDC_USER_KEYWORDS_STATIC,350,135,126,8
EDITTEXT IDC_DEF_EXT_EDIT,17,215,61,14,ES_AUTOHSCROLL | ES_READONLY EDITTEXT IDC_USER_KEYWORDS_EDIT,347,146,136,52,ES_MULTILINE | WS_VSCROLL
LTEXT "Default ext. : ",IDC_DEF_EXT_STATIC,20,203,61,8
EDITTEXT IDC_USER_EXT_EDIT,93,215,71,14,ES_AUTOHSCROLL CONTROL "Enable global foreground colour",IDC_GLOBAL_FG_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,191,134,132,10
LTEXT "User ext. :",IDC_USER_EXT_STATIC,95,204,71,8 CONTROL "Enable global background colour",IDC_GLOBAL_BG_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,191,149,131,10
CONTROL "Underline",IDC_UNDERLINE_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,327,112,80,10
EDITTEXT IDC_DEF_KEYWORDS_EDIT,191,151,136,43,ES_MULTILINE | ES_READONLY | WS_VSCROLL
EDITTEXT IDC_USER_KEYWORDS_EDIT,347,150,134,43,ES_MULTILINE | WS_VSCROLL
LTEXT "Default keywords",IDC_DEF_KEYWORDS_STATIC,193,141,122,8
LTEXT "User-defined keywords",IDC_USER_KEYWORDS_STATIC,349,140,126,8
LTEXT "+",IDC_PLUSSYMBOL_STATIC,335,166,8,8
PUSHBUTTON "Cancel",IDCANCEL,332,222,57,14
PUSHBUTTON "Save && Close",IDC_SAVECLOSE_BUTTON,255,222,69,14
CONTROL "",IDC_SC_PERCENTAGE_SLIDER,"msctls_trackbar32",TBS_BOTH | TBS_NOTICKS | TBS_TRANSPARENTBKGND | NOT WS_VISIBLE | WS_TABSTOP,441,235,53,10
CONTROL "Transparency",IDC_SC_TRANSPARENT_CHECK,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_TABSTOP,431,221,63,10
LISTBOX IDC_LANGUAGES_LIST,17,46,59,146,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_TABSTOP
LISTBOX IDC_STYLES_LIST,87,46,76,146,LBS_NOINTEGRALHEIGHT | WS_VSCROLL | WS_HSCROLL | WS_TABSTOP
GROUPBOX "",IDC_STATIC,7,24,166,212
LTEXT "Language :",IDC_LANGDESC_STATIC,19,34,61,8
GROUPBOX "",IDC_STATIC,181,24,310,184
LTEXT "+",IDC_PLUSSYMBOL2_STATIC,83,217,8,8
CONTROL "Enable global foreground colour",IDC_GLOBAL_FG_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,191,138,132,10
CONTROL "Enable global background colour",IDC_GLOBAL_BG_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,191,153,131,10
CONTROL "Enable global font",IDC_GLOBAL_FONT_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,327,134,153,10 CONTROL "Enable global font",IDC_GLOBAL_FONT_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,327,134,153,10
CONTROL "Enable global font size",IDC_GLOBAL_FONTSIZE_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,327,149,135,10 CONTROL "Enable global font size",IDC_GLOBAL_FONTSIZE_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,327,149,135,10
CONTROL "Enable global bold font style",IDC_GLOBAL_BOLD_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,328,164,135,10 CONTROL "Enable global bold font style",IDC_GLOBAL_BOLD_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,327,164,135,10
CONTROL "Enable global italic font style",IDC_GLOBAL_ITALIC_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,328,179,135,10 CONTROL "Enable global italic font style",IDC_GLOBAL_ITALIC_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,327,179,135,10
CONTROL "Enable global underline font style",IDC_GLOBAL_UNDERLINE_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,328,194,135,10 CONTROL "Enable global underline font style",IDC_GLOBAL_UNDERLINE_CHECK,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,327,194,135,10
PUSHBUTTON "Save && Close",IDC_SAVECLOSE_BUTTON,264,222,69,14
PUSHBUTTON "Cancel",IDCANCEL,337,222,50,14
LTEXT "Go to settings",IDC_GLOBAL_GOTOSETTINGS_LINK,210,153,131,10,WS_TABSTOP LTEXT "Go to settings",IDC_GLOBAL_GOTOSETTINGS_LINK,210,153,131,10,WS_TABSTOP
CONTROL "Transparency",IDC_SC_TRANSPARENT_CHECK,"Button",BS_AUTOCHECKBOX | NOT WS_VISIBLE | WS_TABSTOP,431,221,63,10
CONTROL "",IDC_SC_PERCENTAGE_SLIDER,"msctls_trackbar32",TBS_BOTH | TBS_NOTICKS | TBS_TRANSPARENTBKGND | NOT WS_VISIBLE | WS_TABSTOP,441,235,53,10
END END