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