From a651caac8973c57c7f4c8bc6d4e0473d5bc83fca Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Mon, 25 Apr 2016 16:45:49 -0400 Subject: [PATCH] Started migrating ui_unix.h. SyncEnableState can be dropped from the GTK+ port, so let's do that next. --- ui_unix.h | 138 ++++++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 112 insertions(+), 26 deletions(-) diff --git a/ui_unix.h b/ui_unix.h index d3c456f8..425f197b 100644 --- a/ui_unix.h +++ b/ui_unix.h @@ -14,42 +14,128 @@ extern "C" { typedef struct uiUnixControl uiUnixControl; struct uiUnixControl { uiControl c; + void (*SetContainer)(uiUnixControl *, GtkContainer *, gboolean); }; #define uiUnixControl(this) ((uiUnixControl *) (this)) - // TODO document -#define uiUnixDefineControlWithOnDestroy(type, onDestroy) \ - static void _ ## type ## CommitDestroy(uiControl *c) \ +_UI_EXTERN void uiUnixControlSetContainer(uiUnixControl *, GtkContainer *, gboolean); + +#define uiUnixControlDefaultDestroy(type, handlefield) \ + static void type ## Destroy(uiControl *c) \ { \ - type *this = type(c); \ - onDestroy; \ - g_object_unref(this->widget); \ - } \ - static uintptr_t _ ## type ## Handle(uiControl *c) \ + uiControlVerifyDestroy(c); \ + [type(c)->handlefield release]; \ + uiFreeControl(c); \ + } +#define uiUnixControlDefaultHandle(type, handlefield) \ + static uintptr_t type ## Handle(uiControl *c) \ { \ - return (uintptr_t) (type(c)->widget); \ - } \ - static void _ ## type ## ContainerUpdateState(uiControl *c) \ + return (uintptr_t) (type(c)->handlefield); \ + } +#define uiUnixControlDefaultParent(type, handlefield) \ + static uiControl *type ## Parent(uiControl *c) \ { \ - /* do nothing */ \ + return uiUnixControl(c)->parent; \ + } +#define uiUnixControlDefaultSetParent(type, handlefield) \ + static void type ## SetParent(uiControl *c, uiControl *parent) \ + { \ + uiControlVerifySetParent(c, parent); \ + uiUnixControl(c)->parent = parent; \ + } +#define uiUnixControlDefaultToplevel(type, handlefield) \ + static int type ## Toplevel(uiControl *c) \ + { \ + return 0; \ + } +#define uiUnixControlDefaultVisible(type, handlefield) \ + static int type ## Visible(uiControl *c) \ + { \ + return uiUnixControl(c)->visible; \ + } +#define uiUnixControlDefaultShow(type, handlefield) \ + static void type ## Show(uiControl *c) \ + { \ + uiUnixControl(c)->visible = YES; \ + [type(c)->handlefield setHidden:NO]; \ + } +#define uiUnixControlDefaultHide(type, handlefield) \ + static void type ## Hide(uiControl *c) \ + { \ + uiUnixControl(c)->visible = NO; \ + [type(c)->handlefield setHidden:YES]; \ + } +#define uiUnixControlDefaultEnabled(type, handlefield) \ + static int type ## Enabled(uiControl *c) \ + { \ + return uiUnixControl(c)->enabled; \ + } +#define uiUnixControlDefaultEnable(type, handlefield) \ + static void type ## Enable(uiControl *c) \ + { \ + uiUnixControl(c)->enabled = YES; \ + uiControlSyncEnableState(c, uiControlEnabledToUser(c)); \ + } +#define uiUnixControlDefaultDisable(type, handlefield) \ + static void type ## Disable(uiControl *c) \ + { \ + uiUnixControl(c)->enabled = NO; \ + uiControlSyncEnableState(c, uiControlEnabledToUser(c)); \ + } +#define uiUnixControlDefaultSyncEnableState(type, handlefield) \ + static void type ## SyncEnableState(uiControl *c, int enabled) \ + { \ + if ([type(c)->handlefield respondsToSelector:@selector(setEnabled:)]) \ + [((id) type(c)->handlefield) setEnabled:enabled]; /* id cast to make compiler happy; thanks mikeash in irc.freenode.net/#macdev */ \ + } +#define uiUnixControlDefaultSetSuperview(type, handlefield) \ + static void type ## SetSuperview(uiUnixControl *c, NSView *superview) \ + { \ + [type(c)->handlefield setTranslatesAutoresizingMaskIntoConstraints:NO]; \ + if (superview == nil) \ + [type(c)->handlefield removeFromSuperview]; \ + else \ + [superview addSubview:type(c)->handlefield]; \ } -#define uiUnixDefineControl(type) \ - uiUnixDefineControlWithOnDestroy(type, (void) this;) +#define uiUnixControlAllDefaultsExceptDestroy(type, handlefield) \ + uiUnixControlDefaultHandle(type, handlefield) \ + uiUnixControlDefaultParent(type, handlefield) \ + uiUnixControlDefaultSetParent(type, handlefield) \ + uiUnixControlDefaultToplevel(type, handlefield) \ + uiUnixControlDefaultVisible(type, handlefield) \ + uiUnixControlDefaultShow(type, handlefield) \ + uiUnixControlDefaultHide(type, handlefield) \ + uiUnixControlDefaultEnabled(type, handlefield) \ + uiUnixControlDefaultEnable(type, handlefield) \ + uiUnixControlDefaultDisable(type, handlefield) \ + uiUnixControlDefaultSyncEnableState(type, handlefield) \ + uiUnixControlDefaultSetSuperview(type, handlefield) + +#define uiUnixControlAllDefaults(type, handlefield) \ + uiUnixControlDefaultDestroy(type, handlefield) \ + uiUnixControlAllDefaultsExceptDestroy(type, handlefield) // TODO document -#define uiNewControl(type) uiUnixNewControl(sizeof (type), type ## Signature, #type) -_UI_EXTERN uiUnixControl *uiUnixNewControl(size_t n, uint32_t typesig, const char *typenamestr); - -#define uiUnixFinishNewControl(variable, type) \ - uiControl(variable)->CommitDestroy = _ ## type ## CommitDestroy; \ - uiControl(variable)->Handle = _ ## type ## Handle; \ - uiControl(variable)->ContainerUpdateState = _ ## type ## ContainerUpdateState; \ - uiUnixFinishControl(uiControl(variable)); - -// This is a function used to set up a control. -// Don't call it directly; use uiUnixFinishNewControl() instead. -_UI_EXTERN void uiUnixFinishControl(uiControl *c); +#define uiUnixNewControl(type, var) \ + var = type(uiUnixAllocControl(sizeof (type), type ## Signature, #type)); \ + uiControl(var)->Destroy = type ## Destroy; \ + uiControl(var)->Handle = type ## Handle; \ + uiControl(var)->Parent = type ## Parent; \ + uiControl(var)->SetParent = type ## SetParent; \ + uiControl(var)->Toplevel = type ## Toplevel; \ + uiControl(var)->Visible = type ## Visible; \ + uiControl(var)->Show = type ## Show; \ + uiControl(var)->Hide = type ## Hide; \ + uiControl(var)->Enabled = type ## Enabled; \ + uiControl(var)->Enable = type ## Enable; \ + uiControl(var)->Disable = type ## Disable; \ + uiControl(var)->SyncEnableState = type ## SyncEnableState; \ + uiUnixControl(var)->SetSuperview = type ## SetSuperview; \ + uiUnixControl(var)->visible = YES; \ + uiUnixControl(var)->enabled = YES; +// TODO document +_UI_EXTERN uiUnixControl *uiUnixAllocControl(size_t n, uint32_t typesig, const char *typenamestr); // uiUnixStrdupText() takes the given string and produces a copy of it suitable for being freed by uiFreeText(). _UI_EXTERN char *uiUnixStrdupText(const char *);