From 2ff913cd588abd53984bf53ec8f6bbcc3627e2b2 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 18 May 2015 22:02:37 -0400 Subject: [PATCH] Started splitting the shared control code into portable and non-portable files. This handles the portable part; the non-portable part comes next. --- TODO.md | 1 + redo/control.c | 175 +++++++++++++++++++++++++++++++++++++++++++++++++ redo/uipriv.h | 14 +++- 3 files changed, 189 insertions(+), 1 deletion(-) create mode 100644 redo/control.c diff --git a/TODO.md b/TODO.md index d6e8f87e..53d531e7 100644 --- a/TODO.md +++ b/TODO.md @@ -1,3 +1,4 @@ +- make the various onDestroy() functions take the uiControl instead - make sure all calls to uiControlResize() are preceded with calls to uiControlGetSizing() - require explicit calls to uiContainerUpdate() everywhere, because sigh... diff --git a/redo/control.c b/redo/control.c new file mode 100644 index 00000000..bd84183a --- /dev/null +++ b/redo/control.c @@ -0,0 +1,175 @@ +// 6 april 2015 +#include "uipriv_windows.h" + +struct singleControl { + void *internal; + uiControl *parent; + int userHidden; + int containerHidden; + int userDisabled; + int containerDisabled; +}; + +static void singleDestroy(uiControl *c) +{ + struct singleControl *s = (struct singleControl *) (c->Internal); + + if (s->parent != NULL) + complain("attempt to destroy a uiControl at %p while it still has a parent", c); + osOnDestroy(s->internal); + uiFree(s); +} + +static uintptr_t singleHandle(uiControl *c) +{ + struct singleControl *s = (struct singleControl *) (c->Internal); + + return osSingleHandle(s->internal); +} + +static uiControl *singleParent(uiControl *c) +{ + struct singleControl *s = (struct singleControl *) (c->Internal); + + return s->parent; +} + +static void singleSetParent(uiControl *c, uiControl *parent) +{ + struct singleControl *s = (struct singleControl *) (c->Internal); + uiControl *oldparent; + + oldparent = s->parent; + s->parent = parent; + osSingleSetParent(s->internal, oldparent, s->parent); +} + +static void singleResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d) +{ + struct singleControl *s = (struct singleControl *) (c->Internal); + + osSingleResize(s->internal, x, y, width, height, d); +} + +static void singleQueueResize(uiControl *c) +{ + queueResize(c); +} + +static uiSizing *singleSizing(uiControl *c) +{ + struct singleControl *s = (struct singleControl *) (c->Internal); + + return osSingleSizing(s->internal, c); +} + +static int singleContainerVisible(uiControl *c) +{ + struct singleControl *s = (struct singleControl *) (c->Internal); + + return !s->userHidden && !s->containerHidden; +} + +static void singleShow(uiControl *c) +{ + struct singleControl *s = (struct singleControl *) (c->Internal); + + s->userHidden = 0; + if (!s->containerHidden) + osSingleShow(s->internal); + if (s->parent != NULL) + uiControlQueueResize(s->parent); +} + +static void singleHide(uiControl *c) +{ + struct singleControl *s = (struct singleControl *) (c->Internal); + + s->userHidden = 1; + osSingleHide(s->internal); + if (s->parent != NULL) + uiControlQueueResize(s->parent); +} + +static void singleContainerShow(uiControl *c) +{ + struct singleControl *s = (struct singleControl *) (c->Internal); + + s->containerHidden = 0; + if (!s->userHidden) + osSingleShow(s->internal); + if (s->parent != NULL) + uiControlQueueResize(s->parent); +} + +static void singleContainerHide(uiControl *c) +{ + struct singleControl *s = (struct singleControl *) (c->Internal); + + s->containerHidden = 1; + osSingleHide(s->internal); + if (s->parent != NULL) + uiControlQueueResize(s->parent); +} + +static void singleEnable(uiControl *c) +{ + struct singleControl *s = (struct singleControl *) (c->Internal); + + s->userDisabled = 0; + if (!s->containerDisabled) + osSingleEnable(s->internal); +} + +static void singleDisable(uiControl *c) +{ + struct singleControl *s = (struct singleControl *) (c->Internal); + + s->userDisabled = 1; + osSingleDisable(s->internal); +} + +static void singleContainerEnable(uiControl *c) +{ + struct singleControl *s = (struct singleControl *) (c->Internal); + + s->containerDisabled = 0; + if (!s->userDisabled) + osSingleEnable(s->internal); +} + +static void singleContainerDisable(uiControl *c) +{ + struct singleControl *s = (struct singleControl *) (c->Internal); + + s->containerDisabled = 1; + osSingleDisable(s->internal); +} + +void makeControl(uiControl *c, void *internal) +{ + struct singleControl *s; + + s = uiNew(struct singleControl); + + s->internal = internal; + + uiControl(c)->Internal = s; + uiControl(c)->Destroy = singleDestroy; + uiControl(c)->Handle = singleHandle; + uiControl(c)->Parent = singleParent; + uiControl(c)->SetParent = singleSetParent; + // PreferredSize() implemented by the individual controls + uiControl(c)->Resize = singleResize; + uiControl(c)->QueueResize = singleQueueResize; + uiControl(c)->Sizing = singleSizing; + uiControl(c)->ContainerVisible = singleContainerVisible; + uiControl(c)->Show = singleShow; + uiControl(c)->Hide = singleHide; + uiControl(c)->ContainerShow = singleContainerShow; + uiControl(c)->ContainerHide = singleContainerHide; + uiControl(c)->Enable = singleEnable; + uiControl(c)->Disable = singleDisable; + uiControl(c)->ContainerEnable = singleContainerEnable; + uiControl(c)->ContainerDisable = singleContainerDisable; +} diff --git a/redo/uipriv.h b/redo/uipriv.h index 66462db4..a0cc516c 100644 --- a/redo/uipriv.h +++ b/redo/uipriv.h @@ -10,7 +10,7 @@ extern void uiFree(void *); extern void complain(const char *, ...); -// array.c +// ptrarray.c struct ptrArray { void **ptrs; uintmax_t len; @@ -25,3 +25,15 @@ void ptrArrayDelete(struct ptrArray *, uintmax_t); // shouldquit.c int shouldQuit(void); + +// control.c +extern void osSingleDestroy(void *); +extern uintptr_t osSingleHandle(void *); +extern void osSingleSetParent(void *, uiControl *, uiControl *); +extern void osSingleResize(void *, intmax_t, intmax_t, intmax_t, intmax_t, uiSizing *); +extern uiSizing *osSingleSizing(void *, uiControl *); +extern void osSingleShow(void *); +extern void osSingleHide(void *); +extern void osSingleEnable(void *); +extern void osSingleDisable(void *); +extern void makeControl(uiControl *, void *);