]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/iphone/nonownedwnd.mm
adding comment
[wxWidgets.git] / src / osx / iphone / nonownedwnd.mm
index 8fe020d1581e3e1873908bedcf63f6580091b97f..1be798fb72403c3436aaba7c3e23cdad9885befc 100644 (file)
@@ -1,10 +1,10 @@
 /////////////////////////////////////////////////////////////////////////////
-// Name:        src/osx/cocoa/nonownedwnd.mm
+// Name:        src/osx/iphone/nonownedwnd.mm
 // Purpose:     non owned window for iphone
 // Author:      Stefan Csomor
 // Modified by:
 // Created:     2008-06-20
-// RCS-ID:      $Id: nonownedwnd.mm 48805 2007-09-19 14:52:25Z SC $
+// RCS-ID:      $Id$
 // Copyright:   (c) Stefan Csomor
 // Licence:     wxWindows licence
 /////////////////////////////////////////////////////////////////////////////
@@ -55,7 +55,7 @@ wxPoint wxFromNSPoint( UIView* parent, const CGPoint& p )
 
 @end
 
-@interface wxUIContentView : wxUIView
+@interface wxUIContentView : UIView
 {
     wxUIContentViewController* _controller;
 }
@@ -135,6 +135,11 @@ long style, long extraStyle, const wxString& name )
     [m_macWindow setWindowLevel:level];
 }
 
+void wxNonOwnedWindowIPhoneImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow )
+{
+    m_macWindow = nativeWindow;
+}
+
 
 WXWindow wxNonOwnedWindowIPhoneImpl::GetWXWindow() const
 {
@@ -268,6 +273,11 @@ void wxNonOwnedWindowIPhoneImpl::Iconize( bool iconize )
 
 void wxNonOwnedWindowIPhoneImpl::Maximize(bool maximize)
 {
+    if ( maximize )
+    {
+        CGRect r = [[UIScreen mainScreen] bounds];
+        [m_macWindow setFrame:r];
+    }
 }
 
 bool wxNonOwnedWindowIPhoneImpl::IsFullScreen() const
@@ -304,6 +314,14 @@ void wxNonOwnedWindowIPhoneImpl::WindowToScreen( int *x, int *y )
         *y = p.y;
 }
 
+wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow)
+{
+    wxNonOwnedWindowIPhoneImpl* now = new wxNonOwnedWindowIPhoneImpl( wxpeer );
+    now->Create( parent, nativeWindow );
+    return now;
+}
+
+
 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
     long style, long extraStyle, const wxString& name )
 {
@@ -321,8 +339,12 @@ wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
 
     wxUIContentView* contentview = [[wxUIContentView alloc] initWithFrame:( fullscreen ? frame : appframe ) ];
     contentview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
-    wxUIContentViewController* controller = [[wxUIContentViewController alloc] init];
+    wxUIContentViewController* controller = [[wxUIContentViewController alloc] initWithNibName:nil bundle:nil];
+
+#ifdef __IPHONE_3_0
     controller.wantsFullScreenLayout = fullscreen;
+#endif
+
     controller.view = contentview;
     [contentview release];
     [contentview setController:controller];
@@ -330,7 +352,15 @@ wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
     
     wxWidgetIPhoneImpl* impl = new wxWidgetIPhoneImpl( now, contentview, true );
     impl->InstallEventHandler();
-    [toplevelwindow addSubview:contentview];
+    
+    if ([toplevelwindow respondsToSelector:@selector(setRootViewController:)])
+    {
+        toplevelwindow.rootViewController = controller;
+    }
+    else
+    {
+        [toplevelwindow addSubview:contentview];
+    }
     return impl;
 }
 
@@ -350,6 +380,16 @@ wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
     return _controller;
 }
 
++ (void)initialize
+{
+    static BOOL initialized = NO;
+    if (!initialized)
+    {
+        initialized = YES;
+        wxOSXIPhoneClassAddWXMethods( self );
+    }
+}
 @end
 
 @implementation wxUIContentViewController
@@ -364,6 +404,21 @@ wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
     return YES;
 }
 
+// iOS 6 support, right now unconditionally supporting all orientations, TODO use a orientation mask
+
+-(BOOL)shouldAutorotate
+{
+    return YES;
+}
+
+ - (NSUInteger)supportedInterfaceOrientations
+{
+     return UIInterfaceOrientationMaskAll;
+}
+
+
 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
 {
     wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
@@ -390,15 +445,18 @@ wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
 -(void) viewWillDisappear:(BOOL)animated
 {
     wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
-    wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
-    wxNonOwnedWindowIPhoneImpl* nowimpl = dynamic_cast<wxNonOwnedWindowIPhoneImpl*> (now->GetNonOwnedPeer());
-    
-    if ( nowimpl->InitialShowEventSent() )
+    if( impl )
     {
-        wxShowEvent eventShow(now->GetId(), false);
-        eventShow.SetEventObject(now);
-    
-        now->HandleWindowEvent(eventShow);
+        wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
+        wxNonOwnedWindowIPhoneImpl* nowimpl = dynamic_cast<wxNonOwnedWindowIPhoneImpl*> (now->GetNonOwnedPeer());
+        
+        if ( nowimpl->InitialShowEventSent() )
+        {
+            wxShowEvent eventShow(now->GetId(), false);
+            eventShow.SetEventObject(now);
+        
+            now->HandleWindowEvent(eventShow);
+        }
     }
 }
 
@@ -419,6 +477,7 @@ wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
             footerView = frame->GetToolBar()->GetHandle();
         }
     }
+    return footerView;
 }
 
 @end