]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/private.h
As members have gone private, use Accessors
[wxWidgets.git] / include / wx / mac / carbon / private.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: private.h
3 // Purpose: Private declarations: as this header is only included by
4 // wxWidgets itself, it may contain identifiers which don't start
5 // with "wx".
6 // Author: Stefan Csomor
7 // Modified by:
8 // Created: 1998-01-01
9 // RCS-ID: $Id$
10 // Copyright: (c) Stefan Csomor
11 // Licence: wxWindows licence
12 /////////////////////////////////////////////////////////////////////////////
13
14 #ifndef _WX_PRIVATE_H_
15 #define _WX_PRIVATE_H_
16
17 #include "wx/defs.h"
18 #include "wx/app.h"
19
20 #ifdef __DARWIN__
21 # include <Carbon/Carbon.h>
22 #else
23 # include <Debugging.h>
24 # include <Quickdraw.h>
25 # include <Appearance.h>
26 # include <Folders.h>
27 # include <Controls.h>
28 # include <ControlDefinitions.h>
29 # include <LowMem.h>
30 # include <Gestalt.h>
31 # include <FixMath.h>
32 #endif
33
34 #if UNIVERSAL_INTERFACES_VERSION < 0x0340
35 #error "please update to Apple's lastest universal headers from http://developer.apple.com/sdk/"
36 #endif
37
38 #ifndef MAC_OS_X_VERSION_10_3
39 #define MAC_OS_X_VERSION_10_3 1030
40 #endif
41
42 #ifdef __WXMAC_CARBON__
43 #include "wx/mac/corefoundation/cfstring.h"
44 #endif
45
46 #ifndef FixedToInt
47 // as macro in FixMath.h for 10.3
48 inline Fixed IntToFixed( int inInt )
49 {
50 return (((SInt32) inInt) << 16);
51 }
52
53 inline int FixedToInt( Fixed inFixed )
54 {
55 return (((SInt32) inFixed) >> 16);
56 }
57 #endif
58
59 #if wxUSE_GUI
60
61 #include "wx/window.h"
62
63 class wxMacPortStateHelper
64 {
65 DECLARE_NO_COPY_CLASS(wxMacPortStateHelper)
66
67 public:
68 wxMacPortStateHelper( GrafPtr newport) ;
69 wxMacPortStateHelper() ;
70 ~wxMacPortStateHelper() ;
71
72 void Setup( GrafPtr newport ) ;
73 void Clear() ;
74 bool IsCleared() { return m_clip == NULL ; }
75 GrafPtr GetCurrentPort() { return m_currentPort ; }
76
77 private:
78 GrafPtr m_currentPort ;
79 GrafPtr m_oldPort ;
80 RgnHandle m_clip ;
81 ThemeDrawingState m_drawingState ;
82 short m_textFont ;
83 short m_textSize ;
84 short m_textStyle ;
85 short m_textMode ;
86 } ;
87
88 class WXDLLEXPORT wxMacPortSaver
89 {
90 DECLARE_NO_COPY_CLASS(wxMacPortSaver)
91
92 public:
93 wxMacPortSaver( GrafPtr port )
94 {
95 ::GetPort( &m_port ) ;
96 ::SetPort( port ) ;
97 }
98 ~wxMacPortSaver()
99 {
100 ::SetPort( m_port ) ;
101 }
102 private :
103 GrafPtr m_port ;
104 } ;
105
106 class WXDLLEXPORT wxMacPortSetter
107 {
108 DECLARE_NO_COPY_CLASS(wxMacPortSetter)
109
110 public:
111 wxMacPortSetter( const wxDC* dc ) ;
112 ~wxMacPortSetter() ;
113 private:
114 wxMacPortStateHelper m_ph ;
115 const wxDC* m_dc ;
116 } ;
117
118 /*
119 Clips to the visible region of a control within the current port
120 */
121
122 class WXDLLEXPORT wxMacWindowClipper : public wxMacPortSaver
123 {
124 DECLARE_NO_COPY_CLASS(wxMacWindowClipper)
125
126 public:
127 wxMacWindowClipper( const wxWindow* win ) ;
128 ~wxMacWindowClipper() ;
129 private:
130 GrafPtr m_newPort ;
131 RgnHandle m_formerClip ;
132 RgnHandle m_newClip ;
133 } ;
134
135 class WXDLLEXPORT wxMacWindowStateSaver : public wxMacWindowClipper
136 {
137 DECLARE_NO_COPY_CLASS(wxMacWindowStateSaver)
138
139 public:
140 wxMacWindowStateSaver( const wxWindow* win ) ;
141 ~wxMacWindowStateSaver() ;
142 private:
143 GrafPtr m_newPort ;
144 ThemeDrawingState m_themeDrawingState ;
145 } ;
146
147 /*
148 class wxMacDrawingHelper
149 {
150 DECLARE_NO_COPY_CLASS(wxMacDrawingHelper)
151
152 public:
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 ; }
160 private:
161 Point m_origin ;
162 GrafPtr m_formerPort ;
163 GrafPtr m_currentPort ;
164 PenState m_savedPenState ;
165 bool m_ok ;
166 } ;
167 */
168
169 // app.h
170 bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec) ;
171
172 #endif // wxUSE_GUI
173
174 // filefn.h
175 WXDLLEXPORT wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) ;
176 WXDLLEXPORT void wxMacFilename2FSSpec( const wxString &path , FSSpec *spec ) ;
177
178 // utils.h
179 WXDLLEXPORT wxString wxMacFindFolder(short vRefNum,
180 OSType folderType,
181 Boolean createFolder);
182
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 ; }
198 #endif
199 template<> inline EventParamType wxMacGetEventParamType<Collection>() { return typeCollection ; }
200 template<> inline EventParamType wxMacGetEventParamType<CGContextRef>() { return typeCGContextRef ; }
201 /*
202 These are ambiguous
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 ; }
207 */
208
209 class wxMacCarbonEvent
210 {
211
212 public :
213 wxMacCarbonEvent()
214 {
215 m_eventRef = 0 ;
216 m_release = false ;
217 }
218
219 wxMacCarbonEvent( EventRef event , bool release = false )
220 {
221 m_eventRef = event ;
222 m_release = release ;
223 }
224
225 wxMacCarbonEvent(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone)
226 {
227 m_eventRef = NULL ;
228 verify_noerr( MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef) ) ;
229 m_release = true ;
230 }
231
232 ~wxMacCarbonEvent()
233 {
234 if ( m_release )
235 ReleaseEvent( m_eventRef ) ;
236 }
237
238 OSStatus Create(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone)
239 {
240 verify( (m_eventRef == NULL) || m_release ) ;
241 if ( m_eventRef && m_release )
242 {
243 ReleaseEvent( m_eventRef ) ;
244 m_release = false ;
245 m_eventRef = NULL ;
246
247 }
248 OSStatus err = MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef) ;
249 if ( err == noErr )
250 m_release = true ;
251 return err ;
252 }
253
254 OSStatus GetParameter( EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) ;
255
256 template <typename T> OSStatus GetParameter( EventParamName inName, EventParamType type , T *data )
257 {
258 return GetParameter( inName, type , sizeof( T ) , data ) ;
259 }
260 template <typename T> OSStatus GetParameter( EventParamName inName, T *data )
261 {
262 return GetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ;
263 }
264
265 template <typename T> T GetParameter( EventParamName inName )
266 {
267 T value ;
268 verify_noerr( GetParameter<T>( inName, &value ) ) ;
269 return value ;
270 }
271 template <typename T> T GetParameter( EventParamName inName, EventParamType inDesiredType )
272 {
273 T value ;
274 verify_noerr( GetParameter<T>( inName, inDesiredType , &value ) ) ;
275 return value ;
276 }
277
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 )
280 {
281 return SetParameter( inName, inDesiredType , sizeof( T ) , data ) ;
282 }
283 template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T& data )
284 {
285 return SetParameter<T>( inName, inDesiredType , &data ) ;
286 }
287 template <typename T> OSStatus SetParameter( EventParamName inName, const T *data )
288 {
289 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ;
290 }
291 template <typename T> OSStatus SetParameter( EventParamName inName, const T& data )
292 {
293 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , &data ) ;
294 }
295 UInt32 GetClass()
296 {
297 return ::GetEventClass( m_eventRef ) ;
298 }
299 UInt32 GetKind()
300 {
301 return ::GetEventKind( m_eventRef ) ;
302 }
303 EventTime GetTime()
304 {
305 return ::GetEventTime( m_eventRef ) ;
306 }
307 UInt32 GetTicks()
308 {
309 return EventTimeToTicks( GetTime() ) ;
310 }
311 OSStatus SetTime( EventTime inWhen = 0 /*now*/ )
312 {
313 return ::SetEventTime( m_eventRef , inWhen ? inWhen : GetCurrentEventTime() ) ;
314 }
315 operator EventRef () { return m_eventRef; }
316
317 bool IsValid() { return m_eventRef != 0 ; }
318 protected :
319 EventRef m_eventRef ;
320 bool m_release ;
321 } ;
322
323 //
324 // helper class for allocating and deallocating Universal Proc Ptrs
325 //
326
327 template <typename procType, typename uppType , uppType (*newUPP)(procType) , void (*disposeUPP)(uppType) > class wxMacUPP
328 {
329 public :
330 wxMacUPP( procType proc )
331 {
332 m_upp = NULL ;
333 m_upp = (*newUPP)( NULL ) ;
334 }
335 ~wxMacUPP()
336 {
337 if ( m_upp )
338 disposeUPP( m_upp ) ;
339 }
340 operator uppType() { return m_upp ; }
341 private :
342 uppType m_upp ;
343 } ;
344
345 typedef wxMacUPP<NMProcPtr,NMUPP,NewNMUPP,DisposeNMUPP> wxMacNMUPP ;
346
347 #if wxUSE_GUI
348
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 ) ;
356
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)
367
368 struct wxOpaqueWindowRef
369 {
370 wxOpaqueWindowRef( WindowRef ref ) { m_data = ref ; }
371 operator WindowRef() { return m_data ; }
372 private :
373 WindowRef m_data ;
374 } ;
375
376 wxWindow * wxFindControlFromMacControl(ControlRef inControl ) ;
377 wxTopLevelWindowMac* wxFindWinFromMacWindow( WindowRef inWindow ) ;
378 wxMenu* wxFindMenuFromMacMenu(MenuRef inMenuRef) ;
379
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 ) ;
383
384 class wxMacControl
385 {
386 public :
387 wxMacControl()
388 {
389 m_controlRef = NULL ;
390 }
391
392 wxMacControl( ControlRef control )
393 {
394 m_controlRef = control ;
395 }
396 wxMacControl( WXWidget control )
397 {
398 m_controlRef = (ControlRef) control ;
399 }
400 virtual ~wxMacControl()
401 {
402 }
403
404 virtual void Dispose() ;
405
406 bool Ok() const { return GetControlRef() != NULL ; }
407
408 virtual ControlRef * GetControlRefAddr() { return &m_controlRef; }
409 virtual ControlRef GetControlRef() const { return m_controlRef ; }
410
411 virtual void SetReference( SInt32 data ) ;
412 /*
413 void operator= (ControlRef c) { m_controlRef = c ; }
414 operator ControlRef () { return m_controlRef; }
415 operator ControlRef * () { return &m_controlRef; }
416 */
417 // accessing data and values
418
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 ) ;
424
425 virtual OSStatus SendHICommand( UInt32 commandID , OptionBits inOptions = 0 ) ;
426
427 virtual SInt32 GetValue() const ;
428 virtual SInt32 GetMaximum() const ;
429 virtual SInt32 GetMinimum() const ;
430
431 virtual void SetValue( SInt32 v ) ;
432 virtual void SetMinimum( SInt32 v ) ;
433 virtual void SetMaximum( SInt32 v ) ;
434
435 virtual void SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum ) ;
436 virtual void SetRange( SInt32 minimum , SInt32 maximum ) ;
437
438 virtual OSStatus SetFocus( ControlFocusPart focusPart ) ;
439 virtual bool HasFocus() const ;
440 virtual bool NeedsFocusRect() const ;
441
442 // templated helpers
443
444 Size GetDataSize( ControlPartCode inPartCode , ResType inTag ) const
445 {
446 Size sz ;
447 verify_noerr( GetDataSize( inPartCode , inTag , &sz ) ) ;
448 return sz ;
449 }
450 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T *data )
451 {
452 return SetData( inPartCode , inTag , sizeof( T ) , data ) ;
453 }
454 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T& data )
455 {
456 return SetData( inPartCode , inTag , sizeof( T ) , &data ) ;
457 }
458 template <typename T> OSStatus GetData( ControlPartCode inPartCode , ResType inTag , T *data ) const
459 {
460 Size dummy ;
461 return GetData( inPartCode , inTag , sizeof( T ) , data , &dummy ) ;
462 }
463 template <typename T> T GetData( ControlPartCode inPartCode , ResType inTag ) const
464 {
465 T value ;
466 verify_noerr( GetData<T>( inPartCode , inTag , &value ) ) ;
467 return value ;
468 }
469
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 ;
479
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 ) ;
485
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 ) ;
491
492 virtual void ScrollRect( const wxRect &rect , int dx , int dy ) ;
493
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 ) ;
501
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
506
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 ) ;
533
534 // to be moved into a tab control class
535
536 virtual OSStatus SetTabEnabled( SInt16 tabNo , bool enable ) ;
537 protected :
538 ControlRef m_controlRef ;
539 wxFont m_font ;
540 long m_windowStyle ;
541 } ;
542
543 #endif // wxUSE_GUI
544
545 //---------------------------------------------------------------------------
546 // wxMac string conversions
547 //---------------------------------------------------------------------------
548
549 void wxMacSetupConverters() ;
550 void wxMacCleanupConverters() ;
551
552 void wxMacStringToPascal( const wxString&from , StringPtr to ) ;
553 wxString wxMacMakeStringFromPascal( ConstStringPtr from ) ;
554
555 // toplevel.cpp
556
557 ControlRef wxMacFindControlUnderMouse( Point location , WindowRef window , ControlPartCode *outPart ) ;
558
559 // filefn.cpp
560
561 wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL ) ;
562 OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef ) ;
563 wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname ) ;
564
565 #endif
566 // _WX_PRIVATE_H_