]> git.saurik.com Git - wxWidgets.git/blob - src/osx/iphone/nonownedwnd.mm
Correct typo in configure introduced in r63832.
[wxWidgets.git] / src / osx / iphone / nonownedwnd.mm
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/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: 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"
18 #include <algorithm>
19
20 CGRect 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
28 wxRect 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
36 CGPoint 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
44 wxPoint 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 : wxUIView
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
73 IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowIPhoneImpl , wxNonOwnedWindowImpl )
74
75 wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl( wxNonOwnedWindow* nonownedwnd) :
76 wxNonOwnedWindowImpl(nonownedwnd)
77 {
78 m_macWindow = NULL;
79 m_macFullScreenData = NULL;
80 m_initialShowSent = false;
81 }
82
83 wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl()
84 {
85 m_macWindow = NULL;
86 m_macFullScreenData = NULL;
87 m_initialShowSent = false;
88 }
89
90 wxNonOwnedWindowIPhoneImpl::~wxNonOwnedWindowIPhoneImpl()
91 {
92 [m_macWindow release];
93 }
94
95 void wxNonOwnedWindowIPhoneImpl::WillBeDestroyed()
96 {
97 }
98
99 void wxNonOwnedWindowIPhoneImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
100 long 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
138
139 WXWindow wxNonOwnedWindowIPhoneImpl::GetWXWindow() const
140 {
141 return m_macWindow;
142 }
143
144 void wxNonOwnedWindowIPhoneImpl::Raise()
145 {
146 }
147
148 void wxNonOwnedWindowIPhoneImpl::Lower()
149 {
150 }
151
152 bool wxNonOwnedWindowIPhoneImpl::Show(bool show)
153 {
154 [m_macWindow setHidden:(show ? NO : YES)];
155 if ( show )
156 {
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 }
167 //[m_macWindow orderFront: self];
168 [m_macWindow makeKeyWindow];
169 }
170 return true;
171 }
172
173 bool wxNonOwnedWindowIPhoneImpl::ShowWithEffect(bool show, wxShowEffect effect, unsigned timeout)
174 {
175 return Show(show);
176 }
177
178 void wxNonOwnedWindowIPhoneImpl::Update()
179 {
180 // TODO [m_macWindow displayIfNeeded];
181 }
182
183 bool wxNonOwnedWindowIPhoneImpl::SetTransparent(wxByte alpha)
184 {
185 [m_macWindow setAlpha:(CGFloat) alpha/255.0];
186 return true;
187 }
188
189 bool wxNonOwnedWindowIPhoneImpl::SetBackgroundColour(const wxColour& col )
190 {
191 return true;
192 }
193
194 void wxNonOwnedWindowIPhoneImpl::SetExtraStyle( long exStyle )
195 {
196 // no special styles supported
197 }
198
199 bool wxNonOwnedWindowIPhoneImpl::SetBackgroundStyle(wxBackgroundStyle style)
200 {
201 return true;
202 }
203
204 bool wxNonOwnedWindowIPhoneImpl::CanSetTransparent()
205 {
206 return true;
207 }
208
209 void wxNonOwnedWindowIPhoneImpl::MoveWindow(int x, int y, int width, int height)
210 {
211 CGRect r = CGRectMake( x,y,width,height) ;
212 if ( UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) )
213 std::swap(r.size.width,r.size.height);
214
215 [m_macWindow setFrame:r];
216 }
217
218 void 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
225 void wxNonOwnedWindowIPhoneImpl::GetSize( int &width, int &height ) const
226 {
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;
232 }
233
234 void wxNonOwnedWindowIPhoneImpl::GetContentArea( int& left, int &top, int &width, int &height ) const
235 {
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;
243 }
244
245 bool wxNonOwnedWindowIPhoneImpl::SetShape(const wxRegion& region)
246 {
247 return false;
248 }
249
250 void wxNonOwnedWindowIPhoneImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
251 {
252 // TODO change title of app ?
253 }
254
255 bool wxNonOwnedWindowIPhoneImpl::IsMaximized() const
256 {
257 return false;
258 }
259
260 bool wxNonOwnedWindowIPhoneImpl::IsIconized() const
261 {
262 return false;
263 }
264
265 void wxNonOwnedWindowIPhoneImpl::Iconize( bool iconize )
266 {
267 }
268
269 void wxNonOwnedWindowIPhoneImpl::Maximize(bool maximize)
270 {
271 }
272
273 bool wxNonOwnedWindowIPhoneImpl::IsFullScreen() const
274 {
275 return m_macFullScreenData != NULL ;
276 }
277
278 bool wxNonOwnedWindowIPhoneImpl::ShowFullScreen(bool show, long style)
279 {
280 return true;
281 }
282
283 void wxNonOwnedWindowIPhoneImpl::RequestUserAttention(int WXUNUSED(flags))
284 {
285 }
286
287 void 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
297 void 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
307 wxNonOwnedWindowImpl* 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 }
314
315 wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
316 {
317 UIWindow* toplevelwindow = now->GetWXWindow();
318 CGRect frame = [toplevelwindow bounds];
319 CGRect appframe = [[UIScreen mainScreen] applicationFrame];
320 BOOL fullscreen = now->GetWindowStyle() == wxDEFAULT_FRAME_STYLE && [[UIApplication sharedApplication] statusBarStyle] == UIStatusBarStyleBlackTranslucent;
321
322 wxUIContentView* contentview = [[wxUIContentView alloc] initWithFrame:( fullscreen ? frame : appframe ) ];
323 contentview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
324 wxUIContentViewController* controller = [[wxUIContentViewController alloc] init];
325 controller.wantsFullScreenLayout = fullscreen;
326 controller.view = contentview;
327 [contentview release];
328 [contentview setController:controller];
329 [contentview setHidden:YES];
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
343 - (void) setController: (wxUIContentViewController*) controller
344 {
345 _controller = controller;
346 }
347
348 - (wxUIContentViewController*) controller
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 {
369 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
370 wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
371
372 now->HandleResized(0);
373 }
374
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() )
382 {
383 wxShowEvent eventShow(now->GetId(), true);
384 eventShow.SetEventObject(now);
385
386 now->HandleWindowEvent(eventShow);
387 }
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());
395
396 if ( nowimpl->InitialShowEventSent() )
397 {
398 wxShowEvent eventShow(now->GetId(), false);
399 eventShow.SetEventObject(now);
400
401 now->HandleWindowEvent(eventShow);
402 }
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