1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/mac/carbon/utils.cpp
3 // Purpose: Various utilities
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
20 #include "wx/toplevel.h"
25 #include "wx/apptrait.h"
28 #include "wx/mac/uma.h"
38 #include "MoreFilesX.h"
46 #if TARGET_API_MAC_OSX
47 #include <CoreServices/CoreServices.h>
49 #include <DriverServices.h>
50 #include <Multiprocessing.h>
54 #include <Carbon/Carbon.h>
56 #include <ATSUnicode.h>
57 #include <TextCommon.h>
58 #include <TextEncodingConverter.h>
62 #include "wx/mac/private.h"
64 #if defined(__MWERKS__) && wxUSE_UNICODE
65 #if __MWERKS__ < 0x4100 || !defined(__DARWIN__)
72 // our OS version is the same in non GUI and GUI cases
73 wxOperatingSystemId
wxGetOsVersion(int *majorVsn
, int *minorVsn
)
76 Gestalt(gestaltSystemVersion
, &theSystem
);
78 if ( majorVsn
!= NULL
)
79 *majorVsn
= (theSystem
>> 8);
81 if ( minorVsn
!= NULL
)
82 *minorVsn
= (theSystem
& 0xFF);
84 #if defined( __DARWIN__ )
85 return wxOS_MAC_OSX_DARWIN
;
91 // ----------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
95 #if defined(__WXDEBUG__) && defined(__WXMAC__) && !defined(__DARWIN__) && defined(__MWERKS__) && (__MWERKS__ >= 0x2400)
97 // MetroNub stuff doesn't seem to work in CodeWarrior 5.3 Carbon builds...
99 #ifndef __MetroNubUtils__
100 #include "MetroNubUtils.h"
107 #if TARGET_API_MAC_CARBON
109 #include <CodeFragments.h>
111 extern "C" long CallUniversalProc(UniversalProcPtr theProcPtr
, ProcInfoType procInfo
, ...);
113 ProcPtr gCallUniversalProc_Proc
= NULL
;
117 static MetroNubUserEntryBlock
* gMetroNubEntry
= NULL
;
119 static long fRunOnce
= false;
122 Boolean
IsMetroNubInstalled()
129 gMetroNubEntry
= NULL
;
131 if (Gestalt(gestaltSystemVersion
, &value
) == noErr
&& value
< 0x1000)
133 // look for MetroNub's Gestalt selector
134 if (Gestalt(kMetroNubUserSignature
, &result
) == noErr
)
136 #if TARGET_API_MAC_CARBON
137 if (gCallUniversalProc_Proc
== NULL
)
139 CFragConnectionID connectionID
;
142 ProcPtr symbolAddress
;
144 CFragSymbolClass symbolClass
;
146 symbolAddress
= NULL
;
147 err
= GetSharedLibrary("\pInterfaceLib", kPowerPCCFragArch
, kFindCFrag
,
148 &connectionID
, &mainAddress
, errorString
);
152 gCallUniversalProc_Proc
= NULL
;
156 err
= FindSymbol(connectionID
, "\pCallUniversalProc",
157 (Ptr
*) &gCallUniversalProc_Proc
, &symbolClass
);
161 gCallUniversalProc_Proc
= NULL
;
168 MetroNubUserEntryBlock
* block
= (MetroNubUserEntryBlock
*)result
;
170 // make sure the version of the API is compatible
171 if (block
->apiLowVersion
<= kMetroNubUserAPIVersion
&&
172 kMetroNubUserAPIVersion
<= block
->apiHiVersion
)
175 gMetroNubEntry
= block
;
184 #if TARGET_API_MAC_CARBON
185 return (gMetroNubEntry
!= NULL
&& gCallUniversalProc_Proc
!= NULL
);
187 return (gMetroNubEntry
!= NULL
);
191 Boolean
IsMWDebuggerRunning()
193 if (IsMetroNubInstalled())
194 return CallIsDebuggerRunningProc(gMetroNubEntry
->isDebuggerRunning
);
199 Boolean
AmIBeingMWDebugged()
201 if (IsMetroNubInstalled())
202 return CallAmIBeingDebuggedProc(gMetroNubEntry
->amIBeingDebugged
);
207 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
209 return IsMWDebuggerRunning() && AmIBeingMWDebugged();
214 extern bool WXDLLEXPORT
wxIsDebuggerRunning()
219 #endif // defined(__WXMAC__) && !defined(__DARWIN__) && (__MWERKS__ >= 0x2400)
223 // defined in unix/utilsunx.cpp for Mac OS X
225 // get full hostname (with domain name if possible)
226 bool wxGetFullHostName(wxChar
*buf
, int maxSize
)
228 return wxGetHostName(buf
, maxSize
);
231 // Get user ID e.g. jacs
232 bool wxGetUserId(wxChar
*buf
, int maxSize
)
234 return wxGetUserName( buf
, maxSize
);
237 const wxChar
* wxGetHomeDir(wxString
*pstr
)
239 *pstr
= wxMacFindFolder( (short) kOnSystemDisk
, kPreferencesFolderType
, kDontCreateFolder
);
240 return pstr
->c_str();
243 // Get hostname only (without domain name)
244 bool wxGetHostName(wxChar
*buf
, int maxSize
)
246 // Gets Chooser name of user by examining a System resource.
249 const short kComputerNameID
= -16413;
251 short oldResFile
= CurResFile();
253 StringHandle chooserName
= (StringHandle
)::GetString(kComputerNameID
);
254 UseResFile(oldResFile
);
256 if (chooserName
&& *chooserName
)
258 HLock( (Handle
) chooserName
);
259 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
260 HUnlock( (Handle
) chooserName
);
261 ReleaseResource( (Handle
) chooserName
);
262 wxStrncpy( buf
, name
, maxSize
- 1 );
268 // Get user name e.g. Stefan Csomor
269 bool wxGetUserName(wxChar
*buf
, int maxSize
)
271 // Gets Chooser name of user by examining a System resource.
274 const short kChooserNameID
= -16096;
276 short oldResFile
= CurResFile();
278 StringHandle chooserName
= (StringHandle
)::GetString(kChooserNameID
);
279 UseResFile(oldResFile
);
281 if (chooserName
&& *chooserName
)
283 HLock( (Handle
) chooserName
);
284 wxString name
= wxMacMakeStringFromPascal( *chooserName
);
285 HUnlock( (Handle
) chooserName
);
286 ReleaseResource( (Handle
) chooserName
);
287 wxStrncpy( buf
, name
, maxSize
- 1 );
293 int wxKill(long pid
, wxSignal sig
, wxKillError
*rc
, int flags
)
299 WXDLLEXPORT
bool wxGetEnv(const wxString
& var
, wxString
*value
)
301 // TODO : under classic there is no environement support, under X yes
305 // set the env var name to the given value, return true on success
306 WXDLLEXPORT
bool wxSetEnv(const wxString
& var
, const wxChar
*value
)
308 // TODO : under classic there is no environement support, under X yes
312 // Execute a program in an Interactive Shell
313 bool wxShell(const wxString
& command
)
319 // Shutdown or reboot the PC
320 bool wxShutdown(wxShutdownFlags wFlags
)
326 // Get free memory in bytes, or -1 if cannot determine amount (e.g. on UNIX)
327 wxMemorySize
wxGetFreeMemory()
329 return (wxMemorySize
)FreeMem();
334 void wxMicroSleep(unsigned long microseconds
)
336 AbsoluteTime wakeup
= AddDurationToAbsolute( microseconds
* durationMicrosecond
, UpTime());
337 MPDelayUntil( & wakeup
);
340 void wxMilliSleep(unsigned long milliseconds
)
342 AbsoluteTime wakeup
= AddDurationToAbsolute( milliseconds
, UpTime());
343 MPDelayUntil( & wakeup
);
346 void wxSleep(int nSecs
)
348 wxMilliSleep(1000*nSecs
);
353 // Consume all events until no more left
358 #endif // !__DARWIN__
373 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
375 // We suppose that toolkit version is the same as OS version under Mac
376 wxGetOsVersion(verMaj
, verMin
);
381 // Reading and writing resources (eg WIN.INI, .Xdefaults)
383 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, const wxString
& value
, const wxString
& file
)
389 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, float value
, const wxString
& file
)
392 buf
.Printf(wxT("%.4f"), value
);
394 return wxWriteResource(section
, entry
, buf
, file
);
397 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, long value
, const wxString
& file
)
400 buf
.Printf(wxT("%ld"), value
);
402 return wxWriteResource(section
, entry
, buf
, file
);
405 bool wxWriteResource(const wxString
& section
, const wxString
& entry
, int value
, const wxString
& file
)
408 buf
.Printf(wxT("%d"), value
);
410 return wxWriteResource(section
, entry
, buf
, file
);
413 bool wxGetResource(const wxString
& section
, const wxString
& entry
, char **value
, const wxString
& file
)
419 bool wxGetResource(const wxString
& section
, const wxString
& entry
, float *value
, const wxString
& file
)
422 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
425 *value
= (float)strtod(s
, NULL
);
432 bool wxGetResource(const wxString
& section
, const wxString
& entry
, long *value
, const wxString
& file
)
435 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
438 *value
= strtol(s
, NULL
, 10);
445 bool wxGetResource(const wxString
& section
, const wxString
& entry
, int *value
, const wxString
& file
)
448 bool succ
= wxGetResource(section
, entry
, (char **)&s
, file
);
451 *value
= (int)strtol(s
, NULL
, 10);
457 #endif // wxUSE_RESOURCES
459 int gs_wxBusyCursorCount
= 0;
460 extern wxCursor gMacCurrentCursor
;
461 wxCursor gMacStoredActiveCursor
;
463 // Set the cursor to the busy cursor for all windows
464 void wxBeginBusyCursor(const wxCursor
*cursor
)
466 if (gs_wxBusyCursorCount
++ == 0)
468 gMacStoredActiveCursor
= gMacCurrentCursor
;
469 cursor
->MacInstall();
471 //else: nothing to do, already set
474 // Restore cursor to normal
475 void wxEndBusyCursor()
477 wxCHECK_RET( gs_wxBusyCursorCount
> 0,
478 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
480 if (--gs_wxBusyCursorCount
== 0)
482 gMacStoredActiveCursor
.MacInstall();
483 gMacStoredActiveCursor
= wxNullCursor
;
487 // true if we're between the above two calls
490 return (gs_wxBusyCursorCount
> 0);
497 wxString
wxMacFindFolderNoSeparator( short vol
,
499 Boolean createFolder
)
504 if ( FSFindFolder( vol
, folderType
, createFolder
, &fsRef
) == noErr
)
506 strDir
= wxMacFSRefToPath( &fsRef
);
512 wxString
wxMacFindFolder( short vol
,
514 Boolean createFolder
)
516 return wxMacFindFolderNoSeparator(vol
, folderType
, createFolder
) + wxFILE_SEP_PATH
;
523 // Check whether this window wants to process messages, e.g. Stop button
524 // in long calculations.
525 bool wxCheckForInterrupt(wxWindow
*wnd
)
531 void wxGetMousePosition( int* x
, int* y
)
534 #if wxMAC_USE_CORE_GRAPHICS
538 LocalToGlobal( &pt
);
544 // Return true if we have a colour display
545 bool wxColourDisplay()
550 // Returns depth of screen
554 #if wxMAC_USE_CORE_GRAPHICS
555 theDepth
= (int) CGDisplayBitsPerPixel(CGMainDisplayID());
558 SetRect(&globRect
, -32760, -32760, 32760, 32760);
559 GDHandle theMaxDevice
;
561 theMaxDevice
= GetMaxDevice(&globRect
);
562 if (theMaxDevice
!= NULL
)
563 theDepth
= (**(**theMaxDevice
).gdPMap
).pixelSize
;
568 // Get size of display
569 void wxDisplaySize(int *width
, int *height
)
571 #if wxMAC_USE_CORE_GRAPHICS
572 // TODO adapt for multi-displays
573 CGRect bounds
= CGDisplayBounds(CGMainDisplayID());
575 *width
= (int)bounds
.size
.width
;
577 *height
= (int)bounds
.size
.height
;
580 GetQDGlobalsScreenBits( &screenBits
);
583 *width
= screenBits
.bounds
.right
- screenBits
.bounds
.left
;
586 *height
= screenBits
.bounds
.bottom
- screenBits
.bounds
.top
;
590 void wxDisplaySizeMM(int *width
, int *height
)
592 wxDisplaySize(width
, height
);
593 // on mac 72 is fixed (at least now;-)
594 float cvPt2Mm
= 25.4 / 72;
597 *width
= int( *width
* cvPt2Mm
);
600 *height
= int( *height
* cvPt2Mm
);
603 void wxClientDisplayRect(int *x
, int *y
, int *width
, int *height
)
605 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5
607 HIWindowGetAvailablePositioningBounds(kCGNullDirectDisplay
,kHICoordSpace72DPIGlobal
,
610 *x
= bounds
.origin
.x
;
612 *y
= bounds
.origin
.y
;
614 *width
= bounds
.size
.width
;
616 *height
= bounds
.size
.height
;
619 GetAvailableWindowPositioningBounds( GetMainDevice() , &r
);
625 *width
= r
.right
- r
.left
;
627 *height
= r
.bottom
- r
.top
;
631 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
633 return wxGenericFindWindowAtPoint(pt
);
640 wxString
wxGetOsDescription()
642 #ifdef WXWIN_OS_DESCRIPTION
643 // use configure generated description if available
644 return wxString(wxT("MacOS (")) + wxT(WXWIN_OS_DESCRIPTION
) + wxString(wxT(")"));
646 return wxT("MacOS"); //TODO:define further
651 wxChar
*wxGetUserHome (const wxString
& user
)
657 bool wxGetDiskSpace(const wxString
& path
, wxDiskspaceSize_t
*pTotal
, wxDiskspaceSize_t
*pFree
)
666 int pos
= p
.Find(':');
667 if ( pos
!= wxNOT_FOUND
)
675 err
= wxMacPathToFSRef( p
, &fsRef
);
678 FSVolumeRefNum vRefNum
;
679 err
= FSGetVRefNum( &fsRef
, &vRefNum
);
682 UInt64 freeBytes
, totalBytes
;
683 err
= FSGetVInfo( vRefNum
, NULL
, &freeBytes
, &totalBytes
);
687 *pTotal
= wxDiskspaceSize_t( totalBytes
);
689 *pFree
= wxDiskspaceSize_t( freeBytes
);
696 #endif // !__DARWIN__
698 //---------------------------------------------------------------------------
699 // wxMac Specific utility functions
700 //---------------------------------------------------------------------------
702 void wxMacStringToPascal( const wxString
&from
, StringPtr to
)
704 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
705 int len
= strlen(buf
);
710 memcpy( (char*) &to
[1] , buf
, len
);
713 wxString
wxMacMakeStringFromPascal( ConstStringPtr from
)
715 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
718 // ----------------------------------------------------------------------------
719 // Common Event Support
720 // ----------------------------------------------------------------------------
722 extern ProcessSerialNumber gAppProcess
;
726 ProcessSerialNumber psn
;
728 psn
.highLongOfPSN
= 0;
729 psn
.lowLongOfPSN
= kCurrentProcess
;
730 SameProcess( &gAppProcess
, &psn
, &isSame
);
734 OSStatus err
= noErr
;
737 // lead sometimes to race conditions, although all calls used should be thread safe ...
738 static wxMacCarbonEvent s_wakeupEvent
;
739 if ( !s_wakeupEvent
.IsValid() )
741 err
= s_wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
742 kEventAttributeNone
);
747 if ( IsEventInQueue( GetMainEventQueue() , s_wakeupEvent
) )
749 s_wakeupEvent
.SetCurrentTime();
750 err
= PostEventToQueue(GetMainEventQueue(), s_wakeupEvent
,
751 kEventPriorityHigh
);
754 wxMacCarbonEvent wakeupEvent
;
755 wakeupEvent
.Create( 'WXMC', 'WXMC', GetCurrentEventTime(),
756 kEventAttributeNone
);
757 err
= PostEventToQueue(GetMainEventQueue(), wakeupEvent
,
758 kEventPriorityHigh
);
761 PostEvent( nullEvent
, 0 );
766 WakeUpProcess( &gAppProcess
);
774 // ----------------------------------------------------------------------------
775 // Native Struct Conversions
776 // ----------------------------------------------------------------------------
778 void wxMacRectToNative( const wxRect
*wx
, Rect
*n
)
782 n
->right
= wx
->x
+ wx
->width
;
783 n
->bottom
= wx
->y
+ wx
->height
;
786 void wxMacNativeToRect( const Rect
*n
, wxRect
* wx
)
790 wx
->width
= n
->right
- n
->left
;
791 wx
->height
= n
->bottom
- n
->top
;
794 void wxMacPointToNative( const wxPoint
* wx
, Point
*n
)
800 void wxMacNativeToPoint( const Point
*n
, wxPoint
* wx
)
806 // ----------------------------------------------------------------------------
807 // Carbon Event Support
808 // ----------------------------------------------------------------------------
810 OSStatus
wxMacCarbonEvent::GetParameter(EventParamName inName
, EventParamType inDesiredType
, UInt32 inBufferSize
, void * outData
)
812 return ::GetEventParameter( m_eventRef
, inName
, inDesiredType
, NULL
, inBufferSize
, NULL
, outData
);
815 OSStatus
wxMacCarbonEvent::SetParameter(EventParamName inName
, EventParamType inType
, UInt32 inBufferSize
, const void * inData
)
817 return ::SetEventParameter( m_eventRef
, inName
, inType
, inBufferSize
, inData
);
820 // ----------------------------------------------------------------------------
821 // Control Access Support
822 // ----------------------------------------------------------------------------
824 IMPLEMENT_DYNAMIC_CLASS( wxMacControl
, wxObject
)
826 wxMacControl::wxMacControl()
831 wxMacControl::wxMacControl(wxWindow
* peer
, bool isRootControl
)
835 m_isRootControl
= isRootControl
;
838 wxMacControl::wxMacControl( wxWindow
* peer
, ControlRef control
)
842 m_controlRef
= control
;
845 wxMacControl::wxMacControl( wxWindow
* peer
, WXWidget control
)
849 m_controlRef
= (ControlRef
) control
;
852 wxMacControl::~wxMacControl()
856 void wxMacControl::Init()
860 m_needsFocusRect
= false;
861 m_isRootControl
= false;
864 void wxMacControl::Dispose()
866 wxASSERT_MSG( IsValidControlHandle(m_controlRef
) , wxT("Invalid Control Handle (maybe already released) in Dispose") );
868 // we cannot check the ref count here anymore, as autorelease objects might delete their refs later
869 CFRelease(m_controlRef
);
873 void wxMacControl::SetReference( URefCon data
)
875 SetControlReference( m_controlRef
, data
);
878 OSStatus
wxMacControl::GetData(ControlPartCode inPartCode
, ResType inTag
, Size inBufferSize
, void * inOutBuffer
, Size
* outActualSize
) const
880 return ::GetControlData( m_controlRef
, inPartCode
, inTag
, inBufferSize
, inOutBuffer
, outActualSize
);
883 OSStatus
wxMacControl::GetDataSize(ControlPartCode inPartCode
, ResType inTag
, Size
* outActualSize
) const
885 return ::GetControlDataSize( m_controlRef
, inPartCode
, inTag
, outActualSize
);
888 OSStatus
wxMacControl::SetData(ControlPartCode inPartCode
, ResType inTag
, Size inSize
, const void * inData
)
890 return ::SetControlData( m_controlRef
, inPartCode
, inTag
, inSize
, inData
);
893 OSStatus
wxMacControl::SendEvent( EventRef event
, OptionBits inOptions
)
895 #if TARGET_API_MAC_OSX
896 return SendEventToEventTargetWithOptions( event
,
897 HIObjectGetEventTarget( (HIObjectRef
) m_controlRef
), inOptions
);
899 #pragma unused(inOptions)
900 return SendEventToEventTarget(event
,GetControlEventTarget( m_controlRef
) );
904 OSStatus
wxMacControl::SendHICommand( HICommand
&command
, OptionBits inOptions
)
906 wxMacCarbonEvent
event( kEventClassCommand
, kEventCommandProcess
);
908 event
.SetParameter
<HICommand
>(kEventParamDirectObject
,command
);
910 return SendEvent( event
, inOptions
);
913 OSStatus
wxMacControl::SendHICommand( UInt32 commandID
, OptionBits inOptions
)
917 memset( &command
, 0 , sizeof(command
) );
918 command
.commandID
= commandID
;
919 return SendHICommand( command
, inOptions
);
922 void wxMacControl::Flash( ControlPartCode part
, UInt32 ticks
)
924 unsigned long finalTicks
;
926 HiliteControl( m_controlRef
, part
);
927 Delay( ticks
, &finalTicks
);
928 HiliteControl( m_controlRef
, kControlNoPart
);
931 SInt32
wxMacControl::GetValue() const
933 return ::GetControl32BitValue( m_controlRef
);
936 SInt32
wxMacControl::GetMaximum() const
938 return ::GetControl32BitMaximum( m_controlRef
);
941 SInt32
wxMacControl::GetMinimum() const
943 return ::GetControl32BitMinimum( m_controlRef
);
946 void wxMacControl::SetValue( SInt32 v
)
948 ::SetControl32BitValue( m_controlRef
, v
);
951 void wxMacControl::SetMinimum( SInt32 v
)
953 ::SetControl32BitMinimum( m_controlRef
, v
);
956 void wxMacControl::SetMaximum( SInt32 v
)
958 ::SetControl32BitMaximum( m_controlRef
, v
);
961 void wxMacControl::SetValueAndRange( SInt32 value
, SInt32 minimum
, SInt32 maximum
)
963 ::SetControl32BitMinimum( m_controlRef
, minimum
);
964 ::SetControl32BitMaximum( m_controlRef
, maximum
);
965 ::SetControl32BitValue( m_controlRef
, value
);
968 OSStatus
wxMacControl::SetFocus( ControlFocusPart focusPart
)
970 return SetKeyboardFocus( GetControlOwner( m_controlRef
), m_controlRef
, focusPart
);
973 bool wxMacControl::HasFocus() const
976 GetKeyboardFocus( GetUserFocusWindow() , &control
);
977 return control
== m_controlRef
;
980 void wxMacControl::SetNeedsFocusRect( bool needs
)
982 m_needsFocusRect
= needs
;
985 bool wxMacControl::NeedsFocusRect() const
987 return m_needsFocusRect
;
990 void wxMacControl::VisibilityChanged(bool shown
)
994 void wxMacControl::SuperChangedPosition()
998 void wxMacControl::SetFont( const wxFont
& font
, const wxColour
& foreground
, long windowStyle
)
1001 ControlFontStyleRec fontStyle
;
1002 if ( font
.MacGetThemeFontID() != kThemeCurrentPortFont
)
1004 switch ( font
.MacGetThemeFontID() )
1006 case kThemeSmallSystemFont
:
1007 fontStyle
.font
= kControlFontSmallSystemFont
;
1010 case 109 : // mini font
1011 fontStyle
.font
= -5;
1014 case kThemeSystemFont
:
1015 fontStyle
.font
= kControlFontBigSystemFont
;
1019 fontStyle
.font
= kControlFontBigSystemFont
;
1023 fontStyle
.flags
= kControlUseFontMask
;
1027 fontStyle
.font
= font
.MacGetFontNum();
1028 fontStyle
.style
= font
.MacGetFontStyle();
1029 fontStyle
.size
= font
.MacGetFontSize();
1030 fontStyle
.flags
= kControlUseFontMask
| kControlUseFaceMask
| kControlUseSizeMask
;
1033 fontStyle
.just
= teJustLeft
;
1034 fontStyle
.flags
|= kControlUseJustMask
;
1035 if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_CENTER_HORIZONTAL
)
1036 fontStyle
.just
= teJustCenter
;
1037 else if ( ( windowStyle
& wxALIGN_MASK
) & wxALIGN_RIGHT
)
1038 fontStyle
.just
= teJustRight
;
1041 // we only should do this in case of a non-standard color, as otherwise 'disabled' controls
1042 // won't get grayed out by the system anymore
1044 if ( foreground
!= *wxBLACK
)
1046 fontStyle
.foreColor
= MAC_WXCOLORREF( foreground
.GetPixel() );
1047 fontStyle
.flags
|= kControlUseForeColorMask
;
1050 ::SetControlFontStyle( m_controlRef
, &fontStyle
);
1053 void wxMacControl::SetBackground( const wxBrush
&WXUNUSED(brush
) )
1056 // setting up a color proc is not recommended anymore
1059 void wxMacControl::SetRange( SInt32 minimum
, SInt32 maximum
)
1061 ::SetControl32BitMinimum( m_controlRef
, minimum
);
1062 ::SetControl32BitMaximum( m_controlRef
, maximum
);
1065 short wxMacControl::HandleKey( SInt16 keyCode
, SInt16 charCode
, EventModifiers modifiers
)
1068 return HandleControlKey( m_controlRef
, keyCode
, charCode
, modifiers
);
1074 void wxMacControl::SetActionProc( ControlActionUPP actionProc
)
1076 SetControlAction( m_controlRef
, actionProc
);
1079 void wxMacControl::SetViewSize( SInt32 viewSize
)
1081 SetControlViewSize(m_controlRef
, viewSize
);
1084 SInt32
wxMacControl::GetViewSize() const
1086 return GetControlViewSize( m_controlRef
);
1089 bool wxMacControl::IsVisible() const
1091 return IsControlVisible( m_controlRef
);
1094 void wxMacControl::SetVisibility( bool visible
, bool redraw
)
1096 SetControlVisibility( m_controlRef
, visible
, redraw
);
1099 bool wxMacControl::IsEnabled() const
1101 #if TARGET_API_MAC_OSX
1102 return IsControlEnabled( m_controlRef
);
1104 return IsControlActive( m_controlRef
);
1108 bool wxMacControl::IsActive() const
1110 return IsControlActive( m_controlRef
);
1113 void wxMacControl::Enable( bool enable
)
1116 EnableControl( m_controlRef
);
1118 DisableControl( m_controlRef
);
1121 void wxMacControl::SetDrawingEnabled( bool enable
)
1123 HIViewSetDrawingEnabled( m_controlRef
, enable
);
1126 bool wxMacControl::GetNeedsDisplay() const
1128 return HIViewGetNeedsDisplay( m_controlRef
);
1131 void wxMacControl::SetNeedsDisplay( RgnHandle where
)
1136 HIViewSetNeedsDisplayInRegion( m_controlRef
, where
, true );
1139 void wxMacControl::SetNeedsDisplay( Rect
* where
)
1144 if ( where
!= NULL
)
1146 RgnHandle update
= NewRgn();
1147 RectRgn( update
, where
);
1148 HIViewSetNeedsDisplayInRegion( m_controlRef
, update
, true );
1149 DisposeRgn( update
);
1152 HIViewSetNeedsDisplay( m_controlRef
, true );
1155 void wxMacControl::Convert( wxPoint
*pt
, wxMacControl
*from
, wxMacControl
*to
)
1161 HIViewConvertPoint( &hiPoint
, from
->m_controlRef
, to
->m_controlRef
);
1162 pt
->x
= (int)hiPoint
.x
;
1163 pt
->y
= (int)hiPoint
.y
;
1166 void wxMacControl::SetRect( Rect
*r
)
1168 //A HIRect is actually a CGRect on OSX - which consists of two structures -
1169 //CGPoint and CGSize, which have two floats each
1170 HIRect hir
= { { r
->left
, r
->top
}, { r
->right
- r
->left
, r
->bottom
- r
->top
} };
1171 HIViewSetFrame ( m_controlRef
, &hir
);
1172 // eventuall we might have to do a SetVisibility( false , true );
1173 // before and a SetVisibility( true , true ); after
1176 void wxMacControl::GetRect( Rect
*r
)
1178 GetControlBounds( m_controlRef
, r
);
1181 void wxMacControl::GetRectInWindowCoords( Rect
*r
)
1183 UMAGetControlBoundsInWindowCoords( m_controlRef
, r
);
1186 void wxMacControl::GetBestRect( Rect
*r
)
1188 short baselineoffset
;
1190 GetBestControlRect( m_controlRef
, r
, &baselineoffset
);
1193 void wxMacControl::SetLabel( const wxString
&title
)
1195 wxFontEncoding encoding
;
1198 encoding
= m_font
.GetEncoding();
1200 encoding
= wxFont::GetDefaultEncoding();
1202 UMASetControlTitle( m_controlRef
, title
, encoding
);
1205 void wxMacControl::GetFeatures( UInt32
* features
)
1207 GetControlFeatures( m_controlRef
, features
);
1210 OSStatus
wxMacControl::GetRegion( ControlPartCode partCode
, RgnHandle region
)
1212 OSStatus err
= GetControlRegion( m_controlRef
, partCode
, region
);
1216 OSStatus
wxMacControl::SetZOrder( bool above
, wxMacControl
* other
)
1218 #if TARGET_API_MAC_OSX
1219 return HIViewSetZOrder( m_controlRef
,above
? kHIViewZOrderAbove
: kHIViewZOrderBelow
,
1220 (other
!= NULL
) ? other
->m_controlRef
: NULL
);
1226 #if TARGET_API_MAC_OSX
1227 // SetNeedsDisplay would not invalidate the children
1228 static void InvalidateControlAndChildren( HIViewRef control
)
1230 HIViewSetNeedsDisplay( control
, true );
1231 UInt16 childrenCount
= 0;
1232 OSStatus err
= CountSubControls( control
, &childrenCount
);
1233 if ( err
== errControlIsNotEmbedder
)
1236 wxASSERT_MSG( err
== noErr
, wxT("Unexpected error when accessing subcontrols") );
1238 for ( UInt16 i
= childrenCount
; i
>=1; --i
)
1242 err
= GetIndexedSubControl( control
, i
, & child
);
1243 if ( err
== errControlIsNotEmbedder
)
1246 InvalidateControlAndChildren( child
);
1251 void wxMacControl::InvalidateWithChildren()
1253 #if TARGET_API_MAC_OSX
1254 InvalidateControlAndChildren( m_controlRef
);
1258 void wxMacControl::ScrollRect( wxRect
*r
, int dx
, int dy
)
1260 wxASSERT( r
!= NULL
);
1262 HIRect scrollarea
= CGRectMake( r
->x
, r
->y
, r
->width
, r
->height
);
1263 HIViewScrollRect ( m_controlRef
, &scrollarea
, dx
,dy
);
1266 OSType wxMacCreator
= 'WXMC';
1267 OSType wxMacControlProperty
= 'MCCT';
1269 void wxMacControl::SetReferenceInNativeControl()
1272 verify_noerr( SetControlProperty ( m_controlRef
,
1273 wxMacCreator
,wxMacControlProperty
, sizeof(data
), &data
) );
1276 wxMacControl
* wxMacControl::GetReferenceFromNativeControl(ControlRef control
)
1278 wxMacControl
* ctl
= NULL
;
1279 ByteCount actualSize
;
1280 if ( GetControlProperty( control
,wxMacCreator
,wxMacControlProperty
, sizeof(ctl
) ,
1281 &actualSize
, &ctl
) == noErr
)
1288 // ============================================================================
1289 // DataBrowser Wrapper
1290 // ============================================================================
1292 // basing on DataBrowserItemIDs
1295 IMPLEMENT_ABSTRACT_CLASS( wxMacDataBrowserControl
, wxMacControl
)
1297 pascal void wxMacDataBrowserControl::DataBrowserItemNotificationProc(
1299 DataBrowserItemID itemID
,
1300 DataBrowserItemNotification message
,
1301 DataBrowserItemDataRef itemData
)
1303 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
1306 ctl
->ItemNotification(itemID
, message
, itemData
);
1310 pascal OSStatus
wxMacDataBrowserControl::DataBrowserGetSetItemDataProc(
1312 DataBrowserItemID itemID
,
1313 DataBrowserPropertyID property
,
1314 DataBrowserItemDataRef itemData
,
1315 Boolean changeValue
)
1317 OSStatus err
= errDataBrowserPropertyNotSupported
;
1318 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
1321 err
= ctl
->GetSetItemData(itemID
, property
, itemData
, changeValue
);
1326 pascal Boolean
wxMacDataBrowserControl::DataBrowserCompareProc(
1328 DataBrowserItemID itemOneID
,
1329 DataBrowserItemID itemTwoID
,
1330 DataBrowserPropertyID sortProperty
)
1332 wxMacDataBrowserControl
* ctl
= wxDynamicCast(wxMacControl::GetReferenceFromNativeControl( browser
), wxMacDataBrowserControl
);
1335 return ctl
->CompareItems(itemOneID
, itemTwoID
, sortProperty
);
1340 DataBrowserItemDataUPP gDataBrowserItemDataUPP
= NULL
;
1341 DataBrowserItemNotificationUPP gDataBrowserItemNotificationUPP
= NULL
;
1342 DataBrowserItemCompareUPP gDataBrowserItemCompareUPP
= NULL
;
1344 wxMacDataBrowserControl::wxMacDataBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) : wxMacControl( peer
)
1346 Rect bounds
= wxMacGetBoundsForControl( peer
, pos
, size
);
1347 OSStatus err
= ::CreateDataBrowserControl(
1348 MAC_WXHWND(peer
->MacGetTopLevelWindowRef()),
1349 &bounds
, kDataBrowserListView
, &m_controlRef
);
1350 SetReferenceInNativeControl();
1351 verify_noerr( err
);
1352 if ( gDataBrowserItemCompareUPP
== NULL
)
1353 gDataBrowserItemCompareUPP
= NewDataBrowserItemCompareUPP(DataBrowserCompareProc
);
1354 if ( gDataBrowserItemDataUPP
== NULL
)
1355 gDataBrowserItemDataUPP
= NewDataBrowserItemDataUPP(DataBrowserGetSetItemDataProc
);
1356 if ( gDataBrowserItemNotificationUPP
== NULL
)
1358 gDataBrowserItemNotificationUPP
=
1359 #if TARGET_API_MAC_OSX
1360 (DataBrowserItemNotificationUPP
) NewDataBrowserItemNotificationWithItemUPP(DataBrowserItemNotificationProc
);
1362 NewDataBrowserItemNotificationUPP(DataBrowserItemNotificationProc
);
1366 DataBrowserCallbacks callbacks
;
1367 InitializeDataBrowserCallbacks( &callbacks
, kDataBrowserLatestCallbacks
);
1369 callbacks
.u
.v1
.itemDataCallback
= gDataBrowserItemDataUPP
;
1370 callbacks
.u
.v1
.itemCompareCallback
= gDataBrowserItemCompareUPP
;
1371 callbacks
.u
.v1
.itemNotificationCallback
= gDataBrowserItemNotificationUPP
;
1372 SetCallbacks( &callbacks
);
1376 OSStatus
wxMacDataBrowserControl::GetItemCount( DataBrowserItemID container
,
1378 DataBrowserItemState state
,
1379 ItemCount
*numItems
) const
1381 return GetDataBrowserItemCount( m_controlRef
, container
, recurse
, state
, numItems
);
1384 OSStatus
wxMacDataBrowserControl::GetItems( DataBrowserItemID container
,
1386 DataBrowserItemState state
,
1389 return GetDataBrowserItems( m_controlRef
, container
, recurse
, state
, items
);
1392 OSStatus
wxMacDataBrowserControl::SetSelectionFlags( DataBrowserSelectionFlags options
)
1394 return SetDataBrowserSelectionFlags( m_controlRef
, options
);
1397 OSStatus
wxMacDataBrowserControl::AddColumn( DataBrowserListViewColumnDesc
*columnDesc
,
1398 DataBrowserTableViewColumnIndex position
)
1400 return AddDataBrowserListViewColumn( m_controlRef
, columnDesc
, position
);
1403 OSStatus
wxMacDataBrowserControl::GetColumnIDFromIndex( DataBrowserTableViewColumnIndex position
, DataBrowserTableViewColumnID
* id
){
1404 return GetDataBrowserTableViewColumnProperty( m_controlRef
, position
, id
);
1407 OSStatus
wxMacDataBrowserControl::RemoveColumn( DataBrowserTableViewColumnIndex position
)
1409 DataBrowserTableViewColumnID id
;
1410 GetColumnIDFromIndex( position
, &id
);
1411 return RemoveDataBrowserTableViewColumn( m_controlRef
, id
);
1414 OSStatus
wxMacDataBrowserControl::AutoSizeColumns()
1416 return AutoSizeDataBrowserListViewColumns(m_controlRef
);
1419 OSStatus
wxMacDataBrowserControl::SetHasScrollBars( bool horiz
, bool vert
)
1421 return SetDataBrowserHasScrollBars( m_controlRef
, horiz
, vert
);
1424 OSStatus
wxMacDataBrowserControl::SetHiliteStyle( DataBrowserTableViewHiliteStyle hiliteStyle
)
1426 return SetDataBrowserTableViewHiliteStyle( m_controlRef
, hiliteStyle
);
1429 OSStatus
wxMacDataBrowserControl::SetHeaderButtonHeight(UInt16 height
)
1431 return SetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1434 OSStatus
wxMacDataBrowserControl::GetHeaderButtonHeight(UInt16
*height
)
1436 return GetDataBrowserListViewHeaderBtnHeight( m_controlRef
, height
);
1439 OSStatus
wxMacDataBrowserControl::SetCallbacks(const DataBrowserCallbacks
*callbacks
)
1441 return SetDataBrowserCallbacks( m_controlRef
, callbacks
);
1444 OSStatus
wxMacDataBrowserControl::UpdateItems(
1445 DataBrowserItemID container
,
1447 const DataBrowserItemID
*items
,
1448 DataBrowserPropertyID preSortProperty
,
1449 DataBrowserPropertyID propertyID
) const
1451 return UpdateDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
, propertyID
);
1454 bool wxMacDataBrowserControl::IsItemSelected( DataBrowserItemID item
) const
1456 return IsDataBrowserItemSelected( m_controlRef
, item
);
1459 OSStatus
wxMacDataBrowserControl::AddItems(
1460 DataBrowserItemID container
,
1462 const DataBrowserItemID
*items
,
1463 DataBrowserPropertyID preSortProperty
)
1465 return AddDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1468 OSStatus
wxMacDataBrowserControl::RemoveItems(
1469 DataBrowserItemID container
,
1471 const DataBrowserItemID
*items
,
1472 DataBrowserPropertyID preSortProperty
)
1474 return RemoveDataBrowserItems( m_controlRef
, container
, numItems
, items
, preSortProperty
);
1477 OSStatus
wxMacDataBrowserControl::RevealItem(
1478 DataBrowserItemID item
,
1479 DataBrowserPropertyID propertyID
,
1480 DataBrowserRevealOptions options
) const
1482 return RevealDataBrowserItem( m_controlRef
, item
, propertyID
, options
);
1485 OSStatus
wxMacDataBrowserControl::SetSelectedItems(
1487 const DataBrowserItemID
*items
,
1488 DataBrowserSetOption operation
)
1490 return SetDataBrowserSelectedItems( m_controlRef
, numItems
, items
, operation
);
1493 OSStatus
wxMacDataBrowserControl::GetSelectionAnchor( DataBrowserItemID
*first
, DataBrowserItemID
*last
) const
1495 return GetDataBrowserSelectionAnchor( m_controlRef
, first
, last
);
1498 OSStatus
wxMacDataBrowserControl::GetItemID( DataBrowserTableViewRowIndex row
, DataBrowserItemID
* item
) const
1500 return GetDataBrowserTableViewItemID( m_controlRef
, row
, item
);
1503 OSStatus
wxMacDataBrowserControl::GetItemRow( DataBrowserItemID item
, DataBrowserTableViewRowIndex
* row
) const
1505 return GetDataBrowserTableViewItemRow( m_controlRef
, item
, row
);
1508 OSStatus
wxMacDataBrowserControl::SetDefaultRowHeight( UInt16 height
)
1510 return SetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1513 OSStatus
wxMacDataBrowserControl::GetDefaultRowHeight( UInt16
* height
) const
1515 return GetDataBrowserTableViewRowHeight( m_controlRef
, height
);
1518 OSStatus
wxMacDataBrowserControl::SetRowHeight( DataBrowserItemID item
, UInt16 height
)
1520 return SetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1523 OSStatus
wxMacDataBrowserControl::GetRowHeight( DataBrowserItemID item
, UInt16
*height
) const
1525 return GetDataBrowserTableViewItemRowHeight( m_controlRef
, item
, height
);
1528 OSStatus
wxMacDataBrowserControl::GetColumnWidth( DataBrowserPropertyID column
, UInt16
*width
) const
1530 return GetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1533 OSStatus
wxMacDataBrowserControl::SetColumnWidth( DataBrowserPropertyID column
, UInt16 width
)
1535 return SetDataBrowserTableViewNamedColumnWidth( m_controlRef
, column
, width
);
1538 OSStatus
wxMacDataBrowserControl::GetDefaultColumnWidth( UInt16
*width
) const
1540 return GetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1543 OSStatus
wxMacDataBrowserControl::SetDefaultColumnWidth( UInt16 width
)
1545 return SetDataBrowserTableViewColumnWidth( m_controlRef
, width
);
1548 OSStatus
wxMacDataBrowserControl::GetColumnCount(UInt32
* numColumns
) const
1550 return GetDataBrowserTableViewColumnCount( m_controlRef
, numColumns
);
1553 OSStatus
wxMacDataBrowserControl::GetColumnPosition( DataBrowserPropertyID column
,
1554 DataBrowserTableViewColumnIndex
*position
) const
1556 return GetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1559 OSStatus
wxMacDataBrowserControl::SetColumnPosition( DataBrowserPropertyID column
, DataBrowserTableViewColumnIndex position
)
1561 return SetDataBrowserTableViewColumnPosition( m_controlRef
, column
, position
);
1564 OSStatus
wxMacDataBrowserControl::GetScrollPosition( UInt32
*top
, UInt32
*left
) const
1566 return GetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1569 OSStatus
wxMacDataBrowserControl::SetScrollPosition( UInt32 top
, UInt32 left
)
1571 return SetDataBrowserScrollPosition( m_controlRef
, top
, left
);
1574 OSStatus
wxMacDataBrowserControl::GetSortProperty( DataBrowserPropertyID
*column
) const
1576 return GetDataBrowserSortProperty( m_controlRef
, column
);
1579 OSStatus
wxMacDataBrowserControl::SetSortProperty( DataBrowserPropertyID column
)
1581 return SetDataBrowserSortProperty( m_controlRef
, column
);
1584 OSStatus
wxMacDataBrowserControl::GetSortOrder( DataBrowserSortOrder
*order
) const
1586 return GetDataBrowserSortOrder( m_controlRef
, order
);
1589 OSStatus
wxMacDataBrowserControl::SetSortOrder( DataBrowserSortOrder order
)
1591 return SetDataBrowserSortOrder( m_controlRef
, order
);
1594 OSStatus
wxMacDataBrowserControl::GetPropertyFlags( DataBrowserPropertyID property
,
1595 DataBrowserPropertyFlags
*flags
) const
1597 return GetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1600 OSStatus
wxMacDataBrowserControl::SetPropertyFlags( DataBrowserPropertyID property
,
1601 DataBrowserPropertyFlags flags
)
1603 return SetDataBrowserPropertyFlags( m_controlRef
, property
, flags
);
1606 OSStatus
wxMacDataBrowserControl::GetHeaderDesc( DataBrowserPropertyID property
,
1607 DataBrowserListViewHeaderDesc
*desc
) const
1609 return GetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1612 OSStatus
wxMacDataBrowserControl::SetHeaderDesc( DataBrowserPropertyID property
,
1613 DataBrowserListViewHeaderDesc
*desc
)
1615 return SetDataBrowserListViewHeaderDesc( m_controlRef
, property
, desc
);
1618 OSStatus
wxMacDataBrowserControl::SetDisclosureColumn( DataBrowserPropertyID property
,
1619 Boolean expandableRows
)
1621 return SetDataBrowserListViewDisclosureColumn( m_controlRef
, property
, expandableRows
);
1624 // ============================================================================
1625 // Higher-level Databrowser
1626 // ============================================================================
1628 // basing on data item objects
1631 wxMacDataItem::wxMacDataItem()
1636 m_colId
= kTextColumnId
; // for compat with existing wx*ListBox impls.
1639 wxMacDataItem::~wxMacDataItem()
1643 void wxMacDataItem::SetOrder( SInt32 order
)
1648 SInt32
wxMacDataItem::GetOrder() const
1653 void wxMacDataItem::SetData( void* data
)
1658 void* wxMacDataItem::GetData() const
1663 short wxMacDataItem::GetColumn()
1668 void wxMacDataItem::SetColumn( short col
)
1673 void wxMacDataItem::SetLabel( const wxString
& str
)
1676 m_cfLabel
.Assign( str
, wxLocale::GetSystemEncoding());
1679 const wxString
& wxMacDataItem::GetLabel() const
1684 bool wxMacDataItem::IsLessThan(wxMacDataItemBrowserControl
*owner
,
1685 const wxMacDataItem
* rhs
,
1686 DataBrowserPropertyID sortProperty
) const
1688 const wxMacDataItem
* otherItem
= wx_const_cast(wxMacDataItem
*,rhs
);
1689 bool retval
= false;
1691 if ( sortProperty
== m_colId
){
1692 retval
= m_label
.CmpNoCase( otherItem
->m_label
) < 0;
1695 else if ( sortProperty
== kNumericOrderColumnId
)
1696 retval
= m_order
< otherItem
->m_order
;
1701 OSStatus
wxMacDataItem::GetSetData( wxMacDataItemBrowserControl
*owner
,
1702 DataBrowserPropertyID property
,
1703 DataBrowserItemDataRef itemData
,
1706 OSStatus err
= errDataBrowserPropertyNotSupported
;
1709 if ( property
== m_colId
){
1710 err
= ::SetDataBrowserItemDataText( itemData
, m_cfLabel
);
1713 else if ( property
== kNumericOrderColumnId
){
1714 err
= ::SetDataBrowserItemDataValue( itemData
, m_order
);
1724 // no editable props here
1733 void wxMacDataItem::Notification(wxMacDataItemBrowserControl
*owner
,
1734 DataBrowserItemNotification message
,
1735 DataBrowserItemDataRef itemData
) const
1739 IMPLEMENT_DYNAMIC_CLASS( wxMacDataItemBrowserControl
, wxMacDataBrowserControl
)
1741 wxMacDataItemBrowserControl::wxMacDataItemBrowserControl( wxWindow
* peer
, const wxPoint
& pos
, const wxSize
& size
, long style
) :
1742 wxMacDataBrowserControl( peer
, pos
, size
, style
)
1744 m_suppressSelection
= false;
1745 m_sortOrder
= SortOrder_None
;
1746 m_clientDataItemsType
= wxClientData_None
;
1749 wxMacDataItem
* wxMacDataItemBrowserControl::CreateItem()
1751 return new wxMacDataItem();
1754 wxMacDataItemBrowserSelectionSuppressor::wxMacDataItemBrowserSelectionSuppressor(wxMacDataItemBrowserControl
*browser
)
1756 m_former
= browser
->SuppressSelection(true);
1757 m_browser
= browser
;
1760 wxMacDataItemBrowserSelectionSuppressor::~wxMacDataItemBrowserSelectionSuppressor()
1762 m_browser
->SuppressSelection(m_former
);
1765 bool wxMacDataItemBrowserControl::SuppressSelection( bool suppress
)
1767 bool former
= m_suppressSelection
;
1768 m_suppressSelection
= suppress
;
1773 Boolean
wxMacDataItemBrowserControl::CompareItems(DataBrowserItemID itemOneID
,
1774 DataBrowserItemID itemTwoID
,
1775 DataBrowserPropertyID sortProperty
)
1777 wxMacDataItem
* itemOne
= (wxMacDataItem
*) itemOneID
;
1778 wxMacDataItem
* itemTwo
= (wxMacDataItem
*) itemTwoID
;
1779 return CompareItems( itemOne
, itemTwo
, sortProperty
);
1782 Boolean
wxMacDataItemBrowserControl::CompareItems(const wxMacDataItem
* itemOne
,
1783 const wxMacDataItem
* itemTwo
,
1784 DataBrowserPropertyID sortProperty
)
1786 Boolean retval
= false;
1787 if ( itemOne
!= NULL
)
1788 retval
= itemOne
->IsLessThan( this , itemTwo
, sortProperty
);
1792 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1793 DataBrowserItemID itemID
,
1794 DataBrowserPropertyID property
,
1795 DataBrowserItemDataRef itemData
,
1796 Boolean changeValue
)
1798 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1799 return GetSetItemData(item
, property
, itemData
, changeValue
);
1802 OSStatus
wxMacDataItemBrowserControl::GetSetItemData(
1803 wxMacDataItem
* item
,
1804 DataBrowserPropertyID property
,
1805 DataBrowserItemDataRef itemData
,
1806 Boolean changeValue
)
1808 OSStatus err
= errDataBrowserPropertyNotSupported
;
1811 case kDataBrowserContainerIsClosableProperty
:
1812 case kDataBrowserContainerIsSortableProperty
:
1813 case kDataBrowserContainerIsOpenableProperty
:
1814 // right now default behaviour on these
1818 if ( item
!= NULL
){
1819 err
= item
->GetSetData( this, property
, itemData
, changeValue
);
1827 void wxMacDataItemBrowserControl::ItemNotification(
1828 DataBrowserItemID itemID
,
1829 DataBrowserItemNotification message
,
1830 DataBrowserItemDataRef itemData
)
1832 wxMacDataItem
* item
= (wxMacDataItem
*) itemID
;
1833 ItemNotification( item
, message
, itemData
);
1836 void wxMacDataItemBrowserControl::ItemNotification(
1837 const wxMacDataItem
* item
,
1838 DataBrowserItemNotification message
,
1839 DataBrowserItemDataRef itemData
)
1842 item
->Notification( this, message
, itemData
);
1845 unsigned int wxMacDataItemBrowserControl::GetItemCount(const wxMacDataItem
* container
,
1846 bool recurse
, DataBrowserItemState state
) const
1848 ItemCount numItems
= 0;
1849 verify_noerr( wxMacDataBrowserControl::GetItemCount( (DataBrowserItemID
)container
,
1850 recurse
, state
, &numItems
) );
1854 unsigned int wxMacDataItemBrowserControl::GetSelectedItemCount( const wxMacDataItem
* container
,
1855 bool recurse
) const
1857 return GetItemCount( container
, recurse
, kDataBrowserItemIsSelected
);
1861 void wxMacDataItemBrowserControl::GetItems(const wxMacDataItem
* container
,
1862 bool recurse
, DataBrowserItemState state
, wxArrayMacDataItemPtr
&items
) const
1864 Handle handle
= NewHandle(0);
1865 verify_noerr( wxMacDataBrowserControl::GetItems( (DataBrowserItemID
)container
,
1866 recurse
, state
, handle
) );
1868 int itemCount
= GetHandleSize(handle
)/sizeof(DataBrowserItemID
);
1870 wxMacDataItemPtr
* itemsArray
= (wxMacDataItemPtr
*) *handle
;
1871 for ( int i
= 0; i
< itemCount
; ++i
)
1873 items
.Add(itemsArray
[i
]);
1876 DisposeHandle( handle
);
1879 unsigned int wxMacDataItemBrowserControl::GetLineFromItem(const wxMacDataItem
* item
) const
1881 DataBrowserTableViewRowIndex row
;
1882 OSStatus err
= GetItemRow( (DataBrowserItemID
) item
, &row
);
1883 wxASSERT( err
== noErr
);
1887 wxMacDataItem
* wxMacDataItemBrowserControl::GetItemFromLine(unsigned int n
) const
1889 DataBrowserItemID id
;
1890 OSStatus err
= GetItemID( (DataBrowserTableViewRowIndex
) n
, &id
);
1891 wxASSERT( err
== noErr
);
1892 return (wxMacDataItem
*) id
;
1895 void wxMacDataItemBrowserControl::UpdateItem(const wxMacDataItem
*container
,
1896 const wxMacDataItem
*item
, DataBrowserPropertyID property
) const
1898 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, 1,
1899 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1902 void wxMacDataItemBrowserControl::UpdateItems(const wxMacDataItem
*container
,
1903 wxArrayMacDataItemPtr
&itemArray
, DataBrowserPropertyID property
) const
1905 unsigned int noItems
= itemArray
.GetCount();
1906 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1907 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1908 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1910 verify_noerr( wxMacDataBrowserControl::UpdateItems((DataBrowserItemID
)container
, noItems
,
1911 items
, kDataBrowserItemNoProperty
/* notSorted */, property
) );
1915 void wxMacDataItemBrowserControl::InsertColumn(int colId
, DataBrowserPropertyType colType
,
1916 const wxString
& title
, SInt16 just
, int defaultWidth
)
1918 DataBrowserListViewColumnDesc columnDesc
;
1919 columnDesc
.headerBtnDesc
.titleOffset
= 0;
1920 columnDesc
.headerBtnDesc
.version
= kDataBrowserListViewLatestHeaderDesc
;
1922 columnDesc
.headerBtnDesc
.btnFontStyle
.flags
=
1923 kControlUseFontMask
| kControlUseJustMask
;
1925 columnDesc
.headerBtnDesc
.btnContentInfo
.contentType
= kControlContentTextOnly
;
1926 columnDesc
.headerBtnDesc
.btnFontStyle
.just
= just
;
1927 columnDesc
.headerBtnDesc
.btnFontStyle
.font
= kControlFontViewSystemFont
;
1928 columnDesc
.headerBtnDesc
.btnFontStyle
.style
= normal
;
1930 // TODO: Why is m_font not defined when we enter wxLC_LIST mode, but is
1931 // defined for other modes?
1934 enc
= m_font
.GetEncoding();
1936 enc
= wxLocale::GetSystemEncoding();
1937 wxMacCFStringHolder cfTitle
;
1938 cfTitle
.Assign( title
, enc
);
1939 columnDesc
.headerBtnDesc
.titleString
= cfTitle
;
1941 columnDesc
.headerBtnDesc
.minimumWidth
= 0;
1942 columnDesc
.headerBtnDesc
.maximumWidth
= 30000;
1944 columnDesc
.propertyDesc
.propertyID
= (kMinColumnId
+ colId
);
1945 columnDesc
.propertyDesc
.propertyType
= colType
;
1946 columnDesc
.propertyDesc
.propertyFlags
= kDataBrowserListViewSortableColumn
;
1947 #if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_2
1948 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewTypeSelectColumn
;
1950 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_4
1951 columnDesc
.propertyDesc
.propertyFlags
|= kDataBrowserListViewNoGapForIconInHeaderButton
;
1954 verify_noerr( AddColumn( &columnDesc
, kDataBrowserListViewAppendColumn
) );
1956 if (defaultWidth
> 0){
1957 SetColumnWidth(colId
, defaultWidth
);
1962 void wxMacDataItemBrowserControl::SetColumnWidth(int colId
, int width
)
1964 DataBrowserPropertyID id
;
1965 GetColumnIDFromIndex(colId
, &id
);
1966 verify_noerr( wxMacDataBrowserControl::SetColumnWidth(id
, width
));
1969 int wxMacDataItemBrowserControl::GetColumnWidth(int colId
)
1971 DataBrowserPropertyID id
;
1972 GetColumnIDFromIndex(colId
, &id
);
1974 verify_noerr( wxMacDataBrowserControl::GetColumnWidth(id
, &result
));
1978 void wxMacDataItemBrowserControl::AddItem(wxMacDataItem
*container
, wxMacDataItem
*item
)
1980 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, 1,
1981 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
) );
1984 void wxMacDataItemBrowserControl::AddItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
1986 unsigned int noItems
= itemArray
.GetCount();
1987 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
1988 for ( unsigned int i
= 0; i
< noItems
; ++i
)
1989 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
1991 verify_noerr( wxMacDataBrowserControl::AddItems( (DataBrowserItemID
)container
, noItems
,
1992 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
) );
1996 void wxMacDataItemBrowserControl::RemoveItem(wxMacDataItem
*container
, wxMacDataItem
* item
)
1998 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 1,
1999 (DataBrowserItemID
*) &item
, kDataBrowserItemNoProperty
);
2000 verify_noerr( err
);
2003 void wxMacDataItemBrowserControl::RemoveItems(wxMacDataItem
*container
, wxArrayMacDataItemPtr
&itemArray
)
2005 unsigned int noItems
= itemArray
.GetCount();
2006 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
2007 for ( unsigned int i
= 0; i
< noItems
; ++i
)
2008 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
2010 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, noItems
,
2011 (DataBrowserItemID
*) items
, kDataBrowserItemNoProperty
);
2012 verify_noerr( err
);
2016 void wxMacDataItemBrowserControl::RemoveAllItems(wxMacDataItem
*container
)
2018 OSStatus err
= wxMacDataBrowserControl::RemoveItems( (DataBrowserItemID
)container
, 0 , NULL
, kDataBrowserItemNoProperty
);
2019 verify_noerr( err
);
2022 void wxMacDataItemBrowserControl::SetSelectedItem(wxMacDataItem
* item
, DataBrowserSetOption option
)
2024 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 1, (DataBrowserItemID
*) &item
, option
));
2027 void wxMacDataItemBrowserControl::SetSelectedAllItems(DataBrowserSetOption option
)
2029 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( 0 , NULL
, option
));
2032 void wxMacDataItemBrowserControl::SetSelectedItems(wxArrayMacDataItemPtr
&itemArray
, DataBrowserSetOption option
)
2034 unsigned int noItems
= itemArray
.GetCount();
2035 DataBrowserItemID
*items
= new DataBrowserItemID
[noItems
];
2036 for ( unsigned int i
= 0; i
< noItems
; ++i
)
2037 items
[i
] = (DataBrowserItemID
) itemArray
[i
];
2039 verify_noerr(wxMacDataBrowserControl::SetSelectedItems( noItems
, (DataBrowserItemID
*) items
, option
));
2043 Boolean
wxMacDataItemBrowserControl::IsItemSelected( const wxMacDataItem
* item
) const
2045 return wxMacDataBrowserControl::IsItemSelected( (DataBrowserItemID
) item
);
2048 void wxMacDataItemBrowserControl::RevealItem( wxMacDataItem
* item
, DataBrowserRevealOptions options
)
2050 verify_noerr(wxMacDataBrowserControl::RevealItem( (DataBrowserItemID
) item
, kDataBrowserNoItem
, options
) );
2053 void wxMacDataItemBrowserControl::GetSelectionAnchor( wxMacDataItemPtr
* first
, wxMacDataItemPtr
* last
) const
2055 verify_noerr(wxMacDataBrowserControl::GetSelectionAnchor( (DataBrowserItemID
*) first
, (DataBrowserItemID
*) last
) );
2058 wxClientDataType
wxMacDataItemBrowserControl::GetClientDataType() const
2060 return m_clientDataItemsType
;
2062 void wxMacDataItemBrowserControl::SetClientDataType(wxClientDataType clientDataItemsType
)
2064 m_clientDataItemsType
= clientDataItemsType
;
2067 unsigned int wxMacDataItemBrowserControl::MacGetCount() const
2069 return GetItemCount(wxMacDataBrowserRootContainer
,false,kDataBrowserItemAnyState
);
2072 void wxMacDataItemBrowserControl::MacDelete( unsigned int n
)
2074 wxMacDataItem
* item
= (wxMacDataItem
*)GetItemFromLine( n
);
2075 RemoveItem( wxMacDataBrowserRootContainer
, item
);
2078 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, const wxString
& text
, int column
)
2080 wxMacDataItem
* newItem
= CreateItem();
2081 newItem
->SetLabel( text
);
2083 newItem
->SetColumn( kMinColumnId
+ column
);
2085 if ( m_sortOrder
== SortOrder_None
)
2087 // increase the order of the lines to be shifted
2088 unsigned int lines
= MacGetCount();
2089 for ( unsigned int i
= n
; i
< lines
; ++i
)
2091 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
2092 iter
->SetOrder( iter
->GetOrder() + 1 );
2095 SInt32 frontLineOrder
= 0;
2098 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
2099 frontLineOrder
= iter
->GetOrder();
2101 newItem
->SetOrder( frontLineOrder
+ 1 );
2104 AddItem( wxMacDataBrowserRootContainer
, newItem
);
2107 void wxMacDataItemBrowserControl::MacInsert( unsigned int n
, const wxArrayString
& items
, int column
)
2109 size_t itemsCount
= items
.GetCount();
2110 if ( itemsCount
== 0 )
2113 SInt32 frontLineOrder
= 0;
2115 if ( m_sortOrder
== SortOrder_None
)
2117 // increase the order of the lines to be shifted
2118 unsigned int lines
= MacGetCount();
2119 for ( unsigned int i
= n
; i
< lines
; ++i
)
2121 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(i
);
2122 iter
->SetOrder( iter
->GetOrder() + itemsCount
);
2126 wxMacDataItem
* iter
= (wxMacDataItem
*) GetItemFromLine(n
-1);
2127 frontLineOrder
= iter
->GetOrder();
2131 wxArrayMacDataItemPtr ids
;
2132 ids
.SetCount( itemsCount
);
2134 for ( unsigned int i
= 0; i
< itemsCount
; ++i
)
2136 wxMacDataItem
* item
= CreateItem();
2137 item
->SetLabel( items
[i
]);
2139 item
->SetColumn( kMinColumnId
+ column
);
2141 if ( m_sortOrder
== SortOrder_None
)
2142 item
->SetOrder( frontLineOrder
+ 1 + i
);
2147 AddItems( wxMacDataBrowserRootContainer
, ids
);
2150 int wxMacDataItemBrowserControl::MacAppend( const wxString
& text
)
2152 wxMacDataItem
* item
= CreateItem();
2153 item
->SetLabel( text
);
2154 if ( m_sortOrder
== SortOrder_None
)
2156 unsigned int lines
= MacGetCount();
2158 item
->SetOrder( 1 );
2161 wxMacDataItem
* frontItem
= (wxMacDataItem
*) GetItemFromLine(lines
-1);
2162 item
->SetOrder( frontItem
->GetOrder() + 1 );
2165 AddItem( wxMacDataBrowserRootContainer
, item
);
2167 return GetLineFromItem(item
);
2170 void wxMacDataItemBrowserControl::MacClear()
2172 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2173 RemoveAllItems(wxMacDataBrowserRootContainer
);
2176 void wxMacDataItemBrowserControl::MacDeselectAll()
2178 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2179 SetSelectedAllItems( kDataBrowserItemsRemove
);
2182 void wxMacDataItemBrowserControl::MacSetSelection( unsigned int n
, bool select
, bool multi
)
2184 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
2185 wxMacDataItemBrowserSelectionSuppressor
suppressor(this);
2187 if ( IsItemSelected( item
) != select
)
2190 SetSelectedItem( item
, multi
? kDataBrowserItemsAdd
: kDataBrowserItemsAssign
);
2192 SetSelectedItem( item
, kDataBrowserItemsRemove
);
2198 bool wxMacDataItemBrowserControl::MacIsSelected( unsigned int n
) const
2200 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine(n
);
2201 return IsItemSelected( item
);
2204 int wxMacDataItemBrowserControl::MacGetSelection() const
2206 wxMacDataItemPtr first
, last
;
2207 GetSelectionAnchor( &first
, &last
);
2209 if ( first
!= NULL
)
2211 return GetLineFromItem( first
);
2217 int wxMacDataItemBrowserControl::MacGetSelections( wxArrayInt
& aSelections
) const
2219 aSelections
.Empty();
2220 wxArrayMacDataItemPtr selectedItems
;
2221 GetItems( wxMacDataBrowserRootContainer
, false , kDataBrowserItemIsSelected
, selectedItems
);
2223 int count
= selectedItems
.GetCount();
2225 for ( int i
= 0; i
< count
; ++i
)
2227 aSelections
.Add(GetLineFromItem(selectedItems
[i
]));
2233 void wxMacDataItemBrowserControl::MacSetString( unsigned int n
, const wxString
& text
)
2235 // as we don't store the strings we only have to issue a redraw
2236 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2237 item
->SetLabel( text
);
2238 UpdateItem( wxMacDataBrowserRootContainer
, item
, kTextColumnId
);
2241 wxString
wxMacDataItemBrowserControl::MacGetString( unsigned int n
) const
2243 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2244 return item
->GetLabel();
2247 void wxMacDataItemBrowserControl::MacSetClientData( unsigned int n
, void * data
)
2249 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2250 item
->SetData( data
);
2251 // not displayed, therefore no Update infos to DataBrowser
2254 void * wxMacDataItemBrowserControl::MacGetClientData( unsigned int n
) const
2256 wxMacDataItem
* item
= (wxMacDataItem
*) GetItemFromLine( n
);
2257 return item
->GetData();
2260 void wxMacDataItemBrowserControl::MacScrollTo( unsigned int n
)
2262 RevealItem( GetItemFromLine( n
) , kDataBrowserRevealWithoutSelecting
);
2271 OSStatus
wxMacControl::SetTabEnabled( SInt16 tabNo
, bool enable
)
2273 return ::SetTabEnabled( m_controlRef
, tabNo
, enable
);
2280 #ifdef __WXMAC_OSX__
2281 // snippets from Sketch Sample from Apple :
2283 #define kGenericRGBProfilePathStr "/System/Library/ColorSync/Profiles/Generic RGB Profile.icc"
2286 This function locates, opens, and returns the profile reference for the calibrated
2287 Generic RGB color space. It is up to the caller to call CMCloseProfile when done
2288 with the profile reference this function returns.
2290 CMProfileRef
wxMacOpenGenericProfile()
2292 static CMProfileRef cachedRGBProfileRef
= NULL
;
2294 // we only create the profile reference once
2295 if (cachedRGBProfileRef
== NULL
)
2297 CMProfileLocation loc
;
2299 loc
.locType
= cmPathBasedProfile
;
2300 strcpy(loc
.u
.pathLoc
.path
, kGenericRGBProfilePathStr
);
2302 verify_noerr( CMOpenProfile(&cachedRGBProfileRef
, &loc
) );
2305 // clone the profile reference so that the caller has their own reference, not our cached one
2306 if (cachedRGBProfileRef
)
2307 CMCloneProfileRef(cachedRGBProfileRef
);
2309 return cachedRGBProfileRef
;
2313 Return the generic RGB color space. This is a 'get' function and the caller should
2314 not release the returned value unless the caller retains it first. Usually callers
2315 of this routine will immediately use the returned colorspace with CoreGraphics
2316 so they typically do not need to retain it themselves.
2318 This function creates the generic RGB color space once and hangs onto it so it can
2319 return it whenever this function is called.
2322 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
2324 static wxMacCFRefHolder
<CGColorSpaceRef
> genericRGBColorSpace
;
2326 if (genericRGBColorSpace
== NULL
)
2328 if ( UMAGetSystemVersion() >= 0x1040 )
2330 genericRGBColorSpace
.Set( CGColorSpaceCreateWithName( CFSTR("kCGColorSpaceGenericRGB") ) );
2334 CMProfileRef genericRGBProfile
= wxMacOpenGenericProfile();
2336 if (genericRGBProfile
)
2338 genericRGBColorSpace
.Set( CGColorSpaceCreateWithPlatformColorSpace(genericRGBProfile
) );
2340 wxASSERT_MSG( genericRGBColorSpace
!= NULL
, wxT("couldn't create the generic RGB color space") );
2342 // we opened the profile so it is up to us to close it
2343 CMCloseProfile(genericRGBProfile
);
2348 return genericRGBColorSpace
;
2354 wxMacPortSaver::wxMacPortSaver( GrafPtr port
)
2356 ::GetPort( &m_port
);
2360 wxMacPortSaver::~wxMacPortSaver()
2362 ::SetPort( m_port
);
2366 void wxMacGlobalToLocal( WindowRef window
, Point
*pt
)
2368 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
2369 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
2370 HIViewRef contentView
;
2371 // TODO check toolbar offset
2372 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
2373 HIPointConvert( &p
, kHICoordSpace72DPIGlobal
, NULL
, kHICoordSpaceView
, contentView
);
2377 QDGlobalToLocalPoint( GetWindowPort(window
), pt
) ;
2381 void wxMacLocalToGlobal( WindowRef window
, Point
*pt
)
2383 #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_4
2384 HIPoint p
= CGPointMake( pt
->h
, pt
->v
);
2385 HIViewRef contentView
;
2386 // TODO check toolbar offset
2387 HIViewFindByID( HIViewGetRoot( window
), kHIViewWindowContentID
, &contentView
) ;
2388 HIPointConvert( &p
, kHICoordSpaceView
, contentView
, kHICoordSpace72DPIGlobal
, NULL
);
2392 QDLocalToGlobalPoint( GetWindowPort(window
), pt
) ;