]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/private.h
Give wx.GridTableBase a destructor, and clear the ownership when it is
[wxWidgets.git] / include / wx / mac / carbon / private.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/mac/carbon/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 # include <CoreServices.h>
33 #endif
34
35 #if UNIVERSAL_INTERFACES_VERSION < 0x0342
36 #error "please update to Apple's lastest universal headers from http://developer.apple.com/sdk/"
37 #endif
38
39 #ifndef MAC_OS_X_VERSION_10_3
40 #define MAC_OS_X_VERSION_10_3 1030
41 #endif
42
43 #ifndef MAC_OS_X_VERSION_10_4
44 #define MAC_OS_X_VERSION_10_4 1040
45 #endif
46
47 #ifdef __WXMAC_CARBON__
48 #include "wx/mac/corefoundation/cfstring.h"
49 #endif
50
51 #ifndef FixedToInt
52 // as macro in FixMath.h for 10.3
53 inline Fixed IntToFixed( int inInt )
54 {
55 return (((SInt32) inInt) << 16);
56 }
57
58 inline int FixedToInt( Fixed inFixed )
59 {
60 return (((SInt32) inFixed) >> 16);
61 }
62 #endif
63
64 #if wxUSE_GUI
65
66 #include "wx/dc.h"
67 #include "wx/window.h"
68 #include "wx/toplevel.h"
69
70 class wxMacPortStateHelper
71 {
72 DECLARE_NO_COPY_CLASS(wxMacPortStateHelper)
73
74 public:
75 wxMacPortStateHelper( GrafPtr newport) ;
76 wxMacPortStateHelper() ;
77 ~wxMacPortStateHelper() ;
78
79 void Setup( GrafPtr newport ) ;
80 void Clear() ;
81 bool IsCleared() { return m_clip == NULL ; }
82 GrafPtr GetCurrentPort() { return m_currentPort ; }
83
84 private:
85 GrafPtr m_currentPort ;
86 GrafPtr m_oldPort ;
87 RgnHandle m_clip ;
88 ThemeDrawingState m_drawingState ;
89 short m_textFont ;
90 short m_textSize ;
91 short m_textStyle ;
92 short m_textMode ;
93 } ;
94
95 class WXDLLEXPORT wxMacPortSaver
96 {
97 DECLARE_NO_COPY_CLASS(wxMacPortSaver)
98
99 public:
100 wxMacPortSaver( GrafPtr port );
101 ~wxMacPortSaver();
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 #if wxMAC_USE_CORE_GRAPHICS
148 class WXDLLEXPORT wxMacCGContextStateSaver
149 {
150 DECLARE_NO_COPY_CLASS(wxMacCGContextStateSaver)
151
152 public:
153 wxMacCGContextStateSaver( CGContextRef cg )
154 {
155 m_cg = cg ;
156 CGContextSaveGState( cg ) ;
157 }
158 ~wxMacCGContextStateSaver()
159 {
160 CGContextRestoreGState( m_cg ) ;
161 }
162 private:
163 CGContextRef m_cg ;
164 } ;
165
166 #endif
167 /*
168 class wxMacDrawingHelper
169 {
170 DECLARE_NO_COPY_CLASS(wxMacDrawingHelper)
171
172 public:
173 wxMacDrawingHelper( wxWindowMac * theWindow , bool clientArea = false ) ;
174 ~wxMacDrawingHelper() ;
175 bool Ok() { return m_ok ; }
176 void LocalToWindow( Rect *rect) { OffsetRect( rect , m_origin.h , m_origin.v ) ; }
177 void LocalToWindow( Point *pt ) { AddPt( m_origin , pt ) ; }
178 void LocalToWindow( RgnHandle rgn ) { OffsetRgn( rgn , m_origin.h , m_origin.v ) ; }
179 const Point& GetOrigin() { return m_origin ; }
180 private:
181 Point m_origin ;
182 GrafPtr m_formerPort ;
183 GrafPtr m_currentPort ;
184 PenState m_savedPenState ;
185 bool m_ok ;
186 } ;
187 */
188
189 // app.h
190 bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec) ;
191
192 #endif // wxUSE_GUI
193
194 // filefn.h
195 WXDLLEXPORT wxString wxMacFSSpec2MacFilename( const FSSpec *spec ) ;
196 WXDLLEXPORT void wxMacFilename2FSSpec( const wxString &path , FSSpec *spec ) ;
197
198 // utils.h
199 WXDLLEXPORT wxString wxMacFindFolder(short vRefNum,
200 OSType folderType,
201 Boolean createFolder);
202
203 template<typename T> EventParamType wxMacGetEventParamType() { wxFAIL_MSG( wxT("Unknown Param Type") ) ; return 0 ; }
204 template<> inline EventParamType wxMacGetEventParamType<RgnHandle>() { return typeQDRgnHandle ; }
205 template<> inline EventParamType wxMacGetEventParamType<ControlRef>() { return typeControlRef ; }
206 template<> inline EventParamType wxMacGetEventParamType<WindowRef>() { return typeWindowRef ; }
207 template<> inline EventParamType wxMacGetEventParamType<MenuRef>() { return typeMenuRef ; }
208 template<> inline EventParamType wxMacGetEventParamType<EventRef>() { return typeEventRef ; }
209 template<> inline EventParamType wxMacGetEventParamType<Point>() { return typeQDPoint ; }
210 template<> inline EventParamType wxMacGetEventParamType<Rect>() { return typeQDRectangle ; }
211 template<> inline EventParamType wxMacGetEventParamType<Boolean>() { return typeBoolean ; }
212 template<> inline EventParamType wxMacGetEventParamType<SInt16>() { return typeSInt16 ; }
213 template<> inline EventParamType wxMacGetEventParamType<SInt32>() { return typeSInt32 ; }
214 template<> inline EventParamType wxMacGetEventParamType<UInt32>() { return typeUInt32 ; }
215 template<> inline EventParamType wxMacGetEventParamType<RGBColor>() { return typeRGBColor ; }
216 #if TARGET_API_MAC_OSX
217 template<> inline EventParamType wxMacGetEventParamType<HICommand>() { return typeHICommand ; }
218 template<> inline EventParamType wxMacGetEventParamType<HIPoint>() { return typeHIPoint ; }
219 template<> inline EventParamType wxMacGetEventParamType<HISize>() { return typeHISize ; }
220 template<> inline EventParamType wxMacGetEventParamType<HIRect>() { return typeHIRect ; }
221 template<> inline EventParamType wxMacGetEventParamType<void*>() { return typeVoidPtr ; }
222 #endif
223 #if TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 )
224 template<> inline EventParamType wxMacGetEventParamType<CFDictionaryRef>() { return typeCFDictionaryRef ; }
225 #endif
226 template<> inline EventParamType wxMacGetEventParamType<Collection>() { return typeCollection ; }
227 template<> inline EventParamType wxMacGetEventParamType<CGContextRef>() { return typeCGContextRef ; }
228 /*
229 These are ambiguous
230 template<> EventParamType wxMacGetEventParamType<GrafPtr>() { return typeGrafPtr ; }
231 template<> EventParamType wxMacGetEventParamType<OSStatus>() { return typeOSStatus ; }
232 template<> EventParamType wxMacGetEventParamType<CFIndex>() { return typeCFIndex ; }
233 template<> EventParamType wxMacGetEventParamType<GWorldPtr>() { return typeGWorldPtr ; }
234 */
235
236 class wxMacCarbonEvent
237 {
238
239 public :
240 wxMacCarbonEvent()
241 {
242 m_eventRef = 0 ;
243 m_release = false ;
244 }
245
246 wxMacCarbonEvent( EventRef event , bool release = false )
247 {
248 m_eventRef = event ;
249 m_release = release ;
250 }
251
252 wxMacCarbonEvent(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone)
253 {
254 m_eventRef = NULL ;
255 verify_noerr( MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef) ) ;
256 m_release = true ;
257 }
258
259 ~wxMacCarbonEvent()
260 {
261 if ( m_release )
262 ReleaseEvent( m_eventRef ) ;
263 }
264
265 OSStatus Create(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone)
266 {
267 verify( (m_eventRef == NULL) || m_release ) ;
268 if ( m_eventRef && m_release )
269 {
270 ReleaseEvent( m_eventRef ) ;
271 m_release = false ;
272 m_eventRef = NULL ;
273 }
274 OSStatus err = MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef) ;
275 if ( err == noErr )
276 m_release = true ;
277 return err ;
278 }
279
280 OSStatus GetParameter( EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData) ;
281
282 template <typename T> OSStatus GetParameter( EventParamName inName, EventParamType type , T *data )
283 {
284 return GetParameter( inName, type , sizeof( T ) , data ) ;
285 }
286 template <typename T> OSStatus GetParameter( EventParamName inName, T *data )
287 {
288 return GetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ;
289 }
290
291 template <typename T> T GetParameter( EventParamName inName )
292 {
293 T value ;
294 verify_noerr( GetParameter<T>( inName, &value ) ) ;
295 return value ;
296 }
297 template <typename T> T GetParameter( EventParamName inName, EventParamType inDesiredType )
298 {
299 T value ;
300 verify_noerr( GetParameter<T>( inName, inDesiredType , &value ) ) ;
301 return value ;
302 }
303
304 OSStatus SetParameter( EventParamName inName, EventParamType inType, UInt32 inSize, const void * inData) ;
305 template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T *data )
306 {
307 return SetParameter( inName, inDesiredType , sizeof( T ) , data ) ;
308 }
309 template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T& data )
310 {
311 return SetParameter<T>( inName, inDesiredType , &data ) ;
312 }
313 template <typename T> OSStatus SetParameter( EventParamName inName, const T *data )
314 {
315 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , data ) ;
316 }
317 template <typename T> OSStatus SetParameter( EventParamName inName, const T& data )
318 {
319 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , &data ) ;
320 }
321 UInt32 GetClass()
322 {
323 return ::GetEventClass( m_eventRef ) ;
324 }
325 UInt32 GetKind()
326 {
327 return ::GetEventKind( m_eventRef ) ;
328 }
329 EventTime GetTime()
330 {
331 return ::GetEventTime( m_eventRef ) ;
332 }
333 UInt32 GetTicks()
334 {
335 return EventTimeToTicks( GetTime() ) ;
336 }
337 OSStatus SetCurrentTime( )
338 {
339 return ::SetEventTime( m_eventRef , GetCurrentEventTime() ) ;
340 }
341 OSStatus SetTime( EventTime when )
342 {
343 return ::SetEventTime( m_eventRef , when ) ;
344 }
345 operator EventRef () { return m_eventRef; }
346
347 bool IsValid() { return m_eventRef != 0 ; }
348 protected :
349 EventRef m_eventRef ;
350 bool m_release ;
351 } ;
352
353 //
354 // helper class for allocating and deallocating Universal Proc Ptrs
355 //
356
357 template <typename procType, typename uppType , uppType (*newUPP)(procType) , void (*disposeUPP)(uppType) > class wxMacUPP
358 {
359 public :
360 wxMacUPP( procType proc )
361 {
362 m_upp = NULL ;
363 m_upp = (*newUPP)( NULL ) ;
364 }
365 ~wxMacUPP()
366 {
367 if ( m_upp )
368 disposeUPP( m_upp ) ;
369 }
370 operator uppType() { return m_upp ; }
371 private :
372 uppType m_upp ;
373 } ;
374
375 typedef wxMacUPP<NMProcPtr,NMUPP,NewNMUPP,DisposeNMUPP> wxMacNMUPP ;
376
377 template <typename refType> class wxMacCFRefHolder
378 {
379 public :
380 wxMacCFRefHolder()
381 : m_ref(NULL) , m_release(false)
382 {
383 }
384
385 wxMacCFRefHolder( refType ref , bool release = true )
386 : m_ref(ref) , m_release(release)
387 {
388 }
389
390 ~wxMacCFRefHolder()
391 {
392 Release() ;
393 }
394
395 void Release()
396 {
397 if ( m_release && m_ref != NULL )
398 CFRelease( m_ref ) ;
399 m_ref = NULL ;
400 }
401
402 refType Detach()
403 {
404 refType val = m_ref ;
405 m_release = false ;
406 m_ref = NULL ;
407 return val ;
408 }
409
410 void Set( refType ref , bool release = true )
411 {
412 Release() ;
413 m_release = release ;
414 m_ref = ref ;
415 }
416
417 operator refType () const { return m_ref; }
418
419 private :
420 refType m_ref ;
421 bool m_release ;
422
423 DECLARE_NO_COPY_CLASS( wxMacCFRefHolder )
424 } ;
425
426 #if wxUSE_GUI
427 /*
428 GWorldPtr wxMacCreateGWorld( int width , int height , int depth ) ;
429 void wxMacDestroyGWorld( GWorldPtr gw ) ;
430 PicHandle wxMacCreatePict( GWorldPtr gw , GWorldPtr mask = NULL ) ;
431 CIconHandle wxMacCreateCIcon(GWorldPtr image , GWorldPtr mask , short dstDepth , short iconSize ) ;
432 void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue ) ;
433 CTabHandle wxMacCreateColorTable( int numColors ) ;
434 */
435 void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType = 0 ) ;
436 void wxMacReleaseBitmapButton( ControlButtonContentInfo*info ) ;
437
438 #define MAC_WXCOLORREF(a) (*((RGBColor*)&(a)))
439 #define MAC_WXHBITMAP(a) (GWorldPtr(a))
440 #define MAC_WXHMETAFILE(a) (PicHandle(a))
441 #define MAC_WXHICON(a) (IconRef(a))
442 #define MAC_WXHCURSOR(a) (CursHandle(a))
443 #define MAC_WXHRGN(a) (RgnHandle(a))
444 #define MAC_WXHWND(a) (WindowPtr(a))
445 #define MAC_WXRECPTR(a) ((Rect*)a)
446 #define MAC_WXPOINTPTR(a) ((Point*)a)
447 #define MAC_WXHMENU(a) ((MenuHandle)a)
448
449 struct wxOpaqueWindowRef
450 {
451 wxOpaqueWindowRef( WindowRef ref ) { m_data = ref ; }
452 operator WindowRef() { return m_data ; }
453 private :
454 WindowRef m_data ;
455 } ;
456
457 void wxMacRectToNative( const wxRect *wx , Rect *n ) ;
458 void wxMacNativeToRect( const Rect *n , wxRect* wx ) ;
459 void wxMacPointToNative( const wxPoint* wx , Point *n ) ;
460 void wxMacNativeToPoint( const Point *n , wxPoint* wx ) ;
461
462 wxWindow * wxFindControlFromMacControl(ControlRef inControl ) ;
463 wxTopLevelWindowMac* wxFindWinFromMacWindow( WindowRef inWindow ) ;
464 wxMenu* wxFindMenuFromMacMenu(MenuRef inMenuRef) ;
465
466 int wxMacCommandToId( UInt32 macCommandId ) ;
467 UInt32 wxIdToMacCommand( int wxId ) ;
468 wxMenu* wxFindMenuFromMacCommand( const HICommand &macCommandId , wxMenuItem* &item ) ;
469
470 extern wxWindow* g_MacLastWindow ;
471 pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data ) ;
472 Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin = true ) ;
473
474 ControlActionUPP GetwxMacLiveScrollbarActionProc() ;
475
476 class wxMacControl
477 {
478 public :
479 wxMacControl( wxWindow* peer , bool isRootControl = false ) ;
480 wxMacControl( wxWindow* peer , ControlRef control ) ;
481 wxMacControl( wxWindow* peer , WXWidget control ) ;
482 virtual ~wxMacControl() ;
483
484 void Init() ;
485
486 virtual void Dispose() ;
487
488 bool Ok() const { return GetControlRef() != NULL ; }
489
490 virtual ControlRef * GetControlRefAddr() { return &m_controlRef; }
491 virtual ControlRef GetControlRef() const { return m_controlRef ; }
492
493 virtual void SetReference( SInt32 data ) ;
494 /*
495 void operator= (ControlRef c) { m_controlRef = c ; }
496 operator ControlRef () { return m_controlRef; }
497 operator ControlRef * () { return &m_controlRef; }
498 */
499 // accessing data and values
500
501 virtual OSStatus SetData( ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData ) ;
502 virtual OSStatus GetData( ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const ;
503 virtual OSStatus GetDataSize( ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const ;
504 virtual OSStatus SendEvent( EventRef ref , OptionBits inOptions = 0 ) ;
505 virtual OSStatus SendHICommand( HICommand &command , OptionBits inOptions = 0 ) ;
506
507 virtual OSStatus SendHICommand( UInt32 commandID , OptionBits inOptions = 0 ) ;
508
509 virtual SInt32 GetValue() const ;
510 virtual SInt32 GetMaximum() const ;
511 virtual SInt32 GetMinimum() const ;
512
513 virtual void SetValue( SInt32 v ) ;
514 virtual void SetMinimum( SInt32 v ) ;
515 virtual void SetMaximum( SInt32 v ) ;
516
517 virtual void SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum ) ;
518 virtual void SetRange( SInt32 minimum , SInt32 maximum ) ;
519
520 virtual OSStatus SetFocus( ControlFocusPart focusPart ) ;
521 virtual bool HasFocus() const ;
522 virtual bool NeedsFocusRect() const ;
523 virtual void SetNeedsFocusRect( bool needs ) ;
524
525 // templated helpers
526
527 Size GetDataSize( ControlPartCode inPartCode , ResType inTag ) const
528 {
529 Size sz ;
530 verify_noerr( GetDataSize( inPartCode , inTag , &sz ) ) ;
531 return sz ;
532 }
533 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T *data )
534 {
535 return SetData( inPartCode , inTag , sizeof( T ) , data ) ;
536 }
537 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T& data )
538 {
539 return SetData( inPartCode , inTag , sizeof( T ) , &data ) ;
540 }
541 template <typename T> OSStatus SetData( ResType inTag , const T *data )
542 {
543 return SetData( kControlEntireControl , inTag , sizeof( T ) , data ) ;
544 }
545 template <typename T> OSStatus SetData( ResType inTag , const T& data )
546 {
547 return SetData( kControlEntireControl , inTag , sizeof( T ) , &data ) ;
548 }
549 template <typename T> OSStatus GetData( ControlPartCode inPartCode , ResType inTag , T *data ) const
550 {
551 Size dummy ;
552 return GetData( inPartCode , inTag , sizeof( T ) , data , &dummy ) ;
553 }
554 template <typename T> T GetData( ControlPartCode inPartCode , ResType inTag ) const
555 {
556 T value ;
557 verify_noerr( GetData<T>( inPartCode , inTag , &value ) ) ;
558 return value ;
559 }
560 template <typename T> OSStatus GetData( ResType inTag , T *data ) const
561 {
562 Size dummy ;
563 return GetData( kControlEntireControl , inTag , sizeof( T ) , data , &dummy ) ;
564 }
565 template <typename T> T GetData( ResType inTag ) const
566 {
567 T value ;
568 verify_noerr( GetData<T>( kControlEntireControl , inTag , &value ) ) ;
569 return value ;
570 }
571
572 // Flash the control for the specified amount of time
573 virtual void Flash( ControlPartCode part , UInt32 ticks = 8 ) ;
574
575 virtual void VisibilityChanged( bool shown ) ;
576 virtual void SuperChangedPosition() ;
577
578
579 virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle ) ;
580 virtual void SetBackground( const wxBrush &brush ) ;
581 virtual ControlPartCode HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers ) ;
582 void SetActionProc( ControlActionUPP actionProc ) ;
583 void SetViewSize( SInt32 viewSize ) ;
584 SInt32 GetViewSize() const ;
585
586 virtual bool IsVisible() const ;
587 virtual void SetVisibility( bool visible , bool redraw ) ;
588 virtual bool IsEnabled() const ;
589 virtual bool IsActive() const ;
590 virtual void Enable( bool enable ) ;
591
592 // invalidates this control and all children
593 virtual void InvalidateWithChildren() ;
594 virtual void SetDrawingEnabled( bool enable ) ;
595 #ifdef __WXMAC_OSX__
596 virtual bool GetNeedsDisplay() const ;
597 #endif
598 // where is in native window relative coordinates
599 virtual void SetNeedsDisplay( RgnHandle where ) ;
600 // where is in native window relative coordinates
601 virtual void SetNeedsDisplay( Rect* where = NULL ) ;
602
603 // if rect = NULL, entire view
604 virtual void ScrollRect( wxRect *rect , int dx , int dy ) ;
605
606 // in native parent window relative coordinates
607 virtual void GetRect( Rect *r ) ;
608
609 // in native parent window relative coordinates
610 virtual void SetRect( Rect *r ) ;
611
612 virtual void GetRectInWindowCoords( Rect *r ) ;
613 virtual void GetBestRect( Rect *r ) ;
614 virtual void SetLabel( const wxString &title ) ;
615 // converts from Toplevel-Content relative to local
616 static void Convert( wxPoint *pt , wxMacControl *convert , wxMacControl *to ) ;
617
618 virtual void GetFeatures( UInt32 *features ) ;
619 virtual OSStatus GetRegion( ControlPartCode partCode , RgnHandle region ) ;
620 virtual OSStatus SetZOrder( bool above , wxMacControl* other ) ;
621 // to be moved into a databrowser subclass
622
623 virtual OSStatus SetSelectionFlags( DataBrowserSelectionFlags ) ;
624 virtual OSStatus AddListViewColumn( DataBrowserListViewColumnDesc *columnDesc,
625 DataBrowserTableViewColumnIndex position ) ;
626 virtual OSStatus AutoSizeListViewColumns() ;
627 virtual OSStatus SetHasScrollBars( bool horiz , bool vert ) ;
628 virtual OSStatus SetTableViewHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle ) ;
629 virtual OSStatus SetListViewHeaderBtnHeight(UInt16 height) ;
630 virtual OSStatus SetCallbacks(const DataBrowserCallbacks * callbacks) ;
631 virtual OSStatus UpdateItems( DataBrowserItemID container, UInt32 numItems,
632 const DataBrowserItemID* items,
633 DataBrowserPropertyID preSortProperty,
634 DataBrowserPropertyID propertyID ) ;
635 virtual OSStatus AddItems( DataBrowserItemID container, UInt32 numItems,
636 const DataBrowserItemID* items,
637 DataBrowserPropertyID preSortProperty ) ;
638 virtual OSStatus RemoveItems( DataBrowserItemID container, UInt32 numItems,
639 const DataBrowserItemID* items,
640 DataBrowserPropertyID preSortProperty ) ;
641 virtual OSStatus RevealItem( DataBrowserItemID item,
642 DataBrowserPropertyID propertyID,
643 DataBrowserRevealOptions options ) ;
644 virtual OSStatus GetSelectionAnchor( DataBrowserItemID * first, DataBrowserItemID * last ) ;
645 virtual bool IsItemSelected( DataBrowserItemID item ) ;
646 virtual OSStatus SetSelectedItems(UInt32 numItems,
647 const DataBrowserItemID * items,
648 DataBrowserSetOption operation ) ;
649
650 // to be moved into a tab control class
651
652 virtual OSStatus SetTabEnabled( SInt16 tabNo , bool enable ) ;
653 bool IsCompositing() { return m_isCompositing ; }
654 bool IsRootControl() { return m_isRootControl ; }
655 protected :
656 ControlRef m_controlRef ;
657 wxFont m_font ;
658 long m_windowStyle ;
659 wxWindow* m_peer ;
660 bool m_needsFocusRect ;
661 bool m_isCompositing ;
662 bool m_isRootControl ;
663 } ;
664
665 #if wxMAC_USE_CORE_GRAPHICS
666
667 class WXDLLEXPORT wxMacCGPath : public wxGraphicPath
668 {
669 DECLARE_NO_COPY_CLASS(wxMacCGPath)
670 public :
671 wxMacCGPath() ;
672 ~wxMacCGPath() ;
673
674 // Starts a new subpath at
675 void MoveToPoint( wxCoord x1 , wxCoord y1 ) ;
676 void AddLineToPoint( wxCoord x1 , wxCoord y1 ) ;
677 void AddQuadCurveToPoint( wxCoord cx1, wxCoord cy1, wxCoord x1, wxCoord y1 ) ;
678 void AddRectangle( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) ;
679 void AddCircle( wxCoord x, wxCoord y , wxCoord r ) ;
680
681 // closes the current subpath
682 void CloseSubpath() ;
683
684 CGPathRef GetPath() const ;
685 private :
686 CGMutablePathRef m_path ;
687 } ;
688
689 class WXDLLEXPORT wxMacCGContext : public wxGraphicContext
690 {
691 DECLARE_NO_COPY_CLASS(wxMacCGContext)
692
693 public:
694 wxMacCGContext( CGrafPtr port ) ;
695 wxMacCGContext( CGContextRef cgcontext ) ;
696 wxMacCGContext() ;
697 ~wxMacCGContext() ;
698
699 virtual void Clip( const wxRegion &region ) ;
700 virtual void StrokePath( const wxGraphicPath *p ) ;
701 virtual void DrawPath( const wxGraphicPath *p , int fillStyle = wxWINDING_RULE ) ;
702 virtual void FillPath( const wxGraphicPath *p , const wxColor &fillColor , int fillStyle = wxWINDING_RULE ) ;
703
704 virtual wxGraphicPath* CreatePath() ;
705 virtual void SetPen( const wxPen &pen ) ;
706 virtual void SetBrush( const wxBrush &brush ) ;
707 CGContextRef GetNativeContext() ;
708 void SetNativeContext( CGContextRef cg ) ;
709 CGPathDrawingMode GetDrawingMode() const { return m_mode ; }
710 private:
711 CGContextRef m_cgContext ;
712 CGrafPtr m_qdPort ;
713 CGPathDrawingMode m_mode ;
714 wxPen m_pen ;
715 wxBrush m_brush ;
716 } ;
717
718 #endif // wxMAC_USE_CORE_GRAPHICS
719
720 #ifdef __WXMAC_OSX__
721
722 CGColorSpaceRef wxMacGetGenericRGBColorSpace(void) ;
723 void wxMacMemoryBufferReleaseProc(void *info, const void *data, size_t size) ;
724
725 #endif
726
727 class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
728 {
729 DECLARE_NO_COPY_CLASS(wxBitmapRefData)
730
731 friend class WXDLLEXPORT wxIcon;
732 friend class WXDLLEXPORT wxCursor;
733 public:
734 wxBitmapRefData(int width , int height , int depth);
735 wxBitmapRefData();
736 ~wxBitmapRefData();
737
738 void Free() ;
739 bool Ok() const { return m_ok ; }
740 void SetOk( bool isOk) { m_ok = isOk ; }
741
742 void SetWidth( int width ) { m_width = width ; }
743 void SetHeight( int height ) { m_height = height ; }
744 void SetDepth( int depth ) { m_depth = depth ; }
745
746 int GetWidth() const { return m_width ; }
747 int GetHeight() const { return m_height ; }
748 int GetDepth() const { return m_depth ; }
749
750 void *GetRawAccess() const ;
751 void *BeginRawAccess() ;
752 void EndRawAccess() ;
753
754 bool HasAlpha() const { return m_hasAlpha ; }
755 void UseAlpha( bool useAlpha ) ;
756
757 public:
758 #if wxUSE_PALETTE
759 wxPalette m_bitmapPalette;
760 #endif // wxUSE_PALETTE
761
762 wxMask * m_bitmapMask; // Optional mask
763 #ifdef __WXMAC_OSX__
764 CGImageRef CGImageCreate() const ;
765 #endif
766
767 // returns true if the bitmap has a size that
768 // can be natively transferred into a true icon
769 // if no is returned GetIconRef will still produce
770 // an icon but it will be generated via a PICT and
771 // rescaled to 16 x 16
772 bool HasNativeSize() ;
773
774 // caller should increase ref count if needed longer
775 // than the bitmap exists
776 IconRef GetIconRef() ;
777
778 // returns a Pict from the bitmap content
779 PicHandle GetPictHandle() ;
780 GWorldPtr GetHBITMAP(GWorldPtr * mask = NULL ) const ;
781 void UpdateAlphaMask() const ;
782
783 private :
784 bool Create(int width , int height , int depth) ;
785 void Init() ;
786
787 int m_width;
788 int m_height;
789 int m_bytesPerRow ;
790 int m_depth;
791 bool m_hasAlpha;
792 wxMemoryBuffer m_memBuf ;
793 int m_rawAccessCount ;
794 bool m_ok;
795 #ifdef __WXMAC_OSX__
796 mutable CGImageRef m_cgImageRef ;
797 #endif
798 IconRef m_iconRef ;
799 PicHandle m_pictHandle ;
800 GWorldPtr m_hBitmap;
801 GWorldPtr m_hMaskBitmap ;
802 wxMemoryBuffer m_maskMemBuf ;
803 int m_maskBytesPerRow ;
804 };
805
806 class WXDLLEXPORT wxIconRefData : public wxGDIRefData
807 {
808 public:
809 wxIconRefData() ;
810 wxIconRefData( WXHICON ) ;
811 virtual ~wxIconRefData() { Free(); }
812
813 void Init() ;
814 virtual void Free();
815
816 void SetWidth( int width ) { m_width = width ; }
817 void SetHeight( int height ) { m_height = height ; }
818
819 int GetWidth() const { return m_width ; }
820 int GetHeight() const { return m_height ; }
821
822 WXHICON GetHICON() const { return (WXHICON) m_iconRef ; }
823 private :
824 IconRef m_iconRef ;
825 int m_width ;
826 int m_height ;
827 };
828
829 // toplevel.cpp
830
831 ControlRef wxMacFindControlUnderMouse( wxTopLevelWindowMac* toplevelWindow, const Point& location , WindowRef window , ControlPartCode *outPart ) ;
832
833 #ifdef WORDS_BIGENDIAN
834 inline Rect* wxMacGetPictureBounds( PicHandle pict , Rect* rect )
835 {
836 *rect = (**pict).picFrame ;
837 return rect ;
838 }
839 #else
840 inline Rect* wxMacGetPictureBounds( PicHandle pict , Rect* rect )
841 {
842 return QDGetPictureBounds( pict , rect ) ;
843 }
844 #endif
845
846 #endif // wxUSE_GUI
847
848 #define wxMAC_DEFINE_PROC_GETTER( UPP , x ) \
849 UPP Get##x() \
850 { \
851 static UPP sHandler = NULL; \
852 if ( sHandler == NULL ) \
853 sHandler = New##UPP( x ); \
854 return sHandler; \
855 }
856
857 //---------------------------------------------------------------------------
858 // wxMac string conversions
859 //---------------------------------------------------------------------------
860
861 void wxMacSetupConverters() ;
862 void wxMacCleanupConverters() ;
863
864 void wxMacStringToPascal( const wxString&from , StringPtr to ) ;
865 wxString wxMacMakeStringFromPascal( ConstStringPtr from ) ;
866
867 // filefn.cpp
868
869 wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL ) ;
870 OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef ) ;
871 wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname ) ;
872
873 #endif
874 // _WX_PRIVATE_H_