]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/private.h
Moved wxCFStringHolder and some other string functions to their own files.
[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 #if wxUSE_GUI
170
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 ) ;
178
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)
189
190 struct wxOpaqueWindowRef
191 {
192 wxOpaqueWindowRef( WindowRef ref ) { m_data = ref ; }
193 operator WindowRef() { return m_data ; }
194 private :
195 WindowRef m_data ;
196 } ;
197
198 wxWindow * wxFindControlFromMacControl(ControlRef inControl ) ;
199 wxTopLevelWindowMac* wxFindWinFromMacWindow( WindowRef inWindow ) ;
200 wxMenu* wxFindMenuFromMacMenu(MenuRef inMenuRef) ;
201
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 ) ;
205
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 ; }
221 #endif
222 template<> inline EventParamType wxMacGetEventParamType<Collection>() { return typeCollection ; }
223 template<> inline EventParamType wxMacGetEventParamType<CGContextRef>() { return typeCGContextRef ; }
224 /*
225 These are ambiguous
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 ; }
230 */
231
232 class wxMacCarbonEvent
233 {
234
235 public :
236 wxMacCarbonEvent( EventRef event , bool release = false )
237 {
238 m_eventRef = event ;
239 m_release = release ;
240 }
241 wxMacCarbonEvent(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone)
242 {
243 m_eventRef = NULL ;
244 verify_noerr( MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef) ) ;
245 m_release = true ;
246 }
247 ~wxMacCarbonEvent()
248 {
249 if ( m_release )
250 ReleaseEvent( m_eventRef ) ;
251 }
252
253 OSStatus GetParameter( EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) ;
254
255 template <typename T> OSStatus GetParameter( EventParamName inName, EventParamType type , T *data )
256 {
257 return GetParameter( inName, type , sizeof( T ) , data ) ;
258 }
259 template <typename T> OSStatus GetParameter( EventParamName inName, T *data )
260 {
261 return GetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ;
262 }
263
264 template <typename T> T GetParameter( EventParamName inName )
265 {
266 T value ;
267 verify_noerr( GetParameter<T>( inName, &value ) ) ;
268 return value ;
269 }
270 template <typename T> T GetParameter( EventParamName inName, EventParamType inDesiredType )
271 {
272 T value ;
273 verify_noerr( GetParameter<T>( inName, inDesiredType , &value ) ) ;
274 return value ;
275 }
276
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 )
279 {
280 return SetParameter( inName, inDesiredType , sizeof( T ) , data ) ;
281 }
282 template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T& data )
283 {
284 return SetParameter<T>( inName, inDesiredType , &data ) ;
285 }
286 template <typename T> OSStatus SetParameter( EventParamName inName, const T *data )
287 {
288 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ;
289 }
290 template <typename T> OSStatus SetParameter( EventParamName inName, const T& data )
291 {
292 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , &data ) ;
293 }
294 UInt32 GetClass()
295 {
296 return ::GetEventClass( m_eventRef ) ;
297 }
298 UInt32 GetKind()
299 {
300 return ::GetEventKind( m_eventRef ) ;
301 }
302 EventTime GetTime()
303 {
304 return ::GetEventTime( m_eventRef ) ;
305 }
306 UInt32 GetTicks()
307 {
308 return EventTimeToTicks( GetTime() ) ;
309 }
310 operator EventRef () { return m_eventRef; }
311 protected :
312 EventRef m_eventRef ;
313 bool m_release ;
314 } ;
315
316 class wxMacControl
317 {
318 public :
319 wxMacControl()
320 {
321 m_controlRef = NULL ;
322 }
323
324 wxMacControl( ControlRef control )
325 {
326 m_controlRef = control ;
327 }
328 wxMacControl( WXWidget control )
329 {
330 m_controlRef = (ControlRef) control ;
331 }
332 virtual ~wxMacControl()
333 {
334 }
335
336 virtual void Dispose() ;
337
338 bool Ok() const { return GetControlRef() != NULL ; }
339
340 virtual ControlRef * GetControlRefAddr() { return &m_controlRef; }
341 virtual ControlRef GetControlRef() const { return m_controlRef ; }
342
343 virtual void SetReference( SInt32 data ) ;
344 /*
345 void operator= (ControlRef c) { m_controlRef = c ; }
346 operator ControlRef () { return m_controlRef; }
347 operator ControlRef * () { return &m_controlRef; }
348 */
349 // accessing data and values
350
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 ) ;
356
357 virtual OSStatus SendHICommand( UInt32 commandID , OptionBits inOptions = 0 ) ;
358
359 virtual SInt32 GetValue() const ;
360 virtual SInt32 GetMaximum() const ;
361 virtual SInt32 GetMinimum() const ;
362
363 virtual void SetValue( SInt32 v ) ;
364 virtual void SetMinimum( SInt32 v ) ;
365 virtual void SetMaximum( SInt32 v ) ;
366
367 virtual void SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum ) ;
368 virtual void SetRange( SInt32 minimum , SInt32 maximum ) ;
369
370 virtual OSStatus SetFocus( ControlFocusPart focusPart ) ;
371 virtual bool HasFocus() const ;
372 virtual bool NeedsFocusRect() const ;
373
374 // templated helpers
375
376 Size GetDataSize( ControlPartCode inPartCode , ResType inTag ) const
377 {
378 Size sz ;
379 verify_noerr( GetDataSize( inPartCode , inTag , &sz ) ) ;
380 return sz ;
381 }
382 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T *data )
383 {
384 return SetData( inPartCode , inTag , sizeof( T ) , data ) ;
385 }
386 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T& data )
387 {
388 return SetData( inPartCode , inTag , sizeof( T ) , &data ) ;
389 }
390 template <typename T> OSStatus GetData( ControlPartCode inPartCode , ResType inTag , T *data ) const
391 {
392 Size dummy ;
393 return GetData( inPartCode , inTag , sizeof( T ) , data , &dummy ) ;
394 }
395 template <typename T> T GetData( ControlPartCode inPartCode , ResType inTag ) const
396 {
397 T value ;
398 verify_noerr( GetData<T>( inPartCode , inTag , &value ) ) ;
399 return value ;
400 }
401
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 ;
411
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 ) ;
417
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 ) ;
423
424 virtual void ScrollRect( const wxRect &rect , int dx , int dy ) ;
425
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 ) ;
433
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
438
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 bool IsItemSelected( DataBrowserItemID item ) ;
461 virtual OSStatus SetSelectedItems(UInt32 numItems,
462 const DataBrowserItemID * items,
463 DataBrowserSetOption operation ) ;
464
465 // to be moved into a tab control class
466
467 virtual OSStatus SetTabEnabled( SInt16 tabNo , bool enable ) ;
468 protected :
469 ControlRef m_controlRef ;
470 wxFont m_font ;
471 long m_windowStyle ;
472 } ;
473
474 #endif // wxUSE_GUI
475
476 //---------------------------------------------------------------------------
477 // wxMac string conversions
478 //---------------------------------------------------------------------------
479
480 void wxMacSetupConverters() ;
481 void wxMacCleanupConverters() ;
482
483 void wxMacStringToPascal( const wxString&from , StringPtr to ) ;
484 wxString wxMacMakeStringFromPascal( ConstStringPtr from ) ;
485
486 // toplevel.cpp
487
488 ControlRef wxMacFindControlUnderMouse( Point location , WindowRef window , ControlPartCode *outPart ) ;
489
490 // filefn.cpp
491
492 wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL ) ;
493 OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef ) ;
494 wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname ) ;
495
496 #endif
497 // _WX_PRIVATE_H_