// 7 april 2015 /* This file assumes that you have imported and "ui.h" beforehand. It provides API-specific functions for interfacing with foreign controls on Mac OS X. */ #ifndef __LIBUI_UI_DARWIN_H__ #define __LIBUI_UI_DARWIN_H__ #ifdef __cplusplus extern "C" { #endif typedef struct uiDarwinControl uiDarwinControl; struct uiDarwinControl { uiControl c; uiControl *parent; BOOL enabled; BOOL visible; void (*SetSuperview)(uiDarwinControl *, NSView *); }; #define uiDarwinControl(this) ((uiDarwinControl *) (this)) // TODO document _UI_EXTERN void uiDarwinControlSetSuperview(uiDarwinControl *, NSView *); #define uiDarwinControlDefaultDestroy(type, handlefield) \ static void type ## Destroy(uiControl *c) \ { \ uiControlVerifyDestroy(c); \ [type(c)->handlefield release]; \ } #define uiDarwinControlDefaultHandle(type, handlefield) \ static uintptr_t type ## Handle(uiControl *c) \ { \ return (uintptr_t) (type(c)->handlefield); \ } #define uiDarwinControlDefaultParent(type, handlefield) \ static uiControl *type ## Parent(uiControl *c) \ { \ return uiDarwinControl(c)->parent; \ } #define uiDarwinControlDefaultSetParent(type, handlefield) \ static void type ## SetParent(uiControl *c, uiControl *parent) \ { \ uiControlVerifySetParent(c, parent); \ uiDarwinControl(c)->parent = parent; \ if (uiDarwinControl(c)->parent == NULL) \ [type(c)->handlefield removeFromSuperview]; \ else \ uiDarwinControlAddSubview(uiDarwinControl(uiDarwinControl(c)->parent), type(c)->handlefield); \ } #define uiDarwinControlDefaultToplevel(type) \ static int type ## Toplevel(uiControl *c) \ { \ return 0; \ } #define uiDarwinControlDefaultVisible(type, handlefield) \ static int type ## Visible(uiControl *c) \ { \ return uiDarwinControl(c)->visible; \ } #define uiDarwinControlDefaultShow(type, handlefield) \ static void type ## Show(uiControl *c) \ { \ uiDarwinControl(c)->visible = YES; \ [type(c)->handlefield setHidden:NO]; \ } #define uiDarwinControlDefaultHide(type, handlefield) \ static void type ## Hide(uiControl *c) \ { \ uiDarwinControl(c)->visible = NO; \ [type(c)->handlefield setHidden:YES]; \ } #define uiDarwinControlDefaultEnabled(type, handlefield) \ static int type ## Visible(uiControl *c) \ { \ return uiDarwinControl(c)->enabled; \ } #define uiDarwinControlDefaultEnabled(type, handlefield) \ static void type ## Enable(uiControl *c) \ { \ uiDarwinControl(c)->enabled = YES; \ uiControlSyncEnableState(c, uiControlEnabledToUser(c)); \ } #define uiDarwinControlDefaultHide(type, handlefield) \ static void type ## Disable(uiControl *c) \ { \ uiDarwinControl(c)->enabled = NO; \ uiControlSyncEnableState(c, uiControlEnabledToUser(c)); \ } #define uiDarwinControlDefaultSyncEnableState(type, handlefield) \ static void type ## SyncEnableState(uiControl *c, int enabled) \ { \ if ([type(e)->handlefield respondsToSelector:@selector(setEnabled:)]) \ [type(e)->handlefield setEnabled:enabled]; \ } #define uiDarwinControlDefaultSetSuperview(type, handlefield) \ static void type ## AddSubview(uiDarwinControl *c, NSView *superview) \ { \ if (superview == nil) \ [type(c)->handlefield removeFromSuperview]; \ else \ [superview addSubview:type(c)->handlefield]; \ } #define uiDarwinControlAllDefaults(type, handlefield) \ uiDarwinControlDefaultDestroy(type, handlefield) \ uiDarwinControlDefaultHandle(type, handlefield) \ uiDarwinControlDefaultParent(type, handlefield) \ uiDarwinControlDefaultSetParent(type, handlefield) \ uiDarwinControlDefaultToplevel(type, handlefield) \ uiDarwinControlDefaultVisible(type, handlefield) \ uiDarwinControlDefaultShow(type, handlefield) \ uiDarwinControlDefaultHide(type, handlefield) \ uiDarwinControlDefaultEnabled(type, handlefield) \ uiDarwinControlDefaultEnable(type, handlefield) \ uiDarwinControlDefaultDisable(type, handlefield) \ uiDarwinControlDefaultSetEnableState(type, handlefield) \ uiDarwinControlDefaultSetSuperview(type, handlefield) // TODO document #define uiDarwinNewControl(var, type) \ var = type(uiDarwinNewControl(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; \ uiDarwinControl(var)->SetSuperview = type ## SetSuperview; // TODO document _UI_EXTERN uiDarwinControl *uiDarwinAllocControl(size_t n, uint32_t typesig, const char *typenamestr); // Use this function as a shorthand for setting control fonts. _UI_EXTERN void uiDarwinSetControlFont(NSControl *c, NSControlSize size); // You can use this function from within your control implementations to return text strings that can be freed with uiFreeText(). _UI_EXTERN char *uiDarwinNSStringToText(NSString *); #ifdef __cplusplus } #endif #endif