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>
34 #if UNIVERSAL_INTERFACES_VERSION < 0x0340
35 #error "please update to Apple's lastest universal headers from http://developer.apple.com/sdk/"
38 #ifndef MAC_OS_X_VERSION_10_3
39 #define MAC_OS_X_VERSION_10_3 1030
42 #ifdef __WXMAC_CARBON__
43 #include "wx/mac/corefoundation/cfstring.h"
47 // as macro in FixMath.h for 10.3
48 inline Fixed
IntToFixed( int inInt
)
50 return (((SInt32
) inInt
) << 16);
53 inline int FixedToInt( Fixed inFixed
)
55 return (((SInt32
) inFixed
) >> 16);
61 #include "wx/window.h"
63 class wxMacPortStateHelper
65 DECLARE_NO_COPY_CLASS(wxMacPortStateHelper
)
68 wxMacPortStateHelper( GrafPtr newport
) ;
69 wxMacPortStateHelper() ;
70 ~wxMacPortStateHelper() ;
72 void Setup( GrafPtr newport
) ;
74 bool IsCleared() { return m_clip
== NULL
; }
75 GrafPtr
GetCurrentPort() { return m_currentPort
; }
78 GrafPtr m_currentPort
;
81 ThemeDrawingState m_drawingState
;
88 class WXDLLEXPORT wxMacPortSaver
90 DECLARE_NO_COPY_CLASS(wxMacPortSaver
)
93 wxMacPortSaver( GrafPtr port
)
95 ::GetPort( &m_port
) ;
100 ::SetPort( m_port
) ;
106 class WXDLLEXPORT wxMacPortSetter
108 DECLARE_NO_COPY_CLASS(wxMacPortSetter
)
111 wxMacPortSetter( const wxDC
* dc
) ;
114 wxMacPortStateHelper m_ph
;
119 Clips to the visible region of a control within the current port
122 class WXDLLEXPORT wxMacWindowClipper
: public wxMacPortSaver
124 DECLARE_NO_COPY_CLASS(wxMacWindowClipper
)
127 wxMacWindowClipper( const wxWindow
* win
) ;
128 ~wxMacWindowClipper() ;
131 RgnHandle m_formerClip
;
132 RgnHandle m_newClip
;
135 class WXDLLEXPORT wxMacWindowStateSaver
: public wxMacWindowClipper
137 DECLARE_NO_COPY_CLASS(wxMacWindowStateSaver
)
140 wxMacWindowStateSaver( const wxWindow
* win
) ;
141 ~wxMacWindowStateSaver() ;
144 ThemeDrawingState m_themeDrawingState
;
148 class wxMacDrawingHelper
150 DECLARE_NO_COPY_CLASS(wxMacDrawingHelper)
153 wxMacDrawingHelper( wxWindowMac * theWindow , bool clientArea = false ) ;
154 ~wxMacDrawingHelper() ;
155 bool Ok() { return m_ok ; }
156 void LocalToWindow( Rect *rect) { OffsetRect( rect , m_origin.h , m_origin.v ) ; }
157 void LocalToWindow( Point *pt ) { AddPt( m_origin , pt ) ; }
158 void LocalToWindow( RgnHandle rgn ) { OffsetRgn( rgn , m_origin.h , m_origin.v ) ; }
159 const Point& GetOrigin() { return m_origin ; }
162 GrafPtr m_formerPort ;
163 GrafPtr m_currentPort ;
164 PenState m_savedPenState ;
170 bool wxMacConvertEventToRecord( EventRef event
, EventRecord
*rec
) ;
175 WXDLLEXPORT wxString
wxMacFSSpec2MacFilename( const FSSpec
*spec
) ;
176 WXDLLEXPORT
void wxMacFilename2FSSpec( const wxString
&path
, FSSpec
*spec
) ;
179 WXDLLEXPORT wxString
wxMacFindFolder(short vRefNum
,
181 Boolean createFolder
);
183 template<typename T
> EventParamType
wxMacGetEventParamType() { wxFAIL_MSG( wxT("Unknown Param Type") ) ; return 0 ; }
184 template<> inline EventParamType wxMacGetEventParamType
<RgnHandle
>() { return typeQDRgnHandle
; }
185 template<> inline EventParamType wxMacGetEventParamType
<ControlRef
>() { return typeControlRef
; }
186 template<> inline EventParamType wxMacGetEventParamType
<WindowRef
>() { return typeWindowRef
; }
187 template<> inline EventParamType wxMacGetEventParamType
<MenuRef
>() { return typeMenuRef
; }
188 template<> inline EventParamType wxMacGetEventParamType
<EventRef
>() { return typeEventRef
; }
189 template<> inline EventParamType wxMacGetEventParamType
<Point
>() { return typeQDPoint
; }
190 template<> inline EventParamType wxMacGetEventParamType
<Rect
>() { return typeQDRectangle
; }
191 template<> inline EventParamType wxMacGetEventParamType
<Boolean
>() { return typeBoolean
; }
192 #if TARGET_API_MAC_OSX
193 template<> inline EventParamType wxMacGetEventParamType
<HICommand
>() { return typeHICommand
; }
194 template<> inline EventParamType wxMacGetEventParamType
<HIPoint
>() { return typeHIPoint
; }
195 template<> inline EventParamType wxMacGetEventParamType
<HISize
>() { return typeHISize
; }
196 template<> inline EventParamType wxMacGetEventParamType
<HIRect
>() { return typeHIRect
; }
197 template<> inline EventParamType wxMacGetEventParamType
<void*>() { return typeVoidPtr
; }
199 template<> inline EventParamType wxMacGetEventParamType
<Collection
>() { return typeCollection
; }
200 template<> inline EventParamType wxMacGetEventParamType
<CGContextRef
>() { return typeCGContextRef
; }
203 template<> EventParamType wxMacGetEventParamType<GrafPtr>() { return typeGrafPtr ; }
204 template<> EventParamType wxMacGetEventParamType<OSStatus>() { return typeOSStatus ; }
205 template<> EventParamType wxMacGetEventParamType<CFIndex>() { return typeCFIndex ; }
206 template<> EventParamType wxMacGetEventParamType<GWorldPtr>() { return typeGWorldPtr ; }
209 class wxMacCarbonEvent
219 wxMacCarbonEvent( EventRef event
, bool release
= false )
222 m_release
= release
;
225 wxMacCarbonEvent(UInt32 inClassID
,UInt32 inKind
,EventTime inWhen
= 0 /*now*/,EventAttributes inAttributes
=kEventAttributeNone
)
228 verify_noerr( MacCreateEvent( NULL
, inClassID
, inKind
,inWhen
,inAttributes
,&m_eventRef
) ) ;
235 ReleaseEvent( m_eventRef
) ;
238 OSStatus
Create(UInt32 inClassID
,UInt32 inKind
,EventTime inWhen
= 0 /*now*/,EventAttributes inAttributes
=kEventAttributeNone
)
240 verify( (m_eventRef
== NULL
) || m_release
) ;
241 if ( m_eventRef
&& m_release
)
243 ReleaseEvent( m_eventRef
) ;
248 OSStatus err
= MacCreateEvent( NULL
, inClassID
, inKind
,inWhen
,inAttributes
,&m_eventRef
) ;
254 OSStatus
GetParameter( EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
) ;
256 template <typename T
> OSStatus
GetParameter( EventParamName inName
, EventParamType type
, T
*data
)
258 return GetParameter( inName
, type
, sizeof( T
) , data
) ;
260 template <typename T
> OSStatus
GetParameter( EventParamName inName
, T
*data
)
262 return GetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , data
) ;
265 template <typename T
> T
GetParameter( EventParamName inName
)
268 verify_noerr( GetParameter
<T
>( inName
, &value
) ) ;
271 template <typename T
> T
GetParameter( EventParamName inName
, EventParamType inDesiredType
)
274 verify_noerr( GetParameter
<T
>( inName
, inDesiredType
, &value
) ) ;
278 OSStatus
SetParameter( EventParamName inName
, EventParamType inType
, UInt32 inSize
, const void * inData
) ;
279 template <typename T
> OSStatus
SetParameter( EventParamName inName
, EventParamType inDesiredType
, const T
*data
)
281 return SetParameter( inName
, inDesiredType
, sizeof( T
) , data
) ;
283 template <typename T
> OSStatus
SetParameter( EventParamName inName
, EventParamType inDesiredType
, const T
& data
)
285 return SetParameter
<T
>( inName
, inDesiredType
, &data
) ;
287 template <typename T
> OSStatus
SetParameter( EventParamName inName
, const T
*data
)
289 return SetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , data
) ;
291 template <typename T
> OSStatus
SetParameter( EventParamName inName
, const T
& data
)
293 return SetParameter
<T
>( inName
, wxMacGetEventParamType
<T
>() , &data
) ;
297 return ::GetEventClass( m_eventRef
) ;
301 return ::GetEventKind( m_eventRef
) ;
305 return ::GetEventTime( m_eventRef
) ;
309 return EventTimeToTicks( GetTime() ) ;
311 OSStatus
SetTime( EventTime inWhen
= 0 /*now*/ )
313 return ::SetEventTime( m_eventRef
, inWhen
? inWhen
: GetCurrentEventTime() ) ;
315 operator EventRef () { return m_eventRef
; }
317 bool IsValid() { return m_eventRef
!= 0 ; }
319 EventRef m_eventRef
;
324 // helper class for allocating and deallocating Universal Proc Ptrs
327 template <typename procType
, typename uppType
, uppType (*newUPP
)(procType
) , void (*disposeUPP
)(uppType
) > class wxMacUPP
330 wxMacUPP( procType proc
)
333 m_upp
= (*newUPP
)( NULL
) ;
338 disposeUPP( m_upp
) ;
340 operator uppType() { return m_upp
; }
345 typedef wxMacUPP
<NMProcPtr
,NMUPP
,NewNMUPP
,DisposeNMUPP
> wxMacNMUPP
;
349 GWorldPtr
wxMacCreateGWorld( int width
, int height
, int depth
) ;
350 void wxMacDestroyGWorld( GWorldPtr gw
) ;
351 PicHandle
wxMacCreatePict( GWorldPtr gw
, GWorldPtr mask
= NULL
) ;
352 CIconHandle
wxMacCreateCIcon(GWorldPtr image
, GWorldPtr mask
, short dstDepth
, short iconSize
) ;
353 void wxMacSetColorTableEntry( CTabHandle newColors
, int index
, int red
, int green
, int blue
) ;
354 CTabHandle
wxMacCreateColorTable( int numColors
) ;
355 void wxMacCreateBitmapButton( ControlButtonContentInfo
*info
, const wxBitmap
& bitmap
, int forceType
= 0 ) ;
357 #define MAC_WXCOLORREF(a) (*((RGBColor*)&(a)))
358 #define MAC_WXHBITMAP(a) (GWorldPtr(a))
359 #define MAC_WXHMETAFILE(a) (PicHandle(a))
360 #define MAC_WXHICON(a) (CIconHandle(a))
361 #define MAC_WXHCURSOR(a) (CursHandle(a))
362 #define MAC_WXHRGN(a) (RgnHandle(a))
363 #define MAC_WXHWND(a) (WindowPtr(a))
364 #define MAC_WXRECPTR(a) ((Rect*)a)
365 #define MAC_WXPOINTPTR(a) ((Point*)a)
366 #define MAC_WXHMENU(a) ((MenuHandle)a)
368 struct wxOpaqueWindowRef
370 wxOpaqueWindowRef( WindowRef ref
) { m_data
= ref
; }
371 operator WindowRef() { return m_data
; }
376 wxWindow
* wxFindControlFromMacControl(ControlRef inControl
) ;
377 wxTopLevelWindowMac
* wxFindWinFromMacWindow( WindowRef inWindow
) ;
378 wxMenu
* wxFindMenuFromMacMenu(MenuRef inMenuRef
) ;
380 extern wxWindow
* g_MacLastWindow
;
381 pascal OSStatus
wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler
, EventRef event
, void *data
) ;
382 Rect
wxMacGetBoundsForControl( wxWindow
* window
, const wxPoint
& pos
, const wxSize
&size
, bool adjustForOrigin
= true ) ;
389 m_controlRef
= NULL
;
392 wxMacControl( ControlRef control
)
394 m_controlRef
= control
;
396 wxMacControl( WXWidget control
)
398 m_controlRef
= (ControlRef
) control
;
400 virtual ~wxMacControl()
404 virtual void Dispose() ;
406 bool Ok() const { return GetControlRef() != NULL
; }
408 virtual ControlRef
* GetControlRefAddr() { return &m_controlRef
; }
409 virtual ControlRef
GetControlRef() const { return m_controlRef
; }
411 virtual void SetReference( SInt32 data
) ;
413 void operator= (ControlRef c) { m_controlRef = c ; }
414 operator ControlRef () { return m_controlRef; }
415 operator ControlRef * () { return &m_controlRef; }
417 // accessing data and values
419 virtual OSStatus
SetData( ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
) ;
420 virtual OSStatus
GetData( ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const ;
421 virtual OSStatus
GetDataSize( ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const ;
422 virtual OSStatus
SendEvent( EventRef ref
, OptionBits inOptions
= 0 ) ;
423 virtual OSStatus
SendHICommand( HICommand
&command
, OptionBits inOptions
= 0 ) ;
425 virtual OSStatus
SendHICommand( UInt32 commandID
, OptionBits inOptions
= 0 ) ;
427 virtual SInt32
GetValue() const ;
428 virtual SInt32
GetMaximum() const ;
429 virtual SInt32
GetMinimum() const ;
431 virtual void SetValue( SInt32 v
) ;
432 virtual void SetMinimum( SInt32 v
) ;
433 virtual void SetMaximum( SInt32 v
) ;
435 virtual void SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
) ;
436 virtual void SetRange( SInt32 minimum
, SInt32 maximum
) ;
438 virtual OSStatus
SetFocus( ControlFocusPart focusPart
) ;
439 virtual bool HasFocus() const ;
440 virtual bool NeedsFocusRect() const ;
444 Size
GetDataSize( ControlPartCode inPartCode
, ResType inTag
) const
447 verify_noerr( GetDataSize( inPartCode
, inTag
, &sz
) ) ;
450 template <typename T
> OSStatus
SetData( ControlPartCode inPartCode
, ResType inTag
, const T
*data
)
452 return SetData( inPartCode
, inTag
, sizeof( T
) , data
) ;
454 template <typename T
> OSStatus
SetData( ControlPartCode inPartCode
, ResType inTag
, const T
& data
)
456 return SetData( inPartCode
, inTag
, sizeof( T
) , &data
) ;
458 template <typename T
> OSStatus
GetData( ControlPartCode inPartCode
, ResType inTag
, T
*data
) const
461 return GetData( inPartCode
, inTag
, sizeof( T
) , data
, &dummy
) ;
463 template <typename T
> T
GetData( ControlPartCode inPartCode
, ResType inTag
) const
466 verify_noerr( GetData
<T
>( inPartCode
, inTag
, &value
) ) ;
470 // Flash the control for the specified amount of time
471 virtual void Flash( ControlPartCode part
, UInt32 ticks
= 8 ) ;
472 virtual void VisibilityChanged( bool shown
) ;
473 virtual void SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
) ;
474 virtual void SetBackground( const wxBrush
&brush
) ;
475 virtual ControlPartCode
HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
) ;
476 void SetActionProc( ControlActionUPP actionProc
) ;
477 void SetViewSize( SInt32 viewSize
) ;
478 SInt32
GetViewSize() const ;
480 virtual bool IsVisible() const ;
481 virtual void SetVisibility( bool visible
, bool redraw
) ;
482 virtual bool IsEnabled() const ;
483 virtual bool IsActive() const ;
484 virtual void Enable( bool enable
) ;
486 // invalidates this control and all children
487 virtual void InvalidateWithChildren() ;
488 virtual void SetDrawingEnabled( bool enable
) ;
489 virtual bool GetNeedsDisplay() const ;
490 virtual void SetNeedsDisplay( bool needsDisplay
, RgnHandle where
= NULL
) ;
492 virtual void ScrollRect( const wxRect
&rect
, int dx
, int dy
) ;
494 virtual void GetRect( Rect
*r
) ;
495 virtual void SetRect( Rect
*r
) ;
496 virtual void GetRectInWindowCoords( Rect
*r
) ;
497 virtual void GetBestRect( Rect
*r
) ;
498 virtual void SetTitle( const wxString
&title
) ;
499 // converts from Toplevel-Content relative to local
500 static void Convert( wxPoint
*pt
, wxMacControl
*convert
, wxMacControl
*to
) ;
502 virtual void GetFeatures( UInt32
*features
) ;
503 virtual OSStatus
GetRegion( ControlPartCode partCode
, RgnHandle region
) ;
504 virtual OSStatus
SetZOrder( bool above
, wxMacControl
* other
) ;
505 // to be moved into a databrowser subclass
507 virtual OSStatus
SetSelectionFlags( DataBrowserSelectionFlags
) ;
508 virtual OSStatus
AddListViewColumn( DataBrowserListViewColumnDesc
*columnDesc
,
509 DataBrowserTableViewColumnIndex position
) ;
510 virtual OSStatus
AutoSizeListViewColumns() ;
511 virtual OSStatus
SetHasScrollBars( bool horiz
, bool vert
) ;
512 virtual OSStatus
SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
) ;
513 virtual OSStatus
SetListViewHeaderBtnHeight(UInt16 height
) ;
514 virtual OSStatus
SetCallbacks(const DataBrowserCallbacks
* callbacks
) ;
515 virtual OSStatus
UpdateItems( DataBrowserItemID container
, UInt32 numItems
,
516 const DataBrowserItemID
* items
,
517 DataBrowserPropertyID preSortProperty
,
518 DataBrowserPropertyID propertyID
) ;
519 virtual OSStatus
AddItems( DataBrowserItemID container
, UInt32 numItems
,
520 const DataBrowserItemID
* items
,
521 DataBrowserPropertyID preSortProperty
) ;
522 virtual OSStatus
RemoveItems( DataBrowserItemID container
, UInt32 numItems
,
523 const DataBrowserItemID
* items
,
524 DataBrowserPropertyID preSortProperty
) ;
525 virtual OSStatus
RevealItem( DataBrowserItemID item
,
526 DataBrowserPropertyID propertyID
,
527 DataBrowserRevealOptions options
) ;
528 virtual OSStatus
GetSelectionAnchor( DataBrowserItemID
* first
, DataBrowserItemID
* last
) ;
529 virtual bool IsItemSelected( DataBrowserItemID item
) ;
530 virtual OSStatus
SetSelectedItems(UInt32 numItems
,
531 const DataBrowserItemID
* items
,
532 DataBrowserSetOption operation
) ;
534 // to be moved into a tab control class
536 virtual OSStatus
SetTabEnabled( SInt16 tabNo
, bool enable
) ;
538 ControlRef m_controlRef
;
545 //---------------------------------------------------------------------------
546 // wxMac string conversions
547 //---------------------------------------------------------------------------
549 void wxMacSetupConverters() ;
550 void wxMacCleanupConverters() ;
552 void wxMacStringToPascal( const wxString
&from
, StringPtr to
) ;
553 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
) ;
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
) ;