]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/private.h
Simplify use of MacIsWindowScrollbar
[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
19 #ifdef __DARWIN__
20 # include <Carbon/Carbon.h>
21 #else
22 # include <Debugging.h>
23 # include <Quickdraw.h>
24 # include <Appearance.h>
25 # include <Folders.h>
26 # include <Controls.h>
27 # include <ControlDefinitions.h>
28 # include <LowMem.h>
29 # include <Gestalt.h>
30 # include <FixMath.h>
31 # include <CoreServices.h>
32 #endif
33
34 #if UNIVERSAL_INTERFACES_VERSION < 0x0342
35 #error "please update to Apple's latest 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 #ifndef MAC_OS_X_VERSION_10_4
43 #define MAC_OS_X_VERSION_10_4 1040
44 #endif
45
46 #ifdef __WXMAC_CARBON__
47 #include "wx/mac/corefoundation/cfstring.h"
48 #endif
49
50 #ifndef FixedToInt
51 // as macro in FixMath.h for 10.3
52 inline Fixed IntToFixed( int inInt )
53 {
54 return (((SInt32) inInt) << 16);
55 }
56
57 inline int FixedToInt( Fixed inFixed )
58 {
59 return (((SInt32) inFixed) >> 16);
60 }
61 #endif
62
63 #if wxUSE_GUI
64
65 #include "wx/listbox.h"
66
67 class wxMacPortStateHelper
68 {
69 DECLARE_NO_COPY_CLASS(wxMacPortStateHelper)
70
71 public:
72 wxMacPortStateHelper( GrafPtr newport);
73 wxMacPortStateHelper();
74 ~wxMacPortStateHelper();
75
76 void Setup( GrafPtr newport );
77 void Clear();
78 bool IsCleared() { return m_clip == NULL; }
79 GrafPtr GetCurrentPort() { return m_currentPort; }
80
81 private:
82 GrafPtr m_currentPort;
83 GrafPtr m_oldPort;
84 RgnHandle m_clip;
85 ThemeDrawingState m_drawingState;
86 short m_textFont;
87 short m_textSize;
88 short m_textStyle;
89 short m_textMode;
90 };
91
92 class WXDLLEXPORT wxMacPortSaver
93 {
94 DECLARE_NO_COPY_CLASS(wxMacPortSaver)
95
96 public:
97 wxMacPortSaver( GrafPtr port );
98 ~wxMacPortSaver();
99 private :
100 GrafPtr m_port;
101 };
102
103 class WXDLLEXPORT wxMacPortSetter
104 {
105 DECLARE_NO_COPY_CLASS(wxMacPortSetter)
106
107 public:
108 wxMacPortSetter( const wxDC* dc );
109 ~wxMacPortSetter();
110 private:
111 wxMacPortStateHelper m_ph;
112 const wxDC* m_dc;
113 };
114
115 /*
116 Clips to the visible region of a control within the current port
117 */
118
119 class WXDLLEXPORT wxMacWindowClipper : public wxMacPortSaver
120 {
121 DECLARE_NO_COPY_CLASS(wxMacWindowClipper)
122
123 public:
124 wxMacWindowClipper( const wxWindow* win );
125 ~wxMacWindowClipper();
126 private:
127 GrafPtr m_newPort;
128 RgnHandle m_formerClip;
129 RgnHandle m_newClip;
130 };
131
132 class WXDLLEXPORT wxMacWindowStateSaver : public wxMacWindowClipper
133 {
134 DECLARE_NO_COPY_CLASS(wxMacWindowStateSaver)
135
136 public:
137 wxMacWindowStateSaver( const wxWindow* win );
138 ~wxMacWindowStateSaver();
139 private:
140 GrafPtr m_newPort;
141 ThemeDrawingState m_themeDrawingState;
142 };
143
144 #if wxMAC_USE_CORE_GRAPHICS
145 class WXDLLEXPORT wxMacCGContextStateSaver
146 {
147 DECLARE_NO_COPY_CLASS(wxMacCGContextStateSaver)
148
149 public:
150 wxMacCGContextStateSaver( CGContextRef cg )
151 {
152 m_cg = cg;
153 CGContextSaveGState( cg );
154 }
155 ~wxMacCGContextStateSaver()
156 {
157 CGContextRestoreGState( m_cg );
158 }
159 private:
160 CGContextRef m_cg;
161 };
162
163 #endif
164 /*
165 class wxMacDrawingHelper
166 {
167 DECLARE_NO_COPY_CLASS(wxMacDrawingHelper)
168
169 public:
170 wxMacDrawingHelper( wxWindowMac * theWindow , bool clientArea = false );
171 ~wxMacDrawingHelper();
172 bool Ok() { return m_ok; }
173 void LocalToWindow( Rect *rect) { OffsetRect( rect , m_origin.h , m_origin.v ); }
174 void LocalToWindow( Point *pt ) { AddPt( m_origin , pt ); }
175 void LocalToWindow( RgnHandle rgn ) { OffsetRgn( rgn , m_origin.h , m_origin.v ); }
176 const Point& GetOrigin() { return m_origin; }
177 private:
178 Point m_origin;
179 GrafPtr m_formerPort;
180 GrafPtr m_currentPort;
181 PenState m_savedPenState;
182 bool m_ok;
183 };
184 */
185
186 // app.h
187 bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec);
188
189 #endif // wxUSE_GUI
190
191 // filefn.h
192 WXDLLEXPORT wxString wxMacFSSpec2MacFilename( const FSSpec *spec );
193 WXDLLEXPORT void wxMacFilename2FSSpec( const wxString &path , FSSpec *spec );
194
195 // utils.h
196 WXDLLEXPORT wxString wxMacFindFolderNoSeparator(short vRefNum,
197 OSType folderType,
198 Boolean createFolder);
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 /*
429 GWorldPtr wxMacCreateGWorld( int width , int height , int depth );
430 void wxMacDestroyGWorld( GWorldPtr gw );
431 PicHandle wxMacCreatePict( GWorldPtr gw , GWorldPtr mask = NULL );
432 CIconHandle wxMacCreateCIcon(GWorldPtr image , GWorldPtr mask , short dstDepth , short iconSize );
433 void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue );
434 CTabHandle wxMacCreateColorTable( int numColors );
435 */
436 void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType = 0 );
437 void wxMacReleaseBitmapButton( ControlButtonContentInfo*info );
438
439 #define MAC_WXCOLORREF(a) (*((RGBColor*)&(a)))
440 #define MAC_WXHBITMAP(a) (GWorldPtr(a))
441 #define MAC_WXHMETAFILE(a) (PicHandle(a))
442 #define MAC_WXHICON(a) (IconRef(a))
443 #define MAC_WXHCURSOR(a) (CursHandle(a))
444 #define MAC_WXHRGN(a) (RgnHandle(a))
445 #define MAC_WXHWND(a) (WindowPtr(a))
446 #define MAC_WXRECPTR(a) ((Rect*)a)
447 #define MAC_WXPOINTPTR(a) ((Point*)a)
448 #define MAC_WXHMENU(a) ((MenuHandle)a)
449
450 struct wxOpaqueWindowRef
451 {
452 wxOpaqueWindowRef( WindowRef ref ) { m_data = ref; }
453 operator WindowRef() { return m_data; }
454 private :
455 WindowRef m_data;
456 };
457
458 void wxMacRectToNative( const wxRect *wx , Rect *n );
459 void wxMacNativeToRect( const Rect *n , wxRect* wx );
460 void wxMacPointToNative( const wxPoint* wx , Point *n );
461 void wxMacNativeToPoint( const Point *n , wxPoint* wx );
462
463 wxWindow * wxFindControlFromMacControl(ControlRef inControl );
464 wxTopLevelWindowMac* wxFindWinFromMacWindow( WindowRef inWindow );
465 wxMenu* wxFindMenuFromMacMenu(MenuRef inMenuRef);
466
467 int wxMacCommandToId( UInt32 macCommandId );
468 UInt32 wxIdToMacCommand( int wxId );
469 wxMenu* wxFindMenuFromMacCommand( const HICommand &macCommandId , wxMenuItem* &item );
470
471 extern wxWindow* g_MacLastWindow;
472 pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data );
473 Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin = true );
474
475 ControlActionUPP GetwxMacLiveScrollbarActionProc();
476
477 class wxMacControl
478 {
479 public :
480 wxMacControl( wxWindow* peer , bool isRootControl = false );
481 wxMacControl( wxWindow* peer , ControlRef control );
482 wxMacControl( wxWindow* peer , WXWidget control );
483 virtual ~wxMacControl();
484
485 void Init();
486
487 virtual void Dispose();
488
489 bool Ok() const { return GetControlRef() != NULL; }
490
491 void SetReferenceInNativeControl();
492 static wxMacControl* GetReferenceFromNativeControl(ControlRef control);
493
494 virtual ControlRef * GetControlRefAddr() { return &m_controlRef; }
495 virtual ControlRef GetControlRef() const { return m_controlRef; }
496
497 virtual void SetReference( SInt32 data );
498 /*
499 void operator= (ControlRef c) { m_controlRef = c; }
500 operator ControlRef () { return m_controlRef; }
501 operator ControlRef * () { return &m_controlRef; }
502 */
503 // accessing data and values
504
505 virtual OSStatus SetData( ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData );
506 virtual OSStatus GetData( ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const;
507 virtual OSStatus GetDataSize( ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const;
508 virtual OSStatus SendEvent( EventRef ref , OptionBits inOptions = 0 );
509 virtual OSStatus SendHICommand( HICommand &command , OptionBits inOptions = 0 );
510
511 virtual OSStatus SendHICommand( UInt32 commandID , OptionBits inOptions = 0 );
512
513 virtual SInt32 GetValue() const;
514 virtual SInt32 GetMaximum() const;
515 virtual SInt32 GetMinimum() const;
516
517 virtual void SetValue( SInt32 v );
518 virtual void SetMinimum( SInt32 v );
519 virtual void SetMaximum( SInt32 v );
520
521 virtual void SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum );
522 virtual void SetRange( SInt32 minimum , SInt32 maximum );
523
524 virtual OSStatus SetFocus( ControlFocusPart focusPart );
525 virtual bool HasFocus() const;
526 virtual bool NeedsFocusRect() const;
527 virtual void SetNeedsFocusRect( bool needs );
528
529 // templated helpers
530
531 Size GetDataSize( ControlPartCode inPartCode , ResType inTag ) const
532 {
533 Size sz;
534 verify_noerr( GetDataSize( inPartCode , inTag , &sz ) );
535 return sz;
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( ControlPartCode inPartCode , ResType inTag , const T& data )
542 {
543 return SetData( inPartCode , 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 SetData( ResType inTag , const T& data )
550 {
551 return SetData( kControlEntireControl , inTag , sizeof( T ) , &data );
552 }
553 template <typename T> OSStatus GetData( ControlPartCode inPartCode , ResType inTag , T *data ) const
554 {
555 Size dummy;
556 return GetData( inPartCode , inTag , sizeof( T ) , data , &dummy );
557 }
558 template <typename T> T GetData( ControlPartCode inPartCode , ResType inTag ) const
559 {
560 T value;
561 OSStatus err = GetData<T>( inPartCode , inTag , &value );
562
563 wxASSERT_MSG( err == noErr,
564 wxString::Format(wxT("GetData Failed for Part [%i] and Tag [%i]"),
565 inPartCode, (int)inTag) );
566 return value;
567 }
568 template <typename T> OSStatus GetData( ResType inTag , T *data ) const
569 {
570 Size dummy;
571 return GetData( kControlEntireControl , inTag , sizeof( T ) , data , &dummy );
572 }
573 template <typename T> T GetData( ResType inTag ) const
574 {
575 return GetData<T>( kControlEntireControl , inTag );
576 }
577
578 // Flash the control for the specified amount of time
579 virtual void Flash( ControlPartCode part , UInt32 ticks = 8 );
580
581 virtual void VisibilityChanged( bool shown );
582 virtual void SuperChangedPosition();
583
584
585 virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle );
586 virtual void SetBackground( const wxBrush &brush );
587 virtual ControlPartCode HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers );
588 void SetActionProc( ControlActionUPP actionProc );
589 void SetViewSize( SInt32 viewSize );
590 SInt32 GetViewSize() const;
591
592 virtual bool IsVisible() const;
593 virtual void SetVisibility( bool visible , bool redraw );
594 virtual bool IsEnabled() const;
595 virtual bool IsActive() const;
596 virtual void Enable( bool enable );
597
598 // invalidates this control and all children
599 virtual void InvalidateWithChildren();
600 virtual void SetDrawingEnabled( bool enable );
601 #ifdef __WXMAC_OSX__
602 virtual bool GetNeedsDisplay() const;
603 #endif
604 // where is in native window relative coordinates
605 virtual void SetNeedsDisplay( RgnHandle where );
606 // where is in native window relative coordinates
607 virtual void SetNeedsDisplay( Rect* where = NULL );
608
609 // if rect = NULL, entire view
610 virtual void ScrollRect( wxRect *rect , int dx , int dy );
611
612 // in native parent window relative coordinates
613 virtual void GetRect( Rect *r );
614
615 // in native parent window relative coordinates
616 virtual void SetRect( Rect *r );
617
618 virtual void GetRectInWindowCoords( Rect *r );
619 virtual void GetBestRect( Rect *r );
620 virtual void SetLabel( const wxString &title );
621 // converts from Toplevel-Content relative to local
622 static void Convert( wxPoint *pt , wxMacControl *convert , wxMacControl *to );
623
624 virtual void GetFeatures( UInt32 *features );
625 virtual OSStatus GetRegion( ControlPartCode partCode , RgnHandle region );
626 virtual OSStatus SetZOrder( bool above , wxMacControl* other );
627
628 bool IsRootControl() { return m_isRootControl; }
629
630 wxWindow* GetPeer() const
631 {
632 return m_peer;
633 }
634
635 // to be moved into a tab control class
636
637 virtual OSStatus SetTabEnabled( SInt16 tabNo , bool enable );
638 protected :
639 ControlRef m_controlRef;
640 wxFont m_font;
641 long m_windowStyle;
642 wxWindow* m_peer;
643 bool m_needsFocusRect;
644 bool m_isRootControl;
645 };
646
647 // ============================================================================
648 // DataBrowser Wrapper
649 // ============================================================================
650 //
651 // basing on DataBrowserItemIDs
652 //
653
654 class wxMacDataBrowserControl : public wxMacControl
655 {
656 public :
657 wxMacDataBrowserControl( wxWindow* peer, const wxPoint& pos, const wxSize& size, long style);
658
659 OSStatus SetCallbacks( const DataBrowserCallbacks *callbacks );
660
661 OSStatus GetItemCount( DataBrowserItemID container,
662 Boolean recurse,
663 DataBrowserItemState state,
664 UInt32 *numItems) const;
665
666 OSStatus GetItems( DataBrowserItemID container,
667 Boolean recurse,
668 DataBrowserItemState state,
669 Handle items) const;
670
671
672 OSStatus AddColumn( DataBrowserListViewColumnDesc *columnDesc,
673 DataBrowserTableViewColumnIndex position );
674
675 OSStatus AutoSizeColumns();
676
677 OSStatus SetHasScrollBars( bool horiz, bool vert );
678 OSStatus SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle );
679
680 OSStatus SetHeaderButtonHeight( UInt16 height );
681 OSStatus GetHeaderButtonHeight( UInt16 *height );
682
683 OSStatus UpdateItems( DataBrowserItemID container, UInt32 numItems,
684 const DataBrowserItemID *items,
685 DataBrowserPropertyID preSortProperty,
686 DataBrowserPropertyID propertyID ) const;
687
688 OSStatus AddItems( DataBrowserItemID container, UInt32 numItems,
689 const DataBrowserItemID *items,
690 DataBrowserPropertyID preSortProperty );
691 OSStatus RemoveItems( DataBrowserItemID container, UInt32 numItems,
692 const DataBrowserItemID *items,
693 DataBrowserPropertyID preSortProperty );
694 OSStatus RevealItem( DataBrowserItemID item,
695 DataBrowserPropertyID propertyID,
696 DataBrowserRevealOptions options ) const;
697
698 OSStatus SetSelectionFlags( DataBrowserSelectionFlags );
699 OSStatus GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const;
700 bool IsItemSelected( DataBrowserItemID item ) const;
701 OSStatus SetSelectedItems( UInt32 numItems,
702 const DataBrowserItemID *items,
703 DataBrowserSetOption operation );
704
705 OSStatus GetItemID( DataBrowserTableViewRowIndex row,
706 DataBrowserItemID * item ) const;
707 OSStatus GetItemRow( DataBrowserItemID item,
708 DataBrowserTableViewRowIndex * row ) const;
709
710 OSStatus SetDefaultRowHeight( UInt16 height );
711 OSStatus GetDefaultRowHeight( UInt16 * height ) const;
712
713 OSStatus SetRowHeight( DataBrowserItemID item , UInt16 height);
714 OSStatus GetRowHeight( DataBrowserItemID item , UInt16 *height) const;
715
716 OSStatus GetColumnWidth( DataBrowserPropertyID column , UInt16 *width ) const;
717 OSStatus SetColumnWidth( DataBrowserPropertyID column , UInt16 width );
718
719 OSStatus GetDefaultColumnWidth( UInt16 *width ) const;
720 OSStatus SetDefaultColumnWidth( UInt16 width );
721
722 OSStatus GetColumnCount( UInt32* numColumns) const;
723
724 OSStatus GetColumnPosition( DataBrowserPropertyID column, UInt32 *position) const;
725 OSStatus SetColumnPosition( DataBrowserPropertyID column, UInt32 position);
726
727 OSStatus GetScrollPosition( UInt32 *top , UInt32 *left ) const;
728 OSStatus SetScrollPosition( UInt32 top , UInt32 left );
729
730 OSStatus GetSortProperty( DataBrowserPropertyID *column ) const;
731 OSStatus SetSortProperty( DataBrowserPropertyID column );
732
733 OSStatus GetSortOrder( DataBrowserSortOrder *order ) const;
734 OSStatus SetSortOrder( DataBrowserSortOrder order );
735
736 OSStatus GetPropertyFlags( DataBrowserPropertyID property, DataBrowserPropertyFlags *flags ) const;
737 OSStatus SetPropertyFlags( DataBrowserPropertyID property, DataBrowserPropertyFlags flags );
738
739 OSStatus GetHeaderDesc( DataBrowserPropertyID property, DataBrowserListViewHeaderDesc *desc ) const;
740 OSStatus SetHeaderDesc( DataBrowserPropertyID property, DataBrowserListViewHeaderDesc *desc );
741
742 OSStatus SetDisclosureColumn( DataBrowserPropertyID property , Boolean expandableRows );
743 protected :
744
745 static pascal void DataBrowserItemNotificationProc(
746 ControlRef browser,
747 DataBrowserItemID itemID,
748 DataBrowserItemNotification message,
749 DataBrowserItemDataRef itemData );
750
751 virtual void ItemNotification(
752 DataBrowserItemID itemID,
753 DataBrowserItemNotification message,
754 DataBrowserItemDataRef itemData) = 0;
755
756 static pascal OSStatus DataBrowserGetSetItemDataProc(
757 ControlRef browser,
758 DataBrowserItemID itemID,
759 DataBrowserPropertyID property,
760 DataBrowserItemDataRef itemData,
761 Boolean changeValue );
762
763 virtual OSStatus GetSetItemData(
764 DataBrowserItemID itemID,
765 DataBrowserPropertyID property,
766 DataBrowserItemDataRef itemData,
767 Boolean changeValue ) = 0;
768
769 static pascal Boolean DataBrowserCompareProc(
770 ControlRef browser,
771 DataBrowserItemID itemOneID,
772 DataBrowserItemID itemTwoID,
773 DataBrowserPropertyID sortProperty);
774
775 virtual Boolean CompareItems(DataBrowserItemID itemOneID,
776 DataBrowserItemID itemTwoID,
777 DataBrowserPropertyID sortProperty) = 0;
778 };
779
780 // ============================================================================
781 // Higher-level Databrowser
782 // ============================================================================
783 //
784 // basing on data item objects
785 //
786
787 // forward decl
788
789 class wxMacDataItemBrowserControl;
790
791 // base class for databrowser items
792
793 class wxMacDataItem
794 {
795 public :
796 wxMacDataItem();
797 virtual ~wxMacDataItem();
798
799 virtual bool IsLessThan(wxMacDataItemBrowserControl *owner ,
800 const wxMacDataItem*,
801 DataBrowserPropertyID property) const;
802
803 // returns true if access was successful, otherwise false
804 virtual OSStatus GetSetData(wxMacDataItemBrowserControl *owner ,
805 DataBrowserPropertyID property,
806 DataBrowserItemDataRef itemData,
807 bool changeValue );
808
809 virtual void Notification(wxMacDataItemBrowserControl *owner ,
810 DataBrowserItemNotification message,
811 DataBrowserItemDataRef itemData ) const;
812 };
813
814 typedef wxMacDataItem* wxMacDataItemPtr;
815 const wxMacDataItemPtr wxMacDataBrowserRootContainer = NULL;
816
817 WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxMacDataItemPtr, wxArrayMacDataItemPtr, class WXDLLIMPEXP_CORE);
818
819 class wxMacDataItemBrowserControl : public wxMacDataBrowserControl
820 {
821 public :
822 wxMacDataItemBrowserControl( wxWindow* peer , const wxPoint& pos, const wxSize& size, long style);
823
824 unsigned int GetItemCount(const wxMacDataItem* container, bool recurse , DataBrowserItemState state) const;
825 void GetItems(const wxMacDataItem* container, bool recurse ,
826 DataBrowserItemState state, wxArrayMacDataItemPtr &items ) const;
827
828 unsigned int GetLineFromItem(const wxMacDataItem *item) const;
829 wxMacDataItem * GetItemFromLine(unsigned int n) const;
830
831 void UpdateItem(const wxMacDataItem *container, const wxMacDataItem *item,
832 DataBrowserPropertyID property) const;
833 void UpdateItems(const wxMacDataItem *container, wxArrayMacDataItemPtr &items,
834 DataBrowserPropertyID property) const;
835
836 void AddItem(wxMacDataItem *container, wxMacDataItem *item);
837 void AddItems(wxMacDataItem *container, wxArrayMacDataItemPtr &items );
838
839 void RemoveAllItems(wxMacDataItem *container);
840 void RemoveItem(wxMacDataItem *container, wxMacDataItem* item);
841 void RemoveItems(wxMacDataItem *container, wxArrayMacDataItemPtr &items);
842
843 void SetSelectedItem( wxMacDataItem* item , DataBrowserSetOption option);
844 void SetSelectedItems( wxArrayMacDataItemPtr &items , DataBrowserSetOption option);
845 void SetSelectedAllItems( DataBrowserSetOption option);
846 Boolean IsItemSelected( const wxMacDataItem* item) const;
847
848 void RevealItem( wxMacDataItem* item, DataBrowserRevealOptions options);
849
850 void GetSelectionAnchor( wxMacDataItemPtr* first , wxMacDataItemPtr* last) const;
851
852 // item aware methods, to be used in subclasses
853
854 virtual Boolean CompareItems(const wxMacDataItem* itemOneID,
855 const wxMacDataItem* itemTwoID,
856 DataBrowserPropertyID sortProperty);
857
858 virtual OSStatus GetSetItemData(wxMacDataItem* itemID,
859 DataBrowserPropertyID property,
860 DataBrowserItemDataRef itemData,
861 Boolean changeValue );
862
863 virtual void ItemNotification(
864 const wxMacDataItem* itemID,
865 DataBrowserItemNotification message,
866 DataBrowserItemDataRef itemData);
867
868 // as we are getting the same events for human and API selection we have to suppress
869 // events in the latter case, since this will be used from many subclasses we keep it here
870
871 bool IsSelectionSuppressed() const { return m_suppressSelection; }
872 bool SuppressSelection( bool suppress );
873
874 protected:
875 // ID aware base methods, should be 'final' ie not changed in subclasses
876
877 virtual Boolean CompareItems(DataBrowserItemID itemOneID,
878 DataBrowserItemID itemTwoID,
879 DataBrowserPropertyID sortProperty);
880
881 virtual OSStatus GetSetItemData(DataBrowserItemID itemID,
882 DataBrowserPropertyID property,
883 DataBrowserItemDataRef itemData,
884 Boolean changeValue );
885
886 virtual void ItemNotification(
887 DataBrowserItemID itemID,
888 DataBrowserItemNotification message,
889 DataBrowserItemDataRef itemData);
890
891 private :
892
893 bool m_suppressSelection;
894 };
895
896 class wxMacDataItemBrowserSelectionSuppressor
897 {
898 public :
899 wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl *browser);
900 ~wxMacDataItemBrowserSelectionSuppressor();
901
902 private :
903
904 bool m_former;
905 wxMacDataItemBrowserControl* m_browser;
906 };
907
908 // ============================================================================
909 // platform listbox implementation
910 // ============================================================================
911 //
912 // exposed for reuse in wxCheckListBox
913
914 class wxMacListBoxItem : public wxMacDataItem
915 {
916 public :
917 wxMacListBoxItem();
918
919 virtual ~wxMacListBoxItem();
920
921 void SetLabel( const wxString& str);
922 const wxString& GetLabel() const;
923
924 virtual bool IsLessThan(wxMacDataItemBrowserControl *owner ,
925 const wxMacDataItem* rhs,
926 DataBrowserPropertyID sortProperty) const;
927
928 virtual OSStatus GetSetData( wxMacDataItemBrowserControl *owner ,
929 DataBrowserPropertyID property,
930 DataBrowserItemDataRef itemData,
931 bool changeValue );
932
933 virtual void Notification(wxMacDataItemBrowserControl *owner ,
934 DataBrowserItemNotification message,
935 DataBrowserItemDataRef itemData ) const;
936
937 void SetOrder( SInt32 order );
938 SInt32 GetOrder() const;
939
940 void SetData( void* data);
941 void* GetData() const;
942
943 private :
944 wxString m_label;
945 wxMacCFStringHolder m_cfLabel;
946 void * m_data;
947 SInt32 m_order;
948 };
949
950 class wxMacDataBrowserListControl : public wxMacDataItemBrowserControl , public wxMacListControl
951 {
952 public:
953 wxMacDataBrowserListControl( wxListBox *peer, const wxPoint& pos, const wxSize& size, long style );
954 virtual ~wxMacDataBrowserListControl();
955
956 // create a list item (can be a subclass of wxMacListBoxItem)
957
958 virtual wxMacListBoxItem* CreateItem();
959
960 // add and remove
961
962 void MacDelete( unsigned int n );
963 void MacInsert( unsigned int n, const wxString& item );
964 void MacInsert( unsigned int n, const wxArrayString& items );
965 int MacAppend( const wxString& item );
966 void MacClear();
967
968 // selecting
969
970 void MacDeselectAll();
971 void MacSetSelection( unsigned int n, bool select );
972 int MacGetSelection() const;
973 int MacGetSelections( wxArrayInt& aSelections ) const;
974 bool MacIsSelected( unsigned int n ) const;
975
976 // display
977
978 void MacScrollTo( unsigned int n );
979
980 // accessing content
981
982 void MacSetString( unsigned int n, const wxString& item );
983 void MacSetClientData( unsigned int n, void * data);
984 wxString MacGetString( unsigned int n) const;
985 void * MacGetClientData( unsigned int) const;
986 unsigned int MacGetCount() const;
987
988 // client data
989
990 wxClientDataType GetClientDataType() const;
991 void SetClientDataType(wxClientDataType clientDataItemsType);
992
993 // pointing back
994
995 wxListBox * GetPeer() const;
996 private :
997 bool m_stringSorted;
998 wxClientDataType m_clientDataItemsType;
999 };
1000
1001 // ============================================================================
1002 // graphics implementation
1003 // ============================================================================
1004
1005 #if wxMAC_USE_CORE_GRAPHICS
1006
1007 class WXDLLEXPORT wxMacCGPath : public wxGraphicPath
1008 {
1009 DECLARE_NO_COPY_CLASS(wxMacCGPath)
1010 public :
1011 wxMacCGPath();
1012 ~wxMacCGPath();
1013
1014 // Starts a new subpath at
1015 void MoveToPoint( wxCoord x1 , wxCoord y1 );
1016 void AddLineToPoint( wxCoord x1 , wxCoord y1 );
1017 void AddQuadCurveToPoint( wxCoord cx1, wxCoord cy1, wxCoord x1, wxCoord y1 );
1018 void AddRectangle( wxCoord x, wxCoord y, wxCoord w, wxCoord h );
1019 void AddCircle( wxCoord x, wxCoord y , wxCoord r );
1020
1021 // closes the current subpath
1022 void CloseSubpath();
1023
1024 CGPathRef GetPath() const;
1025 private :
1026 CGMutablePathRef m_path;
1027 };
1028
1029 class WXDLLEXPORT wxMacCGContext : public wxGraphicContext
1030 {
1031 DECLARE_NO_COPY_CLASS(wxMacCGContext)
1032
1033 public:
1034 wxMacCGContext( CGrafPtr port );
1035 wxMacCGContext( CGContextRef cgcontext );
1036 wxMacCGContext();
1037 virtual ~wxMacCGContext();
1038
1039 virtual void Clip( const wxRegion &region );
1040 virtual void StrokePath( const wxGraphicPath *p );
1041 virtual void DrawPath( const wxGraphicPath *p , int fillStyle = wxWINDING_RULE );
1042 virtual void FillPath( const wxGraphicPath *p , const wxColor &fillColor , int fillStyle = wxWINDING_RULE );
1043
1044 virtual wxGraphicPath* CreatePath();
1045 virtual void SetPen( const wxPen &pen ) ;
1046 virtual void SetBrush( const wxBrush &brush );
1047 CGContextRef GetNativeContext();
1048 void SetNativeContext( CGContextRef cg );
1049 CGPathDrawingMode GetDrawingMode() const { return m_mode; }
1050 private:
1051 CGContextRef m_cgContext;
1052 CGrafPtr m_qdPort;
1053 CGPathDrawingMode m_mode;
1054 wxPen m_pen;
1055 wxBrush m_brush;
1056 };
1057
1058 #endif // wxMAC_USE_CORE_GRAPHICS
1059
1060 #ifdef __WXMAC_OSX__
1061
1062 CGColorSpaceRef wxMacGetGenericRGBColorSpace(void);
1063 void wxMacMemoryBufferReleaseProc(void *info, const void *data, size_t size);
1064
1065 #endif
1066
1067 class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
1068 {
1069 DECLARE_NO_COPY_CLASS(wxBitmapRefData)
1070
1071 friend class WXDLLEXPORT wxIcon;
1072 friend class WXDLLEXPORT wxCursor;
1073 public:
1074 wxBitmapRefData(int width , int height , int depth);
1075 wxBitmapRefData();
1076 virtual ~wxBitmapRefData();
1077
1078 void Free();
1079 bool Ok() const { return m_ok; }
1080 void SetOk( bool isOk) { m_ok = isOk; }
1081
1082 void SetWidth( int width ) { m_width = width; }
1083 void SetHeight( int height ) { m_height = height; }
1084 void SetDepth( int depth ) { m_depth = depth; }
1085
1086 int GetWidth() const { return m_width; }
1087 int GetHeight() const { return m_height; }
1088 int GetDepth() const { return m_depth; }
1089
1090 void *GetRawAccess() const;
1091 void *BeginRawAccess();
1092 void EndRawAccess();
1093
1094 bool HasAlpha() const { return m_hasAlpha; }
1095 void UseAlpha( bool useAlpha );
1096
1097 public:
1098 #if wxUSE_PALETTE
1099 wxPalette m_bitmapPalette;
1100 #endif // wxUSE_PALETTE
1101
1102 wxMask * m_bitmapMask; // Optional mask
1103 #ifdef __WXMAC_OSX__
1104 CGImageRef CGImageCreate() const;
1105 #endif
1106
1107 // returns true if the bitmap has a size that
1108 // can be natively transferred into a true icon
1109 // if no is returned GetIconRef will still produce
1110 // an icon but it will be generated via a PICT and
1111 // rescaled to 16 x 16
1112 bool HasNativeSize();
1113
1114 // caller should increase ref count if needed longer
1115 // than the bitmap exists
1116 IconRef GetIconRef();
1117
1118 // returns a Pict from the bitmap content
1119 PicHandle GetPictHandle();
1120 GWorldPtr GetHBITMAP(GWorldPtr * mask = NULL ) const;
1121 void UpdateAlphaMask() const;
1122
1123 private :
1124 bool Create(int width , int height , int depth);
1125 void Init();
1126
1127 int m_width;
1128 int m_height;
1129 int m_bytesPerRow;
1130 int m_depth;
1131 bool m_hasAlpha;
1132 wxMemoryBuffer m_memBuf;
1133 int m_rawAccessCount;
1134 bool m_ok;
1135 #ifdef __WXMAC_OSX__
1136 mutable CGImageRef m_cgImageRef;
1137 #endif
1138 IconRef m_iconRef;
1139 PicHandle m_pictHandle;
1140 GWorldPtr m_hBitmap;
1141 GWorldPtr m_hMaskBitmap;
1142 wxMemoryBuffer m_maskMemBuf;
1143 int m_maskBytesPerRow;
1144 };
1145
1146 class WXDLLEXPORT wxIconRefData : public wxGDIRefData
1147 {
1148 public:
1149 wxIconRefData();
1150 wxIconRefData( WXHICON );
1151 virtual ~wxIconRefData() { Free(); }
1152
1153 void Init();
1154 virtual void Free();
1155
1156 void SetWidth( int width ) { m_width = width; }
1157 void SetHeight( int height ) { m_height = height; }
1158
1159 int GetWidth() const { return m_width; }
1160 int GetHeight() const { return m_height; }
1161
1162 WXHICON GetHICON() const { return (WXHICON) m_iconRef; }
1163 private :
1164 IconRef m_iconRef;
1165 int m_width;
1166 int m_height;
1167 };
1168
1169 // toplevel.cpp
1170
1171 ControlRef wxMacFindControlUnderMouse( wxTopLevelWindowMac* toplevelWindow, const Point& location , WindowRef window , ControlPartCode *outPart );
1172
1173 #ifdef WORDS_BIGENDIAN
1174 inline Rect* wxMacGetPictureBounds( PicHandle pict , Rect* rect )
1175 {
1176 *rect = (**pict).picFrame;
1177 return rect;
1178 }
1179 #else
1180 inline Rect* wxMacGetPictureBounds( PicHandle pict , Rect* rect )
1181 {
1182 return QDGetPictureBounds( pict , rect );
1183 }
1184 #endif
1185
1186 #endif // wxUSE_GUI
1187
1188 #define wxMAC_DEFINE_PROC_GETTER( UPP , x ) \
1189 UPP Get##x() \
1190 { \
1191 static UPP sHandler = NULL; \
1192 if ( sHandler == NULL ) \
1193 sHandler = New##UPP( x ); \
1194 return sHandler; \
1195 }
1196
1197 //---------------------------------------------------------------------------
1198 // wxMac string conversions
1199 //---------------------------------------------------------------------------
1200
1201 void wxMacSetupConverters();
1202 void wxMacCleanupConverters();
1203
1204 void wxMacStringToPascal( const wxString&from , StringPtr to );
1205 wxString wxMacMakeStringFromPascal( ConstStringPtr from );
1206
1207 // filefn.cpp
1208
1209 wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL );
1210 OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef );
1211 wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname );
1212
1213 #endif
1214 // _WX_PRIVATE_H_