]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/iphone/nonownedwnd.mm
Remove temporary files created by wxFileName unit test case.
[wxWidgets.git] / src / osx / iphone / nonownedwnd.mm
index 609b4039bdbcfbc5a7797e698a7402ccc210b893..53168f0dafc5e87feae8a4bede9a886d38b0922a 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
 /////////////////////////////////////////////////////////////////////////////
@@ -15,6 +15,7 @@
 
 #include "wx/nonownedwnd.h"
 #include "wx/frame.h"
+#include <algorithm>
 
 CGRect wxToNSRect(UIView* parent, const wxRect& r )
 {
@@ -48,41 +49,62 @@ wxPoint wxFromNSPoint( UIView* parent, const CGPoint& p )
     return wxPoint( x, y);
 }
 
+@interface wxUIContentViewController : UIViewController
+{
+}
+
+@end
+
+@interface wxUIContentView : UIView
+{
+    wxUIContentViewController* _controller;
+}
+
+- (void) setController: (wxUIContentViewController*) controller;
+- (wxUIContentViewController*) controller;
+@end
+
+
+
+//
+// c++ impl
+//
 
 IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowIPhoneImpl , wxNonOwnedWindowImpl )
 
-wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl( wxNonOwnedWindow* nonownedwnd) : 
+wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl( wxNonOwnedWindow* nonownedwnd) :
     wxNonOwnedWindowImpl(nonownedwnd)
 {
     m_macWindow = NULL;
     m_macFullScreenData = NULL;
+    m_initialShowSent = false;
 }
-    
-wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl() 
+
+wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl()
 {
     m_macWindow = NULL;
     m_macFullScreenData = NULL;
+    m_initialShowSent = false;
 }
-    
+
 wxNonOwnedWindowIPhoneImpl::~wxNonOwnedWindowIPhoneImpl()
 {
     [m_macWindow release];
 }
 
-void wxNonOwnedWindowIPhoneImpl::Destroy()
+void wxNonOwnedWindowIPhoneImpl::WillBeDestroyed()
 {
-    wxPendingDelete.Append( new wxDeferredObjectDeleter( this ) );
 }
 
 void wxNonOwnedWindowIPhoneImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
 long style, long extraStyle, const wxString& name )
 {
     m_macWindow = [UIWindow alloc];
-    
+
     UIWindowLevel level = UIWindowLevelNormal;
-    
+
     // most styles are not supported on the iphone
-    
+
     if ( style & wxFRAME_TOOL_WINDOW )
     {
         level = UIWindowLevelAlert; ;
@@ -102,13 +124,20 @@ long style, long extraStyle, const wxString& name )
     }
 
     if ( ( style & wxSTAY_ON_TOP ) )
-        level = UIWindowLevelAlert;    
+        level = UIWindowLevelAlert;
     CGRect r = CGRectMake( 0, 0, size.x, size.y) ;
-    
+    if ( UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) )
+        std::swap(r.size.width,r.size.height);
+
     [m_macWindow initWithFrame:r ];
-        
+    [m_macWindow setHidden:YES];
+
     [m_macWindow setWindowLevel:level];
-    // [m_macWindow makeKeyAndOrderFront:nil];
+}
+
+void wxNonOwnedWindowIPhoneImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow )
+{
+    m_macWindow = nativeWindow;
 }
 
 
@@ -120,7 +149,7 @@ WXWindow wxNonOwnedWindowIPhoneImpl::GetWXWindow() const
 void wxNonOwnedWindowIPhoneImpl::Raise()
 {
 }
-    
+
 void wxNonOwnedWindowIPhoneImpl::Lower()
 {
 }
@@ -130,12 +159,22 @@ bool wxNonOwnedWindowIPhoneImpl::Show(bool show)
     [m_macWindow setHidden:(show ? NO : YES)];
     if ( show )
     {
+        if ( !m_initialShowSent )
+        {
+            wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (GetWXPeer());
+            wxShowEvent eventShow(now->GetId(), true);
+            eventShow.SetEventObject(now);
+            
+            now->HandleWindowEvent(eventShow);
+
+            m_initialShowSent = true;
+        }
         //[m_macWindow orderFront: self];
         [m_macWindow makeKeyWindow];
     }
     return true;
 }
-    
+
 bool wxNonOwnedWindowIPhoneImpl::ShowWithEffect(bool show, wxShowEffect effect, unsigned timeout)
 {
     return Show(show);
@@ -161,12 +200,12 @@ void wxNonOwnedWindowIPhoneImpl::SetExtraStyle( long exStyle )
 {
     // no special styles supported
 }
-    
+
 bool wxNonOwnedWindowIPhoneImpl::SetBackgroundStyle(wxBackgroundStyle style)
 {
     return true;
 }
-    
+
 bool wxNonOwnedWindowIPhoneImpl::CanSetTransparent()
 {
     return true;
@@ -175,6 +214,9 @@ bool wxNonOwnedWindowIPhoneImpl::CanSetTransparent()
 void wxNonOwnedWindowIPhoneImpl::MoveWindow(int x, int y, int width, int height)
 {
     CGRect r = CGRectMake( x,y,width,height) ;
+    if ( UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) )
+        std::swap(r.size.width,r.size.height);
+
     [m_macWindow setFrame:r];
 }
 
@@ -187,55 +229,64 @@ void wxNonOwnedWindowIPhoneImpl::GetPosition( int &x, int &y ) const
 
 void wxNonOwnedWindowIPhoneImpl::GetSize( int &width, int &height ) const
 {
-    CGRect rect = [m_macWindow frame];
-    width = rect.size.width;
-    height = rect.size.height;
+    CGRect r = [m_macWindow frame];
+    if ( UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) )
+        std::swap(r.size.width,r.size.height);
+    width = r.size.width;
+    height = r.size.height;
 }
 
 void wxNonOwnedWindowIPhoneImpl::GetContentArea( int& left, int &top, int &width, int &height ) const
 {
-    CGRect rect = [m_macWindow frame];
-    width = rect.size.width;
-    height = rect.size.height;
-    left = rect.origin.x;
-    top = rect.origin.y;
+    CGRect r = [m_macWindow bounds];
+    if ( UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) )
+        std::swap(r.size.width,r.size.height);
+    width = r.size.width;
+    height = r.size.height;
+    left = r.origin.x;
+    top = r.origin.y;
 }
-    
+
 bool wxNonOwnedWindowIPhoneImpl::SetShape(const wxRegion& region)
 {
     return false;
 }
 
-void wxNonOwnedWindowIPhoneImpl::SetTitle( const wxString& title, wxFontEncoding encoding ) 
+void wxNonOwnedWindowIPhoneImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
 {
 // TODO change title of app ?
 }
-    
+
 bool wxNonOwnedWindowIPhoneImpl::IsMaximized() const
 {
     return false;
 }
-    
+
 bool wxNonOwnedWindowIPhoneImpl::IsIconized() const
 {
     return false;
 }
-    
+
 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
 {
     return m_macFullScreenData != NULL ;
 }
-    
+
 bool wxNonOwnedWindowIPhoneImpl::ShowFullScreen(bool show, long style)
-{    
+{
     return true;
 }
 
@@ -263,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 )
 {
@@ -270,3 +329,134 @@ wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWind
     now->Create( parent, pos, size, style , extraStyle, name );
     return now;
 }
+
+wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
+{
+    UIWindow* toplevelwindow = now->GetWXWindow();
+    CGRect frame = [toplevelwindow bounds];
+    CGRect appframe = [[UIScreen mainScreen] applicationFrame];
+    BOOL fullscreen = now->GetWindowStyle() == wxDEFAULT_FRAME_STYLE && [[UIApplication sharedApplication] statusBarStyle] == UIStatusBarStyleBlackTranslucent;
+
+    wxUIContentView* contentview = [[wxUIContentView alloc] initWithFrame:( fullscreen ? frame : appframe ) ];
+    contentview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
+    wxUIContentViewController* controller = [[wxUIContentViewController alloc] initWithNibName:nil bundle:nil];
+
+#ifdef __IPHONE_3_0
+    controller.wantsFullScreenLayout = fullscreen;
+#endif
+
+    controller.view = contentview;
+    [contentview release];
+    [contentview setController:controller];
+    [contentview setHidden:YES];
+    
+    wxWidgetIPhoneImpl* impl = new wxWidgetIPhoneImpl( now, contentview, true );
+    impl->InstallEventHandler();
+    [toplevelwindow addSubview:contentview];
+    return impl;
+}
+
+//
+// obj-c impl
+//
+
+@implementation wxUIContentView
+
+- (void) setController: (wxUIContentViewController*) controller
+{
+    _controller = controller;
+}
+
+- (wxUIContentViewController*) controller
+{
+    return _controller;
+}
+
++ (void)initialize
+{
+    static BOOL initialized = NO;
+    if (!initialized)
+    {
+        initialized = YES;
+        wxOSXIPhoneClassAddWXMethods( self );
+    }
+}
+@end
+
+@implementation wxUIContentViewController
+
+- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation
+{
+    wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
+    wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
+    
+    // TODO: determine NO or YES based on min size requirements (whether it fits on the new orientation)
+    
+    return YES;
+}
+
+- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
+{
+    wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
+    wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
+    
+    now->HandleResized(0);
+}
+
+-(void) viewWillAppear:(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() )
+    {
+        wxShowEvent eventShow(now->GetId(), true);
+        eventShow.SetEventObject(now);
+    
+        now->HandleWindowEvent(eventShow);
+    }
+}
+
+-(void) viewWillDisappear:(BOOL)animated
+{
+    wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
+    if( impl )
+    {
+        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);
+        }
+    }
+}
+
+-(void) dealloc
+{
+    [super dealloc];
+}
+
+- (UIView*) rotatingFooterView
+{
+    UIView* footerView = [super rotatingFooterView];
+    if ( footerView == nil )
+    {
+        wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
+        wxFrame* frame = dynamic_cast<wxFrame*> (impl->GetWXPeer());
+        if ( frame && frame->GetToolBar())
+        {
+            footerView = frame->GetToolBar()->GetHandle();
+        }
+    }
+}
+
+@end
+
+
+