From 997c8aac357a1d87d449379f655d1fb2016669e0 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Tue, 14 Jun 2016 15:55:24 -0400 Subject: [PATCH] Implemented visibility change detection on Windows. Now to refine the actual implementation of hidden controls. --- README.md | 2 ++ doc/form | 1 + ui_windows.h | 16 +++++++++++++++- windows/box.cpp | 6 ++++++ windows/control.cpp | 13 +++++++++++++ windows/form.cpp | 6 ++++++ windows/grid.cpp | 6 ++++++ windows/group.cpp | 6 ++++++ windows/tab.cpp | 6 ++++++ windows/window.cpp | 6 ++++++ 10 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 doc/form diff --git a/README.md b/README.md index 04fa0104..445b3ce3 100644 --- a/README.md +++ b/README.md @@ -20,6 +20,8 @@ This README is being written.
* **14 June 2016** * uiDarwinControl now has a `ChildVisibilityChanged()` method and a corresponding `NotifyVisibilityChanged()` function that is called by the default show/hide handlers. This is used to make visibility changes work on OS X; uiBox, uiForm, and uiGrid all respect these now. + * The same has been done on the Windows side as well. + * Hiding a control in a uiForm now hides its label on all platforms. * **13 June 2016** * `intmax_t` and `uintmax_t` are no longer used for libui API functions; now we use `int`. This should make things much easier for bindings. `int` should be at least 32 bits wide; this should be sufficient for all but the most extreme cases. diff --git a/doc/form b/doc/form new file mode 100644 index 00000000..f24a94dc --- /dev/null +++ b/doc/form @@ -0,0 +1 @@ +hiding a control also hides its label diff --git a/ui_windows.h b/ui_windows.h index 3ea511c9..69dda366 100644 --- a/ui_windows.h +++ b/ui_windows.h @@ -26,6 +26,7 @@ struct uiWindowsControl { void (*MinimumSizeChanged)(uiWindowsControl *); void (*LayoutRect)(uiWindowsControl *c, RECT *r); void (*AssignControlIDZOrder)(uiWindowsControl *, LONG_PTR *, HWND *); + void (*ChildVisibilityChanged)(uiWindowsControl *); }; #define uiWindowsControl(this) ((uiWindowsControl *) (this)) // TODO document @@ -35,6 +36,7 @@ _UI_EXTERN void uiWindowsControlMinimumSize(uiWindowsControl *, int *, int *); _UI_EXTERN void uiWindowsControlMinimumSizeChanged(uiWindowsControl *); _UI_EXTERN void uiWindowsControlLayoutRect(uiWindowsControl *, RECT *); _UI_EXTERN void uiWindowsControlAssignControlIDZOrder(uiWindowsControl *, LONG_PTR *, HWND *); +_UI_EXTERN void uiWindowsControlChildVisibilityChanged(uiWindowsControl *); // TODO document #define uiWindowsControlDefaultDestroy(type) \ @@ -74,12 +76,14 @@ _UI_EXTERN void uiWindowsControlAssignControlIDZOrder(uiWindowsControl *, LONG_P { \ uiWindowsControl(c)->visible = 1; \ ShowWindow(type(c)->hwnd, SW_SHOW); \ + uiWindowsControlNotifyVisibilityChanged(uiWindowsControl(c)); \ } #define uiWindowsControlDefaultHide(type) \ static void type ## Hide(uiControl *c) \ { \ uiWindowsControl(c)->visible = 0; \ ShowWindow(type(c)->hwnd, SW_HIDE); \ + uiWindowsControlNotifyVisibilityChanged(uiWindowsControl(c)); \ } #define uiWindowsControlDefaultEnabled(type) \ static int type ## Enabled(uiControl *c) \ @@ -131,6 +135,11 @@ _UI_EXTERN void uiWindowsControlAssignControlIDZOrder(uiWindowsControl *, LONG_P { \ uiWindowsEnsureAssignControlIDZOrder(type(c)->hwnd, controlID, insertAfter); \ } +#define uiWindowsControlDefaultChildVisibilityChanged(type) \ + static void type ## ChildVisibilityChanged(uiWindowsControl *c) \ + { \ + /* do nothing */ \ + } #define uiWindowsControlAllDefaultsExceptDestroy(type) \ uiWindowsControlDefaultHandle(type) \ @@ -147,7 +156,8 @@ _UI_EXTERN void uiWindowsControlAssignControlIDZOrder(uiWindowsControl *, LONG_P uiWindowsControlDefaultSetParentHWND(type) \ uiWindowsControlDefaultMinimumSizeChanged(type) \ uiWindowsControlDefaultLayoutRect(type) \ - uiWindowsControlDefaultAssignControlIDZOrder(type) + uiWindowsControlDefaultAssignControlIDZOrder(type) \ + uiWindowsControlDefaultChildVisibilityChanged(type) #define uiWindowsControlAllDefaults(type) \ uiWindowsControlDefaultDestroy(type) \ @@ -173,6 +183,7 @@ _UI_EXTERN void uiWindowsControlAssignControlIDZOrder(uiWindowsControl *, LONG_P uiWindowsControl(var)->MinimumSizeChanged = type ## MinimumSizeChanged; \ uiWindowsControl(var)->LayoutRect = type ## LayoutRect; \ uiWindowsControl(var)->AssignControlIDZOrder = type ## AssignControlIDZOrder; \ + uiWindowsControl(var)->ChildVisibilityChanged = type ## ChildVisibilityChanged; \ uiWindowsControl(var)->visible = 1; \ uiWindowsControl(var)->enabled = 1; // TODO document @@ -246,6 +257,9 @@ _UI_EXTERN void uiWindowsControlAssignSoleControlIDZOrder(uiWindowsControl *); // TODO document _UI_EXTERN BOOL uiWindowsShouldStopSyncEnableState(uiWindowsControl *c, int enabled); +// TODO document +_UI_EXTERN void uiWindowsControlNotifyVisibilityChanged(uiWindowsControl *c); + #ifdef __cplusplus } #endif diff --git a/windows/box.cpp b/windows/box.cpp index d87f73e2..334f20f2 100644 --- a/windows/box.cpp +++ b/windows/box.cpp @@ -226,6 +226,12 @@ static void uiBoxMinimumSizeChanged(uiWindowsControl *c) uiWindowsControlDefaultLayoutRect(uiBox) uiWindowsControlDefaultAssignControlIDZOrder(uiBox) +static void uiBoxChildVisibilityChanged(uiWindowsControl *c) +{ + // TODO eliminate the redundancy + uiWindowsControlMinimumSizeChanged(c); +} + static void boxArrangeChildren(uiBox *b) { LONG_PTR controlID; diff --git a/windows/control.cpp b/windows/control.cpp index d59132b9..ce953cf9 100644 --- a/windows/control.cpp +++ b/windows/control.cpp @@ -21,6 +21,7 @@ void uiWindowsControlMinimumSizeChanged(uiWindowsControl *c) (*(c->MinimumSizeChanged))(c); } +// TODO get rid of this void uiWindowsControlLayoutRect(uiWindowsControl *c, RECT *r) { (*(c->LayoutRect))(c, r); @@ -31,6 +32,11 @@ void uiWindowsControlAssignControlIDZOrder(uiWindowsControl *c, LONG_PTR *contro (*(c->AssignControlIDZOrder))(c, controlID, insertAfter); } +void uiWindowsControlChildVisibilityChanged(uiWindowsControl *c) +{ + (*(c->ChildVisibilityChanged))(c); +} + HWND uiWindowsEnsureCreateControlHWND(DWORD dwExStyle, LPCWSTR lpClassName, LPCWSTR lpWindowName, DWORD dwStyle, HINSTANCE hInstance, LPVOID lpParam, BOOL useStandardControlFont) { HWND hwnd; @@ -106,3 +112,10 @@ void uiWindowsControlContinueMinimumSizeChanged(uiWindowsControl *c) if (parent != NULL) uiWindowsControlMinimumSizeChanged(uiWindowsControl(parent)); } + +// TODO rename this nad the OS X this and hugging ones to NotifyChild +void uiWindowsControlNotifyVisibilityChanged(uiWindowsControl *c) +{ + // TODO we really need to figure this out; the duplication is a mess + uiWindowsControlContinueMinimumSizeChanged(c); +} diff --git a/windows/form.cpp b/windows/form.cpp index e15e9571..6c91834e 100644 --- a/windows/form.cpp +++ b/windows/form.cpp @@ -222,6 +222,12 @@ static void uiFormMinimumSizeChanged(uiWindowsControl *c) uiWindowsControlDefaultLayoutRect(uiForm) uiWindowsControlDefaultAssignControlIDZOrder(uiForm) +static void uiFormChildVisibilityChanged(uiWindowsControl *c) +{ + // TODO eliminate the redundancy + uiWindowsControlMinimumSizeChanged(c); +} + static void formArrangeChildren(uiForm *f) { LONG_PTR controlID; diff --git a/windows/grid.cpp b/windows/grid.cpp index bcf89980..280f6344 100644 --- a/windows/grid.cpp +++ b/windows/grid.cpp @@ -422,6 +422,12 @@ static void uiGridMinimumSizeChanged(uiWindowsControl *c) uiWindowsControlDefaultLayoutRect(uiGrid) uiWindowsControlDefaultAssignControlIDZOrder(uiGrid) +static void uiGridChildVisibilityChanged(uiWindowsControl *c) +{ + // TODO eliminate the redundancy + uiWindowsControlMinimumSizeChanged(c); +} + // must have called gridRecomputeMinMax() first static void gridArrangeChildren(uiGrid *g) { diff --git a/windows/group.cpp b/windows/group.cpp index 9e2cf6e1..8824c5a4 100644 --- a/windows/group.cpp +++ b/windows/group.cpp @@ -121,6 +121,12 @@ static void uiGroupMinimumSizeChanged(uiWindowsControl *c) uiWindowsControlDefaultLayoutRect(uiGroup) uiWindowsControlDefaultAssignControlIDZOrder(uiGroup) +static void uiGroupChildVisibilityChanged(uiWindowsControl *c) +{ + // TODO eliminate the redundancy + uiWindowsControlMinimumSizeChanged(c); +} + char *uiGroupTitle(uiGroup *g) { return uiWindowsWindowText(g->hwnd); diff --git a/windows/tab.cpp b/windows/tab.cpp index 2af2bff3..365f5a1f 100644 --- a/windows/tab.cpp +++ b/windows/tab.cpp @@ -166,6 +166,12 @@ static void uiTabMinimumSizeChanged(uiWindowsControl *c) uiWindowsControlDefaultLayoutRect(uiTab) uiWindowsControlDefaultAssignControlIDZOrder(uiTab) +static void uiTabChildVisibilityChanged(uiWindowsControl *c) +{ + // TODO eliminate the redundancy + uiWindowsControlMinimumSizeChanged(c); +} + static void tabArrangePages(uiTab *t) { LONG_PTR controlID = 100; diff --git a/windows/window.cpp b/windows/window.cpp index 0edd7183..411cb86e 100644 --- a/windows/window.cpp +++ b/windows/window.cpp @@ -260,6 +260,12 @@ static void uiWindowLayoutRect(uiWindowsControl *c, RECT *r) uiWindowsControlDefaultAssignControlIDZOrder(uiWindow) +static void uiWindowChildVisibilityChanged(uiWindowsControl *c) +{ + // TODO eliminate the redundancy + uiWindowsControlMinimumSizeChanged(c); +} + char *uiWindowTitle(uiWindow *w) { return uiWindowsWindowText(w->hwnd);