]> git.saurik.com Git - wxWidgets.git/blame - src/osx/iphone/nonownedwnd.mm
Fix mistake, though this assert is unfortunate since now FindString("whatever") will...
[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
63- (void) setController: (UIViewController*) controller;
64- (UIViewController*) controller;
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;
80}
03647350
VZ
81
82wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl()
c16b2153
SC
83{
84 m_macWindow = NULL;
85 m_macFullScreenData = NULL;
86}
03647350 87
c16b2153
SC
88wxNonOwnedWindowIPhoneImpl::~wxNonOwnedWindowIPhoneImpl()
89{
90 [m_macWindow release];
91}
92
0aaa6ace 93void wxNonOwnedWindowIPhoneImpl::WillBeDestroyed()
c16b2153 94{
c16b2153
SC
95}
96
97void wxNonOwnedWindowIPhoneImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
98long style, long extraStyle, const wxString& name )
99{
100 m_macWindow = [UIWindow alloc];
03647350 101
c16b2153 102 UIWindowLevel level = UIWindowLevelNormal;
03647350 103
c16b2153 104 // most styles are not supported on the iphone
03647350 105
c16b2153
SC
106 if ( style & wxFRAME_TOOL_WINDOW )
107 {
108 level = UIWindowLevelAlert; ;
109 }
110 else if ( ( style & wxPOPUP_WINDOW ) )
111 {
112 level = UIWindowLevelAlert;;
113 }
114 else if ( ( style & wxCAPTION ) )
115 {
116 }
117 else if ( ( style & wxFRAME_DRAWER ) )
118 {
119 }
120 else
121 {
122 }
123
124 if ( ( style & wxSTAY_ON_TOP ) )
03647350 125 level = UIWindowLevelAlert;
c16b2153 126 CGRect r = CGRectMake( 0, 0, size.x, size.y) ;
de7cb655
SC
127 if ( UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) )
128 std::swap(r.size.width,r.size.height);
03647350 129
c16b2153 130 [m_macWindow initWithFrame:r ];
03647350 131
c16b2153
SC
132 [m_macWindow setWindowLevel:level];
133 // [m_macWindow makeKeyAndOrderFront:nil];
134}
135
136
137WXWindow wxNonOwnedWindowIPhoneImpl::GetWXWindow() const
138{
139 return m_macWindow;
140}
141
142void wxNonOwnedWindowIPhoneImpl::Raise()
143{
144}
03647350 145
c16b2153
SC
146void wxNonOwnedWindowIPhoneImpl::Lower()
147{
148}
149
150bool wxNonOwnedWindowIPhoneImpl::Show(bool show)
151{
152 [m_macWindow setHidden:(show ? NO : YES)];
153 if ( show )
154 {
155 //[m_macWindow orderFront: self];
156 [m_macWindow makeKeyWindow];
157 }
158 return true;
159}
03647350 160
c16b2153
SC
161bool wxNonOwnedWindowIPhoneImpl::ShowWithEffect(bool show, wxShowEffect effect, unsigned timeout)
162{
163 return Show(show);
164}
165
166void wxNonOwnedWindowIPhoneImpl::Update()
167{
168// TODO [m_macWindow displayIfNeeded];
169}
170
171bool wxNonOwnedWindowIPhoneImpl::SetTransparent(wxByte alpha)
172{
173 [m_macWindow setAlpha:(CGFloat) alpha/255.0];
174 return true;
175}
176
177bool wxNonOwnedWindowIPhoneImpl::SetBackgroundColour(const wxColour& col )
178{
179 return true;
180}
181
182void wxNonOwnedWindowIPhoneImpl::SetExtraStyle( long exStyle )
183{
184 // no special styles supported
185}
03647350 186
c16b2153
SC
187bool wxNonOwnedWindowIPhoneImpl::SetBackgroundStyle(wxBackgroundStyle style)
188{
189 return true;
190}
03647350 191
c16b2153
SC
192bool wxNonOwnedWindowIPhoneImpl::CanSetTransparent()
193{
194 return true;
195}
196
197void wxNonOwnedWindowIPhoneImpl::MoveWindow(int x, int y, int width, int height)
198{
d3929256 199 CGRect r = CGRectMake( x,y,width,height) ;
de7cb655
SC
200 if ( UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) )
201 std::swap(r.size.width,r.size.height);
202
c16b2153
SC
203 [m_macWindow setFrame:r];
204}
205
206void wxNonOwnedWindowIPhoneImpl::GetPosition( int &x, int &y ) const
207{
208 CGRect r = [m_macWindow frame];
209 x = r.origin.x;
210 y = r.origin.y;
211}
212
213void wxNonOwnedWindowIPhoneImpl::GetSize( int &width, int &height ) const
214{
de7cb655
SC
215 CGRect r = [m_macWindow frame];
216 if ( UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) )
217 std::swap(r.size.width,r.size.height);
218 width = r.size.width;
219 height = r.size.height;
c16b2153
SC
220}
221
d3929256 222void wxNonOwnedWindowIPhoneImpl::GetContentArea( int& left, int &top, int &width, int &height ) const
c16b2153 223{
de7cb655
SC
224 CGRect r = [m_macWindow bounds];
225 if ( UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) )
226 std::swap(r.size.width,r.size.height);
227 width = r.size.width;
228 height = r.size.height;
229 left = r.origin.x;
230 top = r.origin.y;
c16b2153 231}
03647350 232
c16b2153
SC
233bool wxNonOwnedWindowIPhoneImpl::SetShape(const wxRegion& region)
234{
235 return false;
236}
237
03647350 238void wxNonOwnedWindowIPhoneImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
c16b2153
SC
239{
240// TODO change title of app ?
241}
03647350 242
c16b2153
SC
243bool wxNonOwnedWindowIPhoneImpl::IsMaximized() const
244{
245 return false;
246}
03647350 247
c16b2153
SC
248bool wxNonOwnedWindowIPhoneImpl::IsIconized() const
249{
250 return false;
251}
03647350 252
c16b2153
SC
253void wxNonOwnedWindowIPhoneImpl::Iconize( bool iconize )
254{
255}
03647350 256
c16b2153
SC
257void wxNonOwnedWindowIPhoneImpl::Maximize(bool maximize)
258{
259}
260
261bool wxNonOwnedWindowIPhoneImpl::IsFullScreen() const
262{
263 return m_macFullScreenData != NULL ;
264}
03647350 265
c16b2153 266bool wxNonOwnedWindowIPhoneImpl::ShowFullScreen(bool show, long style)
03647350 267{
c16b2153
SC
268 return true;
269}
270
271void wxNonOwnedWindowIPhoneImpl::RequestUserAttention(int WXUNUSED(flags))
272{
273}
274
275void wxNonOwnedWindowIPhoneImpl::ScreenToWindow( int *x, int *y )
276{
277 CGPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) );
278 p = [m_macWindow convertPoint:p fromWindow:nil];
279 if ( x )
280 *x = p.x;
281 if ( y )
282 *y = p.y;
283}
284
285void wxNonOwnedWindowIPhoneImpl::WindowToScreen( int *x, int *y )
286{
287 CGPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) );
288 p = [m_macWindow convertPoint:p toWindow:nil];
289 if ( x )
290 *x = p.x;
291 if ( y )
292 *y = p.y;
293}
294
524c47aa
SC
295wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
296 long style, long extraStyle, const wxString& name )
297{
298 wxNonOwnedWindowImpl* now = new wxNonOwnedWindowIPhoneImpl( wxpeer );
299 now->Create( parent, pos, size, style , extraStyle, name );
300 return now;
301}
de7cb655
SC
302
303wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
304{
305 UIWindow* toplevelwindow = now->GetWXWindow();
306 CGRect frame = [toplevelwindow bounds];
307 CGRect appframe = [[UIScreen mainScreen] applicationFrame];
308
c7109e1a 309 if ( now->GetWindowStyle() == wxDEFAULT_FRAME_STYLE && [[UIApplication sharedApplication] statusBarStyle] != UIStatusBarStyleBlackTranslucent)
de7cb655
SC
310 {
311 double offset = appframe.origin.y;
312 frame.origin.y += offset;
313 frame.size.height -= offset;
314 }
315
316 wxUIContentView* contentview = [[wxUIContentView alloc] initWithFrame:frame];
317 contentview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
318 wxUIContentViewController* controller = [[wxUIContentViewController alloc] init];
319 controller.view = contentview;
320 [contentview setController:controller];
321
322 wxWidgetIPhoneImpl* impl = new wxWidgetIPhoneImpl( now, contentview, true );
323 impl->InstallEventHandler();
324 [toplevelwindow addSubview:contentview];
325 return impl;
326}
327
328//
329// obj-c impl
330//
331
332@implementation wxUIContentView
333
334- (void) setController: (UIViewController*) controller
335{
336 _controller = controller;
337}
338
339- (UIViewController*) controller
340{
341 return _controller;
342}
343
344@end
345
346@implementation wxUIContentViewController
347
348- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation
349{
350 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
351 wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
352
353 // TODO: determine NO or YES based on min size requirements (whether it fits on the new orientation)
354
355 return YES;
356}
357
358- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
359{
c7109e1a 360 CGRect frame = [self.view frame];
de7cb655
SC
361 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
362 wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
c7109e1a
SC
363
364 if ( now->GetWindowStyle() == wxDEFAULT_FRAME_STYLE && [[UIApplication sharedApplication] statusBarStyle] == UIStatusBarStyleBlackTranslucent)
365 {
366 CGRect appframe = [[UIScreen mainScreen] applicationFrame];
367 if ( CGRectEqualToRect(appframe, frame) )
368 {
369 if ( appframe.origin.y != 0 )
370 {
371 double offset = appframe.origin.y;
372 frame.origin.y -= offset;
373 frame.size.height += offset;
374 }
375 else
376 {
377 double offset = appframe.origin.x;
378 frame.origin.x -= offset;
379 frame.size.width += offset;
380 }
381
382 [self.view setFrame:frame];
383 }
384 }
de7cb655
SC
385
386 now->HandleResized(0);
387}
388
389-(void) dealloc
390{
391 [super dealloc];
392}
393
394- (UIView*) rotatingFooterView
395{
396 UIView* footerView = [super rotatingFooterView];
397 if ( footerView == nil )
398 {
399 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
400 wxFrame* frame = dynamic_cast<wxFrame*> (impl->GetWXPeer());
401 if ( frame && frame->GetToolBar())
402 {
403 footerView = frame->GetToolBar()->GetHandle();
404 }
405 }
406}
407
408@end
409
410
411