From e03d9ae2bd749f75daafa4c302deb4a85808ffb6 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 10 Apr 2015 17:53:59 -0400 Subject: [PATCH] Changed the Windows new control system to automatically assign the standard control font if a flag is set in the creation parameters structure. --- button_windows.c | 5 +---- checkbox_windows.c | 5 +---- entry_windows.c | 8 ++------ newcontrol_windows.c | 5 ++++- ui_windows.h | 4 +++- 5 files changed, 11 insertions(+), 16 deletions(-) diff --git a/button_windows.c b/button_windows.c index 149c52b1..0bd30210 100644 --- a/button_windows.c +++ b/button_windows.c @@ -66,7 +66,6 @@ uiControl *uiNewButton(const char *text) struct button *b; uiWindowsNewControlParams p; WCHAR *wtext; - HWND hwnd; p.dwExStyle = 0; p.lpClassName = L"button"; @@ -74,6 +73,7 @@ uiControl *uiNewButton(const char *text) p.lpWindowName = wtext; p.dwStyle = BS_PUSHBUTTON | WS_TABSTOP; p.hInstance = hInstance; + p.useStandardControlFont = TRUE; p.onWM_COMMAND = onWM_COMMAND; p.onWM_NOTIFY = onWM_NOTIFY; p.onWM_DESTROY = onWM_DESTROY; @@ -82,9 +82,6 @@ uiControl *uiNewButton(const char *text) c->preferredSize = preferredSize; - hwnd = (HWND) uiControlHandle(c); - SendMessageW(hwnd, WM_SETFONT, (WPARAM) hMessageFont, (LPARAM) TRUE); - b = uiNew(struct button); b->onClicked = defaultOnClicked; c->data = b; diff --git a/checkbox_windows.c b/checkbox_windows.c index 4f903ef9..28433d2f 100644 --- a/checkbox_windows.c +++ b/checkbox_windows.c @@ -61,7 +61,6 @@ uiControl *uiNewCheckbox(const char *text) struct checkbox *cc; uiWindowsNewControlParams p; WCHAR *wtext; - HWND hwnd; p.dwExStyle = 0; p.lpClassName = L"button"; @@ -69,6 +68,7 @@ uiControl *uiNewCheckbox(const char *text) p.lpWindowName = wtext; p.dwStyle = BS_CHECKBOX | WS_TABSTOP; p.hInstance = hInstance; + p.useStandardControlFont = TRUE; p.onWM_COMMAND = onWM_COMMAND; p.onWM_NOTIFY = onWM_NOTIFY; p.onWM_DESTROY = onWM_DESTROY; @@ -77,9 +77,6 @@ uiControl *uiNewCheckbox(const char *text) c->preferredSize = preferredSize; - hwnd = (HWND) uiControlHandle(c); - SendMessageW(hwnd, WM_SETFONT, (WPARAM) hMessageFont, (LPARAM) TRUE); - cc = uiNew(struct checkbox); cc->onToggled = defaultOnToggled; c->data = cc; diff --git a/entry_windows.c b/entry_windows.c index 41614c5d..2297c28b 100644 --- a/entry_windows.c +++ b/entry_windows.c @@ -36,14 +36,13 @@ uiControl *uiNewEntry(void) uiControl *c; struct entry *e; uiWindowsNewControlParams p; - HWND hwnd; p.dwExStyle = WS_EX_CLIENTEDGE; p.lpClassName = L"edit"; p.lpWindowName = L""; - // TODO ES_NOHIDESEL? - p.dwStyle = ES_AUTOHSCROLL | ES_LEFT | WS_TABSTOP; + p.dwStyle = ES_AUTOHSCROLL | ES_LEFT | ES_NOHIDESEL | WS_TABSTOP; p.hInstance = hInstance; + p.useStandardControlFont = TRUE; p.onWM_COMMAND = onWM_COMMAND; p.onWM_NOTIFY = onWM_NOTIFY; p.onWM_DESTROY = onWM_DESTROY; @@ -51,9 +50,6 @@ uiControl *uiNewEntry(void) c->preferredSize = preferredSize; - hwnd = (HWND) uiControlHandle(c); - SendMessageW(hwnd, WM_SETFONT, (WPARAM) hMessageFont, (LPARAM) TRUE); - e = uiNew(struct entry); c->data = e; diff --git a/newcontrol_windows.c b/newcontrol_windows.c index 0122db73..5ca9ad19 100644 --- a/newcontrol_windows.c +++ b/newcontrol_windows.c @@ -105,16 +105,19 @@ uiControl *uiWindowsNewControl(uiWindowsNewControlParams *p) s->onWM_DESTROY = p->onWM_DESTROY; c = uiNew(uiControl); - c->internal = s; c->destroy = singleDestroy; c->handle = singleHandle; c->setParent = singleSetParent; c->removeParent = singleRemoveParent; c->resize = singleResize; + if (p->useStandardControlFont) + SendMessageW(s->hwnd, WM_SETFONT, (WPARAM) hMessageFont, (LPARAM) TRUE); + if ((*fv_SetWindowSubclass)(s->hwnd, singleSubclassProc, 0, (DWORD_PTR) c) == FALSE) logLastError("error subclassing Windows control in uiWindowsNewControl()"); + c->internal = s; return c; } diff --git a/ui_windows.h b/ui_windows.h index cfea2877..0fba5931 100644 --- a/ui_windows.h +++ b/ui_windows.h @@ -18,6 +18,9 @@ struct uiWindowsNewControlParams { DWORD dwStyle; // WS_CHILD and WS_VISIBLE are automatically applied. HINSTANCE hInstance; + // Set this to non-FALSE to use the standard control font used by other ui controls. + BOOL useStandardControlFont; + // These are called when the control sends a WM_COMMAND or WM_NOTIFY (respectively) to its parent. // ui redirects the message back and calls these functions. // Store the result in *lResult and return any non-FALSE value (such as TRUE) to return the given result; return FALSE to pass the notification up to your window procedure. @@ -42,7 +45,6 @@ struct uiSizingSys { #define uiDlgUnitsToY(dlg, baseY) MulDiv((dlg), baseY, 8) // and use this if you need the text of the window width -// TODO really export? extern intmax_t uiWindowsWindowTextWidth(HWND hwnd); // these functions get and set the window text for such a uiControl