+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 )
+{
+ wxNonOwnedWindowImpl* now = new wxNonOwnedWindowIPhoneImpl( wxpeer );
+ 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();
+
+ if ([toplevelwindow respondsToSelector:@selector(setRootViewController:)])
+ {
+ toplevelwindow.rootViewController = controller;
+ }
+ else
+ {
+ [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;
+}
+
+// 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] );
+ 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();
+ }
+ }
+ return footerView;
+}
+
+@end
+
+
+