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
_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

View File

@ -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)

View File

@ -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)

View File

@ -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);
}

View File

@ -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;
}

View File

@ -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)

View File

@ -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)