1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Private declarations: as this header is only included by
4 // wxWidgets 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/"
37 #ifndef MAC_OS_X_VERSION_10_3
38 #define MAC_OS_X_VERSION_10_3 1030
43 #include "wx/window.h"
45 class wxMacPortStateHelper
47 DECLARE_NO_COPY_CLASS(wxMacPortStateHelper
)
50 wxMacPortStateHelper( GrafPtr newport
) ;
51 wxMacPortStateHelper() ;
52 ~wxMacPortStateHelper() ;
54 void Setup( GrafPtr newport
) ;
56 bool IsCleared() { return m_clip
== NULL
; }
57 GrafPtr
GetCurrentPort() { return m_currentPort
; }
60 GrafPtr m_currentPort
;
63 ThemeDrawingState m_drawingState
;
70 class WXDLLEXPORT wxMacPortSaver
72 DECLARE_NO_COPY_CLASS(wxMacPortSaver
)
75 wxMacPortSaver( GrafPtr port
)
77 ::GetPort( &m_port
) ;
88 class WXDLLEXPORT wxMacPortSetter
90 DECLARE_NO_COPY_CLASS(wxMacPortSetter
)
93 wxMacPortSetter( const wxDC
* dc
) ;
96 wxMacPortStateHelper m_ph
;
101 Clips to the visible region of a control within the current port
104 class WXDLLEXPORT wxMacWindowClipper
: public wxMacPortSaver
106 DECLARE_NO_COPY_CLASS(wxMacWindowClipper
)
109 wxMacWindowClipper( const wxWindow
* win
) ;
110 ~wxMacWindowClipper() ;
113 RgnHandle m_formerClip
;
114 RgnHandle m_newClip
;
117 class WXDLLEXPORT wxMacWindowStateSaver
: public wxMacWindowClipper
119 DECLARE_NO_COPY_CLASS(wxMacWindowStateSaver
)
122 wxMacWindowStateSaver( const wxWindow
* win
) ;
123 ~wxMacWindowStateSaver() ;
126 ThemeDrawingState m_themeDrawingState
;
130 class wxMacDrawingHelper
132 DECLARE_NO_COPY_CLASS(wxMacDrawingHelper)
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 ; }
144 GrafPtr m_formerPort ;
145 GrafPtr m_currentPort ;
146 PenState m_savedPenState ;
152 bool wxMacConvertEventToRecord( EventRef event
, EventRecord
*rec
) ;
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
) ;
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
);
169 WXDLLEXPORT wxString
wxMacFindFolder(short vRefNum
,
171 Boolean createFolder
);
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 ) ;
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)
194 struct wxOpaqueWindowRef
196 wxOpaqueWindowRef( WindowRef ref
) { m_data
= ref
; }
197 operator WindowRef() { return m_data
; }
202 wxWindow
* wxFindControlFromMacControl(ControlRef inControl
) ;
203 wxTopLevelWindowMac
* wxFindWinFromMacWindow( WindowRef inWindow
) ;
204 wxMenu
* wxFindMenuFromMacMenu(MenuRef inMenuRef
) ;
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 ) ;
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
<HICommand
>() { return typeHICommand
; }
221 template<> inline EventParamType wxMacGetEventParamType
<HIPoint
>() { return typeHIPoint
; }
222 template<> inline EventParamType wxMacGetEventParamType
<HISize
>() { return typeHISize
; }
223 template<> inline EventParamType wxMacGetEventParamType
<HIRect
>() { return typeHIRect
; }
224 template<> inline EventParamType wxMacGetEventParamType
<void*>() { return typeVoidPtr
; }
226 template<> inline EventParamType wxMacGetEventParamType
<Collection
>() { return typeCollection
; }
227 template<> inline EventParamType wxMacGetEventParamType
<CGContextRef
>() { return typeCGContextRef
; }
230 template<> EventParamType wxMacGetEventParamType<GrafPtr>() { return typeGrafPtr ; }
231 template<> EventParamType wxMacGetEventParamType<OSStatus>() { return typeOSStatus ; }
232 template<> EventParamType wxMacGetEventParamType<CFIndex>() { return typeCFIndex ; }
233 template<> EventParamType wxMacGetEventParamType<GWorldPtr>() { return typeGWorldPtr ; }
236 class wxMacCarbonEvent
240 wxMacCarbonEvent( EventRef event
, bool release
= false )
243 m_release
= release
;
245 wxMacCarbonEvent(UInt32 inClassID
,UInt32 inKind
,EventTime inWhen
= 0 /*now*/,EventAttributes inAttributes
=kEventAttributeNone
)
248 verify_noerr( MacCreateEvent( NULL
, inClassID
, inKind
,inWhen
,inAttributes
,&m_eventRef
) ) ;
254 ReleaseEvent( m_eventRef
) ;
257 OSStatus
GetParameter( EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
) ;
259 template <typename T
> OSStatus
GetParameter( EventParamName inName
, EventParamType type
, T
*data
)
261 return GetParameter( inName
, type
, sizeof( T
) , data
) ;
263 template <typename T
> OSStatus
GetParameter( EventParamName inName
, T
*data
)
265 return GetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , data
) ;
268 template <typename T
> T
GetParameter( EventParamName inName
)
271 verify_noerr( GetParameter
<T
>( inName
, &value
) ) ;
274 template <typename T
> T
GetParameter( EventParamName inName
, EventParamType inDesiredType
)
277 verify_noerr( GetParameter
<T
>( inName
, inDesiredType
, &value
) ) ;
281 OSStatus
SetParameter( EventParamName inName
, EventParamType inType
, UInt32 inSize
, const void * inData
) ;
282 template <typename T
> OSStatus
SetParameter( EventParamName inName
, EventParamType inDesiredType
, const T
*data
)
284 return SetParameter( inName
, inDesiredType
, sizeof( T
) , data
) ;
286 template <typename T
> OSStatus
SetParameter( EventParamName inName
, EventParamType inDesiredType
, const T
& data
)
288 return SetParameter
<T
>( inName
, inDesiredType
, &data
) ;
290 template <typename T
> OSStatus
SetParameter( EventParamName inName
, const T
*data
)
292 return SetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , data
) ;
294 template <typename T
> OSStatus
SetParameter( EventParamName inName
, const T
& data
)
296 return SetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , &data
) ;
300 return ::GetEventClass( m_eventRef
) ;
304 return ::GetEventKind( m_eventRef
) ;
308 return ::GetEventTime( m_eventRef
) ;
312 return EventTimeToTicks( GetTime() ) ;
314 operator EventRef () { return m_eventRef
; }
316 EventRef m_eventRef
;
325 m_controlRef
= NULL
;
328 wxMacControl( ControlRef control
)
330 m_controlRef
= control
;
332 wxMacControl( WXWidget control
)
334 m_controlRef
= (ControlRef
) control
;
336 virtual ~wxMacControl()
339 bool Ok() const { return m_controlRef
!= NULL
; }
341 void operator= (ControlRef c
) { m_controlRef
= c
; }
342 operator ControlRef () { return m_controlRef
; }
343 operator ControlRef
* () { return &m_controlRef
; }
345 // accessing data and values
347 virtual OSStatus
SetData( ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
) ;
348 virtual OSStatus
GetData( ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const ;
349 virtual OSStatus
GetDataSize( ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const ;
350 virtual OSStatus
SendEvent( EventRef ref
, OptionBits inOptions
= 0 ) ;
351 virtual OSStatus
SendHICommand( HICommand
&command
, OptionBits inOptions
= 0 ) ;
353 virtual OSStatus
SendHICommand( UInt32 commandID
, OptionBits inOptions
= 0 ) ;
355 virtual SInt32
GetValue() const ;
356 virtual SInt32
GetMaximum() const ;
357 virtual SInt32
GetMinimum() const ;
359 virtual void SetValue( SInt32 v
) ;
360 virtual void SetMinimum( SInt32 v
) ;
361 virtual void SetMaximum( SInt32 v
) ;
363 virtual void SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
) ;
364 virtual void SetRange( SInt32 minimum
, SInt32 maximum
) ;
368 Size
GetDataSize( ControlPartCode inPartCode
, ResType inTag
) const
371 verify_noerr( GetDataSize( inPartCode
, inTag
, &sz
) ) ;
374 template <typename T
> OSStatus
SetData( ControlPartCode inPartCode
, ResType inTag
, const T
*data
)
376 return SetData( inPartCode
, inTag
, sizeof( T
) , data
) ;
378 template <typename T
> OSStatus
SetData( ControlPartCode inPartCode
, ResType inTag
, const T
& data
)
380 return SetData( inPartCode
, inTag
, sizeof( T
) , &data
) ;
382 template <typename T
> OSStatus
GetData( ControlPartCode inPartCode
, ResType inTag
, T
*data
) const
385 return GetData( inPartCode
, inTag
, sizeof( T
) , data
, &dummy
) ;
387 template <typename T
> T
GetData( ControlPartCode inPartCode
, ResType inTag
) const
390 verify_noerr( GetData
<T
>( inPartCode
, inTag
, &value
) ) ;
394 // Flash the control for the specified amount of time
395 virtual void Flash( ControlPartCode part
, UInt32 ticks
= 8 ) ;
396 virtual void VisibilityChanged( bool shown
) ;
397 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
400 ControlRef m_controlRef
;
407 //---------------------------------------------------------------------------
408 // wxMac string conversions
409 //---------------------------------------------------------------------------
411 void wxMacSetupConverters() ;
412 void wxMacCleanupConverters() ;
414 void wxMacStringToPascal( const wxString
&from
, StringPtr to
) ;
415 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
) ;
417 void wxMacConvertNewlines13To10( char * data
) ;
418 void wxMacConvertNewlines10To13( char * data
) ;
419 void wxMacConvertNewlines13To10( wxString
*data
) ;
420 void wxMacConvertNewlines10To13( wxString
*data
) ;
423 void wxMacConvertNewlines13To10( wxChar
* data
) ;
424 void wxMacConvertNewlines10To13( wxChar
* data
) ;
429 class wxMacCFStringHolder
432 wxMacCFStringHolder()
438 wxMacCFStringHolder(const wxString
&str
, wxFontEncoding encoding
)
442 Assign( str
, encoding
) ;
445 wxMacCFStringHolder(CFStringRef ref
, bool release
= true )
448 m_release
= release
;
451 ~wxMacCFStringHolder()
458 CFStringRef retval
= m_cfs
;
466 if ( m_release
&& m_cfs
)
471 void Assign( const wxString
&str
, wxFontEncoding encoding
) ;
473 operator CFStringRef () { return m_cfs
; }
474 wxString
AsString( wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
) ;
486 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
) ;
487 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
) ;
492 ControlRef
wxMacFindControlUnderMouse( Point location
, WindowRef window
, ControlPartCode
*outPart
) ;