void InstallEventHandler( WXWidget control = NULL );
virtual bool DoHandleMouseEvent(NSEvent *event);
- virtual bool DoHandleKeyEvent(NSEvent *event);
+ virtual bool DoHandleKeyEvent(NSEvent *event);
+ virtual bool DoHandleCharEvent(NSEvent *event, NSString *text);
virtual void DoNotifyFocusEvent(bool receivedFocus);
void SetFlipped(bool flipped);
virtual bool performDragOperation(void* sender, WXWidget slf, void* _cmd);
virtual void mouseEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
virtual void keyEvent(WX_NSEvent event, WXWidget slf, void* _cmd);
+ virtual void insertText(NSString* text, WXWidget slf, void* _cmd);
virtual bool performKeyEquivalent(WX_NSEvent event, WXWidget slf, void* _cmd);
virtual bool becomeFirstResponder(WXWidget slf, void* _cmd);
virtual bool resignFirstResponder(WXWidget slf, void* _cmd);
protected:
WXWidget m_osxView;
+ NSEvent* m_lastKeyDownEvent;
bool m_isFlipped;
DECLARE_DYNAMIC_CLASS_NO_COPY(wxWidgetCocoaImpl)
@interface wxNSTextField : NSTextField
{
+ wxWidgetCocoaImpl* impl;
}
+ - (void) setImplementation:(wxWidgetCocoaImpl*) item;
+ - (wxWidgetCocoaImpl*) implementation;
@end
@interface wxNSMenu : NSMenu
// the tracking tag is needed to track mouse enter / exit events
- (void) setTrackingTag: (NSTrackingRectTag)tag;
- (NSTrackingRectTag) trackingTag;
-
@end // wxNSView
@interface NSView(PossibleMethods)
return retval;
}
-void SetupKeyEvent( wxKeyEvent &wxevent , NSEvent * nsEvent )
+void SetupKeyEvent( wxKeyEvent &wxevent , NSEvent * nsEvent, NSString* charString = NULL )
{
UInt32 modifiers = [nsEvent modifierFlags] ;
int eventType = [nsEvent type];
if ( eventType != NSFlagsChanged )
{
NSString* nschars = [nsEvent characters];
+ if ( charString )
+ nschars = charString;
+
if ( nschars )
{
wxCFStringRef cfchars((CFStringRef)[nschars retain]);
impl->keyEvent(event, self, _cmd);
}
+void wxOSX_insertText(NSView* self, SEL _cmd, NSString* text)
+{
+ wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
+ if (impl == NULL)
+ return;
+
+ impl->insertText(text, self, _cmd);
+}
+
BOOL wxOSX_performKeyEquivalent(NSView* self, SEL _cmd, NSEvent *event)
{
wxWidgetCocoaImpl* impl = (wxWidgetCocoaImpl* ) wxWidgetImpl::FindFromWXWidget( self );
void wxWidgetCocoaImpl::keyEvent(WX_NSEvent event, WXWidget slf, void *_cmd)
{
- if ( !DoHandleKeyEvent(event) )
+ if ( [[slf window] firstResponder] != slf || !DoHandleKeyEvent(event) )
{
wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
superimpl(slf, (SEL)_cmd, event);
}
}
-bool wxWidgetCocoaImpl::performKeyEquivalent(WX_NSEvent event, WXWidget slf, void *_cmd)
+void wxWidgetCocoaImpl::insertText(NSString* text, WXWidget slf, void *_cmd)
{
- if ( !DoHandleKeyEvent(event) )
+ if (m_lastKeyDownEvent && !DoHandleCharEvent(m_lastKeyDownEvent, text) )
{
- wxOSX_PerformKeyEventHandlerPtr superimpl = (wxOSX_PerformKeyEventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
- return superimpl(slf, (SEL)_cmd, event);
+ wxOSX_EventHandlerPtr superimpl = (wxOSX_EventHandlerPtr) [[slf superclass] instanceMethodForSelector:@selector(insertText:)];
+ superimpl(slf, @selector(insertText:), text);
}
+ m_lastKeyDownEvent = NULL;
+}
- return YES;
+
+bool wxWidgetCocoaImpl::performKeyEquivalent(WX_NSEvent event, WXWidget slf, void *_cmd)
+{
+ wxOSX_PerformKeyEventHandlerPtr superimpl = (wxOSX_PerformKeyEventHandlerPtr) [[slf superclass] instanceMethodForSelector:(SEL)_cmd];
+ return superimpl(slf, (SEL)_cmd, event);
}
bool wxWidgetCocoaImpl::becomeFirstResponder(WXWidget slf, void *_cmd)
wxOSX_CLASS_ADD_METHOD(c, @selector(keyDown:), (IMP) wxOSX_keyEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(keyUp:), (IMP) wxOSX_keyEvent, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(flagsChanged:), (IMP) wxOSX_keyEvent, "v@:@" )
+
+ wxOSX_CLASS_ADD_METHOD(c, @selector(insertText:), (IMP) wxOSX_insertText, "v@:@" )
wxOSX_CLASS_ADD_METHOD(c, @selector(performKeyEquivalent:), (IMP) wxOSX_performKeyEquivalent, "v@:@" )
{
m_osxView = NULL;
m_isFlipped = true;
+ m_lastKeyDownEvent = NULL;
}
wxWidgetCocoaImpl::~wxWidgetCocoaImpl()
}
}
+static bool g_inKeyEvent = false;
+
+bool wxWidgetCocoaImpl::DoHandleCharEvent(NSEvent *event, NSString *text)
+{
+ wxKeyEvent wxevent(wxEVT_KEY_DOWN);
+ SetupKeyEvent( wxevent, event, text );
+
+ wxevent.SetEventType(wxEVT_CHAR);
+
+ return GetWXPeer()->OSXHandleKeyEvent(wxevent);
+}
+
bool wxWidgetCocoaImpl::DoHandleKeyEvent(NSEvent *event)
{
+ wxASSERT_MSG(!g_inKeyEvent, "Re-entering key handler...\n");
+ g_inKeyEvent = true;
wxKeyEvent wxevent(wxEVT_KEY_DOWN);
SetupKeyEvent( wxevent, event );
+
+ bool result = GetWXPeer()->OSXHandleKeyEvent(wxevent);
- return GetWXPeer()->OSXHandleKeyEvent(wxevent);
+ // this will fire higher level events, like insertText, to help
+ // us handle EVT_CHAR, etc.
+ if ([event type] == NSKeyDown)
+ {
+ m_lastKeyDownEvent = event;
+ [m_osxView interpretKeyEvents:[NSArray arrayWithObject:event]];
+ }
+ g_inKeyEvent = false;
+ return result;
}
bool wxWidgetCocoaImpl::DoHandleMouseEvent(NSEvent *event)