diff options
author | Steve Northover <steve> | 2007-10-26 22:40:09 +0000 |
---|---|---|
committer | Steve Northover <steve> | 2007-10-26 22:40:09 +0000 |
commit | 1f0268d817d4d6da6a35f97f46ada77b8aa2e671 (patch) | |
tree | 27f843aa6d40666c5a0ce9b68b487d92c0de66c7 /bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse | |
parent | 0354f2fcd681774fe492f4e3d5f23f1a78e0b89a (diff) | |
download | eclipse.platform.swt-1f0268d817d4d6da6a35f97f46ada77b8aa2e671.tar.gz eclipse.platform.swt-1f0268d817d4d6da6a35f97f46ada77b8aa2e671.tar.xz eclipse.platform.swt-1f0268d817d4d6da6a35f97f46ada77b8aa2e671.zip |
206095 - DCR - possibility to print the contents of SWT widgets, 168979 - transparent shell, alpha in shell, Control.setRegion()
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse')
6 files changed, 122 insertions, 29 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java index fb888e3914..29e64c8c43 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java @@ -177,6 +177,13 @@ static int checkStyle (int style) { return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT); } +public static GC gtk_new(int handle, GCData data) { + GC gc = new GC(); + gc.device = data.device; + gc.init(null, data, handle); + return gc; +} + public static GC gtk_new(Drawable drawable, GCData data) { GC gc = new GC(); int /*long*/ gdkGC = drawable.internal_new_GC(data); @@ -561,8 +568,9 @@ public void dispose() { /* Dispose the GC */ Device device = data.device; - drawable.internal_dispose_GC(handle, data); - + if (drawable != null) { + drawable.internal_dispose_GC(handle, data); + } data.drawable = data.clipRgn = 0; drawable = null; handle = 0; @@ -1025,7 +1033,7 @@ void drawImageMask(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeig void drawImageXRender(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int /*long*/ maskPixmap, int maskType) { int translateX = 0, translateY = 0; int /*long*/ drawable = data.drawable; - if (data.image == null) { + if (data.image == null && !data.realDrawable) { int[] x = new int[1], y = new int[1]; int /*long*/ [] real_drawable = new int /*long*/ [1]; OS.gdk_window_get_internal_paint_info(drawable, real_drawable, x, y); @@ -2792,12 +2800,14 @@ void initCairo() { if (data.image != null) { xDrawable = OS.GDK_PIXMAP_XID(drawable); } else { - int[] x = new int[1], y = new int[1]; - int /*long*/ [] real_drawable = new int /*long*/ [1]; - OS.gdk_window_get_internal_paint_info(drawable, real_drawable, x, y); - xDrawable = OS.gdk_x11_drawable_get_xid(real_drawable[0]); - translateX = -x[0]; - translateY = -y[0]; + if (!data.realDrawable) { + int[] x = new int[1], y = new int[1]; + int /*long*/ [] real_drawable = new int /*long*/ [1]; + OS.gdk_window_get_internal_paint_info(drawable, real_drawable, x, y); + xDrawable = OS.gdk_x11_drawable_get_xid(real_drawable[0]); + translateX = -x[0]; + translateY = -y[0]; + } } int[] w = new int[1], h = new int[1]; OS.gdk_drawable_get_size(drawable, w, h); diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GCData.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GCData.java index bbc4898e2c..33fbf02568 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GCData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GCData.java @@ -57,4 +57,5 @@ public final class GCData { public int stringWidth = -1; public int stringHeight = -1; public int drawFlags; + public boolean realDrawable; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java index 257747a9fa..3495504c96 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java @@ -68,7 +68,7 @@ Canvas () {} * @see Widget#getStyle */ public Canvas (Composite parent, int style) { - super (parent, style); + super (parent, checkStyle (style)); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java index efe87cb856..162123d9d6 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java @@ -89,7 +89,12 @@ Composite () { * @see Widget#getStyle */ public Composite (Composite parent, int style) { - super (parent, style); + super (parent, checkStyle (style)); +} + +static int checkStyle (int style) { + style &= ~SWT.TRANSPARENT; + return style; } Control [] _getChildren () { @@ -1117,16 +1122,32 @@ int /*long*/ parentingHandle () { return fixedHandle != 0 ? fixedHandle : handle; } -void printWidget (int gc, int drawable, int depth, int x, int y) { +void printWidget (GC gc, int /*long*/ drawable, int depth, int x, int y) { + Region oldClip = new Region (gc.getDevice ()); + Region newClip = new Region (gc.getDevice ()); + gc.getClipping (oldClip); + Rectangle rect = getBounds (); + newClip.add (oldClip); + newClip.intersect (x, y, rect.width, rect.height); + gc.setClipping (newClip); super.printWidget (gc, drawable, depth, x, y); + Rectangle clientRect = getClientArea (); + Point pt = display.map (this, parent, clientRect.x, clientRect.y); + clientRect.x = x + pt.x - rect.x; + clientRect.y = y + pt.y - rect.y; + newClip.intersect (clientRect); + gc.setClipping (newClip); Control [] children = _getChildren (); - for (int i=children.length-1; i>= 0; --i) { + for (int i=children.length-1; i>=0; --i) { Control child = children [i]; if (child.getVisible ()) { Point location = child.getLocation (); child.printWidget (gc, drawable, depth, x + location.x, y + location.y); } } + gc.setClipping (oldClip); + oldClip.dispose (); + newClip.dispose (); } void redrawChildren () { 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 1924747fea..773bb46569 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 @@ -46,6 +46,7 @@ public abstract class Control extends Widget implements Drawable { Menu menu; Image backgroundImage; Font font; + Region region; String toolTipText; Object layoutData; Accessible accessible; @@ -279,29 +280,29 @@ int /*long*/ paintWindow () { return OS.GTK_WIDGET_WINDOW (paintHandle); } -/*public*/ boolean print (GC gc) { +public boolean print (GC gc) { checkWidget (); if (gc == null) error (SWT.ERROR_NULL_ARGUMENT); if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); int /*long*/ topHandle = topHandle (); OS.gtk_widget_realize (topHandle); int /*long*/ window = OS.GTK_WIDGET_WINDOW (topHandle); - OS.gdk_window_process_updates (window, true); GCData data = gc.getGCData (); - printWidget (gc.handle, data.drawable, OS.gdk_drawable_get_depth (data.drawable), 0, 0); + OS.gdk_window_process_updates (window, true); + printWidget (gc, data.drawable, OS.gdk_drawable_get_depth (data.drawable), 0, 0); return true; } -void printWidget (int /*long*/ gc, int /*long*/ drawable, int depth, int x, int y) { +void printWidget (GC gc, int /*long*/ drawable, int depth, int x, int y) { boolean obscured = (state & OBSCURED) != 0; state &= ~OBSCURED; int /*long*/ topHandle = topHandle (); int /*long*/ window = OS.GTK_WIDGET_WINDOW (topHandle); - printWindow (this, gc, drawable, depth, window, x, y); + printWindow (true, this, gc.handle, drawable, depth, window, x, y); if (obscured) state |= OBSCURED; } -void printWindow (Control control, int /*long*/ gc, int /*long*/ drawable, int depth, int /*long*/ window, int x, int y) { +void printWindow (boolean first, Control control, int /*long*/ gc, int /*long*/ drawable, int depth, int /*long*/ window, int x, int y) { if (OS.gdk_drawable_get_depth (window) != depth) return; GdkRectangle rect = new GdkRectangle (); int [] width = new int [1], height = new int [1]; @@ -314,7 +315,55 @@ void printWindow (Control control, int /*long*/ gc, int /*long*/ drawable, int int /*long*/ [] real_drawable = new int /*long*/ [1]; int [] x_offset = new int [1], y_offset = new int [1]; OS.gdk_window_get_internal_paint_info (window, real_drawable, x_offset, y_offset); - OS.gdk_draw_drawable (drawable, gc, real_drawable [0], x_offset [0], y_offset [0], x, y, width [0], height [0]); + if (window == paintWindow ()) { + if (hooks (SWT.Paint) || filters (SWT.Paint)) { + GCData data = new GCData (); + int /*long*/ gdkGC = OS.gdk_gc_new (real_drawable [0]); + if (gdkGC == 0) error (SWT.ERROR_NO_HANDLES); + if (data != null) { + int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT; + if ((data.style & mask) == 0) { + data.style |= style & (mask | SWT.MIRRORED); + } else { + if ((data.style & SWT.RIGHT_TO_LEFT) != 0) { + data.style |= SWT.MIRRORED; + } + } + data.realDrawable = true; + data.drawable = real_drawable [0]; + data.device = display; + data.foreground = getForegroundColor (); + Control backgroundControl = findBackgroundControl (); + if (backgroundControl == null) backgroundControl = this; + data.background = backgroundControl.getBackgroundColor (); + data.font = font != null ? font.handle : defaultFont (); + } + Event event = new Event (); + event.width = width [0]; + event.height = height [0]; + if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.width - event.x; + GC paintGC = event.gc = GC.gtk_new (gdkGC, data); + sendEvent (SWT.Paint, event); + paintGC.dispose (); + OS.g_object_unref (gdkGC); + } + } + int srcX = x_offset [0], srcY = y_offset [0]; + int destX = x, destY = y, destWidth = width [0], destHeight = height [0]; + if (!first) { + int [] cX = new int [1], cY = new int [1]; + OS.gdk_window_get_position (window, cX, cY); + int /*long*/ parentWindow = OS.gdk_window_get_parent (window); + int [] pW = new int [1], pH = new int [1]; + OS.gdk_drawable_get_size (parentWindow, pW, pH); + srcX = x_offset [0] - cX [0]; + srcY = y_offset [0] - cY [0]; + destX = x - cX [0]; + destY = y - cY [0]; + destWidth = Math.min (cX [0] + width [0], pW [0]); + destHeight = Math.min (cY [0] + height [0], pH [0]); + } + OS.gdk_draw_drawable (drawable, gc, real_drawable [0], srcX, srcY, destX, destY, destWidth, destHeight); OS.gdk_window_end_paint (window); int /*long*/ children = OS.gdk_window_get_children (window); if (children != 0) { @@ -329,7 +378,7 @@ void printWindow (Control control, int /*long*/ gc, int /*long*/ drawable, int if (widget == null || widget == control) { int [] x_pos = new int [1], y_pos = new int [1]; OS.gdk_window_get_position (child, x_pos, y_pos); - printWindow (control, gc, drawable, depth, child, x + x_pos [0], y + y_pos [0]); + printWindow (false, control, gc, drawable, depth, child, x + x_pos [0], y + y_pos [0]); } } } @@ -883,6 +932,16 @@ public void setSize (Point size) { setBounds (0, 0, Math.max (0, size.x), Math.max (0, size.y), false, true); } +public void setRegion (Region region) { + checkWidget (); + if ((style & SWT.NO_TRIM) == 0) return; + if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); + int /*long*/ window = OS.GTK_WIDGET_WINDOW (topHandle ()); + int /*long*/ shape_region = (region == null) ? 0 : region.handle; + OS.gdk_window_shape_combine_region (window, shape_region, 0, 0); + this.region = region; +} + void setRelations () { int /*long*/ parentHandle = parent.parentingHandle (); int /*long*/ list = OS.gtk_container_get_children (parentHandle); @@ -2330,6 +2389,11 @@ Control [] getPath () { return result; } +public Region getRegion () { + checkWidget (); + return region; +} + /** * Returns the receiver's shell. For all controls other than * shells, this simply returns the control's nearest ancestor @@ -2558,7 +2622,7 @@ int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) { } return 0; } - + int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ eventPtr) { if ((state & OBSCURED) != 0) return 0; if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0; @@ -3128,6 +3192,7 @@ void releaseWidget () { toolTipText = null; layoutData = null; accessible = null; + region = null; } boolean sendDragEvent (int button, int stateMask, int x, int y, boolean isStateMask) { diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java index c4221f6126..b4ffa95501 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java @@ -119,7 +119,6 @@ public class Shell extends Decorations { int oldX, oldY, oldWidth, oldHeight; int minWidth, minHeight; Control lastActive; - Region region; static final int MAXIMUM_TRIM = 128; @@ -355,6 +354,7 @@ public static Shell internal_new (Display display, int /*long*/ handle) { static int checkStyle (int style) { style = Decorations.checkStyle (style); + style &= ~SWT.TRANSPARENT; if ((style & SWT.ON_TOP) != 0) style &= ~SWT.SHELL_TRIM; int mask = SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.PRIMARY_MODAL; int bits = style & ~mask; @@ -894,6 +894,7 @@ public boolean getVisible () { */ public Region getRegion () { checkWidget (); + /* This method is needed for @since 3.0 Javadoc */ return region; } @@ -1507,11 +1508,7 @@ public void setMinimumSize (Point size) { public void setRegion (Region region) { checkWidget (); if ((style & SWT.NO_TRIM) == 0) return; - if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle); - int /*long*/ shape_region = (region == null) ? 0 : region.handle; - OS.gdk_window_shape_combine_region (window, shape_region, 0, 0); - this.region = region; + super.setRegion (region); } /* @@ -1836,7 +1833,6 @@ void releaseWidget () { group = modalGroup = 0; int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle); OS.gdk_window_remove_filter(window, display.filterProc, shellHandle); - region = null; lastActive = null; } |