]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/private.h
fixed typo in last commit
[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 wxMacFindFolderNoSeparator(short vRefNum,
200 OSType folderType,
201 Boolean createFolder);
202 WXDLLEXPORT wxString wxMacFindFolder(short vRefNum,
203 OSType folderType,
204 Boolean createFolder);
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 template<> inline EventParamType wxMacGetEventParamType<SInt16>() { return typeSInt16; }
216 template<> inline EventParamType wxMacGetEventParamType<SInt32>() { return typeSInt32; }
217 template<> inline EventParamType wxMacGetEventParamType<UInt32>() { return typeUInt32; }
218 template<> inline EventParamType wxMacGetEventParamType<RGBColor>() { return typeRGBColor; }
219 #if TARGET_API_MAC_OSX
220 template<> inline EventParamType wxMacGetEventParamType<HICommand>() { return typeHICommand; }
221 template<> inline EventParamType wxMacGetEventParamType<HIPoint>() { return typeHIPoint; }
222 template<> inline EventParamType wxMacGetEventParamType<HISize>() { return typeHISize; }
223 template<> inline EventParamType wxMacGetEventParamType<HIRect>() { return typeHIRect; }
224 template<> inline EventParamType wxMacGetEventParamType<void*>() { return typeVoidPtr; }
225 #endif
226 #if TARGET_API_MAC_OSX && ( MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2 )
227 template<> inline EventParamType wxMacGetEventParamType<CFDictionaryRef>() { return typeCFDictionaryRef; }
228 #endif
229 template<> inline EventParamType wxMacGetEventParamType<Collection>() { return typeCollection; }
230 template<> inline EventParamType wxMacGetEventParamType<CGContextRef>() { return typeCGContextRef; }
231 /*
232 These are ambiguous
233 template<> EventParamType wxMacGetEventParamType<GrafPtr>() { return typeGrafPtr; }
234 template<> EventParamType wxMacGetEventParamType<OSStatus>() { return typeOSStatus; }
235 template<> EventParamType wxMacGetEventParamType<CFIndex>() { return typeCFIndex; }
236 template<> EventParamType wxMacGetEventParamType<GWorldPtr>() { return typeGWorldPtr; }
237 */
238
239 class wxMacCarbonEvent
240 {
241
242 public :
243 wxMacCarbonEvent()
244 {
245 m_eventRef = 0;
246 m_release = false;
247 }
248
249 wxMacCarbonEvent( EventRef event , bool release = false )
250 {
251 m_eventRef = event;
252 m_release = release;
253 }
254
255 wxMacCarbonEvent(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone)
256 {
257 m_eventRef = NULL;
258 verify_noerr( MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef) );
259 m_release = true;
260 }
261
262 ~wxMacCarbonEvent()
263 {
264 if ( m_release )
265 ReleaseEvent( m_eventRef );
266 }
267
268 OSStatus Create(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone)
269 {
270 verify( (m_eventRef == NULL) || m_release );
271 if ( m_eventRef && m_release )
272 {
273 ReleaseEvent( m_eventRef );
274 m_release = false;
275 m_eventRef = NULL;
276 }
277 OSStatus err = MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef);
278 if ( err == noErr )
279 m_release = true;
280 return err;
281 }
282
283 OSStatus GetParameter( EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData);
284
285 template <typename T> OSStatus GetParameter( EventParamName inName, EventParamType type , T *data )
286 {
287 return GetParameter( inName, type , sizeof( T ) , data );
288 }
289 template <typename T> OSStatus GetParameter( EventParamName inName, T *data )
290 {
291 return GetParameter<T>( inName, wxMacGetEventParamType<T>() , data );
292 }
293
294 template <typename T> T GetParameter( EventParamName inName )
295 {
296 T value;
297 verify_noerr( GetParameter<T>( inName, &value ) );
298 return value;
299 }
300 template <typename T> T GetParameter( EventParamName inName, EventParamType inDesiredType )
301 {
302 T value;
303 verify_noerr( GetParameter<T>( inName, inDesiredType , &value ) );
304 return value;
305 }
306
307 OSStatus SetParameter( EventParamName inName, EventParamType inType, UInt32 inSize, const void * inData);
308 template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T *data )
309 {
310 return SetParameter( inName, inDesiredType , sizeof( T ) , data );
311 }
312 template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T& data )
313 {
314 return SetParameter<T>( inName, inDesiredType , &data );
315 }
316 template <typename T> OSStatus SetParameter( EventParamName inName, const T *data )
317 {
318 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , data );
319 }
320 template <typename T> OSStatus SetParameter( EventParamName inName, const T& data )
321 {
322 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , &data );
323 }
324 UInt32 GetClass()
325 {
326 return ::GetEventClass( m_eventRef );
327 }
328 UInt32 GetKind()
329 {
330 return ::GetEventKind( m_eventRef );
331 }
332 EventTime GetTime()
333 {
334 return ::GetEventTime( m_eventRef );
335 }
336 UInt32 GetTicks()
337 {
338 return EventTimeToTicks( GetTime() );
339 }
340 OSStatus SetCurrentTime( )
341 {
342 return ::SetEventTime( m_eventRef , GetCurrentEventTime() );
343 }
344 OSStatus SetTime( EventTime when )
345 {
346 return ::SetEventTime( m_eventRef , when );
347 }
348 operator EventRef () { return m_eventRef; }
349
350 bool IsValid() { return m_eventRef != 0; }
351 protected :
352 EventRef m_eventRef;
353 bool m_release;
354 };
355
356 //
357 // helper class for allocating and deallocating Universal Proc Ptrs
358 //
359
360 template <typename procType, typename uppType , uppType (*newUPP)(procType) , void (*disposeUPP)(uppType) > class wxMacUPP
361 {
362 public :
363 wxMacUPP( procType proc )
364 {
365 m_upp = NULL;
366 m_upp = (*newUPP)( NULL );
367 }
368 ~wxMacUPP()
369 {
370 if ( m_upp )
371 disposeUPP( m_upp );
372 }
373 operator uppType() { return m_upp; }
374 private :
375 uppType m_upp;
376 };
377
378 typedef wxMacUPP<NMProcPtr,NMUPP,NewNMUPP,DisposeNMUPP> wxMacNMUPP;
379
380 template <typename refType> class wxMacCFRefHolder
381 {
382 public :
383 wxMacCFRefHolder()
384 : m_ref(NULL) , m_release(false)
385 {
386 }
387
388 wxMacCFRefHolder( refType ref , bool release = true )
389 : m_ref(ref) , m_release(release)
390 {
391 }
392
393 ~wxMacCFRefHolder()
394 {
395 Release();
396 }
397
398 void Release()
399 {
400 if ( m_release && m_ref != NULL )
401 CFRelease( m_ref );
402 m_ref = NULL;
403 }
404
405 refType Detach()
406 {
407 refType val = m_ref;
408 m_release = false;
409 m_ref = NULL;
410 return val;
411 }
412
413 void Set( refType ref , bool release = true )
414 {
415 Release();
416 m_release = release;
417 m_ref = ref;
418 }
419
420 operator refType () const { return m_ref; }
421
422 private :
423 refType m_ref;
424 bool m_release;
425
426 DECLARE_NO_COPY_CLASS( wxMacCFRefHolder )
427 };
428
429 #if wxUSE_GUI
430
431 #include "wx/listbox.h"
432
433 /*
434 GWorldPtr wxMacCreateGWorld( int width , int height , int depth );
435 void wxMacDestroyGWorld( GWorldPtr gw );
436 PicHandle wxMacCreatePict( GWorldPtr gw , GWorldPtr mask = NULL );
437 CIconHandle wxMacCreateCIcon(GWorldPtr image , GWorldPtr mask , short dstDepth , short iconSize );
438 void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue );
439 CTabHandle wxMacCreateColorTable( int numColors );
440 */
441 void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType = 0 );
442 void wxMacReleaseBitmapButton( ControlButtonContentInfo*info );
443
444 #define MAC_WXCOLORREF(a) (*((RGBColor*)&(a)))
445 #define MAC_WXHBITMAP(a) (GWorldPtr(a))
446 #define MAC_WXHMETAFILE(a) (PicHandle(a))
447 #define MAC_WXHICON(a) (IconRef(a))
448 #define MAC_WXHCURSOR(a) (CursHandle(a))
449 #define MAC_WXHRGN(a) (RgnHandle(a))
450 #define MAC_WXHWND(a) (WindowPtr(a))
451 #define MAC_WXRECPTR(a) ((Rect*)a)
452 #define MAC_WXPOINTPTR(a) ((Point*)a)
453 #define MAC_WXHMENU(a) ((MenuHandle)a)
454
455 struct wxOpaqueWindowRef
456 {
457 wxOpaqueWindowRef( WindowRef ref ) { m_data = ref; }
458 operator WindowRef() { return m_data; }
459 private :
460 WindowRef m_data;
461 };
462
463 void wxMacRectToNative( const wxRect *wx , Rect *n );
464 void wxMacNativeToRect( const Rect *n , wxRect* wx );
465 void wxMacPointToNative( const wxPoint* wx , Point *n );
466 void wxMacNativeToPoint( const Point *n , wxPoint* wx );
467
468 wxWindow * wxFindControlFromMacControl(ControlRef inControl );
469 wxTopLevelWindowMac* wxFindWinFromMacWindow( WindowRef inWindow );
470 wxMenu* wxFindMenuFromMacMenu(MenuRef inMenuRef);
471
472 int wxMacCommandToId( UInt32 macCommandId );
473 UInt32 wxIdToMacCommand( int wxId );
474 wxMenu* wxFindMenuFromMacCommand( const HICommand &macCommandId , wxMenuItem* &item );
475
476 extern wxWindow* g_MacLastWindow;
477 pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data );
478 Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin = true );
479
480 ControlActionUPP GetwxMacLiveScrollbarActionProc();
481
482 class wxMacControl
483 {
484 public :
485 wxMacControl( wxWindow* peer , bool isRootControl = false );
486 wxMacControl( wxWindow* peer , ControlRef control );
487 wxMacControl( wxWindow* peer , WXWidget control );
488 virtual ~wxMacControl();
489
490 void Init();
491
492 virtual void Dispose();
493
494 bool Ok() const { return GetControlRef() != NULL; }
495
496 void SetReferenceInNativeControl();
497 static wxMacControl* GetReferenceFromNativeControl(ControlRef control);
498
499 virtual ControlRef * GetControlRefAddr() { return &m_controlRef; }
500 virtual ControlRef GetControlRef() const { return m_controlRef; }
501
502 virtual void SetReference( SInt32 data );
503 /*
504 void operator= (ControlRef c) { m_controlRef = c; }
505 operator ControlRef () { return m_controlRef; }
506 operator ControlRef * () { return &m_controlRef; }
507 */
508 // accessing data and values
509
510 virtual OSStatus SetData( ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData );
511 virtual OSStatus GetData( ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const;
512 virtual OSStatus GetDataSize( ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const;
513 virtual OSStatus SendEvent( EventRef ref , OptionBits inOptions = 0 );
514 virtual OSStatus SendHICommand( HICommand &command , OptionBits inOptions = 0 );
515
516 virtual OSStatus SendHICommand( UInt32 commandID , OptionBits inOptions = 0 );
517
518 virtual SInt32 GetValue() const;
519 virtual SInt32 GetMaximum() const;
520 virtual SInt32 GetMinimum() const;
521
522 virtual void SetValue( SInt32 v );
523 virtual void SetMinimum( SInt32 v );
524 virtual void SetMaximum( SInt32 v );
525
526 virtual void SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum );
527 virtual void SetRange( SInt32 minimum , SInt32 maximum );
528
529 virtual OSStatus SetFocus( ControlFocusPart focusPart );
530 virtual bool HasFocus() const;
531 virtual bool NeedsFocusRect() const;
532 virtual void SetNeedsFocusRect( bool needs );
533
534 // templated helpers
535
536 Size GetDataSize( ControlPartCode inPartCode , ResType inTag ) const
537 {
538 Size sz;
539 verify_noerr( GetDataSize( inPartCode , inTag , &sz ) );
540 return sz;
541 }
542 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T *data )
543 {
544 return SetData( inPartCode , inTag , sizeof( T ) , data );
545 }
546 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T& data )
547 {
548 return SetData( inPartCode , inTag , sizeof( T ) , &data );
549 }
550 template <typename T> OSStatus SetData( ResType inTag , const T *data )
551 {
552 return SetData( kControlEntireControl , inTag , sizeof( T ) , data );
553 }
554 template <typename T> OSStatus SetData( ResType inTag , const T& data )
555 {
556 return SetData( kControlEntireControl , inTag , sizeof( T ) , &data );
557 }
558 template <typename T> OSStatus GetData( ControlPartCode inPartCode , ResType inTag , T *data ) const
559 {
560 Size dummy;
561 return GetData( inPartCode , inTag , sizeof( T ) , data , &dummy );
562 }
563 template <typename T> T GetData( ControlPartCode inPartCode , ResType inTag ) const
564 {
565 T value;
566 OSStatus err = GetData<T>( inPartCode , inTag , &value );
567
568 wxASSERT_MSG( err == noErr,
569 wxString::Format(wxT("GetData Failed for Part [%i] and Tag [%i]"),
570 inPartCode, (int)inTag) );
571 return value;
572 }
573 template <typename T> OSStatus GetData( ResType inTag , T *data ) const
574 {
575 Size dummy;
576 return GetData( kControlEntireControl , inTag , sizeof( T ) , data , &dummy );
577 }
578 template <typename T> T GetData( ResType inTag ) const
579 {
580 return GetData<T>( kControlEntireControl , inTag );
581 }
582
583 // Flash the control for the specified amount of time
584 virtual void Flash( ControlPartCode part , UInt32 ticks = 8 );
585
586 virtual void VisibilityChanged( bool shown );
587 virtual void SuperChangedPosition();
588
589
590 virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle );
591 virtual void SetBackground( const wxBrush &brush );
592 virtual ControlPartCode HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers );
593 void SetActionProc( ControlActionUPP actionProc );
594 void SetViewSize( SInt32 viewSize );
595 SInt32 GetViewSize() const;
596
597 virtual bool IsVisible() const;
598 virtual void SetVisibility( bool visible , bool redraw );
599 virtual bool IsEnabled() const;
600 virtual bool IsActive() const;
601 virtual void Enable( bool enable );
602
603 // invalidates this control and all children
604 virtual void InvalidateWithChildren();
605 virtual void SetDrawingEnabled( bool enable );
606 #ifdef __WXMAC_OSX__
607 virtual bool GetNeedsDisplay() const;
608 #endif
609 // where is in native window relative coordinates
610 virtual void SetNeedsDisplay( RgnHandle where );
611 // where is in native window relative coordinates
612 virtual void SetNeedsDisplay( Rect* where = NULL );
613
614 // if rect = NULL, entire view
615 virtual void ScrollRect( wxRect *rect , int dx , int dy );
616
617 // in native parent window relative coordinates
618 virtual void GetRect( Rect *r );
619
620 // in native parent window relative coordinates
621 virtual void SetRect( Rect *r );
622
623 virtual void GetRectInWindowCoords( Rect *r );
624 virtual void GetBestRect( Rect *r );
625 virtual void SetLabel( const wxString &title );
626 // converts from Toplevel-Content relative to local
627 static void Convert( wxPoint *pt , wxMacControl *convert , wxMacControl *to );
628
629 virtual void GetFeatures( UInt32 *features );
630 virtual OSStatus GetRegion( ControlPartCode partCode , RgnHandle region );
631 virtual OSStatus SetZOrder( bool above , wxMacControl* other );
632
633 bool IsCompositing() { return m_isCompositing; }
634 bool IsRootControl() { return m_isRootControl; }
635
636 wxWindow* GetPeer() const
637 {
638 return m_peer;
639 }
640
641 // to be moved into a tab control class
642
643 virtual OSStatus SetTabEnabled( SInt16 tabNo , bool enable );
644 protected :
645 ControlRef m_controlRef;
646 wxFont m_font;
647 long m_windowStyle;
648 wxWindow* m_peer;
649 bool m_needsFocusRect;
650 bool m_isCompositing;
651 bool m_isRootControl;
652 };
653
654 // ============================================================================
655 // DataBrowser Wrapper
656 // ============================================================================
657 //
658 // basing on DataBrowserItemIDs
659 //
660
661 class wxMacDataBrowserControl : public wxMacControl
662 {
663 public :
664 wxMacDataBrowserControl( wxWindow* peer, const wxPoint& pos, const wxSize& size, long style);
665
666 OSStatus SetCallbacks( const DataBrowserCallbacks *callbacks );
667
668 OSStatus GetItemCount( DataBrowserItemID container,
669 Boolean recurse,
670 DataBrowserItemState state,
671 UInt32 *numItems) const;
672
673 OSStatus GetItems( DataBrowserItemID container,
674 Boolean recurse,
675 DataBrowserItemState state,
676 Handle items) const;
677
678
679 OSStatus AddColumn( DataBrowserListViewColumnDesc *columnDesc,
680 DataBrowserTableViewColumnIndex position );
681
682 OSStatus AutoSizeColumns();
683
684 OSStatus SetHasScrollBars( bool horiz, bool vert );
685 OSStatus SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle );
686
687 OSStatus SetHeaderButtonHeight( UInt16 height );
688 OSStatus GetHeaderButtonHeight( UInt16 *height );
689
690 OSStatus UpdateItems( DataBrowserItemID container, UInt32 numItems,
691 const DataBrowserItemID *items,
692 DataBrowserPropertyID preSortProperty,
693 DataBrowserPropertyID propertyID ) const;
694
695 OSStatus AddItems( DataBrowserItemID container, UInt32 numItems,
696 const DataBrowserItemID *items,
697 DataBrowserPropertyID preSortProperty );
698 OSStatus RemoveItems( DataBrowserItemID container, UInt32 numItems,
699 const DataBrowserItemID *items,
700 DataBrowserPropertyID preSortProperty );
701 OSStatus RevealItem( DataBrowserItemID item,
702 DataBrowserPropertyID propertyID,
703 DataBrowserRevealOptions options ) const;
704
705 OSStatus SetSelectionFlags( DataBrowserSelectionFlags );
706 OSStatus GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const;
707 bool IsItemSelected( DataBrowserItemID item ) const;
708 OSStatus SetSelectedItems( UInt32 numItems,
709 const DataBrowserItemID *items,
710 DataBrowserSetOption operation );
711
712 OSStatus GetItemID( DataBrowserTableViewRowIndex row,
713 DataBrowserItemID * item ) const;
714 OSStatus GetItemRow( DataBrowserItemID item,
715 DataBrowserTableViewRowIndex * row ) const;
716
717 OSStatus SetDefaultRowHeight( UInt16 height );
718 OSStatus GetDefaultRowHeight( UInt16 * height ) const;
719
720 OSStatus SetRowHeight( DataBrowserItemID item , UInt16 height);
721 OSStatus GetRowHeight( DataBrowserItemID item , UInt16 *height) const;
722
723 OSStatus GetColumnWidth( DataBrowserPropertyID column , UInt16 *width ) const;
724 OSStatus SetColumnWidth( DataBrowserPropertyID column , UInt16 width );
725
726 OSStatus GetDefaultColumnWidth( UInt16 *width ) const;
727 OSStatus SetDefaultColumnWidth( UInt16 width );
728
729 OSStatus GetColumnCount( UInt32* numColumns) const;
730
731 OSStatus GetColumnPosition( DataBrowserPropertyID column, UInt32 *position) const;
732 OSStatus SetColumnPosition( DataBrowserPropertyID column, UInt32 position);
733
734 OSStatus GetScrollPosition( UInt32 *top , UInt32 *left ) const;
735 OSStatus SetScrollPosition( UInt32 top , UInt32 left );
736
737 OSStatus GetSortProperty( DataBrowserPropertyID *column ) const;
738 OSStatus SetSortProperty( DataBrowserPropertyID column );
739
740 OSStatus GetSortOrder( DataBrowserSortOrder *order ) const;
741 OSStatus SetSortOrder( DataBrowserSortOrder order );
742
743 OSStatus GetPropertyFlags( DataBrowserPropertyID property, DataBrowserPropertyFlags *flags ) const;
744 OSStatus SetPropertyFlags( DataBrowserPropertyID property, DataBrowserPropertyFlags flags );
745
746 OSStatus GetHeaderDesc( DataBrowserPropertyID property, DataBrowserListViewHeaderDesc *desc ) const;
747 OSStatus SetHeaderDesc( DataBrowserPropertyID property, DataBrowserListViewHeaderDesc *desc );
748
749 OSStatus SetDisclosureColumn( DataBrowserPropertyID property , Boolean expandableRows );
750 protected :
751
752 static pascal void DataBrowserItemNotificationProc(
753 ControlRef browser,
754 DataBrowserItemID itemID,
755 DataBrowserItemNotification message,
756 DataBrowserItemDataRef itemData );
757
758 virtual void ItemNotification(
759 DataBrowserItemID itemID,
760 DataBrowserItemNotification message,
761 DataBrowserItemDataRef itemData) = 0;
762
763 static pascal OSStatus DataBrowserGetSetItemDataProc(
764 ControlRef browser,
765 DataBrowserItemID itemID,
766 DataBrowserPropertyID property,
767 DataBrowserItemDataRef itemData,
768 Boolean changeValue );
769
770 virtual OSStatus GetSetItemData(
771 DataBrowserItemID itemID,
772 DataBrowserPropertyID property,
773 DataBrowserItemDataRef itemData,
774 Boolean changeValue ) = 0;
775
776 static pascal Boolean DataBrowserCompareProc(
777 ControlRef browser,
778 DataBrowserItemID itemOneID,
779 DataBrowserItemID itemTwoID,
780 DataBrowserPropertyID sortProperty);
781
782 virtual Boolean CompareItems(DataBrowserItemID itemOneID,
783 DataBrowserItemID itemTwoID,
784 DataBrowserPropertyID sortProperty) = 0;
785 };
786
787 // ============================================================================
788 // Higher-level Databrowser
789 // ============================================================================
790 //
791 // basing on data item objects
792 //
793
794 // forward decl
795
796 class wxMacDataItemBrowserControl;
797
798 // base class for databrowser items
799
800 class wxMacDataItem
801 {
802 public :
803 wxMacDataItem();
804 virtual ~wxMacDataItem();
805
806 virtual bool IsLessThan(wxMacDataItemBrowserControl *owner ,
807 const wxMacDataItem*,
808 DataBrowserPropertyID property) const;
809
810 // returns true if access was successful, otherwise false
811 virtual OSStatus GetSetData(wxMacDataItemBrowserControl *owner ,
812 DataBrowserPropertyID property,
813 DataBrowserItemDataRef itemData,
814 bool changeValue );
815
816 virtual void Notification(wxMacDataItemBrowserControl *owner ,
817 DataBrowserItemNotification message,
818 DataBrowserItemDataRef itemData ) const;
819 };
820
821 typedef wxMacDataItem* wxMacDataItemPtr;
822 const wxMacDataItemPtr wxMacDataBrowserRootContainer = NULL;
823
824 WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxMacDataItemPtr, wxArrayMacDataItemPtr, class WXDLLIMPEXP_CORE);
825
826 class wxMacDataItemBrowserControl : public wxMacDataBrowserControl
827 {
828 public :
829 wxMacDataItemBrowserControl( wxWindow* peer , const wxPoint& pos, const wxSize& size, long style);
830
831 unsigned int GetItemCount(const wxMacDataItem* container, bool recurse , DataBrowserItemState state) const;
832 void GetItems(const wxMacDataItem* container, bool recurse ,
833 DataBrowserItemState state, wxArrayMacDataItemPtr &items ) const;
834
835 unsigned int GetLineFromItem(const wxMacDataItem *item) const;
836 wxMacDataItem * GetItemFromLine(unsigned int n) const;
837
838 void UpdateItem(const wxMacDataItem *container, const wxMacDataItem *item,
839 DataBrowserPropertyID property) const;
840 void UpdateItems(const wxMacDataItem *container, wxArrayMacDataItemPtr &items,
841 DataBrowserPropertyID property) const;
842
843 void AddItem(wxMacDataItem *container, wxMacDataItem *item);
844 void AddItems(wxMacDataItem *container, wxArrayMacDataItemPtr &items );
845
846 void RemoveAllItems(wxMacDataItem *container);
847 void RemoveItem(wxMacDataItem *container, wxMacDataItem* item);
848 void RemoveItems(wxMacDataItem *container, wxArrayMacDataItemPtr &items);
849
850 void SetSelectedItem( wxMacDataItem* item , DataBrowserSetOption option);
851 void SetSelectedItems( wxArrayMacDataItemPtr &items , DataBrowserSetOption option);
852 void SetSelectedAllItems( DataBrowserSetOption option);
853 Boolean IsItemSelected( const wxMacDataItem* item) const;
854
855 void RevealItem( wxMacDataItem* item, DataBrowserRevealOptions options);
856
857 void GetSelectionAnchor( wxMacDataItemPtr* first , wxMacDataItemPtr* last) const;
858
859 // item aware methods, to be used in subclasses
860
861 virtual Boolean CompareItems(const wxMacDataItem* itemOneID,
862 const wxMacDataItem* itemTwoID,
863 DataBrowserPropertyID sortProperty);
864
865 virtual OSStatus GetSetItemData(wxMacDataItem* itemID,
866 DataBrowserPropertyID property,
867 DataBrowserItemDataRef itemData,
868 Boolean changeValue );
869
870 virtual void ItemNotification(
871 const wxMacDataItem* itemID,
872 DataBrowserItemNotification message,
873 DataBrowserItemDataRef itemData);
874
875 // as we are getting the same events for human and API selection we have to suppress
876 // events in the latter case, since this will be used from many subclasses we keep it here
877
878 bool IsSelectionSuppressed() const { return m_suppressSelection; }
879 bool SuppressSelection( bool suppress );
880
881 protected:
882 // ID aware base methods, should be 'final' ie not changed in subclasses
883
884 virtual Boolean CompareItems(DataBrowserItemID itemOneID,
885 DataBrowserItemID itemTwoID,
886 DataBrowserPropertyID sortProperty);
887
888 virtual OSStatus GetSetItemData(DataBrowserItemID itemID,
889 DataBrowserPropertyID property,
890 DataBrowserItemDataRef itemData,
891 Boolean changeValue );
892
893 virtual void ItemNotification(
894 DataBrowserItemID itemID,
895 DataBrowserItemNotification message,
896 DataBrowserItemDataRef itemData);
897
898 private :
899
900 bool m_suppressSelection;
901 };
902
903 class wxMacDataItemBrowserSelectionSuppressor
904 {
905 public :
906 wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl *browser);
907 ~wxMacDataItemBrowserSelectionSuppressor();
908
909 private :
910
911 bool m_former;
912 wxMacDataItemBrowserControl* m_browser;
913 };
914
915 // ============================================================================
916 // platform listbox implementation
917 // ============================================================================
918 //
919 // exposed for reuse in wxCheckListBox
920
921 class wxMacListBoxItem : public wxMacDataItem
922 {
923 public :
924 wxMacListBoxItem();
925
926 virtual ~wxMacListBoxItem();
927
928 void SetLabel( const wxString& str);
929 const wxString& GetLabel() const;
930
931 virtual bool IsLessThan(wxMacDataItemBrowserControl *owner ,
932 const wxMacDataItem* rhs,
933 DataBrowserPropertyID sortProperty) const;
934
935 virtual OSStatus GetSetData( wxMacDataItemBrowserControl *owner ,
936 DataBrowserPropertyID property,
937 DataBrowserItemDataRef itemData,
938 bool changeValue );
939
940 virtual void Notification(wxMacDataItemBrowserControl *owner ,
941 DataBrowserItemNotification message,
942 DataBrowserItemDataRef itemData ) const;
943
944 void SetOrder( SInt32 order );
945 SInt32 GetOrder() const;
946
947 void SetData( void* data);
948 void* GetData() const;
949
950 private :
951 wxString m_label;
952 wxMacCFStringHolder m_cfLabel;
953 void * m_data;
954 SInt32 m_order;
955 };
956
957 class wxMacDataBrowserListControl : public wxMacDataItemBrowserControl , public wxMacListControl
958 {
959 public:
960 wxMacDataBrowserListControl( wxListBox *peer, const wxPoint& pos, const wxSize& size, long style );
961 ~wxMacDataBrowserListControl();
962
963 // create a list item (can be a subclass of wxMacListBoxItem)
964
965 virtual wxMacListBoxItem* CreateItem();
966
967 // add and remove
968
969 void MacDelete( unsigned int n );
970 void MacInsert( unsigned int n, const wxString& item );
971 void MacInsert( unsigned int n, const wxArrayString& items );
972 int MacAppend( const wxString& item );
973 void MacClear();
974
975 // selecting
976
977 void MacDeselectAll();
978 void MacSetSelection( unsigned int n, bool select );
979 int MacGetSelection() const;
980 int MacGetSelections( wxArrayInt& aSelections ) const;
981 bool MacIsSelected( unsigned int n ) const;
982
983 // display
984
985 void MacScrollTo( unsigned int n );
986
987 // accessing content
988
989 void MacSetString( unsigned int n, const wxString& item );
990 void MacSetClientData( unsigned int n, void * data);
991 wxString MacGetString( unsigned int n) const;
992 void * MacGetClientData( unsigned int) const;
993 unsigned int MacGetCount() const;
994
995 // client data
996
997 wxClientDataType GetClientDataType() const;
998 void SetClientDataType(wxClientDataType clientDataItemsType);
999
1000 // pointing back
1001
1002 wxListBox * GetPeer() const;
1003 private :
1004 bool m_stringSorted;
1005 wxClientDataType m_clientDataItemsType;
1006 };
1007
1008 // ============================================================================
1009 // graphics implementation
1010 // ============================================================================
1011
1012 #if wxMAC_USE_CORE_GRAPHICS
1013
1014 class WXDLLEXPORT wxMacCGPath : public wxGraphicPath
1015 {
1016 DECLARE_NO_COPY_CLASS(wxMacCGPath)
1017 public :
1018 wxMacCGPath();
1019 ~wxMacCGPath();
1020
1021 // Starts a new subpath at
1022 void MoveToPoint( wxCoord x1 , wxCoord y1 );
1023 void AddLineToPoint( wxCoord x1 , wxCoord y1 );
1024 void AddQuadCurveToPoint( wxCoord cx1, wxCoord cy1, wxCoord x1, wxCoord y1 );
1025 void AddRectangle( wxCoord x, wxCoord y, wxCoord w, wxCoord h );
1026 void AddCircle( wxCoord x, wxCoord y , wxCoord r );
1027
1028 // closes the current subpath
1029 void CloseSubpath();
1030
1031 CGPathRef GetPath() const;
1032 private :
1033 CGMutablePathRef m_path;
1034 };
1035
1036 class WXDLLEXPORT wxMacCGContext : public wxGraphicContext
1037 {
1038 DECLARE_NO_COPY_CLASS(wxMacCGContext)
1039
1040 public:
1041 wxMacCGContext( CGrafPtr port );
1042 wxMacCGContext( CGContextRef cgcontext );
1043 wxMacCGContext();
1044 ~wxMacCGContext();
1045
1046 virtual void Clip( const wxRegion &region );
1047 virtual void StrokePath( const wxGraphicPath *p );
1048 virtual void DrawPath( const wxGraphicPath *p , int fillStyle = wxWINDING_RULE );
1049 virtual void FillPath( const wxGraphicPath *p , const wxColor &fillColor , int fillStyle = wxWINDING_RULE );
1050
1051 virtual wxGraphicPath* CreatePath();
1052 virtual void SetPen( const wxPen &pen ) ;
1053 virtual void SetBrush( const wxBrush &brush );
1054 CGContextRef GetNativeContext();
1055 void SetNativeContext( CGContextRef cg );
1056 CGPathDrawingMode GetDrawingMode() const { return m_mode; }
1057 private:
1058 CGContextRef m_cgContext;
1059 CGrafPtr m_qdPort;
1060 CGPathDrawingMode m_mode;
1061 wxPen m_pen;
1062 wxBrush m_brush;
1063 };
1064
1065 #endif // wxMAC_USE_CORE_GRAPHICS
1066
1067 #ifdef __WXMAC_OSX__
1068
1069 CGColorSpaceRef wxMacGetGenericRGBColorSpace(void);
1070 void wxMacMemoryBufferReleaseProc(void *info, const void *data, size_t size);
1071
1072 #endif
1073
1074 class WXDLLEXPORT wxBitmapRefData: public wxGDIRefData
1075 {
1076 DECLARE_NO_COPY_CLASS(wxBitmapRefData)
1077
1078 friend class WXDLLEXPORT wxIcon;
1079 friend class WXDLLEXPORT wxCursor;
1080 public:
1081 wxBitmapRefData(int width , int height , int depth);
1082 wxBitmapRefData();
1083 ~wxBitmapRefData();
1084
1085 void Free();
1086 bool Ok() const { return m_ok; }
1087 void SetOk( bool isOk) { m_ok = isOk; }
1088
1089 void SetWidth( int width ) { m_width = width; }
1090 void SetHeight( int height ) { m_height = height; }
1091 void SetDepth( int depth ) { m_depth = depth; }
1092
1093 int GetWidth() const { return m_width; }
1094 int GetHeight() const { return m_height; }
1095 int GetDepth() const { return m_depth; }
1096
1097 void *GetRawAccess() const;
1098 void *BeginRawAccess();
1099 void EndRawAccess();
1100
1101 bool HasAlpha() const { return m_hasAlpha; }
1102 void UseAlpha( bool useAlpha );
1103
1104 public:
1105 #if wxUSE_PALETTE
1106 wxPalette m_bitmapPalette;
1107 #endif // wxUSE_PALETTE
1108
1109 wxMask * m_bitmapMask; // Optional mask
1110 #ifdef __WXMAC_OSX__
1111 CGImageRef CGImageCreate() const;
1112 #endif
1113
1114 // returns true if the bitmap has a size that
1115 // can be natively transferred into a true icon
1116 // if no is returned GetIconRef will still produce
1117 // an icon but it will be generated via a PICT and
1118 // rescaled to 16 x 16
1119 bool HasNativeSize();
1120
1121 // caller should increase ref count if needed longer
1122 // than the bitmap exists
1123 IconRef GetIconRef();
1124
1125 // returns a Pict from the bitmap content
1126 PicHandle GetPictHandle();
1127 GWorldPtr GetHBITMAP(GWorldPtr * mask = NULL ) const;
1128 void UpdateAlphaMask() const;
1129
1130 private :
1131 bool Create(int width , int height , int depth);
1132 void Init();
1133
1134 int m_width;
1135 int m_height;
1136 int m_bytesPerRow;
1137 int m_depth;
1138 bool m_hasAlpha;
1139 wxMemoryBuffer m_memBuf;
1140 int m_rawAccessCount;
1141 bool m_ok;
1142 #ifdef __WXMAC_OSX__
1143 mutable CGImageRef m_cgImageRef;
1144 #endif
1145 IconRef m_iconRef;
1146 PicHandle m_pictHandle;
1147 GWorldPtr m_hBitmap;
1148 GWorldPtr m_hMaskBitmap;
1149 wxMemoryBuffer m_maskMemBuf;
1150 int m_maskBytesPerRow;
1151 };
1152
1153 class WXDLLEXPORT wxIconRefData : public wxGDIRefData
1154 {
1155 public:
1156 wxIconRefData();
1157 wxIconRefData( WXHICON );
1158 virtual ~wxIconRefData() { Free(); }
1159
1160 void Init();
1161 virtual void Free();
1162
1163 void SetWidth( int width ) { m_width = width; }
1164 void SetHeight( int height ) { m_height = height; }
1165
1166 int GetWidth() const { return m_width; }
1167 int GetHeight() const { return m_height; }
1168
1169 WXHICON GetHICON() const { return (WXHICON) m_iconRef; }
1170 private :
1171 IconRef m_iconRef;
1172 int m_width;
1173 int m_height;
1174 };
1175
1176 // toplevel.cpp
1177
1178 ControlRef wxMacFindControlUnderMouse( wxTopLevelWindowMac* toplevelWindow, const Point& location , WindowRef window , ControlPartCode *outPart );
1179
1180 #ifdef WORDS_BIGENDIAN
1181 inline Rect* wxMacGetPictureBounds( PicHandle pict , Rect* rect )
1182 {
1183 *rect = (**pict).picFrame;
1184 return rect;
1185 }
1186 #else
1187 inline Rect* wxMacGetPictureBounds( PicHandle pict , Rect* rect )
1188 {
1189 return QDGetPictureBounds( pict , rect );
1190 }
1191 #endif
1192
1193 #endif // wxUSE_GUI
1194
1195 #define wxMAC_DEFINE_PROC_GETTER( UPP , x ) \
1196 UPP Get##x() \
1197 { \
1198 static UPP sHandler = NULL; \
1199 if ( sHandler == NULL ) \
1200 sHandler = New##UPP( x ); \
1201 return sHandler; \
1202 }
1203
1204 //---------------------------------------------------------------------------
1205 // wxMac string conversions
1206 //---------------------------------------------------------------------------
1207
1208 void wxMacSetupConverters();
1209 void wxMacCleanupConverters();
1210
1211 void wxMacStringToPascal( const wxString&from , StringPtr to );
1212 wxString wxMacMakeStringFromPascal( ConstStringPtr from );
1213
1214 // filefn.cpp
1215
1216 wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL );
1217 OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef );
1218 wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname );
1219
1220 #endif
1221 // _WX_PRIVATE_H_