From 550305c15fce921bf2dc58fcd38c5b63e8c60d71 Mon Sep 17 00:00:00 2001 From: "ho.namkoong" Date: Mon, 10 Dec 2012 01:47:40 +0900 Subject: [PATCH] [Title] implement makeChildBackgroundTransient method [Type] [Module] [Priority] [Jira#] [Redmine#] 7625 [Problem] [Cause] [Solution] [TestCase] Change-Id: I40eb49f4cc105a5c371adf19ffe90bc3ea21c916 --- .../src/org/tizen/common/util/SWTUtil.java | 73 ++++++++++++++++++++++ 1 file changed, 73 insertions(+) diff --git a/org.tizen.common/src/org/tizen/common/util/SWTUtil.java b/org.tizen.common/src/org/tizen/common/util/SWTUtil.java index 6da335f..4e2f9bb 100755 --- a/org.tizen.common/src/org/tizen/common/util/SWTUtil.java +++ b/org.tizen.common/src/org/tizen/common/util/SWTUtil.java @@ -35,6 +35,7 @@ import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Stack; +import java.util.concurrent.atomic.AtomicBoolean; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -50,8 +51,13 @@ import org.eclipse.jface.layout.PixelConverter; import org.eclipse.jface.resource.JFaceResources; import org.eclipse.swt.SWT; import org.eclipse.swt.custom.ScrolledComposite; +import org.eclipse.swt.events.PaintEvent; +import org.eclipse.swt.events.PaintListener; import org.eclipse.swt.events.VerifyEvent; import org.eclipse.swt.events.VerifyListener; +import org.eclipse.swt.graphics.GC; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.graphics.Point; import org.eclipse.swt.graphics.Resource; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; @@ -567,5 +573,72 @@ public class SWTUtil { int widthHint= converter.convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH); return Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); } + + /** + * make background image of child control transient. + * Actually, it just copy parent image and paint it to the child background. + * Also, it works only when background of parent is image + * + * @param parent parent composite + * @param child child control + */ + public static void makeChildBackgroundTransient(final Composite parent) { + if(parent != null) { + final Object lock = new Object(); + final AtomicBoolean finished = new AtomicBoolean(false); + parent.addPaintListener(new PaintListener() { + + class PairControl { + + PairControl(Composite parent, Control child) { + this.parent = parent; + this.child = child; + } + Composite parent; + Control child; + } + + @Override + public void paintControl(PaintEvent e) { + if(finished.get()) { + return; + } + synchronized (lock) { + finished.set(true); + parent.removePaintListener(this); + if(parent.getBackgroundImage() != null) { + + Stack childStack = new Stack(); + + for(Control childControl: parent.getChildren()) { + childStack.add(new PairControl(parent, childControl)); + } + + while(!childStack.isEmpty()) { + PairControl pair = childStack.pop(); + Control childControl = pair.child; + Composite parentComposite = pair.parent; + Image parentImage = parentComposite.getBackgroundImage(); + Point childLoc = childControl.getLocation(); + + if(childControl instanceof Composite) { + Composite childComposite = ((Composite)childControl); + for(Control grandChildControl: childComposite.getChildren()) { + childStack.push(new PairControl(childComposite, grandChildControl)); + } + } + Point childSize = childControl.getSize(); + Image childImage = new Image(SWTUtil.getDisplay(), childSize.x, childSize.y); + GC gc = new GC(parentImage); + gc.copyArea(childImage, childLoc.x, childLoc.y); + gc.dispose(); + childControl.setBackgroundImage(childImage); + } + } + } + } + }); + } + } } -- 2.7.4