1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/utils_osx.cpp
3 // Purpose: Various utilities
4 // Author: Stefan Csomor
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #include "wx/wxprec.h"
22 #include "wx/toplevel.h"
27 #include "wx/apptrait.h"
36 // #include "MoreFilesX.h"
38 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
39 #include <AudioToolbox/AudioServices.h>
42 #include "wx/osx/private.h"
43 #include "wx/osx/private/timer.h"
45 #include "wx/evtloop.h"
47 #if defined(__MWERKS__) && wxUSE_UNICODE
48 #if __MWERKS__ < 0x4100
53 // Check whether this window wants to process messages, e.g. Stop button
54 // in long calculations.
55 bool wxCheckForInterrupt(wxWindow
*WXUNUSED(wnd
))
61 // Return true if we have a colour display
62 bool wxColourDisplay()
64 // always the case on OS X
68 #if wxOSX_USE_COCOA_OR_CARBON
69 // Returns depth of screen
72 int theDepth
= (int) CGDisplayBitsPerPixel(CGMainDisplayID());
76 // Get size of display
77 void wxDisplaySize(int *width
, int *height
)
79 // TODO adapt for multi-displays
80 CGRect bounds
= CGDisplayBounds(CGMainDisplayID());
82 *width
= (int)bounds
.size
.width
;
84 *height
= (int)bounds
.size
.height
;
89 // ----------------------------------------------------------------------------
90 // Launch document with default app
91 // ----------------------------------------------------------------------------
93 bool wxLaunchDefaultApplication(const wxString
& document
, int flags
)
97 wxCFRef
<CFMutableStringRef
> cfMutableString(CFStringCreateMutableCopy(NULL
, 0, wxCFStringRef(document
)));
98 CFStringNormalize(cfMutableString
,kCFStringNormalizationFormD
);
99 wxCFRef
<CFURLRef
> curl(CFURLCreateWithFileSystemPath(kCFAllocatorDefault
, cfMutableString
, kCFURLPOSIXPathStyle
, false));
100 OSStatus err
= LSOpenCFURLRef( curl
, NULL
);
108 wxLogDebug(wxT("Default Application Launch error %d"), (int) err
);
113 // ----------------------------------------------------------------------------
114 // Launch default browser
115 // ----------------------------------------------------------------------------
117 bool wxDoLaunchDefaultBrowser(const wxString
& url
, int flags
)
120 wxCFRef
< CFURLRef
> curl( CFURLCreateWithString( kCFAllocatorDefault
,
121 wxCFStringRef( url
), NULL
) );
122 OSStatus err
= LSOpenCFURLRef( curl
, NULL
);
130 wxLogDebug(wxT("Browser Launch error %d"), (int) err
);
139 void wxDisplaySizeMM(int *width
, int *height
)
141 wxDisplaySize(width
, height
);
142 // on mac 72 is fixed (at least now;-)
143 double cvPt2Mm
= 25.4 / 72;
146 *width
= int( *width
* cvPt2Mm
);
149 *height
= int( *height
* cvPt2Mm
);
153 wxPortId
wxGUIAppTraits::GetToolkitVersion(int *verMaj
, int *verMin
) const
155 // We suppose that toolkit version is the same as OS version under Mac
156 wxGetOsVersion(verMaj
, verMin
);
161 wxEventLoopBase
* wxGUIAppTraits::CreateEventLoop()
163 return new wxEventLoop
;
166 wxWindow
* wxFindWindowAtPoint(wxWindow
* win
, const wxPoint
& pt
);
168 wxWindow
* wxFindWindowAtPoint(const wxPoint
& pt
)
172 Point screenPoint
= { pt
.y
, pt
.x
};
175 if ( FindWindow( screenPoint
, &windowRef
) )
177 wxNonOwnedWindow
*nonOwned
= wxNonOwnedWindow::GetFromWXWindow( windowRef
);
180 return wxFindWindowAtPoint( nonOwned
, pt
);
187 return wxGenericFindWindowAtPoint( pt
);
193 Return the generic RGB color space. This is a 'get' function and the caller should
194 not release the returned value unless the caller retains it first. Usually callers
195 of this routine will immediately use the returned colorspace with CoreGraphics
196 so they typically do not need to retain it themselves.
198 This function creates the generic RGB color space once and hangs onto it so it can
199 return it whenever this function is called.
202 CGColorSpaceRef
wxMacGetGenericRGBColorSpace()
204 static wxCFRef
<CGColorSpaceRef
> genericRGBColorSpace
;
206 if (genericRGBColorSpace
== NULL
)
209 genericRGBColorSpace
.reset( CGColorSpaceCreateDeviceRGB() );
211 genericRGBColorSpace
.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB
) );
215 return genericRGBColorSpace
;
218 #if wxOSX_USE_COCOA_OR_CARBON
220 CGColorRef
wxMacCreateCGColorFromHITheme( ThemeBrush brush
)
223 HIThemeBrushCreateCGColor( brush
, &color
);
227 //---------------------------------------------------------------------------
228 // Mac Specific string utility functions
229 //---------------------------------------------------------------------------
231 void wxMacStringToPascal( const wxString
&from
, unsigned char * to
)
233 wxCharBuffer buf
= from
.mb_str( wxConvLocal
);
234 int len
= strlen(buf
);
239 memcpy( (char*) &to
[1] , buf
, len
);
242 wxString
wxMacMakeStringFromPascal( const unsigned char * from
)
244 return wxString( (char*) &from
[1] , wxConvLocal
, from
[0] );
247 #endif // wxOSX_USE_COCOA_OR_CARBON