summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSilenio Quarti <silenio>2008-06-16 16:01:35 +0000
committerSilenio Quarti <silenio>2008-06-16 16:01:35 +0000
commit46ff5fc529ab224d85a7cd4cf117fa05d3afee3b (patch)
treef39aee5b02bedfe9fade22c2ea59ee287a256fd7
parentaa9b2291ca5b2b9f9d4fccc92c979ab026d9b0e9 (diff)
downloadeclipse.platform.swt-46ff5fc529ab224d85a7cd4cf117fa05d3afee3b.tar.gz
eclipse.platform.swt-46ff5fc529ab224d85a7cd4cf117fa05d3afee3b.tar.xz
eclipse.platform.swt-46ff5fc529ab224d85a7cd4cf117fa05d3afee3b.zip
setBackgroundImage in composites
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Canvas.java7
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java13
-rwxr-xr-xbundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Control.java28
3 files changed, 36 insertions, 12 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Canvas.java
index b8e0041df9..363a4696ee 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Canvas.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Canvas.java
@@ -114,7 +114,12 @@ public void drawBackground (GC gc, int x, int y, int width, int height) {
if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
Control control = findBackgroundControl ();
if (control != null) {
-// control.fillBackground (handle, gc.handle, new Rectangle (x, y, width, height));
+ NSRect rect = new NSRect();
+ rect.x = x;
+ rect.y = y;
+ rect.width = width;
+ rect.height = height;
+ control.fillBackground (view, gc.handle, rect);
} else {
gc.fillRectangle (x, y, width, height);
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java
index c75ec31318..436f8a293a 100755
--- a/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/cocoa/org/eclipse/swt/widgets/Composite.java
@@ -250,17 +250,8 @@ void createHandle () {
void drawRect (int id, NSRect rect) {
if ((state & CANVAS) != 0) {
if ((style & SWT.NO_BACKGROUND) == 0) {
- Control control = findBackgroundControl();
- if (control == null) control = this;
- Color background = control.background;
- if (background != null && !background.isDisposed ()) {
- float [] color = background.handle;
- NSGraphicsContext context = NSGraphicsContext.currentContext();
- context.saveGraphicsState();
- NSColor.colorWithDeviceRed(color [0], color [1], color [2], color [3]).setFill();
- NSBezierPath.fillRect(rect);
- context.restoreGraphicsState();
- }
+ NSGraphicsContext context = NSGraphicsContext.currentContext();
+ fillBackground (view, context, rect);
}
}
super.drawRect (id, rect);
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 265ad8aca7..35d301a762 100755
--- 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
@@ -789,6 +789,34 @@ void enableWidget (boolean enabled) {
}
}
+void fillBackground (NSView view, NSGraphicsContext context, NSRect rect) {
+ Control control = findBackgroundControl();
+ if (control == null) control = this;
+ Image image = control.backgroundImage;
+ if (image != null && !image.isDisposed()) {
+ context.saveGraphicsState();
+ NSColor.colorWithPatternImage(image.handle).setFill();
+ NSPoint phase = new NSPoint();
+ NSView controlView = control.view;
+ NSView contentView = controlView.window().contentView();
+ phase = controlView.convertPoint_toView_(phase, contentView);
+ phase.y = contentView.bounds().height - phase.y;
+ context.setPatternPhase(phase);
+ NSBezierPath.fillRect(rect);
+ context.restoreGraphicsState();
+ return;
+ }
+ Color background = control.background;
+ if (background != null && !background.isDisposed ()) {
+ float [] color = background.handle;
+ context.saveGraphicsState();
+ NSColor.colorWithDeviceRed(color [0], color [1], color [2], color [3]).setFill();
+ NSBezierPath.fillRect(rect);
+ context.restoreGraphicsState();
+ return;
+ }
+}
+
Cursor findCursor () {
if (cursor != null) return cursor;
return parent.findCursor ();