Fixed the SyncEnableState() machinery not quite working properly.

This commit is contained in:
Pietro Gagliardi 2016-04-25 18:07:29 -04:00
parent 7b0780be2a
commit d7d7d4fd76
5 changed files with 23 additions and 0 deletions

View File

@ -70,6 +70,8 @@ static void uiBoxSyncEnableState(uiDarwinControl *c, int enabled)
uiBox *b = uiBox(c);
NSUInteger i;
if (uiDarwinShouldStopSyncEnableState(uiDarwinControl(b), enabled))
return;
for (i = 0; i < [b->children count]; i++) {
NSValue *v;
uiControl *child;

View File

@ -22,3 +22,15 @@ uiDarwinControl *uiDarwinAllocControl(size_t n, uint32_t typesig, const char *ty
{
return uiDarwinControl(uiAllocControl(n, uiDarwinControlSignature, typesig, typenamestr));
}
BOOL uiDarwinShouldStopSyncEnableState(uiDarwinControl *c, BOOL enabled)
{
int ce;
ce = uiControlEnabled(uiControl(c));
// only stop if we're going from disabled back to enabled; don't stop under any other condition
// (if we stop when going from enabled to disabled then enabled children of a disabled control won't get disabled at the OS level)
if (!ce && enabled)
return YES;
return NO;
}

View File

@ -35,6 +35,8 @@ static void uiGroupSyncEnableState(uiDarwinControl *c, int enabled)
{
uiGroup *g = uiGroup(c);
if (uiDarwinShouldStopSyncEnableState(uiDarwinControl(g), enabled))
return;
if (g->child != NULL)
uiDarwinControlSyncEnableState(uiDarwinControl(g->child), enabled);
}

View File

@ -130,6 +130,8 @@ static void uiWindowSyncEnableState(uiDarwinControl *c, int enabled)
{
uiWindow *w = uiWindow(c);
if (uiDarwinShouldStopSyncEnableState(uiDarwinControl(w), enabled))
return;
if (w->child != NULL)
uiDarwinControlSyncEnableState(uiDarwinControl(w->child), enabled);
}

View File

@ -90,6 +90,8 @@ _UI_EXTERN void uiDarwinControlSetSuperview(uiDarwinControl *, NSView *);
#define uiDarwinControlDefaultSyncEnableState(type, handlefield) \
static void type ## SyncEnableState(uiDarwinControl *c, int enabled) \
{ \
if (uiDarwinShouldStopSyncEnableState(c, enabled)) \
return; \
if ([type(c)->handlefield respondsToSelector:@selector(setEnabled:)]) \
[((id) type(c)->handlefield) setEnabled:enabled]; /* id cast to make compiler happy; thanks mikeash in irc.freenode.net/#macdev */ \
}
@ -148,6 +150,9 @@ _UI_EXTERN void uiDarwinSetControlFont(NSControl *c, NSControlSize size);
// You can use this function from within your control implementations to return text strings that can be freed with uiFreeText().
_UI_EXTERN char *uiDarwinNSStringToText(NSString *);
// TODO document
_UI_EXTERN BOOL uiDarwinShouldStopSyncEnableState(uiDarwinControl *, BOOL);
#ifdef __cplusplus
}
#endif