Began Darwin backend migration.

This commit is contained in:
Pietro Gagliardi 2015-04-16 13:04:46 -04:00
parent 79ef30c877
commit f3867ee2d4
2 changed files with 34 additions and 39 deletions

View File

@ -16,21 +16,21 @@ struct singleView {
static void singleDestroy(uiControl *c) static void singleDestroy(uiControl *c)
{ {
singleView *s = (singleView *) (c->internal); singleView *s = (singleView *) (c->Internal);
[destroyedControlsView addSubview:s->immediate]; [destroyedControlsView addSubview:s->immediate];
} }
static uintptr_t singleHandle(uiControl *c) static uintptr_t singleHandle(uiControl *c)
{ {
singleView *s = (singleView *) (c->internal); singleView *s = (singleView *) (c->Internal);
return (uintptr_t) (s->view); return (uintptr_t) (s->view);
} }
static void singleSetParent(uiControl *c, uiParent *parent) static void singleSetParent(uiControl *c, uiParent *parent)
{ {
singleView *s = (singleView *) (c->internal); singleView *s = (singleView *) (c->Internal);
NSView *parentView; NSView *parentView;
uiParent *oldparent; uiParent *oldparent;
@ -51,7 +51,7 @@ static void singleSetParent(uiControl *c, uiParent *parent)
// also good for NSBox and NSProgressIndicator // also good for NSBox and NSProgressIndicator
static void singlePreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height) static void singlePreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intmax_t *height)
{ {
singleView *s = (singleView *) (c->internal); singleView *s = (singleView *) (c->Internal);
NSControl *control; NSControl *control;
NSRect r; NSRect r;
@ -65,7 +65,7 @@ static void singlePreferredSize(uiControl *c, uiSizing *d, intmax_t *width, intm
static void singleResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d) static void singleResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height, uiSizing *d)
{ {
singleView *s = (singleView *) (c->internal); singleView *s = (singleView *) (c->Internal);
NSRect frame; NSRect frame;
frame.origin.x = x; frame.origin.x = x;
@ -79,7 +79,7 @@ static void singleResize(uiControl *c, intmax_t x, intmax_t y, intmax_t width, i
static int singleVisible(uiControl *c) static int singleVisible(uiControl *c)
{ {
singleView *s = (singleView *) (c->internal); singleView *s = (singleView *) (c->Internal);
if (s->userHid) if (s->userHid)
return 0; return 0;
@ -88,7 +88,7 @@ static int singleVisible(uiControl *c)
static void singleShow(uiControl *c) static void singleShow(uiControl *c)
{ {
singleView *s = (singleView *) (c->internal); singleView *s = (singleView *) (c->Internal);
s->userHid = NO; s->userHid = NO;
if (!s->containerHid) { if (!s->containerHid) {
@ -100,7 +100,7 @@ static void singleShow(uiControl *c)
static void singleHide(uiControl *c) static void singleHide(uiControl *c)
{ {
singleView *s = (singleView *) (c->internal); singleView *s = (singleView *) (c->Internal);
s->userHid = YES; s->userHid = YES;
[s->immediate setHidden:YES]; [s->immediate setHidden:YES];
@ -110,7 +110,7 @@ static void singleHide(uiControl *c)
static void singleContainerShow(uiControl *c) static void singleContainerShow(uiControl *c)
{ {
singleView *s = (singleView *) (c->internal); singleView *s = (singleView *) (c->Internal);
s->containerHid = NO; s->containerHid = NO;
if (!s->userHid) { if (!s->userHid) {
@ -122,7 +122,7 @@ static void singleContainerShow(uiControl *c)
static void singleContainerHide(uiControl *c) static void singleContainerHide(uiControl *c)
{ {
singleView *s = (singleView *) (c->internal); singleView *s = (singleView *) (c->Internal);
s->containerHid = YES; s->containerHid = YES;
[s->immediate setHidden:YES]; [s->immediate setHidden:YES];
@ -144,7 +144,7 @@ static void disable(singleView *s)
static void singleEnable(uiControl *c) static void singleEnable(uiControl *c)
{ {
singleView *s = (singleView *) (c->internal); singleView *s = (singleView *) (c->Internal);
s->userDisabled = NO; s->userDisabled = NO;
if (!s->containerDisabled) if (!s->containerDisabled)
@ -153,7 +153,7 @@ static void singleEnable(uiControl *c)
static void singleDisable(uiControl *c) static void singleDisable(uiControl *c)
{ {
singleView *s = (singleView *) (c->internal); singleView *s = (singleView *) (c->Internal);
s->userDisabled = YES; s->userDisabled = YES;
disable(s); disable(s);
@ -161,7 +161,7 @@ static void singleDisable(uiControl *c)
static void singleContainerEnable(uiControl *c) static void singleContainerEnable(uiControl *c)
{ {
singleView *s = (singleView *) (c->internal); singleView *s = (singleView *) (c->Internal);
s->containerDisabled = NO; s->containerDisabled = NO;
if (!s->userDisabled) if (!s->userDisabled)
@ -170,15 +170,14 @@ static void singleContainerEnable(uiControl *c)
static void singleContainerDisable(uiControl *c) static void singleContainerDisable(uiControl *c)
{ {
singleView *s = (singleView *) (c->internal); singleView *s = (singleView *) (c->Internal);
s->containerDisabled = YES; s->containerDisabled = YES;
disable(s); disable(s);
} }
uiControl *uiDarwinNewControl(Class class, BOOL inScrollView, BOOL scrollViewHasBorder) void uiDarwinNewControl(uiControl *c, Class class, BOOL inScrollView, BOOL scrollViewHasBorder)
{ {
uiControl *c;
singleView *s; singleView *s;
s = uiNew(singleView); s = uiNew(singleView);
@ -202,34 +201,30 @@ uiControl *uiDarwinNewControl(Class class, BOOL inScrollView, BOOL scrollViewHas
// and keep a reference to s->immediate for when we remove the control from its parent // and keep a reference to s->immediate for when we remove the control from its parent
[s->immediate retain]; [s->immediate retain];
c = uiNew(uiControl); c->Internal = s;
c->internal = s; c->Destroy = singleDestroy;
c->destroy = singleDestroy; c->Handle = singleHandle;
c->handle = singleHandle; c->SetParent = singleSetParent;
c->setParent = singleSetParent; c->PreferredSize = singlePreferredSize;
c->preferredSize = singlePreferredSize; c->Resize = singleResize;
c->resize = singleResize; c->Visible = singleVisible;
c->visible = singleVisible; c->Show = singleShow;
c->show = singleShow; c->Hide = singleHide;
c->hide = singleHide; c->ContainerShow = singleContainerShow;
c->containerShow = singleContainerShow; c->ContainerHide = singleContainerHide;
c->containerHide = singleContainerHide; c->Enable = singleEnable;
c->enable = singleEnable; c->Disable = singleDisable;
c->disable = singleDisable; c->ContainerEnable = singleContainerEnable;
c->containerEnable = singleContainerEnable; c->ContainerDisable = singleContainerDisable;
c->containerDisable = singleContainerDisable;
return c;
} }
BOOL uiDarwinControlFreeWhenAppropriate(uiControl *c, NSView *newSuperview) BOOL uiDarwinControlFreeWhenAppropriate(uiControl *c, NSView *newSuperview)
{ {
singleView *s = (singleView *) (c->internal); singleView *s = (singleView *) (c->Internal);
if (newSuperview == destroyedControlsView) { if (newSuperview == destroyedControlsView) {
[s->immediate release]; // we don't need the reference anymore [s->immediate release]; // we don't need the reference anymore
uiFree(s); uiFree(s);
uiFree(c);
return YES; return YES;
} }
return NO; return NO;

View File

@ -7,12 +7,12 @@ This file assumes that you have imported <Cocoa/Cocoa.h> and "ui.h" beforehand.
#ifndef __UI_UI_DARWIN_H__ #ifndef __UI_UI_DARWIN_H__
#define __UI_UI_DARWIN_H__ #define __UI_UI_DARWIN_H__
// uiDarwinNewControl() creates a new uiControl with the given Cocoa control inside. // uiDarwinNewControl() initializes the given uiControl with the given Cocoa control inside.
// The first parameter should come from [RealControlType class]. // The second parameter should come from [RealControlType class].
// The two scrollView parameters allow placing scrollbars on the new control. // The two scrollView parameters allow placing scrollbars on the new control.
// Your control must call uiDarwinControlFreeWhenAppropriate() on the returned uiControl in its -[viewDidMoveToSuperview] method. // Your control must call uiDarwinControlFreeWhenAppropriate() on the returned uiControl in its -[viewDidMoveToSuperview] method.
// If it returns a value other than NO, then the uiControl has been freed and you should set references to it to NULL. // If it returns a value other than NO, then the uiControl has been freed and you should set references to it to NULL.
extern uiControl *uiDarwinNewControl(Class class, BOOL inScrollView, BOOL scrollViewHasBorder); extern void uiDarwinNewControl(uiControl *c, Class class, BOOL inScrollView, BOOL scrollViewHasBorder);
extern BOOL uiDarwinControlFreeWhenAppropriate(uiControl *c, NSView *newSuperview); extern BOOL uiDarwinControlFreeWhenAppropriate(uiControl *c, NSView *newSuperview);
// You can use this function from within your control implementations to return text strings that can be freed with uiTextFree(). // You can use this function from within your control implementations to return text strings that can be freed with uiTextFree().