Got rid of toplevelOwning(); I didn't like that one.

This commit is contained in:
Pietro Gagliardi 2016-04-24 18:23:00 -04:00
parent bc0a1d43c9
commit cf51ec823f
7 changed files with 25 additions and 28 deletions

View File

@ -33,26 +33,12 @@ uiControl *uiControlParent(uiControl *c)
return cb->parent; return cb->parent;
} }
// TODO ask the control instead
int isToplevel(uiControl *c) int isToplevel(uiControl *c)
{ {
return c->TypeSignature == uiWindowSignature; 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) void uiControlSetParent(uiControl *c, uiControl *parent)
{ {
struct controlBase *cb = controlBase(c); struct controlBase *cb = controlBase(c);

View File

@ -17,7 +17,6 @@ extern void uiFree(void *);
extern void complain(const char *, ...); extern void complain(const char *, ...);
extern int isToplevel(uiControl *); extern int isToplevel(uiControl *);
extern uiControl *toplevelOwning(uiControl *);
extern int controlSelfVisible(uiControl *); extern int controlSelfVisible(uiControl *);
extern void controlUpdateState(uiControl *); extern void controlUpdateState(uiControl *);

View File

@ -1,13 +1,20 @@
// 16 august 2015 // 16 august 2015
#import "uipriv_darwin.h" #import "uipriv_darwin.h"
// TODO refine this
void uiDarwinControlTriggerRelayout(uiDarwinControl *c) void uiDarwinControlTriggerRelayout(uiDarwinControl *c)
{ {
uiControl *p; NSView *view;
uiWindow *p;
p = toplevelOwning(uiControl(c)); 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 if (p == NULL) // not in a window
return; return;
} else
p = uiWindow(c);
c = uiDarwinControl(p); c = uiDarwinControl(p);
(*(c->Relayout))(uiDarwinControl(c)); (*(c->Relayout))(uiDarwinControl(c));
} }

View File

@ -111,12 +111,14 @@ uiFontButton *uiNewFontButton(void)
TRUE); TRUE);
loadInitialFontDialogParams(&(b->params)); loadInitialFontDialogParams(&(b->params));
updateFontButtonLabel(b);
uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b)); uiWindowsRegisterWM_COMMANDHandler(b->hwnd, onWM_COMMAND, uiControl(b));
uiFontButtonOnChanged(b, defaultOnChanged, NULL); uiFontButtonOnChanged(b, defaultOnChanged, NULL);
uiWindowsFinishNewControl(b, uiFontButton); 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; return b;
} }

View File

@ -3,17 +3,20 @@
static std::map<uiWindowsControl *, bool> resizes; static std::map<uiWindowsControl *, bool> resizes;
// TODO clicking buttons doesn't get rid of anything?
void uiWindowsControlQueueRelayout(uiWindowsControl *c) void uiWindowsControlQueueRelayout(uiWindowsControl *c)
{ {
uiControl *cc; HWND hwnd;
HWND parent;
uintmax_t i; uintmax_t i;
// resizing a control requires us to reocmpute the sizes of everything in the top-level window // 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 hwnd = (HWND) uiControlHandle(uiControl(c));
cc = toplevelOwning(uiControl(c)); // TODO what if this is toplevel
if (cc == NULL) parent = parentToplevel(hwnd);
if (parent == utilWindow) // not in a parent
return; return;
c = uiWindowsControl(cc); c = uiWindowsControl(SendMessageW(parent, msgGetuiWindow, 0, 0));
resizes[c] = true; resizes[c] = true;
} }

View File

@ -44,6 +44,8 @@ static LRESULT CALLBACK windowWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARA
if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE) if (handleParentMessages(hwnd, uMsg, wParam, lParam, &lResult) != FALSE)
return lResult; return lResult;
switch (uMsg) { switch (uMsg) {
case msgGetuiWindow:
return (LRESULT) w;
case WM_COMMAND: case WM_COMMAND:
// not a menu // not a menu
if (lParam != 0) if (lParam != 0)

View File

@ -135,8 +135,6 @@ HWND parentToplevel(HWND child)
return GetAncestor(child, GA_ROOT); return GetAncestor(child, GA_ROOT);
} }
/////////////
void uiWindowsEnsureMoveWindowDuringResize(HWND hwnd, intmax_t x, intmax_t y, intmax_t width, intmax_t height) void uiWindowsEnsureMoveWindowDuringResize(HWND hwnd, intmax_t x, intmax_t y, intmax_t width, intmax_t height)
{ {
RECT r; RECT r;