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/window.h"
17 #include "wx/tooltip.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 // Turn this on to paint green over the dummy views for debugging
30 #undef WXCOCOA_FILL_DUMMY_VIEW
32 #ifdef WXCOCOA_FILL_DUMMY_VIEW
33 #import <AppKit/NSBezierPath.h>
34 #endif //def WXCOCOA_FILL_DUMMY_VIEW
36 // A category for methods that are only present in Panther's SDK
37 @interface NSView(wxNSViewPrePantherCompatibility)
38 - (void)getRectsBeingDrawn:(const NSRect **)rects count:(int *)count;
41 // ========================================================================
43 // ========================================================================
44 class wxWindowCocoaHider: protected wxCocoaNSView
46 DECLARE_NO_COPY_CLASS(wxWindowCocoaHider)
48 wxWindowCocoaHider(wxWindow *owner);
49 virtual ~wxWindowCocoaHider();
50 inline WX_NSView GetNSView() { return m_dummyNSView; }
52 wxWindowCocoa *m_owner;
53 WX_NSView m_dummyNSView;
54 virtual void Cocoa_FrameChanged(void);
55 #ifdef WXCOCOA_FILL_DUMMY_VIEW
56 virtual bool Cocoa_drawRect(const NSRect& rect);
57 #endif //def WXCOCOA_FILL_DUMMY_VIEW
62 // ========================================================================
63 // wxWindowCocoaScroller
64 // ========================================================================
65 class wxWindowCocoaScroller: protected wxCocoaNSView
67 DECLARE_NO_COPY_CLASS(wxWindowCocoaScroller)
69 wxWindowCocoaScroller(wxWindow *owner);
70 virtual ~wxWindowCocoaScroller();
71 inline WX_NSScrollView GetNSScrollView() { return m_cocoaNSScrollView; }
72 void ClientSizeToSize(int &width, int &height);
73 void DoGetClientSize(int *x, int *y) const;
77 wxWindowCocoa *m_owner;
78 WX_NSScrollView m_cocoaNSScrollView;
79 virtual void Cocoa_FrameChanged(void);
81 wxWindowCocoaScroller();
84 // ========================================================================
86 // ========================================================================
87 @interface wxDummyNSView : NSView
88 - (NSView *)hitTest:(NSPoint)aPoint;
91 @implementation wxDummyNSView : NSView
92 - (NSView *)hitTest:(NSPoint)aPoint
99 // ========================================================================
100 // wxWindowCocoaHider
101 // ========================================================================
102 wxWindowCocoaHider::wxWindowCocoaHider(wxWindow *owner)
106 wxASSERT(owner->GetNSViewForHiding());
107 m_dummyNSView = [[wxDummyNSView alloc]
108 initWithFrame:[owner->GetNSViewForHiding() frame]];
109 [m_dummyNSView setAutoresizingMask: [owner->GetNSViewForHiding() autoresizingMask]];
110 AssociateNSView(m_dummyNSView);
113 wxWindowCocoaHider::~wxWindowCocoaHider()
115 DisassociateNSView(m_dummyNSView);
116 [m_dummyNSView release];
119 void wxWindowCocoaHider::Cocoa_FrameChanged(void)
121 // Keep the real window in synch with the dummy
122 wxASSERT(m_dummyNSView);
123 [m_owner->GetNSViewForHiding() setFrame:[m_dummyNSView frame]];
127 #ifdef WXCOCOA_FILL_DUMMY_VIEW
128 bool wxWindowCocoaHider::Cocoa_drawRect(const NSRect& rect)
130 NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:rect];
131 [[NSColor greenColor] set];
136 #endif //def WXCOCOA_FILL_DUMMY_VIEW
138 // ========================================================================
139 // wxFlippedNSClipView
140 // ========================================================================
141 @interface wxFlippedNSClipView : NSClipView
145 @implementation wxFlippedNSClipView : NSClipView
153 // ========================================================================
154 // wxWindowCocoaScroller
155 // ========================================================================
156 wxWindowCocoaScroller::wxWindowCocoaScroller(wxWindow *owner)
159 wxAutoNSAutoreleasePool pool;
161 wxASSERT(owner->GetNSView());
162 m_cocoaNSScrollView = [[NSScrollView alloc]
163 initWithFrame:[owner->GetNSView() frame]];
164 AssociateNSView(m_cocoaNSScrollView);
166 /* Replace the default NSClipView with a flipped one. This ensures
167 scrolling is "pinned" to the top-left instead of bottom-right. */
168 NSClipView *flippedClip = [[wxFlippedNSClipView alloc]
169 initWithFrame: [[m_cocoaNSScrollView contentView] frame]];
170 [m_cocoaNSScrollView setContentView:flippedClip];
171 [flippedClip release];
173 [m_cocoaNSScrollView setBackgroundColor: [NSColor windowBackgroundColor]];
174 [m_cocoaNSScrollView setHasHorizontalScroller: YES];
175 [m_cocoaNSScrollView setHasVerticalScroller: YES];
179 void wxWindowCocoaScroller::Encapsulate()
181 // Set the scroll view autoresizingMask to match the current NSView
182 [m_cocoaNSScrollView setAutoresizingMask: [m_owner->GetNSView() autoresizingMask]];
183 [m_owner->GetNSView() setAutoresizingMask: NSViewNotSizable];
184 // NOTE: replaceSubView will cause m_cocaNSView to be released
185 // except when it hasn't been added into an NSView hierarchy in which
186 // case it doesn't need to be and this should work out to a no-op
187 m_owner->CocoaReplaceView(m_owner->GetNSView(), m_cocoaNSScrollView);
188 // The NSView is still retained by owner
189 [m_cocoaNSScrollView setDocumentView: m_owner->GetNSView()];
190 // Now it's also retained by the NSScrollView
193 void wxWindowCocoaScroller::Unencapsulate()
195 [m_cocoaNSScrollView setDocumentView: nil];
196 m_owner->CocoaReplaceView(m_cocoaNSScrollView, m_owner->GetNSView());
197 if(![[m_owner->GetNSView() superview] isFlipped])
198 [m_owner->GetNSView() setAutoresizingMask: NSViewMinYMargin];
201 wxWindowCocoaScroller::~wxWindowCocoaScroller()
203 DisassociateNSView(m_cocoaNSScrollView);
204 [m_cocoaNSScrollView release];
207 void wxWindowCocoaScroller::ClientSizeToSize(int &width, int &height)
209 NSSize frameSize = [NSScrollView
210 frameSizeForContentSize: NSMakeSize(width,height)
211 hasHorizontalScroller: [m_cocoaNSScrollView hasHorizontalScroller]
212 hasVerticalScroller: [m_cocoaNSScrollView hasVerticalScroller]
213 borderType: [m_cocoaNSScrollView borderType]];
214 width = (int)frameSize.width;
215 height = (int)frameSize.height;
218 void wxWindowCocoaScroller::DoGetClientSize(int *x, int *y) const
220 NSSize nssize = [m_cocoaNSScrollView contentSize];
222 *x = (int)nssize.width;
224 *y = (int)nssize.height;
227 void wxWindowCocoaScroller::Cocoa_FrameChanged(void)
229 wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_FrameChanged"));
230 wxSizeEvent event(m_owner->GetSize(), m_owner->GetId());
231 event.SetEventObject(m_owner);
232 m_owner->GetEventHandler()->ProcessEvent(event);
235 // ========================================================================
237 // ========================================================================
238 // normally the base classes aren't included, but wxWindow is special
239 #ifdef __WXUNIVERSAL__
240 IMPLEMENT_ABSTRACT_CLASS(wxWindowCocoa, wxWindowBase)
242 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
245 BEGIN_EVENT_TABLE(wxWindowCocoa, wxWindowBase)
248 wxWindow *wxWindowCocoa::sm_capturedWindow = NULL;
251 void wxWindowCocoa::Init()
253 m_cocoaNSView = NULL;
255 m_cocoaScroller = NULL;
256 m_isBeingDeleted = FALSE;
258 m_shouldBeEnabled = true;
262 bool wxWindow::Create(wxWindow *parent, wxWindowID winid,
266 const wxString& name)
268 if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name))
271 // TODO: create the window
272 m_cocoaNSView = NULL;
273 SetNSView([[NSView alloc] initWithFrame: MakeDefaultNSRect(size)]);
274 [m_cocoaNSView release];
278 m_parent->AddChild(this);
279 m_parent->CocoaAddChild(this);
280 SetInitialFrameRect(pos,size);
287 wxWindow::~wxWindow()
289 wxAutoNSAutoreleasePool pool;
292 // Make sure our parent (in the wxWidgets sense) is our superview
293 // before we go removing from it.
294 if(m_parent && m_parent->GetNSView()==[GetNSViewForSuperview() superview])
295 CocoaRemoveFromParent();
297 delete m_cocoaScroller;
303 void wxWindowCocoa::CocoaAddChild(wxWindowCocoa *child)
305 NSView *childView = child->GetNSViewForSuperview();
308 [m_cocoaNSView addSubview: childView];
309 child->m_isShown = !m_cocoaHider;
312 void wxWindowCocoa::CocoaRemoveFromParent(void)
314 [GetNSViewForSuperview() removeFromSuperview];
317 void wxWindowCocoa::SetNSView(WX_NSView cocoaNSView)
319 bool need_debug = cocoaNSView || m_cocoaNSView;
320 if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxWindowCocoa=%p::SetNSView [m_cocoaNSView=%p retainCount]=%d"),this,m_cocoaNSView,[m_cocoaNSView retainCount]);
321 DisassociateNSView(m_cocoaNSView);
322 [cocoaNSView retain];
323 [m_cocoaNSView release];
324 m_cocoaNSView = cocoaNSView;
325 AssociateNSView(m_cocoaNSView);
326 if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxWindowCocoa=%p::SetNSView [cocoaNSView=%p retainCount]=%d"),this,cocoaNSView,[cocoaNSView retainCount]);
329 WX_NSView wxWindowCocoa::GetNSViewForSuperview() const
332 ? m_cocoaHider->GetNSView()
334 ? m_cocoaScroller->GetNSScrollView()
338 WX_NSView wxWindowCocoa::GetNSViewForHiding() const
340 return m_cocoaScroller
341 ? m_cocoaScroller->GetNSScrollView()
345 bool wxWindowCocoa::Cocoa_drawRect(const NSRect &rect)
347 wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_drawRect"));
348 // Recursion can happen if the event loop runs from within the paint
349 // handler. For instance, if an assertion dialog is shown.
350 // FIXME: This seems less than ideal.
353 wxLogDebug(wxT("Paint event recursion!"));
358 // Set m_updateRegion
359 const NSRect *rects = ▭ // The bounding box of the region
361 // Try replacing the larger rectangle with a list of smaller ones:
362 if ([GetNSView() respondsToSelector:@selector(getRectsBeingDrawn:count:)])
363 [GetNSView() getRectsBeingDrawn:&rects count:&countRects];
364 m_updateRegion = wxRegion(rects,countRects);
366 wxPaintEvent event(m_windowId);
367 event.SetEventObject(this);
368 bool ret = GetEventHandler()->ProcessEvent(event);
373 void wxWindowCocoa::InitMouseEvent(wxMouseEvent& event, WX_NSEvent cocoaEvent)
375 wxASSERT_MSG([m_cocoaNSView window]==[cocoaEvent window],wxT("Mouse event for different NSWindow"));
376 NSPoint cocoaPoint = [m_cocoaNSView convertPoint:[(NSEvent*)cocoaEvent locationInWindow] fromView:nil];
377 NSRect cocoaRect = [m_cocoaNSView frame];
378 const wxPoint &clientorigin = GetClientAreaOrigin();
379 event.m_x = (wxCoord)cocoaPoint.x - clientorigin.x;
380 event.m_y = (wxCoord)(cocoaRect.size.height - cocoaPoint.y) - clientorigin.y;
382 event.m_shiftDown = [cocoaEvent modifierFlags] & NSShiftKeyMask;
383 event.m_controlDown = [cocoaEvent modifierFlags] & NSControlKeyMask;
384 event.m_altDown = [cocoaEvent modifierFlags] & NSAlternateKeyMask;
385 event.m_metaDown = [cocoaEvent modifierFlags] & NSCommandKeyMask;
387 // TODO: set timestamp?
388 event.SetEventObject(this);
389 event.SetId(GetId());
392 bool wxWindowCocoa::Cocoa_mouseMoved(WX_NSEvent theEvent)
394 wxMouseEvent event(wxEVT_MOTION);
395 InitMouseEvent(event,theEvent);
396 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y);
397 return GetEventHandler()->ProcessEvent(event);
400 bool wxWindowCocoa::Cocoa_mouseEntered(WX_NSEvent theEvent)
405 bool wxWindowCocoa::Cocoa_mouseExited(WX_NSEvent theEvent)
410 bool wxWindowCocoa::Cocoa_mouseDown(WX_NSEvent theEvent)
412 wxMouseEvent event([theEvent clickCount]<2?wxEVT_LEFT_DOWN:wxEVT_LEFT_DCLICK);
413 InitMouseEvent(event,theEvent);
414 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Down @%d,%d num clicks=%d"),event.m_x,event.m_y,[theEvent clickCount]);
415 return GetEventHandler()->ProcessEvent(event);
418 bool wxWindowCocoa::Cocoa_mouseDragged(WX_NSEvent theEvent)
420 wxMouseEvent event(wxEVT_MOTION);
421 InitMouseEvent(event,theEvent);
422 event.m_leftDown = true;
423 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y);
424 return GetEventHandler()->ProcessEvent(event);
427 bool wxWindowCocoa::Cocoa_mouseUp(WX_NSEvent theEvent)
429 wxMouseEvent event(wxEVT_LEFT_UP);
430 InitMouseEvent(event,theEvent);
431 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Up @%d,%d"),event.m_x,event.m_y);
432 return GetEventHandler()->ProcessEvent(event);
435 bool wxWindowCocoa::Cocoa_rightMouseDown(WX_NSEvent theEvent)
437 wxMouseEvent event([theEvent clickCount]<2?wxEVT_RIGHT_DOWN:wxEVT_RIGHT_DCLICK);
438 InitMouseEvent(event,theEvent);
439 wxLogDebug(wxT("Mouse Down @%d,%d num clicks=%d"),event.m_x,event.m_y,[theEvent clickCount]);
440 return GetEventHandler()->ProcessEvent(event);
443 bool wxWindowCocoa::Cocoa_rightMouseDragged(WX_NSEvent theEvent)
445 wxMouseEvent event(wxEVT_MOTION);
446 InitMouseEvent(event,theEvent);
447 event.m_rightDown = true;
448 wxLogDebug(wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y);
449 return GetEventHandler()->ProcessEvent(event);
452 bool wxWindowCocoa::Cocoa_rightMouseUp(WX_NSEvent theEvent)
454 wxMouseEvent event(wxEVT_RIGHT_UP);
455 InitMouseEvent(event,theEvent);
456 wxLogDebug(wxT("Mouse Up @%d,%d"),event.m_x,event.m_y);
457 return GetEventHandler()->ProcessEvent(event);
460 bool wxWindowCocoa::Cocoa_otherMouseDown(WX_NSEvent theEvent)
465 bool wxWindowCocoa::Cocoa_otherMouseDragged(WX_NSEvent theEvent)
470 bool wxWindowCocoa::Cocoa_otherMouseUp(WX_NSEvent theEvent)
475 void wxWindowCocoa::Cocoa_FrameChanged(void)
477 wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_FrameChanged"));
478 wxSizeEvent event(GetSize(), m_windowId);
479 event.SetEventObject(this);
480 GetEventHandler()->ProcessEvent(event);
483 bool wxWindowCocoa::Cocoa_resetCursorRects()
485 if(!m_cursor.GetNSCursor())
488 [GetNSView() addCursorRect: [GetNSView() visibleRect] cursor: m_cursor.GetNSCursor()];
493 bool wxWindow::Close(bool force)
495 // The only reason this function exists is that it is virtual and
496 // wxTopLevelWindowCocoa will override it.
497 return wxWindowBase::Close(force);
500 void wxWindow::CocoaReplaceView(WX_NSView oldView, WX_NSView newView)
502 [[oldView superview] replaceSubview:oldView with:newView];
505 bool wxWindow::EnableSelfAndChildren(bool enable)
507 // If the state isn't changing, don't do anything
508 if(!wxWindowBase::Enable(enable && m_shouldBeEnabled))
510 // Set the state of the Cocoa window
511 CocoaSetEnabled(m_isEnabled);
512 // Disable all children or (if enabling) return them to their proper state
513 for(wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
514 node; node = node->GetNext())
516 node->GetData()->EnableSelfAndChildren(enable);
521 bool wxWindow::Enable(bool enable)
523 // Keep track of what the window SHOULD be doing
524 m_shouldBeEnabled = enable;
525 // If the parent is disabled for any reason, then this window will be too.
526 if(!IsTopLevel() && GetParent())
528 enable = enable && GetParent()->IsEnabled();
530 return EnableSelfAndChildren(enable);
533 bool wxWindow::Show(bool show)
535 wxAutoNSAutoreleasePool pool;
536 // If the window is marked as visible, then it shouldn't have a dummy view
537 // If the window is marked hidden, then it should have a dummy view
538 // wxSpinCtrl (generic) abuses m_isShown, don't use it for any logic
539 // wxASSERT_MSG( (m_isShown && !m_dummyNSView) || (!m_isShown && m_dummyNSView),wxT("wxWindow: m_isShown does not agree with m_dummyNSView"));
540 // Return false if there isn't a window to show or hide
541 NSView *cocoaView = GetNSViewForHiding();
546 // If state isn't changing, return false
549 CocoaReplaceView(m_cocoaHider->GetNSView(), cocoaView);
550 wxASSERT(![m_cocoaHider->GetNSView() superview]);
553 wxASSERT([cocoaView superview]);
557 // If state isn't changing, return false
560 m_cocoaHider = new wxWindowCocoaHider(this);
561 // NOTE: replaceSubview:with will cause m_cocaNSView to be
562 // (auto)released which balances out addSubview
563 CocoaReplaceView(cocoaView, m_cocoaHider->GetNSView());
564 // m_coocaNSView is now only retained by us
565 wxASSERT([m_cocoaHider->GetNSView() superview]);
566 wxASSERT(![cocoaView superview]);
572 void wxWindowCocoa::DoSetSize(int x, int y, int width, int height, int sizeFlags)
574 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":".");
575 int currentX, currentY;
576 int currentW, currentH;
577 DoGetPosition(¤tX, ¤tY);
578 DoGetSize(¤tW, ¤tH);
579 if((x==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
581 if((y==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
584 AdjustForParentClientOrigin(x,y,sizeFlags);
588 if((width==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
590 if(sizeFlags&wxSIZE_AUTO_WIDTH)
592 size=DoGetBestSize();
598 if((height==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
600 if(sizeFlags&wxSIZE_AUTO_HEIGHT)
603 size=DoGetBestSize();
609 DoMoveWindow(x,y,width,height);
614 void wxWindowCocoa::DoSetToolTip( wxToolTip *tip )
616 wxWindowBase::DoSetToolTip(tip);
620 m_tooltip->SetWindow((wxWindow *)this);
626 void wxWindowCocoa::DoMoveWindow(int x, int y, int width, int height)
628 wxAutoNSAutoreleasePool pool;
629 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoMoveWindow(%d,%d,%d,%d)"),this,x,y,width,height);
631 NSView *nsview = GetNSViewForSuperview();
632 NSView *superview = [nsview superview];
633 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
634 NSRect parentRect = [superview bounds];
636 NSRect cocoaRect = NSMakeRect(x,parentRect.size.height-(y+height),width,height);
637 [nsview setFrame: cocoaRect];
638 // Be sure to redraw the parent to reflect the changed position
639 [superview setNeedsDisplay:YES];
642 void wxWindowCocoa::SetInitialFrameRect(const wxPoint& pos, const wxSize& size)
644 NSView *nsview = GetNSViewForSuperview();
645 NSView *superview = [nsview superview];
646 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
647 NSRect parentRect = [superview bounds];
648 NSRect frameRect = [nsview frame];
650 frameRect.size.width = size.x;
652 frameRect.size.height = size.y;
653 frameRect.origin.x = pos.x;
654 frameRect.origin.y = parentRect.size.height-(pos.y+frameRect.size.height);
655 // Tell Cocoa to change the margin between the bottom of the superview
656 // and the bottom of the control. Keeps the control pinned to the top
657 // of its superview so that its position in the wxWidgets coordinate
658 // system doesn't change.
659 if(![superview isFlipped])
660 [nsview setAutoresizingMask: NSViewMinYMargin];
661 // MUST set the mask before setFrame: which can generate a size event
662 // and cause a scroller to be added!
663 [nsview setFrame: frameRect];
667 void wxWindow::DoGetSize(int *w, int *h) const
669 NSRect cocoaRect = [GetNSViewForSuperview() frame];
671 *w=(int)cocoaRect.size.width;
673 *h=(int)cocoaRect.size.height;
674 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoGetSize = (%d,%d)"),this,(int)cocoaRect.size.width,(int)cocoaRect.size.height);
677 void wxWindow::DoGetPosition(int *x, int *y) const
679 NSView *nsview = GetNSViewForSuperview();
680 NSView *superview = [nsview superview];
681 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
682 NSRect parentRect = [superview bounds];
684 NSRect cocoaRect = [nsview frame];
686 *x=(int)cocoaRect.origin.x;
688 *y=(int)(parentRect.size.height-(cocoaRect.origin.y+cocoaRect.size.height));
689 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoGetPosition = (%d,%d)"),this,(int)cocoaRect.origin.x,(int)cocoaRect.origin.y);
692 WXWidget wxWindow::GetHandle() const
694 return m_cocoaNSView;
697 wxWindow* wxWindow::GetWxWindow() const
699 return (wxWindow*) this;
702 void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
704 [m_cocoaNSView setNeedsDisplay:YES];
707 void wxWindow::SetFocus()
712 [GetNSView() lockFocusIfCanDraw];
714 //Note that the normal lockFocus works on hidden and minimized windows
715 //and has no return value - which probably isn't what we want
719 void wxWindow::DoCaptureMouse()
722 sm_capturedWindow = this;
725 void wxWindow::DoReleaseMouse()
728 sm_capturedWindow = NULL;
731 void wxWindow::DoScreenToClient(int *x, int *y) const
736 void wxWindow::DoClientToScreen(int *x, int *y) const
741 // Get size *available for subwindows* i.e. excluding menu bar etc.
742 void wxWindow::DoGetClientSize(int *x, int *y) const
744 wxLogTrace(wxTRACE_COCOA,wxT("DoGetClientSize:"));
746 m_cocoaScroller->DoGetClientSize(x,y);
748 wxWindowCocoa::DoGetSize(x,y);
751 void wxWindow::DoSetClientSize(int width, int height)
753 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("DoSetClientSize=(%d,%d)"),width,height);
755 m_cocoaScroller->ClientSizeToSize(width,height);
756 CocoaSetWxWindowSize(width,height);
759 void wxWindow::CocoaSetWxWindowSize(int width, int height)
761 wxWindowCocoa::DoSetSize(-1,-1,width,height,wxSIZE_USE_EXISTING);
764 int wxWindow::GetCharHeight() const
770 int wxWindow::GetCharWidth() const
776 void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
777 int *descent, int *externalLeading, const wxFont *theFont) const
782 // Coordinates relative to the window
783 void wxWindow::WarpPointer (int x_pos, int y_pos)
788 int wxWindow::GetScrollPos(int orient) const
794 // This now returns the whole range, not just the number
795 // of positions that we can scroll.
796 int wxWindow::GetScrollRange(int orient) const
802 int wxWindow::GetScrollThumb(int orient) const
808 void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
813 void wxWindow::CocoaCreateNSScrollView()
817 m_cocoaScroller = new wxWindowCocoaScroller(this);
821 // New function that will replace some of the above.
822 void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
823 int range, bool refresh)
825 CocoaCreateNSScrollView();
829 // Does a physical scroll
830 void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
835 void wxWindow::DoSetVirtualSize( int x, int y )
837 wxWindowBase::DoSetVirtualSize(x,y);
838 CocoaCreateNSScrollView();
839 [m_cocoaNSView setFrameSize:NSMakeSize(m_virtualSize.x,m_virtualSize.y)];
842 bool wxWindow::SetFont(const wxFont& font)
848 static int CocoaRaiseWindowCompareFunction(id first, id second, void *target)
850 // first should be ordered higher
852 return NSOrderedDescending;
853 // second should be ordered higher
855 return NSOrderedAscending;
856 return NSOrderedSame;
859 // Raise the window to the top of the Z order
860 void wxWindow::Raise()
862 // wxAutoNSAutoreleasePool pool;
863 NSView *nsview = GetNSViewForSuperview();
864 [[nsview superview] sortSubviewsUsingFunction:
865 CocoaRaiseWindowCompareFunction
869 static int CocoaLowerWindowCompareFunction(id first, id second, void *target)
871 // first should be ordered lower
873 return NSOrderedAscending;
874 // second should be ordered lower
876 return NSOrderedDescending;
877 return NSOrderedSame;
880 // Lower the window to the bottom of the Z order
881 void wxWindow::Lower()
883 NSView *nsview = GetNSViewForSuperview();
884 [[nsview superview] sortSubviewsUsingFunction:
885 CocoaLowerWindowCompareFunction
889 bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
894 // Get the window with the focus
895 wxWindow *wxWindowBase::DoFindFocus()
897 wxCocoaNSView *win = wxCocoaNSView::GetFromCocoa([NSView focusView]);
902 return win->GetWxWindow();
905 /* static */ wxWindow *wxWindowBase::GetCapture()
908 return wxWindowCocoa::sm_capturedWindow;
911 wxWindow *wxGetActiveWindow()
917 wxPoint wxGetMousePosition()
920 return wxDefaultPosition;
923 wxWindow* wxFindWindowAtPointer(wxPoint& pt)
925 pt = wxGetMousePosition();