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 wxString
&path
, FSSpec
*spec
) ;
161 WXDLLEXPORT wxString
wxMacFindFolder(short vRefNum
,
163 Boolean createFolder
);
167 GWorldPtr
wxMacCreateGWorld( int width
, int height
, int depth
) ;
168 void wxMacDestroyGWorld( GWorldPtr gw
) ;
169 PicHandle
wxMacCreatePict( GWorldPtr gw
, GWorldPtr mask
= NULL
) ;
170 CIconHandle
wxMacCreateCIcon(GWorldPtr image
, GWorldPtr mask
, short dstDepth
, short iconSize
) ;
171 void wxMacSetColorTableEntry( CTabHandle newColors
, int index
, int red
, int green
, int blue
) ;
172 CTabHandle
wxMacCreateColorTable( int numColors
) ;
173 void wxMacCreateBitmapButton( ControlButtonContentInfo
*info
, const wxBitmap
& bitmap
, int forceType
= 0 ) ;
175 #define MAC_WXCOLORREF(a) (*((RGBColor*)&(a)))
176 #define MAC_WXHBITMAP(a) (GWorldPtr(a))
177 #define MAC_WXHMETAFILE(a) (PicHandle(a))
178 #define MAC_WXHICON(a) (CIconHandle(a))
179 #define MAC_WXHCURSOR(a) (CursHandle(a))
180 #define MAC_WXHRGN(a) (RgnHandle(a))
181 #define MAC_WXHWND(a) (WindowPtr(a))
182 #define MAC_WXRECPTR(a) ((Rect*)a)
183 #define MAC_WXPOINTPTR(a) ((Point*)a)
184 #define MAC_WXHMENU(a) ((MenuHandle)a)
186 struct wxOpaqueWindowRef
188 wxOpaqueWindowRef( WindowRef ref
) { m_data
= ref
; }
189 operator WindowRef() { return m_data
; }
194 wxWindow
* wxFindControlFromMacControl(ControlRef inControl
) ;
195 wxTopLevelWindowMac
* wxFindWinFromMacWindow( WindowRef inWindow
) ;
196 wxMenu
* wxFindMenuFromMacMenu(MenuRef inMenuRef
) ;
198 extern wxWindow
* g_MacLastWindow
;
199 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
200 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
= true ) ;
202 template<typename T
> EventParamType
wxMacGetEventParamType() { wxFAIL_MSG( wxT("Unknown Param Type") ) ; return 0 ; }
203 template<> inline EventParamType wxMacGetEventParamType
<RgnHandle
>() { return typeQDRgnHandle
; }
204 template<> inline EventParamType wxMacGetEventParamType
<ControlRef
>() { return typeControlRef
; }
205 template<> inline EventParamType wxMacGetEventParamType
<WindowRef
>() { return typeWindowRef
; }
206 template<> inline EventParamType wxMacGetEventParamType
<MenuRef
>() { return typeMenuRef
; }
207 template<> inline EventParamType wxMacGetEventParamType
<EventRef
>() { return typeEventRef
; }
208 template<> inline EventParamType wxMacGetEventParamType
<Point
>() { return typeQDPoint
; }
209 template<> inline EventParamType wxMacGetEventParamType
<Rect
>() { return typeQDRectangle
; }
210 template<> inline EventParamType wxMacGetEventParamType
<Boolean
>() { return typeBoolean
; }
211 #if TARGET_API_MAC_OSX
212 template<> inline EventParamType wxMacGetEventParamType
<HICommand
>() { return typeHICommand
; }
213 template<> inline EventParamType wxMacGetEventParamType
<HIPoint
>() { return typeHIPoint
; }
214 template<> inline EventParamType wxMacGetEventParamType
<HISize
>() { return typeHISize
; }
215 template<> inline EventParamType wxMacGetEventParamType
<HIRect
>() { return typeHIRect
; }
216 template<> inline EventParamType wxMacGetEventParamType
<void*>() { return typeVoidPtr
; }
218 template<> inline EventParamType wxMacGetEventParamType
<Collection
>() { return typeCollection
; }
219 template<> inline EventParamType wxMacGetEventParamType
<CGContextRef
>() { return typeCGContextRef
; }
222 template<> EventParamType wxMacGetEventParamType<GrafPtr>() { return typeGrafPtr ; }
223 template<> EventParamType wxMacGetEventParamType<OSStatus>() { return typeOSStatus ; }
224 template<> EventParamType wxMacGetEventParamType<CFIndex>() { return typeCFIndex ; }
225 template<> EventParamType wxMacGetEventParamType<GWorldPtr>() { return typeGWorldPtr ; }
228 class wxMacCarbonEvent
232 wxMacCarbonEvent( EventRef event
, bool release
= false )
235 m_release
= release
;
237 wxMacCarbonEvent(UInt32 inClassID
,UInt32 inKind
,EventTime inWhen
= 0 /*now*/,EventAttributes inAttributes
=kEventAttributeNone
)
240 verify_noerr( MacCreateEvent( NULL
, inClassID
, inKind
,inWhen
,inAttributes
,&m_eventRef
) ) ;
246 ReleaseEvent( m_eventRef
) ;
249 OSStatus
GetParameter( EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
) ;
251 template <typename T
> OSStatus
GetParameter( EventParamName inName
, EventParamType type
, T
*data
)
253 return GetParameter( inName
, type
, sizeof( T
) , data
) ;
255 template <typename T
> OSStatus
GetParameter( EventParamName inName
, T
*data
)
257 return GetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , data
) ;
260 template <typename T
> T
GetParameter( EventParamName inName
)
263 verify_noerr( GetParameter
<T
>( inName
, &value
) ) ;
266 template <typename T
> T
GetParameter( EventParamName inName
, EventParamType inDesiredType
)
269 verify_noerr( GetParameter
<T
>( inName
, inDesiredType
, &value
) ) ;
273 OSStatus
SetParameter( EventParamName inName
, EventParamType inType
, UInt32 inSize
, const void * inData
) ;
274 template <typename T
> OSStatus
SetParameter( EventParamName inName
, EventParamType inDesiredType
, const T
*data
)
276 return SetParameter( inName
, inDesiredType
, sizeof( T
) , data
) ;
278 template <typename T
> OSStatus
SetParameter( EventParamName inName
, EventParamType inDesiredType
, const T
& data
)
280 return SetParameter
<T
>( inName
, inDesiredType
, &data
) ;
282 template <typename T
> OSStatus
SetParameter( EventParamName inName
, const T
*data
)
284 return SetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , data
) ;
286 template <typename T
> OSStatus
SetParameter( EventParamName inName
, const T
& data
)
288 return SetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , &data
) ;
292 return ::GetEventClass( m_eventRef
) ;
296 return ::GetEventKind( m_eventRef
) ;
300 return ::GetEventTime( m_eventRef
) ;
304 return EventTimeToTicks( GetTime() ) ;
306 operator EventRef () { return m_eventRef
; }
308 EventRef m_eventRef
;
317 m_controlRef
= NULL
;
320 wxMacControl( ControlRef control
)
322 m_controlRef
= control
;
324 wxMacControl( WXWidget control
)
326 m_controlRef
= (ControlRef
) control
;
328 virtual ~wxMacControl()
332 virtual void Dispose() ;
334 bool Ok() const { return GetControlRef() != NULL
; }
336 virtual ControlRef
* GetControlRefAddr() { return &m_controlRef
; }
337 virtual ControlRef
GetControlRef() const { return m_controlRef
; }
339 virtual void SetReference( SInt32 data
) ;
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
) ;
366 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
367 virtual bool HasFocus() const ;
368 virtual bool NeedsFocusRect() const ;
372 Size
GetDataSize( ControlPartCode inPartCode
, ResType inTag
) const
375 verify_noerr( GetDataSize( inPartCode
, inTag
, &sz
) ) ;
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
SetData( ControlPartCode inPartCode
, ResType inTag
, const T
& data
)
384 return SetData( inPartCode
, inTag
, sizeof( T
) , &data
) ;
386 template <typename T
> OSStatus
GetData( ControlPartCode inPartCode
, ResType inTag
, T
*data
) const
389 return GetData( inPartCode
, inTag
, sizeof( T
) , data
, &dummy
) ;
391 template <typename T
> T
GetData( ControlPartCode inPartCode
, ResType inTag
) const
394 verify_noerr( GetData
<T
>( inPartCode
, inTag
, &value
) ) ;
398 // Flash the control for the specified amount of time
399 virtual void Flash( ControlPartCode part
, UInt32 ticks
= 8 ) ;
400 virtual void VisibilityChanged( bool shown
) ;
401 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
402 virtual void SetBackground( const wxBrush
&brush
) ;
403 virtual ControlPartCode
HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
) ;
404 void SetActionProc( ControlActionUPP actionProc
) ;
405 void SetViewSize( SInt32 viewSize
) ;
406 SInt32
GetViewSize() const ;
408 virtual bool IsVisible() const ;
409 virtual void SetVisibility( bool visible
, bool redraw
) ;
410 virtual bool IsEnabled() const ;
411 virtual bool IsActive() const ;
412 virtual void Enable( bool enable
) ;
414 // invalidates this control and all children
415 virtual void InvalidateWithChildren() ;
416 virtual void SetDrawingEnabled( bool enable
) ;
417 virtual bool GetNeedsDisplay() const ;
418 virtual void SetNeedsDisplay( bool needsDisplay
, RgnHandle where
= NULL
) ;
420 virtual void ScrollRect( const wxRect
&rect
, int dx
, int dy
) ;
422 virtual void GetRect( Rect
*r
) ;
423 virtual void SetRect( Rect
*r
) ;
424 virtual void GetRectInWindowCoords( Rect
*r
) ;
425 virtual void GetBestRect( Rect
*r
) ;
426 virtual void SetTitle( const wxString
&title
) ;
427 // converts from Toplevel-Content relative to local
428 static void Convert( wxPoint
*pt
, wxMacControl
*convert
, wxMacControl
*to
) ;
430 virtual void GetFeatures( UInt32
*features
) ;
431 virtual OSStatus
GetRegion( ControlPartCode partCode
, RgnHandle region
) ;
432 virtual OSStatus
SetZOrder( bool above
, wxMacControl
* other
) ;
433 // to be moved into a databrowser subclass
435 virtual OSStatus
SetSelectionFlags( DataBrowserSelectionFlags
) ;
436 virtual OSStatus
AddListViewColumn( DataBrowserListViewColumnDesc
*columnDesc
,
437 DataBrowserTableViewColumnIndex position
) ;
438 virtual OSStatus
AutoSizeListViewColumns() ;
439 virtual OSStatus
SetHasScrollBars( bool horiz
, bool vert
) ;
440 virtual OSStatus
SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
) ;
441 virtual OSStatus
SetListViewHeaderBtnHeight(UInt16 height
) ;
442 virtual OSStatus
SetCallbacks(const DataBrowserCallbacks
* callbacks
) ;
443 virtual OSStatus
UpdateItems( DataBrowserItemID container
, UInt32 numItems
,
444 const DataBrowserItemID
* items
,
445 DataBrowserPropertyID preSortProperty
,
446 DataBrowserPropertyID propertyID
) ;
447 virtual OSStatus
AddItems( DataBrowserItemID container
, UInt32 numItems
,
448 const DataBrowserItemID
* items
,
449 DataBrowserPropertyID preSortProperty
) ;
450 virtual OSStatus
RemoveItems( DataBrowserItemID container
, UInt32 numItems
,
451 const DataBrowserItemID
* items
,
452 DataBrowserPropertyID preSortProperty
) ;
453 virtual OSStatus
RevealItem( DataBrowserItemID item
,
454 DataBrowserPropertyID propertyID
,
455 DataBrowserRevealOptions options
) ;
456 virtual bool IsItemSelected( DataBrowserItemID item
) ;
457 virtual OSStatus
SetSelectedItems(UInt32 numItems
,
458 const DataBrowserItemID
* items
,
459 DataBrowserSetOption operation
) ;
461 // to be moved into a tab control class
463 virtual OSStatus
SetTabEnabled( SInt16 tabNo
, bool enable
) ;
465 ControlRef m_controlRef
;
472 //---------------------------------------------------------------------------
473 // wxMac string conversions
474 //---------------------------------------------------------------------------
476 void wxMacSetupConverters() ;
477 void wxMacCleanupConverters() ;
479 void wxMacStringToPascal( const wxString
&from
, StringPtr to
) ;
480 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
) ;
482 void wxMacConvertNewlines13To10( char * data
) ;
483 void wxMacConvertNewlines10To13( char * data
) ;
484 void wxMacConvertNewlines13To10( wxString
*data
) ;
485 void wxMacConvertNewlines10To13( wxString
*data
) ;
488 void wxMacConvertNewlines13To10( wxChar
* data
) ;
489 void wxMacConvertNewlines10To13( wxChar
* data
) ;
494 class wxMacCFStringHolder
497 wxMacCFStringHolder()
503 wxMacCFStringHolder(const wxString
&str
, wxFontEncoding encoding
)
507 Assign( str
, encoding
) ;
510 wxMacCFStringHolder(CFStringRef ref
, bool release
= true )
513 m_release
= release
;
516 ~wxMacCFStringHolder()
523 CFStringRef retval
= m_cfs
;
531 if ( m_release
&& m_cfs
)
536 void Assign( const wxString
&str
, wxFontEncoding encoding
) ;
538 operator CFStringRef () { return m_cfs
; }
539 wxString
AsString( wxFontEncoding encoding
= wxFONTENCODING_DEFAULT
) ;
551 wxUint32
wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding
) ;
552 wxFontEncoding
wxMacGetFontEncFromSystemEnc(wxUint32 encoding
) ;
557 ControlRef
wxMacFindControlUnderMouse( Point location
, WindowRef window
, ControlPartCode
*outPart
) ;
561 wxString
wxMacFSRefToPath( const FSRef
*fsRef
, CFStringRef additionalPathComponent
= NULL
) ;
562 OSStatus
wxMacPathToFSRef( const wxString
&path
, FSRef
*fsRef
) ;
563 wxString
wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname
) ;