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