summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPietro Gagliardi <[email protected]>2015-04-09 11:12:01 -0400
committerPietro Gagliardi <[email protected]>2015-04-09 11:12:01 -0400
commit79a7e18b8da55b4bcec72cc66f9b4e07878e7eee (patch)
tree1c3b3873576e80ee73cc8a6281cef5e0ef03b1be
parent1f18d88f565844436fb4487b596175ba48138c05 (diff)
Implemented the text functions on Windows.
-rw-r--r--new/button_windows.c10
-rw-r--r--new/entry_windows.c10
-rw-r--r--new/newcontrol_windows.c21
-rw-r--r--new/text_windows.c43
-rw-r--r--new/ui_windows.h5
-rw-r--r--new/uipriv_windows.h2
-rw-r--r--new/window_windows.c21
7 files changed, 110 insertions, 2 deletions
diff --git a/new/button_windows.c b/new/button_windows.c
index 9d3ae65..4a7620c 100644
--- a/new/button_windows.c
+++ b/new/button_windows.c
@@ -93,7 +93,15 @@ uiControl *uiNewButton(const char *text)
return b->c;
}
-// TODO text
+char *uiButtonText(uiControl *c)
+{
+ return uiWindowsControlText(c);
+}
+
+void uiButtonSetText(uiControl *c, const char *text)
+{
+ uiWindowsControlSetText(c, text);
+}
void uiButtonOnClicked(uiControl *c, void (*f)(uiControl *, void *), void *data)
{
diff --git a/new/entry_windows.c b/new/entry_windows.c
index b76d491..f147d5d 100644
--- a/new/entry_windows.c
+++ b/new/entry_windows.c
@@ -61,3 +61,13 @@ uiControl *uiNewEntry(void)
return e->c;
}
+
+char *uiEntryText(uiControl *c)
+{
+ return uiWindowsControlText(c);
+}
+
+void uiEntrySetText(uiControl *c, const char *text)
+{
+ uiWindowsControlSetText(c, text);
+}
diff --git a/new/newcontrol_windows.c b/new/newcontrol_windows.c
index ce7bad4..56719b3 100644
--- a/new/newcontrol_windows.c
+++ b/new/newcontrol_windows.c
@@ -123,3 +123,24 @@ void *uiWindowsControlData(uiControl *c)
{
return S(c)->data;
}
+
+char *uiWindowsControlText(uiControl *c)
+{
+ WCHAR *wtext;
+ char *text;
+
+ wtext = windowText(S(c)->hwnd);
+ text = toUTF8(wtext);
+ uiFree(wtext);
+ return text;
+}
+
+void uiWindowsControlSetText(uiControl *c, const char *text)
+{
+ WCHAR *wtext;
+
+ wtext = toUTF16(text);
+ if (SetWindowTextW(S(c)->hwnd, wtext) == 0)
+ logLastError("error setting control text in uiWindowsControlSetText()");
+ uiFree(wtext);
+}
diff --git a/new/text_windows.c b/new/text_windows.c
index e483a95..4f5b741 100644
--- a/new/text_windows.c
+++ b/new/text_windows.c
@@ -16,3 +16,46 @@ WCHAR *toUTF16(const char *str)
logLastError("error converting from UTF-8 to UTF-16 in toUTF16()");
return wstr;
}
+
+#define WCTMB(wstr, str, bufsiz) WideCharToMultiByte(CP_UTF8, WC_NO_BEST_FIT_CHARS, wstr, -1, str, bufsiz, NULL, FALSE)
+
+char *toUTF8(const WCHAR *wstr)
+{
+ char *str;
+ int n;
+
+ n = WCTMB(wstr, NULL, 0);
+ if (n == 0)
+ logLastError("error figuring out number of characters to convert to in toUTF8()");
+ // TODO does n include the null terminator?
+ str = (char *) uiAlloc((n + 1) * sizeof (char), "char[]");
+ if (WCTMB(wstr, str, n + 1) != n)
+ logLastError("error converting from UTF-16 to UTF-8 in toUTFF8()");
+ return str;
+}
+
+WCHAR *windowText(HWND hwnd)
+{
+ int n;
+ WCHAR *text;
+ DWORD le;
+
+ SetLastError(0);
+ n = GetWindowTextLengthW(hwnd);
+ if (n == 0) {
+ le = GetLastError();
+ SetLastError(le); // just in case
+ if (le != 0)
+ logLastError("error getting window text length in windowText()");
+ }
+ // TODO null terminator?
+ text = (WCHAR *) uiAlloc((n + 1) * sizeof (WCHAR), "WCHAR[]");
+ if (GetWindowTextW(hwnd, text, n + 1) != n)
+ logLastError("error getting window text in windowText()");
+ return text;
+}
+
+void uiFreeText(char *text)
+{
+ uiFree(text);
+}
diff --git a/new/ui_windows.h b/new/ui_windows.h
index 3a4ebd9..d1a9578 100644
--- a/new/ui_windows.h
+++ b/new/ui_windows.h
@@ -47,4 +47,9 @@ void *uiWindowsControlData(uiControl *);
// TODO really export?
extern intmax_t uiWindowsWindowTextWidth(HWND hwnd);
+// these functions get and set the window text for such a uiControl
+// the value returned should be freed with uiFreeText()
+extern char *uiWindowsControlText(uiControl *);
+extern void uiWindowsControlSetText(uiControl *, const char *);
+
#endif
diff --git a/new/uipriv_windows.h b/new/uipriv_windows.h
index 99c742b..2baa7e8 100644
--- a/new/uipriv_windows.h
+++ b/new/uipriv_windows.h
@@ -49,6 +49,8 @@ extern HWND initialParent;
// text_windows.c
extern WCHAR *toUTF16(const char *);
+extern char *toUTF8(const WCHAR *);
+extern WCHAR *windowText(HWND);
// container_windows.c
extern BOOL sharedWndProc(HWND, UINT, WPARAM, LPARAM, LRESULT *);
diff --git a/new/window_windows.c b/new/window_windows.c
index 88e7aae..2a5603f 100644
--- a/new/window_windows.c
+++ b/new/window_windows.c
@@ -116,7 +116,26 @@ uintptr_t uiWindowHandle(uiWindow *w)
return (uintptr_t) (w->hwnd);
}
-// TODO titles
+char *uiWindowTitle(uiWindow *w)
+{
+ WCHAR *wtext;
+ char *text;
+
+ wtext = windowText(w->hwnd);
+ text = toUTF8(wtext);
+ uiFree(wtext);
+ return text;
+}
+
+void uiWindowSetTitle(uiWindow *w, const char *text)
+{
+ WCHAR *wtext;
+
+ wtext = toUTF16(text);
+ if (SetWindowTextW(w->hwnd, wtext) == 0)
+ logLastError("error setting window title in uiWindowSetTitle()");
+ uiFree(wtext);
+}
void uiWindowShow(uiWindow *w)
{