summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--library/entry.tcl12
-rw-r--r--library/text.tcl13
-rw-r--r--library/tk.tcl3
-rw-r--r--macosx/tkMacOSXKeyEvent.c61
4 files changed, 56 insertions, 33 deletions
diff --git a/library/entry.tcl b/library/entry.tcl
index 0cc9ffb..8d1b1b3 100644
--- a/library/entry.tcl
+++ b/library/entry.tcl
@@ -277,6 +277,18 @@ bind Entry <Meta-Delete> {
}
}
+# Bindings for IME text input.
+
+bind Entry <<TkStartIMEMarkedText>> {
+ dict set ::tk::Priv(IMETextMark) "%W" [%W index insert]
+}
+bind Entry <<TkEndIMEMarkedText>> {
+ %W selection range [dict get $::tk::Priv(IMETextMark) "%W"] insert
+}
+bind Entry <<TkClearIMEMarkedText>> {
+ %W delete [dict get $::tk::Priv(IMETextMark) "%W"] [%W index insert]
+}
+
# A few additional bindings of my own.
bind Entry <2> {
diff --git a/library/text.tcl b/library/text.tcl
index f43366b..7525588 100644
--- a/library/text.tcl
+++ b/library/text.tcl
@@ -397,6 +397,19 @@ bind Text <Meta-Delete> {
}
}
+# Bindings for IME text input.
+
+bind Text <<TkStartIMEMarkedText>> {
+ dict set ::tk::Priv(IMETextMark) "%W" [%W index insert]
+}
+bind Text <<TkEndIMEMarkedText>> {
+ %W tag add IMEmarkedtext [dict get $::tk::Priv(IMETextMark) "%W"] insert
+ %W tag configure IMEmarkedtext -underline on
+}
+bind Text <<TkClearIMEMarkedText>> {
+ %W delete IMEmarkedtext.first IMEmarkedtext.last
+}
+
# Macintosh only bindings:
if {[tk windowingsystem] eq "aqua"} {
diff --git a/library/tk.tcl b/library/tk.tcl
index 35433e8..572c1f0 100644
--- a/library/tk.tcl
+++ b/library/tk.tcl
@@ -701,7 +701,10 @@ if {[tk windowingsystem] eq "aqua"} {
}
}
+# Create a dictionary to store the starting index of the IME marked
+# text in an Entry or Text widget.
+set ::tk::Priv(IMETextMark) [dict create]
# Run the Ttk themed widget set initialization
if {$::ttk::library ne ""} {
diff --git a/macosx/tkMacOSXKeyEvent.c b/macosx/tkMacOSXKeyEvent.c
index a3ab2d3..ce9a452 100644
--- a/macosx/tkMacOSXKeyEvent.c
+++ b/macosx/tkMacOSXKeyEvent.c
@@ -306,6 +306,14 @@ static unsigned isFunctionKey(unsigned int code);
processingCompose = NO;
/*
+ * Clear any working text.
+ */
+
+ if (privateWorkingText != nil) {
+ [self deleteWorkingText];
+ }
+
+ /*
* Insert the string as a sequence of keystrokes.
*/
@@ -349,14 +357,6 @@ static unsigned isFunctionKey(unsigned int code);
Tk_QueueWindowEvent(&xEvent, TCL_QUEUE_TAIL);
}
- /*
- * Clear any working text.
- */
-
- if (privateWorkingText != nil) {
- [self deleteWorkingText];
- }
-
releaseCode = (UInt16) [aString characterAtIndex: 0];
}
@@ -380,12 +380,13 @@ static unsigned isFunctionKey(unsigned int code);
selectedRange: (NSRange)selRange
replacementRange: (NSRange)repRange
{
- Tk_Window tkwin = (Tk_Window) TkMacOSXGetTkWindow([self window]);
+ TkWindow *winPtr = TkMacOSXGetTkWindow([self window]);
+ Tk_Window tkwin = (Tk_Window) winPtr;
+ Tk_Window focusWin = (Tk_Window) winPtr->dispPtr->focusPtr;
NSString *temp;
NSString *str = [aString respondsToSelector:@selector (string)] ?
[aString string] : aString;
- printf("Setting marked text for %s to %s\n", Tk_PathName(tkwin),
- [str length] ? str.UTF8String : "None");
+
if (NS_KEYLOG) {
TKLog(@"setMarkedText '%@' len =%lu range %lu from %lu", str,
(unsigned long) [str length], (unsigned long) selRange.length,
@@ -393,30 +394,23 @@ static unsigned isFunctionKey(unsigned int code);
}
if (privateWorkingText != nil) {
- unsigned long length = [privateWorkingText length];
[self deleteWorkingText];
-
}
+
if ([str length] == 0) {
return;
}
/*
- * Warn the widget that we are going to insert the marked text
- * so it can erase the old marked text and display the new.
- */
-
- TkSendVirtualEvent(tkwin, "TkStartIMEMarkedText", NULL);
-
- /*
* Use our insertText method to display the marked text.
*/
+ TkSendVirtualEvent(focusWin, "TkStartIMEMarkedText", NULL);
temp = [str copy];
[self insertText: temp replacementRange:repRange];
privateWorkingText = temp;
processingCompose = YES;
- TkSendVirtualEvent(tkwin, "TkEndIMEMarkedText", NULL);
+ TkSendVirtualEvent(focusWin, "TkEndIMEMarkedText", NULL);
}
@@ -550,20 +544,21 @@ static unsigned isFunctionKey(unsigned int code);
- (void)deleteWorkingText
{
if (privateWorkingText == nil) {
- printf("No working text to delete\n");
return;
- }
- if (NS_KEYLOG) {
- TKLog(@"deleteWorkingText len = %lu\n",
- (unsigned long)[privateWorkingText length]);
- }
- printf("deleteWorkingText %s\n", [privateWorkingText length] ?
- privateWorkingText.UTF8String : "none");
- [privateWorkingText release];
- privateWorkingText = nil;
- processingCompose = NO;
+ } else {
+ TkWindow *winPtr = TkMacOSXGetTkWindow([self window]);
+ Tk_Window focusWin = (Tk_Window) winPtr->dispPtr->focusPtr;
- //PENDING: delete working text
+ if (NS_KEYLOG) {
+ TKLog(@"deleteWorkingText len = %lu\n",
+ (unsigned long)[privateWorkingText length]);
+ }
+
+ [privateWorkingText release];
+ privateWorkingText = nil;
+ processingCompose = NO;
+ TkSendVirtualEvent(focusWin, "TkClearIMEMarkedText", NULL);
+ }
}
@end