# HG changeset patch # User Frank Benoit # Date 1199666993 -3600 # Node ID 4db14dc0bc45fed76eca425e3786cf088f2e6faa # Parent 0a61cfe9ff237391a510ae768a95b6230684aad2 first graphics with gdk/gtk deps diff -r 0a61cfe9ff23 -r 4db14dc0bc45 dsss.conf --- a/dsss.conf Mon Jan 07 00:12:43 2008 +0100 +++ b/dsss.conf Mon Jan 07 01:49:53 2008 +0100 @@ -1,3 +1,4 @@ [dwt] type=library +exclude=dwt/internal/gtk/OS.d diff -r 0a61cfe9ff23 -r 4db14dc0bc45 dwt/graphics/Color.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/graphics/Color.d Mon Jan 07 01:49:53 2008 +0100 @@ -0,0 +1,306 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +module dwt.graphics.Color; + + +import dwt.SWT; +import dwt.internal.gtk.OS; +import dwt.internal.gtk.c.gdktypes : GdkColor, GdkColormap; +import dwt.graphics.Resource; +import dwt.graphics.RGB; + +import tango.text.convert.Format; + + +/** + * Instances of this class manage the operating system resources that + * implement SWT's RGB color model. To create a color you can either + * specify the individual color components as integers in the range + * 0 to 255 or provide an instance of an RGB. + *

+ * Application code must explicitly invoke the Color.dispose() + * method to release the operating system resources managed by each instance + * when those instances are no longer required. + *

+ * + * @see RGB + * @see Device#getSystemColor + */ +public final class Color : Resource { + /** + * the handle to the OS color resource + * (Warning: This field is platform dependent) + *

+ * IMPORTANT: This field is not part of the SWT + * public API. It is marked public only so that it can be shared + * within the packages provided by SWT. It is not available on all + * platforms and should never be accessed from application code. + *

+ */ + public GdkColor* handle; + +this() { +} + +/** + * Constructs a new instance of this class given a device and the + * desired red, green and blue values expressed as ints in the range + * 0 to 255 (where 0 is black and 255 is full brightness). On limited + * color devices, the color instance created by this call may not have + * the same RGB values as the ones specified by the arguments. The + * RGB values on the returned instance will be the color values of + * the operating system color. + *

+ * You must dispose the color when it is no longer required. + *

+ * + * @param device the device on which to allocate the color + * @param red the amount of red in the color + * @param green the amount of green in the color + * @param blue the amount of blue in the color + * + * @exception IllegalArgumentException + * + * @see #dispose + */ +public this(Device device, int red, int green, int blue) { + if (device is null) device = Device.getDevice(); + if (device is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + init(device, red, green, blue); + if (device.tracking) device.new_Object(this); +} + +/** + * Constructs a new instance of this class given a device and an + * RGB describing the desired red, green and blue values. + * On limited color devices, the color instance created by this call + * may not have the same RGB values as the ones specified by the + * argument. The RGB values on the returned instance will be the color + * values of the operating system color. + *

+ * You must dispose the color when it is no longer required. + *

+ * + * @param device the device on which to allocate the color + * @param rgb the RGB values of the desired color + * + * @exception IllegalArgumentException + * + * @see #dispose + */ +public this(Device device, RGB rgb) { + if (device is null) device = Device.getDevice(); + if (device is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (rgb is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + init(device, rgb.red, rgb.green, rgb.blue); + if (device.tracking) device.new_Object(this); +} + +/** + * Disposes of the operating system resources associated with + * the color. Applications must dispose of all colors which + * they allocate. + */ +public void dispose() { + if (handle is null) return; + if (device.isDisposed()) return; + int pixel = handle.pixel; + if (device.colorRefCount !is null) { + /* If this was the last reference, remove the color from the list */ + if (--device.colorRefCount[pixel] == 0) { + device.gdkColors[pixel] = null; + } + } + auto colormap = OS.gdk_colormap_get_system(); + OS.gdk_colormap_free_colors(colormap, handle, 1); + handle = null; + if (device.tracking) device.dispose_Object(this); + device = null; +} + +/** + * Compares the argument to the receiver, and returns true + * if they represent the same object using a class + * specific comparison. + * + * @param object the object to compare with this object + * @return true if the object is the same as this object and false otherwise + * + * @see #hashCode + */ +public int opEquals(Object object) { + if (object is this) return true; + if ( auto color = cast(Color)object ){ + GdkColor* gdkColor = color.handle; + if (handle == gdkColor) return true; + return device == color.device && handle.red == gdkColor.red && + handle.green == gdkColor.green && handle.blue == gdkColor.blue; + } + return false; +} + +/** + * Returns the amount of blue in the color, from 0 to 255. + * + * @return the blue component of the color + * + * @exception SWTException + */ +public int getBlue() { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return (handle.blue >> 8) & 0xFF; +} + +/** + * Returns the amount of green in the color, from 0 to 255. + * + * @return the green component of the color + * + * @exception SWTException + */ +public int getGreen() { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return (handle.green >> 8) & 0xFF; +} + +/** + * Returns the amount of red in the color, from 0 to 255. + * + * @return the red component of the color + * + * @exception SWTException + */ +public int getRed() { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return (handle.red >> 8) & 0xFF; +} + +/** + * Returns an integer hash code for the receiver. Any two + * objects that return true when passed to + * equals must return the same value for this + * method. + * + * @return the receiver's hash + * + * @see #equals + */ +public int hashCode() { + if (isDisposed()) return 0; + return handle.red ^ handle.green ^ handle.blue; +} + +/** + * Returns an RGB representing the receiver. + * + * @return the RGB for the color + * + * @exception SWTException + */ +public RGB getRGB () { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return new RGB(getRed(), getGreen(), getBlue()); +} + +/** + * Invokes platform specific functionality to allocate a new color. + *

+ * IMPORTANT: This method is not part of the public + * API for Color. It is marked public only so that it + * can be shared within the packages provided by SWT. It is not + * available on all platforms, and should never be called from + * application code. + *

+ * + * @param device the device on which to allocate the color + * @param handle the handle for the color + * + * @private + */ +public static Color gtk_new(Device device, GdkColor* gdkColor) { + if (device is null) device = Device.getDevice(); + Color color = new Color(); + color.handle = gdkColor; + color.device = device; + return color; +} + +void init(Device device, int red, int green, int blue) { + this.device = device; + if ((red > 255) || (red < 0) || + (green > 255) || (green < 0) || + (blue > 255) || (blue < 0)) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + GdkColor* gdkColor = new GdkColor(); + gdkColor.red = cast(short)((red & 0xFF) | ((red & 0xFF) << 8)); + gdkColor.green = cast(short)((green & 0xFF) | ((green & 0xFF) << 8)); + gdkColor.blue = cast(short)((blue & 0xFF) | ((blue & 0xFF) << 8)); + auto colormap = OS.gdk_colormap_get_system(); + if (!OS.gdk_colormap_alloc_color(colormap, gdkColor, true, true)) { + /* Allocate black. */ + gdkColor = new GdkColor(); + OS.gdk_colormap_alloc_color(colormap, gdkColor, true, true); + } + handle = gdkColor; + if (device.colorRefCount != null) { + /* Make a copy of the color to put in the colors array */ + GdkColor* colorCopy = new GdkColor(); + colorCopy.red = handle.red; + colorCopy.green = handle.green; + colorCopy.blue = handle.blue; + colorCopy.pixel = handle.pixel; + device.gdkColors[colorCopy.pixel] = colorCopy; + device.colorRefCount[colorCopy.pixel]++; + } +} + +/** + * Returns true if the color has been disposed, + * and false otherwise. + *

+ * This method gets the dispose state for the color. + * When a color has been disposed, it is an error to + * invoke any other method using the color. + * + * @return true when the color is disposed and false otherwise + */ +public bool isDisposed() { + return handle is null; +} + +/** + * Returns a string containing a concise, human-readable + * description of the receiver. + * + * @return a string representation of the receiver + */ +public override char[] toString () { + if (isDisposed()) return "Color {*DISPOSED*}"; + return Format( "Color {{{}, {}, {}}", getRed(), getGreen(), getBlue()); +} + +} diff -r 0a61cfe9ff23 -r 4db14dc0bc45 dwt/graphics/Drawable.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/graphics/Drawable.d Mon Jan 07 01:49:53 2008 +0100 @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2000, 2004 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +module dwt.graphics.Drawable; + + +// PORTING_TYPE +//import dwt.graphics.GCData; +class GCData{ +} + +/** + * Implementers of Drawable can have a graphics context (GC) + * created for them, and then they can be drawn on by sending messages to + * their associated GC. SWT images, and device objects such as the Display + * device and the Printer device, are drawables. + *

+ * IMPORTANT: This class is not part of the SWT + * public API. It is marked public only so that it can be shared + * within the packages provided by SWT. It should never be + * referenced from application code. + *

+ * + * @see Device + * @see Image + * @see GC + */ +public interface Drawable { + +/** + * Invokes platform specific functionality to allocate a new GC handle. + *

+ * IMPORTANT: This method is not part of the public + * API for Drawable. It is marked public only so that it + * can be shared within the packages provided by SWT. It is not + * available on all platforms, and should never be called from + * application code. + *

+ * + * @param data the platform specific GC data + * @return the platform specific GC handle + */ + +public int /*long*/ internal_new_GC (GCData data); + +/** + * Invokes platform specific functionality to dispose a GC handle. + *

+ * IMPORTANT: This method is not part of the public + * API for Drawable. It is marked public only so that it + * can be shared within the packages provided by SWT. It is not + * available on all platforms, and should never be called from + * application code. + *

+ * + * @param handle the platform specific GC handle + * @param data the platform specific GC data + */ +public void internal_dispose_GC (int /*long*/ handle, GCData data); + +} diff -r 0a61cfe9ff23 -r 4db14dc0bc45 dwt/graphics/Font.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/graphics/Font.d Mon Jan 07 01:49:53 2008 +0100 @@ -0,0 +1,303 @@ +/******************************************************************************* + * Copyright (c) 2000, 2006 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +module dwt.graphics.Font; + + +import dwt.SWT; +import dwt.graphics.Resource; +import dwt.graphics.FontData; +//import dwt.graphics.Device; +import dwt.internal.Converter; +import dwt.internal.gtk.OS; +import dwt.internal.gtk.c.pangotypes; + +import tango.text.convert.Format; +import tango.stdc.stringz; + +/** + * Instances of this class manage operating system resources that + * define how text looks when it is displayed. Fonts may be constructed + * by providing a device and either name, size and style information + * or a FontData object which encapsulates this data. + *

+ * Application code must explicitly invoke the Font.dispose() + * method to release the operating system resources managed by each instance + * when those instances are no longer required. + *

+ * + * @see FontData + */ +public final class Font : Resource { + /** + * the handle to the OS font resource + * (Warning: This field is platform dependent) + *

+ * IMPORTANT: This field is not part of the SWT + * public API. It is marked public only so that it can be shared + * within the packages provided by SWT. It is not available on all + * platforms and should never be accessed from application code. + *

+ */ + public PangoFontDescription* handle; + +this() { +} + +/** + * Constructs a new font given a device and font data + * which describes the desired font's appearance. + *

+ * You must dispose the font when it is no longer required. + *

+ * + * @param device the device to create the font on + * @param fd the FontData that describes the desired font (must not be null) + * + * @exception IllegalArgumentException + * @exception SWTError + */ +public this(Device device, FontData fd) { + if (device is null) device = Device.getDevice(); + if (device is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (fd is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + init(device, fd.getName(), fd.getHeightF(), fd.getStyle(), fd.str); + if (device.tracking) device.new_Object(this); +} + +/** + * Constructs a new font given a device and an array + * of font data which describes the desired font's + * appearance. + *

+ * You must dispose the font when it is no longer required. + *

+ * + * @param device the device to create the font on + * @param fds the array of FontData that describes the desired font (must not be null) + * + * @exception IllegalArgumentException + * @exception SWTError + * + * @since 2.1 + */ +public this(Device device, FontData[] fds) { + if (device is null) device = Device.getDevice(); + if (device is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (fds is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (fds.length == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + for (int i=0; i + * You must dispose the font when it is no longer required. + *

+ * + * @param device the device to create the font on + * @param name the name of the font (must not be null) + * @param height the font height in points + * @param style a bit or combination of NORMAL, BOLD, ITALIC + * + * @exception IllegalArgumentException + * @exception SWTError + */ +public this(Device device, char[] name, int height, int style) { + if (device is null) device = Device.getDevice(); + if (device is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + init(device, name, height, style, null); + if (device.tracking) device.new_Object(this); +} + +/*public*/ this(Device device, char[] name, float height, int style) { + if (device is null) device = Device.getDevice(); + if (device is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + init(device, name, height, style, null); + if (device.tracking) device.new_Object(this); +} + +/** + * Disposes of the operating system resources associated with + * the font. Applications must dispose of all fonts which + * they allocate. + */ +public void dispose() { + if (handle is null ) return; + if (device.isDisposed()) return; + OS.pango_font_description_free(handle); + handle = null; + if (device.tracking) device.dispose_Object(this); + device = null; +} + +/** + * Compares the argument to the receiver, and returns true + * if they represent the same object using a class + * specific comparison. + * + * @param object the object to compare with this object + * @return true if the object is the same as this object and false otherwise + * + * @see #hashCode + */ +public int opEquals(Object object) { + if (object == this) return true; + if ( auto font = cast(Font)object ){ + return handle is font.handle; + } + return false; +} + + +/** + * Returns an array of FontDatas representing the receiver. + * On Windows, only one FontData will be returned per font. On X however, + * a Font object may be composed of multiple X + * fonts. To support this case, we return an array of font data objects. + * + * @return an array of font data objects describing the receiver + * + * @exception SWTException + */ +public FontData[] getFontData() { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + + auto family = OS.pango_font_description_get_family(handle); + char[] name = fromUtf8z( family ); + float height = cast(float)OS.pango_font_description_get_size(handle) / OS.PANGO_SCALE; + int pangoStyle = OS.pango_font_description_get_style(handle); + int pangoWeight = OS.pango_font_description_get_weight(handle); + int style = SWT.NORMAL; + if (pangoStyle == OS.PANGO_STYLE_ITALIC) style |= SWT.ITALIC; + if (pangoStyle == OS.PANGO_STYLE_OBLIQUE) style |= SWT.ROMAN; + if (pangoWeight >= OS.PANGO_WEIGHT_BOLD) style |= SWT.BOLD; + auto fontString = OS.pango_font_description_to_string (handle); + auto buffer = fromUtf8z( fontString ).dup; + FontData data = new FontData( buffer , height, style); + OS.g_free (fontString); + data.str = buffer; + return [data]; +} + +/** + * Invokes platform specific functionality to allocate a new font. + *

+ * IMPORTANT: This method is not part of the public + * API for Font. It is marked public only so that it + * can be shared within the packages provided by SWT. It is not + * available on all platforms, and should never be called from + * application code. + *

+ * + * @param device the device on which to allocate the color + * @param handle the handle for the font + * + * @private + */ +public static Font gtk_new(Device device, PangoFontDescription* handle) { + if (device is null) device = Device.getDevice(); + Font font = new Font(); + font.handle = handle; + font.device = device; + return font; +} + +/** + * Returns an integer hash code for the receiver. Any two + * objects that return true when passed to + * equals must return the same value for this + * method. + * + * @return the receiver's hash + * + * @see #equals + */ +public hash_t toHash() { + return cast(hash_t)/*64*/handle; +} + +void init(Device device, char[] name, float height, int style, char[] fontString) { + if (name is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + this.device = device; + if (fontString !is null) { + handle = OS.pango_font_description_from_string (toStringz(fontString)); + if (handle is null) SWT.error(SWT.ERROR_NO_HANDLES); + } else { + handle = OS.pango_font_description_new(); + if (handle is null) SWT.error(SWT.ERROR_NO_HANDLES); + //byte[] buffer = Converter.wcsToMbcs(null, name, true); + OS.pango_font_description_set_family(handle, toStringz(name) ); + OS.pango_font_description_set_size(handle, cast(int)(0.5f + height * OS.PANGO_SCALE)); + OS.pango_font_description_set_stretch(handle, cast(PangoStretch) OS.PANGO_STRETCH_NORMAL); + int pangoStyle = OS.PANGO_STYLE_NORMAL; + int pangoWeight = OS.PANGO_WEIGHT_NORMAL; + if ((style & SWT.ITALIC) != 0) pangoStyle = OS.PANGO_STYLE_ITALIC; + if ((style & SWT.ROMAN) != 0) pangoStyle = OS.PANGO_STYLE_OBLIQUE; + if ((style & SWT.BOLD) != 0) pangoWeight = OS.PANGO_WEIGHT_BOLD; + OS.pango_font_description_set_style(handle, cast(PangoStyle)pangoStyle); + OS.pango_font_description_set_weight(handle, cast(PangoWeight)pangoWeight); + } +} + +/** + * Returns true if the font has been disposed, + * and false otherwise. + *

+ * This method gets the dispose state for the font. + * When a font has been disposed, it is an error to + * invoke any other method using the font. + * + * @return true when the font is disposed and false otherwise + */ +public bool isDisposed() { + return handle is null; +} + +/** + * Returns a string containing a concise, human-readable + * description of the receiver. + * + * @return a string representation of the receiver + */ +public char[] toString () { + if (isDisposed()) return "Font {*DISPOSED*}"; + return Format( "Font {{{}}", handle ); +} + +} diff -r 0a61cfe9ff23 -r 4db14dc0bc45 dwt/graphics/FontData.d --- a/dwt/graphics/FontData.d Mon Jan 07 00:12:43 2008 +0100 +++ b/dwt/graphics/FontData.d Mon Jan 07 01:49:53 2008 +0100 @@ -88,7 +88,7 @@ * platforms and should never be accessed from application code. *

*/ - public byte[] str; + public char[] str; /** * The locales of the font diff -r 0a61cfe9ff23 -r 4db14dc0bc45 dwt/graphics/Region.d --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/dwt/graphics/Region.d Mon Jan 07 01:49:53 2008 +0100 @@ -0,0 +1,598 @@ +/******************************************************************************* + * Copyright (c) 2000, 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +module dwt.graphics.Region; + + +import dwt.SWT; +import dwt.graphics.Resource; +import dwt.graphics.Point; +import dwt.graphics.Rectangle; +//import dwt.graphics.Device; +import dwt.internal.gtk.OS; +import dwt.internal.gtk.c.gdktypes; + +import tango.text.convert.Format; +/** + * Instances of this class represent areas of an x-y coordinate + * system that are aggregates of the areas covered by a number + * of polygons. + *

+ * Application code must explicitly invoke the Region.dispose() + * method to release the operating system resources managed by each instance + * when those instances are no longer required. + *

+ */ +public final class Region : Resource { + /** + * the OS resource for the region + * (Warning: This field is platform dependent) + *

+ * IMPORTANT: This field is not part of the SWT + * public API. It is marked public only so that it can be shared + * within the packages provided by SWT. It is not available on all + * platforms and should never be accessed from application code. + *

+ */ + public GdkRegion* handle; + +/** + * Constructs a new empty region. + * + * @exception SWTError + */ +public this() { + this(null); +} + +/** + * Constructs a new empty region. + *

+ * You must dispose the region when it is no longer required. + *

+ * + * @param device the device on which to allocate the region + * + * @exception IllegalArgumentException + * @exception SWTError + * + * @see #dispose + * + * @since 3.0 + */ +public this(Device device) { + if (device is null) device = Device.getDevice(); + if (device is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + this.device = device; + handle = OS.gdk_region_new(); + if (handle is null) SWT.error(SWT.ERROR_NO_HANDLES); + if (device.tracking) device.new_Object(this); +} + +this(Device device, GdkRegion* handle) { + this.device = device; + this.handle = handle; +} + +/** + * Adds the given polygon to the collection of polygons + * the receiver maintains to describe its area. + * + * @param pointArray points that describe the polygon to merge with the receiver + * + * @exception IllegalArgumentException + * @exception SWTException + * + * @since 3.0 +* + */ +public void add (int[] pointArray) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (pointArray is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); +//PORTING_FIXME: shall the pointArray be changed to be GdkPoint[] ? + auto polyRgn = OS.gdk_region_polygon(cast(GdkPoint*)pointArray.ptr, pointArray.length / 2, cast(GdkFillRule) OS.GDK_EVEN_ODD_RULE); + OS.gdk_region_union(handle, polyRgn); + OS.gdk_region_destroy(polyRgn); +} + +/** + * Adds the given rectangle to the collection of polygons + * the receiver maintains to describe its area. + * + * @param rect the rectangle to merge with the receiver + * + * @exception IllegalArgumentException + * @exception SWTException + */ +public void add(Rectangle rect) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (rect is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + add (rect.x, rect.y, rect.width, rect.height); +} + +/** + * Adds the given rectangle to the collection of polygons + * the receiver maintains to describe its area. + * + * @param x the x coordinate of the rectangle + * @param y the y coordinate of the rectangle + * @param width the width coordinate of the rectangle + * @param height the height coordinate of the rectangle + * + * @exception IllegalArgumentException + * @exception SWTException + * + * @since 3.1 + */ +public void add(int x, int y, int width, int height) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + GdkRectangle* gdkRect = new GdkRectangle(); + gdkRect.x = x; + gdkRect.y = y; + gdkRect.width = width; + gdkRect.height = height; + OS.gdk_region_union_with_rect(handle, gdkRect); +} + +/** + * Adds all of the polygons which make up the area covered + * by the argument to the collection of polygons the receiver + * maintains to describe its area. + * + * @param region the region to merge + * + * @exception IllegalArgumentException + * @exception SWTException + */ +public void add(Region region) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (region is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + OS.gdk_region_union(handle, region.handle); +} + +/** + * Returns true if the point specified by the + * arguments is inside the area specified by the receiver, + * and false otherwise. + * + * @param x the x coordinate of the point to test for containment + * @param y the y coordinate of the point to test for containment + * @return true if the region contains the point and false otherwise + * + * @exception SWTException + */ +public bool contains(int x, int y) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return cast(bool)OS.gdk_region_point_in(handle, x, y); +} + +/** + * Returns true if the given point is inside the + * area specified by the receiver, and false + * otherwise. + * + * @param pt the point to test for containment + * @return true if the region contains the point and false otherwise + * + * @exception IllegalArgumentException + * @exception SWTException + */ +public bool contains(Point pt) { + if (pt is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + return contains(pt.x, pt.y); +} + +/** + * Disposes of the operating system resources associated with + * the region. Applications must dispose of all regions which + * they allocate. + */ +public void dispose() { + if (handle is null) return; + if (device.isDisposed()) return; + OS.gdk_region_destroy(handle); + handle = null; + if (device.tracking) device.dispose_Object(this); + device = null; +} + +/** + * Compares the argument to the receiver, and returns true + * if they represent the same object using a class + * specific comparison. + * + * @param object the object to compare with this object + * @return true if the object is the same as this object and false otherwise + * + * @see #hashCode + */ +public int opEquals(Object object) { + if (this is object) return true; + if ( auto region = cast(Region)object ){ + return handle is region.handle; + } + return false; +} + +/** + * Returns a rectangle which represents the rectangular + * union of the collection of polygons the receiver + * maintains to describe its area. + * + * @return a bounding rectangle for the region + * + * @exception SWTException + * + * @see Rectangle#union + */ +public Rectangle getBounds() { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + GdkRectangle* gdkRect = new GdkRectangle(); + OS.gdk_region_get_clipbox(handle, gdkRect); + return new Rectangle(gdkRect.x, gdkRect.y, gdkRect.width, gdkRect.height); +} + +public static Region gtk_new(Device device, GdkRegion* handle) { + return new Region(device, handle); +} + +/** + * Returns an integer hash code for the receiver. Any two + * objects that return true when passed to + * equals must return the same value for this + * method. + * + * @return the receiver's hash + * + * @see #equals + */ +public override hash_t toHash() { + return cast(hash_t)handle; +} + +/** + * Intersects the given rectangle to the collection of polygons + * the receiver maintains to describe its area. + * + * @param rect the rectangle to intersect with the receiver + * + * @exception IllegalArgumentException + * @exception SWTException + * + * @since 3.0 + */ +public void intersect(Rectangle rect) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (rect is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + intersect (rect.x, rect.y, rect.width, rect.height); +} + +/** + * Intersects the given rectangle to the collection of polygons + * the receiver maintains to describe its area. + * + * @param x the x coordinate of the rectangle + * @param y the y coordinate of the rectangle + * @param width the width coordinate of the rectangle + * @param height the height coordinate of the rectangle + * + * @exception IllegalArgumentException + * @exception SWTException + * + * @since 3.1 + */ +public void intersect(int x, int y, int width, int height) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + GdkRectangle* gdkRect = new GdkRectangle(); + gdkRect.x = x; + gdkRect.y = y; + gdkRect.width = width; + gdkRect.height = height; + auto rectRgn = OS.gdk_region_rectangle(gdkRect); + OS.gdk_region_intersect(handle, rectRgn); + OS.gdk_region_destroy(rectRgn); +} + +/** + * Intersects all of the polygons which make up the area covered + * by the argument to the collection of polygons the receiver + * maintains to describe its area. + * + * @param region the region to intersect + * + * @exception IllegalArgumentException + * @exception SWTException + * + * @since 3.0 + */ +public void intersect(Region region) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (region is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + OS.gdk_region_intersect(handle, region.handle); +} + +/** + * Returns true if the rectangle described by the + * arguments intersects with any of the polygons the receiver + * maintains to describe its area, and false otherwise. + * + * @param x the x coordinate of the origin of the rectangle + * @param y the y coordinate of the origin of the rectangle + * @param width the width of the rectangle + * @param height the height of the rectangle + * @return true if the rectangle intersects with the receiver, and false otherwise + * + * @exception SWTException + * + * @see Rectangle#intersects(Rectangle) + */ +public bool intersects (int x, int y, int width, int height) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + GdkRectangle* gdkRect = new GdkRectangle(); + gdkRect.x = x; + gdkRect.y = y; + gdkRect.width = width; + gdkRect.height = height; + return OS.gdk_region_rect_in(handle, gdkRect) != OS.GDK_OVERLAP_RECTANGLE_OUT; +} +/** + * Returns true if the given rectangle intersects + * with any of the polygons the receiver maintains to describe + * its area and false otherwise. + * + * @param rect the rectangle to test for intersection + * @return true if the rectangle intersects with the receiver, and false otherwise + * + * @exception IllegalArgumentException + * @exception SWTException + * + * @see Rectangle#intersects(Rectangle) + */ +public bool intersects(Rectangle rect) { + if (rect is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + return intersects(rect.x, rect.y, rect.width, rect.height); +} + +/** + * Returns true if the region has been disposed, + * and false otherwise. + *

+ * This method gets the dispose state for the region. + * When a region has been disposed, it is an error to + * invoke any other method using the region. + * + * @return true when the region is disposed, and false otherwise + */ +public bool isDisposed() { + return handle is null; +} + +/** + * Returns true if the receiver does not cover any + * area in the (x, y) coordinate plane, and false if + * the receiver does cover some area in the plane. + * + * @return true if the receiver is empty, and false otherwise + * + * @exception SWTException

+ */ +public bool isEmpty() { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return cast(bool)OS.gdk_region_empty(handle); +} + +/** + * Subtracts the given polygon from the collection of polygons + * the receiver maintains to describe its area. + * + * @param pointArray points that describe the polygon to merge with the receiver + * + * @exception IllegalArgumentException + * @exception SWTException + * + * @since 3.0 + */ +public void subtract (int[] pointArray) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (pointArray is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + auto polyRgn = OS.gdk_region_polygon( cast(GdkPoint*)pointArray.ptr, pointArray.length / 2, cast(GdkFillRule)OS.GDK_EVEN_ODD_RULE); + OS.gdk_region_subtract(handle, polyRgn); + OS.gdk_region_destroy(polyRgn); +} + +/** + * Subtracts the given rectangle from the collection of polygons + * the receiver maintains to describe its area. + * + * @param rect the rectangle to subtract from the receiver + * + * @exception IllegalArgumentException + * @exception SWTException + * + * @since 3.0 + */ +public void subtract(Rectangle rect) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (rect is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + subtract (rect.x, rect.y, rect.width, rect.height); +} + +/** + * Subtracts the given rectangle from the collection of polygons + * the receiver maintains to describe its area. + * + * @param x the x coordinate of the rectangle + * @param y the y coordinate of the rectangle + * @param width the width coordinate of the rectangle + * @param height the height coordinate of the rectangle + * + * @exception IllegalArgumentException + * @exception SWTException + * + * @since 3.1 + */ +public void subtract(int x, int y, int width, int height) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + GdkRectangle* gdkRect = new GdkRectangle(); + gdkRect.x = x; + gdkRect.y = y; + gdkRect.width = width; + gdkRect.height = height; + auto rectRgn = OS.gdk_region_rectangle(gdkRect); + OS.gdk_region_subtract(handle, rectRgn); + OS.gdk_region_destroy(rectRgn); +} + +/** + * Subtracts all of the polygons which make up the area covered + * by the argument from the collection of polygons the receiver + * maintains to describe its area. + * + * @param region the region to subtract + * + * @exception IllegalArgumentException + * @exception SWTException + * + * @since 3.0 + */ +public void subtract(Region region) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (region is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + OS.gdk_region_subtract(handle, region.handle); +} + +/** + * Translate all of the polygons the receiver maintains to describe + * its area by the specified point. + * + * @param x the x coordinate of the point to translate + * @param y the y coordinate of the point to translate + * + * @exception SWTException + * + * @since 3.1 + */ +public void translate (int x, int y) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + OS.gdk_region_offset (handle, x, y); +} + +/** + * Translate all of the polygons the receiver maintains to describe + * its area by the specified point. + * + * @param pt the point to translate + * + * @exception IllegalArgumentException + * @exception SWTException + * + * @since 3.1 + */ +public void translate (Point pt) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (pt is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + translate (pt.x, pt.y); +} + +/** + * Returns a string containing a concise, human-readable + * description of the receiver. + * + * @return a string representation of the receiver + */ +public override char[] toString () { + if (isDisposed()) return "Region {*DISPOSED*}"; + return Format( "Region {{{}}", handle ); +} +} diff -r 0a61cfe9ff23 -r 4db14dc0bc45 dwt/graphics/Resource.d --- a/dwt/graphics/Resource.d Mon Jan 07 00:12:43 2008 +0100 +++ b/dwt/graphics/Resource.d Mon Jan 07 01:49:53 2008 +0100 @@ -13,7 +13,23 @@ import dwt.SWT; //PORTING_TYPE -class Device{} +//import dwt.graphics.Device; +import dwt.internal.gtk.c.gdktypes : GdkColor; +class Device{ + static Device getDevice(){ + return null; + } + void new_Object (Object object) { + } + void dispose_Object (Object object) { + } + bool tracking; + bool isDisposed(){ + return false; + } + int[] colorRefCount; + GdkColor*[] gdkColors; +} /** * This class is the abstract superclass of all graphics resource objects. diff -r 0a61cfe9ff23 -r 4db14dc0bc45 todo.txt --- a/todo.txt Mon Jan 07 00:12:43 2008 +0100 +++ b/todo.txt Mon Jan 07 01:49:53 2008 +0100 @@ -24,12 +24,12 @@ internal/SWTEventListener // OK (java.util.EventListener) internal/SWTEventObject // OK (java.util.EventObject) -graphics/Color +graphics/Color // OK graphics/Cursor -graphics/Device +graphics/Device deps: GCData, Font, graphics/DeviceData // OK (fld: debug->debugging) -graphics/Drawable -graphics/Font +graphics/Drawable // OK (stub GCData) +graphics/Font // OK graphics/FontData // OK graphics/FontMetrics // OK graphics/GC @@ -48,7 +48,7 @@ graphics/Pattern graphics/Point // OK graphics/Rectangle // OK (meth union->makeUnion) -graphics/Region +graphics/Region // OK graphics/Resource // OK (stub: Display) graphics/RGB // OK graphics/TextLayout @@ -150,50 +150,51 @@ internal/cairo/Cairo internal/cairo/cairo_text_extents_t internal/cairo/cairo_font_extents_t -internal/image/FileFormat -internal/image/GIFFileFormat -internal/image/JPEGAppn -internal/image/JPEGArithmeticConditioningTable -internal/image/JPEGComment -internal/image/JPEGDecoder -internal/image/JPEGEndOfImage -internal/image/JPEGFileFormat -internal/image/JPEGFixedSizeSegment -internal/image/JPEGFrameHeader -internal/image/JPEGHuffmanTable -internal/image/JPEGQuantizationTable -internal/image/JPEGRestartInterval -internal/image/JPEGScanHeader -internal/image/JPEGSegment -internal/image/JPEGStartOfImage -internal/image/JPEGVariableSizeSegment -internal/image/LEDataInputStream -internal/image/LEDataOutputStream -internal/image/LZWCodec -internal/image/LZWNode -internal/image/OS2BMPFileFormat -internal/image/PngChunk -internal/image/PngChunkReader -internal/image/PngDecodingDataStream -internal/image/PngDeflater -internal/image/PngEncoder -internal/image/PNGFileFormat -internal/image/PngFileReadState -internal/image/PngHuffmanTable -internal/image/PngHuffmanTables -internal/image/PngIdatChunk -internal/image/PngIendChunk -internal/image/PngIhdrChunk -internal/image/PngInputStream -internal/image/PngLzBlockReader -internal/image/PngPlteChunk -internal/image/PngTrnsChunk -internal/image/TIFFDirectory -internal/image/TIFFFileFormat -internal/image/TIFFModifiedHuffmanCodec -internal/image/TIFFRandomFileAccess -internal/image/WinBMPFileFormat -internal/image/WinICOFileFormat +internal/image/FileFormat // OK +internal/image/GIFFileFormat // OK +internal/image/JPEGAppn // OK +internal/image/JPEGArithmeticConditioningTable // OK +internal/image/JPEGComment // OK +internal/image/JPEGDecoder // OK +internal/image/JPEGEndOfImage // OK +internal/image/JPEGFileFormat // OK +internal/image/JPEGFixedSizeSegment // OK +internal/image/JPEGFrameHeader // OK +internal/image/JPEGHuffmanTable // OK +internal/image/JPEGQuantizationTable // OK +internal/image/JPEGRestartInterval // OK +internal/image/JPEGScanHeader // OK +internal/image/JPEGSegment // OK +internal/image/JPEGStartOfImage // OK +internal/image/JPEGVariableSizeSegment // OK +internal/image/LEDataInputStream // OK +internal/image/LEDataOutputStream // OK +internal/image/LZWCodec // OK +internal/image/LZWNode // OK +internal/image/OS2BMPFileFormat // OK +internal/image/PngChunk // OK +internal/image/PngChunkReader // OK +internal/image/PngDecodingDataStream // OK +internal/image/PngDeflater // OK +internal/image/PngEncoder // OK +internal/image/PNGFileFormat // OK +internal/image/PngFileReadState // OK +internal/image/PngHuffmanTable // OK +internal/image/PngHuffmanTables // OK +internal/image/PngIdatChunk // OK +internal/image/PngIendChunk // OK +internal/image/PngIhdrChunk // OK +internal/image/PngInputStream // OK +internal/image/PngLzBlockReader // OK +internal/image/PngPlteChunk // OK +internal/image/PngTrnsChunk // OK +internal/image/TIFFDirectory // OK +internal/image/TIFFFileFormat // OK +internal/image/TIFFModifiedHuffmanCodec // OK +internal/image/TIFFRandomFileAccess // OK +internal/image/WinBMPFileFormat // OK +internal/image/WinICOFileFormat // OK + internal/gtk/GdkEventCrossing internal/gtk/XAnyEvent internal/gtk/OS