]> git.saurik.com Git - wxWidgets.git/blame - src/osx/iphone/nonownedwnd.mm
Don't allow user to resize non-resizable columns to best size.
[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
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
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;
4cc16dcb 80 m_initialShowSent = false;
c16b2153 81}
03647350
VZ
82
83wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl()
c16b2153
SC
84{
85 m_macWindow = NULL;
86 m_macFullScreenData = NULL;
4cc16dcb 87 m_initialShowSent = false;
c16b2153 88}
03647350 89
c16b2153
SC
90wxNonOwnedWindowIPhoneImpl::~wxNonOwnedWindowIPhoneImpl()
91{
92 [m_macWindow release];
93}
94
0aaa6ace 95void wxNonOwnedWindowIPhoneImpl::WillBeDestroyed()
c16b2153 96{
c16b2153
SC
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];
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
138void wxNonOwnedWindowIPhoneImpl::Create( wxWindow* WXUNUSED(parent), WXWindow nativeWindow )
139{
140 m_macWindow = nativeWindow;
141}
142
c16b2153
SC
143
144WXWindow wxNonOwnedWindowIPhoneImpl::GetWXWindow() const
145{
146 return m_macWindow;
147}
148
149void wxNonOwnedWindowIPhoneImpl::Raise()
150{
151}
03647350 152
c16b2153
SC
153void wxNonOwnedWindowIPhoneImpl::Lower()
154{
155}
156
157bool 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
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}
03647350 203
c16b2153
SC
204bool wxNonOwnedWindowIPhoneImpl::SetBackgroundStyle(wxBackgroundStyle style)
205{
206 return true;
207}
03647350 208
c16b2153
SC
209bool wxNonOwnedWindowIPhoneImpl::CanSetTransparent()
210{
211 return true;
212}
213
214void 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
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{
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 239void 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
250bool wxNonOwnedWindowIPhoneImpl::SetShape(const wxRegion& region)
251{
252 return false;
253}
254
03647350 255void wxNonOwnedWindowIPhoneImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
c16b2153
SC
256{
257// TODO change title of app ?
258}
03647350 259
c16b2153
SC
260bool wxNonOwnedWindowIPhoneImpl::IsMaximized() const
261{
262 return false;
263}
03647350 264
c16b2153
SC
265bool wxNonOwnedWindowIPhoneImpl::IsIconized() const
266{
267 return false;
268}
03647350 269
c16b2153
SC
270void wxNonOwnedWindowIPhoneImpl::Iconize( bool iconize )
271{
272}
03647350 273
c16b2153
SC
274void wxNonOwnedWindowIPhoneImpl::Maximize(bool maximize)
275{
276}
277
278bool wxNonOwnedWindowIPhoneImpl::IsFullScreen() const
279{
280 return m_macFullScreenData != NULL ;
281}
03647350 282
c16b2153 283bool wxNonOwnedWindowIPhoneImpl::ShowFullScreen(bool show, long style)
03647350 284{
c16b2153
SC
285 return true;
286}
287
288void wxNonOwnedWindowIPhoneImpl::RequestUserAttention(int WXUNUSED(flags))
289{
290}
291
292void wxNonOwnedWindowIPhoneImpl::ScreenToWindow( int *x, int *y )
293{
294 CGPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) );
295 p = [m_macWindow convertPoint:p fromWindow:nil];
296 if ( x )
297 *x = p.x;
298 if ( y )
299 *y = p.y;
300}
301
302void wxNonOwnedWindowIPhoneImpl::WindowToScreen( int *x, int *y )
303{
304 CGPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) );
305 p = [m_macWindow convertPoint:p toWindow:nil];
306 if ( x )
307 *x = p.x;
308 if ( y )
309 *y = p.y;
310}
311
c61605ef
SC
312wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, WXWindow nativeWindow)
313{
314 wxNonOwnedWindowIPhoneImpl* now = new wxNonOwnedWindowIPhoneImpl( wxpeer );
315 now->Create( parent, nativeWindow );
316 return now;
317}
318
319
524c47aa
SC
320wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
321 long style, long extraStyle, const wxString& name )
322{
323 wxNonOwnedWindowImpl* now = new wxNonOwnedWindowIPhoneImpl( wxpeer );
324 now->Create( parent, pos, size, style , extraStyle, name );
325 return now;
326}
de7cb655
SC
327
328wxWidgetImpl* wxWidgetImpl::CreateContentView( wxNonOwnedWindow* now )
329{
330 UIWindow* toplevelwindow = now->GetWXWindow();
331 CGRect frame = [toplevelwindow bounds];
332 CGRect appframe = [[UIScreen mainScreen] applicationFrame];
4cc16dcb
SC
333 BOOL fullscreen = now->GetWindowStyle() == wxDEFAULT_FRAME_STYLE && [[UIApplication sharedApplication] statusBarStyle] == UIStatusBarStyleBlackTranslucent;
334
335 wxUIContentView* contentview = [[wxUIContentView alloc] initWithFrame:( fullscreen ? frame : appframe ) ];
de7cb655 336 contentview.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
c61605ef 337 wxUIContentViewController* controller = [[wxUIContentViewController alloc] initWithNibName:nil bundle:nil];
6494f8d1
JS
338
339#ifdef __IPHONE_3_0
4cc16dcb 340 controller.wantsFullScreenLayout = fullscreen;
6494f8d1
JS
341#endif
342
de7cb655 343 controller.view = contentview;
4cc16dcb 344 [contentview release];
de7cb655 345 [contentview setController:controller];
4cc16dcb 346 [contentview setHidden:YES];
de7cb655
SC
347
348 wxWidgetIPhoneImpl* impl = new wxWidgetIPhoneImpl( now, contentview, true );
349 impl->InstallEventHandler();
350 [toplevelwindow addSubview:contentview];
351 return impl;
352}
353
354//
355// obj-c impl
356//
357
358@implementation wxUIContentView
359
4cc16dcb 360- (void) setController: (wxUIContentViewController*) controller
de7cb655
SC
361{
362 _controller = controller;
363}
364
4cc16dcb 365- (wxUIContentViewController*) controller
de7cb655
SC
366{
367 return _controller;
368}
369
370@end
371
372@implementation wxUIContentViewController
373
374- (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation) interfaceOrientation
375{
376 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
377 wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
378
379 // TODO: determine NO or YES based on min size requirements (whether it fits on the new orientation)
380
381 return YES;
382}
383
384- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
385{
de7cb655
SC
386 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
387 wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
4cc16dcb
SC
388
389 now->HandleResized(0);
390}
c7109e1a 391
4cc16dcb
SC
392-(void) viewWillAppear:(BOOL)animated
393{
394 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
395 wxNonOwnedWindow* now = dynamic_cast<wxNonOwnedWindow*> (impl->GetWXPeer());
396 wxNonOwnedWindowIPhoneImpl* nowimpl = dynamic_cast<wxNonOwnedWindowIPhoneImpl*> (now->GetNonOwnedPeer());
397
398 if ( nowimpl->InitialShowEventSent() )
c7109e1a 399 {
4cc16dcb
SC
400 wxShowEvent eventShow(now->GetId(), true);
401 eventShow.SetEventObject(now);
402
403 now->HandleWindowEvent(eventShow);
c7109e1a 404 }
4cc16dcb
SC
405}
406
407-(void) viewWillDisappear:(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());
de7cb655 412
4cc16dcb
SC
413 if ( nowimpl->InitialShowEventSent() )
414 {
415 wxShowEvent eventShow(now->GetId(), false);
416 eventShow.SetEventObject(now);
417
418 now->HandleWindowEvent(eventShow);
419 }
de7cb655
SC
420}
421
422-(void) dealloc
423{
424 [super dealloc];
425}
426
427- (UIView*) rotatingFooterView
428{
429 UIView* footerView = [super rotatingFooterView];
430 if ( footerView == nil )
431 {
432 wxWidgetIPhoneImpl* impl = (wxWidgetIPhoneImpl* ) wxWidgetImpl::FindFromWXWidget( [self view] );
433 wxFrame* frame = dynamic_cast<wxFrame*> (impl->GetWXPeer());
434 if ( frame && frame->GetToolBar())
435 {
436 footerView = frame->GetToolBar()->GetHandle();
437 }
438 }
439}
440
441@end
442
443
444