1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Private declarations: as this header is only included by
4 // wxWindows itself, it may contain identifiers which don't start
6 // Author: Stefan Csomor
10 // Copyright: (c) Stefan Csomor
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
14 #ifndef _WX_PRIVATE_H_
15 #define _WX_PRIVATE_H_
21 # include <Carbon/Carbon.h>
23 # include <Debugging.h>
24 # include <Quickdraw.h>
25 # include <Appearance.h>
27 # include <Controls.h>
28 # include <ControlDefinitions.h>
33 #if UNIVERSAL_INTERFACES_VERSION < 0x0340
34 #error "please update to Apple's lastest universal headers from http://developer.apple.com/sdk/"
39 #include "wx/window.h"
41 class wxMacPortStateHelper
43 DECLARE_NO_COPY_CLASS(wxMacPortStateHelper
)
46 wxMacPortStateHelper( GrafPtr newport
) ;
47 wxMacPortStateHelper() ;
48 ~wxMacPortStateHelper() ;
50 void Setup( GrafPtr newport
) ;
52 bool IsCleared() { return m_clip
== NULL
; }
53 GrafPtr
GetCurrentPort() { return m_currentPort
; }
56 GrafPtr m_currentPort
;
59 ThemeDrawingState m_drawingState
;
66 class WXDLLEXPORT wxMacPortSaver
68 DECLARE_NO_COPY_CLASS(wxMacPortSaver
)
71 wxMacPortSaver( GrafPtr port
)
73 ::GetPort( &m_port
) ;
84 class WXDLLEXPORT wxMacPortSetter
86 DECLARE_NO_COPY_CLASS(wxMacPortSetter
)
89 wxMacPortSetter( const wxDC
* dc
) ;
92 wxMacPortStateHelper m_ph
;
97 Clips to the visible region of a control within the current port
100 class WXDLLEXPORT wxMacWindowClipper
: public wxMacPortSaver
102 DECLARE_NO_COPY_CLASS(wxMacWindowClipper
)
105 wxMacWindowClipper( const wxWindow
* win
) ;
106 ~wxMacWindowClipper() ;
108 RgnHandle m_formerClip
;
109 RgnHandle m_newClip
;
113 class wxMacDrawingHelper
115 DECLARE_NO_COPY_CLASS(wxMacDrawingHelper)
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 ; }
127 GrafPtr m_formerPort ;
128 GrafPtr m_currentPort ;
129 PenState m_savedPenState ;
135 bool wxMacConvertEventToRecord( EventRef event
, EventRecord
*rec
) ;
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
) ;
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
);
152 WXDLLEXPORT wxString
wxMacFindFolder(short vRefNum
,
154 Boolean createFolder
);
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 ) ;
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)
177 struct wxOpaqueWindowRef
179 wxOpaqueWindowRef( WindowRef ref
) { m_data
= ref
; }
180 operator WindowRef() { return m_data
; }
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
) ;
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
; }
206 template<> inline EventParamType wxMacGetEventParamType
<Collection
>() { return typeCollection
; }
207 template<> inline EventParamType wxMacGetEventParamType
<CGContextRef
>() { return typeCGContextRef
; }
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 ; }
216 class wxMacCarbonEvent
220 wxMacCarbonEvent( EventRef event
)
225 OSStatus
GetParameter( EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
) ;
227 template <typename T
> OSStatus
GetParameter( EventParamName inName
, EventParamType type
, T
*data
)
229 return GetParameter( inName
, type
, sizeof( T
) , data
) ;
231 template <typename T
> OSStatus
GetParameter( EventParamName inName
, T
*data
)
233 return GetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , data
) ;
236 template <typename T
> T
GetParameter( EventParamName inName
)
239 verify_noerr( GetParameter
<T
>( inName
, &value
) ) ;
242 template <typename T
> T
GetParameter( EventParamName inName
, EventParamType inDesiredType
)
245 verify_noerr( GetParameter
<T
>( inName
, inDesiredType
, &value
) ) ;
250 OSStatus
SetParameter( EventParamName inName
, EventParamType inType
, UInt32 inSize
, void * inData
) ;
251 template <typename T
> OSStatus
SetParameter( EventParamName inName
, EventParamType type
, T
*data
)
253 return SetParameter( inName
, type
, sizeof( T
) , data
) ;
255 template <typename T
> OSStatus
SetParameter( EventParamName inName
, T
*data
)
257 return SetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , data
) ;
262 return ::GetEventKind( m_eventRef
) ;
266 return ::GetEventTime( m_eventRef
) ;
270 return EventTimeToTicks( GetTime() ) ;
273 EventRef m_eventRef
;
278 //---------------------------------------------------------------------------
279 // wxMac string conversions
280 //---------------------------------------------------------------------------
282 void wxMacSetupConverters() ;
283 void wxMacCleanupConverters() ;
285 void wxMacStringToPascal( const wxString
&from
, StringPtr to
) ;
286 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
) ;
288 void wxMacConvertNewlines13To10( char * data
) ;
289 void wxMacConvertNewlines10To13( char * data
) ;
290 void wxMacConvertNewlines13To10( wxString
*data
) ;
291 void wxMacConvertNewlines10To13( wxString
*data
) ;
294 void wxMacConvertNewlines13To10( wxChar
* data
) ;
295 void wxMacConvertNewlines10To13( wxChar
* data
) ;
300 class wxMacCFStringHolder
303 wxMacCFStringHolder()
309 wxMacCFStringHolder(const wxString
&str
, wxFontEncoding encoding
)
313 Assign( str
, encoding
) ;
316 wxMacCFStringHolder(CFStringRef ref
, bool release
= true )
319 m_release
= release
;
322 ~wxMacCFStringHolder()
329 CFStringRef retval
= m_cfs
;
337 if ( m_release
&& m_cfs
)
342 void Assign( const wxString
&str
, wxFontEncoding encoding
) ;
344 operator CFStringRef () { return m_cfs
; }
345 wxString
AsString( wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
) ;
357 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
) ;
358 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
) ;