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"
18 #include "wx/cocoa/autorelease.h"
20 #import <AppKit/NSView.h>
21 #import <AppKit/NSEvent.h>
22 #import <AppKit/NSScrollView.h>
23 #import <AppKit/NSColor.h>
24 #import <AppKit/NSClipView.h>
25 #import <Foundation/NSException.h>
27 #include <objc/objc-runtime.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 // ========================================================================
38 // ========================================================================
39 class wxWindowCocoaHider: protected wxCocoaNSView
41 DECLARE_NO_COPY_CLASS(wxWindowCocoaHider)
43 wxWindowCocoaHider(wxWindow *owner);
44 virtual ~wxWindowCocoaHider();
45 inline WX_NSView GetNSView() { return m_dummyNSView; }
47 wxWindowCocoa *m_owner;
48 WX_NSView m_dummyNSView;
49 virtual void Cocoa_FrameChanged(void);
50 #ifdef WXCOCOA_FILL_DUMMY_VIEW
51 virtual bool Cocoa_drawRect(const NSRect& rect);
52 #endif //def WXCOCOA_FILL_DUMMY_VIEW
57 // ========================================================================
58 // wxWindowCocoaScroller
59 // ========================================================================
60 class wxWindowCocoaScroller: protected wxCocoaNSView
62 DECLARE_NO_COPY_CLASS(wxWindowCocoaScroller)
64 wxWindowCocoaScroller(wxWindow *owner);
65 virtual ~wxWindowCocoaScroller();
66 inline WX_NSScrollView GetNSScrollView() { return m_cocoaNSScrollView; }
67 void ClientSizeToSize(int &width, int &height);
68 void DoGetClientSize(int *x, int *y) const;
72 wxWindowCocoa *m_owner;
73 WX_NSScrollView m_cocoaNSScrollView;
74 virtual void Cocoa_FrameChanged(void);
76 wxWindowCocoaScroller();
79 // ========================================================================
81 // ========================================================================
82 @interface wxDummyNSView : NSView
83 - (NSView *)hitTest:(NSPoint)aPoint;
86 @implementation wxDummyNSView : NSView
87 - (NSView *)hitTest:(NSPoint)aPoint
94 // ========================================================================
96 // ========================================================================
97 wxWindowCocoaHider::wxWindowCocoaHider(wxWindow *owner)
101 wxASSERT(owner->GetNSViewForHiding());
102 m_dummyNSView = [[wxDummyNSView alloc]
103 initWithFrame:[owner->GetNSViewForHiding() frame]];
104 [m_dummyNSView setAutoresizingMask: [owner->GetNSViewForHiding() autoresizingMask]];
105 AssociateNSView(m_dummyNSView);
108 wxWindowCocoaHider::~wxWindowCocoaHider()
110 DisassociateNSView(m_dummyNSView);
111 [m_dummyNSView release];
114 void wxWindowCocoaHider::Cocoa_FrameChanged(void)
116 // Keep the real window in synch with the dummy
117 wxASSERT(m_dummyNSView);
118 [m_owner->GetNSViewForHiding() setFrame:[m_dummyNSView frame]];
121 #ifdef WXCOCOA_FILL_DUMMY_VIEW
122 bool wxWindowCocoaHider::Cocoa_drawRect(const NSRect& rect)
124 NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:rect];
125 [[NSColor greenColor] set];
130 #endif //def WXCOCOA_FILL_DUMMY_VIEW
132 // ========================================================================
133 // wxFlippedNSClipView
134 // ========================================================================
135 @interface wxFlippedNSClipView : NSClipView
139 @implementation wxFlippedNSClipView : NSClipView
147 // ========================================================================
148 // wxWindowCocoaScroller
149 // ========================================================================
150 wxWindowCocoaScroller::wxWindowCocoaScroller(wxWindow *owner)
153 wxAutoNSAutoreleasePool pool;
155 wxASSERT(owner->GetNSView());
156 m_cocoaNSScrollView = [[NSScrollView alloc]
157 initWithFrame:[owner->GetNSView() frame]];
158 AssociateNSView(m_cocoaNSScrollView);
160 /* Replace the default NSClipView with a flipped one. This ensures
161 scrolling is "pinned" to the top-left instead of bottom-right. */
162 NSClipView *flippedClip = [[wxFlippedNSClipView alloc]
163 initWithFrame: [[m_cocoaNSScrollView contentView] frame]];
164 [m_cocoaNSScrollView setContentView:flippedClip];
165 [flippedClip release];
167 [m_cocoaNSScrollView setBackgroundColor: [NSColor windowBackgroundColor]];
168 [m_cocoaNSScrollView setHasHorizontalScroller: YES];
169 [m_cocoaNSScrollView setHasVerticalScroller: YES];
173 void wxWindowCocoaScroller::Encapsulate()
175 // Set the scroll view autoresizingMask to match the current NSView
176 [m_cocoaNSScrollView setAutoresizingMask: [m_owner->GetNSView() autoresizingMask]];
177 [m_owner->GetNSView() setAutoresizingMask: NSViewNotSizable];
178 // NOTE: replaceSubView will cause m_cocaNSView to be released
179 // except when it hasn't been added into an NSView hierarchy in which
180 // case it doesn't need to be and this should work out to a no-op
181 m_owner->CocoaReplaceView(m_owner->GetNSView(), m_cocoaNSScrollView);
182 // The NSView is still retained by owner
183 [m_cocoaNSScrollView setDocumentView: m_owner->GetNSView()];
184 // Now it's also retained by the NSScrollView
187 void wxWindowCocoaScroller::Unencapsulate()
189 [m_cocoaNSScrollView setDocumentView: nil];
190 m_owner->CocoaReplaceView(m_cocoaNSScrollView, m_owner->GetNSView());
191 if(![[m_owner->GetNSView() superview] isFlipped])
192 [m_owner->GetNSView() setAutoresizingMask: NSViewMinYMargin];
195 wxWindowCocoaScroller::~wxWindowCocoaScroller()
197 DisassociateNSView(m_cocoaNSScrollView);
198 [m_cocoaNSScrollView release];
201 void wxWindowCocoaScroller::ClientSizeToSize(int &width, int &height)
203 NSSize frameSize = [NSScrollView
204 frameSizeForContentSize: NSMakeSize(width,height)
205 hasHorizontalScroller: [m_cocoaNSScrollView hasHorizontalScroller]
206 hasVerticalScroller: [m_cocoaNSScrollView hasVerticalScroller]
207 borderType: [m_cocoaNSScrollView borderType]];
208 width = (int)frameSize.width;
209 height = (int)frameSize.height;
212 void wxWindowCocoaScroller::DoGetClientSize(int *x, int *y) const
214 NSSize nssize = [m_cocoaNSScrollView contentSize];
216 *x = (int)nssize.width;
218 *y = (int)nssize.height;
221 void wxWindowCocoaScroller::Cocoa_FrameChanged(void)
223 wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_FrameChanged"));
224 wxSizeEvent event(m_owner->GetSize(), m_owner->GetId());
225 event.SetEventObject(m_owner);
226 m_owner->GetEventHandler()->ProcessEvent(event);
229 // ========================================================================
231 // ========================================================================
232 // normally the base classes aren't included, but wxWindow is special
233 #ifdef __WXUNIVERSAL__
234 IMPLEMENT_ABSTRACT_CLASS(wxWindowCocoa, wxWindowBase)
236 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
239 BEGIN_EVENT_TABLE(wxWindowCocoa, wxWindowBase)
242 wxWindow *wxWindowCocoa::sm_capturedWindow = NULL;
245 void wxWindowCocoa::Init()
247 m_cocoaNSView = NULL;
249 m_cocoaScroller = NULL;
250 m_isBeingDeleted = FALSE;
252 m_shouldBeEnabled = true;
256 bool wxWindow::Create(wxWindow *parent, wxWindowID winid,
260 const wxString& name)
262 if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name))
265 // TODO: create the window
266 m_cocoaNSView = NULL;
267 SetNSView([[NSView alloc] initWithFrame: MakeDefaultNSRect(size)]);
268 [m_cocoaNSView release];
272 m_parent->AddChild(this);
273 m_parent->CocoaAddChild(this);
274 SetInitialFrameRect(pos,size);
281 wxWindow::~wxWindow()
283 wxAutoNSAutoreleasePool pool;
286 // Make sure our parent (in the wxWidgets sense) is our superview
287 // before we go removing from it.
288 if(m_parent && m_parent->GetNSView()==[GetNSViewForSuperview() superview])
289 CocoaRemoveFromParent();
291 delete m_cocoaScroller;
297 void wxWindowCocoa::CocoaAddChild(wxWindowCocoa *child)
299 NSView *childView = child->GetNSViewForSuperview();
302 [m_cocoaNSView addSubview: childView];
303 child->m_isShown = !m_cocoaHider;
306 void wxWindowCocoa::CocoaRemoveFromParent(void)
308 [GetNSViewForSuperview() removeFromSuperview];
311 void wxWindowCocoa::SetNSView(WX_NSView cocoaNSView)
313 bool need_debug = cocoaNSView || m_cocoaNSView;
314 if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxWindowCocoa=%p::SetNSView [m_cocoaNSView=%p retainCount]=%d"),this,m_cocoaNSView,[m_cocoaNSView retainCount]);
315 DisassociateNSView(m_cocoaNSView);
316 [cocoaNSView retain];
317 [m_cocoaNSView release];
318 m_cocoaNSView = cocoaNSView;
319 AssociateNSView(m_cocoaNSView);
320 if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxWindowCocoa=%p::SetNSView [cocoaNSView=%p retainCount]=%d"),this,cocoaNSView,[cocoaNSView retainCount]);
323 WX_NSView wxWindowCocoa::GetNSViewForSuperview() const
326 ? m_cocoaHider->GetNSView()
328 ? m_cocoaScroller->GetNSScrollView()
332 WX_NSView wxWindowCocoa::GetNSViewForHiding() const
334 return m_cocoaScroller
335 ? m_cocoaScroller->GetNSScrollView()
339 bool wxWindowCocoa::Cocoa_drawRect(const NSRect &rect)
341 wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_drawRect"));
342 // Recursion can happen if the event loop runs from within the paint
343 // handler. For instance, if an assertion dialog is shown.
344 // FIXME: This seems less than ideal.
347 wxLogDebug(wxT("Paint event recursion!"));
352 // Set m_updateRegion
353 const NSRect *rects = ▭ // The bounding box of the region
355 // Try replacing the larger rectangle with a list of smaller ones:
357 // This only works on Panther
358 // [GetNSView() getRectsBeingDrawn:&rects count:&countRects];
359 // This compiles everywhere (and still only works on Panther)
360 objc_msgSend(GetNSView(),@selector(getRectsBeingDrawn:count:),&rects,&countRects);
363 m_updateRegion = wxRegion(rects,countRects);
365 wxPaintEvent event(m_windowId);
366 event.SetEventObject(this);
367 bool ret = GetEventHandler()->ProcessEvent(event);
372 void wxWindowCocoa::InitMouseEvent(wxMouseEvent& event, WX_NSEvent cocoaEvent)
374 wxASSERT_MSG([m_cocoaNSView window]==[cocoaEvent window],wxT("Mouse event for different NSWindow"));
375 NSPoint cocoaPoint = [m_cocoaNSView convertPoint:[(NSEvent*)cocoaEvent locationInWindow] fromView:nil];
376 NSRect cocoaRect = [m_cocoaNSView frame];
377 const wxPoint &clientorigin = GetClientAreaOrigin();
378 event.m_x = (wxCoord)cocoaPoint.x - clientorigin.x;
379 event.m_y = (wxCoord)(cocoaRect.size.height - cocoaPoint.y) - clientorigin.y;
381 event.m_shiftDown = [cocoaEvent modifierFlags] & NSShiftKeyMask;
382 event.m_controlDown = [cocoaEvent modifierFlags] & NSControlKeyMask;
383 event.m_altDown = [cocoaEvent modifierFlags] & NSAlternateKeyMask;
384 event.m_metaDown = [cocoaEvent modifierFlags] & NSCommandKeyMask;
386 // TODO: set timestamp?
387 event.SetEventObject(this);
388 event.SetId(GetId());
391 bool wxWindowCocoa::Cocoa_mouseMoved(WX_NSEvent theEvent)
393 wxMouseEvent event(wxEVT_MOTION);
394 InitMouseEvent(event,theEvent);
395 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y);
396 return GetEventHandler()->ProcessEvent(event);
399 bool wxWindowCocoa::Cocoa_mouseEntered(WX_NSEvent theEvent)
404 bool wxWindowCocoa::Cocoa_mouseExited(WX_NSEvent theEvent)
409 bool wxWindowCocoa::Cocoa_mouseDown(WX_NSEvent theEvent)
411 wxMouseEvent event([theEvent clickCount]<2?wxEVT_LEFT_DOWN:wxEVT_LEFT_DCLICK);
412 InitMouseEvent(event,theEvent);
413 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Down @%d,%d num clicks=%d"),event.m_x,event.m_y,[theEvent clickCount]);
414 return GetEventHandler()->ProcessEvent(event);
417 bool wxWindowCocoa::Cocoa_mouseDragged(WX_NSEvent theEvent)
419 wxMouseEvent event(wxEVT_MOTION);
420 InitMouseEvent(event,theEvent);
421 event.m_leftDown = true;
422 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y);
423 return GetEventHandler()->ProcessEvent(event);
426 bool wxWindowCocoa::Cocoa_mouseUp(WX_NSEvent theEvent)
428 wxMouseEvent event(wxEVT_LEFT_UP);
429 InitMouseEvent(event,theEvent);
430 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Up @%d,%d"),event.m_x,event.m_y);
431 return GetEventHandler()->ProcessEvent(event);
434 bool wxWindowCocoa::Cocoa_rightMouseDown(WX_NSEvent theEvent)
436 wxMouseEvent event([theEvent clickCount]<2?wxEVT_RIGHT_DOWN:wxEVT_RIGHT_DCLICK);
437 InitMouseEvent(event,theEvent);
438 wxLogDebug(wxT("Mouse Down @%d,%d num clicks=%d"),event.m_x,event.m_y,[theEvent clickCount]);
439 return GetEventHandler()->ProcessEvent(event);
442 bool wxWindowCocoa::Cocoa_rightMouseDragged(WX_NSEvent theEvent)
444 wxMouseEvent event(wxEVT_MOTION);
445 InitMouseEvent(event,theEvent);
446 event.m_rightDown = true;
447 wxLogDebug(wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y);
448 return GetEventHandler()->ProcessEvent(event);
451 bool wxWindowCocoa::Cocoa_rightMouseUp(WX_NSEvent theEvent)
453 wxMouseEvent event(wxEVT_RIGHT_UP);
454 InitMouseEvent(event,theEvent);
455 wxLogDebug(wxT("Mouse Up @%d,%d"),event.m_x,event.m_y);
456 return GetEventHandler()->ProcessEvent(event);
459 bool wxWindowCocoa::Cocoa_otherMouseDown(WX_NSEvent theEvent)
464 bool wxWindowCocoa::Cocoa_otherMouseDragged(WX_NSEvent theEvent)
469 bool wxWindowCocoa::Cocoa_otherMouseUp(WX_NSEvent theEvent)
474 void wxWindowCocoa::Cocoa_FrameChanged(void)
476 wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_FrameChanged"));
477 wxSizeEvent event(GetSize(), m_windowId);
478 event.SetEventObject(this);
479 GetEventHandler()->ProcessEvent(event);
482 bool wxWindow::Close(bool force)
484 // The only reason this function exists is that it is virtual and
485 // wxTopLevelWindowCocoa will override it.
486 return wxWindowBase::Close(force);
489 void wxWindow::CocoaReplaceView(WX_NSView oldView, WX_NSView newView)
491 [[oldView superview] replaceSubview:oldView with:newView];
494 bool wxWindow::EnableSelfAndChildren(bool enable)
496 // If the state isn't changing, don't do anything
497 if(!wxWindowBase::Enable(enable && m_shouldBeEnabled))
499 // Set the state of the Cocoa window
500 CocoaSetEnabled(m_isEnabled);
501 // Disable all children or (if enabling) return them to their proper state
502 for(wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
503 node; node = node->GetNext())
505 node->GetData()->EnableSelfAndChildren(enable);
510 bool wxWindow::Enable(bool enable)
512 // Keep track of what the window SHOULD be doing
513 m_shouldBeEnabled = enable;
514 // If the parent is disabled for any reason, then this window will be too.
515 if(!IsTopLevel() && GetParent())
517 enable = enable && GetParent()->IsEnabled();
519 return EnableSelfAndChildren(enable);
522 bool wxWindow::Show(bool show)
524 wxAutoNSAutoreleasePool pool;
525 // If the window is marked as visible, then it shouldn't have a dummy view
526 // If the window is marked hidden, then it should have a dummy view
527 // wxSpinCtrl (generic) abuses m_isShown, don't use it for any logic
528 // wxASSERT_MSG( (m_isShown && !m_dummyNSView) || (!m_isShown && m_dummyNSView),wxT("wxWindow: m_isShown does not agree with m_dummyNSView"));
529 // Return false if there isn't a window to show or hide
530 NSView *cocoaView = GetNSViewForHiding();
535 // If state isn't changing, return false
538 CocoaReplaceView(m_cocoaHider->GetNSView(), cocoaView);
539 wxASSERT(![m_cocoaHider->GetNSView() superview]);
542 wxASSERT([cocoaView superview]);
546 // If state isn't changing, return false
549 m_cocoaHider = new wxWindowCocoaHider(this);
550 // NOTE: replaceSubview:with will cause m_cocaNSView to be
551 // (auto)released which balances out addSubview
552 CocoaReplaceView(cocoaView, m_cocoaHider->GetNSView());
553 // m_coocaNSView is now only retained by us
554 wxASSERT([m_cocoaHider->GetNSView() superview]);
555 wxASSERT(![cocoaView superview]);
561 void wxWindowCocoa::DoSetSize(int x, int y, int width, int height, int sizeFlags)
563 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":".");
564 int currentX, currentY;
565 int currentW, currentH;
566 DoGetPosition(¤tX, ¤tY);
567 DoGetSize(¤tW, ¤tH);
568 if((x==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
570 if((y==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
573 AdjustForParentClientOrigin(x,y,sizeFlags);
577 if((width==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
579 if(sizeFlags&wxSIZE_AUTO_WIDTH)
581 size=DoGetBestSize();
587 if((height==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
589 if(sizeFlags&wxSIZE_AUTO_HEIGHT)
592 size=DoGetBestSize();
598 DoMoveWindow(x,y,width,height);
601 void wxWindowCocoa::DoMoveWindow(int x, int y, int width, int height)
603 wxAutoNSAutoreleasePool pool;
604 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoMoveWindow(%d,%d,%d,%d)"),this,x,y,width,height);
606 NSView *nsview = GetNSViewForSuperview();
607 NSView *superview = [nsview superview];
608 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
609 NSRect parentRect = [superview bounds];
611 NSRect cocoaRect = NSMakeRect(x,parentRect.size.height-(y+height),width,height);
612 [nsview setFrame: cocoaRect];
613 // Be sure to redraw the parent to reflect the changed position
614 [superview setNeedsDisplay:YES];
617 void wxWindowCocoa::SetInitialFrameRect(const wxPoint& pos, const wxSize& size)
619 NSView *nsview = GetNSViewForSuperview();
620 NSView *superview = [nsview superview];
621 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
622 NSRect parentRect = [superview bounds];
623 NSRect frameRect = [nsview frame];
625 frameRect.size.width = size.x;
627 frameRect.size.height = size.y;
628 frameRect.origin.x = pos.x;
629 frameRect.origin.y = parentRect.size.height-(pos.y+frameRect.size.height);
630 // Tell Cocoa to change the margin between the bottom of the superview
631 // and the bottom of the control. Keeps the control pinned to the top
632 // of its superview so that its position in the wxWidgets coordinate
633 // system doesn't change.
634 if(![superview isFlipped])
635 [nsview setAutoresizingMask: NSViewMinYMargin];
636 // MUST set the mask before setFrame: which can generate a size event
637 // and cause a scroller to be added!
638 [nsview setFrame: frameRect];
642 void wxWindow::DoGetSize(int *w, int *h) const
644 NSRect cocoaRect = [GetNSViewForSuperview() frame];
646 *w=(int)cocoaRect.size.width;
648 *h=(int)cocoaRect.size.height;
649 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoGetSize = (%d,%d)"),this,(int)cocoaRect.size.width,(int)cocoaRect.size.height);
652 void wxWindow::DoGetPosition(int *x, int *y) const
654 NSView *nsview = GetNSViewForSuperview();
655 NSView *superview = [nsview superview];
656 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
657 NSRect parentRect = [superview bounds];
659 NSRect cocoaRect = [nsview frame];
661 *x=(int)cocoaRect.origin.x;
663 *y=(int)(parentRect.size.height-(cocoaRect.origin.y+cocoaRect.size.height));
664 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoGetPosition = (%d,%d)"),this,(int)cocoaRect.origin.x,(int)cocoaRect.origin.y);
667 WXWidget wxWindow::GetHandle() const
669 return m_cocoaNSView;
672 void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
674 [m_cocoaNSView setNeedsDisplay:YES];
677 void wxWindow::SetFocus()
682 void wxWindow::DoCaptureMouse()
685 sm_capturedWindow = this;
688 void wxWindow::DoReleaseMouse()
691 sm_capturedWindow = NULL;
694 void wxWindow::DoScreenToClient(int *x, int *y) const
699 void wxWindow::DoClientToScreen(int *x, int *y) const
704 // Get size *available for subwindows* i.e. excluding menu bar etc.
705 void wxWindow::DoGetClientSize(int *x, int *y) const
707 wxLogTrace(wxTRACE_COCOA,wxT("DoGetClientSize:"));
709 m_cocoaScroller->DoGetClientSize(x,y);
711 wxWindowCocoa::DoGetSize(x,y);
714 void wxWindow::DoSetClientSize(int width, int height)
716 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("DoSetClientSize=(%d,%d)"),width,height);
718 m_cocoaScroller->ClientSizeToSize(width,height);
719 CocoaSetWxWindowSize(width,height);
722 void wxWindow::CocoaSetWxWindowSize(int width, int height)
724 wxWindowCocoa::DoSetSize(-1,-1,width,height,wxSIZE_USE_EXISTING);
727 int wxWindow::GetCharHeight() const
733 int wxWindow::GetCharWidth() const
739 void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
740 int *descent, int *externalLeading, const wxFont *theFont) const
745 // Coordinates relative to the window
746 void wxWindow::WarpPointer (int x_pos, int y_pos)
751 int wxWindow::GetScrollPos(int orient) const
757 // This now returns the whole range, not just the number
758 // of positions that we can scroll.
759 int wxWindow::GetScrollRange(int orient) const
765 int wxWindow::GetScrollThumb(int orient) const
771 void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
776 void wxWindow::CocoaCreateNSScrollView()
780 m_cocoaScroller = new wxWindowCocoaScroller(this);
784 // New function that will replace some of the above.
785 void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
786 int range, bool refresh)
788 CocoaCreateNSScrollView();
792 // Does a physical scroll
793 void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
798 void wxWindow::DoSetVirtualSize( int x, int y )
800 wxWindowBase::DoSetVirtualSize(x,y);
801 CocoaCreateNSScrollView();
802 [m_cocoaNSView setFrameSize:NSMakeSize(m_virtualSize.x,m_virtualSize.y)];
805 bool wxWindow::SetFont(const wxFont& font)
811 static int CocoaRaiseWindowCompareFunction(id first, id second, void *target)
813 // first should be ordered higher
815 return NSOrderedDescending;
816 // second should be ordered higher
818 return NSOrderedAscending;
819 return NSOrderedSame;
822 // Raise the window to the top of the Z order
823 void wxWindow::Raise()
825 // wxAutoNSAutoreleasePool pool;
826 NSView *nsview = GetNSViewForSuperview();
827 [[nsview superview] sortSubviewsUsingFunction:
828 CocoaRaiseWindowCompareFunction
832 static int CocoaLowerWindowCompareFunction(id first, id second, void *target)
834 // first should be ordered lower
836 return NSOrderedAscending;
837 // second should be ordered lower
839 return NSOrderedDescending;
840 return NSOrderedSame;
843 // Lower the window to the bottom of the Z order
844 void wxWindow::Lower()
846 NSView *nsview = GetNSViewForSuperview();
847 [[nsview superview] sortSubviewsUsingFunction:
848 CocoaLowerWindowCompareFunction
852 bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
857 // Get the window with the focus
858 wxWindow *wxWindowBase::FindFocus()
864 /* static */ wxWindow *wxWindowBase::GetCapture()
867 return wxWindowCocoa::sm_capturedWindow;
870 wxWindow *wxGetActiveWindow()
876 wxPoint wxGetMousePosition()
879 return wxDefaultPosition;
882 wxWindow* wxFindWindowAtPointer(wxPoint& pt)
884 pt = wxGetMousePosition();