Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNiraj Modi2014-12-24 08:27:53 +0000
committerNiraj Modi2014-12-24 08:27:53 +0000
commit6e1d6eedfff225a770ce5358020d4025b0a296df (patch)
treedf0ea9cb6481b840c7c29ca8b5e7ba663ac16f63
parent21f50fb563fbe509616757d9da699caae0c1911b (diff)
downloadeclipse.platform.swt-6e1d6eedfff225a770ce5358020d4025b0a296df.tar.gz
eclipse.platform.swt-6e1d6eedfff225a770ce5358020d4025b0a296df.tar.xz
eclipse.platform.swt-6e1d6eedfff225a770ce5358020d4025b0a296df.zip
Bug 435384 - Add support for 'transparent' colors
- Code refactored to remove transparentBackground & transparentBackgroundImage in Linux & Mac - Windows refactoring continued for the same. Change-Id: Ibcdf0dd710cb1a0c7e76ecdce6d7a124ee1316ef Signed-off-by: Niraj Modi <niraj.modi@in.ibm.com>
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java43
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java47
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Control.java23
-rw-r--r--examples/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet365.java9
4 files changed, 44 insertions, 78 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java
index 07931bdd0d..f99507d4b9 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java
@@ -60,8 +60,8 @@ public abstract class Control extends Widget implements Drawable {
Object layoutData;
int drawCount, backgroundAlpha = 255;
Menu menu;
- double /*float*/ [] foreground, background, transparentBackground;
- Image backgroundImage, transparentBackgroundImage;
+ double /*float*/ [] foreground, background;
+ Image backgroundImage;
Font font;
Cursor cursor;
Region region;
@@ -1326,7 +1326,7 @@ Cursor findCursor () {
}
Control findBackgroundControl () {
- if (backgroundImage != null || background != null) return this;
+ if ((backgroundImage != null || background != null) && backgroundAlpha > 0) return this;
return (!isTransparent() && (state & PARENT_BACKGROUND) != 0) ? parent.findBackgroundControl () : null;
}
@@ -1547,7 +1547,7 @@ public Accessible getAccessible () {
public Color getBackground () {
checkWidget();
if (backgroundAlpha == 0) {
- Color color = Color.cocoa_new (display, transparentBackground, 0);
+ Color color = Color.cocoa_new (display, background, 0);
return color;
}
else {
@@ -1558,7 +1558,7 @@ public Color getBackground () {
}
Color getBackgroundColor () {
- return background != null ? Color.cocoa_new (display, background) : defaultBackground ();
+ return background != null ? Color.cocoa_new (display, background, backgroundAlpha) : defaultBackground ();
}
/**
@@ -1575,14 +1575,9 @@ Color getBackgroundColor () {
*/
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;
}
/**
@@ -3488,7 +3483,7 @@ public void setBackground (Color color) {
checkWidget ();
_setBackground (color);
if (color != null) {
- setBackgroundTransparency (color.getAlpha ());
+ this.updateBackgroundMode ();
}
}
@@ -3497,28 +3492,14 @@ private void _setBackground (Color color) {
if (color.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
}
double /*float*/ [] background = color != null ? color.handle : null;
- if (equals (background, this.background)) return;
+ int alpha = color != null ? color.getAlpha() : 255;
+ if (equals (background, this.background) && alpha == this.backgroundAlpha) return;
this.background = background;
+ this.backgroundAlpha = alpha;
updateBackgroundColor ();
redrawWidget(view, true);
}
-private void setBackgroundTransparency (int alpha) {
- if (alpha == 0) {
- // clear background
- if (backgroundImage != null) {
- transparentBackgroundImage = getBackgroundImage ();
- setBackgroundImage (null);
- }
- if (getBackground () != null) {
- transparentBackground = background;
- _setBackground (null);
- }
- }
- this.backgroundAlpha = alpha;
- this.updateBackgroundMode ();
-}
-
/**
* Sets the receiver's background image to the image specified
* by the argument, or to the default system color for the control
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
index b755151ced..135f3b653f 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java
@@ -50,8 +50,7 @@ public abstract class Control extends Widget implements Drawable {
Composite parent;
Cursor cursor;
Menu menu;
- Image backgroundImage, transparentBackgroundImage;
- GdkColor transparentBackground;
+ Image backgroundImage;
Font font;
Region region;
String toolTipText;
@@ -2392,7 +2391,7 @@ boolean filterKey (int keyval, long /*int*/ event) {
}
Control findBackgroundControl () {
- if ((state & BACKGROUND) != 0 || backgroundImage != null) return this;
+ if (((state & BACKGROUND) != 0 || backgroundImage != null) && backgroundAlpha > 0) return this;
return (state & PARENT_BACKGROUND) != 0 ? parent.findBackgroundControl () : null;
}
@@ -2495,13 +2494,13 @@ boolean forceFocus (long /*int*/ focusHandle) {
public Color getBackground () {
checkWidget();
if (backgroundAlpha == 0) {
- Color color = Color.gtk_new (display, transparentBackground, 0);
+ Color color = Color.gtk_new (display, this.getBackgroundColor (), 0);
return color;
}
else {
Control control = findBackgroundControl ();
if (control == null) control = this;
- return Color.gtk_new (display, control.getBackgroundColor ());
+ return Color.gtk_new (display, control.getBackgroundColor (), backgroundAlpha);
}
}
@@ -2523,14 +2522,9 @@ GdkColor getBackgroundColor () {
*/
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;
}
GdkColor getContextBackground () {
@@ -4016,7 +4010,7 @@ public void setBackground (Color color) {
checkWidget ();
_setBackground (color);
if (color != null) {
- setBackgroundTransparency (color.getAlpha ());
+ this.updateBackgroundMode ();
}
}
@@ -4026,6 +4020,7 @@ private void _setBackground (Color color) {
if (color != null) {
if (color.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
gdkColor = color.handle;
+ backgroundAlpha = color.getAlpha ();
}
boolean set = false;
if (OS.GTK3) {
@@ -4054,22 +4049,6 @@ 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 = getBackground ().handle;
- _setBackground (null);
- }
- }
- this.backgroundAlpha = alpha;
- this.updateBackgroundMode ();
-}
-
void setBackgroundColor (long /*int*/ context, long /*int*/ handle, GdkRGBA rgba) {
OS.gtk_widget_override_background_color (handle, OS.GTK_STATE_FLAG_NORMAL, rgba);
}
@@ -4101,9 +4080,12 @@ void setBackgroundColor (long /*int*/ handle, GdkColor color) {
color = control.getBackgroundColor();
}
}
+ else {
+ alpha = backgroundAlpha;
+ }
if (color != null) {
rgba = new GdkRGBA ();
- rgba.alpha = alpha;
+ rgba.alpha = alpha / (float)255;
rgba.red = (color.red & 0xFFFF) / (float)0xFFFF;
rgba.green = (color.green & 0xFFFF) / (float)0xFFFF;
rgba.blue = (color.blue & 0xFFFF) / (float)0xFFFF;
@@ -4171,7 +4153,8 @@ void setBackgroundColor (GdkColor color) {
public void setBackgroundImage (Image image) {
checkWidget ();
if (image != null && image.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (image == backgroundImage) return;
+ if (image == backgroundImage && backgroundAlpha > 0) return;
+ backgroundAlpha = 255;
this.backgroundImage = image;
if (backgroundImage != null) {
setBackgroundPixmap (backgroundImage);
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 b76c2393a3..92c78d2133 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
@@ -1166,9 +1166,15 @@ public Accessible getAccessible () {
*/
public Color getBackground () {
checkWidget ();
- Control control = findBackgroundControl ();
- if (control == null) control = this;
- return Color.win32_new (display, control.getBackgroundPixel (), backgroundAlpha);
+ if (backgroundAlpha == 0) {
+ Color color = Color.win32_new (display, background, 0);
+ return color;
+ }
+ else {
+ Control control = findBackgroundControl ();
+ if (control == null) control = this;
+ return Color.win32_new (display, control.getBackgroundPixel (), backgroundAlpha);
+ }
}
/**
@@ -3010,25 +3016,24 @@ public void setBackground (Color color) {
checkWidget ();
_setBackground (color);
if (color != null) {
- setBackgroundTransparency (color.getAlpha());
+ this.updateBackgroundMode ();
}
}
private void _setBackground (Color color) {
int pixel = -1;
+ int alpha = 255;
if (color != null) {
if (color.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
pixel = color.handle;
+ alpha = color.getAlpha();
}
- if (pixel == background) return;
+ if (pixel == background && alpha == backgroundAlpha) return;
background = pixel;
+ backgroundAlpha = alpha;
updateBackgroundColor ();
}
-private void setBackgroundTransparency (int alpha) {
- this.backgroundAlpha = alpha;
- this.updateBackgroundMode ();
-}
/**
* Sets the receiver's background image to the image specified
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 d3a73745ee..950e6dd13d 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
@@ -75,22 +75,19 @@ public class Snippet365 {
@Override
public void widgetSelected(SelectionEvent e) {
boolean transparent = ((Button) e.getSource()).getSelection();
- int alpha = transparent ? 0 : 255;
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));
+ buttonCheckBox.setBackground(null);
+ bar.setBackground(null);
+ label.setBackground(null);
radio.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
check.setBackgroundImage(getBackgroundImage(display));
}

Back to the top