1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/utils.cpp
3 // Purpose: Various utilities
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
20 #include "wx/toplevel.h"
25 #include "wx/apptrait.h"
28 #include "wx/mac/uma.h"
38 #include "MoreFilesX.h"
46 #if TARGET_API_MAC_OSX
47 #include <CoreServices/CoreServices.h>
49 #include <DriverServices.h>
50 #include <Multiprocessing.h>
54 #include <Carbon/Carbon.h>
56 #include <ATSUnicode.h>
57 #include <TextCommon.h>
58 #include <TextEncodingConverter.h>
62 #include "wx/mac/private.h"
64 #if defined(__MWERKS__) && wxUSE_UNICODE
65 #if __MWERKS__ < 0x4100 || !defined(__DARWIN__)
72 // our OS version is the same in non GUI and GUI cases
73 wxOperatingSystemId
wxGetOsVersion(int *majorVsn
, int *minorVsn
)
76 Gestalt(gestaltSystemVersion
, &theSystem
);
78 if ( majorVsn
!= NULL
)
79 *majorVsn
= (theSystem
>> 8);
81 if ( minorVsn
!= NULL
)
82 *minorVsn
= (theSystem
& 0xFF);
84 #if defined( __DARWIN__ )
85 return wxOS_MAC_OSX_DARWIN
;
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
95 #if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
97 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
99 #ifndef __MetroNubUtils__
100 #include "MetroNubUtils.h"
107 #if TARGET_API_MAC_CARBON
109 #include <CodeFragments.h>
111 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
113 ProcPtr gCallUniversalProc_Proc
= NULL
;
117 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
119 static long fRunOnce
= false;
122 Boolean
IsMetroNubInstalled()
129 gMetroNubEntry
= NULL
;
131 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
133 // look for MetroNub's Gestalt selector
134 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
136 #if TARGET_API_MAC_CARBON
137 if (gCallUniversalProc_Proc
== NULL
)
139 CFragConnectionID connectionID
;
142 ProcPtr symbolAddress
;
144 CFragSymbolClass symbolClass
;
146 symbolAddress
= NULL
;
147 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
148 &connectionID
, &mainAddress
, errorString
);
152 gCallUniversalProc_Proc
= NULL
;
156 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
157 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
161 gCallUniversalProc_Proc
= NULL
;
168 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
170 // make sure the version of the API is compatible
171 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
172 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
175 gMetroNubEntry
= block
;
184 #if TARGET_API_MAC_CARBON
185 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
187 return (gMetroNubEntry
!= NULL
);
191 Boolean
IsMWDebuggerRunning()
193 if (IsMetroNubInstalled())
194 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
199 Boolean
AmIBeingMWDebugged()
201 if (IsMetroNubInstalled())
202 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
207 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
209 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
214 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
219 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
223 // defined in unix/utilsunx.cpp for Mac OS X
225 // get full hostname (with domain name if possible)
226 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
228 return wxGetHostName(buf
, maxSize
);
231 // Get user ID e.g. jacs
232 bool wxGetUserId(wxChar
*buf
, int maxSize
)
234 return wxGetUserName( buf
, maxSize
);
237 const wxChar
* wxGetHomeDir(wxString
*pstr
)
239 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
);
240 return pstr
->c_str();
243 // Get hostname only (without domain name)
244 bool wxGetHostName(wxChar
*buf
, int maxSize
)
246 // Gets Chooser name of user by examining a System resource.
249 const short kComputerNameID
= -16413;
251 short oldResFile
= CurResFile();
253 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
254 UseResFile(oldResFile
);
256 if (chooserName
&& *chooserName
)
258 HLock( (Handle
) chooserName
);
259 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
260 HUnlock( (Handle
) chooserName
);
261 ReleaseResource( (Handle
) chooserName
);
262 wxStrncpy( buf
, name
, maxSize
- 1 );
268 // Get user name e.g. Stefan Csomor
269 bool wxGetUserName(wxChar
*buf
, int maxSize
)
271 // Gets Chooser name of user by examining a System resource.
274 const short kChooserNameID
= -16096;
276 short oldResFile
= CurResFile();
278 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
279 UseResFile(oldResFile
);
281 if (chooserName
&& *chooserName
)
283 HLock( (Handle
) chooserName
);
284 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
285 HUnlock( (Handle
) chooserName
);
286 ReleaseResource( (Handle
) chooserName
);
287 wxStrncpy( buf
, name
, maxSize
- 1 );
293 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
, int flags
)
299 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
301 // TODO : under classic there is no environement support, under X yes
305 // set the env var name to the given value, return true on success
306 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
308 // TODO : under classic there is no environement support, under X yes
312 // Execute a program in an Interactive Shell
313 bool wxShell(const wxString
& command
)
319 // Shutdown or reboot the PC
320 bool wxShutdown(wxShutdownFlags wFlags
)
326 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
327 wxMemorySize
wxGetFreeMemory()
329 return (wxMemorySize
)FreeMem();
334 void wxMicroSleep(unsigned long microseconds
)
336 AbsoluteTime wakeup
= AddDurationToAbsolute( microseconds
* durationMicrosecond
, UpTime());
337 MPDelayUntil( & wakeup
);
340 void wxMilliSleep(unsigned long milliseconds
)
342 AbsoluteTime wakeup
= AddDurationToAbsolute( milliseconds
, UpTime());
343 MPDelayUntil( & wakeup
);
346 void wxSleep(int nSecs
)
348 wxMilliSleep(1000*nSecs
);
353 // Consume all events until no more left
358 #endif // !__DARWIN__
373 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
375 // We suppose that toolkit version is the same as OS version under Mac
376 wxGetOsVersion(verMaj
, verMin
);
381 // Reading and writing resources (eg WIN.INI, .Xdefaults)
383 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
389 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
392 buf
.Printf(wxT("%.4f"), value
);
394 return wxWriteResource(section
, entry
, buf
, file
);
397 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
400 buf
.Printf(wxT("%ld"), value
);
402 return wxWriteResource(section
, entry
, buf
, file
);
405 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
408 buf
.Printf(wxT("%d"), value
);
410 return wxWriteResource(section
, entry
, buf
, file
);
413 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
419 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
422 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
425 *value
= (float)strtod(s
, NULL
);
432 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
435 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
438 *value
= strtol(s
, NULL
, 10);
445 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
448 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
451 *value
= (int)strtol(s
, NULL
, 10);
457 #endif // wxUSE_RESOURCES
459 int gs_wxBusyCursorCount
= 0;
460 extern wxCursor gMacCurrentCursor
;
461 wxCursor gMacStoredActiveCursor
;
463 // Set the cursor to the busy cursor for all windows
464 void wxBeginBusyCursor(const wxCursor
*cursor
)
466 if (gs_wxBusyCursorCount
++ == 0)
468 gMacStoredActiveCursor
= gMacCurrentCursor
;
469 cursor
->MacInstall();
471 //else: nothing to do, already set
474 // Restore cursor to normal
475 void wxEndBusyCursor()
477 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
478 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
480 if (--gs_wxBusyCursorCount
== 0)
482 gMacStoredActiveCursor
.MacInstall();
483 gMacStoredActiveCursor
= wxNullCursor
;
487 // true if we're between the above two calls
490 return (gs_wxBusyCursorCount
> 0);
497 wxString
wxMacFindFolderNoSeparator( short vol
,
499 Boolean createFolder
)
504 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
506 strDir
= wxMacFSRefToPath( &fsRef
);
512 wxString
wxMacFindFolder( short vol
,
514 Boolean createFolder
)
516 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
523 // Check whether this window wants to process messages, e.g. Stop button
524 // in long calculations.
525 bool wxCheckForInterrupt(wxWindow
*wnd
)
531 void wxGetMousePosition( int* x
, int* y
)
534 #if wxMAC_USE_CORE_GRAPHICS
538 LocalToGlobal( &pt
);
544 // Return true if we have a colour display
545 bool wxColourDisplay()
550 // Returns depth of screen
554 #if wxMAC_USE_CORE_GRAPHICS
555 theDepth
= (int) CGDisplayBitsPerPixel(CGMainDisplayID());
558 SetRect(&globRect
, -32760, -32760, 32760, 32760);
559 GDHandle theMaxDevice
;
561 theMaxDevice
= GetMaxDevice(&globRect
);
562 if (theMaxDevice
!= NULL
)
563 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
568 // Get size of display
569 void wxDisplaySize(int *width
, int *height
)
571 #if wxMAC_USE_CORE_GRAPHICS
573 // TODO adapt for multi-displays
574 bounds
= CGDisplayBounds(CGMainDisplayID());
576 *width
= bounds
.size
.width
;
578 *height
= bounds
.size
.height
;
581 GetQDGlobalsScreenBits( &screenBits
);
584 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
587 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
591 void wxDisplaySizeMM(int *width
, int *height
)
593 wxDisplaySize(width
, height
);
594 // on mac 72 is fixed (at least now;-)
595 float cvPt2Mm
= 25.4 / 72;
598 *width
= int( *width
* cvPt2Mm
);
601 *height
= int( *height
* cvPt2Mm
);
604 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
606 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
608 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
611 *x
= bounds
.origin
.x
;
613 *y
= bounds
.origin
.y
;
615 *width
= bounds
.size
.width
;
617 *height
= bounds
.size
.height
;
620 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
626 *width
= r
.right
- r
.left
;
628 *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
;
832 wxMacControl::wxMacControl( wxWindow
* peer
, ControlRef control
)
836 m_controlRef
= control
;
839 wxMacControl::wxMacControl( wxWindow
* peer
, WXWidget control
)
843 m_controlRef
= (ControlRef
) control
;
846 wxMacControl::~wxMacControl()
850 void wxMacControl::Init()
854 m_needsFocusRect
= false;
855 m_isRootControl
= false;
858 void wxMacControl::Dispose()
860 wxASSERT_MSG( IsValidControlHandle(m_controlRef
) , wxT("Invalid Control Handle (maybe already released) in Dispose") );
862 CFIndex count
= CFGetRetainCount( m_controlRef
) ;
863 wxASSERT_MSG( count
== 1 , wxT("Reference Count of native control was not 1 in Dispose") );
865 ::DisposeControl( m_controlRef
);
869 void wxMacControl::SetReference( URefCon data
)
871 SetControlReference( m_controlRef
, data
);
874 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
876 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
);
879 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
881 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
);
884 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
886 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
);
889 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
891 #if TARGET_API_MAC_OSX
892 return SendEventToEventTargetWithOptions( event
,
893 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
895 #pragma unused(inOptions)
896 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) );
900 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
902 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
904 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
);
906 return SendEvent( event
, inOptions
);
909 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
913 memset( &command
, 0 , sizeof(command
) );
914 command
.commandID
= commandID
;
915 return SendHICommand( command
, inOptions
);
918 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
920 unsigned long finalTicks
;
922 HiliteControl( m_controlRef
, part
);
923 Delay( ticks
, &finalTicks
);
924 HiliteControl( m_controlRef
, kControlNoPart
);
927 SInt32
wxMacControl::GetValue() const
929 return ::GetControl32BitValue( m_controlRef
);
932 SInt32
wxMacControl::GetMaximum() const
934 return ::GetControl32BitMaximum( m_controlRef
);
937 SInt32
wxMacControl::GetMinimum() const
939 return ::GetControl32BitMinimum( m_controlRef
);
942 void wxMacControl::SetValue( SInt32 v
)
944 ::SetControl32BitValue( m_controlRef
, v
);
947 void wxMacControl::SetMinimum( SInt32 v
)
949 ::SetControl32BitMinimum( m_controlRef
, v
);
952 void wxMacControl::SetMaximum( SInt32 v
)
954 ::SetControl32BitMaximum( m_controlRef
, v
);
957 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
959 ::SetControl32BitMinimum( m_controlRef
, minimum
);
960 ::SetControl32BitMaximum( m_controlRef
, maximum
);
961 ::SetControl32BitValue( m_controlRef
, value
);
964 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
966 return SetKeyboardFocus( GetControlOwner( m_controlRef
), m_controlRef
, focusPart
);
969 bool wxMacControl::HasFocus() const
972 GetKeyboardFocus( GetUserFocusWindow() , &control
);
973 return control
== m_controlRef
;
976 void wxMacControl::SetNeedsFocusRect( bool needs
)
978 m_needsFocusRect
= needs
;
981 bool wxMacControl::NeedsFocusRect() const
983 return m_needsFocusRect
;
986 void wxMacControl::VisibilityChanged(bool shown
)
990 void wxMacControl::SuperChangedPosition()
994 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
997 ControlFontStyleRec fontStyle
;
998 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
1000 switch ( font
.MacGetThemeFontID() )
1002 case kThemeSmallSystemFont
:
1003 fontStyle
.font
= kControlFontSmallSystemFont
;
1006 case 109 : // mini font
1007 fontStyle
.font
= -5;
1010 case kThemeSystemFont
:
1011 fontStyle
.font
= kControlFontBigSystemFont
;
1015 fontStyle
.font
= kControlFontBigSystemFont
;
1019 fontStyle
.flags
= kControlUseFontMask
;
1023 fontStyle
.font
= font
.MacGetFontNum();
1024 fontStyle
.style
= font
.MacGetFontStyle();
1025 fontStyle
.size
= font
.MacGetFontSize();
1026 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
1029 fontStyle
.just
= teJustLeft
;
1030 fontStyle
.flags
|= kControlUseJustMask
;
1031 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
1032 fontStyle
.just
= teJustCenter
;
1033 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
1034 fontStyle
.just
= teJustRight
;
1037 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
1038 // won't get grayed out by the system anymore
1040 if ( foreground
!= *wxBLACK
)
1042 fontStyle
.foreColor
= MAC_WXCOLORREF( foreground
.GetPixel() );
1043 fontStyle
.flags
|= kControlUseForeColorMask
;
1046 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
1049 void wxMacControl::SetBackground( const wxBrush
&WXUNUSED(brush
) )
1052 // setting up a color proc is not recommended anymore
1055 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
1057 ::SetControl32BitMinimum( m_controlRef
, minimum
);
1058 ::SetControl32BitMaximum( m_controlRef
, maximum
);
1061 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
1064 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
);
1070 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
1072 SetControlAction( m_controlRef
, actionProc
);
1075 void wxMacControl::SetViewSize( SInt32 viewSize
)
1077 SetControlViewSize(m_controlRef
, viewSize
);
1080 SInt32
wxMacControl::GetViewSize() const
1082 return GetControlViewSize( m_controlRef
);
1085 bool wxMacControl::IsVisible() const
1087 return IsControlVisible( m_controlRef
);
1090 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
1092 SetControlVisibility( m_controlRef
, visible
, redraw
);
1095 bool wxMacControl::IsEnabled() const
1097 #if TARGET_API_MAC_OSX
1098 return IsControlEnabled( m_controlRef
);
1100 return IsControlActive( m_controlRef
);
1104 bool wxMacControl::IsActive() const
1106 return IsControlActive( m_controlRef
);
1109 void wxMacControl::Enable( bool enable
)
1112 EnableControl( m_controlRef
);
1114 DisableControl( m_controlRef
);
1117 void wxMacControl::SetDrawingEnabled( bool enable
)
1119 HIViewSetDrawingEnabled( m_controlRef
, enable
);
1122 bool wxMacControl::GetNeedsDisplay() const
1124 return HIViewGetNeedsDisplay( m_controlRef
);
1127 void wxMacControl::SetNeedsDisplay( RgnHandle where
)
1132 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, true );
1135 void wxMacControl::SetNeedsDisplay( Rect
* where
)
1140 if ( where
!= NULL
)
1142 RgnHandle update
= NewRgn();
1143 RectRgn( update
, where
);
1144 HIViewSetNeedsDisplayInRegion( m_controlRef
, update
, true );
1145 DisposeRgn( update
);
1148 HIViewSetNeedsDisplay( m_controlRef
, true );
1151 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
1157 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
);
1158 pt
->x
= (int)hiPoint
.x
;
1159 pt
->y
= (int)hiPoint
.y
;
1162 void wxMacControl::SetRect( Rect
*r
)
1164 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1165 //CGPoint and CGSize, which have two floats each
1166 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} };
1167 HIViewSetFrame ( m_controlRef
, &hir
);
1168 // eventuall we might have to do a SetVisibility( false , true );
1169 // before and a SetVisibility( true , true ); after
1172 void wxMacControl::GetRect( Rect
*r
)
1174 GetControlBounds( m_controlRef
, r
);
1177 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
1179 UMAGetControlBoundsInWindowCoords( m_controlRef
, r
);
1182 void wxMacControl::GetBestRect( Rect
*r
)
1184 short baselineoffset
;
1186 GetBestControlRect( m_controlRef
, r
, &baselineoffset
);
1189 void wxMacControl::SetLabel( const wxString
&title
)
1191 wxFontEncoding encoding
;
1194 encoding
= m_font
.GetEncoding();
1196 encoding
= wxFont::GetDefaultEncoding();
1198 UMASetControlTitle( m_controlRef
, title
, encoding
);
1201 void wxMacControl::GetFeatures( UInt32
* features
)
1203 GetControlFeatures( m_controlRef
, features
);
1206 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
1208 OSStatus err
= GetControlRegion( m_controlRef
, partCode
, region
);
1212 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
1214 #if TARGET_API_MAC_OSX
1215 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
1216 (other
!= NULL
) ? other
->m_controlRef
: NULL
);
1222 #if TARGET_API_MAC_OSX
1223 // SetNeedsDisplay would not invalidate the children
1224 static void InvalidateControlAndChildren( HIViewRef control
)
1226 HIViewSetNeedsDisplay( control
, true );
1227 UInt16 childrenCount
= 0;
1228 OSStatus err
= CountSubControls( control
, &childrenCount
);
1229 if ( err
== errControlIsNotEmbedder
)
1232 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") );
1234 for ( UInt16 i
= childrenCount
; i
>=1; --i
)
1238 err
= GetIndexedSubControl( control
, i
, & child
);
1239 if ( err
== errControlIsNotEmbedder
)
1242 InvalidateControlAndChildren( child
);
1247 void wxMacControl::InvalidateWithChildren()
1249 #if TARGET_API_MAC_OSX
1250 InvalidateControlAndChildren( m_controlRef
);
1254 void wxMacControl::ScrollRect( wxRect
*r
, int dx
, int dy
)
1256 wxASSERT( r
!= NULL
);
1258 HIRect scrollarea
= CGRectMake( r
->x
, r
->y
, r
->width
, r
->height
);
1259 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
);
1262 OSType wxMacCreator
= 'WXMC';
1263 OSType wxMacControlProperty
= 'MCCT';
1265 void wxMacControl::SetReferenceInNativeControl()
1268 verify_noerr( SetControlProperty ( m_controlRef
,
1269 wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data
) );
1272 wxMacControl
* wxMacControl::GetReferenceFromNativeControl(ControlRef control
)
1274 wxMacControl
* ctl
= NULL
;
1275 ByteCount actualSize
;
1276 if ( GetControlProperty( control
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) ,
1277 &actualSize
, &ctl
) == noErr
)
1284 // ============================================================================
1285 // DataBrowser Wrapper
1286 // ============================================================================
1288 // basing on DataBrowserItemIDs
1291 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
1293 DataBrowserItemID itemID
,
1294 DataBrowserItemNotification message
,
1295 DataBrowserItemDataRef itemData
)
1297 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1300 ctl
->ItemNotification(itemID
, message
, itemData
);
1304 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
1306 DataBrowserItemID itemID
,
1307 DataBrowserPropertyID property
,
1308 DataBrowserItemDataRef itemData
,
1309 Boolean changeValue
)
1311 OSStatus err
= errDataBrowserPropertyNotSupported
;
1312 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1315 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
1320 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
1322 DataBrowserItemID itemOneID
,
1323 DataBrowserItemID itemTwoID
,
1324 DataBrowserPropertyID sortProperty
)
1326 wxMacDataBrowserControl
* ctl
= dynamic_cast<wxMacDataBrowserControl
*>( wxMacControl::GetReferenceFromNativeControl( browser
) );
1329 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
1334 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
1335 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
1336 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
1338 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) : wxMacControl( peer
)
1340 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
1341 OSStatus err
= ::CreateDataBrowserControl(
1342 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
1343 &bounds
, kDataBrowserListView
, &m_controlRef
);
1344 SetReferenceInNativeControl();
1345 verify_noerr( err
);
1346 if ( gDataBrowserItemCompareUPP
== NULL
)
1347 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
1348 if ( gDataBrowserItemDataUPP
== NULL
)
1349 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
1350 if ( gDataBrowserItemNotificationUPP
== NULL
)
1352 gDataBrowserItemNotificationUPP
=
1353 #if TARGET_API_MAC_OSX
1354 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
1356 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc
);
1360 DataBrowserCallbacks callbacks
;
1361 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
1363 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
1364 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
1365 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
1366 SetCallbacks( &callbacks
);
1370 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
1372 DataBrowserItemState state
,
1373 ItemCount
*numItems
) const
1375 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
1378 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
1380 DataBrowserItemState state
,
1383 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
1386 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1388 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
1391 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1392 DataBrowserTableViewColumnIndex position
)
1394 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
1397 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
){
1398 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
1401 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
1403 DataBrowserTableViewColumnID id
;
1404 GetColumnIDFromIndex( position
, &id
);
1405 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
1408 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
1410 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
1413 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
1415 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
1418 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1420 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
1423 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
1425 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1428 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
1430 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1433 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
1435 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
1438 OSStatus
wxMacDataBrowserControl::UpdateItems(
1439 DataBrowserItemID container
,
1441 const DataBrowserItemID
*items
,
1442 DataBrowserPropertyID preSortProperty
,
1443 DataBrowserPropertyID propertyID
) const
1445 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
1448 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
1450 return IsDataBrowserItemSelected( m_controlRef
, item
);
1453 OSStatus
wxMacDataBrowserControl::AddItems(
1454 DataBrowserItemID container
,
1456 const DataBrowserItemID
*items
,
1457 DataBrowserPropertyID preSortProperty
)
1459 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1462 OSStatus
wxMacDataBrowserControl::RemoveItems(
1463 DataBrowserItemID container
,
1465 const DataBrowserItemID
*items
,
1466 DataBrowserPropertyID preSortProperty
)
1468 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1471 OSStatus
wxMacDataBrowserControl::RevealItem(
1472 DataBrowserItemID item
,
1473 DataBrowserPropertyID propertyID
,
1474 DataBrowserRevealOptions options
) const
1476 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
1479 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
1481 const DataBrowserItemID
*items
,
1482 DataBrowserSetOption operation
)
1484 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
1487 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
1489 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
1492 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
1494 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
1497 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
1499 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
1502 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
1504 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1507 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
1509 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1512 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
1514 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1517 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
1519 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1522 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
1524 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1527 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
1529 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1532 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
1534 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1537 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
1539 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1542 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
1544 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
1547 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
1548 DataBrowserTableViewColumnIndex
*position
) const
1550 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1553 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
1555 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1558 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
1560 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1563 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
1565 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1568 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
1570 return GetDataBrowserSortProperty( m_controlRef
, column
);
1573 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
1575 return SetDataBrowserSortProperty( m_controlRef
, column
);
1578 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
1580 return GetDataBrowserSortOrder( m_controlRef
, order
);
1583 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
1585 return SetDataBrowserSortOrder( m_controlRef
, order
);
1588 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
1589 DataBrowserPropertyFlags
*flags
) const
1591 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1594 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
1595 DataBrowserPropertyFlags flags
)
1597 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1600 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
1601 DataBrowserListViewHeaderDesc
*desc
) const
1603 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1606 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
1607 DataBrowserListViewHeaderDesc
*desc
)
1609 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1612 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
1613 Boolean expandableRows
)
1615 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
1618 // ============================================================================
1619 // Higher-level Databrowser
1620 // ============================================================================
1622 // basing on data item objects
1625 wxMacDataItem::wxMacDataItem()
1629 m_colId
= kTextColumnId
; // for compat with existing wx*ListBox impls.
1632 wxMacDataItem::~wxMacDataItem()
1636 void wxMacDataItem::SetOrder( SInt32 order
)
1641 SInt32
wxMacDataItem::GetOrder() const
1646 void wxMacDataItem::SetData( void* data
)
1651 void* wxMacDataItem::GetData() const
1656 short wxMacDataItem::GetColumn()
1661 void wxMacDataItem::SetColumn( short col
)
1666 void wxMacDataItem::SetLabel( const wxString
& str
)
1669 m_cfLabel
.Assign( str
, wxLocale::GetSystemEncoding());
1672 const wxString
& wxMacDataItem::GetLabel() const
1677 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*owner
,
1678 const wxMacDataItem
* rhs
,
1679 DataBrowserPropertyID sortProperty
) const
1681 const wxMacDataItem
* otherItem
= dynamic_cast<const wxMacDataItem
*>(rhs
);
1682 bool retval
= false;
1684 if ( sortProperty
== m_colId
){
1685 retval
= m_label
.CmpNoCase( otherItem
->m_label
) < 0;
1688 else if ( sortProperty
== kNumericOrderColumnId
)
1689 retval
= m_order
< otherItem
->m_order
;
1694 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*owner
,
1695 DataBrowserPropertyID property
,
1696 DataBrowserItemDataRef itemData
,
1699 OSStatus err
= errDataBrowserPropertyNotSupported
;
1702 if ( property
== m_colId
){
1703 err
= ::SetDataBrowserItemDataText( itemData
, m_cfLabel
);
1706 else if ( property
== kNumericOrderColumnId
){
1707 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
1717 // no editable props here
1726 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*owner
,
1727 DataBrowserItemNotification message
,
1728 DataBrowserItemDataRef itemData
) const
1733 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1734 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1736 m_suppressSelection
= false;
1737 m_sortOrder
= SortOrder_None
;
1738 m_clientDataItemsType
= wxClientData_None
;
1741 wxMacDataItem
* wxMacDataItemBrowserControl::CreateItem()
1743 return new wxMacDataItem();
1746 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1748 m_former
= browser
->SuppressSelection(true);
1749 m_browser
= browser
;
1752 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1754 m_browser
->SuppressSelection(m_former
);
1757 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
1759 bool former
= m_suppressSelection
;
1760 m_suppressSelection
= suppress
;
1765 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
1766 DataBrowserItemID itemTwoID
,
1767 DataBrowserPropertyID sortProperty
)
1769 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1770 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1771 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1774 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
1775 const wxMacDataItem
* itemTwo
,
1776 DataBrowserPropertyID sortProperty
)
1778 Boolean retval
= false;
1779 if ( itemOne
!= NULL
)
1780 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1784 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1785 DataBrowserItemID itemID
,
1786 DataBrowserPropertyID property
,
1787 DataBrowserItemDataRef itemData
,
1788 Boolean changeValue
)
1790 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1791 return GetSetItemData(item
, property
, itemData
, changeValue
);
1794 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1795 wxMacDataItem
* item
,
1796 DataBrowserPropertyID property
,
1797 DataBrowserItemDataRef itemData
,
1798 Boolean changeValue
)
1800 OSStatus err
= errDataBrowserPropertyNotSupported
;
1803 case kDataBrowserContainerIsClosableProperty
:
1804 case kDataBrowserContainerIsSortableProperty
:
1805 case kDataBrowserContainerIsOpenableProperty
:
1806 // right now default behaviour on these
1810 if ( item
!= NULL
){
1811 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1819 void wxMacDataItemBrowserControl::ItemNotification(
1820 DataBrowserItemID itemID
,
1821 DataBrowserItemNotification message
,
1822 DataBrowserItemDataRef itemData
)
1824 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1825 ItemNotification( item
, message
, itemData
);
1828 void wxMacDataItemBrowserControl::ItemNotification(
1829 const wxMacDataItem
* item
,
1830 DataBrowserItemNotification message
,
1831 DataBrowserItemDataRef itemData
)
1834 item
->Notification( this, message
, itemData
);
1837 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
1838 bool recurse
, DataBrowserItemState state
) const
1840 ItemCount numItems
= 0;
1841 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
1842 recurse
, state
, &numItems
) );
1846 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
1847 bool recurse
) const
1849 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
1853 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
1854 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1856 Handle handle
= NewHandle(0);
1857 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
1858 recurse
, state
, handle
) );
1860 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1862 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1863 for ( int i
= 0; i
< itemCount
; ++i
)
1865 items
.Add(itemsArray
[i
]);
1868 DisposeHandle( handle
);
1871 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
1873 DataBrowserTableViewRowIndex row
;
1874 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1875 wxASSERT( err
== noErr
);
1879 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
1881 DataBrowserItemID id
;
1882 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1883 wxASSERT( err
== noErr
);
1884 return (wxMacDataItem
*) id
;
1887 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
1888 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1890 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
1891 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1894 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
1895 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1897 unsigned int noItems
= itemArray
.GetCount();
1898 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1899 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1900 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1902 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
1903 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1907 void wxMacDataItemBrowserControl::InsertColumn(int colId
, DataBrowserPropertyType colType
,
1908 const wxString
& title
, SInt16 just
, int defaultWidth
)
1910 DataBrowserListViewColumnDesc columnDesc
;
1911 columnDesc
.headerBtnDesc
.titleOffset
= 0;
1912 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
1914 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
1915 kControlUseFontMask
| kControlUseJustMask
;
1917 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
1918 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
1919 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
1920 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
1922 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
1923 // defined for other modes?
1926 enc
= m_font
.GetEncoding();
1928 enc
= wxLocale::GetSystemEncoding();
1929 wxMacCFStringHolder cfTitle
;
1930 cfTitle
.Assign( title
, enc
);
1931 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
1933 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
1934 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
1936 columnDesc
.propertyDesc
.propertyID
= (kMinColumnId
+ colId
);
1937 columnDesc
.propertyDesc
.propertyType
= colType
;
1938 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
| kDataBrowserListViewTypeSelectColumn
;
1939 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1940 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
1943 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
1945 if (defaultWidth
> 0){
1946 SetColumnWidth(colId
, defaultWidth
);
1951 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
1953 DataBrowserPropertyID id
;
1954 GetColumnIDFromIndex(colId
, &id
);
1955 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
1958 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
1960 DataBrowserPropertyID id
;
1961 GetColumnIDFromIndex(colId
, &id
);
1963 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
1967 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1969 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
1970 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1973 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1975 unsigned int noItems
= itemArray
.GetCount();
1976 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1977 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1978 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1980 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
1981 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1985 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1987 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
1988 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
1989 verify_noerr( err
);
1992 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1994 unsigned int noItems
= itemArray
.GetCount();
1995 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1996 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1997 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1999 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
2000 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
2001 verify_noerr( err
);
2005 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
2007 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
2008 verify_noerr( err
);
2011 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
2013 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
2016 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
2018 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
2021 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
2023 unsigned int noItems
= itemArray
.GetCount();
2024 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
2025 for ( unsigned int i
= 0; i
< noItems
; ++i
)
2026 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
2028 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
2032 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
2034 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
2037 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
2039 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
2042 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
2044 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
2047 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
2049 return m_clientDataItemsType
;
2051 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
2053 m_clientDataItemsType
= clientDataItemsType
;
2056 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
2058 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);
2061 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
2063 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
2064 RemoveItem( wxMacDataBrowserRootContainer
, item
);
2067 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, const wxString
& text
, int column
)
2069 wxMacDataItem
* newItem
= CreateItem();
2070 newItem
->SetLabel( text
);
2072 newItem
->SetColumn( kMinColumnId
+ column
);
2074 if ( m_sortOrder
== SortOrder_None
)
2076 // increase the order of the lines to be shifted
2077 unsigned int lines
= MacGetCount();
2078 for ( unsigned int i
= n
; i
< lines
; ++i
)
2080 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
2081 iter
->SetOrder( iter
->GetOrder() + 1 );
2084 SInt32 frontLineOrder
= 0;
2087 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
2088 frontLineOrder
= iter
->GetOrder();
2090 newItem
->SetOrder( frontLineOrder
+ 1 );
2093 AddItem( wxMacDataBrowserRootContainer
, newItem
);
2096 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, const wxArrayString
& items
, int column
)
2098 size_t itemsCount
= items
.GetCount();
2099 if ( itemsCount
== 0 )
2102 SInt32 frontLineOrder
= 0;
2104 if ( m_sortOrder
== SortOrder_None
)
2106 // increase the order of the lines to be shifted
2107 unsigned int lines
= MacGetCount();
2108 for ( unsigned int i
= n
; i
< lines
; ++i
)
2110 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
2111 iter
->SetOrder( iter
->GetOrder() + itemsCount
);
2115 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
2116 frontLineOrder
= iter
->GetOrder();
2120 wxArrayMacDataItemPtr ids
;
2121 ids
.SetCount( itemsCount
);
2123 for ( unsigned int i
= 0; i
< itemsCount
; ++i
)
2125 wxMacDataItem
* item
= CreateItem();
2126 item
->SetLabel( items
[i
]);
2128 item
->SetColumn( kMinColumnId
+ column
);
2130 if ( m_sortOrder
== SortOrder_None
)
2131 item
->SetOrder( frontLineOrder
+ 1 + i
);
2136 AddItems( wxMacDataBrowserRootContainer
, ids
);
2139 int wxMacDataItemBrowserControl::MacAppend( const wxString
& text
)
2141 wxMacDataItem
* item
= CreateItem();
2142 item
->SetLabel( text
);
2143 if ( m_sortOrder
== SortOrder_None
)
2145 unsigned int lines
= MacGetCount();
2147 item
->SetOrder( 1 );
2150 wxMacDataItem
* frontItem
= (wxMacDataItem
*) GetItemFromLine(lines
-1);
2151 item
->SetOrder( frontItem
->GetOrder() + 1 );
2154 AddItem( wxMacDataBrowserRootContainer
, item
);
2156 return GetLineFromItem(item
);
2159 void wxMacDataItemBrowserControl::MacClear()
2161 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2162 RemoveAllItems(wxMacDataBrowserRootContainer
);
2165 void wxMacDataItemBrowserControl::MacDeselectAll()
2167 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2168 SetSelectedAllItems( kDataBrowserItemsRemove
);
2171 void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n
, bool select
, bool multi
)
2173 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
2174 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2176 if ( IsItemSelected( item
) != select
)
2179 SetSelectedItem( item
, multi
? kDataBrowserItemsAdd
: kDataBrowserItemsAssign
);
2181 SetSelectedItem( item
, kDataBrowserItemsRemove
);
2187 bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n
) const
2189 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
2190 return IsItemSelected( item
);
2193 int wxMacDataItemBrowserControl::MacGetSelection() const
2195 wxMacDataItemPtr first
, last
;
2196 GetSelectionAnchor( &first
, &last
);
2198 if ( first
!= NULL
)
2200 return GetLineFromItem( first
);
2206 int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt
& aSelections
) const
2208 aSelections
.Empty();
2209 wxArrayMacDataItemPtr selectedItems
;
2210 GetItems( wxMacDataBrowserRootContainer
, false , kDataBrowserItemIsSelected
, selectedItems
);
2212 int count
= selectedItems
.GetCount();
2214 for ( int i
= 0; i
< count
; ++i
)
2216 aSelections
.Add(GetLineFromItem(selectedItems
[i
]));
2222 void wxMacDataItemBrowserControl::MacSetString( unsigned int n
, const wxString
& text
)
2224 // as we don't store the strings we only have to issue a redraw
2225 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2226 item
->SetLabel( text
);
2227 UpdateItem( wxMacDataBrowserRootContainer
, item
, kTextColumnId
);
2230 wxString
wxMacDataItemBrowserControl::MacGetString( unsigned int n
) const
2232 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2233 return item
->GetLabel();
2236 void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n
, void * data
)
2238 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2239 item
->SetData( data
);
2240 // not displayed, therefore no Update infos to DataBrowser
2243 void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n
) const
2245 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2246 return item
->GetData();
2249 void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n
)
2251 RevealItem( GetItemFromLine( n
) , kDataBrowserRevealWithoutSelecting
);
2260 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
2262 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
2269 #ifdef __WXMAC_OSX__
2270 // snippets from Sketch Sample from Apple :
2272 #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
2275 This function locates, opens, and returns the profile reference for the calibrated
2276 Generic RGB color space. It is up to the caller to call CMCloseProfile when done
2277 with the profile reference this function returns.
2279 CMProfileRef
wxMacOpenGenericProfile()
2281 static CMProfileRef cachedRGBProfileRef
= NULL
;
2283 // we only create the profile reference once
2284 if (cachedRGBProfileRef
== NULL
)
2286 CMProfileLocation loc
;
2288 loc
.locType
= cmPathBasedProfile
;
2289 strcpy(loc
.u
.pathLoc
.path
, kGenericRGBProfilePathStr
);
2291 verify_noerr( CMOpenProfile(&cachedRGBProfileRef
, &loc
) );
2294 // clone the profile reference so that the caller has their own reference, not our cached one
2295 if (cachedRGBProfileRef
)
2296 CMCloneProfileRef(cachedRGBProfileRef
);
2298 return cachedRGBProfileRef
;
2302 Return the generic RGB color space. This is a 'get' function and the caller should
2303 not release the returned value unless the caller retains it first. Usually callers
2304 of this routine will immediately use the returned colorspace with CoreGraphics
2305 so they typically do not need to retain it themselves.
2307 This function creates the generic RGB color space once and hangs onto it so it can
2308 return it whenever this function is called.
2311 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
2313 static wxMacCFRefHolder
<CGColorSpaceRef
> genericRGBColorSpace
;
2315 if (genericRGBColorSpace
== NULL
)
2317 if ( UMAGetSystemVersion() >= 0x1040 )
2319 genericRGBColorSpace
.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) );
2323 CMProfileRef genericRGBProfile
= wxMacOpenGenericProfile();
2325 if (genericRGBProfile
)
2327 genericRGBColorSpace
.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile
) );
2329 wxASSERT_MSG( genericRGBColorSpace
!= NULL
, wxT("couldn't create the generic RGB color space") );
2331 // we opened the profile so it is up to us to close it
2332 CMCloseProfile(genericRGBProfile
);
2337 return genericRGBColorSpace
;
2343 wxMacPortSaver::wxMacPortSaver( GrafPtr port
)
2345 ::GetPort( &m_port
);
2349 wxMacPortSaver::~wxMacPortSaver()
2351 ::SetPort( m_port
);
2355 void wxMacGlobalToLocal( WindowRef window
, Point
*pt
)
2357 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
2358 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
2359 HIViewRef contentView
;
2360 // TODO check toolbar offset
2361 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
2362 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
2366 QDGlobalToLocalPoint( GetWindowPort(window
), pt
) ;
2370 void wxMacLocalToGlobal( WindowRef window
, Point
*pt
)
2372 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
2373 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
2374 HIViewRef contentView
;
2375 // TODO check toolbar offset
2376 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
2377 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
2381 QDLocalToGlobalPoint( GetWindowPort(window
), pt
) ;