From 4edef818b9d7649aee9c37ed50c191b26b71eddc Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Wed, 3 Jun 2015 14:54:25 -0400 Subject: [PATCH] Split apart the uiControl text stuff in the same way the other uiControl functions are split in windows/control.c. This is a prerequisite for autoresizing on text change. Also simplified the title handling code in windows/window.c; it can use these functions too. --- redo/ui_windows.h | 8 +++++--- redo/windows/button.c | 4 ++-- redo/windows/checkbox.c | 4 ++-- redo/windows/control.c | 19 +++++++++++++------ redo/windows/entry.c | 4 ++-- redo/windows/label.c | 4 ++-- redo/windows/window.c | 21 ++++----------------- 7 files changed, 30 insertions(+), 34 deletions(-) diff --git a/redo/ui_windows.h b/redo/ui_windows.h index 91ae9212..3d0150d6 100644 --- a/redo/ui_windows.h +++ b/redo/ui_windows.h @@ -41,9 +41,11 @@ extern uiSizing *uiWindowsSizing(uiControl *); // and use this if you need the text of the window width _UI_EXTERN intmax_t uiWindowsWindowTextWidth(HWND hwnd); -// these functions get and set the window text for such a uiControl +// these functions get and set the window text for either a single HWND or a single-HWND uiControl // the value returned should be freed with uiFreeText() -_UI_EXTERN char *uiWindowsControlText(uiControl *); -_UI_EXTERN void uiWindowsControlSetText(uiControl *, const char *); +_UI_EXTERN char *uiWindowsUtilText(HWND); +_UI_EXTERN char *uiWindowsSingleHWNDControlText(uiControl *); +_UI_EXTERN void uiWindowsUtilSetText(HWND, const char *); +_UI_EXTERN void uiWindowsSingleHWNDControlSetText(uiControl *, const char *); #endif diff --git a/redo/windows/button.c b/redo/windows/button.c index 01b25502..253317d3 100644 --- a/redo/windows/button.c +++ b/redo/windows/button.c @@ -68,12 +68,12 @@ static void defaultOnClicked(uiButton *b, void *data) static char *buttonText(uiButton *b) { - return uiWindowsControlText(uiControl(b)); + return uiWindowsSingleHWNDControlText(uiControl(b)); } static void buttonSetText(uiButton *b, const char *text) { - uiWindowsControlSetText(uiControl(b), text); + uiWindowsSingleHWNDControlSetText(uiControl(b), text); } static void buttonOnClicked(uiButton *bb, void (*f)(uiButton *, void *), void *data) diff --git a/redo/windows/checkbox.c b/redo/windows/checkbox.c index 41ee3c97..5faffe26 100644 --- a/redo/windows/checkbox.c +++ b/redo/windows/checkbox.c @@ -65,12 +65,12 @@ static void defaultOnToggled(uiCheckbox *c, void *data) static char *checkboxText(uiCheckbox *c) { - return uiWindowsControlText(uiControl(c)); + return uiWindowsSingleHWNDControlText(uiControl(c)); } static void checkboxSetText(uiCheckbox *c, const char *text) { - uiWindowsControlSetText(uiControl(c), text); + uiWindowsSingleHWNDControlSetText(uiControl(c), text); } static void checkboxOnToggled(uiCheckbox *cc, void (*f)(uiCheckbox *, void *), void *data) diff --git a/redo/windows/control.c b/redo/windows/control.c index a2426b94..eb099a27 100644 --- a/redo/windows/control.c +++ b/redo/windows/control.c @@ -177,27 +177,34 @@ uiControl *uiWindowsNewSingleHWNDControl(uintmax_t type) // TODO migrate these to the system set up above -char *uiWindowsControlText(uiControl *c) +char *uiWindowsUtilText(HWND hwnd) { - HWND hwnd; WCHAR *wtext; char *text; - hwnd = (HWND) uiControlHandle(c); wtext = windowText(hwnd); text = toUTF8(wtext); uiFree(wtext); return text; } -void uiWindowsControlSetText(uiControl *c, const char *text) +// TODO get rid of these I guess +char *uiWindowsSingleHWNDControlText(uiControl *c) +{ + return uiWindowsUtilText(HWND(c)); +} + +void uiWindowsUtilSetText(HWND hwnd, const char *text) { - HWND hwnd; WCHAR *wtext; - hwnd = (HWND) uiControlHandle(c); wtext = toUTF16(text); if (SetWindowTextW(hwnd, wtext) == 0) logLastError("error setting control text in uiWindowsControlSetText()"); uiFree(wtext); } + +void uiWindowsSingleHWNDControlSetText(uiControl *c, const char *text) +{ + uiWindowsUtilSetText(HWND(c), text); +} diff --git a/redo/windows/entry.c b/redo/windows/entry.c index 78e5efeb..10370b82 100644 --- a/redo/windows/entry.c +++ b/redo/windows/entry.c @@ -57,7 +57,7 @@ static void defaultOnChanged(uiEntry *e, void *data) static char *entryText(uiEntry *e) { - return uiWindowsControlText(uiControl(e)); + return uiWindowsSingleHWNDControlText(uiControl(e)); } static void entrySetText(uiEntry *ee, const char *text) @@ -66,7 +66,7 @@ static void entrySetText(uiEntry *ee, const char *text) // doing this raises an EN_CHANGED e->inhibitChanged = TRUE; - uiWindowsControlSetText(uiControl(e), text); + uiWindowsSingleHWNDControlSetText(uiControl(e), text); e->inhibitChanged = FALSE; } diff --git a/redo/windows/label.c b/redo/windows/label.c index d629ae1a..a86118a6 100644 --- a/redo/windows/label.c +++ b/redo/windows/label.c @@ -28,12 +28,12 @@ static void labelPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intma static char *labelText(uiLabel *l) { - return uiWindowsControlText(uiControl(l)); + return uiWindowsSingleHWNDControlText(uiControl(l)); } static void labelSetText(uiLabel *l, const char *text) { - uiWindowsControlSetText(uiControl(l), text); + uiWindowsSingleHWNDControlSetText(uiControl(l), text); } uiLabel *uiNewLabel(const char *text) diff --git a/redo/windows/window.c b/redo/windows/window.c index ae0cd6b1..ddade42f 100644 --- a/redo/windows/window.c +++ b/redo/windows/window.c @@ -130,27 +130,14 @@ static void windowCommitShow(uiControl *c) // TODO container update state -static char *windowTitle(uiWindow *ww) +static char *windowTitle(uiWindow *w) { - struct window *w = (struct window *) ww; - WCHAR *wtext; - char *text; - - wtext = windowText(w->hwnd); - text = toUTF8(wtext); - uiFree(wtext); - return text; + return uiWindowsSingleHWNDControlText(uiControl(w)); } -static void windowSetTitle(uiWindow *ww, const char *title) +static void windowSetTitle(uiWindow *w, const char *title) { - struct window *w = (struct window *) ww; - WCHAR *wtitle; - - wtitle = toUTF16(title); - if (SetWindowTextW(w->hwnd, wtitle) == 0) - logLastError("error setting window title in uiWindowSetTitle()"); - uiFree(wtitle); + uiWindowsSingleHWNDControlSetText(uiControl(w), title); } static void windowOnClosing(uiWindow *ww, int (*f)(uiWindow *, void *), void *data)