]> git.saurik.com Git - wxWidgets.git/blobdiff - src/osx/cocoa/window.mm
add alignment flags support to wxSpinCtrl[Double] (closes #10621)
[wxWidgets.git] / src / osx / cocoa / window.mm
index f26fa31831aef51413ab9b40d06a0f727cbe4d6a..822bf528c75e50c1e422196cde7dfd482b348013 100644 (file)
@@ -73,6 +73,8 @@ NSRect wxOSXGetFrameForControl( wxWindowMac* window , const wxPoint& pos , const
 - (void)setImage:(NSImage *)image;
 - (void)setControlSize:(NSControlSize)size;
 
+- (void)setFont:(NSFont *)fontObject;
+
 - (id)contentView;
 
 - (void)setTarget:(id)anObject;
@@ -791,21 +793,22 @@ bool wxWidgetCocoaImpl::performKeyEquivalent(WX_NSEvent event, WXWidget slf, voi
 
 bool wxWidgetCocoaImpl::acceptsFirstResponder(WXWidget slf, void *_cmd)
 {
-    // Make sure wxWindows can receive focus by default like they do for other ports.
-
-    // FIXME: It'd be nice to have some way to tie this in with AcceptsFocus
-    // but that currently causes loops because the call to m_peer->CanFocus() 
-    // ends up calling this method again. Don't know how to avoid it without
-    // making a setter method for focus.
-    return YES;
+    // FIXME: We need to find a way to query AcceptsFocus here, but when we do it
+    // it calls native APIs which lead us back here and into a loop.
+    wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
+    return superimpl(slf, (SEL)_cmd);
 }
 
 bool wxWidgetCocoaImpl::becomeFirstResponder(WXWidget slf, void *_cmd)
 {
     wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
+    // get the current focus before running becomeFirstResponder
+    NSResponder* currentResponder = [[NSApp keyWindow] firstResponder]; 
+    NSView* otherView = (currentResponder != nil && [currentResponder isKindOfClass:[NSView class]]) ? (NSView*) currentResponder : NULL; 
+    wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
     BOOL r = superimpl(slf, (SEL)_cmd);
     if ( r )
-        DoNotifyFocusEvent( true );
+        DoNotifyFocusEvent( true, otherWindow );
     return r;
 }
 
@@ -813,8 +816,12 @@ bool wxWidgetCocoaImpl::resignFirstResponder(WXWidget slf, void *_cmd)
 {
     wxOSX_FocusHandlerPtr superimpl = (wxOSX_FocusHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
     BOOL r = superimpl(slf, (SEL)_cmd);
+    // get the current focus after running resignFirstResponder
+    NSResponder* currentResponder = [[NSApp keyWindow] firstResponder]; 
+    NSView* otherView = (currentResponder != nil && [currentResponder isKindOfClass:[NSView class]]) ? (NSView*) currentResponder : NULL; 
+    wxWidgetImpl* otherWindow = FindFromWXWidget(otherView);
     if ( r )
-        DoNotifyFocusEvent( false );
+        DoNotifyFocusEvent( false, otherWindow );
     return r;
 }
 
@@ -1073,7 +1080,7 @@ void wxWidgetCocoaImpl::Move(int x, int y, int width, int height)
     wxWindowMac* parent = GetWXPeer()->GetParent();
     // under Cocoa we might have a contentView in the wxParent to which we have to 
     // adjust the coordinates
-    if (parent)
+    if (parent && [m_osxView superview] != parent->GetHandle() )
     {
         int cx = 0,cy = 0,cw = 0,ch = 0;
         if ( parent->GetPeer() )
@@ -1083,8 +1090,10 @@ void wxWidgetCocoaImpl::Move(int x, int y, int width, int height)
             y -= cy;
         }
     }
+    [[m_osxView superview] setNeedsDisplayInRect:[m_osxView frame]];
     NSRect r = wxToNSRect( [m_osxView superview], wxRect(x,y,width, height) );
     [m_osxView setFrame:r];
+    [[m_osxView superview] setNeedsDisplayInRect:r]; 
     
     if ([m_osxView respondsToSelector:@selector(trackingTag)] )
     {
@@ -1343,11 +1352,7 @@ void wxWidgetCocoaImpl::SetControlSize( wxWindowVariant variant )
 void wxWidgetCocoaImpl::SetFont(wxFont const& font, wxColour const&, long, bool)
 {
     if ([m_osxView respondsToSelector:@selector(setFont:)])
-#if wxOSX_USE_CORE_TEXT
-        [m_osxView setFont: (CTFontRef)font.MacGetCTFont()];
-#else
-
-#endif
+        [m_osxView setFont: font.GetNSFont()];
 }
 
 void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
@@ -1406,7 +1411,7 @@ bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)
     return GetWXPeer()->HandleWindowEvent(wxevent);
 }
 
-void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus)
+void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow)
 {
     wxWindow* thisWindow = GetWXPeer();
     if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
@@ -1427,8 +1432,8 @@ void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus)
 
         wxFocusEvent event(wxEVT_SET_FOCUS, thisWindow->GetId());
         event.SetEventObject(thisWindow);
-        // TODO how to find out the targetFocusWindow ?
-        // event.SetWindow(targetFocusWindow);
+        if (otherWindow)
+            event.SetWindow(otherWindow->GetWXPeer());
         thisWindow->HandleWindowEvent(event) ;
     }
     else // !receivedFocuss
@@ -1442,8 +1447,8 @@ void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus)
                     
         wxFocusEvent event( wxEVT_KILL_FOCUS, thisWindow->GetId());
         event.SetEventObject(thisWindow);
-        // TODO how to find out the targetFocusWindow ?
-        // event.SetWindow(targetFocusWindow);
+        if (otherWindow)
+            event.SetWindow(otherWindow->GetWXPeer());
         thisWindow->HandleWindowEvent(event) ;
     }
 }