ASPiK SDK
macstring.h
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 #ifndef __macstring__
6 #define __macstring__
7 
8 #include "../iplatformstring.h"
9 
10 #if MAC
11 #include "../../cstring.h"
12 #include <CoreFoundation/CoreFoundation.h>
13 #include "cfontmac.h"
14 
15 #if defined(__OBJC__)
16 #import <Foundation/Foundation.h>
17 #else
18 struct NSString;
19 #endif
20 
21 namespace VSTGUI {
22 
23 //-----------------------------------------------------------------------------
24 class MacString : public IPlatformString
25 {
26 public:
27  MacString (UTF8StringPtr utf8String);
28  ~MacString () noexcept override;
29 
30  void setUTF8String (UTF8StringPtr utf8String) override;
31 
32  CFStringRef getCFString () const { return cfString; }
33 
34  CTLineRef getCTLine () const { return ctLine; }
35  const void* getCTLineFontRef () const { return ctLineFontRef; }
36  const CColor& getCTLineColor () const { return ctLineColor; }
37 
38  void setCTLine (CTLineRef line, const void* fontRef, const CColor& color);
39 //-----------------------------------------------------------------------------
40 protected:
41  CFStringRef cfString;
42  CTLineRef ctLine;
43  const void* ctLineFontRef;
44  CColor ctLineColor;
45 };
46 
47 //-----------------------------------------------------------------------------
48 template <typename T>
49 inline T fromUTF8String (const UTF8String& str)
50 {
51  vstgui_assert (false);
52  return nullptr;
53 }
54 
55 //-----------------------------------------------------------------------------
56 template <>
57 inline CFStringRef fromUTF8String (const UTF8String& str)
58 {
59  if (auto macString = dynamic_cast<MacString*> (str.getPlatformString ()))
60  return macString->getCFString ();
61  return nullptr;
62 }
63 
64 #ifdef __OBJC__
65 //-----------------------------------------------------------------------------
66 template <>
67 inline NSString* fromUTF8String (const UTF8String& str)
68 {
69  if (auto macString = dynamic_cast<MacString*> (str.getPlatformString ()))
70  return (__bridge NSString*) (macString->getCFString ());
71  return nil;
72 }
73 #endif // __OBJC__
74 
75 } // namespace
76 
77 #endif // MAC
78 
79 #endif // __macstring__
Definition: customcontrols.cpp:8