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]];
125 #ifdef WXCOCOA_FILL_DUMMY_VIEW
126 bool wxWindowCocoaHider::Cocoa_drawRect(const NSRect& rect)
128 NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:rect];
129 [[NSColor greenColor] set];
134 #endif //def WXCOCOA_FILL_DUMMY_VIEW
136 // ========================================================================
137 // wxFlippedNSClipView
138 // ========================================================================
139 @interface wxFlippedNSClipView : NSClipView
143 @implementation wxFlippedNSClipView : NSClipView
151 // ========================================================================
152 // wxWindowCocoaScroller
153 // ========================================================================
154 wxWindowCocoaScroller::wxWindowCocoaScroller(wxWindow *owner)
157 wxAutoNSAutoreleasePool pool;
159 wxASSERT(owner->GetNSView());
160 m_cocoaNSScrollView = [[NSScrollView alloc]
161 initWithFrame:[owner->GetNSView() frame]];
162 AssociateNSView(m_cocoaNSScrollView);
164 /* Replace the default NSClipView with a flipped one. This ensures
165 scrolling is "pinned" to the top-left instead of bottom-right. */
166 NSClipView *flippedClip = [[wxFlippedNSClipView alloc]
167 initWithFrame: [[m_cocoaNSScrollView contentView] frame]];
168 [m_cocoaNSScrollView setContentView:flippedClip];
169 [flippedClip release];
171 [m_cocoaNSScrollView setBackgroundColor: [NSColor windowBackgroundColor]];
172 [m_cocoaNSScrollView setHasHorizontalScroller: YES];
173 [m_cocoaNSScrollView setHasVerticalScroller: YES];
177 void wxWindowCocoaScroller::Encapsulate()
179 // Set the scroll view autoresizingMask to match the current NSView
180 [m_cocoaNSScrollView setAutoresizingMask: [m_owner->GetNSView() autoresizingMask]];
181 [m_owner->GetNSView() setAutoresizingMask: NSViewNotSizable];
182 // NOTE: replaceSubView will cause m_cocaNSView to be released
183 // except when it hasn't been added into an NSView hierarchy in which
184 // case it doesn't need to be and this should work out to a no-op
185 m_owner->CocoaReplaceView(m_owner->GetNSView(), m_cocoaNSScrollView);
186 // The NSView is still retained by owner
187 [m_cocoaNSScrollView setDocumentView: m_owner->GetNSView()];
188 // Now it's also retained by the NSScrollView
191 void wxWindowCocoaScroller::Unencapsulate()
193 [m_cocoaNSScrollView setDocumentView: nil];
194 m_owner->CocoaReplaceView(m_cocoaNSScrollView, m_owner->GetNSView());
195 if(![[m_owner->GetNSView() superview] isFlipped])
196 [m_owner->GetNSView() setAutoresizingMask: NSViewMinYMargin];
199 wxWindowCocoaScroller::~wxWindowCocoaScroller()
201 DisassociateNSView(m_cocoaNSScrollView);
202 [m_cocoaNSScrollView release];
205 void wxWindowCocoaScroller::ClientSizeToSize(int &width, int &height)
207 NSSize frameSize = [NSScrollView
208 frameSizeForContentSize: NSMakeSize(width,height)
209 hasHorizontalScroller: [m_cocoaNSScrollView hasHorizontalScroller]
210 hasVerticalScroller: [m_cocoaNSScrollView hasVerticalScroller]
211 borderType: [m_cocoaNSScrollView borderType]];
212 width = (int)frameSize.width;
213 height = (int)frameSize.height;
216 void wxWindowCocoaScroller::DoGetClientSize(int *x, int *y) const
218 NSSize nssize = [m_cocoaNSScrollView contentSize];
220 *x = (int)nssize.width;
222 *y = (int)nssize.height;
225 void wxWindowCocoaScroller::Cocoa_FrameChanged(void)
227 wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_FrameChanged"));
228 wxSizeEvent event(m_owner->GetSize(), m_owner->GetId());
229 event.SetEventObject(m_owner);
230 m_owner->GetEventHandler()->ProcessEvent(event);
233 // ========================================================================
235 // ========================================================================
236 // normally the base classes aren't included, but wxWindow is special
237 #ifdef __WXUNIVERSAL__
238 IMPLEMENT_ABSTRACT_CLASS(wxWindowCocoa, wxWindowBase)
240 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
243 BEGIN_EVENT_TABLE(wxWindowCocoa, wxWindowBase)
246 wxWindow *wxWindowCocoa::sm_capturedWindow = NULL;
249 void wxWindowCocoa::Init()
251 m_cocoaNSView = NULL;
253 m_cocoaScroller = NULL;
254 m_isBeingDeleted = FALSE;
256 m_shouldBeEnabled = true;
260 bool wxWindow::Create(wxWindow *parent, wxWindowID winid,
264 const wxString& name)
266 if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name))
269 // TODO: create the window
270 m_cocoaNSView = NULL;
271 SetNSView([[NSView alloc] initWithFrame: MakeDefaultNSRect(size)]);
272 [m_cocoaNSView release];
276 m_parent->AddChild(this);
277 m_parent->CocoaAddChild(this);
278 SetInitialFrameRect(pos,size);
285 wxWindow::~wxWindow()
287 wxAutoNSAutoreleasePool pool;
290 // Make sure our parent (in the wxWidgets sense) is our superview
291 // before we go removing from it.
292 if(m_parent && m_parent->GetNSView()==[GetNSViewForSuperview() superview])
293 CocoaRemoveFromParent();
295 delete m_cocoaScroller;
301 void wxWindowCocoa::CocoaAddChild(wxWindowCocoa *child)
303 NSView *childView = child->GetNSViewForSuperview();
306 [m_cocoaNSView addSubview: childView];
307 child->m_isShown = !m_cocoaHider;
310 void wxWindowCocoa::CocoaRemoveFromParent(void)
312 [GetNSViewForSuperview() removeFromSuperview];
315 void wxWindowCocoa::SetNSView(WX_NSView cocoaNSView)
317 bool need_debug = cocoaNSView || m_cocoaNSView;
318 if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxWindowCocoa=%p::SetNSView [m_cocoaNSView=%p retainCount]=%d"),this,m_cocoaNSView,[m_cocoaNSView retainCount]);
319 DisassociateNSView(m_cocoaNSView);
320 [cocoaNSView retain];
321 [m_cocoaNSView release];
322 m_cocoaNSView = cocoaNSView;
323 AssociateNSView(m_cocoaNSView);
324 if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxWindowCocoa=%p::SetNSView [cocoaNSView=%p retainCount]=%d"),this,cocoaNSView,[cocoaNSView retainCount]);
327 WX_NSView wxWindowCocoa::GetNSViewForSuperview() const
330 ? m_cocoaHider->GetNSView()
332 ? m_cocoaScroller->GetNSScrollView()
336 WX_NSView wxWindowCocoa::GetNSViewForHiding() const
338 return m_cocoaScroller
339 ? m_cocoaScroller->GetNSScrollView()
343 bool wxWindowCocoa::Cocoa_drawRect(const NSRect &rect)
345 wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_drawRect"));
346 // Recursion can happen if the event loop runs from within the paint
347 // handler. For instance, if an assertion dialog is shown.
348 // FIXME: This seems less than ideal.
351 wxLogDebug(wxT("Paint event recursion!"));
356 // Set m_updateRegion
357 const NSRect *rects = ▭ // The bounding box of the region
359 // Try replacing the larger rectangle with a list of smaller ones:
361 //getRectsBeingDrawn:count: is a optimization that is only available on
362 //Panthar (10.3) and higher. Check to see if it supports it -
363 if ( [GetNSView() respondsToSelector:@selector(getRectsBeingDrawn:count:)] ) objc_msgSend(GetNSView(),@selector(getRectsBeingDrawn:count:),&rects,&countRects);
366 m_updateRegion = wxRegion(rects,countRects);
368 wxPaintEvent event(m_windowId);
369 event.SetEventObject(this);
370 bool ret = GetEventHandler()->ProcessEvent(event);
375 void wxWindowCocoa::InitMouseEvent(wxMouseEvent& event, WX_NSEvent cocoaEvent)
377 wxASSERT_MSG([m_cocoaNSView window]==[cocoaEvent window],wxT("Mouse event for different NSWindow"));
378 NSPoint cocoaPoint = [m_cocoaNSView convertPoint:[(NSEvent*)cocoaEvent locationInWindow] fromView:nil];
379 NSRect cocoaRect = [m_cocoaNSView frame];
380 const wxPoint &clientorigin = GetClientAreaOrigin();
381 event.m_x = (wxCoord)cocoaPoint.x - clientorigin.x;
382 event.m_y = (wxCoord)(cocoaRect.size.height - cocoaPoint.y) - clientorigin.y;
384 event.m_shiftDown = [cocoaEvent modifierFlags] & NSShiftKeyMask;
385 event.m_controlDown = [cocoaEvent modifierFlags] & NSControlKeyMask;
386 event.m_altDown = [cocoaEvent modifierFlags] & NSAlternateKeyMask;
387 event.m_metaDown = [cocoaEvent modifierFlags] & NSCommandKeyMask;
389 // TODO: set timestamp?
390 event.SetEventObject(this);
391 event.SetId(GetId());
394 bool wxWindowCocoa::Cocoa_mouseMoved(WX_NSEvent theEvent)
396 wxMouseEvent event(wxEVT_MOTION);
397 InitMouseEvent(event,theEvent);
398 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y);
399 return GetEventHandler()->ProcessEvent(event);
402 bool wxWindowCocoa::Cocoa_mouseEntered(WX_NSEvent theEvent)
407 bool wxWindowCocoa::Cocoa_mouseExited(WX_NSEvent theEvent)
412 bool wxWindowCocoa::Cocoa_mouseDown(WX_NSEvent theEvent)
414 wxMouseEvent event([theEvent clickCount]<2?wxEVT_LEFT_DOWN:wxEVT_LEFT_DCLICK);
415 InitMouseEvent(event,theEvent);
416 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Down @%d,%d num clicks=%d"),event.m_x,event.m_y,[theEvent clickCount]);
417 return GetEventHandler()->ProcessEvent(event);
420 bool wxWindowCocoa::Cocoa_mouseDragged(WX_NSEvent theEvent)
422 wxMouseEvent event(wxEVT_MOTION);
423 InitMouseEvent(event,theEvent);
424 event.m_leftDown = true;
425 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y);
426 return GetEventHandler()->ProcessEvent(event);
429 bool wxWindowCocoa::Cocoa_mouseUp(WX_NSEvent theEvent)
431 wxMouseEvent event(wxEVT_LEFT_UP);
432 InitMouseEvent(event,theEvent);
433 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Up @%d,%d"),event.m_x,event.m_y);
434 return GetEventHandler()->ProcessEvent(event);
437 bool wxWindowCocoa::Cocoa_rightMouseDown(WX_NSEvent theEvent)
439 wxMouseEvent event([theEvent clickCount]<2?wxEVT_RIGHT_DOWN:wxEVT_RIGHT_DCLICK);
440 InitMouseEvent(event,theEvent);
441 wxLogDebug(wxT("Mouse Down @%d,%d num clicks=%d"),event.m_x,event.m_y,[theEvent clickCount]);
442 return GetEventHandler()->ProcessEvent(event);
445 bool wxWindowCocoa::Cocoa_rightMouseDragged(WX_NSEvent theEvent)
447 wxMouseEvent event(wxEVT_MOTION);
448 InitMouseEvent(event,theEvent);
449 event.m_rightDown = true;
450 wxLogDebug(wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y);
451 return GetEventHandler()->ProcessEvent(event);
454 bool wxWindowCocoa::Cocoa_rightMouseUp(WX_NSEvent theEvent)
456 wxMouseEvent event(wxEVT_RIGHT_UP);
457 InitMouseEvent(event,theEvent);
458 wxLogDebug(wxT("Mouse Up @%d,%d"),event.m_x,event.m_y);
459 return GetEventHandler()->ProcessEvent(event);
462 bool wxWindowCocoa::Cocoa_otherMouseDown(WX_NSEvent theEvent)
467 bool wxWindowCocoa::Cocoa_otherMouseDragged(WX_NSEvent theEvent)
472 bool wxWindowCocoa::Cocoa_otherMouseUp(WX_NSEvent theEvent)
477 void wxWindowCocoa::Cocoa_FrameChanged(void)
479 wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_FrameChanged"));
480 wxSizeEvent event(GetSize(), m_windowId);
481 event.SetEventObject(this);
482 GetEventHandler()->ProcessEvent(event);
485 bool wxWindowCocoa::Cocoa_resetCursorRects()
487 if(!m_cursor.GetNSCursor())
490 [GetNSView() addCursorRect: [GetNSView() visibleRect] cursor: m_cursor.GetNSCursor()];
495 bool wxWindow::Close(bool force)
497 // The only reason this function exists is that it is virtual and
498 // wxTopLevelWindowCocoa will override it.
499 return wxWindowBase::Close(force);
502 void wxWindow::CocoaReplaceView(WX_NSView oldView, WX_NSView newView)
504 [[oldView superview] replaceSubview:oldView with:newView];
507 bool wxWindow::EnableSelfAndChildren(bool enable)
509 // If the state isn't changing, don't do anything
510 if(!wxWindowBase::Enable(enable && m_shouldBeEnabled))
512 // Set the state of the Cocoa window
513 CocoaSetEnabled(m_isEnabled);
514 // Disable all children or (if enabling) return them to their proper state
515 for(wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
516 node; node = node->GetNext())
518 node->GetData()->EnableSelfAndChildren(enable);
523 bool wxWindow::Enable(bool enable)
525 // Keep track of what the window SHOULD be doing
526 m_shouldBeEnabled = enable;
527 // If the parent is disabled for any reason, then this window will be too.
528 if(!IsTopLevel() && GetParent())
530 enable = enable && GetParent()->IsEnabled();
532 return EnableSelfAndChildren(enable);
535 bool wxWindow::Show(bool show)
537 wxAutoNSAutoreleasePool pool;
538 // If the window is marked as visible, then it shouldn't have a dummy view
539 // If the window is marked hidden, then it should have a dummy view
540 // wxSpinCtrl (generic) abuses m_isShown, don't use it for any logic
541 // wxASSERT_MSG( (m_isShown && !m_dummyNSView) || (!m_isShown && m_dummyNSView),wxT("wxWindow: m_isShown does not agree with m_dummyNSView"));
542 // Return false if there isn't a window to show or hide
543 NSView *cocoaView = GetNSViewForHiding();
548 // If state isn't changing, return false
551 CocoaReplaceView(m_cocoaHider->GetNSView(), cocoaView);
552 wxASSERT(![m_cocoaHider->GetNSView() superview]);
555 wxASSERT([cocoaView superview]);
559 // If state isn't changing, return false
562 m_cocoaHider = new wxWindowCocoaHider(this);
563 // NOTE: replaceSubview:with will cause m_cocaNSView to be
564 // (auto)released which balances out addSubview
565 CocoaReplaceView(cocoaView, m_cocoaHider->GetNSView());
566 // m_coocaNSView is now only retained by us
567 wxASSERT([m_cocoaHider->GetNSView() superview]);
568 wxASSERT(![cocoaView superview]);
574 void wxWindowCocoa::DoSetSize(int x, int y, int width, int height, int sizeFlags)
576 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":".");
577 int currentX, currentY;
578 int currentW, currentH;
579 DoGetPosition(¤tX, ¤tY);
580 DoGetSize(¤tW, ¤tH);
581 if((x==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
583 if((y==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
586 AdjustForParentClientOrigin(x,y,sizeFlags);
590 if((width==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
592 if(sizeFlags&wxSIZE_AUTO_WIDTH)
594 size=DoGetBestSize();
600 if((height==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
602 if(sizeFlags&wxSIZE_AUTO_HEIGHT)
605 size=DoGetBestSize();
611 DoMoveWindow(x,y,width,height);
614 //We should really get rid of wxToolTip :)
615 IMPLEMENT_ABSTRACT_CLASS(wxToolTip, wxObject)
617 void wxWindowCocoa::DoSetToolTip( wxToolTip *tip )
619 wxWindowBase::DoSetToolTip(tip);
621 wxAutoNSAutoreleasePool pool;
625 m_tooltip->SetWindow((wxWindow *)this);
626 [GetNSView() setToolTip:wxNSStringWithWxString(m_tooltip->GetTip())];
630 void wxWindowCocoa::DoMoveWindow(int x, int y, int width, int height)
632 wxAutoNSAutoreleasePool pool;
633 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoMoveWindow(%d,%d,%d,%d)"),this,x,y,width,height);
635 NSView *nsview = GetNSViewForSuperview();
636 NSView *superview = [nsview superview];
637 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
638 NSRect parentRect = [superview bounds];
640 NSRect cocoaRect = NSMakeRect(x,parentRect.size.height-(y+height),width,height);
641 [nsview setFrame: cocoaRect];
642 // Be sure to redraw the parent to reflect the changed position
643 [superview setNeedsDisplay:YES];
646 void wxWindowCocoa::SetInitialFrameRect(const wxPoint& pos, const wxSize& size)
648 NSView *nsview = GetNSViewForSuperview();
649 NSView *superview = [nsview superview];
650 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
651 NSRect parentRect = [superview bounds];
652 NSRect frameRect = [nsview frame];
654 frameRect.size.width = size.x;
656 frameRect.size.height = size.y;
657 frameRect.origin.x = pos.x;
658 frameRect.origin.y = parentRect.size.height-(pos.y+frameRect.size.height);
659 // Tell Cocoa to change the margin between the bottom of the superview
660 // and the bottom of the control. Keeps the control pinned to the top
661 // of its superview so that its position in the wxWidgets coordinate
662 // system doesn't change.
663 if(![superview isFlipped])
664 [nsview setAutoresizingMask: NSViewMinYMargin];
665 // MUST set the mask before setFrame: which can generate a size event
666 // and cause a scroller to be added!
667 [nsview setFrame: frameRect];
671 void wxWindow::DoGetSize(int *w, int *h) const
673 NSRect cocoaRect = [GetNSViewForSuperview() frame];
675 *w=(int)cocoaRect.size.width;
677 *h=(int)cocoaRect.size.height;
678 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoGetSize = (%d,%d)"),this,(int)cocoaRect.size.width,(int)cocoaRect.size.height);
681 void wxWindow::DoGetPosition(int *x, int *y) const
683 NSView *nsview = GetNSViewForSuperview();
684 NSView *superview = [nsview superview];
685 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
686 NSRect parentRect = [superview bounds];
688 NSRect cocoaRect = [nsview frame];
690 *x=(int)cocoaRect.origin.x;
692 *y=(int)(parentRect.size.height-(cocoaRect.origin.y+cocoaRect.size.height));
693 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoGetPosition = (%d,%d)"),this,(int)cocoaRect.origin.x,(int)cocoaRect.origin.y);
696 WXWidget wxWindow::GetHandle() const
698 return m_cocoaNSView;
701 void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
703 [m_cocoaNSView setNeedsDisplay:YES];
706 void wxWindow::SetFocus()
711 void wxWindow::DoCaptureMouse()
714 sm_capturedWindow = this;
717 void wxWindow::DoReleaseMouse()
720 sm_capturedWindow = NULL;
723 void wxWindow::DoScreenToClient(int *x, int *y) const
728 void wxWindow::DoClientToScreen(int *x, int *y) const
733 // Get size *available for subwindows* i.e. excluding menu bar etc.
734 void wxWindow::DoGetClientSize(int *x, int *y) const
736 wxLogTrace(wxTRACE_COCOA,wxT("DoGetClientSize:"));
738 m_cocoaScroller->DoGetClientSize(x,y);
740 wxWindowCocoa::DoGetSize(x,y);
743 void wxWindow::DoSetClientSize(int width, int height)
745 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("DoSetClientSize=(%d,%d)"),width,height);
747 m_cocoaScroller->ClientSizeToSize(width,height);
748 CocoaSetWxWindowSize(width,height);
751 void wxWindow::CocoaSetWxWindowSize(int width, int height)
753 wxWindowCocoa::DoSetSize(-1,-1,width,height,wxSIZE_USE_EXISTING);
756 int wxWindow::GetCharHeight() const
762 int wxWindow::GetCharWidth() const
768 void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
769 int *descent, int *externalLeading, const wxFont *theFont) const
774 // Coordinates relative to the window
775 void wxWindow::WarpPointer (int x_pos, int y_pos)
780 int wxWindow::GetScrollPos(int orient) const
786 // This now returns the whole range, not just the number
787 // of positions that we can scroll.
788 int wxWindow::GetScrollRange(int orient) const
794 int wxWindow::GetScrollThumb(int orient) const
800 void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
805 void wxWindow::CocoaCreateNSScrollView()
809 m_cocoaScroller = new wxWindowCocoaScroller(this);
813 // New function that will replace some of the above.
814 void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
815 int range, bool refresh)
817 CocoaCreateNSScrollView();
821 // Does a physical scroll
822 void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
827 void wxWindow::DoSetVirtualSize( int x, int y )
829 wxWindowBase::DoSetVirtualSize(x,y);
830 CocoaCreateNSScrollView();
831 [m_cocoaNSView setFrameSize:NSMakeSize(m_virtualSize.x,m_virtualSize.y)];
834 bool wxWindow::SetFont(const wxFont& font)
840 static int CocoaRaiseWindowCompareFunction(id first, id second, void *target)
842 // first should be ordered higher
844 return NSOrderedDescending;
845 // second should be ordered higher
847 return NSOrderedAscending;
848 return NSOrderedSame;
851 // Raise the window to the top of the Z order
852 void wxWindow::Raise()
854 // wxAutoNSAutoreleasePool pool;
855 NSView *nsview = GetNSViewForSuperview();
856 [[nsview superview] sortSubviewsUsingFunction:
857 CocoaRaiseWindowCompareFunction
861 static int CocoaLowerWindowCompareFunction(id first, id second, void *target)
863 // first should be ordered lower
865 return NSOrderedAscending;
866 // second should be ordered lower
868 return NSOrderedDescending;
869 return NSOrderedSame;
872 // Lower the window to the bottom of the Z order
873 void wxWindow::Lower()
875 NSView *nsview = GetNSViewForSuperview();
876 [[nsview superview] sortSubviewsUsingFunction:
877 CocoaLowerWindowCompareFunction
881 bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
886 // Get the window with the focus
887 wxWindow *wxWindowBase::DoFindFocus()
893 /* static */ wxWindow *wxWindowBase::GetCapture()
896 return wxWindowCocoa::sm_capturedWindow;
899 wxWindow *wxGetActiveWindow()
905 wxPoint wxGetMousePosition()
908 return wxDefaultPosition;
911 wxWindow* wxFindWindowAtPointer(wxPoint& pt)
913 pt = wxGetMousePosition();