summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelipe Heidrich <fheidric>2007-08-22 21:56:28 +0000
committerFelipe Heidrich <fheidric>2007-08-22 21:56:28 +0000
commita8b66e5526c4d5742c189dc14fbd5713d660c0e6 (patch)
tree1ecf590b1373866d3ef72424fb505fb85d70b589
parentf295d81c96c5f0cad60547a25236d1a3bb649162 (diff)
downloadeclipse.platform.swt-a8b66e5526c4d5742c189dc14fbd5713d660c0e6.tar.gz
eclipse.platform.swt-a8b66e5526c4d5742c189dc14fbd5713d660c0e6.tar.xz
eclipse.platform.swt-a8b66e5526c4d5742c189dc14fbd5713d660c0e6.zip
Bug 108591 - SWT StyledText does not support inline Input method
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java84
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java16
2 files changed, 99 insertions, 1 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
index f2130212a6..aa4c16cec0 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java
@@ -145,10 +145,12 @@ public class StyledText extends Canvas {
Image leftCaretBitmap = null;
Image rightCaretBitmap = null;
int caretDirection = SWT.NULL;
+ int caretWidth = 0;
Caret defaultCaret = null;
boolean updateCaretDirection = true;
boolean fixedLineHeight;
boolean dragDetect = true;
+ int compositionStart = -1, compositionLength;
int alignment;
boolean justify;
@@ -4610,6 +4612,7 @@ int getVisualLineIndex(TextLayout layout, int offsetInLine) {
}
int getCaretDirection() {
if (!isBidiCaret()) return SWT.DEFAULT;
+ if (compositionStart != -1 && compositionLength > 0) return SWT.DEFAULT;
if (!updateCaretDirection && caretDirection != SWT.NULL) return caretDirection;
updateCaretDirection = false;
int caretLine = getCaretLine();
@@ -4797,6 +4800,7 @@ void installListeners() {
public void handleEvent(Event event) {
switch (event.type) {
case SWT.Dispose: handleDispose(event); break;
+ case SWT.ImeComposition: handleImeComposition(event); break;
case SWT.KeyDown: handleKeyDown(event); break;
case SWT.KeyUp: handleKeyUp(event); break;
case SWT.MouseDown: handleMouseDown(event); break;
@@ -4809,6 +4813,7 @@ void installListeners() {
}
};
addListener(SWT.Dispose, listener);
+ addListener(SWT.ImeComposition, listener);
addListener(SWT.KeyDown, listener);
addListener(SWT.KeyUp, listener);
addListener(SWT.MouseDown, listener);
@@ -4920,6 +4925,83 @@ void internalRedrawRange(int start, int length) {
super.redraw(leftMargin, y, clientAreaWidth - rightMargin - leftMargin, endRect.y - y, false);
}
}
+void handleCompositionHittest (Event event) {
+ if (event.y < topMargin || event.x < leftMargin || event.y > clientAreaHeight - bottomMargin || event.x > clientAreaWidth - rightMargin) {
+ event.hitTest = SWT.HITTEST_OUTSIDE_TEXT;
+ return;
+ }
+ int bottomIndex = getPartialBottomIndex();
+ int height = getLinePixel(bottomIndex + 1);
+ if (event.y > height) {
+ event.hitTest = SWT.HITTEST_OUTSIDE_TEXT;
+ return;
+ }
+ int lineIndex = getLineIndex(event.y);
+ int lineOffset = content.getOffsetAtLine(lineIndex);
+ TextLayout layout = renderer.getTextLayout(lineIndex);
+ int[] trailing = new int[1];
+ int x = event.x + horizontalScrollOffset - leftMargin ;
+ int y = event.y - getLinePixel(lineIndex);
+ int offset = layout.getOffset(x, y, trailing);
+ Rectangle rect = layout.getLineBounds(layout.getLineIndex(offset));
+ offset += lineOffset;
+ renderer.disposeTextLayout(layout);
+ if (x > rect.x + rect.width || x < rect.x) {
+ event.hitTest = SWT.HITTEST_OUTSIDE_TEXT;
+ } else {
+ if (compositionStart <= offset && offset < compositionStart + compositionLength) {
+ event.hitTest = SWT.HITTEST_INSIDE_COMPOSITION;
+ event.index = offset - compositionStart;
+ } else {
+ event.hitTest = SWT.HITTEST_INSIDE_TEXT;
+ event.index = offset;
+ }
+ event.trailing = trailing[0];
+ }
+}
+void handleCompositionChanged(Event event) {
+ String text = event.text;
+ int length = text.length();
+ if (compositionStart == -1) {
+ compositionStart = caretOffset;
+ compositionLength = 0;
+ }
+ if (length == event.count) {
+ content.replaceTextRange(compositionStart, compositionLength, "");
+ caretOffset = compositionStart;
+ compositionStart = -1;
+ compositionLength = 0;
+ caretWidth = 0;
+ caretDirection = SWT.NULL;
+ } else {
+ content.replaceTextRange(compositionStart, compositionLength, text);
+ compositionLength = length;
+ if (event.styles != null) {
+ int[] ranges = event.ranges;
+ StyleRange[] styles = new StyleRange[event.styles.length];
+ for (int i = 0; i < event.styles.length; i++) {
+ styles[i] = new StyleRange (event.styles[i]);
+ ranges[i*2] += compositionStart;
+ }
+ setStyleRanges(0, 0, ranges, styles, false);
+ }
+ caretOffset = compositionStart + event.index;
+ if (event.wideCaret) {
+ int lineIndex = getCaretLine();
+ int lineOffset = content.getOffsetAtLine(lineIndex);
+ TextLayout layout = renderer.getTextLayout(lineIndex);
+ caretWidth = layout.getBounds(compositionStart - lineOffset, compositionStart + compositionLength - 1 - lineOffset).width;
+ renderer.disposeTextLayout(layout);
+ }
+ }
+ showCaret();
+}
+void handleImeComposition (Event event) {
+ switch (event.detail) {
+ case SWT.COMPOSITION_CHANGED: handleCompositionChanged(event); break;
+ case SWT.COMPOSITION_HITTEST: handleCompositionHittest(event); break;
+ }
+}
/**
* Frees resources.
*/
@@ -6674,7 +6756,7 @@ void setCaretLocation(Point location, int direction) {
location.x -= (caret.getSize().x - 1);
}
if (isDefaultCaret) {
- caret.setBounds(location.x, location.y, 0, caretHeight);
+ caret.setBounds(location.x, location.y, caretWidth, caretHeight);
} else {
caret.setLocation(location);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java
index 296743e59f..5d78527e0d 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java
@@ -836,6 +836,22 @@ TextLayout getTextLayout(int lineIndex, int orientation, int width, int lineSpac
}
}
if (lastOffset < length) layout.setStyle(null, lastOffset, length);
+ if (event != null) {
+ if (styledText.compositionStart != -1 && styledText.compositionLength > 0) {
+ int compositionLine = styledText.getContent().getLineAtOffset(styledText.compositionStart);
+ if (compositionLine == lineIndex) {
+ StyleRange[] imeStyles = getStyleRanges(styledText.compositionStart, styledText.compositionLength, false);
+ int[] imeRanges = getRanges(styledText.compositionStart, styledText.compositionLength);
+ if (imeStyles != null && imeRanges != null) {
+ for (int i = 0; i < imeStyles.length; i++) {
+ int start = imeRanges[i*2] - lineOffset;
+ layout.setStyle(imeStyles[i], start, start + imeRanges[i*2+1] - 1);
+ }
+ }
+ }
+ }
+ }
+
if (styledText != null && styledText.isFixedLineHeight()) {
int index = -1;
int lineCount = layout.getLineCount();