More OS X lifetime stuff.
This commit is contained in:
parent
57329ea332
commit
5ceda42d74
|
@ -21,12 +21,12 @@ static void singleDestroy(uiControl *c)
|
||||||
singleView *s = (singleView *) (c->Internal);
|
singleView *s = (singleView *) (c->Internal);
|
||||||
|
|
||||||
[s->immediate retain]; // to keep alive when removing
|
[s->immediate retain]; // to keep alive when removing
|
||||||
|
(*(s->onDestroy))(s->onDestroyData);
|
||||||
if (s->parent != NULL) {
|
if (s->parent != NULL) {
|
||||||
[s->immediate removeFromSuperview];
|
[s->immediate removeFromSuperview];
|
||||||
s->parent = NULL;
|
s->parent = NULL;
|
||||||
}
|
}
|
||||||
[destroyedControlsView addSubview:s->immediate];
|
[destroyedControlsView addSubview:s->immediate];
|
||||||
(*(s->onDestroy))(s->onDestroyData);
|
|
||||||
[s->immediate release];
|
[s->immediate release];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
intmax_t marginRight;
|
intmax_t marginRight;
|
||||||
intmax_t marginBottom;
|
intmax_t marginBottom;
|
||||||
}
|
}
|
||||||
|
- (void)uipDestroyMainControl;
|
||||||
- (void)uipSetMainControl:(uiControl *)mainControl parent:(uiParent *)p;
|
- (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)uipSetMarginLeft:(intmax_t)left top:(intmax_t)top right:(intmax_t)right bottom:(intmax_t)bottom;
|
||||||
- (void)uipUpdate;
|
- (void)uipUpdate;
|
||||||
|
@ -17,24 +18,20 @@
|
||||||
|
|
||||||
uiLogObjCClassAllocations
|
uiLogObjCClassAllocations
|
||||||
|
|
||||||
- (void)viewDidMoveToSuperview
|
|
||||||
{
|
|
||||||
// we can't just use nil because NSTabView will set page views to nil when they're tabbed away
|
|
||||||
// this means that we have to explicitly move them to the destroyed controls view when we're done with them, and likewise in NSWindow
|
|
||||||
if ([self superview] == destroyedControlsView)
|
|
||||||
if (self->mainControl != NULL) {
|
|
||||||
uiControlDestroy(self->mainControl);
|
|
||||||
self->mainControl = NULL;
|
|
||||||
}
|
|
||||||
[super viewDidMoveToSuperview];
|
|
||||||
}
|
|
||||||
|
|
||||||
- (void)setFrameSize:(NSSize)s
|
- (void)setFrameSize:(NSSize)s
|
||||||
{
|
{
|
||||||
[super setFrameSize:s];
|
[super setFrameSize:s];
|
||||||
[self uipUpdate];
|
[self uipUpdate];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)uipDestroyMainControl
|
||||||
|
{
|
||||||
|
if (self->mainControl != NULL) {
|
||||||
|
uiControlDestroy(self->mainControl);
|
||||||
|
self->mainControl = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
- (void)uipSetMainControl:(uiControl *)mainControl parent:(uiParent *)p
|
- (void)uipSetMainControl:(uiControl *)mainControl parent:(uiParent *)p
|
||||||
{
|
{
|
||||||
if (self->mainControl != NULL)
|
if (self->mainControl != NULL)
|
||||||
|
@ -82,6 +79,7 @@ static void parentDestroy(uiParent *pp)
|
||||||
uipParent *p = (uipParent *) (pp->Internal);
|
uipParent *p = (uipParent *) (pp->Internal);
|
||||||
|
|
||||||
[p retain]; // to avoid destruction upon removing from superview
|
[p retain]; // to avoid destruction upon removing from superview
|
||||||
|
[p uipDestroyMainControl];
|
||||||
[p removeFromSuperview];
|
[p removeFromSuperview];
|
||||||
[destroyedControlsView addSubview:p];
|
[destroyedControlsView addSubview:p];
|
||||||
[p release];
|
[p release];
|
||||||
|
|
|
@ -29,13 +29,14 @@ uiLogObjCClassAllocations
|
||||||
{
|
{
|
||||||
[self.w setDelegate:nil]; // see http://stackoverflow.com/a/29523141/3408572
|
[self.w setDelegate:nil]; // see http://stackoverflow.com/a/29523141/3408572
|
||||||
|
|
||||||
// when we reach this point, we need to ensure that all the window's children are destroyed (for OS parity)
|
// just to be safe
|
||||||
// because we need to set the content view's superview to the destroyed controls view to trigger deletion, we need to do this manually
|
|
||||||
// first, replace the current content view...
|
|
||||||
[self.w setContentView:[[NSView alloc] initWithFrame:NSZeroRect]];
|
[self.w setContentView:[[NSView alloc] initWithFrame:NSZeroRect]];
|
||||||
// ...then, trigger the deletion
|
uiParentDestroy(self.content);
|
||||||
[destroyedControlsView addSubview:((NSView *) uiParentHandle(self.content))];
|
|
||||||
|
|
||||||
|
// now we need to release the window too
|
||||||
|
[self.w release];
|
||||||
|
|
||||||
|
// and clean up
|
||||||
uiFree(self.uiw);
|
uiFree(self.uiw);
|
||||||
[self release];
|
[self release];
|
||||||
}
|
}
|
||||||
|
@ -135,8 +136,8 @@ uiWindow *uiNewWindow(const char *title, int width, int height)
|
||||||
// NOTE: if you disagree with me about disabling substitutions, start a github issue with why and I'll be happy to consider it
|
// NOTE: if you disagree with me about disabling substitutions, start a github issue with why and I'll be happy to consider it
|
||||||
disableAutocorrect((NSTextView *) [d.w fieldEditor:YES forObject:nil]);
|
disableAutocorrect((NSTextView *) [d.w fieldEditor:YES forObject:nil]);
|
||||||
|
|
||||||
// this is what will destroy the window on close
|
// don't release on close; we'll do it ourselves (see above)
|
||||||
[d.w setReleasedWhenClosed:YES];
|
[d.w setReleasedWhenClosed:NO];
|
||||||
|
|
||||||
d.content = uiNewParent(0);
|
d.content = uiNewParent(0);
|
||||||
[d.w setContentView:((NSView *) uiParentHandle(d.content))];
|
[d.w setContentView:((NSView *) uiParentHandle(d.content))];
|
||||||
|
|
Loading…
Reference in New Issue