Carbon Composited GUIs now work with SDKs > 10.6, although they will be inefficient...
[wdl/wdl-ol.git] / WDL / IPlug / IGraphicsMac.h
blob1c8bd7182b4694e0e839591e08c14e362227995a
1 #ifndef _IGRAPHICSMAC_
2 #define _IGRAPHICSMAC_
4 #if defined(__APPLE__) && defined(__LP64__) && !defined(IPLUG_NO_CARBON_SUPPORT)
5 #define IPLUG_NO_CARBON_SUPPORT
6 #endif
8 // carbon support uses quickdraw methods that have been removed in SDKs > 10.6
9 #if __MAC_OS_X_VERSION_MAX_ALLOWED > 1060
10 #warning Carbon GUIs work best with the 10.6 sdk
11 #endif
13 #include "IGraphics.h"
14 #include "../swell/swell.h"
16 #ifdef VST3_API
17 #define _UINT32 // this is necessary to get VST3 to compile with the 10.6 SDK due to a conflict
18 #endif
20 #include <Carbon/Carbon.h>
22 #ifndef DEFAULT_PATH_OSX
23 #define DEFAULT_PATH_OSX "~/Desktop"
24 #endif
26 #ifndef IPLUG_NO_CARBON_SUPPORT
27 class IGraphicsCarbon;
28 #endif
30 #ifndef COCOA_PREFIX
31 #define COCOA_PREFIX vOliLarkin
32 #endif
34 #if defined(VST_API)
35 #define API _vst
36 #elif defined(AU_API)
37 #define API _au
38 #elif defined(RTAS_API)
39 #define API _rtas
40 #elif defined(AAX_API)
41 #define API _aax
42 #elif defined(VST3_API)
43 #define API _vst3
44 #elif defined(SA_API)
45 #define API _sa
46 #endif
48 #define CONCAT3(a,b,c) a##b##c
49 #define CONCAT2(a,b,c) CONCAT3(a,b,c)
50 #define CONCAT(cname) CONCAT2(cname,COCOA_PREFIX,API)
52 #define IGRAPHICS_COCOA CONCAT(IGraphicsCocoa_)
53 #define IGRAPHICS_NSMENU CONCAT(IGraphicsNSMenu_)
54 #define IGRAPHICS_MENU_RCVR CONCAT(IGraphicsMenuRcvr_)
55 #define CUSTOM_COCOA_WINDOW CONCAT(CustomCocoaWindow_)
56 #define COCOA_FORMATTER CONCAT(CocoaFormatter_)
58 class IGraphicsMac : public IGraphics
60 public:
61 IGraphicsMac(IPlugBase* pPlug, int w, int h, int refreshFPS);
62 virtual ~IGraphicsMac();
64 void SetBundleID(const char* bundleID) { mBundleID.Set(bundleID); }
66 bool DrawScreen(IRECT* pR);
67 bool MeasureIText(IText* pTxt, char* str, IRECT* pR);
69 void* OpenWindow(void* pWindow);
70 #ifndef IPLUG_NO_CARBON_SUPPORT
71 void* OpenWindow(void* pWindow, void* pControl, short leftOffset = 0, short topOffset = 0);
72 #endif
74 void* OpenCocoaWindow(void* pParentView);
75 #ifndef IPLUG_NO_CARBON_SUPPORT
76 void* OpenCarbonWindow(void* pParentWnd, void* pParentControl, short leftOffset, short topOffset);
77 #endif
79 void AttachSubWindow(void* hostWindowRef);
80 void RemoveSubWindow();
82 void CloseWindow();
83 bool WindowIsOpen();
84 void Resize(int w, int h);
86 void HideMouseCursor();
87 void ShowMouseCursor();
89 int ShowMessageBox(const char* pText, const char* pCaption, int type);
90 void ForceEndUserEdit();
92 const char* GetGUIAPI();
94 void UpdateTooltips();
96 void HostPath(WDL_String* pPath);
97 void PluginPath(WDL_String* pPath);
98 void DesktopPath(WDL_String* pPath);
99 void AppSupportPath(WDL_String* pPath);
101 void PromptForFile(WDL_String* pFilename, EFileAction action = kFileOpen, WDL_String* pDir = 0, char* extensions = ""); // extensions = "txt wav" for example.
102 bool PromptForColor(IColor* pColor, char* prompt = "");
104 IPopupMenu* CreateIPopupMenu(IPopupMenu* pMenu, IRECT* pTextRect);
105 void CreateTextEntry(IControl* pControl, IText* pText, IRECT* pTextRect, const char* pString, IParam* pParam );
107 bool OpenURL(const char* url, const char* msgWindowTitle = 0, const char* confirmMsg = 0, const char* errMsgOnFailure = 0);
109 void* GetWindow();
111 const char* GetBundleID() { return mBundleID.Get(); }
112 static int GetUserOSVersion(); // Returns a number like 0x1050 (10.5).
114 protected:
115 virtual LICE_IBitmap* OSLoadBitmap(int ID, const char* name);
117 private:
118 #ifndef IPLUG_NO_CARBON_SUPPORT
119 IGraphicsCarbon* mGraphicsCarbon;
120 #endif
121 void* mGraphicsCocoa; // Can't forward-declare IGraphicsCocoa because it's an obj-C object.
123 WDL_String mBundleID;
125 friend int GetMouseOver(IGraphicsMac* pGraphics);
127 #ifndef IPLUG_NO_CARBON_SUPPORT
128 friend class IGraphicsCarbon;
129 #endif
131 public: //TODO: make this private
132 void* mHostNSWindow;
135 inline CFStringRef MakeCFString(const char* cStr)
137 return CFStringCreateWithCString(0, cStr, kCFStringEncodingUTF8);
140 struct CFStrLocal
142 CFStringRef mCFStr;
143 CFStrLocal(const char* cStr)
145 mCFStr = MakeCFString(cStr);
147 ~CFStrLocal()
149 CFRelease(mCFStr);
153 struct CStrLocal
155 char* mCStr;
156 CStrLocal(CFStringRef cfStr)
158 int n = CFStringGetLength(cfStr) + 1;
159 mCStr = (char*) malloc(n);
160 CFStringGetCString(cfStr, mCStr, n, kCFStringEncodingUTF8);
162 ~CStrLocal()
164 FREE_NULL(mCStr);
168 inline CGRect ToCGRect(int h, IRECT* pR)
170 int B = h - pR->B;
171 return CGRectMake(pR->L, B, pR->W(), B + pR->H());
174 inline int AdjustFontSize(int size)
176 return int(0.9 * (double)size);
179 #endif