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__
373 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
375 // We suppose that toolkit version is the same as OS version under Mac
376 wxGetOsVersion(verMaj
, verMin
);
381 // Reading and writing resources (eg WIN.INI, .Xdefaults)
383 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
389 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
392 buf
.Printf(wxT("%.4f"), value
);
394 return wxWriteResource(section
, entry
, buf
, file
);
397 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
400 buf
.Printf(wxT("%ld"), value
);
402 return wxWriteResource(section
, entry
, buf
, file
);
405 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
408 buf
.Printf(wxT("%d"), value
);
410 return wxWriteResource(section
, entry
, buf
, file
);
413 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
419 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
422 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
425 *value
= (float)strtod(s
, NULL
);
432 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
435 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
438 *value
= strtol(s
, NULL
, 10);
445 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
448 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
451 *value
= (int)strtol(s
, NULL
, 10);
457 #endif // wxUSE_RESOURCES
459 int gs_wxBusyCursorCount
= 0;
460 extern wxCursor gMacCurrentCursor
;
461 wxCursor gMacStoredActiveCursor
;
463 // Set the cursor to the busy cursor for all windows
464 void wxBeginBusyCursor(const wxCursor
*cursor
)
466 if (gs_wxBusyCursorCount
++ == 0)
468 gMacStoredActiveCursor
= gMacCurrentCursor
;
469 cursor
->MacInstall();
471 //else: nothing to do, already set
474 // Restore cursor to normal
475 void wxEndBusyCursor()
477 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
478 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
480 if (--gs_wxBusyCursorCount
== 0)
482 gMacStoredActiveCursor
.MacInstall();
483 gMacStoredActiveCursor
= wxNullCursor
;
487 // true if we're between the above two calls
490 return (gs_wxBusyCursorCount
> 0);
497 wxString
wxMacFindFolderNoSeparator( short vol
,
499 Boolean createFolder
)
504 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
506 strDir
= wxMacFSRefToPath( &fsRef
);
512 wxString
wxMacFindFolder( short vol
,
514 Boolean createFolder
)
516 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
523 // Check whether this window wants to process messages, e.g. Stop button
524 // in long calculations.
525 bool wxCheckForInterrupt(wxWindow
*wnd
)
531 void wxGetMousePosition( int* x
, int* y
)
534 #if wxMAC_USE_CORE_GRAPHICS
538 LocalToGlobal( &pt
);
544 // Return true if we have a colour display
545 bool wxColourDisplay()
550 // Returns depth of screen
554 #if wxMAC_USE_CORE_GRAPHICS
555 theDepth
= (int) CGDisplayBitsPerPixel(CGMainDisplayID());
558 SetRect(&globRect
, -32760, -32760, 32760, 32760);
559 GDHandle theMaxDevice
;
561 theMaxDevice
= GetMaxDevice(&globRect
);
562 if (theMaxDevice
!= NULL
)
563 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
568 // Get size of display
569 void wxDisplaySize(int *width
, int *height
)
571 #if wxMAC_USE_CORE_GRAPHICS
572 // TODO adapt for multi-displays
573 CGRect bounds
= CGDisplayBounds(CGMainDisplayID());
575 *width
= (int)bounds
.size
.width
;
577 *height
= (int)bounds
.size
.height
;
580 GetQDGlobalsScreenBits( &screenBits
);
583 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
586 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
590 void wxDisplaySizeMM(int *width
, int *height
)
592 wxDisplaySize(width
, height
);
593 // on mac 72 is fixed (at least now;-)
594 float cvPt2Mm
= 25.4 / 72;
597 *width
= int( *width
* cvPt2Mm
);
600 *height
= int( *height
* cvPt2Mm
);
603 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
605 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
607 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
610 *x
= bounds
.origin
.x
;
612 *y
= bounds
.origin
.y
;
614 *width
= bounds
.size
.width
;
616 *height
= bounds
.size
.height
;
619 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
625 *width
= r
.right
- r
.left
;
627 *height
= r
.bottom
- r
.top
;
631 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
633 return wxGenericFindWindowAtPoint(pt
);
640 wxString
wxGetOsDescription()
642 #ifdef WXWIN_OS_DESCRIPTION
643 // use configure generated description if available
644 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
646 return wxT("MacOS"); //TODO:define further
651 wxChar
*wxGetUserHome (const wxString
& user
)
657 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
666 int pos
= p
.Find(':');
667 if ( pos
!= wxNOT_FOUND
)
675 err
= wxMacPathToFSRef( p
, &fsRef
);
678 FSVolumeRefNum vRefNum
;
679 err
= FSGetVRefNum( &fsRef
, &vRefNum
);
682 UInt64 freeBytes
, totalBytes
;
683 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
);
687 *pTotal
= wxDiskspaceSize_t( totalBytes
);
689 *pFree
= wxDiskspaceSize_t( freeBytes
);
696 #endif // !__DARWIN__
698 //---------------------------------------------------------------------------
699 // wxMac Specific utility functions
700 //---------------------------------------------------------------------------
702 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
704 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
705 int len
= strlen(buf
);
710 memcpy( (char*) &to
[1] , buf
, len
);
713 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
715 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
718 // ----------------------------------------------------------------------------
719 // Common Event Support
720 // ----------------------------------------------------------------------------
722 extern ProcessSerialNumber gAppProcess
;
726 ProcessSerialNumber psn
;
728 psn
.highLongOfPSN
= 0;
729 psn
.lowLongOfPSN
= kCurrentProcess
;
730 SameProcess( &gAppProcess
, &psn
, &isSame
);
734 OSStatus err
= noErr
;
737 // lead sometimes to race conditions, although all calls used should be thread safe ...
738 static wxMacCarbonEvent s_wakeupEvent
;
739 if ( !s_wakeupEvent
.IsValid() )
741 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
742 kEventAttributeNone
);
747 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
749 s_wakeupEvent
.SetCurrentTime();
750 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
751 kEventPriorityHigh
);
754 wxMacCarbonEvent wakeupEvent
;
755 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
756 kEventAttributeNone
);
757 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
758 kEventPriorityHigh
);
761 PostEvent( nullEvent
, 0 );
766 WakeUpProcess( &gAppProcess
);
774 // ----------------------------------------------------------------------------
775 // Native Struct Conversions
776 // ----------------------------------------------------------------------------
778 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
782 n
->right
= wx
->x
+ wx
->width
;
783 n
->bottom
= wx
->y
+ wx
->height
;
786 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
790 wx
->width
= n
->right
- n
->left
;
791 wx
->height
= n
->bottom
- n
->top
;
794 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
800 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
806 // ----------------------------------------------------------------------------
807 // Carbon Event Support
808 // ----------------------------------------------------------------------------
810 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
812 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
815 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
817 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
820 // ----------------------------------------------------------------------------
821 // Control Access Support
822 // ----------------------------------------------------------------------------
824 wxMacControl::wxMacControl(wxWindow
* peer
, bool isRootControl
)
828 m_isRootControl
= isRootControl
;
831 wxMacControl::wxMacControl( wxWindow
* peer
, ControlRef control
)
835 m_controlRef
= control
;
838 wxMacControl::wxMacControl( wxWindow
* peer
, WXWidget control
)
842 m_controlRef
= (ControlRef
) control
;
845 wxMacControl::~wxMacControl()
849 void wxMacControl::Init()
853 m_needsFocusRect
= false;
854 m_isRootControl
= false;
857 void wxMacControl::Dispose()
859 wxASSERT_MSG( IsValidControlHandle(m_controlRef
) , wxT("Invalid Control Handle (maybe already released) in Dispose") );
861 CFIndex count
= CFGetRetainCount( m_controlRef
) ;
862 wxASSERT_MSG( count
== 1 , wxT("Reference Count of native control was not 1 in Dispose") );
864 ::DisposeControl( m_controlRef
);
868 void wxMacControl::SetReference( URefCon data
)
870 SetControlReference( m_controlRef
, data
);
873 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
875 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
);
878 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
880 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
);
883 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
885 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
);
888 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
890 #if TARGET_API_MAC_OSX
891 return SendEventToEventTargetWithOptions( event
,
892 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
894 #pragma unused(inOptions)
895 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) );
899 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
901 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
903 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
);
905 return SendEvent( event
, inOptions
);
908 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
912 memset( &command
, 0 , sizeof(command
) );
913 command
.commandID
= commandID
;
914 return SendHICommand( command
, inOptions
);
917 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
919 unsigned long finalTicks
;
921 HiliteControl( m_controlRef
, part
);
922 Delay( ticks
, &finalTicks
);
923 HiliteControl( m_controlRef
, kControlNoPart
);
926 SInt32
wxMacControl::GetValue() const
928 return ::GetControl32BitValue( m_controlRef
);
931 SInt32
wxMacControl::GetMaximum() const
933 return ::GetControl32BitMaximum( m_controlRef
);
936 SInt32
wxMacControl::GetMinimum() const
938 return ::GetControl32BitMinimum( m_controlRef
);
941 void wxMacControl::SetValue( SInt32 v
)
943 ::SetControl32BitValue( m_controlRef
, v
);
946 void wxMacControl::SetMinimum( SInt32 v
)
948 ::SetControl32BitMinimum( m_controlRef
, v
);
951 void wxMacControl::SetMaximum( SInt32 v
)
953 ::SetControl32BitMaximum( m_controlRef
, v
);
956 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
958 ::SetControl32BitMinimum( m_controlRef
, minimum
);
959 ::SetControl32BitMaximum( m_controlRef
, maximum
);
960 ::SetControl32BitValue( m_controlRef
, value
);
963 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
965 return SetKeyboardFocus( GetControlOwner( m_controlRef
), m_controlRef
, focusPart
);
968 bool wxMacControl::HasFocus() const
971 GetKeyboardFocus( GetUserFocusWindow() , &control
);
972 return control
== m_controlRef
;
975 void wxMacControl::SetNeedsFocusRect( bool needs
)
977 m_needsFocusRect
= needs
;
980 bool wxMacControl::NeedsFocusRect() const
982 return m_needsFocusRect
;
985 void wxMacControl::VisibilityChanged(bool shown
)
989 void wxMacControl::SuperChangedPosition()
993 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
996 ControlFontStyleRec fontStyle
;
997 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
999 switch ( font
.MacGetThemeFontID() )
1001 case kThemeSmallSystemFont
:
1002 fontStyle
.font
= kControlFontSmallSystemFont
;
1005 case 109 : // mini font
1006 fontStyle
.font
= -5;
1009 case kThemeSystemFont
:
1010 fontStyle
.font
= kControlFontBigSystemFont
;
1014 fontStyle
.font
= kControlFontBigSystemFont
;
1018 fontStyle
.flags
= kControlUseFontMask
;
1022 fontStyle
.font
= font
.MacGetFontNum();
1023 fontStyle
.style
= font
.MacGetFontStyle();
1024 fontStyle
.size
= font
.MacGetFontSize();
1025 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
1028 fontStyle
.just
= teJustLeft
;
1029 fontStyle
.flags
|= kControlUseJustMask
;
1030 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
1031 fontStyle
.just
= teJustCenter
;
1032 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
1033 fontStyle
.just
= teJustRight
;
1036 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
1037 // won't get grayed out by the system anymore
1039 if ( foreground
!= *wxBLACK
)
1041 fontStyle
.foreColor
= MAC_WXCOLORREF( foreground
.GetPixel() );
1042 fontStyle
.flags
|= kControlUseForeColorMask
;
1045 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
1048 void wxMacControl::SetBackground( const wxBrush
&WXUNUSED(brush
) )
1051 // setting up a color proc is not recommended anymore
1054 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
1056 ::SetControl32BitMinimum( m_controlRef
, minimum
);
1057 ::SetControl32BitMaximum( m_controlRef
, maximum
);
1060 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
1063 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
);
1069 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
1071 SetControlAction( m_controlRef
, actionProc
);
1074 void wxMacControl::SetViewSize( SInt32 viewSize
)
1076 SetControlViewSize(m_controlRef
, viewSize
);
1079 SInt32
wxMacControl::GetViewSize() const
1081 return GetControlViewSize( m_controlRef
);
1084 bool wxMacControl::IsVisible() const
1086 return IsControlVisible( m_controlRef
);
1089 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
1091 SetControlVisibility( m_controlRef
, visible
, redraw
);
1094 bool wxMacControl::IsEnabled() const
1096 #if TARGET_API_MAC_OSX
1097 return IsControlEnabled( m_controlRef
);
1099 return IsControlActive( m_controlRef
);
1103 bool wxMacControl::IsActive() const
1105 return IsControlActive( m_controlRef
);
1108 void wxMacControl::Enable( bool enable
)
1111 EnableControl( m_controlRef
);
1113 DisableControl( m_controlRef
);
1116 void wxMacControl::SetDrawingEnabled( bool enable
)
1118 HIViewSetDrawingEnabled( m_controlRef
, enable
);
1121 bool wxMacControl::GetNeedsDisplay() const
1123 return HIViewGetNeedsDisplay( m_controlRef
);
1126 void wxMacControl::SetNeedsDisplay( RgnHandle where
)
1131 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, true );
1134 void wxMacControl::SetNeedsDisplay( Rect
* where
)
1139 if ( where
!= NULL
)
1141 RgnHandle update
= NewRgn();
1142 RectRgn( update
, where
);
1143 HIViewSetNeedsDisplayInRegion( m_controlRef
, update
, true );
1144 DisposeRgn( update
);
1147 HIViewSetNeedsDisplay( m_controlRef
, true );
1150 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
1156 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
);
1157 pt
->x
= (int)hiPoint
.x
;
1158 pt
->y
= (int)hiPoint
.y
;
1161 void wxMacControl::SetRect( Rect
*r
)
1163 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1164 //CGPoint and CGSize, which have two floats each
1165 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} };
1166 HIViewSetFrame ( m_controlRef
, &hir
);
1167 // eventuall we might have to do a SetVisibility( false , true );
1168 // before and a SetVisibility( true , true ); after
1171 void wxMacControl::GetRect( Rect
*r
)
1173 GetControlBounds( m_controlRef
, r
);
1176 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
1178 UMAGetControlBoundsInWindowCoords( m_controlRef
, r
);
1181 void wxMacControl::GetBestRect( Rect
*r
)
1183 short baselineoffset
;
1185 GetBestControlRect( m_controlRef
, r
, &baselineoffset
);
1188 void wxMacControl::SetLabel( const wxString
&title
)
1190 wxFontEncoding encoding
;
1193 encoding
= m_font
.GetEncoding();
1195 encoding
= wxFont::GetDefaultEncoding();
1197 UMASetControlTitle( m_controlRef
, title
, encoding
);
1200 void wxMacControl::GetFeatures( UInt32
* features
)
1202 GetControlFeatures( m_controlRef
, features
);
1205 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
1207 OSStatus err
= GetControlRegion( m_controlRef
, partCode
, region
);
1211 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
1213 #if TARGET_API_MAC_OSX
1214 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
1215 (other
!= NULL
) ? other
->m_controlRef
: NULL
);
1221 #if TARGET_API_MAC_OSX
1222 // SetNeedsDisplay would not invalidate the children
1223 static void InvalidateControlAndChildren( HIViewRef control
)
1225 HIViewSetNeedsDisplay( control
, true );
1226 UInt16 childrenCount
= 0;
1227 OSStatus err
= CountSubControls( control
, &childrenCount
);
1228 if ( err
== errControlIsNotEmbedder
)
1231 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") );
1233 for ( UInt16 i
= childrenCount
; i
>=1; --i
)
1237 err
= GetIndexedSubControl( control
, i
, & child
);
1238 if ( err
== errControlIsNotEmbedder
)
1241 InvalidateControlAndChildren( child
);
1246 void wxMacControl::InvalidateWithChildren()
1248 #if TARGET_API_MAC_OSX
1249 InvalidateControlAndChildren( m_controlRef
);
1253 void wxMacControl::ScrollRect( wxRect
*r
, int dx
, int dy
)
1255 wxASSERT( r
!= NULL
);
1257 HIRect scrollarea
= CGRectMake( r
->x
, r
->y
, r
->width
, r
->height
);
1258 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
);
1261 OSType wxMacCreator
= 'WXMC';
1262 OSType wxMacControlProperty
= 'MCCT';
1264 void wxMacControl::SetReferenceInNativeControl()
1267 verify_noerr( SetControlProperty ( m_controlRef
,
1268 wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data
) );
1271 wxMacControl
* wxMacControl::GetReferenceFromNativeControl(ControlRef control
)
1273 wxMacControl
* ctl
= NULL
;
1274 ByteCount actualSize
;
1275 if ( GetControlProperty( control
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) ,
1276 &actualSize
, &ctl
) == noErr
)
1283 // ============================================================================
1284 // DataBrowser Wrapper
1285 // ============================================================================
1287 // basing on DataBrowserItemIDs
1290 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
1292 DataBrowserItemID itemID
,
1293 DataBrowserItemNotification message
,
1294 DataBrowserItemDataRef itemData
)
1296 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1299 ctl
->ItemNotification(itemID
, message
, itemData
);
1303 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
1305 DataBrowserItemID itemID
,
1306 DataBrowserPropertyID property
,
1307 DataBrowserItemDataRef itemData
,
1308 Boolean changeValue
)
1310 OSStatus err
= errDataBrowserPropertyNotSupported
;
1311 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1314 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
1319 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
1321 DataBrowserItemID itemOneID
,
1322 DataBrowserItemID itemTwoID
,
1323 DataBrowserPropertyID sortProperty
)
1325 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1328 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
1333 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
1334 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
1335 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
1337 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) : wxMacControl( peer
)
1339 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
1340 OSStatus err
= ::CreateDataBrowserControl(
1341 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
1342 &bounds
, kDataBrowserListView
, &m_controlRef
);
1343 SetReferenceInNativeControl();
1344 verify_noerr( err
);
1345 if ( gDataBrowserItemCompareUPP
== NULL
)
1346 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
1347 if ( gDataBrowserItemDataUPP
== NULL
)
1348 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
1349 if ( gDataBrowserItemNotificationUPP
== NULL
)
1351 gDataBrowserItemNotificationUPP
=
1352 #if TARGET_API_MAC_OSX
1353 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
1355 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc
);
1359 DataBrowserCallbacks callbacks
;
1360 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
1362 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
1363 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
1364 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
1365 SetCallbacks( &callbacks
);
1369 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
1371 DataBrowserItemState state
,
1372 ItemCount
*numItems
) const
1374 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
1377 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
1379 DataBrowserItemState state
,
1382 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
1385 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1387 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
1390 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1391 DataBrowserTableViewColumnIndex position
)
1393 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
1396 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
){
1397 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
1400 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
1402 DataBrowserTableViewColumnID id
;
1403 GetColumnIDFromIndex( position
, &id
);
1404 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
1407 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
1409 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
1412 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
1414 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
1417 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1419 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
1422 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
1424 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1427 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
1429 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1432 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
1434 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
1437 OSStatus
wxMacDataBrowserControl::UpdateItems(
1438 DataBrowserItemID container
,
1440 const DataBrowserItemID
*items
,
1441 DataBrowserPropertyID preSortProperty
,
1442 DataBrowserPropertyID propertyID
) const
1444 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
1447 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
1449 return IsDataBrowserItemSelected( m_controlRef
, item
);
1452 OSStatus
wxMacDataBrowserControl::AddItems(
1453 DataBrowserItemID container
,
1455 const DataBrowserItemID
*items
,
1456 DataBrowserPropertyID preSortProperty
)
1458 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1461 OSStatus
wxMacDataBrowserControl::RemoveItems(
1462 DataBrowserItemID container
,
1464 const DataBrowserItemID
*items
,
1465 DataBrowserPropertyID preSortProperty
)
1467 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1470 OSStatus
wxMacDataBrowserControl::RevealItem(
1471 DataBrowserItemID item
,
1472 DataBrowserPropertyID propertyID
,
1473 DataBrowserRevealOptions options
) const
1475 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
1478 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
1480 const DataBrowserItemID
*items
,
1481 DataBrowserSetOption operation
)
1483 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
1486 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
1488 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
1491 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
1493 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
1496 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
1498 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
1501 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
1503 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1506 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
1508 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1511 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
1513 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1516 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
1518 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1521 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
1523 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1526 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
1528 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1531 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
1533 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1536 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
1538 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1541 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
1543 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
1546 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
1547 DataBrowserTableViewColumnIndex
*position
) const
1549 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1552 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
1554 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1557 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
1559 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1562 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
1564 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1567 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
1569 return GetDataBrowserSortProperty( m_controlRef
, column
);
1572 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
1574 return SetDataBrowserSortProperty( m_controlRef
, column
);
1577 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
1579 return GetDataBrowserSortOrder( m_controlRef
, order
);
1582 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
1584 return SetDataBrowserSortOrder( m_controlRef
, order
);
1587 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
1588 DataBrowserPropertyFlags
*flags
) const
1590 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1593 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
1594 DataBrowserPropertyFlags flags
)
1596 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1599 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
1600 DataBrowserListViewHeaderDesc
*desc
) const
1602 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1605 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
1606 DataBrowserListViewHeaderDesc
*desc
)
1608 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1611 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
1612 Boolean expandableRows
)
1614 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
1617 // ============================================================================
1618 // Higher-level Databrowser
1619 // ============================================================================
1621 // basing on data item objects
1624 wxMacDataItem::wxMacDataItem()
1628 m_colId
= kTextColumnId
; // for compat with existing wx*ListBox impls.
1631 wxMacDataItem::~wxMacDataItem()
1635 void wxMacDataItem::SetOrder( SInt32 order
)
1640 SInt32
wxMacDataItem::GetOrder() const
1645 void wxMacDataItem::SetData( void* data
)
1650 void* wxMacDataItem::GetData() const
1655 short wxMacDataItem::GetColumn()
1660 void wxMacDataItem::SetColumn( short col
)
1665 void wxMacDataItem::SetLabel( const wxString
& str
)
1668 m_cfLabel
.Assign( str
, wxLocale::GetSystemEncoding());
1671 const wxString
& wxMacDataItem::GetLabel() const
1676 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*owner
,
1677 const wxMacDataItem
* rhs
,
1678 DataBrowserPropertyID sortProperty
) const
1680 const wxMacDataItem
* otherItem
= dynamic_cast<const wxMacDataItem
*>(rhs
);
1681 bool retval
= false;
1683 if ( sortProperty
== m_colId
){
1684 retval
= m_label
.CmpNoCase( otherItem
->m_label
) < 0;
1687 else if ( sortProperty
== kNumericOrderColumnId
)
1688 retval
= m_order
< otherItem
->m_order
;
1693 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*owner
,
1694 DataBrowserPropertyID property
,
1695 DataBrowserItemDataRef itemData
,
1698 OSStatus err
= errDataBrowserPropertyNotSupported
;
1701 if ( property
== m_colId
){
1702 err
= ::SetDataBrowserItemDataText( itemData
, m_cfLabel
);
1705 else if ( property
== kNumericOrderColumnId
){
1706 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
1716 // no editable props here
1725 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*owner
,
1726 DataBrowserItemNotification message
,
1727 DataBrowserItemDataRef itemData
) const
1732 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1733 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1735 m_suppressSelection
= false;
1736 m_sortOrder
= SortOrder_None
;
1737 m_clientDataItemsType
= wxClientData_None
;
1740 wxMacDataItem
* wxMacDataItemBrowserControl::CreateItem()
1742 return new wxMacDataItem();
1745 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1747 m_former
= browser
->SuppressSelection(true);
1748 m_browser
= browser
;
1751 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1753 m_browser
->SuppressSelection(m_former
);
1756 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
1758 bool former
= m_suppressSelection
;
1759 m_suppressSelection
= suppress
;
1764 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
1765 DataBrowserItemID itemTwoID
,
1766 DataBrowserPropertyID sortProperty
)
1768 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1769 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1770 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1773 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
1774 const wxMacDataItem
* itemTwo
,
1775 DataBrowserPropertyID sortProperty
)
1777 Boolean retval
= false;
1778 if ( itemOne
!= NULL
)
1779 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1783 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1784 DataBrowserItemID itemID
,
1785 DataBrowserPropertyID property
,
1786 DataBrowserItemDataRef itemData
,
1787 Boolean changeValue
)
1789 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1790 return GetSetItemData(item
, property
, itemData
, changeValue
);
1793 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1794 wxMacDataItem
* item
,
1795 DataBrowserPropertyID property
,
1796 DataBrowserItemDataRef itemData
,
1797 Boolean changeValue
)
1799 OSStatus err
= errDataBrowserPropertyNotSupported
;
1802 case kDataBrowserContainerIsClosableProperty
:
1803 case kDataBrowserContainerIsSortableProperty
:
1804 case kDataBrowserContainerIsOpenableProperty
:
1805 // right now default behaviour on these
1809 if ( item
!= NULL
){
1810 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1818 void wxMacDataItemBrowserControl::ItemNotification(
1819 DataBrowserItemID itemID
,
1820 DataBrowserItemNotification message
,
1821 DataBrowserItemDataRef itemData
)
1823 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1824 ItemNotification( item
, message
, itemData
);
1827 void wxMacDataItemBrowserControl::ItemNotification(
1828 const wxMacDataItem
* item
,
1829 DataBrowserItemNotification message
,
1830 DataBrowserItemDataRef itemData
)
1833 item
->Notification( this, message
, itemData
);
1836 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
1837 bool recurse
, DataBrowserItemState state
) const
1839 ItemCount numItems
= 0;
1840 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
1841 recurse
, state
, &numItems
) );
1845 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
1846 bool recurse
) const
1848 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
1852 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
1853 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1855 Handle handle
= NewHandle(0);
1856 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
1857 recurse
, state
, handle
) );
1859 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1861 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1862 for ( int i
= 0; i
< itemCount
; ++i
)
1864 items
.Add(itemsArray
[i
]);
1867 DisposeHandle( handle
);
1870 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
1872 DataBrowserTableViewRowIndex row
;
1873 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1874 wxASSERT( err
== noErr
);
1878 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
1880 DataBrowserItemID id
;
1881 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1882 wxASSERT( err
== noErr
);
1883 return (wxMacDataItem
*) id
;
1886 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
1887 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1889 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
1890 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1893 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
1894 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1896 unsigned int noItems
= itemArray
.GetCount();
1897 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1898 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1899 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1901 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
1902 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1906 void wxMacDataItemBrowserControl::InsertColumn(int colId
, DataBrowserPropertyType colType
,
1907 const wxString
& title
, SInt16 just
, int defaultWidth
)
1909 DataBrowserListViewColumnDesc columnDesc
;
1910 columnDesc
.headerBtnDesc
.titleOffset
= 0;
1911 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
1913 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
1914 kControlUseFontMask
| kControlUseJustMask
;
1916 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
1917 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
1918 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
1919 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
1921 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
1922 // defined for other modes?
1925 enc
= m_font
.GetEncoding();
1927 enc
= wxLocale::GetSystemEncoding();
1928 wxMacCFStringHolder cfTitle
;
1929 cfTitle
.Assign( title
, enc
);
1930 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
1932 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
1933 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
1935 columnDesc
.propertyDesc
.propertyID
= (kMinColumnId
+ colId
);
1936 columnDesc
.propertyDesc
.propertyType
= colType
;
1937 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
| kDataBrowserListViewTypeSelectColumn
;
1938 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1939 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
1942 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
1944 if (defaultWidth
> 0){
1945 SetColumnWidth(colId
, defaultWidth
);
1950 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
1952 DataBrowserPropertyID id
;
1953 GetColumnIDFromIndex(colId
, &id
);
1954 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
1957 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
1959 DataBrowserPropertyID id
;
1960 GetColumnIDFromIndex(colId
, &id
);
1962 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
1966 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1968 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
1969 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1972 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1974 unsigned int noItems
= itemArray
.GetCount();
1975 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1976 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1977 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1979 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
1980 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1984 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1986 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
1987 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
1988 verify_noerr( err
);
1991 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1993 unsigned int noItems
= itemArray
.GetCount();
1994 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1995 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1996 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1998 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
1999 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
2000 verify_noerr( err
);
2004 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
2006 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
2007 verify_noerr( err
);
2010 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
2012 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
2015 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
2017 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
2020 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
2022 unsigned int noItems
= itemArray
.GetCount();
2023 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
2024 for ( unsigned int i
= 0; i
< noItems
; ++i
)
2025 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
2027 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
2031 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
2033 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
2036 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
2038 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
2041 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
2043 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
2046 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
2048 return m_clientDataItemsType
;
2050 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
2052 m_clientDataItemsType
= clientDataItemsType
;
2055 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
2057 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);
2060 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
2062 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
2063 RemoveItem( wxMacDataBrowserRootContainer
, item
);
2066 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, const wxString
& text
, int column
)
2068 wxMacDataItem
* newItem
= CreateItem();
2069 newItem
->SetLabel( text
);
2071 newItem
->SetColumn( kMinColumnId
+ column
);
2073 if ( m_sortOrder
== SortOrder_None
)
2075 // increase the order of the lines to be shifted
2076 unsigned int lines
= MacGetCount();
2077 for ( unsigned int i
= n
; i
< lines
; ++i
)
2079 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
2080 iter
->SetOrder( iter
->GetOrder() + 1 );
2083 SInt32 frontLineOrder
= 0;
2086 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
2087 frontLineOrder
= iter
->GetOrder();
2089 newItem
->SetOrder( frontLineOrder
+ 1 );
2092 AddItem( wxMacDataBrowserRootContainer
, newItem
);
2095 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, const wxArrayString
& items
, int column
)
2097 size_t itemsCount
= items
.GetCount();
2098 if ( itemsCount
== 0 )
2101 SInt32 frontLineOrder
= 0;
2103 if ( m_sortOrder
== SortOrder_None
)
2105 // increase the order of the lines to be shifted
2106 unsigned int lines
= MacGetCount();
2107 for ( unsigned int i
= n
; i
< lines
; ++i
)
2109 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
2110 iter
->SetOrder( iter
->GetOrder() + itemsCount
);
2114 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
2115 frontLineOrder
= iter
->GetOrder();
2119 wxArrayMacDataItemPtr ids
;
2120 ids
.SetCount( itemsCount
);
2122 for ( unsigned int i
= 0; i
< itemsCount
; ++i
)
2124 wxMacDataItem
* item
= CreateItem();
2125 item
->SetLabel( items
[i
]);
2127 item
->SetColumn( kMinColumnId
+ column
);
2129 if ( m_sortOrder
== SortOrder_None
)
2130 item
->SetOrder( frontLineOrder
+ 1 + i
);
2135 AddItems( wxMacDataBrowserRootContainer
, ids
);
2138 int wxMacDataItemBrowserControl::MacAppend( const wxString
& text
)
2140 wxMacDataItem
* item
= CreateItem();
2141 item
->SetLabel( text
);
2142 if ( m_sortOrder
== SortOrder_None
)
2144 unsigned int lines
= MacGetCount();
2146 item
->SetOrder( 1 );
2149 wxMacDataItem
* frontItem
= (wxMacDataItem
*) GetItemFromLine(lines
-1);
2150 item
->SetOrder( frontItem
->GetOrder() + 1 );
2153 AddItem( wxMacDataBrowserRootContainer
, item
);
2155 return GetLineFromItem(item
);
2158 void wxMacDataItemBrowserControl::MacClear()
2160 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2161 RemoveAllItems(wxMacDataBrowserRootContainer
);
2164 void wxMacDataItemBrowserControl::MacDeselectAll()
2166 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2167 SetSelectedAllItems( kDataBrowserItemsRemove
);
2170 void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n
, bool select
, bool multi
)
2172 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
2173 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2175 if ( IsItemSelected( item
) != select
)
2178 SetSelectedItem( item
, multi
? kDataBrowserItemsAdd
: kDataBrowserItemsAssign
);
2180 SetSelectedItem( item
, kDataBrowserItemsRemove
);
2186 bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n
) const
2188 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
2189 return IsItemSelected( item
);
2192 int wxMacDataItemBrowserControl::MacGetSelection() const
2194 wxMacDataItemPtr first
, last
;
2195 GetSelectionAnchor( &first
, &last
);
2197 if ( first
!= NULL
)
2199 return GetLineFromItem( first
);
2205 int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt
& aSelections
) const
2207 aSelections
.Empty();
2208 wxArrayMacDataItemPtr selectedItems
;
2209 GetItems( wxMacDataBrowserRootContainer
, false , kDataBrowserItemIsSelected
, selectedItems
);
2211 int count
= selectedItems
.GetCount();
2213 for ( int i
= 0; i
< count
; ++i
)
2215 aSelections
.Add(GetLineFromItem(selectedItems
[i
]));
2221 void wxMacDataItemBrowserControl::MacSetString( unsigned int n
, const wxString
& text
)
2223 // as we don't store the strings we only have to issue a redraw
2224 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2225 item
->SetLabel( text
);
2226 UpdateItem( wxMacDataBrowserRootContainer
, item
, kTextColumnId
);
2229 wxString
wxMacDataItemBrowserControl::MacGetString( unsigned int n
) const
2231 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2232 return item
->GetLabel();
2235 void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n
, void * data
)
2237 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2238 item
->SetData( data
);
2239 // not displayed, therefore no Update infos to DataBrowser
2242 void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n
) const
2244 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2245 return item
->GetData();
2248 void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n
)
2250 RevealItem( GetItemFromLine( n
) , kDataBrowserRevealWithoutSelecting
);
2259 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
2261 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
2268 #ifdef __WXMAC_OSX__
2269 // snippets from Sketch Sample from Apple :
2271 #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
2274 This function locates, opens, and returns the profile reference for the calibrated
2275 Generic RGB color space. It is up to the caller to call CMCloseProfile when done
2276 with the profile reference this function returns.
2278 CMProfileRef
wxMacOpenGenericProfile()
2280 static CMProfileRef cachedRGBProfileRef
= NULL
;
2282 // we only create the profile reference once
2283 if (cachedRGBProfileRef
== NULL
)
2285 CMProfileLocation loc
;
2287 loc
.locType
= cmPathBasedProfile
;
2288 strcpy(loc
.u
.pathLoc
.path
, kGenericRGBProfilePathStr
);
2290 verify_noerr( CMOpenProfile(&cachedRGBProfileRef
, &loc
) );
2293 // clone the profile reference so that the caller has their own reference, not our cached one
2294 if (cachedRGBProfileRef
)
2295 CMCloneProfileRef(cachedRGBProfileRef
);
2297 return cachedRGBProfileRef
;
2301 Return the generic RGB color space. This is a 'get' function and the caller should
2302 not release the returned value unless the caller retains it first. Usually callers
2303 of this routine will immediately use the returned colorspace with CoreGraphics
2304 so they typically do not need to retain it themselves.
2306 This function creates the generic RGB color space once and hangs onto it so it can
2307 return it whenever this function is called.
2310 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
2312 static wxMacCFRefHolder
<CGColorSpaceRef
> genericRGBColorSpace
;
2314 if (genericRGBColorSpace
== NULL
)
2316 if ( UMAGetSystemVersion() >= 0x1040 )
2318 genericRGBColorSpace
.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) );
2322 CMProfileRef genericRGBProfile
= wxMacOpenGenericProfile();
2324 if (genericRGBProfile
)
2326 genericRGBColorSpace
.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile
) );
2328 wxASSERT_MSG( genericRGBColorSpace
!= NULL
, wxT("couldn't create the generic RGB color space") );
2330 // we opened the profile so it is up to us to close it
2331 CMCloseProfile(genericRGBProfile
);
2336 return genericRGBColorSpace
;
2342 wxMacPortSaver::wxMacPortSaver( GrafPtr port
)
2344 ::GetPort( &m_port
);
2348 wxMacPortSaver::~wxMacPortSaver()
2350 ::SetPort( m_port
);
2354 void wxMacGlobalToLocal( WindowRef window
, Point
*pt
)
2356 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
2357 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
2358 HIViewRef contentView
;
2359 // TODO check toolbar offset
2360 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
2361 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
2365 QDGlobalToLocalPoint( GetWindowPort(window
), pt
) ;
2369 void wxMacLocalToGlobal( WindowRef window
, Point
*pt
)
2371 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
2372 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
2373 HIViewRef contentView
;
2374 // TODO check toolbar offset
2375 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
2376 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
2380 QDLocalToGlobalPoint( GetWindowPort(window
), pt
) ;