/******************************************************************************* * Copyright (c) 2000, 2006 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ package org.eclipse.swt.graphics; import org.eclipse.swt.internal.*; import org.eclipse.swt.internal.carbon.*; import org.eclipse.swt.*; /** * Class GC is where all of the drawing capabilities that are * supported by SWT are located. Instances are used to draw on either an * Image, a Control, or directly on a Display. *
*
Styles:
*
LEFT_TO_RIGHT, RIGHT_TO_LEFT
*
* *

* 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. *

* *

* Application code must explicitly invoke the GC.dispose() * method to release the operating system resources managed by each instance * when those instances are no longer required. This is particularly * important on Windows95 and Windows98 where the operating system has a limited * number of device contexts available. *

* *

* Note: Only one of LEFT_TO_RIGHT and RIGHT_TO_LEFT may be specified. *

* * @see org.eclipse.swt.events.PaintEvent */ public final class GC extends Resource { /** * the handle to the OS device context * (Warning: This field is platform dependent) *

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

*/ public int handle; Drawable drawable; GCData data; static final int TAB_COUNT = 32; final static int FOREGROUND = 1 << 0; final static int BACKGROUND = 1 << 1; final static int FONT = 1 << 2; final static int LINE_STYLE = 1 << 3; final static int LINE_CAP = 1 << 4; final static int LINE_JOIN = 1 << 5; final static int LINE_WIDTH = 1 << 6; final static int LINE_MITERLIMIT = 1 << 7; final static int FOREGROUND_FILL = 1 << 8; final static int DRAW = FOREGROUND | LINE_WIDTH | LINE_STYLE | LINE_CAP | LINE_JOIN | LINE_MITERLIMIT; final static int FILL = BACKGROUND; static final float[] LINE_DOT = new float[]{1, 1}; static final float[] LINE_DASH = new float[]{3, 1}; static final float[] LINE_DASHDOT = new float[]{3, 1, 1, 1}; static final float[] LINE_DASHDOTDOT = new float[]{3, 1, 1, 1, 1, 1}; static final float[] LINE_DOT_ZERO = new float[]{3, 3}; static final float[] LINE_DASH_ZERO = new float[]{18, 6}; static final float[] LINE_DASHDOT_ZERO = new float[]{9, 6, 3, 6}; static final float[] LINE_DASHDOTDOT_ZERO = new float[]{9, 3, 3, 3, 3, 3}; GC() { } /** * Constructs a new instance of this class which has been * configured to draw on the specified drawable. Sets the * foreground and background color in the GC to match those * in the drawable. *

* You must dispose the graphics context when it is no longer required. *

* @param drawable the drawable to draw on * @exception IllegalArgumentException * @exception SWTError */ public GC(Drawable drawable) { this(drawable, 0); } /** * Constructs a new instance of this class which has been * configured to draw on the specified drawable. Sets the * foreground and background color in the GC to match those * in the drawable. *

* You must dispose the graphics context when it is no longer required. *

* * @param drawable the drawable to draw on * @param style the style of GC to construct * * @exception IllegalArgumentException * @exception SWTError * * @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 gdkGC = 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, gdkGC); } 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); } /** * Invokes platform specific functionality to allocate a new graphics context. *

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

* * @param drawable the Drawable for the receiver. * @param data the data for the receiver. * * @return a new GC * * @private */ public static GC carbon_new(Drawable drawable, GCData data) { GC gc = new GC(); int context = drawable.internal_new_GC(data); gc.device = data.device; gc.init(drawable, data, context); return gc; } /** * Invokes platform specific functionality to wrap a graphics context. *

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

* * @param context the Quartz context. * @param data the data for the receiver. * * @return a new GC */ public static GC carbon_new(int context, GCData data) { GC gc = new GC(); gc.device = data.device; gc.init(null, data, context); return gc; } void checkGC (int mask) { int state = data.state; if ((state & mask) == mask) return; state = (state ^ mask) & mask; data.state |= mask; if ((state & FOREGROUND) != 0) { Pattern pattern = data.foregroundPattern; if (pattern != null) { int colorspace = OS.CGColorSpaceCreatePattern(data.device.colorspace); OS.CGContextSetStrokeColorSpace(handle, colorspace); OS.CGColorSpaceRelease(colorspace); if (data.forePattern == 0) data.forePattern = pattern.createPattern(handle); OS.CGContextSetStrokePattern(handle, data.forePattern, data.foreground); } else { OS.CGContextSetStrokeColorSpace(handle, data.device.colorspace); OS.CGContextSetStrokeColor(handle, data.foreground); } } if ((state & FOREGROUND_FILL) != 0) { Pattern pattern = data.foregroundPattern; if (pattern != null) { int colorspace = OS.CGColorSpaceCreatePattern(data.device.colorspace); OS.CGContextSetFillColorSpace(handle, colorspace); OS.CGColorSpaceRelease(colorspace); if (data.forePattern == 0) data.forePattern = pattern.createPattern(handle); OS.CGContextSetFillPattern(handle, data.forePattern, data.foreground); } else { OS.CGContextSetFillColorSpace(handle, data.device.colorspace); OS.CGContextSetFillColor(handle, data.foreground); } data.state &= ~BACKGROUND; } if ((state & BACKGROUND) != 0) { Pattern pattern = data.backgroundPattern; if (pattern != null) { int colorspace = OS.CGColorSpaceCreatePattern(data.device.colorspace); OS.CGContextSetFillColorSpace(handle, colorspace); OS.CGColorSpaceRelease(colorspace); if (data.backPattern == 0) data.backPattern = pattern.createPattern(handle); OS.CGContextSetFillPattern(handle, data.backPattern, data.background); } else { OS.CGContextSetFillColorSpace(handle, data.device.colorspace); OS.CGContextSetFillColor(handle, data.background); } data.state &= ~FOREGROUND_FILL; } if ((state & FONT) != 0) { setCGFont(); } if ((state & LINE_WIDTH) != 0) { OS.CGContextSetLineWidth(handle, data.lineWidth == 0 ? 1 : data.lineWidth); switch (data.lineStyle) { case SWT.LINE_DOT: case SWT.LINE_DASH: case SWT.LINE_DASHDOT: case SWT.LINE_DASHDOTDOT: state |= LINE_STYLE; } } if ((state & LINE_STYLE) != 0) { float[] dashes = null; float width = data.lineWidth; switch (data.lineStyle) { case SWT.LINE_SOLID: break; case SWT.LINE_DASH: dashes = width != 0 ? LINE_DASH : LINE_DASH_ZERO; break; case SWT.LINE_DOT: dashes = width != 0 ? LINE_DOT : LINE_DOT_ZERO; break; case SWT.LINE_DASHDOT: dashes = width != 0 ? LINE_DASHDOT : LINE_DASHDOT_ZERO; break; case SWT.LINE_DASHDOTDOT: dashes = width != 0 ? LINE_DASHDOTDOT : LINE_DASHDOTDOT_ZERO; break; case SWT.LINE_CUSTOM: dashes = data.lineDashes; break; } if (dashes != null) { float[] lengths = new float[dashes.length]; for (int i = 0; i < lengths.length; i++) { lengths[i] = width == 0 || data.lineStyle == SWT.LINE_CUSTOM ? dashes[i] : dashes[i] * width; } OS.CGContextSetLineDash(handle, data.lineDashesOffset, lengths, lengths.length); } else { OS.CGContextSetLineDash(handle, 0, null, 0); } } if ((state & LINE_MITERLIMIT) != 0) { OS.CGContextSetMiterLimit(handle, data.lineMiterLimit); } if ((state & LINE_JOIN) != 0) { int joinStyle = 0; switch (data.lineJoin) { case SWT.JOIN_MITER: joinStyle = OS.kCGLineJoinMiter; break; case SWT.JOIN_ROUND: joinStyle = OS.kCGLineJoinRound; break; case SWT.JOIN_BEVEL: joinStyle = OS.kCGLineJoinBevel; break; } OS.CGContextSetLineJoin(handle, joinStyle); } if ((state & LINE_CAP) != 0) { int capStyle = 0; switch (data.lineCap) { case SWT.CAP_ROUND: capStyle = OS.kCGLineCapRound; break; case SWT.CAP_FLAT: capStyle = OS.kCGLineCapButt; break; case SWT.CAP_SQUARE: capStyle = OS.kCGLineCapSquare; break; } OS.CGContextSetLineCap(handle, capStyle); } } int convertRgn(int rgn, float[] transform) { int newRgn = OS.NewRgn(); Callback callback = new Callback(this, "convertRgn", 4); int proc = callback.getAddress(); if (proc == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); float[] clippingTranform = data.clippingTransform; data.clippingTransform = transform; OS.QDRegionToRects(rgn, OS.kQDParseRegionFromTopLeft, proc, newRgn); data.clippingTransform = clippingTranform; callback.dispose(); return newRgn; } int convertRgn(int message, int rgn, int r, int newRgn) { if (message == OS.kQDRegionToRectsMsgParse) { Rect rect = new Rect(); OS.memcpy(rect, r, Rect.sizeof); CGPoint point = new CGPoint(); int polyRgn = OS.NewRgn(); OS.OpenRgn(); point.x = rect.left; point.y = rect.top; float[] transform = data.clippingTransform; OS.CGPointApplyAffineTransform(point, transform, point); short startX, startY; OS.MoveTo(startX = (short)point.x, startY = (short)point.y); point.x = rect.right; point.y = rect.top; OS.CGPointApplyAffineTransform(point, transform, point); OS.LineTo((short)Math.round(point.x), (short)point.y); point.x = rect.right; point.y = rect.bottom; OS.CGPointApplyAffineTransform(point, transform, point); OS.LineTo((short)Math.round(point.x), (short)Math.round(point.y)); point.x = rect.left; point.y = rect.bottom; OS.CGPointApplyAffineTransform(point, transform, point); OS.LineTo((short)point.x, (short)Math.round(point.y)); OS.LineTo(startX, startY); OS.CloseRgn(polyRgn); OS.UnionRgn(newRgn, polyRgn, newRgn); OS.DisposeRgn(polyRgn); } return 0; } /** * Copies a rectangular area of the receiver at the specified * position into the image, which must be of type SWT.BITMAP. * * @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 * @exception SWTException */ 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); if (data.image != null) { copyArea(image, x, y, data.image.handle); } else if (data.control != 0) { int imageHandle = image.handle; int width = OS.CGImageGetWidth(imageHandle); int height = OS.CGImageGetHeight(imageHandle); int window = OS.GetControlOwner(data.control); Rect srcRect = new Rect (); CGPoint pt = new CGPoint (); int[] contentView = new int[1]; OS.HIViewFindByID(OS.HIViewGetRoot(window), OS.kHIViewWindowContentID(), contentView); OS.HIViewConvertPoint (pt, data.control, contentView[0]); x += (int) pt.x; y += (int) pt.y; Rect inset = data.insetRect; x -= inset.left; y -= inset.top; srcRect.left = (short)x; srcRect.top = (short)y; srcRect.right = (short)(x + width); srcRect.bottom = (short)(y + height); Rect destRect = new Rect(); destRect.right = (short)width; destRect.bottom = (short)height; int bpl = width * 4; int[] gWorld = new int[1]; int port = OS.GetWindowPort(window); OS.NewGWorldFromPtr(gWorld, OS.k32ARGBPixelFormat, destRect, 0, 0, 0, image.data, bpl); OS.CopyBits(OS.GetPortBitMapForCopyBits(port), OS.GetPortBitMapForCopyBits(gWorld[0]), srcRect, destRect, (short)OS.srcCopy, 0); OS.DisposeGWorld(gWorld [0]); } else if (data.window != 0) { int imageHandle = image.handle; CGRect rect = new CGRect(); rect.x = x; rect.y = y; rect.width = OS.CGImageGetWidth(imageHandle); rect.height = OS.CGImageGetHeight(imageHandle); int[] displays = new int[16]; int[] count = new int[1]; if (OS.CGGetDisplaysWithRect(rect, displays.length, displays, count) != 0) return; for (int i = 0; i < count[0]; i++) { int display = displays[i]; int address = OS.CGDisplayBaseAddress(display); if (address != 0) { int width = OS.CGDisplayPixelsWide(display); int height = OS.CGDisplayPixelsHigh(display); int bpr = OS.CGDisplayBytesPerRow(display); int bpp = OS.CGDisplayBitsPerPixel(display); int bps = OS.CGDisplayBitsPerSample(display); int bitmapInfo = OS.kCGImageAlphaNoneSkipFirst; switch (bpp) { case 16: bitmapInfo |= OS.kCGBitmapByteOrder16Host; break; case 32: bitmapInfo |= OS.kCGBitmapByteOrder32Host; break; } int srcImage = 0; if (OS.__BIG_ENDIAN__() && OS.VERSION >= 0x1040) { int context = OS.CGBitmapContextCreate(address, width, height, bps, bpr, data.device.colorspace, bitmapInfo); srcImage = OS.CGBitmapContextCreateImage(context); OS.CGContextRelease(context); } else { int provider = OS.CGDataProviderCreateWithData(0, address, bpr * height, 0); srcImage = OS.CGImageCreate(width, height, bps, bpp, bpr, data.device.colorspace, bitmapInfo, provider, null, true, 0); OS.CGDataProviderRelease(provider); } copyArea(image, x, y, srcImage); if (srcImage != 0) OS.CGImageRelease(srcImage); } } } } void copyArea (Image image, int x, int y, int srcImage) { if (srcImage == 0) return; int imageHandle = image.handle; int bpc = OS.CGImageGetBitsPerComponent(imageHandle); int width = OS.CGImageGetWidth(imageHandle); int height = OS.CGImageGetHeight(imageHandle); int bpr = OS.CGImageGetBytesPerRow(imageHandle); int alphaInfo = OS.CGImageGetAlphaInfo(imageHandle); int context = OS.CGBitmapContextCreate(image.data, width, height, bpc, bpr, data.device.colorspace, alphaInfo); if (context != 0) { CGRect rect = new CGRect(); rect.x = -x; rect.y = y; rect.width = OS.CGImageGetWidth(srcImage); rect.height = OS.CGImageGetHeight(srcImage); OS.CGContextTranslateCTM(context, 0, -(rect.height - height)); OS.CGContextDrawImage(context, rect, srcImage); OS.CGContextRelease(context); } } /** * 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 */ 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 true paint events will be generated for old and obscured areas * * @exception SWTException * * @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); if (data.updateClip) setCGClipping(); if (width <= 0 || height <= 0) return; int deltaX = destX - srcX, deltaY = destY - srcY; if (deltaX == 0 && deltaY == 0) return; if (data.image != null) { OS.CGContextSaveGState(handle); OS.CGContextScaleCTM(handle, 1, -1); OS.CGContextTranslateCTM(handle, 0, -(height + 2 * destY)); CGRect rect = new CGRect(); rect.x = destX; rect.y = destY; rect.width = width; rect.height = height; int h = OS.CGImageGetHeight(data.image.handle); int bpr = OS.CGImageGetBytesPerRow(data.image.handle); int provider = OS.CGDataProviderCreateWithData(0, data.image.data, bpr * h, 0); if (provider != 0) { int colorspace = device.colorspace; int img = OS.CGImageCreate(width, height, 8, 32, bpr, colorspace, OS.kCGImageAlphaNoneSkipFirst, provider, null, true, 0); OS.CGDataProviderRelease(provider); OS.CGContextDrawImage(handle, rect, img); OS.CGImageRelease(img); } OS.CGContextRestoreGState(handle); return; } if (data.control != 0) { int port = data.port; int window = OS.GetControlOwner(data.control); if (port == 0) port = OS.GetWindowPort(window); /* Calculate src and dest rectangles/regions */ Rect rect = new Rect(); OS.GetControlBounds(data.control, rect); int convertX = 0, convertY = 0; CGPoint pt = new CGPoint (); int[] contentView = new int[1]; OS.HIViewFindByID(OS.HIViewGetRoot(window), OS.kHIViewWindowContentID(), contentView); OS.HIViewConvertPoint(pt, OS.HIViewGetSuperview(data.control), contentView[0]); convertX = rect.left + (int) pt.x; convertY = rect.top + (int) pt.y; rect.left += (int) pt.x; rect.top += (int) pt.y; rect.right += (int) pt.x; rect.bottom += (int) pt.y; Rect srcRect = new Rect(); int left = rect.left + srcX; int top = rect.top + srcY; OS.SetRect(srcRect, (short)left, (short)top, (short)(left + width), (short)(top + height)); int srcRgn = OS.NewRgn(); OS.RectRgn(srcRgn, srcRect); OS.SectRect(rect, srcRect, srcRect); Rect destRect = new Rect (); OS.SetRect(destRect, srcRect.left, srcRect.top, srcRect.right, srcRect.bottom); OS.OffsetRect(destRect, (short)deltaX, (short)deltaY); int destRgn = OS.NewRgn(); OS.RectRgn(destRgn, destRect); /* Copy bits with appropriated clipping region */ if (!OS.EmptyRect(srcRect)) { if (data.visibleRgn == 0 || OS.RectInRgn(srcRect, data.visibleRgn)) { int clipRgn = data.visibleRgn; if (data.clipRgn != 0) { clipRgn = OS.NewRgn(); OS.SectRgn(data.clipRgn, data.visibleRgn, clipRgn); } /* * Feature in the Macintosh. ScrollRect() only copies bits * that are inside the specified rectangle. This means that * it is not possible to copy non overlaping bits without * copying the bits in between the source and destination * rectangles. The fix is to check if the source and * destination rectangles are disjoint and use CopyBits() * instead. */ if (!OS.EmptyRgn(clipRgn)) { boolean disjoint = (destX + width < srcX) || (srcX + width < destX) || (destY + height < srcY) || (srcY + height < destY); if (!disjoint && (deltaX == 0 || deltaY == 0)) { int[] currentPort = new int[1]; OS.GetPort(currentPort); OS.SetPort(port); int oldClip = OS.NewRgn(); OS.GetClip(oldClip); OS.SetClip(clipRgn); OS.UnionRect(srcRect, destRect, rect); OS.ScrollRect(rect, (short)deltaX, (short)deltaY, 0); OS.SetClip(oldClip); OS.DisposeRgn(oldClip); OS.SetPort(currentPort[0]); } else { int portBitMap = OS.GetPortBitMapForCopyBits (port); OS.CopyBits(portBitMap, portBitMap, srcRect, destRect, (short)OS.srcCopy, clipRgn); OS.QDFlushPortBuffer(port, destRgn); } } if (clipRgn != data.visibleRgn) OS.DisposeRgn(clipRgn); } } /* Invalidate src and obscured areas */ if (paint) { int invalRgn = OS.NewRgn(); OS.DiffRgn(srcRgn, data.visibleRgn, invalRgn); OS.OffsetRgn(invalRgn, (short)deltaX, (short)deltaY); OS.DiffRgn(srcRgn, destRgn, srcRgn); OS.UnionRgn(srcRgn, invalRgn, invalRgn); OS.SectRgn(data.visibleRgn, invalRgn, invalRgn); OS.OffsetRgn(invalRgn, (short)-convertX, (short)-convertY); OS.HIViewSetNeedsDisplayInRegion(data.control, invalRgn, true); OS.DisposeRgn(invalRgn); } /* Dispose src and dest regions */ OS.DisposeRgn(destRgn); OS.DisposeRgn(srcRgn); } } void createLayout () { int[] buffer = new int[1]; OS.ATSUCreateTextLayout(buffer); if (buffer[0] == 0) SWT.error(SWT.ERROR_NO_HANDLES); data.layout = buffer[0]; int ptr1 = OS.NewPtr(4); buffer[0] = handle; OS.memcpy(ptr1, buffer, 4); int ptr2 = OS.NewPtr(4); buffer[0] = OS.kATSLineUseDeviceMetrics; OS.memcpy(ptr2, buffer, 4); int lineDir = OS.kATSULeftToRightBaseDirection; if ((data.style & SWT.RIGHT_TO_LEFT) != 0) lineDir = OS.kATSURightToLeftBaseDirection; int ptr3 = OS.NewPtr(1); OS.memcpy(ptr3, new byte[] {(byte)lineDir}, 1); int[] tags = new int[]{OS.kATSUCGContextTag, OS.kATSULineLayoutOptionsTag, OS.kATSULineDirectionTag}; int[] sizes = new int[]{4, 4, 1}; int[] values = new int[]{ptr1, ptr2, ptr3}; OS.ATSUSetLayoutControls(data.layout, tags.length, tags, sizes, values); OS.DisposePtr(ptr1); OS.DisposePtr(ptr2); OS.DisposePtr(ptr3); } void createTabs () { ATSUTab tabs = new ATSUTab(); int tabWidth = getCharWidth(' ') * 8; int ptr = OS.NewPtr(ATSUTab.sizeof * TAB_COUNT); for (int i=0, offset=ptr; i * The resulting arc begins at startAngle and extends * for arcAngle degrees, using the current color. * Angles are interpreted such that 0 degrees is at the 3 o'clock * position. A positive value indicates a counter-clockwise rotation * while a negative value indicates a clockwise rotation. *

* The center of the arc is the center of the rectangle whose origin * is (x, y) and whose size is specified by the * width and height arguments. *

* The resulting arc covers an area width + 1 pixels wide * by height + 1 pixels tall. *

* * @param x the x coordinate of the upper-left corner of the arc to be 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 */ 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 (data.updateClip) setCGClipping(); if (width < 0) { x = x + width; width = -width; } if (height < 0) { y = y + height; height = -height; } if (width == 0 || height == 0 || arcAngle == 0) return; OS.CGContextBeginPath(handle); OS.CGContextSaveGState(handle); float offset = data.lineWidth == 0 || (data.lineWidth % 2) == 1 ? 0.5f : 0f; OS.CGContextTranslateCTM(handle, x + offset + width / 2f, y + offset + height / 2f); OS.CGContextScaleCTM(handle, width / 2f, height / 2f); if (arcAngle < 0) { OS.CGContextAddArc(handle, 0, 0, 1, -(startAngle + arcAngle) * (float)Compatibility.PI / 180, -startAngle * (float)Compatibility.PI / 180, true); } else { OS.CGContextAddArc(handle, 0, 0, 1, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180, true); } OS.CGContextRestoreGState(handle); OS.CGContextStrokePath(handle); flush(); } /** * Draws a rectangle, based on the specified arguments, which has * the appearance of the platform's focus rectangle 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 * * @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); if (data.updateClip) setCGClipping(); int[] metric = new int[1]; OS.GetThemeMetric(OS.kThemeMetricFocusRectOutset, metric); CGRect rect = new CGRect (); rect.x = x + metric[0]; rect.y = y + metric[0]; rect.width = width - metric[0] * 2; rect.height = height - metric[0] * 2; OS.HIThemeDrawFocusRect(rect, true, handle, OS.kHIThemeOrientationNormal); flush(); } /** * 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 * @exception SWTException */ 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); if (data.updateClip) setCGClipping(); float offset = data.lineWidth == 0 || (data.lineWidth % 2) == 1 ? 0.5f : 0f; float[] points = new float[pointArray.length]; for (int i=0; ix and x + width. * The top and bottom edges are at y and y + height. * * @param x the x coordinate of the rectangle to be drawn * @param y the y coordinate of the rectangle to be drawn * @param width the width of the rectangle to be drawn * @param height the height of the rectangle to be drawn * * @exception SWTException */ public void drawRectangle(int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(DRAW); if (data.updateClip) setCGClipping(); if (width < 0) { x = x + width; width = -width; } if (height < 0) { y = y + height; height = -height; } CGRect rect = new CGRect(); float offset = data.lineWidth == 0 || (data.lineWidth % 2) == 1 ? 0.5f : 0f; rect.x = x + offset; rect.y = y + offset; rect.width = width; rect.height = height; OS.CGContextStrokeRect(handle, rect); flush(); } /** * Draws the outline of the specified rectangle, using the receiver's * foreground color. The left and right edges of the rectangle are at * rect.x and rect.x + rect.width. The top * and bottom edges are at rect.y and * rect.y + rect.height. * * @param rect the rectangle to draw * * @exception IllegalArgumentException * @exception SWTException */ public void drawRectangle(Rectangle rect) { if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); drawRectangle (rect.x, rect.y, rect.width, rect.height); } /** * Draws the outline of the round-cornered rectangle specified by * the arguments, using the receiver's foreground color. The left and * right edges of the rectangle are at x and x + width. * The top and bottom edges are at y and y + height. * The roundness of the corners is specified by the * arcWidth and arcHeight arguments, which * are respectively the width and height of the ellipse used to draw * the corners. * * @param x the x coordinate of the rectangle to be drawn * @param y the y coordinate of the rectangle to be drawn * @param width the width of the rectangle to be drawn * @param height the height of the rectangle to be drawn * @param arcWidth the width of the arc * @param arcHeight the height of the arc * * @exception SWTException */ public void drawRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(DRAW); if (data.updateClip) setCGClipping(); if (arcWidth == 0 || arcHeight == 0) { drawRectangle(x, y, width, height); return; } int nx = x; int ny = y; int nw = width; int nh = height; int naw = arcWidth; int nah = arcHeight; if (nw < 0) { nw = 0 - nw; nx = nx - nw; } if (nh < 0) { nh = 0 - nh; ny = ny - nh; } if (naw < 0) naw = 0 - naw; if (nah < 0) nah = 0 - nah; if (naw > nw) naw = nw; if (nah > nh) nah = nh; float naw2 = naw / 2f; float nah2 = nah / 2f; float fw = nw / naw2; float fh = nh / nah2; OS.CGContextBeginPath(handle); OS.CGContextSaveGState(handle); float offset = data.lineWidth == 0 || (data.lineWidth % 2) == 1 ? 0.5f : 0f; OS.CGContextTranslateCTM(handle, nx + offset, ny + offset); OS.CGContextScaleCTM(handle, naw2, nah2); OS.CGContextMoveToPoint(handle, fw - 1, 0); OS.CGContextAddArcToPoint(handle, 0, 0, 0, 1, 1); OS.CGContextAddArcToPoint(handle, 0, fh, 1, fh, 1); OS.CGContextAddArcToPoint(handle, fw, fh, fw, fh - 1, 1); OS.CGContextAddArcToPoint(handle, fw, 0, fw - 1, 0, 1); OS.CGContextClosePath(handle); OS.CGContextRestoreGState(handle); OS.CGContextStrokePath(handle); flush(); } /** * 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 * @exception SWTException */ public void drawString (String string, int x, int y) { drawString(string, x, y, false); } /** * Draws the given string, using the receiver's current font and * foreground color. No tab expansion or carriage return processing * will be performed. If isTransparent is true, * then the background of the rectangular area where the string is being * drawn will not be modified, otherwise it will be filled with the * receiver's background color. * * @param string the string to be drawn * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn * @param isTransparent if true the background will be transparent, otherwise it will be opaque * * @exception IllegalArgumentException * @exception SWTException */ 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 * @exception SWTException */ 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 isTransparent is true, * 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 true the background will be transparent, otherwise it will be opaque * * @exception IllegalArgumentException * @exception SWTException */ 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 * flags includes DRAW_TRANSPARENT, * then the background of the rectangular area where the text is being * drawn will not be modified, otherwise it will be filled with the * receiver's background color. *

* The parameter flags may be a combination of: *

*
DRAW_DELIMITER
*
draw multiple lines
*
DRAW_TAB
*
expand tabs
*
DRAW_MNEMONIC
*
underline the mnemonic character
*
DRAW_TRANSPARENT
*
transparent background
*
*

* * @param string the string to be drawn * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn * @param flags the flags specifing how to process the text * * @exception IllegalArgumentException * @exception SWTException */ 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); checkGC(FONT | FOREGROUND_FILL); if (data.updateClip) setCGClipping(); int length = string.length(); if (length == 0) return; OS.CGContextSaveGState(handle); OS.CGContextScaleCTM(handle, 1, -1); boolean mode = true; switch (data.textAntialias) { case SWT.DEFAULT: /* Printer is off by default */ if (data.window == 0 && data.control == 0 && data.image == null) mode = false; break; case SWT.OFF: mode = false; break; } OS.CGContextSetShouldAntialias(handle, mode); length = setString(string, flags); if ((flags & SWT.DRAW_DELIMITER) != 0) { int layout = data.layout; int[] breakCount = new int[1]; OS.ATSUGetSoftLineBreaks(layout, 0, length, 0, null, breakCount); int[] breaks = new int[breakCount[0] + 1]; OS.ATSUGetSoftLineBreaks(layout, 0, length, breakCount[0], breaks, breakCount); breaks[breakCount[0]] = length; for (int i=0, start=0; isame object using a class * specific comparison. * * @param object the object to compare with this object * @return true if the object is the same as this object and false otherwise * * @see #hashCode */ public boolean equals(Object object) { if (object == this) return true; if (!(object instanceof GC)) return false; return handle == ((GC)object).handle; } /** * Fills the interior of a circular or elliptical arc within * the specified rectangular area, with the receiver's background * color. *

* The resulting arc begins at startAngle and extends * for arcAngle degrees, using the current color. * Angles are interpreted such that 0 degrees is at the 3 o'clock * position. A positive value indicates a counter-clockwise rotation * while a negative value indicates a clockwise rotation. *

* The center of the arc is the center of the rectangle whose origin * is (x, y) and whose size is specified by the * width and height arguments. *

* The resulting arc covers an area width + 1 pixels wide * by height + 1 pixels tall. *

* * @param x the x coordinate of the upper-left corner of the arc to be filled * @param y the y coordinate of the upper-left corner of the arc to be filled * @param width the width of the arc to be filled * @param height the height of the arc to be filled * @param startAngle the beginning angle * @param arcAngle the angular extent of the arc, relative to the start angle * * @exception SWTException
    *
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  • *
* * @see #drawArc */ public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(FILL); if (data.updateClip) setCGClipping(); if (width < 0) { x = x + width; width = -width; } if (height < 0) { y = y + height; height = -height; } if (width == 0 || height == 0 || arcAngle == 0) return; OS.CGContextBeginPath(handle); OS.CGContextSaveGState(handle); OS.CGContextTranslateCTM(handle, x + width / 2f, y + height / 2f); OS.CGContextScaleCTM(handle, width / 2f, height / 2f); OS.CGContextMoveToPoint(handle, 0, 0); if (arcAngle < 0) { OS.CGContextAddArc(handle, 0, 0, 1, -(startAngle + arcAngle) * (float)Compatibility.PI / 180, -startAngle * (float)Compatibility.PI / 180, true); } else { OS.CGContextAddArc(handle, 0, 0, 1, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180, true); } OS.CGContextClosePath(handle); OS.CGContextRestoreGState(handle); OS.CGContextFillPath(handle); flush(); } /** * Fills the interior of the specified rectangle with a gradient * sweeping from left to right or top to bottom progressing * from the receiver's foreground color to its background color. * * @param x the x coordinate of the rectangle to be filled * @param y the y coordinate of the rectangle to be filled * @param width the width of the rectangle to be filled, may be negative * (inverts direction of gradient if horizontal) * @param height the height of the rectangle to be filled, may be negative * (inverts direction of gradient if vertical) * @param vertical if true sweeps from top to bottom, else * sweeps from left to right * * @exception SWTException
    *
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  • *
* * @see #drawRectangle(int, int, int, int) */ public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if ((width == 0) || (height == 0)) return; /* Rewrite this to use GdkPixbuf */ RGB backgroundRGB, foregroundRGB; backgroundRGB = getBackground().getRGB(); foregroundRGB = getForeground().getRGB(); RGB fromRGB, toRGB; fromRGB = foregroundRGB; toRGB = backgroundRGB; 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) { fromRGB = backgroundRGB; toRGB = foregroundRGB; } if (fromRGB.equals(toRGB)) { fillRectangle(x, y, width, height); return; } ImageData.fillGradientRectangle(this, data.device, x, y, width, height, vertical, fromRGB, toRGB, 8, 8, 8); } /** * Fills the interior of an oval, within the specified * rectangular area, with the receiver's background * color. * * @param x the x coordinate of the upper left corner of the oval to be filled * @param y the y coordinate of the upper left corner of the oval to be filled * @param width the width of the oval to be filled * @param height the height of the oval to be filled * * @exception SWTException
    *
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  • *
* * @see #drawOval */ public void fillOval(int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(FILL); if (data.updateClip) setCGClipping(); if (width < 0) { x = x + width; width = -width; } if (height < 0) { y = y + height; height = -height; } OS.CGContextBeginPath(handle); OS.CGContextSaveGState(handle); OS.CGContextTranslateCTM(handle, x + width / 2f, y + height / 2f); OS.CGContextScaleCTM(handle, width / 2f, height / 2f); OS.CGContextMoveToPoint(handle, 1, 0); OS.CGContextAddArc(handle, 0, 0, 1, 0, (float)(Compatibility.PI * 2), false); OS.CGContextClosePath(handle); OS.CGContextRestoreGState(handle); OS.CGContextFillPath(handle); flush(); } /** * Fills the path described by the parameter. * * @param path the path to fill * * @exception IllegalArgumentException
    *
  • ERROR_NULL_ARGUMENT - if the parameter is null
  • *
  • ERROR_INVALID_ARGUMENT - if the parameter has been disposed
  • *
* @exception SWTException
    *
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  • *
* * @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); if (data.updateClip) setCGClipping(); OS.CGContextBeginPath(handle); OS.CGContextAddPath(handle, path.handle); if (data.fillRule == SWT.FILL_WINDING) { OS.CGContextFillPath(handle); } else { OS.CGContextEOFillPath(handle); } flush(); } /** * Fills the interior of the closed polygon which is defined by the * specified array of integer coordinates, using the receiver's * background color. The array contains alternating x and y values * which are considered to represent points which are the vertices of * the polygon. Lines are drawn between each consecutive pair, and * between the first pair and last pair in the array. * * @param pointArray an array of alternating x and y values which are the vertices of the polygon * * @exception IllegalArgumentException
    *
  • ERROR_NULL_ARGUMENT if pointArray is null
  • *
* @exception SWTException
    *
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  • *
* * @see #drawPolygon */ public void fillPolygon(int[] pointArray) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); checkGC(FILL); if (data.updateClip) setCGClipping(); float[] points = new float[pointArray.length]; for (int i=0; i *
  • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  • * * * @see #drawRectangle(int, int, int, int) */ public void fillRectangle(int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(FILL); if (data.updateClip) setCGClipping(); if (width < 0) { x = x + width; width = -width; } if (height < 0) { y = y + height; height = -height; } CGRect rect = new CGRect(); rect.x = x; rect.y = y; rect.width = width; rect.height = height; Pattern pattern = data.backgroundPattern; if (pattern != null) pattern.drawRect = rect; OS.CGContextFillRect(handle, rect); if (pattern != null) pattern.drawRect = null; flush(); } /** * Fills the interior of the specified rectangle, using the receiver's * background color. * * @param rect the rectangle to be filled * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the rectangle is null
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @see #drawRectangle(int, int, int, int) */ public void fillRectangle(Rectangle rect) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); fillRectangle(rect.x, rect.y, rect.width, rect.height); } /** * Fills the interior of the round-cornered rectangle specified by * the arguments, using the receiver's background color. * * @param x the x coordinate of the rectangle to be filled * @param y the y coordinate of the rectangle to be filled * @param width the width of the rectangle to be filled * @param height the height of the rectangle to be filled * @param arcWidth the width of the arc * @param arcHeight the height of the arc * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @see #drawRoundRectangle */ public void fillRoundRectangle(int x, int y, int width, int height, int arcWidth, int arcHeight) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(FILL); if (data.updateClip) setCGClipping(); if (arcWidth == 0 || arcHeight == 0) { fillRectangle(x, y, width, height); return; } int nx = x; int ny = y; int nw = width; int nh = height; int naw = arcWidth; int nah = arcHeight; if (nw < 0) { nw = 0 - nw; nx = nx - nw; } if (nh < 0) { nh = 0 - nh; ny = ny - nh; } if (naw < 0) naw = 0 - naw; if (nah < 0) nah = 0 - nah; if (naw > nw) naw = nw; if (nah > nh) nah = nh; float naw2 = naw / 2f; float nah2 = nah / 2f; float fw = nw / naw2; float fh = nh / nah2; OS.CGContextBeginPath(handle); OS.CGContextSaveGState(handle); OS.CGContextTranslateCTM(handle, nx, ny); OS.CGContextScaleCTM(handle, naw2, nah2); OS.CGContextMoveToPoint(handle, fw - 1, 0); OS.CGContextAddArcToPoint(handle, 0, 0, 0, 1, 1); OS.CGContextAddArcToPoint(handle, 0, fh, 1, fh, 1); OS.CGContextAddArcToPoint(handle, fw, fh, fw, fh - 1, 1); OS.CGContextAddArcToPoint(handle, fw, 0, fw - 1, 0, 1); OS.CGContextClosePath(handle); OS.CGContextRestoreGState(handle); OS.CGContextFillPath(handle); flush(); } void flush () { if (data.control != 0 && data.paintEvent == 0) { if (data.thread != Thread.currentThread()) { OS.CGContextFlush(handle); } else { OS.CGContextSynchronize(handle); } } if (data.control == 0 && data.window != 0) OS.CGContextSynchronize(handle); } /** * Returns the advance width of the specified character in * the font which is currently selected into the receiver. *

    * The advance width is defined as the horizontal distance the cursor * should move after printing the character in the selected font. *

    * * @param ch the character to measure * @return the distance in the x direction to move past the character before painting the next * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public int getAdvanceWidth(char ch) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); //NOT DONE return stringExtent(new String(new char[]{ch})).x; } /** * Returns the background color. * * @return the receiver's background color * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public Color getBackground() { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); return Color.carbon_new (data.device, data.background); } /** * Returns the background pattern. The default value is * null. * * @return the receiver's background pattern * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @see Pattern * * @since 3.1 */ public Pattern getBackgroundPattern() { if (handle == 0) SWT.error(SWT.ERROR_WIDGET_DISPOSED); return data.backgroundPattern; } /** * Returns true if receiver is using the operating system's * advanced graphics subsystem. Otherwise, false is returned * to indicate that normal graphics are in use. *

    * Advanced graphics may not be installed for the operating system. In this * case, false is always returned. Some operating system have * only one graphics subsystem. If this subsystem supports advanced graphics, * then true 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, * true is returned. If the receiver has been explicitly switched * to advanced mode and this mode is supported, true is returned. *

    * * @return the advanced value * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @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. * * @return the alpha value * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @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 SWT.DEFAULT, SWT.OFF or * SWT.ON. Note that this controls anti-aliasing for all * non-text drawing operations. * * @return the anti-aliasing setting * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @see #getTextAntialias * * @since 3.1 */ public int getAntialias() { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); return data.antialias; } /** * Returns the width of the specified character in the font * selected into the receiver. *

    * The width is defined as the space taken up by the actual * character, not including the leading and tailing whitespace * or overhang. *

    * * @param ch the character to measure * @return the width of the character * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public int getCharWidth(char ch) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); //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
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public Rectangle getClipping() { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); /* Calculate visible bounds in device space*/ Rect rect = null; int x = 0, y = 0, width = 0, height = 0; if (data.control != 0) { if (rect == null) rect = new Rect(); OS.GetControlBounds(data.control, rect); width = rect.right - rect.left; height = rect.bottom - rect.top; } else { if (data.image != null) { int image = data.image.handle; width = OS.CGImageGetWidth(image); height = OS.CGImageGetHeight(image); } } /* Intersect visible bounds with clipping in device space and then convert the user space */ int clipRgn = data.clipRgn; if (clipRgn != 0 || data.inverseTransform != null) { int rgn = OS.NewRgn(); OS.SetRectRgn(rgn, (short)x, (short)y, (short)(x + width), (short)(y + height)); /* Intersect visible bounds with clipping */ if (clipRgn != 0) { /* Convert clipping to device space if needed */ if (data.clippingTransform != null) { clipRgn = convertRgn(clipRgn, data.clippingTransform); OS.SectRgn(rgn, clipRgn, rgn); OS.DisposeRgn(clipRgn); } else { OS.SectRgn(rgn, clipRgn, rgn); } } /* Convert to user space */ if (data.inverseTransform != null) { clipRgn = convertRgn(rgn, data.inverseTransform); OS.DisposeRgn(rgn); rgn = clipRgn; } if (rect == null) rect = new Rect(); OS.GetRegionBounds(rgn, rect); OS.DisposeRgn(rgn); x = rect.left; y = rect.top; width = rect.right - rect.left; height = rect.bottom - rect.top; } 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
      *
    • ERROR_NULL_ARGUMENT - if the region is null
    • *
    • ERROR_INVALID_ARGUMENT - if the region is disposed
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ 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); Rect bounds = null; int clipping = region.handle; if (data.clipRgn == 0) { int width = 0, height = 0; if (data.control != 0) { if (bounds == null) bounds = new Rect(); OS.GetControlBounds(data.control, bounds); width = bounds.right - bounds.left; height = bounds.bottom - bounds.top; } else { if (data.image != null) { int image = data.image.handle; width = OS.CGImageGetWidth(image); height = OS.CGImageGetHeight(image); } } OS.SetRectRgn(clipping, (short)0, (short)0, (short)width, (short)height); } else { /* Convert clipping to device space if needed */ if (data.clippingTransform != null) { int rgn = convertRgn(data.clipRgn, data.clippingTransform); OS.CopyRgn(rgn, clipping); OS.DisposeRgn(rgn); } else { OS.CopyRgn(data.clipRgn, clipping); } } if (data.paintEvent != 0 && data.visibleRgn != 0) { if (bounds == null) bounds = new Rect(); OS.GetControlBounds(data.control, bounds); if (data.paintEvent == 0) OS.OffsetRgn(data.visibleRgn, (short)-bounds.left, (short)-bounds.top); OS.SectRgn(data.visibleRgn, clipping, clipping); if (data.paintEvent == 0) OS.OffsetRgn(data.visibleRgn, bounds.left, bounds.top); } /* Convert to user space */ if (data.inverseTransform != null) { int rgn = convertRgn(clipping, data.inverseTransform); OS.CopyRgn(rgn, clipping); OS.DisposeRgn(rgn); } } /** * Returns the receiver's fill rule, which will be one of * SWT.FILL_EVEN_ODD or SWT.FILL_WINDING. * * @return the receiver's fill rule * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @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
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public Font getFont() { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); return data.font; } /** * Returns a FontMetrics which contains information * about the font currently being used by the receiver * to draw and measure text. * * @return font metrics for the receiver's font * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public FontMetrics getFontMetrics() { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); checkGC(FONT); Font font = data.font; ATSFontMetrics metrics = new ATSFontMetrics(); OS.ATSFontGetVerticalMetrics(font.handle, OS.kATSOptionFlagsDefault, metrics); OS.ATSFontGetHorizontalMetrics(font.handle, OS.kATSOptionFlagsDefault, metrics); int ascent = (int)(0.5f + metrics.ascent * font.size); int descent = (int)(0.5f + (-metrics.descent + metrics.leading) * font.size); String s = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; int averageCharWidth = stringExtent(s).x / s.length(); return FontMetrics.carbon_new(ascent, descent, averageCharWidth, 0, ascent + descent); } /** * Returns the receiver's foreground color. * * @return the color used for drawing foreground things * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public Color getForeground() { if (handle == 0) SWT.error(SWT.ERROR_WIDGET_DISPOSED); return Color.carbon_new(data.device, data.foreground); } /** * Returns the foreground pattern. The default value is * null. * * @return the receiver's foreground pattern * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @see Pattern * * @since 3.1 */ public Pattern getForegroundPattern() { if (handle == 0) SWT.error(SWT.ERROR_WIDGET_DISPOSED); return data.foregroundPattern; } /** * Returns the GCData. *

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

    * * @return the receiver's GCData * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @see GCData * * @since 3.2 */ public GCData getGCData() { if (handle == 0) SWT.error(SWT.ERROR_WIDGET_DISPOSED); return data; } /** * Returns the receiver's interpolation setting, which will be one of * SWT.DEFAULT, SWT.NONE, * SWT.LOW or SWT.HIGH. * * @return the receiver's interpolation setting * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @since 3.1 */ public int getInterpolation() { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); int interpolation = OS.CGContextGetInterpolationQuality(handle); switch (interpolation) { case OS.kCGInterpolationDefault: return SWT.DEFAULT; case OS.kCGInterpolationNone: return SWT.NONE; case OS.kCGInterpolationLow: return SWT.LOW; case OS.kCGInterpolationHigh: return SWT.HIGH; } return SWT.DEFAULT; } 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 SWT.CAP_FLAT, SWT.CAP_ROUND, * or SWT.CAP_SQUARE. * * @return the cap style used for drawing lines * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @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 * null. * * @return the lin dash style used for drawing lines * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @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]; for (int i = 0; i < lineDashes.length; i++) { lineDashes[i] = (int)data.lineDashes[i]; } return lineDashes; } /** * Returns the receiver's line join style, which will be one * of the constants SWT.JOIN_MITER, SWT.JOIN_ROUND, * or SWT.JOIN_BEVEL. * * @return the join style used for drawing lines * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @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 SWT.LINE_SOLID, SWT.LINE_DASH, * SWT.LINE_DOT, SWT.LINE_DASHDOT or * SWT.LINE_DASHDOTDOT. * * @return the style used for drawing lines * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public int getLineStyle() { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); return data.lineStyle; } /** * Returns the width that will be used when drawing lines * for all of the figure drawing operations (that is, * drawLine, drawRectangle, * drawPolyline, and so forth. * * @return the receiver's line width * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public int getLineWidth() { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); return (int)data.lineWidth; } /** * Returns the receiver's style information. *

    * Note that the value which is returned by this method may * not match the value which was provided to the constructor * when the receiver was created. This can occur when the underlying * operating system does not support a particular combination of * requested styles. *

    * * @return the style bits * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @since 2.1.2 */ public int getStyle () { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); return data.style; } /** * Returns the receiver's text drawing anti-aliasing setting value, * which will be one of SWT.DEFAULT, SWT.OFF or * SWT.ON. Note that this controls anti-aliasing * only for text drawing operations. * * @return the anti-aliasing setting * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @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
      *
    • ERROR_NULL_ARGUMENT - if the parameter is null
    • *
    • ERROR_INVALID_ARGUMENT - if the parameter has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @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); float[] cmt = data.transform; if (cmt != null) { transform.setElements(cmt[0], cmt[1], cmt[2], cmt[3], cmt[4], cmt[5]); } else { transform.setElements(1, 0, 0, 1, 0, 0); } } /** * Returns true if this GC is drawing in the mode * where the resulting color in the destination is the * exclusive or of the color values in the source * and the destination, and false if it is * drawing in the mode where the destination color is being * replaced with the source color value. * * @return true true if the receiver is in XOR mode, and false otherwise * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public boolean getXORMode() { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); return data.xorMode; } /** * Returns an integer hash code for the receiver. Any two * objects that return true when passed to * equals must return the same value for this * method. * * @return the receiver's hash * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @see #equals */ public int hashCode() { return handle; } void init(Drawable drawable, GCData data, int context) { if (data.foreground != null) data.state &= ~(FOREGROUND | FOREGROUND_FILL); if (data.background != null) data.state &= ~BACKGROUND; if (data.font != null) data.state &= ~FONT; Image image = data.image; if (image != null) image.memGC = this; this.drawable = drawable; this.data = data; handle = context; } /** * Returns true if the receiver has a clipping * region set into it, and false otherwise. * If this method returns false, the receiver will draw on all * available space in the destination. If it returns true, * it will draw only in the area that is covered by the region * that can be accessed with getClipping(region). * * @return true if the GC has a clipping region, and false otherwise * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public boolean isClipped() { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); return data.clipRgn != 0; } /** * Returns true if the GC has been disposed, * and false otherwise. *

    * This method gets the dispose state for the GC. * When a GC has been disposed, it is an error to * invoke any other method using the GC. * * @return true when the GC is disposed and false otherwise */ public boolean isDisposed() { return handle == 0; } boolean isIdentity(float[] transform) { return transform[0] == 1 && transform[1] == 0 && transform[2] == 0 && transform[3] == 1 && transform[4] == 0 && transform[5] == 0; } /** * Sets the receiver to always use the operating system's advanced graphics * subsystem for all graphics operations if the argument is true. * If the argument is false, the advanced graphics subsystem is * no longer used, advanced graphics state is cleared and the normal graphics * subsystem is used from now on. *

    * 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. *

    *

    * 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. *

    * * @param advanced the new advanced graphics state * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @see #setAlpha * @see #setAntialias * @see #setBackgroundPattern * @see #setClipping(Path) * @see #setForegroundPattern * @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(0); setForegroundPattern(null); setInterpolation(SWT.DEFAULT); setTextAntialias(SWT.DEFAULT); setTransform(null); } } /** * Sets the receiver's alpha value. * * @param alpha the alpha value * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @since 3.1 */ public void setAlpha(int alpha) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); data.alpha = alpha & 0xFF; OS.CGContextSetAlpha(handle, data.alpha / 255f); } /** * Sets the receiver's anti-aliasing value to the parameter, * which must be one of SWT.DEFAULT, SWT.OFF * or SWT.ON. Note that this controls anti-aliasing for all * non-text drawing operations. * * @param antialias the anti-aliasing setting * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_ARGUMENT - if the parameter is not one of SWT.DEFAULT, * SWT.OFF or SWT.ON
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @see #setTextAntialias * * @since 3.1 */ public void setAntialias(int antialias) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); boolean mode = true; switch (antialias) { case SWT.DEFAULT: /* Printer is off by default */ if (data.window == 0 && data.control == 0 && data.image == null) mode = false; break; case SWT.OFF: mode = false; break; case SWT.ON: mode = true; break; default: SWT.error(SWT.ERROR_INVALID_ARGUMENT); } data.antialias = antialias; OS.CGContextSetShouldAntialias(handle, mode); } /** * Sets the background color. The background color is used * for fill operations and as the background color when text * is drawn. * * @param color the new background color for the receiver * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the color is null
    • *
    • ERROR_INVALID_ARGUMENT - if the color has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public void setBackground(Color color) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); data.background = color.handle; if (data.backPattern != 0) OS.CGPatternRelease(data.backPattern); data.backPattern = 0; data.backgroundPattern = null; data.state &= ~BACKGROUND; } /** * Sets the background pattern. The default value is null. * * @param pattern the new background pattern * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_ARGUMENT - if the parameter has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @see Pattern * * @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; if (data.backPattern != 0) OS.CGPatternRelease(data.backPattern); data.backPattern = 0; data.backgroundPattern = pattern; data.state &= ~BACKGROUND; } void setClipping(int clipRgn) { if (clipRgn == 0) { if (data.clipRgn != 0) { OS.DisposeRgn(data.clipRgn); data.clipRgn = 0; } data.clippingTransform = null; } else { if (data.clipRgn == 0) data.clipRgn = OS.NewRgn(); OS.CopyRgn(clipRgn, data.clipRgn); if (data.transform != null) { if (data.clippingTransform == null) data.clippingTransform = new float[6]; System.arraycopy(data.transform, 0, data.clippingTransform, 0, data.transform.length); } } data.updateClip = true; setCGClipping(); } /** * Sets the area of the receiver which can be changed * by drawing operations to the rectangular area specified * by the arguments. * * @param x the x coordinate of the clipping rectangle * @param y the y coordinate of the clipping rectangle * @param width the width of the clipping rectangle * @param height the height of the clipping rectangle * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public void setClipping(int x, int y, int width, int height) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (width < 0) { x = x + width; width = -width; } if (height < 0) { y = y + height; height = -height; } int clipRgn = OS.NewRgn(); OS.SetRectRgn(clipRgn, (short)x, (short)y, (short)(x + width), (short)(y + height)); setClipping(clipRgn); OS.DisposeRgn(clipRgn); } /** * Sets the area of the receiver which can be changed * by drawing operations to the path specified * by the argument. * * @param path the clipping path. * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_ARGUMENT - if the path has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @see Path * * @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); setClipping(0); if (path != null) { OS.CGContextAddPath(handle, path.handle); OS.CGContextEOClip(handle); } } /** * Sets the area of the receiver which can be changed * by drawing operations to the rectangular area specified * by the argument. Specifying null for the * rectangle reverts the receiver's clipping area to its * original value. * * @param rect the clipping rectangle or null * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public void setClipping(Rectangle rect) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (rect == null) { setClipping(0); } 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 null for the * region reverts the receiver's clipping area to its * original value. * * @param region the clipping region or null * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_ARGUMENT - if the region has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ 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); setClipping(region != null ? region.handle : 0); } void setCGClipping () { data.updateClip = false; if (data.control == 0) { if (data.window != 0 && ! OS.IsWindowVisible(data.window)) OS.ShowWindow (data.window); OS.CGContextScaleCTM(handle, 1, -1); if (data.clipRgn != 0) { OS.ClipCGContextToRegion(handle, new Rect(), data.clipRgn); } else { int rgn = OS.NewRgn(); OS.SetRectRgn(rgn, (short)-32768, (short)-32768, (short)32767, (short)32767); OS.ClipCGContextToRegion(handle, new Rect(), rgn); OS.DisposeRgn(rgn); } OS.CGContextScaleCTM(handle, 1, -1); return; } int port = data.port; int window = OS.GetControlOwner(data.control); if (port == 0) { port = OS.GetWindowPort(window); } Rect portRect = data.portRect; Rect rect = data.controlRect; OS.CGContextTranslateCTM(handle, -rect.left, (portRect.bottom - portRect.top) - rect.top); OS.CGContextScaleCTM(handle, 1, -1); OS.GetPortBounds(port, portRect); OS.GetControlBounds(data.control, rect); boolean isPaint = data.paintEvent != 0; if (isPaint) { rect.right += rect.left; rect.bottom += rect.top; rect.left = rect.top = 0; } else { int [] contentView = new int [1]; OS.HIViewFindByID (OS.HIViewGetRoot (window), OS.kHIViewWindowContentID (), contentView); CGPoint pt = new CGPoint (); OS.HIViewConvertPoint (pt, OS.HIViewGetSuperview (data.control), contentView [0]); rect.left += (int) pt.x; rect.top += (int) pt.y; rect.right += (int) pt.x; rect.bottom += (int) pt.y; } if (data.clipRgn != 0) { int rgn = OS.NewRgn(); OS.CopyRgn(data.clipRgn, rgn); OS.OffsetRgn(rgn, rect.left, rect.top); OS.SectRgn(data.visibleRgn, rgn, rgn); OS.ClipCGContextToRegion(handle, portRect, rgn); OS.DisposeRgn(rgn); } else { OS.ClipCGContextToRegion(handle, portRect, data.visibleRgn); } OS.CGContextScaleCTM(handle, 1, -1); OS.CGContextTranslateCTM(handle, rect.left, -(portRect.bottom - portRect.top) + rect.top); } void setCGFont() { int tabs = data.tabs; if (tabs != 0) OS.DisposePtr(tabs); data.tabs = 0; Font font = data.font; ATSFontMetrics metrics = new ATSFontMetrics(); OS.ATSFontGetVerticalMetrics(font.handle, OS.kATSOptionFlagsDefault, metrics); OS.ATSFontGetHorizontalMetrics(font.handle, OS.kATSOptionFlagsDefault, metrics); data.fontAscent = (int)(0.5f + metrics.ascent * font.size); data.fontDescent = (int)(0.5f + (-metrics.descent + metrics.leading) * font.size); if (font.atsuiStyle == 0) { if (data.atsuiStyle != 0) OS.ATSUDisposeStyle(data.atsuiStyle); data.atsuiStyle = font.createStyle(); } data.string = null; data.stringWidth = data.stringHeight = -1; } /** * Sets the receiver's fill rule to the parameter, which must be one of * SWT.FILL_EVEN_ODD or SWT.FILL_WINDING. * * @param rule the new fill rule * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_ARGUMENT - if the rule is not one of SWT.FILL_EVEN_ODD * or SWT.FILL_WINDING
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @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
      *
    • ERROR_INVALID_ARGUMENT - if the font has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public void setFont(Font font) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (font == null) font = data.device.systemFont; if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); data.font = font; 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
      *
    • ERROR_NULL_ARGUMENT - if the color is null
    • *
    • ERROR_INVALID_ARGUMENT - if the color has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public void setForeground(Color color) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); data.foreground = color.handle; if (data.forePattern != 0) OS.CGPatternRelease(data.forePattern); data.forePattern = 0; data.foregroundPattern = null; data.state &= ~(FOREGROUND | FOREGROUND_FILL); } /** * Sets the foreground pattern. The default value is null. * * @param pattern the new foreground pattern * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_ARGUMENT - if the parameter has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @see Pattern * * @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; if (data.forePattern != 0) OS.CGPatternRelease(data.forePattern); data.forePattern = 0; data.foregroundPattern = pattern; data.state &= ~(FOREGROUND | FOREGROUND_FILL); } /** * Sets the receiver's interpolation setting to the parameter, which * must be one of SWT.DEFAULT, SWT.NONE, * SWT.LOW or SWT.HIGH. * * @param interpolation the new interpolation setting * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_ARGUMENT - if the rule is not one of SWT.DEFAULT, * SWT.NONE, SWT.LOW or SWT.HIGH *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @since 3.1 */ public void setInterpolation(int interpolation) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); int quality = 0; switch (interpolation) { case SWT.DEFAULT: quality = OS.kCGInterpolationDefault; break; case SWT.NONE: quality = OS.kCGInterpolationNone; break; case SWT.LOW: quality = OS.kCGInterpolationLow; break; case SWT.HIGH: quality = OS.kCGInterpolationHigh; break; default: SWT.error(SWT.ERROR_INVALID_ARGUMENT); } OS.CGContextSetInterpolationQuality(handle, quality); } 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.join; 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 SWT.CAP_FLAT, SWT.CAP_ROUND, * or SWT.CAP_SQUARE. * * @param cap the cap style to be used for drawing lines * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_ARGUMENT - if the style is not valid
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @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 null. If the argument is not null, * the receiver's line style is set to SWT.LINE_CUSTOM, otherwise * it is set to SWT.LINE_SOLID. * * @param dashes the dash style to be used for drawing lines * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_ARGUMENT - if any of the values in the array is less than or equal 0
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @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 SWT.JOIN_MITER, SWT.JOIN_ROUND, * or SWT.JOIN_BEVEL. * * @param join the join style to be used for drawing lines * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_ARGUMENT - if the style is not valid
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @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 SWT.LINE_SOLID, SWT.LINE_DASH, * SWT.LINE_DOT, SWT.LINE_DASHDOT or * SWT.LINE_DASHDOTDOT. * * @param lineStyle the style to be used for drawing lines * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_ARGUMENT - if the style is not valid
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public void setLineStyle(int lineStyle) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (data.lineStyle == lineStyle) return; 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, * drawLine, drawRectangle, * drawPolyline, and so forth. *

    * Note that line width of zero is used as a hint to * indicate that the fastest possible line drawing * algorithms should be used. This means that the * output may be different from line width one. *

    * * @param lineWidth the width of a line * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public void setLineWidth(int lineWidth) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (data.lineWidth == lineWidth) return; data.lineWidth = lineWidth; data.state &= ~LINE_WIDTH; } int setString(String string, int flags) { if (data.layout == 0) createLayout (); if (string == data.string && (flags & ~SWT.DRAW_TRANSPARENT) == (data.drawFlags & ~SWT.DRAW_TRANSPARENT)) { return data.stringLength; } int layout = data.layout; int length = string.length(); char[] chars = new char[length]; string.getChars(0, length, chars, 0); int breakCount = 0; int[] breaks = null; if ((flags & (SWT.DRAW_MNEMONIC | SWT.DRAW_DELIMITER)) != 0) { int i=0, j=0; while (i < chars.length) { char c = chars [j++] = chars [i++]; switch (c) { case '&': { if ((flags & SWT.DRAW_MNEMONIC) != 0) { if (i == chars.length) {continue;} if (chars [i] == '&') {i++; continue;} j--; } break; } case '\r': case '\n': { if ((flags & SWT.DRAW_DELIMITER) != 0) { if (c == '\r' && i != chars.length && chars[i] == '\n') i++; j--; if (breaks == null) { breaks = new int[4]; } else if (breakCount == breaks.length) { int[] newBreaks = new int[breaks.length + 4]; System.arraycopy(breaks, 0, newBreaks, 0, breaks.length); breaks = newBreaks; } breaks[breakCount++] = j; } break; } } } length = j; } if ((flags & SWT.DRAW_TAB) != 0) { if (data.tabs == 0) createTabs(); OS.ATSUSetTabArray(layout, data.tabs, TAB_COUNT); } else { OS.ATSUSetTabArray(layout, 0, 0); } int ptr = OS.NewPtr(length * 2); OS.memcpy(ptr, chars, length * 2); OS.ATSUSetTextPointerLocation(layout, ptr, 0, length, length); if ((flags & SWT.DRAW_DELIMITER) != 0 && breaks != null) { for (int i=0; itrue, puts the receiver * in a drawing mode where the resulting color in the destination * is the exclusive or of the color values in the source * and the destination, and if the argument is false, * puts the receiver in a drawing mode where the destination color * is replaced with the source color value. *

    * Note that this mode in fundamentally unsupportable on certain * platforms, notably Carbon (Mac OS X). Clients that want their * code to run on all platforms need to avoid this method. *

    * * @param xor if true, then xor mode is used, otherwise source copy mode is used * * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @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 SWT.DEFAULT, SWT.OFF * or SWT.ON. Note that this controls anti-aliasing only * for all text drawing operations. * * @param antialias the anti-aliasing setting * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_ARGUMENT - if the parameter is not one of SWT.DEFAULT, * SWT.OFF or SWT.ON
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @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 null, the current transform is set to * the identity transform. * * @param transform the transform to set * * @exception IllegalArgumentException
      *
    • ERROR_INVALID_ARGUMENT - if the parameter has been disposed
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    * * @see Transform * * @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); if (data.inverseTransform != null) OS.CGContextConcatCTM(handle, data.inverseTransform); if (transform != null) { OS.CGContextConcatCTM(handle, transform.handle); if (data.transform == null) data.transform = new float[6]; if (data.inverseTransform == null) data.inverseTransform = new float[6]; System.arraycopy(transform.handle, 0, data.transform, 0, data.transform.length); System.arraycopy(transform.handle, 0, data.inverseTransform, 0, data.inverseTransform.length); OS.CGAffineTransformInvert(data.inverseTransform, data.inverseTransform); } else { data.transform = data.inverseTransform = null; } if (data.forePattern != 0) { OS.CGPatternRelease(data.forePattern); data.forePattern = 0; data.state &= ~(FOREGROUND | FOREGROUND_FILL); } if (data.backPattern != 0) { OS.CGPatternRelease(data.backPattern); data.backPattern = 0; data.state &= ~BACKGROUND; } } /** * Returns the extent of the given string. No tab * expansion or carriage return processing will be performed. *

    * The extent of a string is the width and height of * the rectangular area it would cover if drawn in a particular * font (in this case, the current font in the receiver). *

    * * @param string the string to measure * @return a point containing the extent of the string * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the string is null
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public Point stringExtent(String string) { return textExtent(string, 0); } /** * Returns the extent of the given string. Tab expansion and * carriage return processing are performed. *

    * The extent of a string is the width and height of * the rectangular area it would cover if drawn in a particular * font (in this case, the current font in the receiver). *

    * * @param string the string to measure * @return a point containing the extent of the string * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the string is null
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public Point textExtent(String string) { return textExtent(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB); } /** * Returns the extent of the given string. Tab expansion, line * delimiter and mnemonic processing are performed according to * the specified flags, which can be a combination of: *
    *
    DRAW_DELIMITER
    *
    draw multiple lines
    *
    DRAW_TAB
    *
    expand tabs
    *
    DRAW_MNEMONIC
    *
    underline the mnemonic character
    *
    DRAW_TRANSPARENT
    *
    transparent background
    *
    *

    * The extent of a string is the width and height of * the rectangular area it would cover if drawn in a particular * font (in this case, the current font in the receiver). *

    * * @param string the string to measure * @param flags the flags specifing how to process the text * @return a point containing the extent of the string * * @exception IllegalArgumentException
      *
    • ERROR_NULL_ARGUMENT - if the string is null
    • *
    * @exception SWTException
      *
    • ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
    • *
    */ public Point textExtent(String string, int flags) { if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); checkGC(FONT); int length = setString(string, flags); if (data.stringWidth != -1) return new Point(data.stringWidth, data.stringHeight); int width = 0, height; if (length == 0) { height = data.fontAscent + data.fontDescent; } else { ATSTrapezoid trapezoid = new ATSTrapezoid(); if ((flags & SWT.DRAW_DELIMITER) != 0) { height = 0; int layout = data.layout; int[] breakCount = new int[1]; OS.ATSUGetSoftLineBreaks(layout, 0, length, 0, null, breakCount); int[] breaks = new int[breakCount[0] + 1]; OS.ATSUGetSoftLineBreaks(layout, 0, length, breakCount[0], breaks, breakCount); breaks[breakCount[0]] = length; for (int i=0, start=0; i