]>
Commit | Line | Data |
---|---|---|
fb896a32 DE |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/cocoa/window.mm | |
3 | // Purpose: wxWindowCocoa | |
4 | // Author: David Elliott | |
5 | // Modified by: | |
6 | // Created: 2002/12/26 | |
7 | // RCS-ID: $Id: | |
8 | // Copyright: (c) 2002 David Elliott | |
9 | // Licence: wxWindows license | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | #include "wx/window.h" | |
13 | #include "wx/log.h" | |
14 | ||
7fc77f30 DE |
15 | #include "wx/cocoa/autorelease.h" |
16 | ||
fb896a32 | 17 | #import <Appkit/NSView.h> |
69dbb709 | 18 | #import <AppKit/NSEvent.h> |
816c52cf DE |
19 | #import <AppKit/NSScrollView.h> |
20 | #import <AppKit/NSColor.h> | |
21 | #import <AppKit/NSClipView.h> | |
fb896a32 | 22 | |
a82b8141 DE |
23 | // ======================================================================== |
24 | // wxWindowCocoaHider | |
25 | // ======================================================================== | |
26 | class wxWindowCocoaHider: protected wxCocoaNSView | |
27 | { | |
28 | DECLARE_NO_COPY_CLASS(wxWindowCocoaHider) | |
29 | public: | |
30 | wxWindowCocoaHider(wxWindow *owner); | |
31 | virtual ~wxWindowCocoaHider(); | |
32 | inline WX_NSView GetNSView() { return m_dummyNSView; } | |
33 | protected: | |
34 | wxWindowCocoa *m_owner; | |
35 | WX_NSView m_dummyNSView; | |
36 | virtual void Cocoa_FrameChanged(void); | |
37 | private: | |
38 | wxWindowCocoaHider(); | |
39 | }; | |
40 | ||
816c52cf DE |
41 | // ======================================================================== |
42 | // wxWindowCocoaScroller | |
43 | // ======================================================================== | |
44 | class wxWindowCocoaScroller: protected wxCocoaNSView | |
45 | { | |
46 | DECLARE_NO_COPY_CLASS(wxWindowCocoaScroller) | |
47 | public: | |
48 | wxWindowCocoaScroller(wxWindow *owner); | |
49 | virtual ~wxWindowCocoaScroller(); | |
50 | inline WX_NSScrollView GetNSScrollView() { return m_cocoaNSScrollView; } | |
51 | void ClientSizeToSize(int &width, int &height); | |
52 | void DoGetClientSize(int *x, int *y) const; | |
53 | void Encapsulate(); | |
54 | void Unencapsulate(); | |
55 | protected: | |
56 | wxWindowCocoa *m_owner; | |
57 | WX_NSScrollView m_cocoaNSScrollView; | |
58 | virtual void Cocoa_FrameChanged(void); | |
59 | private: | |
60 | wxWindowCocoaScroller(); | |
61 | }; | |
62 | ||
a82b8141 DE |
63 | // ======================================================================== |
64 | // wxWindowCocoaHider | |
65 | // ======================================================================== | |
66 | wxWindowCocoaHider::wxWindowCocoaHider(wxWindow *owner) | |
67 | : m_owner(owner) | |
68 | { | |
69 | wxASSERT(owner); | |
70 | wxASSERT(owner->GetNSViewForHiding()); | |
71 | m_dummyNSView = [[NSView alloc] | |
72 | initWithFrame:[owner->GetNSViewForHiding() frame]]; | |
73 | AssociateNSView(m_dummyNSView); | |
74 | } | |
75 | ||
76 | wxWindowCocoaHider::~wxWindowCocoaHider() | |
77 | { | |
78 | DisassociateNSView(m_dummyNSView); | |
79 | [m_dummyNSView release]; | |
80 | } | |
81 | ||
82 | void wxWindowCocoaHider::Cocoa_FrameChanged(void) | |
83 | { | |
84 | // Keep the real window in synch with the dummy | |
85 | wxASSERT(m_dummyNSView); | |
86 | [m_owner->GetNSViewForHiding() setFrame:[m_dummyNSView frame]]; | |
87 | } | |
88 | ||
816c52cf DE |
89 | // ======================================================================== |
90 | // wxFlippedNSClipView | |
91 | // ======================================================================== | |
92 | @interface wxFlippedNSClipView : NSClipView | |
93 | - (BOOL)isFlipped; | |
94 | @end | |
95 | ||
96 | @implementation wxFlippedNSClipView : NSClipView | |
97 | - (BOOL)isFlipped | |
98 | { | |
99 | return YES; | |
100 | } | |
101 | ||
102 | @end | |
103 | ||
104 | // ======================================================================== | |
105 | // wxWindowCocoaScroller | |
106 | // ======================================================================== | |
107 | wxWindowCocoaScroller::wxWindowCocoaScroller(wxWindow *owner) | |
108 | : m_owner(owner) | |
109 | { | |
110 | wxASSERT(owner); | |
111 | wxASSERT(owner->GetNSView()); | |
112 | m_cocoaNSScrollView = [[NSScrollView alloc] | |
113 | initWithFrame:[owner->GetNSView() frame]]; | |
114 | AssociateNSView(m_cocoaNSScrollView); | |
115 | ||
116 | /* Replace the default NSClipView with a flipped one. This ensures | |
117 | scrolling is "pinned" to the top-left instead of bottom-right. */ | |
118 | NSClipView *flippedClip = [[wxFlippedNSClipView alloc] | |
119 | initWithFrame: [[m_cocoaNSScrollView contentView] frame]]; | |
120 | [m_cocoaNSScrollView setContentView:flippedClip]; | |
121 | [flippedClip release]; | |
122 | ||
123 | [m_cocoaNSScrollView setBackgroundColor: [NSColor windowBackgroundColor]]; | |
124 | [m_cocoaNSScrollView setHasHorizontalScroller: YES]; | |
125 | [m_cocoaNSScrollView setHasVerticalScroller: YES]; | |
126 | Encapsulate(); | |
127 | } | |
128 | ||
129 | void wxWindowCocoaScroller::Encapsulate() | |
130 | { | |
131 | // NOTE: replaceSubView will cause m_cocaNSView to be released | |
132 | // except when it hasn't been added into an NSView hierarchy in which | |
133 | // case it doesn't need to be and this should work out to a no-op | |
134 | m_owner->CocoaReplaceView(m_owner->GetNSView(), m_cocoaNSScrollView); | |
135 | // The NSView is still retained by owner | |
136 | [m_cocoaNSScrollView setDocumentView: m_owner->GetNSView()]; | |
137 | // Now it's also retained by the NSScrollView | |
138 | } | |
139 | ||
140 | void wxWindowCocoaScroller::Unencapsulate() | |
141 | { | |
142 | [m_cocoaNSScrollView setDocumentView: nil]; | |
143 | m_owner->CocoaReplaceView(m_cocoaNSScrollView, m_owner->GetNSView()); | |
144 | } | |
145 | ||
146 | wxWindowCocoaScroller::~wxWindowCocoaScroller() | |
147 | { | |
148 | DisassociateNSView(m_cocoaNSScrollView); | |
149 | [m_cocoaNSScrollView release]; | |
150 | } | |
151 | ||
152 | void wxWindowCocoaScroller::ClientSizeToSize(int &width, int &height) | |
153 | { | |
154 | NSSize frameSize = [NSScrollView | |
155 | frameSizeForContentSize: NSMakeSize(width,height) | |
156 | hasHorizontalScroller: [m_cocoaNSScrollView hasHorizontalScroller] | |
157 | hasVerticalScroller: [m_cocoaNSScrollView hasVerticalScroller] | |
158 | borderType: [m_cocoaNSScrollView borderType]]; | |
159 | width = frameSize.width; | |
160 | height = frameSize.height; | |
161 | } | |
162 | ||
163 | void wxWindowCocoaScroller::DoGetClientSize(int *x, int *y) const | |
164 | { | |
165 | NSSize nssize = [m_cocoaNSScrollView contentSize]; | |
166 | if(x) | |
167 | *x = nssize.width; | |
168 | if(y) | |
169 | *y = nssize.height; | |
170 | } | |
171 | ||
172 | void wxWindowCocoaScroller::Cocoa_FrameChanged(void) | |
173 | { | |
174 | wxLogDebug("Cocoa_FrameChanged"); | |
175 | wxSizeEvent event(m_owner->GetSize(), m_owner->GetId()); | |
176 | event.SetEventObject(m_owner); | |
177 | m_owner->GetEventHandler()->ProcessEvent(event); | |
178 | } | |
179 | ||
a82b8141 DE |
180 | // ======================================================================== |
181 | // wxWindowCocoa | |
182 | // ======================================================================== | |
fb896a32 DE |
183 | // normally the base classes aren't included, but wxWindow is special |
184 | #ifdef __WXUNIVERSAL__ | |
185 | IMPLEMENT_ABSTRACT_CLASS(wxWindowCocoa, wxWindowBase) | |
186 | #else | |
187 | IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase) | |
188 | #endif | |
189 | ||
190 | BEGIN_EVENT_TABLE(wxWindowCocoa, wxWindowBase) | |
191 | END_EVENT_TABLE() | |
192 | ||
b9505233 DE |
193 | wxWindow *wxWindowCocoa::sm_capturedWindow = NULL; |
194 | ||
fb896a32 DE |
195 | // Constructor |
196 | void wxWindowCocoa::Init() | |
197 | { | |
198 | InitBase(); | |
199 | ||
200 | m_cocoaNSView = NULL; | |
a82b8141 | 201 | m_cocoaHider = NULL; |
816c52cf | 202 | m_cocoaScroller = NULL; |
fb896a32 | 203 | m_isBeingDeleted = FALSE; |
55c5be5e | 204 | m_isInPaint = FALSE; |
fb896a32 DE |
205 | } |
206 | ||
207 | // Constructor | |
208 | bool wxWindow::Create(wxWindow *parent, wxWindowID winid, | |
209 | const wxPoint& pos, | |
210 | const wxSize& size, | |
211 | long style, | |
212 | const wxString& name) | |
213 | { | |
214 | if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name)) | |
215 | return false; | |
216 | ||
217 | // TODO: create the window | |
fb896a32 | 218 | m_cocoaNSView = NULL; |
d139c3a8 | 219 | SetNSView([[NSView alloc] initWithFrame: MakeDefaultNSRect(size)]); |
fb896a32 DE |
220 | [m_cocoaNSView release]; |
221 | ||
222 | if (m_parent) | |
223 | { | |
224 | m_parent->AddChild(this); | |
225 | m_parent->CocoaAddChild(this); | |
226 | } | |
d139c3a8 | 227 | SetInitialFrameRect(pos,size); |
fb896a32 DE |
228 | |
229 | return TRUE; | |
230 | } | |
231 | ||
232 | // Destructor | |
233 | wxWindow::~wxWindow() | |
234 | { | |
7fc77f30 | 235 | wxAutoNSAutoreleasePool pool; |
fb896a32 DE |
236 | DestroyChildren(); |
237 | ||
238 | if(m_parent) | |
239 | m_parent->RemoveChild(this); | |
240 | ||
241 | CocoaRemoveFromParent(); | |
a82b8141 | 242 | delete m_cocoaHider; |
816c52cf | 243 | delete m_cocoaScroller; |
fb896a32 DE |
244 | SetNSView(NULL); |
245 | } | |
246 | ||
247 | void wxWindowCocoa::CocoaAddChild(wxWindowCocoa *child) | |
248 | { | |
a82b8141 DE |
249 | NSView *childView = child->GetNSViewForSuperview(); |
250 | ||
251 | wxASSERT(childView); | |
252 | [m_cocoaNSView addSubview: childView]; | |
253 | child->m_isShown = !m_cocoaHider; | |
fb896a32 DE |
254 | } |
255 | ||
256 | void wxWindowCocoa::CocoaRemoveFromParent(void) | |
257 | { | |
a82b8141 | 258 | [GetNSViewForSuperview() removeFromSuperview]; |
fb896a32 DE |
259 | } |
260 | ||
261 | void wxWindowCocoa::SetNSView(WX_NSView cocoaNSView) | |
262 | { | |
263 | bool need_debug = cocoaNSView || m_cocoaNSView; | |
264 | if(need_debug) wxLogDebug("wxWindowCocoa=%p::SetNSView [m_cocoaNSView=%p retainCount]=%d",this,m_cocoaNSView,[m_cocoaNSView retainCount]); | |
bac6f234 | 265 | DisassociateNSView(m_cocoaNSView); |
fb896a32 DE |
266 | [cocoaNSView retain]; |
267 | [m_cocoaNSView release]; | |
268 | m_cocoaNSView = cocoaNSView; | |
bac6f234 | 269 | AssociateNSView(m_cocoaNSView); |
fb896a32 DE |
270 | if(need_debug) wxLogDebug("wxWindowCocoa=%p::SetNSView [cocoaNSView=%p retainCount]=%d",this,cocoaNSView,[cocoaNSView retainCount]); |
271 | } | |
272 | ||
a82b8141 DE |
273 | WX_NSView wxWindowCocoa::GetNSViewForSuperview() const |
274 | { | |
275 | return m_cocoaHider | |
276 | ? m_cocoaHider->GetNSView() | |
816c52cf DE |
277 | : m_cocoaScroller |
278 | ? m_cocoaScroller->GetNSScrollView() | |
279 | : m_cocoaNSView; | |
a82b8141 DE |
280 | } |
281 | ||
282 | WX_NSView wxWindowCocoa::GetNSViewForHiding() const | |
283 | { | |
816c52cf DE |
284 | return m_cocoaScroller |
285 | ? m_cocoaScroller->GetNSScrollView() | |
286 | : m_cocoaNSView; | |
a82b8141 DE |
287 | } |
288 | ||
8ea5271e DE |
289 | bool wxWindowCocoa::Cocoa_drawRect(const NSRect &rect) |
290 | { | |
291 | wxLogDebug("Cocoa_drawRect"); | |
55c5be5e DE |
292 | // Recursion can happen if the event loop runs from within the paint |
293 | // handler. For instance, if an assertion dialog is shown. | |
294 | // FIXME: This seems less than ideal. | |
295 | if(m_isInPaint) | |
296 | { | |
297 | wxLogDebug("Paint event recursion!"); | |
298 | return false; | |
299 | } | |
8ea5271e | 300 | //FIXME: should probably turn that rect into the update region |
55c5be5e | 301 | m_isInPaint = TRUE; |
8ea5271e DE |
302 | wxPaintEvent event(m_windowId); |
303 | event.SetEventObject(this); | |
55c5be5e DE |
304 | bool ret = GetEventHandler()->ProcessEvent(event); |
305 | m_isInPaint = FALSE; | |
306 | return ret; | |
8ea5271e DE |
307 | } |
308 | ||
69dbb709 DE |
309 | void wxWindowCocoa::InitMouseEvent(wxMouseEvent& event, WX_NSEvent cocoaEvent) |
310 | { | |
a82b8141 DE |
311 | wxASSERT_MSG([m_cocoaNSView window]==[cocoaEvent window],"Mouse event for different NSWindow"); |
312 | NSPoint cocoaPoint = [m_cocoaNSView convertPoint:[(NSEvent*)cocoaEvent locationInWindow] fromView:nil]; | |
313 | NSRect cocoaRect = [m_cocoaNSView frame]; | |
69dbb709 DE |
314 | const wxPoint &clientorigin = GetClientAreaOrigin(); |
315 | event.m_x = (wxCoord)cocoaPoint.x - clientorigin.x; | |
316 | event.m_y = (wxCoord)(cocoaRect.size.height - cocoaPoint.y) - clientorigin.y; | |
317 | ||
318 | event.m_shiftDown = [cocoaEvent modifierFlags] & NSShiftKeyMask; | |
319 | event.m_controlDown = [cocoaEvent modifierFlags] & NSControlKeyMask; | |
320 | event.m_altDown = [cocoaEvent modifierFlags] & NSAlternateKeyMask; | |
321 | event.m_metaDown = [cocoaEvent modifierFlags] & NSCommandKeyMask; | |
322 | ||
323 | // TODO: set timestamp? | |
324 | event.SetEventObject(this); | |
325 | event.SetId(GetId()); | |
326 | } | |
327 | ||
328 | bool wxWindowCocoa::Cocoa_mouseMoved(WX_NSEvent theEvent) | |
329 | { | |
330 | wxMouseEvent event(wxEVT_MOTION); | |
331 | InitMouseEvent(event,theEvent); | |
332 | wxLogDebug("Mouse Drag @%d,%d",event.m_x,event.m_y); | |
333 | return GetEventHandler()->ProcessEvent(event); | |
334 | } | |
335 | ||
336 | bool wxWindowCocoa::Cocoa_mouseEntered(WX_NSEvent theEvent) | |
337 | { | |
338 | return false; | |
339 | } | |
340 | ||
341 | bool wxWindowCocoa::Cocoa_mouseExited(WX_NSEvent theEvent) | |
342 | { | |
343 | return false; | |
344 | } | |
345 | ||
346 | bool wxWindowCocoa::Cocoa_mouseDown(WX_NSEvent theEvent) | |
347 | { | |
348 | wxMouseEvent event([theEvent clickCount]<2?wxEVT_LEFT_DOWN:wxEVT_LEFT_DCLICK); | |
349 | InitMouseEvent(event,theEvent); | |
350 | wxLogDebug("Mouse Down @%d,%d num clicks=%d",event.m_x,event.m_y,[theEvent clickCount]); | |
351 | return GetEventHandler()->ProcessEvent(event); | |
352 | } | |
353 | ||
354 | bool wxWindowCocoa::Cocoa_mouseDragged(WX_NSEvent theEvent) | |
355 | { | |
356 | wxMouseEvent event(wxEVT_MOTION); | |
357 | InitMouseEvent(event,theEvent); | |
358 | event.m_leftDown = true; | |
359 | wxLogDebug("Mouse Drag @%d,%d",event.m_x,event.m_y); | |
360 | return GetEventHandler()->ProcessEvent(event); | |
361 | } | |
362 | ||
363 | bool wxWindowCocoa::Cocoa_mouseUp(WX_NSEvent theEvent) | |
364 | { | |
365 | wxMouseEvent event(wxEVT_LEFT_UP); | |
366 | InitMouseEvent(event,theEvent); | |
367 | wxLogDebug("Mouse Up @%d,%d",event.m_x,event.m_y); | |
368 | return GetEventHandler()->ProcessEvent(event); | |
369 | } | |
370 | ||
371 | bool wxWindowCocoa::Cocoa_rightMouseDown(WX_NSEvent theEvent) | |
372 | { | |
373 | return false; | |
374 | } | |
375 | ||
376 | bool wxWindowCocoa::Cocoa_rightMouseDragged(WX_NSEvent theEvent) | |
377 | { | |
378 | return false; | |
379 | } | |
380 | ||
381 | bool wxWindowCocoa::Cocoa_rightMouseUp(WX_NSEvent theEvent) | |
382 | { | |
383 | return false; | |
384 | } | |
385 | ||
386 | bool wxWindowCocoa::Cocoa_otherMouseDown(WX_NSEvent theEvent) | |
387 | { | |
388 | return false; | |
389 | } | |
390 | ||
391 | bool wxWindowCocoa::Cocoa_otherMouseDragged(WX_NSEvent theEvent) | |
392 | { | |
393 | return false; | |
394 | } | |
395 | ||
396 | bool wxWindowCocoa::Cocoa_otherMouseUp(WX_NSEvent theEvent) | |
397 | { | |
398 | return false; | |
399 | } | |
400 | ||
fb896a32 DE |
401 | void wxWindowCocoa::Cocoa_FrameChanged(void) |
402 | { | |
403 | wxLogDebug("Cocoa_FrameChanged"); | |
404 | wxSizeEvent event(GetSize(), m_windowId); | |
405 | event.SetEventObject(this); | |
406 | GetEventHandler()->ProcessEvent(event); | |
407 | } | |
408 | ||
409 | bool wxWindow::Close(bool force) | |
410 | { | |
411 | return false; | |
412 | } | |
413 | ||
a82b8141 DE |
414 | void wxWindow::CocoaReplaceView(WX_NSView oldView, WX_NSView newView) |
415 | { | |
416 | [[oldView superview] replaceSubview:oldView with:newView]; | |
417 | } | |
418 | ||
fb896a32 DE |
419 | bool wxWindow::Show(bool show) |
420 | { | |
7fc77f30 | 421 | wxAutoNSAutoreleasePool pool; |
fb896a32 DE |
422 | // If the window is marked as visible, then it shouldn't have a dummy view |
423 | // If the window is marked hidden, then it should have a dummy view | |
addbdd29 DE |
424 | // wxSpinCtrl (generic) abuses m_isShown, don't use it for any logic |
425 | // wxASSERT_MSG( (m_isShown && !m_dummyNSView) || (!m_isShown && m_dummyNSView),"wxWindow: m_isShown does not agree with m_dummyNSView"); | |
fb896a32 | 426 | // Return false if there isn't a window to show or hide |
a82b8141 DE |
427 | NSView *cocoaView = GetNSViewForHiding(); |
428 | if(!cocoaView) | |
fb896a32 | 429 | return false; |
fb896a32 DE |
430 | if(show) |
431 | { | |
addbdd29 | 432 | // If state isn't changing, return false |
a82b8141 | 433 | if(!m_cocoaHider) |
addbdd29 | 434 | return false; |
a82b8141 DE |
435 | CocoaReplaceView(m_cocoaHider->GetNSView(), cocoaView); |
436 | wxASSERT(![m_cocoaHider->GetNSView() superview]); | |
437 | delete m_cocoaHider; | |
438 | m_cocoaHider = NULL; | |
439 | wxASSERT([cocoaView superview]); | |
fb896a32 DE |
440 | } |
441 | else | |
442 | { | |
addbdd29 | 443 | // If state isn't changing, return false |
a82b8141 | 444 | if(m_cocoaHider) |
addbdd29 | 445 | return false; |
a82b8141 DE |
446 | m_cocoaHider = new wxWindowCocoaHider(this); |
447 | // NOTE: replaceSubview:with will cause m_cocaNSView to be | |
448 | // (auto)released which balances out addSubview | |
449 | CocoaReplaceView(cocoaView, m_cocoaHider->GetNSView()); | |
fb896a32 | 450 | // m_coocaNSView is now only retained by us |
a82b8141 DE |
451 | wxASSERT([m_cocoaHider->GetNSView() superview]); |
452 | wxASSERT(![cocoaView superview]); | |
fb896a32 | 453 | } |
a6b4ff2e DE |
454 | m_isShown = show; |
455 | return true; | |
fb896a32 DE |
456 | } |
457 | ||
458 | void wxWindowCocoa::DoSetSize(int x, int y, int width, int height, int sizeFlags) | |
459 | { | |
ddf7346a | 460 | // wxLogDebug("wxWindow=%p::DoSetSizeWindow(%d,%d,%d,%d,Auto: %s%s)",this,x,y,width,height,(sizeFlags&wxSIZE_AUTO_WIDTH)?"W":".",sizeFlags&wxSIZE_AUTO_HEIGHT?"H":"."); |
fb896a32 DE |
461 | int currentX, currentY; |
462 | int currentW, currentH; | |
463 | DoGetPosition(¤tX, ¤tY); | |
464 | DoGetSize(¤tW, ¤tH); | |
465 | if((x==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE)) | |
466 | x=currentX; | |
467 | if((y==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE)) | |
468 | y=currentY; | |
469 | ||
470 | AdjustForParentClientOrigin(x,y,sizeFlags); | |
471 | ||
472 | wxSize size(-1,-1); | |
473 | ||
474 | if((width==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE)) | |
475 | { | |
476 | if(sizeFlags&wxSIZE_AUTO_WIDTH) | |
477 | { | |
478 | size=DoGetBestSize(); | |
479 | width=size.x; | |
480 | } | |
481 | else | |
482 | width=currentW; | |
483 | } | |
484 | if((height==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE)) | |
485 | { | |
486 | if(sizeFlags&wxSIZE_AUTO_HEIGHT) | |
487 | { | |
488 | if(size.x==-1) | |
489 | size=DoGetBestSize(); | |
490 | height=size.y; | |
491 | } | |
492 | else | |
493 | height=currentH; | |
494 | } | |
495 | DoMoveWindow(x,y,width,height); | |
496 | } | |
497 | ||
498 | void wxWindowCocoa::DoMoveWindow(int x, int y, int width, int height) | |
499 | { | |
ddf7346a | 500 | // wxLogDebug("wxWindow=%p::DoMoveWindow(%d,%d,%d,%d)",this,x,y,width,height); |
fb896a32 | 501 | |
a82b8141 | 502 | NSView *nsview = GetNSViewForSuperview(); |
d449cf47 | 503 | NSView *superview = [nsview superview]; |
fb896a32 DE |
504 | wxCHECK_RET(superview,"NSView does not have a superview"); |
505 | NSRect parentRect = [superview frame]; | |
506 | ||
507 | NSRect cocoaRect = NSMakeRect(x,parentRect.size.height-(y+height),width,height); | |
a82b8141 | 508 | [nsview setFrame: cocoaRect]; |
fb896a32 DE |
509 | } |
510 | ||
d139c3a8 DE |
511 | void wxWindowCocoa::SetInitialFrameRect(const wxPoint& pos, const wxSize& size) |
512 | { | |
513 | NSView *nsview = GetNSViewForSuperview(); | |
514 | NSView *superview = [nsview superview]; | |
515 | wxCHECK_RET(superview,"NSView does not have a superview"); | |
516 | NSRect parentRect = [superview frame]; | |
517 | NSRect frameRect = [nsview frame]; | |
518 | if(size.x!=-1) | |
519 | frameRect.size.width = size.x; | |
520 | if(size.y!=-1) | |
521 | frameRect.size.height = size.y; | |
522 | frameRect.origin.x = pos.x; | |
523 | frameRect.origin.y = parentRect.size.height-(pos.y+size.y); | |
524 | [nsview setFrame: frameRect]; | |
525 | } | |
526 | ||
fb896a32 DE |
527 | // Get total size |
528 | void wxWindow::DoGetSize(int *w, int *h) const | |
529 | { | |
a82b8141 | 530 | NSRect cocoaRect = [GetNSViewForSuperview() frame]; |
fb896a32 DE |
531 | if(w) |
532 | *w=(int)cocoaRect.size.width; | |
533 | if(h) | |
534 | *h=(int)cocoaRect.size.height; | |
ddf7346a | 535 | // wxLogDebug("wxWindow=%p::DoGetSize = (%d,%d)",this,(int)cocoaRect.size.width,(int)cocoaRect.size.height); |
fb896a32 DE |
536 | } |
537 | ||
538 | void wxWindow::DoGetPosition(int *x, int *y) const | |
539 | { | |
a82b8141 | 540 | NSView *nsview = GetNSViewForSuperview(); |
576a1544 | 541 | NSView *superview = [nsview superview]; |
fb896a32 DE |
542 | wxCHECK_RET(superview,"NSView does not have a superview"); |
543 | NSRect parentRect = [superview frame]; | |
544 | ||
576a1544 | 545 | NSRect cocoaRect = [nsview frame]; |
fb896a32 DE |
546 | if(x) |
547 | *x=(int)cocoaRect.origin.x; | |
548 | if(y) | |
549 | *y=(int)(parentRect.size.height-(cocoaRect.origin.y+cocoaRect.size.height)); | |
ddf7346a | 550 | // wxLogDebug("wxWindow=%p::DoGetPosition = (%d,%d)",this,(int)cocoaRect.origin.x,(int)cocoaRect.origin.y); |
fb896a32 DE |
551 | } |
552 | ||
553 | WXWidget wxWindow::GetHandle() const | |
554 | { | |
555 | return m_cocoaNSView; | |
556 | } | |
557 | ||
ddf7346a DE |
558 | void wxWindow::Refresh(bool eraseBack, const wxRect *rect) |
559 | { | |
560 | [m_cocoaNSView setNeedsDisplay:YES]; | |
561 | } | |
562 | ||
fb896a32 DE |
563 | void wxWindow::SetFocus() |
564 | { | |
565 | // TODO | |
566 | } | |
567 | ||
568 | void wxWindow::DoCaptureMouse() | |
569 | { | |
570 | // TODO | |
b9505233 | 571 | sm_capturedWindow = this; |
fb896a32 DE |
572 | } |
573 | ||
574 | void wxWindow::DoReleaseMouse() | |
575 | { | |
576 | // TODO | |
b9505233 | 577 | sm_capturedWindow = NULL; |
fb896a32 DE |
578 | } |
579 | ||
580 | void wxWindow::DoScreenToClient(int *x, int *y) const | |
581 | { | |
582 | // TODO | |
583 | } | |
584 | ||
585 | void wxWindow::DoClientToScreen(int *x, int *y) const | |
586 | { | |
587 | // TODO | |
588 | } | |
589 | ||
590 | // Get size *available for subwindows* i.e. excluding menu bar etc. | |
591 | void wxWindow::DoGetClientSize(int *x, int *y) const | |
592 | { | |
593 | wxLogDebug("DoGetClientSize:"); | |
816c52cf DE |
594 | if(m_cocoaScroller) |
595 | m_cocoaScroller->DoGetClientSize(x,y); | |
596 | else | |
597 | wxWindowCocoa::DoGetSize(x,y); | |
fb896a32 DE |
598 | } |
599 | ||
600 | void wxWindow::DoSetClientSize(int width, int height) | |
601 | { | |
602 | wxLogDebug("DoSetClientSize=(%d,%d)",width,height); | |
603 | // TODO | |
604 | } | |
605 | ||
606 | int wxWindow::GetCharHeight() const | |
607 | { | |
608 | // TODO | |
609 | return 0; | |
610 | } | |
611 | ||
612 | int wxWindow::GetCharWidth() const | |
613 | { | |
614 | // TODO | |
615 | return 0; | |
616 | } | |
617 | ||
618 | void wxWindow::GetTextExtent(const wxString& string, int *x, int *y, | |
619 | int *descent, int *externalLeading, const wxFont *theFont) const | |
620 | { | |
621 | // TODO | |
622 | } | |
623 | ||
fb896a32 DE |
624 | // Coordinates relative to the window |
625 | void wxWindow::WarpPointer (int x_pos, int y_pos) | |
626 | { | |
627 | // TODO | |
628 | } | |
629 | ||
630 | int wxWindow::GetScrollPos(int orient) const | |
631 | { | |
632 | // TODO | |
633 | return 0; | |
634 | } | |
635 | ||
636 | // This now returns the whole range, not just the number | |
637 | // of positions that we can scroll. | |
638 | int wxWindow::GetScrollRange(int orient) const | |
639 | { | |
640 | // TODO | |
641 | return 0; | |
642 | } | |
643 | ||
644 | int wxWindow::GetScrollThumb(int orient) const | |
645 | { | |
646 | // TODO | |
647 | return 0; | |
648 | } | |
649 | ||
650 | void wxWindow::SetScrollPos(int orient, int pos, bool refresh) | |
651 | { | |
652 | // TODO | |
653 | } | |
654 | ||
816c52cf DE |
655 | void wxWindow::CocoaCreateNSScrollView() |
656 | { | |
657 | if(!m_cocoaScroller) | |
658 | { | |
659 | m_cocoaScroller = new wxWindowCocoaScroller(this); | |
660 | } | |
661 | } | |
662 | ||
fb896a32 DE |
663 | // New function that will replace some of the above. |
664 | void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible, | |
665 | int range, bool refresh) | |
666 | { | |
667 | // TODO | |
668 | } | |
669 | ||
670 | // Does a physical scroll | |
671 | void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect) | |
672 | { | |
673 | // TODO | |
674 | } | |
675 | ||
816c52cf DE |
676 | void wxWindow::DoSetVirtualSize( int x, int y ) |
677 | { | |
678 | wxWindowBase::DoSetVirtualSize(x,y); | |
679 | CocoaCreateNSScrollView(); | |
680 | [m_cocoaNSView setFrameSize:NSMakeSize(m_virtualSize.x,m_virtualSize.y)]; | |
681 | } | |
682 | ||
fb896a32 DE |
683 | bool wxWindow::SetFont(const wxFont& font) |
684 | { | |
685 | // TODO | |
686 | return TRUE; | |
687 | } | |
688 | ||
4328a6ba DE |
689 | static int CocoaRaiseWindowCompareFunction(id first, id second, void *target) |
690 | { | |
691 | // first should be ordered higher | |
692 | if(first==target) | |
693 | return NSOrderedDescending; | |
694 | // second should be ordered higher | |
695 | if(second==target) | |
696 | return NSOrderedAscending; | |
697 | return NSOrderedSame; | |
698 | } | |
699 | ||
fb896a32 DE |
700 | // Raise the window to the top of the Z order |
701 | void wxWindow::Raise() | |
702 | { | |
4328a6ba | 703 | // wxAutoNSAutoreleasePool pool; |
a82b8141 | 704 | NSView *nsview = GetNSViewForSuperview(); |
4328a6ba DE |
705 | [[nsview superview] sortSubviewsUsingFunction: |
706 | CocoaRaiseWindowCompareFunction | |
707 | context: nsview]; | |
708 | } | |
709 | ||
710 | static int CocoaLowerWindowCompareFunction(id first, id second, void *target) | |
711 | { | |
712 | // first should be ordered lower | |
713 | if(first==target) | |
714 | return NSOrderedAscending; | |
715 | // second should be ordered lower | |
716 | if(second==target) | |
717 | return NSOrderedDescending; | |
718 | return NSOrderedSame; | |
fb896a32 DE |
719 | } |
720 | ||
721 | // Lower the window to the bottom of the Z order | |
722 | void wxWindow::Lower() | |
723 | { | |
4328a6ba DE |
724 | NSView *nsview = GetNSViewForSuperview(); |
725 | [[nsview superview] sortSubviewsUsingFunction: | |
726 | CocoaLowerWindowCompareFunction | |
727 | context: nsview]; | |
fb896a32 DE |
728 | } |
729 | ||
730 | bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y) | |
731 | { | |
732 | return FALSE; | |
733 | } | |
734 | ||
735 | // Get the window with the focus | |
736 | wxWindow *wxWindowBase::FindFocus() | |
737 | { | |
738 | // TODO | |
739 | return NULL; | |
740 | } | |
741 | ||
742 | /* static */ wxWindow *wxWindowBase::GetCapture() | |
743 | { | |
744 | // TODO | |
b9505233 | 745 | return wxWindowCocoa::sm_capturedWindow; |
fb896a32 DE |
746 | } |
747 | ||
748 | wxWindow *wxGetActiveWindow() | |
749 | { | |
750 | // TODO | |
751 | return NULL; | |
752 | } | |
753 | ||
7c9428ab DE |
754 | wxPoint wxGetMousePosition() |
755 | { | |
756 | // TODO | |
757 | return wxDefaultPosition; | |
758 | } | |
759 | ||
760 | wxWindow* wxFindWindowAtPointer(wxPoint& pt) | |
761 | { | |
762 | pt = wxGetMousePosition(); | |
763 | return NULL; | |
764 | } | |
765 |