summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--new/TODO.md3
-rw-r--r--new/windows/window.c118
2 files changed, 76 insertions, 45 deletions
diff --git a/new/TODO.md b/new/TODO.md
index cfd298a..fe05013 100644
--- a/new/TODO.md
+++ b/new/TODO.md
@@ -13,7 +13,8 @@
- SWP_NOCOPYBITS (or was it WS_CLIPCHILDREN?)
- buttons not in tab get drawover issues
- buttons in tab without transparent drawing code get copied into the label when stack shown and rehidden
-- see if we can clean up the GTK+ backend
+- see if we can clean up the GTK+ and Windows backends
+ - rename all method implementations to typeMethod
ultimately:
- make everything vtable-based
diff --git a/new/windows/window.c b/new/windows/window.c
index fb92c0d..16ea5ba 100644
--- a/new/windows/window.c
+++ b/new/windows/window.c
@@ -1,7 +1,8 @@
// 6 april 2015
#include "uipriv_windows.h"
-struct uiWindow {
+struct window {
+ uiWindow w;
HWND hwnd;
uiParent *content;
BOOL shownOnce;
@@ -14,13 +15,13 @@ struct uiWindow {
static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
- uiWindow *w;
+ struct window *w;
CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam;
WINDOWPOS *wp = (WINDOWPOS *) lParam;
RECT r;
HWND contenthwnd;
- w = (uiWindow *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
+ w = (struct window *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
if (w == NULL) {
if (uMsg == WM_CREATE)
SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (cs->lpCreateParams));
@@ -73,50 +74,23 @@ static int defaultOnClosing(uiWindow *w, void *data)
return 1;
}
-uiWindow *uiNewWindow(char *title, int width, int height)
+static void windowDestroy(uiWindow *ww)
{
- uiWindow *w;
- RECT adjust;
- WCHAR *wtitle;
-
- w = uiNew(uiWindow);
- w->onClosing = defaultOnClosing;
+ struct window *w = (struct window *) ww;
- adjust.left = 0;
- adjust.top = 0;
- adjust.right = width;
- adjust.bottom = height;
- if (AdjustWindowRectEx(&adjust, style, FALSE, exstyle) == 0)
- logLastError("error getting real window coordinates in uiWindow()");
-
- wtitle = toUTF16(title);
- w->hwnd = CreateWindowExW(exstyle,
- uiWindowClass, wtitle,
- style,
- CW_USEDEFAULT, CW_USEDEFAULT,
- adjust.right - adjust.left, adjust.bottom - adjust.top,
- NULL, NULL, hInstance, w);
- if (w->hwnd == NULL)
- logLastError("error creating window in uiWindow()");
- uiFree(wtitle);
-
- w->content = uiNewParent((uintptr_t) (w->hwnd));
-
- return w;
-}
-
-void uiWindowDestroy(uiWindow *w)
-{
DestroyWindow(w->hwnd);
}
-uintptr_t uiWindowHandle(uiWindow *w)
+static uintptr_t windowHandle(uiWindow *ww)
{
+ struct window *w = (struct window *) ww;
+
return (uintptr_t) (w->hwnd);
}
-char *uiWindowTitle(uiWindow *w)
+static char *windowTitle(uiWindow *ww)
{
+ struct window *w = (struct window *) ww;
WCHAR *wtext;
char *text;
@@ -126,8 +100,9 @@ char *uiWindowTitle(uiWindow *w)
return text;
}
-void uiWindowSetTitle(uiWindow *w, const char *text)
+static void windowSetTitle(uiWindow *ww, const char *text)
{
+ struct window *w = (struct window *) ww;
WCHAR *wtext;
wtext = toUTF16(text);
@@ -136,8 +111,10 @@ void uiWindowSetTitle(uiWindow *w, const char *text)
uiFree(wtext);
}
-void uiWindowShow(uiWindow *w)
+void uiWindowShow(uiWindow *ww)
{
+ struct window *w = (struct window *) ww;
+
if (w->shownOnce) {
ShowWindow(w->hwnd, SW_SHOW);
return;
@@ -148,35 +125,45 @@ void uiWindowShow(uiWindow *w)
logLastError("error calling UpdateWindow() after showing uiWindow for the first time");
}
-void uiWindowHide(uiWindow *w)
+void uiWindowHide(uiWindow *ww)
{
+ struct window *w = (struct window *) ww;
+
ShowWindow(w->hwnd, SW_HIDE);
}
-void uiWindowOnClosing(uiWindow *w, int (*f)(uiWindow *, void *), void *data)
+static void windowOnClosing(uiWindow *ww, int (*f)(uiWindow *, void *), void *data)
{
+ struct window *w = (struct window *) ww;
+
w->onClosing = f;
w->onClosingData = data;
}
-void uiWindowSetChild(uiWindow *w, uiControl *c)
+static void windowSetChild(uiWindow *ww, uiControl *c)
{
+ struct window *w = (struct window *) ww
+
uiParentSetChild(w->content, c);
// don't call uiParentUpdate(); instead, synthesize a resize
// otherwise, we'll have a 0x0 content area at first
SendMessageW(w->hwnd, msgUpdateChild, 0, 0);
}
-int uiWindowMargined(uiWindow *w)
+int uiWindowMargined(uiWindow *ww)
{
+ struct window *w = (struct window *) ww;
+
return w->margined;
}
// from https://msdn.microsoft.com/en-us/library/windows/desktop/dn742486.aspx#sizingandspacing
#define windowMargin 7
-void uiWindowSetMargined(uiWindow *w, int margined)
+void uiWindowSetMargined(uiWindow *ww, int margined)
{
+ struct window *w = (struct window *) ww;
+
w->margined = margined;
if (w->margined)
uiParentSetMargins(w->content, windowMargin, windowMargin, windowMargin, windowMargin);
@@ -184,3 +171,46 @@ void uiWindowSetMargined(uiWindow *w, int margined)
uiParentSetMargins(w->content, 0, 0, 0, 0);
uiParentUpdate(w->content);
}
+
+uiWindow *uiNewWindow(char *title, int width, int height)
+{
+ struct window *w;
+ RECT adjust;
+ WCHAR *wtitle;
+
+ w = uiNew(struct window);
+ w->onClosing = defaultOnClosing;
+
+ adjust.left = 0;
+ adjust.top = 0;
+ adjust.right = width;
+ adjust.bottom = height;
+ if (AdjustWindowRectEx(&adjust, style, FALSE, exstyle) == 0)
+ logLastError("error getting real window coordinates in uiWindow()");
+
+ wtitle = toUTF16(title);
+ w->hwnd = CreateWindowExW(exstyle,
+ uiWindowClass, wtitle,
+ style,
+ CW_USEDEFAULT, CW_USEDEFAULT,
+ adjust.right - adjust.left, adjust.bottom - adjust.top,
+ NULL, NULL, hInstance, w);
+ if (w->hwnd == NULL)
+ logLastError("error creating window in uiWindow()");
+ uiFree(wtitle);
+
+ w->content = uiNewParent((uintptr_t) (w->hwnd));
+
+ uiWindow(w)->Destroy = windowDestroy;
+ uiWindow(w)->Handle = windowHandle;
+ uiWindow(w)->Title = windowTitle;
+ uiWindow(w)->SetTitle = windowSetTitle;
+ uiWindow(w)->Show = windowShow;
+ uiWindow(w)->Hide = windowHide;
+ uiWindow(w)->OnClosing = windowOnClosing;
+ uiWindow(w)->SetChild = windowSetChild;
+ uiWindow(w)->Margined = windowMargined;
+ uiWindow(w)->SetMargined = windowSetMargined;
+
+ return uiWindow(w);
+}