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-24 20:51:08 -05:00
|
|
|
void (*AddSubview)(uiDarwinControl *, NSView *);
|
2015-08-17 18:19:02 -05:00
|
|
|
void (*Relayout)(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-24 20:51:08 -05:00
|
|
|
_UI_EXTERN void uiDarwinControlAddSubview(uiDarwinControl *, NSView *);
|
2015-08-18 18:57:16 -05:00
|
|
|
_UI_EXTERN void uiDarwinControlTriggerRelayout(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]; \
|
|
|
|
}
|
|
|
|
#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
|
|
|
}
|
|
|
|
#define uiDarwinControlDefaultParent(type) \
|
|
|
|
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; \
|
|
|
|
if (uiDarwinControl(c)->parent == NULL) \
|
|
|
|
[type(c)->handlefield removeFromSuperview]; \
|
2016-04-24 20:51:08 -05:00
|
|
|
else \
|
|
|
|
uiDarwinControlAddSubview(uiDarwinControl(uiDarwinControl(c)->parent), type(c)->handlefield); \
|
|
|
|
}
|
|
|
|
#define uiDarwinControlDefaultToplevel(type) \
|
|
|
|
static int type ## Toplevel(uiControl *c) \
|
|
|
|
{ \
|
|
|
|
return 0; \
|
|
|
|
}
|
|
|
|
#define uiDarwinControlDefaultVisible(type) \
|
|
|
|
static int type ## Visible(uiDarwinControl *c) \
|
|
|
|
{ \
|
|
|
|
/* TODO */ \
|
|
|
|
return uiDarwinControl(c)->visible; \
|
|
|
|
}
|
|
|
|
// TODO others here
|
|
|
|
#define uiDarwinControlDefaultAddSubview(type) \
|
|
|
|
static void type ## AddSubview(uiDarwinControl *c, NSView *subview) \
|
|
|
|
{ \
|
|
|
|
/* TODO do nothing or log? one of the two */ \
|
2016-04-24 18:56:14 -05:00
|
|
|
}
|
|
|
|
#define uiDarwinControlDefaultRelayout(type) \
|
|
|
|
static void type ## Relayout(uiDarwinControl *c) \
|
2015-08-17 18:11:35 -05:00
|
|
|
{ \
|
2015-08-18 18:57:16 -05:00
|
|
|
/* do nothing */ \
|
2015-08-16 19:56:39 -05:00
|
|
|
}
|
|
|
|
|
2016-04-24 18:56:14 -05:00
|
|
|
#define uiDarwinControlAllDefaults(type, handlefield) \
|
|
|
|
uiDarwinControlDefaultDestroy(type, handlefield) \
|
|
|
|
uiDarwinControlDefaultHandle(type, handlefield) \
|
|
|
|
uiDarwinControlDefaultParent(type) \
|
2016-04-24 20:51:08 -05:00
|
|
|
uiDarwinControlDefaultSetParent(type, handlefield) \
|
|
|
|
uiDarwinControlDefaultToplevel(type) \
|
2016-04-24 18:56:14 -05:00
|
|
|
xxxxx \
|
2016-04-24 20:51:08 -05:00
|
|
|
uiDarwinControlDefaultAddSubview(type) \
|
2016-04-24 18:56:14 -05:00
|
|
|
uiDarwinControlDefaultRelayout(type)
|
2015-08-16 19:56:39 -05:00
|
|
|
|
2016-04-24 14:46:29 -05:00
|
|
|
// TODO document
|
2016-04-24 20:51:08 -05:00
|
|
|
#define uiDarwinNewControl(var, type) \
|
|
|
|
var = type(uiDarwinNewControl(sizeof (type), type ## Signature, #type)) \
|
|
|
|
TODO
|
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
|
|
|
#define uiDarwinFinishNewControl(variable, type) \
|
2015-08-16 22:08:00 -05:00
|
|
|
uiControl(variable)->CommitDestroy = _ ## type ## CommitDestroy; \
|
|
|
|
uiControl(variable)->Handle = _ ## type ## Handle; \
|
|
|
|
uiControl(variable)->ContainerUpdateState = _ ## type ## ContainerUpdateState; \
|
2015-08-17 18:11:35 -05:00
|
|
|
uiDarwinControl(variable)->Relayout = _ ## type ## Relayout; \
|
2015-08-16 19:56:39 -05:00
|
|
|
uiDarwinFinishControl(uiControl(variable));
|
|
|
|
|
|
|
|
// This is a function used to set up a control.
|
|
|
|
// Don't call it directly; use uiDarwinFinishNewControl() instead.
|
|
|
|
_UI_EXTERN void uiDarwinFinishControl(uiControl *c);
|
|
|
|
|
|
|
|
// 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 *);
|
|
|
|
|
2015-11-16 09:55:44 -06:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-08-16 19:56:39 -05:00
|
|
|
#endif
|