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
);
169 template<typename T
> EventParamType
wxMacGetEventParamType() { wxFAIL_MSG( wxT("Unknown Param Type") ) ; return 0 ; }
170 template<> inline EventParamType wxMacGetEventParamType
<RgnHandle
>() { return typeQDRgnHandle
; }
171 template<> inline EventParamType wxMacGetEventParamType
<ControlRef
>() { return typeControlRef
; }
172 template<> inline EventParamType wxMacGetEventParamType
<WindowRef
>() { return typeWindowRef
; }
173 template<> inline EventParamType wxMacGetEventParamType
<MenuRef
>() { return typeMenuRef
; }
174 template<> inline EventParamType wxMacGetEventParamType
<EventRef
>() { return typeEventRef
; }
175 template<> inline EventParamType wxMacGetEventParamType
<Point
>() { return typeQDPoint
; }
176 template<> inline EventParamType wxMacGetEventParamType
<Rect
>() { return typeQDRectangle
; }
177 template<> inline EventParamType wxMacGetEventParamType
<Boolean
>() { return typeBoolean
; }
178 #if TARGET_API_MAC_OSX
179 template<> inline EventParamType wxMacGetEventParamType
<HICommand
>() { return typeHICommand
; }
180 template<> inline EventParamType wxMacGetEventParamType
<HIPoint
>() { return typeHIPoint
; }
181 template<> inline EventParamType wxMacGetEventParamType
<HISize
>() { return typeHISize
; }
182 template<> inline EventParamType wxMacGetEventParamType
<HIRect
>() { return typeHIRect
; }
183 template<> inline EventParamType wxMacGetEventParamType
<void*>() { return typeVoidPtr
; }
185 template<> inline EventParamType wxMacGetEventParamType
<Collection
>() { return typeCollection
; }
186 template<> inline EventParamType wxMacGetEventParamType
<CGContextRef
>() { return typeCGContextRef
; }
189 template<> EventParamType wxMacGetEventParamType<GrafPtr>() { return typeGrafPtr ; }
190 template<> EventParamType wxMacGetEventParamType<OSStatus>() { return typeOSStatus ; }
191 template<> EventParamType wxMacGetEventParamType<CFIndex>() { return typeCFIndex ; }
192 template<> EventParamType wxMacGetEventParamType<GWorldPtr>() { return typeGWorldPtr ; }
195 class wxMacCarbonEvent
205 wxMacCarbonEvent( EventRef event
, bool release
= false )
208 m_release
= release
;
211 wxMacCarbonEvent(UInt32 inClassID
,UInt32 inKind
,EventTime inWhen
= 0 /*now*/,EventAttributes inAttributes
=kEventAttributeNone
)
214 verify_noerr( MacCreateEvent( NULL
, inClassID
, inKind
,inWhen
,inAttributes
,&m_eventRef
) ) ;
221 ReleaseEvent( m_eventRef
) ;
224 OSStatus
Create(UInt32 inClassID
,UInt32 inKind
,EventTime inWhen
= 0 /*now*/,EventAttributes inAttributes
=kEventAttributeNone
)
226 verify( (m_eventRef
== NULL
) || m_release
) ;
227 if ( m_eventRef
&& m_release
)
229 ReleaseEvent( m_eventRef
) ;
234 OSStatus err
= MacCreateEvent( NULL
, inClassID
, inKind
,inWhen
,inAttributes
,&m_eventRef
) ;
240 OSStatus
GetParameter( EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
) ;
242 template <typename T
> OSStatus
GetParameter( EventParamName inName
, EventParamType type
, T
*data
)
244 return GetParameter( inName
, type
, sizeof( T
) , data
) ;
246 template <typename T
> OSStatus
GetParameter( EventParamName inName
, T
*data
)
248 return GetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , data
) ;
251 template <typename T
> T
GetParameter( EventParamName inName
)
254 verify_noerr( GetParameter
<T
>( inName
, &value
) ) ;
257 template <typename T
> T
GetParameter( EventParamName inName
, EventParamType inDesiredType
)
260 verify_noerr( GetParameter
<T
>( inName
, inDesiredType
, &value
) ) ;
264 OSStatus
SetParameter( EventParamName inName
, EventParamType inType
, UInt32 inSize
, const void * inData
) ;
265 template <typename T
> OSStatus
SetParameter( EventParamName inName
, EventParamType inDesiredType
, const T
*data
)
267 return SetParameter( inName
, inDesiredType
, sizeof( T
) , data
) ;
269 template <typename T
> OSStatus
SetParameter( EventParamName inName
, EventParamType inDesiredType
, const T
& data
)
271 return SetParameter
<T
>( inName
, inDesiredType
, &data
) ;
273 template <typename T
> OSStatus
SetParameter( EventParamName inName
, const T
*data
)
275 return SetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , data
) ;
277 template <typename T
> OSStatus
SetParameter( EventParamName inName
, const T
& data
)
279 return SetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , &data
) ;
283 return ::GetEventClass( m_eventRef
) ;
287 return ::GetEventKind( m_eventRef
) ;
291 return ::GetEventTime( m_eventRef
) ;
295 return EventTimeToTicks( GetTime() ) ;
297 OSStatus
SetTime( EventTime inWhen
= 0 /*now*/ )
299 return ::SetEventTime( m_eventRef
, inWhen
? inWhen
: GetCurrentEventTime() ) ;
301 operator EventRef () { return m_eventRef
; }
303 bool IsValid() { return m_eventRef
!= 0 ; }
305 EventRef m_eventRef
;
310 // helper class for allocating and deallocating Universal Proc Ptrs
313 template <typename procType
, typename uppType
, uppType (*newUPP
)(procType
) , void (*disposeUPP
)(uppType
) > class wxMacUPP
316 wxMacUPP( procType proc
)
319 m_upp
= (*newUPP
)( NULL
) ;
324 disposeUPP( m_upp
) ;
326 operator uppType() { return m_upp
; }
331 typedef wxMacUPP
<NMProcPtr
,NMUPP
,NewNMUPP
,DisposeNMUPP
> wxMacNMUPP
;
335 GWorldPtr
wxMacCreateGWorld( int width
, int height
, int depth
) ;
336 void wxMacDestroyGWorld( GWorldPtr gw
) ;
337 PicHandle
wxMacCreatePict( GWorldPtr gw
, GWorldPtr mask
= NULL
) ;
338 CIconHandle
wxMacCreateCIcon(GWorldPtr image
, GWorldPtr mask
, short dstDepth
, short iconSize
) ;
339 void wxMacSetColorTableEntry( CTabHandle newColors
, int index
, int red
, int green
, int blue
) ;
340 CTabHandle
wxMacCreateColorTable( int numColors
) ;
341 void wxMacCreateBitmapButton( ControlButtonContentInfo
*info
, const wxBitmap
& bitmap
, int forceType
= 0 ) ;
343 #define MAC_WXCOLORREF(a) (*((RGBColor*)&(a)))
344 #define MAC_WXHBITMAP(a) (GWorldPtr(a))
345 #define MAC_WXHMETAFILE(a) (PicHandle(a))
346 #define MAC_WXHICON(a) (CIconHandle(a))
347 #define MAC_WXHCURSOR(a) (CursHandle(a))
348 #define MAC_WXHRGN(a) (RgnHandle(a))
349 #define MAC_WXHWND(a) (WindowPtr(a))
350 #define MAC_WXRECPTR(a) ((Rect*)a)
351 #define MAC_WXPOINTPTR(a) ((Point*)a)
352 #define MAC_WXHMENU(a) ((MenuHandle)a)
354 struct wxOpaqueWindowRef
356 wxOpaqueWindowRef( WindowRef ref
) { m_data
= ref
; }
357 operator WindowRef() { return m_data
; }
362 wxWindow
* wxFindControlFromMacControl(ControlRef inControl
) ;
363 wxTopLevelWindowMac
* wxFindWinFromMacWindow( WindowRef inWindow
) ;
364 wxMenu
* wxFindMenuFromMacMenu(MenuRef inMenuRef
) ;
366 extern wxWindow
* g_MacLastWindow
;
367 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
368 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
= true ) ;
375 m_controlRef
= NULL
;
378 wxMacControl( ControlRef control
)
380 m_controlRef
= control
;
382 wxMacControl( WXWidget control
)
384 m_controlRef
= (ControlRef
) control
;
386 virtual ~wxMacControl()
390 virtual void Dispose() ;
392 bool Ok() const { return GetControlRef() != NULL
; }
394 virtual ControlRef
* GetControlRefAddr() { return &m_controlRef
; }
395 virtual ControlRef
GetControlRef() const { return m_controlRef
; }
397 virtual void SetReference( SInt32 data
) ;
399 void operator= (ControlRef c) { m_controlRef = c ; }
400 operator ControlRef () { return m_controlRef; }
401 operator ControlRef * () { return &m_controlRef; }
403 // accessing data and values
405 virtual OSStatus
SetData( ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
) ;
406 virtual OSStatus
GetData( ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const ;
407 virtual OSStatus
GetDataSize( ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const ;
408 virtual OSStatus
SendEvent( EventRef ref
, OptionBits inOptions
= 0 ) ;
409 virtual OSStatus
SendHICommand( HICommand
&command
, OptionBits inOptions
= 0 ) ;
411 virtual OSStatus
SendHICommand( UInt32 commandID
, OptionBits inOptions
= 0 ) ;
413 virtual SInt32
GetValue() const ;
414 virtual SInt32
GetMaximum() const ;
415 virtual SInt32
GetMinimum() const ;
417 virtual void SetValue( SInt32 v
) ;
418 virtual void SetMinimum( SInt32 v
) ;
419 virtual void SetMaximum( SInt32 v
) ;
421 virtual void SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
) ;
422 virtual void SetRange( SInt32 minimum
, SInt32 maximum
) ;
424 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
425 virtual bool HasFocus() const ;
426 virtual bool NeedsFocusRect() const ;
430 Size
GetDataSize( ControlPartCode inPartCode
, ResType inTag
) const
433 verify_noerr( GetDataSize( inPartCode
, inTag
, &sz
) ) ;
436 template <typename T
> OSStatus
SetData( ControlPartCode inPartCode
, ResType inTag
, const T
*data
)
438 return SetData( inPartCode
, inTag
, sizeof( T
) , data
) ;
440 template <typename T
> OSStatus
SetData( ControlPartCode inPartCode
, ResType inTag
, const T
& data
)
442 return SetData( inPartCode
, inTag
, sizeof( T
) , &data
) ;
444 template <typename T
> OSStatus
GetData( ControlPartCode inPartCode
, ResType inTag
, T
*data
) const
447 return GetData( inPartCode
, inTag
, sizeof( T
) , data
, &dummy
) ;
449 template <typename T
> T
GetData( ControlPartCode inPartCode
, ResType inTag
) const
452 verify_noerr( GetData
<T
>( inPartCode
, inTag
, &value
) ) ;
456 // Flash the control for the specified amount of time
457 virtual void Flash( ControlPartCode part
, UInt32 ticks
= 8 ) ;
458 virtual void VisibilityChanged( bool shown
) ;
459 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
460 virtual void SetBackground( const wxBrush
&brush
) ;
461 virtual ControlPartCode
HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
) ;
462 void SetActionProc( ControlActionUPP actionProc
) ;
463 void SetViewSize( SInt32 viewSize
) ;
464 SInt32
GetViewSize() const ;
466 virtual bool IsVisible() const ;
467 virtual void SetVisibility( bool visible
, bool redraw
) ;
468 virtual bool IsEnabled() const ;
469 virtual bool IsActive() const ;
470 virtual void Enable( bool enable
) ;
472 // invalidates this control and all children
473 virtual void InvalidateWithChildren() ;
474 virtual void SetDrawingEnabled( bool enable
) ;
475 virtual bool GetNeedsDisplay() const ;
476 virtual void SetNeedsDisplay( bool needsDisplay
, RgnHandle where
= NULL
) ;
478 virtual void ScrollRect( const wxRect
&rect
, int dx
, int dy
) ;
480 virtual void GetRect( Rect
*r
) ;
481 virtual void SetRect( Rect
*r
) ;
482 virtual void GetRectInWindowCoords( Rect
*r
) ;
483 virtual void GetBestRect( Rect
*r
) ;
484 virtual void SetTitle( const wxString
&title
) ;
485 // converts from Toplevel-Content relative to local
486 static void Convert( wxPoint
*pt
, wxMacControl
*convert
, wxMacControl
*to
) ;
488 virtual void GetFeatures( UInt32
*features
) ;
489 virtual OSStatus
GetRegion( ControlPartCode partCode
, RgnHandle region
) ;
490 virtual OSStatus
SetZOrder( bool above
, wxMacControl
* other
) ;
491 // to be moved into a databrowser subclass
493 virtual OSStatus
SetSelectionFlags( DataBrowserSelectionFlags
) ;
494 virtual OSStatus
AddListViewColumn( DataBrowserListViewColumnDesc
*columnDesc
,
495 DataBrowserTableViewColumnIndex position
) ;
496 virtual OSStatus
AutoSizeListViewColumns() ;
497 virtual OSStatus
SetHasScrollBars( bool horiz
, bool vert
) ;
498 virtual OSStatus
SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
) ;
499 virtual OSStatus
SetListViewHeaderBtnHeight(UInt16 height
) ;
500 virtual OSStatus
SetCallbacks(const DataBrowserCallbacks
* callbacks
) ;
501 virtual OSStatus
UpdateItems( DataBrowserItemID container
, UInt32 numItems
,
502 const DataBrowserItemID
* items
,
503 DataBrowserPropertyID preSortProperty
,
504 DataBrowserPropertyID propertyID
) ;
505 virtual OSStatus
AddItems( DataBrowserItemID container
, UInt32 numItems
,
506 const DataBrowserItemID
* items
,
507 DataBrowserPropertyID preSortProperty
) ;
508 virtual OSStatus
RemoveItems( DataBrowserItemID container
, UInt32 numItems
,
509 const DataBrowserItemID
* items
,
510 DataBrowserPropertyID preSortProperty
) ;
511 virtual OSStatus
RevealItem( DataBrowserItemID item
,
512 DataBrowserPropertyID propertyID
,
513 DataBrowserRevealOptions options
) ;
514 virtual OSStatus
GetSelectionAnchor( DataBrowserItemID
* first
, DataBrowserItemID
* last
) ;
515 virtual bool IsItemSelected( DataBrowserItemID item
) ;
516 virtual OSStatus
SetSelectedItems(UInt32 numItems
,
517 const DataBrowserItemID
* items
,
518 DataBrowserSetOption operation
) ;
520 // to be moved into a tab control class
522 virtual OSStatus
SetTabEnabled( SInt16 tabNo
, bool enable
) ;
524 ControlRef m_controlRef
;
531 //---------------------------------------------------------------------------
532 // wxMac string conversions
533 //---------------------------------------------------------------------------
535 void wxMacSetupConverters() ;
536 void wxMacCleanupConverters() ;
538 void wxMacStringToPascal( const wxString
&from
, StringPtr to
) ;
539 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
) ;
543 ControlRef
wxMacFindControlUnderMouse( Point location
, WindowRef window
, ControlPartCode
*outPart
) ;
547 wxString
wxMacFSRefToPath( const FSRef
*fsRef
, CFStringRef additionalPathComponent
= NULL
) ;
548 OSStatus
wxMacPathToFSRef( const wxString
&path
, FSRef
*fsRef
) ;
549 wxString
wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname
) ;