]>
Commit | Line | Data |
---|---|---|
c16b2153 | 1 | ///////////////////////////////////////////////////////////////////////////// |
80fdcdb9 | 2 | // Name: src/osx/iphone/nonownedwnd.mm |
c16b2153 SC |
3 | // Purpose: non owned window for iphone |
4 | // Author: Stefan Csomor | |
5 | // Modified by: | |
6 | // Created: 2008-06-20 | |
a9a4f229 | 7 | // RCS-ID: $Id$ |
c16b2153 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 |
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 | ||
de7cb655 SC |
52 | @interface wxUIContentViewController : UIViewController |
53 | { | |
54 | } | |
55 | ||
56 | @end | |
57 | ||
ba508df0 | 58 | @interface wxUIContentView : UIView |
de7cb655 SC |
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 |
73 | IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowIPhoneImpl , wxNonOwnedWindowImpl ) |
74 | ||
03647350 | 75 | wxNonOwnedWindowIPhoneImpl::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 | |
83 | wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl() | |
c16b2153 SC |
84 | { |
85 | m_macWindow = NULL; | |
86 | m_macFullScreenData = NULL; | |
4cc16dcb | 87 | m_initialShowSent = false; |
c16b2153 | 88 | } |
03647350 | 89 | |
c16b2153 SC |
90 | wxNonOwnedWindowIPhoneImpl::~wxNonOwnedWindowIPhoneImpl() |
91 | { | |
92 | [m_macWindow release]; | |
93 | } | |
94 | ||
0aaa6ace | 95 | void wxNonOwnedWindowIPhoneImpl::WillBeDestroyed() |
c16b2153 | 96 | { |
c16b2153 SC |
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]; | |
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 | ||
c61605ef SC |
138 | void wxNonOwnedWindowIPhoneImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow ) |
139 | { | |
140 | m_macWindow = nativeWindow; | |
141 | } | |
142 | ||
c16b2153 SC |
143 | |
144 | WXWindow wxNonOwnedWindowIPhoneImpl::GetWXWindow() const | |
145 | { | |
146 | return m_macWindow; | |
147 | } | |
148 | ||
149 | void wxNonOwnedWindowIPhoneImpl::Raise() | |
150 | { | |
151 | } | |
03647350 | 152 | |
c16b2153 SC |
153 | void wxNonOwnedWindowIPhoneImpl::Lower() |
154 | { | |
155 | } | |
156 | ||
157 | bool wxNonOwnedWindowIPhoneImpl::Show(bool show) | |
158 | { | |
159 | [m_macWindow setHidden:(show ? NO : YES)]; | |
160 | if ( show ) | |
161 | { | |
4cc16dcb SC |
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 | } | |
c16b2153 SC |
172 | //[m_macWindow orderFront: self]; |
173 | [m_macWindow makeKeyWindow]; | |
174 | } | |
175 | return true; | |
176 | } | |
03647350 | 177 | |
c16b2153 SC |
178 | bool wxNonOwnedWindowIPhoneImpl::ShowWithEffect(bool show, wxShowEffect effect, unsigned timeout) |
179 | { | |
180 | return Show(show); | |
181 | } | |
182 | ||
183 | void wxNonOwnedWindowIPhoneImpl::Update() | |
184 | { | |
185 | // TODO [m_macWindow displayIfNeeded]; | |
186 | } | |
187 | ||
188 | bool wxNonOwnedWindowIPhoneImpl::SetTransparent(wxByte alpha) | |
189 | { | |
190 | [m_macWindow setAlpha:(CGFloat) alpha/255.0]; | |
191 | return true; | |
192 | } | |
193 | ||
194 | bool wxNonOwnedWindowIPhoneImpl::SetBackgroundColour(const wxColour& col ) | |
195 | { | |
196 | return true; | |
197 | } | |
198 | ||
199 | void wxNonOwnedWindowIPhoneImpl::SetExtraStyle( long exStyle ) | |
200 | { | |
201 | // no special styles supported | |
202 | } | |
03647350 | 203 | |
c16b2153 SC |
204 | bool wxNonOwnedWindowIPhoneImpl::SetBackgroundStyle(wxBackgroundStyle style) |
205 | { | |
206 | return true; | |
207 | } | |
03647350 | 208 | |
c16b2153 SC |
209 | bool wxNonOwnedWindowIPhoneImpl::CanSetTransparent() |
210 | { | |
211 | return true; | |
212 | } | |
213 | ||
214 | void wxNonOwnedWindowIPhoneImpl::MoveWindow(int x, int y, int width, int height) | |
215 | { | |
d3929256 | 216 | CGRect r = CGRectMake( x,y,width,height) ; |
de7cb655 SC |
217 | if ( UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]) ) |
218 | std::swap(r.size.width,r.size.height); | |
219 | ||
c16b2153 SC |
220 | [m_macWindow setFrame:r]; |
221 | } | |
222 | ||
223 | void 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 | ||
230 | void wxNonOwnedWindowIPhoneImpl::GetSize( int &width, int &height ) const | |
231 | { | |
de7cb655 SC |
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; | |
c16b2153 SC |
237 | } |
238 | ||
d3929256 | 239 | void wxNonOwnedWindowIPhoneImpl::GetContentArea( int& left, int &top, int &width, int &height ) const |
c16b2153 | 240 | { |
de7cb655 SC |
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; | |
c16b2153 | 248 | } |
03647350 | 249 | |
c16b2153 SC |
250 | bool wxNonOwnedWindowIPhoneImpl::SetShape(const wxRegion& region) |
251 | { | |
252 | return false; | |
253 | } | |
254 | ||
03647350 | 255 | void wxNonOwnedWindowIPhoneImpl::SetTitle( const wxString& title, wxFontEncoding encoding ) |
c16b2153 SC |
256 | { |
257 | // TODO change title of app ? | |
258 | } | |
03647350 | 259 | |
c16b2153 SC |
260 | bool wxNonOwnedWindowIPhoneImpl::IsMaximized() const |
261 | { | |
262 | return false; | |
263 | } | |
03647350 | 264 | |
c16b2153 SC |
265 | bool wxNonOwnedWindowIPhoneImpl::IsIconized() const |
266 | { | |
267 | return false; | |
268 | } | |
03647350 | 269 | |
c16b2153 SC |
270 | void wxNonOwnedWindowIPhoneImpl::Iconize( bool iconize ) |
271 | { | |
272 | } | |
03647350 | 273 | |
c16b2153 SC |
274 | void wxNonOwnedWindowIPhoneImpl::Maximize(bool maximize) |
275 | { | |
01470e37 SC |
276 | if ( maximize ) |
277 | { | |
516e9d13 | 278 | CGRect r = [[UIScreen mainScreen] bounds]; |
01470e37 SC |
279 | [m_macWindow setFrame:r]; |
280 | } | |
c16b2153 SC |
281 | } |
282 | ||
283 | bool wxNonOwnedWindowIPhoneImpl::IsFullScreen() const | |
284 | { | |
285 | return m_macFullScreenData != NULL ; | |
286 | } | |
03647350 | 287 | |
c16b2153 | 288 | bool wxNonOwnedWindowIPhoneImpl::ShowFullScreen(bool show, long style) |
03647350 | 289 | { |
c16b2153 SC |
290 | return true; |
291 | } | |
292 | ||
293 | void wxNonOwnedWindowIPhoneImpl::RequestUserAttention(int WXUNUSED(flags)) | |
294 | { | |
295 | } | |
296 | ||
297 | void 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 | ||
307 | void 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 | ||
c61605ef SC |
317 | wxNonOwnedWindowImpl* 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 | ||
524c47aa SC |
325 | wxNonOwnedWindowImpl* 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 | } | |
de7cb655 SC |
332 | |
333 | wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now ) | |
334 | { | |
335 | UIWindow* toplevelwindow = now->GetWXWindow(); | |
336 | CGRect frame = [toplevelwindow bounds]; | |
337 | CGRect appframe = [[UIScreen mainScreen] applicationFrame]; | |
4cc16dcb SC |
338 | BOOL fullscreen = now->GetWindowStyle() == wxDEFAULT_FRAME_STYLE && [[UIApplication sharedApplication] statusBarStyle] == UIStatusBarStyleBlackTranslucent; |
339 | ||
340 | wxUIContentView* contentview = [[wxUIContentView alloc] initWithFrame:( fullscreen ? frame : appframe ) ]; | |
de7cb655 | 341 | contentview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; |
c61605ef | 342 | wxUIContentViewController* controller = [[wxUIContentViewController alloc] initWithNibName:nil bundle:nil]; |
6494f8d1 JS |
343 | |
344 | #ifdef __IPHONE_3_0 | |
4cc16dcb | 345 | controller.wantsFullScreenLayout = fullscreen; |
6494f8d1 JS |
346 | #endif |
347 | ||
de7cb655 | 348 | controller.view = contentview; |
4cc16dcb | 349 | [contentview release]; |
de7cb655 | 350 | [contentview setController:controller]; |
4cc16dcb | 351 | [contentview setHidden:YES]; |
de7cb655 SC |
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 | ||
4cc16dcb | 365 | - (void) setController: (wxUIContentViewController*) controller |
de7cb655 SC |
366 | { |
367 | _controller = controller; | |
368 | } | |
369 | ||
4cc16dcb | 370 | - (wxUIContentViewController*) controller |
de7cb655 SC |
371 | { |
372 | return _controller; | |
373 | } | |
374 | ||
ba508df0 SC |
375 | + (void)initialize |
376 | { | |
377 | static BOOL initialized = NO; | |
378 | if (!initialized) | |
379 | { | |
380 | initialized = YES; | |
381 | wxOSXIPhoneClassAddWXMethods( self ); | |
382 | } | |
383 | } | |
384 | ||
de7cb655 SC |
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 | { | |
de7cb655 SC |
401 | wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] ); |
402 | wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer()); | |
4cc16dcb SC |
403 | |
404 | now->HandleResized(0); | |
405 | } | |
c7109e1a | 406 | |
4cc16dcb SC |
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() ) | |
c7109e1a | 414 | { |
4cc16dcb SC |
415 | wxShowEvent eventShow(now->GetId(), true); |
416 | eventShow.SetEventObject(now); | |
417 | ||
418 | now->HandleWindowEvent(eventShow); | |
c7109e1a | 419 | } |
4cc16dcb SC |
420 | } |
421 | ||
422 | -(void) viewWillDisappear:(BOOL)animated | |
423 | { | |
424 | wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] ); | |
3fdfbc9c | 425 | if( impl ) |
4cc16dcb | 426 | { |
3fdfbc9c SC |
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 | } | |
4cc16dcb | 437 | } |
de7cb655 SC |
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 |