From d7d7d4fd76ccae1cb7801249982eccae3ac9193e Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 25 Apr 2016 18:07:29 -0400 Subject: [PATCH] Fixed the SyncEnableState() machinery not quite working properly. --- darwin/box.m | 2 ++ darwin/control.m | 12 ++++++++++++ darwin/group.m | 2 ++ darwin/window.m | 2 ++ ui_darwin.h | 5 +++++ 5 files changed, 23 insertions(+) diff --git a/darwin/box.m b/darwin/box.m index d4c88a14..35a0ea0f 100644 --- a/darwin/box.m +++ b/darwin/box.m @@ -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; diff --git a/darwin/control.m b/darwin/control.m index cb847d7e..81a971fd 100644 --- a/darwin/control.m +++ b/darwin/control.m @@ -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; +} diff --git a/darwin/group.m b/darwin/group.m index c5f876e4..f67036be 100644 --- a/darwin/group.m +++ b/darwin/group.m @@ -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); } diff --git a/darwin/window.m b/darwin/window.m index 1c66f52c..c3160f76 100644 --- a/darwin/window.m +++ b/darwin/window.m @@ -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); } diff --git a/ui_darwin.h b/ui_darwin.h index 8f74fd11..ffd47896 100644 --- a/ui_darwin.h +++ b/ui_darwin.h @@ -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