From ef08a106f929d07d309706a9e5034b1d23a4c477 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Fri, 29 May 2015 20:40:54 -0400 Subject: [PATCH] Prepared a few things for migrating windows/container.c. --- redo/box.c | 22 +++++++++++++++------- redo/ui.idl | 2 +- redo/windows/control.c | 13 +++++++++---- redo/windows/uipriv_windows.h | 3 +++ 4 files changed, 28 insertions(+), 12 deletions(-) diff --git a/redo/box.c b/redo/box.c index 8241963d..4ae4e9e0 100644 --- a/redo/box.c +++ b/redo/box.c @@ -4,7 +4,8 @@ struct box { uiBox b; - void (*baseDestroy)(uiControl *); + void (*baseCommitDestroy)(uiControl *); + uintptr_t handle; struct ptrArray *controls; int vertical; int padded; @@ -18,7 +19,7 @@ struct boxControl { intmax_t height; }; -static void boxDestroy(uiControl *c) +static void boxCommitDestroy(uiControl *c) { struct box *b = (struct box *) c; struct boxControl *bc; @@ -33,8 +34,14 @@ static void boxDestroy(uiControl *c) } ptrArrayDestroy(b->controls); // NOW we can chain up to base - (*(b->baseDestroy))(uiControl(b)); - uiFree(b); + (*(b->baseCommitDestroy))(uiControl(b)); +} + +static uintptr_t boxHandle(uiControl *c) +{ + struct box *b = (struct box *) c; + + return b->handle; } static void boxPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height) @@ -257,16 +264,17 @@ uiBox *uiNewHorizontalBox(void) b = uiNew(struct box); uiTyped(b)->Type = uiTypeBox(); - uiMakeContainer(uiControl(b)); + b->handle = uiMakeContainer(uiControl(b)); b->controls = newPtrArray(); - b->baseDestroy = uiControl(b)->Destroy; - uiControl(b)->Destroy = boxDestroy; + uiControl(b)->Handle = boxHandle; uiControl(b)->PreferredSize = boxPreferredSize; b->baseResize = uiControl(b)->Resize; uiControl(b)->Resize = boxResize; uiControl(b)->SysFunc = boxSysFunc; + b->baseCommitDestroy = uiControl(b)->CommitDestroy; + uiControl(b)->CommitDestroy = boxCommitDestroy; uiBox(b)->Append = boxAppend; uiBox(b)->Delete = boxDelete; diff --git a/redo/ui.idl b/redo/ui.idl index 322866a2..8d346ad0 100644 --- a/redo/ui.idl +++ b/redo/ui.idl @@ -87,7 +87,7 @@ raw " }"; func FreeSizing(d *Sizing); -func MakeContainer(c *Control); +func MakeContainer(c *Control) uintptr_t; interface Window from Control { func Title(void) *char; diff --git a/redo/windows/control.c b/redo/windows/control.c index 118cf1db..1a38efe1 100644 --- a/redo/windows/control.c +++ b/redo/windows/control.c @@ -144,11 +144,8 @@ static void singleHWNDStartZOrder(uiControl *c, uiControlSysFuncParams *p) uiWindowsUtilStartZOrder(HWND(c), p); } -uiControl *uiWindowsNewSingleHWNDControl(uintmax_t type) +void setSingleHWNDFuncs(uiControl *c) { - uiControl *c; - - c = uiNewControl(type); uiControl(c)->CommitDestroy = singleHWNDCommitDestroy; uiControl(c)->CommitSetParent = singleHWNDCommitSetParent; uiControl(c)->Resize = singleHWNDResize; @@ -159,5 +156,13 @@ uiControl *uiWindowsNewSingleHWNDControl(uintmax_t type) uiControl(c)->CommitDisable = singleHWNDCommitDisable; uiControl(c)->SysFunc = singleHWNDSysFunc; uiControl(c)->StartZOrder = singleHWNDStartZOrder; +} + +uiControl *uiWindowsNewSingleHWNDControl(uintmax_t type) +{ + uiControl *c; + + c = uiNewControl(type); + setSingleHWNDFuncs(c); return c; } diff --git a/redo/windows/uipriv_windows.h b/redo/windows/uipriv_windows.h index 9b32313b..22942609 100644 --- a/redo/windows/uipriv_windows.h +++ b/redo/windows/uipriv_windows.h @@ -128,3 +128,6 @@ extern void dialogHelperUnregisterWindow(HWND); extern ATOM initDialogHelper(HICON, HCURSOR); extern HWND beginDialogHelper(void); extern void endDialogHelper(HWND); + +// control.c +extern void setSingleHWNDFuncs(uiControl *);