]>
Commit | Line | Data |
---|---|---|
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. | |
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 | { | |
128ad183 | 64 | // always the case on OS X |
3ccc5735 SC |
65 | return true; |
66 | } | |
67 | ||
68 | #if wxOSX_USE_COCOA_OR_CARBON | |
69 | // Returns depth of screen | |
70 | int wxDisplayDepth() | |
71 | { | |
72 | int theDepth = (int) CGDisplayBitsPerPixel(CGMainDisplayID()); | |
73 | return theDepth; | |
74 | } | |
75 | ||
76 | // Get size of display | |
77 | void wxDisplaySize(int *width, int *height) | |
78 | { | |
79 | // TODO adapt for multi-displays | |
80 | CGRect bounds = CGDisplayBounds(CGMainDisplayID()); | |
81 | if ( width ) | |
82 | *width = (int)bounds.size.width ; | |
83 | if ( height ) | |
84 | *height = (int)bounds.size.height; | |
85 | } | |
2ae328d1 SC |
86 | |
87 | #if wxUSE_GUI | |
88 | ||
89 | // ---------------------------------------------------------------------------- | |
90 | // Launch document with default app | |
91 | // ---------------------------------------------------------------------------- | |
92 | ||
93 | bool wxLaunchDefaultApplication(const wxString& document, int flags) | |
94 | { | |
95 | wxUnusedVar(flags); | |
96 | ||
2ea60735 SC |
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 ); | |
ce00f59b | 101 | |
2ea60735 SC |
102 | if (err == noErr) |
103 | { | |
2ae328d1 | 104 | return true; |
2ea60735 SC |
105 | } |
106 | else | |
107 | { | |
108 | wxLogDebug(wxT("Default Application Launch error %d"), (int) err); | |
109 | return false; | |
110 | } | |
2ae328d1 SC |
111 | } |
112 | ||
113 | // ---------------------------------------------------------------------------- | |
114 | // Launch default browser | |
115 | // ---------------------------------------------------------------------------- | |
116 | ||
117 | bool wxDoLaunchDefaultBrowser(const wxString& url, int flags) | |
118 | { | |
119 | wxUnusedVar(flags); | |
120 | wxCFRef< CFURLRef > curl( CFURLCreateWithString( kCFAllocatorDefault, | |
121 | wxCFStringRef( url ), NULL ) ); | |
122 | OSStatus err = LSOpenCFURLRef( curl , NULL ); | |
123 | ||
124 | if (err == noErr) | |
125 | { | |
126 | return true; | |
127 | } | |
128 | else | |
129 | { | |
130 | wxLogDebug(wxT("Browser Launch error %d"), (int) err); | |
131 | return false; | |
132 | } | |
133 | } | |
134 | ||
135 | #endif // wxUSE_GUI | |
136 | ||
3ccc5735 SC |
137 | #endif |
138 | ||
139 | void wxDisplaySizeMM(int *width, int *height) | |
140 | { | |
141 | wxDisplaySize(width, height); | |
142 | // on mac 72 is fixed (at least now;-) | |
143 | double cvPt2Mm = 25.4 / 72; | |
144 | ||
145 | if (width != NULL) | |
146 | *width = int( *width * cvPt2Mm ); | |
147 | ||
148 | if (height != NULL) | |
149 | *height = int( *height * cvPt2Mm ); | |
150 | } | |
151 | ||
152 | ||
153 | wxPortId wxGUIAppTraits::GetToolkitVersion(int *verMaj, int *verMin) const | |
154 | { | |
155 | // We suppose that toolkit version is the same as OS version under Mac | |
156 | wxGetOsVersion(verMaj, verMin); | |
157 | ||
158 | return wxPORT_OSX; | |
159 | } | |
160 | ||
161 | wxEventLoopBase* wxGUIAppTraits::CreateEventLoop() | |
162 | { | |
163 | return new wxEventLoop; | |
164 | } | |
165 | ||
2b76dfb0 VZ |
166 | wxWindow* wxFindWindowAtPoint(wxWindow* win, const wxPoint& pt); |
167 | ||
3ccc5735 SC |
168 | wxWindow* wxFindWindowAtPoint(const wxPoint& pt) |
169 | { | |
2b76dfb0 VZ |
170 | #if wxOSX_USE_CARBON |
171 | ||
172 | Point screenPoint = { pt.y , pt.x }; | |
173 | WindowRef windowRef; | |
174 | ||
175 | if ( FindWindow( screenPoint , &windowRef ) ) | |
176 | { | |
9876e900 | 177 | wxNonOwnedWindow *nonOwned = wxNonOwnedWindow::GetFromWXWindow( windowRef ); |
2b76dfb0 VZ |
178 | |
179 | if ( nonOwned ) | |
180 | return wxFindWindowAtPoint( nonOwned , pt ); | |
181 | } | |
182 | ||
183 | return NULL; | |
184 | ||
185 | #else | |
186 | ||
187 | return wxGenericFindWindowAtPoint( pt ); | |
188 | ||
189 | #endif | |
3ccc5735 SC |
190 | } |
191 | ||
192 | /* | |
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. | |
197 | ||
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. | |
200 | */ | |
201 | ||
202 | CGColorSpaceRef wxMacGetGenericRGBColorSpace() | |
203 | { | |
204 | static wxCFRef<CGColorSpaceRef> genericRGBColorSpace; | |
205 | ||
206 | if (genericRGBColorSpace == NULL) | |
207 | { | |
208 | #if wxOSX_USE_IPHONE | |
209 | genericRGBColorSpace.reset( CGColorSpaceCreateDeviceRGB() ); | |
210 | #else | |
211 | genericRGBColorSpace.reset( CGColorSpaceCreateWithName( kCGColorSpaceGenericRGB ) ); | |
212 | #endif | |
213 | } | |
214 | ||
215 | return genericRGBColorSpace; | |
216 | } | |
217 | ||
218 | #if wxOSX_USE_COCOA_OR_CARBON | |
219 | ||
220 | CGColorRef wxMacCreateCGColorFromHITheme( ThemeBrush brush ) | |
221 | { | |
222 | CGColorRef color ; | |
223 | HIThemeBrushCreateCGColor( brush, &color ); | |
224 | return color; | |
225 | } | |
226 | ||
1e181c7a SC |
227 | //--------------------------------------------------------------------------- |
228 | // Mac Specific string utility functions | |
229 | //--------------------------------------------------------------------------- | |
230 | ||
231 | void wxMacStringToPascal( const wxString&from , unsigned char * to ) | |
232 | { | |
233 | wxCharBuffer buf = from.mb_str( wxConvLocal ); | |
234 | int len = strlen(buf); | |
235 | ||
236 | if ( len > 255 ) | |
237 | len = 255; | |
238 | to[0] = len; | |
239 | memcpy( (char*) &to[1] , buf , len ); | |
240 | } | |
241 | ||
242 | wxString wxMacMakeStringFromPascal( const unsigned char * from ) | |
243 | { | |
244 | return wxString( (char*) &from[1] , wxConvLocal , from[0] ); | |
245 | } | |
246 | ||
3ccc5735 | 247 | #endif // wxOSX_USE_COCOA_OR_CARBON |