Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLynn Kues2001-09-14 20:14:11 +0000
committerLynn Kues2001-09-14 20:14:11 +0000
commit3d12d611e15f14e078e4ac98a3e7080e2f2e19df (patch)
tree2773415b16dafbb34da79ba4502437bb3601cebd /bundles
parentb8e084e7cc1ee636d470b815faddf44f304c9fef (diff)
downloadeclipse.platform.swt-3d12d611e15f14e078e4ac98a3e7080e2f2e19df.tar.gz
eclipse.platform.swt-3d12d611e15f14e078e4ac98a3e7080e2f2e19df.tar.xz
eclipse.platform.swt-3d12d611e15f14e078e4ac98a3e7080e2f2e19df.zip
1GJ6ABF-c
Diffstat (limited to 'bundles')
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java85
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextBidi.java122
2 files changed, 148 insertions, 59 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 8288307e4e..624a70c153 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
@@ -1215,6 +1215,7 @@ void createBidiCaret() {
if (caret == null) {
caret = new Caret(this, SWT.NULL);
}
+
int direction = StyledTextBidi.getKeyboardLanguageDirection();
if (direction == caretDirection) {
return;
@@ -1406,6 +1407,54 @@ void doBidiCursorPrevious() {
doBidiSelectionCursorPrevious();
}
}
+void doBidiMouseLocationChange(int x, int y, boolean select) {
+ int line = (y + verticalScrollOffset) / lineHeight;
+ int lineCount = content.getLineCount();
+
+ if (line > lineCount - 1) {
+ line = lineCount - 1;
+ }
+ if (line >= 0) {
+ String lineText = content.getLine(line);
+ int lineOffset = content.getOffsetAtLine(line);
+
+
+ GC gc = new GC(this);
+ StyleRange[] styles = null;
+ StyledTextEvent event = getLineStyleData(lineOffset, lineText);
+
+ x += horizontalScrollOffset;
+ if (event != null) {
+ styles = filterLineStyles(event.styles);
+ }
+ lastCaretDirection = SWT.NULL;
+ int[] boldStyles = getBoldRanges(styles, lineOffset, lineText.length());
+ StyledTextBidi bidi = new StyledTextBidi(gc, tabWidth, lineText, boldStyles, boldFont);
+ int[] values = bidi.getCaretOffsetAndDirectionAtX(x);
+ int offsetInLine = values[0];
+ lastCaretDirection = values[1];
+ int newCaretOffset = lineOffset + offsetInLine;
+// if (newCaretOffset != caretOffset) {
+ caretOffset = newCaretOffset;
+ if (select) {
+ doMouseSelection();
+ }
+ Caret caret = getCaret();
+ if (caret != null) {
+ int caretX = bidi.getCaretPosition(offsetInLine, lastCaretDirection);
+ caretX = caretX - horizontalScrollOffset;
+ if (StyledTextBidi.getKeyboardLanguageDirection() == SWT.RIGHT) {
+ caretX -= (getCaretWidth() - 1);
+ }
+ createBidiCaret();
+ caret.setLocation(caretX, line * lineHeight - verticalScrollOffset);
+ }
+// }
+ if (select == false) {
+ clearSelection(true);
+ }
+ }
+}
void doBidiSelectionCursorNext() {
int line = content.getLineAtOffset(caretOffset);
int lineOffset = content.getOffsetAtLine(line);
@@ -1830,6 +1879,10 @@ void doLineUp() {
* include the line delimiter in the selection
*/
void doMouseLocationChange(int x, int y, boolean select) {
+ if (isBidi()) {
+ doBidiMouseLocationChange(x, y, select);
+ return;
+ }
int line = (y + verticalScrollOffset) / lineHeight;
int lineCount = content.getLineCount();
@@ -2556,30 +2609,24 @@ int getCaretOffsetAtX(String line, int lineOffset, int lineXOffset) {
if (event != null) {
styles = filterLineStyles(event.styles);
}
- if (isBidi()) {
- int[] boldStyles = getBoldRanges(styles, lineOffset, line.length());
- StyledTextBidi bidi = new StyledTextBidi(gc, tabWidth, line, boldStyles, boldFont);
- offset = bidi.getCaretOffsetAtX(lineXOffset);
- }
- else {
- int low = -1;
- int high = line.length();
- while (high - low > 1) {
- offset = (high + low) / 2;
- int x = textWidth(line, lineOffset, 0, offset, styles, 0, gc, null);
- int charWidth = textWidth(line, lineOffset, 0, offset + 1, styles, 0, gc, null) - x;
- if (lineXOffset <= x + charWidth / 2) {
- high = offset;
- }
- else {
- low = offset;
- }
+ int low = -1;
+ int high = line.length();
+ while (high - low > 1) {
+ offset = (high + low) / 2;
+ int x = textWidth(line, lineOffset, 0, offset, styles, 0, gc, null);
+ int charWidth = textWidth(line, lineOffset, 0, offset + 1, styles, 0, gc, null) - x;
+ if (lineXOffset <= x + charWidth / 2) {
+ high = offset;
+ }
+ else {
+ low = offset;
}
- offset = high;
}
+ offset = high;
gc.dispose();
return offset;
}
+
/**
* Returns the caret width.
* <p>
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextBidi.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextBidi.java
index fb636dbcba..d8bed03841 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextBidi.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledTextBidi.java
@@ -215,63 +215,106 @@ public void fillBackground(int logicalStart, int length, int xOffset, int yOffse
gc.fillRectangle(xOffset + startX, yOffset, run.getRenderStopX() - startX, height);
}
}
-public int getCaretOffsetAtX(int x) {
+public int[] getCaretOffsetAndDirectionAtX(int x) {
int lineLength = getTextLength();
int low = -1;
int high = lineLength;
int offset;
- int logicalHigh;
if (lineLength == 0) {
- return 0;
+ return new int[] {0,0};
}
- if (x > renderPositions[renderPositions.length - 1] + dx[dx.length - 1]) {
- return lineLength;
+
+ int eol = renderPositions[renderPositions.length - 1] + dx[dx.length - 1];
+ if (x > eol) {
+ return new int[] {lineLength,ST.COLUMN_NEXT};
}
- while (high - low > 1) {
- offset = (high + low) / 2;
- int visualX = renderPositions[offset];
- if (x <= visualX + dx[offset] / 2) {
- high = offset;
+
+ // get the index visually clicked character
+ int visualIndex = 0;
+ int visualX = renderPositions[visualIndex];
+ while ((x > visualX) && (visualIndex < renderPositions.length)) {
+ visualIndex++;
+ if (visualIndex < renderPositions.length) visualX = renderPositions[visualIndex];
+ }
+ visualIndex = Math.max(0,visualIndex-1);
+ // figure out if the character was clicked on the right or left
+ int halfway = renderPositions[visualIndex] + (dx[visualIndex] / 2);
+ boolean visualLeft = (x <= halfway);
+ int direction;
+ // handle visual beginning
+ if (visualIndex == 0) {
+ offset = order[0];
+ if (isRightToLeft(offset)) {
+ if (visualLeft) {
+ offset = order[0] + 1;
+ direction = ST.COLUMN_NEXT;
+ }
+ else {
+ offset = order[0];
+ direction = ST.COLUMN_PREVIOUS;
+ }
}
else {
- low = offset;
+ if (visualLeft) {
+ offset = order[0];
+ direction = ST.COLUMN_PREVIOUS;
+ }
+ else {
+ offset = order[0] + 1;
+ direction = ST.COLUMN_NEXT;
+ }
+ }
+ return new int[] {offset, direction};
+ }
+
+ offset = getLogicalOffset(visualIndex);
+ // handle visual end
+ if (visualIndex == renderPositions.length - 1) {
+ if (isRightToLeft(offset)) {
+ if (visualLeft) {
+ offset = offset + 1;
+ direction = ST.COLUMN_NEXT;
+ }
+ else {
+ offset = offset;
+ direction = ST.COLUMN_PREVIOUS;
+ }
}
- }
- logicalHigh = getLogicalOffset(high);
- offset = logicalHigh;
- // is x on first glyph?
- if (low == -1) {
- int logicalLow = getLogicalOffset(0);
- // if in R2L segment find the offset behind the glyph (which may be a ligature)
- if (isRightToLeft(logicalLow)) {
- int i = logicalLow + 1;
- while (i < order.length && order[i] == order[logicalLow]) {
- i++;
+ else {
+ if (visualLeft) {
+ offset = offset;
+ direction = ST.COLUMN_PREVIOUS;
+ }
+ else {
+ offset = offset + 1;
+ direction = ST.COLUMN_NEXT;
}
- offset = i;
+ }
+ return new int[] {offset, direction};
+ }
+
+ if (isRightToLeft(offset)) {
+ if (visualLeft) {
+ offset = offset + 1;
+ direction = ST.COLUMN_NEXT;
+ }
+ else {
+ offset = offset;
+ direction = ST.COLUMN_PREVIOUS;
}
}
else {
- int logicalLow = getLogicalOffset(low);
- // if x is in R2L segment
- if (isRightToLeft(logicalLow)) {
- offset = logicalLow;
+ if (visualLeft) {
+ offset = offset;
+ direction = ST.COLUMN_PREVIOUS;
}
- else
- if (isRightToLeft(logicalLow) == false && isRightToLeft(logicalHigh)) {
- // if x is between L2R and R2L segment, place offset either logically at
- // first character of R2L segment or in front of next L2R segment.
- // This reflects the possible keyboard cursor movement.
- if (x <= renderPositions[low] + dx[low]) {
- offset = logicalLow + 1;
- }
- if (x > renderPositions[high]) {
- offset = logicalHigh + 1;
- }
+ else {
+ offset = offset + 1;
+ direction = ST.COLUMN_NEXT;
}
}
- return offset;
+ return new int[] {offset, direction};
}
public int getCaretPosition(int logicalOffset) {
int caretX;
@@ -326,7 +369,6 @@ public int getCaretPosition(int logicalOffset, int direction) {
return StyledText.xInset;
}
int caretX;
-
// at or past end of line?
if (logicalOffset >= order.length) {
logicalOffset = Math.min(logicalOffset, order.length - 1);

Back to the top