Rewrote the Mac OS X uiParent.
This commit is contained in:
parent
cb44d902f2
commit
cb05779d0a
|
@ -1,23 +1,16 @@
|
||||||
// 4 august 2014
|
// 17 april 2015
|
||||||
#import "uipriv_darwin.h"
|
#import "uipriv_darwin.h"
|
||||||
|
|
||||||
// calling -[className] on the content views of NSWindow, NSTabItem, and NSBox all return NSView, so I'm assuming I just need to override these
|
|
||||||
// fornunately:
|
|
||||||
// - NSWindow resizing calls -[setFrameSize:] (but not -[setFrame:])
|
|
||||||
// - NSTabView resizing calls both -[setFrame:] and -[setFrameSIze:] on the current tab
|
|
||||||
// - NSTabView switching tabs calls both -[setFrame:] and -[setFrameSize:] on the new tab
|
|
||||||
// so we just override setFrameSize:
|
|
||||||
// thanks to mikeash and JtRip in irc.freenode.net/#macdev
|
|
||||||
@interface uipParent : NSView {
|
@interface uipParent : NSView {
|
||||||
// TODO
|
|
||||||
@public
|
|
||||||
uiControl *mainControl;
|
uiControl *mainControl;
|
||||||
intmax_t marginLeft;
|
intmax_t marginLeft;
|
||||||
intmax_t marginTop;
|
intmax_t marginTop;
|
||||||
intmax_t marginRight;
|
intmax_t marginRight;
|
||||||
intmax_t marginBottom;
|
intmax_t marginBottom;
|
||||||
}
|
}
|
||||||
- (void)uiUpdateNow;
|
- (void)uipSetMainControl:(uiControl *)mainControl parent:(uiParent *)p;
|
||||||
|
- (void)uipSetMarginLeft:(intmax_t)left top:(intmax_t)top right:(intmax_t)right bottom:(intmax_t)bottom;
|
||||||
|
- (void)uipUpdate;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation uipParent
|
@implementation uipParent
|
||||||
|
@ -32,7 +25,6 @@ uiLogObjCClassAllocations
|
||||||
if (self->mainControl != NULL) {
|
if (self->mainControl != NULL) {
|
||||||
uiControlDestroy(self->mainControl);
|
uiControlDestroy(self->mainControl);
|
||||||
self->mainControl = NULL;
|
self->mainControl = NULL;
|
||||||
[self release];
|
|
||||||
}
|
}
|
||||||
[super viewDidMoveToSuperview];
|
[super viewDidMoveToSuperview];
|
||||||
}
|
}
|
||||||
|
@ -40,7 +32,24 @@ uiLogObjCClassAllocations
|
||||||
- (void)setFrameSize:(NSSize)s
|
- (void)setFrameSize:(NSSize)s
|
||||||
{
|
{
|
||||||
[super setFrameSize:s];
|
[super setFrameSize:s];
|
||||||
[self uiUpdateNow];
|
[self uipUpdate];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)uipSetMainControl:(uiControl *)mainControl parent:(uiParent *)p
|
||||||
|
{
|
||||||
|
if (self->mainControl != NULL)
|
||||||
|
uiControlSetParent(self->mainControl, NULL);
|
||||||
|
self->mainControl = mainControl;
|
||||||
|
if (self->mainControl != NULL)
|
||||||
|
uiControlSetParent(self->mainControl, p);
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)uipSetMarginLeft:(intmax_t)left top:(intmax_t)top right:(intmax_t)right bottom:(intmax_t)bottom
|
||||||
|
{
|
||||||
|
self->marginLeft = left;
|
||||||
|
self->marginTop = top;
|
||||||
|
self->marginRight = right;
|
||||||
|
self->marginBottom = bottom;
|
||||||
}
|
}
|
||||||
|
|
||||||
// These are based on measurements from Interface Builder.
|
// These are based on measurements from Interface Builder.
|
||||||
|
@ -50,7 +59,7 @@ uiLogObjCClassAllocations
|
||||||
// Likewise, this one appears to be 12 for pairs of push buttons...
|
// Likewise, this one appears to be 12 for pairs of push buttons...
|
||||||
#define macYPadding 8
|
#define macYPadding 8
|
||||||
|
|
||||||
- (void)uiUpdateNow
|
- (void)uipUpdate
|
||||||
{
|
{
|
||||||
uiSizing d;
|
uiSizing d;
|
||||||
intmax_t x, y, width, height;
|
intmax_t x, y, width, height;
|
||||||
|
@ -68,53 +77,58 @@ uiLogObjCClassAllocations
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
static void parentDestroy(uiParent *pp)
|
||||||
|
{
|
||||||
|
uipParent *p = (uipParent *) (pp->Internal);
|
||||||
|
|
||||||
|
[p retain]; // to avoid destruction upon removing from superview
|
||||||
|
[p removeFromSuperview];
|
||||||
|
[destroyedControlsView addSubview:p];
|
||||||
|
[p release];
|
||||||
|
}
|
||||||
|
|
||||||
static uintptr_t parentHandle(uiParent *p)
|
static uintptr_t parentHandle(uiParent *p)
|
||||||
{
|
{
|
||||||
uipParent *pp = (uipParent *) (p->Internal);
|
return (uintptr_t) (p->Internal);
|
||||||
|
|
||||||
return (uintptr_t) pp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parentSetMainControl(uiParent *pp, uiControl *mainControl)
|
static void parentSetMainControl(uiParent *pp, uiControl *mainControl)
|
||||||
{
|
{
|
||||||
uipParent *p = (uipParent *) (pp->Internal);
|
uipParent *p = (uipParent *) (pp->Internal);
|
||||||
|
|
||||||
if (p->mainControl != NULL)
|
[p uipSetMainControl:mainControl parent:pp];
|
||||||
uiControlSetParent(p->mainControl, NULL);
|
|
||||||
p->mainControl = mainControl;
|
|
||||||
if (p->mainControl != NULL)
|
|
||||||
uiControlSetParent(p->mainControl, pp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parentSetMargins(uiParent *p, intmax_t left, intmax_t top, intmax_t right, intmax_t bottom)
|
static void parentSetMargins(uiParent *pp, intmax_t left, intmax_t top, intmax_t right, intmax_t bottom)
|
||||||
{
|
{
|
||||||
uipParent *pp = (uipParent *) (p->Internal);
|
uipParent *p = (uipParent *) (pp->Internal);
|
||||||
|
|
||||||
pp->marginLeft = left;
|
[p uipSetMarginLeft:left top:top right:right bottom:bottom];
|
||||||
pp->marginTop = top;
|
|
||||||
pp->marginRight = right;
|
|
||||||
pp->marginBottom = bottom;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void parentUpdate(uiParent *p)
|
static void parentUpdate(uiParent *pp)
|
||||||
{
|
{
|
||||||
uipParent *pp = (uipParent *) (p->Internal);
|
uipParent *p = (uipParent *) (pp->Internal);
|
||||||
|
|
||||||
[pp uiUpdateNow];
|
[p uipUpdate];
|
||||||
}
|
}
|
||||||
|
|
||||||
uiParent *uiNewParent(uintptr_t osParent)
|
uiParent *uiNewParent(uintptr_t osParent)
|
||||||
{
|
{
|
||||||
uiParent *p;
|
uiParent *p;
|
||||||
|
uipParent *pp;
|
||||||
|
|
||||||
p = uiNew(uiParent);
|
p = uiNew(uiParent);
|
||||||
p->Internal = [[uipParent alloc] initWithFrame:NSZeroRect];
|
|
||||||
|
pp = [[uipParent alloc] initWithFrame:NSZeroRect];
|
||||||
|
// don't use osParent; we'll need to call specific selectors to set the parent view
|
||||||
|
p->Internal = pp;
|
||||||
|
|
||||||
|
p->Destroy = parentDestroy;
|
||||||
p->Handle = parentHandle;
|
p->Handle = parentHandle;
|
||||||
p->SetMainControl = parentSetMainControl;
|
p->SetMainControl = parentSetMainControl;
|
||||||
p->SetMargins = parentSetMargins;
|
p->SetMargins = parentSetMargins;
|
||||||
p->Update = parentUpdate;
|
p->Update = parentUpdate;
|
||||||
// don't use osParent; we'll need to call specific selectors to set the parent view
|
|
||||||
// and keep the view alive so we can release it properly later
|
|
||||||
[((uipParent *) (p->Internal)) retain];
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
Loading…
Reference in New Issue