1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/cocoa/window.mm
3 // Purpose: wxWindowCocoa
4 // Author: David Elliott
8 // Copyright: (c) 2002 David Elliott
9 // Licence: wxWindows license
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>
26 // Turn this on to paint green over the dummy views for debugging
27 #undef WXCOCOA_FILL_DUMMY_VIEW
29 #ifdef WXCOCOA_FILL_DUMMY_VIEW
30 #import <AppKit/NSBezierPath.h>
31 #endif //def WXCOCOA_FILL_DUMMY_VIEW
33 // ========================================================================
35 // ========================================================================
36 class wxWindowCocoaHider: protected wxCocoaNSView
38 DECLARE_NO_COPY_CLASS(wxWindowCocoaHider)
40 wxWindowCocoaHider(wxWindow *owner);
41 virtual ~wxWindowCocoaHider();
42 inline WX_NSView GetNSView() { return m_dummyNSView; }
44 wxWindowCocoa *m_owner;
45 WX_NSView m_dummyNSView;
46 virtual void Cocoa_FrameChanged(void);
47 #ifdef WXCOCOA_FILL_DUMMY_VIEW
48 virtual bool Cocoa_drawRect(const NSRect& rect);
49 #endif //def WXCOCOA_FILL_DUMMY_VIEW
54 // ========================================================================
55 // wxWindowCocoaScroller
56 // ========================================================================
57 class wxWindowCocoaScroller: protected wxCocoaNSView
59 DECLARE_NO_COPY_CLASS(wxWindowCocoaScroller)
61 wxWindowCocoaScroller(wxWindow *owner);
62 virtual ~wxWindowCocoaScroller();
63 inline WX_NSScrollView GetNSScrollView() { return m_cocoaNSScrollView; }
64 void ClientSizeToSize(int &width, int &height);
65 void DoGetClientSize(int *x, int *y) const;
69 wxWindowCocoa *m_owner;
70 WX_NSScrollView m_cocoaNSScrollView;
71 virtual void Cocoa_FrameChanged(void);
73 wxWindowCocoaScroller();
76 // ========================================================================
78 // ========================================================================
79 @interface wxDummyNSView : NSView
80 - (NSView *)hitTest:(NSPoint)aPoint;
83 @implementation wxDummyNSView : NSView
84 - (NSView *)hitTest:(NSPoint)aPoint
91 // ========================================================================
93 // ========================================================================
94 wxWindowCocoaHider::wxWindowCocoaHider(wxWindow *owner)
98 wxASSERT(owner->GetNSViewForHiding());
99 m_dummyNSView = [[wxDummyNSView alloc]
100 initWithFrame:[owner->GetNSViewForHiding() frame]];
101 [m_dummyNSView setAutoresizingMask: [owner->GetNSViewForHiding() autoresizingMask]];
102 AssociateNSView(m_dummyNSView);
105 wxWindowCocoaHider::~wxWindowCocoaHider()
107 DisassociateNSView(m_dummyNSView);
108 [m_dummyNSView release];
111 void wxWindowCocoaHider::Cocoa_FrameChanged(void)
113 // Keep the real window in synch with the dummy
114 wxASSERT(m_dummyNSView);
115 [m_owner->GetNSViewForHiding() setFrame:[m_dummyNSView frame]];
118 #ifdef WXCOCOA_FILL_DUMMY_VIEW
119 bool wxWindowCocoaHider::Cocoa_drawRect(const NSRect& rect)
121 NSBezierPath *bezpath = [NSBezierPath bezierPathWithRect:rect];
122 [[NSColor greenColor] set];
127 #endif //def WXCOCOA_FILL_DUMMY_VIEW
129 // ========================================================================
130 // wxFlippedNSClipView
131 // ========================================================================
132 @interface wxFlippedNSClipView : NSClipView
136 @implementation wxFlippedNSClipView : NSClipView
144 // ========================================================================
145 // wxWindowCocoaScroller
146 // ========================================================================
147 wxWindowCocoaScroller::wxWindowCocoaScroller(wxWindow *owner)
150 wxAutoNSAutoreleasePool pool;
152 wxASSERT(owner->GetNSView());
153 m_cocoaNSScrollView = [[NSScrollView alloc]
154 initWithFrame:[owner->GetNSView() frame]];
155 AssociateNSView(m_cocoaNSScrollView);
157 /* Replace the default NSClipView with a flipped one. This ensures
158 scrolling is "pinned" to the top-left instead of bottom-right. */
159 NSClipView *flippedClip = [[wxFlippedNSClipView alloc]
160 initWithFrame: [[m_cocoaNSScrollView contentView] frame]];
161 [m_cocoaNSScrollView setContentView:flippedClip];
162 [flippedClip release];
164 [m_cocoaNSScrollView setBackgroundColor: [NSColor windowBackgroundColor]];
165 [m_cocoaNSScrollView setHasHorizontalScroller: YES];
166 [m_cocoaNSScrollView setHasVerticalScroller: YES];
170 void wxWindowCocoaScroller::Encapsulate()
172 // Set the scroll view autoresizingMask to match the current NSView
173 [m_cocoaNSScrollView setAutoresizingMask: [m_owner->GetNSView() autoresizingMask]];
174 [m_owner->GetNSView() setAutoresizingMask: NSViewNotSizable];
175 // NOTE: replaceSubView will cause m_cocaNSView to be released
176 // except when it hasn't been added into an NSView hierarchy in which
177 // case it doesn't need to be and this should work out to a no-op
178 m_owner->CocoaReplaceView(m_owner->GetNSView(), m_cocoaNSScrollView);
179 // The NSView is still retained by owner
180 [m_cocoaNSScrollView setDocumentView: m_owner->GetNSView()];
181 // Now it's also retained by the NSScrollView
184 void wxWindowCocoaScroller::Unencapsulate()
186 [m_cocoaNSScrollView setDocumentView: nil];
187 m_owner->CocoaReplaceView(m_cocoaNSScrollView, m_owner->GetNSView());
188 if(![[m_owner->GetNSView() superview] isFlipped])
189 [m_owner->GetNSView() setAutoresizingMask: NSViewMinYMargin];
192 wxWindowCocoaScroller::~wxWindowCocoaScroller()
194 DisassociateNSView(m_cocoaNSScrollView);
195 [m_cocoaNSScrollView release];
198 void wxWindowCocoaScroller::ClientSizeToSize(int &width, int &height)
200 NSSize frameSize = [NSScrollView
201 frameSizeForContentSize: NSMakeSize(width,height)
202 hasHorizontalScroller: [m_cocoaNSScrollView hasHorizontalScroller]
203 hasVerticalScroller: [m_cocoaNSScrollView hasVerticalScroller]
204 borderType: [m_cocoaNSScrollView borderType]];
205 width = (int)frameSize.width;
206 height = (int)frameSize.height;
209 void wxWindowCocoaScroller::DoGetClientSize(int *x, int *y) const
211 NSSize nssize = [m_cocoaNSScrollView contentSize];
213 *x = (int)nssize.width;
215 *y = (int)nssize.height;
218 void wxWindowCocoaScroller::Cocoa_FrameChanged(void)
220 wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_FrameChanged"));
221 wxSizeEvent event(m_owner->GetSize(), m_owner->GetId());
222 event.SetEventObject(m_owner);
223 m_owner->GetEventHandler()->ProcessEvent(event);
226 // ========================================================================
228 // ========================================================================
229 // normally the base classes aren't included, but wxWindow is special
230 #ifdef __WXUNIVERSAL__
231 IMPLEMENT_ABSTRACT_CLASS(wxWindowCocoa, wxWindowBase)
233 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
236 BEGIN_EVENT_TABLE(wxWindowCocoa, wxWindowBase)
239 wxWindow *wxWindowCocoa::sm_capturedWindow = NULL;
242 void wxWindowCocoa::Init()
244 m_cocoaNSView = NULL;
246 m_cocoaScroller = NULL;
247 m_isBeingDeleted = FALSE;
249 m_shouldBeEnabled = true;
253 bool wxWindow::Create(wxWindow *parent, wxWindowID winid,
257 const wxString& name)
259 if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name))
262 // TODO: create the window
263 m_cocoaNSView = NULL;
264 SetNSView([[NSView alloc] initWithFrame: MakeDefaultNSRect(size)]);
265 [m_cocoaNSView release];
269 m_parent->AddChild(this);
270 m_parent->CocoaAddChild(this);
271 SetInitialFrameRect(pos,size);
278 wxWindow::~wxWindow()
280 wxAutoNSAutoreleasePool pool;
283 // Make sure our parent (in the wxWindows sense) is our superview
284 // before we go removing from it.
285 if(m_parent && m_parent->GetNSView()==[GetNSViewForSuperview() superview])
286 CocoaRemoveFromParent();
288 delete m_cocoaScroller;
292 void wxWindowCocoa::CocoaAddChild(wxWindowCocoa *child)
294 NSView *childView = child->GetNSViewForSuperview();
297 [m_cocoaNSView addSubview: childView];
298 child->m_isShown = !m_cocoaHider;
301 void wxWindowCocoa::CocoaRemoveFromParent(void)
303 [GetNSViewForSuperview() removeFromSuperview];
306 void wxWindowCocoa::SetNSView(WX_NSView cocoaNSView)
308 // Assume setting the NSView to NULL means this wxWindow is being destroyed
309 if(m_cocoaNSView && !cocoaNSView)
312 bool need_debug = cocoaNSView || m_cocoaNSView;
313 if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxWindowCocoa=%p::SetNSView [m_cocoaNSView=%p retainCount]=%d"),this,m_cocoaNSView,[m_cocoaNSView retainCount]);
314 DisassociateNSView(m_cocoaNSView);
315 [cocoaNSView retain];
316 [m_cocoaNSView release];
317 m_cocoaNSView = cocoaNSView;
318 AssociateNSView(m_cocoaNSView);
319 if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxWindowCocoa=%p::SetNSView [cocoaNSView=%p retainCount]=%d"),this,cocoaNSView,[cocoaNSView retainCount]);
322 WX_NSView wxWindowCocoa::GetNSViewForSuperview() const
325 ? m_cocoaHider->GetNSView()
327 ? m_cocoaScroller->GetNSScrollView()
331 WX_NSView wxWindowCocoa::GetNSViewForHiding() const
333 return m_cocoaScroller
334 ? m_cocoaScroller->GetNSScrollView()
338 bool wxWindowCocoa::Cocoa_drawRect(const NSRect &rect)
340 wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_drawRect"));
341 // Recursion can happen if the event loop runs from within the paint
342 // handler. For instance, if an assertion dialog is shown.
343 // FIXME: This seems less than ideal.
346 wxLogDebug(wxT("Paint event recursion!"));
349 //FIXME: should probably turn that rect into the update region
351 wxPaintEvent event(m_windowId);
352 event.SetEventObject(this);
353 bool ret = GetEventHandler()->ProcessEvent(event);
358 void wxWindowCocoa::InitMouseEvent(wxMouseEvent& event, WX_NSEvent cocoaEvent)
360 wxASSERT_MSG([m_cocoaNSView window]==[cocoaEvent window],wxT("Mouse event for different NSWindow"));
361 NSPoint cocoaPoint = [m_cocoaNSView convertPoint:[(NSEvent*)cocoaEvent locationInWindow] fromView:nil];
362 NSRect cocoaRect = [m_cocoaNSView frame];
363 const wxPoint &clientorigin = GetClientAreaOrigin();
364 event.m_x = (wxCoord)cocoaPoint.x - clientorigin.x;
365 event.m_y = (wxCoord)(cocoaRect.size.height - cocoaPoint.y) - clientorigin.y;
367 event.m_shiftDown = [cocoaEvent modifierFlags] & NSShiftKeyMask;
368 event.m_controlDown = [cocoaEvent modifierFlags] & NSControlKeyMask;
369 event.m_altDown = [cocoaEvent modifierFlags] & NSAlternateKeyMask;
370 event.m_metaDown = [cocoaEvent modifierFlags] & NSCommandKeyMask;
372 // TODO: set timestamp?
373 event.SetEventObject(this);
374 event.SetId(GetId());
377 bool wxWindowCocoa::Cocoa_mouseMoved(WX_NSEvent theEvent)
379 wxMouseEvent event(wxEVT_MOTION);
380 InitMouseEvent(event,theEvent);
381 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y);
382 return GetEventHandler()->ProcessEvent(event);
385 bool wxWindowCocoa::Cocoa_mouseEntered(WX_NSEvent theEvent)
390 bool wxWindowCocoa::Cocoa_mouseExited(WX_NSEvent theEvent)
395 bool wxWindowCocoa::Cocoa_mouseDown(WX_NSEvent theEvent)
397 wxMouseEvent event([theEvent clickCount]<2?wxEVT_LEFT_DOWN:wxEVT_LEFT_DCLICK);
398 InitMouseEvent(event,theEvent);
399 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Down @%d,%d num clicks=%d"),event.m_x,event.m_y,[theEvent clickCount]);
400 return GetEventHandler()->ProcessEvent(event);
403 bool wxWindowCocoa::Cocoa_mouseDragged(WX_NSEvent theEvent)
405 wxMouseEvent event(wxEVT_MOTION);
406 InitMouseEvent(event,theEvent);
407 event.m_leftDown = true;
408 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y);
409 return GetEventHandler()->ProcessEvent(event);
412 bool wxWindowCocoa::Cocoa_mouseUp(WX_NSEvent theEvent)
414 wxMouseEvent event(wxEVT_LEFT_UP);
415 InitMouseEvent(event,theEvent);
416 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Up @%d,%d"),event.m_x,event.m_y);
417 return GetEventHandler()->ProcessEvent(event);
420 bool wxWindowCocoa::Cocoa_rightMouseDown(WX_NSEvent theEvent)
422 wxMouseEvent event([theEvent clickCount]<2?wxEVT_RIGHT_DOWN:wxEVT_RIGHT_DCLICK);
423 InitMouseEvent(event,theEvent);
424 wxLogDebug(wxT("Mouse Down @%d,%d num clicks=%d"),event.m_x,event.m_y,[theEvent clickCount]);
425 return GetEventHandler()->ProcessEvent(event);
428 bool wxWindowCocoa::Cocoa_rightMouseDragged(WX_NSEvent theEvent)
430 wxMouseEvent event(wxEVT_MOTION);
431 InitMouseEvent(event,theEvent);
432 event.m_rightDown = true;
433 wxLogDebug(wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y);
434 return GetEventHandler()->ProcessEvent(event);
437 bool wxWindowCocoa::Cocoa_rightMouseUp(WX_NSEvent theEvent)
439 wxMouseEvent event(wxEVT_RIGHT_UP);
440 InitMouseEvent(event,theEvent);
441 wxLogDebug(wxT("Mouse Up @%d,%d"),event.m_x,event.m_y);
442 return GetEventHandler()->ProcessEvent(event);
445 bool wxWindowCocoa::Cocoa_otherMouseDown(WX_NSEvent theEvent)
450 bool wxWindowCocoa::Cocoa_otherMouseDragged(WX_NSEvent theEvent)
455 bool wxWindowCocoa::Cocoa_otherMouseUp(WX_NSEvent theEvent)
460 void wxWindowCocoa::Cocoa_FrameChanged(void)
462 wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_FrameChanged"));
463 wxSizeEvent event(GetSize(), m_windowId);
464 event.SetEventObject(this);
465 GetEventHandler()->ProcessEvent(event);
468 bool wxWindow::Close(bool force)
470 // The only reason this function exists is that it is virtual and
471 // wxTopLevelWindowCocoa will override it.
472 return wxWindowBase::Close(force);
475 void wxWindow::CocoaReplaceView(WX_NSView oldView, WX_NSView newView)
477 [[oldView superview] replaceSubview:oldView with:newView];
480 bool wxWindow::EnableSelfAndChildren(bool enable)
482 // If the state isn't changing, don't do anything
483 if(!wxWindowBase::Enable(enable && m_shouldBeEnabled))
485 // Set the state of the Cocoa window
486 CocoaSetEnabled(m_isEnabled);
487 // Disable all children or (if enabling) return them to their proper state
488 for(wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
489 node; node = node->GetNext())
491 node->GetData()->EnableSelfAndChildren(enable);
496 bool wxWindow::Enable(bool enable)
498 // Keep track of what the window SHOULD be doing
499 m_shouldBeEnabled = enable;
500 // If the parent is disabled for any reason, then this window will be too.
501 if(!IsTopLevel() && GetParent())
503 enable = enable && GetParent()->IsEnabled();
505 return EnableSelfAndChildren(enable);
508 bool wxWindow::Show(bool show)
510 wxAutoNSAutoreleasePool pool;
511 // If the window is marked as visible, then it shouldn't have a dummy view
512 // If the window is marked hidden, then it should have a dummy view
513 // wxSpinCtrl (generic) abuses m_isShown, don't use it for any logic
514 // wxASSERT_MSG( (m_isShown && !m_dummyNSView) || (!m_isShown && m_dummyNSView),wxT("wxWindow: m_isShown does not agree with m_dummyNSView"));
515 // Return false if there isn't a window to show or hide
516 NSView *cocoaView = GetNSViewForHiding();
521 // If state isn't changing, return false
524 CocoaReplaceView(m_cocoaHider->GetNSView(), cocoaView);
525 wxASSERT(![m_cocoaHider->GetNSView() superview]);
528 wxASSERT([cocoaView superview]);
532 // If state isn't changing, return false
535 m_cocoaHider = new wxWindowCocoaHider(this);
536 // NOTE: replaceSubview:with will cause m_cocaNSView to be
537 // (auto)released which balances out addSubview
538 CocoaReplaceView(cocoaView, m_cocoaHider->GetNSView());
539 // m_coocaNSView is now only retained by us
540 wxASSERT([m_cocoaHider->GetNSView() superview]);
541 wxASSERT(![cocoaView superview]);
547 void wxWindowCocoa::DoSetSize(int x, int y, int width, int height, int sizeFlags)
549 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":".");
550 int currentX, currentY;
551 int currentW, currentH;
552 DoGetPosition(¤tX, ¤tY);
553 DoGetSize(¤tW, ¤tH);
554 if((x==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
556 if((y==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
559 AdjustForParentClientOrigin(x,y,sizeFlags);
563 if((width==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
565 if(sizeFlags&wxSIZE_AUTO_WIDTH)
567 size=DoGetBestSize();
573 if((height==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
575 if(sizeFlags&wxSIZE_AUTO_HEIGHT)
578 size=DoGetBestSize();
584 DoMoveWindow(x,y,width,height);
587 void wxWindowCocoa::DoMoveWindow(int x, int y, int width, int height)
589 wxAutoNSAutoreleasePool pool;
590 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoMoveWindow(%d,%d,%d,%d)"),this,x,y,width,height);
592 NSView *nsview = GetNSViewForSuperview();
593 NSView *superview = [nsview superview];
594 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
595 NSRect parentRect = [superview bounds];
597 NSRect cocoaRect = NSMakeRect(x,parentRect.size.height-(y+height),width,height);
598 [nsview setFrame: cocoaRect];
599 // Be sure to redraw the parent to reflect the changed position
600 [superview setNeedsDisplay:YES];
603 void wxWindowCocoa::SetInitialFrameRect(const wxPoint& pos, const wxSize& size)
605 NSView *nsview = GetNSViewForSuperview();
606 NSView *superview = [nsview superview];
607 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
608 NSRect parentRect = [superview bounds];
609 NSRect frameRect = [nsview frame];
611 frameRect.size.width = size.x;
613 frameRect.size.height = size.y;
614 frameRect.origin.x = pos.x;
615 frameRect.origin.y = parentRect.size.height-(pos.y+frameRect.size.height);
616 // Tell Cocoa to change the margin between the bottom of the superview
617 // and the bottom of the control. Keeps the control pinned to the top
618 // of its superview so that its position in the wxWindows coordinate
619 // system doesn't change.
620 if(![superview isFlipped])
621 [nsview setAutoresizingMask: NSViewMinYMargin];
622 // MUST set the mask before setFrame: which can generate a size event
623 // and cause a scroller to be added!
624 [nsview setFrame: frameRect];
628 void wxWindow::DoGetSize(int *w, int *h) const
630 NSRect cocoaRect = [GetNSViewForSuperview() frame];
632 *w=(int)cocoaRect.size.width;
634 *h=(int)cocoaRect.size.height;
635 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoGetSize = (%d,%d)"),this,(int)cocoaRect.size.width,(int)cocoaRect.size.height);
638 void wxWindow::DoGetPosition(int *x, int *y) const
640 NSView *nsview = GetNSViewForSuperview();
641 NSView *superview = [nsview superview];
642 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
643 NSRect parentRect = [superview bounds];
645 NSRect cocoaRect = [nsview frame];
647 *x=(int)cocoaRect.origin.x;
649 *y=(int)(parentRect.size.height-(cocoaRect.origin.y+cocoaRect.size.height));
650 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxWindow=%p::DoGetPosition = (%d,%d)"),this,(int)cocoaRect.origin.x,(int)cocoaRect.origin.y);
653 WXWidget wxWindow::GetHandle() const
655 return m_cocoaNSView;
658 void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
660 [m_cocoaNSView setNeedsDisplay:YES];
663 void wxWindow::SetFocus()
668 void wxWindow::DoCaptureMouse()
671 sm_capturedWindow = this;
674 void wxWindow::DoReleaseMouse()
677 sm_capturedWindow = NULL;
680 void wxWindow::DoScreenToClient(int *x, int *y) const
685 void wxWindow::DoClientToScreen(int *x, int *y) const
690 // Get size *available for subwindows* i.e. excluding menu bar etc.
691 void wxWindow::DoGetClientSize(int *x, int *y) const
693 wxLogTrace(wxTRACE_COCOA,wxT("DoGetClientSize:"));
695 m_cocoaScroller->DoGetClientSize(x,y);
697 wxWindowCocoa::DoGetSize(x,y);
700 void wxWindow::DoSetClientSize(int width, int height)
702 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("DoSetClientSize=(%d,%d)"),width,height);
704 m_cocoaScroller->ClientSizeToSize(width,height);
705 CocoaSetWxWindowSize(width,height);
708 void wxWindow::CocoaSetWxWindowSize(int width, int height)
710 wxWindowCocoa::DoSetSize(-1,-1,width,height,wxSIZE_USE_EXISTING);
713 int wxWindow::GetCharHeight() const
719 int wxWindow::GetCharWidth() const
725 void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
726 int *descent, int *externalLeading, const wxFont *theFont) const
731 // Coordinates relative to the window
732 void wxWindow::WarpPointer (int x_pos, int y_pos)
737 int wxWindow::GetScrollPos(int orient) const
743 // This now returns the whole range, not just the number
744 // of positions that we can scroll.
745 int wxWindow::GetScrollRange(int orient) const
751 int wxWindow::GetScrollThumb(int orient) const
757 void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
762 void wxWindow::CocoaCreateNSScrollView()
766 m_cocoaScroller = new wxWindowCocoaScroller(this);
770 // New function that will replace some of the above.
771 void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
772 int range, bool refresh)
774 CocoaCreateNSScrollView();
778 // Does a physical scroll
779 void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
784 void wxWindow::DoSetVirtualSize( int x, int y )
786 wxWindowBase::DoSetVirtualSize(x,y);
787 CocoaCreateNSScrollView();
788 [m_cocoaNSView setFrameSize:NSMakeSize(m_virtualSize.x,m_virtualSize.y)];
791 bool wxWindow::SetFont(const wxFont& font)
797 static int CocoaRaiseWindowCompareFunction(id first, id second, void *target)
799 // first should be ordered higher
801 return NSOrderedDescending;
802 // second should be ordered higher
804 return NSOrderedAscending;
805 return NSOrderedSame;
808 // Raise the window to the top of the Z order
809 void wxWindow::Raise()
811 // wxAutoNSAutoreleasePool pool;
812 NSView *nsview = GetNSViewForSuperview();
813 [[nsview superview] sortSubviewsUsingFunction:
814 CocoaRaiseWindowCompareFunction
818 static int CocoaLowerWindowCompareFunction(id first, id second, void *target)
820 // first should be ordered lower
822 return NSOrderedAscending;
823 // second should be ordered lower
825 return NSOrderedDescending;
826 return NSOrderedSame;
829 // Lower the window to the bottom of the Z order
830 void wxWindow::Lower()
832 NSView *nsview = GetNSViewForSuperview();
833 [[nsview superview] sortSubviewsUsingFunction:
834 CocoaLowerWindowCompareFunction
838 bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
843 // Get the window with the focus
844 wxWindow *wxWindowBase::FindFocus()
850 /* static */ wxWindow *wxWindowBase::GetCapture()
853 return wxWindowCocoa::sm_capturedWindow;
856 wxWindow *wxGetActiveWindow()
862 wxPoint wxGetMousePosition()
865 return wxDefaultPosition;
868 wxWindow* wxFindWindowAtPointer(wxPoint& pt)
870 pt = wxGetMousePosition();