]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/private.h
cocoa doesn't need system framework - string conversion for cocoa - focus for cocoa...
[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 #if wxUSE_GUI
42
43 #include "wx/window.h"
44
45 class wxMacPortStateHelper
46 {
47 DECLARE_NO_COPY_CLASS(wxMacPortStateHelper)
48
49 public:
50 wxMacPortStateHelper( GrafPtr newport) ;
51 wxMacPortStateHelper() ;
52 ~wxMacPortStateHelper() ;
53
54 void Setup( GrafPtr newport ) ;
55 void Clear() ;
56 bool IsCleared() { return m_clip == NULL ; }
57 GrafPtr GetCurrentPort() { return m_currentPort ; }
58
59 private:
60 GrafPtr m_currentPort ;
61 GrafPtr m_oldPort ;
62 RgnHandle m_clip ;
63 ThemeDrawingState m_drawingState ;
64 short m_textFont ;
65 short m_textSize ;
66 short m_textStyle ;
67 short m_textMode ;
68 } ;
69
70 class WXDLLEXPORT wxMacPortSaver
71 {
72 DECLARE_NO_COPY_CLASS(wxMacPortSaver)
73
74 public:
75 wxMacPortSaver( GrafPtr port )
76 {
77 ::GetPort( &m_port ) ;
78 ::SetPort( port ) ;
79 }
80 ~wxMacPortSaver()
81 {
82 ::SetPort( m_port ) ;
83 }
84 private :
85 GrafPtr m_port ;
86 } ;
87
88 class WXDLLEXPORT wxMacPortSetter
89 {
90 DECLARE_NO_COPY_CLASS(wxMacPortSetter)
91
92 public:
93 wxMacPortSetter( const wxDC* dc ) ;
94 ~wxMacPortSetter() ;
95 private:
96 wxMacPortStateHelper m_ph ;
97 const wxDC* m_dc ;
98 } ;
99
100 /*
101 Clips to the visible region of a control within the current port
102 */
103
104 class WXDLLEXPORT wxMacWindowClipper : public wxMacPortSaver
105 {
106 DECLARE_NO_COPY_CLASS(wxMacWindowClipper)
107
108 public:
109 wxMacWindowClipper( const wxWindow* win ) ;
110 ~wxMacWindowClipper() ;
111 private:
112 GrafPtr m_newPort ;
113 RgnHandle m_formerClip ;
114 RgnHandle m_newClip ;
115 } ;
116
117 class WXDLLEXPORT wxMacWindowStateSaver : public wxMacWindowClipper
118 {
119 DECLARE_NO_COPY_CLASS(wxMacWindowStateSaver)
120
121 public:
122 wxMacWindowStateSaver( const wxWindow* win ) ;
123 ~wxMacWindowStateSaver() ;
124 private:
125 GrafPtr m_newPort ;
126 ThemeDrawingState m_themeDrawingState ;
127 } ;
128
129 /*
130 class wxMacDrawingHelper
131 {
132 DECLARE_NO_COPY_CLASS(wxMacDrawingHelper)
133
134 public:
135 wxMacDrawingHelper( wxWindowMac * theWindow , bool clientArea = false ) ;
136 ~wxMacDrawingHelper() ;
137 bool Ok() { return m_ok ; }
138 void LocalToWindow( Rect *rect) { OffsetRect( rect , m_origin.h , m_origin.v ) ; }
139 void LocalToWindow( Point *pt ) { AddPt( m_origin , pt ) ; }
140 void LocalToWindow( RgnHandle rgn ) { OffsetRgn( rgn , m_origin.h , m_origin.v ) ; }
141 const Point& GetOrigin() { return m_origin ; }
142 private:
143 Point m_origin ;
144 GrafPtr m_formerPort ;
145 GrafPtr m_currentPort ;
146 PenState m_savedPenState ;
147 bool m_ok ;
148 } ;
149 */
150
151 // app.h
152 bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec) ;
153
154 #endif // wxUSE_GUI
155
156 // filefn.h
157 WXDLLEXPORT wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) ;
158 WXDLLEXPORT void wxMacFilename2FSSpec( const wxString &path , FSSpec *spec ) ;
159
160 // utils.h
161 WXDLLEXPORT wxString wxMacFindFolder(short vRefNum,
162 OSType folderType,
163 Boolean createFolder);
164
165 #if wxUSE_GUI
166
167 GWorldPtr wxMacCreateGWorld( int width , int height , int depth ) ;
168 void wxMacDestroyGWorld( GWorldPtr gw ) ;
169 PicHandle wxMacCreatePict( GWorldPtr gw , GWorldPtr mask = NULL ) ;
170 CIconHandle wxMacCreateCIcon(GWorldPtr image , GWorldPtr mask , short dstDepth , short iconSize ) ;
171 void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue ) ;
172 CTabHandle wxMacCreateColorTable( int numColors ) ;
173 void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType = 0 ) ;
174
175 #define MAC_WXCOLORREF(a) (*((RGBColor*)&(a)))
176 #define MAC_WXHBITMAP(a) (GWorldPtr(a))
177 #define MAC_WXHMETAFILE(a) (PicHandle(a))
178 #define MAC_WXHICON(a) (CIconHandle(a))
179 #define MAC_WXHCURSOR(a) (CursHandle(a))
180 #define MAC_WXHRGN(a) (RgnHandle(a))
181 #define MAC_WXHWND(a) (WindowPtr(a))
182 #define MAC_WXRECPTR(a) ((Rect*)a)
183 #define MAC_WXPOINTPTR(a) ((Point*)a)
184 #define MAC_WXHMENU(a) ((MenuHandle)a)
185
186 struct wxOpaqueWindowRef
187 {
188 wxOpaqueWindowRef( WindowRef ref ) { m_data = ref ; }
189 operator WindowRef() { return m_data ; }
190 private :
191 WindowRef m_data ;
192 } ;
193
194 wxWindow * wxFindControlFromMacControl(ControlRef inControl ) ;
195 wxTopLevelWindowMac* wxFindWinFromMacWindow( WindowRef inWindow ) ;
196 wxMenu* wxFindMenuFromMacMenu(MenuRef inMenuRef) ;
197
198 extern wxWindow* g_MacLastWindow ;
199 pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ;
200 Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin = true ) ;
201
202 template<typename T> EventParamType wxMacGetEventParamType() { wxFAIL_MSG( wxT("Unknown Param Type") ) ; return 0 ; }
203 template<> inline EventParamType wxMacGetEventParamType<RgnHandle>() { return typeQDRgnHandle ; }
204 template<> inline EventParamType wxMacGetEventParamType<ControlRef>() { return typeControlRef ; }
205 template<> inline EventParamType wxMacGetEventParamType<WindowRef>() { return typeWindowRef ; }
206 template<> inline EventParamType wxMacGetEventParamType<MenuRef>() { return typeMenuRef ; }
207 template<> inline EventParamType wxMacGetEventParamType<EventRef>() { return typeEventRef ; }
208 template<> inline EventParamType wxMacGetEventParamType<Point>() { return typeQDPoint ; }
209 template<> inline EventParamType wxMacGetEventParamType<Rect>() { return typeQDRectangle ; }
210 template<> inline EventParamType wxMacGetEventParamType<Boolean>() { return typeBoolean ; }
211 #if TARGET_API_MAC_OSX
212 template<> inline EventParamType wxMacGetEventParamType<HICommand>() { return typeHICommand ; }
213 template<> inline EventParamType wxMacGetEventParamType<HIPoint>() { return typeHIPoint ; }
214 template<> inline EventParamType wxMacGetEventParamType<HISize>() { return typeHISize ; }
215 template<> inline EventParamType wxMacGetEventParamType<HIRect>() { return typeHIRect ; }
216 template<> inline EventParamType wxMacGetEventParamType<void*>() { return typeVoidPtr ; }
217 #endif
218 template<> inline EventParamType wxMacGetEventParamType<Collection>() { return typeCollection ; }
219 template<> inline EventParamType wxMacGetEventParamType<CGContextRef>() { return typeCGContextRef ; }
220 /*
221 These are ambiguous
222 template<> EventParamType wxMacGetEventParamType<GrafPtr>() { return typeGrafPtr ; }
223 template<> EventParamType wxMacGetEventParamType<OSStatus>() { return typeOSStatus ; }
224 template<> EventParamType wxMacGetEventParamType<CFIndex>() { return typeCFIndex ; }
225 template<> EventParamType wxMacGetEventParamType<GWorldPtr>() { return typeGWorldPtr ; }
226 */
227
228 class wxMacCarbonEvent
229 {
230
231 public :
232 wxMacCarbonEvent( EventRef event , bool release = false )
233 {
234 m_eventRef = event ;
235 m_release = release ;
236 }
237 wxMacCarbonEvent(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone)
238 {
239 m_eventRef = NULL ;
240 verify_noerr( MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef) ) ;
241 m_release = true ;
242 }
243 ~wxMacCarbonEvent()
244 {
245 if ( m_release )
246 ReleaseEvent( m_eventRef ) ;
247 }
248
249 OSStatus GetParameter( EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) ;
250
251 template <typename T> OSStatus GetParameter( EventParamName inName, EventParamType type , T *data )
252 {
253 return GetParameter( inName, type , sizeof( T ) , data ) ;
254 }
255 template <typename T> OSStatus GetParameter( EventParamName inName, T *data )
256 {
257 return GetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ;
258 }
259
260 template <typename T> T GetParameter( EventParamName inName )
261 {
262 T value ;
263 verify_noerr( GetParameter<T>( inName, &value ) ) ;
264 return value ;
265 }
266 template <typename T> T GetParameter( EventParamName inName, EventParamType inDesiredType )
267 {
268 T value ;
269 verify_noerr( GetParameter<T>( inName, inDesiredType , &value ) ) ;
270 return value ;
271 }
272
273 OSStatus SetParameter( EventParamName inName, EventParamType inType, UInt32 inSize, const void * inData) ;
274 template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T *data )
275 {
276 return SetParameter( inName, inDesiredType , sizeof( T ) , data ) ;
277 }
278 template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T& data )
279 {
280 return SetParameter<T>( inName, inDesiredType , &data ) ;
281 }
282 template <typename T> OSStatus SetParameter( EventParamName inName, const T *data )
283 {
284 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ;
285 }
286 template <typename T> OSStatus SetParameter( EventParamName inName, const T& data )
287 {
288 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , &data ) ;
289 }
290 UInt32 GetClass()
291 {
292 return ::GetEventClass( m_eventRef ) ;
293 }
294 UInt32 GetKind()
295 {
296 return ::GetEventKind( m_eventRef ) ;
297 }
298 EventTime GetTime()
299 {
300 return ::GetEventTime( m_eventRef ) ;
301 }
302 UInt32 GetTicks()
303 {
304 return EventTimeToTicks( GetTime() ) ;
305 }
306 operator EventRef () { return m_eventRef; }
307 protected :
308 EventRef m_eventRef ;
309 bool m_release ;
310 } ;
311
312 class wxMacControl
313 {
314 public :
315 wxMacControl()
316 {
317 m_controlRef = NULL ;
318 }
319
320 wxMacControl( ControlRef control )
321 {
322 m_controlRef = control ;
323 }
324 wxMacControl( WXWidget control )
325 {
326 m_controlRef = (ControlRef) control ;
327 }
328 virtual ~wxMacControl()
329 {
330 }
331
332 virtual void Dispose() ;
333
334 bool Ok() const { return GetControlRef() != NULL ; }
335
336 virtual ControlRef * GetControlRefAddr() { return &m_controlRef; }
337 virtual ControlRef GetControlRef() const { return m_controlRef ; }
338
339 virtual void SetReference( SInt32 data ) ;
340 /*
341 void operator= (ControlRef c) { m_controlRef = c ; }
342 operator ControlRef () { return m_controlRef; }
343 operator ControlRef * () { return &m_controlRef; }
344 */
345 // accessing data and values
346
347 virtual OSStatus SetData( ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData ) ;
348 virtual OSStatus GetData( ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const ;
349 virtual OSStatus GetDataSize( ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const ;
350 virtual OSStatus SendEvent( EventRef ref , OptionBits inOptions = 0 ) ;
351 virtual OSStatus SendHICommand( HICommand &command , OptionBits inOptions = 0 ) ;
352
353 virtual OSStatus SendHICommand( UInt32 commandID , OptionBits inOptions = 0 ) ;
354
355 virtual SInt32 GetValue() const ;
356 virtual SInt32 GetMaximum() const ;
357 virtual SInt32 GetMinimum() const ;
358
359 virtual void SetValue( SInt32 v ) ;
360 virtual void SetMinimum( SInt32 v ) ;
361 virtual void SetMaximum( SInt32 v ) ;
362
363 virtual void SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum ) ;
364 virtual void SetRange( SInt32 minimum , SInt32 maximum ) ;
365
366 virtual OSStatus SetFocus( ControlFocusPart focusPart ) ;
367 virtual bool HasFocus() const ;
368 virtual bool NeedsFocusRect() const ;
369
370 // templated helpers
371
372 Size GetDataSize( ControlPartCode inPartCode , ResType inTag ) const
373 {
374 Size sz ;
375 verify_noerr( GetDataSize( inPartCode , inTag , &sz ) ) ;
376 return sz ;
377 }
378 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T *data )
379 {
380 return SetData( inPartCode , inTag , sizeof( T ) , data ) ;
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 GetData( ControlPartCode inPartCode , ResType inTag , T *data ) const
387 {
388 Size dummy ;
389 return GetData( inPartCode , inTag , sizeof( T ) , data , &dummy ) ;
390 }
391 template <typename T> T GetData( ControlPartCode inPartCode , ResType inTag ) const
392 {
393 T value ;
394 verify_noerr( GetData<T>( inPartCode , inTag , &value ) ) ;
395 return value ;
396 }
397
398 // Flash the control for the specified amount of time
399 virtual void Flash( ControlPartCode part , UInt32 ticks = 8 ) ;
400 virtual void VisibilityChanged( bool shown ) ;
401 virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) ;
402 virtual void SetBackground( const wxBrush &brush ) ;
403 virtual ControlPartCode HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers ) ;
404 void SetActionProc( ControlActionUPP actionProc ) ;
405 void SetViewSize( SInt32 viewSize ) ;
406 SInt32 GetViewSize() const ;
407
408 virtual bool IsVisible() const ;
409 virtual void SetVisibility( bool visible , bool redraw ) ;
410 virtual bool IsEnabled() const ;
411 virtual bool IsActive() const ;
412 virtual void Enable( bool enable ) ;
413
414 // invalidates this control and all children
415 virtual void InvalidateWithChildren() ;
416 virtual void SetDrawingEnabled( bool enable ) ;
417 virtual bool GetNeedsDisplay() const ;
418 virtual void SetNeedsDisplay( bool needsDisplay , RgnHandle where = NULL ) ;
419
420 virtual void ScrollRect( const wxRect &rect , int dx , int dy ) ;
421
422 virtual void GetRect( Rect *r ) ;
423 virtual void SetRect( Rect *r ) ;
424 virtual void GetRectInWindowCoords( Rect *r ) ;
425 virtual void GetBestRect( Rect *r ) ;
426 virtual void SetTitle( const wxString &title ) ;
427 // converts from Toplevel-Content relative to local
428 static void Convert( wxPoint *pt , wxMacControl *convert , wxMacControl *to ) ;
429
430 virtual void GetFeatures( UInt32 *features ) ;
431 virtual OSStatus GetRegion( ControlPartCode partCode , RgnHandle region ) ;
432 virtual OSStatus SetZOrder( bool above , wxMacControl* other ) ;
433 // to be moved into a databrowser subclass
434
435 virtual OSStatus SetSelectionFlags( DataBrowserSelectionFlags ) ;
436 virtual OSStatus AddListViewColumn( DataBrowserListViewColumnDesc *columnDesc,
437 DataBrowserTableViewColumnIndex position ) ;
438 virtual OSStatus AutoSizeListViewColumns() ;
439 virtual OSStatus SetHasScrollBars( bool horiz , bool vert ) ;
440 virtual OSStatus SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle ) ;
441 virtual OSStatus SetListViewHeaderBtnHeight(UInt16 height) ;
442 virtual OSStatus SetCallbacks(const DataBrowserCallbacks * callbacks) ;
443 virtual OSStatus UpdateItems( DataBrowserItemID container, UInt32 numItems,
444 const DataBrowserItemID* items,
445 DataBrowserPropertyID preSortProperty,
446 DataBrowserPropertyID propertyID ) ;
447 virtual OSStatus AddItems( DataBrowserItemID container, UInt32 numItems,
448 const DataBrowserItemID* items,
449 DataBrowserPropertyID preSortProperty ) ;
450 virtual OSStatus RemoveItems( DataBrowserItemID container, UInt32 numItems,
451 const DataBrowserItemID* items,
452 DataBrowserPropertyID preSortProperty ) ;
453 virtual OSStatus RevealItem( DataBrowserItemID item,
454 DataBrowserPropertyID propertyID,
455 DataBrowserRevealOptions options ) ;
456 virtual bool IsItemSelected( DataBrowserItemID item ) ;
457 virtual OSStatus SetSelectedItems(UInt32 numItems,
458 const DataBrowserItemID * items,
459 DataBrowserSetOption operation ) ;
460
461 // to be moved into a tab control class
462
463 virtual OSStatus SetTabEnabled( SInt16 tabNo , bool enable ) ;
464 protected :
465 ControlRef m_controlRef ;
466 wxFont m_font ;
467 long m_windowStyle ;
468 } ;
469
470 #endif // wxUSE_GUI
471
472 //---------------------------------------------------------------------------
473 // wxMac string conversions
474 //---------------------------------------------------------------------------
475
476 void wxMacSetupConverters() ;
477 void wxMacCleanupConverters() ;
478
479 void wxMacStringToPascal( const wxString&from , StringPtr to ) ;
480 wxString wxMacMakeStringFromPascal( ConstStringPtr from ) ;
481
482 void wxMacConvertNewlines13To10( char * data ) ;
483 void wxMacConvertNewlines10To13( char * data ) ;
484 void wxMacConvertNewlines13To10( wxString *data ) ;
485 void wxMacConvertNewlines10To13( wxString *data ) ;
486
487 #if wxUSE_UNICODE
488 void wxMacConvertNewlines13To10( wxChar * data ) ;
489 void wxMacConvertNewlines10To13( wxChar * data ) ;
490 #endif
491
492 #if TARGET_CARBON
493
494 class wxMacCFStringHolder
495 {
496 public:
497 wxMacCFStringHolder()
498 {
499 m_cfs = NULL ;
500 m_release = false ;
501 }
502
503 wxMacCFStringHolder(const wxString &str , wxFontEncoding encoding )
504 {
505 m_cfs = NULL ;
506 m_release = false ;
507 Assign( str , encoding ) ;
508 }
509
510 wxMacCFStringHolder(CFStringRef ref , bool release = true )
511 {
512 m_cfs = ref ;
513 m_release = release ;
514 }
515
516 ~wxMacCFStringHolder()
517 {
518 Release() ;
519 }
520
521 CFStringRef Detach()
522 {
523 CFStringRef retval = m_cfs ;
524 m_release = false ;
525 m_cfs = NULL ;
526 return retval ;
527 }
528
529 void Release()
530 {
531 if ( m_release && m_cfs)
532 CFRelease( m_cfs ) ;
533 m_cfs = NULL ;
534 }
535
536 void Assign( const wxString &str , wxFontEncoding encoding ) ;
537
538 operator CFStringRef () { return m_cfs; }
539 wxString AsString( wxFontEncoding encoding = wxFONTENCODING_DEFAULT ) ;
540
541 private:
542
543 CFStringRef m_cfs;
544 bool m_release ;
545 } ;
546
547 #endif
548
549 // utils.cpp
550
551 wxUint32 wxMacGetSystemEncFromFontEnc(wxFontEncoding encoding) ;
552 wxFontEncoding wxMacGetFontEncFromSystemEnc(wxUint32 encoding) ;
553 void wxMacWakeUp() ;
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_