]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/private.h
Add constructor and Set taking NSColor.
[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 #endif
32
33 #if UNIVERSAL_INTERFACES_VERSION < 0x0340
34 #error "please update to Apple's lastest universal headers from http://developer.apple.com/sdk/"
35 #endif
36
37 #ifndef MAC_OS_X_VERSION_10_3
38 #define MAC_OS_X_VERSION_10_3 1030
39 #endif
40
41 #ifdef __WXMAC_CARBON__
42 #include "wx/mac/corefoundation/cfstring.h"
43 #endif
44
45 #if wxUSE_GUI
46
47 #include "wx/window.h"
48
49 class wxMacPortStateHelper
50 {
51 DECLARE_NO_COPY_CLASS(wxMacPortStateHelper)
52
53 public:
54 wxMacPortStateHelper( GrafPtr newport) ;
55 wxMacPortStateHelper() ;
56 ~wxMacPortStateHelper() ;
57
58 void Setup( GrafPtr newport ) ;
59 void Clear() ;
60 bool IsCleared() { return m_clip == NULL ; }
61 GrafPtr GetCurrentPort() { return m_currentPort ; }
62
63 private:
64 GrafPtr m_currentPort ;
65 GrafPtr m_oldPort ;
66 RgnHandle m_clip ;
67 ThemeDrawingState m_drawingState ;
68 short m_textFont ;
69 short m_textSize ;
70 short m_textStyle ;
71 short m_textMode ;
72 } ;
73
74 class WXDLLEXPORT wxMacPortSaver
75 {
76 DECLARE_NO_COPY_CLASS(wxMacPortSaver)
77
78 public:
79 wxMacPortSaver( GrafPtr port )
80 {
81 ::GetPort( &m_port ) ;
82 ::SetPort( port ) ;
83 }
84 ~wxMacPortSaver()
85 {
86 ::SetPort( m_port ) ;
87 }
88 private :
89 GrafPtr m_port ;
90 } ;
91
92 class WXDLLEXPORT wxMacPortSetter
93 {
94 DECLARE_NO_COPY_CLASS(wxMacPortSetter)
95
96 public:
97 wxMacPortSetter( const wxDC* dc ) ;
98 ~wxMacPortSetter() ;
99 private:
100 wxMacPortStateHelper m_ph ;
101 const wxDC* m_dc ;
102 } ;
103
104 /*
105 Clips to the visible region of a control within the current port
106 */
107
108 class WXDLLEXPORT wxMacWindowClipper : public wxMacPortSaver
109 {
110 DECLARE_NO_COPY_CLASS(wxMacWindowClipper)
111
112 public:
113 wxMacWindowClipper( const wxWindow* win ) ;
114 ~wxMacWindowClipper() ;
115 private:
116 GrafPtr m_newPort ;
117 RgnHandle m_formerClip ;
118 RgnHandle m_newClip ;
119 } ;
120
121 class WXDLLEXPORT wxMacWindowStateSaver : public wxMacWindowClipper
122 {
123 DECLARE_NO_COPY_CLASS(wxMacWindowStateSaver)
124
125 public:
126 wxMacWindowStateSaver( const wxWindow* win ) ;
127 ~wxMacWindowStateSaver() ;
128 private:
129 GrafPtr m_newPort ;
130 ThemeDrawingState m_themeDrawingState ;
131 } ;
132
133 /*
134 class wxMacDrawingHelper
135 {
136 DECLARE_NO_COPY_CLASS(wxMacDrawingHelper)
137
138 public:
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 ; }
146 private:
147 Point m_origin ;
148 GrafPtr m_formerPort ;
149 GrafPtr m_currentPort ;
150 PenState m_savedPenState ;
151 bool m_ok ;
152 } ;
153 */
154
155 // app.h
156 bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec) ;
157
158 #endif // wxUSE_GUI
159
160 // filefn.h
161 WXDLLEXPORT wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) ;
162 WXDLLEXPORT void wxMacFilename2FSSpec( const wxString &path , FSSpec *spec ) ;
163
164 // utils.h
165 WXDLLEXPORT wxString wxMacFindFolder(short vRefNum,
166 OSType folderType,
167 Boolean createFolder);
168
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 ; }
184 #endif
185 template<> inline EventParamType wxMacGetEventParamType<Collection>() { return typeCollection ; }
186 template<> inline EventParamType wxMacGetEventParamType<CGContextRef>() { return typeCGContextRef ; }
187 /*
188 These are ambiguous
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 ; }
193 */
194
195 class wxMacCarbonEvent
196 {
197
198 public :
199 wxMacCarbonEvent()
200 {
201 m_eventRef = 0 ;
202 m_release = false ;
203 }
204
205 wxMacCarbonEvent( EventRef event , bool release = false )
206 {
207 m_eventRef = event ;
208 m_release = release ;
209 }
210
211 wxMacCarbonEvent(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone)
212 {
213 m_eventRef = NULL ;
214 verify_noerr( MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef) ) ;
215 m_release = true ;
216 }
217
218 ~wxMacCarbonEvent()
219 {
220 if ( m_release )
221 ReleaseEvent( m_eventRef ) ;
222 }
223
224 OSStatus Create(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone)
225 {
226 verify( (m_eventRef == NULL) || m_release ) ;
227 if ( m_eventRef && m_release )
228 {
229 ReleaseEvent( m_eventRef ) ;
230 m_release = false ;
231 m_eventRef = NULL ;
232
233 }
234 OSStatus err = MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef) ;
235 if ( err == noErr )
236 m_release = true ;
237 return err ;
238 }
239
240 OSStatus GetParameter( EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) ;
241
242 template <typename T> OSStatus GetParameter( EventParamName inName, EventParamType type , T *data )
243 {
244 return GetParameter( inName, type , sizeof( T ) , data ) ;
245 }
246 template <typename T> OSStatus GetParameter( EventParamName inName, T *data )
247 {
248 return GetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ;
249 }
250
251 template <typename T> T GetParameter( EventParamName inName )
252 {
253 T value ;
254 verify_noerr( GetParameter<T>( inName, &value ) ) ;
255 return value ;
256 }
257 template <typename T> T GetParameter( EventParamName inName, EventParamType inDesiredType )
258 {
259 T value ;
260 verify_noerr( GetParameter<T>( inName, inDesiredType , &value ) ) ;
261 return value ;
262 }
263
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 )
266 {
267 return SetParameter( inName, inDesiredType , sizeof( T ) , data ) ;
268 }
269 template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T& data )
270 {
271 return SetParameter<T>( inName, inDesiredType , &data ) ;
272 }
273 template <typename T> OSStatus SetParameter( EventParamName inName, const T *data )
274 {
275 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ;
276 }
277 template <typename T> OSStatus SetParameter( EventParamName inName, const T& data )
278 {
279 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , &data ) ;
280 }
281 UInt32 GetClass()
282 {
283 return ::GetEventClass( m_eventRef ) ;
284 }
285 UInt32 GetKind()
286 {
287 return ::GetEventKind( m_eventRef ) ;
288 }
289 EventTime GetTime()
290 {
291 return ::GetEventTime( m_eventRef ) ;
292 }
293 UInt32 GetTicks()
294 {
295 return EventTimeToTicks( GetTime() ) ;
296 }
297 OSStatus SetTime( EventTime inWhen = 0 /*now*/ )
298 {
299 return ::SetEventTime( m_eventRef , inWhen ? inWhen : GetCurrentEventTime() ) ;
300 }
301 operator EventRef () { return m_eventRef; }
302
303 bool IsValid() { return m_eventRef != 0 ; }
304 protected :
305 EventRef m_eventRef ;
306 bool m_release ;
307 } ;
308
309 //
310 // helper class for allocating and deallocating Universal Proc Ptrs
311 //
312
313 template <typename procType, typename uppType , uppType (*newUPP)(procType) , void (*disposeUPP)(uppType) > class wxMacUPP
314 {
315 public :
316 wxMacUPP( procType proc )
317 {
318 m_upp = NULL ;
319 m_upp = (*newUPP)( NULL ) ;
320 }
321 ~wxMacUPP()
322 {
323 if ( m_upp )
324 disposeUPP( m_upp ) ;
325 }
326 operator uppType() { return m_upp ; }
327 private :
328 uppType m_upp ;
329 } ;
330
331 typedef wxMacUPP<NMProcPtr,NMUPP,NewNMUPP,DisposeNMUPP> wxMacNMUPP ;
332
333 #if wxUSE_GUI
334
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 ) ;
342
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)
353
354 struct wxOpaqueWindowRef
355 {
356 wxOpaqueWindowRef( WindowRef ref ) { m_data = ref ; }
357 operator WindowRef() { return m_data ; }
358 private :
359 WindowRef m_data ;
360 } ;
361
362 wxWindow * wxFindControlFromMacControl(ControlRef inControl ) ;
363 wxTopLevelWindowMac* wxFindWinFromMacWindow( WindowRef inWindow ) ;
364 wxMenu* wxFindMenuFromMacMenu(MenuRef inMenuRef) ;
365
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 ) ;
369
370 class wxMacControl
371 {
372 public :
373 wxMacControl()
374 {
375 m_controlRef = NULL ;
376 }
377
378 wxMacControl( ControlRef control )
379 {
380 m_controlRef = control ;
381 }
382 wxMacControl( WXWidget control )
383 {
384 m_controlRef = (ControlRef) control ;
385 }
386 virtual ~wxMacControl()
387 {
388 }
389
390 virtual void Dispose() ;
391
392 bool Ok() const { return GetControlRef() != NULL ; }
393
394 virtual ControlRef * GetControlRefAddr() { return &m_controlRef; }
395 virtual ControlRef GetControlRef() const { return m_controlRef ; }
396
397 virtual void SetReference( SInt32 data ) ;
398 /*
399 void operator= (ControlRef c) { m_controlRef = c ; }
400 operator ControlRef () { return m_controlRef; }
401 operator ControlRef * () { return &m_controlRef; }
402 */
403 // accessing data and values
404
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 ) ;
410
411 virtual OSStatus SendHICommand( UInt32 commandID , OptionBits inOptions = 0 ) ;
412
413 virtual SInt32 GetValue() const ;
414 virtual SInt32 GetMaximum() const ;
415 virtual SInt32 GetMinimum() const ;
416
417 virtual void SetValue( SInt32 v ) ;
418 virtual void SetMinimum( SInt32 v ) ;
419 virtual void SetMaximum( SInt32 v ) ;
420
421 virtual void SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum ) ;
422 virtual void SetRange( SInt32 minimum , SInt32 maximum ) ;
423
424 virtual OSStatus SetFocus( ControlFocusPart focusPart ) ;
425 virtual bool HasFocus() const ;
426 virtual bool NeedsFocusRect() const ;
427
428 // templated helpers
429
430 Size GetDataSize( ControlPartCode inPartCode , ResType inTag ) const
431 {
432 Size sz ;
433 verify_noerr( GetDataSize( inPartCode , inTag , &sz ) ) ;
434 return sz ;
435 }
436 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T *data )
437 {
438 return SetData( inPartCode , inTag , sizeof( T ) , data ) ;
439 }
440 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T& data )
441 {
442 return SetData( inPartCode , inTag , sizeof( T ) , &data ) ;
443 }
444 template <typename T> OSStatus GetData( ControlPartCode inPartCode , ResType inTag , T *data ) const
445 {
446 Size dummy ;
447 return GetData( inPartCode , inTag , sizeof( T ) , data , &dummy ) ;
448 }
449 template <typename T> T GetData( ControlPartCode inPartCode , ResType inTag ) const
450 {
451 T value ;
452 verify_noerr( GetData<T>( inPartCode , inTag , &value ) ) ;
453 return value ;
454 }
455
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 ;
465
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 ) ;
471
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 ) ;
477
478 virtual void ScrollRect( const wxRect &rect , int dx , int dy ) ;
479
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 ) ;
487
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
492
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 ) ;
519
520 // to be moved into a tab control class
521
522 virtual OSStatus SetTabEnabled( SInt16 tabNo , bool enable ) ;
523 protected :
524 ControlRef m_controlRef ;
525 wxFont m_font ;
526 long m_windowStyle ;
527 } ;
528
529 #endif // wxUSE_GUI
530
531 //---------------------------------------------------------------------------
532 // wxMac string conversions
533 //---------------------------------------------------------------------------
534
535 void wxMacSetupConverters() ;
536 void wxMacCleanupConverters() ;
537
538 void wxMacStringToPascal( const wxString&from , StringPtr to ) ;
539 wxString wxMacMakeStringFromPascal( ConstStringPtr from ) ;
540
541 // toplevel.cpp
542
543 ControlRef wxMacFindControlUnderMouse( Point location , WindowRef window , ControlPartCode *outPart ) ;
544
545 // filefn.cpp
546
547 wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL ) ;
548 OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef ) ;
549 wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname ) ;
550
551 #endif
552 // _WX_PRIVATE_H_