Migrated darwin/newcontrol.m.

This commit is contained in:
Pietro Gagliardi 2015-04-29 09:38:20 -04:00
parent b2d739a636
commit f45e57494b
2 changed files with 22 additions and 84 deletions

View File

@ -7,6 +7,7 @@ osMFILES = \
darwin/init.m \ darwin/init.m \
darwin/main.m \ darwin/main.m \
darwin/menu.m \ darwin/menu.m \
darwin/newcontrol.m \
darwin/text.m \ darwin/text.m \
darwin/util.m \ darwin/util.m \
darwin/window.m darwin/window.m

View File

@ -7,11 +7,8 @@ struct singleView {
NSView *view; NSView *view;
NSScrollView *scrollView; NSScrollView *scrollView;
NSView *immediate; // the control that is added to the parent container; either view or scrollView NSView *immediate; // the control that is added to the parent container; either view or scrollView
uiParent *parent; uiContainer *parent;
BOOL userHid; int hidden;
BOOL containerHid;
BOOL userDisabled;
BOOL containerDisabled;
void (*onDestroy)(void *); void (*onDestroy)(void *);
void *onDestroyData; void *onDestroyData;
}; };
@ -21,7 +18,7 @@ static void singleDestroy(uiControl *c)
singleView *s = (singleView *) (c->Internal); singleView *s = (singleView *) (c->Internal);
if (s->parent != NULL) if (s->parent != NULL)
complain("attempt to destroy a uiControl at %p while it still has a parent %p", c, s->parent); complain("attempt to destroy a uiControl at %p while it still has a parent", c);
[s->immediate retain]; // to keep alive when removing [s->immediate retain]; // to keep alive when removing
(*(s->onDestroy))(s->onDestroyData); (*(s->onDestroy))(s->onDestroyData);
[destroyedControlsView addSubview:s->immediate]; [destroyedControlsView addSubview:s->immediate];
@ -35,7 +32,7 @@ static uintptr_t singleHandle(uiControl *c)
return (uintptr_t) (s->view); return (uintptr_t) (s->view);
} }
// TODO figure out retain/release for this // TODO update refcounting here and in the GTK+ port
static void singleSetParent(uiControl *c, uiParent *parent) static void singleSetParent(uiControl *c, uiParent *parent)
{ {
singleView *s = (singleView *) (c->Internal); singleView *s = (singleView *) (c->Internal);
@ -44,16 +41,16 @@ static void singleSetParent(uiControl *c, uiParent *parent)
oldparent = s->parent; oldparent = s->parent;
s->parent = parent; s->parent = parent;
if (oldparent != NULL) { if (oldparent != NULL)
[s->immediate removeFromSuperview]; [s->immediate removeFromSuperview];
uiParentUpdate(oldparent);
}
if (s->parent != NULL) { if (s->parent != NULL) {
// TODO uiControlView(), uiParentView() parentView = (NSView *) uiControlHandle(uiControls->parent));
parentView = (NSView *) uiParentHandle(s->parent);
[parentView addSubview:s->immediate]; [parentView addSubview:s->immediate];
uiParentUpdate(s->parent);
} }
if (oldparent != NULL)
uiContainerUpdate(oldparent);
if (s->parent != NULL)
uiParentUpdate(s->parent);
} }
// also good for NSBox and NSProgressIndicator // also good for NSBox and NSProgressIndicator
@ -89,99 +86,43 @@ static int singleVisible(uiControl *c)
{ {
singleView *s = (singleView *) (c->Internal); singleView *s = (singleView *) (c->Internal);
if (s->userHid) return !s->hidden;
return 0;
return 1;
} }
static void singleShow(uiControl *c) static void singleShow(uiControl *c)
{ {
singleView *s = (singleView *) (c->Internal); singleView *s = (singleView *) (c->Internal);
s->userHid = NO; [s->immediate setHidden:NO];
if (!s->containerHid) { if (s->parent != NULL)
[s->immediate setHidden:NO]; uiContainerUpdate(s->parent);
if (s->parent != NULL) s->hidden = 0;
uiParentUpdate(s->parent);
}
} }
static void singleHide(uiControl *c) static void singleHide(uiControl *c)
{ {
singleView *s = (singleView *) (c->Internal); singleView *s = (singleView *) (c->Internal);
s->userHid = YES;
[s->immediate setHidden:YES]; [s->immediate setHidden:YES];
if (s->parent != NULL) if (s->parent != NULL)
uiParentUpdate(s->parent); uiContainerUpdate(s->parent);
} s->hidden = 1;
static void singleContainerShow(uiControl *c)
{
singleView *s = (singleView *) (c->Internal);
s->containerHid = NO;
if (!s->userHid) {
[s->immediate setHidden:NO];
if (s->parent != NULL)
uiParentUpdate(s->parent);
}
}
static void singleContainerHide(uiControl *c)
{
singleView *s = (singleView *) (c->Internal);
s->containerHid = YES;
[s->immediate setHidden:YES];
if (s->parent != NULL)
uiParentUpdate(s->parent);
}
static void enable(singleView *s)
{
if ([s->view respondsToSelector:@selector(setEnabled:)])
[((NSControl *) (s->view)) setEnabled:YES];
}
static void disable(singleView *s)
{
if ([s->view respondsToSelector:@selector(setEnabled:)])
[((NSControl *) (s->view)) setEnabled:NO];
} }
static void singleEnable(uiControl *c) static void singleEnable(uiControl *c)
{ {
singleView *s = (singleView *) (c->Internal); singleView *s = (singleView *) (c->Internal);
s->userDisabled = NO; if ([s->view respondsToSelector:@selector(setEnabled:)])
if (!s->containerDisabled) [((NSControl *) (s->view)) setEnabled:YES];
enable(s);
} }
static void singleDisable(uiControl *c) static void singleDisable(uiControl *c)
{ {
singleView *s = (singleView *) (c->Internal); singleView *s = (singleView *) (c->Internal);
s->userDisabled = YES; if ([s->view respondsToSelector:@selector(setEnabled:)])
disable(s); [((NSControl *) (s->view)) setEnabled:NO];
}
static void singleContainerEnable(uiControl *c)
{
singleView *s = (singleView *) (c->Internal);
s->containerDisabled = NO;
if (!s->userDisabled)
enable(s);
}
static void singleContainerDisable(uiControl *c)
{
singleView *s = (singleView *) (c->Internal);
s->containerDisabled = YES;
disable(s);
} }
void uiDarwinNewControl(uiControl *c, Class class, BOOL inScrollView, BOOL scrollViewHasBorder, void (*onDestroy)(void *), void *onDestroyData) void uiDarwinNewControl(uiControl *c, Class class, BOOL inScrollView, BOOL scrollViewHasBorder, void (*onDestroy)(void *), void *onDestroyData)
@ -221,10 +162,6 @@ void uiDarwinNewControl(uiControl *c, Class class, BOOL inScrollView, BOOL scrol
c->Visible = singleVisible; c->Visible = singleVisible;
c->Show = singleShow; c->Show = singleShow;
c->Hide = singleHide; c->Hide = singleHide;
c->ContainerShow = singleContainerShow;
c->ContainerHide = singleContainerHide;
c->Enable = singleEnable; c->Enable = singleEnable;
c->Disable = singleDisable; c->Disable = singleDisable;
c->ContainerEnable = singleContainerEnable;
c->ContainerDisable = singleContainerDisable;
} }