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