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
236 wxMacCarbonEvent( EventRef event
, bool release
= false )
239 m_release
= release
;
241 wxMacCarbonEvent(UInt32 inClassID
,UInt32 inKind
,EventTime inWhen
= 0 /*now*/,EventAttributes inAttributes
=kEventAttributeNone
)
244 verify_noerr( MacCreateEvent( NULL
, inClassID
, inKind
,inWhen
,inAttributes
,&m_eventRef
) ) ;
250 ReleaseEvent( m_eventRef
) ;
253 OSStatus
GetParameter( EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
) ;
255 template <typename T
> OSStatus
GetParameter( EventParamName inName
, EventParamType type
, T
*data
)
257 return GetParameter( inName
, type
, sizeof( T
) , data
) ;
259 template <typename T
> OSStatus
GetParameter( EventParamName inName
, T
*data
)
261 return GetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , data
) ;
264 template <typename T
> T
GetParameter( EventParamName inName
)
267 verify_noerr( GetParameter
<T
>( inName
, &value
) ) ;
270 template <typename T
> T
GetParameter( EventParamName inName
, EventParamType inDesiredType
)
273 verify_noerr( GetParameter
<T
>( inName
, inDesiredType
, &value
) ) ;
277 OSStatus
SetParameter( EventParamName inName
, EventParamType inType
, UInt32 inSize
, const void * inData
) ;
278 template <typename T
> OSStatus
SetParameter( EventParamName inName
, EventParamType inDesiredType
, const T
*data
)
280 return SetParameter( inName
, inDesiredType
, sizeof( T
) , data
) ;
282 template <typename T
> OSStatus
SetParameter( EventParamName inName
, EventParamType inDesiredType
, const T
& data
)
284 return SetParameter
<T
>( inName
, inDesiredType
, &data
) ;
286 template <typename T
> OSStatus
SetParameter( EventParamName inName
, const T
*data
)
288 return SetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , data
) ;
290 template <typename T
> OSStatus
SetParameter( EventParamName inName
, const T
& data
)
292 return SetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , &data
) ;
296 return ::GetEventClass( m_eventRef
) ;
300 return ::GetEventKind( m_eventRef
) ;
304 return ::GetEventTime( m_eventRef
) ;
308 return EventTimeToTicks( GetTime() ) ;
310 operator EventRef () { return m_eventRef
; }
312 EventRef m_eventRef
;
321 m_controlRef
= NULL
;
324 wxMacControl( ControlRef control
)
326 m_controlRef
= control
;
328 wxMacControl( WXWidget control
)
330 m_controlRef
= (ControlRef
) control
;
332 virtual ~wxMacControl()
336 virtual void Dispose() ;
338 bool Ok() const { return GetControlRef() != NULL
; }
340 virtual ControlRef
* GetControlRefAddr() { return &m_controlRef
; }
341 virtual ControlRef
GetControlRef() const { return m_controlRef
; }
343 virtual void SetReference( SInt32 data
) ;
345 void operator= (ControlRef c) { m_controlRef = c ; }
346 operator ControlRef () { return m_controlRef; }
347 operator ControlRef * () { return &m_controlRef; }
349 // accessing data and values
351 virtual OSStatus
SetData( ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
) ;
352 virtual OSStatus
GetData( ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const ;
353 virtual OSStatus
GetDataSize( ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const ;
354 virtual OSStatus
SendEvent( EventRef ref
, OptionBits inOptions
= 0 ) ;
355 virtual OSStatus
SendHICommand( HICommand
&command
, OptionBits inOptions
= 0 ) ;
357 virtual OSStatus
SendHICommand( UInt32 commandID
, OptionBits inOptions
= 0 ) ;
359 virtual SInt32
GetValue() const ;
360 virtual SInt32
GetMaximum() const ;
361 virtual SInt32
GetMinimum() const ;
363 virtual void SetValue( SInt32 v
) ;
364 virtual void SetMinimum( SInt32 v
) ;
365 virtual void SetMaximum( SInt32 v
) ;
367 virtual void SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
) ;
368 virtual void SetRange( SInt32 minimum
, SInt32 maximum
) ;
370 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
371 virtual bool HasFocus() const ;
372 virtual bool NeedsFocusRect() const ;
376 Size
GetDataSize( ControlPartCode inPartCode
, ResType inTag
) const
379 verify_noerr( GetDataSize( inPartCode
, inTag
, &sz
) ) ;
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
SetData( ControlPartCode inPartCode
, ResType inTag
, const T
& data
)
388 return SetData( inPartCode
, inTag
, sizeof( T
) , &data
) ;
390 template <typename T
> OSStatus
GetData( ControlPartCode inPartCode
, ResType inTag
, T
*data
) const
393 return GetData( inPartCode
, inTag
, sizeof( T
) , data
, &dummy
) ;
395 template <typename T
> T
GetData( ControlPartCode inPartCode
, ResType inTag
) const
398 verify_noerr( GetData
<T
>( inPartCode
, inTag
, &value
) ) ;
402 // Flash the control for the specified amount of time
403 virtual void Flash( ControlPartCode part
, UInt32 ticks
= 8 ) ;
404 virtual void VisibilityChanged( bool shown
) ;
405 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
406 virtual void SetBackground( const wxBrush
&brush
) ;
407 virtual ControlPartCode
HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
) ;
408 void SetActionProc( ControlActionUPP actionProc
) ;
409 void SetViewSize( SInt32 viewSize
) ;
410 SInt32
GetViewSize() const ;
412 virtual bool IsVisible() const ;
413 virtual void SetVisibility( bool visible
, bool redraw
) ;
414 virtual bool IsEnabled() const ;
415 virtual bool IsActive() const ;
416 virtual void Enable( bool enable
) ;
418 // invalidates this control and all children
419 virtual void InvalidateWithChildren() ;
420 virtual void SetDrawingEnabled( bool enable
) ;
421 virtual bool GetNeedsDisplay() const ;
422 virtual void SetNeedsDisplay( bool needsDisplay
, RgnHandle where
= NULL
) ;
424 virtual void ScrollRect( const wxRect
&rect
, int dx
, int dy
) ;
426 virtual void GetRect( Rect
*r
) ;
427 virtual void SetRect( Rect
*r
) ;
428 virtual void GetRectInWindowCoords( Rect
*r
) ;
429 virtual void GetBestRect( Rect
*r
) ;
430 virtual void SetTitle( const wxString
&title
) ;
431 // converts from Toplevel-Content relative to local
432 static void Convert( wxPoint
*pt
, wxMacControl
*convert
, wxMacControl
*to
) ;
434 virtual void GetFeatures( UInt32
*features
) ;
435 virtual OSStatus
GetRegion( ControlPartCode partCode
, RgnHandle region
) ;
436 virtual OSStatus
SetZOrder( bool above
, wxMacControl
* other
) ;
437 // to be moved into a databrowser subclass
439 virtual OSStatus
SetSelectionFlags( DataBrowserSelectionFlags
) ;
440 virtual OSStatus
AddListViewColumn( DataBrowserListViewColumnDesc
*columnDesc
,
441 DataBrowserTableViewColumnIndex position
) ;
442 virtual OSStatus
AutoSizeListViewColumns() ;
443 virtual OSStatus
SetHasScrollBars( bool horiz
, bool vert
) ;
444 virtual OSStatus
SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
) ;
445 virtual OSStatus
SetListViewHeaderBtnHeight(UInt16 height
) ;
446 virtual OSStatus
SetCallbacks(const DataBrowserCallbacks
* callbacks
) ;
447 virtual OSStatus
UpdateItems( DataBrowserItemID container
, UInt32 numItems
,
448 const DataBrowserItemID
* items
,
449 DataBrowserPropertyID preSortProperty
,
450 DataBrowserPropertyID propertyID
) ;
451 virtual OSStatus
AddItems( DataBrowserItemID container
, UInt32 numItems
,
452 const DataBrowserItemID
* items
,
453 DataBrowserPropertyID preSortProperty
) ;
454 virtual OSStatus
RemoveItems( DataBrowserItemID container
, UInt32 numItems
,
455 const DataBrowserItemID
* items
,
456 DataBrowserPropertyID preSortProperty
) ;
457 virtual OSStatus
RevealItem( DataBrowserItemID item
,
458 DataBrowserPropertyID propertyID
,
459 DataBrowserRevealOptions options
) ;
460 virtual OSStatus
GetSelectionAnchor( DataBrowserItemID
* first
, DataBrowserItemID
* last
) ;
461 virtual bool IsItemSelected( DataBrowserItemID item
) ;
462 virtual OSStatus
SetSelectedItems(UInt32 numItems
,
463 const DataBrowserItemID
* items
,
464 DataBrowserSetOption operation
) ;
466 // to be moved into a tab control class
468 virtual OSStatus
SetTabEnabled( SInt16 tabNo
, bool enable
) ;
470 ControlRef m_controlRef
;
477 //---------------------------------------------------------------------------
478 // wxMac string conversions
479 //---------------------------------------------------------------------------
481 void wxMacSetupConverters() ;
482 void wxMacCleanupConverters() ;
484 void wxMacStringToPascal( const wxString
&from
, StringPtr to
) ;
485 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
) ;
489 ControlRef
wxMacFindControlUnderMouse( Point location
, WindowRef window
, ControlPartCode
*outPart
) ;
493 wxString
wxMacFSRefToPath( const FSRef
*fsRef
, CFStringRef additionalPathComponent
= NULL
) ;
494 OSStatus
wxMacPathToFSRef( const wxString
&path
, FSRef
*fsRef
) ;
495 wxString
wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname
) ;