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>
29 #include <objc/objc-runtime.h>
31 // Turn this on to paint green over the dummy views for debugging
32 #undef WXCOCOA_FILL_DUMMY_VIEW
34 #ifdef WXCOCOA_FILL_DUMMY_VIEW
35 #import <AppKit/NSBezierPath.h>
36 #endif //def WXCOCOA_FILL_DUMMY_VIEW
38 // ========================================================================
40 // ========================================================================
41 class wxWindowCocoaHider: protected wxCocoaNSView
43 DECLARE_NO_COPY_CLASS(wxWindowCocoaHider)
45 wxWindowCocoaHider(wxWindow *owner);
46 virtual ~wxWindowCocoaHider();
47 inline WX_NSView GetNSView() { return m_dummyNSView; }
49 wxWindowCocoa *m_owner;
50 WX_NSView m_dummyNSView;
51 virtual void Cocoa_FrameChanged(void);
52 #ifdef WXCOCOA_FILL_DUMMY_VIEW
53 virtual bool Cocoa_drawRect(const NSRect& rect);
54 #endif //def WXCOCOA_FILL_DUMMY_VIEW
59 // ========================================================================
60 // wxWindowCocoaScroller
61 // ========================================================================
62 class wxWindowCocoaScroller: protected wxCocoaNSView
64 DECLARE_NO_COPY_CLASS(wxWindowCocoaScroller)
66 wxWindowCocoaScroller(wxWindow *owner);
67 virtual ~wxWindowCocoaScroller();
68 inline WX_NSScrollView GetNSScrollView() { return m_cocoaNSScrollView; }
69 void ClientSizeToSize(int &width, int &height);
70 void DoGetClientSize(int *x, int *y) const;
74 wxWindowCocoa *m_owner;
75 WX_NSScrollView m_cocoaNSScrollView;
76 virtual void Cocoa_FrameChanged(void);
78 wxWindowCocoaScroller();
81 // ========================================================================
83 // ========================================================================
84 @interface wxDummyNSView : NSView
85 - (NSView *)hitTest:(NSPoint)aPoint;
88 @implementation wxDummyNSView : NSView
89 - (NSView *)hitTest:(NSPoint)aPoint
96 // ========================================================================
98 // ========================================================================
99 wxWindowCocoaHider::wxWindowCocoaHider(wxWindow *owner)
103 wxASSERT(owner->GetNSViewForHiding());
104 m_dummyNSView = [[wxDummyNSView alloc]
105 initWithFrame:[owner->GetNSViewForHiding() frame]];
106 [m_dummyNSView setAutoresizingMask: [owner->GetNSViewForHiding() autoresizingMask]];
107 AssociateNSView(m_dummyNSView);
110 wxWindowCocoaHider::~wxWindowCocoaHider()
112 DisassociateNSView(m_dummyNSView);
113 [m_dummyNSView release];
116 void wxWindowCocoaHider::Cocoa_FrameChanged(void)
118 // Keep the real window in synch with the dummy
119 wxASSERT(m_dummyNSView);
120 [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 wxWindowCocoa::Cocoa_resetCursorRects()
486 if(!m_cursor.GetNSCursor())
489 [GetNSView() addCursorRect: [GetNSView() visibleRect] cursor: m_cursor.GetNSCursor()];
494 bool wxWindow::Close(bool force)
496 // The only reason this function exists is that it is virtual and
497 // wxTopLevelWindowCocoa will override it.
498 return wxWindowBase::Close(force);
501 void wxWindow::CocoaReplaceView(WX_NSView oldView, WX_NSView newView)
503 [[oldView superview] replaceSubview:oldView with:newView];
506 bool wxWindow::EnableSelfAndChildren(bool enable)
508 // If the state isn't changing, don't do anything
509 if(!wxWindowBase::Enable(enable && m_shouldBeEnabled))
511 // Set the state of the Cocoa window
512 CocoaSetEnabled(m_isEnabled);
513 // Disable all children or (if enabling) return them to their proper state
514 for(wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
515 node; node = node->GetNext())
517 node->GetData()->EnableSelfAndChildren(enable);
522 bool wxWindow::Enable(bool enable)
524 // Keep track of what the window SHOULD be doing
525 m_shouldBeEnabled = enable;
526 // If the parent is disabled for any reason, then this window will be too.
527 if(!IsTopLevel() && GetParent())
529 enable = enable && GetParent()->IsEnabled();
531 return EnableSelfAndChildren(enable);
534 bool wxWindow::Show(bool show)
536 wxAutoNSAutoreleasePool pool;
537 // If the window is marked as visible, then it shouldn't have a dummy view
538 // If the window is marked hidden, then it should have a dummy view
539 // wxSpinCtrl (generic) abuses m_isShown, don't use it for any logic
540 // wxASSERT_MSG( (m_isShown && !m_dummyNSView) || (!m_isShown && m_dummyNSView),wxT("wxWindow: m_isShown does not agree with m_dummyNSView"));
541 // Return false if there isn't a window to show or hide
542 NSView *cocoaView = GetNSViewForHiding();
547 // If state isn't changing, return false
550 CocoaReplaceView(m_cocoaHider->GetNSView(), cocoaView);
551 wxASSERT(![m_cocoaHider->GetNSView() superview]);
554 wxASSERT([cocoaView superview]);
558 // If state isn't changing, return false
561 m_cocoaHider = new wxWindowCocoaHider(this);
562 // NOTE: replaceSubview:with will cause m_cocaNSView to be
563 // (auto)released which balances out addSubview
564 CocoaReplaceView(cocoaView, m_cocoaHider->GetNSView());
565 // m_coocaNSView is now only retained by us
566 wxASSERT([m_cocoaHider->GetNSView() superview]);
567 wxASSERT(![cocoaView superview]);
573 void wxWindowCocoa::DoSetSize(int x, int y, int width, int height, int sizeFlags)
575 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":".");
576 int currentX, currentY;
577 int currentW, currentH;
578 DoGetPosition(¤tX, ¤tY);
579 DoGetSize(¤tW, ¤tH);
580 if((x==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
582 if((y==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
585 AdjustForParentClientOrigin(x,y,sizeFlags);
589 if((width==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
591 if(sizeFlags&wxSIZE_AUTO_WIDTH)
593 size=DoGetBestSize();
599 if((height==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
601 if(sizeFlags&wxSIZE_AUTO_HEIGHT)
604 size=DoGetBestSize();
610 DoMoveWindow(x,y,width,height);
615 void wxWindowCocoa::DoSetToolTip( wxToolTip *tip )
617 wxWindowBase::DoSetToolTip(tip);
621 m_tooltip->SetWindow((wxWindow *)this);
627 void wxWindowCocoa::DoMoveWindow(int x, int y, int width, int height)
629 wxAutoNSAutoreleasePool pool;
630 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoMoveWindow(%d,%d,%d,%d)"),this,x,y,width,height);
632 NSView *nsview = GetNSViewForSuperview();
633 NSView *superview = [nsview superview];
634 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
635 NSRect parentRect = [superview bounds];
637 NSRect cocoaRect = NSMakeRect(x,parentRect.size.height-(y+height),width,height);
638 [nsview setFrame: cocoaRect];
639 // Be sure to redraw the parent to reflect the changed position
640 [superview setNeedsDisplay:YES];
643 void wxWindowCocoa::SetInitialFrameRect(const wxPoint& pos, const wxSize& size)
645 NSView *nsview = GetNSViewForSuperview();
646 NSView *superview = [nsview superview];
647 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
648 NSRect parentRect = [superview bounds];
649 NSRect frameRect = [nsview frame];
651 frameRect.size.width = size.x;
653 frameRect.size.height = size.y;
654 frameRect.origin.x = pos.x;
655 frameRect.origin.y = parentRect.size.height-(pos.y+frameRect.size.height);
656 // Tell Cocoa to change the margin between the bottom of the superview
657 // and the bottom of the control. Keeps the control pinned to the top
658 // of its superview so that its position in the wxWidgets coordinate
659 // system doesn't change.
660 if(![superview isFlipped])
661 [nsview setAutoresizingMask: NSViewMinYMargin];
662 // MUST set the mask before setFrame: which can generate a size event
663 // and cause a scroller to be added!
664 [nsview setFrame: frameRect];
668 void wxWindow::DoGetSize(int *w, int *h) const
670 NSRect cocoaRect = [GetNSViewForSuperview() frame];
672 *w=(int)cocoaRect.size.width;
674 *h=(int)cocoaRect.size.height;
675 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoGetSize = (%d,%d)"),this,(int)cocoaRect.size.width,(int)cocoaRect.size.height);
678 void wxWindow::DoGetPosition(int *x, int *y) const
680 NSView *nsview = GetNSViewForSuperview();
681 NSView *superview = [nsview superview];
682 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
683 NSRect parentRect = [superview bounds];
685 NSRect cocoaRect = [nsview frame];
687 *x=(int)cocoaRect.origin.x;
689 *y=(int)(parentRect.size.height-(cocoaRect.origin.y+cocoaRect.size.height));
690 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoGetPosition = (%d,%d)"),this,(int)cocoaRect.origin.x,(int)cocoaRect.origin.y);
693 WXWidget wxWindow::GetHandle() const
695 return m_cocoaNSView;
698 wxWindow* wxWindow::GetWxWindow() const
700 return (wxWindow*) this;
703 void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
705 [m_cocoaNSView setNeedsDisplay:YES];
708 void wxWindow::SetFocus()
713 [GetNSView() lockFocusIfCanDraw];
715 //Note that the normal lockFocus works on hidden and minimized windows
716 //and has no return value - which probably isn't what we want
720 void wxWindow::DoCaptureMouse()
723 sm_capturedWindow = this;
726 void wxWindow::DoReleaseMouse()
729 sm_capturedWindow = NULL;
732 void wxWindow::DoScreenToClient(int *x, int *y) const
737 void wxWindow::DoClientToScreen(int *x, int *y) const
742 // Get size *available for subwindows* i.e. excluding menu bar etc.
743 void wxWindow::DoGetClientSize(int *x, int *y) const
745 wxLogTrace(wxTRACE_COCOA,wxT("DoGetClientSize:"));
747 m_cocoaScroller->DoGetClientSize(x,y);
749 wxWindowCocoa::DoGetSize(x,y);
752 void wxWindow::DoSetClientSize(int width, int height)
754 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("DoSetClientSize=(%d,%d)"),width,height);
756 m_cocoaScroller->ClientSizeToSize(width,height);
757 CocoaSetWxWindowSize(width,height);
760 void wxWindow::CocoaSetWxWindowSize(int width, int height)
762 wxWindowCocoa::DoSetSize(-1,-1,width,height,wxSIZE_USE_EXISTING);
765 int wxWindow::GetCharHeight() const
771 int wxWindow::GetCharWidth() const
777 void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
778 int *descent, int *externalLeading, const wxFont *theFont) const
783 // Coordinates relative to the window
784 void wxWindow::WarpPointer (int x_pos, int y_pos)
789 int wxWindow::GetScrollPos(int orient) const
795 // This now returns the whole range, not just the number
796 // of positions that we can scroll.
797 int wxWindow::GetScrollRange(int orient) const
803 int wxWindow::GetScrollThumb(int orient) const
809 void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
814 void wxWindow::CocoaCreateNSScrollView()
818 m_cocoaScroller = new wxWindowCocoaScroller(this);
822 // New function that will replace some of the above.
823 void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
824 int range, bool refresh)
826 CocoaCreateNSScrollView();
830 // Does a physical scroll
831 void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
836 void wxWindow::DoSetVirtualSize( int x, int y )
838 wxWindowBase::DoSetVirtualSize(x,y);
839 CocoaCreateNSScrollView();
840 [m_cocoaNSView setFrameSize:NSMakeSize(m_virtualSize.x,m_virtualSize.y)];
843 bool wxWindow::SetFont(const wxFont& font)
849 static int CocoaRaiseWindowCompareFunction(id first, id second, void *target)
851 // first should be ordered higher
853 return NSOrderedDescending;
854 // second should be ordered higher
856 return NSOrderedAscending;
857 return NSOrderedSame;
860 // Raise the window to the top of the Z order
861 void wxWindow::Raise()
863 // wxAutoNSAutoreleasePool pool;
864 NSView *nsview = GetNSViewForSuperview();
865 [[nsview superview] sortSubviewsUsingFunction:
866 CocoaRaiseWindowCompareFunction
870 static int CocoaLowerWindowCompareFunction(id first, id second, void *target)
872 // first should be ordered lower
874 return NSOrderedAscending;
875 // second should be ordered lower
877 return NSOrderedDescending;
878 return NSOrderedSame;
881 // Lower the window to the bottom of the Z order
882 void wxWindow::Lower()
884 NSView *nsview = GetNSViewForSuperview();
885 [[nsview superview] sortSubviewsUsingFunction:
886 CocoaLowerWindowCompareFunction
890 bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
895 // Get the window with the focus
896 wxWindow *wxWindowBase::DoFindFocus()
898 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa([NSView focusView]);
903 return win->GetWxWindow();
906 /* static */ wxWindow *wxWindowBase::GetCapture()
909 return wxWindowCocoa::sm_capturedWindow;
912 wxWindow *wxGetActiveWindow()
918 wxPoint wxGetMousePosition()
921 return wxDefaultPosition;
924 wxWindow* wxFindWindowAtPointer(wxPoint& pt)
926 pt = wxGetMousePosition();