5 #ifndef __cocoahelpers__ 6 #define __cocoahelpers__ 8 #import "../../../crect.h" 9 #import "../../../cpoint.h" 10 #import "../../../ccolor.h" 12 #if MAC_COCOA && defined (__OBJC__) 14 #import <objc/runtime.h> 15 #import <objc/message.h> 16 #import <Cocoa/Cocoa.h> 19 #define HIDDEN __attribute__((__visibility__("hidden"))) 22 #define VSTGUI_CHECK_YES(x) { BOOL res = x; vstgui_assert (res == YES); } 24 #define VSTGUI_CHECK_YES(x) x; 28 inline HIDDEN
id get_Objc_Value (
id obj,
const char* name)
30 Ivar ivar = class_getInstanceVariable ([obj
class], name);
33 id value = object_getIvar (obj, ivar);
40 inline HIDDEN
void set_Objc_Value (
id obj,
const char* name,
id value)
42 Ivar ivar = class_getInstanceVariable ([obj
class], name);
45 object_setIvar (obj, ivar, value);
49 #define __OBJC_SUPER(x) objc_super __os; __os.receiver = x; __os.super_class = class_getSuperclass ([x class]); 51 #define OBJC_GET_VALUE(x,y) get_Objc_Value (x, #y) 52 #define OBJC_SET_VALUE(x,y,z) set_Objc_Value (x, #y, (id)z) 54 extern HIDDEN Class generateUniqueClass (NSMutableString* className, Class baseClass);
55 extern HIDDEN
VstKeyCode CreateVstKeyCodeFromNSEvent (NSEvent* theEvent);
56 extern HIDDEN NSString* GetVirtualKeyCodeString (int32_t virtualKeyCode);
57 extern HIDDEN int32_t eventButton (NSEvent* theEvent);
58 extern HIDDEN
void convertPointToGlobal (NSView* view, NSPoint& p);
63 HIDDEN
inline NSRect nsRectFromCRect (
const VSTGUI::CRect& rect)
66 r.origin.x =
static_cast<CGFloat
> (rect.left);
67 r.origin.y =
static_cast<CGFloat
> (rect.top);
68 r.size.width =
static_cast<CGFloat
> (rect.getWidth ());
69 r.size.height =
static_cast<CGFloat
> (rect.getHeight ());
74 HIDDEN
inline NSPoint nsPointFromCPoint (
const VSTGUI::CPoint& point)
76 NSPoint p = {
static_cast<CGFloat
>(point.x), static_cast<CGFloat>(point.y) };
81 HIDDEN
inline VSTGUI::CRect rectFromNSRect (
const NSRect& rect)
84 r.setWidth (rect.size.width);
85 r.setHeight (rect.size.height);
90 HIDDEN
inline VSTGUI::CPoint pointFromNSPoint (
const NSPoint& point)
97 HIDDEN
inline NSColor* nsColorFromCColor (
const VSTGUI::CColor& color)
99 return [NSColor colorWithDeviceRed:
static_cast<CGFloat
> (color.
red/255.) green:
static_cast<CGFloat
> (color.
green/255.) blue:
static_cast<CGFloat
> (color.
blue/255.) alpha:
static_cast<CGFloat
> (color.
alpha/255.)];
103 HIDDEN
inline NSImage* imageFromCGImageRef (CGImageRef image)
105 return [[NSImage alloc] initWithCGImage:image size:NSZeroSize];
109 struct MacEventModifier
113 #ifdef MAC_OS_X_VERSION_10_12 114 ShiftKeyMask = NSEventModifierFlagShift,
115 CommandKeyMask = NSEventModifierFlagCommand,
116 AlternateKeyMask = NSEventModifierFlagOption,
117 ControlKeyMask = NSEventModifierFlagControl
119 ShiftKeyMask = NSShiftKeyMask,
120 CommandKeyMask = NSCommandKeyMask,
121 AlternateKeyMask = NSAlternateKeyMask,
122 ControlKeyMask = NSControlKeyMask
128 namespace MacEventType
130 #ifdef MAC_OS_X_VERSION_10_12 131 static constexpr
auto LeftMouseDown = ::NSEventTypeLeftMouseDown;
132 static constexpr
auto LeftMouseDragged = ::NSEventTypeLeftMouseDragged;
133 static constexpr
auto MouseMoved = ::NSEventTypeMouseMoved;
135 static constexpr
auto LeftMouseDown = ::NSLeftMouseDown;
136 static constexpr
auto LeftMouseDragged = ::NSLeftMouseDragged;
137 static constexpr
auto MouseMoved = ::NSMouseMoved;
142 namespace MacWindowStyleMask
144 #ifdef MAC_OS_X_VERSION_10_12 145 static constexpr
auto Borderless = ::NSWindowStyleMaskBorderless;
146 static constexpr
auto Titled = ::NSWindowStyleMaskTitled;
147 static constexpr
auto Resizable = ::NSWindowStyleMaskResizable;
148 static constexpr
auto Miniaturizable = ::NSWindowStyleMaskMiniaturizable;
149 static constexpr
auto Closable = ::NSWindowStyleMaskClosable;
150 static constexpr
auto Utility = ::NSWindowStyleMaskUtilityWindow;
152 static constexpr
auto Borderless = ::NSBorderlessWindowMask;
153 static constexpr
auto Titled = ::NSTitledWindowMask;
154 static constexpr
auto Resizable = ::NSResizableWindowMask;
155 static constexpr
auto Miniaturizable = ::NSMiniaturizableWindowMask;
156 static constexpr
auto Closable = ::NSClosableWindowMask;
157 static constexpr
auto Utility = ::NSUtilityWindowMask;
162 #endif // __cocoahelpers__ Rect structure.
Definition: crect.h:17
Definition: vstkeycode.h:12
RGBA Color structure.
Definition: ccolor.h:15
uint8_t blue
blue component [0..255]
Definition: ccolor.h:97
uint8_t green
green component [0..255]
Definition: ccolor.h:96
uint8_t alpha
alpha component [0..255]
Definition: ccolor.h:98
uint8_t red
red component [0..255]
Definition: ccolor.h:95
Point structure.
Definition: cpoint.h:17