]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/private.h
expose metal appearance
[wxWidgets.git] / include / wx / mac / carbon / private.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: private.h
3 // Purpose: Private declarations: as this header is only included by
4 // wxWindows itself, it may contain identifiers which don't start
5 // with "wx".
6 // Author: Stefan Csomor
7 // Modified by:
8 // Created: 1998-01-01
9 // RCS-ID: $Id$
10 // Copyright: (c) Stefan Csomor
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
13
14 #ifndef _WX_PRIVATE_H_
15 #define _WX_PRIVATE_H_
16
17 #include "wx/defs.h"
18 #include "wx/app.h"
19
20 #ifdef __DARWIN__
21 # include <Carbon/Carbon.h>
22 #else
23 # include <Debugging.h>
24 # include <Quickdraw.h>
25 # include <Appearance.h>
26 # include <Folders.h>
27 # include <Controls.h>
28 # include <ControlDefinitions.h>
29 # include <LowMem.h>
30 # include <Gestalt.h>
31 #endif
32
33 #if UNIVERSAL_INTERFACES_VERSION < 0x0340
34 #error "please update to Apple's lastest universal headers from http://developer.apple.com/sdk/"
35 #endif
36
37 #if wxUSE_GUI
38
39 #include "wx/window.h"
40
41 class wxMacPortStateHelper
42 {
43 DECLARE_NO_COPY_CLASS(wxMacPortStateHelper)
44
45 public:
46 wxMacPortStateHelper( GrafPtr newport) ;
47 wxMacPortStateHelper() ;
48 ~wxMacPortStateHelper() ;
49
50 void Setup( GrafPtr newport ) ;
51 void Clear() ;
52 bool IsCleared() { return m_clip == NULL ; }
53 GrafPtr GetCurrentPort() { return m_currentPort ; }
54
55 private:
56 GrafPtr m_currentPort ;
57 GrafPtr m_oldPort ;
58 RgnHandle m_clip ;
59 ThemeDrawingState m_drawingState ;
60 short m_textFont ;
61 short m_textSize ;
62 short m_textStyle ;
63 short m_textMode ;
64 } ;
65
66 class WXDLLEXPORT wxMacPortSaver
67 {
68 DECLARE_NO_COPY_CLASS(wxMacPortSaver)
69
70 public:
71 wxMacPortSaver( GrafPtr port )
72 {
73 ::GetPort( &m_port ) ;
74 ::SetPort( port ) ;
75 }
76 ~wxMacPortSaver()
77 {
78 ::SetPort( m_port ) ;
79 }
80 private :
81 GrafPtr m_port ;
82 } ;
83
84 class WXDLLEXPORT wxMacPortSetter
85 {
86 DECLARE_NO_COPY_CLASS(wxMacPortSetter)
87
88 public:
89 wxMacPortSetter( const wxDC* dc ) ;
90 ~wxMacPortSetter() ;
91 private:
92 wxMacPortStateHelper m_ph ;
93 const wxDC* m_dc ;
94 } ;
95
96 /*
97 Clips to the visible region of a control within the current port
98 */
99
100 class WXDLLEXPORT wxMacWindowClipper : public wxMacPortSaver
101 {
102 DECLARE_NO_COPY_CLASS(wxMacWindowClipper)
103
104 public:
105 wxMacWindowClipper( const wxWindow* win ) ;
106 ~wxMacWindowClipper() ;
107 private:
108 RgnHandle m_formerClip ;
109 RgnHandle m_newClip ;
110 } ;
111
112 /*
113 class wxMacDrawingHelper
114 {
115 DECLARE_NO_COPY_CLASS(wxMacDrawingHelper)
116
117 public:
118 wxMacDrawingHelper( wxWindowMac * theWindow , bool clientArea = false ) ;
119 ~wxMacDrawingHelper() ;
120 bool Ok() { return m_ok ; }
121 void LocalToWindow( Rect *rect) { OffsetRect( rect , m_origin.h , m_origin.v ) ; }
122 void LocalToWindow( Point *pt ) { AddPt( m_origin , pt ) ; }
123 void LocalToWindow( RgnHandle rgn ) { OffsetRgn( rgn , m_origin.h , m_origin.v ) ; }
124 const Point& GetOrigin() { return m_origin ; }
125 private:
126 Point m_origin ;
127 GrafPtr m_formerPort ;
128 GrafPtr m_currentPort ;
129 PenState m_savedPenState ;
130 bool m_ok ;
131 } ;
132 */
133
134 // app.h
135 bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec) ;
136
137 #endif // wxUSE_GUI
138
139 // filefn.h
140 WXDLLEXPORT wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) ;
141 WXDLLEXPORT void wxMacFilename2FSSpec( const char *path , FSSpec *spec ) ;
142 WXDLLEXPORT void wxMacFilename2FSSpec( const wxChar *path , FSSpec *spec ) ;
143 # ifndef __DARWIN__
144 // Mac file names are POSIX (Unix style) under Darwin, so these are not needed
145 WXDLLEXPORT wxString wxMacFSSpec2UnixFilename( const FSSpec *spec ) ;
146 WXDLLEXPORT void wxUnixFilename2FSSpec( const char *path , FSSpec *spec ) ;
147 WXDLLEXPORT wxString wxMac2UnixFilename( const char *s) ;
148 WXDLLEXPORT wxString wxUnix2MacFilename( const char *s);
149 # endif
150
151 // utils.h
152 WXDLLEXPORT wxString wxMacFindFolder(short vRefNum,
153 OSType folderType,
154 Boolean createFolder);
155
156 #if wxUSE_GUI
157
158 GWorldPtr wxMacCreateGWorld( int width , int height , int depth ) ;
159 void wxMacDestroyGWorld( GWorldPtr gw ) ;
160 PicHandle wxMacCreatePict( GWorldPtr gw , GWorldPtr mask = NULL ) ;
161 CIconHandle wxMacCreateCIcon(GWorldPtr image , GWorldPtr mask , short dstDepth , short iconSize ) ;
162 void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue ) ;
163 CTabHandle wxMacCreateColorTable( int numColors ) ;
164 void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType = 0 ) ;
165
166 #define MAC_WXCOLORREF(a) (*((RGBColor*)&(a)))
167 #define MAC_WXHBITMAP(a) (GWorldPtr(a))
168 #define MAC_WXHMETAFILE(a) (PicHandle(a))
169 #define MAC_WXHICON(a) (CIconHandle(a))
170 #define MAC_WXHCURSOR(a) (CursHandle(a))
171 #define MAC_WXHRGN(a) (RgnHandle(a))
172 #define MAC_WXHWND(a) (WindowPtr(a))
173 #define MAC_WXRECPTR(a) ((Rect*)a)
174 #define MAC_WXPOINTPTR(a) ((Point*)a)
175 #define MAC_WXHMENU(a) ((MenuHandle)a)
176
177 struct wxOpaqueWindowRef
178 {
179 wxOpaqueWindowRef( WindowRef ref ) { m_data = ref ; }
180 operator WindowRef() { return m_data ; }
181 private :
182 WindowRef m_data ;
183 } ;
184
185 wxWindow *wxFindControlFromMacControl(ControlRef inControl ) ;
186 wxTopLevelWindowMac* wxFindWinFromMacWindow( WindowRef inWindow ) ;
187 extern wxWindow* g_MacLastWindow ;
188 pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ;
189 Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size ) ;
190
191 template<typename T> EventParamType wxMacGetEventParamType() { wxFAIL_MSG( wxT("Unknown Param Type") ) ; return 0 ; }
192 template<> inline EventParamType wxMacGetEventParamType<RgnHandle>() { return typeQDRgnHandle ; }
193 template<> inline EventParamType wxMacGetEventParamType<ControlRef>() { return typeControlRef ; }
194 template<> inline EventParamType wxMacGetEventParamType<WindowRef>() { return typeWindowRef ; }
195 template<> inline EventParamType wxMacGetEventParamType<MenuRef>() { return typeMenuRef ; }
196 template<> inline EventParamType wxMacGetEventParamType<EventRef>() { return typeEventRef ; }
197 template<> inline EventParamType wxMacGetEventParamType<Point>() { return typeQDPoint ; }
198 template<> inline EventParamType wxMacGetEventParamType<Rect>() { return typeQDRectangle ; }
199 template<> inline EventParamType wxMacGetEventParamType<Boolean>() { return typeBoolean ; }
200 #if TARGET_API_MAC_OSX
201 template<> inline EventParamType wxMacGetEventParamType<HIPoint>() { return typeHIPoint ; }
202 template<> inline EventParamType wxMacGetEventParamType<HISize>() { return typeHISize ; }
203 template<> inline EventParamType wxMacGetEventParamType<HIRect>() { return typeHIRect ; }
204 template<> inline EventParamType wxMacGetEventParamType<void*>() { return typeVoidPtr ; }
205 #endif
206 template<> inline EventParamType wxMacGetEventParamType<Collection>() { return typeCollection ; }
207 template<> inline EventParamType wxMacGetEventParamType<CGContextRef>() { return typeCGContextRef ; }
208 /*
209 These are ambiguous
210 template<> EventParamType wxMacGetEventParamType<GrafPtr>() { return typeGrafPtr ; }
211 template<> EventParamType wxMacGetEventParamType<OSStatus>() { return typeOSStatus ; }
212 template<> EventParamType wxMacGetEventParamType<CFIndex>() { return typeCFIndex ; }
213 template<> EventParamType wxMacGetEventParamType<GWorldPtr>() { return typeGWorldPtr ; }
214 */
215
216 class wxMacCarbonEvent
217 {
218
219 public :
220 wxMacCarbonEvent( EventRef event )
221 {
222 m_eventRef = event ;
223 }
224
225 OSStatus GetParameter( EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) ;
226
227 template <typename T> OSStatus GetParameter( EventParamName inName, EventParamType type , T *data )
228 {
229 return GetParameter( inName, type , sizeof( T ) , data ) ;
230 }
231 template <typename T> OSStatus GetParameter( EventParamName inName, T *data )
232 {
233 return GetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ;
234 }
235
236 template <typename T> T GetParameter( EventParamName inName )
237 {
238 T value ;
239 verify_noerr( GetParameter<T>( inName, &value ) ) ;
240 return value ;
241 }
242 template <typename T> T GetParameter( EventParamName inName, EventParamType inDesiredType )
243 {
244 T value ;
245 verify_noerr( GetParameter<T>( inName, inDesiredType , &value ) ) ;
246 return value ;
247 }
248
249
250 OSStatus SetParameter( EventParamName inName, EventParamType inType, UInt32 inSize, void * inData) ;
251 template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType type , T *data )
252 {
253 return SetParameter( inName, type , sizeof( T ) , data ) ;
254 }
255 template <typename T> OSStatus SetParameter( EventParamName inName, T *data )
256 {
257 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ;
258 }
259
260 EventKind GetKind()
261 {
262 return ::GetEventKind( m_eventRef ) ;
263 }
264 EventTime GetTime()
265 {
266 return ::GetEventTime( m_eventRef ) ;
267 }
268 UInt32 GetTicks()
269 {
270 return EventTimeToTicks( GetTime() ) ;
271 }
272 protected :
273 EventRef m_eventRef ;
274 } ;
275
276 #endif // wxUSE_GUI
277
278 //---------------------------------------------------------------------------
279 // wxMac string conversions
280 //---------------------------------------------------------------------------
281
282 void wxMacSetupConverters() ;
283 void wxMacCleanupConverters() ;
284
285 void wxMacStringToPascal( const wxString&from , StringPtr to ) ;
286 wxString wxMacMakeStringFromPascal( ConstStringPtr from ) ;
287
288 void wxMacConvertNewlines13To10( char * data ) ;
289 void wxMacConvertNewlines10To13( char * data ) ;
290 void wxMacConvertNewlines13To10( wxString *data ) ;
291 void wxMacConvertNewlines10To13( wxString *data ) ;
292
293 #if wxUSE_UNICODE
294 void wxMacConvertNewlines13To10( wxChar * data ) ;
295 void wxMacConvertNewlines10To13( wxChar * data ) ;
296 #endif
297
298 #if TARGET_CARBON
299
300 class wxMacCFStringHolder
301 {
302 public:
303 wxMacCFStringHolder()
304 {
305 m_cfs = NULL ;
306 m_release = false ;
307 }
308
309 wxMacCFStringHolder(const wxString &str , wxFontEncoding encoding )
310 {
311 m_cfs = NULL ;
312 m_release = false ;
313 Assign( str , encoding ) ;
314 }
315
316 wxMacCFStringHolder(CFStringRef ref , bool release = true )
317 {
318 m_cfs = ref ;
319 m_release = release ;
320 }
321
322 ~wxMacCFStringHolder()
323 {
324 Release() ;
325 }
326
327 CFStringRef Detach()
328 {
329 CFStringRef retval = m_cfs ;
330 m_release = false ;
331 m_cfs = NULL ;
332 return retval ;
333 }
334
335 void Release()
336 {
337 if ( m_release && m_cfs)
338 CFRelease( m_cfs ) ;
339 m_cfs = NULL ;
340 }
341
342 void Assign( const wxString &str , wxFontEncoding encoding ) ;
343
344 operator CFStringRef () { return m_cfs; }
345 wxString AsString( wxFontEncoding encoding = wxFONTENCODING_DEFAULT ) ;
346
347 private:
348
349 CFStringRef m_cfs;
350 bool m_release ;
351 } ;
352
353 #endif
354
355
356
357 wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding) ;
358 wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding) ;
359
360
361 #endif
362 // _WX_PRIVATE_H_