summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Color.java364
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Cursor.java445
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Device.java920
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/DeviceData.java23
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Font.java379
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/FontData.java722
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/FontMetrics.java165
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/GC.java3555
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/GCData.java53
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Image.java978
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Region.java776
11 files changed, 0 insertions, 8380 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Color.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Color.java
deleted file mode 100644
index 9d39595e17..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Color.java
+++ /dev/null
@@ -1,364 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
- * Portion Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Nokia Corporation - Qt implementation
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import com.trolltech.qt.gui.QColor;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-
-/**
- * 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 <code>RGB</code>.
- * <p>
- * Application code must explicitly invoke the <code>Color.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see RGB
- * @see Device#getSystemColor
- */
-public final class Color extends Resource {
-
- /**
- * the handle to the OS color resource (Warning: This field is platform
- * dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> 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.
- * </p>
- */
- private QColor color;
-
- /**
- * Prevents uninitialized instances from being created outside the package.
- */
- Color() {
- }
-
- /**
- * 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.
- * <p>
- * You must dispose the color when it is no longer required.
- * </p>
- *
- * @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
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is
- * no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue
- * argument is not between 0 and 255</li>
- * </ul>
- *
- * @see #dispose
- */
- public Color(Device device, int red, int green, int blue) {
- init(device, red, green, blue);
- }
-
- /**
- * Constructs a new instance of this class given a device and an
- * <code>RGB</code> 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.
- * <p>
- * You must dispose the color when it is no longer required.
- * </p>
- *
- * @param device
- * the device on which to allocate the color
- * @param rgb
- * the RGB values of the desired color
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is
- * no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the rgb argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue
- * components of the argument are not between 0 and 255</li>
- * </ul>
- *
- * @see #dispose
- */
- public Color(Device device, RGB rgb) {
- if (rgb == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- init(device, rgb.red, rgb.green, rgb.blue);
- }
-
- /**
- * Disposes of the operating system resources associated with this resource.
- * Applications must dispose of all resources which they allocate.
- */
- @Override
- public void dispose() {
- if (device == null) {
- return;
- }
- if (device.isDisposed()) {
- return;
- }
- if (device.tracking) {
- device.dispose_Object(this);
- }
- device = null;
- color = null;
- }
-
- /**
- * Compares the argument to the receiver, and returns true if they represent
- * the <em>same</em> object using a class specific comparison.
- *
- * @param object
- * the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and
- * <code>false</code> otherwise
- *
- * @see #hashCode
- */
- @Override
- public boolean equals(Object object) {
- if (object == this) {
- return true;
- }
- if (!(object instanceof Color)) {
- return false;
- }
- Color color = (Color) object;
- if (isDisposed() || color.isDisposed()) {
- return false;
- }
- return this.color.equals(color.color);
- }
-
- /**
- * Returns the amount of blue in the color, from 0 to 255.
- *
- * @return the blue component of the color
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public int getBlue() {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return color.blue();
- }
-
- /**
- * Returns the amount of green in the color, from 0 to 255.
- *
- * @return the green component of the color
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public int getGreen() {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return color.green();
- }
-
- /**
- * Returns the amount of red in the color, from 0 to 255.
- *
- * @return the red component of the color
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public int getRed() {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return color.red();
- }
-
- /**
- * Returns an <code>RGB</code> representing the receiver.
- *
- * @return the RGB for the color
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public RGB getRGB() {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return new RGB(color.red(), color.green(), color.blue());
- }
-
- /**
- * Returns an integer hash code for the receiver. Any two objects that
- * return <code>true</code> when passed to <code>equals</code> must return
- * the same value for this method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
- @Override
- public int hashCode() {
- if (isDisposed()) {
- return 0;
- }
- return color.hashCode();
- }
-
- /**
- * Invokes platform specific functionality to allocate a new color.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public API for
- * <code>Color</code>. 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.
- * </p>
- *
- * @param red
- * the red component
- * @param green
- * the green component
- * @param blue
- * the blue component
- *
- * @private
- */
-
- void init(Device device, int red, int green, int blue) {
-
- if (device == null) {
- device = Device.getDevice();
- }
- if (device == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- this.device = device;
-
- if (red > 255 || red < 0 || green > 255 || green < 0 || blue > 255 || blue < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- // Keep this after dealing with all exceptions!
- if (device.tracking) {
- device.new_Object(this);
- }
- color = new QColor(red, green, blue);
- }
-
- public QColor getColor() {
- if (color == null) {
- color = new QColor(getRed(), getGreen(), getBlue());
- }
- return color;
- }
-
- /**
- * Returns <code>true</code> if the color has been disposed, and
- * <code>false</code> otherwise.
- * <p>
- * 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 <code>true</code> when the color is disposed and
- * <code>false</code> otherwise
- */
- @Override
- public boolean isDisposed() {
- return color == null;
- }
-
- /**
- * Returns a string containing a concise, human-readable description of the
- * receiver.
- *
- * @return a string representation of the receiver
- */
- @Override
- public String toString() {
- if (isDisposed()) {
- return "Color {*DISPOSED*}"; //$NON-NLS-1$
- }
- return "Color {" + getRed() + ", " + getGreen() + ", " + getBlue() + "}"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- }
-
- /**
- * Invokes platform specific functionality to allocate a new color.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public API for
- * <code>Color</code>. 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.
- * </p>
- *
- * @param device
- * the device on which to allocate the color
- * @param handle
- * the handle for the color
- * @return a new color object containing the specified device and handle
- */
- public static Color qt_new(Device device, int rgb) {
- Color color = new Color();
- color.device = device;
- color.color = new QColor(rgb);
- return color;
- }
-
- public static Color qt_new(Device device, QColor qColor) {
- Color color = new Color(device, qColor.red(), qColor.green(), qColor.blue());
- color.color = qColor;
- return color;
- }
-
- public int getPixel() {
- return getColor().value();
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Cursor.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Cursor.java
deleted file mode 100644
index 6803a4d1a8..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Cursor.java
+++ /dev/null
@@ -1,445 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import com.trolltech.qt.core.Qt.CursorShape;
-import com.trolltech.qt.gui.QCursor;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTError;
-
-/**
- * Instances of this class manage operating system resources that specify the
- * appearance of the on-screen pointer. To create a cursor you specify the
- * device and either a simple cursor style describing one of the standard
- * operating system provided cursors or the image and mask data for the desired
- * appearance.
- * <p>
- * Application code must explicitly invoke the <code>Cursor.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>
- * CURSOR_ARROW, CURSOR_WAIT, CURSOR_CROSS, CURSOR_APPSTARTING, CURSOR_HELP,
- * CURSOR_SIZEALL, CURSOR_SIZENESW, CURSOR_SIZENS, CURSOR_SIZENWSE,
- * CURSOR_SIZEWE, CURSOR_SIZEN, CURSOR_SIZES, CURSOR_SIZEE, CURSOR_SIZEW,
- * CURSOR_SIZENE, CURSOR_SIZESE, CURSOR_SIZESW, CURSOR_SIZENW, CURSOR_UPARROW,
- * CURSOR_IBEAM, CURSOR_NO, CURSOR_HAND</dd>
- * </dl>
- * <p>
- * Note: Only one of the above styles may be specified.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/snippets/#cursor">Cursor
- * snippets</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further
- * information</a>
- */
-
-public final class Cursor extends Resource {
-
- /**
- * the handle to the OS cursor resource (Warning: This field is platform
- * dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> 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.
- * </p>
- */
- public QCursor cursor;
-
- boolean isIcon;
-
- /**
- * Prevents uninitialized instances from being created outside the package.
- */
- Cursor(Device device) {
- super(device);
- }
-
- /**
- * Constructs a new cursor given a device and a style constant describing
- * the desired cursor appearance.
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device
- * the device on which to allocate the cursor
- * @param style
- * the style of cursor to allocate
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is
- * no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - when an unknown style is
- * specified</li>
- * </ul>
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained
- * for cursor creation</li>
- * </ul>
- *
- * @see SWT#CURSOR_ARROW
- * @see SWT#CURSOR_WAIT
- * @see SWT#CURSOR_CROSS
- * @see SWT#CURSOR_APPSTARTING
- * @see SWT#CURSOR_HELP
- * @see SWT#CURSOR_SIZEALL
- * @see SWT#CURSOR_SIZENESW
- * @see SWT#CURSOR_SIZENS
- * @see SWT#CURSOR_SIZENWSE
- * @see SWT#CURSOR_SIZEWE
- * @see SWT#CURSOR_SIZEN
- * @see SWT#CURSOR_SIZES
- * @see SWT#CURSOR_SIZEE
- * @see SWT#CURSOR_SIZEW
- * @see SWT#CURSOR_SIZENE
- * @see SWT#CURSOR_SIZESE
- * @see SWT#CURSOR_SIZESW
- * @see SWT#CURSOR_SIZENW
- * @see SWT#CURSOR_UPARROW
- * @see SWT#CURSOR_IBEAM
- * @see SWT#CURSOR_NO
- * @see SWT#CURSOR_HAND
- */
- public Cursor(Device device, int style) {
- super(device);
- CursorShape cursorShape = null;
- switch (style) {
- case SWT.CURSOR_HAND:
- cursorShape = CursorShape.PointingHandCursor;
- break;
- case SWT.CURSOR_ARROW:
- cursorShape = CursorShape.ArrowCursor;
- break;
- case SWT.CURSOR_WAIT:
- cursorShape = CursorShape.WaitCursor;
- break;
- case SWT.CURSOR_CROSS:
- cursorShape = CursorShape.CrossCursor;
- break;
- case SWT.CURSOR_APPSTARTING:
- cursorShape = CursorShape.BusyCursor;
- break;
- case SWT.CURSOR_HELP:
- cursorShape = CursorShape.WhatsThisCursor;
- break;
- case SWT.CURSOR_SIZEALL:
- cursorShape = CursorShape.SizeAllCursor;
- break;
- case SWT.CURSOR_SIZENESW:
- cursorShape = CursorShape.SizeBDiagCursor;
- break;
- case SWT.CURSOR_SIZENS:
- cursorShape = CursorShape.SizeVerCursor;
- break;
- case SWT.CURSOR_SIZENWSE:
- cursorShape = CursorShape.SizeFDiagCursor;
- break;
- case SWT.CURSOR_SIZEWE:
- cursorShape = CursorShape.SizeHorCursor;
- break;
- case SWT.CURSOR_SIZEN:
- cursorShape = CursorShape.SizeVerCursor;
- break;
- case SWT.CURSOR_SIZES:
- cursorShape = CursorShape.SizeVerCursor;
- break;
- case SWT.CURSOR_SIZEE:
- cursorShape = CursorShape.SizeHorCursor;
- break;
- case SWT.CURSOR_SIZEW:
- cursorShape = CursorShape.SizeHorCursor;
- break;
- case SWT.CURSOR_SIZENE:
- cursorShape = CursorShape.SizeBDiagCursor;
- break;
- case SWT.CURSOR_SIZESE:
- cursorShape = CursorShape.SizeBDiagCursor;
- break;
- case SWT.CURSOR_SIZESW:
- cursorShape = CursorShape.SizeFDiagCursor;
- break;
- case SWT.CURSOR_SIZENW:
- cursorShape = CursorShape.SizeFDiagCursor;
- break;
- case SWT.CURSOR_UPARROW:
- cursorShape = CursorShape.UpArrowCursor;
- break;
- case SWT.CURSOR_IBEAM:
- cursorShape = CursorShape.IBeamCursor;
- break;
- case SWT.CURSOR_NO:
- cursorShape = CursorShape.ForbiddenCursor;
-
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- cursor = new QCursor(cursorShape);
- init();
- }
-
- /**
- * Constructs a new cursor given a device, image and mask data describing
- * the desired cursor appearance, and the x and y coordinates of the
- * <em>hotspot</em> (that is, the point within the area covered by the
- * cursor which is considered to be where the on-screen pointer is
- * "pointing").
- * <p>
- * The mask data is allowed to be null, but in this case the source must be
- * an ImageData representing an icon that specifies both color data and mask
- * data.
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device
- * the device on which to allocate the cursor
- * @param source
- * the color data for the cursor
- * @param mask
- * the mask data for the cursor (or null)
- * @param hotspotX
- * the x coordinate of the cursor's hotspot
- * @param hotspotY
- * the y coordinate of the cursor's hotspot
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is
- * no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the source is null</li>
- * <li>ERROR_NULL_ARGUMENT - if the mask is null and the
- * source does not have a mask</li>
- * <li>ERROR_INVALID_ARGUMENT - if the source and the mask
- * are not the same size, or if the hotspot is outside the
- * bounds of the image</li>
- * </ul>
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained
- * for cursor creation</li>
- * </ul>
- */
- public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) {
- this(device, SWT.CURSOR_ARROW);
- //TODO
- // super(device);
- // if (source == null) {
- // SWT.error(SWT.ERROR_NULL_ARGUMENT);
- // }
- // if (mask == null) {
- // if (source.getTransparencyType() != SWT.TRANSPARENCY_MASK) {
- // SWT.error(SWT.ERROR_NULL_ARGUMENT);
- // }
- // mask = source.getTransparencyMask();
- // }
- // /* Check the bounds. Mask must be the same size as source */
- // if (mask.width != source.width || mask.height != source.height) {
- // SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- // }
- // /* Check the hotspots */
- // if (hotspotX >= source.width || hotspotX < 0 || hotspotY >= source.height || hotspotY < 0) {
- // SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- // }
- // /* Convert depth to 1 */
- // mask = ImageData.convertMask(mask);
- // source = ImageData.convertMask(source);
- //
- // /* Make sure source and mask scanline pad is 2 */
- // byte[] sourceData = ImageData.convertPad(source.data, source.width, source.height, source.depth,
- // source.scanlinePad, 2);
- // byte[] maskData = ImageData.convertPad(mask.data, mask.width, mask.height, mask.depth, mask.scanlinePad, 2);
-
- /* Create the cursor */
- // TODO
- // cursor = new QCursor(mask.)
- // int /* long */hInst = OS.GetModuleHandle(null);
- // if (OS.IsWinCE) {
- // SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- // }
- // handle = OS.CreateCursor(hInst, hotspotX, hotspotY, source.width, source.height, sourceData, maskData);
- // if (handle == 0) {
- // SWT.error(SWT.ERROR_NO_HANDLES);
- // }
- //init();
- }
-
- /**
- * Constructs a new cursor given a device, image data describing the desired
- * cursor appearance, and the x and y coordinates of the <em>hotspot</em>
- * (that is, the point within the area covered by the cursor which is
- * considered to be where the on-screen pointer is "pointing").
- * <p>
- * You must dispose the cursor when it is no longer required.
- * </p>
- *
- * @param device
- * the device on which to allocate the cursor
- * @param source
- * the image data for the cursor
- * @param hotspotX
- * the x coordinate of the cursor's hotspot
- * @param hotspotY
- * the y coordinate of the cursor's hotspot
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is
- * no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the hotspot is outside the
- * bounds of the image</li>
- * </ul>
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES - if a handle could not be obtained
- * for cursor creation</li>
- * </ul>
- *
- * @since 3.0
- */
- public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) {
- this(device, SWT.CURSOR_ARROW);
- // if (source == null) {
- // SWT.error(SWT.ERROR_NULL_ARGUMENT);
- // }
- // /* Check the hotspots */
- // if (hotspotX >= source.width || hotspotX < 0 || hotspotY >= source.height || hotspotY < 0) {
- // SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- // }
-
- // ImageData mask = source.getTransparencyMask();
- // int /* long */[] result = new int[2]; // TODO = Image.init(this.device, null, source, mask);
- // int /* long */hBitmap = result[0];
- // int /* long */hMask = result[1];
- // /* Create the icon */
- // ICONINFO info = new ICONINFO();
- // info.fIcon = false;
- // info.hbmColor = hBitmap;
- // info.hbmMask = hMask;
- // info.xHotspot = hotspotX;
- // info.yHotspot = hotspotY;
- //TODO
- // handle = OS.CreateIconIndirect(info);
- // if (handle == 0) {
- // SWT.error(SWT.ERROR_NO_HANDLES);
- // }
- // OS.DeleteObject(hBitmap);
- // OS.DeleteObject(hMask);
- //isIcon = true;
- // init();
- }
-
- @Override
- void destroy() {
- cursor = null;
- }
-
- /**
- * Compares the argument to the receiver, and returns true if they represent
- * the <em>same</em> object using a class specific comparison.
- *
- * @param object
- * the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and
- * <code>false</code> otherwise
- *
- * @see #hashCode
- */
- @Override
- public boolean equals(Object object) {
- if (object == this) {
- return true;
- }
- if (!(object instanceof Cursor)) {
- return false;
- }
- Cursor cursor = (Cursor) object;
- return device == cursor.device && this.cursor == cursor.cursor;
- }
-
- /**
- * Returns an integer hash code for the receiver. Any two objects that
- * return <code>true</code> when passed to <code>equals</code> must return
- * the same value for this method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
- @Override
- public int hashCode() {
- return cursor.hashCode();
- }
-
- /**
- * Returns <code>true</code> if the cursor has been disposed, and
- * <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the cursor. When a cursor has been
- * disposed, it is an error to invoke any other method using the cursor.
- *
- * @return <code>true</code> when the cursor is disposed and
- * <code>false</code> otherwise
- */
- @Override
- public boolean isDisposed() {
- return cursor == null;
- }
-
- /**
- * Returns a string containing a concise, human-readable description of the
- * receiver.
- *
- * @return a string representation of the receiver
- */
- @Override
- public String toString() {
- if (isDisposed()) {
- return "Cursor {*DISPOSED*}"; //$NON-NLS-1$
- }
- return "Cursor {" + cursor + "}"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Invokes platform specific functionality to allocate a new cursor.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public API for
- * <code>Cursor</code>. 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.
- * </p>
- *
- * @param device
- * the device on which to allocate the color
- * @param handle
- * the handle for the cursor
- * @return a new cursor object containing the specified device and handle
- */
- public static Cursor win32_new(Device device, int handle) {
- Cursor cursor = new Cursor(device);
- // TODO
- // cursor.cursor = handle;
- return cursor;
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Device.java
deleted file mode 100644
index 99a3dcb47a..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Device.java
+++ /dev/null
@@ -1,920 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import com.trolltech.qt.gui.QApplication;
-import com.trolltech.qt.gui.QColor;
-import com.trolltech.qt.gui.QFontDatabase;
-import com.trolltech.qt.gui.QPaintDeviceInterface;
-import com.trolltech.qt.gui.QPalette;
-import com.trolltech.qt.gui.QPalette.ColorGroup;
-import com.trolltech.qt.gui.QPalette.ColorRole;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-
-/**
- * This class is the abstract superclass of all device objects, such as the
- * Display device and the Printer device. Devices can have a graphics context
- * (GC) created for them, and they can be drawn on by sending messages to the
- * associated GC.
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further
- * information</a>
- */
-public abstract class Device implements Drawable {
-
- /* Debugging */
- public static boolean DEBUG;
- private boolean debug = DEBUG;
- boolean tracking = DEBUG;
- private Error[] errors;
- private Object[] objects;
- private Object trackingLock;
-
- /* System Font */
- Font systemFont;
- private QColor COLOR_LIST_BACKGROUND;
- private QColor COLOR_LIST_FOREGROUND;
- private QColor COLOR_LIST_SELECTION;
- private QColor COLOR_LIST_SELECTION_TEXT;
- private QColor COLOR_TITLE_BACKGROUND;
- private QColor COLOR_TITLE_BACKGROUND_GRADIENT;
- private QColor COLOR_TITLE_FOREGROUND;
- private QColor COLOR_TITLE_INACTIVE_BACKGROUND;
- private QColor COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT;
- private QColor COLOR_TITLE_INACTIVE_FOREGROUND;
- private QColor COLOR_WIDGET_BACKGROUND;
- private QColor COLOR_WIDGET_BORDER;
- private QColor COLOR_WIDGET_DARK_SHADOW;
- private QColor COLOR_WIDGET_FOREGROUND;
- private QColor COLOR_WIDGET_HIGHLIGHT_SHADOW;
- private QColor COLOR_WIDGET_LIGHT_SHADOW;
- private QColor COLOR_WIDGET_NORMAL_SHADOW;
- private QColor COLOR_INFO_FOREGROUND;
- private QColor COLOR_INFO_BACKGROUND;
-
- private boolean disposed;
- private QPaintDeviceInterface paintDevice;
-
- /*
- * TEMPORARY CODE. When a graphics object is created and the device
- * parameter is null, the current Display is used. This presents a problem
- * because SWT graphics does not reference classes in SWT widgets. The
- * correct fix is to remove this feature. Unfortunately, too many
- * application programs rely on this feature.
- */
- protected static Device CurrentDevice;
- protected static Runnable DeviceFinder;
- static {
- try {
- Class.forName("org.eclipse.swt.widgets.Display"); //$NON-NLS-1$
- } catch (ClassNotFoundException e) {
- }
- }
-
- /*
- * TEMPORARY CODE.
- */
- static synchronized Device getDevice() {
- if (DeviceFinder != null) {
- DeviceFinder.run();
- }
- Device device = CurrentDevice;
- CurrentDevice = null;
- return device;
- }
-
- /**
- * Constructs a new instance of this class.
- * <p>
- * You must dispose the device when it is no longer required.
- * </p>
- *
- * @see #create
- * @see #init
- *
- * @since 3.1
- */
- public Device() {
- this(null);
- }
-
- /**
- * Constructs a new instance of this class.
- * <p>
- * You must dispose the device when it is no longer required.
- * </p>
- *
- * @param data
- * the DeviceData which describes the receiver
- *
- * @see #create
- * @see #init
- * @see DeviceData
- */
- public Device(DeviceData data) {
- synchronized (Device.class) {
- if (data != null) {
- debug = data.debug;
- tracking = data.tracking;
- }
- if (tracking) {
- errors = new Error[128];
- objects = new Object[128];
- trackingLock = new Object();
- }
- create(data);
- init();
- }
- }
-
- protected void setPaintDevice(QPaintDeviceInterface paintDevice) {
- this.paintDevice = paintDevice;
- }
-
- /**
- * Throws an <code>SWTException</code> if the receiver can not be accessed
- * by the caller. This may include both checks on the state of the receiver
- * and more generally on the entire execution context. This method
- * <em>should</em> be called by device implementors to enforce the standard
- * SWT invariants.
- * <p>
- * Currently, it is an error to invoke any method (other than
- * <code>isDisposed()</code> and <code>dispose()</code>) on a device that
- * has had its <code>dispose()</code> method called.
- * </p>
- * <p>
- * In future releases of SWT, there may be more or fewer error checks and
- * exceptions may be thrown for different reasons.
- * <p>
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- protected void checkDevice() {
- if (disposed) {
- SWT.error(SWT.ERROR_DEVICE_DISPOSED);
- }
- }
-
- /**
- * Creates the device in the operating system. If the device does not have a
- * handle, this method may do nothing depending on the device.
- * <p>
- * This method is called before <code>init</code>.
- * </p>
- * <p>
- * Subclasses are supposed to reimplement this method and not call the
- * <code>super</code> implementation.
- * </p>
- *
- * @param data
- * the DeviceData which describes the receiver
- *
- * @see #init
- */
- protected void create(DeviceData data) {
- }
-
- /**
- * Destroys the device in the operating system and releases the device's
- * handle. If the device does not have a handle, this method may do nothing
- * depending on the device.
- * <p>
- * This method is called after <code>release</code>.
- * </p>
- * <p>
- * Subclasses are supposed to reimplement this method and not call the
- * <code>super</code> implementation.
- * </p>
- *
- * @see #dispose
- * @see #release
- */
- protected void destroy() {
- }
-
- /**
- * Disposes of the operating system resources associated with the receiver.
- * After this method has been invoked, the receiver will answer
- * <code>true</code> when sent the message <code>isDisposed()</code>.
- *
- * @see #release
- * @see #destroy
- * @see #checkDevice
- */
- public void dispose() {
- synchronized (Device.class) {
- if (isDisposed()) {
- return;
- }
- checkDevice();
- release();
- destroy();
- disposed = true;
- if (tracking) {
- synchronized (trackingLock) {
- printErrors();
- objects = null;
- errors = null;
- trackingLock = null;
- }
- }
- }
- }
-
- void dispose_Object(Object object) {
- synchronized (trackingLock) {
- for (int i = 0; i < objects.length; i++) {
- if (objects[i] == object) {
- objects[i] = null;
- errors[i] = null;
- return;
- }
- }
- }
- }
-
- /**
- * Returns a rectangle describing the receiver's size and location.
- *
- * @return the bounding rectangle
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public Rectangle getBounds() {
- checkDevice();
- return new Rectangle(0, 0, paintDevice.width(), paintDevice.height());
- }
-
- /**
- * Returns a <code>DeviceData</code> based on the receiver. Modifications
- * made to this <code>DeviceData</code> will not affect the receiver.
- *
- * @return a <code>DeviceData</code> containing the device's data and
- * attributes
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see DeviceData
- */
- public DeviceData getDeviceData() {
- checkDevice();
- DeviceData data = new DeviceData();
- data.debug = debug;
- data.tracking = tracking;
- if (tracking) {
- synchronized (trackingLock) {
- int count = 0, length = objects.length;
- for (int i = 0; i < length; i++) {
- if (objects[i] != null) {
- count++;
- }
- }
- int index = 0;
- data.objects = new Object[count];
- data.errors = new Error[count];
- for (int i = 0; i < length; i++) {
- if (objects[i] != null) {
- data.objects[index] = objects[i];
- data.errors[index] = errors[i];
- index++;
- }
- }
- }
- } else {
- data.objects = new Object[0];
- data.errors = new Error[0];
- }
- return data;
- }
-
- /**
- * Returns a rectangle which describes the area of the receiver which is
- * capable of displaying data.
- *
- * @return the client area
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see #getBounds
- */
- public Rectangle getClientArea() {
- return getBounds();
- }
-
- /**
- * Returns the bit depth of the screen, which is the number of bits it takes
- * to represent the number of unique colors that the screen is currently
- * capable of displaying. This number will typically be one of 1, 8, 15, 16,
- * 24 or 32.
- *
- * @return the depth of the screen
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public int getDepth() {
- checkDevice();
- return paintDevice.depth();
- }
-
- /**
- * Returns a point whose x coordinate is the horizontal dots per inch of the
- * display, and whose y coordinate is the vertical dots per inch of the
- * display.
- *
- * @return the horizontal and vertical DPI
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public Point getDPI() {
- checkDevice();
- return new Point(paintDevice.physicalDpiX(), paintDevice.physicalDpiY());
- }
-
- /**
- * Returns <code>FontData</code> objects which describe the fonts that match
- * the given arguments. If the <code>faceName</code> is null, all fonts will
- * be returned.
- *
- * @param faceName
- * the name of the font to look for, or null
- * @param scalable
- * if true only scalable fonts are returned, otherwise only
- * non-scalable fonts are returned.
- * @return the matching font data
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public FontData[] getFontList(String faceName, boolean scalable) {
- checkDevice();
- QFontDatabase qFontDatabase = null;
- qFontDatabase = new QFontDatabase();
- String fontFamilies[] = qFontDatabase.families().toArray(new String[0]);
- // for storing FontData arrays
- List<FontData> fontData = new ArrayList<FontData>();
-
- for (int i = 0; i < fontFamilies.length; i++) {
- String family = null;
- if (faceName == null) {
- family = fontFamilies[i];
- } else {
- if (faceName.equals(fontFamilies[i])) {
- family = fontFamilies[i];
- } else {
- continue;
- }
- }
- getFontList(fontData, qFontDatabase, family, scalable);
- if (faceName != null) {
- break;
- }
- }
-
- qFontDatabase.dispose(); //TODO_DISPOSE (called many times)
- qFontDatabase = null;
-
- if (fontData.size() > 0) {
- FontData[] result = new FontData[fontData.size()];
- int size = fontData.size();
- for (int i = 0; i < size; ++i) {
- result[i] = fontData.get(i);
- }
- return result;
- } else {
- return new FontData[0];
- }
- }
-
- private void getFontList(List<FontData> fontData, QFontDatabase qFontDatabase, String family, boolean onlyScalable) {
- String nativeStyles[] = qFontDatabase.styles(family).toArray(new String[0]);
- int prevStyle = -1;
- int i = 0;
- // Go trough each native style of the font family, map them to SWT
- // styles
- // and create a new FontData for each newly found SWT style of the
- // family.
- // Still, it may be possible that there are no native styles for a
- // family,
- // in which case we add a single FontData with default SWT style:
- // NORMAL.
- // In addition we go trough all heights of non scalable font families,
- // creating a new FontData for all heights of all native styles.
- do {
- String nativeStyle = nativeStyles.length > 0 ? nativeStyles[i] : null;
- boolean isScalable = qFontDatabase.isScalable(family, nativeStyle);
- int style = SWT.NORMAL;
- if (qFontDatabase.bold(family, nativeStyle)) {
- style |= SWT.BOLD;
- }
- if (qFontDatabase.italic(family, nativeStyle)) {
- style |= SWT.ITALIC;
- }
- if (style != prevStyle) {
- prevStyle = style;
- int[] heights = null;
- int j = 0;
- if (onlyScalable && isScalable) {
- heights = new int[1];
- heights[0] = FontData.FONT_DEF_HEIGHT;
- } else if (!onlyScalable && !isScalable) {
- List<Integer> pointSizes = null;
- if (nativeStyle == null) {
- pointSizes = qFontDatabase.pointSizes(family);
- } else {
- pointSizes = qFontDatabase.pointSizes(family, nativeStyle);
- }
- heights = new int[pointSizes.size()];
- for (int x = 0; x < pointSizes.size(); x++) {
- heights[x] = pointSizes.get(x);
- }
- }
- if (heights != null) {
- do {
- FontData fd = new FontData(family, heights[j], style);
- fontData.add(fd);
- j++;
- } while (!onlyScalable && !isScalable && j < heights.length);
- }
- }
- i++;
- } while (i < nativeStyles.length);
- }
-
- /**
- * Returns the matching standard color for the given constant, which should
- * be one of the color constants specified in class <code>SWT</code>. Any
- * value other than one of the SWT color constants which is passed in will
- * result in the color black. This color should not be freed because it was
- * allocated by the system, not the application.
- *
- * @param id
- * the color constant
- * @return the matching color
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see SWT
- */
- public Color getSystemColor(int id) {
- checkDevice();
- int pixel = 0x00000000;
- switch (id) {
- case SWT.COLOR_WHITE:
- return Color.qt_new(this, QColor.white);
- case SWT.COLOR_BLACK:
- return Color.qt_new(this, QColor.black);
- case SWT.COLOR_RED:
- return Color.qt_new(this, QColor.red);
- case SWT.COLOR_DARK_RED:
- return Color.qt_new(this, QColor.darkRed);
- case SWT.COLOR_GREEN:
- return Color.qt_new(this, QColor.green);
- case SWT.COLOR_DARK_GREEN:
- return Color.qt_new(this, QColor.darkGreen);
- case SWT.COLOR_YELLOW:
- return Color.qt_new(this, QColor.yellow);
- case SWT.COLOR_DARK_YELLOW:
- return Color.qt_new(this, QColor.darkYellow);
- case SWT.COLOR_BLUE:
- return Color.qt_new(this, QColor.blue);
- case SWT.COLOR_DARK_BLUE:
- return Color.qt_new(this, QColor.darkBlue);
- case SWT.COLOR_MAGENTA:
- return Color.qt_new(this, QColor.magenta);
- case SWT.COLOR_DARK_MAGENTA:
- return Color.qt_new(this, QColor.magenta);
- case SWT.COLOR_CYAN:
- return Color.qt_new(this, QColor.cyan);
- case SWT.COLOR_DARK_CYAN:
- return Color.qt_new(this, QColor.darkCyan);
- case SWT.COLOR_GRAY:
- return Color.qt_new(this, QColor.gray);
- case SWT.COLOR_DARK_GRAY:
- return Color.qt_new(this, QColor.darkGray);
- case SWT.COLOR_LIST_BACKGROUND:
- return Color.qt_new(this, COLOR_LIST_BACKGROUND);
- case SWT.COLOR_LIST_FOREGROUND:
- return Color.qt_new(this, COLOR_LIST_FOREGROUND);
- case SWT.COLOR_LIST_SELECTION:
- return Color.qt_new(this, COLOR_LIST_SELECTION);
- case SWT.COLOR_LIST_SELECTION_TEXT:
- return Color.qt_new(this, COLOR_LIST_SELECTION_TEXT);
- case SWT.COLOR_TITLE_BACKGROUND:
- return Color.qt_new(this, COLOR_TITLE_BACKGROUND);
- case SWT.COLOR_TITLE_BACKGROUND_GRADIENT:
- return Color.qt_new(this, COLOR_TITLE_BACKGROUND_GRADIENT);
- case SWT.COLOR_TITLE_FOREGROUND:
- return Color.qt_new(this, COLOR_TITLE_FOREGROUND);
- case SWT.COLOR_TITLE_INACTIVE_BACKGROUND:
- return Color.qt_new(this, COLOR_TITLE_INACTIVE_BACKGROUND);
- case SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT:
- return Color.qt_new(this, COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT);
- case SWT.COLOR_TITLE_INACTIVE_FOREGROUND:
- return Color.qt_new(this, COLOR_TITLE_INACTIVE_FOREGROUND);
- case SWT.COLOR_WIDGET_BACKGROUND:
- return Color.qt_new(this, COLOR_WIDGET_BACKGROUND);
- case SWT.COLOR_WIDGET_BORDER:
- return Color.qt_new(this, COLOR_WIDGET_BORDER);
- case SWT.COLOR_WIDGET_DARK_SHADOW:
- return Color.qt_new(this, COLOR_WIDGET_DARK_SHADOW);
- case SWT.COLOR_WIDGET_FOREGROUND:
- return Color.qt_new(this, COLOR_WIDGET_FOREGROUND);
- case SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW:
- return Color.qt_new(this, COLOR_WIDGET_HIGHLIGHT_SHADOW);
- case SWT.COLOR_WIDGET_LIGHT_SHADOW:
- return Color.qt_new(this, COLOR_WIDGET_LIGHT_SHADOW);
- case SWT.COLOR_WIDGET_NORMAL_SHADOW:
- return Color.qt_new(this, COLOR_WIDGET_NORMAL_SHADOW);
- case SWT.COLOR_INFO_FOREGROUND:
- return Color.qt_new(this, COLOR_INFO_FOREGROUND);
- case SWT.COLOR_INFO_BACKGROUND:
- return Color.qt_new(this, COLOR_INFO_BACKGROUND);
- }
- return Color.qt_new(this, pixel);
- }
-
- /**
- * Returns a reasonable font for applications to use. On some platforms,
- * this will match the "default font" or "system font" if such can be found.
- * This font should not be freed because it was allocated by the system, not
- * the application.
- * <p>
- * Typically, applications which want the default look should simply not set
- * the font on the widgets they create. Widgets are always created with the
- * correct default font for the class of user-interface component they
- * represent.
- * </p>
- *
- * @return a font
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public Font getSystemFont() {
- checkDevice();
- return Font.qt_new(this, QApplication.font());
- }
-
- /**
- * Returns <code>true</code> if the underlying window system prints out
- * warning messages on the console, and <code>setWarnings</code> had
- * previously been called with <code>true</code>.
- *
- * @return <code>true</code>if warnings are being handled, and
- * <code>false</code> otherwise
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public boolean getWarnings() {
- checkDevice();
- return false;
- }
-
- /**
- * Initializes any internal resources needed by the device.
- * <p>
- * This method is called after <code>create</code>.
- * </p>
- * <p>
- * If subclasses reimplement this method, they must call the
- * <code>super</code> implementation.
- * </p>
- *
- * @see #create
- */
- protected void init() {
- /* Initialize the system font slot */
- systemFont = getSystemFont();
- QPalette palette = QApplication.style().standardPalette();
- try {
- // Mapping colors from the QPalette to SWT colors. Not all
- // colors are 100% right. Use snippet 235 and 235_1 to get
- // all colors displayed.
-
- // Info
- COLOR_INFO_FOREGROUND = palette.color(ColorGroup.Active, ColorRole.ToolTipText);
- COLOR_INFO_BACKGROUND = palette.color(ColorGroup.Active, ColorRole.ToolTipBase);
-
- // List
- COLOR_LIST_BACKGROUND = palette.color(ColorGroup.Active, ColorRole.Base);
- COLOR_LIST_FOREGROUND = palette.color(ColorGroup.Active, ColorRole.Text);
- COLOR_LIST_SELECTION = palette.color(ColorGroup.Active, ColorRole.Highlight);
- COLOR_LIST_SELECTION_TEXT = palette.color(ColorGroup.Active, ColorRole.HighlightedText);
-
- // Title
- COLOR_TITLE_BACKGROUND = new QColor(0, 84, 227); // palette.color(ColorGroup.Active, ColorRole.Highlight);
- // TODO The required blue/grey does not exist in QPalette. Using grey as a substitute.
- COLOR_TITLE_BACKGROUND_GRADIENT = new QColor(61, 149, 255);// palette.color(ColorGroup.Active, ColorRole.Light);
- COLOR_TITLE_FOREGROUND = palette.color(ColorGroup.Active, ColorRole.HighlightedText);
-
- // Inactive highlight
- COLOR_TITLE_INACTIVE_BACKGROUND = new QColor(122, 150, 223);// palette.color(ColorGroup.Inactive, ColorRole.Dark);
- // TODO The required shade of grey does not exist in QPalette. Should be a bit lighter.
- COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT = new QColor(157, 185, 235); //palette.color(ColorGroup.Inactive, ColorRole.Light);
- // TODO The required shade of grey does not exist in QPalette. Should be a bit lighter.
- // Even lighter still than background gradient. It's the same at the moment.
- COLOR_TITLE_INACTIVE_FOREGROUND = new QColor(216, 228, 248); //palette.color(ColorGroup.Inactive, ColorRole.BrightText);
-
- // Window
- //QApplication.style().
- COLOR_WIDGET_BACKGROUND = palette.color(ColorGroup.Active, ColorRole.Window);//new QColor(239, 235, 231);
- COLOR_WIDGET_DARK_SHADOW = palette.color(ColorGroup.Active, ColorRole.Shadow);
- COLOR_WIDGET_FOREGROUND = COLOR_WIDGET_BORDER = palette.color(ColorGroup.Active, ColorRole.WindowText);
- COLOR_WIDGET_HIGHLIGHT_SHADOW = palette.color(ColorGroup.Active, ColorRole.Light);
-
- COLOR_WIDGET_LIGHT_SHADOW = new QColor(236, 233, 216); //palette.color(ColorGroup.Active, ColorRole.Button);
- COLOR_WIDGET_NORMAL_SHADOW = new QColor(157, 155, 144); //palette.color(ColorGroup.Active, ColorRole.Mid);
-
- } finally {
- palette.dispose();
- }
- }
-
- /**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public API for
- * <code>Device</code>. 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.
- * </p>
- *
- * @param data
- * the platform specific GC data
- * @return the platform specific GC handle
- */
- public abstract QPaintDeviceInterface internal_new_GC(GCData data);
-
- /**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public API for
- * <code>Device</code>. 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.
- * </p>
- *
- * @param hDC
- * the platform specific GC handle
- * @param data
- * the platform specific GC data
- */
- public abstract void internal_dispose_GC(QPaintDeviceInterface paintDevice, GCData data);
-
- /**
- * Returns <code>true</code> if the device has been disposed, and
- * <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the device. When a device has been
- * disposed, it is an error to invoke any other method using the device.
- *
- * @return <code>true</code> when the device is disposed and
- * <code>false</code> otherwise
- */
- public boolean isDisposed() {
- synchronized (Device.class) {
- return disposed;
- }
- }
-
- /**
- * Loads the font specified by a file. The font will be present in the list
- * of fonts available to the application.
- *
- * @param path
- * the font file path
- * @return whether the font was successfully loaded
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if path is null</li>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see Font
- *
- * @since 3.3
- */
- public boolean loadFont(String path) {
- checkDevice();
- if (path == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- int retCode = QFontDatabase.addApplicationFont(path);
- return retCode != -1; // -1 == font load failed
- }
-
- void new_Object(Object object) {
- synchronized (trackingLock) {
- for (int i = 0; i < objects.length; i++) {
- if (objects[i] == null) {
- objects[i] = object;
- errors[i] = new Error();
- return;
- }
- }
- Object[] newObjects = new Object[objects.length + 128];
- System.arraycopy(objects, 0, newObjects, 0, objects.length);
- newObjects[objects.length] = object;
- objects = newObjects;
- Error[] newErrors = new Error[errors.length + 128];
- System.arraycopy(errors, 0, newErrors, 0, errors.length);
- newErrors[errors.length] = new Error();
- errors = newErrors;
- }
- }
-
- void printErrors() {
- if (!DEBUG) {
- return;
- }
- if (tracking) {
- synchronized (trackingLock) {
- if (objects == null || errors == null) {
- return;
- }
- int objectCount = 0;
- int colors = 0, cursors = 0, fonts = 0, gcs = 0, images = 0;
- int paths = 0, patterns = 0, regions = 0, textLayouts = 0, transforms = 0;
- for (int i = 0; i < objects.length; i++) {
- Object object = objects[i];
- if (object != null) {
- objectCount++;
- if (object instanceof Color) {
- colors++;
- }
- if (object instanceof Cursor) {
- cursors++;
- }
- if (object instanceof Font) {
- fonts++;
- }
- if (object instanceof GC) {
- gcs++;
- }
- if (object instanceof Image) {
- images++;
- }
- if (object instanceof Path) {
- paths++;
- }
- if (object instanceof Pattern) {
- patterns++;
- }
- if (object instanceof Region) {
- regions++;
- }
- if (object instanceof TextLayout) {
- textLayouts++;
- }
- if (object instanceof Transform) {
- transforms++;
- }
- }
- }
- if (objectCount != 0) {
- String string = "Summary: "; //$NON-NLS-1$
- if (colors != 0) {
- string += colors + " Color(s), ";//$NON-NLS-1$
- }
- if (cursors != 0) {
- string += cursors + " Cursor(s), ";//$NON-NLS-1$
- }
- if (fonts != 0) {
- string += fonts + " Font(s), ";//$NON-NLS-1$
- }
- if (gcs != 0) {
- string += gcs + " GC(s), ";//$NON-NLS-1$
- }
- if (images != 0) {
- string += images + " Image(s), ";//$NON-NLS-1$
- }
- if (paths != 0) {
- string += paths + " Path(s), ";//$NON-NLS-1$
- }
- if (patterns != 0) {
- string += patterns + " Pattern(s), ";//$NON-NLS-1$
- }
- if (regions != 0) {
- string += regions + " Region(s), ";//$NON-NLS-1$
- }
- if (textLayouts != 0) {
- string += textLayouts + " TextLayout(s), ";//$NON-NLS-1$
- }
- if (transforms != 0) {
- string += transforms + " Transforms(s), ";//$NON-NLS-1$
- }
- if (string.length() != 0) {
- string = string.substring(0, string.length() - 2);
- System.err.println(string);
- }
- for (int i = 0; i < errors.length; i++) {
- if (errors[i] != null) {
- errors[i].printStackTrace(System.err);
- }
- }
- }
- }
- }
- }
-
- /**
- * Releases any internal resources back to the operating system and clears
- * all fields except the device handle.
- * <p>
- * When a device is destroyed, resources that were acquired on behalf of the
- * programmer need to be returned to the operating system. For example, if
- * the device allocated a font to be used as the system font, this font
- * would be freed in <code>release</code>. Also,to assist the garbage
- * collector and minimize the amount of memory that is not reclaimed when
- * the programmer keeps a reference to a disposed device, all fields except
- * the handle are zero'd. The handle is needed by <code>destroy</code>.
- * </p>
- * This method is called before <code>destroy</code>. </p>
- * <p>
- * If subclasses reimplement this method, they must call the
- * <code>super</code> implementation.
- * </p>
- *
- * @see #dispose
- * @see #destroy
- */
- protected void release() {
- paintDevice = null;
- }
-
- /**
- * If the underlying window system supports printing warning messages to the
- * console, setting warnings to <code>false</code> prevents these messages
- * from being printed. If the argument is <code>true</code> then message
- * printing is not blocked.
- *
- * @param warnings
- * <code>true</code>if warnings should be printed, and
- * <code>false</code> otherwise
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_DEVICE_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void setWarnings(boolean warnings) {
- checkDevice();
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/DeviceData.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/DeviceData.java
deleted file mode 100644
index 8dd1012d58..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/DeviceData.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2005 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-public class DeviceData {
- /*
- * Debug fields - may not be honoured on some SWT platforms.
- */
- public boolean debug;
- public boolean tracking;
- public Error[] errors;
- public Object[] objects;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Font.java
deleted file mode 100644
index 0758f4d05f..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Font.java
+++ /dev/null
@@ -1,379 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import com.trolltech.qt.gui.QFont;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTError;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.internal.qt.QtSupplementaryFontData;
-import org.eclipse.swt.internal.qt.SWQT;
-
-/**
- * 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 <code>FontData</code>
- * object which encapsulates this data.
- * <p>
- * Application code must explicitly invoke the <code>Font.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see FontData
- * @see <a href="http://www.eclipse.org/swt/snippets/#font">Font snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples:
- * GraphicsExample, PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further
- * information</a>
- */
-
-public final class Font extends Resource {
-
- /**
- * the handle to the OS font resource (Warning: This field is platform
- * dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> 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.
- * </p>
- */
- private QFont font;
-
- boolean extraFontStyle;
- String xlfd;
-
- /**
- * Prevents uninitialized instances from being created outside the package.
- */
- Font() {
- }
-
- /**
- * Prevents uninitialized instances from being created outside the package.
- */
- Font(Device device) {
- super(device);
- }
-
- /**
- * Constructs a new font given a device and font data which describes the
- * desired font's appearance.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device
- * the device to create the font on
- * @param fd
- * the FontData that describes the desired font (must not be
- * null)
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is
- * no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the fd argument is null</li>
- * </ul>
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from
- * the given font data</li>
- * </ul>
- */
- public Font(Device device, FontData fd) {
- super(device);
- init(fd);
- init();
- }
-
- /**
- * Constructs a new font given a device and an array of font data which
- * describes the desired font's appearance.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @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
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is
- * no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the fds argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the length of fds is zero</li>
- * <li>ERROR_NULL_ARGUMENT - if any fd in the array is null</li>
- * </ul>
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from
- * the given font data</li>
- * </ul>
- *
- * @since 2.1
- */
- public Font(Device device, FontData[] fds) {
- super(device);
- if (fds == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (fds.length == 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- for (int i = 0; i < fds.length; i++) {
- if (fds[i] == null) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- init(fds[0]);
- init();
- }
-
- /**
- * Constructs a new font given a device, a font name, the height of the
- * desired font in points, and a font style.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @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
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is
- * no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the name argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from
- * the given arguments</li>
- * </ul>
- */
- public Font(Device device, String name, int height, int style) {
- super(device);
- if (name == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- init(new FontData(name, height, style));
- init();
- }
-
- public QFont getQFont() {
- return font;
- }
-
- // /*public*/ Font(Device device, String name, float height, int style) {
- // super(device);
- // if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- // init(new FontData (name, height, style));
- // init();
- // }
- @Override
- void destroy() {
- font.dispose(); // TODO_DISPOSE
- font = null;
-
- }
-
- /**
- * Compares the argument to the receiver, and returns true if they represent
- * the <em>same</em> object using a class specific comparison.
- *
- * @param object
- * the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and
- * <code>false</code> otherwise
- *
- * @see #hashCode
- */
- @Override
- public boolean equals(Object object) {
- if (object == this) {
- return true;
- }
- if (!(object instanceof Font)) {
- return false;
- }
- Font font = (Font) object;
- return this.getQFont().equals(font.getQFont());
- }
-
- /**
- * Returns an array of <code>FontData</code>s representing the receiver. On
- * Windows, only one FontData will be returned per font. On X however, a
- * <code>Font</code> object <em>may</em> 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
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public FontData[] getFontData() {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- String family = font.family();
- int pointSize = font.pointSize();
- int weight = font.weight();
- boolean italic = font.italic();
-
- int style = SWT.NORMAL;
- if (weight > SWQT.QT_FONTNORMAL) {
- style |= SWT.BOLD;
- }
- if (italic) {
- style |= SWT.ITALIC;
- }
- FontData data = new FontData(family, pointSize, style);
- if (xlfd != null) {
- data.xlfd = xlfd;
- } else if (extraFontStyle) {
- data.extraFontData = new QtSupplementaryFontData();
- QtSupplementaryFontData extraData = data.extraFontData;
- extraData.underline = font.underline() ? 1 : 0;
- extraData.overline = font.overline() ? 1 : 0;
- extraData.strikeOut = font.strikeOut() ? 1 : 0;
- extraData.stretch = font.stretch();
- extraData.fixedPitch = font.fixedPitch() ? 1 : 0;
- extraData.style = font.style();
- extraData.weight = font.weight();
- extraData.styleStrategy = font.styleStrategy();
- }
- return new FontData[] { data };
- }
-
- /**
- * Returns an integer hash code for the receiver. Any two objects that
- * return <code>true</code> when passed to <code>equals</code> must return
- * the same value for this method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
- @Override
- public int hashCode() {
- if (font == null) {
- return 0;
- }
- return font.toString().hashCode(); // TODO
- }
-
- void init(FontData fd) {
- if (fd == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- int weight = QFont.Weight.Normal.value();
- boolean italic = false;
- if (fd.extraFontData != null) {
- weight = fd.extraFontData.weight;
- italic = fd.extraFontData.style == QFont.Style.StyleItalic;
- }
-
- font = new QFont(fd.name, fd.getHeight(), weight, italic);
- // TODO font can be BOLD AND ITALIC
- if (fd.style == SWT.BOLD) {
- font.setBold(true);
- }
- if (fd.style == SWT.ITALIC) {
- font.setItalic(true);
- }
- // int lfHeight = fontData.lfHeight;
- // fontData.lfHeight = device.computePixels(fd.height);
- // handle = OS.CreateFontIndirect(logFont);
- // fontData.lfHeight = lfHeight;
- // if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- }
-
- /**
- * Returns <code>true</code> if the font has been disposed, and
- * <code>false</code> otherwise.
- * <p>
- * 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 <code>true</code> when the font is disposed and
- * <code>false</code> otherwise
- */
- @Override
- public boolean isDisposed() {
- return font == null;
- }
-
- /**
- * Returns a string containing a concise, human-readable description of the
- * receiver.
- *
- * @return a string representation of the receiver
- */
- @Override
- public String toString() {
- if (isDisposed()) {
- return "Font {*DISPOSED*}"; //$NON-NLS-1$
- }
- return "Font {" + font.family() + "}"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Invokes platform specific functionality to allocate a new font.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public API for
- * <code>Font</code>. 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.
- * </p>
- *
- * @param device
- * the device on which to allocate the color
- * @param handle
- * the handle for the font
- * @return a new font object containing the specified device and handle
- */
- public static Font qt_new(Device device, QFont fontParm) {
- if (fontParm == null) {
- return null;
- }
- if (device == null) {
- device = Device.getDevice();
- }
- if (device == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- Font font = new Font();
- font.font = fontParm;
- font.device = device;
- return font;
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/FontData.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/FontData.java
deleted file mode 100644
index 89db2b04ff..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/FontData.java
+++ /dev/null
@@ -1,722 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
- * Portion Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Nokia Corporation - Qt implementation
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import com.trolltech.qt.gui.QFont;
-import com.trolltech.qt.gui.QFont.Style;
-import com.trolltech.qt.gui.QFont.StyleStrategy;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.internal.qt.QtSupplementaryFontData;
-import org.eclipse.swt.internal.qt.SWQT;
-
-/**
- * Instances of this class describe operating system fonts.
- * <p>
- * For platform-independent behaviour, use the get and set methods corresponding
- * to the following properties:
- * <dl>
- * <dt>height</dt>
- * <dd>the height of the font in points</dd>
- * <dt>name</dt>
- * <dd>the face name of the font, which may include the foundry</dd>
- * <dt>style</dt>
- * <dd>A bitwise combination of NORMAL, ITALIC and BOLD</dd>
- * </dl>
- * If extra, platform-dependent functionality is required:
- * <ul>
- * <li>On <em>Windows</em>, the data member of the <code>FontData</code>
- * corresponds to a Windows <code>LOGFONT</code> structure whose fields may be
- * retrieved and modified.</li>
- * <li>On <em>X</em>, the fields of the <code>FontData</code> correspond to the
- * entries in the font's XLFD name and may be retrieved and modified.
- * </ul>
- * Application code does <em>not</em> need to explicitly release the resources
- * managed by each instance when those instances are no longer required, and
- * thus no <code>dispose()</code> method is provided.
- *
- * @see Font
- */
-public final class FontData {
- /**
- * the font name
- */
- String name;
-
- /**
- * The height of the font data in points
- */
- int height;
-
- /**
- * the font style
- */
- int style;
-
- /**
- * The locales of the font
- */
- String lang, country, variant;
-
- QtSupplementaryFontData extraFontData;
- String xlfd;
-
- public static final int FONT_DEF_HEIGHT = 12;
-
- /**
- * Constructs a new uninitialized font data.
- */
- public FontData() {
- this("", FONT_DEF_HEIGHT, SWT.NORMAL); //$NON-NLS-1$
- }
-
- // The characters in the string must all be decimal digits
- // the value must be given with radix 10
-
- /**
- * Constructs a new FontData given a string representation in the form
- * generated by the <code>FontData.toString</code> method.
- * <p>
- * Note that the representation varies between platforms, and a FontData can
- * only be created from a string that was generated on the same platform.
- * </p>
- *
- * @param string
- * the string representation of a <code>FontData</code> (must not
- * be null)
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument does not
- * represent a valid description</li>
- * </ul>
- *
- * @see #toString
- */
- public FontData(String string) {
- if (string == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- parseFontDescriptor(string);
- updateFontData();
-
- }
-
- /**
- * Constructs a new font data given a font name, the height of the desired
- * font in points, and a font style.
- *
- * @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
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - when the font name is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- */
- public FontData(String name, int height, int style) {
- if (name == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (height < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- setName(name);
- setHeight(height);
- setStyle(style);
- }
-
- /**
- * Compares the argument to the receiver, and returns true if they represent
- * the <em>same</em> object using a class specific comparison.
- *
- * @param object
- * the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and
- * <code>false</code> otherwise
- *
- * @see #hashCode
- */
- @Override
- public boolean equals(Object object) {
- if (object == this) {
- return true;
- }
- if (!(object instanceof FontData)) {
- return false;
- }
-
- FontData data = (FontData) object;
-
- if (!(xlfd == null && data.xlfd == null || xlfd != null && data.xlfd != null)) {
- return false;
- }
-
- if (!(extraFontData == null && data.extraFontData == null || extraFontData != null
- && data.extraFontData != null)) {
- return false;
- }
-
- if (xlfd != null) {
- return xlfd.trim().equals(data.xlfd.trim());
- }
-
- boolean mainFontStyleEqual = name.equals(data.name) && height == data.height && style == data.style;
- if (mainFontStyleEqual && extraFontData != null) {
- return mainFontStyleEqual && extraFontData.underline == data.extraFontData.underline
- && extraFontData.underline == data.extraFontData.underline
- && extraFontData.overline == data.extraFontData.overline
- && extraFontData.strikeOut == data.extraFontData.strikeOut
- && extraFontData.stretch == data.extraFontData.stretch
- && extraFontData.fixedPitch == data.extraFontData.fixedPitch
- && extraFontData.style == data.extraFontData.style
- && extraFontData.weight == data.extraFontData.weight
- && extraFontData.styleStrategy == data.extraFontData.styleStrategy;
- } else {
- return mainFontStyleEqual;
- }
- }
-
- /**
- * Returns the height of the receiver in points.
- *
- * @return the height of this FontData
- *
- * @see #setHeight(int)
- */
- public int getHeight() {
- return height;
- }
-
- /**
- * Returns the locale of the receiver.
- * <p>
- * The locale determines which platform character set this font is going to
- * use. Widgets and graphics operations that use this font will convert
- * UNICODE strings to the platform character set of the specified locale.
- * </p>
- * <p>
- * On platforms where there are multiple character sets for a given
- * language/country locale, the variant portion of the locale will determine
- * the character set.
- * </p>
- *
- * @return the <code>String</code> representing a Locale object
- * @since 3.0
- */
- public String getLocale() {
- StringBuffer buffer = new StringBuffer();
- char sep = '_';
- if (lang != null) {
- buffer.append(lang);
- buffer.append(sep);
- }
- if (country != null) {
- buffer.append(country);
- buffer.append(sep);
- }
- if (variant != null) {
- buffer.append(variant);
- }
-
- String result = buffer.toString();
- int length = result.length();
- if (length > 0) {
- if (result.charAt(length - 1) == sep) {
- result = result.substring(0, length - 1);
- }
- }
- return result;
- }
-
- /**
- * Returns the name of the receiver. On platforms that support font
- * foundries, the return value will be the foundry followed by a dash ("-")
- * followed by the face name.
- *
- * @return the name of this <code>FontData</code>
- *
- * @see #setName
- */
- public String getName() {
- return name;
- }
-
- /**
- * Returns the style of the receiver which is a bitwise OR of one or more of
- * the <code>SWT</code> constants NORMAL, BOLD and ITALIC.
- *
- * @return the style of this <code>FontData</code>
- *
- * @see #setStyle
- */
- public int getStyle() {
- return style;
- }
-
- /**
- * Returns an integer hash code for the receiver. Any two objects that
- * return <code>true</code> when passed to <code>equals</code> must return
- * the same value for this method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
- @Override
- public int hashCode() {
- return name.hashCode() ^ height ^ style;
- }
-
- void parseFontDescriptor(String string) {
- int start = 0;
- int end = string.indexOf('|');
- if (end == -1) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- String version1 = string.substring(start, end);
- try {
- if (Integer.parseInt(version1) != 1) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- String name = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int height = 0;
- try {
- height = Integer.parseInt(string.substring(start, end));
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int style = 0;
- try {
- style = Integer.parseInt(string.substring(start, end));
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- setName(name);
- setHeight(height);
- setStyle(style);
- if (end == -1) {
- return;
- }
- String platform = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) {
- return;
- }
- String version2 = string.substring(start, end);
-
- if (platform.trim().toUpperCase().equals("QT") && version2.equals("1")) { //$NON-NLS-1$ //$NON-NLS-2$
- try {
- extraFontData = new QtSupplementaryFontData();
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) {
- return;
- }
- extraFontData.underline = Integer.parseInt(string.substring(start, end));
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) {
- return;
- }
- extraFontData.overline = Integer.parseInt(string.substring(start, end));
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) {
- return;
- }
- extraFontData.strikeOut = Integer.parseInt(string.substring(start, end));
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) {
- return;
- }
- int stretch = Integer.parseInt(string.substring(start, end));
- if (stretch > 0) {
- if (stretch > 4000) {
- stretch = 4000;
- }
- extraFontData.stretch = stretch;
- }
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) {
- extraFontData = null;
- return;
- }
- extraFontData.fixedPitch = Integer.parseInt(string.substring(start, end));
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) {
- return;
- }
- int fontStyle = Integer.parseInt(string.substring(start, end));
- if (fontStyle == SWQT.QFONT_STYLE_NORMAL) {
- extraFontData.style = Style.StyleNormal;
- }
- if (fontStyle == SWQT.QFONT_STYLE_ITALIC) {
- extraFontData.style = Style.StyleItalic;
- }
- if (fontStyle == SWQT.QFONT_STYLE_OBLIQUE) {
- extraFontData.style = Style.StyleOblique;
- }
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) {
- return;
- }
- int weight = Integer.parseInt(string.substring(start, end));
- if (weight > -1) {
- if (weight > 99) {
- weight = 99;
- }
- extraFontData.weight = weight;
- }
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) {
- return;
- }
- int styleStrategy = Integer.parseInt(string.substring(start, end));
- int[] strategies = new int[] { SWQT.QFONT_STYLESTRATEGY_PREFERDEFALUT,
- SWQT.QFONT_STYLESTRATEGY_PREFERBITMAP, SWQT.QFONT_STYLESTRATEGY_PREFERDEVICE,
- SWQT.QFONT_STYLESTRATEGY_PREFEROUTLINE, SWQT.QFONT_STYLESTRATEGY_FORCEOUTLINE,
- SWQT.QFONT_STYLESTRATEGY_NOANTIALIAS, SWQT.QFONT_STYLESTRATEGY_PREFERANTIALIAS,
- SWQT.QFONT_STYLESTRATEGY_OPENGLCOMPATIABLE, SWQT.QFONT_STYLESTRATEGY_NOFONTMERGING };
- boolean isValidStrategy = styleStrategy == SWQT.QFONT_STYLESTRATEGY_PREFERQUALITY
- || styleStrategy == SWQT.QFONT_STYLESTRATEGY_PREFERMATCH ? true : false;
- for (int i = 0; i < strategies.length; i++) {
- if ((styleStrategy & strategies[i]) == 0) {
- continue;
- } else {
- if (styleStrategy == strategies[i]
- || styleStrategy == (strategies[i] | SWQT.QFONT_STYLESTRATEGY_PREFERQUALITY)
- || styleStrategy == (strategies[i] | SWQT.QFONT_STYLESTRATEGY_PREFERMATCH)) {
- isValidStrategy = true;
- }
- break;
- }
- }
- if (isValidStrategy) {
- if (styleStrategy == SWQT.QFONT_STYLESTRATEGY_FORCEOUTLINE) {
- extraFontData.styleStrategy = StyleStrategy.ForceOutline;
- }
- if (styleStrategy == SWQT.QFONT_STYLESTRATEGY_NOANTIALIAS) {
- extraFontData.styleStrategy = StyleStrategy.NoAntialias;
- }
- if (styleStrategy == SWQT.QFONT_STYLESTRATEGY_NOFONTMERGING) {
- extraFontData.styleStrategy = StyleStrategy.NoFontMerging;
- }
- if (styleStrategy == SWQT.QFONT_STYLESTRATEGY_OPENGLCOMPATIABLE) {
- extraFontData.styleStrategy = StyleStrategy.OpenGLCompatible;
- }
- if (styleStrategy == SWQT.QFONT_STYLESTRATEGY_PREFERANTIALIAS) {
- extraFontData.styleStrategy = StyleStrategy.PreferAntialias;
- }
- if (styleStrategy == SWQT.QFONT_STYLESTRATEGY_PREFERBITMAP) {
- extraFontData.styleStrategy = StyleStrategy.PreferBitmap;
- }
- if (styleStrategy == SWQT.QFONT_STYLESTRATEGY_PREFERDEFALUT) {
- extraFontData.styleStrategy = StyleStrategy.PreferDefault;
- }
- if (styleStrategy == SWQT.QFONT_STYLESTRATEGY_PREFERDEVICE) {
- extraFontData.styleStrategy = StyleStrategy.PreferDevice;
- }
- if (styleStrategy == SWQT.QFONT_STYLESTRATEGY_PREFERMATCH) {
- extraFontData.styleStrategy = StyleStrategy.PreferMatch;
- }
- if (styleStrategy == SWQT.QFONT_STYLESTRATEGY_PREFEROUTLINE) {
- extraFontData.styleStrategy = StyleStrategy.PreferOutline;
- }
- if (styleStrategy == SWQT.QFONT_STYLESTRATEGY_PREFERQUALITY) {
- extraFontData.styleStrategy = StyleStrategy.PreferQuality;
- }
- }
- } catch (NumberFormatException e) {
- extraFontData = null;
- }
- }
- // else if (platform.trim().toUpperCase().equals("X11")
- // && OS.windowServer == OS.WS_X11) {
- // start = end + 1;
- // end = string.indexOf('|', start);
- // if (end == -1)
- // return;
- // xlfd = string.substring(start, end);
- // if (xlfd.length() < 1) {
- // xlfd = null;
- // }
- // }
-
- }
-
- /**
- * Sets the height of the receiver. The parameter is specified in terms of
- * points, where a point is one seventy-second of an inch.
- *
- * @param height
- * the height of the <code>FontData</code>
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li>
- * </ul>
- *
- * @see #getHeight
- */
- public void setHeight(int height) {
- if (height < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- this.height = height;
- }
-
- /**
- * Sets the locale of the receiver.
- * <p>
- * The locale determines which platform character set this font is going to
- * use. Widgets and graphics operations that use this font will convert
- * UNICODE strings to the platform character set of the specified locale.
- * </p>
- * <p>
- * On platforms where there are multiple character sets for a given
- * language/country locale, the variant portion of the locale will determine
- * the character set.
- * </p>
- *
- * @param locale
- * the <code>String</code> representing a Locale object
- * @see java.util.Locale#toString
- */
- public void setLocale(String locale) {
- lang = country = variant = null;
- if (locale != null) {
- char sep = '_';
- int length = locale.length();
- int firstSep, secondSep;
-
- firstSep = locale.indexOf(sep);
- if (firstSep == -1) {
- firstSep = secondSep = length;
- } else {
- secondSep = locale.indexOf(sep, firstSep + 1);
- if (secondSep == -1) {
- secondSep = length;
- }
- }
- if (firstSep > 0) {
- lang = locale.substring(0, firstSep);
- }
- if (secondSep > firstSep + 1) {
- country = locale.substring(firstSep + 1, secondSep);
- }
- if (length > secondSep + 1) {
- variant = locale.substring(secondSep + 1);
- }
- }
- }
-
- /**
- * Sets the name of the receiver.
- * <p>
- * Some platforms support font foundries. On these platforms, the name of
- * the font specified in setName() may have one of the following forms:
- * <ol>
- * <li>a face name (for example, "courier")</li>
- * <li>a foundry followed by a dash ("-") followed by a face name (for
- * example, "adobe-courier")</li>
- * </ol>
- * In either case, the name returned from getName() will include the
- * foundry.
- * </p>
- * <p>
- * On platforms that do not support font foundries, only the face name (for
- * example, "courier") is used in <code>setName()</code> and
- * <code>getName()</code>.
- * </p>
- *
- * @param name
- * the name of the font data (must not be null)
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - when the font name is null</li>
- * </ul>
- *
- * @see #getName
- */
- public void setName(String name) {
- if (name == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- this.name = name;
- }
-
- /**
- * Sets the style of the receiver to the argument which must be a bitwise OR
- * of one or more of the <code>SWT</code> constants NORMAL, BOLD and ITALIC.
- * All other style bits are ignored.
- *
- * @param style
- * the new style for this <code>FontData</code>
- *
- * @see #getStyle
- */
- public void setStyle(int style) {
- this.style = style;
- }
-
- /**
- * Returns a string representation of the receiver which is suitable for
- * constructing an equivalent instance using the
- * <code>FontData(String)</code> constructor.
- *
- * @return a string representation of the FontData
- *
- * @see FontData
- */
- @Override
- public String toString() {
- StringBuffer buffer = new StringBuffer();
- buffer.append("1|"); //$NON-NLS-1$
- buffer.append(getName());
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(getHeight());
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(getStyle());
- buffer.append("|"); //$NON-NLS-1$
- if (xlfd != null) {
- buffer.append("X11|1|"); //$NON-NLS-1$
- buffer.append(xlfd);
- buffer.append("|"); //$NON-NLS-1$
- } else if (extraFontData != null) {
- buffer.append("QT|1|"); //$NON-NLS-1$
- buffer.append(extraFontData.overline);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(extraFontData.underline);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(extraFontData.strikeOut);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(extraFontData.stretch);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(extraFontData.fixedPitch);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(extraFontData.style);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(extraFontData.weight);
- buffer.append("|"); //$NON-NLS-1$
- buffer.append(extraFontData.styleStrategy);
- buffer.append("|"); //$NON-NLS-1$
- }
- return buffer.toString();
- }
-
- void updateFontData() {
- if (extraFontData == null && xlfd == null) {
- return;
- }
-
- boolean italic = (style & SWT.ITALIC) != 0;
- int weight = SWQT.QT_FONTNORMAL;
- if ((style & SWT.BOLD) != 0) {
- weight = SWQT.QT_FONTBOLD;
- }
- QFont font = new QFont(name, height, weight, italic);
-
- if (xlfd != null) {
- font.setRawName(xlfd);
-
- } else {
- if (extraFontData.underline > -1) {
- font.setUnderline(extraFontData.underline > 0 ? true : false);
- }
- if (extraFontData.overline > -1) {
- font.setOverline(extraFontData.overline > 0 ? true : false);
- }
- if (extraFontData.strikeOut > -1) {
- font.setStrikeOut(extraFontData.strikeOut > 0 ? true : false);
- }
- if (extraFontData.stretch > -1) {
- font.setStretch(extraFontData.stretch);
- }
- if (extraFontData.fixedPitch > -1) {
- font.setFixedPitch(extraFontData.fixedPitch > 0 ? true : false);
- }
- if (extraFontData.style != null) {
- font.setStyle(extraFontData.style);
- }
- if (extraFontData.weight > -1) {
- font.setWeight(extraFontData.weight);
- }
- if (extraFontData.styleStrategy != null) {
- font.setStyleStrategy(extraFontData.styleStrategy);
- }
- }
-
- name = font.family();
- height = font.pointSize();
- weight = font.weight();
- italic = font.italic();
- style = SWT.NORMAL;
- if (weight > SWQT.QT_FONTNORMAL) {
- style |= SWT.BOLD;
- }
- if (italic == true) {
- style |= SWT.ITALIC;
- }
- if (extraFontData != null) {
- extraFontData.underline = font.underline() == true ? 1 : 0;
- extraFontData.overline = font.overline() == true ? 1 : 0;
- extraFontData.strikeOut = font.strikeOut() == true ? 1 : 0;
- extraFontData.stretch = font.stretch();
- extraFontData.fixedPitch = font.fixedPitch() == true ? 1 : 0;
- extraFontData.style = font.style();
- extraFontData.weight = font.weight();
- extraFontData.styleStrategy = font.styleStrategy();
- font.dispose();
- }
- }
-} \ No newline at end of file
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/FontMetrics.java
deleted file mode 100644
index 2be6f6e78e..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/FontMetrics.java
+++ /dev/null
@@ -1,165 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import com.trolltech.qt.gui.QFontMetrics;
-
-/**
- * Instances of this class provide measurement information about fonts including
- * ascent, descent, height, leading space between rows, and average character
- * width. <code>FontMetrics</code> are obtained from <code>GC</code>s using the
- * <code>getFontMetrics()</code> method.
- *
- * @see GC#getFontMetrics
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further
- * information</a>
- */
-public final class FontMetrics {
- private final int ascent;
- private final int descent;
- private final int aveCharWidth;
- private final int leading;
- private final int height;
-
- private FontMetrics(int ascent, int descent, int aveCharWidth, int leading, int height) {
- this.ascent = ascent;
- this.descent = descent;
- this.aveCharWidth = aveCharWidth;
- this.leading = leading;
- this.height = height;
- }
-
- /**
- * Compares the argument to the receiver, and returns true if they represent
- * the <em>same</em> object using a class specific comparison.
- *
- * @param object
- * the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and
- * <code>false</code> otherwise
- *
- * @see #hashCode
- */
- @Override
- public boolean equals(Object object) {
- if (object == this) {
- return true;
- }
- if (!(object instanceof FontMetrics)) {
- return false;
- }
- FontMetrics other = (FontMetrics) object;
- return ascent == other.ascent && descent == other.descent && aveCharWidth == other.aveCharWidth
- && leading == other.leading && height == other.height;
- }
-
- /**
- * Returns the ascent of the font described by the receiver. A font's
- * <em>ascent</em> is the distance from the baseline to the top of actual
- * characters, not including any of the leading area, measured in pixels.
- *
- * @return the ascent of the font
- */
- public int getAscent() {
- return ascent;
- }
-
- /**
- * Returns the average character width, measured in pixels, of the font
- * described by the receiver.
- *
- * @return the average character width of the font
- */
- public int getAverageCharWidth() {
- return aveCharWidth;
- }
-
- /**
- * Returns the descent of the font described by the receiver. A font's
- * <em>descent</em> is the distance from the baseline to the bottom of
- * actual characters, not including any of the leading area, measured in
- * pixels.
- *
- * @return the descent of the font
- */
- public int getDescent() {
- return descent;
- }
-
- /**
- * Returns the height of the font described by the receiver, measured in
- * pixels. A font's <em>height</em> is the sum of its ascent, descent and
- * leading area.
- *
- * @return the height of the font
- *
- * @see #getAscent
- * @see #getDescent
- * @see #getLeading
- */
- public int getHeight() {
- return height;
- }
-
- /**
- * Returns the leading area of the font described by the receiver. A font's
- * <em>leading area</em> is the space above its ascent which may include
- * accents or other marks.
- *
- * @return the leading space of the font
- */
- public int getLeading() {
- return leading;
- }
-
- /**
- * Returns an integer hash code for the receiver. Any two objects that
- * return <code>true</code> when passed to <code>equals</code> must return
- * the same value for this method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
- @Override
- public int hashCode() {
- return ascent ^ descent ^ aveCharWidth ^ leading ^ height;
- }
-
- /**
- * Invokes platform specific functionality to allocate a new font metrics.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public API for
- * <code>FontMetrics</code>. 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.
- * </p>
- *
- * @param metrics
- * the <code>QFontMetrics</code> containing information about a
- * font
- * @return a new font metrics object containing the specified
- * <code>TEXTMETRIC</code>
- */
- public static FontMetrics internal_new(QFontMetrics qfm) {
- return new FontMetrics(qfm.ascent(), qfm.descent(), qfm.averageCharWidth(), 0, qfm.height());
- }
-
- public static FontMetrics internal_new(Font font) {
- return internal_new(new QFontMetrics(font.getQFont()));
- }
-
- public static FontMetrics internal_new(int ascent, int descent, int aveCharWidth, int leading, int height) {
- return new FontMetrics(ascent, descent, aveCharWidth, leading, height);
- }
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/GC.java
deleted file mode 100644
index 026041b62b..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/GC.java
+++ /dev/null
@@ -1,3555 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import com.trolltech.qt.core.QPointF;
-import com.trolltech.qt.core.QRect;
-import com.trolltech.qt.core.Qt.AlignmentFlag;
-import com.trolltech.qt.core.Qt.BGMode;
-import com.trolltech.qt.core.Qt.FillRule;
-import com.trolltech.qt.core.Qt.PenStyle;
-import com.trolltech.qt.core.Qt.SizeMode;
-import com.trolltech.qt.core.Qt.TextFlag;
-import com.trolltech.qt.gui.QApplication;
-import com.trolltech.qt.gui.QBrush;
-import com.trolltech.qt.gui.QColor;
-import com.trolltech.qt.gui.QFontMetrics;
-import com.trolltech.qt.gui.QLinearGradient;
-import com.trolltech.qt.gui.QPaintDeviceInterface;
-import com.trolltech.qt.gui.QPainter;
-import com.trolltech.qt.gui.QPixmap;
-import com.trolltech.qt.gui.QPolygon;
-import com.trolltech.qt.gui.QRegion;
-import com.trolltech.qt.gui.QStyleOptionFocusRect;
-import com.trolltech.qt.gui.QStyle.PrimitiveElement;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTError;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.internal.qt.QtSWTConverter;
-
-/**
- * Class <code>GC</code> is where all of the drawing capabilities that are
- * supported by SWT are located. Instances are used to draw on either an
- * <code>Image</code>, a <code>Control</code>, or directly on a
- * <code>Display</code>.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd>
- * </dl>
- *
- * <p>
- * The SWT drawing coordinate system is the two-dimensional space with the
- * origin (0,0) at the top left corner of the drawing area and with (x,y) values
- * increasing to the right and downward respectively.
- * </p>
- *
- * <p>
- * The result of drawing on an image that was created with an indexed palette
- * using a color that is not in the palette is platform specific. Some platforms
- * will match to the nearest color while other will draw the color itself. This
- * happens because the allocated image might use a direct palette on platforms
- * that do not support indexed palette.
- * </p>
- *
- * <p>
- * Application code must explicitly invoke the <code>GC.dispose()</code> method
- * to release the operating system resources managed by each instance when those
- * instances are no longer required. This is <em>particularly</em> important on
- * Windows95 and Windows98 where the operating system has a limited number of
- * device contexts available.
- * </p>
- *
- * <p>
- * Note: Only one of LEFT_TO_RIGHT and RIGHT_TO_LEFT may be specified.
- * </p>
- *
- * @see org.eclipse.swt.events.PaintEvent
- * @see <a href="http://www.eclipse.org/swt/snippets/#gc">GC snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples:
- * GraphicsExample, PaintExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further
- * information</a>
- */
-public final class GC extends Resource {
-
- /**
- * the handle to the OS device context (Warning: This field is platform
- * dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> 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.
- * </p>
- */
- private QPaintDeviceInterface paintDevice;
- private QPainter activePainter;
- private QRegion activeClipping;
-
- public int handle;
-
- private Drawable drawable;
- private GCData data;
- private FillRule fillRule;
-
- private int antialias = SWT.OFF; // TODO make sure this flag does not get lost, currently not interpreted
-
- private static final int FOREGROUND = 1 << 0;
- private static final int BACKGROUND = 1 << 1;
- private static final int FONT = 1 << 2;
- private static final int LINE_STYLE = 1 << 3;
- private static final int LINE_WIDTH = 1 << 4;
- private static final int LINE_CAP = 1 << 5;
- private static final int LINE_JOIN = 1 << 6;
- private static final int LINE_MITERLIMIT = 1 << 7;
- private static final int FOREGROUND_TEXT = 1 << 8;
- private static final int BACKGROUND_TEXT = 1 << 9;
- private static final int BRUSH = 1 << 10;
- private static final int PEN = 1 << 11;
- private static final int NULL_BRUSH = 1 << 12;
- private static final int NULL_PEN = 1 << 13;
- private static final int DRAW_OFFSET = 1 << 14;
-
- /**
- * Prevents uninitialized instances from being created outside the package.
- */
- GC() {
- }
-
- /**
- * Constructs a new instance of this class which has been configured to draw
- * on the specified drawable. Sets the foreground color, background color
- * and font in the GC to match those in the drawable.
- * <p>
- * You must dispose the graphics context when it is no longer required.
- * </p>
- *
- * @param drawable
- * the drawable to draw on
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li>
- * <li>ERROR_NULL_ARGUMENT - if there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - if the drawable is an image
- * that is not a bitmap or an icon - if the drawable is an
- * image or printer that is already selected into another
- * graphics context</li>
- * </ul>
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for
- * GC creation</li>
- * <li>ERROR_THREAD_INVALID_ACCESS if not called from the
- * thread that created the drawable</li>
- * </ul>
- */
- public GC(Drawable drawable) {
- this(drawable, SWT.NONE);
- }
-
- /**
- * Constructs a new instance of this class which has been configured to draw
- * on the specified drawable. Sets the foreground color, background color
- * and font in the GC to match those in the drawable.
- * <p>
- * You must dispose the graphics context when it is no longer required.
- * </p>
- *
- * @param drawable
- * the drawable to draw on
- * @param style
- * the style of GC to construct
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li>
- * <li>ERROR_NULL_ARGUMENT - if there is no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - if the drawable is an image
- * that is not a bitmap or an icon - if the drawable is an
- * image or printer that is already selected into another
- * graphics context</li>
- * </ul>
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for
- * GC creation</li>
- * <li>ERROR_THREAD_INVALID_ACCESS if not called from the
- * thread that created the drawable</li>
- * </ul>
- *
- * @since 2.1.2
- */
- public GC(Drawable drawable, int style) {
- if (drawable == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
-
- GCData data = new GCData();
- data.style = checkStyle(style);
- QPaintDeviceInterface paintDevice = drawable.internal_new_GC(data);
- Device device = data.device;
- if (device == null) {
- device = Device.getDevice();
- }
- if (device == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- this.device = data.device = device;
- init(drawable, data, paintDevice);
- init();
- }
-
- private QPainter getActivePainter() {
- if (activePainter == null) {
- activePainter = new QPainter();
- // if (paintDevice.paintingActive()) {
- //System.out.println("new painter for " + paintDevice + "active: " + paintDevice.paintingActive());
- // //paintDevice.paintEngine().end();
- // }
- }
-
- if (!activePainter.isActive()) {
- activePainter.begin(paintDevice);
- }
-
- if (!activePainter.isActive()) {
- System.out.println("inactive painter for: " + paintDevice + " painter: " //$NON-NLS-1$ //$NON-NLS-2$
- + paintDevice.paintEngine().painter());
- // RuntimeException re = new RuntimeException();
- // re.printStackTrace();
- }
-
- if (activeClipping != null) {
- activePainter.setClipRegion(activeClipping);
- }
- return activePainter;
- }
-
- static int checkStyle(int style) {
- if ((style & SWT.LEFT_TO_RIGHT) != 0) {
- style &= ~SWT.RIGHT_TO_LEFT;
- }
- return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT);
- }
-
- void init(Drawable drawable, GCData data, QPaintDeviceInterface paintDevice) {
- this.paintDevice = paintDevice;
-
- Color foreground = data.foregroundColor;
- if (foreground != null) {
- data.state &= ~(FOREGROUND | FOREGROUND_TEXT | PEN);
- } else {
- data.foregroundColor = data.device.getSystemColor(SWT.COLOR_BLACK);
- }
- Color background = data.backgroundColor;
- if (background != null) {
- data.state &= ~(BACKGROUND | BACKGROUND_TEXT | BRUSH);
- } else {
- data.backgroundColor = data.device.getSystemColor(SWT.COLOR_WHITE);
- }
- data.state &= ~(NULL_BRUSH | NULL_PEN);
- Font font = data.font;
- if (font != null) {
- data.state &= ~FONT;
- } else {
- data.font = device.getSystemFont();
- }
- Image image = data.image;
- if (image != null) {
- image.setMemGC(this);
- }
- if ((data.style & SWT.RIGHT_TO_LEFT) != 0) {
- data.style |= SWT.MIRRORED;
- }
- this.drawable = drawable;
- this.data = data;
- }
-
- /**
- * Copies a rectangular area of the receiver at the specified position into
- * the image, which must be of type <code>SWT.BITMAP</code>.
- *
- * @param image
- * the image to copy into
- * @param x
- * the x coordinate in the receiver of the area to be copied
- * @param y
- * the y coordinate in the receiver of the area to be copied
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image is not a bitmap
- * or has been disposed</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void copyArea(Image image, int x, int y) {
- // TODO
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (!image.isBitmap() || image.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
-
- /**
- * Copies a rectangular area of the receiver at the source position onto the
- * receiver at the destination position.
- *
- * @param srcX
- * the x coordinate in the receiver of the area to be copied
- * @param srcY
- * the y coordinate in the receiver of the area to be copied
- * @param width
- * the width of the area to copy
- * @param height
- * the height of the area to copy
- * @param destX
- * the x coordinate in the receiver of the area to copy to
- * @param destY
- * the y coordinate in the receiver of the area to copy to
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY) {
- copyArea(srcX, srcY, width, height, destX, destY, true);
- }
-
- /**
- * Copies a rectangular area of the receiver at the source position onto the
- * receiver at the destination position.
- *
- * @param srcX
- * the x coordinate in the receiver of the area to be copied
- * @param srcY
- * the y coordinate in the receiver of the area to be copied
- * @param width
- * the width of the area to copy
- * @param height
- * the height of the area to copy
- * @param destX
- * the x coordinate in the receiver of the area to copy to
- * @param destY
- * the y coordinate in the receiver of the area to copy to
- * @param paint
- * if <code>true</code> paint events will be generated for old
- * and obscured areas
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.1
- */
- public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- //TODO
- /*
- * Feature in WinCE. The function WindowFromDC is not part of the WinCE
- * SDK. The fix is to remember the HWND.
- */
- // int /* long */hwnd = data.hwnd;
- // if (hwnd == 0) {
- // OS.BitBlt(handle, destX, destY, width, height, handle, srcX, srcY, OS.SRCCOPY);
- // } else {
- // RECT lprcClip = null;
- // int /* long */hrgn = OS.CreateRectRgn(0, 0, 0, 0);
- // if (OS.GetClipRgn(handle, hrgn) == 1) {
- // lprcClip = new RECT();
- // OS.GetRgnBox(hrgn, lprcClip);
- // }
- // OS.DeleteObject(hrgn);
- // RECT lprcScroll = new RECT();
- // OS.SetRect(lprcScroll, srcX, srcY, srcX + width, srcY + height);
- // int flags = paint ? OS.SW_INVALIDATE | OS.SW_ERASE : 0;
- // int res = OS.ScrollWindowEx(hwnd, destX - srcX, destY - srcY, lprcScroll, lprcClip, 0, null, flags);
- //
- // /*
- // * Feature in WinCE. ScrollWindowEx does not accept combined
- // * vertical and horizontal scrolling. The fix is to do a BitBlt and
- // * invalidate the appropriate source area.
- // */
- // }
- }
-
- /**
- * Disposes of the operating system resources associated with the graphics
- * context. Applications must dispose of all GCs which they allocate.
- *
- * @exception SWTError
- * <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS if not called from the
- * thread that created the drawable</li>
- * </ul>
- */
- @Override
- void destroy() {
- if (activePainter != null) {
- activePainter.end();
- //System.out.println("end painter for " + paintDevice);
- activePainter = null;
- }
-
- Image image = data.image;
- if (image != null) {
- image.setMemGC(null);
- }
-
- if (drawable != null) {
- drawable.internal_dispose_GC(paintDevice, data);
- }
- drawable = null;
- data.image = null;
- data = null;
- paintDevice = null;
- }
-
- /**
- * Draws the outline of a circular or elliptical arc within the specified
- * rectangular area.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends for
- * <code>arcAngle</code> degrees, using the current color. Angles are
- * interpreted such that 0 degrees is at the 3 o'clock position. A positive
- * value indicates a counter-clockwise rotation while a negative value
- * indicates a clockwise rotation.
- * </p>
- * <p>
- * The center of the arc is the center of the rectangle whose origin is (
- * <code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p>
- * <p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide by
- * <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x
- * the x coordinate of the upper-left corner of the arc to be
- * drawn
- * @param y
- * the y coordinate of the upper-left corner of the arc to be
- * drawn
- * @param width
- * the width of the arc to be drawn
- * @param height
- * the height of the arc to be drawn
- * @param startAngle
- * the beginning angle
- * @param arcAngle
- * the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- QPainter painter = getActivePainter();
- painter.setPen(getForeground().getColor());
- painter.drawArc(x, y, width, height, startAngle, arcAngle);
- }
-
- /**
- * Draws a rectangle, based on the specified arguments, which has the
- * appearance of the platform's <em>focus rectangle</em> if the platform
- * supports such a notion, and otherwise draws a simple rectangle in the
- * receiver's foreground color.
- *
- * @param x
- * the x coordinate of the rectangle
- * @param y
- * the y coordinate of the rectangle
- * @param width
- * the width of the rectangle
- * @param height
- * the height of the rectangle
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
- public void drawFocus(int x, int y, int width, int height) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- QPainter painter = getActivePainter();
- painter.setPen(getForeground().getColor());
- QStyleOptionFocusRect option = new QStyleOptionFocusRect();
- option.rect().setRect(x, y, width, height);
- QApplication.style().drawPrimitive(PrimitiveElement.PE_FrameFocusRect, option, painter);
- }
-
- /**
- * Draws the given image in the receiver at the specified coordinates.
- *
- * @param image
- * the image to draw
- * @param x
- * the x coordinate of where to draw
- * @param y
- * the y coordinate of where to draw
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been
- * disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if the given coordinates are
- * outside the bounds of the image</li>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to
- * perform the operation</li>
- * </ul>
- */
- public void drawImage(Image image, int x, int y) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (image == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (image.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- QPainter painter = getActivePainter();
- QPixmap pic = image.getQPixmap();
- painter.drawPixmap(x, y, pic);
- }
-
- /**
- * Copies a rectangular area from the source image into a (potentially
- * different sized) rectangular area in the receiver. If the source and
- * destination areas are of differing sizes, then the source area will be
- * stretched or shrunk to fit the destination area as it is copied. The copy
- * fails if any part of the source rectangle lies outside the bounds of the
- * source image, or if any of the width or height arguments are negative.
- *
- * @param image
- * the source image
- * @param srcX
- * the x coordinate in the source image to copy from
- * @param srcY
- * the y coordinate in the source image to copy from
- * @param srcWidth
- * the width in pixels to copy from the source
- * @param srcHeight
- * the height in pixels to copy from the source
- * @param destX
- * the x coordinate in the destination to copy to
- * @param destY
- * the y coordinate in the destination to copy to
- * @param destWidth
- * the width in pixels of the destination rectangle
- * @param destHeight
- * the height in pixels of the destination rectangle
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been
- * disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if any of the width or height
- * arguments are negative.
- * <li>ERROR_INVALID_ARGUMENT - if the source rectangle is
- * not contained within the bounds of the source image</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES - if no handles are available to
- * perform the operation</li>
- * </ul>
- */
- public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY,
- int destWidth, int destHeight) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (srcWidth == 0 || srcHeight == 0 || destWidth == 0 || destHeight == 0) {
- return;
- }
- if (srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 || destWidth < 0 || destHeight < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (image == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (image.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- QPainter painter = getActivePainter();
- painter.drawPixmap(new QRect(destX, destY, destWidth, destHeight), image.getQPixmap(), new QRect(srcX, srcY,
- srcWidth, srcHeight));
- }
-
- /**
- * Draws a line, using the foreground color, between the points (
- * <code>x1</code>, <code>y1</code>) and (<code>x2</code>, <code>y2</code>).
- *
- * @param x1
- * the first point's x coordinate
- * @param y1
- * the first point's y coordinate
- * @param x2
- * the second point's x coordinate
- * @param y2
- * the second point's y coordinate
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void drawLine(int x1, int y1, int x2, int y2) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- QPainter painter = getActivePainter();
- painter.setPen(getForeground().getColor());
- painter.drawLine(x1, y1, x2, y2);
- }
-
- /**
- * Draws the outline of an oval, using the foreground color, within the
- * specified rectangular area.
- * <p>
- * The result is a circle or ellipse that fits within the rectangle
- * specified by the <code>x</code>, <code>y</code>, <code>width</code>, and
- * <code>height</code> arguments.
- * </p>
- * <p>
- * The oval covers an area that is <code>width + 1</code> pixels wide and
- * <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x
- * the x coordinate of the upper left corner of the oval to be
- * drawn
- * @param y
- * the y coordinate of the upper left corner of the oval to be
- * drawn
- * @param width
- * the width of the oval to be drawn
- * @param height
- * the height of the oval to be drawn
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void drawOval(int x, int y, int width, int height) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- QPainter painter = getActivePainter();
- painter.setPen(getForeground().getColor());
- painter.drawEllipse(x, y, width, height);
- }
-
- /**
- * Draws the path described by the parameter.
- * <p>
- * This operation requires the operating system's advanced graphics
- * subsystem which may not be available on some platforms.
- * </p>
- *
- * @param path
- * the path to draw
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been
- * disposed</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are
- * not available</li>
- * </ul>
- *
- * @see Path
- *
- * @since 3.1
- */
- public void drawPath(Path path) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (path.handle == 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- //checkGC(DRAW);
- //TODO
- // int /* long */gdipGraphics = data.gdipGraphics;
- // Gdip.Graphics_TranslateTransform(gdipGraphics, data.gdipXOffset, data.gdipYOffset, Gdip.MatrixOrderPrepend);
- // Gdip.Graphics_DrawPath(gdipGraphics, data.gdipPen, path.handle);
- // Gdip.Graphics_TranslateTransform(gdipGraphics, -data.gdipXOffset, -data.gdipYOffset, Gdip.MatrixOrderPrepend);
- }
- }
-
- /**
- * Draws a pixel, using the foreground color, at the specified point (
- * <code>x</code>, <code>y</code>).
- * <p>
- * Note that the receiver's line attributes do not affect this operation.
- * </p>
- *
- * @param x
- * the point's x coordinate
- * @param y
- * the point's y coordinate
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.0
- */
- public void drawPoint(int x, int y) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- QPainter painter = getActivePainter();
- painter.setPen(getForeground().getColor());
- painter.drawPoint(x, y);
- }
-
- /**
- * Draws the closed polygon which is defined by the specified array of
- * integer coordinates, using the receiver's foreground color. The array
- * contains alternating x and y values which are considered to represent
- * points which are the vertices of the polygon. Lines are drawn between
- * each consecutive pair, and between the first pair and last pair in the
- * array.
- *
- * @param pointArray
- * an array of alternating x and y values which are the vertices
- * of the polygon
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT if pointArray is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void drawPolygon(int[] pointArray) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- validatePointArray(pointArray);
- QPainter painter = getActivePainter();
- painter.setPen(getForeground().getColor());
- painter.drawPolygon(createPolygonFromArray(pointArray));
- }
-
- /**
- * Draws the polyline which is defined by the specified array of integer
- * coordinates, using the receiver's foreground color. The array contains
- * alternating x and y values which are considered to represent points which
- * are the corners of the polyline. Lines are drawn between each consecutive
- * pair, but not between the first pair and last pair in the array.
- *
- * @param pointArray
- * an array of alternating x and y values which are the corners
- * of the polyline
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point array is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void drawPolyline(int[] pointArray) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (pointArray == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- validatePointArray(pointArray);
- QPainter painter = getActivePainter();
- painter.setPen(getForeground().getColor());
- painter.drawPolyline(createPolygonFromArray(pointArray));
- }
-
- /**
- * Draws the outline of the rectangle specified by the arguments, using the
- * receiver's foreground color. The left and right edges of the rectangle
- * are at <code>x</code> and <code>x + width</code>. The top and bottom
- * edges are at <code>y</code> and <code>y + height</code>.
- *
- * @param x
- * the x coordinate of the rectangle to be drawn
- * @param y
- * the y coordinate of the rectangle to be drawn
- * @param width
- * the width of the rectangle to be drawn
- * @param height
- * the height of the rectangle to be drawn
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void drawRectangle(int x, int y, int width, int height) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- QPainter painter = getActivePainter();
- painter.setPen(getForeground().getColor());
- painter.drawRect(x, y, width, height);
- }
-
- /**
- * Draws the outline of the specified rectangle, using the receiver's
- * foreground color. The left and right edges of the rectangle are at
- * <code>rect.x</code> and <code>rect.x + rect.width</code>. The top and
- * bottom edges are at <code>rect.y</code> and
- * <code>rect.y + rect.height</code>.
- *
- * @param rect
- * the rectangle to draw
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void drawRectangle(Rectangle rect) {
- if (rect == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- drawRectangle(rect.x, rect.y, rect.width, rect.height);
- }
-
- /**
- * Draws the outline of the round-cornered rectangle specified by the
- * arguments, using the receiver's foreground color. The left and right
- * edges of the rectangle are at <code>x</code> and <code>x + width</code>.
- * The top and bottom edges are at <code>y</code> and
- * <code>y + height</code>. The <em>roundness</em> of the corners is
- * specified by the <code>arcWidth</code> and <code>arcHeight</code>
- * arguments, which are respectively the width and height of the ellipse
- * used to draw the corners.
- *
- * @param x
- * the x coordinate of the rectangle to be drawn
- * @param y
- * the y coordinate of the rectangle to be drawn
- * @param width
- * the width of the rectangle to be drawn
- * @param height
- * the height of the rectangle to be drawn
- * @param arcWidth
- * the width of the arc
- * @param arcHeight
- * the height of the arc
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void drawRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- QPainter painter = getActivePainter();
- painter.setPen(getForeground().getColor());
- painter.drawRoundedRect(x, y, width, height, arcWidth, arcHeight, SizeMode.AbsoluteSize);
- }
-
- /**
- * Draws the given string, using the receiver's current font and foreground
- * color. No tab expansion or carriage return processing will be performed.
- * The background of the rectangular area where the string is being drawn
- * will be filled with the receiver's background color.
- *
- * @param string
- * the string to be drawn
- * @param x
- * the x coordinate of the top left corner of the rectangular
- * area where the string is to be drawn
- * @param y
- * the y coordinate of the top left corner of the rectangular
- * area where the string is to be drawn
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void drawString(String string, int x, int y) {
- drawString(string, x, y, false);
- }
-
- /**
- * Draws the given string, using the receiver's current font and foreground
- * color. No tab expansion or carriage return processing will be performed.
- * If <code>isTransparent</code> is <code>true</code>, then the background
- * of the rectangular area where the string is being drawn will not be
- * modified, otherwise it will be filled with the receiver's background
- * color.
- *
- * @param string
- * the string to be drawn
- * @param x
- * the x coordinate of the top left corner of the rectangular
- * area where the string is to be drawn
- * @param y
- * the y coordinate of the top left corner of the rectangular
- * area where the string is to be drawn
- * @param isTransparent
- * if <code>true</code> the background will be transparent,
- * otherwise it will be opaque
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void drawString(String string, int x, int y, boolean isTransparent) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- QPainter painter = getActivePainter();
- if (isTransparent) {
- painter.setBackgroundMode(BGMode.TransparentMode);
- } else {
- painter.setBackgroundMode(BGMode.OpaqueMode);
- painter.setBackground(new QBrush(getBackground().getColor()));
- }
- painter.setFont(data.font.getQFont());
- painter.setPen(getForeground().getColor());
- //System.out.println("drawText(" + x + ", " + y + ", " + string + ")");
-
- painter.drawText(x, y + getHightCorrection(painter), string);
- }
-
- private int getHightCorrection(QPainter painter) {
- QFontMetrics fm = painter.fontMetrics();
- return fm.ascent();
- }
-
- /**
- * Draws the given string, using the receiver's current font and foreground
- * color. Tab expansion and carriage return processing are performed. The
- * background of the rectangular area where the text is being drawn will be
- * filled with the receiver's background color.
- *
- * @param string
- * the string to be drawn
- * @param x
- * the x coordinate of the top left corner of the rectangular
- * area where the text is to be drawn
- * @param y
- * the y coordinate of the top left corner of the rectangular
- * area where the text is to be drawn
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void drawText(String string, int x, int y) {
- drawText(string, x, y, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
- }
-
- /**
- * Draws the given string, using the receiver's current font and foreground
- * color. Tab expansion and carriage return processing are performed. If
- * <code>isTransparent</code> is <code>true</code>, then the background of
- * the rectangular area where the text is being drawn will not be modified,
- * otherwise it will be filled with the receiver's background color.
- *
- * @param string
- * the string to be drawn
- * @param x
- * the x coordinate of the top left corner of the rectangular
- * area where the text is to be drawn
- * @param y
- * the y coordinate of the top left corner of the rectangular
- * area where the text is to be drawn
- * @param isTransparent
- * if <code>true</code> the background will be transparent,
- * otherwise it will be opaque
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void drawText(String string, int x, int y, boolean isTransparent) {
- int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB;
- if (isTransparent) {
- flags |= SWT.DRAW_TRANSPARENT;
- }
- drawText(string, x, y, flags);
- }
-
- /**
- * Draws the given string, using the receiver's current font and foreground
- * color. Tab expansion, line delimiter and mnemonic processing are
- * performed according to the specified flags. If <code>flags</code>
- * includes <code>DRAW_TRANSPARENT</code>, then the background of the
- * rectangular area where the text is being drawn will not be modified,
- * otherwise it will be filled with the receiver's background color.
- * <p>
- * The parameter <code>flags</code> may be a combination of:
- * <dl>
- * <dt><b>DRAW_DELIMITER</b></dt>
- * <dd>draw multiple lines</dd>
- * <dt><b>DRAW_TAB</b></dt>
- * <dd>expand tabs</dd>
- * <dt><b>DRAW_MNEMONIC</b></dt>
- * <dd>underline the mnemonic character</dd>
- * <dt><b>DRAW_TRANSPARENT</b></dt>
- * <dd>transparent background</dd>
- * </dl>
- * </p>
- *
- * @param string
- * the string to be drawn
- * @param x
- * the x coordinate of the top left corner of the rectangular
- * area where the text is to be drawn
- * @param y
- * the y coordinate of the top left corner of the rectangular
- * area where the text is to be drawn
- * @param flags
- * the flags specifying how to process the text
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void drawText(String string, int x, int y, int flags) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- QPainter painter = getActivePainter();
- if ((flags & SWT.DRAW_TRANSPARENT) != 0) {
- painter.setBackgroundMode(BGMode.TransparentMode);
- painter.setBackground(new QBrush(getBackground().getColor()));
- }
-
- int translatedFlags = translateTextFlags(flags);
-
- painter.setPen(getForeground().getColor());
-
- QRect r = painter.boundingRect(0, 0, 0, 0, translatedFlags, string);
-
- //System.out.println("drawText(" + x + ", " + y + ", " + r.width() + ", " + r.height() + ", " + string + ")");
- painter.drawText(x, y, r.width(), r.height(), translatedFlags, string);
- }
-
- /**
- * @param flags
- * @return
- */
- private int translateTextFlags(int flags) {
- int translatedFlags = AlignmentFlag.AlignTop.value() | AlignmentFlag.AlignLeft.value();
- if ((flags & SWT.DRAW_DELIMITER) == 0) {
- translatedFlags |= TextFlag.TextSingleLine.value();
- }
- if ((flags & SWT.DRAW_TAB) != 0) {
- translatedFlags |= TextFlag.TextExpandTabs.value();
- }
- if ((flags & SWT.DRAW_MNEMONIC) != 0) {
- translatedFlags |= TextFlag.TextShowMnemonic.value();
- }
- return translatedFlags;
- }
-
- /**
- * Compares the argument to the receiver, and returns true if they represent
- * the <em>same</em> object using a class specific comparison.
- *
- * @param object
- * the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and
- * <code>false</code> otherwise
- *
- * @see #hashCode
- */
- @Override
- public boolean equals(Object object) {
- return object == this || object instanceof GC && paintDevice == ((GC) object).paintDevice;
- }
-
- /**
- * Fills the interior of a circular or elliptical arc within the specified
- * rectangular area, with the receiver's background color.
- * <p>
- * The resulting arc begins at <code>startAngle</code> and extends for
- * <code>arcAngle</code> degrees, using the current color. Angles are
- * interpreted such that 0 degrees is at the 3 o'clock position. A positive
- * value indicates a counter-clockwise rotation while a negative value
- * indicates a clockwise rotation.
- * </p>
- * <p>
- * The center of the arc is the center of the rectangle whose origin is (
- * <code>x</code>, <code>y</code>) and whose size is specified by the
- * <code>width</code> and <code>height</code> arguments.
- * </p>
- * <p>
- * The resulting arc covers an area <code>width + 1</code> pixels wide by
- * <code>height + 1</code> pixels tall.
- * </p>
- *
- * @param x
- * the x coordinate of the upper-left corner of the arc to be
- * filled
- * @param y
- * the y coordinate of the upper-left corner of the arc to be
- * filled
- * @param width
- * the width of the arc to be filled
- * @param height
- * the height of the arc to be filled
- * @param startAngle
- * the beginning angle
- * @param arcAngle
- * the angular extent of the arc, relative to the start angle
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see #drawArc
- */
- public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- QPainter painter = getActivePainter();
- painter.setBrush(getBackground().getColor());
- //painter.setPen(getBackground().getColor());
- painter.setPen(PenStyle.NoPen);
- painter.drawArc(x, y, width, height, startAngle, arcAngle);
- }
-
- /**
- * Fills the interior of the specified rectangle with a gradient sweeping
- * from left to right or top to bottom progressing from the receiver's
- * foreground color to its background color.
- *
- * @param x
- * the x coordinate of the rectangle to be filled
- * @param y
- * the y coordinate of the rectangle to be filled
- * @param width
- * the width of the rectangle to be filled, may be negative
- * (inverts direction of gradient if horizontal)
- * @param height
- * the height of the rectangle to be filled, may be negative
- * (inverts direction of gradient if vertical)
- * @param vertical
- * if true sweeps from top to bottom, else sweeps from left to
- * right
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
- public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (width == 0 || height == 0) {
- return;
- }
- // if (true) {
- // return;
- // }
-
- QColor fromColor = getForeground().getColor();
- QColor toColor = getBackground().getColor();
-
- boolean swapColors = false;
- if (width < 0) {
- x += width;
- width = -width;
- if (!vertical) {
- swapColors = true;
- }
- }
- if (height < 0) {
- y += height;
- height = -height;
- if (vertical) {
- swapColors = true;
- }
- }
- if (swapColors) {
- QColor tmp = fromColor;
- fromColor = toColor;
- toColor = tmp;
- }
- if (fromColor.equals(toColor)) {
- fillRectangle(x, y, width, height);
- return;
- }
-
- QPointF p1 = new QPointF(), p2 = new QPointF();
- p1.setX(x);
- p1.setY(y);
- if (vertical) {
- p2.setX(p1.x());
- p2.setY(p1.y() + height);
- } else {
- p2.setX(p1.x() + width);
- p2.setY(p1.y());
- }
- QPainter painter = getActivePainter();
- QLinearGradient fade = new QLinearGradient(p1, p2);
- fade.setColorAt(0.0, fromColor);
- fade.setColorAt(1.0, toColor);
- QBrush brush = new QBrush(fade);
- painter.fillRect(x, y, width, height, brush);
- }
-
- /**
- * Fills the interior of an oval, within the specified rectangular area,
- * with the receiver's background color.
- *
- * @param x
- * the x coordinate of the upper left corner of the oval to be
- * filled
- * @param y
- * the y coordinate of the upper left corner of the oval to be
- * filled
- * @param width
- * the width of the oval to be filled
- * @param height
- * the height of the oval to be filled
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see #drawOval
- */
- public void fillOval(int x, int y, int width, int height) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- QPainter painter = getActivePainter();
- painter.setBrush(getBackground().getColor());
- painter.setPen(getBackground().getColor());
- painter.drawEllipse(x, y, width, height);
- }
-
- /**
- * Fills the path described by the parameter.
- * <p>
- * This operation requires the operating system's advanced graphics
- * subsystem which may not be available on some platforms.
- * </p>
- *
- * @param path
- * the path to fill
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been
- * disposed</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are
- * not available</li>
- * </ul>
- *
- * @see Path
- *
- * @since 3.1
- */
- public void fillPath(Path path) {
- //TODO
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (path.handle == 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
-
- /**
- * Fills the interior of the closed polygon which is defined by the
- * specified array of integer coordinates, using the receiver's background
- * color. The array contains alternating x and y values which are considered
- * to represent points which are the vertices of the polygon. Lines are
- * drawn between each consecutive pair, and between the first pair and last
- * pair in the array.
- *
- * @param pointArray
- * an array of alternating x and y values which are the vertices
- * of the polygon
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT if pointArray is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see #drawPolygon
- */
- public void fillPolygon(int[] pointArray) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- validatePointArray(pointArray);
- QPainter painter = getActivePainter();
- painter.setBrush(getBackground().getColor());
- painter.setPen(getBackground().getColor());
- painter.drawPolygon(createPolygonFromArray(pointArray), FillRule.WindingFill);
- }
-
- private void validatePointArray(int[] pointArray) {
- if (pointArray == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (pointArray.length % 2 != 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- }
-
- public static QPolygon createPolygonFromArray(int[] pointArray) {
- QPolygon polygon = new QPolygon();
- for (int i = 0; i < pointArray.length; i += 2) {
- polygon.add(pointArray[i], pointArray[i + 1]);
- }
- return polygon;
- }
-
- /**
- * Fills the interior of the rectangle specified by the arguments, using the
- * receiver's background color.
- *
- * @param x
- * the x coordinate of the rectangle to be filled
- * @param y
- * the y coordinate of the rectangle to be filled
- * @param width
- * the width of the rectangle to be filled
- * @param height
- * the height of the rectangle to be filled
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
- public void fillRectangle(int x, int y, int width, int height) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- QPainter painter = getActivePainter();
- painter.fillRect(x, y, width, height, getBackground().getColor());
- }
-
- /**
- * Fills the interior of the specified rectangle, using the receiver's
- * background color.
- *
- * @param rect
- * the rectangle to be filled
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see #drawRectangle(int, int, int, int)
- */
- public void fillRectangle(Rectangle rect) {
- if (rect == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- fillRectangle(rect.x, rect.y, rect.width, rect.height);
- }
-
- /**
- * Fills the interior of the round-cornered rectangle specified by the
- * arguments, using the receiver's background color.
- *
- * @param x
- * the x coordinate of the rectangle to be filled
- * @param y
- * the y coordinate of the rectangle to be filled
- * @param width
- * the width of the rectangle to be filled
- * @param height
- * the height of the rectangle to be filled
- * @param arcWidth
- * the width of the arc
- * @param arcHeight
- * the height of the arc
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see #drawRoundRectangle
- */
- public void fillRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- QPainter painter = getActivePainter();
- painter.setBrush(getBackground().getColor());
- painter.setPen(getBackground().getColor());
- painter.drawRoundedRect(x, y, width, height, arcWidth, arcHeight);
- }
-
- void flush() {
- }
-
- /**
- * Returns the <em>advance width</em> of the specified character in the font
- * which is currently selected into the receiver.
- * <p>
- * The advance width is defined as the horizontal distance the cursor should
- * move after printing the character in the selected font.
- * </p>
- *
- * @param ch
- * the character to measure
- * @return the distance in the x direction to move past the character before
- * painting the next
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public int getAdvanceWidth(char ch) {
-
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- QPainter activePainter = getActivePainter();
- return activePainter.fontMetrics().width(ch);
- // //checkGC(FONT);
- // int tch = ch;
- // if (ch > 0x7F) {
- // TCHAR buffer = new TCHAR(getCodePage(), ch, false);
- // tch = buffer.tcharAt(0);
- // }
- // int[] width = new int[1];
- // OS.GetCharWidth(handle, tch, tch, width);
- // return width[0];
- }
-
- /**
- * Returns the receiver's alpha value. The alpha value is between 0
- * (transparent) and 255 (opaque).
- *
- * @return the alpha value
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.1
- */
- public int getAlpha() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return data.alpha;
- }
-
- /**
- * Returns the receiver's anti-aliasing setting value, which will be one of
- * <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or <code>SWT.ON</code>.
- * Note that this controls anti-aliasing for all <em>non-text drawing</em>
- * operations.
- *
- * @return the anti-aliasing setting
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see #getTextAntialias
- *
- * @since 3.1
- */
- public int getAntialias() {
- return antialias;
- // if (handle == 0) {
- // SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- // }
- // if (data.gdipGraphics == 0)
- // return SWT.DEFAULT;
- // int mode = Gdip.Graphics_GetSmoothingMode(data.gdipGraphics);
- // switch (mode) {
- // case Gdip.SmoothingModeDefault:
- // return SWT.DEFAULT;
- // case Gdip.SmoothingModeHighSpeed:
- // case Gdip.SmoothingModeNone:
- // return SWT.OFF;
- // case Gdip.SmoothingModeAntiAlias:
- // case Gdip.SmoothingModeAntiAlias8x8:
- // case Gdip.SmoothingModeHighQuality:
- // return SWT.ON;
- // }
- // return SWT.DEFAULT;
- }
-
- /**
- * Returns the background color.
- *
- * @return the receiver's background color
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public Color getBackground() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return data.backgroundColor;
- }
-
- /**
- * Returns the background pattern. The default value is <code>null</code>.
- *
- * @return the receiver's background pattern
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see Pattern
- *
- * @since 3.1
- */
- public Pattern getBackgroundPattern() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return data.backgroundPattern;
- }
-
- /**
- * Returns the width of the specified character in the font selected into
- * the receiver.
- * <p>
- * The width is defined as the space taken up by the actual character, not
- * including the leading and tailing whitespace or overhang.
- * </p>
- *
- * @param ch
- * the character to measure
- * @return the width of the character
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public int getCharWidth(char ch) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- //checkGC(FONT);
- // TODO
- return 10;
- }
-
- /**
- * Returns the bounding rectangle of the receiver's clipping region. If no
- * clipping region is set, the return value will be a rectangle which covers
- * the entire bounds of the object the receiver is drawing on.
- *
- * @return the bounding rectangle of the clipping region
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public Rectangle getClipping() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- QPainter painter = getActivePainter();
- if (painter.hasClipping()) {
- return QtSWTConverter.convert(painter.clipRegion());
- } else {
- return new Rectangle(0, 0, paintDevice.width(), paintDevice.height());
- }
- }
-
- /**
- * Sets the region managed by the argument to the current clipping region of
- * the receiver.
- *
- * @param region
- * the region to fill with the clipping region
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the region is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the region is disposed</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void getClipping(Region region) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (region == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (region.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- QPainter painter = getActivePainter();
- Rectangle rect;
- if (painter.hasClipping()) {
- rect = QtSWTConverter.convert(painter.clipRegion());
- } else {
- rect = new Rectangle(0, 0, paintDevice.width(), paintDevice.height());
- }
- region.add(rect);
- }
-
- /**
- * Returns the receiver's fill rule, which will be one of
- * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>.
- *
- * @return the receiver's fill rule
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.1
- */
- public int getFillRule() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (fillRule == null || fillRule.equals(FillRule.WindingFill)) {
- return SWT.FILL_WINDING;
- }
- return SWT.FILL_EVEN_ODD;
- }
-
- /**
- * Sets the receiver's fill rule to the parameter, which must be one of
- * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>.
- *
- * @param rule
- * the new fill rule
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of
- * <code>SWT.FILL_EVEN_ODD</code> or
- * <code>SWT.FILL_WINDING</code></li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.1
- */
- public void setFillRule(int rule) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- switch (rule) {
- case SWT.FILL_WINDING:
- fillRule = FillRule.WindingFill;
- break;
- case SWT.FILL_EVEN_ODD:
- fillRule = FillRule.OddEvenFill;
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
-
- /**
- * Returns the font currently being used by the receiver to draw and measure
- * text.
- *
- * @return the receiver's font
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public Font getFont() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return data.font;
- }
-
- /**
- * Returns a FontMetrics which contains information about the font currently
- * being used by the receiver to draw and measure text.
- *
- * @return font metrics for the receiver's font
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public FontMetrics getFontMetrics() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- //checkGC(FONT);
- //if (!paintDevice.paintingActive()) {
- return FontMetrics.internal_new(data.font);
- // }
- // QPainter painter = getActivePainter();
- // painter.setFont(data.font.getQFont());
- // try {
- // return FontMetrics.internal_new(painter.fontMetrics());
- // } finally {
- // painter.end();
- // }
-
- }
-
- /**
- * Returns the receiver's foreground color.
- *
- * @return the color used for drawing foreground things
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public Color getForeground() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return data.foregroundColor;
- }
-
- /**
- * Returns the foreground pattern. The default value is <code>null</code>.
- *
- * @return the receiver's foreground pattern
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see Pattern
- *
- * @since 3.1
- */
- public Pattern getForegroundPattern() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return data.foregroundPattern;
- }
-
- /**
- * Returns the GCData.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public API for
- * <code>GC</code>. 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.
- * </p>
- *
- * @return the receiver's GCData
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see GCData
- *
- * @since 3.2
- * @noreference This method is not intended to be referenced by clients.
- */
- public GCData getGCData() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return data;
- }
-
- /**
- * Returns the receiver's interpolation setting, which will be one of
- * <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>, <code>SWT.LOW</code> or
- * <code>SWT.HIGH</code>.
- *
- * @return the receiver's interpolation setting
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.1
- */
- public int getInterpolation() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return SWT.DEFAULT;
- //TODO
- // int mode = Gdip.Graphics_GetInterpolationMode(data.gdipGraphics);
- // switch (mode) {
- // case Gdip.InterpolationModeDefault:
- // return SWT.DEFAULT;
- // case Gdip.InterpolationModeNearestNeighbor:
- // return SWT.NONE;
- // case Gdip.InterpolationModeBilinear:
- // case Gdip.InterpolationModeLowQuality:
- // return SWT.LOW;
- // case Gdip.InterpolationModeBicubic:
- // case Gdip.InterpolationModeHighQualityBilinear:
- // case Gdip.InterpolationModeHighQualityBicubic:
- // case Gdip.InterpolationModeHighQuality:
- // return SWT.HIGH;
- // }
- // return SWT.DEFAULT;
- }
-
- /**
- * Returns the receiver's line attributes.
- *
- * @return the line attributes used for drawing lines
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.3
- */
- public LineAttributes getLineAttributes() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- float[] dashes = null;
- if (data.lineDashes != null) {
- dashes = new float[data.lineDashes.length];
- System.arraycopy(data.lineDashes, 0, dashes, 0, dashes.length);
- }
- return new LineAttributes(data.lineWidth, data.lineCap, data.lineJoin, data.lineStyle, dashes,
- data.lineDashesOffset, data.lineMiterLimit);
- }
-
- /**
- * Returns the receiver's line cap style, which will be one of the constants
- * <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>, or
- * <code>SWT.CAP_SQUARE</code>.
- *
- * @return the cap style used for drawing lines
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.1
- */
- public int getLineCap() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return data.lineCap;
- }
-
- /**
- * Returns the receiver's line dash style. The default value is
- * <code>null</code>.
- *
- * @return the line dash style used for drawing lines
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.1
- */
- public int[] getLineDash() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (data.lineDashes == null) {
- return null;
- }
- int[] lineDashes = new int[data.lineDashes.length];
- for (int i = 0; i < lineDashes.length; i++) {
- lineDashes[i] = (int) data.lineDashes[i];
- }
- return lineDashes;
- }
-
- /**
- * Returns the receiver's line join style, which will be one of the
- * constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>, or
- * <code>SWT.JOIN_BEVEL</code>.
- *
- * @return the join style used for drawing lines
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.1
- */
- public int getLineJoin() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return data.lineJoin;
- }
-
- /**
- * Returns the receiver's line style, which will be one of the constants
- * <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
- * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or
- * <code>SWT.LINE_DASHDOTDOT</code>.
- *
- * @return the style used for drawing lines
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public int getLineStyle() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return data.lineStyle;
- }
-
- /**
- * Returns the width that will be used when drawing lines for all of the
- * figure drawing operations (that is, <code>drawLine</code>,
- * <code>drawRectangle</code>, <code>drawPolyline</code>, and so forth.
- *
- * @return the receiver's line width
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public int getLineWidth() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return (int) data.lineWidth;
- }
-
- /**
- * Returns the receiver's style information.
- * <p>
- * Note that the value which is returned by this method <em>may
- * not match</em> the value which was provided to the constructor when the
- * receiver was created. This can occur when the underlying operating system
- * does not support a particular combination of requested styles.
- * </p>
- *
- * @return the style bits
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 2.1.2
- */
- public int getStyle() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return data.style;
- }
-
- /**
- * Returns the receiver's text drawing anti-aliasing setting value, which
- * will be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code>. Note that this controls anti-aliasing <em>only</em>
- * for text drawing operations.
- *
- * @return the anti-aliasing setting
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see #getAntialias
- *
- * @since 3.1
- */
- public int getTextAntialias() {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- // if (data.gdipGraphics == 0)
- return SWT.DEFAULT;
- // TODO
- // int mode = Gdip.Graphics_GetTextRenderingHint(data.gdipGraphics);
- // switch (mode) {
- // case Gdip.TextRenderingHintSystemDefault:
- // return SWT.DEFAULT;
- // case Gdip.TextRenderingHintSingleBitPerPixel:
- // case Gdip.TextRenderingHintSingleBitPerPixelGridFit:
- // return SWT.OFF;
- // case Gdip.TextRenderingHintAntiAlias:
- // case Gdip.TextRenderingHintAntiAliasGridFit:
- // case Gdip.TextRenderingHintClearTypeGridFit:
- // return SWT.ON;
- // }
- // return SWT.DEFAULT;
- }
-
- /**
- * Sets the parameter to the transform that is currently being used by the
- * receiver.
- *
- * @param transform
- * the destination to copy the transform into
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been
- * disposed</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see Transform
- *
- * @since 3.1
- */
- public void getTransform(Transform transform) {
- //TODO
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transform == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (transform.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- // int /* long */gdipGraphics = data.gdipGraphics;
- // if (gdipGraphics != 0) {
- // Gdip.Graphics_GetTransform(gdipGraphics, transform.handle);
- // int /* long */identity = identity();
- // Gdip.Matrix_Invert(identity);
- // Gdip.Matrix_Multiply(transform.handle, identity, Gdip.MatrixOrderAppend);
- // Gdip.Matrix_delete(identity);
- // } else {
- // transform.setElements(1, 0, 0, 1, 0, 0);
- // }
- }
- }
-
- /**
- * Returns <code>true</code> if this GC is drawing in the mode where the
- * resulting color in the destination is the <em>exclusive or</em> of the
- * color values in the source and the destination, and <code>false</code> if
- * it is drawing in the mode where the destination color is being replaced
- * with the source color value.
- *
- * @return <code>true</code> true if the receiver is in XOR mode, and false
- * otherwise
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public boolean getXORMode() {
- //TODO
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- // int rop2 = 0;
- // rop2 = OS.GetROP2(handle);
- return false; //rop2 == OS.R2_XORPEN;
- }
-
- /**
- * If the argument is <code>true</code>, puts the receiver in a drawing mode
- * where the resulting color in the destination is the <em>exclusive or</em>
- * of the color values in the source and the destination, and if the
- * argument is <code>false</code>, puts the receiver in a drawing mode where
- * the destination color is replaced with the source color value.
- * <p>
- * Note that this mode in fundamentally unsupportable on certain platforms,
- * notably Carbon (Mac OS X). Clients that want their code to run on all
- * platforms need to avoid this method.
- * </p>
- *
- * @param xor
- * if <code>true</code>, then <em>xor</em> mode is used,
- * otherwise <em>source copy</em> mode is used
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @deprecated this functionality is not supported on some platforms
- */
- @Deprecated
- public void setXORMode(boolean xor) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- //TODO
- //OS.SetROP2(handle, xor ? OS.R2_XORPEN : OS.R2_COPYPEN);
- }
-
- /**
- * Returns an integer hash code for the receiver. Any two objects that
- * return <code>true</code> when passed to <code>equals</code> must return
- * the same value for this method.
- *
- * @return the receiver's hash
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see #equals
- */
- @Override
- public int hashCode() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return paintDevice.hashCode();
- }
-
- /**
- * Returns <code>true</code> if the receiver has a clipping region set into
- * it, and <code>false</code> otherwise. If this method returns false, the
- * receiver will draw on all available space in the destination. If it
- * returns true, it will draw only in the area that is covered by the region
- * that can be accessed with <code>getClipping(region)</code>.
- *
- * @return <code>true</code> if the GC has a clipping region, and
- * <code>false</code> otherwise
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public boolean isClipped() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return activeClipping != null;
- }
-
- /**
- * Returns <code>true</code> if the GC has been disposed, and
- * <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the GC. When a GC has been
- * disposed, it is an error to invoke any other method using the GC.
- *
- * @return <code>true</code> when the GC is disposed and <code>false</code>
- * otherwise
- */
- @Override
- public boolean isDisposed() {
- return paintDevice == null;
- }
-
- /**
- * Sets the receiver to always use the operating system's advanced graphics
- * subsystem for all graphics operations if the argument is
- * <code>true</code>. If the argument is <code>false</code>, the advanced
- * graphics subsystem is no longer used, advanced graphics state is cleared
- * and the normal graphics subsystem is used from now on.
- * <p>
- * Normally, the advanced graphics subsystem is invoked automatically when
- * any one of the alpha, antialias, patterns, interpolation, paths, clipping
- * or transformation operations in the receiver is requested. When the
- * receiver is switched into advanced mode, the advanced graphics subsystem
- * performs both advanced and normal graphics operations. Because the two
- * subsystems are different, their output may differ. Switching to advanced
- * graphics before any graphics operations are performed ensures that the
- * output is consistent.
- * </p>
- * <p>
- * Advanced graphics may not be installed for the operating system. In this
- * case, this operation does nothing. Some operating system have only one
- * graphics subsystem, so switching from normal to advanced graphics does
- * nothing. However, switching from advanced to normal graphics will always
- * clear the advanced graphics state, even for operating systems that have
- * only one graphics subsystem.
- * </p>
- *
- * @param advanced
- * the new advanced graphics state
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see #setAlpha
- * @see #setAntialias
- * @see #setBackgroundPattern
- * @see #setClipping(Path)
- * @see #setForegroundPattern
- * @see #setLineAttributes
- * @see #setInterpolation
- * @see #setTextAntialias
- * @see #setTransform
- * @see #getAdvanced
- *
- * @since 3.1
- */
- public void setAdvanced(boolean advanced) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- }
-
- /**
- * Returns <code>true</code> if receiver is using the operating system's
- * advanced graphics subsystem. Otherwise, <code>false</code> is returned to
- * indicate that normal graphics are in use.
- * <p>
- * Advanced graphics may not be installed for the operating system. In this
- * case, <code>false</code> is always returned. Some operating system have
- * only one graphics subsystem. If this subsystem supports advanced
- * graphics, then <code>true</code> is always returned. If any graphics
- * operation such as alpha, antialias, patterns, interpolation, paths,
- * clipping or transformation has caused the receiver to switch from regular
- * to advanced graphics mode, <code>true</code> is returned. If the receiver
- * has been explicitly switched to advanced mode and this mode is supported,
- * <code>true</code> is returned.
- * </p>
- *
- * @return the advanced value
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see #setAdvanced
- *
- * @since 3.1
- */
- public boolean getAdvanced() {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- // Qt is Advanced :)
- return true;
- }
-
- /**
- * Sets the receiver's anti-aliasing value to the parameter, which must be
- * one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code>. Note that this controls anti-aliasing for all
- * <em>non-text drawing</em> operations.
- * <p>
- * This operation requires the operating system's advanced graphics
- * subsystem which may not be available on some platforms.
- * </p>
- *
- * @param antialias
- * the anti-aliasing setting
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one
- * of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code></li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are
- * not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- * @see #setTextAntialias
- *
- * @since 3.1
- */
- public void setAntialias(int antialias) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- this.antialias = antialias;
- // if (handle == 0) {
- // SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- // TODO
- // if (data.gdipGraphics == 0 && antialias == SWT.DEFAULT)
- // return;
- // int mode = 0;
- // switch (antialias) {
- // case SWT.DEFAULT:
- // mode = Gdip.SmoothingModeDefault;
- // break;
- // case SWT.OFF:
- // mode = Gdip.SmoothingModeNone;
- // break;
- // case SWT.ON:
- // mode = Gdip.SmoothingModeAntiAlias;
- // break;
- // default:
- // SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- // }
- // }
- }
-
- /**
- * Sets the receiver's alpha value which must be between 0 (transparent) and
- * 255 (opaque).
- * <p>
- * This operation requires the operating system's advanced graphics
- * subsystem which may not be available on some platforms.
- * </p>
- *
- * @param alpha
- * the alpha value
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are
- * not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
- public void setAlpha(int alpha) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- //TODO
- data.alpha = alpha & 0xFF;
- data.state &= ~(BACKGROUND | FOREGROUND);
- }
-
- /**
- * Sets the background color. The background color is used for fill
- * operations and as the background color when text is drawn.
- *
- * @param color
- * the new background color for the receiver
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been
- * disposed</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void setBackground(Color color) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (color == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (color.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (data.backgroundPattern == null && data.backgroundColor.equals(color)) {
- return;
- }
- data.backgroundPattern = null;
- data.backgroundColor = color;
- data.state &= ~(BACKGROUND | BACKGROUND_TEXT);
- }
-
- /**
- * Sets the background pattern. The default value is <code>null</code>.
- * <p>
- * This operation requires the operating system's advanced graphics
- * subsystem which may not be available on some platforms.
- * </p>
- *
- * @param pattern
- * the new background pattern
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been
- * disposed</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are
- * not available</li>
- * </ul>
- *
- * @see Pattern
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
- public void setBackgroundPattern(Pattern pattern) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (pattern != null && pattern.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (data.backgroundPattern == pattern) {
- return;
- }
- data.backgroundPattern = pattern;
- data.state &= ~BACKGROUND;
- }
-
- /**
- * Sets the area of the receiver which can be changed by drawing operations
- * to the rectangular area specified by the arguments.
- *
- * @param x
- * the x coordinate of the clipping rectangle
- * @param y
- * the y coordinate of the clipping rectangle
- * @param width
- * the width of the clipping rectangle
- * @param height
- * the height of the clipping rectangle
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void setClipping(int x, int y, int width, int height) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- activeClipping = new QRegion(x, y, width, height);
- }
-
- /**
- * Sets the area of the receiver which can be changed by drawing operations
- * to the path specified by the argument.
- * <p>
- * This operation requires the operating system's advanced graphics
- * subsystem which may not be available on some platforms.
- * </p>
- *
- * @param path
- * the clipping path.
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the path has been disposed
- * </li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are
- * not available</li>
- * </ul>
- *
- * @see Path
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
- public void setClipping(Path path) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (path != null && path.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (path == null) {
- activeClipping = null;
- }
- //TODO
- }
-
- /**
- * Sets the area of the receiver which can be changed by drawing operations
- * to the rectangular area specified by the argument. Specifying
- * <code>null</code> for the rectangle reverts the receiver's clipping area
- * to its original value.
- *
- * @param rect
- * the clipping rectangle or <code>null</code>
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void setClipping(Rectangle rect) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (rect != null) {
- activeClipping = new QRegion(rect.x, rect.y, rect.width, rect.height);
- } else {
- activeClipping = null;
- }
- }
-
- /**
- * Sets the area of the receiver which can be changed by drawing operations
- * to the region specified by the argument. Specifying <code>null</code> for
- * the region reverts the receiver's clipping area to its original value.
- *
- * @param region
- * the clipping region or <code>null</code>
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the region has been
- * disposed</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void setClipping(Region region) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (region != null && region.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (region != null) {
- activeClipping = region.getQRegion();
- } else {
- activeClipping = null;
- }
- }
-
- /**
- * Sets the font which will be used by the receiver to draw and measure text
- * to the argument. If the argument is null, then a default font appropriate
- * for the platform will be used instead.
- *
- * @param font
- * the new font for the receiver, or null to indicate a default
- * font
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed
- * </li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void setFont(Font font) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (font != null && font.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.font = font != null ? font : data.device.getSystemFont();
- data.state &= ~FONT;
- }
-
- /**
- * Sets the foreground color. The foreground color is used for drawing
- * operations including when text is drawn.
- *
- * @param color
- * the new foreground color for the receiver
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been
- * disposed</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void setForeground(Color color) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (color == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (color.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (data.foregroundPattern == null && color.equals(data.foregroundColor)) {
- return;
- }
- data.foregroundPattern = null;
- data.foregroundColor = color;
- data.state &= ~(FOREGROUND | FOREGROUND_TEXT);
- }
-
- /**
- * Sets the foreground pattern. The default value is <code>null</code>.
- * <p>
- * This operation requires the operating system's advanced graphics
- * subsystem which may not be available on some platforms.
- * </p>
- *
- * @param pattern
- * the new foreground pattern
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been
- * disposed</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are
- * not available</li>
- * </ul>
- *
- * @see Pattern
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
- public void setForegroundPattern(Pattern pattern) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (pattern != null && pattern.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- // if (data.gdipGraphics == 0 && pattern == null)
- // return;
- // initGdip();
- if (data.foregroundPattern == pattern) {
- return;
- }
- data.foregroundPattern = pattern;
- data.state &= ~FOREGROUND;
- }
-
- /**
- * Sets the receiver's interpolation setting to the parameter, which must be
- * one of <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>,
- * <code>SWT.LOW</code> or <code>SWT.HIGH</code>.
- * <p>
- * This operation requires the operating system's advanced graphics
- * subsystem which may not be available on some platforms.
- * </p>
- *
- * @param interpolation
- * the new interpolation setting
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of
- * <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>,
- * <code>SWT.LOW</code> or <code>SWT.HIGH</code>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are
- * not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
- public void setInterpolation(int interpolation) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- //TODO
- //if (data.gdipGraphics == 0 && interpolation == SWT.DEFAULT)
- // int mode = 0;
- // switch (interpolation) {
- // case SWT.DEFAULT:
- // mode = Gdip.InterpolationModeDefault;
- // break;
- // case SWT.NONE:
- // mode = Gdip.InterpolationModeNearestNeighbor;
- // break;
- // case SWT.LOW:
- // mode = Gdip.InterpolationModeLowQuality;
- // break;
- // case SWT.HIGH:
- // mode = Gdip.InterpolationModeHighQuality;
- // break;
- // default:
- // SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- // }
- // initGdip();
- //Gdip.Graphics_SetInterpolationMode(data.gdipGraphics, mode);
- }
-
- /**
- * Sets the receiver's line attributes.
- * <p>
- * This operation requires the operating system's advanced graphics
- * subsystem which may not be available on some platforms.
- * </p>
- *
- * @param attributes
- * the line attributes
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the attributes is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if any of the line attributes
- * is not valid</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are
- * not available</li>
- * </ul>
- *
- * @see LineAttributes
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.3
- */
- public void setLineAttributes(LineAttributes attributes) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (attributes == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- int mask = 0;
- float lineWidth = attributes.width;
- if (lineWidth != data.lineWidth) {
- mask |= LINE_WIDTH | DRAW_OFFSET;
- }
- int lineStyle = attributes.style;
- if (lineStyle != data.lineStyle) {
- mask |= LINE_STYLE;
- switch (lineStyle) {
- case SWT.LINE_SOLID:
- case SWT.LINE_DASH:
- case SWT.LINE_DOT:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- break;
- case SWT.LINE_CUSTOM:
- if (attributes.dash == null) {
- lineStyle = SWT.LINE_SOLID;
- }
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- int join = attributes.join;
- if (join != data.lineJoin) {
- mask |= LINE_JOIN;
- switch (join) {
- case SWT.CAP_ROUND:
- case SWT.CAP_FLAT:
- case SWT.CAP_SQUARE:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- int cap = attributes.cap;
- if (cap != data.lineCap) {
- mask |= LINE_CAP;
- switch (cap) {
- case SWT.JOIN_MITER:
- case SWT.JOIN_ROUND:
- case SWT.JOIN_BEVEL:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- float[] dashes = attributes.dash;
- float[] lineDashes = data.lineDashes;
- if (dashes != null && dashes.length > 0) {
- boolean changed = lineDashes == null || lineDashes.length != dashes.length;
- for (int i = 0; i < dashes.length; i++) {
- float dash = dashes[i];
- if (dash <= 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (!changed && lineDashes[i] != dash) {
- changed = true;
- }
- }
- if (changed) {
- float[] newDashes = new float[dashes.length];
- System.arraycopy(dashes, 0, newDashes, 0, dashes.length);
- dashes = newDashes;
- mask |= LINE_STYLE;
- } else {
- dashes = lineDashes;
- }
- } else {
- if (lineDashes != null && lineDashes.length > 0) {
- mask |= LINE_STYLE;
- } else {
- dashes = lineDashes;
- }
- }
- float dashOffset = attributes.dashOffset;
- if (dashOffset != data.lineDashesOffset) {
- mask |= LINE_STYLE;
- }
- float miterLimit = attributes.miterLimit;
- if (miterLimit != data.lineMiterLimit) {
- mask |= LINE_MITERLIMIT;
- }
- // initGdip();
- if (mask == 0) {
- return;
- }
- data.lineWidth = lineWidth;
- data.lineStyle = lineStyle;
- data.lineCap = cap;
- data.lineJoin = join;
- data.lineDashes = dashes;
- data.lineDashesOffset = dashOffset;
- data.lineMiterLimit = miterLimit;
- data.state &= ~mask;
- }
-
- /**
- * Sets the receiver's line cap style to the argument, which must be one of
- * the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>, or
- * <code>SWT.CAP_SQUARE</code>.
- *
- * @param cap
- * the cap style to be used for drawing lines
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.1
- */
- public void setLineCap(int cap) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- if (data.lineCap == cap) {
- return;
- }
- switch (cap) {
- case SWT.CAP_ROUND:
- case SWT.CAP_FLAT:
- case SWT.CAP_SQUARE:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineCap = cap;
- data.state &= ~LINE_CAP;
- }
-
- /**
- * Sets the receiver's line dash style to the argument. The default value is
- * <code>null</code>. If the argument is not <code>null</code>, the
- * receiver's line style is set to <code>SWT.LINE_CUSTOM</code>, otherwise
- * it is set to <code>SWT.LINE_SOLID</code>.
- *
- * @param dashes
- * the dash style to be used for drawing lines
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_INVALID_ARGUMENT - if any of the values in the
- * array is less than or equal 0</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.1
- */
- public void setLineDash(int[] dashes) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- float[] lineDashes = data.lineDashes;
- if (dashes != null && dashes.length > 0) {
- boolean changed = data.lineStyle != SWT.LINE_CUSTOM || lineDashes == null
- || lineDashes.length != dashes.length;
- for (int i = 0; i < dashes.length; i++) {
- int dash = dashes[i];
- if (dash <= 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (!changed && lineDashes[i] != dash) {
- changed = true;
- }
- }
- if (!changed) {
- return;
- }
- data.lineDashes = new float[dashes.length];
- for (int i = 0; i < dashes.length; i++) {
- data.lineDashes[i] = dashes[i];
- }
- data.lineStyle = SWT.LINE_CUSTOM;
- } else {
- if (data.lineStyle == SWT.LINE_SOLID && (lineDashes == null || lineDashes.length == 0)) {
- return;
- }
- data.lineDashes = null;
- data.lineStyle = SWT.LINE_SOLID;
- }
- data.state &= ~LINE_STYLE;
- }
-
- /**
- * Sets the receiver's line join style to the argument, which must be one of
- * the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>,
- * or <code>SWT.JOIN_BEVEL</code>.
- *
- * @param join
- * the join style to be used for drawing lines
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.1
- */
- public void setLineJoin(int join) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (data.lineJoin == join) {
- return;
- }
- switch (join) {
- case SWT.JOIN_MITER:
- case SWT.JOIN_ROUND:
- case SWT.JOIN_BEVEL:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineJoin = join;
- data.state &= ~LINE_JOIN;
- }
-
- /**
- * Sets the receiver's line style to the argument, which must be one of the
- * constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>,
- * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or
- * <code>SWT.LINE_DASHDOTDOT</code>.
- *
- * @param lineStyle
- * the style to be used for drawing lines
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void setLineStyle(int lineStyle) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (data.lineStyle == lineStyle) {
- return;
- }
- switch (lineStyle) {
- case SWT.LINE_SOLID:
- case SWT.LINE_DASH:
- case SWT.LINE_DOT:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- break;
- case SWT.LINE_CUSTOM:
- if (data.lineDashes == null) {
- lineStyle = SWT.LINE_SOLID;
- }
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineStyle = lineStyle;
- data.state &= ~LINE_STYLE;
- }
-
- /**
- * Sets the width that will be used when drawing lines for all of the figure
- * drawing operations (that is, <code>drawLine</code>,
- * <code>drawRectangle</code>, <code>drawPolyline</code>, and so forth.
- * <p>
- * Note that line width of zero is used as a hint to indicate that the
- * fastest possible line drawing algorithms should be used. This means that
- * the output may be different from line width one.
- * </p>
- *
- * @param lineWidth
- * the width of a line
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void setLineWidth(int lineWidth) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- if (data.lineWidth == lineWidth) {
- return;
- }
- data.lineWidth = lineWidth;
- data.state &= ~(LINE_WIDTH | DRAW_OFFSET);
- }
-
- /**
- * Sets the receiver's text anti-aliasing value to the parameter, which must
- * be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code>. Note that this controls anti-aliasing only for all
- * <em>text drawing</em> operations.
- * <p>
- * This operation requires the operating system's advanced graphics
- * subsystem which may not be available on some platforms.
- * </p>
- *
- * @param antialias
- * the anti-aliasing setting
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one
- * of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or
- * <code>SWT.ON</code></li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are
- * not available</li>
- * </ul>
- *
- * @see #getAdvanced
- * @see #setAdvanced
- * @see #setAntialias
- *
- * @since 3.1
- */
- public void setTextAntialias(int antialias) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- //TODO
- // if (data.gdipGraphics == 0 && antialias == SWT.DEFAULT)
- // return;
- // int textMode = 0;
- // switch (antialias) {
- // case SWT.DEFAULT:
- // textMode = Gdip.TextRenderingHintSystemDefault;
- // break;
- // case SWT.OFF:
- // textMode = Gdip.TextRenderingHintSingleBitPerPixelGridFit;
- // break;
- // case SWT.ON:
- // int[] type = new int[1];
- // OS.SystemParametersInfo(OS.SPI_GETFONTSMOOTHINGTYPE, 0, type, 0);
- // if (type[0] == OS.FE_FONTSMOOTHINGCLEARTYPE) {
- // textMode = Gdip.TextRenderingHintClearTypeGridFit;
- // } else {
- // textMode = Gdip.TextRenderingHintAntiAliasGridFit;
- // }
- // break;
- // default:
- // SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- // }
- // // initGdip();
- // Gdip.Graphics_SetTextRenderingHint(data.gdipGraphics, textMode);
- }
-
- /**
- * Sets the transform that is currently being used by the receiver. If the
- * argument is <code>null</code>, the current transform is set to the
- * identity transform.
- * <p>
- * This operation requires the operating system's advanced graphics
- * subsystem which may not be available on some platforms.
- * </p>
- *
- * @param transform
- * the transform to set
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the parameter has been
- * disposed</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are
- * not available</li>
- * </ul>
- *
- * @see Transform
- * @see #getAdvanced
- * @see #setAdvanced
- *
- * @since 3.1
- */
- public void setTransform(Transform transform) {
- //TODO
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transform != null && transform.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- // if (data.gdipGraphics == 0 && transform == null)
- // return;
- // // initGdip();
- // int /* long */identity = identity();
- // if (transform != null) {
- // Gdip.Matrix_Multiply(identity, transform.handle, Gdip.MatrixOrderPrepend);
- // }
- // Gdip.Graphics_SetTransform(data.gdipGraphics, identity);
- // Gdip.Matrix_delete(identity);
- // data.state &= ~DRAW_OFFSET;
- }
- }
-
- /**
- * Returns the extent of the given string. No tab expansion or carriage
- * return processing will be performed.
- * <p>
- * The <em>extent</em> of a string is the width and height of the
- * rectangular area it would cover if drawn in a particular font (in this
- * case, the current font in the receiver).
- * </p>
- *
- * @param string
- * the string to measure
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public Point stringExtent(String string) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- return _textExtent(getActivePainter(), string, 0);
- }
-
- /**
- * Returns the extent of the given string. Tab expansion and carriage return
- * processing are performed.
- * <p>
- * The <em>extent</em> of a string is the width and height of the
- * rectangular area it would cover if drawn in a particular font (in this
- * case, the current font in the receiver).
- * </p>
- *
- * @param string
- * the string to measure
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public Point textExtent(String string) {
- return textExtent(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
- }
-
- /**
- * Returns the extent of the given string. Tab expansion, line delimiter and
- * mnemonic processing are performed according to the specified flags, which
- * can be a combination of:
- * <dl>
- * <dt><b>DRAW_DELIMITER</b></dt>
- * <dd>draw multiple lines</dd>
- * <dt><b>DRAW_TAB</b></dt>
- * <dd>expand tabs</dd>
- * <dt><b>DRAW_MNEMONIC</b></dt>
- * <dd>underline the mnemonic character</dd>
- * <dt><b>DRAW_TRANSPARENT</b></dt>
- * <dd>transparent background</dd>
- * </dl>
- * <p>
- * The <em>extent</em> of a string is the width and height of the
- * rectangular area it would cover if drawn in a particular font (in this
- * case, the current font in the receiver).
- * </p>
- *
- * @param string
- * the string to measure
- * @param flags
- * the flags specifying how to process the text
- * @return a point containing the extent of the string
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public Point textExtent(String string, int flags) {
- if (paintDevice == null) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (string == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- QPainter painter = getActivePainter();
- return _textExtent(painter, string, flags);
- }
-
- private Point _textExtent(QPainter painter, String string, int flags) {
- int qFlags = translateTextFlags(flags);
- painter.setFont(data.font.getQFont());
- QRect rect = painter.boundingRect((QRect) null, qFlags, string);
- //System.out.println("textExtent: " + string + " -> " + rect.width() + "x" + rect.height());
- return new Point(rect.width(), rect.height());
- }
-
- /**
- * Invokes platform specific functionality to allocate a new graphics
- * context.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public API for
- * <code>GC</code>. 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.
- * </p>
- *
- * @param drawable
- * the Drawable for the receiver.
- * @param data
- * the data for the receiver.
- *
- * @return a new <code>GC</code>
- */
- public static GC qt_new(Drawable drawable, GCData data) {
- GC gc = new GC();
- QPaintDeviceInterface paintDevice = drawable.internal_new_GC(data);
- gc.device = data.device;
- gc.init(drawable, data, paintDevice);
- return gc;
- }
-
- /**
- * Invokes platform specific functionality to wrap a graphics context.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public API for
- * <code>GC</code>. 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.
- * </p>
- *
- * @param hDC
- * the Windows HDC.
- * @param data
- * the data for the receiver.
- *
- * @return a new <code>GC</code>
- */
- public static GC qt_new(Drawable drawable, QPaintDeviceInterface paintDevice, GCData data) {
- GC gc = new GC();
- gc.device = data.device;
- gc.init(drawable, data, paintDevice);
- return gc;
- }
-
- /**
- * Returns a string containing a concise, human-readable description of the
- * receiver.
- *
- * @return a string representation of the receiver
- */
- @Override
- public String toString() {
- if (isDisposed()) {
- return "GC {*DISPOSED*}"; //$NON-NLS-1$
- }
- return "GC {" + paintDevice + "}"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/GCData.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/GCData.java
deleted file mode 100644
index a5050c0fdd..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/GCData.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.SWT;
-
-/**
- * Instances of this class are descriptions of GCs in terms of unallocated
- * platform-specific data fields.
- * <p>
- * <b>IMPORTANT:</b> This class is <em>not</em> part of the public API for SWT.
- * 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.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further
- * information</a>
- * @noinstantiate This class is not intended to be instantiated by clients.
- */
-
-public final class GCData {
- public Device device;
- public int style, state = -1;
- public Color foregroundColor = null;
- public Color backgroundColor = null;
- public Font font;
- public Pattern foregroundPattern;
- public Pattern backgroundPattern;
- public int lineStyle = SWT.LINE_SOLID;
- public float lineWidth;
- public int lineCap = SWT.CAP_FLAT;
- public int lineJoin = SWT.JOIN_MITER;
- public float lineDashesOffset;
- public float[] lineDashes;
- public float lineMiterLimit = 10;
- public int alpha = 0xFF;
- public Image image;
- public int layout = -1;
- public int uiState = 0;
- public boolean focusDrawn;
- public int handle;
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Image.java
deleted file mode 100644
index fe3374b526..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Image.java
+++ /dev/null
@@ -1,978 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import java.io.InputStream;
-import java.util.Arrays;
-import java.util.List;
-
-import com.trolltech.qt.core.QSize;
-import com.trolltech.qt.gui.QIcon;
-import com.trolltech.qt.gui.QImage;
-import com.trolltech.qt.gui.QPaintDeviceInterface;
-import com.trolltech.qt.gui.QPixmap;
-import com.trolltech.qt.gui.QImage.Format;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTError;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.widgets.Display;
-
-/**
- * Instances of this class are graphics which have been prepared for display on
- * a specific device. That is, they are ready to paint using methods such as
- * <code>GC.drawImage()</code> and display on widgets with, for example,
- * <code>Button.setImage()</code>.
- * <p>
- * If loaded from a file format that supports it, an <code>Image</code> may have
- * transparency, meaning that certain pixels are specified as being transparent
- * when drawn. Examples of file formats that support transparency are GIF and
- * PNG.
- * </p>
- * <p>
- * There are two primary ways to use <code>Images</code>. The first is to load a
- * graphic file from disk and create an <code>Image</code> from it. This is done
- * using an <code>Image</code> constructor, for example:
- *
- * <pre>
- * Image i = new Image(device, &quot;C:\\graphic.bmp&quot;);
- * </pre>
- *
- * A graphic file may contain a color table specifying which colors the image
- * was intended to possess. In the above example, these colors will be mapped to
- * the closest available color in SWT. It is possible to get more control over
- * the mapping of colors as the image is being created, using code of the form:
- *
- * <pre>
- * ImageData data = new ImageData(&quot;C:\\graphic.bmp&quot;);
- * RGB[] rgbs = data.getRGBs();
- * // At this point, rgbs contains specifications of all
- * // the colors contained within this image. You may
- * // allocate as many of these colors as you wish by
- * // using the Color constructor Color(RGB), then
- * // create the image:
- * Image i = new Image(device, data);
- * </pre>
- * <p>
- * Applications which require even greater control over the image loading
- * process should use the support provided in class <code>ImageLoader</code>.
- * </p>
- * <p>
- * Application code must explicitly invoke the <code>Image.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see Color
- * @see ImageData
- * @see ImageLoader
- * @see <a href="http://www.eclipse.org/swt/snippets/#image">Image snippets</a>
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples:
- * GraphicsExample, ImageAnalyzer</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further
- * information</a>
- */
-public final class Image extends Resource implements Drawable {
-
- /**
- * specifies whether the receiver is a bitmap or an icon (one of
- * <code>SWT.BITMAP</code>, <code>SWT.ICON</code>)
- */
- private int type = SWT.BITMAP;
-
- private int transparentPixel = -1;
-
- /**
- * The GC the image is currently selected in.
- */
- private GC memGC;
-
- /**
- * The global alpha value to be used for every pixel.
- */
- private int alpha = -1;
-
- private boolean hasMask = false;
-
- //private QImage image;
- private QIcon icon;
- private QPixmap pixmap;
-
- Image(Device device) {
- super(device);
- }
-
- /**
- * Constructs an empty instance of this class with the specified width and
- * height. The result may be drawn upon by creating a GC and using any of
- * its drawing operations, as shown in the following example:
- *
- * <pre>
- * Image i = new Image(device, width, height);
- * GC gc = new GC(i);
- * gc.drawRectangle(0, 0, 50, 50);
- * gc.dispose();
- * </pre>
- * <p>
- * Note: Some platforms may have a limitation on the size of image that can
- * be created (size depends on width, height, and depth). For example,
- * Windows 95, 98, and ME do not allow images larger than 16M.
- * </p>
- *
- * @param device
- * the device on which to create the image
- * @param width
- * the width of the new image
- * @param height
- * the height of the new image
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is
- * no current device</li>
- * <li>ERROR_INVALID_ARGUMENT - if either the width or height
- * is negative or zero</li>
- * </ul>
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for
- * image creation</li>
- * </ul>
- */
- public Image(Device device, int width, int height) {
- super(device);
- init(width, height);
- init();
- }
-
- /**
- * Constructs a new instance of this class based on the provided image, with
- * an appearance that varies depending on the value of the flag. The
- * possible flag values are:
- * <dl>
- * <dt><b>{@link SWT#IMAGE_COPY}</b></dt>
- * <dd>the result is an identical copy of srcImage</dd>
- * <dt><b>{@link SWT#IMAGE_DISABLE}</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>disabled</em> look</dd>
- * <dt><b>{@link SWT#IMAGE_GRAY}</b></dt>
- * <dd>the result is a copy of srcImage which has a <em>gray scale</em> look
- * </dd>
- * </dl>
- *
- * @param device
- * the device on which to create the image
- * @param srcImage
- * the image to use as the source
- * @param flag
- * the style, either <code>IMAGE_COPY</code>,
- * <code>IMAGE_DISABLE</code> or <code>IMAGE_GRAY</code>
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is
- * no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if srcImage is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the flag is not one of
- * <code>IMAGE_COPY</code>, <code>IMAGE_DISABLE</code> or
- * <code>IMAGE_GRAY</code></li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been
- * disposed</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or
- * an icon, or is otherwise in an invalid state</li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the image is
- * not supported</li>
- * </ul>
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for
- * image creation</li>
- * </ul>
- */
- public Image(Device device, Image srcImage, int flag) {
- super(device);
- if (srcImage == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (srcImage.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- device = this.device;
- this.type = srcImage.type;
- switch (flag) {
- case SWT.IMAGE_COPY:
- this.pixmap = new QPixmap(srcImage.pixmap);
- break;
- case SWT.IMAGE_DISABLE:
- this.pixmap = createDisabledImage(srcImage);
- break;
- case SWT.IMAGE_GRAY:
- this.pixmap = createGrayImage(srcImage);
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- init();
- }
-
- /**
- * Constructs an empty instance of this class with the width and height of
- * the specified rectangle. The result may be drawn upon by creating a GC
- * and using any of its drawing operations, as shown in the following
- * example:
- *
- * <pre>
- * Image i = new Image(device, boundsRectangle);
- * GC gc = new GC(i);
- * gc.drawRectangle(0, 0, 50, 50);
- * gc.dispose();
- * </pre>
- * <p>
- * Note: Some platforms may have a limitation on the size of image that can
- * be created (size depends on width, height, and depth). For example,
- * Windows 95, 98, and ME do not allow images larger than 16M.
- * </p>
- *
- * @param device
- * the device on which to create the image
- * @param bounds
- * a rectangle specifying the image's width and height (must not
- * be null)
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is
- * no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the bounds rectangle is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if either the rectangle's
- * width or height is negative</li>
- * </ul>
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for
- * image creation</li>
- * </ul>
- */
- public Image(Device device, Rectangle bounds) {
- super(device);
- if (bounds == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- init(bounds.width, bounds.height);
- init();
- }
-
- /**
- * Constructs an instance of this class from the given
- * <code>ImageData</code>.
- *
- * @param device
- * the device on which to create the image
- * @param data
- * the image data to create the image from (must not be null)
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is
- * no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the image data is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the
- * ImageData is not supported</li>
- * </ul>
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for
- * image creation</li>
- * </ul>
- */
- public Image(Device device, ImageData data) {
- super(device);
- init(data);
- init();
- }
-
- /**
- * Constructs an instance of this class, whose type is <code>SWT.ICON</code>
- * , from the two given <code>ImageData</code> objects. The two images must
- * be the same size. Pixel transparency in either image will be ignored.
- * <p>
- * The mask image should contain white wherever the icon is to be visible,
- * and black wherever the icon is to be transparent. In addition, the source
- * image should contain black wherever the icon is to be transparent.
- * </p>
- *
- * @param device
- * the device on which to create the icon
- * @param source
- * the color data for the icon
- * @param mask
- * the mask data for the icon
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is
- * no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if either the source or mask is
- * null</li>
- * <li>ERROR_INVALID_ARGUMENT - if source and mask are
- * different sizes</li>
- * </ul>
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for
- * image creation</li>
- * </ul>
- */
- public Image(Device device, ImageData source, ImageData mask) {
- super(device);
- if (source == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (mask == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (source.width != mask.width || source.height != mask.height) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- mask = ImageData.convertMask(mask);
- ImageData image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad,
- source.data);
- image.maskPad = mask.scanlinePad;
- image.maskData = mask.data;
- init(image);
- }
-
- /**
- * Constructs an instance of this class by loading its representation from
- * the specified input stream. Throws an error if an error occurs while
- * loading the image, or if the result is an image of an unsupported type.
- * Application code is still responsible for closing the input stream.
- * <p>
- * This constructor is provided for convenience when loading a single image
- * only. If the stream contains multiple images, only the first one will be
- * loaded. To load multiple images, use <code>ImageLoader.load()</code>.
- * </p>
- * <p>
- * This constructor may be used to load a resource as follows:
- * </p>
- *
- * <pre>
- * static Image loadImage(Display display, Class clazz, String string) {
- * InputStream stream = clazz.getResourceAsStream(string);
- * if (stream == null)
- * return null;
- * Image image = null;
- * try {
- * image = new Image(display, stream);
- * } catch (SWTException ex) {
- * } finally {
- * try {
- * stream.close();
- * } catch (IOException ex) {
- * }
- * }
- * return image;
- * }
- * </pre>
- *
- * @param device
- * the device on which to create the image
- * @param stream
- * the input stream to load the image from
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is
- * no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the stream is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from
- * the stream</li>
- * <li>ERROR_INVALID_IMAGE - if the image stream contains
- * invalid data</li>
- * <li>ERROR_UNSUPPORTED_DEPTH - if the image stream
- * describes an image with an unsupported depth</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image stream
- * contains an unrecognized format</li>
- * </ul>
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for
- * image creation</li>
- * </ul>
- */
- public Image(Device device, InputStream stream) {
- super(device);
- init(new ImageData(stream));
- init();
- }
-
- /**
- * Constructs an instance of this class by loading its representation from
- * the file with the specified name. Throws an error if an error occurs
- * while loading the image, or if the result is an image of an unsupported
- * type.
- * <p>
- * This constructor is provided for convenience when loading a single image
- * only. If the specified file contains multiple images, only the first one
- * will be used.
- *
- * @param device
- * the device on which to create the image
- * @param filename
- * the name of the file to load the image from
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is
- * no current device</li> <li>ERROR_NULL_ARGUMENT - if the
- * file name is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_IO - if an IO error occurs while reading from
- * the file</li> <li>ERROR_INVALID_IMAGE - if the image file
- * contains invalid data </li> <li>ERROR_UNSUPPORTED_DEPTH -
- * if the image file describes an image with an unsupported
- * depth</li> <li>ERROR_UNSUPPORTED_FORMAT - if the image
- * file contains an unrecognized format</li>
- * </ul>
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for
- * image creation</li>
- * </ul>
- */
- public Image(Device device, String filename) {
- super(device);
- if (filename == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- initNative(filename);
- if (this.pixmap == null) {
- init(new ImageData(filename));
- }
- init();
- }
-
- void init(int width, int height) {
- if (width <= 0 || height <= 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- this.type = SWT.BITMAP;
- pixmap = new QPixmap(width, height); //, Format.Format_ARGB32
- }
-
- void init(ImageData imageData) {
- if (imageData == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
-
- this.type = SWT.BITMAP;
-
- Format format = getImageFormat(imageData);
- byte[] buffer = imageData2RawData(imageData, format);
- QImage image = new QImage(buffer, imageData.width, imageData.height, format);
-
- if (imageData.colorTable != null) {
- image.setColorTable(imageData.colorTable);
- }
-
- if (imageData.maskData != null) {
- hasMask = true;
- }
- updateAlphaChannel(image, imageData);
-
- pixmap = QPixmap.fromImage(image);
-
- try {
- this.transparentPixel = getTransparentPixel(imageData);
- } catch (Error e) {
- pixmap = null;
- throw e;
- }
- }
-
- private Format getImageFormat(ImageData imageData) {
- switch (imageData.depth) {
- case 32:
- return Format.Format_ARGB32;
- case 24:
- return Format.Format_RGB888;
- case 16:
- return Format.Format_RGB16;
- case 8:
- case 4:
- return Format.Format_Indexed8;
- case 1:
- return Format.Format_Mono;
- default:
- throw new RuntimeException("invalid color depth"); //$NON-NLS-1$
- }
- }
-
- private void updateAlphaChannel(QImage image, ImageData imageData) {
- Format format = null;
- byte[] data = null;
- if (imageData.maskData != null) {
- // Mask data is 1 bit/pixel
- data = imageData.maskData;
- format = Format.Format_Mono;
- } else if (imageData.alpha != -1) {
- data = new byte[image.width() * image.height()];
- Arrays.fill(data, (byte) alpha);
- format = Format.Format_Indexed8;
- } else if (imageData.alphaData != null) {
- data = imageData.alphaData;
- format = Format.Format_Indexed8;
- }
- if (data != null) {
- QImage alpha = new QImage(data, imageData.width, imageData.height, format);
- image.setAlphaChannel(alpha);
- }
- }
-
- private byte[] imageData2RawData(ImageData image, Format format) {
- PaletteData palette = image.palette;
- if (!((image.depth == 1 || image.depth == 2 || image.depth == 4 || image.depth == 8) && !palette.isDirect
- || image.depth == 8 || (image.depth == 16 || image.depth == 24 || image.depth == 32)
- && palette.isDirect)) {
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- }
-
- byte[] buffer = image.data;
- if (format.equals(Format.Format_RGB888)) {
- // swap red and blue bytes
- for (int i = 0; i < buffer.length - 2; i += 3) {
- byte tmp = buffer[i + 2];
- buffer[i + 2] = buffer[i];
- buffer[i] = tmp;
- }
- }
-
- return buffer;
- }
-
- private int getTransparentPixel(ImageData image) {
- if (image.transparentPixel != -1) {
- PaletteData palette = image.palette;
- RGB rgb = null;
- if (palette.isDirect) {
- rgb = palette.getRGB(image.transparentPixel);
- } else {
- if (image.transparentPixel < palette.colors.length) {
- rgb = palette.getRGB(image.transparentPixel);
- }
- }
-
- if (rgb != null) {
- return rgb.red << 24 | rgb.green << 16 | rgb.blue << 8 | 0xFF;
- }
- }
- return -1;
- }
-
- void initNative(String filename) {
- if (filename.toLowerCase().endsWith(".ico")) { //$NON-NLS-1$
- this.type = SWT.ICON;
- icon = new QIcon(filename);
- } else {
- this.type = SWT.BITMAP;
- pixmap = new QPixmap(filename);
- }
- }
-
- private QPixmap createGrayImage(Image srcImage) {
- return srcImage.getQPixmap(); //.convertToFormat(Format.Format_Indexed8, ImageConversionFlag.ThresholdDither);
- }
-
- private QPixmap createDisabledImage(Image srcImage) {
- // TODO the same as gray?
- return createGrayImage(srcImage);
- }
-
- private QImage getQImage() {
- return pixmap.toImage();
- }
-
- public QIcon getQIcon() {
- // fallback strategy if image is a bitmap
- if (icon == null) {
- icon = new QIcon(getQPixmap());
- }
- return icon;
- }
-
- public QPixmap getQPixmap() {
- // if (pixmap == null) {
- // if (image != null) {
- // pixmap = QPixmap.fromImage(image);
- // } else if (icon != null) {
- // pixmap = icon.pixmap(getDefaultIconSize());
- // }
- // }
- return pixmap;
- }
-
- public QSize getDefaultIconSize() {
- List<QSize> sizes = getQIcon().availableSizes();
- if (sizes.isEmpty()) {
- return new QSize();
- }
- return sizes.get(0);
- }
-
- public boolean isIcon() {
- return type == SWT.ICON;
- }
-
- public boolean isBitmap() {
- return type == SWT.BITMAP;
- }
-
- @Override
- void destroy() {
- if (memGC != null) {
- memGC.dispose();
- memGC = null;
- }
- // image = null;
- // icon = null;
- pixmap = null;
- }
-
- /**
- * Compares the argument to the receiver, and returns true if they represent
- * the <em>same</em> object using a class specific comparison.
- *
- * @param object
- * the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and
- * <code>false</code> otherwise
- *
- * @see #hashCode
- */
- @Override
- public boolean equals(Object object) {
- if (object == this) {
- return true;
- }
- if (!(object instanceof Image)) {
- return false;
- }
- Image other = (Image) object;
- return device == other.device && pixmap == other.pixmap && transparentPixel == other.transparentPixel;
- }
-
- /**
- * Returns the color to which to map the transparent pixel, or null if the
- * receiver has no transparent pixel.
- * <p>
- * There are certain uses of Images that do not support transparency (for
- * example, setting an image into a button or label). In these cases, it may
- * be desired to simulate transparency by using the background color of the
- * widget to paint the transparent pixels of the image. Use this method to
- * check which color will be used in these cases in place of transparency.
- * This value may be set with setBackground().
- * <p>
- *
- * @return the background color of the image, or null if there is no
- * transparency in the image
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public Color getBackground() {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (transparentPixel == -1) {
- return null;
- }
- int red = transparentPixel >> 16 & 0xFF;
- int green = transparentPixel >> 8 & 0xFF;
- int blue = transparentPixel >> 0 & 0xFF;
- return new Color(device, red, green, blue);
- }
-
- /**
- * Returns the bounds of the receiver. The rectangle will always have x and
- * y values of 0, and the width and height of the image.
- *
- * @return a rectangle specifying the image's bounds
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or
- * an icon</li>
- * </ul>
- */
- public Rectangle getBounds() {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- return new Rectangle(0, 0, pixmap.width(), pixmap.height());
- }
-
- /**
- * Returns an <code>ImageData</code> based on the receiver Modifications
- * made to this <code>ImageData</code> will not affect the Image.
- *
- * @return an <code>ImageData</code> containing the image's data and
- * attributes
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or
- * an icon</li>
- * </ul>
- *
- * @see ImageData
- */
- public ImageData getImageData() {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
-
- QImage image = getQImage();
-
- PaletteData palette = new PaletteData(0x00FF0000, 0x00FF00, 0x00FF);
- ImageData imageData = new ImageData(image.width(), image.height(), image.depth(), palette, 4, image
- .copyOfBytes());
- imageData.bytesPerLine = image.bytesPerLine();
- imageData.transparentPixel = -1;
- imageData.alpha = alpha;
- imageData.alphaData = getAlphaData(image);
-
- if (image.numColors() > 0) {
- List<Integer> colorTable = image.colorTable();
- imageData.colorTable = colorTable;
- }
-
- return imageData;
- }
-
- private byte[] getAlphaData(QImage image) {
- if (hasMask) {
- // Mask data is 1 bit/pixel
- if (image.hasAlphaChannel()) {
- QImage alpha = image.alphaChannel();
- alpha.convertToFormat(Format.Format_Mono);
- return alpha.copyOfBytes();
- } else {
- int maskSize = image.width() * image.height() / 8;
- byte[] alphaData = new byte[maskSize];
- Arrays.fill(alphaData, (byte) 0xFF);
- return alphaData;
- //imageData.maskPad = 8;
- }
- } else if (alpha != -1) {
- byte[] alphaData = new byte[image.width() * image.height()];
- Arrays.fill(alphaData, (byte) alpha);
- return alphaData;
- } else if (image.hasAlphaChannel()) {
- QImage alpha = image.alphaChannel();
- return alpha.copyOfBytes();
- }
- return null;
- }
-
- public static Image qt_new(Display device, int type, QIcon qIcon) {
- Image image = new Image(device);
- image.type = type;
- image.icon = qIcon;
- return image;
- }
-
- /**
- * Returns an integer hash code for the receiver. Any two objects that
- * return <code>true</code> when passed to <code>equals</code> must return
- * the same value for this method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
- @Override
- public int hashCode() {
- return pixmap != null ? (int) pixmap.hashCode() : 0;
- }
-
- /**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public API for
- * <code>Image</code>. 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.
- * </p>
- *
- * @param data
- * the platform specific GC data
- * @return the platform specific GC handle
- */
- public QPaintDeviceInterface internal_new_GC(GCData data) {
- data.backgroundColor = getBackground();
- data.device = device;
- return pixmap;
- }
-
- /**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public API for
- * <code>Image</code>. 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.
- * </p>
- *
- * @param hDC
- * the platform specific GC handle
- * @param data
- * the platform specific GC data
- */
- public void internal_dispose_GC(QPaintDeviceInterface paintDevice, GCData data) {
- }
-
- /**
- * Returns <code>true</code> if the image has been disposed, and
- * <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the image. When an image has been
- * disposed, it is an error to invoke any other method using the image.
- *
- * @return <code>true</code> when the image is disposed and
- * <code>false</code> otherwise
- */
- @Override
- public boolean isDisposed() {
- return pixmap == null && icon == null;
- }
-
- /**
- * Sets the color to which to map the transparent pixel.
- * <p>
- * There are certain uses of <code>Images</code> that do not support
- * transparency (for example, setting an image into a button or label). In
- * these cases, it may be desired to simulate transparency by using the
- * background color of the widget to paint the transparent pixels of the
- * image. This method specifies the color that will be used in these cases.
- * For example:
- *
- * <pre>
- * Button b = new Button();
- * image.setBackground(b.getBackground());
- * b.setImage(image);
- * </pre>
- *
- * </p>
- * <p>
- * The image may be modified by this operation (in effect, the transparent
- * regions may be filled with the supplied color). Hence this operation is
- * not reversible and it is not legal to call this function twice or with a
- * null argument.
- * </p>
- * <p>
- * This method has no effect if the receiver does not have a transparent
- * pixel value.
- * </p>
- *
- * @param color
- * the color to use when a transparent pixel is specified
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been
- * disposed</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void setBackground(Color color) {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (color == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (color.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (transparentPixel == -1) {
- return;
- }
- return; // TODO function disabled
- // byte red = (byte) ((transparentPixel >> 16) & 0xFF);
- // byte green = (byte) ((transparentPixel >> 8) & 0xFF);
- // byte blue = (byte) ((transparentPixel >> 0) & 0xFF);
- // byte newRed = (byte) ((int) (color.handle[0] * 255) & 0xFF);
- // byte newGreen = (byte) ((int) (color.handle[1] * 255) & 0xFF);
- // byte newBlue = (byte) ((int) (color.handle[2] * 255) & 0xFF);
- // NSBitmapImageRep imageRep = getRepresentation();
- // long /* int */bpr = imageRep.bytesPerRow();
- // long /* int */data = imageRep.bitmapData();
- // byte[] line = new byte[(int) bpr];
- // for (int i = 0, offset = 0; i < height; i++, offset += bpr) {
- // OS.memmove(line, data + offset, bpr);
- // for (int j = 0; j < line.length; j += 4) {
- // if (line[j + 1] == red && line[j + 2] == green
- // && line[j + 3] == blue) {
- // line[j + 1] = newRed;
- // line[j + 2] = newGreen;
- // line[j + 3] = newBlue;
- // }
- // }
- // OS.memmove(data + offset, line, bpr);
- // }
- // transparentPixel = (newRed & 0xFF) << 16 | (newGreen & 0xFF) << 8
- // | (newBlue & 0xFF);
- }
-
- /**
- * Returns a string containing a concise, human-readable description of the
- * receiver.
- *
- * @return a string representation of the receiver
- */
- @Override
- public String toString() {
- if (isDisposed()) {
- return "Image {*DISPOSED*}"; //$NON-NLS-1$
- }
- return "Image {pixmap: " + pixmap + ", icon: " + icon + " }"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- public void setMemGC(GC gc) {
- this.memGC = gc;
- }
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Region.java b/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Region.java
deleted file mode 100644
index 23c2ec90e0..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/qt/org/eclipse/swt/graphics/Region.java
+++ /dev/null
@@ -1,776 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
- * Portion Copyright (c) 2009-2010 compeople AG (http://www.compeople.de).
- * 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
- * Compeople AG - QtJambi/Qt based implementation for Windows/Mac OS X/Linux
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import com.trolltech.qt.core.QPoint;
-import com.trolltech.qt.core.QRect;
-import com.trolltech.qt.gui.QRegion;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTError;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.internal.qt.QtSWTConverter;
-
-/**
- * Instances of this class represent areas of an x-y coordinate system that are
- * aggregates of the areas covered by a number of polygons.
- * <p>
- * Application code must explicitly invoke the <code>Region.dispose()</code>
- * method to release the operating system resources managed by each instance
- * when those instances are no longer required.
- * </p>
- *
- * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example:
- * GraphicsExample</a>
- * @see <a href="http://www.eclipse.org/swt/">Sample code and further
- * information</a>
- */
-
-public final class Region extends Resource {
-
- /**
- * the OS resource for the region (Warning: This field is platform
- * dependent)
- * <p>
- * <b>IMPORTANT:</b> This field is <em>not</em> 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.
- * </p>
- */
- private QRegion region;
-
- /**
- * Constructs a new empty region.
- *
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for
- * region creation</li>
- * </ul>
- */
- public Region() {
- this(null);
- }
-
- /**
- * Constructs a new empty region.
- * <p>
- * You must dispose the region when it is no longer required.
- * </p>
- *
- * @param device
- * the device on which to allocate the region
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is
- * no current device</li>
- * </ul>
- * @exception SWTError
- * <ul>
- * <li>ERROR_NO_HANDLES if a handle could not be obtained for
- * region creation</li>
- * </ul>
- *
- * @see #dispose
- *
- * @since 3.0
- */
- public Region(Device device) {
- super(device);
- region = new QRegion();
- init();
- }
-
- /**
- * Constructs a new region given a handle to the operating system resources
- * that it should represent.
- *
- * @param handle
- * the handle for the result
- */
- Region(Device device, QRegion region) {
- super(device);
- this.region = region;
- }
-
- QRegion getQRegion() {
- return region;
- }
-
- /**
- * 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
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.0
- *
- */
- public void add(int[] pointArray) {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (pointArray == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- QRegion rg = new QRegion(GC.createPolygonFromArray(pointArray));
- region = region.united(rg);
- }
-
- /**
- * 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
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or
- * height is negative</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void add(Rectangle rect) {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (rect == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- region = region.unite(QtSWTConverter.convert(rect));
- }
-
- /**
- * 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
- * <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or
- * height is negative</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @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);
- }
- region = region.united(new QRect(x, y, width, height));
- }
-
- /**
- * 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
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been
- * disposed</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public void add(Region region) {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (region == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (region.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- this.region = this.region.united(region.getQRegion());
- }
-
- /**
- * Returns <code>true</code> if the point specified by the arguments is
- * inside the area specified by the receiver, and <code>false</code>
- * 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 <code>true</code> if the region contains the point and
- * <code>false</code> otherwise
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public boolean contains(int x, int y) {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return region.contains(new QPoint(x, y));
- }
-
- /**
- * Returns <code>true</code> if the given point is inside the area specified
- * by the receiver, and <code>false</code> otherwise.
- *
- * @param pt
- * the point to test for containment
- * @return <code>true</code> if the region contains the point and
- * <code>false</code> otherwise
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public boolean contains(Point pt) {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (pt == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- return region.contains(QtSWTConverter.convert(pt));
- }
-
- @Override
- void destroy() {
- region = null;
- }
-
- /**
- * Compares the argument to the receiver, and returns true if they represent
- * the <em>same</em> object using a class specific comparison.
- *
- * @param object
- * the object to compare with this object
- * @return <code>true</code> if the object is the same as this object and
- * <code>false</code> otherwise
- *
- * @see #hashCode
- */
- @Override
- public boolean equals(Object object) {
- if (this == object) {
- return true;
- }
- if (!(object instanceof Region)) {
- return false;
- }
- return region.equals(((Region) object).getQRegion());
- }
-
- /**
- * 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
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see Rectangle#union
- */
- public Rectangle getBounds() {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return QtSWTConverter.convert(region.boundingRect());
- }
-
- /**
- * Returns an integer hash code for the receiver. Any two objects that
- * return <code>true</code> when passed to <code>equals</code> must return
- * the same value for this method.
- *
- * @return the receiver's hash
- *
- * @see #equals
- */
- @Override
- public int hashCode() {
- return region.hashCode();
- }
-
- /**
- * 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
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or
- * height is negative</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.0
- */
- public void intersect(Rectangle rect) {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (rect == 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
- * <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or
- * height is negative</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @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);
- }
- region = region.intersect(new QRect(x, y, width, height));
- }
-
- /**
- * 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
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been
- * disposed</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.0
- */
- public void intersect(Region region) {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (region == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (region.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- this.region = this.region.intersected(region.getQRegion());
- }
-
- /**
- * Returns <code>true</code> if the rectangle described by the arguments
- * intersects with any of the polygons the receiver maintains to describe
- * its area, and <code>false</code> 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 <code>true</code> if the rectangle intersects with the receiver,
- * and <code>false</code> otherwise
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see Rectangle#intersects(Rectangle)
- */
- public boolean intersects(int x, int y, int width, int height) {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return region.intersects(new QRect(x, y, width, height));
- }
-
- /**
- * Returns <code>true</code> if the given rectangle intersects with any of
- * the polygons the receiver maintains to describe its area and
- * <code>false</code> otherwise.
- *
- * @param rect
- * the rectangle to test for intersection
- * @return <code>true</code> if the rectangle intersects with the receiver,
- * and <code>false</code> otherwise
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @see Rectangle#intersects(Rectangle)
- */
- public boolean intersects(Rectangle rect) {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (rect == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- return intersects(rect.x, rect.y, rect.width, rect.height);
- }
-
- /**
- * Returns <code>true</code> if the region has been disposed, and
- * <code>false</code> otherwise.
- * <p>
- * 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 <code>true</code> when the region is disposed, and
- * <code>false</code> otherwise
- */
- @Override
- public boolean isDisposed() {
- return region == null;
- }
-
- /**
- * Returns <code>true</code> if the receiver does not cover any area in the
- * (x, y) coordinate plane, and <code>false</code> if the receiver does
- * cover some area in the plane.
- *
- * @return <code>true</code> if the receiver is empty, and
- * <code>false</code> otherwise
- *
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- */
- public boolean isEmpty() {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- return region.isEmpty();
- }
-
- /**
- * 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
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.0
- */
- public void subtract(int[] pointArray) {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (pointArray == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- QRegion rg = new QRegion(GC.createPolygonFromArray(pointArray));
- region = region.subtracted(rg);
- }
-
- /**
- * 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
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or
- * height is negative</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.0
- */
- public void subtract(Rectangle rect) {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (rect == 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
- * <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or
- * height is negative</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @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);
- }
- region = region.subtracted(new QRegion(x, y, width, height));
- }
-
- /**
- * 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
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been
- * disposed</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.0
- */
- public void subtract(Region region) {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (region == null) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- if (region.isDisposed()) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- this.region = this.region.subtracted(region.getQRegion());
- }
-
- /**
- * 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
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.1
- */
- public void translate(int x, int y) {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- region = region.translated(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
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the argument is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been
- * disposed</li>
- * </ul>
- *
- * @since 3.1
- */
- public void translate(Point pt) {
- if (isDisposed()) {
- SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- }
- if (pt == 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
- */
- @Override
- public String toString() {
- if (isDisposed()) {
- return "Region {*DISPOSED*}"; //$NON-NLS-1$
- }
- return "Region {" + region + "}"; //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- /**
- * Invokes platform specific functionality to allocate a new region.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public API for
- * <code>Region</code>. 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.
- * </p>
- *
- * @param device
- * the device on which to allocate the region
- * @param handle
- * the handle for the region
- * @return a new region object containing the specified device and handle
- */
- public static Region win32_new(Device device, QRegion region) {
- return new Region(device, region);
- }
-
-}