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"
21 #include "wx/apptrait.h"
24 #include "wx/mac/uma.h"
26 #include "wx/toplevel.h"
36 #include "MoreFilesX.h"
44 #if TARGET_API_MAC_OSX
45 #include <CoreServices/CoreServices.h>
47 #include <DriverServices.h>
48 #include <Multiprocessing.h>
52 #include <Carbon/Carbon.h>
54 #include <ATSUnicode.h>
55 #include <TextCommon.h>
56 #include <TextEncodingConverter.h>
60 #include "wx/mac/private.h"
62 #if defined(__MWERKS__) && wxUSE_UNICODE
63 #if __MWERKS__ < 0x4100 || !defined(__DARWIN__)
68 // ---------------------------------------------------------------------------
69 // code used in both base and GUI compilation
70 // ---------------------------------------------------------------------------
72 // our OS version is the same in non GUI and GUI cases
73 static int DoGetOSVersion(int *majorVsn
, int *minorVsn
)
77 // are there x-platform conventions ?
79 Gestalt(gestaltSystemVersion
, &theSystem
);
81 *minorVsn
= (theSystem
& 0xFF);
84 *majorVsn
= (theSystem
>> 8);
96 // ----------------------------------------------------------------------------
98 // ----------------------------------------------------------------------------
100 #if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
102 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
104 #ifndef __MetroNubUtils__
105 #include "MetroNubUtils.h"
112 #if TARGET_API_MAC_CARBON
114 #include <CodeFragments.h>
116 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
118 ProcPtr gCallUniversalProc_Proc
= NULL
;
122 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
124 static long fRunOnce
= false;
127 Boolean
IsMetroNubInstalled()
134 gMetroNubEntry
= NULL
;
136 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
138 // look for MetroNub's Gestalt selector
139 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
141 #if TARGET_API_MAC_CARBON
142 if (gCallUniversalProc_Proc
== NULL
)
144 CFragConnectionID connectionID
;
147 ProcPtr symbolAddress
;
149 CFragSymbolClass symbolClass
;
151 symbolAddress
= NULL
;
152 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
153 &connectionID
, &mainAddress
, errorString
);
157 gCallUniversalProc_Proc
= NULL
;
161 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
162 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
166 gCallUniversalProc_Proc
= NULL
;
173 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
175 // make sure the version of the API is compatible
176 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
177 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
180 gMetroNubEntry
= block
;
189 #if TARGET_API_MAC_CARBON
190 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
192 return (gMetroNubEntry
!= NULL
);
196 Boolean
IsMWDebuggerRunning()
198 if (IsMetroNubInstalled())
199 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
204 Boolean
AmIBeingMWDebugged()
206 if (IsMetroNubInstalled())
207 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
212 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
214 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
219 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
224 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
228 // defined in unix/utilsunx.cpp for Mac OS X
230 // get full hostname (with domain name if possible)
231 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
233 return wxGetHostName(buf
, maxSize
);
236 // Get user ID e.g. jacs
237 bool wxGetUserId(wxChar
*buf
, int maxSize
)
239 return wxGetUserName( buf
, maxSize
);
242 const wxChar
* wxGetHomeDir(wxString
*pstr
)
244 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
);
245 return pstr
->c_str();
248 // Get hostname only (without domain name)
249 bool wxGetHostName(wxChar
*buf
, int maxSize
)
251 // Gets Chooser name of user by examining a System resource.
254 const short kComputerNameID
= -16413;
256 short oldResFile
= CurResFile();
258 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
259 UseResFile(oldResFile
);
261 if (chooserName
&& *chooserName
)
263 HLock( (Handle
) chooserName
);
264 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
265 HUnlock( (Handle
) chooserName
);
266 ReleaseResource( (Handle
) chooserName
);
267 wxStrncpy( buf
, name
, maxSize
- 1 );
273 // Get user name e.g. Stefan Csomor
274 bool wxGetUserName(wxChar
*buf
, int maxSize
)
276 // Gets Chooser name of user by examining a System resource.
279 const short kChooserNameID
= -16096;
281 short oldResFile
= CurResFile();
283 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
284 UseResFile(oldResFile
);
286 if (chooserName
&& *chooserName
)
288 HLock( (Handle
) chooserName
);
289 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
290 HUnlock( (Handle
) chooserName
);
291 ReleaseResource( (Handle
) chooserName
);
292 wxStrncpy( buf
, name
, maxSize
- 1 );
298 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
, int flags
)
304 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
306 // TODO : under classic there is no environement support, under X yes
310 // set the env var name to the given value, return true on success
311 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
313 // TODO : under classic there is no environement support, under X yes
317 // Execute a program in an Interactive Shell
318 bool wxShell(const wxString
& command
)
324 // Shutdown or reboot the PC
325 bool wxShutdown(wxShutdownFlags wFlags
)
331 wxPowerType
wxGetPowerType()
334 return wxPOWER_UNKNOWN
;
337 wxBatteryState
wxGetBatteryState()
340 return wxBATTERY_UNKNOWN_STATE
;
343 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
344 wxMemorySize
wxGetFreeMemory()
346 return (wxMemorySize
)FreeMem();
351 void wxMicroSleep(unsigned long microseconds
)
353 AbsoluteTime wakeup
= AddDurationToAbsolute( microseconds
* durationMicrosecond
, UpTime());
354 MPDelayUntil( & wakeup
);
357 void wxMilliSleep(unsigned long milliseconds
)
359 AbsoluteTime wakeup
= AddDurationToAbsolute( milliseconds
, UpTime());
360 MPDelayUntil( & wakeup
);
363 void wxSleep(int nSecs
)
365 wxMilliSleep(1000*nSecs
);
370 // Consume all events until no more left
375 #endif // !__DARWIN__
383 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
385 static wxToolkitInfo info
;
387 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
388 info
.name
= _T("wxBase");
397 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
399 static wxToolkitInfo info
;
401 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
402 info
.shortName
= _T("mac");
403 info
.name
= _T("wxMac");
405 #ifdef __WXUNIVERSAL__
406 info
.shortName
<< _T("univ");
407 info
.name
<< _T("/wxUniversal");
413 // Reading and writing resources (eg WIN.INI, .Xdefaults)
415 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
421 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
424 buf
.Printf(wxT("%.4f"), value
);
426 return wxWriteResource(section
, entry
, buf
, file
);
429 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
432 buf
.Printf(wxT("%ld"), value
);
434 return wxWriteResource(section
, entry
, buf
, file
);
437 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
440 buf
.Printf(wxT("%d"), value
);
442 return wxWriteResource(section
, entry
, buf
, file
);
445 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
451 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
454 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
457 *value
= (float)strtod(s
, NULL
);
464 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
467 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
470 *value
= strtol(s
, NULL
, 10);
477 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
480 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
483 *value
= (int)strtol(s
, NULL
, 10);
489 #endif // wxUSE_RESOURCES
491 int gs_wxBusyCursorCount
= 0;
492 extern wxCursor gMacCurrentCursor
;
493 wxCursor gMacStoredActiveCursor
;
495 // Set the cursor to the busy cursor for all windows
496 void wxBeginBusyCursor(const wxCursor
*cursor
)
498 if (gs_wxBusyCursorCount
++ == 0)
500 gMacStoredActiveCursor
= gMacCurrentCursor
;
501 cursor
->MacInstall();
503 //else: nothing to do, already set
506 // Restore cursor to normal
507 void wxEndBusyCursor()
509 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
510 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
512 if (--gs_wxBusyCursorCount
== 0)
514 gMacStoredActiveCursor
.MacInstall();
515 gMacStoredActiveCursor
= wxNullCursor
;
519 // true if we're between the above two calls
522 return (gs_wxBusyCursorCount
> 0);
529 wxString
wxMacFindFolderNoSeparator( short vol
,
531 Boolean createFolder
)
536 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
538 strDir
= wxMacFSRefToPath( &fsRef
);
544 wxString
wxMacFindFolder( short vol
,
546 Boolean createFolder
)
548 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
555 // Check whether this window wants to process messages, e.g. Stop button
556 // in long calculations.
557 bool wxCheckForInterrupt(wxWindow
*wnd
)
563 void wxGetMousePosition( int* x
, int* y
)
568 LocalToGlobal( &pt
);
573 // Return true if we have a colour display
574 bool wxColourDisplay()
579 // Returns depth of screen
583 SetRect(&globRect
, -32760, -32760, 32760, 32760);
584 GDHandle theMaxDevice
;
587 theMaxDevice
= GetMaxDevice(&globRect
);
588 if (theMaxDevice
!= NULL
)
589 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
594 // Get size of display
595 void wxDisplaySize(int *width
, int *height
)
598 GetQDGlobalsScreenBits( &screenBits
);
601 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
604 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
607 void wxDisplaySizeMM(int *width
, int *height
)
609 wxDisplaySize(width
, height
);
610 // on mac 72 is fixed (at least now;-)
611 float cvPt2Mm
= 25.4 / 72;
614 *width
= int( *width
* cvPt2Mm
);
617 *height
= int( *height
* cvPt2Mm
);
620 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
624 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
630 *width
= r
.right
- r
.left
;
632 *height
= r
.bottom
- r
.top
;
635 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
637 return wxGenericFindWindowAtPoint(pt
);
644 wxString
wxGetOsDescription()
646 #ifdef WXWIN_OS_DESCRIPTION
647 // use configure generated description if available
648 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
650 return wxT("MacOS"); //TODO:define further
655 wxChar
*wxGetUserHome (const wxString
& user
)
661 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
670 int pos
= p
.Find(':');
671 if ( pos
!= wxNOT_FOUND
)
679 err
= wxMacPathToFSRef( p
, &fsRef
);
682 FSVolumeRefNum vRefNum
;
683 err
= FSGetVRefNum( &fsRef
, &vRefNum
);
686 UInt64 freeBytes
, totalBytes
;
687 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
);
691 *pTotal
= wxDiskspaceSize_t( totalBytes
);
693 *pFree
= wxDiskspaceSize_t( freeBytes
);
700 #endif // !__DARWIN__
702 //---------------------------------------------------------------------------
703 // wxMac Specific utility functions
704 //---------------------------------------------------------------------------
706 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
708 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
709 int len
= strlen(buf
);
714 memcpy( (char*) &to
[1] , buf
, len
);
717 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
719 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
722 // ----------------------------------------------------------------------------
723 // Common Event Support
724 // ----------------------------------------------------------------------------
726 extern ProcessSerialNumber gAppProcess
;
730 ProcessSerialNumber psn
;
732 psn
.highLongOfPSN
= 0;
733 psn
.lowLongOfPSN
= kCurrentProcess
;
734 SameProcess( &gAppProcess
, &psn
, &isSame
);
738 OSStatus err
= noErr
;
741 // lead sometimes to race conditions, although all calls used should be thread safe ...
742 static wxMacCarbonEvent s_wakeupEvent
;
743 if ( !s_wakeupEvent
.IsValid() )
745 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
746 kEventAttributeNone
);
751 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
753 s_wakeupEvent
.SetCurrentTime();
754 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
755 kEventPriorityHigh
);
758 wxMacCarbonEvent wakeupEvent
;
759 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
760 kEventAttributeNone
);
761 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
762 kEventPriorityHigh
);
765 PostEvent( nullEvent
, 0 );
770 WakeUpProcess( &gAppProcess
);
778 // ----------------------------------------------------------------------------
779 // Native Struct Conversions
780 // ----------------------------------------------------------------------------
782 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
786 n
->right
= wx
->x
+ wx
->width
;
787 n
->bottom
= wx
->y
+ wx
->height
;
790 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
794 wx
->width
= n
->right
- n
->left
;
795 wx
->height
= n
->bottom
- n
->top
;
798 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
804 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
810 // ----------------------------------------------------------------------------
811 // Carbon Event Support
812 // ----------------------------------------------------------------------------
814 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
816 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
819 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
821 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
824 // ----------------------------------------------------------------------------
825 // Control Access Support
826 // ----------------------------------------------------------------------------
828 wxMacControl::wxMacControl(wxWindow
* peer
, bool isRootControl
)
832 m_isRootControl
= isRootControl
;
833 m_isCompositing
= peer
->MacGetTopLevelWindow()->MacUsesCompositing();
836 wxMacControl::wxMacControl( wxWindow
* peer
, ControlRef control
)
840 m_isCompositing
= peer
->MacGetTopLevelWindow()->MacUsesCompositing();
841 m_controlRef
= control
;
844 wxMacControl::wxMacControl( wxWindow
* peer
, WXWidget control
)
848 m_isCompositing
= peer
->MacGetTopLevelWindow()->MacUsesCompositing();
849 m_controlRef
= (ControlRef
) control
;
852 wxMacControl::~wxMacControl()
856 void wxMacControl::Init()
860 m_needsFocusRect
= false;
861 m_isCompositing
= false;
862 m_isRootControl
= false;
865 void wxMacControl::Dispose()
867 ::DisposeControl( m_controlRef
);
871 void wxMacControl::SetReference( SInt32 data
)
873 SetControlReference( m_controlRef
, data
);
876 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
878 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
);
881 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
883 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
);
886 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
888 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
);
891 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
893 #if TARGET_API_MAC_OSX
894 return SendEventToEventTargetWithOptions( event
,
895 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
897 #pragma unused(inOptions)
898 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) );
902 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
904 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
906 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
);
908 return SendEvent( event
, inOptions
);
911 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
915 memset( &command
, 0 , sizeof(command
) );
916 command
.commandID
= commandID
;
917 return SendHICommand( command
, inOptions
);
920 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
922 unsigned long finalTicks
;
924 HiliteControl( m_controlRef
, part
);
925 Delay( ticks
, &finalTicks
);
926 HiliteControl( m_controlRef
, kControlNoPart
);
929 SInt32
wxMacControl::GetValue() const
931 return ::GetControl32BitValue( m_controlRef
);
934 SInt32
wxMacControl::GetMaximum() const
936 return ::GetControl32BitMaximum( m_controlRef
);
939 SInt32
wxMacControl::GetMinimum() const
941 return ::GetControl32BitMinimum( m_controlRef
);
944 void wxMacControl::SetValue( SInt32 v
)
946 ::SetControl32BitValue( m_controlRef
, v
);
949 void wxMacControl::SetMinimum( SInt32 v
)
951 ::SetControl32BitMinimum( m_controlRef
, v
);
954 void wxMacControl::SetMaximum( SInt32 v
)
956 ::SetControl32BitMaximum( m_controlRef
, v
);
959 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
961 ::SetControl32BitMinimum( m_controlRef
, minimum
);
962 ::SetControl32BitMaximum( m_controlRef
, maximum
);
963 ::SetControl32BitValue( m_controlRef
, value
);
966 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
968 return SetKeyboardFocus( GetControlOwner( m_controlRef
), m_controlRef
, focusPart
);
971 bool wxMacControl::HasFocus() const
974 GetKeyboardFocus( GetUserFocusWindow() , &control
);
975 return control
== m_controlRef
;
978 void wxMacControl::SetNeedsFocusRect( bool needs
)
980 m_needsFocusRect
= needs
;
983 bool wxMacControl::NeedsFocusRect() const
985 return m_needsFocusRect
;
988 void wxMacControl::VisibilityChanged(bool shown
)
992 void wxMacControl::SuperChangedPosition()
996 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
999 ControlFontStyleRec fontStyle
;
1000 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
1002 switch ( font
.MacGetThemeFontID() )
1004 case kThemeSmallSystemFont
:
1005 fontStyle
.font
= kControlFontSmallSystemFont
;
1008 case 109 : // mini font
1009 fontStyle
.font
= -5;
1012 case kThemeSystemFont
:
1013 fontStyle
.font
= kControlFontBigSystemFont
;
1017 fontStyle
.font
= kControlFontBigSystemFont
;
1021 fontStyle
.flags
= kControlUseFontMask
;
1025 fontStyle
.font
= font
.MacGetFontNum();
1026 fontStyle
.style
= font
.MacGetFontStyle();
1027 fontStyle
.size
= font
.MacGetFontSize();
1028 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
1031 fontStyle
.just
= teJustLeft
;
1032 fontStyle
.flags
|= kControlUseJustMask
;
1033 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
1034 fontStyle
.just
= teJustCenter
;
1035 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
1036 fontStyle
.just
= teJustRight
;
1039 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
1040 // won't get grayed out by the system anymore
1042 if ( foreground
!= *wxBLACK
)
1044 fontStyle
.foreColor
= MAC_WXCOLORREF( foreground
.GetPixel() );
1045 fontStyle
.flags
|= kControlUseForeColorMask
;
1048 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
1051 void wxMacControl::SetBackground( const wxBrush
&WXUNUSED(brush
) )
1054 // setting up a color proc is not recommended anymore
1057 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
1059 ::SetControl32BitMinimum( m_controlRef
, minimum
);
1060 ::SetControl32BitMaximum( m_controlRef
, maximum
);
1063 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
1065 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
);
1068 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
1070 SetControlAction( m_controlRef
, actionProc
);
1073 void wxMacControl::SetViewSize( SInt32 viewSize
)
1075 SetControlViewSize(m_controlRef
, viewSize
);
1078 SInt32
wxMacControl::GetViewSize() const
1080 return GetControlViewSize( m_controlRef
);
1083 bool wxMacControl::IsVisible() const
1085 return IsControlVisible( m_controlRef
);
1088 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
1090 SetControlVisibility( m_controlRef
, visible
, redraw
);
1093 bool wxMacControl::IsEnabled() const
1095 #if TARGET_API_MAC_OSX
1096 return IsControlEnabled( m_controlRef
);
1098 return IsControlActive( m_controlRef
);
1102 bool wxMacControl::IsActive() const
1104 return IsControlActive( m_controlRef
);
1107 void wxMacControl::Enable( bool enable
)
1109 #if TARGET_API_MAC_OSX
1111 EnableControl( m_controlRef
);
1113 DisableControl( m_controlRef
);
1116 ActivateControl( m_controlRef
);
1118 DeactivateControl( m_controlRef
);
1122 void wxMacControl::SetDrawingEnabled( bool enable
)
1124 #if TARGET_API_MAC_OSX
1125 HIViewSetDrawingEnabled( m_controlRef
, enable
);
1129 #if TARGET_API_MAC_OSX
1130 bool wxMacControl::GetNeedsDisplay() const
1132 #if TARGET_API_MAC_OSX
1133 if ( m_isCompositing
)
1135 return HIViewGetNeedsDisplay( m_controlRef
);
1144 GetControlBounds( m_controlRef
, &controlBounds
);
1145 RgnHandle rgn
= NewRgn();
1146 GetWindowRegion ( GetControlOwner( m_controlRef
) , kWindowUpdateRgn
, rgn
);
1147 Boolean intersect
= RectInRgn ( &controlBounds
, rgn
);
1155 void wxMacControl::SetNeedsDisplay( RgnHandle where
)
1160 #if TARGET_API_MAC_OSX
1161 if ( m_isCompositing
)
1163 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, true );
1169 GetControlBounds( m_controlRef
, &controlBounds
);
1170 RgnHandle update
= NewRgn();
1171 CopyRgn( where
, update
);
1172 OffsetRgn( update
, controlBounds
.left
, controlBounds
.top
);
1173 InvalWindowRgn( GetControlOwner( m_controlRef
) , update
);
1177 void wxMacControl::SetNeedsDisplay( Rect
* where
)
1182 #if TARGET_API_MAC_OSX
1183 if ( m_isCompositing
)
1185 if ( where
!= NULL
)
1187 RgnHandle update
= NewRgn();
1188 RectRgn( update
, where
);
1189 HIViewSetNeedsDisplayInRegion( m_controlRef
, update
, true );
1190 DisposeRgn( update
);
1193 HIViewSetNeedsDisplay( m_controlRef
, true );
1200 GetControlBounds( m_controlRef
, &controlBounds
);
1203 Rect whereLocal
= *where
;
1204 OffsetRect( &whereLocal
, controlBounds
.left
, controlBounds
.top
);
1205 SectRect( &controlBounds
, &whereLocal
, &controlBounds
);
1208 InvalWindowRect( GetControlOwner( m_controlRef
) , &controlBounds
);
1212 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
1214 #if TARGET_API_MAC_OSX
1215 if ( from
->m_peer
->MacGetTopLevelWindow()->MacUsesCompositing() )
1221 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
);
1222 pt
->x
= (int)hiPoint
.x
;
1223 pt
->y
= (int)hiPoint
.y
;
1228 Rect fromRect
, toRect
;
1230 GetControlBounds( from
->m_controlRef
, &fromRect
);
1231 GetControlBounds( to
->m_controlRef
, &toRect
);
1232 if ( from
->m_isRootControl
)
1233 fromRect
.left
= fromRect
.top
= 0;
1234 if ( to
->m_isRootControl
)
1235 toRect
.left
= toRect
.top
= 0;
1237 pt
->x
= pt
->x
+ fromRect
.left
- toRect
.left
;
1238 pt
->y
= pt
->y
+ fromRect
.top
- toRect
.top
;
1242 void wxMacControl::SetRect( Rect
*r
)
1244 #if TARGET_API_MAC_OSX
1245 if ( m_isCompositing
)
1247 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1248 //CGPoint and CGSize, which have two floats each
1249 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} };
1250 HIViewSetFrame ( m_controlRef
, &hir
);
1251 // eventuall we might have to do a SetVisibility( false , true );
1252 // before and a SetVisibility( true , true ); after
1257 bool vis
= IsVisible();
1261 GetControlBounds( m_controlRef
, &former
);
1262 InvalWindowRect( GetControlOwner( m_controlRef
) , &former
);
1265 Rect controlBounds
= *r
;
1267 // since the rect passed in is always (even in non-compositing) relative
1268 // to the (native) parent, we have to adjust to window relative here
1269 wxMacControl
* parent
= m_peer
->GetParent()->GetPeer();
1270 if ( !parent
->m_isRootControl
)
1273 GetControlBounds( parent
->m_controlRef
, &superRect
);
1274 OffsetRect( &controlBounds
, superRect
.left
, superRect
.top
);
1277 SetControlBounds( m_controlRef
, &controlBounds
);
1279 InvalWindowRect( GetControlOwner( m_controlRef
) , &controlBounds
);
1283 void wxMacControl::GetRect( Rect
*r
)
1285 GetControlBounds( m_controlRef
, r
);
1286 if ( !m_isCompositing
)
1288 // correct the case of the root control
1289 if ( m_isRootControl
)
1291 WindowRef wr
= GetControlOwner( m_controlRef
);
1292 GetWindowBounds( wr
, kWindowContentRgn
, r
);
1293 r
->right
-= r
->left
;
1294 r
->bottom
-= r
->top
;
1300 wxMacControl
* parent
= m_peer
->GetParent()->GetPeer();
1301 if ( !parent
->m_isRootControl
)
1304 GetControlBounds( parent
->m_controlRef
, &superRect
);
1305 OffsetRect( r
, -superRect
.left
, -superRect
.top
);
1311 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
1313 UMAGetControlBoundsInWindowCoords( m_controlRef
, r
);
1316 void wxMacControl::GetBestRect( Rect
*r
)
1318 short baselineoffset
;
1320 GetBestControlRect( m_controlRef
, r
, &baselineoffset
);
1323 void wxMacControl::SetLabel( const wxString
&title
)
1325 wxFontEncoding encoding
;
1328 encoding
= m_font
.GetEncoding();
1330 encoding
= wxFont::GetDefaultEncoding();
1332 UMASetControlTitle( m_controlRef
, title
, encoding
);
1335 void wxMacControl::GetFeatures( UInt32
* features
)
1337 GetControlFeatures( m_controlRef
, features
);
1340 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
1342 OSStatus err
= GetControlRegion( m_controlRef
, partCode
, region
);
1343 if ( !m_isCompositing
)
1345 if ( !m_isRootControl
)
1349 GetControlBounds(m_controlRef
, &r
);
1350 if ( !EmptyRgn( region
) )
1351 OffsetRgn( region
, -r
.left
, -r
.top
);
1358 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
1360 #if TARGET_API_MAC_OSX
1361 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
1362 (other
!= NULL
) ? other
->m_controlRef
: NULL
);
1368 #if TARGET_API_MAC_OSX
1369 // SetNeedsDisplay would not invalidate the children
1370 static void InvalidateControlAndChildren( HIViewRef control
)
1372 HIViewSetNeedsDisplay( control
, true );
1373 UInt16 childrenCount
= 0;
1374 OSStatus err
= CountSubControls( control
, &childrenCount
);
1375 if ( err
== errControlIsNotEmbedder
)
1378 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") );
1380 for ( UInt16 i
= childrenCount
; i
>=1; --i
)
1384 err
= GetIndexedSubControl( control
, i
, & child
);
1385 if ( err
== errControlIsNotEmbedder
)
1388 InvalidateControlAndChildren( child
);
1393 void wxMacControl::InvalidateWithChildren()
1395 #if TARGET_API_MAC_OSX
1396 InvalidateControlAndChildren( m_controlRef
);
1400 void wxMacControl::ScrollRect( wxRect
*r
, int dx
, int dy
)
1402 wxASSERT( r
!= NULL
);
1404 #if TARGET_API_MAC_OSX
1405 if ( m_isCompositing
)
1407 HIRect scrollarea
= CGRectMake( r
->x
, r
->y
, r
->width
, r
->height
);
1408 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
);
1415 GetControlBounds( m_controlRef
, &bounds
);
1416 bounds
.left
+= r
->x
;
1418 bounds
.bottom
= bounds
.top
+ r
->height
;
1419 bounds
.right
= bounds
.left
+ r
->width
;
1420 wxMacWindowClipper
clip( m_peer
);
1421 RgnHandle updateRgn
= NewRgn();
1422 ::ScrollRect( &bounds
, dx
, dy
, updateRgn
);
1423 InvalWindowRgn( GetControlOwner( m_controlRef
) , updateRgn
);
1424 DisposeRgn( updateRgn
);
1428 OSType wxMacCreator
= 'WXMC';
1429 OSType wxMacControlProperty
= 'MCCT';
1431 void wxMacControl::SetReferenceInNativeControl()
1434 verify_noerr( SetControlProperty ( m_controlRef
,
1435 wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data
) );
1438 wxMacControl
* wxMacControl::GetReferenceFromNativeControl(ControlRef control
)
1440 wxMacControl
* ctl
= NULL
;
1442 if ( GetControlProperty( control
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) ,
1443 &actualSize
, &ctl
) == noErr
)
1450 // ============================================================================
1451 // DataBrowser Wrapper
1452 // ============================================================================
1454 // basing on DataBrowserItemIDs
1457 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
1459 DataBrowserItemID itemID
,
1460 DataBrowserItemNotification message
,
1461 DataBrowserItemDataRef itemData
)
1463 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1466 ctl
->ItemNotification(itemID
, message
, itemData
);
1470 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
1472 DataBrowserItemID itemID
,
1473 DataBrowserPropertyID property
,
1474 DataBrowserItemDataRef itemData
,
1475 Boolean changeValue
)
1477 OSStatus err
= errDataBrowserPropertyNotSupported
;
1479 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1482 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
1487 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
1489 DataBrowserItemID itemOneID
,
1490 DataBrowserItemID itemTwoID
,
1491 DataBrowserPropertyID sortProperty
)
1493 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1496 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
1501 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
1502 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
1503 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
1505 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) : wxMacControl( peer
)
1507 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
1508 OSStatus err
= ::CreateDataBrowserControl(
1509 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
1510 &bounds
, kDataBrowserListView
, &m_controlRef
);
1511 SetReferenceInNativeControl();
1512 verify_noerr( err
);
1513 if ( gDataBrowserItemCompareUPP
== NULL
)
1514 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
1515 if ( gDataBrowserItemDataUPP
== NULL
)
1516 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
1517 if ( gDataBrowserItemNotificationUPP
== NULL
)
1519 gDataBrowserItemNotificationUPP
=
1520 #if TARGET_API_MAC_OSX
1521 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
1523 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc
);
1527 DataBrowserCallbacks callbacks
;
1528 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
1530 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
1531 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
1532 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
1533 SetCallbacks( &callbacks
);
1537 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
1539 DataBrowserItemState state
,
1540 UInt32
*numItems
) const
1542 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
1545 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
1547 DataBrowserItemState state
,
1550 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
1553 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1555 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
1558 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1559 DataBrowserTableViewColumnIndex position
)
1561 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
1564 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
1566 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
1569 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
1571 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
1574 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1576 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
1579 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
1581 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1584 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
1586 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1589 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
1591 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
1594 OSStatus
wxMacDataBrowserControl::UpdateItems(
1595 DataBrowserItemID container
,
1597 const DataBrowserItemID
*items
,
1598 DataBrowserPropertyID preSortProperty
,
1599 DataBrowserPropertyID propertyID
) const
1601 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
1604 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
1606 return IsDataBrowserItemSelected( m_controlRef
, item
);
1609 OSStatus
wxMacDataBrowserControl::AddItems(
1610 DataBrowserItemID container
,
1612 const DataBrowserItemID
*items
,
1613 DataBrowserPropertyID preSortProperty
)
1615 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1618 OSStatus
wxMacDataBrowserControl::RemoveItems(
1619 DataBrowserItemID container
,
1621 const DataBrowserItemID
*items
,
1622 DataBrowserPropertyID preSortProperty
)
1624 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1627 OSStatus
wxMacDataBrowserControl::RevealItem(
1628 DataBrowserItemID item
,
1629 DataBrowserPropertyID propertyID
,
1630 DataBrowserRevealOptions options
) const
1632 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
1635 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
1637 const DataBrowserItemID
*items
,
1638 DataBrowserSetOption operation
)
1640 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
1643 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
1645 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
1648 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
1650 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
1653 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
1655 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
1658 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
1660 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1663 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
1665 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1668 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
1670 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1673 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
1675 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1678 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
1680 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1683 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
1685 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1688 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
1690 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1693 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
1695 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1698 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
1700 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
1703 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
1704 UInt32
*position
) const
1706 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1709 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, UInt32 position
)
1711 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1714 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
1716 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1719 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
1721 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1724 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
1726 return GetDataBrowserSortProperty( m_controlRef
, column
);
1729 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
1731 return SetDataBrowserSortProperty( m_controlRef
, column
);
1734 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
1736 return GetDataBrowserSortOrder( m_controlRef
, order
);
1739 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
1741 return SetDataBrowserSortOrder( m_controlRef
, order
);
1744 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
1745 DataBrowserPropertyFlags
*flags
) const
1747 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1750 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
1751 DataBrowserPropertyFlags flags
)
1753 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1756 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
1757 DataBrowserListViewHeaderDesc
*desc
) const
1759 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1762 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
1763 DataBrowserListViewHeaderDesc
*desc
)
1765 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1768 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
1769 Boolean expandableRows
)
1771 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
1774 // ============================================================================
1775 // Higher-level Databrowser
1776 // ============================================================================
1778 // basing on data item objects
1781 wxMacDataItem::wxMacDataItem()
1785 wxMacDataItem::~wxMacDataItem()
1789 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*owner
,
1790 const wxMacDataItem
*,
1791 DataBrowserPropertyID property
) const
1796 OSStatus
wxMacDataItem::GetSetData(wxMacDataItemBrowserControl
*owner
,
1797 DataBrowserPropertyID property
,
1798 DataBrowserItemDataRef itemData
,
1801 return errDataBrowserPropertyNotSupported
;
1804 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*owner
,
1805 DataBrowserItemNotification message
,
1806 DataBrowserItemDataRef itemData
) const
1811 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1812 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1814 m_suppressSelection
= false;
1817 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1819 m_former
= browser
->SuppressSelection(true);
1820 m_browser
= browser
;
1823 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1825 m_browser
->SuppressSelection(m_former
);
1828 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
1830 bool former
= m_suppressSelection
;
1831 m_suppressSelection
= suppress
;
1836 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
1837 DataBrowserItemID itemTwoID
,
1838 DataBrowserPropertyID sortProperty
)
1840 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1841 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1842 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1845 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
1846 const wxMacDataItem
* itemTwo
,
1847 DataBrowserPropertyID sortProperty
)
1849 Boolean retval
= false;
1850 if ( itemOne
!= NULL
)
1851 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1855 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1856 DataBrowserItemID itemID
,
1857 DataBrowserPropertyID property
,
1858 DataBrowserItemDataRef itemData
,
1859 Boolean changeValue
)
1861 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1862 return GetSetItemData(item
, property
, itemData
, changeValue
);
1865 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1866 wxMacDataItem
* item
,
1867 DataBrowserPropertyID property
,
1868 DataBrowserItemDataRef itemData
,
1869 Boolean changeValue
)
1871 OSStatus err
= errDataBrowserPropertyNotSupported
;
1874 case kDataBrowserContainerIsClosableProperty
:
1875 case kDataBrowserContainerIsSortableProperty
:
1876 case kDataBrowserContainerIsOpenableProperty
:
1877 // right now default behaviour on these
1881 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1888 void wxMacDataItemBrowserControl::ItemNotification(
1889 DataBrowserItemID itemID
,
1890 DataBrowserItemNotification message
,
1891 DataBrowserItemDataRef itemData
)
1893 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1894 ItemNotification( item
, message
, itemData
);
1897 void wxMacDataItemBrowserControl::ItemNotification(
1898 const wxMacDataItem
* item
,
1899 DataBrowserItemNotification message
,
1900 DataBrowserItemDataRef itemData
)
1903 item
->Notification( this, message
, itemData
);
1906 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
1907 bool recurse
, DataBrowserItemState state
) const
1909 UInt32 numItems
= 0;
1910 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
1911 recurse
, state
, &numItems
) );
1915 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
1916 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1918 Handle handle
= NewHandle(0);
1919 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
1920 recurse
, state
, handle
) );
1922 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1924 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1925 for ( int i
= 0; i
< itemCount
; ++i
)
1927 items
.Add(itemsArray
[i
]);
1930 DisposeHandle( handle
);
1933 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
1935 DataBrowserTableViewRowIndex row
;
1936 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1937 wxASSERT( err
== noErr
);
1941 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
1943 DataBrowserItemID id
;
1944 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1945 wxASSERT( err
== noErr
);
1946 return (wxMacDataItem
*) id
;
1949 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
1950 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1952 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
1953 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1956 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
1957 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1959 unsigned int noItems
= itemArray
.GetCount();
1960 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1961 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1962 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1964 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
1965 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1969 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1971 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
1972 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1975 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1977 unsigned int noItems
= itemArray
.GetCount();
1978 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1979 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1980 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1982 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
1983 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1987 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1989 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
1990 (UInt32
*) &item
, kDataBrowserItemNoProperty
);
1991 verify_noerr( err
);
1994 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1996 unsigned int noItems
= itemArray
.GetCount();
1997 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1998 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1999 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
2001 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
2002 (UInt32
*) items
, kDataBrowserItemNoProperty
);
2003 verify_noerr( err
);
2007 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
2009 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
2010 verify_noerr( err
);
2013 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
2015 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
2018 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
2020 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
2023 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
2025 unsigned int noItems
= itemArray
.GetCount();
2026 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
2027 for ( unsigned int i
= 0; i
< noItems
; ++i
)
2028 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
2030 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
2034 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
2036 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
2039 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
2041 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
2044 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
2046 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
2055 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
2057 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
2064 #ifdef __WXMAC_OSX__
2065 // snippets from Sketch Sample from Apple :
2067 #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
2070 This function locates, opens, and returns the profile reference for the calibrated
2071 Generic RGB color space. It is up to the caller to call CMCloseProfile when done
2072 with the profile reference this function returns.
2074 CMProfileRef
wxMacOpenGenericProfile()
2076 static CMProfileRef cachedRGBProfileRef
= NULL
;
2078 // we only create the profile reference once
2079 if (cachedRGBProfileRef
== NULL
)
2081 CMProfileLocation loc
;
2083 loc
.locType
= cmPathBasedProfile
;
2084 strcpy(loc
.u
.pathLoc
.path
, kGenericRGBProfilePathStr
);
2086 verify_noerr( CMOpenProfile(&cachedRGBProfileRef
, &loc
) );
2089 // clone the profile reference so that the caller has their own reference, not our cached one
2090 if (cachedRGBProfileRef
)
2091 CMCloneProfileRef(cachedRGBProfileRef
);
2093 return cachedRGBProfileRef
;
2097 Return the generic RGB color space. This is a 'get' function and the caller should
2098 not release the returned value unless the caller retains it first. Usually callers
2099 of this routine will immediately use the returned colorspace with CoreGraphics
2100 so they typically do not need to retain it themselves.
2102 This function creates the generic RGB color space once and hangs onto it so it can
2103 return it whenever this function is called.
2106 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
2108 static wxMacCFRefHolder
<CGColorSpaceRef
> genericRGBColorSpace
;
2110 if (genericRGBColorSpace
== NULL
)
2112 if ( UMAGetSystemVersion() >= 0x1040 )
2114 genericRGBColorSpace
.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) );
2118 CMProfileRef genericRGBProfile
= wxMacOpenGenericProfile();
2120 if (genericRGBProfile
)
2122 genericRGBColorSpace
.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile
) );
2124 wxASSERT_MSG( genericRGBColorSpace
!= NULL
, wxT("couldn't create the generic RGB color space") );
2126 // we opened the profile so it is up to us to close it
2127 CMCloseProfile(genericRGBProfile
);
2132 return genericRGBColorSpace
;
2136 wxMacPortSaver::wxMacPortSaver( GrafPtr port
)
2138 ::GetPort( &m_port
);
2142 wxMacPortSaver::~wxMacPortSaver()
2144 ::SetPort( m_port
);