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)
151 wxASSERT(owner->GetNSView());
152 m_cocoaNSScrollView = [[NSScrollView alloc]
153 initWithFrame:[owner->GetNSView() frame]];
154 AssociateNSView(m_cocoaNSScrollView);
156 /* Replace the default NSClipView with a flipped one. This ensures
157 scrolling is "pinned" to the top-left instead of bottom-right. */
158 NSClipView *flippedClip = [[wxFlippedNSClipView alloc]
159 initWithFrame: [[m_cocoaNSScrollView contentView] frame]];
160 [m_cocoaNSScrollView setContentView:flippedClip];
161 [flippedClip release];
163 [m_cocoaNSScrollView setBackgroundColor: [NSColor windowBackgroundColor]];
164 [m_cocoaNSScrollView setHasHorizontalScroller: YES];
165 [m_cocoaNSScrollView setHasVerticalScroller: YES];
169 void wxWindowCocoaScroller::Encapsulate()
171 // Set the scroll view autoresizingMask to match the current NSView
172 [m_cocoaNSScrollView setAutoresizingMask: [m_owner->GetNSView() autoresizingMask]];
173 [m_owner->GetNSView() setAutoresizingMask: NSViewNotSizable];
174 // NOTE: replaceSubView will cause m_cocaNSView to be released
175 // except when it hasn't been added into an NSView hierarchy in which
176 // case it doesn't need to be and this should work out to a no-op
177 m_owner->CocoaReplaceView(m_owner->GetNSView(), m_cocoaNSScrollView);
178 // The NSView is still retained by owner
179 [m_cocoaNSScrollView setDocumentView: m_owner->GetNSView()];
180 // Now it's also retained by the NSScrollView
183 void wxWindowCocoaScroller::Unencapsulate()
185 [m_cocoaNSScrollView setDocumentView: nil];
186 m_owner->CocoaReplaceView(m_cocoaNSScrollView, m_owner->GetNSView());
187 if(![[m_owner->GetNSView() superview] isFlipped])
188 [m_owner->GetNSView() setAutoresizingMask: NSViewMinYMargin];
191 wxWindowCocoaScroller::~wxWindowCocoaScroller()
193 DisassociateNSView(m_cocoaNSScrollView);
194 [m_cocoaNSScrollView release];
197 void wxWindowCocoaScroller::ClientSizeToSize(int &width, int &height)
199 NSSize frameSize = [NSScrollView
200 frameSizeForContentSize: NSMakeSize(width,height)
201 hasHorizontalScroller: [m_cocoaNSScrollView hasHorizontalScroller]
202 hasVerticalScroller: [m_cocoaNSScrollView hasVerticalScroller]
203 borderType: [m_cocoaNSScrollView borderType]];
204 width = (int)frameSize.width;
205 height = (int)frameSize.height;
208 void wxWindowCocoaScroller::DoGetClientSize(int *x, int *y) const
210 NSSize nssize = [m_cocoaNSScrollView contentSize];
212 *x = (int)nssize.width;
214 *y = (int)nssize.height;
217 void wxWindowCocoaScroller::Cocoa_FrameChanged(void)
219 wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_FrameChanged"));
220 wxSizeEvent event(m_owner->GetSize(), m_owner->GetId());
221 event.SetEventObject(m_owner);
222 m_owner->GetEventHandler()->ProcessEvent(event);
225 // ========================================================================
227 // ========================================================================
228 // normally the base classes aren't included, but wxWindow is special
229 #ifdef __WXUNIVERSAL__
230 IMPLEMENT_ABSTRACT_CLASS(wxWindowCocoa, wxWindowBase)
232 IMPLEMENT_DYNAMIC_CLASS(wxWindow, wxWindowBase)
235 BEGIN_EVENT_TABLE(wxWindowCocoa, wxWindowBase)
238 wxWindow *wxWindowCocoa::sm_capturedWindow = NULL;
241 void wxWindowCocoa::Init()
243 m_cocoaNSView = NULL;
245 m_cocoaScroller = NULL;
246 m_isBeingDeleted = FALSE;
248 m_shouldBeEnabled = true;
252 bool wxWindow::Create(wxWindow *parent, wxWindowID winid,
256 const wxString& name)
258 if(!CreateBase(parent,winid,pos,size,style,wxDefaultValidator,name))
261 // TODO: create the window
262 m_cocoaNSView = NULL;
263 SetNSView([[NSView alloc] initWithFrame: MakeDefaultNSRect(size)]);
264 [m_cocoaNSView release];
268 m_parent->AddChild(this);
269 m_parent->CocoaAddChild(this);
270 SetInitialFrameRect(pos,size);
277 wxWindow::~wxWindow()
279 wxAutoNSAutoreleasePool pool;
282 // Make sure our parent (in the wxWindows sense) is our superview
283 // before we go removing from it.
284 if(m_parent && m_parent->GetNSView()==[GetNSViewForSuperview() superview])
285 CocoaRemoveFromParent();
287 delete m_cocoaScroller;
291 void wxWindowCocoa::CocoaAddChild(wxWindowCocoa *child)
293 NSView *childView = child->GetNSViewForSuperview();
296 [m_cocoaNSView addSubview: childView];
297 child->m_isShown = !m_cocoaHider;
300 void wxWindowCocoa::CocoaRemoveFromParent(void)
302 [GetNSViewForSuperview() removeFromSuperview];
305 void wxWindowCocoa::SetNSView(WX_NSView cocoaNSView)
307 // Assume setting the NSView to NULL means this wxWindow is being destroyed
308 if(m_cocoaNSView && !cocoaNSView)
311 bool need_debug = cocoaNSView || m_cocoaNSView;
312 if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxWindowCocoa=%p::SetNSView [m_cocoaNSView=%p retainCount]=%d"),this,m_cocoaNSView,[m_cocoaNSView retainCount]);
313 DisassociateNSView(m_cocoaNSView);
314 [cocoaNSView retain];
315 [m_cocoaNSView release];
316 m_cocoaNSView = cocoaNSView;
317 AssociateNSView(m_cocoaNSView);
318 if(need_debug) wxLogTrace(wxTRACE_COCOA_RetainRelease,wxT("wxWindowCocoa=%p::SetNSView [cocoaNSView=%p retainCount]=%d"),this,cocoaNSView,[cocoaNSView retainCount]);
321 WX_NSView wxWindowCocoa::GetNSViewForSuperview() const
324 ? m_cocoaHider->GetNSView()
326 ? m_cocoaScroller->GetNSScrollView()
330 WX_NSView wxWindowCocoa::GetNSViewForHiding() const
332 return m_cocoaScroller
333 ? m_cocoaScroller->GetNSScrollView()
337 bool wxWindowCocoa::Cocoa_drawRect(const NSRect &rect)
339 wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_drawRect"));
340 // Recursion can happen if the event loop runs from within the paint
341 // handler. For instance, if an assertion dialog is shown.
342 // FIXME: This seems less than ideal.
345 wxLogDebug(wxT("Paint event recursion!"));
348 //FIXME: should probably turn that rect into the update region
350 wxPaintEvent event(m_windowId);
351 event.SetEventObject(this);
352 bool ret = GetEventHandler()->ProcessEvent(event);
357 void wxWindowCocoa::InitMouseEvent(wxMouseEvent& event, WX_NSEvent cocoaEvent)
359 wxASSERT_MSG([m_cocoaNSView window]==[cocoaEvent window],wxT("Mouse event for different NSWindow"));
360 NSPoint cocoaPoint = [m_cocoaNSView convertPoint:[(NSEvent*)cocoaEvent locationInWindow] fromView:nil];
361 NSRect cocoaRect = [m_cocoaNSView frame];
362 const wxPoint &clientorigin = GetClientAreaOrigin();
363 event.m_x = (wxCoord)cocoaPoint.x - clientorigin.x;
364 event.m_y = (wxCoord)(cocoaRect.size.height - cocoaPoint.y) - clientorigin.y;
366 event.m_shiftDown = [cocoaEvent modifierFlags] & NSShiftKeyMask;
367 event.m_controlDown = [cocoaEvent modifierFlags] & NSControlKeyMask;
368 event.m_altDown = [cocoaEvent modifierFlags] & NSAlternateKeyMask;
369 event.m_metaDown = [cocoaEvent modifierFlags] & NSCommandKeyMask;
371 // TODO: set timestamp?
372 event.SetEventObject(this);
373 event.SetId(GetId());
376 bool wxWindowCocoa::Cocoa_mouseMoved(WX_NSEvent theEvent)
378 wxMouseEvent event(wxEVT_MOTION);
379 InitMouseEvent(event,theEvent);
380 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y);
381 return GetEventHandler()->ProcessEvent(event);
384 bool wxWindowCocoa::Cocoa_mouseEntered(WX_NSEvent theEvent)
389 bool wxWindowCocoa::Cocoa_mouseExited(WX_NSEvent theEvent)
394 bool wxWindowCocoa::Cocoa_mouseDown(WX_NSEvent theEvent)
396 wxMouseEvent event([theEvent clickCount]<2?wxEVT_LEFT_DOWN:wxEVT_LEFT_DCLICK);
397 InitMouseEvent(event,theEvent);
398 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Down @%d,%d num clicks=%d"),event.m_x,event.m_y,[theEvent clickCount]);
399 return GetEventHandler()->ProcessEvent(event);
402 bool wxWindowCocoa::Cocoa_mouseDragged(WX_NSEvent theEvent)
404 wxMouseEvent event(wxEVT_MOTION);
405 InitMouseEvent(event,theEvent);
406 event.m_leftDown = true;
407 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y);
408 return GetEventHandler()->ProcessEvent(event);
411 bool wxWindowCocoa::Cocoa_mouseUp(WX_NSEvent theEvent)
413 wxMouseEvent event(wxEVT_LEFT_UP);
414 InitMouseEvent(event,theEvent);
415 wxLogTrace(wxTRACE_COCOA,wxT("Mouse Up @%d,%d"),event.m_x,event.m_y);
416 return GetEventHandler()->ProcessEvent(event);
419 bool wxWindowCocoa::Cocoa_rightMouseDown(WX_NSEvent theEvent)
421 wxMouseEvent event([theEvent clickCount]<2?wxEVT_RIGHT_DOWN:wxEVT_RIGHT_DCLICK);
422 InitMouseEvent(event,theEvent);
423 wxLogDebug(wxT("Mouse Down @%d,%d num clicks=%d"),event.m_x,event.m_y,[theEvent clickCount]);
424 return GetEventHandler()->ProcessEvent(event);
427 bool wxWindowCocoa::Cocoa_rightMouseDragged(WX_NSEvent theEvent)
429 wxMouseEvent event(wxEVT_MOTION);
430 InitMouseEvent(event,theEvent);
431 event.m_rightDown = true;
432 wxLogDebug(wxT("Mouse Drag @%d,%d"),event.m_x,event.m_y);
433 return GetEventHandler()->ProcessEvent(event);
436 bool wxWindowCocoa::Cocoa_rightMouseUp(WX_NSEvent theEvent)
438 wxMouseEvent event(wxEVT_RIGHT_UP);
439 InitMouseEvent(event,theEvent);
440 wxLogDebug(wxT("Mouse Up @%d,%d"),event.m_x,event.m_y);
441 return GetEventHandler()->ProcessEvent(event);
444 bool wxWindowCocoa::Cocoa_otherMouseDown(WX_NSEvent theEvent)
449 bool wxWindowCocoa::Cocoa_otherMouseDragged(WX_NSEvent theEvent)
454 bool wxWindowCocoa::Cocoa_otherMouseUp(WX_NSEvent theEvent)
459 void wxWindowCocoa::Cocoa_FrameChanged(void)
461 wxLogTrace(wxTRACE_COCOA,wxT("Cocoa_FrameChanged"));
462 wxSizeEvent event(GetSize(), m_windowId);
463 event.SetEventObject(this);
464 GetEventHandler()->ProcessEvent(event);
467 bool wxWindow::Close(bool force)
469 // The only reason this function exists is that it is virtual and
470 // wxTopLevelWindowCocoa will override it.
471 return wxWindowBase::Close(force);
474 void wxWindow::CocoaReplaceView(WX_NSView oldView, WX_NSView newView)
476 [[oldView superview] replaceSubview:oldView with:newView];
479 bool wxWindow::EnableSelfAndChildren(bool enable)
481 // If the state isn't changing, don't do anything
482 if(!wxWindowBase::Enable(enable && m_shouldBeEnabled))
484 // Set the state of the Cocoa window
485 CocoaSetEnabled(m_isEnabled);
486 // Disable all children or (if enabling) return them to their proper state
487 for(wxWindowList::compatibility_iterator node = GetChildren().GetFirst();
488 node; node = node->GetNext())
490 node->GetData()->EnableSelfAndChildren(enable);
495 bool wxWindow::Enable(bool enable)
497 // Keep track of what the window SHOULD be doing
498 m_shouldBeEnabled = enable;
499 // If the parent is disabled for any reason, then this window will be too.
500 if(!IsTopLevel() && GetParent())
502 enable = enable && GetParent()->IsEnabled();
504 return EnableSelfAndChildren(enable);
507 bool wxWindow::Show(bool show)
509 wxAutoNSAutoreleasePool pool;
510 // If the window is marked as visible, then it shouldn't have a dummy view
511 // If the window is marked hidden, then it should have a dummy view
512 // wxSpinCtrl (generic) abuses m_isShown, don't use it for any logic
513 // wxASSERT_MSG( (m_isShown && !m_dummyNSView) || (!m_isShown && m_dummyNSView),wxT("wxWindow: m_isShown does not agree with m_dummyNSView"));
514 // Return false if there isn't a window to show or hide
515 NSView *cocoaView = GetNSViewForHiding();
520 // If state isn't changing, return false
523 CocoaReplaceView(m_cocoaHider->GetNSView(), cocoaView);
524 wxASSERT(![m_cocoaHider->GetNSView() superview]);
527 wxASSERT([cocoaView superview]);
531 // If state isn't changing, return false
534 m_cocoaHider = new wxWindowCocoaHider(this);
535 // NOTE: replaceSubview:with will cause m_cocaNSView to be
536 // (auto)released which balances out addSubview
537 CocoaReplaceView(cocoaView, m_cocoaHider->GetNSView());
538 // m_coocaNSView is now only retained by us
539 wxASSERT([m_cocoaHider->GetNSView() superview]);
540 wxASSERT(![cocoaView superview]);
546 void wxWindowCocoa::DoSetSize(int x, int y, int width, int height, int sizeFlags)
548 wxLogTrace(wxTRACE_COCOA_Window_Size,"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":".");
549 int currentX, currentY;
550 int currentW, currentH;
551 DoGetPosition(¤tX, ¤tY);
552 DoGetSize(¤tW, ¤tH);
553 if((x==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
555 if((y==-1) && !(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
558 AdjustForParentClientOrigin(x,y,sizeFlags);
562 if((width==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
564 if(sizeFlags&wxSIZE_AUTO_WIDTH)
566 size=DoGetBestSize();
572 if((height==-1)&&!(sizeFlags&wxSIZE_ALLOW_MINUS_ONE))
574 if(sizeFlags&wxSIZE_AUTO_HEIGHT)
577 size=DoGetBestSize();
583 DoMoveWindow(x,y,width,height);
586 void wxWindowCocoa::DoMoveWindow(int x, int y, int width, int height)
588 wxAutoNSAutoreleasePool pool;
589 wxLogTrace(wxTRACE_COCOA_Window_Size,"wxWindow=%p::DoMoveWindow(%d,%d,%d,%d)",this,x,y,width,height);
591 NSView *nsview = GetNSViewForSuperview();
592 NSView *superview = [nsview superview];
593 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
594 NSRect parentRect = [superview bounds];
596 NSRect cocoaRect = NSMakeRect(x,parentRect.size.height-(y+height),width,height);
597 [nsview setFrame: cocoaRect];
598 // Be sure to redraw the parent to reflect the changed position
599 [superview setNeedsDisplay:YES];
602 void wxWindowCocoa::SetInitialFrameRect(const wxPoint& pos, const wxSize& size)
604 NSView *nsview = GetNSViewForSuperview();
605 NSView *superview = [nsview superview];
606 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
607 NSRect parentRect = [superview bounds];
608 NSRect frameRect = [nsview frame];
610 frameRect.size.width = size.x;
612 frameRect.size.height = size.y;
613 frameRect.origin.x = pos.x;
614 frameRect.origin.y = parentRect.size.height-(pos.y+frameRect.size.height);
615 // Tell Cocoa to change the margin between the bottom of the superview
616 // and the bottom of the control. Keeps the control pinned to the top
617 // of its superview so that its position in the wxWindows coordinate
618 // system doesn't change.
619 if(![superview isFlipped])
620 [nsview setAutoresizingMask: NSViewMinYMargin];
621 // MUST set the mask before setFrame: which can generate a size event
622 // and cause a scroller to be added!
623 [nsview setFrame: frameRect];
627 void wxWindow::DoGetSize(int *w, int *h) const
629 NSRect cocoaRect = [GetNSViewForSuperview() frame];
631 *w=(int)cocoaRect.size.width;
633 *h=(int)cocoaRect.size.height;
634 wxLogTrace(wxTRACE_COCOA_Window_Size,"wxWindow=%p::DoGetSize = (%d,%d)",this,(int)cocoaRect.size.width,(int)cocoaRect.size.height);
637 void wxWindow::DoGetPosition(int *x, int *y) const
639 NSView *nsview = GetNSViewForSuperview();
640 NSView *superview = [nsview superview];
641 wxCHECK_RET(superview,wxT("NSView does not have a superview"));
642 NSRect parentRect = [superview bounds];
644 NSRect cocoaRect = [nsview frame];
646 *x=(int)cocoaRect.origin.x;
648 *y=(int)(parentRect.size.height-(cocoaRect.origin.y+cocoaRect.size.height));
649 wxLogTrace(wxTRACE_COCOA_Window_Size,"wxWindow=%p::DoGetPosition = (%d,%d)",this,(int)cocoaRect.origin.x,(int)cocoaRect.origin.y);
652 WXWidget wxWindow::GetHandle() const
654 return m_cocoaNSView;
657 void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
659 [m_cocoaNSView setNeedsDisplay:YES];
662 void wxWindow::SetFocus()
667 void wxWindow::DoCaptureMouse()
670 sm_capturedWindow = this;
673 void wxWindow::DoReleaseMouse()
676 sm_capturedWindow = NULL;
679 void wxWindow::DoScreenToClient(int *x, int *y) const
684 void wxWindow::DoClientToScreen(int *x, int *y) const
689 // Get size *available for subwindows* i.e. excluding menu bar etc.
690 void wxWindow::DoGetClientSize(int *x, int *y) const
692 wxLogTrace(wxTRACE_COCOA,wxT("DoGetClientSize:"));
694 m_cocoaScroller->DoGetClientSize(x,y);
696 wxWindowCocoa::DoGetSize(x,y);
699 void wxWindow::DoSetClientSize(int width, int height)
701 wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("DoSetClientSize=(%d,%d)"),width,height);
703 m_cocoaScroller->ClientSizeToSize(width,height);
704 CocoaSetWxWindowSize(width,height);
707 void wxWindow::CocoaSetWxWindowSize(int width, int height)
709 wxWindowCocoa::DoSetSize(-1,-1,width,height,wxSIZE_USE_EXISTING);
712 int wxWindow::GetCharHeight() const
718 int wxWindow::GetCharWidth() const
724 void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
725 int *descent, int *externalLeading, const wxFont *theFont) const
730 // Coordinates relative to the window
731 void wxWindow::WarpPointer (int x_pos, int y_pos)
736 int wxWindow::GetScrollPos(int orient) const
742 // This now returns the whole range, not just the number
743 // of positions that we can scroll.
744 int wxWindow::GetScrollRange(int orient) const
750 int wxWindow::GetScrollThumb(int orient) const
756 void wxWindow::SetScrollPos(int orient, int pos, bool refresh)
761 void wxWindow::CocoaCreateNSScrollView()
765 m_cocoaScroller = new wxWindowCocoaScroller(this);
769 // New function that will replace some of the above.
770 void wxWindow::SetScrollbar(int orient, int pos, int thumbVisible,
771 int range, bool refresh)
773 CocoaCreateNSScrollView();
777 // Does a physical scroll
778 void wxWindow::ScrollWindow(int dx, int dy, const wxRect *rect)
783 void wxWindow::DoSetVirtualSize( int x, int y )
785 wxWindowBase::DoSetVirtualSize(x,y);
786 CocoaCreateNSScrollView();
787 [m_cocoaNSView setFrameSize:NSMakeSize(m_virtualSize.x,m_virtualSize.y)];
790 bool wxWindow::SetFont(const wxFont& font)
796 static int CocoaRaiseWindowCompareFunction(id first, id second, void *target)
798 // first should be ordered higher
800 return NSOrderedDescending;
801 // second should be ordered higher
803 return NSOrderedAscending;
804 return NSOrderedSame;
807 // Raise the window to the top of the Z order
808 void wxWindow::Raise()
810 // wxAutoNSAutoreleasePool pool;
811 NSView *nsview = GetNSViewForSuperview();
812 [[nsview superview] sortSubviewsUsingFunction:
813 CocoaRaiseWindowCompareFunction
817 static int CocoaLowerWindowCompareFunction(id first, id second, void *target)
819 // first should be ordered lower
821 return NSOrderedAscending;
822 // second should be ordered lower
824 return NSOrderedDescending;
825 return NSOrderedSame;
828 // Lower the window to the bottom of the Z order
829 void wxWindow::Lower()
831 NSView *nsview = GetNSViewForSuperview();
832 [[nsview superview] sortSubviewsUsingFunction:
833 CocoaLowerWindowCompareFunction
837 bool wxWindow::DoPopupMenu(wxMenu *menu, int x, int y)
842 // Get the window with the focus
843 wxWindow *wxWindowBase::FindFocus()
849 /* static */ wxWindow *wxWindowBase::GetCapture()
852 return wxWindowCocoa::sm_capturedWindow;
855 wxWindow *wxGetActiveWindow()
861 wxPoint wxGetMousePosition()
864 return wxDefaultPosition;
867 wxWindow* wxFindWindowAtPointer(wxPoint& pt)
869 pt = wxGetMousePosition();