summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/GC.java
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/GC.java')
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/GC.java3112
1 files changed, 0 insertions, 3112 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/GC.java
deleted file mode 100644
index dae4748e16..0000000000
--- a/bundles/org.eclipse.swt/Eclipse SWT/wpf/org/eclipse/swt/graphics/GC.java
+++ /dev/null
@@ -1,3112 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * IBM Corporation - initial API and implementation
- *******************************************************************************/
-package org.eclipse.swt.graphics;
-
-import org.eclipse.swt.internal.wpf.*;
-import org.eclipse.swt.*;
-
-/**
- * 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>
- */
- public int handle;
-
- Drawable drawable;
- GCData data;
-
- static final int FOREGROUND = 1 << 0;
- static final int BACKGROUND = 1 << 1;
- static final int FONT = 1 << 2;
- static final int LINE_STYLE = 1 << 3;
- static final int LINE_WIDTH = 1 << 4;
- static final int LINE_CAP = 1 << 5;
- static final int LINE_JOIN = 1 << 6;
- static final int LINE_MITERLIMIT = 1 << 7;
- static final int ALPHA = 1 << 8;
- static final int CLIPPING = 1 << 9;
- static final int TRANSFORM = 1 << 10;
-
- static final int DRAW = FOREGROUND | LINE_STYLE | LINE_WIDTH | LINE_CAP | LINE_JOIN | ALPHA | CLIPPING | TRANSFORM;
- static final int FILL = BACKGROUND | ALPHA | CLIPPING | TRANSFORM;
- static final int IMAGE = ALPHA | CLIPPING | TRANSFORM;
-
- static final double[] LINE_DOT_ZERO = new double[]{3, 3};
- static final double[] LINE_DASH_ZERO = new double[]{18, 6};
- static final double[] LINE_DASHDOT_ZERO = new double[]{9, 6, 3, 6};
- static final double[] LINE_DASHDOTDOT_ZERO = new double[]{9, 3, 3, 3, 3, 3};
-
-/**
- * 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);
- int hDC = 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, hDC);
- init();
-}
-
-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 checkGC(int mask) {
- int state = data.state;
- if ((state & mask) == mask) return;
- state = (state ^ mask) & mask;
- data.state |= mask;
- if ((state & (FOREGROUND | LINE_WIDTH | LINE_STYLE | LINE_JOIN | LINE_CAP | LINE_MITERLIMIT)) != 0) {
- int pen = data.pen;
- if (pen != 0) OS.GCHandle_Free(pen);
- pen = data.pen = OS.gcnew_Pen();
- int brush;
- Pattern pattern = data.foregroundPattern;
- if (pattern != null) {
- brush = pattern.handle;
- } else {
- int foreground = data.foreground;
- brush = OS.gcnew_SolidColorBrush(foreground);
- if (brush == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- }
- OS.Pen_Brush(pen, brush);
- if (pattern == null) OS.GCHandle_Free(brush);
- float width = data.lineWidth;
- OS.Pen_Thickness(pen, width == 0 ? 1 : width);
- double[] dashes = null;
- int dashStyle = 0;
- switch (data.lineStyle) {
- case SWT.LINE_SOLID: dashStyle = OS.DashStyles_Solid(); break;
- case SWT.LINE_DOT: if (width == 0) dashes = LINE_DOT_ZERO; else dashStyle = OS.DashStyles_Dot(); break;
- case SWT.LINE_DASH: if (width == 0) dashes = LINE_DASH_ZERO; else dashStyle = OS.DashStyles_Dash(); break;
- case SWT.LINE_DASHDOT: if (width == 0) dashes = LINE_DASHDOT_ZERO; else dashStyle = OS.DashStyles_DashDot(); break;
- case SWT.LINE_DASHDOTDOT: if (width == 0) dashes = LINE_DASHDOTDOT_ZERO; else dashStyle = OS.DashStyles_DashDotDot(); break;
- case SWT.LINE_CUSTOM: {
- if (data.lineDashes != null) {
- dashes = new double[data.lineDashes.length * 2];
- for (int i = 0; i < data.lineDashes.length; i++) {
- double dash = (double)data.lineDashes[i] / Math.max (1, width);
- dashes[i] = dash;
- dashes[i + data.lineDashes.length] = dash;
- }
- } else {
- dashStyle = OS.DashStyles_Solid();
- }
- }
- }
- if (dashes != null) {
- int list = OS.gcnew_DoubleCollection(dashes.length);
- for (int i = 0; i < dashes.length; i++) {
- OS.DoubleCollection_Add(list, dashes[i]);
- }
- dashStyle = OS.gcnew_DashStyle(list, data.lineDashesOffset);
- OS.GCHandle_Free(list);
- }
- OS.Pen_DashStyle(pen, dashStyle);
- OS.GCHandle_Free(dashStyle);
- int joinStyle = 0;
- switch (data.lineJoin) {
- case SWT.JOIN_MITER: joinStyle = OS.PenLineJoin_Miter; break;
- case SWT.JOIN_BEVEL: joinStyle = OS.PenLineJoin_Bevel; break;
- case SWT.JOIN_ROUND: joinStyle = OS.PenLineJoin_Round; break;
- }
- OS.Pen_LineJoin(pen, joinStyle);
- int capStyle = OS.PenLineCap_Flat;
- switch (data.lineCap) {
- case SWT.CAP_FLAT: capStyle = OS.PenLineCap_Flat; break;
- case SWT.CAP_ROUND: capStyle = OS.PenLineCap_Round; break;
- case SWT.CAP_SQUARE: capStyle = OS.PenLineCap_Square; break;
- }
- OS.Pen_DashCap(pen, capStyle);
- OS.Pen_EndLineCap(pen, capStyle);
- OS.Pen_StartLineCap(pen, capStyle);
- OS.Pen_MiterLimit(pen, data.lineMiterLimit);
- }
- if ((state & BACKGROUND) != 0) {
- if (data.brush != 0) OS.GCHandle_Free(data.brush);
- data.brush = 0;
- Pattern pattern = data.backgroundPattern;
- if (pattern != null) {
- data.currentBrush = pattern.handle;
- } else {
- int background = data.background;
- int brush = OS.gcnew_SolidColorBrush(background);
- if (brush == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- data.currentBrush = data.brush = brush;
- }
- }
- if ((state & (ALPHA | CLIPPING | TRANSFORM)) != 0) {
- for (int i = 0; i < data.pushCount; i++) OS.DrawingContext_Pop(handle);
- data.pushCount = 0;
- if (data.alpha != 0xFF) {
- OS.DrawingContext_PushOpacity(handle, (data.alpha & 0xFF) / (double)0xFF);
- data.pushCount++;
- }
- if (data.clip != 0) {
- OS.DrawingContext_PushClip(handle, data.clip);
- data.pushCount++;
- }
- if (data.transform != 0) {
- OS.DrawingContext_PushTransform(handle, data.transform);
- data.pushCount++;
- }
- }
-
-}
-
-/**
- * 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) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-
- //TODO - implement copyArea
-}
-
-/**
- * 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) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-
- //TODO - implement copyArea
-
-// /*
-// * Feature in WinCE. The function WindowFromDC is not part of the
-// * WinCE SDK. The fix is to remember the HWND.
-// */
-// int hwnd = data.hwnd;
-// if (hwnd == 0) {
-// OS.BitBlt(handle, destX, destY, width, height, handle, srcX, srcY, OS.SRCCOPY);
-// } else {
-// RECT lprcClip = null;
-// int 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.
-// */
-// if (res == 0 && OS.IsWinCE) {
-// OS.BitBlt(handle, destX, destY, width, height, handle, srcX, srcY, OS.SRCCOPY);
-// if (paint) {
-// int deltaX = destX - srcX, deltaY = destY - srcY;
-// boolean disjoint = (destX + width < srcX) || (srcX + width < destX) || (destY + height < srcY) || (srcY + height < destY);
-// if (disjoint) {
-// OS.InvalidateRect(hwnd, lprcScroll, true);
-// } else {
-// if (deltaX != 0) {
-// int newX = destX - deltaX;
-// if (deltaX < 0) newX = destX + width;
-// OS.SetRect(lprcScroll, newX, srcY, newX + Math.abs(deltaX), srcY + height);
-// OS.InvalidateRect(hwnd, lprcScroll, true);
-// }
-// if (deltaY != 0) {
-// int newY = destY - deltaY;
-// if (deltaY < 0) newY = destY + height;
-// OS.SetRect(lprcScroll, srcX, newY, srcX + width, newY + Math.abs(deltaY));
-// OS.InvalidateRect(hwnd, lprcScroll, true);
-// }
-// }
-// }
-// }
-// }
-}
-
-void destroy() {
- int brush = data.brush;
- if (brush != 0) OS.GCHandle_Free(brush);
- data.brush = 0;
- int pen = data.pen;
- if (pen != 0) OS.GCHandle_Free(pen);
- data.pen = 0;
- int clip = data.clip;
- if (clip != 0) OS.GCHandle_Free(clip);
- data.clip = 0;
- int transform = data.transform;
- if (transform != 0) OS.GCHandle_Free(transform);
- data.transform = 0;
-
- Image image = data.image;
- if (image != null) image.memGC = null;
-
- if (drawable != null) drawable.internal_dispose_GC(handle, data);
- drawable = null;
- handle = 0;
- data.image = null;
- data = 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- double offset = 0;
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) offset = 0.5;
- if (arcAngle >= 360 || arcAngle <= -360) {
- int center = OS.gcnew_Point(x + offset + width / 2f, y + offset + height / 2f);
- OS.DrawingContext_DrawEllipse(handle, 0, data.pen, center, width / 2f, height / 2f);
- OS.GCHandle_Free(center);
- return;
- }
- boolean isNegative = arcAngle < 0;
- boolean isLargeAngle = arcAngle > 180 || arcAngle < -180;
- arcAngle = arcAngle + startAngle;
- if (isNegative) {
- // swap angles
- int tmp = startAngle;
- startAngle = arcAngle;
- arcAngle = tmp;
- }
- double x1 = Math.cos(startAngle * Math.PI / 180) * width/2.0 + x + offset + width/2.0;
- double y1 = -1 * Math.sin(startAngle * Math.PI / 180) * height/2.0 + y + offset + height/2.0;
- double x2 = Math.cos(arcAngle * Math.PI / 180) * width/2.0 + x + offset + width/2.0;
- double y2 = -1 * Math.sin(arcAngle * Math.PI / 180) * height/2.0 + y + offset + height/2.0;
- int startPoint = OS.gcnew_Point(x1, y1);
- int endPoint = OS.gcnew_Point(x2, y2);
- int size = OS.gcnew_Size(width / 2.0, height / 2.0);
- int arc = OS.gcnew_ArcSegment(endPoint, size, 0, isLargeAngle, OS.SweepDirection_Clockwise, true);
- int figure = OS.gcnew_PathFigure();
- OS.PathFigure_StartPoint(figure, startPoint);
- int segments = OS.PathFigure_Segments(figure);
- OS.PathSegmentCollection_Add(segments, arc);
- int path = OS.gcnew_PathGeometry();
- int figures = OS.PathGeometry_Figures(path);
- OS.PathFigureCollection_Add(figures, figure);
- OS.DrawingContext_DrawGeometry(handle, 0, data.pen, path);
- OS.GCHandle_Free(figures);
- OS.GCHandle_Free(path);
- OS.GCHandle_Free(segments);
- OS.GCHandle_Free(figure);
- OS.GCHandle_Free(arc);
- OS.GCHandle_Free(size);
- OS.GCHandle_Free(endPoint);
- OS.GCHandle_Free(startPoint);
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- //TODO - implement drawFocus
-}
-
-/**
- * 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 (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);
- drawImage(image, 0, 0, -1, -1, x, y, -1, -1, true);
-}
-
-/**
- * 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 (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);
- drawImage(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false);
-}
-
-void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
- checkGC(IMAGE);
- int imageHandle = image.handle;
- int imgWidth = OS.BitmapSource_PixelWidth(imageHandle);
- int imgHeight = OS.BitmapSource_PixelHeight(imageHandle);
- if (simple) {
- srcWidth = destWidth = imgWidth;
- srcHeight = destHeight = imgHeight;
- } else {
- simple = srcX == 0 && srcY == 0 &&
- srcWidth == destWidth && destWidth == imgWidth &&
- srcHeight == destHeight && destHeight == imgHeight;
- if (srcX + srcWidth > imgWidth || srcY + srcHeight > imgHeight) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- int mode = 0;
- switch (data.interpolation) {
- case SWT.DEFAULT: mode = OS.BitmapScalingMode_Unspecified; break;
- case SWT.NONE: mode = OS.BitmapScalingMode_LowQuality; break;
- case SWT.LOW: mode = OS.BitmapScalingMode_LowQuality; break;
- case SWT.HIGH: mode = OS.BitmapScalingMode_HighQuality; break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (srcX != 0 || srcY != 0 || srcWidth != imgWidth || srcHeight != imgHeight) {
- int rect = OS.gcnew_Int32Rect(srcX, srcY, srcWidth, srcHeight);
- imageHandle = OS.gcnew_CroppedBitmap(imageHandle, rect);
- OS.RenderOptions_SetBitmapScalingMode(imageHandle, mode);
- OS.GCHandle_Free(rect);
- } else {
- if (mode != OS.RenderOptions_GetBitmapScalingMode(imageHandle)) {
- imageHandle = OS.Freezable_Clone(imageHandle);
- OS.RenderOptions_SetBitmapScalingMode(imageHandle, mode);
- }
- }
- int rect = OS.gcnew_Rect(destX, destY, destWidth, destHeight);
- OS.DrawingContext_DrawImage(handle, imageHandle, rect);
- OS.GCHandle_Free(rect);
- if (image.handle != imageHandle) OS.GCHandle_Free(imageHandle);
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- double offset = 0;
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) offset = 0.5;
- int point0 = OS.gcnew_Point(x1 + offset, y1 + offset);
- int point1 = OS.gcnew_Point(x2 + offset, y2 + offset);
- OS.DrawingContext_DrawLine(handle, data.pen, point0, point1);
- OS.GCHandle_Free(point0);
- OS.GCHandle_Free(point1);
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- double offset = 0;
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) offset = 0.5;
- int center = OS.gcnew_Point(x + offset + width / 2f, y + offset + height / 2f);
- OS.DrawingContext_DrawEllipse(handle, 0, data.pen, center, width / 2f, height / 2f);
- OS.GCHandle_Free(center);
-}
-
-/**
- * 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) {
- if (handle == 0) 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 - check offset to draw in the midle of pixel
- OS.PathGeometry_FillRule(path.handle, data.fillRule == SWT.FILL_EVEN_ODD ? OS.FillRule_EvenOdd : OS.FillRule_Nonzero);
- OS.DrawingContext_DrawGeometry(handle, 0, data.pen, path.handle);
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- int rect = OS.gcnew_Rect(x, y, 1, 1);
- int brush = OS.Pen_Brush(data.pen);
- OS.DrawingContext_DrawRectangle(handle, brush, 0, rect);
- OS.GCHandle_Free(brush);
- OS.GCHandle_Free(rect);
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(DRAW);
- drawPolyLineSegment(pointArray, true, true);
-}
-
-void drawPolyLineSegment(int[] pointArray, boolean closed, boolean stroked) {
- if (pointArray.length < 4) return;
- int list = OS.gcnew_PointCollection(pointArray.length / 2);
- double offset = 0;
- if (stroked && (data.lineWidth == 0 || (data.lineWidth % 2) == 1)) offset = 0.5;
- for (int i = 2; i < pointArray.length; i += 2) {
- int point = OS.gcnew_Point(pointArray[i] + offset, pointArray[i + 1] + offset);
- OS.PointCollection_Add(list, point);
- OS.GCHandle_Free(point);
- }
- int poly = OS.gcnew_PolyLineSegment(list, stroked);
- OS.GCHandle_Free(list);
- int figure = OS.gcnew_PathFigure();
- int startPoint = OS.gcnew_Point(pointArray[0] + offset, pointArray[1] + offset);
- OS.PathFigure_StartPoint(figure, startPoint);
- OS.PathFigure_IsClosed(figure, closed);
- int segments = OS.PathFigure_Segments(figure);
- OS.PathSegmentCollection_Add(segments, poly);
- int path = OS.gcnew_PathGeometry();
-// int mode = 0;
-// switch (data.antialias) {
-// case SWT.DEFAULT:
-// case SWT.ON: mode = OS.EdgeMode_Unspecified; break;
-// case SWT.OFF: mode = OS.EdgeMode_Aliased; break;
-// }
-// OS.RenderOptions_SetEdgeMode(path, mode);
- if (!stroked) OS.PathGeometry_FillRule(path, data.fillRule == SWT.FILL_EVEN_ODD ? OS.FillRule_EvenOdd : OS.FillRule_Nonzero);
- int figures = OS.PathGeometry_Figures(path);
- OS.PathFigureCollection_Add(figures, figure);
- OS.DrawingContext_DrawGeometry(handle, stroked ? 0 : data.currentBrush, stroked ? data.pen : 0, path);
- OS.GCHandle_Free(figures);
- OS.GCHandle_Free(path);
- OS.GCHandle_Free(segments);
- OS.GCHandle_Free(figure);
- OS.GCHandle_Free(startPoint);
- OS.GCHandle_Free(poly);
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(DRAW);
- drawPolyLineSegment(pointArray, false, true);
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(DRAW);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- double offset = 0;
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) offset = 0.5;
- int rect = OS.gcnew_Rect(x + offset, y + offset, width, height);
- OS.DrawingContext_DrawRectangle(handle, 0, data.pen, rect);
- OS.GCHandle_Free(rect);
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (arcWidth < 0 || arcHeight < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- checkGC(DRAW);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (arcWidth < 0) arcWidth = -arcWidth;
- if (arcHeight < 0) arcHeight = -arcHeight;
- double offset = 0;
- if (data.lineWidth == 0 || (data.lineWidth % 2) == 1) offset = 0.5;
- int rect = OS.gcnew_Rect(x + offset, y + offset, width, height);
- OS.DrawingContext_DrawRoundedRectangle(handle, 0, data.pen, rect, arcWidth / 2f, arcHeight / 2f);
- OS.GCHandle_Free(rect);
-}
-
-/**
- * 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) {
- drawText(string, x, y, isTransparent ? SWT.DRAW_TRANSPARENT : 0);
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int length = string.length ();
- if (length == 0) return;
- checkGC(FONT | FOREGROUND | ALPHA | CLIPPING | TRANSFORM | ((flags & SWT.DRAW_TRANSPARENT) != 0 ? 0 : BACKGROUND));
- char [] buffer = new char [length + 1];
- string.getChars(0, length, buffer, 0);
- int mask = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC;
- int mnemonic = -1;
- if ((flags & mask) != mask) {
- for (int i = 0, j = 0; i < buffer.length; i++) {
- char c = buffer[i];
- switch (c) {
- case '&': {
- if ((flags & SWT.DRAW_MNEMONIC) != 0) {
- if (i + 1 < length) {
- if (buffer[i + 1] == '&') {
- i++;
- } else {
- if (mnemonic == -1) mnemonic = j;
- }
- }
- continue;
- }
- break;
- }
- case '\r':
- case '\n':
- if ((flags & SWT.DRAW_DELIMITER) == 0) continue;
- break;
- case '\t':
- if ((flags & SWT.DRAW_TAB) == 0) continue;
- break;
- }
- buffer[j++] = c;
- }
- }
- int str = OS.gcnew_String (buffer);
- int culture = OS.CultureInfo_CurrentUICulture();
- Font font = data.font;
- int direction = (data.style & SWT.RIGHT_TO_LEFT) != 0 ? OS.FlowDirection_RightToLeft : OS.FlowDirection_LeftToRight;
- int brush = OS.Pen_Brush(data.pen);
- int text = OS.gcnew_FormattedText(str, culture, direction, font.handle, font.size, brush);
- int point = OS.gcnew_Point(x, y);
- if (mnemonic != -1) {
- int underline = OS.TextDecorations_Underline();
- OS.FormattedText_SetTextDecorations(text, underline, mnemonic, 1);
- OS.GCHandle_Free(underline);
- }
- if ((flags & SWT.DRAW_TRANSPARENT) == 0) {
- double width = OS.FormattedText_WidthIncludingTrailingWhitespace(text);
- double height = OS.FormattedText_Height(text);
- int rect = OS.gcnew_Rect(x, y, width, height);
- OS.DrawingContext_DrawRectangle(handle, data.currentBrush, 0, rect);
- OS.GCHandle_Free(rect);
-
- }
- OS.DrawingContext_DrawText(handle, text, point);
- OS.GCHandle_Free(point);
- OS.GCHandle_Free(culture);
- OS.GCHandle_Free(str);
- OS.GCHandle_Free(brush);
- OS.GCHandle_Free(text);
-}
-
-/**
- * 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
- */
-public boolean equals (Object object) {
- return (object == this) || ((object instanceof GC) && (handle == ((GC)object).handle));
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || arcAngle == 0) return;
- if (arcAngle >= 360 || arcAngle <= -360) {
- int center = OS.gcnew_Point(x + width / 2f, y + height / 2f);
- OS.DrawingContext_DrawEllipse(handle, data.currentBrush, 0, center, width / 2f, height / 2f);
- OS.GCHandle_Free(center);
- return;
- }
- boolean isNegative = arcAngle < 0;
- boolean isLargeAngle = arcAngle > 180 || arcAngle < -180;
- arcAngle = arcAngle + startAngle;
- if (isNegative) {
- // swap angles
- int tmp = startAngle;
- startAngle = arcAngle;
- arcAngle = tmp;
- }
- double x1 = Math.cos(startAngle * Math.PI / 180) * width/2.0 + x + width/2.0;
- double y1 = -1 * Math.sin(startAngle * Math.PI / 180) * height/2.0 + y + height/2.0;
- double x2 = Math.cos(arcAngle * Math.PI / 180) * width/2.0 + x + width/2.0;
- double y2 = -1 * Math.sin(arcAngle * Math.PI / 180) * height/2.0 + y + height/2.0;
- int startPoint = OS.gcnew_Point(x1, y1);
- int endPoint = OS.gcnew_Point(x2, y2);
- int center = OS.gcnew_Point(x + width / 2.0, y + height / 2.0);
- int size = OS.gcnew_Size(width / 2.0, height / 2.0);
- int arc = OS.gcnew_ArcSegment(endPoint, size, 0, isLargeAngle, OS.SweepDirection_Clockwise, false);
- int line = OS.gcnew_LineSegment(center, false);
- int figure = OS.gcnew_PathFigure();
- OS.PathFigure_StartPoint(figure, startPoint);
- int segments = OS.PathFigure_Segments(figure);
- OS.PathSegmentCollection_Add(segments, arc);
- OS.PathSegmentCollection_Add(segments, line);
- int path = OS.gcnew_PathGeometry();
- int figures = OS.PathGeometry_Figures(path);
- OS.PathFigureCollection_Add(figures, figure);
- OS.DrawingContext_DrawGeometry(handle, data.currentBrush, 0, path);
- OS.GCHandle_Free(figures);
- OS.GCHandle_Free(path);
- OS.GCHandle_Free(segments);
- OS.GCHandle_Free(figure);
- OS.GCHandle_Free(arc);
- OS.GCHandle_Free(line);
- OS.GCHandle_Free(size);
- OS.GCHandle_Free(endPoint);
- OS.GCHandle_Free(startPoint);
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width == 0 || height == 0) return;
- checkGC(FILL);
-
- int fromColor = data.foreground;
- int toColor = data.background;
-
- 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) {
- int temp = fromColor;
- fromColor = toColor;
- toColor = temp;
- }
- int brush = OS.gcnew_LinearGradientBrush(fromColor, toColor, vertical ? 90 : 0);
- int rect = OS.gcnew_Rect(x, y, width, height);
- OS.DrawingContext_DrawRectangle(handle, brush, 0, rect);
- OS.GCHandle_Free(rect);
- OS.GCHandle_Free(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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int center = OS.gcnew_Point(x + width / 2f, y + height / 2f);
- OS.DrawingContext_DrawEllipse(handle, data.currentBrush, 0, center, width / 2f, height / 2f);
- OS.GCHandle_Free(center);
-}
-
-/**
- * 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) {
- if (handle == 0) 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(FILL);
- OS.PathGeometry_FillRule(path.handle, data.fillRule == SWT.FILL_EVEN_ODD ? OS.FillRule_EvenOdd : OS.FillRule_Nonzero);
- OS.DrawingContext_DrawGeometry(handle, data.currentBrush, 0, path.handle);
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- checkGC(FILL);
- drawPolyLineSegment(pointArray, true, false);
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int rect = OS.gcnew_Rect(x, y, width, height);
- OS.DrawingContext_DrawRectangle(handle, data.currentBrush, 0, rect);
- OS.GCHandle_Free(rect);
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FILL);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (arcWidth < 0) arcWidth = -arcWidth;
- if (arcHeight < 0) arcHeight = -arcHeight;
- int rect = OS.gcnew_Rect(x, y, width, height);
- OS.DrawingContext_DrawRoundedRectangle(handle, data.currentBrush, 0, rect, arcWidth / 2f, arcHeight / 2f);
- OS.GCHandle_Free(rect);
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- //NOT DONE
- return stringExtent(new String(new char[]{ch})).x;
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return true;
-}
-
-/**
- * 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 (handle == 0) 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() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.antialias;
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return Color.wpf_new(data.device, data.background);
-}
-
-/**
- * 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 (handle == 0) 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) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- //NOT DONE
- return stringExtent(new String(new char[]{ch})).x;
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int x = 0, y = 0, width = 0, height = 0;
- int visualType = OS.Object_GetType(data.visual);
- int drawingVisualType = OS.DrawingVisual_typeid();
- if (OS.Object_Equals(visualType, drawingVisualType)) {
- int clip = OS.ContainerVisual_Clip(data.visual);
- int rect = OS.Geometry_Bounds(clip);
- width = (int)OS.Rect_Width(rect);
- height = (int)OS.Rect_Height(rect);
- OS.GCHandle_Free(rect);
- OS.GCHandle_Free(clip);
- } else {
- width = (int)OS.FrameworkElement_ActualWidth(data.visual);
- height = (int)OS.FrameworkElement_ActualHeight(data.visual);
- }
- OS.GCHandle_Free(drawingVisualType);
- OS.GCHandle_Free(visualType);
- if (data.clip != 0) {
- int bounds = OS.gcnew_Rect(x, y, width, height);
- int rect = OS.Geometry_Bounds(data.clip);
- OS.Rect_Intersect(bounds, rect);
- x = (int)OS.Rect_X(bounds);
- y = (int)OS.Rect_Y(bounds);
- width = (int)OS.Rect_Width(bounds);
- height = (int)OS.Rect_Height(bounds);
- OS.GCHandle_Free(rect);
- OS.GCHandle_Free(bounds);
- }
- return new Rectangle(x, y, width, 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- int bounds;
- int visualType = OS.Object_GetType(data.visual);
- int drawingVisualType = OS.DrawingVisual_typeid();
- if (OS.Object_Equals(visualType, drawingVisualType)) {
- bounds = OS.ContainerVisual_Clip(data.visual);
- } else {
- double width = OS.FrameworkElement_ActualWidth(data.visual);
- double height = OS.FrameworkElement_ActualHeight(data.visual);
- int rect = OS.gcnew_Rect(0, 0, width, height);
- bounds = OS.gcnew_RectangleGeometry(rect);
- OS.GCHandle_Free(rect);
- }
- OS.GCHandle_Free(drawingVisualType);
- OS.GCHandle_Free(visualType);
- int geometries = OS.GeometryGroup_Children(region.handle);
- OS.GeometryCollection_Clear(geometries);
- if (data.clip != 0) {
- int clip = OS.Geometry_GetFlattenedPathGeometry(data.clip);
- int newGeometry = OS.gcnew_CombinedGeometry(OS.GeometryCombineMode_Intersect, bounds, clip);
- OS.GeometryCollection_Add(geometries, newGeometry);
- OS.GCHandle_Free(clip);
- OS.GCHandle_Free(newGeometry);
- } else {
- OS.GeometryCollection_Add(geometries, bounds);
- }
- OS.GCHandle_Free(bounds);
- OS.GCHandle_Free(geometries);
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.fillRule;
-}
-
-/**
- * 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 (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.
- *
- * @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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- checkGC(FONT);
- //TODO - find a better way of getting font metrics
- String string = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
- int length = string.length();
- char [] buffer = new char [length + 1];
- string.getChars (0, length, buffer, 0);
- int str = OS.gcnew_String (buffer);
- int culture = OS.CultureInfo_CurrentUICulture();
- Font font = data.font;
- int direction = (data.style & SWT.RIGHT_TO_LEFT) != 0 ? OS.FlowDirection_RightToLeft : OS.FlowDirection_LeftToRight;
- int brush = OS.Brushes_White();
- int text = OS.gcnew_FormattedText(str, culture, direction, font.handle, font.size, brush);
- double width = OS.FormattedText_WidthIncludingTrailingWhitespace(text);
- double height = OS.FormattedText_Height(text);
- double baseline = OS.FormattedText_Baseline(text);
- OS.GCHandle_Free(text);
- OS.GCHandle_Free(brush);
- OS.GCHandle_Free(culture);
- OS.GCHandle_Free(str);
- return FontMetrics.wpf_new((int)baseline, (int)(height - baseline), (int)width / string.length(), 0, (int)height);
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return Color.wpf_new(data.device, data.foreground);
-}
-
-/**
- * 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 (handle == 0) 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 (handle == 0) 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.interpolation;
-}
-
-/**
- * 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 (handle == 0) 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 (handle == 0) 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineDashes == null) return null;
- int[] lineDashes = new int[data.lineDashes.length];
- System.arraycopy(data.lineDashes, 0, lineDashes, 0, lineDashes.length);
- 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 (handle == 0) 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 (handle == 0) 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 (handle == 0) 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 (handle == 0) 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() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.textAntialias;
-}
-
-/**
- * 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) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transform == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.transform != 0) {
- OS.MatrixTransform_Matrix(transform.handle, data.transform);
- } 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() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.xorMode;
-}
-
-void init(Drawable drawable, GCData data, int hDC) {
- int foreground = data.foreground;
- if (foreground != -1) data.state &= ~FOREGROUND;
- int background = data.background;
- if (background != 0) data.state &= ~BACKGROUND;
- Font font = data.font;
- if (font != null) data.state &= ~FONT;
- Image image = data.image;
- if (image != null) image.memGC = this;
-// int layout = data.layout;
-// if (layout != -1) {
-// if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION(4, 10)) {
-// int flags = OS.GetLayout(hDC);
-// if ((flags & OS.LAYOUT_RTL) != (layout & OS.LAYOUT_RTL)) {
-// flags &= ~OS.LAYOUT_RTL;
-// OS.SetLayout(hDC, flags | layout);
-// }
-// if ((data.style & SWT.RIGHT_TO_LEFT) != 0) data.style |= SWT.MIRRORED;
-// }
-// }
- this.drawable = drawable;
- this.data = data;
- handle = hDC;
-}
-
-/**
- * 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
- */
-public int hashCode () {
- return handle;
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.clip != 0;
-}
-
-/**
- * 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
- */
-public boolean isDisposed() {
- return handle == 0;
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (!advanced) {
- setAlpha(0xFF);
- setAntialias(SWT.DEFAULT);
- setBackgroundPattern(null);
- setClipping((Rectangle)null);
- setForegroundPattern(null);
- setInterpolation(SWT.DEFAULT);
- setTextAntialias(SWT.DEFAULT);
- setTransform(null);
- }
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (antialias) {
- case SWT.DEFAULT:
- case SWT.OFF:
- case SWT.ON:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.antialias = antialias;
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- data.alpha = alpha & 0xFF;
- data.state &= ~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 <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 (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);
- if (data.backgroundPattern == null && data.background == color.handle) return;
- data.backgroundPattern = null;
- data.background = color.handle;
- data.state &= ~BACKGROUND;
-}
-
-/**
- * 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 (handle == 0) 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int rect = OS.gcnew_Rect(x, y, width, height);
- int clip = OS.gcnew_RectangleGeometry(rect);
- OS.GCHandle_Free(rect);
- if (data.clip != 0) OS.GCHandle_Free(data.clip);
- data.clip = clip;
- data.state &= ~CLIPPING;
-}
-
-/**
- * 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) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (path != null && path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.clip != 0) OS.GCHandle_Free(data.clip);
- data.clip = path != null ? OS.Geometry_Clone(path.handle) : 0;
- data.state &= ~CLIPPING;
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) {
- if (data.clip != 0) OS.GCHandle_Free(data.clip);
- data.clip = 0;
- data.state &= ~CLIPPING;
- } else {
- setClipping(rect.x, rect.y, rect.width, rect.height);
- }
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region != null && region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (data.clip != 0) OS.GCHandle_Free(data.clip);
- data.clip = region != null ? OS.Geometry_Clone(region.handle) : 0;
- data.state &= ~CLIPPING;
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (rule) {
- case SWT.FILL_WINDING:
- case SWT.FILL_EVEN_ODD: break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.fillRule = rule;
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.font = font != null ? font : data.device.systemFont;
- 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 (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);
- if (data.foregroundPattern == null && color.handle == data.foreground) return;
- data.foregroundPattern = null;
- data.foreground = color.handle;
- data.state &= ~FOREGROUND;
-}
-
-/**
- * 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- 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) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (interpolation) {
- case SWT.DEFAULT: break;
- case SWT.NONE: break;
- case SWT.LOW: break;
- case SWT.HIGH: break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.interpolation = interpolation;
-}
-
-/**
- * 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 (handle == 0) 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;
- }
- 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;
- }
- 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 (handle == 0) 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 (handle == 0) 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 (handle == 0) 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 (handle == 0) 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineWidth == lineWidth) return;
- data.lineWidth = lineWidth;
- data.state &= ~LINE_WIDTH;
- switch (data.lineStyle) {
- case SWT.LINE_DOT:
- case SWT.LINE_DASH:
- case SWT.LINE_DASHDOT:
- case SWT.LINE_DASHDOTDOT:
- data.state &= ~LINE_STYLE;
- }
-}
-
-/**
- * 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
- */
-public void setXORMode(boolean xor) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- data.xorMode = xor;
-}
-
-/**
- * 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) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- switch (antialias) {
- case SWT.DEFAULT:
- case SWT.OFF:
- case SWT.ON:
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.textAntialias = antialias;
-}
-
-/**
- * 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) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transform != null && transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.transform = transform != null ? OS.gcnew_MatrixTransform(transform.handle) : 0;
- data.state &= ~TRANSFORM;
-}
-
-/**
- * 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) {
- return textExtent(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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- checkGC(FONT);
- int length = string.length();
- char [] buffer = new char [length + 1];
- string.getChars (0, length, buffer, 0);
- if ((flags & (SWT.DRAW_DELIMITER | SWT.DRAW_TAB)) != (SWT.DRAW_DELIMITER | SWT.DRAW_TAB)) {
- for (int i = 0, j = 0; i < buffer.length; i++) {
- char c = buffer[i];
- switch (c) {
- case '\r':
- case '\n':
- if ((flags & SWT.DRAW_DELIMITER) == 0) continue;
- break;
- case '\t':
- if ((flags & SWT.DRAW_TAB) == 0) continue;
- break;
- }
- buffer[j++] = c;
- }
- }
- int str = OS.gcnew_String (buffer);
- int culture = OS.CultureInfo_CurrentUICulture();
- Font font = data.font;
- int direction = (data.style & SWT.RIGHT_TO_LEFT) != 0 ? OS.FlowDirection_RightToLeft : OS.FlowDirection_LeftToRight;
- int brush = OS.Brushes_White();
- int text = OS.gcnew_FormattedText(str, culture, direction, font.handle, font.size, brush);
- double width = OS.FormattedText_WidthIncludingTrailingWhitespace(text);
- double height = OS.FormattedText_Height(text);
- OS.GCHandle_Free(text);
- OS.GCHandle_Free(brush);
- OS.GCHandle_Free(culture);
- OS.GCHandle_Free(str);
- return new Point((int)width, (int)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 + "}";
-}
-
-/**
- * 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 wpf_new(Drawable drawable, GCData data) {
- GC gc = new GC();
- int hDC = drawable.internal_new_GC(data);
- gc.device = data.device;
- gc.init(drawable, data, hDC);
- 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 wpf_new(int hDC, GCData data) {
- GC gc = new GC();
- gc.device = data.device;
- gc.init(null, data, hDC);
- return gc;
-}
-
-}