/////////////////////////////////////////////////////////////////////////////
-// 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
/////////////////////////////////////////////////////////////////////////////
@end
-@interface wxUIContentView : wxUIView
+@interface wxUIContentView : UIView
{
wxUIContentViewController* _controller;
}
-- (void) setController: (UIViewController*) controller;
-- (UIViewController*) controller;
+- (void) setController: (wxUIContentViewController*) controller;
+- (wxUIContentViewController*) controller;
@end
{
m_macWindow = NULL;
m_macFullScreenData = NULL;
+ m_initialShowSent = false;
}
wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl()
{
m_macWindow = NULL;
m_macFullScreenData = NULL;
+ m_initialShowSent = false;
}
wxNonOwnedWindowIPhoneImpl::~wxNonOwnedWindowIPhoneImpl()
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;
}
[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];
}
void wxNonOwnedWindowIPhoneImpl::Maximize(bool maximize)
{
+ if ( maximize )
+ {
+ CGRect r = [[UIScreen mainScreen] bounds];
+ [m_macWindow setFrame:r];
+ }
}
bool wxNonOwnedWindowIPhoneImpl::IsFullScreen() const
*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 )
{
UIWindow* toplevelwindow = now->GetWXWindow();
CGRect frame = [toplevelwindow bounds];
CGRect appframe = [[UIScreen mainScreen] applicationFrame];
-
- if ( now->GetWindowStyle() == wxDEFAULT_FRAME_STYLE && [[UIApplication sharedApplication] statusBarStyle] != UIStatusBarStyleBlackTranslucent)
- {
- double offset = appframe.origin.y;
- frame.origin.y += offset;
- frame.size.height -= offset;
- }
-
- wxUIContentView* contentview = [[wxUIContentView alloc] initWithFrame:frame];
+ 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] 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];
+ [contentview setHidden:YES];
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;
}
@implementation wxUIContentView
-- (void) setController: (UIViewController*) controller
+- (void) setController: (wxUIContentViewController*) controller
{
_controller = controller;
}
-- (UIViewController*) controller
+- (wxUIContentViewController*) controller
{
return _controller;
}
++ (void)initialize
+{
+ static BOOL initialized = NO;
+ if (!initialized)
+ {
+ initialized = YES;
+ wxOSXIPhoneClassAddWXMethods( self );
+ }
+}
+
@end
@implementation wxUIContentViewController
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
{
- CGRect frame = [self.view frame];
wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
+
+ now->HandleResized(0);
+}
- if ( now->GetWindowStyle() == wxDEFAULT_FRAME_STYLE && [[UIApplication sharedApplication] statusBarStyle] == UIStatusBarStyleBlackTranslucent)
+-(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() )
{
- CGRect appframe = [[UIScreen mainScreen] applicationFrame];
- if ( CGRectEqualToRect(appframe, frame) )
+ 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() )
{
- if ( appframe.origin.y != 0 )
- {
- double offset = appframe.origin.y;
- frame.origin.y -= offset;
- frame.size.height += offset;
- }
- else
- {
- double offset = appframe.origin.x;
- frame.origin.x -= offset;
- frame.size.width += offset;
- }
-
- [self.view setFrame:frame];
+ wxShowEvent eventShow(now->GetId(), false);
+ eventShow.SetEventObject(now);
+
+ now->HandleWindowEvent(eventShow);
}
}
-
- now->HandleResized(0);
}
-(void) dealloc
footerView = frame->GetToolBar()->GetHandle();
}
}
+ return footerView;
}
@end