]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/private.h
mac cleanup
[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 #include <Carbon/Carbon.h>
20
21 #include "wx/mac/corefoundation/cfstring.h"
22 #include "wx/mac/corefoundation/cfdataref.h"
23
24 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
25 typedef UInt32 URefCon;
26 typedef SInt32 SRefCon;
27 #endif
28
29 #if wxUSE_GUI
30
31 #include "wx/listbox.h"
32
33 #ifndef __LP64__
34
35 class wxMacPortStateHelper
36 {
37 DECLARE_NO_COPY_CLASS(wxMacPortStateHelper)
38
39 public:
40 wxMacPortStateHelper( GrafPtr newport);
41 wxMacPortStateHelper();
42 ~wxMacPortStateHelper();
43
44 void Setup( GrafPtr newport );
45 void Clear();
46 bool IsCleared() { return m_clip == NULL; }
47 GrafPtr GetCurrentPort() { return m_currentPort; }
48
49 private:
50 GrafPtr m_currentPort;
51 GrafPtr m_oldPort;
52 RgnHandle m_clip;
53 ThemeDrawingState m_drawingState;
54 short m_textFont;
55 short m_textSize;
56 short m_textStyle;
57 short m_textMode;
58 };
59
60 class WXDLLEXPORT wxMacPortSaver
61 {
62 DECLARE_NO_COPY_CLASS(wxMacPortSaver)
63
64 public:
65 wxMacPortSaver( GrafPtr port );
66 ~wxMacPortSaver();
67 private :
68 GrafPtr m_port;
69 };
70
71 class WXDLLEXPORT wxMacPortSetter
72 {
73 DECLARE_NO_COPY_CLASS(wxMacPortSetter)
74
75 public:
76 wxMacPortSetter( const wxDC* dc );
77 ~wxMacPortSetter();
78 private:
79 wxMacPortStateHelper m_ph;
80 const wxDC* m_dc;
81 };
82
83 /*
84 Clips to the visible region of a control within the current port
85 */
86
87 class WXDLLEXPORT wxMacWindowClipper : public wxMacPortSaver
88 {
89 DECLARE_NO_COPY_CLASS(wxMacWindowClipper)
90
91 public:
92 wxMacWindowClipper( const wxWindow* win );
93 ~wxMacWindowClipper();
94 private:
95 GrafPtr m_newPort;
96 RgnHandle m_formerClip;
97 RgnHandle m_newClip;
98 };
99
100 class WXDLLEXPORT wxMacWindowStateSaver : public wxMacWindowClipper
101 {
102 DECLARE_NO_COPY_CLASS(wxMacWindowStateSaver)
103
104 public:
105 wxMacWindowStateSaver( const wxWindow* win );
106 ~wxMacWindowStateSaver();
107 private:
108 GrafPtr m_newPort;
109 ThemeDrawingState m_themeDrawingState;
110 };
111 #endif
112
113 class WXDLLEXPORT wxMacCGContextStateSaver
114 {
115 DECLARE_NO_COPY_CLASS(wxMacCGContextStateSaver)
116
117 public:
118 wxMacCGContextStateSaver( CGContextRef cg )
119 {
120 m_cg = cg;
121 CGContextSaveGState( cg );
122 }
123 ~wxMacCGContextStateSaver()
124 {
125 CGContextRestoreGState( m_cg );
126 }
127 private:
128 CGContextRef m_cg;
129 };
130
131 /*
132 class wxMacDrawingHelper
133 {
134 DECLARE_NO_COPY_CLASS(wxMacDrawingHelper)
135
136 public:
137 wxMacDrawingHelper( wxWindowMac * theWindow , bool clientArea = false );
138 ~wxMacDrawingHelper();
139 bool Ok() const { return IsOk(); }
140 bool IsOk() { return m_ok; }
141 void LocalToWindow( Rect *rect) { OffsetRect( rect , m_origin.h , m_origin.v ); }
142 void LocalToWindow( Point *pt ) { AddPt( m_origin , pt ); }
143 void LocalToWindow( RgnHandle rgn ) { OffsetRgn( rgn , m_origin.h , m_origin.v ); }
144 const Point& GetOrigin() { return m_origin; }
145 private:
146 Point m_origin;
147 GrafPtr m_formerPort;
148 GrafPtr m_currentPort;
149 PenState m_savedPenState;
150 bool m_ok;
151 };
152 */
153
154 // app.h
155 bool wxMacConvertEventToRecord( EventRef event , EventRecord *rec);
156
157 #endif // wxUSE_GUI
158
159 // filefn.h
160 WXDLLIMPEXP_BASE wxString wxMacFSSpec2MacFilename( const FSSpec *spec );
161 WXDLLIMPEXP_BASE void wxMacFilename2FSSpec( const wxString &path , FSSpec *spec );
162
163 // utils.h
164 WXDLLIMPEXP_BASE wxString wxMacFindFolderNoSeparator(short vRefNum,
165 OSType folderType,
166 Boolean createFolder);
167 WXDLLIMPEXP_BASE wxString wxMacFindFolder(short vRefNum,
168 OSType folderType,
169 Boolean createFolder);
170
171 template<typename T> EventParamType wxMacGetEventParamType() { wxFAIL_MSG( wxT("Unknown Param Type") ); return 0; }
172 template<> inline EventParamType wxMacGetEventParamType<RgnHandle>() { return typeQDRgnHandle; }
173 template<> inline EventParamType wxMacGetEventParamType<ControlRef>() { return typeControlRef; }
174 template<> inline EventParamType wxMacGetEventParamType<WindowRef>() { return typeWindowRef; }
175 template<> inline EventParamType wxMacGetEventParamType<MenuRef>() { return typeMenuRef; }
176 template<> inline EventParamType wxMacGetEventParamType<EventRef>() { return typeEventRef; }
177 template<> inline EventParamType wxMacGetEventParamType<Point>() { return typeQDPoint; }
178 template<> inline EventParamType wxMacGetEventParamType<Rect>() { return typeQDRectangle; }
179 template<> inline EventParamType wxMacGetEventParamType<Boolean>() { return typeBoolean; }
180 template<> inline EventParamType wxMacGetEventParamType<SInt16>() { return typeSInt16; }
181 template<> inline EventParamType wxMacGetEventParamType<SInt32>() { return typeSInt32; }
182 template<> inline EventParamType wxMacGetEventParamType<UInt32>() { return typeUInt32; }
183 template<> inline EventParamType wxMacGetEventParamType<RGBColor>() { return typeRGBColor; }
184 template<> inline EventParamType wxMacGetEventParamType<HICommand>() { return typeHICommand; }
185 template<> inline EventParamType wxMacGetEventParamType<HIPoint>() { return typeHIPoint; }
186 template<> inline EventParamType wxMacGetEventParamType<HISize>() { return typeHISize; }
187 template<> inline EventParamType wxMacGetEventParamType<HIRect>() { return typeHIRect; }
188 template<> inline EventParamType wxMacGetEventParamType<void*>() { return typeVoidPtr; }
189 template<> inline EventParamType wxMacGetEventParamType<CFDictionaryRef>() { return typeCFDictionaryRef; }
190 template<> inline EventParamType wxMacGetEventParamType<Collection>() { return typeCollection; }
191 template<> inline EventParamType wxMacGetEventParamType<CGContextRef>() { return typeCGContextRef; }
192 /*
193 These are ambiguous
194 template<> EventParamType wxMacGetEventParamType<GrafPtr>() { return typeGrafPtr; }
195 template<> EventParamType wxMacGetEventParamType<OSStatus>() { return typeOSStatus; }
196 template<> EventParamType wxMacGetEventParamType<CFIndex>() { return typeCFIndex; }
197 template<> EventParamType wxMacGetEventParamType<GWorldPtr>() { return typeGWorldPtr; }
198 */
199
200 class wxMacCarbonEvent
201 {
202
203 public :
204 wxMacCarbonEvent()
205 {
206 m_eventRef = 0;
207 m_release = false;
208 }
209
210 wxMacCarbonEvent( EventRef event , bool release = false )
211 {
212 m_eventRef = event;
213 m_release = release;
214 }
215
216 wxMacCarbonEvent(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone)
217 {
218 m_eventRef = NULL;
219 verify_noerr( MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef) );
220 m_release = true;
221 }
222
223 ~wxMacCarbonEvent()
224 {
225 if ( m_release )
226 ReleaseEvent( m_eventRef );
227 }
228
229 OSStatus Create(UInt32 inClassID,UInt32 inKind,EventTime inWhen = 0 /*now*/,EventAttributes inAttributes=kEventAttributeNone)
230 {
231 verify( (m_eventRef == NULL) || m_release );
232 if ( m_eventRef && m_release )
233 {
234 ReleaseEvent( m_eventRef );
235 m_release = false;
236 m_eventRef = NULL;
237 }
238 OSStatus err = MacCreateEvent( NULL , inClassID, inKind,inWhen,inAttributes,&m_eventRef);
239 if ( err == noErr )
240 m_release = true;
241 return err;
242 }
243
244 OSStatus GetParameter( EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData);
245
246 template <typename T> OSStatus GetParameter( EventParamName inName, EventParamType type , T *data )
247 {
248 return GetParameter( inName, type , sizeof( T ) , data );
249 }
250 template <typename T> OSStatus GetParameter( EventParamName inName, T *data )
251 {
252 return GetParameter<T>( inName, wxMacGetEventParamType<T>() , data );
253 }
254
255 template <typename T> T GetParameter( EventParamName inName )
256 {
257 T value;
258 verify_noerr( GetParameter<T>( inName, &value ) );
259 return value;
260 }
261 template <typename T> T GetParameter( EventParamName inName, EventParamType inDesiredType )
262 {
263 T value;
264 verify_noerr( GetParameter<T>( inName, inDesiredType , &value ) );
265 return value;
266 }
267
268 OSStatus SetParameter( EventParamName inName, EventParamType inType, UInt32 inSize, const void * inData);
269 template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T *data )
270 {
271 return SetParameter( inName, inDesiredType , sizeof( T ) , data );
272 }
273 template <typename T> OSStatus SetParameter( EventParamName inName, EventParamType inDesiredType , const T& data )
274 {
275 return SetParameter<T>( inName, inDesiredType , &data );
276 }
277 template <typename T> OSStatus SetParameter( EventParamName inName, const T *data )
278 {
279 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , data );
280 }
281 template <typename T> OSStatus SetParameter( EventParamName inName, const T& data )
282 {
283 return SetParameter<T>( inName, wxMacGetEventParamType<T>() , &data );
284 }
285 UInt32 GetClass()
286 {
287 return ::GetEventClass( m_eventRef );
288 }
289 UInt32 GetKind()
290 {
291 return ::GetEventKind( m_eventRef );
292 }
293 EventTime GetTime()
294 {
295 return ::GetEventTime( m_eventRef );
296 }
297 UInt32 GetTicks()
298 {
299 return EventTimeToTicks( GetTime() );
300 }
301 OSStatus SetCurrentTime( )
302 {
303 return ::SetEventTime( m_eventRef , GetCurrentEventTime() );
304 }
305 OSStatus SetTime( EventTime when )
306 {
307 return ::SetEventTime( m_eventRef , when );
308 }
309 operator EventRef () { return m_eventRef; }
310
311 bool IsValid() { return m_eventRef != 0; }
312 protected :
313 EventRef m_eventRef;
314 bool m_release;
315 };
316
317 //
318 // helper class for allocating and deallocating Universal Proc Ptrs
319 //
320
321 template <typename procType, typename uppType , uppType (*newUPP)(procType) , void (*disposeUPP)(uppType) > class wxMacUPP
322 {
323 public :
324 wxMacUPP( procType WXUNUSED(proc) )
325 {
326 m_upp = NULL;
327 m_upp = (*newUPP)( NULL );
328 }
329 ~wxMacUPP()
330 {
331 if ( m_upp )
332 disposeUPP( m_upp );
333 }
334 operator uppType() { return m_upp; }
335 private :
336 uppType m_upp;
337 };
338
339 typedef wxMacUPP<NMProcPtr,NMUPP,NewNMUPP,DisposeNMUPP> wxMacNMUPP;
340
341 template <typename refType> class wxMacCFRefHolder
342 {
343 public :
344 wxMacCFRefHolder()
345 : m_ref(NULL) , m_release(false)
346 {
347 }
348
349 wxMacCFRefHolder( refType ref , bool release = true )
350 : m_ref(ref) , m_release(release)
351 {
352 }
353
354 ~wxMacCFRefHolder()
355 {
356 Release();
357 }
358
359 void Release()
360 {
361 if ( m_release && m_ref != NULL )
362 CFRelease( m_ref );
363 m_ref = NULL;
364 }
365
366 refType Detach()
367 {
368 refType val = m_ref;
369 m_release = false;
370 m_ref = NULL;
371 return val;
372 }
373
374 void Set( refType ref , bool release = true )
375 {
376 Release();
377 m_release = release;
378 m_ref = ref;
379 }
380
381 operator refType () const { return m_ref; }
382
383 wxMacCFRefHolder& operator=(refType r)
384 {
385 Set( r );
386 return *this;
387 }
388 private :
389 refType m_ref;
390 bool m_release;
391
392 DECLARE_NO_COPY_CLASS( wxMacCFRefHolder )
393 };
394
395 #if wxUSE_GUI
396
397 class wxMacToolTipTimer ;
398
399 class wxMacToolTip
400 {
401 public :
402 wxMacToolTip() ;
403 ~wxMacToolTip() ;
404
405 void Setup( WindowRef window , const wxString& text , const wxPoint& localPosition ) ;
406 void Draw() ;
407 void Clear() ;
408
409 long GetMark()
410 { return m_mark ; }
411
412 bool IsShown()
413 { return m_shown ; }
414
415 private :
416 wxString m_label ;
417 wxPoint m_position ;
418 Rect m_rect ;
419 WindowRef m_window ;
420 PicHandle m_backpict ;
421 bool m_shown ;
422 long m_mark ;
423 #if wxUSE_TIMER
424 wxMacToolTipTimer* m_timer ;
425 #endif
426 wxMacCFStringHolder m_helpTextRef ;
427 } ;
428
429 /*
430 GWorldPtr wxMacCreateGWorld( int width , int height , int depth );
431 void wxMacDestroyGWorld( GWorldPtr gw );
432 PicHandle wxMacCreatePict( GWorldPtr gw , GWorldPtr mask = NULL );
433 CIconHandle wxMacCreateCIcon(GWorldPtr image , GWorldPtr mask , short dstDepth , short iconSize );
434 void wxMacSetColorTableEntry( CTabHandle newColors , int index , int red , int green , int blue );
435 CTabHandle wxMacCreateColorTable( int numColors );
436 */
437 void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType = 0 );
438 void wxMacReleaseBitmapButton( ControlButtonContentInfo*info );
439 CGImageRef wxMacCreateCGImageFromBitmap( const wxBitmap& bitmap );
440
441 #define MAC_WXHBITMAP(a) (GWorldPtr(a))
442 #define MAC_WXHMETAFILE(a) (PicHandle(a))
443 #define MAC_WXHICON(a) (IconRef(a))
444 #define MAC_WXHCURSOR(a) (CursHandle(a))
445 #define MAC_WXHRGN(a) (RgnHandle(a))
446 #define MAC_WXHWND(a) (WindowPtr(a))
447 #define MAC_WXRECPTR(a) ((Rect*)a)
448 #define MAC_WXPOINTPTR(a) ((Point*)a)
449 #define MAC_WXHMENU(a) ((MenuHandle)a)
450
451 struct wxOpaqueWindowRef
452 {
453 wxOpaqueWindowRef( WindowRef ref ) { m_data = ref; }
454 operator WindowRef() { return m_data; }
455 private :
456 WindowRef m_data;
457 };
458
459 void wxMacRectToNative( const wxRect *wx , Rect *n );
460 void wxMacNativeToRect( const Rect *n , wxRect* wx );
461 void wxMacPointToNative( const wxPoint* wx , Point *n );
462 void wxMacNativeToPoint( const Point *n , wxPoint* wx );
463
464 WXDLLIMPEXP_CORE wxWindow * wxFindControlFromMacControl(ControlRef inControl );
465 WXDLLIMPEXP_CORE wxTopLevelWindowMac* wxFindWinFromMacWindow( WindowRef inWindow );
466 WXDLLIMPEXP_CORE wxMenu* wxFindMenuFromMacMenu(MenuRef inMenuRef);
467
468 WXDLLIMPEXP_CORE int wxMacCommandToId( UInt32 macCommandId );
469 WXDLLIMPEXP_CORE UInt32 wxIdToMacCommand( int wxId );
470 WXDLLIMPEXP_CORE wxMenu* wxFindMenuFromMacCommand( const HICommand &macCommandId , wxMenuItem* &item );
471
472 extern wxWindow* g_MacLastWindow;
473 WXDLLIMPEXP_CORE pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data );
474 WXDLLIMPEXP_CORE Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin = true );
475
476 ControlActionUPP GetwxMacLiveScrollbarActionProc();
477
478 class wxMacControl : public wxObject
479 {
480 public :
481 wxMacControl( wxWindow* peer , bool isRootControl = false );
482 wxMacControl( wxWindow* peer , ControlRef control );
483 wxMacControl( wxWindow* peer , WXWidget control );
484 wxMacControl() ;
485 virtual ~wxMacControl();
486
487 void Init();
488
489 virtual void Dispose();
490
491 bool Ok() const { return IsOk(); }
492 bool IsOk() const { return GetControlRef() != NULL; }
493
494 void SetReferenceInNativeControl();
495 static wxMacControl* GetReferenceFromNativeControl(ControlRef control);
496
497 virtual ControlRef * GetControlRefAddr() { return &m_controlRef; }
498 virtual ControlRef GetControlRef() const { return m_controlRef; }
499
500 virtual void SetReference( URefCon data );
501 /*
502 void operator= (ControlRef c) { m_controlRef = c; }
503 operator ControlRef () { return m_controlRef; }
504 operator ControlRef * () { return &m_controlRef; }
505 */
506 // accessing data and values
507
508 virtual OSStatus SetData( ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData );
509 virtual OSStatus GetData( ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const;
510 virtual OSStatus GetDataSize( ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const;
511 virtual OSStatus SendEvent( EventRef ref , OptionBits inOptions = 0 );
512 virtual OSStatus SendHICommand( HICommand &command , OptionBits inOptions = 0 );
513
514 virtual OSStatus SendHICommand( UInt32 commandID , OptionBits inOptions = 0 );
515
516 virtual SInt32 GetValue() const;
517 virtual SInt32 GetMaximum() const;
518 virtual SInt32 GetMinimum() const;
519
520 virtual void SetValue( SInt32 v );
521 virtual void SetMinimum( SInt32 v );
522 virtual void SetMaximum( SInt32 v );
523
524 virtual void SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum );
525 virtual void SetRange( SInt32 minimum , SInt32 maximum );
526
527 virtual OSStatus SetFocus( ControlFocusPart focusPart );
528 virtual bool HasFocus() const;
529 virtual bool NeedsFocusRect() const;
530 virtual void SetNeedsFocusRect( bool needs );
531
532 // templated helpers
533
534 Size GetDataSize( ControlPartCode inPartCode , ResType inTag ) const
535 {
536 Size sz;
537 verify_noerr( GetDataSize( inPartCode , inTag , &sz ) );
538 return sz;
539 }
540 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T *data )
541 {
542 return SetData( inPartCode , inTag , sizeof( T ) , data );
543 }
544 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T& data )
545 {
546 return SetData( inPartCode , inTag , sizeof( T ) , &data );
547 }
548 template <typename T> OSStatus SetData( ResType inTag , const T *data )
549 {
550 return SetData( kControlEntireControl , inTag , sizeof( T ) , data );
551 }
552 template <typename T> OSStatus SetData( ResType inTag , const T& data )
553 {
554 return SetData( kControlEntireControl , inTag , sizeof( T ) , &data );
555 }
556 template <typename T> OSStatus GetData( ControlPartCode inPartCode , ResType inTag , T *data ) const
557 {
558 Size dummy;
559 return GetData( inPartCode , inTag , sizeof( T ) , data , &dummy );
560 }
561 template <typename T> T GetData( ControlPartCode inPartCode , ResType inTag ) const
562 {
563 T value;
564 OSStatus err = GetData<T>( inPartCode , inTag , &value );
565
566 wxASSERT_MSG( err == noErr,
567 wxString::Format(wxT("GetData Failed for Part [%i] and Tag [%i]"),
568 inPartCode, (int)inTag) );
569 return value;
570 }
571 template <typename T> OSStatus GetData( ResType inTag , T *data ) const
572 {
573 Size dummy;
574 return GetData( kControlEntireControl , inTag , sizeof( T ) , data , &dummy );
575 }
576 template <typename T> T GetData( ResType inTag ) const
577 {
578 return GetData<T>( kControlEntireControl , inTag );
579 }
580
581 // Flash the control for the specified amount of time
582 virtual void Flash( ControlPartCode part , UInt32 ticks = 8 );
583
584 virtual void VisibilityChanged( bool shown );
585 virtual void SuperChangedPosition();
586
587
588 virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle );
589 virtual void SetBackgroundColour( const wxColour& col );
590 virtual ControlPartCode HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers );
591 void SetActionProc( ControlActionUPP actionProc );
592 void SetViewSize( SInt32 viewSize );
593 SInt32 GetViewSize() const;
594
595 virtual bool IsVisible() const;
596 virtual void SetVisibility( bool visible , bool redraw );
597 virtual bool IsEnabled() const;
598 virtual bool IsActive() const;
599 virtual void Enable( bool enable );
600
601 // invalidates this control and all children
602 virtual void InvalidateWithChildren();
603 virtual void SetDrawingEnabled( bool enable );
604 virtual bool GetNeedsDisplay() const;
605
606 // where is in native window relative coordinates
607 virtual void SetNeedsDisplay( RgnHandle where );
608 // where is in native window relative coordinates
609 virtual void SetNeedsDisplay( Rect* where = NULL );
610
611 // if rect = NULL, entire view
612 virtual void ScrollRect( wxRect *rect , int dx , int dy );
613
614 // in native parent window relative coordinates
615 virtual void GetRect( Rect *r );
616
617 // in native parent window relative coordinates
618 virtual void SetRect( Rect *r );
619
620 virtual void GetRectInWindowCoords( Rect *r );
621 virtual void GetBestRect( Rect *r );
622 virtual void SetLabel( const wxString &title );
623 // converts from Toplevel-Content relative to local
624 static void Convert( wxPoint *pt , wxMacControl *convert , wxMacControl *to );
625
626 virtual void GetFeatures( UInt32 *features );
627 virtual OSStatus GetRegion( ControlPartCode partCode , RgnHandle region );
628 virtual OSStatus SetZOrder( bool above , wxMacControl* other );
629
630 bool IsRootControl() { return m_isRootControl; }
631
632 wxWindow* GetPeer() const
633 {
634 return m_peer;
635 }
636
637 // to be moved into a tab control class
638
639 virtual OSStatus SetTabEnabled( SInt16 tabNo , bool enable );
640 protected :
641 ControlRef m_controlRef;
642 wxFont m_font;
643 long m_windowStyle;
644 wxWindow* m_peer;
645 bool m_needsFocusRect;
646 bool m_isRootControl;
647 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacControl)
648 };
649
650 // ============================================================================
651 // DataBrowser Wrapper
652 // ============================================================================
653 //
654 // basing on DataBrowserItemIDs
655 //
656
657 class wxMacDataBrowserControl : public wxMacControl
658 {
659 public :
660 wxMacDataBrowserControl( wxWindow* peer, const wxPoint& pos, const wxSize& size, long style);
661 wxMacDataBrowserControl() {}
662
663 OSStatus SetCallbacks( const DataBrowserCallbacks *callbacks );
664
665 OSStatus GetItemCount( DataBrowserItemID container,
666 Boolean recurse,
667 DataBrowserItemState state,
668 ItemCount *numItems) const;
669
670 OSStatus GetItems( DataBrowserItemID container,
671 Boolean recurse,
672 DataBrowserItemState state,
673 Handle items) const;
674
675
676 OSStatus AddColumn( DataBrowserListViewColumnDesc *columnDesc,
677 DataBrowserTableViewColumnIndex position );
678
679 OSStatus RemoveColumn( DataBrowserTableViewColumnIndex position );
680
681 OSStatus AutoSizeColumns();
682
683 OSStatus SetHasScrollBars( bool horiz, bool vert );
684 OSStatus SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle );
685
686 OSStatus SetHeaderButtonHeight( UInt16 height );
687 OSStatus GetHeaderButtonHeight( UInt16 *height );
688
689 OSStatus UpdateItems( DataBrowserItemID container, UInt32 numItems,
690 const DataBrowserItemID *items,
691 DataBrowserPropertyID preSortProperty,
692 DataBrowserPropertyID propertyID ) const;
693
694 OSStatus AddItems( DataBrowserItemID container, UInt32 numItems,
695 const DataBrowserItemID *items,
696 DataBrowserPropertyID preSortProperty );
697 OSStatus RemoveItems( DataBrowserItemID container, UInt32 numItems,
698 const DataBrowserItemID *items,
699 DataBrowserPropertyID preSortProperty );
700 OSStatus RevealItem( DataBrowserItemID item,
701 DataBrowserPropertyID propertyID,
702 DataBrowserRevealOptions options ) const;
703
704 OSStatus SetSelectionFlags( DataBrowserSelectionFlags );
705 OSStatus GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const;
706 bool IsItemSelected( DataBrowserItemID item ) const;
707 OSStatus SetSelectedItems( UInt32 numItems,
708 const DataBrowserItemID *items,
709 DataBrowserSetOption operation );
710
711 OSStatus GetItemID( DataBrowserTableViewRowIndex row,
712 DataBrowserItemID * item ) const;
713 OSStatus GetItemRow( DataBrowserItemID item,
714 DataBrowserTableViewRowIndex * row ) const;
715
716 OSStatus SetDefaultRowHeight( UInt16 height );
717 OSStatus GetDefaultRowHeight( UInt16 * height ) const;
718
719 OSStatus SetRowHeight( DataBrowserItemID item , UInt16 height);
720 OSStatus GetRowHeight( DataBrowserItemID item , UInt16 *height) const;
721
722 OSStatus GetColumnWidth( DataBrowserPropertyID column , UInt16 *width ) const;
723 OSStatus SetColumnWidth( DataBrowserPropertyID column , UInt16 width );
724
725 OSStatus GetDefaultColumnWidth( UInt16 *width ) const;
726 OSStatus SetDefaultColumnWidth( UInt16 width );
727
728 OSStatus GetColumnCount( UInt32* numColumns) const;
729
730 OSStatus GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position, DataBrowserTableViewColumnID* id );
731
732 OSStatus GetColumnPosition( DataBrowserPropertyID column, DataBrowserTableViewColumnIndex *position) const;
733 OSStatus SetColumnPosition( DataBrowserPropertyID column, DataBrowserTableViewColumnIndex position);
734
735 OSStatus GetScrollPosition( UInt32 *top , UInt32 *left ) const;
736 OSStatus SetScrollPosition( UInt32 top , UInt32 left );
737
738 OSStatus GetSortProperty( DataBrowserPropertyID *column ) const;
739 OSStatus SetSortProperty( DataBrowserPropertyID column );
740
741 OSStatus GetSortOrder( DataBrowserSortOrder *order ) const;
742 OSStatus SetSortOrder( DataBrowserSortOrder order );
743
744 OSStatus GetPropertyFlags( DataBrowserPropertyID property, DataBrowserPropertyFlags *flags ) const;
745 OSStatus SetPropertyFlags( DataBrowserPropertyID property, DataBrowserPropertyFlags flags );
746
747 OSStatus GetHeaderDesc( DataBrowserPropertyID property, DataBrowserListViewHeaderDesc *desc ) const;
748 OSStatus SetHeaderDesc( DataBrowserPropertyID property, DataBrowserListViewHeaderDesc *desc );
749
750 OSStatus SetDisclosureColumn( DataBrowserPropertyID property , Boolean expandableRows );
751 protected :
752
753 static pascal void DataBrowserItemNotificationProc(
754 ControlRef browser,
755 DataBrowserItemID itemID,
756 DataBrowserItemNotification message,
757 DataBrowserItemDataRef itemData );
758
759 virtual void ItemNotification(
760 DataBrowserItemID itemID,
761 DataBrowserItemNotification message,
762 DataBrowserItemDataRef itemData) = 0;
763
764 static pascal OSStatus DataBrowserGetSetItemDataProc(
765 ControlRef browser,
766 DataBrowserItemID itemID,
767 DataBrowserPropertyID property,
768 DataBrowserItemDataRef itemData,
769 Boolean changeValue );
770
771 virtual OSStatus GetSetItemData(
772 DataBrowserItemID itemID,
773 DataBrowserPropertyID property,
774 DataBrowserItemDataRef itemData,
775 Boolean changeValue ) = 0;
776
777 static pascal Boolean DataBrowserCompareProc(
778 ControlRef browser,
779 DataBrowserItemID itemOneID,
780 DataBrowserItemID itemTwoID,
781 DataBrowserPropertyID sortProperty);
782
783 virtual Boolean CompareItems(DataBrowserItemID itemOneID,
784 DataBrowserItemID itemTwoID,
785 DataBrowserPropertyID sortProperty) = 0;
786 DECLARE_ABSTRACT_CLASS(wxMacDataBrowserControl)
787 };
788
789 // ============================================================================
790 // Higher-level Databrowser
791 // ============================================================================
792 //
793 // basing on data item objects
794 //
795
796 // forward decl
797
798 class wxMacDataItemBrowserControl;
799 class wxMacListBoxItem;
800
801 const DataBrowserPropertyID kTextColumnId = 1024;
802 const DataBrowserPropertyID kNumericOrderColumnId = 1025;
803
804 // for multi-column controls, we will use this + the column ID to identify the
805 // column. We don't use kTextColumnId there, and ideally the two should merge.
806 const DataBrowserPropertyID kMinColumnId = 1050;
807
808 // base API for high-level databrowser operations
809
810 class wxMacListControl
811 {
812 public:
813 virtual void MacDelete( unsigned int n ) = 0;
814 virtual void MacInsert( unsigned int n, const wxArrayStringsAdapter& items, int column = -1 ) = 0;
815 // returns index of newly created line
816 virtual int MacAppend( const wxString& item ) = 0;
817 virtual void MacSetString( unsigned int n, const wxString& item ) = 0;
818 virtual void MacClear() = 0;
819 virtual void MacDeselectAll() = 0;
820 virtual void MacSetSelection( unsigned int n, bool select, bool multi ) = 0;
821 virtual int MacGetSelection() const = 0;
822 virtual int MacGetSelections( wxArrayInt& aSelections ) const = 0;
823 virtual bool MacIsSelected( unsigned int n ) const = 0;
824 virtual void MacScrollTo( unsigned int n ) = 0;
825 virtual wxString MacGetString( unsigned int n) const = 0;
826 virtual unsigned int MacGetCount() const = 0;
827
828 virtual void MacSetClientData( unsigned int n, void * data) = 0;
829 virtual void * MacGetClientData( unsigned int) const = 0;
830
831 virtual ~wxMacListControl() { }
832 };
833
834 // base class for databrowser items
835
836 enum DataItemType {
837 DataItem_Text
838 };
839
840 class wxMacDataItem
841 {
842 public :
843 wxMacDataItem();
844 virtual ~wxMacDataItem();
845
846 virtual bool IsLessThan(wxMacDataItemBrowserControl *owner ,
847 const wxMacDataItem*,
848 DataBrowserPropertyID property) const;
849
850 // returns true if access was successful, otherwise false
851 virtual OSStatus GetSetData(wxMacDataItemBrowserControl *owner ,
852 DataBrowserPropertyID property,
853 DataBrowserItemDataRef itemData,
854 bool changeValue );
855
856 virtual void Notification(wxMacDataItemBrowserControl *owner ,
857 DataBrowserItemNotification message,
858 DataBrowserItemDataRef itemData ) const;
859
860 void SetLabel( const wxString& str);
861 const wxString& GetLabel() const;
862
863 void SetOrder( SInt32 order );
864 SInt32 GetOrder() const;
865
866 void SetData( void* data);
867 void* GetData() const;
868
869 void SetColumn( short col );
870 short GetColumn();
871
872 protected :
873 wxString m_label;
874 wxMacCFStringHolder m_cfLabel;
875 void * m_data;
876 SInt32 m_order;
877 DataBrowserPropertyID m_colId;
878
879 };
880
881 enum ListSortOrder {
882 SortOrder_None,
883 SortOrder_Text_Ascending,
884 SortOrder_Text_Descending
885 };
886
887 typedef wxMacDataItem* wxMacDataItemPtr;
888 const wxMacDataItemPtr wxMacDataBrowserRootContainer = NULL;
889
890 WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxMacDataItemPtr, wxArrayMacDataItemPtr, class WXDLLIMPEXP_CORE);
891
892 class wxMacDataItemBrowserControl : public wxMacDataBrowserControl, public wxMacListControl
893 {
894 public :
895 wxMacDataItemBrowserControl( wxWindow* peer , const wxPoint& pos, const wxSize& size, long style);
896 wxMacDataItemBrowserControl() {}
897 // create a list item (can be a subclass of wxMacListBoxItem)
898
899 virtual wxMacDataItem* CreateItem();
900
901 unsigned int GetItemCount(const wxMacDataItem* container, bool recurse , DataBrowserItemState state) const;
902 void GetItems(const wxMacDataItem* container, bool recurse ,
903 DataBrowserItemState state, wxArrayMacDataItemPtr &items ) const;
904
905 unsigned int GetSelectedItemCount( const wxMacDataItem* container, bool recurse ) const;
906
907 unsigned int GetLineFromItem(const wxMacDataItem *item) const;
908 wxMacDataItem * GetItemFromLine(unsigned int n) const;
909
910 void UpdateItem(const wxMacDataItem *container, const wxMacDataItem *item,
911 DataBrowserPropertyID property) const;
912 void UpdateItems(const wxMacDataItem *container, wxArrayMacDataItemPtr &items,
913 DataBrowserPropertyID property) const;
914
915 void InsertColumn(int colId, DataBrowserPropertyType colType,
916 const wxString& title, SInt16 just = teFlushDefault, int defaultWidth = -1);
917
918 int GetColumnWidth(int colId);
919 void SetColumnWidth(int colId, int width);
920
921 void AddItem(wxMacDataItem *container, wxMacDataItem *item);
922 void AddItems(wxMacDataItem *container, wxArrayMacDataItemPtr &items );
923
924 void RemoveAllItems(wxMacDataItem *container);
925 void RemoveItem(wxMacDataItem *container, wxMacDataItem* item);
926 void RemoveItems(wxMacDataItem *container, wxArrayMacDataItemPtr &items);
927
928 void SetSelectedItem( wxMacDataItem* item , DataBrowserSetOption option);
929 void SetSelectedItems( wxArrayMacDataItemPtr &items , DataBrowserSetOption option);
930 void SetSelectedAllItems( DataBrowserSetOption option);
931 Boolean IsItemSelected( const wxMacDataItem* item) const;
932
933 void RevealItem( wxMacDataItem* item, DataBrowserRevealOptions options);
934
935 void GetSelectionAnchor( wxMacDataItemPtr* first , wxMacDataItemPtr* last) const;
936
937 // item aware methods, to be used in subclasses
938
939 virtual Boolean CompareItems(const wxMacDataItem* itemOneID,
940 const wxMacDataItem* itemTwoID,
941 DataBrowserPropertyID sortProperty);
942
943 virtual OSStatus GetSetItemData(wxMacDataItem* itemID,
944 DataBrowserPropertyID property,
945 DataBrowserItemDataRef itemData,
946 Boolean changeValue );
947
948 virtual void ItemNotification(
949 const wxMacDataItem* itemID,
950 DataBrowserItemNotification message,
951 DataBrowserItemDataRef itemData);
952
953 // as we are getting the same events for human and API selection we have to suppress
954 // events in the latter case, since this will be used from many subclasses we keep it here
955
956 bool IsSelectionSuppressed() const { return m_suppressSelection; }
957 bool SuppressSelection( bool suppress );
958
959
960 // wxMacListControl Methods
961 // add and remove
962
963 virtual void MacDelete( unsigned int n );
964 virtual void MacInsert( unsigned int n, const wxArrayStringsAdapter& items, int column = -1 );
965 virtual int MacAppend( const wxString& item );
966 virtual void MacClear();
967
968 // selecting
969
970 virtual void MacDeselectAll();
971 virtual void MacSetSelection( unsigned int n, bool select, bool multi = false );
972 virtual int MacGetSelection() const;
973 virtual int MacGetSelections( wxArrayInt& aSelections ) const;
974 virtual bool MacIsSelected( unsigned int n ) const;
975
976 // display
977
978 virtual void MacScrollTo( unsigned int n );
979
980 // accessing content
981
982 virtual void MacSetString( unsigned int n, const wxString& item );
983 virtual void MacSetClientData( unsigned int n, void * data);
984 virtual wxString MacGetString( unsigned int n) const;
985 virtual void * MacGetClientData( unsigned int) const;
986 virtual unsigned int MacGetCount() const;
987
988 // client data
989
990 virtual wxClientDataType GetClientDataType() const;
991 virtual void SetClientDataType(wxClientDataType clientDataItemsType);
992 //virtual ListSortOrder GetSortOrder() const;
993 //virtual void SetSortOrder(const ListSortOrder sort);
994
995
996
997 protected:
998
999 ListSortOrder m_sortOrder;
1000 wxClientDataType m_clientDataItemsType;
1001
1002 // ID aware base methods, should be 'final' ie not changed in subclasses
1003
1004 virtual Boolean CompareItems(DataBrowserItemID itemOneID,
1005 DataBrowserItemID itemTwoID,
1006 DataBrowserPropertyID sortProperty);
1007
1008 virtual OSStatus GetSetItemData(DataBrowserItemID itemID,
1009 DataBrowserPropertyID property,
1010 DataBrowserItemDataRef itemData,
1011 Boolean changeValue );
1012
1013 virtual void ItemNotification(
1014 DataBrowserItemID itemID,
1015 DataBrowserItemNotification message,
1016 DataBrowserItemDataRef itemData);
1017
1018
1019 private :
1020
1021 bool m_suppressSelection;
1022 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataItemBrowserControl)
1023 };
1024
1025 class wxMacDataItemBrowserSelectionSuppressor
1026 {
1027 public :
1028 wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl *browser);
1029 ~wxMacDataItemBrowserSelectionSuppressor();
1030
1031 private :
1032
1033 bool m_former;
1034 wxMacDataItemBrowserControl* m_browser;
1035 };
1036
1037 // ============================================================================
1038 // platform listbox implementation
1039 // ============================================================================
1040
1041 // exposed for reuse in wxCheckListBox
1042
1043 class wxMacListBoxItem : public wxMacDataItem
1044 {
1045 public :
1046 wxMacListBoxItem();
1047
1048 virtual ~wxMacListBoxItem();
1049
1050 virtual void Notification(wxMacDataItemBrowserControl *owner ,
1051 DataBrowserItemNotification message,
1052 DataBrowserItemDataRef itemData ) const;
1053 };
1054
1055 class wxMacDataBrowserListControl : public wxMacDataItemBrowserControl
1056 {
1057 public:
1058 wxMacDataBrowserListControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style );
1059 wxMacDataBrowserListControl() {}
1060 virtual ~wxMacDataBrowserListControl();
1061
1062 virtual wxMacDataItem* CreateItem();
1063
1064 // pointing back
1065
1066 wxWindow * GetPeer() const;
1067
1068 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserListControl)
1069 };
1070
1071 // ============================================================================
1072 // graphics implementation
1073 // ============================================================================
1074
1075 // draw the image 'upside down' corrected as HIViewDrawCGImage does
1076
1077 OSStatus WXDLLEXPORT wxMacDrawCGImage(
1078 CGContextRef inContext,
1079 const HIRect * inBounds,
1080 CGImageRef inImage) ;
1081
1082 CGColorRef wxMacCreateCGColorFromHITheme( ThemeBrush brush ) ;
1083
1084 CGColorSpaceRef wxMacGetGenericRGBColorSpace(void);
1085
1086 void wxMacMemoryBufferReleaseProc(void *info, const void *data, size_t size);
1087
1088 // toplevel.cpp
1089
1090 class wxMacDeferredWindowDeleter : public wxObject
1091 {
1092 public :
1093 wxMacDeferredWindowDeleter( WindowRef windowRef );
1094 virtual ~wxMacDeferredWindowDeleter();
1095
1096 protected :
1097 WindowRef m_macWindow ;
1098 } ;
1099
1100 #endif // wxUSE_GUI
1101
1102 #define wxMAC_DEFINE_PROC_GETTER( UPP , x ) \
1103 UPP Get##x() \
1104 { \
1105 static UPP sHandler = NULL; \
1106 if ( sHandler == NULL ) \
1107 sHandler = New##UPP( x ); \
1108 return sHandler; \
1109 }
1110
1111 //---------------------------------------------------------------------------
1112 // wxMac string conversions
1113 //---------------------------------------------------------------------------
1114
1115 void wxMacSetupConverters();
1116 void wxMacCleanupConverters();
1117
1118 WXDLLIMPEXP_BASE void wxMacStringToPascal( const wxString&from , StringPtr to );
1119 WXDLLIMPEXP_BASE wxString wxMacMakeStringFromPascal( ConstStringPtr from );
1120
1121 // filefn.cpp
1122
1123 WXDLLIMPEXP_BASE wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL );
1124 WXDLLIMPEXP_BASE OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef );
1125 WXDLLIMPEXP_BASE wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname );
1126
1127 #if wxUSE_GUI
1128
1129 // deprecating QD
1130
1131 void wxMacLocalToGlobal( WindowRef window , Point*pt );
1132 void wxMacGlobalToLocal( WindowRef window , Point*pt );
1133
1134 #endif
1135
1136 //---------------------------------------------------------------------------
1137 // cocoa bridging utilities
1138 //---------------------------------------------------------------------------
1139
1140 bool wxMacInitCocoa();
1141
1142 class wxMacAutoreleasePool
1143 {
1144 public :
1145 wxMacAutoreleasePool();
1146 ~wxMacAutoreleasePool();
1147 private :
1148 void* m_pool;
1149 };
1150
1151 // NSObject
1152
1153 void wxMacCocoaRelease( void* obj );
1154 void wxMacCocoaAutorelease( void* obj );
1155 void wxMacCocoaRetain( void* obj );
1156
1157 #if wxMAC_USE_COCOA
1158
1159 // NSCursor
1160
1161 WX_NSCursor wxMacCocoaCreateStockCursor( int cursor_type );
1162 WX_NSCursor wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef, float hotSpotX, float hotSpotY );
1163 void wxMacCocoaSetCursor( WX_NSCursor cursor );
1164 void wxMacCocoaHideCursor();
1165 void wxMacCocoaShowCursor();
1166
1167 typedef struct tagClassicCursor
1168 {
1169 wxUint16 bits[16];
1170 wxUint16 mask[16];
1171 wxInt16 hotspot[2];
1172 }ClassicCursor;
1173
1174 #else // !wxMAC_USE_COCOA
1175
1176 // non Darwin
1177
1178 typedef Cursor ClassicCursor;
1179
1180 #endif // wxMAC_USE_COCOA
1181
1182 // -------------
1183 // Common to all
1184 // -------------
1185
1186 // Cursor support
1187
1188 const short kwxCursorBullseye = 0;
1189 const short kwxCursorBlank = 1;
1190 const short kwxCursorPencil = 2;
1191 const short kwxCursorMagnifier = 3;
1192 const short kwxCursorNoEntry = 4;
1193 const short kwxCursorPaintBrush = 5;
1194 const short kwxCursorPointRight = 6;
1195 const short kwxCursorPointLeft = 7;
1196 const short kwxCursorQuestionArrow = 8;
1197 const short kwxCursorRightArrow = 9;
1198 const short kwxCursorSizeNS = 10;
1199 const short kwxCursorSize = 11;
1200 const short kwxCursorSizeNESW = 12;
1201 const short kwxCursorSizeNWSE = 13;
1202 const short kwxCursorRoller = 14;
1203 const short kwxCursorLast = kwxCursorRoller;
1204
1205 // exposing our fallback cursor map
1206
1207 extern ClassicCursor gMacCursors[];
1208
1209 #endif
1210 // _WX_PRIVATE_H_