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