This commit is contained in:
Mirek Fidler 2024-11-12 21:38:36 +01:00
parent fdc39acfcd
commit a388cf9d20
7 changed files with 75 additions and 10 deletions

View file

@ -23,6 +23,7 @@ class UWord : public TopWindow {
public:
virtual void DragAndDrop(Point, PasteClip& d);
virtual void FrameDragAndDrop(Point, PasteClip& d);
virtual void Skin();
protected:
RichEdit editor;
@ -240,6 +241,11 @@ void UWord::SetBar()
toolbar.Set(THISBACK(MainBar));
}
void UWord::Skin()
{
SetBar();
}
UWord::UWord()
{
#ifdef PLATFORM_COCOA

View file

@ -94,9 +94,39 @@ double ContrastRatio(Color c1, Color c2) {
return (max(rl1, rl2) + 0.05) / (min(rl1, rl2) + 0.05);
}
static std::atomic<int> s_logical_color_ii;
static Color s_logical_color[1024];
static Color (*s_logical_color_fn[1024])();
LogicalColor::LogicalColor(Color (*fn)())
{
int ii = s_logical_color_ii++;
ASSERT(ii < 1024);
ii = min(ii, 1023);
s_logical_color_fn[ii] = fn;
s_logical_color[ii] = (*fn)();
SetSpecial(ii + LOGICAL_COLOR);
}
void LogicalColor::Refresh()
{
int n = min((int)s_logical_color_ii, 1024);
for(int i = 0; i < n; i++)
s_logical_color[i] = (*s_logical_color_fn[i])();
}
dword Color::Get() const
{
if(IsNullInstance()) return 0;
int ii = GetSpecial();
if(ii >= 0) {
if(ii >= LOGICAL_COLOR) {
ii -= LOGICAL_COLOR;
if(ii < 1024)
return s_logical_color[ii];
}
return 0;
}
dword c = color;
return c & 0xffffff;
}

View file

@ -42,7 +42,10 @@ class Color : public ValueType<Color, COLOR_V, Moveable<Color> > {
protected:
dword color;
dword Get() const;
dword Get() const;
void SetSpecial(int n) { color = 0x80000000 | n; }
enum { LOGICAL_COLOR = 0x40000000 };
public:
dword GetRaw() const { return color; }
@ -76,7 +79,7 @@ public:
Color(Color (*fn)()) { color = (*fn)().color; }
static Color FromRaw(dword co) { Color c; c.color = co; return c; }
static Color Special(int n) { Color c; c.color = 0x80000000 | n; return c; }
static Color Special(int n) { Color c; c.SetSpecial(n); return c; }
int GetSpecial() const { return color & 0x80000000 ? color & 0x7fffffff : -1; }
@ -91,6 +94,12 @@ private:
Color(int);
};
struct LogicalColor : Color { // this is supposed to be static / global
LogicalColor(Color (*fn)());
static void Refresh();
};
RGBA operator*(int alpha, Color c);
inline Color StraightColor(RGBA rgba) { return Color(rgba.r, rgba.g, rgba.b); }

View file

@ -957,11 +957,25 @@ void Ctrl::ReSkin()
Vector<Ctrl *> ctrl = GetTopCtrls();
for(int i = 0; i < ctrl.GetCount(); i++) {
ctrl[i]->RefreshLayoutDeep();
ctrl[i]->DoSkin();
ctrl[i]->RefreshFrame();
}
lock--;
}
void Ctrl::PostReSkin()
{ // use timer so that it is done just once if there are multiple windows
static TimeCallback tm;
tm.KillPost([=] { ReSkin(); });
}
void Ctrl::DoSkin()
{
for(Ctrl& q : *this)
q.DoSkin();
Skin();
}
CH_INT(GUI_GlobalStyle, GUISTYLE_CLASSIC);
CH_INT(GUI_DragFullWindow, 1);
CH_INT(GUI_PopUpEffect, GUIEFFECT_SLIDE);

View file

@ -1057,6 +1057,8 @@ public:
virtual String GetDesc() const;
virtual void SetMinSize(Size sz) {}
virtual void Skin() {}
Event<> WhenAction;
@ -1424,6 +1426,8 @@ public:
static void GlobalBackBuffer(bool b = true);
static void ReSkin();
static void PostReSkin();
void DoSkin();
String Name() const;
static String Name(Ctrl *ctrl);

View file

@ -593,9 +593,6 @@ LRESULT Ctrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
case WM_ACTIVATE:
LLOG("WM_ACTIVATE " << Name() << ", wParam = " << (int)wParam << ", focusCtrlWnd = " << UPP::Name(focusCtrlWnd) << ", raw = " << (void *)::GetFocus());
ignorekeyup = true;
case 0x031A: // WM_THEMECHANGED
XpClear();
break;
case WM_SETFOCUS:
LLOG("WM_SETFOCUS " << Name() << ", focusCtrlWnd = " << UPP::Name(focusCtrlWnd) << ", raw = " << (void *)::GetFocus());
if(this != focusCtrlWnd || focusCtrl && focusCtrlWnd != focusCtrl->GetTopCtrl()) { // second condition fixes popup issue when clicking dialog parent
@ -664,13 +661,10 @@ LRESULT Ctrl::WindowProc(UINT message, WPARAM wParam, LPARAM lParam) {
}
return 0L;
#endif
/* case WM_SETTINGCHANGE:
case WM_SETTINGCHANGE:
case 0x031A: // WM_THEMECHANGED
ReSkin();
RefreshLayoutDeep();
RefreshFrame();
PostReSkin();
break;
*/
/*
case WM_IME_COMPOSITION:
HIMC himc = ImmGetContext(hwnd);

View file

@ -2513,6 +2513,14 @@ be statically overloaded to receive minimal size of layout.&]
[s7;i1120;a17; [%-*C@3 sz]-|Minimal size of layout.&]
[s3;%- &]
[s4;%- &]
[s5;:Upp`:`:Ctrl`:`:Skin`(`):%- [@(0.0.255) void] [* Skin]()&]
[s2; Called when the application skin (e.g. widget appearance, system
colors or dark / light theme switch) changes. It is called in
children first order. Application should use this to adjust colors,
which might actually include resetting some widgets and data
content.&]
[s3;%- &]
[s4;%- &]
[s5;:Ctrl`:`:Csizeinit`(`):%- [@(0.0.255) static] [@(0.0.255) void]_[* Csizeinit]()&]
[s2;b17;a17; Sets zoom factor used to scale layouts (to scale zoomed
positioning methods like LeftPosZ). Horizontal distances are