+ * - ERROR_NULL_ARGUMENT - if the image is null
+ * - ERROR_INVALID_ARGUMENT - if the image has been disposed
+ * - ERROR_INVALID_ARGUMENT - if the given coordinates are
+ * outside the bounds of the image
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ * @exception SWTError
+ *
+ * - ERROR_NO_HANDLES - if no handles are available to perform
+ * the operation
+ *
+ */
+public void drawImage(Image image, int x, int y) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (image == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ if (image.isDisposed()) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ // Reset all mirroring transformation and calculate the mirrored coordinates
+ // manually.
+ if ((data.style & SWT.MIRRORED) != 0) {
+ data.internalGc.resetTransform();
+ data.state = ~FOREGROUND;
+ int clientWidth = OS.QPaintDevice_width(data.drawable);
+ x = clientWidth - x - image.getBounds().width;
+ }
+ data.internalGc.drawImage(image.getImage(), x, y);
+}
+
+/**
+ * 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
+ *
+ * - ERROR_NULL_ARGUMENT - if the image is null
+ * - ERROR_INVALID_ARGUMENT - if the image has been disposed
+ * - ERROR_INVALID_ARGUMENT - if any of the width or height
+ * arguments are negative.
+ *
- ERROR_INVALID_ARGUMENT - if the source rectangle is not
+ * contained within the bounds of the source image
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ * @exception SWTError
+ *
+ * - ERROR_NO_HANDLES - if no handles are available to perform
+ * the operation
+ *
+ */
+public void drawImage(Image image, int srcX, int srcY, int srcWidth,
+ int srcHeight, int destX, int destY, int destWidth, int destHeight) {
+ if (handle == 0) {
+ 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);
+ }
+ // Reset all mirroring transformation and calculate the mirrored coordinates
+ // manually.
+ if ((data.style & SWT.MIRRORED) != 0) {
+ data.internalGc.resetTransform();
+ data.state = ~FOREGROUND;
+ int clientWidth = OS.QPaintDevice_width(data.drawable);
+ srcX = image.getBounds().width - srcX - srcWidth;
+ destX = clientWidth - destX - destWidth;
+ }
+ data.internalGc.drawImage(image.getImage(), destX, destY,
+ destWidth, destHeight, srcX, srcY, srcWidth, srcHeight);
+}
+
+/**
+ * Draws a line, using the foreground color, between the points (x1
+ * , y1
) and (x2
, y2
).
+ *
+ * @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
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public void drawLine(int x1, int y1, int x2, int y2) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ checkGC(FOREGROUND);
+ data.internalGc.drawLine(x1, y1, x2, y2);
+}
+
+/**
+ * Draws the outline of an oval, using the foreground color, within the
+ * specified rectangular area.
+ *
+ * The result is a circle or ellipse that fits within the rectangle specified by
+ * the x
, y
, width
, and
+ * height
arguments.
+ *
+ *
+ * The oval covers an area that is width + 1
pixels wide and
+ * height + 1
pixels tall.
+ *
+ *
+ * @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
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public void drawOval(int x, int y, int width, int height) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (width < 0) {
+ x = x + width;
+ width = -width;
+ }
+ if (height < 0) {
+ y = y + height;
+ height = -height;
+ }
+ checkGC(FOREGROUND);
+ data.internalGc.drawEllipse(x, y, width, height);
+}
+
+/**
+ * Draws a pixel, using the foreground color, at the specified point (
+ * x
, y
).
+ *
+ * Note that the receiver's line attributes do not affect this operation.
+ *
+ *
+ * @param x
+ * the point's x coordinate
+ * @param y
+ * the point's y coordinate
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ *
+ * @since 3.0
+ */
+public void drawPoint(int x, int y) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ checkGC(FOREGROUND);
+ data.internalGc.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
+ *
+ * - ERROR_NULL_ARGUMENT if pointArray is null
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public void drawPolygon(int[] pointArray) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (pointArray == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ checkGC(FOREGROUND);
+ data.internalGc.drawPolygon(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
+ *
+ * - ERROR_NULL_ARGUMENT - if the point array is null
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public void drawPolyline(int[] pointArray) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (pointArray == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ checkGC(FOREGROUND);
+ data.internalGc.drawPolyline(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
+ * x
and x + width
. The top and bottom edges are at
+ * y
and y + height
.
+ *
+ * @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
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public void drawRectangle(int x, int y, int width, int height) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (width < 0) {
+ x = x + width;
+ width = -width;
+ }
+ if (height < 0) {
+ y = y + height;
+ height = -height;
+ }
+ checkGC(FOREGROUND);
+ data.internalGc.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 rect.x
+ * and rect.x + rect.width
. The top and bottom edges are at
+ * rect.y
and rect.y + rect.height
.
+ *
+ * @param rect
+ * the rectangle to draw
+ *
+ * @exception IllegalArgumentException
+ *
+ * - ERROR_NULL_ARGUMENT - if the rectangle is null
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+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 x
and x + width
. The top and
+ * bottom edges are at y
and y + height
. The
+ * roundness of the corners is specified by the arcWidth
+ * and arcHeight
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
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public void drawRoundRectangle(int x, int y, int width, int height,
+ int arcWidth, int arcHeight) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ checkGC(FOREGROUND);
+ data.internalGc.drawRoundRect(x, y, width, height, arcWidth, arcHeight);
+}
+
+/**
+ * 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
+ *
+ * - ERROR_NULL_ARGUMENT - if the string is null
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+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
+ * isTransparent
is true
, 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 true
the background will be transparent, otherwise
+ * it will be opaque
+ *
+ * @exception IllegalArgumentException
+ *
+ * - ERROR_NULL_ARGUMENT - if the string is null
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public void drawString(String string, int x, int y, boolean isTransparent) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (string == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ if (string.length() == 0) {
+ return;
+ }
+ // Reset all mirroring transformation and calculate the mirrored coordinates
+ // manually.
+ if ((data.style & SWT.MIRRORED) != 0) {
+ data.internalGc.resetTransform();
+ data.state = ~FOREGROUND;
+ int clientWidth = OS.QPaintDevice_width(data.drawable);
+ int box[] = new int[4];
+ data.internalGc
+ .getTextBoundingBox(
+ box,
+ string,
+ (GraphicsContext.ALIGNMENT_LEFT | GraphicsContext.ALIGNMENT_TOP),
+ GraphicsContext.TEXT_SINGLE_LINE);
+ x = clientWidth - x - box[GraphicsContext.RECT_WIDTH];
+ }
+ data.internalGc.drawString(string, x, y, isTransparent);
+}
+
+/**
+ * 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
+ *
+ * - ERROR_NULL_ARGUMENT - if the string is null
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+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, line delimiter and mnemonic processing are performed
+ * according to the specified flags. If flags
includes
+ * DRAW_TRANSPARENT
, 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.
+ *
+ * The parameter flags
may be a combination of:
+ *
+ * - DRAW_DELIMITER
+ * - draw multiple lines
+ * - DRAW_TAB
+ * - expand tabs
+ * - DRAW_MNEMONIC
+ * - underline the mnemonic character
+ * - DRAW_TRANSPARENT
+ * - transparent background
+ *
+ *
+ *
+ * @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
+ *
+ * - ERROR_NULL_ARGUMENT - if the string is null
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public void drawText(String string, int x, int y, int flags) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (string == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ if (string.length() == 0) {
+ return;
+ }
+
+ int translatedFlags = 0;
+ boolean isTransparent = false;
+
+ if ((flags & SWT.DRAW_DELIMITER) == 0) {
+ translatedFlags |= GraphicsContext.TEXT_SINGLE_LINE;
+ }
+ if ((flags & SWT.DRAW_TAB) != 0) {
+ translatedFlags |= GraphicsContext.TEXT_EXPAND_TABS;
+ }
+ if ((flags & SWT.DRAW_MNEMONIC) != 0) {
+ translatedFlags |= GraphicsContext.TEXT_SHOW_MNEMONIC;
+ }
+ if ((flags & SWT.DRAW_TRANSPARENT) != 0) {
+ isTransparent = true;
+ }
+ // Reset all mirroring transformation and calculate the mirrored coordinates
+ // manually.
+ if ((data.style & SWT.MIRRORED) != 0) {
+ data.internalGc.resetTransform();
+ data.state = ~FOREGROUND;
+ int clientWidth = OS.QPaintDevice_width(data.drawable);
+ int box[] = new int[4];
+ data.internalGc
+ .getTextBoundingBox(
+ box,
+ string,
+ (GraphicsContext.ALIGNMENT_HCENTER | GraphicsContext.ALIGNMENT_LEFT),
+ translatedFlags);
+ x = clientWidth - x - box[GraphicsContext.RECT_WIDTH];
+ }
+ data.internalGc
+ .drawString(
+ string,
+ x,
+ y,
+ 0,
+ 0,
+ (GraphicsContext.ALIGNMENT_HCENTER | GraphicsContext.ALIGNMENT_LEFT),
+ translatedFlags, isTransparent);
+}
+
+/**
+ * Compares the argument to the receiver, and returns true if they represent the
+ * same object using a class specific comparison.
+ *
+ * @param object
+ * the object to compare with this object
+ * @return true
if the object is the same as this object and
+ * false
otherwise
+ *
+ * @see #hashCode
+ */
+public boolean equals(Object object) {
+ if (object == this) {
+ return true;
+ }
+ if (!(object instanceof GC)) {
+ return false;
+ }
+ return handle == ((GC) object).handle;
+}
+
+/**
+ * Fills the interior of a circular or elliptical arc within the specified
+ * rectangular area, with the receiver's background color.
+ *
+ * The resulting arc begins at startAngle
and extends for
+ * arcAngle
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.
+ *
+ *
+ * The center of the arc is the center of the rectangle whose origin is (
+ * x
, y
) and whose size is specified by the
+ * width
and height
arguments.
+ *
+ *
+ * The resulting arc covers an area width + 1
pixels wide by
+ * height + 1
pixels tall.
+ *
+ *
+ * @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
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ *
+ * @see #drawArc
+ */
+public void fillArc(int x, int y, int width, int height, int startAngle,
+ int arcAngle) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (width < 0) {
+ x = x + width;
+ width = -width;
+ }
+ if (height < 0) {
+ y = y + height;
+ height = -height;
+ }
+ if (width == 0 || height == 0 || arcAngle == 0) {
+ return;
+ }
+ checkGC(FOREGROUND);
+ data.internalGc.fillArc(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
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ *
+ * @see #drawRectangle(int, int, int, int)
+ */
+public void fillGradientRectangle(int x, int y, int width, int height,
+ boolean vertical) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if ((width == 0) || (height == 0)) {
+ return;
+ }
+
+ boolean swapColors = false;
+ if (width < 0) {
+ if (!vertical) {
+ swapColors = true;
+ }
+ width = Math.abs(width);
+ }
+ if (height < 0) {
+ if (vertical) {
+ swapColors = true;
+ }
+ height = Math.abs(height);
+ }
+ checkGC(FOREGROUND);
+ data.internalGc.fillGradientRect(x, y, width, height, vertical, swapColors);
+}
+
+/**
+ * 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
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ *
+ * @see #drawOval
+ */
+public void fillOval(int x, int y, int width, int height) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (width < 0) {
+ x = x + width;
+ width = -width;
+ }
+ if (height < 0) {
+ y = y + height;
+ height = -height;
+ }
+ checkGC(FOREGROUND);
+ data.internalGc.fillEllipse(x, y, width, height);
+}
+
+/**
+ * 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
+ *
+ * - ERROR_NULL_ARGUMENT if pointArray is null
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ *
+ * @see #drawPolygon
+ */
+public void fillPolygon(int[] pointArray) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (pointArray == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ checkGC(FOREGROUND);
+ data.internalGc.fillPolygon(pointArray);
+}
+
+/**
+ * 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
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ *
+ * @see #drawRectangle(int, int, int, int)
+ */
+public void fillRectangle(int x, int y, int width, int height) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (width < 0) {
+ x = x + width;
+ width = -width;
+ }
+ if (height < 0) {
+ y = y + height;
+ height = -height;
+ }
+ checkGC(FOREGROUND);
+ data.internalGc.fillRect(x, y, width, height);
+}
+
+/**
+ * Fills the interior of the specified rectangle, using the receiver's
+ * background color.
+ *
+ * @param rect
+ * the rectangle to be filled
+ *
+ * @exception IllegalArgumentException
+ *
+ * - ERROR_NULL_ARGUMENT - if the rectangle is null
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ *
+ * @see #drawRectangle(int, int, int, int)
+ */
+public void fillRectangle(Rectangle rect) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ 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
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ *
+ * @see #drawRoundRectangle
+ */
+public void fillRoundRectangle(int x, int y, int width, int height,
+ int arcWidth, int arcHeight) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ checkGC(FOREGROUND);
+ data.internalGc.fillRoundRect(x, y, width, height, arcWidth, arcHeight);
+}
+
+/**
+ * Returns the advance width of the specified character in the font
+ * which is currently selected into the receiver.
+ *
+ * The advance width is defined as the horizontal distance the cursor should
+ * move after printing the character in the selected font.
+ *
+ *
+ * @param ch
+ * the character to measure
+ * @return the distance in the x direction to move past the character before
+ * painting the next
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public int getAdvanceWidth(char ch) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ return data.internalGc.getAdvancedCharacterWidth(ch);
+}
+
+/**
+ * Returns the receiver's alpha value. Default alpha value is 0xFF, fully opaque
+ *
+ *
+ * @return the alpha value
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public int getAlpha() {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ return data.alpha;
+}
+
+/**
+ * Returns the background color.
+ *
+ * @return the receiver's background color
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public Color getBackground() {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ return customBackground != null ? customBackground : data.background;
+}
+
+/**
+ * Returns the width of the specified character in the font selected into the
+ * receiver.
+ *
+ * The width is defined as the space taken up by the actual character, not
+ * including the leading and tailing whitespace or overhang.
+ *
+ *
+ * @param ch
+ * the character to measure
+ * @return the width of the character
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public int getCharWidth(char ch) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ return data.internalGc.getCharacterWidth(ch);
+}
+
+/**
+ * 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
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public Rectangle getClipping() {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ checkGC(FOREGROUND);
+ if (data.clippingRect == null) {
+ int[] clip = new int[4];
+ data.internalGc.getClip(clip);
+ data.clippingRect = new Rectangle(clip[GraphicsContext.RECT_X],
+ clip[GraphicsContext.RECT_Y], clip[GraphicsContext.RECT_WIDTH],
+ clip[GraphicsContext.RECT_HEIGHT]);
+ }
+ return new Rectangle(data.clippingRect.x, data.clippingRect.y,
+ data.clippingRect.width, data.clippingRect.height);
+}
+
+/**
+ * Returns the font currently being used by the receiver to draw and measure
+ * text.
+ *
+ * @return the receiver's font
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public Font getFont() {
+ if (handle == 0) {
+ 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. Note that if the font is
+ * changed later, the font metrics object is not updated accordingly.
+ *
+ * @return font metrics for the receiver's font
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public FontMetrics getFontMetrics() {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+
+ // Read the FontMetrics data from the native
+ int fmData[] = new int[FM_DATA_COUNT];
+ data.internalGc.getFontMetricsData(fmData, 0, false);
+ // Create and fill up FonMetrics object.
+ FontMetrics fm = new FontMetrics();
+ fm.ascent = fmData[FM_ASCENT];
+ fm.averageCharWidth = fmData[FM_AVERAGE_CHAR_WIDTH];
+ fm.descent = fmData[FM_DESCENT];
+ fm.height = fmData[FM_HEIGHT];
+ fm.leading = fmData[FM_LEADING];
+ return fm;
+}
+
+/**
+ * Returns the receiver's foreground color.
+ *
+ * @return the color used for drawing foreground things
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public Color getForeground() {
+ if (isDisposed()) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ return customForeground != null ? customForeground : data.foreground;
+}
+
+/**
+ * Returns the GCData.
+ *
+ * IMPORTANT: This method is not part of the public API for
+ * GC
. 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.
+ *
+ *
+ * @return the receiver's GCData
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ *
+ * @see GCData
+ *
+ * @since 3.2
+ */
+public GCData getGCData() {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ return data;
+}
+
+/**
+ * Returns the receiver's line style, which will be one of the constants
+ * SWT.LINE_SOLID
, SWT.LINE_DASH
,
+ * SWT.LINE_DOT
, SWT.LINE_DASHDOT
or
+ * SWT.LINE_DASHDOTDOT
.
+ *
+ * @return the style used for drawing lines
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public int getLineStyle() {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (data.lineStyle == GCData.NOT_DEFINED) {
+ data.lineStyle = GCData.translateStrokeStyle(data.internalGc
+ .getStrokeStyle(), false);
+ }
+ return data.lineStyle;
+}
+
+/**
+ * Returns the width that will be used when drawing lines for all of the figure
+ * drawing operations (that is, drawLine
,
+ * drawRectangle
, drawPolyline
, and so forth.
+ *
+ * @return the receiver's line width
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public int getLineWidth() {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (data.lineWidth == GCData.NOT_DEFINED) {
+ data.lineWidth = data.internalGc.getStrokeWidth();
+ }
+ return data.lineWidth;
+}
+
+/**
+ * Returns the receiver's style information.
+ *
+ * Note that the value which is returned by this method may
+ * not match 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.
+ *
+ *
+ * @return the style bits. Possible values are:
+ *
+ * - LEFT_TO_RIGHT
+ * - RIGHT_TO_LEFT
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ *
+ * @since 2.1.2
+ */
+public int getStyle() {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ return data.style;
+}
+
+/**
+ * Returns true
if this GC is drawing in the mode where the
+ * resulting color in the destination is the exclusive or of the color
+ * values in the source and the destination, and false
if it is
+ * drawing in the mode where the destination color is being replaced with the
+ * source color value.
+ *
+ * @return true
true if the receiver is in XOR mode, and false
+ * otherwise
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public boolean getXORMode() {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (data.xorMode == GCData.NOT_DEFINED) {
+ data.xorMode = (data.internalGc.getBlendingMode() == GraphicsContext.BLENDING_MODE_XOR ? GCData.XOR_MODE_ON
+ : GCData.XOR_MODE_OFF);
+ }
+ return (data.xorMode == GCData.XOR_MODE_ON);
+}
+
+/**
+ * Returns an integer hash code for the receiver. Any two objects that return
+ * true
when passed to equals
must return the same
+ * value for this method.
+ *
+ * @return the receiver's hash
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ *
+ * @see #equals
+ */
+public int hashCode() {
+ return handle;
+}
+
+void init(Drawable drawable, GCData data, int /* long */gcHandle) {
+ this.drawable = drawable;
+ this.data = data;
+ this.handle = gcHandle;
+ if (data.foreground == null) {
+ data.foreground = data.device.getSystemColor(SWT.COLOR_BLACK);
+ }
+ if (data.background == null) {
+ data.background = data.device.getSystemColor(SWT.COLOR_WHITE);
+ }
+ data.internalGc.setForegroundColor(data.foreground.getRed(),
+ data.foreground.getGreen(), data.foreground.getBlue());
+ data.internalGc.setBackgroundColor(data.background.getRed(),
+ data.background.getGreen(), data.background.getBlue());
+ this.drawable = drawable;
+ this.data = data;
+ handle = gcHandle;
+}
+
+/**
+ * Returns true
if the receiver has a clipping region set into it,
+ * and false
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 getClipping(region)
.
+ *
+ * @return true
if the GC has a clipping region, and
+ * false
otherwise
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public boolean isClipped() {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ return data.internalGc.hasClipping();
+}
+
+/**
+ * Returns true
if the GC has been disposed, and false
+ * otherwise.
+ *
+ * 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 true
when the GC is disposed and false
+ * otherwise
+ */
+public boolean isDisposed() {
+ return handle == 0;
+}
+
+/**
+ * Sets the receiver's alpha value.
+ *
+ * This operation requires the operating system's advanced graphics subsystem
+ * which may not be available on some platforms.
+ *
+ *
+ * @param alpha
+ * the alpha value
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ * - ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not
+ * available
+ *
+ *
+ * @see #getAdvanced
+ * @see #setAdvanced
+ *
+ * @since 3.1
+ */
+public void setAlpha(int alpha) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ data.alpha = alpha & 0xff;
+ data.internalGc.setForegroundAlpha(data.alpha);
+ data.internalGc.setBackgroundAlpha(data.alpha);
+}
+
+/**
+ * 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
+ *
+ * - ERROR_NULL_ARGUMENT - if the color is null
+ * - ERROR_INVALID_ARGUMENT - if the color has been disposed
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public void setBackground(Color color) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (color == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ if (color.isDisposed()) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ this.customBackground = color;
+ data.internalGc.setBackgroundColor(color.getRed(), color.getGreen(), color
+ .getBlue());
+}
+
+/**
+ * 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
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public void setClipping(int x, int y, int width, int height) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (width < 0) {
+ x = x + width;
+ width = -width;
+ }
+ if (height < 0) {
+ y = y + height;
+ height = -height;
+ }
+ // Reset all mirroring transformation and calculate the mirrored coordinates
+ // manually.
+ if ((data.style & SWT.MIRRORED) != 0) {
+ data.internalGc.resetTransform();
+ data.state = ~FOREGROUND;
+ int clientWidth = OS.QPaintDevice_width(data.drawable);
+ x = clientWidth - x - (width + 1);
+ }
+ data.clippingRect = new Rectangle(x, y, width, height);
+ data.internalGc.setClip(x, y, width + 1, height, false);
+}
+
+/**
+ * Sets the area of the receiver which can be changed by drawing operations to
+ * the rectangular area specified by the argument. Specifying null
+ * for the rectangle reverts the receiver's clipping area to its original value.
+ *
+ * @param rect
+ * the clipping rectangle or null
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public void setClipping(Rectangle rect) {
+ if (handle == 0)
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (rect != null) {
+ setClipping(rect.x, rect.y, rect.width, rect.height);
+ } else {
+ data.internalGc.cancelClipping();
+ }
+}
+
+/**
+ * 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
+ *
+ * - ERROR_INVALID_ARGUMENT - if the font has been disposed
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public void setFont(Font font) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (font != null && font.isDisposed()) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ data.font = font != null ? font : Font.qt_new(data.device, OS.SwtFontCache_cache(OS.QApplication_swt_font_new()));
+ data.internalGc.setFont(data.font.handle);
+}
+
+/**
+ * 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
+ *
+ * - ERROR_NULL_ARGUMENT - if the color is null
+ * - ERROR_INVALID_ARGUMENT - if the color has been disposed
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public void setForeground(Color color) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (color == null) {
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+ }
+ if (color.isDisposed()) {
+ SWT.error(SWT.ERROR_INVALID_ARGUMENT);
+ }
+ customForeground = color;
+ data.internalGc.setForegroundColor(color.getRed(), color.getGreen(), color
+ .getBlue());
+}
+
+/**
+ * Sets the receiver's line style to the argument, which must be one of the
+ * constants SWT.LINE_SOLID
, SWT.LINE_DASH
,
+ * SWT.LINE_DOT
, SWT.LINE_DASHDOT
or
+ * SWT.LINE_DASHDOTDOT
.
+ *
+ * @param lineStyle
+ * the style to be used for drawing lines
+ *
+ * @exception IllegalArgumentException
+ *
+ * - ERROR_INVALID_ARGUMENT - if the style is not valid
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public void setLineStyle(int lineStyle) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (data.lineStyle == lineStyle) {
+ return;
+ }
+ data.internalGc
+ .setStrokeStyle(GCData.translateStrokeStyle(lineStyle, true));
+ data.lineStyle = lineStyle;
+}
+
+/**
+ * Sets the width that will be used when drawing lines for all of the figure
+ * drawing operations (that is, drawLine
,
+ * drawRectangle
, drawPolyline
, and so forth.
+ *
+ * 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.
+ *
+ *
+ * @param lineWidth
+ * the width of a line
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public void setLineWidth(int lineWidth) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (data.lineWidth == lineWidth) {
+ return;
+ }
+ data.lineWidth = lineWidth;
+ data.internalGc.setStrokeWidth(lineWidth);
+}
+
+/**
+ * If the argument is true
, puts the receiver in a drawing mode
+ * where the resulting color in the destination is the exclusive or of
+ * the color values in the source and the destination, and if the argument is
+ * false
, puts the receiver in a drawing mode where the destination
+ * color is replaced with the source color value.
+ *
+ * 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.
+ *
+ *
+ * @param xor
+ * if true
, then xor mode is used, otherwise
+ * source copy mode is used
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public void setXORMode(boolean xor) {
+ if (handle == 0) {
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ }
+ if (xor) {
+ if (data.xorMode == GCData.XOR_MODE_ON) {
+ return;
+ }
+ data.xorMode = GCData.XOR_MODE_ON;
+ data.internalGc.setBlendingMode(GraphicsContext.BLENDING_MODE_XOR);
+ } else {
+ if (data.xorMode == GCData.XOR_MODE_OFF) {
+ return;
+ }
+ data.xorMode = GCData.XOR_MODE_OFF;
+ data.internalGc.setBlendingMode(GraphicsContext.BLENDING_MODE_SRC_OVER);
+ }
+}
+
+/**
+ * Returns the extent of the given string. No tab expansion or carriage return
+ * processing will be performed.
+ *
+ * The extent 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).
+ *
+ *
+ * @param string
+ * the string to measure
+ * @return a point containing the extent of the string
+ *
+ * @exception IllegalArgumentException
+ *
+ * - ERROR_NULL_ARGUMENT - if the string is null
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public Point stringExtent(String string) {
+ return textExtent(string, 0);
+}
+
+/**
+ * Returns the extent of the given string. Tab expansion and carriage return
+ * processing are performed.
+ *
+ * The extent 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).
+ *
+ *
+ * @param string
+ * the string to measure
+ * @return a point containing the extent of the string
+ *
+ * @exception IllegalArgumentException
+ *
+ * - ERROR_NULL_ARGUMENT - if the string is null
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+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:
+ *
+ * - DRAW_DELIMITER
+ * - draw multiple lines
+ * - DRAW_TAB
+ * - expand tabs
+ * - DRAW_MNEMONIC
+ * - underline the mnemonic character
+ * - DRAW_TRANSPARENT
+ * - transparent background
+ *
+ *
+ * The extent 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).
+ *
+ *
+ * @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
+ *
+ * - ERROR_NULL_ARGUMENT - if the string is null
+ *
+ * @exception SWTException
+ *
+ * - ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
+ *
+ *
+ */
+public Point textExtent(String string, int flags) {
+ if (handle == 0)
+ SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (string == null)
+ SWT.error(SWT.ERROR_NULL_ARGUMENT);
+
+ int[] box = new int[4];
+ int textFlags = 0;
+
+ if ((flags & SWT.DRAW_DELIMITER) == 0) {
+ textFlags |= GraphicsContext.TEXT_SINGLE_LINE;
+ }
+ if ((flags & SWT.DRAW_TAB) != 0) {
+ textFlags |= GraphicsContext.TEXT_EXPAND_TABS;
+ }
+ if ((flags & SWT.DRAW_MNEMONIC) != 0) {
+ textFlags |= GraphicsContext.TEXT_SHOW_MNEMONIC;
+ }
+
+ data.internalGc.getTextBoundingBox(box, string,
+ GraphicsContext.ALIGNMENT_LEFT, textFlags);
+
+ return new Point(box[GraphicsContext.RECT_WIDTH],
+ box[GraphicsContext.RECT_HEIGHT]);
+}
+
+/**
+ * Returns a string containing a concise, human-readable description of the
+ * receiver.
+ *
+ * @return a string representation of the receiver
+ */
+public String toString() {
+ if (isDisposed())
+ return "GC {*DISPOSED*}";
+ return "GC {" + handle + "}";
+}
+}