1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/window.mm
3 // Purpose: wxWindowCocoa
4 // Author: David Elliott
8 // Copyright: (c) 2002 David Elliott
9 // Licence: wxWidgets licence
10 /////////////////////////////////////////////////////////////////////////////
12 #include "wx/wxprec.h"
15 #include "wx/tooltip.h"
16 #include "wx/window.h"
19 #include "wx/cocoa/autorelease.h"
20 #include "wx/cocoa/string.h"
22 #import <AppKit/NSView.h>
23 #import <AppKit/NSEvent.h>
24 #import <AppKit/NSScrollView.h>
25 #import <AppKit/NSColor.h>
26 #import <AppKit/NSClipView.h>
27 #import <Foundation/NSException.h>
28 #import <Foundation/NSString.h>
30 #include <objc/objc-runtime.h>
32 // Turn this on to paint green over the dummy views for debugging
33 #undef WXCOCOA_FILL_DUMMY_VIEW
35 #ifdef WXCOCOA_FILL_DUMMY_VIEW
36 #import <AppKit/NSBezierPath.h>
37 #endif //def WXCOCOA_FILL_DUMMY_VIEW
39 // ========================================================================
41 // ========================================================================
42 class wxWindowCocoaHider: protected wxCocoaNSView
44 DECLARE_NO_COPY_CLASS(wxWindowCocoaHider)
46 wxWindowCocoaHider(wxWindow *owner);
47 virtual ~wxWindowCocoaHider();
48 inline WX_NSView GetNSView() { return m_dummyNSView; }
50 wxWindowCocoa *m_owner;
51 WX_NSView m_dummyNSView;
52 virtual void Cocoa_FrameChanged(void);
53 #ifdef WXCOCOA_FILL_DUMMY_VIEW
54 virtual bool Cocoa_drawRect(const NSRect& rect);
55 #endif //def WXCOCOA_FILL_DUMMY_VIEW
60 // ========================================================================
61 // wxWindowCocoaScroller
62 // ========================================================================
63 class wxWindowCocoaScroller: protected wxCocoaNSView
65 DECLARE_NO_COPY_CLASS(wxWindowCocoaScroller)
67 wxWindowCocoaScroller(wxWindow *owner);
68 virtual ~wxWindowCocoaScroller();
69 inline WX_NSScrollView GetNSScrollView() { return m_cocoaNSScrollView; }
70 void ClientSizeToSize(int &width, int &height);
71 void DoGetClientSize(int *x, int *y) const;
75 wxWindowCocoa *m_owner;
76 WX_NSScrollView m_cocoaNSScrollView;
77 virtual void Cocoa_FrameChanged(void);
79 wxWindowCocoaScroller();
82 // ========================================================================
84 // ========================================================================
85 @interface wxDummyNSView : NSView
86 - (NSView *)hitTest:(NSPoint)aPoint;
89 @implementation wxDummyNSView : NSView
90 - (NSView *)hitTest:(NSPoint)aPoint
97 // ========================================================================
99 // ========================================================================
100 wxWindowCocoaHider::wxWindowCocoaHider(wxWindow *owner)
104 wxASSERT(owner->GetNSViewForHiding());
105 m_dummyNSView = [[wxDummyNSView alloc]
106 initWithFrame:[owner->GetNSViewForHiding() frame]];
107 [m_dummyNSView setAutoresizingMask: [owner->GetNSViewForHiding() autoresizingMask]];
108 AssociateNSView(m_dummyNSView);
111 wxWindowCocoaHider::~wxWindowCocoaHider()
113 DisassociateNSView(m_dummyNSView);
114 [m_dummyNSView release];
117 void wxWindowCocoaHider::Cocoa_FrameChanged(void)
119 // Keep the real window in synch with the dummy
120 wxASSERT(m_dummyNSView);
121 [m_owner->GetNSViewForHiding() setFrame:[m_dummyNSView frame]];
124 #ifdef WXCOCOA_FILL_DUMMY_VIEW
125 bool wxWindowCocoaHider::Cocoa_drawRect(const NSRect& rect)
127 NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:rect];
128 [[NSColor greenColor] set];
133 #endif //def WXCOCOA_FILL_DUMMY_VIEW
135 // ========================================================================
136 // wxFlippedNSClipView
137 // ========================================================================
138 @interface wxFlippedNSClipView : NSClipView
142 @implementation wxFlippedNSClipView : NSClipView
150 // ========================================================================
151 // wxWindowCocoaScroller
152 // ========================================================================
153 wxWindowCocoaScroller::wxWindowCocoaScroller(wxWindow *owner)
156 wxAutoNSAutoreleasePool pool;
158 wxASSERT(owner->GetNSView());
159 m_cocoaNSScrollView = [[NSScrollView alloc]
160 initWithFrame:[owner->GetNSView() frame]];
161 AssociateNSView(m_cocoaNSScrollView);
163 /* Replace the default NSClipView with a flipped one. This ensures
164 scrolling is "pinned" to the top-left instead of bottom-right. */
165 NSClipView *flippedClip = [[wxFlippedNSClipView alloc]
166 initWithFrame: [[m_cocoaNSScrollView contentView] frame]];
167 [m_cocoaNSScrollView setContentView:flippedClip];
168 [flippedClip release];
170 [m_cocoaNSScrollView setBackgroundColor: [NSColor windowBackgroundColor]];
171 [m_cocoaNSScrollView setHasHorizontalScroller: YES];
172 [m_cocoaNSScrollView setHasVerticalScroller: YES];
176 void wxWindowCocoaScroller::Encapsulate()
178 // Set the scroll view autoresizingMask to match the current NSView
179 [m_cocoaNSScrollView setAutoresizingMask: [m_owner->GetNSView() autoresizingMask]];
180 [m_owner->GetNSView() setAutoresizingMask: NSViewNotSizable];
181 // NOTE: replaceSubView will cause m_cocaNSView to be released
182 // except when it hasn't been added into an NSView hierarchy in which
183 // case it doesn't need to be and this should work out to a no-op
184 m_owner->CocoaReplaceView(m_owner->GetNSView(), m_cocoaNSScrollView);
185 // The NSView is still retained by owner
186 [m_cocoaNSScrollView setDocumentView: m_owner->GetNSView()];
187 // Now it's also retained by the NSScrollView
190 void wxWindowCocoaScroller::Unencapsulate()
192 [m_cocoaNSScrollView setDocumentView: nil];
193 m_owner->CocoaReplaceView(m_cocoaNSScrollView, m_owner->GetNSView());
194 if(![[m_owner->GetNSView() superview] isFlipped])
195 [m_owner->GetNSView() setAutoresizingMask: NSViewMinYMargin];
198 wxWindowCocoaScroller::~wxWindowCocoaScroller()
200 DisassociateNSView(m_cocoaNSScrollView);
201 [m_cocoaNSScrollView release];
204 void wxWindowCocoaScroller::ClientSizeToSize(int &width, int &height)
206 NSSize frameSize = [NSScrollView
207 frameSizeForContentSize: NSMakeSize(width,height)
208 hasHorizontalScroller: [m_cocoaNSScrollView hasHorizontalScroller]
209 hasVerticalScroller: [m_cocoaNSScrollView hasVerticalScroller]
210 borderType: [m_cocoaNSScrollView borderType]];
211 width = (int)frameSize.width;
212 height = (int)frameSize.height;
215 void wxWindowCocoaScroller::DoGetClientSize(int *x, int *y) const
217 NSSize nssize = [m_cocoaNSScrollView contentSize];
219 *x = (int)nssize.width;
221 *y = (int)nssize.height;
224 void wxWindowCocoaScroller::Cocoa_FrameChanged(void)
226 wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_FrameChanged"));
227 wxSizeEvent event(m_owner->GetSize(), m_owner->GetId());
228 event.SetEventObject(m_owner);
229 m_owner->GetEventHandler()->ProcessEvent(event);
232 // ========================================================================
234 // ========================================================================
235 // normally the base classes aren't included, but wxWindow is special
236 #ifdef __WXUNIVERSAL__
237 IMPLEMENT_ABSTRACT_CLASS(wxWindowCocoa, wxWindowBase)
239 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
242 BEGIN_EVENT_TABLE(wxWindowCocoa, wxWindowBase)
245 wxWindow *wxWindowCocoa::sm_capturedWindow = NULL;
248 void wxWindowCocoa::Init()
250 m_cocoaNSView = NULL;
252 m_cocoaScroller = NULL;
253 m_isBeingDeleted = FALSE;
255 m_shouldBeEnabled = true;
259 bool wxWindow::Create(wxWindow *parent, wxWindowID winid,
263 const wxString& name)
265 if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name))
268 // TODO: create the window
269 m_cocoaNSView = NULL;
270 SetNSView([[NSView alloc] initWithFrame: MakeDefaultNSRect(size)]);
271 [m_cocoaNSView release];
275 m_parent->AddChild(this);
276 m_parent->CocoaAddChild(this);
277 SetInitialFrameRect(pos,size);
284 wxWindow::~wxWindow()
286 wxAutoNSAutoreleasePool pool;
289 // Make sure our parent (in the wxWidgets sense) is our superview
290 // before we go removing from it.
291 if(m_parent && m_parent->GetNSView()==[GetNSViewForSuperview() superview])
292 CocoaRemoveFromParent();
294 delete m_cocoaScroller;
300 void wxWindowCocoa::CocoaAddChild(wxWindowCocoa *child)
302 NSView *childView = child->GetNSViewForSuperview();
305 [m_cocoaNSView addSubview: childView];
306 child->m_isShown = !m_cocoaHider;
309 void wxWindowCocoa::CocoaRemoveFromParent(void)
311 [GetNSViewForSuperview() removeFromSuperview];
314 void wxWindowCocoa::SetNSView(WX_NSView cocoaNSView)
316 bool need_debug = cocoaNSView || m_cocoaNSView;
317 if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxWindowCocoa=%p::SetNSView [m_cocoaNSView=%p retainCount]=%d"),this,m_cocoaNSView,[m_cocoaNSView retainCount]);
318 DisassociateNSView(m_cocoaNSView);
319 [cocoaNSView retain];
320 [m_cocoaNSView release];
321 m_cocoaNSView = cocoaNSView;
322 AssociateNSView(m_cocoaNSView);
323 if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxWindowCocoa=%p::SetNSView [cocoaNSView=%p retainCount]=%d"),this,cocoaNSView,[cocoaNSView retainCount]);
326 WX_NSView wxWindowCocoa::GetNSViewForSuperview() const
329 ? m_cocoaHider->GetNSView()
331 ? m_cocoaScroller->GetNSScrollView()
335 WX_NSView wxWindowCocoa::GetNSViewForHiding() const
337 return m_cocoaScroller
338 ? m_cocoaScroller->GetNSScrollView()
342 bool wxWindowCocoa::Cocoa_drawRect(const NSRect &rect)
344 wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_drawRect"));
345 // Recursion can happen if the event loop runs from within the paint
346 // handler. For instance, if an assertion dialog is shown.
347 // FIXME: This seems less than ideal.
350 wxLogDebug(wxT("Paint event recursion!"));
355 // Set m_updateRegion
356 const NSRect *rects = ▭ // The bounding box of the region
358 // Try replacing the larger rectangle with a list of smaller ones:
360 //getRectsBeingDrawn:count: is a optimization that is only available on
361 //Panthar (10.3) and higher. Check to see if it supports it -
362 if ( [GetNSView() respondsToSelector:@selector(getRectsBeingDrawn:count:)] ) objc_msgSend(GetNSView(),@selector(getRectsBeingDrawn:count:),&rects,&countRects);
365 m_updateRegion = wxRegion(rects,countRects);
367 wxPaintEvent event(m_windowId);
368 event.SetEventObject(this);
369 bool ret = GetEventHandler()->ProcessEvent(event);
374 void wxWindowCocoa::InitMouseEvent(wxMouseEvent& event, WX_NSEvent cocoaEvent)
376 wxASSERT_MSG([m_cocoaNSView window]==[cocoaEvent window],wxT("Mouse event for different NSWindow"));
377 NSPoint cocoaPoint = [m_cocoaNSView convertPoint:[(NSEvent*)cocoaEvent locationInWindow] fromView:nil];
378 NSRect cocoaRect = [m_cocoaNSView frame];
379 const wxPoint &clientorigin = GetClientAreaOrigin();
380 event.m_x = (wxCoord)cocoaPoint.x - clientorigin.x;
381 event.m_y = (wxCoord)(cocoaRect.size.height - cocoaPoint.y) - clientorigin.y;
383 event.m_shiftDown = [cocoaEvent modifierFlags] & NSShiftKeyMask;
384 event.m_controlDown = [cocoaEvent modifierFlags] & NSControlKeyMask;
385 event.m_altDown = [cocoaEvent modifierFlags] & NSAlternateKeyMask;
386 event.m_metaDown = [cocoaEvent modifierFlags] & NSCommandKeyMask;
388 // TODO: set timestamp?
389 event.SetEventObject(this);
390 event.SetId(GetId());
393 bool wxWindowCocoa::Cocoa_mouseMoved(WX_NSEvent theEvent)
395 wxMouseEvent event(wxEVT_MOTION);
396 InitMouseEvent(event,theEvent);
397 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y);
398 return GetEventHandler()->ProcessEvent(event);
401 bool wxWindowCocoa::Cocoa_mouseEntered(WX_NSEvent theEvent)
406 bool wxWindowCocoa::Cocoa_mouseExited(WX_NSEvent theEvent)
411 bool wxWindowCocoa::Cocoa_mouseDown(WX_NSEvent theEvent)
413 wxMouseEvent event([theEvent clickCount]<2?wxEVT_LEFT_DOWN:wxEVT_LEFT_DCLICK);
414 InitMouseEvent(event,theEvent);
415 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Down @%d,%d num clicks=%d"),event.m_x,event.m_y,[theEvent clickCount]);
416 return GetEventHandler()->ProcessEvent(event);
419 bool wxWindowCocoa::Cocoa_mouseDragged(WX_NSEvent theEvent)
421 wxMouseEvent event(wxEVT_MOTION);
422 InitMouseEvent(event,theEvent);
423 event.m_leftDown = true;
424 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y);
425 return GetEventHandler()->ProcessEvent(event);
428 bool wxWindowCocoa::Cocoa_mouseUp(WX_NSEvent theEvent)
430 wxMouseEvent event(wxEVT_LEFT_UP);
431 InitMouseEvent(event,theEvent);
432 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Up @%d,%d"),event.m_x,event.m_y);
433 return GetEventHandler()->ProcessEvent(event);
436 bool wxWindowCocoa::Cocoa_rightMouseDown(WX_NSEvent theEvent)
438 wxMouseEvent event([theEvent clickCount]<2?wxEVT_RIGHT_DOWN:wxEVT_RIGHT_DCLICK);
439 InitMouseEvent(event,theEvent);
440 wxLogDebug(wxT("Mouse Down @%d,%d num clicks=%d"),event.m_x,event.m_y,[theEvent clickCount]);
441 return GetEventHandler()->ProcessEvent(event);
444 bool wxWindowCocoa::Cocoa_rightMouseDragged(WX_NSEvent theEvent)
446 wxMouseEvent event(wxEVT_MOTION);
447 InitMouseEvent(event,theEvent);
448 event.m_rightDown = true;
449 wxLogDebug(wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y);
450 return GetEventHandler()->ProcessEvent(event);
453 bool wxWindowCocoa::Cocoa_rightMouseUp(WX_NSEvent theEvent)
455 wxMouseEvent event(wxEVT_RIGHT_UP);
456 InitMouseEvent(event,theEvent);
457 wxLogDebug(wxT("Mouse Up @%d,%d"),event.m_x,event.m_y);
458 return GetEventHandler()->ProcessEvent(event);
461 bool wxWindowCocoa::Cocoa_otherMouseDown(WX_NSEvent theEvent)
466 bool wxWindowCocoa::Cocoa_otherMouseDragged(WX_NSEvent theEvent)
471 bool wxWindowCocoa::Cocoa_otherMouseUp(WX_NSEvent theEvent)
476 void wxWindowCocoa::Cocoa_FrameChanged(void)
478 wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_FrameChanged"));
479 wxSizeEvent event(GetSize(), m_windowId);
480 event.SetEventObject(this);
481 GetEventHandler()->ProcessEvent(event);
484 bool wxWindow::Close(bool force)
486 // The only reason this function exists is that it is virtual and
487 // wxTopLevelWindowCocoa will override it.
488 return wxWindowBase::Close(force);
491 void wxWindow::CocoaReplaceView(WX_NSView oldView, WX_NSView newView)
493 [[oldView superview] replaceSubview:oldView with:newView];
496 bool wxWindow::EnableSelfAndChildren(bool enable)
498 // If the state isn't changing, don't do anything
499 if(!wxWindowBase::Enable(enable && m_shouldBeEnabled))
501 // Set the state of the Cocoa window
502 CocoaSetEnabled(m_isEnabled);
503 // Disable all children or (if enabling) return them to their proper state
504 for(wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
505 node; node = node->GetNext())
507 node->GetData()->EnableSelfAndChildren(enable);
512 bool wxWindow::Enable(bool enable)
514 // Keep track of what the window SHOULD be doing
515 m_shouldBeEnabled = enable;
516 // If the parent is disabled for any reason, then this window will be too.
517 if(!IsTopLevel() && GetParent())
519 enable = enable && GetParent()->IsEnabled();
521 return EnableSelfAndChildren(enable);
524 bool wxWindow::Show(bool show)
526 wxAutoNSAutoreleasePool pool;
527 // If the window is marked as visible, then it shouldn't have a dummy view
528 // If the window is marked hidden, then it should have a dummy view
529 // wxSpinCtrl (generic) abuses m_isShown, don't use it for any logic
530 // wxASSERT_MSG( (m_isShown && !m_dummyNSView) || (!m_isShown && m_dummyNSView),wxT("wxWindow: m_isShown does not agree with m_dummyNSView"));
531 // Return false if there isn't a window to show or hide
532 NSView *cocoaView = GetNSViewForHiding();
537 // If state isn't changing, return false
540 CocoaReplaceView(m_cocoaHider->GetNSView(), cocoaView);
541 wxASSERT(![m_cocoaHider->GetNSView() superview]);
544 wxASSERT([cocoaView superview]);
548 // If state isn't changing, return false
551 m_cocoaHider = new wxWindowCocoaHider(this);
552 // NOTE: replaceSubview:with will cause m_cocaNSView to be
553 // (auto)released which balances out addSubview
554 CocoaReplaceView(cocoaView, m_cocoaHider->GetNSView());
555 // m_coocaNSView is now only retained by us
556 wxASSERT([m_cocoaHider->GetNSView() superview]);
557 wxASSERT(![cocoaView superview]);
563 void wxWindowCocoa::DoSetSize(int x, int y, int width, int height, int sizeFlags)
565 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("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":".");
566 int currentX, currentY;
567 int currentW, currentH;
568 DoGetPosition(¤tX, ¤tY);
569 DoGetSize(¤tW, ¤tH);
570 if((x==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
572 if((y==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
575 AdjustForParentClientOrigin(x,y,sizeFlags);
579 if((width==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
581 if(sizeFlags&wxSIZE_AUTO_WIDTH)
583 size=DoGetBestSize();
589 if((height==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
591 if(sizeFlags&wxSIZE_AUTO_HEIGHT)
594 size=DoGetBestSize();
600 DoMoveWindow(x,y,width,height);
603 //We should really get rid of wxToolTip :)
604 IMPLEMENT_ABSTRACT_CLASS(wxToolTip, wxObject)
606 void wxWindowCocoa::DoSetToolTip( wxToolTip *tip )
608 wxWindowBase::DoSetToolTip(tip);
610 wxAutoNSAutoreleasePool pool;
614 m_tooltip->SetWindow((wxWindow *)this);
615 [GetNSView() setToolTip:wxNSStringWithWxString(m_tooltip->GetTip())];
619 void wxWindowCocoa::DoMoveWindow(int x, int y, int width, int height)
621 wxAutoNSAutoreleasePool pool;
622 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoMoveWindow(%d,%d,%d,%d)"),this,x,y,width,height);
624 NSView *nsview = GetNSViewForSuperview();
625 NSView *superview = [nsview superview];
626 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
627 NSRect parentRect = [superview bounds];
629 NSRect cocoaRect = NSMakeRect(x,parentRect.size.height-(y+height),width,height);
630 [nsview setFrame: cocoaRect];
631 // Be sure to redraw the parent to reflect the changed position
632 [superview setNeedsDisplay:YES];
635 void wxWindowCocoa::SetInitialFrameRect(const wxPoint& pos, const wxSize& size)
637 NSView *nsview = GetNSViewForSuperview();
638 NSView *superview = [nsview superview];
639 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
640 NSRect parentRect = [superview bounds];
641 NSRect frameRect = [nsview frame];
643 frameRect.size.width = size.x;
645 frameRect.size.height = size.y;
646 frameRect.origin.x = pos.x;
647 frameRect.origin.y = parentRect.size.height-(pos.y+frameRect.size.height);
648 // Tell Cocoa to change the margin between the bottom of the superview
649 // and the bottom of the control. Keeps the control pinned to the top
650 // of its superview so that its position in the wxWidgets coordinate
651 // system doesn't change.
652 if(![superview isFlipped])
653 [nsview setAutoresizingMask: NSViewMinYMargin];
654 // MUST set the mask before setFrame: which can generate a size event
655 // and cause a scroller to be added!
656 [nsview setFrame: frameRect];
660 void wxWindow::DoGetSize(int *w, int *h) const
662 NSRect cocoaRect = [GetNSViewForSuperview() frame];
664 *w=(int)cocoaRect.size.width;
666 *h=(int)cocoaRect.size.height;
667 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoGetSize = (%d,%d)"),this,(int)cocoaRect.size.width,(int)cocoaRect.size.height);
670 void wxWindow::DoGetPosition(int *x, int *y) const
672 NSView *nsview = GetNSViewForSuperview();
673 NSView *superview = [nsview superview];
674 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
675 NSRect parentRect = [superview bounds];
677 NSRect cocoaRect = [nsview frame];
679 *x=(int)cocoaRect.origin.x;
681 *y=(int)(parentRect.size.height-(cocoaRect.origin.y+cocoaRect.size.height));
682 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoGetPosition = (%d,%d)"),this,(int)cocoaRect.origin.x,(int)cocoaRect.origin.y);
685 WXWidget wxWindow::GetHandle() const
687 return m_cocoaNSView;
690 void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
692 [m_cocoaNSView setNeedsDisplay:YES];
695 void wxWindow::SetFocus()
700 void wxWindow::DoCaptureMouse()
703 sm_capturedWindow = this;
706 void wxWindow::DoReleaseMouse()
709 sm_capturedWindow = NULL;
712 void wxWindow::DoScreenToClient(int *x, int *y) const
717 void wxWindow::DoClientToScreen(int *x, int *y) const
722 // Get size *available for subwindows* i.e. excluding menu bar etc.
723 void wxWindow::DoGetClientSize(int *x, int *y) const
725 wxLogTrace(wxTRACE_COCOA,wxT("DoGetClientSize:"));
727 m_cocoaScroller->DoGetClientSize(x,y);
729 wxWindowCocoa::DoGetSize(x,y);
732 void wxWindow::DoSetClientSize(int width, int height)
734 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("DoSetClientSize=(%d,%d)"),width,height);
736 m_cocoaScroller->ClientSizeToSize(width,height);
737 CocoaSetWxWindowSize(width,height);
740 void wxWindow::CocoaSetWxWindowSize(int width, int height)
742 wxWindowCocoa::DoSetSize(-1,-1,width,height,wxSIZE_USE_EXISTING);
745 int wxWindow::GetCharHeight() const
751 int wxWindow::GetCharWidth() const
757 void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
758 int *descent, int *externalLeading, const wxFont *theFont) const
763 // Coordinates relative to the window
764 void wxWindow::WarpPointer (int x_pos, int y_pos)
769 int wxWindow::GetScrollPos(int orient) const
775 // This now returns the whole range, not just the number
776 // of positions that we can scroll.
777 int wxWindow::GetScrollRange(int orient) const
783 int wxWindow::GetScrollThumb(int orient) const
789 void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
794 void wxWindow::CocoaCreateNSScrollView()
798 m_cocoaScroller = new wxWindowCocoaScroller(this);
802 // New function that will replace some of the above.
803 void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
804 int range, bool refresh)
806 CocoaCreateNSScrollView();
810 // Does a physical scroll
811 void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
816 void wxWindow::DoSetVirtualSize( int x, int y )
818 wxWindowBase::DoSetVirtualSize(x,y);
819 CocoaCreateNSScrollView();
820 [m_cocoaNSView setFrameSize:NSMakeSize(m_virtualSize.x,m_virtualSize.y)];
823 bool wxWindow::SetFont(const wxFont& font)
829 static int CocoaRaiseWindowCompareFunction(id first, id second, void *target)
831 // first should be ordered higher
833 return NSOrderedDescending;
834 // second should be ordered higher
836 return NSOrderedAscending;
837 return NSOrderedSame;
840 // Raise the window to the top of the Z order
841 void wxWindow::Raise()
843 // wxAutoNSAutoreleasePool pool;
844 NSView *nsview = GetNSViewForSuperview();
845 [[nsview superview] sortSubviewsUsingFunction:
846 CocoaRaiseWindowCompareFunction
850 static int CocoaLowerWindowCompareFunction(id first, id second, void *target)
852 // first should be ordered lower
854 return NSOrderedAscending;
855 // second should be ordered lower
857 return NSOrderedDescending;
858 return NSOrderedSame;
861 // Lower the window to the bottom of the Z order
862 void wxWindow::Lower()
864 NSView *nsview = GetNSViewForSuperview();
865 [[nsview superview] sortSubviewsUsingFunction:
866 CocoaLowerWindowCompareFunction
870 bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
875 // Get the window with the focus
876 wxWindow *wxWindowBase::DoFindFocus()
882 /* static */ wxWindow *wxWindowBase::GetCapture()
885 return wxWindowCocoa::sm_capturedWindow;
888 wxWindow *wxGetActiveWindow()
894 wxPoint wxGetMousePosition()
897 return wxDefaultPosition;
900 wxWindow* wxFindWindowAtPointer(wxPoint& pt)
902 pt = wxGetMousePosition();