]> git.saurik.com Git - wxWidgets.git/blame_incremental - src/osx/iphone/nonownedwnd.mm
Update version to 2.9.4 in version.bkl too and rebake everything.
[wxWidgets.git] / src / osx / iphone / nonownedwnd.mm
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/iphone/nonownedwnd.mm
3// Purpose: non owned window for iphone
4// Author: Stefan Csomor
5// Modified by:
6// Created: 2008-06-20
7// RCS-ID: $Id$
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"
18#include <algorithm>
19
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
52@interface wxUIContentViewController : UIViewController
53{
54}
55
56@end
57
58@interface wxUIContentView : UIView
59{
60 wxUIContentViewController* _controller;
61}
62
63- (void) setController: (wxUIContentViewController*) controller;
64- (wxUIContentViewController*) controller;
65@end
66
67
68
69//
70// c++ impl
71//
72
73IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowIPhoneImpl , wxNonOwnedWindowImpl )
74
75wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl( wxNonOwnedWindow* nonownedwnd) :
76 wxNonOwnedWindowImpl(nonownedwnd)
77{
78 m_macWindow = NULL;
79 m_macFullScreenData = NULL;
80 m_initialShowSent = false;
81}
82
83wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl()
84{
85 m_macWindow = NULL;
86 m_macFullScreenData = NULL;
87 m_initialShowSent = false;
88}
89
90wxNonOwnedWindowIPhoneImpl::~wxNonOwnedWindowIPhoneImpl()
91{
92 [m_macWindow release];
93}
94
95void wxNonOwnedWindowIPhoneImpl::WillBeDestroyed()
96{
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];
103
104 UIWindowLevel level = UIWindowLevelNormal;
105
106 // most styles are not supported on the iphone
107
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 ) )
127 level = UIWindowLevelAlert;
128 CGRect r = CGRectMake( 0, 0, size.x, size.y) ;
129 if ( UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) )
130 std::swap(r.size.width,r.size.height);
131
132 [m_macWindow initWithFrame:r ];
133 [m_macWindow setHidden:YES];
134
135 [m_macWindow setWindowLevel:level];
136}
137
138void wxNonOwnedWindowIPhoneImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow )
139{
140 m_macWindow = nativeWindow;
141}
142
143
144WXWindow wxNonOwnedWindowIPhoneImpl::GetWXWindow() const
145{
146 return m_macWindow;
147}
148
149void wxNonOwnedWindowIPhoneImpl::Raise()
150{
151}
152
153void wxNonOwnedWindowIPhoneImpl::Lower()
154{
155}
156
157bool wxNonOwnedWindowIPhoneImpl::Show(bool show)
158{
159 [m_macWindow setHidden:(show ? NO : YES)];
160 if ( show )
161 {
162 if ( !m_initialShowSent )
163 {
164 wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (GetWXPeer());
165 wxShowEvent eventShow(now->GetId(), true);
166 eventShow.SetEventObject(now);
167
168 now->HandleWindowEvent(eventShow);
169
170 m_initialShowSent = true;
171 }
172 //[m_macWindow orderFront: self];
173 [m_macWindow makeKeyWindow];
174 }
175 return true;
176}
177
178bool wxNonOwnedWindowIPhoneImpl::ShowWithEffect(bool show, wxShowEffect effect, unsigned timeout)
179{
180 return Show(show);
181}
182
183void wxNonOwnedWindowIPhoneImpl::Update()
184{
185// TODO [m_macWindow displayIfNeeded];
186}
187
188bool wxNonOwnedWindowIPhoneImpl::SetTransparent(wxByte alpha)
189{
190 [m_macWindow setAlpha:(CGFloat) alpha/255.0];
191 return true;
192}
193
194bool wxNonOwnedWindowIPhoneImpl::SetBackgroundColour(const wxColour& col )
195{
196 return true;
197}
198
199void wxNonOwnedWindowIPhoneImpl::SetExtraStyle( long exStyle )
200{
201 // no special styles supported
202}
203
204bool wxNonOwnedWindowIPhoneImpl::SetBackgroundStyle(wxBackgroundStyle style)
205{
206 return true;
207}
208
209bool wxNonOwnedWindowIPhoneImpl::CanSetTransparent()
210{
211 return true;
212}
213
214void wxNonOwnedWindowIPhoneImpl::MoveWindow(int x, int y, int width, int height)
215{
216 CGRect r = CGRectMake( x,y,width,height) ;
217 if ( UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) )
218 std::swap(r.size.width,r.size.height);
219
220 [m_macWindow setFrame:r];
221}
222
223void wxNonOwnedWindowIPhoneImpl::GetPosition( int &x, int &y ) const
224{
225 CGRect r = [m_macWindow frame];
226 x = r.origin.x;
227 y = r.origin.y;
228}
229
230void wxNonOwnedWindowIPhoneImpl::GetSize( int &width, int &height ) const
231{
232 CGRect r = [m_macWindow frame];
233 if ( UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) )
234 std::swap(r.size.width,r.size.height);
235 width = r.size.width;
236 height = r.size.height;
237}
238
239void wxNonOwnedWindowIPhoneImpl::GetContentArea( int& left, int &top, int &width, int &height ) const
240{
241 CGRect r = [m_macWindow bounds];
242 if ( UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) )
243 std::swap(r.size.width,r.size.height);
244 width = r.size.width;
245 height = r.size.height;
246 left = r.origin.x;
247 top = r.origin.y;
248}
249
250bool wxNonOwnedWindowIPhoneImpl::SetShape(const wxRegion& region)
251{
252 return false;
253}
254
255void wxNonOwnedWindowIPhoneImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
256{
257// TODO change title of app ?
258}
259
260bool wxNonOwnedWindowIPhoneImpl::IsMaximized() const
261{
262 return false;
263}
264
265bool wxNonOwnedWindowIPhoneImpl::IsIconized() const
266{
267 return false;
268}
269
270void wxNonOwnedWindowIPhoneImpl::Iconize( bool iconize )
271{
272}
273
274void wxNonOwnedWindowIPhoneImpl::Maximize(bool maximize)
275{
276 if ( maximize )
277 {
278 CGRect r = [[UIScreen mainScreen] bounds];
279 [m_macWindow setFrame:r];
280 }
281}
282
283bool wxNonOwnedWindowIPhoneImpl::IsFullScreen() const
284{
285 return m_macFullScreenData != NULL ;
286}
287
288bool wxNonOwnedWindowIPhoneImpl::ShowFullScreen(bool show, long style)
289{
290 return true;
291}
292
293void wxNonOwnedWindowIPhoneImpl::RequestUserAttention(int WXUNUSED(flags))
294{
295}
296
297void wxNonOwnedWindowIPhoneImpl::ScreenToWindow( int *x, int *y )
298{
299 CGPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) );
300 p = [m_macWindow convertPoint:p fromWindow:nil];
301 if ( x )
302 *x = p.x;
303 if ( y )
304 *y = p.y;
305}
306
307void wxNonOwnedWindowIPhoneImpl::WindowToScreen( int *x, int *y )
308{
309 CGPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) );
310 p = [m_macWindow convertPoint:p toWindow:nil];
311 if ( x )
312 *x = p.x;
313 if ( y )
314 *y = p.y;
315}
316
317wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow)
318{
319 wxNonOwnedWindowIPhoneImpl* now = new wxNonOwnedWindowIPhoneImpl( wxpeer );
320 now->Create( parent, nativeWindow );
321 return now;
322}
323
324
325wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
326 long style, long extraStyle, const wxString& name )
327{
328 wxNonOwnedWindowImpl* now = new wxNonOwnedWindowIPhoneImpl( wxpeer );
329 now->Create( parent, pos, size, style , extraStyle, name );
330 return now;
331}
332
333wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
334{
335 UIWindow* toplevelwindow = now->GetWXWindow();
336 CGRect frame = [toplevelwindow bounds];
337 CGRect appframe = [[UIScreen mainScreen] applicationFrame];
338 BOOL fullscreen = now->GetWindowStyle() == wxDEFAULT_FRAME_STYLE && [[UIApplication sharedApplication] statusBarStyle] == UIStatusBarStyleBlackTranslucent;
339
340 wxUIContentView* contentview = [[wxUIContentView alloc] initWithFrame:( fullscreen ? frame : appframe ) ];
341 contentview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
342 wxUIContentViewController* controller = [[wxUIContentViewController alloc] initWithNibName:nil bundle:nil];
343
344#ifdef __IPHONE_3_0
345 controller.wantsFullScreenLayout = fullscreen;
346#endif
347
348 controller.view = contentview;
349 [contentview release];
350 [contentview setController:controller];
351 [contentview setHidden:YES];
352
353 wxWidgetIPhoneImpl* impl = new wxWidgetIPhoneImpl( now, contentview, true );
354 impl->InstallEventHandler();
355 [toplevelwindow addSubview:contentview];
356 return impl;
357}
358
359//
360// obj-c impl
361//
362
363@implementation wxUIContentView
364
365- (void) setController: (wxUIContentViewController*) controller
366{
367 _controller = controller;
368}
369
370- (wxUIContentViewController*) controller
371{
372 return _controller;
373}
374
375+ (void)initialize
376{
377 static BOOL initialized = NO;
378 if (!initialized)
379 {
380 initialized = YES;
381 wxOSXIPhoneClassAddWXMethods( self );
382 }
383}
384
385@end
386
387@implementation wxUIContentViewController
388
389- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation
390{
391 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
392 wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
393
394 // TODO: determine NO or YES based on min size requirements (whether it fits on the new orientation)
395
396 return YES;
397}
398
399- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
400{
401 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
402 wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
403
404 now->HandleResized(0);
405}
406
407-(void) viewWillAppear:(BOOL)animated
408{
409 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
410 wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
411 wxNonOwnedWindowIPhoneImpl* nowimpl = dynamic_cast<wxNonOwnedWindowIPhoneImpl*> (now->GetNonOwnedPeer());
412
413 if ( nowimpl->InitialShowEventSent() )
414 {
415 wxShowEvent eventShow(now->GetId(), true);
416 eventShow.SetEventObject(now);
417
418 now->HandleWindowEvent(eventShow);
419 }
420}
421
422-(void) viewWillDisappear:(BOOL)animated
423{
424 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
425 if( impl )
426 {
427 wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
428 wxNonOwnedWindowIPhoneImpl* nowimpl = dynamic_cast<wxNonOwnedWindowIPhoneImpl*> (now->GetNonOwnedPeer());
429
430 if ( nowimpl->InitialShowEventSent() )
431 {
432 wxShowEvent eventShow(now->GetId(), false);
433 eventShow.SetEventObject(now);
434
435 now->HandleWindowEvent(eventShow);
436 }
437 }
438}
439
440-(void) dealloc
441{
442 [super dealloc];
443}
444
445- (UIView*) rotatingFooterView
446{
447 UIView* footerView = [super rotatingFooterView];
448 if ( footerView == nil )
449 {
450 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
451 wxFrame* frame = dynamic_cast<wxFrame*> (impl->GetWXPeer());
452 if ( frame && frame->GetToolBar())
453 {
454 footerView = frame->GetToolBar()->GetHandle();
455 }
456 }
457}
458
459@end
460
461
462