diff --git a/TODO.md b/TODO.md index 4c7bd3f5..be62e75c 100644 --- a/TODO.md +++ b/TODO.md @@ -51,7 +51,6 @@ - drop "Page" from uiTab method names? (uiTabAppendPage() -> uiTabAppend()) - override dock menu quit item to act like our app menu quit item - consider calling setAppleMenu: for the application menu; it doesn't seem to make much of a difference but -- we might need to bring ContainerEnable() and ContainerDisable() back because of OS X and Windows :( ultimately: - add some sort of runtime type checking diff --git a/darwin/bin.m b/darwin/bin.m index 7344faa3..2594e842 100644 --- a/darwin/bin.m +++ b/darwin/bin.m @@ -50,6 +50,14 @@ void binPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *heig *height += marginY; } +void binSysFunc(uiControl *c, uiControlSysFuncParams *p) +{ + struct bin *b = (struct bin *) c; + + if (b->mainControl != NULL) + uiControlSysFunc(b->mainControl, p); +} + void binResizeChildren(uiContainer *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d) { struct bin *b = (struct bin *) c; @@ -74,6 +82,7 @@ uiContainer *newBin(void) b->baseDestroy = uiControl(b)->Destroy; uiControl(b)->Destroy = binDestroy; uiControl(b)->PreferredSize = binPreferredSize; + uiControl(b)->SysFunc = binSysFunc; uiContainer(b)->ResizeChildren = binResizeChildren; diff --git a/darwin/container.m b/darwin/container.m index 7cf30a05..10f10a01 100644 --- a/darwin/container.m +++ b/darwin/container.m @@ -131,15 +131,19 @@ static void containerHide(uiControl *cc) static void containerEnable(uiControl *cc) { containerView *c = (containerView *) (cc->Internal); + uiControlSysFuncParams p; - // TODO + p.Func = uiDarwinSysFuncContainerEnable; + uiControlSysFunc(cc, &p); } static void containerDisable(uiControl *cc) { containerView *c = (containerView *) (cc->Internal); + uiControlSysFuncParams p; - // TODO + p.Func = uiDarwinSysFuncContainerDisable; + uiControlSysFunc(cc, &p); } static void containerUpdate(uiContainer *cc) @@ -169,6 +173,7 @@ void uiMakeContainer(uiContainer *cc) uiControl(cc)->Hide = containerHide; uiControl(cc)->Enable = containerEnable; uiControl(cc)->Disable = containerDisable; + // SysFunc() is provided by subclasses // ResizeChildren() is provided by subclasses uiContainer(cc)->Update = containerUpdate; diff --git a/darwin/newcontrol.m b/darwin/newcontrol.m index 4fda0dcf..fd709d94 100644 --- a/darwin/newcontrol.m +++ b/darwin/newcontrol.m @@ -9,6 +9,8 @@ struct singleView { NSView *immediate; // the control that is added to the parent container; either view or scrollView uiContainer *parent; int hidden; + int userDisabled; + int containerDisabled; void (*onDestroy)(void *); void *onDestroyData; }; @@ -112,18 +114,41 @@ static void singleEnable(uiControl *c) { singleView *s = (singleView *) (c->Internal); - if ([s->view respondsToSelector:@selector(setEnabled:)]) - [((NSControl *) (s->view)) setEnabled:YES]; + s->userDisabled = 0; + if (!s->containerDisabled) + if ([s->view respondsToSelector:@selector(setEnabled:)]) + [((NSControl *) (s->view)) setEnabled:YES]; } static void singleDisable(uiControl *c) { singleView *s = (singleView *) (c->Internal); + s->userDisabled = 1; if ([s->view respondsToSelector:@selector(setEnabled:)]) [((NSControl *) (s->view)) setEnabled:NO]; } +static void singleSysFunc(uiControl *c, uiControlSysFuncParams *p) +{ + singleView *s = (singleView *) (c->Internal); + + switch (p->Func) { + case uiDarwinSysFuncContainerEnable: + s->containerDisabled = 0; + if (!s->userDisabled) + if ([s->view respondsToSelector:@selector(setEnabled:)]) + [((NSControl *) (s->view)) setEnabled:YES]; + return; + case uiDarwinSysFuncContainerDisable: + s->containerDisabled = 1; + if ([s->view respondsToSelector:@selector(setEnabled:)]) + [((NSControl *) (s->view)) setEnabled:NO]; + return; + } + complain("unknown p->Func %d in singleSysFunc()", p->Func); +} + void uiDarwinMakeControl(uiControl *c, Class class, BOOL inScrollView, BOOL scrollViewHasBorder, void (*onDestroy)(void *), void *onDestroyData) { singleView *s; @@ -163,4 +188,5 @@ void uiDarwinMakeControl(uiControl *c, Class class, BOOL inScrollView, BOOL scro uiControl(c)->Hide = singleHide; uiControl(c)->Enable = singleEnable; uiControl(c)->Disable = singleDisable; + uiControl(c)->SysFunc = singleSysFunc; } diff --git a/darwin/window.m b/darwin/window.m index 0ae71bbb..9882480f 100644 --- a/darwin/window.m +++ b/darwin/window.m @@ -121,14 +121,14 @@ static void windowEnable(uiControl *c) { struct window *w = (struct window *) c; - // TODO + uiControlEnable(uiControl(w->bin)); } static void windowDisable(uiControl *c) { struct window *w = (struct window *) c; - // TODO + uiControlDisable(uiControl(w->bin)); } static char *windowTitle(uiWindow *ww) diff --git a/ui_darwin.h b/ui_darwin.h index b6ef7ae3..0fa407d7 100644 --- a/ui_darwin.h +++ b/ui_darwin.h @@ -20,4 +20,15 @@ struct uiSizingSys { // this structure currently left blank }; +struct uiControlSysFuncParams { + int Func; +}; + +enum { + // These should enable and disable the uiControl while preserving the user enable/disable setting. + // These are needed because enabling and disabling of views on OS X is available on a view-by-view basis, and is not transitive to subviews by default as a result. + uiDarwinSysFuncContainerEnable, + uiDarwinSysFuncContainerDisable, +}; + #endif