From 2cd336903d933661a96c38bcf1b00ba3b817df32 Mon Sep 17 00:00:00 2001 From: Pietro Gagliardi Date: Sun, 16 Aug 2015 20:56:39 -0400 Subject: [PATCH] Rewrote the public-facing OS X control macro. --- redo/reredo/ui.h | 1 + redo/reredo/ui_darwin.h | 48 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 redo/reredo/ui_darwin.h diff --git a/redo/reredo/ui.h b/redo/reredo/ui.h index 51488646..ae6eaf5b 100644 --- a/redo/reredo/ui.h +++ b/redo/reredo/ui.h @@ -49,6 +49,7 @@ struct Sizing { typedef struct uiControl uiControl; struct uiControl { + uiTyped t; void *Internal; // for use by libui only void (*CommitDestroy)(uiControl *); uintptr_t (*Handle)(uiControl *); diff --git a/redo/reredo/ui_darwin.h b/redo/reredo/ui_darwin.h new file mode 100644 index 00000000..0c8f4da2 --- /dev/null +++ b/redo/reredo/ui_darwin.h @@ -0,0 +1,48 @@ +// 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__ + +// TODO document +#define uiDarwinDefineControlWithOnDestroy(type, typefn, handlefield, onDestroy) \ + static uintmax_t _ ## type ## Type = 0; \ + uintmax_t typefn(void) \ + { \ + if (_ ## type ## Type == 0) \ + _ ## type ## Type = uiRegisterType(#type, uiDarwinControlType(), sizeof (type)); \ + return _ ## type ## Type; \ + } \ + static void _ ## type ## CommitDestroy(uiControl *c) \ + { \ + type *this = type(c); \ + onDestroy; \ + [this->handlefield release]; \ + } \ + static uintptr_t _ ## type ## Handle(uiControl *c) \ + { \ + return type(c)->handlefield; \ + } + +#define uiDarwinDefineControl(type, typefn, handlefield) \ + uiDarwinDefineControlWithOnDestroy(type, typefn, handlefield, (void) this;) + +#define uiDarwinFinishNewControl(variable, type) \ + type(variable)->CommitDestroy = _ ## type ## CommitDestroy; \ + type(variable)->Handle = _ ## type ## Handle; \ + 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 *); + +#endif