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
41 #ifdef __WXMAC_CARBON__
42 #include "wx/mac/corefoundation/cfstring.h"
47 #include "wx/window.h"
49 class wxMacPortStateHelper
51 DECLARE_NO_COPY_CLASS(wxMacPortStateHelper
)
54 wxMacPortStateHelper( GrafPtr newport
) ;
55 wxMacPortStateHelper() ;
56 ~wxMacPortStateHelper() ;
58 void Setup( GrafPtr newport
) ;
60 bool IsCleared() { return m_clip
== NULL
; }
61 GrafPtr
GetCurrentPort() { return m_currentPort
; }
64 GrafPtr m_currentPort
;
67 ThemeDrawingState m_drawingState
;
74 class WXDLLEXPORT wxMacPortSaver
76 DECLARE_NO_COPY_CLASS(wxMacPortSaver
)
79 wxMacPortSaver( GrafPtr port
)
81 ::GetPort( &m_port
) ;
92 class WXDLLEXPORT wxMacPortSetter
94 DECLARE_NO_COPY_CLASS(wxMacPortSetter
)
97 wxMacPortSetter( const wxDC
* dc
) ;
100 wxMacPortStateHelper m_ph
;
105 Clips to the visible region of a control within the current port
108 class WXDLLEXPORT wxMacWindowClipper
: public wxMacPortSaver
110 DECLARE_NO_COPY_CLASS(wxMacWindowClipper
)
113 wxMacWindowClipper( const wxWindow
* win
) ;
114 ~wxMacWindowClipper() ;
117 RgnHandle m_formerClip
;
118 RgnHandle m_newClip
;
121 class WXDLLEXPORT wxMacWindowStateSaver
: public wxMacWindowClipper
123 DECLARE_NO_COPY_CLASS(wxMacWindowStateSaver
)
126 wxMacWindowStateSaver( const wxWindow
* win
) ;
127 ~wxMacWindowStateSaver() ;
130 ThemeDrawingState m_themeDrawingState
;
134 class wxMacDrawingHelper
136 DECLARE_NO_COPY_CLASS(wxMacDrawingHelper)
139 wxMacDrawingHelper( wxWindowMac * theWindow , bool clientArea = false ) ;
140 ~wxMacDrawingHelper() ;
141 bool Ok() { return m_ok ; }
142 void LocalToWindow( Rect *rect) { OffsetRect( rect , m_origin.h , m_origin.v ) ; }
143 void LocalToWindow( Point *pt ) { AddPt( m_origin , pt ) ; }
144 void LocalToWindow( RgnHandle rgn ) { OffsetRgn( rgn , m_origin.h , m_origin.v ) ; }
145 const Point& GetOrigin() { return m_origin ; }
148 GrafPtr m_formerPort ;
149 GrafPtr m_currentPort ;
150 PenState m_savedPenState ;
156 bool wxMacConvertEventToRecord( EventRef event
, EventRecord
*rec
) ;
161 WXDLLEXPORT wxString
wxMacFSSpec2MacFilename( const FSSpec
*spec
) ;
162 WXDLLEXPORT
void wxMacFilename2FSSpec( const wxString
&path
, FSSpec
*spec
) ;
165 WXDLLEXPORT wxString
wxMacFindFolder(short vRefNum
,
167 Boolean createFolder
);
171 GWorldPtr
wxMacCreateGWorld( int width
, int height
, int depth
) ;
172 void wxMacDestroyGWorld( GWorldPtr gw
) ;
173 PicHandle
wxMacCreatePict( GWorldPtr gw
, GWorldPtr mask
= NULL
) ;
174 CIconHandle
wxMacCreateCIcon(GWorldPtr image
, GWorldPtr mask
, short dstDepth
, short iconSize
) ;
175 void wxMacSetColorTableEntry( CTabHandle newColors
, int index
, int red
, int green
, int blue
) ;
176 CTabHandle
wxMacCreateColorTable( int numColors
) ;
177 void wxMacCreateBitmapButton( ControlButtonContentInfo
*info
, const wxBitmap
& bitmap
, int forceType
= 0 ) ;
179 #define MAC_WXCOLORREF(a) (*((RGBColor*)&(a)))
180 #define MAC_WXHBITMAP(a) (GWorldPtr(a))
181 #define MAC_WXHMETAFILE(a) (PicHandle(a))
182 #define MAC_WXHICON(a) (CIconHandle(a))
183 #define MAC_WXHCURSOR(a) (CursHandle(a))
184 #define MAC_WXHRGN(a) (RgnHandle(a))
185 #define MAC_WXHWND(a) (WindowPtr(a))
186 #define MAC_WXRECPTR(a) ((Rect*)a)
187 #define MAC_WXPOINTPTR(a) ((Point*)a)
188 #define MAC_WXHMENU(a) ((MenuHandle)a)
190 struct wxOpaqueWindowRef
192 wxOpaqueWindowRef( WindowRef ref
) { m_data
= ref
; }
193 operator WindowRef() { return m_data
; }
198 wxWindow
* wxFindControlFromMacControl(ControlRef inControl
) ;
199 wxTopLevelWindowMac
* wxFindWinFromMacWindow( WindowRef inWindow
) ;
200 wxMenu
* wxFindMenuFromMacMenu(MenuRef inMenuRef
) ;
202 extern wxWindow
* g_MacLastWindow
;
203 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
204 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
= true ) ;
206 template<typename T
> EventParamType
wxMacGetEventParamType() { wxFAIL_MSG( wxT("Unknown Param Type") ) ; return 0 ; }
207 template<> inline EventParamType wxMacGetEventParamType
<RgnHandle
>() { return typeQDRgnHandle
; }
208 template<> inline EventParamType wxMacGetEventParamType
<ControlRef
>() { return typeControlRef
; }
209 template<> inline EventParamType wxMacGetEventParamType
<WindowRef
>() { return typeWindowRef
; }
210 template<> inline EventParamType wxMacGetEventParamType
<MenuRef
>() { return typeMenuRef
; }
211 template<> inline EventParamType wxMacGetEventParamType
<EventRef
>() { return typeEventRef
; }
212 template<> inline EventParamType wxMacGetEventParamType
<Point
>() { return typeQDPoint
; }
213 template<> inline EventParamType wxMacGetEventParamType
<Rect
>() { return typeQDRectangle
; }
214 template<> inline EventParamType wxMacGetEventParamType
<Boolean
>() { return typeBoolean
; }
215 #if TARGET_API_MAC_OSX
216 template<> inline EventParamType wxMacGetEventParamType
<HICommand
>() { return typeHICommand
; }
217 template<> inline EventParamType wxMacGetEventParamType
<HIPoint
>() { return typeHIPoint
; }
218 template<> inline EventParamType wxMacGetEventParamType
<HISize
>() { return typeHISize
; }
219 template<> inline EventParamType wxMacGetEventParamType
<HIRect
>() { return typeHIRect
; }
220 template<> inline EventParamType wxMacGetEventParamType
<void*>() { return typeVoidPtr
; }
222 template<> inline EventParamType wxMacGetEventParamType
<Collection
>() { return typeCollection
; }
223 template<> inline EventParamType wxMacGetEventParamType
<CGContextRef
>() { return typeCGContextRef
; }
226 template<> EventParamType wxMacGetEventParamType<GrafPtr>() { return typeGrafPtr ; }
227 template<> EventParamType wxMacGetEventParamType<OSStatus>() { return typeOSStatus ; }
228 template<> EventParamType wxMacGetEventParamType<CFIndex>() { return typeCFIndex ; }
229 template<> EventParamType wxMacGetEventParamType<GWorldPtr>() { return typeGWorldPtr ; }
232 class wxMacCarbonEvent
242 wxMacCarbonEvent( EventRef event
, bool release
= false )
245 m_release
= release
;
248 wxMacCarbonEvent(UInt32 inClassID
,UInt32 inKind
,EventTime inWhen
= 0 /*now*/,EventAttributes inAttributes
=kEventAttributeNone
)
251 verify_noerr( MacCreateEvent( NULL
, inClassID
, inKind
,inWhen
,inAttributes
,&m_eventRef
) ) ;
258 ReleaseEvent( m_eventRef
) ;
261 OSStatus
Create(UInt32 inClassID
,UInt32 inKind
,EventTime inWhen
= 0 /*now*/,EventAttributes inAttributes
=kEventAttributeNone
)
263 verify( (m_eventRef
== NULL
) || m_release
) ;
264 if ( m_eventRef
&& m_release
)
266 ReleaseEvent( m_eventRef
) ;
271 OSStatus err
= MacCreateEvent( NULL
, inClassID
, inKind
,inWhen
,inAttributes
,&m_eventRef
) ;
277 OSStatus
GetParameter( EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
) ;
279 template <typename T
> OSStatus
GetParameter( EventParamName inName
, EventParamType type
, T
*data
)
281 return GetParameter( inName
, type
, sizeof( T
) , data
) ;
283 template <typename T
> OSStatus
GetParameter( EventParamName inName
, T
*data
)
285 return GetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , data
) ;
288 template <typename T
> T
GetParameter( EventParamName inName
)
291 verify_noerr( GetParameter
<T
>( inName
, &value
) ) ;
294 template <typename T
> T
GetParameter( EventParamName inName
, EventParamType inDesiredType
)
297 verify_noerr( GetParameter
<T
>( inName
, inDesiredType
, &value
) ) ;
301 OSStatus
SetParameter( EventParamName inName
, EventParamType inType
, UInt32 inSize
, const void * inData
) ;
302 template <typename T
> OSStatus
SetParameter( EventParamName inName
, EventParamType inDesiredType
, const T
*data
)
304 return SetParameter( inName
, inDesiredType
, sizeof( T
) , data
) ;
306 template <typename T
> OSStatus
SetParameter( EventParamName inName
, EventParamType inDesiredType
, const T
& data
)
308 return SetParameter
<T
>( inName
, inDesiredType
, &data
) ;
310 template <typename T
> OSStatus
SetParameter( EventParamName inName
, const T
*data
)
312 return SetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , data
) ;
314 template <typename T
> OSStatus
SetParameter( EventParamName inName
, const T
& data
)
316 return SetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , &data
) ;
320 return ::GetEventClass( m_eventRef
) ;
324 return ::GetEventKind( m_eventRef
) ;
328 return ::GetEventTime( m_eventRef
) ;
332 return EventTimeToTicks( GetTime() ) ;
334 OSStatus
SetTime( EventTime inWhen
= 0 /*now*/ )
336 return ::SetEventTime( m_eventRef
, inWhen
? inWhen
: GetCurrentEventTime() ) ;
338 operator EventRef () { return m_eventRef
; }
340 bool IsValid() { return m_eventRef
!= 0 ; }
342 EventRef m_eventRef
;
351 m_controlRef
= NULL
;
354 wxMacControl( ControlRef control
)
356 m_controlRef
= control
;
358 wxMacControl( WXWidget control
)
360 m_controlRef
= (ControlRef
) control
;
362 virtual ~wxMacControl()
366 virtual void Dispose() ;
368 bool Ok() const { return GetControlRef() != NULL
; }
370 virtual ControlRef
* GetControlRefAddr() { return &m_controlRef
; }
371 virtual ControlRef
GetControlRef() const { return m_controlRef
; }
373 virtual void SetReference( SInt32 data
) ;
375 void operator= (ControlRef c) { m_controlRef = c ; }
376 operator ControlRef () { return m_controlRef; }
377 operator ControlRef * () { return &m_controlRef; }
379 // accessing data and values
381 virtual OSStatus
SetData( ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
) ;
382 virtual OSStatus
GetData( ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const ;
383 virtual OSStatus
GetDataSize( ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const ;
384 virtual OSStatus
SendEvent( EventRef ref
, OptionBits inOptions
= 0 ) ;
385 virtual OSStatus
SendHICommand( HICommand
&command
, OptionBits inOptions
= 0 ) ;
387 virtual OSStatus
SendHICommand( UInt32 commandID
, OptionBits inOptions
= 0 ) ;
389 virtual SInt32
GetValue() const ;
390 virtual SInt32
GetMaximum() const ;
391 virtual SInt32
GetMinimum() const ;
393 virtual void SetValue( SInt32 v
) ;
394 virtual void SetMinimum( SInt32 v
) ;
395 virtual void SetMaximum( SInt32 v
) ;
397 virtual void SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
) ;
398 virtual void SetRange( SInt32 minimum
, SInt32 maximum
) ;
400 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
401 virtual bool HasFocus() const ;
402 virtual bool NeedsFocusRect() const ;
406 Size
GetDataSize( ControlPartCode inPartCode
, ResType inTag
) const
409 verify_noerr( GetDataSize( inPartCode
, inTag
, &sz
) ) ;
412 template <typename T
> OSStatus
SetData( ControlPartCode inPartCode
, ResType inTag
, const T
*data
)
414 return SetData( inPartCode
, inTag
, sizeof( T
) , data
) ;
416 template <typename T
> OSStatus
SetData( ControlPartCode inPartCode
, ResType inTag
, const T
& data
)
418 return SetData( inPartCode
, inTag
, sizeof( T
) , &data
) ;
420 template <typename T
> OSStatus
GetData( ControlPartCode inPartCode
, ResType inTag
, T
*data
) const
423 return GetData( inPartCode
, inTag
, sizeof( T
) , data
, &dummy
) ;
425 template <typename T
> T
GetData( ControlPartCode inPartCode
, ResType inTag
) const
428 verify_noerr( GetData
<T
>( inPartCode
, inTag
, &value
) ) ;
432 // Flash the control for the specified amount of time
433 virtual void Flash( ControlPartCode part
, UInt32 ticks
= 8 ) ;
434 virtual void VisibilityChanged( bool shown
) ;
435 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
436 virtual void SetBackground( const wxBrush
&brush
) ;
437 virtual ControlPartCode
HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
) ;
438 void SetActionProc( ControlActionUPP actionProc
) ;
439 void SetViewSize( SInt32 viewSize
) ;
440 SInt32
GetViewSize() const ;
442 virtual bool IsVisible() const ;
443 virtual void SetVisibility( bool visible
, bool redraw
) ;
444 virtual bool IsEnabled() const ;
445 virtual bool IsActive() const ;
446 virtual void Enable( bool enable
) ;
448 // invalidates this control and all children
449 virtual void InvalidateWithChildren() ;
450 virtual void SetDrawingEnabled( bool enable
) ;
451 virtual bool GetNeedsDisplay() const ;
452 virtual void SetNeedsDisplay( bool needsDisplay
, RgnHandle where
= NULL
) ;
454 virtual void ScrollRect( const wxRect
&rect
, int dx
, int dy
) ;
456 virtual void GetRect( Rect
*r
) ;
457 virtual void SetRect( Rect
*r
) ;
458 virtual void GetRectInWindowCoords( Rect
*r
) ;
459 virtual void GetBestRect( Rect
*r
) ;
460 virtual void SetTitle( const wxString
&title
) ;
461 // converts from Toplevel-Content relative to local
462 static void Convert( wxPoint
*pt
, wxMacControl
*convert
, wxMacControl
*to
) ;
464 virtual void GetFeatures( UInt32
*features
) ;
465 virtual OSStatus
GetRegion( ControlPartCode partCode
, RgnHandle region
) ;
466 virtual OSStatus
SetZOrder( bool above
, wxMacControl
* other
) ;
467 // to be moved into a databrowser subclass
469 virtual OSStatus
SetSelectionFlags( DataBrowserSelectionFlags
) ;
470 virtual OSStatus
AddListViewColumn( DataBrowserListViewColumnDesc
*columnDesc
,
471 DataBrowserTableViewColumnIndex position
) ;
472 virtual OSStatus
AutoSizeListViewColumns() ;
473 virtual OSStatus
SetHasScrollBars( bool horiz
, bool vert
) ;
474 virtual OSStatus
SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
) ;
475 virtual OSStatus
SetListViewHeaderBtnHeight(UInt16 height
) ;
476 virtual OSStatus
SetCallbacks(const DataBrowserCallbacks
* callbacks
) ;
477 virtual OSStatus
UpdateItems( DataBrowserItemID container
, UInt32 numItems
,
478 const DataBrowserItemID
* items
,
479 DataBrowserPropertyID preSortProperty
,
480 DataBrowserPropertyID propertyID
) ;
481 virtual OSStatus
AddItems( DataBrowserItemID container
, UInt32 numItems
,
482 const DataBrowserItemID
* items
,
483 DataBrowserPropertyID preSortProperty
) ;
484 virtual OSStatus
RemoveItems( DataBrowserItemID container
, UInt32 numItems
,
485 const DataBrowserItemID
* items
,
486 DataBrowserPropertyID preSortProperty
) ;
487 virtual OSStatus
RevealItem( DataBrowserItemID item
,
488 DataBrowserPropertyID propertyID
,
489 DataBrowserRevealOptions options
) ;
490 virtual OSStatus
GetSelectionAnchor( DataBrowserItemID
* first
, DataBrowserItemID
* last
) ;
491 virtual bool IsItemSelected( DataBrowserItemID item
) ;
492 virtual OSStatus
SetSelectedItems(UInt32 numItems
,
493 const DataBrowserItemID
* items
,
494 DataBrowserSetOption operation
) ;
496 // to be moved into a tab control class
498 virtual OSStatus
SetTabEnabled( SInt16 tabNo
, bool enable
) ;
500 ControlRef m_controlRef
;
507 //---------------------------------------------------------------------------
508 // wxMac string conversions
509 //---------------------------------------------------------------------------
511 void wxMacSetupConverters() ;
512 void wxMacCleanupConverters() ;
514 void wxMacStringToPascal( const wxString
&from
, StringPtr to
) ;
515 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
) ;
519 ControlRef
wxMacFindControlUnderMouse( Point location
, WindowRef window
, ControlPartCode
*outPart
) ;
523 wxString
wxMacFSRefToPath( const FSRef
*fsRef
, CFStringRef additionalPathComponent
= NULL
) ;
524 OSStatus
wxMacPathToFSRef( const wxString
&path
, FSRef
*fsRef
) ;
525 wxString
wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname
) ;