]> git.saurik.com Git - wxWidgets.git/blame - src/osx/utils_osx.cpp
fixing build
[wxWidgets.git] / src / osx / utils_osx.cpp
CommitLineData
3ccc5735
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/utils_osx.cpp
3// Purpose: Various utilities
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
b5b208a1 7// RCS-ID: $Id$
3ccc5735
SC
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"
a56a99ab 20 #include "wx/log.h"
3ccc5735
SC
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"
b2767951 43#include "wx/osx/private/timer.h"
3ccc5735
SC
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
3ccc5735
SC
53// Check whether this window wants to process messages, e.g. Stop button
54// in long calculations.
55bool wxCheckForInterrupt(wxWindow *WXUNUSED(wnd))
56{
57 // TODO
58 return false;
59}
60
61// Return true if we have a colour display
62bool wxColourDisplay()
63{
128ad183 64 // always the case on OS X
3ccc5735
SC
65 return true;
66}
67
fdb2f6a2
SC
68
69#if wxOSX_USE_COCOA_OR_CARBON
70
d1d9736d
SC
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
73CG_EXTERN size_t CGDisplayBitsPerPixel(CGDirectDisplayID display)
74CG_AVAILABLE_BUT_DEPRECATED(__MAC_10_0, __MAC_10_6,
75 __IPHONE_NA, __IPHONE_NA);
76#endif
77
3ccc5735
SC
78// Returns depth of screen
79int wxDisplayDepth()
80{
d1d9736d
SC
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 }
3ccc5735
SC
107 return theDepth;
108}
109
110// Get size of display
111void 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}
2ae328d1
SC
120
121#if wxUSE_GUI
122
123// ----------------------------------------------------------------------------
124// Launch document with default app
125// ----------------------------------------------------------------------------
126
127bool wxLaunchDefaultApplication(const wxString& document, int flags)
128{
129 wxUnusedVar(flags);
130
2ea60735
SC
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 );
ce00f59b 135
2ea60735
SC
136 if (err == noErr)
137 {
2ae328d1 138 return true;
2ea60735
SC
139 }
140 else
141 {
142 wxLogDebug(wxT("Default Application Launch error %d"), (int) err);
143 return false;
144 }
2ae328d1
SC
145}
146
147// ----------------------------------------------------------------------------
148// Launch default browser
149// ----------------------------------------------------------------------------
150
151bool 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
3ccc5735
SC
171#endif
172
173void 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
187wxPortId 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
195wxEventLoopBase* wxGUIAppTraits::CreateEventLoop()
196{
197 return new wxEventLoop;
198}
199
2b76dfb0
VZ
200wxWindow* wxFindWindowAtPoint(wxWindow* win, const wxPoint& pt);
201
3ccc5735
SC
202wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
203{
2b76dfb0
VZ
204#if wxOSX_USE_CARBON
205
206 Point screenPoint = { pt.y , pt.x };
207 WindowRef windowRef;
208
209 if ( FindWindow( screenPoint , &windowRef ) )
210 {
9876e900 211 wxNonOwnedWindow *nonOwned = wxNonOwnedWindow::GetFromWXWindow( windowRef );
2b76dfb0
VZ
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
3ccc5735
SC
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
236CGColorSpaceRef 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
254CGColorRef wxMacCreateCGColorFromHITheme( ThemeBrush brush )
255{
256 CGColorRef color ;
257 HIThemeBrushCreateCGColor( brush, &color );
258 return color;
259}
260
1e181c7a
SC
261//---------------------------------------------------------------------------
262// Mac Specific string utility functions
263//---------------------------------------------------------------------------
264
265void 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
276wxString wxMacMakeStringFromPascal( const unsigned char * from )
277{
278 return wxString( (char*) &from[1] , wxConvLocal , from[0] );
279}
280
3ccc5735 281#endif // wxOSX_USE_COCOA_OR_CARBON