diff options
Diffstat (limited to 'alf')
| -rw-r--r-- | alf/alf.cpp | 31 | ||||
| -rw-r--r-- | alf/alf.h | 19 | ||||
| -rw-r--r-- | alf/alfbutton.cpp | 2 | ||||
| -rw-r--r-- | alf/alfcombobox.cpp | 2 | ||||
| -rw-r--r-- | alf/alfedit.cpp | 2 | ||||
| -rw-r--r-- | alf/alflabel.cpp | 2 | ||||
| -rw-r--r-- | alf/alflayout.cpp | 39 | ||||
| -rw-r--r-- | alf/alflayout.h | 3 | ||||
| -rw-r--r-- | alf/alfnotebook.cpp | 14 | ||||
| -rw-r--r-- | alf/alfpanel.cpp | 4 | ||||
| -rw-r--r-- | alf/alfpriv.h | 4 |
11 files changed, 39 insertions, 83 deletions
diff --git a/alf/alf.cpp b/alf/alf.cpp index b4d9052..ad4295d 100644 --- a/alf/alf.cpp +++ b/alf/alf.cpp @@ -43,16 +43,6 @@ ALF_UpdateFonts(HWND win) } void -ALF_ApplyFontsPriv(HWND win, ALFWindowPriv *priv) -{ - ALF_Layout_ApplyFonts(&priv->layout, win, &priv->fonts); - - if (priv->vtbl->applyfonts) { - priv->vtbl->applyfonts(priv->closure, win, &priv->fonts); - } -} - -void ALF_UpdateFontsPriv(HWND win, ALFWindowPriv *priv) { priv->fonts.dpi = ALF_Compat_GetDpiForWindow(win); @@ -81,13 +71,7 @@ ALF_UpdateFontsPriv(HWND win, ALFWindowPriv *priv) } priv->fonts.hMessageFont = CreateFontIndirect(&priv->fonts.lfMessageFont); - ALF_ApplyFontsPriv(win, priv); -} - -void -ALF_ApplyFonts(HWND win) -{ - SendMessage(win, ALF_WM_APPLYFONTS, 0, 0); + SendMessage(win, WM_SETFONT, (WPARAM)priv->fonts.hMessageFont, (LPARAM)1); } void @@ -164,9 +148,16 @@ ALF_DefWindowProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) return 0; } - if (msg == ALF_WM_APPLYFONTS) { - ALF_ApplyFontsPriv(hwnd, priv); - return 0; + if (msg == WM_SETFONT) { + priv->font = (HFONT)wparam; + if (LOWORD(lparam) != 0) + InvalidateRect(hwnd, NULL, TRUE); + + // fallthrough to layout, will propagate font to children + } + + if (msg == WM_GETFONT) { + return (LRESULT)priv->font; } if (msg == ALF_WM_PRETRANSLATEMSG) { @@ -18,7 +18,6 @@ typedef struct { void (*destroy)(void * /*closure*/, HWND /*window*/); BOOL (*close)(void * /*closure*/, HWND /*window*/); void (*postdestroy)(void * /*closure*/); - void (*applyfonts)(void * /*closure*/, HWND /*window*/, const ALFWindowFonts *fonts); LRESULT (*message)(void * /*closure*/, HWND, UINT, WPARAM, LPARAM); LRESULT (*command)(void * /*closure*/, HWND /*window*/, WORD /*notificationcode*/, WORD /*sourceid*/, HWND /*control*/); LRESULT (*notify)(void * /*closure*/, HWND /*window*/, WPARAM /*sourceid*/, NMHDR *); @@ -30,11 +29,7 @@ typedef struct { #define ALF_APPLYSIZE 0x02 #define ALF_HEXPAND 0x04 #define ALF_VEXPAND 0x08 -#define ALF_MESSAGEFONT 0x10 -#define ALF_STATUSFONT 0x20 -#define ALF_ICONTITLEFONT 0x40 -// sends a ALF_WM_APPLYFONTS message to the widget with ALFWindowFonts* lparam -#define ALF_SENDAPPLYFONTS 0x80 +#define ALF_INHERITFONT 0x10 // label style flags #define ALF_LABEL_ALIGN_LEFT 0 @@ -65,8 +60,7 @@ typedef struct { #define ALF_WM_GETLAYOUTPARAMS (ALF_WM__BASE + 13) #define ALF_WM_SETLAYOUTPARAMS (ALF_WM__BASE + 14) #define ALF_WM_GETWIDGETATPOS (ALF_WM__BASE + 15) -#define ALF_WM_APPLYFONTS (ALF_WM__BASE + 16) -#define ALF_WM_PRETRANSLATEMSG (ALF_WM__BASE + 17) +#define ALF_WM_PRETRANSLATEMSG (ALF_WM__BASE + 16) #define ALF_WM_LBL_GETSTYLE (ALF_WM__BASE + 201) #define ALF_WM_LBL_SETSTYLE (ALF_WM__BASE + 202) @@ -173,15 +167,6 @@ ALF_RecalculateLayout(HWND win); void ALF_UpdateFonts(HWND win); -// Applies window fonts to all children (depending on their layout flags). -// also calls the applyfonts() virtual function. -// -// Call this after you have added new child widgets. -// Since widget sizes depend on the assigned font, you should probably -// call ALF_RecalculateLayout() afterwards. -void -ALF_ApplyFonts(HWND win); - void ALF_ResizeWindow(HWND win, int cptWidth, int cptHeight); diff --git a/alf/alfbutton.cpp b/alf/alfbutton.cpp index 0bb0627..582a90c 100644 --- a/alf/alfbutton.cpp +++ b/alf/alfbutton.cpp @@ -508,7 +508,7 @@ ALF_AddButton(HWND win, WORD id, UINT x, UINT y, const TCHAR *text) p.y = y; p.width = 0; p.height = 0; - p.flags = ALF_QUERYSIZE | ALF_MESSAGEFONT; + p.flags = ALF_QUERYSIZE | ALF_INHERITFONT; ALF_AddWidgetEx(win, &p); diff --git a/alf/alfcombobox.cpp b/alf/alfcombobox.cpp index c9da2ed..097e2a4 100644 --- a/alf/alfcombobox.cpp +++ b/alf/alfcombobox.cpp @@ -310,7 +310,7 @@ ALF_InternalAddComboBox(HWND win, WORD id, UINT x, UINT y, DWORD style, const TC p.y = y; p.width = 0; p.height = 0; - p.flags = ALF_QUERYSIZE | ALF_MESSAGEFONT; + p.flags = ALF_QUERYSIZE | ALF_INHERITFONT; ALF_AddWidgetEx(win, &p); diff --git a/alf/alfedit.cpp b/alf/alfedit.cpp index 95150ba..c352a8b 100644 --- a/alf/alfedit.cpp +++ b/alf/alfedit.cpp @@ -83,7 +83,7 @@ ALF_AddEdit(HWND win, WORD id, UINT x, UINT y, const TCHAR *text) p.y = y; p.width = 0; p.height = 0; - p.flags = ALF_QUERYSIZE | ALF_APPLYSIZE | ALF_MESSAGEFONT; + p.flags = ALF_QUERYSIZE | ALF_APPLYSIZE | ALF_INHERITFONT; ALF_AddWidgetEx(win, &p); diff --git a/alf/alflabel.cpp b/alf/alflabel.cpp index 5292a13..fd2cab7 100644 --- a/alf/alflabel.cpp +++ b/alf/alflabel.cpp @@ -232,7 +232,7 @@ ALF_AddLabel(HWND win, WORD id, UINT x, UINT y, const TCHAR *text) p.y = y; p.width = 0; p.height = 0; - p.flags = ALF_QUERYSIZE | ALF_MESSAGEFONT; + p.flags = ALF_QUERYSIZE | ALF_INHERITFONT; ALF_AddWidgetEx(win, &p); diff --git a/alf/alflayout.cpp b/alf/alflayout.cpp index 9c4b8f1..0cc6cdf 100644 --- a/alf/alflayout.cpp +++ b/alf/alflayout.cpp @@ -22,31 +22,15 @@ ALF_Layout_Clear(ALFLayout *layout) layout->nRows = 0; } - static void -ALF_ApplyFontForWidget(ALFWidgetPriv *widget, const ALFWindowFonts *fonts) -{ - if (widget->hwnd) { - if (widget->flags & ALF_MESSAGEFONT) { - SendMessage(widget->hwnd, WM_SETFONT, (WPARAM)fonts->hMessageFont, (LPARAM)NULL); - - // XXX: Invalidating should IMHO be the decision of the control, but at - // least the commctl32 V5 static control doesn't do it. - InvalidateRect(widget->hwnd, NULL, TRUE); - } - if (widget->flags & ALF_SENDAPPLYFONTS) { - SendMessage(widget->hwnd, ALF_WM_APPLYFONTS, 0, (LPARAM)fonts); - } - } -} - -void -ALF_Layout_ApplyFonts(ALFLayout *layout, HWND window, const ALFWindowFonts *fonts) +ALF_Layout_ForwardFont(ALFLayout *layout, HWND window, HFONT font, LPARAM redraw) { (void)window; ALF_FOR_LIST(ALFWidgetPriv, list, &layout->widgets, i) { - ALF_ApplyFontForWidget(i, fonts); + if (i->flags & ALF_INHERITFONT) { + SendMessage(i->hwnd, WM_SETFONT, (WPARAM)font, redraw); + } } } @@ -265,6 +249,10 @@ ALF_Layout_AddWidget(ALFLayout* layout, HWND window, const ALFWidgetLayoutParams if (GetParent(w->hwnd) != window) SetParent(w->hwnd, window); + if (w->flags & ALF_INHERITFONT) { + SendMessage(w->hwnd, WM_SETFONT, (WPARAM)SendMessage(window, WM_GETFONT, 0, 0), 0); + } + ALF_ListInsert(layout->widgets.prev, &w->list); } @@ -340,11 +328,6 @@ ALF_Layout_HandleMessage(ALFLayout *layout, HWND hwnd, UINT msg, WPARAM wparam, return TRUE; } - if (msg == ALF_WM_APPLYFONTS && lparam != 0) { - ALF_Layout_ApplyFonts(layout, hwnd, (const ALFWindowFonts *)lparam); - return TRUE; - } - if (msg == ALF_WM_APPLYLAYOUT) { ALF_Layout_Apply(layout, hwnd); return TRUE; @@ -370,5 +353,11 @@ ALF_Layout_HandleMessage(ALFLayout *layout, HWND hwnd, UINT msg, WPARAM wparam, return TRUE; } + if (msg == WM_SETFONT) { + ALF_Layout_ForwardFont(layout, hwnd, (HFONT)wparam, lparam); + *pRet = 0; + return TRUE; + } + return FALSE; } diff --git a/alf/alflayout.h b/alf/alflayout.h index a9a766c..c279afa 100644 --- a/alf/alflayout.h +++ b/alf/alflayout.h @@ -65,6 +65,3 @@ ALF_Layout_HandleMessage(ALFLayout *layout, HWND window, UINT msg, WPARAM wparam HWND ALF_Layout_WidgetAtPos(ALFLayout *layout, UINT x, UINT y); - -void -ALF_Layout_ApplyFonts(ALFLayout *layout, HWND window, const ALFWindowFonts *fonts); diff --git a/alf/alfnotebook.cpp b/alf/alfnotebook.cpp index 705d314..3b60ba5 100644 --- a/alf/alfnotebook.cpp +++ b/alf/alfnotebook.cpp @@ -103,6 +103,8 @@ ALF_Notebook_InternalAddTab(HWND notebook, HWND tabControl, const TCHAR *title) HWND hwndPanel = ALF_CreatePanelWindow(notebook, (WORD)-1); SetWindowPos(hwndPanel, NULL, r.left, r.top, r.right - r.left, r.bottom - r.top, SWP_HIDEWINDOW|SWP_NOACTIVATE|SWP_NOZORDER|SWP_NOOWNERZORDER); + SendMessage(hwndPanel, WM_SETFONT, (WPARAM)SendMessage(tabControl, WM_GETFONT, 0, 0), 0); + TCITEM tie; ZeroMemory(&tie, sizeof(tie)); @@ -198,14 +200,6 @@ ALF__NotebookWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) ALF_Notebook_FreePriv(priv); SetWindowLongPtr(hwnd, 0, 0); priv = NULL; - } else if (uMsg == ALF_WM_APPLYFONTS) { - int n = ALF_Notebook_InternalTabCount(hwnd, priv->hwndTabCtrl); - for (int i = 0; i < n; ++i) { - HWND p = ALF_Notebook_InternalTabPanel(hwnd, priv->hwndTabCtrl, i); - SendMessage(p, ALF_WM_APPLYFONTS, wParam, lParam); - } - - return TRUE; } else if (uMsg == WM_SETFONT) { SendMessage(priv->hwndTabCtrl, WM_SETFONT, wParam, lParam); @@ -214,6 +208,8 @@ ALF__NotebookWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) HWND p = ALF_Notebook_InternalTabPanel(hwnd, priv->hwndTabCtrl, i); SendMessage(p, WM_SETFONT, wParam, lParam); } + } else if (uMsg == WM_GETFONT) { + return SendMessage(priv->hwndTabCtrl, WM_GETFONT, wParam, lParam); } else if (uMsg == ALF_WM_QUERYSIZE) { int n = ALF_Notebook_InternalTabCount(hwnd, priv->hwndTabCtrl); RECT r = { 0, 0, 0, 0 }; @@ -338,7 +334,7 @@ ALF_AddNotebook(HWND parent, WORD id, UINT x, UINT y) p.y = y; p.width = 0; p.height = 0; - p.flags = ALF_QUERYSIZE | ALF_MESSAGEFONT | ALF_SENDAPPLYFONTS; + p.flags = ALF_QUERYSIZE | ALF_INHERITFONT; ALF_AddWidgetEx(parent, &p); diff --git a/alf/alfpanel.cpp b/alf/alfpanel.cpp index ce640a2..076bd9f 100644 --- a/alf/alfpanel.cpp +++ b/alf/alfpanel.cpp @@ -75,7 +75,7 @@ ALF__PanelWindowProc(HWND window, UINT msg, WPARAM wparam, LPARAM lparam) if (LOWORD(lparam) != 0) InvalidateRect(window, NULL, TRUE); - return 0; + // fallthrough to layout, will propagate font to children } if (msg == WM_GETFONT) { @@ -167,7 +167,7 @@ ALF_AddPanel(HWND parent, WORD id, UINT x, UINT y) p.y = y; p.width = 0; p.height = 0; - p.flags = ALF_QUERYSIZE | ALF_SENDAPPLYFONTS | ALF_MESSAGEFONT; + p.flags = ALF_QUERYSIZE | ALF_INHERITFONT; ALF_AddWidgetEx(parent, &p); diff --git a/alf/alfpriv.h b/alf/alfpriv.h index 4bccebc..a38cd25 100644 --- a/alf/alfpriv.h +++ b/alf/alfpriv.h @@ -25,6 +25,7 @@ typedef struct { ALFLayout layout; WORD defid; HWND hwndFocus; + HFONT font; } ALFWindowPriv; extern TCHAR *_alf_comboClass; @@ -39,9 +40,6 @@ ALF_CentipointsToPxPriv(ALFWindowPriv *priv, int cptValue); void ALF_UpdateFontsPriv(HWND hwnd, ALFWindowPriv *priv); -void -ALF_ApplyFontsPriv(HWND win, ALFWindowPriv *priv); - BOOL ALF_PreTranslateMessagePriv(HWND win, ALFWindowPriv *priv, MSG *message); |
