summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/DisplayRenderer.java24
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/StyledText.java86
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java31
3 files changed, 120 insertions, 21 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/DisplayRenderer.java b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/DisplayRenderer.java
index 77adc4b41a..d328c942cf 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/DisplayRenderer.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT Custom Widgets/common/org/eclipse/swt/custom/DisplayRenderer.java
@@ -95,8 +95,8 @@ protected void drawLineSelectionBackground(String line, int lineOffset, StyleRan
selectionLength = lineLength - selectionStart;
}
}
- gc.setBackground(getSelectionBackground());
- gc.setForeground(getSelectionForeground());
+ gc.setBackground(parent.getSelectionBackground());
+ gc.setForeground(parent.getSelectionForeground());
if (selectionBackgroundWidth == -1) {
boolean isWrappedLine = false;
@@ -226,22 +226,6 @@ protected Point getSelection() {
return parent.internalGetSelection();
}
/**
- * Returns the background color to be used for rendering selected text.
- * <p>
- * @return background color to be used for rendering selected text
- */
-private Color getSelectionBackground() {
- return getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION);
-}
-/**
- * Returns the foreground color to be used for rendering selected text.
- * <p>
- * @return foreground color to be used for rendering selected text
- */
-private Color getSelectionForeground() {
- return getDevice().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
-}
-/**
* @see StyledTextRenderer#getSelectionLineStyles
*/
/*
@@ -335,8 +319,8 @@ protected StyleRange[] mergeSelectionLineStyles(StyleRange[] styles) {
int selectionEnd = selection.y;
Vector newStyles = new Vector(styles.length);
StyleRange selectionStyle = null;
- Color foreground = getSelectionForeground();
- Color background = getSelectionBackground();
+ Color foreground = parent.getSelectionForeground();
+ Color background = parent.getSelectionBackground();
// potential optimization: ignore styles if there is no bold style and the entire line is selected
for (int i = 0; i < styles.length; i++) {
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 6cbed3de32..bac0a8e87b 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
@@ -86,6 +86,8 @@ public class StyledText extends Canvas {
static final int TextChanged = 3006;
static final int LineGetSegments = 3007;
+ Color selectionBackground; // selection background color
+ Color selectionForeground; // selection foreground color
StyledTextContent logicalContent; // native content (default or user specified)
StyledTextContent content; // line wrapping content, same as logicalContent if word wrap is off
DisplayRenderer renderer;
@@ -3862,6 +3864,24 @@ public Point getSelectionRange() {
return new Point(selection.x, selection.y - selection.x);
}
/**
+ * Returns the receiver's selection background color.
+ *
+ * @return the selection background color
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ * @since 2.1
+ */
+public Color getSelectionBackground() {
+ checkWidget();
+ if (selectionBackground == null) {
+ return getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION);
+ }
+ return selectionBackground;
+}
+/**
* Gets the number of selected characters.
* <p>
*
@@ -3876,6 +3896,24 @@ public int getSelectionCount() {
return getSelectionRange().y;
}
/**
+ * Returns the receiver's selection foreground color.
+ *
+ * @return the selection foreground color
+ *
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ * @since 2.1
+ */
+public Color getSelectionForeground() {
+ checkWidget();
+ if (selectionForeground == null) {
+ return getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT);
+ }
+ return selectionForeground;
+}
+/**
* Returns the selected text.
* <p>
*
@@ -6947,6 +6985,54 @@ public void setSelection(Point point) {
if (point == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
setSelection(point.x, point.y);
}
+/**
+ * Sets the receiver's selection background color to the color specified
+ * by the argument, or to the default system color for the control
+ * if the argument is null.
+ *
+ * @param color the new color (or null)
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ * @since 2.1
+ */
+public void setSelectionBackground (Color color) {
+ checkWidget ();
+ if (color != null) {
+ if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ selectionBackground = color;
+ redraw();
+}
+/**
+ * Sets the receiver's selection foreground color to the color specified
+ * by the argument, or to the default system color for the control
+ * if the argument is null.
+ *
+ * @param color the new color (or null)
+ *
+ * @exception IllegalArgumentException <ul>
+ * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
+ * </ul>
+ * @exception SWTException <ul>
+ * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ * @since 2.1
+ */
+public void setSelectionForeground (Color color) {
+ checkWidget ();
+ if (color != null) {
+ if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ selectionForeground = color;
+ redraw();
+}
/**
* Sets the selection and scrolls it into view.
* <p>
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java
index f61551cda8..8635069937 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_custom_StyledText.java
@@ -1090,7 +1090,16 @@ public void test_getSelection(){
text.setSelection(new Point(3, 2));
assertTrue(":c:", text.getSelection().equals(new Point(2, 3)));
}
-
+public void test_getSelectionBackground() {
+ assertTrue(":1:", text.getSelectionBackground() != null);
+ text.setSelectionBackground(getColor(YELLOW));
+ assertTrue(":1:", text.getSelectionBackground() == getColor(YELLOW));
+}
+public void test_getSelectionForeground() {
+ assertTrue(":1:", text.getSelectionForeground() != null);
+ text.setSelectionForeground(getColor(RED));
+ assertTrue(":1:", text.getSelectionForeground() == getColor(RED));
+}
public void test_getSelectionRange() {
String testText = "Line1\r\nLine2";
int invalidRanges [][] = {{-1, 0}, {-1, -1}, {100, 1}, {100, -1}, {12, 1}, {11, 2}, {2, -3}, {50, -1}};
@@ -2970,6 +2979,18 @@ public void test_setSelectionII(){
assertTrue(exceptionThrown);
}
}
+public void test_setSelectionBackgroundLorg_eclipse_swt_graphics_Color(){
+ text.setSelectionBackground(getColor(YELLOW));
+ assertTrue(":1a:", text.getSelectionBackground() == getColor(YELLOW));
+ text.setSelectionBackground(null);
+ assertTrue(":1b:", text.getSelectionBackground().equals(text.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION)));
+}
+public void test_setSelectionForegroundLorg_eclipse_swt_graphics_Color(){
+ text.setSelectionForeground(getColor(RED));
+ assertTrue(":1a:", text.getSelectionForeground() == getColor(RED));
+ text.setSelectionForeground(null);
+ assertTrue(":1b:", text.getSelectionForeground().equals(text.getDisplay().getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT)));
+}
public void test_setSelectionRangeII(){
// setSelectionRange already tested in test_getSelectionRange
@@ -4032,6 +4053,8 @@ public static java.util.Vector methodNames() {
methodNames.addElement("test_getOffsetAtLineI");
methodNames.addElement("test_getOffsetAtLocationLorg_eclipse_swt_graphics_Point");
methodNames.addElement("test_getSelection");
+ methodNames.addElement("test_getSelectionBackground");
+ methodNames.addElement("test_getSelectionForeground");
methodNames.addElement("test_getSelectionRange");
methodNames.addElement("test_getSelectionCount");
methodNames.addElement("test_getSelectionText");
@@ -4077,6 +4100,8 @@ public static java.util.Vector methodNames() {
methodNames.addElement("test_setSelectionI");
methodNames.addElement("test_setSelectionLorg_eclipse_swt_graphics_Point");
methodNames.addElement("test_setSelectionII");
+ methodNames.addElement("test_setSelectionBackgroundLorg_eclipse_swt_graphics_Color");
+ methodNames.addElement("test_setSelectionForegroundLorg_eclipse_swt_graphics_Color");
methodNames.addElement("test_setSelectionRangeII");
methodNames.addElement("test_setStyleRangeLorg_eclipse_swt_custom_StyleRange");
methodNames.addElement("test_setStyleRanges$Lorg_eclipse_swt_custom_StyleRange");
@@ -4123,6 +4148,8 @@ protected void runTest() throws Throwable {
else if (getName().equals("test_getOffsetAtLineI")) test_getOffsetAtLineI();
else if (getName().equals("test_getOffsetAtLocationLorg_eclipse_swt_graphics_Point")) test_getOffsetAtLocationLorg_eclipse_swt_graphics_Point();
else if (getName().equals("test_getSelection")) test_getSelection();
+ else if (getName().equals("test_getSelectionBackground")) test_getSelectionBackground();
+ else if (getName().equals("test_getSelectionForeground")) test_getSelectionForeground();
else if (getName().equals("test_getSelectionRange")) test_getSelectionRange();
else if (getName().equals("test_getSelectionCount")) test_getSelectionCount();
else if (getName().equals("test_getSelectionText")) test_getSelectionText();
@@ -4167,6 +4194,8 @@ protected void runTest() throws Throwable {
else if (getName().equals("test_setLineBackgroundIILorg_eclipse_swt_graphics_Color")) test_setLineBackgroundIILorg_eclipse_swt_graphics_Color();
else if (getName().equals("test_setSelectionI")) test_setSelectionI();
else if (getName().equals("test_setSelectionLorg_eclipse_swt_graphics_Point")) test_setSelectionLorg_eclipse_swt_graphics_Point();
+ else if (getName().equals("test_setSelectionBackgroundLorg_eclipse_swt_graphics_Color")) test_setSelectionBackgroundLorg_eclipse_swt_graphics_Color();
+ else if (getName().equals("test_setSelectionForegroundLorg_eclipse_swt_graphics_Color")) test_setSelectionForegroundLorg_eclipse_swt_graphics_Color();
else if (getName().equals("test_setSelectionII")) test_setSelectionII();
else if (getName().equals("test_setSelectionRangeII")) test_setSelectionRangeII();
else if (getName().equals("test_setStyleRangeLorg_eclipse_swt_custom_StyleRange")) test_setStyleRangeLorg_eclipse_swt_custom_StyleRange();