]> git.saurik.com Git - wxWidgets.git/blob - src/osx/utils_osx.cpp
Disable some wxWebView tests that fail on the buildbot but not locally.
[wxWidgets.git] / src / osx / utils_osx.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/utils_osx.cpp
3 // Purpose: Various utilities
4 // Author: Stefan Csomor
5 // Modified by:
6 // Created: 1998-01-01
7 // RCS-ID: $Id$
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12
13 #include "wx/wxprec.h"
14
15 #include "wx/utils.h"
16
17 #ifndef WX_PRECOMP
18 #include "wx/intl.h"
19 #include "wx/app.h"
20 #include "wx/log.h"
21 #if wxUSE_GUI
22 #include "wx/toplevel.h"
23 #include "wx/font.h"
24 #endif
25 #endif
26
27 #include "wx/apptrait.h"
28
29 #include <ctype.h>
30
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <stdarg.h>
35
36 // #include "MoreFilesX.h"
37
38 #if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5
39 #include <AudioToolbox/AudioServices.h>
40 #endif
41
42 #include "wx/osx/private.h"
43 #include "wx/osx/private/timer.h"
44
45 #include "wx/evtloop.h"
46
47 #if defined(__MWERKS__) && wxUSE_UNICODE
48 #if __MWERKS__ < 0x4100
49 #include <wtime.h>
50 #endif
51 #endif
52
53 // Check whether this window wants to process messages, e.g. Stop button
54 // in long calculations.
55 bool wxCheckForInterrupt(wxWindow *WXUNUSED(wnd))
56 {
57 // TODO
58 return false;
59 }
60
61 // Return true if we have a colour display
62 bool wxColourDisplay()
63 {
64 // always the case on OS X
65 return true;
66 }
67
68
69 #if wxOSX_USE_COCOA_OR_CARBON
70
71 #if (MAC_OS_X_VERSION_MAX_ALLOWED >= 1070) && (MAC_OS_X_VERSION_MIN_REQUIRED < 1060)
72 // bring back declaration so that we can support deployment targets < 10_6
73 CG_EXTERN size_t CGDisplayBitsPerPixel(CGDirectDisplayID display)
74 CG_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_6,
75 __IPHONE_NA, __IPHONE_NA);
76 #endif
77
78 // Returns depth of screen
79 int wxDisplayDepth()
80 {
81 int theDepth = 0;
82
83 #if MAC_OS_X_VERSION_MAX_ALLOWED >= 1060
84 if ( UMAGetSystemVersion() >= 0x1060 )
85 {
86 CGDisplayModeRef currentMode = CGDisplayCopyDisplayMode(kCGDirectMainDisplay);
87 CFStringRef encoding = CGDisplayModeCopyPixelEncoding(currentMode);
88
89 if(CFStringCompare(encoding, CFSTR(IO32BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
90 theDepth = 32;
91 else if(CFStringCompare(encoding, CFSTR(IO16BitDirectPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
92 theDepth = 16;
93 else if(CFStringCompare(encoding, CFSTR(IO8BitIndexedPixels), kCFCompareCaseInsensitive) == kCFCompareEqualTo)
94 theDepth = 8;
95 else
96 theDepth = 32; // some reasonable default
97
98 CFRelease(encoding);
99 }
100 else
101 #endif
102 {
103 #if MAC_OS_X_VERSION_MIN_REQUIRED < 1060
104 theDepth = (int) CGDisplayBitsPerPixel(CGMainDisplayID());
105 #endif
106 }
107 return theDepth;
108 }
109
110 // Get size of display
111 void wxDisplaySize(int *width, int *height)
112 {
113 // TODO adapt for multi-displays
114 CGRect bounds = CGDisplayBounds(CGMainDisplayID());
115 if ( width )
116 *width = (int)bounds.size.width ;
117 if ( height )
118 *height = (int)bounds.size.height;
119 }
120
121 #if wxUSE_GUI
122
123 // ----------------------------------------------------------------------------
124 // Launch document with default app
125 // ----------------------------------------------------------------------------
126
127 bool wxLaunchDefaultApplication(const wxString& document, int flags)
128 {
129 wxUnusedVar(flags);
130
131 wxCFRef<CFMutableStringRef> cfMutableString(CFStringCreateMutableCopy(NULL, 0, wxCFStringRef(document)));
132 CFStringNormalize(cfMutableString,kCFStringNormalizationFormD);
133 wxCFRef<CFURLRef> curl(CFURLCreateWithFileSystemPath(kCFAllocatorDefault, cfMutableString , kCFURLPOSIXPathStyle, false));
134 OSStatus err = LSOpenCFURLRef( curl , NULL );
135
136 if (err == noErr)
137 {
138 return true;
139 }
140 else
141 {
142 wxLogDebug(wxT("Default Application Launch error %d"), (int) err);
143 return false;
144 }
145 }
146
147 // ----------------------------------------------------------------------------
148 // Launch default browser
149 // ----------------------------------------------------------------------------
150
151 bool wxDoLaunchDefaultBrowser(const wxString& url, int flags)
152 {
153 wxUnusedVar(flags);
154 wxCFRef< CFURLRef > curl( CFURLCreateWithString( kCFAllocatorDefault,
155 wxCFStringRef( url ), NULL ) );
156 OSStatus err = LSOpenCFURLRef( curl , NULL );
157
158 if (err == noErr)
159 {
160 return true;
161 }
162 else
163 {
164 wxLogDebug(wxT("Browser Launch error %d"), (int) err);
165 return false;
166 }
167 }
168
169 #endif // wxUSE_GUI
170
171 #endif
172
173 void wxDisplaySizeMM(int *width, int *height)
174 {
175 wxDisplaySize(width, height);
176 // on mac 72 is fixed (at least now;-)
177 double cvPt2Mm = 25.4 / 72;
178
179 if (width != NULL)
180 *width = int( *width * cvPt2Mm );
181
182 if (height != NULL)
183 *height = int( *height * cvPt2Mm );
184 }
185
186
187 wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const
188 {
189 // We suppose that toolkit version is the same as OS version under Mac
190 wxGetOsVersion(verMaj, verMin);
191
192 return wxPORT_OSX;
193 }
194
195 wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
196 {
197 return new wxEventLoop;
198 }
199
200 wxWindow* wxFindWindowAtPoint(wxWindow* win, const wxPoint& pt);
201
202 wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
203 {
204 #if wxOSX_USE_CARBON
205
206 Point screenPoint = { pt.y , pt.x };
207 WindowRef windowRef;
208
209 if ( FindWindow( screenPoint , &windowRef ) )
210 {
211 wxNonOwnedWindow *nonOwned = wxNonOwnedWindow::GetFromWXWindow( windowRef );
212
213 if ( nonOwned )
214 return wxFindWindowAtPoint( nonOwned , pt );
215 }
216
217 return NULL;
218
219 #else
220
221 return wxGenericFindWindowAtPoint( pt );
222
223 #endif
224 }
225
226 /*
227 Return the generic RGB color space. This is a 'get' function and the caller should
228 not release the returned value unless the caller retains it first. Usually callers
229 of this routine will immediately use the returned colorspace with CoreGraphics
230 so they typically do not need to retain it themselves.
231
232 This function creates the generic RGB color space once and hangs onto it so it can
233 return it whenever this function is called.
234 */
235
236 CGColorSpaceRef wxMacGetGenericRGBColorSpace()
237 {
238 static wxCFRef<CGColorSpaceRef> genericRGBColorSpace;
239
240 if (genericRGBColorSpace == NULL)
241 {
242 #if wxOSX_USE_IPHONE
243 genericRGBColorSpace.reset( CGColorSpaceCreateDeviceRGB() );
244 #else
245 genericRGBColorSpace.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB ) );
246 #endif
247 }
248
249 return genericRGBColorSpace;
250 }
251
252 #if wxOSX_USE_COCOA_OR_CARBON
253
254 CGColorRef wxMacCreateCGColorFromHITheme( ThemeBrush brush )
255 {
256 CGColorRef color ;
257 HIThemeBrushCreateCGColor( brush, &color );
258 return color;
259 }
260
261 //---------------------------------------------------------------------------
262 // Mac Specific string utility functions
263 //---------------------------------------------------------------------------
264
265 void wxMacStringToPascal( const wxString&from , unsigned char * to )
266 {
267 wxCharBuffer buf = from.mb_str( wxConvLocal );
268 int len = strlen(buf);
269
270 if ( len > 255 )
271 len = 255;
272 to[0] = len;
273 memcpy( (char*) &to[1] , buf , len );
274 }
275
276 wxString wxMacMakeStringFromPascal( const unsigned char * from )
277 {
278 return wxString( (char*) &from[1] , wxConvLocal , from[0] );
279 }
280
281 #endif // wxOSX_USE_COCOA_OR_CARBON