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>
62 #include "wx/mac/private.h"
64 #if defined(__MWERKS__) && wxUSE_UNICODE
65 #if __MWERKS__ < 0x4100 || !defined(__DARWIN__)
72 // our OS version is the same in non GUI and GUI cases
73 wxOperatingSystemId
wxGetOsVersion(int *majorVsn
, int *minorVsn
)
76 Gestalt(gestaltSystemVersion
, &theSystem
);
78 if ( majorVsn
!= NULL
)
79 *majorVsn
= (theSystem
>> 8);
81 if ( minorVsn
!= NULL
)
82 *minorVsn
= (theSystem
& 0xFF);
84 #if defined( __DARWIN__ )
85 return wxOS_MAC_OSX_DARWIN
;
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
95 #if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
97 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
99 #ifndef __MetroNubUtils__
100 #include "MetroNubUtils.h"
107 #if TARGET_API_MAC_CARBON
109 #include <CodeFragments.h>
111 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
113 ProcPtr gCallUniversalProc_Proc
= NULL
;
117 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
119 static long fRunOnce
= false;
122 Boolean
IsMetroNubInstalled()
129 gMetroNubEntry
= NULL
;
131 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
133 // look for MetroNub's Gestalt selector
134 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
136 #if TARGET_API_MAC_CARBON
137 if (gCallUniversalProc_Proc
== NULL
)
139 CFragConnectionID connectionID
;
142 ProcPtr symbolAddress
;
144 CFragSymbolClass symbolClass
;
146 symbolAddress
= NULL
;
147 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
148 &connectionID
, &mainAddress
, errorString
);
152 gCallUniversalProc_Proc
= NULL
;
156 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
157 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
161 gCallUniversalProc_Proc
= NULL
;
168 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
170 // make sure the version of the API is compatible
171 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
172 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
175 gMetroNubEntry
= block
;
184 #if TARGET_API_MAC_CARBON
185 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
187 return (gMetroNubEntry
!= NULL
);
191 Boolean
IsMWDebuggerRunning()
193 if (IsMetroNubInstalled())
194 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
199 Boolean
AmIBeingMWDebugged()
201 if (IsMetroNubInstalled())
202 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
207 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
209 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
214 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
219 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
223 // defined in unix/utilsunx.cpp for Mac OS X
225 // get full hostname (with domain name if possible)
226 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
228 return wxGetHostName(buf
, maxSize
);
231 // Get user ID e.g. jacs
232 bool wxGetUserId(wxChar
*buf
, int maxSize
)
234 return wxGetUserName( buf
, maxSize
);
237 const wxChar
* wxGetHomeDir(wxString
*pstr
)
239 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
);
240 return pstr
->c_str();
243 // Get hostname only (without domain name)
244 bool wxGetHostName(wxChar
*buf
, int maxSize
)
246 // Gets Chooser name of user by examining a System resource.
249 const short kComputerNameID
= -16413;
251 short oldResFile
= CurResFile();
253 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
254 UseResFile(oldResFile
);
256 if (chooserName
&& *chooserName
)
258 HLock( (Handle
) chooserName
);
259 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
260 HUnlock( (Handle
) chooserName
);
261 ReleaseResource( (Handle
) chooserName
);
262 wxStrncpy( buf
, name
, maxSize
- 1 );
268 // Get user name e.g. Stefan Csomor
269 bool wxGetUserName(wxChar
*buf
, int maxSize
)
271 // Gets Chooser name of user by examining a System resource.
274 const short kChooserNameID
= -16096;
276 short oldResFile
= CurResFile();
278 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
279 UseResFile(oldResFile
);
281 if (chooserName
&& *chooserName
)
283 HLock( (Handle
) chooserName
);
284 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
285 HUnlock( (Handle
) chooserName
);
286 ReleaseResource( (Handle
) chooserName
);
287 wxStrncpy( buf
, name
, maxSize
- 1 );
293 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
, int flags
)
299 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
301 // TODO : under classic there is no environement support, under X yes
305 // set the env var name to the given value, return true on success
306 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
308 // TODO : under classic there is no environement support, under X yes
312 // Execute a program in an Interactive Shell
313 bool wxShell(const wxString
& command
)
319 // Shutdown or reboot the PC
320 bool wxShutdown(wxShutdownFlags wFlags
)
326 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
327 wxMemorySize
wxGetFreeMemory()
329 return (wxMemorySize
)FreeMem();
334 void wxMicroSleep(unsigned long microseconds
)
336 AbsoluteTime wakeup
= AddDurationToAbsolute( microseconds
* durationMicrosecond
, UpTime());
337 MPDelayUntil( & wakeup
);
340 void wxMilliSleep(unsigned long milliseconds
)
342 AbsoluteTime wakeup
= AddDurationToAbsolute( milliseconds
, UpTime());
343 MPDelayUntil( & wakeup
);
346 void wxSleep(int nSecs
)
348 wxMilliSleep(1000*nSecs
);
353 // Consume all events until no more left
358 #endif // !__DARWIN__
371 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
373 // We suppose that toolkit version is the same as OS version under Mac
374 wxGetOsVersion(verMaj
, verMin
);
379 // Reading and writing resources (eg WIN.INI, .Xdefaults)
381 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
387 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
390 buf
.Printf(wxT("%.4f"), value
);
392 return wxWriteResource(section
, entry
, buf
, file
);
395 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
398 buf
.Printf(wxT("%ld"), value
);
400 return wxWriteResource(section
, entry
, buf
, file
);
403 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
406 buf
.Printf(wxT("%d"), value
);
408 return wxWriteResource(section
, entry
, buf
, file
);
411 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
417 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
420 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
423 *value
= (float)strtod(s
, NULL
);
430 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
433 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
436 *value
= strtol(s
, NULL
, 10);
443 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
446 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
449 *value
= (int)strtol(s
, NULL
, 10);
455 #endif // wxUSE_RESOURCES
457 int gs_wxBusyCursorCount
= 0;
458 extern wxCursor gMacCurrentCursor
;
459 wxCursor gMacStoredActiveCursor
;
461 // Set the cursor to the busy cursor for all windows
462 void wxBeginBusyCursor(const wxCursor
*cursor
)
464 if (gs_wxBusyCursorCount
++ == 0)
466 gMacStoredActiveCursor
= gMacCurrentCursor
;
467 cursor
->MacInstall();
469 //else: nothing to do, already set
472 // Restore cursor to normal
473 void wxEndBusyCursor()
475 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
476 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
478 if (--gs_wxBusyCursorCount
== 0)
480 gMacStoredActiveCursor
.MacInstall();
481 gMacStoredActiveCursor
= wxNullCursor
;
485 // true if we're between the above two calls
488 return (gs_wxBusyCursorCount
> 0);
495 wxString
wxMacFindFolderNoSeparator( short vol
,
497 Boolean createFolder
)
502 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
504 strDir
= wxMacFSRefToPath( &fsRef
);
510 wxString
wxMacFindFolder( short vol
,
512 Boolean createFolder
)
514 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
521 // Check whether this window wants to process messages, e.g. Stop button
522 // in long calculations.
523 bool wxCheckForInterrupt(wxWindow
*wnd
)
529 void wxGetMousePosition( int* x
, int* y
)
534 LocalToGlobal( &pt
);
539 // Return true if we have a colour display
540 bool wxColourDisplay()
545 // Returns depth of screen
549 SetRect(&globRect
, -32760, -32760, 32760, 32760);
550 GDHandle theMaxDevice
;
553 theMaxDevice
= GetMaxDevice(&globRect
);
554 if (theMaxDevice
!= NULL
)
555 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
560 // Get size of display
561 void wxDisplaySize(int *width
, int *height
)
564 GetQDGlobalsScreenBits( &screenBits
);
567 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
570 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
573 void wxDisplaySizeMM(int *width
, int *height
)
575 wxDisplaySize(width
, height
);
576 // on mac 72 is fixed (at least now;-)
577 float cvPt2Mm
= 25.4 / 72;
580 *width
= int( *width
* cvPt2Mm
);
583 *height
= int( *height
* cvPt2Mm
);
586 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
590 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
596 *width
= r
.right
- r
.left
;
598 *height
= r
.bottom
- r
.top
;
601 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
603 return wxGenericFindWindowAtPoint(pt
);
610 wxString
wxGetOsDescription()
612 #ifdef WXWIN_OS_DESCRIPTION
613 // use configure generated description if available
614 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
616 return wxT("MacOS"); //TODO:define further
621 wxChar
*wxGetUserHome (const wxString
& user
)
627 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
636 int pos
= p
.Find(':');
637 if ( pos
!= wxNOT_FOUND
)
645 err
= wxMacPathToFSRef( p
, &fsRef
);
648 FSVolumeRefNum vRefNum
;
649 err
= FSGetVRefNum( &fsRef
, &vRefNum
);
652 UInt64 freeBytes
, totalBytes
;
653 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
);
657 *pTotal
= wxDiskspaceSize_t( totalBytes
);
659 *pFree
= wxDiskspaceSize_t( freeBytes
);
666 #endif // !__DARWIN__
668 //---------------------------------------------------------------------------
669 // wxMac Specific utility functions
670 //---------------------------------------------------------------------------
672 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
674 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
675 int len
= strlen(buf
);
680 memcpy( (char*) &to
[1] , buf
, len
);
683 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
685 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
688 // ----------------------------------------------------------------------------
689 // Common Event Support
690 // ----------------------------------------------------------------------------
692 extern ProcessSerialNumber gAppProcess
;
696 ProcessSerialNumber psn
;
698 psn
.highLongOfPSN
= 0;
699 psn
.lowLongOfPSN
= kCurrentProcess
;
700 SameProcess( &gAppProcess
, &psn
, &isSame
);
704 OSStatus err
= noErr
;
707 // lead sometimes to race conditions, although all calls used should be thread safe ...
708 static wxMacCarbonEvent s_wakeupEvent
;
709 if ( !s_wakeupEvent
.IsValid() )
711 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
712 kEventAttributeNone
);
717 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
719 s_wakeupEvent
.SetCurrentTime();
720 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
721 kEventPriorityHigh
);
724 wxMacCarbonEvent wakeupEvent
;
725 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
726 kEventAttributeNone
);
727 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
728 kEventPriorityHigh
);
731 PostEvent( nullEvent
, 0 );
736 WakeUpProcess( &gAppProcess
);
744 // ----------------------------------------------------------------------------
745 // Native Struct Conversions
746 // ----------------------------------------------------------------------------
748 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
752 n
->right
= wx
->x
+ wx
->width
;
753 n
->bottom
= wx
->y
+ wx
->height
;
756 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
760 wx
->width
= n
->right
- n
->left
;
761 wx
->height
= n
->bottom
- n
->top
;
764 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
770 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
776 // ----------------------------------------------------------------------------
777 // Carbon Event Support
778 // ----------------------------------------------------------------------------
780 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
782 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
785 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
787 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
790 // ----------------------------------------------------------------------------
791 // Control Access Support
792 // ----------------------------------------------------------------------------
794 wxMacControl::wxMacControl(wxWindow
* peer
, bool isRootControl
)
798 m_isRootControl
= isRootControl
;
801 wxMacControl::wxMacControl( wxWindow
* peer
, ControlRef control
)
805 m_controlRef
= control
;
808 wxMacControl::wxMacControl( wxWindow
* peer
, WXWidget control
)
812 m_controlRef
= (ControlRef
) control
;
815 wxMacControl::~wxMacControl()
819 void wxMacControl::Init()
823 m_needsFocusRect
= false;
824 m_isRootControl
= false;
827 void wxMacControl::Dispose()
829 wxASSERT_MSG( IsValidControlHandle(m_controlRef
) , wxT("Invalid Control Handle (maybe already released) in Dispose") );
831 CFIndex count
= CFGetRetainCount( m_controlRef
) ;
832 wxASSERT_MSG( count
== 1 , wxT("Reference Count of native control was not 1 in Dispose") );
834 ::DisposeControl( m_controlRef
);
838 void wxMacControl::SetReference( SInt32 data
)
840 SetControlReference( m_controlRef
, data
);
843 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
845 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
);
848 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
850 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
);
853 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
855 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
);
858 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
860 #if TARGET_API_MAC_OSX
861 return SendEventToEventTargetWithOptions( event
,
862 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
864 #pragma unused(inOptions)
865 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) );
869 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
871 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
873 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
);
875 return SendEvent( event
, inOptions
);
878 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
882 memset( &command
, 0 , sizeof(command
) );
883 command
.commandID
= commandID
;
884 return SendHICommand( command
, inOptions
);
887 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
889 unsigned long finalTicks
;
891 HiliteControl( m_controlRef
, part
);
892 Delay( ticks
, &finalTicks
);
893 HiliteControl( m_controlRef
, kControlNoPart
);
896 SInt32
wxMacControl::GetValue() const
898 return ::GetControl32BitValue( m_controlRef
);
901 SInt32
wxMacControl::GetMaximum() const
903 return ::GetControl32BitMaximum( m_controlRef
);
906 SInt32
wxMacControl::GetMinimum() const
908 return ::GetControl32BitMinimum( m_controlRef
);
911 void wxMacControl::SetValue( SInt32 v
)
913 ::SetControl32BitValue( m_controlRef
, v
);
916 void wxMacControl::SetMinimum( SInt32 v
)
918 ::SetControl32BitMinimum( m_controlRef
, v
);
921 void wxMacControl::SetMaximum( SInt32 v
)
923 ::SetControl32BitMaximum( m_controlRef
, v
);
926 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
928 ::SetControl32BitMinimum( m_controlRef
, minimum
);
929 ::SetControl32BitMaximum( m_controlRef
, maximum
);
930 ::SetControl32BitValue( m_controlRef
, value
);
933 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
935 return SetKeyboardFocus( GetControlOwner( m_controlRef
), m_controlRef
, focusPart
);
938 bool wxMacControl::HasFocus() const
941 GetKeyboardFocus( GetUserFocusWindow() , &control
);
942 return control
== m_controlRef
;
945 void wxMacControl::SetNeedsFocusRect( bool needs
)
947 m_needsFocusRect
= needs
;
950 bool wxMacControl::NeedsFocusRect() const
952 return m_needsFocusRect
;
955 void wxMacControl::VisibilityChanged(bool shown
)
959 void wxMacControl::SuperChangedPosition()
963 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
966 ControlFontStyleRec fontStyle
;
967 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
969 switch ( font
.MacGetThemeFontID() )
971 case kThemeSmallSystemFont
:
972 fontStyle
.font
= kControlFontSmallSystemFont
;
975 case 109 : // mini font
979 case kThemeSystemFont
:
980 fontStyle
.font
= kControlFontBigSystemFont
;
984 fontStyle
.font
= kControlFontBigSystemFont
;
988 fontStyle
.flags
= kControlUseFontMask
;
992 fontStyle
.font
= font
.MacGetFontNum();
993 fontStyle
.style
= font
.MacGetFontStyle();
994 fontStyle
.size
= font
.MacGetFontSize();
995 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
998 fontStyle
.just
= teJustLeft
;
999 fontStyle
.flags
|= kControlUseJustMask
;
1000 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
1001 fontStyle
.just
= teJustCenter
;
1002 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
1003 fontStyle
.just
= teJustRight
;
1006 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
1007 // won't get grayed out by the system anymore
1009 if ( foreground
!= *wxBLACK
)
1011 fontStyle
.foreColor
= MAC_WXCOLORREF( foreground
.GetPixel() );
1012 fontStyle
.flags
|= kControlUseForeColorMask
;
1015 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
1018 void wxMacControl::SetBackground( const wxBrush
&WXUNUSED(brush
) )
1021 // setting up a color proc is not recommended anymore
1024 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
1026 ::SetControl32BitMinimum( m_controlRef
, minimum
);
1027 ::SetControl32BitMaximum( m_controlRef
, maximum
);
1030 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
1032 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
);
1035 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
1037 SetControlAction( m_controlRef
, actionProc
);
1040 void wxMacControl::SetViewSize( SInt32 viewSize
)
1042 SetControlViewSize(m_controlRef
, viewSize
);
1045 SInt32
wxMacControl::GetViewSize() const
1047 return GetControlViewSize( m_controlRef
);
1050 bool wxMacControl::IsVisible() const
1052 return IsControlVisible( m_controlRef
);
1055 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
1057 SetControlVisibility( m_controlRef
, visible
, redraw
);
1060 bool wxMacControl::IsEnabled() const
1062 #if TARGET_API_MAC_OSX
1063 return IsControlEnabled( m_controlRef
);
1065 return IsControlActive( m_controlRef
);
1069 bool wxMacControl::IsActive() const
1071 return IsControlActive( m_controlRef
);
1074 void wxMacControl::Enable( bool enable
)
1077 EnableControl( m_controlRef
);
1079 DisableControl( m_controlRef
);
1082 void wxMacControl::SetDrawingEnabled( bool enable
)
1084 HIViewSetDrawingEnabled( m_controlRef
, enable
);
1087 bool wxMacControl::GetNeedsDisplay() const
1089 return HIViewGetNeedsDisplay( m_controlRef
);
1092 void wxMacControl::SetNeedsDisplay( RgnHandle where
)
1097 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, true );
1100 void wxMacControl::SetNeedsDisplay( Rect
* where
)
1105 if ( where
!= NULL
)
1107 RgnHandle update
= NewRgn();
1108 RectRgn( update
, where
);
1109 HIViewSetNeedsDisplayInRegion( m_controlRef
, update
, true );
1110 DisposeRgn( update
);
1113 HIViewSetNeedsDisplay( m_controlRef
, true );
1116 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
1122 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
);
1123 pt
->x
= (int)hiPoint
.x
;
1124 pt
->y
= (int)hiPoint
.y
;
1127 void wxMacControl::SetRect( Rect
*r
)
1129 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1130 //CGPoint and CGSize, which have two floats each
1131 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} };
1132 HIViewSetFrame ( m_controlRef
, &hir
);
1133 // eventuall we might have to do a SetVisibility( false , true );
1134 // before and a SetVisibility( true , true ); after
1137 void wxMacControl::GetRect( Rect
*r
)
1139 GetControlBounds( m_controlRef
, r
);
1142 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
1144 UMAGetControlBoundsInWindowCoords( m_controlRef
, r
);
1147 void wxMacControl::GetBestRect( Rect
*r
)
1149 short baselineoffset
;
1151 GetBestControlRect( m_controlRef
, r
, &baselineoffset
);
1154 void wxMacControl::SetLabel( const wxString
&title
)
1156 wxFontEncoding encoding
;
1159 encoding
= m_font
.GetEncoding();
1161 encoding
= wxFont::GetDefaultEncoding();
1163 UMASetControlTitle( m_controlRef
, title
, encoding
);
1166 void wxMacControl::GetFeatures( UInt32
* features
)
1168 GetControlFeatures( m_controlRef
, features
);
1171 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
1173 OSStatus err
= GetControlRegion( m_controlRef
, partCode
, region
);
1177 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
1179 #if TARGET_API_MAC_OSX
1180 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
1181 (other
!= NULL
) ? other
->m_controlRef
: NULL
);
1187 #if TARGET_API_MAC_OSX
1188 // SetNeedsDisplay would not invalidate the children
1189 static void InvalidateControlAndChildren( HIViewRef control
)
1191 HIViewSetNeedsDisplay( control
, true );
1192 UInt16 childrenCount
= 0;
1193 OSStatus err
= CountSubControls( control
, &childrenCount
);
1194 if ( err
== errControlIsNotEmbedder
)
1197 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") );
1199 for ( UInt16 i
= childrenCount
; i
>=1; --i
)
1203 err
= GetIndexedSubControl( control
, i
, & child
);
1204 if ( err
== errControlIsNotEmbedder
)
1207 InvalidateControlAndChildren( child
);
1212 void wxMacControl::InvalidateWithChildren()
1214 #if TARGET_API_MAC_OSX
1215 InvalidateControlAndChildren( m_controlRef
);
1219 void wxMacControl::ScrollRect( wxRect
*r
, int dx
, int dy
)
1221 wxASSERT( r
!= NULL
);
1223 HIRect scrollarea
= CGRectMake( r
->x
, r
->y
, r
->width
, r
->height
);
1224 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
);
1227 OSType wxMacCreator
= 'WXMC';
1228 OSType wxMacControlProperty
= 'MCCT';
1230 void wxMacControl::SetReferenceInNativeControl()
1233 verify_noerr( SetControlProperty ( m_controlRef
,
1234 wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data
) );
1237 wxMacControl
* wxMacControl::GetReferenceFromNativeControl(ControlRef control
)
1239 wxMacControl
* ctl
= NULL
;
1241 if ( GetControlProperty( control
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) ,
1242 &actualSize
, &ctl
) == noErr
)
1249 // ============================================================================
1250 // DataBrowser Wrapper
1251 // ============================================================================
1253 // basing on DataBrowserItemIDs
1256 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
1258 DataBrowserItemID itemID
,
1259 DataBrowserItemNotification message
,
1260 DataBrowserItemDataRef itemData
)
1262 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1265 ctl
->ItemNotification(itemID
, message
, itemData
);
1269 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
1271 DataBrowserItemID itemID
,
1272 DataBrowserPropertyID property
,
1273 DataBrowserItemDataRef itemData
,
1274 Boolean changeValue
)
1276 OSStatus err
= errDataBrowserPropertyNotSupported
;
1277 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1280 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
1285 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
1287 DataBrowserItemID itemOneID
,
1288 DataBrowserItemID itemTwoID
,
1289 DataBrowserPropertyID sortProperty
)
1291 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1294 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
1299 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
1300 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
1301 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
1303 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) : wxMacControl( peer
)
1305 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
1306 OSStatus err
= ::CreateDataBrowserControl(
1307 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
1308 &bounds
, kDataBrowserListView
, &m_controlRef
);
1309 SetReferenceInNativeControl();
1310 verify_noerr( err
);
1311 if ( gDataBrowserItemCompareUPP
== NULL
)
1312 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
1313 if ( gDataBrowserItemDataUPP
== NULL
)
1314 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
1315 if ( gDataBrowserItemNotificationUPP
== NULL
)
1317 gDataBrowserItemNotificationUPP
=
1318 #if TARGET_API_MAC_OSX
1319 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
1321 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc
);
1325 DataBrowserCallbacks callbacks
;
1326 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
1328 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
1329 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
1330 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
1331 SetCallbacks( &callbacks
);
1335 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
1337 DataBrowserItemState state
,
1338 UInt32
*numItems
) const
1340 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
1343 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
1345 DataBrowserItemState state
,
1348 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
1351 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1353 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
1356 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1357 DataBrowserTableViewColumnIndex position
)
1359 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
1362 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
){
1363 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
1366 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
1368 DataBrowserTableViewColumnID id
;
1369 GetColumnIDFromIndex( position
, &id
);
1370 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
1373 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
1375 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
1378 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
1380 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
1383 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1385 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
1388 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
1390 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1393 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
1395 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1398 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
1400 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
1403 OSStatus
wxMacDataBrowserControl::UpdateItems(
1404 DataBrowserItemID container
,
1406 const DataBrowserItemID
*items
,
1407 DataBrowserPropertyID preSortProperty
,
1408 DataBrowserPropertyID propertyID
) const
1410 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
1413 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
1415 return IsDataBrowserItemSelected( m_controlRef
, item
);
1418 OSStatus
wxMacDataBrowserControl::AddItems(
1419 DataBrowserItemID container
,
1421 const DataBrowserItemID
*items
,
1422 DataBrowserPropertyID preSortProperty
)
1424 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1427 OSStatus
wxMacDataBrowserControl::RemoveItems(
1428 DataBrowserItemID container
,
1430 const DataBrowserItemID
*items
,
1431 DataBrowserPropertyID preSortProperty
)
1433 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1436 OSStatus
wxMacDataBrowserControl::RevealItem(
1437 DataBrowserItemID item
,
1438 DataBrowserPropertyID propertyID
,
1439 DataBrowserRevealOptions options
) const
1441 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
1444 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
1446 const DataBrowserItemID
*items
,
1447 DataBrowserSetOption operation
)
1449 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
1452 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
1454 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
1457 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
1459 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
1462 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
1464 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
1467 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
1469 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1472 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
1474 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1477 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
1479 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1482 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
1484 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1487 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
1489 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1492 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
1494 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1497 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
1499 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1502 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
1504 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1507 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
1509 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
1512 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
1513 UInt32
*position
) const
1515 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1518 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, UInt32 position
)
1520 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1523 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
1525 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1528 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
1530 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1533 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
1535 return GetDataBrowserSortProperty( m_controlRef
, column
);
1538 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
1540 return SetDataBrowserSortProperty( m_controlRef
, column
);
1543 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
1545 return GetDataBrowserSortOrder( m_controlRef
, order
);
1548 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
1550 return SetDataBrowserSortOrder( m_controlRef
, order
);
1553 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
1554 DataBrowserPropertyFlags
*flags
) const
1556 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1559 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
1560 DataBrowserPropertyFlags flags
)
1562 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1565 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
1566 DataBrowserListViewHeaderDesc
*desc
) const
1568 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1571 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
1572 DataBrowserListViewHeaderDesc
*desc
)
1574 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1577 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
1578 Boolean expandableRows
)
1580 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
1583 // ============================================================================
1584 // Higher-level Databrowser
1585 // ============================================================================
1587 // basing on data item objects
1590 wxMacDataItem::wxMacDataItem()
1594 m_colId
= kTextColumnId
; // for compat with existing wx*ListBox impls.
1597 wxMacDataItem::~wxMacDataItem()
1601 void wxMacDataItem::SetOrder( SInt32 order
)
1606 SInt32
wxMacDataItem::GetOrder() const
1611 void wxMacDataItem::SetData( void* data
)
1616 void* wxMacDataItem::GetData() const
1621 short wxMacDataItem::GetColumn()
1626 void wxMacDataItem::SetColumn( short col
)
1631 void wxMacDataItem::SetLabel( const wxString
& str
)
1634 m_cfLabel
.Assign( str
, wxLocale::GetSystemEncoding());
1637 const wxString
& wxMacDataItem::GetLabel() const
1642 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*owner
,
1643 const wxMacDataItem
* rhs
,
1644 DataBrowserPropertyID sortProperty
) const
1646 const wxMacDataItem
* otherItem
= dynamic_cast<const wxMacDataItem
*>(rhs
);
1647 bool retval
= false;
1649 if ( sortProperty
== m_colId
&& owner
->GetSortOrder() != SortOrder_None
){
1650 retval
= m_label
.CmpNoCase( otherItem
->m_label
) < 0;
1653 else if ( owner
->GetSortOrder() == SortOrder_None
|| sortProperty
== kNumericOrderColumnId
)
1654 retval
= m_order
< otherItem
->m_order
;
1659 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*owner
,
1660 DataBrowserPropertyID property
,
1661 DataBrowserItemDataRef itemData
,
1664 OSStatus err
= errDataBrowserPropertyNotSupported
;
1667 if ( property
== m_colId
){
1668 err
= ::SetDataBrowserItemDataText( itemData
, m_cfLabel
);
1671 else if ( property
== kNumericOrderColumnId
){
1672 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
1682 // no editable props here
1691 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*owner
,
1692 DataBrowserItemNotification message
,
1693 DataBrowserItemDataRef itemData
) const
1698 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1699 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1701 m_suppressSelection
= false;
1702 m_sortOrder
= SortOrder_None
;
1703 m_clientDataItemsType
= wxClientData_None
;
1706 ListSortOrder
wxMacDataItemBrowserControl::GetSortOrder() const
1711 void wxMacDataItemBrowserControl::SetSortOrder(const ListSortOrder sort
)
1716 wxMacDataItem
* wxMacDataItemBrowserControl::CreateItem()
1718 return new wxMacDataItem();
1721 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1723 m_former
= browser
->SuppressSelection(true);
1724 m_browser
= browser
;
1727 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1729 m_browser
->SuppressSelection(m_former
);
1732 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
1734 bool former
= m_suppressSelection
;
1735 m_suppressSelection
= suppress
;
1740 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
1741 DataBrowserItemID itemTwoID
,
1742 DataBrowserPropertyID sortProperty
)
1744 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1745 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1746 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1749 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
1750 const wxMacDataItem
* itemTwo
,
1751 DataBrowserPropertyID sortProperty
)
1753 Boolean retval
= false;
1754 if ( itemOne
!= NULL
)
1755 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1759 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1760 DataBrowserItemID itemID
,
1761 DataBrowserPropertyID property
,
1762 DataBrowserItemDataRef itemData
,
1763 Boolean changeValue
)
1765 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1766 return GetSetItemData(item
, property
, itemData
, changeValue
);
1769 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1770 wxMacDataItem
* item
,
1771 DataBrowserPropertyID property
,
1772 DataBrowserItemDataRef itemData
,
1773 Boolean changeValue
)
1775 OSStatus err
= errDataBrowserPropertyNotSupported
;
1778 case kDataBrowserContainerIsClosableProperty
:
1779 case kDataBrowserContainerIsSortableProperty
:
1780 case kDataBrowserContainerIsOpenableProperty
:
1781 // right now default behaviour on these
1785 if ( item
!= NULL
){
1786 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1794 void wxMacDataItemBrowserControl::ItemNotification(
1795 DataBrowserItemID itemID
,
1796 DataBrowserItemNotification message
,
1797 DataBrowserItemDataRef itemData
)
1799 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1800 ItemNotification( item
, message
, itemData
);
1803 void wxMacDataItemBrowserControl::ItemNotification(
1804 const wxMacDataItem
* item
,
1805 DataBrowserItemNotification message
,
1806 DataBrowserItemDataRef itemData
)
1809 item
->Notification( this, message
, itemData
);
1812 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
1813 bool recurse
, DataBrowserItemState state
) const
1815 UInt32 numItems
= 0;
1816 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
1817 recurse
, state
, &numItems
) );
1821 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
1822 bool recurse
) const
1824 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
1828 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
1829 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1831 Handle handle
= NewHandle(0);
1832 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
1833 recurse
, state
, handle
) );
1835 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1837 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1838 for ( int i
= 0; i
< itemCount
; ++i
)
1840 items
.Add(itemsArray
[i
]);
1843 DisposeHandle( handle
);
1846 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
1848 DataBrowserTableViewRowIndex row
;
1849 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1850 wxASSERT( err
== noErr
);
1854 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
1856 DataBrowserItemID id
;
1857 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1858 wxASSERT( err
== noErr
);
1859 return (wxMacDataItem
*) id
;
1862 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
1863 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1865 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
1866 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1869 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
1870 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1872 unsigned int noItems
= itemArray
.GetCount();
1873 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1874 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1875 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1877 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
1878 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1882 void wxMacDataItemBrowserControl::InsertColumn(int colId
, DataBrowserPropertyType colType
,
1883 const wxString
& title
, SInt16 just
, int defaultWidth
)
1885 DataBrowserListViewColumnDesc columnDesc
;
1886 columnDesc
.headerBtnDesc
.titleOffset
= 0;
1887 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
1889 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
1890 kControlUseFontMask
| kControlUseJustMask
;
1892 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
1893 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
1894 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
1895 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
1897 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
1898 // defined for other modes?
1901 enc
= m_font
.GetEncoding();
1903 enc
= wxLocale::GetSystemEncoding();
1904 wxMacCFStringHolder cfTitle
;
1905 cfTitle
.Assign( title
, enc
);
1906 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
1908 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
1909 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
1911 columnDesc
.propertyDesc
.propertyID
= (kMinColumnId
+ colId
);
1912 columnDesc
.propertyDesc
.propertyType
= colType
;
1913 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewDefaultColumnFlags
| kDataBrowserListViewTypeSelectColumn
;;
1914 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1915 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewNoGapForIconInHeaderButton
;
1918 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
1920 if (defaultWidth
> 0){
1921 SetColumnWidth(colId
, defaultWidth
);
1926 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
1928 DataBrowserPropertyID id
;
1929 GetColumnIDFromIndex(colId
, &id
);
1930 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
1933 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
1935 DataBrowserPropertyID id
;
1936 GetColumnIDFromIndex(colId
, &id
);
1938 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
1942 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1944 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
1945 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1948 void wxMacDataItemBrowserControl::AddItems(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 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
1956 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1960 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1962 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
1963 (UInt32
*) &item
, kDataBrowserItemNoProperty
);
1964 verify_noerr( err
);
1967 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1969 unsigned int noItems
= itemArray
.GetCount();
1970 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1971 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1972 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1974 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
1975 (UInt32
*) items
, kDataBrowserItemNoProperty
);
1976 verify_noerr( err
);
1980 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
1982 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
1983 verify_noerr( err
);
1986 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
1988 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
1991 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
1993 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
1996 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
1998 unsigned int noItems
= itemArray
.GetCount();
1999 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
2000 for ( unsigned int i
= 0; i
< noItems
; ++i
)
2001 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
2003 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
2007 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
2009 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
2012 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
2014 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
2017 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
2019 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
2022 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
2024 return m_clientDataItemsType
;
2026 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
2028 m_clientDataItemsType
= clientDataItemsType
;
2031 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
2033 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);
2036 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
2038 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
2039 RemoveItem( wxMacDataBrowserRootContainer
, item
);
2042 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, const wxString
& text
, int column
)
2044 wxMacDataItem
* newItem
= CreateItem();
2045 newItem
->SetLabel( text
);
2047 newItem
->SetColumn( kMinColumnId
+ column
);
2049 if ( m_sortOrder
== SortOrder_None
)
2051 // increase the order of the lines to be shifted
2052 unsigned int lines
= MacGetCount();
2053 for ( unsigned int i
= n
; i
< lines
; ++i
)
2055 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
2056 iter
->SetOrder( iter
->GetOrder() + 1 );
2059 SInt32 frontLineOrder
= 0;
2062 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
2063 frontLineOrder
= iter
->GetOrder();
2065 newItem
->SetOrder( frontLineOrder
+ 1 );
2068 AddItem( wxMacDataBrowserRootContainer
, newItem
);
2071 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, const wxArrayString
& items
, int column
)
2073 size_t itemsCount
= items
.GetCount();
2074 if ( itemsCount
== 0 )
2077 SInt32 frontLineOrder
= 0;
2079 if ( m_sortOrder
== SortOrder_None
)
2081 // increase the order of the lines to be shifted
2082 unsigned int lines
= MacGetCount();
2083 for ( unsigned int i
= n
; i
< lines
; ++i
)
2085 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
2086 iter
->SetOrder( iter
->GetOrder() + itemsCount
);
2090 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
2091 frontLineOrder
= iter
->GetOrder();
2095 wxArrayMacDataItemPtr ids
;
2096 ids
.SetCount( itemsCount
);
2098 for ( unsigned int i
= 0; i
< itemsCount
; ++i
)
2100 wxMacDataItem
* item
= CreateItem();
2101 item
->SetLabel( items
[i
]);
2103 item
->SetColumn( kMinColumnId
+ column
);
2105 if ( m_sortOrder
== SortOrder_None
)
2106 item
->SetOrder( frontLineOrder
+ 1 + i
);
2111 AddItems( wxMacDataBrowserRootContainer
, ids
);
2114 int wxMacDataItemBrowserControl::MacAppend( const wxString
& text
)
2116 wxMacDataItem
* item
= CreateItem();
2117 item
->SetLabel( text
);
2118 if ( m_sortOrder
== SortOrder_None
)
2120 unsigned int lines
= MacGetCount();
2122 item
->SetOrder( 1 );
2125 wxMacDataItem
* frontItem
= (wxMacDataItem
*) GetItemFromLine(lines
-1);
2126 item
->SetOrder( frontItem
->GetOrder() + 1 );
2129 AddItem( wxMacDataBrowserRootContainer
, item
);
2131 return GetLineFromItem(item
);
2134 void wxMacDataItemBrowserControl::MacClear()
2136 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2137 RemoveAllItems(wxMacDataBrowserRootContainer
);
2140 void wxMacDataItemBrowserControl::MacDeselectAll()
2142 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2143 SetSelectedAllItems( kDataBrowserItemsRemove
);
2146 void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n
, bool select
, bool multi
)
2148 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
2149 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2151 if ( IsItemSelected( item
) != select
)
2154 SetSelectedItem( item
, multi
? kDataBrowserItemsAdd
: kDataBrowserItemsAssign
);
2156 SetSelectedItem( item
, kDataBrowserItemsRemove
);
2162 bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n
) const
2164 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
2165 return IsItemSelected( item
);
2168 int wxMacDataItemBrowserControl::MacGetSelection() const
2170 wxMacDataItemPtr first
, last
;
2171 GetSelectionAnchor( &first
, &last
);
2173 if ( first
!= NULL
)
2175 return GetLineFromItem( first
);
2181 int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt
& aSelections
) const
2183 aSelections
.Empty();
2184 wxArrayMacDataItemPtr selectedItems
;
2185 GetItems( wxMacDataBrowserRootContainer
, false , kDataBrowserItemIsSelected
, selectedItems
);
2187 int count
= selectedItems
.GetCount();
2189 for ( int i
= 0; i
< count
; ++i
)
2191 aSelections
.Add(GetLineFromItem(selectedItems
[i
]));
2197 void wxMacDataItemBrowserControl::MacSetString( unsigned int n
, const wxString
& text
)
2199 // as we don't store the strings we only have to issue a redraw
2200 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2201 item
->SetLabel( text
);
2202 UpdateItem( wxMacDataBrowserRootContainer
, item
, kTextColumnId
);
2205 wxString
wxMacDataItemBrowserControl::MacGetString( unsigned int n
) const
2207 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2208 return item
->GetLabel();
2211 void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n
, void * data
)
2213 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2214 item
->SetData( data
);
2215 // not displayed, therefore no Update infos to DataBrowser
2218 void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n
) const
2220 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2221 return item
->GetData();
2224 void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n
)
2226 RevealItem( GetItemFromLine( n
) , kDataBrowserRevealWithoutSelecting
);
2235 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
2237 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
2244 #ifdef __WXMAC_OSX__
2245 // snippets from Sketch Sample from Apple :
2247 #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
2250 This function locates, opens, and returns the profile reference for the calibrated
2251 Generic RGB color space. It is up to the caller to call CMCloseProfile when done
2252 with the profile reference this function returns.
2254 CMProfileRef
wxMacOpenGenericProfile()
2256 static CMProfileRef cachedRGBProfileRef
= NULL
;
2258 // we only create the profile reference once
2259 if (cachedRGBProfileRef
== NULL
)
2261 CMProfileLocation loc
;
2263 loc
.locType
= cmPathBasedProfile
;
2264 strcpy(loc
.u
.pathLoc
.path
, kGenericRGBProfilePathStr
);
2266 verify_noerr( CMOpenProfile(&cachedRGBProfileRef
, &loc
) );
2269 // clone the profile reference so that the caller has their own reference, not our cached one
2270 if (cachedRGBProfileRef
)
2271 CMCloneProfileRef(cachedRGBProfileRef
);
2273 return cachedRGBProfileRef
;
2277 Return the generic RGB color space. This is a 'get' function and the caller should
2278 not release the returned value unless the caller retains it first. Usually callers
2279 of this routine will immediately use the returned colorspace with CoreGraphics
2280 so they typically do not need to retain it themselves.
2282 This function creates the generic RGB color space once and hangs onto it so it can
2283 return it whenever this function is called.
2286 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
2288 static wxMacCFRefHolder
<CGColorSpaceRef
> genericRGBColorSpace
;
2290 if (genericRGBColorSpace
== NULL
)
2292 if ( UMAGetSystemVersion() >= 0x1040 )
2294 genericRGBColorSpace
.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) );
2298 CMProfileRef genericRGBProfile
= wxMacOpenGenericProfile();
2300 if (genericRGBProfile
)
2302 genericRGBColorSpace
.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile
) );
2304 wxASSERT_MSG( genericRGBColorSpace
!= NULL
, wxT("couldn't create the generic RGB color space") );
2306 // we opened the profile so it is up to us to close it
2307 CMCloseProfile(genericRGBProfile
);
2312 return genericRGBColorSpace
;
2316 wxMacPortSaver::wxMacPortSaver( GrafPtr port
)
2318 ::GetPort( &m_port
);
2322 wxMacPortSaver::~wxMacPortSaver()
2324 ::SetPort( m_port
);