]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/iphone/utils.mm
avoid setting initial position if it was not specified, broken in r70734
[wxWidgets.git] / src / osx / iphone / utils.mm
index 565f345f3dd8e31a32306b47c02544578f833abe..633c7b72ac21b082ff0b976098a30855cd90925a 100644 (file)
@@ -1,10 +1,9 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        src/osx/cocoa/utils.mm
+// Name:        src/osx/iphone/utils.mm
 // Purpose:     various cocoa utility functions
 // Author:      Stefan Csomor
 // Modified by:
 // Created:     1998-01-01
-// RCS-ID:      $Id: utils.mm 48805 2007-09-19 14:52:25Z SC $
 // Copyright:   (c) Stefan Csomor
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
 
 #include <AudioToolbox/AudioServices.h>
 
-#if wxUSE_BASE
-
-// Emit a beeeeeep
-void wxBell()
-{
-    // would be kSystemSoundID_UserPreferredAlert but since the headers aren't correct, add it manually
-    AudioServicesPlayAlertSound(0x00001000 );
-}
+#if 1 // wxUSE_BASE
 
 // ----------------------------------------------------------------------------
 // Common Event Support
@@ -57,10 +49,22 @@ void wxBell()
 
 @implementation wxAppDelegate
 
+- (BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+    wxUnusedVar(application);
+    wxUnusedVar(launchOptions);
+    wxTheApp->OSXOnWillFinishLaunching();
+    return YES;
+}
+
 - (void)applicationDidFinishLaunching:(UIApplication *)application {   
-       wxTheApp->OnInit();
+    wxTheApp->OSXOnDidFinishLaunching();
 }
 
+- (void)applicationWillTerminate:(UIApplication *)application { 
+    wxUnusedVar(application);
+    wxTheApp->OSXOnWillTerminate();
+}
 
 - (void)dealloc {
        [super dealloc];
@@ -74,14 +78,6 @@ bool wxApp::CallOnInit()
     return true;
 }
 
-int wxApp::OnRun()
-{
-    wxMacAutoreleasePool pool;
-    char* appname = "test";
-    UIApplicationMain( 1, &appname, nil, @"wxAppDelegate" );
-    return 1;
-}
-
 bool wxApp::DoInitGui()
 {
     return true;
@@ -91,14 +87,26 @@ void wxApp::DoCleanUp()
 {
 }
 
-void wxMacWakeUp()
+#endif // wxUSE_BASE
+
+#if wxUSE_GUI
+
+// Emit a beeeeeep
+void wxBell()
 {
-    // TODO
+    // would be kSystemSoundID_UserPreferredAlert but since the headers aren't correct, add it manually
+    AudioServicesPlayAlertSound(0x00001000 );
 }
 
-#endif // wxUSE_BASE
+// ----------------------------------------------------------------------------
+// Launch default browser
+// ----------------------------------------------------------------------------
 
-#if wxUSE_GUI
+bool wxDoLaunchDefaultBrowser(const wxString& url, int flags)
+{
+    return [[UIApplication sharedApplication] openURL:[NSURL URLWithString:wxCFStringRef(url).AsNSString()]]
+        == YES;
+}
 
 // TODO : reorganize
 
@@ -117,6 +125,11 @@ extern UIFont* CreateUIFont( const wxFont& font )
     return [UIFont fontWithName:wxCFStringRef(font.GetFaceName() ).AsNSString() size:font.GetPointSize()];
 }
 
+CFArrayRef CopyAvailableFontFamilyNames()
+{
+    return (CFArrayRef) [[UIFont familyNames] retain];
+}
+
 extern void DrawTextInContext( CGContextRef context, CGPoint where, UIFont *font, NSString* text )
 {
     bool contextChanged = ( UIGraphicsGetCurrentContext() != context );
@@ -136,23 +149,58 @@ extern CGSize MeasureTextInContext( UIFont *font, NSString* text )
 
 void wxClientDisplayRect(int *x, int *y, int *width, int *height)
 {
+#if 0
     CGRect r = [[UIScreen mainScreen] applicationFrame];
+    CGRect bounds = [[UIScreen mainScreen] bounds];
+    if ( bounds.size.height > r.size.height )
+    {
+        // portrait
+        if ( x )
+            *x = r.origin.x;
+        if ( y )
+            *y = r.origin.y;
+        if ( width )
+            *width = r.size.width;
+        if ( height )
+            *height = r.size.height;
+    }
+    else
+    {
+        // landscape
+        if ( x )
+            *x = r.origin.y;
+        if ( y )
+            *y = r.origin.x;
+        if ( width )
+            *width = r.size.height;
+        if ( height )
+            *height = r.size.width;
+    }
+#else
+    // it's easier to treat the status bar as an element of the toplevel window 
+    // instead of the desktop in order to support easy rotation
     if ( x )
-        *x = r.origin.x;
+        *x = 0;
     if ( y )
-        *y = r.origin.y;
-    if ( width )
-        *width = r.size.width;
-    if ( height )
-        *height = r.size.height;
-
+        *y = 0;
+    wxDisplaySize(width, height);
+#endif
 }
 
 void wxGetMousePosition( int* x, int* y )
 {
-//    wxPoint pt = wxFromNSPoint(NULL, [NSEvent mouseLocation]);
+    if ( x )
+        *x = 0;
+    if ( y )
+        *y = 0;
 };
 
+wxMouseState wxGetMouseState()
+{
+    wxMouseState ms;
+    return ms;
+}    
+
 // Returns depth of screen
 int wxDisplayDepth()
 {
@@ -162,12 +210,25 @@ int wxDisplayDepth()
 // Get size of display
 void wxDisplaySize(int *width, int *height)
 {
+    CGRect r = [[UIScreen mainScreen] applicationFrame];
     CGRect bounds = [[UIScreen mainScreen] bounds];
 
-    if ( width )
-        *width = (int)bounds.size.width ;
-    if ( height )
-        *height = (int)bounds.size.height;
+    if ( UIInterfaceOrientationIsPortrait([[UIApplication sharedApplication] statusBarOrientation]) )
+    {
+        // portrait
+        if ( width )
+            *width = (int)bounds.size.width ;
+        if ( height )
+            *height = (int)bounds.size.height;
+    }
+    else
+    {
+        // landscape
+        if ( width )
+            *width = (int)bounds.size.height ;
+        if ( height )
+            *height = (int)bounds.size.width;
+    }
 }
 
 wxTimerImpl* wxGUIAppTraits::CreateTimerImpl(wxTimer *timer)
@@ -287,4 +348,4 @@ wxString wxGetOsDescription()
 }
 
 
-#endif // wxOSX_USE_IPHONE
\ No newline at end of file
+#endif // wxOSX_USE_IPHONE