1609
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of the License "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
package com.nokia.carbide.internal.discovery.ui.editor;
|
|
18 |
|
|
19 |
import org.eclipse.swt.SWT;
|
|
20 |
import org.eclipse.swt.events.PaintEvent;
|
|
21 |
import org.eclipse.swt.events.PaintListener;
|
|
22 |
import org.eclipse.swt.graphics.GC;
|
|
23 |
import org.eclipse.swt.graphics.Image;
|
|
24 |
import org.eclipse.swt.graphics.Rectangle;
|
|
25 |
import org.eclipse.swt.widgets.Canvas;
|
|
26 |
import org.eclipse.swt.widgets.Composite;
|
|
27 |
|
|
28 |
class SharedBackgroundComposite extends Canvas {
|
|
29 |
|
|
30 |
private final Composite backgroundParent;
|
|
31 |
|
|
32 |
public SharedBackgroundComposite(Composite parent, Composite backgroundParent) {
|
|
33 |
super(parent, SWT.NO_BACKGROUND);
|
|
34 |
this.backgroundParent = backgroundParent;
|
|
35 |
addPaintListener(new PaintListener() {
|
|
36 |
@Override
|
|
37 |
public void paintControl(PaintEvent e) {
|
|
38 |
Rectangle b = getBounds();
|
|
39 |
drawBackground(e.gc, b.x, b.y, b.width, b.height);
|
|
40 |
}
|
|
41 |
});
|
|
42 |
}
|
|
43 |
|
|
44 |
@Override
|
|
45 |
public void drawBackground(GC gc, int x, int y, int width, int height) {
|
|
46 |
Composite relParent = getParent();
|
|
47 |
while (relParent != backgroundParent) {
|
|
48 |
Rectangle relB = relParent.getBounds();
|
|
49 |
x += relB.x;
|
|
50 |
y += relB.y;
|
|
51 |
relParent = relParent.getParent();
|
|
52 |
}
|
|
53 |
|
|
54 |
Image image = backgroundParent.getBackgroundImage();
|
|
55 |
Rectangle imageBounds = image.getBounds();
|
|
56 |
width = Math.min(width, imageBounds.width - x);
|
|
57 |
height = Math.min(height, imageBounds.height - y);
|
|
58 |
if (width > 0 && height > 0)
|
|
59 |
gc.drawImage(image, x, y, width, height, 0, 0, width, height);
|
1618
|
60 |
// gc.drawText(getClass().getSimpleName(), 2, 2);
|
1609
|
61 |
// gc.setForeground(gc.getDevice().getSystemColor(SWT.COLOR_WHITE));
|
|
62 |
// gc.drawRectangle(1, 1, width - 2, height - 2);
|
|
63 |
}
|
|
64 |
|
|
65 |
}
|