Implemented uiControlEnable() and uiControlDisable() for containers and uiWIndow on Mac OS X.

This commit is contained in:
Pietro Gagliardi 2015-05-04 01:14:18 -04:00
parent d237449060
commit d23fae34be
6 changed files with 57 additions and 7 deletions

View File

@ -51,7 +51,6 @@
- drop "Page" from uiTab method names? (uiTabAppendPage() -> uiTabAppend()) - drop "Page" from uiTab method names? (uiTabAppendPage() -> uiTabAppend())
- override dock menu quit item to act like our app menu quit item - 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 - 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: ultimately:
- add some sort of runtime type checking - add some sort of runtime type checking

View File

@ -50,6 +50,14 @@ void binPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *heig
*height += marginY; *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) void binResizeChildren(uiContainer *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
{ {
struct bin *b = (struct bin *) c; struct bin *b = (struct bin *) c;
@ -74,6 +82,7 @@ uiContainer *newBin(void)
b->baseDestroy = uiControl(b)->Destroy; b->baseDestroy = uiControl(b)->Destroy;
uiControl(b)->Destroy = binDestroy; uiControl(b)->Destroy = binDestroy;
uiControl(b)->PreferredSize = binPreferredSize; uiControl(b)->PreferredSize = binPreferredSize;
uiControl(b)->SysFunc = binSysFunc;
uiContainer(b)->ResizeChildren = binResizeChildren; uiContainer(b)->ResizeChildren = binResizeChildren;

View File

@ -131,15 +131,19 @@ static void containerHide(uiControl *cc)
static void containerEnable(uiControl *cc) static void containerEnable(uiControl *cc)
{ {
containerView *c = (containerView *) (cc->Internal); containerView *c = (containerView *) (cc->Internal);
uiControlSysFuncParams p;
// TODO p.Func = uiDarwinSysFuncContainerEnable;
uiControlSysFunc(cc, &p);
} }
static void containerDisable(uiControl *cc) static void containerDisable(uiControl *cc)
{ {
containerView *c = (containerView *) (cc->Internal); containerView *c = (containerView *) (cc->Internal);
uiControlSysFuncParams p;
// TODO p.Func = uiDarwinSysFuncContainerDisable;
uiControlSysFunc(cc, &p);
} }
static void containerUpdate(uiContainer *cc) static void containerUpdate(uiContainer *cc)
@ -169,6 +173,7 @@ void uiMakeContainer(uiContainer *cc)
uiControl(cc)->Hide = containerHide; uiControl(cc)->Hide = containerHide;
uiControl(cc)->Enable = containerEnable; uiControl(cc)->Enable = containerEnable;
uiControl(cc)->Disable = containerDisable; uiControl(cc)->Disable = containerDisable;
// SysFunc() is provided by subclasses
// ResizeChildren() is provided by subclasses // ResizeChildren() is provided by subclasses
uiContainer(cc)->Update = containerUpdate; uiContainer(cc)->Update = containerUpdate;

View File

@ -9,6 +9,8 @@ struct singleView {
NSView *immediate; // the control that is added to the parent container; either view or scrollView NSView *immediate; // the control that is added to the parent container; either view or scrollView
uiContainer *parent; uiContainer *parent;
int hidden; int hidden;
int userDisabled;
int containerDisabled;
void (*onDestroy)(void *); void (*onDestroy)(void *);
void *onDestroyData; void *onDestroyData;
}; };
@ -112,18 +114,41 @@ static void singleEnable(uiControl *c)
{ {
singleView *s = (singleView *) (c->Internal); singleView *s = (singleView *) (c->Internal);
if ([s->view respondsToSelector:@selector(setEnabled:)]) s->userDisabled = 0;
[((NSControl *) (s->view)) setEnabled:YES]; if (!s->containerDisabled)
if ([s->view respondsToSelector:@selector(setEnabled:)])
[((NSControl *) (s->view)) setEnabled:YES];
} }
static void singleDisable(uiControl *c) static void singleDisable(uiControl *c)
{ {
singleView *s = (singleView *) (c->Internal); singleView *s = (singleView *) (c->Internal);
s->userDisabled = 1;
if ([s->view respondsToSelector:@selector(setEnabled:)]) if ([s->view respondsToSelector:@selector(setEnabled:)])
[((NSControl *) (s->view)) setEnabled:NO]; [((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) void uiDarwinMakeControl(uiControl *c, Class class, BOOL inScrollView, BOOL scrollViewHasBorder, void (*onDestroy)(void *), void *onDestroyData)
{ {
singleView *s; singleView *s;
@ -163,4 +188,5 @@ void uiDarwinMakeControl(uiControl *c, Class class, BOOL inScrollView, BOOL scro
uiControl(c)->Hide = singleHide; uiControl(c)->Hide = singleHide;
uiControl(c)->Enable = singleEnable; uiControl(c)->Enable = singleEnable;
uiControl(c)->Disable = singleDisable; uiControl(c)->Disable = singleDisable;
uiControl(c)->SysFunc = singleSysFunc;
} }

View File

@ -121,14 +121,14 @@ static void windowEnable(uiControl *c)
{ {
struct window *w = (struct window *) c; struct window *w = (struct window *) c;
// TODO uiControlEnable(uiControl(w->bin));
} }
static void windowDisable(uiControl *c) static void windowDisable(uiControl *c)
{ {
struct window *w = (struct window *) c; struct window *w = (struct window *) c;
// TODO uiControlDisable(uiControl(w->bin));
} }
static char *windowTitle(uiWindow *ww) static char *windowTitle(uiWindow *ww)

View File

@ -20,4 +20,15 @@ struct uiSizingSys {
// this structure currently left blank // 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 #endif