1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/osx/cocoa/nonownedwnd.mm
3 // Purpose: non owned window for iphone
4 // Author: Stefan Csomor
7 // RCS-ID: $Id: nonownedwnd.mm 48805 2007-09-19 14:52:25Z SC $
8 // Copyright: (c) Stefan Csomor
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
14 #include "wx/osx/private.h"
16 #include "wx/nonownedwnd.h"
19 CGRect wxToNSRect(UIView* parent, const wxRect& r )
21 CGRect frame = parent ? [parent bounds] : [[UIScreen mainScreen] bounds];
24 return CGRectMake(x, y, r.width , r.height);
27 wxRect wxFromNSRect( UIView* parent, const CGRect& rect )
29 CGRect frame = parent ? [parent bounds] : [[UIScreen mainScreen] bounds];
30 int y = rect.origin.y;
31 int x = rect.origin.x;
32 return wxRect( x, y, rect.size.width, rect.size.height );
35 CGPoint wxToNSPoint( UIView* parent, const wxPoint& p )
37 CGRect frame = parent ? [parent bounds] : [[UIScreen mainScreen] bounds];
40 return CGPointMake(x, y);
43 wxPoint wxFromNSPoint( UIView* parent, const CGPoint& p )
45 CGRect frame = parent ? [parent bounds] : [[UIScreen mainScreen] bounds];
48 return wxPoint( x, y);
52 IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowIPhoneImpl , wxNonOwnedWindowImpl )
54 wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl( wxNonOwnedWindow* nonownedwnd) :
55 wxNonOwnedWindowImpl(nonownedwnd)
58 m_macFullScreenData = NULL;
61 wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl()
64 m_macFullScreenData = NULL;
67 wxNonOwnedWindowIPhoneImpl::~wxNonOwnedWindowIPhoneImpl()
69 [m_macWindow release];
72 void wxNonOwnedWindowIPhoneImpl::Destroy()
74 wxPendingDelete.Append( new wxDeferredObjectDeleter( this ) );
77 void wxNonOwnedWindowIPhoneImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size,
78 long style, long extraStyle, const wxString& name )
80 m_macWindow = [UIWindow alloc];
82 UIWindowLevel level = UIWindowLevelNormal;
84 // most styles are not supported on the iphone
86 if ( style & wxFRAME_TOOL_WINDOW )
88 level = UIWindowLevelAlert; ;
90 else if ( ( style & wxPOPUP_WINDOW ) )
92 level = UIWindowLevelAlert;;
94 else if ( ( style & wxCAPTION ) )
97 else if ( ( style & wxFRAME_DRAWER ) )
104 if ( ( style & wxSTAY_ON_TOP ) )
105 level = UIWindowLevelAlert;
106 CGRect r = CGRectMake( 0, 0, size.x, size.y) ;
108 [m_macWindow initWithFrame:r ];
110 [m_macWindow setWindowLevel:level];
111 // [m_macWindow makeKeyAndOrderFront:nil];
115 WXWindow wxNonOwnedWindowIPhoneImpl::GetWXWindow() const
120 void wxNonOwnedWindowIPhoneImpl::Raise()
124 void wxNonOwnedWindowIPhoneImpl::Lower()
128 bool wxNonOwnedWindowIPhoneImpl::Show(bool show)
130 [m_macWindow setHidden:(show ? NO : YES)];
133 //[m_macWindow orderFront: self];
134 [m_macWindow makeKeyWindow];
139 bool wxNonOwnedWindowIPhoneImpl::ShowWithEffect(bool show, wxShowEffect effect, unsigned timeout)
144 void wxNonOwnedWindowIPhoneImpl::Update()
146 // TODO [m_macWindow displayIfNeeded];
149 bool wxNonOwnedWindowIPhoneImpl::SetTransparent(wxByte alpha)
151 [m_macWindow setAlpha:(CGFloat) alpha/255.0];
155 bool wxNonOwnedWindowIPhoneImpl::SetBackgroundColour(const wxColour& col )
160 void wxNonOwnedWindowIPhoneImpl::SetExtraStyle( long exStyle )
162 // no special styles supported
165 bool wxNonOwnedWindowIPhoneImpl::SetBackgroundStyle(wxBackgroundStyle style)
170 bool wxNonOwnedWindowIPhoneImpl::CanSetTransparent()
175 void wxNonOwnedWindowIPhoneImpl::MoveWindow(int x, int y, int width, int height)
177 CGRect r = CGRectMake( x,y,width,height) ;
178 [m_macWindow setFrame:r];
181 void wxNonOwnedWindowIPhoneImpl::GetPosition( int &x, int &y ) const
183 CGRect r = [m_macWindow frame];
188 void wxNonOwnedWindowIPhoneImpl::GetSize( int &width, int &height ) const
190 CGRect rect = [m_macWindow frame];
191 width = rect.size.width;
192 height = rect.size.height;
195 void wxNonOwnedWindowIPhoneImpl::GetContentArea( int& left, int &top, int &width, int &height ) const
197 CGRect rect = [m_macWindow bounds];
198 width = rect.size.width;
199 height = rect.size.height;
200 left = rect.origin.x;
204 bool wxNonOwnedWindowIPhoneImpl::SetShape(const wxRegion& region)
209 void wxNonOwnedWindowIPhoneImpl::SetTitle( const wxString& title, wxFontEncoding encoding )
211 // TODO change title of app ?
214 bool wxNonOwnedWindowIPhoneImpl::IsMaximized() const
219 bool wxNonOwnedWindowIPhoneImpl::IsIconized() const
224 void wxNonOwnedWindowIPhoneImpl::Iconize( bool iconize )
228 void wxNonOwnedWindowIPhoneImpl::Maximize(bool maximize)
232 bool wxNonOwnedWindowIPhoneImpl::IsFullScreen() const
234 return m_macFullScreenData != NULL ;
237 bool wxNonOwnedWindowIPhoneImpl::ShowFullScreen(bool show, long style)
242 void wxNonOwnedWindowIPhoneImpl::RequestUserAttention(int WXUNUSED(flags))
246 void wxNonOwnedWindowIPhoneImpl::ScreenToWindow( int *x, int *y )
248 CGPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) );
249 p = [m_macWindow convertPoint:p fromWindow:nil];
256 void wxNonOwnedWindowIPhoneImpl::WindowToScreen( int *x, int *y )
258 CGPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) );
259 p = [m_macWindow convertPoint:p toWindow:nil];
266 wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size,
267 long style, long extraStyle, const wxString& name )
269 wxNonOwnedWindowImpl* now = new wxNonOwnedWindowIPhoneImpl( wxpeer );
270 now->Create( parent, pos, size, style , extraStyle, name );