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