diff --git a/common/control.c b/common/control.c index 3e00db78..a42e44fd 100644 --- a/common/control.c +++ b/common/control.c @@ -33,26 +33,12 @@ uiControl *uiControlParent(uiControl *c) return cb->parent; } +// TODO ask the control instead int isToplevel(uiControl *c) { return c->TypeSignature == uiWindowSignature; } -// returns self if self is a window -uiControl *toplevelOwning(uiControl *c) -{ - struct controlBase *cb; - - for (;;) { - if (isToplevel(c)) - return c; - cb = controlBase(c); - if (cb->parent == NULL) - return NULL; - c = cb->parent; - } -} - void uiControlSetParent(uiControl *c, uiControl *parent) { struct controlBase *cb = controlBase(c); diff --git a/common/uipriv.h b/common/uipriv.h index 83ce6e74..d6a5b8fd 100644 --- a/common/uipriv.h +++ b/common/uipriv.h @@ -17,7 +17,6 @@ extern void uiFree(void *); extern void complain(const char *, ...); extern int isToplevel(uiControl *); -extern uiControl *toplevelOwning(uiControl *); extern int controlSelfVisible(uiControl *); extern void controlUpdateState(uiControl *); diff --git a/darwin/control.m b/darwin/control.m index 3abeebd9..abff03e6 100644 --- a/darwin/control.m +++ b/darwin/control.m @@ -1,13 +1,20 @@ // 16 august 2015 #import "uipriv_darwin.h" +// TODO refine this void uiDarwinControlTriggerRelayout(uiDarwinControl *c) { - uiControl *p; + NSView *view; + uiWindow *p; - p = toplevelOwning(uiControl(c)); - if (p == NULL) // not in a window - return; + view = (NSView *) uiControlHandle(uiControl(c)); + // this can be a NSWindow + if (![view isKindOfClass:[NSWindow class]]) { + p = windowFromNSWindow([view window]); + if (p == NULL) // not in a window + return; + } else + p = uiWindow(c); c = uiDarwinControl(p); (*(c->Relayout))(uiDarwinControl(c)); } diff --git a/windows/fontbutton.cpp b/windows/fontbutton.cpp index 5c71770f..aada19c3 100644 --- a/windows/fontbutton.cpp +++ b/windows/fontbutton.cpp @@ -111,12 +111,14 @@ uiFontButton *uiNewFontButton(void) TRUE); loadInitialFontDialogParams(&(b->params)); - updateFontButtonLabel(b); uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b)); uiFontButtonOnChanged(b, defaultOnChanged, NULL); uiWindowsFinishNewControl(b, uiFontButton); + // TODO move this back above the previous when merging with uiNewControl(); it's here because this calls Handle() + updateFontButtonLabel(b); + return b; } diff --git a/windows/resize.cpp b/windows/resize.cpp index 7e6572b3..da8bd06d 100644 --- a/windows/resize.cpp +++ b/windows/resize.cpp @@ -3,17 +3,20 @@ static std::map resizes; +// TODO clicking buttons doesn't get rid of anything? void uiWindowsControlQueueRelayout(uiWindowsControl *c) { - uiControl *cc; + HWND hwnd; + HWND parent; uintmax_t i; // resizing a control requires us to reocmpute the sizes of everything in the top-level window - // TODO get rid of this call, make one for finding the root through the HWND - cc = toplevelOwning(uiControl(c)); - if (cc == NULL) + hwnd = (HWND) uiControlHandle(uiControl(c)); + // TODO what if this is toplevel + parent = parentToplevel(hwnd); + if (parent == utilWindow) // not in a parent return; - c = uiWindowsControl(cc); + c = uiWindowsControl(SendMessageW(parent, msgGetuiWindow, 0, 0)); resizes[c] = true; } diff --git a/windows/window.cpp b/windows/window.cpp index eafa4615..a7000f92 100644 --- a/windows/window.cpp +++ b/windows/window.cpp @@ -44,6 +44,8 @@ static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARA if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE) return lResult; switch (uMsg) { + case msgGetuiWindow: + return (LRESULT) w; case WM_COMMAND: // not a menu if (lParam != 0) diff --git a/windows/winutil.cpp b/windows/winutil.cpp index 53440cbc..c8789124 100644 --- a/windows/winutil.cpp +++ b/windows/winutil.cpp @@ -135,8 +135,6 @@ HWND parentToplevel(HWND child) return GetAncestor(child, GA_ROOT); } -///////////// - void uiWindowsEnsureMoveWindowDuringResize(HWND hwnd, intmax_t x, intmax_t y, intmax_t width, intmax_t height) { RECT r;