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