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"
16 #include "wx/apptrait.h"
19 #include "wx/mac/uma.h"
21 #include "wx/toplevel.h"
33 #include "MoreFilesX.h"
41 #if TARGET_API_MAC_OSX
42 #include <CoreServices/CoreServices.h>
44 #include <DriverServices.h>
45 #include <Multiprocessing.h>
49 #include <Carbon/Carbon.h>
51 #include <ATSUnicode.h>
52 #include <TextCommon.h>
53 #include <TextEncodingConverter.h>
57 #include "wx/mac/private.h"
59 #if defined(__MWERKS__) && wxUSE_UNICODE
60 #if __MWERKS__ < 0x4100 || !defined(__DARWIN__)
65 // ---------------------------------------------------------------------------
66 // code used in both base and GUI compilation
67 // ---------------------------------------------------------------------------
69 // our OS version is the same in non GUI and GUI cases
70 static int DoGetOSVersion(int *majorVsn
, int *minorVsn
)
74 // are there x-platform conventions ?
76 Gestalt(gestaltSystemVersion
, &theSystem
);
78 *minorVsn
= (theSystem
& 0xFF);
81 *majorVsn
= (theSystem
>> 8);
93 // ----------------------------------------------------------------------------
95 // ----------------------------------------------------------------------------
97 #if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
99 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
101 #ifndef __MetroNubUtils__
102 #include "MetroNubUtils.h"
109 #if TARGET_API_MAC_CARBON
111 #include <CodeFragments.h>
113 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
115 ProcPtr gCallUniversalProc_Proc
= NULL
;
119 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
121 static long fRunOnce
= false;
124 Boolean
IsMetroNubInstalled()
131 gMetroNubEntry
= NULL
;
133 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
135 // look for MetroNub's Gestalt selector
136 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
138 #if TARGET_API_MAC_CARBON
139 if (gCallUniversalProc_Proc
== NULL
)
141 CFragConnectionID connectionID
;
144 ProcPtr symbolAddress
;
146 CFragSymbolClass symbolClass
;
148 symbolAddress
= NULL
;
149 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
150 &connectionID
, &mainAddress
, errorString
);
154 gCallUniversalProc_Proc
= NULL
;
158 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
159 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
163 gCallUniversalProc_Proc
= NULL
;
170 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
172 // make sure the version of the API is compatible
173 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
174 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
177 gMetroNubEntry
= block
;
186 #if TARGET_API_MAC_CARBON
187 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
189 return (gMetroNubEntry
!= NULL
);
193 Boolean
IsMWDebuggerRunning()
195 if (IsMetroNubInstalled())
196 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
201 Boolean
AmIBeingMWDebugged()
203 if (IsMetroNubInstalled())
204 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
209 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
211 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
216 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
221 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
225 // defined in unix/utilsunx.cpp for Mac OS X
227 // get full hostname (with domain name if possible)
228 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
230 return wxGetHostName(buf
, maxSize
);
233 // Get user ID e.g. jacs
234 bool wxGetUserId(wxChar
*buf
, int maxSize
)
236 return wxGetUserName( buf
, maxSize
);
239 const wxChar
* wxGetHomeDir(wxString
*pstr
)
241 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
);
242 return pstr
->c_str();
245 // Get hostname only (without domain name)
246 bool wxGetHostName(wxChar
*buf
, int maxSize
)
248 // Gets Chooser name of user by examining a System resource.
251 const short kComputerNameID
= -16413;
253 short oldResFile
= CurResFile();
255 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
256 UseResFile(oldResFile
);
258 if (chooserName
&& *chooserName
)
260 HLock( (Handle
) chooserName
);
261 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
262 HUnlock( (Handle
) chooserName
);
263 ReleaseResource( (Handle
) chooserName
);
264 wxStrncpy( buf
, name
, maxSize
- 1 );
270 // Get user name e.g. Stefan Csomor
271 bool wxGetUserName(wxChar
*buf
, int maxSize
)
273 // Gets Chooser name of user by examining a System resource.
276 const short kChooserNameID
= -16096;
278 short oldResFile
= CurResFile();
280 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
281 UseResFile(oldResFile
);
283 if (chooserName
&& *chooserName
)
285 HLock( (Handle
) chooserName
);
286 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
287 HUnlock( (Handle
) chooserName
);
288 ReleaseResource( (Handle
) chooserName
);
289 wxStrncpy( buf
, name
, maxSize
- 1 );
295 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
, int flags
)
301 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
303 // TODO : under classic there is no environement support, under X yes
307 // set the env var name to the given value, return true on success
308 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
310 // TODO : under classic there is no environement support, under X yes
314 // Execute a program in an Interactive Shell
315 bool wxShell(const wxString
& command
)
321 // Shutdown or reboot the PC
322 bool wxShutdown(wxShutdownFlags wFlags
)
328 wxPowerType
wxGetPowerType()
331 return wxPOWER_UNKNOWN
;
334 wxBatteryState
wxGetBatteryState()
337 return wxBATTERY_UNKNOWN_STATE
;
340 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
341 wxMemorySize
wxGetFreeMemory()
343 return (wxMemorySize
)FreeMem();
348 void wxMicroSleep(unsigned long microseconds
)
350 AbsoluteTime wakeup
= AddDurationToAbsolute( microseconds
* durationMicrosecond
, UpTime());
351 MPDelayUntil( & wakeup
);
354 void wxMilliSleep(unsigned long milliseconds
)
356 AbsoluteTime wakeup
= AddDurationToAbsolute( milliseconds
, UpTime());
357 MPDelayUntil( & wakeup
);
360 void wxSleep(int nSecs
)
362 wxMilliSleep(1000*nSecs
);
367 // Consume all events until no more left
372 #endif // !__DARWIN__
380 wxToolkitInfo
& wxConsoleAppTraits::GetToolkitInfo()
382 static wxToolkitInfo info
;
384 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
385 info
.name
= _T("wxBase");
394 wxToolkitInfo
& wxGUIAppTraits::GetToolkitInfo()
396 static wxToolkitInfo info
;
398 info
.os
= DoGetOSVersion(&info
.versionMajor
, &info
.versionMinor
);
399 info
.shortName
= _T("mac");
400 info
.name
= _T("wxMac");
402 #ifdef __WXUNIVERSAL__
403 info
.shortName
<< _T("univ");
404 info
.name
<< _T("/wxUniversal");
410 // Reading and writing resources (eg WIN.INI, .Xdefaults)
412 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
418 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
421 buf
.Printf(wxT("%.4f"), value
);
423 return wxWriteResource(section
, entry
, buf
, file
);
426 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
429 buf
.Printf(wxT("%ld"), value
);
431 return wxWriteResource(section
, entry
, buf
, file
);
434 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
437 buf
.Printf(wxT("%d"), value
);
439 return wxWriteResource(section
, entry
, buf
, file
);
442 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
448 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
451 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
454 *value
= (float)strtod(s
, NULL
);
461 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
464 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
467 *value
= strtol(s
, NULL
, 10);
474 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
477 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
480 *value
= (int)strtol(s
, NULL
, 10);
486 #endif // wxUSE_RESOURCES
488 int gs_wxBusyCursorCount
= 0;
489 extern wxCursor gMacCurrentCursor
;
490 wxCursor gMacStoredActiveCursor
;
492 // Set the cursor to the busy cursor for all windows
493 void wxBeginBusyCursor(const wxCursor
*cursor
)
495 if (gs_wxBusyCursorCount
++ == 0)
497 gMacStoredActiveCursor
= gMacCurrentCursor
;
498 cursor
->MacInstall();
500 //else: nothing to do, already set
503 // Restore cursor to normal
504 void wxEndBusyCursor()
506 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
507 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
509 if (--gs_wxBusyCursorCount
== 0)
511 gMacStoredActiveCursor
.MacInstall();
512 gMacStoredActiveCursor
= wxNullCursor
;
516 // true if we're between the above two calls
519 return (gs_wxBusyCursorCount
> 0);
526 wxString
wxMacFindFolderNoSeparator( short vol
,
528 Boolean createFolder
)
533 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
535 strDir
= wxMacFSRefToPath( &fsRef
);
541 wxString
wxMacFindFolder( short vol
,
543 Boolean createFolder
)
545 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
552 // Check whether this window wants to process messages, e.g. Stop button
553 // in long calculations.
554 bool wxCheckForInterrupt(wxWindow
*wnd
)
560 void wxGetMousePosition( int* x
, int* y
)
565 LocalToGlobal( &pt
);
570 // Return true if we have a colour display
571 bool wxColourDisplay()
576 // Returns depth of screen
580 SetRect(&globRect
, -32760, -32760, 32760, 32760);
581 GDHandle theMaxDevice
;
584 theMaxDevice
= GetMaxDevice(&globRect
);
585 if (theMaxDevice
!= NULL
)
586 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
591 // Get size of display
592 void wxDisplaySize(int *width
, int *height
)
595 GetQDGlobalsScreenBits( &screenBits
);
598 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
601 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
604 void wxDisplaySizeMM(int *width
, int *height
)
606 wxDisplaySize(width
, height
);
607 // on mac 72 is fixed (at least now;-)
608 float cvPt2Mm
= 25.4 / 72;
611 *width
= int( *width
* cvPt2Mm
);
614 *height
= int( *height
* cvPt2Mm
);
617 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
621 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
627 *width
= r
.right
- r
.left
;
629 *height
= r
.bottom
- r
.top
;
632 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
634 return wxGenericFindWindowAtPoint(pt
);
641 wxString
wxGetOsDescription()
643 #ifdef WXWIN_OS_DESCRIPTION
644 // use configure generated description if available
645 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
647 return wxT("MacOS"); //TODO:define further
652 wxChar
*wxGetUserHome (const wxString
& user
)
658 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
667 int pos
= p
.Find(':');
668 if ( pos
!= wxNOT_FOUND
)
676 err
= wxMacPathToFSRef( p
, &fsRef
);
679 FSVolumeRefNum vRefNum
;
680 err
= FSGetVRefNum( &fsRef
, &vRefNum
);
683 UInt64 freeBytes
, totalBytes
;
684 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
);
688 *pTotal
= wxDiskspaceSize_t( totalBytes
);
690 *pFree
= wxDiskspaceSize_t( freeBytes
);
697 #endif // !__DARWIN__
699 //---------------------------------------------------------------------------
700 // wxMac Specific utility functions
701 //---------------------------------------------------------------------------
703 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
705 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
706 int len
= strlen(buf
);
711 memcpy( (char*) &to
[1] , buf
, len
);
714 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
716 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
719 // ----------------------------------------------------------------------------
720 // Common Event Support
721 // ----------------------------------------------------------------------------
723 extern ProcessSerialNumber gAppProcess
;
727 ProcessSerialNumber psn
;
729 psn
.highLongOfPSN
= 0;
730 psn
.lowLongOfPSN
= kCurrentProcess
;
731 SameProcess( &gAppProcess
, &psn
, &isSame
);
735 OSStatus err
= noErr
;
738 // lead sometimes to race conditions, although all calls used should be thread safe ...
739 static wxMacCarbonEvent s_wakeupEvent
;
740 if ( !s_wakeupEvent
.IsValid() )
742 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
743 kEventAttributeNone
);
748 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
750 s_wakeupEvent
.SetCurrentTime();
751 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
752 kEventPriorityHigh
);
755 wxMacCarbonEvent wakeupEvent
;
756 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
757 kEventAttributeNone
);
758 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
759 kEventPriorityHigh
);
762 PostEvent( nullEvent
, 0 );
767 WakeUpProcess( &gAppProcess
);
775 // ----------------------------------------------------------------------------
776 // Native Struct Conversions
777 // ----------------------------------------------------------------------------
779 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
783 n
->right
= wx
->x
+ wx
->width
;
784 n
->bottom
= wx
->y
+ wx
->height
;
787 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
791 wx
->width
= n
->right
- n
->left
;
792 wx
->height
= n
->bottom
- n
->top
;
795 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
801 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
807 // ----------------------------------------------------------------------------
808 // Carbon Event Support
809 // ----------------------------------------------------------------------------
811 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
813 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
816 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
818 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
821 // ----------------------------------------------------------------------------
822 // Control Access Support
823 // ----------------------------------------------------------------------------
825 wxMacControl::wxMacControl(wxWindow
* peer
, bool isRootControl
)
829 m_isRootControl
= isRootControl
;
830 m_isCompositing
= peer
->MacGetTopLevelWindow()->MacUsesCompositing();
833 wxMacControl::wxMacControl( wxWindow
* peer
, ControlRef control
)
837 m_isCompositing
= peer
->MacGetTopLevelWindow()->MacUsesCompositing();
838 m_controlRef
= control
;
841 wxMacControl::wxMacControl( wxWindow
* peer
, WXWidget control
)
845 m_isCompositing
= peer
->MacGetTopLevelWindow()->MacUsesCompositing();
846 m_controlRef
= (ControlRef
) control
;
849 wxMacControl::~wxMacControl()
853 void wxMacControl::Init()
857 m_needsFocusRect
= false;
858 m_isCompositing
= false;
859 m_isRootControl
= false;
862 void wxMacControl::Dispose()
864 ::DisposeControl( m_controlRef
);
868 void wxMacControl::SetReference( SInt32 data
)
870 SetControlReference( m_controlRef
, data
);
873 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
875 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
);
878 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
880 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
);
883 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
885 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
);
888 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
890 #if TARGET_API_MAC_OSX
891 return SendEventToEventTargetWithOptions( event
,
892 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
894 #pragma unused(inOptions)
895 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) );
899 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
901 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
903 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
);
905 return SendEvent( event
, inOptions
);
908 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
912 memset( &command
, 0 , sizeof(command
) );
913 command
.commandID
= commandID
;
914 return SendHICommand( command
, inOptions
);
917 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
919 unsigned long finalTicks
;
921 HiliteControl( m_controlRef
, part
);
922 Delay( ticks
, &finalTicks
);
923 HiliteControl( m_controlRef
, kControlNoPart
);
926 SInt32
wxMacControl::GetValue() const
928 return ::GetControl32BitValue( m_controlRef
);
931 SInt32
wxMacControl::GetMaximum() const
933 return ::GetControl32BitMaximum( m_controlRef
);
936 SInt32
wxMacControl::GetMinimum() const
938 return ::GetControl32BitMinimum( m_controlRef
);
941 void wxMacControl::SetValue( SInt32 v
)
943 ::SetControl32BitValue( m_controlRef
, v
);
946 void wxMacControl::SetMinimum( SInt32 v
)
948 ::SetControl32BitMinimum( m_controlRef
, v
);
951 void wxMacControl::SetMaximum( SInt32 v
)
953 ::SetControl32BitMaximum( m_controlRef
, v
);
956 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
958 ::SetControl32BitMinimum( m_controlRef
, minimum
);
959 ::SetControl32BitMaximum( m_controlRef
, maximum
);
960 ::SetControl32BitValue( m_controlRef
, value
);
963 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
965 return SetKeyboardFocus( GetControlOwner( m_controlRef
), m_controlRef
, focusPart
);
968 bool wxMacControl::HasFocus() const
971 GetKeyboardFocus( GetUserFocusWindow() , &control
);
972 return control
== m_controlRef
;
975 void wxMacControl::SetNeedsFocusRect( bool needs
)
977 m_needsFocusRect
= needs
;
980 bool wxMacControl::NeedsFocusRect() const
982 return m_needsFocusRect
;
985 void wxMacControl::VisibilityChanged(bool shown
)
989 void wxMacControl::SuperChangedPosition()
993 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
996 ControlFontStyleRec fontStyle
;
997 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
999 switch ( font
.MacGetThemeFontID() )
1001 case kThemeSmallSystemFont
:
1002 fontStyle
.font
= kControlFontSmallSystemFont
;
1005 case 109 : // mini font
1006 fontStyle
.font
= -5;
1009 case kThemeSystemFont
:
1010 fontStyle
.font
= kControlFontBigSystemFont
;
1014 fontStyle
.font
= kControlFontBigSystemFont
;
1018 fontStyle
.flags
= kControlUseFontMask
;
1022 fontStyle
.font
= font
.MacGetFontNum();
1023 fontStyle
.style
= font
.MacGetFontStyle();
1024 fontStyle
.size
= font
.MacGetFontSize();
1025 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
1028 fontStyle
.just
= teJustLeft
;
1029 fontStyle
.flags
|= kControlUseJustMask
;
1030 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
1031 fontStyle
.just
= teJustCenter
;
1032 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
1033 fontStyle
.just
= teJustRight
;
1036 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
1037 // won't get grayed out by the system anymore
1039 if ( foreground
!= *wxBLACK
)
1041 fontStyle
.foreColor
= MAC_WXCOLORREF( foreground
.GetPixel() );
1042 fontStyle
.flags
|= kControlUseForeColorMask
;
1045 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
1048 void wxMacControl::SetBackground( const wxBrush
&WXUNUSED(brush
) )
1051 // setting up a color proc is not recommended anymore
1054 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
1056 ::SetControl32BitMinimum( m_controlRef
, minimum
);
1057 ::SetControl32BitMaximum( m_controlRef
, maximum
);
1060 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
1062 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
);
1065 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
1067 SetControlAction( m_controlRef
, actionProc
);
1070 void wxMacControl::SetViewSize( SInt32 viewSize
)
1072 SetControlViewSize(m_controlRef
, viewSize
);
1075 SInt32
wxMacControl::GetViewSize() const
1077 return GetControlViewSize( m_controlRef
);
1080 bool wxMacControl::IsVisible() const
1082 return IsControlVisible( m_controlRef
);
1085 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
1087 SetControlVisibility( m_controlRef
, visible
, redraw
);
1090 bool wxMacControl::IsEnabled() const
1092 #if TARGET_API_MAC_OSX
1093 return IsControlEnabled( m_controlRef
);
1095 return IsControlActive( m_controlRef
);
1099 bool wxMacControl::IsActive() const
1101 return IsControlActive( m_controlRef
);
1104 void wxMacControl::Enable( bool enable
)
1106 #if TARGET_API_MAC_OSX
1108 EnableControl( m_controlRef
);
1110 DisableControl( m_controlRef
);
1113 ActivateControl( m_controlRef
);
1115 DeactivateControl( m_controlRef
);
1119 void wxMacControl::SetDrawingEnabled( bool enable
)
1121 #if TARGET_API_MAC_OSX
1122 HIViewSetDrawingEnabled( m_controlRef
, enable
);
1126 #if TARGET_API_MAC_OSX
1127 bool wxMacControl::GetNeedsDisplay() const
1129 #if TARGET_API_MAC_OSX
1130 if ( m_isCompositing
)
1132 return HIViewGetNeedsDisplay( m_controlRef
);
1141 GetControlBounds( m_controlRef
, &controlBounds
);
1142 RgnHandle rgn
= NewRgn();
1143 GetWindowRegion ( GetControlOwner( m_controlRef
) , kWindowUpdateRgn
, rgn
);
1144 Boolean intersect
= RectInRgn ( &controlBounds
, rgn
);
1152 void wxMacControl::SetNeedsDisplay( RgnHandle where
)
1157 #if TARGET_API_MAC_OSX
1158 if ( m_isCompositing
)
1160 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, true );
1166 GetControlBounds( m_controlRef
, &controlBounds
);
1167 RgnHandle update
= NewRgn();
1168 CopyRgn( where
, update
);
1169 OffsetRgn( update
, controlBounds
.left
, controlBounds
.top
);
1170 InvalWindowRgn( GetControlOwner( m_controlRef
) , update
);
1174 void wxMacControl::SetNeedsDisplay( Rect
* where
)
1179 #if TARGET_API_MAC_OSX
1180 if ( m_isCompositing
)
1182 if ( where
!= NULL
)
1184 RgnHandle update
= NewRgn();
1185 RectRgn( update
, where
);
1186 HIViewSetNeedsDisplayInRegion( m_controlRef
, update
, true );
1187 DisposeRgn( update
);
1190 HIViewSetNeedsDisplay( m_controlRef
, true );
1197 GetControlBounds( m_controlRef
, &controlBounds
);
1200 Rect whereLocal
= *where
;
1201 OffsetRect( &whereLocal
, controlBounds
.left
, controlBounds
.top
);
1202 SectRect( &controlBounds
, &whereLocal
, &controlBounds
);
1205 InvalWindowRect( GetControlOwner( m_controlRef
) , &controlBounds
);
1209 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
1211 #if TARGET_API_MAC_OSX
1212 if ( from
->m_peer
->MacGetTopLevelWindow()->MacUsesCompositing() )
1218 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
);
1219 pt
->x
= (int)hiPoint
.x
;
1220 pt
->y
= (int)hiPoint
.y
;
1225 Rect fromRect
, toRect
;
1227 GetControlBounds( from
->m_controlRef
, &fromRect
);
1228 GetControlBounds( to
->m_controlRef
, &toRect
);
1229 if ( from
->m_isRootControl
)
1230 fromRect
.left
= fromRect
.top
= 0;
1231 if ( to
->m_isRootControl
)
1232 toRect
.left
= toRect
.top
= 0;
1234 pt
->x
= pt
->x
+ fromRect
.left
- toRect
.left
;
1235 pt
->y
= pt
->y
+ fromRect
.top
- toRect
.top
;
1239 void wxMacControl::SetRect( Rect
*r
)
1241 #if TARGET_API_MAC_OSX
1242 if ( m_isCompositing
)
1244 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1245 //CGPoint and CGSize, which have two floats each
1246 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} };
1247 HIViewSetFrame ( m_controlRef
, &hir
);
1248 // eventuall we might have to do a SetVisibility( false , true );
1249 // before and a SetVisibility( true , true ); after
1254 bool vis
= IsVisible();
1258 GetControlBounds( m_controlRef
, &former
);
1259 InvalWindowRect( GetControlOwner( m_controlRef
) , &former
);
1262 Rect controlBounds
= *r
;
1264 // since the rect passed in is always (even in non-compositing) relative
1265 // to the (native) parent, we have to adjust to window relative here
1266 wxMacControl
* parent
= m_peer
->GetParent()->GetPeer();
1267 if ( !parent
->m_isRootControl
)
1270 GetControlBounds( parent
->m_controlRef
, &superRect
);
1271 OffsetRect( &controlBounds
, superRect
.left
, superRect
.top
);
1274 SetControlBounds( m_controlRef
, &controlBounds
);
1276 InvalWindowRect( GetControlOwner( m_controlRef
) , &controlBounds
);
1280 void wxMacControl::GetRect( Rect
*r
)
1282 GetControlBounds( m_controlRef
, r
);
1283 if ( !m_isCompositing
)
1285 // correct the case of the root control
1286 if ( m_isRootControl
)
1288 WindowRef wr
= GetControlOwner( m_controlRef
);
1289 GetWindowBounds( wr
, kWindowContentRgn
, r
);
1290 r
->right
-= r
->left
;
1291 r
->bottom
-= r
->top
;
1297 wxMacControl
* parent
= m_peer
->GetParent()->GetPeer();
1298 if ( !parent
->m_isRootControl
)
1301 GetControlBounds( parent
->m_controlRef
, &superRect
);
1302 OffsetRect( r
, -superRect
.left
, -superRect
.top
);
1308 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
1310 UMAGetControlBoundsInWindowCoords( m_controlRef
, r
);
1313 void wxMacControl::GetBestRect( Rect
*r
)
1315 short baselineoffset
;
1317 GetBestControlRect( m_controlRef
, r
, &baselineoffset
);
1320 void wxMacControl::SetLabel( const wxString
&title
)
1322 wxFontEncoding encoding
;
1325 encoding
= m_font
.GetEncoding();
1327 encoding
= wxFont::GetDefaultEncoding();
1329 UMASetControlTitle( m_controlRef
, title
, encoding
);
1332 void wxMacControl::GetFeatures( UInt32
* features
)
1334 GetControlFeatures( m_controlRef
, features
);
1337 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
1339 OSStatus err
= GetControlRegion( m_controlRef
, partCode
, region
);
1340 if ( !m_isCompositing
)
1342 if ( !m_isRootControl
)
1346 GetControlBounds(m_controlRef
, &r
);
1347 if ( !EmptyRgn( region
) )
1348 OffsetRgn( region
, -r
.left
, -r
.top
);
1355 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
1357 #if TARGET_API_MAC_OSX
1358 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
1359 (other
!= NULL
) ? other
->m_controlRef
: NULL
);
1365 #if TARGET_API_MAC_OSX
1366 // SetNeedsDisplay would not invalidate the children
1367 static void InvalidateControlAndChildren( HIViewRef control
)
1369 HIViewSetNeedsDisplay( control
, true );
1370 UInt16 childrenCount
= 0;
1371 OSStatus err
= CountSubControls( control
, &childrenCount
);
1372 if ( err
== errControlIsNotEmbedder
)
1375 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") );
1377 for ( UInt16 i
= childrenCount
; i
>=1; --i
)
1381 err
= GetIndexedSubControl( control
, i
, & child
);
1382 if ( err
== errControlIsNotEmbedder
)
1385 InvalidateControlAndChildren( child
);
1390 void wxMacControl::InvalidateWithChildren()
1392 #if TARGET_API_MAC_OSX
1393 InvalidateControlAndChildren( m_controlRef
);
1397 void wxMacControl::ScrollRect( wxRect
*r
, int dx
, int dy
)
1399 wxASSERT( r
!= NULL
);
1401 #if TARGET_API_MAC_OSX
1402 if ( m_isCompositing
)
1404 HIRect scrollarea
= CGRectMake( r
->x
, r
->y
, r
->width
, r
->height
);
1405 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
);
1412 GetControlBounds( m_controlRef
, &bounds
);
1413 bounds
.left
+= r
->x
;
1415 bounds
.bottom
= bounds
.top
+ r
->height
;
1416 bounds
.right
= bounds
.left
+ r
->width
;
1417 wxMacWindowClipper
clip( m_peer
);
1418 RgnHandle updateRgn
= NewRgn();
1419 ::ScrollRect( &bounds
, dx
, dy
, updateRgn
);
1420 InvalWindowRgn( GetControlOwner( m_controlRef
) , updateRgn
);
1421 DisposeRgn( updateRgn
);
1425 OSType wxMacCreator
= 'WXMC';
1426 OSType wxMacControlProperty
= 'MCCT';
1428 void wxMacControl::SetReferenceInNativeControl()
1431 verify_noerr( SetControlProperty ( m_controlRef
,
1432 wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data
) );
1435 wxMacControl
* wxMacControl::GetReferenceFromNativeControl(ControlRef control
)
1437 wxMacControl
* ctl
= NULL
;
1439 if ( GetControlProperty( control
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) ,
1440 &actualSize
, &ctl
) == noErr
)
1447 // ============================================================================
1448 // DataBrowser Wrapper
1449 // ============================================================================
1451 // basing on DataBrowserItemIDs
1454 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
1456 DataBrowserItemID itemID
,
1457 DataBrowserItemNotification message
,
1458 DataBrowserItemDataRef itemData
)
1460 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1463 ctl
->ItemNotification(itemID
, message
, itemData
);
1467 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
1469 DataBrowserItemID itemID
,
1470 DataBrowserPropertyID property
,
1471 DataBrowserItemDataRef itemData
,
1472 Boolean changeValue
)
1474 OSStatus err
= errDataBrowserPropertyNotSupported
;
1476 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1479 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
1484 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
1486 DataBrowserItemID itemOneID
,
1487 DataBrowserItemID itemTwoID
,
1488 DataBrowserPropertyID sortProperty
)
1490 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1493 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
1498 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
1499 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
1500 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
1502 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) : wxMacControl( peer
)
1504 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
1505 OSStatus err
= ::CreateDataBrowserControl(
1506 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
1507 &bounds
, kDataBrowserListView
, &m_controlRef
);
1508 SetReferenceInNativeControl();
1509 verify_noerr( err
);
1510 if ( gDataBrowserItemCompareUPP
== NULL
)
1511 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
1512 if ( gDataBrowserItemDataUPP
== NULL
)
1513 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
1514 if ( gDataBrowserItemNotificationUPP
== NULL
)
1516 gDataBrowserItemNotificationUPP
=
1517 #if TARGET_API_MAC_OSX
1518 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
1520 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc
);
1524 DataBrowserCallbacks callbacks
;
1525 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
1527 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
1528 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
1529 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
1530 SetCallbacks( &callbacks
);
1534 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
1536 DataBrowserItemState state
,
1537 UInt32
*numItems
) const
1539 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
1542 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
1544 DataBrowserItemState state
,
1547 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
1550 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1552 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
1555 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1556 DataBrowserTableViewColumnIndex position
)
1558 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
1561 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
1563 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
1566 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
1568 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
1571 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1573 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
1576 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
1578 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1581 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
1583 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1586 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
1588 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
1591 OSStatus
wxMacDataBrowserControl::UpdateItems(
1592 DataBrowserItemID container
,
1594 const DataBrowserItemID
*items
,
1595 DataBrowserPropertyID preSortProperty
,
1596 DataBrowserPropertyID propertyID
) const
1598 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
1601 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
1603 return IsDataBrowserItemSelected( m_controlRef
, item
);
1606 OSStatus
wxMacDataBrowserControl::AddItems(
1607 DataBrowserItemID container
,
1609 const DataBrowserItemID
*items
,
1610 DataBrowserPropertyID preSortProperty
)
1612 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1615 OSStatus
wxMacDataBrowserControl::RemoveItems(
1616 DataBrowserItemID container
,
1618 const DataBrowserItemID
*items
,
1619 DataBrowserPropertyID preSortProperty
)
1621 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1624 OSStatus
wxMacDataBrowserControl::RevealItem(
1625 DataBrowserItemID item
,
1626 DataBrowserPropertyID propertyID
,
1627 DataBrowserRevealOptions options
) const
1629 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
1632 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
1634 const DataBrowserItemID
*items
,
1635 DataBrowserSetOption operation
)
1637 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
1640 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
1642 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
1645 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
1647 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
1650 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
1652 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
1655 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
1657 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1660 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
1662 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1665 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
1667 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1670 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
1672 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1675 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
1677 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1680 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
1682 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1685 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
1687 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1690 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
1692 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1695 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
1697 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
1700 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
1701 UInt32
*position
) const
1703 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1706 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, UInt32 position
)
1708 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1711 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
1713 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1716 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
1718 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1721 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
1723 return GetDataBrowserSortProperty( m_controlRef
, column
);
1726 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
1728 return SetDataBrowserSortProperty( m_controlRef
, column
);
1731 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
1733 return GetDataBrowserSortOrder( m_controlRef
, order
);
1736 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
1738 return SetDataBrowserSortOrder( m_controlRef
, order
);
1741 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
1742 DataBrowserPropertyFlags
*flags
) const
1744 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1747 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
1748 DataBrowserPropertyFlags flags
)
1750 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1753 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
1754 DataBrowserListViewHeaderDesc
*desc
) const
1756 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1759 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
1760 DataBrowserListViewHeaderDesc
*desc
)
1762 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1765 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
1766 Boolean expandableRows
)
1768 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
1771 // ============================================================================
1772 // Higher-level Databrowser
1773 // ============================================================================
1775 // basing on data item objects
1778 wxMacDataItem::wxMacDataItem()
1782 wxMacDataItem::~wxMacDataItem()
1786 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*owner
,
1787 const wxMacDataItem
*,
1788 DataBrowserPropertyID property
) const
1793 OSStatus
wxMacDataItem::GetSetData(wxMacDataItemBrowserControl
*owner
,
1794 DataBrowserPropertyID property
,
1795 DataBrowserItemDataRef itemData
,
1798 return errDataBrowserPropertyNotSupported
;
1801 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*owner
,
1802 DataBrowserItemNotification message
,
1803 DataBrowserItemDataRef itemData
) const
1808 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1809 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1811 m_suppressSelection
= false;
1814 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1816 m_former
= browser
->SuppressSelection(true);
1817 m_browser
= browser
;
1820 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1822 m_browser
->SuppressSelection(m_former
);
1825 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
1827 bool former
= m_suppressSelection
;
1828 m_suppressSelection
= suppress
;
1833 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
1834 DataBrowserItemID itemTwoID
,
1835 DataBrowserPropertyID sortProperty
)
1837 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1838 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1839 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1842 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
1843 const wxMacDataItem
* itemTwo
,
1844 DataBrowserPropertyID sortProperty
)
1846 Boolean retval
= false;
1847 if ( itemOne
!= NULL
)
1848 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1852 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1853 DataBrowserItemID itemID
,
1854 DataBrowserPropertyID property
,
1855 DataBrowserItemDataRef itemData
,
1856 Boolean changeValue
)
1858 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1859 return GetSetItemData(item
, property
, itemData
, changeValue
);
1862 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1863 wxMacDataItem
* item
,
1864 DataBrowserPropertyID property
,
1865 DataBrowserItemDataRef itemData
,
1866 Boolean changeValue
)
1868 OSStatus err
= errDataBrowserPropertyNotSupported
;
1871 case kDataBrowserContainerIsClosableProperty
:
1872 case kDataBrowserContainerIsSortableProperty
:
1873 case kDataBrowserContainerIsOpenableProperty
:
1874 // right now default behaviour on these
1878 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1885 void wxMacDataItemBrowserControl::ItemNotification(
1886 DataBrowserItemID itemID
,
1887 DataBrowserItemNotification message
,
1888 DataBrowserItemDataRef itemData
)
1890 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1891 ItemNotification( item
, message
, itemData
);
1894 void wxMacDataItemBrowserControl::ItemNotification(
1895 const wxMacDataItem
* item
,
1896 DataBrowserItemNotification message
,
1897 DataBrowserItemDataRef itemData
)
1900 item
->Notification( this, message
, itemData
);
1903 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
1904 bool recurse
, DataBrowserItemState state
) const
1906 UInt32 numItems
= 0;
1907 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
1908 recurse
, state
, &numItems
) );
1912 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
1913 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1915 Handle handle
= NewHandle(0);
1916 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
1917 recurse
, state
, handle
) );
1919 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1921 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1922 for ( int i
= 0; i
< itemCount
; ++i
)
1924 items
.Add(itemsArray
[i
]);
1927 DisposeHandle( handle
);
1930 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
1932 DataBrowserTableViewRowIndex row
;
1933 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1934 wxASSERT( err
== noErr
);
1938 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
1940 DataBrowserItemID id
;
1941 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1942 wxASSERT( err
== noErr
);
1943 return (wxMacDataItem
*) id
;
1946 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
1947 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1949 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
1950 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1953 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
1954 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1956 unsigned int noItems
= itemArray
.GetCount();
1957 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1958 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1959 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1961 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
1962 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1966 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1968 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
1969 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1972 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1974 unsigned int noItems
= itemArray
.GetCount();
1975 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1976 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1977 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1979 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
1980 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1984 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1986 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
1987 (UInt32
*) &item
, kDataBrowserItemNoProperty
);
1988 verify_noerr( err
);
1991 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1993 unsigned int noItems
= itemArray
.GetCount();
1994 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1995 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1996 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1998 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
1999 (UInt32
*) items
, kDataBrowserItemNoProperty
);
2000 verify_noerr( err
);
2004 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
2006 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
2007 verify_noerr( err
);
2010 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
2012 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
2015 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
2017 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
2020 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
2022 unsigned int noItems
= itemArray
.GetCount();
2023 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
2024 for ( unsigned int i
= 0; i
< noItems
; ++i
)
2025 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
2027 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
2031 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
2033 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
2036 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
2038 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
2041 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
2043 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
2052 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
2054 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
2061 #ifdef __WXMAC_OSX__
2062 // snippets from Sketch Sample from Apple :
2064 #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
2067 This function locates, opens, and returns the profile reference for the calibrated
2068 Generic RGB color space. It is up to the caller to call CMCloseProfile when done
2069 with the profile reference this function returns.
2071 CMProfileRef
wxMacOpenGenericProfile()
2073 static CMProfileRef cachedRGBProfileRef
= NULL
;
2075 // we only create the profile reference once
2076 if (cachedRGBProfileRef
== NULL
)
2078 CMProfileLocation loc
;
2080 loc
.locType
= cmPathBasedProfile
;
2081 strcpy(loc
.u
.pathLoc
.path
, kGenericRGBProfilePathStr
);
2083 verify_noerr( CMOpenProfile(&cachedRGBProfileRef
, &loc
) );
2086 // clone the profile reference so that the caller has their own reference, not our cached one
2087 if (cachedRGBProfileRef
)
2088 CMCloneProfileRef(cachedRGBProfileRef
);
2090 return cachedRGBProfileRef
;
2094 Return the generic RGB color space. This is a 'get' function and the caller should
2095 not release the returned value unless the caller retains it first. Usually callers
2096 of this routine will immediately use the returned colorspace with CoreGraphics
2097 so they typically do not need to retain it themselves.
2099 This function creates the generic RGB color space once and hangs onto it so it can
2100 return it whenever this function is called.
2103 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
2105 static wxMacCFRefHolder
<CGColorSpaceRef
> genericRGBColorSpace
;
2107 if (genericRGBColorSpace
== NULL
)
2109 if ( UMAGetSystemVersion() >= 0x1040 )
2111 genericRGBColorSpace
.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) );
2115 CMProfileRef genericRGBProfile
= wxMacOpenGenericProfile();
2117 if (genericRGBProfile
)
2119 genericRGBColorSpace
.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile
) );
2121 wxASSERT_MSG( genericRGBColorSpace
!= NULL
, wxT("couldn't create the generic RGB color space") );
2123 // we opened the profile so it is up to us to close it
2124 CMCloseProfile(genericRGBProfile
);
2129 return genericRGBColorSpace
;
2133 wxMacPortSaver::wxMacPortSaver( GrafPtr port
)
2135 ::GetPort( &m_port
);
2139 wxMacPortSaver::~wxMacPortSaver()
2141 ::SetPort( m_port
);