CtrlLib: Fixed Chameleon color issue, fixed dark mode option when app is started from theide

git-svn-id: svn://ultimatepp.org/upp/trunk@14311 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
cxl 2020-04-15 10:46:02 +00:00
parent b7389a4a8e
commit 8dc013f007
7 changed files with 48 additions and 104 deletions

View file

@ -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;

View file

@ -9,8 +9,6 @@ namespace Upp {
#define IMAGEFILE <CtrlLib/Ctrls.iml>
#include <Draw/iml_source.h>
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());

View file

@ -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);

View file

@ -294,7 +294,7 @@ void ChHostSkin()
SColorInfoText_Write(SColorText());
#endif
ColoredOverride(CtrlsImg::Iml(), CtrlsImg::Iml());
ChBaseSkin();
#if 0 // TODO (?)
{ SColorLight_Write, 2*5 + 0 },

View file

@ -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 <uxtheme.h>
#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
}

View file

@ -5,10 +5,8 @@ namespace Upp {
#define TFILE <CtrlLib/CtrlLib.t>
#include <Core/t.h>
void CtrlSetDefaultSkin(void (*fn1)(), void (*fn2)());
INITIALIZER(CtrlLib) {
CtrlSetDefaultSkin(ChBaseSkin, ChHostSkin);
Ctrl::SetSkin(ChHostSkin);
};
}

View file

@ -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;