1 // This file is part of VSTGUI. It is subject to the license terms 2 // in the LICENSE file found in the top-level directory of this 3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE 4 5 #pragma once 6 7 #include "../iplatformstring.h" 8 9 #if MAC 10 #include "../../cstring.h" 11 #include <CoreFoundation/CoreFoundation.h> 12 #include "cfontmac.h" 13 14 #if defined(__OBJC__) 15 #import <Foundation/Foundation.h> 16 #else 17 struct NSString; 18 #endif 19 20 namespace VSTGUI { 21 22 //----------------------------------------------------------------------------- 23 class MacString : public IPlatformString 24 { 25 public: 26 MacString (UTF8StringPtr utf8String); 27 ~MacString () noexcept override; 28 29 void setUTF8String (UTF8StringPtr utf8String) override; 30 getCFString()31 CFStringRef getCFString () const { return cfString; } 32 getCTLine()33 CTLineRef getCTLine () const { return ctLine; } getCTLineFontRef()34 const void* getCTLineFontRef () const { return ctLineFontRef; } getCTLineColor()35 const CColor& getCTLineColor () const { return ctLineColor; } 36 37 void setCTLine (CTLineRef line, const void* fontRef, const CColor& color); 38 //----------------------------------------------------------------------------- 39 protected: 40 CFStringRef cfString; 41 CTLineRef ctLine; 42 const void* ctLineFontRef; 43 CColor ctLineColor; 44 }; 45 46 //----------------------------------------------------------------------------- 47 template <typename T> fromUTF8String(const UTF8String & str)48inline T fromUTF8String (const UTF8String& str) 49 { 50 vstgui_assert (false); 51 return nullptr; 52 } 53 54 //----------------------------------------------------------------------------- 55 template <> fromUTF8String(const UTF8String & str)56inline CFStringRef fromUTF8String (const UTF8String& str) 57 { 58 if (auto macString = dynamic_cast<MacString*> (str.getPlatformString ())) 59 return macString->getCFString (); 60 return nullptr; 61 } 62 63 #ifdef __OBJC__ 64 //----------------------------------------------------------------------------- 65 template <> fromUTF8String(const UTF8String & str)66inline NSString* fromUTF8String (const UTF8String& str) 67 { 68 if (auto macString = dynamic_cast<MacString*> (str.getPlatformString ())) 69 return (__bridge NSString*) (macString->getCFString ()); 70 return nil; 71 } 72 #endif // __OBJC__ 73 74 } // VSTGUI 75 76 #endif // MAC 77