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.

This commit is contained in:
Pietro Gagliardi 2015-06-03 14:54:25 -04:00
parent 96570d78be
commit 4edef818b9
7 changed files with 30 additions and 34 deletions

View File

@ -41,9 +41,11 @@ extern uiSizing *uiWindowsSizing(uiControl *);
// and use this if you need the text of the window width // and use this if you need the text of the window width
_UI_EXTERN intmax_t uiWindowsWindowTextWidth(HWND hwnd); _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() // the value returned should be freed with uiFreeText()
_UI_EXTERN char *uiWindowsControlText(uiControl *); _UI_EXTERN char *uiWindowsUtilText(HWND);
_UI_EXTERN void uiWindowsControlSetText(uiControl *, const char *); _UI_EXTERN char *uiWindowsSingleHWNDControlText(uiControl *);
_UI_EXTERN void uiWindowsUtilSetText(HWND, const char *);
_UI_EXTERN void uiWindowsSingleHWNDControlSetText(uiControl *, const char *);
#endif #endif

View File

@ -68,12 +68,12 @@ static void defaultOnClicked(uiButton *b, void *data)
static char *buttonText(uiButton *b) static char *buttonText(uiButton *b)
{ {
return uiWindowsControlText(uiControl(b)); return uiWindowsSingleHWNDControlText(uiControl(b));
} }
static void buttonSetText(uiButton *b, const char *text) 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) static void buttonOnClicked(uiButton *bb, void (*f)(uiButton *, void *), void *data)

View File

@ -65,12 +65,12 @@ static void defaultOnToggled(uiCheckbox *c, void *data)
static char *checkboxText(uiCheckbox *c) static char *checkboxText(uiCheckbox *c)
{ {
return uiWindowsControlText(uiControl(c)); return uiWindowsSingleHWNDControlText(uiControl(c));
} }
static void checkboxSetText(uiCheckbox *c, const char *text) 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) static void checkboxOnToggled(uiCheckbox *cc, void (*f)(uiCheckbox *, void *), void *data)

View File

@ -177,27 +177,34 @@ uiControl *uiWindowsNewSingleHWNDControl(uintmax_t type)
// TODO migrate these to the system set up above // TODO migrate these to the system set up above
char *uiWindowsControlText(uiControl *c) char *uiWindowsUtilText(HWND hwnd)
{ {
HWND hwnd;
WCHAR *wtext; WCHAR *wtext;
char *text; char *text;
hwnd = (HWND) uiControlHandle(c);
wtext = windowText(hwnd); wtext = windowText(hwnd);
text = toUTF8(wtext); text = toUTF8(wtext);
uiFree(wtext); uiFree(wtext);
return text; 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; WCHAR *wtext;
hwnd = (HWND) uiControlHandle(c);
wtext = toUTF16(text); wtext = toUTF16(text);
if (SetWindowTextW(hwnd, wtext) == 0) if (SetWindowTextW(hwnd, wtext) == 0)
logLastError("error setting control text in uiWindowsControlSetText()"); logLastError("error setting control text in uiWindowsControlSetText()");
uiFree(wtext); uiFree(wtext);
} }
void uiWindowsSingleHWNDControlSetText(uiControl *c, const char *text)
{
uiWindowsUtilSetText(HWND(c), text);
}

View File

@ -57,7 +57,7 @@ static void defaultOnChanged(uiEntry *e, void *data)
static char *entryText(uiEntry *e) static char *entryText(uiEntry *e)
{ {
return uiWindowsControlText(uiControl(e)); return uiWindowsSingleHWNDControlText(uiControl(e));
} }
static void entrySetText(uiEntry *ee, const char *text) 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 // doing this raises an EN_CHANGED
e->inhibitChanged = TRUE; e->inhibitChanged = TRUE;
uiWindowsControlSetText(uiControl(e), text); uiWindowsSingleHWNDControlSetText(uiControl(e), text);
e->inhibitChanged = FALSE; e->inhibitChanged = FALSE;
} }

View File

@ -28,12 +28,12 @@ static void labelPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intma
static char *labelText(uiLabel *l) static char *labelText(uiLabel *l)
{ {
return uiWindowsControlText(uiControl(l)); return uiWindowsSingleHWNDControlText(uiControl(l));
} }
static void labelSetText(uiLabel *l, const char *text) static void labelSetText(uiLabel *l, const char *text)
{ {
uiWindowsControlSetText(uiControl(l), text); uiWindowsSingleHWNDControlSetText(uiControl(l), text);
} }
uiLabel *uiNewLabel(const char *text) uiLabel *uiNewLabel(const char *text)

View File

@ -130,27 +130,14 @@ static void windowCommitShow(uiControl *c)
// TODO container update state // TODO container update state
static char *windowTitle(uiWindow *ww) static char *windowTitle(uiWindow *w)
{ {
struct window *w = (struct window *) ww; return uiWindowsSingleHWNDControlText(uiControl(w));
WCHAR *wtext;
char *text;
wtext = windowText(w->hwnd);
text = toUTF8(wtext);
uiFree(wtext);
return text;
} }
static void windowSetTitle(uiWindow *ww, const char *title) static void windowSetTitle(uiWindow *w, const char *title)
{ {
struct window *w = (struct window *) ww; uiWindowsSingleHWNDControlSetText(uiControl(w), title);
WCHAR *wtitle;
wtitle = toUTF16(title);
if (SetWindowTextW(w->hwnd, wtitle) == 0)
logLastError("error setting window title in uiWindowSetTitle()");
uiFree(wtitle);
} }
static void windowOnClosing(uiWindow *ww, int (*f)(uiWindow *, void *), void *data) static void windowOnClosing(uiWindow *ww, int (*f)(uiWindow *, void *), void *data)