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__)
70 // ---------------------------------------------------------------------------
71 // code used in both base and GUI compilation
72 // ---------------------------------------------------------------------------
74 // our OS version is the same in non GUI and GUI cases
75 static int DoGetOSVersion(int *majorVsn
, int *minorVsn
)
79 // are there x-platform conventions ?
81 Gestalt(gestaltSystemVersion
, &theSystem
);
83 *minorVsn
= (theSystem
& 0xFF);
86 *majorVsn
= (theSystem
>> 8);
98 // ----------------------------------------------------------------------------
100 // ----------------------------------------------------------------------------
102 #if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
104 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
106 #ifndef __MetroNubUtils__
107 #include "MetroNubUtils.h"
114 #if TARGET_API_MAC_CARBON
116 #include <CodeFragments.h>
118 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
120 ProcPtr gCallUniversalProc_Proc
= NULL
;
124 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
126 static long fRunOnce
= false;
129 Boolean
IsMetroNubInstalled()
136 gMetroNubEntry
= NULL
;
138 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
140 // look for MetroNub's Gestalt selector
141 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
143 #if TARGET_API_MAC_CARBON
144 if (gCallUniversalProc_Proc
== NULL
)
146 CFragConnectionID connectionID
;
149 ProcPtr symbolAddress
;
151 CFragSymbolClass symbolClass
;
153 symbolAddress
= NULL
;
154 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
155 &connectionID
, &mainAddress
, errorString
);
159 gCallUniversalProc_Proc
= NULL
;
163 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
164 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
168 gCallUniversalProc_Proc
= NULL
;
175 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
177 // make sure the version of the API is compatible
178 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
179 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
182 gMetroNubEntry
= block
;
191 #if TARGET_API_MAC_CARBON
192 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
194 return (gMetroNubEntry
!= NULL
);
198 Boolean
IsMWDebuggerRunning()
200 if (IsMetroNubInstalled())
201 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
206 Boolean
AmIBeingMWDebugged()
208 if (IsMetroNubInstalled())
209 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
214 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
216 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
221 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
226 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
230 // defined in unix/utilsunx.cpp for Mac OS X
232 // get full hostname (with domain name if possible)
233 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
235 return wxGetHostName(buf
, maxSize
);
238 // Get user ID e.g. jacs
239 bool wxGetUserId(wxChar
*buf
, int maxSize
)
241 return wxGetUserName( buf
, maxSize
);
244 const wxChar
* wxGetHomeDir(wxString
*pstr
)
246 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
);
247 return pstr
->c_str();
250 // Get hostname only (without domain name)
251 bool wxGetHostName(wxChar
*buf
, int maxSize
)
253 // Gets Chooser name of user by examining a System resource.
256 const short kComputerNameID
= -16413;
258 short oldResFile
= CurResFile();
260 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
261 UseResFile(oldResFile
);
263 if (chooserName
&& *chooserName
)
265 HLock( (Handle
) chooserName
);
266 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
267 HUnlock( (Handle
) chooserName
);
268 ReleaseResource( (Handle
) chooserName
);
269 wxStrncpy( buf
, name
, maxSize
- 1 );
275 // Get user name e.g. Stefan Csomor
276 bool wxGetUserName(wxChar
*buf
, int maxSize
)
278 // Gets Chooser name of user by examining a System resource.
281 const short kChooserNameID
= -16096;
283 short oldResFile
= CurResFile();
285 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
286 UseResFile(oldResFile
);
288 if (chooserName
&& *chooserName
)
290 HLock( (Handle
) chooserName
);
291 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
292 HUnlock( (Handle
) chooserName
);
293 ReleaseResource( (Handle
) chooserName
);
294 wxStrncpy( buf
, name
, maxSize
- 1 );
300 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
, int flags
)
306 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
308 // TODO : under classic there is no environement support, under X yes
312 // set the env var name to the given value, return true on success
313 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
315 // TODO : under classic there is no environement support, under X yes
319 // Execute a program in an Interactive Shell
320 bool wxShell(const wxString
& command
)
326 // Shutdown or reboot the PC
327 bool wxShutdown(wxShutdownFlags wFlags
)
333 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
334 wxMemorySize
wxGetFreeMemory()
336 return (wxMemorySize
)FreeMem();
341 void wxMicroSleep(unsigned long microseconds
)
343 AbsoluteTime wakeup
= AddDurationToAbsolute( microseconds
* durationMicrosecond
, UpTime());
344 MPDelayUntil( & wakeup
);
347 void wxMilliSleep(unsigned long milliseconds
)
349 AbsoluteTime wakeup
= AddDurationToAbsolute( milliseconds
, UpTime());
350 MPDelayUntil( & wakeup
);
353 void wxSleep(int nSecs
)
355 wxMilliSleep(1000*nSecs
);
360 // Consume all events until no more left
365 #endif // !__DARWIN__
373 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
375 static wxToolkitInfo info
;
377 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
378 info
.name
= _T("wxBase");
387 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
389 static wxToolkitInfo info
;
391 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
392 info
.shortName
= _T("mac");
393 info
.name
= _T("wxMac");
395 #ifdef __WXUNIVERSAL__
396 info
.shortName
<< _T("univ");
397 info
.name
<< _T("/wxUniversal");
403 // Reading and writing resources (eg WIN.INI, .Xdefaults)
405 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
411 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
414 buf
.Printf(wxT("%.4f"), value
);
416 return wxWriteResource(section
, entry
, buf
, file
);
419 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
422 buf
.Printf(wxT("%ld"), value
);
424 return wxWriteResource(section
, entry
, buf
, file
);
427 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
430 buf
.Printf(wxT("%d"), value
);
432 return wxWriteResource(section
, entry
, buf
, file
);
435 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
441 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
444 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
447 *value
= (float)strtod(s
, NULL
);
454 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
457 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
460 *value
= strtol(s
, NULL
, 10);
467 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
470 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
473 *value
= (int)strtol(s
, NULL
, 10);
479 #endif // wxUSE_RESOURCES
481 int gs_wxBusyCursorCount
= 0;
482 extern wxCursor gMacCurrentCursor
;
483 wxCursor gMacStoredActiveCursor
;
485 // Set the cursor to the busy cursor for all windows
486 void wxBeginBusyCursor(const wxCursor
*cursor
)
488 if (gs_wxBusyCursorCount
++ == 0)
490 gMacStoredActiveCursor
= gMacCurrentCursor
;
491 cursor
->MacInstall();
493 //else: nothing to do, already set
496 // Restore cursor to normal
497 void wxEndBusyCursor()
499 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
500 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
502 if (--gs_wxBusyCursorCount
== 0)
504 gMacStoredActiveCursor
.MacInstall();
505 gMacStoredActiveCursor
= wxNullCursor
;
509 // true if we're between the above two calls
512 return (gs_wxBusyCursorCount
> 0);
519 wxString
wxMacFindFolderNoSeparator( short vol
,
521 Boolean createFolder
)
526 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
528 strDir
= wxMacFSRefToPath( &fsRef
);
534 wxString
wxMacFindFolder( short vol
,
536 Boolean createFolder
)
538 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
545 // Check whether this window wants to process messages, e.g. Stop button
546 // in long calculations.
547 bool wxCheckForInterrupt(wxWindow
*wnd
)
553 void wxGetMousePosition( int* x
, int* y
)
558 LocalToGlobal( &pt
);
563 // Return true if we have a colour display
564 bool wxColourDisplay()
569 // Returns depth of screen
573 SetRect(&globRect
, -32760, -32760, 32760, 32760);
574 GDHandle theMaxDevice
;
577 theMaxDevice
= GetMaxDevice(&globRect
);
578 if (theMaxDevice
!= NULL
)
579 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
584 // Get size of display
585 void wxDisplaySize(int *width
, int *height
)
588 GetQDGlobalsScreenBits( &screenBits
);
591 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
594 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
597 void wxDisplaySizeMM(int *width
, int *height
)
599 wxDisplaySize(width
, height
);
600 // on mac 72 is fixed (at least now;-)
601 float cvPt2Mm
= 25.4 / 72;
604 *width
= int( *width
* cvPt2Mm
);
607 *height
= int( *height
* cvPt2Mm
);
610 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
614 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
620 *width
= r
.right
- r
.left
;
622 *height
= r
.bottom
- r
.top
;
625 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
627 return wxGenericFindWindowAtPoint(pt
);
634 wxString
wxGetOsDescription()
636 #ifdef WXWIN_OS_DESCRIPTION
637 // use configure generated description if available
638 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
640 return wxT("MacOS"); //TODO:define further
645 wxChar
*wxGetUserHome (const wxString
& user
)
651 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
660 int pos
= p
.Find(':');
661 if ( pos
!= wxNOT_FOUND
)
669 err
= wxMacPathToFSRef( p
, &fsRef
);
672 FSVolumeRefNum vRefNum
;
673 err
= FSGetVRefNum( &fsRef
, &vRefNum
);
676 UInt64 freeBytes
, totalBytes
;
677 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
);
681 *pTotal
= wxDiskspaceSize_t( totalBytes
);
683 *pFree
= wxDiskspaceSize_t( freeBytes
);
690 #endif // !__DARWIN__
692 //---------------------------------------------------------------------------
693 // wxMac Specific utility functions
694 //---------------------------------------------------------------------------
696 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
698 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
699 int len
= strlen(buf
);
704 memcpy( (char*) &to
[1] , buf
, len
);
707 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
709 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
712 // ----------------------------------------------------------------------------
713 // Common Event Support
714 // ----------------------------------------------------------------------------
716 extern ProcessSerialNumber gAppProcess
;
720 ProcessSerialNumber psn
;
722 psn
.highLongOfPSN
= 0;
723 psn
.lowLongOfPSN
= kCurrentProcess
;
724 SameProcess( &gAppProcess
, &psn
, &isSame
);
728 OSStatus err
= noErr
;
731 // lead sometimes to race conditions, although all calls used should be thread safe ...
732 static wxMacCarbonEvent s_wakeupEvent
;
733 if ( !s_wakeupEvent
.IsValid() )
735 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
736 kEventAttributeNone
);
741 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
743 s_wakeupEvent
.SetCurrentTime();
744 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
745 kEventPriorityHigh
);
748 wxMacCarbonEvent wakeupEvent
;
749 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
750 kEventAttributeNone
);
751 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
752 kEventPriorityHigh
);
755 PostEvent( nullEvent
, 0 );
760 WakeUpProcess( &gAppProcess
);
768 // ----------------------------------------------------------------------------
769 // Native Struct Conversions
770 // ----------------------------------------------------------------------------
772 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
776 n
->right
= wx
->x
+ wx
->width
;
777 n
->bottom
= wx
->y
+ wx
->height
;
780 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
784 wx
->width
= n
->right
- n
->left
;
785 wx
->height
= n
->bottom
- n
->top
;
788 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
794 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
800 // ----------------------------------------------------------------------------
801 // Carbon Event Support
802 // ----------------------------------------------------------------------------
804 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
806 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
809 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
811 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
814 // ----------------------------------------------------------------------------
815 // Control Access Support
816 // ----------------------------------------------------------------------------
818 wxMacControl::wxMacControl(wxWindow
* peer
, bool isRootControl
)
822 m_isRootControl
= isRootControl
;
823 m_isCompositing
= peer
->MacGetTopLevelWindow()->MacUsesCompositing();
826 wxMacControl::wxMacControl( wxWindow
* peer
, ControlRef control
)
830 m_isCompositing
= peer
->MacGetTopLevelWindow()->MacUsesCompositing();
831 m_controlRef
= control
;
834 wxMacControl::wxMacControl( wxWindow
* peer
, WXWidget control
)
838 m_isCompositing
= peer
->MacGetTopLevelWindow()->MacUsesCompositing();
839 m_controlRef
= (ControlRef
) control
;
842 wxMacControl::~wxMacControl()
846 void wxMacControl::Init()
850 m_needsFocusRect
= false;
851 m_isCompositing
= false;
852 m_isRootControl
= false;
855 void wxMacControl::Dispose()
857 ::DisposeControl( m_controlRef
);
861 void wxMacControl::SetReference( SInt32 data
)
863 SetControlReference( m_controlRef
, data
);
866 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
868 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
);
871 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
873 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
);
876 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
878 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
);
881 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
883 #if TARGET_API_MAC_OSX
884 return SendEventToEventTargetWithOptions( event
,
885 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
887 #pragma unused(inOptions)
888 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) );
892 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
894 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
896 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
);
898 return SendEvent( event
, inOptions
);
901 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
905 memset( &command
, 0 , sizeof(command
) );
906 command
.commandID
= commandID
;
907 return SendHICommand( command
, inOptions
);
910 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
912 unsigned long finalTicks
;
914 HiliteControl( m_controlRef
, part
);
915 Delay( ticks
, &finalTicks
);
916 HiliteControl( m_controlRef
, kControlNoPart
);
919 SInt32
wxMacControl::GetValue() const
921 return ::GetControl32BitValue( m_controlRef
);
924 SInt32
wxMacControl::GetMaximum() const
926 return ::GetControl32BitMaximum( m_controlRef
);
929 SInt32
wxMacControl::GetMinimum() const
931 return ::GetControl32BitMinimum( m_controlRef
);
934 void wxMacControl::SetValue( SInt32 v
)
936 ::SetControl32BitValue( m_controlRef
, v
);
939 void wxMacControl::SetMinimum( SInt32 v
)
941 ::SetControl32BitMinimum( m_controlRef
, v
);
944 void wxMacControl::SetMaximum( SInt32 v
)
946 ::SetControl32BitMaximum( m_controlRef
, v
);
949 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
951 ::SetControl32BitMinimum( m_controlRef
, minimum
);
952 ::SetControl32BitMaximum( m_controlRef
, maximum
);
953 ::SetControl32BitValue( m_controlRef
, value
);
956 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
958 return SetKeyboardFocus( GetControlOwner( m_controlRef
), m_controlRef
, focusPart
);
961 bool wxMacControl::HasFocus() const
964 GetKeyboardFocus( GetUserFocusWindow() , &control
);
965 return control
== m_controlRef
;
968 void wxMacControl::SetNeedsFocusRect( bool needs
)
970 m_needsFocusRect
= needs
;
973 bool wxMacControl::NeedsFocusRect() const
975 return m_needsFocusRect
;
978 void wxMacControl::VisibilityChanged(bool shown
)
982 void wxMacControl::SuperChangedPosition()
986 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
989 ControlFontStyleRec fontStyle
;
990 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
992 switch ( font
.MacGetThemeFontID() )
994 case kThemeSmallSystemFont
:
995 fontStyle
.font
= kControlFontSmallSystemFont
;
998 case 109 : // mini font
1002 case kThemeSystemFont
:
1003 fontStyle
.font
= kControlFontBigSystemFont
;
1007 fontStyle
.font
= kControlFontBigSystemFont
;
1011 fontStyle
.flags
= kControlUseFontMask
;
1015 fontStyle
.font
= font
.MacGetFontNum();
1016 fontStyle
.style
= font
.MacGetFontStyle();
1017 fontStyle
.size
= font
.MacGetFontSize();
1018 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
1021 fontStyle
.just
= teJustLeft
;
1022 fontStyle
.flags
|= kControlUseJustMask
;
1023 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
1024 fontStyle
.just
= teJustCenter
;
1025 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
1026 fontStyle
.just
= teJustRight
;
1029 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
1030 // won't get grayed out by the system anymore
1032 if ( foreground
!= *wxBLACK
)
1034 fontStyle
.foreColor
= MAC_WXCOLORREF( foreground
.GetPixel() );
1035 fontStyle
.flags
|= kControlUseForeColorMask
;
1038 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
1041 void wxMacControl::SetBackground( const wxBrush
&WXUNUSED(brush
) )
1044 // setting up a color proc is not recommended anymore
1047 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
1049 ::SetControl32BitMinimum( m_controlRef
, minimum
);
1050 ::SetControl32BitMaximum( m_controlRef
, maximum
);
1053 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
1055 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
);
1058 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
1060 SetControlAction( m_controlRef
, actionProc
);
1063 void wxMacControl::SetViewSize( SInt32 viewSize
)
1065 SetControlViewSize(m_controlRef
, viewSize
);
1068 SInt32
wxMacControl::GetViewSize() const
1070 return GetControlViewSize( m_controlRef
);
1073 bool wxMacControl::IsVisible() const
1075 return IsControlVisible( m_controlRef
);
1078 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
1080 SetControlVisibility( m_controlRef
, visible
, redraw
);
1083 bool wxMacControl::IsEnabled() const
1085 #if TARGET_API_MAC_OSX
1086 return IsControlEnabled( m_controlRef
);
1088 return IsControlActive( m_controlRef
);
1092 bool wxMacControl::IsActive() const
1094 return IsControlActive( m_controlRef
);
1097 void wxMacControl::Enable( bool enable
)
1099 #if TARGET_API_MAC_OSX
1101 EnableControl( m_controlRef
);
1103 DisableControl( m_controlRef
);
1106 ActivateControl( m_controlRef
);
1108 DeactivateControl( m_controlRef
);
1112 void wxMacControl::SetDrawingEnabled( bool enable
)
1114 #if TARGET_API_MAC_OSX
1115 HIViewSetDrawingEnabled( m_controlRef
, enable
);
1119 #if TARGET_API_MAC_OSX
1120 bool wxMacControl::GetNeedsDisplay() const
1122 #if TARGET_API_MAC_OSX
1123 if ( m_isCompositing
)
1125 return HIViewGetNeedsDisplay( m_controlRef
);
1134 GetControlBounds( m_controlRef
, &controlBounds
);
1135 RgnHandle rgn
= NewRgn();
1136 GetWindowRegion ( GetControlOwner( m_controlRef
) , kWindowUpdateRgn
, rgn
);
1137 Boolean intersect
= RectInRgn ( &controlBounds
, rgn
);
1145 void wxMacControl::SetNeedsDisplay( RgnHandle where
)
1150 #if TARGET_API_MAC_OSX
1151 if ( m_isCompositing
)
1153 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, true );
1159 GetControlBounds( m_controlRef
, &controlBounds
);
1160 RgnHandle update
= NewRgn();
1161 CopyRgn( where
, update
);
1162 OffsetRgn( update
, controlBounds
.left
, controlBounds
.top
);
1163 InvalWindowRgn( GetControlOwner( m_controlRef
) , update
);
1167 void wxMacControl::SetNeedsDisplay( Rect
* where
)
1172 #if TARGET_API_MAC_OSX
1173 if ( m_isCompositing
)
1175 if ( where
!= NULL
)
1177 RgnHandle update
= NewRgn();
1178 RectRgn( update
, where
);
1179 HIViewSetNeedsDisplayInRegion( m_controlRef
, update
, true );
1180 DisposeRgn( update
);
1183 HIViewSetNeedsDisplay( m_controlRef
, true );
1190 GetControlBounds( m_controlRef
, &controlBounds
);
1193 Rect whereLocal
= *where
;
1194 OffsetRect( &whereLocal
, controlBounds
.left
, controlBounds
.top
);
1195 SectRect( &controlBounds
, &whereLocal
, &controlBounds
);
1198 InvalWindowRect( GetControlOwner( m_controlRef
) , &controlBounds
);
1202 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
1204 #if TARGET_API_MAC_OSX
1205 if ( from
->m_peer
->MacGetTopLevelWindow()->MacUsesCompositing() )
1211 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
);
1212 pt
->x
= (int)hiPoint
.x
;
1213 pt
->y
= (int)hiPoint
.y
;
1218 Rect fromRect
, toRect
;
1220 GetControlBounds( from
->m_controlRef
, &fromRect
);
1221 GetControlBounds( to
->m_controlRef
, &toRect
);
1222 if ( from
->m_isRootControl
)
1223 fromRect
.left
= fromRect
.top
= 0;
1224 if ( to
->m_isRootControl
)
1225 toRect
.left
= toRect
.top
= 0;
1227 pt
->x
= pt
->x
+ fromRect
.left
- toRect
.left
;
1228 pt
->y
= pt
->y
+ fromRect
.top
- toRect
.top
;
1232 void wxMacControl::SetRect( Rect
*r
)
1234 #if TARGET_API_MAC_OSX
1235 if ( m_isCompositing
)
1237 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1238 //CGPoint and CGSize, which have two floats each
1239 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} };
1240 HIViewSetFrame ( m_controlRef
, &hir
);
1241 // eventuall we might have to do a SetVisibility( false , true );
1242 // before and a SetVisibility( true , true ); after
1247 bool vis
= IsVisible();
1251 GetControlBounds( m_controlRef
, &former
);
1252 InvalWindowRect( GetControlOwner( m_controlRef
) , &former
);
1255 Rect controlBounds
= *r
;
1257 // since the rect passed in is always (even in non-compositing) relative
1258 // to the (native) parent, we have to adjust to window relative here
1259 wxMacControl
* parent
= m_peer
->GetParent()->GetPeer();
1260 if ( !parent
->m_isRootControl
)
1263 GetControlBounds( parent
->m_controlRef
, &superRect
);
1264 OffsetRect( &controlBounds
, superRect
.left
, superRect
.top
);
1267 SetControlBounds( m_controlRef
, &controlBounds
);
1269 InvalWindowRect( GetControlOwner( m_controlRef
) , &controlBounds
);
1273 void wxMacControl::GetRect( Rect
*r
)
1275 GetControlBounds( m_controlRef
, r
);
1276 if ( !m_isCompositing
)
1278 // correct the case of the root control
1279 if ( m_isRootControl
)
1281 WindowRef wr
= GetControlOwner( m_controlRef
);
1282 GetWindowBounds( wr
, kWindowContentRgn
, r
);
1283 r
->right
-= r
->left
;
1284 r
->bottom
-= r
->top
;
1290 wxMacControl
* parent
= m_peer
->GetParent()->GetPeer();
1291 if ( !parent
->m_isRootControl
)
1294 GetControlBounds( parent
->m_controlRef
, &superRect
);
1295 OffsetRect( r
, -superRect
.left
, -superRect
.top
);
1301 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
1303 UMAGetControlBoundsInWindowCoords( m_controlRef
, r
);
1306 void wxMacControl::GetBestRect( Rect
*r
)
1308 short baselineoffset
;
1310 GetBestControlRect( m_controlRef
, r
, &baselineoffset
);
1313 void wxMacControl::SetLabel( const wxString
&title
)
1315 wxFontEncoding encoding
;
1318 encoding
= m_font
.GetEncoding();
1320 encoding
= wxFont::GetDefaultEncoding();
1322 UMASetControlTitle( m_controlRef
, title
, encoding
);
1325 void wxMacControl::GetFeatures( UInt32
* features
)
1327 GetControlFeatures( m_controlRef
, features
);
1330 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
1332 OSStatus err
= GetControlRegion( m_controlRef
, partCode
, region
);
1333 if ( !m_isCompositing
)
1335 if ( !m_isRootControl
)
1339 GetControlBounds(m_controlRef
, &r
);
1340 if ( !EmptyRgn( region
) )
1341 OffsetRgn( region
, -r
.left
, -r
.top
);
1348 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
1350 #if TARGET_API_MAC_OSX
1351 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
1352 (other
!= NULL
) ? other
->m_controlRef
: NULL
);
1358 #if TARGET_API_MAC_OSX
1359 // SetNeedsDisplay would not invalidate the children
1360 static void InvalidateControlAndChildren( HIViewRef control
)
1362 HIViewSetNeedsDisplay( control
, true );
1363 UInt16 childrenCount
= 0;
1364 OSStatus err
= CountSubControls( control
, &childrenCount
);
1365 if ( err
== errControlIsNotEmbedder
)
1368 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") );
1370 for ( UInt16 i
= childrenCount
; i
>=1; --i
)
1374 err
= GetIndexedSubControl( control
, i
, & child
);
1375 if ( err
== errControlIsNotEmbedder
)
1378 InvalidateControlAndChildren( child
);
1383 void wxMacControl::InvalidateWithChildren()
1385 #if TARGET_API_MAC_OSX
1386 InvalidateControlAndChildren( m_controlRef
);
1390 void wxMacControl::ScrollRect( wxRect
*r
, int dx
, int dy
)
1392 wxASSERT( r
!= NULL
);
1394 #if TARGET_API_MAC_OSX
1395 if ( m_isCompositing
)
1397 HIRect scrollarea
= CGRectMake( r
->x
, r
->y
, r
->width
, r
->height
);
1398 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
);
1405 GetControlBounds( m_controlRef
, &bounds
);
1406 bounds
.left
+= r
->x
;
1408 bounds
.bottom
= bounds
.top
+ r
->height
;
1409 bounds
.right
= bounds
.left
+ r
->width
;
1410 wxMacWindowClipper
clip( m_peer
);
1411 RgnHandle updateRgn
= NewRgn();
1412 ::ScrollRect( &bounds
, dx
, dy
, updateRgn
);
1413 InvalWindowRgn( GetControlOwner( m_controlRef
) , updateRgn
);
1414 DisposeRgn( updateRgn
);
1418 OSType wxMacCreator
= 'WXMC';
1419 OSType wxMacControlProperty
= 'MCCT';
1421 void wxMacControl::SetReferenceInNativeControl()
1424 verify_noerr( SetControlProperty ( m_controlRef
,
1425 wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data
) );
1428 wxMacControl
* wxMacControl::GetReferenceFromNativeControl(ControlRef control
)
1430 wxMacControl
* ctl
= NULL
;
1432 if ( GetControlProperty( control
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) ,
1433 &actualSize
, &ctl
) == noErr
)
1440 // ============================================================================
1441 // DataBrowser Wrapper
1442 // ============================================================================
1444 // basing on DataBrowserItemIDs
1447 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
1449 DataBrowserItemID itemID
,
1450 DataBrowserItemNotification message
,
1451 DataBrowserItemDataRef itemData
)
1453 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1456 ctl
->ItemNotification(itemID
, message
, itemData
);
1460 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
1462 DataBrowserItemID itemID
,
1463 DataBrowserPropertyID property
,
1464 DataBrowserItemDataRef itemData
,
1465 Boolean changeValue
)
1467 OSStatus err
= errDataBrowserPropertyNotSupported
;
1469 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1472 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
1477 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
1479 DataBrowserItemID itemOneID
,
1480 DataBrowserItemID itemTwoID
,
1481 DataBrowserPropertyID sortProperty
)
1483 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1486 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
1491 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
1492 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
1493 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
1495 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) : wxMacControl( peer
)
1497 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
1498 OSStatus err
= ::CreateDataBrowserControl(
1499 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
1500 &bounds
, kDataBrowserListView
, &m_controlRef
);
1501 SetReferenceInNativeControl();
1502 verify_noerr( err
);
1503 if ( gDataBrowserItemCompareUPP
== NULL
)
1504 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
1505 if ( gDataBrowserItemDataUPP
== NULL
)
1506 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
1507 if ( gDataBrowserItemNotificationUPP
== NULL
)
1509 gDataBrowserItemNotificationUPP
=
1510 #if TARGET_API_MAC_OSX
1511 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
1513 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc
);
1517 DataBrowserCallbacks callbacks
;
1518 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
1520 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
1521 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
1522 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
1523 SetCallbacks( &callbacks
);
1527 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
1529 DataBrowserItemState state
,
1530 UInt32
*numItems
) const
1532 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
1535 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
1537 DataBrowserItemState state
,
1540 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
1543 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1545 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
1548 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1549 DataBrowserTableViewColumnIndex position
)
1551 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
1554 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
1556 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
1559 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
1561 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
1564 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1566 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
1569 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
1571 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1574 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
1576 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1579 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
1581 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
1584 OSStatus
wxMacDataBrowserControl::UpdateItems(
1585 DataBrowserItemID container
,
1587 const DataBrowserItemID
*items
,
1588 DataBrowserPropertyID preSortProperty
,
1589 DataBrowserPropertyID propertyID
) const
1591 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
1594 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
1596 return IsDataBrowserItemSelected( m_controlRef
, item
);
1599 OSStatus
wxMacDataBrowserControl::AddItems(
1600 DataBrowserItemID container
,
1602 const DataBrowserItemID
*items
,
1603 DataBrowserPropertyID preSortProperty
)
1605 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1608 OSStatus
wxMacDataBrowserControl::RemoveItems(
1609 DataBrowserItemID container
,
1611 const DataBrowserItemID
*items
,
1612 DataBrowserPropertyID preSortProperty
)
1614 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1617 OSStatus
wxMacDataBrowserControl::RevealItem(
1618 DataBrowserItemID item
,
1619 DataBrowserPropertyID propertyID
,
1620 DataBrowserRevealOptions options
) const
1622 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
1625 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
1627 const DataBrowserItemID
*items
,
1628 DataBrowserSetOption operation
)
1630 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
1633 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
1635 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
1638 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
1640 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
1643 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
1645 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
1648 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
1650 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1653 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
1655 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1658 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
1660 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1663 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
1665 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1668 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
1670 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1673 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
1675 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1678 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
1680 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1683 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
1685 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1688 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
1690 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
1693 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
1694 UInt32
*position
) const
1696 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1699 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, UInt32 position
)
1701 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1704 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
1706 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1709 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
1711 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1714 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
1716 return GetDataBrowserSortProperty( m_controlRef
, column
);
1719 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
1721 return SetDataBrowserSortProperty( m_controlRef
, column
);
1724 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
1726 return GetDataBrowserSortOrder( m_controlRef
, order
);
1729 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
1731 return SetDataBrowserSortOrder( m_controlRef
, order
);
1734 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
1735 DataBrowserPropertyFlags
*flags
) const
1737 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1740 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
1741 DataBrowserPropertyFlags flags
)
1743 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1746 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
1747 DataBrowserListViewHeaderDesc
*desc
) const
1749 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1752 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
1753 DataBrowserListViewHeaderDesc
*desc
)
1755 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1758 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
1759 Boolean expandableRows
)
1761 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
1764 // ============================================================================
1765 // Higher-level Databrowser
1766 // ============================================================================
1768 // basing on data item objects
1771 wxMacDataItem::wxMacDataItem()
1775 wxMacDataItem::~wxMacDataItem()
1779 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*owner
,
1780 const wxMacDataItem
*,
1781 DataBrowserPropertyID property
) const
1786 OSStatus
wxMacDataItem::GetSetData(wxMacDataItemBrowserControl
*owner
,
1787 DataBrowserPropertyID property
,
1788 DataBrowserItemDataRef itemData
,
1791 return errDataBrowserPropertyNotSupported
;
1794 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*owner
,
1795 DataBrowserItemNotification message
,
1796 DataBrowserItemDataRef itemData
) const
1801 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1802 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1804 m_suppressSelection
= false;
1807 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1809 m_former
= browser
->SuppressSelection(true);
1810 m_browser
= browser
;
1813 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1815 m_browser
->SuppressSelection(m_former
);
1818 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
1820 bool former
= m_suppressSelection
;
1821 m_suppressSelection
= suppress
;
1826 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
1827 DataBrowserItemID itemTwoID
,
1828 DataBrowserPropertyID sortProperty
)
1830 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1831 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1832 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1835 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
1836 const wxMacDataItem
* itemTwo
,
1837 DataBrowserPropertyID sortProperty
)
1839 Boolean retval
= false;
1840 if ( itemOne
!= NULL
)
1841 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1845 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1846 DataBrowserItemID itemID
,
1847 DataBrowserPropertyID property
,
1848 DataBrowserItemDataRef itemData
,
1849 Boolean changeValue
)
1851 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1852 return GetSetItemData(item
, property
, itemData
, changeValue
);
1855 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1856 wxMacDataItem
* item
,
1857 DataBrowserPropertyID property
,
1858 DataBrowserItemDataRef itemData
,
1859 Boolean changeValue
)
1861 OSStatus err
= errDataBrowserPropertyNotSupported
;
1864 case kDataBrowserContainerIsClosableProperty
:
1865 case kDataBrowserContainerIsSortableProperty
:
1866 case kDataBrowserContainerIsOpenableProperty
:
1867 // right now default behaviour on these
1871 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1878 void wxMacDataItemBrowserControl::ItemNotification(
1879 DataBrowserItemID itemID
,
1880 DataBrowserItemNotification message
,
1881 DataBrowserItemDataRef itemData
)
1883 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1884 ItemNotification( item
, message
, itemData
);
1887 void wxMacDataItemBrowserControl::ItemNotification(
1888 const wxMacDataItem
* item
,
1889 DataBrowserItemNotification message
,
1890 DataBrowserItemDataRef itemData
)
1893 item
->Notification( this, message
, itemData
);
1896 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
1897 bool recurse
, DataBrowserItemState state
) const
1899 UInt32 numItems
= 0;
1900 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
1901 recurse
, state
, &numItems
) );
1905 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
1906 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1908 Handle handle
= NewHandle(0);
1909 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
1910 recurse
, state
, handle
) );
1912 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1914 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1915 for ( int i
= 0; i
< itemCount
; ++i
)
1917 items
.Add(itemsArray
[i
]);
1920 DisposeHandle( handle
);
1923 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
1925 DataBrowserTableViewRowIndex row
;
1926 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1927 wxASSERT( err
== noErr
);
1931 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
1933 DataBrowserItemID id
;
1934 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1935 wxASSERT( err
== noErr
);
1936 return (wxMacDataItem
*) id
;
1939 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
1940 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1942 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
1943 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1946 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
1947 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1949 unsigned int noItems
= itemArray
.GetCount();
1950 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1951 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1952 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1954 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
1955 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1959 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1961 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
1962 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1965 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1967 unsigned int noItems
= itemArray
.GetCount();
1968 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1969 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1970 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1972 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
1973 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1977 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1979 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
1980 (UInt32
*) &item
, kDataBrowserItemNoProperty
);
1981 verify_noerr( err
);
1984 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1986 unsigned int noItems
= itemArray
.GetCount();
1987 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1988 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1989 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1991 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
1992 (UInt32
*) items
, kDataBrowserItemNoProperty
);
1993 verify_noerr( err
);
1997 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
1999 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
2000 verify_noerr( err
);
2003 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
2005 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
2008 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
2010 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
2013 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
2015 unsigned int noItems
= itemArray
.GetCount();
2016 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
2017 for ( unsigned int i
= 0; i
< noItems
; ++i
)
2018 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
2020 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
2024 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
2026 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
2029 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
2031 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
2034 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
2036 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
2045 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
2047 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
2054 #ifdef __WXMAC_OSX__
2055 // snippets from Sketch Sample from Apple :
2057 #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
2060 This function locates, opens, and returns the profile reference for the calibrated
2061 Generic RGB color space. It is up to the caller to call CMCloseProfile when done
2062 with the profile reference this function returns.
2064 CMProfileRef
wxMacOpenGenericProfile()
2066 static CMProfileRef cachedRGBProfileRef
= NULL
;
2068 // we only create the profile reference once
2069 if (cachedRGBProfileRef
== NULL
)
2071 CMProfileLocation loc
;
2073 loc
.locType
= cmPathBasedProfile
;
2074 strcpy(loc
.u
.pathLoc
.path
, kGenericRGBProfilePathStr
);
2076 verify_noerr( CMOpenProfile(&cachedRGBProfileRef
, &loc
) );
2079 // clone the profile reference so that the caller has their own reference, not our cached one
2080 if (cachedRGBProfileRef
)
2081 CMCloneProfileRef(cachedRGBProfileRef
);
2083 return cachedRGBProfileRef
;
2087 Return the generic RGB color space. This is a 'get' function and the caller should
2088 not release the returned value unless the caller retains it first. Usually callers
2089 of this routine will immediately use the returned colorspace with CoreGraphics
2090 so they typically do not need to retain it themselves.
2092 This function creates the generic RGB color space once and hangs onto it so it can
2093 return it whenever this function is called.
2096 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
2098 static wxMacCFRefHolder
<CGColorSpaceRef
> genericRGBColorSpace
;
2100 if (genericRGBColorSpace
== NULL
)
2102 if ( UMAGetSystemVersion() >= 0x1040 )
2104 genericRGBColorSpace
.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) );
2108 CMProfileRef genericRGBProfile
= wxMacOpenGenericProfile();
2110 if (genericRGBProfile
)
2112 genericRGBColorSpace
.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile
) );
2114 wxASSERT_MSG( genericRGBColorSpace
!= NULL
, wxT("couldn't create the generic RGB color space") );
2116 // we opened the profile so it is up to us to close it
2117 CMCloseProfile(genericRGBProfile
);
2122 return genericRGBColorSpace
;
2126 wxMacPortSaver::wxMacPortSaver( GrafPtr port
)
2128 ::GetPort( &m_port
);
2132 wxMacPortSaver::~wxMacPortSaver()
2134 ::SetPort( m_port
);