- (void)setImage:(NSImage *)image;
- (void)setControlSize:(NSControlSize)size;
+- (void)setFont:(NSFont *)fontObject;
+
- (id)contentView;
- (void)setTarget:(id)anObject;
return impl->performKeyEquivalent(event, self, _cmd);
}
+BOOL wxOSX_acceptsFirstResponder(NSView* self, SEL _cmd)
+{
+ wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+ if (impl == NULL)
+ return NO;
+
+ return impl->acceptsFirstResponder(self, _cmd);
+}
+
BOOL wxOSX_becomeFirstResponder(NSView* self, SEL _cmd)
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
return superimpl(slf, (SEL)_cmd, event);
}
+bool wxWidgetCocoaImpl::acceptsFirstResponder(WXWidget slf, void *_cmd)
+{
+ // 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;
}
{
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;
}
wxOSX_CLASS_ADD_METHOD(c, @selector(performKeyEquivalent:), (IMP) wxOSX_performKeyEquivalent, "v@:@" )
+ wxOSX_CLASS_ADD_METHOD(c, @selector(acceptsFirstResponder), (IMP) wxOSX_acceptsFirstResponder, "c@:" )
wxOSX_CLASS_ADD_METHOD(c, @selector(becomeFirstResponder), (IMP) wxOSX_becomeFirstResponder, "c@:" )
wxOSX_CLASS_ADD_METHOD(c, @selector(resignFirstResponder), (IMP) wxOSX_resignFirstResponder, "c@:" )
wxOSX_CLASS_ADD_METHOD(c, @selector(resetCursorRects), (IMP) wxOSX_resetCursorRects, "v@:" )
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() )
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)] )
{
void wxWidgetCocoaImpl::GetBestRect( wxRect *r ) const
{
r->x = r->y = r->width = r->height = 0;
-// if ( [m_osxView isKindOfClass:[NSControl class]] )
+
if ( [m_osxView respondsToSelector:@selector(sizeToFit)] )
{
NSRect former = [m_osxView frame];
[m_osxView setControlSize:size];
}
-void wxWidgetCocoaImpl::SetFont(wxFont const&, wxColour const&, long, bool)
+void wxWidgetCocoaImpl::SetFont(wxFont const& font, wxColour const&, long, bool)
{
- // TODO
+ if ([m_osxView respondsToSelector:@selector(setFont:)])
+ [m_osxView setFont: font.GetNSFont()];
}
void wxWidgetCocoaImpl::InstallEventHandler( WXWidget control )
return GetWXPeer()->HandleWindowEvent(wxevent);
}
-void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus)
+void wxWidgetCocoaImpl::DoNotifyFocusEvent(bool receivedFocus, wxWidgetImpl* otherWindow)
{
wxWindow* thisWindow = GetWXPeer();
if ( thisWindow->MacGetTopLevelWindow() && NeedsFocusRect() )
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
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) ;
}
}