diff --git a/uppsrc/CtrlCore/Ctrl.cpp b/uppsrc/CtrlCore/Ctrl.cpp index 639c2a8a7..fd4634f68 100644 --- a/uppsrc/CtrlCore/Ctrl.cpp +++ b/uppsrc/CtrlCore/Ctrl.cpp @@ -864,7 +864,6 @@ bool Ctrl::IsDarkThemeEnabled() return ApplicationDarkThemeEnabled; } - Font StdFontZ(int height) { return FontZ(Font::STDFONT, height); } Font SansSerifZ(int height) { return FontZ(Font::SANSSERIF, height); } Font SerifZ(int height) { return FontZ(Font::SERIF, height); } @@ -973,17 +972,8 @@ INITBLOCK { whenSetStdFont = &Ctrl::ReSkin; } -void (*s_chdefault)(); - void (*Ctrl::skin)(); -void CtrlSetDefaultSkin(void (*fn1)(), void (*fn2)()) -{ - GuiLock __; - s_chdefault = fn1; - Ctrl::skin = fn2; -} - void Ctrl::SetSkin(void (*_skin)()) { GuiLock __; @@ -999,9 +989,8 @@ void Ctrl::ReSkin() return; lock++; ChReset(); + Iml::ResetAll(); Csize.cx = Dsize.cx = IsNoLayoutZoom; - if(s_chdefault) - (*s_chdefault)(); if(skin) (*skin)(); Csize.cx = Dsize.cx = IsNoLayoutZoom; diff --git a/uppsrc/CtrlLib/Ch.cpp b/uppsrc/CtrlLib/Ch.cpp index 66eca8705..44cb00ee4 100644 --- a/uppsrc/CtrlLib/Ch.cpp +++ b/uppsrc/CtrlLib/Ch.cpp @@ -9,8 +9,6 @@ namespace Upp { #define IMAGEFILE #include -void ChSysInit(); - Color AdjustColor(Color c, int adj) { return Color(clamp(c.GetR() + adj, 0, 255), @@ -96,7 +94,8 @@ void ChClassicSkin() { LLOG("ChInitWinClassic"); - ChSysInit(); + ChBaseSkin(); + GUI_GlobalStyle_Write(GUISTYLE_CLASSIC); GUI_PopUpEffect_Write(Ctrl::IsCompositedGui() ? GUIEFFECT_NONE : GUIEFFECT_SLIDE); @@ -227,17 +226,6 @@ void ChClassicSkin() MakeDialogIcons(); } -#ifdef PLATFORM_X11 - -void ChSysInit() -{ - CtrlImg::Reset(); - CtrlsImg::Reset(); - ChReset(); -} - -#endif - void FillImage(Painter& p, const Rectf& r, const Image& m) { Xform2D xform = Xform2D::Translation(r.left, r.top); @@ -589,7 +577,6 @@ void ChSynthetic(Image *button100x100, Color *text, bool macos) void ChBaseSkin() { - ChSysInit(); GUI_GlobalStyle_Write(GUISTYLE_XP); GUI_PopUpEffect_Write(Ctrl::IsCompositedGui() ? GUIEFFECT_NONE : GUIEFFECT_SLIDE); ColoredOverride(CtrlsImg::Iml(), CtrlsImg::Iml()); diff --git a/uppsrc/CtrlLib/ChCoco.cpp b/uppsrc/CtrlLib/ChCoco.cpp index c95ec2535..9696a284e 100644 --- a/uppsrc/CtrlLib/ChCoco.cpp +++ b/uppsrc/CtrlLib/ChCoco.cpp @@ -86,7 +86,7 @@ void ChHostSkin() SColorText_Write(CocoColor(COCO_TEXT)); SColorDisabled_Write(CocoColor(COCO_DISABLED)); - ColoredOverride(CtrlsImg::Iml(), CtrlsImg::Iml()); + ChBaseSkin(); SOImages(CtrlsImg::I_S0, COCO_RADIOBUTTON, 0); SOImages(CtrlsImg::I_S1, COCO_RADIOBUTTON, 1); diff --git a/uppsrc/CtrlLib/ChGtk3.cpp b/uppsrc/CtrlLib/ChGtk3.cpp index cb22ef7a4..7a1bc5c3e 100644 --- a/uppsrc/CtrlLib/ChGtk3.cpp +++ b/uppsrc/CtrlLib/ChGtk3.cpp @@ -294,7 +294,7 @@ void ChHostSkin() SColorInfoText_Write(SColorText()); #endif - ColoredOverride(CtrlsImg::Iml(), CtrlsImg::Iml()); + ChBaseSkin(); #if 0 // TODO (?) { SColorLight_Write, 2*5 + 0 }, diff --git a/uppsrc/CtrlLib/ChWin32.cpp b/uppsrc/CtrlLib/ChWin32.cpp index 181fe265d..8592f5ed2 100644 --- a/uppsrc/CtrlLib/ChWin32.cpp +++ b/uppsrc/CtrlLib/ChWin32.cpp @@ -1,32 +1,9 @@ #include "CtrlLib.h" -namespace Upp { - -#define LLOG(x) // RLOG(x) -#define LTIMING(x) // RTIMING(x) - -void ChSysInit(); - #ifdef GUI_WIN -#ifdef PLATFORM_WINCE - -void ChSysInit() -{ - CtrlImg::Reset(); - CtrlsImg::Reset(); - ChReset(); - GUI_GlobalStyle_Write(GUISTYLE_CLASSIC); -} - -void ChHostSkin() -{ - ChClassicSkin(); -} - -#else - -} +#define LLOG(x) // RLOG(x) +#define LTIMING(x) // RTIMING(x) #include #if defined(_MSC_VER) && _MSC_VER > 1400 // Visual C > 2005 @@ -344,8 +321,8 @@ struct sysColor { }; static sysColor sSysColor[] = { - { SColorFace_Write, COLOR_3DFACE }, { SColorPaper_Write, COLOR_WINDOW }, + { SColorFace_Write, COLOR_3DFACE }, { SColorText_Write, COLOR_WINDOWTEXT }, { SColorHighlight_Write, COLOR_HIGHLIGHT }, { SColorHighlightText_Write, COLOR_HIGHLIGHTTEXT }, @@ -373,13 +350,51 @@ void ToImageIfDark(Value& v) } } +bool IsSystemThemeDark() +{ + String s = GetWinRegString("AppsUseLightTheme", "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", HKEY_CURRENT_USER); + bool b = s.GetCount() && *s == 0; + return GetEnv("UPP_DARKMODE__") == "1" ? !b : b; +} + void ChHostSkin() { + if(Ctrl::IsUHDEnabled()) { + HRESULT (STDAPICALLTYPE *SetProcessDpiAwareness)(int); + DllFn(SetProcessDpiAwareness, "Shcore.dll", "SetProcessDpiAwareness"); + if(SetProcessDpiAwareness) + SetProcessDpiAwareness(1); + else { + BOOL (STDAPICALLTYPE * SetProcessDPIAware)(void); + DllFn(SetProcessDPIAware, "User32.dll", "SetProcessDPIAware"); + if(SetProcessDPIAware) + (*SetProcessDPIAware)(); + } + } + + sEmulateDarkTheme = Ctrl::IsDarkThemeEnabled() && IsSystemThemeDark() && !IsDark(Color::FromCR(GetSysColor(COLOR_WINDOW))); + + NONCLIENTMETRICS ncm; +#if (WINVER >= 0x0600 && !defined(__MINGW32_VERSION)) + ncm.cbSize = sizeof(ncm) - sizeof(ncm.iPaddedBorderWidth); // WinXP does not like it... +#else + ncm.cbSize = sizeof(ncm); +#endif + ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0); + String name = FromSystemCharset(ncm.lfMenuFont.lfFaceName); + int height = abs((int)ncm.lfMenuFont.lfHeight); + + int q = Font::FindFaceNameIndex(name); + if(height > 0 && height < 200) // sanity.. + Font::SetDefaultFont(Font(q >= 0 ? q : Font::SANSSERIF, height)); + XpClear(); for(sysColor *s = sSysColor; s < sSysColor + __countof(sSysColor); s++) // this also resets all imls via SColorPaper_Write!!! (*s->set)(sAdjust(Color::FromCR(GetSysColor(s->syscolor)))); + ChBaseSkin(); + GUI_GlobalStyle_Write(IsWinXP() && !ScreenInPaletteMode() && IsSysFlag(0x1022 /*SPI_GETFLATMENU*/) ? GUISTYLE_XP : GUISTYLE_CLASSIC); #ifndef PLATFORM_WINCE @@ -678,50 +693,6 @@ void ChHostSkin() ChClassicSkin(); } -bool IsSystemThemeDark() -{ - String s = GetWinRegString("AppsUseLightTheme", "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", HKEY_CURRENT_USER); - return s.GetCount() && *s == 0; -} - -void ChSysInit() -{ - if(Ctrl::IsUHDEnabled()) { - HRESULT (STDAPICALLTYPE *SetProcessDpiAwareness)(int); - DllFn(SetProcessDpiAwareness, "Shcore.dll", "SetProcessDpiAwareness"); - if(SetProcessDpiAwareness) - SetProcessDpiAwareness(1); - else { - BOOL (STDAPICALLTYPE * SetProcessDPIAware)(void); - DllFn(SetProcessDPIAware, "User32.dll", "SetProcessDPIAware"); - if(SetProcessDPIAware) - (*SetProcessDPIAware)(); - } - } - - sEmulateDarkTheme = Ctrl::IsDarkThemeEnabled() && IsSystemThemeDark() && !IsDark(Color::FromCR(GetSysColor(COLOR_WINDOW))); - - CtrlImg::Reset(); - CtrlsImg::Reset(); - ChReset(); - - NONCLIENTMETRICS ncm; -#if (WINVER >= 0x0600 && !defined(__MINGW32_VERSION)) - ncm.cbSize = sizeof(ncm) - sizeof(ncm.iPaddedBorderWidth); // WinXP does not like it... -#else - ncm.cbSize = sizeof(ncm); -#endif - ::SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0); - String name = FromSystemCharset(ncm.lfMenuFont.lfFaceName); - int height = abs((int)ncm.lfMenuFont.lfHeight); - - int q = Font::FindFaceNameIndex(name); - if(height > 0 && height < 200) // sanity.. - Font::SetDefaultFont(Font(q >= 0 ? q : Font::SANSSERIF, height)); } #endif - -#endif - -} diff --git a/uppsrc/CtrlLib/CtrlLibInit.cpp b/uppsrc/CtrlLib/CtrlLibInit.cpp index 02e47dd5c..9c3d2e126 100644 --- a/uppsrc/CtrlLib/CtrlLibInit.cpp +++ b/uppsrc/CtrlLib/CtrlLibInit.cpp @@ -5,10 +5,8 @@ namespace Upp { #define TFILE #include -void CtrlSetDefaultSkin(void (*fn1)(), void (*fn2)()); - INITIALIZER(CtrlLib) { - CtrlSetDefaultSkin(ChBaseSkin, ChHostSkin); + Ctrl::SetSkin(ChHostSkin); }; } diff --git a/uppsrc/GridCtrl/GridDisplay.cpp b/uppsrc/GridCtrl/GridDisplay.cpp index 89f7c1e3c..d81e3584f 100644 --- a/uppsrc/GridCtrl/GridDisplay.cpp +++ b/uppsrc/GridCtrl/GridDisplay.cpp @@ -198,7 +198,7 @@ void GridDisplay::PaintFixed(Draw &w, bool firstx, bool firsty, int x, int y, in if(moved) DrawBorder(w, x, y, cx, cy, BlackBorder); - Color col = style & GD::READONLY ? Gray : Black; + Color col = style & GD::READONLY ? SGray() : SBlack(); if(sortmode > 0) { @@ -220,7 +220,6 @@ void GridDisplay::PaintFixed(Draw &w, bool firstx, bool firsty, int x, int y, in bool asc = sortmode == 1; if(reverse_sort_icon) asc = !asc; - w.DrawImage(xf, yf, asc ? GridImg::SortAsc() : GridImg::SortDsc(), col); tx += 3;