From d54f7dd6827411993e8eb59aec1cd00abf9c0fae Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 14 Jun 2016 10:37:19 -0400 Subject: [PATCH] Added a facility to the OS X port to be notified when a child's visibility has changed; this is necessary for implementing hiding and showing properly. --- darwin/box.m | 7 +++++++ darwin/control.m | 14 ++++++++++++++ darwin/form.m | 7 +++++++ darwin/grid.m | 7 +++++++ darwin/group.m | 7 +++++++ darwin/tab.m | 7 +++++++ darwin/window.m | 7 +++++++ test/page11.c | 1 + ui_darwin.h | 16 ++++++++++++++-- 9 files changed, 71 insertions(+), 2 deletions(-) diff --git a/darwin/box.m b/darwin/box.m index 4b688e65..aefd17aa 100644 --- a/darwin/box.m +++ b/darwin/box.m @@ -396,6 +396,13 @@ static void uiBoxChildEdgeHuggingChanged(uiDarwinControl *c) uiDarwinControlDefaultHuggingPriority(uiBox, view) uiDarwinControlDefaultSetHuggingPriority(uiBox, view) +static void uiBoxChildVisibilityChanged(uiDarwinControl *c) +{ + uiBox *b = uiBox(c); + + [b->view establishOurConstraints]; +} + void uiBoxAppend(uiBox *b, uiControl *c, int stretchy) { // LONGTERM on other platforms diff --git a/darwin/control.m b/darwin/control.m index 4451ee9a..9eaf47a2 100644 --- a/darwin/control.m +++ b/darwin/control.m @@ -36,6 +36,11 @@ void uiDarwinControlSetHuggingPriority(uiDarwinControl *c, NSLayoutPriority prio (*(c->SetHuggingPriority))(c, priority, orientation); } +void uiDarwinControlChildVisibilityChanged(uiDarwinControl *c) +{ + (*(c->ChildVisibilityChanged))(c); +} + void uiDarwinSetControlFont(NSControl *c, NSControlSize size) { [c setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:size]]]; @@ -68,3 +73,12 @@ void uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl *c) if (parent != NULL) uiDarwinControlChildEdgeHuggingChanged(uiDarwinControl(parent)); } + +void uiDarwinNotifyVisibilityChanged(uiDarwinControl *c) +{ + uiControl *parent; + + parent = uiControlParent(uiControl(c)); + if (parent != NULL) + uiDarwinControlChildVisibilityChanged(uiDarwinControl(parent)); +} diff --git a/darwin/form.m b/darwin/form.m index acc33a3e..75edf23a 100644 --- a/darwin/form.m +++ b/darwin/form.m @@ -476,6 +476,13 @@ static void uiFormChildEdgeHuggingChanged(uiDarwinControl *c) uiDarwinControlDefaultHuggingPriority(uiForm, view) uiDarwinControlDefaultSetHuggingPriority(uiForm, view) +static void uiFormChildVisibilityChanged(uiDarwinControl *c) +{ + uiForm *f = uiForm(c); + + [f->view establishOurConstraints]; +} + void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy) { // LONGTERM on other platforms diff --git a/darwin/grid.m b/darwin/grid.m index 40021a00..b6d6a513 100644 --- a/darwin/grid.m +++ b/darwin/grid.m @@ -590,6 +590,13 @@ static void uiGridChildEdgeHuggingChanged(uiDarwinControl *c) uiDarwinControlDefaultHuggingPriority(uiGrid, view) uiDarwinControlDefaultSetHuggingPriority(uiGrid, view) +static void uiGridChildVisibilityChanged(uiDarwinControl *c) +{ + uiGrid *g = uiGrid(c); + + [g->view establishOurConstraints]; +} + static gridChild *toChild(uiControl *c, int xspan, int yspan, int hexpand, uiAlign halign, int vexpand, uiAlign valign) { gridChild *gc; diff --git a/darwin/group.m b/darwin/group.m index 8dba62c3..0050bbdd 100644 --- a/darwin/group.m +++ b/darwin/group.m @@ -117,6 +117,13 @@ static void uiGroupSetHuggingPriority(uiDarwinControl *c, NSLayoutPriority prior uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(g)); } +static void uiGroupChildVisibilityChanged(uiDarwinControl *c) +{ + uiGroup *g = uiGroup(c); + + groupRelayout(g); +} + char *uiGroupTitle(uiGroup *g) { return uiDarwinNSStringToText([g->box title]); diff --git a/darwin/tab.m b/darwin/tab.m index 0d03f3e6..3d2ca9f0 100644 --- a/darwin/tab.m +++ b/darwin/tab.m @@ -180,6 +180,13 @@ static void uiTabSetHuggingPriority(uiDarwinControl *c, NSLayoutPriority priorit uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(t)); } +static void uiTabChildVisibilityChanged(uiDarwinControl *c) +{ + uiTab *t = uiTab(c); + + tabRelayout(t); +} + void uiTabAppend(uiTab *t, const char *name, uiControl *child) { uiTabInsertAt(t, name, [t->pages count], child); diff --git a/darwin/window.m b/darwin/window.m index 2d8d2e45..ffb6b30d 100644 --- a/darwin/window.m +++ b/darwin/window.m @@ -187,6 +187,13 @@ uiDarwinControlDefaultHuggingPriority(uiWindow, window) uiDarwinControlDefaultSetHuggingPriority(uiWindow, window) // end TODO +static void uiWindowChildVisibilityChanged(uiDarwinControl *c) +{ + uiWindow *w = uiWindow(c); + + windowRelayout(w); +} + char *uiWindowTitle(uiWindow *w) { return uiDarwinNSStringToText([w->window title]); diff --git a/test/page11.c b/test/page11.c index cbe3d6cd..02ad213a 100644 --- a/test/page11.c +++ b/test/page11.c @@ -2,6 +2,7 @@ #include "test.h" // TODO add a test for childless windows +// TODO add tests for contianers with all controls hidden static uiGroup *newg(const char *n, int s) { diff --git a/ui_darwin.h b/ui_darwin.h index 81e71f2c..c9c6ad54 100644 --- a/ui_darwin.h +++ b/ui_darwin.h @@ -24,6 +24,7 @@ struct uiDarwinControl { void (*ChildEdgeHuggingChanged)(uiDarwinControl *); NSLayoutPriority (*HuggingPriority)(uiDarwinControl *, NSLayoutConstraintOrientation); void (*SetHuggingPriority)(uiDarwinControl *, NSLayoutPriority, NSLayoutConstraintOrientation); + void (*ChildVisibilityChanged)(uiDarwinControl *); }; #define uiDarwinControl(this) ((uiDarwinControl *) (this)) // TODO document @@ -34,6 +35,7 @@ _UI_EXTERN BOOL uiDarwinControlHugsBottom(uiDarwinControl *); _UI_EXTERN void uiDarwinControlChildEdgeHuggingChanged(uiDarwinControl *); _UI_EXTERN NSLayoutPriority uiDarwinControlHuggingPriority(uiDarwinControl *, NSLayoutConstraintOrientation); _UI_EXTERN void uiDarwinControlSetHuggingPriority(uiDarwinControl *, NSLayoutPriority, NSLayoutConstraintOrientation); +_UI_EXTERN void uiDarwinControlChildVisibilityChanged(uiDarwinControl *); #define uiDarwinControlDefaultDestroy(type, handlefield) \ static void type ## Destroy(uiControl *c) \ @@ -72,12 +74,14 @@ _UI_EXTERN void uiDarwinControlSetHuggingPriority(uiDarwinControl *, NSLayoutPri { \ uiDarwinControl(c)->visible = YES; \ [type(c)->handlefield setHidden:NO]; \ + uiDarwinNotifyVisibilityChanged(uiDarwinControl(c)); \ } #define uiDarwinControlDefaultHide(type, handlefield) \ static void type ## Hide(uiControl *c) \ { \ uiDarwinControl(c)->visible = NO; \ [type(c)->handlefield setHidden:YES]; \ + uiDarwinNotifyVisibilityChanged(uiDarwinControl(c)); \ } #define uiDarwinControlDefaultEnabled(type, handlefield) \ static int type ## Enabled(uiControl *c) \ @@ -102,7 +106,7 @@ _UI_EXTERN void uiDarwinControlSetHuggingPriority(uiDarwinControl *, NSLayoutPri 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 */ \ + [((id) (type(c)->handlefield)) setEnabled:enabled]; /* id cast to make compiler happy; thanks mikeash in irc.freenode.net/#macdev */ \ } #define uiDarwinControlDefaultSetSuperview(type, handlefield) \ static void type ## SetSuperview(uiDarwinControl *c, NSView *superview) \ @@ -138,6 +142,11 @@ _UI_EXTERN void uiDarwinControlSetHuggingPriority(uiDarwinControl *, NSLayoutPri { \ [type(c)->handlefield setContentHuggingPriority:priority forOrientation:orientation]; \ } +#define uiDarwinControlDefaultChildVisibilityChanged(type, handlefield) \ + static void type ## ChildVisibilityChanged(uiDarwinControl *c) \ + { \ + /* do nothing */ \ + } #define uiDarwinControlAllDefaultsExceptDestroy(type, handlefield) \ uiDarwinControlDefaultHandle(type, handlefield) \ @@ -156,7 +165,8 @@ _UI_EXTERN void uiDarwinControlSetHuggingPriority(uiDarwinControl *, NSLayoutPri uiDarwinControlDefaultHugsBottom(type, handlefield) \ uiDarwinControlDefaultChildEdgeHuggingChanged(type, handlefield) \ uiDarwinControlDefaultHuggingPriority(type, handlefield) \ - uiDarwinControlDefaultSetHuggingPriority(type, handlefield) + uiDarwinControlDefaultSetHuggingPriority(type, handlefield) \ + uiDarwinControlDefaultChildVisibilityChanged(type, handlefield) #define uiDarwinControlAllDefaults(type, handlefield) \ uiDarwinControlDefaultDestroy(type, handlefield) \ @@ -183,6 +193,7 @@ _UI_EXTERN void uiDarwinControlSetHuggingPriority(uiDarwinControl *, NSLayoutPri uiDarwinControl(var)->ChildEdgeHuggingChanged = type ## ChildEdgeHuggingChanged; \ uiDarwinControl(var)->HuggingPriority = type ## HuggingPriority; \ uiDarwinControl(var)->SetHuggingPriority = type ## SetHuggingPriority; \ + uiDarwinControl(var)->ChildVisibilityChanged = type ## ChildVisibilityChanged; \ uiDarwinControl(var)->visible = YES; \ uiDarwinControl(var)->enabled = YES; // TODO document @@ -199,6 +210,7 @@ _UI_EXTERN BOOL uiDarwinShouldStopSyncEnableState(uiDarwinControl *, BOOL); // TODO document _UI_EXTERN void uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl *); +_UI_EXTERN void uiDarwinNotifyVisibilityChanged(uiDarwinControl *c); // TODO document // TODO document that values should not be cached