]> git.saurik.com Git - wxWidgets.git/blame - src/osx/iphone/utils.mm
Don't close arcs drawn in wxPostScriptDC.
[wxWidgets.git] / src / osx / iphone / utils.mm
CommitLineData
c16b2153 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/osx/iphone/utils.mm
c16b2153
SC
3// Purpose: various cocoa utility functions
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
a9a4f229 7// RCS-ID: $Id$
c16b2153
SC
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#include "wx/wxprec.h"
15
16#include "wx/utils.h"
17
18#ifndef WX_PRECOMP
19 #include "wx/intl.h"
20 #include "wx/app.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 "wx/osx/private.h"
30
31#if wxUSE_GUI
32 #include "wx/osx/private/timer.h"
33 #include "wx/osx/dcclient.h"
34#endif // wxUSE_GUI
35
36#if wxOSX_USE_IPHONE
37
38#include <AudioToolbox/AudioServices.h>
39
5d38a504 40#if 1 // wxUSE_BASE
c16b2153
SC
41
42// Emit a beeeeeep
43void wxBell()
44{
45 // would be kSystemSoundID_UserPreferredAlert but since the headers aren't correct, add it manually
46 AudioServicesPlayAlertSound(0x00001000 );
47}
48
49// ----------------------------------------------------------------------------
50// Common Event Support
51// ----------------------------------------------------------------------------
52
53@interface wxAppDelegate : NSObject <UIApplicationDelegate> {
54}
55
56@end
57
58@implementation wxAppDelegate
59
60- (void)applicationDidFinishLaunching:(UIApplication *)application {
61 wxTheApp->OnInit();
62}
63
747dbaba
SC
64- (void)applicationWillTerminate:(UIApplication *)application {
65 wxCloseEvent event;
66 wxTheApp->OnEndSession(event);
67}
c16b2153
SC
68
69- (void)dealloc {
70 [super dealloc];
71}
72
73
74@end
75
76bool wxApp::CallOnInit()
77{
78 return true;
79}
80
d3929256
SC
81bool wxApp::DoInitGui()
82{
83 return true;
84}
85
86void wxApp::DoCleanUp()
87{
88}
89
c16b2153
SC
90#endif // wxUSE_BASE
91
92#if wxUSE_GUI
93
f3769d53
SC
94// ----------------------------------------------------------------------------
95// Launch default browser
96// ----------------------------------------------------------------------------
97
98bool wxDoLaunchDefaultBrowser(const wxString& url, int flags)
99{
100 return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:wxCFStringRef(url).AsNSString()]]
101 == YES;
102}
103
c16b2153
SC
104// TODO : reorganize
105
106extern wxFont* CreateNormalFont()
107{
108 return new wxFont([UIFont systemFontSize] , wxSWISS, wxNORMAL, wxNORMAL, FALSE, "Helvetica" );
109}
110
111extern wxFont* CreateSmallFont()
112{
113 return new wxFont([UIFont smallSystemFontSize] , wxSWISS, wxNORMAL, wxNORMAL, FALSE, "Helvetica" );
114}
115
116extern UIFont* CreateUIFont( const wxFont& font )
117{
118 return [UIFont fontWithName:wxCFStringRef(font.GetFaceName() ).AsNSString() size:font.GetPointSize()];
119}
120
121extern void DrawTextInContext( CGContextRef context, CGPoint where, UIFont *font, NSString* text )
122{
123 bool contextChanged = ( UIGraphicsGetCurrentContext() != context );
124 if ( contextChanged )
125 UIGraphicsPushContext(context);
126
127 [text drawAtPoint:where withFont:font];
128
129 if ( contextChanged )
130 UIGraphicsPopContext();
131}
132
133extern CGSize MeasureTextInContext( UIFont *font, NSString* text )
134{
135 return [text sizeWithFont:font];
136}
137
138void wxClientDisplayRect(int *x, int *y, int *width, int *height)
139{
65536c92 140#if 0
c16b2153 141 CGRect r = [[UIScreen mainScreen] applicationFrame];
62018605
SC
142 CGRect bounds = [[UIScreen mainScreen] bounds];
143 if ( bounds.size.height > r.size.height )
144 {
145 // portrait
146 if ( x )
147 *x = r.origin.x;
148 if ( y )
149 *y = r.origin.y;
150 if ( width )
151 *width = r.size.width;
152 if ( height )
153 *height = r.size.height;
154 }
155 else
156 {
157 // landscape
158 if ( x )
159 *x = r.origin.y;
160 if ( y )
161 *y = r.origin.x;
162 if ( width )
163 *width = r.size.height;
164 if ( height )
165 *height = r.size.width;
166 }
65536c92
SC
167#else
168 // it's easier to treat the status bar as an element of the toplevel window
169 // instead of the desktop in order to support easy rotation
170 if ( x )
171 *x = 0;
172 if ( y )
173 *y = 0;
174 wxDisplaySize(width, height);
175#endif
c16b2153
SC
176}
177
178void wxGetMousePosition( int* x, int* y )
179{
f3769d53
SC
180 if ( x )
181 *x = 0;
182 if ( y )
183 *y = 0;
c16b2153
SC
184};
185
f3769d53
SC
186wxMouseState wxGetMouseState()
187{
188 wxMouseState ms;
189 return ms;
190}
191
c16b2153
SC
192// Returns depth of screen
193int wxDisplayDepth()
194{
195 return 32; // TODO can we determine this ?
196}
197
198// Get size of display
199void wxDisplaySize(int *width, int *height)
200{
62018605 201 CGRect r = [[UIScreen mainScreen] applicationFrame];
c16b2153 202 CGRect bounds = [[UIScreen mainScreen] bounds];
03647350 203
f3769d53 204 if ( UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) )
62018605
SC
205 {
206 // portrait
207 if ( width )
208 *width = (int)bounds.size.width ;
209 if ( height )
210 *height = (int)bounds.size.height;
211 }
212 else
213 {
214 // landscape
215 if ( width )
216 *width = (int)bounds.size.height ;
217 if ( height )
218 *height = (int)bounds.size.width;
219 }
c16b2153
SC
220}
221
222wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
223{
224 return new wxOSXTimerImpl(timer);
225}
226
227int gs_wxBusyCursorCount = 0;
228extern wxCursor gMacCurrentCursor;
229wxCursor gMacStoredActiveCursor;
230
231// Set the cursor to the busy cursor for all windows
232void wxBeginBusyCursor(const wxCursor *cursor)
233{
234 if (gs_wxBusyCursorCount++ == 0)
235 {
236 gMacStoredActiveCursor = gMacCurrentCursor;
237 cursor->MacInstall();
238
239 wxSetCursor(*cursor);
240 }
241 //else: nothing to do, already set
242}
243
244// Restore cursor to normal
245void wxEndBusyCursor()
246{
247 wxCHECK_RET( gs_wxBusyCursorCount > 0,
248 wxT("no matching wxBeginBusyCursor() for wxEndBusyCursor()") );
249
250 if (--gs_wxBusyCursorCount == 0)
251 {
252 gMacStoredActiveCursor.MacInstall();
253 gMacStoredActiveCursor = wxNullCursor;
254
255 wxSetCursor(wxNullCursor);
256 }
257}
258
259// true if we're between the above two calls
260bool wxIsBusy()
261{
262 return (gs_wxBusyCursorCount > 0);
263}
264
265bool wxGetKeyState (wxKeyCode key)
266{
267 return false;
268}
269
270wxBitmap wxWindowDCImpl::DoGetAsBitmap(const wxRect *subrect) const
271{
272 // wxScreenDC is derived from wxWindowDC, so a screen dc will
273 // call this method when a Blit is performed with it as a source.
274 if (!m_window)
275 return wxNullBitmap;
03647350 276
c16b2153 277 wxSize sz = m_window->GetSize();
03647350 278
c16b2153
SC
279 int left = subrect != NULL ? subrect->x : 0 ;
280 int top = subrect != NULL ? subrect->y : 0 ;
281 int width = subrect != NULL ? subrect->width : sz.x;
282 int height = subrect != NULL ? subrect->height : sz.y ;
03647350 283
c16b2153 284 wxBitmap bmp = wxBitmap(width, height, 32);
03647350 285
c16b2153 286 CGContextRef context = (CGContextRef)bmp.GetHBITMAP();
03647350 287
c16b2153 288 CGContextSaveGState(context);
03647350
VZ
289
290
c16b2153
SC
291 CGContextTranslateCTM( context, 0, height );
292 CGContextScaleCTM( context, 1, -1 );
293
294 if ( subrect )
295 CGContextTranslateCTM( context, -subrect->x, -subrect->y ) ;
296
297 UIGraphicsPushContext(context);
298 [ (NSView*) m_window->GetHandle() drawRect:CGRectMake(left, top, width, height ) ];
299 UIGraphicsPopContext();
300 CGContextRestoreGState(context);
301
302 return bmp;
303}
304
305#endif // wxUSE_GUI
306
307wxOperatingSystemId wxGetOsVersion(int *verMaj, int *verMin)
308{
309 // get OS version
310 int major, minor;
311
d3929256 312 wxString release = wxCFStringRef( wxCFRetain( [ [UIDevice currentDevice] systemVersion] ) ).AsString() ;
c16b2153
SC
313
314 if ( release.empty() ||
d3929256
SC
315 // TODO use wx method
316 scanf(release.c_str(), wxT("%d.%d"), &major, &minor) != 2 )
c16b2153
SC
317 {
318 // failed to get version string or unrecognized format
319 major =
320 minor = -1;
321 }
322
323 if ( verMaj )
324 *verMaj = major;
325 if ( verMin )
326 *verMin = minor;
327
328 return wxOS_MAC_OSX_DARWIN;
329}
330
331wxString wxGetOsDescription()
332{
d3929256 333 wxString release = wxCFStringRef( wxCFRetain([ [UIDevice currentDevice] systemName] )).AsString() ;
c16b2153
SC
334
335 return release;
336}
337
338
5d38a504 339#endif // wxOSX_USE_IPHONE