1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/utils.cpp
3 // Purpose: Various utilities
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
20 #include "wx/toplevel.h"
25 #include "wx/apptrait.h"
28 #include "wx/mac/uma.h"
38 #include "MoreFilesX.h"
46 #if TARGET_API_MAC_OSX
47 #include <CoreServices/CoreServices.h>
49 #include <DriverServices.h>
50 #include <Multiprocessing.h>
54 #include <Carbon/Carbon.h>
56 #include <ATSUnicode.h>
57 #include <TextCommon.h>
58 #include <TextEncodingConverter.h>
61 #include "wx/mac/private/timer.h"
64 #include "wx/evtloop.h"
65 #include "wx/mac/private.h"
67 #if defined(__MWERKS__) && wxUSE_UNICODE
68 #if __MWERKS__ < 0x4100 || !defined(__DARWIN__)
75 // our OS version is the same in non GUI and GUI cases
76 wxOperatingSystemId
wxGetOsVersion(int *majorVsn
, int *minorVsn
)
79 Gestalt(gestaltSystemVersion
, &theSystem
);
81 if ( majorVsn
!= NULL
)
82 *majorVsn
= (theSystem
>> 8);
84 if ( minorVsn
!= NULL
)
85 *minorVsn
= (theSystem
& 0xFF);
87 #if defined( __DARWIN__ )
88 return wxOS_MAC_OSX_DARWIN
;
94 // ----------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
98 #if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
100 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
102 #ifndef __MetroNubUtils__
103 #include "MetroNubUtils.h"
110 #if TARGET_API_MAC_CARBON
112 #include <CodeFragments.h>
114 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
116 ProcPtr gCallUniversalProc_Proc
= NULL
;
120 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
122 static long fRunOnce
= false;
125 Boolean
IsMetroNubInstalled()
132 gMetroNubEntry
= NULL
;
134 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
136 // look for MetroNub's Gestalt selector
137 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
139 #if TARGET_API_MAC_CARBON
140 if (gCallUniversalProc_Proc
== NULL
)
142 CFragConnectionID connectionID
;
145 ProcPtr symbolAddress
;
147 CFragSymbolClass symbolClass
;
149 symbolAddress
= NULL
;
150 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
151 &connectionID
, &mainAddress
, errorString
);
155 gCallUniversalProc_Proc
= NULL
;
159 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
160 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
164 gCallUniversalProc_Proc
= NULL
;
171 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
173 // make sure the version of the API is compatible
174 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
175 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
178 gMetroNubEntry
= block
;
187 #if TARGET_API_MAC_CARBON
188 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
190 return (gMetroNubEntry
!= NULL
);
194 Boolean
IsMWDebuggerRunning()
196 if (IsMetroNubInstalled())
197 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
202 Boolean
AmIBeingMWDebugged()
204 if (IsMetroNubInstalled())
205 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
210 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
212 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
217 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
222 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
226 // defined in unix/utilsunx.cpp for Mac OS X
228 // get full hostname (with domain name if possible)
229 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
231 return wxGetHostName(buf
, maxSize
);
234 // Get user ID e.g. jacs
235 bool wxGetUserId(wxChar
*buf
, int maxSize
)
237 return wxGetUserName( buf
, maxSize
);
240 const wxChar
* wxGetHomeDir(wxString
*pstr
)
242 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
);
243 return pstr
->c_str();
246 // Get hostname only (without domain name)
247 bool wxGetHostName(wxChar
*buf
, int maxSize
)
249 // Gets Chooser name of user by examining a System resource.
252 const short kComputerNameID
= -16413;
254 short oldResFile
= CurResFile();
256 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
257 UseResFile(oldResFile
);
259 if (chooserName
&& *chooserName
)
261 HLock( (Handle
) chooserName
);
262 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
263 HUnlock( (Handle
) chooserName
);
264 ReleaseResource( (Handle
) chooserName
);
265 wxStrncpy( buf
, name
, maxSize
- 1 );
271 // Get user name e.g. Stefan Csomor
272 bool wxGetUserName(wxChar
*buf
, int maxSize
)
274 // Gets Chooser name of user by examining a System resource.
277 const short kChooserNameID
= -16096;
279 short oldResFile
= CurResFile();
281 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
282 UseResFile(oldResFile
);
284 if (chooserName
&& *chooserName
)
286 HLock( (Handle
) chooserName
);
287 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
288 HUnlock( (Handle
) chooserName
);
289 ReleaseResource( (Handle
) chooserName
);
290 wxStrncpy( buf
, name
, maxSize
- 1 );
296 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
, int flags
)
302 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
304 // TODO : under classic there is no environement support, under X yes
308 // set the env var name to the given value, return true on success
309 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxString
& value
)
311 // TODO : under classic there is no environement support, under X yes
315 WXDLLEXPORT
bool wxUnsetEnv(const wxString
& var
)
317 // TODO : under classic there is no environement support, under X yes
321 // Execute a program in an Interactive Shell
322 bool wxShell(const wxString
& command
)
328 // Shutdown or reboot the PC
329 bool wxShutdown(wxShutdownFlags wFlags
)
335 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
336 wxMemorySize
wxGetFreeMemory()
338 return (wxMemorySize
)FreeMem();
343 void wxMicroSleep(unsigned long microseconds
)
345 AbsoluteTime wakeup
= AddDurationToAbsolute( microseconds
* durationMicrosecond
, UpTime());
346 MPDelayUntil( & wakeup
);
349 void wxMilliSleep(unsigned long milliseconds
)
351 AbsoluteTime wakeup
= AddDurationToAbsolute( milliseconds
, UpTime());
352 MPDelayUntil( & wakeup
);
355 void wxSleep(int nSecs
)
357 wxMilliSleep(1000*nSecs
);
362 // Consume all events until no more left
367 #endif // !__DARWIN__
382 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
384 // We suppose that toolkit version is the same as OS version under Mac
385 wxGetOsVersion(verMaj
, verMin
);
390 wxEventLoopBase
* wxGUIAppTraits::CreateEventLoop()
392 return new wxEventLoop
;
395 wxTimerImpl
* wxGUIAppTraits::CreateTimerImpl(wxTimer
*timer
)
397 return new wxCarbonTimerImpl(timer
);
400 int gs_wxBusyCursorCount
= 0;
401 extern wxCursor gMacCurrentCursor
;
402 wxCursor gMacStoredActiveCursor
;
404 // Set the cursor to the busy cursor for all windows
405 void wxBeginBusyCursor(const wxCursor
*cursor
)
407 if (gs_wxBusyCursorCount
++ == 0)
409 gMacStoredActiveCursor
= gMacCurrentCursor
;
410 cursor
->MacInstall();
412 //else: nothing to do, already set
415 // Restore cursor to normal
416 void wxEndBusyCursor()
418 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
419 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
421 if (--gs_wxBusyCursorCount
== 0)
423 gMacStoredActiveCursor
.MacInstall();
424 gMacStoredActiveCursor
= wxNullCursor
;
428 // true if we're between the above two calls
431 return (gs_wxBusyCursorCount
> 0);
438 wxString
wxMacFindFolderNoSeparator( short vol
,
440 Boolean createFolder
)
445 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
447 strDir
= wxMacFSRefToPath( &fsRef
);
453 wxString
wxMacFindFolder( short vol
,
455 Boolean createFolder
)
457 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
464 // Check whether this window wants to process messages, e.g. Stop button
465 // in long calculations.
466 bool wxCheckForInterrupt(wxWindow
*wnd
)
472 void wxGetMousePosition( int* x
, int* y
)
475 #if wxMAC_USE_CORE_GRAPHICS
479 LocalToGlobal( &pt
);
485 // Return true if we have a colour display
486 bool wxColourDisplay()
491 // Returns depth of screen
495 #if wxMAC_USE_CORE_GRAPHICS
496 theDepth
= (int) CGDisplayBitsPerPixel(CGMainDisplayID());
499 SetRect(&globRect
, -32760, -32760, 32760, 32760);
500 GDHandle theMaxDevice
;
502 theMaxDevice
= GetMaxDevice(&globRect
);
503 if (theMaxDevice
!= NULL
)
504 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
509 // Get size of display
510 void wxDisplaySize(int *width
, int *height
)
512 #if wxMAC_USE_CORE_GRAPHICS
513 // TODO adapt for multi-displays
514 CGRect bounds
= CGDisplayBounds(CGMainDisplayID());
516 *width
= (int)bounds
.size
.width
;
518 *height
= (int)bounds
.size
.height
;
521 GetQDGlobalsScreenBits( &screenBits
);
524 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
527 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
531 void wxDisplaySizeMM(int *width
, int *height
)
533 wxDisplaySize(width
, height
);
534 // on mac 72 is fixed (at least now;-)
535 float cvPt2Mm
= 25.4 / 72;
538 *width
= int( *width
* cvPt2Mm
);
541 *height
= int( *height
* cvPt2Mm
);
544 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
546 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
548 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
551 *x
= bounds
.origin
.x
;
553 *y
= bounds
.origin
.y
;
555 *width
= bounds
.size
.width
;
557 *height
= bounds
.size
.height
;
560 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
566 *width
= r
.right
- r
.left
;
568 *height
= r
.bottom
- r
.top
;
572 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
574 return wxGenericFindWindowAtPoint(pt
);
581 wxString
wxGetOsDescription()
583 #ifdef WXWIN_OS_DESCRIPTION
584 // use configure generated description if available
585 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
587 return wxT("MacOS"); //TODO:define further
592 wxChar
*wxGetUserHome (const wxString
& user
)
598 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
607 int pos
= p
.Find(':');
608 if ( pos
!= wxNOT_FOUND
)
616 err
= wxMacPathToFSRef( p
, &fsRef
);
619 FSVolumeRefNum vRefNum
;
620 err
= FSGetVRefNum( &fsRef
, &vRefNum
);
623 UInt64 freeBytes
, totalBytes
;
624 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
);
628 *pTotal
= wxDiskspaceSize_t( totalBytes
);
630 *pFree
= wxDiskspaceSize_t( freeBytes
);
637 #endif // !__DARWIN__
639 //---------------------------------------------------------------------------
640 // wxMac Specific utility functions
641 //---------------------------------------------------------------------------
643 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
645 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
646 int len
= strlen(buf
);
651 memcpy( (char*) &to
[1] , buf
, len
);
654 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
656 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
659 // ----------------------------------------------------------------------------
660 // Common Event Support
661 // ----------------------------------------------------------------------------
663 extern ProcessSerialNumber gAppProcess
;
667 ProcessSerialNumber psn
;
669 psn
.highLongOfPSN
= 0;
670 psn
.lowLongOfPSN
= kCurrentProcess
;
671 SameProcess( &gAppProcess
, &psn
, &isSame
);
675 OSStatus err
= noErr
;
678 // lead sometimes to race conditions, although all calls used should be thread safe ...
679 static wxMacCarbonEvent s_wakeupEvent
;
680 if ( !s_wakeupEvent
.IsValid() )
682 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
683 kEventAttributeNone
);
688 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
690 s_wakeupEvent
.SetCurrentTime();
691 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
692 kEventPriorityHigh
);
695 wxMacCarbonEvent wakeupEvent
;
696 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
697 kEventAttributeNone
);
698 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
699 kEventPriorityHigh
);
702 PostEvent( nullEvent
, 0 );
707 WakeUpProcess( &gAppProcess
);
715 // ----------------------------------------------------------------------------
716 // Native Struct Conversions
717 // ----------------------------------------------------------------------------
719 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
723 n
->right
= wx
->x
+ wx
->width
;
724 n
->bottom
= wx
->y
+ wx
->height
;
727 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
731 wx
->width
= n
->right
- n
->left
;
732 wx
->height
= n
->bottom
- n
->top
;
735 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
741 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
747 // ----------------------------------------------------------------------------
748 // Carbon Event Support
749 // ----------------------------------------------------------------------------
751 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
753 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
756 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
758 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
761 // ----------------------------------------------------------------------------
762 // Control Access Support
763 // ----------------------------------------------------------------------------
765 IMPLEMENT_DYNAMIC_CLASS( wxMacControl
, wxObject
)
767 wxMacControl::wxMacControl()
772 wxMacControl::wxMacControl(wxWindow
* peer
, bool isRootControl
)
776 m_isRootControl
= isRootControl
;
779 wxMacControl::wxMacControl( wxWindow
* peer
, ControlRef control
)
783 m_controlRef
= control
;
786 wxMacControl::wxMacControl( wxWindow
* peer
, WXWidget control
)
790 m_controlRef
= (ControlRef
) control
;
793 wxMacControl::~wxMacControl()
797 void wxMacControl::Init()
801 m_needsFocusRect
= false;
802 m_isRootControl
= false;
805 void wxMacControl::Dispose()
807 wxASSERT_MSG( m_controlRef
!= NULL
, wxT("Control Handle already NULL, Dispose called twice ?") );
808 wxASSERT_MSG( IsValidControlHandle(m_controlRef
) , wxT("Invalid Control Handle (maybe already released) in Dispose") );
810 // we cannot check the ref count here anymore, as autorelease objects might delete their refs later
811 // we can have situations when being embedded, where the control gets deleted behind our back, so only
812 // CFRelease if we are safe
813 if ( IsValidControlHandle(m_controlRef
) )
814 CFRelease(m_controlRef
);
818 void wxMacControl::SetReference( URefCon data
)
820 SetControlReference( m_controlRef
, data
);
823 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
825 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
);
828 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
830 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
);
833 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
835 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
);
838 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
840 #if TARGET_API_MAC_OSX
841 return SendEventToEventTargetWithOptions( event
,
842 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
844 #pragma unused(inOptions)
845 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) );
849 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
851 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
853 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
);
855 return SendEvent( event
, inOptions
);
858 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
862 memset( &command
, 0 , sizeof(command
) );
863 command
.commandID
= commandID
;
864 return SendHICommand( command
, inOptions
);
867 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
869 unsigned long finalTicks
;
871 HiliteControl( m_controlRef
, part
);
872 Delay( ticks
, &finalTicks
);
873 HiliteControl( m_controlRef
, kControlNoPart
);
876 SInt32
wxMacControl::GetValue() const
878 return ::GetControl32BitValue( m_controlRef
);
881 SInt32
wxMacControl::GetMaximum() const
883 return ::GetControl32BitMaximum( m_controlRef
);
886 SInt32
wxMacControl::GetMinimum() const
888 return ::GetControl32BitMinimum( m_controlRef
);
891 void wxMacControl::SetValue( SInt32 v
)
893 ::SetControl32BitValue( m_controlRef
, v
);
896 void wxMacControl::SetMinimum( SInt32 v
)
898 ::SetControl32BitMinimum( m_controlRef
, v
);
901 void wxMacControl::SetMaximum( SInt32 v
)
903 ::SetControl32BitMaximum( m_controlRef
, v
);
906 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
908 ::SetControl32BitMinimum( m_controlRef
, minimum
);
909 ::SetControl32BitMaximum( m_controlRef
, maximum
);
910 ::SetControl32BitValue( m_controlRef
, value
);
913 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
915 return SetKeyboardFocus( GetControlOwner( m_controlRef
), m_controlRef
, focusPart
);
918 bool wxMacControl::HasFocus() const
921 GetKeyboardFocus( GetUserFocusWindow() , &control
);
922 return control
== m_controlRef
;
925 void wxMacControl::SetNeedsFocusRect( bool needs
)
927 m_needsFocusRect
= needs
;
930 bool wxMacControl::NeedsFocusRect() const
932 return m_needsFocusRect
;
935 void wxMacControl::VisibilityChanged(bool shown
)
939 void wxMacControl::SuperChangedPosition()
943 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
946 ControlFontStyleRec fontStyle
;
947 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
949 switch ( font
.MacGetThemeFontID() )
951 case kThemeSmallSystemFont
:
952 fontStyle
.font
= kControlFontSmallSystemFont
;
955 case 109 : // mini font
959 case kThemeSystemFont
:
960 fontStyle
.font
= kControlFontBigSystemFont
;
964 fontStyle
.font
= kControlFontBigSystemFont
;
968 fontStyle
.flags
= kControlUseFontMask
;
972 fontStyle
.font
= font
.MacGetFontNum();
973 fontStyle
.style
= font
.MacGetFontStyle();
974 fontStyle
.size
= font
.MacGetFontSize();
975 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
978 fontStyle
.just
= teJustLeft
;
979 fontStyle
.flags
|= kControlUseJustMask
;
980 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
981 fontStyle
.just
= teJustCenter
;
982 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
983 fontStyle
.just
= teJustRight
;
986 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
987 // won't get grayed out by the system anymore
989 if ( foreground
!= *wxBLACK
)
991 fontStyle
.foreColor
= MAC_WXCOLORREF( foreground
.GetPixel() );
992 fontStyle
.flags
|= kControlUseForeColorMask
;
995 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
998 void wxMacControl::SetBackground( const wxBrush
&WXUNUSED(brush
) )
1001 // setting up a color proc is not recommended anymore
1004 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
1006 ::SetControl32BitMinimum( m_controlRef
, minimum
);
1007 ::SetControl32BitMaximum( m_controlRef
, maximum
);
1010 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
1013 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
);
1019 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
1021 SetControlAction( m_controlRef
, actionProc
);
1024 void wxMacControl::SetViewSize( SInt32 viewSize
)
1026 SetControlViewSize(m_controlRef
, viewSize
);
1029 SInt32
wxMacControl::GetViewSize() const
1031 return GetControlViewSize( m_controlRef
);
1034 bool wxMacControl::IsVisible() const
1036 return IsControlVisible( m_controlRef
);
1039 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
1041 SetControlVisibility( m_controlRef
, visible
, redraw
);
1044 bool wxMacControl::IsEnabled() const
1046 #if TARGET_API_MAC_OSX
1047 return IsControlEnabled( m_controlRef
);
1049 return IsControlActive( m_controlRef
);
1053 bool wxMacControl::IsActive() const
1055 return IsControlActive( m_controlRef
);
1058 void wxMacControl::Enable( bool enable
)
1061 EnableControl( m_controlRef
);
1063 DisableControl( m_controlRef
);
1066 void wxMacControl::SetDrawingEnabled( bool enable
)
1068 HIViewSetDrawingEnabled( m_controlRef
, enable
);
1071 bool wxMacControl::GetNeedsDisplay() const
1073 return HIViewGetNeedsDisplay( m_controlRef
);
1076 void wxMacControl::SetNeedsDisplay( RgnHandle where
)
1081 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, true );
1084 void wxMacControl::SetNeedsDisplay( Rect
* where
)
1089 if ( where
!= NULL
)
1091 RgnHandle update
= NewRgn();
1092 RectRgn( update
, where
);
1093 HIViewSetNeedsDisplayInRegion( m_controlRef
, update
, true );
1094 DisposeRgn( update
);
1097 HIViewSetNeedsDisplay( m_controlRef
, true );
1100 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
1106 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
);
1107 pt
->x
= (int)hiPoint
.x
;
1108 pt
->y
= (int)hiPoint
.y
;
1111 void wxMacControl::SetRect( Rect
*r
)
1113 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1114 //CGPoint and CGSize, which have two floats each
1115 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} };
1116 HIViewSetFrame ( m_controlRef
, &hir
);
1117 // eventuall we might have to do a SetVisibility( false , true );
1118 // before and a SetVisibility( true , true ); after
1121 void wxMacControl::GetRect( Rect
*r
)
1123 GetControlBounds( m_controlRef
, r
);
1126 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
1128 UMAGetControlBoundsInWindowCoords( m_controlRef
, r
);
1131 void wxMacControl::GetBestRect( Rect
*r
)
1133 short baselineoffset
;
1135 GetBestControlRect( m_controlRef
, r
, &baselineoffset
);
1138 void wxMacControl::SetLabel( const wxString
&title
)
1140 wxFontEncoding encoding
;
1143 encoding
= m_font
.GetEncoding();
1145 encoding
= wxFont::GetDefaultEncoding();
1147 UMASetControlTitle( m_controlRef
, title
, encoding
);
1150 void wxMacControl::GetFeatures( UInt32
* features
)
1152 GetControlFeatures( m_controlRef
, features
);
1155 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
1157 OSStatus err
= GetControlRegion( m_controlRef
, partCode
, region
);
1161 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
1163 #if TARGET_API_MAC_OSX
1164 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
1165 (other
!= NULL
) ? other
->m_controlRef
: NULL
);
1171 #if TARGET_API_MAC_OSX
1172 // SetNeedsDisplay would not invalidate the children
1173 static void InvalidateControlAndChildren( HIViewRef control
)
1175 HIViewSetNeedsDisplay( control
, true );
1176 UInt16 childrenCount
= 0;
1177 OSStatus err
= CountSubControls( control
, &childrenCount
);
1178 if ( err
== errControlIsNotEmbedder
)
1181 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") );
1183 for ( UInt16 i
= childrenCount
; i
>=1; --i
)
1187 err
= GetIndexedSubControl( control
, i
, & child
);
1188 if ( err
== errControlIsNotEmbedder
)
1191 InvalidateControlAndChildren( child
);
1196 void wxMacControl::InvalidateWithChildren()
1198 #if TARGET_API_MAC_OSX
1199 InvalidateControlAndChildren( m_controlRef
);
1203 void wxMacControl::ScrollRect( wxRect
*r
, int dx
, int dy
)
1205 wxASSERT( r
!= NULL
);
1207 HIRect scrollarea
= CGRectMake( r
->x
, r
->y
, r
->width
, r
->height
);
1208 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
);
1211 OSType wxMacCreator
= 'WXMC';
1212 OSType wxMacControlProperty
= 'MCCT';
1214 void wxMacControl::SetReferenceInNativeControl()
1217 verify_noerr( SetControlProperty ( m_controlRef
,
1218 wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data
) );
1221 wxMacControl
* wxMacControl::GetReferenceFromNativeControl(ControlRef control
)
1223 wxMacControl
* ctl
= NULL
;
1224 ByteCount actualSize
;
1225 if ( GetControlProperty( control
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) ,
1226 &actualSize
, &ctl
) == noErr
)
1233 // ============================================================================
1234 // DataBrowser Wrapper
1235 // ============================================================================
1237 // basing on DataBrowserItemIDs
1240 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl
, wxMacControl
)
1242 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
1244 DataBrowserItemID itemID
,
1245 DataBrowserItemNotification message
,
1246 DataBrowserItemDataRef itemData
)
1248 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
1251 ctl
->ItemNotification(itemID
, message
, itemData
);
1255 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
1257 DataBrowserItemID itemID
,
1258 DataBrowserPropertyID property
,
1259 DataBrowserItemDataRef itemData
,
1260 Boolean changeValue
)
1262 OSStatus err
= errDataBrowserPropertyNotSupported
;
1263 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
1266 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
1271 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
1273 DataBrowserItemID itemOneID
,
1274 DataBrowserItemID itemTwoID
,
1275 DataBrowserPropertyID sortProperty
)
1277 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
1280 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
1285 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
1286 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
1287 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
1289 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) : wxMacControl( peer
)
1291 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
1292 OSStatus err
= ::CreateDataBrowserControl(
1293 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
1294 &bounds
, kDataBrowserListView
, &m_controlRef
);
1295 SetReferenceInNativeControl();
1296 verify_noerr( err
);
1297 if ( gDataBrowserItemCompareUPP
== NULL
)
1298 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
1299 if ( gDataBrowserItemDataUPP
== NULL
)
1300 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
1301 if ( gDataBrowserItemNotificationUPP
== NULL
)
1303 gDataBrowserItemNotificationUPP
=
1304 #if TARGET_API_MAC_OSX
1305 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
1307 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc
);
1311 DataBrowserCallbacks callbacks
;
1312 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
1314 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
1315 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
1316 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
1317 SetCallbacks( &callbacks
);
1321 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
1323 DataBrowserItemState state
,
1324 ItemCount
*numItems
) const
1326 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
1329 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
1331 DataBrowserItemState state
,
1334 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
1337 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1339 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
1342 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1343 DataBrowserTableViewColumnIndex position
)
1345 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
1348 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
){
1349 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
1352 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
1354 DataBrowserTableViewColumnID id
;
1355 GetColumnIDFromIndex( position
, &id
);
1356 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
1359 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
1361 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
1364 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
1366 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
1369 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1371 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
1374 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
1376 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1379 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
1381 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1384 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
1386 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
1389 OSStatus
wxMacDataBrowserControl::UpdateItems(
1390 DataBrowserItemID container
,
1392 const DataBrowserItemID
*items
,
1393 DataBrowserPropertyID preSortProperty
,
1394 DataBrowserPropertyID propertyID
) const
1396 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
1399 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
1401 return IsDataBrowserItemSelected( m_controlRef
, item
);
1404 OSStatus
wxMacDataBrowserControl::AddItems(
1405 DataBrowserItemID container
,
1407 const DataBrowserItemID
*items
,
1408 DataBrowserPropertyID preSortProperty
)
1410 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1413 OSStatus
wxMacDataBrowserControl::RemoveItems(
1414 DataBrowserItemID container
,
1416 const DataBrowserItemID
*items
,
1417 DataBrowserPropertyID preSortProperty
)
1419 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1422 OSStatus
wxMacDataBrowserControl::RevealItem(
1423 DataBrowserItemID item
,
1424 DataBrowserPropertyID propertyID
,
1425 DataBrowserRevealOptions options
) const
1427 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
1430 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
1432 const DataBrowserItemID
*items
,
1433 DataBrowserSetOption operation
)
1435 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
1438 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
1440 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
1443 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
1445 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
1448 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
1450 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
1453 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
1455 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1458 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
1460 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1463 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
1465 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1468 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
1470 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1473 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
1475 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1478 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
1480 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1483 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
1485 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1488 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
1490 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1493 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
1495 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
1498 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
1499 DataBrowserTableViewColumnIndex
*position
) const
1501 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1504 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
1506 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1509 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
1511 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1514 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
1516 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1519 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
1521 return GetDataBrowserSortProperty( m_controlRef
, column
);
1524 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
1526 return SetDataBrowserSortProperty( m_controlRef
, column
);
1529 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
1531 return GetDataBrowserSortOrder( m_controlRef
, order
);
1534 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
1536 return SetDataBrowserSortOrder( m_controlRef
, order
);
1539 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
1540 DataBrowserPropertyFlags
*flags
) const
1542 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1545 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
1546 DataBrowserPropertyFlags flags
)
1548 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1551 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
1552 DataBrowserListViewHeaderDesc
*desc
) const
1554 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1557 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
1558 DataBrowserListViewHeaderDesc
*desc
)
1560 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1563 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
1564 Boolean expandableRows
)
1566 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
1569 // ============================================================================
1570 // Higher-level Databrowser
1571 // ============================================================================
1573 // basing on data item objects
1576 wxMacDataItem::wxMacDataItem()
1581 m_colId
= kTextColumnId
; // for compat with existing wx*ListBox impls.
1584 wxMacDataItem::~wxMacDataItem()
1588 void wxMacDataItem::SetOrder( SInt32 order
)
1593 SInt32
wxMacDataItem::GetOrder() const
1598 void wxMacDataItem::SetData( void* data
)
1603 void* wxMacDataItem::GetData() const
1608 short wxMacDataItem::GetColumn()
1613 void wxMacDataItem::SetColumn( short col
)
1618 void wxMacDataItem::SetLabel( const wxString
& str
)
1621 m_cfLabel
.Assign( str
, wxLocale::GetSystemEncoding());
1624 const wxString
& wxMacDataItem::GetLabel() const
1629 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*owner
,
1630 const wxMacDataItem
* rhs
,
1631 DataBrowserPropertyID sortProperty
) const
1633 const wxMacDataItem
* otherItem
= wx_const_cast(wxMacDataItem
*,rhs
);
1634 bool retval
= false;
1636 if ( sortProperty
== m_colId
){
1637 retval
= m_label
.CmpNoCase( otherItem
->m_label
) < 0;
1640 else if ( sortProperty
== kNumericOrderColumnId
)
1641 retval
= m_order
< otherItem
->m_order
;
1646 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*owner
,
1647 DataBrowserPropertyID property
,
1648 DataBrowserItemDataRef itemData
,
1651 OSStatus err
= errDataBrowserPropertyNotSupported
;
1654 if ( property
== m_colId
){
1655 err
= ::SetDataBrowserItemDataText( itemData
, m_cfLabel
);
1658 else if ( property
== kNumericOrderColumnId
){
1659 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
1669 // no editable props here
1678 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*owner
,
1679 DataBrowserItemNotification message
,
1680 DataBrowserItemDataRef itemData
) const
1684 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
1686 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1687 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1689 m_suppressSelection
= false;
1690 m_sortOrder
= SortOrder_None
;
1691 m_clientDataItemsType
= wxClientData_None
;
1694 wxMacDataItem
* wxMacDataItemBrowserControl::CreateItem()
1696 return new wxMacDataItem();
1699 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1701 m_former
= browser
->SuppressSelection(true);
1702 m_browser
= browser
;
1705 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1707 m_browser
->SuppressSelection(m_former
);
1710 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
1712 bool former
= m_suppressSelection
;
1713 m_suppressSelection
= suppress
;
1718 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
1719 DataBrowserItemID itemTwoID
,
1720 DataBrowserPropertyID sortProperty
)
1722 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1723 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1724 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1727 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
1728 const wxMacDataItem
* itemTwo
,
1729 DataBrowserPropertyID sortProperty
)
1731 Boolean retval
= false;
1732 if ( itemOne
!= NULL
)
1733 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1737 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1738 DataBrowserItemID itemID
,
1739 DataBrowserPropertyID property
,
1740 DataBrowserItemDataRef itemData
,
1741 Boolean changeValue
)
1743 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1744 return GetSetItemData(item
, property
, itemData
, changeValue
);
1747 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1748 wxMacDataItem
* item
,
1749 DataBrowserPropertyID property
,
1750 DataBrowserItemDataRef itemData
,
1751 Boolean changeValue
)
1753 OSStatus err
= errDataBrowserPropertyNotSupported
;
1756 case kDataBrowserContainerIsClosableProperty
:
1757 case kDataBrowserContainerIsSortableProperty
:
1758 case kDataBrowserContainerIsOpenableProperty
:
1759 // right now default behaviour on these
1763 if ( item
!= NULL
){
1764 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1772 void wxMacDataItemBrowserControl::ItemNotification(
1773 DataBrowserItemID itemID
,
1774 DataBrowserItemNotification message
,
1775 DataBrowserItemDataRef itemData
)
1777 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1778 ItemNotification( item
, message
, itemData
);
1781 void wxMacDataItemBrowserControl::ItemNotification(
1782 const wxMacDataItem
* item
,
1783 DataBrowserItemNotification message
,
1784 DataBrowserItemDataRef itemData
)
1787 item
->Notification( this, message
, itemData
);
1790 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
1791 bool recurse
, DataBrowserItemState state
) const
1793 ItemCount numItems
= 0;
1794 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
1795 recurse
, state
, &numItems
) );
1799 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
1800 bool recurse
) const
1802 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
1806 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
1807 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1809 Handle handle
= NewHandle(0);
1810 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
1811 recurse
, state
, handle
) );
1813 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1815 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1816 for ( int i
= 0; i
< itemCount
; ++i
)
1818 items
.Add(itemsArray
[i
]);
1821 DisposeHandle( handle
);
1824 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
1826 DataBrowserTableViewRowIndex row
;
1827 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1828 wxASSERT( err
== noErr
);
1832 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
1834 DataBrowserItemID id
;
1835 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1836 wxASSERT( err
== noErr
);
1837 return (wxMacDataItem
*) id
;
1840 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
1841 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1843 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
1844 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1847 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
1848 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1850 unsigned int noItems
= itemArray
.GetCount();
1851 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1852 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1853 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1855 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
1856 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1860 void wxMacDataItemBrowserControl::InsertColumn(int colId
, DataBrowserPropertyType colType
,
1861 const wxString
& title
, SInt16 just
, int defaultWidth
)
1863 DataBrowserListViewColumnDesc columnDesc
;
1864 columnDesc
.headerBtnDesc
.titleOffset
= 0;
1865 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
1867 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
1868 kControlUseFontMask
| kControlUseJustMask
;
1870 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
1871 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
1872 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
1873 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
1875 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
1876 // defined for other modes?
1879 enc
= m_font
.GetEncoding();
1881 enc
= wxLocale::GetSystemEncoding();
1882 wxMacCFStringHolder cfTitle
;
1883 cfTitle
.Assign( title
, enc
);
1884 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
1886 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
1887 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
1889 columnDesc
.propertyDesc
.propertyID
= (kMinColumnId
+ colId
);
1890 columnDesc
.propertyDesc
.propertyType
= colType
;
1891 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
1892 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1893 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
1895 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1896 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
1899 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
1901 if (defaultWidth
> 0){
1902 SetColumnWidth(colId
, defaultWidth
);
1907 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
1909 DataBrowserPropertyID id
;
1910 GetColumnIDFromIndex(colId
, &id
);
1911 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
1914 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
1916 DataBrowserPropertyID id
;
1917 GetColumnIDFromIndex(colId
, &id
);
1919 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
1923 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1925 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
1926 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1929 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1931 unsigned int noItems
= itemArray
.GetCount();
1932 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1933 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1934 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1936 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
1937 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1941 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1943 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
1944 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
1945 verify_noerr( err
);
1948 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1950 unsigned int noItems
= itemArray
.GetCount();
1951 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1952 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1953 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1955 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
1956 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
1957 verify_noerr( err
);
1961 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
1963 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
1964 verify_noerr( err
);
1967 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
1969 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
1972 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
1974 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
1977 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
1979 unsigned int noItems
= itemArray
.GetCount();
1980 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1981 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1982 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1984 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
1988 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
1990 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
1993 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
1995 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
1998 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
2000 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
2003 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
2005 return m_clientDataItemsType
;
2007 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
2009 m_clientDataItemsType
= clientDataItemsType
;
2012 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
2014 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);
2017 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
2019 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
2020 RemoveItem( wxMacDataBrowserRootContainer
, item
);
2023 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, const wxString
& text
, int column
)
2025 wxMacDataItem
* newItem
= CreateItem();
2026 newItem
->SetLabel( text
);
2028 newItem
->SetColumn( kMinColumnId
+ column
);
2030 if ( m_sortOrder
== SortOrder_None
)
2032 // increase the order of the lines to be shifted
2033 unsigned int lines
= MacGetCount();
2034 for ( unsigned int i
= n
; i
< lines
; ++i
)
2036 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
2037 iter
->SetOrder( iter
->GetOrder() + 1 );
2040 SInt32 frontLineOrder
= 0;
2043 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
2044 frontLineOrder
= iter
->GetOrder();
2046 newItem
->SetOrder( frontLineOrder
+ 1 );
2049 AddItem( wxMacDataBrowserRootContainer
, newItem
);
2052 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, const wxArrayString
& items
, int column
)
2054 size_t itemsCount
= items
.GetCount();
2055 if ( itemsCount
== 0 )
2058 SInt32 frontLineOrder
= 0;
2060 if ( m_sortOrder
== SortOrder_None
)
2062 // increase the order of the lines to be shifted
2063 unsigned int lines
= MacGetCount();
2064 for ( unsigned int i
= n
; i
< lines
; ++i
)
2066 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
2067 iter
->SetOrder( iter
->GetOrder() + itemsCount
);
2071 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
2072 frontLineOrder
= iter
->GetOrder();
2076 wxArrayMacDataItemPtr ids
;
2077 ids
.SetCount( itemsCount
);
2079 for ( unsigned int i
= 0; i
< itemsCount
; ++i
)
2081 wxMacDataItem
* item
= CreateItem();
2082 item
->SetLabel( items
[i
]);
2084 item
->SetColumn( kMinColumnId
+ column
);
2086 if ( m_sortOrder
== SortOrder_None
)
2087 item
->SetOrder( frontLineOrder
+ 1 + i
);
2092 AddItems( wxMacDataBrowserRootContainer
, ids
);
2095 int wxMacDataItemBrowserControl::MacAppend( const wxString
& text
)
2097 wxMacDataItem
* item
= CreateItem();
2098 item
->SetLabel( text
);
2099 if ( m_sortOrder
== SortOrder_None
)
2101 unsigned int lines
= MacGetCount();
2103 item
->SetOrder( 1 );
2106 wxMacDataItem
* frontItem
= (wxMacDataItem
*) GetItemFromLine(lines
-1);
2107 item
->SetOrder( frontItem
->GetOrder() + 1 );
2110 AddItem( wxMacDataBrowserRootContainer
, item
);
2112 return GetLineFromItem(item
);
2115 void wxMacDataItemBrowserControl::MacClear()
2117 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2118 RemoveAllItems(wxMacDataBrowserRootContainer
);
2121 void wxMacDataItemBrowserControl::MacDeselectAll()
2123 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2124 SetSelectedAllItems( kDataBrowserItemsRemove
);
2127 void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n
, bool select
, bool multi
)
2129 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
2130 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2132 if ( IsItemSelected( item
) != select
)
2135 SetSelectedItem( item
, multi
? kDataBrowserItemsAdd
: kDataBrowserItemsAssign
);
2137 SetSelectedItem( item
, kDataBrowserItemsRemove
);
2143 bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n
) const
2145 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
2146 return IsItemSelected( item
);
2149 int wxMacDataItemBrowserControl::MacGetSelection() const
2151 wxMacDataItemPtr first
, last
;
2152 GetSelectionAnchor( &first
, &last
);
2154 if ( first
!= NULL
)
2156 return GetLineFromItem( first
);
2162 int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt
& aSelections
) const
2164 aSelections
.Empty();
2165 wxArrayMacDataItemPtr selectedItems
;
2166 GetItems( wxMacDataBrowserRootContainer
, false , kDataBrowserItemIsSelected
, selectedItems
);
2168 int count
= selectedItems
.GetCount();
2170 for ( int i
= 0; i
< count
; ++i
)
2172 aSelections
.Add(GetLineFromItem(selectedItems
[i
]));
2178 void wxMacDataItemBrowserControl::MacSetString( unsigned int n
, const wxString
& text
)
2180 // as we don't store the strings we only have to issue a redraw
2181 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2182 item
->SetLabel( text
);
2183 UpdateItem( wxMacDataBrowserRootContainer
, item
, kTextColumnId
);
2186 wxString
wxMacDataItemBrowserControl::MacGetString( unsigned int n
) const
2188 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2189 return item
->GetLabel();
2192 void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n
, void * data
)
2194 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2195 item
->SetData( data
);
2196 // not displayed, therefore no Update infos to DataBrowser
2199 void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n
) const
2201 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2202 return item
->GetData();
2205 void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n
)
2207 RevealItem( GetItemFromLine( n
) , kDataBrowserRevealWithoutSelecting
);
2216 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
2218 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
2225 #ifdef __WXMAC_OSX__
2226 // snippets from Sketch Sample from Apple :
2228 #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
2231 This function locates, opens, and returns the profile reference for the calibrated
2232 Generic RGB color space. It is up to the caller to call CMCloseProfile when done
2233 with the profile reference this function returns.
2235 CMProfileRef
wxMacOpenGenericProfile()
2237 static CMProfileRef cachedRGBProfileRef
= NULL
;
2239 // we only create the profile reference once
2240 if (cachedRGBProfileRef
== NULL
)
2242 CMProfileLocation loc
;
2244 loc
.locType
= cmPathBasedProfile
;
2245 strcpy(loc
.u
.pathLoc
.path
, kGenericRGBProfilePathStr
);
2247 verify_noerr( CMOpenProfile(&cachedRGBProfileRef
, &loc
) );
2250 // clone the profile reference so that the caller has their own reference, not our cached one
2251 if (cachedRGBProfileRef
)
2252 CMCloneProfileRef(cachedRGBProfileRef
);
2254 return cachedRGBProfileRef
;
2258 Return the generic RGB color space. This is a 'get' function and the caller should
2259 not release the returned value unless the caller retains it first. Usually callers
2260 of this routine will immediately use the returned colorspace with CoreGraphics
2261 so they typically do not need to retain it themselves.
2263 This function creates the generic RGB color space once and hangs onto it so it can
2264 return it whenever this function is called.
2267 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
2269 static wxMacCFRefHolder
<CGColorSpaceRef
> genericRGBColorSpace
;
2271 if (genericRGBColorSpace
== NULL
)
2273 if ( UMAGetSystemVersion() >= 0x1040 )
2275 genericRGBColorSpace
.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) );
2279 CMProfileRef genericRGBProfile
= wxMacOpenGenericProfile();
2281 if (genericRGBProfile
)
2283 genericRGBColorSpace
.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile
) );
2285 wxASSERT_MSG( genericRGBColorSpace
!= NULL
, wxT("couldn't create the generic RGB color space") );
2287 // we opened the profile so it is up to us to close it
2288 CMCloseProfile(genericRGBProfile
);
2293 return genericRGBColorSpace
;
2299 wxMacPortSaver::wxMacPortSaver( GrafPtr port
)
2301 ::GetPort( &m_port
);
2305 wxMacPortSaver::~wxMacPortSaver()
2307 ::SetPort( m_port
);
2311 void wxMacGlobalToLocal( WindowRef window
, Point
*pt
)
2313 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
2314 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
2315 HIViewRef contentView
;
2316 // TODO check toolbar offset
2317 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
2318 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
2322 QDGlobalToLocalPoint( GetWindowPort(window
), pt
) ;
2326 void wxMacLocalToGlobal( WindowRef window
, Point
*pt
)
2328 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
2329 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
2330 HIViewRef contentView
;
2331 // TODO check toolbar offset
2332 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
2333 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
2337 QDLocalToGlobalPoint( GetWindowPort(window
), pt
) ;