2015-08-16 19:56:39 -05:00
|
|
|
// 7 april 2015
|
|
|
|
|
|
|
|
/*
|
|
|
|
This file assumes that you have imported <Cocoa/Cocoa.h> 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__
|
|
|
|
|
2015-11-16 09:55:44 -06:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-08-16 22:16:42 -05:00
|
|
|
typedef struct uiDarwinControl uiDarwinControl;
|
|
|
|
struct uiDarwinControl {
|
|
|
|
uiControl c;
|
2016-04-24 18:56:14 -05:00
|
|
|
uiControl *parent;
|
|
|
|
BOOL enabled;
|
|
|
|
BOOL visible;
|
2016-04-25 16:52:16 -05:00
|
|
|
void (*SyncEnableState)(uiDarwinControl *, int);
|
2016-04-25 08:57:05 -05:00
|
|
|
void (*SetSuperview)(uiDarwinControl *, NSView *);
|
2016-05-11 16:00:01 -05:00
|
|
|
BOOL (*HugsTrailingEdge)(uiDarwinControl *);
|
|
|
|
BOOL (*HugsBottom)(uiDarwinControl *);
|
|
|
|
void (*ChildEdgeHuggingChanged)(uiDarwinControl *);
|
2015-08-16 22:16:42 -05:00
|
|
|
};
|
2016-04-24 13:15:56 -05:00
|
|
|
#define uiDarwinControl(this) ((uiDarwinControl *) (this))
|
2015-08-17 18:11:35 -05:00
|
|
|
// TODO document
|
2016-04-25 16:52:16 -05:00
|
|
|
_UI_EXTERN void uiDarwinControlSyncEnableState(uiDarwinControl *, int);
|
2016-04-25 08:57:05 -05:00
|
|
|
_UI_EXTERN void uiDarwinControlSetSuperview(uiDarwinControl *, NSView *);
|
2016-05-11 16:00:01 -05:00
|
|
|
_UI_EXTERN BOOL uiDarwinControlHugsTrailingEdge(uiDarwinControl *);
|
|
|
|
_UI_EXTERN BOOL uiDarwinControlHugsBottom(uiDarwinControl *);
|
|
|
|
_UI_EXTERN void uiDarwinControlChildEdgeHuggingChanged(uiDarwinControl *);
|
2015-08-16 22:16:42 -05:00
|
|
|
|
2016-04-24 18:56:14 -05:00
|
|
|
#define uiDarwinControlDefaultDestroy(type, handlefield) \
|
|
|
|
static void type ## Destroy(uiControl *c) \
|
2015-08-16 19:56:39 -05:00
|
|
|
{ \
|
2016-04-24 18:56:14 -05:00
|
|
|
uiControlVerifyDestroy(c); \
|
|
|
|
[type(c)->handlefield release]; \
|
2016-04-25 12:44:13 -05:00
|
|
|
uiFreeControl(c); \
|
2016-04-24 18:56:14 -05:00
|
|
|
}
|
|
|
|
#define uiDarwinControlDefaultHandle(type, handlefield) \
|
|
|
|
static uintptr_t type ## Handle(uiControl *c) \
|
2015-08-16 19:56:39 -05:00
|
|
|
{ \
|
2015-08-16 22:16:42 -05:00
|
|
|
return (uintptr_t) (type(c)->handlefield); \
|
2016-04-24 18:56:14 -05:00
|
|
|
}
|
2016-04-25 08:57:05 -05:00
|
|
|
#define uiDarwinControlDefaultParent(type, handlefield) \
|
2016-04-24 18:56:14 -05:00
|
|
|
static uiControl *type ## Parent(uiControl *c) \
|
2015-08-16 21:19:15 -05:00
|
|
|
{ \
|
2016-04-24 18:56:14 -05:00
|
|
|
return uiDarwinControl(c)->parent; \
|
|
|
|
}
|
|
|
|
#define uiDarwinControlDefaultSetParent(type, handlefield) \
|
|
|
|
static void type ## SetParent(uiControl *c, uiControl *parent) \
|
|
|
|
{ \
|
|
|
|
uiControlVerifySetParent(c, parent); \
|
|
|
|
uiDarwinControl(c)->parent = parent; \
|
2016-04-24 20:51:08 -05:00
|
|
|
}
|
2016-04-25 09:23:16 -05:00
|
|
|
#define uiDarwinControlDefaultToplevel(type, handlefield) \
|
2016-04-24 20:51:08 -05:00
|
|
|
static int type ## Toplevel(uiControl *c) \
|
|
|
|
{ \
|
|
|
|
return 0; \
|
|
|
|
}
|
2016-04-25 08:57:05 -05:00
|
|
|
#define uiDarwinControlDefaultVisible(type, handlefield) \
|
|
|
|
static int type ## Visible(uiControl *c) \
|
2016-04-24 20:51:08 -05:00
|
|
|
{ \
|
|
|
|
return uiDarwinControl(c)->visible; \
|
|
|
|
}
|
2016-04-25 08:57:05 -05:00
|
|
|
#define uiDarwinControlDefaultShow(type, handlefield) \
|
|
|
|
static void type ## Show(uiControl *c) \
|
2016-04-24 20:51:08 -05:00
|
|
|
{ \
|
2016-04-25 08:57:05 -05:00
|
|
|
uiDarwinControl(c)->visible = YES; \
|
|
|
|
[type(c)->handlefield setHidden:NO]; \
|
2016-04-24 18:56:14 -05:00
|
|
|
}
|
2016-04-25 08:57:05 -05:00
|
|
|
#define uiDarwinControlDefaultHide(type, handlefield) \
|
|
|
|
static void type ## Hide(uiControl *c) \
|
2015-08-17 18:11:35 -05:00
|
|
|
{ \
|
2016-04-25 08:57:05 -05:00
|
|
|
uiDarwinControl(c)->visible = NO; \
|
|
|
|
[type(c)->handlefield setHidden:YES]; \
|
|
|
|
}
|
|
|
|
#define uiDarwinControlDefaultEnabled(type, handlefield) \
|
2016-04-25 12:38:17 -05:00
|
|
|
static int type ## Enabled(uiControl *c) \
|
2016-04-25 08:57:05 -05:00
|
|
|
{ \
|
|
|
|
return uiDarwinControl(c)->enabled; \
|
|
|
|
}
|
2016-04-25 09:23:16 -05:00
|
|
|
#define uiDarwinControlDefaultEnable(type, handlefield) \
|
2016-04-25 08:57:05 -05:00
|
|
|
static void type ## Enable(uiControl *c) \
|
|
|
|
{ \
|
|
|
|
uiDarwinControl(c)->enabled = YES; \
|
2016-04-25 16:52:16 -05:00
|
|
|
uiDarwinControlSyncEnableState(uiDarwinControl(c), uiControlEnabledToUser(c)); \
|
2016-04-25 08:57:05 -05:00
|
|
|
}
|
2016-04-25 09:23:16 -05:00
|
|
|
#define uiDarwinControlDefaultDisable(type, handlefield) \
|
2016-04-25 08:57:05 -05:00
|
|
|
static void type ## Disable(uiControl *c) \
|
|
|
|
{ \
|
|
|
|
uiDarwinControl(c)->enabled = NO; \
|
2016-04-25 16:52:16 -05:00
|
|
|
uiDarwinControlSyncEnableState(uiDarwinControl(c), uiControlEnabledToUser(c)); \
|
2016-04-25 08:57:05 -05:00
|
|
|
}
|
|
|
|
#define uiDarwinControlDefaultSyncEnableState(type, handlefield) \
|
2016-04-25 16:52:16 -05:00
|
|
|
static void type ## SyncEnableState(uiDarwinControl *c, int enabled) \
|
2016-04-25 08:57:05 -05:00
|
|
|
{ \
|
2016-04-25 17:07:29 -05:00
|
|
|
if (uiDarwinShouldStopSyncEnableState(c, enabled)) \
|
|
|
|
return; \
|
2016-04-25 12:38:17 -05:00
|
|
|
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 */ \
|
2016-04-25 08:57:05 -05:00
|
|
|
}
|
|
|
|
#define uiDarwinControlDefaultSetSuperview(type, handlefield) \
|
2016-04-25 09:00:31 -05:00
|
|
|
static void type ## SetSuperview(uiDarwinControl *c, NSView *superview) \
|
2016-04-25 08:57:05 -05:00
|
|
|
{ \
|
2016-04-25 11:55:51 -05:00
|
|
|
[type(c)->handlefield setTranslatesAutoresizingMaskIntoConstraints:NO]; \
|
2016-04-25 08:57:05 -05:00
|
|
|
if (superview == nil) \
|
|
|
|
[type(c)->handlefield removeFromSuperview]; \
|
|
|
|
else \
|
|
|
|
[superview addSubview:type(c)->handlefield]; \
|
2015-08-16 19:56:39 -05:00
|
|
|
}
|
2016-05-11 16:00:01 -05:00
|
|
|
#define uiDarwinControlDefaultHugsTrailingEdge(type, handlefield) \
|
|
|
|
static BOOL type ## HugsTrailingEdge(uiDarwinControl *c) \
|
|
|
|
{ \
|
|
|
|
return YES; /* always hug by default */ \
|
|
|
|
}
|
|
|
|
#define uiDarwinControlDefaultHugsBottom(type, handlefield) \
|
|
|
|
static BOOL type ## HugsBottom(uiDarwinControl *c) \
|
|
|
|
{ \
|
|
|
|
return YES; /* always hug by default */ \
|
|
|
|
}
|
|
|
|
#define uiDarwinControlDefaultChildEdgeHuggingChanged(type, handlefield) \
|
|
|
|
static void type ## ChildEdgeHuggingChanged(uiDarwinControl *c) \
|
|
|
|
{ \
|
|
|
|
/* do nothing */ \
|
|
|
|
}
|
2015-08-16 19:56:39 -05:00
|
|
|
|
2016-04-25 09:23:16 -05:00
|
|
|
#define uiDarwinControlAllDefaultsExceptDestroy(type, handlefield) \
|
2016-04-24 18:56:14 -05:00
|
|
|
uiDarwinControlDefaultHandle(type, handlefield) \
|
2016-04-25 08:57:05 -05:00
|
|
|
uiDarwinControlDefaultParent(type, handlefield) \
|
2016-04-24 20:51:08 -05:00
|
|
|
uiDarwinControlDefaultSetParent(type, handlefield) \
|
2016-04-25 08:57:05 -05:00
|
|
|
uiDarwinControlDefaultToplevel(type, handlefield) \
|
|
|
|
uiDarwinControlDefaultVisible(type, handlefield) \
|
|
|
|
uiDarwinControlDefaultShow(type, handlefield) \
|
|
|
|
uiDarwinControlDefaultHide(type, handlefield) \
|
|
|
|
uiDarwinControlDefaultEnabled(type, handlefield) \
|
|
|
|
uiDarwinControlDefaultEnable(type, handlefield) \
|
|
|
|
uiDarwinControlDefaultDisable(type, handlefield) \
|
2016-04-25 09:23:16 -05:00
|
|
|
uiDarwinControlDefaultSyncEnableState(type, handlefield) \
|
2016-05-11 16:00:01 -05:00
|
|
|
uiDarwinControlDefaultSetSuperview(type, handlefield) \
|
|
|
|
uiDarwinControlDefaultHugsTrailingEdge(type, handlefield) \
|
|
|
|
uiDarwinControlDefaultHugsBottom(type, handlefield) \
|
|
|
|
uiDarwinControlDefaultChildEdgeHuggingChanged(type, handlefield)
|
2015-08-16 19:56:39 -05:00
|
|
|
|
2016-04-25 09:23:16 -05:00
|
|
|
#define uiDarwinControlAllDefaults(type, handlefield) \
|
|
|
|
uiDarwinControlDefaultDestroy(type, handlefield) \
|
|
|
|
uiDarwinControlAllDefaultsExceptDestroy(type, handlefield)
|
|
|
|
|
2016-04-24 14:46:29 -05:00
|
|
|
// TODO document
|
2016-04-25 09:23:16 -05:00
|
|
|
#define uiDarwinNewControl(type, var) \
|
2016-04-25 12:38:17 -05:00
|
|
|
var = type(uiDarwinAllocControl(sizeof (type), type ## Signature, #type)); \
|
2016-04-25 08:57:05 -05:00
|
|
|
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; \
|
2016-04-25 16:52:16 -05:00
|
|
|
uiDarwinControl(var)->SyncEnableState = type ## SyncEnableState; \
|
2016-04-25 12:44:13 -05:00
|
|
|
uiDarwinControl(var)->SetSuperview = type ## SetSuperview; \
|
2016-05-11 16:00:01 -05:00
|
|
|
uiDarwinControl(var)->HugsTrailingEdge = type ## HugsTrailingEdge; \
|
|
|
|
uiDarwinControl(var)->HugsBottom = type ## HugsBottom; \
|
|
|
|
uiDarwinControl(var)->ChildEdgeHuggingChanged = type ## ChildEdgeHuggingChanged; \
|
2016-04-25 12:44:13 -05:00
|
|
|
uiDarwinControl(var)->visible = YES; \
|
|
|
|
uiDarwinControl(var)->enabled = YES;
|
2016-04-25 08:57:05 -05:00
|
|
|
// TODO document
|
2016-04-24 18:56:14 -05:00
|
|
|
_UI_EXTERN uiDarwinControl *uiDarwinAllocControl(size_t n, uint32_t typesig, const char *typenamestr);
|
2016-04-24 14:46:29 -05:00
|
|
|
|
2015-08-16 19:56:39 -05:00
|
|
|
// 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 *);
|
|
|
|
|
2016-04-25 17:07:29 -05:00
|
|
|
// TODO document
|
|
|
|
_UI_EXTERN BOOL uiDarwinShouldStopSyncEnableState(uiDarwinControl *, BOOL);
|
|
|
|
|
2015-11-16 09:55:44 -06:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-08-16 19:56:39 -05:00
|
|
|
#endif
|