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()
1629 m_colId
= kTextColumnId
; // for compat with existing wx*ListBox impls.
1632 wxMacDataItem::~wxMacDataItem()
1636 void wxMacDataItem::SetOrder( SInt32 order
)
1641 SInt32
wxMacDataItem::GetOrder() const
1646 void wxMacDataItem::SetData( void* data
)
1651 void* wxMacDataItem::GetData() const
1656 short wxMacDataItem::GetColumn()
1661 void wxMacDataItem::SetColumn( short col
)
1666 void wxMacDataItem::SetLabel( const wxString
& str
)
1669 m_cfLabel
.Assign( str
, wxLocale::GetSystemEncoding());
1672 const wxString
& wxMacDataItem::GetLabel() const
1677 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*owner
,
1678 const wxMacDataItem
* rhs
,
1679 DataBrowserPropertyID sortProperty
) const
1681 const wxMacDataItem
* otherItem
= dynamic_cast<const wxMacDataItem
*>(rhs
);
1682 bool retval
= false;
1684 if ( sortProperty
== m_colId
){
1685 retval
= m_label
.CmpNoCase( otherItem
->m_label
) < 0;
1688 else if ( sortProperty
== kNumericOrderColumnId
)
1689 retval
= m_order
< otherItem
->m_order
;
1694 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*owner
,
1695 DataBrowserPropertyID property
,
1696 DataBrowserItemDataRef itemData
,
1699 OSStatus err
= errDataBrowserPropertyNotSupported
;
1702 if ( property
== m_colId
){
1703 err
= ::SetDataBrowserItemDataText( itemData
, m_cfLabel
);
1706 else if ( property
== kNumericOrderColumnId
){
1707 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
1717 // no editable props here
1726 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*owner
,
1727 DataBrowserItemNotification message
,
1728 DataBrowserItemDataRef itemData
) const
1733 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1734 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1736 m_suppressSelection
= false;
1737 m_sortOrder
= SortOrder_None
;
1738 m_clientDataItemsType
= wxClientData_None
;
1741 wxMacDataItem
* wxMacDataItemBrowserControl::CreateItem()
1743 return new wxMacDataItem();
1746 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1748 m_former
= browser
->SuppressSelection(true);
1749 m_browser
= browser
;
1752 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1754 m_browser
->SuppressSelection(m_former
);
1757 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
1759 bool former
= m_suppressSelection
;
1760 m_suppressSelection
= suppress
;
1765 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
1766 DataBrowserItemID itemTwoID
,
1767 DataBrowserPropertyID sortProperty
)
1769 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1770 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1771 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1774 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
1775 const wxMacDataItem
* itemTwo
,
1776 DataBrowserPropertyID sortProperty
)
1778 Boolean retval
= false;
1779 if ( itemOne
!= NULL
)
1780 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1784 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1785 DataBrowserItemID itemID
,
1786 DataBrowserPropertyID property
,
1787 DataBrowserItemDataRef itemData
,
1788 Boolean changeValue
)
1790 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1791 return GetSetItemData(item
, property
, itemData
, changeValue
);
1794 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1795 wxMacDataItem
* item
,
1796 DataBrowserPropertyID property
,
1797 DataBrowserItemDataRef itemData
,
1798 Boolean changeValue
)
1800 OSStatus err
= errDataBrowserPropertyNotSupported
;
1803 case kDataBrowserContainerIsClosableProperty
:
1804 case kDataBrowserContainerIsSortableProperty
:
1805 case kDataBrowserContainerIsOpenableProperty
:
1806 // right now default behaviour on these
1810 if ( item
!= NULL
){
1811 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1819 void wxMacDataItemBrowserControl::ItemNotification(
1820 DataBrowserItemID itemID
,
1821 DataBrowserItemNotification message
,
1822 DataBrowserItemDataRef itemData
)
1824 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1825 ItemNotification( item
, message
, itemData
);
1828 void wxMacDataItemBrowserControl::ItemNotification(
1829 const wxMacDataItem
* item
,
1830 DataBrowserItemNotification message
,
1831 DataBrowserItemDataRef itemData
)
1834 item
->Notification( this, message
, itemData
);
1837 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
1838 bool recurse
, DataBrowserItemState state
) const
1840 ItemCount numItems
= 0;
1841 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
1842 recurse
, state
, &numItems
) );
1846 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
1847 bool recurse
) const
1849 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
1853 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
1854 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1856 Handle handle
= NewHandle(0);
1857 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
1858 recurse
, state
, handle
) );
1860 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1862 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1863 for ( int i
= 0; i
< itemCount
; ++i
)
1865 items
.Add(itemsArray
[i
]);
1868 DisposeHandle( handle
);
1871 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
1873 DataBrowserTableViewRowIndex row
;
1874 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1875 wxASSERT( err
== noErr
);
1879 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
1881 DataBrowserItemID id
;
1882 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1883 wxASSERT( err
== noErr
);
1884 return (wxMacDataItem
*) id
;
1887 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
1888 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1890 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
1891 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1894 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
1895 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1897 unsigned int noItems
= itemArray
.GetCount();
1898 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1899 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1900 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1902 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
1903 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1907 void wxMacDataItemBrowserControl::InsertColumn(int colId
, DataBrowserPropertyType colType
,
1908 const wxString
& title
, SInt16 just
, int defaultWidth
)
1910 DataBrowserListViewColumnDesc columnDesc
;
1911 columnDesc
.headerBtnDesc
.titleOffset
= 0;
1912 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
1914 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
1915 kControlUseFontMask
| kControlUseJustMask
;
1917 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
1918 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
1919 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
1920 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
1922 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
1923 // defined for other modes?
1926 enc
= m_font
.GetEncoding();
1928 enc
= wxLocale::GetSystemEncoding();
1929 wxMacCFStringHolder cfTitle
;
1930 cfTitle
.Assign( title
, enc
);
1931 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
1933 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
1934 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
1936 columnDesc
.propertyDesc
.propertyID
= (kMinColumnId
+ colId
);
1937 columnDesc
.propertyDesc
.propertyType
= colType
;
1938 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
1939 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1940 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
1942 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1943 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
1946 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
1948 if (defaultWidth
> 0){
1949 SetColumnWidth(colId
, defaultWidth
);
1954 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
1956 DataBrowserPropertyID id
;
1957 GetColumnIDFromIndex(colId
, &id
);
1958 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
1961 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
1963 DataBrowserPropertyID id
;
1964 GetColumnIDFromIndex(colId
, &id
);
1966 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
1970 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1972 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
1973 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1976 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1978 unsigned int noItems
= itemArray
.GetCount();
1979 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1980 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1981 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1983 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
1984 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1988 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1990 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
1991 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
1992 verify_noerr( err
);
1995 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1997 unsigned int noItems
= itemArray
.GetCount();
1998 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1999 for ( unsigned int i
= 0; i
< noItems
; ++i
)
2000 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
2002 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
2003 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
2004 verify_noerr( err
);
2008 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
2010 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
2011 verify_noerr( err
);
2014 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
2016 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
2019 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
2021 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
2024 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
2026 unsigned int noItems
= itemArray
.GetCount();
2027 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
2028 for ( unsigned int i
= 0; i
< noItems
; ++i
)
2029 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
2031 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
2035 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
2037 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
2040 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
2042 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
2045 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
2047 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
2050 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
2052 return m_clientDataItemsType
;
2054 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
2056 m_clientDataItemsType
= clientDataItemsType
;
2059 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
2061 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);
2064 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
2066 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
2067 RemoveItem( wxMacDataBrowserRootContainer
, item
);
2070 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, const wxString
& text
, int column
)
2072 wxMacDataItem
* newItem
= CreateItem();
2073 newItem
->SetLabel( text
);
2075 newItem
->SetColumn( kMinColumnId
+ column
);
2077 if ( m_sortOrder
== SortOrder_None
)
2079 // increase the order of the lines to be shifted
2080 unsigned int lines
= MacGetCount();
2081 for ( unsigned int i
= n
; i
< lines
; ++i
)
2083 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
2084 iter
->SetOrder( iter
->GetOrder() + 1 );
2087 SInt32 frontLineOrder
= 0;
2090 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
2091 frontLineOrder
= iter
->GetOrder();
2093 newItem
->SetOrder( frontLineOrder
+ 1 );
2096 AddItem( wxMacDataBrowserRootContainer
, newItem
);
2099 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, const wxArrayString
& items
, int column
)
2101 size_t itemsCount
= items
.GetCount();
2102 if ( itemsCount
== 0 )
2105 SInt32 frontLineOrder
= 0;
2107 if ( m_sortOrder
== SortOrder_None
)
2109 // increase the order of the lines to be shifted
2110 unsigned int lines
= MacGetCount();
2111 for ( unsigned int i
= n
; i
< lines
; ++i
)
2113 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
2114 iter
->SetOrder( iter
->GetOrder() + itemsCount
);
2118 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
2119 frontLineOrder
= iter
->GetOrder();
2123 wxArrayMacDataItemPtr ids
;
2124 ids
.SetCount( itemsCount
);
2126 for ( unsigned int i
= 0; i
< itemsCount
; ++i
)
2128 wxMacDataItem
* item
= CreateItem();
2129 item
->SetLabel( items
[i
]);
2131 item
->SetColumn( kMinColumnId
+ column
);
2133 if ( m_sortOrder
== SortOrder_None
)
2134 item
->SetOrder( frontLineOrder
+ 1 + i
);
2139 AddItems( wxMacDataBrowserRootContainer
, ids
);
2142 int wxMacDataItemBrowserControl::MacAppend( const wxString
& text
)
2144 wxMacDataItem
* item
= CreateItem();
2145 item
->SetLabel( text
);
2146 if ( m_sortOrder
== SortOrder_None
)
2148 unsigned int lines
= MacGetCount();
2150 item
->SetOrder( 1 );
2153 wxMacDataItem
* frontItem
= (wxMacDataItem
*) GetItemFromLine(lines
-1);
2154 item
->SetOrder( frontItem
->GetOrder() + 1 );
2157 AddItem( wxMacDataBrowserRootContainer
, item
);
2159 return GetLineFromItem(item
);
2162 void wxMacDataItemBrowserControl::MacClear()
2164 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2165 RemoveAllItems(wxMacDataBrowserRootContainer
);
2168 void wxMacDataItemBrowserControl::MacDeselectAll()
2170 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2171 SetSelectedAllItems( kDataBrowserItemsRemove
);
2174 void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n
, bool select
, bool multi
)
2176 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
2177 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2179 if ( IsItemSelected( item
) != select
)
2182 SetSelectedItem( item
, multi
? kDataBrowserItemsAdd
: kDataBrowserItemsAssign
);
2184 SetSelectedItem( item
, kDataBrowserItemsRemove
);
2190 bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n
) const
2192 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
2193 return IsItemSelected( item
);
2196 int wxMacDataItemBrowserControl::MacGetSelection() const
2198 wxMacDataItemPtr first
, last
;
2199 GetSelectionAnchor( &first
, &last
);
2201 if ( first
!= NULL
)
2203 return GetLineFromItem( first
);
2209 int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt
& aSelections
) const
2211 aSelections
.Empty();
2212 wxArrayMacDataItemPtr selectedItems
;
2213 GetItems( wxMacDataBrowserRootContainer
, false , kDataBrowserItemIsSelected
, selectedItems
);
2215 int count
= selectedItems
.GetCount();
2217 for ( int i
= 0; i
< count
; ++i
)
2219 aSelections
.Add(GetLineFromItem(selectedItems
[i
]));
2225 void wxMacDataItemBrowserControl::MacSetString( unsigned int n
, const wxString
& text
)
2227 // as we don't store the strings we only have to issue a redraw
2228 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2229 item
->SetLabel( text
);
2230 UpdateItem( wxMacDataBrowserRootContainer
, item
, kTextColumnId
);
2233 wxString
wxMacDataItemBrowserControl::MacGetString( unsigned int n
) const
2235 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2236 return item
->GetLabel();
2239 void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n
, void * data
)
2241 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2242 item
->SetData( data
);
2243 // not displayed, therefore no Update infos to DataBrowser
2246 void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n
) const
2248 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2249 return item
->GetData();
2252 void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n
)
2254 RevealItem( GetItemFromLine( n
) , kDataBrowserRevealWithoutSelecting
);
2263 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
2265 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
2272 #ifdef __WXMAC_OSX__
2273 // snippets from Sketch Sample from Apple :
2275 #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
2278 This function locates, opens, and returns the profile reference for the calibrated
2279 Generic RGB color space. It is up to the caller to call CMCloseProfile when done
2280 with the profile reference this function returns.
2282 CMProfileRef
wxMacOpenGenericProfile()
2284 static CMProfileRef cachedRGBProfileRef
= NULL
;
2286 // we only create the profile reference once
2287 if (cachedRGBProfileRef
== NULL
)
2289 CMProfileLocation loc
;
2291 loc
.locType
= cmPathBasedProfile
;
2292 strcpy(loc
.u
.pathLoc
.path
, kGenericRGBProfilePathStr
);
2294 verify_noerr( CMOpenProfile(&cachedRGBProfileRef
, &loc
) );
2297 // clone the profile reference so that the caller has their own reference, not our cached one
2298 if (cachedRGBProfileRef
)
2299 CMCloneProfileRef(cachedRGBProfileRef
);
2301 return cachedRGBProfileRef
;
2305 Return the generic RGB color space. This is a 'get' function and the caller should
2306 not release the returned value unless the caller retains it first. Usually callers
2307 of this routine will immediately use the returned colorspace with CoreGraphics
2308 so they typically do not need to retain it themselves.
2310 This function creates the generic RGB color space once and hangs onto it so it can
2311 return it whenever this function is called.
2314 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
2316 static wxMacCFRefHolder
<CGColorSpaceRef
> genericRGBColorSpace
;
2318 if (genericRGBColorSpace
== NULL
)
2320 if ( UMAGetSystemVersion() >= 0x1040 )
2322 genericRGBColorSpace
.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) );
2326 CMProfileRef genericRGBProfile
= wxMacOpenGenericProfile();
2328 if (genericRGBProfile
)
2330 genericRGBColorSpace
.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile
) );
2332 wxASSERT_MSG( genericRGBColorSpace
!= NULL
, wxT("couldn't create the generic RGB color space") );
2334 // we opened the profile so it is up to us to close it
2335 CMCloseProfile(genericRGBProfile
);
2340 return genericRGBColorSpace
;
2346 wxMacPortSaver::wxMacPortSaver( GrafPtr port
)
2348 ::GetPort( &m_port
);
2352 wxMacPortSaver::~wxMacPortSaver()
2354 ::SetPort( m_port
);
2358 void wxMacGlobalToLocal( WindowRef window
, Point
*pt
)
2360 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
2361 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
2362 HIViewRef contentView
;
2363 // TODO check toolbar offset
2364 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
2365 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
2369 QDGlobalToLocalPoint( GetWindowPort(window
), pt
) ;
2373 void wxMacLocalToGlobal( WindowRef window
, Point
*pt
)
2375 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
2376 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
2377 HIViewRef contentView
;
2378 // TODO check toolbar offset
2379 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
2380 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
2384 QDLocalToGlobalPoint( GetWindowPort(window
), pt
) ;