diff options
author | Felipe Heidrich <fheidric> | 2007-09-25 20:50:32 +0000 |
---|---|---|
committer | Felipe Heidrich <fheidric> | 2007-09-25 20:50:32 +0000 |
commit | ce9f674596b826eb792a6262915132ee2d8a527d (patch) | |
tree | 8c28463945038c6f24a46f410a1deff61cd468f2 | |
parent | f6778a3a2aa5528a49001184aff4ec937a05d413 (diff) | |
download | eclipse.platform.swt-ce9f674596b826eb792a6262915132ee2d8a527d.tar.gz eclipse.platform.swt-ce9f674596b826eb792a6262915132ee2d8a527d.tar.xz eclipse.platform.swt-ce9f674596b826eb792a6262915132ee2d8a527d.zip |
new event for ime object and support for string reconversion
5 files changed, 49 insertions, 6 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java index 6ed57bd8cc..d4b1226c68 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/carbon/org/eclipse/swt/internal/carbon/OS.java @@ -465,6 +465,7 @@ public class OS extends C { public static final int kEventParamTextInputReplyLeadingEdge = ('t'<<24) + ('r'<<16) + ('l'<<8) + 'e'; public static final int kEventParamTextInputReplyPoint = ('t'<<24) + ('r'<<16) + ('p'<<8) + 't'; public static final int kEventParamTextInputReplyRegionClass = ('t'<<24) + ('r'<<16) + ('r'<<8) + 'g'; + public static final int kEventParamTextInputReplyText = ('t'<<24) + ('r'<<16) + ('t'<<8) + 'x'; public static final int kEventParamTextInputReplyTextOffset = ('t'<<24) + ('r'<<16) + ('t'<<8) + 'o'; public static final int kEventParamTextInputSendCurrentPoint = ('t'<<24) + ('s'<<16) + ('c'<<8) + 'p'; public static final int kEventParamTextInputSendFixLen = ('t'<<24) + ('s'<<16) + ('f'<<8) + 'x'; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Canvas.java index 7873e4da73..77a949980b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Canvas.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Canvas.java @@ -188,6 +188,14 @@ int kEventTextInputUpdateActiveInputArea (int nextHandler, int theEvent, int use return super.kEventTextInputUpdateActiveInputArea (nextHandler, theEvent, userData); } +int kEventTextInputGetSelectedText (int nextHandler, int theEvent, int userData) { + if (ime != null) { + int result = ime.kEventTextInputGetSelectedText (nextHandler, theEvent, userData); + if (result != OS.eventNotHandledErr) return result; + } + return super.kEventTextInputGetSelectedText (nextHandler, theEvent, userData); +} + void redrawWidget (int control, boolean children) { boolean isFocus = caret != null && caret.isFocusCaret (); if (isFocus) caret.killFocus (); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java index b5b7b5e3d2..e8b9ee45f7 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Display.java @@ -2146,6 +2146,7 @@ void initializeCallbacks () { OS.kEventClassTextInput, OS.kEventTextInputUpdateActiveInputArea, OS.kEventClassTextInput, OS.kEventTextInputOffsetToPos, OS.kEventClassTextInput, OS.kEventTextInputPosToOffset, + OS.kEventClassTextInput, OS.kEventTextInputGetSelectedText, }; OS.InstallEventHandler (focusTarget, textInputProc, mask5.length / 2, mask5, 0, null); OS.AEInstallEventHandler (OS.kAppearanceEventClass, OS.kAEAppearanceChanged, appearanceProc, 0, false); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/IME.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/IME.java index c7b27d0e3d..3956f09b6e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/IME.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/IME.java @@ -71,12 +71,20 @@ public int getCompositionOffset () { public int [] getRanges () { checkWidget (); - return ranges != null ? ranges : new int [0]; + if (ranges == null) return new int [0]; + int[] result = new int [ranges.length]; + for (int i = 0; i < result.length; i++) { + result[i] = ranges [i] + startOffset; + } + return result; } public TextStyle [] getStyles () { checkWidget (); - return styles != null ? styles : new TextStyle [0]; + if (styles == null) return new TextStyle [0]; + TextStyle[] result = new TextStyle [styles.length]; + System.arraycopy (styles, 0, result, 0, styles.length); + return result; } public String getText () { @@ -136,6 +144,20 @@ int kEventTextInputPosToOffset (int nextHandler, int theEvent, int userData) { return OS.noErr; } +int kEventTextInputGetSelectedText (int nextHandler, int theEvent, int userData) { + Event event = new Event (); + event.detail = SWT.COMPOSITION_SELECTION; + sendEvent (SWT.ImeComposition, event); + String text = event.text; + if (text.length() > 0) { + char [] buffer = new char [text.length()]; + text.getChars (0, buffer.length, buffer, 0); + OS.SetEventParameter (theEvent, OS.kEventParamTextInputReplyText, OS.typeUnicodeText, buffer.length * 2, buffer); + return OS.noErr; + } + return OS.eventNotHandledErr; +} + int kEventTextInputUpdateActiveInputArea (int nextHandler, int theEvent, int userData) { if (!isInlineEnabled ()) return OS.eventNotHandledErr; ranges = null; @@ -172,7 +194,7 @@ int kEventTextInputUpdateActiveInputArea (int nextHandler, int theEvent, int use case OS.kSelectedRawText: case OS.kRawText: ranges [j * 2] = range.fStart / 2; - ranges [j * 2 + 1] = range.fEnd / 2 - range.fStart / 2 + 0; + ranges [j * 2 + 1] = range.fEnd / 2 - 1; styles [j] = new TextStyle (); styles [j].underline = true; styles [j].underlineStyle = UNDERLINE_IME_INPUT; @@ -196,14 +218,18 @@ int kEventTextInputUpdateActiveInputArea (int nextHandler, int theEvent, int use caretOffset = firstSelectedConverted / 2; } } + int end = startOffset + text.length(); if (startOffset == -1) { - Caret caret = parent.getCaret(); - startOffset = caret != null ? caret.getOffset() : 0; + Event event = new Event (); + event.detail = SWT.COMPOSITION_SELECTION; + sendEvent (SWT.ImeComposition, event); + startOffset = event.start; + end = event.end; } Event event = new Event (); event.detail = SWT.COMPOSITION_CHANGED; event.start = startOffset; - event.end = startOffset + text.length(); + event.end = end; event.text = text = new String(chars, 0, length [0] / 2); commitCount = fixed_length [0] != -1 ? fixed_length [0] / 2: length [0] / 2; sendEvent (SWT.ImeComposition, event); @@ -211,6 +237,8 @@ int kEventTextInputUpdateActiveInputArea (int nextHandler, int theEvent, int use text = ""; caretOffset = commitCount = 0; startOffset = -1; + ranges = null; + styles = null; } if (event.doit) { if (fixed_length [0] == -1 || fixed_length [0] == length [0]) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Widget.java index b30e010ba4..854fb8740d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Widget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/carbon/org/eclipse/swt/widgets/Widget.java @@ -1194,6 +1194,10 @@ int kEventTextInputPosToOffset (int nextHandler, int theEvent, int userData) { return OS.eventNotHandledErr; } +int kEventTextInputGetSelectedText (int nextHandler, int theEvent, int userData) { + return OS.eventNotHandledErr; +} + int kEventWindowActivated (int nextHandler, int theEvent, int userData) { return OS.eventNotHandledErr; } @@ -1943,6 +1947,7 @@ int textInputProc (int nextHandler, int theEvent, int userData) { case OS.kEventTextInputUpdateActiveInputArea: return kEventTextInputUpdateActiveInputArea (nextHandler, theEvent, userData); case OS.kEventTextInputOffsetToPos: return kEventTextInputOffsetToPos (nextHandler, theEvent, userData); case OS.kEventTextInputPosToOffset: return kEventTextInputPosToOffset (nextHandler, theEvent, userData); + case OS.kEventTextInputGetSelectedText: return kEventTextInputGetSelectedText (nextHandler, theEvent, userData); } return OS.eventNotHandledErr; } |