diff options
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/motif')
45 files changed, 0 insertions, 45353 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java deleted file mode 100755 index b202ed4fa5..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java +++ /dev/null @@ -1,339 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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.motif.*; -import org.eclipse.swt.*; - -/** - * Instances of this class manage the operating system resources that - * implement SWT's RGB color model. To create a color you can either - * specify the individual color components as integers in the range - * 0 to 255 or provide an instance of an <code>RGB</code>. - * <p> - * Application code must explicitly invoke the <code>Color.dispose()</code> - * method to release the operating system resources managed by each instance - * when those instances are no longer required. - * </p> - * - * @see RGB - * @see Device#getSystemColor - * @see <a href="http://www.eclipse.org/swt/snippets/#color">Color and RGB snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: PaintExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public final class Color extends Resource { - /** - * the handle to the OS color resource - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public XColor handle; - -Color(Device device) { - super(device); -} -/** - * Constructs a new instance of this class given a device and the - * desired red, green and blue values expressed as ints in the range - * 0 to 255 (where 0 is black and 255 is full brightness). On limited - * color devices, the color instance created by this call may not have - * the same RGB values as the ones specified by the arguments. The - * RGB values on the returned instance will be the color values of - * the operating system color. - * <p> - * You must dispose the color when it is no longer required. - * </p> - * - * @param device the device on which to allocate the color - * @param red the amount of red in the color - * @param green the amount of green in the color - * @param blue the amount of blue in the color - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255</li> - * </ul> - * - * @see #dispose - */ -public Color (Device device, int red, int green, int blue) { - super(device); - init(red, green, blue); - init(); -} -/** - * Constructs a new instance of this class given a device and an - * <code>RGB</code> describing the desired red, green and blue values. - * On limited color devices, the color instance created by this call - * may not have the same RGB values as the ones specified by the - * argument. The RGB values on the returned instance will be the color - * values of the operating system color. - * <p> - * You must dispose the color when it is no longer required. - * </p> - * - * @param device the device on which to allocate the color - * @param rgb the RGB values of the desired color - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_NULL_ARGUMENT - if the rgb argument is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue components of the argument are not between 0 and 255</li> - * </ul> - * - * @see #dispose - */ -public Color (Device device, RGB rgb) { - super(device); - if (rgb == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - init(rgb.red, rgb.green, rgb.blue); - init(); -} -void destroy() { - int xDisplay = device.xDisplay; - int pixel = handle.pixel; - if (device.colorRefCount != null) { - /* If this was the last reference, remove the color from the list */ - if (--device.colorRefCount[pixel] == 0) { - device.xcolors[pixel] = null; - } - } - int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay)); - OS.XFreeColors(xDisplay, colormap, new int[] { pixel }, 1, 0); - handle = null; -} -/** - * Compares the argument to the receiver, and returns true - * if they represent the <em>same</em> object using a class - * specific comparison. - * - * @param object the object to compare with this object - * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise - * - * @see #hashCode - */ -public boolean equals (Object object) { - if (object == this) return true; - if (!(object instanceof Color)) return false; - Color color = (Color)object; - XColor xColor = color.handle; - if (handle == xColor) return true; - return device == color.device && handle.red == xColor.red && - handle.green == xColor.green && handle.blue == xColor.blue; -} -/** - * Returns the amount of blue in the color, from 0 to 255. - * - * @return the blue component of the color - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int getBlue () { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return (handle.blue >> 8) & 0xFF; -} -/** - * Returns the amount of green in the color, from 0 to 255. - * - * @return the green component of the color - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int getGreen () { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return (handle.green >> 8) & 0xFF; -} -/** - * Returns the amount of red in the color, from 0 to 255. - * - * @return the red component of the color - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int getRed () { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return (handle.red >> 8) & 0xFF; -} -/** - * Returns an <code>RGB</code> representing the receiver. - * - * @return the RGB for the color - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public RGB getRGB () { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return new RGB((handle.red >> 8) & 0xFF, (handle.green >> 8) & 0xFF, (handle.blue >> 8) & 0xFF); -} -/** - * Returns an integer hash code for the receiver. Any two - * objects that return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals - */ -public int hashCode () { - if (isDisposed()) return 0; - return handle.red ^ handle.green ^ handle.blue; -} -void init(int red, int green, int blue) { - if ((red > 255) || (red < 0) || - (green > 255) || (green < 0) || - (blue > 255) || (blue < 0)) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - XColor xColor = new XColor(); - xColor.red = (short)((red & 0xFF) | ((red & 0xFF) << 8)); - xColor.green = (short)((green & 0xFF) | ((green & 0xFF) << 8)); - xColor.blue = (short)((blue & 0xFF) | ((blue & 0xFF) << 8)); - handle = xColor; - int xDisplay = device.xDisplay; - int screen = OS.XDefaultScreen(xDisplay); - int colormap = OS.XDefaultColormap(xDisplay, screen); - /* 1. Try to allocate the color */ - if (OS.XAllocColor(xDisplay, colormap, xColor) != 0) { - if (device.colorRefCount != null) { - /* Make a copy of the color to put in the colors array */ - XColor colorCopy = new XColor(); - colorCopy.red = xColor.red; - colorCopy.green = xColor.green; - colorCopy.blue = xColor.blue; - colorCopy.pixel = xColor.pixel; - device.xcolors[colorCopy.pixel] = colorCopy; - device.colorRefCount[xColor.pixel]++; - } - return; - } - /* - * 2. Allocation failed. Query the entire colormap and - * find the closest match which can be allocated. - * This should never occur on a truecolor display. - */ - Visual visual = new Visual(); - OS.memmove(visual, OS.XDefaultVisual(xDisplay, screen), Visual.sizeof); - int mapEntries = visual.map_entries; - XColor[] queried = new XColor[mapEntries]; - int[] distances = new int[mapEntries]; - /* - * Query all colors in the colormap and calculate the distance - * from each to the desired color. - */ - for (int i = 0; i < mapEntries; i++) { - XColor color = new XColor(); - color.pixel = i; - queried[i] = color; - OS.XQueryColor(xDisplay, colormap, color); - int r = red - ((color.red >> 8) & 0xFF); - int g = green - ((color.green >> 8) & 0xFF); - int b = blue - ((color.blue >> 8) & 0xFF); - distances[i] = r*r + g*g + b*b; - } - /* - * Try to allocate closest matching queried color. - * The allocation can fail if the closest matching - * color is allocated privately, so go through them - * in order of increasing distance. - */ - for (int i = 0; i < mapEntries; i++) { - int minDist = 0x30000; - int minIndex = 0; - for (int j = 0; j < mapEntries; j++) { - if (distances[j] < minDist) { - minDist = distances[j]; - minIndex = j; - } - } - XColor queriedColor = queried[minIndex]; - XColor osColor = new XColor(); - osColor.red = queriedColor.red; - osColor.green = queriedColor.green; - osColor.blue = queriedColor.blue; - if (OS.XAllocColor(xDisplay, colormap, osColor) != 0) { - /* Allocation succeeded. Copy the fields into the handle */ - xColor.red = osColor.red; - xColor.green = osColor.green; - xColor.blue = osColor.blue; - xColor.pixel = osColor.pixel; - if (device.colorRefCount != null) { - /* Put osColor in the colors array */ - device.xcolors[osColor.pixel] = osColor; - device.colorRefCount[osColor.pixel]++; - } - return; - } - /* The allocation failed; matching color is allocated privately */ - distances[minIndex] = 0x30000; - } - /* - * 3. Couldn't allocate any of the colors in the colormap. - * This means all colormap entries were allocated privately - * by other applications. Give up and allocate black. - */ - XColor osColor = new XColor(); - OS.XAllocColor(xDisplay, colormap, osColor); - /* Copy the fields into the handle */ - xColor.red = osColor.red; - xColor.green = osColor.green; - xColor.blue = osColor.blue; - xColor.pixel = osColor.pixel; - if (device.colorRefCount != null) { - /* Put osColor in the colors array */ - device.xcolors[osColor.pixel] = osColor; - device.colorRefCount[osColor.pixel]++; - } -} -/** - * Returns <code>true</code> if the color has been disposed, - * and <code>false</code> otherwise. - * <p> - * This method gets the dispose state for the color. - * When a color has been disposed, it is an error to - * invoke any other method using the color. - * - * @return <code>true</code> when the color is disposed and <code>false</code> otherwise - */ -public boolean isDisposed() { - return handle == null; -} -public static Color motif_new(Device device, XColor xColor) { - Color color = new Color(device); - color.handle = xColor; - return color; -} -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the receiver - */ -public String toString () { - if (isDisposed()) return "Color {*DISPOSED*}"; - return "Color {" + getRed() + ", " + getGreen() + ", " + getBlue() + "}"; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Cursor.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Cursor.java deleted file mode 100755 index cc3c048e0f..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Cursor.java +++ /dev/null @@ -1,441 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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.motif.*; -import org.eclipse.swt.*; - -/** - * Instances of this class manage operating system resources that - * specify the appearance of the on-screen pointer. To create a - * cursor you specify the device and either a simple cursor style - * describing one of the standard operating system provided cursors - * or the image and mask data for the desired appearance. - * <p> - * Application code must explicitly invoke the <code>Cursor.dispose()</code> - * method to release the operating system resources managed by each instance - * when those instances are no longer required. - * </p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd> - * CURSOR_ARROW, CURSOR_WAIT, CURSOR_CROSS, CURSOR_APPSTARTING, CURSOR_HELP, - * CURSOR_SIZEALL, CURSOR_SIZENESW, CURSOR_SIZENS, CURSOR_SIZENWSE, CURSOR_SIZEWE, - * CURSOR_SIZEN, CURSOR_SIZES, CURSOR_SIZEE, CURSOR_SIZEW, CURSOR_SIZENE, CURSOR_SIZESE, - * CURSOR_SIZESW, CURSOR_SIZENW, CURSOR_UPARROW, CURSOR_IBEAM, CURSOR_NO, CURSOR_HAND - * </dd> - * </dl> - * <p> - * Note: Only one of the above styles may be specified. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#cursor">Cursor snippets</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public final class Cursor extends Resource { - /** - * the handle to the OS cursor resource - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public int handle; - - static final byte[] APPSTARTING_SRC = { - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, - 0x0c, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x00, - 0x7c, 0x00, 0x00, 0x00, (byte)0xfc, 0x00, 0x00, 0x00, (byte)0xfc, 0x01, 0x00, 0x00, - (byte)0xfc, 0x3b, 0x00, 0x00, 0x7c, 0x38, 0x00, 0x00, 0x6c, 0x54, 0x00, 0x00, - (byte)0xc4, (byte)0xdc, 0x00, 0x00, (byte)0xc0, 0x44, 0x00, 0x00, (byte)0x80, 0x39, 0x00, 0x00, - (byte)0x80, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - - static final byte[] APPSTARTING_MASK = { - 0x00, 0x00, 0x00, 0x00, 0x06, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, - 0x1e, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, 0x7e, 0x00, 0x00, 0x00, - (byte)0xfe, 0x00, 0x00, 0x00, (byte)0xfe, 0x01, 0x00, 0x00, (byte)0xfe, 0x3b, 0x00, 0x00, - (byte)0xfe, 0x7f, 0x00, 0x00, (byte)0xfe, 0x7f, 0x00, 0x00, (byte)0xfe, (byte)0xfe, 0x00, 0x00, - (byte)0xee, (byte)0xff, 0x01, 0x00, (byte)0xe4, (byte)0xff, 0x00, 0x00, (byte)0xc0, 0x7f, 0x00, 0x00, - (byte)0xc0, 0x7f, 0x00, 0x00, (byte)0x80, 0x39, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; - -Cursor (Device device) { - super(device); -} -/** - * Constructs a new cursor given a device and a style - * constant describing the desired cursor appearance. - * <p> - * You must dispose the cursor when it is no longer required. - * </p> - * - * @param device the device on which to allocate the cursor - * @param style the style of cursor to allocate - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_INVALID_ARGUMENT - when an unknown style is specified</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li> - * </ul> - * - * @see SWT#CURSOR_ARROW - * @see SWT#CURSOR_WAIT - * @see SWT#CURSOR_CROSS - * @see SWT#CURSOR_APPSTARTING - * @see SWT#CURSOR_HELP - * @see SWT#CURSOR_SIZEALL - * @see SWT#CURSOR_SIZENESW - * @see SWT#CURSOR_SIZENS - * @see SWT#CURSOR_SIZENWSE - * @see SWT#CURSOR_SIZEWE - * @see SWT#CURSOR_SIZEN - * @see SWT#CURSOR_SIZES - * @see SWT#CURSOR_SIZEE - * @see SWT#CURSOR_SIZEW - * @see SWT#CURSOR_SIZENE - * @see SWT#CURSOR_SIZESE - * @see SWT#CURSOR_SIZESW - * @see SWT#CURSOR_SIZENW - * @see SWT#CURSOR_UPARROW - * @see SWT#CURSOR_IBEAM - * @see SWT#CURSOR_NO - * @see SWT#CURSOR_HAND - */ -public Cursor (Device device, int style) { - super(device); - int shape = 0; - switch (style) { - case SWT.CURSOR_APPSTARTING: break; - case SWT.CURSOR_ARROW: shape = OS.XC_left_ptr; break; - case SWT.CURSOR_WAIT: shape = OS.XC_watch; break; - case SWT.CURSOR_HAND: shape = OS.XC_hand2; break; - case SWT.CURSOR_CROSS: shape = OS.XC_cross; break; - case SWT.CURSOR_HELP: shape = OS.XC_question_arrow; break; - case SWT.CURSOR_SIZEALL: shape = OS.XC_fleur; break; - case SWT.CURSOR_SIZENESW: shape = OS.XC_sizing; break; - case SWT.CURSOR_SIZENS: shape = OS.XC_double_arrow; break; - case SWT.CURSOR_SIZENWSE: shape = OS.XC_sizing; break; - case SWT.CURSOR_SIZEWE: shape = OS.XC_sb_h_double_arrow; break; - case SWT.CURSOR_SIZEN: shape = OS.XC_top_side; break; - case SWT.CURSOR_SIZES: shape = OS.XC_bottom_side; break; - case SWT.CURSOR_SIZEE: shape = OS.XC_right_side; break; - case SWT.CURSOR_SIZEW: shape = OS.XC_left_side; break; - case SWT.CURSOR_SIZENE: shape = OS.XC_top_right_corner; break; - case SWT.CURSOR_SIZESE: shape = OS.XC_bottom_right_corner; break; - case SWT.CURSOR_SIZESW: shape = OS.XC_bottom_left_corner; break; - case SWT.CURSOR_SIZENW: shape = OS.XC_top_left_corner; break; - case SWT.CURSOR_UPARROW: shape = OS.XC_sb_up_arrow; break; - case SWT.CURSOR_IBEAM: shape = OS.XC_xterm; break; - case SWT.CURSOR_NO: shape = OS.XC_X_cursor; break; - default: - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - if (shape == 0 && style == SWT.CURSOR_APPSTARTING) { - handle = createCursor(APPSTARTING_SRC, APPSTARTING_MASK, 32, 32, 2, 2, true); - } else { - handle = OS.XCreateFontCursor(this.device.xDisplay, shape); - } - if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); - init(); -} -/** - * Constructs a new cursor given a device, image and mask - * data describing the desired cursor appearance, and the x - * and y coordinates of the <em>hotspot</em> (that is, the point - * within the area covered by the cursor which is considered - * to be where the on-screen pointer is "pointing"). - * <p> - * The mask data is allowed to be null, but in this case the source - * must be an ImageData representing an icon that specifies both - * color data and mask data. - * <p> - * You must dispose the cursor when it is no longer required. - * </p> - * - * @param device the device on which to allocate the cursor - * @param source the color data for the cursor - * @param mask the mask data for the cursor (or null) - * @param hotspotX the x coordinate of the cursor's hotspot - * @param hotspotY the y coordinate of the cursor's hotspot - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_NULL_ARGUMENT - if the source is null</li> - * <li>ERROR_NULL_ARGUMENT - if the mask is null and the source does not have a mask</li> - * <li>ERROR_INVALID_ARGUMENT - if the source and the mask are not the same - * size, or if the hotspot is outside the bounds of the image</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li> - * </ul> - */ -public Cursor (Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) { - super(device); - if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (mask == null) { - if (source.getTransparencyType() != SWT.TRANSPARENCY_MASK) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - mask = source.getTransparencyMask(); - } - /* Check the bounds. Mask must be the same size as source */ - if (mask.width != source.width || mask.height != source.height) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - /* Check the hotspots */ - if (hotspotX >= source.width || hotspotX < 0 || - hotspotY >= source.height || hotspotY < 0) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - /* Convert depth to 1 */ - source = ImageData.convertMask(source); - mask = ImageData.convertMask(mask); - byte[] sourceData = new byte[source.data.length]; - byte[] maskData = new byte[mask.data.length]; - /* Swap the bits in each byte and convert to appropriate scanline pad */ - byte[] data = source.data; - for (int i = 0; i < data.length; i++) { - byte s = data[i]; - sourceData[i] = (byte)(((s & 0x80) >> 7) | - ((s & 0x40) >> 5) | - ((s & 0x20) >> 3) | - ((s & 0x10) >> 1) | - ((s & 0x08) << 1) | - ((s & 0x04) << 3) | - ((s & 0x02) << 5) | - ((s & 0x01) << 7)); - sourceData[i] = (byte) ~sourceData[i]; - } - sourceData = ImageData.convertPad(sourceData, source.width, source.height, source.depth, source.scanlinePad, 1); - data = mask.data; - for (int i = 0; i < data.length; i++) { - byte s = data[i]; - maskData[i] = (byte)(((s & 0x80) >> 7) | - ((s & 0x40) >> 5) | - ((s & 0x20) >> 3) | - ((s & 0x10) >> 1) | - ((s & 0x08) << 1) | - ((s & 0x04) << 3) | - ((s & 0x02) << 5) | - ((s & 0x01) << 7)); - maskData[i] = (byte) ~maskData[i]; - } - maskData = ImageData.convertPad(maskData, mask.width, mask.height, mask.depth, mask.scanlinePad, 1); - /* Note that the mask and source are reversed */ - handle = createCursor(maskData, sourceData, source.width, source.height, hotspotX, hotspotY, true); - if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); - init(); -} -/** - * Constructs a new cursor given a device, image data describing - * the desired cursor appearance, and the x and y coordinates of - * the <em>hotspot</em> (that is, the point within the area - * covered by the cursor which is considered to be where the - * on-screen pointer is "pointing"). - * <p> - * You must dispose the cursor when it is no longer required. - * </p> - * - * @param device the device on which to allocate the cursor - * @param source the image data for the cursor - * @param hotspotX the x coordinate of the cursor's hotspot - * @param hotspotY the y coordinate of the cursor's hotspot - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_NULL_ARGUMENT - if the image is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the hotspot is outside the bounds of the - * image</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li> - * </ul> - * - * @since 3.0 - */ -public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) { - super(device); - if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (hotspotX >= source.width || hotspotX < 0 || - hotspotY >= source.height || hotspotY < 0) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - ImageData mask = source.getTransparencyMask(); - - /* Ensure depth is equal to 1 */ - if (source.depth > 1) { - /* Create a destination image with no data */ - ImageData newSource = new ImageData( - source.width, source.height, 1, ImageData.bwPalette(), - 1, null, 0, null, null, -1, -1, 0, 0, 0, 0, 0); - - byte[] newReds = new byte[]{0, (byte)255}, newGreens = newReds, newBlues = newReds; - - /* Convert the source to a black and white image of depth 1 */ - PaletteData palette = source.palette; - if (palette.isDirect) { - ImageData.blit(ImageData.BLIT_SRC, - source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, palette.redMask, palette.greenMask, palette.blueMask, - ImageData.ALPHA_OPAQUE, null, 0, 0, 0, - newSource.data, newSource.depth, newSource.bytesPerLine, newSource.getByteOrder(), 0, 0, newSource.width, newSource.height, newReds, newGreens, newBlues, - false, false); - } else { - RGB[] rgbs = palette.getRGBs(); - int length = rgbs.length; - byte[] srcReds = new byte[length]; - byte[] srcGreens = new byte[length]; - byte[] srcBlues = new byte[length]; - for (int i = 0; i < rgbs.length; i++) { - RGB rgb = rgbs[i]; - if (rgb == null) continue; - srcReds[i] = (byte)rgb.red; - srcGreens[i] = (byte)rgb.green; - srcBlues[i] = (byte)rgb.blue; - } - ImageData.blit(ImageData.BLIT_SRC, - source.data, source.depth, source.bytesPerLine, source.getByteOrder(), 0, 0, source.width, source.height, srcReds, srcGreens, srcBlues, - ImageData.ALPHA_OPAQUE, null, 0, 0, 0, - newSource.data, newSource.depth, newSource.bytesPerLine, newSource.getByteOrder(), 0, 0, newSource.width, newSource.height, newReds, newGreens, newBlues, - false, false); - } - source = newSource; - } - - /* Swap the bits in each byte and convert to appropriate scanline pad */ - byte[] sourceData = new byte[source.data.length]; - byte[] maskData = new byte[mask.data.length]; - byte[] data = source.data; - for (int i = 0; i < data.length; i++) { - byte s = data[i]; - sourceData[i] = (byte)(((s & 0x80) >> 7) | - ((s & 0x40) >> 5) | - ((s & 0x20) >> 3) | - ((s & 0x10) >> 1) | - ((s & 0x08) << 1) | - ((s & 0x04) << 3) | - ((s & 0x02) << 5) | - ((s & 0x01) << 7)); - } - sourceData = ImageData.convertPad(sourceData, source.width, source.height, source.depth, source.scanlinePad, 1); - data = mask.data; - for (int i = 0; i < data.length; i++) { - byte s = data[i]; - maskData[i] = (byte)(((s & 0x80) >> 7) | - ((s & 0x40) >> 5) | - ((s & 0x20) >> 3) | - ((s & 0x10) >> 1) | - ((s & 0x08) << 1) | - ((s & 0x04) << 3) | - ((s & 0x02) << 5) | - ((s & 0x01) << 7)); - } - maskData = ImageData.convertPad(maskData, mask.width, mask.height, mask.depth, mask.scanlinePad, 1); - handle = createCursor(sourceData, maskData, source.width, source.height, hotspotX, hotspotY, false); - if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); - init(); -} -int createCursor(byte[] sourceData, byte[] maskData, int width, int height, int hotspotX, int hotspotY, boolean reverse) { - int xDisplay = device.xDisplay; - int drawable = OS.XDefaultRootWindow(xDisplay); - int sourcePixmap = OS.XCreateBitmapFromData(xDisplay, drawable, sourceData, width, height); - int maskPixmap = OS.XCreateBitmapFromData(xDisplay, drawable, maskData, width, height); - int cursor = 0; - if (sourcePixmap != 0 && maskPixmap != 0) { - int screenNum = OS.XDefaultScreen(xDisplay); - XColor foreground = new XColor(); - foreground.pixel = !reverse ? OS.XWhitePixel(xDisplay, screenNum) : OS.XBlackPixel(xDisplay, screenNum); - if (!reverse) foreground.red = foreground.green = foreground.blue = (short)0xFFFF; - XColor background = new XColor(); - background.pixel = reverse ? OS.XWhitePixel(xDisplay, screenNum) : OS.XBlackPixel(xDisplay, screenNum); - if (reverse) background.red = background.green = background.blue = (short)0xFFFF; - cursor = OS.XCreatePixmapCursor(xDisplay, sourcePixmap, maskPixmap, foreground, background, hotspotX, hotspotY); - } - if (sourcePixmap != 0) OS.XFreePixmap(xDisplay, sourcePixmap); - if (maskPixmap != 0) OS.XFreePixmap(xDisplay, maskPixmap); - return cursor; -} -void destroy() { - OS.XFreeCursor(device.xDisplay, handle); - handle = 0; -} -/** - * Compares the argument to the receiver, and returns true - * if they represent the <em>same</em> object using a class - * specific comparison. - * - * @param object the object to compare with this object - * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise - * - * @see #hashCode - */ -public boolean equals (Object object) { - if (object == this) return true; - if (!(object instanceof Cursor)) return false; - Cursor cursor = (Cursor)object; - return device == cursor.device && handle == cursor.handle; -} -/** - * Returns an integer hash code for the receiver. Any two - * objects that return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals - */ -public int hashCode () { - return handle; -} -/** - * Returns <code>true</code> if the cursor has been disposed, - * and <code>false</code> otherwise. - * <p> - * This method gets the dispose state for the cursor. - * When a cursor has been disposed, it is an error to - * invoke any other method using the cursor. - * - * @return <code>true</code> when the cursor is disposed and <code>false</code> otherwise - */ -public boolean isDisposed() { - return handle == 0; -} -public static Cursor motif_new(Device device, int handle) { - Cursor cursor = new Cursor(device); - cursor.handle = handle; - return cursor; -} -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the receiver - */ -public String toString () { - if (isDisposed()) return "Cursor {*DISPOSED*}"; - return "Cursor {" + handle + "}"; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java deleted file mode 100755 index 4587d5ffe2..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java +++ /dev/null @@ -1,1021 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - - -import org.eclipse.swt.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; - -/** - * This class is the abstract superclass of all device objects, - * such as the Display device and the Printer device. Devices - * can have a graphics context (GC) created for them, and they - * can be drawn on by sending messages to the associated GC. - * - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public abstract class Device implements Drawable { - /** - * the handle to the X Display - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public int xDisplay; - - /** - * whether the XLFD resolution should match the - * resolution of the device when fonts are created - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - // TEMPORARY CODE - public boolean setDPI; - - /* Debugging */ - public static boolean DEBUG; - boolean debug = DEBUG; - boolean tracking = DEBUG; - Error [] errors; - Object [] objects; - Object trackingLock; - - /* Arguments for XtOpenDisplay */ - String display_name; - String application_name; - String application_class; - - /* Colormap and reference count for this display */ - XColor [] xcolors; - int [] colorRefCount; - - /* System Colors */ - Color COLOR_BLACK, COLOR_DARK_RED, COLOR_DARK_GREEN, COLOR_DARK_YELLOW, COLOR_DARK_BLUE; - Color COLOR_DARK_MAGENTA, COLOR_DARK_CYAN, COLOR_GRAY, COLOR_DARK_GRAY, COLOR_RED; - Color COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE; - - /* System Font */ - Font systemFont; - - int shellHandle; - - boolean useXRender; - - static boolean CAIRO_LOADED; - - /* Parsing Tables */ - int tabPointer, crPointer; - /** - * parse table mappings for tab and cr - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - // TEMPORARY CODE - public int tabMapping, crMapping; - - /* Xt Warning and Error Handlers */ - boolean warnings = true; - Callback xtWarningCallback, xtErrorCallback; - int xtWarningProc, xtErrorProc, xtNullWarningProc, xtNullErrorProc; - - /* X Warning and Error Handlers */ - static Callback XErrorCallback, XIOErrorCallback; - static int XErrorProc, XIOErrorProc, XNullErrorProc, XNullIOErrorProc; - static Device[] Devices = new Device[4]; - - /* Initialize X and Xt */ - static { - /* - * This code is intentionally commented. - */ -// OS.XInitThreads (); -// OS.XtToolkitThreadInitialize (); - OS.XtToolkitInitialize (); - } - - /* - * TEMPORARY CODE. When a graphics object is - * created and the device parameter is null, - * the current Display is used. This presents - * a problem because SWT graphics does not - * reference classes in SWT widgets. The correct - * fix is to remove this feature. Unfortunately, - * too many application programs rely on this - * feature. - */ - protected static Device CurrentDevice; - protected static Runnable DeviceFinder; - static { - try { - Class.forName ("org.eclipse.swt.widgets.Display"); - } catch (ClassNotFoundException e) {} - } - -/* -* TEMPORARY CODE -*/ -static synchronized Device getDevice () { - if (DeviceFinder != null) DeviceFinder.run(); - Device device = CurrentDevice; - CurrentDevice = null; - return device; -} - -/** - * Constructs a new instance of this class. - * <p> - * You must dispose the device when it is no longer required. - * </p> - * - * @see #create - * @see #init - * - * @since 3.1 - */ -public Device() { - this(null); -} - -/** - * Constructs a new instance of this class. - * <p> - * You must dispose the device when it is no longer required. - * </p> - * - * @param data the DeviceData which describes the receiver - * - * @see #create - * @see #init - * @see DeviceData - */ -public Device(DeviceData data) { - synchronized (Device.class) { - if (data != null) { - display_name = data.display_name; - application_name = data.application_name; - application_class = data.application_class; - tracking = data.tracking; - debug = data.debug; - } - if (tracking) { - errors = new Error [128]; - objects = new Object [128]; - trackingLock = new Object (); - } - create (data); - init (); - register (this); - - /* Initialize the system font slot */ - systemFont = getSystemFont (); - } -} - -void checkCairo() { - if (CAIRO_LOADED) return; - try { - /* Check if cairo is available on the system */ - byte[] buffer = Converter.wcsToMbcs(null, "libcairo.so.2", true); - int /*long*/ libcairo = OS.dlopen(buffer, OS.RTLD_LAZY); - if (libcairo != 0) { - OS.dlclose(libcairo); - } else { - try { - System.loadLibrary("cairo-swt"); - } catch (UnsatisfiedLinkError e) { - /* Ignore problems loading the fallback library */ - } - } - Class.forName("org.eclipse.swt.internal.cairo.Cairo"); - CAIRO_LOADED = true; - } catch (Throwable t) { - SWT.error(SWT.ERROR_NO_GRAPHICS_LIBRARY, t, " [Cairo required]"); - } -} - -/** - * Throws an <code>SWTException</code> if the receiver can not - * be accessed by the caller. This may include both checks on - * the state of the receiver and more generally on the entire - * execution context. This method <em>should</em> be called by - * device implementors to enforce the standard SWT invariants. - * <p> - * Currently, it is an error to invoke any method (other than - * <code>isDisposed()</code> and <code>dispose()</code>) on a - * device that has had its <code>dispose()</code> method called. - * </p><p> - * In future releases of SWT, there may be more or fewer error - * checks and exceptions may be thrown for different reasons. - * <p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -protected void checkDevice () { - if (xDisplay == 0) SWT.error (SWT.ERROR_DEVICE_DISPOSED); -} - -/** - * Creates the device in the operating system. If the device - * does not have a handle, this method may do nothing depending - * on the device. - * <p> - * This method is called before <code>init</code>. - * </p><p> - * Subclasses are supposed to reimplement this method and not - * call the <code>super</code> implementation. - * </p> - * - * @param data the DeviceData which describes the receiver - * - * @see #init - */ -protected void create (DeviceData data) { -} - -synchronized static void deregister (Device device) { - for (int i=0; i<Devices.length; i++) { - if (device == Devices [i]) Devices [i] = null; - } -} - -/** - * Destroys the device in the operating system and releases - * the device's handle. If the device does not have a handle, - * this method may do nothing depending on the device. - * <p> - * This method is called after <code>release</code>. - * </p><p> - * Subclasses are supposed to reimplement this method and not - * call the <code>super</code> implementation. - * </p> - * - * @see #dispose - * @see #release - */ -protected void destroy () { -} - -/** - * Disposes of the operating system resources associated with - * the receiver. After this method has been invoked, the receiver - * will answer <code>true</code> when sent the message - * <code>isDisposed()</code>. - * - * @see #release - * @see #destroy - * @see #checkDevice - */ -public void dispose () { - synchronized (Device.class) { - if (isDisposed()) return; - checkDevice (); - release (); - destroy (); - deregister (this); - xDisplay = 0; - if (tracking) { - synchronized (trackingLock) { - objects = null; - errors = null; - trackingLock = null; - } - } - } -} - -void dispose_Object (Object object) { - synchronized (trackingLock) { - for (int i=0; i<objects.length; i++) { - if (objects [i] == object) { - objects [i] = null; - errors [i] = null; - return; - } - } - } -} - -static synchronized Device findDevice (int xDisplay) { - for (int i=0; i<Devices.length; i++) { - Device device = Devices [i]; - if (device != null && device.xDisplay == xDisplay) { - return device; - } - } - return null; -} - -/** - * Returns a rectangle describing the receiver's size and location. - * - * @return the bounding rectangle - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Rectangle getBounds () { - checkDevice (); - int screen = OS.XDefaultScreen (xDisplay); - int width = OS.XDisplayWidth (xDisplay, screen); - int height = OS.XDisplayHeight (xDisplay, screen); - return new Rectangle (0, 0, width, height); -} - -/** - * Returns a rectangle which describes the area of the - * receiver which is capable of displaying data. - * - * @return the client area - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #getBounds - */ -public Rectangle getClientArea () { - return getBounds (); -} - -/** - * Returns the bit depth of the screen, which is the number of - * bits it takes to represent the number of unique colors that - * the screen is currently capable of displaying. This number - * will typically be one of 1, 8, 15, 16, 24 or 32. - * - * @return the depth of the screen - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int getDepth () { - checkDevice (); - int xScreenPtr = OS.XDefaultScreenOfDisplay (xDisplay); - return OS.XDefaultDepthOfScreen (xScreenPtr); -} - -/** - * Returns a <code>DeviceData</code> based on the receiver. - * Modifications made to this <code>DeviceData</code> will not - * affect the receiver. - * - * @return a <code>DeviceData</code> containing the device's data and attributes - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see DeviceData - */ -public DeviceData getDeviceData () { - checkDevice (); - DeviceData data = new DeviceData (); - data.display_name = display_name; - data.application_name = application_name; - data.application_class = application_class; - data.debug = debug; - data.tracking = tracking; - if (tracking) { - synchronized (trackingLock) { - int count = 0, length = objects.length; - for (int i=0; i<length; i++) { - if (objects [i] != null) count++; - } - int index = 0; - data.objects = new Object [count]; - data.errors = new Error [count]; - for (int i=0; i<length; i++) { - if (objects [i] != null) { - data.objects [index] = objects [i]; - data.errors [index] = errors [i]; - index++; - } - } - } - } else { - data.objects = new Object [0]; - data.errors = new Error [0]; - } - return data; -} - -/** - * Returns a point whose x coordinate is the horizontal - * dots per inch of the display, and whose y coordinate - * is the vertical dots per inch of the display. - * - * @return the horizontal and vertical DPI - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Point getDPI () { - checkDevice (); - int xScreenNum = OS.XDefaultScreen (xDisplay); - int width = OS.XDisplayWidth (xDisplay, xScreenNum); - int height = OS.XDisplayHeight (xDisplay, xScreenNum); - int mmX = OS.XDisplayWidthMM (xDisplay, xScreenNum); - int mmY = OS.XDisplayHeightMM (xDisplay, xScreenNum); - /* 0.03937 mm/inch */ - double inchesX = mmX * 0.03937; - double inchesY = mmY * 0.03937; - int x = (int)((width / inchesX) + 0.5); - int y = (int)((height / inchesY) + 0.5); - return new Point (x, y); -} - -/** - * Returns <code>FontData</code> objects which describe - * the fonts that match the given arguments. If the - * <code>faceName</code> is null, all fonts will be returned. - * - * @param faceName the name of the font to look for, or null - * @param scalable if true only scalable fonts are returned, otherwise only non-scalable fonts are returned. - * @return the matching font data - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public FontData [] getFontList (String faceName, boolean scalable) { - checkDevice (); - String xlfd; - if (faceName == null) { - xlfd = "-*-*-*-*-*-*-*-*-*-*-*-*-*-*"; - } else { - int dashIndex = faceName.indexOf('-'); - if (dashIndex < 0) { - xlfd = "-*-" + faceName + "-*-*-*-*-*-*-*-*-*-*-*-*"; - } else { - xlfd = "-" + faceName + "-*-*-*-*-*-*-*-*-*-*-*-*"; - } - } - /* Use the character encoding for the default locale */ - byte [] buffer1 = Converter.wcsToMbcs (null, xlfd, true); - int [] ret = new int [1]; - int listPtr = OS.XListFonts (xDisplay, buffer1, 65535, ret); - int ptr = listPtr; - int [] intBuf = new int [1]; - FontData [] fd = new FontData [ret [0]]; - int fdIndex = 0; - for (int i = 0; i < ret [0]; i++) { - OS.memmove (intBuf, ptr, 4); - int charPtr = intBuf [0]; - int length = OS.strlen (charPtr); - byte [] buffer2 = new byte [length]; - OS.memmove (buffer2, charPtr, length); - /* Use the character encoding for the default locale */ - char [] chars = Converter.mbcsToWcs (null, buffer2); - try { - FontData data = FontData.motif_new (new String (chars)); - boolean isScalable = data.averageWidth == 0 && data.pixels == 0 && data.points == 0; - if (isScalable == scalable) { - fd [fdIndex++] = data; - } - } catch (Exception e) { - /* do not add the font to the list */ - } - ptr += 4; - } - OS.XFreeFontNames (listPtr); - if (fdIndex == ret [0]) return fd; - FontData [] result = new FontData [fdIndex]; - System.arraycopy (fd, 0, result, 0, fdIndex); - return result; -} - -/** - * Returns the matching standard color for the given - * constant, which should be one of the color constants - * specified in class <code>SWT</code>. Any value other - * than one of the SWT color constants which is passed - * in will result in the color black. This color should - * not be freed because it was allocated by the system, - * not the application. - * - * @param id the color constant - * @return the matching color - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see SWT - */ -public Color getSystemColor (int id) { - checkDevice (); - switch (id) { - case SWT.COLOR_BLACK: return COLOR_BLACK; - case SWT.COLOR_DARK_RED: return COLOR_DARK_RED; - case SWT.COLOR_DARK_GREEN: return COLOR_DARK_GREEN; - case SWT.COLOR_DARK_YELLOW: return COLOR_DARK_YELLOW; - case SWT.COLOR_DARK_BLUE: return COLOR_DARK_BLUE; - case SWT.COLOR_DARK_MAGENTA: return COLOR_DARK_MAGENTA; - case SWT.COLOR_DARK_CYAN: return COLOR_DARK_CYAN; - case SWT.COLOR_GRAY: return COLOR_GRAY; - case SWT.COLOR_DARK_GRAY: return COLOR_DARK_GRAY; - case SWT.COLOR_RED: return COLOR_RED; - case SWT.COLOR_GREEN: return COLOR_GREEN; - case SWT.COLOR_YELLOW: return COLOR_YELLOW; - case SWT.COLOR_BLUE: return COLOR_BLUE; - case SWT.COLOR_MAGENTA: return COLOR_MAGENTA; - case SWT.COLOR_CYAN: return COLOR_CYAN; - case SWT.COLOR_WHITE: return COLOR_WHITE; - } - return COLOR_BLACK; -} - -/** - * Returns a reasonable font for applications to use. - * On some platforms, this will match the "default font" - * or "system font" if such can be found. This font - * should not be freed because it was allocated by the - * system, not the application. - * <p> - * Typically, applications which want the default look - * should simply not set the font on the widgets they - * create. Widgets are always created with the correct - * default font for the class of user-interface component - * they represent. - * </p> - * - * @return a font - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Font getSystemFont () { - checkDevice (); - return systemFont; -} - -/** - * Returns <code>true</code> if the underlying window system prints out - * warning messages on the console, and <code>setWarnings</code> - * had previously been called with <code>true</code>. - * - * @return <code>true</code>if warnings are being handled, and <code>false</code> otherwise - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public boolean getWarnings () { - checkDevice (); - return _getWarnings(); -} - -boolean _getWarnings () { - return warnings; -} - -/** - * Initializes any internal resources needed by the - * device. - * <p> - * This method is called after <code>create</code>. - * </p><p> - * If subclasses reimplement this method, they must - * call the <code>super</code> implementation. - * </p> - * - * @see #create - */ -protected void init () { - if (debug) OS.XSynchronize (xDisplay, true); - - int[] event_basep = new int[1], error_basep = new int [1]; - if (OS.XRenderQueryExtension (xDisplay, event_basep, error_basep)) { - int[] major_versionp = new int[1], minor_versionp = new int [1]; - OS.XRenderQueryVersion (xDisplay, major_versionp, minor_versionp); - useXRender = major_versionp[0] > 0 || (major_versionp[0] == 0 && minor_versionp[0] >= 8); - } - - /* Create the warning and error callbacks */ - Class clazz = getClass (); - synchronized (clazz) { - if (XErrorCallback == null) { - XErrorCallback = new Callback (clazz, "XErrorProc", 2); - XNullErrorProc = XErrorCallback.getAddress (); - if (XNullErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - XErrorProc = OS.XSetErrorHandler (XNullErrorProc); - } - if (XIOErrorCallback == null) { - XIOErrorCallback = new Callback (clazz, "XIOErrorProc", 1); - XNullIOErrorProc = XIOErrorCallback.getAddress (); - if (XNullIOErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - XIOErrorProc = OS.XSetIOErrorHandler (XNullIOErrorProc); - } - } - xtWarningCallback = new Callback (this, "xtWarningProc", 1); - xtNullWarningProc = xtWarningCallback.getAddress (); - if (xtNullWarningProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - xtErrorCallback = new Callback (this, "xtErrorProc", 1); - xtNullErrorProc = xtErrorCallback.getAddress (); - if (xtNullErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - int xtContext = OS.XtDisplayToApplicationContext (xDisplay); - xtWarningProc = OS.XtAppSetWarningHandler (xtContext, xtNullWarningProc); - xtErrorProc = OS.XtAppSetErrorHandler (xtContext, xtNullErrorProc); - - /* Only use palettes for <= 8 bpp default visual */ - int xScreenPtr = OS.XDefaultScreenOfDisplay (xDisplay); - int defaultDepth = OS.XDefaultDepthOfScreen (xScreenPtr); - if (defaultDepth <= 8) { - int numColors = 1 << defaultDepth; - colorRefCount = new int [numColors]; - xcolors = new XColor [numColors]; - } - - /* - * The following colors are listed in the Windows - * Programmer's Reference as the colors in the default - * palette. - */ - COLOR_BLACK = new Color (this, 0,0,0); - COLOR_DARK_RED = new Color (this, 0x80,0,0); - COLOR_DARK_GREEN = new Color (this, 0,0x80,0); - COLOR_DARK_YELLOW = new Color (this, 0x80,0x80,0); - COLOR_DARK_BLUE = new Color (this, 0,0,0x80); - COLOR_DARK_MAGENTA = new Color (this, 0x80,0,0x80); - COLOR_DARK_CYAN = new Color (this, 0,0x80,0x80); - COLOR_GRAY = new Color (this, 0xC0,0xC0,0xC0); - COLOR_DARK_GRAY = new Color (this, 0x80,0x80,0x80); - COLOR_RED = new Color (this, 0xFF,0,0); - COLOR_GREEN = new Color (this, 0,0xFF,0); - COLOR_YELLOW = new Color (this, 0xFF,0xFF,0); - COLOR_BLUE = new Color (this, 0,0,0xFF); - COLOR_MAGENTA = new Color (this, 0xFF,0,0xFF); - COLOR_CYAN = new Color (this, 0,0xFF,0xFF); - COLOR_WHITE = new Color (this, 0xFF,0xFF,0xFF); - - int widgetClass = OS.topLevelShellWidgetClass (); - shellHandle = OS.XtAppCreateShell (null, null, widgetClass, xDisplay, null, 0); - if (shellHandle == 0) SWT.error(SWT.ERROR_NO_HANDLES); - - /* Create the parsing tables */ - byte[] tabBuffer = {(byte) '\t', 0}; - tabPointer = OS.XtMalloc (tabBuffer.length); - OS.memmove (tabPointer, tabBuffer, tabBuffer.length); - int tabString = OS.XmStringComponentCreate(OS.XmSTRING_COMPONENT_TAB, 0, null); - int [] argList = { - OS.XmNpattern, tabPointer, - OS.XmNsubstitute, tabString, - }; - tabMapping = OS.XmParseMappingCreate(argList, argList.length / 2); - OS.XmStringFree(tabString); - byte[] crBuffer = {(byte) '\n', 0}; - crPointer = OS.XtMalloc (crBuffer.length); - OS.memmove (crPointer, crBuffer, crBuffer.length); - int crString = OS.XmStringComponentCreate(OS.XmSTRING_COMPONENT_SEPARATOR, 0, null); - argList = new int[] { - OS.XmNpattern, crPointer, - OS.XmNsubstitute, crString, - }; - crMapping = OS.XmParseMappingCreate(argList, argList.length / 2); - OS.XmStringFree(crString); -} - -/** - * Invokes platform specific functionality to allocate a new GC handle. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>Device</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @param data the platform specific GC data - * @return the platform specific GC handle - */ -public abstract int internal_new_GC (GCData data); - -/** - * Invokes platform specific functionality to dispose a GC handle. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>Device</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @param hDC the platform specific GC handle - * @param data the platform specific GC data - */ -public abstract void internal_dispose_GC (int handle, GCData data); - -/** - * Returns <code>true</code> if the device has been disposed, - * and <code>false</code> otherwise. - * <p> - * This method gets the dispose state for the device. - * When a device has been disposed, it is an error to - * invoke any other method using the device. - * - * @return <code>true</code> when the device is disposed and <code>false</code> otherwise - */ -public boolean isDisposed () { - synchronized (Device.class) { - return xDisplay == 0; - } -} - -/** - * Loads the font specified by a file. The font will be - * present in the list of fonts available to the application. - * - * @param path the font file path - * @return whether the font was successfully loaded - * - * @exception SWTException <ul> - * <li>ERROR_NULL_ARGUMENT - if path is null</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see Font - * - * @since 3.3 - */ -public boolean loadFont (String path) { - checkDevice(); - if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - //TEMPORARY CODE - /*if (true)*/ return false; -// int index = path.lastIndexOf ("/"); -// if (index != -1) path = path.substring (0, index); -// int [] ndirs = new int [1]; -// int dirs = OS.XGetFontPath (xDisplay, ndirs); -// int [] ptr = new int [1]; -// for (int i = 0; i < ndirs [0]; i++) { -// OS.memmove (ptr, dirs + (i * 4), 4); -// int length = OS.strlen (ptr [0]); -// byte [] buffer = new byte [length]; -// OS.memmove (buffer, ptr [0], length); -// if (Converter.mbcsToWcs (null, buffer).equals (path)) { -// OS.XFreeFontPath (dirs); -// return true; -// } -// } -// int newDirs = OS.XtMalloc ((ndirs [0] + 1) * 4); -// int[] dirsBuffer = new int [ndirs [0] + 1]; -// OS.memmove (dirsBuffer, dirs, ndirs [0] * 4); -// byte[] buffer = Converter.wcsToMbcs (null, path, true); -// int pathPtr = OS.XtMalloc (buffer.length); -// OS.memmove (pathPtr, buffer, buffer.length); -// dirsBuffer [dirsBuffer.length - 1] = pathPtr; -// OS.memmove (newDirs, dirsBuffer, dirsBuffer.length * 4); -// OS.XSetFontPath (xDisplay, newDirs, dirsBuffer.length); -// OS.XFreeFontPath (dirs); -// OS.XFree (newDirs); -// OS.XFree (pathPtr); -// return true; -} - -void new_Object (Object object) { - synchronized (trackingLock) { - for (int i=0; i<objects.length; i++) { - if (objects [i] == null) { - objects [i] = object; - errors [i] = new Error (); - return; - } - } - Object [] newObjects = new Object [objects.length + 128]; - System.arraycopy (objects, 0, newObjects, 0, objects.length); - newObjects [objects.length] = object; - objects = newObjects; - Error [] newErrors = new Error [errors.length + 128]; - System.arraycopy (errors, 0, newErrors, 0, errors.length); - newErrors [errors.length] = new Error (); - errors = newErrors; - } -} - -static synchronized void register (Device device) { - for (int i=0; i<Devices.length; i++) { - if (Devices [i] == null) { - Devices [i] = device; - return; - } - } - Device [] newDevices = new Device [Devices.length + 4]; - System.arraycopy (Devices, 0, newDevices, 0, Devices.length); - newDevices [Devices.length] = device; - Devices = newDevices; -} - -/** - * Releases any internal resources back to the operating - * system and clears all fields except the device handle. - * <p> - * When a device is destroyed, resources that were acquired - * on behalf of the programmer need to be returned to the - * operating system. For example, if the device allocated a - * font to be used as the system font, this font would be - * freed in <code>release</code>. Also,to assist the garbage - * collector and minimize the amount of memory that is not - * reclaimed when the programmer keeps a reference to a - * disposed device, all fields except the handle are zero'd. - * The handle is needed by <code>destroy</code>. - * </p> - * This method is called before <code>destroy</code>. - * </p><p> - * If subclasses reimplement this method, they must - * call the <code>super</code> implementation. - * </p> - * - * @see #dispose - * @see #destroy - */ -protected void release () { - /* Free the parsing tables */ - OS.XtFree(tabPointer); - OS.XtFree(crPointer); - OS.XmParseMappingFree(tabMapping); - OS.XmParseMappingFree(crMapping); - tabPointer = crPointer = tabMapping = crMapping = 0; - - if (shellHandle != 0) OS.XtDestroyWidget (shellHandle); - shellHandle = 0; - - /* - * Free the palette. Note that this disposes all colors on - * the display that were allocated using the Color constructor. - */ - if (xcolors != null) { - int xScreen = OS.XDefaultScreen (xDisplay); - int xColormap = OS.XDefaultColormap (xDisplay, xScreen); - int [] pixel = new int [1]; - for (int i = 0; i < xcolors.length; i++) { - XColor color = xcolors [i]; - if (color != null) { - pixel [0] = color.pixel; - while (colorRefCount [i] > 0) { - OS.XFreeColors (xDisplay, xColormap, pixel, 1, 0); - --colorRefCount [i]; - } - } - } - } - xcolors = null; - colorRefCount = null; - - if (COLOR_BLACK != null) COLOR_BLACK.dispose(); - if (COLOR_DARK_RED != null) COLOR_DARK_RED.dispose(); - if (COLOR_DARK_GREEN != null) COLOR_DARK_GREEN.dispose(); - if (COLOR_DARK_YELLOW != null) COLOR_DARK_YELLOW.dispose(); - if (COLOR_DARK_BLUE != null) COLOR_DARK_BLUE.dispose(); - if (COLOR_DARK_MAGENTA != null) COLOR_DARK_MAGENTA.dispose(); - if (COLOR_DARK_CYAN != null) COLOR_DARK_CYAN.dispose(); - if (COLOR_GRAY != null) COLOR_GRAY.dispose(); - if (COLOR_DARK_GRAY != null) COLOR_DARK_GRAY.dispose(); - if (COLOR_RED != null) COLOR_RED.dispose(); - if (COLOR_GREEN != null) COLOR_GREEN.dispose(); - if (COLOR_YELLOW != null) COLOR_YELLOW.dispose(); - if (COLOR_BLUE != null) COLOR_BLUE.dispose(); - if (COLOR_MAGENTA != null) COLOR_MAGENTA.dispose(); - if (COLOR_CYAN != null) COLOR_CYAN.dispose(); - if (COLOR_WHITE != null) COLOR_WHITE.dispose(); - COLOR_BLACK = COLOR_DARK_RED = COLOR_DARK_GREEN = COLOR_DARK_YELLOW = - COLOR_DARK_BLUE = COLOR_DARK_MAGENTA = COLOR_DARK_CYAN = COLOR_GRAY = COLOR_DARK_GRAY = COLOR_RED = - COLOR_GREEN = COLOR_YELLOW = COLOR_BLUE = COLOR_MAGENTA = COLOR_CYAN = COLOR_WHITE = null; - - /* Free the Xt error handler */ - int xtContext = OS.XtDisplayToApplicationContext (xDisplay); - OS.XtAppSetErrorHandler (xtContext, xtErrorProc); - xtErrorCallback.dispose (); xtErrorCallback = null; - xtNullErrorProc = xtErrorProc = 0; - - /* Free the Xt Warning handler */ - OS.XtAppSetWarningHandler (xtContext, xtWarningProc); - xtWarningCallback.dispose (); xtWarningCallback = null; - xtNullWarningProc = xtWarningProc = 0; - - int count = 0; - for (int i = 0; i < Devices.length; i++){ - if (Devices [i] != null) count++; - } - if (count == 1) { - /* Free the X IO error handler */ - OS.XSetIOErrorHandler (XIOErrorProc); - XIOErrorCallback.dispose (); XIOErrorCallback = null; - XNullIOErrorProc = XIOErrorProc = 0; - - /* Free the X error handler */ - /* - * Bug in Motif. For some reason, when a pixmap is - * set into a button or label, despite the fact that - * the pixmap is cleared from the widget before it - * is disposed, Motif still references the pixmap - * and attempts to dispose it in XtDestroyApplicationContext(). - * The fix is to avoid warnings by leaving our handler - * and settings warnings to false. - * - * NOTE: The warning callback is leaked. - */ - warnings = false; -// OS.XSetErrorHandler (XErrorProc); -// XErrorCallback.dispose (); XErrorCallback = null; -// XNullErrorProc = XErrorProc = 0; - } -} - -/** - * If the underlying window system supports printing warning messages - * to the console, setting warnings to <code>false</code> prevents these - * messages from being printed. If the argument is <code>true</code> then - * message printing is not blocked. - * - * @param warnings <code>true</code>if warnings should be printed, and <code>false</code> otherwise - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setWarnings (boolean warnings) { - checkDevice (); - _setWarnings(warnings); -} - -void _setWarnings (boolean warnings) { - this.warnings = warnings; -} - -static int XErrorProc (int xDisplay, int xErrorEvent) { - Device device = findDevice (xDisplay); - if (device != null) { - if (device.warnings) { - if (DEBUG || device.debug) { - new SWTError ().printStackTrace (); - } - OS.Call (XErrorProc, xDisplay, xErrorEvent); - } - } else { - if (DEBUG) new SWTError ().printStackTrace (); - OS.Call (XErrorProc, xDisplay, xErrorEvent); - } - return 0; -} - -static int XIOErrorProc (int xDisplay) { - Device device = findDevice (xDisplay); - if (device != null) { - if (DEBUG || device.debug) { - new SWTError ().printStackTrace (); - } - } else { - if (DEBUG) new SWTError ().printStackTrace (); - } - OS.Call (XIOErrorProc, xDisplay, 0); - return 0; -} - -int xtErrorProc (int message) { - if (DEBUG || debug) { - new SWTError ().printStackTrace (); - } - OS.Call (xtErrorProc, message, 0); - return 0; -} - -int xtWarningProc (int message) { - if (warnings) { - if (DEBUG || debug) { - new SWTError ().printStackTrace (); - } - OS.Call (xtWarningProc, message, 0); - } - return 0; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/DeviceData.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/DeviceData.java deleted file mode 100755 index ac1c73cf34..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/DeviceData.java +++ /dev/null @@ -1,30 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2005 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - - -public class DeviceData { - /* - * Motif only fields. - */ - public String display_name; - public String application_name; - public String application_class; - - /* - * Debug fields - may not be honoured - * on some SWT platforms. - */ - public boolean debug; - public boolean tracking; - public Error [] errors; - public Object [] objects; -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Font.java deleted file mode 100755 index d5b38499bd..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Font.java +++ /dev/null @@ -1,536 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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.motif.*; -import org.eclipse.swt.*; - -/** - * Instances of this class manage operating system resources that - * define how text looks when it is displayed. Fonts may be constructed - * by providing a device and either name, size and style information - * or a <code>FontData</code> object which encapsulates this data. - * <p> - * Application code must explicitly invoke the <code>Font.dispose()</code> - * method to release the operating system resources managed by each instance - * when those instances are no longer required. - * </p> - * - * @see FontData - * @see <a href="http://www.eclipse.org/swt/snippets/#font">Font snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, PaintExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public final class Font extends Resource { - /** - * the handle to the OS font resource - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public int handle; - - /** - * the code page of the font - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - * - * @since 2.0 - */ - public String codePage; - -Font (Device device) { - super(device); -} - -/** - * Constructs a new font given a device and font data - * which describes the desired font's appearance. - * <p> - * You must dispose the font when it is no longer required. - * </p> - * - * @param device the device to create the font on - * @param fd the FontData that describes the desired font (must not be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_NULL_ARGUMENT - if the fd argument is null</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li> - * </ul> - */ -public Font (Device device, FontData fd) { - super(device); - if (fd == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - init(new FontData[] {fd}); - init(); -} - -/** - * Constructs a new font given a device and an array - * of font data which describes the desired font's - * appearance. - * <p> - * You must dispose the font when it is no longer required. - * </p> - * - * @param device the device to create the font on - * @param fds the array of FontData that describes the desired font (must not be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_NULL_ARGUMENT - if the fds argument is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the length of fds is zero</li> - * <li>ERROR_NULL_ARGUMENT - if any fd in the array is null</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li> - * </ul> - * - * @since 2.1 - */ -public Font (Device device, FontData[] fds) { - super(device); - if (fds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (fds.length == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - for (int i=0; i<fds.length; i++) { - if (fds[i] == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - } - init(fds); - init(); -} - -/** - * Constructs a new font given a device, a font name, - * the height of the desired font in points, and a font - * style. - * <p> - * You must dispose the font when it is no longer required. - * </p> - * - * @param device the device to create the font on - * @param name the name of the font (must not be null) - * @param height the font height in points - * @param style a bit or combination of NORMAL, BOLD, ITALIC - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_NULL_ARGUMENT - if the name argument is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES - if a font could not be created from the given arguments</li> - * </ul> - */ -public Font (Device device, String name, int height, int style) { - super(device); - if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - init(new FontData[]{new FontData(name, height, style)}); - init(); -} - -/*public*/ Font (Device device, String name, float height, int style) { - super(device); - if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - init(new FontData[]{new FontData(name, height, style)}); - init(); -} - -void destroy() { - if (handle == device.systemFont.handle) return; - OS.XmFontListFree (handle); - handle = 0; -} - -/** - * Compares the argument to the receiver, and returns true - * if they represent the <em>same</em> object using a class - * specific comparison. - * - * @param object the object to compare with this object - * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise - * - * @see #hashCode - */ -public boolean equals (Object object) { - if (object == this) return true; - if (!(object instanceof Font)) return false; - Font font = (Font)object; - return device == font.device && handle == font.handle; -} - -/** - * Returns the code page for the specified font list. - * - * @return the code page for the font list - */ -static String getCodePage (int xDisplay, int fontList) { - int[] buffer = new int[1]; - if (!OS.XmFontListInitFontContext(buffer, fontList)) return null; - int context = buffer[0]; - XFontStruct fontStruct = new XFontStruct(); - int fontListEntry; - String codePage = null; - /* Go through each entry in the font list */ - while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) { - int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer); - if (buffer[0] == OS.XmFONT_IS_FONT) { - /* FontList contains a single font */ - OS.memmove(fontStruct,fontPtr,20 * 4); - int propPtr = fontStruct.properties; - for (int i = 0; i < fontStruct.n_properties; i++) { - /* Look through properties for XAFONT */ - int[] prop = new int[2]; - OS.memmove(prop, propPtr, 8); - if (prop[0] == OS.XA_FONT) { - /* Found it, prop[1] points to the string */ - int ptr = OS.XmGetAtomName(xDisplay, prop[1]); - int length = OS.strlen(ptr); - byte[] nameBuf = new byte[length]; - OS.memmove(nameBuf, ptr, length); - /* Use the character encoding for the default locale */ - String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase(); - int start = xlfd.lastIndexOf ('-'); - if (start != -1 && start > 0) { - start = xlfd.lastIndexOf ('-', start - 1); - if (start != -1) { - codePage = xlfd.substring (start + 1, xlfd.length ()); - if (codePage.indexOf ("iso") == 0) { - if (OS.IsLinux) { - codePage = "ISO-" + codePage.substring (3, codePage.length ()); - } - if (OS.IsAIX) { - codePage = "ISO" + codePage.substring (3, codePage.length ()); - } - if (OS.IsHPUX) { - start = codePage.lastIndexOf('-'); - if (start != -1) { - codePage = codePage.substring (0, start) + codePage.substring (start + 1, codePage.length ()); - } - } - } - } - } - OS.XtFree(ptr); - break; - } - propPtr += 8; - } - } - else { - /* FontList contains a fontSet */ - - /* Get the font set locale */ - int localePtr = OS.XLocaleOfFontSet(fontPtr); - int length = OS.strlen (localePtr); - byte [] locale = new byte [length + 1]; - OS.memmove (locale, localePtr, length); - - /* Get code page for the font set locale */ - OS.setlocale (OS.LC_CTYPE, locale); - int codesetPtr = OS.nl_langinfo (OS.CODESET); - length = OS.strlen (codesetPtr); - byte [] codeset = new byte [length]; - OS.memmove (codeset, codesetPtr, length); - codePage = new String(Converter.mbcsToWcs(null, codeset)); - - /* Reset the locale */ - OS.setlocale (OS.LC_CTYPE, new byte[1]); - } - } - OS.XmFontListFreeFontContext(context); - return codePage; -} - -/** - * Returns an array of <code>FontData</code>s representing the receiver. - * On Windows, only one FontData will be returned per font. On X however, - * a <code>Font</code> object <em>may</em> be composed of multiple X - * fonts. To support this case, we return an array of font data objects. - * - * @return an array of font data objects describing the receiver - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public FontData[] getFontData() { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - int xDisplay = device.xDisplay; - /* - * Create a font context to iterate over each element in the font list. - */ - int[] buffer = new int[1]; - if (!OS.XmFontListInitFontContext(buffer, handle)) { - SWT.error (SWT.ERROR_INVALID_FONT); - } - int context = buffer[0]; - XFontStruct fontStruct = new XFontStruct(); - int fontListEntry; - int[] fontStructPtr = new int[1]; - int[] fontNamePtr = new int[1]; - FontData[] data = new FontData[0]; - try { - /* Go through each entry in the font list */ - while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) { - int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer); - if (buffer[0] == OS.XmFONT_IS_FONT) { - /* FontList contains a single font */ - OS.memmove(fontStruct,fontPtr,20 * 4); - int propPtr = fontStruct.properties; - for (int i = 0; i < fontStruct.n_properties; i++) { - /* Look through properties for XAFONT */ - int[] prop = new int[2]; - OS.memmove(prop, propPtr, 8); - if (prop[0] == OS.XA_FONT) { - /* Found it, prop[1] points to the string */ - int ptr = OS.XmGetAtomName(xDisplay, prop[1]); - int length = OS.strlen(ptr); - byte[] nameBuf = new byte[length]; - OS.memmove(nameBuf, ptr, length); - OS.XtFree(ptr); - /* Use the character encoding for the default locale */ - String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase(); - /* Add the xlfd to the array */ - FontData[] newData = new FontData[data.length + 1]; - System.arraycopy(data, 0, newData, 0, data.length); - newData[newData.length - 1] = FontData.motif_new(xlfd); - data = newData; - break; - } - propPtr += 8; - } - } - else { - /* FontList contains a fontSet */ - int nFonts = OS.XFontsOfFontSet(fontPtr,fontStructPtr,fontNamePtr); - int [] fontStructs = new int[nFonts]; - OS.memmove(fontStructs,fontStructPtr[0],nFonts * 4); - for (int i = 0; i < nFonts; i++) { // Go through each fontStruct in the font set. - OS.memmove(fontStruct,fontStructs[i],20 * 4); - int propPtr = fontStruct.properties; - for (int j = 0; j < fontStruct.n_properties; j++) { - // Look through properties for XAFONT - int[] prop = new int[2]; - OS.memmove(prop, propPtr, 8); - if (prop[0] == OS.XA_FONT) { - /* Found it, prop[1] points to the string */ - int ptr = OS.XmGetAtomName(xDisplay, prop[1]); - int length = OS.strlen(ptr); - byte[] nameBuf = new byte[length]; - OS.memmove(nameBuf, ptr, length); - OS.XFree(ptr); - String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase(); - /* Add the xlfd to the array */ - FontData[] newData = new FontData[data.length + 1]; - System.arraycopy(data, 0, newData, 0, data.length); - try { - newData[newData.length - 1] = FontData.motif_new(xlfd); - } catch (Exception e) { - /* - * Some font servers, for example, xfstt, do not pass - * reasonable font properties to the client, so we - * cannot construct a FontData for these. Try to use - * the font name instead. - */ - int[] fontName = new int[1]; - OS.memmove(fontName, fontNamePtr [0] + (i * 4), 4); - ptr = fontName[0]; - if (ptr != 0) { - length = OS.strlen(ptr); - nameBuf = new byte[length]; - OS.memmove(nameBuf, ptr, length); - xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase(); - newData[newData.length - 1] = FontData.motif_new(xlfd); - } - } - data = newData; - break; - } - propPtr += 8; - } - } - } - } - if (data.length == 0) SWT.error (SWT.ERROR_INVALID_FONT); - } catch (Exception e) { - /* - * Some font servers, for example, xfstt, do not pass - * reasonable font properties to the client, so we - * cannot construct a FontData for these. - */ - SWT.error (SWT.ERROR_INVALID_FONT); - } finally { - OS.XmFontListFreeFontContext(context); - } - return data; -} - -/** - * Returns an integer hash code for the receiver. Any two - * objects that return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals - */ -public int hashCode () { - return handle; -} - -void init (FontData[] fds) { - /* Change current locale if needed. Note: only the first font data is used */ - FontData firstFd = fds[0]; - if (firstFd.lang != null) { - String lang = firstFd.lang; - String country = firstFd.country; - String variant = firstFd.variant; - String osLocale = lang; - if (country != null) osLocale += "_" + country; - if (variant != null) osLocale += "." + variant; - int length = osLocale.length(); - byte [] buffer = new byte[length + 1]; - for (int i=0; i<length; i++) { - buffer[i] = (byte)osLocale.charAt(i); - } - OS.setlocale (OS.LC_CTYPE, buffer); - } - - int fontType = OS.XmFONT_IS_FONTSET; - /* - * Bug in HPUX. If the locale is "C" then FontSets do not work - * properly. The fix is to detect this case and use a Font struct - * instead. - */ - if (OS.IsHPUX) { - int localePtr = OS.setlocale(OS.LC_CTYPE, null); - int length = OS.strlen(localePtr); - byte[] buffer = new byte[length]; - OS.memmove(buffer, localePtr, length); - if ("C".equals(new String(Converter.mbcsToWcs(null, buffer)))) { - fontType = OS.XmFONT_IS_FONT; - } - } - - /* Generate desire font name */ - Point dpi = null; - if (device.setDPI) dpi = device.getDPI(); - StringBuffer stringBuffer = new StringBuffer(); - for (int i = 0; i < fds.length; i++) { - if (i != 0) stringBuffer.append(','); - FontData fd = fds[i]; - int hRes = fd.horizontalResolution, vRes = fd.verticalResolution; - if (dpi != null) { - fd.horizontalResolution = dpi.x; - fd.verticalResolution = dpi.y; - } - stringBuffer.append(fd.getXlfd()); - fd.horizontalResolution = hRes; - fd.verticalResolution = vRes; - } - - /* Append simplified font name */ - FontData newFd = new FontData(); - newFd.points = firstFd.points; - /* - * Bug in Motif. In Japanese AIX only, in some cases loading a bold Japanese - * font takes a very long time (10 minutes) when there are no Japanese bold - * fonts available. The fix is to wildcard the field weight. - */ - if (fontType == OS.XmFONT_IS_FONTSET) { - if (OS.IsAIX && OS.IsDBLocale) { - stringBuffer.append(','); - stringBuffer.append(newFd.getXlfd()); - } else { - newFd.weight = firstFd.weight; - newFd.slant = firstFd.slant; - stringBuffer.append(','); - stringBuffer.append(newFd.getXlfd()); - newFd.weight = null; - newFd.slant = null; - stringBuffer.append(','); - stringBuffer.append(newFd.getXlfd()); - } - } - - /* Load font list entry */ - boolean warnings = device._getWarnings (); - device._setWarnings (false); - byte[] buffer = Converter.wcsToMbcs(null, stringBuffer.toString() , true); - int fontListEntry = OS.XmFontListEntryLoad(device.xDisplay, buffer, fontType, OS.XmFONTLIST_DEFAULT_TAG); - device._setWarnings (warnings); - if (fontListEntry != 0) { - handle = OS.XmFontListAppendEntry(0, fontListEntry); - OS.XmFontListEntryFree(new int[]{fontListEntry}); - int codesetPtr = OS.nl_langinfo(OS.CODESET); - int length = OS.strlen(codesetPtr); - buffer = new byte[length]; - OS.memmove(buffer, codesetPtr, length); - codePage = new String(Converter.mbcsToWcs(null, buffer)); - } else { - Font systemFont = device.systemFont; - handle = systemFont.handle; - codePage = systemFont.codePage; - } - - /* Reset current locale if needed */ - if (firstFd.lang != null) OS.setlocale(OS.LC_CTYPE, new byte[0]); - - if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); -} - -/** - * Returns <code>true</code> if the font has been disposed, - * and <code>false</code> otherwise. - * <p> - * This method gets the dispose state for the font. - * When a font has been disposed, it is an error to - * invoke any other method using the font. - * - * @return <code>true</code> when the font is disposed and <code>false</code> otherwise - */ -public boolean isDisposed() { - return handle == 0; -} - -public static Font motif_new(Device device, int handle) { - Font font = new Font(device); - font.handle = handle; - font.codePage = getCodePage(device.xDisplay, handle); - return font; -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the receiver - */ -public String toString () { - if (isDisposed()) return "Font {*DISPOSED*}"; - return "Font {" + handle + "}"; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java deleted file mode 100755 index 6f50eb10b8..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java +++ /dev/null @@ -1,669 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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.*; - -/** - * Instances of this class describe operating system fonts. - * <p> - * For platform-independent behaviour, use the get and set methods - * corresponding to the following properties: - * <dl> - * <dt>height</dt><dd>the height of the font in points</dd> - * <dt>name</dt><dd>the face name of the font, which may include the foundry</dd> - * <dt>style</dt><dd>A bitwise combination of NORMAL, ITALIC and BOLD</dd> - * </dl> - * If extra, platform-dependent functionality is required: - * <ul> - * <li>On <em>Windows</em>, the data member of the <code>FontData</code> - * corresponds to a Windows <code>LOGFONT</code> structure whose fields - * may be retrieved and modified.</li> - * <li>On <em>X</em>, the fields of the <code>FontData</code> correspond - * to the entries in the font's XLFD name and may be retrieved and modified. - * </ul> - * Application code does <em>not</em> need to explicitly release the - * resources managed by each instance when those instances are no longer - * required, and thus no <code>dispose()</code> method is provided. - * - * @see Font - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public final class FontData { - /** - * The company that produced the font - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public String foundry; - /** - * The common name of the font - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public String fontFamily; - /** - * The weight ("medium", "bold") - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public String weight; - /** - * The slant ("o" for oblique, "i" for italic) - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public String slant; - /** - * The set width of the font - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public String setWidth; - /** - * Additional font styles - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public String addStyle; - /** - * The height of the font in pixels - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public int pixels; - /** - * The height of the font in tenths of a point - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public int points; - /** - * The horizontal screen resolution for which the font was designed - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public int horizontalResolution; - /** - * The vertical screen resolution for which the font was designed - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public int verticalResolution; - /** - * The font spacing ("m" for monospace, "p" for proportional) - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public String spacing; - /** - * The average character width for the font - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public int averageWidth; - /** - * The ISO character set registry - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public String characterSetRegistry; - /** - * The ISO character set name - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public String characterSetName; - - /** - * The locales of the font - */ - String lang, country, variant; -/** - * Constructs a new uninitialized font data. - */ -public FontData () { -} -/** - * Constructs a new FontData given a string representation - * in the form generated by the <code>FontData.toString</code> - * method. - * <p> - * Note that the representation varies between platforms, - * and a FontData can only be created from a string that was - * generated on the same platform. - * </p> - * - * @param string the string representation of a <code>FontData</code> (must not be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the argument does not represent a valid description</li> - * </ul> - * - * @see #toString - */ -public FontData(String string) { - if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - int start = 0; - int end = string.indexOf('|'); - if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT); - String version1 = string.substring(start, end); - try { - if (Integer.parseInt(version1) != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } catch (NumberFormatException e) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - - start = end + 1; - end = string.indexOf('|', start); - if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT); - String name = string.substring(start, end); - - start = end + 1; - end = string.indexOf('|', start); - if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT); - float height = 0; - try { - height = Float.parseFloat(string.substring(start, end)); - } catch (NumberFormatException e) { - SWT.error(SWT.ERROR_NULL_ARGUMENT); - } - - start = end + 1; - end = string.indexOf('|', start); - if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT); - int style = 0; - try { - style = Integer.parseInt(string.substring(start, end)); - } catch (NumberFormatException e) { - SWT.error(SWT.ERROR_NULL_ARGUMENT); - } - - start = end + 1; - end = string.indexOf('|', start); - if (end == -1) { - setName(name); - setHeight(height); - setStyle(style); - return; - } - String platform = string.substring(start, end); - - start = end + 1; - end = string.indexOf('|', start); - if (end == -1) { - setName(name); - setHeight(height); - setStyle(style); - return; - } - String version2 = string.substring(start, end); - - if (platform.equals("MOTIF") && version2.equals("1")) { - start = end + 1; - end = string.length(); - if (end == -1) { - setName(name); - setHeight(height); - setStyle(style); - return; - } - String xlfd = string.substring(start, end); - setXlfd(xlfd); - return; - } - setName(name); - setHeight(height); - setStyle(style); -} -/** - * Constructs a new font data given a font name, - * the height of the desired font in points, - * and a font style. - * - * @param name the name of the font (must not be null) - * @param height the font height in points - * @param style a bit or combination of NORMAL, BOLD, ITALIC - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - when the font name is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li> - * </ul> - */ -public FontData (String name, int height, int style) { - if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - int dash = name.indexOf('-'); - if (dash != -1) { - foundry = name.substring(0, dash); - fontFamily = name.substring(dash + 1); - } else { - fontFamily = name; - } - points = height * 10; - weight = (style & SWT.BOLD) != 0 ? "bold" : "medium"; - slant = (style & SWT.ITALIC) != 0 ? "i" : "r"; -} -/*public*/ FontData (String name, float height, int style) { - if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - int dash = name.indexOf('-'); - if (dash != -1) { - foundry = name.substring(0, dash); - fontFamily = name.substring(dash + 1); - } else { - fontFamily = name; - } - points = (int)(height * 10); - weight = (style & SWT.BOLD) != 0 ? "bold" : "medium"; - slant = (style & SWT.ITALIC) != 0 ? "i" : "r"; -} -/** - * Compares the argument to the receiver, and returns true - * if they represent the <em>same</em> object using a class - * specific comparison. - * - * @param object the object to compare with this object - * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise - * - * @see #hashCode - */ -public boolean equals (Object object) { - return (object == this) || ((object instanceof FontData) && - getXlfd().equals(((FontData)object).getXlfd())); -} -/** - * Returns the height of the receiver in points. - * - * @return the height of this FontData - * - * @see #setHeight(int) - */ -public int getHeight() { - return points / 10; -} -/*public*/ float getHeightF() { - return points / 10f; -} -/** - * Returns the locale of the receiver. - * <p> - * The locale determines which platform character set this - * font is going to use. Widgets and graphics operations that - * use this font will convert UNICODE strings to the platform - * character set of the specified locale. - * </p> - * <p> - * On platforms where there are multiple character sets for a - * given language/country locale, the variant portion of the - * locale will determine the character set. - * </p> - * - * @return the <code>String</code> representing a Locale object - * @since 3.0 - */ -public String getLocale () { - StringBuffer buffer = new StringBuffer (); - char sep = '_'; - if (lang != null) { - buffer.append (lang); - buffer.append (sep); - } - if (country != null) { - buffer.append (country); - buffer.append (sep); - } - if (variant != null) { - buffer.append (variant); - } - - String result = buffer.toString (); - int length = result.length (); - if (length > 0) { - if (result.charAt (length - 1) == sep) { - result = result.substring (0, length - 1); - } - } - return result; -} -/** - * Returns the name of the receiver. - * On platforms that support font foundries, the return value will - * be the foundry followed by a dash ("-") followed by the face name. - * - * @return the name of this <code>FontData</code> - * - * @see #setName - */ -public String getName() { - StringBuffer buffer = new StringBuffer(); - if (foundry != null) { - buffer.append(foundry); - buffer.append("-"); - } - if (fontFamily != null) buffer.append(fontFamily); - return buffer.toString(); -} -/** - * Returns the style of the receiver which is a bitwise OR of - * one or more of the <code>SWT</code> constants NORMAL, BOLD - * and ITALIC. - * - * @return the style of this <code>FontData</code> - * - * @see #setStyle - */ -public int getStyle() { - int style = 0; - if (weight != null && weight.equals("bold")) style |= SWT.BOLD; - if (slant != null && slant.equals("i")) style |= SWT.ITALIC; - return style; -} -String getXlfd() { - String s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14; - s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = s9 = s10 = s11 = s12 = s13 = s14 = "*"; - - if (foundry != null) s1 = foundry; - if (fontFamily != null) s2 = fontFamily; - if (weight != null) s3 = weight; - if (slant != null) s4 = slant; - if (setWidth != null) s5 = setWidth; - if (addStyle != null) s6 = addStyle; - if (pixels != 0) s7 = Integer.toString(pixels); - if (points != 0) s8 = Integer.toString(points); - if (horizontalResolution != 0) s9 = Integer.toString(horizontalResolution); - if (verticalResolution != 0) s10 = Integer.toString(verticalResolution); - if (spacing != null) s11 = spacing; - if (averageWidth != 0) s12 = Integer.toString(averageWidth); - if (characterSetRegistry != null) s13 = characterSetRegistry; - if (characterSetName != null) s14 = characterSetName; - - return "-" + s1+ "-" + s2 + "-" + s3 + "-" + s4 + "-" + s5 + "-" + s6 + "-" + s7 + "-" + s8 + "-" - + s9 + "-" + s10 + "-" + s11 + "-" + s12 + "-" + s13 + "-" + s14; -} -/** - * Returns an integer hash code for the receiver. Any two - * objects that return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals - */ -public int hashCode () { - return getXlfd().hashCode(); -} -public static FontData motif_new(String xlfd) { - FontData fontData = new FontData(); - fontData.setXlfd(xlfd); - return fontData; -} -/** - * Sets the height of the receiver. The parameter is - * specified in terms of points, where a point is one - * seventy-second of an inch. - * - * @param height the height of the <code>FontData</code> - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li> - * </ul> - * - * @see #getHeight - */ -public void setHeight(int height) { - if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - points = height * 10; -} -/*public*/ void setHeight(float height) { - if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - points = (int)(height * 10); -} -/** - * Sets the name of the receiver. - * <p> - * Some platforms support font foundries. On these platforms, the name - * of the font specified in setName() may have one of the following forms: - * <ol> - * <li>a face name (for example, "courier")</li> - * <li>a foundry followed by a dash ("-") followed by a face name (for example, "adobe-courier")</li> - * </ol> - * In either case, the name returned from getName() will include the - * foundry. - * </p> - * <p> - * On platforms that do not support font foundries, only the face name - * (for example, "courier") is used in <code>setName()</code> and - * <code>getName()</code>. - * </p> - * - * @param name the name of the font data (must not be null) - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - when the font name is null</li> - * </ul> - * - * @see #getName - */ -public void setName(String name) { - if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - int dash = name.indexOf('-'); - if (dash != -1) { - foundry = name.substring(0, dash); - fontFamily = name.substring(dash + 1); - } else { - fontFamily = name; - } -} -/** - * Sets the locale of the receiver. - * <p> - * The locale determines which platform character set this - * font is going to use. Widgets and graphics operations that - * use this font will convert UNICODE strings to the platform - * character set of the specified locale. - * </p> - * <p> - * On platforms where there are multiple character sets for a - * given language/country locale, the variant portion of the - * locale will determine the character set. - * </p> - * - * @param locale the <code>String</code> representing a Locale object - * @see java.util.Locale#toString - */ -public void setLocale(String locale) { - lang = country = variant = null; - if (locale != null) { - char sep = '_'; - int length = locale.length(); - int firstSep, secondSep; - - firstSep = locale.indexOf(sep); - if (firstSep == -1) { - firstSep = secondSep = length; - } else { - secondSep = locale.indexOf(sep, firstSep + 1); - if (secondSep == -1) secondSep = length; - } - if (firstSep > 0) lang = locale.substring(0, firstSep); - if (secondSep > firstSep + 1) country = locale.substring(firstSep + 1, secondSep); - if (length > secondSep + 1) variant = locale.substring(secondSep + 1); - } -} -/** - * Sets the style of the receiver to the argument which must - * be a bitwise OR of one or more of the <code>SWT</code> - * constants NORMAL, BOLD and ITALIC. All other style bits are - * ignored. - * - * @param style the new style for this <code>FontData</code> - * - * @see #getStyle - */ -public void setStyle(int style) { - weight = (style & SWT.BOLD) != 0 ? "bold" : "medium"; - slant = (style & SWT.ITALIC) != 0 ? "i" : "r"; - averageWidth = 0; -} -void setXlfd(String xlfd) { - int start, stop; - start = 1; - stop = xlfd.indexOf ("-", start); - foundry = xlfd.substring(start, stop); - if (foundry.equals("*")) foundry = null; - start = stop + 1; - stop = xlfd.indexOf ("-", start); - fontFamily = xlfd.substring(start, stop); - if (fontFamily.equals("*")) fontFamily = null; - start = stop + 1; - stop = xlfd.indexOf ("-", start); - weight = xlfd.substring(start, stop); - if (weight.equals("*")) weight = null; - start = stop + 1; - stop = xlfd.indexOf ("-", start); - slant = xlfd.substring(start, stop); - if (slant.equals("*")) slant = null; - start = stop + 1; - stop = xlfd.indexOf ("-", start); - setWidth = xlfd.substring(start, stop); - if (setWidth.equals("*")) setWidth = null; - start = stop + 1; - stop = xlfd.indexOf ("-", start); - addStyle = xlfd.substring(start, stop); - if (addStyle.equals("*")) addStyle = null; - start = stop + 1; - stop = xlfd.indexOf ("-", start); - String s = xlfd.substring(start, stop); - if (!s.equals("") && !s.equals("*")) - pixels = Integer.parseInt(s); - start = stop + 1; - stop = xlfd.indexOf ("-", start); - s = xlfd.substring(start, stop); - if (!s.equals("") && !s.equals("*")) - points = Integer.parseInt(s); - start = stop + 1; - stop = xlfd.indexOf ("-", start); - s = xlfd.substring(start, stop); - if (!s.equals("") && !s.equals("*")) - horizontalResolution = Integer.parseInt(s); - start = stop + 1; - stop = xlfd.indexOf ("-", start); - s = xlfd.substring(start, stop); - if (!s.equals("") && !s.equals("*")) - verticalResolution = Integer.parseInt(s); - start = stop + 1; - stop = xlfd.indexOf ("-", start); - spacing = xlfd.substring(start, stop); - start = stop + 1; - stop = xlfd.indexOf ("-", start); - s = xlfd.substring(start, stop); - if (!s.equals("") && !s.equals("*")) { - if (s.startsWith ("~")) { - s = "-" + s.substring(1); - } - averageWidth = Integer.parseInt(s); - } - start = stop + 1; - stop = xlfd.indexOf ("-", start); - characterSetRegistry = xlfd.substring(start, stop); - if (characterSetRegistry.equals("*")) characterSetRegistry = null; - start = stop + 1; - stop = xlfd.indexOf ("-", start); - characterSetName = xlfd.substring(start); - if (characterSetName.equals("*")) characterSetName = null; -} -/** - * Returns a string representation of the receiver which is suitable - * for constructing an equivalent instance using the - * <code>FontData(String)</code> constructor. - * - * @return a string representation of the FontData - * - * @see FontData - */ -public String toString() { - return "1|" + fontFamily + "|" + getHeightF() + "|" + getStyle() + "|" + - "MOTIF|1|" + getXlfd(); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontMetrics.java deleted file mode 100755 index 83b12e5bcb..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontMetrics.java +++ /dev/null @@ -1,123 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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; - - -/** - * Instances of this class provide measurement information - * about fonts including ascent, descent, height, leading - * space between rows, and average character width. - * <code>FontMetrics</code> are obtained from <code>GC</code>s - * using the <code>getFontMetrics()</code> method. - * - * @see GC#getFontMetrics - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public final class FontMetrics { - int ascent, descent, averageCharWidth, leading, height; -FontMetrics() { -} -/** - * Compares the argument to the receiver, and returns true - * if they represent the <em>same</em> object using a class - * specific comparison. - * - * @param object the object to compare with this object - * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise - * - * @see #hashCode - */ -public boolean equals (Object object) { - if (object == this) return true; - if (!(object instanceof FontMetrics)) return false; - FontMetrics metrics = (FontMetrics)object; - return ascent == metrics.ascent && descent == metrics.descent && - averageCharWidth == metrics.averageCharWidth && leading == metrics.leading && - height == metrics.height; -} -/** - * Returns the ascent of the font described by the receiver. A - * font's <em>ascent</em> is the distance from the baseline to the - * top of actual characters, not including any of the leading area, - * measured in pixels. - * - * @return the ascent of the font - */ -public int getAscent() { - return ascent; -} -/** - * Returns the average character width, measured in pixels, - * of the font described by the receiver. - * - * @return the average character width of the font - */ -public int getAverageCharWidth() { - return averageCharWidth; -} -/** - * Returns the descent of the font described by the receiver. A - * font's <em>descent</em> is the distance from the baseline to the - * bottom of actual characters, not including any of the leading area, - * measured in pixels. - * - * @return the descent of the font - */ -public int getDescent() { - return descent; -} -/** - * Returns the height of the font described by the receiver, - * measured in pixels. A font's <em>height</em> is the sum of - * its ascent, descent and leading area. - * - * @return the height of the font - * - * @see #getAscent - * @see #getDescent - * @see #getLeading - */ -public int getHeight() { - return height; -} -/** - * Returns the leading area of the font described by the - * receiver. A font's <em>leading area</em> is the space - * above its ascent which may include accents or other marks. - * - * @return the leading space of the font - */ -public int getLeading() { - return leading; -} -/** - * Returns an integer hash code for the receiver. Any two - * objects that return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals - */ -public int hashCode() { - return ascent ^ descent ^ averageCharWidth ^ leading ^ height; -} -public static FontMetrics motif_new(int ascent, int descent, int averageCharWidth, int leading, int height) { - FontMetrics fontMetrics = new FontMetrics(); - fontMetrics.ascent = ascent; - fontMetrics.descent = descent; - fontMetrics.averageCharWidth = averageCharWidth; - fontMetrics.leading = leading; - fontMetrics.height = height; - return fontMetrics; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java deleted file mode 100755 index e5e3c8ca44..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java +++ /dev/null @@ -1,4568 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - - -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.cairo.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; - -/** - * Class <code>GC</code> is where all of the drawing capabilities that are - * supported by SWT are located. Instances are used to draw on either an - * <code>Image</code>, a <code>Control</code>, or directly on a <code>Display</code>. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd> - * </dl> - * - * <p> - * The SWT drawing coordinate system is the two-dimensional space with the origin - * (0,0) at the top left corner of the drawing area and with (x,y) values increasing - * to the right and downward respectively. - * </p> - * - * <p> - * The result of drawing on an image that was created with an indexed - * palette using a color that is not in the palette is platform specific. - * Some platforms will match to the nearest color while other will draw - * the color itself. This happens because the allocated image might use - * a direct palette on platforms that do not support indexed palette. - * </p> - * - * <p> - * Application code must explicitly invoke the <code>GC.dispose()</code> - * method to release the operating system resources managed by each instance - * when those instances are no longer required. This is <em>particularly</em> - * important on Windows95 and Windows98 where the operating system has a limited - * number of device contexts available. - * </p> - * - * <p> - * Note: Only one of LEFT_TO_RIGHT and RIGHT_TO_LEFT may be specified. - * </p> - * - * @see org.eclipse.swt.events.PaintEvent - * @see <a href="http://www.eclipse.org/swt/snippets/#gc">GC snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, PaintExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public final class GC extends Resource { - /** - * the handle to the OS device context - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public int handle; - - Drawable drawable; - GCData data; - - 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 BACKGROUND_BG = 1 << 8; - final static int FOREGROUND_RGB = 1 << 9; - final static int BACKGROUND_RGB = 1 << 10; - final static int DRAW_OFFSET = 1 << 11; - final static int DRAW = FOREGROUND | LINE_WIDTH | LINE_STYLE | LINE_CAP | LINE_JOIN | LINE_MITERLIMIT | DRAW_OFFSET; - 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 color, background color and font in the GC - * to match those in the drawable. - * <p> - * You must dispose the graphics context when it is no longer required. - * </p> - * @param drawable the drawable to draw on - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li> - * <li>ERROR_NULL_ARGUMENT - if there is no current device</li> - * <li>ERROR_INVALID_ARGUMENT - * - if the drawable is an image that is not a bitmap or an icon - * - if the drawable is an image or printer that is already selected - * into another graphics context</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li> - * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li> - * </ul> - */ -public GC(Drawable drawable) { - this(drawable, 0); -} -/** - * Constructs a new instance of this class which has been - * configured to draw on the specified drawable. Sets the - * foreground color, background color and font in the GC - * to match those in the drawable. - * <p> - * You must dispose the graphics context when it is no longer required. - * </p> - * - * @param drawable the drawable to draw on - * @param style the style of GC to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the drawable is null</li> - * <li>ERROR_NULL_ARGUMENT - if there is no current device</li> - * <li>ERROR_INVALID_ARGUMENT - * - if the drawable is an image that is not a bitmap or an icon - * - if the drawable is an image or printer that is already selected - * into another graphics context</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES if a handle could not be obtained for GC creation</li> - * <li>ERROR_THREAD_INVALID_ACCESS if not called from the thread that created the drawable</li> - * </ul> - * - * @since 2.1.2 - */ -public GC(Drawable drawable, int style) { - if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - GCData data = new GCData(); - data.style = checkStyle(style); - int xGC = 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, xGC); - init(); -} -static void addCairoString(int cairo, String string, float x, float y, Font font) { - byte[] buffer = Converter.wcsToMbcs(null, string, true); - GC.setCairoFont(cairo, font); - cairo_font_extents_t extents = new cairo_font_extents_t(); - Cairo.cairo_font_extents(cairo, extents); - double baseline = y + extents.ascent; - Cairo.cairo_move_to(cairo, x, baseline); - Cairo.cairo_text_path(cairo, buffer); -} -static int checkStyle (int style) { - if ((style & SWT.LEFT_TO_RIGHT) != 0) style &= ~SWT.RIGHT_TO_LEFT; - return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT); -} - -void checkGC (int mask) { - int state = data.state; - if ((state & mask) == mask) return; - state = (state ^ mask) & mask; - data.state |= mask; - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - if ((state & (BACKGROUND | FOREGROUND)) != 0) { - XColor color; - Pattern pattern; - if ((state & FOREGROUND) != 0) { - color = data.foreground; - if ((data.state & FOREGROUND_RGB) == 0) { - OS.XQueryColor (data.display, data.colormap, color); - data.state |= FOREGROUND_RGB; - } - pattern = data.foregroundPattern; - data.state &= ~BACKGROUND; - } else { - color = data.background; - if ((data.state & BACKGROUND_RGB) == 0) { - OS.XQueryColor (data.display, data.colormap, color); - data.state |= BACKGROUND_RGB; - } - pattern = data.backgroundPattern; - data.state &= ~FOREGROUND; - } - if (pattern != null) { - Cairo.cairo_set_source(cairo, pattern.handle); - } else { - Cairo.cairo_set_source_rgba(cairo, (color.red & 0xFFFF) / (float)0xFFFF, (color.green & 0xFFFF) / (float)0xFFFF, (color.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF); - } - } - if ((state & FONT) != 0) { - setCairoFont(cairo, data.font); - } - if ((state & LINE_CAP) != 0) { - int cap_style = 0; - switch (data.lineCap) { - case SWT.CAP_ROUND: cap_style = Cairo.CAIRO_LINE_CAP_ROUND; break; - case SWT.CAP_FLAT: cap_style = Cairo.CAIRO_LINE_CAP_BUTT; break; - case SWT.CAP_SQUARE: cap_style = Cairo.CAIRO_LINE_CAP_SQUARE; break; - } - Cairo.cairo_set_line_cap(cairo, cap_style); - } - if ((state & LINE_JOIN) != 0) { - int join_style = 0; - switch (data.lineJoin) { - case SWT.JOIN_MITER: join_style = Cairo.CAIRO_LINE_JOIN_MITER; break; - case SWT.JOIN_ROUND: join_style = Cairo.CAIRO_LINE_JOIN_ROUND; break; - case SWT.JOIN_BEVEL: join_style = Cairo.CAIRO_LINE_JOIN_BEVEL; break; - } - Cairo.cairo_set_line_join(cairo, join_style); - } - if ((state & LINE_WIDTH) != 0) { - Cairo.cairo_set_line_width(cairo, 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 dashesOffset = 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) { - dashesOffset = data.lineDashesOffset; - double[] cairoDashes = new double[dashes.length]; - for (int i = 0; i < cairoDashes.length; i++) { - cairoDashes[i] = width == 0 || data.lineStyle == SWT.LINE_CUSTOM ? dashes[i] : dashes[i] * width; - } - Cairo.cairo_set_dash(cairo, cairoDashes, cairoDashes.length, dashesOffset); - } else { - Cairo.cairo_set_dash(cairo, null, 0, 0); - } - } - if ((state & LINE_MITERLIMIT) != 0) { - Cairo.cairo_set_miter_limit(cairo, data.lineMiterLimit); - } - if ((state & DRAW_OFFSET) != 0) { - data.cairoXoffset = data.cairoYoffset = 0; - double[] matrix = new double[6]; - Cairo.cairo_get_matrix(cairo, matrix); - double[] dx = new double[]{1}; - double[] dy = new double[]{1}; - Cairo.cairo_user_to_device_distance(cairo, dx, dy); - double scaling = dx[0]; - if (scaling < 0) scaling = -scaling; - double strokeWidth = data.lineWidth * scaling; - if (strokeWidth == 0 || ((int)strokeWidth % 2) == 1) { - data.cairoXoffset = 0.5 / scaling; - } - scaling = dy[0]; - if (scaling < 0) scaling = -scaling; - strokeWidth = data.lineWidth * scaling; - if (strokeWidth == 0 || ((int)strokeWidth % 2) == 1) { - data.cairoYoffset = 0.5 / scaling; - } - } - return; - } - int xDisplay = data.display; - if ((state & (BACKGROUND | FOREGROUND)) != 0) { - XColor foreground; - if ((state & FOREGROUND) != 0) { - foreground = data.foreground; - data.state &= ~BACKGROUND; - } else { - foreground = data.background; - data.state &= ~FOREGROUND; - } - OS.XSetForeground (xDisplay, handle, foreground.pixel); - } - if ((state & BACKGROUND_BG) != 0) { - XColor background = data.background; - OS.XSetBackground(xDisplay, handle, background.pixel); - } - if ((state & (LINE_CAP | LINE_JOIN | LINE_STYLE | LINE_WIDTH)) != 0) { - int cap_style = 0; - int join_style = 0; - int width = (int)data.lineWidth; - int line_style = 0; - float[] dashes = null; - switch (data.lineCap) { - case SWT.CAP_ROUND: cap_style = OS.CapRound; break; - case SWT.CAP_FLAT: cap_style = OS.CapButt; break; - case SWT.CAP_SQUARE: cap_style = OS.CapProjecting; break; - } - switch (data.lineJoin) { - case SWT.JOIN_ROUND: join_style = OS.JoinRound; break; - case SWT.JOIN_MITER: join_style = OS.JoinMiter; break; - case SWT.JOIN_BEVEL: join_style = OS.JoinBevel; break; - } - 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) { - if ((state & LINE_STYLE) != 0) { - byte[] dash_list = new byte[dashes.length]; - for (int i = 0; i < dash_list.length; i++) { - dash_list[i] = (byte)(width == 0 || data.lineStyle == SWT.LINE_CUSTOM ? dashes[i] : dashes[i] * width); - } - OS.XSetDashes(xDisplay, handle, 0, dash_list, dash_list.length); - } - line_style = OS.LineOnOffDash; - } else { - line_style = OS.LineSolid; - } - OS.XSetLineAttributes(xDisplay, handle, width, line_style, cap_style, join_style); - } -} -int convertRgn(int rgn, double[] matrix) { - int /*long*/ newRgn = OS.XCreateRegion(); - //TODO - get rectangles from region instead of clip box - XRectangle rect = new XRectangle(); - OS.XClipBox(rgn, rect); - short[] pointArray = new short[8]; - double[] x = new double[1], y = new double[1]; - x[0] = rect.x; - y[0] = rect.y; - Cairo.cairo_matrix_transform_point(matrix, x, y); - pointArray[0] = (short)x[0]; - pointArray[1] = (short)y[0]; - x[0] = rect.x + rect.width; - y[0] = rect.y; - Cairo.cairo_matrix_transform_point(matrix, x, y); - pointArray[2] = (short)Math.round(x[0]); - pointArray[3] = (short)y[0]; - x[0] = rect.x + rect.width; - y[0] = rect.y + rect.height; - Cairo.cairo_matrix_transform_point(matrix, x, y); - pointArray[4] = (short)Math.round(x[0]); - pointArray[5] = (short)Math.round(y[0]); - x[0] = rect.x; - y[0] = rect.y + rect.height; - Cairo.cairo_matrix_transform_point(matrix, x, y); - pointArray[6] = (short)x[0]; - pointArray[7] = (short)Math.round(y[0]); - int /*long*/ polyRgn = OS.XPolygonRegion(pointArray, pointArray.length / 2, OS.EvenOddRule); - OS.XUnionRegion(newRgn, polyRgn, newRgn); - OS.XDestroyRegion(polyRgn); - return newRgn; -} -/** - * Copies a rectangular area of the receiver at the source - * position onto the receiver at the destination position. - * - * @param srcX the x coordinate in the receiver of the area to be copied - * @param srcY the y coordinate in the receiver of the area to be copied - * @param width the width of the area to copy - * @param height the height of the area to copy - * @param destX the x coordinate in the receiver of the area to copy to - * @param destY the y coordinate in the receiver of the area to copy to - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void copyArea(int x, int y, int width, int height, int destX, int destY) { - copyArea(x, y, width, height, destX, destY, true); -} -/** - * Copies a rectangular area of the receiver at the source - * position onto the receiver at the destination position. - * - * @param srcX the x coordinate in the receiver of the area to be copied - * @param srcY the y coordinate in the receiver of the area to be copied - * @param width the width of the area to copy - * @param height the height of the area to copy - * @param destX the x coordinate in the receiver of the area to copy to - * @param destY the y coordinate in the receiver of the area to copy to - * @param paint if <code>true</code> paint events will be generated for old and obscured areas - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public void copyArea(int x, int y, int width, int height, int destX, int destY, boolean paint) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (width <= 0 || height <= 0) return; - int deltaX = destX - x, deltaY = destY - y; - if (deltaX == 0 && deltaY == 0) return; - int xDisplay = data.display; - int xDrawable = data.drawable; - if (data.backgroundImage != null && paint) { - OS.XClearArea (xDisplay, xDrawable, x, y, width, height, true); - OS.XClearArea (xDisplay, xDrawable, destX, destY, width, height, true); - return; - } - if (data.image == null && paint) OS.XSetGraphicsExposures (xDisplay, handle, true); - OS.XCopyArea(xDisplay, xDrawable, xDrawable, handle, x, y, width, height, destX, destY); - if (data.image == null && paint) { - OS.XSetGraphicsExposures (xDisplay, handle, false); - boolean disjoint = (destX + width < x) || (x + width < destX) || (destY + height < y) || (y + height < destY); - if (disjoint) { - OS.XClearArea (xDisplay, xDrawable, x, y, width, height, true); - } else { - if (deltaX != 0) { - int newX = destX - deltaX; - if (deltaX < 0) newX = destX + width; - OS.XClearArea (xDisplay, xDrawable, newX, y, Math.abs (deltaX), height, true); - } - if (deltaY != 0) { - int newY = destY - deltaY; - if (deltaY < 0) newY = destY + height; - OS.XClearArea (xDisplay, xDrawable, x, newY, width, Math.abs (deltaY), true); - } - } - } -} -/** - * Copies a rectangular area of the receiver at the specified - * position into the image, which must be of type <code>SWT.BITMAP</code>. - * - * @param image the image to copy into - * @param x the x coordinate in the receiver of the area to be copied - * @param y the y coordinate in the receiver of the area to be copied - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the image is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the image is not a bitmap or has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void copyArea(Image image, int x, int y) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - Rectangle rect = image.getBounds(); - int xDisplay = data.display; - int xGC = OS.XCreateGC(xDisplay, image.pixmap, 0, null); - if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES); - OS.XSetSubwindowMode (xDisplay, xGC, OS.IncludeInferiors); - OS.XCopyArea(xDisplay, data.drawable, image.pixmap, xGC, x, y, rect.width, rect.height, 0, 0); - OS.XFreeGC(xDisplay, xGC); -} -void destroy() { - int /*long*/ cairo = data.cairo; - if (cairo != 0) Cairo.cairo_destroy(cairo); - data.cairo = 0; - - /* Free resources */ - int clipRgn = data.clipRgn; - if (clipRgn != 0) OS.XDestroyRegion(clipRgn); - Image image = data.image; - if (image != null) { - image.memGC = null; - if (image.transparentPixel != -1) image.createMask(); - } - - int renderTable = data.renderTable; - if (renderTable != 0) OS.XmRenderTableFree(renderTable); - int xmString = data.xmString; - if (xmString != 0) OS.XmStringFree (xmString); - int xmText = data.xmText; - if (xmText != 0) OS.XmStringFree (xmText); - int xmMnemonic = data.xmMnemonic; - if (xmMnemonic != 0) OS.XmStringFree (xmMnemonic); - - /* Dispose the GC */ - if (drawable != null) drawable.internal_dispose_GC(handle, data); - - data.display = data.drawable = data.colormap = - data.clipRgn = data.renderTable = data.xmString = data.xmText = - data.xmMnemonic = 0; - data.font = null; - drawable = null; - handle = 0; - data.image = null; - data = null; -} -/** - * Draws the outline of a circular or elliptical arc - * within the specified rectangular area. - * <p> - * The resulting arc begins at <code>startAngle</code> and extends - * for <code>arcAngle</code> degrees, using the current color. - * Angles are interpreted such that 0 degrees is at the 3 o'clock - * position. A positive value indicates a counter-clockwise rotation - * while a negative value indicates a clockwise rotation. - * </p><p> - * The center of the arc is the center of the rectangle whose origin - * is (<code>x</code>, <code>y</code>) and whose size is specified by the - * <code>width</code> and <code>height</code> arguments. - * </p><p> - * The resulting arc covers an area <code>width + 1</code> pixels wide - * by <code>height + 1</code> pixels tall. - * </p> - * - * @param x the x coordinate of the upper-left corner of the arc to be drawn - * @param y the y coordinate of the upper-left corner of the arc to be drawn - * @param width the width of the arc to be drawn - * @param height the height of the arc to be drawn - * @param startAngle the beginning angle - * @param arcAngle the angular extent of the arc, relative to the start angle - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawArc(int x, int y, int width, int height, int startAngle, int arcAngle) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - checkGC(DRAW); - if (width < 0) { - x = x + width; - width = -width; - } - if (height < 0) { - y = y + height; - height = -height; - } - if (width == 0 || height == 0 || arcAngle == 0) return; - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset; - if (width == height) { - if (arcAngle >= 0) { - Cairo.cairo_arc_negative(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f, width / 2f, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180); - } else { - Cairo.cairo_arc(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f, width / 2f, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180); - } - } else { - Cairo.cairo_save(cairo); - Cairo.cairo_translate(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f); - Cairo.cairo_scale(cairo, width / 2f, height / 2f); - if (arcAngle >= 0) { - Cairo.cairo_arc_negative(cairo, 0, 0, 1, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180); - } else { - Cairo.cairo_arc(cairo, 0, 0, 1, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180); - } - Cairo.cairo_restore(cairo); - } - Cairo.cairo_stroke(cairo); - return; - } - OS.XDrawArc(data.display, data.drawable, handle, x, y, width, height, startAngle * 64, arcAngle * 64); -} -/** - * Draws a rectangle, based on the specified arguments, which has - * the appearance of the platform's <em>focus rectangle</em> if the - * platform supports such a notion, and otherwise draws a simple - * rectangle in the receiver's foreground color. - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param width the width of the rectangle - * @param height the height of the rectangle - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #drawRectangle(int, int, int, int) - */ -public void drawFocus (int x, int y, int width, int height) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - /* - * When the drawable is not a widget, the highlight - * color is zero. - */ - int xDisplay = data.display; - int xDrawable = data.drawable; - int highlightColor = 0; - int widget = OS.XtWindowToWidget (xDisplay, xDrawable); - if (widget != 0) { - int [] argList = {OS.XmNhighlightColor, 0}; - OS.XtGetValues (widget, argList, argList.length / 2); - highlightColor = argList [1]; - } - - /* Draw the focus rectangle */ - if (width < 0) { - x = x + width; - width = -width; - } - if (height < 0) { - y = y + height; - height = -height; - } - int cairo = data.cairo; - if (cairo != 0) { - int lineWidth = 1; - Cairo.cairo_save(cairo); - Cairo.cairo_set_line_width(cairo, lineWidth); - XColor color = new XColor(); - color.pixel = highlightColor; - OS.XQueryColor (data.display, data.colormap, color); - Cairo.cairo_set_source_rgba(cairo, (color.red & 0xFFFF) / (float)0xFFFF, (color.green & 0xFFFF) / (float)0xFFFF, (color.blue & 0xFFFF) / (float)0xFFFF, 1); - Cairo.cairo_rectangle(cairo, x + lineWidth / 2f, y + lineWidth / 2f, width, height); - Cairo.cairo_stroke(cairo); - Cairo.cairo_restore(cairo); - return; - } - OS.XSetForeground (xDisplay, handle, highlightColor); - OS.XDrawRectangle (xDisplay, xDrawable, handle, x, y, width - 1, height - 1); - data.state &= ~(BACKGROUND | FOREGROUND); -} -/** - * Draws the given image in the receiver at the specified - * coordinates. - * - * @param image the image to draw - * @param x the x coordinate of where to draw - * @param y the y coordinate of where to draw - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the image is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> - * <li>ERROR_INVALID_ARGUMENT - if the given coordinates are outside the bounds of the image</li> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li> - * </ul> - */ -public void drawImage(Image image, int x, int y) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - drawImage(image, 0, 0, -1, -1, x, y, -1, -1, true); -} - -/** - * Copies a rectangular area from the source image into a (potentially - * different sized) rectangular area in the receiver. If the source - * and destination areas are of differing sizes, then the source - * area will be stretched or shrunk to fit the destination area - * as it is copied. The copy fails if any part of the source rectangle - * lies outside the bounds of the source image, or if any of the width - * or height arguments are negative. - * - * @param image the source image - * @param srcX the x coordinate in the source image to copy from - * @param srcY the y coordinate in the source image to copy from - * @param srcWidth the width in pixels to copy from the source - * @param srcHeight the height in pixels to copy from the source - * @param destX the x coordinate in the destination to copy to - * @param destY the y coordinate in the destination to copy to - * @param destWidth the width in pixels of the destination rectangle - * @param destHeight the height in pixels of the destination rectangle - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the image is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> - * <li>ERROR_INVALID_ARGUMENT - if any of the width or height arguments are negative. - * <li>ERROR_INVALID_ARGUMENT - if the source rectangle is not contained within the bounds of the source image</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li> - * </ul> - */ -public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (srcWidth == 0 || srcHeight == 0 || destWidth == 0 || destHeight == 0) return; - if (srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 || destWidth < 0 || destHeight < 0) { - SWT.error (SWT.ERROR_INVALID_ARGUMENT); - } - if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - drawImage(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false); -} -void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) { - int[] width = new int[1]; - int[] height = new int[1]; - int[] depth = new int[1]; - int[] unused = new int[1]; - OS.XGetGeometry(data.display, srcImage.pixmap, unused, unused, unused, width, height, unused, depth); - int imgWidth = width[0]; - int imgHeight = height[0]; - if (simple) { - srcWidth = destWidth = imgWidth; - srcHeight = destHeight = imgHeight; - } else { - simple = srcX == 0 && srcY == 0 && - srcWidth == destWidth && destWidth == imgWidth && - srcHeight == destHeight && destHeight == imgHeight; - if (srcX + srcWidth > imgWidth || srcY + srcHeight > imgHeight) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - } - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - if (data.alpha != 0) { - srcImage.createSurface(); - Cairo.cairo_save(cairo); - Cairo.cairo_rectangle(cairo, destX , destY, destWidth, destHeight); - Cairo.cairo_clip(cairo); - Cairo.cairo_translate(cairo, destX - srcX, destY - srcY); - if (srcWidth != destWidth || srcHeight != destHeight) { - Cairo.cairo_scale(cairo, destWidth / (float)srcWidth, destHeight / (float)srcHeight); - } - int filter = Cairo.CAIRO_FILTER_GOOD; - switch (data.interpolation) { - case SWT.DEFAULT: filter = Cairo.CAIRO_FILTER_GOOD; break; - case SWT.NONE: filter = Cairo.CAIRO_FILTER_NEAREST; break; - case SWT.LOW: filter = Cairo.CAIRO_FILTER_FAST; break; - case SWT.HIGH: filter = Cairo.CAIRO_FILTER_BEST; break; - } - int /*long*/ pattern = Cairo.cairo_pattern_create_for_surface(srcImage.surface); - if (pattern == 0) SWT.error(SWT.ERROR_NO_HANDLES); - if (srcWidth != destWidth || srcHeight != destHeight) { - /* - * Bug in Cairo. When drawing the image streched with an interpolation - * alghorithm, the edges of the image are faded. This is not a bug, but - * it is not desired. To avoid the faded edges, it should be possible to - * use cairo_pattern_set_extend() to set the pattern extend to either - * CAIRO_EXTEND_REFLECT or CAIRO_EXTEND_PAD, but these are not implemented - * in some versions of cairo (1.2.x) and have bugs in others (in 1.4.2 it - * draws with black edges). The fix is to implement CAIRO_EXTEND_REFLECT - * by creating an image that is 3 times bigger than the original, drawing - * the original image in every quadrant (with an appropriate transform) and - * use this image as the pattern. - * - * NOTE: For some reaons, it is necessary to use CAIRO_EXTEND_PAD with - * the image that was created or the edges are still faded. - */ - if (Cairo.cairo_version () >= Cairo.CAIRO_VERSION_ENCODE(1, 4, 2)) { - int /*long*/ surface = Cairo.cairo_image_surface_create(Cairo.CAIRO_FORMAT_ARGB32, imgWidth * 3, imgHeight * 3); - int /*long*/ cr = Cairo.cairo_create(surface); - Cairo.cairo_set_source_surface(cr, srcImage.surface, imgWidth, imgHeight); - Cairo.cairo_paint(cr); - Cairo.cairo_scale(cr, -1, -1); - Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth, -imgHeight); - Cairo.cairo_paint(cr); - Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth * 3, -imgHeight); - Cairo.cairo_paint(cr); - Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth, -imgHeight * 3); - Cairo.cairo_paint(cr); - Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth * 3, -imgHeight * 3); - Cairo.cairo_paint(cr); - Cairo.cairo_scale(cr, 1, -1); - Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth, imgHeight); - Cairo.cairo_paint(cr); - Cairo.cairo_set_source_surface(cr, srcImage.surface, -imgWidth * 3, imgHeight); - Cairo.cairo_paint(cr); - Cairo.cairo_scale(cr, -1, -1); - Cairo.cairo_set_source_surface(cr, srcImage.surface, imgWidth, -imgHeight); - Cairo.cairo_paint(cr); - Cairo.cairo_set_source_surface(cr, srcImage.surface, imgWidth, -imgHeight * 3); - Cairo.cairo_paint(cr); - Cairo.cairo_destroy(cr); - int /*long*/ newPattern = Cairo.cairo_pattern_create_for_surface(surface); - Cairo.cairo_surface_destroy(surface); - if (newPattern == 0) SWT.error(SWT.ERROR_NO_HANDLES); - Cairo.cairo_pattern_destroy(pattern); - pattern = newPattern; - Cairo.cairo_pattern_set_extend(pattern, Cairo.CAIRO_EXTEND_PAD); - double[] matrix = new double[6]; - Cairo.cairo_matrix_init_translate(matrix, imgWidth, imgHeight); - Cairo.cairo_pattern_set_matrix(pattern, matrix); - } -// Cairo.cairo_pattern_set_extend(pattern, Cairo.CAIRO_EXTEND_REFLECT); - } - Cairo.cairo_pattern_set_filter(pattern, filter); - Cairo.cairo_set_source(cairo, pattern); - if (data.alpha != 0xFF) { - Cairo.cairo_paint_with_alpha(cairo, data.alpha / (float)0xFF); - } else { - Cairo.cairo_paint(cairo); - } - Cairo.cairo_restore(cairo); - Cairo.cairo_pattern_destroy(pattern); - } - return; - } - if (srcImage.alpha != -1 || srcImage.alphaData != null) { - drawImageAlpha(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth[0]); - } else if (srcImage.transparentPixel != -1 || srcImage.mask != 0) { - drawImageMask(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth[0]); - } else { - drawImage(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth[0]); - } -} -void drawImageAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int depth) { - /* Simple cases */ - if (srcImage.alpha == 0) return; - if (srcImage.alpha == 255) { - drawImage(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth); - return; - } - if (device.useXRender) { - drawImageXRender(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, srcImage.mask, OS.PictStandardA8); - return; - } - - /* Check the clipping */ - Rectangle rect = getClipping(); - rect = rect.intersection(new Rectangle(destX, destY, destWidth, destHeight)); - if (rect.isEmpty()) return; - - /* Optimization. Recalculate the src and dest rectangles so that - * only the clipping area is drawn. - */ - int sx1 = srcX + (((rect.x - destX) * srcWidth) / destWidth); - int sx2 = srcX + ((((rect.x + rect.width) - destX) * srcWidth) / destWidth); - int sy1 = srcY + (((rect.y - destY) * srcHeight) / destHeight); - int sy2 = srcY + ((((rect.y + rect.height) - destY) * srcHeight) / destHeight); - destX = rect.x; - destY = rect.y; - destWidth = rect.width; - destHeight = rect.height; - srcX = sx1; - srcY = sy1; - srcWidth = Math.max(1, sx2 - sx1); - srcHeight = Math.max(1, sy2 - sy1); - - int xDisplay = data.display; - int xDrawable = data.drawable; - int xDestImagePtr = 0, xSrcImagePtr = 0; - try { - /* Get the background pixels */ - xDestImagePtr = OS.XGetImage(xDisplay, xDrawable, destX, destY, destWidth, destHeight, OS.AllPlanes, OS.ZPixmap); - if (xDestImagePtr == 0) return; - XImage xDestImage = new XImage(); - OS.memmove(xDestImage, xDestImagePtr, XImage.sizeof); - byte[] destData = new byte[xDestImage.bytes_per_line * xDestImage.height]; - OS.memmove(destData, xDestImage.data, destData.length); - - /* Get the foreground pixels */ - xSrcImagePtr = OS.XGetImage(xDisplay, srcImage.pixmap, srcX, srcY, srcWidth, srcHeight, OS.AllPlanes, OS.ZPixmap); - if (xSrcImagePtr == 0) return; - XImage xSrcImage = new XImage(); - OS.memmove(xSrcImage, xSrcImagePtr, XImage.sizeof); - byte[] srcData = new byte[xSrcImage.bytes_per_line * xSrcImage.height]; - OS.memmove(srcData, xSrcImage.data, srcData.length); - - /* Compose the pixels */ - if (xSrcImage.depth <= 8) { - XColor[] xcolors = data.device.xcolors; - if (xcolors == null) SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH); - byte[] reds = new byte[xcolors.length]; - byte[] greens = new byte[xcolors.length]; - byte[] blues = new byte[xcolors.length]; - for (int i = 0; i < xcolors.length; i++) { - XColor color = xcolors[i]; - if (color == null) continue; - reds[i] = (byte)((color.red >> 8) & 0xFF); - greens[i] = (byte)((color.green >> 8) & 0xFF); - blues[i] = (byte)((color.blue >> 8) & 0xFF); - } - ImageData.blit(ImageData.BLIT_ALPHA, - srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, xSrcImage.byte_order, 0, 0, srcWidth, srcHeight, reds, greens, blues, - srcImage.alpha, srcImage.alphaData, imgWidth, srcX, srcY, - destData, xDestImage.bits_per_pixel, xDestImage.bytes_per_line, xDestImage.byte_order, 0, 0, destWidth, destHeight, reds, greens, blues, - false, false); - } else { - int srcRedMask = xSrcImage.red_mask; - int srcGreenMask = xSrcImage.green_mask; - int srcBlueMask = xSrcImage.blue_mask; - int destRedMask = xDestImage.red_mask; - int destGreenMask = xDestImage.green_mask; - int destBlueMask = xDestImage.blue_mask; - - /* - * Feature in X. XGetImage does not retrieve the RGB masks if the drawable - * is a Pixmap. The fix is to detect that the masks are not valid and use - * the default visual masks instead. - * - * NOTE: It is safe to use the default Visual masks, since we always - * create images with these masks. - */ - int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay)); - Visual xVisual = new Visual(); - OS.memmove(xVisual, visual, Visual.sizeof); - if (srcRedMask == 0 && srcGreenMask == 0 && srcBlueMask == 0) { - srcRedMask = xVisual.red_mask; - srcGreenMask = xVisual.green_mask; - srcBlueMask = xVisual.blue_mask; - } - if (destRedMask == 0 && destGreenMask == 0 && destBlueMask == 0) { - destRedMask = xVisual.red_mask; - destGreenMask = xVisual.green_mask; - destBlueMask = xVisual.blue_mask; - } - - ImageData.blit(ImageData.BLIT_ALPHA, - srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, xSrcImage.byte_order, 0, 0, srcWidth, srcHeight, srcRedMask, srcGreenMask, srcBlueMask, - srcImage.alpha, srcImage.alphaData, imgWidth, srcX, srcY, - destData, xDestImage.bits_per_pixel, xDestImage.bytes_per_line, xDestImage.byte_order, 0, 0, destWidth, destHeight, destRedMask, destGreenMask, destBlueMask, - false, false); - } - - /* Draw the composed pixels */ - OS.memmove(xDestImage.data, destData, destData.length); - OS.XPutImage(xDisplay, xDrawable, handle, xDestImagePtr, 0, 0, destX, destY, destWidth, destHeight); - } finally { - if (xSrcImagePtr != 0) OS.XDestroyImage(xSrcImagePtr); - if (xDestImagePtr != 0) OS.XDestroyImage(xDestImagePtr); - } -} -void drawImageMask(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int depth) { - int xDisplay = data.display; - int xDrawable = data.drawable; - /* Generate the mask if necessary. */ - if (srcImage.transparentPixel != -1) srcImage.createMask(); - - if (device.useXRender) { - drawImageXRender(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, srcImage.mask, OS.PictStandardA1); - } else { - int colorPixmap = 0, maskPixmap = 0; - int foreground = 0x00000000; - if (simple || (srcWidth == destWidth && srcHeight == destHeight)) { - colorPixmap = srcImage.pixmap; - maskPixmap = srcImage.mask; - } else { - /* Stretch the color and mask*/ - int xImagePtr = scalePixmap(xDisplay, srcImage.pixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false); - if (xImagePtr != 0) { - int xMaskPtr = scalePixmap(xDisplay, srcImage.mask, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false); - if (xMaskPtr != 0) { - /* Create color scaled pixmaps */ - colorPixmap = OS.XCreatePixmap(xDisplay, xDrawable, destWidth, destHeight, depth); - int tempGC = OS.XCreateGC(xDisplay, colorPixmap, 0, null); - OS.XPutImage(xDisplay, colorPixmap, tempGC, xImagePtr, 0, 0, 0, 0, destWidth, destHeight); - OS.XFreeGC(xDisplay, tempGC); - - /* Create mask scaled pixmaps */ - maskPixmap = OS.XCreatePixmap(xDisplay, xDrawable, destWidth, destHeight, 1); - tempGC = OS.XCreateGC(xDisplay, maskPixmap, 0, null); - OS.XPutImage(xDisplay, maskPixmap, tempGC, xMaskPtr, 0, 0, 0, 0, destWidth, destHeight); - OS.XFreeGC(xDisplay, tempGC); - - OS.XDestroyImage(xMaskPtr); - } - OS.XDestroyImage(xImagePtr); - } - - /* Change the source rectangle */ - srcX = srcY = 0; - srcWidth = destWidth; - srcHeight = destHeight; - - foreground = ~foreground; - } - - /* Do the blts */ - if (colorPixmap != 0 && maskPixmap != 0) { - XGCValues values = new XGCValues(); - OS.XGetGCValues(xDisplay, handle, OS.GCForeground | OS. GCBackground | OS.GCFunction, values); - OS.XSetFunction(xDisplay, handle, OS.GXxor); - OS.XCopyArea(xDisplay, colorPixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY); - OS.XSetForeground(xDisplay, handle, foreground); - OS.XSetBackground(xDisplay, handle, ~foreground); - OS.XSetFunction(xDisplay, handle, OS.GXand); - OS.XCopyPlane(xDisplay, maskPixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY, 1); - OS.XSetFunction(xDisplay, handle, OS.GXxor); - OS.XCopyArea(xDisplay, colorPixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY); - OS.XSetForeground(xDisplay, handle, values.foreground); - OS.XSetBackground(xDisplay, handle, values.background); - OS.XSetFunction(xDisplay, handle, values.function); - } - - /* Destroy scaled pixmaps */ - if (colorPixmap != 0 && srcImage.pixmap != colorPixmap) OS.XFreePixmap(xDisplay, colorPixmap); - if (maskPixmap != 0 && srcImage.mask != maskPixmap) OS.XFreePixmap(xDisplay, maskPixmap); - } - - /* Destroy the image mask if the there is a GC created on the image */ - if (srcImage.transparentPixel != -1 && srcImage.memGC != null) srcImage.destroyMask(); -} -void drawImageXRender(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int maskPixmap, int maskType) { - int drawable = data.drawable; - int xDisplay = data.display; - int maskPict = 0; - if (maskPixmap != 0) { - int attribCount = 0; - XRenderPictureAttributes attrib = null; - if (srcImage.alpha != -1) { - attribCount = 1; - attrib = new XRenderPictureAttributes(); - attrib.repeat = true; - } - maskPict = OS.XRenderCreatePicture(xDisplay, maskPixmap, OS.XRenderFindStandardFormat(xDisplay, maskType), attribCount, attrib); - if (maskPict == 0) SWT.error(SWT.ERROR_NO_HANDLES); - } - int format = OS.XRenderFindVisualFormat(xDisplay, OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay))); - int destPict = OS.XRenderCreatePicture(xDisplay, drawable, format, 0, null); - if (destPict == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int srcPict = OS.XRenderCreatePicture(xDisplay, srcImage.pixmap, format, 0, null); - if (srcPict == 0) SWT.error(SWT.ERROR_NO_HANDLES); - if (srcWidth != destWidth || srcHeight != destHeight) { - int[] transform = new int[]{(int)(((float)srcWidth / destWidth) * 65536), 0, 0, 0, (int)(((float)srcHeight / destHeight) * 65536), 0, 0, 0, 65536}; - OS.XRenderSetPictureTransform(xDisplay, srcPict, transform); - if (maskPict != 0) OS.XRenderSetPictureTransform(xDisplay, maskPict, transform); - srcX *= destWidth / (float)srcWidth; - srcY *= destHeight / (float)srcHeight; - } - int clipping = data.clipRgn; - if (data.damageRgn != 0) { - if (clipping == 0) { - clipping = data.damageRgn; - } else { - clipping = OS.XCreateRegion (); - OS.XUnionRegion(clipping, data.clipRgn, clipping); - OS.XIntersectRegion(clipping, data.damageRgn, clipping); - } - } - if (clipping != 0) { - OS.XRenderSetPictureClipRegion(xDisplay, destPict, clipping); - if (clipping != data.clipRgn && clipping != data.damageRgn) { - OS.XDestroyRegion(clipping); - } - } - OS.XRenderComposite(xDisplay, maskPict != 0 ? OS.PictOpOver : OS.PictOpSrc, srcPict, maskPict, destPict, srcX, srcY, srcX, srcY, destX, destY, destWidth, destHeight); - OS.XRenderFreePicture(xDisplay, destPict); - OS.XRenderFreePicture(xDisplay, srcPict); - if (maskPict != 0) OS.XRenderFreePicture(xDisplay, maskPict); -} -void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int depth) { - int xDisplay = data.display; - int xDrawable = data.drawable; - /* Simple case: no stretching */ - if ((srcWidth == destWidth) && (srcHeight == destHeight)) { - OS.XCopyArea(xDisplay, srcImage.pixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY); - return; - } - if (device.useXRender) { - drawImageXRender(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, 0, -1); - return; - } - - /* Streching case */ - int xImagePtr = scalePixmap(xDisplay, srcImage.pixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false); - if (xImagePtr != 0) { - OS.XPutImage(xDisplay, xDrawable, handle, xImagePtr, 0, 0, destX, destY, destWidth, destHeight); - OS.XDestroyImage(xImagePtr); - } -} -static int scalePixmap(int display, int pixmap, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean flipX, boolean flipY) { - int xSrcImagePtr = OS.XGetImage(display, pixmap, srcX, srcY, srcWidth, srcHeight, OS.AllPlanes, OS.ZPixmap); - if (xSrcImagePtr == 0) return 0; - XImage xSrcImage = new XImage(); - OS.memmove(xSrcImage, xSrcImagePtr, XImage.sizeof); - byte[] srcData = new byte[xSrcImage.bytes_per_line * xSrcImage.height]; - OS.memmove(srcData, xSrcImage.data, srcData.length); - OS.XDestroyImage(xSrcImagePtr); - int xImagePtr = 0; - int visual = OS.XDefaultVisual(display, OS.XDefaultScreen(display)); - switch (xSrcImage.bits_per_pixel) { - case 1: - case 4: - case 8: { - int format = xSrcImage.bits_per_pixel == 1 ? OS.XYBitmap : OS.ZPixmap; - xImagePtr = OS.XCreateImage(display, visual, xSrcImage.depth, format, 0, 0, destWidth, destHeight, xSrcImage.bitmap_pad, 0); - if (xImagePtr == 0) return 0; - XImage xImage = new XImage(); - OS.memmove(xImage, xImagePtr, XImage.sizeof); - int bufSize = xImage.bytes_per_line * xImage.height; - if (bufSize < 0) { - OS.XDestroyImage(xImagePtr); - return 0; - } - int bufPtr = OS.XtMalloc(bufSize); - xImage.data = bufPtr; - OS.memmove(xImagePtr, xImage, XImage.sizeof); - byte[] buf = new byte[bufSize]; - int srcOrder = xSrcImage.bits_per_pixel == 1 ? xSrcImage.bitmap_bit_order : xSrcImage.byte_order; - int destOrder = xImage.bits_per_pixel == 1 ? xImage.bitmap_bit_order : xImage.byte_order; - ImageData.blit(ImageData.BLIT_SRC, - srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, srcOrder, 0, 0, srcWidth, srcHeight, null, null, null, - ImageData.ALPHA_OPAQUE, null, 0, 0, 0, - buf, xImage.bits_per_pixel, xImage.bytes_per_line, destOrder, 0, 0, destWidth, destHeight, null, null, null, - flipX, flipY); - OS.memmove(bufPtr, buf, bufSize); - break; - } - case 16: - case 24: - case 32: { - xImagePtr = OS.XCreateImage(display, visual, xSrcImage.depth, OS.ZPixmap, 0, 0, destWidth, destHeight, xSrcImage.bitmap_pad, 0); - if (xImagePtr == 0) return 0; - XImage xImage = new XImage(); - OS.memmove(xImage, xImagePtr, XImage.sizeof); - int bufSize = xImage.bytes_per_line * xImage.height; - if (bufSize < 0) { - OS.XDestroyImage(xImagePtr); - return 0; - } - int bufPtr = OS.XtMalloc(bufSize); - xImage.data = bufPtr; - OS.memmove(xImagePtr, xImage, XImage.sizeof); - byte[] buf = new byte[bufSize]; - ImageData.blit(ImageData.BLIT_SRC, - srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, xSrcImage.byte_order, 0, 0, srcWidth, srcHeight, 0, 0, 0, - ImageData.ALPHA_OPAQUE, null, 0, 0, 0, - buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, 0, 0, 0, - flipX, flipY); - OS.memmove(bufPtr, buf, bufSize); - break; - } - } - return xImagePtr; -} -/** - * Draws a line, using the foreground color, between the points - * (<code>x1</code>, <code>y1</code>) and (<code>x2</code>, <code>y2</code>). - * - * @param x1 the first point's x coordinate - * @param y1 the first point's y coordinate - * @param x2 the second point's x coordinate - * @param y2 the second point's y coordinate - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawLine (int x1, int y1, int x2, int y2) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - checkGC(DRAW); - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset; - Cairo.cairo_move_to(cairo, x1 + xOffset, y1 + yOffset); - Cairo.cairo_line_to(cairo, x2 + xOffset, y2 + yOffset); - Cairo.cairo_stroke(cairo); - return; - } - OS.XDrawLine (data.display, data.drawable, handle, x1, y1, x2, y2); -} -/** - * Draws the outline of an oval, using the foreground color, - * within the specified rectangular area. - * <p> - * The result is a circle or ellipse that fits within the - * rectangle specified by the <code>x</code>, <code>y</code>, - * <code>width</code>, and <code>height</code> arguments. - * </p><p> - * The oval covers an area that is <code>width + 1</code> - * pixels wide and <code>height + 1</code> pixels tall. - * </p> - * - * @param x the x coordinate of the upper left corner of the oval to be drawn - * @param y the y coordinate of the upper left corner of the oval to be drawn - * @param width the width of the oval to be drawn - * @param height the height of the oval to be drawn - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawOval(int x, int y, int width, int height) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - checkGC(DRAW); - if (width < 0) { - x = x + width; - width = -width; - } - if (height < 0) { - y = y + height; - height = -height; - } - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset; - if (width == height) { - Cairo.cairo_arc_negative(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f, width / 2f, 0, -2 * (float)Compatibility.PI); - } else { - Cairo.cairo_save(cairo); - Cairo.cairo_translate(cairo, x + xOffset + width / 2f, y + yOffset + height / 2f); - Cairo.cairo_scale(cairo, width / 2f, height / 2f); - Cairo.cairo_arc_negative(cairo, 0, 0, 1, 0, -2 * (float)Compatibility.PI); - Cairo.cairo_restore(cairo); - } - Cairo.cairo_stroke(cairo); - return; - } - OS.XDrawArc(data.display, data.drawable, handle, x, y, width, height, 0, 23040); -} -/** - * Draws the path described by the parameter. - * <p> - * This operation requires the operating system's advanced - * graphics subsystem which may not be available on some - * platforms. - * </p> - * - * @param path the path to draw - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> - * </ul> - * - * @see Path - * - * @since 3.1 - */ -public void drawPath(Path path) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (path.handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - initCairo(); - checkGC(DRAW); - int /*long*/ cairo = data.cairo; - Cairo.cairo_save(cairo); - double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset; - Cairo.cairo_translate(cairo, xOffset, yOffset); - int /*long*/ copy = Cairo.cairo_copy_path(path.handle); - if (copy == 0) SWT.error(SWT.ERROR_NO_HANDLES); - Cairo.cairo_append_path(cairo, copy); - Cairo.cairo_path_destroy(copy); - Cairo.cairo_stroke(cairo); - Cairo.cairo_restore(cairo); -} -/** - * Draws a pixel, using the foreground color, at the specified - * point (<code>x</code>, <code>y</code>). - * <p> - * Note that the receiver's line attributes do not affect this - * operation. - * </p> - * - * @param x the point's x coordinate - * @param y the point's y coordinate - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.0 - */ -public void drawPoint (int x, int y) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - checkGC(DRAW); - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - Cairo.cairo_rectangle(cairo, x, y, 1, 1); - Cairo.cairo_fill(cairo); - return; - } - OS.XDrawPoint(data.display, data.drawable, handle, x, y); -} -/** - * Draws the closed polygon which is defined by the specified array - * of integer coordinates, using the receiver's foreground color. The array - * contains alternating x and y values which are considered to represent - * points which are the vertices of the polygon. Lines are drawn between - * each consecutive pair, and between the first pair and last pair in the - * array. - * - * @param pointArray an array of alternating x and y values which are the vertices of the polygon - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT if pointArray is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawPolygon(int[] pointArray) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - checkGC(DRAW); - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - drawPolyline(cairo, pointArray, true); - Cairo.cairo_stroke(cairo); - return; - } - - // Motif does not have a native drawPolygon() call. Instead we ensure - // that the first and last points are the same and call drawPolyline(). - - int length = pointArray.length; - - // Need at least 3 points to define the polygon. If 2 or fewer points - // passed in, it is either a line or point so just call drawPolyline(). - // Check what happens when XOR is implemented. We may not be able to - // do this optimization. - - if (length < 4) { - drawPolyline(pointArray); - return; - } - - // If first and last points are the same, the polygon is already closed. - // Just call drawPolyline(). - // - // Check what happens when XOR is implemented. We may not be able to - // do this optimization. - - if (pointArray[0] == pointArray[length - 2] && (pointArray[1] == pointArray[length - 1])) { - drawPolyline(pointArray); - return; - } - - // Grow the list of points by one element and make sure the first and last - // points are the same. This will close the polygon and we can use the - // drawPolyline() call. - - int newPoints[] = new int[length + 2]; - for (int i = 0; i < length ; i++) - newPoints[i] = pointArray[i]; - newPoints[length] = pointArray[0]; - newPoints[length + 1] = pointArray[1]; - - drawPolyline(newPoints); -} -/** - * Draws the polyline which is defined by the specified array - * of integer coordinates, using the receiver's foreground color. The array - * contains alternating x and y values which are considered to represent - * points which are the corners of the polyline. Lines are drawn between - * each consecutive pair, but not between the first pair and last pair in - * the array. - * - * @param pointArray an array of alternating x and y values which are the corners of the polyline - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the point array is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawPolyline(int[] pointArray) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - checkGC(DRAW); - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - drawPolyline(cairo, pointArray, false); - Cairo.cairo_stroke(cairo); - return; - } - short[] xPoints = new short[pointArray.length]; - for (int i = 0; i<pointArray.length;i++) { - xPoints[i] = (short) pointArray[i]; - } - OS.XDrawLines(data.display,data.drawable,handle,xPoints,xPoints.length / 2, OS.CoordModeOrigin); -} -void drawPolyline(int /*long*/ cairo, int[] pointArray, boolean close) { - int count = pointArray.length / 2; - if (count == 0) return; - double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset; - Cairo.cairo_move_to(cairo, pointArray[0] + xOffset, pointArray[1] + yOffset); - for (int i = 1, j=2; i < count; i++, j += 2) { - Cairo.cairo_line_to(cairo, pointArray[j] + xOffset, pointArray[j + 1] + yOffset); - } - if (close) Cairo.cairo_close_path(cairo); -} -/** - * Draws the outline of the rectangle specified by the arguments, - * using the receiver's foreground color. The left and right edges - * of the rectangle are at <code>x</code> and <code>x + width</code>. - * The top and bottom edges are at <code>y</code> and <code>y + height</code>. - * - * @param x the x coordinate of the rectangle to be drawn - * @param y the y coordinate of the rectangle to be drawn - * @param width the width of the rectangle to be drawn - * @param height the height of the rectangle to be drawn - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawRectangle (int x, int y, int width, int height) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - checkGC(DRAW); - if (width < 0) { - x = x + width; - width = -width; - } - if (height < 0) { - y = y + height; - height = -height; - } - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset; - Cairo.cairo_rectangle(cairo, x + xOffset, y + yOffset, width, height); - Cairo.cairo_stroke(cairo); - return; - } - OS.XDrawRectangle (data.display, data.drawable, handle, x, y, width, height); -} -/** - * Draws the outline of the specified rectangle, using the receiver's - * foreground color. The left and right edges of the rectangle are at - * <code>rect.x</code> and <code>rect.x + rect.width</code>. The top - * and bottom edges are at <code>rect.y</code> and - * <code>rect.y + rect.height</code>. - * - * @param rect the rectangle to draw - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawRectangle (Rectangle rect) { - if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - drawRectangle (rect.x, rect.y, rect.width, rect.height); -} -/** - * Draws the outline of the round-cornered rectangle specified by - * the arguments, using the receiver's foreground color. The left and - * right edges of the rectangle are at <code>x</code> and <code>x + width</code>. - * The top and bottom edges are at <code>y</code> and <code>y + height</code>. - * The <em>roundness</em> of the corners is specified by the - * <code>arcWidth</code> and <code>arcHeight</code> arguments, which - * are respectively the width and height of the ellipse used to draw - * the corners. - * - * @param x the x coordinate of the rectangle to be drawn - * @param y the y coordinate of the rectangle to be drawn - * @param width the width of the rectangle to be drawn - * @param height the height of the rectangle to be drawn - * @param arcWidth the width of the arc - * @param arcHeight the height of the arc - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - checkGC(DRAW); - 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; - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - double xOffset = data.cairoXoffset, yOffset = data.cairoYoffset; - if (naw == 0 || nah == 0) { - Cairo.cairo_rectangle(cairo, x + xOffset, y + yOffset, width, height); - } else { - float naw2 = naw / 2f; - float nah2 = nah / 2f; - float fw = nw / naw2; - float fh = nh / nah2; - Cairo.cairo_save(cairo); - Cairo.cairo_translate(cairo, nx + xOffset, ny + yOffset); - Cairo.cairo_scale(cairo, naw2, nah2); - Cairo.cairo_move_to(cairo, fw - 1, 0); - Cairo.cairo_arc(cairo, fw - 1, 1, 1, Compatibility.PI + Compatibility.PI/2.0, Compatibility.PI*2.0); - Cairo.cairo_arc(cairo, fw - 1, fh - 1, 1, 0, Compatibility.PI/2.0); - Cairo.cairo_arc(cairo, 1, fh - 1, 1, Compatibility.PI/2, Compatibility.PI); - Cairo.cairo_arc(cairo, 1, 1, 1, Compatibility.PI, 270.0*Compatibility.PI/180.0); - Cairo.cairo_close_path(cairo); - Cairo.cairo_restore(cairo); - } - Cairo.cairo_stroke(cairo); - return; - } - int naw2 = naw / 2; - int nah2 = nah / 2; - int xDisplay = data.display; - int xDrawable = data.drawable; - if (nw > naw) { - if (nh > nah) { - OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny, naw, nah, 5760, 5760); - OS.XDrawLine(xDisplay, xDrawable, handle, nx + naw2, ny, nx + nw - naw2, ny); - OS.XDrawArc(xDisplay, xDrawable, handle, nx + nw - naw, ny, naw, nah, 0, 5760); - OS.XDrawLine(xDisplay, xDrawable, handle, nx + nw, ny + nah2, nx + nw, ny + nh - nah2); - OS.XDrawArc(xDisplay, xDrawable, handle, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760); - OS.XDrawLine(xDisplay,xDrawable,handle, nx + naw2, ny + nh, nx + nw - naw2, ny + nh); - OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny + nh - nah, naw, nah, 11520, 5760); - OS.XDrawLine(xDisplay, xDrawable, handle, nx, ny + nah2, nx, ny + nh - nah2); - } else { - OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny, naw, nh, 5760, 11520); - OS.XDrawLine(xDisplay, xDrawable, handle, nx + naw2, ny, nx + nw - naw2, ny); - OS.XDrawArc(xDisplay, xDrawable, handle, nx + nw - naw, ny, naw, nh, 17280, 11520); - OS.XDrawLine(xDisplay,xDrawable,handle, nx + naw2, ny + nh, nx + nw - naw2, ny + nh); - } - } else { - if (nh > nah) { - OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny, nw, nah, 0, 11520); - OS.XDrawLine(xDisplay, xDrawable, handle, nx + nw, ny + nah2, nx + nw, ny + nh - nah2); - OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny + nh - nah, nw, nah, 11520, 11520); - OS.XDrawLine(xDisplay,xDrawable,handle, nx, ny + nah2, nx, ny + nh - nah2); - } else { - OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny, nw, nh, 0, 23040); - } - } -} -/** - * Draws the given string, using the receiver's current font and - * foreground color. No tab expansion or carriage return processing - * will be performed. The background of the rectangular area where - * the string is being drawn will be filled with the receiver's - * background color. - * - * @param string the string to be drawn - * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn - * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawString (String string, int x, int y) { - drawString(string, x, y, false); -} -/** - * Draws the given string, using the receiver's current font and - * foreground color. No tab expansion or carriage return processing - * will be performed. If <code>isTransparent</code> is <code>true</code>, - * then the background of the rectangular area where the string is being - * drawn will not be modified, otherwise it will be filled with the - * receiver's background color. - * - * @param string the string to be drawn - * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn - * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn - * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawString (String string, int x, int y, boolean isTransparent) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (string.length() == 0) return; - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - //TODO - honor isTransparent - checkGC(FOREGROUND | FONT); - cairo_font_extents_t extents = new cairo_font_extents_t(); - Cairo.cairo_font_extents(cairo, extents); - double baseline = y + extents.ascent; - Cairo.cairo_move_to(cairo, x, baseline); - byte[] buffer = Converter.wcsToMbcs(null, string, true); - Cairo.cairo_show_text(cairo, buffer); - Cairo.cairo_new_path(cairo); - return; - } - setString(string); - checkGC(FOREGROUND | FONT | BACKGROUND_BG); - if (isTransparent) { - OS.XmStringDraw (data.display, data.drawable, data.font.handle, data.xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null); - } else { - OS.XmStringDrawImage (data.display, data.drawable, data.font.handle, data.xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null); - } -} -void createRenderTable() { - int fontList = data.font.handle; - /* Get the width of the tabs */ - byte[] buffer = {(byte)' ', 0}; - int xmString = OS.XmStringCreate(buffer, OS.XmFONTLIST_DEFAULT_TAG); - int tabWidth = OS.XmStringWidth(fontList, xmString) * 8; - OS.XmStringFree(xmString); - - /* Create the tab list */ - int [] tabs = new int[16]; - int tab = OS.XmTabCreate(tabWidth, (byte) OS.XmPIXELS, (byte) OS.XmRELATIVE, (byte) OS.XmALIGNMENT_BEGINNING, null); - for (int i = 0; i < tabs.length; i++) tabs[i] = tab; - int tabList = OS.XmTabListInsertTabs(0, tabs, tabs.length, 0); - - /* Create a font context to iterate over the elements in the font list */ - int[] fontBuffer = new int[1]; - if (!OS.XmFontListInitFontContext(fontBuffer, fontList)) { - SWT.error(SWT.ERROR_NO_HANDLES); - } - int context = fontBuffer[0], fontListEntry = 0; - int[] renditions = new int[4]; int renditionCount = 0; - - /* Create a rendition for each entry in the font list */ - while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) { - int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, fontBuffer); - int fontType = (fontBuffer [0] == 0) ? OS.XmFONT_IS_FONT : OS.XmFONT_IS_FONTSET; - if (fontPtr == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int [] argList = { - OS.XmNtabList, tabList, - OS.XmNfont, fontPtr, - OS.XmNfontType, fontType, - }; - int rendition = OS.XmRenditionCreate(data.device.shellHandle, OS.XmFONTLIST_DEFAULT_TAG, argList, argList.length / 2); - renditions[renditionCount++] = rendition; - if (renditionCount == renditions.length) { - int[] newArray = new int[renditions.length + 4]; - System.arraycopy(newArray, 0, renditions, 0, renditionCount); - renditions = newArray; - } - } - OS.XmFontListFreeFontContext(context); - OS.XmTabFree(tab); - OS.XmTabListFree(tabList); - - /* Create the render table from the renditions */ - data.renderTable = OS.XmRenderTableAddRenditions(0, renditions, renditionCount, OS.XmMERGE_REPLACE); - for (int i = 0; i < renditionCount; i++) OS.XmRenditionFree(renditions[i]); -} -/** - * Draws the given string, using the receiver's current font and - * foreground color. Tab expansion and carriage return processing - * are performed. The background of the rectangular area where - * the text is being drawn will be filled with the receiver's - * background color. - * - * @param string the string to be drawn - * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn - * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawText (String string, int x, int y) { - drawText(string, x, y, SWT.DRAW_DELIMITER | SWT.DRAW_TAB); -} -/** - * Draws the given string, using the receiver's current font and - * foreground color. Tab expansion and carriage return processing - * are performed. If <code>isTransparent</code> is <code>true</code>, - * then the background of the rectangular area where the text is being - * drawn will not be modified, otherwise it will be filled with the - * receiver's background color. - * - * @param string the string to be drawn - * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn - * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn - * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawText (String string, int x, int y, boolean isTransparent) { - int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB; - if (isTransparent) flags |= SWT.DRAW_TRANSPARENT; - drawText(string, x, y, flags); -} -/** - * Draws the given string, using the receiver's current font and - * foreground color. Tab expansion, line delimiter and mnemonic - * processing are performed according to the specified flags. If - * <code>flags</code> includes <code>DRAW_TRANSPARENT</code>, - * then the background of the rectangular area where the text is being - * drawn will not be modified, otherwise it will be filled with the - * receiver's background color. - * <p> - * The parameter <code>flags</code> may be a combination of: - * <dl> - * <dt><b>DRAW_DELIMITER</b></dt> - * <dd>draw multiple lines</dd> - * <dt><b>DRAW_TAB</b></dt> - * <dd>expand tabs</dd> - * <dt><b>DRAW_MNEMONIC</b></dt> - * <dd>underline the mnemonic character</dd> - * <dt><b>DRAW_TRANSPARENT</b></dt> - * <dd>transparent background</dd> - * </dl> - * </p> - * - * @param string the string to be drawn - * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn - * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn - * @param flags the flags specifying how to process the text - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawText (String string, int x, int y, int flags) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (string.length() == 0) return; - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - //TODO - honor flags - checkGC(FOREGROUND | FONT); - cairo_font_extents_t extents = new cairo_font_extents_t(); - Cairo.cairo_font_extents(cairo, extents); - double baseline = y + extents.ascent; - Cairo.cairo_move_to(cairo, x, baseline); - byte[] buffer = Converter.wcsToMbcs(null, string, true); - Cairo.cairo_show_text(cairo, buffer); - Cairo.cairo_new_path(cairo); - return; - } - setText(string, flags); - checkGC(FOREGROUND | FONT | BACKGROUND_BG); - int xDisplay = data.display; - int xDrawable = data.drawable; - if (data.image != null) OS.XtRegisterDrawable (xDisplay, xDrawable, data.device.shellHandle); - int xmMnemonic = data.xmMnemonic; - if (xmMnemonic != 0) { - OS.XmStringDrawUnderline(xDisplay, xDrawable, data.renderTable, data.xmText, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null, xmMnemonic); - } else { - if ((flags & SWT.DRAW_TRANSPARENT) != 0) { - OS.XmStringDraw(xDisplay, xDrawable, data.renderTable, data.xmText, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null); - } else { - OS.XmStringDrawImage(xDisplay, xDrawable, data.renderTable, data.xmText, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null); - } - } - if (data.image != null) OS.XtUnregisterDrawable (xDisplay, xDrawable); -} -/** - * Compares the argument to the receiver, and returns true - * if they represent the <em>same</em> object using a class - * specific comparison. - * - * @param object the object to compare with this object - * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise - * - * @see #hashCode - */ -public boolean equals (Object object) { - 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. - * <p> - * The resulting arc begins at <code>startAngle</code> and extends - * for <code>arcAngle</code> degrees, using the current color. - * Angles are interpreted such that 0 degrees is at the 3 o'clock - * position. A positive value indicates a counter-clockwise rotation - * while a negative value indicates a clockwise rotation. - * </p><p> - * The center of the arc is the center of the rectangle whose origin - * is (<code>x</code>, <code>y</code>) and whose size is specified by the - * <code>width</code> and <code>height</code> arguments. - * </p><p> - * The resulting arc covers an area <code>width + 1</code> pixels wide - * by <code>height + 1</code> pixels tall. - * </p> - * - * @param x the x coordinate of the upper-left corner of the arc to be filled - * @param y the y coordinate of the upper-left corner of the arc to be filled - * @param width the width of the arc to be filled - * @param height the height of the arc to be filled - * @param startAngle the beginning angle - * @param arcAngle the angular extent of the arc, relative to the start angle - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #drawArc - */ -public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - checkGC(FILL); - if (width < 0) { - x = x + width; - width = -width; - } - if (height < 0) { - y = y + height; - height = -height; - } - if (width == 0 || height == 0 || arcAngle == 0) return; - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - if (width == height) { - if (arcAngle >= 0) { - Cairo.cairo_arc_negative(cairo, x + width / 2f, y + height / 2f, width / 2f, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180); - } else { - Cairo.cairo_arc(cairo, x + width / 2f, y + height / 2f, width / 2f, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180); - } - Cairo.cairo_line_to(cairo, x + width / 2f, y + height / 2f); - } else { - Cairo.cairo_save(cairo); - Cairo.cairo_translate(cairo, x + width / 2f, y + height / 2f); - Cairo.cairo_scale(cairo, width / 2f, height / 2f); - if (arcAngle >= 0) { - Cairo.cairo_arc_negative(cairo, 0, 0, 1, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180); - } else { - Cairo.cairo_arc(cairo, 0, 0, 1, -startAngle * (float)Compatibility.PI / 180, -(startAngle + arcAngle) * (float)Compatibility.PI / 180); - } - Cairo.cairo_line_to(cairo, 0, 0); - Cairo.cairo_restore(cairo); - } - Cairo.cairo_fill(cairo); - return; - } - OS.XFillArc(data.display, data.drawable, handle, x, y, width, height, startAngle * 64, arcAngle * 64); -} - -/** - * Fills the interior of the specified rectangle with a gradient - * sweeping from left to right or top to bottom progressing - * from the receiver's foreground color to its background color. - * - * @param x the x coordinate of the rectangle to be filled - * @param y the y coordinate of the rectangle to be filled - * @param width the width of the rectangle to be filled, may be negative - * (inverts direction of gradient if horizontal) - * @param height the height of the rectangle to be filled, may be negative - * (inverts direction of gradient if vertical) - * @param vertical if true sweeps from top to bottom, else - * sweeps from left to right - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #drawRectangle(int, int, int, int) - */ -public void fillGradientRectangle(int x, int y, int width, int height, boolean vertical) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if ((width == 0) || (height == 0)) return; - - 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; - } - /* X Window deals with a virtually limitless array of color formats - * but we only distinguish between paletted and direct modes - */ - int xDisplay = data.display; - int xScreenNum = OS.XDefaultScreen(xDisplay); - final int xScreen = OS.XDefaultScreenOfDisplay(xDisplay); - final int xVisual = OS.XDefaultVisual(xDisplay, xScreenNum); - Visual visual = new Visual(); - OS.memmove(visual, xVisual, Visual.sizeof); - final int depth = OS.XDefaultDepthOfScreen(xScreen); - final boolean directColor = (depth > 8); - - // This code is intentionally commented since elsewhere in SWT we - // assume that depth <= 8 means we are in a paletted mode though - // this is not always the case. - //final boolean directColor = (visual.c_class == OS.TrueColor) || (visual.c_class == OS.DirectColor); - - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - int /*long*/ pattern; - if (vertical) { - pattern = Cairo.cairo_pattern_create_linear (0.0, 0.0, 0.0, 1.0); - } else { - pattern = Cairo.cairo_pattern_create_linear (0.0, 0.0, 1.0, 0.0); - } - Cairo.cairo_pattern_add_color_stop_rgba (pattern, 0, fromRGB.red / 255f, fromRGB.green / 255f, fromRGB.blue / 255f, data.alpha / 255f); - Cairo.cairo_pattern_add_color_stop_rgba (pattern, 1, toRGB.red / 255f, toRGB.green / 255f, toRGB.blue / 255f, data.alpha / 255f); - Cairo.cairo_save(cairo); - Cairo.cairo_translate(cairo, x, y); - Cairo.cairo_scale(cairo, width, height); - Cairo.cairo_rectangle(cairo, 0, 0, 1, 1); - Cairo.cairo_set_source(cairo, pattern); - Cairo.cairo_fill(cairo); - Cairo.cairo_restore(cairo); - Cairo.cairo_pattern_destroy(pattern); - return; - } - final int redBits, greenBits, blueBits; - if (directColor) { - // RGB mapped display - redBits = getChannelWidth(visual.red_mask); - greenBits = getChannelWidth(visual.green_mask); - blueBits = getChannelWidth(visual.blue_mask); - } else { - // Index display - redBits = greenBits = blueBits = 0; - } - ImageData.fillGradientRectangle(this, data.device, - x, y, width, height, vertical, fromRGB, toRGB, - redBits, greenBits, blueBits); -} - -/** - * Computes the required channel width (depth) from a mask. - */ -static int getChannelWidth(int mask) { - int width = 0; - while (mask != 0) { - width += (mask & 1); - mask >>>= 1; - } - return width; -} - -/** - * Fills the interior of an oval, within the specified - * rectangular area, with the receiver's background - * color. - * - * @param x the x coordinate of the upper left corner of the oval to be filled - * @param y the y coordinate of the upper left corner of the oval to be filled - * @param width the width of the oval to be filled - * @param height the height of the oval to be filled - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #drawOval - */ -public void fillOval (int x, int y, int width, int height) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - checkGC(FILL); - if (width < 0) { - x = x + width; - width = -width; - } - if (height < 0) { - y = y + height; - height = -height; - } - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - if (width == height) { - Cairo.cairo_arc_negative(cairo, x + width / 2f, y + height / 2f, width / 2f, 0, 2 * (float)Compatibility.PI); - } else { - Cairo.cairo_save(cairo); - Cairo.cairo_translate(cairo, x + width / 2f, y + height / 2f); - Cairo.cairo_scale(cairo, width / 2f, height / 2f); - Cairo.cairo_arc_negative(cairo, 0, 0, 1, 0, 2 * (float)Compatibility.PI); - Cairo.cairo_restore(cairo); - } - Cairo.cairo_fill(cairo); - return; - } - OS.XFillArc (data.display, data.drawable, handle, x, y, width, height, 0, 23040); -} -/** - * Fills the path described by the parameter. - * <p> - * This operation requires the operating system's advanced - * graphics subsystem which may not be available on some - * platforms. - * </p> - * - * @param path the path to fill - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> - * </ul> - * - * @see Path - * - * @since 3.1 - */ -public void fillPath (Path path) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (path == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (path.handle == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - initCairo(); - checkGC(FILL); - int /*long*/ cairo = data.cairo; - int /*long*/ copy = Cairo.cairo_copy_path(path.handle); - if (copy == 0) SWT.error(SWT.ERROR_NO_HANDLES); - Cairo.cairo_append_path(cairo, copy); - Cairo.cairo_path_destroy(copy); - Cairo.cairo_fill(cairo); -} -/** - * Fills the interior of the closed polygon which is defined by the - * specified array of integer coordinates, using the receiver's - * background color. The array contains alternating x and y values - * which are considered to represent points which are the vertices of - * the polygon. Lines are drawn between each consecutive pair, and - * between the first pair and last pair in the array. - * - * @param pointArray an array of alternating x and y values which are the vertices of the polygon - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT if pointArray is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #drawPolygon - */ -public void fillPolygon(int[] pointArray) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - checkGC(FILL); - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - drawPolyline(cairo, pointArray, true); - Cairo.cairo_fill(cairo); - return; - } - short[] xPoints = new short[pointArray.length]; - for (int i = 0; i<pointArray.length;i++) { - xPoints[i] = (short) pointArray[i]; - } - OS.XFillPolygon(data.display, data.drawable, handle,xPoints, xPoints.length / 2, OS.Complex, OS.CoordModeOrigin); -} -/** - * Fills the interior of the rectangle specified by the arguments, - * using the receiver's background color. - * - * @param x the x coordinate of the rectangle to be filled - * @param y the y coordinate of the rectangle to be filled - * @param width the width of the rectangle to be filled - * @param height the height of the rectangle to be filled - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #drawRectangle(int, int, int, int) - */ -public void fillRectangle (int x, int y, int width, int height) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - checkGC(FILL); - if (width < 0) { - x = x + width; - width = -width; - } - if (height < 0) { - y = y + height; - height = -height; - } - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - Cairo.cairo_rectangle(cairo, x, y, width, height); - Cairo.cairo_fill(cairo); - return; - } - OS.XFillRectangle (data.display, data.drawable, handle, x, y, width, height); -} -/** - * Fills the interior of the specified rectangle, using the receiver's - * background color. - * - * @param rect the rectangle to be filled - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #drawRectangle(int, int, int, int) - */ -public void fillRectangle (Rectangle rect) { - if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - fillRectangle(rect.x, rect.y, rect.width, rect.height); -} -/** - * Fills the interior of the round-cornered rectangle specified by - * the arguments, using the receiver's background color. - * - * @param x the x coordinate of the rectangle to be filled - * @param y the y coordinate of the rectangle to be filled - * @param width the width of the rectangle to be filled - * @param height the height of the rectangle to be filled - * @param arcWidth the width of the arc - * @param arcHeight the height of the arc - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #drawRoundRectangle - */ -public void fillRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - checkGC(FILL); - 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; - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - if (naw == 0 || nah == 0) { - Cairo.cairo_rectangle(cairo, x, y, width, height); - } else { - float naw2 = naw / 2f; - float nah2 = nah / 2f; - float fw = nw / naw2; - float fh = nh / nah2; - Cairo.cairo_save(cairo); - Cairo.cairo_translate(cairo, nx, ny); - Cairo.cairo_scale(cairo, naw2, nah2); - Cairo.cairo_move_to(cairo, fw - 1, 0); - Cairo.cairo_arc(cairo, fw - 1, 1, 1, Compatibility.PI + Compatibility.PI/2.0, Compatibility.PI*2.0); - Cairo.cairo_arc(cairo, fw - 1, fh - 1, 1, 0, Compatibility.PI/2.0); - Cairo.cairo_arc(cairo, 1, fh - 1, 1, Compatibility.PI/2, Compatibility.PI); - Cairo.cairo_arc(cairo, 1, 1, 1, Compatibility.PI, 270.0*Compatibility.PI/180.0); - Cairo.cairo_close_path(cairo); - Cairo.cairo_restore(cairo); - } - Cairo.cairo_fill(cairo); - return; - } - int naw2 = naw / 2; - int nah2 = nah / 2; - int xDisplay = data.display; - int xDrawable = data.drawable; - if (nw > naw) { - if (nh > nah) { - OS.XFillArc(xDisplay, xDrawable, handle, nx, ny, naw, nah, 5760, 5760); - OS.XFillRectangle(xDisplay, xDrawable, handle, nx + naw2, ny, nw - naw2 * 2, nah2); - OS.XFillArc(xDisplay, xDrawable, handle, nx + nw - naw, ny, naw, nah, 0, 5760); - OS.XFillRectangle(xDisplay, xDrawable, handle, nx, ny + nah2, nw, nh - nah2 * 2); - OS.XFillArc(xDisplay, xDrawable, handle, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760); - OS.XFillRectangle(xDisplay, xDrawable, handle, nx + naw2, ny + nh - nah2, nw - naw2 * 2, nah2); - OS.XFillArc(xDisplay, xDrawable, handle, nx, ny + nh - nah, naw, nah, 11520, 5760); - } else { - OS.XFillArc(xDisplay, xDrawable, handle, nx, ny, naw, nh, 5760, 11520); - OS.XFillRectangle(xDisplay, xDrawable, handle, nx + naw2, ny, nw - naw2 * 2, nh); - OS.XFillArc(xDisplay, xDrawable, handle, nx + nw - naw, ny, naw, nh, 17280, 11520); - } - } else { - if (nh > nah) { - OS.XFillArc(xDisplay, xDrawable, handle, nx, ny, nw, nah, 0, 11520); - OS.XFillRectangle(xDisplay, xDrawable, handle, nx, ny + nah2, nw, nh - nah2 * 2); - OS.XFillArc(xDisplay, xDrawable, handle, nx, ny + nh - nah, nw, nah, 11520, 11520); - } else { - OS.XFillArc(xDisplay, xDrawable, handle, nx, ny, nw, nh, 0, 23040); - } - } -} -char fixMnemonic(char[] text) { - char mnemonic=0; - int i=0, j=0; - while (i < text.length) { - if ((text [j++] = text [i++]) == '&') { - if (i == text.length) {continue;} - if (text [i] == '&') {i++; continue;} - if (mnemonic == 0) mnemonic = text [i]; - j--; - } - } - while (j < text.length) text [j++] = 0; - return mnemonic; -} -/** - * Returns the <em>advance width</em> of the specified character in - * the font which is currently selected into the receiver. - * <p> - * The advance width is defined as the horizontal distance the cursor - * should move after printing the character in the selected font. - * </p> - * - * @param ch the character to measure - * @return the distance in the x direction to move past the character before painting the next - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int getAdvanceWidth(char ch) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - checkGC(FONT); - int fontList = data.font.handle; - byte[] charBuffer = Converter.wcsToMbcs(getCodePage (), new char[] { ch }, false); - int val = charBuffer[0] & 0xFF; - /* Create a font context to iterate over each element in the font list */ - int[] buffer = new int[1]; - if (!OS.XmFontListInitFontContext(buffer, fontList)) { - SWT.error(SWT.ERROR_NO_HANDLES); - } - int context = buffer[0]; - XFontStruct fontStruct = new XFontStruct(); - XCharStruct charStruct = new XCharStruct(); - int fontListEntry; - int[] fontStructPtr = new int[1]; - int[] fontNamePtr = new int[1]; - /* Go through each entry in the font list. */ - while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) { - int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer); - if (buffer[0] == 0) { - OS.memmove(fontStruct, fontPtr, XFontStruct.sizeof); - /* FontList contains a single font */ - if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) { - /* Single byte fontStruct */ - if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) { - /* The font contains the character */ - int charWidth = 0; - int perCharPtr = fontStruct.per_char; - if (perCharPtr == 0) { - /* - * If perCharPtr is 0 then all glyphs in the font have - * the same width as the font's maximum width. - */ - charWidth = fontStruct.max_bounds_width; - } else { - OS.memmove(charStruct, perCharPtr + ((val - fontStruct.min_char_or_byte2) * XCharStruct.sizeof), XCharStruct.sizeof); - charWidth = charStruct.width; - } - if (charWidth != 0) { - OS.XmFontListFreeFontContext(context); - return charWidth; - } - } - } else { - /* Double byte fontStruct */ - int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1; - int row = 0; - if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1; - int col = charBuffer[0] - fontStruct.min_char_or_byte2; - if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) { - /* The font contains the character */ - int charWidth = 0; - int perCharPtr = fontStruct.per_char; - if (perCharPtr == 0) { - /* - * If perCharPtr is 0 then all glyphs in the font have - * the same width as the font's maximum width. - */ - charWidth = fontStruct.max_bounds_width; - } else { - int offset = row * charsPerRow + col; - OS.memmove(charStruct, perCharPtr + offset * XCharStruct.sizeof, XCharStruct.sizeof); - charWidth = charStruct.width; - } - if (charWidth != 0) { - OS.XmFontListFreeFontContext(context); - return charWidth; - } - } - } - } else { - /* FontList contains a fontSet */ - int nFonts = OS.XFontsOfFontSet(fontPtr, fontStructPtr, fontNamePtr); - int [] fontStructs = new int[nFonts]; - OS.memmove(fontStructs, fontStructPtr[0], nFonts * 4); - /* Go through each fontStruct in the font set */ - for (int i = 0; i < nFonts; i++) { - OS.memmove(fontStruct, fontStructs[i], XFontStruct.sizeof); - if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) { - /* Single byte fontStruct */ - if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) { - /* The font contains the character */ - int charWidth = 0; - int perCharPtr = fontStruct.per_char; - if (perCharPtr == 0) { - /* - * If perCharPtr is 0 then all glyphs in the font have - * the same width as the font's maximum width. - */ - charWidth = fontStruct.max_bounds_width; - } else { - OS.memmove(charStruct, perCharPtr + ((val - fontStruct.min_char_or_byte2) * XCharStruct.sizeof), XCharStruct.sizeof); - charWidth = charStruct.width; - } - if (charWidth != 0) { - OS.XmFontListFreeFontContext(context); - return charWidth; - } - } - } else { - /* Double byte fontStruct */ - int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1; - int row = 0; - if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1; - int col = charBuffer[0] - fontStruct.min_char_or_byte2; - if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) { - /* The font contains the character */ - int charWidth = 0; - int perCharPtr = fontStruct.per_char; - if (perCharPtr == 0) { - /* - * If perCharPtr is 0 then all glyphs in the font have - * the same width as the font's maximum width. - */ - charWidth = fontStruct.max_bounds_width; - } else { - int offset = row * charsPerRow + col; - OS.memmove(charStruct, perCharPtr + offset * XCharStruct.sizeof, XCharStruct.sizeof); - charWidth = charStruct.width; - } - if (charWidth != 0) { - OS.XmFontListFreeFontContext(context); - return charWidth; - } - } - } - } - } - } - OS.XmFontListFreeFontContext(context); - return stringExtent(new String(new char[]{ch})).x; -} -/** - * Returns <code>true</code> if receiver is using the operating system's - * advanced graphics subsystem. Otherwise, <code>false</code> is returned - * to indicate that normal graphics are in use. - * <p> - * Advanced graphics may not be installed for the operating system. In this - * case, <code>false</code> is always returned. Some operating system have - * only one graphics subsystem. If this subsystem supports advanced graphics, - * then <code>true</code> is always returned. If any graphics operation such - * as alpha, antialias, patterns, interpolation, paths, clipping or transformation - * has caused the receiver to switch from regular to advanced graphics mode, - * <code>true</code> is returned. If the receiver has been explicitly switched - * to advanced mode and this mode is supported, <code>true</code> is returned. - * </p> - * - * @return the advanced value - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #setAdvanced - * - * @since 3.1 - */ -public boolean getAdvanced() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return data.cairo != 0; -} -/** - * Returns the receiver's alpha value. The alpha value - * is between 0 (transparent) and 255 (opaque). - * - * @return the alpha value - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public int getAlpha() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return data.alpha; -} -/** - * Returns the receiver's anti-aliasing setting value, which will be - * one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or - * <code>SWT.ON</code>. Note that this controls anti-aliasing for all - * <em>non-text drawing</em> operations. - * - * @return the anti-aliasing setting - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #getTextAntialias - * - * @since 3.1 - */ -public int getAntialias() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (data.cairo == 0) return SWT.DEFAULT; - int antialias = Cairo.cairo_get_antialias(data.cairo); - switch (antialias) { - case Cairo.CAIRO_ANTIALIAS_DEFAULT: return SWT.DEFAULT; - case Cairo.CAIRO_ANTIALIAS_NONE: return SWT.OFF; - case Cairo.CAIRO_ANTIALIAS_GRAY: - case Cairo.CAIRO_ANTIALIAS_SUBPIXEL: return SWT.ON; - } - return SWT.DEFAULT; -} -/** - * Returns the background color. - * - * @return the receiver's background color - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Color getBackground() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - XColor color = data.background; - if ((data.state & BACKGROUND_RGB) == 0) { - OS.XQueryColor(data.display, data.colormap, color); - data.state |= BACKGROUND_RGB; - } - return Color.motif_new(data.device, color); -} -/** - * Returns the background pattern. The default value is - * <code>null</code>. - * - * @return the receiver's background pattern - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see Pattern - * - * @since 3.1 - */ -public Pattern getBackgroundPattern() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return data.backgroundPattern; -} -/** - * Returns the width of the specified character in the font - * selected into the receiver. - * <p> - * The width is defined as the space taken up by the actual - * character, not including the leading and tailing whitespace - * or overhang. - * </p> - * - * @param ch the character to measure - * @return the width of the character - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int getCharWidth(char ch) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - checkGC(FONT); - int fontList = data.font.handle; - byte[] charBuffer = Converter.wcsToMbcs(getCodePage (), new char[] { ch }, false); - int val = charBuffer[0] & 0xFF; - /* Create a font context to iterate over each element in the font list */ - int[] buffer = new int[1]; - if (!OS.XmFontListInitFontContext(buffer, fontList)) { - SWT.error(SWT.ERROR_NO_HANDLES); - } - int context = buffer[0]; - XFontStruct fontStruct = new XFontStruct(); - XCharStruct charStruct = new XCharStruct(); - int fontListEntry; - int[] fontStructPtr = new int[1]; - int[] fontNamePtr = new int[1]; - /* Go through each entry in the font list. */ - while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) { - int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer); - if (buffer[0] == 0) { - OS.memmove(fontStruct, fontPtr, XFontStruct.sizeof); - /* FontList contains a single font */ - if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) { - /* Single byte fontStruct */ - if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) { - /* The font contains the character */ - int charWidth = 0; - int lBearing = 0; - int rBearing = 0; - int perCharPtr = fontStruct.per_char; - if (perCharPtr == 0) { - /* - * If perCharPtr is 0 then all glyphs in the font have - * the same width and left/right bearings as the font. - */ - charWidth = fontStruct.max_bounds_width; - lBearing = fontStruct.min_bounds_lbearing; - rBearing = fontStruct.max_bounds_rbearing; - } else { - OS.memmove(charStruct, perCharPtr + ((val - fontStruct.min_char_or_byte2) * XCharStruct.sizeof), XCharStruct.sizeof); - charWidth = charStruct.width; - lBearing = charStruct.lbearing; - rBearing = charStruct.rbearing; - } - if (charWidth != 0) { - OS.XmFontListFreeFontContext(context); - return rBearing - lBearing; - } - } - } else { - /* Double byte fontStruct */ - int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1; - int row = 0; - if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1; - int col = charBuffer[0] - fontStruct.min_char_or_byte2; - if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) { - /* The font contains the character */ - int charWidth = 0; - int lBearing = 0; - int rBearing = 0; - int perCharPtr = fontStruct.per_char; - if (perCharPtr == 0) { - /* - * If perCharPtr is 0 then all glyphs in the font have - * the same width and left/right bearings as the font. - */ - charWidth = fontStruct.max_bounds_width; - lBearing = fontStruct.min_bounds_lbearing; - rBearing = fontStruct.max_bounds_rbearing; - } else { - int offset = row * charsPerRow + col; - OS.memmove(charStruct, perCharPtr + offset * XCharStruct.sizeof, XCharStruct.sizeof); - charWidth = charStruct.width; - lBearing = charStruct.lbearing; - rBearing = charStruct.rbearing; - } - if (charWidth != 0) { - OS.XmFontListFreeFontContext(context); - return rBearing - lBearing; - } - } - } - } else { - /* FontList contains a fontSet */ - int nFonts = OS.XFontsOfFontSet(fontPtr, fontStructPtr, fontNamePtr); - int [] fontStructs = new int[nFonts]; - OS.memmove(fontStructs, fontStructPtr[0], nFonts * 4); - /* Go through each fontStruct in the font set */ - for (int i = 0; i < nFonts; i++) { - OS.memmove(fontStruct, fontStructs[i], XFontStruct.sizeof); - if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) { - /* Single byte fontStruct */ - if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) { - /* The font contains the character */ - int charWidth = 0; - int lBearing = 0; - int rBearing = 0; - int perCharPtr = fontStruct.per_char; - if (perCharPtr == 0) { - /* - * If perCharPtr is 0 then all glyphs in the font have - * the same width and left/right bearings as the font. - */ - charWidth = fontStruct.max_bounds_width; - lBearing = fontStruct.min_bounds_lbearing; - rBearing = fontStruct.max_bounds_rbearing; - } else { - OS.memmove(charStruct, perCharPtr + ((val - fontStruct.min_char_or_byte2) * XCharStruct.sizeof), XCharStruct.sizeof); - charWidth = charStruct.width; - lBearing = charStruct.lbearing; - rBearing = charStruct.rbearing; - } - if (charWidth != 0) { - OS.XmFontListFreeFontContext(context); - return rBearing - lBearing; - } - } - } else { - /* Double byte fontStruct */ - int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1; - int row = 0; - if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1; - int col = charBuffer[0] - fontStruct.min_char_or_byte2; - if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) { - /* The font contains the character */ - int charWidth = 0; - int lBearing = 0; - int rBearing = 0; - int perCharPtr = fontStruct.per_char; - if (perCharPtr == 0) { - /* - * If perCharPtr is 0 then all glyphs in the font have - * the same width and left/right bearings as the font. - */ - charWidth = fontStruct.max_bounds_width; - lBearing = fontStruct.min_bounds_lbearing; - rBearing = fontStruct.max_bounds_rbearing; - } else { - int offset = row * charsPerRow + col; - OS.memmove(charStruct, perCharPtr + offset * XCharStruct.sizeof, XCharStruct.sizeof); - charWidth = charStruct.width; - lBearing = charStruct.lbearing; - rBearing = charStruct.rbearing; - } - if (charWidth != 0) { - OS.XmFontListFreeFontContext(context); - return rBearing - lBearing; - } - } - } - } - } - } - OS.XmFontListFreeFontContext(context); - return stringExtent(new String(new char[]{ch})).x; -} -/** - * Returns the bounding rectangle of the receiver's clipping - * region. If no clipping region is set, the return value - * will be a rectangle which covers the entire bounds of the - * object the receiver is drawing on. - * - * @return the bounding rectangle of the clipping region - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Rectangle getClipping() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - /* Calculate visible bounds in device space */ - int x = 0, y = 0, width = 0, height = 0; - int[] w = new int[1], h = new int[1], unused = new int[1]; - OS.XGetGeometry(data.display, data.drawable, unused, unused, unused, w, h, unused, unused); - width = w[0]; - height = h[0]; - /* Intersect visible bounds with clipping in device space and then convert then to user space */ - int cairo = data.cairo; - int clipRgn = data.clipRgn; - int damageRgn = data.damageRgn; - if (clipRgn != 0 || damageRgn != 0 || cairo != 0) { - int rgn = OS.XCreateRegion (); - XRectangle rect = new XRectangle(); - rect.width = (short)width; - rect.height = (short)height; - OS.XUnionRectWithRegion(rect, rgn, rgn); - if (damageRgn != 0) { - OS.XIntersectRegion (damageRgn, rgn, rgn); - } - /* 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.XIntersectRegion(rgn, clipRgn, rgn); - OS.XDestroyRegion(clipRgn); - } else { - OS.XIntersectRegion(rgn, clipRgn, rgn); - } - } - /* Convert to user space */ - if (cairo != 0) { - double[] matrix = new double[6]; - Cairo.cairo_get_matrix(cairo, matrix); - Cairo.cairo_matrix_invert(matrix); - clipRgn = convertRgn(rgn, matrix); - OS.XDestroyRegion(rgn); - rgn = clipRgn; - } - OS.XClipBox(rgn, rect); - OS.XDestroyRegion(rgn); - x = rect.x; - y = rect.y; - width = rect.width; - height = rect.height; - } - return new Rectangle(x, y, width, height); -} -/** - * Sets the region managed by the argument to the current - * clipping region of the receiver. - * - * @param region the region to fill with the clipping region - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the region is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the region is disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void getClipping(Region region) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - int clipping = region.handle; - OS.XSubtractRegion (clipping, clipping, clipping); - int /*long*/ cairo = data.cairo; - int clipRgn = data.clipRgn; - if (clipRgn == 0) { - int[] width = new int[1], height = new int[1], unused = new int[1]; - OS.XGetGeometry(data.display, data.drawable, unused, unused, unused, width, height, unused, unused); - XRectangle rect = new XRectangle(); - rect.x = 0; - rect.y = 0; - rect.width = (short)width[0]; - rect.height = (short)height[0]; - OS.XUnionRectWithRegion(rect, clipping, clipping); - } else { - /* Convert clipping to device space if needed */ - if (data.clippingTransform != null) { - int rgn = convertRgn(clipRgn, data.clippingTransform); - OS.XUnionRegion(clipping, rgn, clipping); - OS.XDestroyRegion(rgn); - } else { - OS.XUnionRegion(clipping, clipRgn, clipping); - } - } - if (data.damageRgn != 0) { - OS.XIntersectRegion(clipping, data.damageRgn, clipping); - } - /* Convert to user space */ - if (cairo != 0) { - double[] matrix = new double[6]; - Cairo.cairo_get_matrix(cairo, matrix); - Cairo.cairo_matrix_invert(matrix); - int rgn = convertRgn(clipping, matrix); - OS.XSubtractRegion(clipping, clipping, clipping); - OS.XUnionRegion(clipping, rgn, clipping); - OS.XDestroyRegion(rgn); - } -} -String getCodePage () { - return data.font.codePage; -} -/** - * Returns the receiver's fill rule, which will be one of - * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>. - * - * @return the receiver's fill rule - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public int getFillRule() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - XGCValues values = new XGCValues(); - OS.XGetGCValues(data.display, handle, OS.GCFillRule, values); - return values.fill_rule == OS.WindingRule ? SWT.FILL_WINDING : SWT.FILL_EVEN_ODD; -} -/** - * Returns the font currently being used by the receiver - * to draw and measure text. - * - * @return the receiver's font - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Font getFont () { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return Font.motif_new(data.device, data.font.handle); -} -int getFontHeight () { - int fontList = data.font.handle; - /* Create a font context to iterate over each element in the font list */ - int [] buffer = new int [1]; - if (!OS.XmFontListInitFontContext (buffer, fontList)) { - SWT.error(SWT.ERROR_NO_HANDLES); - } - int context = buffer [0]; - - /* Values discovering during iteration */ - int height = 0; - XFontStruct fontStruct = new XFontStruct (); - int fontListEntry; - int [] fontStructPtr = new int [1]; - int [] fontNamePtr = new int [1]; - - /* Go through each entry in the font list. */ - while ((fontListEntry = OS.XmFontListNextEntry (context)) != 0) { - int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer); - if (buffer [0] == 0) { - /* FontList contains a single font */ - OS.memmove (fontStruct, fontPtr, XFontStruct.sizeof); - int fontHeight = fontStruct.ascent + fontStruct.descent; - height = Math.max(height, fontHeight); - } else { - /* FontList contains a fontSet */ - int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr); - int [] fontStructs = new int [nFonts]; - OS.memmove (fontStructs, fontStructPtr [0], nFonts * 4); - - /* Go through each fontStruct in the font set */ - for (int i=0; i<nFonts; i++) { - OS.memmove (fontStruct, fontStructs[i], XFontStruct.sizeof); - int fontHeight = fontStruct.ascent + fontStruct.descent; - height = Math.max(height, fontHeight); - } - } - } - - OS.XmFontListFreeFontContext (context); - return height; -} -/** - * Returns a FontMetrics which contains information - * about the font currently being used by the receiver - * to draw and measure text. - * - * @return font metrics for the receiver's font - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public FontMetrics getFontMetrics() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - checkGC(FONT); - int xDisplay = data.display; - Font font = data.font; - int fontList = font.handle; - /* Create a font context to iterate over each element in the font list */ - int[] buffer = new int[1]; - if (!OS.XmFontListInitFontContext(buffer, fontList)) { - SWT.error(SWT.ERROR_NO_HANDLES); - } - int context = buffer[0]; - /* Values discovering during iteration */ - int ascent = 0; - int descent = 0; - int averageCharWidth = 0, numAverageCharWidth = 0; - int leading = 0; - int height = 0; - - XFontStruct fontStruct = new XFontStruct(); - int fontListEntry; - int[] fontStructPtr = new int[1]; - int[] fontNamePtr = new int[1]; - /* Go through each entry in the font list. */ - while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) { - int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer); - if (buffer[0] == 0) { - /* FontList contains a single font */ - OS.memmove(fontStruct, fontPtr, XFontStruct.sizeof); - ascent = Math.max(ascent, fontStruct.ascent); - descent = Math.max(descent, fontStruct.descent); - int fontHeight = fontStruct.ascent + fontStruct.descent; - height = Math.max(height, fontHeight); - /* Calculate average character width */ - int propPtr = fontStruct.properties; - for (int i = 0; i < fontStruct.n_properties; i++) { - /* Look through properties for XAFONT */ - int[] prop = new int[2]; - OS.memmove(prop, propPtr, 8); - if (prop[0] == OS.XA_FONT) { - /* Found it, prop[1] points to the string */ - int ptr = OS.XmGetAtomName(xDisplay, prop[1]); - int length = OS.strlen(ptr); - byte[] nameBuf = new byte[length]; - OS.memmove(nameBuf, ptr, length); - OS.XFree(ptr); - String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase(); - int avg = 0; - try { - avg = FontData.motif_new(xlfd).averageWidth / 10; - } catch (Exception e) { - // leave avg unchanged so that it will be computed below - } - if (avg == 0) { - /* - * Not all fonts have average character width encoded - * in the xlfd. This one doesn't, so do it the hard - * way by averaging all the character widths. - */ - int perCharPtr = fontStruct.per_char; - if (perCharPtr == 0) { - /* - * If perCharPtr is 0 then all glyphs in the font have - * the same width as the font's maximum width. So no - * averaging is required. - */ - averageCharWidth = fontStruct.max_bounds_width; - } else { - int sum = 0, count = 0; - int cols = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1; - XCharStruct struct = new XCharStruct(); - for (int index = 0; index < cols; index++) { - OS.memmove(struct, perCharPtr + (index * XCharStruct.sizeof), XCharStruct.sizeof); - int w = struct.width; - if (w != 0) { - sum += w; - count++; - } - } - averageCharWidth += sum / count; - } - } else { - /* Average character width was in the xlfd */ - averageCharWidth += avg; - } - numAverageCharWidth++; - break; - } - propPtr += 8; - } - } else { - /* FontList contains a fontSet */ - int nFonts = OS.XFontsOfFontSet(fontPtr, fontStructPtr, fontNamePtr); - int [] fontStructs = new int[nFonts]; - OS.memmove(fontStructs, fontStructPtr[0], nFonts * 4); - /* Go through each fontStruct in the font set */ - for (int i = 0; i < nFonts; i++) { - OS.memmove(fontStruct, fontStructs[i], XFontStruct.sizeof); - ascent = Math.max(ascent, fontStruct.ascent); - descent = Math.max(descent, fontStruct.descent); - int fontHeight = fontStruct.ascent + fontStruct.descent; - height = Math.max(height, fontHeight); - /* Calculate average character width */ - int propPtr = fontStruct.properties; - for (int j = 0; j < fontStruct.n_properties; j++) { - /* Look through properties for XAFONT */ - int[] prop = new int[2]; - OS.memmove(prop, propPtr, 8); - if (prop[0] == OS.XA_FONT) { - /* Found it, prop[1] points to the string */ - int ptr = OS.XmGetAtomName(xDisplay, prop[1]); - int length = OS.strlen(ptr); - byte[] nameBuf = new byte[length]; - OS.memmove(nameBuf, ptr, length); - OS.XFree(ptr); - String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase(); - int avg = 0; - try { - avg = FontData.motif_new(xlfd).averageWidth / 10; - } catch (Exception e) { - /* - * Some font servers, for example, xfstt, do not pass - * reasonable font properties to the client, so we - * cannot construct a FontData for these. Use the font - * name instead. - */ - int[] fontName = new int[1]; - OS.memmove(fontName, fontNamePtr [0] + (i * 4), 4); - ptr = fontName[0]; - if (ptr != 0 ) { - length = OS.strlen(ptr); - nameBuf = new byte[length]; - OS.memmove(nameBuf, ptr, length); - xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase(); - try { - avg = FontData.motif_new(xlfd).averageWidth / 10; - } catch (Exception ex) { - // leave avg unchanged (0) so that it will be computed below - } - } - } - if (avg == 0) { - /* - * Not all fonts have average character width encoded - * in the xlfd. This one doesn't, so do it the hard - * way by averaging all the character widths. - */ - int perCharPtr = fontStruct.per_char; - if (perCharPtr == 0) { - /* - * If perCharPtr is 0 then all glyphs in the font have - * the same width as the font's maximum width. So no - * averaging is required. - */ - averageCharWidth = fontStruct.max_bounds_width; - } else { - int sum = 0, count = 0; - int cols = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1; - XCharStruct struct = new XCharStruct(); - for (int index = 0; index < cols; index++) { - OS.memmove(struct, perCharPtr + (index * XCharStruct.sizeof), XCharStruct.sizeof); - int w = struct.width; - if (w != 0) { - sum += w; - count++; - } - } - averageCharWidth += sum / count; - } - } else { - /* Average character width was in the xlfd */ - averageCharWidth += avg; - } - numAverageCharWidth++; - break; - } - propPtr += 8; - } - } - } - } - OS.XmFontListFreeFontContext(context); - return FontMetrics.motif_new(ascent, descent, averageCharWidth / numAverageCharWidth, leading, height); -} -/** - * Returns the receiver's foreground color. - * - * @return the color used for drawing foreground things - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Color getForeground() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - XColor color = data.foreground; - if ((data.state & FOREGROUND_RGB) == 0) { - OS.XQueryColor(data.display, data.colormap, color); - data.state |= FOREGROUND_RGB; - } - return Color.motif_new(data.device, color); -} -/** - * Returns the foreground pattern. The default value is - * <code>null</code>. - * - * @return the receiver's foreground pattern - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see Pattern - * - * @since 3.1 - */ -public Pattern getForegroundPattern() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return data.foregroundPattern; -} -/** - * Returns the GCData. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>GC</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @return the receiver's GCData - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see GCData - * - * @since 3.2 - * @noreference This method is not intended to be referenced by clients. - */ -public GCData getGCData() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return data; -} -/** - * Returns the receiver's interpolation setting, which will be one of - * <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>, - * <code>SWT.LOW</code> or <code>SWT.HIGH</code>. - * - * @return the receiver's interpolation setting - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public int getInterpolation() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return data.interpolation; -} -/** - * Returns the receiver's line attributes. - * - * @return the line attributes used for drawing lines - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.3 - */ -public LineAttributes getLineAttributes() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - float[] dashes = null; - if (data.lineDashes != null) { - dashes = new float[data.lineDashes.length]; - System.arraycopy(data.lineDashes, 0, dashes, 0, dashes.length); - } - return new LineAttributes(data.lineWidth, data.lineCap, data.lineJoin, data.lineStyle, dashes, data.lineDashesOffset, data.lineMiterLimit); -} -/** - * Returns the receiver's line cap style, which will be one - * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>, - * or <code>SWT.CAP_SQUARE</code>. - * - * @return the cap style used for drawing lines - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public int getLineCap() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return data.lineCap; -} -/** - * Returns the receiver's line dash style. The default value is - * <code>null</code>. - * - * @return the line dash style used for drawing lines - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public int[] getLineDash() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (data.lineDashes == null) return null; - int[] lineDashes = new int[data.lineDashes.length]; - for (int i = 0; i < lineDashes.length; i++) { - lineDashes[i] = (int)data.lineDashes[i]; - } - return lineDashes; -} -/** - * Returns the receiver's line join style, which will be one - * of the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>, - * or <code>SWT.JOIN_BEVEL</code>. - * - * @return the join style used for drawing lines - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public int getLineJoin() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return data.lineJoin; -} -/** - * Returns the receiver's line style, which will be one - * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>, - * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or - * <code>SWT.LINE_DASHDOTDOT</code>. - * - * @return the style used for drawing lines - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int getLineStyle() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return data.lineStyle; -} -/** - * Returns the width that will be used when drawing lines - * for all of the figure drawing operations (that is, - * <code>drawLine</code>, <code>drawRectangle</code>, - * <code>drawPolyline</code>, and so forth. - * - * @return the receiver's line width - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int getLineWidth() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return (int)data.lineWidth; -} -/** - * Returns the receiver's style information. - * <p> - * Note that the value which is returned by this method <em>may - * not match</em> the value which was provided to the constructor - * when the receiver was created. This can occur when the underlying - * operating system does not support a particular combination of - * requested styles. - * </p> - * - * @return the style bits - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 2.1.2 - */ -public int getStyle () { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return data.style; -} -/** - * Returns the receiver's text drawing anti-aliasing setting value, - * which will be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> or - * <code>SWT.ON</code>. Note that this controls anti-aliasing - * <em>only</em> for text drawing operations. - * - * @return the anti-aliasing setting - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #getAntialias - * - * @since 3.1 - */ -public int getTextAntialias() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (data.cairo == 0) return SWT.DEFAULT; - int /*long*/ options = Cairo.cairo_font_options_create(); - Cairo.cairo_get_font_options(data.cairo, options); - int antialias = Cairo.cairo_font_options_get_antialias(options); - Cairo.cairo_font_options_destroy(options); - switch (antialias) { - case Cairo.CAIRO_ANTIALIAS_DEFAULT: return SWT.DEFAULT; - case Cairo.CAIRO_ANTIALIAS_NONE: return SWT.OFF; - case Cairo.CAIRO_ANTIALIAS_GRAY: - case Cairo.CAIRO_ANTIALIAS_SUBPIXEL: return SWT.ON; - } - return SWT.DEFAULT; -} -/** - * Sets the parameter to the transform that is currently being - * used by the receiver. - * - * @param transform the destination to copy the transform into - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see Transform - * - * @since 3.1 - */ -public void getTransform(Transform transform) { - 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); - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - Cairo.cairo_get_matrix(cairo, transform.handle); - } else { - transform.setElements(1, 0, 0, 1, 0, 0); - } -} -/** - * Returns <code>true</code> if this GC is drawing in the mode - * where the resulting color in the destination is the - * <em>exclusive or</em> of the color values in the source - * and the destination, and <code>false</code> if it is - * drawing in the mode where the destination color is being - * replaced with the source color value. - * - * @return <code>true</code> true if the receiver is in XOR mode, and false otherwise - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public boolean getXORMode() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - XGCValues values = new XGCValues (); - OS.XGetGCValues (data.display, handle, OS.GCFunction, values); - return values.function == OS.GXxor; -} -/** - * Returns an integer hash code for the receiver. Any two - * objects that return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #equals - */ -public int hashCode () { - return handle; -} -void init(Drawable drawable, GCData data, int xGC) { - if (data.foreground != null) data.state &= ~(FOREGROUND | FOREGROUND_RGB); - if (data.background != null) data.state &= ~(BACKGROUND | BACKGROUND_BG | BACKGROUND_RGB); - if (data.font != null) data.state &= ~FONT; - Image image = data.image; - if (image != null) { - image.memGC = this; - /* - * The transparent pixel mask might change when drawing on - * the image. Destroy it so that it is regenerated when - * necessary. - */ - if (image.transparentPixel != -1) image.destroyMask(); - } - this.drawable = drawable; - this.data = data; - handle = xGC; -} -void initCairo() { - data.device.checkCairo(); - int /*long*/ cairo = data.cairo; - if (cairo != 0) return; - int xDisplay = data.display; - int xDrawable = data.drawable; - int xVisual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay)); - int[] width = new int[1], height = new int[1], unused = new int[1]; - OS.XGetGeometry(xDisplay, xDrawable, unused, unused, unused, width, height, unused, unused); - int /*long*/ surface = Cairo.cairo_xlib_surface_create(xDisplay, xDrawable, xVisual, width[0], height[0]); - if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES); - data.cairo = cairo = Cairo.cairo_create(surface); - Cairo.cairo_surface_destroy(surface); - if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES); - Cairo.cairo_set_fill_rule(cairo, Cairo.CAIRO_FILL_RULE_EVEN_ODD); - data.state &= ~(BACKGROUND | FOREGROUND | FONT | LINE_WIDTH | LINE_CAP | LINE_JOIN | LINE_STYLE | DRAW_OFFSET); - setCairoClip(data.damageRgn, data.clipRgn); -} -/** - * Returns <code>true</code> if the receiver has a clipping - * region set into it, and <code>false</code> otherwise. - * If this method returns false, the receiver will draw on all - * available space in the destination. If it returns true, - * it will draw only in the area that is covered by the region - * that can be accessed with <code>getClipping(region)</code>. - * - * @return <code>true</code> if the GC has a clipping region, and <code>false</code> otherwise - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public boolean isClipped() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return data.clipRgn != 0; -} -/** - * Returns <code>true</code> if the GC has been disposed, - * and <code>false</code> otherwise. - * <p> - * This method gets the dispose state for the GC. - * When a GC has been disposed, it is an error to - * invoke any other method using the GC. - * - * @return <code>true</code> when the GC is disposed and <code>false</code> otherwise - */ -public boolean isDisposed() { - return handle == 0; -} -boolean isIdentity(double[] matrix) { - if (matrix == null) return true; - return matrix[0] == 1 && matrix[1] == 0 && matrix[2] == 0 && matrix[3] == 1 && matrix[4] == 0 && matrix[5] == 0; -} -/** - * Sets the receiver to always use the operating system's advanced graphics - * subsystem for all graphics operations if the argument is <code>true</code>. - * If the argument is <code>false</code>, the advanced graphics subsystem is - * no longer used, advanced graphics state is cleared and the normal graphics - * subsystem is used from now on. - * <p> - * Normally, the advanced graphics subsystem is invoked automatically when - * any one of the alpha, antialias, patterns, interpolation, paths, clipping - * or transformation operations in the receiver is requested. When the receiver - * is switched into advanced mode, the advanced graphics subsystem performs both - * advanced and normal graphics operations. Because the two subsystems are - * different, their output may differ. Switching to advanced graphics before - * any graphics operations are performed ensures that the output is consistent. - * </p><p> - * Advanced graphics may not be installed for the operating system. In this - * case, this operation does nothing. Some operating system have only one - * graphics subsystem, so switching from normal to advanced graphics does - * nothing. However, switching from advanced to normal graphics will always - * clear the advanced graphics state, even for operating systems that have - * only one graphics subsystem. - * </p> - * - * @param advanced the new advanced graphics state - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #setAlpha - * @see #setAntialias - * @see #setBackgroundPattern - * @see #setClipping(Path) - * @see #setForegroundPattern - * @see #setLineAttributes - * @see #setInterpolation - * @see #setTextAntialias - * @see #setTransform - * @see #getAdvanced - * - * @since 3.1 - */ -public void setAdvanced(boolean advanced) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (advanced && data.cairo != 0) return; - if (advanced) { - try { - initCairo(); - } catch (SWTException e) {} - } else { - int /*long*/ cairo = data.cairo; - if (cairo != 0) Cairo.cairo_destroy(cairo); - data.cairo = 0; - data.interpolation = SWT.DEFAULT; - data.backgroundPattern = data.foregroundPattern = null; - data.state = 0; - setClipping(0); - } -} -/** - * Sets the receiver's alpha value which must be - * between 0 (transparent) and 255 (opaque). - * <p> - * This operation requires the operating system's advanced - * graphics subsystem which may not be available on some - * platforms. - * </p> - * @param alpha the alpha value - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> - * </ul> - * - * @see #getAdvanced - * @see #setAdvanced - * - * @since 3.1 - */ -public void setAlpha(int alpha) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (data.cairo == 0 && (alpha & 0xff) == 0xff) return; - initCairo(); - data.alpha = alpha & 0xff; - data.state &= ~(BACKGROUND | FOREGROUND | BACKGROUND_BG); -} -/** - * Sets the receiver's anti-aliasing value to the parameter, - * which must be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> - * or <code>SWT.ON</code>. Note that this controls anti-aliasing for all - * <em>non-text drawing</em> operations. - * <p> - * This operation requires the operating system's advanced - * graphics subsystem which may not be available on some - * platforms. - * </p> - * - * @param antialias the anti-aliasing setting - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one of <code>SWT.DEFAULT</code>, - * <code>SWT.OFF</code> or <code>SWT.ON</code></li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> - * </ul> - * - * @see #getAdvanced - * @see #setAdvanced - * @see #setTextAntialias - * - * @since 3.1 - */ -public void setAntialias(int antialias) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (data.cairo == 0 && antialias == SWT.DEFAULT) return; - int mode = 0; - switch (antialias) { - case SWT.DEFAULT: mode = Cairo.CAIRO_ANTIALIAS_DEFAULT; break; - case SWT.OFF: mode = Cairo.CAIRO_ANTIALIAS_NONE; break; - case SWT.ON: mode = Cairo.CAIRO_ANTIALIAS_GRAY; - break; - default: - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - initCairo(); - int /*long*/ cairo = data.cairo; - Cairo.cairo_set_antialias(cairo, mode); -} -/** - * Invokes platform specific functionality to allocate a new graphics context. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>GC</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @param drawable the Drawable for the receiver. - * @param data the data for the receiver. - * - * @return a new <code>GC</code> - */ -public static GC motif_new(Drawable drawable, GCData data) { - GC gc = new GC(); - int xGC = drawable.internal_new_GC(data); - gc.device = data.device; - gc.init(drawable, data, xGC); - return gc; -} -/** - * Invokes platform specific functionality to wrap a graphics context. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>GC</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @param xGC the X Windows graphics context. - * @param data the data for the receiver. - * - * @return a new <code>GC</code> - */ -public static GC motif_new(int xGC, GCData data) { - GC gc = new GC(); - gc.device = data.device; - gc.init(null, data, xGC); - return gc; -} -/** - * Sets the background color. The background color is used - * for fill operations and as the background color when text - * is drawn. - * - * @param color the new background color for the receiver - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the color is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setBackground (Color color) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - data.background = color.handle; - data.backgroundPattern = null; - data.state &= ~(BACKGROUND | BACKGROUND_BG); - data.state |= BACKGROUND_RGB; -} -/** - * Sets the background pattern. The default value is <code>null</code>. - * <p> - * This operation requires the operating system's advanced - * graphics subsystem which may not be available on some - * platforms. - * </p> - * - * @param pattern the new background pattern - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> - * </ul> - * - * @see Pattern - * @see #getAdvanced - * @see #setAdvanced - * - * @since 3.1 - */ -public void setBackgroundPattern(Pattern pattern) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (data.cairo == 0 && pattern == null) return; - initCairo(); - if (data.backgroundPattern == pattern) return; - data.backgroundPattern = pattern; - data.state &= ~BACKGROUND; -} -static void setCairoFont(int /*long*/ cairo, Font font) { - //TODO - use X font instead of loading new one??? - FontData[] fds = font.getFontData(); - FontData fd = fds[0]; - int style = fd.getStyle(); - int slant = Cairo.CAIRO_FONT_SLANT_NORMAL; - if ((style & SWT.ITALIC) != 0) slant = Cairo.CAIRO_FONT_SLANT_ITALIC; - int weight = Cairo.CAIRO_FONT_WEIGHT_NORMAL; - if ((style & SWT.BOLD) != 0) weight = Cairo.CAIRO_FONT_WEIGHT_BOLD; - String name = fd.getName(); - int index = name.indexOf('-'); - if (index != -1) name = name.substring(index + 1); - byte[] buffer = Converter.wcsToMbcs(null, name, true); - Cairo.cairo_select_font_face(cairo, buffer, slant, weight); - Cairo.cairo_set_font_size(cairo, fd.getHeight()); -} -static void setCairoRegion(int /*long*/ cairo, int /*long*/ rgn) { - //TODO - get rectangles from region instead of clip box - XRectangle rect = new XRectangle(); - OS.XClipBox(rgn, rect); - Cairo.cairo_rectangle(cairo, rect.x, rect.y, rect.width, rect.height); -} -static void setCairoPatternColor(int /*long*/ pattern, int offset, Color c, int alpha) { - XColor color = c.handle; - double aa = (alpha & 0xFF) / (double)0xFF; - double red = ((color.red & 0xFFFF) / (double)0xFFFF); - double green = ((color.green & 0xFFFF) / (double)0xFFFF); - double blue = ((color.blue & 0xFFFF) / (double)0xFFFF); - Cairo.cairo_pattern_add_color_stop_rgba(pattern, offset, red, green, blue, aa); -} -void setCairoClip(int /*long*/ damageRgn, int /*long*/ clipRgn) { - int /*long*/ cairo = data.cairo; - Cairo.cairo_reset_clip(cairo); - if (damageRgn != 0) { - double[] matrix = new double[6]; - Cairo.cairo_get_matrix(cairo, matrix); - Cairo.cairo_identity_matrix(cairo); - setCairoRegion(cairo, damageRgn); - Cairo.cairo_clip(cairo); - Cairo.cairo_set_matrix(cairo, matrix); - } - if (clipRgn != 0) { - setCairoRegion(cairo, clipRgn); - Cairo.cairo_clip(cairo); - } -} -void setClipping(int clipRgn) { - int /*long*/ cairo = data.cairo; - if (clipRgn == 0) { - if (data.clipRgn != 0) { - OS.XDestroyRegion (data.clipRgn); - data.clipRgn = 0; - } - if (cairo != 0) { - data.clippingTransform = null; - setCairoClip(data.damageRgn, 0); - } else { - if (data.damageRgn == 0) { - OS.XSetClipMask (data.display, handle, OS.None); - } else { - OS.XSetRegion (data.display, handle, data.damageRgn); - } - } - } else { - if (data.clipRgn == 0) data.clipRgn = OS.XCreateRegion (); - OS.XSubtractRegion (data.clipRgn, data.clipRgn, data.clipRgn); - OS.XUnionRegion (clipRgn, data.clipRgn, data.clipRgn); - if (cairo != 0) { - if (data.clippingTransform == null) data.clippingTransform = new double[6]; - Cairo.cairo_get_matrix(cairo, data.clippingTransform); - setCairoClip(data.damageRgn, clipRgn); - } else { - int clipping = clipRgn; - if (data.damageRgn != 0) { - clipping = OS.XCreateRegion(); - OS.XUnionRegion(clipping, clipRgn, clipping); - OS.XIntersectRegion(clipping, data.damageRgn, clipping); - } - OS.XSetRegion (data.display, handle, clipping); - if (clipping != clipRgn) OS.XDestroyRegion(clipping); - } - } -} -/** - * Sets the area of the receiver which can be changed - * by drawing operations to the rectangular area specified - * by the arguments. - * - * @param x the x coordinate of the clipping rectangle - * @param y the y coordinate of the clipping rectangle - * @param width the width of the clipping rectangle - * @param height the height of the clipping rectangle - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setClipping (int x, int y, int width, int height) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (width < 0) { - x = x + width; - width = -width; - } - if (height < 0) { - y = y + height; - height = -height; - } - XRectangle rect = new XRectangle (); - rect.x = (short) x; - rect.y = (short) y; - rect.width = (short) Math.max (0, width); - rect.height = (short) Math.max (0, height); - int clipRgn = OS.XCreateRegion(); - OS.XUnionRectWithRegion(rect, clipRgn, clipRgn); - setClipping(clipRgn); - OS.XDestroyRegion(clipRgn); -} -/** - * Sets the area of the receiver which can be changed - * by drawing operations to the path specified - * by the argument. - * <p> - * This operation requires the operating system's advanced - * graphics subsystem which may not be available on some - * platforms. - * </p> - * - * @param path the clipping path. - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the path has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> - * </ul> - * - * @see Path - * @see #getAdvanced - * @see #setAdvanced - * - * @since 3.1 - */ -public void setClipping(Path path) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (path != null && path.isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - setClipping(0); - if (path != null) { - initCairo(); - int /*long*/ cairo = data.cairo; - int /*long*/ copy = Cairo.cairo_copy_path(path.handle); - if (copy == 0) SWT.error(SWT.ERROR_NO_HANDLES); - Cairo.cairo_append_path(cairo, copy); - Cairo.cairo_path_destroy(copy); - Cairo.cairo_clip(cairo); - Cairo.cairo_new_path(cairo); - } -} -/** - * Sets the area of the receiver which can be changed - * by drawing operations to the rectangular area specified - * by the argument. Specifying <code>null</code> for the - * rectangle reverts the receiver's clipping area to its - * original value. - * - * @param rect the clipping rectangle or <code>null</code> - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setClipping (Rectangle rect) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (rect == null) { - 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 <code>null</code> for the - * region reverts the receiver's clipping area to its - * original value. - * - * @param region the clipping region or <code>null</code> - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setClipping (Region region) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (region != null && region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - setClipping(region != null ? region.handle : 0); -} -/** - * Sets the receiver's fill rule to the parameter, which must be one of - * <code>SWT.FILL_EVEN_ODD</code> or <code>SWT.FILL_WINDING</code>. - * - * @param rule the new fill rule - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of <code>SWT.FILL_EVEN_ODD</code> - * or <code>SWT.FILL_WINDING</code></li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public void setFillRule(int rule) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - int mode = OS.EvenOddRule, cairo_mode = Cairo.CAIRO_FILL_RULE_EVEN_ODD; - switch (rule) { - case SWT.FILL_WINDING: - mode = OS.WindingRule; cairo_mode = Cairo.CAIRO_FILL_RULE_WINDING; break; - case SWT.FILL_EVEN_ODD: - mode = OS.EvenOddRule; cairo_mode = Cairo.CAIRO_FILL_RULE_EVEN_ODD; break; - default: - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - OS.XSetFillRule(data.display, handle, mode); - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - Cairo.cairo_set_fill_rule(cairo, cairo_mode); - } -} -/** - * Sets the font which will be used by the receiver - * to draw and measure text to the argument. If the - * argument is null, then a default font appropriate - * for the platform will be used instead. - * - * @param font the new font for the receiver, or null to indicate a default font - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setFont (Font font) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - data.font = font != null ? font : data.device.systemFont; - data.state &= ~FONT; - if (data.renderTable != 0) OS.XmRenderTableFree(data.renderTable); - data.renderTable = 0; - data.stringWidth = data.stringHeight = data.textWidth = data.textHeight = -1; -} -/** - * Sets the foreground color. The foreground color is used - * for drawing operations including when text is drawn. - * - * @param color the new foreground color for the receiver - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the color is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setForeground (Color color) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - data.foreground = color.handle; - data.foregroundPattern = null; - data.state &= ~FOREGROUND; - data.state |= FOREGROUND_RGB; -} -/** - * Sets the foreground pattern. The default value is <code>null</code>. - * <p> - * This operation requires the operating system's advanced - * graphics subsystem which may not be available on some - * platforms. - * </p> - * @param pattern the new foreground pattern - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> - * </ul> - * - * @see Pattern - * @see #getAdvanced - * @see #setAdvanced - * - * @since 3.1 - */ -public void setForegroundPattern(Pattern pattern) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (pattern != null && pattern.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (data.cairo == 0 && pattern == null) return; - initCairo(); - if (data.foregroundPattern == pattern) return; - data.foregroundPattern = pattern; - data.state &= ~FOREGROUND; -} -/** - * Sets the receiver's interpolation setting to the parameter, which - * must be one of <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>, - * <code>SWT.LOW</code> or <code>SWT.HIGH</code>. - * <p> - * This operation requires the operating system's advanced - * graphics subsystem which may not be available on some - * platforms. - * </p> - * - * @param interpolation the new interpolation setting - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the rule is not one of <code>SWT.DEFAULT</code>, - * <code>SWT.NONE</code>, <code>SWT.LOW</code> or <code>SWT.HIGH</code> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> - * </ul> - * - * @see #getAdvanced - * @see #setAdvanced - * - * @since 3.1 - */ -public void setInterpolation(int interpolation) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (data.cairo == 0 && interpolation == SWT.DEFAULT) return; - switch (interpolation) { - case SWT.DEFAULT: - case SWT.NONE: - case SWT.LOW: - case SWT.HIGH: - break; - default: - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - initCairo(); - data.interpolation = interpolation; -} -/** - * Sets the receiver's line attributes. - * <p> - * This operation requires the operating system's advanced - * graphics subsystem which may not be available on some - * platforms. - * </p> - * @param attributes the line attributes - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the attributes is null</li> - * <li>ERROR_INVALID_ARGUMENT - if any of the line attributes is not valid</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> - * </ul> - * - * @see LineAttributes - * @see #getAdvanced - * @see #setAdvanced - * - * @since 3.3 - */ -public void setLineAttributes(LineAttributes attributes) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (attributes == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - int mask = 0; - float lineWidth = attributes.width; - if (lineWidth != data.lineWidth) { - mask |= LINE_WIDTH | DRAW_OFFSET; - } - int lineStyle = attributes.style; - if (lineStyle != data.lineStyle) { - mask |= LINE_STYLE; - switch (lineStyle) { - case SWT.LINE_SOLID: - case SWT.LINE_DASH: - case SWT.LINE_DOT: - case SWT.LINE_DASHDOT: - case SWT.LINE_DASHDOTDOT: - break; - case SWT.LINE_CUSTOM: - if (attributes.dash == null) lineStyle = SWT.LINE_SOLID; - break; - default: - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - } - int join = attributes.join; - if (join != data.lineJoin) { - mask |= LINE_JOIN; - switch (join) { - case SWT.CAP_ROUND: - case SWT.CAP_FLAT: - case SWT.CAP_SQUARE: - break; - default: - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - } - int cap = attributes.cap; - if (cap != data.lineCap) { - mask |= LINE_CAP; - switch (cap) { - case SWT.JOIN_MITER: - case SWT.JOIN_ROUND: - case SWT.JOIN_BEVEL: - break; - default: - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - } - float[] dashes = attributes.dash; - float[] lineDashes = data.lineDashes; - if (dashes != null && dashes.length > 0) { - boolean changed = lineDashes == null || lineDashes.length != dashes.length; - for (int i = 0; i < dashes.length; i++) { - float dash = dashes[i]; - if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (!changed && lineDashes[i] != dash) changed = true; - } - if (changed) { - float[] newDashes = new float[dashes.length]; - System.arraycopy(dashes, 0, newDashes, 0, dashes.length); - dashes = newDashes; - mask |= LINE_STYLE; - } else { - dashes = lineDashes; - } - } else { - if (lineDashes != null && lineDashes.length > 0) { - mask |= LINE_STYLE; - } else { - dashes = lineDashes; - } - } - float dashOffset = attributes.dashOffset; - if (dashOffset != data.lineDashesOffset) { - mask |= LINE_STYLE; - } - float miterLimit = attributes.miterLimit; - if (miterLimit != data.lineMiterLimit) { - mask |= LINE_MITERLIMIT; - } - initCairo(); - if (mask == 0) return; - data.lineWidth = lineWidth; - data.lineStyle = lineStyle; - data.lineCap = cap; - data.lineJoin = join; - data.lineDashes = dashes; - data.lineDashesOffset = dashOffset; - data.lineMiterLimit = miterLimit; - data.state &= ~mask; -} -/** - * Sets the receiver's line cap style to the argument, which must be one - * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>, - * or <code>SWT.CAP_SQUARE</code>. - * - * @param cap the cap style to be used for drawing lines - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public void setLineCap(int cap) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (data.lineCap == cap) return; - switch (cap) { - case SWT.CAP_ROUND: - case SWT.CAP_FLAT: - case SWT.CAP_SQUARE: - break; - default: - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - data.lineCap = cap; - data.state &= ~LINE_CAP; -} -/** - * Sets the receiver's line dash style to the argument. The default - * value is <code>null</code>. If the argument is not <code>null</code>, - * the receiver's line style is set to <code>SWT.LINE_CUSTOM</code>, otherwise - * it is set to <code>SWT.LINE_SOLID</code>. - * - * @param dashes the dash style to be used for drawing lines - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if any of the values in the array is less than or equal 0</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public void setLineDash(int[] dashes) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - float[] lineDashes = data.lineDashes; - if (dashes != null && dashes.length > 0) { - boolean changed = data.lineStyle != SWT.LINE_CUSTOM || lineDashes == null || lineDashes.length != dashes.length; - for (int i = 0; i < dashes.length; i++) { - int dash = dashes[i]; - if (dash <= 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (!changed && lineDashes[i] != dash) changed = true; - } - if (!changed) return; - data.lineDashes = new float[dashes.length]; - for (int i = 0; i < dashes.length; i++) { - data.lineDashes[i] = dashes[i]; - } - data.lineStyle = SWT.LINE_CUSTOM; - } else { - if (data.lineStyle == SWT.LINE_SOLID && (lineDashes == null || lineDashes.length == 0)) return; - data.lineDashes = null; - data.lineStyle = SWT.LINE_SOLID; - } - data.state &= ~LINE_STYLE; -} -/** - * Sets the receiver's line join style to the argument, which must be one - * of the constants <code>SWT.JOIN_MITER</code>, <code>SWT.JOIN_ROUND</code>, - * or <code>SWT.JOIN_BEVEL</code>. - * - * @param join the join style to be used for drawing lines - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public void setLineJoin(int join) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (data.lineJoin == join) return; - switch (join) { - case SWT.JOIN_MITER: - case SWT.JOIN_ROUND: - case SWT.JOIN_BEVEL: - break; - default: - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - data.lineJoin = join; - data.state &= ~LINE_JOIN; -} -/** - * Sets the receiver's line style to the argument, which must be one - * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>, - * <code>SWT.LINE_DOT</code>, <code>SWT.LINE_DASHDOT</code> or - * <code>SWT.LINE_DASHDOTDOT</code>. - * - * @param lineStyle the style to be used for drawing lines - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the style is not valid</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setLineStyle(int lineStyle) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (data.lineStyle == lineStyle) return; - switch (lineStyle) { - case SWT.LINE_SOLID: - case SWT.LINE_DASH: - case SWT.LINE_DOT: - case SWT.LINE_DASHDOT: - case SWT.LINE_DASHDOTDOT: - break; - case SWT.LINE_CUSTOM: - if (data.lineDashes == null) lineStyle = SWT.LINE_SOLID; - break; - default: - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - data.lineStyle = lineStyle; - data.state &= ~LINE_STYLE; -} -/** - * Sets the width that will be used when drawing lines - * for all of the figure drawing operations (that is, - * <code>drawLine</code>, <code>drawRectangle</code>, - * <code>drawPolyline</code>, and so forth. - * <p> - * Note that line width of zero is used as a hint to - * indicate that the fastest possible line drawing - * algorithms should be used. This means that the - * output may be different from line width one. - * </p> - * - * @param lineWidth the width of a line - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setLineWidth(int lineWidth) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (data.lineWidth == lineWidth) return; - data.lineWidth = lineWidth; - data.state &= ~(LINE_WIDTH | DRAW_OFFSET); -} -void setString(String string) { - if (string == data.string) return; - if (data.xmString != 0) OS.XmStringFree(data.xmString); - byte[] buffer = Converter.wcsToMbcs(getCodePage (), string, true); - data.xmString = OS.XmStringCreate(buffer, OS.XmFONTLIST_DEFAULT_TAG); - data.string = string; - data.stringWidth = data.stringHeight = -1; -} -void setText(String string, int flags) { - if (data.renderTable == 0) createRenderTable(); - if (string == data.text && (flags & ~SWT.DRAW_TRANSPARENT) == (data.drawFlags & ~SWT.DRAW_TRANSPARENT)) { - return; - } - if (data.xmText != 0) OS.XmStringFree(data.xmText); - if (data.xmMnemonic != 0) OS.XmStringFree(data.xmMnemonic); - char mnemonic = 0; - int tableLength = 0; - Device device = data.device; - int[] parseTable = new int[2]; - char[] text = new char[string.length()]; - string.getChars(0, text.length, text, 0); - if ((flags & SWT.DRAW_DELIMITER) != 0) parseTable[tableLength++] = device.crMapping; - if ((flags & SWT.DRAW_TAB) != 0) parseTable[tableLength++] = device.tabMapping; - if ((flags & SWT.DRAW_MNEMONIC) != 0) mnemonic = fixMnemonic(text); - String codePage = getCodePage(); - byte[] buffer = Converter.wcsToMbcs(codePage, text, true); - data.xmText = OS.XmStringParseText(buffer, 0, OS.XmFONTLIST_DEFAULT_TAG, OS.XmCHARSET_TEXT, parseTable, tableLength, 0); - if (mnemonic != 0) { - byte [] buffer1 = Converter.wcsToMbcs(codePage, new char[]{mnemonic}, true); - data.xmMnemonic = OS.XmStringCreate (buffer1, OS.XmFONTLIST_DEFAULT_TAG); - } else { - data.xmMnemonic = 0; - } - data.text = string; - data.textWidth = data.textHeight = -1; - data.drawFlags = flags; -} -/** - * Sets the receiver's text anti-aliasing value to the parameter, - * which must be one of <code>SWT.DEFAULT</code>, <code>SWT.OFF</code> - * or <code>SWT.ON</code>. Note that this controls anti-aliasing only - * for all <em>text drawing</em> operations. - * <p> - * This operation requires the operating system's advanced - * graphics subsystem which may not be available on some - * platforms. - * </p> - * - * @param antialias the anti-aliasing setting - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the parameter is not one of <code>SWT.DEFAULT</code>, - * <code>SWT.OFF</code> or <code>SWT.ON</code></li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> - * </ul> - * - * @see #getAdvanced - * @see #setAdvanced - * @see #setAntialias - * - * @since 3.1 - */ -public void setTextAntialias(int antialias) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (data.cairo == 0 && antialias == SWT.DEFAULT) return; - int mode = 0; - switch (antialias) { - case SWT.DEFAULT: mode = Cairo.CAIRO_ANTIALIAS_DEFAULT; break; - case SWT.OFF: mode = Cairo.CAIRO_ANTIALIAS_NONE; break; - case SWT.ON: mode = Cairo.CAIRO_ANTIALIAS_GRAY; - break; - default: - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - initCairo(); - int /*long*/ options = Cairo.cairo_font_options_create(); - Cairo.cairo_font_options_set_antialias(options, mode); - Cairo.cairo_set_font_options(data.cairo, options); - Cairo.cairo_font_options_destroy(options); -} -/** - * Sets the transform that is currently being used by the receiver. If - * the argument is <code>null</code>, the current transform is set to - * the identity transform. - * <p> - * This operation requires the operating system's advanced - * graphics subsystem which may not be available on some - * platforms. - * </p> - * - * @param transform the transform to set - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> - * </ul> - * - * @see Transform - * @see #getAdvanced - * @see #setAdvanced - * - * @since 3.1 - */ -public void setTransform(Transform transform) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (transform != null && transform.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (data.cairo == 0 && transform == null) return; - initCairo(); - int /*long*/ cairo = data.cairo; - if (transform != null) { - Cairo.cairo_set_matrix(cairo, transform.handle); - } else { - Cairo.cairo_identity_matrix(cairo); - } - data.state &= ~DRAW_OFFSET; -} -/** - * If the argument is <code>true</code>, puts the receiver - * in a drawing mode where the resulting color in the destination - * is the <em>exclusive or</em> of the color values in the source - * and the destination, and if the argument is <code>false</code>, - * puts the receiver in a drawing mode where the destination color - * is replaced with the source color value. - * <p> - * Note that this mode in fundamentally unsupportable on certain - * platforms, notably Carbon (Mac OS X). Clients that want their - * code to run on all platforms need to avoid this method. - * </p> - * - * @param xor if <code>true</code>, then <em>xor</em> mode is used, otherwise <em>source copy</em> mode is used - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @deprecated this functionality is not supported on some platforms - */ -public void setXORMode(boolean xor) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - OS.XSetFunction(data.display, handle, xor ? OS.GXxor : OS.GXcopy); -} -/** - * Returns the extent of the given string. No tab - * expansion or carriage return processing will be performed. - * <p> - * The <em>extent</em> of a string is the width and height of - * the rectangular area it would cover if drawn in a particular - * font (in this case, the current font in the receiver). - * </p> - * - * @param string the string to measure - * @return a point containing the extent of the string - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Point stringExtent(String string) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - checkGC(FONT); - byte[] buffer = Converter.wcsToMbcs(null, string, true); - cairo_font_extents_t font_extents = new cairo_font_extents_t(); - Cairo.cairo_font_extents(cairo, font_extents); - cairo_text_extents_t extents = new cairo_text_extents_t(); - Cairo.cairo_text_extents(cairo, buffer, extents); - return new Point((int)extents.width, (int)font_extents.height); - } - setString(string); - checkGC(FONT); - if (data.stringWidth != -1) return new Point(data.stringWidth, data.stringHeight); - int width, height; - if (string.length() == 0) { - width = 0; - height = getFontHeight(); - } else { - int fontList = data.font.handle; - int xmString = data.xmString; - width = OS.XmStringWidth(fontList, xmString); - height = OS.XmStringHeight(fontList, xmString); - } - return new Point(data.stringWidth = width, data.stringHeight = height); -} -/** - * Returns the extent of the given string. Tab expansion and - * carriage return processing are performed. - * <p> - * The <em>extent</em> of a string is the width and height of - * the rectangular area it would cover if drawn in a particular - * font (in this case, the current font in the receiver). - * </p> - * - * @param string the string to measure - * @return a point containing the extent of the string - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Point textExtent(String string) { - return textExtent(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB); -} -/** - * Returns the extent of the given string. Tab expansion, line - * delimiter and mnemonic processing are performed according to - * the specified flags, which can be a combination of: - * <dl> - * <dt><b>DRAW_DELIMITER</b></dt> - * <dd>draw multiple lines</dd> - * <dt><b>DRAW_TAB</b></dt> - * <dd>expand tabs</dd> - * <dt><b>DRAW_MNEMONIC</b></dt> - * <dd>underline the mnemonic character</dd> - * <dt><b>DRAW_TRANSPARENT</b></dt> - * <dd>transparent background</dd> - * </dl> - * <p> - * The <em>extent</em> of a string is the width and height of - * the rectangular area it would cover if drawn in a particular - * font (in this case, the current font in the receiver). - * </p> - * - * @param string the string to measure - * @param flags the flags specifying how to process the text - * @return a point containing the extent of the string - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Point textExtent(String string, int flags) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - //TODO - honor flags - checkGC(FONT); - byte[] buffer = Converter.wcsToMbcs(null, string, true); - cairo_font_extents_t font_extents = new cairo_font_extents_t(); - Cairo.cairo_font_extents(cairo, font_extents); - cairo_text_extents_t extents = new cairo_text_extents_t(); - Cairo.cairo_text_extents(cairo, buffer, extents); - return new Point((int)extents.width, (int)font_extents.height); - } - setText(string, flags); - checkGC(FONT); - if (data.textWidth != -1) return new Point(data.textWidth, data.textHeight); - int width, height; - if (string.length() == 0) { - width = 0; - height = getFontHeight(); - } else { - int fontList = data.font.handle; - int xmText = data.xmText; - width = OS.XmStringWidth(fontList, xmText); - height = OS.XmStringHeight(fontList, xmText); - } - return new Point(data.textWidth = width, data.textHeight = height); -} -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the receiver - */ -public String toString () { - if (isDisposed()) return "GC {*DISPOSED*}"; - return "GC {" + handle + "}"; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GCData.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GCData.java deleted file mode 100755 index 8d6836cd9a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GCData.java +++ /dev/null @@ -1,67 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - - -import org.eclipse.swt.*; -import org.eclipse.swt.internal.motif.*; - -/** - * Instances of this class are descriptions of GCs in terms - * of unallocated platform-specific data fields. - * <p> - * <b>IMPORTANT:</b> This class is <em>not</em> part of the public - * API for SWT. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms, and should never be called from application code. - * </p> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noinstantiate This class is not intended to be instantiated by clients. - */ -public final class GCData { - public Device device; - public int style, state = -1; - public XColor foreground; - public XColor background; - public Pattern foregroundPattern; - public Pattern backgroundPattern; - public Font font; - public int clipRgn; - public int lineStyle = SWT.LINE_SOLID; - public float lineWidth; - public int lineCap = SWT.CAP_FLAT; - public int lineJoin = SWT.JOIN_MITER; - public float[] lineDashes; - public float lineDashesOffset; - public float lineMiterLimit = 10; - public int alpha = 0xFF; - public int interpolation = SWT.DEFAULT; - - public int renderTable; - public int damageRgn; - public int colormap; - public Image backgroundImage; - public Image image; - public int display; - public int drawable; - public int /*long*/ cairo; - public double cairoXoffset, cairoYoffset; - public double[] clippingTransform; - public String string; - public int stringWidth = -1; - public int stringHeight = -1; - public int xmString; - public String text; - public int textWidth = -1; - public int textHeight = -1; - public int xmText, xmMnemonic; - public int drawFlags; -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java deleted file mode 100755 index 6aa4d87995..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java +++ /dev/null @@ -1,1429 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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.cairo.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import java.io.*; - -/** - * Instances of this class are graphics which have been prepared - * for display on a specific device. That is, they are ready - * to paint using methods such as <code>GC.drawImage()</code> - * and display on widgets with, for example, <code>Button.setImage()</code>. - * <p> - * If loaded from a file format that supports it, an - * <code>Image</code> may have transparency, meaning that certain - * pixels are specified as being transparent when drawn. Examples - * of file formats that support transparency are GIF and PNG. - * </p><p> - * There are two primary ways to use <code>Images</code>. - * The first is to load a graphic file from disk and create an - * <code>Image</code> from it. This is done using an <code>Image</code> - * constructor, for example: - * <pre> - * Image i = new Image(device, "C:\\graphic.bmp"); - * </pre> - * A graphic file may contain a color table specifying which - * colors the image was intended to possess. In the above example, - * these colors will be mapped to the closest available color in - * SWT. It is possible to get more control over the mapping of - * colors as the image is being created, using code of the form: - * <pre> - * ImageData data = new ImageData("C:\\graphic.bmp"); - * RGB[] rgbs = data.getRGBs(); - * // At this point, rgbs contains specifications of all - * // the colors contained within this image. You may - * // allocate as many of these colors as you wish by - * // using the Color constructor Color(RGB), then - * // create the image: - * Image i = new Image(device, data); - * </pre> - * <p> - * Applications which require even greater control over the image - * loading process should use the support provided in class - * <code>ImageLoader</code>. - * </p><p> - * Application code must explicitly invoke the <code>Image.dispose()</code> - * method to release the operating system resources managed by each instance - * when those instances are no longer required. - * </p> - * - * @see Color - * @see ImageData - * @see ImageLoader - * @see <a href="http://www.eclipse.org/swt/snippets/#image">Image snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Examples: GraphicsExample, ImageAnalyzer</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public final class Image extends Resource implements Drawable { - /** - * specifies whether the receiver is a bitmap or an icon - * (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public int type; - - /** - * The handle to the OS pixmap resource. - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public int pixmap; - - /** - * The handle to the OS mask resource. - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public int mask; - - int /*long*/ surface; - - /** - * specifies the transparent pixel - */ - int transparentPixel = -1; - - /** - * The GC the image is currently selected in. - */ - GC memGC; - - /** - * The alpha data of the image. - */ - byte[] alphaData; - - /** - * The global alpha value to be used for every pixel. - */ - int alpha = -1; - - /** - * The width of the image. - */ - int width = -1; - - /** - * The height of the image. - */ - int height = -1; - - /** - * Specifies the default scanline padding. - */ - static final int DEFAULT_SCANLINE_PAD = 4; - -Image(Device device) { - super(device); -} -/** - * Constructs an empty instance of this class with the - * specified width and height. The result may be drawn upon - * by creating a GC and using any of its drawing operations, - * as shown in the following example: - * <pre> - * Image i = new Image(device, width, height); - * GC gc = new GC(i); - * gc.drawRectangle(0, 0, 50, 50); - * gc.dispose(); - * </pre> - * <p> - * Note: Some platforms may have a limitation on the size - * of image that can be created (size depends on width, height, - * and depth). For example, Windows 95, 98, and ME do not allow - * images larger than 16M. - * </p> - * - * @param device the device on which to create the image - * @param width the width of the new image - * @param height the height of the new image - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_INVALID_ARGUMENT - if either the width or height is negative or zero</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> - * </ul> - */ -public Image(Device device, int width, int height) { - super(device); - init(width, height); - init(); -} -/** - * Constructs a new instance of this class based on the - * provided image, with an appearance that varies depending - * on the value of the flag. The possible flag values are: - * <dl> - * <dt><b>{@link SWT#IMAGE_COPY}</b></dt> - * <dd>the result is an identical copy of srcImage</dd> - * <dt><b>{@link SWT#IMAGE_DISABLE}</b></dt> - * <dd>the result is a copy of srcImage which has a <em>disabled</em> look</dd> - * <dt><b>{@link SWT#IMAGE_GRAY}</b></dt> - * <dd>the result is a copy of srcImage which has a <em>gray scale</em> look</dd> - * </dl> - * - * @param device the device on which to create the image - * @param srcImage the image to use as the source - * @param flag the style, either <code>IMAGE_COPY</code>, <code>IMAGE_DISABLE</code> or <code>IMAGE_GRAY</code> - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_NULL_ARGUMENT - if srcImage is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the flag is not one of <code>IMAGE_COPY</code>, <code>IMAGE_DISABLE</code> or <code>IMAGE_GRAY</code></li> - * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon, or is otherwise in an invalid state</li> - * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the image is not supported</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> - * </ul> - */ -public Image(Device device, Image srcImage, int flag) { - super(device); - device = this.device; - if (srcImage == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (srcImage.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - int xDisplay = device.xDisplay; - this.type = srcImage.type; - this.mask = 0; - int[] unused = new int[1]; - int[] w = new int[1]; - int[] h = new int[1]; - OS.XGetGeometry(xDisplay, srcImage.pixmap, unused, unused, unused, w, h, unused, unused); - int width = w[0]; - int height = h[0]; - int drawable = OS.XDefaultRootWindow(xDisplay); - /* Don't create the mask here if flag is SWT.IMAGE_GRAY. See below.*/ - if (flag != SWT.IMAGE_GRAY && ((srcImage.type == SWT.ICON && srcImage.mask != 0) || srcImage.transparentPixel != -1)) { - /* Generate the mask if necessary. */ - if (srcImage.transparentPixel != -1) srcImage.createMask(); - int mask = OS.XCreatePixmap(xDisplay, drawable, width, height, 1); - int gc = OS.XCreateGC(xDisplay, mask, 0, null); - OS.XCopyArea(xDisplay, srcImage.mask, mask, gc, 0, 0, width, height, 0, 0); - OS.XFreeGC(xDisplay, gc); - this.mask = mask; - /* Destroy the image mask if the there is a GC created on the image */ - if (srcImage.transparentPixel != -1 && srcImage.memGC != null) srcImage.destroyMask(); - } - switch (flag) { - case SWT.IMAGE_COPY: - int[] depth = new int[1]; - OS.XGetGeometry(xDisplay, srcImage.pixmap, unused, unused, unused, unused, unused, unused, depth); - int pixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, depth[0]); - int gc = OS.XCreateGC(xDisplay, pixmap, 0, null); - OS.XCopyArea(xDisplay, srcImage.pixmap, pixmap, gc, 0, 0, width, height, 0, 0); - OS.XFreeGC(xDisplay, gc); - this.pixmap = pixmap; - transparentPixel = srcImage.transparentPixel; - alpha = srcImage.alpha; - if (srcImage.alphaData != null) { - alphaData = new byte[srcImage.alphaData.length]; - System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length); - } - createAlphaMask(width, height); - break; - case SWT.IMAGE_DISABLE: - /* Get src image data */ - XImage srcXImage = new XImage(); - int srcXImagePtr = OS.XGetImage(xDisplay, srcImage.pixmap, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap); - OS.memmove(srcXImage, srcXImagePtr, XImage.sizeof); - byte[] srcData = new byte[srcXImage.bytes_per_line * srcXImage.height]; - OS.memmove(srcData, srcXImage.data, srcData.length); - /* Create destination image */ - int destPixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, srcXImage.depth); - int visualPtr = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay)); - int screenDepth = OS.XDefaultDepthOfScreen(OS.XDefaultScreenOfDisplay(xDisplay)); - int destXImagePtr = OS.XCreateImage(xDisplay, visualPtr, screenDepth, OS.ZPixmap, 0, 0, width, height, srcXImage.bitmap_pad, 0); - XImage destXImage = new XImage(); - OS.memmove(destXImage, destXImagePtr, XImage.sizeof); - int bufSize = destXImage.bytes_per_line * destXImage.height; - int bufPtr = OS.XtMalloc(bufSize); - destXImage.data = bufPtr; - OS.memmove(destXImagePtr, destXImage, XImage.sizeof); - byte[] destData = new byte[bufSize]; - /* Find the colors to map to */ - Color zeroColor = device.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW); - Color oneColor = device.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); - int zeroPixel = zeroColor.handle.pixel; - int onePixel = oneColor.handle.pixel; - switch (srcXImage.bits_per_pixel) { - case 1: - /* - * Nothing we can reasonably do here except copy - * the bitmap; we can't make it a higher color depth. - * Short-circuit the rest of the code and return. - */ - gc = OS.XCreateGC(xDisplay, drawable, 0, null); - pixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, 1); - OS.XCopyArea(xDisplay, srcImage.pixmap, pixmap, gc, 0, 0, width, height, 0, 0); - OS.XDestroyImage(srcXImagePtr); - OS.XDestroyImage(destXImagePtr); - OS.XFreeGC(xDisplay, gc); - return; - case 4: - SWT.error(SWT.ERROR_NOT_IMPLEMENTED); - break; - case 8: - int index = 0; - int srcPixel, r, g, b; - XColor[] colors = new XColor[256]; - int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay)); - for (int y = 0; y < srcXImage.height; y++) { - for (int x = 0; x < srcXImage.bytes_per_line; x++) { - srcPixel = srcData[index + x] & 0xFF; - /* Get the RGB values of srcPixel */ - if (colors[srcPixel] == null) { - XColor color = new XColor(); - color.pixel = srcPixel; - OS.XQueryColor(xDisplay, colormap, color); - colors[srcPixel] = color; - } - XColor xColor = colors[srcPixel]; - r = (xColor.red >> 8) & 0xFF; - g = (xColor.green >> 8) & 0xFF; - b = (xColor.blue >> 8) & 0xFF; - /* See if the rgb maps to 0 or 1 */ - if ((r * r + g * g + b * b) < 98304) { - /* Map down to 0 */ - destData[index + x] = (byte)zeroPixel; - } else { - /* Map up to 1 */ - destData[index + x] = (byte)onePixel; - } - } - index += srcXImage.bytes_per_line; - } - break; - case 16: - index = 0; - /* Get masks */ - Visual visual = new Visual(); - OS.memmove(visual, visualPtr, Visual.sizeof); - int redMask = visual.red_mask; - int greenMask = visual.green_mask; - int blueMask = visual.blue_mask; - /* Calculate mask shifts */ - int[] shift = new int[1]; - getOffsetForMask(16, redMask, srcXImage.byte_order, shift); - int rShift = 24 - shift[0]; - getOffsetForMask(16, greenMask, srcXImage.byte_order, shift); - int gShift = 24 - shift[0]; - getOffsetForMask(16, blueMask, srcXImage.byte_order, shift); - int bShift = 24 - shift[0]; - byte zeroLow = (byte)(zeroPixel & 0xFF); - byte zeroHigh = (byte)((zeroPixel >> 8) & 0xFF); - byte oneLow = (byte)(onePixel & 0xFF); - byte oneHigh = (byte)((onePixel >> 8) & 0xFF); - for (int y = 0; y < srcXImage.height; y++) { - int xIndex = 0; - for (int x = 0; x < srcXImage.bytes_per_line; x += 2) { - srcPixel = ((srcData[index + xIndex + 1] & 0xFF) << 8) | (srcData[index + xIndex] & 0xFF); - r = (srcPixel & redMask) << rShift >> 16; - g = (srcPixel & greenMask) << gShift >> 16; - b = (srcPixel & blueMask) << bShift >> 16; - /* See if the rgb maps to 0 or 1 */ - if ((r * r + g * g + b * b) < 98304) { - /* Map down to 0 */ - destData[index + xIndex] = zeroLow; - destData[index + xIndex + 1] = zeroHigh; - } else { - /* Map up to 1 */ - destData[index + xIndex] = oneLow; - destData[index + xIndex + 1] = oneHigh; - } - xIndex += srcXImage.bits_per_pixel / 8; - } - index += srcXImage.bytes_per_line; - } - break; - case 24: - case 32: - index = 0; - /* Get masks */ - visual = new Visual(); - OS.memmove(visual, visualPtr, Visual.sizeof); - redMask = visual.red_mask; - greenMask = visual.green_mask; - blueMask = visual.blue_mask; - /* Calculate mask shifts */ - shift = new int[1]; - getOffsetForMask(srcXImage.bits_per_pixel, redMask, srcXImage.byte_order, shift); - rShift = shift[0]; - getOffsetForMask(srcXImage.bits_per_pixel, greenMask, srcXImage.byte_order, shift); - gShift = shift[0]; - getOffsetForMask(srcXImage.bits_per_pixel, blueMask, srcXImage.byte_order, shift); - bShift = shift[0]; - byte zeroR = (byte)zeroColor.getRed(); - byte zeroG = (byte)zeroColor.getGreen(); - byte zeroB = (byte)zeroColor.getBlue(); - byte oneR = (byte)oneColor.getRed(); - byte oneG = (byte)oneColor.getGreen(); - byte oneB = (byte)oneColor.getBlue(); - for (int y = 0; y < srcXImage.height; y++) { - int xIndex = 0; - for (int x = 0; x < srcXImage.width; x++) { - r = srcData[index + xIndex + rShift] & 0xFF; - g = srcData[index + xIndex + gShift] & 0xFF; - b = srcData[index + xIndex + bShift] & 0xFF; - /* See if the rgb maps to 0 or 1 */ - if ((r * r + g * g + b * b) < 98304) { - /* Map down to 0 */ - destData[index + xIndex + rShift] = zeroR; - destData[index + xIndex + gShift] = zeroG; - destData[index + xIndex + bShift] = zeroB; - } else { - /* Map up to 1 */ - destData[index + xIndex + rShift] = oneR; - destData[index + xIndex + gShift] = oneG; - destData[index + xIndex + bShift] = oneB; - } - xIndex += destXImage.bits_per_pixel / 8; - } - index += srcXImage.bytes_per_line; - } - break; - default: - SWT.error(SWT.ERROR_INVALID_IMAGE); - } - OS.memmove(destXImage.data, destData, destData.length); - gc = OS.XCreateGC(xDisplay, destPixmap, 0, null); - OS.XPutImage(xDisplay, destPixmap, gc, destXImagePtr, 0, 0, 0, 0, width, height); - OS.XDestroyImage(destXImagePtr); - OS.XDestroyImage(srcXImagePtr); - OS.XFreeGC(xDisplay, gc); - alpha = srcImage.alpha; - if (srcImage.alphaData != null) { - alphaData = new byte[srcImage.alphaData.length]; - System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length); - } - createAlphaMask(width, height); - this.pixmap = destPixmap; - break; - case SWT.IMAGE_GRAY: - ImageData data = srcImage.getImageData(); - PaletteData palette = data.palette; - ImageData newData = data; - if (!palette.isDirect) { - /* Convert the palette entries to gray. */ - RGB [] rgbs = palette.getRGBs(); - for (int i=0; i<rgbs.length; i++) { - if (data.transparentPixel != i) { - RGB color = rgbs [i]; - int red = color.red; - int green = color.green; - int blue = color.blue; - int intensity = (red+red+green+green+green+green+green+blue) >> 3; - color.red = color.green = color.blue = intensity; - } - } - newData.palette = new PaletteData(rgbs); - } else { - /* Create a 8 bit depth image data with a gray palette. */ - RGB[] rgbs = new RGB[256]; - for (int i=0; i<rgbs.length; i++) { - rgbs[i] = new RGB(i, i, i); - } - newData = new ImageData(width, height, 8, new PaletteData(rgbs)); - newData.alpha = data.alpha; - newData.alphaData = data.alphaData; - newData.maskData = data.maskData; - newData.maskPad = data.maskPad; - if (data.transparentPixel != -1) newData.transparentPixel = 254; - - /* Convert the pixels. */ - int[] scanline = new int[width]; - int redMask = palette.redMask; - int greenMask = palette.greenMask; - int blueMask = palette.blueMask; - int redShift = palette.redShift; - int greenShift = palette.greenShift; - int blueShift = palette.blueShift; - for (int y=0; y<height; y++) { - int offset = y * newData.bytesPerLine; - data.getPixels(0, y, width, scanline, 0); - for (int x=0; x<width; x++) { - int pixel = scanline[x]; - if (pixel != data.transparentPixel) { - int red = pixel & redMask; - red = (redShift < 0) ? red >>> -redShift : red << redShift; - int green = pixel & greenMask; - green = (greenShift < 0) ? green >>> -greenShift : green << greenShift; - int blue = pixel & blueMask; - blue = (blueShift < 0) ? blue >>> -blueShift : blue << blueShift; - int intensity = (red+red+green+green+green+green+green+blue) >> 3; - if (newData.transparentPixel == intensity) intensity = 255; - newData.data[offset] = (byte)intensity; - } else { - newData.data[offset] = (byte)254; - } - offset++; - } - } - } - init (newData); - break; - default: - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - init(); -} -/** - * Constructs an empty instance of this class with the - * width and height of the specified rectangle. The result - * may be drawn upon by creating a GC and using any of its - * drawing operations, as shown in the following example: - * <pre> - * Image i = new Image(device, boundsRectangle); - * GC gc = new GC(i); - * gc.drawRectangle(0, 0, 50, 50); - * gc.dispose(); - * </pre> - * <p> - * Note: Some platforms may have a limitation on the size - * of image that can be created (size depends on width, height, - * and depth). For example, Windows 95, 98, and ME do not allow - * images larger than 16M. - * </p> - * - * @param device the device on which to create the image - * @param bounds a rectangle specifying the image's width and height (must not be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_NULL_ARGUMENT - if the bounds rectangle is null</li> - * <li>ERROR_INVALID_ARGUMENT - if either the rectangle's width or height is negative</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> - * </ul> - */ -public Image(Device device, Rectangle bounds) { - super(device); - if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - init(bounds.width, bounds.height); - init(); -} -/** - * Constructs an instance of this class from the given - * <code>ImageData</code>. - * - * @param device the device on which to create the image - * @param data the image data to create the image from (must not be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_NULL_ARGUMENT - if the image data is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the ImageData is not supported</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> - * </ul> - */ -public Image(Device device, ImageData image) { - super(device); - init(image); - init(); -} -/** - * Constructs an instance of this class, whose type is - * <code>SWT.ICON</code>, from the two given <code>ImageData</code> - * objects. The two images must be the same size. Pixel transparency - * in either image will be ignored. - * <p> - * The mask image should contain white wherever the icon is to be visible, - * and black wherever the icon is to be transparent. In addition, - * the source image should contain black wherever the icon is to be - * transparent. - * </p> - * - * @param device the device on which to create the icon - * @param source the color data for the icon - * @param mask the mask data for the icon - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_NULL_ARGUMENT - if either the source or mask is null </li> - * <li>ERROR_INVALID_ARGUMENT - if source and mask are different sizes</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> - * </ul> - */ -public Image(Device device, ImageData source, ImageData mask) { - super(device); - if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (mask == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (source.width != mask.width || source.height != mask.height) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - mask = ImageData.convertMask(mask); - ImageData image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad, source.data); - image.maskPad = mask.scanlinePad; - image.maskData = mask.data; - init(image); - init(); -} -/** - * Constructs an instance of this class by loading its representation - * from the specified input stream. Throws an error if an error - * occurs while loading the image, or if the result is an image - * of an unsupported type. Application code is still responsible - * for closing the input stream. - * <p> - * This constructor is provided for convenience when loading a single - * image only. If the stream contains multiple images, only the first - * one will be loaded. To load multiple images, use - * <code>ImageLoader.load()</code>. - * </p><p> - * This constructor may be used to load a resource as follows: - * </p> - * <pre> - * static Image loadImage (Display display, Class clazz, String string) { - * InputStream stream = clazz.getResourceAsStream (string); - * if (stream == null) return null; - * Image image = null; - * try { - * image = new Image (display, stream); - * } catch (SWTException ex) { - * } finally { - * try { - * stream.close (); - * } catch (IOException ex) {} - * } - * return image; - * } - * </pre> - * - * @param device the device on which to create the image - * @param stream the input stream to load the image from - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_NULL_ARGUMENT - if the stream is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_IO - if an IO error occurs while reading from the stream</li> - * <li>ERROR_INVALID_IMAGE - if the image stream contains invalid data </li> - * <li>ERROR_UNSUPPORTED_DEPTH - if the image stream describes an image with an unsupported depth</li> - * <li>ERROR_UNSUPPORTED_FORMAT - if the image stream contains an unrecognized format</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> - * </ul> - */ -public Image(Device device, InputStream stream) { - super(device); - init(new ImageData(stream)); - init(); -} -/** - * Constructs an instance of this class by loading its representation - * from the file with the specified name. Throws an error if an error - * occurs while loading the image, or if the result is an image - * of an unsupported type. - * <p> - * This constructor is provided for convenience when loading - * a single image only. If the specified file contains - * multiple images, only the first one will be used. - * - * @param device the device on which to create the image - * @param filename the name of the file to load the image from - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_NULL_ARGUMENT - if the file name is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_IO - if an IO error occurs while reading from the file</li> - * <li>ERROR_INVALID_IMAGE - if the image file contains invalid data </li> - * <li>ERROR_UNSUPPORTED_DEPTH - if the image file describes an image with an unsupported depth</li> - * <li>ERROR_UNSUPPORTED_FORMAT - if the image file contains an unrecognized format</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> - * </ul> - */ -public Image(Device device, String filename) { - super(device); - init(new ImageData(filename)); - init(); -} -void createAlphaMask(int width, int height) { - if (device.useXRender && (alpha != -1 || alphaData != null)) { - int xDisplay = device.xDisplay; - int drawable = OS.XDefaultRootWindow(xDisplay); - mask = OS.XCreatePixmap(xDisplay, drawable, alpha != -1 ? 1 : width, alpha != -1 ? 1 : height, 8); - if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int gc = OS.XCreateGC(xDisplay, mask, 0, null); - if (alpha != -1) { - OS.XSetForeground(xDisplay, gc, (alpha & 0xFF) << 8 | (alpha & 0xFF)); - OS.XFillRectangle(xDisplay, mask, gc, 0, 0, 1, 1); - } else { - int imagePtr = OS.XGetImage(xDisplay, mask, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap); - XImage xImage = new XImage(); - OS.memmove(xImage, imagePtr, XImage.sizeof); - if (xImage.bytes_per_line == width) { - OS.memmove(xImage.data, alphaData, alphaData.length); - } else { - byte[] line = new byte[xImage.bytes_per_line]; - for (int y = 0; y < height; y++) { - System.arraycopy(alphaData, width * y, line, 0, width); - OS.memmove(xImage.data + (xImage.bytes_per_line * y), line, xImage.bytes_per_line); - } - } - OS.XPutImage(xDisplay, mask, gc, imagePtr, 0, 0, 0, 0, width, height); - OS.XDestroyImage(imagePtr); - } - OS.XFreeGC(xDisplay, gc); - } -} -/** - * Create the receiver's mask if necessary. - */ -void createMask() { - if (mask != 0) return; - int xDisplay = device.xDisplay; - int drawable = OS.XDefaultRootWindow(xDisplay); - int screenDepth = OS.XDefaultDepthOfScreen(OS.XDefaultScreenOfDisplay(xDisplay)); - int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay)); - ImageData maskImage = getImageData().getTransparencyMask(); - int maskPixmap = OS.XCreatePixmap(xDisplay, drawable, maskImage.width, maskImage.height, 1); - XColor[] xcolors = device.xcolors; - int gc = OS.XCreateGC(xDisplay, maskPixmap, 0, null); - Image.putImage(maskImage, 0, 0, maskImage.width, maskImage.height, 0, 0, maskImage.width, maskImage.height, xDisplay, visual, screenDepth, xcolors, null, true, maskPixmap, gc); - OS.XFreeGC(xDisplay, gc); - this.mask = maskPixmap; -} -void createSurface() { - if (surface != 0) return; - int [] unused = new int [1]; int [] width = new int [1]; int [] height = new int [1]; - OS.XGetGeometry (device.xDisplay, pixmap, unused, unused, unused, width, height, unused, unused); - int xDisplay = device.xDisplay; - int xDrawable = pixmap; - int xVisual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay)); - surface = Cairo.cairo_xlib_surface_create(xDisplay, xDrawable, xVisual, width[0], height[0]); -} -void destroy() { - if (memGC != null) memGC.dispose(); - int xDisplay = device.xDisplay; - if (pixmap != 0) OS.XFreePixmap (xDisplay, pixmap); - if (mask != 0) OS.XFreePixmap (xDisplay, mask); - if (surface != 0) Cairo.cairo_surface_destroy(surface); - surface = pixmap = mask = 0; - memGC = null; -} -/** - * Destroy the receiver's mask if it exists. - */ -void destroyMask() { - if (mask == 0) return; - OS.XFreePixmap (device.xDisplay, mask); - mask = 0; -} -/** - * Compares the argument to the receiver, and returns true - * if they represent the <em>same</em> object using a class - * specific comparison. - * - * @param object the object to compare with this object - * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise - * - * @see #hashCode - */ -public boolean equals (Object object) { - if (object == this) return true; - if (!(object instanceof Image)) return false; - Image image = (Image)object; - return device == image.device && pixmap == image.pixmap; -} -/** - * Returns the color to which to map the transparent pixel, or null if - * the receiver has no transparent pixel. - * <p> - * There are certain uses of Images that do not support transparency - * (for example, setting an image into a button or label). In these cases, - * it may be desired to simulate transparency by using the background - * color of the widget to paint the transparent pixels of the image. - * Use this method to check which color will be used in these cases - * in place of transparency. This value may be set with setBackground(). - * <p> - * - * @return the background color of the image, or null if there is no transparency in the image - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Color getBackground() { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (transparentPixel == -1) return null; - XColor xColor = new XColor(); - xColor.pixel = transparentPixel; - int xDisplay = device.xDisplay; - int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay)); - OS.XQueryColor(xDisplay, colormap, xColor); - return Color.motif_new(device, xColor); -} -/** - * Returns the bounds of the receiver. The rectangle will always - * have x and y values of 0, and the width and height of the - * image. - * - * @return a rectangle specifying the image's bounds - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li> - * </ul> - */ -public Rectangle getBounds () { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (width != -1 && height != -1) { - return new Rectangle(0, 0, width, height); - } - int [] unused = new int [1]; int [] w = new int [1]; int [] h = new int [1]; - OS.XGetGeometry (device.xDisplay, pixmap, unused, unused, unused, w, h, unused, unused); - return new Rectangle(0, 0, width = w [0], height = h [0]); -} -/** - * Returns an <code>ImageData</code> based on the receiver - * Modifications made to this <code>ImageData</code> will not - * affect the Image. - * - * @return an <code>ImageData</code> containing the image's data and attributes - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li> - * </ul> - * - * @see ImageData - */ -public ImageData getImageData() { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - Rectangle srcBounds = getBounds(); - int width = srcBounds.width; - int height = srcBounds.height; - int xDisplay = device.xDisplay; - int xSrcImagePtr = OS.XGetImage(xDisplay, pixmap, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap); - if (xSrcImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES); - XImage xSrcImage = new XImage(); - OS.memmove(xSrcImage, xSrcImagePtr, XImage.sizeof); - - /* Get the data and palette of the source image. */ - PaletteData palette = null; - int length = xSrcImage.bytes_per_line * xSrcImage.height; - byte[] srcData = new byte[length]; - OS.memmove(srcData, xSrcImage.data, length); - switch (xSrcImage.bits_per_pixel) { - case 1: - palette = new PaletteData(new RGB[] { - new RGB(0, 0, 0), - new RGB(255, 255, 255) - }); - break; - case 4: - /* - * We currently don't run on a 4-bit server, so 4-bit images - * should not exist. - */ - SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH); - case 8: - /* Normalize the pixels in the source image data (by making the - * pixel values sequential starting at pixel 0). Reserve normalized - * pixel 0 so that it maps to real pixel 0. This assumes pixel 0 is - * always used in the image. - */ - byte[] normPixel = new byte[256]; - for (int index = 0; index < normPixel.length; index++) { - normPixel[index] = 0; - } - int numPixels = 1; - int index = 0; - for (int y = 0; y < xSrcImage.height; y++) { - for (int x = 0; x < xSrcImage.bytes_per_line; x++) { - int srcPixel = srcData[index + x] & 0xFF; - if (srcPixel != 0 && normPixel[srcPixel] == 0) { - normPixel[srcPixel] = (byte)numPixels++; - } - srcData[index + x] = normPixel[srcPixel]; - } - index += xSrcImage.bytes_per_line; - } - - /* Create a palette with only the RGB values used in the image. */ - int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay)); - RGB[] rgbs = new RGB[numPixels]; - XColor color = new XColor(); - for (int srcPixel = 0; srcPixel < normPixel.length; srcPixel++) { - /* If the pixel value was used in the image, get its RGB values. */ - if (srcPixel == 0 || normPixel[srcPixel] != 0) { - color.pixel = srcPixel; - OS.XQueryColor(xDisplay, colormap, color); - int rgbIndex = normPixel[srcPixel] & 0xFF; - rgbs[rgbIndex] = new RGB((color.red >> 8) & 0xFF, (color.green >> 8) & 0xFF, (color.blue >> 8) & 0xFF); - } - } - palette = new PaletteData(rgbs); - break; - case 16: - /* Byte swap the data if necessary */ - if (xSrcImage.byte_order == OS.MSBFirst) { - for (int i = 0; i < srcData.length; i += 2) { - byte b = srcData[i]; - srcData[i] = srcData[i+1]; - srcData[i+1] = b; - } - } - break; - case 24: - break; - case 32: - /* Byte swap the data if necessary */ - if (xSrcImage.byte_order == OS.LSBFirst) { - for (int i = 0; i < srcData.length; i += 4) { - byte b = srcData[i]; - srcData[i] = srcData[i+3]; - srcData[i+3] = b; - b = srcData[i+1]; - srcData[i+1] = srcData[i+2]; - srcData[i+2] = b; - } - } - break; - default: - SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH); - } - if (palette == null) { - /* - * For some reason, the XImage does not have the mask information. - * We must get it from the defualt visual. - */ - int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay)); - Visual v = new Visual(); - OS.memmove(v, visual, Visual.sizeof); - palette = new PaletteData(v.red_mask, v.green_mask, v.blue_mask); - } - ImageData data = new ImageData(width, height, xSrcImage.bits_per_pixel, palette, 4, srcData); - if (transparentPixel == -1 && type == SWT.ICON && mask != 0) { - /* Get the icon mask data */ - int xMaskPtr = OS.XGetImage(xDisplay, mask, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap); - if (xMaskPtr == 0) SWT.error(SWT.ERROR_NO_HANDLES); - XImage xMask = new XImage(); - OS.memmove(xMask, xMaskPtr, XImage.sizeof); - byte[] maskData = new byte[xMask.bytes_per_line * xMask.height]; - OS.memmove(maskData, xMask.data, maskData.length); - OS.XDestroyImage(xMaskPtr); - int maskPad = xMask.bitmap_pad / 8; - /* Make mask scanline pad equals to 2 */ - data.maskPad = 2; - maskData = ImageData.convertPad(maskData, width, height, 1, maskPad, data.maskPad); - /* Bit swap the mask data if necessary */ - if (xMask.bitmap_bit_order == OS.LSBFirst) { - for (int i = 0; i < maskData.length; i++) { - byte b = maskData[i]; - maskData[i] = (byte)(((b & 0x01) << 7) | ((b & 0x02) << 5) | - ((b & 0x04) << 3) | ((b & 0x08) << 1) | ((b & 0x10) >> 1) | - ((b & 0x20) >> 3) | ((b & 0x40) >> 5) | ((b & 0x80) >> 7)); - } - } - data.maskData = maskData; - } - data.transparentPixel = transparentPixel; - data.alpha = alpha; - if (alpha == -1 && alphaData != null) { - data.alphaData = new byte[alphaData.length]; - System.arraycopy(alphaData, 0, data.alphaData, 0, alphaData.length); - } - OS.XDestroyImage(xSrcImagePtr); - return data; -} -/** - * Get the offset for the given mask. - * - * For 24 and 32-bit masks, the offset indicates which byte holds the - * data for the given mask (indexed from 0). - * For example, in 0x0000FF00, the byte offset is 1. - * - * For 16-bit masks, the offset indicates which bit holds the most significant - * data for the given mask (indexed from 1). - * For example, in 0x7E0, the bit offset is 11. - * - * The different semantics are necessary because 24- and 32-bit images - * have their color components aligned on byte boundaries, and 16-bit images - * do not. - */ -static boolean getOffsetForMask(int bitspp, int mask, int byteOrder, int[] poff) { - if (bitspp % 8 != 0) { - return false; - } - switch (mask) { - /* 24-bit and 32-bit masks */ - case 0x000000FF: - poff[0] = 0; - break; - case 0x0000FF00: - poff[0] = 1; - break; - case 0x00FF0000: - poff[0] = 2; - break; - case 0xFF000000: - poff[0] = 3; - break; - /* 16-bit masks */ - case 0x001F: - poff[0] = 5; - break; - case 0x03E0: - poff[0] = 10; - break; - case 0x07E0: - poff[0] = 11; - break; - case 0x7C00: - poff[0] = 15; - break; - case 0xF800: - poff[0] = 16; - break; - default: - return false; - } - if (bitspp == 16) { - return true; - } - if (poff[0] >= bitspp / 8) { - return false; - } - if (byteOrder == OS.MSBFirst) { - poff[0] = (bitspp/8 - 1) - poff[0]; - } - return true; -} -/** - * Returns an integer hash code for the receiver. Any two - * objects that return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals - */ -public int hashCode () { - return pixmap; -} -void init(int width, int height) { - if (width <= 0 || height <= 0) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - - /* Create the pixmap */ - this.type = SWT.BITMAP; - int xDisplay = device.xDisplay; - int screen = OS.XDefaultScreenOfDisplay(xDisplay); - int depth = OS.XDefaultDepthOfScreen(screen); - int screenNum = OS.XDefaultScreen(xDisplay); - int drawable = OS.XDefaultRootWindow(xDisplay); - int pixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, depth); - if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES); - /* Fill the bitmap with white */ - int xGC = OS.XCreateGC(xDisplay, drawable, 0, null); - OS.XSetForeground(xDisplay, xGC, OS.XWhitePixel(xDisplay, screenNum)); - OS.XFillRectangle(xDisplay, pixmap, xGC, 0, 0, width, height); - OS.XFreeGC(xDisplay, xGC); - this.pixmap = pixmap; -} -void init(ImageData image) { - if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - int xDisplay = device.xDisplay; - int drawable = OS.XDefaultRootWindow(xDisplay); - int screenDepth = OS.XDefaultDepthOfScreen(OS.XDefaultScreenOfDisplay(xDisplay)); - int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay)); - int pixmap = OS.XCreatePixmap(xDisplay, drawable, image.width, image.height, screenDepth); - if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int gc = OS.XCreateGC(xDisplay, pixmap, 0, null); - int[] transPixel = null; - if (image.transparentPixel != -1) transPixel = new int[]{image.transparentPixel}; - int error = putImage(image, 0, 0, image.width, image.height, 0, 0, image.width, image.height, xDisplay, visual, screenDepth, device.xcolors, transPixel, false, pixmap, gc); - OS.XFreeGC(xDisplay, gc); - if (error != 0) { - OS.XFreePixmap (xDisplay, pixmap); - SWT.error(error); - } - if (image.getTransparencyType() == SWT.TRANSPARENCY_MASK || image.transparentPixel != -1) { - if (image.transparentPixel != -1) transparentPixel = transPixel[0]; - ImageData maskImage = image.getTransparencyMask(); - int mask = OS.XCreatePixmap(xDisplay, drawable, image.width, image.height, 1); - gc = OS.XCreateGC(xDisplay, mask, 0, null); - error = putImage(maskImage, 0, 0, maskImage.width, maskImage.height, 0, 0, maskImage.width, maskImage.height, xDisplay, visual, screenDepth, device.xcolors, null, true, mask, gc); - OS.XFreeGC(xDisplay, gc); - if (error != 0) { - OS.XFreePixmap (xDisplay, pixmap); - OS.XFreePixmap (xDisplay, mask); - SWT.error(error); - } - this.mask = mask; - if (image.getTransparencyType() == SWT.TRANSPARENCY_MASK) { - this.type = SWT.ICON; - } else { - this.type = SWT.BITMAP; - } - } else { - this.type = SWT.BITMAP; - this.mask = 0; - this.alpha = image.alpha; - if (image.alpha == -1 && image.alphaData != null) { - this.alphaData = new byte[image.alphaData.length]; - System.arraycopy(image.alphaData, 0, this.alphaData, 0, alphaData.length); - } - createAlphaMask(image.width, image.height); - } - this.pixmap = pixmap; -} -/** - * Invokes platform specific functionality to allocate a new GC handle. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>Image</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @param data the platform specific GC data - * @return the platform specific GC handle - */ -public int internal_new_GC (GCData data) { - if (pixmap == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (type != SWT.BITMAP || memGC != null) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - int xDisplay = device.xDisplay; - int xGC = OS.XCreateGC (xDisplay, pixmap, 0, null); - if (xGC == 0) SWT.error (SWT.ERROR_NO_HANDLES); - if (data != null) { - int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT; - if ((data.style & mask) == 0) { - data.style |= SWT.LEFT_TO_RIGHT; - } - data.device = device; - data.display = xDisplay; - data.drawable = pixmap; - data.background = device.COLOR_WHITE.handle; - data.foreground = device.COLOR_BLACK.handle; - data.font = device.systemFont; - data.colormap = OS.XDefaultColormap (xDisplay, OS.XDefaultScreen (xDisplay)); - data.image = this; - } - return xGC; -} -/** - * Invokes platform specific functionality to dispose a GC handle. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>Image</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @param hDC the platform specific GC handle - * @param data the platform specific GC data - */ -public void internal_dispose_GC (int gc, GCData data) { - int xDisplay = 0; - if (data != null) xDisplay = data.display; - if (xDisplay == 0 && device != null) xDisplay = device.xDisplay; - if (xDisplay == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.XFreeGC(xDisplay, gc); -} -/** - * Returns <code>true</code> if the image has been disposed, - * and <code>false</code> otherwise. - * <p> - * This method gets the dispose state for the image. - * When an image has been disposed, it is an error to - * invoke any other method using the image. - * - * @return <code>true</code> when the image is disposed and <code>false</code> otherwise - */ -public boolean isDisposed() { - return pixmap == 0; -} -public static Image motif_new(Device device, int type, int pixmap, int mask) { - Image image = new Image(device); - image.type = type; - image.pixmap = pixmap; - image.mask = mask; - return image; -} -/** - * Put a device-independent image of any depth into a drawable of any depth, - * stretching if necessary. - */ -static int putImage(ImageData image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, int display, int visual, int screenDepth, XColor[] xcolors, int[] transparentPixel, boolean isMask, int drawable, int gc) { - PaletteData palette = image.palette; - if (!(((image.depth == 1 || image.depth == 2 || image.depth == 4 || image.depth == 8) && !palette.isDirect) || - ((image.depth == 8) || (image.depth == 16 || image.depth == 24 || image.depth == 32) && palette.isDirect))) - return SWT.ERROR_UNSUPPORTED_DEPTH; - - boolean flipX = destWidth < 0; - boolean flipY = destHeight < 0; - if (flipX) { - destWidth = -destWidth; - destX = destX - destWidth; - } - if (flipY) { - destHeight = -destHeight; - destY = destY - destHeight; - } - byte[] srcReds = null, srcGreens = null, srcBlues = null; - if (!palette.isDirect) { - RGB[] rgbs = palette.getRGBs(); - int length = rgbs.length; - srcReds = new byte[length]; - srcGreens = new byte[length]; - srcBlues = new byte[length]; - for (int i = 0; i < rgbs.length; i++) { - RGB rgb = rgbs[i]; - if (rgb == null) continue; - srcReds[i] = (byte)rgb.red; - srcGreens[i] = (byte)rgb.green; - srcBlues[i] = (byte)rgb.blue; - } - } - byte[] destReds = null, destGreens = null, destBlues = null; - int destRedMask = 0, destGreenMask = 0, destBlueMask = 0; - final boolean screenDirect; - if (screenDepth <= 8) { - if (xcolors == null) return SWT.ERROR_UNSUPPORTED_DEPTH; - destReds = new byte[xcolors.length]; - destGreens = new byte[xcolors.length]; - destBlues = new byte[xcolors.length]; - for (int i = 0; i < xcolors.length; i++) { - XColor color = xcolors[i]; - if (color == null) continue; - destReds[i] = (byte)((color.red >> 8) & 0xFF); - destGreens[i] = (byte)((color.green >> 8) & 0xFF); - destBlues[i] = (byte)((color.blue >> 8) & 0xFF); - } - screenDirect = false; - } else { - Visual xVisual = new Visual(); - OS.memmove(xVisual, visual, Visual.sizeof); - destRedMask = xVisual.red_mask; - destGreenMask = xVisual.green_mask; - destBlueMask = xVisual.blue_mask; - screenDirect = true; - } - if (transparentPixel != null) { - int transRed = 0, transGreen = 0, transBlue = 0; - if (palette.isDirect) { - RGB rgb = palette.getRGB(transparentPixel[0]); - transRed = rgb.red; - transGreen = rgb.green; - transBlue = rgb.blue; - } else { - RGB[] rgbs = palette.getRGBs(); - if (transparentPixel[0] < rgbs.length) { - RGB rgb = rgbs[transparentPixel[0]]; - transRed = rgb.red; - transGreen = rgb.green; - transBlue = rgb.blue; - } - } - transparentPixel[0] = ImageData.closestMatch(screenDepth, (byte)transRed, (byte)transGreen, (byte)transBlue, - destRedMask, destGreenMask, destBlueMask, destReds, destGreens, destBlues); - } - - /* Depth 1 */ - if (image.depth == 1) { - int xImagePtr = OS.XCreateImage(display, visual, 1, OS.XYBitmap, 0, 0, destWidth, destHeight, image.scanlinePad * 8, 0); - if (xImagePtr == 0) return SWT.ERROR_NO_HANDLES; - XImage xImage = new XImage(); - OS.memmove(xImage, xImagePtr, XImage.sizeof); - int bufSize = xImage.bytes_per_line * xImage.height; - int bufPtr = OS.XtMalloc(bufSize); - xImage.data = bufPtr; - OS.memmove(xImagePtr, xImage, XImage.sizeof); - byte[] buf = new byte[bufSize]; - ImageData.blit(ImageData.BLIT_SRC, - image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, null, null, null, - ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY, - buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.bitmap_bit_order, 0, 0, destWidth, destHeight, null, null, null, - flipX, flipY); - OS.memmove(xImage.data, buf, bufSize); - - int foreground = 1, background = 0; - if (!isMask) { - foreground = 0; - if (srcReds.length > 1) { - foreground = ImageData.closestMatch(screenDepth, srcReds[1], srcGreens[1], srcBlues[1], - destRedMask, destGreenMask, destBlueMask, destReds, destGreens, destBlues); - } - if (srcReds.length > 0) { - background = ImageData.closestMatch(screenDepth, srcReds[0], srcGreens[0], srcBlues[0], - destRedMask, destGreenMask, destBlueMask, destReds, destGreens, destBlues); - } - } - XGCValues values = new XGCValues(); - OS.XGetGCValues(display, gc, OS.GCForeground | OS.GCBackground, values); - OS.XSetForeground(display, gc, foreground); - OS.XSetBackground(display, gc, background); - OS.XPutImage(display, drawable, gc, xImagePtr, 0, 0, destX, destY, destWidth, destHeight); - OS.XSetForeground(display, gc, values.foreground); - OS.XSetBackground(display, gc, values.background); - OS.XDestroyImage(xImagePtr); - return 0; - } - - /* Depths other than 1 */ - int xImagePtr = OS.XCreateImage(display, visual, screenDepth, OS.ZPixmap, 0, 0, destWidth, destHeight, image.scanlinePad * 8, 0); - if (xImagePtr == 0) return SWT.ERROR_NO_HANDLES; - XImage xImage = new XImage(); - OS.memmove(xImage, xImagePtr, XImage.sizeof); - int bufSize = xImage.bytes_per_line * xImage.height; - int bufPtr = OS.XtMalloc(bufSize); - xImage.data = bufPtr; - OS.memmove(xImagePtr, xImage, XImage.sizeof); - byte[] buf = new byte[bufSize]; - if (palette.isDirect) { - if (screenDirect) { - ImageData.blit(ImageData.BLIT_SRC, - image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, palette.redMask, palette.greenMask, palette.blueMask, - ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY, - buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, xImage.red_mask, xImage.green_mask, xImage.blue_mask, - flipX, flipY); - } else { - ImageData.blit(ImageData.BLIT_SRC, - image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, palette.redMask, palette.greenMask, palette.blueMask, - ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY, - buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, destReds, destGreens, destBlues, - flipX, flipY); - } - } else { - if (screenDirect) { - ImageData.blit(ImageData.BLIT_SRC, - image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, srcReds, srcGreens, srcBlues, - ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY, - buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, xImage.red_mask, xImage.green_mask, xImage.blue_mask, - flipX, flipY); - } else { - ImageData.blit(ImageData.BLIT_SRC, - image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, srcReds, srcGreens, srcBlues, - ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY, - buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, destReds, destGreens, destBlues, - flipX, flipY); - } - } - OS.memmove(xImage.data, buf, bufSize); - OS.XPutImage(display, drawable, gc, xImagePtr, 0, 0, destX, destY, destWidth, destHeight); - OS.XDestroyImage(xImagePtr); - return 0; -} -/** - * Sets the color to which to map the transparent pixel. - * <p> - * There are certain uses of <code>Images</code> that do not support - * transparency (for example, setting an image into a button or label). - * In these cases, it may be desired to simulate transparency by using - * the background color of the widget to paint the transparent pixels - * of the image. This method specifies the color that will be used in - * these cases. For example: - * <pre> - * Button b = new Button(); - * image.setBackground(b.getBackground()); - * b.setImage(image); - * </pre> - * </p><p> - * The image may be modified by this operation (in effect, the - * transparent regions may be filled with the supplied color). Hence - * this operation is not reversible and it is not legal to call - * this function twice or with a null argument. - * </p><p> - * This method has no effect if the receiver does not have a transparent - * pixel value. - * </p> - * - * @param color the color to use when a transparent pixel is specified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the color is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setBackground(Color color) { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (transparentPixel == -1) return; - /* Generate the mask if necessary. */ - if (mask == 0) createMask(); - Rectangle bounds = getBounds(); - int[] unused = new int[1]; - int[] depth = new int[1]; - int xDisplay = device.xDisplay; - OS.XGetGeometry(xDisplay, pixmap, unused, unused, unused, unused, unused, unused, depth); - int drawable = OS.XDefaultRootWindow(xDisplay); - int tempPixmap = OS.XCreatePixmap(xDisplay, drawable, bounds.width, bounds.height, depth[0]); - int xGC = OS.XCreateGC(xDisplay, tempPixmap, 0, null); - OS.XSetForeground(xDisplay, xGC, color.handle.pixel); - OS.XFillRectangle(xDisplay, tempPixmap, xGC, 0, 0, bounds.width, bounds.height); - OS.XSetClipMask(xDisplay, xGC, mask); - OS.XCopyArea(xDisplay, pixmap, tempPixmap, xGC, 0, 0, bounds.width, bounds.height, 0, 0); - OS.XSetClipMask(xDisplay, xGC, OS.None); - OS.XCopyArea(xDisplay, tempPixmap, pixmap, xGC, 0, 0, bounds.width, bounds.height, 0, 0); - OS.XFreePixmap(xDisplay, tempPixmap); - OS.XFreeGC(xDisplay, xGC); - /* Destroy the receiver's mask if the there is a GC created on it */ - if (memGC != null) destroyMask(); -} -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the receiver - */ -public String toString () { - if (isDisposed()) return "Image {*DISPOSED*}"; - return "Image {" + pixmap + "}"; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java deleted file mode 100755 index 8aaaefb757..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java +++ /dev/null @@ -1,561 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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.motif.*; -import org.eclipse.swt.*; - -/** - * Instances of this class represent areas of an x-y coordinate - * system that are aggregates of the areas covered by a number - * of polygons. - * <p> - * Application code must explicitly invoke the <code>Region.dispose()</code> - * method to release the operating system resources managed by each instance - * when those instances are no longer required. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public final class Region extends Resource { - /** - * the OS resource for the region - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public int handle; - -/** - * Constructs a new empty region. - * - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li> - * </ul> - */ -public Region () { - this(null); -} -/** - * Constructs a new empty region. - * <p> - * You must dispose the region when it is no longer required. - * </p> - * - * @param device the device on which to allocate the region - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li> - * </ul> - * - * @see #dispose - * - * @since 3.0 - */ -public Region (Device device) { - super(device); - handle = OS.XCreateRegion (); - if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); - init(); -} -Region (Device device, int handle) { - super(device); - this.handle = handle; -} -/** - * Adds the given polygon to the collection of polygons - * the receiver maintains to describe its area. - * - * @param pointArray points that describe the polygon to merge with the receiver - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.0 -* - */ -public void add (int[] pointArray) { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - short[] points = new short[pointArray.length]; - for (int i = 0; i < pointArray.length; i++) { - points[i] = (short)pointArray[i]; - } - int polyRgn = OS.XPolygonRegion(points, points.length / 2, OS.EvenOddRule); - OS.XUnionRegion(handle, polyRgn, handle); - OS.XDestroyRegion(polyRgn); -} -/** - * Adds the given rectangle to the collection of polygons - * the receiver maintains to describe its area. - * - * @param rect the rectangle to merge with the receiver - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void add (Rectangle rect) { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - add (rect.x, rect.y, rect.width, rect.height); -} -/** - * Adds the given rectangle to the collection of polygons - * the receiver maintains to describe its area. - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param width the width coordinate of the rectangle - * @param height the height coordinate of the rectangle - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public void add (int x, int y, int width, int height) { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - XRectangle xRect = new XRectangle(); - xRect.x = (short)x; - xRect.y = (short)y; - xRect.width = (short)width; - xRect.height = (short)height; - OS.XUnionRectWithRegion(xRect, handle, handle); -} -/** - * Adds all of the polygons which make up the area covered - * by the argument to the collection of polygons the receiver - * maintains to describe its area. - * - * @param region the region to merge - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void add (Region region) { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - OS.XUnionRegion(handle, region.handle, handle); -} -/** - * Returns <code>true</code> if the point specified by the - * arguments is inside the area specified by the receiver, - * and <code>false</code> otherwise. - * - * @param x the x coordinate of the point to test for containment - * @param y the y coordinate of the point to test for containment - * @return <code>true</code> if the region contains the point and <code>false</code> otherwise - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public boolean contains (int x, int y) { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return OS.XPointInRegion(handle, x, y); -} -/** - * Returns <code>true</code> if the given point is inside the - * area specified by the receiver, and <code>false</code> - * otherwise. - * - * @param pt the point to test for containment - * @return <code>true</code> if the region contains the point and <code>false</code> otherwise - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public boolean contains (Point pt) { - if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - return contains(pt.x, pt.y); -} -void destroy() { - OS.XDestroyRegion(handle); - handle = 0; -} -/** - * Compares the argument to the receiver, and returns true - * if they represent the <em>same</em> object using a class - * specific comparison. - * - * @param object the object to compare with this object - * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise - * - * @see #hashCode - */ -public boolean equals (Object object) { - if (this == object) return true; - if (!(object instanceof Region)) return false; - Region region = (Region)object; - return handle == region.handle; -} -/** - * Returns a rectangle which represents the rectangular - * union of the collection of polygons the receiver - * maintains to describe its area. - * - * @return a bounding rectangle for the region - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see Rectangle#union - */ -public Rectangle getBounds() { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - XRectangle rect = new XRectangle(); - OS.XClipBox(handle, rect); - return new Rectangle(rect.x, rect.y, rect.width, rect.height); -} -/** - * Returns an integer hash code for the receiver. Any two - * objects that return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals - */ -public int hashCode () { - return handle; -} -/** - * Intersects the given rectangle to the collection of polygons - * the receiver maintains to describe its area. - * - * @param rect the rectangle to intersect with the receiver - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.0 - */ -public void intersect (Rectangle rect) { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - intersect(rect.x, rect.y, rect.width, rect.height); -} -/** - * Intersects the given rectangle to the collection of polygons - * the receiver maintains to describe its area. - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param width the width coordinate of the rectangle - * @param height the height coordinate of the rectangle - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public void intersect (int x, int y, int width, int height) { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - int rectRgn = OS.XCreateRegion(); - XRectangle xRect = new XRectangle(); - xRect.x = (short)x; - xRect.y = (short)y; - xRect.width = (short)width; - xRect.height = (short)height; - OS.XUnionRectWithRegion(xRect, rectRgn, rectRgn); - OS.XIntersectRegion(handle, rectRgn, handle); - OS.XDestroyRegion(rectRgn); -} -/** - * Intersects all of the polygons which make up the area covered - * by the argument to the collection of polygons the receiver - * maintains to describe its area. - * - * @param region the region to intersect - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.0 - */ -public void intersect (Region region) { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - OS.XIntersectRegion(handle, region.handle, handle); -} -/** - * Returns <code>true</code> if the rectangle described by the - * arguments intersects with any of the polygons the receiver - * maintains to describe its area, and <code>false</code> otherwise. - * - * @param x the x coordinate of the origin of the rectangle - * @param y the y coordinate of the origin of the rectangle - * @param width the width of the rectangle - * @param height the height of the rectangle - * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see Rectangle#intersects(Rectangle) - */ -public boolean intersects (int x, int y, int width, int height) { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return OS.XRectInRegion (handle, x, y, width, height) != OS.RectangleOut; -} -/** - * Returns <code>true</code> if the given rectangle intersects - * with any of the polygons the receiver maintains to describe - * its area and <code>false</code> otherwise. - * - * @param rect the rectangle to test for intersection - * @return <code>true</code> if the rectangle intersects with the receiver, and <code>false</code> otherwise - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see Rectangle#intersects(Rectangle) - */ -public boolean intersects (Rectangle rect) { - if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - return intersects(rect.x, rect.y, rect.width, rect.height); -} -/** - * Returns <code>true</code> if the region has been disposed, - * and <code>false</code> otherwise. - * <p> - * This method gets the dispose state for the region. - * When a region has been disposed, it is an error to - * invoke any other method using the region. - * - * @return <code>true</code> when the region is disposed, and <code>false</code> otherwise - */ -public boolean isDisposed() { - return handle == 0; -} -/** - * Returns <code>true</code> if the receiver does not cover any - * area in the (x, y) coordinate plane, and <code>false</code> if - * the receiver does cover some area in the plane. - * - * @return <code>true</code> if the receiver is empty, and <code>false</code> otherwise - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public boolean isEmpty () { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return OS.XEmptyRegion(handle); -} -public static Region motif_new(Device device, int handle) { - return new Region(device, handle); -} -/** - * Subtracts the given polygon from the collection of polygons - * the receiver maintains to describe its area. - * - * @param pointArray points that describe the polygon to merge with the receiver - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.0 - */ -public void subtract (int[] pointArray) { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - short[] points = new short[pointArray.length]; - for (int i = 0; i < pointArray.length; i++) { - points[i] = (short)pointArray[i]; - } - int polyRgn = OS.XPolygonRegion(points, points.length / 2, OS.EvenOddRule); - OS.XSubtractRegion(handle, polyRgn, handle); - OS.XDestroyRegion(polyRgn); -} -/** - * Subtracts the given rectangle from the collection of polygons - * the receiver maintains to describe its area. - * - * @param rect the rectangle to subtract from the receiver - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.0 - */ -public void subtract (Rectangle rect) { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - subtract (rect.x, rect.y, rect.width, rect.height); -} -/** - * Subtracts the given rectangle from the collection of polygons - * the receiver maintains to describe its area. - * - * @param x the x coordinate of the rectangle - * @param y the y coordinate of the rectangle - * @param width the width coordinate of the rectangle - * @param height the height coordinate of the rectangle - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the rectangle's width or height is negative</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public void subtract (int x, int y, int width, int height) { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (width < 0 || height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - int rectRgn = OS.XCreateRegion(); - XRectangle xRect = new XRectangle(); - xRect.x = (short)x; - xRect.y = (short)y; - xRect.width = (short)width; - xRect.height = (short)height; - OS.XUnionRectWithRegion(xRect, rectRgn, rectRgn); - OS.XSubtractRegion(handle, rectRgn, handle); - OS.XDestroyRegion(rectRgn); -} -/** - * Subtracts all of the polygons which make up the area covered - * by the argument from the collection of polygons the receiver - * maintains to describe its area. - * - * @param region the region to subtract - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.0 - */ -public void subtract (Region region) { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - OS.XSubtractRegion(handle, region.handle, handle); -} -/** - * Translate all of the polygons the receiver maintains to describe - * its area by the specified point. - * - * @param x the x coordinate of the point to translate - * @param y the y coordinate of the point to translate - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public void translate (int x, int y) { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - OS.XOffsetRegion (handle, x, y); -} -/** - * Translate all of the polygons the receiver maintains to describe - * its area by the specified point. - * - * @param pt the point to translate - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public void translate (Point pt) { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - translate (pt.x, pt.y); -} -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the receiver - */ -public String toString () { - if (isDisposed()) return "Region {*DISPOSED*}"; - return "Region {" + handle + "}"; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/TextLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/TextLayout.java deleted file mode 100644 index a03a44526c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/TextLayout.java +++ /dev/null @@ -1,1935 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.graphics; - -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; - -/** - * <code>TextLayout</code> is a graphic object that represents - * styled text. - * <p> - * Instances of this class provide support for drawing, cursor - * navigation, hit testing, text wrapping, alignment, tab expansion - * line breaking, etc. These are aspects required for rendering internationalized text. - * </p><p> - * Application code must explicitly invoke the <code>TextLayout#dispose()</code> - * method to release the operating system resources managed by each instance - * when those instances are no longer required. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#textlayout">TextLayout, TextStyle snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: CustomControlExample, StyledText tab</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 3.0 - */ -public final class TextLayout extends Resource { - Font font; - String text; - int lineSpacing; - int ascent, descent; - int alignment; - int wrapWidth; - int orientation; - int indent; - boolean justify; - int[] tabs; - int[] segments; - StyleItem[] styles; - - StyleItem[][] runs; - int[] lineOffset, lineY, lineWidth; - int defaultAscent, defaultDescent; - - static final RGB LINK_FOREGROUND = new RGB (0, 51, 153); - - static class StyleItem { - TextStyle style; - int start, length, width, height, baseline; - boolean lineBreak, softBreak, tab; - - public String toString () { - return "StyleItem {" + start + ", " + style + "}"; - } - } - -/** - * Constructs a new instance of this class on the given device. - * <p> - * You must dispose the text layout when it is no longer required. - * </p> - * - * @param device the device on which to allocate the text layout - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * </ul> - * - * @see #dispose() - */ -public TextLayout (Device device) { - super(device); - wrapWidth = ascent = descent = -1; - lineSpacing = 0; - orientation = SWT.LEFT_TO_RIGHT; - XFontStruct fontStruct = getFontHeigth(this.device.getSystemFont()); - defaultAscent = fontStruct.ascent; - defaultDescent = fontStruct.descent; - styles = new StyleItem[2]; - styles[0] = new StyleItem(); - styles[1] = new StyleItem(); - text = ""; //$NON-NLS-1$ - init(); -} - -void checkLayout () { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); -} - -int stringWidth (StyleItem run, char[] ch) { - if (ch.length == 0) return 0; - Font font = getItemFont(run); - int fontList = font.handle; - byte[] buffer = Converter.wcsToMbcs(font.codePage, ch, true); - int xmString = OS.XmStringCreateLocalized(buffer); - int width = OS.XmStringWidth(fontList, xmString); - OS.XmStringFree(xmString); - return width; -} - -void computeRuns () { - if (runs != null) return; - StyleItem[] allRuns = itemize(); - for (int i=0; i<allRuns.length-1; i++) { - StyleItem run = allRuns[i]; - place(run); - } - int lineWidth = 0, lineStart = 0, lineCount = 1; - for (int i=0; i<allRuns.length - 1; i++) { - StyleItem run = allRuns[i]; - if (run.length == 1) { - char ch = text.charAt(run.start); - switch (ch) { - case '\t': { - run.tab = true; - run.baseline = 0; - if (tabs == null) break; - int tabsLength = tabs.length, j; - for (j = 0; j < tabsLength; j++) { - if (tabs[j] > lineWidth) { - run.width = tabs[j] - lineWidth; - break; - } - } - if (j == tabsLength) { - int tabX = tabs[tabsLength-1]; - int lastTabWidth = tabsLength > 1 ? tabs[tabsLength-1] - tabs[tabsLength-2] : tabs[0]; - if (lastTabWidth > 0) { - while (tabX <= lineWidth) tabX += lastTabWidth; - run.width = tabX - lineWidth; - } - } - break; - } - case '\n': - run.lineBreak = true; - run.baseline = run.width = 0; - break; - case '\r': - run.lineBreak = true; - run.baseline = run.width = 0; - StyleItem next = allRuns[i + 1]; - if (next.length != 0 && text.charAt(next.start) == '\n') { - run.length += 1; - i++; - } - break; - } - } - if (wrapWidth != -1 && lineWidth + run.width > wrapWidth && !run.tab) { - int start = 0; - char[] chars = new char[run.length]; - text.getChars(run.start, run.start + run.length, chars, 0); - if (!(run.style != null && run.style.metrics != null)) { - int width = 0, maxWidth = wrapWidth - lineWidth; - char[] buffer = new char[1]; - buffer[0] = chars[start]; - int charWidth = stringWidth(run, buffer); - while (width + charWidth < maxWidth) { - width += charWidth; - start++; - buffer[0] = chars[start]; - charWidth = stringWidth(run, buffer); - } - } - int firstStart = start; - int firstIndice = i; - while (i >= lineStart) { - chars = new char[run.length]; - text.getChars(run.start, run.start + run.length, chars, 0); - while(start >= 0) { - if (Compatibility.isSpaceChar(chars[start]) || Compatibility.isWhitespace(chars[start])) break; - start--; - } - if (start >= 0 || i == lineStart) break; - run = allRuns[--i]; - start = run.length - 1; - } - if (start == 0 && i != lineStart) { - run = allRuns[--i]; - } else if (start <= 0 && i == lineStart) { - i = firstIndice; - run = allRuns[i]; - start = Math.max(1, firstStart); - } - chars = new char[run.length]; - text.getChars(run.start, run.start + run.length, chars, 0); - while (start < run.length) { - if (!Compatibility.isWhitespace(chars[start])) break; - start++; - } - if (0 < start && start < run.length) { - StyleItem newRun = new StyleItem(); - newRun.start = run.start + start; - newRun.length = run.length - start; - newRun.style = run.style; - run.length = start; - place (run); - place (newRun); - StyleItem[] newAllRuns = new StyleItem[allRuns.length + 1]; - System.arraycopy(allRuns, 0, newAllRuns, 0, i + 1); - System.arraycopy(allRuns, i + 1, newAllRuns, i + 2, allRuns.length - i - 1); - allRuns = newAllRuns; - allRuns[i + 1] = newRun; - } - if (i != allRuns.length - 2) { - run.softBreak = run.lineBreak = true; - } - } - lineWidth += run.width; - if (run.lineBreak) { - lineStart = i + 1; - lineWidth = 0; - lineCount++; - } - } - lineWidth = 0; - runs = new StyleItem[lineCount][]; - lineOffset = new int[lineCount + 1]; - lineY = new int[lineCount + 1]; - this.lineWidth = new int[lineCount]; - int lineRunCount = 0, line = 0; - int ascent = Math.max(defaultAscent, this.ascent); - int descent = Math.max(defaultDescent, this.descent); - StyleItem[] lineRuns = new StyleItem[allRuns.length]; - XFontStruct fontStruct; - for (int i=0; i<allRuns.length; i++) { - StyleItem run = allRuns[i]; - lineRuns[lineRunCount++] = run; - lineWidth += run.width; - if (run.style != null ) { - int runAscent = defaultAscent; - int runDescent = defaultDescent; - if (run.style.metrics != null) { - GlyphMetrics metrics = run.style.metrics; - runAscent = metrics.ascent; - runDescent = metrics.descent; - } else if (run.style.font != null) { - fontStruct = getFontHeigth(run.style.font); - runAscent = fontStruct.ascent; - runDescent = fontStruct.descent; - } - ascent = Math.max(ascent, runAscent + run.style.rise); - descent = Math.max(descent, runDescent - run.style.rise); - if (run.style.rise != 0) { - run.baseline += run.style.rise; - } - } - if (run.lineBreak || i == allRuns.length - 1) { - runs[line] = new StyleItem[lineRunCount]; - System.arraycopy(lineRuns, 0, runs[line], 0, lineRunCount); - StyleItem lastRun = runs[line][lineRunCount - 1]; - this.lineWidth[line] = lineWidth; - line++; - lineY[line] = lineY[line - 1] + ascent + descent + lineSpacing; - lineOffset[line] = lastRun.start + lastRun.length; - lineRunCount = lineWidth = 0; - ascent = Math.max(defaultAscent, this.ascent); - descent = Math.max(defaultDescent, this.descent); - } - } -} - -void destroy() { - freeRuns(); - font = null; - text = null; - tabs = null; - styles = null; - lineOffset = null; - lineY = null; - lineWidth = null; -} - -/** - * Draws the receiver's text using the specified GC at the specified - * point. - * - * @param gc the GC to draw - * @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 SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the gc is null</li> - * </ul> - */ -public void draw (GC gc, int x, int y) { - draw(gc, x, y, -1, -1, null, null); -} - -/** - * Draws the receiver's text using the specified GC at the specified - * point. - * - * @param gc the GC to draw - * @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 selectionStart the offset where the selections starts, or -1 indicating no selection - * @param selectionEnd the offset where the selections ends, or -1 indicating no selection - * @param selectionForeground selection foreground, or NULL to use the system default color - * @param selectionBackground selection background, or NULL to use the system default color - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the gc is null</li> - * </ul> - */ -public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground) { - draw(gc, x, y, selectionStart, selectionEnd, selectionForeground, selectionBackground, 0); -} - -/** - * Draws the receiver's text using the specified GC at the specified - * point. - * <p> - * The parameter <code>flags</code> can include one of <code>SWT.DELIMITER_SELECTION</code> - * or <code>SWT.FULL_SELECTION</code> to specify the selection behavior on all lines except - * for the last line, and can also include <code>SWT.LAST_LINE_SELECTION</code> to extend - * the specified selection behavior to the last line. - * </p> - * @param gc the GC to draw - * @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 selectionStart the offset where the selections starts, or -1 indicating no selection - * @param selectionEnd the offset where the selections ends, or -1 indicating no selection - * @param selectionForeground selection foreground, or NULL to use the system default color - * @param selectionBackground selection background, or NULL to use the system default color - * @param flags drawing options - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the gc is null</li> - * </ul> - * - * @since 3.3 - */ -public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags) { - checkLayout(); - computeRuns(); - if (gc == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (selectionForeground != null && selectionForeground.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (selectionBackground != null && selectionBackground.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - gc.checkGC(GC.FOREGROUND); - int length = text.length(); - if (length == 0 && flags == 0) return; - boolean hasSelection = selectionStart <= selectionEnd && selectionStart != -1 && selectionEnd != -1; - if (hasSelection || (flags & SWT.LAST_LINE_SELECTION) != 0) { - selectionStart = Math.min(Math.max(0, selectionStart), length - 1); - selectionEnd = Math.min(Math.max(0, selectionEnd), length - 1); - if (selectionForeground == null) selectionForeground = device.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT); - if (selectionBackground == null) selectionBackground = device.getSystemColor(SWT.COLOR_LIST_SELECTION); - } - final Color foreground = gc.getForeground(); - final Color background = gc.getBackground(); - final Font gcFont = gc.getFont(); - Color linkColor = null; - Rectangle clip = gc.getClipping(); - for (int line=0; line<runs.length; line++) { - int drawX = x + getLineIndent(line); - int drawY = y + lineY[line]; - StyleItem[] lineRuns = runs[line]; - int lineHeight = lineY[line+1] - lineY[line]; - if (flags != 0 && (hasSelection || (flags & SWT.LAST_LINE_SELECTION) != 0)) { - boolean extent = false; - if (line == runs.length - 1 && (flags & SWT.LAST_LINE_SELECTION) != 0) { - extent = true; - } else { - StyleItem run = lineRuns[lineRuns.length - 1]; - if (run.lineBreak && !run.softBreak) { - if (selectionStart <= run.start && run.start <= selectionEnd) extent = true; - } else { - int endOffset = run.start + run.length - 1; - if (selectionStart <= endOffset && endOffset < selectionEnd && (flags & SWT.FULL_SELECTION) != 0) { - extent = true; - } - } - } - if (extent) { - gc.setBackground(selectionBackground); - int width = (flags & SWT.FULL_SELECTION) != 0 ? 0x7fffffff : lineHeight / 3; - gc.fillRectangle(drawX + lineWidth[line], drawY, width, lineHeight); - } - } - if (drawX > clip.x + clip.width) continue; - if (drawX + lineWidth[line] < clip.x) continue; - int baseline = Math.max(0, this.ascent); - for (int i = 0; i < lineRuns.length; i++) { - baseline = Math.max(baseline, lineRuns[i].baseline); - } - for (int i = 0; i < lineRuns.length; i++) { - StyleItem run = lineRuns[i]; - if (run.length == 0) continue; - if (drawX > clip.x + clip.width) break; - if (drawX + run.width >= clip.x) { - if (!run.lineBreak || run.softBreak) { - String string = text.substring(run.start, run.start + run.length); - int drawRunY = drawY + (baseline - run.baseline); - int end = run.start + run.length - 1; - gc.setFont(getItemFont(run)); - boolean fullSelection = hasSelection && selectionStart <= run.start && selectionEnd >= end; - TextStyle style = run.style; - if (fullSelection) { - gc.setBackground(selectionBackground); - gc.fillRectangle(drawX, drawY, run.width, lineHeight); - if (!run.tab && !(style != null && style.metrics != null)) { - gc.setForeground(selectionForeground); - gc.drawString(string, drawX, drawRunY, true); - drawLines(gc, run, drawX, drawRunY, run.width); - } - } else { - if (style != null && style.background != null) { - Color bg = style.background; - gc.setBackground(bg); - gc.fillRectangle(drawX, drawRunY, run.width, run.height); - } - if (!run.tab) { - Color fg = foreground; - if (style != null) { - if (style.foreground != null) { - fg = style.foreground; - } else { - if (style.underline && style.underlineStyle == SWT.UNDERLINE_LINK) { - if (linkColor == null) { - linkColor = new Color(device, LINK_FOREGROUND); - } - fg = linkColor; - } - } - } - if (!(style != null && style.metrics != null)) { - gc.setForeground(fg); - gc.drawString(string, drawX, drawRunY, true); - drawLines(gc, run, drawX, drawRunY, run.width); - } - boolean partialSelection = hasSelection && !(selectionStart > end || run.start > selectionEnd); - if (partialSelection) { - int selStart = Math.max(selectionStart, run.start); - int selEnd = Math.min(selectionEnd, end); - string = text.substring(run.start, selStart); - int selX = drawX + gc.stringExtent(string).x; - string = text.substring(selStart, selEnd + 1); - int selWidth = gc.stringExtent(string).x; - gc.setBackground(selectionBackground); - gc.fillRectangle(selX, drawY, selWidth, lineHeight); - if (fg != selectionForeground && !(style != null && style.metrics != null)) { - gc.setForeground(selectionForeground); - gc.drawString(string, selX, drawRunY, true); - drawLines(gc, run, selX, drawRunY, selWidth); - } - } - } - } - drawBorder(gc, lineRuns, i, drawX, drawY, lineHeight, foreground); - } - } - drawX += run.width; - } - } - gc.setForeground(foreground); - gc.setBackground(background); - gc.setFont(gcFont); - if (linkColor != null) linkColor.dispose(); -} - -void drawBorder(GC gc, StyleItem[] line, int index, int x, int y, int lineHeight, Color color) { - StyleItem run = line[index]; - TextStyle style = run.style; - if (style == null) return; - if (style.borderStyle != SWT.NONE && (index + 1 >= line.length || !style.isAdherentBorder(line[index + 1].style))) { - int width = run.width; - for (int i = index; i > 0 && style.isAdherentBorder(line[i - 1].style); i--) { - x -= line[i - 1].width; - width += line[i - 1].width; - } - if (style.borderColor != null) { - color = style.borderColor; - } else { - if (style.foreground != null) { - color = style.foreground; - } - } - gc.setForeground(color); - int lineStyle = gc.getLineStyle(); - int[] dashes = null; - if (lineStyle == SWT.LINE_CUSTOM) { - dashes = gc.getLineDash(); - } - switch (style.borderStyle) { - case SWT.BORDER_SOLID: - gc.setLineStyle(SWT.LINE_SOLID); - break; - case SWT.BORDER_DASH: - gc.setLineStyle(SWT.LINE_DASH); - break; - case SWT.BORDER_DOT: - gc.setLineStyle(SWT.LINE_DOT); - break; - } - gc.drawRectangle(x, y, width - 1, lineHeight - 1); - gc.setLineStyle(lineStyle); - if (dashes != null) { - gc.setLineDash(dashes); - } - } -} - -void drawLines(GC gc, StyleItem run, int x, int y, int width) { - TextStyle style = run.style; - if (style == null) return; - if (style.underline) { - int underlineY = y + run.baseline + 1 - style.rise; - if (style.underlineColor != null) { - gc.setForeground(style.underlineColor); - } - switch (style.underlineStyle) { - case SWT.UNDERLINE_SQUIGGLE: - case SWT.UNDERLINE_ERROR: - int squigglyThickness = 1; - int squigglyHeight = 2 * squigglyThickness; - int squigglyY = Math.min(underlineY, y + run.height - squigglyHeight - 1); - int[] points = computePolyline(x, squigglyY, x + width, squigglyY + squigglyHeight); - gc.drawPolyline(points); - break; - case SWT.UNDERLINE_DOUBLE: - gc.drawLine (x, underlineY + 2, x + width, underlineY + 2); - //FALLTHROU - case SWT.UNDERLINE_LINK: - case SWT.UNDERLINE_SINGLE: - gc.drawLine (x, underlineY, x + width, underlineY); - } - } - if (style.strikeout) { - int strikeoutY = y + run.height - run.height/2 - 1; - if (style.strikeoutColor != null) { - gc.setForeground(style.strikeoutColor); - } - gc.drawLine (x, strikeoutY, x + width, strikeoutY); - } -} - -int[] computePolyline(int left, int top, int right, int bottom) { - int height = bottom - top; // can be any number - int width = 2 * height; // must be even - int peaks = (right - left) / width; - if (peaks == 0 && right - left > 2) { - peaks = 1; - } - int length = ((2 * peaks) + 1) * 2; - if (length < 0) return new int[0]; - - int[] coordinates = new int[length]; - for (int i = 0; i < peaks; i++) { - int index = 4 * i; - coordinates[index] = left + (width * i); - coordinates[index+1] = bottom; - coordinates[index+2] = coordinates[index] + width / 2; - coordinates[index+3] = top; - } - coordinates[length-2] = Math.min(Math.max(0, right - 1), left + (width * peaks)); - coordinates[length-1] = bottom; - return coordinates; -} - -void freeRuns() { - runs = null; -} - -/** - * Returns the receiver's horizontal text alignment, which will be one - * of <code>SWT.LEFT</code>, <code>SWT.CENTER</code> or - * <code>SWT.RIGHT</code>. - * - * @return the alignment used to positioned text horizontally - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int getAlignment () { - checkLayout(); - return alignment; -} - -/** - * Returns the ascent of the receiver. - * - * @return the ascent - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #getDescent() - * @see #setDescent(int) - * @see #setAscent(int) - * @see #getLineMetrics(int) - */ -public int getAscent () { - checkLayout(); - return ascent; -} - -/** - * Returns the bounds of the receiver. The width returned is either the - * width of the longest line or the width set using {@link TextLayout#setWidth(int)}. - * To obtain the text bounds of a line use {@link TextLayout#getLineBounds(int)}. - * - * @return the bounds of the receiver - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #setWidth(int) - * @see #getLineBounds(int) - */ -public Rectangle getBounds () { - checkLayout(); - computeRuns(); - int width = 0; - if (wrapWidth != -1) { - width = wrapWidth; - } else { - for (int line=0; line<runs.length; line++) { - width = Math.max(width, lineWidth[line] + getLineIndent(line)); - } - } - return new Rectangle (0, 0, width, lineY[lineY.length - 1]); -} - -/** - * Returns the bounds for the specified range of characters. The - * bounds is the smallest rectangle that encompasses all characters - * in the range. The start and end offsets are inclusive and will be - * clamped if out of range. - * - * @param start the start offset - * @param end the end offset - * @return the bounds of the character range - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Rectangle getBounds (int start, int end) { - checkLayout(); - computeRuns(); - int length = text.length(); - if (length == 0) return new Rectangle(0, 0, 0, 0); - if (start > end) return new Rectangle(0, 0, 0, 0); - start = Math.min(Math.max(0, start), length - 1); - end = Math.min(Math.max(0, end), length - 1); - int startLine = getLineIndex(start); - int endLine = getLineIndex(end); - - Rectangle rect = new Rectangle(0, 0, 0, 0); - rect.y = lineY[startLine]; - rect.height = lineY[endLine + 1] - rect.y - lineSpacing; - if (startLine == endLine) { - rect.x = getLocation(start, false).x; - rect.width = getLocation(end, true).x - rect.x; - } else { - while (startLine <= endLine) { - rect.width = Math.max(rect.width, lineWidth[startLine++]); - } - } - return rect; -} - -/** - * Returns the descent of the receiver. - * - * @return the descent - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #getAscent() - * @see #setAscent(int) - * @see #setDescent(int) - * @see #getLineMetrics(int) - */ -public int getDescent () { - checkLayout(); - return descent; -} - -/** - * Returns the default font currently being used by the receiver - * to draw and measure text. - * - * @return the receiver's font - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Font getFont () { - checkLayout(); - return font; -} - -XFontStruct getFontHeigth(Font font) { - int fontList = font.handle; - int [] buffer = new int [1]; - if (!OS.XmFontListInitFontContext (buffer, fontList)) { - SWT.error(SWT.ERROR_NO_HANDLES); - } - int context = buffer [0]; - int ascent = 0, descent = 0; - XFontStruct fontStruct = new XFontStruct (); - int fontListEntry; - int [] fontStructPtr = new int [1]; - int [] fontNamePtr = new int [1]; - while ((fontListEntry = OS.XmFontListNextEntry (context)) != 0) { - int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer); - if (buffer [0] == 0) { - OS.memmove (fontStruct, fontPtr, XFontStruct.sizeof); - ascent = Math.max(ascent, fontStruct.ascent); - descent = Math.max(descent, fontStruct.descent); - } else { - int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr); - int [] fontStructs = new int [nFonts]; - OS.memmove (fontStructs, fontStructPtr [0], nFonts * 4); - for (int i=0; i<nFonts; i++) { - OS.memmove (fontStruct, fontStructs[i], XFontStruct.sizeof); - ascent = Math.max(ascent, fontStruct.ascent); - descent = Math.max(descent, fontStruct.descent); - } - } - } - OS.XmFontListFreeFontContext (context); - fontStruct.ascent = ascent; - fontStruct.descent = descent; - return fontStruct; -} - -/** -* Returns the receiver's indent. -* -* @return the receiver's indent -* -* @exception SWTException <ul> -* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> -* </ul> -* -* @since 3.2 -*/ -public int getIndent () { - checkLayout(); - return indent; -} - -/** -* Returns the receiver's justification. -* -* @return the receiver's justification -* -* @exception SWTException <ul> -* <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> -* </ul> -* -* @since 3.2 -*/ -public boolean getJustify () { - checkLayout(); - return justify; -} - -/** - * Returns the embedding level for the specified character offset. The - * embedding level is usually used to determine the directionality of a - * character in bidirectional text. - * - * @param offset the character offset - * @return the embedding level - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - */ -public int getLevel (int offset) { - checkLayout(); - int length = text.length(); - if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE); - return 0; -} - -/** - * Returns the line offsets. Each value in the array is the - * offset for the first character in a line except for the last - * value, which contains the length of the text. - * - * @return the line offsets - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int[] getLineOffsets () { - checkLayout(); - computeRuns(); - int[] offsets = new int[lineOffset.length]; - System.arraycopy(lineOffset, 0, offsets, 0, offsets.length); - return offsets; -} - -/** - * Returns the bounds of the line for the specified line index. - * - * @param lineIndex the line index - * @return the line bounds - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Rectangle getLineBounds(int lineIndex) { - checkLayout(); - computeRuns(); - if (!(0 <= lineIndex && lineIndex < runs.length)) SWT.error(SWT.ERROR_INVALID_RANGE); - int x = getLineIndent(lineIndex); - int y = lineY[lineIndex]; - int width = lineWidth[lineIndex]; - int height = lineY[lineIndex + 1] - y - lineSpacing; - return new Rectangle (x, y, width, height); -} - -/** - * Returns the receiver's line count. This includes lines caused - * by wrapping. - * - * @return the line count - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int getLineCount () { - checkLayout(); - computeRuns(); - return runs.length; -} - -int getLineIndent (int lineIndex) { - int lineIndent = 0; - if (lineIndex == 0) { - lineIndent = indent; - } else { - StyleItem[] previousLine = runs[lineIndex - 1]; - StyleItem previousRun = previousLine[previousLine.length - 1]; - if (previousRun.lineBreak && !previousRun.softBreak) { - lineIndent = indent; - } - } - if (wrapWidth != -1) { - boolean partialLine = true; -// if (justify) { -// StyleItem[] lineRun = runs[lineIndex]; -// if (lineRun[lineRun.length - 1].softBreak) { -// partialLine = false; -// } -// } - if (partialLine) { - int lineWidth = this.lineWidth[lineIndex] + lineIndent; - switch (alignment) { - case SWT.CENTER: lineIndent += (wrapWidth - lineWidth) / 2; break; - case SWT.RIGHT: lineIndent += wrapWidth - lineWidth; break; - } - } - } - return lineIndent; -} - -/** - * Returns the index of the line that contains the specified - * character offset. - * - * @param offset the character offset - * @return the line index - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int getLineIndex (int offset) { - checkLayout(); - computeRuns(); - int length = text.length(); - if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE); - for (int line=0; line<runs.length; line++) { - if (lineOffset[line + 1] > offset) { - return line; - } - } - return runs.length - 1; -} - -/** - * Returns the font metrics for the specified line index. - * - * @param lineIndex the line index - * @return the font metrics - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the line index is out of range</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public FontMetrics getLineMetrics (int lineIndex) { - checkLayout(); - computeRuns(); - if (!(0 <= lineIndex && lineIndex < runs.length)) SWT.error(SWT.ERROR_INVALID_RANGE); - int ascent = Math.max(defaultAscent, this.ascent); - int descent = Math.max(defaultDescent, this.descent); - if (text.length() != 0) { - GC gc = new GC(device); - StyleItem[] lineRuns = runs[lineIndex]; - for (int i = 0; i < lineRuns.length; i++) { - StyleItem run = lineRuns[i]; - if (run.style != null) { - int runAscent = 0; - int runDescent = 0; - if (run.style.metrics != null) { - GlyphMetrics glyphMetrics = run.style.metrics; - runAscent = glyphMetrics.ascent; - runDescent = glyphMetrics.descent; - } else if (run.style.font != null) { - gc.setFont(run.style.font); - FontMetrics metrics = gc.getFontMetrics(); - runAscent = metrics.getAscent(); - runDescent = metrics.getDescent(); - } - ascent = Math.max(ascent, runAscent + run.style.rise); - descent = Math.max(descent, runDescent - run.style.rise); - } - } - gc.dispose(); - } - return FontMetrics.motif_new(ascent, descent, 0, 0, ascent + descent); -} - -/** - * Returns the location for the specified character offset. The - * <code>trailing</code> argument indicates whether the offset - * corresponds to the leading or trailing edge of the cluster. - * - * @param offset the character offset - * @param trailing the trailing flag - * @return the location of the character offset - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #getOffset(Point, int[]) - * @see #getOffset(int, int, int[]) - */ -public Point getLocation (int offset, boolean trailing) { - checkLayout(); - computeRuns(); - int length = text.length(); - if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE); - int line; - for (line=0; line<runs.length; line++) { - if (lineOffset[line + 1] > offset) break; - } - line = Math.min(line, runs.length - 1); - StyleItem[] lineRuns = runs[line]; - Point result = null; - if (offset == length) { - result = new Point(lineWidth[line], lineY[line]); - } else { - int width = 0; - for (int i=0; i<lineRuns.length; i++) { - StyleItem run = lineRuns[i]; - int end = run.start + run.length; - if (run.start <= offset && offset < end) { - if (run.tab) { - if (trailing || offset == length) width += run.width; - } else { - if (trailing) offset++; - if (run.style != null && run.style.metrics != null) { - GlyphMetrics metrics = run.style.metrics; - width += metrics.width * (offset - run.start); - } else { - char[] chars = new char[offset - run.start]; - text.getChars(run.start, offset, chars, 0); - width += stringWidth(run, chars); - } - } - result = new Point(width, lineY[line]); - break; - } - width += run.width; - } - } - if (result == null) result = new Point(0, 0); - result.x += getLineIndent(line); - return result; -} - -Font getItemFont(StyleItem item) { - if (item.style != null && item.style.font != null) { - return item.style.font; - } - if (this.font != null) { - return this.font; - } - return device.systemFont; -} - -/** - * Returns the next offset for the specified offset and movement - * type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>, - * <code>SWT.MOVEMENT_CLUSTER</code>, <code>SWT.MOVEMENT_WORD</code>, - * <code>SWT.MOVEMENT_WORD_END</code> or <code>SWT.MOVEMENT_WORD_START</code>. - * - * @param offset the start offset - * @param movement the movement type - * @return the next offset - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #getPreviousOffset(int, int) - */ -public int getNextOffset (int offset, int movement) { - checkLayout(); - computeRuns(); - int length = text.length(); - if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE); - if (offset == length) return length; - if ((movement & (SWT.MOVEMENT_CHAR | SWT.MOVEMENT_CLUSTER)) != 0) return offset + 1; - int lineEnd = 0; - for (int i=1; i<lineOffset.length; i++) { - if (lineOffset[i] > offset) { - lineEnd = Math.max(lineOffset[i - 1], lineOffset[i] - 1); - if (i == runs.length) lineEnd++; - break; - } - } - boolean previousSpaceChar = !Compatibility.isLetterOrDigit(text.charAt(offset)); - offset++; - while (offset < lineEnd) { - boolean spaceChar = !Compatibility.isLetterOrDigit(text.charAt(offset)); - if (movement == SWT.MOVEMENT_WORD || movement == SWT.MOVEMENT_WORD_END) { - if (spaceChar && !previousSpaceChar) break; - } - if (movement == SWT.MOVEMENT_WORD_START) { - if (!spaceChar && previousSpaceChar) break; - } - previousSpaceChar = spaceChar; - offset++; - } - return offset; -} - -/** - * Returns the character offset for the specified point. - * For a typical character, the trailing argument will be filled in to - * indicate whether the point is closer to the leading edge (0) or - * the trailing edge (1). When the point is over a cluster composed - * of multiple characters, the trailing argument will be filled with the - * position of the character in the cluster that is closest to - * the point. - * - * @param point the point - * @param trailing the trailing buffer - * @return the character offset - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li> - * <li>ERROR_NULL_ARGUMENT - if the point is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #getLocation(int, boolean) - */ -public int getOffset (Point point, int[] trailing) { - checkLayout(); - if (point == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); - return getOffset (point.x, point.y, trailing); -} - -/** - * Returns the character offset for the specified point. - * For a typical character, the trailing argument will be filled in to - * indicate whether the point is closer to the leading edge (0) or - * the trailing edge (1). When the point is over a cluster composed - * of multiple characters, the trailing argument will be filled with the - * position of the character in the cluster that is closest to - * the point. - * - * @param x the x coordinate of the point - * @param y the y coordinate of the point - * @param trailing the trailing buffer - * @return the character offset - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the trailing length is less than <code>1</code></li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #getLocation(int, boolean) - */ -public int getOffset (int x, int y, int[] trailing) { - checkLayout(); - computeRuns(); - if (trailing != null && trailing.length < 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - int line; - int lineCount = runs.length; - for (line=0; line<lineCount; line++) { - if (lineY[line + 1] > y) break; - } - line = Math.min(line, runs.length - 1); - x -= getLineIndent(line); - if (x >= lineWidth[line]) x = lineWidth[line] - 1; - if (x < 0) x = 0; - StyleItem[] lineRuns = runs[line]; - int width = 0; - for (int i = 0; i < lineRuns.length; i++) { - StyleItem run = lineRuns[i]; - if (run.lineBreak && !run.softBreak) return run.start; - if (width + run.width > x) { - if (run.style != null && run.style.metrics != null) { - int xRun = x - width; - GlyphMetrics metrics = run.style.metrics; - if (metrics.width > 0) { - if (trailing != null) { - trailing[0] = (xRun % metrics.width < metrics.width / 2) ? 0 : 1; - } - return run.start + xRun / metrics.width; - } - } - if (run.tab) { - if (trailing != null) { - trailing[0] = x < (width + run.width / 2) ? 0 : 1; - } - return run.start; - } - int offset = 0; - char[] buffer = new char[1]; - char[] chars = new char[run.length]; - text.getChars(run.start, run.start + run.length, chars, 0); - for (offset = 0; offset < chars.length; offset++) { - buffer[0] = chars[offset]; - int charWidth = stringWidth(run, buffer); - if (width + charWidth > x) { - if (trailing != null) { - trailing[0] = x < (width + charWidth / 2) ? 0 : 1; - } - break; - } - width += charWidth; - } - return run.start + offset; - } - width += run.width; - } - if (trailing != null) trailing[0] = 0; - return lineOffset[line + 1]; -} - -/** - * Returns the orientation of the receiver. - * - * @return the orientation style - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int getOrientation () { - checkLayout(); - return orientation; -} - -/** - * Returns the previous offset for the specified offset and movement - * type. The movement is one of <code>SWT.MOVEMENT_CHAR</code>, - * <code>SWT.MOVEMENT_CLUSTER</code> or <code>SWT.MOVEMENT_WORD</code>, - * <code>SWT.MOVEMENT_WORD_END</code> or <code>SWT.MOVEMENT_WORD_START</code>. - * - * @param offset the start offset - * @param movement the movement type - * @return the previous offset - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the offset is out of range</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #getNextOffset(int, int) - */ -public int getPreviousOffset (int offset, int movement) { - checkLayout(); - computeRuns(); - int length = text.length(); - if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE); - if (offset == 0) return 0; - if ((movement & (SWT.MOVEMENT_CHAR | SWT.MOVEMENT_CLUSTER)) != 0) return offset - 1; - int lineStart = 0; - for (int i=0; i<lineOffset.length-1; i++) { - int lineEnd = lineOffset[i+1]; - if (i == runs.length - 1) lineEnd++; - if (lineEnd > offset) { - lineStart = lineOffset[i]; - break; - } - } - offset--; - boolean previousSpaceChar = !Compatibility.isLetterOrDigit(text.charAt(offset)); - while (lineStart < offset) { - boolean spaceChar = !Compatibility.isLetterOrDigit(text.charAt(offset - 1)); - if (movement == SWT.MOVEMENT_WORD_END) { - if (!spaceChar && previousSpaceChar) break; - } - if (movement == SWT.MOVEMENT_WORD || movement == SWT.MOVEMENT_WORD_START) { - if (spaceChar && !previousSpaceChar) break; - } - offset--; - previousSpaceChar = spaceChar; - } - return offset; -} - -/** - * Gets the ranges of text that are associated with a <code>TextStyle</code>. - * - * @return the ranges, an array of offsets representing the start and end of each - * text style. - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #getStyles() - * - * @since 3.2 - */ -public int[] getRanges () { - checkLayout(); - int[] result = new int[styles.length * 2]; - int count = 0; - for (int i=0; i<styles.length - 1; i++) { - if (styles[i].style != null) { - result[count++] = styles[i].start; - result[count++] = styles[i + 1].start - 1; - } - } - if (count != result.length) { - int[] newResult = new int[count]; - System.arraycopy(result, 0, newResult, 0, count); - result = newResult; - } - return result; -} - -/** - * Returns the text segments offsets of the receiver. - * - * @return the text segments offsets - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int[] getSegments() { - checkLayout(); - return segments; -} - -/** - * Returns the line spacing of the receiver. - * - * @return the line spacing - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int getSpacing () { - checkLayout(); - return lineSpacing; -} - -/** - * Gets the style of the receiver at the specified character offset. - * - * @param offset the text offset - * @return the style or <code>null</code> if not set - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the character offset is out of range</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public TextStyle getStyle (int offset) { - checkLayout(); - int length = text.length(); - if (!(0 <= offset && offset < length)) SWT.error(SWT.ERROR_INVALID_RANGE); - for (int i=1; i<styles.length; i++) { - StyleItem item = styles[i]; - if (item.start > offset) { - return styles[i - 1].style; - } - } - return null; -} - -/** - * Gets all styles of the receiver. - * - * @return the styles - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #getRanges() - * - * @since 3.2 - */ -public TextStyle[] getStyles () { - checkLayout(); - TextStyle[] result = new TextStyle[styles.length]; - int count = 0; - for (int i=0; i<styles.length; i++) { - if (styles[i].style != null) { - result[count++] = styles[i].style; - } - } - if (count != result.length) { - TextStyle[] newResult = new TextStyle[count]; - System.arraycopy(result, 0, newResult, 0, count); - result = newResult; - } - return result; -} - -/** - * Returns the tab list of the receiver. - * - * @return the tab list - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int[] getTabs () { - checkLayout(); - return tabs; -} - -/** - * Gets the receiver's text, which will be an empty - * string if it has never been set. - * - * @return the receiver's text - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public String getText () { - checkLayout(); - return text; -} - -/** - * Returns the width of the receiver. - * - * @return the width - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int getWidth () { - checkLayout(); - return wrapWidth; -} - -/** - * Returns <code>true</code> if the text layout has been disposed, - * and <code>false</code> otherwise. - * <p> - * This method gets the dispose state for the text layout. - * When a text layout has been disposed, it is an error to - * invoke any other method using the text layout. - * </p> - * - * @return <code>true</code> when the text layout is disposed and <code>false</code> otherwise - */ -public boolean isDisposed () { - return device == null; -} - -/* - * Itemize the receiver text, create run for - */ -StyleItem[] itemize () { - int length = text.length(); - if (length == 0) { - return new StyleItem[]{new StyleItem(), new StyleItem()}; - } - int runCount = 0, start = 0; - StyleItem[] runs = new StyleItem[length]; - char[] chars = text.toCharArray(); - for (int i = 0; i<length; i++) { - char ch = chars[i]; - if (ch == '\t' || ch == '\r' || ch == '\n') { - if (i != start) { - StyleItem item = new StyleItem(); - item.start = start; - runs[runCount++] = item; - } - StyleItem item = new StyleItem(); - item.start = i; - runs[runCount++] = item; - start = i + 1; - } - } - char lastChar = chars[length - 1]; - if (!(lastChar == '\t' || lastChar == '\r' || lastChar == '\n')) { - StyleItem item = new StyleItem(); - item.start = start; - runs[runCount++] = item; - } - if (runCount != length) { - StyleItem[] newRuns = new StyleItem[runCount]; - System.arraycopy(runs, 0, newRuns, 0, runCount); - runs = newRuns; - } - runs = merge(runs, runCount); - return runs; -} - -/* - * Merge styles ranges and script items - */ -StyleItem[] merge (StyleItem[] items, int itemCount) { - int length = text.length(); - int count = 0, start = 0, end = length, itemIndex = 0, styleIndex = 0; - StyleItem[] runs = new StyleItem[itemCount + styles.length]; - while (start < end) { - StyleItem item = new StyleItem(); - item.start = start; - item.style = styles[styleIndex].style; - runs[count++] = item; - int itemLimit = itemIndex + 1 < items.length ? items[itemIndex + 1].start : length; - int styleLimit = styleIndex + 1 < styles.length ? styles[styleIndex + 1].start : length; - if (styleLimit <= itemLimit) { - styleIndex++; - start = styleLimit; - } - if (itemLimit <= styleLimit) { - itemIndex++; - start = itemLimit; - } - item.length = start - item.start; - } - StyleItem item = new StyleItem(); - item.start = end; - runs[count++] = item; - if (runs.length != count) { - StyleItem[] result = new StyleItem[count]; - System.arraycopy(runs, 0, result, 0, count); - return result; - } - return runs; -} - -void place (StyleItem run) { - if (run.length == 0) return; - if (run.style != null && run.style.metrics != null) { - GlyphMetrics glyphMetrics = run.style.metrics; - run.width = glyphMetrics.width * run.length; - run.baseline = glyphMetrics.ascent; - run.height = glyphMetrics.ascent + glyphMetrics.descent; - } else { - char[] chars = new char[run.length]; - text.getChars(run.start, run.start + run.length, chars, 0); - Font font = getItemFont(run); - int fontList = font.handle; - byte[] buffer = Converter.wcsToMbcs(font.codePage, chars, true); - short[] width = new short[1], height = new short[1]; - int xmString = OS.XmStringCreateLocalized(buffer); - OS.XmStringExtent(fontList, xmString, width, height); - run.width = width[0] & 0xFFFF; - run.height = height[0] & 0xFFFF; - run.baseline = OS.XmStringBaseline(fontList, xmString); - OS.XmStringFree(xmString); - } -} - -/** - * Sets the text alignment for the receiver. The alignment controls - * how a line of text is positioned horizontally. The argument should - * be one of <code>SWT.LEFT</code>, <code>SWT.RIGHT</code> or <code>SWT.CENTER</code>. - * <p> - * The default alignment is <code>SWT.LEFT</code>. Note that the receiver's - * width must be set in order to use <code>SWT.RIGHT</code> or <code>SWT.CENTER</code> - * alignment. - * </p> - * - * @param alignment the new alignment - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #setWidth(int) - */ -public void setAlignment (int alignment) { - checkLayout(); - int mask = SWT.LEFT | SWT.CENTER | SWT.RIGHT; - alignment &= mask; - if (alignment == 0) return; - if ((alignment & SWT.LEFT) != 0) alignment = SWT.LEFT; - if ((alignment & SWT.RIGHT) != 0) alignment = SWT.RIGHT; - freeRuns(); - this.alignment = alignment; -} - -/** - * Sets the ascent of the receiver. The ascent is distance in pixels - * from the baseline to the top of the line and it is applied to all - * lines. The default value is <code>-1</code> which means that the - * ascent is calculated from the line fonts. - * - * @param ascent the new ascent - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the ascent is less than <code>-1</code></li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #setDescent(int) - * @see #getLineMetrics(int) - */ -public void setAscent (int ascent) { - checkLayout(); - if (ascent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (this.ascent == ascent) return; - freeRuns(); - this.ascent = ascent; -} - -/** - * Sets the descent of the receiver. The descent is distance in pixels - * from the baseline to the bottom of the line and it is applied to all - * lines. The default value is <code>-1</code> which means that the - * descent is calculated from the line fonts. - * - * @param descent the new descent - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the descent is less than <code>-1</code></li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #setAscent(int) - * @see #getLineMetrics(int) - */ -public void setDescent (int descent) { - checkLayout(); - if (descent < -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (this.descent == descent) return; - freeRuns(); - this.descent = descent; -} - -/** - * Sets the default font which will be used by the receiver - * to draw and measure text. If the - * argument is null, then a default font appropriate - * for the platform will be used instead. Note that a text - * style can override the default font. - * - * @param font the new font for the receiver, or null to indicate a default font - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setFont (Font font) { - checkLayout (); - if (font != null && font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - Font oldFont = this.font; - if (oldFont == font) return; - this.font = font; - if (oldFont != null && oldFont.equals(font)) return; - freeRuns(); - XFontStruct fontStruct = getFontHeigth(font != null ? font : device.systemFont); - defaultAscent = fontStruct.ascent; - defaultDescent = fontStruct.descent; -} - -/** - * Sets the indent of the receiver. This indent it applied of the first line of - * each paragraph. - * - * @param indent new indent - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.2 - */ -public void setIndent (int indent) { - checkLayout(); - if (indent < 0) return; - if (this.indent == indent) return; - freeRuns(); - this.indent = indent; -} - -/** - * Sets the justification of the receiver. Note that the receiver's - * width must be set in order to use justification. - * - * @param justify new justify - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.2 - */ -public void setJustify (boolean justify) { - checkLayout(); - if (this.justify == justify) return; - freeRuns(); - this.justify = justify; -} - -/** - * Sets the orientation of the receiver, which must be one - * of <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>. - * - * @param orientation new orientation style - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setOrientation (int orientation) { - checkLayout(); - int mask = SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT; - orientation &= mask; - if (orientation == 0) return; - if ((orientation & SWT.LEFT_TO_RIGHT) != 0) orientation = SWT.LEFT_TO_RIGHT; - this.orientation = orientation; -} - -/** - * Sets the line spacing of the receiver. The line spacing - * is the space left between lines. - * - * @param spacing the new line spacing - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the spacing is negative</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setSpacing (int spacing) { - checkLayout(); - if (spacing < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (this.lineSpacing == spacing) return; - freeRuns(); - this.lineSpacing = spacing; -} - -/** - * Sets the offsets of the receiver's text segments. Text segments are used to - * override the default behaviour of the bidirectional algorithm. - * Bidirectional reordering can happen within a text segment but not - * between two adjacent segments. - * <p> - * Each text segment is determined by two consecutive offsets in the - * <code>segments</code> arrays. The first element of the array should - * always be zero and the last one should always be equals to length of - * the text. - * </p> - * - * @param segments the text segments offset - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setSegments(int[] segments) { - checkLayout(); - if (this.segments == null && segments == null) return; - if (this.segments != null && segments !=null) { - if (this.segments.length == segments.length) { - int i; - for (i = 0; i <segments.length; i++) { - if (this.segments[i] != segments[i]) break; - } - if (i == segments.length) return; - } - } - freeRuns(); - this.segments = segments; -} - -/** - * Sets the style of the receiver for the specified range. Styles previously - * set for that range will be overwritten. The start and end offsets are - * inclusive and will be clamped if out of range. - * - * @param style the style - * @param start the start offset - * @param end the end offset - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setStyle (TextStyle style, int start, int end) { - checkLayout(); - int length = text.length(); - if (length == 0) return; - if (start > end) return; - start = Math.min(Math.max(0, start), length - 1); - end = Math.min(Math.max(0, end), length - 1); - int low = -1; - int high = styles.length; - while (high - low > 1) { - int index = (high + low) / 2; - if (styles[index + 1].start > start) { - high = index; - } else { - low = index; - } - } - if (0 <= high && high < styles.length) { - StyleItem item = styles[high]; - if (item.start == start && styles[high + 1].start - 1 == end) { - if (style == null) { - if (item.style == null) return; - } else { - if (style.equals(item.style)) return; - } - } - } - freeRuns(); - int modifyStart = high; - int modifyEnd = modifyStart; - while (modifyEnd < styles.length) { - if (styles[modifyEnd + 1].start > end) break; - modifyEnd++; - } - if (modifyStart == modifyEnd) { - int styleStart = styles[modifyStart].start; - int styleEnd = styles[modifyEnd + 1].start - 1; - if (styleStart == start && styleEnd == end) { - styles[modifyStart].style = style; - return; - } - if (styleStart != start && styleEnd != end) { - StyleItem[] newStyles = new StyleItem[styles.length + 2]; - System.arraycopy(styles, 0, newStyles, 0, modifyStart + 1); - StyleItem item = new StyleItem(); - item.start = start; - item.style = style; - newStyles[modifyStart + 1] = item; - item = new StyleItem(); - item.start = end + 1; - item.style = styles[modifyStart].style; - newStyles[modifyStart + 2] = item; - System.arraycopy(styles, modifyEnd + 1, newStyles, modifyEnd + 3, styles.length - modifyEnd - 1); - styles = newStyles; - return; - } - } - if (start == styles[modifyStart].start) modifyStart--; - if (end == styles[modifyEnd + 1].start - 1) modifyEnd++; - int newLength = styles.length + 1 - (modifyEnd - modifyStart - 1); - StyleItem[] newStyles = new StyleItem[newLength]; - System.arraycopy(styles, 0, newStyles, 0, modifyStart + 1); - StyleItem item = new StyleItem(); - item.start = start; - item.style = style; - newStyles[modifyStart + 1] = item; - styles[modifyEnd].start = end + 1; - System.arraycopy(styles, modifyEnd, newStyles, modifyStart + 2, styles.length - modifyEnd); - styles = newStyles; -} - -/** - * Sets the receiver's tab list. Each value in the tab list specifies - * the space in pixels from the origin of the text layout to the respective - * tab stop. The last tab stop width is repeated continuously. - * - * @param tabs the new tab list - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setTabs (int[] tabs) { - checkLayout(); - if (this.tabs == null && tabs == null) return; - if (this.tabs != null && tabs !=null) { - if (this.tabs.length == tabs.length) { - int i; - for (i = 0; i <tabs.length; i++) { - if (this.tabs[i] != tabs[i]) break; - } - if (i == tabs.length) return; - } - } - freeRuns(); - this.tabs = tabs; -} - -/** - * Sets the receiver's text. - *<p> - * Note: Setting the text also clears all the styles. This method - * returns without doing anything if the new text is the same as - * the current text. - * </p> - * - * @param text the new text - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the text is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setText (String text) { - checkLayout(); - if (text == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (text.equals(this.text)) return; - freeRuns(); - this.text = text; - styles = new StyleItem[2]; - styles[0] = new StyleItem(); - styles[1] = new StyleItem(); - styles[1].start = text.length(); -} - -/** - * Sets the line width of the receiver, which determines how - * text should be wrapped and aligned. The default value is - * <code>-1</code> which means wrapping is disabled. - * - * @param width the new width - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the width is <code>0</code> or less than <code>-1</code></li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #setAlignment(int) - */ -public void setWidth (int width) { - checkLayout(); - if (width < -1 || width == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (this.wrapWidth == width) return; - freeRuns(); - this.wrapWidth = width; -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the receiver - */ -public String toString () { - if (isDisposed()) return "TextLayout {*DISPOSED*}"; - return "TextLayout {}"; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java deleted file mode 100755 index 83b07b22ed..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java +++ /dev/null @@ -1,405 +0,0 @@ -/******************************************************************************* - * 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.internal; - - -import org.eclipse.swt.internal.motif.*; - -/** - * This class implements the conversions between unicode characters - * and the <em>platform supported</em> representation for characters. - * <p> - * Note that, unicode characters which can not be found in the platform - * encoding will be converted to an arbitrary platform specific character. - * </p> - */ - -public final class Converter { - - static final byte [] NULL_BYTE_ARRAY = new byte [1]; - static final byte [] EMPTY_BYTE_ARRAY = new byte [0]; - static final char [] EMPTY_CHAR_ARRAY = new char [0]; - - static String CodePage; - static final byte[] UCS2; - static final byte[] UTF8; - - static final Object LOCK = new Object (); - - /* Converter cache */ - static boolean LastMbcsToUCS2Failed, LastUCS2ToMbcsFailed; - static String LastMbcsToUCS2CodePage; - static String LastUCS2ToMbcsCodePage; - static int LastUCS2ToMbcs = -1; - static int LastUTF8ToMbcs = -1; - static int LastMbcsToUCS2 = -1; - static int LastMbcsToUTF8 = -1; - static int UTF8ToUCS2 = -1; - static int UCS2ToUTF8 = -1; - - /* Buffers cache */ - static int BufferSize; - static int MbcsBuffer, Ucs2Buffer, Utf8Buffer; - - static { - if (OS.IsHPUX) { - UCS2 = getAsciiBytes("ucs2"); - UTF8 = getAsciiBytes("utf8"); - } else { - UCS2 = getAsciiBytes("UCS-2"); - UTF8 = getAsciiBytes("UTF-8"); - } - - int length, item = OS.nl_langinfo (OS.CODESET); - if (item != 0 && (length = OS.strlen (item)) > 0) { - byte [] buffer = new byte [length]; - OS.memmove (buffer, item, length); - CodePage = new String (buffer); - if (OS.IsSunOS) { - if (length > 3 && CodePage.indexOf ("ISO") == 0) { - CodePage = CodePage.substring (3, length); - } - } - } else { - if (OS.IsLinux) CodePage = "ISO-8859-1"; - else if (OS.IsAIX) CodePage = "ISO8859-1"; - else if (OS.IsSunOS) CodePage = "8859-1"; - else if (OS.IsHPUX) CodePage = "iso88591"; - else CodePage = "iso8859_1"; - } - - /* - * The buffers can hold up to 512 unicode characters when converting - * from UCS-2 to any MBCS (including UTF-8). And they can hold - * at least 512 MBCS characters when converting from any MBCS to - * UCS-2. - */ - BufferSize = 512; - Ucs2Buffer = OS.XtMalloc (BufferSize * 2); - Utf8Buffer = OS.XtMalloc (BufferSize * 6); - MbcsBuffer = OS.XtMalloc (BufferSize * 6); - } - -/** - * Returns the default code page for the platform where the - * application is currently running. - * - * @return the default code page - */ -public static String defaultCodePage () { - return CodePage; -} - -static byte[] getAsciiBytes (String str) { - int length = str.length (); - byte [] buffer = new byte [length + 1]; - for (int i=0; i<length; i++) { - buffer [i] = (byte)str.charAt (i); - } - return buffer; -} - -static String getAsciiString (byte [] buffer) { - int length = buffer.length; - char [] chars = new char [length]; - for (int i=0; i<length; i++) { - chars [i] = (char)buffer [i]; - } - return new String (chars); -} - -/** - * Converts an array of bytes representing the platform's encoding, - * in the given code page, of some character data into an array of - * matching unicode characters. - * - * @param codePage the code page to use for conversion - * @param buffer the array of bytes to be converted - * @return the unicode conversion - */ -public static char [] mbcsToWcs (String codePage, byte [] buffer) { - - /* Check for the simple cases */ - if (buffer == null) { - return EMPTY_CHAR_ARRAY; - } - int length = buffer.length; - if (length == 0) { - return EMPTY_CHAR_ARRAY; - } - - /* - * Optimize for English ASCII encoding. If no conversion is - * performed, it is safe to return any object that will also not - * be converted if this routine is called again with the result. - * This ensures that double conversion will not be performed - * on the same bytes. Note that this relies on the fact that - * lead bytes are never in the range 0..0x7F. - */ - char [] wideCharStr = new char [length]; - for (int i=0; i<length; i++) { - if ((buffer [i] & 0xFF) <= 0x7F) { - wideCharStr [i] = (char) buffer [i]; // all bytes <= 0x7F, so no ((char) (buffer[i]&0xFF)) needed - } else { - synchronized (LOCK) { - /* - * Feature in Solaris. Some Solaris machines do not provide an iconv - * decoder/encoder that converts directly from/to any MBCS encoding to/from - * USC-2. The fix is to convert to UTF-8 enconding first and them - * convert to UCS-2. - */ - String cp = codePage != null ? codePage : CodePage; - if (cp != LastMbcsToUCS2CodePage && !cp.equals (LastMbcsToUCS2CodePage)) { - if (LastMbcsToUCS2 != -1) OS.iconv_close (LastMbcsToUCS2); - if (LastMbcsToUTF8 != -1) OS.iconv_close (LastMbcsToUTF8); - LastMbcsToUCS2 = LastMbcsToUTF8 = -1; - LastMbcsToUCS2CodePage = cp; - LastMbcsToUCS2Failed = false; - } - int cd = LastMbcsToUCS2; - if (cd == -1 && !LastMbcsToUCS2Failed) { - cd = LastMbcsToUCS2 = OS.iconv_open (UCS2, getAsciiBytes (cp)); - } - if (cd == -1) { - LastMbcsToUCS2Failed = true; - cd = UTF8ToUCS2; - if (cd == -1) cd = UTF8ToUCS2 = OS.iconv_open (UCS2, UTF8); - if (cd == -1) return EMPTY_CHAR_ARRAY; - cd = LastMbcsToUTF8; - if (cd == -1) cd = LastMbcsToUTF8 = OS.iconv_open (UTF8, getAsciiBytes (cp)); - } - if (cd == -1) return EMPTY_CHAR_ARRAY; - boolean utf8 = cd == LastMbcsToUTF8; - int inByteCount = length; - int outByteCount = utf8 ? length * 6 : length * 2; - int ptr1 = 0, ptr2 = 0, ptr3 = 0; - if (length <= BufferSize) { - ptr1 = MbcsBuffer; - ptr2 = Utf8Buffer; - ptr3 = Ucs2Buffer; - } else { - ptr1 = OS.XtMalloc (inByteCount); - if (utf8) ptr2 = OS.XtMalloc (length * 6); - ptr3 = OS.XtMalloc (length * 2); - } - int ptr = utf8 ? ptr2 : ptr3; - int [] inBuffer = {ptr1}; - int [] inBytesLeft = {inByteCount}; - int [] outBuffer = {ptr}; - int [] outBytesLeft = {outByteCount}; - OS.memmove (ptr1, buffer, inByteCount); - OS.iconv (cd, inBuffer, inBytesLeft, outBuffer, outBytesLeft); - outByteCount = outBuffer [0] - ptr; - if (utf8) { - cd = UTF8ToUCS2; - inByteCount = outByteCount; - outByteCount = length * 2; - inBuffer[0] = ptr2; - inBytesLeft[0] = inByteCount; - outBuffer[0] = ptr3; - outBytesLeft [0]= outByteCount; - OS.iconv (cd, inBuffer, inBytesLeft, outBuffer, outBytesLeft); - outByteCount = outBuffer [0] - ptr3; - } - wideCharStr = new char [outByteCount / 2]; - OS.memmove (wideCharStr, ptr3, outByteCount); - if (ptr1 != 0 && ptr1 != MbcsBuffer) OS.XtFree (ptr1); - if (ptr2 != 0 && ptr2 != Utf8Buffer) OS.XtFree (ptr2); - if (ptr3 != 0 && ptr3 != Ucs2Buffer) OS.XtFree (ptr3); - } - return wideCharStr; - } - } - return wideCharStr; -} - -/** - * Free any cached resources. - */ -public static void release () { - synchronized (LOCK) { - if (Ucs2Buffer != 0) OS.XtFree (Ucs2Buffer); - if (Utf8Buffer != 0) OS.XtFree (Utf8Buffer); - if (MbcsBuffer != 0) OS.XtFree (MbcsBuffer); - if (LastUCS2ToMbcs != -1) OS.iconv_close (LastUCS2ToMbcs); - if (LastUTF8ToMbcs != -1) OS.iconv_close (LastUTF8ToMbcs); - if (LastMbcsToUCS2 != -1) OS.iconv_close (LastMbcsToUCS2); - if (LastMbcsToUTF8 != -1) OS.iconv_close (LastMbcsToUTF8); - if (UTF8ToUCS2 != -1) OS.iconv_close (UTF8ToUCS2); - if (UCS2ToUTF8 != -1) OS.iconv_close (UCS2ToUTF8); - LastUCS2ToMbcs = LastUTF8ToMbcs = LastMbcsToUCS2 = LastMbcsToUTF8 = UTF8ToUCS2 = UCS2ToUTF8 -1; - Ucs2Buffer = Utf8Buffer = MbcsBuffer = 0; - } -} - -/** - * Converts an array of chars (containing unicode data) to an array - * of bytes representing the platform's encoding, of those characters - * in the given code page. - * - * @param codePage the code page to use for conversion - * @param buffer the array of chars to be converted - * @return the platform encoding - */ -public static byte [] wcsToMbcs (String codePage, char [] buffer) { - return wcsToMbcs (codePage, buffer, false); -} - -/** - * Converts an array of chars (containing unicode data) to an array - * of bytes representing the platform's encoding, of those characters - * in the given code page. If the termination flag is true, the resulting - * byte data will be null (zero) terminated. - * - * @param codePage the code page to use for conversion - * @param buffer the array of chars to be converted - * @param terminate <code>true</code> if the result should be null terminated and false otherwise. - * @return the platform encoding - */ -public static byte [] wcsToMbcs (String codePage, char [] buffer, boolean terminate) { - - /* Check for the simple cases */ - if (buffer == null) { - return (terminate) ? NULL_BYTE_ARRAY : EMPTY_BYTE_ARRAY; - } - int length = buffer.length; - if (length == 0) { - return (terminate) ? NULL_BYTE_ARRAY : EMPTY_BYTE_ARRAY; - } - - /* - * Optimize for English ASCII encoding. This optimization - * relies on the fact that lead bytes can never be in the - * range 0..0x7F. - */ - byte [] mbcs = new byte [(terminate) ? length + 1 : length]; - for (int i=0; i<length; i++) { - if ((buffer [i] & 0xFFFF) <= 0x7F) { - mbcs [i] = (byte) buffer [i]; - } else { - synchronized (LOCK) { - /* - * Feature in Solaris. Some Solaris machines do not provide an iconv - * decoder/encoder that converts directly from/to any MBCS encoding to/from - * USC-2. The fix is to convert to UTF-8 enconding first and them - * convert to UCS-2. - */ - String cp = codePage != null ? codePage : CodePage; - if (cp != LastUCS2ToMbcsCodePage && !cp.equals (LastUCS2ToMbcsCodePage)) { - if (LastUCS2ToMbcs != -1) OS.iconv_close (LastUCS2ToMbcs); - if (LastUTF8ToMbcs != -1) OS.iconv_close (LastUTF8ToMbcs); - LastUCS2ToMbcs = LastUTF8ToMbcs = -1; - LastUCS2ToMbcsCodePage = cp; - } - int cd = LastUCS2ToMbcs; - if (cd == -1 && !LastUCS2ToMbcsFailed) { - cd = LastUCS2ToMbcs = OS.iconv_open (getAsciiBytes (cp), UCS2); - } - if (cd == -1) { - LastUCS2ToMbcsFailed = true; - cd = LastUTF8ToMbcs; - if (cd == -1) cd = LastUTF8ToMbcs = OS.iconv_open (getAsciiBytes (cp), UTF8); - if (cd == -1) return (terminate) ? NULL_BYTE_ARRAY : EMPTY_BYTE_ARRAY; - cd = UCS2ToUTF8; - if (cd == -1) cd = UCS2ToUTF8 = OS.iconv_open (UTF8, UCS2); - } - if (cd == -1) return (terminate) ? NULL_BYTE_ARRAY : EMPTY_BYTE_ARRAY; - boolean utf8 = cd == UCS2ToUTF8; - int inByteCount = length * 2; - int outByteCount = length * 6; - int ptr1 = 0, ptr2 = 0, ptr3 = 0; - if (length <= BufferSize) { - ptr1 = Ucs2Buffer; - ptr2 = Utf8Buffer; - ptr3 = MbcsBuffer; - } else { - ptr1 = OS.XtMalloc (inByteCount); - if (utf8) ptr2 = OS.XtMalloc (outByteCount); - ptr3 = OS.XtMalloc (outByteCount); - } - int ptr = utf8 ? ptr2 : ptr3; - int [] inBuffer = {ptr1}; - int [] inBytesLeft = {inByteCount}; - int [] outBuffer = {ptr}; - int [] outBytesLeft = {outByteCount}; - OS.memmove (ptr1, buffer, inByteCount); - while (inBytesLeft [0] > 0) { - OS.iconv (cd, inBuffer, inBytesLeft, outBuffer, outBytesLeft); - if (inBytesLeft [0] != 0) { - inBuffer [0] += 2; - inBytesLeft [0] -= 2; - } - } - outByteCount = outBuffer [0] - ptr; - if (utf8) { - cd = LastUTF8ToMbcs; - inByteCount = outByteCount; - outByteCount = length * 6; - inBuffer[0] = ptr2; - inBytesLeft[0] = inByteCount; - outBuffer[0] = ptr3; - outBytesLeft [0]= outByteCount; - OS.iconv (cd, inBuffer, inBytesLeft, outBuffer, outBytesLeft); - outByteCount = outBuffer [0] - ptr3; - } - mbcs = new byte [terminate ? outByteCount + 1 : outByteCount]; - OS.memmove (mbcs, ptr3, outByteCount); - if (ptr1 != 0 && ptr1 != Ucs2Buffer) OS.XtFree (ptr1); - if (ptr2 != 0 && ptr2 != Utf8Buffer) OS.XtFree (ptr2); - if (ptr3 != 0 && ptr3 != MbcsBuffer) OS.XtFree (ptr3); - } - return mbcs; - } - } - return mbcs; -} - -/** - * Converts a String (containing unicode data) to an array - * of bytes representing the platform's encoding, of those characters - * in the given code page. - * - * @param codePage the code page to use for conversion - * @param string the string to be converted - * @return the platform encoding - */ -public static byte [] wcsToMbcs (String codePage, String string) { - return wcsToMbcs (codePage, string, false); -} - -/** - * Converts a String (containing unicode data) to an array - * of bytes representing the platform's encoding, of those characters - * in the given code page. If the termination flag is true, the resulting - * byte data will be null (zero) terminated. - * - * @param codePage the code page to use for conversion - * @param string the string to be converted - * @param terminate <code>true</code> if the result should be null terminated and false otherwise. - * @return the platform encoding - */ -public static byte [] wcsToMbcs (String codePage, String string, boolean terminate) { - if (terminate) { - if (string == null) return NULL_BYTE_ARRAY; - int count = string.length (); - char [] buffer = new char [count + 1]; - string.getChars (0, count, buffer, 0); - return wcsToMbcs (codePage, buffer, false); - } else { - if (string == null) return EMPTY_BYTE_ARRAY; - int count = string.length (); - char [] buffer = new char [count]; - string.getChars (0, count, buffer, 0); - return wcsToMbcs (codePage, buffer, false); - } -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java deleted file mode 100755 index 2c10e59b0b..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java +++ /dev/null @@ -1,859 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class represent a selectable user interface object that - * issues notification when pressed and released. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>ARROW, CHECK, PUSH, RADIO, TOGGLE, FLAT</dd> - * <dd>UP, DOWN, LEFT, RIGHT, CENTER</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection</dd> - * </dl> - * <p> - * Note: Only one of the styles ARROW, CHECK, PUSH, RADIO, and TOGGLE - * may be specified. - * </p><p> - * Note: Only one of the styles LEFT, RIGHT, and CENTER may be specified. - * </p><p> - * Note: Only one of the styles UP, DOWN, LEFT, and RIGHT may be specified - * when the ARROW style is specified. - * </p><p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#button">Button snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class Button extends Control { - String text = ""; - Image image, bitmap, disabled; - boolean grayed; - static final byte [] ARM_AND_ACTIVATE; - static { - String name = "ArmAndActivate"; - int length = name.length(); - char [] unicode = new char [length]; - name.getChars (0, length, unicode, 0); - byte [] buffer = new byte [length + 1]; - for (int i = 0; i < length; i++) { - buffer[i] = (byte) unicode[i]; - } - ARM_AND_ACTIVATE = buffer; - } -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#ARROW - * @see SWT#CHECK - * @see SWT#PUSH - * @see SWT#RADIO - * @see SWT#TOGGLE - * @see SWT#FLAT - * @see SWT#UP - * @see SWT#DOWN - * @see SWT#LEFT - * @see SWT#RIGHT - * @see SWT#CENTER - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Button (Composite parent, int style) { - super (parent, checkStyle (style)); -} -void _setImage (Image image) { - int labelPixmap = OS.XmUNSPECIFIED_PIXMAP; - int labelInsensitivePixmap = OS.XmUNSPECIFIED_PIXMAP; - if (bitmap != null) bitmap.dispose (); - if (disabled != null) disabled.dispose (); - bitmap = disabled = null; - if (image != null) { - if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - switch (image.type) { - case SWT.BITMAP: - ImageData data; - if (image.mask == 0 && (data = image.getImageData ()).alpha == -1 && data.alphaData == null && data.transparentPixel == -1) { - labelPixmap = image.pixmap; - disabled = new Image (display, image, SWT.IMAGE_DISABLE); - labelInsensitivePixmap = disabled.pixmap; - break; - } - //FALL THROUGH - case SWT.ICON: - Rectangle rect = image.getBounds (); - bitmap = new Image (display, rect.width, rect.height); - GC gc = new GC (bitmap); - gc.setBackground (getBackground ()); - gc.fillRectangle (rect); - gc.drawImage (image, 0, 0); - gc.dispose (); - labelPixmap = bitmap.pixmap; - disabled = new Image (display, bitmap, SWT.IMAGE_DISABLE); - labelInsensitivePixmap = disabled.pixmap; - break; - default: - error (SWT.ERROR_NOT_IMPLEMENTED); - } - } - int [] argList = { - OS.XmNlabelType, image == null ? OS.XmSTRING : OS.XmPIXMAP, - OS.XmNlabelPixmap, labelPixmap, - OS.XmNlabelInsensitivePixmap, labelInsensitivePixmap, - }; - OS.XtSetValues (handle, argList, argList.length / 2); -} -void _setText (String string) { - char [] text = new char [string.length ()]; - string.getChars (0, text.length, text, 0); - int mnemonic = fixMnemonic (text); - byte [] buffer = Converter.wcsToMbcs (getCodePage (), text, true); - int xmString = OS.XmStringParseText ( - buffer, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - if (xmString == 0) error (SWT.ERROR_CANNOT_SET_TEXT); - if (mnemonic == 0) mnemonic = OS.XK_VoidSymbol; - int [] argList = { - OS.XmNlabelType, OS.XmSTRING, - OS.XmNlabelString, xmString, - OS.XmNmnemonic, mnemonic, - }; - OS.XtSetValues (handle, argList, argList.length / 2); - if (xmString != 0) OS.XmStringFree (xmString); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the control is selected by the user, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * <code>widgetSelected</code> is called when the control is selected by the user. - * <code>widgetDefaultSelected</code> is not called. - * </p> - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener(listener); - addListener(SWT.Selection,typedListener); - addListener(SWT.DefaultSelection,typedListener); -} -static int checkStyle (int style) { - style = checkBits (style, SWT.PUSH, SWT.ARROW, SWT.CHECK, SWT.RADIO, SWT.TOGGLE, 0); - if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) { - return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0); - } - if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { - return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0); - } - if ((style & SWT.ARROW) != 0) { - style |= SWT.NO_FOCUS; - return checkBits (style, SWT.UP, SWT.DOWN, SWT.LEFT, SWT.RIGHT, 0, 0); - } - return style; -} -void click () { - int event = OS.XtMalloc (XEvent.sizeof); - OS.XtCallActionProc (handle, ARM_AND_ACTIVATE, event, null, 0); - OS.XtFree (event); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - int border = getBorderWidth (); - int width = border * 2, height = border * 2; - if ((style & SWT.ARROW) != 0) { - width += display.scrolledMarginX; - height += display.scrolledMarginY; - if (wHint != SWT.DEFAULT) width = wHint + (border * 2); - if (hHint != SWT.DEFAULT) height = hHint + (border * 2); - return new Point (width, height); - } - XtWidgetGeometry result = new XtWidgetGeometry (); - result.request_mode = OS.CWWidth | OS.CWHeight; - int [] argList2 = {OS.XmNrecomputeSize, 1}; - OS.XtSetValues(handle, argList2, argList2.length / 2); - OS.XtQueryGeometry (handle, null, result); - int [] argList3 = {OS.XmNrecomputeSize, 0}; - OS.XtSetValues(handle, argList3, argList3.length / 2); - width += result.width; - height += result.height; - /* - * Feature in Motif. If a button's labelType is XmSTRING but it - * has no label set into it yet, recomputing the size will - * not take into account the height of the font, as we would - * like it to. Take care of this case. - */ - int [] argList = {OS.XmNlabelType, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (argList [1] == OS.XmSTRING) { - int [] argList1 = {OS.XmNlabelString, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int xmString = argList1 [1]; - if (xmString != 0) { - if (OS.XmStringEmpty (xmString)) { - int xmString2 = OS.XmStringCreateLocalized (new byte[]{' ', '\0'}); - if (xmString2 != 0) { - height += OS.XmStringHeight (font.handle, xmString2); - OS.XmStringFree(xmString2); - } - } - OS.XmStringFree (xmString); - } - } - if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) { - int [] argList4 = new int [] { - OS.XmNmarginLeft, 0, - OS.XmNmarginRight, 0, - OS.XmNmarginTop, 0, - OS.XmNmarginBottom, 0, - }; - OS.XtGetValues (handle, argList4, argList4.length / 2); - if (wHint != SWT.DEFAULT) width = wHint + argList4 [1] + argList4 [3] + (border * 2); - if (hHint != SWT.DEFAULT) height = hHint + argList4 [5] + argList4 [7] + (border * 2); - } - return new Point (width, height); -} -void createHandle (int index) { - if ((style & SWT.PUSH) == 0) state |= THEME_BACKGROUND; - int borderWidth = (style & SWT.BORDER) != 0 ? 1 : 0; - int parentHandle = parent.handle; - - /* ARROW button */ - if ((style & SWT.ARROW) != 0) { - int alignment = OS.XmARROW_UP; - if ((style & SWT.UP) != 0) alignment = OS.XmARROW_UP; - if ((style & SWT.DOWN) != 0) alignment = OS.XmARROW_DOWN; - if ((style & SWT.LEFT) != 0) alignment = OS.XmARROW_LEFT; - if ((style & SWT.RIGHT) != 0) alignment = OS.XmARROW_RIGHT; - int [] argList = { - OS.XmNtraversalOn, 0, - OS.XmNarrowDirection, alignment, - OS.XmNborderWidth, borderWidth, - OS.XmNancestorSensitive, 1, - }; - handle = OS.XmCreateArrowButton (parentHandle, null, argList, argList.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - if ((style & SWT.FLAT) != 0) { - int [] argList1 = {OS.XmNbottomShadowColor, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int [] argList2 = { - OS.XmNshadowThickness, 1, - OS.XmNtopShadowColor, argList1 [1], - }; - OS.XtSetValues (handle, argList2, argList2.length / 2); - } - return; - } - - /* Compute alignment */ - int alignment = OS.XmALIGNMENT_BEGINNING; - if ((style & SWT.CENTER) != 0) alignment = OS.XmALIGNMENT_CENTER; - if ((style & SWT.RIGHT) != 0) alignment = OS.XmALIGNMENT_END; - - /* TOGGLE button */ - if ((style & SWT.TOGGLE) != 0) { - /* - * Bug in Motif. When XmNindicatorOn is set to false, - * Motif doesn't reset the shadow thickness to give a - * push button look. The fix is to set the shadow - * thickness when ever this resource is changed. - */ - int thickness = display.buttonShadowThickness; - int [] argList = { - OS.XmNancestorSensitive, 1, - OS.XmNrecomputeSize, 0, - OS.XmNindicatorOn, 0, - OS.XmNshadowThickness, (style & SWT.FLAT) != 0 ? 1 : thickness, - OS.XmNalignment, alignment, - OS.XmNborderWidth, borderWidth, - }; - handle = OS.XmCreateToggleButton (parentHandle, null, argList, argList.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - if ((style & SWT.FLAT) != 0) { - int [] argList1 = {OS.XmNbottomShadowColor, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int [] argList2 = {OS.XmNtopShadowColor, argList1 [1]}; - OS.XtSetValues (handle, argList2, argList2.length / 2); - } - return; - } - - /* CHECK or RADIO button */ - if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { - /* - * Bug in Motif. For some reason, a toggle button - * with XmNindicatorType XmONE_OF_MANY must have this - * value set at creation or the highlight color will - * not be correct. The fix is to set these values - * on create. - */ - int indicatorType = OS.XmONE_OF_MANY; - if ((style & SWT.CHECK) != 0) indicatorType = OS.XmN_OF_MANY; - int [] argList = { - OS.XmNancestorSensitive, 1, - OS.XmNrecomputeSize, 0, - OS.XmNindicatorType, indicatorType, - OS.XmNalignment, alignment, - OS.XmNborderWidth, borderWidth, - }; - handle = OS.XmCreateToggleButton (parentHandle, null, argList, argList.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - return; - } - - /* PUSH button */ - int [] argList = { - OS.XmNancestorSensitive, 1, - OS.XmNrecomputeSize, 0, - OS.XmNalignment, alignment, - OS.XmNborderWidth, borderWidth, - /* - * This code is intentionally commented. On some - * platforms, the standard behavior is that push - * buttons are tab groups, traversed with the tab - * key. On Motif, push buttons are tab items, - * that are traversed with the arrow keys. This - * behavior is unspecifed so the line remains - * commented. - */ -// OS.XmNnavigationType, OS.XmTAB_GROUP, - }; - handle = OS.XmCreatePushButton (parentHandle, null, argList, argList.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - if ((style & SWT.FLAT) != 0) { - int [] argList1 = {OS.XmNbottomShadowColor, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int [] argList2 = { - OS.XmNshadowThickness, 1, - OS.XmNtopShadowColor, argList1 [1], - }; - OS.XtSetValues (handle, argList2, argList2.length / 2); - } -} -void createWidget (int index) { - super.createWidget (index); - if ((style & SWT.PUSH) == 0) return; - if (getShell ().parent == null) return; - int [] argList = new int [] {OS.XmNdefaultButtonShadowThickness, 1}; - OS.XtSetValues (handle, argList, argList.length / 2); -} -int defaultBackground () { - return display.buttonBackground; -} -Font defaultFont () { - return display.buttonFont; -} -int defaultForeground () { - return display.buttonForeground; -} -/** - * Returns a value which describes the position of the - * text or image in the receiver. The value will be one of - * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code> - * unless the receiver is an <code>ARROW</code> button, in - * which case, the alignment will indicate the direction of - * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>, - * <code>UP</code> or <code>DOWN</code>). - * - * @return the alignment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getAlignment () { - checkWidget(); - if ((style & SWT.ARROW) != 0) { - int [] argList = {OS.XmNarrowDirection, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int direction = argList [1]; - if (direction == OS.XmARROW_UP) return SWT.UP; - if (direction == OS.XmARROW_DOWN) return SWT.DOWN; - if (direction == OS.XmARROW_LEFT) return SWT.LEFT; - if (direction == OS.XmARROW_RIGHT) return SWT.RIGHT; - return SWT.UP; - } - int [] argList = {OS.XmNalignment, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int alignment = argList [1]; - if (alignment == OS.XmALIGNMENT_BEGINNING) return SWT.LEFT; - if (alignment == OS.XmALIGNMENT_CENTER) return SWT.CENTER; - if (alignment == OS.XmALIGNMENT_END)return SWT.RIGHT; - return SWT.CENTER; -} -boolean getDefault () { - if ((style & SWT.PUSH) == 0) return false; -// int [] argList = {OS.XmNshowAsDefault, 0}; -// OS.XtGetValues (handle, argList, argList.length / 2); -// return argList [1] != 0; - return this == menuShell ().defaultButton; -} -/** - * Returns <code>true</code> if the receiver is grayed, - * and false otherwise. When the widget does not have - * the <code>CHECK</code> style, return false. - * - * @return the grayed state of the checkbox - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.4 - */ -public boolean getGrayed () { - checkWidget(); - if ((style & SWT.CHECK) == 0) return false; - return grayed; -} -/** - * Returns the receiver's image if it has one, or null - * if it does not. - * - * @return the receiver's image - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Image getImage () { - checkWidget(); - return image; -} -String getNameText () { - return getText (); -} -/** - * Returns <code>true</code> if the receiver is selected, - * and false otherwise. - * <p> - * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, - * it is selected when it is checked. When it is of type <code>TOGGLE</code>, - * it is selected when it is pushed in. If the receiver is of any other type, - * this method returns false. - * - * @return the selection state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getSelection () { - checkWidget(); - if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false; - int [] argList = {OS.XmNset, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1] != OS.XmUNSET; -} -/** - * Returns the receiver's text, which will be an empty - * string if it has never been set or if the receiver is - * an <code>ARROW</code> button. - * - * @return the receiver's text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getText () { - checkWidget(); - if ((style & SWT.ARROW) != 0) return ""; - return text; -} -void hookEvents () { - super.hookEvents (); - int windowProc = display.windowProc; - if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) != 0) { - OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK); - } else { - OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK); - } - -} -boolean mnemonicHit (char key) { - if (!setFocus ()) return false; - click (); - return true; -} -boolean mnemonicMatch (char key) { - char mnemonic = findMnemonic (getText ()); - if (mnemonic == '\0') return false; - return Character.toUpperCase (key) == Character.toUpperCase (mnemonic); -} -void releaseWidget () { - super.releaseWidget (); - int [] argList = { - OS.XmNlabelPixmap, OS.XmUNSPECIFIED_PIXMAP, - OS.XmNlabelInsensitivePixmap, OS.XmUNSPECIFIED_PIXMAP, - }; - OS.XtSetValues (handle, argList, argList.length / 2); - if (bitmap != null) bitmap.dispose (); - if (disabled != null) disabled.dispose (); - image = bitmap = disabled = null; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is selected by the user. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.Selection, listener); - eventTable.unhook(SWT.DefaultSelection,listener); -} -void selectRadio () { - /* - * This code is intentionally commented. When two groups - * of radio buttons with the same parent are separated by - * another control, the correct behavior should be that - * the two groups act independently. This is consistent - * with radio tool and menu items. The commented code - * implements this behavior. - */ -// int index = 0; -// Control [] children = parent._getChildren (); -// while (index < children.length && children [index] != this) index++; -// int i = index - 1; -// while (i >= 0 && children [i].setRadioSelection (false)) --i; -// int j = index + 1; -// while (j < children.length && children [j].setRadioSelection (false)) j++; -// setSelection (true); - Control [] children = parent._getChildren (); - for (int i=0; i<children.length; i++) { - Control child = children [i]; - if (this != child) child.setRadioSelection (false); - } - setSelection (true); -} -/** - * Controls how text, images and arrows will be displayed - * in the receiver. The argument should be one of - * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code> - * unless the receiver is an <code>ARROW</code> button, in - * which case, the argument indicates the direction of - * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>, - * <code>UP</code> or <code>DOWN</code>). - * - * @param alignment the new alignment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setAlignment (int alignment) { - checkWidget(); - if ((style & SWT.ARROW) != 0) { - int [] argList = {OS.XmNarrowDirection, OS.XmARROW_UP}; - if ((alignment & SWT.UP) != 0) argList [1] = OS.XmARROW_UP; - if ((alignment & SWT.DOWN) != 0) argList [1] = OS.XmARROW_DOWN; - if ((alignment & SWT.LEFT) != 0) argList [1] = OS.XmARROW_LEFT; - if ((alignment & SWT.RIGHT) != 0) argList [1] = OS.XmARROW_RIGHT; - OS.XtSetValues (handle, argList, argList.length / 2); - return; - } - if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return; - int [] argList = {OS.XmNalignment, OS.XmALIGNMENT_BEGINNING}; - if ((alignment & SWT.CENTER) != 0) argList [1] = OS.XmALIGNMENT_CENTER; - if ((alignment & SWT.RIGHT) != 0) argList [1] = OS.XmALIGNMENT_END; - OS.XtSetValues (handle, argList, argList.length / 2); -} -void setBackgroundPixel (int pixel) { - super.setBackgroundPixel (pixel); - if ((style & SWT.FLAT) != 0) { - int [] argList1 = {OS.XmNbottomShadowColor, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int [] argList2 = {OS.XmNtopShadowColor, argList1 [1]}; - OS.XtSetValues (handle, argList2, argList2.length / 2); - } - int [] argList = {OS.XmNlabelType, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (argList [1] == OS.XmPIXMAP) _setImage (image); -} - -void setDefault (boolean value) { - if ((style & SWT.PUSH) == 0) return; - if (getShell ().parent == null) return; - int [] argList = {OS.XmNshowAsDefault, (value ? 1 : 0)}; - OS.XtSetValues (handle, argList, argList.length / 2); -} -public void setFont (Font font) { - checkWidget(); - - /* - * Bug in Motif. Setting the font in a button widget that does - * not have a non-empty string causes GP on UTF-8 locale. - * The fix is to set a non-empty string, change the font, - * and restore the empty string at the end. - */ - int [] argList1 = {OS.XmNlabelString, 0, OS.XmNlabelType, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - boolean fixString = OS.IsDBLocale && OS.XmStringEmpty (argList1 [1]); - if (fixString) { - byte[] buffer = Converter.wcsToMbcs (getCodePage (), "string", true); - int xmString = OS.XmStringCreateLocalized (buffer); - int [] argList2 = { - OS.XmNlabelType, OS.XmSTRING, - OS.XmNlabelString, xmString, - }; - OS.XtSetValues (handle, argList2, argList2.length / 2); - OS.XmStringFree (xmString); - } - super.setFont (font); - if (fixString) OS.XtSetValues (handle, argList1, argList1.length / 2); -} -/** - * Sets the grayed state of the receiver. This state change - * only applies if the control was created with the SWT.CHECK - * style. - * - * @param grayed the new grayed state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.4 - */ -public void setGrayed (boolean grayed) { - checkWidget(); - if ((style & SWT.CHECK) == 0) return; - this.grayed = grayed; -} -/** - * Sets the receiver's image to the argument, which may be - * <code>null</code> indicating that no image should be displayed. - * <p> - * Note that a Button can display an image and text simultaneously - * on Windows (starting with XP), GTK+ and OSX. On other platforms, - * a Button that has an image and text set into it will display the - * image or text that was set most recently. - * </p> - * @param image the image to display on the receiver (may be <code>null</code>) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setImage (Image image) { - checkWidget(); - if (image != null && image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - if ((style & SWT.ARROW) != 0) return; - this.image = image; - /* This code is intentionally commented*/ -// if (image == null || text.length () != 0) { -// _setText (text); -// return; -// } - _setImage (image); -} -boolean setRadioSelection (boolean value) { - if ((style & SWT.RADIO) == 0) return false; - if (getSelection () != value) { - setSelection (value); - postEvent (SWT.Selection); - } - return true; -} -/** - * Sets the selection state of the receiver, if it is of type <code>CHECK</code>, - * <code>RADIO</code>, or <code>TOGGLE</code>. - * - * <p> - * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, - * it is selected when it is checked. When it is of type <code>TOGGLE</code>, - * it is selected when it is pushed in. - * - * @param selected the new selection state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (boolean selected) { - checkWidget(); - if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return; - int [] argList = {OS.XmNset, selected ? OS.XmSET : OS.XmUNSET}; - OS.XtSetValues (handle, argList, argList.length / 2); - updateShadows (); -} -/** - * Sets the receiver's text. - * <p> - * This method sets the button label. The label may include - * the mnemonic character but must not contain line delimiters. - * </p> - * <p> - * Mnemonics are indicated by an '&' that causes the next - * character to be the mnemonic. When the user presses a - * key sequence that matches the mnemonic, a selection - * event occurs. On most platforms, the mnemonic appears - * underlined but may be emphasized in a platform specific - * manner. The mnemonic indicator character '&' can be - * escaped by doubling it in the string, causing a single - * '&' to be displayed. - * </p><p> - * Note that a Button can display an image and text simultaneously - * on Windows (starting with XP), GTK+ and OSX. On other platforms, - * a Button that has an image and text set into it will display the - * image or text that was set most recently. - * </p> - * @param string the new text - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the text is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if ((style & SWT.ARROW) != 0) return; - /* - * Feature in Motif. Motif does not optimize the case - * when the same text is set into a button causing - * it to flash. The fix is to test for equality and - * do nothing. - */ - if (text.equals (string)) return; - text = string; - /* This code is intentionally commented*/ -// if (text.length () == 0 && image != null) { -// _setImage (image); -// return; -// } - _setText (string); -} -int traversalCode (int key, XKeyEvent xEvent) { - return super.traversalCode (key, xEvent) | SWT.TRAVERSE_MNEMONIC; -} -void updateShadows () { - if ((style & SWT.FLAT) != 0 && (style & SWT.TOGGLE) != 0) { - int [] argList1 = {OS.XmNset, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int pixel = argList1 [1] == OS.XmUNSET ? display.compositeBottomShadow : display.compositeTopShadow; - int [] argList2 = {OS.XmNtopShadowColor, pixel}; - OS.XtSetValues (handle, argList2, argList2.length / 2); - } -} -int xFocusIn (XFocusChangeEvent xEvent) { - super.xFocusIn (xEvent); - // widget could be disposed at this point - if (handle == 0) return 0; - if ((style & SWT.PUSH) != 0) { - menuShell ().setDefaultButton (this, false); - } - return 0; -} -int xFocusOut (XFocusChangeEvent xEvent) { - super.xFocusOut (xEvent); - // widget could be disposed at this point - if (handle == 0) return 0; - if ((style & SWT.PUSH) != 0 && getDefault ()) { - menuShell ().setDefaultButton (null, false); - } - return 0; -} -int XmNactivateCallback (int w, int client_data, int call_data) { - postEvent (SWT.Selection); - return 0; -} -int XmNvalueChangedCallback (int w, int client_data, int call_data) { - if ((style & SWT.RADIO) != 0) { - if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) { - selectRadio (); - } - } - updateShadows (); - postEvent (SWT.Selection); - return 0; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java deleted file mode 100755 index 439c284228..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java +++ /dev/null @@ -1,329 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2008 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.widgets; - - -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class provide a surface for drawing - * arbitrary graphics. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * This class may be subclassed by custom control implementors - * who are building controls that are <em>not</em> constructed - * from aggregates of other controls. That is, they are either - * painted using SWT graphics calls or are handled by native - * methods. - * </p> - * - * @see Composite - * @see <a href="http://www.eclipse.org/swt/snippets/#canvas">Canvas snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public class Canvas extends Composite { - Caret caret; - IME ime; - -Canvas () { - /* Do nothing */ -} -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * </ul> - * - * @see SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Canvas (Composite parent, int style) { - super (parent, checkStyle (style)); -} -/** - * Fills the interior of the rectangle specified by the arguments, - * with the receiver's background. - * - * @param gc the gc where the rectangle is to be filled - * @param x the x coordinate of the rectangle to be filled - * @param y the y coordinate of the rectangle to be filled - * @param width the width of the rectangle to be filled - * @param height the height of the rectangle to be filled - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the gc is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.2 - */ -public void drawBackground (GC gc, int x, int y, int width, int height) { - checkWidget (); - if (gc == null) error (SWT.ERROR_NULL_ARGUMENT); - if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - super.drawBackground (gc, x, y, width, height); -} -/** - * Returns the caret. - * <p> - * The caret for the control is automatically hidden - * and shown when the control is painted or resized, - * when focus is gained or lost and when an the control - * is scrolled. To avoid drawing on top of the caret, - * the programmer must hide and show the caret when - * drawing in the window any other time. - * </p> - * - * @return the caret for the receiver, may be null - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Caret getCaret () { - checkWidget(); - return caret; -} -/** - * Returns the IME. - * - * @return the IME - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.4 - */ -public IME getIME () { - checkWidget (); - return ime; -} -Caret getIMCaret () { - return caret; -} -void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean allChildren, boolean trim) { - boolean isFocus = caret != null && caret.isFocusCaret (); - if (isFocus) caret.killFocus (); - super.redrawWidget (x, y, width, height, redrawAll, allChildren, trim); - if (isFocus) caret.setFocus (); -} - -void releaseChildren (boolean destroy) { - if (caret != null) { - caret.release (false); - caret = null; - } - if (ime != null) { - ime.release (false); - ime = null; - } - super.releaseChildren (destroy); -} - -/** - * Scrolls a rectangular area of the receiver by first copying - * the source area to the destination and then causing the area - * of the source which is not covered by the destination to - * be repainted. Children that intersect the rectangle are - * optionally moved during the operation. In addition, outstanding - * paint events are flushed before the source area is copied to - * ensure that the contents of the canvas are drawn correctly. - * - * @param destX the x coordinate of the destination - * @param destY the y coordinate of the destination - * @param x the x coordinate of the source - * @param y the y coordinate of the source - * @param width the width of the area - * @param height the height of the area - * @param all <code>true</code>if children should be scrolled, and <code>false</code> otherwise - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) { - checkWidget(); - if (width <= 0 || height <= 0) return; - int deltaX = destX - x, deltaY = destY - y; - if (deltaX == 0 && deltaY == 0) return; - if (!isVisible ()) return; - boolean isFocus = caret != null && caret.isFocusCaret (); - if (isFocus) caret.killFocus (); - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int xWindow = OS.XtWindow (handle); - if (xWindow == 0) return; - int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (Math.min(x + width, argList [1]) >= Math.max (x, 0) && Math.min(y + height, 0 + argList [3]) >= Math.max (y, 0)) { - int xEvent = OS.XtMalloc (XEvent.sizeof); - OS.XSync (xDisplay, false); - OS.XSync (xDisplay, false); - while (OS.XCheckWindowEvent (xDisplay, xWindow, OS.ExposureMask, xEvent)) { - OS.XtDispatchEvent (xEvent); - } - OS.XtFree (xEvent); - } - Control control = findBackgroundControl (); - if (control == null) control = this; - if (control.backgroundImage != null) { - redrawWidget (x, y, width, height, false, false, false); - redrawWidget (destX, destY, width, height, false, false, false); - } else { - int xGC = OS.XCreateGC (xDisplay, xWindow, 0, null); - OS.XCopyArea (xDisplay, xWindow, xWindow, xGC, x, y, width, height, destX, destY); - OS.XFreeGC (xDisplay, xGC); - boolean disjoint = (destX + width < x) || (x + width < destX) || (destY + height < y) || (y + height < destY); - if (disjoint) { - OS.XClearArea (xDisplay, xWindow, x, y, width, height, true); - } else { - if (deltaX != 0) { - int newX = destX - deltaX; - if (deltaX < 0) newX = destX + width; - OS.XClearArea (xDisplay, xWindow, newX, y, Math.abs (deltaX), height, true); - } - if (deltaY != 0) { - int newY = destY - deltaY; - if (deltaY < 0) newY = destY + height; - OS.XClearArea (xDisplay, xWindow, x, newY, width, Math.abs (deltaY), true); - } - } - } - if (all) { - Control [] children = _getChildren (); - for (int i=0; i<children.length; i++) { - Control child = children [i]; - Rectangle rect = child.getBounds (); - if (Math.min(x + width, rect.x + rect.width) >= Math.max (x, rect.x) && - Math.min(y + height, rect.y + rect.height) >= Math.max (y, rect.y)) { - child.setLocation (rect.x + deltaX, rect.y + deltaY); - } - } - } - if (isFocus) caret.setFocus (); -} -/** - * Sets the receiver's caret. - * <p> - * The caret for the control is automatically hidden - * and shown when the control is painted or resized, - * when focus is gained or lost and when an the control - * is scrolled. To avoid drawing on top of the caret, - * the programmer must hide and show the caret when - * drawing in the window any other time. - * </p> - * @param caret the new caret for the receiver, may be null - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the caret has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setCaret (Caret caret) { - checkWidget(); - Caret newCaret = caret; - Caret oldCaret = this.caret; - this.caret = newCaret; - if (hasFocus ()) { - if (oldCaret != null) oldCaret.killFocus (); - if (newCaret != null) { - if (newCaret.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - newCaret.setFocus (); - } - } -} -boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - boolean isFocus = caret != null && caret.isFocusCaret (); - if (isFocus) caret.killFocus (); - boolean changed = super.setBounds (x, y, width, height, move, resize); - if (isFocus) caret.setFocus (); - return changed; -} -public void setFont (Font font) { - checkWidget(); - if (caret != null) caret.setFont (font); - super.setFont (font); -} -/** - * Sets the receiver's IME. - * - * @param ime the new IME for the receiver, may be null - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the IME has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.4 - */ -public void setIME (IME ime) { - checkWidget (); - if (ime != null && ime.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - this.ime = ime; -} -int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) { - boolean isFocus = caret != null && caret.isFocusCaret (); - if (isFocus) caret.killFocus (); - int result = super.XExposure (w, client_data, call_data, continue_to_dispatch); - if (isFocus) caret.setFocus (); - return result; -} -int xFocusIn (XFocusChangeEvent xEvent) { - int result = super.xFocusIn (xEvent); - if (caret != null) caret.setFocus (); - return result; -} -int xFocusOut (XFocusChangeEvent xEvent) { - int result = super.xFocusOut (xEvent); - if (caret != null) caret.killFocus (); - return result; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java deleted file mode 100755 index f875f34b10..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java +++ /dev/null @@ -1,480 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class provide an i-beam that is typically used - * as the insertion point for text. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#caret">Caret snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Canvas tab</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class Caret extends Widget { - Canvas parent; - int x, y, width, height; - boolean isVisible, isShowing; - int blinkRate; - Image image; - Font font; -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Caret (Canvas parent, int style) { - super (parent, style); - this.parent = parent; - createWidget (0); -} -boolean blinkCaret () { - if (!isVisible) return true; - if (!isShowing) return showCaret (); - if (blinkRate == 0) return true; - return hideCaret (); -} -void createWidget (int index) { - super.createWidget (index); - blinkRate = display.getCaretBlinkTime (); - isVisible = true; - if (parent.getCaret () == null) { - parent.setCaret (this); - } -} -boolean drawCaret () { - if (parent == null) return false; - if (parent.isDisposed ()) return false; - int handle = parent.handle; - int window = OS.XtWindow (handle); - if (window == 0) return false; - int xDisplay = OS.XtDisplay (handle); - int gc = OS.XCreateGC (xDisplay, window, 0, null); - int color; - if (OS.IsSunOS) { - int foreground = parent.getForegroundPixel (); - Control control = parent.findBackgroundControl (); - if (control == null) control = parent; - int background = control.getBackgroundPixel (); - color = foreground ^ background; - } else { - int screenNum = OS.XDefaultScreen (xDisplay); - color = OS.XWhitePixel(xDisplay, screenNum); - } - OS.XSetForeground (xDisplay, gc, color); - OS.XSetFunction (xDisplay, gc, OS.GXxor); - if (image != null && !image.isDisposed() && image.mask == 0) { - int [] unused = new int [1]; int [] width = new int [1]; int [] height = new int [1]; - OS.XGetGeometry (xDisplay, image.pixmap, unused, unused, unused, width, height, unused, unused); - OS.XCopyArea(xDisplay, image.pixmap, window, gc, 0, 0, width[0], height[0], x, y); - } else { - int nWidth = width, nHeight = height; - if (nWidth <= 0) nWidth = 1; - OS.XFillRectangle (xDisplay, window, gc, x, y, nWidth, nHeight); - } - OS.XFreeGC (xDisplay, gc); - return true; -} -/** - * Returns a rectangle describing the receiver's size and location - * relative to its parent (or its display if its parent is null). - * - * @return the receiver's bounding rectangle - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Rectangle getBounds () { - checkWidget(); - if (image != null) { - Rectangle rect = image.getBounds (); - return new Rectangle (x, y, rect.width, rect.height); - } - return new Rectangle (x, y, width, height); -} -/** - * Returns the font that the receiver will use to paint textual information. - * - * @return the receiver's font - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Font getFont () { - checkWidget(); - if (font != null) return font; - return parent.getFont (); -} -/** - * Returns the image that the receiver will use to paint the caret. - * - * @return the receiver's image - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Image getImage () { - checkWidget(); - return image; -} -/** - * Returns a point describing the receiver's location relative - * to its parent (or its display if its parent is null). - * - * @return the receiver's location - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Point getLocation () { - checkWidget(); - return new Point (x, y); -} -/** - * Returns the receiver's parent, which must be a <code>Canvas</code>. - * - * @return the receiver's parent - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Canvas getParent () { - checkWidget(); - return parent; -} -/** - * Returns a point describing the receiver's size. - * - * @return the receiver's size - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Point getSize () { - checkWidget(); - if (image != null) { - Rectangle rect = image.getBounds (); - return new Point (rect.width, rect.height); - } - return new Point (width, height); -} -/** - * Returns <code>true</code> if the receiver is visible, and - * <code>false</code> otherwise. - * <p> - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, this method - * may still indicate that it is considered visible even though - * it may not actually be showing. - * </p> - * - * @return the receiver's visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getVisible () { - checkWidget(); - return isVisible; -} -boolean hideCaret () { - if (!isShowing) return true; - isShowing = false; - return drawCaret (); -} -/** - * Returns <code>true</code> if the receiver is visible and all - * of the receiver's ancestors are visible and <code>false</code> - * otherwise. - * - * @return the receiver's visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getVisible - */ -public boolean isVisible () { - checkWidget(); - return isVisible && parent.isVisible () && parent.hasFocus (); -} -boolean isFocusCaret () { - return this == display.currentCaret; -} -void killFocus () { - if (display.currentCaret != this) return; - display.setCurrentCaret (null); - if (isVisible) hideCaret (); -} -void releaseParent () { - super.releaseParent (); - if (this == parent.getCaret ()) parent.setCaret (null); -} -void releaseWidget () { - super.releaseWidget (); - if (display.currentCaret == this) { - hideCaret (); - display.setCurrentCaret (null); - } - parent = null; - image = null; -} -/** - * Sets the receiver's size and location to the rectangular - * area specified by the arguments. The <code>x</code> and - * <code>y</code> arguments are relative to the receiver's - * parent (or its display if its parent is null). - * - * @param x the new x coordinate for the receiver - * @param y the new y coordinate for the receiver - * @param width the new width for the receiver - * @param height the new height for the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setBounds (int x, int y, int width, int height) { - checkWidget(); - if (this.x == x && this.y == y && this.width == width && this.height == height) return; - boolean isFocus = isFocusCaret (); - if (isFocus && isVisible) hideCaret (); - this.x = x; this.y = y; - this.width = width; this.height = height; - if (isVisible) parent.updateIM (); - if (isFocus && isVisible) showCaret (); -} -/** - * Sets the receiver's size and location to the rectangular - * area specified by the argument. The <code>x</code> and - * <code>y</code> fields of the rectangle are relative to - * the receiver's parent (or its display if its parent is null). - * - * @param rect the new bounds for the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setBounds (Rectangle rect) { - checkWidget(); - if (rect == null) error (SWT.ERROR_NULL_ARGUMENT); - setBounds (rect.x, rect.y, rect.width, rect.height); -} -void setFocus () { - if (display.currentCaret == this) return; - display.setCurrentCaret (this); - if (isVisible) showCaret (); -} -/** - * Sets the font that the receiver will use to paint textual information - * to the font specified by the argument, or to the default font for that - * kind of control if the argument is null. - * - * @param font the new font (or null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setFont (Font font) { - checkWidget(); - if (font != null && font.isDisposed ()) { - error (SWT.ERROR_INVALID_ARGUMENT); - } - this.font = font; - if (isVisible) parent.updateIM (); -} -/** - * Sets the image that the receiver will use to paint the caret - * to the image specified by the argument, or to the default - * which is a filled rectangle if the argument is null - * - * @param image the new image (or null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setImage (Image image) { - checkWidget(); - if (image != null && image.isDisposed ()) { - error (SWT.ERROR_INVALID_ARGUMENT); - } - boolean isFocus = isFocusCaret (); - if (isFocus && isVisible) hideCaret (); - this.image = image; - if (isFocus && isVisible) showCaret (); -} -/** - * Sets the receiver's location to the point specified by - * the arguments which are relative to the receiver's - * parent (or its display if its parent is null). - * - * @param x the new x coordinate for the receiver - * @param y the new y coordinate for the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setLocation (int x, int y) { - checkWidget(); - setBounds (x, y, width, height); -} -/** - * Sets the receiver's location to the point specified by - * the argument which is relative to the receiver's - * parent (or its display if its parent is null). - * - * @param location the new location for the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setLocation (Point location) { - checkWidget(); - if (location == null) error (SWT.ERROR_NULL_ARGUMENT); - setLocation (location.x, location.y); -} -/** - * Sets the receiver's size to the point specified by the arguments. - * - * @param width the new width for the receiver - * @param height the new height for the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSize (int width, int height) { - checkWidget(); - setBounds (x, y, width, height); -} -/** - * Sets the receiver's size to the point specified by the argument. - * - * @param size the new extent for the receiver - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the point is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSize (Point size) { - checkWidget(); - if (size == null) error (SWT.ERROR_NULL_ARGUMENT); - setSize (size.x, size.y); -} -/** - * Marks the receiver as visible if the argument is <code>true</code>, - * and marks it invisible otherwise. - * <p> - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, marking - * it visible may not actually cause it to be displayed. - * </p> - * - * @param visible the new visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setVisible (boolean visible) { - checkWidget(); - if (visible == isVisible) return; - isVisible = visible; - if (!isFocusCaret ()) return; - if (isVisible) { - showCaret (); - } else { - hideCaret (); - } -} -boolean showCaret () { - if (isShowing) return true; - isShowing = true; - return drawCaret (); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java deleted file mode 100755 index 51be4bfc3f..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java +++ /dev/null @@ -1,466 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; - -/** - * Instances of this class allow the user to select a color - * from a predefined set of available colors. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class ColorDialog extends Dialog { - private static final int COLORSWATCH_SIZE_DEPTH4 = 40; - private static final int COLORSWATCH_SIZE_DEPTH8 = 15; - private static final int COLORSWATCH_SIZE_DEPTH16 = 10; - private static final int COLORSWATCH_BORDER = 1; // border between each color pad - - private Shell shell; // the dialog shell - private Canvas colorsCanvas; - private Label sampleLabel, selectionLabel; - private Canvas sampleCanvas, selectionCanvas; - private Button okButton, cancelButton; - private int colorChooserWidth, colorChooserHeight; - - private boolean okSelected; - private RGB rgb; - private int colorSwatchExtent; // the size of each color square - private Color colorGrid[][]; // the colors displayed in the dialog - -/** - * Constructs a new instance of this class given only its parent. - * - * @param parent a composite control which will be the parent of the new instance - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public ColorDialog(Shell parent) { - this (parent, SWT.APPLICATION_MODAL); -} -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public ColorDialog(Shell parent, int style) { - super (parent, checkStyle (parent, style)); - checkSubclass (); -} -void createChildren() { - Shell dialog = shell; - GridLayout layout = new GridLayout (2, false); - dialog.setLayout(layout); - - colorChooserWidth = colorSwatchExtent * colorGrid.length - 1; - colorChooserHeight = colorSwatchExtent * colorGrid[0].length - 1; - colorsCanvas = new Canvas(dialog, SWT.BORDER); - GridData data = new GridData (); - data.widthHint = colorChooserWidth; - data.heightHint = colorChooserHeight; - colorsCanvas.setLayoutData(data); - - Composite buttonsGroup = new Composite (dialog, SWT.NONE); - buttonsGroup.setLayout(new GridLayout()); - buttonsGroup.setLayoutData(new GridData(GridData.BEGINNING)); - createOkCancel(buttonsGroup); - - Composite bottomGroup = new Composite (dialog,SWT.NONE); - layout = new GridLayout(2, true); - layout.marginHeight = 0; - layout.marginWidth = 0; - bottomGroup.setLayout(layout); - bottomGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); - - createSampleGroup(bottomGroup); - createSelectionGroup(bottomGroup); -} -void createOkCancel(Composite parent) { - okButton = new Button(parent, SWT.PUSH); - okButton.setText(SWT.getMessage("SWT_OK")); - shell.setDefaultButton(okButton); - GridData data = new GridData(GridData.FILL_HORIZONTAL); - okButton.setLayoutData(data); - - cancelButton = new Button(parent, SWT.PUSH); - cancelButton.setText(SWT.getMessage("SWT_Cancel")); - data = new GridData(GridData.FILL_HORIZONTAL); - cancelButton.setLayoutData(data); -} -void createSampleGroup(Composite parent) { - Group sampleGroup = new Group(parent, SWT.NULL); - GridData data = new GridData(GridData.FILL_BOTH); - data.grabExcessHorizontalSpace = true; - sampleGroup.setLayout(new GridLayout()); - sampleGroup.setLayoutData(data); - sampleGroup.setText(SWT.getMessage("SWT_Sample")); - - sampleLabel = new Label(sampleGroup, SWT.CENTER | SWT.BORDER); - sampleLabel.setAlignment(SWT.CENTER); - sampleLabel.setText(SWT.getMessage("SWT_A_Sample_Text")); - data = new GridData(GridData.FILL_HORIZONTAL); - sampleLabel.setLayoutData(data); - - sampleCanvas = new Canvas(sampleGroup, SWT.BORDER); - data = new GridData(GridData.FILL_HORIZONTAL); - data.heightHint = 15; - sampleCanvas.setLayoutData(data); -} -void createSelectionGroup(Composite parent) { - Group selectionGroup = new Group(parent, SWT.NULL); - GridData data = new GridData(GridData.FILL_BOTH); - data.grabExcessHorizontalSpace = true; - selectionGroup.setLayout(new GridLayout()); - selectionGroup.setLayoutData(data); - selectionGroup.setText(SWT.getMessage("SWT_Selection")); - - selectionLabel = new Label(selectionGroup, SWT.CENTER | SWT.BORDER); - selectionLabel.setAlignment(SWT.CENTER); - selectionLabel.setText(SWT.getMessage("SWT_Current_Selection")); - data = new GridData(GridData.FILL_HORIZONTAL); - data.grabExcessHorizontalSpace = true; - selectionLabel.setLayoutData(data); - - selectionCanvas = new Canvas(selectionGroup, SWT.BORDER); - data = new GridData(GridData.FILL_HORIZONTAL); - data.grabExcessHorizontalSpace = true; - data.heightHint = 15; - selectionCanvas.setLayoutData(data); -} -void disposeColors() { - for (int row = 0; row < colorGrid.length; row++) { - for (int column = 0; column < colorGrid[row].length; column++) { - colorGrid[row][column].dispose(); - } - } -} -void drawColor(int xIndex, int yIndex, Color color, GC gc) { - int colorExtent = colorSwatchExtent - COLORSWATCH_BORDER; - gc.setBackground(color); - gc.fillRectangle( - xIndex * colorSwatchExtent, - yIndex * colorSwatchExtent, - colorExtent, colorExtent); -} -/** - * Returns the currently selected color in the receiver. - * - * @return the RGB value for the selected color, may be null - * - * @see PaletteData#getRGBs - */ -public RGB getRGB() { - return rgb; -} -void handleEvents(Event event) { - if (event.type == SWT.Paint) { - paint(event); - } - else - if (event.type == SWT.MouseDown) { - mouseDown(event); - } - else - if (event.type == SWT.MouseMove) { - mouseMove(event); - } - else - if (event.type == SWT.Selection) { - if (event.widget == okButton) { - okSelected = true; - shell.setVisible(false); - } - else - if (event.widget == cancelButton) { - okSelected = false; - shell.setVisible(false); - } - } -} -void initialize4BitColors() { - Display display = shell.display; - - colorGrid[0][0] = new Color(display, 0, 0, 0); - colorGrid[0][1] = new Color(display, 255, 255, 255); - colorGrid[1][0] = new Color(display, 128, 128, 128); - colorGrid[1][1] = new Color(display, 192, 192, 192); - - colorGrid[2][0] = new Color(display, 0, 0, 128); - colorGrid[2][1] = new Color(display, 0, 0, 255); - colorGrid[3][0] = new Color(display, 0, 128, 128); - colorGrid[3][1] = new Color(display, 0, 255, 255); - - colorGrid[4][0] = new Color(display, 0, 128, 0); - colorGrid[4][1] = new Color(display, 0, 255, 0); - colorGrid[5][0] = new Color(display, 128, 128, 0); - colorGrid[5][1] = new Color(display, 255, 255, 0); - - colorGrid[6][0] = new Color(display, 128, 0, 0); - colorGrid[6][1] = new Color(display, 255, 0, 0); - colorGrid[7][0] = new Color(display, 128, 0, 128); - colorGrid[7][1] = new Color(display, 255, 0, 255); -} -void initialize8BitColors() { - Display display = shell.display; - int numRows = colorGrid[0].length; - int iterationStep = 64; - int row = 0, column = 0; - int red, green, blue; - // run the loops from 0 to 256 inclusive since this is easiest for the step - // size, then adjust the 256 case to the proper 255 value when needed - for (red = 0; red <= 256; red += iterationStep) { - for (blue = 0; blue <= 256; blue += iterationStep) { - for (green = 0; green <= 256; green += iterationStep) { - if (row == numRows) { - row = 0; - column++; - } - if (red == 256) red = 255; - if (blue == 256) blue = 255; - if (green == 256) green = 255; - colorGrid[column][row++] = new Color(display, red, green, blue); - } - } - } -} -void initialize16BitColors() { - Display display = shell.display; - int numRows = colorGrid[0].length; - int iterationStep = 51; - int row = 0, column = 0; - int red, green, blue; - - for (red = 0; red <= 255; red += iterationStep) { - for (blue = 0; blue <= 255; blue += iterationStep) { - if (blue == iterationStep && column < 20) { // evenly distribute 256 colors on 32 columns - blue += iterationStep; - } - for (green = 0; green <= 255; green += iterationStep) { - if (row == 2 || row == 5) { // evenly distribute 256 colors on 8 rows - colorGrid[column][row++] = new Color(display, red, green - iterationStep / 2, blue); - } - if (row == numRows) { - row = 0; - column++; - } - colorGrid[column][row++] = new Color(display, red, green, blue); - } - } - } -} -void initializeWidgets() { - Display display = shell.display; - if (rgb != null) { - Color selectionColor = new Color(display, rgb); - selectionCanvas.setBackground(selectionColor); - selectionLabel.setBackground(selectionColor); - selectionColor.dispose(); - } -} -void installListeners() { - Listener listener = new Listener() { - public void handleEvent(Event event) {handleEvents(event);} - }; - okButton.addListener(SWT.Selection, listener); - cancelButton.addListener(SWT.Selection, listener); - colorsCanvas.addListener(SWT.Paint, listener); - colorsCanvas.addListener(SWT.MouseDown, listener); - colorsCanvas.addListener(SWT.MouseMove, listener); -} -void mouseDown(Event event) { - int swatchExtent = colorSwatchExtent; - Color color = colorGrid[event.x / swatchExtent][event.y / swatchExtent]; - selectionCanvas.setBackground(color); - selectionLabel.setBackground(color); -} -void mouseMove(Event event) { - int swatchExtent = colorSwatchExtent; - // adjust for events received from moving over the Canvas' border - if (!(0 <= event.x && event.x <= colorChooserWidth)) return; - if (!(0 <= event.y && event.y <= colorChooserHeight)) return; - int xgrid = Math.min(colorGrid.length - 1, event.x / swatchExtent); - int ygrid = Math.min(colorGrid[0].length - 1, event.y / swatchExtent); - Color color = colorGrid[xgrid][ygrid]; - sampleCanvas.setBackground(color); - sampleLabel.setBackground(color); -} -/** - * Makes the receiver visible and brings it to the front - * of the display. - * - * @return the selected color, or null if the dialog was - * cancelled, no color was selected, or an error - * occurred - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public RGB open() { - shell = new Shell(parent, getStyle() | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL); - Display display = shell.display; - setColorDepth(display.getDepth()); - createChildren(); - installListeners(); - openModal(); - if (okSelected) { - Color selectionColor = selectionCanvas.getBackground(); - rgb = new RGB( - selectionColor.getRed(), - selectionColor.getGreen(), - selectionColor.getBlue()); - } - disposeColors(); - if (shell.isDisposed() == false) { - shell.dispose(); - } - if (!okSelected) return null; - return rgb; -} -/** - * Open the receiver and set its size to the size calculated by - * the layout manager. - */ -void openDialog() { - Shell dialog = shell; - - // Start everything off by setting the shell size to its computed size. - Point pt = dialog.computeSize(-1, -1, false); - - // Ensure that the width of the shell fits the display. - Display display = dialog.display; - Rectangle displayRect = display.getBounds(); - int widthLimit = displayRect.width * 7 / 8; - int heightLimit = displayRect.height * 7 / 8; - if (pt.x > widthLimit) { - pt = dialog.computeSize (widthLimit, -1, false); - } - - /* - * If the parent is visible then center this dialog on it, - * otherwise center this dialog on the parent's monitor - */ - Rectangle parentBounds = null; - if (parent.isVisible ()) { - parentBounds = getParent ().getBounds (); - } else { - parentBounds = parent.getMonitor ().getBounds (); - } - int originX = (parentBounds.width - pt.x) / 2 + parentBounds.x; - originX = Math.max (originX, 0); - originX = Math.min (originX, widthLimit - pt.x); - int originY = (parentBounds.height - pt.y) / 2 + parentBounds.y; - originY = Math.max (originY, 0); - originY = Math.min (originY, heightLimit - pt.y); - dialog.setBounds (originX, originY, pt.x, pt.y); - - String title = getText (); - if (title.length () == 0) title = SWT.getMessage ("SWT_ColorDialog_Title"); - shell.setText(title); - - dialog.open(); -} -void openModal() { - Display display = shell.display; - initializeWidgets(); - openDialog(); - while (shell.isDisposed() == false && shell.getVisible() == true) { - if (display.readAndDispatch() == false) { - display.sleep(); - } - } -} -void paint(Event event) { - for (int column = 0; column < colorGrid.length; column++) { - for (int row = 0; row < colorGrid[0].length; row++) { - drawColor(column, row, colorGrid[column][row], event.gc); - } - } -} -void setColorDepth(int bits) { - if (bits == 4) { - colorSwatchExtent = COLORSWATCH_SIZE_DEPTH4; - colorGrid = new Color[8][2]; - initialize4BitColors(); - return; - } - if (bits == 8) { - colorSwatchExtent = COLORSWATCH_SIZE_DEPTH8; - colorGrid = new Color[25][5]; - initialize8BitColors(); - return; - } - // default case: 16, 24 or 32 bits - colorSwatchExtent = COLORSWATCH_SIZE_DEPTH16; - colorGrid = new Color[32][8]; - initialize16BitColors(); -} -/** - * Sets the receiver's selected color to be the argument. - * - * @param rgb the new RGB value for the selected color, may be - * null to let the platform select a default when - * open() is called - * @see PaletteData#getRGBs - */ -public void setRGB(RGB rgb) { - this.rgb = rgb; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java deleted file mode 100755 index 8ad4709e7a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java +++ /dev/null @@ -1,1726 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class are controls that allow the user - * to choose an item from a list of items, or optionally - * enter a new value by typing it into an editable text - * field. Often, <code>Combo</code>s are used in the same place - * where a single selection <code>List</code> widget could - * be used but space is limited. A <code>Combo</code> takes - * less space than a <code>List</code> widget and shows - * similar information. - * <p> - * Note: Since <code>Combo</code>s can contain both a list - * and an editable text field, it is possible to confuse methods - * which access one versus the other (compare for example, - * <code>clearSelection()</code> and <code>deselectAll()</code>). - * The API documentation is careful to indicate either "the - * receiver's list" or the "the receiver's text field" to - * distinguish between the two cases. - * </p><p> - * Note that although this class is a subclass of <code>Composite</code>, - * it does not make sense to add children to it, or set a layout on it. - * </p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>DROP_DOWN, READ_ONLY, SIMPLE</dd> - * <dt><b>Events:</b></dt> - * <dd>DefaultSelection, Modify, Selection, Verify</dd> - * </dl> - * <p> - * Note: Only one of the styles DROP_DOWN and SIMPLE may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see List - * @see <a href="http://www.eclipse.org/swt/snippets/#combo">Combo snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class Combo extends Composite { - int visibleCount = 5; - - /** - * the operating system limit for the number of characters - * that the text field in an instance of this class can hold - */ - public static final int LIMIT; - - /* - * These values can be different on different platforms. - * Therefore they are not initialized in the declaration - * to stop the compiler from inlining. - */ - static { - LIMIT = 0x7FFFFFFF; - } - - boolean ignoreSelect; -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#DROP_DOWN - * @see SWT#READ_ONLY - * @see SWT#SIMPLE - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Combo (Composite parent, int style) { - super (parent, checkStyle (style)); -} -/** - * Adds the argument to the end of the receiver's list. - * - * @param string the new item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #add(String,int) - */ -public void add (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - - byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true); - int xmString = OS.XmStringCreateLocalized (buffer); - if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED); - OS.XmComboBoxAddItem(handle, xmString, -1, false); - OS.XmStringFree (xmString); -} -/** - * Adds the argument to the receiver's list at the given - * zero-relative index. - * <p> - * Note: To add an item at the end of the list, use the - * result of calling <code>getItemCount()</code> as the - * index or use <code>add(String)</code>. - * </p> - * - * @param string the new item - * @param index the index for the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #add(String) - */ -public void add (String string, int index) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if (index == -1) error (SWT.ERROR_INVALID_RANGE); - - /* - * Feature in Motif. When an index is out of range, - * the list widget adds the item at the end. This - * behavior is not wrong but it is unwanted. The - * fix is to check the range before adding the item. - */ - int [] argList = {OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (!(0 <= index && index <= argList [1])) { - error (SWT.ERROR_INVALID_RANGE); - } - byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true); - int xmString = OS.XmStringCreateLocalized (buffer); - if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED); - OS.XmComboBoxAddItem(handle, xmString, index + 1, false); - OS.XmStringFree (xmString); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's text is modified, by sending - * it one of the messages defined in the <code>ModifyListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ModifyListener - * @see #removeModifyListener - */ -public void addModifyListener (ModifyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Modify, typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the user changes the receiver's selection, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * <code>widgetSelected</code> is called when the user changes the combo's list selection. - * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed the combo's text area. - * </p> - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Selection,typedListener); - addListener (SWT.DefaultSelection,typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's text is verified, by sending - * it one of the messages defined in the <code>VerifyListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see VerifyListener - * @see #removeVerifyListener - * - * @since 3.1 - */ -public void addVerifyListener (VerifyListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Verify, typedListener); -} -static int checkStyle (int style) { - /* - * Feature in Windows. It is not possible to create - * a combo box that has a border using Windows style - * bits. All combo boxes draw their own border and - * do not use the standard Windows border styles. - * Therefore, no matter what style bits are specified, - * clear the BORDER bits so that the SWT style will - * match the Windows widget. - * - * The Windows behavior is currently implemented on - * all platforms. - */ - style &= ~SWT.BORDER; - - /* - * Even though it is legal to create this widget - * with scroll bars, they serve no useful purpose - * because they do not automatically scroll the - * widget's client area. The fix is to clear - * the SWT style. - */ - style &= ~(SWT.H_SCROLL | SWT.V_SCROLL); - style = checkBits (style, SWT.DROP_DOWN, SWT.SIMPLE, 0, 0, 0, 0); - if ((style & SWT.SIMPLE) != 0) return style & ~SWT.READ_ONLY; - return style; -} -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} -/** - * Sets the selection in the receiver's text field to an empty - * selection starting just before the first character. If the - * text field is editable, this has the effect of placing the - * i-beam at the start of the text. - * <p> - * Note: To clear the selected items in the receiver's list, - * use <code>deselectAll()</code>. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #deselectAll - */ -public void clearSelection () { - checkWidget(); - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - OS.XmTextClearSelection (argList[1], OS.XtLastTimestampProcessed (xDisplay)); -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - int [] argList = { - OS.XmNlist, 0, - OS.XmNtextField, 0, - OS.XmNitemCount, 0, - OS.XmNmarginWidth, 0, - OS.XmNshadowThickness, 0, - OS.XmNhighlightThickness, 0, - OS.XmNarrowSize, 0, - OS.XmNarrowSpacing, 0, - }; - OS.XtGetValues(handle, argList, argList.length / 2); - XtWidgetGeometry result = new XtWidgetGeometry (); - result.request_mode = OS.CWWidth; - OS.XtQueryGeometry (argList[1], null, result); - int width = result.width, height = getTextHeight(); - int[] argList2 = {OS.XmNmarginWidth, 0, OS.XmNshadowThickness, 0}; - OS.XtGetValues(argList[3], argList2, argList2.length / 2); - if ((style & SWT.READ_ONLY) == 0) width += (2 * argList[7]); - if ((style & SWT.DROP_DOWN) != 0) { - width += argList[13] + argList[15]; - } else { - int itemCount = (argList[5] == 0) ? 5 : argList[5]; - height += (getItemHeight () * itemCount); - } - width += (2 * argList[9]) - + (2 * argList[11]) - + (2 * argList2[1]) - + (2 * argList2[3]); - if (argList[5] == 0) width = DEFAULT_WIDTH; - if (hHint != SWT.DEFAULT) height = hHint; - if (wHint != SWT.DEFAULT) width = wHint; - Rectangle rect = computeTrim (0, 0, width, height); - return new Point (rect.width, rect.height); -} -/** - * Copies the selected text. - * <p> - * The current selection is copied to the clipboard. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.1 - */ -public void copy () { - checkWidget(); - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - OS.XmTextCopy (argList [1], OS.XtLastTimestampProcessed (xDisplay)); -} -void createHandle (int index) { - /* - * Feature in Motif. When items are added or removed - * from a combo, it may request and be granted, a new - * preferred size. This behavior is unwanted. The fix - * is to create a parent for the list that will disallow - * geometry requests. - */ - int parentHandle = parent.handle; - int [] argList1 = {OS.XmNancestorSensitive, 1}; - formHandle = OS.XmCreateForm (parentHandle, null, argList1, argList1.length / 2); - if (formHandle == 0) error (SWT.ERROR_NO_HANDLES); - int comboBoxType = OS.XmDROP_DOWN_COMBO_BOX; - if ((style & SWT.SIMPLE) != 0) { - comboBoxType = OS.XmCOMBO_BOX; - } else if ((style & SWT.READ_ONLY) != 0) { - comboBoxType = OS.XmDROP_DOWN_LIST; - } - int [] argList2 = { - OS.XmNcomboBoxType, comboBoxType, - OS.XmNtopAttachment, OS.XmATTACH_FORM, - OS.XmNbottomAttachment, OS.XmATTACH_FORM, - OS.XmNleftAttachment, OS.XmATTACH_FORM, - OS.XmNrightAttachment, OS.XmATTACH_FORM, - OS.XmNresizable, 0, - }; - handle = OS.XmCreateComboBox (formHandle, null, argList2, argList2.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - int [] argList3 = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList3, argList3.length / 2); - int textHandle = argList3 [1]; - int [] argList4 = {OS.XmNverifyBell, 0}; - OS.XtSetValues (textHandle, argList4, argList4.length / 2); - /* - * Feature in Motif. The Combo widget is created with a default - * drop target. This is inconsistent with other platforms. - * To be consistent, disable the default drop target. - */ - OS.XmDropSiteUnregister (textHandle); -} -/** - * Cuts the selected text. - * <p> - * The current selection is first copied to the - * clipboard and then deleted from the widget. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.1 - */ -public void cut () { - checkWidget(); - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - OS.XmTextCut (argList [1], OS.XtLastTimestampProcessed (xDisplay)); -} -/** - * Deselects the item at the given zero-relative index in the receiver's - * list. If the item at the index was already deselected, it remains - * deselected. Indices that are out of range are ignored. - * - * @param index the index of the item to deselect - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void deselect (int index) { - checkWidget(); - if (index == -1) return; - int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - - if (OS.XmListPosSelected (argList[3], index + 1)) { - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XmTextSetString (argList[1], new byte[1]); - display.setWarnings (warnings); - OS.XmListDeselectAllItems (argList[3]); - } -} -/** - * Deselects all selected items in the receiver's list. - * <p> - * Note: To clear the selection in the receiver's text field, - * use <code>clearSelection()</code>. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #clearSelection - */ -public void deselectAll () { - checkWidget(); - int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XmTextSetString (argList[1], new byte[1]); - display.setWarnings(warnings); - OS.XmListDeselectAllItems (argList[3]); -} -/** - * Returns the item at the given, zero-relative index in the - * receiver's list. Throws an exception if the index is out - * of range. - * - * @param index the index of the item to return - * @return the item at the given index - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getItem (int index) { - checkWidget(); - int [] argList = {OS.XmNitemCount, 0, OS.XmNitems, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (!(0 <= index && index < argList [1])) { - error (SWT.ERROR_INVALID_RANGE); - } - if (argList [3] == 0) error (SWT.ERROR_CANNOT_GET_ITEM); - int ptr = argList [3] + (index * 4); - int [] buffer1 = new int [1]; - OS.memmove (buffer1, ptr, 4); - ptr = buffer1 [0]; - int [] table = new int [] {display.tabMapping, display.crMapping}; - int address = OS.XmStringUnparse ( - ptr, - null, - OS.XmCHARSET_TEXT, - OS.XmCHARSET_TEXT, - table, - table.length, - OS.XmOUTPUT_ALL); - if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM); - int length = OS.strlen (address); - byte [] buffer = new byte [length]; - OS.memmove (buffer, address, length); - OS.XtFree (address); - return decodeString(new String (Converter.mbcsToWcs (getCodePage (), buffer))); -} -/** - * Returns the number of items contained in the receiver's list. - * - * @return the number of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getItemCount () { - checkWidget(); - int [] argList = {OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the height of the area which would be used to - * display <em>one</em> of the items in the receiver's list. - * - * @return the height of one item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getItemHeight () { - checkWidget(); - int [] listHandleArgs = {OS.XmNlist, 0}; - OS.XtGetValues (handle, listHandleArgs, listHandleArgs.length / 2); - int [] argList = {OS.XmNlistSpacing, 0, OS.XmNhighlightThickness, 0, OS.XmNfontList, 0}; - OS.XtGetValues (listHandleArgs[1], argList, argList.length / 2); - int spacing = argList [1], highlight = argList [3], fontList = argList [5]; - /* Result is from empirical analysis on Linux and AIX */ - return getFontHeight (fontList) + spacing + (2 * highlight); -} -/** - * Returns a (possibly empty) array of <code>String</code>s which are - * the items in the receiver's list. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its list of items, so modifying the array will - * not affect the receiver. - * </p> - * - * @return the items in the receiver's list - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String [] getItems () { - checkWidget(); - int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int items = argList [1], itemCount = argList [3]; - int [] buffer1 = new int [1]; - String [] result = new String [itemCount]; - String codePage = getCodePage (); - for (int i = 0; i < itemCount; i++) { - OS.memmove (buffer1, items, 4); - int ptr = buffer1 [0]; - int [] table = new int [] {display.tabMapping, display.crMapping}; - int address = OS.XmStringUnparse ( - ptr, - null, - OS.XmCHARSET_TEXT, - OS.XmCHARSET_TEXT, - table, - table.length, - OS.XmOUTPUT_ALL); - if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM); - int length = OS.strlen (address); - byte [] buffer = new byte [length]; - OS.memmove (buffer, address, length); - OS.XtFree (address); - result[i] = decodeString(new String (Converter.mbcsToWcs (codePage, buffer))); - items += 4; - } - return result; -} -/** - * Returns <code>true</code> if the receiver's list is visible, - * and <code>false</code> otherwise. - * <p> - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, this method - * may still indicate that it is considered visible even though - * it may not actually be showing. - * </p> - * - * @return the receiver's list's visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.4 - */ -public boolean getListVisible () { - checkWidget (); - int[] argList1 = new int[] {OS.XmNlist, 0, OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int xtParent = OS.XtParent (argList1 [1]); - while (xtParent != 0 && !OS.XtIsSubclass (xtParent, OS.shellWidgetClass ())) { - xtParent = OS.XtParent (xtParent); - } - if (xtParent != 0) { - int xDisplay = OS.XtDisplay (xtParent); - if (xDisplay == 0) return false; - int xWindow = OS.XtWindow (xtParent); - if (xWindow == 0) return false; - XWindowAttributes attributes = new XWindowAttributes (); - OS.XGetWindowAttributes (xDisplay, xWindow, attributes); - return attributes.map_state == OS.IsViewable; - } - return false; -} -int getMinimumHeight () { - return getTextHeight (); -} -String getNameText () { - return getText (); -} -/** - * Returns the orientation of the receiver. - * - * @return the orientation style - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.1.2 - */ -public int getOrientation () { - checkWidget(); - return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT); -} -/** - * Returns a <code>Point</code> whose x coordinate is the - * character position representing the start of the selection - * in the receiver's text field, and whose y coordinate is the - * character position representing the end of the selection. - * An "empty" selection is indicated by the x and y coordinates - * having the same value. - * <p> - * Indexing is zero based. The range of a selection is from - * 0..N where N is the number of characters in the widget. - * </p> - * - * @return a point representing the selection start and end - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Point getSelection () { - checkWidget(); - int [] start = new int [1], end = new int [1]; - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - OS.XmTextGetSelectionPosition (argList[1], start, end); - if (start [0] == end [0]) { - start [0] = end [0] = OS.XmTextGetInsertionPosition (argList[1]); - } - return new Point (start [0], end [0]); -} -/** - * Returns the zero-relative index of the item which is currently - * selected in the receiver's list, or -1 if no item is selected. - * - * @return the index of the selected item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getSelectionIndex () { - checkWidget(); - int [] argList = {OS.XmNlist, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - - int index = OS.XmListGetKbdItemPos (argList[1]); - if (OS.XmListPosSelected (argList[1], index)) return index - 1; - int [] count = new int [1], positions = new int [1]; - if (!OS.XmListGetSelectedPos (argList[1], positions, count)) return -1; - if (count [0] == 0) return -1; - int address = positions [0]; - int [] indices = new int [1]; - OS.memmove (indices, address, 4); - OS.XtFree (address); - return indices [0] - 1; -} -/** - * Returns a string containing a copy of the contents of the - * receiver's text field, or an empty string if there are no - * contents. - * - * @return the receiver's text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getText () { - checkWidget(); - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - - int ptr = OS.XmTextGetString (argList[1]); - if (ptr == 0) return ""; - int length = OS.strlen (ptr); - byte [] buffer = new byte [length]; - OS.memmove (buffer, ptr, length); - OS.XtFree (ptr); - return decodeString(new String (Converter.mbcsToWcs (getCodePage (), buffer))); -} -/** - * Returns the height of the receivers's text field. - * - * @return the text height - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getTextHeight () { - checkWidget(); - if ((style & SWT.DROP_DOWN) != 0) { - /* - * Bug in MOTIF. For some reason, XtQueryGeometry () - * returns the wrong height when the combo is not realized. - * The fix is to force the combo to be realized by forcing - * the shell to be realized. - */ - if (!OS.XtIsRealized (handle)) getShell ().realizeWidget (); - XtWidgetGeometry result = new XtWidgetGeometry (); - result.request_mode = OS.CWHeight; - OS.XtQueryGeometry (handle, null, result); - return result.height; - } else { - /* Calculate text field height. */ - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int [] argList2 = {OS.XmNmarginHeight, 0}; - OS.XtGetValues (argList[1], argList2, argList2.length / 2); - int height = getFontHeight (font.handle); - XRectangle rect = new XRectangle (); - OS.XmWidgetGetDisplayRect (argList[1], rect); - height += (rect.y * 2) + (2 * argList2[1]); - - /* Add in combo box margins. */ - int [] argList3 = {OS.XmNmarginHeight, 0, OS.XmNshadowThickness, 0, OS.XmNhighlightThickness, 0}; - OS.XtGetValues(handle, argList3, argList3.length / 2); - height += (2 * argList3[1]) + (2 * argList3[3]) + (2 * argList3[5]); - - return height; - } -} -/** - * Returns the maximum number of characters that the receiver's - * text field is capable of holding. If this has not been changed - * by <code>setTextLimit()</code>, it will be the constant - * <code>Combo.LIMIT</code>. - * - * @return the text limit - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #LIMIT - */ -public int getTextLimit () { - checkWidget(); - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return OS.XmTextGetMaxLength (argList[1]); -} -/** - * Gets the number of items that are visible in the drop - * down portion of the receiver's list. - * <p> - * Note: This operation is a hint and is not supported on - * platforms that do not have this concept. - * </p> - * - * @return the number of items that are visible - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.0 - */ -public int getVisibleItemCount () { - checkWidget (); - if ((style & SWT.SIMPLE) != 0) return visibleCount; - int [] argList = new int [] {OS.XmNvisibleItemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -void hookEvents () { - super.hookEvents (); - int windowProc = display.windowProc; - int [] argList = {OS.XmNlist, 0, OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int listHandle = argList [1]; - int textHandle = argList [3]; - OS.XtAddCallback (listHandle, OS.XmNbrowseSelectionCallback, windowProc, BROWSE_SELECTION_CALLBACK); - OS.XtAddEventHandler (listHandle, OS.KeyPressMask, false, windowProc, KEY_PRESS); - OS.XtAddEventHandler (listHandle, OS.KeyReleaseMask, false, windowProc, KEY_RELEASE); - OS.XtAddCallback (textHandle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK); - OS.XtAddCallback (textHandle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK); - OS.XtAddCallback (textHandle, OS.XmNmodifyVerifyCallback, windowProc, MODIFY_VERIFY_CALLBACK); - OS.XtAddEventHandler (textHandle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS); - OS.XtAddEventHandler (textHandle, OS.ButtonReleaseMask, false, windowProc, BUTTON_RELEASE); - OS.XtAddEventHandler (textHandle, OS.EnterWindowMask, false, windowProc, ENTER_WINDOW); - OS.XtAddEventHandler (textHandle, OS.LeaveWindowMask, false, windowProc, LEAVE_WINDOW); - OS.XtAddEventHandler (textHandle, OS.KeyPressMask, false, windowProc, KEY_PRESS); - OS.XtAddEventHandler (textHandle, OS.KeyReleaseMask, false, windowProc, KEY_RELEASE); - OS.XtInsertEventHandler (textHandle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail); -} -/** - * Searches the receiver's list starting at the first item - * (index 0) until an item is found that is equal to the - * argument, and returns the index of that item. If no item - * is found, returns -1. - * - * @param string the search item - * @return the index of the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int indexOf (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - - byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true); - int xmString = OS.XmStringCreateLocalized (buffer); - if (xmString == 0) return -1; - - int [] argList = {OS.XmNlist, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - - int index = OS.XmListItemPos (argList[1], xmString); - OS.XmStringFree (xmString); - return index - 1; -} -/** - * Searches the receiver's list starting at the given, - * zero-relative index until an item is found that is equal - * to the argument, and returns the index of that item. If - * no item is found or the starting index is out of range, - * returns -1. - * - * @param string the search item - * @param start the zero-relative index at which to begin the search - * @return the index of the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int indexOf (String string, int start) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int items = argList [1], itemCount = argList [3]; - if (!((0 <= start) && (start < itemCount))) return -1; - byte [] buffer1 = Converter.wcsToMbcs (getCodePage (), encodeString(string), true); - int xmString = OS.XmStringCreateLocalized (buffer1); - if (xmString == 0) return -1; - int index = start; - items += start * 4; - int [] buffer2 = new int [1]; - while (index < itemCount) { - OS.memmove (buffer2, items, 4); - if (OS.XmStringCompare (buffer2 [0], xmString)) break; - items += 4; index++; - } - OS.XmStringFree (xmString); - if (index == itemCount) return -1; - return index; -} -/** - * Pastes text from clipboard. - * <p> - * The selected text is deleted from the widget - * and new text inserted from the clipboard. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.1 - */ -public void paste () { - checkWidget(); - boolean warnings = display.getWarnings (); - display.setWarnings (false); - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - OS.XmTextFieldPaste (argList [1]); - display.setWarnings (warnings); -} -/** - * Removes the item from the receiver's list at the given - * zero-relative index. - * - * @param index the index for the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void remove (int index) { - checkWidget(); - if (index == -1) error (SWT.ERROR_INVALID_RANGE); - /* - * Feature in Motif. An index out of range is handled - * correctly by the list widget but causes an unwanted - * Xm Warning. The fix is to check the range before - * deleting an item. - */ - int [] argList = {OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (!(0 <= index && index < argList [1])) { - error (SWT.ERROR_INVALID_RANGE); - } - if (argList [1] == 1) { - removeAll (); - } else { - OS.XmComboBoxDeletePos (handle, index + 1); - } -} -/** - * Removes the items from the receiver's list which are - * between the given zero-relative start and end - * indices (inclusive). - * - * @param start the start of the range - * @param end the end of the range - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void remove (int start, int end) { - checkWidget(); - if (start > end) return; - int [] argList = {OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (!(0 <= start && start <= end && end < argList [1])) { - error (SWT.ERROR_INVALID_RANGE); - } - if (argList [1] == (end - start + 1)) { - removeAll (); - } else { - for (int i = start; i <= end; i++) { - OS.XmComboBoxDeletePos (handle, start + 1); - } - } -} -void register () { - super.register (); - int [] argList = {OS.XmNlist, 0, OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - display.addWidget (argList[1], this); - display.addWidget (argList[3], this); -} -void releaseWidget () { - super.releaseWidget (); - if (display.focusedCombo == this) display.focusedCombo = null; - /* - * Bug in Motif. Disposing a Combo while its list is visible - * causes Motif to crash. The fix is to hide the drop down - * list before disposing the Combo. - */ - if ((style & SWT.DROP_DOWN) != 0) { - int[] argList = new int[] {OS.XmNlist, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int xtParent = OS.XtParent (argList [1]); - while (xtParent != 0 && !OS.XtIsSubclass (xtParent, OS.shellWidgetClass ())) { - xtParent = OS.XtParent (xtParent); - } - if (xtParent != 0) OS.XtPopdown (xtParent); - } -} -/** - * Searches the receiver's list starting at the first item - * until an item is found that is equal to the argument, - * and removes that item from the list. - * - * @param string the item to remove - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void remove (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true); - int xmString = OS.XmStringCreateLocalized (buffer); - if (xmString == 0) error (SWT.ERROR_ITEM_NOT_REMOVED); - int [] argList = {OS.XmNlist, 0, OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int index = OS.XmListItemPos (argList[1], xmString); - OS.XmStringFree (xmString); - if (index == 0) error (SWT.ERROR_INVALID_ARGUMENT); - if (argList [3] == 1) { - removeAll (); - } else { - OS.XmComboBoxDeletePos (handle, index); - } -} -/** - * Removes all of the items from the receiver's list and clear the - * contents of receiver's text field. - * <p> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void removeAll () { - checkWidget(); - int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0, OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XmTextSetString (argList[1], new byte[1]); - display.setWarnings(warnings); - OS.XmListDeselectAllItems (argList[3]); - for (int i = 0; i < argList[5]; i++) { - OS.XmComboBoxDeletePos(handle, 1); - } -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's text is modified. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ModifyListener - * @see #addModifyListener - */ -public void removeModifyListener (ModifyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Modify, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the user changes the receiver's selection. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener (SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Selection, listener); - eventTable.unhook (SWT.DefaultSelection,listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is verified. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see VerifyListener - * @see #addVerifyListener - * - * @since 3.1 - */ -public void removeVerifyListener (VerifyListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Verify, listener); -} -/** - * Selects the item at the given zero-relative index in the receiver's - * list. If the item at the index was already selected, it remains - * selected. Indices that are out of range are ignored. - * - * @param index the index of the item to select - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void select (int index) { - checkWidget(); - if (index == -1) { - int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XmTextSetString (argList[1], new byte[1]); - display.setWarnings (warnings); - OS.XmListDeselectAllItems (argList[3]); - } else { - int [] argList = {OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (!(0 <= index && index < argList [1])) return; - int [] argList2 = {OS.XmNselectedPosition, index}; - ignoreSelect = true; - OS.XtSetValues(handle, argList2, argList2.length / 2); - ignoreSelect = false; - } -} -void sendFocusEvent (int type) { - Display display = this.display; - Control focusedCombo = display.focusedCombo; - if (type == SWT.FocusIn && focusedCombo != this) { - super.sendFocusEvent (type); - if (!isDisposed ()) display.focusedCombo = this; - } -} -boolean sendIMKeyEvent (int type, XKeyEvent xEvent) { - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return super.sendIMKeyEvent (type, xEvent, argList [1]); -} -void setBackgroundPixel (int pixel) { - super.setBackgroundPixel (pixel); - int [] argList1 = {OS.XmNtextField, 0, OS.XmNlist, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int text = argList1 [1], list = argList1 [3]; - int [] argList2 = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0}; - OS.XtGetValues (text, argList2, argList2.length / 2); - OS.XmChangeColor (text, pixel); - OS.XtSetValues (text, argList2, argList2.length / 2); - int [] argList3 = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0}; - OS.XtGetValues (list, argList3, argList3.length / 2); - OS.XmChangeColor (list, pixel); - OS.XtSetValues (list, argList3, argList3.length / 2); -} -boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - checkWidget(); - int newHeight = (resize && (style & SWT.DROP_DOWN) != 0) ? getTextHeight() : height; - return super.setBounds (x, y, width, newHeight, move, resize); -} -public void setFont (Font font) { - checkWidget(); - - /* - * Bug in Motif. Setting the font in a combo widget that does - * not have any items causes a GP on UTF-8 locale. - * The fix is to add an item, change the font, then - * remove the added item at the end. - */ - int [] argList1 = {OS.XmNitems, 0, OS.XmNitemCount, 0,}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - boolean fixString = OS.IsDBLocale && argList1 [3] == 0; - if (fixString) { - byte [] buffer = Converter.wcsToMbcs (getCodePage (), "string", true); - int xmString = OS.XmStringCreateLocalized (buffer); - OS.XmComboBoxAddItem (handle, xmString, -1, false); - OS.XmStringFree (xmString); - } - super.setFont (font); - if (fixString) OS.XtSetValues (handle, argList1, argList1.length / 2); - - /* - * Bug in Motif. When a font is set in a combo box after the widget - * is realized, the combo box does not lay out properly. For example, - * the drop down arrow may be positioned in the middle of the text - * field or may be invisible, positioned outside the bounds of the - * widget. The fix is to detect these cases and force the combo box - * to be laid out properly by temporarily growing and then shrinking - * the widget. - * - * NOTE: This problem also occurs for simple combo boxes. - */ - if (OS.XtIsRealized (handle)) { - int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - OS.XtGetValues (handle, argList2, argList2.length / 2); - OS.XtResizeWidget (handle, argList2 [1], argList2 [3] + 1, argList2 [5]); - OS.XtResizeWidget (handle, argList2 [1], argList2 [3], argList2 [5]); - } -} -void setForegroundPixel (int pixel) { - int [] argList1 = {OS.XmNtextField, 0, OS.XmNlist, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int [] argList2 = {OS.XmNforeground, pixel}; - OS.XtSetValues (argList1 [1], argList2, argList2.length / 2); - OS.XtSetValues (argList1 [3], argList2, argList2.length / 2); - super.setForegroundPixel (pixel); -} -/** - * Sets the text of the item in the receiver's list at the given - * zero-relative index to the string argument. - * - * @param index the index for the item - * @param string the new text for the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setItem (int index, String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if (index == -1) error (SWT.ERROR_INVALID_RANGE); - int [] argList = {OS.XmNlist, 0, OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (!(0 <= index && index < argList [3])) { - error (SWT.ERROR_INVALID_RANGE); - } - byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true); - int xmString = OS.XmStringCreateLocalized (buffer); - if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED); - boolean isSelected = OS.XmListPosSelected (argList[1], index + 1); - OS.XmListReplaceItemsPosUnselected (argList[1], new int [] {xmString}, 1, index + 1); - if (isSelected) OS.XmListSelectPos (argList[1], index + 1, false); - OS.XmStringFree (xmString); -} -/** - * Sets the receiver's list to be the given array of items. - * - * @param items the array of items - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the items array is null</li> - * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setItems (String [] items) { - checkWidget(); - if (items == null) error (SWT.ERROR_NULL_ARGUMENT); - for (int i=0; i<items.length; i++) { - if (items [i] == null) error (SWT.ERROR_INVALID_ARGUMENT); - } - - if (items.length == 0) { - removeAll(); - return; - } - - int index = 0; - int [] table = new int [items.length]; - String codePage = getCodePage (); - while (index < items.length) { - String string = items [index]; - byte [] buffer = Converter.wcsToMbcs (codePage, encodeString(string), true); - int xmString = OS.XmStringCreateLocalized (buffer); - if (xmString == 0) break; - table [index++] = xmString; - } - int ptr = OS.XtMalloc (index * 4); - OS.memmove (ptr, table, index * 4); - int [] argList1 = {OS.XmNitems, ptr, OS.XmNitemCount, index}; - OS.XtSetValues (handle, argList1, argList1.length / 2); - for (int i=0; i<index; i++) OS.XmStringFree (table [i]); - OS.XtFree (ptr); - if (index < items.length) error (SWT.ERROR_ITEM_NOT_ADDED); - - int [] argList2 = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList2, argList2.length / 2); - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XmTextSetString (argList2[1], new byte[1]); - display.setWarnings(warnings); - int [] argList3 = {OS.XmNlist, 0}; - OS.XtGetValues (handle, argList3, argList3.length / 2); - int [] argList4 = {OS.XmNselectedItemCount, 0, OS.XmNselectedItems, 0}; - OS.XtSetValues (argList3 [1], argList4, argList4.length / 2); -} -/** - * Marks the receiver's list as visible if the argument is <code>true</code>, - * and marks it invisible otherwise. - * <p> - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, marking - * it visible may not actually cause it to be displayed. - * </p> - * - * @param visible the new visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.4 - */ -public void setListVisible (boolean visible) { - checkWidget (); - if ((style & SWT.DROP_DOWN) != 0) { - int[] argList1 = new int[] {OS.XmNlist, 0, OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int xtParent = OS.XtParent (argList1 [1]); - while (xtParent != 0 && !OS.XtIsSubclass (xtParent, OS.shellWidgetClass ())) { - xtParent = OS.XtParent (xtParent); - } - if (xtParent != 0) { - if (visible) { - int [] argList2 = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - OS.XtGetValues (argList1 [3], argList2, argList2.length / 2); - int x = argList2 [1], y = argList2 [3] + argList2 [7] + argList2 [9]; - short [] root_x = new short [1], root_y = new short [1]; - OS.XtTranslateCoords (handle, (short) x, (short) y, root_x, root_y); - OS.XtMoveWidget (xtParent, root_x [0], root_y [0]); - OS.XtPopup (xtParent, OS.XtGrabNone); - } else { - // This code is intentionally commented - //OS.XtPopdown (xtParent); - } - } - } -} -/** - * Sets the orientation of the receiver, which must be one - * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>. - * <p> - * - * @param orientation new orientation style - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.1.2 - */ -public void setOrientation (int orientation) { - checkWidget(); -} -/** - * Sets the selection in the receiver's text field to the - * range specified by the argument whose x coordinate is the - * start of the selection and whose y coordinate is the end - * of the selection. - * - * @param selection a point representing the new selection start and end - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the point is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (Point selection) { - checkWidget(); - if (selection == null) error (SWT.ERROR_NULL_ARGUMENT); - - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - - /* Clear the highlight before setting the selection. */ - int position = OS.XmTextGetLastPosition (argList[1]); - - /* - * Bug in MOTIF. XmTextSetSelection () fails to set the - * selection when the receiver is not realized. The fix - * is to force the receiver to be realized by forcing the - * shell to be realized. If the receiver is realized before - * the shell, MOTIF fails to draw the text widget and issues - * lots of X BadDrawable errors. - */ - if (!OS.XtIsRealized (handle)) getShell ().realizeWidget (); - - /* Set the selection. */ - int xDisplay = OS.XtDisplay (argList[1]); - if (xDisplay == 0) return; - int nStart = Math.min (Math.max (Math.min (selection.x, selection.y), 0), position); - int nEnd = Math.min (Math.max (Math.max (selection.x, selection.y), 0), position); - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XmTextSetSelection (argList[1], nStart, nEnd, OS.XtLastTimestampProcessed (xDisplay)); - - /* Force the i-beam to follow the highlight/selection. */ - OS.XmTextSetInsertionPosition (argList[1], nEnd); - display.setWarnings(warnings); -} -/** - * Sets the contents of the receiver's text field to the - * given string. - * <p> - * This call is ignored when the receiver is read only and - * the given string is not in the receiver's list. - * </p> - * <p> - * Note: The text field in a <code>Combo</code> is typically - * only capable of displaying a single line of text. Thus, - * setting the text to a string containing line breaks or - * other special characters will probably cause it to - * display incorrectly. - * </p> - * - * @param string the new text - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - - /* - * The read-only and non-read-only cases must be handled - * separately here because the platform will allow the - * text of a read-only combo to be set to any value, - * regardless of whether it appears in the combo's item - * list or not. - */ - if ((style & SWT.READ_ONLY) != 0) { - int index = indexOf (string); - if (index != -1) select (index); - } else { - byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); - int xmString = OS.XmStringCreateLocalized (buffer); - if (xmString == 0) return; - int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int index = OS.XmListItemPos (argList[3], xmString); - if (index > 0) { - /* The list contains the item. */ - OS.XmComboBoxSelectItem(handle, xmString); - } else { - /* The list does not contain the item. */ - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XmTextSetString (argList[1], buffer); - OS.XmTextSetInsertionPosition (argList[1], 0); - display.setWarnings(warnings); - } - OS.XmStringFree (xmString); - } -} -/** - * Sets the maximum number of characters that the receiver's - * text field is capable of holding to be the argument. - * <p> - * To reset this value to the default, use <code>setTextLimit(Combo.LIMIT)</code>. - * Specifying a limit value larger than <code>Combo.LIMIT</code> sets the - * receiver's limit to <code>Combo.LIMIT</code>. - * </p> - * @param limit new text limit - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #LIMIT - */ -public void setTextLimit (int limit) { - checkWidget(); - if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO); - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - OS.XmTextSetMaxLength (argList[1], limit); -} -/** - * Sets the number of items that are visible in the drop - * down portion of the receiver's list. - * <p> - * Note: This operation is a hint and is not supported on - * platforms that do not have this concept. - * </p> - * - * @param count the new number of items to be visible - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.0 - */ -public void setVisibleItemCount (int count) { - checkWidget (); - if (count < 0) return; - this.visibleCount = count; - /* - * But in Motif. Setting the XmNvisibleItemCount resource - * for the combo box after it has been realized causes the - * widget to layout badly, sometimes moving the drop down - * arrow part of the combo box outside of the bounds. - * The fix is to set the XmNvisibleItemCount resource on - * the list instead. - */ - int [] argList1 = new int [] {OS.XmNlist, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int [] argList2 = {OS.XmNvisibleItemCount, count}; - OS.XtSetValues (argList1 [1], argList2, argList2.length / 2); -} -void deregister () { - super.deregister (); - int [] argList = {OS.XmNlist, 0, OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - display.removeWidget (argList[1]); - display.removeWidget (argList[3]); -} -void enableWidget (boolean enabled) { - super.enableWidget (enabled); - int [] argList = { - OS.XmNlist, 0, - OS.XmNtextField, 0, - }; - OS.XtGetValues (handle, argList, argList.length / 2); - enableHandle (enabled, argList [1]); - enableHandle (enabled, argList [3]); -} -/** - * Bug in Motif. - * Empty strings in the combo will cause GPFs if a) they - * are the only items in the combo or b) if they are - * included in an array which is set as the value of the - * combo's items resource. To protect against these GPFs, - * make sure that no empty strings are added to the combo. - * The solution is to add a space to empty strings or - * strings which are all spaces. This space is removed - * when answering the text of items which are all spaces. - */ -String encodeString(String string) { - for (int i = 0; i < string.length(); i++) { - if (string.charAt(i) != ' ') { - return string; - } - } - return string + ' '; -} -/** - * Bug in Motif. - * Empty strings in the combo will cause GPFs if a) they - * are the only items in the combo or b) if they are - * included in an array which is set as the value of the - * combo's items resource. To protect against these GPFs, - * make sure that no empty strings are added to the combo. - * The solution is to add a space to empty strings or - * strings which include only spaces. A space is removed - * when answering the text of items which are all spaces. - */ -String decodeString(String string) { - if (string.length() == 0) return string; - - for (int i = 0; i < string.length(); i++) { - if (string.charAt(i) != ' ') { - return string; - } - } - return string.substring(0, string.length() - 1); -} -int XmNactivateCallback (int w, int client_data, int call_data) { - postEvent (SWT.DefaultSelection); - return 0; -} -int XmNbrowseSelectionCallback (int w, int client_data, int call_data) { - /* - * Bug in MOTIF. If items have been added and removed from a - * combo then users are able to select an empty drop-down item - * in the combo once and force a resulting callback. In such - * cases we want to eat this callback so that listeners are not - * notified. - */ - if (ignoreSelect || getSelectionIndex() == -1) return 0; - postEvent (SWT.Selection); - return 0; -} -int XmNmodifyVerifyCallback (int w, int client_data, int call_data) { - int result = super.XmNmodifyVerifyCallback (w, client_data, call_data); - if (result != 0) return result; - if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return result; - XmTextVerifyCallbackStruct textVerify = new XmTextVerifyCallbackStruct (); - OS.memmove (textVerify, call_data, XmTextVerifyCallbackStruct.sizeof); - XmTextBlockRec textBlock = new XmTextBlockRec (); - OS.memmove (textBlock, textVerify.text, XmTextBlockRec.sizeof); - byte [] buffer = new byte [textBlock.length]; - OS.memmove (buffer, textBlock.ptr, textBlock.length); - String codePage = getCodePage (); - String text = new String (Converter.mbcsToWcs (codePage, buffer)); - Event event = new Event (); - if (textVerify.event != 0) { - XKeyEvent xEvent = new XKeyEvent (); - OS.memmove (xEvent, textVerify.event, XKeyEvent.sizeof); - event.time = xEvent.time; - setKeyState (event, xEvent); - } - event.start = textVerify.startPos; - event.end = textVerify.endPos; - event.doit = textVerify.doit == 1; - event.text = text; - sendEvent (SWT.Verify, event); - String newText = event.text; - textVerify.doit = (byte) ((event.doit && newText != null) ? 1 : 0); - if (newText != null && newText != text) { - OS.XtFree(textBlock.ptr); - byte [] buffer2 = Converter.wcsToMbcs (codePage, newText, true); - int length = buffer2.length; - int ptr = OS.XtMalloc (length); - OS.memmove (ptr, buffer2, length); - textBlock.ptr = ptr; - textBlock.length = buffer2.length - 1; - OS.memmove (textVerify.text, textBlock, XmTextBlockRec.sizeof); - } - OS.memmove (call_data, textVerify, XmTextVerifyCallbackStruct.sizeof); - return result; -} -int XmNvalueChangedCallback (int w, int client_data, int call_data) { - sendEvent (SWT.Modify); - return 0; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java deleted file mode 100755 index e026007d46..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java +++ /dev/null @@ -1,1565 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.cairo.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class are controls which are capable - * of containing other controls. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>NO_BACKGROUND, NO_FOCUS, NO_MERGE_PAINTS, NO_REDRAW_RESIZE, NO_RADIO_GROUP, EMBEDDED, DOUBLE_BUFFERED</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * Note: The <code>NO_BACKGROUND</code>, <code>NO_FOCUS</code>, <code>NO_MERGE_PAINTS</code>, - * and <code>NO_REDRAW_RESIZE</code> styles are intended for use with <code>Canvas</code>. - * They can be used with <code>Composite</code> if you are drawing your own, but their - * behavior is undefined if they are used with subclasses of <code>Composite</code> other - * than <code>Canvas</code>. - * </p><p> - * Note: The <code>CENTER</code> style, although undefined for composites, has the - * same value as <code>EMBEDDED</code> which is used to embed widgets from other - * widget toolkits into SWT. On some operating systems (GTK, Motif), this may cause - * the children of this composite to be obscured. - * </p><p> - * This class may be subclassed by custom control implementors - * who are building controls that are constructed from aggregates - * of other controls. - * </p> - * - * @see Canvas - * @see <a href="http://www.eclipse.org/swt/snippets/#composite">Composite snippets</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public class Composite extends Scrollable { - Layout layout; - public int embeddedHandle; - int focusHandle, damagedRegion, clientWindow; - Control [] tabList; - int layoutCount, backgroundMode; - - static byte [] _XEMBED_INFO = Converter.wcsToMbcs (null, "_XEMBED_INFO", true); - static byte[] _XEMBED = Converter.wcsToMbcs (null, "_XEMBED", true); - -Composite () { - /* Do nothing */ -} -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a widget which will be the parent of the new instance (cannot be null) - * @param style the style of widget to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * </ul> - * - * @see SWT#NO_BACKGROUND - * @see SWT#NO_FOCUS - * @see SWT#NO_MERGE_PAINTS - * @see SWT#NO_REDRAW_RESIZE - * @see SWT#NO_RADIO_GROUP - * @see SWT#EMBEDDED - * @see SWT#DOUBLE_BUFFERED - * @see Widget#getStyle - */ -public Composite (Composite parent, int style) { - super (parent, style); -} -static int checkStyle (int style) { - style &= ~SWT.TRANSPARENT; - return style; -} -Control [] _getChildren () { - int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int ptr = argList [1], count = argList [3]; - if (count == 0 || ptr == 0) return new Control [0]; - int [] handles = new int [count]; - OS.memmove (handles, ptr, count * 4); - int length = focusHandle != 0 ? count - 1 : count; - Control [] children = new Control [length]; - int i = 0, j = 0; - while (i < count) { - int handle = handles [i]; - if (handle != 0) { - Widget widget = display.getWidget (handle); - if (widget != null && widget != this) { - if (widget instanceof Control) { - children [j++] = (Control) widget; - } - } - } - i++; - } - if (j == length) return children; - Control [] newChildren = new Control [j]; - System.arraycopy (children, 0, newChildren, 0, j); - return newChildren; -} -Control [] _getTabList () { - if (tabList == null) return tabList; - int count = 0; - for (int i=0; i<tabList.length; i++) { - if (!tabList [i].isDisposed ()) count++; - } - if (count == tabList.length) return tabList; - Control [] newList = new Control [count]; - int index = 0; - for (int i=0; i<tabList.length; i++) { - if (!tabList [i].isDisposed ()) { - newList [index++] = tabList [i]; - } - } - tabList = newList; - return tabList; -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - Point size; - if (layout != null) { - if ((wHint == SWT.DEFAULT) || (hHint == SWT.DEFAULT)) { - changed |= (state & LAYOUT_CHANGED) != 0; - size = layout.computeSize (this, wHint, hHint, changed); - state &= ~LAYOUT_CHANGED; - } else { - size = new Point (wHint, hHint); - } - } else { - size = minimumSize (wHint, hHint, changed); - } - if (size.x == 0) size.x = DEFAULT_WIDTH; - if (size.y == 0) size.y = DEFAULT_HEIGHT; - if (wHint != SWT.DEFAULT) size.x = wHint; - if (hHint != SWT.DEFAULT) size.y = hHint; - Rectangle trim = computeTrim (0, 0, size.x, size.y); - return new Point (trim.width, trim.height); -} -Control [] computeTabList () { - Control result [] = super.computeTabList (); - if (result.length == 0) return result; - Control [] list = tabList != null ? _getTabList () : _getChildren (); - for (int i=0; i<list.length; i++) { - Control child = list [i]; - Control [] childList = child.computeTabList (); - if (childList.length != 0) { - Control [] newResult = new Control [result.length + childList.length]; - System.arraycopy (result, 0, newResult, 0, result.length); - System.arraycopy (childList, 0, newResult, result.length, childList.length); - result = newResult; - } - } - return result; -} -/** - * Clears any data that has been cached by a Layout for all widgets that - * are in the parent hierarchy of the changed control up to and including the - * receiver. If an ancestor does not have a layout, it is skipped. - * - * @param changed an array of controls that changed state and require a recalculation of size - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li> - * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.1 - */ -public void changed (Control[] changed) { - checkWidget (); - if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT); - for (int i=0; i<changed.length; i++) { - Control control = changed [i]; - if (control == null) error (SWT.ERROR_INVALID_ARGUMENT); - if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - boolean ancestor = false; - Composite composite = control.parent; - while (composite != null) { - ancestor = composite == this; - if (ancestor) break; - composite = composite.parent; - } - if (!ancestor) error (SWT.ERROR_INVALID_PARENT); - } - for (int i=0; i<changed.length; i++) { - Control child = changed [i]; - Composite composite = child.parent; - while (child != this) { - if (composite.layout == null || !composite.layout.flushCache (child)) { - composite.state |= LAYOUT_CHANGED; - } - child = composite; - composite = child.parent; - } - } -} -void checkBuffered () { - if ((state & CANVAS) == 0) { - super.checkBuffered (); - } -} -protected void checkSubclass () { - /* Do nothing - Subclassing is allowed */ -} -void createHandle (int index) { - state |= CANVAS; - boolean scroll = (style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0; - if (!scroll) state |= THEME_BACKGROUND; - createHandle (index, parent.handle, scroll); -} -void createHandle (int index, int parentHandle, boolean scrolled) { - if (scrolled) { - int [] argList = {OS.XmNancestorSensitive, 1}; - scrolledHandle = OS.XmCreateMainWindow (parentHandle, null, argList, argList.length / 2); - if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES); - } - if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) { - int [] argList1 = { - OS.XmNmarginWidth, 3, - OS.XmNmarginHeight, 3, - OS.XmNresizePolicy, OS.XmRESIZE_NONE, - OS.XmNshadowType, OS.XmSHADOW_IN, - OS.XmNshadowThickness, hasBorder () ? display.buttonShadowThickness : 0, - }; - formHandle = OS.XmCreateForm (scrolledHandle, null, argList1, argList1.length / 2); - if (formHandle == 0) error (SWT.ERROR_NO_HANDLES); - int [] argList2 = { - OS.XmNtopAttachment, OS.XmATTACH_FORM, - OS.XmNbottomAttachment, OS.XmATTACH_FORM, - OS.XmNleftAttachment, OS.XmATTACH_FORM, - OS.XmNrightAttachment, OS.XmATTACH_FORM, - OS.XmNresizable, 0, - OS.XmNmarginWidth, 0, - OS.XmNmarginHeight, 0, - OS.XmNresizePolicy, OS.XmRESIZE_NONE, - OS.XmNtraversalOn, (style & SWT.NO_FOCUS) != 0 ? 0 : 1, - }; - handle = OS.XmCreateDrawingArea (formHandle, null, argList2, argList2.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - } else { - int [] argList = { - OS.XmNancestorSensitive, 1, - OS.XmNborderWidth, hasBorder () ? 1 : 0, - OS.XmNmarginWidth, 0, - OS.XmNmarginHeight, 0, - OS.XmNresizePolicy, OS.XmRESIZE_NONE, - OS.XmNtraversalOn, (style & SWT.NO_FOCUS) != 0 ? 0 : 1, - }; - if (scrolledHandle != 0) parentHandle = scrolledHandle; - handle = OS.XmCreateDrawingArea (parentHandle, null, argList, argList.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - } - int [] argList = {OS.XmNtraversalOn, 0}; - focusHandle = OS.XmCreateDrawingArea (handle, null, argList, argList.length / 2); - if (focusHandle == 0) error (SWT.ERROR_NO_HANDLES); - int [] argList1 = {OS.XmNforeground, 0, OS.XmNbackground, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - if (formHandle != 0) OS.XtSetValues (formHandle, argList1, argList1.length / 2); -} -int defaultBackground () { - return display.compositeBackground; -} -int defaultForeground () { - return display.compositeForeground; -} -void deregister () { - super.deregister (); - if (focusHandle != 0) display.removeWidget (focusHandle); -} -void drawBackground (GC gc, int x, int y, int width, int height) { - Control control = findBackgroundControl (); - if (control != null) { - GCData data = gc.getGCData (); - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - Cairo.cairo_save (cairo); - if (control.backgroundImage != null) { - short [] root_x = new short [1], root_y = new short [1]; - OS.XtTranslateCoords (handle, (short) 0, (short) 0, root_x, root_y); - short [] control_x = new short [1], control_y = new short [1]; - OS.XtTranslateCoords (control.handle, (short) 0, (short) 0, control_x, control_y); - int tileX = root_x[0] - control_x[0], tileY = root_y[0] - control_y[0]; - Cairo.cairo_translate (cairo, -tileX, -tileY); - x += tileX; - y += tileY; - int xDisplay = OS.XtDisplay (handle); - int xVisual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay)); - int xDrawable = control.backgroundImage.pixmap; - int [] unused = new int [1]; int [] w = new int [1]; int [] h = new int [1]; - OS.XGetGeometry (xDisplay, xDrawable, unused, unused, unused, w, h, unused, unused); - int /*long*/ surface = Cairo.cairo_xlib_surface_create (xDisplay, xDrawable, xVisual, w [0], h [0]); - if (surface == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ pattern = Cairo.cairo_pattern_create_for_surface (surface); - if (pattern == 0) error (SWT.ERROR_NO_HANDLES); - Cairo.cairo_pattern_set_extend (pattern, Cairo.CAIRO_EXTEND_REPEAT); - Cairo.cairo_set_source (cairo, pattern); - Cairo.cairo_surface_destroy (surface); - Cairo.cairo_pattern_destroy (pattern); - } else { - XColor color = getXColor (control.getBackgroundPixel ()); - Cairo.cairo_set_source_rgba (cairo, (color.red & 0xFFFF) / (float)0xFFFF, (color.green & 0xFFFF) / (float)0xFFFF, (color.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF); - } - Cairo.cairo_rectangle (cairo, x, y, width, height); - Cairo.cairo_fill (cairo); - Cairo.cairo_restore (cairo); - } else { - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int xGC = gc.handle; - XGCValues values = new XGCValues(); - if (control.backgroundImage != null) { - OS.XGetGCValues (xDisplay, xGC, OS.GCFillStyle | OS.GCTile | OS.GCTileStipXOrigin | OS.GCTileStipYOrigin, values); - short [] root_x = new short [1], root_y = new short [1]; - OS.XtTranslateCoords (handle, (short) 0, (short) 0, root_x, root_y); - short [] control_x = new short [1], control_y = new short [1]; - OS.XtTranslateCoords (control.handle, (short) 0, (short) 0, control_x, control_y); - int tileX = root_x[0] - control_x[0], tileY = root_y[0] - control_y[0]; - OS.XSetFillStyle (xDisplay, xGC, OS.FillTiled); - OS.XSetTSOrigin (xDisplay, xGC, -tileX, -tileY); - OS.XSetTile (xDisplay, xGC, control.backgroundImage.pixmap); - OS.XFillRectangle (data.display, data.drawable, xGC, x, y, width, height); - OS.XSetFillStyle (xDisplay, xGC, values.fill_style); - OS.XSetTSOrigin (xDisplay, xGC, values.ts_x_origin, values.ts_y_origin); - } else { - OS.XGetGCValues (xDisplay, xGC, OS.GCForeground, values); - OS.XSetForeground (xDisplay, xGC, control.getBackgroundPixel ()); - OS.XFillRectangle (data.display, data.drawable, xGC, x, y, width, height); - OS.XSetForeground (xDisplay, xGC, values.foreground); - } - } - } else { - gc.fillRectangle (x, y, width, height); - } -} -Composite findDeferredControl () { - return layoutCount > 0 ? this : parent.findDeferredControl (); -} -void fixTabList (Control control) { - if (tabList == null) return; - int count = 0; - for (int i=0; i<tabList.length; i++) { - if (tabList [i] == control) count++; - } - if (count == 0) return; - Control [] newList = null; - int length = tabList.length - count; - if (length != 0) { - newList = new Control [length]; - int index = 0; - for (int i=0; i<tabList.length; i++) { - if (tabList [i] != control) { - newList [index++] = tabList [i]; - } - } - } - tabList = newList; -} -int focusHandle () { - if (focusHandle == 0) return super.focusHandle (); - return focusHandle; -} -int focusProc (int w, int client_data, int call_data, int continue_to_dispatch) { - XFocusChangeEvent xEvent = new XFocusChangeEvent (); - OS.memmove (xEvent, call_data, XFocusChangeEvent.sizeof); - int handle = OS.XtWindowToWidget (xEvent.display, xEvent.window); - Shell shell = getShell (); - if (handle != shell.shellHandle) { - return super.XFocusChange (w, client_data, call_data, continue_to_dispatch); - } - if (xEvent.mode != OS.NotifyNormal) return 0; - switch (xEvent.detail) { - case OS.NotifyNonlinear: - case OS.NotifyNonlinearVirtual: { - switch (xEvent.type) { - case OS.FocusIn: - sendClientEvent (OS.CurrentTime, OS.XEMBED_WINDOW_ACTIVATE, 0, 0, 0); - break; - case OS.FocusOut: - sendClientEvent (OS.CurrentTime, OS.XEMBED_WINDOW_DEACTIVATE, 0, 0, 0); - break; - } - } - } - return 0; -} -boolean fowardKeyEvent (int event) { - if (clientWindow == 0) return false; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - XKeyEvent xEvent = new XKeyEvent (); - OS.memmove (xEvent, event, XKeyEvent.sizeof); - xEvent.window = clientWindow; - int newEvent = OS.XtMalloc (XEvent.sizeof); - OS.memmove (newEvent, xEvent, XKeyEvent.sizeof); - int xDisplay = OS.XtDisplay (handle); - OS.XSendEvent (xDisplay, clientWindow, false, 0, newEvent); - OS.XSync (xDisplay, false); - OS.XtFree (newEvent); - display.setWarnings (warnings); - return true; -} -/** - * Returns the receiver's background drawing mode. This - * will be one of the following constants defined in class - * <code>SWT</code>: - * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>, - * <code>INHERTIT_FORCE</code>. - * - * @return the background mode - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SWT - * - * @since 3.2 - */ -public int getBackgroundMode () { - checkWidget (); - return backgroundMode; -} -/** - * Returns a (possibly empty) array containing the receiver's children. - * Children are returned in the order that they are drawn. The topmost - * control appears at the beginning of the array. Subsequent controls - * draw beneath this control and appear later in the array. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its list of children, so modifying the array will - * not affect the receiver. - * </p> - * - * @return an array of children - * - * @see Control#moveAbove - * @see Control#moveBelow - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Control [] getChildren () { - checkWidget(); - return _getChildren (); -} -public Rectangle getClientArea () { - checkWidget(); - /* - * Bug in Motif. For some reason, if a form has not been realized, - * calling XtResizeWidget () on the form does not lay out properly. - * The fix is to force the widget to be realized by forcing the shell - * to be realized. - */ - if (formHandle != 0) { - if (!OS.XtIsRealized (handle)) getShell ().realizeWidget (); - } - return super.getClientArea (); -} -int getChildrenCount () { - /* - * NOTE: The current implementation will count - * non-registered children. - */ - int [] argList = {OS.XmNnumChildren, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (focusHandle != 0) return Math.max (0, argList [1] - 1); - return argList [1]; -} -/** - * Returns layout which is associated with the receiver, or - * null if one has not been set. - * - * @return the receiver's layout or null - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Layout getLayout () { - checkWidget(); - return layout; -} -/** - * Returns <code>true</code> if the receiver has deferred - * the performing of layout, and <code>false</code> otherwise. - * - * @return the receiver's deferred layout state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #setLayoutDeferred(boolean) - * @see #isLayoutDeferred() - * - * @since 3.1 - */ -public boolean getLayoutDeferred () { - checkWidget (); - return layoutCount > 0 ; -} -/** - * Gets the (possibly empty) tabbing order for the control. - * - * @return tabList the ordered list of controls representing the tab order - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #setTabList - */ -public Control [] getTabList () { - checkWidget (); - Control [] tabList = _getTabList (); - if (tabList == null) { - int count = 0; - Control [] list =_getChildren (); - for (int i=0; i<list.length; i++) { - if (list [i].isTabGroup ()) count++; - } - tabList = new Control [count]; - int index = 0; - for (int i=0; i<list.length; i++) { - if (list [i].isTabGroup ()) { - tabList [index++] = list [i]; - } - } - } - return tabList; -} -boolean hasBorder () { - return (style & SWT.BORDER) != 0; -} -void hookEvents () { - super.hookEvents (); - if ((state & CANVAS) != 0) { - OS.XtInsertEventHandler (handle, 0, true, display.windowProc, NON_MASKABLE, OS.XtListTail); - } - if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) { - int focusProc = display.focusProc; - int windowProc = display.windowProc; - OS.XtInsertEventHandler (handle, OS.StructureNotifyMask | OS.SubstructureNotifyMask, false, windowProc, STRUCTURE_NOTIFY, OS.XtListTail); - OS.XtInsertEventHandler (handle, OS.PropertyChangeMask, false, windowProc, PROPERTY_CHANGE, OS.XtListTail); - OS.XtInsertEventHandler (handle, 0, true, windowProc, NON_MASKABLE, OS.XtListTail); - Shell shell = getShell (); - OS.XtInsertEventHandler (shell.shellHandle, OS.FocusChangeMask, false, focusProc, handle, OS.XtListTail); - } -} - -boolean hooksKeys () { - return hooks (SWT.KeyDown) || hooks (SWT.KeyUp); -} -/** - * Returns <code>true</code> if the receiver or any ancestor - * up to and including the receiver's nearest ancestor shell - * has deferred the performing of layouts. Otherwise, <code>false</code> - * is returned. - * - * @return the receiver's deferred layout state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #setLayoutDeferred(boolean) - * @see #getLayoutDeferred() - * - * @since 3.1 - */ -public boolean isLayoutDeferred () { - checkWidget (); - return findDeferredControl () != null; -} -boolean isTabGroup () { - if ((state & CANVAS) != 0) return true; - return super.isTabGroup (); -} -/** - * If the receiver has a layout, asks the layout to <em>lay out</em> - * (that is, set the size and location of) the receiver's children. - * If the receiver does not have a layout, do nothing. - * <p> - * This is equivalent to calling <code>layout(true)</code>. - * </p> - * <p> - * Note: Layout is different from painting. If a child is - * moved or resized such that an area in the parent is - * exposed, then the parent will paint. If no child is - * affected, the parent will not paint. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void layout () { - checkWidget (); - layout (true); -} -/** - * If the receiver has a layout, asks the layout to <em>lay out</em> - * (that is, set the size and location of) the receiver's children. - * If the argument is <code>true</code> the layout must not rely - * on any information it has cached about the immediate children. If it - * is <code>false</code> the layout may (potentially) optimize the - * work it is doing by assuming that none of the receiver's - * children has changed state since the last layout. - * If the receiver does not have a layout, do nothing. - * <p> - * If a child is resized as a result of a call to layout, the - * resize event will invoke the layout of the child. The layout - * will cascade down through all child widgets in the receiver's widget - * tree until a child is encountered that does not resize. Note that - * a layout due to a resize will not flush any cached information - * (same as <code>layout(false)</code>). - * </p> - * <p> - * Note: Layout is different from painting. If a child is - * moved or resized such that an area in the parent is - * exposed, then the parent will paint. If no child is - * affected, the parent will not paint. - * </p> - * - * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void layout (boolean changed) { - checkWidget (); - if (layout == null) return; - layout (changed, false); -} -/** - * If the receiver has a layout, asks the layout to <em>lay out</em> - * (that is, set the size and location of) the receiver's children. - * If the changed argument is <code>true</code> the layout must not rely - * on any information it has cached about its children. If it - * is <code>false</code> the layout may (potentially) optimize the - * work it is doing by assuming that none of the receiver's - * children has changed state since the last layout. - * If the all argument is <code>true</code> the layout will cascade down - * through all child widgets in the receiver's widget tree, regardless of - * whether the child has changed size. The changed argument is applied to - * all layouts. If the all argument is <code>false</code>, the layout will - * <em>not</em> cascade down through all child widgets in the receiver's widget - * tree. However, if a child is resized as a result of a call to layout, the - * resize event will invoke the layout of the child. Note that - * a layout due to a resize will not flush any cached information - * (same as <code>layout(false)</code>). - * </p> - * <p> - * Note: Layout is different from painting. If a child is - * moved or resized such that an area in the parent is - * exposed, then the parent will paint. If no child is - * affected, the parent will not paint. - * </p> - * - * @param changed <code>true</code> if the layout must flush its caches, and <code>false</code> otherwise - * @param all <code>true</code> if all children in the receiver's widget tree should be laid out, and <code>false</code> otherwise - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.1 - */ -public void layout (boolean changed, boolean all) { - checkWidget (); - if (layout == null && !all) return; - markLayout (changed, all); - updateLayout (all); -} -/** - * Forces a lay out (that is, sets the size and location) of all widgets that - * are in the parent hierarchy of the changed control up to and including the - * receiver. The layouts in the hierarchy must not rely on any information - * cached about the changed control or any of its ancestors. The layout may - * (potentially) optimize the work it is doing by assuming that none of the - * peers of the changed control have changed state since the last layout. - * If an ancestor does not have a layout, skip it. - * <p> - * Note: Layout is different from painting. If a child is - * moved or resized such that an area in the parent is - * exposed, then the parent will paint. If no child is - * affected, the parent will not paint. - * </p> - * - * @param changed a control that has had a state change which requires a recalculation of its size - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the changed array is null any of its controls are null or have been disposed</li> - * <li>ERROR_INVALID_PARENT - if any control in changed is not in the widget tree of the receiver</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.1 - */ -public void layout (Control [] changed) { - checkWidget (); - if (changed == null) error (SWT.ERROR_INVALID_ARGUMENT); - for (int i=0; i<changed.length; i++) { - Control control = changed [i]; - if (control == null) error (SWT.ERROR_INVALID_ARGUMENT); - if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - boolean ancestor = false; - Composite composite = control.parent; - while (composite != null) { - ancestor = composite == this; - if (ancestor) break; - composite = composite.parent; - } - if (!ancestor) error (SWT.ERROR_INVALID_PARENT); - } - int updateCount = 0; - Composite [] update = new Composite [16]; - for (int i=0; i<changed.length; i++) { - Control child = changed [i]; - Composite composite = child.parent; - while (child != this) { - if (composite.layout != null) { - composite.state |= LAYOUT_NEEDED; - if (!composite.layout.flushCache (child)) { - composite.state |= LAYOUT_CHANGED; - } - } - if (updateCount == update.length) { - Composite [] newUpdate = new Composite [update.length + 16]; - System.arraycopy (update, 0, newUpdate, 0, update.length); - update = newUpdate; - } - child = update [updateCount++] = composite; - composite = child.parent; - } - } - for (int i=updateCount-1; i>=0; i--) { - update [i].updateLayout (false); - } -} -void manageChildren () { - if (focusHandle != 0) { - OS.XtSetMappedWhenManaged (focusHandle, false); - OS.XtManageChild (focusHandle); - } - super.manageChildren (); - if (focusHandle != 0) { - OS.XtConfigureWidget(focusHandle, 0, 0, 1, 1, 0); - OS.XtSetMappedWhenManaged (focusHandle, true); - } - if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) { - Shell shell = getShell (); - shell.createFocusProxy (); - if (!OS.XtIsRealized (handle)) shell.realizeWidget (); - int xDisplay = OS.XtDisplay (handle); - OS.XSync (xDisplay, false); - embeddedHandle = OS.XtWindow (handle); - } -} -void markLayout (boolean changed, boolean all) { - if (layout != null) { - state |= LAYOUT_NEEDED; - if (changed) state |= LAYOUT_CHANGED; - } - if (all) { - Control [] children = _getChildren (); - for (int i=0; i<children.length; i++) { - children [i].markLayout (changed, all); - } - } -} -Point minimumSize (int wHint, int hHint, boolean changed) { - Control [] children = _getChildren (); - int width = 0, height = 0; - for (int i=0; i<children.length; i++) { - Rectangle rect = children [i].getBounds (); - width = Math.max (width, rect.x + rect.width); - height = Math.max (height, rect.y + rect.height); - } - return new Point (width, height); -} -void moveAbove (int handle1, int handle2) { - if (handle1 == handle2) return; - int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int ptr = argList [1], count = argList [3]; - if (count == 0 || ptr == 0) return; - int [] handles = new int [count]; - OS.memmove (handles, ptr, count * 4); - if (handle2 == 0) handle2 = handles [0]; - int i = 0, index1 = -1, index2 = -1; - while (i < count) { - int handle = handles [i]; - if (handle == handle1) index1 = i; - if (handle == handle2) index2 = i; - if (index1 != -1 && index2 != -1) break; - i++; - } - if (index1 == -1 || index2 == -1) return; - if (index1 == index2) return; - if (index1 < index2) { - System.arraycopy (handles, index1 + 1, handles, index1, index2 - index1 - 1); - handles [index2 - 1] = handle1; - } else { - System.arraycopy (handles, index2, handles, index2 + 1, index1 - index2); - handles [index2] = handle1; - } - OS.memmove (ptr, handles, count * 4); -} -void moveBelow (int handle1, int handle2) { - if (handle1 == handle2) return; - int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int ptr = argList [1], count = argList [3]; - if (count == 0 || ptr == 0) return; - int [] handles = new int [count]; - OS.memmove (handles, ptr, count * 4); - if (handle2 == 0) handle2 = handles [count - 1]; - int i = 0, index1 = -1, index2 = -1; - while (i < count) { - int handle = handles [i]; - if (handle == handle1) index1 = i; - if (handle == handle2) index2 = i; - if (index1 != -1 && index2 != -1) break; - i++; - } - if (index1 == -1 || index2 == -1) return; - if (index1 == index2) return; - if (index1 < index2) { - System.arraycopy (handles, index1 + 1, handles, index1, index2 - index1); - handles [index2] = handle1; - } else { - System.arraycopy (handles, index2 + 1, handles, index2 + 2, index1 - index2 - 1); - handles [index2 + 1] = handle1; - } - OS.memmove (ptr, handles, count * 4); -} -void propagateChildren (boolean enabled) { - super.propagateChildren (enabled); - Control [] children = _getChildren (); - for (int i = 0; i < children.length; i++) { - Control child = children [i]; - if (child.getEnabled ()) { - child.propagateChildren (enabled); - } - } -} -void realizeChildren () { - super.realizeChildren (); - Control [] children = _getChildren (); - for (int i=0; i<children.length; i++) { - children [i].realizeChildren (); - } - /* - * Feature in Motif. XmProcessTraversal() will not give focus to - * a widget that is obscured so the focus handle must be inside the - * client area of the parent. This means that it is visible as a - * single pixel widget in the parent. The fix is to unmap the - * focus handle so that it will be traversed by XmProcessTraversal() - * and will accept focus but will not be visible in the parent. - */ - if (focusHandle != 0) OS.XtUnmapWidget (focusHandle); - if ((state & CANVAS) != 0) { - if ((style & (SWT.DOUBLE_BUFFERED | SWT.NO_BACKGROUND)) != 0 || (style & SWT.NO_REDRAW_RESIZE) == 0) { - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int xWindow = OS.XtWindow (handle); - if (xWindow == 0) return; - int flags = 0; - XSetWindowAttributes attributes = new XSetWindowAttributes (); - if ((style & (SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED)) != 0) { - flags |= OS.CWBackPixmap; - attributes.background_pixmap = OS.None; - } - if ((style & SWT.NO_REDRAW_RESIZE) == 0) { - flags |= OS.CWBitGravity; - attributes.bit_gravity = OS.ForgetGravity; - } - if (flags != 0) { - OS.XChangeWindowAttributes (xDisplay, xWindow, flags, attributes); - } - } - } -} -void redrawChildren () { - super.redrawChildren (); - Control [] children = _getChildren (); - for (int i = 0; i < children.length; i++) { - Control child = children [i]; - if ((child.state & PARENT_BACKGROUND) != 0) { - child.redrawWidget (0, 0, 0, 0, true, false, true); - child.redrawChildren (); - } - } -} -void register () { - super.register (); - if (focusHandle != 0) display.addWidget (focusHandle, this); -} -void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean allChildren, boolean trim) { - super.redrawWidget (x, y, width, height, redrawAll, allChildren, trim); - if (!allChildren) return; - Control [] children = _getChildren (); - for (int i = 0; i < children.length; i++) { - Control child = children [i]; - Point location = child.getClientLocation (); - child.redrawWidget (x - location.x, y - location.y, width, height, redrawAll, allChildren, true); - } -} -void release (boolean destroy) { - if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) { - Shell shell = getShell (); - int focusProc = display.focusProc; - OS.XtRemoveEventHandler (shell.shellHandle, OS.FocusChangeMask, false, focusProc, handle); - if (clientWindow != 0) { - boolean warnings = display.getWarnings (); - display.setWarnings (false); - int xDisplay = OS.XtDisplay (handle); - OS.XUnmapWindow (xDisplay, clientWindow); - OS.XReparentWindow (xDisplay, clientWindow, OS.XDefaultRootWindow (xDisplay), 0, 0); - OS.XSync (xDisplay, false); - display.setWarnings (warnings); - } - setClientWindow (0); - } - super.release (destroy); -} -void releaseChildren (boolean destroy) { - Control [] children = _getChildren (); - for (int i=0; i<children.length; i++) { - Control child = children [i]; - if (child != null && !child.isDisposed ()) { - child.release (false); - } - } - super.releaseChildren (destroy); -} -void releaseHandle () { - super.releaseHandle (); - focusHandle = embeddedHandle = 0; -} -void releaseWidget () { - super.releaseWidget (); - layout = null; - tabList = null; - if (damagedRegion != 0) OS.XDestroyRegion (damagedRegion); - damagedRegion = 0; -} -void removeControl (Control control) { - fixTabList (control); -} -void resizeClientWindow () { - if (clientWindow == 0) return; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int xDisplay = OS.XtDisplay (handle); - OS.XMoveResizeWindow (xDisplay, clientWindow, 0, 0, Math.max(1, argList [1]), Math.max(1, argList [3])); - display.setWarnings (warnings); -} -void sendClientEvent (int time, int message, int detail, int data1, int data2) { - if (clientWindow == 0) return; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - int xDisplay = OS.XtDisplay (handle); - XClientMessageEvent xEvent = new XClientMessageEvent (); - xEvent.type = OS.ClientMessage; - xEvent.window = clientWindow; - xEvent.message_type = OS.XInternAtom (xDisplay, _XEMBED, false); - xEvent.format = 32; - xEvent.data [0] = time != 0 ? time : OS.XtLastTimestampProcessed (xDisplay); - xEvent.data [1] = message; - xEvent.data [2] = detail; - xEvent.data [3] = data1; - xEvent.data [4] = data2; - int event = OS.XtMalloc (XEvent.sizeof); - OS.memmove (event, xEvent, XClientMessageEvent.sizeof); - OS.XSendEvent (xDisplay, clientWindow, false, 0, event); - OS.XSync (xDisplay, false); - OS.XtFree (event); - display.setWarnings (warnings); -} -/** - * Sets the background drawing mode to the argument which should - * be one of the following constants defined in class <code>SWT</code>: - * <code>INHERIT_NONE</code>, <code>INHERIT_DEFAULT</code>, - * <code>INHERIT_FORCE</code>. - * - * @param mode the new background mode - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SWT - * - * @since 3.2 - */ -public void setBackgroundMode (int mode) { - checkWidget (); - backgroundMode = mode; - Control[] children = _getChildren (); - for (int i = 0; i < children.length; i++) { - children [i].updateBackgroundMode (); - } -} -void setBackgroundPixel (int pixel) { - super.setBackgroundPixel (pixel); - if ((state & CANVAS) != 0) { - if ((style & (SWT.NO_BACKGROUND | SWT.DOUBLE_BUFFERED)) != 0) { - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int xWindow = OS.XtWindow (handle); - if (xWindow == 0) return; - XSetWindowAttributes attributes = new XSetWindowAttributes (); - attributes.background_pixmap = OS.None; - OS.XChangeWindowAttributes (xDisplay, xWindow, OS.CWBackPixmap, attributes); - } - } -} -boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - boolean changed = super.setBounds (x, y, width, height, move, resize); - if (changed && resize) { - if (focusHandle != 0) { - int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - OS.XtConfigureWidget (focusHandle, 0, 0, argList [1], argList [3], 0); - } - if (layout != null) { - markLayout (false, false); - updateLayout (false); - } - if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) { - resizeClientWindow (); - } - } - return changed; -} -void setClientWindow (int window) { - if (focusHandle != 0) { - if (window == OS.XtWindow (focusHandle)) return; - } - boolean warnings = display.getWarnings (); - display.setWarnings (false); - int xDisplay = OS.XtDisplay (handle); - if (window != 0) { - if (clientWindow == 0) { - clientWindow = window; - sendClientEvent (0, OS.XEMBED_EMBEDDED_NOTIFY, 0, 0, 0); - OS.XtRegisterDrawable (xDisplay, clientWindow, handle); - OS.XSelectInput (xDisplay, clientWindow, OS.PropertyChangeMask); - updateMapped (); - resizeClientWindow (); - Shell shell = getShell (); - if (shell == display.getActiveShell ()) { - shell.bringToTop (true); - sendClientEvent (0, OS.XEMBED_WINDOW_ACTIVATE, 0, 0, 0); - if (this == display.getFocusControl ()) { - sendClientEvent (0, OS.XEMBED_FOCUS_IN, OS.XEMBED_FOCUS_CURRENT, 0, 0); - } - } - } - } else { - if (clientWindow != 0) OS.XtUnregisterDrawable (xDisplay, clientWindow); - clientWindow = 0; - } - display.setWarnings (warnings); -} -public boolean setFocus () { - checkWidget (); - Control [] children = _getChildren (); - for (int i=0; i<children.length; i++) { - Control child = children [i]; - if (child.setFocus ()) return true; - } - return super.setFocus (); -} -public void setFont (Font font) { - checkWidget(); - super.setFont (font); - if ((state & CANVAS) != 0) { - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int xWindow = OS.XtWindow (handle); - if (xWindow == 0) return; - OS.XClearArea (xDisplay, xWindow, 0, 0, 0, 0, true); - } -} -void setForegroundPixel (int pixel) { - super.setForegroundPixel (pixel); - if ((state & CANVAS) != 0) { - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int xWindow = OS.XtWindow (handle); - if (xWindow == 0) return; - OS.XClearArea (xDisplay, xWindow, 0, 0, 0, 0, true); - } -} -/** - * Sets the layout which is associated with the receiver to be - * the argument which may be null. - * - * @param layout the receiver's new layout or null - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setLayout (Layout layout) { - checkWidget(); - this.layout = layout; -} -/** - * If the argument is <code>true</code>, causes subsequent layout - * operations in the receiver or any of its children to be ignored. - * No layout of any kind can occur in the receiver or any of its - * children until the flag is set to false. - * Layout operations that occurred while the flag was - * <code>true</code> are remembered and when the flag is set to - * <code>false</code>, the layout operations are performed in an - * optimized manner. Nested calls to this method are stacked. - * - * @param defer the new defer state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #layout(boolean) - * @see #layout(Control[]) - * - * @since 3.1 - */ -public void setLayoutDeferred (boolean defer) { - if (!defer) { - if (--layoutCount == 0) { - if ((state & LAYOUT_CHILD) != 0 || (state & LAYOUT_NEEDED) != 0) { - updateLayout (true); - } - } - } else { - layoutCount++; - } -} -/** - * Sets the tabbing order for the specified controls to - * match the order that they occur in the argument list. - * - * @param tabList the ordered list of controls representing the tab order or null - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if a widget in the tabList is null or has been disposed</li> - * <li>ERROR_INVALID_PARENT - if widget in the tabList is not in the same widget tree</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setTabList (Control [] tabList) { - checkWidget (); - if (tabList != null) { - for (int i=0; i<tabList.length; i++) { - Control control = tabList [i]; - if (control == null) error (SWT.ERROR_INVALID_ARGUMENT); - if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - if (control.parent != this) error (SWT.ERROR_INVALID_PARENT); - } - Control [] newList = new Control [tabList.length]; - System.arraycopy (tabList, 0, newList, 0, tabList.length); - tabList = newList; - } - this.tabList = tabList; -} -void setParentBackground () { - super.setParentBackground (); - if (scrolledHandle != 0) setParentBackground (scrolledHandle); - if (formHandle != 0) setParentBackground (formHandle); -} -boolean setScrollBarVisible (ScrollBar bar, boolean visible) { - boolean changed = super.setScrollBarVisible (bar, visible); - if (changed && layout != null) { - markLayout (false, false); - updateLayout (false); - } - return changed; -} -boolean setTabGroupFocus (boolean next) { - if (isTabItem ()) return setTabItemFocus (next); - boolean takeFocus = (style & SWT.NO_FOCUS) == 0; - if ((state & CANVAS) != 0) { - takeFocus = hooksKeys (); - if ((style & SWT.EMBEDDED) != 0) takeFocus = true; - } - if (takeFocus && setTabItemFocus (next)) return true; - Control [] children = _getChildren (); - for (int i=0; i<children.length; i++) { - Control child = children [i]; - if (child.isTabItem () && child.setTabItemFocus (next)) return true; - } - return false; -} -boolean setTabItemFocus (boolean next) { - if (!super.setTabItemFocus (next)) return false; - if (handle != 0) { - if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) { - int detail = next ? OS.XEMBED_FOCUS_FIRST : OS.XEMBED_FOCUS_LAST; - sendClientEvent (0, OS.XEMBED_FOCUS_IN, detail, 0, 0); - } - } - return true; -} -int traversalCode (int key, XKeyEvent xEvent) { - if ((state & CANVAS) != 0) { - if ((style & SWT.NO_FOCUS) != 0) return 0; - if (hooksKeys ()) return 0; - } - return super.traversalCode (key, xEvent); -} -boolean translateMnemonic (Event event, Control control) { - if (super.translateMnemonic (event, control)) return true; - if (control != null) { - Control [] children = _getChildren (); - for (int i=0; i<children.length; i++) { - Control child = children [i]; - if (child.translateMnemonic (event, control)) return true; - } - } - return false; -} -boolean translateTraversal (int key, XKeyEvent xEvent) { - if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) return false; - return super.translateTraversal (key, xEvent); -} -void updateBackgroundMode () { - super.updateBackgroundMode (); - Control [] children = _getChildren (); - for (int i = 0; i < children.length; i++) { - children [i].updateBackgroundMode (); - } -} -void updateLayout (boolean all) { - Composite parent = findDeferredControl (); - if (parent != null) { - parent.state |= LAYOUT_CHILD; - return; - } - if ((state & LAYOUT_NEEDED) != 0) { - boolean changed = (state & LAYOUT_CHANGED) != 0; - state &= ~(LAYOUT_NEEDED | LAYOUT_CHANGED); - layout.layout (this, changed); - } - if (all) { - state &= ~LAYOUT_CHILD; - Control [] children = _getChildren (); - for (int i=0; i<children.length; i++) { - children [i].updateLayout (all); - } - } -} -int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XButtonPress (w, client_data, call_data, continue_to_dispatch); - if (result != 0) return result; - - /* Set focus for a canvas with no children */ - if ((state & CANVAS) != 0) { - XButtonEvent xEvent = new XButtonEvent (); - OS.memmove (xEvent, call_data, XButtonEvent.sizeof); - if ((style & SWT.NO_FOCUS) == 0 && hooksKeys ()) { - if (xEvent.button == 1) { - if (getChildrenCount () == 0) setFocus (); - } - } - /* - * Bug in Motif. On Solaris 8 only, stopping the other event - * handlers from being invoked after a menu has been displayed - * causes a segment fault. The fix is to not stop the event for - * button 3. - */ - if (xEvent.button != 3) { - OS.memmove (continue_to_dispatch, new int [1], 4); - } - return 1; - } - return result; -} -int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) { - if ((state & CANVAS) == 0) { - return super.XExposure (w, client_data, call_data, continue_to_dispatch); - } - if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0; - if (damagedRegion == 0) damagedRegion = OS.XCreateRegion (); - OS.XtAddExposureToRegion (call_data, damagedRegion); - if ((style & SWT.NO_MERGE_PAINTS) == 0) { - XExposeEvent xEvent = new XExposeEvent (); - OS.memmove (xEvent, call_data, XExposeEvent.sizeof); - int exposeCount = xEvent.count; - if (exposeCount == 0) { - if (OS.XEventsQueued (xEvent.display, OS.QueuedAfterReading) != 0) { - int xEvent1 = OS.XtMalloc (XEvent.sizeof); - display.exposeCount = display.lastExpose = 0; - int checkExposeProc = display.checkExposeProc; - OS.XCheckIfEvent (xEvent.display, xEvent1, checkExposeProc, xEvent.window); - exposeCount = display.exposeCount; - int lastExpose = display.lastExpose; - if (exposeCount != 0 && lastExpose != 0) { - XExposeEvent xExposeEvent = display.xExposeEvent; - OS.memmove (xExposeEvent, lastExpose, XExposeEvent.sizeof); - xExposeEvent.count = 0; - OS.memmove (lastExpose, xExposeEvent, XExposeEvent.sizeof); - } - OS.XtFree (xEvent1); - } - } - if (exposeCount != 0) return 0; - } - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return 0; - int damageRgn = damagedRegion; - damagedRegion = 0; - GCData data = new GCData (); - data.damageRgn = damageRgn; - GC gc = GC.motif_new (this, data); - OS.XSetRegion (xDisplay, gc.handle, damageRgn); - XRectangle rect = new XRectangle (); - OS.XClipBox (damageRgn, rect); - GC paintGC = null; - Image image = null; - if ((style & SWT.DOUBLE_BUFFERED) != 0) { - Rectangle client = getClientArea (); - int width = Math.max (1, Math.min (client.width, rect.x + rect.width)); - int height = Math.max (1, Math.min (client.height, rect.y + rect.height)); - image = new Image (display, width, height); - paintGC = gc; - GCData imageGCData = new GCData (); - imageGCData.damageRgn = damageRgn; - gc = GC.motif_new (image, imageGCData); - gc.setForeground (getForeground ()); - gc.setBackground (getBackground ()); - gc.setFont (getFont ()); - if ((style & SWT.NO_BACKGROUND) != 0) { - /* This code is intentionaly commented because it is too slow to copy bits from the screen */ -// paintGC.copyArea(image, 0, 0); - } else { - drawBackground (gc, 0, 0, width, height); - } - } - Event event = new Event (); - event.x = rect.x; - event.y = rect.y; - event.width = rect.width; - event.height = rect.height; - event.gc = gc; - sendEvent (SWT.Paint, event); - event.gc = null; - if ((style & SWT.DOUBLE_BUFFERED) != 0) { - gc.dispose (); - if (!isDisposed ()) { - paintGC.drawImage (image, 0, 0); - } - image.dispose (); - gc = paintGC; - } - gc.dispose (); - OS.XDestroyRegion (damageRgn); - return 0; -} -int xFocusIn (XFocusChangeEvent xEvent) { - int result = super.xFocusIn (xEvent); - if (handle != 0) { - if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) { - sendClientEvent (0, OS.XEMBED_FOCUS_IN, OS.XEMBED_FOCUS_CURRENT, 0, 0); - } - } - return result; -} -int xFocusOut (XFocusChangeEvent xEvent) { - int result = super.xFocusOut (xEvent); - if (handle != 0) { - if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) { - sendClientEvent (0, OS.XEMBED_FOCUS_OUT, 0, 0, 0); - } - } - return result; -} -int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XKeyPress (w, client_data, call_data, continue_to_dispatch); - if (result == 0) { - if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) { - if (fowardKeyEvent (call_data)) return 0; - } - } - return result; -} -int XKeyRelease (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XKeyRelease (w, client_data, call_data, continue_to_dispatch); - if (result == 0) { - if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) { - if (fowardKeyEvent (call_data)) return 0; - } - } - return result; -} -int XNonMaskable (int w, int client_data, int call_data, int continue_to_dispatch) { - if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) { - XEvent xEvent = new XEvent (); - OS.memmove (xEvent, call_data, XEvent.sizeof); - if (xEvent.type == OS.ClientMessage) { - XClientMessageEvent xClientEvent = new XClientMessageEvent (); - OS.memmove (xClientEvent, call_data, XClientMessageEvent.sizeof); - int xDisplay = OS.XtDisplay (handle); - if (xClientEvent.message_type == OS.XInternAtom (xDisplay, _XEMBED, false)) { - int type = xClientEvent.data [1]; - switch (type) { - case OS.XEMBED_REQUEST_FOCUS: { - setFocus (); - break; - } - case OS.XEMBED_FOCUS_PREV: { - traverse (SWT.TRAVERSE_TAB_PREVIOUS); - break; - } - case OS.XEMBED_FOCUS_NEXT: { - traverse (SWT.TRAVERSE_TAB_NEXT); - break; - } - } - } - return 0; - } - } - if ((state & CANVAS) != 0) { - XEvent xEvent = new XEvent (); - OS.memmove (xEvent, call_data, XEvent.sizeof); - if (xEvent.type == OS.GraphicsExpose) { - return XExposure (w, client_data, call_data, continue_to_dispatch); - } - } - return 0; -} -int XPropertyChange (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XPropertyChange (w, client_data, call_data, continue_to_dispatch); - if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) { - XPropertyEvent xPropertyEvent = new XPropertyEvent (); - OS.memmove(xPropertyEvent, call_data, XPropertyEvent.sizeof); - if (xPropertyEvent.window == clientWindow) { - int atom = xPropertyEvent.atom; - int xDisplay = xPropertyEvent.display; - if (atom == OS.XInternAtom (xDisplay, _XEMBED_INFO, false)) { - updateMapped (); - } - } - } - return result; -} -int XStructureNotify (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XStructureNotify (w, client_data, call_data, continue_to_dispatch); - if ((state & CANVAS) != 0 && (style & SWT.EMBEDDED) != 0) { - XEvent xEvent = new XEvent (); - OS.memmove (xEvent, call_data, XEvent.sizeof); - switch (xEvent.type) { - case OS.ReparentNotify: { - XReparentEvent xReparentEvent = new XReparentEvent (); - OS.memmove (xReparentEvent, call_data, XReparentEvent.sizeof); - if (clientWindow == 0) setClientWindow (xReparentEvent.window); - break; - } - case OS.CreateNotify: { - XCreateWindowEvent xCreateEvent = new XCreateWindowEvent (); - OS.memmove (xCreateEvent, call_data, XCreateWindowEvent.sizeof); - if (clientWindow == 0) setClientWindow (xCreateEvent.window); - break; - } - case OS.DestroyNotify: { - XDestroyWindowEvent xDestroyEvent = new XDestroyWindowEvent (); - OS.memmove (xDestroyEvent, call_data, XDestroyWindowEvent.sizeof); - if (xDestroyEvent.window == clientWindow) setClientWindow (0); - break; - } - case OS.ConfigureNotify: { - XConfigureEvent xConfigureEvent = new XConfigureEvent (); - OS.memmove (xConfigureEvent, call_data, XConfigureEvent.sizeof); - if (xConfigureEvent.window == clientWindow) resizeClientWindow (); - break; - } - } - } - return result; -} -void updateMapped () { - if (clientWindow == 0) return; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - int xDisplay = OS.XtDisplay (handle); - int prop = OS.XInternAtom (xDisplay, _XEMBED_INFO, false); - int [] type = new int [1], format = new int [1]; - int [] nitems = new int [1], bytes_after = new int [1], data = new int [1]; - if (OS.XGetWindowProperty (xDisplay, clientWindow, prop, 0, 2, false, prop, type, format, nitems, bytes_after, data) == 0) { - if (type [0] == prop) { - if (nitems [0] >= 2) { - int [] buffer = new int [2]; - OS.memmove (buffer, data [0], buffer.length * 4); - int flags = buffer [1]; - if ((flags & OS.XEMBED_MAPPED) != 0) { - OS.XMapWindow (xDisplay, clientWindow); - } else { - OS.XUnmapWindow (xDisplay, clientWindow); - } - } - } - } - if (data [0] != 0) OS.XFree (data [0]); - display.setWarnings (warnings); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java deleted file mode 100755 index 0a10bccddb..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java +++ /dev/null @@ -1,3761 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.accessibility.*; - -/** - * Control is the abstract superclass of all windowed user interface classes. - * <p> - * <dl> - * <dt><b>Styles:</b> - * <dd>BORDER</dd> - * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd> - * <dt><b>Events:</b> - * <dd>DragDetect, FocusIn, FocusOut, Help, KeyDown, KeyUp, MenuDetect, MouseDoubleClick, MouseDown, MouseEnter, - * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize, Traverse</dd> - * </dl> - * </p><p> - * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified. - * </p><p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#control">Control snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public abstract class Control extends Widget implements Drawable { - int drawCount, redrawWindow; - Composite parent; - Cursor cursor; - Menu menu; - Image backgroundImage; - Font font; - Region region; - String toolTipText; - Object layoutData; - Accessible accessible; - -Control () { - /* Do nothing */ -} -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#BORDER - * @see SWT#LEFT_TO_RIGHT - * @see SWT#RIGHT_TO_LEFT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Control (Composite parent, int style) { - super (parent, style); - this.parent = parent; - createWidget (0); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the control is moved or resized, by sending - * it one of the messages defined in the <code>ControlListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ControlListener - * @see #removeControlListener - */ -public void addControlListener(ControlListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Resize,typedListener); - addListener (SWT.Move,typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when a drag gesture occurs, by sending it - * one of the messages defined in the <code>DragDetectListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see DragDetectListener - * @see #removeDragDetectListener - * - * @since 3.3 - */ -public void addDragDetectListener (DragDetectListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.DragDetect,typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the control gains or loses focus, by sending - * it one of the messages defined in the <code>FocusListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see FocusListener - * @see #removeFocusListener - */ -public void addFocusListener(FocusListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener(SWT.FocusIn,typedListener); - addListener(SWT.FocusOut,typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when help events are generated for the control, - * by sending it one of the messages defined in the - * <code>HelpListener</code> interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see HelpListener - * @see #removeHelpListener - */ -public void addHelpListener (HelpListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Help, typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when keys are pressed and released on the system keyboard, by sending - * it one of the messages defined in the <code>KeyListener</code> - * interface. - * <p> - * When a key listener is added to a control, the control - * will take part in widget traversal. By default, all - * traversal keys (such as the tab key and so on) are - * delivered to the control. In order for a control to take - * part in traversal, it should listen for traversal events. - * Otherwise, the user can traverse into a control but not - * out. Note that native controls such as table and tree - * implement key traversal in the operating system. It is - * not necessary to add traversal listeners for these controls, - * unless you want to override the default traversal. - * </p> - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see KeyListener - * @see #removeKeyListener - */ -public void addKeyListener(KeyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener(SWT.KeyUp,typedListener); - addListener(SWT.KeyDown,typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the platform-specific context menu trigger - * has occurred, by sending it one of the messages defined in - * the <code>MenuDetectListener</code> interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see MenuDetectListener - * @see #removeMenuDetectListener - * - * @since 3.3 - */ -public void addMenuDetectListener (MenuDetectListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.MenuDetect, typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when mouse buttons are pressed and released, by sending - * it one of the messages defined in the <code>MouseListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see MouseListener - * @see #removeMouseListener - */ -public void addMouseListener(MouseListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener(SWT.MouseDown,typedListener); - addListener(SWT.MouseUp,typedListener); - addListener(SWT.MouseDoubleClick,typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the mouse moves, by sending it one of the - * messages defined in the <code>MouseMoveListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see MouseMoveListener - * @see #removeMouseMoveListener - */ -public void addMouseMoveListener(MouseMoveListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener(SWT.MouseMove,typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the mouse passes or hovers over controls, by sending - * it one of the messages defined in the <code>MouseTrackListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see MouseTrackListener - * @see #removeMouseTrackListener - */ -public void addMouseTrackListener (MouseTrackListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.MouseEnter,typedListener); - addListener (SWT.MouseExit,typedListener); - addListener (SWT.MouseHover,typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the mouse wheel is scrolled, by sending - * it one of the messages defined in the - * <code>MouseWheelListener</code> interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see MouseWheelListener - * @see #removeMouseWheelListener - * - * @since 3.3 - */ -public void addMouseWheelListener (MouseWheelListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.MouseWheel, typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver needs to be painted, by sending it - * one of the messages defined in the <code>PaintListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see PaintListener - * @see #removePaintListener - */ -public void addPaintListener(PaintListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener(SWT.Paint,typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when traversal events occur, by sending it - * one of the messages defined in the <code>TraverseListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see TraverseListener - * @see #removeTraverseListener - */ -public void addTraverseListener (TraverseListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Traverse,typedListener); -} -int borderHandle () { - return topHandle (); -} -void checkBackground () { - Shell shell = getShell (); - if (this == shell) return; - state &= ~PARENT_BACKGROUND; - Composite composite = parent; - do { - int mode = composite.backgroundMode; - if (mode != 0) { - if (mode == SWT.INHERIT_DEFAULT) { - Control control = this; - do { - if ((control.state & THEME_BACKGROUND) == 0) { - return; - } - control = control.parent; - } while (control != composite); - } - state |= PARENT_BACKGROUND; - return; - } - if (composite == shell) break; - composite = composite.parent; - } while (true); -} -void checkBuffered () { - style &= ~SWT.DOUBLE_BUFFERED; -} -/** - * Returns the preferred size of the receiver. - * <p> - * The <em>preferred size</em> of a control is the size that it would - * best be displayed at. The width hint and height hint arguments - * allow the caller to ask a control questions such as "Given a particular - * width, how high does the control need to be to show all of the contents?" - * To indicate that the caller does not wish to constrain a particular - * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint. - * </p> - * - * @param wHint the width hint (can be <code>SWT.DEFAULT</code>) - * @param hHint the height hint (can be <code>SWT.DEFAULT</code>) - * @return the preferred size of the control - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see Layout - * @see #getBorderWidth - * @see #getBounds - * @see #getSize - * @see #pack(boolean) - * @see "computeTrim, getClientArea for controls that implement them" - */ -public Point computeSize (int wHint, int hHint) { - return computeSize (wHint, hHint, true); -} -/** - * Returns the preferred size of the receiver. - * <p> - * The <em>preferred size</em> of a control is the size that it would - * best be displayed at. The width hint and height hint arguments - * allow the caller to ask a control questions such as "Given a particular - * width, how high does the control need to be to show all of the contents?" - * To indicate that the caller does not wish to constrain a particular - * dimension, the constant <code>SWT.DEFAULT</code> is passed for the hint. - * </p><p> - * If the changed flag is <code>true</code>, it indicates that the receiver's - * <em>contents</em> have changed, therefore any caches that a layout manager - * containing the control may have been keeping need to be flushed. When the - * control is resized, the changed flag will be <code>false</code>, so layout - * manager caches can be retained. - * </p> - * - * @param wHint the width hint (can be <code>SWT.DEFAULT</code>) - * @param hHint the height hint (can be <code>SWT.DEFAULT</code>) - * @param changed <code>true</code> if the control's contents have changed, and <code>false</code> otherwise - * @return the preferred size of the control. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see Layout - * @see #getBorderWidth - * @see #getBounds - * @see #getSize - * @see #pack(boolean) - * @see "computeTrim, getClientArea for controls that implement them" - */ -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - int width = DEFAULT_WIDTH; - int height = DEFAULT_HEIGHT; - if (wHint != SWT.DEFAULT) width = wHint; - if (hHint != SWT.DEFAULT) height = hHint; - int border = getBorderWidth (); - width += border * 2; - height += border * 2; - return new Point (width, height); -} - -Control computeTabGroup () { - if (isTabGroup ()) return this; - return parent.computeTabGroup (); -} - -Control computeTabRoot () { - Control [] tabList = parent._getTabList (); - if (tabList != null) { - int index = 0; - while (index < tabList.length) { - if (tabList [index] == this) break; - index++; - } - if (index == tabList.length) { - if (isTabGroup ()) return this; - } - } - return parent.computeTabRoot (); -} - -Control [] computeTabList () { - if (isTabGroup ()) { - if (getVisible () && getEnabled ()) { - return new Control [] {this}; - } - } - return new Control [0]; -} - -void createWidget (int index) { - state |= DRAG_DETECT; - checkOrientation (parent); - super.createWidget (index); - checkBackground (); - checkBuffered (); - setParentTraversal (); - overrideTranslations (); - - /* - * Register for the IME. This is necessary on single byte - * platforms as well as double byte platforms in order to - * get composed characters. For example, accented characters - * on a German locale. - */ - if (!hasIMSupport()) { - OS.XmImRegister (handle, 0); - int focusHandle = focusHandle (); - if (handle != focusHandle) { - OS.XmImRegister (focusHandle, 0); - } - } - - /* - * Feature in MOTIF. When a widget is created before the - * parent has been realized, the widget is created behind - * all siblings in the Z-order. When a widget is created - * after the parent has been realized, it is created in - * front of all siblings. This is not incorrect but is - * unexpected. The fix is to force all widgets to always - * be created behind their siblings. - */ - int topHandle = topHandle (); - if (OS.XtIsRealized (topHandle) && !OS.XtIsSubclass (topHandle, OS.shellWidgetClass ())) { - int window = OS.XtWindow (topHandle); - if (window != 0) { - int display = OS.XtDisplay (topHandle); - if (display != 0) OS.XLowerWindow (display, window); - } - /* - * Make sure that the widget has been properly realized - * because the widget was created after the parent - * has been realized. This is not part of the fix - * for Z-order in the code above. - */ - realizeChildren (); - } - - /* - * Bug in Motif. Under certain circumstances, when a - * text widget is created as a child of another control - * that has drag and drop, starting a drag in the text - * widget causes a protection fault. The fix is to - * disable the built in drag and drop for all widgets - * by overriding the drag start traslation. - */ - OS.XtOverrideTranslations (handle, display.dragTranslations); - - /* - * Feature in Motif. When the XmNfontList resource is set for - * a widget, Motif creates a copy of the fontList and disposes - * the copy when the widget is disposed. This means that when - * the programmer queries the font, not only will the handle be - * different but the font will be unexpectedly disposed when - * the widget is disposed. This can cause GP's when the font - * is set in another widget. The fix is to cache the font that - * the programmer provides. The initial value of the cache is - * the default font for the widget. - */ - font = defaultFont (); -} -int defaultBackground () { - return display.defaultBackground; -} -Font defaultFont () { - return display.defaultFont; -} -int defaultForeground () { - return display.defaultForeground; -} -/** - * Detects a drag and drop gesture. This method is used - * to detect a drag gesture when called from within a mouse - * down listener. - * - * <p>By default, a drag is detected when the gesture - * occurs anywhere within the client area of a control. - * Some controls, such as tables and trees, override this - * behavior. In addition to the operating system specific - * drag gesture, they require the mouse to be inside an - * item. Custom widget writers can use <code>setDragDetect</code> - * to disable the default detection, listen for mouse down, - * and then call <code>dragDetect()</code> from within the - * listener to conditionally detect a drag. - * </p> - * - * @param event the mouse down event - * - * @return <code>true</code> if the gesture occurred, and <code>false</code> otherwise. - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT when the event is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see DragDetectListener - * @see #addDragDetectListener - * - * @see #getDragDetect - * @see #setDragDetect - * - * @since 3.3 - */ -public boolean dragDetect (Event event) { - checkWidget (); - if (event == null) error (SWT.ERROR_NULL_ARGUMENT); - return dragDetect (event.button, event.count, event.stateMask, event.x, event.y); -} -/** - * Detects a drag and drop gesture. This method is used - * to detect a drag gesture when called from within a mouse - * down listener. - * - * <p>By default, a drag is detected when the gesture - * occurs anywhere within the client area of a control. - * Some controls, such as tables and trees, override this - * behavior. In addition to the operating system specific - * drag gesture, they require the mouse to be inside an - * item. Custom widget writers can use <code>setDragDetect</code> - * to disable the default detection, listen for mouse down, - * and then call <code>dragDetect()</code> from within the - * listener to conditionally detect a drag. - * </p> - * - * @param event the mouse down event - * - * @return <code>true</code> if the gesture occurred, and <code>false</code> otherwise. - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT when the event is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see DragDetectListener - * @see #addDragDetectListener - * - * @see #getDragDetect - * @see #setDragDetect - * - * @since 3.3 - */ -public boolean dragDetect (MouseEvent event) { - checkWidget (); - if (event == null) error (SWT.ERROR_NULL_ARGUMENT); - return dragDetect (event.button, event.count, event.stateMask, event.x, event.y); -} -boolean dragDetect (int button, int count, int stateMask, int x, int y) { - if (button != 2 || count != 1) return false; - if (!dragDetect (x, y, false, null)) return false; - return sendDragEvent (button, stateMask, x, y, true); -} -boolean dragDetect (int x, int y, boolean force, boolean [] consume) { - return true; -} -boolean drawGripper (int x, int y, int width, int height, boolean vertical) { - return false; -} -void enableWidget (boolean enabled) { - enableHandle (enabled, handle); -} -Control findBackgroundControl () { - if ((state & BACKGROUND) != 0 || backgroundImage != null) return this; - return (state & PARENT_BACKGROUND) != 0 ? parent.findBackgroundControl () : null; -} -char findMnemonic (String string) { - int index = 0; - int length = string.length (); - do { - while (index < length && string.charAt (index) != '&') index++; - if (++index >= length) return '\0'; - if (string.charAt (index) != '&') return string.charAt (index); - index++; - } while (index < length); - return '\0'; -} -void fixFocus (Control focusControl) { - Shell shell = getShell (); - Control control = this; - while (control != shell && (control = control.parent) != null) { - if (control.setFocus ()) return; - } - shell.setSavedFocus (focusControl); -} -int focusHandle () { - return handle; -} -int fontHandle () { - return handle; -} -/** - * Forces the receiver to have the <em>keyboard focus</em>, causing - * all keyboard events to be delivered to it. - * - * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #setFocus - */ -public boolean forceFocus () { - checkWidget(); - if (display.focusEvent == SWT.FocusOut) return false; - Decorations shell = menuShell (); - shell.setSavedFocus (this); - shell.bringToTop (false); - int focusHandle = focusHandle (); - if (handle != focusHandle) { - int [] argList1 = {OS.XmNnumChildren, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - if (argList1 [1] > 1) { - int [] argList = new int [] {OS.XmNtraversalOn, 0}; - OS.XtGetValues (focusHandle, argList, argList.length / 2); - if (argList [1] == 0) { - argList [1] = 1; - OS.XtSetValues (focusHandle, argList, argList.length / 2); - overrideTranslations (); - } - } else { - focusHandle = handle; - } - } - int [] argList = new int [] {OS.XmNtraversalOn, 0}; - OS.XtGetValues (focusHandle, argList, argList.length / 2); - boolean force = argList [1] == 0; - if (force) { - state |= FOCUS_FORCED; - argList [1] = 1; - OS.XtSetValues (focusHandle, argList, argList.length / 2); - overrideTranslations (); - } - if (XmProcessTraversal (focusHandle, OS.XmTRAVERSE_CURRENT)) return true; - if (force) { - state &= ~FOCUS_FORCED; - argList [1] = 0; - OS.XtSetValues (focusHandle, argList, argList.length / 2); - } - return false; -} - -/** - * Returns the accessible object for the receiver. - * If this is the first time this object is requested, - * then the object is created and returned. - * - * @return the accessible object - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see Accessible#addAccessibleListener - * @see Accessible#addAccessibleControlListener - * - * @since 2.0 - */ -public Accessible getAccessible () { - checkWidget (); - if (accessible == null) { - accessible = Accessible.internal_new_Accessible (this); - } - return accessible; -} - -/** - * Returns the receiver's background color. - * <p> - * Note: This operation is a hint and may be overridden by the platform. - * For example, on some versions of Windows the background of a TabFolder, - * is a gradient rather than a solid color. - * </p> - * @return the background color - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Color getBackground () { - checkWidget(); - Control control = findBackgroundControl (); - if (control == null) control = this; - return Color.motif_new (display, getXColor (control.getBackgroundPixel ())); -} -/** - * Returns the receiver's background image. - * - * @return the background image - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.2 - */ -public Image getBackgroundImage () { - checkWidget (); - Control control = findBackgroundControl (); - if (control == null) control = this; - return control.backgroundImage; -} -int getBackgroundPixel () { - int [] argList = {OS.XmNbackground, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the receiver's border width. - * - * @return the border width - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getBorderWidth () { - checkWidget(); - int borderHandle = borderHandle (); - int [] argList = {OS.XmNborderWidth, 0}; - OS.XtGetValues (borderHandle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns a rectangle describing the receiver's size and location - * relative to its parent (or its display if its parent is null), - * unless the receiver is a shell. In this case, the location is - * relative to the display. - * - * @return the receiver's bounding rectangle - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Rectangle getBounds () { - checkWidget(); - int topHandle = topHandle (); - int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - OS.XtGetValues (topHandle, argList, argList.length / 2); - int borders = argList [9] * 2; - return new Rectangle ((short) argList [1], (short) argList [3], argList [5] + borders, argList [7] + borders); -} -Point getClientLocation () { - short [] handle_x = new short [1], handle_y = new short [1]; - OS.XtTranslateCoords (handle, (short) 0, (short) 0, handle_x, handle_y); - short [] topHandle_x = new short [1], topHandle_y = new short [1]; - OS.XtTranslateCoords (parent.handle, (short) 0, (short) 0, topHandle_x, topHandle_y); - return new Point (handle_x [0] - topHandle_x [0], handle_y [0] - topHandle_y [0]); -} -String getCodePage () { - return font.codePage; -} -/** - * Returns the receiver's cursor, or null if it has not been set. - * <p> - * When the mouse pointer passes over a control its appearance - * is changed to match the control's cursor. - * </p> - * - * @return the receiver's cursor or <code>null</code> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.3 - */ -public Cursor getCursor () { - checkWidget (); - return cursor; -} -/** - * Returns <code>true</code> if the receiver is detecting - * drag gestures, and <code>false</code> otherwise. - * - * @return the receiver's drag detect state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.3 - */ -public boolean getDragDetect () { - checkWidget (); - return (state & DRAG_DETECT) != 0; -} -/** - * Returns <code>true</code> if the receiver is enabled, and - * <code>false</code> otherwise. A disabled control is typically - * not selectable from the user interface and draws with an - * inactive or "grayed" look. - * - * @return the receiver's enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #isEnabled - */ -public boolean getEnabled () { - checkWidget(); - int [] argList = {OS.XmNsensitive, 0}; - OS.XtGetValues (topHandle (), argList, argList.length / 2); - return argList [1] != 0; -} -/** - * Returns the font that the receiver will use to paint textual information. - * - * @return the receiver's font - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Font getFont () { - checkWidget(); - return font; -} - -int getFontAscent (int font) { - - /* Create a font context to iterate over each element in the font list */ - int [] buffer = new int [1]; - if (!OS.XmFontListInitFontContext (buffer, font)) { - error (SWT.ERROR_NO_HANDLES); - } - int context = buffer [0]; - - /* Values discovering during iteration */ - int ascent = 0; - XFontStruct fontStruct = new XFontStruct (); - int fontListEntry; - int [] fontStructPtr = new int [1]; - int [] fontNamePtr = new int [1]; - - /* Go through each entry in the font list. */ - while ((fontListEntry = OS.XmFontListNextEntry (context)) != 0) { - int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer); - if (buffer [0] == 0) { - /* FontList contains a single font */ - OS.memmove (fontStruct, fontPtr, XFontStruct.sizeof); - if (fontStruct.ascent > ascent) ascent = fontStruct.ascent; - } else { - /* FontList contains a fontSet */ - int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr); - int [] fontStructs = new int [nFonts]; - OS.memmove (fontStructs, fontStructPtr [0], nFonts * 4); - - /* Go through each fontStruct in the font set */ - for (int i=0; i<nFonts; i++) { - OS.memmove (fontStruct, fontStructs[i], XFontStruct.sizeof); - if (fontStruct.ascent > ascent) ascent = fontStruct.ascent; - } - } - } - - OS.XmFontListFreeFontContext (context); - return ascent; -} - -int getFontHeight (int font) { - - /* Create a font context to iterate over each element in the font list */ - int [] buffer = new int [1]; - if (!OS.XmFontListInitFontContext (buffer, font)) { - error (SWT.ERROR_NO_HANDLES); - } - int context = buffer [0]; - - /* Values discovering during iteration */ - int height = 0; - XFontStruct fontStruct = new XFontStruct (); - int fontListEntry; - int [] fontStructPtr = new int [1]; - int [] fontNamePtr = new int [1]; - - /* Go through each entry in the font list. */ - while ((fontListEntry = OS.XmFontListNextEntry (context)) != 0) { - int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer); - if (buffer [0] == 0) { - /* FontList contains a single font */ - OS.memmove (fontStruct, fontPtr, XFontStruct.sizeof); - int fontHeight = fontStruct.ascent + fontStruct.descent; - if (fontHeight > height) height = fontHeight; - } else { - /* FontList contains a fontSet */ - int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr); - int [] fontStructs = new int [nFonts]; - OS.memmove (fontStructs, fontStructPtr [0], nFonts * 4); - - /* Go through each fontStruct in the font set */ - for (int i=0; i<nFonts; i++) { - OS.memmove (fontStruct, fontStructs[i], XFontStruct.sizeof); - int fontHeight = fontStruct.ascent + fontStruct.descent; - if (fontHeight > height) height = fontHeight; - } - } - } - - OS.XmFontListFreeFontContext (context); - return height; -} -//int getFontList () { -// int fontHandle = fontHandle (); -// int [] argList = {OS.XmNfontList, 0}; -// OS.XtGetValues (fontHandle, argList, argList.length / 2); -// if (argList [1] != 0) return argList [1]; -// if (fontList == 0) fontList = defaultFont (); -// return fontList; -//} -/** - * Returns the foreground color that the receiver will use to draw. - * - * @return the receiver's foreground color - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Color getForeground () { - checkWidget(); - return Color.motif_new (display, getXColor (getForegroundPixel ())); -} -int getForegroundPixel () { - int [] argList = {OS.XmNforeground, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -Caret getIMCaret () { - return null; -} -/** - * Returns layout data which is associated with the receiver. - * - * @return the receiver's layout data - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Object getLayoutData () { - checkWidget(); - return layoutData; -} -/** - * Returns a point describing the receiver's location relative - * to its parent (or its display if its parent is null), unless - * the receiver is a shell. In this case, the point is - * relative to the display. - * - * @return the receiver's location - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Point getLocation () { - checkWidget(); - int topHandle = topHandle (); - int [] argList = {OS.XmNx, 0, OS.XmNy, 0}; - OS.XtGetValues (topHandle, argList, argList.length / 2); - return new Point ((short) argList [1], (short) argList [3]); -} -/** - * Returns the receiver's pop up menu if it has one, or null - * if it does not. All controls may optionally have a pop up - * menu that is displayed when the user requests one for - * the control. The sequence of key strokes, button presses - * and/or button releases that are used to request a pop up - * menu is platform specific. - * - * @return the receiver's menu - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Menu getMenu () { - checkWidget(); - return menu; -} -int getMinimumHeight () { - return 0; -} -/** - * Returns the receiver's monitor. - * - * @return the receiver's monitor - * - * @since 3.0 - */ -public Monitor getMonitor () { - checkWidget(); - Monitor [] monitors = display.getMonitors (); - if (monitors.length == 1) return monitors [0]; - int index = -1, value = -1; - Rectangle bounds = getBounds (); - if (this != getShell ()) { - bounds = display.map (this.parent, null, bounds); - } - for (int i=0; i<monitors.length; i++) { - Rectangle rect = bounds.intersection (monitors [i].getBounds ()); - int area = rect.width * rect.height; - if (area > 0 && area > value) { - index = i; - value = area; - } - } - if (index >= 0) return monitors [index]; - int centerX = bounds.x + bounds.width / 2, centerY = bounds.y + bounds.height / 2; - for (int i=0; i<monitors.length; i++) { - Rectangle rect = monitors [i].getBounds (); - int x = centerX < rect.x ? rect.x - centerX : centerX > rect.x + rect.width ? centerX - rect.x - rect.width : 0; - int y = centerY < rect.y ? rect.y - centerY : centerY > rect.y + rect.height ? centerY - rect.y - rect.height : 0; - int distance = x * x + y * y; - if (index == -1 || distance < value) { - index = i; - value = distance; - } - } - return monitors [index]; -} -int getNavigationType () { - int [] argList = {OS.XmNnavigationType, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the receiver's parent, which must be a <code>Composite</code> - * or null when the receiver is a shell that was created with null or - * a display for a parent. - * - * @return the receiver's parent - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Composite getParent () { - checkWidget(); - return parent; -} -Control [] getPath () { - int count = 0; - Shell shell = getShell (); - Control control = this; - while (control != shell) { - count++; - control = control.parent; - } - control = this; - Control [] result = new Control [count]; - while (control != shell) { - result [--count] = control; - control = control.parent; - } - return result; -} -/** - * Returns the region that defines the shape of the control, - * or null if the control has the default shape. - * - * @return the region that defines the shape of the shell (or null) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.4 - */ -public Region getRegion () { - checkWidget (); - return region; -} -/** - * Returns the receiver's shell. For all controls other than - * shells, this simply returns the control's nearest ancestor - * shell. Shells return themselves, even if they are children - * of other shells. - * - * @return the receiver's shell - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getParent - */ -public Shell getShell () { - checkWidget(); - return parent.getShell (); -} -/** - * Returns a point describing the receiver's size. The - * x coordinate of the result is the width of the receiver. - * The y coordinate of the result is the height of the - * receiver. - * - * @return the receiver's size - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Point getSize () { - checkWidget(); - int topHandle = topHandle (); - int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - OS.XtGetValues (topHandle, argList, argList.length / 2); - int borders = argList [5] * 2; - return new Point (argList [1] + borders, argList [3] + borders); -} -/** - * Returns the receiver's tool tip text, or null if it has - * not been set. - * - * @return the receiver's tool tip text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getToolTipText () { - checkWidget(); - return toolTipText; -} -/** - * Returns <code>true</code> if the receiver is visible, and - * <code>false</code> otherwise. - * <p> - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, this method - * may still indicate that it is considered visible even though - * it may not actually be showing. - * </p> - * - * @return the receiver's visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getVisible () { - checkWidget(); - int topHandle = topHandle (); - int [] argList = {OS.XmNmappedWhenManaged, 0}; - OS.XtGetValues (topHandle, argList, argList.length / 2); - return argList [1] != 0; -} -XColor getXColor (int pixel) { - int display = OS.XtDisplay (handle); - if (display == 0) return null; - int [] argList = {OS.XmNcolormap, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int colormap = argList [1]; - if (colormap == 0) return null; - XColor color = new XColor (); - color.pixel = pixel; - OS.XQueryColor (display, colormap, color); - return color; -} -boolean hasFocus () { - return this == display.getFocusControl (); -} -/** - * Returns true if the widget has native IM support - */ -boolean hasIMSupport() { - return false; -} -void hookEvents () { - int windowProc = display.windowProc; - OS.XtAddEventHandler (handle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS); - OS.XtAddEventHandler (handle, OS.ButtonReleaseMask, false, windowProc, BUTTON_RELEASE); - OS.XtAddEventHandler (handle, OS.PointerMotionMask, false, windowProc, POINTER_MOTION); - OS.XtAddEventHandler (handle, OS.EnterWindowMask, false, windowProc, ENTER_WINDOW); - OS.XtAddEventHandler (handle, OS.LeaveWindowMask, false, windowProc, LEAVE_WINDOW); - OS.XtInsertEventHandler (handle, OS.ExposureMask, false, windowProc, EXPOSURE, OS.XtListTail); - OS.XtAddCallback (handle, OS.XmNhelpCallback, windowProc, HELP_CALLBACK); - OS.XtAddEventHandler (handle, OS.KeyPressMask, false, windowProc, KEY_PRESS); - OS.XtAddEventHandler (handle, OS.KeyReleaseMask, false, windowProc, KEY_RELEASE); - OS.XtInsertEventHandler (handle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail); - int focusHandle = focusHandle (); - if (handle != focusHandle) { - OS.XtAddEventHandler (focusHandle, OS.KeyPressMask, false, windowProc, KEY_PRESS); - OS.XtAddEventHandler (focusHandle, OS.KeyReleaseMask, false, windowProc, KEY_RELEASE); - OS.XtInsertEventHandler (focusHandle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail); - } -} -int hoverProc (int id) { - return hoverProc (id, true); -} -int hoverProc (int id, boolean showTip) { - if (showTip) display.showToolTip (handle, toolTipText); - sendMouseEvent (SWT.MouseHover); - return 0; -} -/** - * Invokes platform specific functionality to allocate a new GC handle. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>Control</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @param data the platform specific GC data - * @return the platform specific GC handle - */ -public int internal_new_GC (GCData data) { - checkWidget(); - if (!OS.XtIsRealized (handle)) { - Shell shell = getShell (); - shell.realizeWidget (); - } - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int xWindow = OS.XtWindow (handle); - if (xWindow == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int xGC = OS.XCreateGC (xDisplay, xWindow, 0, null); - if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES); - OS.XSetGraphicsExposures (xDisplay, xGC, false); - if (data != null) { - int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT; - if ((data.style & mask) == 0) { - data.style |= style & (mask | SWT.MIRRORED); - } - data.device = display; - data.display = xDisplay; - data.drawable = xWindow; - XColor foreground = new XColor (); - foreground.pixel = getForegroundPixel (); - data.foreground = foreground; - Control control = findBackgroundControl (); - if (control == null) control = this; - XColor background = new XColor (); - background.pixel = control.getBackgroundPixel (); - data.background = background; - data.backgroundImage = control.backgroundImage; - data.font = font; - int [] argList = {OS.XmNcolormap, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - data.colormap = argList [1]; - } - return xGC; -} -/** - * Invokes platform specific functionality to dispose a GC handle. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>Control</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @param hDC the platform specific GC handle - * @param data the platform specific GC data - */ -public void internal_dispose_GC (int xGC, GCData data) { - checkWidget (); - int xDisplay = 0; - if (data != null) xDisplay = data.display; - if (xDisplay == 0 && handle != 0) xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) SWT.error(SWT.ERROR_NO_HANDLES); - OS.XFreeGC (xDisplay, xGC); -} -/** - * Returns <code>true</code> if the receiver is enabled and all - * ancestors up to and including the receiver's nearest ancestor - * shell are enabled. Otherwise, <code>false</code> is returned. - * A disabled control is typically not selectable from the user - * interface and draws with an inactive or "grayed" look. - * - * @return the receiver's enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getEnabled - */ -public boolean isEnabled () { - checkWidget(); - return getEnabled () && parent.isEnabled (); -} -boolean isFocusAncestor (Control control) { - while (control != null && control != this && !(control instanceof Shell)) { - control = control.parent; - } - return control == this; -} -/** - * Returns <code>true</code> if the receiver has the user-interface - * focus, and <code>false</code> otherwise. - * - * @return the receiver's focus state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean isFocusControl () { - checkWidget(); - return hasFocus (); -} -/** - * Returns <code>true</code> if the underlying operating - * system supports this reparenting, otherwise <code>false</code> - * - * @return <code>true</code> if the widget can be reparented, otherwise <code>false</code> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean isReparentable () { - checkWidget(); - return false; -} -boolean isShowing () { - /* - * This is not complete. Need to check if the - * widget is obscurred by a parent or sibling. - */ - if (!isVisible ()) return false; - Control control = this; - while (control != null) { - Point size = control.getSize (); - if (size.x == 1 || size.y == 1) { - return false; - } - control = control.parent; - } - return true; -} -boolean isTabGroup () { - Control [] tabList = parent._getTabList (); - if (tabList != null) { - for (int i=0; i<tabList.length; i++) { - if (tabList [i] == this) return true; - } - } - int code = traversalCode (0, null); - if ((code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) != 0) return false; - return (code & (SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_TAB_NEXT)) != 0; -} -boolean isTabItem () { - Control [] tabList = parent._getTabList (); - if (tabList != null) { - for (int i=0; i<tabList.length; i++) { - if (tabList [i] == this) return false; - } - } - int code = traversalCode (0, null); - return (code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) != 0; -} -/** - * Returns <code>true</code> if the receiver is visible and all - * ancestors up to and including the receiver's nearest ancestor - * shell are visible. Otherwise, <code>false</code> is returned. - * - * @return the receiver's visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getVisible - */ -public boolean isVisible () { - checkWidget(); - return getVisible () && parent.isVisible (); -} -void manageChildren () { - OS.XtSetMappedWhenManaged (handle, false); - OS.XtManageChild (handle); - int [] argList3 = {OS.XmNborderWidth, 0}; - OS.XtGetValues (handle, argList3, argList3.length / 2); - OS.XtResizeWidget (handle, 1, 1, argList3 [1]); - OS.XtSetMappedWhenManaged (handle, true); -} -void markLayout (boolean changed, boolean all) { - /* Do nothing */ -} -Decorations menuShell () { - return parent.menuShell (); -} -boolean mnemonicHit (char key) { - return false; -} -boolean mnemonicMatch (char key) { - return false; -} -/** - * Moves the receiver above the specified control in the - * drawing order. If the argument is null, then the receiver - * is moved to the top of the drawing order. The control at - * the top of the drawing order will not be covered by other - * controls even if they occupy intersecting areas. - * - * @param control the sibling control (or null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see Control#moveBelow - * @see Composite#getChildren - */ -public void moveAbove (Control control) { - checkWidget(); - if (control != null) { - if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT); - if (parent != control.parent) return; - } - setZOrder (control, true); -} -/** - * Moves the receiver below the specified control in the - * drawing order. If the argument is null, then the receiver - * is moved to the bottom of the drawing order. The control at - * the bottom of the drawing order will be covered by all other - * controls which occupy intersecting areas. - * - * @param control the sibling control (or null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see Control#moveAbove - * @see Composite#getChildren - */ -public void moveBelow (Control control) { - checkWidget(); - if (control != null) { - if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT); - if (parent != control.parent) return; - } - setZOrder (control, false); -} -void overrideTranslations () { - OS.XtOverrideTranslations (handle, display.tabTranslations); - OS.XtOverrideTranslations (handle, display.arrowTranslations); - int focusHandle = focusHandle (); - if (handle != focusHandle) { - OS.XtOverrideTranslations (focusHandle, display.tabTranslations); - OS.XtOverrideTranslations (focusHandle, display.arrowTranslations); - } -} -/** - * Causes the receiver to be resized to its preferred size. - * For a composite, this involves computing the preferred size - * from its layout, if there is one. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #computeSize(int, int, boolean) - */ -public void pack () { - checkWidget(); - pack (true); -} -/** - * Causes the receiver to be resized to its preferred size. - * For a composite, this involves computing the preferred size - * from its layout, if there is one. - * <p> - * If the changed flag is <code>true</code>, it indicates that the receiver's - * <em>contents</em> have changed, therefore any caches that a layout manager - * containing the control may have been keeping need to be flushed. When the - * control is resized, the changed flag will be <code>false</code>, so layout - * manager caches can be retained. - * </p> - * - * @param changed whether or not the receiver's contents have changed - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #computeSize(int, int, boolean) - */ -public void pack (boolean changed) { - checkWidget(); - setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed)); -} -void propagateChildren (boolean enabled) { - propagateWidget (enabled); -} -void propagateWidget (boolean enabled) { - int xCursor = enabled && cursor != null ? cursor.handle : OS.None; - propagateHandle (enabled, handle, xCursor); -} -/** - * Prints the receiver and all children. - * - * @param gc the gc where the drawing occurs - * @return <code>true</code> if the operation was successful and <code>false</code> otherwise - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the gc is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.4 - */ -public boolean print (GC gc) { - checkWidget (); - if (gc == null) error (SWT.ERROR_NULL_ARGUMENT); - if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - return false; -} -void realizeChildren () { - if (isEnabled ()) { - if (cursor != null) { - int xWindow = OS.XtWindow (handle); - if (xWindow == 0) return; - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - OS.XDefineCursor (xDisplay, xWindow, cursor.handle); - OS.XFlush (xDisplay); - } - } else { - propagateWidget (false); - } - if ((state & PARENT_BACKGROUND) != 0) { - setParentBackground (); - } -} -/** - * Causes the entire bounds of the receiver to be marked - * as needing to be redrawn. The next time a paint request - * is processed, the control will be completely painted, - * including the background. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #update() - * @see PaintListener - * @see SWT#Paint - * @see SWT#NO_BACKGROUND - * @see SWT#NO_REDRAW_RESIZE - * @see SWT#NO_MERGE_PAINTS - * @see SWT#DOUBLE_BUFFERED - */ -public void redraw () { - checkWidget(); - redrawWidget (0, 0, 0, 0, true, false, false); -} -/** - * Causes the rectangular area of the receiver specified by - * the arguments to be marked as needing to be redrawn. - * The next time a paint request is processed, that area of - * the receiver will be painted, including the background. - * If the <code>all</code> flag is <code>true</code>, any - * children of the receiver which intersect with the specified - * area will also paint their intersecting areas. If the - * <code>all</code> flag is <code>false</code>, the children - * will not be painted. - * - * @param x the x coordinate of the area to draw - * @param y the y coordinate of the area to draw - * @param width the width of the area to draw - * @param height the height of the area to draw - * @param all <code>true</code> if children should redraw, and <code>false</code> otherwise - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #update() - * @see PaintListener - * @see SWT#Paint - * @see SWT#NO_BACKGROUND - * @see SWT#NO_REDRAW_RESIZE - * @see SWT#NO_MERGE_PAINTS - * @see SWT#DOUBLE_BUFFERED - */ -public void redraw (int x, int y, int width, int height, boolean all) { - checkWidget (); - if (width > 0 && height > 0) { - redrawWidget (x, y, width, height, false, all, false); - } -} -void redrawChildren () { -} -void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean allChildren, boolean trim) { - redrawHandle (x, y, width, height, redrawAll, handle); -} -void releaseHandle () { - super.releaseHandle (); - parent = null; -} -void releaseParent () { - parent.removeControl (this); -} -void releaseWidget () { - super.releaseWidget (); - /* - * Restore the default font for the widget in case the - * application disposes the widget font in the dispose - * callback. If a font is disposed while it is still - * in use in the widget, Motif GP's. - */ - int fontList = defaultFont ().handle; - if (font.handle != fontList) { - int fontHandle = fontHandle (); - int [] argList2 = {OS.XmNfontList, fontList}; - OS.XtSetValues (fontHandle, argList2, argList2.length / 2); - OS.XmImSetValues (fontHandle, argList2, argList2.length / 2); - } - display.releaseToolTipHandle (handle); - toolTipText = null; - if (menu != null && !menu.isDisposed ()) { - menu.dispose (); - } - menu = null; - cursor = null; - if (!hasIMSupport()) { - OS.XmImUnregister (handle); - int focusHandle = focusHandle (); - if (handle != focusHandle) { - OS.XmImUnregister (focusHandle); - } - } - layoutData = null; - region = null; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is moved or resized. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ControlListener - * @see #addControlListener - */ -public void removeControlListener (ControlListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Move, listener); - eventTable.unhook (SWT.Resize, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when a drag gesture occurs. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see DragDetectListener - * @see #addDragDetectListener - * - * @since 3.3 - */ -public void removeDragDetectListener(DragDetectListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.DragDetect, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the control gains or loses focus. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see FocusListener - * @see #addFocusListener - */ -public void removeFocusListener(FocusListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.FocusIn, listener); - eventTable.unhook(SWT.FocusOut, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the help events are generated for the control. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see HelpListener - * @see #addHelpListener - */ -public void removeHelpListener (HelpListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Help, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when keys are pressed and released on the system keyboard. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see KeyListener - * @see #addKeyListener - */ -public void removeKeyListener(KeyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.KeyUp, listener); - eventTable.unhook(SWT.KeyDown, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the platform-specific context menu trigger has - * occurred. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see MenuDetectListener - * @see #addMenuDetectListener - * - * @since 3.3 - */ -public void removeMenuDetectListener (MenuDetectListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.MenuDetect, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when mouse buttons are pressed and released. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see MouseListener - * @see #addMouseListener - */ -public void removeMouseListener(MouseListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.MouseDown, listener); - eventTable.unhook(SWT.MouseUp, listener); - eventTable.unhook(SWT.MouseDoubleClick, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the mouse moves. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see MouseMoveListener - * @see #addMouseMoveListener - */ -public void removeMouseMoveListener(MouseMoveListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.MouseMove, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the mouse passes or hovers over controls. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see MouseTrackListener - * @see #addMouseTrackListener - */ -public void removeMouseTrackListener(MouseTrackListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.MouseEnter, listener); - eventTable.unhook (SWT.MouseExit, listener); - eventTable.unhook (SWT.MouseHover, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the mouse wheel is scrolled. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see MouseWheelListener - * @see #addMouseWheelListener - * - * @since 3.3 - */ -public void removeMouseWheelListener (MouseWheelListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.MouseWheel, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver needs to be painted. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see PaintListener - * @see #addPaintListener - */ -public void removePaintListener(PaintListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.Paint, listener); -}/** - * Removes the listener from the collection of listeners who will - * be notified when traversal events occur. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see TraverseListener - * @see #addTraverseListener - */ -public void removeTraverseListener(TraverseListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Traverse, listener); -} -boolean sendDragEvent (int button, int stateMask, int x, int y, boolean isStateMask) { - Event event = new Event (); - event.button = button; - event.x = x; - event.y = y; - if (isStateMask) { - event.stateMask = stateMask; - } else { - setInputState (event, stateMask); - } - postEvent (SWT.DragDetect, event); - if (isDisposed ()) return false; - return event.doit; -} -void sendFocusEvent (int type) { - Display display = this.display; - if (type == SWT.FocusIn) { - Control focusedCombo = display.focusedCombo; - display.focusedCombo = null; - if (focusedCombo != null && focusedCombo != this && !focusedCombo.isDisposed ()) { - display.sendFocusEvent (focusedCombo, SWT.FocusOut); - } - } - display.sendFocusEvent (this, type); -} -void sendHelpEvent (int callData) { - Control control = this; - while (control != null) { - if (control.hooks (SWT.Help)) { - control.postEvent (SWT.Help); - return; - } - control = control.parent; - } -} -boolean sendMouseEvent (int type) { - if (!hooks (type) && !filters (type)) return true; - int xDisplay = OS.XtDisplay (handle), xWindow = OS.XtWindow (handle); - int [] windowX = new int [1], windowY = new int [1], mask = new int [1], unused = new int [1]; - OS.XQueryPointer (xDisplay, xWindow, unused, unused, unused, unused, windowX, windowY, mask); - return sendMouseEvent (type, 0, 0, 0, false, 0, windowX [0], windowY [0], mask [0]); -} -boolean sendMouseEvent (int type, int button, int count, int detail, boolean send, int time, int x, int y, int state) { -// if (!hooks (type) && !filters (type)) return true; - Event event = new Event (); - event.time = time; - event.button = button; - event.count = count; - event.detail = detail; - event.x = x; - event.y = y; - setInputState (event, state); - if (send) { - sendEvent (type, event); - if (isDisposed ()) return false; - } else { - postEvent (type, event); - } - return event.doit; -} -boolean sendMouseEvent (int type, XButtonEvent xEvent) { - int button = xEvent.button; - switch (button) { - case 4: - case 5: - /* Use MouseDown button 4 and 5 to emulated MouseWheel */ - if (type != SWT.MouseDown) return true; - type = SWT.MouseWheel; - if (!hooks (type) && !filters (type)) return true; - short [] x_root = new short [1], y_root = new short [1]; - OS.XtTranslateCoords (handle, (short) 0, (short) 0, x_root, y_root); - int x = xEvent.x_root - x_root [0], y = xEvent.y_root - y_root [0]; - int count = button == 4 ? 3 : -3; - Control control = this; - Shell shell = getShell (); - do { - if (!control.sendMouseEvent (type, 0, count, SWT.SCROLL_LINE, true, xEvent.time, x, y, xEvent.state)) { - return false; - } - if (control == shell) break; - control = control.parent; - OS.XtTranslateCoords (control.handle, (short) 0, (short) 0, x_root, y_root); - x = xEvent.x_root - x_root [0]; - y = xEvent.y_root - y_root [0]; - } while (control != null); - return true; - case 6: - button = 4; - break; - case 7: - button = 5; - break; - } - if (!hooks (type) && !filters (type)) return true; - short [] x_root = new short [1], y_root = new short [1]; - OS.XtTranslateCoords (handle, (short) 0, (short) 0, x_root, y_root); - int x = xEvent.x_root - x_root [0], y = xEvent.y_root - y_root [0]; - return sendMouseEvent (type, button, display.clickCount, 0, false, xEvent.time, x, y, xEvent.state); -} -boolean sendMouseEvent (int type, XCrossingEvent xEvent) { - if (!hooks (type) && !filters (type)) return true; - short [] x_root = new short [1], y_root = new short [1]; - OS.XtTranslateCoords (handle, (short) 0, (short) 0, x_root, y_root); - int x = xEvent.x_root - x_root [0], y = xEvent.y_root - y_root [0]; - return sendMouseEvent (type, 0, 0, 0, false, xEvent.time, x, y, xEvent.state); -} -boolean sendMouseEvent (int type, XMotionEvent xEvent) { - if (!hooks (type) && !filters (type)) return true; - short [] x_root = new short [1], y_root = new short [1]; - OS.XtTranslateCoords (handle, (short) 0, (short) 0, x_root, y_root); - int x = xEvent.x_root - x_root [0], y = xEvent.y_root - y_root [0]; - return sendMouseEvent (type, 0, 0, 0, false, xEvent.time, x, y, xEvent.state); -} -void setBackground () { - if ((state & PARENT_BACKGROUND) != 0 && (state & BACKGROUND) == 0 && backgroundImage == null) { - setParentBackground (); - } else { - if (backgroundImage != null) { - int [] argList = {OS.XmNbackgroundPixmap, backgroundImage.pixmap}; - OS.XtSetValues (handle, argList, argList.length / 2); - } else { - /* Ensure the resource value changes, otherwise XtSetValues() does nothing */ - int pixel = getBackgroundPixel (); - setBackgroundPixel (pixel + 1); - setBackgroundPixel (pixel); - } - } - redrawWidget (0, 0, 0, 0, true, false, false); -} -/** - * Sets the receiver's background color to the color specified - * by the argument, or to the default system color for the control - * if the argument is null. - * <p> - * Note: This operation is a hint and may be overridden by the platform. - * For example, on Windows the background of a Button cannot be changed. - * </p> - * @param color the new color (or null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setBackground (Color color) { - checkWidget(); - if (color == null) { - state &= ~BACKGROUND; - setBackgroundPixel (defaultBackground ()); - } else { - if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - state |= BACKGROUND; - setBackgroundPixel (color.handle.pixel); - } - if ((state & PARENT_BACKGROUND) != 0 && (state & BACKGROUND) == 0 && backgroundImage == null) { - setParentBackground (); - redrawWidget (0, 0, 0, 0, true, false, false); - } - redrawChildren (); -} -/** - * Sets the receiver's background image to the image specified - * by the argument, or to the default system color for the control - * if the argument is null. The background image is tiled to fill - * the available space. - * <p> - * Note: This operation is a hint and may be overridden by the platform. - * For example, on Windows the background of a Button cannot be changed. - * </p> - * @param image the new image (or null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> - * <li>ERROR_INVALID_ARGUMENT - if the argument is not a bitmap</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.2 - */ -public void setBackgroundImage (Image image) { - checkWidget (); - if (image != null && image.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (image == backgroundImage) return; - this.backgroundImage = image; - int pixmap = image != null ? image.pixmap : OS.XmUNSPECIFIED_PIXMAP; - int [] argList = {OS.XmNbackgroundPixmap, pixmap}; - OS.XtSetValues (handle, argList, argList.length / 2); - if ((state & PARENT_BACKGROUND) != 0 && (state & BACKGROUND) == 0 && backgroundImage == null) { - setParentBackground (); - redrawWidget (0, 0, 0, 0, true, false, false); - } - redrawChildren (); -} -void setBackgroundPixel (int pixel) { - int [] argList = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - OS.XmChangeColor (handle, pixel); - OS.XtSetValues (handle, argList, argList.length / 2); -} -boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - int topHandle = topHandle (); - if (move && resize) { - int [] argList = { - OS.XmNx, 0, /* 1 */ - OS.XmNy, 0, /* 3 */ - OS.XmNwidth, 0, /* 5 */ - OS.XmNheight, 0, /* 7 */ - OS.XmNborderWidth, 0, /* 9 */ - }; - OS.XtGetValues (topHandle, argList, argList.length / 2); - /* - * Feature in Motif. Motif will not allow a window - * to have a zero width or zero height. The fix is - * to ensure these values are never zero. - */ - width = Math.max (width - (argList [9] * 2), 1); - height = Math.max (height - (argList [9] * 2), 1); - boolean sameOrigin = (x == (short) argList [1]) && (y == (short) argList [3]); - boolean sameExtent = (width == argList [5]) && (height == argList [7]); - if (sameOrigin && sameExtent) return false; - if (redrawWindow != 0) { - int xDisplay = OS.XtDisplay (handle); - OS.XResizeWindow (xDisplay, redrawWindow, width, height); - } - OS.XtConfigureWidget (topHandle, x, y, width, height, argList [9]); - updateIM (); - if (!sameOrigin) { - Control control = findBackgroundControl (); - if (control != null && control.backgroundImage != null) { - if (isVisible ()) redrawWidget (0, 0, 0, 0, true, true, true); - } - sendEvent (SWT.Move); - } - if (!sameExtent) sendEvent (SWT.Resize); - return true; - } - if (move) { - int [] argList = {OS.XmNx, 0, OS.XmNy, 0}; - OS.XtGetValues (topHandle, argList, argList.length / 2); - if (x == (short) argList [1] && y == (short) argList [3]) return false; - OS.XtMoveWidget (topHandle, x, y); - Control control = findBackgroundControl (); - if (control != null && control.backgroundImage != null) { - if (isVisible ()) redrawWidget (0, 0, 0, 0, true, true, true); - } - sendEvent (SWT.Move); - return true; - } - if (resize) { - int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - OS.XtGetValues (topHandle, argList, argList.length / 2); - /* - * Feature in Motif. Motif will not allow a window - * to have a zero width or zero height. The fix is - * to ensure these values are never zero. - */ - width = Math.max (width - (argList [5] * 2), 1); - height = Math.max (height - (argList [5] * 2), 1); - if (width == argList [1] && height == argList [3]) return false; - if (redrawWindow != 0) { - int xDisplay = OS.XtDisplay (handle); - OS.XResizeWindow (xDisplay, redrawWindow, width, height); - } - OS.XtResizeWidget (topHandle, width, height, argList [5]); - updateIM (); - sendEvent (SWT.Resize); - return true; - } - return false; -} -/** - * Sets the receiver's size and location to the rectangular - * area specified by the arguments. The <code>x</code> and - * <code>y</code> arguments are relative to the receiver's - * parent (or its display if its parent is null), unless - * the receiver is a shell. In this case, the <code>x</code> - * and <code>y</code> arguments are relative to the display. - * <p> - * Note: Attempting to set the width or height of the - * receiver to a negative number will cause that - * value to be set to zero instead. - * </p> - * - * @param x the new x coordinate for the receiver - * @param y the new y coordinate for the receiver - * @param width the new width for the receiver - * @param height the new height for the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setBounds (int x, int y, int width, int height) { - checkWidget(); - setBounds (x, y, Math.max (0, width), Math.max (0, height), true, true); -} -/** - * Sets the receiver's size and location to the rectangular - * area specified by the argument. The <code>x</code> and - * <code>y</code> fields of the rectangle are relative to - * the receiver's parent (or its display if its parent is null). - * <p> - * Note: Attempting to set the width or height of the - * receiver to a negative number will cause that - * value to be set to zero instead. - * </p> - * - * @param rect the new bounds for the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setBounds (Rectangle rect) { - checkWidget (); - if (rect == null) error (SWT.ERROR_NULL_ARGUMENT); - setBounds (rect.x, rect.y, rect.width, rect.height); -} -/** - * If the argument is <code>true</code>, causes the receiver to have - * all mouse events delivered to it until the method is called with - * <code>false</code> as the argument. Note that on some platforms, - * a mouse button must currently be down for capture to be assigned. - * - * @param capture <code>true</code> to capture the mouse, and <code>false</code> to release it - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setCapture (boolean capture) { - checkWidget(); - int display = OS.XtDisplay (handle); - if (display == 0) return; - if (capture) { - int window = OS.XtWindow (handle); - if (window == 0) return; - OS.XGrabPointer ( - display, - window, - 0, - OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask, - OS.GrabModeAsync, - OS.GrabModeAsync, - OS.None, - OS.None, - OS.CurrentTime); - } else { - OS.XUngrabPointer (display, OS.CurrentTime); - } -} -/** - * Sets the receiver's cursor to the cursor specified by the - * argument, or to the default cursor for that kind of control - * if the argument is null. - * <p> - * When the mouse pointer passes over a control its appearance - * is changed to match the control's cursor. - * </p> - * - * @param cursor the new cursor (or null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setCursor (Cursor cursor) { - checkWidget(); - if (cursor != null && cursor.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - this.cursor = cursor; - if (!isEnabled ()) { - if (this != getShell ()) return; - } - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int xWindow = OS.XtWindow (handle); - if (xWindow == 0) return; - if (cursor == null) { - OS.XUndefineCursor (xDisplay, xWindow); - } else { - if (cursor.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - OS.XDefineCursor (xDisplay, xWindow, cursor.handle); - } - OS.XFlush (xDisplay); -} -/** - * Sets the receiver's drag detect state. If the argument is - * <code>true</code>, the receiver will detect drag gestures, - * otherwise these gestures will be ignored. - * - * @param dragDetect the new drag detect state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.3 - */ -public void setDragDetect (boolean dragDetect) { - checkWidget (); - if (dragDetect) { - state |= DRAG_DETECT; - } else { - state &= ~DRAG_DETECT; - } -} -/** - * Enables the receiver if the argument is <code>true</code>, - * and disables it otherwise. A disabled control is typically - * not selectable from the user interface and draws with an - * inactive or "grayed" look. - * - * @param enabled the new enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setEnabled (boolean enabled) { - checkWidget(); - if (enabled == getEnabled ()) return; - Control control = null; - boolean fixFocus = false; - if (!enabled) { - if (display.focusEvent != SWT.FocusOut) { - control = display.getFocusControl (); - fixFocus = isFocusAncestor (control); - } - } - enableWidget (enabled); - if (fixFocus) fixFocus (control); - if (!enabled || (isEnabled () && enabled)) { - propagateChildren (enabled); - } -} -/** - * Causes the receiver to have the <em>keyboard focus</em>, - * such that all keyboard events will be delivered to it. Focus - * reassignment will respect applicable platform constraints. - * - * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #forceFocus - */ -public boolean setFocus () { - checkWidget(); - if ((style & SWT.NO_FOCUS) != 0) return false; - return forceFocus (); -} -/** - * Sets the font that the receiver will use to paint textual information - * to the font specified by the argument, or to the default font for that - * kind of control if the argument is null. - * - * @param font the new font (or null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setFont (Font font) { - checkWidget(); - if (font == null) font = defaultFont (); - if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - this.font = font; - - /* - * Feature in Motif. Setting the font in a widget - * can cause the widget to automatically resize in - * the OS. This behavior is unwanted. The fix is - * to force the widget to resize to original size - * after every font change. - */ - int [] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - - /* Set the font list */ - int fontHandle = fontHandle (); - int [] argList2 = {OS.XmNfontList, font.handle}; - OS.XtSetValues (fontHandle, argList2, argList2.length / 2); - updateIM (); - - /* - * Feature in Motif. When XtSetValues() is used to restore the width and - * height of the widget, the new width and height are sometimes ignored. - * The fix is to use XtResizeWidget(). - */ - OS.XtResizeWidget (handle, argList1 [1], argList1 [3], argList1 [5]); -} -/** - * Sets the receiver's foreground color to the color specified - * by the argument, or to the default system color for the control - * if the argument is null. - * <p> - * Note: This operation is a hint and may be overridden by the platform. - * </p> - * @param color the new color (or null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setForeground (Color color) { - checkWidget(); - if (color == null) { - state &= ~FOREGROUND; - setForegroundPixel (defaultForeground ()); - } else { - if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - state |= FOREGROUND; - setForegroundPixel (color.handle.pixel); - } -} -void setForegroundPixel (int pixel) { - int [] argList = {OS.XmNforeground, pixel}; - OS.XtSetValues (handle, argList, argList.length / 2); -} -/** - * Sets the layout data associated with the receiver to the argument. - * - * @param layoutData the new layout data for the receiver. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setLayoutData (Object layoutData) { - checkWidget(); - this.layoutData = layoutData; -} -/** - * Sets the receiver's location to the point specified by - * the arguments which are relative to the receiver's - * parent (or its display if its parent is null), unless - * the receiver is a shell. In this case, the point is - * relative to the display. - * - * @param x the new x coordinate for the receiver - * @param y the new y coordinate for the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setLocation (int x, int y) { - checkWidget(); - setBounds (x, y, 0, 0, true, false); -} -/** - * Sets the receiver's location to the point specified by - * the arguments which are relative to the receiver's - * parent (or its display if its parent is null), unless - * the receiver is a shell. In this case, the point is - * relative to the display. - * - * @param location the new location for the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setLocation (Point location) { - checkWidget (); - if (location == null) error (SWT.ERROR_NULL_ARGUMENT); - setBounds (location.x, location.y, 0, 0, true, false); -} -/** - * Sets the receiver's pop up menu to the argument. - * All controls may optionally have a pop up - * menu that is displayed when the user requests one for - * the control. The sequence of key strokes, button presses - * and/or button releases that are used to request a pop up - * menu is platform specific. - * <p> - * Note: Disposing of a control that has a pop up menu will - * dispose of the menu. To avoid this behavior, set the - * menu to null before the control is disposed. - * </p> - * - * @param menu the new pop up menu - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu</li> - * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li> - * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMenu (Menu menu) { - checkWidget(); - if (menu != null) { - if (menu.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if ((menu.style & SWT.POP_UP) == 0) { - error (SWT.ERROR_MENU_NOT_POP_UP); - } - if (menu.parent != menuShell ()) { - error (SWT.ERROR_INVALID_PARENT); - } - } - this.menu = menu; -} -/** - * Changes the parent of the widget to be the one provided if - * the underlying operating system supports this feature. - * Returns <code>true</code> if the parent is successfully changed. - * - * @param parent the new parent for the control. - * @return <code>true</code> if the parent is changed and <code>false</code> otherwise. - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> - * <li>ERROR_NULL_ARGUMENT - if the parent is <code>null</code></li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean setParent (Composite parent) { - checkWidget(); - if (parent.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - return false; -} -void setParentBackground () { - setParentBackground (handle); -} -void setParentBackground (int widget) { - int xDisplay = OS.XtDisplay (widget); - if (xDisplay == 0) return; - int xWindow = OS.XtWindow (widget); - if (xWindow == 0) return; - OS.XSetWindowBackgroundPixmap (xDisplay, xWindow, OS.ParentRelative); -} -void setParentTraversal () { - /* - * When the parent was created with NO_FOCUS, XmNtraversalOn was - * set to false disallowing focus in the parent and all children. - * In order to allow the new child to take focus like other platforms, - * set XmNtraversalOn to true in the parent. - */ - if ((parent.style & SWT.NO_FOCUS) != 0) { - int parentHandle = parent.handle; - int [] argList = {OS.XmNtraversalOn, 0}; - OS.XtGetValues (parentHandle, argList, argList.length / 2); - if (argList [1] == 0) { - argList [1] = 1; - OS.XtSetValues (parentHandle, argList, argList.length / 2); - parent.overrideTranslations (); - } - } -} -boolean setRadioSelection (boolean value) { - return false; -} -/** - * If the argument is <code>false</code>, causes subsequent drawing - * operations in the receiver to be ignored. No drawing of any kind - * can occur in the receiver until the flag is set to true. - * Graphics operations that occurred while the flag was - * <code>false</code> are lost. When the flag is set to <code>true</code>, - * the entire widget is marked as needing to be redrawn. Nested calls - * to this method are stacked. - * <p> - * Note: This operation is a hint and may not be supported on some - * platforms or for some widgets. - * </p> - * - * @param redraw the new redraw state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #redraw(int, int, int, int, boolean) - * @see #update() - */ -public void setRedraw (boolean redraw) { - checkWidget(); - if (redraw) { - if (--drawCount == 0) { - if (redrawWindow != 0) { - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int xWindow = OS.XtWindow (handle); - if (xWindow == 0) return; - OS.XDestroyWindow (xDisplay, redrawWindow); - OS.XSelectInput (xDisplay, xWindow, OS.XtBuildEventMask (handle)); - redrawWindow = 0; - } - } - } else { - if (drawCount++ == 0) { - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int xWindow = OS.XtWindow (handle); - if (xWindow == 0) return; - Rectangle rect = getBounds(); - XSetWindowAttributes attributes = new XSetWindowAttributes (); - attributes.background_pixmap = OS.None; - attributes.event_mask = OS.ExposureMask; - int mask = OS.CWDontPropagate | OS.CWEventMask | OS.CWBackPixmap; - redrawWindow = OS.XCreateWindow (xDisplay, xWindow, 0, 0, rect.width, rect.height, - 0,OS.CopyFromParent, OS.CopyFromParent, OS.CopyFromParent, mask, attributes); - if (redrawWindow != 0) { - int mouseMask = OS.ButtonPressMask | OS.ButtonReleaseMask | - OS.LeaveWindowMask | OS.PointerMotionMask | - OS.PointerMotionMask | OS.PointerMotionHintMask | - OS.ButtonMotionMask | OS.Button1MotionMask | OS.Button2MotionMask | - OS.Button3MotionMask | OS.Button4MotionMask | OS.Button5MotionMask; - OS.XSelectInput (xDisplay, xWindow, OS.XtBuildEventMask (handle) & ~mouseMask); - OS.XRaiseWindow (xDisplay, redrawWindow); - OS.XMapWindow (xDisplay, redrawWindow); - } - } - } -} -/** - * Sets the shape of the control to the region specified - * by the argument. When the argument is null, the - * default shape of the control is restored. - * - * @param region the region that defines the shape of the control (or null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.4 - */ -public void setRegion (Region region) { - checkWidget (); - if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - int topHandle = topHandle (); - Shell shell = getShell (); - if (!OS.XtIsRealized (topHandle)) shell.realizeWidget (); - int xDisplay = OS.XtDisplay (topHandle); - if (xDisplay == 0) return; - int xWindow = OS.XtWindow (topHandle); - if (xWindow == 0) return; - if (region != null) { - OS.XShapeCombineRegion (xDisplay, xWindow, OS.ShapeBounding, 0, 0, region.handle, OS.ShapeSet); - } else { - OS.XShapeCombineMask (xDisplay, xWindow, OS.ShapeBounding, 0, 0, 0, OS.ShapeSet); - } - this.region = region; -} -boolean setTabGroupFocus (boolean next) { - return setTabItemFocus (next); -} -boolean setTabItemFocus (boolean next) { - if (!isShowing ()) return false; - return forceFocus (); -} -/** - * Sets the receiver's size to the point specified by the arguments. - * <p> - * Note: Attempting to set the width or height of the - * receiver to a negative number will cause that - * value to be set to zero instead. - * </p> - * - * @param width the new width for the receiver - * @param height the new height for the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSize (int width, int height) { - checkWidget(); - setBounds (0, 0, Math.max (0, width), Math.max (0, height), false, true); -} -/** - * Sets the receiver's size to the point specified by the argument. - * <p> - * Note: Attempting to set the width or height of the - * receiver to a negative number will cause them to be - * set to zero instead. - * </p> - * - * @param size the new size for the receiver - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the point is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSize (Point size) { - checkWidget(); - if (size == null) error (SWT.ERROR_NULL_ARGUMENT); - setBounds (0, 0, size.x, size.y, false, true); -} -/** - * Sets the receiver's tool tip text to the argument, which - * may be null indicating that the default tool tip for the - * control will be shown. For a control that has a default - * tool tip, such as the Tree control on Windows, setting - * the tool tip text to an empty string replaces the default, - * causing no tool tip text to be shown. - * <p> - * The mnemonic indicator (character '&') is not displayed in a tool tip. - * To display a single '&' in the tool tip, the character '&' can be - * escaped by doubling it in the string. - * </p> - * - * @param string the new tool tip text (or null) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setToolTipText (String string) { - checkWidget(); - display.setToolTipText (handle, toolTipText = string); -} -/** - * Marks the receiver as visible if the argument is <code>true</code>, - * and marks it invisible otherwise. - * <p> - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, marking - * it visible may not actually cause it to be displayed. - * </p> - * - * @param visible the new visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setVisible (boolean visible) { - checkWidget(); - int topHandle = topHandle (); - int [] argList = {OS.XmNmappedWhenManaged, 0}; - OS.XtGetValues (topHandle, argList, argList.length / 2); - if ((argList [1] != 0) == visible) return; - Control control = null; - boolean fixFocus = false; - if (!visible) { - if (display.focusEvent != SWT.FocusOut) { - control = display.getFocusControl (); - fixFocus = isFocusAncestor (control); - } - } - OS.XtSetMappedWhenManaged (topHandle, visible); - if (fixFocus) fixFocus (control); - /* - * It is possible (but unlikely) that application code could - * have disposed the widget in the FocusOut event that is - * triggered by invoking fixFocus() if the widget being hidden - * has focus. If this happens, just return; - */ - if (isDisposed ()) return; - sendEvent (visible ? SWT.Show : SWT.Hide); -} -void setZOrder (Control control, boolean above) { - setZOrder (control, above, true); -} -void setZOrder (Control control, boolean above, boolean fixChildren) { - /* - * Feature in Xt. We cannot use XtMakeGeometryRequest() to - * restack widgets because this call can fail under certain - * conditions. For example, XtMakeGeometryRequest() answers - * XtGeometryNo when attempting to bring a child widget that - * is larger than the parent widget to the front. The fix - * is to use X calls instead. - */ - int topHandle1 = topHandle (); - int display = OS.XtDisplay (topHandle1); - if (display == 0) return; - if (!OS.XtIsRealized (topHandle1)) { - Shell shell = this.getShell (); - shell.realizeWidget (); - } - int window1 = OS.XtWindow (topHandle1); - if (window1 == 0) return; - int redrawWindow = fixChildren ? parent.redrawWindow : 0; - if (control == null && (!above || redrawWindow == 0)) { - if (above) { - OS.XRaiseWindow (display, window1); - if (fixChildren) parent.moveAbove (topHandle1, 0); - } else { - OS.XLowerWindow (display, window1); - if (fixChildren) parent.moveBelow (topHandle1, 0); - } - return; - } - int window2, topHandle2 = 0; - if (control != null) { - topHandle2 = control.topHandle (); - if (display != OS.XtDisplay (topHandle2)) return; - if (!OS.XtIsRealized (topHandle2)) { - Shell shell = control.getShell (); - shell.realizeWidget (); - } - window2 = OS.XtWindow (topHandle2); - } else { - window2 = redrawWindow; - } - if (window2 == 0) return; - XWindowChanges struct = new XWindowChanges (); - struct.sibling = window2; - struct.stack_mode = above ? OS.Above : OS.Below; - if (window2 == redrawWindow) struct.stack_mode = OS.Below; - /* - * Feature in X. If the receiver is a top level, XConfigureWindow () - * will fail (with a BadMatch error) for top level shells because top - * level shells are reparented by the window manager and do not share - * the same X window parent. This is the correct behavior but it is - * unexpected. The fix is to use XReconfigureWMWindow () instead. - * When the receiver is not a top level shell, XReconfigureWMWindow () - * behaves the same as XConfigureWindow (). - */ - int screen = OS.XDefaultScreen (display); - int flags = OS.CWStackMode | OS.CWSibling; - OS.XReconfigureWMWindow (display, window1, screen, flags, struct); - if (above) { - if (fixChildren) parent.moveAbove (topHandle1, topHandle2); - } else { - if (fixChildren) parent.moveBelow (topHandle1, topHandle2); - } -} -void showMenu (int x, int y) { - Event event = new Event (); - event.x = x; - event.y = y; - sendEvent (SWT.MenuDetect, event); - if (event.doit) { - if (menu != null && !menu.isDisposed ()) { - if (event.x != x || event.y != y) { - menu.setLocation (event.x, event.y); - } - menu.setVisible (true); - } - } -} -/** - * Returns a point which is the result of converting the - * argument, which is specified in display relative coordinates, - * to coordinates relative to the receiver. - * <p> - * @param x the x coordinate to be translated - * @param y the y coordinate to be translated - * @return the translated coordinates - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.1 - */ -public Point toControl (int x, int y) { - checkWidget(); - short [] root_x = new short [1], root_y = new short [1]; - OS.XtTranslateCoords (handle, (short) 0, (short) 0, root_x, root_y); - return new Point (x - root_x [0], y - root_y [0]); -} -/** - * Returns a point which is the result of converting the - * argument, which is specified in display relative coordinates, - * to coordinates relative to the receiver. - * <p> - * @param point the point to be translated (must not be null) - * @return the translated coordinates - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the point is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Point toControl (Point point) { - checkWidget(); - if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - return toControl (point.x, point.y); -} -/** - * Returns a point which is the result of converting the - * argument, which is specified in coordinates relative to - * the receiver, to display relative coordinates. - * <p> - * @param x the x coordinate to be translated - * @param y the y coordinate to be translated - * @return the translated coordinates - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.1 - */ -public Point toDisplay (int x, int y) { - checkWidget(); - short [] root_x = new short [1], root_y = new short [1]; - OS.XtTranslateCoords (handle, (short) x, (short) y, root_x, root_y); - return new Point (root_x [0], root_y [0]); -} -/** - * Returns a point which is the result of converting the - * argument, which is specified in coordinates relative to - * the receiver, to display relative coordinates. - * <p> - * @param point the point to be translated (must not be null) - * @return the translated coordinates - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the point is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Point toDisplay (Point point) { - checkWidget(); - if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - return toDisplay (point.x, point.y); -} -boolean translateAccelerator (char key, int keysym, XKeyEvent xEvent, boolean doit) { - return menuShell ().translateAccelerator (key, keysym, xEvent, doit); -} -boolean translateMnemonic (Event event, Control control) { - if (control == this) return false; - if (!isVisible () || !isEnabled ()) return false; - event.doit = mnemonicMatch (event.character); - return traverse (event); -} -boolean translateMnemonic (char key, int keysym, XKeyEvent xEvent) { - if (key < 0x20) return false; - if (xEvent.state == 0) { - int code = traversalCode (key, xEvent); - if ((code & SWT.TRAVERSE_MNEMONIC) == 0) return false; - } else { - int mask = OS.ControlMask | OS.ShiftMask | OS.Mod1Mask; - if ((xEvent.state & mask) != OS.Mod1Mask) return false; - } - Decorations shell = menuShell (); - if (shell.isVisible () && shell.isEnabled ()) { - Event event = new Event(); - event.time = xEvent.time; - event.detail = SWT.TRAVERSE_MNEMONIC; - event.character = key; - event.keyCode = keysym; - if (setInputState (event, xEvent.state)) { - return translateMnemonic (event, null) || shell.translateMnemonic (event, this); - } - } - return false; -} -boolean translateTraversal (int key, XKeyEvent xEvent) { - int detail = SWT.TRAVERSE_NONE; - int code = traversalCode (key, xEvent); - boolean all = false; - switch (key) { - case OS.XK_Escape: { - all = true; - detail = SWT.TRAVERSE_ESCAPE; - break; - } - case OS.XK_KP_Enter: - case OS.XK_Return: { - all = true; - detail = SWT.TRAVERSE_RETURN; - break; - } - case OS.XK_Tab: { - boolean next = (xEvent.state & OS.ShiftMask) == 0; - detail = next ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS; - break; - } - case OS.XK_Up: - case OS.XK_Left: - case OS.XK_Down: - case OS.XK_Right: { - boolean next = key == OS.XK_Down || key == OS.XK_Right; - detail = next ? SWT.TRAVERSE_ARROW_NEXT : SWT.TRAVERSE_ARROW_PREVIOUS; - break; - } - case OS.XK_Page_Up: - case OS.XK_Page_Down: { - all = true; - if ((xEvent.state & OS.ControlMask) == 0) return false; - detail = key == OS.XK_Page_Down ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS; - break; - } - default: - return false; - } - Event event = new Event (); - event.doit = (code & detail) != 0; - event.detail = detail; - event.time = xEvent.time; - if (!setKeyState (event, xEvent)) return false; - Shell shell = getShell (); - Control control = this; - do { - if (control.traverse (event)) return true; - if (!event.doit && control.hooks (SWT.Traverse)) return false; - if (control == shell) return false; - control = control.parent; - } while (all && control != null); - return false; -} -int traversalCode (int key, XKeyEvent xEvent) { - int [] argList = new int [] {OS.XmNtraversalOn, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (argList [1] == 0) return 0; - int code = SWT.TRAVERSE_RETURN | SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_PAGE_NEXT | SWT.TRAVERSE_PAGE_PREVIOUS; - Shell shell = getShell (); - if (shell.parent != null) code |= SWT.TRAVERSE_ESCAPE; - if (getNavigationType () == OS.XmNONE) { - code |= SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS; - } - return code; -} -boolean traverse (Event event) { - sendEvent (SWT.Traverse, event); - if (isDisposed ()) return true; - if (!event.doit) return false; - switch (event.detail) { - case SWT.TRAVERSE_NONE: return true; - case SWT.TRAVERSE_ESCAPE: return traverseEscape (); - case SWT.TRAVERSE_RETURN: return traverseReturn (); - case SWT.TRAVERSE_TAB_NEXT: return traverseGroup (true); - case SWT.TRAVERSE_TAB_PREVIOUS: return traverseGroup (false); - case SWT.TRAVERSE_ARROW_NEXT: return traverseItem (true); - case SWT.TRAVERSE_ARROW_PREVIOUS: return traverseItem (false); - case SWT.TRAVERSE_MNEMONIC: return traverseMnemonic (event.character); - case SWT.TRAVERSE_PAGE_NEXT: return traversePage (true); - case SWT.TRAVERSE_PAGE_PREVIOUS: return traversePage (false); - } - return false; -} -/** - * Based on the argument, perform one of the expected platform - * traversal action. The argument should be one of the constants: - * <code>SWT.TRAVERSE_ESCAPE</code>, <code>SWT.TRAVERSE_RETURN</code>, - * <code>SWT.TRAVERSE_TAB_NEXT</code>, <code>SWT.TRAVERSE_TAB_PREVIOUS</code>, - * <code>SWT.TRAVERSE_ARROW_NEXT</code> and <code>SWT.TRAVERSE_ARROW_PREVIOUS</code>. - * - * @param traversal the type of traversal - * @return true if the traversal succeeded - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean traverse (int traversal) { - checkWidget(); - Event event = new Event (); - event.doit = true; - event.detail = traversal; - return traverse (event); -} -boolean traverseEscape () { - return false; -} -boolean traverseGroup (boolean next) { - Control root = computeTabRoot (); - Control group = computeTabGroup (); - Control [] list = root.computeTabList (); - int length = list.length; - int index = 0; - while (index < length) { - if (list [index] == group) break; - index++; - } - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in focus in - * or out events. Ensure that a disposed widget is - * not accessed. - */ - if (index == length) return false; - int start = index, offset = (next) ? 1 : -1; - while ((index = ((index + offset + length) % length)) != start) { - Control control = list [index]; - if (!control.isDisposed () && control.setTabGroupFocus (next)) { - return true; - } - } - if (group.isDisposed ()) return false; - return group.setTabGroupFocus (next); -} -boolean traverseItem (boolean next) { - Control [] children = parent._getChildren (); - int length = children.length; - int index = 0; - while (index < length) { - if (children [index] == this) break; - index++; - } - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in focus in - * or out events. Ensure that a disposed widget is - * not accessed. - */ - if (index == length) return false; - int start = index, offset = (next) ? 1 : -1; - while ((index = (index + offset + length) % length) != start) { - Control child = children [index]; - if (!child.isDisposed () && child.isTabItem ()) { - if (child.setTabItemFocus (next)) return true; - } - } - return false; -} -boolean traversePage (boolean next) { - return false; -} -boolean traverseMnemonic (char key) { - return mnemonicHit (key); -} -boolean traverseReturn () { - return false; -} -/** - * Forces all outstanding paint requests for the widget - * to be processed before this method returns. If there - * are no outstanding paint request, this method does - * nothing. - * <p> - * Note: This method does not cause a redraw. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #redraw() - * @see #redraw(int, int, int, int, boolean) - * @see PaintListener - * @see SWT#Paint - */ -public void update () { - checkWidget(); - update (false); -} -void update (boolean all) { -// checkWidget(); - if (all) { - display.update (); - } else { - int display = OS.XtDisplay (handle); - if (display == 0) return; - int window = OS.XtWindow (handle); - if (window == 0) return; - int event = OS.XtMalloc (XEvent.sizeof); - OS.XSync (display, false); - OS.XSync (display, false); - while (OS.XCheckWindowEvent (display, window, OS.ExposureMask, event)) { - OS.XtDispatchEvent (event); - } - OS.XtFree (event); - } -} -void updateBackgroundMode () { - int oldState = state & PARENT_BACKGROUND; - checkBackground (); - if (oldState != (state & PARENT_BACKGROUND)) { - setBackground (); - } -} -void updateIM () { - if (!OS.IsDBLocale) return; - if (!hasFocus ()) return; - int[] argList2; - int ptr1 = 0, ptr2 = 0; - if (hasIMSupport ()) { - argList2 = new int[]{ - OS.XmNfontList, font.handle, -// OS.XmNforeground, getForegroundPixel (), -// OS.XmNbackground, getBackgroundPixel (), - }; - } else { - int x = 0, y = 0; - Font font = this.font; - Caret caret = getIMCaret (); - if (caret != null) { - x += caret.x + (caret.width <= 0 ? 2 : caret.width); - y += caret.y; - if (caret.font != null) font = caret.font; - } - y += getFontAscent (font.handle); - short [] point = new short[]{(short) x, (short) y}; - ptr1 = OS.XtMalloc (4); - OS.memmove (ptr1, point, 4); - int [] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - short [] rect = new short[]{0, 0, (short) argList1 [1], (short) argList1 [3]}; - ptr2 = OS.XtMalloc (8); - OS.memmove (ptr2, rect, 8); - /* - * Feature in Motif. The XmNarea resource has to be set after - * the XmNspotLocation. - */ - argList2 = new int[]{ - OS.XmNfontList, font.handle, -// OS.XmNforeground, getForegroundPixel (), -// OS.XmNbackground, getBackgroundPixel (), - OS.XmNspotLocation, ptr1, - OS.XmNarea, ptr2, - }; - } - OS.XmImSetValues (handle, argList2, argList2.length / 2); - int focusHandle = focusHandle (); - if (handle != focusHandle) { - OS.XmImSetValues (focusHandle, argList2, argList2.length / 2); - } - if (ptr1 != 0) OS.XtFree (ptr1); - if (ptr2 != 0) OS.XtFree (ptr2); -} -void updateLayout (boolean all) { - /* Do nothing */ -} -int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) { - Display display = this.display; - display.hideToolTip (); - Shell shell = getShell (); - /* - * When a shell is created with SWT.ON_TOP and SWT.NO_FOCUS, - * do not activate the shell when the user clicks on the - * the client area or on the border or a control within the - * shell that does not take focus. - */ - if (((shell.style & SWT.ON_TOP) != 0) && (((shell.style & SWT.NO_FOCUS) == 0) || ((style & SWT.NO_FOCUS) == 0))) { - shell.forceActive(); - } - boolean dispatch = true, dragging = false; - XButtonEvent xEvent = new XButtonEvent (); - OS.memmove (xEvent, call_data, XButtonEvent.sizeof); - int clickTime = display.getDoubleClickTime (); - int lastTime = display.lastTime, eventTime = xEvent.time; - int lastButton = display.lastButton, eventButton = xEvent.button; - if (lastButton == eventButton && lastTime != 0 && Math.abs (lastTime - eventTime) <= clickTime) { - display.clickCount++; - } else { - display.clickCount = 1; - } - display.lastTime = eventTime == 0 ? 1 : eventTime; - display.lastButton = eventButton; - if (xEvent.button == 2) { - if ((state & DRAG_DETECT) != 0 && hooks (SWT.DragDetect)) { - boolean [] consume = new boolean [1]; - if (dragDetect (xEvent.x, xEvent.y, true, consume)) { - dragging = true; - dispatch = !consume [0]; - } - if (isDisposed ()) return 1; - } - } - if (!sendMouseEvent (SWT.MouseDown, xEvent)) dispatch = false; - if (isDisposed ()) return 1; - if (display.clickCount == 2) { - if (!sendMouseEvent (SWT.MouseDoubleClick, xEvent)) dispatch = false; - if (isDisposed ()) return 1; - // widget could be disposed at this point - } - if (dragging) { - sendDragEvent (xEvent.button, xEvent.state, xEvent.x, xEvent.y, false); - if (isDisposed ()) return 1; - } - if (xEvent.button == 3) { - if (menu != null || hooks (SWT.MenuDetect)) { - if (!isFocusControl ()) setFocus (); - } - showMenu (xEvent.x_root, xEvent.y_root); - if (isDisposed ()) return 1; - } - if (!shell.isDisposed ()) shell.setActiveControl (this); - if (!dispatch) { - OS.memmove (continue_to_dispatch, new int [1], 4); - return 1; - } - return 0; -} -int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) { - display.hideToolTip (); - XButtonEvent xEvent = new XButtonEvent (); - OS.memmove (xEvent, call_data, XButtonEvent.sizeof); - if (!sendMouseEvent (SWT.MouseUp, xEvent)) { - OS.memmove (continue_to_dispatch, new int [1], 4); - return 1; - } - return 0; -} -int XEnterWindow (int w, int client_data, int call_data, int continue_to_dispatch) { - XCrossingEvent xEvent = new XCrossingEvent (); - OS.memmove (xEvent, call_data, XCrossingEvent.sizeof); - if (xEvent.mode != OS.NotifyNormal && xEvent.mode != OS.NotifyUngrab) return 0; - if ((xEvent.state & (OS.Button1Mask | OS.Button2Mask | OS.Button3Mask)) != 0) return 0; - if (xEvent.subwindow != 0) return 0; - if (!sendMouseEvent (SWT.MouseEnter, xEvent)) { - OS.memmove (continue_to_dispatch, new int [1], 4); - return 1; - } - return 0; -} -int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) { - if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0; - XExposeEvent xEvent = new XExposeEvent (); - OS.memmove (xEvent, call_data, XExposeEvent.sizeof); - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return 0; - int damageRgn = OS.XCreateRegion (); - OS.XtAddExposureToRegion (call_data, damageRgn); - Event event = new Event (); - event.count = xEvent.count; - event.x = xEvent.x; - event.y = xEvent.y; - event.width = xEvent.width; - event.height = xEvent.height; - GCData data = new GCData(); - data.damageRgn = damageRgn; - GC gc = event.gc = GC.motif_new(this, data); - OS.XSetRegion (xDisplay, gc.handle, damageRgn); - sendEvent (SWT.Paint, event); - event.gc = null; - gc.dispose (); - OS.XDestroyRegion(damageRgn); - return 0; -} -int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatch) { - - /* Get the focus change event */ - XFocusChangeEvent xEvent = new XFocusChangeEvent (); - OS.memmove (xEvent, call_data, XFocusChangeEvent.sizeof); - - /* Ignore focus changes caused by grabbing and ungrabing */ - if (xEvent.mode != OS.NotifyNormal) return 0; - - /* Only process focus callbacks between windows */ - if (xEvent.detail != OS.NotifyAncestor && - xEvent.detail != OS.NotifyInferior && - xEvent.detail != OS.NotifyNonlinear) return 0; - - /* Process the focus change for the widget */ - Display display = this.display; - Shell shell = getShell (); - switch (xEvent.type) { - case OS.FocusIn: - xFocusIn (xEvent); - // widget could be disposed at this point - - /* - * It is possible that the shell may be - * disposed at this point. If this happens - * don't send the activate and deactivate - * events. - */ - if (!shell.isDisposed ()) { - shell.setActiveControl (this); - } - break; - case OS.FocusOut: - xFocusOut (xEvent); - // widget could be disposed at this point - - /* - * It is possible that the shell may be - * disposed at this point. If this happens - * don't send the activate and deactivate - * events. - */ - if (!shell.isDisposed ()) { - if (shell != display.getActiveShell ()) { - shell.setActiveControl (null); - } - } - break; - } - return 0; -} -int xFocusIn (XFocusChangeEvent xEvent) { - /* - * Bug in Motif. For some reason, when the widget font is - * not the default font and the widget loses focus, the - * X input method segment faults. A BadFont (invalid font - * parameter) error is printed. This problem also happens - * to XmText and XmTextField. The fix is to change the - * X input method font back to the default font when the - * widget loses focus and restore it when the widget gets - * focus. - */ - updateIM (); - if (!hasIMSupport ()) { - int focusHandle = OS.XtWindowToWidget (xEvent.display, xEvent.window); - OS.XmImSetFocusValues (focusHandle, null, 0); - } - sendFocusEvent (SWT.FocusIn); - return 0; -} -int xFocusOut (XFocusChangeEvent xEvent) { - int focusHandle = OS.XtWindowToWidget (xEvent.display, xEvent.window); - if (!hasIMSupport ()) OS.XmImUnsetFocus (focusHandle); - - /* - * Bug in Motif. For some reason, when the widget font is - * not the default font and the widget loses focus, the - * X input method segment faults. A BadFont (invalid font - * parameter) error is printed. This problem also happens - * to XmText and XmTextField. The fix is to change the - * X input method font back to the default font when the - * widget loses focus and restore it when the widget gets - * focus. - * - * NOTE: On AIX, changing the IM font when focus is lost because - * the shell was resized by the user causes the ConfigureNotify - * event for the shell to be lost. The event is not in the - * event queue and therefore not dispatched. The fix is to avoid - * the workaround for AIX. - */ - if (!OS.IsAIX) { - int fontList = defaultFont ().handle; - if (font.handle != fontList) { - int [] argList2 = {OS.XmNfontList, fontList}; - OS.XmImSetValues (focusHandle, argList2, argList2.length / 2); - } - } - - sendFocusEvent (SWT.FocusOut); - - /* Restore XmNtraversalOn if it was focus was forced */ - if (handle == 0) return 0; - if ((style & SWT.NO_FOCUS) != 0) { - int [] argList = new int [] {OS.XmNtraversalOn, 0}; - OS.XtGetValues (focusHandle, argList, argList.length / 2); - if (argList [1] != 0 && (state & FOCUS_FORCED) != 0) { - argList [1] = 0; - OS.XtSetValues (focusHandle, argList, argList.length / 2); - } - } - return 0; -} -int XKeyRelease (int w, int client_data, int call_data, int continue_to_dispatch) { - XKeyEvent xEvent = new XKeyEvent (); - OS.memmove (xEvent, call_data, XKeyEvent.sizeof); - if (menu != null && xEvent.state == OS.ShiftMask) { - byte [] buffer = new byte [1]; - int [] keysym = new int [1]; - OS.XLookupString (xEvent, buffer, buffer.length, keysym, null); - if (keysym [0] == OS.XK_F10) { - showMenu (xEvent.x_root, xEvent.y_root); - } - } - return super.XKeyRelease (w, client_data, call_data, continue_to_dispatch); -} -int XLeaveWindow (int w, int client_data, int call_data, int continue_to_dispatch) { - display.removeMouseHoverTimeOut (); - display.hideToolTip (); - XCrossingEvent xEvent = new XCrossingEvent (); - OS.memmove (xEvent, call_data, XCrossingEvent.sizeof); - if (xEvent.mode != OS.NotifyNormal && xEvent.mode != OS.NotifyUngrab) return 0; - if ((xEvent.state & (OS.Button1Mask | OS.Button2Mask | OS.Button3Mask)) != 0) return 0; - if (xEvent.subwindow != 0) return 0; - if (!sendMouseEvent (SWT.MouseExit, xEvent)) { - OS.memmove (continue_to_dispatch, new int [1], 4); - return 1; - } - return 0; -} -int XmNhelpCallback (int w, int client_data, int call_data) { - sendHelpEvent (call_data); - return 0; -} -int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) { - display.addMouseHoverTimeOut (handle); - XMotionEvent xEvent = new XMotionEvent (); - OS.memmove (xEvent, call_data, XMotionEvent.sizeof); - if (!sendMouseEvent (SWT.MouseMove, xEvent)) { - OS.memmove (continue_to_dispatch, new int [1], 4); - return 1; - } - return 0; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java deleted file mode 100755 index 5c0b2ba927..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java +++ /dev/null @@ -1,797 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class provide the appearance and - * behavior of <code>Shells</code>, but are not top - * level shells or dialogs. Class <code>Shell</code> - * shares a significant amount of code with this class, - * and is a subclass. - * <p> - * IMPORTANT: This class was intended to be abstract and - * should <em>never</em> be referenced or instantiated. - * Instead, the class <code>Shell</code> should be used. - * </p> - * <p> - * Instances are always displayed in one of the maximized, - * minimized or normal states: - * <ul> - * <li> - * When an instance is marked as <em>maximized</em>, the - * window manager will typically resize it to fill the - * entire visible area of the display, and the instance - * is usually put in a state where it can not be resized - * (even if it has style <code>RESIZE</code>) until it is - * no longer maximized. - * </li><li> - * When an instance is in the <em>normal</em> state (neither - * maximized or minimized), its appearance is controlled by - * the style constants which were specified when it was created - * and the restrictions of the window manager (see below). - * </li><li> - * When an instance has been marked as <em>minimized</em>, - * its contents (client area) will usually not be visible, - * and depending on the window manager, it may be - * "iconified" (that is, replaced on the desktop by a small - * simplified representation of itself), relocated to a - * distinguished area of the screen, or hidden. Combinations - * of these changes are also possible. - * </li> - * </ul> - * </p> - * Note: The styles supported by this class must be treated - * as <em>HINT</em>s, since the window manager for the - * desktop on which the instance is visible has ultimate - * control over the appearance and behavior of decorations. - * For example, some window managers only support resizable - * windows and will always assume the RESIZE style, even if - * it is not set. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * Class <code>SWT</code> provides two "convenience constants" - * for the most commonly required style combinations: - * <dl> - * <dt><code>SHELL_TRIM</code></dt> - * <dd> - * the result of combining the constants which are required - * to produce a typical application top level shell: (that - * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>) - * </dd> - * <dt><code>DIALOG_TRIM</code></dt> - * <dd> - * the result of combining the constants which are required - * to produce a typical application dialog shell: (that - * is, <code>TITLE | CLOSE | BORDER</code>) - * </dd> - * </dl> - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - * - * @see #getMinimized - * @see #getMaximized - * @see Shell - * @see SWT - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class Decorations extends Canvas { - String label; - Image image; - Image [] images = new Image [0]; - int dialogHandle; - boolean minimized, maximized; - Menu menuBar; - Menu [] menus; - Control savedFocus; - Button defaultButton, saveDefault; -Decorations () { - /* Do nothing */ -} -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#BORDER - * @see SWT#CLOSE - * @see SWT#MIN - * @see SWT#MAX - * @see SWT#RESIZE - * @see SWT#TITLE - * @see SWT#NO_TRIM - * @see SWT#SHELL_TRIM - * @see SWT#DIALOG_TRIM - * @see SWT#ON_TOP - * @see SWT#TOOL - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Decorations (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -void _setImages (Image [] images) { - if (images != null && images.length > 1) { - Image [] bestImages = new Image [images.length]; - System.arraycopy (images, 0, bestImages, 0, images.length); - sort (bestImages); - images = bestImages; - } - Image icon = images != null && images.length > 0 ? icon = images [0] : null; - int pixmap = 0, mask = 0; - if (icon != null) { - switch (icon.type) { - case SWT.BITMAP: - pixmap = icon.pixmap; - break; - case SWT.ICON: - pixmap = icon.pixmap; - mask = icon.mask; - break; - } - } - int [] argList = { - OS.XmNiconPixmap, pixmap, - OS.XmNiconMask, mask, - }; - int topHandle = topHandle (); - OS.XtSetValues (topHandle, argList, argList.length / 2); -} - -void addMenu (Menu menu) { - if (menus == null) menus = new Menu [4]; - for (int i=0; i<menus.length; i++) { - if (menus [i] == null) { - menus [i] = menu; - return; - } - } - Menu [] newMenus = new Menu [menus.length + 4]; - newMenus [menus.length] = menu; - System.arraycopy (menus, 0, newMenus, 0, menus.length); - menus = newMenus; -} -void bringToTop (boolean force) { - moveAbove (null); -} -static int checkStyle (int style) { - if ((style & SWT.NO_TRIM) != 0) { - style &= ~(SWT.CLOSE | SWT.TITLE | SWT.MIN | SWT.MAX | SWT.RESIZE | SWT.BORDER); - } - if ((style & (SWT.MENU | SWT.MIN | SWT.MAX | SWT.CLOSE)) != 0) { - style |= SWT.TITLE; - } - return style; -} -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} - -int compare (ImageData data1, ImageData data2) { - int transparent1 = data1.getTransparencyType (); - int transparent2 = data2.getTransparencyType (); - if (transparent1 != transparent2) { - if (transparent1 == SWT.TRANSPARENCY_ALPHA) return 1; - if (transparent2 == SWT.TRANSPARENCY_ALPHA) return -1; - } - if (data1.width == data2.width && data1.height == data2.height) { - if (transparent1 == SWT.TRANSPARENCY_MASK) return -1; - if (transparent2 == SWT.TRANSPARENCY_MASK) return 1; - if (transparent1 == SWT.TRANSPARENCY_PIXEL) return -1; - if (transparent2 == SWT.TRANSPARENCY_PIXEL) return 1; - return 0; - } - return data1.width > data2.width || data1.height > data2.height ? -1 : 1; -} - -Control computeTabGroup () { - return this; -} - -Control computeTabRoot () { - return this; -} - -public Rectangle computeTrim (int x, int y, int width, int height) { - checkWidget(); - Rectangle trim = super.computeTrim (x, y, width, height); - if (menuBar != null) { - XtWidgetGeometry request = new XtWidgetGeometry (); - XtWidgetGeometry result = new XtWidgetGeometry (); - request.request_mode = OS.CWWidth; - request.width = trim.width; - OS.XtQueryGeometry (menuBar.handle, request, result); - trim.height += result.height; - } - return trim; -} -void createHandle (int index) { - state |= CANVAS; - createHandle (index, parent.handle, true); -} -void createWidget (int index) { - super.createWidget (index); - label = ""; -} -int dialogHandle () { - if (dialogHandle != 0) return dialogHandle; - return dialogHandle = OS.XmCreateDialogShell (handle, null, null, 0); -} -/** - * Returns the receiver's default button if one had - * previously been set, otherwise returns null. - * - * @return the default button or null - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #setDefaultButton(Button) - */ -public Button getDefaultButton () { - checkWidget(); - return defaultButton; -} -/** - * Returns the receiver's image if it had previously been - * set using <code>setImage()</code>. The image is typically - * displayed by the window manager when the instance is - * marked as iconified, and may also be displayed somewhere - * in the trim when the instance is in normal or maximized - * states. - * <p> - * Note: This method will return null if called before - * <code>setImage()</code> is called. It does not provide - * access to a window manager provided, "default" image - * even if one exists. - * </p> - * - * @return the image - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Image getImage () { - checkWidget(); - return image; -} -/** - * Returns the receiver's images if they had previously been - * set using <code>setImages()</code>. Images are typically - * displayed by the window manager when the instance is - * marked as iconified, and may also be displayed somewhere - * in the trim when the instance is in normal or maximized - * states. Depending where the icon is displayed, the platform - * chooses the icon with the "best" attributes. It is expected - * that the array will contain the same icon rendered at different - * sizes, with different depth and transparency attributes. - * - * <p> - * Note: This method will return an empty array if called before - * <code>setImages()</code> is called. It does not provide - * access to a window manager provided, "default" image - * even if one exists. - * </p> - * - * @return the images - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.0 - */ -public Image [] getImages () { - checkWidget (); - if (images == null) return new Image [0]; - Image [] result = new Image [images.length]; - System.arraycopy (images, 0, result, 0, images.length); - return result; -} -/** - * Returns <code>true</code> if the receiver is currently - * maximized, and false otherwise. - * <p> - * - * @return the maximized state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #setMaximized - */ -public boolean getMaximized () { - checkWidget(); - return maximized; -} -/** - * Returns the receiver's menu bar if one had previously - * been set, otherwise returns null. - * - * @return the menu bar or null - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Menu getMenuBar () { - checkWidget(); - return menuBar; -} -/** - * Returns <code>true</code> if the receiver is currently - * minimized, and false otherwise. - * <p> - * - * @return the minimized state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #setMinimized - */ -public boolean getMinimized () { - checkWidget(); - return minimized; -} -String getNameText () { - return getText (); -} -/** - * Returns the receiver's text, which is the string that the - * window manager will typically display as the receiver's - * <em>title</em>. If the text has not previously been set, - * returns an empty string. - * - * @return the text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getText () { - checkWidget(); - return label; -} -boolean isTabGroup () { - return true; -} -boolean isTabItem () { - return false; -} -Decorations menuShell () { - return this; -} -void propagateWidget (boolean enabled) { - super.propagateWidget (enabled); - int [] argList = {OS.XmNmenuBar, 0}; - OS.XtGetValues (scrolledHandle, argList, argList.length / 2); - if (argList [1] != 0) propagateHandle (enabled, argList [1], OS.None); -} -void releaseChildren (boolean destroy) { - if (menuBar != null) { - menuBar.release (false); - menuBar = null; - } - super.releaseChildren (destroy); - if (menus != null) { - for (int i=0; i<menus.length; i++) { - Menu menu = menus [i]; - if (menu != null && !menu.isDisposed ()) { - menu.release (false); - } - } - menus = null; - } -} -void releaseHandle () { - super.releaseHandle (); - dialogHandle = 0; -} -void releaseWidget () { - super.releaseWidget (); - image = null; - images = null; - savedFocus = null; - defaultButton = saveDefault = null; - label = null; -} -boolean restoreFocus () { - if (savedFocus != null && savedFocus.isDisposed ()) savedFocus = null; - boolean restored = savedFocus != null && savedFocus.setFocus (); - savedFocus = null; - /* - * This code is intentionally commented. When no widget - * has been given focus, some platforms give focus to the - * default button. Motif doesn't do this. - */ -// if (restored) return true; -// if (defaultButton != null && !defaultButton.isDisposed ()) { -// if (defaultButton.setFocus ()) return true; -// } -// return false; - return restored; -} -void removeMenu (Menu menu) { - if (menus == null) return; - for (int i=0; i<menus.length; i++) { - if (menus [i] == menu) { - menus [i] = null; - return; - } - } -} -/** - * If the argument is not null, sets the receiver's default - * button to the argument, and if the argument is null, sets - * the receiver's default button to the first button which - * was set as the receiver's default button (called the - * <em>saved default button</em>). If no default button had - * previously been set, or the saved default button was - * disposed, the receiver's default button will be set to - * null. - * <p> - * The default button is the button that is selected when - * the receiver is active and the user presses ENTER. - * </p> - * - * @param button the new default button - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the button has been disposed</li> - * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setDefaultButton (Button button) { - checkWidget(); - if (button != null) { - if (button.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT); - if (button.menuShell () != this) error(SWT.ERROR_INVALID_PARENT); - } - setDefaultButton (button, true); -} -void setDefaultButton (Button button, boolean save) { - if (button == null) { - if (defaultButton == saveDefault) { - if (save) saveDefault = null; - return; - } - } else { - if ((button.style & SWT.PUSH) == 0) return; - if (button == defaultButton) return; - } - if (defaultButton != null) { - if (!defaultButton.isDisposed ()) defaultButton.setDefault (false); - } - if ((defaultButton = button) == null) defaultButton = saveDefault; - if (defaultButton != null) { - if (!defaultButton.isDisposed ()) defaultButton.setDefault (true); - } - if (save) saveDefault = defaultButton; - if (saveDefault != null && saveDefault.isDisposed ()) saveDefault = null; -} -/** - * Sets the receiver's image to the argument, which may - * be null. The image is typically displayed by the window - * manager when the instance is marked as iconified, and - * may also be displayed somewhere in the trim when the - * instance is in normal or maximized states. - * - * @param image the new image (or null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setImage (Image image) { - checkWidget(); - if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - this.image = image; - _setImages (image != null ? new Image [] {image} : null); -} - -/** - * Sets the receiver's images to the argument, which may - * be an empty array. Images are typically displayed by the - * window manager when the instance is marked as iconified, - * and may also be displayed somewhere in the trim when the - * instance is in normal or maximized states. Depending where - * the icon is displayed, the platform chooses the icon with - * the "best" attributes. It is expected that the array will - * contain the same icon rendered at different sizes, with - * different depth and transparency attributes. - * - * @param images the new image array - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li> - * <li>ERROR_INVALID_ARGUMENT - if one of the images is null or has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.0 - */ -public void setImages (Image [] images) { - checkWidget (); - if (images == null) error (SWT.ERROR_INVALID_ARGUMENT); - for (int i = 0; i < images.length; i++) { - if (images [i] == null || images [i].isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - } - this.images = images; - _setImages (images); -} - -/** - * Sets the maximized state of the receiver. - * If the argument is <code>true</code> causes the receiver - * to switch to the maximized state, and if the argument is - * <code>false</code> and the receiver was previously maximized, - * causes the receiver to switch back to either the minimized - * or normal states. - * <p> - * Note: The result of intermixing calls to <code>setMaximized(true)</code> - * and <code>setMinimized(true)</code> will vary by platform. Typically, - * the behavior will match the platform user's expectations, but not - * always. This should be avoided if possible. - * </p> - * - * @param maximized the new maximized state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #setMinimized - */ -public void setMaximized (boolean maximized) { - checkWidget(); - this.maximized = maximized; -} -/** - * Sets the receiver's menu bar to the argument, which - * may be null. - * - * @param menu the new menu bar - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li> - * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMenuBar (Menu menu) { - checkWidget(); - if (menuBar == menu) return; - if (menu != null) { - if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR); - if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT); - } - - /* Ensure the new menu bar is correctly enabled */ - if (menuBar != null) { - if (!isEnabled () && menuBar.getEnabled ()) { - propagateHandle (true, menuBar.handle, OS.None); - } - menuBar.removeAccelerators (); - } - if (menu != null) { - if (!isEnabled ()) { - propagateHandle (false, menu.handle, OS.None); - } - menu.addAccelerators (); - } - - /* Save the old client area */ - int [] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - - /* - * Bug in Motif. When a XmMainWindowSetAreas () is used - * to replace an existing menu, both menus must be managed - * before the call to XmMainWindowSetAreas () or the new - * menu will not be laid out properly. - */ - int newHandle = (menu != null) ? menu.handle : 0; - int oldHandle = (menuBar != null) ? menuBar.handle : 0; - menuBar = menu; - int hHandle = (horizontalBar != null) ? horizontalBar.handle : 0; - int vHandle = (verticalBar != null) ? verticalBar.handle : 0; - if (newHandle != 0) { - OS.XtSetMappedWhenManaged (newHandle, false); - OS.XtManageChild (newHandle); - } - int clientHandle = formHandle != 0 ? formHandle : handle; - OS.XmMainWindowSetAreas (scrolledHandle, newHandle, 0, hHandle, vHandle, clientHandle); - if (oldHandle != 0) OS.XtUnmanageChild (oldHandle); - if (newHandle != 0) { - OS.XtSetMappedWhenManaged (newHandle, true); - } - - /* - * Bug in Motif. When a menu bar is removed after the - * main window has been realized, the main window does - * not layout the new menu bar or the work window. - * The fix is to force a layout by temporarily resizing - * the main window. - */ - if (newHandle == 0 && OS.XtIsRealized (scrolledHandle)) { - int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - OS.XtGetValues (scrolledHandle, argList, argList.length / 2); - OS.XtResizeWidget (scrolledHandle, argList [1] + 1, argList [3], argList [5]); - OS.XtResizeWidget (scrolledHandle, argList [1], argList [3], argList [5]); - } - - /* - * Compare the old client area with the new client area. - * If the client area has changed, send a resize event - * and layout. - */ - int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0}; - OS.XtGetValues (handle, argList2, argList2.length / 2); - if (argList1 [1] != argList2 [1] || argList1 [3] != argList2 [3]) { - sendEvent (SWT.Resize); - if (layout != null) { - markLayout (false, false); - updateLayout (false); - } - } -} -/** - * Sets the minimized stated of the receiver. - * If the argument is <code>true</code> causes the receiver - * to switch to the minimized state, and if the argument is - * <code>false</code> and the receiver was previously minimized, - * causes the receiver to switch back to either the maximized - * or normal states. - * <p> - * Note: The result of intermixing calls to <code>setMaximized(true)</code> - * and <code>setMinimized(true)</code> will vary by platform. Typically, - * the behavior will match the platform user's expectations, but not - * always. This should be avoided if possible. - * </p> - * - * @param minimized the new maximized state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #setMaximized - */ -public void setMinimized (boolean minimized) { - checkWidget(); - this.minimized = minimized; -} -void setSavedFocus (Control control) { - if (this == control) return; - savedFocus = control; -} -/** - * Sets the receiver's text, which is the string that the - * window manager will typically display as the receiver's - * <em>title</em>, to the argument, which must not be null. - * - * @param string the new text - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the text is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - label = string; -} -void sort (Image [] images) { - /* Shell Sort from K&R, pg 108 */ - int length = images.length; - if (length <= 1) return; - ImageData [] datas = new ImageData [length]; - for (int i = 0; i < length; i++) { - datas [i] = images [i].getImageData (); - } - for (int gap=length/2; gap>0; gap/=2) { - for (int i=gap; i<length; i++) { - for (int j=i-gap; j>=0; j-=gap) { - if (compare (datas [j], datas [j + gap]) >= 0) { - Image swap = images [j]; - images [j] = images [j + gap]; - images [j + gap] = swap; - ImageData swapData = datas [j]; - datas [j] = datas [j + gap]; - datas [j + gap] = swapData; - } - } - } - } -} -boolean translateAccelerator (char key, int keysym, XKeyEvent xEvent, boolean doit) { - if (menuBar == null || !menuBar.getEnabled ()) return false; - int accelerator = Display.translateKey (keysym); - if (accelerator == 0) accelerator = key; - if (accelerator == 0) return false; - if ((xEvent.state & OS.Mod1Mask) != 0) accelerator |= SWT.ALT; - if ((xEvent.state & OS.ShiftMask) != 0) accelerator |= SWT.SHIFT; - if ((xEvent.state & OS.ControlMask) != 0) accelerator |= SWT.CONTROL; - return menuBar.translateAccelerator (accelerator, doit); -} -boolean traverseItem (boolean next) { - return false; -} -boolean traverseReturn () { - if (defaultButton == null || defaultButton.isDisposed ()) return false; - if (!defaultButton.isVisible () || !defaultButton.isEnabled ()) return false; - defaultButton.click (); - return true; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java deleted file mode 100755 index 9d38b2ac95..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java +++ /dev/null @@ -1,347 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; - -/** - * Instances of this class allow the user to navigate - * the file system and select a directory. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#directorydialog">DirectoryDialog snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class DirectoryDialog extends Dialog { - String filterPath = ""; //$NON-NLS-1$ - boolean cancel = true; - String message = ""; //$NON-NLS-1$ - static final String SEPARATOR = System.getProperty ("file.separator"); //$NON-NLS-1$ - -/** - * Constructs a new instance of this class given only its parent. - * - * @param parent a shell which will be the parent of the new instance - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - */ -public DirectoryDialog (Shell parent) { - this (parent, SWT.APPLICATION_MODAL); -} -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a shell which will be the parent of the new instance - * @param style the style of dialog to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - */ -public DirectoryDialog (Shell parent, int style) { - super (parent, checkStyle (parent, style)); - checkSubclass (); -} -int activate (int widget, int client, int call) { - cancel = client == OS.XmDIALOG_CANCEL_BUTTON; - OS.XtUnmanageChild (widget); - return 0; -} -/** - * Returns the path which the dialog will use to filter - * the directories it shows. - * - * @return the filter path - * - * @see #setFilterPath - */ -public String getFilterPath () { - return filterPath; -} -/** - * Returns the dialog's message, which is a description of - * the purpose for which it was opened. This message will be - * visible on the dialog while it is open. - * - * @return the message - */ -public String getMessage () { - return message; -} -/** - * Makes the dialog visible and brings it to the front - * of the display. - * - * @return a string describing the absolute path of the selected directory, - * or null if the dialog was cancelled or an error occurred - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li> - * </ul> - */ -public String open () { - /* Compute the dialog title */ - /* - * Feature in Motif. It is not possible to set a shell - * title to an empty string. The fix is to set the title - * to be a single space. - */ - String string = title; - if (string.length () == 0) string = " "; //$NON-NLS-1$ - - /* Use the character encoding for the default locale */ - byte [] buffer1 = Converter.wcsToMbcs (null, string, true); - int xmStringPtr1 = OS.XmStringParseText ( - buffer1, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - - /* Compute the filter */ - /* Use the character encoding for the default locale */ - byte [] buffer2 = Converter.wcsToMbcs (null, "*", true); //$NON-NLS-1$ - int xmStringPtr2 = OS.XmStringParseText ( - buffer2, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - - /* Compute the filter path */ - if (filterPath == null) filterPath = ""; //$NON-NLS-1$ - /* Use the character encoding for the default locale */ - byte [] buffer3 = Converter.wcsToMbcs (null, filterPath, true); - int xmStringPtr3 = OS.XmStringParseText ( - buffer3, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - - /* Use the character encoding for the default locale */ - byte [] buffer7 = Converter.wcsToMbcs (null, SWT.getMessage ("SWT_Selection"), true); - int xmStringPtr4 = OS.XmStringParseText ( - buffer7, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - - /* Create the dialog */ - boolean defaultPos = parent.isVisible (); - Display display = parent.display; - int [] argList1 = { - OS.XmNresizePolicy, OS.XmRESIZE_NONE, - OS.XmNdialogStyle, OS.XmDIALOG_PRIMARY_APPLICATION_MODAL, - OS.XmNwidth, OS.XDisplayWidth (display.xDisplay, OS.XDefaultScreen (display.xDisplay)) * 4 / 9, - OS.XmNdialogTitle, xmStringPtr1, - OS.XmNpattern, xmStringPtr2, - OS.XmNdirectory, xmStringPtr3, - OS.XmNpathMode, OS.XmPATH_MODE_FULL, - OS.XmNfilterLabelString, xmStringPtr4, - OS.XmNdefaultPosition, defaultPos ? 1 : 0, - }; - - /* - * Bug in AIX. The dialog does not respond to input, if the parent - * is not realized. The fix is to realize the parent. - */ - if (OS.IsAIX) parent.realizeWidget (); - int parentHandle = parent.shellHandle; - /* - * Feature in Linux. For some reason, the XmCreateFileSelectionDialog() - * will not accept NULL for the widget name. This works fine on the other - * Motif platforms and in the other XmCreate calls on Linux. The fix is - * to pass in a NULL terminated string, not a NULL pointer. - */ - byte [] name = new byte [] {0}; - int dialog = OS.XmCreateFileSelectionDialog (parentHandle, name, argList1, argList1.length / 2); - int child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_HELP_BUTTON); - if (child != 0) OS.XtUnmanageChild (child); - child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST); - if (child != 0) { - int parent2 = OS.XtParent(child); - if (parent2 !=0) OS.XtUnmanageChild (parent2); - } - child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST_LABEL); - if (child != 0) OS.XtUnmanageChild (child); - child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_TEXT); - if (child != 0) OS.XtUnmanageChild (child); - child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_SELECTION_LABEL); - if (child != 0) OS.XtUnmanageChild (child); - OS.XmStringFree (xmStringPtr1); - OS.XmStringFree (xmStringPtr2); - OS.XmStringFree (xmStringPtr3); - OS.XmStringFree (xmStringPtr4); - - /* Add label widget for message text. */ - /* Use the character encoding for the default locale */ - byte [] buffer4 = Converter.wcsToMbcs (null, message, true); - int xmString1 = OS.XmStringGenerate(buffer4, null, OS.XmCHARSET_TEXT, null); - int [] argList2 = { - OS.XmNlabelType, OS.XmSTRING, - OS.XmNlabelString, xmString1 - }; - int textArea = OS.XmCreateLabel(dialog, name, argList2, argList2.length/2); - OS.XtManageChild(textArea); - OS.XmStringFree (xmString1); - - /* Hook the callbacks. */ - Callback callback = new Callback (this, "activate", 3); //$NON-NLS-1$ - int address = callback.getAddress (); - if (address == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - OS.XtAddCallback (dialog, OS.XmNokCallback, address, OS.XmDIALOG_OK_BUTTON); - OS.XtAddCallback (dialog, OS.XmNcancelCallback, address, OS.XmDIALOG_CANCEL_BUTTON); - - /* Open the dialog and dispatch events. */ - cancel = true; - if (!defaultPos) { - OS.XtRealizeWidget (dialog); - int[] argList3 = new int[] { - OS.XmNwidth, 0, - OS.XmNheight, 0, - }; - OS.XtGetValues (dialog, argList3, argList3.length / 2); - Monitor monitor = parent.getMonitor (); - Rectangle bounds = monitor.getBounds (); - int x = bounds.x + (bounds.width - argList3 [1]) / 2; - int y = bounds.y + (bounds.height - argList3 [3]) / 2; - int[] argList4 = new int[] { - OS.XmNx, x, - OS.XmNy, y, - }; - OS.XtSetValues (dialog, argList4, argList4.length / 2); - } - OS.XtManageChild (dialog); - - /* Should be a pure OS message loop (no SWT AppContext) */ - while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog)) - if (!display.readAndDispatch ()) display.sleep (); - - /* Set the new path, file name and filter. */ - String directoryPath=""; //$NON-NLS-1$ - if (!cancel) { - int [] argList5 = {OS.XmNdirMask, 0}; - OS.XtGetValues (dialog, argList5, argList5.length / 2); - int xmString3 = argList5 [1]; - int [] table = new int [] {display.tabMapping, display.crMapping}; - int ptr = OS.XmStringUnparse ( - xmString3, - null, - OS.XmCHARSET_TEXT, - OS.XmCHARSET_TEXT, - table, - table.length, - OS.XmOUTPUT_ALL); - if (ptr != 0) { - int length = OS.strlen (ptr); - byte [] buffer = new byte [length]; - OS.memmove (buffer, ptr, length); - OS.XtFree (ptr); - /* Use the character encoding for the default locale */ - directoryPath = new String (Converter.mbcsToWcs (null, buffer)); - } - OS.XmStringFree (xmString3); - int length = directoryPath.length (); - if (directoryPath.charAt (length - 1) == '*') { - directoryPath = directoryPath.substring (0, length - 1); - length--; - } - if (directoryPath.endsWith (SEPARATOR) && !directoryPath.equals (SEPARATOR)) { - directoryPath = directoryPath.substring (0, length - 1); - } - filterPath = directoryPath; - } - - /* Destroy the dialog and update the display. */ - if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog); - callback.dispose (); - - if (cancel) return null; - return directoryPath; -} -/** - * Sets the path that the dialog will use to filter - * the directories it shows to the argument, which may - * be null. If the string is null, then the operating - * system's default filter path will be used. - * <p> - * Note that the path string is platform dependent. - * For convenience, either '/' or '\' can be used - * as a path separator. - * </p> - * - * @param string the filter path - */ -public void setFilterPath (String string) { - filterPath = string; -} -/** - * Sets the dialog's message, which is a description of - * the purpose for which it was opened. This message will be - * visible on the dialog while it is open. - * - * @param string the message - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - */ -public void setMessage (String string) { - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - message = string; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java deleted file mode 100755 index 0f8d1f1021..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java +++ /dev/null @@ -1,3830 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class are responsible for managing the - * connection between SWT and the underlying operating - * system. Their most important function is to implement - * the SWT event loop in terms of the platform event model. - * They also provide various methods for accessing information - * about the operating system, and have overall control over - * the operating system resources which SWT allocates. - * <p> - * Applications which are built with SWT will <em>almost always</em> - * require only a single display. In particular, some platforms - * which SWT supports will not allow more than one <em>active</em> - * display. In other words, some platforms do not support - * creating a new display if one already exists that has not been - * sent the <code>dispose()</code> message. - * <p> - * In SWT, the thread which creates a <code>Display</code> - * instance is distinguished as the <em>user-interface thread</em> - * for that display. - * </p> - * The user-interface thread for a particular display has the - * following special attributes: - * <ul> - * <li> - * The event loop for that display must be run from the thread. - * </li> - * <li> - * Some SWT API methods (notably, most of the public methods in - * <code>Widget</code> and its subclasses), may only be called - * from the thread. (To support multi-threaded user-interface - * applications, class <code>Display</code> provides inter-thread - * communication methods which allow threads other than the - * user-interface thread to request that it perform operations - * on their behalf.) - * </li> - * <li> - * The thread is not allowed to construct other - * <code>Display</code>s until that display has been disposed. - * (Note that, this is in addition to the restriction mentioned - * above concerning platform support for multiple displays. Thus, - * the only way to have multiple simultaneously active displays, - * even on platforms which support it, is to have multiple threads.) - * </li> - * </ul> - * Enforcing these attributes allows SWT to be implemented directly - * on the underlying operating system's event model. This has - * numerous benefits including smaller footprint, better use of - * resources, safer memory management, clearer program logic, - * better performance, and fewer overall operating system threads - * required. The down side however, is that care must be taken - * (only) when constructing multi-threaded applications to use the - * inter-thread communication mechanisms which this class provides - * when required. - * </p><p> - * All SWT API methods which may only be called from the user-interface - * thread are distinguished in their documentation by indicating that - * they throw the "<code>ERROR_THREAD_INVALID_ACCESS</code>" - * SWT exception. - * </p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>Close, Dispose, Settings</dd> - * </dl> - * <p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * @see #syncExec - * @see #asyncExec - * @see #wake - * @see #readAndDispatch - * @see #sleep - * @see Device#dispose - * @see <a href="http://www.eclipse.org/swt/snippets/#display">Display snippets</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class Display extends Device { - - /* Motif Only Public Fields */ - public int xEvent; - int lastSerial; - - /* Windows, Events and Callbacks */ - Callback windowCallback; - int windowProc, shellHandle; - static String APP_NAME = "SWT"; //$NON-NLS-1$ - static final String SHELL_HANDLE_KEY = "org.eclipse.swt.internal.motif.shellHandle"; //$NON-NLS-1$ - byte [] displayName, appName, appClass; - Event [] eventQueue; - XKeyEvent keyEvent = new XKeyEvent (); - EventTable eventTable, filterTable; - - /* Widget Table */ - int freeSlot = 0; - int [] indexTable, userData; - Shell [] shellTable; - Widget [] widgetTable; - static final int GROW_SIZE = 1024; - - /* Focus */ - int focusEvent; - boolean postFocusOut; - Combo focusedCombo; - - /* Default Fonts, Colors, Insets, Widths and Heights. */ - Font defaultFont; - Font listFont, textFont, buttonFont, labelFont; - int buttonBackground, buttonForeground, buttonShadowThickness; - int compositeBackground, compositeForeground; - int compositeTopShadow, compositeBottomShadow, compositeBorder; - int listBackground, listForeground, listSelect, textBackground, textForeground; - int labelBackground, labelForeground; - int scrolledInsetX, scrolledInsetY, scrolledMarginX, scrolledMarginY; - int defaultBackground, defaultForeground; - int textHighlightThickness, blinkRate; - - /* System Colors */ - XColor COLOR_WIDGET_DARK_SHADOW, COLOR_WIDGET_NORMAL_SHADOW, COLOR_WIDGET_LIGHT_SHADOW; - XColor COLOR_WIDGET_HIGHLIGHT_SHADOW, COLOR_WIDGET_FOREGROUND, COLOR_WIDGET_BACKGROUND, COLOR_WIDGET_BORDER; - XColor COLOR_LIST_FOREGROUND, COLOR_LIST_BACKGROUND, COLOR_LIST_SELECTION, COLOR_LIST_SELECTION_TEXT; - Color COLOR_INFO_BACKGROUND; - - /* Popup Menus */ - Menu [] popups; - - /* System Images and Masks */ - int errorPixmap, infoPixmap, questionPixmap, warningPixmap, workingPixmap; - int errorMask, infoMask, questionMask, warningMask, workingMask; - - /* System Cursors */ - Cursor [] cursors = new Cursor [SWT.CURSOR_HAND + 1]; - - /* Initial Guesses for Shell Trimmings. */ - int leftBorderWidth = 2, rightBorderWidth = 2; - int topBorderHeight = 2, bottomBorderHeight = 2; - int leftResizeWidth = 3, rightResizeWidth = 3; - int topResizeHeight = 3, bottomResizeHeight = 3; - int leftTitleBorderWidth = 3, rightTitleBorderWidth = 2; - int topTitleBorderHeight = 26, bottomTitleBorderHeight = 2; - int leftTitleResizeWidth = 3, rightTitleResizeWidth = 3; - int topTitleResizeHeight = 26, bottomTitleResizeHeight = 3; - int leftTitleWidth = 0, rightTitleWidth = 0; - int topTitleHeight = 23, bottomTitleHeight = 0; - boolean ignoreTrim; - - /* Sync/Async Widget Communication */ - Synchronizer synchronizer = new Synchronizer (this); - Thread thread; - - /* Display Shutdown */ - Runnable [] disposeList; - - /* System Tray */ - Tray tray; - - /* Timers */ - int [] timerIds; - Runnable [] timerList; - Callback timerCallback; - int timerProc; - - /* Widget Timers */ - Callback windowTimerCallback; - int windowTimerProc; - - /* Key Mappings. */ - static int [] [] KeyTable = { - - /* Keyboard and Mouse Masks */ - {OS.XK_Alt_L, SWT.ALT}, - {OS.XK_Alt_R, SWT.ALT}, - {OS.XK_Meta_L, SWT.ALT}, - {OS.XK_Meta_R, SWT.ALT}, - {OS.XK_Shift_L, SWT.SHIFT}, - {OS.XK_Shift_R, SWT.SHIFT}, - {OS.XK_Control_L, SWT.CONTROL}, - {OS.XK_Control_R, SWT.CONTROL}, -// {OS.XP_????, SWT.COMMAND}, -// {OS.XP_????, SWT.COMMAND}, - - /* Non-Numeric Keypad Keys */ - {OS.XK_Up, SWT.ARROW_UP}, - {OS.XK_KP_Up, SWT.ARROW_UP}, - {OS.XK_Down, SWT.ARROW_DOWN}, - {OS.XK_KP_Down, SWT.ARROW_DOWN}, - {OS.XK_Left, SWT.ARROW_LEFT}, - {OS.XK_KP_Left, SWT.ARROW_LEFT}, - {OS.XK_Right, SWT.ARROW_RIGHT}, - {OS.XK_KP_Right, SWT.ARROW_RIGHT}, - {OS.XK_Page_Up, SWT.PAGE_UP}, - {OS.XK_KP_Page_Up, SWT.PAGE_UP}, - {OS.XK_Page_Down, SWT.PAGE_DOWN}, - {OS.XK_KP_Page_Down,SWT.PAGE_DOWN}, - {OS.XK_Home, SWT.HOME}, - {OS.XK_KP_Home, SWT.HOME}, - {OS.XK_End, SWT.END}, - {OS.XK_KP_End, SWT.END}, - {OS.XK_Insert, SWT.INSERT}, - {OS.XK_KP_Insert, SWT.INSERT}, - - /* Virtual and Ascii Keys */ - {OS.XK_BackSpace, SWT.BS}, - {OS.XK_Return, SWT.CR}, - {OS.XK_Delete, SWT.DEL}, - {OS.XK_KP_Delete, SWT.DEL}, - {OS.XK_Escape, SWT.ESC}, - {OS.XK_Linefeed, SWT.LF}, - {OS.XK_Tab, SWT.TAB}, - {OS.XK_ISO_Left_Tab,SWT.TAB}, - - /* Functions Keys */ - {OS.XK_F1, SWT.F1}, - {OS.XK_F2, SWT.F2}, - {OS.XK_F3, SWT.F3}, - {OS.XK_F4, SWT.F4}, - {OS.XK_F5, SWT.F5}, - {OS.XK_F6, SWT.F6}, - {OS.XK_F7, SWT.F7}, - {OS.XK_F8, SWT.F8}, - {OS.XK_F9, SWT.F9}, - {OS.XK_F10, SWT.F10}, - {OS.XK_F11, SWT.F11}, - {OS.XK_F12, SWT.F12}, - {OS.XK_F13, SWT.F13}, - {OS.XK_F14, SWT.F14}, - {OS.XK_F15, SWT.F15}, - - /* Numeric Keypad Keys */ - {OS.XK_KP_Multiply, SWT.KEYPAD_MULTIPLY}, - {OS.XK_KP_Add, SWT.KEYPAD_ADD}, - {OS.XK_KP_Enter, SWT.KEYPAD_CR}, - {OS.XK_KP_Subtract, SWT.KEYPAD_SUBTRACT}, - {OS.XK_KP_Decimal, SWT.KEYPAD_DECIMAL}, - {OS.XK_KP_Divide, SWT.KEYPAD_DIVIDE}, - {OS.XK_KP_0, SWT.KEYPAD_0}, - {OS.XK_KP_1, SWT.KEYPAD_1}, - {OS.XK_KP_2, SWT.KEYPAD_2}, - {OS.XK_KP_3, SWT.KEYPAD_3}, - {OS.XK_KP_4, SWT.KEYPAD_4}, - {OS.XK_KP_5, SWT.KEYPAD_5}, - {OS.XK_KP_6, SWT.KEYPAD_6}, - {OS.XK_KP_7, SWT.KEYPAD_7}, - {OS.XK_KP_8, SWT.KEYPAD_8}, - {OS.XK_KP_9, SWT.KEYPAD_9}, - {OS.XK_KP_Equal, SWT.KEYPAD_EQUAL}, - - /* Other keys */ - {OS.XK_Caps_Lock, SWT.CAPS_LOCK}, - {OS.XK_Num_Lock, SWT.NUM_LOCK}, - {OS.XK_Scroll_Lock, SWT.SCROLL_LOCK}, - {OS.XK_Pause, SWT.PAUSE}, - {OS.XK_Break, SWT.BREAK}, - {OS.XK_Print, SWT.PRINT_SCREEN}, - {OS.XK_Help, SWT.HELP}, - - }; - static String numLock; - - /* Multiple Displays. */ - static Display Default; - static Display [] Displays = new Display [4]; - - /* Double Click */ - int lastTime, lastButton, clickCount = 1; - - /* Current caret */ - Caret currentCaret; - Callback caretCallback; - int caretID, caretProc; - - /* Workaround for GP when disposing a display */ - static boolean DisplayDisposed; - - /* Package Name */ - static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets."; //$NON-NLS-1$ - /* - * This code is intentionally commented. In order - * to support CLDC, .class cannot be used because - * it does not compile on some Java compilers when - * they are targeted for CLDC. - */ -// static { -// String name = Display.class.getName (); -// int index = name.lastIndexOf ('.'); -// PACKAGE_PREFIX = name.substring (0, index + 1); -// } - - /* Mouse Hover */ - Callback mouseHoverCallback; - int mouseHoverID, mouseHoverProc; - int mouseHoverHandle, toolTipHandle; - - /* Xt Translations */ - int dragTranslations; - int arrowTranslations, tabTranslations; - - /* Check Expose Proc */ - Callback checkExposeCallback; - int checkExposeProc, exposeCount, lastExpose; - XExposeEvent xExposeEvent = new XExposeEvent (); - - /* Check Resize Proc */ - Callback checkResizeCallback; - int checkResizeProc, resizeWidth, resizeHeight, resizeCount, resizeWindow; - XConfigureEvent xConfigureEvent = new XConfigureEvent (); - - /* Focus Proc */ - Callback focusCallback; - int focusProc; - - /* Wake and Sleep */ - Callback wakeCallback; - int wakeProc, read_fd, write_fd, inputID; - byte [] wake_buffer = new byte [1]; - int [] timeout = new int [2]; - byte [] fd_set; - - /* Display Data */ - Object data; - String [] keys; - Object [] values; - - /* - * TEMPORARY CODE. Install the runnable that - * gets the current display. This code will - * be removed in the future. - */ - static { - DeviceFinder = new Runnable () { - public void run () { - Device device = getCurrent (); - if (device == null) { - device = getDefault (); - } - setDevice (device); - } - }; - } - -/* -* TEMPORARY CODE. -*/ -static void setDevice (Device device) { - CurrentDevice = device; -} - -/** - * Constructs a new instance of this class. - * <p> - * Note: The resulting display is marked as the <em>current</em> - * display. If this is the first display which has been - * constructed since the application started, it is also - * marked as the <em>default</em> display. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if called from a thread that already created an existing display</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see #getCurrent - * @see #getDefault - * @see Widget#checkSubclass - * @see Shell - */ -public Display () { - this (null); -} -/** - * Constructs a new instance of this class using the parameter. - * - * @param data the device data - */ -public Display (DeviceData data) { - super (checkNull (data)); -} -static DeviceData checkNull (DeviceData data) { - if (data == null) data = new DeviceData (); - if (data.application_name == null) { - data.application_name = APP_NAME; - } - if (data.application_class == null) { - data.application_class = APP_NAME; - } - return data; -} -protected void checkDevice () { - if (thread == null) error (SWT.ERROR_WIDGET_DISPOSED); - if (thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); -} -void addMouseHoverTimeOut (int handle) { - if (mouseHoverID != 0) OS.XtRemoveTimeOut (mouseHoverID); - int xtContext = OS.XtDisplayToApplicationContext (xDisplay); - mouseHoverID = OS.XtAppAddTimeOut (xtContext, 400, mouseHoverProc, handle); - mouseHoverHandle = handle; -} -void addWidget (int handle, Widget widget) { - if (handle == 0) return; - if (OS.XtIsSubclass (handle, OS.shellWidgetClass ())) { - for (int i=0; i<shellTable.length; i++) { - if (shellTable [i] == null) { - shellTable [i] = (Shell) widget; - return; - } - } - Shell [] newShells = new Shell [shellTable.length + GROW_SIZE / 8]; - System.arraycopy (shellTable, 0, newShells, 0, shellTable.length); - newShells [shellTable.length] = (Shell) widget; - shellTable = newShells; - return; - } - if (freeSlot == -1) { - int length = (freeSlot = indexTable.length) + GROW_SIZE; - int [] newIndexTable = new int [length]; - Widget [] newWidgetTable = new Widget [length]; - System.arraycopy (indexTable, 0, newIndexTable, 0, freeSlot); - System.arraycopy (widgetTable, 0, newWidgetTable, 0, freeSlot); - for (int i=freeSlot; i<length-1; i++) { - newIndexTable [i] = i + 1; - } - newIndexTable [length - 1] = -1; - indexTable = newIndexTable; - widgetTable = newWidgetTable; - } - userData [1] = freeSlot + 1; - OS.XtSetValues (handle, userData, userData.length / 2); - int oldSlot = freeSlot; - freeSlot = indexTable [oldSlot]; - indexTable [oldSlot] = -2; - widgetTable [oldSlot] = widget; -} -/** - * Adds the listener to the collection of listeners who will - * be notified when an event of the given type occurs anywhere - * in a widget. The event type is one of the event constants - * defined in class <code>SWT</code>. When the event does occur, - * the listener is notified by sending it the <code>handleEvent()</code> - * message. - * <p> - * Setting the type of an event to <code>SWT.None</code> from - * within the <code>handleEvent()</code> method can be used to - * change the event type and stop subsequent Java listeners - * from running. Because event filters run before other listeners, - * event filters can both block other listeners and set arbitrary - * fields within an event. For this reason, event filters are both - * powerful and dangerous. They should generally be avoided for - * performance, debugging and code maintenance reasons. - * </p> - * - * @param eventType the type of event to listen for - * @param listener the listener which should be notified when the event occurs - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see Listener - * @see SWT - * @see #removeFilter - * @see #removeListener - * - * @since 3.0 - */ -public void addFilter (int eventType, Listener listener) { - checkDevice (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (filterTable == null) filterTable = new EventTable (); - filterTable.hook (eventType, listener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when an event of the given type occurs. The event - * type is one of the event constants defined in class <code>SWT</code>. - * When the event does occur in the display, the listener is notified by - * sending it the <code>handleEvent()</code> message. - * - * @param eventType the type of event to listen for - * @param listener the listener which should be notified when the event occurs - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see Listener - * @see SWT - * @see #removeListener - * - * @since 2.0 - */ -public void addListener (int eventType, Listener listener) { - checkDevice (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) eventTable = new EventTable (); - eventTable.hook (eventType, listener); -} -void addPopup (Menu menu) { - if (popups == null) popups = new Menu [4]; - int length = popups.length; - for (int i=0; i<length; i++) { - if (popups [i] == menu) return; - } - int index = 0; - while (index < length) { - if (popups [index] == null) break; - index++; - } - if (index == length) { - Menu [] newPopups = new Menu [length + 4]; - System.arraycopy (popups, 0, newPopups, 0, length); - popups = newPopups; - } - popups [index] = menu; -} -/** - * Causes the <code>run()</code> method of the runnable to - * be invoked by the user-interface thread at the next - * reasonable opportunity. The caller of this method continues - * to run in parallel, and is not notified when the - * runnable has completed. Specifying <code>null</code> as the - * runnable simply wakes the user-interface thread when run. - * <p> - * Note that at the time the runnable is invoked, widgets - * that have the receiver as their display may have been - * disposed. Therefore, it is necessary to check for this - * case inside the runnable before accessing the widget. - * </p> - * - * @param runnable code to run on the user-interface thread or <code>null</code> - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #syncExec - */ -public void asyncExec (Runnable runnable) { - synchronized (Device.class) { - if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); - synchronizer.asyncExec (runnable); - } -} -/** - * Causes the system hardware to emit a short sound - * (if it supports this capability). - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void beep () { - checkDevice (); - OS.XBell (xDisplay, 100); - OS.XFlush (xDisplay); -} -int caretProc (int clientData, int id) { - caretID = 0; - if (currentCaret == null) return 0; - if (currentCaret.blinkCaret ()) { - int blinkRate = currentCaret.blinkRate; - if (blinkRate == 0) return 0; - int xtContext = OS.XtDisplayToApplicationContext (xDisplay); - caretID = OS.XtAppAddTimeOut (xtContext, blinkRate, caretProc, 0); - } else { - currentCaret = null; - } - return 0; -} - -int checkExposeProc (int display, int event, int window) { - OS.memmove (xExposeEvent, event, XExposeEvent.sizeof); - if (xExposeEvent.window != window) return 0; - switch (xExposeEvent.type) { - case OS.Expose: - case OS.GraphicsExpose: - exposeCount++; - lastExpose = event; - xExposeEvent.count = 1; - OS.memmove (event, xExposeEvent, XExposeEvent.sizeof); - break; - } - return 0; -} -int checkResizeProc (int display, int event, int arg) { - OS.memmove (xConfigureEvent, event, XConfigureEvent.sizeof); - if (xConfigureEvent.window != resizeWindow) return 0; - switch (xConfigureEvent.type) { - case OS.ConfigureNotify: - int width = xConfigureEvent.width; - int height = xConfigureEvent.height; - if (width != resizeWidth || height != resizeHeight) { - resizeCount++; - } - break; - } - return 0; -} -static void checkDisplay (Thread thread, boolean multiple) { - synchronized (Device.class) { - for (int i=0; i<Displays.length; i++) { - if (Displays [i] != null) { - if (!multiple) SWT.error (SWT.ERROR_NOT_IMPLEMENTED, null, " [multiple displays]"); //$NON-NLS-1$ - if (Displays [i].thread == thread) SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS); - } - } - } -} -/** - * Checks that this class can be subclassed. - * <p> - * IMPORTANT: See the comment in <code>Widget.checkSubclass()</code>. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see Widget#checkSubclass - */ -protected void checkSubclass () { - if (!Display.isValidClass (getClass ())) { - error (SWT.ERROR_INVALID_SUBCLASS); - } -} -/** - * Requests that the connection between SWT and the underlying - * operating system be closed. - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see Device#dispose - * - * @since 2.0 - */ -public void close () { - checkDevice (); - Event event = new Event (); - sendEvent (SWT.Close, event); - if (event.doit) dispose (); -} -String convertToLf(String text) { - char Cr = '\r'; - char Lf = '\n'; - int length = text.length (); - if (length == 0) return text; - - /* Check for an LF or CR/LF. Assume the rest of the string - * is formated that way. This will not work if the string - * contains mixed delimiters. */ - int i = text.indexOf (Lf, 0); - if (i == -1 || i == 0) return text; - if (text.charAt (i - 1) != Cr) return text; - - /* The string is formatted with CR/LF. - * Create a new string with the LF line delimiter. */ - i = 0; - StringBuffer result = new StringBuffer (); - while (i < length) { - int j = text.indexOf (Cr, i); - if (j == -1) j = length; - String s = text.substring (i, j); - result.append (s); - i = j + 2; - result.append (Lf); - } - return result.toString (); -} -/** - * Creates the device in the operating system. If the device - * does not have a handle, this method may do nothing depending - * on the device. - * <p> - * This method is called before <code>init</code>. - * </p> - * - * @param data the DeviceData which describes the receiver - * - * @see #init - */ -protected void create (DeviceData data) { - checkSubclass (); - checkDisplay (thread = Thread.currentThread (), true); - createDisplay (data); - register (this); - if (Default == null) Default = this; -} -void createDisplay (DeviceData data) { - /* Create the AppContext */ - xEvent = OS.XtMalloc (XEvent.sizeof); - - int dpy = 0; - if (Default == null) { - int xtContext = OS.__XtDefaultAppContext (); - int [] dpy_return = new int [1]; - int [] num_dpy_return = new int [1]; - OS.XtGetDisplays (xtContext, dpy_return, num_dpy_return); - if (num_dpy_return [0] > 0) { - OS.memmove (dpy_return, dpy_return [0], 4); - dpy = dpy_return [0]; - } - } - - if (dpy != 0) { - xDisplay = dpy; - } else { - int [] argc = new int [] {0}; - int xtContext = OS.XtCreateApplicationContext (); - OS.XtSetLanguageProc (xtContext, 0, 0); - - /* - * Feature in Linux. On some DBCS Linux platforms, the default - * font is not be properly initialized to contain a font set. - * This causes the IME to fail. The fix is to set a fallback - * resource with an appropriated font to ensure a font set is - * found. - */ - int ptr1 = 0, ptr2 = 0; - if (OS.IsLinux && OS.IsDBLocale) { - String resource = "*fontList: -*-*-medium-r-*-*-*-120-*-*-*-*-*-*:"; //$NON-NLS-1$ - byte [] buffer = Converter.wcsToMbcs (null, resource, true); - ptr1 = OS.XtMalloc (buffer.length); - if (ptr1 != 0) OS.memmove (ptr1, buffer, buffer.length); - int [] spec = new int[]{ptr1, 0}; - ptr2 = OS.XtMalloc (spec.length * 4); - if (ptr2 != 0)OS.memmove (ptr2, spec, spec.length * 4); - OS.XtAppSetFallbackResources(xtContext, ptr2); - } - - /* Compute the display name, application name and class */ - String display_name = null; - String application_name = APP_NAME; - String application_class = APP_NAME; - if (data != null) { - if (data.display_name != null) display_name = data.display_name; - if (data.application_name != null) application_name = data.application_name; - if (data.application_class != null) application_class = data.application_class; - } - /* Use the character encoding for the default locale */ - if (display_name != null) displayName = Converter.wcsToMbcs (null, display_name, true); - if (application_name != null) appName = Converter.wcsToMbcs (null, application_name, true); - if (application_class != null) appClass = Converter.wcsToMbcs (null, application_class, true); - - /* Create the XDisplay */ - xDisplay = OS.XtOpenDisplay (xtContext, displayName, appName, appClass, 0, 0, argc, 0); - DisplayDisposed = false; - - if (ptr2 != 0) { - OS.XtAppSetFallbackResources (xtContext, 0); - OS.XtFree (ptr2); - } - if (ptr1 != 0) OS.XtFree (ptr1); - } -} -int createMask (int pixmap) { - if (pixmap == 0) return 0; - int [] unused = new int [1]; int [] width = new int [1]; int [] height = new int [1]; - OS.XGetGeometry (xDisplay, pixmap, unused, unused, unused, width, height, unused, unused); - int mask = OS.XCreatePixmap (xDisplay, pixmap, width [0], height [0], 1); - int gc = OS.XCreateGC (xDisplay, mask, 0, null); - if (OS.IsSunOS) { - OS.XSetBackground (xDisplay, gc, 0); - OS.XSetForeground (xDisplay, gc, 1); - } - OS.XCopyPlane (xDisplay, pixmap, mask, gc, 0, 0, width [0], height [0], 0, 0, 1); - OS.XFreeGC (xDisplay, gc); - return mask; -} -int createPixmap (String name) { - int screen = OS.XDefaultScreenOfDisplay (xDisplay); - int fgPixel = OS.XBlackPixel (xDisplay, OS.XDefaultScreen (xDisplay)); - int bgPixel = OS.XWhitePixel (xDisplay, OS.XDefaultScreen (xDisplay)); - byte[] buffer = Converter.wcsToMbcs (null, name, true); - int pixmap = OS.XmGetPixmap (screen, buffer, fgPixel, bgPixel); - if (pixmap == OS.XmUNSPECIFIED_PIXMAP) { - buffer = Converter.wcsToMbcs (null, "default_" + name, true); //$NON-NLS-1$ - pixmap = OS.XmGetPixmap (screen, buffer, fgPixel, bgPixel); - if (pixmap == OS.XmUNSPECIFIED_PIXMAP) { - if (OS.IsSunOS) { - buffer = Converter.wcsToMbcs (null, "/usr/dt/share/include/bitmaps/" + name, true); //$NON-NLS-1$ - pixmap = OS.XmGetPixmap (screen, buffer, fgPixel, bgPixel); - if (pixmap == OS.XmUNSPECIFIED_PIXMAP) pixmap = 0; - } else { - pixmap = 0; - } - } - } - return pixmap; -} -static void deregister (Display display) { - synchronized (Device.class) { - for (int i=0; i<Displays.length; i++) { - if (display == Displays [i]) Displays [i] = null; - } - } -} -/** - * Destroys the device in the operating system and releases - * the device's handle. If the device does not have a handle, - * this method may do nothing depending on the device. - * <p> - * This method is called after <code>release</code>. - * </p> - * @see Device#dispose - * @see #release - */ -protected void destroy () { - if (this == Default) Default = null; - deregister (this); - destroyDisplay (); -} -void destroyDisplay () { - /* - * Bug in Motif. For some reason, XtAppCreateShell GP's when called - * after an application context has been destroyed. The fix is to - * destroy the default XmDisplay associated with the X Display for - * the application context. The following code fragment GP's without - * this work around: - * - * OS.XtToolkitInitialize(); - * int xContext = OS.XtCreateApplicationContext(); - * int xDisplay = OS.XtOpenDisplay(xContext, null, null, null, 0, 0, new int[1], 0); - * OS.XtAppCreateShell(null, null, OS.topLevelShellWidgetClass(), xDisplay, null, 0); - * //OS.XtDestroyWidget (OS.XmGetXmDisplay (xDisplay)); - * OS.XtDestroyApplicationContext(xContext); - * xContext = OS.XtCreateApplicationContext(); - * xDisplay = OS.XtOpenDisplay(xContext, null, null, null, 0, 0, new int[1], 0); - * OS.XtAppCreateShell(null, null, OS.topLevelShellWidgetClass(), xDisplay, null, 0); - * OS.XtDestroyApplicationContext(xContext); - */ - if (!OS.IsSunOS) { - OS.XtDestroyWidget (OS.XmGetXmDisplay (xDisplay)); - } - - /* - * Destroy AppContext (this destroys the display) - */ - int xtContext = OS.XtDisplayToApplicationContext (xDisplay); - OS.XtDestroyApplicationContext (xtContext); - DisplayDisposed = true; -} -/** - * Causes the <code>run()</code> method of the runnable to - * be invoked by the user-interface thread just before the - * receiver is disposed. Specifying a <code>null</code> runnable - * is ignored. - * - * @param runnable code to run at dispose time. - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void disposeExec (Runnable runnable) { - checkDevice (); - if (disposeList == null) disposeList = new Runnable [4]; - for (int i=0; i<disposeList.length; i++) { - if (disposeList [i] == null) { - disposeList [i] = runnable; - return; - } - } - Runnable [] newDisposeList = new Runnable [disposeList.length + 4]; - System.arraycopy (disposeList, 0, newDisposeList, 0, disposeList.length); - newDisposeList [disposeList.length] = runnable; - disposeList = newDisposeList; -} -void error (int code) { - SWT.error(code); -} -boolean filterEvent (Event event) { - if (filterTable != null) filterTable.sendEvent (event); - return false; -} -boolean filters (int eventType) { - if (filterTable == null) return false; - return filterTable.hooks (eventType); -} -boolean filterEvent (int event) { - - /* Check the event and find the widget */ - OS.memmove (keyEvent, event, XKeyEvent.sizeof); - if (keyEvent.type != OS.KeyPress) return false; - if (keyEvent.keycode == 0) return false; - int xWindow = keyEvent.window; - if (xWindow == 0) return false; - int handle = OS.XtWindowToWidget (xDisplay, xWindow); - if (handle == 0) return false; - handle = OS.XmGetFocusWidget (handle); - if (handle == 0) return false; - Widget widget = getWidget (handle); - if (widget == null) return false; - - /* Get the unaffected character and keysym */ - char key = 0; - byte [] buffer = new byte [5]; - int [] keysym = new int [1]; - int oldState = keyEvent.state; - keyEvent.state = 0; - int length = OS.XLookupString (keyEvent, buffer, buffer.length, keysym, null); - keyEvent.state = oldState; - fixKey (keysym, buffer, 0); - if (length != 0) { - char [] result = Converter.mbcsToWcs (null, buffer); - if (result.length != 0) key = result [0]; - } - keysym [0] &= 0xFFFF; - - /* - * Bug in AIX. If XFilterEvent() is called for every key event, accelerators - * do not work. XFilterEvent() is needed on AIX to invoke the default button. - * The fix is to call XFilterEvent() only for return keys. This means that an - * accelerator that is only a return key will not work. - */ - if (keysym [0] == OS.XK_Return || keysym [0] == OS.XK_KP_Enter) { - /* - * Bug in Linux. If XFilter() is called more than once for the same - * event, it causes an infinite loop. The fix to remember the serial - * number and never call XFilterEvent() twice for the same event. - */ - if (keyEvent.serial != lastSerial) { - if (OS.XFilterEvent (event, OS.XtWindow (handle))) return true; - lastSerial = keyEvent.serial; - } - } - - /* - * Bug in Solaris. When accelerators are set more - * than once in the same menu bar, the time it takes - * to set the accelerator increases exponentially. - * The fix is to implement our own accelerator table - * on Solaris. - */ - if (OS.IsSunOS) { - /* Ignore modifiers. */ - switch (keysym [0]) { - case OS.XK_Control_L: - case OS.XK_Control_R: - case OS.XK_Alt_L: - case OS.XK_Alt_R: - case OS.XK_Meta_L: - case OS.XK_Meta_R: - case OS.XK_Shift_L: - case OS.XK_Shift_R: break; - default: - if (widget.translateAccelerator (key, keysym [0], keyEvent, true)) { - return true; - } - } - } - - /* Check for a mnemonic key */ - if (key != 0) { - if (widget.translateMnemonic (key, keysym [0], keyEvent)) return true; - } - - /* Check for a traversal key */ - switch (keysym [0]) { - case OS.XK_Escape: - case OS.XK_Tab: - case OS.XK_KP_Enter: - case OS.XK_Return: - case OS.XK_Up: - case OS.XK_Down: - case OS.XK_Left: - case OS.XK_Right: - case OS.XK_Page_Up: - case OS.XK_Page_Down: - /* - * If a traversal key has been assigned as an accelerator, - * allow the accelerator to run, not the traversal key. - */ - if (!OS.IsSunOS) { - if (widget.translateAccelerator (key, keysym [0], keyEvent, true)) { - return true; - } - } - if (widget.translateTraversal (keysym [0], keyEvent)) return true; - } - - /* Answer false because the event was not processed */ - return false; -} -/** - * Given the operating system handle for a widget, returns - * the instance of the <code>Widget</code> subclass which - * represents it in the currently running application, if - * such exists, or null if no matching widget can be found. - * <p> - * <b>IMPORTANT:</b> This method should not be called from - * application code. The arguments are platform-specific. - * </p> - * - * @param handle the handle for the widget - * @return the SWT widget that the handle represents - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Widget findWidget (int handle) { - checkDevice (); - return getWidget (handle); -} -/** - * Given the operating system handle for a widget, - * and widget-specific id, returns the instance of - * the <code>Widget</code> subclass which represents - * the handle/id pair in the currently running application, - * if such exists, or null if no matching widget can be found. - * <p> - * <b>IMPORTANT:</b> This method should not be called from - * application code. The arguments are platform-specific. - * </p> - * - * @param handle the handle for the widget - * @param id the id for the subwidget (usually an item) - * @return the SWT widget that the handle/id pair represents - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public Widget findWidget (int handle, int id) { - checkDevice (); - return null; -} -/** - * Given a widget and a widget-specific id, returns the - * instance of the <code>Widget</code> subclass which represents - * the widget/id pair in the currently running application, - * if such exists, or null if no matching widget can be found. - * - * @param widget the widget - * @param id the id for the subwidget (usually an item) - * @return the SWT subwidget (usually an item) that the widget/id pair represents - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.3 - */ -public Widget findWidget (Widget widget, int id) { - checkDevice (); - return null; -} -boolean fixKey (int[] keysym, byte[] buffer, int state) { - /* - * Bug in MOTIF. On Solaris only, XK_F11 and XK_F12 are not - * translated correctly by XLookupString(). They are mapped - * to SunXK_F36 and SunXK_F37 respectively. The fix is to - * look for these values (and others) and explicitly correct - * them. - */ - if (OS.IsSunOS && keysym [0] != 0) { - switch (keysym [0]) { - case OS.SunXK_F36: - keysym [0] = OS.XK_F11; - buffer [0] = 0; - break; - case OS.SunXK_F37: - keysym [0] = OS.XK_F12; - buffer [0] = 0; - break; - case OS.XK_R1: keysym [0] = OS.XK_Pause; break; - case OS.XK_R2: keysym [0] = OS.XK_Print; break; - case OS.XK_R3: keysym [0] = OS.XK_Scroll_Lock; break; - case OS.XK_R4: keysym [0] = OS.XK_KP_Subtract; break; - case OS.XK_R5: keysym [0] = OS.XK_KP_Divide; break; - case OS.XK_R6: keysym [0] = OS.XK_KP_Multiply; break; - case OS.XK_R7: keysym [0] = OS.XK_KP_Home; break; - case OS.XK_R9: keysym [0] = OS.XK_KP_Page_Up; break; - case OS.XK_R13: keysym [0] = OS.XK_KP_End; break; - case OS.XK_R15: keysym [0] = OS.XK_KP_Page_Down; break; - } - /* - * Bug in MOTIF. On Solaris only, there is garbage in the - * high 16-bits for Keysyms such as XK_Down. Since Keysyms - * must be 16-bits to fit into a Character, mask away the - * high 16-bits on all platforms. - */ - keysym [0] &= 0xFFFF; - } - - /* - * Bug in Motif. On HP-UX only, Shift+F9, Shift+F10, Shift+F11 - * and Shift+F12 are not translated correctly by XLookupString(). - * The fix is to look for these values (and others) explicitly - * and correct them. - */ - if (OS.IsHPUX && keysym [0] != 0) { - switch (keysym [0]) { - case OS.XK_KP_F1: keysym [0] = OS.XK_F9; break; - case OS.XK_KP_F2: keysym [0] = OS.XK_F10; break; - case OS.XK_KP_F3: keysym [0] = OS.XK_F11; break; - case OS.XK_KP_F4: keysym [0] = OS.XK_F12; break; - case OS.hpXK_BackTab: keysym [0] = OS.XK_ISO_Left_Tab; break; - } - } - - /* - * Bug in Motif. There are some keycodes for which - * XLookupString() does not translate the character. - * Some of examples are Shift+Tab and Ctrl+Space. - */ - switch (keysym [0]) { - case OS.XK_KP_Delete: buffer [0] = 0x7f; break; - case OS.XK_ISO_Left_Tab: buffer [0] = '\t'; break; - case OS.XK_space: buffer [0] = ' '; break; - } - - /* - * Feature in MOTIF. For some reason, XLookupString() fails - * to translate both the keysym and the character when the - * control key is down. For example, Ctrl+2 has the correct - * keysym value (50) but no character value, while Ctrl+/ has - * the keysym value (2F) but an invalid character value - * (1F). It seems that Motif is applying the algorithm to - * convert a character to a control character for characters - * that are not valid control characters. The fix is to test - * for 7-bit ASCII keysym values that fall outside of the - * the valid control character range and use the keysym value - * as the character, not the incorrect value that XLookupString() - * returns. Even though lower case values are not strictly - * valid control characters, they are included in the range. - * - * Some other cases include Ctrl+3..Ctr+8, Ctrl+[. - */ - boolean isNull = false; - int key = keysym [0]; - if ((state & OS.ControlMask) != 0) { - if (0 <= key && key <= 0x7F) { - if ('a' <= key && key <= 'z') key -= 'a' - 'A'; - if (!(64 <= key && key <= 95)) buffer [0] = (byte) key; - isNull = key == '@' && buffer [0] == 0; - } else { - switch (keysym [0]) { - case OS.XK_KP_0: buffer [0] = '0'; break; - case OS.XK_KP_1: buffer [0] = '1'; break; - case OS.XK_KP_2: buffer [0] = '2'; break; - case OS.XK_KP_3: buffer [0] = '3'; break; - case OS.XK_KP_4: buffer [0] = '4'; break; - case OS.XK_KP_5: buffer [0] = '5'; break; - case OS.XK_KP_6: buffer [0] = '6'; break; - case OS.XK_KP_7: buffer [0] = '7'; break; - case OS.XK_KP_8: buffer [0] = '8'; break; - case OS.XK_KP_9: buffer [0] = '9'; break; - } - } - } - return isNull; -} -int focusProc (int w, int client_data, int call_data, int continue_to_dispatch) { - Widget widget = getWidget (client_data); - if (widget == null) return 0; - return widget.focusProc (w, client_data, call_data, continue_to_dispatch); -} -/** - * Returns the currently active <code>Shell</code>, or null - * if no shell belonging to the currently running application - * is active. - * - * @return the active shell or null - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Shell getActiveShell () { - checkDevice (); - int [] buffer1 = new int [1], buffer2 = new int [1]; - OS.XGetInputFocus (xDisplay, buffer1, buffer2); - int xWindow = buffer1 [0]; - if (xWindow == 0) return null; - int handle = OS.XtWindowToWidget (xDisplay, xWindow); - if (handle == 0) return null; - do { - if (OS.XtIsSubclass (handle, OS.shellWidgetClass ())) { - Widget widget = getWidget (handle); - if (widget instanceof Shell) return (Shell) widget; - return null; - } - } while ((handle = OS.XtParent (handle)) != 0); - return null; -} -/** - * Returns the display which the currently running thread is - * the user-interface thread for, or null if the currently - * running thread is not a user-interface thread for any display. - * - * @return the current display - */ -public static Display getCurrent () { - return findDisplay (Thread.currentThread ()); -} -/** - * Returns the display which the given thread is the - * user-interface thread for, or null if the given thread - * is not a user-interface thread for any display. Specifying - * <code>null</code> as the thread will return <code>null</code> - * for the display. - * - * @param thread the user-interface thread - * @return the display for the given thread - */ -public static Display findDisplay (Thread thread) { - synchronized (Device.class) { - for (int i=0; i<Displays.length; i++) { - Display display = Displays [i]; - if (display != null && display.thread == thread) { - return display; - } - } - return null; - } -} -int getCaretBlinkTime () { -// checkDevice (); - return blinkRate; -} -/** - * Returns the control which the on-screen pointer is currently - * over top of, or null if it is not currently over one of the - * controls built by the currently running application. - * - * @return the control under the cursor - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Control getCursorControl () { - checkDevice (); - int [] unused = new int [1], buffer = new int [1]; - int xWindow, xParent = OS.XDefaultRootWindow (xDisplay); - do { - if (OS.XQueryPointer (xDisplay, xParent, unused, buffer, unused, unused, unused, unused, unused) == 0) { - return null; - } - if ((xWindow = buffer [0]) != 0) xParent = xWindow; - } while (xWindow != 0); - int handle = OS.XtWindowToWidget (xDisplay, xParent); - if (handle == 0) return null; - do { - Widget widget = getWidget (handle); - if (widget != null && widget instanceof Control) { - Control control = (Control) widget; - if (control.isEnabled ()) return control; - } - } while ((handle = OS.XtParent (handle)) != 0); - return null; -} -/** - * Returns the location of the on-screen pointer relative - * to the top left corner of the screen. - * - * @return the cursor location - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Point getCursorLocation () { - checkDevice (); - int window = OS.XDefaultRootWindow (xDisplay); - int [] rootX = new int [1], rootY = new int [1], unused = new int [1]; - OS.XQueryPointer (xDisplay, window, unused, unused, rootX, rootY, unused, unused, unused); - return new Point (rootX [0], rootY [0]); -} -/** - * Returns an array containing the recommended cursor sizes. - * - * @return the array of cursor sizes - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.0 - */ -public Point [] getCursorSizes() { - checkDevice (); - int xDrawable = OS.XDefaultRootWindow (xDisplay); - int [] width_return = new int [1], height_return = new int [1]; - OS.XQueryBestCursor (xDisplay, xDrawable, 16, 16, width_return, height_return); - Point pt = new Point (width_return [0], height_return [0]); - OS.XQueryBestCursor (xDisplay, xDrawable, 32, 32, width_return, height_return); - return pt.x == width_return [0] && pt.y == height_return [0] ? - new Point [] {pt} : new Point [] {pt, new Point (width_return [0], height_return [0])}; -} -/** - * Returns the default display. One is created (making the - * thread that invokes this method its user-interface thread) - * if it did not already exist. - * - * @return the default display - */ -public static Display getDefault () { - synchronized (Device.class) { - if (Default == null) Default = new Display (); - return Default; - } -} -/** - * Returns the application defined property of the receiver - * with the specified name, or null if it has not been set. - * <p> - * Applications may have associated arbitrary objects with the - * receiver in this fashion. If the objects stored in the - * properties need to be notified when the display is disposed - * of, it is the application's responsibility to provide a - * <code>disposeExec()</code> handler which does so. - * </p> - * - * @param key the name of the property - * @return the value of the property or null if it has not been set - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the key is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #setData(String, Object) - * @see #disposeExec(Runnable) - */ -public Object getData (String key) { - checkDevice (); - if (key == null) error (SWT.ERROR_NULL_ARGUMENT); - if (key.equals (SHELL_HANDLE_KEY)) { - return new Integer(shellHandle); - } - if (keys == null) return null; - for (int i=0; i<keys.length; i++) { - if (keys [i].equals (key)) return values [i]; - } - return null; -} -/** - * Returns the application defined, display specific data - * associated with the receiver, or null if it has not been - * set. The <em>display specific data</em> is a single, - * unnamed field that is stored with every display. - * <p> - * Applications may put arbitrary objects in this field. If - * the object stored in the display specific data needs to - * be notified when the display is disposed of, it is the - * application's responsibility to provide a - * <code>disposeExec()</code> handler which does so. - * </p> - * - * @return the display specific data - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #setData(Object) - * @see #disposeExec(Runnable) - */ -public Object getData () { - checkDevice (); - return data; -} -/** - * Returns the button dismissal alignment, one of <code>LEFT</code> or <code>RIGHT</code>. - * The button dismissal alignment is the ordering that should be used when positioning the - * default dismissal button for a dialog. For example, in a dialog that contains an OK and - * CANCEL button, on platforms where the button dismissal alignment is <code>LEFT</code>, the - * button ordering should be OK/CANCEL. When button dismissal alignment is <code>RIGHT</code>, - * the button ordering should be CANCEL/OK. - * - * @return the button dismissal order - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 2.1 - */ -public int getDismissalAlignment () { - checkDevice (); - return SWT.LEFT; -} -/** - * Returns the longest duration, in milliseconds, between - * two mouse button clicks that will be considered a - * <em>double click</em> by the underlying operating system. - * - * @return the double click time - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int getDoubleClickTime () { - checkDevice (); - return OS.XtGetMultiClickTime (xDisplay); -} -/** - * Returns the control which currently has keyboard focus, - * or null if keyboard events are not currently going to - * any of the controls built by the currently running - * application. - * - * @return the control under the cursor - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Control getFocusControl () { - checkDevice (); - int [] buffer1 = new int [1], buffer2 = new int [1]; - OS.XGetInputFocus (xDisplay, buffer1, buffer2); - int xWindow = buffer1 [0]; - if (xWindow == 0) return null; - int handle = OS.XtWindowToWidget (xDisplay, xWindow); - if (handle == 0) return null; - handle = OS.XmGetFocusWidget (handle); - if (handle == 0) return null; - do { - Widget widget = getWidget (handle); - if (widget != null && widget instanceof Control) { - Control control = (Control) widget; - return control.isEnabled () ? control : null; - } - } while ((handle = OS.XtParent (handle)) != 0); - return null; -} -/** - * Returns true when the high contrast mode is enabled. - * Otherwise, false is returned. - * <p> - * Note: This operation is a hint and is not supported on - * platforms that do not have this concept. - * </p> - * - * @return the high contrast mode - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.0 - */ -public boolean getHighContrast () { - checkDevice (); - return false; -} -/** - * Returns the maximum allowed depth of icons on this display, in bits per pixel. - * On some platforms, this may be different than the actual depth of the display. - * - * @return the maximum icon depth - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see Device#getDepth - */ -public int getIconDepth () { - return getDepth (); -} -/** - * Returns an array containing the recommended icon sizes. - * - * @return the array of icon sizes - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see Decorations#setImages(Image[]) - * - * @since 3.0 - */ -public Point [] getIconSizes () { - checkDevice (); - int w = OS.XDefaultRootWindow (xDisplay); - int [] size_list_return = new int [1]; - int [] count_return = new int [1]; - Point min, max; - int status = OS.XGetIconSizes (xDisplay, w, size_list_return, count_return); - if (status != 0 && count_return [0] > 0) { - XIconSize iconSize = new XIconSize (); - OS.memmove (iconSize, size_list_return [0], XIconSize.sizeof); - min = new Point (iconSize.min_width, iconSize.min_height); - max = new Point (iconSize.max_width, iconSize.max_height); - OS.XFree (size_list_return [0]); - } else { - min = new Point (16, 16); - max = new Point (32, 32); - } - return new Point [] {min, max}; -} -int getLastEventTime () { -// checkDevice (); - return OS.XtLastTimestampProcessed (xDisplay); -} -int getMessageCount () { - return synchronizer.getMessageCount (); -} -/** - * Returns an array of monitors attached to the device. - * - * @return the array of monitors - * - * @since 3.0 - */ -public Monitor [] getMonitors () { - checkDevice (); - Monitor [] monitors = null; - if (OS.IsLinux) { - boolean result = OS.XineramaIsActive (xDisplay); - if (result) { - int [] number = new int [1]; - int ptr = OS.XineramaQueryScreens (xDisplay, number); - int monitorCount = number [0]; - if (ptr != 0 && monitorCount > 0) { - monitors = new Monitor [monitorCount]; - XineramaScreenInfo info = new XineramaScreenInfo (); - int address = ptr; - for (int i = 0; i < monitorCount; i++) { - Monitor monitor = new Monitor (); - OS.memmove (info, address, XineramaScreenInfo.sizeof); - address += XineramaScreenInfo.sizeof; - monitor.handle = info.screen_number; - monitor.x = info.x_org; - monitor.y = info.y_org; - monitor.width = info.width; - monitor.height = info.height; - monitor.clientX = monitor.x; - monitor.clientY = monitor.y; - monitor.clientWidth = monitor.width; - monitor.clientHeight = monitor.height; - monitors [i] = monitor; - } - } - if (ptr != 0) OS.XFree (ptr); - } - } - if (monitors == null) { - /* No multimonitor support detected, default to one monitor */ - Monitor monitor = new Monitor (); - Rectangle bounds = getBounds (); - monitor.x = bounds.x; - monitor.y = bounds.y; - monitor.width = bounds.width; - monitor.height = bounds.height; - monitor.clientX = monitor.x; - monitor.clientY = monitor.y; - monitor.clientWidth = monitor.width; - monitor.clientHeight = monitor.height; - monitors = new Monitor [] { monitor }; - } - return monitors; -} -/** - * Returns the primary monitor for that device. - * - * @return the primary monitor - * - * @since 3.0 - */ -public Monitor getPrimaryMonitor () { - checkDevice (); - Monitor monitor = null; - if (OS.IsLinux) { - boolean result = OS.XineramaIsActive (xDisplay); - if (result) { - int[] number = new int [1]; - /* Assume first monitor returned is the primary one */ - int ptr = OS.XineramaQueryScreens (xDisplay, number); - int monitorCount = number [0]; - if (ptr != 0 && monitorCount >= 1) { - monitor = new Monitor (); - XineramaScreenInfo info = new XineramaScreenInfo (); - OS.memmove (info, ptr, XineramaScreenInfo.sizeof); - monitor.handle = info.screen_number; - monitor.x = info.x_org; - monitor.y = info.y_org; - monitor.width = info.width; - monitor.height = info.height; - monitor.clientX = monitor.x; - monitor.clientY = monitor.y; - monitor.clientWidth = monitor.width; - monitor.clientHeight = monitor.height; - } - if (ptr != 0) OS.XFree (ptr); - } - } - if (monitor == null) { - /* No multimonitor support detected, default to one monitor */ - monitor = new Monitor (); - Rectangle bounds = getBounds (); - monitor.x = bounds.x; - monitor.y = bounds.y; - monitor.width = bounds.width; - monitor.height = bounds.height; - monitor.clientX = monitor.x; - monitor.clientY = monitor.y; - monitor.clientWidth = monitor.width; - monitor.clientHeight = monitor.height; - } - return monitor; -} -/** - * Returns a (possibly empty) array containing all shells which have - * not been disposed and have the receiver as their display. - * - * @return the receiver's shells - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Shell [] getShells () { - checkDevice (); - int length = 0; - for (int i=0; i<shellTable.length; i++) { - if (shellTable [i] != null) length++; - } - int index = 0; - Shell [] result = new Shell [length]; - for (int i=0; i<shellTable.length; i++) { - Shell widget = shellTable [i]; - if (widget != null) result [index++] = widget; - } - return result; -} -/** - * Gets the synchronizer used by the display. - * - * @return the receiver's synchronizer - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.4 - */ -public Synchronizer getSynchronizer () { - checkDevice (); - return synchronizer; -} -/** - * Returns the thread that has invoked <code>syncExec</code> - * or null if no such runnable is currently being invoked by - * the user-interface thread. - * <p> - * Note: If a runnable invoked by asyncExec is currently - * running, this method will return null. - * </p> - * - * @return the receiver's sync-interface thread - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Thread getSyncThread () { - synchronized (Device.class) { - if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); - return synchronizer.syncThread; - } -} -/** - * Returns the matching standard color for the given - * constant, which should be one of the color constants - * specified in class <code>SWT</code>. Any value other - * than one of the SWT color constants which is passed - * in will result in the color black. This color should - * not be free'd because it was allocated by the system, - * not the application. - * - * @param id the color constant - * @return the matching color - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see SWT - */ -public Color getSystemColor (int id) { - checkDevice (); - XColor xColor = null; - switch (id) { - case SWT.COLOR_INFO_FOREGROUND: return super.getSystemColor (SWT.COLOR_BLACK); - case SWT.COLOR_INFO_BACKGROUND: return COLOR_INFO_BACKGROUND; - case SWT.COLOR_TITLE_FOREGROUND: return super.getSystemColor (SWT.COLOR_WHITE); - case SWT.COLOR_TITLE_BACKGROUND: return super.getSystemColor (SWT.COLOR_DARK_BLUE); - case SWT.COLOR_TITLE_BACKGROUND_GRADIENT: return super.getSystemColor (SWT.COLOR_BLUE); - case SWT.COLOR_TITLE_INACTIVE_FOREGROUND: return super.getSystemColor (SWT.COLOR_BLACK); - case SWT.COLOR_TITLE_INACTIVE_BACKGROUND: return super.getSystemColor (SWT.COLOR_DARK_GRAY); - case SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT: return super.getSystemColor (SWT.COLOR_GRAY); - case SWT.COLOR_WIDGET_DARK_SHADOW: xColor = COLOR_WIDGET_DARK_SHADOW; break; - case SWT.COLOR_WIDGET_NORMAL_SHADOW: xColor = COLOR_WIDGET_NORMAL_SHADOW; break; - case SWT.COLOR_WIDGET_LIGHT_SHADOW: xColor = COLOR_WIDGET_LIGHT_SHADOW; break; - case SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: xColor = COLOR_WIDGET_HIGHLIGHT_SHADOW; break; - case SWT.COLOR_WIDGET_BACKGROUND: xColor = COLOR_WIDGET_BACKGROUND; break; - case SWT.COLOR_WIDGET_FOREGROUND: xColor = COLOR_WIDGET_FOREGROUND; break; - case SWT.COLOR_WIDGET_BORDER: xColor = COLOR_WIDGET_BORDER; break; - case SWT.COLOR_LIST_FOREGROUND: xColor = COLOR_LIST_FOREGROUND; break; - case SWT.COLOR_LIST_BACKGROUND: xColor = COLOR_LIST_BACKGROUND; break; - case SWT.COLOR_LIST_SELECTION: xColor = COLOR_LIST_SELECTION; break; - case SWT.COLOR_LIST_SELECTION_TEXT: xColor = COLOR_LIST_SELECTION_TEXT; break; - default: - return super.getSystemColor (id); - } - if (xColor == null) return super.getSystemColor (SWT.COLOR_BLACK); - return Color.motif_new (this, xColor); -} -/** - * Returns the matching standard platform cursor for the given - * constant, which should be one of the cursor constants - * specified in class <code>SWT</code>. This cursor should - * not be free'd because it was allocated by the system, - * not the application. A value of <code>null</code> will - * be returned if the supplied constant is not an SWT cursor - * constant. - * - * @param id the SWT cursor constant - * @return the corresponding cursor or <code>null</code> - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see SWT#CURSOR_ARROW - * @see SWT#CURSOR_WAIT - * @see SWT#CURSOR_CROSS - * @see SWT#CURSOR_APPSTARTING - * @see SWT#CURSOR_HELP - * @see SWT#CURSOR_SIZEALL - * @see SWT#CURSOR_SIZENESW - * @see SWT#CURSOR_SIZENS - * @see SWT#CURSOR_SIZENWSE - * @see SWT#CURSOR_SIZEWE - * @see SWT#CURSOR_SIZEN - * @see SWT#CURSOR_SIZES - * @see SWT#CURSOR_SIZEE - * @see SWT#CURSOR_SIZEW - * @see SWT#CURSOR_SIZENE - * @see SWT#CURSOR_SIZESE - * @see SWT#CURSOR_SIZESW - * @see SWT#CURSOR_SIZENW - * @see SWT#CURSOR_UPARROW - * @see SWT#CURSOR_IBEAM - * @see SWT#CURSOR_NO - * @see SWT#CURSOR_HAND - * - * @since 3.0 - */ -public Cursor getSystemCursor (int id) { - checkDevice (); - if (!(0 <= id && id < cursors.length)) return null; - if (cursors [id] == null) { - cursors [id] = new Cursor (this, id); - } - return cursors [id]; -} -/** - * Returns a reasonable font for applications to use. - * On some platforms, this will match the "default font" - * or "system font" if such can be found. This font - * should not be free'd because it was allocated by the - * system, not the application. - * <p> - * Typically, applications which want the default look - * should simply not set the font on the widgets they - * create. Widgets are always created with the correct - * default font for the class of user-interface component - * they represent. - * </p> - * - * @return a font - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Font getSystemFont () { - checkDevice (); - return defaultFont; -} -/** - * Returns the matching standard platform image for the given - * constant, which should be one of the icon constants - * specified in class <code>SWT</code>. This image should - * not be free'd because it was allocated by the system, - * not the application. A value of <code>null</code> will - * be returned either if the supplied constant is not an - * SWT icon constant or if the platform does not define an - * image that corresponds to the constant. - * - * @param id the SWT icon constant - * @return the corresponding image or <code>null</code> - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see SWT#ICON_ERROR - * @see SWT#ICON_INFORMATION - * @see SWT#ICON_QUESTION - * @see SWT#ICON_WARNING - * @see SWT#ICON_WORKING - * - * @since 3.0 - */ -public Image getSystemImage (int style) { - checkDevice (); - int imagePixmap = 0, maskPixmap = 0; - switch (style) { - case SWT.ICON_ERROR: - if (errorPixmap == 0) { - errorPixmap = createPixmap ("xm_error"); //$NON-NLS-1$ - errorMask = createMask (errorPixmap); - } - imagePixmap = errorPixmap; - maskPixmap = errorMask; - break; - case SWT.ICON_INFORMATION: - if (infoPixmap == 0) { - infoPixmap = createPixmap ("xm_information"); //$NON-NLS-1$ - infoMask = createMask (infoPixmap); - } - imagePixmap = infoPixmap; - maskPixmap = infoMask; - break; - case SWT.ICON_QUESTION: - if (questionPixmap == 0) { - questionPixmap = createPixmap ("xm_question"); //$NON-NLS-1$ - questionMask = createMask (questionPixmap); - } - imagePixmap = questionPixmap; - maskPixmap = questionMask; - break; - case SWT.ICON_WARNING: - if (warningPixmap == 0) { - warningPixmap = createPixmap ("xm_warning"); //$NON-NLS-1$ - warningMask = createMask (warningPixmap); - } - imagePixmap = warningPixmap; - maskPixmap = warningMask; - break; - case SWT.ICON_WORKING: - if (workingPixmap == 0) { - workingPixmap = createPixmap ("xm_working"); //$NON-NLS-1$ - workingMask = createMask (workingPixmap); - } - imagePixmap = workingPixmap; - maskPixmap = workingMask; - break; - } - if (imagePixmap == 0) return null; - return Image.motif_new (this, SWT.ICON, imagePixmap, maskPixmap); -} -/** - * Returns the single instance of the system tray or null - * when there is no system tray available for the platform. - * - * @return the system tray or <code>null</code> - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.0 - */ -public Tray getSystemTray () { - checkDevice (); - return null; -} -/** - * Returns the user-interface thread for the receiver. - * - * @return the receiver's user-interface thread - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Thread getThread () { - synchronized (Device.class) { - if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); - return thread; - } -} -Widget getWidget (int handle) { - if (handle == 0) return null; - if (OS.XtIsSubclass (handle, OS.shellWidgetClass ())) { - for (int i=0; i<shellTable.length; i++) { - Widget shell = shellTable [i]; - if (shell != null && shell.topHandle () == handle) return shell; - } - return null; - } - userData [1] = 0; - OS.XtGetValues (handle, userData, userData.length / 2); - if (userData [1] == 0) return null; - int index = userData [1] - 1; - if (0 <= index && index < widgetTable.length) return widgetTable [index]; - return null; -} -void hideToolTip () { - if (toolTipHandle != 0) { - int shellHandle = OS.XtParent(toolTipHandle); - OS.XtDestroyWidget(shellHandle); - } - toolTipHandle = 0; -} -/** - * Initializes any internal resources needed by the - * device. - * <p> - * This method is called after <code>create</code>. - * </p> - * - * @see #create - */ -protected void init () { - super.init (); - initializeDisplay (); - initializeButton (); - initializeComposite (); - initializeDialog (); - initializeLabel (); - initializeList (); - initializeScrollBar (); - initializeText (); - initializeSystemColors (); - initializeDefaults (); - initializeTranslations (); - initializeWidgetTable (); - initializeNumLock (); - initializePixmaps (); -} -void initializeButton () { - - int shellHandle, widgetHandle; - int widgetClass = OS.topLevelShellWidgetClass (); - - /* Get the push button information */ - shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0); - - /* - * Bug in Motif. When running on UTF-8, Motif becomes unstable and - * GP's some time later when a button widget is created with empty - * text. The fix is to create the button with a non-empty string. - */ - byte [] buffer = Converter.wcsToMbcs(null, "string", true); //$NON-NLS-1$ - widgetHandle = OS.XmCreatePushButton (shellHandle, buffer, null, 0); - OS.XtManageChild (widgetHandle); - OS.XtSetMappedWhenManaged (shellHandle, false); - OS.XtRealizeWidget (shellHandle); - int [] argList = { - OS.XmNforeground, 0, /* 1 */ - OS.XmNbackground, 0, /* 3 */ - OS.XmNshadowThickness, 0, /* 5 */ - OS.XmNfontList, 0, /* 7 */ - }; - OS.XtGetValues (widgetHandle, argList, argList.length / 2); - buttonForeground = argList [1]; buttonBackground = argList [3]; - buttonShadowThickness = argList [5]; - /* - * Feature in Motif. Querying the font list from the widget and - * then destroying the shell (and the widget) could cause the - * font list to be freed as well. The fix is to make a copy of - * the font list, then to free it when the display is disposed. - */ - - buttonFont = Font.motif_new (this, OS.XmFontListCopy (argList [7])); - OS.XtDestroyWidget (shellHandle); -} -void initializeComposite () { - int widgetClass = OS.topLevelShellWidgetClass (); - int shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0); - int scrolledHandle = OS.XmCreateMainWindow (shellHandle, null, null, 0); - int [] argList1 = {OS.XmNorientation, OS.XmHORIZONTAL}; - int hScrollHandle = OS.XmCreateScrollBar (scrolledHandle, null, argList1, argList1.length / 2); - OS.XtManageChild (hScrollHandle); - int [] argList2 = {OS.XmNorientation, OS.XmVERTICAL}; - int vScrollHandle = OS.XmCreateScrollBar (scrolledHandle, null, argList2, argList2.length / 2); - OS.XtManageChild (vScrollHandle); - OS.XtManageChild (scrolledHandle); - int [] argList5 = { - OS.XmNmarginWidth, 3, - OS.XmNmarginHeight, 3, - }; - int formHandle = OS.XmCreateForm (scrolledHandle, null, argList5, argList5.length / 2); - OS.XtManageChild (formHandle); - int [] argList6 = { - OS.XmNmarginWidth, 0, - OS.XmNmarginHeight, 0, - OS.XmNresizePolicy, OS.XmRESIZE_NONE, - OS.XmNtopAttachment, OS.XmATTACH_FORM, - OS.XmNbottomAttachment, OS.XmATTACH_FORM, - OS.XmNleftAttachment, OS.XmATTACH_FORM, - OS.XmNrightAttachment, OS.XmATTACH_FORM, - }; - int widgetHandle = OS.XmCreateDrawingArea (formHandle, null, argList6, argList6.length / 2); - OS.XtManageChild (widgetHandle); - OS.XmMainWindowSetAreas (scrolledHandle, 0, 0, hScrollHandle, vScrollHandle, formHandle); - OS.XtSetMappedWhenManaged (shellHandle, false); - int screen = OS.XDefaultScreen (xDisplay); - OS.XtResizeWidget (shellHandle, OS.XDisplayWidth (xDisplay, screen), OS.XDisplayHeight (xDisplay, screen), 0); - OS.XtRealizeWidget (shellHandle); - int [] argList3 = {OS.XmNwidth, 0, OS.XmNheight, 0}; - OS.XtGetValues (scrolledHandle, argList3, argList3.length / 2); - int [] argList8 = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0}; - OS.XtGetValues (formHandle, argList8, argList8.length / 2); - int [] argList4 = { - OS.XmNx, 0, /* 1 */ - OS.XmNy, 0, /* 3 */ - OS.XmNwidth, 0, /* 5 */ - OS.XmNheight, 0, /* 7 */ - OS.XmNforeground, 0, /* 9 */ - OS.XmNbackground, 0, /* 11 */ - OS.XmNtopShadowColor, 0, /* 13 */ - OS.XmNbottomShadowColor, 0, /* 15 */ - OS.XmNborderColor, 0, /* 17 */ - }; - OS.XtGetValues (widgetHandle, argList4, argList4.length / 2); - scrolledInsetX = argList4 [1] + argList8 [1]; - scrolledInsetY = argList4 [3] + argList8 [3]; - scrolledMarginX = argList3 [1] - argList8 [1] - argList4 [1] - argList4 [5]; - scrolledMarginY = argList3 [3] - argList8 [3] - argList4 [3] - argList4 [7]; - compositeForeground = argList4 [9]; compositeBackground = argList4 [11]; - compositeTopShadow = argList4 [13]; compositeBottomShadow = argList4 [15]; - compositeBorder = argList4 [17]; - OS.XtDestroyWidget (shellHandle); -} -void initializeDefaults () { - defaultFont = labelFont; - defaultForeground = compositeForeground; - defaultBackground = compositeBackground; -} -void initializeDialog () { - //int shellHandle, widgetHandle; - //int widgetClass = OS.topLevelShellWidgetClass (); - //shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0); - //widgetHandle = OS.XmCreateDialogShell (shellHandle, null, null, 0); - //OS.XtSetMappedWhenManaged (shellHandle, false); - //OS.XtRealizeWidget (shellHandle); - //int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0}; - //OS.XtGetValues (widgetHandle, argList, argList.length / 2); - //dialogForeground = argList [1]; dialogBackground = argList [3]; - //OS.XtDestroyWidget (shellHandle); -} -void initializeDisplay () { - - /* Create the callbacks */ - focusCallback = new Callback (this, "focusProc", 4); //$NON-NLS-1$ - focusProc = focusCallback.getAddress (); - if (focusProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - windowCallback = new Callback (this, "windowProc", 4); //$NON-NLS-1$ - windowProc = windowCallback.getAddress (); - if (windowProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - windowTimerCallback = new Callback (this, "windowTimerProc", 2); //$NON-NLS-1$ - windowTimerProc = windowTimerCallback.getAddress (); - if (windowTimerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - timerCallback = new Callback (this, "timerProc", 2); //$NON-NLS-1$ - timerProc = timerCallback.getAddress (); - if (timerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - caretCallback = new Callback (this, "caretProc", 2); //$NON-NLS-1$ - caretProc = caretCallback.getAddress (); - if (caretProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - mouseHoverCallback = new Callback (this, "mouseHoverProc", 2); //$NON-NLS-1$ - mouseHoverProc = mouseHoverCallback.getAddress (); - if (mouseHoverProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - checkExposeCallback = new Callback (this, "checkExposeProc", 3); //$NON-NLS-1$ - checkExposeProc = checkExposeCallback.getAddress (); - if (checkExposeProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - checkResizeCallback = new Callback (this, "checkResizeProc", 3); //$NON-NLS-1$ - checkResizeProc = checkResizeCallback.getAddress (); - if (checkResizeProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - wakeCallback = new Callback (this, "wakeProc", 3); //$NON-NLS-1$ - wakeProc = wakeCallback.getAddress (); - if (wakeProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - /* Create and install the pipe used to wake up from sleep */ - int [] filedes = new int [2]; - if (OS.pipe (filedes) != 0) error (SWT.ERROR_NO_HANDLES); - read_fd = filedes [0]; - write_fd = filedes [1]; - int xtContext = OS.XtDisplayToApplicationContext (xDisplay); - inputID = OS.XtAppAddInput (xtContext, read_fd, OS.XtInputReadMask, wakeProc, 0); - fd_set = new byte [OS.fd_set_sizeof ()]; - - /* - * Use dynamic Drag and Drop Protocol styles. - * Preregistered protocol is not supported. - */ - int xmDisplay = OS.XmGetXmDisplay (xDisplay); - int [] args = new int [] { - OS.XmNenableThinThickness, 1, - OS.XmNdragInitiatorProtocolStyle, OS.XmDRAG_DYNAMIC, - OS.XmNdragReceiverProtocolStyle, OS.XmDRAG_DYNAMIC, - }; - OS.XtSetValues (xmDisplay, args, args.length / 2); - - /* Create the hidden Override shell parent */ - int xScreen = OS.XDefaultScreen (xDisplay); - int widgetClass = OS.topLevelShellWidgetClass (); - shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0); - OS.XtSetMappedWhenManaged (shellHandle, false); - OS.XtResizeWidget (shellHandle, OS.XDisplayWidth (xDisplay, xScreen), OS.XDisplayHeight (xDisplay, xScreen), 0); - OS.XtRealizeWidget (shellHandle); -} -void initializeLabel () { - int shellHandle, widgetHandle; - int widgetClass = OS.topLevelShellWidgetClass (); - shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0); - - /* - * Bug in Motif. When running on UTF-8, Motif becomes unstable and - * GP's some time later when a label widget is created with empty - * text. The fix is to create the label with a non-empty string. - */ - byte [] buffer = Converter.wcsToMbcs(null, "string", true); //$NON-NLS-1$ - widgetHandle = OS.XmCreateLabel (shellHandle, buffer, null, 0); - OS.XtManageChild (widgetHandle); - OS.XtSetMappedWhenManaged (shellHandle, false); - OS.XtRealizeWidget (shellHandle); - int [] argList2 = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNfontList, 0}; - OS.XtGetValues (widgetHandle, argList2, argList2.length / 2); - labelForeground = argList2 [1]; labelBackground = argList2 [3]; - /* - * Feature in Motif. Querying the font list from the widget and - * then destroying the shell (and the widget) could cause the - * font list to be freed as well. The fix is to make a copy of - * the font list, then to free it when the display is disposed. - */ - - labelFont = Font.motif_new (this, OS.XmFontListCopy (argList2 [5])); - OS.XtDestroyWidget (shellHandle); -} -void initializeList () { - int shellHandle, widgetHandle; - int widgetClass = OS.topLevelShellWidgetClass (); - shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0); - widgetHandle = OS.XmCreateScrolledList (shellHandle, new byte [1], null, 0); - OS.XtManageChild (widgetHandle); - OS.XtSetMappedWhenManaged (shellHandle, false); - OS.XtRealizeWidget (shellHandle); - int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNfontList, 0, OS.XmNselectColor, 0, OS.XmNhighlightColor, 0}; - OS.XtGetValues (widgetHandle, argList, argList.length / 2); - listForeground = argList [1]; - listBackground = argList [3]; - - /* - * Feature in Motif. Querying the font list from the widget and - * then destroying the shell (and the widget) could cause the - * font list to be freed as well. The fix is to make a copy of - * the font list, then to free it when the display is disposed. - */ - - listFont = Font.motif_new (this, OS.XmFontListCopy (argList [5])); - - /* - * Feature in Motif. If the value of resource XmNselectColor is - * XmDEFAULT_SELECT_COLOR then querying for this resource gives - * the value of the selection color to use, which is between the - * background and bottom shadow colors. If the resource value - * that is returned is XmDEFAULT_SELECT_COLOR, and not the color, - * since there is no API to query the color, use the list foreground - * color. - */ - int selectColor = (byte) argList [7]; - switch (selectColor) { - case OS.XmDEFAULT_SELECT_COLOR: - case OS.XmREVERSED_GROUND_COLORS: - listSelect = listForeground; - break; - case OS.XmHIGHLIGHT_COLOR: - listSelect = argList [9]; - break; - default: - listSelect = argList [7]; // the middle color to use - } - OS.XtDestroyWidget (shellHandle); -} - -void initializeNumLock () { - int numLockCode = OS.XKeysymToKeycode (xDisplay, OS.XK_Num_Lock); - int keymapHandle = OS.XGetModifierMapping (xDisplay); - XModifierKeymap keymap = new XModifierKeymap (); - OS.memmove (keymap, keymapHandle, XModifierKeymap.sizeof); - for (int i = 0; i < 8 * keymap.max_keypermod; i++) { - byte [] keymapCode = new byte [1]; - OS.memmove (keymapCode, keymap.modifiermap + i, 1); - if (keymapCode [0] == numLockCode) { - int modIndex = i / keymap.max_keypermod; - switch (modIndex) { - case OS.Mod1MapIndex: numLock = "Mod1"; break; //$NON-NLS-1$ - case OS.Mod2MapIndex: numLock = "Mod2"; break; //$NON-NLS-1$ - case OS.Mod3MapIndex: numLock = "Mod3"; break; //$NON-NLS-1$ - case OS.Mod4MapIndex: numLock = "Mod4"; break; //$NON-NLS-1$ - case OS.Mod5MapIndex: numLock = "Mod5"; break; //$NON-NLS-1$ - default: numLock = "Mod2"; //$NON-NLS-1$ - } - break; - } - } - OS.XFreeModifiermap (keymapHandle); -} -void initializePixmaps () { - /* - * Feature in Motif. The system pixmaps are initially installed the first - * time a system dialog is created, so create and destroy a system dialog - * in order to make these pixmaps available. - */ - int dialog = OS.XmCreateErrorDialog (shellHandle, null, null, 0); - OS.XtDestroyWidget (dialog); -} -void initializeScrollBar () { - //int shellHandle, widgetHandle; - //int widgetClass = OS.topLevelShellWidgetClass (); - //shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0); - //widgetHandle = OS.XmCreateScrollBar (shellHandle, null, null, 0); - //OS.XtManageChild (widgetHandle); - //OS.XtSetMappedWhenManaged (shellHandle, false); - //OS.XtRealizeWidget (shellHandle); - //int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0}; - //OS.XtGetValues (widgetHandle, argList, argList.length / 2); - //scrollBarForeground = argList [1]; scrollBarBackground = argList [3]; - //OS.XtDestroyWidget (shellHandle); -} -void initializeSystemColors () { - int [] argList = {OS.XmNcolormap, 0}; - OS.XtGetValues (shellHandle, argList, argList.length / 2); - int colormap = argList [1]; - - COLOR_WIDGET_DARK_SHADOW = new XColor(); - COLOR_WIDGET_DARK_SHADOW.pixel = compositeBottomShadow; - OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_DARK_SHADOW); - - COLOR_WIDGET_NORMAL_SHADOW = new XColor(); - COLOR_WIDGET_NORMAL_SHADOW.pixel = compositeBottomShadow; - OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_NORMAL_SHADOW); - - COLOR_WIDGET_LIGHT_SHADOW = new XColor(); - COLOR_WIDGET_LIGHT_SHADOW.pixel = compositeTopShadow; - OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_LIGHT_SHADOW); - - COLOR_WIDGET_HIGHLIGHT_SHADOW = new XColor(); - COLOR_WIDGET_HIGHLIGHT_SHADOW.pixel = compositeTopShadow; - OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_HIGHLIGHT_SHADOW); - - COLOR_WIDGET_FOREGROUND = new XColor(); - COLOR_WIDGET_FOREGROUND.pixel = textForeground; - OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_FOREGROUND); - - COLOR_WIDGET_BACKGROUND = new XColor(); - COLOR_WIDGET_BACKGROUND.pixel = compositeBackground; - OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_BACKGROUND); - - COLOR_WIDGET_BORDER = new XColor(); - COLOR_WIDGET_BORDER.pixel = compositeBorder; - OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_BORDER); - - COLOR_LIST_FOREGROUND = new XColor(); - COLOR_LIST_FOREGROUND.pixel = listForeground; - OS.XQueryColor (xDisplay, colormap, COLOR_LIST_FOREGROUND); - - COLOR_LIST_BACKGROUND = new XColor(); - COLOR_LIST_BACKGROUND.pixel = listBackground; - OS.XQueryColor (xDisplay, colormap, COLOR_LIST_BACKGROUND); - - COLOR_LIST_SELECTION = new XColor(); - COLOR_LIST_SELECTION.pixel = listSelect; - OS.XQueryColor (xDisplay, colormap, COLOR_LIST_SELECTION); - - COLOR_LIST_SELECTION_TEXT = new XColor(); - COLOR_LIST_SELECTION_TEXT.pixel = listBackground; - OS.XQueryColor (xDisplay, colormap, COLOR_LIST_SELECTION_TEXT); - - COLOR_INFO_BACKGROUND = new Color (this, 0xFF, 0xFF, 0xE1); -} -void initializeText () { - int shellHandle, widgetHandle; - int widgetClass = OS.topLevelShellWidgetClass (); - shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0); - widgetHandle = OS.XmCreateScrolledText (shellHandle, new byte [1], null, 0); - OS.XtManageChild (widgetHandle); - OS.XtSetMappedWhenManaged (shellHandle, false); - OS.XtRealizeWidget (shellHandle); - int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNfontList, 0, OS.XmNhighlightThickness, 0, OS.XmNblinkRate, 0}; - OS.XtGetValues (widgetHandle, argList, argList.length / 2); - textForeground = argList [1]; - textBackground = argList [3]; - textHighlightThickness = argList[7]; - blinkRate = argList[9]; - /* - * Feature in Motif. Querying the font list from the widget and - * then destroying the shell (and the widget) could cause the - * font list to be freed as well. The fix is to make a copy of - * the font list, then to free it when the display is disposed. - */ - - textFont = Font.motif_new (this, OS.XmFontListCopy (argList [5])); - OS.XtDestroyWidget (shellHandle); - -} -void initializeTranslations () { - byte [] buffer1 = Converter.wcsToMbcs (null, "<Key>osfUp:\n<Key>osfDown:\n<Key>osfLeft:\n<Key>osfRight:\0"); //$NON-NLS-1$ - arrowTranslations = OS.XtParseTranslationTable (buffer1); - byte [] buffer2 = Converter.wcsToMbcs (null, "~Meta ~Alt <Key>Tab:\nShift ~Meta ~Alt <Key>Tab:\0"); //$NON-NLS-1$ - tabTranslations = OS.XtParseTranslationTable (buffer2); - byte [] buffer3 = Converter.wcsToMbcs (null, "<Btn2Down>:\0"); //$NON-NLS-1$ - dragTranslations = OS.XtParseTranslationTable (buffer3); -} -void initializeWidgetTable () { - userData = new int [] {OS.XmNuserData, 0}; - indexTable = new int [GROW_SIZE]; - shellTable = new Shell [GROW_SIZE / 8]; - widgetTable = new Widget [GROW_SIZE]; - for (int i=0; i<GROW_SIZE-1; i++) indexTable [i] = i + 1; - indexTable [GROW_SIZE - 1] = -1; -} -/** - * Invokes platform specific functionality to allocate a new GC handle. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>Display</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @param data the platform specific GC data - * @return the platform specific GC handle - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES if a handle could not be obtained for gc creation</li> - * </ul> - */ -public int internal_new_GC (GCData data) { - if (isDisposed()) SWT.error(SWT.ERROR_DEVICE_DISPOSED); - int xDrawable = OS.XDefaultRootWindow (xDisplay); - int xGC = OS.XCreateGC (xDisplay, xDrawable, 0, null); - if (xGC == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.XSetSubwindowMode (xDisplay, xGC, OS.IncludeInferiors); - if (data != null) { - int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT; - if ((data.style & mask) == 0) { - data.style |= SWT.LEFT_TO_RIGHT; - } - data.device = this; - data.display = xDisplay; - data.drawable = xDrawable; - data.background = getSystemColor (SWT.COLOR_WHITE).handle; - data.foreground = getSystemColor (SWT.COLOR_BLACK).handle; - data.font = defaultFont; - data.colormap = OS.XDefaultColormap (xDisplay, OS.XDefaultScreen (xDisplay)); - } - return xGC; -} -/** - * Invokes platform specific functionality to dispose a GC handle. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>Display</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @param hDC the platform specific GC handle - * @param data the platform specific GC data - */ -public void internal_dispose_GC (int gc, GCData data) { - OS.XFreeGC(xDisplay, gc); -} -boolean isValidThread () { - return thread == Thread.currentThread (); -} -static boolean isValidClass (Class clazz) { - String name = clazz.getName (); - int index = name.lastIndexOf ('.'); - return name.substring (0, index + 1).equals (PACKAGE_PREFIX); -} -/** - * Maps a point from one coordinate system to another. - * When the control is null, coordinates are mapped to - * the display. - * <p> - * NOTE: On right-to-left platforms where the coordinate - * systems are mirrored, special care needs to be taken - * when mapping coordinates from one control to another - * to ensure the result is correctly mirrored. - * - * Mapping a point that is the origin of a rectangle and - * then adding the width and height is not equivalent to - * mapping the rectangle. When one control is mirrored - * and the other is not, adding the width and height to a - * point that was mapped causes the rectangle to extend - * in the wrong direction. Mapping the entire rectangle - * instead of just one point causes both the origin and - * the corner of the rectangle to be mapped. - * </p> - * - * @param from the source <code>Control</code> or <code>null</code> - * @param to the destination <code>Control</code> or <code>null</code> - * @param point to be mapped - * @return point with mapped coordinates - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the point is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 2.1.2 - */ -public Point map (Control from, Control to, Point point) { - checkDevice (); - if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - return map (from, to, point.x, point.y); -} -/** - * Maps a point from one coordinate system to another. - * When the control is null, coordinates are mapped to - * the display. - * <p> - * NOTE: On right-to-left platforms where the coordinate - * systems are mirrored, special care needs to be taken - * when mapping coordinates from one control to another - * to ensure the result is correctly mirrored. - * - * Mapping a point that is the origin of a rectangle and - * then adding the width and height is not equivalent to - * mapping the rectangle. When one control is mirrored - * and the other is not, adding the width and height to a - * point that was mapped causes the rectangle to extend - * in the wrong direction. Mapping the entire rectangle - * instead of just one point causes both the origin and - * the corner of the rectangle to be mapped. - * </p> - * - * @param from the source <code>Control</code> or <code>null</code> - * @param to the destination <code>Control</code> or <code>null</code> - * @param x coordinates to be mapped - * @param y coordinates to be mapped - * @return point with mapped coordinates - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 2.1.2 - */ -public Point map (Control from, Control to, int x, int y) { - checkDevice (); - if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - Point point = new Point (x, y); - if (from == to) return point; - if (from != null) { - short [] root_x = new short [1], root_y = new short [1]; - OS.XtTranslateCoords (from.handle, (short) x, (short) y, root_x, root_y); - point.x = root_x [0]; - point.y = root_y [0]; - } - if (to != null) { - short [] root_x = new short [1], root_y = new short [1]; - OS.XtTranslateCoords (to.handle, (short) 0, (short) 0, root_x, root_y); - point.x -= root_x [0]; - point.y -= root_y [0]; - } - return point; -} -/** - * Maps a point from one coordinate system to another. - * When the control is null, coordinates are mapped to - * the display. - * <p> - * NOTE: On right-to-left platforms where the coordinate - * systems are mirrored, special care needs to be taken - * when mapping coordinates from one control to another - * to ensure the result is correctly mirrored. - * - * Mapping a point that is the origin of a rectangle and - * then adding the width and height is not equivalent to - * mapping the rectangle. When one control is mirrored - * and the other is not, adding the width and height to a - * point that was mapped causes the rectangle to extend - * in the wrong direction. Mapping the entire rectangle - * instead of just one point causes both the origin and - * the corner of the rectangle to be mapped. - * </p> - * - * @param from the source <code>Control</code> or <code>null</code> - * @param to the destination <code>Control</code> or <code>null</code> - * @param rectangle to be mapped - * @return rectangle with mapped coordinates - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the rectangle is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 2.1.2 - */ -public Rectangle map (Control from, Control to, Rectangle rectangle) { - checkDevice(); - if (rectangle == null) error (SWT.ERROR_NULL_ARGUMENT); - return map (from, to, rectangle.x, rectangle.y, rectangle.width, rectangle.height); -} -/** - * Maps a point from one coordinate system to another. - * When the control is null, coordinates are mapped to - * the display. - * <p> - * NOTE: On right-to-left platforms where the coordinate - * systems are mirrored, special care needs to be taken - * when mapping coordinates from one control to another - * to ensure the result is correctly mirrored. - * - * Mapping a point that is the origin of a rectangle and - * then adding the width and height is not equivalent to - * mapping the rectangle. When one control is mirrored - * and the other is not, adding the width and height to a - * point that was mapped causes the rectangle to extend - * in the wrong direction. Mapping the entire rectangle - * instead of just one point causes both the origin and - * the corner of the rectangle to be mapped. - * </p> - * - * @param from the source <code>Control</code> or <code>null</code> - * @param to the destination <code>Control</code> or <code>null</code> - * @param x coordinates to be mapped - * @param y coordinates to be mapped - * @param width coordinates to be mapped - * @param height coordinates to be mapped - * @return rectangle with mapped coordinates - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the Control from or the Control to have been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 2.1.2 - */ -public Rectangle map (Control from, Control to, int x, int y, int width, int height) { - checkDevice(); - if (from != null && from.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - if (to != null && to.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - Rectangle rect = new Rectangle (x, y, width, height); - if (from == to) return rect; - if (from != null) { - short [] root_x = new short [1], root_y = new short [1]; - OS.XtTranslateCoords (from.handle, (short) x, (short) y, root_x, root_y); - rect.x = root_x [0]; - rect.y = root_y [0]; - } - if (to != null) { - short [] root_x = new short [1], root_y = new short [1]; - OS.XtTranslateCoords (to.handle, (short) 0, (short) 0, root_x, root_y); - rect.x -= root_x [0]; - rect.y -= root_y [0]; - } - return rect; -} -int mouseHoverProc (int handle, int id) { - mouseHoverID = mouseHoverHandle = 0; - Widget widget = getWidget (handle); - if (widget == null) return 0; - return widget.hoverProc (id); -} -/** - * Generate a low level system event. - * - * <code>post</code> is used to generate low level keyboard - * and mouse events. The intent is to enable automated UI - * testing by simulating the input from the user. Most - * SWT applications should never need to call this method. - * <p> - * Note that this operation can fail when the operating system - * fails to generate the event for any reason. For example, - * this can happen when there is no such key or mouse button - * or when the system event queue is full. - * </p> - * <p> - * <b>Event Types:</b> - * <p>KeyDown, KeyUp - * <p>The following fields in the <code>Event</code> apply: - * <ul> - * <li>(in) type KeyDown or KeyUp</li> - * <p> Either one of: - * <li>(in) character a character that corresponds to a keyboard key</li> - * <li>(in) keyCode the key code of the key that was typed, - * as defined by the key code constants in class <code>SWT</code></li> - * </ul> - * <p>MouseDown, MouseUp</p> - * <p>The following fields in the <code>Event</code> apply: - * <ul> - * <li>(in) type MouseDown or MouseUp - * <li>(in) button the button that is pressed or released - * </ul> - * <p>MouseMove</p> - * <p>The following fields in the <code>Event</code> apply: - * <ul> - * <li>(in) type MouseMove - * <li>(in) x the x coordinate to move the mouse pointer to in screen coordinates - * <li>(in) y the y coordinate to move the mouse pointer to in screen coordinates - * </ul> - * <p>MouseWheel</p> - * <p>The following fields in the <code>Event</code> apply: - * <ul> - * <li>(in) type MouseWheel - * <li>(in) detail either SWT.SCROLL_LINE or SWT.SCROLL_PAGE - * <li>(in) count the number of lines or pages to scroll - * </ul> - * </dl> - * - * @param event the event to be generated - * - * @return true if the event was generated or false otherwise - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the event is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.0 - * - */ -public boolean post (Event event) { - /* - * Get the operating system lock before synchronizing on the device - * lock so that the device lock will not be held should another - * thread already be in the operating system. This avoids deadlock - * should the other thread need the device lock. - */ - Lock lock = OS.lock; - lock.lock(); - try { - synchronized (Device.class) { - if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); - if (event == null) error (SWT.ERROR_NULL_ARGUMENT); - int type = event.type; - switch (type) { - case SWT.KeyDown : - case SWT.KeyUp : { - int keyCode = 0; - int keysym = untranslateKey (event.keyCode); - if (keysym != 0) keyCode = OS.XKeysymToKeycode (xDisplay, keysym); - if (keyCode == 0) { - char key = event.character; - switch (key) { - case SWT.BS: keysym = OS.XK_BackSpace; break; - case SWT.CR: keysym = OS.XK_Return; break; - case SWT.DEL: keysym = OS.XK_Delete; break; - case SWT.ESC: keysym = OS.XK_Escape; break; - case SWT.TAB: keysym = OS.XK_Tab; break; - case SWT.LF: keysym = OS.XK_Linefeed; break; - default: - keysym = key; - } - keyCode = OS.XKeysymToKeycode (xDisplay, keysym); - if (keyCode == 0) return false; - } - OS.XTestFakeKeyEvent (xDisplay, keyCode, type == SWT.KeyDown, 0); - return true; - } - case SWT.MouseDown : - case SWT.MouseMove : - case SWT.MouseUp : { - if (type == SWT.MouseMove) { - OS.XTestFakeMotionEvent (xDisplay, -1, event.x, event.y, 0); - return true; - } else { - int button = event.button; - if (button < 1 || button > 3) return false; - OS.XTestFakeButtonEvent (xDisplay, button, type == SWT.MouseDown, 0); - return true; - } - } - } - return false; - } - } finally { - lock.unlock(); - } -} -void postEvent (Event event) { - /* - * Place the event at the end of the event queue. - * This code is always called in the Display's - * thread so it must be re-enterant but does not - * need to be synchronized. - */ - if (eventQueue == null) eventQueue = new Event [4]; - int index = 0; - int length = eventQueue.length; - while (index < length) { - if (eventQueue [index] == null) break; - index++; - } - if (index == length) { - Event [] newQueue = new Event [length + 4]; - System.arraycopy (eventQueue, 0, newQueue, 0, length); - eventQueue = newQueue; - } - eventQueue [index] = event; -} -/** - * Reads an event from the operating system's event queue, - * dispatches it appropriately, and returns <code>true</code> - * if there is potentially more work to do, or <code>false</code> - * if the caller can sleep until another event is placed on - * the event queue. - * <p> - * In addition to checking the system event queue, this method also - * checks if any inter-thread messages (created by <code>syncExec()</code> - * or <code>asyncExec()</code>) are waiting to be processed, and if - * so handles them before returning. - * </p> - * - * @return <code>false</code> if the caller can sleep upon return from this method - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li> - * </ul> - * - * @see #sleep - * @see #wake - */ -public boolean readAndDispatch () { - checkDevice (); - boolean events = runPopups (); - int xtContext = OS.XtDisplayToApplicationContext (xDisplay); - int status = OS.XtAppPending (xtContext); - if (status != 0) { - events |= true; - if ((status & OS.XtIMTimer) != 0) { - OS.XtAppProcessEvent (xtContext, OS.XtIMTimer); - status = OS.XtAppPending (xtContext); - } - if ((status & OS.XtIMAlternateInput) != 0) { - OS.XtAppProcessEvent (xtContext, OS.XtIMAlternateInput); - status = OS.XtAppPending (xtContext); - } - if ((status & OS.XtIMXEvent) != 0) { - OS.XtAppNextEvent (xtContext, xEvent); - if (!filterEvent (xEvent)) OS.XtDispatchEvent (xEvent); - } - } - if (events) { - runDeferredEvents (); - return true; - } - return isDisposed () || runAsyncMessages (false); -} -static void register (Display display) { - synchronized (Device.class) { - for (int i=0; i<Displays.length; i++) { - if (Displays [i] == null) { - Displays [i] = display; - return; - } - } - Display [] newDisplays = new Display [Displays.length + 4]; - System.arraycopy (Displays, 0, newDisplays, 0, Displays.length); - newDisplays [Displays.length] = display; - Displays = newDisplays; - } -} -/** - * Releases any internal resources back to the operating - * system and clears all fields except the device handle. - * <p> - * Disposes all shells which are currently open on the display. - * After this method has been invoked, all related related shells - * will answer <code>true</code> when sent the message - * <code>isDisposed()</code>. - * </p><p> - * When a device is destroyed, resources that were acquired - * on behalf of the programmer need to be returned to the - * operating system. For example, if the device allocated a - * font to be used as the system font, this font would be - * freed in <code>release</code>. Also,to assist the garbage - * collector and minimize the amount of memory that is not - * reclaimed when the programmer keeps a reference to a - * disposed device, all fields except the handle are zero'd. - * The handle is needed by <code>destroy</code>. - * </p> - * This method is called before <code>destroy</code>. - * - * @see Device#dispose - * @see #destroy - */ -protected void release () { - sendEvent (SWT.Dispose, new Event ()); - Shell [] shells = getShells (); - for (int i=0; i<shells.length; i++) { - Shell shell = shells [i]; - if (!shell.isDisposed ()) shell.dispose (); - } - if (tray != null) tray.dispose (); - tray = null; - while (readAndDispatch ()) {} - if (disposeList != null) { - for (int i=0; i<disposeList.length; i++) { - if (disposeList [i] != null) disposeList [i].run (); - } - } - disposeList = null; - synchronizer.releaseSynchronizer (); - synchronizer = null; - releaseDisplay (); - super.release (); -} -void releaseDisplay () { - /* destroy the System Images */ - int screen = OS.XDefaultScreenOfDisplay (xDisplay); - if (errorPixmap != 0) { - OS.XmDestroyPixmap (screen, errorPixmap); - OS.XFreePixmap (xDisplay, errorMask); - } - if (infoPixmap != 0) { - OS.XmDestroyPixmap (screen, infoPixmap); - OS.XFreePixmap (xDisplay, infoMask); - } - if (questionPixmap != 0) { - OS.XmDestroyPixmap (screen, questionPixmap); - OS.XFreePixmap (xDisplay, questionMask); - } - if (warningPixmap != 0) { - OS.XmDestroyPixmap (screen, warningPixmap); - OS.XFreePixmap (xDisplay, warningMask); - } - if (workingPixmap != 0) { - OS.XmDestroyPixmap (screen, workingPixmap); - OS.XFreePixmap (xDisplay, workingMask); - } - errorPixmap = infoPixmap = questionPixmap = warningPixmap = workingPixmap = 0; - errorMask = infoMask = questionMask = warningMask = workingMask = 0; - - /* Release the System Cursors */ - for (int i = 0; i < cursors.length; i++) { - if (cursors [i] != null) cursors [i].dispose (); - } - cursors = null; - - /* Destroy the hidden Override shell parent */ - if (shellHandle != 0) { - if (!OS.IsSunOS) { - OS.XtDestroyWidget (shellHandle); - } - shellHandle = 0; - } - - /* Dispose the caret callback */ - if (caretID != 0) OS.XtRemoveTimeOut (caretID); - caretID = caretProc = 0; - caretCallback.dispose (); - caretCallback = null; - - /* Dispose the timer callback */ - if (timerIds != null) { - for (int i=0; i<timerIds.length; i++) { - if (timerIds [i] != 0) OS.XtRemoveTimeOut (timerIds [i]); - } - } - timerIds = null; - timerList = null; - timerProc = 0; - timerCallback.dispose (); - timerCallback = null; - - /* Dispose the window timer callback */ - windowTimerProc = 0; - windowTimerCallback.dispose (); - windowTimerCallback = null; - - /* Dispose the mouse hover callback */ - if (mouseHoverID != 0) OS.XtRemoveTimeOut (mouseHoverID); - mouseHoverID = mouseHoverProc = mouseHoverHandle = toolTipHandle = 0; - mouseHoverCallback.dispose (); - mouseHoverCallback = null; - - /* Dispose window, expose and resize callbacks */ - windowCallback.dispose (); windowCallback = null; - checkExposeCallback.dispose (); checkExposeCallback = null; - checkExposeProc = 0; - checkResizeCallback.dispose (); checkResizeCallback = null; - checkResizeProc = 0; - - /* Dispose the wake callback, id and pipe */ - if (inputID != 0) OS.XtRemoveInput (inputID); - wakeCallback.dispose (); wakeCallback = null; - wakeProc = 0; - OS.close (read_fd); - OS.close (write_fd); - - focusCallback.dispose (); focusCallback = null; - focusProc = 0; - - /* Free the font lists */ - if (buttonFont != null) { - OS.XmFontListFree (buttonFont.handle); - buttonFont.handle = 0; - } - if (labelFont != null) { - OS.XmFontListFree (labelFont.handle); - labelFont.handle = 0; - } - if (textFont != null) { - OS.XmFontListFree (textFont.handle); - textFont.handle = 0; - } - if (listFont != null) { - OS.XmFontListFree (listFont.handle); - listFont.handle = 0; - } - listFont = textFont = labelFont = buttonFont = null; - defaultFont = null; - - /* Free the translations (no documentation describes how to do this) */ - //OS.XtFree (arrowTranslations); - //OS.XtFree (tabTranslations); - //OS.XtFree (dragTranslations); - - if (xEvent != 0) OS.XtFree(xEvent); - xEvent = 0; - - /* Release references */ - thread = null; - buttonBackground = buttonForeground = 0; - defaultBackground = defaultForeground = 0; - COLOR_WIDGET_DARK_SHADOW = COLOR_WIDGET_NORMAL_SHADOW = COLOR_WIDGET_LIGHT_SHADOW = - COLOR_WIDGET_HIGHLIGHT_SHADOW = COLOR_WIDGET_FOREGROUND = COLOR_WIDGET_BACKGROUND = COLOR_WIDGET_BORDER = - COLOR_LIST_FOREGROUND = COLOR_LIST_BACKGROUND = COLOR_LIST_SELECTION = COLOR_LIST_SELECTION_TEXT = null; - COLOR_INFO_BACKGROUND = null; - - popups = null; - focusedCombo = null; - displayName = appName = appClass = wake_buffer = fd_set = null; - keyEvent = null; - eventTable = filterTable = null; - indexTable = userData = timeout = null; - widgetTable = shellTable = null; - xExposeEvent = null; - xConfigureEvent = null; - data = null; - values = keys = null; -} -void releaseToolTipHandle (int handle) { - if (mouseHoverHandle == handle) removeMouseHoverTimeOut (); - if (toolTipHandle != 0) { - int shellHandle = OS.XtParent(toolTipHandle); - int shellParent = OS.XtParent(shellHandle); - if (handle == shellParent) toolTipHandle = 0; - } -} -void removeMouseHoverTimeOut () { - if (mouseHoverID != 0) OS.XtRemoveTimeOut (mouseHoverID); - mouseHoverID = mouseHoverHandle = 0; -} -Widget removeWidget (int handle) { - if (handle == 0) return null; - if (OS.XtIsSubclass (handle, OS.shellWidgetClass ())) { - for (int i=0; i<shellTable.length; i++) { - Widget shell = shellTable [i]; - if (shell != null && shell.topHandle () == handle) { - shellTable [i] = null; - return shell; - } - } - return null; - } - userData [1] = 0; - Widget widget = null; - OS.XtGetValues (handle, userData, userData.length / 2); - int index = userData [1] - 1; - if (0 <= index && index < widgetTable.length) { - widget = widgetTable [index]; - widgetTable [index] = null; - indexTable [index] = freeSlot; - freeSlot = index; - userData [1] = 0; - OS.XtSetValues (handle, userData, userData.length / 2); - } - return widget; -} -void removePopup (Menu menu) { - if (popups == null) return; - for (int i=0; i<popups.length; i++) { - if (popups [i] == menu) { - popups [i] = null; - return; - } - } -} -/** - * Removes the listener from the collection of listeners who will - * be notified when an event of the given type occurs anywhere in - * a widget. The event type is one of the event constants defined - * in class <code>SWT</code>. - * - * @param eventType the type of event to listen for - * @param listener the listener which should no longer be notified when the event occurs - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see Listener - * @see SWT - * @see #addFilter - * @see #addListener - * - * @since 3.0 - */ -public void removeFilter (int eventType, Listener listener) { - checkDevice (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (filterTable == null) return; - filterTable.unhook (eventType, listener); - if (filterTable.size () == 0) filterTable = null; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when an event of the given type occurs. The event type - * is one of the event constants defined in class <code>SWT</code>. - * - * @param eventType the type of event to listen for - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see Listener - * @see SWT - * @see #addListener - * - * @since 2.0 - */ -public void removeListener (int eventType, Listener listener) { - checkDevice (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (eventType, listener); -} -boolean runAsyncMessages (boolean all) { - return synchronizer.runAsyncMessages (all); -} -boolean runDeferredEvents () { - boolean run = false; - /* - * Run deferred events. This code is always - * called in the Display's thread so it must - * be re-enterant but need not be synchronized. - */ - while (eventQueue != null) { - - /* Take an event off the queue */ - Event event = eventQueue [0]; - if (event == null) break; - int length = eventQueue.length; - System.arraycopy (eventQueue, 1, eventQueue, 0, --length); - eventQueue [length] = null; - - /* Run the event */ - Widget widget = event.widget; - if (widget != null && !widget.isDisposed ()) { - Widget item = event.item; - if (item == null || !item.isDisposed ()) { - run = true; - widget.sendEvent (event); - } - } - - /* - * At this point, the event queue could - * be null due to a recursive invokation - * when running the event. - */ - } - - /* Clear the queue */ - eventQueue = null; - return run; -} -boolean runFocusOutEvents () { - if (eventQueue == null) return false; - Event [] focusQueue = null; - int index = 0, count = 0, length = eventQueue.length; - while (index < length) { - Event event = eventQueue [index]; - if (event != null && event.type == SWT.FocusOut) { - if (focusQueue == null) focusQueue = new Event [length]; - focusQueue [count++] = event; - System.arraycopy (eventQueue, index + 1, eventQueue, index, --length - index); - eventQueue [length] = null; - } else { - index++; - } - } - if (focusQueue == null) return false; - for (int i=0; i<count; i++) { - Event event = focusQueue [i]; - Widget widget = event.widget; - if (widget != null && !widget.isDisposed ()) { - Widget item = event.item; - if (item == null || !item.isDisposed ()) { - widget.sendEvent (event); - } - } - } - return true; -} -boolean runPopups () { - if (popups == null) return false; - boolean result = false; - while (popups != null) { - Menu menu = popups [0]; - if (menu == null) break; - int length = popups.length; - System.arraycopy (popups, 1, popups, 0, --length); - popups [length] = null; - runDeferredEvents (); - if (!menu.isDisposed ()) menu._setVisible (true); - result = true; - } - popups = null; - return result; -} -void sendEvent (int eventType, Event event) { - if (eventTable == null && filterTable == null) { - return; - } - if (event == null) event = new Event (); - event.display = this; - event.type = eventType; - if (event.time == 0) event.time = getLastEventTime (); - if (!filterEvent (event)) { - if (eventTable != null) eventTable.sendEvent (event); - } -} -void sendFocusEvent (Control control, int type) { - if (type == SWT.FocusIn) { - focusEvent = SWT.FocusIn; - control.sendEvent (SWT.FocusIn); - focusEvent = SWT.None; - } else { - if (postFocusOut) { - control.postEvent (SWT.FocusOut); - } else { - focusEvent = SWT.FocusOut; - control.sendEvent (SWT.FocusOut); - focusEvent = SWT.None; - } - } -} -/** - * Sets the location of the on-screen pointer relative to the top left corner - * of the screen. <b>Note: It is typically considered bad practice for a - * program to move the on-screen pointer location.</b> - * - * @param x the new x coordinate for the cursor - * @param y the new y coordinate for the cursor - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 2.1 - */ -public void setCursorLocation (int x, int y) { - checkDevice (); - int xWindow = OS.XDefaultRootWindow (xDisplay); - OS.XWarpPointer (xDisplay, OS.None, xWindow, 0, 0, 0, 0, x, y); -} -/** - * Sets the location of the on-screen pointer relative to the top left corner - * of the screen. <b>Note: It is typically considered bad practice for a - * program to move the on-screen pointer location.</b> - * - * @param point new position - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_NULL_ARGUMENT - if the point is null - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 2.0 - */ -public void setCursorLocation (Point point) { - checkDevice (); - if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - setCursorLocation (point.x, point.y); -} -/** - * On platforms which support it, sets the application name - * to be the argument. On Motif, for example, this can be used - * to set the name used for resource lookup. Specifying - * <code>null</code> for the name clears it. - * - * @param name the new app name or <code>null</code> - */ -public static void setAppName (String name) { - APP_NAME = name; -} -void setCurrentCaret (Caret caret) { - if (caretID != 0) OS.XtRemoveTimeOut (caretID); - caretID = 0; - currentCaret = caret; - if (currentCaret != null) { - int blinkRate = currentCaret.blinkRate; - int xtContext = OS.XtDisplayToApplicationContext (xDisplay); - caretID = OS.XtAppAddTimeOut (xtContext, blinkRate, caretProc, 0); - } -} -/** - * Sets the application defined property of the receiver - * with the specified name to the given argument. - * <p> - * Applications may have associated arbitrary objects with the - * receiver in this fashion. If the objects stored in the - * properties need to be notified when the display is disposed - * of, it is the application's responsibility provide a - * <code>disposeExec()</code> handler which does so. - * </p> - * - * @param key the name of the property - * @param value the new value for the property - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the key is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #getData(String) - * @see #disposeExec(Runnable) - */ -public void setData (String key, Object value) { - checkDevice (); - if (key == null) error (SWT.ERROR_NULL_ARGUMENT); - - /* Remove the key/value pair */ - if (value == null) { - if (keys == null) return; - int index = 0; - while (index < keys.length && !keys [index].equals (key)) index++; - if (index == keys.length) return; - if (keys.length == 1) { - keys = null; - values = null; - } else { - String [] newKeys = new String [keys.length - 1]; - Object [] newValues = new Object [values.length - 1]; - System.arraycopy (keys, 0, newKeys, 0, index); - System.arraycopy (keys, index + 1, newKeys, index, newKeys.length - index); - System.arraycopy (values, 0, newValues, 0, index); - System.arraycopy (values, index + 1, newValues, index, newValues.length - index); - keys = newKeys; - values = newValues; - } - return; - } - - /* Add the key/value pair */ - if (keys == null) { - keys = new String [] {key}; - values = new Object [] {value}; - return; - } - for (int i=0; i<keys.length; i++) { - if (keys [i].equals (key)) { - values [i] = value; - return; - } - } - String [] newKeys = new String [keys.length + 1]; - Object [] newValues = new Object [values.length + 1]; - System.arraycopy (keys, 0, newKeys, 0, keys.length); - System.arraycopy (values, 0, newValues, 0, values.length); - newKeys [keys.length] = key; - newValues [values.length] = value; - keys = newKeys; - values = newValues; -} -/** - * Sets the application defined, display specific data - * associated with the receiver, to the argument. - * The <em>display specific data</em> is a single, - * unnamed field that is stored with every display. - * <p> - * Applications may put arbitrary objects in this field. If - * the object stored in the display specific data needs to - * be notified when the display is disposed of, it is the - * application's responsibility provide a - * <code>disposeExec()</code> handler which does so. - * </p> - * - * @param data the new display specific data - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #getData() - * @see #disposeExec(Runnable) - */ -public void setData (Object data) { - checkDevice (); - this.data = data; -} -/** - * Sets the synchronizer used by the display to be - * the argument, which can not be null. - * - * @param synchronizer the new synchronizer for the display (must not be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the synchronizer is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_FAILED_EXEC - if an exception occurred while running an inter-thread message</li> - * </ul> - */ -public void setSynchronizer (Synchronizer synchronizer) { - checkDevice (); - if (synchronizer == null) error (SWT.ERROR_NULL_ARGUMENT); - if (synchronizer == this.synchronizer) return; - Synchronizer oldSynchronizer; - synchronized (Device.class) { - oldSynchronizer = this.synchronizer; - this.synchronizer = synchronizer; - } - if (oldSynchronizer != null) { - oldSynchronizer.runAsyncMessages(true); - } -} -void setToolTipText (int handle, String toolTipText) { - if (toolTipHandle == 0) return; - int shellHandle = OS.XtParent (toolTipHandle); - int shellParent = OS.XtParent (shellHandle); - if (handle != shellParent) return; - showToolTip (handle, toolTipText); -} -void showToolTip (int handle, String toolTipText) { - int shellHandle = 0; - if (toolTipText == null) toolTipText = ""; //$NON-NLS-1$ - char [] text = new char [toolTipText.length ()]; - toolTipText.getChars (0, text.length, text, 0); - Widget.fixMnemonic (text); - /* Use the character encoding for the default locale */ - byte [] buffer = Converter.wcsToMbcs (null, text, true); - if (toolTipHandle != 0) { - shellHandle = OS.XtParent (toolTipHandle); - int shellParent = OS.XtParent (shellHandle); - if (handle != shellParent) return; - int xmString = OS.XmStringGenerate (buffer, null, OS.XmCHARSET_TEXT, null); - int [] argList = {OS.XmNlabelString, xmString}; - OS.XtSetValues (toolTipHandle, argList, argList.length / 2); - if (xmString != 0) OS.XmStringFree (xmString); - } else { - int widgetClass = OS.overrideShellWidgetClass (); - int [] argList1 = { - OS.XmNmwmDecorations, 0, - OS.XmNborderWidth, 1, - OS.XmNallowShellResize, 1, - }; - shellHandle = OS.XtCreatePopupShell (null, widgetClass, handle, argList1, argList1.length / 2); - Color infoForeground = getSystemColor (SWT.COLOR_INFO_FOREGROUND); - Color infoBackground = getSystemColor (SWT.COLOR_INFO_BACKGROUND); - int foregroundPixel = infoForeground.handle.pixel; - int backgroundPixel = infoBackground.handle.pixel; - int [] argList2 = { - OS.XmNforeground, foregroundPixel, - OS.XmNbackground, backgroundPixel, - OS.XmNalignment, OS.XmALIGNMENT_BEGINNING, - }; - toolTipHandle = OS.XmCreateLabel (shellHandle, buffer, argList2, argList2.length / 2); - OS.XtManageChild (toolTipHandle); - } - if (toolTipText == null || toolTipText.length () == 0) { - OS.XtPopdown (shellHandle); - } else { - /* - * Feature in X. There is no way to query the size of a cursor. - * The fix is to use the default cursor size which is 16x16. - */ - int xWindow = OS.XDefaultRootWindow (xDisplay); - int [] rootX = new int [1], rootY = new int [1], unused = new int [1], mask = new int [1]; - OS.XQueryPointer (xDisplay, xWindow, unused, unused, rootX, rootY, unused, unused, mask); - int x = rootX [0] + 16, y = rootY [0] + 16; - - /* - * Ensure that the tool tip is on the screen. - */ - int screen = OS.XDefaultScreen (xDisplay); - int width = OS.XDisplayWidth (xDisplay, screen); - int height = OS.XDisplayHeight (xDisplay, screen); - int [] argList4 = {OS.XmNwidth, 0, OS.XmNheight, 0}; - OS.XtGetValues (toolTipHandle, argList4, argList4.length / 2); - x = Math.max (0, Math.min (x, width - argList4 [1])); - y = Math.max (0, Math.min (y, height - argList4 [3])); - OS.XtMoveWidget (shellHandle, x, y); - int flags = OS.Button1Mask | OS.Button2Mask | OS.Button3Mask; - if ((mask [0] & flags) == 0) OS.XtPopup (shellHandle, OS.XtGrabNone); - } -} -/** - * Causes the user-interface thread to <em>sleep</em> (that is, - * to be put in a state where it does not consume CPU cycles) - * until an event is received or it is otherwise awakened. - * - * @return <code>true</code> if an event requiring dispatching was placed on the queue. - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #wake - */ -public boolean sleep () { - checkDevice (); - if (getMessageCount () != 0) return true; - - /* - * This code is intentionally commented. - */ -// boolean result; -// int xtContext = OS.XtDisplayToApplicationContext (xDisplay); -// do { -// /* -// * Bug in Xt. Under certain circumstances Xt waits -// * forever looking for X events, ignoring alternate -// * inputs. The fix is to never sleep forever. -// */ -// //int sleepID = OS.XtAppAddTimeOut (xtContext, 50, 0, 0); -// result = OS.XtAppPeekEvent (xtContext, xEvent); -// //if (sleepID != 0) OS.XtRemoveTimeOut (sleepID); -// } while (!result && getMessageCount () == 0 && OS.XtAppPending (xtContext) == 0); -// return result; - - /* Wait for input */ - int result, status; - boolean workProc = true; - int display_fd = OS.ConnectionNumber (xDisplay); - int xtContext = OS.XtDisplayToApplicationContext (xDisplay); - int max_fd = display_fd > read_fd ? display_fd : read_fd; - do { - OS.FD_ZERO (fd_set); - OS.FD_SET (display_fd, fd_set); - OS.FD_SET (read_fd, fd_set); - timeout [0] = 0; - timeout [1] = 50000; - /* Exit the OS lock to allow other threads to enter Motif */ - Lock lock = OS.lock; - int count = lock.lock (); - for (int i = 0; i < count; i++) lock.unlock (); - try { - result = OS.select (max_fd + 1, fd_set, null, null, timeout); - } finally { - for (int i = 0; i < count; i++) lock.lock (); - lock.unlock (); - } - /* - * Force Xt work procs that were added by native - * widgets to run by calling XtAppProcessEvent(). - * Ensure that XtAppProcessEvent() does not block - * by adding a time out. - */ - status = OS.XtAppPending (xtContext); - if (workProc && status == 0) { - workProc = false; - OS.XtAppAddTimeOut (xtContext, 1, 0, 0); - OS.XtAppProcessEvent (xtContext, OS.XtIMTimer); - } - } while (result == 0 && getMessageCount () == 0 && status == 0); - return OS.FD_ISSET (display_fd, fd_set); -} -/** - * Causes the <code>run()</code> method of the runnable to - * be invoked by the user-interface thread at the next - * reasonable opportunity. The thread which calls this method - * is suspended until the runnable completes. Specifying <code>null</code> - * as the runnable simply wakes the user-interface thread. - * <p> - * Note that at the time the runnable is invoked, widgets - * that have the receiver as their display may have been - * disposed. Therefore, it is necessary to check for this - * case inside the runnable before accessing the widget. - * </p> - * - * @param runnable code to run on the user-interface thread or <code>null</code> - * - * @exception SWTException <ul> - * <li>ERROR_FAILED_EXEC - if an exception occurred when executing the runnable</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #asyncExec - */ -public void syncExec (Runnable runnable) { - Synchronizer synchronizer; - synchronized (Device.class) { - if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); - synchronizer = this.synchronizer; - } - synchronizer.syncExec (runnable); -} -int textWidth (String string, Font font) { - if (string.length () == 0) return 0; - int fontList = font.handle; - String codePage = font.codePage; - byte [] textBuffer = Converter.wcsToMbcs (codePage, string, true); - int xmString = OS.XmStringGenerate (textBuffer, null, OS.XmCHARSET_TEXT, null); - int width = OS.XmStringWidth (fontList, xmString); - OS.XmStringFree (xmString); - return width; -} -/** - * Causes the <code>run()</code> method of the runnable to - * be invoked by the user-interface thread after the specified - * number of milliseconds have elapsed. If milliseconds is less - * than zero, the runnable is not executed. - * <p> - * Note that at the time the runnable is invoked, widgets - * that have the receiver as their display may have been - * disposed. Therefore, it is necessary to check for this - * case inside the runnable before accessing the widget. - * </p> - * - * @param milliseconds the delay before running the runnable - * @param runnable code to run on the user-interface thread - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #asyncExec - */ -public void timerExec (int milliseconds, Runnable runnable) { - checkDevice (); - if (runnable == null) error (SWT.ERROR_NULL_ARGUMENT); - if (timerList == null) timerList = new Runnable [4]; - if (timerIds == null) timerIds = new int [4]; - int index = 0; - while (index < timerList.length) { - if (timerList [index] == runnable) break; - index++; - } - if (index != timerList.length) { - OS.XtRemoveTimeOut (timerIds [index]); - timerList [index] = null; - timerIds [index] = 0; - if (milliseconds < 0) return; - } else { - if (milliseconds < 0) return; - index = 0; - while (index < timerList.length) { - if (timerList [index] == null) break; - index++; - } - if (index == timerList.length) { - Runnable [] newTimerList = new Runnable [timerList.length + 4]; - System.arraycopy (timerList, 0, newTimerList, 0, timerList.length); - timerList = newTimerList; - int [] newTimerIds = new int [timerIds.length + 4]; - System.arraycopy (timerIds, 0, newTimerIds, 0, timerIds.length); - timerIds = newTimerIds; - } - } - int xtContext = OS.XtDisplayToApplicationContext (xDisplay); - int timerId = OS.XtAppAddTimeOut (xtContext, milliseconds, timerProc, index); - if (timerId != 0) { - timerIds [index] = timerId; - timerList [index] = runnable; - } -} -int timerProc (int index, int id) { - if (timerList == null) return 0; - if (0 <= index && index < timerList.length) { - Runnable runnable = timerList [index]; - timerList [index] = null; - timerIds [index] = 0; - if (runnable != null) runnable.run (); - } - return 0; -} -static int translateKey (int key) { - for (int i=0; i<KeyTable.length; i++) { - if (KeyTable [i] [0] == key) return KeyTable [i] [1]; - } - return 0; -} -static int untranslateKey (int key) { - for (int i=0; i<KeyTable.length; i++) { - if (KeyTable [i] [1] == key) return KeyTable [i] [0]; - } - return 0; -} -/** - * Forces all outstanding paint requests for the display - * to be processed before this method returns. - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see Control#update() - */ -public void update () { - checkDevice (); - int event = OS.XtMalloc (XEvent.sizeof); - int mask = OS.ExposureMask | OS.ResizeRedirectMask | - OS.StructureNotifyMask | OS.SubstructureNotifyMask | - OS.SubstructureRedirectMask; - OS.XSync (xDisplay, false); - OS.XSync (xDisplay, false); - while (OS.XCheckMaskEvent (xDisplay, mask, event)) OS.XtDispatchEvent (event); - OS.XtFree (event); -} -/** - * If the receiver's user-interface thread was <code>sleep</code>ing, - * causes it to be awakened and start running again. Note that this - * method may be called from any thread. - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #sleep - */ -public void wake () { - synchronized (Device.class) { - if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); - if (thread == Thread.currentThread ()) return; - wakeThread (); - } -} -void wakeThread () { - /* Write a single byte to the wake up pipe */ - while (OS.write (write_fd, wake_buffer, 1) != 1) {/* empty */} -} -int wakeProc (int closure, int source, int id) { - /* Read a single byte from the wake up pipe */ - while (OS.read (read_fd, wake_buffer, 1) != 1) {/* empty */} - return 0; -} -static int wcsToMbcs (char ch) { - return wcsToMbcs (ch, null); -} -static int wcsToMbcs (char ch, String codePage) { - int key = ch & 0xFFFF; - if (key <= 0x7F) return ch; - byte [] buffer = Converter.wcsToMbcs (codePage, new char [] {ch}, false); - if (buffer.length == 1) return (char) buffer [0]; - if (buffer.length == 2) { - return (char) (((buffer [0] & 0xFF) << 8) | (buffer [1] & 0xFF)); - } - return 0; -} -int windowTimerProc (int handle, int id) { - Widget widget = getWidget (handle); - if (widget == null) return 0; - return widget.timerProc (id); -} -int windowProc (int w, int client_data, int call_data, int continue_to_dispatch) { - Widget widget = getWidget (w); - if (widget == null) return 0; - return widget.windowProc (w, client_data, call_data, continue_to_dispatch); -} -String wrapText (String text, Font font, int width) { - String Lf = "\n"; //$NON-NLS-1$ - text = convertToLf (text); - int length = text.length (); - if (width <= 0 || length == 0 || length == 1) return text; - StringBuffer result = new StringBuffer (); - int lineStart = 0, lineEnd = 0; - while (lineStart < length) { - lineEnd = text.indexOf (Lf, lineStart); - boolean noLf = lineEnd == -1; - if (noLf) lineEnd = length; - int nextStart = lineEnd + Lf.length (); - while (lineEnd > lineStart + 1 && Compatibility.isWhitespace (text.charAt (lineEnd - 1))) { - lineEnd--; - } - int wordStart = lineStart, wordEnd = lineStart; - int i = lineStart; - while (i < lineEnd) { - int lastStart = wordStart, lastEnd = wordEnd; - wordStart = i; - while (i < lineEnd && !Compatibility.isWhitespace (text.charAt (i))) { - i++; - } - wordEnd = i - 1; - String line = text.substring (lineStart, wordEnd + 1); - int lineWidth = textWidth (line, font); - while (i < lineEnd && Compatibility.isWhitespace (text.charAt (i))) { - i++; - } - if (lineWidth > width) { - if (lastStart == wordStart) { - while (wordStart < wordEnd) { - line = text.substring (lineStart, wordStart + 1); - lineWidth = textWidth (line, font); - if (lineWidth >= width) break; - wordStart++; - } - if (wordStart == lastStart) wordStart++; - lastEnd = wordStart - 1; - } - line = text.substring (lineStart, lastEnd + 1); - result.append (line); result.append (Lf); - i = wordStart; lineStart = wordStart; wordEnd = wordStart; - } - } - if (lineStart < lineEnd) { - result.append (text.substring (lineStart, lineEnd)); - } - if (!noLf) { - result.append (Lf); - } - lineStart = nextStart; - } - return result.toString (); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java deleted file mode 100755 index 363448ab89..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java +++ /dev/null @@ -1,650 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; - -/** - * Instances of this class allow the user to navigate - * the file system and select or enter a file name. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>SAVE, OPEN, MULTI</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * Note: Only one of the styles SAVE and OPEN may be specified. - * </p><p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#filedialog">FileDialog snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class FileDialog extends Dialog { - int dialog; - String [] filterNames = new String [0]; - String [] filterExtensions = new String [0]; - String [] fileNames = new String [0]; - String fileName = ""; //$NON-NLS-1$ - String filterPath = ""; //$NON-NLS-1$ - String fullPath; - int filterIndex = -1; - boolean overwrite = false; - static final String FILTER = "*"; //$NON-NLS-1$ - static final char SEPARATOR = System.getProperty ("file.separator").charAt (0); //$NON-NLS-1$ - -/** - * Constructs a new instance of this class given only its parent. - * - * @param parent a shell which will be the parent of the new instance - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - */ -public FileDialog (Shell parent) { - this (parent, SWT.APPLICATION_MODAL); -} - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a shell which will be the parent of the new instance - * @param style the style of dialog to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#SAVE - * @see SWT#OPEN - * @see SWT#MULTI - */ -public FileDialog (Shell parent, int style) { - super (parent, checkStyle (parent, style)); - checkSubclass (); -} - -int cancelPressed (int widget, int client, int call) { - OS.XtUnmanageChild (widget); - return 0; -} -/** - * Returns the path of the first file that was - * selected in the dialog relative to the filter path, or an - * empty string if no such file has been selected. - * - * @return the relative path of the file - */ -public String getFileName () { - return fileName; -} - -/** - * Returns a (possibly empty) array with the paths of all files - * that were selected in the dialog relative to the filter path. - * - * @return the relative paths of the files - */ -public String [] getFileNames () { - return fileNames; -} - -/** - * Returns the file extensions which the dialog will - * use to filter the files it shows. - * - * @return the file extensions filter - */ -public String [] getFilterExtensions () { - return filterExtensions; -} - -/** - * Get the 0-based index of the file extension filter - * which was selected by the user, or -1 if no filter - * was selected. - * <p> - * This is an index into the FilterExtensions array and - * the FilterNames array. - * </p> - * - * @return index the file extension filter index - * - * @see #getFilterExtensions - * @see #getFilterNames - * - * @since 3.4 - */ -public int getFilterIndex () { - return filterIndex; -} - -/** - * Returns the names that describe the filter extensions - * which the dialog will use to filter the files it shows. - * - * @return the list of filter names - */ -public String [] getFilterNames () { - return filterNames; -} - -/** - * Returns the directory path that the dialog will use, or an empty - * string if this is not set. File names in this path will appear - * in the dialog, filtered according to the filter extensions. - * - * @return the directory path string - * - * @see #setFilterExtensions - */ -public String getFilterPath () { - return filterPath; -} - -/** - * Returns the flag that the dialog will use to - * determine whether to prompt the user for file - * overwrite if the selected file already exists. - * - * @return true if the dialog will prompt for file overwrite, false otherwise - * - * @since 3.4 - */ -public boolean getOverwrite () { - return overwrite; -} - -int itemSelected (int widget, int client, int call) { - /* this callback will only be hooked if the dialog style is MULTI */ - int fileList = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST); - if (fileList == 0) return 0; - int selectionText = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_TEXT); - if (selectionText == 0) return 0; - - int [] argList = {OS.XmNselectedItems, 0, OS.XmNselectedItemCount, 0}; - OS.XtGetValues (fileList, argList, argList.length / 2); - int items = argList [1], itemCount = argList [3]; - int ptr = 0; - if (itemCount == 0) { - int [] argList2 = {OS.XmNdirectory, 0}; - OS.XtGetValues (dialog, argList2, argList2.length / 2); - ptr = argList2 [1]; - } else { - int [] buffer = new int [1]; - OS.memmove (buffer, items, 4); - ptr = buffer [0]; - } - if (ptr == 0) return 0; - Display display = parent.getDisplay (); - int [] table = new int [] {display.tabMapping, display.crMapping}; - int address = OS.XmStringUnparse ( - ptr, - null, - OS.XmCHARSET_TEXT, - OS.XmCHARSET_TEXT, - table, - table.length, - OS.XmOUTPUT_ALL); - if (itemCount == 0) OS.XmStringFree (ptr); - if (address == 0) return 0; - int length = OS.strlen (address); - byte [] buffer = new byte [length + 1]; - OS.memmove (buffer, address, length); - OS.XtFree (address); - - OS.XmTextSetString (selectionText, buffer); - OS.XmTextSetInsertionPosition (selectionText, OS.XmTextGetLastPosition (selectionText)); - return 0; -} - -int okPressed (int widget, int client, int call) { - String fullPath = null, fileName = null; - String [] fileNames = null; - - int [] argList = {OS.XmNdirSpec, 0, OS.XmNdirectory, 0}; - OS.XtGetValues (dialog, argList, argList.length / 2); - - int xmString1 = argList [1]; - Display display = parent.getDisplay (); - int [] table = new int [] {display.tabMapping, display.crMapping}; - int ptr = OS.XmStringUnparse ( - xmString1, - null, - OS.XmCHARSET_TEXT, - OS.XmCHARSET_TEXT, - table, - table.length, - OS.XmOUTPUT_ALL); - if (ptr != 0) { - int length = OS.strlen (ptr); - byte [] buffer = new byte [length]; - OS.memmove (buffer, ptr, length); - OS.XtFree (ptr); - /* Use the character encoding for the default locale */ - fullPath = new String (Converter.mbcsToWcs (null, buffer)).trim(); - } - OS.XmStringFree (xmString1); - - filterIndex = filterExtensions == null || filterExtensions.length == 0 ? -1 : 0; - if ((style & SWT.MULTI) != 0) { - int fileList = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST); - if (fileList == 0) return 0; - int [] argList2 = {OS.XmNselectedItems, 0, OS.XmNselectedItemCount, 0}; - OS.XtGetValues (fileList, argList2, argList2.length / 2); - int items = argList2 [1], itemCount = argList2 [3]; - int [] buffer1 = new int [1]; - fileNames = new String [itemCount]; - boolean match = false; - for (int i = 0; i < itemCount; i++) { - OS.memmove (buffer1, items, 4); - ptr = buffer1 [0]; - int address = OS.XmStringUnparse ( - ptr, - null, - OS.XmCHARSET_TEXT, - OS.XmCHARSET_TEXT, - table, - table.length, - OS.XmOUTPUT_ALL); - if (address != 0) { - int length = OS.strlen (address); - byte [] buffer = new byte [length]; - OS.memmove (buffer, address, length); - OS.XtFree (address); - /* Use the character encoding for the default locale */ - String fullFilename = new String (Converter.mbcsToWcs (null, buffer)); - int index = fullFilename.lastIndexOf (SEPARATOR); - fileNames [i] = fullFilename.substring (index + 1, fullFilename.length ()); - if (fullFilename.equals (fullPath)) match = true; - } - items += 4; - } - if (match) { - fileName = fileNames [0]; - } else { - /* The user has modified the text field such that it doesn't match any - * of the selected files, so use this value instead - */ - int index = fullPath.lastIndexOf (SEPARATOR); - fileName = fullPath.substring (index + 1, fullPath.length ()); - fileNames = new String [] {fileName}; - } - } else { - int index = fullPath.lastIndexOf (SEPARATOR); - fileName = fullPath.substring (index + 1, fullPath.length ()); - fileNames = new String [] {fileName}; - } - - // if no file selected then go into the current directory - if (fileName.equals("")) { //$NON-NLS-1$ - int [] argList1 = {OS.XmNdirMask, 0}; - OS.XtGetValues (dialog, argList1, argList1.length / 2); - int directoryHandle = argList1[1]; - int [] argList2 = {OS.XmNpattern,directoryHandle}; - OS.XtSetValues (dialog, argList2, argList2.length / 2); - OS.XmStringFree (directoryHandle); - return 0; - } - - int xmString2 = argList [3]; - ptr = OS.XmStringUnparse ( - xmString2, - null, - OS.XmCHARSET_TEXT, - OS.XmCHARSET_TEXT, - table, - table.length, - OS.XmOUTPUT_ALL); - if (ptr != 0) { - int length = OS.strlen (ptr); - byte [] buffer = new byte [length]; - OS.memmove (buffer, ptr, length); - OS.XtFree (ptr); - /* Use the character encoding for the default locale */ - filterPath = new String (Converter.mbcsToWcs (null, buffer)); - } - OS.XmStringFree (xmString2); - int length = filterPath.length (); - if (length > 0) { - if (filterPath.charAt (length - 1) == SEPARATOR) { - filterPath = filterPath.substring (0, length - 1); - } - } - - this.fullPath = fullPath; - this.fileName = fileName; - this.fileNames = fileNames; - OS.XtUnmanageChild (widget); - return 0; -} - -/** - * Makes the dialog visible and brings it to the front - * of the display. - * - * @return a string describing the absolute path of the first selected file, - * or null if the dialog was cancelled or an error occurred - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li> - * </ul> - */ -public String open () { - /* Compute the dialog title */ - /* - * Feature in Motif. It is not possible to set a shell - * title to an empty string. The fix is to set the title - * to be a single space. - */ - String string = title; - if (string.length () == 0) string = " "; //$NON-NLS-1$ - /* Use the character encoding for the default locale */ - byte [] buffer1 = Converter.wcsToMbcs (null, string, true); - int xmStringPtr1 = OS.XmStringParseText ( - buffer1, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - - fullPath = null; - fileNames = new String [0]; - - /* Compute the filter */ - String mask = FILTER; - if (filterExtensions == null) filterExtensions = new String [0]; - if (filterNames == null) filterNames = new String [0]; - if (filterExtensions.length != 0) { - /* Motif does not support multiple filters, so ignore them - * if there are more than one, or if there is a ; separator. - */ - if (filterExtensions.length == 1) { - String filter = filterExtensions [0]; - if (filter.indexOf (';', 0) == -1) mask = filter; - } - } - /* Use the character encoding for the default locale */ - byte [] buffer2 = Converter.wcsToMbcs (null, mask, true); - int xmStringPtr2 = OS.XmStringParseText ( - buffer2, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - - /* Compute the filter path */ - if (filterPath == null) filterPath = ""; //$NON-NLS-1$ - int length = filterPath.length (); - if (length == 0 || filterPath.charAt (length - 1) != SEPARATOR) { - filterPath += SEPARATOR; - } - /* Use the character encoding for the default locale */ - byte [] buffer3 = Converter.wcsToMbcs (null, filterPath, true); - int xmStringPtr3 = OS.XmStringParseText ( - buffer3, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - - /* Create the dialog */ - boolean defaultPos = parent.isVisible (); - Display display = parent.display; - int [] argList1 = { - OS.XmNresizePolicy, OS.XmRESIZE_NONE, - OS.XmNdialogStyle, OS.XmDIALOG_PRIMARY_APPLICATION_MODAL, - OS.XmNwidth, OS.XDisplayWidth (display.xDisplay, OS.XDefaultScreen (display.xDisplay)) * 4 / 9, - OS.XmNpathMode, OS.XmPATH_MODE_FULL, - OS.XmNdialogTitle, xmStringPtr1, - OS.XmNpattern, xmStringPtr2, - OS.XmNdirMask, xmStringPtr3, - OS.XmNdefaultPosition, defaultPos ? 1 : 0, - }; - /* - * Bug in AIX. The dialog does not respond to input, if the parent - * is not realized. The fix is to realize the parent. - */ - if (OS.IsAIX) parent.realizeWidget (); - int parentHandle = parent.shellHandle; - /* - * Feature in Linux. For some reason, the XmCreateFileSelectionDialog() - * will not accept NULL for the widget name. This works fine on the other - * Motif platforms and in the other XmCreate calls on Linux. The fix is - * to pass in a NULL terminated string, not a NULL pointer. - */ - byte [] name = new byte [] {0}; - dialog = OS.XmCreateFileSelectionDialog (parentHandle, name, argList1, argList1.length / 2); - int child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_HELP_BUTTON); - if (child != 0) OS.XtUnmanageChild (child); - OS.XmStringFree (xmStringPtr1); - OS.XmStringFree (xmStringPtr2); - OS.XmStringFree (xmStringPtr3); - - /* - * Can override the selection text field if necessary now that - * its initial value has been computed by the platform dialog. - */ - if (fileName != null && fileName.length() > 0) { - /* Use the character encoding for the default locale */ - byte [] buffer4 = Converter.wcsToMbcs (null, fileName, true); - int xmStringPtr4 = OS.XmStringParseText ( - buffer4, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - int [] argList2 = {OS.XmNdirSpec, 0}; - OS.XtGetValues (dialog, argList2, argList2.length / 2); - int oldDirSpec = argList2 [1]; - int newDirSpec = OS.XmStringConcat (oldDirSpec, xmStringPtr4); - argList2 [1] = newDirSpec; - OS.XtSetValues (dialog, argList2, argList2.length / 2); - OS.XmStringFree (xmStringPtr4); - OS.XmStringFree (oldDirSpec); - OS.XmStringFree (newDirSpec); - } - - /* Hook the callbacks. */ - Callback cancelCallback = new Callback (this, "cancelPressed", 3); //$NON-NLS-1$ - int cancelAddress = cancelCallback.getAddress (); - if (cancelAddress == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - OS.XtAddCallback (dialog, OS.XmNcancelCallback, cancelAddress, 0); - Callback okCallback = new Callback (this, "okPressed", 3); //$NON-NLS-1$ - int okAddress = okCallback.getAddress (); - if (okAddress == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - OS.XtAddCallback (dialog, OS.XmNokCallback, okAddress, 0); - Callback selectCallback = null; - if ((style & SWT.MULTI) != 0) { - child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST); - if (child != 0) { - int [] argList3 = {OS.XmNselectionPolicy, OS.XmEXTENDED_SELECT}; - OS.XtSetValues(child, argList3, argList3.length / 2); - selectCallback = new Callback (this, "itemSelected", 3); //$NON-NLS-1$ - int selectAddress = selectCallback.getAddress (); - if (selectAddress == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - OS.XtAddCallback (child, OS.XmNextendedSelectionCallback, selectAddress, 0); - } - } - - if (!defaultPos) { - OS.XtRealizeWidget (dialog); - int[] argList4 = new int[] { - OS.XmNwidth, 0, - OS.XmNheight, 0, - }; - OS.XtGetValues (dialog, argList4, argList4.length / 2); - Monitor monitor = parent.getMonitor (); - Rectangle bounds = monitor.getBounds (); - int x = bounds.x + (bounds.width - argList4 [1]) / 2; - int y = bounds.y + (bounds.height - argList4 [3]) / 2; - int[] argList5 = new int[] { - OS.XmNx, x, - OS.XmNy, y, - }; - OS.XtSetValues (dialog, argList5, argList5.length / 2); - } - OS.XtManageChild (dialog); - - // Should be a pure OS message loop (no SWT AppContext) - while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog)) - if (!display.readAndDispatch ()) display.sleep (); - - /* Destroy the dialog and update the display. */ - if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog); - okCallback.dispose (); - cancelCallback.dispose (); - if (selectCallback != null) selectCallback.dispose (); - return fullPath; -} - -/** - * Set the initial filename which the dialog will - * select by default when opened to the argument, - * which may be null. The name will be prefixed with - * the filter path when one is supplied. - * - * @param string the file name - */ -public void setFileName (String string) { - fileName = string; -} - -/** - * Set the file extensions which the dialog will - * use to filter the files it shows to the argument, - * which may be null. - * <p> - * The strings are platform specific. For example, on - * some platforms, an extension filter string is typically - * of the form "*.extension", where "*.*" matches all files. - * For filters with multiple extensions, use semicolon as - * a separator, e.g. "*.jpg;*.png". - * </p> - * - * @param extensions the file extension filter - * - * @see #setFilterNames to specify the user-friendly - * names corresponding to the extensions - */ -public void setFilterExtensions (String [] extensions) { - filterExtensions = extensions; -} - -/** - * Set the 0-based index of the file extension filter - * which the dialog will use initially to filter the files - * it shows to the argument. - * <p> - * This is an index into the FilterExtensions array and - * the FilterNames array. - * </p> - * - * @param index the file extension filter index - * - * @see #setFilterExtensions - * @see #setFilterNames - * - * @since 3.4 - */ -public void setFilterIndex (int index) { - filterIndex = index; -} - -/** - * Sets the names that describe the filter extensions - * which the dialog will use to filter the files it shows - * to the argument, which may be null. - * <p> - * Each name is a user-friendly short description shown for - * its corresponding filter. The <code>names</code> array must - * be the same length as the <code>extensions</code> array. - * </p> - * - * @param names the list of filter names, or null for no filter names - * - * @see #setFilterExtensions - */ -public void setFilterNames (String [] names) { - filterNames = names; -} - -/** - * Sets the directory path that the dialog will use - * to the argument, which may be null. File names in this - * path will appear in the dialog, filtered according - * to the filter extensions. If the string is null, - * then the operating system's default filter path - * will be used. - * <p> - * Note that the path string is platform dependent. - * For convenience, either '/' or '\' can be used - * as a path separator. - * </p> - * - * @param string the directory path - * - * @see #setFilterExtensions - */ -public void setFilterPath (String string) { - filterPath = string; -} - -/** - * Sets the flag that the dialog will use to - * determine whether to prompt the user for file - * overwrite if the selected file already exists. - * - * @param overwrite true if the dialog will prompt for file overwrite, false otherwise - * - * @since 3.4 - */ -public void setOverwrite (boolean overwrite) { -// this.overwrite = overwrite; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java deleted file mode 100755 index 7107e8e7f6..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java +++ /dev/null @@ -1,1176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.layout.*; - -import java.util.*; - -/** - * Instances of this class allow the user to select a font - * from all available fonts in the system. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class FontDialog extends Dialog { - private FontData [] fontData; - private FontData currentFontData; - private Font sampleFont; // the displayed sample font - private Color sampleColor; // the displayed sample color - private RGB rgb; - private boolean okSelected = false; - private boolean ignoreEvents = false; - /* - * Table containing all available fonts as FontData objects. - * The table is structured as a series of embedded Hashtables as follows: - * <br>characterRegistryName -> faceName -> extendedStyle -> size -> style - */ - private Hashtable characterSets = new Hashtable (); - - // widgets - private Shell shell; - private List fontSetList; - private List charSetList, faceNameList, extStyleList; - private List fontStyleList, fontSizeList; - private Label sampleLabel; - private Button upButton, downButton, newButton, removeButton; - private Button okButton, cancelButton, colorButton; - - // constants - private static final String TEXT_SAMPLE = "AaBbYyZz"; - private static String SCALABLE_SIZES []; - private static final int DEFAULT_SIZE = 14; - private static final String DEFAULT_STYLE = "medium"; - private static final Integer SCALABLE_KEY = new Integer (0); - private static final int LIST_WIDTH = 200; - private static final int EXTSTYLE_WIDTH = 150; - private static final int LIST_HEIGHT = 150; - private static final int SAMPLE_HEIGHT = 75; - private static final String PREFIX_ISO8859 = "iso8859"; - private static final String PREFIX_ISO646 = "iso646"; - private static final String PREFIX_UNICODE = "ucs"; - private static final String PREFIX_JAPANESE = "jis"; - private static final String PREFIX_SIMPLIFIEDCHINESE = "gb"; - private static final String PREFIX_TRADITIONALCHINESE = "cns"; - private static final String PREFIX_KOREAN = "ks"; - private static final String [] ISO_CHARSETS = new String [] { - "", // 0 undefined - SWT.getMessage ("SWT_Charset_Western"), - SWT.getMessage ("SWT_Charset_EastEuropean"), - SWT.getMessage ("SWT_Charset_SouthEuropean"), - SWT.getMessage ("SWT_Charset_NorthEuropean"), - SWT.getMessage ("SWT_Charset_Cyrillic"), - SWT.getMessage ("SWT_Charset_Arabic"), - SWT.getMessage ("SWT_Charset_Greek"), - SWT.getMessage ("SWT_Charset_Hebrew"), - SWT.getMessage ("SWT_Charset_Turkish"), - SWT.getMessage ("SWT_Charset_Nordic"), - SWT.getMessage ("SWT_Charset_Thai"), - "", // 12 undefined - SWT.getMessage ("SWT_Charset_BalticRim"), - SWT.getMessage ("SWT_Charset_Celtic"), - SWT.getMessage ("SWT_Charset_Euro"), - SWT.getMessage ("SWT_Charset_Romanian") - }; - - static { - SCALABLE_SIZES = new String [69]; - for (int i = 0; i < 69; i++) { - SCALABLE_SIZES [i] = String.valueOf (i + 4); - } - } - -/** - * Constructs a new instance of this class given only its parent. - * - * @param parent a shell which will be the parent of the new instance - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - */ -public FontDialog (Shell parent) { - this (parent, SWT.APPLICATION_MODAL); -} - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a shell which will be the parent of the new instance - * @param style the style of dialog to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - */ -public FontDialog (Shell parent, int style) { - super (parent, checkStyle (parent, style)); - checkSubclass (); -} - -/** - * Add the fonts found in 'fonts' to the list of fonts. - * Fonts are stored by character set and face name. For each character - * set/face name combination there is one FontExtStyles object that - * captures the different extended styles and the sizes and styles - * available for that extended style. - */ -void addFonts (FontData fonts []) { - for (int i = 0; i < fonts.length; i++) { - FontData font = fonts [i]; - String charSetName = getTranslatedCharSet (font, true); - Hashtable charSet = (Hashtable) characterSets.get (charSetName); - if (charSet == null) { - charSet = new Hashtable (9); - characterSets.put (charSetName, charSet); - } - - String faceName = getTranslatedFaceName (font); - Hashtable faceSet = (Hashtable) charSet.get (faceName); - if (faceSet == null) { - faceSet = new Hashtable (9); - charSet.put (faceName, faceSet); - } - - String extStyleName = font.addStyle; - Hashtable extStyleSet = (Hashtable) faceSet.get (extStyleName); - if (extStyleSet == null) { - extStyleSet = new Hashtable (9); - faceSet.put (extStyleName, extStyleSet); - } - - Integer sizeValue = new Integer (font.getHeight ()); - Hashtable sizeSet = (Hashtable) extStyleSet.get (sizeValue); - if (sizeSet == null) { - sizeSet = new Hashtable (9); - extStyleSet.put (sizeValue, sizeSet); - } - - String style = font.weight; - sizeSet.put (style,font); - } -} - -void centerListIndex (List list, int index) { - int visibleItems = list.getSize ().y / list.getItemHeight (); - int topIndex = Math.max (0, index - visibleItems / 2); - list.setTopIndex (topIndex); -} - -FontData copyFontData (FontData data) { - FontData result = new FontData (); - result.addStyle = data.addStyle; - result.averageWidth = data.averageWidth; - result.characterSetName = data.characterSetName; - result.characterSetRegistry = data.characterSetRegistry; - result.fontFamily = data.fontFamily; - result.foundry = data.foundry; - result.horizontalResolution = data.horizontalResolution; - result.pixels = data.pixels; - result.points = data.points; - result.setWidth = data.setWidth; - result.slant = data.slant; - result.spacing = data.spacing; - result.verticalResolution = data.verticalResolution; - result.weight = data.weight; - return result; -} - -void createButtons (Composite parent) { - int buttonAlignment = GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING; - okButton = new Button (parent, SWT.PUSH); - okButton.setText (SWT.getMessage ("SWT_OK")); - okButton.setLayoutData (new GridData (buttonAlignment)); - shell.setDefaultButton (okButton); - - cancelButton = new Button (parent, SWT.PUSH); - cancelButton.setText (SWT.getMessage ("SWT_Cancel")); - cancelButton.setLayoutData (new GridData (buttonAlignment)); - - colorButton = new Button (parent, SWT.PUSH); - colorButton.setText (SWT.getMessage ("SWT_Color")); - colorButton.setLayoutData (new GridData (buttonAlignment)); -} - -void createControls (Composite parent) { - Composite composite = new Composite (parent, SWT.NONE); - GridLayout layout = new GridLayout (); - layout.numColumns = 2; - composite.setLayout (layout); - - Composite controls = new Composite (composite, SWT.NONE); - layout = new GridLayout (); - layout.marginHeight = layout.marginWidth = 0; - layout.numColumns = 3; - controls.setLayout (layout); - - // labels row (1) - new Label (controls, SWT.NONE).setText (SWT.getMessage ("SWT_Character_set") + ":"); - new Label (controls, SWT.NONE).setText (SWT.getMessage ("SWT_Font") + ":"); - new Label (controls, SWT.NONE).setText (SWT.getMessage ("SWT_Extended_style") + ":"); - - // lists row (2) - charSetList = new List (controls, SWT.V_SCROLL | SWT.BORDER); - GridData gridData = new GridData (GridData.FILL_HORIZONTAL); - gridData.heightHint = LIST_HEIGHT; - gridData.widthHint = LIST_WIDTH; - charSetList.setLayoutData (gridData); - - faceNameList = new List (controls, SWT.V_SCROLL | SWT.BORDER); - gridData = new GridData (GridData.FILL_HORIZONTAL); - gridData.heightHint = LIST_HEIGHT; - gridData.widthHint = LIST_WIDTH; - faceNameList.setLayoutData (gridData); - - extStyleList = new List (controls, SWT.V_SCROLL | SWT.MULTI | SWT.BORDER); - gridData = new GridData (GridData.FILL_HORIZONTAL); - gridData.heightHint = LIST_HEIGHT; - gridData.widthHint = EXTSTYLE_WIDTH; - extStyleList.setLayoutData (gridData); - - // labels row (3) - new Label (controls, SWT.NONE).setText (SWT.getMessage ("SWT_Size") + ":"); - new Label (controls, SWT.NONE).setText (SWT.getMessage ("SWT_Style") + ":"); - new Label (controls, SWT.NONE); // filler - - // lists row (4) - fontSizeList = new List (controls, SWT.V_SCROLL | SWT.BORDER); - gridData = new GridData (GridData.FILL_HORIZONTAL); - gridData.heightHint = LIST_HEIGHT; - gridData.widthHint = LIST_WIDTH; - fontSizeList.setLayoutData (gridData); - - fontStyleList = new List (controls, SWT.V_SCROLL | SWT.BORDER); - gridData = new GridData (GridData.FILL_HORIZONTAL); - gridData.heightHint = LIST_HEIGHT; - gridData.widthHint = LIST_WIDTH; - fontStyleList.setLayoutData (gridData); - - new Label (controls, SWT.NONE); // filler - - // font sets group - Group fontSetGroup = new Group (controls, SWT.NONE); - fontSetGroup.setText(SWT.getMessage ("SWT_FontSet")); - layout = new GridLayout (); - layout.numColumns = 2; - fontSetGroup.setLayout (layout); - GridData data = new GridData (GridData.FILL_BOTH); - data.horizontalSpan = 3; - fontSetGroup.setLayoutData (data); - - fontSetList = new List (fontSetGroup, SWT.V_SCROLL | SWT.BORDER); - data = new GridData (GridData.FILL_BOTH); - data.grabExcessHorizontalSpace = true; - fontSetList.setLayoutData (data); - - Composite buttonsGroup = new Composite (fontSetGroup, SWT.NONE); - layout = new GridLayout (); - layout.numColumns = 3; - layout.makeColumnsEqualWidth = false; - layout.marginHeight = layout.marginWidth = 0; - layout.horizontalSpacing = layout.verticalSpacing = 0; - buttonsGroup.setLayout (layout); - - Composite upDownButtonsGroup = new Composite (buttonsGroup, SWT.NONE); - layout = new GridLayout (); - layout.marginHeight = layout.marginWidth = 0; - layout.horizontalSpacing = layout.verticalSpacing = 0; - upDownButtonsGroup.setLayout(layout); - - int buttonAlignment = GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_BEGINNING; - upButton = new Button (upDownButtonsGroup, SWT.PUSH); - upButton.setLayoutData (new GridData (buttonAlignment)); - upButton.setText (SWT.getMessage ("SWT_Up")); - downButton = new Button (upDownButtonsGroup, SWT.PUSH); - downButton.setLayoutData (new GridData (buttonAlignment)); - downButton.setText (SWT.getMessage ("SWT_Down")); - - new Label (buttonsGroup, SWT.SEPARATOR | SWT.VERTICAL); - - Composite newRemoveButtonsGroup = new Composite (buttonsGroup, SWT.NONE); - layout = new GridLayout (); - layout.marginHeight = layout.marginWidth = 0; - layout.horizontalSpacing = layout.verticalSpacing = 0; - newRemoveButtonsGroup.setLayout(layout); - - newButton = new Button (newRemoveButtonsGroup, SWT.PUSH); - newButton.setLayoutData (new GridData (buttonAlignment)); - newButton.setText (SWT.getMessage ("SWT_NewFont")); - removeButton = new Button (newRemoveButtonsGroup, SWT.PUSH); - removeButton.setLayoutData (new GridData (buttonAlignment)); - removeButton.setText (SWT.getMessage ("SWT_Remove")); - - // font sample group - Group sampleGroup = new Group (controls, SWT.NONE); - sampleGroup.setText (SWT.getMessage ("SWT_Sample")); - gridData = new GridData (); - gridData.heightHint = SAMPLE_HEIGHT; - gridData.horizontalSpan = 3; - gridData.horizontalAlignment = GridData.FILL; - sampleGroup.setLayoutData (gridData); - layout = new GridLayout (); - layout.marginWidth = 10; - layout.marginHeight = 10; - sampleGroup.setLayout (layout); - - sampleLabel = new Label (sampleGroup, SWT.CENTER); - sampleLabel.setText (TEXT_SAMPLE); - gridData = new GridData (); - gridData.grabExcessHorizontalSpace = true; - gridData.grabExcessVerticalSpace = true; - gridData.verticalAlignment = GridData.FILL; - gridData.horizontalAlignment = GridData.FILL; - sampleLabel.setLayoutData (gridData); - - Composite okCancelGroup = new Composite (composite, SWT.NONE); - layout = new GridLayout (); - layout.marginHeight = layout.marginWidth = layout.verticalSpacing = 0; - okCancelGroup.setLayout (layout); - okCancelGroup.setLayoutData (new GridData (GridData.VERTICAL_ALIGN_BEGINNING)); - createButtons (okCancelGroup); -} - -Hashtable getExtStyles (String charsetName, String faceName) { - Hashtable faces = getFaces (charsetName); - if (faces == null) return null; - return (Hashtable) faces.get (faceName); -} - -Hashtable getFaces (String charsetName) { - return (Hashtable) getFonts ().get (charsetName); -} - -/** - * Returns a FontData object describing the font that was - * selected in the dialog, or null if none is available. - * - * @return the FontData for the selected font, or null - * @deprecated use #getFontList () - */ -public FontData getFontData () { - if (fontData != null && fontData.length > 0) { - return fontData [0]; - } - return null; - -} - -FontData getFontData (String charsetName, String faceName, String extStyle, int size, String style) { - Hashtable styles = getStyles (charsetName, faceName, extStyle, size); - if (styles == null) return null; - return (FontData) styles.get (style); -} - -/** - * Returns a FontData set describing the font that was - * selected in the dialog, or null if none is available. - * - * @return the FontData for the selected font, or null - * @since 2.1.1 - */ -public FontData [] getFontList () { - return fontData; -} - -/** - * Returns the collection of fonts that are displayed by the - * receiver. - * See the class definition for an explanation of the structure - * of the returned Hashtable. - */ -Hashtable getFonts () { - return characterSets; -} - -String getListSelection (List list) { - String [] selection = list.getSelection (); - if (selection.length > 0) return selection [0]; - return ""; -} - -/** - * Returns an RGB describing the color that was selected - * in the dialog, or null if none is available. - * - * @return the RGB value for the selected color, or null - * - * @see PaletteData#getRGBs - * - * @since 2.1 - */ -public RGB getRGB () { - return rgb; -} - -/** - * Returns a FontData object that can be used to load the selected - * font. - */ -FontData getSelectionFontData () { - String charSetName = getListSelection (charSetList); - String faceName = getListSelection (faceNameList); - String extStyle = getListSelection (extStyleList); - int size = DEFAULT_SIZE; - try { - size = Integer.valueOf (getListSelection (fontSizeList)).intValue (); - if (size < 1) size = DEFAULT_SIZE; - } catch (NumberFormatException e) { - /* - * This block is purposely left empty since a default - * value is already specified above. - */ - } - String style = getListSelection (fontStyleList); - FontData result = getFontData (charSetName, faceName, extStyle, size, style); - - if (result != null) { - result = copyFontData (result); - } else { - /* - * One or more of the dialog's widgets contain custom typed values. - * Create a FontData that mirrors these values so that the Font created - * below will try to find the best match. - */ - result = new FontData (); - result.characterSetRegistry = charSetName; - result.setName (faceName); - result.addStyle = extStyle; - result.weight = style; - } - result.setHeight (size); - return result; -} - -Hashtable getSizes (String charsetName, String faceName, String extStyle) { - Hashtable extStyles = getExtStyles (charsetName, faceName); - if (extStyles == null) return null; - return (Hashtable) extStyles.get (extStyle); -} - -Hashtable getStyles (String charsetName, String faceName, String extStyle, int size) { - Hashtable sizes = getSizes (charsetName, faceName, extStyle); - if (sizes == null) return null; - Hashtable result = (Hashtable) sizes.get (new Integer (size)); - if (result == null) - result = (Hashtable) sizes.get (SCALABLE_KEY); - return result; -} - -/** - * Returns the character set found in 'fontData' prefixed - * with a string explaining the character set. - */ -String getTranslatedCharSet (FontData fontData, boolean includeDescription) { - String characterSet = fontData.characterSetRegistry; - String translatedCharSet = null; - - if (characterSet.startsWith (PREFIX_ISO8859)) { - int charSetName = 1; - try { - charSetName = Integer.valueOf (fontData.characterSetName).intValue (); - } catch (NumberFormatException e) { - /* - * This block is purposely left empty since a default - * value is already specified above. - */ - } - characterSet = PREFIX_ISO8859 + "-" + charSetName; - if (charSetName < ISO_CHARSETS.length) { - translatedCharSet = ISO_CHARSETS [charSetName]; - } - } - else - if (characterSet.startsWith (PREFIX_ISO646)) { - translatedCharSet = SWT.getMessage("SWT_Charset_ASCII"); - } - else - if (characterSet.startsWith (PREFIX_UNICODE)) { - translatedCharSet = SWT.getMessage("SWT_Charset_Unicode"); - } - else - if (characterSet.startsWith (PREFIX_JAPANESE)) { - translatedCharSet = SWT.getMessage("SWT_Charset_Japanese"); - } - else - if (characterSet.startsWith (PREFIX_SIMPLIFIEDCHINESE)) { - translatedCharSet = SWT.getMessage("SWT_Charset_SimplifiedChinese"); - } - else - if (characterSet.startsWith (PREFIX_TRADITIONALCHINESE)) { - translatedCharSet = SWT.getMessage("SWT_Charset_TraditionalChinese"); - } - else - if (characterSet.startsWith (PREFIX_KOREAN)) { - translatedCharSet = SWT.getMessage("SWT_Charset_Korean"); - } - if (includeDescription && translatedCharSet != null) { - translatedCharSet = characterSet + " (" + translatedCharSet + ')'; - } - else { - translatedCharSet = characterSet; - } - return translatedCharSet; -} - -/** - * Returns the face name as specified in FontData.familyName followed by - * the foundry set in parantheses if available. - * We display the face name first so that the list sorts the fonts by - * face name, not by foundry. Users generally want to select fonts based - * on the face name and not by foundry. Once they've found the desired - * face name in the list they can compare the font variations from - * different foundries if available. - */ -String getTranslatedFaceName (FontData fontData) { - StringBuffer faceNameBuffer; - - if (fontData.foundry != null && fontData.foundry.length () > 0) { - faceNameBuffer = new StringBuffer (fontData.fontFamily); - faceNameBuffer.append (" ("); - faceNameBuffer.append (fontData.foundry); - faceNameBuffer.append (')'); - } - else { - faceNameBuffer = new StringBuffer (fontData.getName ()); - } - return faceNameBuffer.toString (); -} - -/** - * Handle the events the receiver is listening to. - * List selections cause the downstream lists to be initialized - * with font data and the sample text to be updated. - */ -void handleEvent (Event event) { - if (ignoreEvents) return; - if (event.widget instanceof List) { - List list = (List) event.widget; - String text = getListSelection (list); - int oldSelectIndex = ((Integer)list.getData ()).intValue (); - int newSelectIndex = list.indexOf (text); - if (oldSelectIndex != newSelectIndex || newSelectIndex == -1) { - ignoreEvents = true; - if (list == charSetList) initFaceNameList (); - else if (list == faceNameList) initExtStyleList (); - else if (list == extStyleList) initSizeList (); - else if (list == fontSizeList) initStyleList (); - else if (event.widget == fontSetList) { - currentFontData = fontData [fontSetList.getSelectionIndex ()]; - setFontControls (currentFontData); - updateButtonEnablements (); - } - - updateSampleFont (); - updateFontList (); - list.setData (new Integer (newSelectIndex)); - if (newSelectIndex != -1) { - list.select (newSelectIndex); - } - ignoreEvents = false; - } - return; - } - - if (event.widget instanceof Button) { - if (event.widget == okButton) { - okSelected = true; - shell.close (); - } - else if (event.widget == cancelButton) { - okSelected = false; - shell.close (); - } - else if (event.widget == colorButton) { - ColorDialog colorDialog = new ColorDialog (shell, SWT.NONE); - colorDialog.setRGB (rgb); - RGB newRgb = colorDialog.open (); - if (newRgb != null) { - rgb = newRgb; - updateSampleColor (); - } - } - else if (event.widget == newButton) { - FontData [] newFontData = new FontData [fontData.length + 1]; - System.arraycopy (fontData, 0, newFontData, 0, fontData.length); - FontData source = fontData [fontSetList.getSelectionIndex ()]; - FontData newFd = copyFontData (source); - newFontData [newFontData.length - 1] = newFd; - this.fontData = newFontData; - updateFontList (); - fontSetList.select (newFontData.length - 1); - fontSetList.setData (new Integer (newFontData.length - 1)); - fontSetList.showSelection(); - updateButtonEnablements (); - } - else if (event.widget == removeButton) { - int selectionIndex = fontSetList.getSelectionIndex (); - FontData [] newFontData = new FontData [fontData.length - 1]; - System.arraycopy (fontData, 0, newFontData, 0, selectionIndex); - System.arraycopy (fontData, selectionIndex + 1, newFontData, selectionIndex, newFontData.length - selectionIndex); - fontData = newFontData; - updateFontList (); - updateButtonEnablements (); - setFontControls (fontData [fontSetList.getSelectionIndex ()]); - } - else if (event.widget == upButton) { - int selectionIndex = fontSetList.getSelectionIndex (); - FontData temp = fontData [selectionIndex]; - fontData [selectionIndex] = fontData [selectionIndex - 1]; - fontData [selectionIndex - 1] = temp; - fontSetList.select (selectionIndex - 1); - fontSetList.setData (new Integer (selectionIndex - 1)); - updateFontList (); - updateButtonEnablements (); - } - else if (event.widget == downButton) { - int selectionIndex = fontSetList.getSelectionIndex (); - FontData temp = fontData [selectionIndex]; - fontData [selectionIndex] = fontData [selectionIndex + 1]; - fontData [selectionIndex + 1] = temp; - fontSetList.select (selectionIndex + 1); - fontSetList.setData (new Integer (selectionIndex + 1)); - updateFontList (); - updateButtonEnablements (); - } - } -} - -void hookListeners () { - Listener listener = new Listener () { - public void handleEvent (Event event) { - FontDialog.this.handleEvent (event); - } - }; - okButton.addListener (SWT.Selection, listener); - cancelButton.addListener (SWT.Selection, listener); - colorButton.addListener (SWT.Selection, listener); - charSetList.addListener (SWT.Selection, listener); - faceNameList.addListener (SWT.Selection, listener); - fontStyleList.addListener (SWT.Selection, listener); - extStyleList.addListener (SWT.Selection, listener); - fontSizeList.addListener (SWT.Selection, listener); - newButton.addListener (SWT.Selection, listener); - removeButton.addListener (SWT.Selection, listener); - upButton.addListener (SWT.Selection, listener); - downButton.addListener (SWT.Selection, listener); - fontSetList.addListener (SWT.Selection, listener); -} - -/** - * Initialize the extended styles list with the extended styles - * available for the selected font. - * Downstream lists are initialized as well (style and size). - */ -void initExtStyleList () { - String oldSelect = getListSelection (extStyleList); - extStyleList.removeAll (); - - String characterSet = getListSelection (charSetList); - String faceName = getListSelection (faceNameList); - Hashtable extStyles = getExtStyles (characterSet, faceName); - setItemsSorted (extStyleList, extStyles); - - int selectIndex = extStyleList.indexOf (oldSelect); - extStyleList.select (selectIndex); - extStyleList.setData (new Integer (selectIndex)); - centerListIndex (extStyleList, selectIndex); - initSizeList (); -} - -/** - * Initialize the face name list with all font names - * available in the selected character set. - * Downstream lists are initialized as well (extended style). - */ -void initFaceNameList () { - String oldSelect = getListSelection (faceNameList); - faceNameList.removeAll (); - String charSetText = getListSelection (charSetList); - if (charSetText.length () == 0) return; - - Hashtable faceNames = getFaces (charSetText); - setItemsSorted (faceNameList, faceNames); - - int selectIndex = faceNameList.indexOf (oldSelect); - selectIndex = Math.max (0, selectIndex); - faceNameList.select (selectIndex); - faceNameList.setData (new Integer (selectIndex)); - centerListIndex (faceNameList, selectIndex); - initExtStyleList (); -} - -/** - * Initialize the widgets of the receiver with the data of - * all installed fonts. If the user specified a default font - * preselect that font in the lists. - */ -void initFonts () { - Display display = shell.display; - // get all fonts available on the current display - addFonts (display.getFontList (null, false)); - addFonts (display.getFontList (null, true)); - setItemsSorted (charSetList, getFonts ()); - if (fontData != null) { - // verify that the initial font data is a valid font - Font font = new Font (display, fontData); - fontData = font.getFontData (); - currentFontData = fontData [0]; - font.dispose (); - } else { - fontData = display.textFont.getFontData (); - currentFontData = fontData [0]; - } -} - -/** - * Initialize the size list with the sizes the selected font - * is available in. If the selected font is scalable a selection - * of preset sizes is used. - */ -void initSizeList () { - String oldSelect = getListSelection (fontSizeList); - fontSizeList.removeAll (); - - String characterSet = getListSelection (charSetList); - String faceName = getListSelection (faceNameList); - String extStyle = getListSelection (extStyleList); - Hashtable sizes = getSizes (characterSet, faceName, extStyle); - if (sizes != null) { - if (sizes.get (SCALABLE_KEY) == null) { - /* - * Font is not scalable so just present the provided sizes. - */ - setSizeItemsSorted (sizes.keys ()); - } else { - /* - * Font is scalable so present the provided sizes and scalable - * sizes for selection. - */ - Vector allSizes = new Vector (); - /* - * Add the scalable sizes. - */ - for (int i = 0; i < SCALABLE_SIZES.length; i++) { - allSizes.addElement (Integer.valueOf (SCALABLE_SIZES [i])); - } - /* - * Add the provided sizes. - */ - Enumeration providedSizes = sizes.keys (); - while (providedSizes.hasMoreElements ()) { - Integer size = (Integer) providedSizes.nextElement (); - if (!size.equals (SCALABLE_KEY) && !allSizes.contains (size)) { - allSizes.addElement (size); - } - } - setSizeItemsSorted (allSizes.elements ()); - } - } - - int selectIndex = fontSizeList.indexOf (oldSelect); - if (selectIndex == -1) { - selectIndex = fontSizeList.indexOf (String.valueOf (DEFAULT_SIZE)); - } - selectIndex = Math.max (0, selectIndex); - fontSizeList.select (selectIndex); - fontSizeList.setData (new Integer (selectIndex)); - centerListIndex (fontSizeList, selectIndex); - initStyleList (); -} - -/** - * Initialize the styles list with the styles the selected font - * is available in. - */ -void initStyleList () { - String oldSelect = getListSelection (fontStyleList); - fontStyleList.removeAll (); - - String characterSet = getListSelection (charSetList); - String faceName = getListSelection (faceNameList); - String extStyle = getListSelection (extStyleList); - try { - int size = Integer.valueOf (getListSelection (fontSizeList)).intValue (); - if (size > 0) { - Hashtable styles = getStyles (characterSet, faceName, extStyle, size); - setItemsSorted (fontStyleList, styles); - } - } catch (NumberFormatException e) { - // fall through - } - - int selectIndex = fontStyleList.indexOf (oldSelect); - if (selectIndex == -1) { - selectIndex = fontStyleList.indexOf (String.valueOf (DEFAULT_STYLE)); - } - selectIndex = Math.max (0, selectIndex); - fontStyleList.select (selectIndex); - fontStyleList.setData (new Integer (selectIndex)); - centerListIndex (fontStyleList, selectIndex); -} - -/** - * Makes the dialog visible and brings it to the front - * of the display. - * - * @return a FontData object describing the font that was selected, - * or null if the dialog was cancelled or an error occurred - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li> - * </ul> - */ -public FontData open () { - shell = new Shell (getParent (), getStyle () | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL); - shell.setLayout (new GridLayout ()); - createControls (shell); - - FontData [] originalFontData = fontData; - RGB originalRGB = rgb; - initFonts (); - openDialog (); - setFontControls (currentFontData); - updateSampleFont (); - updateSampleColor (); - updateFontList (); - fontSetList.select (0); - fontSetList.setData (new Integer (0)); - updateButtonEnablements (); - hookListeners (); - Display display = shell.display; - while (!shell.isDisposed ()) { - if (!display.readAndDispatch ()) display.sleep (); - } - - FontData result = null; - if (okSelected) { - result = fontData [0]; - } else { - fontData = originalFontData; - rgb = originalRGB; - } - if (sampleFont != null) sampleFont.dispose (); - sampleFont = null; - if (sampleColor != null) sampleColor.dispose (); - sampleColor = null; - return result; -} - -/** - * Open the receiver and set its size to the size calculated by - * the layout manager. - */ -void openDialog () { - // Start everything off by setting the shell size to its computed size. - Point pt = shell.computeSize (SWT.DEFAULT, SWT.DEFAULT, false); - - // Ensure that the width of the shell fits the display. - Display display = shell.display; - Rectangle displayRect = display.getBounds (); - int widthLimit = displayRect.width * 7 / 8; - int heightLimit = displayRect.height * 7 / 8; - if (pt.x > widthLimit) { - pt = shell.computeSize (widthLimit, SWT.DEFAULT, false); - } - - /* - * If the parent is visible then center this dialog on it, - * otherwise center this dialog on the parent's monitor - */ - Rectangle parentBounds = null; - if (parent.isVisible ()) { - parentBounds = getParent ().getBounds (); - } else { - parentBounds = parent.getMonitor ().getBounds (); - } - int originX = (parentBounds.width - pt.x) / 2 + parentBounds.x; - originX = Math.max (originX, 0); - originX = Math.min (originX, widthLimit - pt.x); - int originY = (parentBounds.height - pt.y) / 2 + parentBounds.y; - originY = Math.max (originY, 0); - originY = Math.min (originY, heightLimit - pt.y); - shell.setBounds (originX, originY, pt.x, pt.y); - - String title = getText (); - if (title.length () == 0) title = SWT.getMessage ("SWT_FontDialog_Title"); - shell.setText (title); - - // Open the window. - shell.open (); -} - -/** - * Initialize the lists with the data of the preselected - * font specified by the user. - */ -void setFontControls (FontData fontData) { - ignoreEvents = true; - String characterSet = getTranslatedCharSet (fontData, true); - String faceName = getTranslatedFaceName (fontData); - charSetList.select (new String[] {characterSet}); - int index = charSetList.indexOf (characterSet); - charSetList.setData (new Integer (index)); - if (index != -1) centerListIndex (charSetList, index); - - initFaceNameList (); - faceNameList.select (new String[] {faceName}); - index = faceNameList.indexOf (faceName); - faceNameList.setData (new Integer (index)); - if (index != -1) centerListIndex (faceNameList, index); - - initExtStyleList (); - extStyleList.select (new String[] {fontData.addStyle}); - index = extStyleList.indexOf (fontData.addStyle); - extStyleList.setData (new Integer (index)); - if (index != -1) centerListIndex (extStyleList, index); - - initSizeList (); - String value = String.valueOf (fontData.getHeight ()); - fontSizeList.select (new String[] {value}); - index = fontSizeList.indexOf (value); - fontSizeList.setData (new Integer (index)); - if (index != -1) centerListIndex (fontSizeList, index); - - initStyleList (); - fontStyleList.select (new String[] {fontData.weight}); - index = fontStyleList.indexOf (fontData.weight); - fontStyleList.setData (new Integer (index)); - if (index != -1) centerListIndex (fontStyleList, index); - ignoreEvents = false; -} - -/** - * Sets a FontData object describing the font to be - * selected by default in the dialog, or null to let - * the platform choose one. - * - * @param fontData the FontData to use initially, or null - * @deprecated use #setFontList (FontData []) - */ -public void setFontData (FontData fontData) { - if (fontData == null) { - this.fontData = null; - } else { - this.fontData = new FontData [1]; - this.fontData [0] = fontData; - } -} - -/** - * Sets the set of FontData objects describing the font to - * be selected by default in the dialog, or null to let - * the platform choose one. - * - * @param fontData the set of FontData objects to use initially, or null - * to let the platform select a default when open() is called - * - * @see Font#getFontData - * - * @since 2.1.1 - */ -public void setFontList (FontData [] fontData) { - this.fontData = fontData; -} - -/** - * Set the contents of 'list' to the keys of 'items'. - * Keys are sorted in ascending order first and have to be Strings. - */ -void setItemsSorted (List list, Hashtable items) { - if (items == null) return; - Enumeration itemKeys = items.keys (); - String [] sortedItems = new String [items.size ()]; - int index = 0; - while (itemKeys.hasMoreElements ()) { - String item = (String) itemKeys.nextElement (); - if (item.length () != 0) sortedItems [index++] = item; - } - if (index != sortedItems.length) { - String [] newItems = new String [index]; - System.arraycopy (sortedItems, 0, newItems, 0, index); - sortedItems = newItems; - } - sort (sortedItems); - list.setItems (sortedItems); -} - -/** - * Sets the RGB describing the color to be selected by default - * in the dialog, or null to let the platform choose one. - * - * @param rgb the RGB value to use initially, or null to let - * the platform select a default when open() is called - * - * @see PaletteData#getRGBs - * - * @since 2.1 - */ -public void setRGB (RGB rgb) { - this.rgb = rgb; -} - -/** - * Set the contents of the size list to the keys of 'items'. - * Keys are sorted in ascending order first and have to be Integers. - */ -void setSizeItemsSorted (Enumeration itemsEnum) { - Vector items = new Vector (); - while (itemsEnum.hasMoreElements ()) { - items.addElement (itemsEnum.nextElement ()); - } - Integer [] sortedItems = new Integer [items.size ()]; - items.copyInto (sortedItems); - sort (sortedItems); - String [] sortedItemStrings = new String [items.size ()]; - for (int i = 0; i < sortedItemStrings.length; i++) { - sortedItemStrings [i] = String.valueOf (sortedItems [i].intValue ()); - } - fontSizeList.setItems (sortedItemStrings); -} - -/** - * Sort 'items' in ascending order. - */ -void sort (Integer [] items) { - /* Shell Sort from K&R, pg 108 */ - int length = items.length; - for (int gap = length / 2; gap > 0; gap /= 2) { - for (int i = gap; i < length; i++) { - for (int j = i - gap; j >= 0; j -= gap) { - if (items [j].intValue () > items [j + gap].intValue ()) { - Integer swap = items [j]; - items [j] = items [j + gap]; - items [j + gap] = swap; - } - } - } - } -} - -/** - * Sort 'items' in ascending order. - */ -void sort (String items []) { - /* Shell Sort from K&R, pg 108 */ - int length = items.length; - for (int gap = length / 2; gap > 0; gap /= 2) { - for (int i = gap; i < length; i++) { - for (int j = i - gap; j >= 0; j -= gap) { - if (items [j].compareTo (items [j + gap]) > 0) { - String swap = items [j]; - items [j] = items [j + gap]; - items [j + gap] = swap; - } - } - } - } -} - -void updateButtonEnablements () { - removeButton.setEnabled (fontSetList.getItemCount () > 1); - upButton.setEnabled (fontSetList.getSelectionIndex () > 0); - downButton.setEnabled (fontSetList.getSelectionIndex () < fontSetList.getItemCount () - 1); -} - -void updateFontList () { - int selectionIndex = fontSetList.getSelectionIndex (); - int topIndex = Math.max (0, fontSetList.getTopIndex ()); - String [] items = new String [fontData.length]; - for (int i = 0; i < fontData.length; i++) { - StringBuffer buffer = new StringBuffer (); - buffer.append (i); - buffer.append (": "); - buffer.append (getTranslatedCharSet (fontData [i], false)); - buffer.append ("-"); - buffer.append (getTranslatedFaceName (fontData [i])); - buffer.append ("-"); - if (!fontData [i].addStyle.equals ("")) { - buffer.append (fontData [i].addStyle); - buffer.append ("-"); - } - buffer.append (fontData [i].getHeight ()); - buffer.append ("-"); - buffer.append (fontData [i].weight); - items [i] = buffer.toString (); - } - fontSetList.setItems (items); - if (selectionIndex >= items.length) selectionIndex--; - fontSetList.select (selectionIndex); - fontSetList.setData (new Integer (selectionIndex)); - fontSetList.setTopIndex (topIndex); - fontSetList.showSelection (); -} - -void updateSampleColor () { - if (rgb == null) { - rgb = new RGB (0, 0, 0); - } - if (sampleColor != null) { - if (sampleColor.getRGB ().equals (rgb)) return; - sampleColor.dispose (); - } - sampleColor = new Color (parent.display, rgb); - sampleLabel.setForeground (sampleColor); -} - -/** - * Set the font of the sample text to the selected font. - * Display an error in place of the sample text if the selected - * font could not be loaded. - */ -void updateSampleFont () { - FontData selectionFontData = getSelectionFontData (); - /* - * sampleFont may not be the same as the one specified in selectionFontData. - * This happens when selectionFontData specifies a font alias. - */ - if (sampleFont != null) sampleFont.dispose (); - int selectionIndex = Math.max (0, fontSetList.getSelectionIndex ()); - fontData [selectionIndex] = selectionFontData; - sampleFont = new Font (shell.display, selectionFontData); - sampleLabel.setFont (sampleFont); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java deleted file mode 100755 index ce900951f8..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java +++ /dev/null @@ -1,348 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.*; - -/** - * Instances of this class provide an etched border - * with an optional title. - * <p> - * Shadow styles are hints and may not be honoured - * by the platform. To create a group with the - * default shadow style for the platform, do not - * specify a shadow style. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>SHADOW_ETCHED_IN, SHADOW_ETCHED_OUT, SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * Note: Only one of the above styles may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class Group extends Composite { - int labelHandle; - String text = ""; - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#SHADOW_ETCHED_IN - * @see SWT#SHADOW_ETCHED_OUT - * @see SWT#SHADOW_IN - * @see SWT#SHADOW_OUT - * @see SWT#SHADOW_NONE - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Group (Composite parent, int style) { - super (parent, checkStyle (style)); -} -static int checkStyle (int style) { - style |= SWT.NO_FOCUS; - /* - * Even though it is legal to create this widget - * with scroll bars, they serve no useful purpose - * because they do not automatically scroll the - * widget's client area. The fix is to clear - * the SWT style. - */ - return style & ~(SWT.H_SCROLL | SWT.V_SCROLL); -} -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - Point size = super.computeSize (wHint, hHint, changed); - if (OS.XtIsManaged (labelHandle)) { - int [] argList = { - OS.XmNshadowThickness, 0, - OS.XmNmarginWidth, 0, - }; - OS.XtGetValues (handle, argList, argList.length / 2); - int thickness = argList [1]; - int marginWidth = argList [3]; - int borderWidth = getBorderWidth (); - int [] argList2 = {OS.XmNchildHorizontalSpacing, 0}; - OS.XtGetValues (labelHandle, argList2, argList2.length / 2); - XtWidgetGeometry result = new XtWidgetGeometry (); - OS.XtQueryGeometry (labelHandle, null, result); - int titleWidth = result.width + 2 * (argList2 [1] + marginWidth + thickness + borderWidth); - size.x = Math.max (size.x, titleWidth); - } - return size; -} -public Rectangle computeTrim (int x, int y, int width, int height) { - checkWidget(); - int trimX, trimY, trimWidth, trimHeight; - int [] argList = { - OS.XmNshadowThickness, 0, - OS.XmNmarginWidth, 0, - OS.XmNmarginHeight, 0 - }; - OS.XtGetValues (handle, argList, argList.length / 2); - int thickness = argList [1]; - int marginWidth = argList [3]; - int marginHeight = argList [5]; - int borderWidth = getBorderWidth (); - trimX = x - marginWidth - thickness - borderWidth; - trimY = y - marginHeight - thickness - borderWidth; - trimWidth = width + ((marginWidth + thickness + borderWidth) * 2); - trimHeight = height + ((marginHeight + thickness + borderWidth) * 2); - if (OS.XtIsManaged (labelHandle)) { - int [] argList2 = {OS.XmNy, 0, OS.XmNheight, 0}; - OS.XtGetValues (labelHandle, argList2, argList2.length / 2); - int titleHeight = ((short) argList2 [1]) + argList2 [3]; - trimY = y - titleHeight; - trimHeight = height + titleHeight + (marginHeight + thickness + borderWidth); - } - return new Rectangle (trimX, trimY, trimWidth, trimHeight); -} -void createHandle (int index) { - state |= THEME_BACKGROUND; - /* - * Feature in Motif. When a widget is managed or unmanaged, - * it may request and be granted, a new size in the OS. This - * behavior is unwanted. The fix is to create a parent for - * the list that will disallow geometry requests. - */ - int border = (style & SWT.BORDER) != 0 ? 1 : 0; - int [] argList1 = { - OS.XmNancestorSensitive, 1, - OS.XmNborderWidth, border, - }; - int parentHandle = parent.handle; - formHandle = OS.XmCreateForm (parentHandle, null, argList1, argList1.length / 2); - if (formHandle == 0) error (SWT.ERROR_NO_HANDLES); - int [] argList2 = { - OS.XmNshadowType, shadowType (), - OS.XmNtopAttachment, OS.XmATTACH_FORM, - OS.XmNbottomAttachment, OS.XmATTACH_FORM, - OS.XmNleftAttachment, OS.XmATTACH_FORM, - OS.XmNrightAttachment, OS.XmATTACH_FORM, - OS.XmNresizable, 0, - }; - handle = OS.XmCreateFrame (formHandle, null, argList2, argList2.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - int [] argList3 = {OS.XmNframeChildType, OS.XmFRAME_TITLE_CHILD}; - labelHandle = OS.XmCreateLabel (handle, null, argList3, argList3.length / 2); - if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES); - int [] argList4 = {OS.XmNforeground, 0, OS.XmNbackground, 0}; - OS.XtGetValues (handle, argList4, argList4.length / 2); - OS.XtSetValues (labelHandle, argList4, argList4.length / 2); -} -void deregister () { - super.deregister (); - display.removeWidget (labelHandle); -} -void enableWidget (boolean enabled) { - super.enableWidget (enabled); - enableHandle (enabled, labelHandle); -} -int fontHandle () { - return labelHandle; -} -public Rectangle getClientArea () { - checkWidget(); - /* - * Bug in Motif. For some reason, if a form has not been realized, - * calling XtResizeWidget () on the form does not lay out properly. - * The fix is to force the widget to be realized by forcing the shell - * to be realized. - */ - if (!OS.XtIsRealized (handle)) getShell ().realizeWidget (); - int [] argList = { - OS.XmNwidth, 0, - OS.XmNheight, 0, - OS.XmNshadowThickness, 0, - OS.XmNmarginWidth, 0, - OS.XmNmarginHeight, 0 - }; - OS.XtGetValues (handle, argList, argList.length / 2); - int thickness = argList [5]; - int marginWidth = argList [7]; - int marginHeight = argList [9]; - int borderWidth = getBorderWidth (); - int x = marginWidth + thickness + borderWidth; - int y = marginHeight + thickness + borderWidth; - int width = argList [1] - ((marginWidth + thickness + borderWidth) * 2); - int height = argList [3] - ((marginHeight + thickness + borderWidth) * 2); - if (OS.XtIsManaged (labelHandle)) { - int [] argList2 = {OS.XmNy, 0, OS.XmNheight, 0}; - OS.XtGetValues (labelHandle, argList2, argList2.length / 2); - y = ((short) argList2 [1]) + argList2 [3]; - height = argList [3] - y - (marginHeight + thickness + borderWidth); - } - return new Rectangle (x, y, width, height); -} -/** - * Returns the receiver's text, which is the string that the - * is used as the <em>title</em>. If the text has not previously - * been set, returns an empty string. - * - * @return the text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getText () { - checkWidget(); - return text; -} -void hookEvents () { - super.hookEvents (); - int windowProc = display.windowProc; - OS.XtAddEventHandler (labelHandle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS); - OS.XtAddEventHandler (labelHandle, OS.ButtonReleaseMask, false, windowProc, BUTTON_RELEASE); - OS.XtAddEventHandler (labelHandle, OS.PointerMotionMask, false, windowProc, POINTER_MOTION); -} -boolean mnemonicHit (char key) { - return setFocus (); -} -boolean mnemonicMatch (char key) { - char mnemonic = findMnemonic (getText ()); - if (mnemonic == '\0') return false; - return Character.toUpperCase (key) == Character.toUpperCase (mnemonic); -} -void propagateWidget (boolean enabled) { - super.propagateWidget (enabled); - propagateHandle (enabled, labelHandle, OS.None); -} -void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean allChildren, boolean trim) { - super.redrawWidget (x, y, width, height, redrawAll, allChildren, trim); - short [] root_x = new short [1], root_y = new short [1]; - OS.XtTranslateCoords (handle, (short) x, (short) y, root_x, root_y); - short [] label_x = new short [1], label_y = new short [1]; - OS.XtTranslateCoords (labelHandle, (short) 0, (short) 0, label_x, label_y); - redrawHandle (root_x [0] - label_x [0], root_y [0] - label_y [0], width, height, redrawAll, labelHandle); -} -void register () { - super.register (); - display.addWidget (labelHandle, this); -} -void releaseHandle () { - super.releaseHandle (); - labelHandle = 0; -} -void setBackgroundPixel (int pixel) { - super.setBackgroundPixel (pixel); - int [] argList = {OS.XmNforeground, 0}; - OS.XtGetValues (labelHandle, argList, argList.length / 2); - OS.XmChangeColor (labelHandle, pixel); - OS.XtSetValues (labelHandle, argList, argList.length / 2); -} -void setForegroundPixel (int pixel) { - int [] argList = {OS.XmNforeground, pixel}; - OS.XtSetValues (labelHandle, argList, argList.length / 2); - super.setForegroundPixel (pixel); -} -void setParentBackground () { - super.setParentBackground (); - if (labelHandle != 0) setParentBackground (labelHandle); -} -/** - * Sets the receiver's text, which is the string that will - * be displayed as the receiver's <em>title</em>, to the argument, - * which may not be null. The string may include the mnemonic character. - * </p> - * Mnemonics are indicated by an '&' that causes the next - * character to be the mnemonic. When the user presses a - * key sequence that matches the mnemonic, focus is assigned - * to the first child of the group. On most platforms, the - * mnemonic appears underlined but may be emphasised in a - * platform specific manner. The mnemonic indicator character - * '&' can be escaped by doubling it in the string, causing - * a single '&' to be displayed. - * </p> - * @param string the new text - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the text is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - text = string; - char [] text = new char [string.length ()]; - string.getChars (0, text.length, text, 0); - int mnemonic = fixMnemonic (text); - byte [] buffer = Converter.wcsToMbcs (getCodePage (), text, true); - int xmString = OS.XmStringParseText ( - buffer, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - if (xmString == 0) error (SWT.ERROR_CANNOT_SET_TEXT); - if (mnemonic == 0) mnemonic = OS.XK_VoidSymbol; - int [] argList = { - OS.XmNlabelType, OS.XmSTRING, - OS.XmNlabelString, xmString, - OS.XmNmnemonic, mnemonic, - }; - OS.XtSetValues (labelHandle, argList, argList.length / 2); - if (xmString != 0) OS.XmStringFree (xmString); - if (string.length () == 0) { - OS.XtUnmanageChild (labelHandle); - } else { - OS.XtManageChild (labelHandle); - } -} -int shadowType () { - if ((style & SWT.SHADOW_IN) != 0) return OS.XmSHADOW_IN; - if ((style & SWT.SHADOW_OUT) != 0) return OS.XmSHADOW_OUT; - if ((style & SWT.SHADOW_ETCHED_IN) != 0) return OS.XmSHADOW_ETCHED_IN; - if ((style & SWT.SHADOW_ETCHED_OUT) != 0) return OS.XmSHADOW_ETCHED_OUT; - return OS.XmSHADOW_ETCHED_IN; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java deleted file mode 100755 index 1a53672046..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java +++ /dev/null @@ -1,643 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class represent a non-selectable - * user interface object that displays a string or image. - * When SEPARATOR is specified, displays a single - * vertical or horizontal line. - * <p> - * Shadow styles are hints and may not be honored - * by the platform. To create a separator label - * with the default shadow style for the platform, - * do not specify a shadow style. - * </p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>SEPARATOR, HORIZONTAL, VERTICAL</dd> - * <dd>SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd> - * <dd>CENTER, LEFT, RIGHT, WRAP</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * Note: Only one of SHADOW_IN, SHADOW_OUT and SHADOW_NONE may be specified. - * SHADOW_NONE is a HINT. Only one of HORIZONTAL and VERTICAL may be specified. - * Only one of CENTER, LEFT and RIGHT may be specified. - * </p><p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#label">Label snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class Label extends Control { - int formHandle; - String text = ""; - Image image, bitmap, disabled; - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#SEPARATOR - * @see SWT#HORIZONTAL - * @see SWT#VERTICAL - * @see SWT#SHADOW_IN - * @see SWT#SHADOW_OUT - * @see SWT#SHADOW_NONE - * @see SWT#CENTER - * @see SWT#LEFT - * @see SWT#RIGHT - * @see SWT#WRAP - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Label (Composite parent, int style) { - super (parent, checkStyle (style)); -} -static int checkStyle (int style) { - style |= SWT.NO_FOCUS; - if ((style & SWT.SEPARATOR) != 0) { - style = checkBits (style, SWT.VERTICAL, SWT.HORIZONTAL, 0, 0, 0, 0); - return checkBits (style, SWT.SHADOW_OUT, SWT.SHADOW_IN, SWT.SHADOW_NONE, 0, 0, 0); - } - return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0); -} -void _setText (String string) { - /* - * Bug in Motif. The widget will not receive mouse events, if the - * label string is empty. The fix is to detect that and set a single - * space instead. - */ - if (string.length () == 0) string = " "; - - /* Strip out mnemonic marker symbols, and remember the mnemonic. */ - char [] unicode = new char [string.length ()]; - string.getChars (0, unicode.length, unicode, 0); - int mnemonic = fixMnemonic (unicode); - - /* Wrap the text if necessary, and convert to mbcs. */ - byte [] buffer = null; - if ((style & SWT.WRAP) != 0) { - int [] argList = { - OS.XmNwidth, 0, /* 1 */ - OS.XmNmarginWidth, 0, /* 3 */ - }; - OS.XtGetValues (handle, argList, argList.length / 2); - int width = argList [1] - argList [3] * 2; - if (mnemonic != 0) string = new String (unicode); - string = display.wrapText (string, font, width); - buffer = Converter.wcsToMbcs (getCodePage (), string, true); - } else { - buffer = Converter.wcsToMbcs (getCodePage (), unicode, true); - } - - int xmString = OS.XmStringGenerate(buffer, null, OS.XmCHARSET_TEXT, null); - if (xmString == 0) error (SWT.ERROR_CANNOT_SET_TEXT); - - /* - * Bug in Solaris. If a mnemonic is defined to be a character - * that appears in a string in a position that follows a '\n', - * Solaris segment faults. For example, a label with text - * "Hello\nthe&re" would GP since "r" appears after '\n'. - * - * The fix is to remove mnemonics from labels that contain - * '\n', which is fine since such labels generally just act - * as descriptive texts anyways. - */ - if (mnemonic == 0 || string.indexOf ('\n') != -1) { - mnemonic = OS.XK_VoidSymbol; - } - int [] argList = { - OS.XmNlabelType, OS.XmSTRING, - OS.XmNlabelString, xmString, - OS.XmNmnemonic, mnemonic, - }; - OS.XtSetValues (handle, argList, argList.length / 2); - if (xmString != 0) OS.XmStringFree (xmString); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - int border = getBorderWidth (); - int width = border * 2, height = border * 2; - if ((style & SWT.SEPARATOR) != 0) { - if ((style & SWT.HORIZONTAL) != 0) { - width += DEFAULT_WIDTH; height += 3; - } else { - width += 3; height += DEFAULT_HEIGHT; - } - if (wHint != SWT.DEFAULT) width = wHint + border * 2; - if (hHint != SWT.DEFAULT) height = hHint + border * 2; - return new Point (width, height); - } - int [] argList1 = {OS.XmNlabelType, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int labelType = argList1 [1]; - if (labelType == OS.XmSTRING && (style & SWT.WRAP) != 0) { - /* If we are wrapping text, calculate the height based on wHint. */ - int [] argList2 = { - OS.XmNmarginTop, 0, /* 1 */ - OS.XmNmarginBottom, 0, /* 3 */ - OS.XmNmarginHeight, 0, /* 5 */ - OS.XmNmarginWidth, 0, /* 7 */ - OS.XmNmarginLeft, 0, /* 9 */ - OS.XmNmarginRight, 0, /* 11 */ - }; - OS.XtGetValues (handle, argList2, argList2.length / 2); - String string = text; - if (wHint != SWT.DEFAULT) { - string = display.wrapText (string, font, wHint - (argList2 [7] * 2) - argList2 [9] - argList2 [11]); - } - GC gc = new GC (this); - Point extent = gc.textExtent (string); - gc.dispose (); - height = extent.y + argList2 [1] + argList2 [3] + (argList2 [5] * 2) + (border * 2); - if (wHint == SWT.DEFAULT) { - width += extent.x + (argList2 [7] * 2) + argList2 [9] + argList2 [11]; - } - } else { - /* If we are not wrapping, ask the widget for its geometry. */ - XtWidgetGeometry result = new XtWidgetGeometry (); - result.request_mode = OS.CWWidth | OS.CWHeight; - OS.XtQueryGeometry (handle, null, result); - width += result.width; - height += result.height; - } - - /* - * Feature in Motif. If a label's labelType is XmSTRING but - * the label string is empty, recomputing the size will - * not take into account the height of the font, as we would - * like it to. Take care of this case. - * - * Note: When the label string is empty a single space is set - * into the widget. So the preferred height is computed properly. - * Just make sure the preferred width is zero. - */ - if (labelType == OS.XmSTRING && text.length () == 0) { - width = 0; - } - if (wHint != SWT.DEFAULT) { - int [] argList3 = { - OS.XmNmarginWidth, 0, /* 1 */ - OS.XmNmarginLeft, 0, /* 3 */ - OS.XmNmarginRight, 0, /* 5 */ - }; - OS.XtGetValues (handle, argList3, argList3.length / 2); - width = wHint + (border * 2) + (argList3 [1] * 2) + argList3 [3] + argList3 [5]; - } - if (hHint != SWT.DEFAULT) { - int [] argList4 = { - OS.XmNmarginHeight, 0, /* 1 */ - OS.XmNmarginTop, 0, /* 3 */ - OS.XmNmarginBottom, 0, /* 5 */ - }; - OS.XtGetValues (handle, argList4, argList4.length / 2); - height = hHint + (border * 2) + (argList4 [1] * 2) + argList4 [3] + argList4 [5]; - } - return new Point (width, height); -} -void createHandle (int index) { - state |= THEME_BACKGROUND; - int parentHandle = parent.handle; - int borderWidth = (style & SWT.BORDER) != 0 ? 1 : 0; - if ((style & SWT.SEPARATOR) != 0) { - int separatorType = separatorType (); - int orientation = (style & SWT.HORIZONTAL) != 0 ? OS.XmHORIZONTAL : OS.XmVERTICAL; - int [] argList = { - OS.XmNancestorSensitive, 1, - OS.XmNborderWidth, borderWidth, - OS.XmNorientation, orientation, - OS.XmNseparatorType, separatorType, - }; - handle = OS.XmCreateSeparator (parentHandle, null, argList, argList.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - return; - } - int [] argList1 = { - OS.XmNancestorSensitive, 1, - OS.XmNmarginWidth, 0, - OS.XmNmarginHeight, 0, - OS.XmNresizePolicy, OS.XmRESIZE_NONE, - OS.XmNborderWidth, borderWidth, - }; - formHandle = OS.XmCreateForm (parentHandle, null, argList1, argList1.length / 2); - if (formHandle == 0) error (SWT.ERROR_NO_HANDLES); - int alignment = OS.XmALIGNMENT_BEGINNING; - if ((style & SWT.CENTER) != 0) alignment = OS.XmALIGNMENT_CENTER; - if ((style & SWT.RIGHT) != 0) alignment = OS.XmALIGNMENT_END; - int [] argList2 = { - OS.XmNalignment, alignment, - OS.XmNtopAttachment, OS.XmATTACH_FORM, - OS.XmNleftAttachment, OS.XmATTACH_FORM, - OS.XmNrightAttachment, OS.XmATTACH_FORM, - }; - /* - * Bug in Motif. The widget will not receive mouse events, if the - * label string is empty. The fix is to initialize it to a space. - */ - byte [] buffer = {(byte) ' ', 0}; - handle = OS.XmCreateLabel (formHandle, buffer, argList2, argList2.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - int [] argList3 = {OS.XmNbackground, 0}; - OS.XtGetValues (handle, argList3, argList3.length / 2); - OS.XtSetValues (formHandle, argList3, argList3.length / 2); -} -int defaultBackground () { - return display.labelBackground; -} -Font defaultFont () { - return display.labelFont; -} -int defaultForeground () { - return display.labelForeground; -} -void deregister () { - super.deregister (); - if (formHandle != 0) display.removeWidget (formHandle); -} -void enableWidget (boolean enabled) { - super.enableWidget (enabled); - if (formHandle != 0) enableHandle (enabled, formHandle); -} -/** - * Returns a value which describes the position of the - * text or image in the receiver. The value will be one of - * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code> - * unless the receiver is a <code>SEPARATOR</code> label, in - * which case, <code>NONE</code> is returned. - * - * @return the alignment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getAlignment () { - checkWidget(); - if ((style & SWT.SEPARATOR) != 0) return SWT.LEFT; - int [] argList = {OS.XmNalignment, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int alignment = argList [1]; - if (alignment == OS.XmALIGNMENT_BEGINNING) return SWT.LEFT; - if (alignment == OS.XmALIGNMENT_CENTER) return SWT.CENTER; - if (alignment == OS.XmALIGNMENT_END)return SWT.RIGHT; - return SWT.LEFT; -} -/** - * Returns the receiver's image if it has one, or null - * if it does not. - * - * @return the receiver's image - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Image getImage () { - checkWidget(); - return image; -} -String getNameText () { - return getText (); -} -/** - * Returns the receiver's text, which will be an empty - * string if it has never been set or if the receiver is - * a <code>SEPARATOR</code> label. - * - * @return the receiver's text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getText () { - checkWidget(); - if ((style & SWT.SEPARATOR) != 0) return ""; - return text; -} -void hookEvents () { - super.hookEvents (); - if (formHandle != 0) { - int windowProc = display.windowProc; - OS.XtAddEventHandler (formHandle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS); - OS.XtAddEventHandler (formHandle, OS.ButtonReleaseMask, false, windowProc, BUTTON_RELEASE); - OS.XtAddEventHandler (formHandle, OS.PointerMotionMask, false, windowProc, POINTER_MOTION); - OS.XtAddEventHandler (formHandle, OS.EnterWindowMask, false, windowProc, ENTER_WINDOW); - OS.XtAddEventHandler (formHandle, OS.LeaveWindowMask, false, windowProc, LEAVE_WINDOW); - OS.XtInsertEventHandler (formHandle, OS.ExposureMask, false, windowProc, EXPOSURE, OS.XtListTail); - } -} -void manageChildren () { - if (formHandle != 0) { - OS.XtSetMappedWhenManaged (formHandle, false); - OS.XtManageChild (formHandle); - } - super.manageChildren (); - if (formHandle != 0) { - int [] argList = {OS.XmNborderWidth, 0}; - OS.XtGetValues (formHandle, argList, argList.length / 2); - OS.XtResizeWidget (formHandle, 1, 1, argList [1]); - OS.XtSetMappedWhenManaged (formHandle, true); - } -} -boolean mnemonicHit (char key) { - Composite control = this.parent; - while (control != null) { - Control [] children = control._getChildren (); - int index = 0; - while (index < children.length) { - if (children [index] == this) break; - index++; - } - index++; - if (index < children.length) { - if (children [index].setFocus ()) return true; - } - control = control.parent; - } - return false; -} -boolean mnemonicMatch (char key) { - char mnemonic = findMnemonic (getText ()); - if (mnemonic == '\0') return false; - return Character.toUpperCase (key) == Character.toUpperCase (mnemonic); -} -void propagateWidget (boolean enabled) { - super.propagateWidget (enabled); - if (formHandle != 0) propagateHandle (enabled, formHandle, OS.None); -} -void realizeChildren () { - super.realizeChildren (); - setBitGravity (); -} -void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean allChildren, boolean trim) { - super.redrawWidget (x, y, width, height, redrawAll, allChildren, trim); - if (formHandle != 0) { - short [] root_x = new short [1], root_y = new short [1]; - OS.XtTranslateCoords (handle, (short) x, (short) y, root_x, root_y); - short [] label_x = new short [1], label_y = new short [1]; - OS.XtTranslateCoords (formHandle, (short) 0, (short) 0, label_x, label_y); - redrawHandle (root_x [0] - label_x [0], root_y [0] - label_y [0], width, height, redrawAll, formHandle); - } -} -void register () { - super.register (); - if (formHandle != 0) display.addWidget (formHandle, this); -} -void releaseHandle () { - super.releaseHandle (); - formHandle = 0; -} -void releaseWidget () { - super.releaseWidget (); - int [] argList = { - OS.XmNlabelPixmap, OS.XmUNSPECIFIED_PIXMAP, - OS.XmNlabelInsensitivePixmap, OS.XmUNSPECIFIED_PIXMAP, - }; - OS.XtSetValues (handle, argList, argList.length / 2); - if (bitmap != null) bitmap.dispose (); - if (disabled != null) disabled.dispose (); - image = bitmap = disabled = null; -} -int separatorType () { - if ((style & (SWT.SHADOW_IN)) != 0) return OS.XmSHADOW_ETCHED_IN; - if ((style & (SWT.SHADOW_OUT)) != 0) return OS.XmSHADOW_ETCHED_OUT; - return OS.XmSINGLE_LINE; -} -/** - * Controls how text and images will be displayed in the receiver. - * The argument should be one of <code>LEFT</code>, <code>RIGHT</code> - * or <code>CENTER</code>. If the receiver is a <code>SEPARATOR</code> - * label, the argument is ignored and the alignment is not changed. - * - * @param alignment the new alignment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setAlignment (int alignment) { - checkWidget(); - if ((style & SWT.SEPARATOR) != 0) return; - int [] argList = {OS.XmNalignment, OS.XmALIGNMENT_BEGINNING}; - if ((alignment & SWT.CENTER) != 0) argList [1] = OS.XmALIGNMENT_CENTER; - if ((alignment & SWT.RIGHT) != 0) argList [1] = OS.XmALIGNMENT_END; - OS.XtSetValues (handle, argList, argList.length / 2); - setBitGravity (); -} -void setBackgroundPixel (int pixel) { - super.setBackgroundPixel (pixel); - if (formHandle != 0) { - int [] argList1 = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0}; - OS.XtGetValues (formHandle, argList1, argList1.length / 2); - OS.XmChangeColor (formHandle, pixel); - OS.XtSetValues (formHandle, argList1, argList1.length / 2); - } - int [] argList2 = {OS.XmNlabelType, 0}; - OS.XtGetValues (handle, argList2, argList2.length / 2); - if (argList2 [1] == OS.XmPIXMAP) setBitmap (image); -} -void setBitGravity () { - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int xWindow = OS.XtWindow (handle); - if (xWindow == 0) return; - int flags = OS.CWBitGravity; - XSetWindowAttributes attributes = new XSetWindowAttributes (); - attributes.bit_gravity = (style & SWT.LEFT) != 0 ? OS.NorthWestGravity : OS.ForgetGravity; - OS.XChangeWindowAttributes (xDisplay, xWindow, flags, attributes); -} -void setBitmap (Image image) { - int labelPixmap = OS.XmUNSPECIFIED_PIXMAP; - int labelInsensitivePixmap = OS.XmUNSPECIFIED_PIXMAP; - if (bitmap != null) bitmap.dispose (); - if (disabled != null) disabled.dispose (); - bitmap = disabled = null; - if (image != null) { - if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - switch (image.type) { - case SWT.BITMAP: - ImageData data; - if (image.mask == 0 && (data = image.getImageData ()).alpha == -1 && data.alphaData == null && data.transparentPixel == -1) { - labelPixmap = image.pixmap; - disabled = new Image (display, image, SWT.IMAGE_DISABLE); - labelInsensitivePixmap = disabled.pixmap; - break; - } - //FALL THROUGH - case SWT.ICON: - Rectangle rect = image.getBounds (); - bitmap = new Image (display, rect.width, rect.height); - GC gc = new GC (bitmap); - gc.setBackground (getBackground ()); - gc.fillRectangle (rect); - gc.drawImage (image, 0, 0); - gc.dispose (); - labelPixmap = bitmap.pixmap; - disabled = new Image (display, bitmap, SWT.IMAGE_DISABLE); - labelInsensitivePixmap = disabled.pixmap; - break; - default: - error (SWT.ERROR_NOT_IMPLEMENTED); - } - } - int [] argList = { - OS.XmNlabelType, image == null ? OS.XmSTRING : OS.XmPIXMAP, - OS.XmNlabelPixmap, labelPixmap, - OS.XmNlabelInsensitivePixmap, labelInsensitivePixmap, - }; - OS.XtSetValues (handle, argList, argList.length / 2); -} -boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - boolean changed = super.setBounds (x, y, width, height, move, resize); - if (changed && resize && (style & SWT.WRAP) != 0) { - int [] argList = {OS.XmNlabelType, 0,}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (argList [1] == OS.XmSTRING) _setText (text); - } - return changed; -} -public void setFont (Font font) { - checkWidget(); - - /* - * Bug in Motif. Setting the font in a label widget that does - * not have a non-empty string causes GP on UTF-8 locale. - * The fix is to set a non-empty string, change the font, - * and restore the empty string at the end. - */ - int [] argList1 = {OS.XmNlabelString, 0, OS.XmNlabelType, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - boolean fixString = OS.IsDBLocale && OS.XmStringEmpty (argList1 [1]); - if (fixString) { - byte[] buffer = Converter.wcsToMbcs (getCodePage (), "string", true); - int xmString = OS.XmStringCreateLocalized (buffer); - int [] argList2 = { - OS.XmNlabelType, OS.XmSTRING, - OS.XmNlabelString, xmString, - }; - OS.XtSetValues (handle, argList2, argList2.length / 2); - OS.XmStringFree (xmString); - } - super.setFont (font); - if (fixString) OS.XtSetValues (handle, argList1, argList1.length / 2); - if ((style & SWT.WRAP) != 0) { - int [] argList = {OS.XmNlabelType, 0,}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (argList [1] == OS.XmSTRING) _setText (text); - } -} -/** - * Sets the receiver's image to the argument, which may be - * null indicating that no image should be displayed. - * - * @param image the image to display on the receiver (may be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setImage (Image image) { - checkWidget(); - if ((style & SWT.SEPARATOR) != 0) return; - setBitmap (this.image = image); -} -void setParentBackground () { - super.setParentBackground (); - if (formHandle != 0) setParentBackground (formHandle); -} -/** - * Sets the receiver's text. - * <p> - * This method sets the widget label. The label may include - * the mnemonic character and line delimiters. - * </p> - * <p> - * Mnemonics are indicated by an '&' that causes the next - * character to be the mnemonic. When the user presses a - * key sequence that matches the mnemonic, focus is assigned - * to the control that follows the label. On most platforms, - * the mnemonic appears underlined but may be emphasised in a - * platform specific manner. The mnemonic indicator character - * '&' can be escaped by doubling it in the string, causing - * a single '&' to be displayed. - * </p> - * - * @param string the new text - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the text is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if ((style & SWT.SEPARATOR) != 0) return; - /* - * Feature in Motif. Motif does not optimize the case - * when the same text is set into a label causing - * it to flash. The fix is to test for equality and - * do nothing. - */ - if (text.equals (string)) return; - _setText (text = string); -} -int topHandle () { - if (formHandle != 0) return formHandle; - return handle; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Link.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Link.java deleted file mode 100644 index 8d82436f87..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Link.java +++ /dev/null @@ -1,660 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class represent a selectable - * user interface object that displays a text with - * links. - * <p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection</dd> - * </dl> - * <p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#link">Link snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 3.1 - * @noextend This class is not intended to be subclassed by clients. - */ -public class Link extends Control { - String text; - TextLayout layout; - Color linkColor, disabledColor; - Point [] offsets; - Point selection; - String [] ids; - int [] mnemonics; - int focusIndex; - - static final RGB LINK_FOREGROUND = new RGB (0, 51, 153); - static final RGB LINK_DISABLED_FOREGROUND = new RGB (172, 168, 153); - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Link (Composite parent, int style) { - super (parent, style); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the control is selected by the user, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * <code>widgetSelected</code> is called when the control is selected by the user. - * <code>widgetDefaultSelected</code> is not called. - * </p> - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener (SelectionListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Selection, typedListener); - addListener (SWT.DefaultSelection, typedListener); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; - if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; - int width, height; - int layoutWidth = layout.getWidth (); - //TEMPORARY CODE - if (wHint == 0) { - layout.setWidth (1); - Rectangle rect = layout.getBounds (); - width = 0; - height = rect.height; - } else { - layout.setWidth (wHint); - Rectangle rect = layout.getBounds (); - width = rect.width; - height = rect.height; - } - layout.setWidth (layoutWidth); - if (wHint != SWT.DEFAULT) width = wHint; - if (hHint != SWT.DEFAULT) height = hHint; - int border = getBorderWidth (); - width += border * 2; - height += border * 2; - return new Point (width, height); -} -void createHandle (int index) { - state |= THEME_BACKGROUND; - int [] argList = { - OS.XmNancestorSensitive, 1, - OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0, - OS.XmNmarginWidth, 0, - OS.XmNmarginHeight, 0, - OS.XmNresizePolicy, OS.XmRESIZE_NONE, - OS.XmNtraversalOn, 0, - }; - handle = OS.XmCreateDrawingArea (parent.handle, null, argList, argList.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - layout = new TextLayout (display); - linkColor = new Color (display, LINK_FOREGROUND); - disabledColor = new Color (display, LINK_DISABLED_FOREGROUND); - offsets = new Point [0]; - ids = new String [0]; - mnemonics = new int [0]; - selection = new Point (-1, -1); - focusIndex = -1; -} -void createWidget (int index) { - super.createWidget (index); - text = ""; - //TODO - accessibility -} -void enableWidget (boolean enabled) { - super.enableWidget (enabled); - TextStyle linkStyle = new TextStyle (null, enabled ? linkColor : disabledColor, null); - linkStyle.underline = true; - for (int i = 0; i < offsets.length; i++) { - Point point = offsets [i]; - layout.setStyle (linkStyle, point.x, point.y); - } - redraw (); -} -String getNameText () { - return getText (); -} -Rectangle [] getRectangles (int linkIndex) { - int lineCount = layout.getLineCount (); - Rectangle [] rects = new Rectangle [lineCount]; - int [] lineOffsets = layout.getLineOffsets (); - Point point = offsets [linkIndex]; - int lineStart = 1; - while (point.x > lineOffsets [lineStart]) lineStart++; - int lineEnd = 1; - while (point.y > lineOffsets [lineEnd]) lineEnd++; - int index = 0; - if (lineStart == lineEnd) { - rects [index++] = layout.getBounds (point.x, point.y); - } else { - rects [index++] = layout.getBounds (point.x, lineOffsets [lineStart]-1); - rects [index++] = layout.getBounds (lineOffsets [lineEnd-1], point.y); - if (lineEnd - lineStart > 1) { - for (int i = lineStart; i < lineEnd - 1; i++) { - rects [index++] = layout.getLineBounds (i); - } - } - } - if (rects.length != index) { - Rectangle [] tmp = new Rectangle [index]; - System.arraycopy (rects, 0, tmp, 0, index); - rects = tmp; - } - return rects; -} -/** - * Returns the receiver's text, which will be an empty - * string if it has never been set. - * - * @return the receiver's text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getText () { - checkWidget (); - return text; -} -void releaseWidget () { - super.releaseWidget (); - if (layout != null) layout.dispose (); - layout = null; - if (linkColor != null) linkColor.dispose (); - linkColor = null; - if (disabledColor != null) disabledColor.dispose (); - disabledColor = null; - offsets = null; - ids = null; - mnemonics = null; - text = null; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is selected by the user. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener (SelectionListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Selection, listener); - eventTable.unhook (SWT.DefaultSelection, listener); -} -String parse (String string) { - int length = string.length (); - offsets = new Point [length / 4]; - ids = new String [length / 4]; - mnemonics = new int [length / 4 + 1]; - StringBuffer result = new StringBuffer (); - char [] buffer = new char [length]; - string.getChars (0, string.length (), buffer, 0); - int index = 0, state = 0, linkIndex = 0; - int start = 0, tagStart = 0, linkStart = 0, endtagStart = 0, refStart = 0; - while (index < length) { - char c = Character.toLowerCase (buffer [index]); - switch (state) { - case 0: - if (c == '<') { - tagStart = index; - state++; - } - break; - case 1: - if (c == 'a') state++; - break; - case 2: - switch (c) { - case 'h': - state = 7; - break; - case '>': - linkStart = index + 1; - state++; - break; - default: - if (Character.isWhitespace(c)) break; - else state = 13; - } - break; - case 3: - if (c == '<') { - endtagStart = index; - state++; - } - break; - case 4: - state = c == '/' ? state + 1 : 3; - break; - case 5: - state = c == 'a' ? state + 1 : 3; - break; - case 6: - if (c == '>') { - mnemonics [linkIndex] = parseMnemonics (buffer, start, tagStart, result); - int offset = result.length (); - parseMnemonics (buffer, linkStart, endtagStart, result); - offsets [linkIndex] = new Point (offset, result.length () - 1); - if (ids [linkIndex] == null) { - ids [linkIndex] = new String (buffer, linkStart, endtagStart - linkStart); - } - linkIndex++; - start = tagStart = linkStart = endtagStart = refStart = index + 1; - state = 0; - } else { - state = 3; - } - break; - case 7: - state = c == 'r' ? state + 1 : 0; - break; - case 8: - state = c == 'e' ? state + 1 : 0; - break; - case 9: - state = c == 'f' ? state + 1 : 0; - break; - case 10: - state = c == '=' ? state + 1 : 0; - break; - case 11: - if (c == '"') { - state++; - refStart = index + 1; - } else { - state = 0; - } - break; - case 12: - if (c == '"') { - ids[linkIndex] = new String (buffer, refStart, index - refStart); - state = 2; - } - break; - case 13: - if (Character.isWhitespace (c)) { - state = 0; - } else if (c == '='){ - state++; - } - break; - case 14: - state = c == '"' ? state + 1 : 0; - break; - case 15: - if (c == '"') state = 2; - break; - default: - state = 0; - break; - } - index++; - } - if (start < length) { - int tmp = parseMnemonics (buffer, start, tagStart, result); - int mnemonic = parseMnemonics (buffer, Math.max (tagStart, linkStart), length, result); - if (mnemonic == -1) mnemonic = tmp; - mnemonics [linkIndex] = mnemonic; - } else { - mnemonics [linkIndex] = -1; - } - if (offsets.length != linkIndex) { - Point [] newOffsets = new Point [linkIndex]; - System.arraycopy (offsets, 0, newOffsets, 0, linkIndex); - offsets = newOffsets; - String [] newIDs = new String [linkIndex]; - System.arraycopy (ids, 0, newIDs, 0, linkIndex); - ids = newIDs; - int [] newMnemonics = new int [linkIndex + 1]; - System.arraycopy (mnemonics, 0, newMnemonics, 0, linkIndex + 1); - mnemonics = newMnemonics; - } - return result.toString (); -} -int parseMnemonics (char[] buffer, int start, int end, StringBuffer result) { - int mnemonic = -1, index = start; - while (index < end) { - if (buffer [index] == '&') { - if (index + 1 < end && buffer [index + 1] == '&') { - result.append (buffer [index]); - index++; - } else { - mnemonic = result.length(); - } - } else { - result.append (buffer [index]); - } - index++; - } - return mnemonic; -} -boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - boolean changed = super.setBounds (x, y, width,height, move, resize); - if (changed && resize) { - layout.setWidth (width > 0 ? width : -1); - redraw (); - } - return changed; -} -public void setFont (Font font) { - super.setFont (font); - layout.setFont (this.font); - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int xWindow = OS.XtWindow (handle); - if (xWindow == 0) return; - OS.XClearArea (xDisplay, xWindow, 0, 0, 0, 0, true); -} -void setForegroundPixel (int pixel) { - super.setForegroundPixel (pixel); - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int xWindow = OS.XtWindow (handle); - if (xWindow == 0) return; - OS.XClearArea (xDisplay, xWindow, 0, 0, 0, 0, true); -} -/** - * Sets the receiver's text. - * <p> - * The string can contain both regular text and hyperlinks. A hyperlink - * is delimited by an anchor tag, <A> and </A>. Within an - * anchor, a single HREF attribute is supported. When a hyperlink is - * selected, the text field of the selection event contains either the - * text of the hyperlink or the value of its HREF, if one was specified. - * In the rare case of identical hyperlinks within the same string, the - * HREF attribute can be used to distinguish between them. The string may - * include the mnemonic character and line delimiters. The only delimiter - * the HREF attribute supports is the quotation mark ("). - * </p> - * - * @param string the new text - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the text is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setText (String string) { - checkWidget (); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if (string.equals (text)) return; - text = string; - layout.setText (parse (string)); - focusIndex = offsets.length > 0 ? 0 : -1; - selection.x = selection.y = -1; - int [] argList = new int [] {OS.XmNtraversalOn, offsets.length > 0 ? 1 : 0}; - OS.XtSetValues (handle, argList, argList.length / 2); - int [] argList1 = {OS.XmNsensitive, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - boolean enabled = argList1 [1] != 0; - TextStyle linkStyle = new TextStyle (null, enabled ? linkColor : disabledColor, null); - linkStyle.underline = true; - for (int i = 0; i < offsets.length; i++) { - Point point = offsets [i]; - layout.setStyle (linkStyle, point.x, point.y); - } - TextStyle mnemonicStyle = new TextStyle (null, null, null); - mnemonicStyle.underline = true; - for (int i = 0; i < mnemonics.length; i++) { - int mnemonic = mnemonics [i]; - if (mnemonic != -1) { - layout.setStyle (mnemonicStyle, mnemonic, mnemonic); - } - } - redraw (); -} -int traversalCode (int key, XKeyEvent event) { - if (offsets.length == 0) return 0; - int bits = super.traversalCode (key, event); - if (event != null && key == OS.XK_Tab) { - boolean next = (event.state & OS.ShiftMask) == 0; - if (next && focusIndex < offsets.length - 1) { - return bits & ~SWT.TRAVERSE_TAB_NEXT; - } - if (!next && focusIndex > 0) { - return bits & ~SWT.TRAVERSE_TAB_PREVIOUS; - } - } - return bits; -} -int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XButtonPress (w, client_data, call_data, continue_to_dispatch); - if (result != 0) return result; - XButtonEvent xEvent = new XButtonEvent (); - OS.memmove (xEvent, call_data, XButtonEvent.sizeof); - if (xEvent.button == 1) { - int offset = layout.getOffset (xEvent.x, xEvent.y, null); - int oldSelectionX = selection.x; - int oldSelectionY = selection.y; - selection.x = offset; - selection.y = -1; - if (oldSelectionX != -1 && oldSelectionY != -1) { - if (oldSelectionX > oldSelectionY) { - int temp = oldSelectionX; - oldSelectionX = oldSelectionY; - oldSelectionY = temp; - } - Rectangle rect = layout.getBounds (oldSelectionX, oldSelectionY); - redraw (rect.x, rect.y, rect.width, rect.height, false); - } - for (int j = 0; j < offsets.length; j++) { - Rectangle [] rects = getRectangles (j); - for (int i = 0; i < rects.length; i++) { - Rectangle rect = rects [i]; - if (rect.contains (xEvent.x, xEvent.y)) { - focusIndex = j; - redraw (); - return result; - } - } - } - } - return result; -} -int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XButtonRelease (w, client_data, call_data, continue_to_dispatch); - if (result != 0) return result; - if (focusIndex == -1) return result; - XButtonEvent xEvent = new XButtonEvent (); - OS.memmove (xEvent, call_data, XButtonEvent.sizeof); - if (xEvent.button == 1) { - Rectangle [] rects = getRectangles (focusIndex); - for (int i = 0; i < rects.length; i++) { - Rectangle rect = rects [i]; - if (rect.contains (xEvent.x, xEvent.y)) { - Event event = new Event (); - event.text = ids [focusIndex]; - notifyListeners (SWT.Selection, event); - return result; - } - } - } - return result; -} -int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) { - XExposeEvent xEvent = new XExposeEvent (); - OS.memmove (xEvent, call_data, XExposeEvent.sizeof); - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return 0; - int damageRgn = OS.XCreateRegion (); - OS.XtAddExposureToRegion (call_data, damageRgn); - GCData data = new GCData (); - data.damageRgn = damageRgn; - GC gc = GC.motif_new (this, data); - OS.XSetRegion (xDisplay, gc.handle, damageRgn); - int selStart = selection.x; - int selEnd = selection.y; - if (selStart > selEnd) { - selStart = selection.y; - selEnd = selection.x; - } - // temporary code to disable text selection - selStart = selEnd = -1; - int [] argList = {OS.XmNsensitive, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (argList [1] == 0) gc.setForeground (disabledColor); - layout.draw (gc, 0, 0, selStart, selEnd, null, null); - if (hasFocus () && focusIndex != -1) { - Rectangle [] rects = getRectangles (focusIndex); - for (int i = 0; i < rects.length; i++) { - Rectangle rect = rects [i]; - gc.drawFocus (rect.x, rect.y, rect.width, rect.height); - } - } - gc.dispose (); - OS.XDestroyRegion (damageRgn); - return super.XExposure (w, client_data, call_data, continue_to_dispatch); -} -int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XFocusChange (w, client_data, call_data, continue_to_dispatch); - redraw (); - return result; -} -int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XKeyPress (w, client_data, call_data, continue_to_dispatch); - if (result != 0) return result; - if (focusIndex == -1) return result; - XKeyEvent xEvent = new XKeyEvent (); - OS.memmove (xEvent, call_data, XKeyEvent.sizeof); - int [] keysym = new int [1]; - OS.XLookupString (xEvent, null, 0, keysym, null); - keysym [0] &= 0xFFFF; - switch (keysym [0]) { - case OS.XK_space: - case OS.XK_Return: - case OS.XK_KP_Enter: - Event event = new Event (); - event.text = ids [focusIndex]; - sendEvent (SWT.Selection, event); - break; - case OS.XK_Tab: - if (focusIndex < offsets.length - 1) { - focusIndex++; - redraw (); - OS.memmove (continue_to_dispatch, new int [1], 4); - return 1; - } - break; - case OS.XK_ISO_Left_Tab: - if (focusIndex > 0) { - focusIndex--; - redraw (); - OS.memmove (continue_to_dispatch, new int [1], 4); - return 1; - } - break; - } - return result; -} -int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XPointerMotion (w, client_data, call_data, continue_to_dispatch); - if (result != 0) return result; - XMotionEvent xEvent = new XMotionEvent (); - OS.memmove (xEvent, call_data, XMotionEvent.sizeof); - if ((xEvent.state & OS.Button1Mask) != 0) { - int oldSelection = selection.y; - selection.y = layout.getOffset (xEvent.x, xEvent.y, null); - if (selection.y != oldSelection) { - int newSelection = selection.y; - if (oldSelection > newSelection) { - int temp = oldSelection; - oldSelection = newSelection; - newSelection = temp; - } - Rectangle rect = layout.getBounds (oldSelection, newSelection); - redraw (rect.x, rect.y, rect.width, rect.height, false); - } - return result; - } - for (int j = 0; j < offsets.length; j++) { - Rectangle [] rects = getRectangles (j); - for (int i = 0; i < rects.length; i++) { - Rectangle rect = rects [i]; - if (rect.contains (xEvent.x, xEvent.y)) { - setCursor (display.getSystemCursor (SWT.CURSOR_HAND)); - return result; - } - } - } - setCursor (null); - return result; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java deleted file mode 100755 index 16b42b1466..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java +++ /dev/null @@ -1,1567 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - - -/** - * Instances of this class represent a selectable user interface - * object that displays a list of strings and issues notification - * when a string is selected. A list may be single or multi select. - * <p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>SINGLE, MULTI</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection, DefaultSelection</dd> - * </dl> - * <p> - * Note: Only one of SINGLE and MULTI may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#list">List snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class List extends Scrollable { -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#SINGLE - * @see SWT#MULTI - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public List (Composite parent, int style) { - /* - * Feature in Motif. It is not possible to create - * scrolled list that will never show the vertical - * scroll bar. Therefore, not matter what style - * bits are specified, set the V_SCROLL bits to - * match the widget Motif creates. - */ - super (parent, checkStyle (style | SWT.V_SCROLL)); -} -/** - * Adds the argument to the end of the receiver's list. - * - * @param string the new item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #add(String,int) - */ -public void add (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); - int xmString = OS.XmStringCreateLocalized (buffer); - if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED); - OS.XmListAddItemUnselected (handle, xmString, 0); - OS.XmStringFree (xmString); -} -/** - * Adds the argument to the receiver's list at the given - * zero-relative index. - * <p> - * Note: To add an item at the end of the list, use the - * result of calling <code>getItemCount()</code> as the - * index or use <code>add(String)</code>. - * </p> - * - * @param string the new item - * @param index the index for the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #add(String) - */ -public void add (String string, int index) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if (index == -1) error (SWT.ERROR_INVALID_RANGE); - /* - * Feature in Motif. When an index is out of range, - * the list widget adds the item at the end. This - * behavior is not wrong but it is unwanted. The - * fix is to check the range before adding the item. - */ - int [] argList = {OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (!(0 <= index && index <= argList [1])) { - error (SWT.ERROR_INVALID_RANGE); - } - byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); - int xmString = OS.XmStringCreateLocalized (buffer); - if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED); - OS.XmListAddItemUnselected (handle, xmString, index + 1); - OS.XmStringFree (xmString); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the user changes the receiver's selection, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * <code>widgetSelected</code> is called when the selection changes. - * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked. - * </p> - * - * @param listener the listener which should be notified when the user changes the receiver's selection - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener(listener); - addListener(SWT.Selection,typedListener); - addListener(SWT.DefaultSelection,typedListener); -} -static int checkStyle (int style) { - return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - XtWidgetGeometry result = new XtWidgetGeometry (); - result.request_mode = OS.CWWidth; - OS.XtQueryGeometry (handle, null, result); - int width = result.width, height = 0; - if (wHint != SWT.DEFAULT) width = wHint; - if (hHint != SWT.DEFAULT) height = hHint; - if (hHint == SWT.DEFAULT || wHint == SWT.DEFAULT) { - int [] argList = {OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int count = argList [1]; - if (hHint == SWT.DEFAULT) { - if (count == 0) { - height = DEFAULT_HEIGHT; - } else { - height = getItemHeight () * count; - } - } - if (wHint == SWT.DEFAULT && count == 0) { - width = DEFAULT_WIDTH; - } - } - Rectangle rect = computeTrim (0, 0, width, height); - return new Point (rect.width, rect.height); -} -public Rectangle computeTrim (int x, int y, int width, int height) { - checkWidget(); - int border = getBorderWidth (); - int trimX = x - border; - int trimY = y - border; - int trimWidth = width + (border * 2); - int trimHeight = height + (border * 2); - if (horizontalBar != null) { - int [] argList = {OS.XmNheight, 0}; - OS.XtGetValues (horizontalBar.handle, argList, argList.length / 2); - /* - * Motif adds four pixels between the bottom of the - * list and the horizontal scroll bar. Add those now. - */ - trimHeight += argList [1] + 4; - trimY -= display.scrolledInsetY; - if (verticalBar != null) { - trimX -= display.scrolledInsetX; - } - } - if (verticalBar != null) { - int [] argList = {OS.XmNwidth, 0}; - OS.XtGetValues (verticalBar.handle, argList, argList.length / 2); - trimWidth += argList [1]; - trimX -= display.scrolledInsetX; - if (horizontalBar != null) { - trimY -= display.scrolledInsetY; - } - } - int [] argList = { - OS.XmNhighlightThickness, 0, /* 1 */ - OS.XmNshadowThickness, 0, /* 3 */ - OS.XmNlistMarginWidth, 0, /* 5 */ - OS.XmNlistMarginHeight, 0 /* 7 */ - }; - OS.XtGetValues (handle, argList, argList.length / 2); - int thickness = argList [1] + (argList [3] * 2); - trimWidth += thickness + argList [5] + 1; - trimHeight += thickness + argList [7] + 1; - trimX -= argList [1] + argList [3] + argList [5]; - trimY -= argList [1] + argList [3] + argList [7]; - return new Rectangle (trimX, trimY, trimWidth, trimHeight); -} -void createHandle (int index) { - /* - * Feature in Motif. When items are added or removed - * from a list, it may request and be granted, a new - * preferred size. This behavior is unwanted. The fix - * is to create a parent for the list that will disallow - * geometry requests. - */ - int parentHandle = parent.handle; - int [] argList1 = {OS.XmNancestorSensitive, 1}; - formHandle = OS.XmCreateForm (parentHandle, null, argList1, argList1.length / 2); - if (formHandle == 0) error (SWT.ERROR_NO_HANDLES); - int selectionPolicy = OS.XmBROWSE_SELECT, listSizePolicy = OS.XmCONSTANT; - if ((style & SWT.MULTI) != 0) { - selectionPolicy = OS.XmEXTENDED_SELECT; - if ((style & SWT.SIMPLE) != 0) selectionPolicy = OS.XmMULTIPLE_SELECT; - } - if ((style & SWT.H_SCROLL) == 0) listSizePolicy = OS.XmVARIABLE; - int [] argList2 = { - OS.XmNlistSizePolicy, listSizePolicy, - OS.XmNselectionPolicy, selectionPolicy, - OS.XmNtopAttachment, OS.XmATTACH_FORM, - OS.XmNbottomAttachment, OS.XmATTACH_FORM, - OS.XmNleftAttachment, OS.XmATTACH_FORM, - OS.XmNrightAttachment, OS.XmATTACH_FORM, - OS.XmNresizable, 0, -// OS.XmNmatchBehavior, OS.XmNONE, - }; - if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) { - handle = OS.XmCreateList (formHandle, null, argList2, argList2.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - } else { - handle = OS.XmCreateScrolledList (formHandle, new byte [1], argList2, argList2.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - scrolledHandle = OS.XtParent (handle); - } - if ((style & SWT.BORDER) == 0) { - int [] argList3 = new int [] {OS.XmNshadowThickness, 0}; - OS.XtSetValues (handle, argList3, argList3.length / 2); - } -} -ScrollBar createScrollBar (int type) { - return createStandardBar (type); -} -int defaultBackground () { - return display.listBackground; -} -Font defaultFont () { - return display.listFont; -} -int defaultForeground () { - return display.listForeground; -} -/** - * Deselects the item at the given zero-relative index in the receiver. - * If the item at the index was already deselected, it remains - * deselected. Indices that are out of range are ignored. - * - * @param index the index of the item to deselect - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void deselect (int index) { - checkWidget(); - /* - * Note: We rely on the fact that XmListDeselectPos () - * fails silently when the indices are out of range. - */ - if (index != -1) OS.XmListDeselectPos (handle, index + 1); -} -/** - * Deselects the items at the given zero-relative indices in the receiver. - * If the item at the given zero-relative index in the receiver - * is selected, it is deselected. If the item at the index - * was not selected, it remains deselected. The range of the - * indices is inclusive. Indices that are out of range are ignored. - * - * @param start the start index of the items to deselect - * @param end the end index of the items to deselect - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void deselect (int start, int end) { - checkWidget(); - if (start > end) return; - /* - * Note: We rely on the fact that XmListDeselectPos () - * fails silently when the indices are out of range. - */ - for (int i=start; i<=end; i++) { - int index = i + 1; - if (index != 0) OS.XmListDeselectPos (handle, index); - } -} -/** - * Deselects the items at the given zero-relative indices in the receiver. - * If the item at the given zero-relative index in the receiver - * is selected, it is deselected. If the item at the index - * was not selected, it remains deselected. Indices that are out - * of range and duplicate indices are ignored. - * - * @param indices the array of indices for the items to deselect - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the set of indices is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void deselect (int [] indices) { - checkWidget(); - if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); - /* - * Note: We rely on the fact that XmListDeselectPos () - * fails silently when the indices are out of range. - */ - for (int i=0; i<indices.length; i++) { - int index = indices [i] + 1; - if (index != 0) OS.XmListDeselectPos (handle, index); - } -} -/** - * Deselects all selected items in the receiver. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void deselectAll () { - checkWidget(); - OS.XmListDeselectAllItems (handle); -} -/** - * Returns the zero-relative index of the item which currently - * has the focus in the receiver, or -1 if no item has focus. - * - * @return the index of the selected item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getFocusIndex () { - checkWidget(); - return OS.XmListGetKbdItemPos (handle) - 1; -} -/** - * Returns the item at the given, zero-relative index in the - * receiver. Throws an exception if the index is out of range. - * - * @param index the index of the item to return - * @return the item at the given index - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getItem (int index) { - checkWidget(); - int [] argList = {OS.XmNitemCount, 0, OS.XmNitems, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (!(0 <= index && index < argList [1])) { - error (SWT.ERROR_INVALID_RANGE); - } - if (argList [3] == 0) error (SWT.ERROR_CANNOT_GET_ITEM); - int ptr = argList [3] + (index * 4); - int [] buffer1 = new int [1]; - OS.memmove (buffer1, ptr, 4); - ptr = buffer1 [0]; - int [] table = new int [] {display.tabMapping, display.crMapping}; - int address = OS.XmStringUnparse ( - ptr, - null, - OS.XmCHARSET_TEXT, - OS.XmCHARSET_TEXT, - table, - table.length, - OS.XmOUTPUT_ALL); - if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM); - int length = OS.strlen (address); - byte [] buffer = new byte [length]; - OS.memmove (buffer, address, length); - OS.XtFree (address); - return new String (Converter.mbcsToWcs (getCodePage (), buffer)); -} -/** - * Returns the number of items contained in the receiver. - * - * @return the number of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getItemCount () { - checkWidget(); - int [] argList = {OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the height of the area which would be used to - * display <em>one</em> of the items in the list. - * - * @return the height of one item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getItemHeight () { - checkWidget(); - int [] argList = { - OS.XmNlistSpacing, 0, - OS.XmNhighlightThickness, 0, - }; - OS.XtGetValues (handle, argList, argList.length / 2); - int spacing = argList [1], highlight = argList [3]; - - /* Result is from empirical analysis on Linux and AIX */ - return getFontHeight (font.handle) + spacing + highlight + 1; -} -/** - * Returns a (possibly empty) array of <code>String</code>s which - * are the items in the receiver. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its list of items, so modifying the array will - * not affect the receiver. - * </p> - * - * @return the items in the receiver's list - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String [] getItems () { - checkWidget(); - int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int items = argList [1], itemCount = argList [3]; - int [] buffer1 = new int [1]; - String [] result = new String [itemCount]; - String codePage = getCodePage (); - for (int i=0; i<itemCount; i++) { - OS.memmove (buffer1, items, 4); - int ptr = buffer1 [0]; - int [] table = new int [] {display.tabMapping, display.crMapping}; - int address = OS.XmStringUnparse ( - ptr, - null, - OS.XmCHARSET_TEXT, - OS.XmCHARSET_TEXT, - table, - table.length, - OS.XmOUTPUT_ALL); - if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM); - int length = OS.strlen (address); - byte [] buffer = new byte [length]; - OS.memmove (buffer, address, length); - OS.XtFree (address); - result[i] = new String (Converter.mbcsToWcs (codePage, buffer)); - items += 4; - } - return result; -} -/** - * Returns an array of <code>String</code>s that are currently - * selected in the receiver. The order of the items is unspecified. - * An empty array indicates that no items are selected. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its selection, so modifying the array will - * not affect the receiver. - * </p> - * @return an array representing the selection - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String [] getSelection () { - checkWidget(); - int [] argList = {OS.XmNselectedItems, 0, OS.XmNselectedItemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int items = argList [1], itemCount = argList [3]; - int [] buffer1 = new int [1]; - String [] result = new String [itemCount]; - String codePage = getCodePage (); - for (int i=0; i<itemCount; i++) { - OS.memmove (buffer1, items, 4); - int ptr = buffer1 [0]; - int[] table = new int[] {display.tabMapping, display.crMapping}; - int address = OS.XmStringUnparse ( - ptr, - null, - OS.XmCHARSET_TEXT, - OS.XmCHARSET_TEXT, - table, - table.length, - OS.XmOUTPUT_ALL); - if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM); - int length = OS.strlen (address); - byte [] buffer = new byte [length]; - OS.memmove (buffer, address, length); - OS.XtFree (address); - result[i] = new String (Converter.mbcsToWcs (codePage, buffer)); - items += 4; - } - return result; -} -/** - * Returns the number of selected items contained in the receiver. - * - * @return the number of selected items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getSelectionCount () { - checkWidget(); - int [] argList = {OS.XmNselectedItemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the zero-relative index of the item which is currently - * selected in the receiver, or -1 if no item is selected. - * - * @return the index of the selected item or -1 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getSelectionIndex () { - checkWidget(); - int index = OS.XmListGetKbdItemPos (handle); - if (OS.XmListPosSelected (handle, index)) return index - 1; - int [] count = new int [1], positions = new int [1]; - if (!OS.XmListGetSelectedPos (handle, positions, count)) return -1; - if (count [0] == 0) return -1; - int address = positions [0]; - int [] indices = new int [1]; - OS.memmove (indices, address, 4); - OS.XtFree (address); - return indices [0] - 1; -} -/** - * Returns the zero-relative indices of the items which are currently - * selected in the receiver. The order of the indices is unspecified. - * The array is empty if no items are selected. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its selection, so modifying the array will - * not affect the receiver. - * </p> - * @return the array of indices of the selected items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int [] getSelectionIndices () { - checkWidget(); - int [] count = new int [1], positions = new int [1]; - OS.XmListGetSelectedPos (handle, positions, count); - int [] result = new int [count [0]]; - OS.memmove (result, positions [0], count [0] * 4); - if (positions [0] != 0) OS.XtFree (positions [0]); - for (int i=0; i<result.length; i++) --result [i]; - return result; -} -/** - * Returns the zero-relative index of the item which is currently - * at the top of the receiver. This index can change when items are - * scrolled or new items are added or removed. - * - * @return the index of the top item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getTopIndex () { - checkWidget(); - int [] argList = {OS.XmNtopItemPosition, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1] - 1; -} -void hookEvents () { - super.hookEvents (); - int windowProc = display.windowProc; - OS.XtAddCallback (handle, OS.XmNbrowseSelectionCallback, windowProc, BROWSE_SELECTION_CALLBACK); - OS.XtAddCallback (handle, OS.XmNextendedSelectionCallback, windowProc, EXTENDED_SELECTION_CALLBACK); - OS.XtAddCallback (handle, OS.XmNmultipleSelectionCallback, windowProc, MULTIPLE_SELECTION_CALLBACK); - OS.XtAddCallback (handle, OS.XmNdefaultActionCallback, windowProc, DEFAULT_ACTION_CALLBACK); -} -/** - * Gets the index of an item. - * <p> - * The list is searched starting at 0 until an - * item is found that is equal to the search item. - * If no item is found, -1 is returned. Indexing - * is zero based. - * - * @param string the search item - * @return the index of the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int indexOf (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); - int xmString = OS.XmStringCreateLocalized (buffer); - if (xmString == 0) return -1; - int index = OS.XmListItemPos (handle, xmString); - OS.XmStringFree (xmString); - return index - 1; -} -/** - * Searches the receiver's list starting at the given, - * zero-relative index until an item is found that is equal - * to the argument, and returns the index of that item. If - * no item is found or the starting index is out of range, - * returns -1. - * - * @param string the search item - * @param start the zero-relative index at which to start the search - * @return the index of the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int indexOf (String string, int start) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int items = argList [1], itemCount = argList [3]; - if (!((0 <= start) && (start < itemCount))) return -1; - byte [] buffer1 = Converter.wcsToMbcs (getCodePage (), string, true); - int xmString = OS.XmStringCreateLocalized (buffer1); - if (xmString == 0) return -1; - int index = start; - items += start * 4; - int [] buffer2 = new int [1]; - while (index < itemCount) { - OS.memmove (buffer2, items, 4); - if (OS.XmStringCompare (buffer2 [0], xmString)) break; - items += 4; index++; - } - OS.XmStringFree (xmString); - if (index == itemCount) return -1; - return index; -} -/** - * Returns <code>true</code> if the item is selected, - * and <code>false</code> otherwise. Indices out of - * range are ignored. - * - * @param index the index of the item - * @return the selection state of the item at the index - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean isSelected (int index) { - checkWidget(); - if (index == -1) return false; - return OS.XmListPosSelected (handle, index + 1); -} -void overrideTranslations () { - OS.XtOverrideTranslations (handle, display.tabTranslations); -} -/** - * Removes the item from the receiver at the given - * zero-relative index. - * - * @param index the index for the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void remove (int index) { - checkWidget(); - if (index == -1) error (SWT.ERROR_INVALID_RANGE); - /* - * Feature in Motif. An index out of range handled - * correctly by the list widget but causes an unwanted - * Xm Warning. The fix is to check the range before - * deleting an item. - */ - int [] argList = {OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (!(0 <= index && index < argList [1])) { - error (SWT.ERROR_INVALID_RANGE); - } - OS.XmListDeletePos (handle, index + 1); -} -/** - * Removes the items from the receiver which are - * between the given zero-relative start and end - * indices (inclusive). - * - * @param start the start of the range - * @param end the end of the range - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void remove (int start, int end) { - checkWidget(); - if (start > end) return; - int [] argList = {OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (!(0 <= start && start <= end && end < argList [1])) { - error (SWT.ERROR_INVALID_RANGE); - } - int count = end - start + 1; - OS.XmListDeleteItemsPos (handle, count, start + 1); -} -/** - * Searches the receiver's list starting at the first item - * until an item is found that is equal to the argument, - * and removes that item from the list. - * - * @param string the item to remove - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the string is not found in the list</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void remove (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); - int xmString = OS.XmStringCreateLocalized (buffer); - if (xmString == 0) error (SWT.ERROR_ITEM_NOT_REMOVED); - int index = OS.XmListItemPos (handle, xmString); - OS.XmStringFree (xmString); - if (index == 0) error (SWT.ERROR_INVALID_ARGUMENT); - OS.XmListDeletePos (handle, index); -} -/** - * Removes the items from the receiver at the given - * zero-relative indices. - * - * @param indices the array of indices of the items - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * <li>ERROR_NULL_ARGUMENT - if the indices array is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void remove (int [] indices) { - checkWidget(); - if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); - if (indices.length == 0) return; - int [] argList = {OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int [] newIndices = new int [indices.length]; - for (int i=0; i<indices.length; i++) { - if (!(0 <= indices [i] && indices [i] < argList [1])) { - error (SWT.ERROR_INVALID_RANGE); - } - newIndices [i] = indices [i] + 1; - } - OS.XmListDeletePositions (handle, newIndices, newIndices.length); -} -/** - * Removes all of the items from the receiver. - * <p> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void removeAll () { - checkWidget(); - OS.XmListDeselectAllItems (handle); - OS.XmListDeleteAllItems (handle); - /* - * Bug in AIX. When all list items are deleted - * from a scrolled list that is currently showing a - * horizontal scroll bar, the horizontal scroll bar - * is hidden, but the list does not grow to take up - * the space once occupied by the bar. The fix is - * of force a resize of the list. - */ - if ((style & SWT.H_SCROLL) != 0) OS.XtResizeWindow (handle); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the user changes the receiver's selection. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.Selection, listener); - eventTable.unhook(SWT.DefaultSelection,listener); -} -/** - * Selects the item at the given zero-relative index in the receiver's - * list. If the item at the index was already selected, it remains - * selected. Indices that are out of range are ignored. - * - * @param index the index of the item to select - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void select (int index) { - checkWidget(); - if (index == -1) return; - if (OS.XmListPosSelected (handle, index + 1)) return; - /* - * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos () - * in a XmEXTENDED_SELECT list widget will add the index to the selected - * indices. The observed behavior does not match the spec. The fix is - * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT - * and then switch it back because XmListSelectPost () works as specified - * for XmMULTIPLE_SELECT list widgets. - */ - int [] argList = {OS.XmNselectionPolicy, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int oldPolicy = argList [1]; - if (oldPolicy == OS.XmEXTENDED_SELECT) { - argList [1] = OS.XmMULTIPLE_SELECT; - OS.XtSetValues (handle, argList, argList.length / 2); - } - /* - * Note: We rely on the fact that XmListSelectPos () - * fails silently when the indices are out of range. - */ - OS.XmListSelectPos (handle, index + 1, false); - if (oldPolicy == OS.XmEXTENDED_SELECT) { - argList [1] = OS.XmEXTENDED_SELECT; - OS.XtSetValues (handle, argList, argList.length / 2); - } -} -/** - * Selects the items in the range specified by the given zero-relative - * indices in the receiver. The range of indices is inclusive. - * The current selection is not cleared before the new items are selected. - * <p> - * If an item in the given range is not selected, it is selected. - * If an item in the given range was already selected, it remains selected. - * Indices that are out of range are ignored and no items will be selected - * if start is greater than end. - * If the receiver is single-select and there is more than one item in the - * given range, then all indices are ignored. - * - * @param start the start of the range - * @param end the end of the range - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see List#setSelection(int,int) - */ -public void select (int start, int end) { - checkWidget (); - if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return; - int [] argList = {OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int count = argList[1]; - if (count == 0 || start >= count) return; - start = Math.max (0, start); - end = Math.min (end, count - 1); - if ((style & SWT.SINGLE) != 0) { - OS.XmListSelectPos (handle, start + 1, false); - return; - } - /* - * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos () - * in a XmEXTENDED_SELECT list widget will add the index to the selected - * indices. The observed behavior does not match the spec. The fix is - * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT - * and then switch it back because XmListSelectPos () works as specified - * for XmMULTIPLE_SELECT list widgets. - */ - argList = new int[] {OS.XmNselectionPolicy, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int oldPolicy = argList [1]; - if (oldPolicy == OS.XmEXTENDED_SELECT) { - argList [1] = OS.XmMULTIPLE_SELECT; - OS.XtSetValues (handle, argList, argList.length / 2); - } - /* - * Note: XmListSelectPos () fails silently when the indices are out of range. - */ - for (int i=start; i<=end; i++) { - int index = i + 1; - if (!OS.XmListPosSelected (handle, index)) { - OS.XmListSelectPos (handle, index, false); - } - } - if (oldPolicy == OS.XmEXTENDED_SELECT) { - argList [1] = OS.XmEXTENDED_SELECT; - OS.XtSetValues (handle, argList, argList.length / 2); - } -} -/** - * Selects the items at the given zero-relative indices in the receiver. - * The current selection is not cleared before the new items are selected. - * <p> - * If the item at a given index is not selected, it is selected. - * If the item at a given index was already selected, it remains selected. - * Indices that are out of range and duplicate indices are ignored. - * If the receiver is single-select and multiple indices are specified, - * then all indices are ignored. - * - * @param indices the array of indices for the items to select - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see List#setSelection(int[]) - */ -public void select (int [] indices) { - checkWidget (); - if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); - int length = indices.length; - if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return; - if ((style & SWT.SINGLE) != 0) { - int [] argList = {OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int count = argList [1]; - int index = indices [0]; - if (0 <= index && index < count) { - select (index); - } - return; - } - /* - * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos () - * in a XmEXTENDED_SELECT list widget will add the index to the selected - * indices. The observed behavior does not match the spec. The fix is - * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT - * and then switch it back because XmListSelectPos () works as specified - * for XmMULTIPLE_SELECT list widgets. - */ - int [] argList = {OS.XmNselectionPolicy, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int oldPolicy = argList [1]; - if (oldPolicy == OS.XmEXTENDED_SELECT) { - argList [1] = OS.XmMULTIPLE_SELECT; - OS.XtSetValues (handle, argList, argList.length / 2); - } - /* - * Note: We rely on the fact that XmListSelectPos () - * fails silently when the indices are out of range. - */ - for (int i=0; i<length; i++) { - int index = indices [i] + 1; - if ((index != 0) && !OS.XmListPosSelected (handle, index)) { - OS.XmListSelectPos (handle, index, false); - } - } - if (oldPolicy == OS.XmEXTENDED_SELECT) { - argList [1] = OS.XmEXTENDED_SELECT; - OS.XtSetValues (handle, argList, argList.length / 2); - } -} -void select (String [] items) { - checkWidget(); - int [] table = new int [items.length]; - String codePage = getCodePage (); - for (int i=0; i<items.length; i++) { - String string = items [i]; - byte [] buffer = Converter.wcsToMbcs (codePage, string, true); - int xmString = OS.XmStringCreateLocalized (buffer); - table [i] = xmString; - } - int ptr = OS.XtMalloc (items.length * 4); - OS.memmove (ptr, table, items.length * 4); - int [] argList = {OS.XmNselectedItems, ptr, OS.XmNselectedItemCount, table.length}; - OS.XtSetValues (handle, argList, argList.length / 2); - for (int i=0; i<table.length; i++) OS.XmStringFree (table [i]); - OS.XtFree (ptr); - OS.XmListUpdateSelectedList (handle); -} -/** - * Selects all of the items in the receiver. - * <p> - * If the receiver is single-select, do nothing. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void selectAll () { - checkWidget(); - if ((style & SWT.SINGLE) != 0) return; - /* - * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos () - * in a XmEXTENDED_SELECT list widget will add the index to the selected - * indices. The observed behavior does not match the spec. The fix is - * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT - * and then switch it back because XmListSelectPos () works as specified - * for XmMULTIPLE_SELECT list widgets. - */ - int [] argList = {OS.XmNselectionPolicy, 0, OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int oldPolicy = argList [1]; - if (oldPolicy == OS.XmEXTENDED_SELECT) { - argList [1] = OS.XmMULTIPLE_SELECT; - OS.XtSetValues (handle, argList, argList.length / 2); - } - for (int i=0; i<argList[3]; i++) { - int index = i + 1; - if (!OS.XmListPosSelected (handle, index)) { - OS.XmListSelectPos (handle, index, false); - } - } - if (oldPolicy == OS.XmEXTENDED_SELECT) { - argList [1] = OS.XmEXTENDED_SELECT; - OS.XtSetValues (handle, argList, argList.length / 2); - } -} -boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - boolean changed = super.setBounds (x, y, width, height, move, resize); - /* - * Bug in AIX. When the receiver has a vertical scroll bar - * that is currently not visible and no horizontal scroll bar - * and is resized to be smaller in both the width and height - * and goes from the state where the width of the longest item - * is smaller than the width of the list to the state where the - * width of the longest item is longer than the width of the - * list, the list hides the vertical scroll bar and leaves a - * blank space where it should be. This often happens when a - * shell containing a list that matches the above criteria is - * maximized and then restored. This is just one of a number - * of repeatable cases where the scrolled window hides the - * scroll bars but does not resize the list. The fix is to - * detect these cases and force the scroll bars to be laid - * out properly by growing and then shrinking the scrolled - * window. - */ - - /* Grow and shrink the scrolled window by one pixel */ - if (changed && scrolledHandle != 0) { - int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - OS.XtGetValues (scrolledHandle, argList, argList.length / 2); - OS.XtResizeWidget (scrolledHandle, argList [1] + 1, argList [3], argList [5]); - OS.XtResizeWidget (scrolledHandle, argList [1], argList [3], argList [5]); - } - return changed; -} -void setFocusIndex (int index) { - int [] argList = {OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int count = argList [1]; - if (!(0 <= index && index < count)) return; - OS.XmListSetKbdItemPos (handle, index + 1); -} -public void setFont (Font font) { - checkWidget (); - - /* - * Bug in Motif. Setting the font in a list widget that does - * not have any items causes a GP on UTF-8 locale. - * The fix is to add an item, change the font, then - * remove the added item at the end. - */ - int [] argList1 = {OS.XmNitems, 0, OS.XmNitemCount, 0,}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - boolean fixString = OS.IsDBLocale && argList1 [3] == 0; - if (fixString) { - byte [] buffer = Converter.wcsToMbcs (getCodePage (), "string", true); - int xmString = OS.XmStringCreateLocalized (buffer); - OS.XmListAddItemUnselected (handle, xmString, -1); - OS.XmStringFree (xmString); - } - super.setFont (font); - if (fixString) OS.XtSetValues (handle, argList1, argList1.length / 2); -} -/** - * Sets the text of the item in the receiver's list at the given - * zero-relative index to the string argument. - * - * @param index the index for the item - * @param string the new text for the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setItem (int index, String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if (index == -1) error (SWT.ERROR_INVALID_RANGE); - int [] argList = {OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (!(0 <= index && index < argList [1])) { - error (SWT.ERROR_INVALID_RANGE); - } - byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); - int xmString = OS.XmStringCreateLocalized (buffer); - if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED); - boolean isSelected = OS.XmListPosSelected (handle, index + 1); - OS.XmListReplaceItemsPosUnselected (handle, new int [] {xmString}, 1, index + 1); - if (isSelected) OS.XmListSelectPos (handle, index + 1, false); - OS.XmStringFree (xmString); -} -/** - * Sets the receiver's items to be the given array of items. - * - * @param items the array of items - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the items array is null</li> - * <li>ERROR_INVALID_ARGUMENT - if an item in the items array is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setItems (String [] items) { - checkWidget(); - if (items == null) error (SWT.ERROR_NULL_ARGUMENT); - for (int i=0; i<items.length; i++) { - if (items [i] == null) error (SWT.ERROR_INVALID_ARGUMENT); - } - /* - * Bug in AIX. When all list items are replaced - * in a scrolled list that is currently showing a - * horizontal scroll bar, the horizontal scroll bar - * is hidden, but the list does not grow to take up - * the space once occupied by the bar. The fix is - * of force the horizontal bar to be recomputed by - * removing all items and resizing the list. - */ - OS.XmListSetPos (handle, 0); - OS.XmListDeselectAllItems (handle); - if ((style & SWT.H_SCROLL) != 0) { - OS.XmListDeleteAllItems (handle); - } - int index = 0; - int [] table = new int [items.length]; - String codePage = getCodePage (); - while (index < items.length) { - String string = items [index]; - byte [] buffer = Converter.wcsToMbcs (codePage, string, true); - int xmString = OS.XmStringCreateLocalized (buffer); - if (xmString == 0) break; - table [index++] = xmString; - } - int ptr = OS.XtMalloc (index * 4); - OS.memmove (ptr, table, index * 4); - int [] argList = {OS.XmNitems, ptr, OS.XmNitemCount, index}; - OS.XtSetValues (handle, argList, argList.length / 2); - for (int i=0; i<index; i++) OS.XmStringFree (table [i]); - OS.XtFree (ptr); - /* - * Bug in Motif. Resize the list to work around - * the horizontal scroll bar display bug described - * above. - */ - if ((style & SWT.H_SCROLL) != 0) { - OS.XtResizeWindow (handle); - } - if (index < items.length) error (SWT.ERROR_ITEM_NOT_ADDED); -} -/** - * Selects the item at the given zero-relative index in the receiver. - * If the item at the index was already selected, it remains selected. - * The current selection is first cleared, then the new item is selected. - * Indices that are out of range are ignored. - * - * @param index the index of the item to select - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * @see List#deselectAll() - * @see List#select(int) - */ -public void setSelection (int index) { - checkWidget(); - deselectAll (); - select (index); - showSelection (); - if ((style & SWT.MULTI) != 0) { - if (0 <= index) setFocusIndex (index); - } -} -/** - * Selects the items in the range specified by the given zero-relative - * indices in the receiver. The range of indices is inclusive. - * The current selection is cleared before the new items are selected. - * <p> - * Indices that are out of range are ignored and no items will be selected - * if start is greater than end. - * If the receiver is single-select and there is more than one item in the - * given range, then all indices are ignored. - * - * @param start the start index of the items to select - * @param end the end index of the items to select - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see List#deselectAll() - * @see List#select(int,int) - */ -public void setSelection (int start, int end) { - checkWidget (); - if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) { - deselectAll (); - return; - } - int [] argList = {OS.XmNitemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int count = argList[1]; - if (count == 0 || start >= count) { - deselectAll (); - return; - } - start = Math.max (0, start); - end = Math.min (end, count - 1); - if ((style & SWT.MULTI) != 0) deselectAll (); - select (start, end); - showSelection (); - if ((style & SWT.MULTI) != 0) { - setFocusIndex (start); - } -} -/** - * Selects the items at the given zero-relative indices in the receiver. - * The current selection is cleared before the new items are selected. - * <p> - * Indices that are out of range and duplicate indices are ignored. - * If the receiver is single-select and multiple indices are specified, - * then all indices are ignored. - * - * @param indices the indices of the items to select - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the array of indices is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see List#deselectAll() - * @see List#select(int[]) - */ -public void setSelection(int[] indices) { - checkWidget (); - if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); - deselectAll (); - int length = indices.length; - if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return; - select (indices); - showSelection (); - if ((style & SWT.MULTI) != 0) { - int focusIndex = indices [0]; - if (0 <= focusIndex) setFocusIndex (focusIndex); - } -} -/** - * Sets the receiver's selection to be the given array of items. - * The current selection is cleared before the new items are selected. - * <p> - * Items that are not in the receiver are ignored. - * If the receiver is single-select and multiple items are specified, - * then all items are ignored. - * - * @param items the array of items - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see List#deselectAll() - * @see List#select(int[]) - * @see List#setSelection(int[]) - */ -public void setSelection (String [] items) { - checkWidget (); - if (items == null) error (SWT.ERROR_NULL_ARGUMENT); - int length = items.length; - if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) { - deselectAll (); - return; - } - String codePage = getCodePage (); - if ((style & SWT.SINGLE) != 0) { - String string = items [0]; - if (string != null) { - byte [] buffer = Converter.wcsToMbcs (codePage, string, true); - int xmString = OS.XmStringCreateLocalized (buffer); - if (xmString != 0) { - int index = OS.XmListItemPos (handle, xmString); - if (index != 0) OS.XmListSelectPos (handle, index, false); - OS.XmStringFree (xmString); - if (index != 0 && OS.XmListPosSelected (handle, index)) { - showSelection (); - return; - } - } - } - deselectAll (); - return; - } - deselectAll (); - int count = 0; - int [] table = new int [length]; - for (int i=0; i<length; i++) { - String string = items [i]; - if (string != null) { - byte [] buffer = Converter.wcsToMbcs (codePage, string, true); - int xmString = OS.XmStringCreateLocalized (buffer); - if (xmString != 0) table [count++] = xmString; - } - } - int ptr = OS.XtMalloc (count * 4); - OS.memmove (ptr, table, count * 4); - int [] argList = {OS.XmNselectedItems, ptr, OS.XmNselectedItemCount, count}; - OS.XtSetValues (handle, argList, argList.length / 2); - boolean focusSet = false; - for (int i = 0; i < count; i++) { - if (!focusSet) { - int index = OS.XmListItemPos (handle, table [i]); - if (index > 0) { - focusSet = true; - setFocusIndex (index - 1); - } - } - OS.XmStringFree (table [i]); - } - OS.XtFree (ptr); - OS.XmListUpdateSelectedList (handle); - showSelection (); -} -/** - * Sets the zero-relative index of the item which is currently - * at the top of the receiver. This index can change when items - * are scrolled or new items are added and removed. - * - * @param index the index of the top item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setTopIndex (int index) { - checkWidget(); - int [] argList = {OS.XmNitemCount, 0, OS.XmNvisibleItemCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int newIndex = Math.max (1, Math.min (index + 1, argList [1])); - int lastIndex = Math.max (1, argList [1] - argList [3] + 1); - if (newIndex > lastIndex) newIndex = lastIndex; - OS.XmListSetPos (handle, newIndex); -} -/** - * Shows the selection. If the selection is already showing in the receiver, - * this method simply returns. Otherwise, the items are scrolled until - * the selection is visible. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void showSelection () { - checkWidget(); - int [] buffer = new int [1], positions = new int [1]; - if (!OS.XmListGetSelectedPos (handle, positions, buffer)) return; - if (buffer [0] == 0) return; - int address = positions [0]; - int [] indices = new int [1]; - OS.memmove (indices, address, 4); - OS.XtFree (address); - int index = indices [0]; - int [] argList = { - OS.XmNtopItemPosition, 0, - OS.XmNvisibleItemCount, 0, - OS.XmNitemCount, 0, - }; - OS.XtGetValues (handle, argList, argList.length / 2); - int topIndex = argList [1], visibleCount = argList [3], count = argList [5]; - int bottomIndex = Math.min (topIndex + visibleCount - 1, count); - if ((topIndex <= index) && (index <= bottomIndex)) return; - int lastIndex = Math.max (1, count - visibleCount + 1); - int newTop = Math.min (Math.max (index - (visibleCount / 2), 1), lastIndex); - OS.XmListSetPos (handle, newTop); -} -int topHandle () { - /* - * Normally, when a composite has both a form handle - * and a scrolled handle, the scrolled handle is the - * parent of the form handle. In the case of a list, - * both handles are present but the form handle is - * parent of the scrolled handle and therefore is - * the top handle of the list. - */ - return formHandle; -} -int XmNbrowseSelectionCallback (int w, int client_data, int call_data) { - postEvent (SWT.Selection); - return 0; -} -int XmNdefaultActionCallback (int w, int client_data, int call_data) { - postEvent (SWT.DefaultSelection); - return 0; -} -int XmNextendedSelectionCallback (int w, int client_data, int call_data) { - postEvent (SWT.Selection); - return 0; -} -int XmNmultipleSelectionCallback (int w, int client_data, int call_data) { - postEvent (SWT.Selection); - return 0; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java deleted file mode 100755 index a9c5f18866..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java +++ /dev/null @@ -1,913 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class are user interface objects that contain - * menu items. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>BAR, DROP_DOWN, POP_UP, NO_RADIO_GROUP</dd> - * <dd>LEFT_TO_RIGHT, RIGHT_TO_LEFT</dd> - * <dt><b>Events:</b></dt> - * <dd>Help, Hide, Show </dd> - * </dl> - * <p> - * Note: Only one of BAR, DROP_DOWN and POP_UP may be specified. - * Only one of LEFT_TO_RIGHT or RIGHT_TO_LEFT may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#menu">Menu snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class Menu extends Widget { - boolean hasLocation; - MenuItem cascade, defaultItem; - Decorations parent; -/** - * Constructs a new instance of this class given its parent, - * and sets the style for the instance so that the instance - * will be a popup menu on the given parent's shell. - * <p> - * After constructing a menu, it can be set into its parent - * using <code>parent.setMenu(menu)</code>. In this case, the parent may - * be any control in the same widget tree as the parent. - * </p> - * - * @param parent a control which will be the parent of the new instance (cannot be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#POP_UP - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Menu (Control parent) { - this (checkNull(parent).menuShell (), SWT.POP_UP); -} -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Decorations</code>) and a style value - * describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p><p> - * After constructing a menu or menuBar, it can be set into its parent - * using <code>parent.setMenu(menu)</code> or <code>parent.setMenuBar(menuBar)</code>. - * </p> - * - * @param parent a decorations control which will be the parent of the new instance (cannot be null) - * @param style the style of menu to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#BAR - * @see SWT#DROP_DOWN - * @see SWT#POP_UP - * @see SWT#NO_RADIO_GROUP - * @see SWT#LEFT_TO_RIGHT - * @see SWT#RIGHT_TO_LEFT - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Menu (Decorations parent, int style) { - super (parent, checkStyle (style)); - this.parent = parent; - createWidget (0); -} -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Menu</code>) and sets the style - * for the instance so that the instance will be a drop-down - * menu on the given parent's parent. - * <p> - * After constructing a drop-down menu, it can be set into its parentMenu - * using <code>parentMenu.setMenu(menu)</code>. - * </p> - * - * @param parentMenu a menu which will be the parent of the new instance (cannot be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#DROP_DOWN - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Menu (Menu parentMenu) { - this (checkNull(parentMenu).parent, SWT.DROP_DOWN); -} -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>MenuItem</code>) and sets the style - * for the instance so that the instance will be a drop-down - * menu on the given parent's parent menu. - * <p> - * After constructing a drop-down menu, it can be set into its parentItem - * using <code>parentItem.setMenu(menu)</code>. - * </p> - * - * @param parentItem a menu item which will be the parent of the new instance (cannot be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#DROP_DOWN - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Menu (MenuItem parentItem) { - this (checkNull(parentItem).parent); -} -void _setVisible (boolean visible) { - if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return; - if (visible) { - sendEvent (SWT.Show); - if (getItemCount () != 0) { - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int xWindow = OS.XDefaultRootWindow (xDisplay); - if (xWindow == 0) return; - int [] rootX = new int [1], rootY = new int [1], unused = new int [1], mask = new int [1]; - if (OS.XQueryPointer (xDisplay, xWindow, unused, unused, rootX, rootY, unused, unused, mask) == 0) { - return; - } - if (!hasLocation) { - /* - * Bug in Motif. For some reason, when a menu is popped up - * under the mouse, the menu will not highlight until the - * mouse exits and then enters the menu again. The fix is - * to pop the menu up outside the current mouse position - * causing highlighting to work properly when the user - * waits for the menu to appear. - */ - rootX[0] += 1; rootY[0] += 1; - int [] argList = {OS.XmNx, rootX [0], OS.XmNy, rootY [0]}; - OS.XtSetValues (handle, argList, argList.length / 2); - } - /* - * Feature in Motif. If an X grab is active, then - * the menu pops us but issues and error message an - * fails to grab the pointer. The fix is to ensure - * that no grab is active before showing the menu. - */ - OS.XUngrabPointer (xDisplay, OS.CurrentTime); - OS.XtManageChild (handle); - /* - * Feature in Motif. There is no API to force the menu - * to accept keyboard traversal when popped up using - * XtManageChild. The fix is to call undocumented API - * to do this. - */ - int flags = OS.Button1Mask | OS.Button2Mask | OS.Button3Mask; - if ((mask [0] & flags) == 0) OS._XmSetMenuTraversal (handle, true); - } else { - sendEvent (SWT.Hide); - } - } else { - OS.XtUnmanageChild (handle); - } -} -void addAccelerators () { - MenuItem [] items = getItems (); - for (int i = 0; i < items.length; i++) { - MenuItem item = items[i]; - item.addAccelerators (); - } -} -/** - * Adds the listener to the collection of listeners who will - * be notified when help events are generated for the control, - * by sending it one of the messages defined in the - * <code>HelpListener</code> interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see HelpListener - * @see #removeHelpListener - */ -public void addHelpListener (HelpListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Help, typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when menus are hidden or shown, by sending it - * one of the messages defined in the <code>MenuListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see MenuListener - * @see #removeMenuListener - */ -public void addMenuListener(MenuListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener(SWT.Hide,typedListener); - addListener(SWT.Show,typedListener); -} -static int checkStyle (int style) { - return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0); -} -static Control checkNull (Control control) { - if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); - return control; -} -static Menu checkNull (Menu menu) { - if (menu == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); - return menu; -} -static MenuItem checkNull (MenuItem item) { - if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); - return item; -} -void createHandle (int index) { - /* - * Bug in Motif. For some reason, creating a menu after any application context - * and shell have been destroyed will segment fault unless a new application - * context and shell have been created in the current thread. The fix is to - * detect this case and create and destroy a temporary application context and - * shell. - */ - int xDisplay = 0, shellHandle = 0; - if (Display.DisplayDisposed) { - int [] argc = new int [] {0}; - int xtContext = OS.XtCreateApplicationContext (); - xDisplay = OS.XtOpenDisplay (xtContext, null, null, null, 0, 0, argc, 0); - shellHandle = OS.XtAppCreateShell (null, null, OS.topLevelShellWidgetClass (), xDisplay, null, 0); - } - - /* BAR menu */ - if ((style & SWT.BAR) != 0) { - int parentHandle = parent.scrolledHandle; - int [] argList = {OS.XmNancestorSensitive, 1}; - handle = OS.XmCreateMenuBar (parentHandle, null, argList, argList.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - return; - } - - /* POPUP and PULLDOWN menus */ - - /* - * Bug in Motif. When an existing popup menu is destroyed just - * before creating a new popup menu and the new menu is managed, - * the cursor changes to the menu cursor but the new menu is not - * displayed. Also, Motif fails to show a popup menu when the - * mouse is released. Both problems stem from the fact that the - * popup menu is in the widget tree of a visible shell. The fix - * is to create all popup menus as children of a hidden dialog - * shell. Menus created this way are automatically destroyed - * when the shell is destroyed. - */ - byte [] buffer = new byte [1]; - int [] argList = {OS.XmNancestorSensitive, 1}; - if ((style & SWT.POP_UP) != 0) { - int parentHandle = parent.dialogHandle (); - handle = OS.XmCreatePopupMenu (parentHandle, buffer, argList, argList.length / 2); - } else { - /* - * Bug in Linux. For some reason, when the parent of the pulldown - * menu is not the main window handle, XtDestroyWidget() occasionally - * segment faults when the shell is destroyed. The fix is to ensure - * that the parent is the main window. - */ - int parentHandle = parent.scrolledHandle; - handle = OS.XmCreatePulldownMenu (parentHandle, buffer, argList, argList.length / 2); - } - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - - /* Workaround for bug in Motif */ - if (Display.DisplayDisposed) { - if (shellHandle != 0) OS.XtDestroyWidget (shellHandle); - if (xDisplay != 0) { - int xtContext = OS.XtDisplayToApplicationContext (xDisplay); - OS.XtDestroyApplicationContext (xtContext); - } - } -} -void createWidget (int index) { - checkOrientation (parent); - super.createWidget (index); - parent.addMenu (this); -} -/*public*/ Rectangle getBounds () { - checkWidget(); - if (!OS.XtIsManaged (handle)) return new Rectangle (0, 0, 0, 0); - int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int x = argList [1], y = argList [3]; - if ((style & SWT.BAR) != 0) { - short [] root_x = new short [1], root_y = new short [1]; - OS.XtTranslateCoords (handle, (short) x, (short) x, root_x, root_y); - x = root_x [0]; - y = root_y [0]; - } - return new Rectangle (x, y, argList [5], argList [7]); -} -/** - * Returns the default menu item or null if none has - * been previously set. - * - * @return the default menu item. - * - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public MenuItem getDefaultItem () { - checkWidget(); - return defaultItem; -} -/** - * Returns <code>true</code> if the receiver is enabled, and - * <code>false</code> otherwise. A disabled menu is typically - * not selectable from the user interface and draws with an - * inactive or "grayed" look. - * - * @return the receiver's enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #isEnabled - */ -public boolean getEnabled () { - checkWidget(); - int [] argList = {OS.XmNsensitive, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1] != 0; -} -/** - * Returns the item at the given, zero-relative index in the - * receiver. Throws an exception if the index is out of range. - * - * @param index the index of the item to return - * @return the item at the given index - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public MenuItem getItem (int index) { - checkWidget(); - int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (argList [1] == 0) error (SWT.ERROR_CANNOT_GET_ITEM); - int [] handles = new int [argList [3]]; - OS.memmove (handles, argList [1], argList[3] * 4); - int i = 0, count = 0; - while (i < argList [3]) { - if (OS.XtIsManaged (handles [i])) { - if (index == count) break; - count++; - } - i++; - } - if (index != count) error (SWT.ERROR_INVALID_RANGE); - Widget widget = display.getWidget (handles [i]); - if (!(widget instanceof MenuItem)) error (SWT.ERROR_CANNOT_GET_ITEM); - return (MenuItem) widget; -} -/** - * Returns the number of items contained in the receiver. - * - * @return the number of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getItemCount () { - checkWidget(); - int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (argList [1] == 0 || argList [3] == 0) return 0; - int [] handles = new int [argList [3]]; - OS.memmove (handles, argList [1], argList [3] * 4); - int count = 0; - for (int i=0; i<argList [3]; i++) { - if (OS.XtIsManaged (handles [i])) count++; - } - return count; -} -/** - * Returns a (possibly empty) array of <code>MenuItem</code>s which - * are the items in the receiver. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its list of items, so modifying the array will - * not affect the receiver. - * </p> - * - * @return the items in the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public MenuItem [] getItems () { - checkWidget(); - int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int ptr = argList [1], count = argList [3]; - if (count == 0 || ptr == 0) return new MenuItem [0]; - int [] handles = new int [count]; - OS.memmove (handles, ptr, count * 4); - MenuItem [] items = new MenuItem [count]; - int i = 0, j = 0; - while (i < count) { - Widget item = display.getWidget (handles [i]); - if (item != null) items [j++] = (MenuItem) item; - i++; - } - if (i == j) return items; - MenuItem [] newItems = new MenuItem [j]; - System.arraycopy (items, 0, newItems, 0, j); - return newItems; -} -String getNameText () { - String result = ""; - MenuItem [] items = getItems (); - int length = items.length; - if (length > 0) { - for (int i=0; i<length-1; i++) { - result = result + items [i].getNameText() + ", "; - } - result = result + items [length-1].getNameText (); - } - return result; -} -/** - * Returns the receiver's parent, which must be a <code>Decorations</code>. - * - * @return the receiver's parent - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Decorations getParent () { - checkWidget(); - return parent; -} -/** - * Returns the receiver's parent item, which must be a - * <code>MenuItem</code> or null when the receiver is a - * root. - * - * @return the receiver's parent item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public MenuItem getParentItem () { - checkWidget(); - return cascade; -} -/** - * Returns the receiver's parent item, which must be a - * <code>Menu</code> or null when the receiver is a - * root. - * - * @return the receiver's parent item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Menu getParentMenu () { - checkWidget(); - if (cascade != null) return cascade.parent; - return null; -} -/** - * Returns the receiver's shell. For all controls other than - * shells, this simply returns the control's nearest ancestor - * shell. Shells return themselves, even if they are children - * of other shells. - * - * @return the receiver's shell - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getParent - */ -public Shell getShell () { - checkWidget(); - return parent.getShell (); -} -/** - * Returns <code>true</code> if the receiver is visible, and - * <code>false</code> otherwise. - * <p> - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, this method - * may still indicate that it is considered visible even though - * it may not actually be showing. - * </p> - * - * @return the receiver's visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getVisible () { - checkWidget(); - if ((style & SWT.POP_UP) != 0) { - Menu [] popups = display.popups; - if (popups != null) { - for (int i=0; i<popups.length; i++) { - if (popups [i] == this) return true; - } - } - } - return OS.XtIsManaged (handle); -} -void hookEvents () { - int windowProc = display.windowProc; - OS.XtAddCallback (handle, OS.XmNhelpCallback, windowProc, HELP_CALLBACK); - OS.XtAddCallback (handle, OS.XmNmapCallback, windowProc, MAP_CALLBACK); - OS.XtAddCallback (handle, OS.XmNunmapCallback, windowProc, UNMAP_CALLBACK); -} -/** - * Searches the receiver's list starting at the first item - * (index 0) until an item is found that is equal to the - * argument, and returns the index of that item. If no item - * is found, returns -1. - * - * @param item the search item - * @return the index of the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the item is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int indexOf (MenuItem item) { - checkWidget(); - int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int [] handles = new int [argList [3]]; - OS.memmove (handles, argList [1], handles.length * 4); - int index = 0; - for (int i=0; i<handles.length; i++) { - if (OS.XtIsManaged (handles [i])) { - if (handles [i] == item.handle) return index; - index++; - } - } - return -1; -} -/** - * Returns <code>true</code> if the receiver is enabled and all - * of the receiver's ancestors are enabled, and <code>false</code> - * otherwise. A disabled menu is typically not selectable from the - * user interface and draws with an inactive or "grayed" look. - * - * @return the receiver's enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getEnabled - */ -public boolean isEnabled () { - checkWidget(); - Menu parentMenu = getParentMenu (); - if (parentMenu == null) { - return getEnabled () && parent.isEnabled (); - } - return getEnabled () && parentMenu.isEnabled (); -} -/** - * Returns <code>true</code> if the receiver is visible and all - * of the receiver's ancestors are visible and <code>false</code> - * otherwise. - * - * @return the receiver's visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getVisible - */ -public boolean isVisible () { - checkWidget(); - return getVisible (); -} -void releaseChildren (boolean destroy) { - MenuItem [] items = getItems (); - for (int i=0; i<items.length; i++) { - MenuItem item = items [i]; - if (item != null && !item.isDisposed ()) { - item.release (false); - } - } - super.releaseChildren (destroy); -} -void releaseParent () { - super.releaseParent (); - if (cascade != null) cascade.setMenu (null); - if ((style & SWT.BAR) != 0 && this == parent.menuBar) parent.setMenuBar (null); -} -void releaseWidget () { - super.releaseWidget (); - if (parent != null) parent.removeMenu (this); - parent = null; - cascade = defaultItem = null; -} -void removeAccelerators () { - MenuItem [] items = getItems (); - for (int i = 0; i < items.length; i++) { - MenuItem item = items[i]; - item.removeAccelerators (); - } -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the help events are generated for the control. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see HelpListener - * @see #addHelpListener - */ -public void removeHelpListener (HelpListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Help, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the menu events are generated for the control. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see MenuListener - * @see #addMenuListener - */ -public void removeMenuListener(MenuListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.Hide, listener); - eventTable.unhook(SWT.Show, listener); -} -void sendHelpEvent (int callData) { - if (hooks (SWT.Help)) { - postEvent (SWT.Help); - return; - } - parent.sendHelpEvent (callData); -} -/** - * Sets the default menu item to the argument or removes - * the default emphasis when the argument is <code>null</code>. - * - * @param item the default menu item or null - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the menu item has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setDefaultItem (MenuItem item) { - checkWidget(); - if (item != null && item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - defaultItem = item; -} -/** - * Enables the receiver if the argument is <code>true</code>, - * and disables it otherwise. A disabled menu is typically - * not selectable from the user interface and draws with an - * inactive or "grayed" look. - * - * @param enabled the new enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setEnabled (boolean enabled) { - checkWidget(); - int [] argList = {OS.XmNsensitive, enabled ? 1 : 0}; - OS.XtSetValues (handle, argList, argList.length / 2); -} -/** - * Sets the location of the receiver, which must be a popup, - * to the point specified by the arguments which are relative - * to the display. - * <p> - * Note that this is different from most widgets where the - * location of the widget is relative to the parent. - * </p><p> - * Note that the platform window manager ultimately has control - * over the location of popup menus. - * </p> - * - * @param x the new x coordinate for the receiver - * @param y the new y coordinate for the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setLocation (int x, int y) { - checkWidget(); - if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return; - int [] argList = {OS.XmNx, x, OS.XmNy, y}; - OS.XtSetValues (handle, argList, argList.length / 2); - hasLocation = true; -} -/** - * Sets the location of the receiver, which must be a popup, - * to the point specified by the argument which is relative - * to the display. - * <p> - * Note that this is different from most widgets where the - * location of the widget is relative to the parent. - * </p><p> - * Note that the platform window manager ultimately has control - * over the location of popup menus. - * </p> - * - * @param location the new location for the receiver - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the point is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.1 - */ -public void setLocation (Point location) { - checkWidget(); - if (location == null) error (SWT.ERROR_NULL_ARGUMENT); - setLocation (location.x, location.y); -} -/** - * Marks the receiver as visible if the argument is <code>true</code>, - * and marks it invisible otherwise. - * <p> - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, marking - * it visible may not actually cause it to be displayed. - * </p> - * - * @param visible the new visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setVisible (boolean visible) { - checkWidget(); - if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return; - if (visible) { - display.addPopup (this); - } else { - display.removePopup (this); - _setVisible (false); - } -} -boolean translateAccelerator (int accel, boolean doit) { - if (!getEnabled ()) return false; - MenuItem [] items = getItems (); - for (int i = 0; i < items.length; i++) { - MenuItem item = items [i]; - if (item.translateAccelerator (accel, doit)) return true; - } - return false; -} -int XmNhelpCallback (int w, int client_data, int call_data) { - sendHelpEvent (call_data); - return 0; -} -int XmNmapCallback (int w, int client_data, int call_data) { - if ((style & SWT.POP_UP) != 0) return 0; - sendEvent (SWT.Show); - return 0; -} -int XmNunmapCallback (int w, int client_data, int call_data) { - sendEvent (SWT.Hide); - return 0; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java deleted file mode 100755 index 592f9042de..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java +++ /dev/null @@ -1,984 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class represent a selectable user interface object - * that issues notification when pressed and released. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>CHECK, CASCADE, PUSH, RADIO, SEPARATOR</dd> - * <dt><b>Events:</b></dt> - * <dd>Arm, Help, Selection</dd> - * </dl> - * <p> - * Note: Only one of the styles CHECK, CASCADE, PUSH, RADIO and SEPARATOR - * may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class MenuItem extends Item { - int accelerator; - Menu parent, menu; - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Menu</code>) and a style value - * describing its behavior and appearance. The item is added - * to the end of the items maintained by its parent. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a menu control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#CHECK - * @see SWT#CASCADE - * @see SWT#PUSH - * @see SWT#RADIO - * @see SWT#SEPARATOR - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public MenuItem (Menu parent, int style) { - super (parent, checkStyle (style)); - this.parent = parent; - createWidget (OS.XmLAST_POSITION); -} - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Menu</code>), a style value - * describing its behavior and appearance, and the index - * at which to place it in the items maintained by its parent. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a menu control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * @param index the zero-relative index to store the receiver in its parent - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#CHECK - * @see SWT#CASCADE - * @see SWT#PUSH - * @see SWT#RADIO - * @see SWT#SEPARATOR - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public MenuItem (Menu parent, int style, int index) { - super (parent, checkStyle (style)); - this.parent = parent; - if (index == OS.XmLAST_POSITION) error (SWT.ERROR_INVALID_RANGE); - createWidget (index); -} -void addAccelerator () { - if (accelerator == 0 || !getEnabled ()) return; - if ((accelerator & SWT.COMMAND) != 0) return; - /* - * Bug in Solaris. When accelerators are set more - * than once in the same menu bar, the time it takes - * to set the accelerator increases exponentially. - * The fix is to implement our own accelerator table - * on Solaris. - */ - if (OS.IsSunOS) return; - String ctrl, alt, shift; - ctrl = alt = shift = ""; - if ((accelerator & SWT.ALT) != 0) alt = "Meta "; - if ((accelerator & SWT.SHIFT) != 0) shift = "Shift "; - if ((accelerator & SWT.CONTROL) != 0) ctrl = "Ctrl "; - int keysym = accelerator & SWT.KEY_MASK; - int newKey = Display.untranslateKey (keysym); - if (newKey != 0) { - keysym = newKey; - } else { - keysym = Display.wcsToMbcs ((char) keysym); - } - /* - * Feature in Motif. Motif does not activate an accelerator - * when the CapsLock, NumLock and NumLock+CapsLock keys are pressed. - * In order to activate accelerators when these keys are pressed, - * it is necessary to look for all of these key sequences. The fix - * is to add these modifiers to the accelerator. - */ - String key = ctrl + alt + shift + "<Key>" + keysymName (keysym); - String allKeys = key + ",Lock " + key; - String numLock = Display.numLock; - if (numLock != null) { - allKeys += "," + numLock + " " + key + ",Lock " + numLock + " " + key; - } - /* Use the character encoding for the default locale */ - byte [] buffer = Converter.wcsToMbcs (null, allKeys, true); - int ptr = OS.XtMalloc (buffer.length); - if (ptr != 0) OS.memmove (ptr, buffer, buffer.length); - - int [] argList = {OS.XmNaccelerator, ptr}; - OS.XtSetValues (handle, argList, argList.length / 2); - if (ptr != 0) OS.XtFree (ptr); -} -void addAccelerators () { - addAccelerator (); - if (menu != null) menu.addAccelerators (); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the arm events are generated for the control, by sending - * it one of the messages defined in the <code>ArmListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ArmListener - * @see #removeArmListener - */ -public void addArmListener (ArmListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Arm, typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the help events are generated for the control, by sending - * it one of the messages defined in the <code>HelpListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see HelpListener - * @see #removeHelpListener - */ -public void addHelpListener (HelpListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Help, typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the menu item is selected by the user, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * When <code>widgetSelected</code> is called, the stateMask field of the event object is valid. - * <code>widgetDefaultSelected</code> is not called. - * </p> - * - * @param listener the listener which should be notified when the menu item is selected by the user - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener(listener); - addListener(SWT.Selection,typedListener); - addListener(SWT.DefaultSelection,typedListener); -} -static int checkStyle (int style) { - return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.CASCADE, 0); -} -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} -void createHandle (int index) { - int parentHandle = parent.handle; - int [] argList1 = {OS.XmNchildren, 0, OS.XmNnumChildren, 0}; - OS.XtGetValues (parentHandle, argList1, argList1.length / 2); - if (index != OS.XmLAST_POSITION && argList1 [1] != 0) { - int [] handles = new int [argList1 [3]]; - OS.memmove (handles, argList1 [1], argList1 [3] * 4); - int i = 0, count = 0; - while (i < argList1 [3]) { - if (OS.XtIsManaged (handles [i])) { - if (index == count) break; - count++; - } - i++; - } - if (index != count) error (SWT.ERROR_INVALID_RANGE); - index = i; - } - if ((style & SWT.SEPARATOR) != 0) { - int [] argList = { - OS.XmNancestorSensitive, 1, - OS.XmNorientation, (parent.style & SWT.BAR) != 0 ? OS.XmVERTICAL : OS.XmHORIZONTAL, - OS.XmNpositionIndex, index, - }; - handle = OS.XmCreateSeparatorGadget (parentHandle, null, argList, argList.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - return; - } - int [] argList = { - OS.XmNancestorSensitive, 1, - OS.XmNpositionIndex, index, - }; - if ((style & SWT.PUSH) != 0) { - handle = OS.XmCreatePushButtonGadget (parentHandle, null, argList, argList.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - return; - } - if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { - handle = OS.XmCreateToggleButtonGadget (parentHandle, null, argList, argList.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - int indicatorType = OS.XmONE_OF_MANY; - if ((style & SWT.CHECK) != 0) indicatorType = OS.XmN_OF_MANY; - int [] argList2 = {OS.XmNindicatorType, indicatorType}; - OS.XtSetValues (handle, argList2, argList2.length / 2); - return; - } - handle = OS.XmCreateCascadeButtonGadget (parentHandle, null, argList, argList.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); -} -void destroyWidget () { - /* - * Feature in Motif. When a popup menu item - * is destroyed, the menu does not recompute - * the menu size until the next time the menu - * is managed. This means that the user can - * watch the menu get updated as new items are - * added and old ones deleted. The fix is to - * unmanaged the item before destroying it to - * force the menu to recompute the menu size. - */ - OS.XtUnmanageChild (handle); - super.destroyWidget (); -} -/** - * Returns the widget accelerator. An accelerator is the bit-wise - * OR of zero or more modifier masks and a key. Examples: - * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>. - * The default value is zero, indicating that the menu item does - * not have an accelerator. - * - * @return the accelerator or 0 - * - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getAccelerator () { - checkWidget(); - return accelerator; -} -/*public*/ Rectangle getBounds () { - checkWidget(); - if (!OS.XtIsManaged (handle)) return new Rectangle (0, 0, 0, 0); - int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return new Rectangle ((short) argList [1], (short) argList [3], argList [5], argList [7]); -} -/** - * Returns <code>true</code> if the receiver is enabled, and - * <code>false</code> otherwise. A disabled menu item is typically - * not selectable from the user interface and draws with an - * inactive or "grayed" look. - * - * @return the receiver's enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #isEnabled - */ -public boolean getEnabled () { - checkWidget(); - int [] argList = {OS.XmNsensitive, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1] != 0; -} -/** - * Returns the receiver's cascade menu if it has one or null - * if it does not. Only <code>CASCADE</code> menu items can have - * a pull down menu. The sequence of key strokes, button presses - * and/or button releases that are used to request a pull down - * menu is platform specific. - * - * @return the receiver's menu - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Menu getMenu () { - checkWidget(); - return menu; -} -String getNameText () { - if ((style & SWT.SEPARATOR) != 0) return "|"; - return super.getNameText (); -} -/** - * Returns the receiver's parent, which must be a <code>Menu</code>. - * - * @return the receiver's parent - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Menu getParent () { - checkWidget(); - return parent; -} -/** - * Returns <code>true</code> if the receiver is selected, - * and false otherwise. - * <p> - * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, - * it is selected when it is checked. - * - * @return the selection state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getSelection () { - checkWidget(); - if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false; - int [] argList = {OS.XmNset, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1] != OS.XmUNSET; -} -void hookEvents () { - if ((style & SWT.SEPARATOR) != 0) return; - int windowProc = display.windowProc; - OS.XtAddCallback (handle, OS.XmNhelpCallback, windowProc, HELP_CALLBACK); - if ((style & SWT.CASCADE) != 0) { - OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK); - OS.XtAddCallback (handle, OS.XmNcascadingCallback, windowProc, CASCADING_CALLBACK); - } else { - OS.XtAddCallback (handle, OS.XmNarmCallback, windowProc, ARM_CALLBACK); - if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { - OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK); - } else { - OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK); - } - } -} -boolean isAccelActive () { - Menu menu = parent; - while (menu != null && menu.cascade != null) { - menu = menu.cascade.parent; - } - if (menu == null) return false; - Decorations shell = menu.parent; - return shell.menuBar == menu; -} -/** - * Returns <code>true</code> if the receiver is enabled and all - * of the receiver's ancestors are enabled, and <code>false</code> - * otherwise. A disabled menu item is typically not selectable from the - * user interface and draws with an inactive or "grayed" look. - * - * @return the receiver's enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getEnabled - */ -public boolean isEnabled () { - return getEnabled () && parent.isEnabled (); -} -String keysymName (int keysym) { - switch (keysym) { - case SWT.BS: return "BackSpace"; - case SWT.TAB: return "Tab"; - /* - * Bug in Motif. For some reason, the XmNaccelerator - * resource will not accept XK_Linefeed and prints Xt - * warnings. The fix is to use XK_Return instead. - */ -// case SWT.LF: -// case OS.XK_Linefeed: return "Linefeed"; - case SWT.LF: - case OS.XK_Linefeed: - case SWT.CR: return "Return"; - case SWT.ESC: return "Escape"; - case SWT.DEL: return "Delete"; - } - if (('0' <= keysym && keysym <= '9') || - ('a' <= keysym && keysym <= 'z') || - ('A' <= keysym && keysym <= 'Z')) { - return new String (new char [] {(char) keysym}); - } - /* - * Note that XKeysymToString returns a value in a static - * area which must not be modified or freed. - */ - int ptr = OS.XKeysymToString (keysym); - if (ptr == 0) return ""; - int length = OS.strlen (ptr); - byte [] buffer = new byte [length]; - OS.memmove (buffer, ptr, buffer.length); - /* Use the character encoding for the default locale */ - return new String (Converter.mbcsToWcs (null, buffer)); -} -void manageChildren () { - OS.XtManageChild (handle); -} -void releaseChildren (boolean destroy) { - if (menu != null) { - menu.release (false); - menu = null; - } - super.releaseChildren (destroy); -} -void releaseParent () { - super.releaseParent (); - if (menu != null) menu.dispose (); - menu = null; -} -void releaseWidget () { - super.releaseWidget (); - accelerator = 0; - if (this == parent.defaultItem) { - parent.defaultItem = null; - } - parent = null; -} -void removeAccelerator () { - if (accelerator == 0) return; - /* - * Bug in Solaris. When accelerators are set more - * than once in the same menu bar, the time it takes - * to set the accelerator increases exponentially. - * The fix is to implement our own accelerator table - * on Solaris. - */ - if (OS.IsSunOS) return; - int [] argList = {OS.XmNaccelerator, 0}; - OS.XtSetValues (handle, argList, argList.length / 2); -} -void removeAccelerators () { - removeAccelerator (); - if (menu != null) menu.removeAccelerators (); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the arm events are generated for the control. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ArmListener - * @see #addArmListener - */ -public void removeArmListener (ArmListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Arm, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the help events are generated for the control. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see HelpListener - * @see #addHelpListener - */ -public void removeHelpListener (HelpListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Help, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is selected by the user. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.Selection, listener); - eventTable.unhook(SWT.DefaultSelection,listener); -} -void selectRadio () { - int index = 0; - MenuItem [] items = parent.getItems (); - while (index < items.length && items [index] != this) index++; - int i = index - 1; - while (i >= 0 && items [i].setRadioSelection (false)) --i; - int j = index + 1; - while (j < items.length && items [j].setRadioSelection (false)) j++; - setSelection (true); -} -/** - * Sets the widget accelerator. An accelerator is the bit-wise - * OR of zero or more modifier masks and a key. Examples: - * <code>SWT.MOD1 | SWT.MOD2 | 'T', SWT.MOD3 | SWT.F2</code>. - * <code>SWT.CONTROL | SWT.SHIFT | 'T', SWT.ALT | SWT.F2</code>. - * The default value is zero, indicating that the menu item does - * not have an accelerator. - * - * @param accelerator an integer that is the bit-wise OR of masks and a key - * - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setAccelerator (int accelerator) { - checkWidget(); - if (this.accelerator == accelerator) return; - this.accelerator = accelerator; - if (isAccelActive ()) { - if (accelerator != 0) { - addAccelerator (); - } else { - removeAccelerator (); - } - } -} -/** - * Enables the receiver if the argument is <code>true</code>, - * and disables it otherwise. A disabled menu item is typically - * not selectable from the user interface and draws with an - * inactive or "grayed" look. - * - * @param enabled the new enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setEnabled (boolean enabled) { - checkWidget(); - if (getEnabled () == enabled) return; - int [] argList = {OS.XmNsensitive, enabled ? 1 : 0}; - OS.XtSetValues (handle, argList, argList.length / 2); - if (isAccelActive ()) { - if (enabled) { - addAccelerator (); - } else { - removeAccelerator (); - } - } -} -/** - * Sets the receiver's pull down menu to the argument. - * Only <code>CASCADE</code> menu items can have a - * pull down menu. The sequence of key strokes, button presses - * and/or button releases that are used to request a pull down - * menu is platform specific. - * <p> - * Note: Disposing of a menu item that has a pull down menu - * will dispose of the menu. To avoid this behavior, set the - * menu to null before the menu item is disposed. - * </p> - * - * @param menu the new pull down menu - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_MENU_NOT_DROP_DOWN - if the menu is not a drop down menu</li> - * <li>ERROR_MENUITEM_NOT_CASCADE - if the menu item is not a <code>CASCADE</code></li> - * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li> - * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMenu (Menu menu) { - checkWidget(); - /* Check to make sure the new menu is valid */ - if ((style & SWT.CASCADE) == 0) { - error (SWT.ERROR_MENUITEM_NOT_CASCADE); - } - if (menu != null) { - if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - if ((menu.style & SWT.DROP_DOWN) == 0) { - error (SWT.ERROR_MENU_NOT_DROP_DOWN); - } - if (menu.parent != parent.parent) { - error (SWT.ERROR_INVALID_PARENT); - } - } - - /* Assign the new menu */ - Menu oldMenu = this.menu; - if (oldMenu == menu) return; - - /* - * Bug in Motif. When XmNsubMenuId is set and the - * previous menu has accelerators, the time it takes - * to add any new accelerators increases exponentially. - * The fix is to remove the accelerators from the previous - * menu before setting the new one. - */ - boolean isActive = isAccelActive (); - if (isActive) removeAccelerators (); - - if (oldMenu != null) oldMenu.cascade = null; - this.menu = menu; - - /* Set the new menu in the OS */ - int menuHandle = 0; - if (menu != null) { - menu.cascade = this; - menuHandle = menu.handle; - } - int [] argList = {OS.XmNsubMenuId, menuHandle}; - OS.XtSetValues (handle, argList, argList.length / 2); - - if (isActive) addAccelerators (); -} -boolean setRadioSelection (boolean value) { - if ((style & SWT.RADIO) == 0) return false; - if (getSelection () != value) { - setSelection (value); - postEvent (SWT.Selection); - } - return true; -} -/** - * Sets the selection state of the receiver. - * <p> - * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, - * it is selected when it is checked. - * - * @param selected the new selection state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (boolean selected) { - checkWidget(); - if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return; - int [] argList = {OS.XmNset, selected ? OS.XmSET : OS.XmUNSET}; - OS.XtSetValues (handle, argList, argList.length / 2); -} -/** - * Sets the receiver's text. The string may include - * the mnemonic character and accelerator text. - * <p> - * Mnemonics are indicated by an '&' that causes the next - * character to be the mnemonic. When the user presses a - * key sequence that matches the mnemonic, a selection - * event occurs. On most platforms, the mnemonic appears - * underlined but may be emphasised in a platform specific - * manner. The mnemonic indicator character '&' can be - * escaped by doubling it in the string, causing a single - * '&' to be displayed. - * </p> - * <p> - * Accelerator text is indicated by the '\t' character. - * On platforms that support accelerator text, the text - * that follows the '\t' character is displayed to the user, - * typically indicating the key stroke that will cause - * the item to become selected. On most platforms, the - * accelerator text appears right aligned in the menu. - * Setting the accelerator text does not install the - * accelerator key sequence. The accelerator key sequence - * is installed using #setAccelerator. - * </p> - * - * @param string the new text - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the text is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #setAccelerator - */ -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - /* - * Feature in Motif. Motif does not optimize the case - * when the same text is set into a menu item causing - * it to flash. The fix is to test for equality and - * do nothing. - */ - if (text.equals (string)) return; - super.setText (string); - if ((style & (SWT.ARROW | SWT.SEPARATOR)) != 0) return; - - /* - * Bug in Linux. In certain contexts setting the label of a - * CHECK or RADIO menu item to the empty string can cause a - * GP. The fix is to set the menu label to a space in such - * cases since it displays equivalently. - */ - if (OS.IsLinux && (style & (SWT.CHECK | SWT.RADIO)) != 0) { - if (string.length () == 0) string = " "; - } - char [] text = new char [string.length ()]; - string.getChars (0, text.length, text, 0); - boolean accel = false; - int i=0, j=0, mnemonic=0; - while (i < text.length) { - if (text [i] == '\t') {accel = true; break;} - if ((text [j++] = text [i++]) == '&') { - if (i == text.length) {continue;} - if (text [i] == '&') {i++; continue;} - if (mnemonic == 0) mnemonic = text [i]; - j--; - } - } - int xmString2 = 0; - if (accel && ++i < text.length) { - char [] accelText = new char [text.length - i]; - System.arraycopy (text, i, accelText, 0, accelText.length); - /* Use the character encoding for the default locale */ - byte [] buffer2 = Converter.wcsToMbcs (null, accelText, true); - xmString2 = OS.XmStringParseText ( - buffer2, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - if (xmString2 == 0) error (SWT.ERROR_CANNOT_SET_TEXT); - } else { - /* - * Bug in linux. In some versions of linux motif setting a menu item's - * accelerator to NULL will cause a GP. The workaround is to instead - * set these accelerators to a functionally equivalent non-null value. - */ - xmString2 = OS.XmStringGenerate (new byte[1], null, OS.XmCHARSET_TEXT, null); - if (xmString2 == 0) error (SWT.ERROR_CANNOT_SET_TEXT); - } - while (j < text.length) text [j++] = 0; - /* Use the character encoding for the default locale */ - byte [] buffer1 = Converter.wcsToMbcs (null, text, true); - int xmString1 = OS.XmStringParseText ( - buffer1, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - if (xmString1 == 0) error (SWT.ERROR_CANNOT_SET_TEXT); - if (mnemonic == 0) mnemonic = OS.XK_VoidSymbol; - int [] argList = { - OS.XmNlabelString, xmString1, - OS.XmNmnemonic, mnemonic, - OS.XmNacceleratorText, xmString2, - }; - OS.XtSetValues (handle, argList, argList.length / 2); - if (xmString1 != 0) OS.XmStringFree (xmString1); - if (xmString2 != 0) OS.XmStringFree (xmString2); -} -boolean translateAccelerator (int accel, boolean doit) { - if (!getEnabled ()) return false; - if (menu != null) return menu.translateAccelerator (accel, doit); - int accelerator = this.accelerator; - if ((accelerator & SWT.KEYCODE_BIT) == 0) { - int key = accelerator & SWT.KEY_MASK; - if ('A' <= key && key <= 'Z') { - key += 'a' - 'A'; - } - int mods = accelerator & SWT.MODIFIER_MASK; - accelerator = mods | key; - } - if (accelerator == accel) { - if (doit) postEvent (SWT.Selection); - return true; - } - return false; -} -int XmNactivateCallback (int w, int client_data, int call_data) { - if ((style & SWT.CASCADE) != 0) { - sendEvent (SWT.Arm); - } - if (!isEnabled ()) return 0; - XmAnyCallbackStruct struct = new XmAnyCallbackStruct (); - OS.memmove (struct, call_data, XmAnyCallbackStruct.sizeof); - Event event = new Event (); - if (struct.event != 0) { - XButtonEvent xEvent = new XButtonEvent (); - OS.memmove (xEvent, struct.event, XButtonEvent.sizeof); - event.time = xEvent.time; - switch (xEvent.type) { - case OS.ButtonPress: - case OS.ButtonRelease: - case OS.KeyPress: - case OS.KeyRelease: - setInputState (event, xEvent.state); - break; - } - } - postEvent (SWT.Selection, event); - return 0; -} -int XmNarmCallback (int w, int client_data, int call_data) { - sendEvent (SWT.Arm); - return 0; -} -int XmNcascadingCallback (int w, int client_data, int call_data) { - /* - * Bug in Motif. When XmNlabelString is set as a result of - * an XmNcascadingCallback after the callback has returned, - * Motif measures the new string properly but does not draw - * it. The fix is to send rather than post the SWT.Arm event. - */ - sendEvent (SWT.Arm); - return 0; -} -int XmNhelpCallback (int w, int client_data, int call_data) { - if (hooks (SWT.Help)) { - postEvent (SWT.Help); - return 0; - } - parent.sendHelpEvent (call_data); - return 0; -} -int XmNvalueChangedCallback (int w, int client_data, int call_data) { - if (!isEnabled ()) return 0; - XmAnyCallbackStruct struct = new XmAnyCallbackStruct (); - OS.memmove (struct, call_data, XmAnyCallbackStruct.sizeof); - Event event = new Event (); - if (struct.event != 0) { - XButtonEvent xEvent = new XButtonEvent (); - OS.memmove (xEvent, struct.event, XButtonEvent.sizeof); - event.time = xEvent.time; - switch (xEvent.type) { - case OS.ButtonPress: - case OS.ButtonRelease: - case OS.KeyPress: - case OS.KeyRelease: - setInputState (event, xEvent.state); - break; - } - } - if ((style & SWT.RADIO) != 0) { - if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) { - selectRadio (); - } - } - postEvent (SWT.Selection, event); - return 0; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java deleted file mode 100755 index a8d37cdb22..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java +++ /dev/null @@ -1,436 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class are used to inform or warn the user. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, ICON_WARNING, ICON_WORKING</dd> - * <dd>OK, OK | CANCEL</dd> - * <dd>YES | NO, YES | NO | CANCEL</dd> - * <dd>RETRY | CANCEL</dd> - * <dd>ABORT | RETRY | IGNORE</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, - * ICON_WARNING and ICON_WORKING may be specified. - * </p><p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample, Dialog tab</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class MessageBox extends Dialog { - int button; - String message = ""; //$NON-NLS-1$ - -/** - * Constructs a new instance of this class given only its parent. - * - * @param parent a shell which will be the parent of the new instance - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - */ -public MessageBox (Shell parent) { - this (parent, SWT.OK | SWT.ICON_INFORMATION | SWT.APPLICATION_MODAL); -} - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * - * @param parent a shell which will be the parent of the new instance - * @param style the style of dialog to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#ICON_ERROR - * @see SWT#ICON_INFORMATION - * @see SWT#ICON_QUESTION - * @see SWT#ICON_WARNING - * @see SWT#ICON_WORKING - * @see SWT#OK - * @see SWT#CANCEL - * @see SWT#YES - * @see SWT#NO - * @see SWT#ABORT - * @see SWT#RETRY - * @see SWT#IGNORE - */ -public MessageBox (Shell parent, int style) { - super (parent, checkStyle (parent, checkStyle (style))); - checkSubclass (); -} -int activate (int widget, int client, int call) { - OS.XtUnmanageChild (widget); - button = client; - return 0; -} -static int checkStyle (int style) { - int mask = (SWT.YES | SWT.NO | SWT.OK | SWT.CANCEL | SWT.ABORT | SWT.RETRY | SWT.IGNORE); - int bits = style & mask; - if (bits == SWT.OK || bits == SWT.CANCEL || bits == (SWT.OK | SWT.CANCEL)) return style; - if (bits == SWT.YES || bits == SWT.NO || bits == (SWT.YES | SWT.NO) || bits == (SWT.YES | SWT.NO | SWT.CANCEL)) return style; - if (bits == (SWT.RETRY | SWT.CANCEL) || bits == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) return style; - style = (style & ~mask) | SWT.OK; - return style; -} -int createHandle (int parentHandle, int [] argList) { - if ((style & SWT.ICON_ERROR) != 0) return OS.XmCreateErrorDialog (parentHandle, null, argList, argList.length / 2); - if ((style & SWT.ICON_INFORMATION) != 0) return OS.XmCreateInformationDialog (parentHandle, null, argList, argList.length / 2); - if ((style & SWT.ICON_QUESTION) != 0) return OS.XmCreateQuestionDialog (parentHandle, null, argList, argList.length / 2); - if ((style & SWT.ICON_WARNING) != 0) return OS.XmCreateWarningDialog (parentHandle, null, argList, argList.length / 2); - if ((style & SWT.ICON_WORKING) != 0) return OS.XmCreateWorkingDialog (parentHandle, null, argList, argList.length / 2); - return OS.XmCreateMessageDialog (parentHandle, null, argList, argList.length / 2); -} - -/** - * Returns the dialog's message, or an empty string if it does not have one. - * The message is a description of the purpose for which the dialog was opened. - * This message will be visible in the dialog while it is open. - * - * @return the message - */ -public String getMessage () { - return message; -} - -/** - * Makes the dialog visible and brings it to the front - * of the display. - * - * @return the ID of the button that was selected to dismiss the - * message box (e.g. SWT.OK, SWT.CANCEL, etc.) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li> - * </ul> - */ -public int open () { - /* Compute the dialog title */ - /* - * Feature in Motif. It is not possible to set a shell - * title to an empty string. The fix is to set the title - * to be a single space. - */ - String string = title; - if (string.length () == 0) string = " "; //$NON-NLS-1$ - /* Use the character encoding for the default locale */ - byte [] buffer = Converter.wcsToMbcs (null, string, true); - int xmStringPtr = OS.XmStringParseText ( - buffer, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - /* - * Feature in Motif. The modal values are only hints - * to the window manager. For example Enlightenment treats all modes - * as SWT.APPLICATION_MODAL. The generic Motif - * Window Manager honours all modes. - */ - int dialogStyle = OS.XmDIALOG_MODELESS; - if ((style & SWT.PRIMARY_MODAL) != 0) dialogStyle = OS.XmDIALOG_PRIMARY_APPLICATION_MODAL; - if ((style & SWT.APPLICATION_MODAL) != 0) dialogStyle = OS.XmDIALOG_FULL_APPLICATION_MODAL; - if ((style & SWT.SYSTEM_MODAL) != 0) dialogStyle = OS.XmDIALOG_SYSTEM_MODAL; - if (dialogStyle == OS.XmDIALOG_MODELESS) { - dialogStyle = OS.XmDIALOG_PRIMARY_APPLICATION_MODAL; - } - boolean defaultPos = parent.isVisible (); - int [] argList = { - OS.XmNnoResize, 1, - OS.XmNresizePolicy, OS.XmRESIZE_NONE, - OS.XmNdialogStyle, dialogStyle, - OS.XmNdialogTitle, xmStringPtr, - OS.XmNdefaultPosition, defaultPos ? 1 : 0, - }; - int parentHandle = parent.shellHandle; - int dialog = createHandle (parentHandle, argList); - if (dialog == 0) error (SWT.ERROR_NO_HANDLES); - OS.XmStringFree (xmStringPtr); - setMessage (dialog); - setButtons (dialog); - - /* Hook the callbacks. */ - Callback callback = new Callback (this, "activate", 3); //$NON-NLS-1$ - int address = callback.getAddress (); - if (address == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - OS.XtAddCallback (dialog, OS.XmNokCallback, address, OS.XmDIALOG_OK_BUTTON); - OS.XtAddCallback (dialog, OS.XmNcancelCallback, address, OS.XmDIALOG_CANCEL_BUTTON); - OS.XtAddCallback (dialog, OS.XmNhelpCallback, address, OS.XmDIALOG_HELP_BUTTON); - - /* Open the dialog and dispatch events. */ - if (!defaultPos) { - OS.XtRealizeWidget (dialog); - int[] argList1 = new int[] { - OS.XmNwidth, 0, - OS.XmNheight, 0, - }; - OS.XtGetValues (dialog, argList1, argList1.length / 2); - Monitor monitor = parent.getMonitor (); - Rectangle bounds = monitor.getBounds (); - int x = bounds.x + (bounds.width - argList1 [1]) / 2; - int y = bounds.y + (bounds.height - argList1 [3]) / 2; - int[] argList2 = new int[] { - OS.XmNx, x, - OS.XmNy, y, - }; - OS.XtSetValues (dialog, argList2, argList2.length / 2); - } - OS.XtManageChild (dialog); - - // Should be a pure OS message loop (no SWT AppContext) - Display display = parent.display; - while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog)) - if (!display.readAndDispatch()) display.sleep (); - - /* Destroy the dialog and update the display. */ - if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog); - callback.dispose (); - - if ((style & (SWT.YES | SWT.NO | SWT.CANCEL)) == (SWT.YES | SWT.NO | SWT.CANCEL)) { - if (button == OS.XmDIALOG_OK_BUTTON) return SWT.YES; - if (button == OS.XmDIALOG_CANCEL_BUTTON) return SWT.NO; - return SWT.CANCEL; - } - if ((style & (SWT.YES | SWT.NO)) == (SWT.YES | SWT.NO)) { - return (button == OS.XmDIALOG_OK_BUTTON) ? SWT.YES : SWT.NO; - } - if ((style & (SWT.OK | SWT.CANCEL)) == (SWT.OK | SWT.CANCEL)) { - return (button == OS.XmDIALOG_OK_BUTTON) ? SWT.OK : SWT.CANCEL; - } - if ((style & SWT.OK) == SWT.OK) return SWT.OK; - if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) { - return (button == OS.XmDIALOG_OK_BUTTON) ? SWT.RETRY : SWT.CANCEL; - } - if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) { - if (button == OS.XmDIALOG_OK_BUTTON) return SWT.ABORT; - if (button == OS.XmDIALOG_CANCEL_BUTTON) return SWT.RETRY; - return SWT.IGNORE; - } - return SWT.CANCEL; -} -void setButtons (int dialogHandle) { - - /* Get the button children */ - OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_OK_BUTTON); - int cancel = OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_CANCEL_BUTTON); - int help = OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_HELP_BUTTON); - OS.XtUnmanageChild (help); - - /* Set the button labels */ - if ((style & (SWT.OK | SWT.CANCEL)) == (SWT.OK | SWT.CANCEL)) return; - if ((style & SWT.OK) == SWT.OK) { - OS.XtUnmanageChild (cancel); - return; - } - if ((style & (SWT.YES | SWT.NO | SWT.CANCEL)) == (SWT.YES | SWT.NO | SWT.CANCEL)) { - OS.XtManageChild (help); - /* Use the character encoding for the default locale */ - byte [] buffer1 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Yes"), true); //$NON-NLS-1$ - int xmString1 = OS.XmStringParseText ( - buffer1, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - /* Use the character encoding for the default locale */ - byte [] buffer2 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_No"), true); //$NON-NLS-1$ - int xmString2 = OS.XmStringParseText ( - buffer2, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - /* Use the character encoding for the default locale */ - byte [] buffer3 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Cancel"), true); //$NON-NLS-1$ - int xmString3 = OS.XmStringParseText ( - buffer3, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2, OS.XmNhelpLabelString, xmString3}; - OS.XtSetValues (dialogHandle, argList, argList.length / 2); - OS.XmStringFree (xmString1); OS.XmStringFree (xmString2); OS.XmStringFree (xmString3); - return; - } - if ((style & (SWT.YES | SWT.NO)) == (SWT.YES | SWT.NO)) { - /* Use the character encoding for the default locale */ - byte [] buffer1 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Yes"), true); //$NON-NLS-1$ - int xmString1 = OS.XmStringParseText ( - buffer1, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - /* Use the character encoding for the default locale */ - byte [] buffer2 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_No"), true); //$NON-NLS-1$ - int xmString2 = OS.XmStringParseText ( - buffer2, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2}; - OS.XtSetValues (dialogHandle, argList, argList.length / 2); - OS.XmStringFree (xmString1); OS.XmStringFree (xmString2); - return; - } - if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) { - /* Use the character encoding for the default locale */ - byte [] buffer1 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Retry"), true); //$NON-NLS-1$ - int xmString1 = OS.XmStringParseText ( - buffer1, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - /* Use the character encoding for the default locale */ - byte [] buffer2 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Cancel"), true); //$NON-NLS-1$ - int xmString2 = OS.XmStringParseText ( - buffer2, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2}; - OS.XtSetValues (dialogHandle, argList, argList.length / 2); - OS.XmStringFree (xmString1); OS.XmStringFree (xmString2); - return; - } - if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) { - OS.XtManageChild (help); - /* Use the character encoding for the default locale */ - byte [] buffer1 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Abort"), true); //$NON-NLS-1$ - int xmString1 = OS.XmStringParseText ( - buffer1, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - /* Use the character encoding for the default locale */ - byte [] buffer2 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Retry"), true); //$NON-NLS-1$ - int xmString2 = OS.XmStringParseText ( - buffer2, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - /* Use the character encoding for the default locale */ - byte [] buffer3 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Ignore"), true); //$NON-NLS-1$ - int xmString3 = OS.XmStringParseText ( - buffer3, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2, OS.XmNhelpLabelString, xmString3}; - OS.XtSetValues (dialogHandle, argList, argList.length / 2); - OS.XmStringFree (xmString1); OS.XmStringFree (xmString2); OS.XmStringFree (xmString3); - return; - } -} -void setMessage (int dialogHandle) { - String text = message; - int label = OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_MESSAGE_LABEL); - if (label != 0) { - int [] argList = {OS.XmNfontList, 0}; - OS.XtGetValues (label, argList, argList.length / 2); - int fontList = argList [1]; - if (fontList != 0) { - Display display = parent.display; - int xDisplay = display.xDisplay; - int screen = OS.XDefaultScreen (xDisplay); - int width = OS.XDisplayWidth (xDisplay, screen); - Font font = Font.motif_new (display, fontList); - text = display.wrapText (message, font, width * 3 / 5); - } - } - /* Use the character encoding for the default locale */ - byte [] buffer = Converter.wcsToMbcs (null, text, true); - int xmString = OS.XmStringGenerate(buffer, null, OS.XmCHARSET_TEXT, null); - int [] argList = {OS.XmNmessageString, xmString}; - OS.XtSetValues (dialogHandle, argList, argList.length / 2); - OS.XmStringFree (xmString); -} - -/** - * Sets the dialog's message, which is a description of - * the purpose for which it was opened. This message will be - * visible on the dialog while it is open. - * - * @param string the message - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - */ -public void setMessage (String string) { - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - message = string; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java deleted file mode 100755 index e537ea4a53..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java +++ /dev/null @@ -1,422 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of the receiver represent an unselectable - * user interface object that is used to display progress, - * typically in the form of a bar. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>SMOOTH, HORIZONTAL, VERTICAL, INDETERMINATE</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. - * </p><p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#progressbar">ProgressBar snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class ProgressBar extends Control { - int timerId; - static final int DELAY = 100; - int foreground; - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#SMOOTH - * @see SWT#HORIZONTAL - * @see SWT#VERTICAL - * @see SWT#INDETERMINATE - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public ProgressBar (Composite parent, int style) { - /* - * Feature in Motif. If you set the progress bar's value to 0, - * the thumb does not disappear. In order to make this happen, - * we hide the widget when the value is set to zero by changing - * its colors to render it invisible, which means that it - * would not visible unless a border is present. The fix is to - * always ensure that there is a border, which will be drawn - * even when the value is 0. - */ - super (parent, checkStyle (style | SWT.BORDER)); -} -static int checkStyle (int style) { - style |= SWT.NO_FOCUS; - return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - int border = getBorderWidth (); - int width = border * 2, height = border * 2; - int hScroll = display.scrolledMarginX; - int vScroll = display.scrolledMarginY; - if ((style & SWT.HORIZONTAL) != 0) { - width += hScroll * 10; - height += vScroll; - } else { - width += hScroll; - height += vScroll * 10; - } - if (wHint != SWT.DEFAULT) width = wHint + (border * 2); - if (hHint != SWT.DEFAULT) height = hHint + (border * 2); - return new Point (width, height); -} -void createHandle (int index) { - int background = defaultBackground (); - int parentHandle = parent.handle; - int [] argList = { - OS.XmNshowArrows, 0, - OS.XmNsliderSize, 1, - OS.XmNtraversalOn, 0, - OS.XmNtroughColor, background, - OS.XmNtopShadowColor, background, - OS.XmNbottomShadowColor, background, - OS.XmNforeground, background, - OS.XmNshadowThickness, 1, - OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0, - OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL, - OS.XmNprocessingDirection, ((style & SWT.H_SCROLL) != 0) ? OS.XmMAX_ON_RIGHT : OS.XmMAX_ON_TOP, - OS.XmNancestorSensitive, 1, - OS.XmNsliderVisual, OS.XmFOREGROUND_COLOR, - }; - handle = OS.XmCreateScrollBar (parentHandle, null, argList, argList.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - if ((style & SWT.INDETERMINATE) != 0) createTimer (); -} -void createWidget (int index) { - super.createWidget (index); - foreground = defaultForeground (); -} -void createTimer () { - int xDisplay = display.xDisplay; - int windowTimerProc = display.windowTimerProc; - int xtContext = OS.XtDisplayToApplicationContext (xDisplay); - timerId = OS.XtAppAddTimeOut (xtContext, DELAY, windowTimerProc, handle); -} -void destroyTimer () { - if (timerId != 0) OS.XtRemoveTimeOut (timerId); - timerId = 0; -} -int getForegroundPixel () { - return foreground == -1 ? super.getForegroundPixel () : foreground; -} -/** - * Returns the maximum value which the receiver will allow. - * - * @return the maximum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getMaximum () { - checkWidget(); - int [] argList = {OS.XmNmaximum, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the minimum value which the receiver will allow. - * - * @return the minimum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getMinimum () { - checkWidget(); - int [] argList = {OS.XmNminimum, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the single 'selection' that is the receiver's position. - * - * @return the selection - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getSelection () { - checkWidget(); - int [] argList = { - OS.XmNminimum, 0, - OS.XmNsliderSize, 0, - }; - OS.XtGetValues (handle, argList, argList.length / 2); - int minimum = argList [1], sliderSize = argList [3]; - return minimum + (foreground != -1 ? 0 : sliderSize); -} -/** - * Returns the state of the receiver. The value will be one of: - * <ul> - * <li>{@link SWT#NORMAL}</li> - * <li>{@link SWT#ERROR}</li> - * <li>{@link SWT#PAUSED}</li> - * </ul> - * - * @return the state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.4 - */ -public int getState () { - checkWidget (); - return SWT.NORMAL; -} -void releaseWidget () { - super.releaseWidget (); - destroyTimer (); -} -void setBackgroundPixel (int pixel) { - checkWidget(); - super.setBackgroundPixel (pixel); - if (foreground != -1) super.setForegroundPixel (pixel); -} -void setForegroundPixel (int pixel) { - checkWidget(); - if (foreground == -1) { - super.setForegroundPixel (pixel); - } else { - foreground = pixel; - } -} -/** - * Sets the maximum value that the receiver will allow. This new - * value will be ignored if it is not greater than the receiver's current - * minimum value. If the new maximum is applied then the receiver's - * selection value will be adjusted if necessary to fall within its new range. - * - * @param value the new maximum, which must be greater than the current minimum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMaximum (int value) { - checkWidget(); - if (value < 0) return; - int [] argList = {OS.XmNmaximum, value, OS.XmNvalue, 0}; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XtSetValues (handle, argList, argList.length / 2); - display.setWarnings (warnings); -} -/** - * Sets the minimum value that the receiver will allow. This new - * value will be ignored if it is negative or is not less than the receiver's - * current maximum value. If the new minimum is applied then the receiver's - * selection value will be adjusted if necessary to fall within its new range. - * - * @param value the new minimum, which must be nonnegative and less than the current maximum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMinimum (int value) { - checkWidget(); - if (value < 0) return; - int [] argList = { - OS.XmNminimum, 0, - OS.XmNmaximum, 0, - OS.XmNsliderSize, 0, - OS.XmNvalue, 0, - }; - OS.XtGetValues (handle, argList, argList.length / 2); - int minimum = argList [1]; - int maximum = argList [3]; - int sliderSize = argList [5]; - - if (value >= maximum) return; - int selection = sliderSize + minimum; - if (value > selection) selection = value; - argList [1] = value; - argList [7] = value; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XtSetValues (handle, argList, argList.length / 2); - display.setWarnings (warnings); - setThumb(selection - value); -} -/** - * Sets the single 'selection' that is the receiver's - * position to the argument which must be greater than or equal - * to zero. - * - * @param value the new selection (must be zero or greater) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (int value) { - checkWidget(); - int [] argList = { - OS.XmNminimum, 0, - OS.XmNmaximum, 0, - }; - OS.XtGetValues (handle, argList, argList.length / 2); - int minimum = argList [1]; - int maximum = argList [3]; - - int selection = value; - if (selection < minimum) selection = minimum; - if (selection > maximum) selection = maximum; - setThumb(selection - minimum); - update (); -} -/** - * Sets the state of the receiver. The state must be one of these values: - * <ul> - * <li>{@link SWT#NORMAL}</li> - * <li>{@link SWT#ERROR}</li> - * <li>{@link SWT#PAUSED}</li> - * </ul> - * - * @param state the new state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.4 - */ -public void setState (int state) { - checkWidget (); - //NOT IMPLEMENTED -} -void setThumb (int sliderSize) { - int [] argList1 = new int [] { - OS.XmNtroughColor, 0, - OS.XmNminimum, 0, - }; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int troughColor = argList1 [1]; - if (sliderSize == 0) { - if (foreground == -1) { - foreground = getForegroundPixel (); - super.setForegroundPixel (troughColor); - } - } else { - if (foreground != -1) { - super.setForegroundPixel (foreground); - foreground = -1; - } - } - int [] argList2 = new int [] { - OS.XmNsliderSize, sliderSize == 0 ? 1 : sliderSize, - OS.XmNvalue, argList1 [3] - }; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XtSetValues (handle, argList2, argList2.length / 2); - display.setWarnings (warnings); -} -int timerProc (int id) { - int minimum = getMinimum (); - int range = getMaximum () - minimum + 1; - int value = getSelection () - minimum + 1; - setSelection (minimum + (value % range)); - createTimer (); - return 0; -} -int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XButtonPress (w, client_data, call_data, continue_to_dispatch); - int [] argList = {OS.XmNsensitive, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (argList [1] != 0) { - OS.memmove (continue_to_dispatch, new int [1], 4); - return 1; - } - return result; -} -int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XButtonRelease (w, client_data, call_data, continue_to_dispatch); - int [] argList = {OS.XmNsensitive, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (argList [1] != 0) { - OS.memmove (continue_to_dispatch, new int [1], 4); - return 1; - } - return result; -} -int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XKeyPress (w, client_data, call_data, continue_to_dispatch); - int [] argList = {OS.XmNsensitive, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (argList [1] != 0) { - OS.memmove (continue_to_dispatch, new int [1], 4); - return 1; - } - return result; -} -int XKeyRelease (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XKeyRelease (w, client_data, call_data, continue_to_dispatch); - int [] argList = {OS.XmNsensitive, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (argList [1] != 0) { - OS.memmove (continue_to_dispatch, new int [1], 4); - return 1; - } - return result; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java deleted file mode 100755 index 711f9c34b5..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java +++ /dev/null @@ -1,446 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Instances of the receiver represent a selectable user interface object - * that allows the user to drag a rubber banded outline of the sash within - * the parent control. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>HORIZONTAL, VERTICAL, SMOOTH</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection</dd> - * </dl> - * <p> - * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. - * </p><p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#sash">Sash snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class Sash extends Control { - boolean dragging; - int startX, startY, lastX, lastY; - int cursor; - private final static int INCREMENT = 1; - private final static int PAGE_INCREMENT = 9; - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#HORIZONTAL - * @see SWT#VERTICAL - * @see SWT#SMOOTH - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Sash (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the control is selected by the user, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * When <code>widgetSelected</code> is called, the x, y, width, and height fields of the event object are valid. - * If the receiver is being dragged, the event object detail field contains the value <code>SWT.DRAG</code>. - * <code>widgetDefaultSelected</code> is not called. - * </p> - * - * @param listener the listener which should be notified when the control is selected by the user - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener(listener); - addListener(SWT.Selection,typedListener); - addListener(SWT.DefaultSelection,typedListener); -} -static int checkStyle (int style) { - return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - int border = getBorderWidth (); - int width = border * 2, height = border * 2; - if ((style & SWT.HORIZONTAL) != 0) { - width += DEFAULT_WIDTH; height += 3; - } else { - width += 3; height += DEFAULT_HEIGHT; - } - if (wHint != SWT.DEFAULT) width = wHint + (border * 2); - if (hHint != SWT.DEFAULT) height = hHint + (border * 2); - return new Point (width, height); -} -void createHandle (int index) { - state |= THEME_BACKGROUND; - int border = (style & SWT.BORDER) != 0 ? 1 : 0; - int [] argList = { - OS.XmNborderWidth, border, - OS.XmNmarginWidth, 0, - OS.XmNmarginHeight, 0, - OS.XmNresizePolicy, OS.XmRESIZE_NONE, - OS.XmNancestorSensitive, 1, - OS.XmNtraversalOn, 0, - }; - int parentHandle = parent.handle; - handle = OS.XmCreateDrawingArea (parentHandle, null, argList, argList.length / 2); -} -void drawBand (int x, int y, int width, int height) { - if ((style & SWT.SMOOTH) != 0) return; - int display = OS.XtDisplay (parent.handle); - if (display == 0) return; - int window = OS.XtWindow (parent.handle); - if (window == 0) return; - int foreground = parent.getForegroundPixel (); - Control control = parent.findBackgroundControl (); - if (control == null) control = parent; - int background = control.getBackgroundPixel (); - int color = foreground ^ background; - byte [] bits = {-86, 85, -86, 85, -86, 85, -86, 85}; - int stipplePixmap = OS.XCreateBitmapFromData (display, window, bits, 8, 8); - int gc = OS.XCreateGC (display, window, 0, null); - OS.XSetForeground (display, gc, color); - OS.XSetStipple (display, gc, stipplePixmap); - OS.XSetSubwindowMode (display, gc, OS.IncludeInferiors); - OS.XSetFillStyle (display, gc, OS.FillStippled); - OS.XSetFunction (display, gc, OS.GXxor); - OS.XFillRectangle (display, window, gc, x, y, width, height); - OS.XFreePixmap (display, stipplePixmap); - OS.XFreeGC (display, gc); -} -void propagateWidget (boolean enabled) { - int xCursor = enabled && super.cursor != null ? super.cursor.handle : cursor; - propagateHandle (enabled, handle, xCursor); -} -void realizeChildren () { - super.realizeChildren (); - int xWindow = OS.XtWindow (handle); - if (xWindow == 0) return; - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - if ((style & SWT.HORIZONTAL) != 0) { - cursor = OS.XCreateFontCursor (xDisplay, OS.XC_sb_v_double_arrow); - } else { - cursor = OS.XCreateFontCursor (xDisplay, OS.XC_sb_h_double_arrow); - } - if (super.cursor == null && isEnabled ()) { - OS.XDefineCursor (xDisplay, xWindow, cursor); - OS.XFlush (xDisplay); - } -} -void releaseWidget () { - super.releaseWidget (); - if (cursor != 0) { - int display = OS.XtDisplay (handle); - if (display != 0) OS.XFreeCursor (display, cursor); - } - cursor = 0; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is selected by the user. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.Selection, listener); - eventTable.unhook(SWT.DefaultSelection,listener); -} -public void setCursor (Cursor cursor) { - checkWidget(); - super.setCursor (cursor); - if (cursor == null && this.cursor != 0) { - int xWindow = OS.XtWindow (handle); - if (xWindow == 0) return; - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - OS.XDefineCursor (xDisplay, xWindow, this.cursor); - OS.XFlush (xDisplay); - } -} -public boolean setFocus () { - checkWidget(); - return forceFocus (); -} -int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XButtonPress (w, client_data, call_data, continue_to_dispatch); - if (result != 0) return result; - XButtonEvent xEvent = new XButtonEvent (); - OS.memmove (xEvent, call_data, XButtonEvent.sizeof); - if (xEvent.button != 1) return result; - short [] x_root = new short [1], y_root = new short [1]; - OS.XtTranslateCoords (handle, (short) 0, (short) 0, x_root, y_root); - startX = xEvent.x_root - x_root [0]; - startY = xEvent.y_root - y_root [0]; - int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int border = argList [9], width = argList [5] + (border * 2), height = argList [7] + (border * 2); - lastX = ((short) argList [1]) - border; lastY = ((short) argList [3]) - border; - Event event = new Event (); - event.time = xEvent.time; - event.x = lastX; - event.y = lastY; - event.width = width; - event.height = height; - if ((style & SWT.SMOOTH) == 0) { - event.detail = SWT.DRAG; - } - sendEvent (SWT.Selection, event); - if (isDisposed ()) return result; - if (event.doit) { - dragging = true; - lastX = event.x; - lastY = event.y; - parent.update (true); - drawBand (event.x, event.y, width, height); - if ((style & SWT.SMOOTH) != 0) { - setBounds (event.x, event.y, width, height); - // widget could be disposed at this point - } - } - return result; -} -int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XButtonRelease (w, client_data, call_data, continue_to_dispatch); - if (result != 0) return result; - XButtonEvent xEvent = new XButtonEvent (); - OS.memmove (xEvent, call_data, XButtonEvent.sizeof); - if (xEvent.button != 1) return result; - if (!dragging) return result; - dragging = false; - int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int border = argList [5]; - int width = argList [1] + (border * 2), height = argList [3] + (border * 2); - Event event = new Event (); - event.time = xEvent.time; - event.x = lastX; - event.y = lastY; - event.width = width; - event.height = height; - drawBand (lastX, lastY, width, height); - sendEvent (SWT.Selection, event); - if (isDisposed ()) return result; - if (event.doit) { - if ((style & SWT.SMOOTH) != 0) { - setBounds (event.x, event.y, width, height); - // widget could be disposed at this point - } - } - return result; -} -int xFocusIn (XFocusChangeEvent xEvent) { - int result = super.xFocusIn (xEvent); - if (handle == 0) return result; - int [] argList = {OS.XmNx, 0, OS.XmNy, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - lastX = argList [1]; - lastY = argList [3]; - return result; -} -int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XKeyPress (w, client_data, call_data, continue_to_dispatch); - if (result != 0) return result; - XKeyEvent xEvent = new XKeyEvent (); - OS.memmove (xEvent, call_data, XKeyEvent.sizeof); - byte [] buffer = new byte [1]; - int [] keysym = new int [1]; - OS.XLookupString (xEvent, buffer, buffer.length, keysym, null); - - switch (keysym [0]) { - case OS.XK_Left: - case OS.XK_Right: - case OS.XK_Up: - case OS.XK_Down: - int xChange = 0, yChange = 0; - int stepSize = PAGE_INCREMENT; - if ((xEvent.state & OS.ControlMask) != 0) stepSize = INCREMENT; - if ((style & SWT.VERTICAL) != 0) { - if (keysym [0] == OS.XK_Up || keysym [0] == OS.XK_Down) break; - xChange = keysym [0] == OS.XK_Left ? -stepSize : stepSize; - } else { - if (keysym [0] == OS.XK_Left || keysym [0] == OS.XK_Right) break; - yChange = keysym [0] == OS.XK_Up ? -stepSize : stepSize; - } - - int [] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int border = argList1 [5]; - int width = argList1 [1] + (border * 2), height = argList1 [3] + (border * 2); - int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - OS.XtGetValues (parent.handle, argList2, argList2.length / 2); - int parentBorder = argList2 [5]; - int parentWidth = argList2 [1] + (parentBorder * 2); - int parentHeight = argList2 [3] + (parentBorder * 2); - int newX = lastX, newY = lastY; - if ((style & SWT.VERTICAL) != 0) { - newX = Math.min (Math.max (0, lastX + xChange - parentBorder - startX), parentWidth - width); - } else { - newY = Math.min (Math.max (0, lastY + yChange - parentBorder - startY), parentHeight - height); - } - if (newX == lastX && newY == lastY) return result; - - /* Ensure that the pointer image does not change */ - int xDisplay = display.xDisplay; - int xWindow = OS.XtWindow (parent.handle); - int ptrGrabResult = OS.XGrabPointer ( - xDisplay, - xWindow, - 1, - OS.None, - OS.GrabModeAsync, - OS.GrabModeAsync, - OS.None, - cursor, - OS.CurrentTime); - - Event event = new Event (); - event.time = xEvent.time; - event.x = newX; - event.y = newY; - event.width = width; - event.height = height; - sendEvent (SWT.Selection, event); - if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime); - if (isDisposed ()) break; - - if (event.doit) { - lastX = event.x; - lastY = event.y; - if ((style & SWT.SMOOTH) != 0) { - setBounds (event.x, event.y, width, height); - if (isDisposed ()) break; - } - int cursorX = event.x, cursorY = event.y; - if ((style & SWT.VERTICAL) != 0) { - cursorY += height / 2; - } else { - cursorX += width / 2; - } - OS.XWarpPointer (xDisplay, OS.None, xWindow, 0, 0, 0, 0, cursorX, cursorY); - } - break; - } - - return result; -} -int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XPointerMotion (w, client_data, call_data, continue_to_dispatch); - if (result != 0) return result; - XMotionEvent xEvent = new XMotionEvent (); - OS.memmove (xEvent, call_data, XMotionEvent.sizeof); - if (!dragging || (xEvent.state & OS.Button1Mask) == 0) return result; - short [] x_root = new short [1], y_root = new short [1]; - OS.XtTranslateCoords (handle, (short) 0, (short) 0, x_root, y_root); - int eventX = xEvent.x_root - x_root [0], eventY = xEvent.y_root - y_root [0]; - int [] argList1 = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int border = argList1 [9], x = ((short) argList1 [1]) - border, y = ((short) argList1 [3]) - border; - int width = argList1 [5] + (border * 2), height = argList1 [7] + (border * 2); - int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - OS.XtGetValues (parent.handle, argList2, argList2.length / 2); - int parentBorder = argList2 [5]; - int parentWidth = argList2 [1] + (parentBorder * 2); - int parentHeight = argList2 [3] + (parentBorder * 2); - int newX = lastX, newY = lastY; - if ((style & SWT.VERTICAL) != 0) { - newX = Math.min (Math.max (0, eventX + x - startX - parentBorder), parentWidth - width); - } else { - newY = Math.min (Math.max (0, eventY + y - startY - parentBorder), parentHeight - height); - } - if (newX == lastX && newY == lastY) return result; - drawBand (lastX, lastY, width, height); - Event event = new Event (); - event.time = xEvent.time; - event.x = newX; - event.y = newY; - event.width = width; - event.height = height; - if ((style & SWT.SMOOTH) == 0) { - event.detail = SWT.DRAG; - } - sendEvent (SWT.Selection, event); - if (isDisposed ()) return result; - if (event.doit) { - lastX = event.x; - lastY = event.y; - } - parent.update (true); - drawBand (lastX, lastY, width, height); - if ((style & SWT.SMOOTH) != 0) { - setBounds (lastX, lastY, width, height); - // widget could be disposed at this point - } - return result; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java deleted file mode 100755 index bd9f4ef40d..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java +++ /dev/null @@ -1,385 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of the receiver represent a selectable user - * interface object that present a range of continuous - * numeric values. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>HORIZONTAL, VERTICAL</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection</dd> - * </dl> - * <p> - * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. - * </p><p> - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#scale">Scale snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class Scale extends Control { - int scrollHandle; - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#HORIZONTAL - * @see SWT#VERTICAL - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Scale (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the user changes the receiver's value, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * <code>widgetSelected</code> is called when the user changes the receiver's value. - * <code>widgetDefaultSelected</code> is not called. - * </p> - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener(listener); - addListener(SWT.Selection,typedListener); - addListener(SWT.DefaultSelection,typedListener); -} -static int checkStyle (int style) { - return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - int border = getBorderWidth (); - int width = border * 2, height = border * 2; - int hScroll = display.scrolledMarginX; - int vScroll = display.scrolledMarginY; - if ((style & SWT.HORIZONTAL) != 0) { - width += hScroll * 10; - height += vScroll; - } else { - width += hScroll; - height += vScroll * 10; - } - if (wHint != SWT.DEFAULT) width = wHint + (border * 2); - if (hHint != SWT.DEFAULT) height = hHint + (border * 2); - return new Point (width, height); -} -void createHandle (int index) { - state |= THEME_BACKGROUND; - int [] argList = { - OS.XmNtitleString, 0, - OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0, - OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL, - OS.XmNprocessingDirection, ((style & SWT.H_SCROLL) != 0) ? OS.XmMAX_ON_RIGHT : OS.XmMAX_ON_BOTTOM, - OS.XmNancestorSensitive, 1, - }; - int parentHandle = parent.handle; - handle = OS.XmCreateScale (parentHandle, null, argList, argList.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - byte[] scrollbar = Converter.wcsToMbcs (null, "Scrollbar\0"); - scrollHandle = OS.XtNameToWidget (handle, scrollbar); -} -void deregister () { - super.deregister (); - if (scrollHandle != 0) display.removeWidget (scrollHandle); -} -/** - * Returns the amount that the receiver's value will be - * modified by when the up/down (or right/left) arrows - * are pressed. - * - * @return the increment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getIncrement () { - checkWidget(); - return 1; -} -/** - * Returns the maximum value which the receiver will allow. - * - * @return the maximum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getMaximum () { - checkWidget(); - int [] argList = {OS.XmNmaximum, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the minimum value which the receiver will allow. - * - * @return the minimum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getMinimum () { - checkWidget(); - int [] argList = {OS.XmNminimum, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the amount that the receiver's value will be - * modified by when the page increment/decrement areas - * are selected. - * - * @return the page increment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getPageIncrement () { - checkWidget(); - int [] argList = {OS.XmNscaleMultiple, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the 'selection', which is the receiver's position. - * - * @return the selection - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getSelection () { - checkWidget(); - int [] argList = {OS.XmNvalue, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -void hookEvents () { - super.hookEvents (); - int windowProc = display.windowProc; - OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK); - OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, DRAG_CALLBACK); - if (scrollHandle != 0) { - OS.XtAddEventHandler (scrollHandle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS); - OS.XtAddEventHandler (scrollHandle, OS.ButtonReleaseMask, false, windowProc, BUTTON_RELEASE); - OS.XtAddEventHandler (scrollHandle, OS.EnterWindowMask, false, windowProc, ENTER_WINDOW); - OS.XtAddEventHandler (scrollHandle, OS.LeaveWindowMask, false, windowProc, LEAVE_WINDOW); - OS.XtAddEventHandler (scrollHandle, OS.KeyPressMask, false, windowProc, KEY_PRESS); - OS.XtAddEventHandler (scrollHandle, OS.KeyReleaseMask, false, windowProc, KEY_RELEASE); - OS.XtInsertEventHandler (scrollHandle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail); - } -} -void overrideTranslations () { - OS.XtOverrideTranslations (handle, display.tabTranslations); -} -void register () { - super.register (); - if (scrollHandle != 0) display.addWidget (scrollHandle, this); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the user changes the receiver's value. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.Selection, listener); - eventTable.unhook(SWT.DefaultSelection,listener); -} -/** - * Sets the amount that the receiver's value will be - * modified by when the up/down (or right/left) arrows - * are pressed to the argument, which must be at least - * one. - * - * @param increment the new increment (must be greater than zero) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setIncrement (int increment) { - checkWidget(); -} -/** - * Sets the maximum value that the receiver will allow. This new - * value will be ignored if it is not greater than the receiver's current - * minimum value. If the new maximum is applied then the receiver's - * selection value will be adjusted if necessary to fall within its new range. - * - * @param value the new maximum, which must be greater than the current minimum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMaximum (int value) { - checkWidget(); - if (value < 0) return; - int [] argList = {OS.XmNmaximum, value}; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XtSetValues (handle, argList, argList.length / 2); - display.setWarnings (warnings); -} -/** - * Sets the minimum value that the receiver will allow. This new - * value will be ignored if it is negative or is not less than the receiver's - * current maximum value. If the new minimum is applied then the receiver's - * selection value will be adjusted if necessary to fall within its new range. - * - * @param value the new minimum, which must be nonnegative and less than the current maximum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMinimum (int value) { - checkWidget(); - if (value < 0) return; - int [] argList = {OS.XmNminimum, value}; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XtSetValues (handle, argList, argList.length / 2); - display.setWarnings (warnings); -} -/** - * Sets the amount that the receiver's value will be - * modified by when the page increment/decrement areas - * are selected to the argument, which must be at least - * one. - * - * @param pageIncrement the page increment (must be greater than zero) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setPageIncrement (int pageIncrement) { - checkWidget(); - if (pageIncrement < 1) return; - int [] argList = {OS.XmNscaleMultiple, pageIncrement}; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XtSetValues (handle, argList, argList.length / 2); - display.setWarnings (warnings); -} -/** - * Sets the 'selection', which is the receiver's value, - * to the argument which must be greater than or equal to zero. - * - * @param value the new selection (must be zero or greater) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (int selection) { - checkWidget(); - int [] argList = {OS.XmNvalue, selection}; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XtSetValues (handle, argList, argList.length / 2); - display.setWarnings (warnings); -} -int XmNdragCallback (int w, int client_data, int call_data) { - postEvent (SWT.Selection); - return 0; -} -int XmNvalueChangedCallback (int w, int client_data, int call_data) { - postEvent (SWT.Selection); - return 0; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java deleted file mode 100755 index f7756ac77a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java +++ /dev/null @@ -1,728 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class are selectable user interface - * objects that represent a range of positive, numeric values. - * <p> - * At any given moment, a given scroll bar will have a - * single 'selection' that is considered to be its - * value, which is constrained to be within the range of - * values the scroll bar represents (that is, between its - * <em>minimum</em> and <em>maximum</em> values). - * </p><p> - * Typically, scroll bars will be made up of five areas: - * <ol> - * <li>an arrow button for decrementing the value</li> - * <li>a page decrement area for decrementing the value by a larger amount</li> - * <li>a <em>thumb</em> for modifying the value by mouse dragging</li> - * <li>a page increment area for incrementing the value by a larger amount</li> - * <li>an arrow button for incrementing the value</li> - * </ol> - * Based on their style, scroll bars are either <code>HORIZONTAL</code> - * (which have a left facing button for decrementing the value and a - * right facing button for incrementing it) or <code>VERTICAL</code> - * (which have an upward facing button for decrementing the value - * and a downward facing buttons for incrementing it). - * </p><p> - * On some platforms, the size of the scroll bar's thumb can be - * varied relative to the magnitude of the range of values it - * represents (that is, relative to the difference between its - * maximum and minimum values). Typically, this is used to - * indicate some proportional value such as the ratio of the - * visible area of a document to the total amount of space that - * it would take to display it. SWT supports setting the thumb - * size even if the underlying platform does not, but in this - * case the appearance of the scroll bar will not change. - * </p><p> - * Scroll bars are created by specifying either <code>H_SCROLL</code>, - * <code>V_SCROLL</code> or both when creating a <code>Scrollable</code>. - * They are accessed from the <code>Scrollable</code> using - * <code>getHorizontalBar</code> and <code>getVerticalBar</code>. - * </p><p> - * Note: Scroll bars are not Controls. On some platforms, scroll bars - * that appear as part of some standard controls such as a text or list - * have no operating system resources and are not children of the control. - * For this reason, scroll bars are treated specially. To create a control - * that looks like a scroll bar but has operating system resources, use - * <code>Slider</code>. - * </p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>HORIZONTAL, VERTICAL</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection</dd> - * </dl> - * <p> - * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see Slider - * @see Scrollable - * @see Scrollable#getHorizontalBar - * @see Scrollable#getVerticalBar - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class ScrollBar extends Widget { - Scrollable parent; - boolean dragSent = false; -ScrollBar () { - /* Do Nothing */ -} -ScrollBar (Scrollable parent, int style) { - super (parent, checkStyle (style)); - this.parent = parent; - createWidget (0); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the user changes the receiver's value, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values: - * <code>SWT.NONE</code> - for the end of a drag. - * <code>SWT.DRAG</code>. - * <code>SWT.HOME</code>. - * <code>SWT.END</code>. - * <code>SWT.ARROW_DOWN</code>. - * <code>SWT.ARROW_UP</code>. - * <code>SWT.PAGE_DOWN</code>. - * <code>SWT.PAGE_UP</code>. - * <code>widgetDefaultSelected</code> is not called. - * </p> - * - * @param listener the listener which should be notified when the user changes the receiver's value - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener(listener); - addListener(SWT.Selection,typedListener); - addListener(SWT.DefaultSelection,typedListener); -} -static int checkStyle (int style) { - return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0); -} -void createHandle (int index) { - int [] argList = { - OS.XmNancestorSensitive, 1, - OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0, - OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL, - OS.XmNtraversalOn, 0, - }; - int parentHandle = parent.scrolledHandle; - handle = OS.XmCreateScrollBar (parentHandle, null, argList, argList.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); -} -void destroyHandle () { - super.destroyWidget (); -} -void destroyWidget () { - parent.destroyScrollBar (this); - releaseHandle (); - //parent.sendEvent (SWT.Resize); -} -/** - * Returns <code>true</code> if the receiver is enabled, and - * <code>false</code> otherwise. A disabled control is typically - * not selectable from the user interface and draws with an - * inactive or "grayed" look. - * - * @return the receiver's enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #isEnabled - */ -public boolean getEnabled () { - checkWidget(); - int [] argList = {OS.XmNsensitive, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1] != 0; -} -/** - * Returns the amount that the receiver's value will be - * modified by when the up/down (or right/left) arrows - * are pressed. - * - * @return the increment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getIncrement () { - checkWidget(); - int [] argList = {OS.XmNincrement, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the maximum value which the receiver will allow. - * - * @return the maximum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getMaximum () { - checkWidget(); - int [] argList = {OS.XmNmaximum, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the minimum value which the receiver will allow. - * - * @return the minimum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getMinimum () { - checkWidget(); - int [] argList = {OS.XmNminimum, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the amount that the receiver's value will be - * modified by when the page increment/decrement areas - * are selected. - * - * @return the page increment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getPageIncrement () { - checkWidget(); - int [] argList = {OS.XmNpageIncrement, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the receiver's parent, which must be a Scrollable. - * - * @return the receiver's parent - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Scrollable getParent () { - checkWidget(); - return parent; -} -/** - * Returns the single 'selection' that is the receiver's value. - * - * @return the selection - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getSelection () { - checkWidget(); - int [] argList = {OS.XmNvalue, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns a point describing the receiver's size. The - * x coordinate of the result is the width of the receiver. - * The y coordinate of the result is the height of the - * receiver. - * - * @return the receiver's size - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Point getSize () { - checkWidget(); - int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int borders = argList [5] * 2; - return new Point (argList [1] + borders, argList [3] + borders); -} -/** - * Returns the size of the receiver's thumb relative to the - * difference between its maximum and minimum values. - * - * @return the thumb value - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ScrollBar - */ -public int getThumb () { - checkWidget(); - int [] argList = {OS.XmNsliderSize, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns <code>true</code> if the receiver is visible, and - * <code>false</code> otherwise. - * <p> - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, this method - * may still indicate that it is considered visible even though - * it may not actually be showing. - * </p> - * - * @return the receiver's visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getVisible () { - checkWidget(); - return OS.XtIsManaged (handle); -} -void hookEvents () { - int windowProc = display.windowProc; - OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK); - OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, DRAG_CALLBACK); - OS.XtAddCallback (handle, OS.XmNtoBottomCallback, windowProc, TO_BOTTOM_CALLBACK); - OS.XtAddCallback (handle, OS.XmNtoTopCallback, windowProc, TO_TOP_CALLBACK); - OS.XtAddCallback (handle, OS.XmNincrementCallback, windowProc, INCREMENT_CALLBACK); - OS.XtAddCallback (handle, OS.XmNdecrementCallback, windowProc, DECREMENT_CALLBACK); - OS.XtAddCallback (handle, OS.XmNpageIncrementCallback, windowProc, PAGE_INCREMENT_CALLBACK); - OS.XtAddCallback (handle, OS.XmNpageDecrementCallback, windowProc, PAGE_DECREMENT_CALLBACK); - OS.XtAddEventHandler (handle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS); -} -/** - * Returns <code>true</code> if the receiver is enabled and all - * of the receiver's ancestors are enabled, and <code>false</code> - * otherwise. A disabled control is typically not selectable from the - * user interface and draws with an inactive or "grayed" look. - * - * @return the receiver's enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getEnabled - */ -public boolean isEnabled () { - checkWidget(); - return getEnabled () && parent.isEnabled (); -} -/** - * Returns <code>true</code> if the receiver is visible and all - * of the receiver's ancestors are visible and <code>false</code> - * otherwise. - * - * @return the receiver's visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getVisible - */ -public boolean isVisible () { - checkWidget(); - return getVisible () && parent.isVisible (); -} -void manageChildren () { - /* - * Feature in Motif. Hiding or showing a scroll bar - * can cause the widget to automatically resize in - * the OS. This behavior is unwanted. The fix is - * to force the widget to resize to original size. - */ - int scrolledHandle = parent.scrolledHandle; - int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - if (scrolledHandle != 0) { - OS.XtGetValues (scrolledHandle, argList, argList.length / 2); - } - OS.XtManageChild (handle); - /* - * Feature in Motif. When XtSetValues() is used to restore the width and - * height of the widget, the new width and height are sometimes ignored. - * The fix is to use XtResizeWidget(). - */ - if (scrolledHandle != 0) { - OS.XtResizeWidget (scrolledHandle, argList [1], argList [3], argList [5]); - } -} -void propagateWidget (boolean enabled) { - propagateHandle (enabled, handle, OS.None); -} -void releaseHandle () { - super.releaseHandle (); - parent = null; -} -void releaseParent () { - super.releaseParent (); - if (parent.horizontalBar == this) parent.horizontalBar = null; - if (parent.verticalBar == this) parent.verticalBar = null; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the user changes the receiver's value. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.Selection, listener); - eventTable.unhook(SWT.DefaultSelection,listener); -} -void sendScrollEvent (int detail) { - Event event = new Event (); - event.detail = detail; - sendEvent (SWT.Selection, event); - /* - * Feature in Motif. When a scroll bar is selected, - * it does not make the shell active. The fix is to - * make the shell active. - */ - Shell shell = parent.getShell (); - shell.bringToTop (true); -} -/** - * Enables the receiver if the argument is <code>true</code>, - * and disables it otherwise. A disabled control is typically - * not selectable from the user interface and draws with an - * inactive or "grayed" look. - * - * @param enabled the new enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setEnabled (boolean enabled) { - checkWidget(); - int [] argList = {OS.XmNsensitive, enabled ? 1 : 0}; - OS.XtSetValues (handle, argList, argList.length / 2); -} -/** - * Sets the amount that the receiver's value will be - * modified by when the up/down (or right/left) arrows - * are pressed to the argument, which must be at least - * one. - * - * @param value the new increment (must be greater than zero) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setIncrement (int value) { - checkWidget(); - if (value < 1) return; - int [] argList = {OS.XmNincrement, value}; - OS.XtSetValues (handle, argList, argList.length / 2); -} -/** - * Sets the maximum. If this value is negative or less than or - * equal to the minimum, the value is ignored. If necessary, first - * the thumb and then the selection are adjusted to fit within the - * new range. - * - * @param value the new maximum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMaximum (int value) { - checkWidget(); - if (value < 0) return; - int [] argList = {OS.XmNmaximum, value}; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XtSetValues (handle, argList, argList.length / 2); - display.setWarnings (warnings); -} -/** - * Sets the minimum value. If this value is negative or greater - * than or equal to the maximum, the value is ignored. If necessary, - * first the thumb and then the selection are adjusted to fit within - * the new range. - * - * @param value the new minimum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMinimum (int value) { - checkWidget(); - if (value < 0) return; - int [] argList = { - OS.XmNminimum, 0, - OS.XmNmaximum, 0, - OS.XmNsliderSize, 0, - }; - /* - * Feature in Motif. For some reason, when minimium - * is set to be greater than or equal to maximum, Motif - * does not set the minimum. Instead, the value is - * changed and the minimum stays the same. This behavior - * differs from setting the maximum where the slider size - * is always decreased to make room for the new maximum. - * The fix is to decrease the slider to make room for - * the new minimum. - */ - OS.XtGetValues (handle, argList, argList.length / 2); - if (argList [3] - value - argList [5] < 0) { - argList [5] = argList [3] - value; - } - argList [1] = value; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XtSetValues (handle, argList, argList.length / 2); - display.setWarnings (warnings); -} -/** - * Sets the amount that the receiver's value will be - * modified by when the page increment/decrement areas - * are selected to the argument, which must be at least - * one. - * - * @param value the page increment (must be greater than zero) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setPageIncrement (int value) { - checkWidget(); - if (value < 1) return; - int [] argList = {OS.XmNpageIncrement, value}; - OS.XtSetValues (handle, argList, argList.length / 2); -} -/** - * Sets the single <em>selection</em> that is the receiver's - * value to the argument which must be greater than or equal - * to zero. - * - * @param selection the new selection (must be zero or greater) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (int selection) { - checkWidget(); - int [] argList = {OS.XmNvalue, selection}; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XtSetValues (handle, argList, argList.length / 2); - display.setWarnings (warnings); -} -/** - * Sets the size of the receiver's thumb relative to the - * difference between its maximum and minimum values. This new - * value will be ignored if it is less than one, and will be - * clamped if it exceeds the receiver's current range. - * - * @param value the new thumb value, which must be at least one and not - * larger than the size of the current range - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setThumb (int value) { - checkWidget(); - if (value < 1) return; - int [] argList = {OS.XmNminimum, 0, OS.XmNmaximum, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - value = Math.min (value, argList [3] - argList [1]); - int [] argList2 = {OS.XmNsliderSize, value}; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XtSetValues (handle, argList2, argList2.length / 2); - display.setWarnings (warnings); -} -/** - * Sets the receiver's selection, minimum value, maximum - * value, thumb, increment and page increment all at once. - * <p> - * Note: This is similar to setting the values individually - * using the appropriate methods, but may be implemented in a - * more efficient fashion on some platforms. - * </p> - * - * @param selection the new selection value - * @param minimum the new minimum value - * @param maximum the new maximum value - * @param thumb the new thumb value - * @param increment the new increment value - * @param pageIncrement the new pageIncrement value - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) { - checkWidget(); - if (minimum < 0) return; - if (maximum < 0) return; - if (thumb < 1) return; - if (increment < 1) return; - if (pageIncrement < 1) return; - thumb = Math.min (thumb, maximum - minimum); - int [] argList = { - OS.XmNvalue, selection, - OS.XmNminimum, minimum, - OS.XmNmaximum, maximum, - OS.XmNsliderSize, thumb, - OS.XmNincrement, increment, - OS.XmNpageIncrement, pageIncrement, - }; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XtSetValues (handle, argList, argList.length / 2); - display.setWarnings (warnings); -} -/** - * Marks the receiver as visible if the argument is <code>true</code>, - * and marks it invisible otherwise. - * <p> - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, marking - * it visible may not actually cause it to be displayed. - * </p> - * - * @param visible the new visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setVisible (boolean visible) { - checkWidget(); - if (parent.setScrollBarVisible (this, visible)) { - sendEvent (visible ? SWT.Show : SWT.Hide); - parent.sendEvent (SWT.Resize); - } -} -int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XButtonPress (w, client_data, call_data, continue_to_dispatch); - if (result != 0) return result; - dragSent = false; - return result; -} -int XmNdecrementCallback (int w, int client_data, int call_data) { - sendScrollEvent (SWT.ARROW_UP); - return 0; -} -int XmNdragCallback (int w, int client_data, int call_data) { - dragSent = true; - sendScrollEvent (SWT.DRAG); - return 0; -} -int XmNincrementCallback (int w, int client_data, int call_data) { - sendScrollEvent (SWT.ARROW_DOWN); - return 0; -} -int XmNpageDecrementCallback (int w, int client_data, int call_data) { - sendScrollEvent (SWT.PAGE_UP); - return 0; -} -int XmNpageIncrementCallback (int w, int client_data, int call_data) { - sendScrollEvent (SWT.PAGE_DOWN); - return 0; -} -int XmNtoBottomCallback (int w, int client_data, int call_data) { - sendScrollEvent (SWT.END); - return 0; -} -int XmNtoTopCallback (int w, int client_data, int call_data) { - sendScrollEvent (SWT.HOME); - return 0; -} -int XmNvalueChangedCallback (int w, int client_data, int call_data) { - if (!dragSent){ - sendScrollEvent (SWT.DRAG); - dragSent = false; - } - sendScrollEvent (SWT.NONE); - return 0; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java deleted file mode 100755 index bd8cc53cbc..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java +++ /dev/null @@ -1,363 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -/** - * This class is the abstract superclass of all classes which - * represent controls that have standard scroll bars. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>H_SCROLL, V_SCROLL</dd> - * <dt><b>Events:</b> - * <dd>(none)</dd> - * </dl> - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public abstract class Scrollable extends Control { - int scrolledHandle, formHandle; - ScrollBar horizontalBar, verticalBar; -Scrollable () { - /* Do nothing */ -} -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#H_SCROLL - * @see SWT#V_SCROLL - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Scrollable (Composite parent, int style) { - super (parent, style); -} -/** - * Given a desired <em>client area</em> for the receiver - * (as described by the arguments), returns the bounding - * rectangle which would be required to produce that client - * area. - * <p> - * In other words, it returns a rectangle such that, if the - * receiver's bounds were set to that rectangle, the area - * of the receiver which is capable of displaying data - * (that is, not covered by the "trimmings") would be the - * rectangle described by the arguments (relative to the - * receiver's parent). - * </p> - * - * @param x the desired x coordinate of the client area - * @param y the desired y coordinate of the client area - * @param width the desired width of the client area - * @param height the desired height of the client area - * @return the required bounds to produce the given client area - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getClientArea - */ -public Rectangle computeTrim (int x, int y, int width, int height) { - checkWidget(); - int border = getBorderWidth (); - int trimX = x - border, trimY = y - border; - int trimWidth = width + (border * 2), trimHeight = height + (border * 2); - if (horizontalBar != null) { - trimY -= display.scrolledInsetY; - trimHeight += display.scrolledInsetY + display.scrolledMarginY; - if (verticalBar == null) { - trimX -= display.scrolledInsetX; - trimWidth += display.scrolledInsetX * 2; - trimHeight -= display.scrolledInsetY * 2; - } - } - if (verticalBar != null) { - trimX -= display.scrolledInsetX; - trimWidth += display.scrolledInsetX + display.scrolledMarginX; - if (horizontalBar == null) { - trimY -= display.scrolledInsetY; - trimHeight += display.scrolledInsetY * 2; - trimWidth -= display.scrolledInsetX * 2; - } - } - return new Rectangle (trimX, trimY, trimWidth, trimHeight); -} -ScrollBar createScrollBar (int type) { - return new ScrollBar (this, type); -} -ScrollBar createStandardBar (int style) { - if (scrolledHandle == 0) return null; - ScrollBar bar = new ScrollBar (); - bar.parent = this; - bar.style = style; - bar.display = display; - int [] argList = {OS.XmNhorizontalScrollBar, 0, OS.XmNverticalScrollBar, 0}; - OS.XtGetValues (scrolledHandle, argList, argList.length / 2); - if (style == SWT.H_SCROLL) bar.handle = argList [1]; - if (style == SWT.V_SCROLL) bar.handle = argList [3]; - bar.hookEvents (); - bar.register (); - return bar; -} -void createWidget (int index) { - super.createWidget (index); - if ((style & SWT.H_SCROLL) != 0) horizontalBar = createScrollBar (SWT.H_SCROLL); - if ((style & SWT.V_SCROLL) != 0) verticalBar = createScrollBar (SWT.V_SCROLL); -} -void destroyScrollBar (ScrollBar bar) { - setScrollBarVisible (bar, false); - if ((state & CANVAS) != 0) bar.destroyHandle (); -} -void deregister () { - super.deregister (); - if (formHandle != 0) display.removeWidget (formHandle); - if (scrolledHandle != 0) display.removeWidget (scrolledHandle); -} -void enableWidget (boolean enabled) { - super.enableWidget (enabled); - if (formHandle != 0) enableHandle (enabled, formHandle); - if (scrolledHandle != 0) enableHandle (enabled, scrolledHandle); -} -/** - * Returns a rectangle which describes the area of the - * receiver which is capable of displaying data (that is, - * not covered by the "trimmings"). - * - * @return the client area - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #computeTrim - */ -public Rectangle getClientArea () { - checkWidget(); - int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return new Rectangle (0, 0, argList [1], argList [3]); -} -/** - * Returns the receiver's horizontal scroll bar if it has - * one, and null if it does not. - * - * @return the horizontal scroll bar (or null) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public ScrollBar getHorizontalBar () { - checkWidget(); - return horizontalBar; -} -/** - * Returns the receiver's vertical scroll bar if it has - * one, and null if it does not. - * - * @return the vertical scroll bar (or null) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public ScrollBar getVerticalBar () { - checkWidget(); - return verticalBar; -} -void manageChildren () { - if (scrolledHandle != 0) { - OS.XtSetMappedWhenManaged (scrolledHandle, false); - OS.XtManageChild (scrolledHandle); - } - if (formHandle != 0) { - OS.XtSetMappedWhenManaged (formHandle, false); - OS.XtManageChild (formHandle); - } - super.manageChildren (); - if (formHandle != 0) { - int [] argList = {OS.XmNborderWidth, 0}; - OS.XtGetValues (formHandle, argList, argList.length / 2); - OS.XtResizeWidget (formHandle, 1, 1, argList [1]); - OS.XtSetMappedWhenManaged (formHandle, true); - } - if (scrolledHandle != 0) { - int [] argList = {OS.XmNborderWidth, 0}; - OS.XtGetValues (scrolledHandle, argList, argList.length / 2); - OS.XtResizeWidget (scrolledHandle, 1, 1, argList [1]); - OS.XtSetMappedWhenManaged (scrolledHandle, true); - } -} -void propagateWidget (boolean enabled) { - super.propagateWidget (enabled); - if (formHandle != 0) propagateHandle (enabled, formHandle, OS.None); - if (scrolledHandle != 0) { - propagateHandle (enabled, scrolledHandle, OS.None); - if (horizontalBar != null) horizontalBar.propagateWidget (enabled); - if (verticalBar != null) verticalBar.propagateWidget (enabled); - } -} -void register () { - super.register (); - if (formHandle != 0) display.addWidget (formHandle, this); - if (scrolledHandle != 0) display.addWidget (scrolledHandle, this); -} -void releaseChildren (boolean destroy) { - if (horizontalBar != null) { - horizontalBar.release (false); - horizontalBar = null; - } - if (verticalBar != null) { - verticalBar.release (false); - verticalBar = null; - } - super.releaseChildren (destroy); -} -void releaseHandle () { - super.releaseHandle (); - scrolledHandle = formHandle = 0; -} -void setBackgroundPixel (int pixel) { - super.setBackgroundPixel (pixel); - /* - * Uncomment this code to force scrollbars to change color. - */ -// if (scrolledHandle != 0) { -// int [] argList1 = { -// OS.XmNhorizontalScrollBar, 0, -// OS.XmNverticalScrollBar, 0, -// }; -// OS.XtGetValues (scrolledHandle, argList1, argList1.length / 2); -// if (argList1 [1] != 0) OS.XmChangeColor (argList1 [1], pixel); -// if (argList1 [3] != 0) OS.XmChangeColor (argList1 [3], pixel); -// } -} -void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean allChildren, boolean trim) { - super.redrawWidget (x, y, width, height, redrawAll, allChildren, trim); - if (!trim) return; - if (formHandle == 0 && scrolledHandle == 0) return; - short [] root_x = new short [1], root_y = new short [1]; - OS.XtTranslateCoords (handle, (short) x, (short) y, root_x, root_y); - if (formHandle != 0) { - short [] form_x = new short [1], form_y = new short [1]; - OS.XtTranslateCoords (formHandle, (short) 0, (short) 0, form_x, form_y); - redrawHandle (root_x [0] - form_x [0], root_y [0] - form_y [0], width, height, redrawAll, formHandle); - } - if (scrolledHandle != 0) { - short [] scrolled_x = new short [1], scrolled_y = new short [1]; - OS.XtTranslateCoords (scrolledHandle, (short) 0, (short) 0, scrolled_x, scrolled_y); - redrawHandle (root_x [0] - scrolled_x [0], root_y [0] - scrolled_y [0], width, height, redrawAll, scrolledHandle); - if (horizontalBar != null && horizontalBar.getVisible ()) { - int horizontalHandle = horizontalBar.handle; - short [] hscroll_x = new short [1], hscroll_y = new short [1]; - OS.XtTranslateCoords (horizontalHandle, (short) 0, (short) 0, hscroll_x, hscroll_y); - redrawHandle (root_x [0] - hscroll_x [0], root_y [0] - hscroll_y [0], width, height, redrawAll, horizontalHandle); - } - if (verticalBar != null && verticalBar.getVisible ()) { - int verticalHandle = verticalBar.handle; - short [] vscroll_x = new short [1], vscroll_y = new short [1]; - OS.XtTranslateCoords (verticalHandle, (short) 0, (short) 0, vscroll_x, vscroll_y); - redrawHandle (root_x [0] - vscroll_x [0], root_y [0] - vscroll_y [0], width, height, redrawAll, verticalHandle); - } - } -} -boolean setScrollBarVisible (ScrollBar bar, boolean visible) { - if (scrolledHandle == 0) return false; - int barHandle = bar.handle; - boolean managed = OS.XtIsManaged (barHandle); - if (managed == visible) return false; - - /* - * Feature in Motif. Hiding or showing a scroll bar - * can cause the widget to automatically resize in - * the OS. This behavior is unwanted. The fix is - * to force the widget to resize to original size. - */ - int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - OS.XtGetValues (scrolledHandle, argList, argList.length / 2); - - int [] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - - /* Hide or show the scroll bar */ - if (visible) { - OS.XtManageChild (barHandle); - } else { - OS.XtUnmanageChild (barHandle); - } - if ((state & CANVAS) != 0) { - if (formHandle != 0) { - boolean showBorder = (style & SWT.BORDER) != 0; - int margin = showBorder || visible ? 3 : 0; - if ((bar.style & SWT.V_SCROLL) != 0) { - int [] argList2 = new int [] {OS.XmNmarginWidth, margin}; - OS.XtSetValues (formHandle, argList2, argList2.length/2); - } - if ((bar.style & SWT.H_SCROLL) != 0) { - int [] argList2 = new int [] {OS.XmNmarginHeight, margin}; - OS.XtSetValues (formHandle, argList2, argList2.length/2); - } - } - } - - /* - * Feature in Motif. When XtSetValues() is used to restore the width and - * height of the widget, the new width and height are sometimes ignored. - * The fix is to use XtResizeWidget(). - */ - OS.XtResizeWidget (scrolledHandle, argList [1], argList [3], argList [5]); - - bar.sendEvent (visible ? SWT.Show : SWT.Hide); - int [] argList3 = {OS.XmNwidth, 0, OS.XmNheight, 0}; - OS.XtGetValues (handle, argList3, argList3.length / 2); - return argList1 [1] != argList3 [1] || argList1 [3] != argList3 [3]; -} -int topHandle () { - if (scrolledHandle != 0) return scrolledHandle; - if (formHandle != 0) return formHandle; - return handle; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java deleted file mode 100755 index 942cee0886..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java +++ /dev/null @@ -1,2093 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class represent the "windows" - * which the desktop or "window manager" is managing. - * Instances that do not have a parent (that is, they - * are built using the constructor, which takes a - * <code>Display</code> as the argument) are described - * as <em>top level</em> shells. Instances that do have - * a parent are described as <em>secondary</em> or - * <em>dialog</em> shells. - * <p> - * Instances are always displayed in one of the maximized, - * minimized or normal states: - * <ul> - * <li> - * When an instance is marked as <em>maximized</em>, the - * window manager will typically resize it to fill the - * entire visible area of the display, and the instance - * is usually put in a state where it can not be resized - * (even if it has style <code>RESIZE</code>) until it is - * no longer maximized. - * </li><li> - * When an instance is in the <em>normal</em> state (neither - * maximized or minimized), its appearance is controlled by - * the style constants which were specified when it was created - * and the restrictions of the window manager (see below). - * </li><li> - * When an instance has been marked as <em>minimized</em>, - * its contents (client area) will usually not be visible, - * and depending on the window manager, it may be - * "iconified" (that is, replaced on the desktop by a small - * simplified representation of itself), relocated to a - * distinguished area of the screen, or hidden. Combinations - * of these changes are also possible. - * </li> - * </ul> - * </p><p> - * The <em>modality</em> of an instance may be specified using - * style bits. The modality style bits are used to determine - * whether input is blocked for other shells on the display. - * The <code>PRIMARY_MODAL</code> style allows an instance to block - * input to its parent. The <code>APPLICATION_MODAL</code> style - * allows an instance to block input to every other shell in the - * display. The <code>SYSTEM_MODAL</code> style allows an instance - * to block input to all shells, including shells belonging to - * different applications. - * </p><p> - * Note: The styles supported by this class are treated - * as <em>HINT</em>s, since the window manager for the - * desktop on which the instance is visible has ultimate - * control over the appearance and behavior of decorations - * and modality. For example, some window managers only - * support resizable windows and will always assume the - * RESIZE style, even if it is not set. In addition, if a - * modality style is not supported, it is "upgraded" to a - * more restrictive modality style that is supported. For - * example, if <code>PRIMARY_MODAL</code> is not supported, - * it would be upgraded to <code>APPLICATION_MODAL</code>. - * A modality style may also be "downgraded" to a less - * restrictive style. For example, most operating systems - * no longer support <code>SYSTEM_MODAL</code> because - * it can freeze up the desktop, so this is typically - * downgraded to <code>APPLICATION_MODAL</code>. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE, ON_TOP, TOOL, SHEET</dd> - * <dd>APPLICATION_MODAL, MODELESS, PRIMARY_MODAL, SYSTEM_MODAL</dd> - * <dt><b>Events:</b></dt> - * <dd>Activate, Close, Deactivate, Deiconify, Iconify</dd> - * </dl> - * Class <code>SWT</code> provides two "convenience constants" - * for the most commonly required style combinations: - * <dl> - * <dt><code>SHELL_TRIM</code></dt> - * <dd> - * the result of combining the constants which are required - * to produce a typical application top level shell: (that - * is, <code>CLOSE | TITLE | MIN | MAX | RESIZE</code>) - * </dd> - * <dt><code>DIALOG_TRIM</code></dt> - * <dd> - * the result of combining the constants which are required - * to produce a typical application dialog shell: (that - * is, <code>TITLE | CLOSE | BORDER</code>) - * </dd> - * </dl> - * </p> - * <p> - * Note: Only one of the styles APPLICATION_MODAL, MODELESS, - * PRIMARY_MODAL and SYSTEM_MODAL may be specified. - * </p><p> - * IMPORTANT: This class is not intended to be subclassed. - * </p> - * - * @see Decorations - * @see SWT - * @see <a href="http://www.eclipse.org/swt/snippets/#shell">Shell snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public class Shell extends Decorations { - int shellHandle, focusProxy; - boolean reparented, realized, moved, resized, opened, modified, center; - int oldX, oldY, oldWidth, oldHeight; - Control lastActive; - - static final int MAXIMUM_TRIM = 128; - static final byte [] WM_DELETE_WINDOW = Converter.wcsToMbcs(null, "WM_DELETE_WINDOW\0"); - static final byte [] _NET_WM_STATE = Converter.wcsToMbcs(null, "_NET_WM_STATE\0"); - static final byte [] _NET_WM_STATE_MAXIMIZED_VERT = Converter.wcsToMbcs(null, "_NET_WM_STATE_MAXIMIZED_VERT\0"); - static final byte [] _NET_WM_STATE_MAXIMIZED_HORZ = Converter.wcsToMbcs(null, "_NET_WM_STATE_MAXIMIZED_HORZ\0"); - static final byte [] _NET_WM_STATE_FULLSCREEN = Converter.wcsToMbcs(null, "_NET_WM_STATE_FULLSCREEN\0"); -/** - * Constructs a new instance of this class. This is equivalent - * to calling <code>Shell((Display) null)</code>. - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - */ -public Shell () { - this ((Display) null); -} -/** - * Constructs a new instance of this class given only the style - * value describing its behavior and appearance. This is equivalent - * to calling <code>Shell((Display) null, style)</code>. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param style the style of control to construct - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#BORDER - * @see SWT#CLOSE - * @see SWT#MIN - * @see SWT#MAX - * @see SWT#RESIZE - * @see SWT#TITLE - * @see SWT#TOOL - * @see SWT#NO_TRIM - * @see SWT#SHELL_TRIM - * @see SWT#DIALOG_TRIM - * @see SWT#ON_TOP - * @see SWT#MODELESS - * @see SWT#PRIMARY_MODAL - * @see SWT#APPLICATION_MODAL - * @see SWT#SYSTEM_MODAL - * @see SWT#SHEET - */ -public Shell (int style) { - this ((Display) null, style); -} -/** - * Constructs a new instance of this class given only the display - * to create it on. It is created with style <code>SWT.SHELL_TRIM</code>. - * <p> - * Note: Currently, null can be passed in for the display argument. - * This has the effect of creating the shell on the currently active - * display if there is one. If there is no current display, the - * shell is created on a "default" display. <b>Passing in null as - * the display argument is not considered to be good coding style, - * and may not be supported in a future release of SWT.</b> - * </p> - * - * @param display the display to create the shell on - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - */ -public Shell (Display display) { - this (display, SWT.SHELL_TRIM); -} -/** - * Constructs a new instance of this class given the display - * to create it on and a style value describing its behavior - * and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p><p> - * Note: Currently, null can be passed in for the display argument. - * This has the effect of creating the shell on the currently active - * display if there is one. If there is no current display, the - * shell is created on a "default" display. <b>Passing in null as - * the display argument is not considered to be good coding style, - * and may not be supported in a future release of SWT.</b> - * </p> - * - * @param display the display to create the shell on - * @param style the style of control to construct - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#BORDER - * @see SWT#CLOSE - * @see SWT#MIN - * @see SWT#MAX - * @see SWT#RESIZE - * @see SWT#TITLE - * @see SWT#TOOL - * @see SWT#NO_TRIM - * @see SWT#SHELL_TRIM - * @see SWT#DIALOG_TRIM - * @see SWT#ON_TOP - * @see SWT#MODELESS - * @see SWT#PRIMARY_MODAL - * @see SWT#APPLICATION_MODAL - * @see SWT#SYSTEM_MODAL - * @see SWT#SHEET - */ -public Shell (Display display, int style) { - this (display, null, style, 0, false); -} -Shell (Display display, Shell parent, int style, int handle, boolean embedded) { - super (); - checkSubclass (); - if (display == null) display = Display.getCurrent (); - if (display == null) display = Display.getDefault (); - if (!display.isValidThread ()) { - error (SWT.ERROR_THREAD_INVALID_ACCESS); - } - if (parent != null && parent.isDisposed ()) { - error (SWT.ERROR_INVALID_ARGUMENT); - } - this.center = parent != null && (style & SWT.SHEET) != 0; - this.style = checkStyle (parent, style); - this.parent = parent; - this.display = display; - if (handle != 0) { - if (embedded) { - this.handle = handle; - } else { - this.shellHandle = handle; - state |= FOREIGN_HANDLE; - } - } - createWidget (0); -} -/** - * Constructs a new instance of this class given only its - * parent. It is created with style <code>SWT.DIALOG_TRIM</code>. - * <p> - * Note: Currently, null can be passed in for the parent. - * This has the effect of creating the shell on the currently active - * display if there is one. If there is no current display, the - * shell is created on a "default" display. <b>Passing in null as - * the parent is not considered to be good coding style, - * and may not be supported in a future release of SWT.</b> - * </p> - * - * @param parent a shell which will be the parent of the new instance - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - */ -public Shell (Shell parent) { - this (parent, SWT.DIALOG_TRIM); -} -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p><p> - * Note: Currently, null can be passed in for the parent. - * This has the effect of creating the shell on the currently active - * display if there is one. If there is no current display, the - * shell is created on a "default" display. <b>Passing in null as - * the parent is not considered to be good coding style, - * and may not be supported in a future release of SWT.</b> - * </p> - * - * @param parent a shell which will be the parent of the new instance - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#BORDER - * @see SWT#CLOSE - * @see SWT#MIN - * @see SWT#MAX - * @see SWT#RESIZE - * @see SWT#TITLE - * @see SWT#NO_TRIM - * @see SWT#SHELL_TRIM - * @see SWT#DIALOG_TRIM - * @see SWT#ON_TOP - * @see SWT#TOOL - * @see SWT#MODELESS - * @see SWT#PRIMARY_MODAL - * @see SWT#APPLICATION_MODAL - * @see SWT#SYSTEM_MODAL - * @see SWT#SHEET - */ -public Shell (Shell parent, int style) { - this (parent != null ? parent.display : null, parent, style, 0, false); -} - -static int checkStyle (Shell parent, int style) { - style = Decorations.checkStyle (style); - style &= ~SWT.TRANSPARENT; - if ((style & SWT.ON_TOP) != 0) style &= ~SWT.SHELL_TRIM; - int mask = SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.PRIMARY_MODAL; - if ((style & SWT.SHEET) != 0) { - style &= ~SWT.SHEET; - style |= parent == null ? SWT.SHELL_TRIM : SWT.DIALOG_TRIM; - if ((style & mask) == 0) { - style |= parent == null ? SWT.APPLICATION_MODAL : SWT.PRIMARY_MODAL; - } - } - int bits = style & ~mask; - if ((style & SWT.SYSTEM_MODAL) != 0) return bits | SWT.SYSTEM_MODAL; - if ((style & SWT.APPLICATION_MODAL) != 0) return bits | SWT.APPLICATION_MODAL; - if ((style & SWT.PRIMARY_MODAL) != 0) return bits | SWT.PRIMARY_MODAL; - return bits; -} - -public static Shell motif_new (Display display, int handle) { - return new Shell (display, null, SWT.NO_TRIM, handle, true); -} - -/** - * Invokes platform specific functionality to allocate a new shell - * that is not embedded. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>Shell</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @param display the display for the shell - * @param handle the handle for the shell - * @return a new shell object containing the specified display and handle - * - * @since 3.3 - */ -public static Shell internal_new (Display display, int handle) { - return new Shell (display, null, SWT.NO_TRIM, handle, false); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when operations are performed on the receiver, - * by sending the listener one of the messages defined in the - * <code>ShellListener</code> interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ShellListener - * @see #removeShellListener - */ -public void addShellListener(ShellListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener(SWT.Activate,typedListener); - addListener(SWT.Close,typedListener); - addListener(SWT.Deactivate,typedListener); - addListener(SWT.Iconify,typedListener); - addListener(SWT.Deiconify,typedListener); -} -void adjustTrim () { - if (display.ignoreTrim) return; - if (OS.XtIsSubclass (shellHandle, OS.overrideShellWidgetClass ())) { - return; - } - int [] argList = {OS.XmNoverrideRedirect, 0}; - OS.XtGetValues (shellHandle, argList, argList.length / 2); - if (argList [1] != 0) return; - - /* Query the trim insets */ - int shellWindow = OS.XtWindow (shellHandle); - if (shellWindow == 0) return; - int xDisplay = OS.XtDisplay (shellHandle); - if (xDisplay == 0) return; - - /* Find the direct child of the root window */ - int [] unused = new int [1]; - int [] rootWindow = new int [1]; - int [] parent = new int [1]; - int [] ptr = new int [1]; - int trimWindow = shellWindow; - OS.XQueryTree (xDisplay, trimWindow, rootWindow, parent, ptr, unused); - if (ptr [0] != 0) OS.XFree (ptr [0]); - if (parent [0] == 0) return; - while (parent [0] != rootWindow [0]) { - trimWindow = parent [0]; - OS.XQueryTree (xDisplay, trimWindow, unused, parent, ptr, unused); - if (ptr [0] != 0) OS.XFree (ptr [0]); - if (parent [0] == 0) return; - } - - /* - * Translate the coordinates of the shell window to the - * coordinates of the direct child of the root window - */ - if (shellWindow == trimWindow) return; - - /* Query the border width of the direct child of the root window */ - int [] trimBorder = new int [1]; - int [] trimWidth = new int [1]; - int [] trimHeight = new int [1]; - int [] trimX = new int [1]; - int [] trimY = new int [1]; - OS.XGetGeometry (xDisplay, trimWindow, unused, trimX, trimY, trimWidth, trimHeight, trimBorder, unused); - - /* Query the border width of the direct child of the shell window */ - int [] shellBorder = new int [1]; - int [] shellWidth = new int [1]; - int [] shellHeight = new int [1]; - OS.XGetGeometry (xDisplay, shellWindow, unused, unused, unused, shellWidth, shellHeight, shellBorder, unused); - - /* Query the trim-adjusted position of the inner window */ - short [] inner_x = new short [1], inner_y = new short [1]; - OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, inner_x, inner_y); - - /* Calculate the trim */ - int width = (trimWidth [0] + (trimBorder [0] * 2)) - (shellWidth [0] + (shellBorder [0] * 2)); - int height = (trimHeight [0] + (trimBorder [0] * 2)) - (shellHeight [0] + (shellBorder [0] * 2)); - int leftInset = inner_x [0] - trimX [0]; - int topInset = inner_y [0] - trimY [0]; - - /* - * Depending on the window manager, the algorithm to compute the window - * trim sometimes chooses the wrong X window, causing a large incorrect - * value to be calculated. The fix is to ignore the trim values if they - * are too large. - */ - if (width > MAXIMUM_TRIM || height > MAXIMUM_TRIM) { - display.ignoreTrim = true; - return; - } - - /* Update the trim guesses to match the query */ - boolean hasTitle = false, hasResize = false, hasBorder = false; - if ((style & SWT.NO_TRIM) == 0) { - hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0; - hasResize = (style & SWT.RESIZE) != 0; - hasBorder = (style & SWT.BORDER) != 0; - } - if (hasTitle) { - if (hasResize) { - display.leftTitleResizeWidth = leftInset; - display.rightTitleResizeWidth = width - leftInset; - display.topTitleResizeHeight = topInset; - display.bottomTitleResizeHeight = height - topInset; - return; - } - if (hasBorder) { - display.leftTitleBorderWidth = leftInset; - display.rightTitleBorderWidth = width - leftInset; - display.topTitleBorderHeight = topInset; - display.bottomTitleBorderHeight = height - topInset; - return; - } - display.leftTitleWidth = leftInset; - display.rightTitleWidth = width - leftInset; - display.topTitleHeight = topInset; - display.bottomTitleHeight = height - topInset; - return; - } - if (hasResize) { - display.leftResizeWidth = leftInset; - display.rightResizeWidth = width - leftInset; - display.topResizeHeight = topInset; - display.bottomResizeHeight = height - topInset; - return; - } - if (hasBorder) { - display.leftBorderWidth = leftInset; - display.rightBorderWidth = width - leftInset; - display.topBorderHeight = topInset; - display.bottomBorderHeight = height - topInset; - return; - } -} -int borderHandle () { - return handle; -} -void bringToTop (boolean force) { - /* - * Feature in X. Calling XSetInputFocus() when the - * widget is not viewable causes an X bad match error. - * The fix is to call XSetInputFocus() when the widget - * is viewable. - */ - if (minimized) return; - if (!isVisible ()) return; - int xDisplay = OS.XtDisplay (shellHandle); - if (xDisplay == 0) return; - int xWindow = OS.XtWindow (focusProxy != 0 ? focusProxy : shellHandle); - if (xWindow == 0) return; - if (!force) { - int [] buffer1 = new int [1], buffer2 = new int [1]; - OS.XGetInputFocus (xDisplay, buffer1, buffer2); - if (buffer1 [0] == 0) return; - int handle = OS.XtWindowToWidget (xDisplay, buffer1 [0]); - if (handle == 0) return; - } - int shellWindow = OS.XtWindow (shellHandle); - if (shellWindow != 0) OS.XRaiseWindow (xDisplay, shellWindow); - OS.XSetInputFocus (xDisplay, xWindow, OS.RevertToParent, OS.CurrentTime); -} -void center () { - if (parent == null) return; - Rectangle rect = getBounds (); - Rectangle parentRect = display.map (parent, null, parent.getClientArea()); - int x = Math.max (parentRect.x, parentRect.x + (parentRect.width - rect.width) / 2); - int y = Math.max (parentRect.y, parentRect.y + (parentRect.height - rect.height) / 2); - Rectangle monitorRect = parent.getMonitor ().getClientArea(); - if (x + rect.width > monitorRect.x + monitorRect.width) { - x = Math.max (monitorRect.x, monitorRect.x + monitorRect.width - rect.width); - } else { - x = Math.max (x, monitorRect.x); - } - if (y + rect.height > monitorRect.y + monitorRect.height) { - y = Math.max (monitorRect.y, monitorRect.y + monitorRect.height - rect.height); - } else { - y = Math.max (y, monitorRect.y); - } - setLocation (x, y); -} -void checkOpen () { - if (!opened) resized = false; -} -/** - * Requests that the window manager close the receiver in - * the same way it would be closed when the user clicks on - * the "close box" or performs some other platform specific - * key or mouse combination that indicates the window - * should be removed. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SWT#Close - * @see #dispose - */ -public void close () { - checkWidget(); - closeWidget (); -} -void closeWidget () { - Event event = new Event (); - sendEvent (SWT.Close, event); - if (event.doit && !isDisposed ()) dispose (); -} -public Rectangle computeTrim (int x, int y, int width, int height) { - checkWidget(); - Rectangle trim = super.computeTrim (x, y, width, height); - /* - * Feature in Motif. There is no way to get the single pixel border - * surrounding a TopLevelShell or a TransientShell. Attempts to set a - * border on either the shell handle or the main window handle fail. - * The fix is to set the border on the client area. Therefore, the - * border must be added back into the trim. - */ - int border = 0; - if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) { - int [] argList = {OS.XmNborderWidth, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - border = argList [1]; - } - trim.x -= trimLeft () + border; - trim.y -= trimTop () + border; - trim.width += trimWidth () + (border * 2); - trim.height += trimHeight () + imeHeight () + (border * 2); - return trim; -} -void createFocusProxy () { - if (focusProxy != 0) return; - int [] argList = {OS.XmNx, -1, OS.XmNy, -1, OS.XmNwidth, 1, OS.XmNheight, 1}; - focusProxy = OS.XmCreateDrawingArea (scrolledHandle, null, argList, argList.length / 2); - if (focusProxy == 0) error (SWT.ERROR_NO_HANDLES); - OS.XtSetMappedWhenManaged (focusProxy, false); - OS.XtManageChild (focusProxy); - OS.XtSetMappedWhenManaged (focusProxy, true); -} -void createHandle (int index) { - state |= CANVAS; - if (shellHandle == 0) { - int decorations = 0; - if ((style & SWT.NO_TRIM) == 0) { - if ((style & SWT.MIN) != 0) decorations |= OS.MWM_DECOR_MINIMIZE; - if ((style & SWT.MAX) != 0) decorations |= OS.MWM_DECOR_MAXIMIZE; - if ((style & SWT.RESIZE) != 0) decorations |= OS.MWM_DECOR_RESIZEH; - if ((style & SWT.BORDER) != 0) decorations |= OS.MWM_DECOR_BORDER; - if ((style & SWT.MENU) != 0) decorations |= OS.MWM_DECOR_MENU; - if ((style & SWT.TITLE) != 0) decorations |= OS.MWM_DECOR_TITLE; - /* - * Feature in Motif. Under some Window Managers (Sawmill), in order - * to get any border at all from the window manager it is necessary - * to set MWM_DECOR_BORDER. The fix is to force these bits when any - * kind of border is requested. - */ - if ((style & SWT.RESIZE) != 0) decorations |= OS.MWM_DECOR_BORDER; - } - - /* - * Note: Motif treats the modal values as hints to the Window Manager. - * For example, Enlightenment treats all modes except for SWT.MODELESS - * as SWT.APPLICATION_MODAL. The Motif Window Manager honours all modes. - */ - int inputMode = OS.MWM_INPUT_MODELESS; - if ((style & SWT.PRIMARY_MODAL) != 0) inputMode = OS.MWM_INPUT_PRIMARY_APPLICATION_MODAL; - if ((style & SWT.APPLICATION_MODAL) != 0) inputMode = OS.MWM_INPUT_FULL_APPLICATION_MODAL; - if ((style & SWT.SYSTEM_MODAL) != 0) inputMode = OS.MWM_INPUT_SYSTEM_MODAL; - - /* - * Bug in Motif. For some reason, if the title string - * length is not a multiple of 4, Motif occasionally - * draws garbage after the last character in the title. - * The fix is to pad the title. - */ - byte [] buffer = {(byte)' ', 0, 0, 0}; - int ptr = OS.XtMalloc (buffer.length); - OS.memmove (ptr, buffer, buffer.length); - int [] argList1 = { - OS.XmNmwmInputMode, inputMode, - OS.XmNmwmDecorations, decorations, - OS.XmNoverrideRedirect, (style & SWT.ON_TOP) != 0 ? 1 : 0, - OS.XmNtitle, ptr, - }; - - /* - * Feature in Motif. On some Window Managers, when a top level - * shell is created with no decorations, the Window Manager does - * not reparent the window regardless of the XmNoverrideRedirect - * resource. The fix is to treat the window as if it has been - * reparented by the Window Manager despite the fact that this - * has not really happened. - */ - if (isUndecorated ()) { - reparented = true; - } - - /* - * Feature in Motif. When a top level shell has no parent and is - * application modal, Motif does not honour the modality. The fix - * is to create the shell as a child of a hidden shell handle, the - * same way that XmNoverrideRedirect shells without parents are - * created. - */ - byte [] appClass = display.appClass; - if (parent == null && (style & SWT.ON_TOP) == 0 && inputMode != OS.MWM_INPUT_FULL_APPLICATION_MODAL) { - int xDisplay = display.xDisplay; - int widgetClass = OS.applicationShellWidgetClass (); - shellHandle = OS.XtAppCreateShell (display.appName, appClass, widgetClass, xDisplay, argList1, argList1.length / 2); - } else { - int widgetClass = OS.transientShellWidgetClass (); -// if ((style & SWT.ON_TOP) != 0) { -// widgetClass = OS.OverrideShellWidgetClass (); -// } - int parentHandle = display.shellHandle; - if (parent != null) parentHandle = parent.handle; - shellHandle = OS.XtCreatePopupShell (appClass, widgetClass, parentHandle, argList1, argList1.length / 2); - } - OS.XtFree (ptr); - if (shellHandle == 0) error (SWT.ERROR_NO_HANDLES); - if (handle != 0) { - OS.XtSetMappedWhenManaged (shellHandle, false); - OS.XtRealizeWidget (shellHandle); - OS.XtSetMappedWhenManaged (shellHandle, true); - int xDisplay = display.xDisplay; - int xWindow = OS.XtWindow (shellHandle); - if (xWindow == 0) error (SWT.ERROR_NO_HANDLES); - /* - * NOTE: The embedded parent handle must be realized - * before embedding and cannot be realized here because - * the handle belongs to another thread. - */ - OS.XReparentWindow (xDisplay, xWindow, handle, 0, 0); - handle = 0; - } - - /* Create scrolled handle */ - createHandle (index, shellHandle, true); - } else { - int [] buffer = new int [1]; - int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0}; - OS.XtGetValues (shellHandle, argList, argList.length / 2); - if (argList [3] < 1) error (SWT.ERROR_NO_HANDLES); - OS.memmove (buffer, argList [1], 4); - scrolledHandle = buffer [0]; - if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES); - argList [1] = argList [3] = 0; - OS.XtGetValues (scrolledHandle, argList, argList.length / 2); - if (argList [3] < 4) error (SWT.ERROR_NO_HANDLES); - OS.memmove (buffer, argList [1] + (argList [3] - 1) * 4, 4); - handle = buffer [0]; - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - } - - /* - * Feature in Motif. There is no way to get the single pixel - * border surrounding a TopLevelShell or a TransientShell. - * Attempts to set a border on either the shell handle - * or the main window handle fail. The fix is to set the border - * on the client area. - */ - if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) { - int [] argList2 = {OS.XmNborderWidth, 1}; - OS.XtSetValues (handle, argList2, argList2.length / 2); - } - - /* - * Feature in Motif. There is no Motif API to negotiate for the - * status line. The fix is to force the status line to appear - * by creating a hidden text widget. This is much safer than - * using X API because this may conflict with Motif. - * - * Note that XmNtraversalOn must be set to FALSE or the shell - * will not take focus when the user clicks on it. - */ - if ((style & SWT.ON_TOP) == 0) { - int [] argList3 = {OS.XmNtraversalOn, 0}; - int textHandle = OS.XmCreateTextField (handle, null, argList3, argList3.length / 2); - if (textHandle == 0) error (SWT.ERROR_NO_HANDLES); - } -} -void deregister () { - super.deregister (); - display.removeWidget (shellHandle); -} -void destroyWidget () { - /* - * Hide the shell before calling XtDestroyWidget () - * so that the shell will disappear without having - * to dispatch events. Otherwise, the user will be - * able to interact with the trimmings between the - * time that the shell is destroyed and the next - * event is dispatched. - */ - if (OS.XtIsRealized (shellHandle)) { - if (OS.XtIsTopLevelShell (shellHandle)) { - OS.XtUnmapWidget (shellHandle); - } else { - OS.XtPopdown (shellHandle); - } - } - super.destroyWidget (); -} - -public void dispose () { - /* - * Note: It is valid to attempt to dispose a widget - * more than once. If this happens, fail silently. - */ - if (isDisposed()) return; - - /* - * This code is intentionally commented. On some - * platforms, the owner window is repainted right - * away when the dialog window exits. This behavior - * is currently unspecified. - */ -// if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); -// Display oldDisplay = display; - - /* - * Feature in Motif. When the active shell is disposed, - * Motif assigns focus temporarily to the root window - * unless it has previously been told to do otherwise. - * The fix is to make the parent be the active top level - * shell when the child shell is disposed. - */ - if (parent != null) { - Shell activeShell = display.getActiveShell (); - if (activeShell == this) { - Shell shell = parent.getShell (); - shell.bringToTop (false); - } - } - super.dispose (); - - /* - * This code intentionally commented. - */ -// if (oldDisplay != null) oldDisplay.update (); -} -void enableWidget (boolean enabled) { - super.enableWidget (enabled); - enableHandle (enabled, shellHandle); -} -Control findBackgroundControl () { - return (state & BACKGROUND) != 0 || backgroundImage != null ? this : null; -} -Composite findDeferredControl () { - return layoutCount > 0 ? this : null; -} -/** - * If the receiver is visible, moves it to the top of the - * drawing order for the display on which it was created - * (so that all other shells on that display, which are not - * the receiver's children will be drawn behind it) and forces - * the window manager to make the shell active. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.0 - * @see Control#moveAbove - * @see Control#setFocus - * @see Control#setVisible - * @see Display#getActiveShell - * @see Decorations#setDefaultButton(Button) - * @see Shell#open - * @see Shell#setActive - */ -public void forceActive () { - checkWidget (); - bringToTop (true); -} -/** - * Returns the receiver's alpha value. The alpha value - * is between 0 (transparent) and 255 (opaque). - * - * @return the alpha value - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.4 - */ -public int getAlpha () { - checkWidget (); - return 255; -} -public int getBorderWidth () { - checkWidget(); - int [] argList = {OS.XmNborderWidth, 0}; - OS.XtGetValues (scrolledHandle, argList, argList.length / 2); - return argList [1]; -} -public Rectangle getBounds () { - checkWidget(); - Rectangle bounds = new Rectangle (0, 0, 0, 0); - getBounds (null, null, bounds); - return bounds; -} -void getBounds(Point location, Point size, Rectangle bounds) { - int x = 0, y = 0; - if (location != null || bounds != null) { - /* - * Bug in Motif. For some reason, XtTranslateCoords() returns different - * values depending on whether XtMoveWidget() or XtConfigureWidget() has - * been called. This only happens after the shell has been realized. - * The fix is to use XTranslateCoordinates() instead. - */ - if (OS.XtIsRealized (shellHandle)) { - int xDisplay = OS.XtDisplay (shellHandle); - int xWindow = OS.XtWindow (shellHandle); - int[] root_x = new int[1], root_y = new int[1], child = new int[1]; - /* Flush outstanding move and resize requests */ - OS.XSync (xDisplay, false); - OS.XTranslateCoordinates (xDisplay, xWindow, OS.XDefaultRootWindow (xDisplay), 0, 0, root_x, root_y, child); - x = root_x [0]; - y = root_y [0]; - } else { - short [] root_x = new short [1], root_y = new short [1]; - OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, root_x, root_y); - x = root_x [0]; - y = root_y [0]; - } - if (reparented) { - x -= trimLeft (); - y -= trimTop (); - } - } - int width = 0, height = 0; - if (size != null || bounds != null) { - int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - OS.XtGetValues (shellHandle, argList, argList.length / 2); - int border = argList [5]; - int trimWidth = trimWidth (), trimHeight = trimHeight (); - width = argList [1] + trimWidth + (border * 2); - height = argList [3] + trimHeight + (border * 2); - } - if (location != null) { - location.x = x; - location.y = y; - } - if (size != null) { - size.x = width; - size.y = height; - } - if (bounds != null) { - bounds.x = x; - bounds.y = y; - bounds.width = width; - bounds.height = height; - } -} -/** - * Returns <code>true</code> if the receiver is currently - * in fullscreen state, and false otherwise. - * <p> - * - * @return the fullscreen state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.4 - */ -public boolean getFullScreen () { - checkWidget(); - int xDisplay = OS.XtDisplay (shellHandle); - int xWindow = OS.XtWindow (shellHandle); - if (xWindow != 0) { - int property = OS.XInternAtom (xDisplay, _NET_WM_STATE, true); - if (property != 0) { - int[] type = new int[1], format = new int[1], nitems = new int[1], bytes_after = new int[1], atoms = new int[1]; - OS.XGetWindowProperty (xDisplay, xWindow, property, 0, Integer.MAX_VALUE, false, OS.XA_ATOM, type, format, nitems, bytes_after, atoms); - boolean result = false; - if (type [0] != OS.None) { - int fullScreen = OS.XInternAtom (xDisplay, _NET_WM_STATE_FULLSCREEN, true); - if (fullScreen != 0) { - int[] atom = new int[1]; - for (int i=0; i<nitems [0]; i++) { - OS.memmove(atom, atoms [0] + i * 4, 4); - if (atom [0] == fullScreen) { - result = true; - break; - } - } - } - } - if (atoms [0] != 0) OS.XFree (atoms [0]); - return result; - } - } - return false; -} -/** - * Returns the receiver's input method editor mode. This - * will be the result of bitwise OR'ing together one or - * more of the following constants defined in class - * <code>SWT</code>: - * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>, - * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>. - * - * @return the IME mode - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SWT - */ -public int getImeInputMode () { - checkWidget(); - return SWT.NONE; -} -public Point getLocation () { - checkWidget(); - Point location = new Point (0, 0); - getBounds (location, null, null); - return location; -} -public boolean getMaximized () { - checkWidget(); - int xDisplay = OS.XtDisplay (shellHandle); - int xWindow = OS.XtWindow (shellHandle); - if (xWindow != 0) { - int property = OS.XInternAtom (xDisplay, _NET_WM_STATE, true); - if (property != 0) { - int[] type = new int[1], format = new int[1], nitems = new int[1], bytes_after = new int[1], atoms = new int[1]; - OS.XGetWindowProperty (xDisplay, xWindow, property, 0, Integer.MAX_VALUE, false, OS.XA_ATOM, type, format, nitems, bytes_after, atoms); - boolean result = false; - if (type [0] != OS.None) { - int maximizedHorz = OS.XInternAtom (xDisplay, _NET_WM_STATE_MAXIMIZED_HORZ, true); - int maximizedVert = OS.XInternAtom (xDisplay, _NET_WM_STATE_MAXIMIZED_VERT, true); - if (maximizedHorz != 0 && maximizedVert != 0) { - int[] atom = new int[1]; - for (int i=0; i<nitems [0]; i++) { - OS.memmove(atom, atoms [0] + i * 4, 4); - if (atom [0] == maximizedHorz || atom [0] == maximizedVert) { - result = true; - break; - } - } - } - } - if (atoms [0] != 0) OS.XFree (atoms [0]); - return result; - } - } - return super.getMaximized (); -} -/** - * Returns a point describing the minimum receiver's size. The - * x coordinate of the result is the minimum width of the receiver. - * The y coordinate of the result is the minimum height of the - * receiver. - * - * @return the receiver's size - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.1 - */ -public Point getMinimumSize () { - checkWidget (); - int [] argList = {OS.XmNminWidth, 0, OS.XmNminHeight, 0}; - OS.XtGetValues (shellHandle, argList, argList.length / 2); - int width = Math.max (1, Math.max (0, argList [1]) + trimWidth ()); - int height = Math.max (1, Math.max (0, argList [3]) + trimHeight ()); - return new Point (width, height); -} -/** - * Gets the receiver's modified state. - * - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.5 - */ -public boolean getModified () { - checkWidget (); - return modified; -} -/** - * Returns the region that defines the shape of the shell, - * or null if the shell has the default shape. - * - * @return the region that defines the shape of the shell (or null) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.0 - * - */ -public Region getRegion () { - /* This method is needed for the @since 3.0 Javadoc */ - checkWidget (); - return region; -} -public Shell getShell () { - checkWidget(); - return this; -} -/** - * Returns an array containing all shells which are - * descendants of the receiver. - * <p> - * @return the dialog shells - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Shell [] getShells () { - checkWidget(); - int count = 0; - Shell [] shells = display.getShells (); - for (int i=0; i<shells.length; i++) { - Control shell = shells [i]; - do { - shell = shell.parent; - } while (shell != null && shell != this); - if (shell == this) count++; - } - int index = 0; - Shell [] result = new Shell [count]; - for (int i=0; i<shells.length; i++) { - Control shell = shells [i]; - do { - shell = shell.parent; - } while (shell != null && shell != this); - if (shell == this) { - result [index++] = shells [i]; - } - } - return result; -} -public Point getSize () { - checkWidget(); - Point size = new Point (0, 0); - getBounds (null, size, null); - return size; -} -public boolean getVisible () { - checkWidget(); - if (!OS.XtIsRealized (handle)) return false; - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return false; - int xWindow = OS.XtWindow (handle); - if (xWindow == 0) return false; - XWindowAttributes attributes = new XWindowAttributes (); - OS.XGetWindowAttributes (xDisplay, xWindow, attributes); - if (attributes.map_state == OS.IsViewable && reparented) return true; - int [] argList = {OS.XmNmappedWhenManaged, 0}; - OS.XtGetValues (shellHandle, argList, argList.length / 2); - return minimized && attributes.map_state == OS.IsUnviewable && argList [1] != 0; -} -boolean hasBorder () { - return false; -} -void hookEvents () { - super.hookEvents (); - int windowProc = display.windowProc; - OS.XtInsertEventHandler (shellHandle, OS.StructureNotifyMask, false, windowProc, STRUCTURE_NOTIFY, OS.XtListTail); - if (OS.XtIsSubclass (shellHandle, OS.overrideShellWidgetClass ())) return; - OS.XtInsertEventHandler (shellHandle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail); - int [] argList = {OS.XmNdeleteResponse, OS.XmDO_NOTHING}; - OS.XtSetValues (shellHandle, argList, argList.length / 2); - int xDisplay = OS.XtDisplay (shellHandle); - if (xDisplay != 0) { - int atom = OS.XmInternAtom (xDisplay, WM_DELETE_WINDOW, false); - OS.XmAddWMProtocolCallback (shellHandle, atom, windowProc, DELETE_WINDOW); - } -} -int imeHeight () { - if (!OS.IsDBLocale) return 0; - int [] argList1 = {OS.XmNheight, 0}; - OS.XtGetValues (shellHandle, argList1, argList1.length / 2); - int [] argList2 = {OS.XmNheight, 0}; - OS.XtGetValues (scrolledHandle, argList2, argList2.length / 2); - return argList1 [1] - argList2 [1]; -} -public boolean isEnabled () { - checkWidget(); - return getEnabled (); -} -boolean isModal () { - checkWidget(); - int [] argList = {OS.XmNmwmInputMode, 0}; - OS.XtGetValues (shellHandle, argList, argList.length / 2); - return (argList [1] != -1 && argList [1] != OS.MWM_INPUT_MODELESS); -} -boolean isUndecorated () { - return - (style & (SWT.SHELL_TRIM | SWT.BORDER)) == SWT.NONE || - (style & (SWT.NO_TRIM | SWT.ON_TOP)) != 0; -} -public boolean isVisible () { - checkWidget(); - return getVisible (); -} -void manageChildren () { - if ((state & FOREIGN_HANDLE) != 0) return; - OS.XtSetMappedWhenManaged (shellHandle, false); - super.manageChildren (); - int width = 0, height = 0; - if (OS.IsLinux) { - Monitor monitor = getMonitor (); - Rectangle rect = monitor.getClientArea (); - width = rect.width * 5 / 8; - height = rect.height * 5 / 8; - } else { - int xDisplay = OS.XtDisplay (shellHandle); - if (xDisplay == 0) return; - width = OS.XDisplayWidth (xDisplay, OS.XDefaultScreen (xDisplay)) * 5 / 8; - height = OS.XDisplayHeight (xDisplay, OS.XDefaultScreen (xDisplay)) * 5 / 8; - } - OS.XtResizeWidget (shellHandle, width, height, 0); -} -/** - * Moves the receiver to the top of the drawing order for - * the display on which it was created (so that all other - * shells on that display, which are not the receiver's - * children will be drawn behind it), marks it visible, - * sets the focus and asks the window manager to make the - * shell active. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see Control#moveAbove - * @see Control#setFocus - * @see Control#setVisible - * @see Display#getActiveShell - * @see Decorations#setDefaultButton(Button) - * @see Shell#setActive - * @see Shell#forceActive - */ -public void open () { - checkWidget(); - bringToTop (false); - setVisible (true); - if (isDisposed ()) return; - if (!restoreFocus () && !traverseGroup (true)) setFocus (); -} -public boolean print (GC gc) { - checkWidget (); - if (gc == null) error (SWT.ERROR_NULL_ARGUMENT); - if (gc.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - return false; -} -void propagateWidget (boolean enabled) { - super.propagateWidget (enabled); - /* Allow the busy cursor to be displayed in a disabled shell */ - int xCursor = cursor != null && !enabled ? cursor.handle : OS.None; - propagateHandle (enabled, shellHandle, xCursor); -} -void realizeWidget () { - if (realized) return; - OS.XtRealizeWidget (shellHandle); - realizeChildren (); - realized = true; -} -void register () { - super.register (); - display.addWidget (shellHandle, this); -} -void releaseChildren (boolean destroy) { - Shell [] shells = getShells (); - for (int i=0; i<shells.length; i++) { - Shell shell = shells [i]; - if (shell != null && !shell.isDisposed ()) { - shell.release (false); - } - } - super.releaseChildren (destroy); -} -void releaseHandle () { - super.releaseHandle (); - shellHandle = 0; -} -void releaseParent () { - /* Do nothing */ -} -void releaseWidget () { - super.releaseWidget (); - lastActive = null; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when operations are performed on the receiver. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ShellListener - * @see #addShellListener - */ -public void removeShellListener(ShellListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.Activate, listener); - eventTable.unhook(SWT.Close, listener); - eventTable.unhook(SWT.Deactivate, listener); - eventTable.unhook(SWT.Iconify,listener); - eventTable.unhook(SWT.Deiconify,listener); -} - -/** - * If the receiver is visible, moves it to the top of the - * drawing order for the display on which it was created - * (so that all other shells on that display, which are not - * the receiver's children will be drawn behind it) and asks - * the window manager to make the shell active - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.0 - * @see Control#moveAbove - * @see Control#setFocus - * @see Control#setVisible - * @see Display#getActiveShell - * @see Decorations#setDefaultButton(Button) - * @see Shell#open - * @see Shell#setActive - */ -public void setActive () { - checkWidget (); - bringToTop (false); -} - -void setActiveControl (Control control) { - if (control != null && control.isDisposed ()) control = null; - if (lastActive != null && lastActive.isDisposed ()) lastActive = null; - if (lastActive == control) return; - - /* - * Compute the list of controls to be activated and - * deactivated by finding the first common parent - * control. - */ - Control [] activate = (control == null) ? new Control[0] : control.getPath (); - Control [] deactivate = (lastActive == null) ? new Control[0] : lastActive.getPath (); - lastActive = control; - int index = 0, length = Math.min (activate.length, deactivate.length); - while (index < length) { - if (activate [index] != deactivate [index]) break; - index++; - } - - /* - * It is possible (but unlikely), that application - * code could have destroyed some of the widgets. If - * this happens, keep processing those widgets that - * are not disposed. - */ - for (int i=deactivate.length-1; i>=index; --i) { - if (!deactivate [i].isDisposed ()) { - if (display.postFocusOut) { - deactivate [i].postEvent (SWT.Deactivate); - } else { - deactivate [i].sendEvent (SWT.Deactivate); - } - } - } - for (int i=activate.length-1; i>=index; --i) { - if (!activate [i].isDisposed ()) { - activate [i].sendEvent (SWT.Activate); - } - } -} -/** - * Sets the receiver's alpha value which must be - * between 0 (transparent) and 255 (opaque). - * <p> - * This operation requires the operating system's advanced - * widgets subsystem which may not be available on some - * platforms. - * </p> - * @param alpha the alpha value - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.4 - */ -public void setAlpha (int alpha) { - checkWidget (); - /* Not implemented */ -} -/** - * Sets the input method editor mode to the argument which - * should be the result of bitwise OR'ing together one or more - * of the following constants defined in class <code>SWT</code>: - * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>, - * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>. - * - * @param mode the new IME mode - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SWT - */ -public void setImeInputMode (int mode) { - checkWidget(); -} -boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - /* - * Bug in Motif. When a shell that is maximized is resized to - * the same size, when the shell is unmaximized, the origin of - * the shell is moved to (0, 0). The fix is to detect this case - * and avoid resizing the shell. - * - * NOTE: When only the size is changed, the shell moves to (0, 0). - * When only the location is changed, the shell is not moved. There - * is no fix for these problems at this time. - */ - if (getMaximized ()) { - Rectangle rect = getBounds (); - boolean sameOrigin = !move || (rect.x == x && rect.y == y); - boolean sameExtent = !resize || (rect.width == width && rect.height == height); - if (sameOrigin && sameExtent) return false; - } - if (resize) { - int [] argList = {OS.XmNminWidth, 0, OS.XmNminHeight, 0}; - OS.XtGetValues (shellHandle, argList, argList.length / 2); - /* - * Feature in Motif. Motif will not allow a window - * to have a zero width or zero height. The fix is - * to ensure these values are never zero. - */ - width = Math.max (1, Math.max (argList [1], width - trimWidth ())); - height = Math.max (1, Math.max (argList [3], height - trimHeight ())); - updateResizable (width, height); - } - if (move && resize) { - OS.XtConfigureWidget (shellHandle, x, y, width, height, 0); - } else { - if (move) OS.XtMoveWidget (shellHandle, x, y); - if (resize) OS.XtResizeWidget (shellHandle, width, height, 0); - } - if (redrawWindow != 0) { - int xDisplay = OS.XtDisplay (handle); - OS.XResizeWindow (xDisplay, redrawWindow, width, height); - } - if (move && (oldX != x || oldY != y)) { - moved = true; - oldX = x + trimLeft (); - oldY = y + trimTop (); - sendEvent (SWT.Move); - if (isDisposed ()) return false; - } - if (resize && (width != oldWidth || height != oldHeight)) { - resized = true; - oldWidth = width; - oldHeight = height; - sendEvent (SWT.Resize); - if (isDisposed ()) return false; - if (layout != null) { - markLayout (false, false); - updateLayout (false); - } - } - return move || resize; -} -public void setEnabled (boolean enabled) { - checkWidget (); - if (enabled == getEnabled ()) return; - super.setEnabled (enabled); - if (enabled && this == display.getActiveShell ()) { - if (!restoreFocus ()) traverseGroup (false); - } -} -/** - * Sets the full screen state of the receiver. - * If the argument is <code>true</code> causes the receiver - * to switch to the full screen state, and if the argument is - * <code>false</code> and the receiver was previously switched - * into full screen state, causes the receiver to switch back - * to either the maximized or normal states. - * <p> - * Note: The result of intermixing calls to <code>setFullScreen(true)</code>, - * <code>setMaximized(true)</code> and <code>setMinimized(true)</code> will - * vary by platform. Typically, the behavior will match the platform user's - * expectations, but not always. This should be avoided if possible. - * </p> - * - * @param fullScreen the new fullscreen state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.4 - */ -public void setFullScreen (boolean fullScreen) { - checkWidget(); - if (!OS.XtIsRealized (handle)) realizeWidget (); - int xDisplay = OS.XtDisplay (shellHandle); - int xWindow = OS.XtWindow (shellHandle); - if (xWindow == 0) return; - int property = OS.XInternAtom (xDisplay, _NET_WM_STATE, true); - if (property == 0) return; - int atom = OS.XInternAtom (xDisplay, _NET_WM_STATE_FULLSCREEN, true); - if (atom == 0) return; - XClientMessageEvent xEvent = new XClientMessageEvent (); - xEvent.type = OS.ClientMessage; - xEvent.send_event = 1; - xEvent.display = xDisplay; - xEvent.window = xWindow; - xEvent.message_type = property; - xEvent.format = 32; - xEvent.data [0] = fullScreen ? 1 : 0; - xEvent.data [1] = atom; - XWindowAttributes attributes = new XWindowAttributes (); - OS.XGetWindowAttributes (xDisplay, xWindow, attributes); - int rootWindow = OS.XRootWindowOfScreen (attributes.screen); - int event = OS.XtMalloc (XEvent.sizeof); - OS.memmove (event, xEvent, XClientMessageEvent.sizeof); - OS.XSendEvent (xDisplay, rootWindow, false, OS.SubstructureRedirectMask|OS.SubstructureNotifyMask, event); - OS.XSync (xDisplay, false); - OS.XtFree (event); -} -public void setMaximized (boolean maximized) { - checkWidget(); - super.setMaximized (maximized); - if (!OS.XtIsRealized (handle)) realizeWidget (); - int xDisplay = OS.XtDisplay (shellHandle); - int xWindow = OS.XtWindow (shellHandle); - if (xWindow == 0) return; - int property = OS.XInternAtom (xDisplay, _NET_WM_STATE, true); - if (property == 0) return; - int hMaxAtom = OS.XInternAtom (xDisplay, _NET_WM_STATE_MAXIMIZED_HORZ, true); - int vMaxAtom = OS.XInternAtom (xDisplay, _NET_WM_STATE_MAXIMIZED_VERT, true); - if (hMaxAtom == 0 || vMaxAtom == 0) return; - XClientMessageEvent xEvent = new XClientMessageEvent (); - xEvent.type = OS.ClientMessage; - xEvent.send_event = 1; - xEvent.display = xDisplay; - xEvent.window = xWindow; - xEvent.message_type = property; - xEvent.format = 32; - xEvent.data [0] = maximized ? 1 : 0; - xEvent.data [1] = hMaxAtom; - xEvent.data [2] = vMaxAtom; - XWindowAttributes attributes = new XWindowAttributes (); - OS.XGetWindowAttributes (xDisplay, xWindow, attributes); - int rootWindow = OS.XRootWindowOfScreen (attributes.screen); - int event = OS.XtMalloc (XEvent.sizeof); - OS.memmove (event, xEvent, XClientMessageEvent.sizeof); - OS.XSendEvent (xDisplay, rootWindow, false, OS.SubstructureRedirectMask|OS.SubstructureNotifyMask, event); - OS.XSync (xDisplay, false); - OS.XtFree (event); -} -public void setMinimized (boolean minimized) { - checkWidget(); - if (minimized == this.minimized) return; - - /* - * Bug in MOTIF. For some reason, the receiver does not keep the - * value of the XmNiconic resource up to date when the user minimizes - * and restores the window. As a result, a window that is minimized - * by the user and then restored by the programmer is not restored. - * This happens because the XmNiconic resource is unchanged when the - * window is minimized by the user and subsequent attempts to set the - * resource fail because the new value of the resource is the same as - * the old value. The fix is to force XmNiconic to be up to date - * before setting the desired value. - */ - int [] argList = { - OS.XmNiconic, 0, - OS.XmNinitialState, 0, - }; - OS.XtGetValues (shellHandle, argList, argList.length / 2); - if ((argList [1] != 0) != this.minimized) { - argList [1] = this.minimized ? 1 : 0; - OS.XtSetValues (shellHandle, argList, argList.length / 2); - } - - /* Minimize or restore the shell */ - super.setMinimized (minimized); - argList [1] = minimized ? 1 : 0; - argList [3] = minimized ? OS.IconicState : OS.NormalState; - OS.XtSetValues (shellHandle, argList, argList.length / 2); - - /* Force the XWindowAttributes to be up to date */ - int xDisplay = OS.XtDisplay (handle); - if (xDisplay != 0) OS.XSync (xDisplay, false); - - /* Make the restored shell be the active shell */ - if (!minimized) { - int [] argList2 = {OS.XmNmappedWhenManaged, 0}; - OS.XtGetValues (shellHandle, argList2, argList2.length / 2); - if (argList2 [1] != 0) { - do { - display.update (); - } while (!isVisible ()); - setActive (); - } - } -} -/** - * Sets the receiver's minimum size to the size specified by the arguments. - * If the new minimum size is larger than the current size of the receiver, - * the receiver is resized to the new minimum size. - * - * @param width the new minimum width for the receiver - * @param height the new minimum height for the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.1 - */ -public void setMinimumSize (int width, int height) { - checkWidget (); - int [] argList = { - OS.XmNminWidth, Math.max (width, trimWidth ()) - trimWidth (), - OS.XmNminHeight, Math.max (height, trimHeight ()) - trimHeight (), - }; - OS.XtSetValues (shellHandle, argList, argList.length / 2); -} -/** - * Sets the receiver's minimum size to the size specified by the argument. - * If the new minimum size is larger than the current size of the receiver, - * the receiver is resized to the new minimum size. - * - * @param size the new minimum size for the receiver - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the point is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.1 - */ -public void setMinimumSize (Point size) { - checkWidget (); - if (size == null) error (SWT.ERROR_NULL_ARGUMENT); - setMinimumSize (size.x, size.y); -} -/** - * Sets the receiver's modified state as specified by the argument. - * - * @param modified the new modified state for the receiver - * - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.5 - */ -public void setModified (boolean modified) { - checkWidget (); - this.modified = modified; -} -void setParentTraversal () { - /* Do nothing - Child shells do not affect the traversal of their parent shell */ -} -/** - * Sets the shape of the shell to the region specified - * by the argument. When the argument is null, the - * default shape of the shell is restored. The shell - * must be created with the style SWT.NO_TRIM in order - * to specify a region. - * - * @param region the region that defines the shape of the shell (or null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the region has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.0 - * - */ -public void setRegion (Region region) { - checkWidget (); - if ((style & SWT.NO_TRIM) == 0) return; - if (region != null && region.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - super.setRegion (region); -} -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - super.setText (string); - - /* - * Feature in Motif. It is not possible to set a shell - * title to an empty string. The fix is to set the title - * to be a single space. - */ - /* Use the character encoding for the default locale */ - if (string.length () == 0) string = " "; - byte [] buffer1 = Converter.wcsToMbcs (null, string, true); - - /* - * Bug in Motif. For some reason, if the title string - * length is not a multiple of 4, Motif occasionally - * draws garbage after the last character in the title. - * The fix is to pad the title. - */ - byte [] buffer2 = buffer1; - int length = buffer1.length - 1; - if ((length % 4) != 0) { - buffer2 = new byte [(length + 3) / 4 * 4]; - System.arraycopy (buffer1, 0, buffer2, 0, length); - } - - /* Set the title for the shell */ - int ptr = OS.XtMalloc (buffer2.length + 1); - OS.memmove (ptr, buffer2, buffer2.length); - int [] argList = {OS.XmNtitle, ptr, OS.XmNiconName, ptr}; - OS.XtSetValues (shellHandle, argList, argList.length / 2); - OS.XtFree (ptr); -} -public void setVisible (boolean visible) { - checkWidget(); - realizeWidget (); - - /* Show the shell */ - if (visible) { - if (center && !moved) { - center (); - if (isDisposed ()) return; - } - sendEvent (SWT.Show); - if (isDisposed ()) return; - - /* Map the widget */ - OS.XtSetMappedWhenManaged (shellHandle, true); - if (OS.XtIsTopLevelShell (shellHandle)) { - OS.XtMapWidget (shellHandle); - } else { - OS.XtPopup (shellHandle, OS.XtGrabNone); - } - - /* - * Force the shell to be fully exposed before returning. - * This ensures that the shell coordinates are correct - * when queried directly after showing the shell. - * - * Note that if the parent is minimized or withdrawn - * from the desktop, this should not be done since - * the shell will not be mapped until the parent is - * unminimized or shown on the desktop. - */ - boolean iconic = false; - Shell shell = parent != null ? parent.getShell() : null; - do { - display.update (); - if (isDisposed ()) return; - iconic = minimized || (shell != null && shell.minimized); - } while (!isVisible () && !iconic); - if (!iconic) adjustTrim (); - - int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.APPLICATION_MODAL; - if ((style & mask) != 0) { - OS.XUngrabPointer (display.xDisplay, OS.CurrentTime); - } - opened = true; - if (!moved) { - moved = true; - Point location = getLocation (); - oldX = location.x + trimLeft (); - oldY = location.x + trimTop (); - sendEvent (SWT.Move); - if (isDisposed ()) return; - } - if (!resized) { - resized = true; - Point size = getSize (); - oldWidth = size.x - trimWidth (); - oldHeight = size.y - trimHeight (); - sendEvent (SWT.Resize); - if (isDisposed ()) return; - if (layout != null) { - markLayout (false, false); - updateLayout (false); - } - } - } else { - /* - * Feature in Motif. When the active shell is disposed, - * some window managers place focus in a temporary window. - * The fix is to make the parent be the active top level - * shell when the child shell is hidden. - */ - if (parent != null) { - Shell activeShell = display.getActiveShell (); - if (activeShell == this) { - Shell shell = parent.getShell (); - shell.bringToTop (false); - } - } - - /* Hide the shell */ - OS.XtSetMappedWhenManaged (shellHandle, false); - if (OS.XtIsTopLevelShell (shellHandle)) { - OS.XtUnmapWidget (shellHandle); - } else { - OS.XtPopdown (shellHandle); - } - - /* If the shell is iconified, hide the icon */ - int xDisplay = OS.XtDisplay (shellHandle); - if (xDisplay == 0) return; - int xWindow = OS.XtWindow (shellHandle); - if (xWindow == 0) return; - OS.XWithdrawWindow (xDisplay, xWindow, OS.XDefaultScreen (xDisplay)); - - sendEvent (SWT.Hide); - } -} -void setZOrder (Control control, boolean above) { - setZOrder (control, above, false); -} -int topHandle () { - return shellHandle; -} -boolean traverseEscape () { - if (parent == null) return false; - if (!isVisible () || !isEnabled ()) return false; - close (); - return true; -} -int trimHeight () { - if ((style & SWT.NO_TRIM) != 0) return 0; - boolean hasTitle = false, hasResize = false, hasBorder = false; - hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0; - hasResize = (style & SWT.RESIZE) != 0; - hasBorder = (style & SWT.BORDER) != 0; - if (hasTitle) { - if (hasResize) { - return display.topTitleResizeHeight + display.bottomTitleResizeHeight; - } - if (hasBorder) { - return display.topTitleBorderHeight + display.bottomTitleBorderHeight; - } - return display.topTitleHeight + display.bottomTitleHeight; - } - if (hasResize) { - return display.topResizeHeight + display.bottomResizeHeight; - } - if (hasBorder) { - return display.topBorderHeight + display.bottomBorderHeight; - } - return 0; -} -int trimLeft () { - if ((style & SWT.NO_TRIM) != 0) return 0; - boolean hasTitle = false, hasResize = false, hasBorder = false; - hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0; - hasResize = (style & SWT.RESIZE) != 0; - hasBorder = (style & SWT.BORDER) != 0; - if (hasTitle) { - if (hasResize) return display.leftTitleResizeWidth; - if (hasBorder) return display.leftTitleBorderWidth; - return display.leftTitleWidth; - } - if (hasResize) return display.leftResizeWidth; - if (hasBorder) return display.leftBorderWidth; - return 0; -} -int trimTop () { - if ((style & SWT.NO_TRIM) != 0) return 0; - boolean hasTitle = false, hasResize = false, hasBorder = false; - hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0; - hasResize = (style & SWT.RESIZE) != 0; - hasBorder = (style & SWT.BORDER) != 0; - if (hasTitle) { - if (hasResize) return display.topTitleResizeHeight; - if (hasBorder) return display.topTitleBorderHeight; - return display.topTitleHeight; - } - if (hasResize) return display.topResizeHeight; - if (hasBorder) return display.topBorderHeight; - return 0; -} -int trimWidth () { - if ((style & SWT.NO_TRIM) != 0) return 0; - boolean hasTitle = false, hasResize = false, hasBorder = false; - hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0; - hasResize = (style & SWT.RESIZE) != 0; - hasBorder = (style & SWT.BORDER) != 0; - if (hasTitle) { - if (hasResize) { - return display.leftTitleResizeWidth + display.rightTitleResizeWidth; - } - if (hasBorder) { - return display.leftTitleBorderWidth + display.rightTitleBorderWidth; - } - return display.leftTitleWidth + display.rightTitleWidth; - } - if (hasResize) { - return display.leftResizeWidth + display.rightResizeWidth; - } - if (hasBorder) { - return display.leftBorderWidth + display.rightBorderWidth; - } - return 0; -} -void updateResizable (int width, int height) { - if ((style & SWT.RESIZE) != 0) return; - if (!OS.XtIsRealized (shellHandle)) return; - XSizeHints hints = new XSizeHints (); - hints.flags = OS.PMinSize | OS.PMaxSize | OS.PPosition; - hints.min_width = hints.max_width = width; - hints.min_height = hints.max_height = height; - OS.XSetWMNormalHints (OS.XtDisplay (shellHandle), OS.XtWindow (shellHandle), hints); -} -int WM_DELETE_WINDOW (int w, int client_data, int call_data) { - if (!isEnabled ()) return 0; - Control widget = parent; - while (widget != null && !(widget.getShell ().isModal ())) { - widget = widget.parent; - } - if (widget == null) { - Shell [] shells = getShells (); - for (int i=0; i<shells.length; i++) { - Shell shell = shells [i]; - if (shell != this && shell.isModal () && shell.isVisible ()) { - shell.bringToTop (false); - return 0; - } - } - } - closeWidget (); - return 0; -} -int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatch) { - XFocusChangeEvent xEvent = new XFocusChangeEvent (); - OS.memmove (xEvent, call_data, XFocusChangeEvent.sizeof); - int handle = OS.XtWindowToWidget (xEvent.display, xEvent.window); - if (handle != shellHandle) { - return super.XFocusChange (w, client_data, call_data, continue_to_dispatch); - } - if (xEvent.mode != OS.NotifyNormal) return 0; - if (xEvent.type == OS.FocusIn && xEvent.detail == OS.NotifyInferior) { - if (focusProxy != 0) { - int xWindow = OS.XtWindow (focusProxy); - int xDisplay = OS.XtDisplay (focusProxy); - OS.XSetInputFocus (xDisplay, xWindow, OS.RevertToParent, OS.CurrentTime); - } - } - switch (xEvent.detail) { - case OS.NotifyNonlinear: - case OS.NotifyNonlinearVirtual: { - switch (xEvent.type) { - case OS.FocusIn: - if (display.postFocusOut) { - postEvent (SWT.Activate); - } else { - sendEvent (SWT.Activate); - } - break; - case OS.FocusOut: - Display display = this.display; - if (display.postFocusOut) { - postEvent (SWT.Deactivate); - } else { - sendEvent (SWT.Deactivate); - } - Control focusedCombo = display.focusedCombo; - display.focusedCombo = null; - if (focusedCombo != null && focusedCombo != this && !focusedCombo.isDisposed ()) { - display.sendFocusEvent (focusedCombo, SWT.FocusOut); - } - break; - } - } - } - return 0; -} -int XStructureNotify (int w, int client_data, int call_data, int continue_to_dispatch) { - XConfigureEvent xEvent = new XConfigureEvent (); - OS.memmove (xEvent, call_data, XConfigureEvent.sizeof); - int handle = OS.XtWindowToWidget (xEvent.display, xEvent.window); - if (handle != shellHandle) { - return super.XStructureNotify (w, client_data, call_data, continue_to_dispatch); - } - switch (xEvent.type) { - case OS.ReparentNotify: { - reparented = true; - adjustTrim (); - break; - } - case OS.ConfigureNotify: - int [] root_x = new int [1], root_y = new int [1], child = new int [1]; - OS.XTranslateCoordinates (xEvent.display, xEvent.window, OS.XDefaultRootWindow (xEvent.display), 0, 0, root_x, root_y, child); - if (!moved || oldX != root_x [0] || oldY != root_y [0]) { - moved = true; - oldX = root_x [0]; - oldY = root_y [0]; - sendEvent (SWT.Move); - if (isDisposed ()) return 0; - } - updateResizable (xEvent.width, xEvent.height); - if (!resized || oldWidth != xEvent.width || oldHeight != xEvent.height) { - int xEvent1 = OS.XtMalloc (XEvent.sizeof); - display.resizeWindow = xEvent.window; - display.resizeWidth = xEvent.width; - display.resizeHeight = xEvent.height; - display.resizeCount = 0; - int checkResizeProc = display.checkResizeProc; - OS.XCheckIfEvent (xEvent.display, xEvent1, checkResizeProc, 0); - OS.XtFree (xEvent1); - if (display.resizeCount == 0) { - resized = true; - oldWidth = xEvent.width; - oldHeight = xEvent.height; - sendEvent (SWT.Resize); - if (isDisposed ()) return 0; - if (layout != null) { - markLayout (false, false); - updateLayout (false); - } - } - } - return 0; - case OS.UnmapNotify: - int [] argList = {OS.XmNmappedWhenManaged, 0}; - OS.XtGetValues (shellHandle, argList, argList.length / 2); - if (argList [1] != 0) { - minimized = true; - sendEvent (SWT.Iconify); - } - return 0; - case OS.MapNotify: - if (minimized) { - minimized = false; - sendEvent (SWT.Deiconify); - } - return 0; - } - return 0; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java deleted file mode 100755 index 0ac37fc1cc..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java +++ /dev/null @@ -1,553 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class are selectable user interface - * objects that represent a range of positive, numeric values. - * <p> - * At any given moment, a given slider will have a - * single 'selection' that is considered to be its - * value, which is constrained to be within the range of - * values the slider represents (that is, between its - * <em>minimum</em> and <em>maximum</em> values). - * </p><p> - * Typically, sliders will be made up of five areas: - * <ol> - * <li>an arrow button for decrementing the value</li> - * <li>a page decrement area for decrementing the value by a larger amount</li> - * <li>a <em>thumb</em> for modifying the value by mouse dragging</li> - * <li>a page increment area for incrementing the value by a larger amount</li> - * <li>an arrow button for incrementing the value</li> - * </ol> - * Based on their style, sliders are either <code>HORIZONTAL</code> - * (which have a left facing button for decrementing the value and a - * right facing button for incrementing it) or <code>VERTICAL</code> - * (which have an upward facing button for decrementing the value - * and a downward facing buttons for incrementing it). - * </p><p> - * On some platforms, the size of the slider's thumb can be - * varied relative to the magnitude of the range of values it - * represents (that is, relative to the difference between its - * maximum and minimum values). Typically, this is used to - * indicate some proportional value such as the ratio of the - * visible area of a document to the total amount of space that - * it would take to display it. SWT supports setting the thumb - * size even if the underlying platform does not, but in this - * case the appearance of the slider will not change. - * </p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>HORIZONTAL, VERTICAL</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection</dd> - * </dl> - * <p> - * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see ScrollBar - * @see <a href="http://www.eclipse.org/swt/snippets/#slider">Slider snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class Slider extends Control { - boolean dragSent = false; -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#HORIZONTAL - * @see SWT#VERTICAL - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Slider (Composite parent, int style) { - super (parent, checkStyle (style)); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the user changes the receiver's value, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * When <code>widgetSelected</code> is called, the event object detail field contains one of the following values: - * <code>SWT.NONE</code> - for the end of a drag. - * <code>SWT.DRAG</code>. - * <code>SWT.HOME</code>. - * <code>SWT.END</code>. - * <code>SWT.ARROW_DOWN</code>. - * <code>SWT.ARROW_UP</code>. - * <code>SWT.PAGE_DOWN</code>. - * <code>SWT.PAGE_UP</code>. - * <code>widgetDefaultSelected</code> is not called. - * </p> - * - * @param listener the listener which should be notified when the user changes the receiver's value - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener(listener); - addListener(SWT.Selection,typedListener); - addListener(SWT.DefaultSelection,typedListener); -} -static int checkStyle (int style) { - return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - int border = getBorderWidth (); - int width = border * 2, height = border * 2; - int hScroll = display.scrolledMarginX; - int vScroll = display.scrolledMarginY; - if ((style & SWT.HORIZONTAL) != 0) { - width += hScroll * 10; - height += vScroll; - } else { - width += hScroll; - height += vScroll * 10; - } - if (wHint != SWT.DEFAULT) width = wHint + (border * 2); - if (hHint != SWT.DEFAULT) height = hHint + (border * 2); - return new Point (width, height); -} -void createHandle (int index) { - int [] argList = { - OS.XmNancestorSensitive, 1, - OS.XmNhighlightThickness, display.textHighlightThickness, - OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0, - OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL, - OS.XmNtraversalOn, 1, - }; - int parentHandle = parent.handle; - handle = OS.XmCreateScrollBar (parentHandle, null, argList, argList.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); -} -/** - * Returns the amount that the receiver's value will be - * modified by when the up/down (or right/left) arrows - * are pressed. - * - * @return the increment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getIncrement () { - checkWidget(); - int [] argList = {OS.XmNincrement, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the maximum value which the receiver will allow. - * - * @return the maximum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getMaximum () { - checkWidget(); - int [] argList = {OS.XmNmaximum, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the minimum value which the receiver will allow. - * - * @return the minimum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getMinimum () { - checkWidget(); - int [] argList = {OS.XmNminimum, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the amount that the receiver's value will be - * modified by when the page increment/decrement areas - * are selected. - * - * @return the page increment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getPageIncrement () { - checkWidget(); - int [] argList = {OS.XmNpageIncrement, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the 'selection', which is the receiver's value. - * - * @return the selection - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getSelection () { - checkWidget(); - int [] argList = {OS.XmNvalue, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the size of the receiver's thumb relative to the - * difference between its maximum and minimum values. - * - * @return the thumb value - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getThumb () { - checkWidget(); - int [] argList = {OS.XmNsliderSize, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -void hookEvents () { - super.hookEvents (); - int windowProc = display.windowProc; - OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK); - OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, DRAG_CALLBACK); - OS.XtAddCallback (handle, OS.XmNtoBottomCallback, windowProc, TO_BOTTOM_CALLBACK); - OS.XtAddCallback (handle, OS.XmNtoTopCallback, windowProc, TO_TOP_CALLBACK); - OS.XtAddCallback (handle, OS.XmNincrementCallback, windowProc, INCREMENT_CALLBACK); - OS.XtAddCallback (handle, OS.XmNdecrementCallback, windowProc, DECREMENT_CALLBACK); - OS.XtAddCallback (handle, OS.XmNpageIncrementCallback, windowProc, PAGE_INCREMENT_CALLBACK); - OS.XtAddCallback (handle, OS.XmNpageDecrementCallback, windowProc, PAGE_DECREMENT_CALLBACK); -} -void overrideTranslations () { - OS.XtOverrideTranslations (handle, display.tabTranslations); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the user changes the receiver's value. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.Selection, listener); - eventTable.unhook(SWT.DefaultSelection,listener); -} -void sendScrollEvent (int detail) { - Event event = new Event (); - event.detail = detail; - postEvent (SWT.Selection, event); -} -/** - * Sets the amount that the receiver's value will be - * modified by when the up/down (or right/left) arrows - * are pressed to the argument, which must be at least - * one. - * - * @param value the new increment (must be greater than zero) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setIncrement (int value) { - checkWidget(); - if (value < 1) return; - int [] argList = {OS.XmNincrement, value}; - OS.XtSetValues (handle, argList, argList.length / 2); -} -/** - * Sets the maximum. If this value is negative or less than or - * equal to the minimum, the value is ignored. If necessary, first - * the thumb and then the selection are adjusted to fit within the - * new range. - * - * @param value the new maximum, which must be greater than the current minimum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMaximum (int value) { - checkWidget(); - if (value < 0) return; - int [] argList = {OS.XmNmaximum, value}; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XtSetValues (handle, argList, argList.length / 2); - display.setWarnings (warnings); -} -/** - * Sets the minimum value. If this value is negative or greater - * than or equal to the maximum, the value is ignored. If necessary, - * first the thumb and then the selection are adjusted to fit within - * the new range. - * - * @param value the new minimum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMinimum (int value) { - checkWidget(); - if (value < 0) return; - int [] argList = { - OS.XmNminimum, 0, - OS.XmNmaximum, 0, - OS.XmNsliderSize, 0, - }; - /* - * Feature in Motif. For some reason, when minimium - * is set to be greater than or equal to maximum, Motif - * does not set the minimum. Instead, the value is - * changed and the minimum stays the same. This behavior - * differs from setting the maximum where the slider size - * is always decreased to make room for the new maximum. - * The fix is to decrease the slider to make room for - * the new minimum. - */ - OS.XtGetValues (handle, argList, argList.length / 2); - if (argList [3] - value - argList [5] < 0) { - argList [5] = argList [3] - value; - } - argList [1] = value; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XtSetValues (handle, argList, argList.length / 2); - display.setWarnings (warnings); -} -/** - * Sets the amount that the receiver's value will be - * modified by when the page increment/decrement areas - * are selected to the argument, which must be at least - * one. - * - * @param value the page increment (must be greater than zero) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setPageIncrement (int value) { - checkWidget(); - if (value < 1) return; - int [] argList = {OS.XmNpageIncrement, value}; - OS.XtSetValues (handle, argList, argList.length / 2); -} -/** - * Sets the 'selection', which is the receiver's - * value, to the argument which must be greater than or equal - * to zero. - * - * @param value the new selection (must be zero or greater) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (int value) { - checkWidget(); - int [] argList = {OS.XmNvalue, value}; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XtSetValues (handle, argList, argList.length / 2); - display.setWarnings (warnings); -} -/** - * Sets the size of the receiver's thumb relative to the - * difference between its maximum and minimum values. This new - * value will be ignored if it is less than one, and will be - * clamped if it exceeds the receiver's current range. - * - * @param value the new thumb value, which must be at least one and not - * larger than the size of the current range - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setThumb (int value) { - checkWidget(); - if (value < 1) return; - int [] argList = {OS.XmNminimum, 0, OS.XmNmaximum, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - value = Math.min (value, argList [3] - argList [1]); - int [] argList2 = {OS.XmNsliderSize, value}; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XtSetValues (handle, argList2, argList2.length / 2); - display.setWarnings (warnings); -} -/** - * Sets the receiver's selection, minimum value, maximum - * value, thumb, increment and page increment all at once. - * <p> - * Note: This is similar to setting the values individually - * using the appropriate methods, but may be implemented in a - * more efficient fashion on some platforms. - * </p> - * - * @param selection the new selection value - * @param minimum the new minimum value - * @param maximum the new maximum value - * @param thumb the new thumb value - * @param increment the new increment value - * @param pageIncrement the new pageIncrement value - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) { - checkWidget(); - if (minimum < 0) return; - if (maximum < 0) return; - if (thumb < 1) return; - if (increment < 1) return; - if (pageIncrement < 1) return; - thumb = Math.min (thumb, maximum - minimum); - int [] argList = { - OS.XmNvalue, selection, - OS.XmNminimum, minimum, - OS.XmNmaximum, maximum, - OS.XmNsliderSize, thumb, - OS.XmNincrement, increment, - OS.XmNpageIncrement, pageIncrement, - }; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XtSetValues (handle, argList, argList.length / 2); - display.setWarnings (warnings); -} -int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XButtonPress (w, client_data, call_data, continue_to_dispatch); - if (result != 0) return result; - dragSent = false; - return result; -} -int XmNdecrementCallback (int w, int client_data, int call_data) { - sendScrollEvent (SWT.ARROW_UP); - return 0; -} -int XmNdragCallback (int w, int client_data, int call_data) { - dragSent = true; - sendScrollEvent (SWT.DRAG); - return 0; -} -int XmNincrementCallback (int w, int client_data, int call_data) { - sendScrollEvent (SWT.ARROW_DOWN); - return 0; -} -int XmNpageDecrementCallback (int w, int client_data, int call_data) { - sendScrollEvent (SWT.PAGE_UP); - return 0; -} -int XmNpageIncrementCallback (int w, int client_data, int call_data) { - sendScrollEvent (SWT.PAGE_DOWN); - return 0; -} -int XmNtoBottomCallback (int w, int client_data, int call_data) { - sendScrollEvent (SWT.END); - return 0; -} -int XmNtoTopCallback (int w, int client_data, int call_data) { - sendScrollEvent (SWT.HOME); - return 0; -} -int XmNvalueChangedCallback (int w, int client_data, int call_data) { - if (!dragSent){ - sendScrollEvent (SWT.DRAG); - dragSent = false; - } - sendScrollEvent (SWT.NONE); - return 0; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Spinner.java deleted file mode 100644 index f81af4c4ea..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Spinner.java +++ /dev/null @@ -1,1039 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class are selectable user interface - * objects that allow the user to enter and modify numeric - * values. - * <p> - * Note that although this class is a subclass of <code>Composite</code>, - * it does not make sense to add children to it, or set a layout on it. - * </p><p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>READ_ONLY, WRAP</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection, Modify, Verify</dd> - * </dl> - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#spinner">Spinner snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 3.1 - * @noextend This class is not intended to be subclassed by clients. - */ -public class Spinner extends Composite { - /** - * the operating system limit for the number of characters - * that the text field in an instance of this class can hold - * - * @since 3.4 - */ - public static final int LIMIT; - - /* - * These values can be different on different platforms. - * Therefore they are not initialized in the declaration - * to stop the compiler from inlining. - */ - static { - LIMIT = 0x7FFFFFFF; - } - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#READ_ONLY - * @see SWT#WRAP - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Spinner (Composite parent, int style) { - super (parent, checkStyle (style)); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's text is modified, by sending - * it one of the messages defined in the <code>ModifyListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ModifyListener - * @see #removeModifyListener - */ -public void addModifyListener (ModifyListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Modify, typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the control is selected by the user, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * <code>widgetSelected</code> is not called for texts. - * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text. - * </p> - * - * @param listener the listener which should be notified when the control is selected by the user - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener(listener); - addListener(SWT.Selection,typedListener); - addListener(SWT.DefaultSelection,typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's text is verified, by sending - * it one of the messages defined in the <code>VerifyListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see VerifyListener - * @see #removeVerifyListener - */ -void addVerifyListener (VerifyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Verify, typedListener); -} -static int checkStyle (int style) { - /* - * Even though it is legal to create this widget - * with scroll bars, they serve no useful purpose - * because they do not automatically scroll the - * widget's client area. The fix is to clear - * the SWT style. - */ - return style & ~(SWT.H_SCROLL | SWT.V_SCROLL); -} -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; - if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; - int width = wHint; - int height = hHint; - if (wHint == SWT.DEFAULT) { - width = DEFAULT_WIDTH; - int [] argList = { - OS.XmNmaximumValue, 0, - OS.XmNdecimalPoints, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - String string = String.valueOf (argList [1]); - if (argList [3] > 0) { - StringBuffer buffer = new StringBuffer (); - buffer.append (string); - buffer.append (getDecimalSeparator ()); - int count = argList [3] - string.length (); - while (count >= 0) { - buffer.append ("0"); - count--; - } - string = buffer.toString (); - } - byte [] buffer = Converter.wcsToMbcs (getCodePage(), string, true); - int xmString = OS.XmStringCreateLocalized (buffer); - int fontList = font.handle; - width = OS.XmStringWidth (fontList, xmString); - OS.XmStringFree (xmString); - } - if (hHint == SWT.DEFAULT) { - height = getFontHeight (font.handle); - } - Rectangle trim = computeTrim (0, 0, width, height); - if (hHint == SWT.DEFAULT) { - int [] argList = {OS.XmNarrowSize, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - trim.height = Math.max (trim.height, argList [1] * 2); - } - return new Point (trim.width, trim.height); -} -public Rectangle computeTrim (int x, int y, int width, int height) { - checkWidget (); - int [] argList1 = { - OS.XmNtextField, 0, - OS.XmNarrowSize, 0, - OS.XmNmarginWidth, 0, - OS.XmNmarginHeight, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int [] argList2 = { - OS.XmNshadowThickness, 0, - OS.XmNhighlightThickness, 0}; - OS.XtGetValues (argList1 [1], argList2, argList2.length / 2); - XRectangle rect = new XRectangle (); - OS.XmWidgetGetDisplayRect (argList1 [1], rect); - x -= argList1 [5] + argList2 [1] + argList2 [3] + rect.x; - y -= argList1 [7] + argList2 [1] + argList2 [3] + rect.y; - width += (argList1 [5] + argList2 [1] + argList2 [3] + rect.x) * 2 + argList1 [3]; - height += (argList1 [7] + argList2 [1] + argList2 [3] + rect.y) * 2; - return new Rectangle (x, y, width, height); -} -/** - * Copies the selected text. - * <p> - * The current selection is copied to the clipboard. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void copy () { - checkWidget (); - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - OS.XmTextCopy (argList [1], OS.XtLastTimestampProcessed (xDisplay)); -} -void createHandle (int index) { - int [] argList1 = { - OS.XmNcolumns, 2, - OS.XmNdecimalPoints, 0, - OS.XmNincrementValue, 1, - OS.XmNminimumValue, 0, - OS.XmNmaximumValue, 100, - OS.XmNspinBoxChildType, OS.XmNUMERIC, - OS.XmNeditable, (style & SWT.READ_ONLY) != 0 ? 0 : 1, - OS.XmNshadowThickness, 0, - OS.XmNancestorSensitive, 1, - }; - int parentHandle = parent.handle; - handle = OS.XmCreateSimpleSpinBox (parentHandle, null, argList1, argList1.length / 2); - int [] argList2 = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList2, argList2.length / 2); - int textHandle = argList2 [1]; - int [] argList3 = { - OS.XmNverifyBell, 0, - OS.XmNcursorPositionVisible, (style & SWT.READ_ONLY) != 0 ? 0 : 1, - }; - OS.XtSetValues (textHandle, argList3, argList3.length / 2); - if ((style & SWT.BORDER) == 0) { - int [] argList4 = new int [] { - /* - * Bug in Motif. Setting the margin width to zero for - * a single line text field causes the field to draw - * garbage when the caret is placed at the start of - * the widget. The fix is to not set the margin width. - */ -// OS.XmNmarginWidth, 0, - OS.XmNmarginHeight, 0, - OS.XmNshadowThickness, 0, - }; - OS.XtSetValues (textHandle, argList4, argList4.length / 2); - } - /* - * Feature in Motif. The Spinner widget is created with a default - * drop target. This is inconsistent with other platforms. - * To be consistent, disable the default drop target. - */ - OS.XmDropSiteUnregister (textHandle); -} -/** - * Cuts the selected text. - * <p> - * The current selection is first copied to the - * clipboard and then deleted from the widget. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void cut () { - checkWidget (); - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - OS.XmTextCut (argList [1], OS.XtLastTimestampProcessed (xDisplay)); -} -void deregister () { - super.deregister (); - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - display.removeWidget (argList[1]); -} -int fontHandle () { - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the number of decimal places used by the receiver. - * - * @return the digits - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getDigits () { - checkWidget (); - int [] argList = {OS.XmNdecimalPoints, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -String getDecimalSeparator () { - int ptr = OS.localeconv_decimal_point (); - int length = OS.strlen (ptr); - byte [] buffer = new byte [length]; - OS.memmove (buffer, ptr, length); - return new String (Converter.mbcsToWcs (null, buffer)); -} -/** - * Returns the amount that the receiver's value will be - * modified by when the up/down arrows are pressed. - * - * @return the increment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getIncrement () { - checkWidget (); - int [] argList = {OS.XmNincrementValue, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the maximum value which the receiver will allow. - * - * @return the maximum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getMaximum () { - checkWidget (); - int [] argList = {OS.XmNmaximumValue, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the minimum value which the receiver will allow. - * - * @return the minimum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getMinimum () { - checkWidget (); - int [] argList = {OS.XmNminimumValue, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns the amount that the receiver's position will be - * modified by when the page up/down keys are pressed. - * - * @return the page increment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getPageIncrement () { - checkWidget (); - return 1; -} -/** - * Returns the <em>selection</em>, which is the receiver's position. - * - * @return the selection - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getSelection () { - checkWidget (); - int [] argList = {OS.XmNposition, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1]; -} -/** - * Returns a string containing a copy of the contents of the - * receiver's text field, or an empty string if there are no - * contents. - * - * @return the receiver's text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.4 - */ -public String getText () { - checkWidget(); - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - - int ptr = OS.XmTextGetString (argList[1]); - if (ptr == 0) return ""; - int length = OS.strlen (ptr); - byte [] buffer = new byte [length]; - OS.memmove (buffer, ptr, length); - OS.XtFree (ptr); - return new String (Converter.mbcsToWcs (getCodePage (), buffer)); -} -/** - * Returns the maximum number of characters that the receiver's - * text field is capable of holding. If this has not been changed - * by <code>setTextLimit()</code>, it will be the constant - * <code>Spinner.LIMIT</code>. - * - * @return the text limit - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #LIMIT - * - * @since 3.4 - */ -public int getTextLimit () { - checkWidget(); - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return OS.XmTextGetMaxLength (argList[1]); -} -void hookEvents () { - super.hookEvents (); - int windowProc = display.windowProc; - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - int textHandle = argList [1]; - OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK); - OS.XtAddCallback (handle, OS.XmNmodifyVerifyCallback, windowProc, MODIFY_VERIFY_CALLBACK); - OS.XtAddCallback (textHandle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK); - OS.XtAddCallback (textHandle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK); - OS.XtAddCallback (textHandle, OS.XmNmodifyVerifyCallback, windowProc, MODIFY_VERIFY_CALLBACK); - OS.XtAddEventHandler (textHandle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS); - OS.XtAddEventHandler (textHandle, OS.ButtonReleaseMask, false, windowProc, BUTTON_RELEASE); - OS.XtAddEventHandler (textHandle, OS.EnterWindowMask, false, windowProc, ENTER_WINDOW); - OS.XtAddEventHandler (textHandle, OS.LeaveWindowMask, false, windowProc, LEAVE_WINDOW); - OS.XtAddEventHandler (textHandle, OS.KeyPressMask, false, windowProc, KEY_PRESS); - OS.XtAddEventHandler (textHandle, OS.KeyReleaseMask, false, windowProc, KEY_RELEASE); - OS.XtInsertEventHandler (textHandle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail); -} -/** - * Pastes text from clipboard. - * <p> - * The selected text is deleted from the widget - * and new text inserted from the clipboard. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void paste () { - checkWidget (); - boolean warnings = display.getWarnings (); - display.setWarnings (false); - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - OS.XmTextFieldPaste (argList [1]); - display.setWarnings (warnings); -} -void register () { - super.register (); - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - display.addWidget (argList [1], this); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's text is modified. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ModifyListener - * @see #addModifyListener - */ -public void removeModifyListener (ModifyListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Modify, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is selected by the user. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener(SelectionListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.Selection, listener); - eventTable.unhook(SWT.DefaultSelection,listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is verified. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see VerifyListener - * @see #addVerifyListener - */ -void removeVerifyListener (VerifyListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Verify, listener); -} -void setBackgroundPixel (int pixel) { - super.setBackgroundPixel (pixel); - int [] argList1 = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int textHandle = argList1 [1]; - int [] argList2 = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0}; - OS.XtGetValues (textHandle, argList2, argList2.length / 2); - OS.XmChangeColor (textHandle, pixel); - OS.XtSetValues (textHandle, argList2, argList2.length / 2); -} -boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - /* - * Feature in Motif. Setting the bounds of a XmSimpleSpinBox - * does not update the size of the inner XmTextFied. The fix - * is to update its size programmatically. - */ - if (resize) { - int [] argList1 = { - OS.XmNtextField, 0, - OS.XmNarrowSize, 0, - OS.XmNmarginWidth, 0, - OS.XmNmarginHeight, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; - OS.XtGetValues (argList1 [1], argList2, argList2.length / 2); - int textWidth = Math.max (width - argList1 [3] - 2 * argList1 [5], 0); - int textHeight = Math.max (height - 2 * argList1 [7], 0); - if (textWidth != argList2 [1] || textHeight != argList2 [3]) { - OS.XtResizeWidget (argList1 [1], textWidth, textHeight, argList2 [5]); - } - } - return super.setBounds (x, y, width, height, move, resize); -} -/** - * Sets the number of decimal places used by the receiver. - * <p> - * The digit setting is used to allow for floating point values in the receiver. - * For example, to set the selection to a floating point value of 1.37 call setDigits() with - * a value of 2 and setSelection() with a value of 137. Similarly, if getDigits() has a value - * of 2 and getSelection() returns 137 this should be interpreted as 1.37. This applies to all - * numeric APIs. - * </p> - * - * @param value the new digits (must be greater than or equal to zero) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the value is less than zero</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setDigits (int value) { - checkWidget (); - if (value < 0) error (SWT.ERROR_INVALID_ARGUMENT); - int [] argList1 = {OS.XmNposition, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int [] argList2 = {OS.XmNdecimalPoints, value, OS.XmNposition, argList1 [1]}; - OS.XtSetValues (handle, argList2, argList2.length / 2); -} -void setForegroundPixel (int pixel) { - int [] argList1 = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - int [] argList2 = {OS.XmNforeground, pixel}; - OS.XtSetValues (argList1 [1], argList2, argList2.length / 2); - super.setForegroundPixel (pixel); -} -/** - * Sets the amount that the receiver's value will be - * modified by when the up/down arrows are pressed to - * the argument, which must be at least one. - * - * @param value the new increment (must be greater than zero) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setIncrement (int value) { - checkWidget (); - if (value < 1) return; - int [] argList = {OS.XmNincrementValue, value}; - OS.XtSetValues (handle, argList, argList.length / 2); -} -/** - * Sets the maximum value that the receiver will allow. This new - * value will be ignored if it is not greater than the receiver's current - * minimum value. If the new maximum is applied then the receiver's - * selection value will be adjusted if necessary to fall within its new range. - * - * @param value the new maximum, which must be greater than the current minimum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMaximum (int value) { - checkWidget (); - int [] argList1 = {OS.XmNminimumValue, 0, OS.XmNposition, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - if (value <= argList1 [1]) return; - int position = argList1 [3]; - if (value < position) position = value; - int [] argList2 = {OS.XmNposition, position, OS.XmNmaximumValue, value}; - OS.XtSetValues (handle, argList2, argList2.length / 2); -} -/** - * Sets the minimum value that the receiver will allow. This new - * value will be ignored if it is not less than the receiver's - * current maximum value. If the new minimum is applied then the receiver's - * selection value will be adjusted if necessary to fall within its new range. - * - * @param value the new minimum, which must be less than the current maximum - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setMinimum (int value) { - checkWidget (); - int [] argList1 = {OS.XmNmaximumValue, 0, OS.XmNposition, 0}; - OS.XtGetValues (handle, argList1, argList1.length / 2); - if (value >= argList1 [1]) return; - int position = argList1 [3]; - if (value > position) position = value; - int [] argList2 = {OS.XmNposition, position, OS.XmNminimumValue, value}; - OS.XtSetValues (handle, argList2, argList2.length / 2); -} -/** - * Sets the amount that the receiver's position will be - * modified by when the page up/down keys are pressed - * to the argument, which must be at least one. - * - * @param value the page increment (must be greater than zero) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setPageIncrement (int value) { - checkWidget (); - if (value < 1) return; -} -/** - * Sets the <em>selection</em>, which is the receiver's - * position, to the argument. If the argument is not within - * the range specified by minimum and maximum, it will be - * adjusted to fall within this range. - * - * @param value the new selection (must be zero or greater) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (int value) { - checkWidget (); - int [] argList = {OS.XmNmaximumValue, 0, OS.XmNminimumValue, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - value = Math.min (Math.max (argList [3], value), argList [1]); - int [] argList1 = {OS.XmNposition, value}; - OS.XtSetValues (handle, argList1, argList1.length / 2); -} -/** - * Sets the maximum number of characters that the receiver's - * text field is capable of holding to be the argument. - * <p> - * To reset this value to the default, use <code>setTextLimit(Spinner.LIMIT)</code>. - * Specifying a limit value larger than <code>Spinner.LIMIT</code> sets the - * receiver's limit to <code>Spinner.LIMIT</code>. - * </p> - * @param limit new text limit - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #LIMIT - * - * @since 3.4 - */ -public void setTextLimit (int limit) { - checkWidget(); - if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO); - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - OS.XmTextSetMaxLength (argList[1], limit); -} -/** - * Sets the receiver's selection, minimum value, maximum - * value, digits, increment and page increment all at once. - * <p> - * Note: This is similar to setting the values individually - * using the appropriate methods, but may be implemented in a - * more efficient fashion on some platforms. - * </p> - * - * @param selection the new selection value - * @param minimum the new minimum value - * @param maximum the new maximum value - * @param digits the new digits value - * @param increment the new increment value - * @param pageIncrement the new pageIncrement value - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.2 - */ -public void setValues (int selection, int minimum, int maximum, int digits, int increment, int pageIncrement) { - checkWidget (); - if (maximum <= minimum) return; - if (digits < 0) return; - if (increment < 1) return; - if (pageIncrement < 1) return; - selection = Math.min (Math.max (minimum, selection), maximum); - int [] argList = { - OS.XmNposition, selection, - OS.XmNmaximumValue, maximum, - OS.XmNminimumValue, minimum, - OS.XmNincrementValue, increment, - OS.XmNdecimalPoints, digits}; - OS.XtSetValues (handle, argList, argList.length / 2); -} - -void updateText () { - int [] argList = { - OS.XmNtextField, 0, /* 1 */ - OS.XmNminimumValue, 0, /* 3 */ - OS.XmNmaximumValue, 0, /* 5 */ - OS.XmNposition, 0, /* 7 */ - OS.XmNdecimalPoints, 0 /* 9 */}; - OS.XtGetValues (handle, argList, argList.length / 2); - int ptr = OS.XmTextGetString (argList [1]); - int position = argList [7]; - int digits = argList [9]; - if (ptr != 0) { - int length = OS.strlen (ptr); - byte [] buffer = new byte [length]; - OS.memmove (buffer, ptr, length); - OS.XtFree (ptr); - String string = new String (Converter.mbcsToWcs (getCodePage (), buffer)); - try { - int value; - if (digits > 0) { - String decimalSeparator = getDecimalSeparator (); - int index = string.indexOf (decimalSeparator); - if (index != -1) { - int startIndex = string.startsWith ("+") || string.startsWith ("-") ? 1 : 0; - String wholePart = startIndex != index ? string.substring (startIndex, index) : "0"; - String decimalPart = string.substring (index + 1); - if (decimalPart.length () > digits) { - decimalPart = decimalPart.substring (0, digits); - } else { - int i = digits - decimalPart.length (); - for (int j = 0; j < i; j++) { - decimalPart = decimalPart + "0"; - } - } - int wholeValue = Integer.parseInt (wholePart); - int decimalValue = Integer.parseInt (decimalPart); - for (int i = 0; i < digits; i++) wholeValue *= 10; - value = wholeValue + decimalValue; - if (string.startsWith ("-")) value = -value; - } else { - value = Integer.parseInt (string); - for (int i = 0; i < digits; i++) value *= 10; - } - } else { - value = Integer.parseInt (string); - } - if (argList [3] <= value && value <= argList [5]) { - position = value; - } - } catch (NumberFormatException e) { - } - } - if (position == argList [7]) { - String string; - if (digits == 0) { - string = String.valueOf (position); - } else { - string = String.valueOf (Math.abs (position)); - String decimalSeparator = getDecimalSeparator (); - int index = string.length () - digits; - StringBuffer buffer = new StringBuffer (); - if (position < 0) buffer.append ("-"); - if (index > 0) { - buffer.append (string.substring (0, index)); - buffer.append (decimalSeparator); - buffer.append (string.substring (index)); - } else { - buffer.append ("0"); - buffer.append (decimalSeparator); - while (index++ < 0) buffer.append ("0"); - buffer.append (string); - } - string = buffer.toString (); - } - byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XmTextSetString (argList [1], buffer); - display.setWarnings (warnings); - } else { - int [] argList2 = {OS.XmNposition, position}; - OS.XtSetValues (handle, argList2, argList2.length / 2); - } -} -int XmNactivateCallback (int w, int client_data, int call_data) { - postEvent (SWT.DefaultSelection); - updateText (); - return 0; -} -int xFocusOut (XFocusChangeEvent xEvent) { - updateText (); - return super.xFocusOut (xEvent); -} -int XmNmodifyVerifyCallback (int w, int client_data, int call_data) { - if (w == handle) { - if ((style & SWT.WRAP) == 0) { - XmSpinBoxCallbackStruct struct = new XmSpinBoxCallbackStruct (); - OS.memmove (struct, call_data, XmSpinBoxCallbackStruct.sizeof); - if (struct.crossed_boundary != 0) { - struct.doit = (byte) 0; - OS.memmove (call_data, struct, XmSpinBoxCallbackStruct.sizeof); - } - } - return 0; - } - int result = super.XmNmodifyVerifyCallback (w, client_data, call_data); - if (result != 0) return result; - - /* - * Feature in Motif. When XtManageChild() is called for - * a text widget that has just been created, the contents - * are assigned and an XmNmodifyVerifyCallback is sent. - * When this happens, the widget has not been fully - * initialized null pointer exceptions can occur. The - * fix is to check for this case and avoid the callback. - * Note that application code could never have seen it - * in the first place. - */ - if (font == null) return result; - -// if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return result; - XmTextVerifyCallbackStruct textVerify = new XmTextVerifyCallbackStruct (); - OS.memmove (textVerify, call_data, XmTextVerifyCallbackStruct.sizeof); - XmTextBlockRec textBlock = new XmTextBlockRec (); - OS.memmove (textBlock, textVerify.text, XmTextBlockRec.sizeof); - byte [] buffer = new byte [textBlock.length]; - OS.memmove (buffer, textBlock.ptr, textBlock.length); - String codePage = getCodePage (); - String text = new String (Converter.mbcsToWcs (codePage, buffer)); - Event event = new Event (); - if (textVerify.event != 0) { - XKeyEvent xEvent = new XKeyEvent (); - OS.memmove (xEvent, textVerify.event, XKeyEvent.sizeof); - event.time = xEvent.time; - setKeyState (event, xEvent); - } - event.start = textVerify.startPos; - event.end = textVerify.endPos; - event.text = text; - String string = text; - int index = 0; - int [] argList = {OS.XmNdecimalPoints, 0, OS.XmNminimumValue, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (argList [1] > 0) { - String decimalSeparator = getDecimalSeparator (); - index = string.indexOf (decimalSeparator); - if (index != -1) { - string = string.substring (0, index) + string.substring (index + 1); - } - index = 0; - } - if (string.length () > 0) { - if (argList [3] < 0 && string.charAt (0) == '-') index++; - } - while (index < string.length ()) { - if (!Character.isDigit (string.charAt (index))) break; - index++; - } - event.doit = index == string.length (); - sendEvent (SWT.Verify, event); - String newText = event.text; - textVerify.doit = (byte) ((event.doit && newText != null) ? 1 : 0); - if (newText != null && newText != text) { - OS.XtFree(textBlock.ptr); - byte [] buffer2 = Converter.wcsToMbcs (codePage, newText, true); - int length = buffer2.length; - int ptr = OS.XtMalloc (length); - OS.memmove (ptr, buffer2, length); - textBlock.ptr = ptr; - textBlock.length = buffer2.length - 1; - OS.memmove (textVerify.text, textBlock, XmTextBlockRec.sizeof); - } - OS.memmove (call_data, textVerify, XmTextVerifyCallbackStruct.sizeof); - return result; -} -int XmNvalueChangedCallback (int w, int client_data, int call_data) { - int [] argList = {OS.XmNtextField, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - if (w == argList [1]) { - sendEvent (SWT.Modify); - } else { - XmAnyCallbackStruct struct = new XmAnyCallbackStruct (); - OS.memmove (struct, call_data, XmAnyCallbackStruct.sizeof); - if (struct.reason == OS.XmCR_OK) { - postEvent (SWT.Selection); - } - } - return 0; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java deleted file mode 100755 index bb1201790a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java +++ /dev/null @@ -1,1739 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class are selectable user interface - * objects that allow the user to enter and modify text. - * Text controls can be either single or multi-line. - * When a text control is created with a border, the - * operating system includes a platform specific inset - * around the contents of the control. When created - * without a border, an effort is made to remove the - * inset such that the preferred size of the control - * is the same size as the contents. - * <p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>CENTER, ICON_CANCEL, ICON_SEARCH, LEFT, MULTI, PASSWORD, SEARCH, SINGLE, RIGHT, READ_ONLY, WRAP</dd> - * <dt><b>Events:</b></dt> - * <dd>DefaultSelection, Modify, Verify</dd> - * </dl> - * <p> - * Note: Only one of the styles MULTI and SINGLE may be specified, - * and only one of the styles LEFT, CENTER, and RIGHT may be specified. - * </p> - * <p> - * Note: The styles ICON_CANCEL and ICON_SEARCH are hints used in combination with SEARCH. - * When the platform supports the hint, the text control shows these icons. When an icon - * is selected, a default selection event is sent with the detail field set to one of - * ICON_CANCEL or ICON_SEARCH. Normally, application code does not need to check the - * detail. In the case of ICON_CANCEL, the text is cleared before the default selection - * event is sent causing the application to search for an empty string. - * </p> - * <p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#text">Text snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class Text extends Scrollable { - char echoCharacter; - boolean ignoreChange; - String hiddenText, message; - int drawCount; - Color disabledColor; - - static final boolean IsGB18030; - /** - * The maximum number of characters that can be entered - * into a text widget. - * <p> - * Note that this value is platform dependent, based upon - * the native widget implementation. - * </p> - */ - public static final int LIMIT; - /** - * The delimiter used by multi-line text widgets. When text - * is queried and from the widget, it will be delimited using - * this delimiter. - */ - public static final String DELIMITER; - - static final RGB MSG_FOREGROUND = new RGB (172, 168, 153); - - /* - * These values can be different on different platforms. - * Therefore they are not initialized in the declaration - * to stop the compiler from inlining. - */ - static { - LIMIT = 0x7FFFFFFF; - DELIMITER = "\n"; - IsGB18030 = Converter.defaultCodePage ().endsWith ("18030"); - } - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#SINGLE - * @see SWT#MULTI - * @see SWT#READ_ONLY - * @see SWT#WRAP - * @see SWT#LEFT - * @see SWT#RIGHT - * @see SWT#CENTER - * @see SWT#PASSWORD - * @see SWT#SEARCH - * @see SWT#ICON_SEARCH - * @see SWT#ICON_CANCEL - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Text (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's text is modified, by sending - * it one of the messages defined in the <code>ModifyListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ModifyListener - * @see #removeModifyListener - */ -public void addModifyListener (ModifyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Modify, typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the control is selected by the user, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * <code>widgetSelected</code> is not called for texts. - * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed in a single-line text, - * or when ENTER is pressed in a search text. If the receiver has the <code>SWT.SEARCH | SWT.CANCEL</code> style - * and the user cancels the search, the event object detail field contains the value <code>SWT.CANCEL</code>. - * </p> - * - * @param listener the listener which should be notified when the control is selected by the user - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener(listener); - addListener(SWT.Selection,typedListener); - addListener(SWT.DefaultSelection,typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's text is verified, by sending - * it one of the messages defined in the <code>VerifyListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see VerifyListener - * @see #removeVerifyListener - */ -public void addVerifyListener (VerifyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Verify, typedListener); -} -/** - * Appends a string. - * <p> - * The new text is appended to the text at - * the end of the widget. - * </p> - * - * @param string the string to be appended - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void append (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - int position = OS.XmTextGetLastPosition (handle); - byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XmTextSetInsertionPosition (handle, position); - OS.XmTextInsert (handle, position, buffer); - position = OS.XmTextGetLastPosition (handle); - OS.XmTextSetInsertionPosition (handle, position); - display.setWarnings(warnings); -} -static int checkStyle (int style) { - if ((style & SWT.SEARCH) != 0) { - style |= SWT.SINGLE | SWT.BORDER; - style &= ~SWT.PASSWORD; - /* - * NOTE: ICON_CANCEL has the same value as H_SCROLL and - * ICON_SEARCH has the same value as V_SCROLL so they are - * cleared because SWT.SINGLE is set. - */ - } - if ((style & SWT.SINGLE) != 0 && (style & SWT.MULTI) != 0) { - style &= ~SWT.MULTI; - } - style = checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0); - if ((style & SWT.SINGLE) != 0) style &= ~(SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP); - if ((style & SWT.WRAP) != 0) { - style |= SWT.MULTI; - style &= ~SWT.H_SCROLL; - } - if ((style & SWT.MULTI) != 0) style &= ~SWT.PASSWORD; - if ((style & (SWT.SINGLE | SWT.MULTI)) != 0) return style; - if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) return style | SWT.MULTI; - return style | SWT.SINGLE; -} -/** - * Clears the selection. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void clearSelection () { - checkWidget(); - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - OS.XmTextClearSelection (handle, OS.XtLastTimestampProcessed (xDisplay)); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - int width = wHint; - int height = hHint; - if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) { - int ptr = OS.XmTextGetString (handle); - if (ptr == 0) return new Point (0, 0); - int size = OS.strlen (ptr); - if (size == 0) { - if (hHint == SWT.DEFAULT) { - if ((style & SWT.SINGLE) != 0) { - height = getLineHeight (); - } else { - height = DEFAULT_HEIGHT; - } - } - if (wHint == SWT.DEFAULT) { - width = DEFAULT_WIDTH; - } - } else { - byte [] buffer = new byte [size + 1]; - OS.memmove (buffer, ptr, size); - boolean wrap = (style & SWT.MULTI) != 0 && (style & SWT.WRAP) != 0; - if (wrap && wHint != SWT.DEFAULT) { - char[] chars = Converter.mbcsToWcs (getCodePage (), buffer); - String text = new String (chars); - String wrapped = display.wrapText (text, font, wHint); - buffer = Converter.wcsToMbcs (getCodePage (), wrapped, true); - } - int xmString; - if ((style & SWT.SINGLE) != 0) { - xmString = OS.XmStringParseText ( - buffer, - 0, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null, - 0, - 0); - } else { - xmString = OS.XmStringGenerate ( - buffer, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null); - } - int fontList = font.handle; - if (hHint == SWT.DEFAULT) { - if ((style & SWT.SINGLE) != 0) { - height = getLineHeight (); - } else { - height = OS.XmStringHeight (fontList, xmString); - } - } - if (wHint == SWT.DEFAULT) width = OS.XmStringWidth (fontList, xmString); - OS.XmStringFree (xmString); - } - OS.XtFree (ptr); - if ((style & SWT.SINGLE) != 0 && message.length () > 0) { - if (wHint == SWT.DEFAULT) { - byte [] buffer = Converter.wcsToMbcs (getCodePage (), message, true); - int xmString = OS.XmStringGenerate ( - buffer, - OS.XmFONTLIST_DEFAULT_TAG, - OS.XmCHARSET_TEXT, - null); - int fontList = font.handle; - width = Math.max (width, OS.XmStringWidth (fontList, xmString)); - OS.XmStringFree (xmString); - } - } - } - Rectangle trim = computeTrim (0, 0, width, height); - return new Point (trim.width, trim.height); -} -public Rectangle computeTrim (int x, int y, int width, int height) { - checkWidget(); - if (horizontalBar != null) { - int [] argList1 = {OS.XmNheight, 0}; - OS.XtGetValues (horizontalBar.handle, argList1, argList1.length / 2); - height += argList1 [1] + 4; - } - if (verticalBar != null) { - int [] argList1 = {OS.XmNwidth, 0}; - OS.XtGetValues (verticalBar.handle, argList1, argList1.length / 2); - width += argList1 [1] + 4; - } - if ((style & SWT.MULTI) != 0) height+=4; - XRectangle rect = new XRectangle (); - OS.XmWidgetGetDisplayRect (handle, rect); - x -= rect.x; - y -= rect.y; - width += rect.x * 2; - height += rect.y * 2; - int shadow = 0, highlight = 0; - if ((style & SWT.MULTI) != 0 || (style & SWT.BORDER) != 0) { - int [] argList = new int [] { - OS.XmNshadowThickness, 0, - OS.XmNhighlightThickness, 0, - }; - OS.XtGetValues (handle, argList, argList.length / 2); - shadow = argList [1]; - highlight = argList [3]; - } - x -= shadow + highlight; - y -= shadow + highlight; - width += (shadow + highlight) * 2; - height += (shadow + highlight) * 2; - return new Rectangle (x, y, width, height); -} -/** - * Copies the selected text. - * <p> - * The current selection is copied to the clipboard. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void copy () { - checkWidget(); - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - OS.XmTextCopy (handle, OS.XtLastTimestampProcessed (xDisplay)); -} -void createHandle (int index) { - int [] argList1 = { - OS.XmNverifyBell, 0, - OS.XmNeditMode, (style & SWT.SINGLE) != 0 ? OS.XmSINGLE_LINE_EDIT : OS.XmMULTI_LINE_EDIT, - OS.XmNscrollHorizontal, (style & SWT.H_SCROLL) != 0 ? 1 : 0, - OS.XmNscrollVertical, (style & SWT.V_SCROLL) != 0 ? 1 : 0, - OS.XmNwordWrap, !IsGB18030 && (style & SWT.WRAP) != 0 ? 1: 0, - OS.XmNeditable, (style & SWT.READ_ONLY) != 0 ? 0 : 1, - OS.XmNcursorPositionVisible, (style & SWT.READ_ONLY) != 0 ? 0 : 1, -// OS.XmNmarginWidth, 3, -// OS.XmNmarginHeight, 1, - OS.XmNancestorSensitive, 1, - }; - int parentHandle = parent.handle; - if ((style & SWT.SINGLE) != 0) { - handle = OS.XmCreateTextField (parentHandle, null, argList1, argList1.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - int [] argList2 = new int [] {OS.XmNcursorPositionVisible, 0}; - OS.XtSetValues (handle, argList2, argList2.length / 2); - } else { - handle = OS.XmCreateScrolledText (parentHandle, new byte [1], argList1, argList1.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - scrolledHandle = OS.XtParent (handle); - } - if ((style & SWT.BORDER) == 0) { - int [] argList3 = new int [] { - /* - * Bug in Motif. Setting the margin width to zero for - * a single line text field causes the field to draw - * garbage when the caret is placed at the start of - * the widget. The fix is to not set the margin width. - */ -// OS.XmNmarginWidth, 0, - OS.XmNmarginHeight, 0, - OS.XmNshadowThickness, 0, - }; - OS.XtSetValues (handle, argList3, argList3.length / 2); - } - /* - * Feature in Motif. The Text widget is created with a default - * drop target. This is inconsistent with other platforms. - * To be consistent, disable the default drop target. - */ - OS.XmDropSiteUnregister (handle); -} -ScrollBar createScrollBar (int type) { - return createStandardBar (type); -} -void createWidget (int index) { - super.createWidget (index); - hiddenText = message = ""; - if ((style & SWT.PASSWORD) != 0) setEchoChar ('*'); - if ((style & SWT.SINGLE) != 0) { - disabledColor = new Color (display, MSG_FOREGROUND); - } -} -/** - * Cuts the selected text. - * <p> - * The current selection is first copied to the - * clipboard and then deleted from the widget. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void cut () { - checkWidget(); - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - OS.XmTextCut (handle, OS.XtLastTimestampProcessed (xDisplay)); -} -int defaultBackground () { - return display.textBackground; -} -Font defaultFont () { - return display.textFont; -} -int defaultForeground () { - return display.textForeground; -} -boolean dragDetect (int x, int y, boolean filter, boolean [] consume) { - if (filter) { - int [] start = new int [1], end = new int [1]; - OS.XmTextGetSelectionPosition (handle, start, end); - if (start [0] != end [0]) { - int pos = OS.XmTextXYToPos(handle, (short) x, (short) y); - if (start [0] <= pos && pos < end [0]) { - if (super.dragDetect (x, y, filter, consume)) { - if (consume != null) consume [0] = true; - return true; - } - } - } - return false; - } - return super.dragDetect (x, y, filter, consume); -} -/** - * Returns the line number of the caret. - * <p> - * The line number of the caret is returned. - * </p> - * - * @return the line number - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getCaretLineNumber () { - checkWidget(); - return getLineNumber (OS.XmTextGetInsertionPosition (handle)); -} -/** - * Returns a point describing the receiver's location relative - * to its parent (or its display if its parent is null). - * <p> - * The location of the caret is returned. - * </p> - * - * @return a point, the location of the caret - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Point getCaretLocation () { - checkWidget(); - int position; - position = OS.XmTextGetInsertionPosition (handle); - short [] x = new short [1], y = new short [1]; - OS.XmTextPosToXY (handle, position, x, y); - return new Point (x [0], y [0] - getFontAscent (font.handle)); -} -/** - * Returns the character position of the caret. - * <p> - * Indexing is zero based. - * </p> - * - * @return the position of the caret - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getCaretPosition () { - checkWidget(); - return OS.XmTextGetInsertionPosition (handle); -} -/** - * Returns the number of characters. - * - * @return number of characters in the widget - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getCharCount () { - checkWidget(); - return OS.XmTextGetLastPosition (handle); -} -/** - * Returns the double click enabled flag. - * <p> - * The double click flag enables or disables the - * default action of the text widget when the user - * double clicks. - * </p> - * - * @return whether or not double click is enabled - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getDoubleClickEnabled () { - checkWidget(); - int [] argList = {OS.XmNselectionArrayCount, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1] != 1; -} -/** - * Returns the echo character. - * <p> - * The echo character is the character that is - * displayed when the user enters text or the - * text is changed by the programmer. - * </p> - * - * @return the echo character - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #setEchoChar - */ -public char getEchoChar () { - checkWidget(); - return echoCharacter; -} -/** - * Returns the editable state. - * - * @return whether or not the receiver is editable - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getEditable () { - checkWidget(); - /* - * Bug in MOTIF. For some reason, when XmTextGetEditable () is called - * from inside an XmNvalueChangedCallback or XmNModifyVerifyCallback, - * it always returns TRUE. Calls to XmTextGetEditable () outside of - * these callbacks return the correct value. The fix is to query the - * resource directly instead of using the convenience function. - */ - int [] argList = {OS.XmNeditable, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1] != 0; -} -/** - * Returns the number of lines. - * - * @return the number of lines in the widget - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getLineCount () { - checkWidget(); - if ((style & SWT.SINGLE) != 0) return 1; - int lastChar = echoCharacter != '\0' ? hiddenText.length () : OS.XmTextGetLastPosition (handle); - return getLineNumber (lastChar) + 1; -} -/** - * Returns the line delimiter. - * - * @return a string that is the line delimiter - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #DELIMITER - */ -public String getLineDelimiter () { - checkWidget(); - return "\n"; -} -/** - * Returns the height of a line. - * - * @return the height of a row of text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getLineHeight () { - checkWidget(); - return getFontHeight (font.handle); -} -int getLineNumber (int position) { - if (position == 0) return 0; - int count = 0, start = 0, page = 1024; - char [] buffer = new char [page + 1]; - /* - * Bug in Linux. For some reason, XmTextGetSubstringWcs () does - * not copy wchar_t characters into the buffer. Instead, it - * copies 4 bytes per character. This does not happen on other - * platforms such as AIX. The fix is to call XmTextGetSubstring () - * instead on Linux and rely on the fact that Metrolink Motif 1.2 - * does not support multibyte locales. - */ - byte [] buffer1 = null; - if (OS.IsLinux) buffer1 = new byte [page + 1]; - int end = ((position + page - 1) / page) * page; - while (start < end) { - int length = page; - if (start + page > position) length = position - start; - if (echoCharacter != '\0') { - hiddenText.getChars (start, start + length, buffer, 0); - } else { - if (OS.IsLinux) { - OS.XmTextGetSubstring (handle, start, length, buffer1.length, buffer1); - for (int i=0; i<length; i++) buffer [i] = (char) buffer1 [i]; - } else { - OS.XmTextGetSubstringWcs (handle, start, length, buffer.length, buffer); - } - } - for (int i=0; i<length; i++) { - if (buffer [i] == '\n') count++; - } - start += page; - } - return count; -} -/** - * Returns the widget message. The message text is displayed - * as a hint for the user, indicating the purpose of the field. - * <p> - * Typically this is used in conjunction with <code>SWT.SEARCH</code>. - * </p> - * - * @return the widget message - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.3 - */ -public String getMessage () { - checkWidget (); - return message; -} -int getNavigationType () { - /* - * Bug in Motif. On Solaris only, the implementation - * of XtGetValues for XmText does not check for a zero - * pointer in the arg list and GP's. The fix is to - * allocate and free memory for the arg list value. - */ - if ((style & SWT.SINGLE) != 0) { - return super.getNavigationType (); - } - int ptr = OS.XtMalloc (4); - if (ptr == 0) return OS.XmNONE; - int [] argList = {OS.XmNnavigationType, ptr}; - OS.XtGetValues (handle, argList, argList.length / 2); - int [] buffer = new int [1]; - OS.memmove (buffer, ptr, 4); - OS.XtFree (ptr); - return buffer [0]; -} -/** - * Returns the orientation of the receiver, which will be one of the - * constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>. - * - * @return the orientation style - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.1.2 - */ -public int getOrientation () { - checkWidget(); - return style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT); -} -/*public*/ int getPosition (Point point) { - checkWidget (); - if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - return OS.XmTextXYToPos(handle, (short) point.x, (short) point.y); -} -/** - * Returns a <code>Point</code> whose x coordinate is the - * character position representing the start of the selected - * text, and whose y coordinate is the character position - * representing the end of the selection. An "empty" selection - * is indicated by the x and y coordinates having the same value. - * <p> - * Indexing is zero based. The range of a selection is from - * 0..N where N is the number of characters in the widget. - * </p> - * - * @return a point representing the selection start and end - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Point getSelection () { - checkWidget(); - int [] start = new int [1], end = new int [1]; - OS.XmTextGetSelectionPosition (handle, start, end); - if (start [0] == end [0]) { - start [0] = end [0] = OS.XmTextGetInsertionPosition (handle); - } - return new Point (start [0], end [0]); -} -/** - * Returns the number of selected characters. - * - * @return the number of selected characters. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getSelectionCount () { - checkWidget(); - int [] start = new int [1], end = new int [1]; - OS.XmTextGetSelectionPosition (handle, start, end); - return end [0] - start [0]; -} -/** - * Gets the selected text, or an empty string if there is no current selection. - * - * @return the selected text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getSelectionText () { - checkWidget(); - if (echoCharacter != '\0') { - Point selection = getSelection (); - return getText (selection.x, selection.y); - } - int ptr = OS.XmTextGetSelection (handle); - if (ptr == 0) return ""; - int length = OS.strlen (ptr); - byte [] buffer = new byte [length]; - OS.memmove (buffer, ptr, length); - OS.XtFree (ptr); - return new String (Converter.mbcsToWcs (getCodePage (), buffer)); -} -/** - * Returns the number of tabs. - * <p> - * Tab stop spacing is specified in terms of the - * space (' ') character. The width of a single - * tab stop is the pixel width of the spaces. - * </p> - * - * @return the number of tab characters - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getTabs () { - checkWidget(); - /* Tabs are not supported in MOTIF. */ - return 8; -} -/** - * Returns the widget text. - * <p> - * The text for a text widget is the characters in the widget, or - * an empty string if this has never been set. - * </p> - * - * @return the widget text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getText () { - checkWidget(); - if (echoCharacter != '\0') return hiddenText; - int ptr = OS.XmTextGetString (handle); - if (ptr == 0) return ""; - int length = OS.strlen (ptr); - byte [] buffer = new byte [length]; - OS.memmove (buffer, ptr, length); - OS.XtFree (ptr); - return new String (Converter.mbcsToWcs (getCodePage (), buffer)); -} -/** - * Returns a range of text. Returns an empty string if the - * start of the range is greater than the end. - * <p> - * Indexing is zero based. The range of - * a selection is from 0..N-1 where N is - * the number of characters in the widget. - * </p> - * - * @param start the start of the range - * @param end the end of the range - * @return the range of text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getText (int start, int end) { - checkWidget(); - if (!(start <= end && 0 <= end)) return ""; - boolean hasEcho = echoCharacter != '\0'; - int length = hasEcho ? hiddenText.length () : OS.XmTextGetLastPosition (handle); - if (length == 0) return ""; - end = Math.min (end, length - 1); - if (start > end) return ""; - start = Math.max (0, start); - if (hasEcho) return hiddenText.substring (start, end + 1); - int numChars = end - start + 1; - int bufLength = numChars * OS.MB_CUR_MAX () + 1; - byte [] buffer = new byte [bufLength]; - int code = OS.XmTextGetSubstring (handle, start, numChars, bufLength, buffer); - switch (code) { - case OS.XmCOPY_FAILED: - case OS.XmCOPY_TRUNCATED: - error (SWT.ERROR_CANNOT_GET_TEXT); - } - char [] unicode = Converter.mbcsToWcs (getCodePage (), buffer); - return new String (unicode, 0, numChars); -} -/** - * Returns the maximum number of characters that the receiver is capable of holding. - * <p> - * If this has not been changed by <code>setTextLimit()</code>, - * it will be the constant <code>Text.LIMIT</code>. - * </p> - * - * @return the text limit - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #LIMIT - */ -public int getTextLimit () { - checkWidget(); - return OS.XmTextGetMaxLength (handle); -} -/** - * Returns the zero-relative index of the line which is currently - * at the top of the receiver. - * <p> - * This index can change when lines are scrolled or new lines are added or removed. - * </p> - * - * @return the index of the top line - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getTopIndex () { - checkWidget(); - if ((style & SWT.SINGLE) != 0) return 0; - if (scrolledHandle == 0) return 0; - int [] argList1 = {OS.XmNverticalScrollBar, 0}; - OS.XtGetValues (scrolledHandle, argList1, argList1.length / 2); - if (argList1 [1] == 0) return 0; - int [] argList2 = {OS.XmNvalue, 0}; - OS.XtGetValues (argList1 [1], argList2, argList2.length / 2); - return argList2 [1]; -} -/** - * Returns the top pixel. - * <p> - * The top pixel is the pixel position of the line - * that is currently at the top of the widget. On - * some platforms, a text widget can be scrolled by - * pixels instead of lines so that a partial line - * is displayed at the top of the widget. - * </p><p> - * The top pixel changes when the widget is scrolled. - * The top pixel does not include the widget trimming. - * </p> - * - * @return the pixel position of the top line - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getTopPixel () { - checkWidget(); - return getTopIndex () * getLineHeight (); -} -boolean hasIMSupport() { - return true; -} -void hookEvents () { - super.hookEvents (); - int windowProc = display.windowProc; - OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK); - OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK); - OS.XtAddCallback (handle, OS.XmNmodifyVerifyCallback, windowProc, MODIFY_VERIFY_CALLBACK); -} -int inputContext () { - /* Answer zero. The text widget uses the default MOTIF input context. */ - return 0; -} -/** - * Inserts a string. - * <p> - * The old selection is replaced with the new text. - * </p> - * - * @param string the string - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is <code>null</code></li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void insert (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - int [] start = new int [1], end = new int [1]; - OS.XmTextGetSelectionPosition (handle, start, end); - if (start [0] == end [0]) { - start [0] = end [0] = OS.XmTextGetInsertionPosition (handle); - } - byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XmTextReplace (handle, start [0], end [0], buffer); - int position = start [0] + Math.max (0, buffer.length - 1); - OS.XmTextSetInsertionPosition (handle, position); - display.setWarnings (warnings); -} -void overrideTranslations () { - if ((style & SWT.SINGLE) != 0) { - OS.XtOverrideTranslations (handle, display.tabTranslations); - } -} -/** - * Pastes text from clipboard. - * <p> - * The selected text is deleted from the widget - * and new text inserted from the clipboard. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void paste () { - checkWidget(); - boolean warnings = display.getWarnings (); - display.setWarnings (false); - /* - * Bug in Motif. Despite the fact that the documentation - * claims that XmText functions work for XmTextFields, when - * a text field is passed to XmTextPaste, Motif segment faults. - * The fix is to call XmTextFieldPaste instead. - */ - if ((style & SWT.SINGLE) != 0) { - OS.XmTextFieldPaste (handle); - } else { - OS.XmTextPaste (handle); - } - display.setWarnings (warnings); -} -void releaseWidget () { - super.releaseWidget (); - hiddenText = message = null; - if (disabledColor != null) disabledColor.dispose (); - disabledColor = null; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's text is modified. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ModifyListener - * @see #addModifyListener - */ -public void removeModifyListener (ModifyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Modify, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is selected by the user. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.Selection, listener); - eventTable.unhook(SWT.DefaultSelection,listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is verified. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see VerifyListener - * @see #addVerifyListener - */ -public void removeVerifyListener (VerifyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Verify, listener); -} -boolean sendIMKeyEvent (int type, XKeyEvent xEvent) { - return super.sendIMKeyEvent (type, xEvent, handle); -} -/** - * Selects all the text in the receiver. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void selectAll () { - checkWidget(); - /* Clear the highlight before setting the selection. */ - int position = OS.XmTextGetLastPosition (handle); -// OS.XmTextSetHighlight (handle, 0, position, OS.XmHIGHLIGHT_NORMAL); - - /* - * Bug in MOTIF. XmTextSetSelection () fails to set the - * selection when the receiver is not realized. The fix - * is to force the receiver to be realized by forcing the - * shell to be realized. If the receiver is realized before - * the shell, MOTIF fails to draw the text widget and issues - * lots of X BadDrawable errors. - */ - if (!OS.XtIsRealized (handle)) getShell ().realizeWidget (); - - /* Set the selection. */ - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XmTextSetSelection (handle, 0, position, OS.XtLastTimestampProcessed (xDisplay)); - - /* Force the i-beam to follow the highlight/selection. */ - OS.XmTextSetInsertionPosition (handle, 0); - display.setWarnings (warnings); -} -boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - /* - * Bug in Motif. For some reason an Xm warning is - * output whenever a Text widget's caret is beyond - * the visible region during a resize. The fix is - * to temporarily turn off warnings below. - */ - boolean warnings = display.getWarnings (); - display.setWarnings (false); - boolean changed = super.setBounds (x, y, width, height, move, resize); - display.setWarnings(warnings); - return changed; -} -/** - * Sets the double click enabled flag. - * <p> - * The double click flag enables or disables the - * default action of the text widget when the user - * double clicks. - * </p><p> - * Note: This operation is a hint and is not supported on - * platforms that do not have this concept. - * </p> - * - * @param doubleClick the new double click flag - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setDoubleClickEnabled (boolean doubleClick) { - checkWidget(); - int [] argList = {OS.XmNselectionArrayCount, doubleClick ? 4 : 1}; - OS.XtSetValues (handle, argList, argList.length / 2); -} -/** - * Sets the echo character. - * <p> - * The echo character is the character that is - * displayed when the user enters text or the - * text is changed by the programmer. Setting - * the echo character to '\0' clears the echo - * character and redraws the original text. - * If for any reason the echo character is invalid, - * or if the platform does not allow modification - * of the echo character, the default echo character - * for the platform is used. - * </p> - * - * @param echo the new echo character - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setEchoChar (char echo) { - checkWidget(); - if ((style & SWT.MULTI) != 0) return; - if (echoCharacter == echo) return; - String newText; - if (echo == 0) { - newText = hiddenText; - hiddenText = ""; - } else { - newText = hiddenText = getText(); - } - echoCharacter = echo; - Point selection = getSelection(); - boolean oldValue = ignoreChange; - ignoreChange = true; - setText(newText); - setSelection(selection); - ignoreChange = oldValue; -} -/** - * Sets the editable state. - * - * @param editable the new editable state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setEditable (boolean editable) { - checkWidget(); - OS.XmTextSetEditable (handle, editable); - style &= ~SWT.READ_ONLY; - if (!editable) style |= SWT.READ_ONLY; - if ((style & SWT.MULTI) != 0) return; - int [] argList = {OS.XmNcursorPositionVisible, editable && hasFocus () ? 1 : 0}; - OS.XtSetValues (handle, argList, argList.length / 2); -} -/** - * Sets the widget message. The message text is displayed - * as a hint for the user, indicating the purpose of the field. - * <p> - * Typically this is used in conjunction with <code>SWT.SEARCH</code>. - * </p> - * - * @param message the new message - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the message is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 3.3 - */ -public void setMessage (String message) { - checkWidget (); - if (message == null) error (SWT.ERROR_NULL_ARGUMENT); - this.message = message; - redrawHandle (0, 0, 0, 0, true, handle); -} -/** - * Sets the orientation of the receiver, which must be one - * of the constants <code>SWT.LEFT_TO_RIGHT</code> or <code>SWT.RIGHT_TO_LEFT</code>. - * <p> - * Note: This operation is a hint and is not supported on - * platforms that do not have this concept. - * </p> - * - * @param orientation new orientation style - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @since 2.1.2 - */ -public void setOrientation (int orientation) { - checkWidget(); -} -public void setRedraw (boolean redraw) { - checkWidget(); - if ((style & SWT.SINGLE) != 0) return; - if (redraw) { - if (--drawCount == 0) OS.XmTextEnableRedisplay(handle); - } else { - if (drawCount++ == 0) OS.XmTextDisableRedisplay(handle); - } -} -/** - * Sets the selection. - * <p> - * Indexing is zero based. The range of - * a selection is from 0..N where N is - * the number of characters in the widget. - * </p><p> - * Text selections are specified in terms of - * caret positions. In a text widget that - * contains N characters, there are N+1 caret - * positions, ranging from 0..N. This differs - * from other functions that address character - * position such as getText () that use the - * regular array indexing rules. - * </p> - * - * @param start new caret position - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (int start) { - checkWidget(); - /* Clear the selection and highlight before moving the i-beam. */ - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - int position = OS.XmTextGetLastPosition (handle); - int nStart = Math.min (Math.max (start, 0), position); - boolean warnings = display.getWarnings (); - display.setWarnings (false); -// OS.XmTextSetHighlight (handle, 0, position, OS.XmHIGHLIGHT_NORMAL); - OS.XmTextClearSelection (handle, OS.XtLastTimestampProcessed (xDisplay)); - - /* Set the i-beam position. */ - OS.XmTextSetInsertionPosition (handle, nStart); - display.setWarnings (warnings); -} -/** - * Sets the selection to the range specified - * by the given start and end indices. - * <p> - * Indexing is zero based. The range of - * a selection is from 0..N where N is - * the number of characters in the widget. - * </p><p> - * Text selections are specified in terms of - * caret positions. In a text widget that - * contains N characters, there are N+1 caret - * positions, ranging from 0..N. This differs - * from other functions that address character - * position such as getText () that use the - * usual array indexing rules. - * </p> - * - * @param start the start of the range - * @param end the end of the range - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (int start, int end) { - checkWidget(); - /* Clear the highlight before setting the selection. */ - int position = OS.XmTextGetLastPosition (handle); -// OS.XmTextSetHighlight (handle, 0, position, OS.XmHIGHLIGHT_NORMAL); - - /* - * Bug in MOTIF. XmTextSetSelection () fails to set the - * selection when the receiver is not realized. The fix - * is to force the receiver to be realized by forcing the - * shell to be realized. If the receiver is realized before - * the shell, MOTIF fails to draw the text widget and issues - * lots of X BadDrawable errors. - */ - if (!OS.XtIsRealized (handle)) getShell ().realizeWidget (); - - /* Set the selection. */ - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - start = Math.min (Math.max (start, 0), position); - end = Math.min (Math.max (end, 0), position); - int nStart = Math.min (start, end), nEnd = Math.max (start, end); - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XmTextSetSelection (handle, nStart, nEnd, OS.XtLastTimestampProcessed (xDisplay)); - - /* Force the i-beam to follow the highlight/selection. */ - if (start > end) { - OS.XmTextSetInsertionPosition (handle, nStart); - } else { - OS.XmTextSetInsertionPosition (handle, nEnd); - } - display.setWarnings (warnings); -} -/** - * Sets the selection to the range specified - * by the given point, where the x coordinate - * represents the start index and the y coordinate - * represents the end index. - * <p> - * Indexing is zero based. The range of - * a selection is from 0..N where N is - * the number of characters in the widget. - * </p><p> - * Text selections are specified in terms of - * caret positions. In a text widget that - * contains N characters, there are N+1 caret - * positions, ranging from 0..N. This differs - * from other functions that address character - * position such as getText () that use the - * usual array indexing rules. - * </p> - * - * @param selection the point - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the point is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (Point selection) { - checkWidget(); - if (selection == null) error (SWT.ERROR_NULL_ARGUMENT); - setSelection (selection.x, selection.y); -} -/** - * Sets the number of tabs. - * <p> - * Tab stop spacing is specified in terms of the - * space (' ') character. The width of a single - * tab stop is the pixel width of the spaces. - * </p> - * - * @param tabs the number of tabs - * - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setTabs (int tabs) { - checkWidget(); - /* Do nothing. Tabs are not supported in MOTIF. */ -} -/** - * Sets the contents of the receiver to the given string. If the receiver has style - * SINGLE and the argument contains multiple lines of text, the result of this - * operation is undefined and may vary from platform to platform. - * - * @param string the new text - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.XmTextSetString (handle, buffer); - OS.XmTextSetInsertionPosition (handle, 0); - display.setWarnings(warnings); -} -/** - * Sets the maximum number of characters that the receiver - * is capable of holding to be the argument. - * <p> - * Instead of trying to set the text limit to zero, consider - * creating a read-only text widget. - * </p><p> - * To reset this value to the default, use <code>setTextLimit(Text.LIMIT)</code>. - * Specifying a limit value larger than <code>Text.LIMIT</code> sets the - * receiver's limit to <code>Text.LIMIT</code>. - * </p> - * - * @param limit new text limit - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_CANNOT_BE_ZERO - if the limit is zero</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #LIMIT - */ -public void setTextLimit (int limit) { - checkWidget(); - if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO); - OS.XmTextSetMaxLength (handle, limit); -} -/** - * Sets the zero-relative index of the line which is currently - * at the top of the receiver. This index can change when lines - * are scrolled or new lines are added and removed. - * - * @param index the index of the top item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setTopIndex (int index) { - checkWidget(); - if ((style & SWT.SINGLE) != 0) return; - if (scrolledHandle == 0) return; - int [] argList1 = {OS.XmNverticalScrollBar, 0}; - OS.XtGetValues (scrolledHandle, argList1, argList1.length / 2); - if (argList1 [1] == 0) return; - int [] argList2 = {OS.XmNvalue, 0}; - OS.XtGetValues (argList1 [1], argList2, argList2.length / 2); - OS.XmTextScroll (handle, index - argList2 [1]); -} -/** - * Shows the selection. - * <p> - * If the selection is already showing - * in the receiver, this method simply returns. Otherwise, - * lines are scrolled until the selection is visible. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void showSelection () { - checkWidget(); - boolean warnings = display.getWarnings (); - display.setWarnings (false); - int position = OS.XmTextGetInsertionPosition (handle); - OS.XmTextShowPosition (handle, position); - display.setWarnings (warnings); -} -int traversalCode (int key, XKeyEvent xEvent) { - int bits = super.traversalCode (key, xEvent); - if ((style & SWT.READ_ONLY) != 0) return bits; - if ((style & SWT.MULTI) != 0) { - bits &= ~SWT.TRAVERSE_RETURN; - if (key == OS.XK_Tab && xEvent != null) { - boolean next = (xEvent.state & OS.ShiftMask) == 0; - if (next && (xEvent.state & OS.ControlMask) == 0) { - bits &= ~(SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS); - } - } - } - return bits; -} -int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) { - if ((style & SWT.SINGLE) != 0 && message.length () > 0) { - if (!hasFocus () && OS.XmTextGetLastPosition (handle) == 0) { - /* - * Feature in Motif. XmText fills its background during exposure - * without respecting the damage clipping. This erases all previous - * paints. The fix is always to draw the entire content ignoring - * the damage. - */ - int [] argList = new int [] { - OS.XmNmarginWidth, 0, - OS.XmNmarginHeight, 0, - OS.XmNshadowThickness, 0, - OS.XmNhighlightThickness, 0, - OS.XmNwidth, 0, - OS.XmNheight, 0, - }; - OS.XtGetValues (handle, argList, argList.length / 2); - int marginWidth = argList [1] + argList[5] + argList[7]; - int marginHeight = argList [3] + argList[5] + argList[7]; - Rectangle rect = new Rectangle (marginWidth, marginHeight, argList [9] - 2 * marginWidth, argList [11] - 2 * marginHeight); - GCData data = new GCData (); - GC gc = GC.motif_new (this, data); - gc.setForeground (disabledColor); - gc.setClipping (rect); - gc.drawString (message, rect.x, rect.y, true); - gc.dispose (); - } - } - return super.XExposure (w, client_data, call_data, continue_to_dispatch); -} -int xFocusIn (XFocusChangeEvent xEvent) { - super.xFocusIn (xEvent); - // widget could be disposed at this point - if (handle == 0) return 0; - if ((style & (SWT.READ_ONLY | SWT.SINGLE)) != 0) { - int [] argList = {OS.XmNcursorPositionVisible, 1}; - OS.XtSetValues (handle, argList, argList.length / 2); - } - if ((style & SWT.SEARCH) != 0) { - redrawHandle (0, 0, 0, 0, true, handle); - } - return 0; -} -int xFocusOut (XFocusChangeEvent xEvent) { - super.xFocusOut (xEvent); - // widget could be disposed at this point - if (handle == 0) return 0; - if ((style & (SWT.READ_ONLY | SWT.SINGLE)) != 0) { - int [] argList = {OS.XmNcursorPositionVisible, 0}; - OS.XtSetValues (handle, argList, argList.length / 2); - } - if ((style & SWT.SEARCH) != 0) { - redrawHandle (0, 0, 0, 0, true, handle); - } - return 0; -} -int XmNactivateCallback (int w, int client_data, int call_data) { - postEvent (SWT.DefaultSelection); - return 0; -} -int XmNmodifyVerifyCallback (int w, int client_data, int call_data) { - int result = super.XmNmodifyVerifyCallback (w, client_data, call_data); - if (result != 0) return result; - if (echoCharacter == '\0' && !hooks (SWT.Verify) && !filters (SWT.Verify)) return result; - XmTextVerifyCallbackStruct textVerify = new XmTextVerifyCallbackStruct (); - OS.memmove (textVerify, call_data, XmTextVerifyCallbackStruct.sizeof); - XmTextBlockRec textBlock = new XmTextBlockRec (); - OS.memmove (textBlock, textVerify.text, XmTextBlockRec.sizeof); - byte [] buffer = new byte [textBlock.length]; - OS.memmove (buffer, textBlock.ptr, textBlock.length); - String codePage = getCodePage (); - String text = new String (Converter.mbcsToWcs (codePage, buffer)); - String newText = text; - if (!ignoreChange) { - Event event = new Event (); - if (textVerify.event != 0) { - XKeyEvent xEvent = new XKeyEvent (); - OS.memmove (xEvent, textVerify.event, XKeyEvent.sizeof); - event.time = xEvent.time; - setKeyState (event, xEvent); - } - event.start = textVerify.startPos; - event.end = textVerify.endPos; - event.doit = textVerify.doit == 1; - event.text = text; - sendEvent (SWT.Verify, event); - newText = event.text; - textVerify.doit = (byte) ((event.doit && newText != null) ? 1 : 0); - } - if (newText != null) { - if (echoCharacter != '\0' && (textVerify.doit != 0)) { - String prefix = hiddenText.substring (0, textVerify.startPos); - String suffix = hiddenText.substring (textVerify.endPos, hiddenText.length ()); - hiddenText = prefix + newText + suffix; - char [] charBuffer = new char [newText.length ()]; - for (int i=0; i<charBuffer.length; i++) { - charBuffer [i] = echoCharacter; - } - newText = new String (charBuffer); - } - if (newText != text) { - OS.XtFree(textBlock.ptr); - byte [] buffer2 = Converter.wcsToMbcs (codePage, newText, true); - int length = buffer2.length; - int ptr = OS.XtMalloc (length); - OS.memmove (ptr, buffer2, length); - textBlock.ptr = ptr; - textBlock.length = buffer2.length - 1; - OS.memmove (textVerify.text, textBlock, XmTextBlockRec.sizeof); - } - } - OS.memmove (call_data, textVerify, XmTextVerifyCallbackStruct.sizeof); - return result; -} -int XmNvalueChangedCallback (int w, int client_data, int call_data) { - if (!ignoreChange) sendEvent (SWT.Modify); - return 0; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java deleted file mode 100755 index a9d66b0d96..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java +++ /dev/null @@ -1,517 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class support the layout of selectable - * tool bar items. - * <p> - * The item children that may be added to instances of this class - * must be of type <code>ToolItem</code>. - * </p><p> - * Note that although this class is a subclass of <code>Composite</code>, - * it does not make sense to add <code>Control</code> children to it, - * or set a layout on it. - * </p><p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>FLAT, WRAP, RIGHT, HORIZONTAL, VERTICAL, SHADOW_OUT</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#toolbar">ToolBar, ToolItem snippets</a> - * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: ControlExample</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class ToolBar extends Composite { - int drawCount, itemCount; - ToolItem [] items; - ToolItem lastFocus; -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#FLAT - * @see SWT#WRAP - * @see SWT#RIGHT - * @see SWT#HORIZONTAL - * @see SWT#SHADOW_OUT - * @see SWT#VERTICAL - * @see Widget#checkSubclass() - * @see Widget#getStyle() - */ -public ToolBar (Composite parent, int style) { - super (parent, checkStyle (style)); - - /* - * Ensure that either HORIZONTAL or VERTICAL is set. - * NOTE: HORIZONTAL and VERTICAL have the same values - * as H_SCROLL and V_SCROLL so it is necessary to first - * clear these bits to avoid scroll bars and then reset - * the bits using the original style supplied by the - * programmer. - */ - if ((style & SWT.VERTICAL) != 0) { - this.style |= SWT.VERTICAL; - } else { - this.style |= SWT.HORIZONTAL; - } -} -static int checkStyle (int style) { - /* - * Even though it is legal to create this widget - * with scroll bars, they serve no useful purpose - * because they do not automatically scroll the - * widget's client area. The fix is to clear - * the SWT style. - */ - return style & ~(SWT.H_SCROLL | SWT.V_SCROLL); -} -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - int width = wHint, height = hHint; - if (wHint == SWT.DEFAULT) width = 0x7FFFFFFF; - if (hHint == SWT.DEFAULT) height = 0x7FFFFFFF; - int [] result = layout (width, height, false); - int border = getBorderWidth () * 2; - Point extent = new Point (result [1], result [2]); - if (wHint != SWT.DEFAULT) extent.x = wHint; - if (hHint != SWT.DEFAULT) extent.y = hHint; - extent.x += border; - extent.y += border; - return extent; -} -void createHandle (int index) { - super.createHandle (index); - state &= ~CANVAS; -} -void createItem (ToolItem item, int index) { - if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE); - if (itemCount == items.length) { - ToolItem [] newItems = new ToolItem [itemCount + 4]; - System.arraycopy (items, 0, newItems, 0, items.length); - items = newItems; - } - item.createWidget (index); - System.arraycopy (items, index, items, index + 1, itemCount++ - index); - items [index] = item; - relayout (); -} -void createWidget (int index) { - super.createWidget (index); - items = new ToolItem [4]; - itemCount = 0; -} -void destroyItem (ToolItem item) { - int index = 0; - while (index < itemCount) { - if (items [index] == item) break; - index++; - } - if (index == itemCount) return; - System.arraycopy (items, index + 1, items, index, --itemCount - index); - items [itemCount] = null; -} -public boolean forceFocus () { - checkWidget (); - if (display.focusEvent == SWT.FocusOut) return false; - Decorations shell = menuShell (); - shell.setSavedFocus (this); - shell.bringToTop (false); - if (lastFocus != null && lastFocus.setFocus ()) return true; - for (int i = 0; i < itemCount; i++) { - ToolItem item = items [i]; - if (item.setFocus ()) return true; - } - return super.forceFocus (); -} -/** - * Returns the item at the given, zero-relative index in the - * receiver. Throws an exception if the index is out of range. - * - * @param index the index of the item to return - * @return the item at the given index - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public ToolItem getItem (int index) { - checkWidget(); - if (0 <= index && index < itemCount) return items [index]; - error (SWT.ERROR_INVALID_RANGE); - return null; -} - -/** - * Returns the item at the given point in the receiver - * or null if no such item exists. The point is in the - * coordinate system of the receiver. - * - * @param point the point used to locate the item - * @return the item at the given point - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the point is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public ToolItem getItem (Point pt) { - checkWidget(); - if (pt == null) error (SWT.ERROR_NULL_ARGUMENT); - for (int i=0; i<itemCount; i++) { - Rectangle rect = items [i].getBounds (); - if (rect.contains (pt)) return items [i]; - } - return null; -} - -/** - * Returns the number of items contained in the receiver. - * - * @return the number of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getItemCount () { - checkWidget(); - return itemCount; -} -/** - * Returns an array of <code>ToolItem</code>s which are the items - * in the receiver. - * <p> - * Note: This is not the actual structure used by the receiver - * to maintain its list of items, so modifying the array will - * not affect the receiver. - * </p> - * - * @return the items in the receiver - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public ToolItem [] getItems () { - checkWidget(); - ToolItem [] result = new ToolItem [itemCount]; - System.arraycopy (items, 0, result, 0, itemCount); - return result; -} -/** - * Returns the number of rows in the receiver. When - * the receiver has the <code>WRAP</code> style, the - * number of rows can be greater than one. Otherwise, - * the number of rows is always one. - * - * @return the number of items - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getRowCount () { - checkWidget(); - Rectangle rect = getClientArea (); - return layout (rect.width, rect.height, false) [0]; -} -/** - * Searches the receiver's list starting at the first item - * (index 0) until an item is found that is equal to the - * argument, and returns the index of that item. If no item - * is found, returns -1. - * - * @param item the search item - * @return the index of the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the tool item is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the tool item has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int indexOf (ToolItem item) { - checkWidget(); - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - for (int i=0; i<itemCount; i++) { - if (items [i] == item) return i; - } - return -1; -} -int [] layoutHorizontal (int width, int height, boolean resize) { - int xSpacing = 0, ySpacing = (style & SWT.NO_FOCUS) != 0 ? 4 : 2; - int marginWidth = 0, marginHeight = 0; - int x = marginWidth, y = marginHeight; - int maxX = 0, rows = 1; - boolean wrap = (style & SWT.WRAP) != 0; - int itemHeight = 0; - Point [] sizes = new Point [itemCount]; - GC gc = new GC (this); - for (int i=0; i<itemCount; i++) { - Point size = sizes [i] = items [i].computeSize (gc); - itemHeight = Math.max (itemHeight, size.y); - } - for (int i=0; i<itemCount; i++) { - ToolItem item = items [i]; - Point size = sizes [i]; - if (wrap && i != 0 && x + size.x > width) { - rows++; - x = marginWidth; - y += ySpacing + itemHeight; - } - if (resize) { - item.setBounds (x, y, size.x, itemHeight); - boolean visible = x + size.x <= width && y + itemHeight <= height; - item.setVisible (visible); - Control control = item.control; - if (control != null) { - int controlY = y + (itemHeight - size.y) / 2; - control.setBounds (x, controlY, size.x, itemHeight - (controlY - y)); - } - } - x += xSpacing + size.x; - maxX = Math.max (maxX, x); - } - gc.dispose (); - return new int [] {rows, maxX, y + itemHeight}; -} -int [] layoutVertical (int width, int height, boolean resize) { - int xSpacing = (style & SWT.NO_FOCUS) != 0 ? 4 : 2, ySpacing = 0; - int marginWidth = 0, marginHeight = 0; - int x = marginWidth, y = marginHeight; - int maxY = 0, cols = 1; - boolean wrap = (style & SWT.WRAP) != 0; - int itemWidth = 0; - Point [] sizes = new Point [itemCount]; - GC gc = new GC (this); - for (int i=0; i<itemCount; i++) { - Point size = sizes [i] = items [i].computeSize (gc); - itemWidth = Math.max (itemWidth, size.x); - } - for (int i=0; i<itemCount; i++) { - ToolItem item = items [i]; - Point size = sizes [i]; - if (wrap && i != 0 && y + size.y > height) { - cols++; - x += xSpacing + itemWidth; - y = marginHeight; - } - if (resize) { - item.setBounds (x, y, itemWidth, size.y); - boolean visible = x + itemWidth <= width && y + size.y <= height; - item.setVisible (visible); - Control control = item.control; - if (control != null) { - int controlX = x + (itemWidth - size.x) / 2; - control.setBounds (controlX, y, itemWidth - (controlX - x), size.y); - } - } - y += ySpacing + size.y; - maxY = Math.max (maxY, y); - } - return new int [] {cols, x + itemWidth, maxY}; -} -int [] layout (int nWidth, int nHeight, boolean resize) { - if ((style & SWT.VERTICAL) != 0) { - return layoutVertical (nWidth, nHeight, resize); - } else { - return layoutHorizontal (nWidth, nHeight, resize); - } -} -boolean mnemonicHit (char key) { - for (int i = 0; i < itemCount; i++) { - ToolItem item = items [i]; - char mnemonic = findMnemonic (item.getText ()); - if (mnemonic != '\0') { - if (Character.toUpperCase (key) == Character.toUpperCase (mnemonic)) { - XmProcessTraversal (item.handle, OS.XmTRAVERSE_CURRENT); - item.click (false, 0); - return true; - } - } - } - return false; -} -boolean mnemonicMatch (char key) { - for (int i = 0; i < itemCount; i++) { - ToolItem item = items [i]; - if (item.getEnabled ()) { - char mnemonic = findMnemonic (item.getText ()); - if (mnemonic != '\0') { - if (Character.toUpperCase (key) == Character.toUpperCase (mnemonic)) { - return true; - } - } - } - } - return false; -} -void propagateWidget (boolean enabled) { - super.propagateWidget (enabled); - for (int i=0; i<itemCount; i++) { - items [i].propagateWidget (enabled); - } -} -void realizeChildren () { - super.realizeChildren (); - if (items != null) { - for (int i=0; i<itemCount; i++) { - ToolItem item = items [i]; - if (item != null && !item.isDisposed ()) { - item.realizeChildren (); - } - } - } -} -void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean allChildren, boolean trim) { - super.redrawWidget (x, y, width, height, redrawAll, allChildren, trim); - if (items != null) { - for (int i=0; i<itemCount; i++) { - ToolItem item = items [i]; - if (item != null && !item.isDisposed ()) { - item.redrawWidget (x, y, width, height, redrawAll, allChildren, true); - } - } - } -} -void relayout () { - if (drawCount > 0) return; - Rectangle rect = getClientArea (); - layout (rect.width, rect.height, true); -} -void releaseChildren (boolean destroy) { - if (items != null) { - for (int i=0; i<itemCount; i++) { - ToolItem item = items [i]; - if (item != null && !item.isDisposed ()) { - item.release (false); - } - } - items = null; - } - super.releaseChildren (destroy); -} -void removeControl (Control control) { - super.removeControl (control); - for (int i=0; i<itemCount; i++) { - ToolItem item = items [i]; - if (item.control == control) item.setControl (null); - } -} -void setBackgroundPixel (int pixel) { - super.setBackgroundPixel (pixel); - for (int i=0; i<itemCount; i++) { - items[i].setBackgroundPixel (pixel); - } -} -boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - boolean changed = super.setBounds (x, y, width, height, move, resize); - if (changed && resize) relayout (); - return changed; -} -public void setFont (Font font) { - checkWidget(); - super.setFont (font); - relayout (); -} -void setForegroundPixel (int pixel) { - super.setForegroundPixel (pixel); - for (int i = 0; i < itemCount; i++) { - items[i].setForegroundPixel (pixel); - } -} -public void setRedraw (boolean redraw) { - checkWidget(); - if (redraw) { - if (--drawCount == 0) relayout(); - } else { - drawCount++; - } -} -boolean setTabItemFocus (boolean next) { - int index = 0; - while (index < itemCount) { - ToolItem item = items [index]; - if ((item.style & SWT.SEPARATOR) == 0) { - if (item.getEnabled ()) break; - } - index++; - } - if (index == itemCount) return false; - return super.setTabItemFocus (next); -} -int traversalCode (int key, XKeyEvent xEvent) { - return super.traversalCode (key, xEvent) | SWT.TRAVERSE_MNEMONIC; -} -int xFocusIn (XFocusChangeEvent xEvent) { - int newFocus = OS.XmGetFocusWidget (handle); - if (newFocus != focusHandle ()) { - for (int i = 0; i < itemCount; i++) { - if (items [i].handle == newFocus) { - lastFocus = items [i]; - break; - } - } - } - return super.xFocusIn (xEvent); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java deleted file mode 100755 index 9908c4690e..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java +++ /dev/null @@ -1,1164 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class represent a selectable user interface object - * that represents a button in a tool bar. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>PUSH, CHECK, RADIO, SEPARATOR, DROP_DOWN</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection</dd> - * </dl> - * <p> - * Note: Only one of the styles CHECK, PUSH, RADIO, SEPARATOR and DROP_DOWN - * may be specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#toolbar">ToolBar, ToolItem snippets</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class ToolItem extends Item { - ToolBar parent; - Image hotImage, disabledImage; - String toolTipText; - Control control; - int width = DEFAULT_SEPARATOR_WIDTH; - boolean set; - - static final int DEFAULT_WIDTH = 24; - static final int DEFAULT_HEIGHT = 22; - static final int DEFAULT_SEPARATOR_WIDTH = 8; - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>ToolBar</code>) and a style value - * describing its behavior and appearance. The item is added - * to the end of the items maintained by its parent. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#PUSH - * @see SWT#CHECK - * @see SWT#RADIO - * @see SWT#SEPARATOR - * @see SWT#DROP_DOWN - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public ToolItem (ToolBar parent, int style) { - super (parent, checkStyle (style)); - this.parent = parent; - parent.createItem (this, parent.getItemCount ()); -} - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>ToolBar</code>), a style value - * describing its behavior and appearance, and the index - * at which to place it in the items maintained by its parent. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a composite control which will be the parent of the new instance (cannot be null) - * @param style the style of control to construct - * @param index the zero-relative index to store the receiver in its parent - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the parent (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#PUSH - * @see SWT#CHECK - * @see SWT#RADIO - * @see SWT#SEPARATOR - * @see SWT#DROP_DOWN - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public ToolItem (ToolBar parent, int style, int index) { - super (parent, checkStyle (style)); - this.parent = parent; - parent.createItem (this, index); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the control is selected by the user, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * When <code>widgetSelected</code> is called when the mouse is over the arrow portion of a drop-down tool, - * the event object detail field contains the value <code>SWT.ARROW</code>. - * <code>widgetDefaultSelected</code> is not called. - * </p> - * - * @param listener the listener which should be notified when the control is selected by the user, - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #removeSelectionListener - * @see SelectionEvent - */ -public void addSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener(listener); - addListener(SWT.Selection,typedListener); - addListener(SWT.DefaultSelection,typedListener); -} -static int checkStyle (int style) { - return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.DROP_DOWN, 0); -} -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} -void createHandle (int index) { - int parentHandle = parent.handle; - if ((style & SWT.SEPARATOR) != 0) { - int orientation = (parent.style & SWT.HORIZONTAL) != 0 ? OS.XmVERTICAL : OS.XmHORIZONTAL; - int [] argList = { - OS.XmNheight, orientation == OS.XmVERTICAL ? DEFAULT_HEIGHT : DEFAULT_SEPARATOR_WIDTH, - OS.XmNwidth, orientation == OS.XmHORIZONTAL ? DEFAULT_WIDTH : DEFAULT_SEPARATOR_WIDTH, - OS.XmNancestorSensitive, 1, - OS.XmNpositionIndex, index, - OS.XmNorientation, orientation, - OS.XmNseparatorType, (parent.style & SWT.FLAT) != 0 ? OS.XmSHADOW_ETCHED_IN : OS.XmSHADOW_ETCHED_OUT, - }; - handle = OS.XmCreateSeparator (parentHandle, null, argList, argList.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - return; - } - int [] argList = { - OS.XmNwidth, DEFAULT_WIDTH, - OS.XmNheight, DEFAULT_HEIGHT, - OS.XmNrecomputeSize, 0, - OS.XmNhighlightThickness, (parent.style & SWT.NO_FOCUS) != 0 ? 0 : 1, - OS.XmNmarginWidth, 2, - OS.XmNmarginHeight, 1, - OS.XmNtraversalOn, (parent.style & SWT.NO_FOCUS) != 0 ? 0 : 1, - OS.XmNpositionIndex, index, - OS.XmNshadowType, OS.XmSHADOW_OUT, - OS.XmNancestorSensitive, 1, - }; - handle = OS.XmCreateDrawnButton (parentHandle, null, argList, argList.length / 2); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - Control control = parent.findBackgroundControl (); - if (control == null) control = parent; - setBackgroundPixel (parent.getBackgroundPixel ()); -} - -void click (boolean dropDown, int state) { - if ((style & SWT.RADIO) != 0) { - selectRadio (); - } else { - if ((style & SWT.CHECK) != 0) setSelection(!set); - } - Event event = new Event (); - if ((style & SWT.DROP_DOWN) != 0) { - if (dropDown) { - event.detail = SWT.ARROW; - int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNheight, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - event.x = (short) argList [1]; - event.y = (short) argList [3] + (short) argList [5]; - } - } - if (state != 0) setInputState (event, state); - postEvent (SWT.Selection, event); -} - -Point computeSize (GC gc) { - int width = 0, height = 0; - if ((style & SWT.SEPARATOR) != 0) { - if ((parent.style & SWT.HORIZONTAL) != 0) { - width = getWidth (); - height = DEFAULT_HEIGHT; - } else { - width = DEFAULT_WIDTH; - height = getWidth (); - } - if (control != null) { - height = Math.max (height, control.getMinimumHeight ()); - } - return new Point(width, height); - } - int [] argList = { - OS.XmNmarginHeight, 0, - OS.XmNmarginWidth, 0, - OS.XmNshadowThickness, 0, - }; - OS.XtGetValues (handle, argList, argList.length / 2); - int marginHeight = argList [1], marginWidth = argList [3]; - int shadowThickness = argList [5]; - if ((parent.style & SWT.FLAT) != 0) { - shadowThickness = Math.min (2, display.buttonShadowThickness); - } - if (text.length() != 0 || image != null) { - int textWidth = 0, textHeight = 0; - if (text.length () != 0) { - int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC; - Point textExtent = gc.textExtent (text, flags); - textWidth = textExtent.x; - textHeight = textExtent.y; - } - int imageWidth = 0, imageHeight = 0; - if (image != null) { - Rectangle rect = image.getBounds (); - imageWidth = rect.width; - imageHeight = rect.height; - } - if ((parent.style & SWT.RIGHT) != 0) { - width = imageWidth + textWidth; - height = Math.max (imageHeight, textHeight); - if (imageWidth != 0 && textWidth != 0) width += 2; - } else { - height = imageHeight + textHeight; - if (imageHeight != 0 && textHeight != 0) height += 2; - width = Math.max (imageWidth, textWidth); - } - } else { - width = DEFAULT_WIDTH; - height = DEFAULT_HEIGHT; - } - if ((style & SWT.DROP_DOWN) != 0) { - width += 12; - } - if (width != 0) { - width += (marginWidth + shadowThickness) * 2 + 2; - } else { - width = DEFAULT_WIDTH; - } - if (height != 0) { - height += (marginHeight + shadowThickness) * 2 + 2; - } else { - height = DEFAULT_HEIGHT; - } - return new Point (width, height); -} -void createWidget (int index) { - super.createWidget (index); - int topHandle = topHandle (); - if (OS.XtIsRealized (topHandle)) { - /* - * Make sure that the widget has been properly realized - * because the widget was created after the parent - * has been realized. - */ - realizeChildren (); - } -} -void destroyWidget () { - parent.destroyItem (this); - super.destroyWidget (); -} -public void dispose () { - if (isDisposed()) return; - ToolBar parent = this.parent; - super.dispose (); - parent.relayout (); -} -/** - * Returns a rectangle describing the receiver's size and location - * relative to its parent. - * - * @return the receiver's bounding rectangle - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Rectangle getBounds () { - checkWidget(); - int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return new Rectangle ((short) argList [1], (short) argList [3], argList [5], argList [7]); -} -/** - * Returns the control that is used to fill the bounds of - * the item when the item is a <code>SEPARATOR</code>. - * - * @return the control - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Control getControl () { - checkWidget(); - return control; -} -/** - * Returns the receiver's disabled image if it has one, or null - * if it does not. - * <p> - * The disabled image is displayed when the receiver is disabled. - * </p> - * - * @return the receiver's disabled image - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Image getDisabledImage () { - checkWidget(); - return disabledImage; -} -/** - * Returns <code>true</code> if the receiver is enabled, and - * <code>false</code> otherwise. A disabled control is typically - * not selectable from the user interface and draws with an - * inactive or "grayed" look. - * - * @return the receiver's enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #isEnabled - */ -public boolean getEnabled () { - checkWidget(); - int [] argList = {OS.XmNsensitive, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - return argList [1] != 0; -} -/** - * Returns the receiver's hot image if it has one, or null - * if it does not. - * <p> - * The hot image is displayed when the mouse enters the receiver. - * </p> - * - * @return the receiver's hot image - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Image getHotImage () { - checkWidget(); - return hotImage; -} -/** - * Returns the receiver's parent, which must be a <code>ToolBar</code>. - * - * @return the receiver's parent - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public ToolBar getParent () { - checkWidget(); - return parent; -} -/** - * Returns <code>true</code> if the receiver is selected, - * and false otherwise. - * <p> - * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, - * it is selected when it is checked (which some platforms draw as a - * pushed in button). If the receiver is of any other type, this method - * returns false. - * </p> - * - * @return the selection state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getSelection () { - checkWidget(); - if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false; - return set; -} -/** - * Returns the receiver's tool tip text, or null if it has not been set. - * - * @return the receiver's tool tip text - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public String getToolTipText () { - checkWidget(); - return toolTipText; -} -/** - * Gets the width of the receiver. - * - * @return the width - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getWidth () { - checkWidget(); - return width; -} -boolean hasCursor () { - int [] unused = new int [1], buffer = new int [1]; - int xDisplay = OS.XtDisplay (handle); - int xWindow, xParent = OS.XDefaultRootWindow (xDisplay); - do { - if (OS.XQueryPointer ( - xDisplay, xParent, unused, buffer, - unused, unused, unused, unused, unused) == 0) return false; - if ((xWindow = buffer [0]) != 0) xParent = xWindow; - } while (xWindow != 0); - return handle == OS.XtWindowToWidget (xDisplay, xParent); -} -void hookEvents () { - super.hookEvents (); - if ((style & SWT.SEPARATOR) != 0) return; - int windowProc = display.windowProc; - OS.XtAddEventHandler (handle, OS.KeyPressMask, false, windowProc, KEY_PRESS); - OS.XtAddEventHandler (handle, OS.KeyReleaseMask, false, windowProc, KEY_RELEASE); - OS.XtAddEventHandler (handle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS); - OS.XtAddEventHandler (handle, OS.ButtonReleaseMask, false, windowProc, BUTTON_RELEASE); - OS.XtAddEventHandler (handle, OS.PointerMotionMask, false, windowProc, POINTER_MOTION); - OS.XtAddEventHandler (handle, OS.EnterWindowMask, false, windowProc, ENTER_WINDOW); - OS.XtAddEventHandler (handle, OS.LeaveWindowMask, false, windowProc, LEAVE_WINDOW); - OS.XtAddCallback (handle, OS.XmNexposeCallback, windowProc, EXPOSURE_CALLBACK); - OS.XtInsertEventHandler (handle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail); -} -int hoverProc (int id) { - boolean showTip = toolTipText != null; - parent.hoverProc (id, !showTip); - if (showTip) { - display.showToolTip (handle, toolTipText); - } - return 0; -} -/** - * Returns <code>true</code> if the receiver is enabled and all - * of the receiver's ancestors are enabled, and <code>false</code> - * otherwise. A disabled control is typically not selectable from the - * user interface and draws with an inactive or "grayed" look. - * - * @return the receiver's enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getEnabled - */ -public boolean isEnabled () { - checkWidget(); - return getEnabled () && parent.isEnabled (); -} -void manageChildren () { - OS.XtManageChild (handle); -} -void realizeChildren () { - if ((parent.state & PARENT_BACKGROUND) != 0) { - setParentBackground (); - } -} -void redraw () { - int display = OS.XtDisplay (handle); - if (display == 0) return; - int window = OS.XtWindow (handle); - if (window == 0) return; - OS.XClearArea (display, window, 0, 0, 0, 0, true); -} -void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean allChildren, boolean trim) { - redrawHandle (x, y, width, height, redrawAll, handle); -} -void releaseHandle () { - super.releaseHandle (); - parent = null; -} -void releaseWidget () { - super.releaseWidget (); - display.releaseToolTipHandle (handle); - if (parent.lastFocus == this) parent.lastFocus = null; - control = null; - toolTipText = null; - image = disabledImage = hotImage = null; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is selected by the user. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SelectionListener - * @see #addSelectionListener - */ -public void removeSelectionListener(SelectionListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.Selection, listener); - eventTable.unhook(SWT.DefaultSelection,listener); -} -void selectRadio () { - int index = 0; - ToolItem [] items = parent.getItems (); - while (index < items.length && items [index] != this) index++; - int i = index - 1; - while (i >= 0 && items [i].setRadioSelection (false)) --i; - int j = index + 1; - while (j < items.length && items [j].setRadioSelection (false)) j++; - setSelection (true); -} -void setBackgroundPixel(int pixel) { - int [] argList = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - OS.XmChangeColor (handle, pixel); - OS.XtSetValues (handle, argList, argList.length / 2); -} -void setBounds (int x, int y, int width, int height) { - /* - * Feature in Motif. Motif will not allow a window - * to have a zero width or zero height. The fix is - * to ensure these values are never zero. - */ - int newWidth = Math.max (width, 1), newHeight = Math.max (height, 1); - OS.XtConfigureWidget (handle, x, y, newWidth, newHeight, 0); -} -/** - * Sets the control that is used to fill the bounds of - * the item when the item is a <code>SEPARATOR</code>. - * - * @param control the new control - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the control has been disposed</li> - * <li>ERROR_INVALID_PARENT - if the control is not in the same widget tree</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setControl (Control control) { - checkWidget(); - if (control != null) { - if (control.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - if (control.parent != parent) error (SWT.ERROR_INVALID_PARENT); - } - if ((style & SWT.SEPARATOR) == 0) return; - if (this.control == control) return; - this.control = control; - int [] argList = { - OS.XmNseparatorType, control == null ? ((parent.style & SWT.FLAT) != 0 ? OS.XmSHADOW_ETCHED_IN : OS.XmSHADOW_ETCHED_OUT) : OS.XmNO_LINE, - }; - OS.XtSetValues (handle, argList, argList.length / 2); - if (control != null && !control.isDisposed ()) { - /* - * It is possible that the control was created with a - * z-order below that of the current tool item. In this - * case, the control is not visible because it is - * obscured by the tool item. The fix is to move the - * control above this tool item in the z-order. - * The code below is similar to the code found in - * setZOrder. - */ - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return; - if (!OS.XtIsRealized (handle)) { - Shell shell = parent.getShell (); - shell.realizeWidget (); - } - int topHandle1 = control.topHandle (); - int window1 = OS.XtWindow (topHandle1); - if (window1 == 0) return; - int topHandle2 = this.topHandle (); - int window2 = OS.XtWindow (topHandle2); - if (window2 == 0) return; - XWindowChanges struct = new XWindowChanges (); - struct.sibling = window2; - struct.stack_mode = OS.Above; - int screen = OS.XDefaultScreen (xDisplay); - int flags = OS.CWStackMode | OS.CWSibling; - OS.XReconfigureWMWindow (xDisplay, window1, screen, flags, struct); - } - parent.relayout (); -} -/** - * Enables the receiver if the argument is <code>true</code>, - * and disables it otherwise. - * <p> - * A disabled control is typically - * not selectable from the user interface and draws with an - * inactive or "grayed" look. - * </p> - * - * @param enabled the new enabled state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setEnabled (boolean enabled) { - checkWidget(); - int [] argList = {OS.XmNsensitive, enabled ? 1 : 0}; - OS.XtSetValues (handle, argList, argList.length / 2); -} -void setForegroundPixel(int pixel) { - int [] argList = {OS.XmNforeground, pixel}; - OS.XtSetValues (handle, argList, argList.length / 2); -} -/** - * Sets the receiver's disabled image to the argument, which may be - * null indicating that no disabled image should be displayed. - * <p> - * The disabled image is displayed when the receiver is disabled. - * </p> - * - * @param image the disabled image to display on the receiver (may be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setDisabledImage (Image image) { - checkWidget(); - if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - if ((style & SWT.SEPARATOR) != 0) return; - disabledImage = image; - if (!getEnabled ()) redraw (); -} -boolean setFocus () { - if ((style & SWT.SEPARATOR) != 0) return false; - return XmProcessTraversal (handle, OS.XmTRAVERSE_CURRENT); -} -/** - * Sets the receiver's hot image to the argument, which may be - * null indicating that no hot image should be displayed. - * <p> - * The hot image is displayed when the mouse enters the receiver. - * </p> - * - * @param image the hot image to display on the receiver (may be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setHotImage (Image image) { - checkWidget(); - if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - if ((style & SWT.SEPARATOR) != 0) return; - hotImage = image; - if ((parent.style & SWT.FLAT) != 0) redraw (); -} -public void setImage (Image image) { - checkWidget(); - if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - if ((style & SWT.SEPARATOR) != 0) return; - super.setImage (image); - parent.relayout(); - redraw (); -} -void setParentBackground () { - parent.setParentBackground (handle); -} -boolean setRadioSelection (boolean value) { - if ((style & SWT.RADIO) == 0) return false; - if (getSelection () != value) { - setSelection (value); - postEvent (SWT.Selection); - } - return true; -} -/** - * Sets the selection state of the receiver. - * <p> - * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, - * it is selected when it is checked (which some platforms draw as a - * pushed in button). - * </p> - * - * @param selected the new selection state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSelection (boolean selected) { - checkWidget(); - if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return; - if (selected == set) return; - set = selected; - setDrawPressed (set); -} -/** - * Sets the receiver's text. The string may include - * the mnemonic character. - * </p> - * <p> - * Mnemonics are indicated by an '&' that causes the next - * character to be the mnemonic. When the user presses a - * key sequence that matches the mnemonic, a selection - * event occurs. On most platforms, the mnemonic appears - * underlined but may be emphasised in a platform specific - * manner. The mnemonic indicator character '&' can be - * escaped by doubling it in the string, causing a single - * '&' to be displayed. - * </p> - * - * @param string the new text - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the text is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if ((style & SWT.SEPARATOR) != 0) return; - super.setText (string); - parent.relayout(); - redraw (); -} - -/** - * Sets the receiver's tool tip text to the argument, which - * may be null indicating that the default tool tip for the - * control will be shown. For a control that has a default - * tool tip, such as the Tree control on Windows, setting - * the tool tip text to an empty string replaces the default, - * causing no tool tip text to be shown. - * <p> - * The mnemonic indicator (character '&') is not displayed in a tool tip. - * To display a single '&' in the tool tip, the character '&' can be - * escaped by doubling it in the string. - * </p> - * - * @param string the new tool tip text (or null) - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setToolTipText (String string) { - checkWidget(); - toolTipText = string; -} -void setVisible (boolean visible) { - OS.XtSetMappedWhenManaged (handle, visible); -} -/** - * Sets the width of the receiver, for <code>SEPARATOR</code> ToolItems. - * - * @param width the new width - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setWidth (int width) { - checkWidget(); - if ((style & SWT.SEPARATOR) == 0) return; - if (width < 0 || this.width == width) return; - this.width = width; - parent.relayout(); -} -void setDrawPressed (boolean value) { - int shadowType = value ? OS.XmSHADOW_IN : OS.XmSHADOW_OUT; - int [] argList = {OS.XmNshadowType, shadowType}; - OS.XtSetValues(handle, argList, argList.length / 2); -} -boolean translateAccelerator (char key, int keysym, XKeyEvent xEvent, boolean doit) { - return parent.translateAccelerator (key, keysym, xEvent, doit); -} -boolean translateMnemonic (char key, int keysym, XKeyEvent xEvent) { - return parent.translateMnemonic (key, keysym, xEvent); -} -boolean translateTraversal (int key, XKeyEvent xEvent) { - return parent.translateTraversal (key, xEvent); -} -void propagateWidget (boolean enabled) { - propagateHandle (enabled, handle, OS.None); -} -int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) { - display.hideToolTip (); - XButtonEvent xEvent = new XButtonEvent (); - OS.memmove (xEvent, call_data, XButtonEvent.sizeof); - /* - * Forward the mouse event to the parent. - * This is necessary so that mouse listeners - * in the parent will be called, despite the - * fact that the event did not really occur - * in X in the parent. This is done to be - * compatible with Windows. - */ - int [] argList = {OS.XmNx, 0, OS.XmNy, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - xEvent.window = OS.XtWindow (parent.handle); - xEvent.x += argList [1]; xEvent.y += argList [3]; - OS.memmove (call_data, xEvent, XButtonEvent.sizeof); - int result = parent.XButtonPress (w, client_data, call_data, continue_to_dispatch); - xEvent.x -= argList [1]; xEvent.y -= argList [3]; - if (result == 0 && xEvent.button == 1) { - if (!set) setDrawPressed (!set); - } - return result; -} -int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) { - display.hideToolTip(); - XButtonEvent xEvent = new XButtonEvent (); - OS.memmove (xEvent, call_data, XButtonEvent.sizeof); - /* - * Forward the mouse event to the parent. - * This is necessary so that mouse listeners - * in the parent will be called, despite the - * fact that the event did not really occur - * in X in the parent. This is done to be - * compatible with Windows. - */ - int [] argList = {OS.XmNx, 0, OS.XmNy, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - xEvent.window = OS.XtWindow (parent.handle); - xEvent.x += argList [1]; xEvent.y += argList [3]; - OS.memmove (call_data, xEvent, XButtonEvent.sizeof); - int result = parent.XButtonRelease (w, client_data, call_data, continue_to_dispatch); - xEvent.x -= argList [1]; xEvent.y -= argList [3]; - if (result == 0 && xEvent.button == 1) { - int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0}; - OS.XtGetValues (handle, argList2, argList2.length / 2); - int width = argList2 [1], height = argList2 [3]; - if (0 <= xEvent.x && xEvent.x < width && 0 <= xEvent.y && xEvent.y < height) { - click (xEvent.x > width - 12, xEvent.state); - } - setDrawPressed (set); - } - return result; -} -int XEnterWindow (int w, int client_data, int call_data, int continue_to_dispatch) { - XCrossingEvent xEvent = new XCrossingEvent (); - OS.memmove (xEvent, call_data, XCrossingEvent.sizeof); - if ((xEvent.state & OS.Button1Mask) != 0) { - setDrawPressed (!set); - } else { - if ((parent.style & SWT.FLAT) != 0) redraw (); - } - return 0; -} -int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatch) { - /* - * Forward the focus event to the parent. - * This is necessary so that focus listeners - * in the parent will be called, despite the - * fact that the event did not really occur - * in X in the parent. This is done to be - * compatible with Windows. - */ - XFocusChangeEvent xEvent = new XFocusChangeEvent (); - OS.memmove (xEvent, call_data, XFocusChangeEvent.sizeof); - xEvent.window = OS.XtWindow (parent.handle); -// OS.memmove (call_data, xEvent, XFocusChangeEvent.sizeof); - parent.XFocusChange (w, client_data, call_data, continue_to_dispatch); - return 0; -} -int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = 0; - XKeyEvent xEvent = new XKeyEvent (); - OS.memmove (xEvent, call_data, XKeyEvent.sizeof); - int [] keysym = new int [1]; - OS.XLookupString (xEvent, null, 0, keysym, null); - keysym [0] &= 0xFFFF; - switch (keysym [0]) { - case OS.XK_space: - click (false, xEvent.state); - result = 1; - break; - case OS.XK_Down: - if ((style & SWT.DROP_DOWN) != 0) { - click (true, xEvent.state); - result = 1; - } - break; - } - /* - * Forward the key event to the parent. - * This is necessary so that key listeners - * in the parent will be called, despite the - * fact that the event did not really occur - * in X in the parent. This is done to be - * compatible with Windows. - */ - xEvent.window = OS.XtWindow (parent.handle); -// OS.memmove (callData, xEvent, XKeyEvent.sizeof); - parent.XKeyPress (w, client_data, call_data, continue_to_dispatch); - if (result == 1) { - OS.memmove (continue_to_dispatch, new int [1], 4); - } - return result; -} -int XKeyRelease (int w, int client_data, int call_data, int continue_to_dispatch) { - XKeyEvent xEvent = new XKeyEvent (); - OS.memmove (xEvent, call_data, XKeyEvent.sizeof); - - /* - * Forward the key event to the parent. - * This is necessary so that key listeners - * in the parent will be called, despite the - * fact that the event did not really occur - * in X in the parent. This is done to be - * compatible with Windows. - */ - xEvent.window = OS.XtWindow (parent.handle); -// OS.memmove (callData, xEvent, XKeyEvent.sizeof); - parent.XKeyRelease (w, client_data, call_data, continue_to_dispatch); - return 0; -} -int XLeaveWindow (int w, int client_data, int call_data, int continue_to_dispatch) { - display.removeMouseHoverTimeOut (); - display.hideToolTip (); - XCrossingEvent xEvent = new XCrossingEvent (); - OS.memmove (xEvent, call_data, XCrossingEvent.sizeof); - if ((xEvent.state & OS.Button1Mask) != 0) { - setDrawPressed (set); - } else { - if ((parent.style & SWT.FLAT) != 0) redraw (); - } - return 0; -} -int XmNexposureCallback (int w, int client_data, int call_data) { - if ((style & SWT.SEPARATOR) != 0) return 0; - int xDisplay = OS.XtDisplay (handle); - if (xDisplay == 0) return 0; - int xWindow = OS.XtWindow (handle); - if (xWindow == 0) return 0; - int [] argList = { - OS.XmNcolormap, 0, - OS.XmNwidth, 0, - OS.XmNheight, 0, - }; - OS.XtGetValues (handle, argList, argList.length / 2); - int width = argList [3], height = argList [5]; - - Image currentImage = image; - boolean enabled = getEnabled(); - - if ((parent.style & SWT.FLAT) != 0) { - boolean hasCursor = hasCursor (); - - /* Set the shadow thickness */ - int thickness = 0; - if (set || (hasCursor && enabled)) { - thickness = Math.min (2, display.buttonShadowThickness); - } - argList = new int [] {OS.XmNshadowThickness, thickness}; - OS.XtSetValues (handle, argList, argList.length / 2); - - /* Determine if hot image should be used */ - if (enabled && hasCursor && hotImage != null) { - currentImage = hotImage; - } - } - - GCData data = new GCData (); - data.device = display; - data.display = xDisplay; - data.drawable = xWindow; - data.font = parent.font; - data.colormap = argList [1]; - int xGC = OS.XCreateGC (xDisplay, xWindow, 0, null); - if (xGC == 0) SWT.error (SWT.ERROR_NO_HANDLES); - GC gc = GC.motif_new (xGC, data); - - XmAnyCallbackStruct cb = new XmAnyCallbackStruct (); - OS.memmove (cb, call_data, XmAnyCallbackStruct.sizeof); - if (cb.event != 0) { - XExposeEvent xEvent = new XExposeEvent (); - OS.memmove (xEvent, cb.event, XExposeEvent.sizeof); - Rectangle rect = new Rectangle (xEvent.x, xEvent.y, xEvent.width, xEvent.height); - gc.setClipping (rect); - } - - if (!enabled) { - currentImage = disabledImage; - if (currentImage == null && image != null) { - currentImage = new Image (display, image, SWT.IMAGE_DISABLE); - } - Color disabledColor = display.getSystemColor (SWT.COLOR_WIDGET_NORMAL_SHADOW); - gc.setForeground (disabledColor); - } else { - gc.setForeground (parent.getForeground ()); - } - gc.setBackground (parent.getBackground ()); - - int textX = 0, textY = 0, textWidth = 0, textHeight = 0; - if (text.length () != 0) { - int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC; - Point textExtent = gc.textExtent (text, flags); - textWidth = textExtent.x; - textHeight = textExtent.y; - } - int imageX = 0, imageY = 0, imageWidth = 0, imageHeight = 0; - if (currentImage != null) { - Rectangle imageBounds = currentImage.getBounds (); - imageWidth = imageBounds.width; - imageHeight = imageBounds.height; - } - - int spacing = 0; - if (textWidth != 0 && imageWidth != 0) spacing = 2; - if ((parent.style & SWT.RIGHT) != 0) { - imageX = (width - imageWidth - textWidth - spacing) / 2; - imageY = (height - imageHeight) / 2; - textX = spacing + imageX + imageWidth; - textY = (height - textHeight) / 2; - } else { - imageX = (width - imageWidth) / 2; - imageY = (height - imageHeight - textHeight - spacing) / 2; - textX = (width - textWidth) / 2; - textY = spacing + imageY + imageHeight; - } - - if ((style & SWT.DROP_DOWN) != 0) { - textX -= 6; imageX -=6; - } - if (textWidth > 0) { - int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC | SWT.DRAW_TRANSPARENT; - gc.drawText(text, textX, textY, flags); - } - if (imageWidth > 0) gc.drawImage(currentImage, imageX, imageY); - if ((style & SWT.DROP_DOWN) != 0) { - int startX = width - 12, startY = (height - 2) / 2; - int [] arrow = {startX, startY, startX + 3, startY + 3, startX + 6, startY}; - gc.setBackground (parent.getForeground ()); - gc.fillPolygon (arrow); - gc.drawPolygon (arrow); - } - gc.dispose (); - OS.XFreeGC (xDisplay, xGC); - - if (!enabled && disabledImage == null) { - if (currentImage != null) currentImage.dispose (); - } - return 0; -} -int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) { - display.addMouseHoverTimeOut (handle); - - /* - * Forward the mouse event to the parent. - * This is necessary so that mouse listeners - * in the parent will be called, despite the - * fact that the event did not really occur - * in X in the parent. This is done to be - * compatible with Windows. - */ - XMotionEvent xEvent = new XMotionEvent (); - OS.memmove (xEvent, call_data, XMotionEvent.sizeof); - int [] argList = {OS.XmNx, 0, OS.XmNy, 0}; - OS.XtGetValues (handle, argList, argList.length / 2); - xEvent.window = OS.XtWindow (parent.handle); - xEvent.x += argList [1]; xEvent.y += argList [3]; - /* - * This code is intentionally commented. - * Currently, the implementation of the - * mouse move code in the parent interferes - * with tool tips for tool items. - */ -// OS.memmove (callData, xEvent, XButtonEvent.sizeof); -// parent.XPointerMotion (w, client_data, call_data, continue_to_dispatch); - if (!parent.sendMouseEvent (SWT.MouseMove, xEvent)) { - OS.memmove (continue_to_dispatch, new int [1], 4); - return 1; - } - return 0; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java deleted file mode 100755 index b7d096f337..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java +++ /dev/null @@ -1,983 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class implement rubber banding rectangles that are - * drawn onto a parent <code>Composite</code> or <code>Display</code>. - * These rectangles can be specified to respond to mouse and key events - * by either moving or resizing themselves accordingly. Trackers are - * typically used to represent window geometries in a lightweight manner. - * - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>LEFT, RIGHT, UP, DOWN, RESIZE</dd> - * <dt><b>Events:</b></dt> - * <dd>Move, Resize</dd> - * </dl> - * <p> - * Note: Rectangle move behavior is assumed unless RESIZE is specified. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#tracker">Tracker snippets</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noextend This class is not intended to be subclassed by clients. - */ -public class Tracker extends Widget { - Composite parent; - boolean tracking, cancelled, stippled; - Rectangle [] rectangles = new Rectangle [0], proportions = rectangles; - Rectangle bounds; - int cursorOrientation = SWT.NONE; - Cursor cursor; - int window, oldX, oldY; - - final static int STEPSIZE_SMALL = 1; - final static int STEPSIZE_LARGE = 9; - -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a widget which will be the parent of the new instance (cannot be null) - * @param style the style of widget to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#LEFT - * @see SWT#RIGHT - * @see SWT#UP - * @see SWT#DOWN - * @see SWT#RESIZE - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Tracker (Composite parent, int style) { - super (parent, checkStyle (style)); - this.parent = parent; -} - -/** - * Constructs a new instance of this class given the display - * to create it on and a style value describing its behavior - * and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p><p> - * Note: Currently, null can be passed in for the display argument. - * This has the effect of creating the tracker on the currently active - * display if there is one. If there is no current display, the - * tracker is created on a "default" display. <b>Passing in null as - * the display argument is not considered to be good coding style, - * and may not be supported in a future release of SWT.</b> - * </p> - * - * @param display the display to create the tracker on - * @param style the style of control to construct - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT#LEFT - * @see SWT#RIGHT - * @see SWT#UP - * @see SWT#DOWN - * @see SWT#RESIZE - */ -public Tracker (Display display, int style) { - if (display == null) display = Display.getCurrent (); - if (display == null) display = Display.getDefault (); - if (!display.isValidThread ()) { - error (SWT.ERROR_THREAD_INVALID_ACCESS); - } - this.style = checkStyle (style); - this.display = display; -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the control is moved or resized, by sending - * it one of the messages defined in the <code>ControlListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ControlListener - * @see #removeControlListener - */ -public void addControlListener (ControlListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Resize, typedListener); - addListener (SWT.Move, typedListener); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when keys are pressed and released on the system keyboard, by sending - * it one of the messages defined in the <code>KeyListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see KeyListener - * @see #removeKeyListener - */ -public void addKeyListener(KeyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener(SWT.KeyUp,typedListener); - addListener(SWT.KeyDown,typedListener); -} - -Point adjustMoveCursor () { - if (bounds == null) return null; - final int unused[] = new int[1]; - int actualX[] = new int[1]; - int actualY[] = new int[1]; - - int newX = bounds.x + bounds.width / 2; - int newY = bounds.y; - - int xDisplay = display.xDisplay; - OS.XWarpPointer (xDisplay, OS.None, window, 0, 0, 0, 0, newX, newY); - /* - * The call to XWarpPointer does not always place the pointer on the - * exact location that is specified, so do a query (below) to get the - * actual location of the pointer after it has been moved. - */ - OS.XQueryPointer (xDisplay, window, unused, unused, actualX, actualY, unused, unused, unused); - return new Point (actualX[0], actualY[0]); -} -Point adjustResizeCursor () { - if (bounds == null) return null; - int newX, newY; - - if ((cursorOrientation & SWT.LEFT) != 0) { - newX = bounds.x; - } else if ((cursorOrientation & SWT.RIGHT) != 0) { - newX = bounds.x + bounds.width; - } else { - newX = bounds.x + bounds.width / 2; - } - - if ((cursorOrientation & SWT.UP) != 0) { - newY = bounds.y; - } else if ((cursorOrientation & SWT.DOWN) != 0) { - newY = bounds.y + bounds.height; - } else { - newY = bounds.y + bounds.height / 2; - } - - final int unused[] = new int[1]; - int actualX[] = new int[1]; - int actualY[] = new int[1]; - int xDisplay = display.xDisplay; - OS.XWarpPointer (xDisplay, 0, window, 0, 0, 0, 0, newX, newY); - /* - * The call to XWarpPointer does not always place the pointer on the - * exact location that is specified, so do a query (below) to get the - * actual location of the pointer after it has been moved. - */ - OS.XQueryPointer (xDisplay, window, unused, unused, actualX, actualY, unused, unused, unused); - return new Point (actualX[0], actualY[0]); -} -static int checkStyle (int style) { - if ((style & (SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN)) == 0) { - style |= SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN; - } - return style; -} -/** - * Stops displaying the tracker rectangles. Note that this is not considered - * to be a cancelation by the user. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void close () { - checkWidget (); - tracking = false; -} -Rectangle computeBounds () { - if (rectangles.length == 0) return null; - int xMin = rectangles [0].x; - int yMin = rectangles [0].y; - int xMax = rectangles [0].x + rectangles [0].width; - int yMax = rectangles [0].y + rectangles [0].height; - - for (int i = 1; i < rectangles.length; i++) { - if (rectangles [i].x < xMin) xMin = rectangles [i].x; - if (rectangles [i].y < yMin) yMin = rectangles [i].y; - int rectRight = rectangles [i].x + rectangles [i].width; - if (rectRight > xMax) xMax = rectRight; - int rectBottom = rectangles [i].y + rectangles [i].height; - if (rectBottom > yMax) yMax = rectBottom; - } - - return new Rectangle (xMin, yMin, xMax - xMin, yMax - yMin); -} - -Rectangle [] computeProportions (Rectangle [] rects) { - Rectangle [] result = new Rectangle [rects.length]; - bounds = computeBounds (); - if (bounds != null) { - for (int i = 0; i < rects.length; i++) { - int x = 0, y = 0, width = 0, height = 0; - if (bounds.width != 0) { - x = (rects [i].x - bounds.x) * 100 / bounds.width; - width = rects [i].width * 100 / bounds.width; - } else { - width = 100; - } - if (bounds.height != 0) { - y = (rects [i].y - bounds.y) * 100 / bounds.height; - height = rects [i].height * 100 / bounds.height; - } else { - height = 100; - } - result [i] = new Rectangle (x, y, width, height); - } - } - return result; -} - -void drawRectangles (Rectangle [] rects, boolean stippled) { - int xDisplay = display.xDisplay; - int color = OS.XWhitePixel (xDisplay, 0); - int xWindow = OS.XDefaultRootWindow (xDisplay); - if (parent != null) { - xWindow = OS.XtWindow (parent.handle); - if (xWindow == 0) return; - int foreground = parent.getForegroundPixel (); - Control control = parent.findBackgroundControl (); - if (control == null) control = parent; - int background = control.getBackgroundPixel (); - color = foreground ^ background; - } - int gc = OS.XCreateGC (xDisplay, xWindow, 0, null); - OS.XSetForeground (xDisplay, gc, color); - OS.XSetSubwindowMode (xDisplay, gc, OS.IncludeInferiors); - OS.XSetFunction (xDisplay, gc, OS.GXxor); - int stipplePixmap = 0; - if (stippled) { - byte [] bits = {-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0}; - stipplePixmap = OS.XCreateBitmapFromData (xDisplay, xWindow, bits, 8, 8); - OS.XSetStipple (xDisplay, gc, stipplePixmap); - OS.XSetFillStyle (xDisplay, gc, OS.FillStippled); - OS.XSetLineAttributes (xDisplay, gc, 3, OS.LineSolid, OS.CapButt, OS.JoinMiter); - } - for (int i=0; i<rects.length; i++) { - Rectangle rect = rects [i]; - OS.XDrawRectangle (xDisplay, xWindow, gc, rect.x, rect.y, rect.width, rect.height); - } - if (stippled) { - OS.XFreePixmap (xDisplay, stipplePixmap); - } - OS.XFreeGC (xDisplay, gc); -} -/** - * Returns the bounds that are being drawn, expressed relative to the parent - * widget. If the parent is a <code>Display</code> then these are screen - * coordinates. - * - * @return the bounds of the Rectangles being drawn - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Rectangle [] getRectangles () { - checkWidget(); - Rectangle [] result = new Rectangle [rectangles.length]; - for (int i = 0; i < rectangles.length; i++) { - Rectangle current = rectangles [i]; - result [i] = new Rectangle (current.x, current.y, current.width, current.height); - } - return result; -} -/** - * Returns <code>true</code> if the rectangles are drawn with a stippled line, <code>false</code> otherwise. - * - * @return the stippled effect of the rectangles - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean getStippled () { - checkWidget (); - return stippled; -} - -void moveRectangles (int xChange, int yChange) { - if (bounds == null) return; - if (xChange < 0 && ((style & SWT.LEFT) == 0)) xChange = 0; - if (xChange > 0 && ((style & SWT.RIGHT) == 0)) xChange = 0; - if (yChange < 0 && ((style & SWT.UP) == 0)) yChange = 0; - if (yChange > 0 && ((style & SWT.DOWN) == 0)) yChange = 0; - if (xChange == 0 && yChange == 0) return; - bounds.x += xChange; bounds.y += yChange; - for (int i = 0; i < rectangles.length; i++) { - rectangles [i].x += xChange; - rectangles [i].y += yChange; - } -} - -/** - * Displays the Tracker rectangles for manipulation by the user. Returns when - * the user has either finished manipulating the rectangles or has cancelled the - * Tracker. - * - * @return <code>true</code> if the user did not cancel the Tracker, <code>false</code> otherwise - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean open () { - checkWidget (); - int xDisplay = display.xDisplay; - window = OS.XDefaultRootWindow (xDisplay); - if (parent != null) { - window = OS.XtWindow (parent.handle); - if (window == 0) return false; - } - cancelled = false; - tracking = true; - update (); - drawRectangles (rectangles, stippled); - int [] oldX = new int [1], oldY = new int [1]; - int [] unused = new int [1], mask = new int [1]; - OS.XQueryPointer (xDisplay, window, unused, unused, oldX, oldY, unused, unused, mask); - - /* - * If exactly one of UP/DOWN is specified as a style then set the cursor - * orientation accordingly (the same is done for LEFT/RIGHT styles below). - */ - int vStyle = style & (SWT.UP | SWT.DOWN); - if (vStyle == SWT.UP || vStyle == SWT.DOWN) { - cursorOrientation |= vStyle; - } - int hStyle = style & (SWT.LEFT | SWT.RIGHT); - if (hStyle == SWT.LEFT || hStyle == SWT.RIGHT) { - cursorOrientation |= hStyle; - } - - int mouseMasks = OS.Button1Mask | OS.Button2Mask | OS.Button3Mask; - boolean mouseDown = (mask [0] & mouseMasks) != 0; - if (!mouseDown) { - Point cursorPos = null; - if ((style & SWT.RESIZE) != 0) { - cursorPos = adjustResizeCursor (); - } else { - cursorPos = adjustMoveCursor (); - } - if (cursorPos != null) { - oldX [0] = cursorPos.x; - oldY [0] = cursorPos.y; - } - } - this.oldX = oldX [0]; - this.oldY = oldY [0]; - - int ptrGrabResult = OS.XGrabPointer (xDisplay, window, 0, - OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask, - OS.GrabModeAsync, OS.GrabModeAsync, OS.None, OS.None, OS.CurrentTime); - int kbdGrabResult = OS.XGrabKeyboard (xDisplay, window, 0, - OS.GrabModeAsync, OS.GrabModeAsync, OS.CurrentTime); - - /* Tracker behaves like a Dialog with its own OS event loop. */ - XAnyEvent anyEvent = new XAnyEvent(); - int xEvent = OS.XtMalloc (XEvent.sizeof); - int dispatch = OS.XtMalloc (4); - int xtContext = OS.XtDisplayToApplicationContext (xDisplay); - while (tracking) { - if (parent != null && parent.isDisposed ()) break; - OS.XtAppNextEvent (xtContext, xEvent); - OS.memmove (anyEvent, xEvent, XAnyEvent.sizeof); - int widget = OS.XtWindowToWidget (anyEvent.display, anyEvent.window); - switch (anyEvent.type) { - case OS.MotionNotify: XPointerMotion (widget, 0, xEvent, dispatch); break; - case OS.ButtonRelease: XButtonRelease (widget, 0, xEvent, dispatch); break; - case OS.KeyPress: XKeyPress (widget, 0, xEvent, dispatch); break; - case OS.KeyRelease: XKeyRelease (widget, 0, xEvent, dispatch); break; - case OS.ButtonPress: - case OS.EnterNotify: - case OS.LeaveNotify: - /* Do not dispatch these */ - break; - case OS.Expose: - update (); - drawRectangles (rectangles, stippled); - OS.XtDispatchEvent (xEvent); - drawRectangles (rectangles, stippled); - break; - default: - OS.XtDispatchEvent (xEvent); - } - } - if (xEvent != 0) OS.XtFree (xEvent); - if (dispatch != 0) OS.XtFree (dispatch); - if (!isDisposed()) { - update (); - drawRectangles (rectangles, stippled); - } - if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime); - if (kbdGrabResult == OS.GrabSuccess) OS.XUngrabKeyboard (xDisplay, OS.CurrentTime); - window = 0; - return !cancelled; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is moved or resized. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see ControlListener - * @see #addControlListener - */ -public void removeControlListener (ControlListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Resize, listener); - eventTable.unhook (SWT.Move, listener); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when keys are pressed and released on the system keyboard. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see KeyListener - * @see #addKeyListener - */ -public void removeKeyListener(KeyListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.KeyUp, listener); - eventTable.unhook(SWT.KeyDown, listener); -} -void releaseWidget () { - super.releaseWidget (); - parent = null; - rectangles = proportions = null; - bounds = null; -} -void resizeRectangles (int xChange, int yChange) { - if (bounds == null) return; - /* - * If the cursor orientation has not been set in the orientation of - * this change then try to set it here. - */ - if (xChange < 0 && ((style & SWT.LEFT) != 0) && ((cursorOrientation & SWT.RIGHT) == 0)) { - cursorOrientation |= SWT.LEFT; - } - if (xChange > 0 && ((style & SWT.RIGHT) != 0) && ((cursorOrientation & SWT.LEFT) == 0)) { - cursorOrientation |= SWT.RIGHT; - } - if (yChange < 0 && ((style & SWT.UP) != 0) && ((cursorOrientation & SWT.DOWN) == 0)) { - cursorOrientation |= SWT.UP; - } - if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) { - cursorOrientation |= SWT.DOWN; - } - - /* - * If the bounds will flip about the x or y axis then apply the adjustment - * up to the axis (ie.- where bounds width/height becomes 0), change the - * cursor's orientation accordingly, and flip each Rectangle's origin (only - * necessary for > 1 Rectangles) - */ - if ((cursorOrientation & SWT.LEFT) != 0) { - if (xChange > bounds.width) { - if ((style & SWT.RIGHT) == 0) return; - cursorOrientation |= SWT.RIGHT; - cursorOrientation &= ~SWT.LEFT; - bounds.x += bounds.width; - xChange -= bounds.width; - bounds.width = 0; - if (proportions.length > 1) { - for (int i = 0; i < proportions.length; i++) { - Rectangle proportion = proportions [i]; - proportion.x = 100 - proportion.x - proportion.width; - } - } - } - } else if ((cursorOrientation & SWT.RIGHT) != 0) { - if (bounds.width < -xChange) { - if ((style & SWT.LEFT) == 0) return; - cursorOrientation |= SWT.LEFT; - cursorOrientation &= ~SWT.RIGHT; - xChange += bounds.width; - bounds.width = 0; - if (proportions.length > 1) { - for (int i = 0; i < proportions.length; i++) { - Rectangle proportion = proportions [i]; - proportion.x = 100 - proportion.x - proportion.width; - } - } - } - } - if ((cursorOrientation & SWT.UP) != 0) { - if (yChange > bounds.height) { - if ((style & SWT.DOWN) == 0) return; - cursorOrientation |= SWT.DOWN; - cursorOrientation &= ~SWT.UP; - bounds.y += bounds.height; - yChange -= bounds.height; - bounds.height = 0; - if (proportions.length > 1) { - for (int i = 0; i < proportions.length; i++) { - Rectangle proportion = proportions [i]; - proportion.y = 100 - proportion.y - proportion.height; - } - } - } - } else if ((cursorOrientation & SWT.DOWN) != 0) { - if (bounds.height < -yChange) { - if ((style & SWT.UP) == 0) return; - cursorOrientation |= SWT.UP; - cursorOrientation &= ~SWT.DOWN; - yChange += bounds.height; - bounds.height = 0; - if (proportions.length > 1) { - for (int i = 0; i < proportions.length; i++) { - Rectangle proportion = proportions [i]; - proportion.y = 100 - proportion.y - proportion.height; - } - } - } - } - - // apply the bounds adjustment - if ((cursorOrientation & SWT.LEFT) != 0) { - bounds.x += xChange; - bounds.width -= xChange; - } else if ((cursorOrientation & SWT.RIGHT) != 0) { - bounds.width += xChange; - } - if ((cursorOrientation & SWT.UP) != 0) { - bounds.y += yChange; - bounds.height -= yChange; - } else if ((cursorOrientation & SWT.DOWN) != 0) { - bounds.height += yChange; - } - - Rectangle [] newRects = new Rectangle [rectangles.length]; - for (int i = 0; i < rectangles.length; i++) { - Rectangle proportion = proportions[i]; - newRects[i] = new Rectangle ( - proportion.x * bounds.width / 100 + bounds.x, - proportion.y * bounds.height / 100 + bounds.y, - proportion.width * bounds.width / 100, - proportion.height * bounds.height / 100); - } - rectangles = newRects; -} - -/** - * Sets the <code>Cursor</code> of the Tracker. If this cursor is <code>null</code> - * then the cursor reverts to the default. - * - * @param newCursor the new <code>Cursor</code> to display - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setCursor (Cursor value) { - checkWidget (); - cursor = value; -} -/** - * Specifies the rectangles that should be drawn, expressed relative to the parent - * widget. If the parent is a Display then these are screen coordinates. - * - * @param rectangles the bounds of the rectangles to be drawn - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the set of rectangles is null or contains a null rectangle</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setRectangles (Rectangle [] rectangles) { - checkWidget (); - if (rectangles == null) error (SWT.ERROR_NULL_ARGUMENT); - this.rectangles = new Rectangle [rectangles.length]; - for (int i = 0; i < rectangles.length; i++) { - Rectangle current = rectangles [i]; - if (current == null) error (SWT.ERROR_NULL_ARGUMENT); - this.rectangles [i] = new Rectangle (current.x, current.y, current.width, current.height); - } - proportions = computeProportions (rectangles); -} -/** - * Changes the appearance of the line used to draw the rectangles. - * - * @param stippled <code>true</code> if rectangle should appear stippled - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setStippled (boolean stippled) { - checkWidget (); - this.stippled = stippled; -} -void update () { - if (parent != null) { - if (parent.isDisposed ()) return; - parent.getShell ().update (); - } else { - display.update (); - } -} -int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) { - return xMouse (OS.ButtonRelease, w, client_data, call_data, continue_to_dispatch); -} - -int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) { - int result = super.XKeyPress (w, client_data, call_data, continue_to_dispatch); - if (result != 0) return result; - XKeyEvent keyEvent = new XKeyEvent (); - OS.memmove (keyEvent, call_data, XKeyEvent.sizeof); - if (keyEvent.keycode != 0) { - int [] keysym = new int [1]; - OS.XLookupString (keyEvent, null, 0, keysym, null); - keysym [0] &= 0xFFFF; - int xChange = 0, yChange = 0; - int stepSize = ((keyEvent.state & OS.ControlMask) != 0) ? STEPSIZE_SMALL : STEPSIZE_LARGE; - switch (keysym [0]) { - case OS.XK_KP_Enter: - case OS.XK_Return: - tracking = false; - /* Eat the subsequent KeyRelease event */ - OS.XtAppNextEvent (OS.XtDisplayToApplicationContext (keyEvent.display), call_data); - break; - case OS.XK_Escape: - tracking = false; - cancelled = true; - /* Eat the subsequent KeyRelease event */ - OS.XtAppNextEvent (OS.XtDisplayToApplicationContext (keyEvent.display), call_data); - break; - case OS.XK_Left: - xChange = -stepSize; - break; - case OS.XK_Right: - xChange = stepSize; - break; - case OS.XK_Up: - yChange = -stepSize; - break; - case OS.XK_Down: - yChange = stepSize; - break; - } - if (xChange != 0 || yChange != 0) { - Rectangle [] oldRectangles = rectangles; - boolean oldStippled = stippled; - Rectangle [] rectsToErase = new Rectangle [rectangles.length]; - for (int i = 0; i < rectangles.length; i++) { - Rectangle current = rectangles [i]; - rectsToErase [i] = new Rectangle (current.x, current.y, current.width, current.height); - } - Event event = new Event (); - event.x = oldX + xChange; - event.y = oldY + yChange; - Point cursorPos; - if ((style & SWT.RESIZE) != 0) { - resizeRectangles (xChange, yChange); - sendEvent (SWT.Resize, event); - /* - * It is possible (but unlikely) that application code - * could have disposed the widget in the resize event. - * If this happens then return false to indicate that - * the move failed. - */ - if (isDisposed ()) { - cancelled = true; - return 1; - } - boolean draw = false; - /* - * It is possible that application code could have - * changed the rectangles in the resize event. If this - * happens then only redraw the tracker if the rectangle - * values have changed. - */ - if (rectangles != oldRectangles) { - int length = rectangles.length; - if (length != rectsToErase.length) { - draw = true; - } else { - for (int i = 0; i < length; i++) { - if (!rectangles [i].equals (rectsToErase [i])) { - draw = true; - break; - } - } - } - } else { - draw = true; - } - if (draw) { - drawRectangles (rectsToErase, oldStippled); - update (); - drawRectangles (rectangles, stippled); - } - cursorPos = adjustResizeCursor (); - } else { - moveRectangles (xChange, yChange); - sendEvent (SWT.Move, event); - /* - * It is possible (but unlikely) that application code - * could have disposed the widget in the move event. - * If this happens then return false to indicate that - * the move failed. - */ - if (isDisposed ()) { - cancelled = true; - return 1; - } - boolean draw = false; - /* - * It is possible that application code could have - * changed the rectangles in the move event. If this - * happens then only redraw the tracker if the rectangle - * values have changed. - */ - if (rectangles != oldRectangles) { - int length = rectangles.length; - if (length != rectsToErase.length) { - draw = true; - } else { - for (int i = 0; i < length; i++) { - if (!rectangles [i].equals (rectsToErase [i])) { - draw = true; - break; - } - } - } - } else { - draw = true; - } - if (draw) { - drawRectangles (rectsToErase, oldStippled); - update (); - drawRectangles (rectangles, stippled); - } - cursorPos = adjustMoveCursor (); - } - if (cursorPos != null) { - oldX = cursorPos.x; - oldY = cursorPos.y; - } - } - } - return result; -} - -int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) { - if (cursor != null) { - int xDisplay = display.xDisplay; - OS.XChangeActivePointerGrab (xDisplay, - OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask, - cursor.handle, OS.CurrentTime); - } - return xMouse (OS.MotionNotify, w, client_data, call_data, continue_to_dispatch); -} - -int xMouse (int type, int w, int client_data, int call_data, int continue_to_dispatch) { - int xDisplay = display.xDisplay; - int [] newX = new int [1], newY = new int [1], unused = new int [1]; - OS.XQueryPointer (xDisplay, window, unused, unused, newX, newY, unused, unused, unused); - if (oldX != newX [0] || oldY != newY [0]) { - Rectangle [] oldRectangles = rectangles; - boolean oldStippled = stippled; - Rectangle [] rectsToErase = new Rectangle [rectangles.length]; - for (int i = 0; i < rectangles.length; i++) { - Rectangle current = rectangles [i]; - rectsToErase [i] = new Rectangle (current.x, current.y, current.width, current.height); - } - Event event = new Event (); - event.x = newX [0]; - event.y = newY [0]; - if ((style & SWT.RESIZE) != 0) { - resizeRectangles (newX [0] - oldX, newY [0] - oldY); - sendEvent (SWT.Resize, event); - /* - * It is possible (but unlikely) that application code - * could have disposed the widget in the resize event. - * If this happens then return false to indicate that - * the move failed. - */ - if (isDisposed ()) { - cancelled = true; - return 1; - } - boolean draw = false; - /* - * It is possible that application code could have - * changed the rectangles in the resize event. If this - * happens then only redraw the tracker if the rectangle - * values have changed. - */ - if (rectangles != oldRectangles) { - int length = rectangles.length; - if (length != rectsToErase.length) { - draw = true; - } else { - for (int i = 0; i < length; i++) { - if (!rectangles [i].equals (rectsToErase [i])) { - draw = true; - break; - } - } - } - } else { - draw = true; - } - if (draw) { - drawRectangles (rectsToErase, oldStippled); - update (); - drawRectangles (rectangles, stippled); - } - Point cursorPos = adjustResizeCursor (); - if (cursorPos != null) { - newX [0] = cursorPos.x; - newY [0] = cursorPos.y; - } - } else { - moveRectangles (newX [0] - oldX, newY [0] - oldY); - sendEvent (SWT.Move, event); - /* - * It is possible (but unlikely) that application code - * could have disposed the widget in the move event. - * If this happens then return false to indicate that - * the move failed. - */ - if (isDisposed ()) { - cancelled = true; - return 1; - } - boolean draw = false; - /* - * It is possible that application code could have - * changed the rectangles in the move event. If this - * happens then only redraw the tracker if the rectangle - * values have changed. - */ - if (rectangles != oldRectangles) { - int length = rectangles.length; - if (length != rectsToErase.length) { - draw = true; - } else { - for (int i = 0; i < length; i++) { - if (!rectangles [i].equals (rectsToErase [i])) { - draw = true; - break; - } - } - } - } else { - draw = true; - } - if (draw) { - drawRectangles (rectsToErase, oldStippled); - update (); - drawRectangles (rectangles, stippled); - } - } - oldX = newX [0]; - oldY = newY [0]; - } - tracking = type != OS.ButtonRelease; - return 0; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java deleted file mode 100755 index de1353482c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java +++ /dev/null @@ -1,1260 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2009 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.swt.widgets; - - -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.motif.*; -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; - -/** - * This class is the abstract superclass of all user interface objects. - * Widgets are created, disposed and issue notification to listeners - * when events occur which affect them. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>Dispose</dd> - * </dl> - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. However, it has not been marked - * final to allow those outside of the SWT development team to implement - * patched versions of the class in order to get around specific - * limitations in advance of when those limitations can be addressed - * by the team. Any class built using subclassing to access the internals - * of this class will likely fail to compile or run between releases and - * may be strongly platform specific. Subclassing should not be attempted - * without an intimate and detailed understanding of the workings of the - * hierarchy. No support is provided for user-written classes which are - * implemented as subclasses of this class. - * </p> - * - * @see #checkSubclass - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - */ -public abstract class Widget { - /** - * the handle to the OS resource - * (Warning: This field is platform dependent) - * <p> - * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms and should never be accessed from application code. - * </p> - */ - public int handle; - int style, state; - Display display; - EventTable eventTable; - Object data; - - /* Global state flags */ - static final int DISPOSED = 1<<0; - static final int CANVAS = 1<<1; - static final int KEYED_DATA = 1<<2; - static final int FOCUS_FORCED = 1<<3; - static final int BACKGROUND = 1<<4; - static final int FOREGROUND = 1<<5; - static final int PARENT_BACKGROUND = 1<<6; - static final int THEME_BACKGROUND = 1<<7; - - /* A layout was requested on this widget */ - static final int LAYOUT_NEEDED = 1<<8; - - /* The preferred size of a child has changed */ - static final int LAYOUT_CHANGED = 1<<9; - - /* A layout was requested in this widget hierachy */ - static final int LAYOUT_CHILD = 1<<10; - - /* More global state flags */ - static final int RELEASED = 1<<11; - static final int DISPOSE_SENT = 1<<12; - static final int FOREIGN_HANDLE = 1<<13; - static final int DRAG_DETECT = 1<<14; - - /* Default size for widgets */ - static final int DEFAULT_WIDTH = 64; - static final int DEFAULT_HEIGHT = 64; - - /* Events and Callback constants */ - static final int BUTTON_PRESS = 1; - static final int BUTTON_RELEASE = 2; - static final int EXPOSURE = 3; - static final int ENTER_WINDOW = 4; - static final int FOCUS_CHANGE = 5; - static final int KEY_PRESS = 6; - static final int KEY_RELEASE = 7; - static final int LEAVE_WINDOW = 8; - static final int ACTIVATE_CALLBACK = 9; - static final int ARM_CALLBACK = 10; - static final int BROWSE_SELECTION_CALLBACK = 11; - static final int CASCADING_CALLBACK = 12; - static final int DECREMENT_CALLBACK = 13; - static final int DEFAULT_ACTION_CALLBACK = 14; - static final int DRAG_CALLBACK = 15; - static final int EXTENDED_SELECTION_CALLBACK = 16; - static final int HELP_CALLBACK = 17; - static final int INCREMENT_CALLBACK = 18; - static final int MODIFY_VERIFY_CALLBACK = 19; - static final int PAGE_DECREMENT_CALLBACK = 20; - static final int PAGE_INCREMENT_CALLBACK = 21; - static final int TO_BOTTOM_CALLBACK = 22; - static final int TO_TOP_CALLBACK = 23; - static final int VALUE_CHANGED_CALLBACK = 24; - static final int NON_MASKABLE = 25; - static final int POINTER_MOTION = 26; - static final int STRUCTURE_NOTIFY = 27; - static final int MAP_CALLBACK = 28; - static final int UNMAP_CALLBACK = 29; - static final int DELETE_WINDOW = 30; - static final int EXPOSURE_CALLBACK = 31; - static final int MULTIPLE_SELECTION_CALLBACK = 32; - static final int PROPERTY_CHANGE = 33; - -Widget () { - /* Do nothing */ -} -/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * lists the style constants that are applicable to the class. - * Style bits are also inherited from superclasses. - * </p> - * - * @param parent a widget which will be the parent of the new instance (cannot be null) - * @param style the style of widget to construct - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the parent is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the parent is disposed</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - * - * @see SWT - * @see #checkSubclass - * @see #getStyle - */ -public Widget (Widget parent, int style) { - checkSubclass (); - checkParent (parent); - this.style = style; - display = parent.display; -} -/** - * Adds the listener to the collection of listeners who will - * be notified when an event of the given type occurs. When the - * event does occur in the widget, the listener is notified by - * sending it the <code>handleEvent()</code> message. The event - * type is one of the event constants defined in class <code>SWT</code>. - * - * @param eventType the type of event to listen for - * @param listener the listener which should be notified when the event occurs - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see Listener - * @see SWT - * @see #getListeners(int) - * @see #removeListener(int, Listener) - * @see #notifyListeners - */ -public void addListener (int eventType, Listener handler) { - checkWidget(); - if (handler == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) eventTable = new EventTable (); - eventTable.hook (eventType, handler); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the widget is disposed. When the widget is - * disposed, the listener is notified by sending it the - * <code>widgetDisposed()</code> message. - * - * @param listener the listener which should be notified when the receiver is disposed - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see DisposeListener - * @see #removeDisposeListener - */ -public void addDisposeListener (DisposeListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Dispose, typedListener); -} -static int checkBits (int style, int int0, int int1, int int2, int int3, int int4, int int5) { - int mask = int0 | int1 | int2 | int3 | int4 | int5; - if ((style & mask) == 0) style |= int0; - if ((style & int0) != 0) style = (style & ~mask) | int0; - if ((style & int1) != 0) style = (style & ~mask) | int1; - if ((style & int2) != 0) style = (style & ~mask) | int2; - if ((style & int3) != 0) style = (style & ~mask) | int3; - if ((style & int4) != 0) style = (style & ~mask) | int4; - if ((style & int5) != 0) style = (style & ~mask) | int5; - return style; -} -void checkOpen () { - /* Do nothing */ -} -void checkOrientation (Widget parent) { - style &= ~SWT.MIRRORED; - if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) { - if (parent != null) { - if ((parent.style & SWT.LEFT_TO_RIGHT) != 0) style |= SWT.LEFT_TO_RIGHT; - if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) style |= SWT.RIGHT_TO_LEFT; - } - } - style = checkBits (style, SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT, 0, 0, 0, 0); -} -void checkParent (Widget parent) { - if (parent == null) error (SWT.ERROR_NULL_ARGUMENT); - if (parent.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - parent.checkWidget (); - parent.checkOpen (); -} -/** - * Checks that this class can be subclassed. - * <p> - * The SWT class library is intended to be subclassed - * only at specific, controlled points (most notably, - * <code>Composite</code> and <code>Canvas</code> when - * implementing new widgets). This method enforces this - * rule unless it is overridden. - * </p><p> - * <em>IMPORTANT:</em> By providing an implementation of this - * method that allows a subclass of a class which does not - * normally allow subclassing to be created, the implementer - * agrees to be fully responsible for the fact that any such - * subclass will likely fail between SWT releases and will be - * strongly platform specific. No support is provided for - * user-written classes which are implemented in this fashion. - * </p><p> - * The ability to subclass outside of the allowed SWT classes - * is intended purely to enable those not on the SWT development - * team to implement patches in order to get around specific - * limitations in advance of when those limitations can be - * addressed by the team. Subclassing should not be attempted - * without an intimate and detailed understanding of the hierarchy. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> - * </ul> - */ -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} -/** - * Throws an <code>SWTException</code> if the receiver can not - * be accessed by the caller. This may include both checks on - * the state of the receiver and more generally on the entire - * execution context. This method <em>should</em> be called by - * widget implementors to enforce the standard SWT invariants. - * <p> - * Currently, it is an error to invoke any method (other than - * <code>isDisposed()</code>) on a widget that has had its - * <code>dispose()</code> method called. It is also an error - * to call widget methods from any thread that is different - * from the thread that created the widget. - * </p><p> - * In future releases of SWT, there may be more or fewer error - * checks and exceptions may be thrown for different reasons. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -protected void checkWidget () { - Display display = this.display; - if (display == null) error (SWT.ERROR_WIDGET_DISPOSED); - if (display.thread != Thread.currentThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if ((state & DISPOSED) != 0) error (SWT.ERROR_WIDGET_DISPOSED); -} -void createHandle (int index) { - /* Do nothing */ -} -void createWidget (int index) { - createHandle (index); - hookEvents (); - register (); - manageChildren (); -} -void deregister () { - if (handle == 0) return; - display.removeWidget (handle); -} -void destroyWidget () { - int topHandle = topHandle (); - releaseHandle (); - if (topHandle != 0) { - OS.XtDestroyWidget (topHandle); - } -} -/** - * Disposes of the operating system resources associated with - * the receiver and all its descendants. After this method has - * been invoked, the receiver and all descendants will answer - * <code>true</code> when sent the message <code>isDisposed()</code>. - * Any internal connections between the widgets in the tree will - * have been removed to facilitate garbage collection. - * <p> - * NOTE: This method is not called recursively on the descendants - * of the receiver. This means that, widget implementers can not - * detect when a widget is being disposed of by re-implementing - * this method, but should instead listen for the <code>Dispose</code> - * event. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #addDisposeListener - * @see #removeDisposeListener - * @see #checkWidget - */ -public void dispose () { - /* - * Note: It is valid to attempt to dispose a widget - * more than once. If this happens, fail silently. - */ - if (isDisposed ()) return; - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - release (true); -} -void enableHandle (boolean enabled, int widgetHandle) { - int [] argList = {OS.XmNsensitive, enabled ? 1 : 0}; - OS.XtSetValues (widgetHandle, argList, argList.length / 2); -} -void error (int code) { - SWT.error(code); -} -boolean filters (int eventType) { - return display.filters (eventType); -} -static char fixMnemonic (char [] buffer) { - int i=0, j=0; - char mnemonic=0; - while (i < buffer.length) { - if ((buffer [j++] = buffer [i++]) == '&') { - if (i == buffer.length) {continue;} - if (buffer [i] == '&') {i++; continue;} - if (mnemonic == 0) mnemonic = buffer [i]; - j--; - } - } - while (j < buffer.length) buffer [j++] = 0; - return mnemonic; -} -int focusProc (int w, int client_data, int call_data, int continue_to_dispatch) { - return 0; -} -String getCodePage () { - return null; -} -/** - * Returns the application defined widget data associated - * with the receiver, or null if it has not been set. The - * <em>widget data</em> is a single, unnamed field that is - * stored with every widget. - * <p> - * Applications may put arbitrary objects in this field. If - * the object stored in the widget data needs to be notified - * when the widget is disposed of, it is the application's - * responsibility to hook the Dispose event on the widget and - * do so. - * </p> - * - * @return the widget data - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li> - * </ul> - * - * @see #setData(Object) - */ -public Object getData () { - checkWidget(); - return (state & KEYED_DATA) != 0 ? ((Object []) data) [0] : data; -} - -/** - * Returns the application defined property of the receiver - * with the specified name, or null if it has not been set. - * <p> - * Applications may have associated arbitrary objects with the - * receiver in this fashion. If the objects stored in the - * properties need to be notified when the widget is disposed - * of, it is the application's responsibility to hook the - * Dispose event on the widget and do so. - * </p> - * - * @param key the name of the property - * @return the value of the property or null if it has not been set - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the key is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #setData(String, Object) - */ -public Object getData (String key) { - checkWidget(); - if (key == null) error (SWT.ERROR_NULL_ARGUMENT); - if ((state & KEYED_DATA) != 0) { - Object [] table = (Object []) data; - for (int i=1; i<table.length; i+=2) { - if (key.equals (table [i])) return table [i+1]; - } - } - return null; -} - -/** - * Returns the <code>Display</code> that is associated with - * the receiver. - * <p> - * A widget's display is either provided when it is created - * (for example, top level <code>Shell</code>s) or is the - * same as its parent's display. - * </p> - * - * @return the receiver's display - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Display getDisplay () { - Display display = this.display; - if (display == null) error (SWT.ERROR_WIDGET_DISPOSED); - return display; -} -/** - * Returns an array of listeners who will be notified when an event - * of the given type occurs. The event type is one of the event constants - * defined in class <code>SWT</code>. - * - * @param eventType the type of event to listen for - * @return an array of listeners that will be notified when the event occurs - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see Listener - * @see SWT - * @see #addListener(int, Listener) - * @see #removeListener(int, Listener) - * @see #notifyListeners - * - * @since 3.4 - */ -public Listener[] getListeners (int eventType) { - checkWidget(); - if (eventTable == null) return new Listener[0]; - return eventTable.getListeners(eventType); -} -String getName () { - String string = getClass ().getName (); - int index = string.lastIndexOf ('.'); - if (index == -1) return string; - return string.substring (index + 1, string.length ()); -} -String getNameText () { - return ""; -} -/** - * Returns the receiver's style information. - * <p> - * Note that the value which is returned by this method <em>may - * not match</em> the value which was provided to the constructor - * when the receiver was created. This can occur when the underlying - * operating system does not support a particular combination of - * requested styles. For example, if the platform widget used to - * implement a particular SWT widget always has scroll bars, the - * result of calling this method would always have the - * <code>SWT.H_SCROLL</code> and <code>SWT.V_SCROLL</code> bits set. - * </p> - * - * @return the style bits - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getStyle () { - checkWidget(); - return style; -} -void hookEvents () { - /* Do nothing */ -} -boolean hooks (int eventType) { - if (eventTable == null) return false; - return eventTable.hooks (eventType); -} -/** - * Returns <code>true</code> if the widget has been disposed, - * and <code>false</code> otherwise. - * <p> - * This method gets the dispose state for the widget. - * When a widget has been disposed, it is an error to - * invoke any other method using the widget. - * </p> - * - * @return <code>true</code> when the widget is disposed and <code>false</code> otherwise - */ -public boolean isDisposed () { - return (state & DISPOSED) != 0; -} -/** - * Returns <code>true</code> if there are any listeners - * for the specified event type associated with the receiver, - * and <code>false</code> otherwise. The event type is one of - * the event constants defined in class <code>SWT</code>. - * - * @param eventType the type of event - * @return true if the event is hooked - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SWT - */ -public boolean isListening (int eventType) { - checkWidget(); - return hooks (eventType); -} -boolean isValidSubclass () { - return Display.isValidClass (getClass ()); -} -boolean isValidThread () { - return getDisplay ().isValidThread (); -} -void manageChildren () { - /* Do nothing */ -} -/** - * Notifies all of the receiver's listeners for events - * of the given type that one such event has occurred by - * invoking their <code>handleEvent()</code> method. The - * event type is one of the event constants defined in class - * <code>SWT</code>. - * - * @param eventType the type of event which has occurred - * @param event the event data - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see SWT - * @see #addListener - * @see #getListeners(int) - * @see #removeListener(int, Listener) - */ -public void notifyListeners (int eventType, Event event) { - checkWidget(); - if (event == null) event = new Event (); - sendEvent (eventType, event); -} -void postEvent (int eventType) { - sendEvent (eventType, null, false); -} -void postEvent (int eventType, Event event) { - sendEvent (eventType, event, false); -} -void propagateHandle (boolean enabled, int widgetHandle, int cursor) { - int xDisplay = OS.XtDisplay (widgetHandle); - if (xDisplay == 0) return; - int xWindow = OS.XtWindow (widgetHandle); - if (xWindow == 0) return; - /* - * Get the event mask from the widget. The event mask - * returned by XtBuildEventMask () includes the masks - * associated with all callbacks and event handlers - * that have been hooked on the widget. - */ - int event_mask = OS.XtBuildEventMask (widgetHandle); - int do_not_propagate_mask = - OS.KeyPressMask | OS.KeyReleaseMask | OS.ButtonPressMask | - OS.ButtonReleaseMask | OS.PointerMotionMask; - if (!enabled) { - /* - * Attempting to propogate EnterWindowMask and LeaveWindowMask - * causes an X error so these must be specially cleared out from - * the event mask, not included in the propogate mask. - */ - event_mask &= ~(do_not_propagate_mask | OS.EnterWindowMask | OS.LeaveWindowMask); - do_not_propagate_mask = 0; - } - int mask = OS.CWDontPropagate | OS.CWEventMask | OS.CWCursor; - XSetWindowAttributes attributes = new XSetWindowAttributes (); - attributes.event_mask = event_mask; - attributes.do_not_propagate_mask = do_not_propagate_mask; - attributes.cursor = cursor; - OS.XChangeWindowAttributes (xDisplay, xWindow, mask, attributes); -} -void redrawHandle (int x, int y, int width, int height, boolean redrawAll, int widgetHandle) { - int display = OS.XtDisplay (widgetHandle); - if (display == 0) return; - int window = OS.XtWindow (widgetHandle); - if (window == 0) return; - if (redrawAll) { - OS.XClearArea (display, window, 0, 0, 0, 0, true); - } else { - if (width > 0 && height > 0) { - int [] argList = { - OS.XmNwidth, 0, /* 1 */ - OS.XmNheight, 0, /* 3 */ - }; - OS.XtGetValues (widgetHandle, argList, argList.length / 2); - if ((x < argList [1]) && (y < argList [3]) && (x + width > 0) && (y + height > 0)) { - OS.XClearArea (display, window, x, y, width, height, true); - } - } - } -} -void register () { - if (handle == 0) return; - display.addWidget (handle, this); -} -void release (boolean destroy) { - if ((state & DISPOSE_SENT) == 0) { - state |= DISPOSE_SENT; - sendEvent (SWT.Dispose); - } - if ((state & DISPOSED) == 0) { - releaseChildren (destroy); - } - if ((state & RELEASED) == 0) { - state |= RELEASED; - if (destroy) { - releaseParent (); - releaseWidget (); - destroyWidget (); - } else { - releaseWidget (); - releaseHandle (); - } - } -} -void releaseChildren (boolean destroy) { -} -void releaseHandle () { - handle = 0; - state |= DISPOSED; - display = null; -} -void releaseParent () { - /* Do nothing */ -} -void releaseWidget () { - deregister (); - eventTable = null; - data = null; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when an event of the given type occurs. The event - * type is one of the event constants defined in class <code>SWT</code>. - * - * @param eventType the type of event to listen for - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see Listener - * @see SWT - * @see #addListener - * @see #getListeners(int) - * @see #notifyListeners - */ -public void removeListener (int eventType, Listener handler) { - checkWidget(); - if (handler == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (eventType, handler); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when an event of the given type occurs. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT - * public API. It is marked public only so that it can be shared - * within the packages provided by SWT. It should never be - * referenced from application code. - * </p> - * - * @param eventType the type of event to listen for - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see Listener - * @see #addListener - */ -protected void removeListener (int eventType, SWTEventListener handler) { - checkWidget(); - if (handler == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (eventType, handler); -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the widget is disposed. - * - * @param listener the listener which should no longer be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see DisposeListener - * @see #addDisposeListener - */ -public void removeDisposeListener (DisposeListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Dispose, listener); -} -boolean setInputState (Event event, int state) { - if ((state & OS.Mod1Mask) != 0) event.stateMask |= SWT.ALT; - if ((state & OS.ShiftMask) != 0) event.stateMask |= SWT.SHIFT; - if ((state & OS.ControlMask) != 0) event.stateMask |= SWT.CONTROL; - if ((state & OS.Button1Mask) != 0) event.stateMask |= SWT.BUTTON1; - if ((state & OS.Button2Mask) != 0) event.stateMask |= SWT.BUTTON2; - if ((state & OS.Button3Mask) != 0) event.stateMask |= SWT.BUTTON3; - return true; -} -boolean setKeyState (Event event, XKeyEvent xEvent) { - if (xEvent.keycode == 0) return false; - byte [] buffer = new byte [5]; - int [] keysym = new int [1]; - OS.XLookupString (xEvent, buffer, buffer.length, keysym, null); - boolean isNull = display.fixKey (keysym, buffer, xEvent.state); - if (keysym [0] != 0) { - event.keyCode = Display.translateKey (keysym [0]); - } - if (event.keyCode == 0) { - byte [] buffer1 = new byte [5]; - int [] keysym1 = new int [1]; - int oldState = xEvent.state; - xEvent.state = 0; - OS.XLookupString (xEvent, buffer1, buffer1.length, keysym1, null); - xEvent.state = oldState; - if (buffer1 [0] != 0) { - char [] result = Converter.mbcsToWcs (null, buffer1); - if (result.length != 0) event.keyCode = result [0]; - } - } - if (buffer [0] != 0) { - char [] result = Converter.mbcsToWcs (null, buffer); - if (result.length != 0) event.character = result [0]; - } - if (event.keyCode == 0 && event.character == 0) { - if (!isNull) return false; - } - return setInputState (event, xEvent.state); -} -void sendEvent (Event event) { - Display display = event.display; - if (!display.filterEvent (event)) { - if (eventTable != null) eventTable.sendEvent (event); - } -} -void sendEvent (int eventType) { - sendEvent (eventType, null, true); -} -void sendEvent (int eventType, Event event) { - sendEvent (eventType, event, true); -} -void sendEvent (int eventType, Event event, boolean send) { - if (eventTable == null && !display.filters (eventType)) { - return; - } - if (event == null) event = new Event (); - event.type = eventType; - event.display = display; - event.widget = this; - if (event.time == 0) { - event.time = display.getLastEventTime (); - } - if (send) { - sendEvent (event); - } else { - display.postEvent (event); - } -} -boolean sendIMKeyEvent (int type, XKeyEvent xEvent) { - return sendIMKeyEvent (type, xEvent, 0); -} -boolean sendIMKeyEvent (int type, XKeyEvent xEvent, int textHandle) { - /* - * Bug in Motif. On Linux only, XmImMbLookupString () does not return - * XBufferOverflow as the status if the buffer is too small. The fix - * is to pass a large buffer. - */ - byte [] buffer = new byte [512]; - int [] status = new int [1], unused = new int [1]; - int focusHandle = OS.XtWindowToWidget (xEvent.display, xEvent.window); - int length = OS.XmImMbLookupString (focusHandle, xEvent, buffer, buffer.length, unused, status); - if (status [0] == OS.XBufferOverflow) { - buffer = new byte [length]; - length = OS.XmImMbLookupString (focusHandle, xEvent, buffer, length, unused, status); - } - if (length == 0) return true; - - /* Convert from MBCS to UNICODE and send the event */ - /* Use the character encoding for the default locale */ - char [] chars = Converter.mbcsToWcs (null, buffer); - int index = 0, count = 0; - while (index < chars.length) { - if (chars [index] == 0) { - chars [count] = 0; - break; - } - Event event = new Event (); - event.time = xEvent.time; - event.character = chars [index]; - setInputState (event, xEvent.state); - sendEvent (type, event); - // widget could be disposed at this point - - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in the key - * events. If this happens, end the processing of - * the key by returning false. - */ - if (isDisposed ()) return false; - if (event.doit) chars [count++] = chars [index]; - index++; - } - if (count == 0) return false; - if (textHandle != 0) { - /* - * Bug in Motif. On Solaris and Linux, XmImMbLookupString() clears - * the characters from the IME. This causes the characters to be - * stolen from the text widget. The fix is to detect that the IME - * has been cleared and use XmTextInsert() to insert the stolen - * characters. This problem does not happen on AIX. - */ - byte [] testBuffer = new byte [5]; - int testLength = OS.XmImMbLookupString (textHandle, xEvent, testBuffer, testBuffer.length, unused, unused); - if (testLength == 0 || index != count) { - int [] start = new int [1], end = new int [1]; - OS.XmTextGetSelectionPosition (textHandle, start, end); - if (start [0] == end [0]) { - start [0] = end [0] = OS.XmTextGetInsertionPosition (textHandle); - } - boolean warnings = display.getWarnings (); - display.setWarnings (false); - if (index != count) { - buffer = Converter.wcsToMbcs (getCodePage (), chars, true); - } - OS.XmTextReplace (textHandle, start [0], end [0], buffer); - int position = start [0] + count; - OS.XmTextSetInsertionPosition (textHandle, position); - display.setWarnings (warnings); - return false; - } - } - return true; -} -boolean sendKeyEvent (int type, XKeyEvent xEvent) { - Event event = new Event (); - event.time = xEvent.time; - if (!setKeyState (event, xEvent)) return true; - Widget control = this; - if ((state & CANVAS) != 0) { - if ((style & SWT.NO_FOCUS) != 0) { - control = display.getFocusControl (); - } - } - if (control != null) { - control.sendEvent (type, event); - // widget could be disposed at this point - - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in the key - * events. If this happens, end the processing of - * the key by returning false. - */ - if (isDisposed ()) return false; - } - return event.doit; -} -/** - * Sets the application defined widget data associated - * with the receiver to be the argument. The <em>widget - * data</em> is a single, unnamed field that is stored - * with every widget. - * <p> - * Applications may put arbitrary objects in this field. If - * the object stored in the widget data needs to be notified - * when the widget is disposed of, it is the application's - * responsibility to hook the Dispose event on the widget and - * do so. - * </p> - * - * @param data the widget data - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - when the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li> - * </ul> - * - * @see #getData() - */ -public void setData (Object data) { - checkWidget(); - if ((state & KEYED_DATA) != 0) { - ((Object []) this.data) [0] = data; - } else { - this.data = data; - } -} - -/** - * Sets the application defined property of the receiver - * with the specified name to the given value. - * <p> - * Applications may associate arbitrary objects with the - * receiver in this fashion. If the objects stored in the - * properties need to be notified when the widget is disposed - * of, it is the application's responsibility to hook the - * Dispose event on the widget and do so. - * </p> - * - * @param key the name of the property - * @param value the new value for the property - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the key is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #getData(String) - */ -public void setData (String key, Object value) { - checkWidget(); - if (key == null) error (SWT.ERROR_NULL_ARGUMENT); - int index = 1; - Object [] table = null; - if ((state & KEYED_DATA) != 0) { - table = (Object []) data; - while (index < table.length) { - if (key.equals (table [index])) break; - index += 2; - } - } - if (value != null) { - if ((state & KEYED_DATA) != 0) { - if (index == table.length) { - Object [] newTable = new Object [table.length + 2]; - System.arraycopy (table, 0, newTable, 0, table.length); - data = table = newTable; - } - } else { - table = new Object [3]; - table [0] = data; - data = table; - state |= KEYED_DATA; - } - table [index] = key; - table [index + 1] = value; - } else { - if ((state & KEYED_DATA) != 0) { - if (index != table.length) { - int length = table.length - 2; - if (length == 1) { - data = table [0]; - state &= ~KEYED_DATA; - } else { - Object [] newTable = new Object [length]; - System.arraycopy (table, 0, newTable, 0, index); - System.arraycopy (table, index + 2, newTable, index, length - index); - data = newTable; - } - } - } - } -} - -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the receiver - */ -public String toString () { - String string = "*Disposed*"; - if (!isDisposed ()) { - string = "*Wrong Thread*"; - if (isValidThread ()) string = getNameText (); - } - return getName () + " {" + string + "}"; -} -int topHandle () { - return handle; -} -boolean translateAccelerator (char key, int keysym, XKeyEvent xEvent, boolean doit) { - return false; -} -boolean translateMnemonic (char key, int keysym, XKeyEvent xEvent) { - return false; -} -boolean translateTraversal (int key, XKeyEvent xEvent) { - return false; -} -boolean XmProcessTraversal (int widget, int direction) { - /* - * Bug in Motif. When XtDestroyWidget() is called from - * within a FocusOut event handler, Motif GP's. The fix - * is to post focus events and run them when the handler - * has returned. - */ - Display display = this.display; - boolean oldFocusOut = display.postFocusOut; - display.postFocusOut = true; - boolean result = OS.XmProcessTraversal (widget, direction); - display.postFocusOut = oldFocusOut; - if (!display.postFocusOut) { - display.focusEvent = SWT.FocusOut; - display.runFocusOutEvents (); - display.focusEvent = SWT.None; - } - return result; -} -int hoverProc (int widget) { - return 0; -} -int timerProc (int id) { - return 0; -} -int windowProc (int w, int client_data, int call_data, int continue_to_dispatch) { - switch (client_data) { - case BUTTON_PRESS: return XButtonPress (w, client_data, call_data, continue_to_dispatch); - case BUTTON_RELEASE: return XButtonRelease (w, client_data, call_data, continue_to_dispatch); - case ENTER_WINDOW: return XEnterWindow (w, client_data, call_data, continue_to_dispatch); - case EXPOSURE: return XExposure (w, client_data, call_data, continue_to_dispatch); - case FOCUS_CHANGE: return XFocusChange (w, client_data, call_data, continue_to_dispatch); - case KEY_PRESS: return XKeyPress (w, client_data, call_data, continue_to_dispatch); - case KEY_RELEASE: return XKeyRelease (w, client_data, call_data, continue_to_dispatch); - case LEAVE_WINDOW: return XLeaveWindow (w, client_data, call_data, continue_to_dispatch); - case PROPERTY_CHANGE: return XPropertyChange (w, client_data, call_data, continue_to_dispatch); - case ACTIVATE_CALLBACK: return XmNactivateCallback (w, client_data, call_data); - case ARM_CALLBACK: return XmNarmCallback (w, client_data, call_data); - case BROWSE_SELECTION_CALLBACK: return XmNbrowseSelectionCallback (w, client_data, call_data); - case CASCADING_CALLBACK: return XmNcascadingCallback (w, client_data, call_data); - case DECREMENT_CALLBACK: return XmNdecrementCallback (w, client_data, call_data); - case DEFAULT_ACTION_CALLBACK: return XmNdefaultActionCallback (w, client_data, call_data); - case DRAG_CALLBACK: return XmNdragCallback (w, client_data, call_data); - case EXTENDED_SELECTION_CALLBACK: return XmNextendedSelectionCallback (w, client_data, call_data); - case HELP_CALLBACK: return XmNhelpCallback (w, client_data, call_data); - case INCREMENT_CALLBACK: return XmNincrementCallback (w, client_data, call_data); - case MODIFY_VERIFY_CALLBACK: return XmNmodifyVerifyCallback (w, client_data, call_data); - case MULTIPLE_SELECTION_CALLBACK: return XmNmultipleSelectionCallback (w, client_data, call_data); - case PAGE_DECREMENT_CALLBACK: return XmNpageDecrementCallback (w, client_data, call_data); - case PAGE_INCREMENT_CALLBACK: return XmNpageIncrementCallback (w, client_data, call_data); - case TO_BOTTOM_CALLBACK: return XmNtoBottomCallback (w, client_data, call_data); - case TO_TOP_CALLBACK: return XmNtoTopCallback (w, client_data, call_data); - case VALUE_CHANGED_CALLBACK: return XmNvalueChangedCallback (w, client_data, call_data); - case NON_MASKABLE: return XNonMaskable (w, client_data, call_data, continue_to_dispatch); - case POINTER_MOTION : return XPointerMotion (w, client_data, call_data, continue_to_dispatch); - case STRUCTURE_NOTIFY: return XStructureNotify (w, client_data, call_data, continue_to_dispatch); - case MAP_CALLBACK: return XmNmapCallback (w, client_data, call_data); - case UNMAP_CALLBACK: return XmNunmapCallback (w, client_data, call_data); - case DELETE_WINDOW: return WM_DELETE_WINDOW (w, client_data, call_data); - case EXPOSURE_CALLBACK: return XmNexposureCallback (w, client_data, call_data); - } - return 0; -} -int WM_DELETE_WINDOW (int w, int client_data, int call_data) { - return 0; -} -int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) { - return 0; -} -int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) { - return 0; -} -int XEnterWindow (int w, int client_data, int call_data, int continue_to_dispatch) { - return 0; -} -int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) { - return 0; -} -int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatch) { - return 0; -} -int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) { - XKeyEvent xEvent = new XKeyEvent (); - OS.memmove (xEvent, call_data, XKeyEvent.sizeof); - boolean doit = true; - if (xEvent.keycode != 0) { - doit = sendKeyEvent (SWT.KeyDown, xEvent); - } else { - doit = sendIMKeyEvent (SWT.KeyDown, xEvent); - } - if (!doit) { - OS.memmove (continue_to_dispatch, new int [1], 4); - return 1; - } - return 0; -} -int XKeyRelease (int w, int client_data, int call_data, int continue_to_dispatch) { - XKeyEvent xEvent = new XKeyEvent (); - OS.memmove (xEvent, call_data, XKeyEvent.sizeof); - if (!sendKeyEvent (SWT.KeyUp, xEvent)) { - OS.memmove (continue_to_dispatch, new int [1], 4); - return 1; - } - return 0; -} -int XLeaveWindow (int w, int client_data, int call_data, int continue_to_dispatch) { - return 0; -} -int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) { - return 0; -} -int XPropertyChange (int w, int client_data, int call_data, int continue_to_dispatch) { - return 0; -} -int XmNactivateCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNarmCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNbrowseSelectionCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNcascadingCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNdecrementCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNdefaultActionCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNdragCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNexposureCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNextendedSelectionCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNhelpCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNincrementCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNmapCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNmodifyVerifyCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNmultipleSelectionCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNpageDecrementCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNpageIncrementCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNtoBottomCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNtoTopCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNunmapCallback (int w, int client_data, int call_data) { - return 0; -} -int XmNvalueChangedCallback (int w, int client_data, int call_data) { - return 0; -} -int XNonMaskable (int w, int client_data, int call_data, int continue_to_dispatch) { - return 0; -} -int XStructureNotify (int w, int client_data, int call_data, int continue_to_dispatch) { - return 0; -} -} |