Started work on ensuring things get cleaned up. Added a destroy() method to uiControl and implemented most of the work for Windows.
This commit is contained in:
parent
521829a0a6
commit
54e947eed3
|
@ -1,6 +1,11 @@
|
||||||
// 7 april 2015
|
// 7 april 2015
|
||||||
#include "uipriv.h"
|
#include "uipriv.h"
|
||||||
|
|
||||||
|
void uiControlDestroy(uiControl *c)
|
||||||
|
{
|
||||||
|
(*(c->destroy))(c);
|
||||||
|
}
|
||||||
|
|
||||||
uintptr_t uiControlHandle(uiControl *c)
|
uintptr_t uiControlHandle(uiControl *c)
|
||||||
{
|
{
|
||||||
return (*(c->handle))(c);
|
return (*(c->handle))(c);
|
||||||
|
|
|
@ -15,6 +15,13 @@ struct uiSingleHWNDControl {
|
||||||
|
|
||||||
#define S(c) ((uiSingleHWNDControl *) (c))
|
#define S(c) ((uiSingleHWNDControl *) (c))
|
||||||
|
|
||||||
|
static void singleDestroy(uiControl *c)
|
||||||
|
{
|
||||||
|
if (DestroyWindow(S(c)->hwnd) == 0)
|
||||||
|
logLastError("error destroying control in singleDestroy()");
|
||||||
|
// the uiSingleHWNDControl is destroyed in the subclass procedure
|
||||||
|
}
|
||||||
|
|
||||||
static uintptr_t singleHandle(uiControl *c)
|
static uintptr_t singleHandle(uiControl *c)
|
||||||
{
|
{
|
||||||
return (uintptr_t) (S(c)->hwnd);
|
return (uintptr_t) (S(c)->hwnd);
|
||||||
|
@ -57,6 +64,8 @@ static LRESULT CALLBACK singleSubclassProc(HWND hwnd, UINT uMsg, WPARAM wParam,
|
||||||
return lResult;
|
return lResult;
|
||||||
break;
|
break;
|
||||||
case WM_NCDESTROY:
|
case WM_NCDESTROY:
|
||||||
|
// TODO call an onDestroy handler
|
||||||
|
uiFree(c);
|
||||||
if ((*fv_RemoveWindowSubclass)(hwnd, singleSubclassProc, uIdSubclass) == FALSE)
|
if ((*fv_RemoveWindowSubclass)(hwnd, singleSubclassProc, uIdSubclass) == FALSE)
|
||||||
logLastError("error removing Windows control subclass in singleSubclassProc()");
|
logLastError("error removing Windows control subclass in singleSubclassProc()");
|
||||||
break;
|
break;
|
||||||
|
@ -79,6 +88,7 @@ uiControl *uiWindowsNewControl(uiWindowsNewControlParams *p)
|
||||||
if (c->hwnd == NULL)
|
if (c->hwnd == NULL)
|
||||||
logLastError("error creating control in uiWindowsNewControl()");
|
logLastError("error creating control in uiWindowsNewControl()");
|
||||||
|
|
||||||
|
c->control.destroy = singleDestroy;
|
||||||
c->control.handle = singleHandle;
|
c->control.handle = singleHandle;
|
||||||
c->control.setParent = singleSetParent;
|
c->control.setParent = singleSetParent;
|
||||||
c->control.preferredSize = singlePreferredSize;
|
c->control.preferredSize = singlePreferredSize;
|
||||||
|
|
15
new/stack.c
15
new/stack.c
|
@ -17,6 +17,20 @@ struct stack {
|
||||||
|
|
||||||
#define S(c) ((stack *) (c))
|
#define S(c) ((stack *) (c))
|
||||||
|
|
||||||
|
static void stackDestroy(uiControl *c)
|
||||||
|
{
|
||||||
|
stack *s = (stack *) c;
|
||||||
|
uintmax_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < S(c)->len; i++)
|
||||||
|
uiControlDestroy(s->controls[i]);
|
||||||
|
uiFree(s->controls);
|
||||||
|
uiFree(s->stretchy);
|
||||||
|
uiFree(s->width);
|
||||||
|
uiFree(s->height);
|
||||||
|
uiFree(s);
|
||||||
|
}
|
||||||
|
|
||||||
static uintptr_t stackHandle(uiControl *c)
|
static uintptr_t stackHandle(uiControl *c)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -163,6 +177,7 @@ uiControl *uiNewHorizontalStack(void)
|
||||||
|
|
||||||
s = uiNew(stack);
|
s = uiNew(stack);
|
||||||
|
|
||||||
|
s->control.destroy = stackDestroy;
|
||||||
s->control.handle = stackHandle;
|
s->control.handle = stackHandle;
|
||||||
s->control.setParent = stackSetParent;
|
s->control.setParent = stackSetParent;
|
||||||
s->control.preferredSize = stackPreferredSize;
|
s->control.preferredSize = stackPreferredSize;
|
||||||
|
|
3
new/ui.h
3
new/ui.h
|
@ -16,6 +16,9 @@ void uiMain(void);
|
||||||
void uiQuit(void);
|
void uiQuit(void);
|
||||||
|
|
||||||
typedef struct uiControl uiControl;
|
typedef struct uiControl uiControl;
|
||||||
|
// TODO public?
|
||||||
|
void uiControlDestroy(uiControl *);
|
||||||
|
// TODO before destroy?
|
||||||
uintptr_t uiControlHandle(uiControl *);
|
uintptr_t uiControlHandle(uiControl *);
|
||||||
|
|
||||||
typedef struct uiWindow uiWindow;
|
typedef struct uiWindow uiWindow;
|
||||||
|
|
|
@ -12,6 +12,7 @@ struct uiSize {
|
||||||
|
|
||||||
// TODO handle destruction
|
// TODO handle destruction
|
||||||
struct uiControl {
|
struct uiControl {
|
||||||
|
void (*destroy)(uiControl *);
|
||||||
uintptr_t (*handle)(uiControl *);
|
uintptr_t (*handle)(uiControl *);
|
||||||
void (*setParent)(uiControl *, uintptr_t);
|
void (*setParent)(uiControl *, uintptr_t);
|
||||||
uiSize (*preferredSize)(uiControl *, uiSizing *);
|
uiSize (*preferredSize)(uiControl *, uiSizing *);
|
||||||
|
|
|
@ -46,6 +46,8 @@ static LRESULT CALLBACK uiWindowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPA
|
||||||
return 0;
|
return 0;
|
||||||
break; // fall through to DefWindowProcW()
|
break; // fall through to DefWindowProcW()
|
||||||
case WM_DESTROY:
|
case WM_DESTROY:
|
||||||
|
if (w->child != NULL)
|
||||||
|
uiControlDestroy(w->child);
|
||||||
uiFree(w);
|
uiFree(w);
|
||||||
break; // fall through to DefWindowProcW()
|
break; // fall through to DefWindowProcW()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue