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