Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelipe Heidrich2007-08-29 20:48:12 +0000
committerFelipe Heidrich2007-08-29 20:48:12 +0000
commitcd2b53b4a9279ed54f58046e25d52b26e8ff215a (patch)
tree706f9aebc849d8f6ce17c7bd9ea8d824d5ebcbb1
parent8302dcae845b1fe69dae77b303345ce4bebc2e77 (diff)
downloadeclipse.platform.swt-cd2b53b4a9279ed54f58046e25d52b26e8ff215a.tar.gz
eclipse.platform.swt-cd2b53b4a9279ed54f58046e25d52b26e8ff215a.tar.xz
eclipse.platform.swt-cd2b53b4a9279ed54f58046e25d52b26e8ff215a.zip
merge imeStyles and userStyles
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java16
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextRenderer.java37
2 files changed, 34 insertions, 19 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 aa4c16cec0..14691f1c3c 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
@@ -4966,6 +4966,8 @@ void handleCompositionChanged(Event event) {
compositionStart = caretOffset;
compositionLength = 0;
}
+ renderer.imeRanges = null;
+ renderer.imeStyles = null;
if (length == event.count) {
content.replaceTextRange(compositionStart, compositionLength, "");
caretOffset = compositionStart;
@@ -4976,18 +4978,12 @@ void handleCompositionChanged(Event event) {
} 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;
+ int lineIndex = getCaretLine();
+ renderer.imeRanges = event.ranges;
+ renderer.imeStyles = event.styles;
+ renderer.reset(lineIndex, 1);
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;
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 5d78527e0d..ef9f041f4c 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
@@ -54,6 +54,10 @@ class StyledTextRenderer {
int stylesSetCount = 0;
final static int BULLET_MARGIN = 8;
+ /* IME styles*/
+ int[] imeRanges;
+ TextStyle[] imeStyles;
+
final static boolean COMPACT_STYLES = true;
final static boolean MERGE_STYLES = true;
@@ -836,16 +840,29 @@ 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 (styledText != null && imeRanges != null && imeStyles != null) {
+ int compositionStart = styledText.compositionStart;
+ int compositionLength = styledText.compositionLength;
+ if (compositionStart != -1 && compositionLength > 0) {
+ int compositionLine = content.getLineAtOffset(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);
+ for (int i = 0; i < imeStyles.length; i++) {
+ int start = imeRanges[i*2] + compositionStart - lineOffset;
+ int end = start + imeRanges[i*2+1] - 1;
+ TextStyle imeStyle = imeStyles[i], userStyle;
+ for (int j = start; j <= end; j++) {
+ userStyle = layout.getStyle(j);
+ if (userStyle == null && j > 0) userStyle = layout.getStyle(j - 1);
+ if (userStyle == null && j + 1 < length) userStyle = layout.getStyle(j + 1);
+ if (userStyle == null) {
+ layout.setStyle(imeStyle, j, j);
+ } else {
+ TextStyle newStyle = new TextStyle(imeStyle);
+ if (newStyle.font == null) newStyle.font = userStyle.font;
+ if (newStyle.foreground == null) newStyle.foreground = userStyle.foreground;
+ if (newStyle.background == null) newStyle.background = userStyle.background;
+ layout.setStyle(newStyle, j, j);
+ }
}
}
}
@@ -916,6 +933,8 @@ void reset() {
bullets = null;
bulletsIndices = null;
redrawLines = null;
+ imeRanges = null;
+ imeStyles = null;
}
void reset(int startLine, int lineCount) {
int endLine = startLine + lineCount;

Back to the top