| 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 | |
| 19 | CGRect wxToNSRect(UIView* parent, const wxRect& r ) |
| 20 | { |
| 21 | CGRect frame = parent ? [parent bounds] : [[UIScreen mainScreen] bounds]; |
| 22 | int y = r.y; |
| 23 | int x = r.x ; |
| 24 | return CGRectMake(x, y, r.width , r.height); |
| 25 | } |
| 26 | |
| 27 | wxRect wxFromNSRect( UIView* parent, const CGRect& rect ) |
| 28 | { |
| 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 ); |
| 33 | } |
| 34 | |
| 35 | CGPoint wxToNSPoint( UIView* parent, const wxPoint& p ) |
| 36 | { |
| 37 | CGRect frame = parent ? [parent bounds] : [[UIScreen mainScreen] bounds]; |
| 38 | int x = p.x ; |
| 39 | int y = p.y; |
| 40 | return CGPointMake(x, y); |
| 41 | } |
| 42 | |
| 43 | wxPoint wxFromNSPoint( UIView* parent, const CGPoint& p ) |
| 44 | { |
| 45 | CGRect frame = parent ? [parent bounds] : [[UIScreen mainScreen] bounds]; |
| 46 | int x = p.x; |
| 47 | int y = p.y; |
| 48 | return wxPoint( x, y); |
| 49 | } |
| 50 | |
| 51 | |
| 52 | IMPLEMENT_DYNAMIC_CLASS( wxNonOwnedWindowIPhoneImpl , wxNonOwnedWindowImpl ) |
| 53 | |
| 54 | wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl( wxNonOwnedWindow* nonownedwnd) : |
| 55 | wxNonOwnedWindowImpl(nonownedwnd) |
| 56 | { |
| 57 | m_macWindow = NULL; |
| 58 | m_macFullScreenData = NULL; |
| 59 | } |
| 60 | |
| 61 | wxNonOwnedWindowIPhoneImpl::wxNonOwnedWindowIPhoneImpl() |
| 62 | { |
| 63 | m_macWindow = NULL; |
| 64 | m_macFullScreenData = NULL; |
| 65 | } |
| 66 | |
| 67 | wxNonOwnedWindowIPhoneImpl::~wxNonOwnedWindowIPhoneImpl() |
| 68 | { |
| 69 | [m_macWindow release]; |
| 70 | } |
| 71 | |
| 72 | void wxNonOwnedWindowIPhoneImpl::Destroy() |
| 73 | { |
| 74 | wxPendingDelete.Append( new wxDeferredObjectDeleter( this ) ); |
| 75 | } |
| 76 | |
| 77 | void wxNonOwnedWindowIPhoneImpl::Create( wxWindow* parent, const wxPoint& pos, const wxSize& size, |
| 78 | long style, long extraStyle, const wxString& name ) |
| 79 | { |
| 80 | m_macWindow = [UIWindow alloc]; |
| 81 | |
| 82 | UIWindowLevel level = UIWindowLevelNormal; |
| 83 | |
| 84 | // most styles are not supported on the iphone |
| 85 | |
| 86 | if ( style & wxFRAME_TOOL_WINDOW ) |
| 87 | { |
| 88 | level = UIWindowLevelAlert; ; |
| 89 | } |
| 90 | else if ( ( style & wxPOPUP_WINDOW ) ) |
| 91 | { |
| 92 | level = UIWindowLevelAlert;; |
| 93 | } |
| 94 | else if ( ( style & wxCAPTION ) ) |
| 95 | { |
| 96 | } |
| 97 | else if ( ( style & wxFRAME_DRAWER ) ) |
| 98 | { |
| 99 | } |
| 100 | else |
| 101 | { |
| 102 | } |
| 103 | |
| 104 | if ( ( style & wxSTAY_ON_TOP ) ) |
| 105 | level = UIWindowLevelAlert; |
| 106 | CGRect r = CGRectMake( 0, 0, size.x, size.y) ; |
| 107 | |
| 108 | [m_macWindow initWithFrame:r ]; |
| 109 | |
| 110 | [m_macWindow setWindowLevel:level]; |
| 111 | // [m_macWindow makeKeyAndOrderFront:nil]; |
| 112 | } |
| 113 | |
| 114 | |
| 115 | WXWindow wxNonOwnedWindowIPhoneImpl::GetWXWindow() const |
| 116 | { |
| 117 | return m_macWindow; |
| 118 | } |
| 119 | |
| 120 | void wxNonOwnedWindowIPhoneImpl::Raise() |
| 121 | { |
| 122 | } |
| 123 | |
| 124 | void wxNonOwnedWindowIPhoneImpl::Lower() |
| 125 | { |
| 126 | } |
| 127 | |
| 128 | bool wxNonOwnedWindowIPhoneImpl::Show(bool show) |
| 129 | { |
| 130 | [m_macWindow setHidden:(show ? NO : YES)]; |
| 131 | if ( show ) |
| 132 | { |
| 133 | //[m_macWindow orderFront: self]; |
| 134 | [m_macWindow makeKeyWindow]; |
| 135 | } |
| 136 | return true; |
| 137 | } |
| 138 | |
| 139 | bool wxNonOwnedWindowIPhoneImpl::ShowWithEffect(bool show, wxShowEffect effect, unsigned timeout) |
| 140 | { |
| 141 | return Show(show); |
| 142 | } |
| 143 | |
| 144 | void wxNonOwnedWindowIPhoneImpl::Update() |
| 145 | { |
| 146 | // TODO [m_macWindow displayIfNeeded]; |
| 147 | } |
| 148 | |
| 149 | bool wxNonOwnedWindowIPhoneImpl::SetTransparent(wxByte alpha) |
| 150 | { |
| 151 | [m_macWindow setAlpha:(CGFloat) alpha/255.0]; |
| 152 | return true; |
| 153 | } |
| 154 | |
| 155 | bool wxNonOwnedWindowIPhoneImpl::SetBackgroundColour(const wxColour& col ) |
| 156 | { |
| 157 | return true; |
| 158 | } |
| 159 | |
| 160 | void wxNonOwnedWindowIPhoneImpl::SetExtraStyle( long exStyle ) |
| 161 | { |
| 162 | // no special styles supported |
| 163 | } |
| 164 | |
| 165 | bool wxNonOwnedWindowIPhoneImpl::SetBackgroundStyle(wxBackgroundStyle style) |
| 166 | { |
| 167 | return true; |
| 168 | } |
| 169 | |
| 170 | bool wxNonOwnedWindowIPhoneImpl::CanSetTransparent() |
| 171 | { |
| 172 | return true; |
| 173 | } |
| 174 | |
| 175 | void wxNonOwnedWindowIPhoneImpl::MoveWindow(int x, int y, int width, int height) |
| 176 | { |
| 177 | CGRect r = CGRectMake( x,y,width,height) ; |
| 178 | [m_macWindow setFrame:r]; |
| 179 | } |
| 180 | |
| 181 | void wxNonOwnedWindowIPhoneImpl::GetPosition( int &x, int &y ) const |
| 182 | { |
| 183 | CGRect r = [m_macWindow frame]; |
| 184 | x = r.origin.x; |
| 185 | y = r.origin.y; |
| 186 | } |
| 187 | |
| 188 | void wxNonOwnedWindowIPhoneImpl::GetSize( int &width, int &height ) const |
| 189 | { |
| 190 | CGRect rect = [m_macWindow frame]; |
| 191 | width = rect.size.width; |
| 192 | height = rect.size.height; |
| 193 | } |
| 194 | |
| 195 | void wxNonOwnedWindowIPhoneImpl::GetContentArea( int& left, int &top, int &width, int &height ) const |
| 196 | { |
| 197 | CGRect rect = [m_macWindow frame]; |
| 198 | width = rect.size.width; |
| 199 | height = rect.size.height; |
| 200 | left = rect.origin.x; |
| 201 | top = rect.origin.y; |
| 202 | } |
| 203 | |
| 204 | bool wxNonOwnedWindowIPhoneImpl::SetShape(const wxRegion& region) |
| 205 | { |
| 206 | return false; |
| 207 | } |
| 208 | |
| 209 | void wxNonOwnedWindowIPhoneImpl::SetTitle( const wxString& title, wxFontEncoding encoding ) |
| 210 | { |
| 211 | // TODO change title of app ? |
| 212 | } |
| 213 | |
| 214 | bool wxNonOwnedWindowIPhoneImpl::IsMaximized() const |
| 215 | { |
| 216 | return false; |
| 217 | } |
| 218 | |
| 219 | bool wxNonOwnedWindowIPhoneImpl::IsIconized() const |
| 220 | { |
| 221 | return false; |
| 222 | } |
| 223 | |
| 224 | void wxNonOwnedWindowIPhoneImpl::Iconize( bool iconize ) |
| 225 | { |
| 226 | } |
| 227 | |
| 228 | void wxNonOwnedWindowIPhoneImpl::Maximize(bool maximize) |
| 229 | { |
| 230 | } |
| 231 | |
| 232 | bool wxNonOwnedWindowIPhoneImpl::IsFullScreen() const |
| 233 | { |
| 234 | return m_macFullScreenData != NULL ; |
| 235 | } |
| 236 | |
| 237 | bool wxNonOwnedWindowIPhoneImpl::ShowFullScreen(bool show, long style) |
| 238 | { |
| 239 | return true; |
| 240 | } |
| 241 | |
| 242 | void wxNonOwnedWindowIPhoneImpl::RequestUserAttention(int WXUNUSED(flags)) |
| 243 | { |
| 244 | } |
| 245 | |
| 246 | void wxNonOwnedWindowIPhoneImpl::ScreenToWindow( int *x, int *y ) |
| 247 | { |
| 248 | CGPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) ); |
| 249 | p = [m_macWindow convertPoint:p fromWindow:nil]; |
| 250 | if ( x ) |
| 251 | *x = p.x; |
| 252 | if ( y ) |
| 253 | *y = p.y; |
| 254 | } |
| 255 | |
| 256 | void wxNonOwnedWindowIPhoneImpl::WindowToScreen( int *x, int *y ) |
| 257 | { |
| 258 | CGPoint p = CGPointMake( (x ? *x : 0), (y ? *y : 0) ); |
| 259 | p = [m_macWindow convertPoint:p toWindow:nil]; |
| 260 | if ( x ) |
| 261 | *x = p.x; |
| 262 | if ( y ) |
| 263 | *y = p.y; |
| 264 | } |
| 265 | |
| 266 | wxNonOwnedWindowImpl* wxNonOwnedWindowImpl::CreateNonOwnedWindow( wxNonOwnedWindow* wxpeer, wxWindow* parent, const wxPoint& pos, const wxSize& size, |
| 267 | long style, long extraStyle, const wxString& name ) |
| 268 | { |
| 269 | wxNonOwnedWindowImpl* now = new wxNonOwnedWindowIPhoneImpl( wxpeer ); |
| 270 | now->Create( parent, pos, size, style , extraStyle, name ); |
| 271 | return now; |
| 272 | } |