]> git.saurik.com Git - wxWidgets.git/blob - src/mac/carbon/utils.cpp
ae1ef930d579862799b4d5127f60685dd2d62cde
[wxWidgets.git] / src / mac / carbon / utils.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/utils.cpp
3 // Purpose: Various utilities
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #include "wx/wxprec.h"
13
14 #include "wx/utils.h"
15
16 #ifndef WX_PRECOMP
17 #include "wx/intl.h"
18 #include "wx/app.h"
19 #if wxUSE_GUI
20 #include "wx/toplevel.h"
21 #include "wx/font.h"
22 #endif
23 #endif
24
25 #include "wx/apptrait.h"
26
27 #if wxUSE_GUI
28 #include "wx/mac/uma.h"
29 #endif
30
31 #include <ctype.h>
32
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 #include <stdarg.h>
37
38 #include "MoreFilesX.h"
39
40 #ifndef __DARWIN__
41 #include <Threads.h>
42 #include <Sound.h>
43 #endif
44
45 #if wxUSE_GUI
46 #if TARGET_API_MAC_OSX
47 #include <CoreServices/CoreServices.h>
48 #else
49 #include <DriverServices.h>
50 #include <Multiprocessing.h>
51 #endif
52
53 #ifdef __DARWIN__
54 #include <Carbon/Carbon.h>
55 #else
56 #include <ATSUnicode.h>
57 #include <TextCommon.h>
58 #include <TextEncodingConverter.h>
59 #endif
60
61 #include "wx/mac/private/timer.h"
62 #endif // wxUSE_GUI
63
64 #include "wx/evtloop.h"
65 #include "wx/mac/private.h"
66
67 #if defined(__MWERKS__) && wxUSE_UNICODE
68 #if __MWERKS__ < 0x4100
69 #include <wtime.h>
70 #endif
71 #endif
72
73 #if wxUSE_BASE
74
75 // our OS version is the same in non GUI and GUI cases
76 wxOperatingSystemId wxGetOsVersion(int *majorVsn, int *minorVsn)
77 {
78 SInt32 theSystem;
79 Gestalt(gestaltSystemVersion, &theSystem);
80
81 if ( majorVsn != NULL )
82 *majorVsn = (theSystem >> 8);
83
84 if ( minorVsn != NULL )
85 *minorVsn = (theSystem & 0xFF);
86
87 #if defined( __DARWIN__ )
88 return wxOS_MAC_OSX_DARWIN;
89 #else
90 return wxOS_MAC_OS;
91 #endif
92 }
93
94 extern bool WXDLLEXPORT wxIsDebuggerRunning()
95 {
96 // TODO : try to find out ...
97 return false;
98 }
99
100 // Emit a beeeeeep
101 void wxBell()
102 {
103 #ifndef __LP64__
104 SysBeep(30);
105 #endif
106 }
107
108
109 #endif // wxUSE_BASE
110
111 #if wxUSE_GUI
112
113 wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
114 {
115 // We suppose that toolkit version is the same as OS version under Mac
116 wxGetOsVersion(verMaj, verMin);
117
118 return wxPORT_MAC;
119 }
120
121 wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
122 {
123 return new wxEventLoop;
124 }
125
126 wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
127 {
128 return new wxCarbonTimerImpl(timer);
129 }
130
131 int gs_wxBusyCursorCount = 0;
132 extern wxCursor gMacCurrentCursor;
133 wxCursor gMacStoredActiveCursor;
134
135 // Set the cursor to the busy cursor for all windows
136 void wxBeginBusyCursor(const wxCursor *cursor)
137 {
138 if (gs_wxBusyCursorCount++ == 0)
139 {
140 gMacStoredActiveCursor = gMacCurrentCursor;
141 cursor->MacInstall();
142 }
143 //else: nothing to do, already set
144 }
145
146 // Restore cursor to normal
147 void wxEndBusyCursor()
148 {
149 wxCHECK_RET( gs_wxBusyCursorCount > 0,
150 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
151
152 if (--gs_wxBusyCursorCount == 0)
153 {
154 gMacStoredActiveCursor.MacInstall();
155 gMacStoredActiveCursor = wxNullCursor;
156 }
157 }
158
159 // true if we're between the above two calls
160 bool wxIsBusy()
161 {
162 return (gs_wxBusyCursorCount > 0);
163 }
164
165 #endif // wxUSE_GUI
166
167 #if wxUSE_BASE
168
169 wxString wxMacFindFolderNoSeparator( short vol,
170 OSType folderType,
171 Boolean createFolder)
172 {
173 FSRef fsRef;
174 wxString strDir;
175
176 if ( FSFindFolder( vol, folderType, createFolder, &fsRef) == noErr)
177 {
178 strDir = wxMacFSRefToPath( &fsRef );
179 }
180
181 return strDir;
182 }
183
184 wxString wxMacFindFolder( short vol,
185 OSType folderType,
186 Boolean createFolder)
187 {
188 return wxMacFindFolderNoSeparator(vol, folderType, createFolder) + wxFILE_SEP_PATH;
189 }
190
191 #endif // wxUSE_BASE
192
193 #if wxUSE_GUI
194
195 // Check whether this window wants to process messages, e.g. Stop button
196 // in long calculations.
197 bool wxCheckForInterrupt(wxWindow *WXUNUSED(wnd))
198 {
199 // TODO
200 return false;
201 }
202
203 void wxGetMousePosition( int* x, int* y )
204 {
205 Point pt;
206 #if wxMAC_USE_CORE_GRAPHICS
207 GetGlobalMouse(&pt);
208 #else
209 GetMouse( &pt );
210 LocalToGlobal( &pt );
211 #endif
212 *x = pt.h;
213 *y = pt.v;
214 };
215
216 // Return true if we have a colour display
217 bool wxColourDisplay()
218 {
219 return true;
220 }
221
222 // Returns depth of screen
223 int wxDisplayDepth()
224 {
225 int theDepth = 8;
226 #if wxMAC_USE_CORE_GRAPHICS
227 theDepth = (int) CGDisplayBitsPerPixel(CGMainDisplayID());
228 #else
229 Rect globRect;
230 SetRect(&globRect, -32760, -32760, 32760, 32760);
231 GDHandle theMaxDevice;
232
233 theMaxDevice = GetMaxDevice(&globRect);
234 if (theMaxDevice != NULL)
235 theDepth = (**(**theMaxDevice).gdPMap).pixelSize;
236 #endif
237 return theDepth;
238 }
239
240 // Get size of display
241 void wxDisplaySize(int *width, int *height)
242 {
243 #if wxMAC_USE_CORE_GRAPHICS
244 // TODO adapt for multi-displays
245 CGRect bounds = CGDisplayBounds(CGMainDisplayID());
246 if ( width )
247 *width = (int)bounds.size.width ;
248 if ( height )
249 *height = (int)bounds.size.height;
250 #else
251 BitMap screenBits;
252 GetQDGlobalsScreenBits( &screenBits );
253
254 if (width != NULL)
255 *width = screenBits.bounds.right - screenBits.bounds.left;
256
257 if (height != NULL)
258 *height = screenBits.bounds.bottom - screenBits.bounds.top;
259 #endif
260 }
261
262 void wxDisplaySizeMM(int *width, int *height)
263 {
264 wxDisplaySize(width, height);
265 // on mac 72 is fixed (at least now;-)
266 float cvPt2Mm = 25.4 / 72;
267
268 if (width != NULL)
269 *width = int( *width * cvPt2Mm );
270
271 if (height != NULL)
272 *height = int( *height * cvPt2Mm );
273 }
274
275 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
276 {
277 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
278 HIRect bounds ;
279 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay,kHICoordSpace72DPIGlobal,
280 &bounds);
281 if ( x )
282 *x = bounds.origin.x;
283 if ( y )
284 *y = bounds.origin.y;
285 if ( width )
286 *width = bounds.size.width;
287 if ( height )
288 *height = bounds.size.height;
289 #else
290 Rect r;
291 GetAvailableWindowPositioningBounds( GetMainDevice() , &r );
292 if ( x )
293 *x = r.left;
294 if ( y )
295 *y = r.top;
296 if ( width )
297 *width = r.right - r.left;
298 if ( height )
299 *height = r.bottom - r.top;
300 #endif
301 }
302
303 wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
304 {
305 return wxGenericFindWindowAtPoint(pt);
306 }
307
308 #endif // wxUSE_GUI
309
310 #if wxUSE_BASE
311
312 wxString wxGetOsDescription()
313 {
314 #ifdef WXWIN_OS_DESCRIPTION
315 // use configure generated description if available
316 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION) + wxString(wxT(")"));
317 #else
318 return wxT("MacOS"); //TODO:define further
319 #endif
320 }
321
322 #ifndef __DARWIN__
323 wxString wxGetUserHome (const wxString& user)
324 {
325 // TODO
326 return wxString();
327 }
328
329 bool wxGetDiskSpace(const wxString& path, wxDiskspaceSize_t *pTotal, wxDiskspaceSize_t *pFree)
330 {
331 if ( path.empty() )
332 return false;
333
334 wxString p = path;
335 if (p[0u] == ':' )
336 p = wxGetCwd() + p;
337
338 int pos = p.Find(':');
339 if ( pos != wxNOT_FOUND )
340 p = p.Mid(1,pos);
341
342 p = p + wxT(":");
343
344 OSErr err = noErr;
345
346 FSRef fsRef;
347 err = wxMacPathToFSRef( p , &fsRef );
348 if ( noErr == err )
349 {
350 FSVolumeRefNum vRefNum;
351 err = FSGetVRefNum( &fsRef , &vRefNum );
352 if ( noErr == err )
353 {
354 UInt64 freeBytes , totalBytes;
355 err = FSGetVInfo( vRefNum , NULL , &freeBytes , &totalBytes );
356 if ( noErr == err )
357 {
358 if ( pTotal )
359 *pTotal = wxDiskspaceSize_t( totalBytes );
360 if ( pFree )
361 *pFree = wxDiskspaceSize_t( freeBytes );
362 }
363 }
364 }
365
366 return err == noErr;
367 }
368 #endif // !__DARWIN__
369
370 //---------------------------------------------------------------------------
371 // wxMac Specific utility functions
372 //---------------------------------------------------------------------------
373
374 void wxMacStringToPascal( const wxString&from , StringPtr to )
375 {
376 wxCharBuffer buf = from.mb_str( wxConvLocal );
377 int len = strlen(buf);
378
379 if ( len > 255 )
380 len = 255;
381 to[0] = len;
382 memcpy( (char*) &to[1] , buf , len );
383 }
384
385 wxString wxMacMakeStringFromPascal( ConstStringPtr from )
386 {
387 return wxString( (char*) &from[1] , wxConvLocal , from[0] );
388 }
389
390 // ----------------------------------------------------------------------------
391 // Common Event Support
392 // ----------------------------------------------------------------------------
393
394 extern ProcessSerialNumber gAppProcess;
395
396 void wxMacWakeUp()
397 {
398 ProcessSerialNumber psn;
399 Boolean isSame;
400 psn.highLongOfPSN = 0;
401 psn.lowLongOfPSN = kCurrentProcess;
402 SameProcess( &gAppProcess , &psn , &isSame );
403 if ( isSame )
404 {
405 OSStatus err = noErr;
406
407 #if 0
408 // lead sometimes to race conditions, although all calls used should be thread safe ...
409 static wxMacCarbonEvent s_wakeupEvent;
410 if ( !s_wakeupEvent.IsValid() )
411 {
412 err = s_wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
413 kEventAttributeNone );
414 }
415 if ( err == noErr )
416 {
417
418 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent ) )
419 return;
420 s_wakeupEvent.SetCurrentTime();
421 err = PostEventToQueue(GetMainEventQueue(), s_wakeupEvent,
422 kEventPriorityHigh );
423 }
424 #else
425 wxMacCarbonEvent wakeupEvent;
426 wakeupEvent.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
427 kEventAttributeNone );
428 err = PostEventToQueue(GetMainEventQueue(), wakeupEvent,
429 kEventPriorityHigh );
430 #endif
431 }
432 else
433 {
434 WakeUpProcess( &gAppProcess );
435 }
436 }
437
438 #endif // wxUSE_BASE
439
440 #if wxUSE_GUI
441
442 // ----------------------------------------------------------------------------
443 // Native Struct Conversions
444 // ----------------------------------------------------------------------------
445
446 void wxMacRectToNative( const wxRect *wx , Rect *n )
447 {
448 n->left = wx->x;
449 n->top = wx->y;
450 n->right = wx->x + wx->width;
451 n->bottom = wx->y + wx->height;
452 }
453
454 void wxMacNativeToRect( const Rect *n , wxRect* wx )
455 {
456 wx->x = n->left;
457 wx->y = n->top;
458 wx->width = n->right - n->left;
459 wx->height = n->bottom - n->top;
460 }
461
462 void wxMacPointToNative( const wxPoint* wx , Point *n )
463 {
464 n->h = wx->x;
465 n->v = wx->y;
466 }
467
468 void wxMacNativeToPoint( const Point *n , wxPoint* wx )
469 {
470 wx->x = n->h;
471 wx->y = n->v;
472 }
473
474 // ----------------------------------------------------------------------------
475 // Carbon Event Support
476 // ----------------------------------------------------------------------------
477
478 OSStatus wxMacCarbonEvent::GetParameter(EventParamName inName, EventParamType inDesiredType, UInt32 inBufferSize, void * outData)
479 {
480 return ::GetEventParameter( m_eventRef , inName , inDesiredType , NULL , inBufferSize , NULL , outData );
481 }
482
483 OSStatus wxMacCarbonEvent::SetParameter(EventParamName inName, EventParamType inType, UInt32 inBufferSize, const void * inData)
484 {
485 return ::SetEventParameter( m_eventRef , inName , inType , inBufferSize , inData );
486 }
487
488 // ----------------------------------------------------------------------------
489 // Control Access Support
490 // ----------------------------------------------------------------------------
491
492 IMPLEMENT_DYNAMIC_CLASS( wxMacControl , wxObject )
493
494 wxMacControl::wxMacControl()
495 {
496 Init();
497 }
498
499 wxMacControl::wxMacControl(wxWindow* peer , bool isRootControl )
500 {
501 Init();
502 m_peer = peer;
503 m_isRootControl = isRootControl;
504 }
505
506 wxMacControl::wxMacControl( wxWindow* peer , ControlRef control )
507 {
508 Init();
509 m_peer = peer;
510 m_controlRef = control;
511 }
512
513 wxMacControl::wxMacControl( wxWindow* peer , WXWidget control )
514 {
515 Init();
516 m_peer = peer;
517 m_controlRef = (ControlRef) control;
518 }
519
520 wxMacControl::~wxMacControl()
521 {
522 }
523
524 void wxMacControl::Init()
525 {
526 m_peer = NULL;
527 m_controlRef = NULL;
528 m_needsFocusRect = false;
529 m_isRootControl = false;
530 }
531
532 void wxMacControl::Dispose()
533 {
534 wxASSERT_MSG( m_controlRef != NULL , wxT("Control Handle already NULL, Dispose called twice ?") );
535 wxASSERT_MSG( IsValidControlHandle(m_controlRef) , wxT("Invalid Control Handle (maybe already released) in Dispose") );
536
537 // we cannot check the ref count here anymore, as autorelease objects might delete their refs later
538 // we can have situations when being embedded, where the control gets deleted behind our back, so only
539 // CFRelease if we are safe
540 if ( IsValidControlHandle(m_controlRef) )
541 CFRelease(m_controlRef);
542 m_controlRef = NULL;
543 }
544
545 void wxMacControl::SetReference( URefCon data )
546 {
547 SetControlReference( m_controlRef , data );
548 }
549
550 OSStatus wxMacControl::GetData(ControlPartCode inPartCode , ResType inTag , Size inBufferSize , void * inOutBuffer , Size * outActualSize ) const
551 {
552 return ::GetControlData( m_controlRef , inPartCode , inTag , inBufferSize , inOutBuffer , outActualSize );
553 }
554
555 OSStatus wxMacControl::GetDataSize(ControlPartCode inPartCode , ResType inTag , Size * outActualSize ) const
556 {
557 return ::GetControlDataSize( m_controlRef , inPartCode , inTag , outActualSize );
558 }
559
560 OSStatus wxMacControl::SetData(ControlPartCode inPartCode , ResType inTag , Size inSize , const void * inData)
561 {
562 return ::SetControlData( m_controlRef , inPartCode , inTag , inSize , inData );
563 }
564
565 OSStatus wxMacControl::SendEvent( EventRef event , OptionBits inOptions )
566 {
567 #if TARGET_API_MAC_OSX
568 return SendEventToEventTargetWithOptions( event,
569 HIObjectGetEventTarget( (HIObjectRef) m_controlRef ), inOptions );
570 #else
571 #pragma unused(inOptions)
572 return SendEventToEventTarget(event,GetControlEventTarget( m_controlRef ) );
573 #endif
574 }
575
576 OSStatus wxMacControl::SendHICommand( HICommand &command , OptionBits inOptions )
577 {
578 wxMacCarbonEvent event( kEventClassCommand , kEventCommandProcess );
579
580 event.SetParameter<HICommand>(kEventParamDirectObject,command);
581
582 return SendEvent( event , inOptions );
583 }
584
585 OSStatus wxMacControl::SendHICommand( UInt32 commandID , OptionBits inOptions )
586 {
587 HICommand command;
588
589 memset( &command, 0 , sizeof(command) );
590 command.commandID = commandID;
591 return SendHICommand( command , inOptions );
592 }
593
594 void wxMacControl::Flash( ControlPartCode part , UInt32 ticks )
595 {
596 unsigned long finalTicks;
597
598 HiliteControl( m_controlRef , part );
599 Delay( ticks , &finalTicks );
600 HiliteControl( m_controlRef , kControlNoPart );
601 }
602
603 SInt32 wxMacControl::GetValue() const
604 {
605 return ::GetControl32BitValue( m_controlRef );
606 }
607
608 SInt32 wxMacControl::GetMaximum() const
609 {
610 return ::GetControl32BitMaximum( m_controlRef );
611 }
612
613 SInt32 wxMacControl::GetMinimum() const
614 {
615 return ::GetControl32BitMinimum( m_controlRef );
616 }
617
618 void wxMacControl::SetValue( SInt32 v )
619 {
620 ::SetControl32BitValue( m_controlRef , v );
621 }
622
623 void wxMacControl::SetMinimum( SInt32 v )
624 {
625 ::SetControl32BitMinimum( m_controlRef , v );
626 }
627
628 void wxMacControl::SetMaximum( SInt32 v )
629 {
630 ::SetControl32BitMaximum( m_controlRef , v );
631 }
632
633 void wxMacControl::SetValueAndRange( SInt32 value , SInt32 minimum , SInt32 maximum )
634 {
635 ::SetControl32BitMinimum( m_controlRef , minimum );
636 ::SetControl32BitMaximum( m_controlRef , maximum );
637 ::SetControl32BitValue( m_controlRef , value );
638 }
639
640 OSStatus wxMacControl::SetFocus( ControlFocusPart focusPart )
641 {
642 return SetKeyboardFocus( GetControlOwner( m_controlRef ), m_controlRef, focusPart );
643 }
644
645 bool wxMacControl::HasFocus() const
646 {
647 ControlRef control;
648 GetKeyboardFocus( GetUserFocusWindow() , &control );
649 return control == m_controlRef;
650 }
651
652 void wxMacControl::SetNeedsFocusRect( bool needs )
653 {
654 m_needsFocusRect = needs;
655 }
656
657 bool wxMacControl::NeedsFocusRect() const
658 {
659 return m_needsFocusRect;
660 }
661
662 void wxMacControl::VisibilityChanged(bool WXUNUSED(shown))
663 {
664 }
665
666 void wxMacControl::SuperChangedPosition()
667 {
668 }
669
670 void wxMacControl::SetFont( const wxFont & font , const wxColour& foreground , long windowStyle )
671 {
672 m_font = font;
673 #ifndef __LP64__
674 ControlFontStyleRec fontStyle;
675 if ( font.MacGetThemeFontID() != kThemeCurrentPortFont )
676 {
677 switch ( font.MacGetThemeFontID() )
678 {
679 case kThemeSmallSystemFont :
680 fontStyle.font = kControlFontSmallSystemFont;
681 break;
682
683 case 109 : // mini font
684 fontStyle.font = -5;
685 break;
686
687 case kThemeSystemFont :
688 fontStyle.font = kControlFontBigSystemFont;
689 break;
690
691 default :
692 fontStyle.font = kControlFontBigSystemFont;
693 break;
694 }
695
696 fontStyle.flags = kControlUseFontMask;
697 }
698 else
699 {
700 fontStyle.font = font.MacGetFontNum();
701 fontStyle.style = font.MacGetFontStyle();
702 fontStyle.size = font.MacGetFontSize();
703 fontStyle.flags = kControlUseFontMask | kControlUseFaceMask | kControlUseSizeMask;
704 }
705
706 fontStyle.just = teJustLeft;
707 fontStyle.flags |= kControlUseJustMask;
708 if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_CENTER_HORIZONTAL )
709 fontStyle.just = teJustCenter;
710 else if ( ( windowStyle & wxALIGN_MASK ) & wxALIGN_RIGHT )
711 fontStyle.just = teJustRight;
712
713
714 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
715 // won't get grayed out by the system anymore
716
717 if ( foreground != *wxBLACK )
718 {
719 fontStyle.foreColor = MAC_WXCOLORREF( foreground.GetPixel() );
720 fontStyle.flags |= kControlUseForeColorMask;
721 }
722
723 ::SetControlFontStyle( m_controlRef , &fontStyle );
724 #endif
725 }
726
727 void wxMacControl::SetBackground( const wxBrush &WXUNUSED(brush) )
728 {
729 // TODO
730 // setting up a color proc is not recommended anymore
731 }
732
733 void wxMacControl::SetRange( SInt32 minimum , SInt32 maximum )
734 {
735 ::SetControl32BitMinimum( m_controlRef , minimum );
736 ::SetControl32BitMaximum( m_controlRef , maximum );
737 }
738
739 short wxMacControl::HandleKey( SInt16 keyCode, SInt16 charCode, EventModifiers modifiers )
740 {
741 #ifndef __LP64__
742 return HandleControlKey( m_controlRef , keyCode , charCode , modifiers );
743 #else
744 return 0;
745 #endif
746 }
747
748 void wxMacControl::SetActionProc( ControlActionUPP actionProc )
749 {
750 SetControlAction( m_controlRef , actionProc );
751 }
752
753 void wxMacControl::SetViewSize( SInt32 viewSize )
754 {
755 SetControlViewSize(m_controlRef , viewSize );
756 }
757
758 SInt32 wxMacControl::GetViewSize() const
759 {
760 return GetControlViewSize( m_controlRef );
761 }
762
763 bool wxMacControl::IsVisible() const
764 {
765 return IsControlVisible( m_controlRef );
766 }
767
768 void wxMacControl::SetVisibility( bool visible , bool redraw )
769 {
770 SetControlVisibility( m_controlRef , visible , redraw );
771 }
772
773 bool wxMacControl::IsEnabled() const
774 {
775 #if TARGET_API_MAC_OSX
776 return IsControlEnabled( m_controlRef );
777 #else
778 return IsControlActive( m_controlRef );
779 #endif
780 }
781
782 bool wxMacControl::IsActive() const
783 {
784 return IsControlActive( m_controlRef );
785 }
786
787 void wxMacControl::Enable( bool enable )
788 {
789 if ( enable )
790 EnableControl( m_controlRef );
791 else
792 DisableControl( m_controlRef );
793 }
794
795 void wxMacControl::SetDrawingEnabled( bool enable )
796 {
797 HIViewSetDrawingEnabled( m_controlRef , enable );
798 }
799
800 bool wxMacControl::GetNeedsDisplay() const
801 {
802 return HIViewGetNeedsDisplay( m_controlRef );
803 }
804
805 void wxMacControl::SetNeedsDisplay( RgnHandle where )
806 {
807 if ( !IsVisible() )
808 return;
809
810 HIViewSetNeedsDisplayInRegion( m_controlRef , where , true );
811 }
812
813 void wxMacControl::SetNeedsDisplay( Rect* where )
814 {
815 if ( !IsVisible() )
816 return;
817
818 if ( where != NULL )
819 {
820 RgnHandle update = NewRgn();
821 RectRgn( update , where );
822 HIViewSetNeedsDisplayInRegion( m_controlRef , update , true );
823 DisposeRgn( update );
824 }
825 else
826 HIViewSetNeedsDisplay( m_controlRef , true );
827 }
828
829 void wxMacControl::Convert( wxPoint *pt , wxMacControl *from , wxMacControl *to )
830 {
831 HIPoint hiPoint;
832
833 hiPoint.x = pt->x;
834 hiPoint.y = pt->y;
835 HIViewConvertPoint( &hiPoint , from->m_controlRef , to->m_controlRef );
836 pt->x = (int)hiPoint.x;
837 pt->y = (int)hiPoint.y;
838 }
839
840 void wxMacControl::SetRect( Rect *r )
841 {
842 //A HIRect is actually a CGRect on OSX - which consists of two structures -
843 //CGPoint and CGSize, which have two floats each
844 HIRect hir = { { r->left , r->top }, { r->right - r->left , r->bottom - r->top } };
845 HIViewSetFrame ( m_controlRef , &hir );
846 // eventuall we might have to do a SetVisibility( false , true );
847 // before and a SetVisibility( true , true ); after
848 }
849
850 void wxMacControl::GetRect( Rect *r )
851 {
852 GetControlBounds( m_controlRef , r );
853 }
854
855 void wxMacControl::GetRectInWindowCoords( Rect *r )
856 {
857 UMAGetControlBoundsInWindowCoords( m_controlRef , r );
858 }
859
860 void wxMacControl::GetBestRect( Rect *r )
861 {
862 short baselineoffset;
863
864 GetBestControlRect( m_controlRef , r , &baselineoffset );
865 }
866
867 void wxMacControl::SetLabel( const wxString &title )
868 {
869 wxFontEncoding encoding;
870
871 if ( m_font.Ok() )
872 encoding = m_font.GetEncoding();
873 else
874 encoding = wxFont::GetDefaultEncoding();
875
876 UMASetControlTitle( m_controlRef , title , encoding );
877 }
878
879 void wxMacControl::GetFeatures( UInt32 * features )
880 {
881 GetControlFeatures( m_controlRef , features );
882 }
883
884 OSStatus wxMacControl::GetRegion( ControlPartCode partCode , RgnHandle region )
885 {
886 OSStatus err = GetControlRegion( m_controlRef , partCode , region );
887 return err;
888 }
889
890 OSStatus wxMacControl::SetZOrder( bool above , wxMacControl* other )
891 {
892 #if TARGET_API_MAC_OSX
893 return HIViewSetZOrder( m_controlRef,above ? kHIViewZOrderAbove : kHIViewZOrderBelow,
894 (other != NULL) ? other->m_controlRef : NULL);
895 #else
896 return 0;
897 #endif
898 }
899
900 #if TARGET_API_MAC_OSX
901 // SetNeedsDisplay would not invalidate the children
902 static void InvalidateControlAndChildren( HIViewRef control )
903 {
904 HIViewSetNeedsDisplay( control , true );
905 UInt16 childrenCount = 0;
906 OSStatus err = CountSubControls( control , &childrenCount );
907 if ( err == errControlIsNotEmbedder )
908 return;
909
910 wxASSERT_MSG( err == noErr , wxT("Unexpected error when accessing subcontrols") );
911
912 for ( UInt16 i = childrenCount; i >=1; --i )
913 {
914 HIViewRef child;
915
916 err = GetIndexedSubControl( control , i , & child );
917 if ( err == errControlIsNotEmbedder )
918 return;
919
920 InvalidateControlAndChildren( child );
921 }
922 }
923 #endif
924
925 void wxMacControl::InvalidateWithChildren()
926 {
927 #if TARGET_API_MAC_OSX
928 InvalidateControlAndChildren( m_controlRef );
929 #endif
930 }
931
932 void wxMacControl::ScrollRect( wxRect *r , int dx , int dy )
933 {
934 wxASSERT( r != NULL );
935
936 HIRect scrollarea = CGRectMake( r->x , r->y , r->width , r->height);
937 HIViewScrollRect ( m_controlRef , &scrollarea , dx ,dy );
938 }
939
940 OSType wxMacCreator = 'WXMC';
941 OSType wxMacControlProperty = 'MCCT';
942
943 void wxMacControl::SetReferenceInNativeControl()
944 {
945 void * data = this;
946 verify_noerr( SetControlProperty ( m_controlRef ,
947 wxMacCreator,wxMacControlProperty, sizeof(data), &data ) );
948 }
949
950 wxMacControl* wxMacControl::GetReferenceFromNativeControl(ControlRef control)
951 {
952 wxMacControl* ctl = NULL;
953 ByteCount actualSize;
954 if ( GetControlProperty( control ,wxMacCreator,wxMacControlProperty, sizeof(ctl) ,
955 &actualSize , &ctl ) == noErr )
956 {
957 return ctl;
958 }
959 return NULL;
960 }
961
962 // ============================================================================
963 // DataBrowser Wrapper
964 // ============================================================================
965 //
966 // basing on DataBrowserItemIDs
967 //
968
969 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl , wxMacControl )
970
971 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
972 ControlRef browser,
973 DataBrowserItemID itemID,
974 DataBrowserItemNotification message,
975 DataBrowserItemDataRef itemData )
976 {
977 wxMacDataBrowserControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserControl);
978 if ( ctl != 0 )
979 {
980 ctl->ItemNotification(itemID, message, itemData);
981 }
982 }
983
984 pascal OSStatus wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
985 ControlRef browser,
986 DataBrowserItemID itemID,
987 DataBrowserPropertyID property,
988 DataBrowserItemDataRef itemData,
989 Boolean changeValue )
990 {
991 OSStatus err = errDataBrowserPropertyNotSupported;
992 wxMacDataBrowserControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserControl);
993 if ( ctl != 0 )
994 {
995 err = ctl->GetSetItemData(itemID, property, itemData, changeValue);
996 }
997 return err;
998 }
999
1000 pascal Boolean wxMacDataBrowserControl::DataBrowserCompareProc(
1001 ControlRef browser,
1002 DataBrowserItemID itemOneID,
1003 DataBrowserItemID itemTwoID,
1004 DataBrowserPropertyID sortProperty)
1005 {
1006 wxMacDataBrowserControl* ctl = wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser ), wxMacDataBrowserControl);
1007 if ( ctl != 0 )
1008 {
1009 return ctl->CompareItems(itemOneID, itemTwoID, sortProperty);
1010 }
1011 return false;
1012 }
1013
1014 DataBrowserItemDataUPP gDataBrowserItemDataUPP = NULL;
1015 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP = NULL;
1016 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP = NULL;
1017
1018 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow* peer,
1019 const wxPoint& pos,
1020 const wxSize& size,
1021 long WXUNUSED(style))
1022 : wxMacControl( peer )
1023 {
1024 Rect bounds = wxMacGetBoundsForControl( peer, pos, size );
1025 OSStatus err = ::CreateDataBrowserControl(
1026 MAC_WXHWND(peer->MacGetTopLevelWindowRef()),
1027 &bounds, kDataBrowserListView, &m_controlRef );
1028 SetReferenceInNativeControl();
1029 verify_noerr( err );
1030 if ( gDataBrowserItemCompareUPP == NULL )
1031 gDataBrowserItemCompareUPP = NewDataBrowserItemCompareUPP(DataBrowserCompareProc);
1032 if ( gDataBrowserItemDataUPP == NULL )
1033 gDataBrowserItemDataUPP = NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc);
1034 if ( gDataBrowserItemNotificationUPP == NULL )
1035 {
1036 gDataBrowserItemNotificationUPP =
1037 #if TARGET_API_MAC_OSX
1038 (DataBrowserItemNotificationUPP) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc);
1039 #else
1040 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc);
1041 #endif
1042 }
1043
1044 DataBrowserCallbacks callbacks;
1045 InitializeDataBrowserCallbacks( &callbacks, kDataBrowserLatestCallbacks );
1046
1047 callbacks.u.v1.itemDataCallback = gDataBrowserItemDataUPP;
1048 callbacks.u.v1.itemCompareCallback = gDataBrowserItemCompareUPP;
1049 callbacks.u.v1.itemNotificationCallback = gDataBrowserItemNotificationUPP;
1050 SetCallbacks( &callbacks );
1051
1052 }
1053
1054 OSStatus wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container,
1055 Boolean recurse,
1056 DataBrowserItemState state,
1057 ItemCount *numItems) const
1058 {
1059 return GetDataBrowserItemCount( m_controlRef, container, recurse, state, numItems );
1060 }
1061
1062 OSStatus wxMacDataBrowserControl::GetItems( DataBrowserItemID container,
1063 Boolean recurse,
1064 DataBrowserItemState state,
1065 Handle items) const
1066 {
1067 return GetDataBrowserItems( m_controlRef, container, recurse, state, items );
1068 }
1069
1070 OSStatus wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options )
1071 {
1072 return SetDataBrowserSelectionFlags( m_controlRef, options );
1073 }
1074
1075 OSStatus wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc *columnDesc,
1076 DataBrowserTableViewColumnIndex position )
1077 {
1078 return AddDataBrowserListViewColumn( m_controlRef, columnDesc, position );
1079 }
1080
1081 OSStatus wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position, DataBrowserTableViewColumnID* id ){
1082 return GetDataBrowserTableViewColumnProperty( m_controlRef, position, id );
1083 }
1084
1085 OSStatus wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position )
1086 {
1087 DataBrowserTableViewColumnID id;
1088 GetColumnIDFromIndex( position, &id );
1089 return RemoveDataBrowserTableViewColumn( m_controlRef, id );
1090 }
1091
1092 OSStatus wxMacDataBrowserControl::AutoSizeColumns()
1093 {
1094 return AutoSizeDataBrowserListViewColumns(m_controlRef);
1095 }
1096
1097 OSStatus wxMacDataBrowserControl::SetHasScrollBars( bool horiz, bool vert )
1098 {
1099 return SetDataBrowserHasScrollBars( m_controlRef, horiz, vert );
1100 }
1101
1102 OSStatus wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle )
1103 {
1104 return SetDataBrowserTableViewHiliteStyle( m_controlRef, hiliteStyle );
1105 }
1106
1107 OSStatus wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height)
1108 {
1109 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef, height );
1110 }
1111
1112 OSStatus wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16 *height)
1113 {
1114 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef, height );
1115 }
1116
1117 OSStatus wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks *callbacks)
1118 {
1119 return SetDataBrowserCallbacks( m_controlRef, callbacks );
1120 }
1121
1122 OSStatus wxMacDataBrowserControl::UpdateItems(
1123 DataBrowserItemID container,
1124 UInt32 numItems,
1125 const DataBrowserItemID *items,
1126 DataBrowserPropertyID preSortProperty,
1127 DataBrowserPropertyID propertyID ) const
1128 {
1129 return UpdateDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty, propertyID );
1130 }
1131
1132 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item ) const
1133 {
1134 return IsDataBrowserItemSelected( m_controlRef, item );
1135 }
1136
1137 OSStatus wxMacDataBrowserControl::AddItems(
1138 DataBrowserItemID container,
1139 UInt32 numItems,
1140 const DataBrowserItemID *items,
1141 DataBrowserPropertyID preSortProperty )
1142 {
1143 return AddDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty );
1144 }
1145
1146 OSStatus wxMacDataBrowserControl::RemoveItems(
1147 DataBrowserItemID container,
1148 UInt32 numItems,
1149 const DataBrowserItemID *items,
1150 DataBrowserPropertyID preSortProperty )
1151 {
1152 return RemoveDataBrowserItems( m_controlRef, container, numItems, items, preSortProperty );
1153 }
1154
1155 OSStatus wxMacDataBrowserControl::RevealItem(
1156 DataBrowserItemID item,
1157 DataBrowserPropertyID propertyID,
1158 DataBrowserRevealOptions options ) const
1159 {
1160 return RevealDataBrowserItem( m_controlRef, item, propertyID, options );
1161 }
1162
1163 OSStatus wxMacDataBrowserControl::SetSelectedItems(
1164 UInt32 numItems,
1165 const DataBrowserItemID *items,
1166 DataBrowserSetOption operation )
1167 {
1168 return SetDataBrowserSelectedItems( m_controlRef, numItems, items, operation );
1169 }
1170
1171 OSStatus wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID *first, DataBrowserItemID *last ) const
1172 {
1173 return GetDataBrowserSelectionAnchor( m_controlRef, first, last );
1174 }
1175
1176 OSStatus wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row, DataBrowserItemID * item ) const
1177 {
1178 return GetDataBrowserTableViewItemID( m_controlRef, row, item );
1179 }
1180
1181 OSStatus wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item, DataBrowserTableViewRowIndex * row ) const
1182 {
1183 return GetDataBrowserTableViewItemRow( m_controlRef, item, row );
1184 }
1185
1186 OSStatus wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height )
1187 {
1188 return SetDataBrowserTableViewRowHeight( m_controlRef , height );
1189 }
1190
1191 OSStatus wxMacDataBrowserControl::GetDefaultRowHeight( UInt16 * height ) const
1192 {
1193 return GetDataBrowserTableViewRowHeight( m_controlRef, height );
1194 }
1195
1196 OSStatus wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item , UInt16 height)
1197 {
1198 return SetDataBrowserTableViewItemRowHeight( m_controlRef, item , height );
1199 }
1200
1201 OSStatus wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item , UInt16 *height) const
1202 {
1203 return GetDataBrowserTableViewItemRowHeight( m_controlRef, item , height);
1204 }
1205
1206 OSStatus wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column , UInt16 *width ) const
1207 {
1208 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width );
1209 }
1210
1211 OSStatus wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column , UInt16 width )
1212 {
1213 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef , column , width );
1214 }
1215
1216 OSStatus wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16 *width ) const
1217 {
1218 return GetDataBrowserTableViewColumnWidth( m_controlRef , width );
1219 }
1220
1221 OSStatus wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width )
1222 {
1223 return SetDataBrowserTableViewColumnWidth( m_controlRef , width );
1224 }
1225
1226 OSStatus wxMacDataBrowserControl::GetColumnCount(UInt32* numColumns) const
1227 {
1228 return GetDataBrowserTableViewColumnCount( m_controlRef, numColumns);
1229 }
1230
1231 OSStatus wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column,
1232 DataBrowserTableViewColumnIndex *position) const
1233 {
1234 return GetDataBrowserTableViewColumnPosition( m_controlRef , column , position);
1235 }
1236
1237 OSStatus wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column, DataBrowserTableViewColumnIndex position)
1238 {
1239 return SetDataBrowserTableViewColumnPosition( m_controlRef , column , position);
1240 }
1241
1242 OSStatus wxMacDataBrowserControl::GetScrollPosition( UInt32 *top , UInt32 *left ) const
1243 {
1244 return GetDataBrowserScrollPosition( m_controlRef , top , left );
1245 }
1246
1247 OSStatus wxMacDataBrowserControl::SetScrollPosition( UInt32 top , UInt32 left )
1248 {
1249 return SetDataBrowserScrollPosition( m_controlRef , top , left );
1250 }
1251
1252 OSStatus wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID *column ) const
1253 {
1254 return GetDataBrowserSortProperty( m_controlRef , column );
1255 }
1256
1257 OSStatus wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column )
1258 {
1259 return SetDataBrowserSortProperty( m_controlRef , column );
1260 }
1261
1262 OSStatus wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder *order ) const
1263 {
1264 return GetDataBrowserSortOrder( m_controlRef , order );
1265 }
1266
1267 OSStatus wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order )
1268 {
1269 return SetDataBrowserSortOrder( m_controlRef , order );
1270 }
1271
1272 OSStatus wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property,
1273 DataBrowserPropertyFlags *flags ) const
1274 {
1275 return GetDataBrowserPropertyFlags( m_controlRef , property , flags );
1276 }
1277
1278 OSStatus wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property,
1279 DataBrowserPropertyFlags flags )
1280 {
1281 return SetDataBrowserPropertyFlags( m_controlRef , property , flags );
1282 }
1283
1284 OSStatus wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property,
1285 DataBrowserListViewHeaderDesc *desc ) const
1286 {
1287 return GetDataBrowserListViewHeaderDesc( m_controlRef , property , desc );
1288 }
1289
1290 OSStatus wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property,
1291 DataBrowserListViewHeaderDesc *desc )
1292 {
1293 return SetDataBrowserListViewHeaderDesc( m_controlRef , property , desc );
1294 }
1295
1296 OSStatus wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property ,
1297 Boolean expandableRows )
1298 {
1299 return SetDataBrowserListViewDisclosureColumn( m_controlRef, property, expandableRows);
1300 }
1301
1302 // ============================================================================
1303 // Higher-level Databrowser
1304 // ============================================================================
1305 //
1306 // basing on data item objects
1307 //
1308
1309 wxMacDataItem::wxMacDataItem()
1310 {
1311 m_data = NULL;
1312
1313 m_order = 0;
1314 m_colId = kTextColumnId; // for compat with existing wx*ListBox impls.
1315 }
1316
1317 wxMacDataItem::~wxMacDataItem()
1318 {
1319 }
1320
1321 void wxMacDataItem::SetOrder( SInt32 order )
1322 {
1323 m_order = order;
1324 }
1325
1326 SInt32 wxMacDataItem::GetOrder() const
1327 {
1328 return m_order;
1329 }
1330
1331 void wxMacDataItem::SetData( void* data)
1332 {
1333 m_data = data;
1334 }
1335
1336 void* wxMacDataItem::GetData() const
1337 {
1338 return m_data;
1339 }
1340
1341 short wxMacDataItem::GetColumn()
1342 {
1343 return m_colId;
1344 }
1345
1346 void wxMacDataItem::SetColumn( short col )
1347 {
1348 m_colId = col;
1349 }
1350
1351 void wxMacDataItem::SetLabel( const wxString& str)
1352 {
1353 m_label = str;
1354 m_cfLabel.Assign( str , wxLocale::GetSystemEncoding());
1355 }
1356
1357 const wxString& wxMacDataItem::GetLabel() const
1358 {
1359 return m_label;
1360 }
1361
1362 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl *WXUNUSED(owner) ,
1363 const wxMacDataItem* rhs,
1364 DataBrowserPropertyID sortProperty) const
1365 {
1366 const wxMacDataItem* otherItem = wx_const_cast(wxMacDataItem*,rhs);
1367 bool retval = false;
1368
1369 if ( sortProperty == m_colId ){
1370 retval = m_label.CmpNoCase( otherItem->m_label) < 0;
1371 }
1372
1373 else if ( sortProperty == kNumericOrderColumnId )
1374 retval = m_order < otherItem->m_order;
1375
1376 return retval;
1377 }
1378
1379 OSStatus wxMacDataItem::GetSetData( wxMacDataItemBrowserControl *WXUNUSED(owner) ,
1380 DataBrowserPropertyID property,
1381 DataBrowserItemDataRef itemData,
1382 bool changeValue )
1383 {
1384 OSStatus err = errDataBrowserPropertyNotSupported;
1385 if ( !changeValue )
1386 {
1387 if ( property == m_colId ){
1388 err = ::SetDataBrowserItemDataText( itemData, m_cfLabel );
1389 err = noErr;
1390 }
1391 else if ( property == kNumericOrderColumnId ){
1392 err = ::SetDataBrowserItemDataValue( itemData, m_order );
1393 err = noErr;
1394 }
1395 else{
1396 }
1397 }
1398 else
1399 {
1400 switch (property)
1401 {
1402 // no editable props here
1403 default:
1404 break;
1405 }
1406 }
1407
1408 return err;
1409 }
1410
1411 void wxMacDataItem::Notification(wxMacDataItemBrowserControl *WXUNUSED(owner) ,
1412 DataBrowserItemNotification WXUNUSED(message),
1413 DataBrowserItemDataRef WXUNUSED(itemData) ) const
1414 {
1415 }
1416
1417 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl , wxMacDataBrowserControl )
1418
1419 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow* peer , const wxPoint& pos, const wxSize& size, long style) :
1420 wxMacDataBrowserControl( peer, pos, size, style )
1421 {
1422 m_suppressSelection = false;
1423 m_sortOrder = SortOrder_None;
1424 m_clientDataItemsType = wxClientData_None;
1425 }
1426
1427 wxMacDataItem* wxMacDataItemBrowserControl::CreateItem()
1428 {
1429 return new wxMacDataItem();
1430 }
1431
1432 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl *browser)
1433 {
1434 m_former = browser->SuppressSelection(true);
1435 m_browser = browser;
1436 }
1437
1438 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1439 {
1440 m_browser->SuppressSelection(m_former);
1441 }
1442
1443 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress )
1444 {
1445 bool former = m_suppressSelection;
1446 m_suppressSelection = suppress;
1447
1448 return former;
1449 }
1450
1451 Boolean wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID,
1452 DataBrowserItemID itemTwoID,
1453 DataBrowserPropertyID sortProperty)
1454 {
1455 wxMacDataItem* itemOne = (wxMacDataItem*) itemOneID;
1456 wxMacDataItem* itemTwo = (wxMacDataItem*) itemTwoID;
1457 return CompareItems( itemOne , itemTwo , sortProperty );
1458 }
1459
1460 Boolean wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem* itemOne,
1461 const wxMacDataItem* itemTwo,
1462 DataBrowserPropertyID sortProperty)
1463 {
1464 Boolean retval = false;
1465 if ( itemOne != NULL )
1466 retval = itemOne->IsLessThan( this , itemTwo , sortProperty);
1467 return retval;
1468 }
1469
1470 OSStatus wxMacDataItemBrowserControl::GetSetItemData(
1471 DataBrowserItemID itemID,
1472 DataBrowserPropertyID property,
1473 DataBrowserItemDataRef itemData,
1474 Boolean changeValue )
1475 {
1476 wxMacDataItem* item = (wxMacDataItem*) itemID;
1477 return GetSetItemData(item, property, itemData , changeValue );
1478 }
1479
1480 OSStatus wxMacDataItemBrowserControl::GetSetItemData(
1481 wxMacDataItem* item,
1482 DataBrowserPropertyID property,
1483 DataBrowserItemDataRef itemData,
1484 Boolean changeValue )
1485 {
1486 OSStatus err = errDataBrowserPropertyNotSupported;
1487 switch( property )
1488 {
1489 case kDataBrowserContainerIsClosableProperty :
1490 case kDataBrowserContainerIsSortableProperty :
1491 case kDataBrowserContainerIsOpenableProperty :
1492 // right now default behaviour on these
1493 break;
1494 default :
1495
1496 if ( item != NULL ){
1497 err = item->GetSetData( this, property , itemData , changeValue );
1498 }
1499 break;
1500
1501 }
1502 return err;
1503 }
1504
1505 void wxMacDataItemBrowserControl::ItemNotification(
1506 DataBrowserItemID itemID,
1507 DataBrowserItemNotification message,
1508 DataBrowserItemDataRef itemData)
1509 {
1510 wxMacDataItem* item = (wxMacDataItem*) itemID;
1511 ItemNotification( item , message, itemData);
1512 }
1513
1514 void wxMacDataItemBrowserControl::ItemNotification(
1515 const wxMacDataItem* item,
1516 DataBrowserItemNotification message,
1517 DataBrowserItemDataRef itemData)
1518 {
1519 if (item != NULL)
1520 item->Notification( this, message, itemData);
1521 }
1522
1523 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem* container,
1524 bool recurse , DataBrowserItemState state) const
1525 {
1526 ItemCount numItems = 0;
1527 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID)container,
1528 recurse, state, &numItems ) );
1529 return numItems;
1530 }
1531
1532 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem* container,
1533 bool recurse ) const
1534 {
1535 return GetItemCount( container, recurse, kDataBrowserItemIsSelected );
1536
1537 }
1538
1539 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem* container,
1540 bool recurse , DataBrowserItemState state, wxArrayMacDataItemPtr &items) const
1541 {
1542 Handle handle = NewHandle(0);
1543 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID)container ,
1544 recurse , state, handle) );
1545
1546 int itemCount = GetHandleSize(handle)/sizeof(DataBrowserItemID);
1547 HLock( handle );
1548 wxMacDataItemPtr* itemsArray = (wxMacDataItemPtr*) *handle;
1549 for ( int i = 0; i < itemCount; ++i)
1550 {
1551 items.Add(itemsArray[i]);
1552 }
1553 HUnlock( handle );
1554 DisposeHandle( handle );
1555 }
1556
1557 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem* item) const
1558 {
1559 DataBrowserTableViewRowIndex row;
1560 OSStatus err = GetItemRow( (DataBrowserItemID) item , &row);
1561 wxASSERT( err == noErr);
1562 return row;
1563 }
1564
1565 wxMacDataItem* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n) const
1566 {
1567 DataBrowserItemID id;
1568 OSStatus err = GetItemID( (DataBrowserTableViewRowIndex) n , &id);
1569 wxASSERT( err == noErr);
1570 return (wxMacDataItem*) id;
1571 }
1572
1573 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem *container,
1574 const wxMacDataItem *item , DataBrowserPropertyID property) const
1575 {
1576 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, 1,
1577 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty /* notSorted */, property ) );
1578 }
1579
1580 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem *container,
1581 wxArrayMacDataItemPtr &itemArray , DataBrowserPropertyID property) const
1582 {
1583 unsigned int noItems = itemArray.GetCount();
1584 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1585 for ( unsigned int i = 0; i < noItems; ++i )
1586 items[i] = (DataBrowserItemID) itemArray[i];
1587
1588 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID)container, noItems,
1589 items, kDataBrowserItemNoProperty /* notSorted */, property ) );
1590 delete [] items;
1591 }
1592
1593 void wxMacDataItemBrowserControl::InsertColumn(int colId, DataBrowserPropertyType colType,
1594 const wxString& title, SInt16 just, int defaultWidth)
1595 {
1596 DataBrowserListViewColumnDesc columnDesc;
1597 columnDesc.headerBtnDesc.titleOffset = 0;
1598 columnDesc.headerBtnDesc.version = kDataBrowserListViewLatestHeaderDesc;
1599
1600 columnDesc.headerBtnDesc.btnFontStyle.flags =
1601 kControlUseFontMask | kControlUseJustMask;
1602
1603 columnDesc.headerBtnDesc.btnContentInfo.contentType = kControlContentTextOnly;
1604 columnDesc.headerBtnDesc.btnFontStyle.just = just;
1605 columnDesc.headerBtnDesc.btnFontStyle.font = kControlFontViewSystemFont;
1606 columnDesc.headerBtnDesc.btnFontStyle.style = normal;
1607
1608 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
1609 // defined for other modes?
1610 wxFontEncoding enc;
1611 if ( m_font.Ok() )
1612 enc = m_font.GetEncoding();
1613 else
1614 enc = wxLocale::GetSystemEncoding();
1615 wxMacCFStringHolder cfTitle;
1616 cfTitle.Assign( title, enc );
1617 columnDesc.headerBtnDesc.titleString = cfTitle;
1618
1619 columnDesc.headerBtnDesc.minimumWidth = 0;
1620 columnDesc.headerBtnDesc.maximumWidth = 30000;
1621
1622 columnDesc.propertyDesc.propertyID = (kMinColumnId + colId);
1623 columnDesc.propertyDesc.propertyType = colType;
1624 columnDesc.propertyDesc.propertyFlags = kDataBrowserListViewSortableColumn;
1625 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewTypeSelectColumn;
1626 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1627 columnDesc.propertyDesc.propertyFlags |= kDataBrowserListViewNoGapForIconInHeaderButton;
1628 #endif
1629
1630 verify_noerr( AddColumn( &columnDesc, kDataBrowserListViewAppendColumn ) );
1631
1632 if (defaultWidth > 0){
1633 SetColumnWidth(colId, defaultWidth);
1634 }
1635
1636 }
1637
1638 void wxMacDataItemBrowserControl::SetColumnWidth(int colId, int width)
1639 {
1640 DataBrowserPropertyID id;
1641 GetColumnIDFromIndex(colId, &id);
1642 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id, width));
1643 }
1644
1645 int wxMacDataItemBrowserControl::GetColumnWidth(int colId)
1646 {
1647 DataBrowserPropertyID id;
1648 GetColumnIDFromIndex(colId, &id);
1649 UInt16 result;
1650 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id, &result));
1651 return result;
1652 }
1653
1654 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem *container, wxMacDataItem *item)
1655 {
1656 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, 1,
1657 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty ) );
1658 }
1659
1660 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray )
1661 {
1662 unsigned int noItems = itemArray.GetCount();
1663 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1664 for ( unsigned int i = 0; i < noItems; ++i )
1665 items[i] = (DataBrowserItemID) itemArray[i];
1666
1667 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID)container, noItems,
1668 (DataBrowserItemID*) items, kDataBrowserItemNoProperty ) );
1669 delete [] items;
1670 }
1671
1672 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem *container, wxMacDataItem* item)
1673 {
1674 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 1,
1675 (DataBrowserItemID*) &item, kDataBrowserItemNoProperty );
1676 verify_noerr( err );
1677 }
1678
1679 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem *container, wxArrayMacDataItemPtr &itemArray)
1680 {
1681 unsigned int noItems = itemArray.GetCount();
1682 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1683 for ( unsigned int i = 0; i < noItems; ++i )
1684 items[i] = (DataBrowserItemID) itemArray[i];
1685
1686 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, noItems,
1687 (DataBrowserItemID*) items, kDataBrowserItemNoProperty );
1688 verify_noerr( err );
1689 delete [] items;
1690 }
1691
1692 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem *container)
1693 {
1694 OSStatus err = wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID)container, 0 , NULL , kDataBrowserItemNoProperty );
1695 verify_noerr( err );
1696 }
1697
1698 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem* item , DataBrowserSetOption option)
1699 {
1700 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID*) &item, option ));
1701 }
1702
1703 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option)
1704 {
1705 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL , option ));
1706 }
1707
1708 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr &itemArray , DataBrowserSetOption option)
1709 {
1710 unsigned int noItems = itemArray.GetCount();
1711 DataBrowserItemID *items = new DataBrowserItemID[noItems];
1712 for ( unsigned int i = 0; i < noItems; ++i )
1713 items[i] = (DataBrowserItemID) itemArray[i];
1714
1715 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems, (DataBrowserItemID*) items, option ));
1716 delete [] items;
1717 }
1718
1719 Boolean wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem* item) const
1720 {
1721 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID) item);
1722 }
1723
1724 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem* item, DataBrowserRevealOptions options)
1725 {
1726 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID) item, kDataBrowserNoItem , options ) );
1727 }
1728
1729 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr* first , wxMacDataItemPtr* last) const
1730 {
1731 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID*) first, (DataBrowserItemID*) last) );
1732 }
1733
1734 wxClientDataType wxMacDataItemBrowserControl::GetClientDataType() const
1735 {
1736 return m_clientDataItemsType;
1737 }
1738 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType)
1739 {
1740 m_clientDataItemsType = clientDataItemsType;
1741 }
1742
1743 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
1744 {
1745 return GetItemCount(wxMacDataBrowserRootContainer,false,kDataBrowserItemAnyState);
1746 }
1747
1748 void wxMacDataItemBrowserControl::MacDelete( unsigned int n )
1749 {
1750 wxMacDataItem* item = (wxMacDataItem*)GetItemFromLine( n );
1751 RemoveItem( wxMacDataBrowserRootContainer, item );
1752 }
1753
1754 void wxMacDataItemBrowserControl::MacInsert( unsigned int n,
1755 const wxArrayStringsAdapter& items,
1756 int column )
1757 {
1758 size_t itemsCount = items.GetCount();
1759 if ( itemsCount == 0 )
1760 return;
1761
1762 SInt32 frontLineOrder = 0;
1763
1764 if ( m_sortOrder == SortOrder_None )
1765 {
1766 // increase the order of the lines to be shifted
1767 unsigned int lines = MacGetCount();
1768 for ( unsigned int i = n; i < lines; ++i)
1769 {
1770 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(i);
1771 iter->SetOrder( iter->GetOrder() + itemsCount );
1772 }
1773 if ( n > 0 )
1774 {
1775 wxMacDataItem* iter = (wxMacDataItem*) GetItemFromLine(n-1);
1776 frontLineOrder = iter->GetOrder();
1777 }
1778 }
1779
1780 wxArrayMacDataItemPtr ids;
1781 ids.SetCount( itemsCount );
1782
1783 for ( unsigned int i = 0; i < itemsCount; ++i )
1784 {
1785 wxMacDataItem* item = CreateItem();
1786 item->SetLabel( items[i]);
1787 if ( column != -1 )
1788 item->SetColumn( kMinColumnId + column );
1789
1790 if ( m_sortOrder == SortOrder_None )
1791 item->SetOrder( frontLineOrder + 1 + i );
1792
1793 ids[i] = item;
1794 }
1795
1796 AddItems( wxMacDataBrowserRootContainer, ids );
1797 }
1798
1799 int wxMacDataItemBrowserControl::MacAppend( const wxString& text)
1800 {
1801 wxMacDataItem* item = CreateItem();
1802 item->SetLabel( text );
1803 if ( m_sortOrder == SortOrder_None )
1804 {
1805 unsigned int lines = MacGetCount();
1806 if ( lines == 0 )
1807 item->SetOrder( 1 );
1808 else
1809 {
1810 wxMacDataItem* frontItem = (wxMacDataItem*) GetItemFromLine(lines-1);
1811 item->SetOrder( frontItem->GetOrder() + 1 );
1812 }
1813 }
1814 AddItem( wxMacDataBrowserRootContainer, item );
1815
1816 return GetLineFromItem(item);
1817 }
1818
1819 void wxMacDataItemBrowserControl::MacClear()
1820 {
1821 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
1822 RemoveAllItems(wxMacDataBrowserRootContainer);
1823 }
1824
1825 void wxMacDataItemBrowserControl::MacDeselectAll()
1826 {
1827 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
1828 SetSelectedAllItems( kDataBrowserItemsRemove );
1829 }
1830
1831 void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n, bool select, bool multi )
1832 {
1833 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n);
1834 wxMacDataItemBrowserSelectionSuppressor suppressor(this);
1835
1836 if ( IsItemSelected( item ) != select )
1837 {
1838 if ( select )
1839 SetSelectedItem( item, multi ? kDataBrowserItemsAdd : kDataBrowserItemsAssign );
1840 else
1841 SetSelectedItem( item, kDataBrowserItemsRemove );
1842 }
1843
1844 MacScrollTo( n );
1845 }
1846
1847 bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n ) const
1848 {
1849 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine(n);
1850 return IsItemSelected( item );
1851 }
1852
1853 int wxMacDataItemBrowserControl::MacGetSelection() const
1854 {
1855 wxMacDataItemPtr first, last;
1856 GetSelectionAnchor( &first, &last );
1857
1858 if ( first != NULL )
1859 {
1860 return GetLineFromItem( first );
1861 }
1862
1863 return -1;
1864 }
1865
1866 int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt& aSelections ) const
1867 {
1868 aSelections.Empty();
1869 wxArrayMacDataItemPtr selectedItems;
1870 GetItems( wxMacDataBrowserRootContainer, false , kDataBrowserItemIsSelected, selectedItems);
1871
1872 int count = selectedItems.GetCount();
1873
1874 for ( int i = 0; i < count; ++i)
1875 {
1876 aSelections.Add(GetLineFromItem(selectedItems[i]));
1877 }
1878
1879 return count;
1880 }
1881
1882 void wxMacDataItemBrowserControl::MacSetString( unsigned int n, const wxString& text )
1883 {
1884 // as we don't store the strings we only have to issue a redraw
1885 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine( n);
1886 item->SetLabel( text );
1887 UpdateItem( wxMacDataBrowserRootContainer, item , kTextColumnId );
1888 }
1889
1890 wxString wxMacDataItemBrowserControl::MacGetString( unsigned int n ) const
1891 {
1892 wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n );
1893 return item->GetLabel();
1894 }
1895
1896 void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n, void * data)
1897 {
1898 wxMacDataItem* item = (wxMacDataItem*) GetItemFromLine( n);
1899 item->SetData( data );
1900 // not displayed, therefore no Update infos to DataBrowser
1901 }
1902
1903 void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n) const
1904 {
1905 wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n );
1906 return item->GetData();
1907 }
1908
1909 void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n )
1910 {
1911 UInt32 top , left ;
1912 GetScrollPosition( &top , &left ) ;
1913 wxMacDataItem * item = (wxMacDataItem*) GetItemFromLine( n );
1914
1915 UInt16 height ;
1916 GetRowHeight( (DataBrowserItemID) item , &height ) ;
1917 SetScrollPosition( n * ((UInt32)height) , left ) ;
1918
1919 RevealItem( item , kDataBrowserRevealWithoutSelecting );
1920 }
1921
1922
1923
1924 //
1925 // Tab Control
1926 //
1927
1928 OSStatus wxMacControl::SetTabEnabled( SInt16 tabNo , bool enable )
1929 {
1930 return ::SetTabEnabled( m_controlRef , tabNo , enable );
1931 }
1932
1933 //
1934 // Quartz Support
1935 //
1936
1937 // snippets from Sketch Sample from Apple :
1938
1939 #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
1940
1941 /*
1942 This function locates, opens, and returns the profile reference for the calibrated
1943 Generic RGB color space. It is up to the caller to call CMCloseProfile when done
1944 with the profile reference this function returns.
1945 */
1946 CMProfileRef wxMacOpenGenericProfile()
1947 {
1948 static CMProfileRef cachedRGBProfileRef = NULL;
1949
1950 // we only create the profile reference once
1951 if (cachedRGBProfileRef == NULL)
1952 {
1953 CMProfileLocation loc;
1954
1955 loc.locType = cmPathBasedProfile;
1956 strcpy(loc.u.pathLoc.path, kGenericRGBProfilePathStr);
1957
1958 verify_noerr( CMOpenProfile(&cachedRGBProfileRef, &loc) );
1959 }
1960
1961 // clone the profile reference so that the caller has their own reference, not our cached one
1962 if (cachedRGBProfileRef)
1963 CMCloneProfileRef(cachedRGBProfileRef);
1964
1965 return cachedRGBProfileRef;
1966 }
1967
1968 /*
1969 Return the generic RGB color space. This is a 'get' function and the caller should
1970 not release the returned value unless the caller retains it first. Usually callers
1971 of this routine will immediately use the returned colorspace with CoreGraphics
1972 so they typically do not need to retain it themselves.
1973
1974 This function creates the generic RGB color space once and hangs onto it so it can
1975 return it whenever this function is called.
1976 */
1977
1978 CGColorSpaceRef wxMacGetGenericRGBColorSpace()
1979 {
1980 static wxMacCFRefHolder<CGColorSpaceRef> genericRGBColorSpace;
1981
1982 if (genericRGBColorSpace == NULL)
1983 {
1984 if ( UMAGetSystemVersion() >= 0x1040 )
1985 {
1986 genericRGBColorSpace.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) );
1987 }
1988 else
1989 {
1990 CMProfileRef genericRGBProfile = wxMacOpenGenericProfile();
1991
1992 if (genericRGBProfile)
1993 {
1994 genericRGBColorSpace.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile) );
1995
1996 wxASSERT_MSG( genericRGBColorSpace != NULL, wxT("couldn't create the generic RGB color space") );
1997
1998 // we opened the profile so it is up to us to close it
1999 CMCloseProfile(genericRGBProfile);
2000 }
2001 }
2002 }
2003
2004 return genericRGBColorSpace;
2005 }
2006
2007 #ifndef __LP64__
2008
2009 wxMacPortSaver::wxMacPortSaver( GrafPtr port )
2010 {
2011 ::GetPort( &m_port );
2012 ::SetPort( port );
2013 }
2014
2015 wxMacPortSaver::~wxMacPortSaver()
2016 {
2017 ::SetPort( m_port );
2018 }
2019 #endif
2020
2021 void wxMacGlobalToLocal( WindowRef window , Point*pt )
2022 {
2023 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
2024 HIPoint p = CGPointMake( pt->h, pt->v );
2025 HIViewRef contentView ;
2026 // TODO check toolbar offset
2027 HIViewFindByID( HIViewGetRoot( window ), kHIViewWindowContentID , &contentView) ;
2028 HIPointConvert( &p, kHICoordSpace72DPIGlobal, NULL, kHICoordSpaceView, contentView );
2029 pt->h = p.x;
2030 pt->v = p.y;
2031 #else
2032 QDGlobalToLocalPoint( GetWindowPort(window), pt ) ;
2033 #endif
2034 }
2035
2036 void wxMacLocalToGlobal( WindowRef window , Point*pt )
2037 {
2038 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
2039 HIPoint p = CGPointMake( pt->h, pt->v );
2040 HIViewRef contentView ;
2041 // TODO check toolbar offset
2042 HIViewFindByID( HIViewGetRoot( window ), kHIViewWindowContentID , &contentView) ;
2043 HIPointConvert( &p, kHICoordSpaceView, contentView, kHICoordSpace72DPIGlobal, NULL );
2044 pt->h = p.x;
2045 pt->v = p.y;
2046 #else
2047 QDLocalToGlobalPoint( GetWindowPort(window), pt ) ;
2048 #endif
2049 }
2050
2051 #endif // wxUSE_GUI