]> git.saurik.com Git - wxWidgets.git/blame - src/osx/iphone/nonownedwnd.mm
No real changes, just make wxWindow::CanScroll() virtual.
[wxWidgets.git] / src / osx / iphone / nonownedwnd.mm
CommitLineData
c16b2153 1/////////////////////////////////////////////////////////////////////////////
80fdcdb9 2// Name: src/osx/iphone/nonownedwnd.mm
c16b2153
SC
3// Purpose: non owned window for iphone
4// Author: Stefan Csomor
5// Modified by:
6// Created: 2008-06-20
c16b2153
SC
7// Copyright: (c) Stefan Csomor
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11#include "wx/wxprec.h"
12
13#include "wx/osx/private.h"
14
15#include "wx/nonownedwnd.h"
16#include "wx/frame.h"
de7cb655 17#include <algorithm>
c16b2153 18
d3929256
SC
19CGRect wxToNSRect(UIView* parent, const wxRect& r )
20{
21 CGRect frame = parent ? [parent bounds] : [[UIScreen mainScreen] bounds];
22 int y = r.y;
23 int x = r.x ;
24 return CGRectMake(x, y, r.width , r.height);
25}
26
27wxRect wxFromNSRect( UIView* parent, const CGRect& rect )
28{
29 CGRect frame = parent ? [parent bounds] : [[UIScreen mainScreen] bounds];
30 int y = rect.origin.y;
31 int x = rect.origin.x;
32 return wxRect( x, y, rect.size.width, rect.size.height );
33}
34
35CGPoint wxToNSPoint( UIView* parent, const wxPoint& p )
36{
37 CGRect frame = parent ? [parent bounds] : [[UIScreen mainScreen] bounds];
38 int x = p.x ;
39 int y = p.y;
40 return CGPointMake(x, y);
41}
42
43wxPoint wxFromNSPoint( UIView* parent, const CGPoint& p )
44{
45 CGRect frame = parent ? [parent bounds] : [[UIScreen mainScreen] bounds];
46 int x = p.x;
47 int y = p.y;
48 return wxPoint( x, y);
49}
50
de7cb655
SC
51@interface wxUIContentViewController : UIViewController
52{
53}
54
55@end
56
ba508df0 57@interface wxUIContentView : UIView
de7cb655
SC
58{
59 wxUIContentViewController* _controller;
60}
61
4cc16dcb
SC
62- (void) setController: (wxUIContentViewController*) controller;
63- (wxUIContentViewController*) controller;
de7cb655
SC
64@end
65
66
67
68//
69// c++ impl
70//
d3929256 71
c16b2153
SC
72IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowIPhoneImpl , wxNonOwnedWindowImpl )
73
03647350 74wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl( wxNonOwnedWindow* nonownedwnd) :
c16b2153
SC
75 wxNonOwnedWindowImpl(nonownedwnd)
76{
77 m_macWindow = NULL;
78 m_macFullScreenData = NULL;
4cc16dcb 79 m_initialShowSent = false;
c16b2153 80}
03647350
VZ
81
82wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl()
c16b2153
SC
83{
84 m_macWindow = NULL;
85 m_macFullScreenData = NULL;
4cc16dcb 86 m_initialShowSent = false;
c16b2153 87}
03647350 88
c16b2153
SC
89wxNonOwnedWindowIPhoneImpl::~wxNonOwnedWindowIPhoneImpl()
90{
91 [m_macWindow release];
92}
93
0aaa6ace 94void wxNonOwnedWindowIPhoneImpl::WillBeDestroyed()
c16b2153 95{
c16b2153
SC
96}
97
98void wxNonOwnedWindowIPhoneImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
99long style, long extraStyle, const wxString& name )
100{
101 m_macWindow = [UIWindow alloc];
03647350 102
c16b2153 103 UIWindowLevel level = UIWindowLevelNormal;
03647350 104
c16b2153 105 // most styles are not supported on the iphone
03647350 106
c16b2153
SC
107 if ( style & wxFRAME_TOOL_WINDOW )
108 {
109 level = UIWindowLevelAlert; ;
110 }
111 else if ( ( style & wxPOPUP_WINDOW ) )
112 {
113 level = UIWindowLevelAlert;;
114 }
115 else if ( ( style & wxCAPTION ) )
116 {
117 }
118 else if ( ( style & wxFRAME_DRAWER ) )
119 {
120 }
121 else
122 {
123 }
124
125 if ( ( style & wxSTAY_ON_TOP ) )
03647350 126 level = UIWindowLevelAlert;
c16b2153 127 CGRect r = CGRectMake( 0, 0, size.x, size.y) ;
de7cb655
SC
128 if ( UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) )
129 std::swap(r.size.width,r.size.height);
03647350 130
c16b2153 131 [m_macWindow initWithFrame:r ];
4cc16dcb 132 [m_macWindow setHidden:YES];
03647350 133
c16b2153 134 [m_macWindow setWindowLevel:level];
c16b2153
SC
135}
136
c61605ef
SC
137void wxNonOwnedWindowIPhoneImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow )
138{
139 m_macWindow = nativeWindow;
140}
141
c16b2153
SC
142
143WXWindow wxNonOwnedWindowIPhoneImpl::GetWXWindow() const
144{
145 return m_macWindow;
146}
147
148void wxNonOwnedWindowIPhoneImpl::Raise()
149{
150}
03647350 151
c16b2153
SC
152void wxNonOwnedWindowIPhoneImpl::Lower()
153{
154}
155
156bool wxNonOwnedWindowIPhoneImpl::Show(bool show)
157{
158 [m_macWindow setHidden:(show ? NO : YES)];
159 if ( show )
160 {
4cc16dcb
SC
161 if ( !m_initialShowSent )
162 {
163 wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (GetWXPeer());
164 wxShowEvent eventShow(now->GetId(), true);
165 eventShow.SetEventObject(now);
166
167 now->HandleWindowEvent(eventShow);
168
169 m_initialShowSent = true;
170 }
c16b2153
SC
171 //[m_macWindow orderFront: self];
172 [m_macWindow makeKeyWindow];
173 }
174 return true;
175}
03647350 176
c16b2153
SC
177bool wxNonOwnedWindowIPhoneImpl::ShowWithEffect(bool show, wxShowEffect effect, unsigned timeout)
178{
179 return Show(show);
180}
181
182void wxNonOwnedWindowIPhoneImpl::Update()
183{
184// TODO [m_macWindow displayIfNeeded];
185}
186
187bool wxNonOwnedWindowIPhoneImpl::SetTransparent(wxByte alpha)
188{
189 [m_macWindow setAlpha:(CGFloat) alpha/255.0];
190 return true;
191}
192
193bool wxNonOwnedWindowIPhoneImpl::SetBackgroundColour(const wxColour& col )
194{
195 return true;
196}
197
198void wxNonOwnedWindowIPhoneImpl::SetExtraStyle( long exStyle )
199{
200 // no special styles supported
201}
03647350 202
c16b2153
SC
203bool wxNonOwnedWindowIPhoneImpl::SetBackgroundStyle(wxBackgroundStyle style)
204{
205 return true;
206}
03647350 207
c16b2153
SC
208bool wxNonOwnedWindowIPhoneImpl::CanSetTransparent()
209{
210 return true;
211}
212
213void wxNonOwnedWindowIPhoneImpl::MoveWindow(int x, int y, int width, int height)
214{
d3929256 215 CGRect r = CGRectMake( x,y,width,height) ;
de7cb655
SC
216 if ( UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) )
217 std::swap(r.size.width,r.size.height);
218
c16b2153
SC
219 [m_macWindow setFrame:r];
220}
221
222void wxNonOwnedWindowIPhoneImpl::GetPosition( int &x, int &y ) const
223{
224 CGRect r = [m_macWindow frame];
225 x = r.origin.x;
226 y = r.origin.y;
227}
228
229void wxNonOwnedWindowIPhoneImpl::GetSize( int &width, int &height ) const
230{
de7cb655
SC
231 CGRect r = [m_macWindow frame];
232 if ( UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) )
233 std::swap(r.size.width,r.size.height);
234 width = r.size.width;
235 height = r.size.height;
c16b2153
SC
236}
237
d3929256 238void wxNonOwnedWindowIPhoneImpl::GetContentArea( int& left, int &top, int &width, int &height ) const
c16b2153 239{
de7cb655
SC
240 CGRect r = [m_macWindow bounds];
241 if ( UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) )
242 std::swap(r.size.width,r.size.height);
243 width = r.size.width;
244 height = r.size.height;
245 left = r.origin.x;
246 top = r.origin.y;
c16b2153 247}
03647350 248
c16b2153
SC
249bool wxNonOwnedWindowIPhoneImpl::SetShape(const wxRegion& region)
250{
251 return false;
252}
253
03647350 254void wxNonOwnedWindowIPhoneImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
c16b2153
SC
255{
256// TODO change title of app ?
257}
03647350 258
c16b2153
SC
259bool wxNonOwnedWindowIPhoneImpl::IsMaximized() const
260{
261 return false;
262}
03647350 263
c16b2153
SC
264bool wxNonOwnedWindowIPhoneImpl::IsIconized() const
265{
266 return false;
267}
03647350 268
c16b2153
SC
269void wxNonOwnedWindowIPhoneImpl::Iconize( bool iconize )
270{
271}
03647350 272
c16b2153
SC
273void wxNonOwnedWindowIPhoneImpl::Maximize(bool maximize)
274{
01470e37
SC
275 if ( maximize )
276 {
516e9d13 277 CGRect r = [[UIScreen mainScreen] bounds];
01470e37
SC
278 [m_macWindow setFrame:r];
279 }
c16b2153
SC
280}
281
282bool wxNonOwnedWindowIPhoneImpl::IsFullScreen() const
283{
284 return m_macFullScreenData != NULL ;
285}
03647350 286
c16b2153 287bool wxNonOwnedWindowIPhoneImpl::ShowFullScreen(bool show, long style)
03647350 288{
c16b2153
SC
289 return true;
290}
291
292void wxNonOwnedWindowIPhoneImpl::RequestUserAttention(int WXUNUSED(flags))
293{
294}
295
296void wxNonOwnedWindowIPhoneImpl::ScreenToWindow( int *x, int *y )
297{
298 CGPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) );
299 p = [m_macWindow convertPoint:p fromWindow:nil];
300 if ( x )
301 *x = p.x;
302 if ( y )
303 *y = p.y;
304}
305
306void wxNonOwnedWindowIPhoneImpl::WindowToScreen( int *x, int *y )
307{
308 CGPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) );
309 p = [m_macWindow convertPoint:p toWindow:nil];
310 if ( x )
311 *x = p.x;
312 if ( y )
313 *y = p.y;
314}
315
c61605ef
SC
316wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow)
317{
318 wxNonOwnedWindowIPhoneImpl* now = new wxNonOwnedWindowIPhoneImpl( wxpeer );
319 now->Create( parent, nativeWindow );
320 return now;
321}
322
323
524c47aa
SC
324wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
325 long style, long extraStyle, const wxString& name )
326{
327 wxNonOwnedWindowImpl* now = new wxNonOwnedWindowIPhoneImpl( wxpeer );
328 now->Create( parent, pos, size, style , extraStyle, name );
329 return now;
330}
de7cb655
SC
331
332wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
333{
334 UIWindow* toplevelwindow = now->GetWXWindow();
335 CGRect frame = [toplevelwindow bounds];
336 CGRect appframe = [[UIScreen mainScreen] applicationFrame];
4cc16dcb
SC
337 BOOL fullscreen = now->GetWindowStyle() == wxDEFAULT_FRAME_STYLE && [[UIApplication sharedApplication] statusBarStyle] == UIStatusBarStyleBlackTranslucent;
338
339 wxUIContentView* contentview = [[wxUIContentView alloc] initWithFrame:( fullscreen ? frame : appframe ) ];
de7cb655 340 contentview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
c61605ef 341 wxUIContentViewController* controller = [[wxUIContentViewController alloc] initWithNibName:nil bundle:nil];
6494f8d1
JS
342
343#ifdef __IPHONE_3_0
4cc16dcb 344 controller.wantsFullScreenLayout = fullscreen;
6494f8d1
JS
345#endif
346
de7cb655 347 controller.view = contentview;
4cc16dcb 348 [contentview release];
de7cb655 349 [contentview setController:controller];
4cc16dcb 350 [contentview setHidden:YES];
de7cb655
SC
351
352 wxWidgetIPhoneImpl* impl = new wxWidgetIPhoneImpl( now, contentview, true );
353 impl->InstallEventHandler();
e4064cdf
SC
354
355 if ([toplevelwindow respondsToSelector:@selector(setRootViewController:)])
356 {
357 toplevelwindow.rootViewController = controller;
358 }
359 else
360 {
361 [toplevelwindow addSubview:contentview];
362 }
de7cb655
SC
363 return impl;
364}
365
366//
367// obj-c impl
368//
369
370@implementation wxUIContentView
371
4cc16dcb 372- (void) setController: (wxUIContentViewController*) controller
de7cb655
SC
373{
374 _controller = controller;
375}
376
4cc16dcb 377- (wxUIContentViewController*) controller
de7cb655
SC
378{
379 return _controller;
380}
381
ba508df0
SC
382+ (void)initialize
383{
384 static BOOL initialized = NO;
385 if (!initialized)
386 {
387 initialized = YES;
388 wxOSXIPhoneClassAddWXMethods( self );
389 }
390}
391
de7cb655
SC
392@end
393
394@implementation wxUIContentViewController
395
396- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation
397{
398 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
399 wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
400
401 // TODO: determine NO or YES based on min size requirements (whether it fits on the new orientation)
402
403 return YES;
404}
405
e4064cdf
SC
406// iOS 6 support, right now unconditionally supporting all orientations, TODO use a orientation mask
407
408-(BOOL)shouldAutorotate
409{
410 return YES;
411}
412
413 - (NSUInteger)supportedInterfaceOrientations
414{
415 return UIInterfaceOrientationMaskAll;
416}
417
418
419
420
de7cb655
SC
421- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
422{
de7cb655
SC
423 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
424 wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
4cc16dcb
SC
425
426 now->HandleResized(0);
427}
c7109e1a 428
4cc16dcb
SC
429-(void) viewWillAppear:(BOOL)animated
430{
431 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
432 wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
433 wxNonOwnedWindowIPhoneImpl* nowimpl = dynamic_cast<wxNonOwnedWindowIPhoneImpl*> (now->GetNonOwnedPeer());
434
435 if ( nowimpl->InitialShowEventSent() )
c7109e1a 436 {
4cc16dcb
SC
437 wxShowEvent eventShow(now->GetId(), true);
438 eventShow.SetEventObject(now);
439
440 now->HandleWindowEvent(eventShow);
c7109e1a 441 }
4cc16dcb
SC
442}
443
444-(void) viewWillDisappear:(BOOL)animated
445{
446 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
3fdfbc9c 447 if( impl )
4cc16dcb 448 {
3fdfbc9c
SC
449 wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
450 wxNonOwnedWindowIPhoneImpl* nowimpl = dynamic_cast<wxNonOwnedWindowIPhoneImpl*> (now->GetNonOwnedPeer());
451
452 if ( nowimpl->InitialShowEventSent() )
453 {
454 wxShowEvent eventShow(now->GetId(), false);
455 eventShow.SetEventObject(now);
456
457 now->HandleWindowEvent(eventShow);
458 }
4cc16dcb 459 }
de7cb655
SC
460}
461
462-(void) dealloc
463{
464 [super dealloc];
465}
466
467- (UIView*) rotatingFooterView
468{
469 UIView* footerView = [super rotatingFooterView];
470 if ( footerView == nil )
471 {
472 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
473 wxFrame* frame = dynamic_cast<wxFrame*> (impl->GetWXPeer());
474 if ( frame && frame->GetToolBar())
475 {
476 footerView = frame->GetToolBar()->GetHandle();
477 }
478 }
396b3729 479 return footerView;
de7cb655
SC
480}
481
482@end
483
484
485