]> git.saurik.com Git - wxWidgets.git/blob - include/wx/mac/carbon/private.h
make the Pen/Brush code backward compatible as discussed on wx-dev; marked the blocks...
[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 WXDLLEXPORT 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 #if wxUSE_GUI
245
246 class WXDLLIMPEXP_FWD_CORE wxMacToolTipTimer ;
247
248 class WXDLLEXPORT wxMacToolTip
249 {
250 public :
251 wxMacToolTip() ;
252 ~wxMacToolTip() ;
253
254 void Setup( WindowRef window , const wxString& text , const wxPoint& localPosition ) ;
255 void Draw() ;
256 void Clear() ;
257
258 long GetMark()
259 { return m_mark ; }
260
261 bool IsShown()
262 { return m_shown ; }
263
264 private :
265 wxString m_label ;
266 wxPoint m_position ;
267 Rect m_rect ;
268 WindowRef m_window ;
269 PicHandle m_backpict ;
270 bool m_shown ;
271 long m_mark ;
272 #if wxUSE_TIMER
273 wxMacToolTipTimer* m_timer ;
274 #endif
275 wxCFStringRef m_helpTextRef ;
276 } ;
277
278 // Quartz
279
280 WXDLLIMPEXP_CORE void wxMacCreateBitmapButton( ControlButtonContentInfo*info , const wxBitmap& bitmap , int forceType = 0 );
281 WXDLLIMPEXP_CORE void wxMacReleaseBitmapButton( ControlButtonContentInfo*info );
282 WXDLLIMPEXP_CORE CGImageRef wxMacCreateCGImageFromBitmap( const wxBitmap& bitmap );
283
284 WXDLLIMPEXP_CORE CGDataProviderRef wxMacCGDataProviderCreateWithCFData( CFDataRef data );
285 WXDLLIMPEXP_CORE CGDataConsumerRef wxMacCGDataConsumerCreateWithCFData( CFMutableDataRef data );
286 WXDLLIMPEXP_CORE CGDataProviderRef wxMacCGDataProviderCreateWithMemoryBuffer( const wxMemoryBuffer& buf );
287
288
289 #define MAC_WXHBITMAP(a) (GWorldPtr(a))
290 #define MAC_WXHMETAFILE(a) (PicHandle(a))
291 #define MAC_WXHICON(a) (IconRef(a))
292 #define MAC_WXHCURSOR(a) (CursHandle(a))
293 #define MAC_WXHRGN(a) (RgnHandle(a))
294 #define MAC_WXHWND(a) (WindowPtr(a))
295 #define MAC_WXRECPTR(a) ((Rect*)a)
296 #define MAC_WXPOINTPTR(a) ((Point*)a)
297 #define MAC_WXHMENU(a) ((MenuHandle)a)
298
299 struct wxOpaqueWindowRef
300 {
301 wxOpaqueWindowRef( WindowRef ref ) { m_data = ref; }
302 operator WindowRef() { return m_data; }
303 private :
304 WindowRef m_data;
305 };
306
307 WXDLLIMPEXP_CORE void wxMacRectToNative( const wxRect *wx , Rect *n );
308 WXDLLIMPEXP_CORE void wxMacNativeToRect( const Rect *n , wxRect* wx );
309 WXDLLIMPEXP_CORE void wxMacPointToNative( const wxPoint* wx , Point *n );
310 WXDLLIMPEXP_CORE void wxMacNativeToPoint( const Point *n , wxPoint* wx );
311
312 WXDLLIMPEXP_CORE wxWindow * wxFindControlFromMacControl(ControlRef inControl );
313 WXDLLIMPEXP_CORE wxTopLevelWindowMac* wxFindWinFromMacWindow( WindowRef inWindow );
314 WXDLLIMPEXP_CORE wxMenu* wxFindMenuFromMacMenu(MenuRef inMenuRef);
315
316 WXDLLIMPEXP_CORE int wxMacCommandToId( UInt32 macCommandId );
317 WXDLLIMPEXP_CORE UInt32 wxIdToMacCommand( int wxId );
318 WXDLLIMPEXP_CORE wxMenu* wxFindMenuFromMacCommand( const HICommand &macCommandId , wxMenuItem* &item );
319
320 extern wxWindow* g_MacLastWindow;
321 WXDLLIMPEXP_CORE pascal OSStatus wxMacTopLevelMouseEventHandler( EventHandlerCallRef handler , EventRef event , void *data );
322 WXDLLIMPEXP_CORE Rect wxMacGetBoundsForControl( wxWindow* window , const wxPoint& pos , const wxSize &size , bool adjustForOrigin = true );
323
324 ControlActionUPP GetwxMacLiveScrollbarActionProc();
325
326 // additional optional event defines
327
328 #if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_5
329 enum {
330 kEventControlFocusPartChanged = 164
331 };
332 #endif
333
334 class WXDLLEXPORT wxMacControl : public wxObject
335 {
336 public :
337 wxMacControl( wxWindow* peer , bool isRootControl = false );
338 wxMacControl( wxWindow* peer , ControlRef control );
339 wxMacControl( wxWindow* peer , WXWidget control );
340 wxMacControl() ;
341 virtual ~wxMacControl();
342
343 void Init();
344
345 virtual void Dispose();
346
347 bool Ok() const { return IsOk(); }
348 bool IsOk() const { return GetControlRef() != NULL; }
349
350 void SetReferenceInNativeControl();
351 static wxMacControl* GetReferenceFromNativeControl(ControlRef control);
352
353 virtual ControlRef * GetControlRefAddr() { return &m_controlRef; }
354 virtual ControlRef GetControlRef() const { return m_controlRef; }
355
356 virtual void SetReference( URefCon data );
357 /*
358 void operator= (ControlRef c) { m_controlRef = c; }
359 operator ControlRef () { return m_controlRef; }
360 operator ControlRef * () { return &m_controlRef; }
361 */
362 // accessing data and values
363
364 virtual OSStatus SetData( ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData );
365 virtual OSStatus GetData( ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const;
366 virtual OSStatus GetDataSize( ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const;
367 virtual OSStatus SendEvent( EventRef ref , OptionBits inOptions = 0 );
368 virtual OSStatus SendHICommand( HICommand &command , OptionBits inOptions = 0 );
369
370 virtual OSStatus SendHICommand( UInt32 commandID , OptionBits inOptions = 0 );
371
372 virtual SInt32 GetValue() const;
373 virtual SInt32 GetMaximum() const;
374 virtual SInt32 GetMinimum() const;
375
376 virtual void SetValue( SInt32 v );
377 virtual void SetMinimum( SInt32 v );
378 virtual void SetMaximum( SInt32 v );
379
380 virtual void SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum );
381 virtual void SetRange( SInt32 minimum , SInt32 maximum );
382
383 virtual OSStatus SetFocus( ControlFocusPart focusPart );
384 virtual bool HasFocus() const;
385 virtual bool NeedsFocusRect() const;
386 virtual void SetNeedsFocusRect( bool needs );
387
388 // templated helpers
389
390 Size GetDataSize( ControlPartCode inPartCode , ResType inTag ) const
391 {
392 Size sz;
393 verify_noerr( GetDataSize( inPartCode , inTag , &sz ) );
394 return sz;
395 }
396 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T *data )
397 {
398 return SetData( inPartCode , inTag , sizeof( T ) , data );
399 }
400 template <typename T> OSStatus SetData( ControlPartCode inPartCode , ResType inTag , const T& data )
401 {
402 return SetData( inPartCode , inTag , sizeof( T ) , &data );
403 }
404 template <typename T> OSStatus SetData( ResType inTag , const T *data )
405 {
406 return SetData( kControlEntireControl , inTag , sizeof( T ) , data );
407 }
408 template <typename T> OSStatus SetData( ResType inTag , const T& data )
409 {
410 return SetData( kControlEntireControl , inTag , sizeof( T ) , &data );
411 }
412 template <typename T> OSStatus GetData( ControlPartCode inPartCode , ResType inTag , T *data ) const
413 {
414 Size dummy;
415 return GetData( inPartCode , inTag , sizeof( T ) , data , &dummy );
416 }
417 template <typename T> T GetData( ControlPartCode inPartCode , ResType inTag ) const
418 {
419 T value;
420 OSStatus err = GetData<T>( inPartCode , inTag , &value );
421
422 wxASSERT_MSG( err == noErr,
423 wxString::Format(wxT("GetData Failed for Part [%i] and Tag [%i]"),
424 inPartCode, (int)inTag) );
425 return value;
426 }
427 template <typename T> OSStatus GetData( ResType inTag , T *data ) const
428 {
429 Size dummy;
430 return GetData( kControlEntireControl , inTag , sizeof( T ) , data , &dummy );
431 }
432 template <typename T> T GetData( ResType inTag ) const
433 {
434 return GetData<T>( kControlEntireControl , inTag );
435 }
436
437 // Flash the control for the specified amount of time
438 virtual void Flash( ControlPartCode part , UInt32 ticks = 8 );
439
440 virtual void VisibilityChanged( bool shown );
441 virtual void SuperChangedPosition();
442
443
444 virtual void SetFont( const wxFont & font , const wxColour& foreground , long windowStyle );
445 virtual void SetBackgroundColour( const wxColour& col );
446 virtual ControlPartCode HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers );
447 void SetActionProc( ControlActionUPP actionProc );
448 void SetViewSize( SInt32 viewSize );
449 SInt32 GetViewSize() const;
450
451 virtual bool IsVisible() const;
452 virtual void SetVisibility( bool visible , bool redraw );
453 virtual bool IsEnabled() const;
454 virtual bool IsActive() const;
455 virtual void Enable( bool enable );
456
457 // invalidates this control and all children
458 virtual void InvalidateWithChildren();
459 virtual void SetDrawingEnabled( bool enable );
460 virtual bool GetNeedsDisplay() const;
461
462 // where is in native window relative coordinates
463 virtual void SetNeedsDisplay( RgnHandle where );
464 // where is in native window relative coordinates
465 virtual void SetNeedsDisplay( Rect* where = NULL );
466
467 // if rect = NULL, entire view
468 virtual void ScrollRect( wxRect *rect , int dx , int dy );
469
470 // in native parent window relative coordinates
471 virtual void GetRect( Rect *r );
472
473 // in native parent window relative coordinates
474 virtual void SetRect( Rect *r );
475
476 virtual void GetRectInWindowCoords( Rect *r );
477 virtual void GetBestRect( Rect *r );
478 virtual void SetLabel( const wxString &title );
479 // converts from Toplevel-Content relative to local
480 static void Convert( wxPoint *pt , wxMacControl *convert , wxMacControl *to );
481
482 virtual void GetFeatures( UInt32 *features );
483 virtual OSStatus GetRegion( ControlPartCode partCode , RgnHandle region );
484 virtual OSStatus SetZOrder( bool above , wxMacControl* other );
485
486 bool IsRootControl() { return m_isRootControl; }
487
488 wxWindow* GetPeer() const
489 {
490 return m_peer;
491 }
492
493 // to be moved into a tab control class
494
495 virtual OSStatus SetTabEnabled( SInt16 tabNo , bool enable );
496 protected :
497 ControlRef m_controlRef;
498 wxFont m_font;
499 long m_windowStyle;
500 wxWindow* m_peer;
501 bool m_needsFocusRect;
502 bool m_isRootControl;
503 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacControl)
504 };
505
506 // ============================================================================
507 // DataBrowser Wrapper
508 // ============================================================================
509 //
510 // basing on DataBrowserItemIDs
511 //
512
513 class WXDLLEXPORT wxMacDataBrowserControl : public wxMacControl
514 {
515 public :
516 wxMacDataBrowserControl( wxWindow* peer, const wxPoint& pos, const wxSize& size, long style);
517 wxMacDataBrowserControl() {}
518
519 OSStatus SetCallbacks( const DataBrowserCallbacks *callbacks );
520
521 OSStatus GetItemCount( DataBrowserItemID container,
522 Boolean recurse,
523 DataBrowserItemState state,
524 ItemCount *numItems) const;
525
526 OSStatus GetItems( DataBrowserItemID container,
527 Boolean recurse,
528 DataBrowserItemState state,
529 Handle items) const;
530
531
532 OSStatus AddColumn( DataBrowserListViewColumnDesc *columnDesc,
533 DataBrowserTableViewColumnIndex position );
534
535 OSStatus RemoveColumn( DataBrowserTableViewColumnIndex position );
536
537 OSStatus AutoSizeColumns();
538
539 OSStatus SetHasScrollBars( bool horiz, bool vert );
540 OSStatus SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle );
541
542 OSStatus SetHeaderButtonHeight( UInt16 height );
543 OSStatus GetHeaderButtonHeight( UInt16 *height );
544
545 OSStatus UpdateItems( DataBrowserItemID container, UInt32 numItems,
546 const DataBrowserItemID *items,
547 DataBrowserPropertyID preSortProperty,
548 DataBrowserPropertyID propertyID ) const;
549
550 OSStatus AddItems( DataBrowserItemID container, UInt32 numItems,
551 const DataBrowserItemID *items,
552 DataBrowserPropertyID preSortProperty );
553 OSStatus RemoveItems( DataBrowserItemID container, UInt32 numItems,
554 const DataBrowserItemID *items,
555 DataBrowserPropertyID preSortProperty );
556 OSStatus RevealItem( DataBrowserItemID item,
557 DataBrowserPropertyID propertyID,
558 DataBrowserRevealOptions options ) const;
559
560 OSStatus SetSelectionFlags( DataBrowserSelectionFlags );
561 OSStatus GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const;
562 bool IsItemSelected( DataBrowserItemID item ) const;
563 OSStatus SetSelectedItems( UInt32 numItems,
564 const DataBrowserItemID *items,
565 DataBrowserSetOption operation );
566
567 OSStatus GetItemID( DataBrowserTableViewRowIndex row,
568 DataBrowserItemID * item ) const;
569 OSStatus GetItemRow( DataBrowserItemID item,
570 DataBrowserTableViewRowIndex * row ) const;
571
572 OSStatus SetDefaultRowHeight( UInt16 height );
573 OSStatus GetDefaultRowHeight( UInt16 * height ) const;
574
575 OSStatus SetRowHeight( DataBrowserItemID item , UInt16 height);
576 OSStatus GetRowHeight( DataBrowserItemID item , UInt16 *height) const;
577
578 OSStatus GetColumnWidth( DataBrowserPropertyID column , UInt16 *width ) const;
579 OSStatus SetColumnWidth( DataBrowserPropertyID column , UInt16 width );
580
581 OSStatus GetDefaultColumnWidth( UInt16 *width ) const;
582 OSStatus SetDefaultColumnWidth( UInt16 width );
583
584 OSStatus GetColumnCount( UInt32* numColumns) const;
585
586 OSStatus GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position, DataBrowserTableViewColumnID* id );
587
588 OSStatus GetColumnPosition( DataBrowserPropertyID column, DataBrowserTableViewColumnIndex *position) const;
589 OSStatus SetColumnPosition( DataBrowserPropertyID column, DataBrowserTableViewColumnIndex position);
590
591 OSStatus GetScrollPosition( UInt32 *top , UInt32 *left ) const;
592 OSStatus SetScrollPosition( UInt32 top , UInt32 left );
593
594 OSStatus GetSortProperty( DataBrowserPropertyID *column ) const;
595 OSStatus SetSortProperty( DataBrowserPropertyID column );
596
597 OSStatus GetSortOrder( DataBrowserSortOrder *order ) const;
598 OSStatus SetSortOrder( DataBrowserSortOrder order );
599
600 OSStatus GetPropertyFlags( DataBrowserPropertyID property, DataBrowserPropertyFlags *flags ) const;
601 OSStatus SetPropertyFlags( DataBrowserPropertyID property, DataBrowserPropertyFlags flags );
602
603 OSStatus GetHeaderDesc( DataBrowserPropertyID property, DataBrowserListViewHeaderDesc *desc ) const;
604 OSStatus SetHeaderDesc( DataBrowserPropertyID property, DataBrowserListViewHeaderDesc *desc );
605
606 OSStatus SetDisclosureColumn( DataBrowserPropertyID property , Boolean expandableRows );
607 protected :
608
609 static pascal void DataBrowserItemNotificationProc(
610 ControlRef browser,
611 DataBrowserItemID itemID,
612 DataBrowserItemNotification message,
613 DataBrowserItemDataRef itemData );
614
615 virtual void ItemNotification(
616 DataBrowserItemID itemID,
617 DataBrowserItemNotification message,
618 DataBrowserItemDataRef itemData) = 0;
619
620 static pascal OSStatus DataBrowserGetSetItemDataProc(
621 ControlRef browser,
622 DataBrowserItemID itemID,
623 DataBrowserPropertyID property,
624 DataBrowserItemDataRef itemData,
625 Boolean changeValue );
626
627 virtual OSStatus GetSetItemData(
628 DataBrowserItemID itemID,
629 DataBrowserPropertyID property,
630 DataBrowserItemDataRef itemData,
631 Boolean changeValue ) = 0;
632
633 static pascal Boolean DataBrowserCompareProc(
634 ControlRef browser,
635 DataBrowserItemID itemOneID,
636 DataBrowserItemID itemTwoID,
637 DataBrowserPropertyID sortProperty);
638
639 virtual Boolean CompareItems(DataBrowserItemID itemOneID,
640 DataBrowserItemID itemTwoID,
641 DataBrowserPropertyID sortProperty) = 0;
642 DECLARE_ABSTRACT_CLASS(wxMacDataBrowserControl)
643 };
644
645 // ============================================================================
646 // Higher-level Databrowser
647 // ============================================================================
648 //
649 // basing on data item objects
650 //
651
652 // forward decl
653
654 class wxMacDataItemBrowserControl;
655 class wxMacListBoxItem;
656
657 const DataBrowserPropertyID kTextColumnId = 1024;
658 const DataBrowserPropertyID kNumericOrderColumnId = 1025;
659
660 // for multi-column controls, we will use this + the column ID to identify the
661 // column. We don't use kTextColumnId there, and ideally the two should merge.
662 const DataBrowserPropertyID kMinColumnId = 1050;
663
664 // base API for high-level databrowser operations
665
666 class WXDLLEXPORT wxMacListControl
667 {
668 public:
669 virtual void MacDelete( unsigned int n ) = 0;
670 virtual void MacInsert( unsigned int n, const wxArrayStringsAdapter& items, int column = -1 ) = 0;
671 // returns index of newly created line
672 virtual int MacAppend( const wxString& item ) = 0;
673 virtual void MacSetString( unsigned int n, const wxString& item ) = 0;
674 virtual void MacClear() = 0;
675 virtual void MacDeselectAll() = 0;
676 virtual void MacSetSelection( unsigned int n, bool select, bool multi ) = 0;
677 virtual int MacGetSelection() const = 0;
678 virtual int MacGetSelections( wxArrayInt& aSelections ) const = 0;
679 virtual bool MacIsSelected( unsigned int n ) const = 0;
680 virtual void MacScrollTo( unsigned int n ) = 0;
681 virtual wxString MacGetString( unsigned int n) const = 0;
682 virtual unsigned int MacGetCount() const = 0;
683
684 virtual void MacSetClientData( unsigned int n, void * data) = 0;
685 virtual void * MacGetClientData( unsigned int) const = 0;
686
687 virtual ~wxMacListControl() { }
688 };
689
690 // base class for databrowser items
691
692 enum DataItemType {
693 DataItem_Text
694 };
695
696 class WXDLLEXPORT wxMacDataItem
697 {
698 public :
699 wxMacDataItem();
700 virtual ~wxMacDataItem();
701
702 virtual bool IsLessThan(wxMacDataItemBrowserControl *owner ,
703 const wxMacDataItem*,
704 DataBrowserPropertyID property) const;
705
706 // returns true if access was successful, otherwise false
707 virtual OSStatus GetSetData(wxMacDataItemBrowserControl *owner ,
708 DataBrowserPropertyID property,
709 DataBrowserItemDataRef itemData,
710 bool changeValue );
711
712 virtual void Notification(wxMacDataItemBrowserControl *owner ,
713 DataBrowserItemNotification message,
714 DataBrowserItemDataRef itemData ) const;
715
716 void SetLabel( const wxString& str);
717 const wxString& GetLabel() const;
718
719 void SetOrder( SInt32 order );
720 SInt32 GetOrder() const;
721
722 void SetData( void* data);
723 void* GetData() const;
724
725 void SetColumn( short col );
726 short GetColumn();
727
728 protected :
729 wxString m_label;
730 wxCFStringRef m_cfLabel;
731 void * m_data;
732 SInt32 m_order;
733 DataBrowserPropertyID m_colId;
734
735 };
736
737 enum ListSortOrder {
738 SortOrder_None,
739 SortOrder_Text_Ascending,
740 SortOrder_Text_Descending
741 };
742
743 typedef wxMacDataItem* wxMacDataItemPtr;
744 const wxMacDataItemPtr wxMacDataBrowserRootContainer = NULL;
745
746 WX_DEFINE_USER_EXPORTED_ARRAY_PTR(wxMacDataItemPtr, wxArrayMacDataItemPtr, class WXDLLIMPEXP_CORE);
747
748 class WXDLLEXPORT wxMacDataItemBrowserControl : public wxMacDataBrowserControl, public wxMacListControl
749 {
750 public :
751 wxMacDataItemBrowserControl( wxWindow* peer , const wxPoint& pos, const wxSize& size, long style);
752 wxMacDataItemBrowserControl() {}
753 // create a list item (can be a subclass of wxMacListBoxItem)
754
755 virtual wxMacDataItem* CreateItem();
756
757 unsigned int GetItemCount(const wxMacDataItem* container, bool recurse , DataBrowserItemState state) const;
758 void GetItems(const wxMacDataItem* container, bool recurse ,
759 DataBrowserItemState state, wxArrayMacDataItemPtr &items ) const;
760
761 unsigned int GetSelectedItemCount( const wxMacDataItem* container, bool recurse ) const;
762
763 unsigned int GetLineFromItem(const wxMacDataItem *item) const;
764 wxMacDataItem * GetItemFromLine(unsigned int n) const;
765
766 void UpdateItem(const wxMacDataItem *container, const wxMacDataItem *item,
767 DataBrowserPropertyID property) const;
768 void UpdateItems(const wxMacDataItem *container, wxArrayMacDataItemPtr &items,
769 DataBrowserPropertyID property) const;
770
771 void InsertColumn(int colId, DataBrowserPropertyType colType,
772 const wxString& title, SInt16 just = teFlushDefault, int defaultWidth = -1);
773
774 int GetColumnWidth(int colId);
775 void SetColumnWidth(int colId, int width);
776
777 void AddItem(wxMacDataItem *container, wxMacDataItem *item);
778 void AddItems(wxMacDataItem *container, wxArrayMacDataItemPtr &items );
779
780 void RemoveAllItems(wxMacDataItem *container);
781 void RemoveItem(wxMacDataItem *container, wxMacDataItem* item);
782 void RemoveItems(wxMacDataItem *container, wxArrayMacDataItemPtr &items);
783
784 void SetSelectedItem( wxMacDataItem* item , DataBrowserSetOption option);
785 void SetSelectedItems( wxArrayMacDataItemPtr &items , DataBrowserSetOption option);
786 void SetSelectedAllItems( DataBrowserSetOption option);
787 Boolean IsItemSelected( const wxMacDataItem* item) const;
788
789 void RevealItem( wxMacDataItem* item, DataBrowserRevealOptions options);
790
791 void GetSelectionAnchor( wxMacDataItemPtr* first , wxMacDataItemPtr* last) const;
792
793 // item aware methods, to be used in subclasses
794
795 virtual Boolean CompareItems(const wxMacDataItem* itemOneID,
796 const wxMacDataItem* itemTwoID,
797 DataBrowserPropertyID sortProperty);
798
799 virtual OSStatus GetSetItemData(wxMacDataItem* itemID,
800 DataBrowserPropertyID property,
801 DataBrowserItemDataRef itemData,
802 Boolean changeValue );
803
804 virtual void ItemNotification(
805 const wxMacDataItem* itemID,
806 DataBrowserItemNotification message,
807 DataBrowserItemDataRef itemData);
808
809 // as we are getting the same events for human and API selection we have to suppress
810 // events in the latter case, since this will be used from many subclasses we keep it here
811
812 bool IsSelectionSuppressed() const { return m_suppressSelection; }
813 bool SuppressSelection( bool suppress );
814
815
816 // wxMacListControl Methods
817 // add and remove
818
819 virtual void MacDelete( unsigned int n );
820 virtual void MacInsert( unsigned int n, const wxArrayStringsAdapter& items, int column = -1 );
821 virtual int MacAppend( const wxString& item );
822 virtual void MacClear();
823
824 // selecting
825
826 virtual void MacDeselectAll();
827 virtual void MacSetSelection( unsigned int n, bool select, bool multi = false );
828 virtual int MacGetSelection() const;
829 virtual int MacGetSelections( wxArrayInt& aSelections ) const;
830 virtual bool MacIsSelected( unsigned int n ) const;
831
832 // display
833
834 virtual void MacScrollTo( unsigned int n );
835
836 // accessing content
837
838 virtual void MacSetString( unsigned int n, const wxString& item );
839 virtual void MacSetClientData( unsigned int n, void * data);
840 virtual wxString MacGetString( unsigned int n) const;
841 virtual void * MacGetClientData( unsigned int) const;
842 virtual unsigned int MacGetCount() const;
843
844 // client data
845
846 virtual wxClientDataType GetClientDataType() const;
847 virtual void SetClientDataType(wxClientDataType clientDataItemsType);
848 //virtual ListSortOrder GetSortOrder() const;
849 //virtual void SetSortOrder(const ListSortOrder sort);
850
851
852
853 protected:
854
855 ListSortOrder m_sortOrder;
856 wxClientDataType m_clientDataItemsType;
857
858 // ID aware base methods, should be 'final' ie not changed in subclasses
859
860 virtual Boolean CompareItems(DataBrowserItemID itemOneID,
861 DataBrowserItemID itemTwoID,
862 DataBrowserPropertyID sortProperty);
863
864 virtual OSStatus GetSetItemData(DataBrowserItemID itemID,
865 DataBrowserPropertyID property,
866 DataBrowserItemDataRef itemData,
867 Boolean changeValue );
868
869 virtual void ItemNotification(
870 DataBrowserItemID itemID,
871 DataBrowserItemNotification message,
872 DataBrowserItemDataRef itemData);
873
874
875 private :
876
877 bool m_suppressSelection;
878 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataItemBrowserControl)
879 };
880
881 class WXDLLEXPORT wxMacDataItemBrowserSelectionSuppressor
882 {
883 public :
884 wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl *browser);
885 ~wxMacDataItemBrowserSelectionSuppressor();
886
887 private :
888
889 bool m_former;
890 wxMacDataItemBrowserControl* m_browser;
891 };
892
893 // ============================================================================
894 // platform listbox implementation
895 // ============================================================================
896
897 // exposed for reuse in wxCheckListBox
898
899 class WXDLLEXPORT wxMacListBoxItem : public wxMacDataItem
900 {
901 public :
902 wxMacListBoxItem();
903
904 virtual ~wxMacListBoxItem();
905
906 virtual void Notification(wxMacDataItemBrowserControl *owner ,
907 DataBrowserItemNotification message,
908 DataBrowserItemDataRef itemData ) const;
909 };
910
911 class WXDLLEXPORT wxMacDataBrowserListControl : public wxMacDataItemBrowserControl
912 {
913 public:
914 wxMacDataBrowserListControl( wxWindow *peer, const wxPoint& pos, const wxSize& size, long style );
915 wxMacDataBrowserListControl() {}
916 virtual ~wxMacDataBrowserListControl();
917
918 virtual wxMacDataItem* CreateItem();
919
920 // pointing back
921
922 wxWindow * GetPeer() const;
923
924 DECLARE_DYNAMIC_CLASS_NO_COPY(wxMacDataBrowserListControl)
925 };
926
927 // ============================================================================
928 // graphics implementation
929 // ============================================================================
930
931 // draw the image 'upside down' corrected as HIViewDrawCGImage does
932
933 OSStatus WXDLLIMPEXP_CORE wxMacDrawCGImage(
934 CGContextRef inContext,
935 const HIRect * inBounds,
936 CGImageRef inImage) ;
937
938 CGColorRef WXDLLIMPEXP_CORE wxMacCreateCGColorFromHITheme( ThemeBrush brush ) ;
939
940 CGColorSpaceRef WXDLLIMPEXP_CORE wxMacGetGenericRGBColorSpace(void);
941
942 // toplevel.cpp
943
944 class WXDLLEXPORT wxMacDeferredWindowDeleter : public wxObject
945 {
946 public :
947 wxMacDeferredWindowDeleter( WindowRef windowRef );
948 virtual ~wxMacDeferredWindowDeleter();
949
950 protected :
951 WindowRef m_macWindow ;
952 } ;
953
954 #endif // wxUSE_GUI
955
956 #define wxMAC_DEFINE_PROC_GETTER( UPP , x ) \
957 UPP Get##x() \
958 { \
959 static UPP sHandler = NULL; \
960 if ( sHandler == NULL ) \
961 sHandler = New##UPP( x ); \
962 return sHandler; \
963 }
964
965 //---------------------------------------------------------------------------
966 // wxMac string conversions
967 //---------------------------------------------------------------------------
968
969 void wxMacSetupConverters();
970 void wxMacCleanupConverters();
971
972 WXDLLIMPEXP_BASE void wxMacStringToPascal( const wxString&from , StringPtr to );
973 WXDLLIMPEXP_BASE wxString wxMacMakeStringFromPascal( ConstStringPtr from );
974
975 // filefn.cpp
976
977 WXDLLIMPEXP_BASE wxString wxMacFSRefToPath( const FSRef *fsRef , CFStringRef additionalPathComponent = NULL );
978 WXDLLIMPEXP_BASE OSStatus wxMacPathToFSRef( const wxString&path , FSRef *fsRef );
979 WXDLLIMPEXP_BASE wxString wxMacHFSUniStrToString( ConstHFSUniStr255Param uniname );
980
981 #if wxUSE_GUI
982
983 // deprecating QD
984
985 void wxMacLocalToGlobal( WindowRef window , Point*pt );
986 void wxMacGlobalToLocal( WindowRef window , Point*pt );
987
988 #endif
989
990 //---------------------------------------------------------------------------
991 // cocoa bridging utilities
992 //---------------------------------------------------------------------------
993
994 bool wxMacInitCocoa();
995
996 class WXDLLEXPORT wxMacAutoreleasePool
997 {
998 public :
999 wxMacAutoreleasePool();
1000 ~wxMacAutoreleasePool();
1001 private :
1002 void* m_pool;
1003 };
1004
1005 // NSObject
1006
1007 void wxMacCocoaRelease( void* obj );
1008 void wxMacCocoaAutorelease( void* obj );
1009 void wxMacCocoaRetain( void* obj );
1010
1011 #if wxMAC_USE_COCOA
1012
1013 // NSCursor
1014
1015 WX_NSCursor wxMacCocoaCreateStockCursor( int cursor_type );
1016 WX_NSCursor wxMacCocoaCreateCursorFromCGImage( CGImageRef cgImageRef, float hotSpotX, float hotSpotY );
1017 void wxMacCocoaSetCursor( WX_NSCursor cursor );
1018 void wxMacCocoaHideCursor();
1019 void wxMacCocoaShowCursor();
1020
1021 typedef struct tagClassicCursor
1022 {
1023 wxUint16 bits[16];
1024 wxUint16 mask[16];
1025 wxInt16 hotspot[2];
1026 }ClassicCursor;
1027
1028 #else // !wxMAC_USE_COCOA
1029
1030 // non Darwin
1031
1032 typedef Cursor ClassicCursor;
1033
1034 #endif // wxMAC_USE_COCOA
1035
1036 // -------------
1037 // Common to all
1038 // -------------
1039
1040 // Cursor support
1041
1042 const short kwxCursorBullseye = 0;
1043 const short kwxCursorBlank = 1;
1044 const short kwxCursorPencil = 2;
1045 const short kwxCursorMagnifier = 3;
1046 const short kwxCursorNoEntry = 4;
1047 const short kwxCursorPaintBrush = 5;
1048 const short kwxCursorPointRight = 6;
1049 const short kwxCursorPointLeft = 7;
1050 const short kwxCursorQuestionArrow = 8;
1051 const short kwxCursorRightArrow = 9;
1052 const short kwxCursorSizeNS = 10;
1053 const short kwxCursorSize = 11;
1054 const short kwxCursorSizeNESW = 12;
1055 const short kwxCursorSizeNWSE = 13;
1056 const short kwxCursorRoller = 14;
1057 const short kwxCursorLast = kwxCursorRoller;
1058
1059 // exposing our fallback cursor map
1060
1061 extern ClassicCursor gMacCursors[];
1062
1063 #endif
1064 // _WX_PRIVATE_H_