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