Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiraj Modi2014-12-19 06:01:08 +0000
committerNiraj Modi2014-12-19 06:01:08 +0000
commit21f50fb563fbe509616757d9da699caae0c1911b (patch)
tree48b8d6bb14f292311666d2cb8f82fe75b783e66f
parente43073a0a3cd7418d4c7af0ba6213571228590ca (diff)
downloadeclipse.platform.swt-21f50fb563fbe509616757d9da699caae0c1911b.tar.gz
eclipse.platform.swt-21f50fb563fbe509616757d9da699caae0c1911b.tar.xz
eclipse.platform.swt-21f50fb563fbe509616757d9da699caae0c1911b.zip
Bug 435384 - Add support for 'transparent' colors
- Added SWT.COLOR_TRANSPARENT to get pre-defied transparent color. - Refactored Windows color class - Fixed Color JUnits Change-Id: I3fcd2e82adfc20ef3a09fae0b11bc33da2e53be3 Signed-off-by: Niraj Modi <niraj.modi@in.ibm.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java6
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java7
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java6
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java6
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java47
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet365.java57
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Color.java4
7 files changed, 68 insertions, 65 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java
index f7cc540a53..66ba8f81c7 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/graphics/Device.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -36,7 +36,7 @@ public abstract class Device implements Drawable {
boolean disposed, warnings;
Color COLOR_BLACK, COLOR_DARK_RED, COLOR_DARK_GREEN, COLOR_DARK_YELLOW, COLOR_DARK_BLUE;
- Color COLOR_DARK_MAGENTA, COLOR_DARK_CYAN, COLOR_GRAY, COLOR_DARK_GRAY, COLOR_RED;
+ Color COLOR_DARK_MAGENTA, COLOR_DARK_CYAN, COLOR_GRAY, COLOR_DARK_GRAY, COLOR_RED, COLOR_TRANSPARENT;
Color COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE;
/* System Font */
@@ -437,6 +437,7 @@ Point getScreenDPI () {
public Color getSystemColor (int id) {
checkDevice ();
switch (id) {
+ case SWT.COLOR_TRANSPARENT: return COLOR_TRANSPARENT;
case SWT.COLOR_BLACK: return COLOR_BLACK;
case SWT.COLOR_DARK_RED: return COLOR_DARK_RED;
case SWT.COLOR_DARK_GREEN: return COLOR_DARK_GREEN;
@@ -512,6 +513,7 @@ public boolean getWarnings () {
*/
protected void init () {
/* Create the standard colors */
+ COLOR_TRANSPARENT = new Color (this, 0,0,0,0);
COLOR_BLACK = new Color (this, 0,0,0);
COLOR_DARK_RED = new Color (this, 0x80,0,0);
COLOR_DARK_GREEN = new Color (this, 0,0x80,0);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java
index 493590de58..ab904017fd 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/common/org/eclipse/swt/SWT.java
@@ -3262,6 +3262,13 @@ public class SWT {
public static final int COLOR_LINK_FOREGROUND = 36;
/**
+ * Color used to paint with alpha 0 (value is 37).
+ *
+ * @since 3.104
+ */
+ public static final int COLOR_TRANSPARENT = 37;
+
+ /**
* Draw constant indicating whether the drawing operation
* should fill the background (value is 1&lt;&lt;0).
*/
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java
index cd64f84e85..97c603dac3 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2013 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -74,7 +74,7 @@ public abstract class Device implements Drawable {
* palette.
*/
Color COLOR_BLACK, COLOR_DARK_RED, COLOR_DARK_GREEN, COLOR_DARK_YELLOW, COLOR_DARK_BLUE;
- Color COLOR_DARK_MAGENTA, COLOR_DARK_CYAN, COLOR_GRAY, COLOR_DARK_GRAY, COLOR_RED;
+ Color COLOR_DARK_MAGENTA, COLOR_DARK_CYAN, COLOR_GRAY, COLOR_DARK_GRAY, COLOR_RED, COLOR_TRANSPARENT;
Color COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE;
/* System Font */
@@ -504,6 +504,7 @@ Point getScreenDPI () {
public Color getSystemColor (int id) {
checkDevice ();
switch (id) {
+ case SWT.COLOR_TRANSPARENT: return COLOR_TRANSPARENT;
case SWT.COLOR_BLACK: return COLOR_BLACK;
case SWT.COLOR_DARK_RED: return COLOR_DARK_RED;
case SWT.COLOR_DARK_GREEN: return COLOR_DARK_GREEN;
@@ -634,6 +635,7 @@ protected void init () {
}
/* Create the standard colors */
+ COLOR_TRANSPARENT = new Color (this, 0,0,0,0);
COLOR_BLACK = new Color (this, 0,0,0);
COLOR_DARK_RED = new Color (this, 0x80,0,0);
COLOR_DARK_GREEN = new Color (this, 0,0x80,0);
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java
index a953886042..eeda42fb32 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/graphics/Device.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2012 IBM Corporation and others.
+ * Copyright (c) 2000, 2014 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -605,8 +605,10 @@ String getLastErrorText () {
public Color getSystemColor (int id) {
checkDevice ();
int pixel = 0x00000000;
+ int alpha = 255;
switch (id) {
case SWT.COLOR_WHITE: pixel = 0x00FFFFFF; break;
+ case SWT.COLOR_TRANSPARENT: alpha = 0;
case SWT.COLOR_BLACK: pixel = 0x00000000; break;
case SWT.COLOR_RED: pixel = 0x000000FF; break;
case SWT.COLOR_DARK_RED: pixel = 0x00000080; break;
@@ -623,7 +625,7 @@ public Color getSystemColor (int id) {
case SWT.COLOR_GRAY: pixel = 0x00C0C0C0; break;
case SWT.COLOR_DARK_GRAY: pixel = 0x00808080; break;
}
- return Color.win32_new (this, pixel);
+ return Color.win32_new (this, pixel, alpha);
}
/**
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
index 886aaf1a8f..b76c2393a3 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java
@@ -64,10 +64,10 @@ public abstract class Control extends Widget implements Drawable {
String toolTipText;
Object layoutData;
Accessible accessible;
- Image backgroundImage, transparentBackgroundImage;
+ Image backgroundImage;
Region region;
Font font;
- int drawCount, foreground, background, transparentBackground, backgroundAlpha = 255;
+ int drawCount, foreground, background, backgroundAlpha = 255;
/**
* Prevents uninitialized instances from being created outside the package.
@@ -997,7 +997,7 @@ void fillThemeBackground (long /*int*/ hDC, Control control, RECT rect) {
}
Control findBackgroundControl () {
- if (background != -1 || backgroundImage != null) return this;
+ if ((background != -1 || backgroundImage != null) && backgroundAlpha > 0) return this;
return (state & PARENT_BACKGROUND) != 0 ? parent.findBackgroundControl () : null;
}
@@ -1166,15 +1166,9 @@ public Accessible getAccessible () {
*/
public Color getBackground () {
checkWidget ();
- if (backgroundAlpha == 0) {
- Color color = Color.win32_new (display, transparentBackground, 0);
- return color;
- }
- else {
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- return Color.win32_new (display, control.getBackgroundPixel ());
- }
+ Control control = findBackgroundControl ();
+ if (control == null) control = this;
+ return Color.win32_new (display, control.getBackgroundPixel (), backgroundAlpha);
}
/**
@@ -1191,14 +1185,9 @@ public Color getBackground () {
*/
public Image getBackgroundImage () {
checkWidget ();
- if (backgroundAlpha == 0) {
- return transparentBackgroundImage;
- }
- else {
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- return control.backgroundImage;
- }
+ Control control = findBackgroundControl ();
+ if (control == null) control = this;
+ return control.backgroundImage;
}
int getBackgroundPixel () {
@@ -3037,19 +3026,8 @@ private void _setBackground (Color color) {
}
private void setBackgroundTransparency (int alpha) {
- if (alpha == 0) {
- // clear background
- if (backgroundImage != null) {
- transparentBackgroundImage = getBackgroundImage ();
- setBackgroundImage (null);
- }
- if (getBackground () != null) {
- transparentBackground = getBackgroundPixel ();
- _setBackground (null);
- }
- }
- this.backgroundAlpha = alpha;
- this.updateBackgroundMode ();
+ this.backgroundAlpha = alpha;
+ this.updateBackgroundMode ();
}
/**
@@ -3080,7 +3058,8 @@ public void setBackgroundImage (Image image) {
if (image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
if (image.type != SWT.BITMAP) error (SWT.ERROR_INVALID_ARGUMENT);
}
- if (backgroundImage == image) return;
+ if (backgroundImage == image && backgroundAlpha > 0) return;
+ backgroundAlpha = 255;
backgroundImage = image;
Shell shell = getShell ();
shell.releaseBrushes ();
diff --git a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet365.java b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet365.java
index aac26c5f68..d3a73745ee 100644
--- a/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet365.java
+++ b/examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet365.java
@@ -34,6 +34,7 @@ public class Snippet365 {
static Button check;
static Button push;
static Text text;
+ static Image newImage;
public static void main(String[] args) {
final Display display = new Display();
@@ -41,7 +42,7 @@ public class Snippet365 {
shell.setText("Shell.setBackgroundMode()");
shell.setLayout(new RowLayout(SWT.VERTICAL));
// Standard color background for Shell
- shell.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+// shell.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
// Gradient background for Shell
shell.addListener(SWT.Resize, new Listener() {
@@ -75,19 +76,24 @@ public class Snippet365 {
public void widgetSelected(SelectionEvent e) {
boolean transparent = ((Button) e.getSource()).getSelection();
int alpha = transparent ? 0 : 255;
- composite.setBackground(new Color(display, composite.getBackground().getRGB(), alpha));
- buttonCheckBox.setBackground(new Color(Display.getDefault(), buttonCheckBox.getBackground().getRGB(),
- alpha));
- bar.setBackground(new Color(display, bar.getBackground().getRGB(), alpha));
- list.setBackground(new Color(display, list.getBackground().getRGB(), alpha));
- label.setBackground(new Color(display, label.getBackground().getRGB(), alpha));
- radio.setBackground(new Color(display, radio.getBackground().getRGB(), alpha));
- if (transparent)
- check.setBackground(new Color(display, check.getBackground().getRGB(), alpha));
- else
- check.setBackgroundImage(check.getBackgroundImage());
- push.setBackground(new Color(display, push.getBackground().getRGB(), alpha));
- text.setBackground(new Color(display, text.getBackground().getRGB(), alpha));
+ if (transparent){
+ composite.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ buttonCheckBox.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ bar.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ list.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ label.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ // radio widget have custom background
+ radio.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ check.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+// check.setBackgroundImage(getBackgroundImage(display));
+ push.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ text.setBackground(display.getSystemColor(SWT.COLOR_TRANSPARENT));
+ }
+ else {
+ composite.setBackground(display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND));
+ radio.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
+ check.setBackgroundImage(getBackgroundImage(display));
+ }
}
@Override
@@ -117,15 +123,7 @@ public class Snippet365 {
check.setText("Check box Button");
check.setSelection(true);
// Image
- Rectangle rect = new Rectangle(0, 0, 115, 5);
- Image newImage = new Image(display, Math.max(1, rect.width), 1);
- GC gc = new GC(newImage);
- gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
- gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
- gc.fillGradientRectangle(rect.x, rect.y, rect.width, 1, false);
- gc.dispose();
- shell.setBackgroundImage(newImage);
- check.setBackgroundImage(newImage);
+ check.setBackgroundImage(getBackgroundImage(display));
push = new Button(composite, SWT.PUSH);
push.setText("Push Button");
@@ -143,4 +141,17 @@ public class Snippet365 {
display.dispose();
}
+ private static Image getBackgroundImage(final Display display) {
+ if (newImage == null) {
+ Rectangle rect = new Rectangle(0, 0, 115, 5);
+ newImage = new Image(display, Math.max(1, rect.width), 1);
+ GC gc = new GC(newImage);
+ gc.setForeground(display.getSystemColor(SWT.COLOR_WHITE));
+ gc.setBackground(display.getSystemColor(SWT.COLOR_RED));
+ gc.fillGradientRectangle(rect.x, rect.y, rect.width, 1, false);
+ gc.dispose();
+ }
+ return newImage;
+ }
+
}
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Color.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Color.java
index f88ac86871..fe4afa379a 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Color.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_graphics_Color.java
@@ -219,11 +219,11 @@ public void test_isDisposed() {
}
public void test_toString() {
- Color color = new Color(display, 0, 0, 255);
+ Color color = new Color(display, 0, 0, 255, 255);
try {
assertNotNull(color.toString());
assertTrue(color.toString().length() > 0);
- assertEquals("Color {0, 0, 255}", color.toString());
+ assertEquals("Color {0, 0, 255, 255}", color.toString());
} finally {
color.dispose();
}

Back to the top