]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/private.h
split wxRegion(wxBitmap) ctor into two ctors with clearer semantics
[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 // wxWidgets 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 #ifndef MAC_OS_X_VERSION_10_3
38 #define MAC_OS_X_VERSION_10_3 1030
39 #endif
40
41 #if wxUSE_GUI
42
43 #include "wx/window.h"
44
45 class wxMacPortStateHelper
46 {
47 DECLARE_NO_COPY_CLASS(wxMacPortStateHelper)
48
49 public:
50 wxMacPortStateHelper( GrafPtr newport) ;
51 wxMacPortStateHelper() ;
52 ~wxMacPortStateHelper() ;
53
54 void Setup( GrafPtr newport ) ;
55 void Clear() ;
56 bool IsCleared() { return m_clip == NULL ; }
57 GrafPtr GetCurrentPort() { return m_currentPort ; }
58
59 private:
60 GrafPtr m_currentPort ;
61 GrafPtr m_oldPort ;
62 RgnHandle m_clip ;
63 ThemeDrawingState m_drawingState ;
64 short m_textFont ;
65 short m_textSize ;
66 short m_textStyle ;
67 short m_textMode ;
68 } ;
69
70 class WXDLLEXPORT wxMacPortSaver
71 {
72 DECLARE_NO_COPY_CLASS(wxMacPortSaver)
73
74 public:
75 wxMacPortSaver( GrafPtr port )
76 {
77 ::GetPort( &m_port ) ;
78 ::SetPort( port ) ;
79 }
80 ~wxMacPortSaver()
81 {
82 ::SetPort( m_port ) ;
83 }
84 private :
85 GrafPtr m_port ;
86 } ;
87
88 class WXDLLEXPORT wxMacPortSetter
89 {
90 DECLARE_NO_COPY_CLASS(wxMacPortSetter)
91
92 public:
93 wxMacPortSetter( const wxDC* dc ) ;
94 ~wxMacPortSetter() ;
95 private:
96 wxMacPortStateHelper m_ph ;
97 const wxDC* m_dc ;
98 } ;
99
100 /*
101 Clips to the visible region of a control within the current port
102 */
103
104 class WXDLLEXPORT wxMacWindowClipper : public wxMacPortSaver
105 {
106 DECLARE_NO_COPY_CLASS(wxMacWindowClipper)
107
108 public:
109 wxMacWindowClipper( const wxWindow* win ) ;
110 ~wxMacWindowClipper() ;
111 private:
112 GrafPtr m_newPort ;
113 RgnHandle m_formerClip ;
114 RgnHandle m_newClip ;
115 } ;
116
117 class WXDLLEXPORT wxMacWindowStateSaver : public wxMacWindowClipper
118 {
119 DECLARE_NO_COPY_CLASS(wxMacWindowStateSaver)
120
121 public:
122 wxMacWindowStateSaver( const wxWindow* win ) ;
123 ~wxMacWindowStateSaver() ;
124 private:
125 GrafPtr m_newPort ;
126 ThemeDrawingState m_themeDrawingState ;
127 } ;
128
129 /*
130 class wxMacDrawingHelper
131 {
132 DECLARE_NO_COPY_CLASS(wxMacDrawingHelper)
133
134 public:
135 wxMacDrawingHelper( wxWindowMac * theWindow , bool clientArea = false ) ;
136 ~wxMacDrawingHelper() ;
137 bool Ok() { return m_ok ; }
138 void LocalToWindow( Rect *rect) { OffsetRect( rect , m_origin.h , m_origin.v ) ; }
139 void LocalToWindow( Point *pt ) { AddPt( m_origin , pt ) ; }
140 void LocalToWindow( RgnHandle rgn ) { OffsetRgn( rgn , m_origin.h , m_origin.v ) ; }
141 const Point& GetOrigin() { return m_origin ; }
142 private:
143 Point m_origin ;
144 GrafPtr m_formerPort ;
145 GrafPtr m_currentPort ;
146 PenState m_savedPenState ;
147 bool m_ok ;
148 } ;
149 */
150
151 // app.h
152 bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec) ;
153
154 #endif // wxUSE_GUI
155
156 // filefn.h
157 WXDLLEXPORT wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) ;
158 WXDLLEXPORT void wxMacFilename2FSSpec( const char *path , FSSpec *spec ) ;
159 WXDLLEXPORT void wxMacFilename2FSSpec( const wxChar *path , FSSpec *spec ) ;
160 # ifndef __DARWIN__
161 // Mac file names are POSIX (Unix style) under Darwin, so these are not needed
162 WXDLLEXPORT wxString wxMacFSSpec2UnixFilename( const FSSpec *spec ) ;
163 WXDLLEXPORT void wxUnixFilename2FSSpec( const char *path , FSSpec *spec ) ;
164 WXDLLEXPORT wxString wxMac2UnixFilename( const char *s) ;
165 WXDLLEXPORT wxString wxUnix2MacFilename( const char *s);
166 # endif
167
168 // utils.h
169 WXDLLEXPORT wxString wxMacFindFolder(short vRefNum,
170 OSType folderType,
171 Boolean createFolder);
172
173 #if wxUSE_GUI
174
175 GWorldPtr wxMacCreateGWorld( int width , int height , int depth ) ;
176 void wxMacDestroyGWorld( GWorldPtr gw ) ;
177 PicHandle wxMacCreatePict( GWorldPtr gw , GWorldPtr mask = NULL ) ;
178 CIconHandle wxMacCreateCIcon(GWorldPtr image , GWorldPtr mask , short dstDepth , short iconSize ) ;
179 void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue ) ;
180 CTabHandle wxMacCreateColorTable( int numColors ) ;
181 void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType = 0 ) ;
182
183 #define MAC_WXCOLORREF(a) (*((RGBColor*)&(a)))
184 #define MAC_WXHBITMAP(a) (GWorldPtr(a))
185 #define MAC_WXHMETAFILE(a) (PicHandle(a))
186 #define MAC_WXHICON(a) (CIconHandle(a))
187 #define MAC_WXHCURSOR(a) (CursHandle(a))
188 #define MAC_WXHRGN(a) (RgnHandle(a))
189 #define MAC_WXHWND(a) (WindowPtr(a))
190 #define MAC_WXRECPTR(a) ((Rect*)a)
191 #define MAC_WXPOINTPTR(a) ((Point*)a)
192 #define MAC_WXHMENU(a) ((MenuHandle)a)
193
194 struct wxOpaqueWindowRef
195 {
196 wxOpaqueWindowRef( WindowRef ref ) { m_data = ref ; }
197 operator WindowRef() { return m_data ; }
198 private :
199 WindowRef m_data ;
200 } ;
201
202 wxWindow * wxFindControlFromMacControl(ControlRef inControl ) ;
203 wxTopLevelWindowMac* wxFindWinFromMacWindow( WindowRef inWindow ) ;
204 wxMenu* wxFindMenuFromMacMenu(MenuRef inMenuRef) ;
205
206 extern wxWindow* g_MacLastWindow ;
207 pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ;
208 Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin = true ) ;
209
210 template<typename T> EventParamType wxMacGetEventParamType() { wxFAIL_MSG( wxT("Unknown Param Type") ) ; return 0 ; }
211 template<> inline EventParamType wxMacGetEventParamType<RgnHandle>() { return typeQDRgnHandle ; }
212 template<> inline EventParamType wxMacGetEventParamType<ControlRef>() { return typeControlRef ; }
213 template<> inline EventParamType wxMacGetEventParamType<WindowRef>() { return typeWindowRef ; }
214 template<> inline EventParamType wxMacGetEventParamType<MenuRef>() { return typeMenuRef ; }
215 template<> inline EventParamType wxMacGetEventParamType<EventRef>() { return typeEventRef ; }
216 template<> inline EventParamType wxMacGetEventParamType<Point>() { return typeQDPoint ; }
217 template<> inline EventParamType wxMacGetEventParamType<Rect>() { return typeQDRectangle ; }
218 template<> inline EventParamType wxMacGetEventParamType<Boolean>() { return typeBoolean ; }
219 #if TARGET_API_MAC_OSX
220 template<> inline EventParamType wxMacGetEventParamType<HIPoint>() { return typeHIPoint ; }
221 template<> inline EventParamType wxMacGetEventParamType<HISize>() { return typeHISize ; }
222 template<> inline EventParamType wxMacGetEventParamType<HIRect>() { return typeHIRect ; }
223 template<> inline EventParamType wxMacGetEventParamType<void*>() { return typeVoidPtr ; }
224 #endif
225 template<> inline EventParamType wxMacGetEventParamType<Collection>() { return typeCollection ; }
226 template<> inline EventParamType wxMacGetEventParamType<CGContextRef>() { return typeCGContextRef ; }
227 /*
228 These are ambiguous
229 template<> EventParamType wxMacGetEventParamType<GrafPtr>() { return typeGrafPtr ; }
230 template<> EventParamType wxMacGetEventParamType<OSStatus>() { return typeOSStatus ; }
231 template<> EventParamType wxMacGetEventParamType<CFIndex>() { return typeCFIndex ; }
232 template<> EventParamType wxMacGetEventParamType<GWorldPtr>() { return typeGWorldPtr ; }
233 */
234
235 class wxMacCarbonEvent
236 {
237
238 public :
239 wxMacCarbonEvent( EventRef event )
240 {
241 m_eventRef = event ;
242 }
243
244 OSStatus GetParameter( EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) ;
245
246 template <typename T> OSStatus GetParameter( EventParamName inName, EventParamType type , T *data )
247 {
248 return GetParameter( inName, type , sizeof( T ) , data ) ;
249 }
250 template <typename T> OSStatus GetParameter( EventParamName inName, T *data )
251 {
252 return GetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ;
253 }
254
255 template <typename T> T GetParameter( EventParamName inName )
256 {
257 T value ;
258 verify_noerr( GetParameter<T>( inName, &value ) ) ;
259 return value ;
260 }
261 template <typename T> T GetParameter( EventParamName inName, EventParamType inDesiredType )
262 {
263 T value ;
264 verify_noerr( GetParameter<T>( inName, inDesiredType , &value ) ) ;
265 return value ;
266 }
267
268
269 OSStatus SetParameter( EventParamName inName, EventParamType inType, UInt32 inSize, void * inData) ;
270 template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , T *data )
271 {
272 return SetParameter( inName, inDesiredType , sizeof( T ) , data ) ;
273 }
274 template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , T data )
275 {
276 return SetParameter<T>( inName, inDesiredType , &data ) ;
277 }
278 template <typename T> OSStatus SetParameter( EventParamName inName, T *data )
279 {
280 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ;
281 }
282 template <typename T> OSStatus SetParameter( EventParamName inName, T data )
283 {
284 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , &data ) ;
285 }
286 UInt32 GetClass()
287 {
288 return ::GetEventClass( m_eventRef ) ;
289 }
290 UInt32 GetKind()
291 {
292 return ::GetEventKind( m_eventRef ) ;
293 }
294 EventTime GetTime()
295 {
296 return ::GetEventTime( m_eventRef ) ;
297 }
298 UInt32 GetTicks()
299 {
300 return EventTimeToTicks( GetTime() ) ;
301 }
302 protected :
303 EventRef m_eventRef ;
304 } ;
305
306 class wxMacControl
307 {
308 public :
309 wxMacControl( ControlRef control )
310 {
311 m_controlRef = control ;
312 }
313 wxMacControl( WXWidget control )
314 {
315 m_controlRef = (ControlRef) control ;
316 }
317
318 OSStatus SetData( ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData ) ;
319 OSStatus GetData( ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) ;
320 OSStatus GetDataSize( ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) ;
321 Size GetDataSize( ControlPartCode inPartCode , ResType inTag )
322 {
323 Size sz ;
324 verify_noerr( GetDataSize( inPartCode , inTag , &sz ) ) ;
325 return sz ;
326 }
327 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , T *data )
328 {
329 return SetData( inPartCode , inTag , sizeof( T ) , data ) ;
330 }
331 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , T data )
332 {
333 return SetData( inPartCode , inTag , sizeof( T ) , &data ) ;
334 }
335 template <typename T> OSStatus GetData( ControlPartCode inPartCode , ResType inTag , T *data )
336 {
337 Size dummy ;
338 return GetData( inPartCode , inTag , sizeof( T ) , data , &dummy ) ;
339 }
340 template <typename T> T GetData( ControlPartCode inPartCode , ResType inTag )
341 {
342 T value ;
343 verify_noerr( GetData<T>( inPartCode , inTag , &value ) ) ;
344 return value ;
345 }
346 operator ControlRef () { return m_controlRef; }
347 operator ControlRef * () { return &m_controlRef; }
348 protected :
349 ControlRef m_controlRef ;
350 } ;
351
352 #endif // wxUSE_GUI
353
354 //---------------------------------------------------------------------------
355 // wxMac string conversions
356 //---------------------------------------------------------------------------
357
358 void wxMacSetupConverters() ;
359 void wxMacCleanupConverters() ;
360
361 void wxMacStringToPascal( const wxString&from , StringPtr to ) ;
362 wxString wxMacMakeStringFromPascal( ConstStringPtr from ) ;
363
364 void wxMacConvertNewlines13To10( char * data ) ;
365 void wxMacConvertNewlines10To13( char * data ) ;
366 void wxMacConvertNewlines13To10( wxString *data ) ;
367 void wxMacConvertNewlines10To13( wxString *data ) ;
368
369 #if wxUSE_UNICODE
370 void wxMacConvertNewlines13To10( wxChar * data ) ;
371 void wxMacConvertNewlines10To13( wxChar * data ) ;
372 #endif
373
374 #if TARGET_CARBON
375
376 class wxMacCFStringHolder
377 {
378 public:
379 wxMacCFStringHolder()
380 {
381 m_cfs = NULL ;
382 m_release = false ;
383 }
384
385 wxMacCFStringHolder(const wxString &str , wxFontEncoding encoding )
386 {
387 m_cfs = NULL ;
388 m_release = false ;
389 Assign( str , encoding ) ;
390 }
391
392 wxMacCFStringHolder(CFStringRef ref , bool release = true )
393 {
394 m_cfs = ref ;
395 m_release = release ;
396 }
397
398 ~wxMacCFStringHolder()
399 {
400 Release() ;
401 }
402
403 CFStringRef Detach()
404 {
405 CFStringRef retval = m_cfs ;
406 m_release = false ;
407 m_cfs = NULL ;
408 return retval ;
409 }
410
411 void Release()
412 {
413 if ( m_release && m_cfs)
414 CFRelease( m_cfs ) ;
415 m_cfs = NULL ;
416 }
417
418 void Assign( const wxString &str , wxFontEncoding encoding ) ;
419
420 operator CFStringRef () { return m_cfs; }
421 wxString AsString( wxFontEncoding encoding = wxFONTENCODING_DEFAULT ) ;
422
423 private:
424
425 CFStringRef m_cfs;
426 bool m_release ;
427 } ;
428
429 #endif
430
431 // utils.cpp
432
433 wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding) ;
434 wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding) ;
435 void wxMacWakeUp() ;
436
437 // toplevel.cpp
438
439 ControlRef wxMacFindControlUnderMouse( Point location , WindowRef window , ControlPartCode *outPart ) ;
440
441 #endif
442 // _WX_PRIVATE_H_