More migration work.

This commit is contained in:
Pietro Gagliardi 2015-08-30 19:32:05 -04:00
parent 34f0d71d0c
commit 311a7d4124
2 changed files with 39 additions and 72 deletions

View File

@ -1,7 +1,9 @@
// 26 april 2015 // 26 april 2015
#include "uipriv_windows.h" #include "uipriv_windows.h"
// Code for containers. uiMakeContainer() creates a singleHWND of this window class. // Code for the HWND of the following uiControls:
// - uiBox
// - uiRadioButtons
static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) static LRESULT CALLBACK containerWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
@ -55,10 +57,9 @@ void uninitContainer(void)
logLastError("error unregistering container window class in uninitContainer()"); logLastError("error unregistering container window class in uninitContainer()");
} }
uintptr_t uiMakeContainer(uiControl *c) HWND makeContainer(void)
{ {
setSingleHWNDFuncs(c); return uiWindowsUtilCreateControlHWND(WS_EX_CONTROLPARENT,
return (uintptr_t) uiWindowsUtilCreateControlHWND(WS_EX_CONTROLPARENT,
containerClass, L"", containerClass, L"",
0, 0,
hInstance, NULL, hInstance, NULL,

View File

@ -1,32 +1,35 @@
// 27 april 2015 // 27 april 2015
#include "uipriv_windows.h" #include "uipriv_windows.h"
// TODO ban uiControl methods that mean nothing on toplevels
#define windowClass L"libui_uiWindowClass" #define windowClass L"libui_uiWindowClass"
struct window { struct uiWindow {
uiWindow w; uiWindowsControl c;
HWND hwnd; HWND hwnd;
HMENU menubar; HMENU menubar;
uiControl *child; struct child *child;
BOOL shownOnce; BOOL shownOnce;
int (*onClosing)(uiWindow *, void *); int (*onClosing)(uiWindow *, void *);
void *onClosingData; void *onClosingData;
int margined; int margined;
void (*baseCommitDestroy)(uiControl *);
}; };
uiDefineControlType(uiWindow, uiTypeWindow, struct window) static void onDestroy(uiWindow *);
uiWindowsDefineControlWithOnDestroy(
uiWindow, // type name
uiWindowType, // type function
onDestroy(this); // on destroy
)
static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{ {
struct window *w; uiWindow *w;
CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam; CREATESTRUCTW *cs = (CREATESTRUCTW *) lParam;
WINDOWPOS *wp = (WINDOWPOS *) lParam; WINDOWPOS *wp = (WINDOWPOS *) lParam;
LRESULT lResult; LRESULT lResult;
w = (struct window *) GetWindowLongPtrW(hwnd, GWLP_USERDATA); w = uiWindow((void *) GetWindowLongPtrW(hwnd, GWLP_USERDATA));
if (w == NULL) { if (w == NULL) {
if (uMsg == WM_CREATE) if (uMsg == WM_CREATE)
SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (cs->lpCreateParams)); SetWindowLongPtrW(hwnd, GWLP_USERDATA, (LONG_PTR) (cs->lpCreateParams));
@ -56,7 +59,7 @@ static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARA
SendMessageW(hwnd, WM_ERASEBKGND, wParam, lParam); SendMessageW(hwnd, WM_ERASEBKGND, wParam, lParam);
return 0; return 0;
case WM_CLOSE: case WM_CLOSE:
if ((*(w->onClosing))(uiWindow(w), w->onClosingData)) if ((*(w->onClosing))(w, w->onClosingData))
uiControlDestroy(uiControl(w)); uiControlDestroy(uiControl(w));
return 0; // we destroyed it already return 0; // we destroyed it already
} }
@ -88,36 +91,23 @@ static int defaultOnClosing(uiWindow *w, void *data)
return 0; return 0;
} }
static void windowCommitDestroy(uiControl *c) static void onDestroy(uiWindow *w)
{ {
struct window *w = (struct window *) c;
// first hide ourselves // first hide ourselves
ShowWindow(w->hwnd, SW_HIDE); ShowWindow(w->hwnd, SW_HIDE);
// now destroy the child // now destroy the child
// we need to unset its parent first if (w->child != NULL)
if (w->child != NULL) { childDestroy(w->child);
uiControlSetParent(w->child, NULL);
uiControlDestroy(w->child);
}
// now free the menubar, if any // now free the menubar, if any
if (w->menubar != NULL) if (w->menubar != NULL)
freeMenubar(w->menubar); freeMenubar(w->menubar);
// and finally destroy ourselves // and finally destroy ourselves
dialogHelperUnregisterWindow(w->hwnd); dialogHelperUnregisterWindow(w->hwnd);
(*(w->baseCommitDestroy))(uiControl(w));
}
static uintptr_t windowHandle(uiControl *c)
{
struct window *w = (struct window *) c;
return (uintptr_t) (w->hwnd);
} }
static void windowCommitShow(uiControl *c) static void windowCommitShow(uiControl *c)
{ {
struct window *w = (struct window *) c; uiWindow *w = uiWindow(c);
if (w->shownOnce) { if (w->shownOnce) {
ShowWindow(w->hwnd, SW_SHOW); ShowWindow(w->hwnd, SW_SHOW);
@ -133,59 +123,45 @@ static void windowCommitShow(uiControl *c)
static void windowContainerUpdateState(uiControl *c) static void windowContainerUpdateState(uiControl *c)
{ {
struct window *w = (struct window *) c; uiWindow *w = uiWindow(c);
if (w->child != NULL) if (w->child != NULL)
uiControlUpdateState(w->child); childContainerUpdateState(w->child);
} }
static char *windowTitle(uiWindow *ww) char *uiWindowTitle(uiWindow *w)
{ {
struct window *w = (struct window *) ww;
return uiWindowsUtilText(w->hwnd); return uiWindowsUtilText(w->hwnd);
} }
static void windowSetTitle(uiWindow *ww, const char *title) void uiWindowSetTitle(uiWindow *w, const char *title)
{ {
struct window *w = (struct window *) ww;
uiWindowsUtilSetText(w->hwnd, title); uiWindowsUtilSetText(w->hwnd, title);
// don't queue resize; the caption isn't part of what affects layout and sizing of the client area (it'll be ellipsized if too long) // don't queue resize; the caption isn't part of what affects layout and sizing of the client area (it'll be ellipsized if too long)
} }
static void windowOnClosing(uiWindow *ww, int (*f)(uiWindow *, void *), void *data) void uiWindowOnClosing(uiWindow *ww, int (*f)(uiWindow *, void *), void *data)
{ {
struct window *w = (struct window *) ww;
w->onClosing = f; w->onClosing = f;
w->onClosingData = data; w->onClosingData = data;
} }
static void windowSetChild(uiWindow *ww, uiControl *child) void uiWindowSetChild(uiWindow *w, uiControl *child)
{ {
struct window *w = (struct window *) ww;
if (w->child != NULL) if (w->child != NULL)
uiControlSetParent(w->child, NULL); childRemove(w->child);
w->child = child; w->child = newChild(child, uiControl(w), w->hwnd);
if (w->child != NULL) { if (w->child != NULL)
uiControlSetParent(w->child, uiControl(w));
uiControlQueueResize(w->child); uiControlQueueResize(w->child);
}
} }
static int windowMargined(uiWindow *ww) int uiWindowMargined(uiWindow *w)
{ {
struct window *w = (struct window *) ww;
return w->margined; return w->margined;
} }
static void windowSetMargined(uiWindow *ww, int margined) void uiWindowSetMargined(uiWindow *w, int margined)
{ {
struct window *w = (struct window *) ww;
w->margined = margined; w->margined = margined;
uiControlQueueResize(uiControl(w)); uiControlQueueResize(uiControl(w));
} }
@ -215,7 +191,7 @@ static void windowResizeChild(uiWindow *ww)
} }
// see http://blogs.msdn.com/b/oldnewthing/archive/2003/09/11/54885.aspx and http://blogs.msdn.com/b/oldnewthing/archive/2003/09/13/54917.aspx // see http://blogs.msdn.com/b/oldnewthing/archive/2003/09/11/54885.aspx and http://blogs.msdn.com/b/oldnewthing/archive/2003/09/13/54917.aspx
static void setClientSize(struct window *w, int width, int height, BOOL hasMenubar, DWORD style, DWORD exstyle) static void setClientSize(uiWindow *w, int width, int height, BOOL hasMenubar, DWORD style, DWORD exstyle)
{ {
RECT window; RECT window;
@ -239,11 +215,11 @@ static void setClientSize(struct window *w, int width, int height, BOOL hasMenub
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar) uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
{ {
struct window *w; uiWindow *w;
WCHAR *wtitle; WCHAR *wtitle;
BOOL hasMenubarBOOL; BOOL hasMenubarBOOL;
w = (struct window *) uiWindowsNewSingleHWNDControl(uiTypeWindow()); w = (uiWindow *) uiNewControl(uiWindowType());
hasMenubarBOOL = FALSE; hasMenubarBOOL = FALSE;
if (hasMenubar) if (hasMenubar)
@ -277,21 +253,11 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
// and use the proper size // and use the proper size
setClientSize(w, width, height, hasMenubarBOOL, style, exstyle); setClientSize(w, width, height, hasMenubarBOOL, style, exstyle);
w->onClosing = defaultOnClosing; uiWindowSetOnClosing(w, defaultOnClosing, NULL);
uiControl(w)->Handle = windowHandle; uiWindowsFinishNewControl(w, uiWindow);
w->baseCommitDestroy = uiControl(w)->CommitDestroy;
uiControl(w)->CommitDestroy = windowCommitDestroy;
uiControl(w)->CommitShow = windowCommitShow; uiControl(w)->CommitShow = windowCommitShow;
uiControl(w)->ContainerUpdateState = windowContainerUpdateState; uiControl(w)->ContainerUpdateState = windowContainerUpdateState;
uiWindow(w)->Title = windowTitle; return w;
uiWindow(w)->SetTitle = windowSetTitle;
uiWindow(w)->OnClosing = windowOnClosing;
uiWindow(w)->SetChild = windowSetChild;
uiWindow(w)->Margined = windowMargined;
uiWindow(w)->SetMargined = windowSetMargined;
uiWindow(w)->ResizeChild = windowResizeChild;
return uiWindow(w);
} }