Migrated the OS X uiWindow code back, modernizing it in the process. Also fixed a latent bug in the GTK+ uiWindow code.
This commit is contained in:
parent
eae17fef21
commit
9f1ef9eaa1
|
@ -1,8 +1,6 @@
|
||||||
// 28 april 2015
|
// 28 april 2015
|
||||||
#import "uipriv_darwin.h"
|
#import "uipriv_darwin.h"
|
||||||
|
|
||||||
// TODO rewrite this file to take advantage of bins
|
|
||||||
|
|
||||||
@interface windowDelegate : NSObject <NSWindowDelegate> {
|
@interface windowDelegate : NSObject <NSWindowDelegate> {
|
||||||
uiWindow *w;
|
uiWindow *w;
|
||||||
int (*onClosing)(uiWindow *, void *);
|
int (*onClosing)(uiWindow *, void *);
|
||||||
|
@ -44,9 +42,7 @@ struct window {
|
||||||
uiWindow w;
|
uiWindow w;
|
||||||
NSWindow *window;
|
NSWindow *window;
|
||||||
windowDelegate *delegate;
|
windowDelegate *delegate;
|
||||||
uiBin *bin;
|
uiControl *bin;
|
||||||
int hidden;
|
|
||||||
int margined;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static int defaultOnClosing(uiWindow *w, void *data)
|
static int defaultOnClosing(uiWindow *w, void *data)
|
||||||
|
@ -60,18 +56,20 @@ static void windowDestroy(uiControl *c)
|
||||||
|
|
||||||
// first hide ourselves
|
// first hide ourselves
|
||||||
[w->window orderOut:w->window];
|
[w->window orderOut:w->window];
|
||||||
|
// now destroy the child
|
||||||
|
binSetChild(w->bin, NULL);
|
||||||
|
uiControlDestroy(w->child);
|
||||||
// now destroy the bin
|
// now destroy the bin
|
||||||
// we need to remove the bin from its parent; this is equivalent to calling binSetParent()
|
|
||||||
// we do this by changing the content view to a dummy view
|
// we do this by changing the content view to a dummy view
|
||||||
// the window will release its reference on the bin now, then it will release its reference on the dummy view when the window itself is finally released
|
// the window will release its reference on the bin now, then it will release its reference on the dummy view when the window itself is finally released
|
||||||
[w->window setContentView:[[NSView alloc] initWithFrame:NSZeroRect]];
|
[w->window setContentView:[[NSView alloc] initWithFrame:NSZeroRect]];
|
||||||
uiControlDestroy(uiControl(w->bin));
|
uiControlDestroy(w->bin);
|
||||||
// now destroy the delegate
|
// now destroy the delegate
|
||||||
[w->window setDelegate:nil];
|
[w->window setDelegate:nil];
|
||||||
[w->delegate release];
|
[w->delegate release];
|
||||||
// now destroy ourselves
|
// now destroy ourselves
|
||||||
|
// don't call the base; we use a different method
|
||||||
[w->window close]; // see below about releasing when closed
|
[w->window close]; // see below about releasing when closed
|
||||||
uiFree(w);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static uintptr_t windowHandle(uiControl *c)
|
static uintptr_t windowHandle(uiControl *c)
|
||||||
|
@ -81,56 +79,26 @@ static uintptr_t windowHandle(uiControl *c)
|
||||||
return (uintptr_t) (w->window);
|
return (uintptr_t) (w->window);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void windowSetParent(uiControl *c, uiContainer *parent)
|
static void windowCommitShow(uiControl *c)
|
||||||
{
|
|
||||||
complain("attempt to give the uiWindow at %p a parent", c);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void windowPreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
|
|
||||||
{
|
|
||||||
complain("attempt to get the preferred size of the uiWindow at %p", c);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void windowResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
|
|
||||||
{
|
|
||||||
complain("attempt to resize the uiWindow at %p", c);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int windowVisible(uiControl *c)
|
|
||||||
{
|
|
||||||
struct window *w = (struct window *) c;
|
|
||||||
|
|
||||||
return !w->hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void windowShow(uiControl *c)
|
|
||||||
{
|
{
|
||||||
struct window *w = (struct window *) c;
|
struct window *w = (struct window *) c;
|
||||||
|
|
||||||
[w->window makeKeyAndOrderFront:w->window];
|
[w->window makeKeyAndOrderFront:w->window];
|
||||||
w->hidden = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void windowHide(uiControl *c)
|
static void windowCommitHide(uiControl *c)
|
||||||
{
|
{
|
||||||
struct window *w = (struct window *) c;
|
struct window *w = (struct window *) c;
|
||||||
|
|
||||||
[w->window orderOut:w->window];
|
[w->window orderOut:w->window];
|
||||||
w->hidden = 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void windowEnable(uiControl *c)
|
static void windowContainerUpdateState(uiControl *c)
|
||||||
{
|
{
|
||||||
struct window *w = (struct window *) c;
|
struct window *w = (struct window *) c;
|
||||||
|
|
||||||
uiControlEnable(uiControl(w->bin));
|
if (w->child != NULL)
|
||||||
}
|
uiControlUpdateState(w->child);
|
||||||
|
|
||||||
static void windowDisable(uiControl *c)
|
|
||||||
{
|
|
||||||
struct window *w = (struct window *) c;
|
|
||||||
|
|
||||||
uiControlDisable(uiControl(w->bin));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *windowTitle(uiWindow *ww)
|
static char *windowTitle(uiWindow *ww)
|
||||||
|
@ -158,28 +126,29 @@ static void windowSetChild(uiWindow *ww, uiControl *child)
|
||||||
{
|
{
|
||||||
struct window *w = (struct window *) ww;
|
struct window *w = (struct window *) ww;
|
||||||
|
|
||||||
uiBinSetMainControl(w->bin, child);
|
binSetChild(w->bin, child);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int windowMargined(uiWindow *ww)
|
static int windowMargined(uiWindow *ww)
|
||||||
{
|
{
|
||||||
struct window *w = (struct window *) ww;
|
struct window *w = (struct window *) ww;
|
||||||
|
|
||||||
return w->margined;
|
return binMargined(w->bin);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void windowSetMargined(uiWindow *ww, int margined)
|
static void windowSetMargined(uiWindow *ww, int margined)
|
||||||
{
|
{
|
||||||
struct window *w = (struct window *) ww;
|
struct window *w = (struct window *) ww;
|
||||||
|
|
||||||
w->margined = margined;
|
binSetMargined(w->bin, margined);
|
||||||
if (w->margined)
|
|
||||||
uiBinSetMargins(w->bin, macXMargin, macYMargin, macXMargin, macYMargin);
|
|
||||||
else
|
|
||||||
uiBinSetMargins(w->bin, 0, 0, 0, 0);
|
|
||||||
uiContainerUpdate(uiContainer(w->bin));
|
uiContainerUpdate(uiContainer(w->bin));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void windowResizeChild(uiWindow *ww)
|
||||||
|
{
|
||||||
|
complain("uiWindowResizeChild() meaningless on OS X");
|
||||||
|
}
|
||||||
|
|
||||||
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
||||||
{
|
{
|
||||||
struct window *w;
|
struct window *w;
|
||||||
|
@ -187,7 +156,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
||||||
|
|
||||||
finalizeMenus();
|
finalizeMenus();
|
||||||
|
|
||||||
w = uiNew(struct window);
|
w = (struct window *) uiNewControl(uiTypeWindow());
|
||||||
|
|
||||||
w->window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, (CGFloat) width, (CGFloat) height)
|
w->window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, (CGFloat) width, (CGFloat) height)
|
||||||
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
|
styleMask:(NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask)
|
||||||
|
@ -195,6 +164,9 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
||||||
defer:YES];
|
defer:YES];
|
||||||
[w->window setTitle:toNSString(title)];
|
[w->window setTitle:toNSString(title)];
|
||||||
|
|
||||||
|
// a NSWindow is not a NSView, but nothing we're doing in this function is view-specific
|
||||||
|
uiDarwinMakeSingleWidgetControl(uiControl(w), (NSView *) (w->window));
|
||||||
|
|
||||||
// explicitly release when closed
|
// explicitly release when closed
|
||||||
// the only thing that closes the window is us anyway
|
// the only thing that closes the window is us anyway
|
||||||
[w->window setReleasedWhenClosed:YES];
|
[w->window setReleasedWhenClosed:YES];
|
||||||
|
@ -209,16 +181,11 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
||||||
|
|
||||||
[w->delegate setOnClosing:defaultOnClosing data:NULL];
|
[w->delegate setOnClosing:defaultOnClosing data:NULL];
|
||||||
|
|
||||||
uiControl(w)->Destroy = windowDestroy;
|
|
||||||
uiControl(w)->Handle = windowHandle;
|
uiControl(w)->Handle = windowHandle;
|
||||||
uiControl(w)->SetParent = windowSetParent;
|
uiControl(w)->CommitDestroy = windowCommitDestroy;
|
||||||
uiControl(w)->PreferredSize = windowPreferredSize;
|
uiControl(w)->CommitShow = windowCommitShow;
|
||||||
uiControl(w)->Resize = windowResize;
|
uiControl(w)->CommitHide = windowCommitHide;
|
||||||
uiControl(w)->Visible = windowVisible;
|
uiControl(w)->ContainerUpdateState = windowContainerUpdateState;
|
||||||
uiControl(w)->Show = windowShow;
|
|
||||||
uiControl(w)->Hide = windowHide;
|
|
||||||
uiControl(w)->Enable = windowEnable;
|
|
||||||
uiControl(w)->Disable = windowDisable;
|
|
||||||
|
|
||||||
uiWindow(w)->Title = windowTitle;
|
uiWindow(w)->Title = windowTitle;
|
||||||
uiWindow(w)->SetTitle = windowSetTitle;
|
uiWindow(w)->SetTitle = windowSetTitle;
|
||||||
|
@ -226,6 +193,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
||||||
uiWindow(w)->SetChild = windowSetChild;
|
uiWindow(w)->SetChild = windowSetChild;
|
||||||
uiWindow(w)->Margined = windowMargined;
|
uiWindow(w)->Margined = windowMargined;
|
||||||
uiWindow(w)->SetMargined = windowSetMargined;
|
uiWindow(w)->SetMargined = windowSetMargined;
|
||||||
|
uiWindow(w)->ResizeChild = windowResizeChild;
|
||||||
|
|
||||||
return uiWindow(w);
|
return uiWindow(w);
|
||||||
}
|
}
|
|
@ -144,6 +144,8 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
|
||||||
{
|
{
|
||||||
struct window *w;
|
struct window *w;
|
||||||
|
|
||||||
|
finalizeMenus();
|
||||||
|
|
||||||
w = (struct window *) uiNewControl(uiTypeWindow());
|
w = (struct window *) uiNewControl(uiTypeWindow());
|
||||||
|
|
||||||
w->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
w->widget = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||||
|
|
Loading…
Reference in New Issue