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