summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--new/singlehandle_windows.c52
-rw-r--r--new/ui_windows.h12
-rw-r--r--new/uipriv.h5
3 files changed, 67 insertions, 2 deletions
diff --git a/new/singlehandle_windows.c b/new/singlehandle_windows.c
new file mode 100644
index 0000000..a6e3960
--- /dev/null
+++ b/new/singlehandle_windows.c
@@ -0,0 +1,52 @@
+// 6 april 2015
+#include "tablepriv.h"
+
+// Common code for controls with a single window handle.
+// The only method NOT defined is preferredSize(); this differs between controls.
+
+static uintptr_t singleHandle(uiControl *c)
+{
+ return (uintptr_t) (c->hwnd);
+}
+
+//TODO void (*setParent)(uiControl *, uintptr_t);
+
+static void singleResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
+{
+ if (MoveWindow(c->hwnd, x, y, width, height, TRUE) == 0)
+ logLastError("error moving control in singleResize()");
+}
+
+static void singleContainerShow(uiControl *c)
+{
+ ShowWindow(c->hwnd, SW_SHOW);
+}
+
+static void singleContainerHide(uiControl *c)
+{
+ ShowWindow(c->hwnd, SW_HIDE);
+}
+
+uiSingleHWNDControl *newSingleHWNDControl(DWORD exstyle, const WCHAR *class, DWORD style, HWND parent, HINSTANCE hInstance)
+{
+ uiSingleHWNDControl *c;
+
+ c = uiNew(uiSingleHWNDControl);
+ c->hwnd = CreateWindowExW(exstyle,
+ class, L"",
+ style | WS_CHILD | WS_VISIBLE,
+ 0, 0,
+ 100, 100,
+ // TODO specify control IDs properly
+ parent, NULL, hInstance, NULL);
+ if (c->hwnd == NULL)
+ logLastError("error creating control in newSingleHWNDControl()");
+
+ c->control.handle = singleHandle;
+//TODO c->control.setParent = singleSetParent;
+ c->control.resize = singleResize;
+ c->control.containerShow = singleContainerShow;
+ c->control.containerHide = singleContainerHide;
+
+ return c;
+}
diff --git a/new/ui_windows.h b/new/ui_windows.h
index f0bbe2c..00a14c8 100644
--- a/new/ui_windows.h
+++ b/new/ui_windows.h
@@ -33,6 +33,8 @@
// alloc_windows.c
extern void *uiAlloc(size_t);
+// TODO use this in existing files
+#define uiNew(T) ((T *) uiAlloc(sizeof (T)))
extern void *uiRealloc(void *, size_t);
extern void uiFree(void *);
@@ -52,4 +54,14 @@ extern WCHAR *toUTF16(const char *);
// window_windows.c
extern ATOM registerWindowClass(HICON, HCURSOR);
+// singlehandle_windows.c
+typedef struct uiSingleHWNDControl uiSingleHWNDControl;
+struct uiSingleHWNDControl {
+ uiControl control;
+ HWND hwnd;
+ void (*voidEvent)(uiControl *, void *);
+ void *voidEventData;
+};
+extern uiSingleHWNDControl *newSingleHWNDControl(DWORD, const WCHAR *, DWORD, HWND, HINSTANCE);
+
#endif
diff --git a/new/uipriv.h b/new/uipriv.h
index 158d30c..002adf0 100644
--- a/new/uipriv.h
+++ b/new/uipriv.h
@@ -9,11 +9,12 @@ struct uiSize {
intmax_t height;
};
+// TODO handle destruction
struct uiControl {
uintptr_t (*handle)(uiControl *);
- void (*setParent)(uiControl *, uintptr_t);
+//TODO void (*setParent)(uiControl *, uintptr_t);
uiSize (*preferredSize)(uiControl *, uiSizing *);
- void (*resizing)(uiControl *, intmax_t, intmax_t, intmax_t, intmax_t, uiSizing *);
+ void (*resize)(uiControl *, intmax_t, intmax_t, intmax_t, intmax_t, uiSizing *);
void (*containerShow)(uiControl *);
void (*containerHide)(uiControl *);
};