]> git.saurik.com Git - wxWidgets.git/blob - src/cocoa/window.mm
Use bounds rect instead of frame rect when positioning subviews
[wxWidgets.git] / src / cocoa / window.mm
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
15 #include "wx/cocoa/autorelease.h"
16
17 #import <Appkit/NSView.h>
18 #import <AppKit/NSEvent.h>
19 #import <AppKit/NSScrollView.h>
20 #import <AppKit/NSColor.h>
21 #import <AppKit/NSClipView.h>
22
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
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
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
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
180 // ========================================================================
181 // wxWindowCocoa
182 // ========================================================================
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
193 wxWindow *wxWindowCocoa::sm_capturedWindow = NULL;
194
195 // Constructor
196 void wxWindowCocoa::Init()
197 {
198 InitBase();
199
200 m_cocoaNSView = NULL;
201 m_cocoaHider = NULL;
202 m_cocoaScroller = NULL;
203 m_isBeingDeleted = FALSE;
204 m_isInPaint = FALSE;
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
218 m_cocoaNSView = NULL;
219 SetNSView([[NSView alloc] initWithFrame: MakeDefaultNSRect(size)]);
220 [m_cocoaNSView release];
221
222 if (m_parent)
223 {
224 m_parent->AddChild(this);
225 m_parent->CocoaAddChild(this);
226 }
227 SetInitialFrameRect(pos,size);
228
229 return TRUE;
230 }
231
232 // Destructor
233 wxWindow::~wxWindow()
234 {
235 wxAutoNSAutoreleasePool pool;
236 DestroyChildren();
237
238 if(m_parent)
239 m_parent->RemoveChild(this);
240
241 CocoaRemoveFromParent();
242 delete m_cocoaHider;
243 delete m_cocoaScroller;
244 SetNSView(NULL);
245 }
246
247 void wxWindowCocoa::CocoaAddChild(wxWindowCocoa *child)
248 {
249 NSView *childView = child->GetNSViewForSuperview();
250
251 wxASSERT(childView);
252 [m_cocoaNSView addSubview: childView];
253 child->m_isShown = !m_cocoaHider;
254 }
255
256 void wxWindowCocoa::CocoaRemoveFromParent(void)
257 {
258 [GetNSViewForSuperview() removeFromSuperview];
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]);
265 DisassociateNSView(m_cocoaNSView);
266 [cocoaNSView retain];
267 [m_cocoaNSView release];
268 m_cocoaNSView = cocoaNSView;
269 AssociateNSView(m_cocoaNSView);
270 if(need_debug) wxLogDebug("wxWindowCocoa=%p::SetNSView [cocoaNSView=%p retainCount]=%d",this,cocoaNSView,[cocoaNSView retainCount]);
271 }
272
273 WX_NSView wxWindowCocoa::GetNSViewForSuperview() const
274 {
275 return m_cocoaHider
276 ? m_cocoaHider->GetNSView()
277 : m_cocoaScroller
278 ? m_cocoaScroller->GetNSScrollView()
279 : m_cocoaNSView;
280 }
281
282 WX_NSView wxWindowCocoa::GetNSViewForHiding() const
283 {
284 return m_cocoaScroller
285 ? m_cocoaScroller->GetNSScrollView()
286 : m_cocoaNSView;
287 }
288
289 bool wxWindowCocoa::Cocoa_drawRect(const NSRect &rect)
290 {
291 wxLogDebug("Cocoa_drawRect");
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 }
300 //FIXME: should probably turn that rect into the update region
301 m_isInPaint = TRUE;
302 wxPaintEvent event(m_windowId);
303 event.SetEventObject(this);
304 bool ret = GetEventHandler()->ProcessEvent(event);
305 m_isInPaint = FALSE;
306 return ret;
307 }
308
309 void wxWindowCocoa::InitMouseEvent(wxMouseEvent& event, WX_NSEvent cocoaEvent)
310 {
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];
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
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
414 void wxWindow::CocoaReplaceView(WX_NSView oldView, WX_NSView newView)
415 {
416 [[oldView superview] replaceSubview:oldView with:newView];
417 }
418
419 bool wxWindow::Show(bool show)
420 {
421 wxAutoNSAutoreleasePool pool;
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
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");
426 // Return false if there isn't a window to show or hide
427 NSView *cocoaView = GetNSViewForHiding();
428 if(!cocoaView)
429 return false;
430 if(show)
431 {
432 // If state isn't changing, return false
433 if(!m_cocoaHider)
434 return false;
435 CocoaReplaceView(m_cocoaHider->GetNSView(), cocoaView);
436 wxASSERT(![m_cocoaHider->GetNSView() superview]);
437 delete m_cocoaHider;
438 m_cocoaHider = NULL;
439 wxASSERT([cocoaView superview]);
440 }
441 else
442 {
443 // If state isn't changing, return false
444 if(m_cocoaHider)
445 return false;
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());
450 // m_coocaNSView is now only retained by us
451 wxASSERT([m_cocoaHider->GetNSView() superview]);
452 wxASSERT(![cocoaView superview]);
453 }
454 m_isShown = show;
455 return true;
456 }
457
458 void wxWindowCocoa::DoSetSize(int x, int y, int width, int height, int sizeFlags)
459 {
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":".");
461 int currentX, currentY;
462 int currentW, currentH;
463 DoGetPosition(&currentX, &currentY);
464 DoGetSize(&currentW, &currentH);
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 {
500 // wxLogDebug("wxWindow=%p::DoMoveWindow(%d,%d,%d,%d)",this,x,y,width,height);
501
502 NSView *nsview = GetNSViewForSuperview();
503 NSView *superview = [nsview superview];
504 wxCHECK_RET(superview,"NSView does not have a superview");
505 NSRect parentRect = [superview bounds];
506
507 NSRect cocoaRect = NSMakeRect(x,parentRect.size.height-(y+height),width,height);
508 [nsview setFrame: cocoaRect];
509 // Be sure to redraw the parent to reflect the changed position
510 [superview setNeedsDisplay:YES];
511 }
512
513 void wxWindowCocoa::SetInitialFrameRect(const wxPoint& pos, const wxSize& size)
514 {
515 NSView *nsview = GetNSViewForSuperview();
516 NSView *superview = [nsview superview];
517 wxCHECK_RET(superview,"NSView does not have a superview");
518 NSRect parentRect = [superview bounds];
519 NSRect frameRect = [nsview frame];
520 if(size.x!=-1)
521 frameRect.size.width = size.x;
522 if(size.y!=-1)
523 frameRect.size.height = size.y;
524 frameRect.origin.x = pos.x;
525 frameRect.origin.y = parentRect.size.height-(pos.y+frameRect.size.height);
526 [nsview setFrame: frameRect];
527 // Tell Cocoa to change the margin between the bottom of the superview
528 // and the bottom of the control. Keeps the control pinned to the top
529 // of its superview so that its position in the wxWindows coordinate
530 // system doesn't change.
531 if(![superview isFlipped])
532 [nsview setAutoresizingMask: NSViewMinYMargin];
533 }
534
535 // Get total size
536 void wxWindow::DoGetSize(int *w, int *h) const
537 {
538 NSRect cocoaRect = [GetNSViewForSuperview() frame];
539 if(w)
540 *w=(int)cocoaRect.size.width;
541 if(h)
542 *h=(int)cocoaRect.size.height;
543 // wxLogDebug("wxWindow=%p::DoGetSize = (%d,%d)",this,(int)cocoaRect.size.width,(int)cocoaRect.size.height);
544 }
545
546 void wxWindow::DoGetPosition(int *x, int *y) const
547 {
548 NSView *nsview = GetNSViewForSuperview();
549 NSView *superview = [nsview superview];
550 wxCHECK_RET(superview,"NSView does not have a superview");
551 NSRect parentRect = [superview bounds];
552
553 NSRect cocoaRect = [nsview frame];
554 if(x)
555 *x=(int)cocoaRect.origin.x;
556 if(y)
557 *y=(int)(parentRect.size.height-(cocoaRect.origin.y+cocoaRect.size.height));
558 // wxLogDebug("wxWindow=%p::DoGetPosition = (%d,%d)",this,(int)cocoaRect.origin.x,(int)cocoaRect.origin.y);
559 }
560
561 WXWidget wxWindow::GetHandle() const
562 {
563 return m_cocoaNSView;
564 }
565
566 void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
567 {
568 [m_cocoaNSView setNeedsDisplay:YES];
569 }
570
571 void wxWindow::SetFocus()
572 {
573 // TODO
574 }
575
576 void wxWindow::DoCaptureMouse()
577 {
578 // TODO
579 sm_capturedWindow = this;
580 }
581
582 void wxWindow::DoReleaseMouse()
583 {
584 // TODO
585 sm_capturedWindow = NULL;
586 }
587
588 void wxWindow::DoScreenToClient(int *x, int *y) const
589 {
590 // TODO
591 }
592
593 void wxWindow::DoClientToScreen(int *x, int *y) const
594 {
595 // TODO
596 }
597
598 // Get size *available for subwindows* i.e. excluding menu bar etc.
599 void wxWindow::DoGetClientSize(int *x, int *y) const
600 {
601 wxLogDebug("DoGetClientSize:");
602 if(m_cocoaScroller)
603 m_cocoaScroller->DoGetClientSize(x,y);
604 else
605 wxWindowCocoa::DoGetSize(x,y);
606 }
607
608 void wxWindow::DoSetClientSize(int width, int height)
609 {
610 wxLogDebug("DoSetClientSize=(%d,%d)",width,height);
611 if(m_cocoaScroller)
612 m_cocoaScroller->ClientSizeToSize(width,height);
613 CocoaSetWxWindowSize(width,height);
614 }
615
616 void wxWindow::CocoaSetWxWindowSize(int width, int height)
617 {
618 wxWindowCocoa::DoSetSize(-1,-1,width,height,wxSIZE_USE_EXISTING);
619 }
620
621 int wxWindow::GetCharHeight() const
622 {
623 // TODO
624 return 0;
625 }
626
627 int wxWindow::GetCharWidth() const
628 {
629 // TODO
630 return 0;
631 }
632
633 void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
634 int *descent, int *externalLeading, const wxFont *theFont) const
635 {
636 // TODO
637 }
638
639 // Coordinates relative to the window
640 void wxWindow::WarpPointer (int x_pos, int y_pos)
641 {
642 // TODO
643 }
644
645 int wxWindow::GetScrollPos(int orient) const
646 {
647 // TODO
648 return 0;
649 }
650
651 // This now returns the whole range, not just the number
652 // of positions that we can scroll.
653 int wxWindow::GetScrollRange(int orient) const
654 {
655 // TODO
656 return 0;
657 }
658
659 int wxWindow::GetScrollThumb(int orient) const
660 {
661 // TODO
662 return 0;
663 }
664
665 void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
666 {
667 // TODO
668 }
669
670 void wxWindow::CocoaCreateNSScrollView()
671 {
672 if(!m_cocoaScroller)
673 {
674 m_cocoaScroller = new wxWindowCocoaScroller(this);
675 }
676 }
677
678 // New function that will replace some of the above.
679 void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
680 int range, bool refresh)
681 {
682 CocoaCreateNSScrollView();
683 // TODO
684 }
685
686 // Does a physical scroll
687 void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
688 {
689 // TODO
690 }
691
692 void wxWindow::DoSetVirtualSize( int x, int y )
693 {
694 wxWindowBase::DoSetVirtualSize(x,y);
695 CocoaCreateNSScrollView();
696 [m_cocoaNSView setFrameSize:NSMakeSize(m_virtualSize.x,m_virtualSize.y)];
697 }
698
699 bool wxWindow::SetFont(const wxFont& font)
700 {
701 // TODO
702 return TRUE;
703 }
704
705 static int CocoaRaiseWindowCompareFunction(id first, id second, void *target)
706 {
707 // first should be ordered higher
708 if(first==target)
709 return NSOrderedDescending;
710 // second should be ordered higher
711 if(second==target)
712 return NSOrderedAscending;
713 return NSOrderedSame;
714 }
715
716 // Raise the window to the top of the Z order
717 void wxWindow::Raise()
718 {
719 // wxAutoNSAutoreleasePool pool;
720 NSView *nsview = GetNSViewForSuperview();
721 [[nsview superview] sortSubviewsUsingFunction:
722 CocoaRaiseWindowCompareFunction
723 context: nsview];
724 }
725
726 static int CocoaLowerWindowCompareFunction(id first, id second, void *target)
727 {
728 // first should be ordered lower
729 if(first==target)
730 return NSOrderedAscending;
731 // second should be ordered lower
732 if(second==target)
733 return NSOrderedDescending;
734 return NSOrderedSame;
735 }
736
737 // Lower the window to the bottom of the Z order
738 void wxWindow::Lower()
739 {
740 NSView *nsview = GetNSViewForSuperview();
741 [[nsview superview] sortSubviewsUsingFunction:
742 CocoaLowerWindowCompareFunction
743 context: nsview];
744 }
745
746 bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
747 {
748 return FALSE;
749 }
750
751 // Get the window with the focus
752 wxWindow *wxWindowBase::FindFocus()
753 {
754 // TODO
755 return NULL;
756 }
757
758 /* static */ wxWindow *wxWindowBase::GetCapture()
759 {
760 // TODO
761 return wxWindowCocoa::sm_capturedWindow;
762 }
763
764 wxWindow *wxGetActiveWindow()
765 {
766 // TODO
767 return NULL;
768 }
769
770 wxPoint wxGetMousePosition()
771 {
772 // TODO
773 return wxDefaultPosition;
774 }
775
776 wxWindow* wxFindWindowAtPointer(wxPoint& pt)
777 {
778 pt = wxGetMousePosition();
779 return NULL;
780 }
781