+
+void wxWindowMac::SetFocus()
+{
+ if ( gFocusWindow == this )
+ return ;
+
+ if ( AcceptsFocus() )
+ {
+ if (gFocusWindow )
+ {
+#if wxUSE_CARET
+ // Deal with caret
+ if ( gFocusWindow->m_caret )
+ {
+ gFocusWindow->m_caret->OnKillFocus();
+ }
+#endif // wxUSE_CARET
+#ifndef __WXUNIVERSAL__
+ wxWindow* control = wxDynamicCast( gFocusWindow , wxWindow ) ;
+ // TODO we must use the built-in focusing
+ if ( control && control->GetHandle() /* && control->MacIsReallyShown() */ )
+ {
+ UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetTopLevelWindowRef() , (ControlRef) control->GetHandle() , kControlFocusNoPart ) ;
+ control->MacRedrawControl() ;
+ }
+#endif
+ // Without testing the window id, for some reason
+ // a kill focus event can still be sent to
+ // the control just being focussed.
+ int thisId = this->m_windowId;
+ int gFocusWindowId = gFocusWindow->m_windowId;
+ if (gFocusWindowId != thisId)
+ {
+ wxFocusEvent event(wxEVT_KILL_FOCUS, gFocusWindow->m_windowId);
+ event.SetEventObject(gFocusWindow);
+ gFocusWindow->GetEventHandler()->ProcessEvent(event) ;
+ }
+ }
+ gFocusWindow = this ;
+ {
+ #if wxUSE_CARET
+ // Deal with caret
+ if ( m_caret )
+ {
+ m_caret->OnSetFocus();
+ }
+ #endif // wxUSE_CARET
+ // panel wants to track the window which was the last to have focus in it
+ wxChildFocusEvent eventFocus(this);
+ GetEventHandler()->ProcessEvent(eventFocus);
+
+ #ifndef __WXUNIVERSAL__
+ wxControl* control = wxDynamicCast( gFocusWindow , wxControl ) ;
+ if ( control && control->GetHandle() )
+ {
+ UMASetKeyboardFocus( (WindowRef) gFocusWindow->MacGetTopLevelWindowRef() , (ControlRef) control->GetHandle() , kControlFocusNextPart ) ;
+ }
+ #endif
+ wxFocusEvent event(wxEVT_SET_FOCUS, m_windowId);
+ event.SetEventObject(this);
+ GetEventHandler()->ProcessEvent(event) ;
+ }
+ }
+}
+
+
+void wxWindowMac::DoCaptureMouse()
+{
+ wxTheApp->s_captureWindow = this ;
+}
+
+wxWindow* wxWindowBase::GetCapture()
+{
+ return wxTheApp->s_captureWindow ;
+}
+
+void wxWindowMac::DoReleaseMouse()
+{
+ wxTheApp->s_captureWindow = NULL ;
+}
+
+#if wxUSE_DRAG_AND_DROP
+
+void wxWindowMac::SetDropTarget(wxDropTarget *pDropTarget)
+{
+ if ( m_dropTarget != 0 ) {
+ delete m_dropTarget;
+ }
+
+ m_dropTarget = pDropTarget;
+ if ( m_dropTarget != 0 )
+ {
+ // TODO
+ }
+}
+
+#endif
+
+// Old style file-manager drag&drop
+void wxWindowMac::DragAcceptFiles(bool accept)
+{
+ // TODO
+}
+
+void wxWindowMac::MacGetPositionAndSizeFromControl(int& x, int& y,
+ int& w, int& h) const
+{
+ Rect bounds ;
+ GetControlBounds( (ControlRef) m_macControl , &bounds ) ;
+
+
+ x = bounds.left ;
+ y = bounds.top ;
+ w = bounds.right - bounds.left ;
+ h = bounds.bottom - bounds.top ;
+
+ wxTopLevelWindow* tlw = wxDynamicCast( this , wxTopLevelWindow ) ;
+ if ( tlw )
+ {
+ Point tlworigin = { 0 , 0 } ;
+ GrafPtr port ;
+ ::GetPort( &port ) ;
+ ::SetPort( UMAGetWindowPort( (WindowRef) tlw->MacGetWindowRef() ) ) ;
+ ::LocalToGlobal( &tlworigin ) ;
+ ::SetPort( port ) ;
+ x = tlworigin.h ;
+ y = tlworigin.v ;
+ }
+}
+
+bool wxWindowMac::MacGetBoundsForControl(const wxPoint& pos,
+ const wxSize& size,
+ int& x, int& y,
+ int& w, int& h) const
+{
+ x = (int)pos.x;
+ y = (int)pos.y;
+ // todo the default calls may be used as soon as PostCreateControl Is moved here
+ w = size.x ; // WidthDefault( size.x );
+ h = size.y ; // HeightDefault( size.y ) ;
+#if !TARGET_API_MAC_OSX
+ GetParent()->MacWindowToRootWindow( &x , &y ) ;
+#endif
+
+ return true ;
+}
+
+// Get total size
+void wxWindowMac::DoGetSize(int *x, int *y) const
+{
+#if TARGET_API_MAC_OSX
+ int x1 , y1 , w1 ,h1 ;
+ MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ;
+ if(x) *x = w1 ;
+ if(y) *y = h1 ;
+
+#else
+ Rect bounds ;
+ GetControlBounds( (ControlRef) m_macControl , &bounds ) ;
+ if(x) *x = bounds.right - bounds.left ;
+ if(y) *y = bounds.bottom - bounds.top ;
+#endif
+}
+
+void wxWindowMac::DoGetPosition(int *x, int *y) const
+{
+ #if TARGET_API_MAC_OSX
+ int x1 , y1 , w1 ,h1 ;
+ MacGetPositionAndSizeFromControl( x1 , y1, w1 ,h1 ) ;
+ if ( !IsTopLevel() )
+ {
+ wxWindow *parent = GetParent();
+ if ( parent )
+ {
+ wxPoint pt(parent->GetClientAreaOrigin());
+ x1 -= pt.x ;
+ y1 -= pt.y ;
+ }
+ }
+ if(x) *x = x1 ;
+ if(y) *y = y1 ;
+ #else
+ Rect bounds ;
+ GetControlBounds( (ControlRef) m_macControl , &bounds ) ;
+ wxCHECK_RET( GetParent() , wxT("Missing Parent") ) ;
+
+ int xx = bounds.left ;
+ int yy = bounds.top ;
+
+ if ( !GetParent()->IsTopLevel() )
+ {
+ GetControlBounds( (ControlRef) GetParent()->GetHandle() , &bounds ) ;
+
+ xx -= bounds.left ;
+ yy -= bounds.top ;
+ }
+
+ wxPoint pt(GetParent()->GetClientAreaOrigin());
+ xx -= pt.x;
+ yy -= pt.y;
+
+ if(x) *x = xx;
+ if(y) *y = yy;
+#endif
+}
+
+void wxWindowMac::DoScreenToClient(int *x, int *y) const
+{
+ WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
+
+ wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ;
+
+ {
+ Point localwhere = {0,0} ;
+
+ if(x) localwhere.h = * x ;
+ if(y) localwhere.v = * y ;
+
+ wxMacPortSaver s((GrafPtr)GetWindowPort( window )) ;
+ ::GlobalToLocal( &localwhere ) ;
+ if(x) *x = localwhere.h ;
+ if(y) *y = localwhere.v ;
+
+ }
+ MacRootWindowToWindow( x , y ) ;
+
+ wxPoint origin = GetClientAreaOrigin() ;
+ if(x) *x -= origin.x ;
+ if(y) *y -= origin.y ;
+}
+
+void wxWindowMac::DoClientToScreen(int *x, int *y) const
+{
+ WindowRef window = (WindowRef) MacGetTopLevelWindowRef() ;
+ wxCHECK_RET( window , wxT("TopLevel Window Missing") ) ;
+
+ wxPoint origin = GetClientAreaOrigin() ;
+ if(x) *x += origin.x ;
+ if(y) *y += origin.y ;
+
+ MacWindowToRootWindow( x , y ) ;
+
+ {
+ Point localwhere = { 0,0 };
+ if(x) localwhere.h = * x ;
+ if(y) localwhere.v = * y ;
+
+ wxMacPortSaver s((GrafPtr)GetWindowPort( window )) ;
+ ::LocalToGlobal( &localwhere ) ;
+ if(x) *x = localwhere.h ;
+ if(y) *y = localwhere.v ;
+ }
+}