From ed00fff3cb3f3f1ec01f5d69168222c3ce8d51b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20S=C3=B8rvig?= Date: Mon, 27 Jul 2009 14:17:23 +0200 Subject: Make the Character Palette work on Mac/Cocoa. Handle the case when insertText is called with no corresponding keyDown. This fix is for the Cocoa port. Task-number: 147379 --- src/gui/kernel/qcocoaview_mac.mm | 20 ++++++++++++++++---- src/gui/kernel/qcocoaview_mac_p.h | 1 + 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/gui/kernel/qcocoaview_mac.mm b/src/gui/kernel/qcocoaview_mac.mm index 3bc348c..57c9117 100644 --- a/src/gui/kernel/qcocoaview_mac.mm +++ b/src/gui/kernel/qcocoaview_mac.mm @@ -200,6 +200,7 @@ extern "C" { composingText = new QString(); composing = false; sendKeyEvents = true; + inKeyDown = false; currentCustomTypes = 0; [self setHidden:YES]; return self; @@ -983,6 +984,7 @@ extern "C" { - (void)keyDown:(NSEvent *)theEvent { + inKeyDown = true; sendKeyEvents = true; QWidget *widgetToGetKey = qwidget; @@ -1002,6 +1004,7 @@ extern "C" { if (!keyOK && !sendToPopup) [super keyDown:theEvent]; } + inKeyDown = false; } @@ -1039,14 +1042,23 @@ extern "C" { - (void) insertText:(id)aString { - if ([aString length] && composing) { - // Send the commit string to the widget. - QString commitText; + QString commitText; + if ([aString length]) { if ([aString isKindOfClass:[NSAttributedString class]]) { - commitText = QCFString::toQString(reinterpret_cast([aString string])); + commitText = QCFString::toQString(reinterpret_cast([aString string])); } else { commitText = QCFString::toQString(reinterpret_cast(aString)); }; + } + + if ([aString length] && !inKeyDown) { + // Handle the case where insertText is called from somewhere else than the keyDown + // implementation, for example when inserting text from the character palette. + QInputMethodEvent e; + e.setCommitString(commitText); + qt_sendSpontaneousEvent(qwidget, &e); + } else if ([aString length] && composing) { + // Send the commit string to the widget. composing = false; sendKeyEvents = false; QInputMethodEvent e; diff --git a/src/gui/kernel/qcocoaview_mac_p.h b/src/gui/kernel/qcocoaview_mac_p.h index 4762b17..932c6ca 100644 --- a/src/gui/kernel/qcocoaview_mac_p.h +++ b/src/gui/kernel/qcocoaview_mac_p.h @@ -85,6 +85,7 @@ Q_GUI_EXPORT bool composing; int composingLength; bool sendKeyEvents; + bool inKeyDown; QString *composingText; QStringList *currentCustomTypes; NSInteger dragEnterSequence; -- cgit v0.12