diff options
author | Felipe Heidrich | 2009-06-30 22:00:12 +0000 |
---|---|---|
committer | Felipe Heidrich | 2009-06-30 22:00:12 +0000 |
commit | f664d297f7bb009784868bf3fcf0b3e3bb9a646b (patch) | |
tree | 54012fe4929893eef4891c88cbbf5841272ff433 /bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt | |
parent | bc18a5e014088ce811f09c603b88361094486062 (diff) | |
download | eclipse.platform.swt-f664d297f7bb009784868bf3fcf0b3e3bb9a646b.tar.gz eclipse.platform.swt-f664d297f7bb009784868bf3fcf0b3e3bb9a646b.tar.xz eclipse.platform.swt-f664d297f7bb009784868bf3fcf0b3e3bb9a646b.zip |
*** empty log message ***
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt')
60 files changed, 0 insertions, 62256 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Color.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Color.java deleted file mode 100644 index e3fae9ed44..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Color.java +++ /dev/null @@ -1,289 +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.gtk.*; -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 GdkColor 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 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.gdkColors[pixel] = null; - } - } - int /*long*/ colormap = OS.gdk_colormap_get_system(); - OS.gdk_colormap_free_colors(colormap, handle, 1); - 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; - GdkColor gdkColor = color.handle; - if (handle == gdkColor) return true; - return device == color.device && handle.red == gdkColor.red && - handle.green == gdkColor.green && handle.blue == gdkColor.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 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; -} - -/** - * 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(getRed(), getGreen(), getBlue()); -} - -/** - * Invokes platform specific functionality to allocate a new color. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>Color</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @param device the device on which to allocate the color - * @param handle the handle for the color - * - * @private - */ -public static Color gtk_new(Device device, GdkColor gdkColor) { - Color color = new Color(device); - color.handle = gdkColor; - return color; -} - -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); - } - GdkColor gdkColor = new GdkColor(); - gdkColor.red = (short)((red & 0xFF) | ((red & 0xFF) << 8)); - gdkColor.green = (short)((green & 0xFF) | ((green & 0xFF) << 8)); - gdkColor.blue = (short)((blue & 0xFF) | ((blue & 0xFF) << 8)); - int /*long*/ colormap = OS.gdk_colormap_get_system(); - if (!OS.gdk_colormap_alloc_color(colormap, gdkColor, true, true)) { - /* Allocate black. */ - gdkColor = new GdkColor(); - OS.gdk_colormap_alloc_color(colormap, gdkColor, true, true); - } - handle = gdkColor; - if (device.colorRefCount != null) { - /* Make a copy of the color to put in the colors array */ - GdkColor colorCopy = new GdkColor(); - colorCopy.red = handle.red; - colorCopy.green = handle.green; - colorCopy.blue = handle.blue; - colorCopy.pixel = handle.pixel; - device.gdkColors[colorCopy.pixel] = colorCopy; - device.colorRefCount[colorCopy.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; -} - -/** - * 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/gtk/org/eclipse/swt/graphics/Cursor.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Cursor.java deleted file mode 100644 index ce5768c244..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Cursor.java +++ /dev/null @@ -1,527 +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.*; -import org.eclipse.swt.internal.gtk.*; - -/** - * 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 /*long*/ 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.GDK_LEFT_PTR; break; - case SWT.CURSOR_WAIT: shape = OS.GDK_WATCH; break; - case SWT.CURSOR_CROSS: shape = OS.GDK_CROSS; break; - case SWT.CURSOR_HAND: shape = OS.GDK_HAND2; break; - case SWT.CURSOR_HELP: shape = OS.GDK_QUESTION_ARROW; break; - case SWT.CURSOR_SIZEALL: shape = OS.GDK_FLEUR; break; - case SWT.CURSOR_SIZENESW: shape = OS.GDK_SIZING; break; - case SWT.CURSOR_SIZENS: shape = OS.GDK_DOUBLE_ARROW; break; - case SWT.CURSOR_SIZENWSE: shape = OS.GDK_SIZING; break; - case SWT.CURSOR_SIZEWE: shape = OS.GDK_SB_H_DOUBLE_ARROW; break; - case SWT.CURSOR_SIZEN: shape = OS.GDK_TOP_SIDE; break; - case SWT.CURSOR_SIZES: shape = OS.GDK_BOTTOM_SIDE; break; - case SWT.CURSOR_SIZEE: shape = OS.GDK_RIGHT_SIDE; break; - case SWT.CURSOR_SIZEW: shape = OS.GDK_LEFT_SIDE; break; - case SWT.CURSOR_SIZENE: shape = OS.GDK_TOP_RIGHT_CORNER; break; - case SWT.CURSOR_SIZESE: shape = OS.GDK_BOTTOM_RIGHT_CORNER; break; - case SWT.CURSOR_SIZESW: shape = OS.GDK_BOTTOM_LEFT_CORNER; break; - case SWT.CURSOR_SIZENW: shape = OS.GDK_TOP_LEFT_CORNER; break; - case SWT.CURSOR_UPARROW: shape = OS.GDK_SB_UP_ARROW; break; - case SWT.CURSOR_IBEAM: shape = OS.GDK_XTERM; break; - case SWT.CURSOR_NO: shape = OS.GDK_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.gdk_cursor_new(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_NULL_ARGUMENT); - mask = source.getTransparencyMask(); - } - /* Check the bounds. Mask must be the same size as source */ - if (mask.width != source.width || mask.height != source.height) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - /* Check the hotspots */ - if (hotspotX >= source.width || hotspotX < 0 || - hotspotY >= source.height || hotspotY < 0) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - /* Convert depth to 1 */ - source = ImageData.convertMask(source); - mask = ImageData.convertMask(mask); - - /* 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[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); - 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); - } - int /*long*/ display = 0; - if (OS.GTK_VERSION >= OS.VERSION(2, 4, 0) && OS.gdk_display_supports_cursor_color(display = OS.gdk_display_get_default ())) { - int width = source.width; - int height = source.height; - PaletteData palette = source.palette; - int /*long*/ pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, true, 8, width, height); - if (pixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); - int /*long*/ data = OS.gdk_pixbuf_get_pixels(pixbuf); - byte[] buffer = source.data; - if (!palette.isDirect || source.depth != 24 || stride != source.bytesPerLine || palette.redMask != 0xFF000000 || palette.greenMask != 0xFF0000 || palette.blueMask != 0xFF00) { - buffer = new byte[source.width * source.height * 4]; - 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, - buffer, 32, source.width * 4, ImageData.MSB_FIRST, 0, 0, source.width, source.height, 0xFF000000, 0xFF0000, 0xFF00, - 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, - buffer, 32, source.width * 4, ImageData.MSB_FIRST, 0, 0, source.width, source.height, 0xFF000000, 0xFF0000, 0xFF00, - false, false); - } - if (source.maskData != null || source.transparentPixel != -1) { - ImageData mask = source.getTransparencyMask(); - byte[] maskData = mask.data; - int maskBpl = mask.bytesPerLine; - int offset = 3, maskOffset = 0; - for (int y = 0; y<source.height; y++) { - for (int x = 0; x<source.width; x++) { - buffer[offset] = ((maskData[maskOffset + (x >> 3)]) & (1 << (7 - (x & 0x7)))) != 0 ? (byte)0xff : 0; - offset += 4; - } - maskOffset += maskBpl; - } - } else if (source.alpha != -1) { - byte alpha = (byte)source.alpha; - for (int i=3; i<buffer.length; i+=4) { - buffer[i] = alpha; - } - } else if (source.alphaData != null) { - byte[] alphaData = source.alphaData; - for (int i=3; i<buffer.length; i+=4) { - buffer[i] = alphaData[i/4]; - } - } - } - OS.memmove(data, buffer, stride * height); - handle = OS.gdk_cursor_new_from_pixbuf(display, pixbuf, hotspotX, hotspotY); - OS.g_object_unref(pixbuf); - } else { - - 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 /*long*/ createCursor(byte[] sourceData, byte[] maskData, int width, int height, int hotspotX, int hotspotY, boolean reverse) { - int /*long*/ sourcePixmap = OS.gdk_bitmap_create_from_data(0, sourceData, width, height); - int /*long*/ maskPixmap = OS.gdk_bitmap_create_from_data(0, maskData, width, height); - int /*long*/ cursor = 0; - if (sourcePixmap != 0 && maskPixmap != 0) { - GdkColor foreground = new GdkColor(); - if (!reverse) foreground.red = foreground.green = foreground.blue = (short)0xFFFF; - GdkColor background = new GdkColor(); - if (reverse) background.red = background.green = background.blue = (short)0xFFFF; - cursor = OS.gdk_cursor_new_from_pixmap (sourcePixmap, maskPixmap, foreground, background, hotspotX, hotspotY); - } - if (sourcePixmap != 0) OS.g_object_unref (sourcePixmap); - if (maskPixmap != 0) OS.g_object_unref (maskPixmap); - return cursor; -} - -void destroy() { - OS.gdk_cursor_destroy(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; -} - -/** - * Invokes platform specific functionality to allocate a new cursor. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>Cursor</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @param device the device on which to allocate the color - * @param handle the handle for the cursor - * - * @private - */ -public static Cursor gtk_new(Device device, int /*long*/ handle) { - Cursor cursor = new Cursor(device); - cursor.handle = handle; - return cursor; -} - -/** - * Returns an integer hash code for the receiver. Any two - * objects that return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals - */ -public int hashCode() { - return (int)/*64*/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; -} - -/** - * 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/gtk/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java deleted file mode 100644 index fbacfcf587..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Device.java +++ /dev/null @@ -1,902 +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.gtk.*; - -/** - * 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 protected 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> - */ - protected int /*long*/ xDisplay; - int /*long*/ shellHandle; - - /* Debugging */ - public static boolean DEBUG; - boolean debug = DEBUG; - boolean tracking = DEBUG; - Error [] errors; - Object [] objects; - Object trackingLock; - - /* Colormap and reference count */ - GdkColor [] gdkColors; - int [] colorRefCount; - - /* Disposed flag */ - boolean disposed; - - /* Warning and Error Handlers */ - int /*long*/ logProc; - Callback logCallback; - //NOT DONE - get list of valid names - String [] log_domains = {"GLib-GObject", "GLib", "GObject", "Pango", "ATK", "GdkPixbuf", "Gdk", "Gtk", "GnomeVFS"}; - int [] handler_ids = new int [log_domains.length]; - int warningLevel; - - /* X Warning and Error Handlers */ - static Callback XErrorCallback, XIOErrorCallback; - static int /*long*/ XErrorProc, XIOErrorProc, XNullErrorProc, XNullIOErrorProc; - static Device[] Devices = new Device[4]; - - /* - * The following colors are listed in the Windows - * Programmer's Reference as the colors in the default - * palette. - */ - 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 /*long*/ emptyTab; - - boolean useXRender; - - static boolean CAIRO_LOADED; - - /* - * 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) { - debug = data.debug; - tracking = data.tracking; - } - if (tracking) { - errors = new Error [128]; - objects = new Object [128]; - trackingLock = new Object (); - } - create (data); - init (); - register (this); - } -} - -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 is 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 (disposed) SWT.error(SWT.ERROR_DEVICE_DISPOSED); -} - -/** - * Creates the device in the operating system. If the device - * does not have a handle, this method may do nothing depending - * on the device. - * <p> - * This method is called before <code>init</code>. - * </p><p> - * Subclasses are supposed to reimplement this method and not - * call the <code>super</code> implementation. - * </p> - * - * @param data the DeviceData which describes the receiver - * - * @see #init - */ -protected void create (DeviceData data) { -} - -/** - * 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; - disposed = true; - 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 /*long*/ xDisplay) { - for (int i=0; i<Devices.length; i++) { - Device device = Devices [i]; - if (device != null && device.xDisplay == xDisplay) { - return device; - } - } - return null; -} - -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 () { -} - -/** - * Returns a rectangle describing the receiver's size and location. - * - * @return the bounding rectangle - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Rectangle getBounds () { - checkDevice (); - return new Rectangle(0, 0, 0, 0); -} - -/** - * Returns a <code>DeviceData</code> based on the receiver. - * Modifications made to this <code>DeviceData</code> will not - * affect the receiver. - * - * @return a <code>DeviceData</code> containing the device's data and attributes - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see DeviceData - */ -public DeviceData getDeviceData () { - checkDevice(); - DeviceData data = new DeviceData (); - data.debug = debug; - data.tracking = tracking; - if (tracking) { - synchronized (trackingLock) { - int count = 0, length = objects.length; - for (int i=0; i<length; i++) { - if (objects [i] != null) count++; - } - int index = 0; - data.objects = new Object [count]; - data.errors = new Error [count]; - for (int i=0; i<length; i++) { - if (objects [i] != null) { - data.objects [index] = objects [i]; - data.errors [index] = errors [i]; - index++; - } - } - } - } else { - data.objects = new Object [0]; - data.errors = new Error [0]; - } - return data; -} - -/** - * Returns a rectangle which describes the area of the - * receiver which is capable of displaying data. - * - * @return the client area - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #getBounds - */ -public Rectangle getClientArea () { - checkDevice (); - return getBounds (); -} - -/** - * Returns the bit depth of the screen, which is the number of - * bits it takes to represent the number of unique colors that - * the screen is currently capable of displaying. This number - * will typically be one of 1, 8, 15, 16, 24 or 32. - * - * @return the depth of the screen - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int getDepth () { - checkDevice (); - return 0; -} - -/** - * Returns a point whose x coordinate is the horizontal - * dots per inch of the display, and whose y coordinate - * is the vertical dots per inch of the display. - * - * @return the horizontal and vertical DPI - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Point getDPI () { - checkDevice (); - return new Point (72, 72); -} - -/** - * 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 (); - if (!scalable) return new FontData[0]; - int /*long*/[] family = new int /*long*/[1]; - int /*long*/[] face = new int /*long*/[1]; - int /*long*/[] families = new int /*long*/[1]; - int[] n_families = new int[1]; - int /*long*/[] faces = new int /*long*/[1]; - int[] n_faces = new int[1]; - int /*long*/ context = OS.gdk_pango_context_get(); - OS.pango_context_list_families(context, families, n_families); - int nFds = 0; - FontData[] fds = new FontData[faceName != null ? 4 : n_families[0]]; - for (int i=0; i<n_families[0]; i++) { - OS.memmove(family, families[0] + i * OS.PTR_SIZEOF, OS.PTR_SIZEOF); - boolean match = true; - if (faceName != null) { - int /*long*/ familyName = OS.pango_font_family_get_name(family[0]); - int length = OS.strlen(familyName); - byte[] buffer = new byte[length]; - OS.memmove(buffer, familyName, length); - String name = new String(Converter.mbcsToWcs(null, buffer)); - match = Compatibility.equalsIgnoreCase(faceName, name); - } - if (match) { - OS.pango_font_family_list_faces(family[0], faces, n_faces); - for (int j=0; j<n_faces[0]; j++) { - OS.memmove(face, faces[0] + j * OS.PTR_SIZEOF, OS.PTR_SIZEOF); - int /*long*/ fontDesc = OS.pango_font_face_describe(face[0]); - Font font = Font.gtk_new(this, fontDesc); - FontData data = font.getFontData()[0]; - if (nFds == fds.length) { - FontData[] newFds = new FontData[fds.length + n_families[0]]; - System.arraycopy(fds, 0, newFds, 0, nFds); - fds = newFds; - } - fds[nFds++] = data; - OS.pango_font_description_free(fontDesc); - } - OS.g_free(faces[0]); - if (faceName != null) break; - } - } - OS.g_free(families[0]); - OS.g_object_unref(context); - if (nFds == fds.length) return fds; - FontData[] result = new FontData[nFds]; - System.arraycopy(fds, 0, result, 0, nFds); - 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 warningLevel == 0; -} - -/** - * 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 (xDisplay != 0) { - 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); - } - } - - if (debug) { - if (xDisplay != 0) { - /* Create the warning and error callbacks */ - Class clazz = getClass (); - synchronized (clazz) { - int index = 0; - while (index < Devices.length) { - if (Devices [index] != null) break; - index++; - } - if (index == Devices.length) { - XErrorCallback = new Callback (clazz, "XErrorProc", 2); - XNullErrorProc = XErrorCallback.getAddress (); - if (XNullErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - XIOErrorCallback = new Callback (clazz, "XIOErrorProc", 1); - XNullIOErrorProc = XIOErrorCallback.getAddress (); - if (XNullIOErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - XErrorProc = OS.XSetErrorHandler (XNullErrorProc); - XIOErrorProc = OS.XSetIOErrorHandler (XNullIOErrorProc); - } - } - OS.XSynchronize (xDisplay, true); - } - } - - /* Create GTK warnings and error callbacks */ - if (xDisplay != 0) { - logCallback = new Callback (this, "logProc", 4); - logProc = logCallback.getAddress (); - if (logProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - - /* Set GTK warning and error handlers */ - if (debug) { - int flags = OS.G_LOG_LEVEL_MASK | OS.G_LOG_FLAG_FATAL | OS.G_LOG_FLAG_RECURSION; - for (int i=0; i<log_domains.length; i++) { - byte [] log_domain = Converter.wcsToMbcs (null, log_domains [i], true); - handler_ids [i] = OS.g_log_set_handler (log_domain, flags, logProc, 0); - } - } - } - - /* Create the standard colors */ - 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); - - emptyTab = OS.pango_tab_array_new(1, false); - if (emptyTab == 0) SWT.error(SWT.ERROR_NO_HANDLES); - OS.pango_tab_array_set_tab(emptyTab, 0, OS.PANGO_TAB_LEFT, 1); - - shellHandle = OS.gtk_window_new(OS.GTK_WINDOW_TOPLEVEL); - if (shellHandle == 0) SWT.error(SWT.ERROR_NO_HANDLES); - OS.gtk_widget_realize(shellHandle); - - /* Initialize the system font slot */ - systemFont = getSystemFont (); -} - -/** - * 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 /*long*/ 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 /*long*/ 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 disposed; - } -} - -/** - * Loads the font specified by a file. The font will be - * present in the list of fonts available to the application. - * - * @param path the font file path - * @return whether the font was successfully loaded - * - * @exception SWTException <ul> - * <li>ERROR_NULL_ARGUMENT - if path is null</li> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see Font - * - * @since 3.3 - */ -public boolean loadFont (String path) { - checkDevice(); - if (path == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); - byte [] buffer = Converter.wcsToMbcs (null, path, true); - return OS.FcConfigAppFontAddFile (0, buffer); -} - -int /*long*/ logProc (int /*long*/ log_domain, int /*long*/ log_level, int /*long*/ message, int /*long*/ user_data) { - if (warningLevel == 0) { - if (DEBUG || debug) { - new Error ().printStackTrace (); - } - OS.g_log_default_handler (log_domain, (int)/*64*/log_level, message, 0); - } - return 0; -} - -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 () { - if (shellHandle != 0) OS.gtk_widget_destroy(shellHandle); - shellHandle = 0; - - if (gdkColors != null) { - int /*long*/ colormap = OS.gdk_colormap_get_system(); - for (int i = 0; i < gdkColors.length; i++) { - GdkColor color = gdkColors [i]; - if (color != null) { - while (colorRefCount [i] > 0) { - OS.gdk_colormap_free_colors(colormap, color, 1); - --colorRefCount [i]; - } - } - } - } - gdkColors = 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; - - if (emptyTab != 0) OS.pango_tab_array_free(emptyTab); - emptyTab = 0; - - /* Free the GTK error and warning handler */ - if (xDisplay != 0) { - for (int i=0; i<handler_ids.length; i++) { - if (handler_ids [i] != 0) { - byte [] log_domain = Converter.wcsToMbcs (null, log_domains [i], true); - OS.g_log_remove_handler (log_domain, handler_ids [i]); - handler_ids [i] = 0; - } - } - logCallback.dispose (); logCallback = null; - handler_ids = null; log_domains = null; - logProc = 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 (); - if (warnings) { - if (--warningLevel == 0) { - if (debug) return; - if (logProc != 0) { - for (int i=0; i<handler_ids.length; i++) { - if (handler_ids [i] != 0) { - byte [] log_domain = Converter.wcsToMbcs (null, log_domains [i], true); - OS.g_log_remove_handler (log_domain, handler_ids [i]); - handler_ids [i] = 0; - } - } - } - } - } else { - if (warningLevel++ == 0) { - if (debug) return; - if (logProc != 0) { - int flags = OS.G_LOG_LEVEL_MASK | OS.G_LOG_FLAG_FATAL | OS.G_LOG_FLAG_RECURSION; - for (int i=0; i<log_domains.length; i++) { - byte [] log_domain = Converter.wcsToMbcs (null, log_domains [i], true); - handler_ids [i] = OS.g_log_set_handler (log_domain, flags, logProc, 0); - } - } - } - } -} - -static int /*long*/ XErrorProc (int /*long*/ xDisplay, int /*long*/ xErrorEvent) { - Device device = findDevice (xDisplay); - if (device != null) { - if (device.warningLevel == 0) { - 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 /*long*/ XIOErrorProc (int /*long*/ 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; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/DeviceData.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/DeviceData.java deleted file mode 100644 index 6fc287fd81..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/DeviceData.java +++ /dev/null @@ -1,36 +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 { - /* - * The following fields are platform dependent. - * <p> - * <b>IMPORTANT:</b> These fields are <em>not</em> part of the SWT - * public API. They are marked public only so that they can be shared - * within the packages provided by SWT. They are not available on all - * platforms and should never be accessed from application code. - * </p> - */ - 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/gtk/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java deleted file mode 100644 index 3607e38cfa..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Font.java +++ /dev/null @@ -1,288 +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.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.gtk.*; - -/** - * 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 /*long*/ handle; - -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(fd.getName(), fd.getHeightF(), fd.getStyle(), fd.string); - init(); -} - -/** - * Constructs a new font given a device and an array - * of font data which describes the desired font's - * appearance. - * <p> - * You must dispose the font when it is no longer required. - * </p> - * - * @param device the device to create the font on - * @param fds the array of FontData that describes the desired font (must not be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_NULL_ARGUMENT - if the fds argument is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the length of fds is zero</li> - * <li>ERROR_NULL_ARGUMENT - if any fd in the array is null</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li> - * </ul> - * - * @since 2.1 - */ -public Font(Device device, FontData[] fds) { - super(device); - if (fds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (fds.length == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - for (int i=0; i<fds.length; i++) { - if (fds[i] == null) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - FontData fd = fds[0]; - init(fd.getName(), fd.getHeightF(), fd.getStyle(), fd.string); - 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); - init(name, height, style, null); - init(); -} - -/*public*/ Font(Device device, String name, float height, int style) { - super(device); - init(name, height, style, null); - init(); -} - -void destroy() { - OS.pango_font_description_free(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; - return handle == ((Font)object).handle; -} - -/** - * 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 /*long*/ family = OS.pango_font_description_get_family(handle); - int length = OS.strlen(family); - byte[] buffer = new byte[length]; - OS.memmove(buffer, family, length); - String name = new String(Converter.mbcsToWcs(null, buffer)); - float height = (float)OS.pango_font_description_get_size(handle) / OS.PANGO_SCALE; - int pangoStyle = OS.pango_font_description_get_style(handle); - int pangoWeight = OS.pango_font_description_get_weight(handle); - int style = SWT.NORMAL; - if (pangoStyle == OS.PANGO_STYLE_ITALIC) style |= SWT.ITALIC; - if (pangoStyle == OS.PANGO_STYLE_OBLIQUE) style |= SWT.ROMAN; - if (pangoWeight >= OS.PANGO_WEIGHT_BOLD) style |= SWT.BOLD; - int /*long*/ fontString = OS.pango_font_description_to_string (handle); - length = OS.strlen (fontString); - buffer = new byte [length + 1]; - OS.memmove (buffer, fontString, length); - OS.g_free (fontString); - FontData data = new FontData(name, height, style); - data.string = buffer; - return new FontData[]{data}; -} - -/** - * Invokes platform specific functionality to allocate a new font. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>Font</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @param device the device on which to allocate the color - * @param handle the handle for the font - * - * @private - */ -public static Font gtk_new(Device device, int /*long*/ handle) { - Font font = new Font(device); - font.handle = handle; - return font; -} - -/** - * 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 (int)/*64*/handle; -} - -void init(String name, float height, int style, byte[] fontString) { - if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (fontString != null) { - handle = OS.pango_font_description_from_string (fontString); - if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); - } else { - handle = OS.pango_font_description_new(); - if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); - byte[] buffer = Converter.wcsToMbcs(null, name, true); - OS.pango_font_description_set_family(handle, buffer); - if (height > 0) { - OS.pango_font_description_set_size(handle, (int)(0.5f + height * OS.PANGO_SCALE)); - } - OS.pango_font_description_set_stretch(handle, OS.PANGO_STRETCH_NORMAL); - int pangoStyle = OS.PANGO_STYLE_NORMAL; - int pangoWeight = OS.PANGO_WEIGHT_NORMAL; - if ((style & SWT.ITALIC) != 0) pangoStyle = OS.PANGO_STYLE_ITALIC; - if ((style & SWT.ROMAN) != 0) pangoStyle = OS.PANGO_STYLE_OBLIQUE; - if ((style & SWT.BOLD) != 0) pangoWeight = OS.PANGO_WEIGHT_BOLD; - OS.pango_font_description_set_style(handle, pangoStyle); - OS.pango_font_description_set_weight(handle, pangoWeight); - } -} - -/** - * 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; -} - -/** - * 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/gtk/org/eclipse/swt/graphics/FontData.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontData.java deleted file mode 100644 index 6d15004b12..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontData.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.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 font 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 name; - - /** - * The height of the font data in points - * (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 float height; - - /** - * the font style - * (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 style; - - /** - * the Pango string - * (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 byte[] string; - - /** - * The locales of the font - */ - String lang, country, variant; - -/** - * Constructs a new uninitialized font data. - */ -public FontData () { - this("", 12, SWT.NORMAL); -} - -/** - * 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_INVALID_ARGUMENT); - String version1 = string.substring(start, end); - try { - if (Integer.parseInt(version1) != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } catch (NumberFormatException e) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - - start = end + 1; - end = string.indexOf('|', start); - if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - String name = string.substring(start, end); - - start = end + 1; - end = string.indexOf('|', start); - if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - float height = 0; - try { - height = Float.parseFloat(string.substring(start, end)); - } catch (NumberFormatException e) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - - start = end + 1; - end = string.indexOf('|', start); - if (end == -1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - int style = 0; - try { - style = Integer.parseInt(string.substring(start, end)); - } catch (NumberFormatException e) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - - start = end + 1; - end = string.indexOf('|', start); - setName(name); - setHeight(height); - setStyle(style); - if (end == -1) return; - String platform = string.substring(start, end); - - start = end + 1; - end = string.indexOf('|', start); - if (end == -1) return; - String version2 = string.substring(start, end); - - if (platform.equals("GTK") && version2.equals("1")) { - return; - } -} - -/** - * 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) { - setName(name); - setHeight(height); - setStyle(style); -} - -/*public*/ FontData(String name, float height, int style) { - setName(name); - setHeight(height); - setStyle(style); -} - -/** - * Compares the argument to the receiver, and returns true - * if they represent the <em>same</em> object using a class - * specific comparison. - * - * @param object the object to compare with this object - * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise - * - * @see #hashCode - */ -public boolean equals (Object object) { - if (object == this) return true; - if (!(object instanceof FontData)) return false; - FontData data = (FontData)object; - return name.equals(data.name) && height == data.height && style == data.style; -} - -/** - * Returns the height of the receiver in points. - * - * @return the height of this FontData - * - * @see #setHeight(int) - */ -public int getHeight() { - return (int)(0.5f + height); -} - -/*public*/ float getHeightF() { - return height; -} - -/** - * Returns the locale of the receiver. - * <p> - * The locale determines which platform character set this - * font is going to use. Widgets and graphics operations that - * use this font will convert UNICODE strings to the platform - * character set of the specified locale. - * </p> - * <p> - * On platforms where there are multiple character sets for a - * given language/country locale, the variant portion of the - * locale will determine the character set. - * </p> - * - * @return the <code>String</code> representing a Locale object - * @since 3.0 - */ -public String getLocale () { - StringBuffer buffer = new StringBuffer (); - char sep = '_'; - if (lang != null) { - buffer.append (lang); - buffer.append (sep); - } - if (country != null) { - buffer.append (country); - buffer.append (sep); - } - if (variant != null) { - buffer.append (variant); - } - - String result = buffer.toString (); - int length = result.length (); - if (length > 0) { - if (result.charAt (length - 1) == sep) { - result = result.substring (0, length - 1); - } - } - return result; -} - -/** - * Returns the name of the receiver. - * On platforms that support font foundries, the return value will - * be the foundry followed by a dash ("-") followed by the face name. - * - * @return the name of this <code>FontData</code> - * - * @see #setName - */ -public String getName() { - return name; -} - -/** - * Returns the style of the receiver which is a bitwise OR of - * one or more of the <code>SWT</code> constants NORMAL, BOLD - * and ITALIC. - * - * @return the style of this <code>FontData</code> - * - * @see #setStyle - */ -public int getStyle() { - return style; -} - -/** - * Returns an integer hash code for the receiver. Any two - * objects that return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals - */ -public int hashCode () { - return name.hashCode() ^ getHeight() ^ style; -} - -/** - * Sets the height of the receiver. The parameter is - * specified in terms of points, where a point is one - * seventy-second of an inch. - * - * @param height the height of the <code>FontData</code> - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li> - * </ul> - * - * @see #getHeight - */ -public void setHeight(int height) { - if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - this.height = height; - this.string = null; -} - -/*public*/ void setHeight(float height) { - if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - this.height = height; - this.string = null; -} - -/** - * Sets the locale of the receiver. - * <p> - * The locale determines which platform character set this - * font is going to use. Widgets and graphics operations that - * use this font will convert UNICODE strings to the platform - * character set of the specified locale. - * </p> - * <p> - * On platforms where there are multiple character sets for a - * given language/country locale, the variant portion of the - * locale will determine the character set. - * </p> - * - * @param locale the <code>String</code> representing a Locale object - * @see java.util.Locale#toString - */ -public void setLocale(String locale) { - lang = country = variant = null; - if (locale != null) { - char sep = '_'; - int length = locale.length(); - int firstSep, secondSep; - - firstSep = locale.indexOf(sep); - if (firstSep == -1) { - firstSep = secondSep = length; - } else { - secondSep = locale.indexOf(sep, firstSep + 1); - if (secondSep == -1) secondSep = length; - } - if (firstSep > 0) lang = locale.substring(0, firstSep); - if (secondSep > firstSep + 1) country = locale.substring(firstSep + 1, secondSep); - if (length > secondSep + 1) variant = locale.substring(secondSep + 1); - } -} - -/** - * Sets the name of the receiver. - * <p> - * Some platforms support font foundries. On these platforms, the name - * of the font specified in setName() may have one of the following forms: - * <ol> - * <li>a face name (for example, "courier")</li> - * <li>a foundry followed by a dash ("-") followed by a face name (for example, "adobe-courier")</li> - * </ol> - * In either case, the name returned from getName() will include the - * foundry. - * </p> - * <p> - * On platforms that do not support font foundries, only the face name - * (for example, "courier") is used in <code>setName()</code> and - * <code>getName()</code>. - * </p> - * - * @param name the name of the font data (must not be null) - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - when the font name is null</li> - * </ul> - * - * @see #getName - */ -public void setName(String name) { - if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - this.name = name; - this.string = null; -} - -/** - * Sets the style of the receiver to the argument which must - * be a bitwise OR of one or more of the <code>SWT</code> - * constants NORMAL, BOLD and ITALIC. All other style bits are - * ignored. - * - * @param style the new style for this <code>FontData</code> - * - * @see #getStyle - */ -public void setStyle(int style) { - this.style = style; - this.string = 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() { - StringBuffer buffer = new StringBuffer(128); - buffer.append("1|"); - buffer.append(getName()); - buffer.append("|"); - buffer.append(getHeightF()); - buffer.append("|"); - buffer.append(getStyle()); - buffer.append("|"); - buffer.append("GTK|1|"); - return buffer.toString(); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java deleted file mode 100644 index cd33b62ccf..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/FontMetrics.java +++ /dev/null @@ -1,133 +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; -} - -public static FontMetrics gtk_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; -} - -/** - * 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; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java deleted file mode 100644 index 78c020d109..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GC.java +++ /dev/null @@ -1,4036 +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.cairo.*; -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.internal.*; -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 /*long*/ 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 DRAW_OFFSET = 1 << 9; - 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 /*long*/ gdkGC = drawable.internal_new_GC(data); - Device device = data.device; - if (device == null) device = Device.getDevice(); - if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - this.device = data.device = device; - init(drawable, data, gdkGC); - init(); -} - -static void addCairoString(int /*long*/ cairo, String string, float x, float y, Font font) { - byte[] buffer = Converter.wcsToMbcs(null, string, true); - if (OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) { - int /*long*/ layout = OS.pango_cairo_create_layout(cairo); - if (layout == 0) SWT.error(SWT.ERROR_NO_HANDLES); - OS.pango_layout_set_text(layout, buffer, -1); - OS.pango_layout_set_font_description(layout, font.handle); - double[] currentX = new double[1], currentY = new double[1]; - Cairo.cairo_get_current_point(cairo, currentX, currentY); - if (currentX[0] != x || currentY[0] != y) { - Cairo.cairo_move_to(cairo, x, y); - } - OS.pango_cairo_layout_path(cairo, layout); - OS.g_object_unref(layout); - } else { - 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); -} - -public static GC gtk_new(int /*long*/ handle, GCData data) { - GC gc = new GC(); - gc.device = data.device; - gc.init(null, data, handle); - return gc; -} - -public static GC gtk_new(Drawable drawable, GCData data) { - GC gc = new GC(); - int /*long*/ gdkGC = drawable.internal_new_GC(data); - gc.device = data.device; - gc.init(drawable, data, gdkGC); - return gc; -} - -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) { - GdkColor color; - Pattern pattern; - if ((state & FOREGROUND) != 0) { - color = data.foreground; - pattern = data.foregroundPattern; - data.state &= ~BACKGROUND; - } else { - color = data.background; - pattern = data.backgroundPattern; - data.state &= ~FOREGROUND; - } - if (pattern != null) { - if ((data.style & SWT.MIRRORED) != 0 && pattern.surface != 0) { - int /*long*/ newPattern = Cairo.cairo_pattern_create_for_surface(pattern.surface); - if (newPattern == 0) SWT.error(SWT.ERROR_NO_HANDLES); - Cairo.cairo_pattern_set_extend(newPattern, Cairo.CAIRO_EXTEND_REPEAT); - double[] matrix = {-1, 0, 0, 1, 0, 0}; - Cairo.cairo_pattern_set_matrix(newPattern, matrix); - Cairo.cairo_set_source(cairo, newPattern); - Cairo.cairo_pattern_destroy(newPattern); - } else { - 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) { - if (data.layout != 0) { - Font font = data.font; - OS.pango_layout_set_font_description(data.layout, font.handle); - } - if (OS.GTK_VERSION < OS.VERSION(2, 8, 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; - } - if ((state & (BACKGROUND | FOREGROUND)) != 0) { - GdkColor foreground; - if ((state & FOREGROUND) != 0) { - foreground = data.foreground; - data.state &= ~BACKGROUND; - } else { - foreground = data.background; - data.state &= ~FOREGROUND; - } - OS.gdk_gc_set_foreground(handle, foreground); - } - if ((state & BACKGROUND_BG) != 0) { - GdkColor background = data.background; - OS.gdk_gc_set_background(handle, background); - } - if ((state & FONT) != 0) { - if (data.layout != 0) { - Font font = data.font; - OS.pango_layout_set_font_description(data.layout, font.handle); - } - } - 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.GDK_CAP_ROUND; break; - case SWT.CAP_FLAT: cap_style = OS.GDK_CAP_BUTT; break; - case SWT.CAP_SQUARE: cap_style = OS.GDK_CAP_PROJECTING; break; - } - switch (data.lineJoin) { - case SWT.JOIN_ROUND: join_style = OS.GDK_JOIN_ROUND; break; - case SWT.JOIN_MITER: join_style = OS.GDK_JOIN_MITER; break; - case SWT.JOIN_BEVEL: join_style = OS.GDK_JOIN_BEVEL; 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.gdk_gc_set_dashes(handle, 0, dash_list, dash_list.length); - } - line_style = OS.GDK_LINE_ON_OFF_DASH; - } else { - line_style = OS.GDK_LINE_SOLID; - } - OS.gdk_gc_set_line_attributes(handle, width, line_style, cap_style, join_style); - } -} - -int /*long*/ convertRgn(int /*long*/ rgn, double[] matrix) { - int /*long*/ newRgn = OS.gdk_region_new(); - int[] nRects = new int[1]; - int /*long*/[] rects = new int /*long*/[1]; - OS.gdk_region_get_rectangles(rgn, rects, nRects); - GdkRectangle rect = new GdkRectangle(); - int[] pointArray = new int[8]; - double[] x = new double[1], y = new double[1]; - for (int i=0; i<nRects[0]; i++) { - OS.memmove(rect, rects[0] + (i * GdkRectangle.sizeof), GdkRectangle.sizeof); - x[0] = rect.x; - y[0] = rect.y; - Cairo.cairo_matrix_transform_point(matrix, x, y); - pointArray[0] = (int)x[0]; - pointArray[1] = (int)y[0]; - x[0] = rect.x + rect.width; - y[0] = rect.y; - Cairo.cairo_matrix_transform_point(matrix, x, y); - pointArray[2] = (int)Math.round(x[0]); - pointArray[3] = (int)y[0]; - x[0] = rect.x + rect.width; - y[0] = rect.y + rect.height; - Cairo.cairo_matrix_transform_point(matrix, x, y); - pointArray[4] = (int)Math.round(x[0]); - pointArray[5] = (int)Math.round(y[0]); - x[0] = rect.x; - y[0] = rect.y + rect.height; - Cairo.cairo_matrix_transform_point(matrix, x, y); - pointArray[6] = (int)x[0]; - pointArray[7] = (int)Math.round(y[0]); - int /*long*/ polyRgn = OS.gdk_region_polygon(pointArray, pointArray.length / 2, OS.GDK_EVEN_ODD_RULE); - OS.gdk_region_union(newRgn, polyRgn); - OS.gdk_region_destroy(polyRgn); - } - if (rects[0] != 0) OS.g_free(rects[0]); - return newRgn; -} - -/** - * 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 /*long*/ gdkGC = OS.gdk_gc_new(image.pixmap); - if (gdkGC == 0) SWT.error(SWT.ERROR_NO_HANDLES); - OS.gdk_gc_set_subwindow(gdkGC, OS.GDK_INCLUDE_INFERIORS); - OS.gdk_draw_drawable(image.pixmap, gdkGC, data.drawable, x, y, 0, 0, rect.width, rect.height); - OS.g_object_unref(gdkGC); -} - -/** - * Copies a rectangular area of the receiver at the source - * position onto the receiver at the destination position. - * - * @param srcX the x coordinate in the receiver of the area to be copied - * @param srcY the y coordinate in the receiver of the area to be copied - * @param width the width of the area to copy - * @param height the height of the area to copy - * @param destX the x coordinate in the receiver of the area to copy to - * @param destY the y coordinate in the receiver of the area to copy to - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY) { - copyArea(srcX, srcY, width, height, destX, destY, true); -} -/** - * Copies a rectangular area of the receiver at the source - * position onto the receiver at the destination position. - * - * @param srcX the x coordinate in the receiver of the area to be copied - * @param srcY the y coordinate in the receiver of the area to be copied - * @param width the width of the area to copy - * @param height the height of the area to copy - * @param destX the x coordinate in the receiver of the area to copy to - * @param destY the y coordinate in the receiver of the area to copy to - * @param paint if <code>true</code> paint events will be generated for old and obscured areas - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public void copyArea(int srcX, int srcY, int width, int height, int destX, int destY, boolean paint) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (width <= 0 || height <= 0) return; - int deltaX = destX - srcX, deltaY = destY - srcY; - if (deltaX == 0 && deltaY == 0) return; - int /*long*/ drawable = data.drawable; - if (data.image == null && paint) OS.gdk_gc_set_exposures(handle, true); - OS.gdk_draw_drawable(drawable, handle, drawable, srcX, srcY, destX, destY, width, height); - if (data.image == null & paint) { - OS.gdk_gc_set_exposures(handle, false); - boolean disjoint = (destX + width < srcX) || (srcX + width < destX) || (destY + height < srcY) || (srcY + height < destY); - GdkRectangle rect = new GdkRectangle (); - if (disjoint) { - rect.x = srcX; - rect.y = srcY; - rect.width = width; - rect.height = height; - OS.gdk_window_invalidate_rect (drawable, rect, false); -// OS.gdk_window_clear_area_e(drawable, srcX, srcY, width, height); - } else { - if (deltaX != 0) { - int newX = destX - deltaX; - if (deltaX < 0) newX = destX + width; - rect.x = newX; - rect.y = srcY; - rect.width = Math.abs(deltaX); - rect.height = height; - OS.gdk_window_invalidate_rect (drawable, rect, false); -// OS.gdk_window_clear_area_e(drawable, newX, srcY, Math.abs(deltaX), height); - } - if (deltaY != 0) { - int newY = destY - deltaY; - if (deltaY < 0) newY = destY + height; - rect.x = srcX; - rect.y = newY; - rect.width = width; - rect.height = Math.abs(deltaY); - OS.gdk_window_invalidate_rect (drawable, rect, false); -// OS.gdk_window_clear_area_e(drawable, srcX, newY, width, Math.abs(deltaY)); - } - } - } -} - -void createLayout() { - int /*long*/ context = OS.gdk_pango_context_get(); - if (context == 0) SWT.error(SWT.ERROR_NO_HANDLES); - data.context = context; - int /*long*/ layout = OS.pango_layout_new(context); - if (layout == 0) SWT.error(SWT.ERROR_NO_HANDLES); - data.layout = layout; - OS.pango_context_set_language(context, OS.gtk_get_default_language()); - OS.pango_context_set_base_dir(context, (data.style & SWT.MIRRORED) != 0 ? OS.PANGO_DIRECTION_RTL : OS.PANGO_DIRECTION_LTR); - OS.gdk_pango_context_set_colormap(context, OS.gdk_colormap_get_system()); - if (OS.GTK_VERSION >= OS.VERSION(2, 4, 0)) { - OS.pango_layout_set_auto_dir(layout, false); - } -} - -void disposeLayout() { - data.string = null; - if (data.context != 0) OS.g_object_unref(data.context); - if (data.layout != 0) OS.g_object_unref(data.layout); - data.layout = data.context = 0; -} - -void destroy() { - if (data.disposeCairo) { - int /*long*/ cairo = data.cairo; - if (cairo != 0) Cairo.cairo_destroy(cairo); - data.cairo = 0; - } - - /* Free resources */ - int /*long*/ clipRgn = data.clipRgn; - if (clipRgn != 0) OS.gdk_region_destroy(clipRgn); - Image image = data.image; - if (image != null) { - image.memGC = null; - if (image.transparentPixel != -1) image.createMask(); - } - - disposeLayout(); - - /* Dispose the GC */ - if (drawable != null) { - drawable.internal_dispose_GC(handle, data); - } - data.drawable = data.clipRgn = 0; - drawable = null; - handle = 0; - data.image = null; - data.string = 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.gdk_draw_arc(data.drawable, handle, 0, 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); - /* - * Feature in GTK. The function gtk_widget_get_default_style() - * can't be used here because gtk_paint_focus() uses GCs, which - * are not valid in the default style. The fix is to use a style - * from a widget. - */ - int /*long*/ style = OS.gtk_widget_get_style(data.device.shellHandle); - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - checkGC(FOREGROUND); - int[] lineWidth = new int[1]; - OS.gtk_widget_style_get(data.device.shellHandle, OS.focus_line_width, lineWidth, 0); - Cairo.cairo_save(cairo); - Cairo.cairo_set_line_width(cairo, lineWidth[0]); - double[] dashes = new double[]{1, 1}; - double dash_offset = -lineWidth[0] / 2f; - while (dash_offset < 0) dash_offset += 2; - Cairo.cairo_set_dash(cairo, dashes, dashes.length, dash_offset); - Cairo.cairo_rectangle(cairo, x + lineWidth[0] / 2f, y + lineWidth[0] / 2f, width, height); - Cairo.cairo_stroke(cairo); - Cairo.cairo_restore(cairo); - return; - } - OS.gtk_paint_focus(style, data.drawable, OS.GTK_STATE_NORMAL, null, data.device.shellHandle, new byte[1], x, y, width, height); -} - -/** - * 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]; - OS.gdk_drawable_get_size(srcImage.pixmap, width, height); - 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); - if ((data.style & SWT.MIRRORED) != 0) { - Cairo.cairo_scale(cairo, -1f, 1); - Cairo.cairo_translate(cairo, - 2 * destX - destWidth, 0); - } - 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, 0)) { - 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); - } else if (srcImage.transparentPixel != -1 || srcImage.mask != 0) { - drawImageMask(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight); - } else { - drawImage(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight); - } -} -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) { - if (srcWidth == destWidth && srcHeight == destHeight) { - OS.gdk_draw_drawable(data.drawable, handle, srcImage.pixmap, srcX, srcY, destX, destY, destWidth, destHeight); - } else { - if (device.useXRender) { - drawImageXRender(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, 0, -1); - return; - } - int /*long*/ pixbuf = scale(srcImage.pixmap, srcX, srcY, srcWidth, srcHeight, destWidth, destHeight); - if (pixbuf != 0) { - OS.gdk_pixbuf_render_to_drawable(pixbuf, data.drawable, handle, 0, 0, destX, destY, destWidth, destHeight, OS.GDK_RGB_DITHER_NORMAL, 0, 0); - OS.g_object_unref(pixbuf); - } - } -} -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) { - if (srcImage.alpha == 0) return; - if (srcImage.alpha == 255) { - drawImage(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight); - return; - } - if (device.useXRender) { - drawImageXRender(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, srcImage.mask, OS.PictStandardA8); - return; - } - int /*long*/ pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, true, 8, srcWidth, srcHeight); - if (pixbuf == 0) return; - int /*long*/ colormap = OS.gdk_colormap_get_system(); - OS.gdk_pixbuf_get_from_drawable(pixbuf, srcImage.pixmap, colormap, srcX, srcY, 0, 0, srcWidth, srcHeight); - int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf); - byte[] line = new byte[stride]; - byte alpha = (byte)srcImage.alpha; - byte[] alphaData = srcImage.alphaData; - for (int y=0; y<srcHeight; y++) { - int alphaIndex = (y + srcY) * imgWidth + srcX; - OS.memmove(line, pixels + (y * stride), stride); - for (int x=3; x<stride; x+=4) { - line[x] = alphaData == null ? alpha : alphaData[alphaIndex++]; - } - OS.memmove(pixels + (y * stride), line, stride); - } - if (srcWidth != destWidth || srcHeight != destHeight) { - int /*long*/ scaledPixbuf = OS.gdk_pixbuf_scale_simple(pixbuf, destWidth, destHeight, OS.GDK_INTERP_BILINEAR); - OS.g_object_unref(pixbuf); - if (scaledPixbuf == 0) return; - pixbuf = scaledPixbuf; - } - /* - * Feature in GTK. gdk_draw_pixbuf was introduced in GTK+ 2.2.0 and - * supports clipping. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 2, 0)) { - OS.gdk_draw_pixbuf(data.drawable, handle, pixbuf, 0, 0, destX, destY, destWidth, destHeight, OS.GDK_RGB_DITHER_NORMAL, 0, 0); - } else { - OS.gdk_pixbuf_render_to_drawable_alpha(pixbuf, data.drawable, 0, 0, destX, destY, destWidth, destHeight, OS.GDK_PIXBUF_ALPHA_BILEVEL, 128, OS.GDK_RGB_DITHER_NORMAL, 0, 0); - } - OS.g_object_unref(pixbuf); -} -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 /*long*/ drawable = data.drawable; - int /*long*/ colorPixmap = srcImage.pixmap; - /* Generate the mask if necessary. */ - if (srcImage.transparentPixel != -1) srcImage.createMask(); - int /*long*/ maskPixmap = srcImage.mask; - - if (device.useXRender) { - drawImageXRender(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, maskPixmap, OS.PictStandardA1); - } else { - if (srcWidth != destWidth || srcHeight != destHeight) { - int /*long*/ pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, true, 8, srcWidth, srcHeight); - if (pixbuf != 0) { - int /*long*/ colormap = OS.gdk_colormap_get_system(); - OS.gdk_pixbuf_get_from_drawable(pixbuf, colorPixmap, colormap, srcX, srcY, 0, 0, srcWidth, srcHeight); - int /*long*/ maskPixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, srcWidth, srcHeight); - if (maskPixbuf != 0) { - OS.gdk_pixbuf_get_from_drawable(maskPixbuf, maskPixmap, 0, srcX, srcY, 0, 0, srcWidth, srcHeight); - int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf); - byte[] line = new byte[stride]; - int maskStride = OS.gdk_pixbuf_get_rowstride(maskPixbuf); - int /*long*/ maskPixels = OS.gdk_pixbuf_get_pixels(maskPixbuf); - byte[] maskLine = new byte[maskStride]; - for (int y=0; y<srcHeight; y++) { - int /*long*/ offset = pixels + (y * stride); - OS.memmove(line, offset, stride); - int /*long*/ maskOffset = maskPixels + (y * maskStride); - OS.memmove(maskLine, maskOffset, maskStride); - for (int x=0; x<srcWidth; x++) { - if (maskLine[x * 3] == 0) { - line[x*4+3] = 0; - } - } - OS.memmove(offset, line, stride); - } - OS.g_object_unref(maskPixbuf); - int /*long*/ scaledPixbuf = OS.gdk_pixbuf_scale_simple(pixbuf, destWidth, destHeight, OS.GDK_INTERP_BILINEAR); - if (scaledPixbuf != 0) { - int /*long*/[] colorBuffer = new int /*long*/[1]; - int /*long*/[] maskBuffer = new int /*long*/[1]; - OS.gdk_pixbuf_render_pixmap_and_mask(scaledPixbuf, colorBuffer, maskBuffer, 128); - colorPixmap = colorBuffer[0]; - maskPixmap = maskBuffer[0]; - OS.g_object_unref(scaledPixbuf); - } - } - OS.g_object_unref(pixbuf); - } - srcX = 0; - srcY = 0; - srcWidth = destWidth; - srcHeight = destHeight; - } - - /* Merge clipping with mask if necessary */ - if (data.clipRgn != 0) { - int newWidth = srcX + srcWidth; - int newHeight = srcY + srcHeight; - int bytesPerLine = (newWidth + 7) / 8; - byte[] maskData = new byte[bytesPerLine * newHeight]; - int /*long*/ mask = OS.gdk_bitmap_create_from_data(0, maskData, newWidth, newHeight); - if (mask != 0) { - int /*long*/ gc = OS.gdk_gc_new(mask); - OS.gdk_region_offset(data.clipRgn, -destX + srcX, -destY + srcY); - OS.gdk_gc_set_clip_region(gc, data.clipRgn); - OS.gdk_region_offset(data.clipRgn, destX - srcX, destY - srcY); - GdkColor color = new GdkColor(); - color.pixel = 1; - OS.gdk_gc_set_foreground(gc, color); - OS.gdk_draw_rectangle(mask, gc, 1, 0, 0, newWidth, newHeight); - OS.gdk_gc_set_function(gc, OS.GDK_AND); - OS.gdk_draw_drawable(mask, gc, maskPixmap, 0, 0, 0, 0, newWidth, newHeight); - OS.g_object_unref(gc); - if (maskPixmap != 0 && srcImage.mask != maskPixmap) OS.g_object_unref(maskPixmap); - maskPixmap = mask; - } - } - - /* Blit cliping the mask */ - GdkGCValues values = new GdkGCValues(); - OS.gdk_gc_get_values(handle, values); - OS.gdk_gc_set_clip_mask(handle, maskPixmap); - OS.gdk_gc_set_clip_origin(handle, destX - srcX, destY - srcY); - OS.gdk_draw_drawable(drawable, handle, colorPixmap, srcX, srcY, destX, destY, srcWidth, srcHeight); - OS.gdk_gc_set_values(handle, values, OS.GDK_GC_CLIP_MASK | OS.GDK_GC_CLIP_X_ORIGIN | OS.GDK_GC_CLIP_Y_ORIGIN); - if (data.clipRgn != 0) OS.gdk_gc_set_clip_region(handle, data.clipRgn); - } - - /* Destroy scaled pixmaps */ - if (colorPixmap != 0 && srcImage.pixmap != colorPixmap) OS.g_object_unref(colorPixmap); - if (maskPixmap != 0 && srcImage.mask != maskPixmap) OS.g_object_unref(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 /*long*/ maskPixmap, int maskType) { - int translateX = 0, translateY = 0; - int /*long*/ drawable = data.drawable; - if (data.image == null && !data.realDrawable) { - int[] x = new int[1], y = new int[1]; - int /*long*/ [] real_drawable = new int /*long*/ [1]; - OS.gdk_window_get_internal_paint_info(drawable, real_drawable, x, y); - drawable = real_drawable[0]; - translateX = -x[0]; - translateY = -y[0]; - } - int /*long*/ xDisplay = OS.GDK_DISPLAY(); - int /*long*/ 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, OS.gdk_x11_drawable_get_xid(maskPixmap), OS.XRenderFindStandardFormat(xDisplay, maskType), attribCount, attrib); - if (maskPict == 0) SWT.error(SWT.ERROR_NO_HANDLES); - } - int /*long*/ format = OS.XRenderFindVisualFormat(xDisplay, OS.gdk_x11_visual_get_xvisual(OS.gdk_visual_get_system())); - int /*long*/ destPict = OS.XRenderCreatePicture(xDisplay, OS.gdk_x11_drawable_get_xid(drawable), format, 0, null); - if (destPict == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int /*long*/ srcPict = OS.XRenderCreatePicture(xDisplay, OS.gdk_x11_drawable_get_xid(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 /*long*/ clipping = data.clipRgn; - if (data.damageRgn != 0) { - if (clipping == 0) { - clipping = data.damageRgn; - } else { - clipping = OS.gdk_region_new(); - OS.gdk_region_union(clipping, data.clipRgn); - OS.gdk_region_intersect(clipping, data.damageRgn); - } - } - if (clipping != 0) { - int[] nRects = new int[1]; - int /*long*/[] rects = new int /*long*/[1]; - OS.gdk_region_get_rectangles(clipping, rects, nRects); - GdkRectangle rect = new GdkRectangle(); - short[] xRects = new short[nRects[0] * 4]; - for (int i=0, j=0; i<nRects[0]; i++, j+=4) { - OS.memmove(rect, rects[0] + (i * GdkRectangle.sizeof), GdkRectangle.sizeof); - xRects[j] = (short)rect.x; - xRects[j+1] = (short)rect.y; - xRects[j+2] = (short)rect.width; - xRects[j+3] = (short)rect.height; - } - OS.XRenderSetPictureClipRectangles(xDisplay, destPict, translateX, translateY, xRects, nRects[0]); - if (clipping != data.clipRgn && clipping != data.damageRgn) { - OS.gdk_region_destroy(clipping); - } - if (rects[0] != 0) OS.g_free(rects[0]); - } - OS.XRenderComposite(xDisplay, maskPict != 0 ? OS.PictOpOver : OS.PictOpSrc, srcPict, maskPict, destPict, srcX, srcY, srcX, srcY, destX + translateX, destY + translateY, destWidth, destHeight); - OS.XRenderFreePicture(xDisplay, destPict); - OS.XRenderFreePicture(xDisplay, srcPict); - if (maskPict != 0) OS.XRenderFreePicture(xDisplay, maskPict); -} -int /*long*/ scale(int /*long*/ src, int srcX, int srcY, int srcWidth, int srcHeight, int destWidth, int destHeight) { - int /*long*/ pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, srcWidth, srcHeight); - if (pixbuf == 0) return 0; - int /*long*/ colormap = OS.gdk_colormap_get_system(); - OS.gdk_pixbuf_get_from_drawable(pixbuf, src, colormap, srcX, srcY, 0, 0, srcWidth, srcHeight); - int /*long*/ scaledPixbuf = OS.gdk_pixbuf_scale_simple(pixbuf, destWidth, destHeight, OS.GDK_INTERP_BILINEAR); - OS.g_object_unref(pixbuf); - return scaledPixbuf; -} - -/** - * 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.gdk_draw_line (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.gdk_draw_arc(data.drawable, handle, 0, 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.gdk_draw_point(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; - } - OS.gdk_draw_polygon(data.drawable, handle, 0, pointArray, pointArray.length / 2); -} - -/** - * 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; - } - OS.gdk_draw_lines(data.drawable, handle, pointArray, pointArray.length / 2); -} - -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.gdk_draw_rectangle(data.drawable, handle, 0, 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 /*long*/ drawable = data.drawable; - if (nw > naw) { - if (nh > nah) { - OS.gdk_draw_arc(drawable, handle, 0, nx, ny, naw, nah, 5760, 5760); - OS.gdk_draw_line(drawable, handle, nx + naw2, ny, nx + nw - naw2, ny); - OS.gdk_draw_arc(drawable, handle, 0, nx + nw - naw, ny, naw, nah, 0, 5760); - OS.gdk_draw_line(drawable, handle, nx + nw, ny + nah2, nx + nw, ny + nh - nah2); - OS.gdk_draw_arc(drawable, handle, 0, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760); - OS.gdk_draw_line(drawable,handle, nx + naw2, ny + nh, nx + nw - naw2, ny + nh); - OS.gdk_draw_arc(drawable, handle, 0, nx, ny + nh - nah, naw, nah, 11520, 5760); - OS.gdk_draw_line(drawable, handle, nx, ny + nah2, nx, ny + nh - nah2); - } else { - OS.gdk_draw_arc(drawable, handle, 0, nx, ny, naw, nh, 5760, 11520); - OS.gdk_draw_line(drawable, handle, nx + naw2, ny, nx + nw - naw2, ny); - OS.gdk_draw_arc(drawable, handle, 0, nx + nw - naw, ny, naw, nh, 17280, 11520); - OS.gdk_draw_line(drawable,handle, nx + naw2, ny + nh, nx + nw - naw2, ny + nh); - } - } else { - if (nh > nah) { - OS.gdk_draw_arc(drawable, handle, 0, nx, ny, nw, nah, 0, 11520); - OS.gdk_draw_line(drawable, handle, nx + nw, ny + nah2, nx + nw, ny + nh - nah2); - OS.gdk_draw_arc(drawable, handle, 0, nx, ny + nh - nah, nw, nah, 11520, 11520); - OS.gdk_draw_line(drawable,handle, nx, ny + nah2, nx, ny + nh - nah2); - } else { - OS.gdk_draw_arc(drawable, handle, 0, 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) { - drawText(string, x, y, isTransparent ? SWT.DRAW_TRANSPARENT : 0); -} - -/** - * Draws the given string, using the receiver's current font and - * foreground color. Tab expansion and carriage return processing - * are performed. The background of the rectangular area where - * the text is being drawn will be filled with the receiver's - * background color. - * - * @param string the string to be drawn - * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn - * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawText(String string, int x, int y) { - drawText(string, x, y, SWT.DRAW_DELIMITER | SWT.DRAW_TAB); -} - -/** - * Draws the given string, using the receiver's current font and - * foreground color. Tab expansion and carriage return processing - * are performed. If <code>isTransparent</code> is <code>true</code>, - * then the background of the rectangular area where the text is being - * drawn will not be modified, otherwise it will be filled with the - * receiver's background color. - * - * @param string the string to be drawn - * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn - * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn - * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawText(String string, int x, int y, boolean isTransparent) { - int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB; - if (isTransparent) flags |= SWT.DRAW_TRANSPARENT; - drawText(string, x, y, flags); -} - -/** - * Draws the given string, using the receiver's current font and - * foreground color. Tab expansion, line delimiter and mnemonic - * processing are performed according to the specified flags. If - * <code>flags</code> includes <code>DRAW_TRANSPARENT</code>, - * then the background of the rectangular area where the text is being - * drawn will not be modified, otherwise it will be filled with the - * receiver's background color. - * <p> - * The parameter <code>flags</code> may be a combination of: - * <dl> - * <dt><b>DRAW_DELIMITER</b></dt> - * <dd>draw multiple lines</dd> - * <dt><b>DRAW_TAB</b></dt> - * <dd>expand tabs</dd> - * <dt><b>DRAW_MNEMONIC</b></dt> - * <dd>underline the mnemonic character</dd> - * <dt><b>DRAW_TRANSPARENT</b></dt> - * <dd>transparent background</dd> - * </dl> - * </p> - * - * @param string the string to be drawn - * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn - * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn - * @param flags the flags specifying how to process the text - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawText (String string, int x, int y, int flags) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (string.length() == 0) return; - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - if (OS.GTK_VERSION < OS.VERSION(2, 8, 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; - } - } - setString(string, flags); - if (cairo != 0) { - checkGC(FONT); - if ((flags & SWT.DRAW_TRANSPARENT) == 0) { - checkGC(BACKGROUND); - if (data.stringWidth == -1) { - computeStringSize(); - } - Cairo.cairo_rectangle(cairo, x, y, data.stringWidth, data.stringHeight); - Cairo.cairo_fill(cairo); - } - checkGC(FOREGROUND); - if ((data.style & SWT.MIRRORED) != 0) { - Cairo.cairo_save(cairo); - if (data.stringWidth == -1) { - computeStringSize(); - } - Cairo.cairo_scale(cairo, -1f, 1); - Cairo.cairo_translate(cairo, -2 * x - data.stringWidth, 0); - } - Cairo.cairo_move_to(cairo, x, y); - OS.pango_cairo_show_layout(cairo, data.layout); - if ((data.style & SWT.MIRRORED) != 0) { - Cairo.cairo_restore(cairo); - } - Cairo.cairo_new_path(cairo); - return; - } - checkGC(FOREGROUND | FONT | BACKGROUND_BG); - GdkColor background = null; - if ((flags & SWT.DRAW_TRANSPARENT) == 0) background = data.background; - if (!data.xorMode) { - OS.gdk_draw_layout_with_colors(data.drawable, handle, x, y, data.layout, null, background); - } else { - int /*long*/ layout = data.layout; - if (data.stringWidth == -1) { - computeStringSize(); - } - int /*long*/ pixmap = OS.gdk_pixmap_new(OS.GDK_ROOT_PARENT(), data.stringWidth, data.stringHeight, -1); - if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int /*long*/ gdkGC = OS.gdk_gc_new(pixmap); - if (gdkGC == 0) SWT.error(SWT.ERROR_NO_HANDLES); - GdkColor black = new GdkColor(); - OS.gdk_gc_set_foreground(gdkGC, black); - OS.gdk_draw_rectangle(pixmap, gdkGC, 1, 0, 0, data.stringWidth, data.stringHeight); - OS.gdk_gc_set_foreground(gdkGC, data.foreground); - OS.gdk_draw_layout_with_colors(pixmap, gdkGC, 0, 0, layout, null, background); - OS.g_object_unref(gdkGC); - OS.gdk_draw_drawable(data.drawable, handle, pixmap, 0, 0, x, y, data.stringWidth, data.stringHeight); - OS.g_object_unref(pixmap); - } -} - -/** - * 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.gdk_draw_arc(data.drawable, handle, 1, 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; - - /* Rewrite this to use GdkPixbuf */ - - RGB backgroundRGB, foregroundRGB; - backgroundRGB = getBackground().getRGB(); - foregroundRGB = getForeground().getRGB(); - - RGB fromRGB, toRGB; - fromRGB = foregroundRGB; - toRGB = backgroundRGB; - boolean swapColors = false; - if (width < 0) { - x += width; width = -width; - if (! vertical) swapColors = true; - } - if (height < 0) { - y += height; height = -height; - if (vertical) swapColors = true; - } - if (swapColors) { - fromRGB = backgroundRGB; - toRGB = foregroundRGB; - } - if (fromRGB.equals(toRGB)) { - fillRectangle(x, y, width, height); - return; - } - 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; - } - ImageData.fillGradientRectangle(this, data.device, - x, y, width, height, vertical, fromRGB, toRGB, - 8, 8, 8); -} - -/** - * Fills the interior of an oval, within the specified - * rectangular area, with the receiver's background - * color. - * - * @param x the x coordinate of the upper left corner of the oval to be filled - * @param y the y coordinate of the upper left corner of the oval to be filled - * @param width the width of the oval to be filled - * @param height the height of the oval to be filled - * - * @exception SWTException <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.gdk_draw_arc(data.drawable, handle, 1, 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; - } - OS.gdk_draw_polygon(data.drawable, handle, 1, pointArray, pointArray.length / 2); -} - -/** - * 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.gdk_draw_rectangle(data.drawable, handle, 1, 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - fillRectangle(rect.x, rect.y, rect.width, rect.height); -} - -/** - * Fills the interior of the round-cornered rectangle specified by - * the arguments, using the receiver's background color. - * - * @param x the x coordinate of the rectangle to be filled - * @param y the y coordinate of the rectangle to be filled - * @param width the width of the rectangle to be filled - * @param height the height of the rectangle to be filled - * @param arcWidth the width of the arc - * @param arcHeight the height of the arc - * - * @exception SWTException <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 /*long*/ drawable = data.drawable; - if (nw > naw) { - if (nh > nah) { - OS.gdk_draw_arc(drawable, handle, 1, nx, ny, naw, nah, 5760, 5760); - OS.gdk_draw_rectangle(drawable, handle, 1, nx + naw2, ny, nw - naw2 * 2, nh); - OS.gdk_draw_arc(drawable, handle, 1, nx + nw - naw, ny, naw, nah, 0, 5760); - OS.gdk_draw_rectangle(drawable, handle, 1, nx, ny + nah2, naw2, nh - nah2 * 2); - OS.gdk_draw_arc(drawable, handle, 1, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760); - OS.gdk_draw_rectangle(drawable, handle, 1, nx + nw - naw2, ny + nah2, naw2, nh - nah2 * 2); - OS.gdk_draw_arc(drawable, handle, 1, nx, ny + nh - nah, naw, nah, 11520, 5760); - } else { - OS.gdk_draw_arc(drawable, handle, 1, nx, ny, naw, nh, 5760, 11520); - OS.gdk_draw_rectangle(drawable, handle, 1, nx + naw2, ny, nw - naw2 * 2, nh); - OS.gdk_draw_arc(drawable, handle, 1, nx + nw - naw, ny, naw, nh, 17280, 11520); - } - } else { - if (nh > nah) { - OS.gdk_draw_arc(drawable, handle, 1, nx, ny, nw, nah, 0, 11520); - OS.gdk_draw_rectangle(drawable, handle, 1, nx, ny + nah2, nw, nh - nah2 * 2); - OS.gdk_draw_arc(drawable, handle, 1, nx, ny + nh - nah, nw, nah, 11520, 11520); - } else { - OS.gdk_draw_arc(drawable, handle, 1, nx, ny, nw, nh, 0, 23040); - } - } -} - -int fixMnemonic (char [] buffer) { - int i=0, j=0; - int mnemonic=-1; - while (i < buffer.length) { - if ((buffer [j++] = buffer [i++]) == '&') { - if (i == buffer.length) {continue;} - if (buffer [i] == '&') {i++; continue;} - if (mnemonic == -1) mnemonic = j; - j--; - } - } - while (j < buffer.length) buffer [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); - //BOGUS - 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); - return Color.gtk_new(data.device, data.background); -} - -/** - * Returns the background pattern. The default value is - * <code>null</code>. - * - * @return the receiver's background pattern - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see Pattern - * - * @since 3.1 - */ -public Pattern getBackgroundPattern() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return data.backgroundPattern; -} - -/** - * Returns the width of the specified character in the font - * selected into the receiver. - * <p> - * The width is defined as the space taken up by the actual - * character, not including the leading and tailing whitespace - * or overhang. - * </p> - * - * @param ch the character to measure - * @return the width of the character - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public int getCharWidth(char ch) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - //BOGUS - 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; - if (data.width != -1 && data.height != -1) { - width = data.width; - height = data.height; - } else { - int[] w = new int[1], h = new int[1]; - OS.gdk_drawable_get_size(data.drawable, w, h); - width = w[0]; - height = h[0]; - } - /* Intersect visible bounds with clipping in device space and then convert then to user space */ - int /*long*/ cairo = data.cairo; - int /*long*/ clipRgn = data.clipRgn; - int /*long*/ damageRgn = data.damageRgn; - if (clipRgn != 0 || damageRgn != 0 || cairo != 0) { - int /*long*/ rgn = OS.gdk_region_new(); - GdkRectangle rect = new GdkRectangle(); - rect.width = width; - rect.height = height; - OS.gdk_region_union_with_rect(rgn, rect); - if (damageRgn != 0) { - OS.gdk_region_intersect (rgn, damageRgn); - } - /* 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.gdk_region_intersect(rgn, clipRgn); - OS.gdk_region_destroy(clipRgn); - } else { - OS.gdk_region_intersect(rgn, clipRgn); - } - } - /* 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.gdk_region_destroy(rgn); - rgn = clipRgn; - } - OS.gdk_region_get_clipbox(rgn, rect); - OS.gdk_region_destroy(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); - if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - int /*long*/ clipping = region.handle; - OS.gdk_region_subtract(clipping, clipping); - int /*long*/ cairo = data.cairo; - int /*long*/ clipRgn = data.clipRgn; - if (clipRgn == 0) { - GdkRectangle rect = new GdkRectangle(); - if (data.width != -1 && data.height != -1) { - rect.width = data.width; - rect.height = data.height; - } else { - int[] width = new int[1], height = new int[1]; - OS.gdk_drawable_get_size(data.drawable, width, height); - rect.width = width[0]; - rect.height = height[0]; - } - OS.gdk_region_union_with_rect(clipping, rect); - } else { - /* Convert clipping to device space if needed */ - if (data.clippingTransform != null) { - int /*long*/ rgn = convertRgn(clipRgn, data.clippingTransform); - OS.gdk_region_union(clipping, rgn); - OS.gdk_region_destroy(rgn); - } else { - OS.gdk_region_union(clipping, clipRgn); - } - } - if (data.damageRgn != 0) { - OS.gdk_region_intersect(clipping, data.damageRgn); - } - /* Convert to user space */ - if (cairo != 0) { - double[] matrix = new double[6]; - Cairo.cairo_get_matrix(cairo, matrix); - Cairo.cairo_matrix_invert(matrix); - int /*long*/ rgn = convertRgn(clipping, matrix); - OS.gdk_region_subtract(clipping, clipping); - OS.gdk_region_union(clipping, rgn); - OS.gdk_region_destroy(rgn); - } -} - -/** - * 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); - int /*long*/ cairo = data.cairo; - if (cairo == 0) return SWT.FILL_EVEN_ODD; - return Cairo.cairo_get_fill_rule(cairo) == Cairo.CAIRO_FILL_RULE_WINDING ? 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 data.font; -} - -/** - * Returns a FontMetrics which contains information - * about the font currently being used by the receiver - * to draw and measure text. - * - * @return font metrics for the receiver's font - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public FontMetrics getFontMetrics() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (data.context == 0) createLayout(); - checkGC(FONT); - Font font = data.font; - int /*long*/ context = data.context; - int /*long*/ lang = OS.pango_context_get_language(context); - int /*long*/ metrics = OS.pango_context_get_metrics(context, font.handle, lang); - FontMetrics fm = new FontMetrics(); - fm.ascent = OS.PANGO_PIXELS(OS.pango_font_metrics_get_ascent(metrics)); - fm.descent = OS.PANGO_PIXELS(OS.pango_font_metrics_get_descent(metrics)); - fm.averageCharWidth = OS.PANGO_PIXELS(OS.pango_font_metrics_get_approximate_char_width(metrics)); - fm.height = fm.ascent + fm.descent; - OS.pango_font_metrics_unref(metrics); - return fm; -} - -/** - * 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_WIDGET_DISPOSED); - return Color.gtk_new(data.device, data.foreground); -} - -/** - * Returns the foreground pattern. The default value is - * <code>null</code>. - * - * @return the receiver's foreground pattern - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see Pattern - * - * @since 3.1 - */ -public Pattern getForegroundPattern() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return data.foregroundPattern; -} - -/** - * Returns the GCData. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>GC</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @return the receiver's GCData - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see GCData - * - * @since 3.2 - * @noreference This method is not intended to be referenced by clients. - */ -public GCData getGCData() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return data; -} - -/** - * Returns the receiver's interpolation setting, which will be one of - * <code>SWT.DEFAULT</code>, <code>SWT.NONE</code>, - * <code>SWT.LOW</code> or <code>SWT.HIGH</code>. - * - * @return the receiver's interpolation setting - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public int getInterpolation() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return data.interpolation; -} - -/** - * Returns the receiver's line attributes. - * - * @return the line attributes used for drawing lines - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.3 - */ -public LineAttributes getLineAttributes() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - float[] dashes = null; - if (data.lineDashes != null) { - dashes = new float[data.lineDashes.length]; - System.arraycopy(data.lineDashes, 0, dashes, 0, dashes.length); - } - return new LineAttributes(data.lineWidth, data.lineCap, data.lineJoin, data.lineStyle, dashes, data.lineDashesOffset, data.lineMiterLimit); -} - -/** - * Returns the receiver's line cap style, which will be one - * of the constants <code>SWT.CAP_FLAT</code>, <code>SWT.CAP_ROUND</code>, - * or <code>SWT.CAP_SQUARE</code>. - * - * @return the cap style used for drawing lines - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public int getLineCap() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return data.lineCap; -} - -/** - * Returns the receiver's line dash style. The default value is - * <code>null</code>. - * - * @return the line dash style used for drawing lines - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @since 3.1 - */ -public int[] getLineDash() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (data.lineDashes == null) return null; - int[] lineDashes = new int[data.lineDashes.length]; - 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 antialias = Cairo.CAIRO_ANTIALIAS_DEFAULT; - if (OS.GTK_VERSION < OS.VERSION(2, 8, 0)) { - int /*long*/ options = Cairo.cairo_font_options_create(); - Cairo.cairo_get_font_options(data.cairo, options); - antialias = Cairo.cairo_font_options_get_antialias(options); - Cairo.cairo_font_options_destroy(options); - } else { - if (data.context != 0) { - int /*long*/ options = OS.pango_cairo_context_get_font_options(data.context); - if (options != 0) antialias = Cairo.cairo_font_options_get_antialias(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); - double[] identity = identity(); - Cairo.cairo_matrix_invert(identity); - Cairo.cairo_matrix_multiply(transform.handle, transform.handle, identity); - } else { - transform.setElements(1, 0, 0, 1, 0, 0); - } -} - -/** - * Returns <code>true</code> if this GC is drawing in the mode - * where the resulting color in the destination is the - * <em>exclusive or</em> of the color values in the source - * and the destination, and <code>false</code> if it is - * drawing in the mode where the destination color is being - * replaced with the source color value. - * - * @return <code>true</code> true if the receiver is in XOR mode, and false otherwise - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public boolean getXORMode() { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - return data.xorMode; -} - -/** - * Returns an integer hash code for the receiver. Any two - * objects that return <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 (int)/*64*/handle; -} - -double[] identity() { - double[] identity = new double[6]; - if ((data.style & SWT.MIRRORED) != 0) { - int[] w = new int[1], h = new int[1]; - OS.gdk_drawable_get_size(data.drawable, w, h); - Cairo.cairo_matrix_init(identity, -1, 0, 0, 1, w[0], 0); - } else { - Cairo.cairo_matrix_init_identity(identity); - } - return identity; -} - -void init(Drawable drawable, GCData data, int /*long*/ gdkGC) { - if (data.foreground != null) data.state &= ~FOREGROUND; - if (data.background != null) data.state &= ~(BACKGROUND | BACKGROUND_BG); - 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 = gdkGC; - if ((data.style & SWT.MIRRORED) != 0) { - initCairo(); - int /*long*/ cairo = data.cairo; - Cairo.cairo_set_matrix(cairo, identity()); - } -} - -void initCairo() { - data.device.checkCairo(); - int /*long*/ cairo = data.cairo; - if (cairo != 0) return; - int /*long*/ xDisplay = OS.GDK_DISPLAY(); - int /*long*/ xVisual = OS.gdk_x11_visual_get_xvisual(OS.gdk_visual_get_system()); - int /*long*/ xDrawable = 0; - int translateX = 0, translateY = 0; - int /*long*/ drawable = data.drawable; - if (data.image != null) { - xDrawable = OS.GDK_PIXMAP_XID(drawable); - } else { - if (!data.realDrawable) { - int[] x = new int[1], y = new int[1]; - int /*long*/ [] real_drawable = new int /*long*/ [1]; - OS.gdk_window_get_internal_paint_info(drawable, real_drawable, x, y); - xDrawable = OS.gdk_x11_drawable_get_xid(real_drawable[0]); - translateX = -x[0]; - translateY = -y[0]; - } - } - int[] w = new int[1], h = new int[1]; - OS.gdk_drawable_get_size(drawable, w, h); - int width = w[0], height = h[0]; - int /*long*/ surface = Cairo.cairo_xlib_surface_create(xDisplay, xDrawable, xVisual, width, height); - if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES); - Cairo.cairo_surface_set_device_offset(surface, translateX, translateY); - data.cairo = cairo = Cairo.cairo_create(surface); - Cairo.cairo_surface_destroy(surface); - if (cairo == 0) SWT.error(SWT.ERROR_NO_HANDLES); - data.disposeCairo = true; - 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); -} - -void computeStringSize() { - int[] width = new int[1], height = new int[1]; - OS.pango_layout_get_size(data.layout, width, height); - data.stringHeight = OS.PANGO_PIXELS(height[0]); - data.stringWidth = OS.PANGO_PIXELS(width[0]); -} - -/** - * 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 ((data.style & SWT.MIRRORED) != 0) { - if (!advanced) { - setAlpha(0xFF); - setAntialias(SWT.DEFAULT); - setBackgroundPattern(null); - setClipping(0); - setForegroundPattern(null); - setInterpolation(SWT.DEFAULT); - setTextAntialias(SWT.DEFAULT); - setTransform(null); - } - return; - } - if (advanced && data.cairo != 0) return; - if (advanced) { - try { - initCairo(); - } catch (SWTException e) {} - } else { - if (!data.disposeCairo) return; - int /*long*/ cairo = data.cairo; - if (cairo != 0) Cairo.cairo_destroy(cairo); - data.cairo = 0; - data.interpolation = SWT.DEFAULT; - data.alpha = 0xFF; - 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); -} - -/** - * 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); -} - -/** - * 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) { - setCairoFont(cairo, font.handle); -} - -static void setCairoFont(int /*long*/ cairo, int /*long*/ font) { - int /*long*/ family = OS.pango_font_description_get_family(font); - int length = OS.strlen(family); - byte[] buffer = new byte[length + 1]; - OS.memmove(buffer, family, length); - //TODO - convert font height from pango to cairo - double height = OS.PANGO_PIXELS(OS.pango_font_description_get_size(font)) * 96 / 72; - int pangoStyle = OS.pango_font_description_get_style(font); - int pangoWeight = OS.pango_font_description_get_weight(font); - int slant = Cairo.CAIRO_FONT_SLANT_NORMAL; - if (pangoStyle == OS.PANGO_STYLE_ITALIC) slant = Cairo.CAIRO_FONT_SLANT_ITALIC; - if (pangoStyle == OS.PANGO_STYLE_OBLIQUE) slant = Cairo.CAIRO_FONT_SLANT_OBLIQUE; - int weight = Cairo.CAIRO_FONT_WEIGHT_NORMAL; - if (pangoWeight == OS.PANGO_WEIGHT_BOLD) weight = Cairo.CAIRO_FONT_WEIGHT_BOLD; - Cairo.cairo_select_font_face(cairo, buffer, slant, weight); - Cairo.cairo_set_font_size(cairo, height); -} - -static void setCairoRegion(int /*long*/ cairo, int /*long*/ rgn) { - if (OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) { - OS.gdk_cairo_region(cairo, rgn); - } else { - int[] nRects = new int[1]; - int /*long*/[] rects = new int /*long*/[1]; - OS.gdk_region_get_rectangles(rgn, rects, nRects); - GdkRectangle rect = new GdkRectangle(); - for (int i=0; i<nRects[0]; i++) { - OS.memmove(rect, rects[0] + (i * GdkRectangle.sizeof), GdkRectangle.sizeof); - Cairo.cairo_rectangle(cairo, rect.x, rect.y, rect.width, rect.height); - } - if (rects[0] != 0) OS.g_free(rects[0]); - } -} - -static void setCairoPatternColor(int /*long*/ pattern, int offset, Color c, int alpha) { - GdkColor 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); - double[] identity = new double[6]; - Cairo.cairo_matrix_init_identity(identity); - Cairo.cairo_set_matrix(cairo, identity); - 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 /*long*/ clipRgn) { - int /*long*/ cairo = data.cairo; - if (clipRgn == 0) { - if (data.clipRgn != 0) { - OS.gdk_region_destroy(data.clipRgn); - data.clipRgn = 0; - } - if (cairo != 0) { - data.clippingTransform = null; - setCairoClip(data.damageRgn, 0); - } else { - int /*long*/ clipping = data.damageRgn != 0 ? data.damageRgn : 0; - OS.gdk_gc_set_clip_region(handle, clipping); - } - } else { - if (data.clipRgn == 0) data.clipRgn = OS.gdk_region_new(); - OS.gdk_region_subtract(data.clipRgn, data.clipRgn); - OS.gdk_region_union(data.clipRgn, 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 /*long*/ clipping = clipRgn; - if (data.damageRgn != 0) { - clipping = OS.gdk_region_new(); - OS.gdk_region_union(clipping, clipRgn); - OS.gdk_region_intersect(clipping, data.damageRgn); - } - OS.gdk_gc_set_clip_region(handle, clipping); - if (clipping != clipRgn) OS.gdk_region_destroy(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; - } - GdkRectangle rect = new GdkRectangle(); - rect.x = x; - rect.y = y; - rect.width = width; - rect.height = height; - int /*long*/ clipRgn = OS.gdk_region_new(); - OS.gdk_region_union_with_rect(clipRgn, rect); - setClipping(clipRgn); - OS.gdk_region_destroy(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); - } -} - -/** - * 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 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; - data.stringWidth = data.stringHeight = -1; -} - -/** - * 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 cairo_mode = Cairo.CAIRO_FILL_RULE_EVEN_ODD; - switch (rule) { - case SWT.FILL_WINDING: - cairo_mode = Cairo.CAIRO_FILL_RULE_WINDING; break; - case SWT.FILL_EVEN_ODD: - cairo_mode = Cairo.CAIRO_FILL_RULE_EVEN_ODD; break; - default: - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - //TODO - need fill rule in X, GDK has no API - initCairo(); - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - Cairo.cairo_set_fill_rule(cairo, cairo_mode); - } -} - -/** - * 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; -} - -/** - * 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, int flags) { - if (data.layout == 0) createLayout(); - if (string == data.string && (flags & ~SWT.DRAW_TRANSPARENT) == (data.drawFlags & ~SWT.DRAW_TRANSPARENT)) { - return; - } - byte[] buffer; - int mnemonic, length = string.length (); - int /*long*/ layout = data.layout; - char[] text = new char[length]; - string.getChars(0, length, text, 0); - if ((flags & SWT.DRAW_MNEMONIC) != 0 && (mnemonic = fixMnemonic(text)) != -1) { - char[] text1 = new char[mnemonic - 1]; - System.arraycopy(text, 0, text1, 0, text1.length); - byte[] buffer1 = Converter.wcsToMbcs(null, text1, false); - char[] text2 = new char[text.length - mnemonic]; - System.arraycopy(text, mnemonic - 1, text2, 0, text2.length); - byte[] buffer2 = Converter.wcsToMbcs(null, text2, false); - buffer = new byte[buffer1.length + buffer2.length]; - System.arraycopy(buffer1, 0, buffer, 0, buffer1.length); - System.arraycopy(buffer2, 0, buffer, buffer1.length, buffer2.length); - int /*long*/ attr_list = OS.pango_attr_list_new(); - int /*long*/ attr = OS.pango_attr_underline_new(OS.PANGO_UNDERLINE_LOW); - PangoAttribute attribute = new PangoAttribute(); - OS.memmove(attribute, attr, PangoAttribute.sizeof); - attribute.start_index = buffer1.length; - attribute.end_index = buffer1.length + 1; - OS.memmove(attr, attribute, PangoAttribute.sizeof); - OS.pango_attr_list_insert(attr_list, attr); - OS.pango_layout_set_attributes(layout, attr_list); - OS.pango_attr_list_unref(attr_list); - } else { - buffer = Converter.wcsToMbcs(null, text, false); - OS.pango_layout_set_attributes(layout, 0); - } - OS.pango_layout_set_text(layout, buffer, buffer.length); - OS.pango_layout_set_single_paragraph_mode(layout, (flags & SWT.DRAW_DELIMITER) == 0); - OS.pango_layout_set_tabs(layout, (flags & SWT.DRAW_TAB) != 0 ? 0 : data.device.emptyTab); - data.string = string; - data.stringWidth = data.stringHeight = -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); - if (OS.GTK_VERSION < OS.VERSION(2, 8, 0)) { - Cairo.cairo_set_font_options(data.cairo, options); - } else { - if (data.context == 0) createLayout(); - OS.pango_cairo_context_set_font_options(data.context, 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; - double[] identity = identity(); - if (transform != null) { - Cairo.cairo_matrix_multiply(identity, transform.handle, identity); - } - Cairo.cairo_set_matrix(cairo, identity); - 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.gdk_gc_set_function(handle, xor ? OS.GDK_XOR : OS.GDK_COPY); - data.xorMode = xor; -} - -/** - * Returns the extent of the given string. No tab - * expansion or carriage return processing will be performed. - * <p> - * The <em>extent</em> of a string is the width and height of - * the rectangular area it would cover if drawn in a particular - * font (in this case, the current font in the receiver). - * </p> - * - * @param string the string to measure - * @return a point containing the extent of the string - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Point stringExtent(String string) { - return textExtent(string, 0); -} - -/** - * Returns the extent of the given string. Tab expansion and - * carriage return processing are performed. - * <p> - * The <em>extent</em> of a string is the width and height of - * the rectangular area it would cover if drawn in a particular - * font (in this case, the current font in the receiver). - * </p> - * - * @param string the string to measure - * @return a point containing the extent of the string - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Point textExtent(String string) { - return textExtent(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB); -} - -/** - * Returns the extent of the given string. Tab expansion, line - * delimiter and mnemonic processing are performed according to - * the specified flags, which can be a combination of: - * <dl> - * <dt><b>DRAW_DELIMITER</b></dt> - * <dd>draw multiple lines</dd> - * <dt><b>DRAW_TAB</b></dt> - * <dd>expand tabs</dd> - * <dt><b>DRAW_MNEMONIC</b></dt> - * <dd>underline the mnemonic character</dd> - * <dt><b>DRAW_TRANSPARENT</b></dt> - * <dd>transparent background</dd> - * </dl> - * <p> - * The <em>extent</em> of a string is the width and height of - * the rectangular area it would cover if drawn in a particular - * font (in this case, the current font in the receiver). - * </p> - * - * @param string the string to measure - * @param flags the flags specifying how to process the text - * @return a point containing the extent of the string - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Point textExtent(String string, int flags) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - int /*long*/ cairo = data.cairo; - if (cairo != 0) { - if (OS.GTK_VERSION < OS.VERSION(2, 8, 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); - } - } - setString(string, flags); - checkGC(FONT); - if (data.stringWidth == -1) { - computeStringSize(); - } - return new Point(data.stringWidth, data.stringHeight); -} - -/** - * 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/gtk/org/eclipse/swt/graphics/GCData.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GCData.java deleted file mode 100644 index d507acb51b..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/GCData.java +++ /dev/null @@ -1,64 +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.gtk.*; -import org.eclipse.swt.*; - -/** - * Instances of this class are descriptions of GCs in terms - * of unallocated platform-specific data fields. - * <p> - * <b>IMPORTANT:</b> This class is <em>not</em> part of the public - * API for SWT. It is marked public only so that it can be shared - * within the packages provided by SWT. It is not available on all - * platforms, and should never be called from application code. - * </p> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * @noinstantiate This class is not intended to be instantiated by clients. - */ -public final class GCData { - public Device device; - public int style, state = -1; - public GdkColor foreground; - public GdkColor background; - public Font font; - public Pattern foregroundPattern; - public Pattern backgroundPattern; - public int /*long*/ clipRgn; - public float lineWidth; - public int lineStyle = SWT.LINE_SOLID; - public float[] lineDashes; - public float lineDashesOffset; - public float lineMiterLimit = 10; - public int lineCap = SWT.CAP_FLAT; - public int lineJoin = SWT.JOIN_MITER; - public boolean xorMode; - public int alpha = 0xFF; - public int interpolation = SWT.DEFAULT; - - public int /*long*/ context; - public int /*long*/ layout; - public int /*long*/ damageRgn; - public Image image; - public int /*long*/ drawable; - public int /*long*/ cairo; - public double cairoXoffset, cairoYoffset; - public boolean disposeCairo; - public double[] clippingTransform; - public String string; - public int stringWidth = -1; - public int stringHeight = -1; - public int drawFlags; - public boolean realDrawable; - public int width = -1, height = -1; -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java deleted file mode 100644 index 1754574694..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Image.java +++ /dev/null @@ -1,1165 +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.cairo.*; -import org.eclipse.swt.internal.gtk.*; -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 /*long*/ 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 /*long*/ mask; - - int /*long*/ surface, surfaceData; - - /** - * 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); - if (srcImage == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (srcImage.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - switch (flag) { - case SWT.IMAGE_COPY: - case SWT.IMAGE_DISABLE: - case SWT.IMAGE_GRAY: - break; - default: - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - device = this.device; - this.type = srcImage.type; - - /* Get source image size */ - int[] w = new int[1], h = new int[1]; - OS.gdk_drawable_get_size(srcImage.pixmap, w, h); - int width = w[0]; - int height = h[0]; - - /* Copy the mask */ - if ((srcImage.type == SWT.ICON && srcImage.mask != 0) || srcImage.transparentPixel != -1) { - /* Generate the mask if necessary. */ - if (srcImage.transparentPixel != -1) srcImage.createMask(); - int /*long*/ mask = OS.gdk_pixmap_new(0, width, height, 1); - if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int /*long*/ gdkGC = OS.gdk_gc_new(mask); - if (gdkGC == 0) SWT.error(SWT.ERROR_NO_HANDLES); - OS.gdk_draw_drawable(mask, gdkGC, srcImage.mask, 0, 0, 0, 0, width, height); - OS.g_object_unref(gdkGC); - 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(); - } - - /* Copy transparent pixel and alpha data */ - if (flag != SWT.IMAGE_DISABLE) 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); - - /* Create the new pixmap */ - int /*long*/ pixmap = OS.gdk_pixmap_new (OS.GDK_ROOT_PARENT(), width, height, -1); - if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int /*long*/ gdkGC = OS.gdk_gc_new(pixmap); - if (gdkGC == 0) SWT.error(SWT.ERROR_NO_HANDLES); - this.pixmap = pixmap; - - if (flag == SWT.IMAGE_COPY) { - OS.gdk_draw_drawable(pixmap, gdkGC, srcImage.pixmap, 0, 0, 0, 0, width, height); - OS.g_object_unref(gdkGC); - } else { - - /* Retrieve the source pixmap data */ - int /*long*/ pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, width, height); - if (pixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int /*long*/ colormap = OS.gdk_colormap_get_system(); - OS.gdk_pixbuf_get_from_drawable(pixbuf, srcImage.pixmap, colormap, 0, 0, 0, 0, width, height); - int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf); - - /* Apply transformation */ - switch (flag) { - case SWT.IMAGE_DISABLE: { - Color zeroColor = device.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW); - RGB zeroRGB = zeroColor.getRGB(); - byte zeroRed = (byte)zeroRGB.red; - byte zeroGreen = (byte)zeroRGB.green; - byte zeroBlue = (byte)zeroRGB.blue; - Color oneColor = device.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); - RGB oneRGB = oneColor.getRGB(); - byte oneRed = (byte)oneRGB.red; - byte oneGreen = (byte)oneRGB.green; - byte oneBlue = (byte)oneRGB.blue; - byte[] line = new byte[stride]; - for (int y=0; y<height; y++) { - OS.memmove(line, pixels + (y * stride), stride); - for (int x=0; x<width; x++) { - int offset = x*3; - int red = line[offset] & 0xFF; - int green = line[offset+1] & 0xFF; - int blue = line[offset+2] & 0xFF; - int intensity = red * red + green * green + blue * blue; - if (intensity < 98304) { - line[offset] = zeroRed; - line[offset+1] = zeroGreen; - line[offset+2] = zeroBlue; - } else { - line[offset] = oneRed; - line[offset+1] = oneGreen; - line[offset+2] = oneBlue; - } - } - OS.memmove(pixels + (y * stride), line, stride); - } - break; - } - case SWT.IMAGE_GRAY: { - byte[] line = new byte[stride]; - for (int y=0; y<height; y++) { - OS.memmove(line, pixels + (y * stride), stride); - for (int x=0; x<width; x++) { - int offset = x*3; - int red = line[offset] & 0xFF; - int green = line[offset+1] & 0xFF; - int blue = line[offset+2] & 0xFF; - byte intensity = (byte)((red+red+green+green+green+green+green+blue) >> 3); - line[offset] = line[offset+1] = line[offset+2] = intensity; - } - OS.memmove(pixels + (y * stride), line, stride); - } - break; - } - } - - /* Copy data back to destination pixmap */ - OS.gdk_pixbuf_render_to_drawable(pixbuf, pixmap, gdkGC, 0, 0, 0, 0, width, height, OS.GDK_RGB_DITHER_NORMAL, 0, 0); - - /* Free resources */ - OS.g_object_unref(pixbuf); - OS.g_object_unref(gdkGC); - } - init(); -} - -/** - * Constructs an empty instance of this class with the - * width and height of the specified rectangle. The result - * may be drawn upon by creating a GC and using any of its - * drawing operations, as shown in the following example: - * <pre> - * Image i = new Image(device, boundsRectangle); - * GC gc = new GC(i); - * gc.drawRectangle(0, 0, 50, 50); - * gc.dispose(); - * </pre> - * <p> - * Note: Some platforms may have a limitation on the size - * of image that can be created (size depends on width, height, - * and depth). For example, Windows 95, 98, and ME do not allow - * images larger than 16M. - * </p> - * - * @param device the device on which to create the image - * @param bounds a rectangle specifying the image's width and height (must not be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_NULL_ARGUMENT - if the bounds rectangle is null</li> - * <li>ERROR_INVALID_ARGUMENT - if either the rectangle's width or height is negative</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> - * </ul> - */ -public Image(Device device, Rectangle bounds) { - super(device); - if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - init(bounds.width, bounds.height); - init(); -} - -/** - * Constructs an instance of this class from the given - * <code>ImageData</code>. - * - * @param device the device on which to create the image - * @param data the image data to create the image from (must not be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_NULL_ARGUMENT - if the image data is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_UNSUPPORTED_DEPTH - if the depth of the ImageData is not supported</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> - * </ul> - */ -public Image(Device device, ImageData data) { - super(device); - init(data); - init(); -} - -/** - * Constructs an instance of this class, whose type is - * <code>SWT.ICON</code>, from the two given <code>ImageData</code> - * objects. The two images must be the same size. Pixel transparency - * in either image will be ignored. - * <p> - * The mask image should contain white wherever the icon is to be visible, - * and black wherever the icon is to be transparent. In addition, - * the source image should contain black wherever the icon is to be - * transparent. - * </p> - * - * @param device the device on which to create the icon - * @param source the color data for the icon - * @param mask the mask data for the icon - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> - * <li>ERROR_NULL_ARGUMENT - if either the source or mask is null </li> - * <li>ERROR_INVALID_ARGUMENT - if source and mask are different sizes</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> - * </ul> - */ -public Image(Device device, ImageData source, ImageData mask) { - super(device); - if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (mask == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (source.width != mask.width || source.height != mask.height) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - mask = ImageData.convertMask (mask); - ImageData image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad, source.data); - image.maskPad = mask.scanlinePad; - image.maskData = mask.data; - init(image); - 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); - if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - initNative(filename); - if (this.pixmap == 0) init(new ImageData(filename)); - init(); -} - -void initNative(String filename) { - try { - int length = filename.length (); - char [] chars = new char [length]; - filename.getChars (0, length, chars, 0); - byte [] buffer = Converter.wcsToMbcs(null, chars, true); - int /*long*/ pixbuf = OS.gdk_pixbuf_new_from_file(buffer, null); - if (pixbuf != 0) { - boolean hasAlpha = OS.gdk_pixbuf_get_has_alpha(pixbuf); - if (hasAlpha) { - /* - * Bug in GTK. Depending on the image (seems to affect images that have - * some degree of transparency all over the image), gdk_pixbuff_render_pixmap_and_mask() - * will return a corrupt pixmap. To avoid this, read in and store the alpha channel data - * for the image and then set it to 0xFF to prevent any possible corruption from - * gdk_pixbuff_render_pixmap_and_mask(). - */ - int width = OS.gdk_pixbuf_get_width(pixbuf); - int height = OS.gdk_pixbuf_get_height(pixbuf); - int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf); - byte[] line = new byte[stride]; - alphaData = new byte[width * height]; - for (int y = 0; y < height; y++) { - OS.memmove(line, pixels + (y * stride), stride); - for (int x = 0; x < width; x++) { - alphaData[y*width+x] = line[x*4 + 3]; - line[x*4 + 3] = (byte) 0xFF; - } - OS.memmove(pixels + (y * stride), line, stride); - } - createAlphaMask(width, height); - } - int /*long*/ [] pixmap_return = new int /*long*/ [1]; - OS.gdk_pixbuf_render_pixmap_and_mask(pixbuf, pixmap_return, null, 0); - this.type = SWT.BITMAP; - this.pixmap = pixmap_return[0]; - if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES); - OS.g_object_unref (pixbuf); - } - } catch (SWTException e) {} -} - -void createAlphaMask (int width, int height) { - if (device.useXRender && (alpha != -1 || alphaData != null)) { - mask = OS.gdk_pixmap_new(0, alpha != -1 ? 1 : width, alpha != -1 ? 1 : height, 8); - if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int /*long*/ gc = OS.gdk_gc_new(mask); - if (alpha != -1) { - GdkColor color = new GdkColor(); - color.pixel = (alpha & 0xFF) << 8 | (alpha & 0xFF); - OS.gdk_gc_set_foreground(gc, color); - OS.gdk_draw_rectangle(mask, gc, 1, 0, 0, 1, 1); - } else { - int /*long*/ imagePtr = OS.gdk_drawable_get_image(mask, 0, 0, width, height); - if (imagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES); - GdkImage gdkImage = new GdkImage(); - OS.memmove(gdkImage, imagePtr); - if (gdkImage.bpl == width) { - OS.memmove(gdkImage.mem, alphaData, alphaData.length); - } else { - byte[] line = new byte[gdkImage.bpl]; - for (int y = 0; y < height; y++) { - System.arraycopy(alphaData, width * y, line, 0, width); - OS.memmove(gdkImage.mem + (gdkImage.bpl * y), line, gdkImage.bpl); - } - } - OS.gdk_draw_image(mask, gc, imagePtr, 0, 0, 0, 0, width, height); - OS.g_object_unref(imagePtr); - } - OS.g_object_unref(gc); - } -} - -/** - * Create the receiver's mask if necessary. - */ -void createMask() { - if (mask != 0) return; - mask = createMask(getImageData(), false); - if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES); -} - -int /*long*/ createMask(ImageData image, boolean copy) { - ImageData mask = image.getTransparencyMask(); - byte[] data = mask.data; - byte[] maskData = copy ? new byte[data.length] : data; - for (int i = 0; i < maskData.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); - return OS.gdk_bitmap_create_from_data(0, maskData, mask.width, mask.height); -} - -void createSurface() { - if (surface != 0) return; - /* Generate the mask if necessary. */ - if (transparentPixel != -1) createMask(); - int[] w = new int[1], h = new int[1]; - OS.gdk_drawable_get_size(pixmap, w, h); - int width = w[0], height = h[0]; - if (mask != 0 || alpha != -1 || alphaData != null) { - int /*long*/ pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, true, 8, width, height); - if (pixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int /*long*/ colormap = OS.gdk_colormap_get_system(); - OS.gdk_pixbuf_get_from_drawable(pixbuf, pixmap, colormap, 0, 0, 0, 0, width, height); - int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf); - byte[] line = new byte[stride]; - if (mask != 0 && OS.gdk_drawable_get_depth(mask) == 1) { - int /*long*/ maskPixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, width, height); - if (maskPixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES); - OS.gdk_pixbuf_get_from_drawable(maskPixbuf, mask, 0, 0, 0, 0, 0, width, height); - int maskStride = OS.gdk_pixbuf_get_rowstride(maskPixbuf); - int /*long*/ maskPixels = OS.gdk_pixbuf_get_pixels(maskPixbuf); - byte[] maskLine = new byte[maskStride]; - int /*long*/ offset = pixels, maskOffset = maskPixels; - for (int y=0; y<height; y++) { - OS.memmove(line, offset, stride); - OS.memmove(maskLine, maskOffset, maskStride); - for (int x=0, offset1=0; x<width; x++, offset1 += 4) { - if (maskLine[x * 3] == 0) { - line[offset1 + 0] = line[offset1 + 1] = line[offset1 + 2] = line[offset1 + 3] = 0; - } - byte temp = line[offset1]; - line[offset1] = line[offset1 + 2]; - line[offset1 + 2] = temp; - } - OS.memmove(offset, line, stride); - offset += stride; - maskOffset += maskStride; - } - OS.g_object_unref(maskPixbuf); - } else if (alpha != -1) { - int /*long*/ offset = pixels; - for (int y=0; y<height; y++) { - OS.memmove(line, offset, stride); - for (int x=0, offset1=0; x<width; x++, offset1 += 4) { - line[offset1+3] = (byte)alpha; - /* pre-multiplied alpha */ - int r = ((line[offset1 + 0] & 0xFF) * alpha) + 128; - r = (r + (r >> 8)) >> 8; - int g = ((line[offset1 + 1] & 0xFF) * alpha) + 128; - g = (g + (g >> 8)) >> 8; - int b = ((line[offset1 + 2] & 0xFF) * alpha) + 128; - b = (b + (b >> 8)) >> 8; - line[offset1 + 0] = (byte)b; - line[offset1 + 1] = (byte)g; - line[offset1 + 2] = (byte)r; - } - OS.memmove(offset, line, stride); - offset += stride; - } - } else if (alphaData != null) { - int /*long*/ offset = pixels; - for (int y = 0; y < h [0]; y++) { - OS.memmove (line, offset, stride); - for (int x=0, offset1=0; x<width; x++, offset1 += 4) { - int alpha = alphaData [y*w [0]+x] & 0xFF; - line[offset1+3] = (byte)alpha; - /* pre-multiplied alpha */ - int r = ((line[offset1 + 0] & 0xFF) * alpha) + 128; - r = (r + (r >> 8)) >> 8; - int g = ((line[offset1 + 1] & 0xFF) * alpha) + 128; - g = (g + (g >> 8)) >> 8; - int b = ((line[offset1 + 2] & 0xFF) * alpha) + 128; - b = (b + (b >> 8)) >> 8; - line[offset1 + 0] = (byte)b; - line[offset1 + 1] = (byte)g; - line[offset1 + 2] = (byte)r; - } - OS.memmove (offset, line, stride); - offset += stride; - } - } else { - int /*long*/ offset = pixels; - for (int y = 0; y < h [0]; y++) { - OS.memmove (line, offset, stride); - for (int x=0, offset1=0; x<width; x++, offset1 += 4) { - line[offset1+3] = (byte)0xFF; - byte temp = line[offset1]; - line[offset1] = line[offset1 + 2]; - line[offset1 + 2] = temp; - } - OS.memmove (offset, line, stride); - offset += stride; - } - } - surfaceData = OS.g_malloc(stride * height); - OS.memmove(surfaceData, pixels, stride * height); - surface = Cairo.cairo_image_surface_create_for_data(surfaceData, Cairo.CAIRO_FORMAT_ARGB32, width, height, stride); - OS.g_object_unref(pixbuf); - } else { - int /*long*/ xDisplay = OS.GDK_DISPLAY(); - int /*long*/ xDrawable = OS.GDK_PIXMAP_XID(pixmap); - int /*long*/ xVisual = OS.gdk_x11_visual_get_xvisual(OS.gdk_visual_get_system()); - surface = Cairo.cairo_xlib_surface_create(xDisplay, xDrawable, xVisual, width, height); - } - /* Destroy the image mask if the there is a GC created on the image */ - if (transparentPixel != -1 && memGC != null) destroyMask(); -} - -/** - * Destroy the receiver's mask if it exists. - */ -void destroyMask() { - if (mask == 0) return; - OS.g_object_unref(mask); - mask = 0; -} - -void destroy() { - if (memGC != null) memGC.dispose(); - if (pixmap != 0) OS.g_object_unref(pixmap); - if (mask != 0) OS.g_object_unref(mask); - if (surface != 0) Cairo.cairo_surface_destroy(surface); - if (surfaceData != 0) OS.g_free(surfaceData); - surfaceData = surface = pixmap = mask = 0; - memGC = 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 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; - //NOT DONE - return null; -} - -/** - * 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[] w = new int[1]; int[] h = new int[1]; - OS.gdk_drawable_get_size(pixmap, w, h); - 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); - - int[] w = new int[1], h = new int[1]; - OS.gdk_drawable_get_size(pixmap, w, h); - int width = w[0], height = h[0]; - int /*long*/ pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, width, height); - if (pixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int /*long*/ colormap = OS.gdk_colormap_get_system(); - OS.gdk_pixbuf_get_from_drawable(pixbuf, pixmap, colormap, 0, 0, 0, 0, width, height); - int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf); - byte[] srcData = new byte[stride * height]; - OS.memmove(srcData, pixels, srcData.length); - OS.g_object_unref(pixbuf); - - PaletteData palette = new PaletteData(0xFF0000, 0xFF00, 0xFF); - ImageData data = new ImageData(width, height, 24, palette, 4, srcData); - data.bytesPerLine = stride; - - if (transparentPixel == -1 && type == SWT.ICON && mask != 0) { - /* Get the icon mask data */ - int /*long*/ gdkImagePtr = OS.gdk_drawable_get_image(mask, 0, 0, width, height); - if (gdkImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES); - GdkImage gdkImage = new GdkImage(); - OS.memmove(gdkImage, gdkImagePtr); - byte[] maskData = new byte[gdkImage.bpl * gdkImage.height]; - OS.memmove(maskData, gdkImage.mem, maskData.length); - OS.g_object_unref(gdkImagePtr); - int maskPad; - for (maskPad = 1; maskPad < 128; maskPad++) { - int bpl = (((width + 7) / 8) + (maskPad - 1)) / maskPad * maskPad; - if (gdkImage.bpl == bpl) break; - } - /* 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 (gdkImage.byte_order == OS.GDK_LSB_FIRST) { - 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); - } - return data; -} - -/** - * Invokes platform specific functionality to allocate a new image. - * <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 device the device on which to allocate the color - * @param type the type of the image (<code>SWT.BITMAP</code> or <code>SWT.ICON</code>) - * @param pixmap the OS handle for the image - * @param mask the OS handle for the image mask - * - * @private - */ -public static Image gtk_new(Device device, int type, int /*long*/ pixmap, int /*long*/ mask) { - Image image = new Image(device); - image.type = type; - image.pixmap = pixmap; - image.mask = mask; - return image; -} - -/** - * Returns an integer hash code for the receiver. Any two - * objects that return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals - */ -public int hashCode () { - return (int)/*64*/pixmap; -} - -void init(int width, int height) { - if (width <= 0 || height <= 0) { - SWT.error (SWT.ERROR_INVALID_ARGUMENT); - } - this.type = SWT.BITMAP; - - /* Create the pixmap */ - this.pixmap = OS.gdk_pixmap_new(OS.GDK_ROOT_PARENT(), width, height, -1); - if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES); - /* Fill the bitmap with white */ - GdkColor white = new GdkColor(); - white.red = (short)0xFFFF; - white.green = (short)0xFFFF; - white.blue = (short)0xFFFF; - int /*long*/ colormap = OS.gdk_colormap_get_system(); - OS.gdk_colormap_alloc_color(colormap, white, true, true); - int /*long*/ gdkGC = OS.gdk_gc_new(pixmap); - OS.gdk_gc_set_foreground(gdkGC, white); - OS.gdk_draw_rectangle(pixmap, gdkGC, 1, 0, 0, width, height); - OS.g_object_unref(gdkGC); - OS.gdk_colormap_free_colors(colormap, white, 1); -} - -void init(ImageData image) { - if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - int width = image.width; - int height = image.height; - PaletteData palette = image.palette; - if (!(((image.depth == 1 || image.depth == 2 || image.depth == 4 || image.depth == 8) && !palette.isDirect) || - ((image.depth == 8) || (image.depth == 16 || image.depth == 24 || image.depth == 32) && palette.isDirect))) - SWT.error (SWT.ERROR_UNSUPPORTED_DEPTH); - int /*long*/ pixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, width, height); - if (pixbuf == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); - int /*long*/ data = OS.gdk_pixbuf_get_pixels(pixbuf); - byte[] buffer = image.data; - if (!palette.isDirect || image.depth != 24 || stride != image.bytesPerLine || palette.redMask != 0xFF0000 || palette.greenMask != 0xFF00 || palette.blueMask != 0xFF) { - buffer = new byte[stride * height]; - if (palette.isDirect) { - ImageData.blit(ImageData.BLIT_SRC, - image.data, image.depth, image.bytesPerLine, image.getByteOrder(), 0, 0, width, height, palette.redMask, palette.greenMask, palette.blueMask, - ImageData.ALPHA_OPAQUE, null, 0, 0, 0, - buffer, 24, stride, ImageData.MSB_FIRST, 0, 0, width, height, 0xFF0000, 0xFF00, 0xFF, - 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, - image.data, image.depth, image.bytesPerLine, image.getByteOrder(), 0, 0, width, height, srcReds, srcGreens, srcBlues, - ImageData.ALPHA_OPAQUE, null, 0, 0, 0, - buffer, 24, stride, ImageData.MSB_FIRST, 0, 0, width, height, 0xFF0000, 0xFF00, 0xFF, - false, false); - } - } - OS.memmove(data, buffer, stride * height); - int /*long*/ pixmap = OS.gdk_pixmap_new (OS.GDK_ROOT_PARENT(), width, height, -1); - if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int /*long*/ gdkGC = OS.gdk_gc_new(pixmap); - if (gdkGC == 0) SWT.error(SWT.ERROR_NO_HANDLES); - OS.gdk_pixbuf_render_to_drawable(pixbuf, pixmap, gdkGC, 0, 0, 0, 0, width, height, OS.GDK_RGB_DITHER_NORMAL, 0, 0); - OS.g_object_unref(gdkGC); - OS.g_object_unref(pixbuf); - - boolean isIcon = image.getTransparencyType() == SWT.TRANSPARENCY_MASK; - if (isIcon || image.transparentPixel != -1) { - if (image.transparentPixel != -1) { - RGB rgb = null; - if (palette.isDirect) { - rgb = palette.getRGB(image.transparentPixel); - } else { - if (image.transparentPixel < palette.colors.length) { - rgb = palette.getRGB(image.transparentPixel); - } - } - if (rgb != null) { - transparentPixel = rgb.red << 16 | rgb.green << 8 | rgb.blue; - } - } - int /*long*/ mask = createMask(image, isIcon); - if (mask == 0) SWT.error(SWT.ERROR_NO_HANDLES); - this.mask = mask; - if (isIcon) { - 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(width, 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 /*long*/ 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 /*long*/ gdkGC = OS.gdk_gc_new(pixmap); - if (data != null) { - int mask = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT; - if ((data.style & mask) == 0) { - data.style |= SWT.LEFT_TO_RIGHT; - } else { - if ((data.style & SWT.RIGHT_TO_LEFT) != 0) { - data.style |= SWT.MIRRORED; - } - } - data.device = device; - data.drawable = pixmap; - data.background = device.COLOR_WHITE.handle; - data.foreground = device.COLOR_BLACK.handle; - data.font = device.systemFont; - data.image = this; - } - return gdkGC; -} - -/** - * 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 /*long*/ gdkGC, GCData data) { - OS.g_object_unref(gdkGC); -} - -/** - * 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; -} - -/** - * 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; - //NOT DONE -} - -/** - * 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/gtk/org/eclipse/swt/graphics/Region.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Region.java deleted file mode 100644 index 3ddb8b5b0e..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/Region.java +++ /dev/null @@ -1,594 +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.gtk.*; -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 /*long*/ 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.gdk_region_new(); - if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); - init(); -} - -Region(Device device, int /*long*/ 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); - /* - * Bug in GTK. If gdk_region_polygon() is called with one point, - * it segment faults. The fix is to make sure that it is called - * with enough points for a polygon. - */ - if (pointArray.length < 6) return; - int /*long*/ polyRgn = OS.gdk_region_polygon(pointArray, pointArray.length / 2, OS.GDK_EVEN_ODD_RULE); - OS.gdk_region_union(handle, polyRgn); - OS.gdk_region_destroy(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); - GdkRectangle gdkRect = new GdkRectangle(); - gdkRect.x = x; - gdkRect.y = y; - gdkRect.width = width; - gdkRect.height = height; - OS.gdk_region_union_with_rect(handle, gdkRect); -} - -/** - * 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.gdk_region_union(handle, region.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.gdk_region_point_in(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.gdk_region_destroy(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); - GdkRectangle gdkRect = new GdkRectangle(); - OS.gdk_region_get_clipbox(handle, gdkRect); - return new Rectangle(gdkRect.x, gdkRect.y, gdkRect.width, gdkRect.height); -} - -public static Region gtk_new(Device device, int /*long*/ handle) { - return new Region(device, 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 (int)/*64*/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); - GdkRectangle gdkRect = new GdkRectangle(); - gdkRect.x = x; - gdkRect.y = y; - gdkRect.width = width; - gdkRect.height = height; - int /*long*/ rectRgn = OS.gdk_region_rectangle(gdkRect); - OS.gdk_region_intersect(handle, rectRgn); - OS.gdk_region_destroy(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.gdk_region_intersect(handle, region.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); - GdkRectangle gdkRect = new GdkRectangle(); - gdkRect.x = x; - gdkRect.y = y; - gdkRect.width = width; - gdkRect.height = height; - return OS.gdk_region_rect_in(handle, gdkRect) != OS.GDK_OVERLAP_RECTANGLE_OUT; -} -/** - * 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.gdk_region_empty(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); - /* - * Bug in GTK. If gdk_region_polygon() is called with one point, - * it segment faults. The fix is to make sure that it is called - * with enough points for a polygon. - */ - if (pointArray.length < 6) return; - int /*long*/ polyRgn = OS.gdk_region_polygon(pointArray, pointArray.length / 2, OS.GDK_EVEN_ODD_RULE); - OS.gdk_region_subtract(handle, polyRgn); - OS.gdk_region_destroy(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); - GdkRectangle gdkRect = new GdkRectangle(); - gdkRect.x = x; - gdkRect.y = y; - gdkRect.width = width; - gdkRect.height = height; - int /*long*/ rectRgn = OS.gdk_region_rectangle(gdkRect); - OS.gdk_region_subtract(handle, rectRgn); - OS.gdk_region_destroy(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.gdk_region_subtract(handle, region.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.gdk_region_offset (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/gtk/org/eclipse/swt/graphics/TextLayout.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java deleted file mode 100644 index d72c2bac6d..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/graphics/TextLayout.java +++ /dev/null @@ -1,2201 +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.gtk.*; -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 { - - static class StyleItem { - TextStyle style; - int start; - - public String toString () { - return "StyleItem {" + start + ", " + style + "}"; - } - } - - Font font; - String text; - int ascent, descent; - int[] segments; - int[] tabs; - StyleItem[] styles; - int /*long*/ layout, context, attrList; - int[] invalidOffsets; - static final char LTR_MARK = '\u200E', RTL_MARK = '\u200F', ZWS = '\u200B', ZWNBS = '\uFEFF'; - -/** - * 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); - device = this.device; - context = OS.gdk_pango_context_get(); - if (context == 0) SWT.error(SWT.ERROR_NO_HANDLES); - OS.pango_context_set_language(context, OS.gtk_get_default_language()); - OS.pango_context_set_base_dir(context, OS.PANGO_DIRECTION_LTR); - OS.gdk_pango_context_set_colormap(context, OS.gdk_colormap_get_system()); - layout = OS.pango_layout_new(context); - if (layout == 0) SWT.error(SWT.ERROR_NO_HANDLES); - OS.pango_layout_set_font_description(layout, device.systemFont.handle); - OS.pango_layout_set_wrap(layout, OS.PANGO_WRAP_WORD_CHAR); - OS.pango_layout_set_tabs(layout, device.emptyTab); - if (OS.GTK_VERSION >= OS.VERSION(2, 4, 0)) { - OS.pango_layout_set_auto_dir(layout, false); - } - text = ""; - ascent = descent = -1; - styles = new StyleItem[2]; - styles[0] = new StyleItem(); - styles[1] = new StyleItem(); - init(); -} - -void checkLayout() { - if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); -} - -void computeRuns () { - if (attrList != 0) return; - String segmentsText = getSegmentsText(); - byte[] buffer = Converter.wcsToMbcs(null, segmentsText, false); - OS.pango_layout_set_text (layout, buffer, buffer.length); - if (styles.length == 2 && styles[0].style == null && ascent == -1 && descent == -1 && segments == null) return; - int /*long*/ ptr = OS.pango_layout_get_text(layout); - attrList = OS.pango_attr_list_new(); - PangoAttribute attribute = new PangoAttribute(); - char[] chars = null; - int segementsLength = segmentsText.length(); - if ((ascent != -1 || descent != -1) && segementsLength > 0) { - PangoRectangle rect = new PangoRectangle(); - if (ascent != -1) rect.y = -(ascent * OS.PANGO_SCALE); - rect.height = (Math.max(0, ascent) + Math.max(0, descent)) * OS.PANGO_SCALE; - int lineCount = OS.pango_layout_get_line_count(layout); - chars = new char[segementsLength + lineCount * 2]; - int oldPos = 0, lineIndex = 0; - PangoLayoutLine line = new PangoLayoutLine(); - while (lineIndex < lineCount) { - int /*long*/ linePtr = OS.pango_layout_get_line(layout, lineIndex); - OS.memmove(line, linePtr, PangoLayoutLine.sizeof); - int bytePos = line.start_index; - /* Note: The length in bytes of ZWS and ZWNBS are both equals to 3 */ - int offset = lineIndex * 6; - int /*long*/ attr = OS.pango_attr_shape_new (rect, rect); - OS.memmove (attribute, attr, PangoAttribute.sizeof); - attribute.start_index = bytePos + offset; - attribute.end_index = bytePos + offset + 3; - OS.memmove (attr, attribute, PangoAttribute.sizeof); - OS.pango_attr_list_insert(attrList, attr); - attr = OS.pango_attr_shape_new (rect, rect); - OS.memmove (attribute, attr, PangoAttribute.sizeof); - attribute.start_index = bytePos + offset + 3; - attribute.end_index = bytePos + offset + 6; - OS.memmove (attr, attribute, PangoAttribute.sizeof); - OS.pango_attr_list_insert(attrList, attr); - int pos = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + bytePos); - chars[pos + lineIndex * 2] = ZWS; - chars[pos + lineIndex * 2 + 1] = ZWNBS; - segmentsText.getChars(oldPos, pos, chars, oldPos + lineIndex * 2); - oldPos = pos; - lineIndex++; - } - segmentsText.getChars(oldPos, segementsLength, chars, oldPos + lineIndex * 2); - buffer = Converter.wcsToMbcs(null, chars, false); - OS.pango_layout_set_text (layout, buffer, buffer.length); - ptr = OS.pango_layout_get_text(layout); - } else { - chars = new char[segementsLength]; - segmentsText.getChars(0, segementsLength, chars, 0); - } - int offsetCount = 0; - for (int i = 0; i < chars.length; i++) { - char c = chars[i]; - if (c == LTR_MARK || c == RTL_MARK || c == ZWNBS || c == ZWS) { - offsetCount++; - } - } - invalidOffsets = new int[offsetCount]; - offsetCount = 0; - for (int i = 0; i < chars.length; i++) { - char c = chars[i]; - if (c == LTR_MARK || c == RTL_MARK || c == ZWNBS || c == ZWS) { - invalidOffsets[offsetCount++] = i; - } - } - int strlen = OS.strlen(ptr); - Font defaultFont = font != null ? font : device.systemFont; - for (int i = 0; i < styles.length - 1; i++) { - StyleItem styleItem = styles[i]; - TextStyle style = styleItem.style; - if (style == null) continue; - int start = translateOffset(styleItem.start); - int end = translateOffset(styles[i+1].start - 1); - int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, start) - ptr); - int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, end + 1) - ptr); - byteStart = Math.min(byteStart, strlen); - byteEnd = Math.min(byteEnd, strlen); - Font font = style.font; - if (font != null && !font.isDisposed() && !defaultFont.equals(font)) { - int /*long*/ attr = OS.pango_attr_font_desc_new (font.handle); - OS.memmove (attribute, attr, PangoAttribute.sizeof); - attribute.start_index = byteStart; - attribute.end_index = byteEnd; - OS.memmove (attr, attribute, PangoAttribute.sizeof); - OS.pango_attr_list_insert(attrList, attr); - } - if (style.underline) { - int underlineStyle = OS.PANGO_UNDERLINE_NONE; - switch (style.underlineStyle) { - case SWT.UNDERLINE_SINGLE: - underlineStyle = OS.PANGO_UNDERLINE_SINGLE; - break; - case SWT.UNDERLINE_DOUBLE: - underlineStyle = OS.PANGO_UNDERLINE_DOUBLE; - break; - case SWT.UNDERLINE_SQUIGGLE: - case SWT.UNDERLINE_ERROR: - if (OS.GTK_VERSION >= OS.VERSION(2, 4, 0)) { - underlineStyle = OS.PANGO_UNDERLINE_ERROR; - } - break; - case SWT.UNDERLINE_LINK: { - if (style.foreground == null) { - int /*long*/ attr = OS.pango_attr_foreground_new((short)0, (short)0x3333, (short)0x9999); - OS.memmove (attribute, attr, PangoAttribute.sizeof); - attribute.start_index = byteStart; - attribute.end_index = byteEnd; - OS.memmove (attr, attribute, PangoAttribute.sizeof); - OS.pango_attr_list_insert(attrList, attr); - } - if (style.underlineColor == null) { - underlineStyle = OS.PANGO_UNDERLINE_SINGLE; - } - break; - } - } - if (underlineStyle != OS.PANGO_UNDERLINE_NONE && style.underlineColor == null) { - int /*long*/ attr = OS.pango_attr_underline_new(underlineStyle); - OS.memmove(attribute, attr, PangoAttribute.sizeof); - attribute.start_index = byteStart; - attribute.end_index = byteEnd; - OS.memmove(attr, attribute, PangoAttribute.sizeof); - OS.pango_attr_list_insert(attrList, attr); - } - } - if (style.strikeout && style.strikeoutColor == null) { - int /*long*/ attr = OS.pango_attr_strikethrough_new(true); - OS.memmove(attribute, attr, PangoAttribute.sizeof); - attribute.start_index = byteStart; - attribute.end_index = byteEnd; - OS.memmove(attr, attribute, PangoAttribute.sizeof); - OS.pango_attr_list_insert(attrList, attr); - } - Color foreground = style.foreground; - if (foreground != null && !foreground.isDisposed()) { - GdkColor fg = foreground.handle; - int /*long*/ attr = OS.pango_attr_foreground_new(fg.red, fg.green, fg.blue); - OS.memmove (attribute, attr, PangoAttribute.sizeof); - attribute.start_index = byteStart; - attribute.end_index = byteEnd; - OS.memmove (attr, attribute, PangoAttribute.sizeof); - OS.pango_attr_list_insert(attrList, attr); - } - Color background = style.background; - if (background != null && !background.isDisposed()) { - GdkColor bg = background.handle; - int /*long*/ attr = OS.pango_attr_background_new(bg.red, bg.green, bg.blue); - OS.memmove (attribute, attr, PangoAttribute.sizeof); - attribute.start_index = byteStart; - attribute.end_index = byteEnd; - OS.memmove (attr, attribute, PangoAttribute.sizeof); - OS.pango_attr_list_insert(attrList, attr); - } - GlyphMetrics metrics = style.metrics; - if (metrics != null) { - PangoRectangle rect = new PangoRectangle(); - rect.y = -(metrics.ascent * OS.PANGO_SCALE); - rect.height = (metrics.ascent + metrics.descent) * OS.PANGO_SCALE; - rect.width = metrics.width * OS.PANGO_SCALE; - int /*long*/ attr = OS.pango_attr_shape_new (rect, rect); - OS.memmove (attribute, attr, PangoAttribute.sizeof); - attribute.start_index = byteStart; - attribute.end_index = byteEnd; - OS.memmove (attr, attribute, PangoAttribute.sizeof); - OS.pango_attr_list_insert(attrList, attr); - } - int rise = style.rise; - if (rise != 0) { - int /*long*/ attr = OS.pango_attr_rise_new (rise * OS.PANGO_SCALE); - OS.memmove (attribute, attr, PangoAttribute.sizeof); - attribute.start_index = byteStart; - attribute.end_index = byteEnd; - OS.memmove (attr, attribute, PangoAttribute.sizeof); - OS.pango_attr_list_insert(attrList, attr); - } - } - OS.pango_layout_set_attributes(layout, attrList); -} - -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 = Compatibility.ceil(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] = left + (width * peaks); - coordinates[length-1] = bottom; - return coordinates; -} - -void destroy() { - font = null; - text = null; - styles = null; - freeRuns(); - if (layout != 0) OS.g_object_unref(layout); - layout = 0; - if (context != 0) OS.g_object_unref(context); - context = 0; -} - -/** - * 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(); - boolean hasSelection = selectionStart <= selectionEnd && selectionStart != -1 && selectionEnd != -1; - GCData data = gc.data; - int /*long*/ cairo = data.cairo; - if (flags != 0 && (hasSelection || (flags & SWT.LAST_LINE_SELECTION) != 0)) { - int /*long*/[] attrs = new int /*long*/[1]; - int[] nAttrs = new int[1]; - PangoLogAttr logAttr = new PangoLogAttr(); - PangoRectangle rect = new PangoRectangle(); - int lineCount = OS.pango_layout_get_line_count(layout); - int /*long*/ ptr = OS.pango_layout_get_text(layout); - int /*long*/ iter = OS.pango_layout_get_iter(layout); - if (selectionBackground == null) selectionBackground = device.getSystemColor(SWT.COLOR_LIST_SELECTION); - if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) { - Cairo.cairo_save(cairo); - GdkColor color = selectionBackground.handle; - 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); - } else { - OS.gdk_gc_set_foreground(gc.handle, selectionBackground.handle); - } - int lineIndex = 0; - do { - int lineEnd; - OS.pango_layout_iter_get_line_extents(iter, null, rect); - if (OS.pango_layout_iter_next_line(iter)) { - int bytePos = OS.pango_layout_iter_get_index(iter); - lineEnd = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + bytePos); - } else { - lineEnd = (int)/*64*/OS.g_utf8_strlen(ptr, -1); - } - boolean extent = false; - if (lineIndex == lineCount - 1 && (flags & SWT.LAST_LINE_SELECTION) != 0) { - extent = true; - } else { - if (attrs[0] == 0) OS.pango_layout_get_log_attrs(layout, attrs, nAttrs); - OS.memmove(logAttr, attrs[0] + lineEnd * PangoLogAttr.sizeof, PangoLogAttr.sizeof); - if (!logAttr.is_line_break) { - if (selectionStart <= lineEnd && lineEnd <= selectionEnd) extent = true; - } else { - if (selectionStart <= lineEnd && lineEnd < selectionEnd && (flags & SWT.FULL_SELECTION) != 0) { - extent = true; - } - } - } - if (extent) { - int lineX = x + OS.PANGO_PIXELS(rect.x) + OS.PANGO_PIXELS(rect.width); - int lineY = y + OS.PANGO_PIXELS(rect.y); - int height = OS.PANGO_PIXELS(rect.height); - if (ascent != -1 && descent != -1) { - height = Math.max (height, ascent + descent); - } - int width = (flags & SWT.FULL_SELECTION) != 0 ? 0x7fffffff : height / 3; - if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) { - Cairo.cairo_rectangle(cairo, lineX, lineY, width, height); - Cairo.cairo_fill(cairo); - } else { - OS.gdk_draw_rectangle(data.drawable, gc.handle, 1, lineX, lineY, width, height); - } - } - lineIndex++; - } while (lineIndex < lineCount); - OS.pango_layout_iter_free(iter); - if (attrs[0] != 0) OS.g_free(attrs[0]); - if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) { - Cairo.cairo_restore(cairo); - } else { - OS.gdk_gc_set_foreground(gc.handle, data.foreground); - } - } - if (length == 0) return; - if (!hasSelection) { - if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) { - if ((data.style & SWT.MIRRORED) != 0) { - Cairo.cairo_save(cairo); - Cairo.cairo_scale(cairo, -1, 1); - Cairo.cairo_translate(cairo, -2 * x - width(), 0); - } - Cairo.cairo_move_to(cairo, x, y); - OS.pango_cairo_show_layout(cairo, layout); - drawBorder(gc, x, y, null); - if ((data.style & SWT.MIRRORED) != 0) { - Cairo.cairo_restore(cairo); - } - } else { - OS.gdk_draw_layout(data.drawable, gc.handle, x, y, layout); - drawBorder(gc, x, y, null); - } - } else { - selectionStart = Math.min(Math.max(0, selectionStart), length - 1); - selectionEnd = Math.min(Math.max(0, selectionEnd), length - 1); - length = (int)/*64*/OS.g_utf8_strlen(OS.pango_layout_get_text(layout), -1); - selectionStart = translateOffset(selectionStart); - selectionEnd = translateOffset(selectionEnd); - if (selectionForeground == null) selectionForeground = device.getSystemColor(SWT.COLOR_LIST_SELECTION_TEXT); - if (selectionBackground == null) selectionBackground = device.getSystemColor(SWT.COLOR_LIST_SELECTION); - boolean fullSelection = selectionStart == 0 && selectionEnd == length - 1; - if (fullSelection) { - if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) { - int /*long*/ ptr = OS.pango_layout_get_text(layout); - if ((data.style & SWT.MIRRORED) != 0) { - Cairo.cairo_save(cairo); - Cairo.cairo_scale(cairo, -1, 1); - Cairo.cairo_translate(cairo, -2 * x - width(), 0); - } - drawWithCairo(gc, x, y, 0, OS.strlen(ptr), fullSelection, selectionForeground.handle, selectionBackground.handle); - if ((data.style & SWT.MIRRORED) != 0) { - Cairo.cairo_restore(cairo); - } - } else { - OS.gdk_draw_layout_with_colors(data.drawable, gc.handle, x, y, layout, selectionForeground.handle, selectionBackground.handle); - drawBorder(gc, x, y, selectionForeground.handle); - } - } else { - int /*long*/ ptr = OS.pango_layout_get_text(layout); - int byteSelStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, selectionStart) - ptr); - int byteSelEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, selectionEnd + 1) - ptr); - int strlen = OS.strlen(ptr); - byteSelStart = Math.min(byteSelStart, strlen); - byteSelEnd = Math.min(byteSelEnd, strlen); - if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) { - if ((data.style & SWT.MIRRORED) != 0) { - Cairo.cairo_save(cairo); - Cairo.cairo_scale(cairo, -1, 1); - Cairo.cairo_translate(cairo, -2 * x - width(), 0); - } - drawWithCairo(gc, x, y, byteSelStart, byteSelEnd, fullSelection, selectionForeground.handle, selectionBackground.handle); - if ((data.style & SWT.MIRRORED) != 0) { - Cairo.cairo_restore(cairo); - } - } else { - Region clipping = new Region(); - gc.getClipping(clipping); - OS.gdk_draw_layout(data.drawable, gc.handle, x, y, layout); - drawBorder(gc, x, y, null); - int[] ranges = new int[]{byteSelStart, byteSelEnd}; - int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2); - if (rgn != 0) { - OS.gdk_gc_set_clip_region(gc.handle, rgn); - OS.gdk_region_destroy(rgn); - } - OS.gdk_draw_layout_with_colors(data.drawable, gc.handle, x, y, layout, selectionForeground.handle, selectionBackground.handle); - drawBorder(gc, x, y, selectionForeground.handle); - gc.setClipping(clipping); - clipping.dispose(); - } - } - } -} - -void drawWithCairo(GC gc, int x, int y, int start, int end, boolean fullSelection, GdkColor fg, GdkColor bg) { - GCData data = gc.data; - int /*long*/ cairo = data.cairo; - Cairo.cairo_save(cairo); - if (!fullSelection) { - Cairo.cairo_move_to(cairo, x, y); - OS.pango_cairo_show_layout(cairo, layout); - drawBorder(gc, x, y, null); - } - int[] ranges = new int[]{start, end}; - int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2); - if (rgn != 0) { - OS.gdk_cairo_region(cairo, rgn); - Cairo.cairo_clip(cairo); - Cairo.cairo_set_source_rgba(cairo, (bg.red & 0xFFFF) / (float)0xFFFF, (bg.green & 0xFFFF) / (float)0xFFFF, (bg.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF); - Cairo.cairo_paint(cairo); - OS.gdk_region_destroy(rgn); - } - Cairo.cairo_set_source_rgba(cairo, (fg.red & 0xFFFF) / (float)0xFFFF, (fg.green & 0xFFFF) / (float)0xFFFF, (fg.blue & 0xFFFF) / (float)0xFFFF, data.alpha / (float)0xFF); - Cairo.cairo_move_to(cairo, x, y); - OS.pango_cairo_show_layout(cairo, layout); - drawBorder(gc, x, y, fg); - Cairo.cairo_restore(cairo); -} - -void drawBorder(GC gc, int x, int y, GdkColor selectionColor) { - GCData data = gc.data; - int /*long*/ cairo = data.cairo; - int /*long*/ gdkGC = gc.handle; - int /*long*/ ptr = OS.pango_layout_get_text(layout); - GdkGCValues gcValues = null; - if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) { - Cairo.cairo_save(cairo); - } - for (int i = 0; i < styles.length - 1; i++) { - TextStyle style = styles[i].style; - if (style == null) continue; - - boolean drawBorder = style.borderStyle != SWT.NONE; - if (drawBorder && !style.isAdherentBorder(styles[i+1].style)) { - int start = styles[i].start; - for (int j = i; j > 0 && style.isAdherentBorder(styles[j-1].style); j--) { - start = styles[j - 1].start; - } - start = translateOffset(start); - int end = translateOffset(styles[i+1].start - 1); - int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, start) - ptr); - int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, end + 1) - ptr); - int[] ranges = new int[]{byteStart, byteEnd}; - int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2); - if (rgn != 0) { - int[] nRects = new int[1]; - int /*long*/[] rects = new int /*long*/[1]; - OS.gdk_region_get_rectangles(rgn, rects, nRects); - GdkRectangle rect = new GdkRectangle(); - GdkColor color = null; - if (color == null && style.borderColor != null) color = style.borderColor.handle; - if (color == null && selectionColor != null) color = selectionColor; - if (color == null && style.foreground != null) color = style.foreground.handle; - if (color == null) color = data.foreground; - int width = 1; - float[] dashes = null; - switch (style.borderStyle) { - case SWT.BORDER_SOLID: break; - case SWT.BORDER_DASH: dashes = width != 0 ? GC.LINE_DASH : GC.LINE_DASH_ZERO; break; - case SWT.BORDER_DOT: dashes = width != 0 ? GC.LINE_DOT : GC.LINE_DOT_ZERO; break; - } - if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) { - 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_set_line_width(cairo, width); - if (dashes != null) { - double[] cairoDashes = new double[dashes.length]; - for (int j = 0; j < cairoDashes.length; j++) { - cairoDashes[j] = width == 0 || data.lineStyle == SWT.LINE_CUSTOM ? dashes[j] : dashes[j] * width; - } - Cairo.cairo_set_dash(cairo, cairoDashes, cairoDashes.length, 0); - } else { - Cairo.cairo_set_dash(cairo, null, 0, 0); - } - for (int j=0; j<nRects[0]; j++) { - OS.memmove(rect, rects[0] + (j * GdkRectangle.sizeof), GdkRectangle.sizeof); - Cairo.cairo_rectangle(cairo, rect.x + 0.5, rect.y + 0.5, rect.width - 1, rect.height - 1); - } - Cairo.cairo_stroke(cairo); - } else { - if (gcValues == null) { - gcValues = new GdkGCValues(); - OS.gdk_gc_get_values(gdkGC, gcValues); - } - OS.gdk_gc_set_foreground(gdkGC, color); - int cap_style = OS.GDK_CAP_BUTT; - int join_style = OS.GDK_JOIN_MITER; - int line_style = 0; - if (dashes != null) { - byte[] dash_list = new byte[dashes.length]; - for (int j = 0; j < dash_list.length; j++) { - dash_list[j] = (byte)(width == 0 || data.lineStyle == SWT.LINE_CUSTOM ? dashes[j] : dashes[j] * width); - } - OS.gdk_gc_set_dashes(gdkGC, 0, dash_list, dash_list.length); - line_style = OS.GDK_LINE_ON_OFF_DASH; - } else { - line_style = OS.GDK_LINE_SOLID; - } - OS.gdk_gc_set_line_attributes(gdkGC, width, line_style, cap_style, join_style); - for (int j=0; j<nRects[0]; j++) { - OS.memmove(rect, rects[0] + (j * GdkRectangle.sizeof), GdkRectangle.sizeof); - OS.gdk_draw_rectangle(data.drawable, gdkGC, 0, rect.x, rect.y, rect.width - 1, rect.height - 1); - } - } - if (rects[0] != 0) OS.g_free(rects[0]); - OS.gdk_region_destroy(rgn); - } - } - - boolean drawUnderline = false; - if (style.underline && style.underlineColor != null) drawUnderline = true; - if (style.underline && (style.underlineStyle == SWT.UNDERLINE_ERROR || style.underlineStyle == SWT.UNDERLINE_SQUIGGLE)&& OS.GTK_VERSION < OS.VERSION(2, 4, 0)) drawUnderline = true; - if (drawUnderline && !style.isAdherentUnderline(styles[i+1].style)) { - int start = styles[i].start; - for (int j = i; j > 0 && style.isAdherentUnderline(styles[j-1].style); j--) { - start = styles[j - 1].start; - } - start = translateOffset(start); - int end = translateOffset(styles[i+1].start - 1); - int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, start) - ptr); - int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, end + 1) - ptr); - int[] ranges = new int[]{byteStart, byteEnd}; - int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2); - if (rgn != 0) { - int[] nRects = new int[1]; - int /*long*/[] rects = new int /*long*/[1]; - OS.gdk_region_get_rectangles(rgn, rects, nRects); - GdkRectangle rect = new GdkRectangle(); - GdkColor color = null; - if (color == null && style.underlineColor != null) color = style.underlineColor.handle; - if (color == null && selectionColor != null) color = selectionColor; - if (color == null && style.foreground != null) color = style.foreground.handle; - if (color == null) color = data.foreground; - if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) { - 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); - } else { - if (gcValues == null) { - gcValues = new GdkGCValues(); - OS.gdk_gc_get_values(gdkGC, gcValues); - } - OS.gdk_gc_set_foreground(gdkGC, color); - } - int underlinePosition = -1; - int underlineThickness = 1; - if (OS.GTK_VERSION >= OS.VERSION(2, 6, 0)) { - Font font = style.font; - if (font == null) font = this.font; - if (font == null) font = device.systemFont; - int /*long*/ lang = OS.pango_context_get_language(context); - int /*long*/ metrics = OS.pango_context_get_metrics(context, font.handle, lang); - underlinePosition = OS.PANGO_PIXELS(OS.pango_font_metrics_get_underline_position(metrics)); - underlineThickness = OS.PANGO_PIXELS(OS.pango_font_metrics_get_underline_thickness(metrics)); - OS.pango_font_metrics_unref(metrics); - } - for (int j=0; j<nRects[0]; j++) { - OS.memmove(rect, rects[0] + (j * GdkRectangle.sizeof), GdkRectangle.sizeof); - int offset = getOffset(rect.x - x, rect.y - y, null); - int lineIndex = getLineIndex(offset); - FontMetrics metrics = getLineMetrics(lineIndex); - int underlineY = rect.y + metrics.ascent - underlinePosition - style.rise; - switch (style.underlineStyle) { - case SWT.UNDERLINE_SQUIGGLE: - case SWT.UNDERLINE_ERROR: { - int squigglyThickness = underlineThickness; - int squigglyHeight = 2 * squigglyThickness; - int squigglyY = Math.min(underlineY, rect.y + rect.height - squigglyHeight - 1); - int[] points = computePolyline(rect.x, squigglyY, rect.x + rect.width, squigglyY + squigglyHeight); - if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) { - Cairo.cairo_set_line_width(cairo, squigglyThickness); - Cairo.cairo_set_line_cap(cairo, Cairo.CAIRO_LINE_CAP_BUTT); - Cairo.cairo_set_line_join(cairo, Cairo.CAIRO_LINE_JOIN_MITER); - if (points.length > 0) { - double xOffset = 0.5, yOffset = 0.5; - Cairo.cairo_move_to(cairo, points[0] + xOffset, points[1] + yOffset); - for (int k = 2; k < points.length; k += 2) { - Cairo.cairo_line_to(cairo, points[k] + xOffset, points[k + 1] + yOffset); - } - Cairo.cairo_stroke(cairo); - } - } else { - OS.gdk_gc_set_line_attributes(gdkGC, squigglyThickness, OS.GDK_LINE_SOLID, OS.GDK_CAP_BUTT, OS.GDK_JOIN_MITER); - OS.gdk_draw_lines(data.drawable, gdkGC, points, points.length / 2); - } - break; - } - case SWT.UNDERLINE_DOUBLE: - if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) { - Cairo.cairo_rectangle(cairo, rect.x, underlineY + underlineThickness * 2, rect.width, underlineThickness); - Cairo.cairo_fill(cairo); - } else { - OS.gdk_draw_rectangle(data.drawable, gdkGC, 1, rect.x, underlineY + underlineThickness * 2, rect.width, underlineThickness); - } - //FALLTHROUGH - case SWT.UNDERLINE_LINK: - case SWT.UNDERLINE_SINGLE: - if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) { - Cairo.cairo_rectangle(cairo, rect.x, underlineY, rect.width, underlineThickness); - Cairo.cairo_fill(cairo); - } else { - OS.gdk_draw_rectangle(data.drawable, gdkGC, 1, rect.x, underlineY, rect.width, underlineThickness); - } - break; - } - } - if (rects[0] != 0) OS.g_free(rects[0]); - OS.gdk_region_destroy(rgn); - } - } - - boolean drawStrikeout = false; - if (style.strikeout && style.strikeoutColor != null) drawStrikeout = true; - if (drawStrikeout && !style.isAdherentStrikeout(styles[i+1].style)) { - int start = styles[i].start; - for (int j = i; j > 0 && style.isAdherentStrikeout(styles[j-1].style); j--) { - start = styles[j - 1].start; - } - start = translateOffset(start); - int end = translateOffset(styles[i+1].start - 1); - int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, start) - ptr); - int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, end + 1) - ptr); - int[] ranges = new int[]{byteStart, byteEnd}; - int /*long*/ rgn = OS.gdk_pango_layout_get_clip_region(layout, x, y, ranges, ranges.length / 2); - if (rgn != 0) { - int[] nRects = new int[1]; - int /*long*/[] rects = new int /*long*/[1]; - OS.gdk_region_get_rectangles(rgn, rects, nRects); - GdkRectangle rect = new GdkRectangle(); - GdkColor color = null; - if (color == null && style.strikeoutColor != null) color = style.strikeoutColor.handle; - if (color == null && selectionColor != null) color = selectionColor; - if (color == null && style.foreground != null) color = style.foreground.handle; - if (color == null) color = data.foreground; - if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) { - 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); - } else { - if (gcValues == null) { - gcValues = new GdkGCValues(); - OS.gdk_gc_get_values(gdkGC, gcValues); - } - OS.gdk_gc_set_foreground(gdkGC, color); - } - int strikeoutPosition = -1; - int strikeoutThickness = 1; - if (OS.GTK_VERSION >= OS.VERSION(2, 6, 0)) { - Font font = style.font; - if (font == null) font = this.font; - if (font == null) font = device.systemFont; - int /*long*/ lang = OS.pango_context_get_language(context); - int /*long*/ metrics = OS.pango_context_get_metrics(context, font.handle, lang); - strikeoutPosition = OS.PANGO_PIXELS(OS.pango_font_metrics_get_strikethrough_position(metrics)); - strikeoutThickness = OS.PANGO_PIXELS(OS.pango_font_metrics_get_strikethrough_thickness(metrics)); - OS.pango_font_metrics_unref(metrics); - } - for (int j=0; j<nRects[0]; j++) { - OS.memmove(rect, rects[0] + (j * GdkRectangle.sizeof), GdkRectangle.sizeof); - int strikeoutY = rect.y + rect.height / 2 - style.rise; - if (OS.GTK_VERSION >= OS.VERSION(2, 6, 0)) { - int offset = getOffset(rect.x - x, rect.y - y, null); - int lineIndex = getLineIndex(offset); - FontMetrics metrics = getLineMetrics(lineIndex); - strikeoutY = rect.y + metrics.ascent - strikeoutPosition - style.rise; - } - if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) { - Cairo.cairo_rectangle(cairo, rect.x, strikeoutY, rect.width, strikeoutThickness); - Cairo.cairo_fill(cairo); - } else { - OS.gdk_draw_rectangle(data.drawable, gdkGC, 1, rect.x, strikeoutY, rect.width, strikeoutThickness); - } - } - if (rects[0] != 0) OS.g_free(rects[0]); - OS.gdk_region_destroy(rgn); - } - } - } - if (gcValues != null) { - int mask = OS.GDK_GC_FOREGROUND | OS.GDK_GC_LINE_WIDTH | OS.GDK_GC_LINE_STYLE | OS.GDK_GC_CAP_STYLE | OS.GDK_GC_JOIN_STYLE; - OS.gdk_gc_set_values(gdkGC, gcValues, mask); - data.state &= ~GC.LINE_STYLE; - } - if (cairo != 0 && OS.GTK_VERSION >= OS.VERSION(2, 8, 0)) { - Cairo.cairo_restore(cairo); - } -} - -void freeRuns() { - if (attrList == 0) return; - OS.pango_layout_set_attributes(layout, 0); - OS.pango_attr_list_unref(attrList); - attrList = 0; - invalidOffsets = 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(); - int align = OS.pango_layout_get_alignment(layout); - boolean rtl = OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL; - switch (align) { - case OS.PANGO_ALIGN_LEFT: return rtl ? SWT.RIGHT : SWT.LEFT; - case OS.PANGO_ALIGN_RIGHT: return rtl ? SWT.LEFT : SWT.RIGHT; - } - return SWT.CENTER; -} - -/** - * 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[] w = new int[1], h = new int[1]; - OS.pango_layout_get_size(layout, w, h); - int wrapWidth = OS.pango_layout_get_width(layout); - w[0] = wrapWidth != -1 ? wrapWidth : w[0] + OS.pango_layout_get_indent(layout); - int width = OS.PANGO_PIXELS(w[0]); - int height = OS.PANGO_PIXELS(h[0]); - if (ascent != -1 && descent != -1) { - height = Math.max (height, ascent + descent); - } - height += OS.PANGO_PIXELS(OS.pango_layout_get_spacing(layout)); - return new Rectangle(0, 0, width, height); -} - -/** - * 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); - start = translateOffset(start); - end = translateOffset(end); - int /*long*/ ptr = OS.pango_layout_get_text(layout); - int byteStart = (int)/*64*/(OS.g_utf8_offset_to_pointer (ptr, start) - ptr); - int byteEnd = (int)/*64*/(OS.g_utf8_offset_to_pointer (ptr, end + 1) - ptr); - int strlen = OS.strlen(ptr); - byteStart = Math.min(byteStart, strlen); - byteEnd = Math.min(byteEnd, strlen); - int[] ranges = new int[]{byteStart, byteEnd}; - int /*long*/ clipRegion = OS.gdk_pango_layout_get_clip_region(layout, 0, 0, ranges, 1); - if (clipRegion == 0) return new Rectangle(0, 0, 0, 0); - GdkRectangle rect = new GdkRectangle(); - - /* - * Bug in Pango. The region returned by gdk_pango_layout_get_clip_region() - * includes areas from lines outside of the requested range. The fix - * is to subtract these areas from the clip region. - */ - PangoRectangle pangoRect = new PangoRectangle(); - int /*long*/ iter = OS.pango_layout_get_iter(layout); - if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int /*long*/ linesRegion = OS.gdk_region_new(); - if (linesRegion == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int lineEnd = 0; - do { - OS.pango_layout_iter_get_line_extents(iter, null, pangoRect); - if (OS.pango_layout_iter_next_line(iter)) { - lineEnd = OS.pango_layout_iter_get_index(iter) - 1; - } else { - lineEnd = strlen; - } - if (byteStart > lineEnd) continue; - rect.x = OS.PANGO_PIXELS(pangoRect.x); - rect.y = OS.PANGO_PIXELS(pangoRect.y); - rect.width = OS.PANGO_PIXELS(pangoRect.width); - rect.height = OS.PANGO_PIXELS(pangoRect.height); - OS.gdk_region_union_with_rect(linesRegion, rect); - } while (lineEnd + 1 <= byteEnd); - OS.gdk_region_intersect(clipRegion, linesRegion); - OS.gdk_region_destroy(linesRegion); - OS.pango_layout_iter_free(iter); - - OS.gdk_region_get_clipbox(clipRegion, rect); - OS.gdk_region_destroy(clipRegion); - if (OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL) { - rect.x = width() - rect.x - rect.width; - } - return new Rectangle(rect.x, rect.y, rect.width, rect.height); -} - -/** - * 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; -} - -/** -* 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 OS.PANGO_PIXELS(OS.pango_layout_get_indent(layout)); -} - -/** -* 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 OS.pango_layout_get_justify(layout); -} - -/** - * 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(); - computeRuns(); - int length = text.length(); - if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE); - offset = translateOffset(offset); - int /*long*/ iter = OS.pango_layout_get_iter(layout); - if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES); - int level = 0; - PangoItem item = new PangoItem(); - PangoLayoutRun run = new PangoLayoutRun(); - int /*long*/ ptr = OS.pango_layout_get_text(layout); - int /*long*/ byteOffset = OS.g_utf8_offset_to_pointer(ptr, offset) - ptr; - int strlen = OS.strlen(ptr); - byteOffset = Math.min(byteOffset, strlen); - do { - int /*long*/ runPtr = OS.pango_layout_iter_get_run(iter); - if (runPtr != 0) { - OS.memmove(run, runPtr, PangoLayoutRun.sizeof); - OS.memmove(item, run.item, PangoItem.sizeof); - if (item.offset <= byteOffset && byteOffset < item.offset + item.length) { - level = item.analysis_level; - break; - } - } - } while (OS.pango_layout_iter_next_run(iter)); - OS.pango_layout_iter_free(iter); - return level; -} - -/** - * 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(); - int lineCount = OS.pango_layout_get_line_count(layout); - if (!(0 <= lineIndex && lineIndex < lineCount)) SWT.error(SWT.ERROR_INVALID_RANGE); - int /*long*/ iter = OS.pango_layout_get_iter(layout); - if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES); - for (int i = 0; i < lineIndex; i++) OS.pango_layout_iter_next_line(iter); - PangoRectangle rect = new PangoRectangle(); - OS.pango_layout_iter_get_line_extents(iter, null, rect); - OS.pango_layout_iter_free(iter); - int x = OS.PANGO_PIXELS(rect.x); - int y = OS.PANGO_PIXELS(rect.y); - int width = OS.PANGO_PIXELS(rect.width); - int height = OS.PANGO_PIXELS(rect.height); - if (ascent != -1 && descent != -1) { - height = Math.max (height, ascent + descent); - } - if (OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL) { - x = width() - x - width; - } - 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 OS.pango_layout_get_line_count(layout); -} - -/** - * 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_ARGUMENT); - offset = translateOffset(offset); - int line = 0; - int /*long*/ ptr = OS.pango_layout_get_text(layout); - int /*long*/ byteOffset = OS.g_utf8_offset_to_pointer(ptr,offset) - ptr; - int strlen = OS.strlen(ptr); - byteOffset = Math.min(byteOffset, strlen); - int /*long*/ iter = OS.pango_layout_get_iter(layout); - if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES); - while (OS.pango_layout_iter_next_line(iter)) { - if (OS.pango_layout_iter_get_index(iter) > byteOffset) break; - line++; - } - OS.pango_layout_iter_free(iter); - return line; -} - -/** - * 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(); - int lineCount = OS.pango_layout_get_line_count(layout); - if (!(0 <= lineIndex && lineIndex < lineCount)) SWT.error(SWT.ERROR_INVALID_RANGE); - int ascent = 0, descent = 0; - PangoLayoutLine line = new PangoLayoutLine(); - OS.memmove(line, OS.pango_layout_get_line(layout, lineIndex), PangoLayoutLine.sizeof); - if (line.runs == 0) { - int /*long*/ font = this.font != null ? this.font.handle : device.systemFont.handle; - int /*long*/ lang = OS.pango_context_get_language(context); - int /*long*/ metrics = OS.pango_context_get_metrics(context, font, lang); - ascent = OS.pango_font_metrics_get_ascent(metrics); - descent = OS.pango_font_metrics_get_descent(metrics); - OS.pango_font_metrics_unref(metrics); - } else { - PangoRectangle rect = new PangoRectangle(); - OS.pango_layout_line_get_extents(OS.pango_layout_get_line(layout, lineIndex), null, rect); - ascent = -rect.y; - descent = rect.height - ascent; - } - ascent = Math.max(this.ascent, OS.PANGO_PIXELS(ascent)); - descent = Math.max(this.descent, OS.PANGO_PIXELS(descent)); - return FontMetrics.gtk_new(ascent, descent, 0, 0, ascent + descent); -} - -/** - * 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 lineCount = OS.pango_layout_get_line_count(layout); - int[] offsets = new int [lineCount + 1]; - int /*long*/ ptr = OS.pango_layout_get_text(layout); - PangoLayoutLine line = new PangoLayoutLine(); - for (int i = 0; i < lineCount; i++) { - int /*long*/ linePtr = OS.pango_layout_get_line(layout, i); - OS.memmove(line, linePtr, PangoLayoutLine.sizeof); - int pos = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + line.start_index); - offsets[i] = untranslateOffset(pos); - } - offsets[lineCount] = text.length(); - return offsets; -} - -/** - * 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); - offset = translateOffset(offset); - int /*long*/ ptr = OS.pango_layout_get_text(layout); - int byteOffset = (int)/*64*/(OS.g_utf8_offset_to_pointer(ptr, offset) - ptr); - int strlen = OS.strlen(ptr); - byteOffset = Math.min(byteOffset, strlen); - PangoRectangle pos = new PangoRectangle(); - OS.pango_layout_index_to_pos(layout, byteOffset, pos); - int x = trailing ? pos.x + pos.width : pos.x; - int y = pos.y; - x = OS.PANGO_PIXELS(x); - if (OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL) { - x = width() - x; - } - return new Point(x, OS.PANGO_PIXELS(y)); -} - -/** - * 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) { - return _getOffset(offset, movement, true); -} - -int _getOffset (int offset, int movement, boolean forward) { - checkLayout(); - computeRuns(); - int length = text.length(); - if (!(0 <= offset && offset <= length)) SWT.error(SWT.ERROR_INVALID_RANGE); - if (forward) { - if (offset == length) return length; - } else { - if (offset == 0) return 0; - } - int step = forward ? 1 : -1; - if ((movement & SWT.MOVEMENT_CHAR) != 0) return offset + step; - int /*long*/[] attrs = new int /*long*/[1]; - int[] nAttrs = new int[1]; - OS.pango_layout_get_log_attrs(layout, attrs, nAttrs); - if (attrs[0] == 0) return offset + step; - length = (int)/*64*/OS.g_utf8_strlen(OS.pango_layout_get_text(layout), -1); - offset = translateOffset(offset); - PangoLogAttr logAttr = new PangoLogAttr(); - offset = validateOffset(offset, step); - while (0 < offset && offset < length) { - OS.memmove(logAttr, attrs[0] + offset * PangoLogAttr.sizeof, PangoLogAttr.sizeof); - if (((movement & SWT.MOVEMENT_CLUSTER) != 0) && logAttr.is_cursor_position) break; - if ((movement & SWT.MOVEMENT_WORD) != 0) { - if (forward) { - if (logAttr.is_word_end) break; - } else { - if (logAttr.is_word_start) break; - } - } - if ((movement & SWT.MOVEMENT_WORD_START) != 0) { - if (logAttr.is_word_start) break; - } - if ((movement & SWT.MOVEMENT_WORD_END) != 0) { - if (logAttr.is_word_end) break; - } - offset = validateOffset(offset, step); - } - OS.g_free(attrs[0]); - return Math.min(Math.max(0, untranslateOffset(offset)), text.length()); -} - -/** - * 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); - if (OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL) { - x = width() - x; - } - - /* - * Feature in GTK. pango_layout_xy_to_index() returns the - * logical end/start offset of a line when the coordinates are outside - * the line bounds. In SWT the correct behavior is to return the closest - * visual offset. The fix is to clamp the coordinates inside the - * line bounds. - */ - int /*long*/ iter = OS.pango_layout_get_iter(layout); - if (iter == 0) SWT.error(SWT.ERROR_NO_HANDLES); - PangoRectangle rect = new PangoRectangle(); - do { - OS.pango_layout_iter_get_line_extents(iter, null, rect); - rect.y = OS.PANGO_PIXELS(rect.y); - rect.height = OS.PANGO_PIXELS(rect.height); - if (rect.y <= y && y < rect.y + rect.height) { - rect.x = OS.PANGO_PIXELS(rect.x); - rect.width = OS.PANGO_PIXELS(rect.width); - if (x >= rect.x + rect.width) x = rect.x + rect.width - 1; - if (x < rect.x) x = rect.x; - break; - } - } while (OS.pango_layout_iter_next_line(iter)); - OS.pango_layout_iter_free(iter); - - int[] index = new int[1]; - int[] piTrailing = new int[1]; - OS.pango_layout_xy_to_index(layout, x * OS.PANGO_SCALE, y * OS.PANGO_SCALE, index, piTrailing); - int /*long*/ ptr = OS.pango_layout_get_text(layout); - int offset = (int)/*64*/OS.g_utf8_pointer_to_offset(ptr, ptr + index[0]); - if (trailing != null) trailing[0] = piTrailing[0]; - return untranslateOffset(offset); -} - -/** - * 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(); - int baseDir = OS.pango_context_get_base_dir(context); - return baseDir == OS.PANGO_DIRECTION_RTL ? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT; -} - -/** - * 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 index, int movement) { - return _getOffset(index, movement, false); -} - -/** - * 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; -} - -String getSegmentsText() { - if (segments == null) return text; - int nSegments = segments.length; - if (nSegments <= 1) return text; - int length = text.length(); - if (length == 0) return text; - if (nSegments == 2) { - if (segments[0] == 0 && segments[1] == length) return text; - } - char[] oldChars = new char[length]; - text.getChars(0, length, oldChars, 0); - char[] newChars = new char[length + nSegments]; - int charCount = 0, segmentCount = 0; - char separator = getOrientation() == SWT.RIGHT_TO_LEFT ? RTL_MARK : LTR_MARK; - while (charCount < length) { - if (segmentCount < nSegments && charCount == segments[segmentCount]) { - newChars[charCount + segmentCount++] = separator; - } else { - newChars[charCount + segmentCount] = oldChars[charCount++]; - } - } - if (segmentCount < nSegments) { - segments[segmentCount] = charCount; - newChars[charCount + segmentCount++] = separator; - } - return new String(newChars, 0, Math.min(charCount + segmentCount, newChars.length)); -} - -/** - * 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 OS.PANGO_PIXELS(OS.pango_layout_get_spacing(layout)); -} - -/** - * 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 (); - int width = OS.pango_layout_get_width(layout); - return width != -1 ? OS.PANGO_PIXELS(width) : -1; -} - -/** - * 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 layout == 0; -} - -/** - * 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; - boolean rtl = OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL; - int align = OS.PANGO_ALIGN_CENTER; - switch (alignment) { - case SWT.LEFT: - align = rtl ? OS.PANGO_ALIGN_RIGHT : OS.PANGO_ALIGN_LEFT; - break; - case SWT.RIGHT: - align = rtl ? OS.PANGO_ALIGN_LEFT : OS.PANGO_ALIGN_RIGHT; - break; - } - OS.pango_layout_set_alignment(layout, align); -} - -/** - * 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; - freeRuns(); - this.font = font; - if (oldFont != null && oldFont.equals(font)) return; - OS.pango_layout_set_font_description(layout, font != null ? font.handle : device.systemFont.handle); -} - -/** - * 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; - OS.pango_layout_set_indent(layout, indent * OS.PANGO_SCALE); -} - -/** - * 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(); - OS.pango_layout_set_justify(layout, 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; - int baseDir = orientation == SWT.RIGHT_TO_LEFT ? OS.PANGO_DIRECTION_RTL : OS.PANGO_DIRECTION_LTR; - if (OS.pango_context_get_base_dir(context) == baseDir) return; - OS.pango_context_set_base_dir(context, baseDir); - OS.pango_layout_context_changed(layout); - int align = OS.pango_layout_get_alignment(layout); - if (align != OS.PANGO_ALIGN_CENTER) { - align = align == OS.PANGO_ALIGN_LEFT ? OS.PANGO_ALIGN_RIGHT : OS.PANGO_ALIGN_LEFT; - OS.pango_layout_set_alignment(layout, align); - } -} - -/** - * 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); - OS.pango_layout_set_spacing(layout, spacing * OS.PANGO_SCALE); -} - -/** - * 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); - - /* - * Bug in Pango. Pango 1.2.2 will cause a segmentation fault if a style - * is not applied for a whole ligature. The fix is to applied the - * style for the whole ligature. - * - * NOTE that fix only LamAlef ligatures. - */ - if (start > 0 && isAlef(text.charAt(start)) && isLam(text.charAt(start - 1))) { - start--; - } - if (end < length - 1 && isLam(text.charAt(end)) && isAlef(text.charAt(end + 1))) { - end++; - } - - 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; - } - } - this.tabs = tabs; - if (tabs == null) { - OS.pango_layout_set_tabs(layout, device.emptyTab); - } else { - int /*long*/ tabArray = OS.pango_tab_array_new(tabs.length, true); - if (tabArray != 0) { - for (int i = 0; i < tabs.length; i++) { - OS.pango_tab_array_set_tab(tabArray, i, OS.PANGO_TAB_LEFT, tabs[i]); - } - OS.pango_layout_set_tabs(layout, tabArray); - OS.pango_tab_array_free(tabArray); - } - } - /* - * Bug in Pango. A change in the tab stop array is not automatically reflected in the - * pango layout object because the call pango_layout_set_tabs() does not free the - * lines cache. The fix to use pango_layout_context_changed() to free the lines cache. - */ - OS.pango_layout_context_changed(layout); -} - -/** - * 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[styles.length - 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); - freeRuns(); - if (width == -1) { - OS.pango_layout_set_width(layout, -1); - boolean rtl = OS.pango_context_get_base_dir(context) == OS.PANGO_DIRECTION_RTL; - OS.pango_layout_set_alignment(layout, rtl ? OS.PANGO_ALIGN_RIGHT : OS.PANGO_ALIGN_LEFT); - } else { - OS.pango_layout_set_width(layout, width * OS.PANGO_SCALE); - } -} - -static final boolean isLam(int ch) { - return ch == 0x0644; -} - -static final boolean isAlef(int ch) { - switch (ch) { - case 0x0622: - case 0x0623: - case 0x0625: - case 0x0627: - case 0x0649: - case 0x0670: - case 0x0671: - case 0x0672: - case 0x0673: - case 0x0675: - return true; - } - return false; -} - -/** - * 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 {" + layout + "}"; -} - -/* - * Translate a client offset to an internal offset - */ -int translateOffset(int offset) { - int length = text.length(); - if (length == 0) return offset; - if (invalidOffsets == null) return offset; - for (int i = 0; i < invalidOffsets.length; i++) { - if (offset < invalidOffsets[i]) break; - offset++; - } - return offset; -} - -/* - * Translate an internal offset to a client offset - */ -int untranslateOffset(int offset) { - int length = text.length(); - if (length == 0) return offset; - if (invalidOffsets == null) return offset; - for (int i = 0; i < invalidOffsets.length; i++) { - if (offset == invalidOffsets[i]) { - offset++; - continue; - } - if (offset < invalidOffsets[i]) { - return offset - i; - } - } - return offset - invalidOffsets.length; -} - -int validateOffset(int offset, int step) { - if (invalidOffsets == null) return offset + step; - int i = step > 0 ? 0 : invalidOffsets.length - 1; - do { - offset += step; - while (0 <= i && i < invalidOffsets.length) { - if (invalidOffsets[i] == offset) break; - i += step; - } - } while (0 <= i && i < invalidOffsets.length); - return offset; -} - -int width () { - int wrapWidth = OS.pango_layout_get_width(layout); - if (wrapWidth != -1) return OS.PANGO_PIXELS(wrapWidth); - int[] w = new int[1], h = new int[1]; - OS.pango_layout_get_size(layout, w, h); - return OS.PANGO_PIXELS(w[0] + OS.pango_layout_get_indent(layout)); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/Converter.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/Converter.java deleted file mode 100644 index 779baed6f8..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/internal/Converter.java +++ /dev/null @@ -1,72 +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.internal; - - -import org.eclipse.swt.internal.gtk.OS; - -/** - * 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 { - public static final byte [] NullByteArray = new byte [1]; - public static final byte [] EmptyByteArray = new byte [0]; - public static final char [] EmptyCharArray = new char [0]; - -/** - * Returns the default code page for the platform where the - * application is currently running. - * - * @return the default code page - */ -public static String defaultCodePage () { - return "UTF8"; -} - -public static char [] mbcsToWcs (String codePage, byte [] buffer) { - int /*long*/ [] items_written = new int /*long*/ [1]; - int /*long*/ ptr = OS.g_utf8_to_utf16 (buffer, buffer.length, null, items_written, null); - if (ptr == 0) return EmptyCharArray; - int length = (int)/*64*/items_written [0]; - char [] chars = new char [length]; - OS.memmove (chars, ptr, length * 2); - OS.g_free (ptr); - return chars; -} - -public static byte [] wcsToMbcs (String codePage, String string, boolean terminate) { - int length = string.length (); - char [] buffer = new char [length]; - string.getChars (0, length, buffer, 0); - return wcsToMbcs (codePage, buffer, terminate); -} - -public static byte [] wcsToMbcs (String codePage, char [] buffer, boolean terminate) { - int /*long*/ [] items_read = new int /*long*/ [1], items_written = new int /*long*/ [1]; - /* - * Note that g_utf16_to_utf8() stops converting - * when it finds the first NULL. - */ - int /*long*/ ptr = OS.g_utf16_to_utf8 (buffer, buffer.length, items_read, items_written, null); - if (ptr == 0) return terminate ? NullByteArray : EmptyByteArray; - int written = (int)/*64*/items_written [0]; - byte [] bytes = new byte [written + (terminate ? 1 : 0)]; - OS.memmove (bytes, ptr, written); - OS.g_free (ptr); - return bytes; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java deleted file mode 100644 index 41802dc836..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Button.java +++ /dev/null @@ -1,836 +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.gtk.*; -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 { - int /*long*/ boxHandle, labelHandle, imageHandle, arrowHandle, groupHandle; - boolean selected, grayed; - ImageList imageList; - Image image; - 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#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)); -} - -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; -} - -/** - * 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; - /* - * Feature in GTK, GtkCheckButton and GtkRadioButton allocate - * only the minimum size necessary for its child. This causes the child - * alignment to fail. The fix is to set the child size to the size - * of the button. - */ - forceResize (); - int [] reqWidth = null, reqHeight = null; - if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { - reqWidth = new int [1]; - reqHeight = new int [1]; - OS.gtk_widget_get_size_request (boxHandle, reqWidth, reqHeight); - OS.gtk_widget_set_size_request (boxHandle, -1, -1); - } - Point size = computeNativeSize (handle, wHint, hHint, changed); - if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { - OS.gtk_widget_set_size_request (boxHandle, reqWidth [0], reqHeight [0]); - } - if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) { - if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_CAN_DEFAULT) != 0) { - int /*long*/ [] buffer = new int /*long*/ [1]; - GtkBorder border = new GtkBorder (); - OS.gtk_widget_style_get (handle, OS.default_border, buffer, 0); - if (buffer[0] != 0) { - OS.memmove (border, buffer[0], GtkBorder.sizeof); - } else { - /* Use the GTK+ default value of 1 for each. */ - border.left = border.right = border.top = border.bottom = 1; - } - if (wHint != SWT.DEFAULT) size.x += border.left + border.right; - if (hHint != SWT.DEFAULT) size.y += border.top + border.bottom; - } - } - return size; -} - -void createHandle (int index) { - state |= HANDLE; - if ((style & (SWT.PUSH | SWT.TOGGLE)) == 0) state |= THEME_BACKGROUND; - int bits = SWT.ARROW | SWT.TOGGLE | SWT.CHECK | SWT.RADIO | SWT.PUSH; - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - switch (style & bits) { - case SWT.ARROW: - int arrow_type = OS.GTK_ARROW_UP; - if ((style & SWT.UP) != 0) arrow_type = OS.GTK_ARROW_UP; - if ((style & SWT.DOWN) != 0) arrow_type = OS.GTK_ARROW_DOWN; - if ((style & SWT.LEFT) != 0) arrow_type = OS.GTK_ARROW_LEFT; - if ((style & SWT.RIGHT) != 0) arrow_type = OS.GTK_ARROW_RIGHT; - handle = OS.gtk_button_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - arrowHandle = OS.gtk_arrow_new (arrow_type, OS.GTK_SHADOW_OUT); - if (arrowHandle == 0) error (SWT.ERROR_NO_HANDLES); - break; - case SWT.TOGGLE: - handle = OS.gtk_toggle_button_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - break; - case SWT.CHECK: - handle = OS.gtk_check_button_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - break; - case SWT.RADIO: - /* - * Feature in GTK. In GTK, radio button must always be part of - * a radio button group. In a GTK radio group, one button is always - * selected. This means that it is not possible to have a single - * radio button that is unselected. This is necessary to allow - * applications to implement their own radio behavior or use radio - * buttons outside of radio groups. The fix is to create a hidden - * radio button for each radio button we create and add them - * to the same group. This allows the visible button to be - * unselected. - */ - groupHandle = OS.gtk_radio_button_new (0); - if (groupHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.g_object_ref (groupHandle); - OS.gtk_object_sink (groupHandle); - handle = OS.gtk_radio_button_new (OS.gtk_radio_button_get_group (groupHandle)); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - break; - case SWT.PUSH: - default: - handle = OS.gtk_button_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.GTK_WIDGET_SET_FLAGS(handle, OS.GTK_CAN_DEFAULT); - break; - } - if ((style & SWT.ARROW) != 0) { - OS.gtk_container_add (handle, arrowHandle); - } else { - boxHandle = OS.gtk_hbox_new (false, 4); - if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES); - labelHandle = OS.gtk_label_new_with_mnemonic (null); - if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES); - imageHandle = OS.gtk_image_new (); - if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (handle, boxHandle); - OS.gtk_container_add (boxHandle, imageHandle); - OS.gtk_container_add (boxHandle, labelHandle); - } - OS.gtk_container_add (fixedHandle, handle); - - if ((style & SWT.ARROW) != 0) return; - _setAlignment (style & (SWT.LEFT | SWT.CENTER | SWT.RIGHT)); -} - -void createWidget (int index) { - super.createWidget (index); - text = ""; -} - -void deregister () { - super.deregister (); - if (boxHandle != 0) display.removeWidget (boxHandle); - if (labelHandle != 0) display.removeWidget (labelHandle); - if (imageHandle != 0) display.removeWidget (imageHandle); - if (arrowHandle != 0) display.removeWidget (arrowHandle); -} - -int /*long*/ fontHandle () { - if (labelHandle != 0) return labelHandle; - return super.fontHandle (); -} - -/** - * 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) { - if ((style & SWT.UP) != 0) return SWT.UP; - if ((style & SWT.DOWN) != 0) return SWT.DOWN; - if ((style & SWT.LEFT) != 0) return SWT.LEFT; - if ((style & SWT.RIGHT) != 0) return SWT.RIGHT; - return SWT.UP; - } - if ((style & SWT.LEFT) != 0) return SWT.LEFT; - if ((style & SWT.CENTER) != 0) return SWT.CENTER; - if ((style & SWT.RIGHT) != 0) return SWT.RIGHT; - return SWT.LEFT; -} - -/** - * 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; - return OS.gtk_toggle_button_get_active (handle); -} - -/** - * 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; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_button_press_event (widget, event); - if (result != 0) return result; - if ((style & SWT.RADIO) != 0) selected = getSelection (); - return result; -} - -int /*long*/ gtk_clicked (int /*long*/ widget) { - if ((style & SWT.RADIO) != 0) { - if ((parent.getStyle () & SWT.NO_RADIO_GROUP) != 0) { - setSelection (!selected); - } else { - selectRadio (); - } - } else { - if ((style & SWT.CHECK) != 0) { - if (grayed) { - if (OS.gtk_toggle_button_get_active (handle)) { - OS.gtk_toggle_button_set_inconsistent (handle, true); - } else { - OS.gtk_toggle_button_set_inconsistent (handle, false); - } - } - } - } - postEvent (SWT.Selection); - return 0; -} - -int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_focus_in_event (widget, event); - // widget could be disposed at this point - if (handle == 0) return 0; - if ((style & SWT.PUSH) != 0 && OS.GTK_WIDGET_HAS_DEFAULT (handle)) { - Decorations menuShell = menuShell (); - menuShell.defaultButton = this; - } - return result; -} - -int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_focus_out_event (widget, event); - // widget could be disposed at this point - if (handle == 0) return 0; - if ((style & SWT.PUSH) != 0 && !OS.GTK_WIDGET_HAS_DEFAULT (handle)) { - Decorations menuShell = menuShell (); - if (menuShell.defaultButton == this) { - menuShell.defaultButton = null; - } - } - return result; -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_key_press_event (widget, event); - if (result != 0) return result; - if ((style & SWT.RADIO) != 0) selected = getSelection (); - return result; -} - -void hookEvents () { - super.hookEvents(); - OS.g_signal_connect_closure (handle, OS.clicked, display.closures [CLICKED], false); - if (labelHandle != 0) { - OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false); - } -} - -boolean isDescribedByLabel () { - return false; -} - -boolean mnemonicHit (char key) { - if (labelHandle == 0) return false; - boolean result = super.mnemonicHit (labelHandle, key); - if (result) setFocus (); - return result; -} - -boolean mnemonicMatch (char key) { - if (labelHandle == 0) return false; - return mnemonicMatch (labelHandle, key); -} - -void register () { - super.register (); - if (boxHandle != 0) display.addWidget (boxHandle, this); - if (labelHandle != 0) display.addWidget (labelHandle, this); - if (imageHandle != 0) display.addWidget (imageHandle, this); - if (arrowHandle != 0) display.addWidget (arrowHandle, this); -} - -void releaseHandle () { - super.releaseHandle (); - boxHandle = imageHandle = labelHandle = arrowHandle = 0; -} - -void releaseWidget () { - super.releaseWidget (); - if (groupHandle != 0) OS.g_object_unref (groupHandle); - groupHandle = 0; - if (imageList != null) imageList.dispose (); - imageList = null; - image = 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); -} - -void resizeHandle (int width, int height) { - super.resizeHandle (width, height); - /* - * Feature in GTK, GtkCheckButton and GtkRadioButton allocate - * only the minimum size necessary for its child. This causes the child - * alignment to fail. The fix is to set the child size to the size - * of the button. - */ - if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { - OS.gtk_widget_set_size_request (boxHandle, width, -1); - } -} - -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 (); - _setAlignment (alignment); -} - -void _setAlignment (int alignment) { - if ((style & SWT.ARROW) != 0) { - if ((style & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT)) == 0) return; - style &= ~(SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT); - style |= alignment & (SWT.UP | SWT.DOWN | SWT.LEFT | SWT.RIGHT); - int arrow_type = OS.GTK_ARROW_UP; - boolean isRTL = (style & SWT.RIGHT_TO_LEFT) != 0; - switch (alignment) { - case SWT.UP: arrow_type = OS.GTK_ARROW_UP; break; - case SWT.DOWN: arrow_type = OS.GTK_ARROW_DOWN; break; - case SWT.LEFT: arrow_type = isRTL ? OS.GTK_ARROW_RIGHT : OS.GTK_ARROW_LEFT; break; - case SWT.RIGHT: arrow_type = isRTL ? OS.GTK_ARROW_LEFT : OS.GTK_ARROW_RIGHT; break; - } - OS.gtk_arrow_set (arrowHandle, arrow_type, OS.GTK_SHADOW_OUT); - return; - } - if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return; - style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER); - style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER); - /* Alignment not honoured when image and text are visible */ - boolean bothVisible = OS.GTK_WIDGET_VISIBLE (labelHandle) && OS.GTK_WIDGET_VISIBLE (imageHandle); - if (bothVisible) { - if ((style & (SWT.RADIO | SWT.CHECK)) != 0) alignment = SWT.LEFT; - if ((style & (SWT.PUSH | SWT.TOGGLE)) != 0) alignment = SWT.CENTER; - } - if ((alignment & SWT.LEFT) != 0) { - if (bothVisible) { - OS.gtk_box_set_child_packing (boxHandle, labelHandle, false, false, 0, OS.GTK_PACK_START); - OS.gtk_box_set_child_packing (boxHandle, imageHandle, false, false, 0, OS.GTK_PACK_START); - } - OS.gtk_misc_set_alignment (labelHandle, 0.0f, 0.5f); - OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_LEFT); - OS.gtk_misc_set_alignment (imageHandle, 0.0f, 0.5f); - return; - } - if ((alignment & SWT.CENTER) != 0) { - if (bothVisible) { - OS.gtk_box_set_child_packing (boxHandle, labelHandle, true, true, 0, OS.GTK_PACK_END); - OS.gtk_box_set_child_packing (boxHandle, imageHandle, true, true, 0, OS.GTK_PACK_START); - OS.gtk_misc_set_alignment (labelHandle, 0f, 0.5f); - OS.gtk_misc_set_alignment (imageHandle, 1f, 0.5f); - } else { - OS.gtk_misc_set_alignment (labelHandle, 0.5f, 0.5f); - OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_CENTER); - OS.gtk_misc_set_alignment (imageHandle, 0.5f, 0.5f); - } - return; - } - if ((alignment & SWT.RIGHT) != 0) { - if (bothVisible) { - OS.gtk_box_set_child_packing (boxHandle, labelHandle, false, false, 0, OS.GTK_PACK_END); - OS.gtk_box_set_child_packing (boxHandle, imageHandle, false, false, 0, OS.GTK_PACK_END); - } - OS.gtk_misc_set_alignment (labelHandle, 1.0f, 0.5f); - OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_RIGHT); - OS.gtk_misc_set_alignment (imageHandle, 1.0f, 0.5f); - return; - } -} - -void setBackgroundColor (GdkColor color) { - super.setBackgroundColor (color); - setBackgroundColor(fixedHandle, color); - if (labelHandle != 0) setBackgroundColor(labelHandle, color); - if (imageHandle != 0) setBackgroundColor(imageHandle, color); -} - -void setFontDescription (int /*long*/ font) { - super.setFontDescription (font); - if (labelHandle != 0) OS.gtk_widget_modify_font (labelHandle, font); - if (imageHandle != 0) OS.gtk_widget_modify_font (imageHandle, font); -} - -boolean setRadioSelection (boolean value) { - if ((style & SWT.RADIO) == 0) return false; - if (getSelection () != value) { - setSelection (value); - postEvent (SWT.Selection); - } - return true; -} - -void setForegroundColor (GdkColor color) { - super.setForegroundColor (color); - setForegroundColor (fixedHandle, color); - if (labelHandle != 0) setForegroundColor (labelHandle, color); - if (imageHandle != 0) setForegroundColor (imageHandle, color); -} - -/** - * 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; - if (grayed && OS.gtk_toggle_button_get_active (handle)) { - OS.gtk_toggle_button_set_inconsistent (handle, true); - } else { - OS.gtk_toggle_button_set_inconsistent (handle, false); - } -} - -/** - * 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 ((style & SWT.ARROW) != 0) return; - if (imageList != null) imageList.dispose (); - imageList = null; - if (image != null) { - if (image.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - imageList = new ImageList (); - int imageIndex = imageList.add (image); - int /*long*/ pixbuf = imageList.getPixbuf (imageIndex); - OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); - if (text.length () == 0) OS.gtk_widget_hide (labelHandle); - OS.gtk_widget_show (imageHandle); - } else { - OS.gtk_image_set_from_pixbuf (imageHandle, 0); - OS.gtk_widget_show (labelHandle); - OS.gtk_widget_hide (imageHandle); - } - this.image = image; - _setAlignment (style); -} - -void setOrientation () { - super.setOrientation (); - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - if (boxHandle != 0) OS.gtk_widget_set_direction (boxHandle, OS.GTK_TEXT_DIR_RTL); - if (labelHandle != 0) OS.gtk_widget_set_direction (labelHandle, OS.GTK_TEXT_DIR_RTL); - if (imageHandle != 0) OS.gtk_widget_set_direction (imageHandle, OS.GTK_TEXT_DIR_RTL); - if (arrowHandle != 0) { - switch (style & (SWT.LEFT | SWT.RIGHT)) { - case SWT.LEFT: OS.gtk_arrow_set (arrowHandle, OS.GTK_ARROW_RIGHT, OS.GTK_SHADOW_OUT); break; - case SWT.RIGHT: OS.gtk_arrow_set (arrowHandle, OS.GTK_ARROW_LEFT, OS.GTK_SHADOW_OUT); break; - } - } - } -} - -/** - * 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; - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED); - OS.gtk_toggle_button_set_active (handle, selected); - if ((style & SWT.CHECK) != 0) { - if (selected && grayed) { - OS.gtk_toggle_button_set_inconsistent (handle, true); - } else { - OS.gtk_toggle_button_set_inconsistent (handle, false); - } - } - if ((style & SWT.RADIO) != 0) OS.gtk_toggle_button_set_active (groupHandle, !selected); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED); -} - -/** - * 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; - text = string; - char [] chars = fixMnemonic (string); - byte [] buffer = Converter.wcsToMbcs (null, chars, true); - OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer); - if (image == null) OS.gtk_widget_hide (imageHandle); - OS.gtk_widget_show (labelHandle); - _setAlignment (style); -} - -void showWidget () { - super.showWidget (); - if (boxHandle != 0) OS.gtk_widget_show (boxHandle); - if (labelHandle != 0) OS.gtk_widget_show (labelHandle); - if (arrowHandle != 0) OS.gtk_widget_show (arrowHandle); -} - -int traversalCode (int key, GdkEventKey event) { - int code = super.traversalCode (key, event); - if ((style & SWT.ARROW) != 0) code &= ~(SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS); - if ((style & SWT.RADIO) != 0) code |= SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS; - return code; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java deleted file mode 100644 index ea6a1495d8..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Canvas.java +++ /dev/null @@ -1,407 +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.graphics.*; -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.*; - -/** - * 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 () {} - -/** - * 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; -} - -Point getIMCaretPos () { - if (caret == null) return super.getIMCaretPos (); - return new Point (caret.x, caret.y); -} - -/** - * 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; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - if (ime != null) { - int /*long*/ result = ime.gtk_button_press_event (widget, event); - if (result != 0) return result; - } - return super.gtk_button_press_event (widget, event); -} - -int /*long*/ gtk_commit (int /*long*/ imcontext, int /*long*/ text) { - if (ime != null) { - int /*long*/ result = ime.gtk_commit (imcontext, text); - if (result != 0) return result; - } - return super.gtk_commit (imcontext, text); -} - -int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ event) { - if ((state & OBSCURED) != 0) return 0; - boolean isFocus = caret != null && caret.isFocusCaret (); - if (isFocus) caret.killFocus (); - int /*long*/ result = super.gtk_expose_event (widget, event); - if (isFocus) caret.setFocus (); - return result; -} - -int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_focus_in_event (widget, event); - if (caret != null) caret.setFocus (); - return result; -} - -int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_focus_out_event (widget, event); - if (caret != null) caret.killFocus (); - return result; -} - -int /*long*/ gtk_preedit_changed (int /*long*/ imcontext) { - if (ime != null) { - int /*long*/ result = ime.gtk_preedit_changed (imcontext); - if (result != 0) return result; - } - return super.gtk_preedit_changed (imcontext); -} - -void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean all, boolean trim) { - boolean isFocus = caret != null && caret.isFocusCaret (); - if (isFocus) caret.killFocus (); - super.redrawWidget (x, y, width, height, redrawAll, all, 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; - if ((style & SWT.MIRRORED) != 0) { - int clientWidth = getClientWidth (); - x = clientWidth - width - x; - destX = clientWidth - width - destX; - } - 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 /*long*/ window = paintWindow (); - int /*long*/ visibleRegion = OS.gdk_drawable_get_visible_region (window); - GdkRectangle srcRect = new GdkRectangle (); - srcRect.x = x; - srcRect.y = y; - srcRect.width = width; - srcRect.height = height; - int /*long*/ copyRegion = OS.gdk_region_rectangle (srcRect); - OS.gdk_region_intersect(copyRegion, visibleRegion); - int /*long*/ invalidateRegion = OS.gdk_region_rectangle (srcRect); - OS.gdk_region_subtract (invalidateRegion, visibleRegion); - OS.gdk_region_offset (invalidateRegion, deltaX, deltaY); - GdkRectangle copyRect = new GdkRectangle(); - OS.gdk_region_get_clipbox (copyRegion, copyRect); - if (copyRect.width != 0 && copyRect.height != 0) { - update (); - } - 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 { -// GC gc = new GC (this); -// gc.copyArea (x, y, width, height, destX, destY); -// gc.dispose (); - int /*long*/ gdkGC = OS.gdk_gc_new (window); - OS.gdk_gc_set_exposures (gdkGC, true); - OS.gdk_draw_drawable (window, gdkGC, window, copyRect.x, copyRect.y, copyRect.x + deltaX, copyRect.y + deltaY, copyRect.width, copyRect.height); - OS.g_object_unref (gdkGC); - boolean disjoint = (destX + width < x) || (x + width < destX) || (destY + height < y) || (y + height < destY); - if (disjoint) { - GdkRectangle rect = new GdkRectangle (); - rect.x = x; - rect.y = y; - rect.width = width; - rect.height = height; - OS.gdk_region_union_with_rect (invalidateRegion, rect); - } else { - GdkRectangle rect = new GdkRectangle (); - if (deltaX != 0) { - int newX = destX - deltaX; - if (deltaX < 0) newX = destX + width; - rect.x = newX; - rect.y = y; - rect.width = Math.abs(deltaX); - rect.height = height; - OS.gdk_region_union_with_rect (invalidateRegion, rect); - } - if (deltaY != 0) { - int newY = destY - deltaY; - if (deltaY < 0) newY = destY + height; - rect.x = x; - rect.y = newY; - rect.width = width; - rect.height = Math.abs(deltaY); - OS.gdk_region_union_with_rect (invalidateRegion, rect); - } - } - OS.gdk_window_invalidate_region(window, invalidateRegion, all); - OS.gdk_region_destroy (visibleRegion); - OS.gdk_region_destroy (copyRegion); - OS.gdk_region_destroy (invalidateRegion); - } - 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 (); -} - -int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - boolean isFocus = caret != null && caret.isFocusCaret (); - if (isFocus) caret.killFocus (); - int result = super.setBounds (x, y, width, height, move, resize); - if (isFocus) caret.setFocus (); - return result; -} - -/** - * 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 (); - } - } -} - -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; -} - -void updateCaret () { - int /*long*/ imHandle = imHandle (); - if (imHandle == 0) return; - GdkRectangle rect = new GdkRectangle (); - rect.x = caret.x; - rect.y = caret.y; - rect.width = caret.width; - rect.height = caret.height; - OS.gtk_im_context_set_cursor_location (imHandle, rect); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java deleted file mode 100644 index 8bfa82fd71..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Caret.java +++ /dev/null @@ -1,515 +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.gtk.*; -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; - - static final int DEFAULT_WIDTH = 1; - -/** - * 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 /*long*/ window = parent.paintWindow (); - int /*long*/ gc = OS.gdk_gc_new (window); - GdkColor color = new GdkColor (); - color.red = (short) 0xffff; - color.green = (short) 0xffff; - color.blue = (short) 0xffff; - int /*long*/ colormap = OS.gdk_colormap_get_system (); - OS.gdk_colormap_alloc_color (colormap, color, true, true); - OS.gdk_gc_set_foreground (gc, color); - OS.gdk_gc_set_function (gc, OS.GDK_XOR); - if (image != null && !image.isDisposed() && image.mask == 0) { - int[] width = new int[1]; int[] height = new int[1]; - OS.gdk_drawable_get_size(image.pixmap, width, height); - int nX = x; - if ((parent.style & SWT.MIRRORED) != 0) nX = parent.getClientWidth () - width[0] - nX; - OS.gdk_draw_drawable(window, gc, image.pixmap, 0, 0, nX, y, width[0], height[0]); - } else { - int nWidth = width, nHeight = height; - if (nWidth <= 0) nWidth = DEFAULT_WIDTH; - int nX = x; - if ((parent.style & SWT.MIRRORED) != 0) nX = parent.getClientWidth () - nWidth - nX; - OS.gdk_draw_rectangle (window, gc, 1, nX, y, nWidth, nHeight); - } - OS.g_object_unref (gc); - OS.gdk_colormap_free_colors (colormap, color, 1); - 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); - } else { - if (width == 0) { - return new Rectangle (x, y, DEFAULT_WIDTH, 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); - } else { - if (width == 0) { - return new Point (DEFAULT_WIDTH, 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; - parent.updateCaret (); - 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; -} - -/** - * 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/gtk/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java deleted file mode 100644 index 257f07af33..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ColorDialog.java +++ /dev/null @@ -1,182 +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.gtk.*; -import org.eclipse.swt.graphics.*; - -/** - * 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 { - RGB rgb; -/** - * 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 (); -} - -/** - * 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; -} -/** - * 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 () { - byte [] buffer = Converter.wcsToMbcs (null, title, true); - int /*long*/ handle = OS.gtk_color_selection_dialog_new (buffer); - Display display = parent != null ? parent.getDisplay (): Display.getCurrent (); - if (parent != null) { - int /*long*/ shellHandle = parent.topHandle (); - OS.gtk_window_set_transient_for (handle, shellHandle); - int /*long*/ pixbufs = OS.gtk_window_get_icon_list (shellHandle); - if (pixbufs != 0) { - OS.gtk_window_set_icon_list (handle, pixbufs); - OS.g_list_free (pixbufs); - } - } - OS.gtk_window_set_modal (handle, true); - GtkColorSelectionDialog dialog = new GtkColorSelectionDialog (); - OS.memmove (dialog, handle); - GdkColor color = new GdkColor(); - if (rgb != null) { - color.red = (short)((rgb.red & 0xFF) | ((rgb.red & 0xFF) << 8)); - color.green = (short)((rgb.green & 0xFF) | ((rgb.green & 0xFF) << 8)); - color.blue = (short)((rgb.blue & 0xFF) | ((rgb.blue & 0xFF) << 8)); - OS.gtk_color_selection_set_current_color (dialog.colorsel, color); - } - OS.gtk_color_selection_set_has_palette (dialog.colorsel, true); - display.addIdleProc (); - Dialog oldModal = null; - if (OS.gtk_window_get_modal (handle)) { - oldModal = display.getModalDialog (); - display.setModalDialog (this); - } - int signalId = 0; - int /*long*/ hookId = 0; - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - signalId = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET()); - hookId = OS.g_signal_add_emission_hook (signalId, 0, display.emissionProc, handle, 0); - } - int response = OS.gtk_dialog_run (handle); - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - OS.g_signal_remove_emission_hook (signalId, hookId); - } - if (OS.gtk_window_get_modal (handle)) { - display.setModalDialog (oldModal); - } - boolean success = response == OS.GTK_RESPONSE_OK; - if (success) { - OS.gtk_color_selection_get_current_color (dialog.colorsel, color); - int red = (color.red >> 8) & 0xFF; - int green = (color.green >> 8) & 0xFF; - int blue = (color.blue >> 8) & 0xFF; - rgb = new RGB (red, green, blue); - } - display.removeIdleProc (); - OS.gtk_widget_destroy (handle); - if (!success) return null; - return rgb; -} -/** - * 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/gtk/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java deleted file mode 100644 index 6e526d3b05..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java +++ /dev/null @@ -1,2241 +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.gtk.*; -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 /*long*/ buttonHandle, entryHandle, listHandle, textRenderer, cellHandle, popupHandle; - int lastEventTime, visibleCount = 5; - int /*long*/ gdkEventKey = 0; - int fixStart = -1, fixEnd = -1; - String [] items = new String [0]; - boolean ignoreSelect, lockText; - - /** - * the operating system limit for the number of characters - * that the text field in an instance of this class can hold - */ - public final static 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 = 0xFFFF; - } - -/** - * 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); - add (string, items.length); -} - -/** - * 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 (!(0 <= index && index <= items.length)) { - error (SWT.ERROR_INVALID_RANGE); - } - String [] newItems = new String [items.length + 1]; - System.arraycopy (items, 0, newItems, 0, index); - newItems [index] = string; - System.arraycopy (items, index, newItems, index + 1, items.length - index); - items = newItems; - byte [] buffer = Converter.wcsToMbcs (null, string, true); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.gtk_combo_box_insert_text (handle, index, buffer); - if ((style & SWT.RIGHT_TO_LEFT) != 0 && popupHandle != 0) { - OS.gtk_container_forall (popupHandle, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL); - } - } else { - /* - * Feature in GTK. When the list is empty and the first item - * is added, the combo box selects that item replacing the - * text in the entry field. The fix is to avoid this by - * stopping the "delete" and "insert_text" signal emission. - */ - ignoreSelect = lockText = true; - int /*long*/ item = OS.gtk_list_item_new_with_label (buffer); - int /*long*/ label = OS.gtk_bin_get_child (item); - setForegroundColor (label, getForegroundColor ()); - OS.gtk_widget_modify_font (label, getFontDescription ()); - OS.gtk_widget_set_direction (label, OS.gtk_widget_get_direction (handle)); - OS.gtk_widget_show (item); - int /*long*/ items = OS.g_list_append (0, item); - OS.gtk_list_insert_items (listHandle, items, index); - ignoreSelect = lockText = false; - } -} - -/** - * 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(); - if (entryHandle != 0) { - int position = OS.gtk_editable_get_position (entryHandle); - OS.gtk_editable_select_region (entryHandle, position, position); - } -} - -void clearText () { - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if ((style & SWT.READ_ONLY) != 0) { - int index = OS.gtk_combo_box_get_active (handle); - if (index != -1) { - int /*long*/ modelHandle = OS.gtk_combo_box_get_model (handle); - int /*long*/ [] ptr = new int /*long*/ [1]; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - OS.gtk_tree_model_get (modelHandle, iter, 0, ptr, -1); - OS.g_free (iter); - if (ptr [0] != 0 && OS.strlen (ptr [0]) > 0) postEvent (SWT.Modify); - OS.g_free (ptr [0]); - } - } else { - OS.gtk_entry_set_text (entryHandle, new byte[1]); - } - OS.gtk_combo_box_set_active (handle, -1); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - } -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - return computeNativeSize (handle, wHint, hHint, changed); - } - if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; - if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; - int[] w = new int [1], h = new int [1]; - OS.gtk_widget_realize (entryHandle); - int /*long*/ layout = OS.gtk_entry_get_layout (entryHandle); - OS.pango_layout_get_size (layout, w, h); - int xborder = Display.INNER_BORDER, yborder = Display.INNER_BORDER; - int /*long*/ style = OS.gtk_widget_get_style (entryHandle); - xborder += OS.gtk_style_get_xthickness (style); - yborder += OS.gtk_style_get_ythickness (style); - int [] property = new int [1]; - OS.gtk_widget_style_get (entryHandle, OS.interior_focus, property, 0); - if (property [0] == 0) { - OS.gtk_widget_style_get (entryHandle, OS.focus_line_width, property, 0); - xborder += property [0]; - yborder += property [0]; - } - int width = OS.PANGO_PIXELS (w [0]) + xborder * 2; - int height = OS.PANGO_PIXELS (h [0]) + yborder * 2; - - GtkRequisition arrowRequesition = new GtkRequisition (); - OS.gtk_widget_size_request (buttonHandle, arrowRequesition); - GtkRequisition listRequesition = new GtkRequisition (); - int /*long*/ listParent = OS.gtk_widget_get_parent (listHandle); - OS.gtk_widget_size_request (listParent != 0 ? listParent : listHandle, listRequesition); - - width = Math.max (listRequesition.width, width) + arrowRequesition.width + 4; - width = wHint == SWT.DEFAULT ? width : wHint; - height = hHint == SWT.DEFAULT ? height : hHint; - return new Point (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> - * - * @since 2.1 - */ -public void copy () { - checkWidget (); - if (entryHandle != 0) OS.gtk_editable_copy_clipboard (entryHandle); -} - -void createHandle (int index) { - state |= HANDLE | MENU; - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - int /*long*/ oldList = OS.gtk_window_list_toplevels (); - if ((style & SWT.READ_ONLY) != 0) { - handle = OS.gtk_combo_box_new_text (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - cellHandle = OS.gtk_bin_get_child (handle); - if (cellHandle == 0) error (SWT.ERROR_NO_HANDLES); - } else { - handle = OS.gtk_combo_box_entry_new_text (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - entryHandle = OS.gtk_bin_get_child (handle); - if (entryHandle == 0) error (SWT.ERROR_NO_HANDLES); - } - popupHandle = findPopupHandle (oldList); - OS.gtk_container_add (fixedHandle, handle); - textRenderer = OS.gtk_cell_renderer_text_new (); - if (textRenderer == 0) error (SWT.ERROR_NO_HANDLES); - /* - * Feature in GTK. In order to make a read only combo box the same - * height as an editable combo box the ypad must be set to 0. In - * versions 2.4.x of GTK, a pad of 0 will clip some letters. The - * fix is to set the pad to 1. - */ - int pad = 0; - if (OS.GTK_VERSION < OS.VERSION(2, 6, 0)) pad = 1; - OS.g_object_set (textRenderer, OS.ypad, pad, 0); - /* - * Feature in GTK. In version 2.4.9 of GTK, a warning is issued - * when a call to gtk_cell_layout_clear() is made. The fix is to hide - * the warning. - */ - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.gtk_cell_layout_clear (handle); - display.setWarnings (warnings); - OS.gtk_cell_layout_pack_start (handle, textRenderer, true); - OS.gtk_cell_layout_set_attributes (handle, textRenderer, OS.text, 0, 0); - - /* - * Feature in GTK. There is no API to query the button - * handle from a combo box although it is possible to get the - * text field. The button handle is needed to hook events. The - * fix is to walk the combo tree and find the first child that is - * an instance of button. - */ - OS.gtk_container_forall (handle, display.allChildrenProc, 0); - if (display.allChildren != 0) { - int /*long*/ list = display.allChildren; - while (list != 0) { - int /*long*/ widget = OS.g_list_data (list); - if (OS.GTK_IS_BUTTON (widget)) { - buttonHandle = widget; - break; - } - list = OS.g_list_next (list); - } - OS.g_list_free (display.allChildren); - display.allChildren = 0; - } - /* - * Feature in GTK. By default, read only combo boxes - * process the RETURN key rather than allowing the - * default button to process the key. The fix is to - * clear the GTK_RECEIVES_DEFAULT flag. - */ - if ((style & SWT.READ_ONLY) != 0 && buttonHandle != 0) { - OS.GTK_WIDGET_UNSET_FLAGS (buttonHandle, OS.GTK_RECEIVES_DEFAULT); - } - } else { - handle = OS.gtk_combo_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (fixedHandle, handle); - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle); - entryHandle = combo.entry; - listHandle = combo.list; - - if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) { - int /*long*/ parentHandle = 0; - int /*long*/ temp = listHandle; - while ((temp = OS.gtk_widget_get_parent(temp)) != 0) { - parentHandle = temp; - } - popupHandle = parentHandle; - if (popupHandle != 0) { - int /*long*/ modalGroup = getShell().modalGroup; - if (modalGroup != 0) { - OS.gtk_window_group_add_window (modalGroup, popupHandle); - } - } - } - /* - * Feature in GTK. There is no API to query the arrow - * handle from a combo box although it is possible to - * get the list and text field. The arrow handle is needed - * to hook events. The fix is to find the first child that is - * not the entry or list and assume this is the arrow handle. - */ - int /*long*/ list = OS.gtk_container_get_children (handle); - if (list != 0) { - int i = 0, count = OS.g_list_length (list); - while (i<count) { - int /*long*/ childHandle = OS.g_list_nth_data (list, i); - if (childHandle != entryHandle && childHandle != listHandle) { - buttonHandle = childHandle; - break; - } - i++; - } - OS.g_list_free (list); - } - - boolean editable = (style & SWT.READ_ONLY) == 0; - OS.gtk_editable_set_editable (entryHandle, editable); - OS.gtk_combo_disable_activate (handle); - OS.gtk_combo_set_case_sensitive (handle, true); - } -} - -/** - * 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 (); - if (entryHandle != 0) OS.gtk_editable_cut_clipboard (entryHandle); -} - -void deregister () { - super.deregister (); - if (buttonHandle != 0) display.removeWidget (buttonHandle); - if (entryHandle != 0) display.removeWidget (entryHandle); - if (listHandle != 0) display.removeWidget (listHandle); - int /*long*/ imContext = imContext (); - if (imContext != 0) display.removeWidget (imContext); -} - -boolean filterKey (int keyval, int /*long*/ event) { - int time = OS.gdk_event_get_time (event); - if (time != lastEventTime) { - lastEventTime = time; - int /*long*/ imContext = imContext (); - if (imContext != 0) { - return OS.gtk_im_context_filter_keypress (imContext, event); - } - } - gdkEventKey = event; - return false; -} - -int /*long*/ findPopupHandle (int /*long*/ oldList) { - int /*long*/ hdl = 0; - int /*long*/ currentList = OS.gtk_window_list_toplevels(); - int /*long*/ oldFromList = oldList; - int /*long*/ newFromList = currentList; - boolean isFound; - while (newFromList != 0) { - int /*long*/ newToplevel = OS.g_list_data(newFromList); - isFound = false; - oldFromList = oldList; - while (oldFromList != 0) { - int /*long*/ oldToplevel = OS.g_list_data(oldFromList); - if (newToplevel == oldToplevel) { - isFound = true; - break; - } - oldFromList = OS.g_list_next(oldFromList); - } - if (!isFound) { - hdl = newToplevel; - break; - } - newFromList = OS.g_list_next(newFromList); - } - OS.g_list_free(oldList); - OS.g_list_free(currentList); - return hdl; -} - -void fixModal (int /*long*/ group, int /*long*/ modalGroup) { - if (popupHandle != 0) { - if (group != 0) { - OS.gtk_window_group_add_window (group, popupHandle); - } else { - if (modalGroup != 0) { - OS.gtk_window_group_remove_window (modalGroup, popupHandle); - } - } - } -} - -void fixIM () { - /* - * The IM filter has to be called one time for each key press event. - * When the IM is open the key events are duplicated. The first event - * is filtered by SWT and the second event is filtered by GTK. In some - * cases the GTK handler does not run (the widget is destroyed, the - * application code consumes the event, etc), for these cases the IM - * filter has to be called by SWT. - */ - if (gdkEventKey != 0 && gdkEventKey != -1) { - int /*long*/ imContext = imContext (); - if (imContext != 0) { - OS.gtk_im_context_filter_keypress (imContext, gdkEventKey); - gdkEventKey = -1; - return; - } - } - gdkEventKey = 0; -} - -int /*long*/ fontHandle () { - if (entryHandle != 0) return entryHandle; - return super.fontHandle (); -} - -int /*long*/ focusHandle () { - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if ((style & SWT.READ_ONLY) != 0 && buttonHandle != 0) return buttonHandle; - } - if (entryHandle != 0) return entryHandle; - return super.focusHandle (); -} - -boolean hasFocus () { - if (super.hasFocus ()) return true; - if (entryHandle != 0 && OS.GTK_WIDGET_HAS_FOCUS (entryHandle)) return true; - if (listHandle != 0 && OS.GTK_WIDGET_HAS_FOCUS (listHandle)) return true; - return false; -} - -void hookEvents () { - super.hookEvents (); - if (OS.GTK_VERSION >= OS.VERSION(2, 4, 0)) { - OS.g_signal_connect_closure (handle, OS.changed, display.closures [CHANGED], true); - } - - if (entryHandle != 0) { - OS.g_signal_connect_closure (entryHandle, OS.changed, display.closures [CHANGED], true); - OS.g_signal_connect_closure (entryHandle, OS.insert_text, display.closures [INSERT_TEXT], false); - OS.g_signal_connect_closure (entryHandle, OS.delete_text, display.closures [DELETE_TEXT], false); - OS.g_signal_connect_closure (entryHandle, OS.activate, display.closures [ACTIVATE], false); - OS.g_signal_connect_closure (entryHandle, OS.populate_popup, display.closures [POPULATE_POPUP], false); - } - int eventMask = OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_PRESS_MASK | - OS.GDK_BUTTON_RELEASE_MASK; - int /*long*/ [] handles = new int /*long*/ [] {buttonHandle, entryHandle, listHandle}; - for (int i=0; i<handles.length; i++) { - int /*long*/ eventHandle = handles [i]; - if (eventHandle != 0) { - /* Connect the mouse signals */ - OS.gtk_widget_add_events (eventHandle, eventMask); - OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false); - OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT], false); - OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [MOTION_NOTIFY_EVENT], 0, display.closures [MOTION_NOTIFY_EVENT], false); - /* - * Feature in GTK. Events such as mouse move are propagated up - * the widget hierarchy and are seen by the parent. This is the - * correct GTK behavior but not correct for SWT. The fix is to - * hook a signal after and stop the propagation using a negative - * event number to distinguish this case. - */ - OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT_INVERSE], true); - OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT_INVERSE], true); - OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [MOTION_NOTIFY_EVENT], 0, display.closures [MOTION_NOTIFY_EVENT_INVERSE], true); - - /* Connect the event_after signal for both key and mouse */ - if (eventHandle != focusHandle ()) { - OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [EVENT_AFTER], 0, display.closures [EVENT_AFTER], false); - } - } - } - int /*long*/ imContext = imContext (); - if (imContext != 0) { - OS.g_signal_connect_closure (imContext, OS.commit, display.closures [COMMIT], false); - int id = OS.g_signal_lookup (OS.commit, OS.gtk_im_context_get_type ()); - int blockMask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID; - OS.g_signal_handlers_block_matched (imContext, blockMask, id, 0, 0, 0, entryHandle); - } -} - -int /*long*/ imContext () { - return entryHandle != 0 ? OS.GTK_ENTRY_IM_CONTEXT (entryHandle) : 0; -} - -/** - * 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 < 0 || index >= items.length) return; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (OS.gtk_combo_box_get_active (handle) == index) { - clearText (); - } - } else { - ignoreSelect = true; - int /*long*/ children = OS.gtk_container_get_children (listHandle); - int /*long*/ item = OS.g_list_nth_data (children, index); - boolean selected = OS.GTK_WIDGET_STATE (item) == OS.GTK_STATE_SELECTED; - if (selected) { - OS.gtk_list_unselect_all (listHandle); - OS.gtk_entry_set_text (entryHandle, new byte[1]); - } - OS.g_list_free (children); - ignoreSelect = false; - } -} - -/** - * 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(); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - clearText (); - } else { - ignoreSelect = true; - OS.gtk_list_unselect_all (listHandle); - OS.gtk_entry_set_text (entryHandle, new byte[1]); - ignoreSelect = false; - } -} - -boolean dragDetect(int x, int y, boolean filter, boolean[] consume) { - if (filter && entryHandle != 0) { - int [] index = new int [1]; - int [] trailing = new int [1]; - int /*long*/ layout = OS.gtk_entry_get_layout (entryHandle); - OS.pango_layout_xy_to_index (layout, x * OS.PANGO_SCALE, y * OS.PANGO_SCALE, index, trailing); - int /*long*/ ptr = OS.pango_layout_get_text (layout); - int position = (int)/*64*/OS.g_utf8_pointer_to_offset (ptr, ptr + index[0]) + trailing[0]; - Point selection = getSelection (); - if (selection.x <= position && position < selection.y) { - if (super.dragDetect (x, y, filter, consume)) { - if (consume != null) consume [0] = true; - return true; - } - } - return false; - } - return super.dragDetect (x, y, filter, consume); -} - -int /*long*/ enterExitHandle () { - return fixedHandle; -} - -int /*long*/ eventWindow () { - return paintWindow (); -} - -GdkColor getBackgroundColor () { - return getBaseColor (); -} - -GdkColor getForegroundColor () { - return getTextColor (); -} - -/** - * 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(); - if (!(0 <= index && index < items.length)) { - error (SWT.ERROR_INVALID_RANGE); - } - return items [index]; -} - -/** - * 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(); - return items.length; -} - -/** - * 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(); - return fontHeight (getFontDescription (), listHandle != 0 ? listHandle : handle); -} - -/** - * 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(); - String [] result = new String [items.length]; - System.arraycopy (items, 0, result, 0, items.length); - 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 (); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - return popupHandle != 0 && OS.GTK_WIDGET_VISIBLE (popupHandle); - } - return false; -} - -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 (); - if ((style & SWT.READ_ONLY) != 0) { - int length = 0; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - int index = OS.gtk_combo_box_get_active (handle); - if (index != -1) length = getItem (index).length (); - } else { - int /*long*/ str = OS.gtk_entry_get_text (entryHandle); - if (str != 0) length = (int)/*64*/OS.g_utf8_strlen (str, -1); - } - return new Point (0, length); - } - int [] start = new int [1]; - int [] end = new int [1]; - if (entryHandle != 0) { - OS.gtk_editable_get_selection_bounds (entryHandle, start, end); - } - 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(); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - return OS.gtk_combo_box_get_active (handle); - } - int index = 0, result = -1; - int /*long*/ children = OS.gtk_container_get_children (listHandle); - int /*long*/ temp = children; - while (temp != 0) { - int /*long*/ item = OS.g_list_data (temp); - if (OS.GTK_WIDGET_STATE (item) == OS.GTK_STATE_SELECTED) { - result = index; - break; - } - index++; - temp = OS.g_list_next (temp); - } - OS.g_list_free (children); - return result; -} - -/** - * 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(); - if (entryHandle != 0) { - int /*long*/ str = OS.gtk_entry_get_text (entryHandle); - if (str == 0) return ""; - int length = OS.strlen (str); - byte [] buffer = new byte [length]; - OS.memmove (buffer, str, length); - return new String (Converter.mbcsToWcs (null, buffer)); - } else { - int index = OS.gtk_combo_box_get_active (handle); - return index != -1 ? getItem (index) : ""; - } -} - -String getText (int start, int stop) { - /* - * NOTE: The current implementation uses substring () - * which can reference a potentially large character - * array. - */ - return getText ().substring (start, stop - 1); -} - -/** - * 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(); - GtkRequisition requisition = new GtkRequisition (); - gtk_widget_size_request (handle, requisition); - return OS.GTK_WIDGET_REQUISITION_HEIGHT (handle); -} - -/** - * 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 limit = entryHandle != 0 ? OS.gtk_entry_get_max_length (entryHandle) : 0; - return limit == 0 ? LIMIT : limit; -} - -/** - * 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 (); - return visibleCount; -} - -int /*long*/ gtk_activate (int /*long*/ widget) { - postEvent (SWT.DefaultSelection); - return 0; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - /* - * Feature in GTK. Depending on where the user clicks, GTK prevents - * the left mouse button event from being propagated. The fix is to - * send the mouse event from the event_after handler. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, event, GdkEventButton.sizeof); - if (gdkEvent.type == OS.GDK_BUTTON_PRESS && gdkEvent.button == 1 && (style & SWT.READ_ONLY) != 0) { - return gtk_button_press_event(widget, event, false); - } - } - return super.gtk_button_press_event (widget, event); -} - -int /*long*/ gtk_changed (int /*long*/ widget) { - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (widget == handle) { - if (entryHandle == 0) { - sendEvent(SWT.Modify); - if (isDisposed ()) return 0; - } - /* - * Feature in GTK. GTK emits a changed signal whenever - * the contents of a combo box are altered by typing or - * by selecting an item in the list, but the event should - * only be sent when the list is selected. The fix is to - * only send out a selection event when there is a selected - * item. - * - * NOTE: This code relies on GTK clearing the selected - * item and not matching the item as the user types. - */ - int index = OS.gtk_combo_box_get_active (handle); - if (index != -1) postEvent (SWT.Selection); - return 0; - } - } else { - if (!ignoreSelect) { - int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle); - int length = OS.strlen (ptr); - byte [] buffer = new byte [length]; - OS.memmove (buffer, ptr, length); - String text = new String (Converter.mbcsToWcs (null, buffer)); - for (int i = 0; i < items.length; i++) { - if (items [i].equals (text)) { - postEvent (SWT.Selection); - break; - } - } - } - } - /* - * Feature in GTK. When the user types, GTK positions - * the caret after sending the changed signal. This - * means that application code that attempts to position - * the caret during a changed signal will fail. The fix - * is to post the modify event when the user is typing. - */ - boolean keyPress = false; - int /*long*/ eventPtr = OS.gtk_get_current_event (); - if (eventPtr != 0) { - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof); - switch (gdkEvent.type) { - case OS.GDK_KEY_PRESS: - keyPress = true; - break; - } - OS.gdk_event_free (eventPtr); - } - if (keyPress) { - postEvent (SWT.Modify); - } else { - sendEvent (SWT.Modify); - } - return 0; -} - -int /*long*/ gtk_commit (int /*long*/ imContext, int /*long*/ text) { - if (text == 0) return 0; - if (!OS.gtk_editable_get_editable (entryHandle)) return 0; - int length = OS.strlen (text); - if (length == 0) return 0; - byte [] buffer = new byte [length]; - OS.memmove (buffer, text, length); - char [] chars = Converter.mbcsToWcs (null, buffer); - char [] newChars = sendIMKeyEvent (SWT.KeyDown, null, chars); - if (newChars == null) return 0; - /* - * Feature in GTK. For a GtkEntry, during the insert-text signal, - * GTK allows the programmer to change only the caret location, - * not the selection. If the programmer changes the selection, - * the new selection is lost. The fix is to detect a selection - * change and set it after the insert-text signal has completed. - */ - fixStart = fixEnd = -1; - OS.g_signal_handlers_block_matched (imContext, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, COMMIT); - int id = OS.g_signal_lookup (OS.commit, OS.gtk_im_context_get_type ()); - int mask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID; - OS.g_signal_handlers_unblock_matched (imContext, mask, id, 0, 0, 0, entryHandle); - if (newChars == chars) { - OS.g_signal_emit_by_name (imContext, OS.commit, text); - } else { - buffer = Converter.wcsToMbcs (null, newChars, true); - OS.g_signal_emit_by_name (imContext, OS.commit, buffer); - } - OS.g_signal_handlers_unblock_matched (imContext, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, COMMIT); - OS.g_signal_handlers_block_matched (imContext, mask, id, 0, 0, 0, entryHandle); - if (fixStart != -1 && fixEnd != -1) { - OS.gtk_editable_set_position (entryHandle, fixStart); - OS.gtk_editable_select_region (entryHandle, fixStart, fixEnd); - } - fixStart = fixEnd = -1; - return 0; -} - -int /*long*/ gtk_delete_text (int /*long*/ widget, int /*long*/ start_pos, int /*long*/ end_pos) { - if (lockText) { - OS.gtk_list_unselect_item (listHandle, 0); - OS.g_signal_stop_emission_by_name (entryHandle, OS.delete_text); - return 0; - } - if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0; - String newText = verifyText ("", (int)/*64*/start_pos, (int)/*64*/end_pos); - if (newText == null) { - OS.g_signal_stop_emission_by_name (entryHandle, OS.delete_text); - } else { - if (newText.length () > 0) { - int [] pos = new int [1]; - pos [0] = (int)/*64*/end_pos; - byte [] buffer = Converter.wcsToMbcs (null, newText, false); - OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - OS.gtk_editable_insert_text (entryHandle, buffer, buffer.length, pos); - OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_editable_set_position (entryHandle, pos [0]); - } - } - return 0; -} - -int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) { - /* - * Feature in GTK. Depending on where the user clicks, GTK prevents - * the left mouse button event from being propagated. The fix is to - * send the mouse event from the event_after handler. - * - * Feature in GTK. When the user clicks anywhere in an editable - * combo box, a single focus event should be issued, despite the - * fact that focus might switch between the drop down button and - * the text field. The fix is to use gtk_combo_box_set_focus_on_click () - * to eat all focus events while focus is in the combo box. When the - * user clicks on the drop down button focus is assigned to the text - * field. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - GdkEvent event = new GdkEvent (); - OS.memmove (event, gdkEvent, GdkEvent.sizeof); - switch (event.type) { - case OS.GDK_BUTTON_PRESS: { - GdkEventButton gdkEventButton = new GdkEventButton (); - OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof); - if (gdkEventButton.button == 1) { - if ((style & SWT.READ_ONLY) != 0 && !sendMouseEvent (SWT.MouseDown, gdkEventButton.button, display.clickCount, 0, false, gdkEventButton.time, gdkEventButton.x_root, gdkEventButton.y_root, false, gdkEventButton.state)) { - return 1; - } - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) { - if ((style & SWT.READ_ONLY) == 0 && widget == buttonHandle) { - OS.gtk_widget_grab_focus (entryHandle); - } - } - } - break; - } - case OS.GDK_FOCUS_CHANGE: { - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) { - if ((style & SWT.READ_ONLY) == 0) { - GdkEventFocus gdkEventFocus = new GdkEventFocus (); - OS.memmove (gdkEventFocus, gdkEvent, GdkEventFocus.sizeof); - if (gdkEventFocus.in != 0) { - OS.gtk_combo_box_set_focus_on_click (handle, false); - } else { - OS.gtk_combo_box_set_focus_on_click (handle, true); - } - } - } - break; - } - } - } - return super.gtk_event_after(widget, gdkEvent); -} - -int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) { - fixIM (); - return super.gtk_focus_out_event (widget, event); -} - -int /*long*/ gtk_insert_text (int /*long*/ widget, int /*long*/ new_text, int /*long*/ new_text_length, int /*long*/ position) { - if (lockText) { - OS.gtk_list_unselect_item (listHandle, 0); - OS.g_signal_stop_emission_by_name (entryHandle, OS.insert_text); - return 0; - } - if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0; - if (new_text == 0 || new_text_length == 0) return 0; - byte [] buffer = new byte [(int)/*64*/new_text_length]; - OS.memmove (buffer, new_text, buffer.length); - String oldText = new String (Converter.mbcsToWcs (null, buffer)); - int [] pos = new int [1]; - OS.memmove (pos, position, 4); - if (pos [0] == -1) { - int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle); - pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1); - } - String newText = verifyText (oldText, pos [0], pos [0]); - if (newText != oldText) { - int [] newStart = new int [1], newEnd = new int [1]; - OS.gtk_editable_get_selection_bounds (entryHandle, newStart, newEnd); - if (newText != null) { - if (newStart [0] != newEnd [0]) { - OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT); - OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_editable_delete_selection (entryHandle); - OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT); - OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - } - byte [] buffer3 = Converter.wcsToMbcs (null, newText, false); - OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - OS.gtk_editable_insert_text (entryHandle, buffer3, buffer3.length, pos); - OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - newStart [0] = newEnd [0] = pos [0]; - } - pos [0] = newEnd [0]; - if (newStart [0] != newEnd [0]) { - fixStart = newStart [0]; - fixEnd = newEnd [0]; - } - OS.memmove (position, pos, 4); - OS.g_signal_stop_emission_by_name (entryHandle, OS.insert_text); - } - return 0; -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_key_press_event (widget, event); - if (result != 0) fixIM (); - if (gdkEventKey == -1) result = 1; - gdkEventKey = 0; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0) && (style & SWT.READ_ONLY) == 0) { - GdkEventKey keyEvent = new GdkEventKey (); - OS.memmove (keyEvent, event, GdkEventKey.sizeof); - int oldIndex = OS.gtk_combo_box_get_active (handle); - int newIndex = oldIndex; - int key = keyEvent.keyval; - switch (key) { - case OS.GDK_Down: - case OS.GDK_KP_Down: - if (oldIndex != (items.length - 1)) { - newIndex = oldIndex + 1; - } - break; - case OS.GDK_Up: - case OS.GDK_KP_Up: - if (oldIndex != -1 && oldIndex != 0) { - newIndex = oldIndex - 1; - } - break; - /* - * Feature in GTK. In gtk_combo_box, the PageUp and PageDown keys - * go the first and last items in the list rather than scrolling - * a page at a time. The fix is to emulate this behavior for - * gtk_combo_box_entry. - */ - case OS.GDK_Page_Up: - case OS.GDK_KP_Page_Up: - newIndex = 0; - break; - case OS.GDK_Page_Down: - case OS.GDK_KP_Page_Down: - newIndex = items.length - 1; - break; - } - if (newIndex != oldIndex) { - OS.gtk_combo_box_set_active (handle, newIndex); - return 1; - } - } - return result; -} - -int /*long*/ gtk_populate_popup (int /*long*/ widget, int /*long*/ menu) { - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - OS.gtk_widget_set_direction (menu, OS.GTK_TEXT_DIR_RTL); - OS.gtk_container_forall (menu, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL); - } - return 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 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(); - return indexOf (string, 0); -} - -/** - * 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); - if (!(0 <= start && start < items.length)) return -1; - for (int i=start; i<items.length; i++) { - if (string.equals(items [i])) return i; - } - return -1; -} - -boolean isFocusHandle(int widget) { - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (buttonHandle != 0 && widget == buttonHandle) return true; - if (entryHandle != 0 && widget == entryHandle) return true; - } - return super.isFocusHandle (widget); -} - -int /*long*/ paintWindow () { - int /*long*/ childHandle = entryHandle != 0 ? entryHandle : handle; - OS.gtk_widget_realize (childHandle); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (childHandle); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if ((style & SWT.READ_ONLY) != 0) return window; - } - int /*long*/ children = OS.gdk_window_get_children (window); - if (children != 0) window = OS.g_list_data (children); - OS.g_list_free (children); - return window; -} - -/** - * 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 (); - if (entryHandle != 0) OS.gtk_editable_paste_clipboard (entryHandle); -} - -int /*long*/ parentingHandle() { - return fixedHandle; -} - -void register () { - super.register (); - if (buttonHandle != 0) display.addWidget (buttonHandle, this); - if (entryHandle != 0) display.addWidget (entryHandle, this); - if (listHandle != 0) display.addWidget (listHandle, this); - int /*long*/ imContext = imContext (); - if (imContext != 0) display.addWidget (imContext, this); -} - -void releaseHandle () { - super.releaseHandle (); - buttonHandle = entryHandle = listHandle = 0; -} - -void releaseWidget () { - super.releaseWidget (); - textRenderer = 0; - fixIM (); -} - -/** - * 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 (!(0 <= index && index < items.length)) { - error (SWT.ERROR_INVALID_RANGE); - } - String [] oldItems = items; - String [] newItems = new String [oldItems.length - 1]; - System.arraycopy (oldItems, 0, newItems, 0, index); - System.arraycopy (oldItems, index + 1, newItems, index, oldItems.length - index - 1); - items = newItems; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (OS.gtk_combo_box_get_active (handle) == index) clearText (); - OS.gtk_combo_box_remove_text (handle, index); - } else { - ignoreSelect = true; - int /*long*/ children = OS.gtk_container_get_children (listHandle); - int /*long*/ item = OS.g_list_nth_data (children, index); - boolean selected = OS.GTK_WIDGET_STATE (item) == OS.GTK_STATE_SELECTED; - int /*long*/ items = OS.g_list_append (0, item); - OS.gtk_list_remove_items (listHandle, items); - OS.g_list_free (items); - OS.g_list_free (children); - if (selected) { - OS.gtk_entry_set_text (entryHandle, new byte[1]); - } - ignoreSelect = false; - } -} - -/** - * 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; - if (!(0 <= start && start <= end && end < items.length)) { - error (SWT.ERROR_INVALID_RANGE); - } - String [] oldItems = items; - String [] newItems = new String [oldItems.length - (end - start + 1)]; - System.arraycopy (oldItems, 0, newItems, 0, start); - System.arraycopy (oldItems, end + 1, newItems, start, oldItems.length - end - 1); - items = newItems; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - int index = OS.gtk_combo_box_get_active (handle); - if (start <= index && index <= end) clearText(); - for (int i = end; i >= start; i--) { - OS.gtk_combo_box_remove_text (handle, i); - } - } else { - boolean selected = false; - ignoreSelect = true; - int /*long*/ items = 0; - int /*long*/ children = OS.gtk_container_get_children (listHandle); - for (int i = start; i <= end; i++) { - int /*long*/ item = OS.g_list_nth_data (children, i); - selected |= OS.GTK_WIDGET_STATE (item) == OS.GTK_STATE_SELECTED; - items = OS.g_list_append (items, item); - } - OS.gtk_list_remove_items (listHandle, items); - OS.g_list_free (items); - OS.g_list_free (children); - if (selected) { - OS.gtk_entry_set_text (entryHandle, new byte[1]); - } - ignoreSelect = false; - } -} - -/** - * 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); - int index = indexOf (string, 0); - if (index == -1) error (SWT.ERROR_INVALID_ARGUMENT); - remove (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 count = items.length; - items = new String[0]; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - clearText (); - for (int i = count - 1; i >= 0; i--) { - OS.gtk_combo_box_remove_text (handle, i); - } - } else { - ignoreSelect = true; - OS.gtk_list_clear_items (listHandle, 0, -1); - OS.gtk_entry_set_text (entryHandle, new byte[1]); - ignoreSelect = false; - } -} - -/** - * 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 < 0 || index >= items.length) return; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_combo_box_set_active (handle, index); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if ((style & SWT.READ_ONLY) != 0) { - /* - * Feature in GTK. Read Only combo boxes do not get a chance to send out a - * Modify event in the gtk_changed callback. The fix is to send a Modify event - * here. - */ - sendEvent (SWT.Modify); - } - } else { - ignoreSelect = true; - OS.gtk_list_select_item (listHandle, index); - ignoreSelect = false; - } -} - -void setBackgroundColor (GdkColor color) { - super.setBackgroundColor (color); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (entryHandle != 0) OS.gtk_widget_modify_base (entryHandle, 0, color); - OS.g_object_set (textRenderer, OS.background_gdk, color, 0); - } else { - OS.gtk_widget_modify_base (entryHandle, 0, color); - if (listHandle != 0) OS.gtk_widget_modify_base (listHandle, 0, color); - } -} - -int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - int newHeight = height; - if (resize) newHeight = Math.max (getTextHeight (), height); - return super.setBounds (x, y, width, newHeight, move, resize); -} - -void setFontDescription (int /*long*/ font) { - super.setFontDescription (font); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (entryHandle != 0) OS.gtk_widget_modify_font (entryHandle, font); - OS.g_object_set (textRenderer, OS.font_desc, font, 0); - if ((style & SWT.READ_ONLY) != 0) { - /* - * Bug in GTK. Setting the font can leave the combo box with an - * invalid minimum size. The fix is to temporarily change the - * selected item to force the combo box to resize. - */ - int index = OS.gtk_combo_box_get_active (handle); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_combo_box_set_active (handle, -1); - OS.gtk_combo_box_set_active (handle, index); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - } - } else { - OS.gtk_widget_modify_font (entryHandle, font); - if (listHandle != 0) { - OS.gtk_widget_modify_font (listHandle, font); - int /*long*/ itemsList = OS.gtk_container_get_children (listHandle); - if (itemsList != 0) { - int count = OS.g_list_length (itemsList); - for (int i=count - 1; i>=0; i--) { - int /*long*/ widget = OS.gtk_bin_get_child (OS.g_list_nth_data (itemsList, i)); - OS.gtk_widget_modify_font (widget, font); - } - OS.g_list_free (itemsList); - } - } - } -} - -void setForegroundColor (GdkColor color) { - super.setForegroundColor (color); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (entryHandle != 0) setForegroundColor (entryHandle, color); - OS.g_object_set (textRenderer, OS.foreground_gdk, color, 0); - } else { - setForegroundColor (entryHandle, color); - if (listHandle != 0) { - setForegroundColor (listHandle, color); - int /*long*/ itemsList = OS.gtk_container_get_children (listHandle); - if (itemsList != 0) { - int count = OS.g_list_length (itemsList); - for (int i=count - 1; i>=0; i--) { - int /*long*/ widget = OS.gtk_bin_get_child (OS.g_list_nth_data (itemsList, i)); - setForegroundColor (widget, color); - } - OS.g_list_free (itemsList); - } - } - } -} - -/** - * 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 (!(0 <= index && index < items.length)) { - error (SWT.ERROR_INVALID_ARGUMENT); - } - items [index] = string; - byte [] buffer = Converter.wcsToMbcs (null, string, true); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.gtk_combo_box_remove_text (handle, index); - OS.gtk_combo_box_insert_text (handle, index, buffer); - if ((style & SWT.RIGHT_TO_LEFT) != 0 && popupHandle != 0) { - OS.gtk_container_forall (popupHandle, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL); - } - } else { - ignoreSelect = true; - int /*long*/ children = OS.gtk_container_get_children (listHandle); - int /*long*/ item = OS.g_list_nth_data (children, index); - int /*long*/ label = OS.gtk_bin_get_child (item); - OS.gtk_label_set_text (label, buffer); - OS.g_list_free (children); - ignoreSelect = false; - } -} - -/** - * 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); - } - int count = this.items.length; - this.items = new String [items.length]; - System.arraycopy (items, 0, this.items, 0, items.length); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - clearText (); - for (int i = count - 1; i >= 0; i--) { - OS.gtk_combo_box_remove_text (handle, i); - } - for (int i = 0; i < items.length; i++) { - String string = items [i]; - byte [] buffer = Converter.wcsToMbcs (null, string, true); - OS.gtk_combo_box_insert_text (handle, i, buffer); - if ((style & SWT.RIGHT_TO_LEFT) != 0 && popupHandle != 0) { - OS.gtk_container_forall (popupHandle, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL); - } - } - } else { - lockText = ignoreSelect = true; - OS.gtk_list_clear_items (listHandle, 0, -1); - int /*long*/ font = getFontDescription (); - GdkColor color = getForegroundColor (); - int direction = OS.gtk_widget_get_direction (handle); - int i = 0; - while (i < items.length) { - String string = items [i]; - byte [] buffer = Converter.wcsToMbcs (null, string, true); - int /*long*/ item = OS.gtk_list_item_new_with_label (buffer); - int /*long*/ label = OS.gtk_bin_get_child (item); - setForegroundColor (label, color); - OS.gtk_widget_modify_font (label, font); - OS.gtk_widget_set_direction (label, direction); - OS.gtk_container_add (listHandle, item); - OS.gtk_widget_show (item); - i++; - } - lockText = ignoreSelect = false; - OS.gtk_entry_set_text (entryHandle, new byte[1]); - } -} - -/** - * 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 (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (visible) { - OS.gtk_combo_box_popup (handle); - } else { - OS.gtk_combo_box_popdown (handle); - } - } -} - -void setOrientation() { - super.setOrientation(); - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - if (listHandle != 0) OS.gtk_widget_set_direction (listHandle, OS.GTK_TEXT_DIR_RTL); - if (entryHandle != 0) OS.gtk_widget_set_direction (entryHandle, OS.GTK_TEXT_DIR_RTL); - if (cellHandle != 0) OS.gtk_widget_set_direction (cellHandle, OS.GTK_TEXT_DIR_RTL); - } -} - -/** - * 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) { - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - checkWidget(); - int flags = SWT.RIGHT_TO_LEFT | SWT.LEFT_TO_RIGHT; - if ((orientation & flags) == 0 || (orientation & flags) == flags) return; - style &= ~flags; - style |= orientation & flags; - int dir = (orientation & SWT.RIGHT_TO_LEFT) != 0 ? OS.GTK_TEXT_DIR_RTL : OS.GTK_TEXT_DIR_LTR; - OS.gtk_widget_set_direction (fixedHandle, dir); - OS.gtk_widget_set_direction (handle, dir); - if (entryHandle != 0) OS.gtk_widget_set_direction (entryHandle, dir); - if (listHandle != 0) { - OS.gtk_widget_set_direction (listHandle, dir); - int /*long*/ itemsList = OS.gtk_container_get_children (listHandle); - if (itemsList != 0) { - int count = OS.g_list_length (itemsList); - for (int i=count - 1; i>=0; i--) { - int /*long*/ widget = OS.gtk_bin_get_child (OS.g_list_nth_data (itemsList, i)); - OS.gtk_widget_set_direction (widget, dir); - } - OS.g_list_free (itemsList); - } - } - if (cellHandle != 0) OS.gtk_widget_set_direction (cellHandle, dir); - if (popupHandle != 0) OS.gtk_container_forall (popupHandle, display.setDirectionProc, dir); - } -} - -/** - * 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); - if ((style & SWT.READ_ONLY) != 0) return; - if (entryHandle != 0) { - OS.gtk_editable_set_position (entryHandle, selection.x); - OS.gtk_editable_select_region (entryHandle, selection.x, selection.y); - } -} - -/** - * 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); - if ((style & SWT.READ_ONLY) != 0) { - int index = indexOf (string); - if (index == -1) return; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_combo_box_set_active (handle, index); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - /* - * Feature in GTK. Read Only combo boxes do not get a chance to send out a - * Modify event in the gtk_changed callback. The fix is to send a Modify event - * here. - */ - sendEvent (SWT.Modify); - return; - } - } - /* - * Feature in gtk. When text is set in gtk, separate events are fired for the deletion and - * insertion of the text. This is not wrong, but is inconsistent with other platforms. The - * fix is to block the firing of these events and fire them ourselves in a consistent manner. - */ - if (hooks (SWT.Verify) || filters (SWT.Verify)) { - int /*long*/ ptr = OS.gtk_entry_get_text (entryHandle); - string = verifyText (string, 0, (int)/*64*/OS.g_utf8_strlen (ptr, -1)); - if (string == null) return; - } - byte [] buffer = Converter.wcsToMbcs (null, string, true); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - } - OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT); - OS.g_signal_handlers_block_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - OS.gtk_entry_set_text (entryHandle, buffer); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - } - OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT); - OS.g_signal_handlers_unblock_matched (entryHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - sendEvent (SWT.Modify); -} - -/** - * 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); - if (entryHandle != 0) OS.gtk_entry_set_max_length (entryHandle, limit); -} - -void setToolTipText (Shell shell, String newString) { - if (entryHandle != 0) shell.setToolTipText (entryHandle, newString); - if (buttonHandle != 0) shell.setToolTipText (buttonHandle, newString); -} - -/** - * 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; - visibleCount = count; -} - -boolean checkSubwindow () { - return false; -} - -boolean translateTraversal (GdkEventKey keyEvent) { - int key = keyEvent.keyval; - switch (key) { - case OS.GDK_KP_Enter: - case OS.GDK_Return: { - int /*long*/ imContext = imContext (); - if (imContext != 0) { - int /*long*/ [] preeditString = new int /*long*/ [1]; - OS.gtk_im_context_get_preedit_string (imContext, preeditString, null, null); - if (preeditString [0] != 0) { - int length = OS.strlen (preeditString [0]); - OS.g_free (preeditString [0]); - if (length != 0) return false; - } - } - } - } - return super.translateTraversal (keyEvent); -} - -String verifyText (String string, int start, int end) { - if (string.length () == 0 && start == end) return null; - Event event = new Event (); - event.text = string; - event.start = start; - event.end = end; - int /*long*/ eventPtr = OS.gtk_get_current_event (); - if (eventPtr != 0) { - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof); - switch (gdkEvent.type) { - case OS.GDK_KEY_PRESS: - setKeyState (event, gdkEvent); - break; - } - OS.gdk_event_free (eventPtr); - } - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in the verify - * event. If this happens, answer null to cancel - * the operation. - */ - sendEvent (SWT.Verify, event); - if (!event.doit || isDisposed ()) return null; - return event.text; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java deleted file mode 100644 index 62cda3117c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Composite.java +++ /dev/null @@ -1,1438 +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.cairo.*; -import org.eclipse.swt.internal.gtk.*; -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 { - public int /*long*/ embeddedHandle; - int /*long*/ imHandle, socketHandle; - Layout layout; - Control[] tabList; - int layoutCount, backgroundMode; - - static final String NO_INPUT_METHOD = "org.eclipse.swt.internal.gtk.noInputMethod"; //$NON-NLS-1$ - -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, checkStyle (style)); -} - -static int checkStyle (int style) { - style &= ~SWT.TRANSPARENT; - return style; -} - -Control [] _getChildren () { - int /*long*/ parentHandle = parentingHandle (); - int /*long*/ list = OS.gtk_container_get_children (parentHandle); - if (list == 0) return new Control [0]; - int count = OS.g_list_length (list); - Control [] children = new Control [count]; - int i = 0; - int /*long*/ temp = list; - while (temp != 0) { - int /*long*/ handle = OS.g_list_data (temp); - if (handle != 0) { - Widget widget = display.getWidget (handle); - if (widget != null && widget != this) { - if (widget instanceof Control) { - children [i++] = (Control) widget; - } - } - } - temp = OS.g_list_next (temp); - } - OS.g_list_free (list); - if (i == count) return children; - Control [] newChildren = new Control [i]; - System.arraycopy (children, 0, newChildren, 0, i); - 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; -} - -/** - * 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 ((style & SWT.DOUBLE_BUFFERED) == 0 && (style & SWT.NO_BACKGROUND) != 0) { - return; - } - super.checkBuffered(); -} - -protected void checkSubclass () { - /* Do nothing - Subclassing is allowed */ -} - -int /*long*/ childStyle () { - if (scrolledHandle != 0) return 0; - return super.childStyle (); -} - -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; - 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); -} - -Widget [] computeTabList () { - Widget 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]; - Widget [] childList = child.computeTabList (); - if (childList.length != 0) { - Widget [] newResult = new Widget [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; -} - -void createHandle (int index) { - state |= HANDLE | CANVAS; - boolean scrolled = (style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0; - if (!scrolled) state |= THEME_BACKGROUND; - createHandle (index, true, scrolled || (style & SWT.BORDER) != 0); -} - -void createHandle (int index, boolean fixed, boolean scrolled) { - if (scrolled) { - if (fixed) { - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - } - int /*long*/ vadj = OS.gtk_adjustment_new (0, 0, 100, 1, 10, 10); - if (vadj == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ hadj = OS.gtk_adjustment_new (0, 0, 100, 1, 10, 10); - if (hadj == 0) error (SWT.ERROR_NO_HANDLES); - scrolledHandle = OS.gtk_scrolled_window_new (hadj, vadj); - if (scrolledHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - } - handle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (handle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (handle, true); - OS.GTK_WIDGET_SET_FLAGS(handle, OS.GTK_CAN_FOCUS); - if ((style & SWT.EMBEDDED) == 0) { - if ((state & CANVAS) != 0) { - /* Prevent an input method context from being created for the Browser widget */ - if (display.getData (NO_INPUT_METHOD) == null) { - imHandle = OS.gtk_im_multicontext_new (); - if (imHandle == 0) error (SWT.ERROR_NO_HANDLES); - } - } - } - if (scrolled) { - if (fixed) OS.gtk_container_add (fixedHandle, scrolledHandle); - /* - * Force the scrolledWindow to have a single child that is - * not scrolled automatically. Calling gtk_container_add() - * seems to add the child correctly but cause a warning. - */ - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.gtk_container_add (scrolledHandle, handle); - display.setWarnings (warnings); - - int hsp = (style & SWT.H_SCROLL) != 0 ? OS.GTK_POLICY_ALWAYS : OS.GTK_POLICY_NEVER; - int vsp = (style & SWT.V_SCROLL) != 0 ? OS.GTK_POLICY_ALWAYS : OS.GTK_POLICY_NEVER; - OS.gtk_scrolled_window_set_policy (scrolledHandle, hsp, vsp); - if (hasBorder ()) { - OS.gtk_scrolled_window_set_shadow_type (scrolledHandle, OS.GTK_SHADOW_ETCHED_IN); - } - } - if ((style & SWT.EMBEDDED) != 0) { - socketHandle = OS.gtk_socket_new (); - if (socketHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (handle, socketHandle); - } - if ((style & SWT.NO_REDRAW_RESIZE) != 0 && (style & SWT.RIGHT_TO_LEFT) == 0) { - OS.gtk_widget_set_redraw_on_allocate (handle, false); - } - /* - * Bug in GTK. When a widget is double buffered and the back - * pixmap is null, the double buffer pixmap is filled with the - * background of the widget rather than the current contents of - * the screen. If nothing is drawn during an expose event, - * the pixels are altered. The fix is to clear double buffering - * when NO_BACKGROUND is set and DOUBLE_BUFFERED - * is not explicitly set. - */ - if ((style & SWT.DOUBLE_BUFFERED) == 0 && (style & SWT.NO_BACKGROUND) != 0) { - OS.gtk_widget_set_double_buffered (handle, false); - } -} - -void deregister () { - super.deregister (); - if (socketHandle != 0) display.removeWidget (socketHandle); -} - -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) { - Point pt = display.map (this, control, 0, 0); - Cairo.cairo_translate (cairo, -pt.x, -pt.y); - x += pt.x; - y += pt.y; - int /*long*/ xDisplay = OS.GDK_DISPLAY (); - int /*long*/ xVisual = OS.gdk_x11_visual_get_xvisual (OS.gdk_visual_get_system()); - int /*long*/ drawable = control.backgroundImage.pixmap; - int /*long*/ xDrawable = OS.GDK_PIXMAP_XID (drawable); - int [] w = new int [1], h = new int [1]; - OS.gdk_drawable_get_size (drawable, w, h); - 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); - if ((data.style & SWT.MIRRORED) != 0) { - double[] matrix = {-1, 0, 0, 1, 0, 0}; - Cairo.cairo_pattern_set_matrix(pattern, matrix); - } - Cairo.cairo_set_source (cairo, pattern); - Cairo.cairo_surface_destroy (surface); - Cairo.cairo_pattern_destroy (pattern); - } else { - GdkColor color = control.getBackgroundColor (); - 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 /*long*/ gdkGC = gc.handle; - GdkGCValues values = new GdkGCValues (); - OS.gdk_gc_get_values (gdkGC, values); - if (control.backgroundImage != null) { - Point pt = display.map (this, control, 0, 0); - OS.gdk_gc_set_fill (gdkGC, OS.GDK_TILED); - OS.gdk_gc_set_ts_origin (gdkGC, -pt.x, -pt.y); - OS.gdk_gc_set_tile (gdkGC, control.backgroundImage.pixmap); - OS.gdk_draw_rectangle (data.drawable, gdkGC, 1, x, y, width, height); - OS.gdk_gc_set_fill (gdkGC, values.fill); - OS.gdk_gc_set_ts_origin (gdkGC, values.ts_x_origin, values.ts_y_origin); - } else { - GdkColor color = control.getBackgroundColor (); - OS.gdk_gc_set_foreground (gdkGC, color); - OS.gdk_draw_rectangle (data.drawable, gdkGC, 1, x, y, width, height); - color.pixel = values.foreground_pixel; - OS.gdk_gc_set_foreground (gdkGC, color); - } - } - } else { - gc.fillRectangle (x, y, width, height); - } -} - -void enableWidget (boolean enabled) { - if ((state & CANVAS) != 0) return; - super.enableWidget (enabled); -} - -Composite findDeferredControl () { - return layoutCount > 0 ? this : parent.findDeferredControl (); -} - -Menu [] findMenus (Control control) { - if (control == this) return new Menu [0]; - Menu result [] = super.findMenus (control); - Control [] children = _getChildren (); - for (int i=0; i<children.length; i++) { - Control child = children [i]; - Menu [] menuList = child.findMenus (control); - if (menuList.length != 0) { - Menu [] newResult = new Menu [result.length + menuList.length]; - System.arraycopy (result, 0, newResult, 0, result.length); - System.arraycopy (menuList, 0, newResult, result.length, menuList.length); - result = newResult; - } - } - return result; -} - -void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) { - super.fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus); - Control [] children = _getChildren (); - for (int i=0; i<children.length; i++) { - children [i].fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus); - } -} - -void fixModal(int /*long*/ group, int /*long*/ modalGroup) { - Control[] controls = _getChildren (); - for (int i = 0; i < controls.length; i++) { - controls[i].fixModal (group, modalGroup); - } -} - -void fixStyle () { - super.fixStyle (); - if (scrolledHandle == 0) fixStyle (handle); - Control[] children = _getChildren (); - for (int i = 0; i < children.length; i++) { - children [i].fixStyle (); - } -} - -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; -} - -void fixZOrder () { - if ((state & CANVAS) != 0) return; - int /*long*/ parentHandle = parentingHandle (); - int /*long*/ parentWindow = OS.GTK_WIDGET_WINDOW (parentHandle); - if (parentWindow == 0) return; - int /*long*/ [] userData = new int /*long*/ [1]; - int /*long*/ windowList = OS.gdk_window_get_children (parentWindow); - if (windowList != 0) { - int /*long*/ windows = windowList; - while (windows != 0) { - int /*long*/ window = OS.g_list_data (windows); - if (window != redrawWindow) { - OS.gdk_window_get_user_data (window, userData); - if (userData [0] == 0 || OS.G_OBJECT_TYPE (userData [0]) != display.gtk_fixed_get_type ()) { - OS.gdk_window_lower (window); - } - } - windows = OS.g_list_next (windows); - } - OS.g_list_free (windowList); - } -} - -int /*long*/ focusHandle () { - if (socketHandle != 0) return socketHandle; - return super.focusHandle (); -} - -boolean forceFocus (int /*long*/ focusHandle) { - if (socketHandle != 0) OS.GTK_WIDGET_SET_FLAGS (focusHandle, OS.GTK_CAN_FOCUS); - boolean result = super.forceFocus (focusHandle); - if (socketHandle != 0) OS.GTK_WIDGET_UNSET_FLAGS (focusHandle, OS.GTK_CAN_FOCUS); - return result; -} - -/** - * 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 (); -} - -int getChildrenCount () { - /* - * NOTE: The current implementation will count - * non-registered children. - */ - int /*long*/ list = OS.gtk_container_get_children (handle); - if (list == 0) return 0; - int count = OS.g_list_length (list); - OS.g_list_free (list); - return count; -} - -public Rectangle getClientArea () { - checkWidget(); - if ((state & CANVAS) != 0) { - if ((state & ZERO_WIDTH) != 0 && (state & ZERO_HEIGHT) != 0) { - return new Rectangle (0, 0, 0, 0); - } - forceResize (); - int /*long*/ clientHandle = clientHandle (); - int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (clientHandle); - int height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (clientHandle); - return new Rectangle (0, 0, width, height); - } - return super.getClientArea(); -} - -int getClientWidth() { - return (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (clientHandle ()); -} - -/** - * 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; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_button_press_event (widget, event); - if (result != 0) return result; - if ((state & CANVAS) != 0) { - if ((style & SWT.NO_FOCUS) == 0 && hooksKeys ()) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, event, GdkEventButton.sizeof); - if (gdkEvent.button == 1) { - if (getChildrenCount () == 0) setFocus (); - } - } - } - return result; -} - -int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ eventPtr) { - if ((state & OBSCURED) != 0) return 0; - if ((state & CANVAS) == 0) { - return super.gtk_expose_event (widget, eventPtr); - } - if ((style & SWT.NO_MERGE_PAINTS) == 0) { - return super.gtk_expose_event (widget, eventPtr); - } - if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0; - GdkEventExpose gdkEvent = new GdkEventExpose (); - OS.memmove(gdkEvent, eventPtr, GdkEventExpose.sizeof); - int /*long*/ [] rectangles = new int /*long*/ [1]; - int [] n_rectangles = new int [1]; - OS.gdk_region_get_rectangles (gdkEvent.region, rectangles, n_rectangles); - GdkRectangle rect = new GdkRectangle (); - for (int i=0; i<n_rectangles[0]; i++) { - Event event = new Event (); - OS.memmove (rect, rectangles [0] + i * GdkRectangle.sizeof, GdkRectangle.sizeof); - event.x = rect.x; - event.y = rect.y; - event.width = rect.width; - event.height = rect.height; - if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.width - event.x; - int /*long*/ damageRgn = OS.gdk_region_new (); - OS.gdk_region_union_with_rect (damageRgn, rect); - GCData data = new GCData (); - data.damageRgn = damageRgn; - GC gc = event.gc = GC.gtk_new (this, data); - OS.gdk_gc_set_clip_region (gc.handle, damageRgn); - sendEvent (SWT.Paint, event); - gc.dispose (); - OS.gdk_region_destroy (damageRgn); - event.gc = null; - } - OS.g_free (rectangles [0]); - return 0; -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_key_press_event (widget, event); - if (result != 0) return result; - /* - * Feature in GTK. The default behavior when the return key - * is pressed is to select the default button. This is not the - * expected behavior for Composite and its subclasses. The - * fix is to avoid calling the default handler. - */ - if ((state & CANVAS) != 0 && socketHandle == 0) { - GdkEventKey keyEvent = new GdkEventKey (); - OS.memmove (keyEvent, event, GdkEventKey.sizeof); - int key = keyEvent.keyval; - switch (key) { - case OS.GDK_Return: - case OS.GDK_KP_Enter: return 1; - } - } - return result; -} - -int /*long*/ gtk_focus (int /*long*/ widget, int /*long*/ directionType) { - if (widget == socketHandle) return 0; - return super.gtk_focus (widget, directionType); -} - -int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_focus_in_event (widget, event); - return (state & CANVAS) != 0 ? 1 : result; -} - -int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_focus_out_event (widget, event); - return (state & CANVAS) != 0 ? 1 : result; -} - -int /*long*/ gtk_map (int /*long*/ widget) { - fixZOrder (); - return 0; -} - -int /*long*/ gtk_realize (int /*long*/ widget) { - int /*long*/ result = super.gtk_realize (widget); - if ((style & SWT.NO_BACKGROUND) != 0) { - int /*long*/ window = OS.GTK_WIDGET_WINDOW (paintHandle ()); - if (window != 0) OS.gdk_window_set_back_pixmap (window, 0, false); - } - if (socketHandle != 0) { - embeddedHandle = OS.gtk_socket_get_id (socketHandle); - } - return result; -} - -int /*long*/ gtk_scroll_child (int /*long*/ widget, int /*long*/ scrollType, int /*long*/ horizontal) { - /* Stop GTK scroll child signal for canvas */ - OS.g_signal_stop_emission_by_name (widget, OS.scroll_child); - return 1; -} - -int /*long*/ gtk_style_set (int /*long*/ widget, int /*long*/ previousStyle) { - int /*long*/ result = super.gtk_style_set (widget, previousStyle); - if ((style & SWT.NO_BACKGROUND) != 0) { - int /*long*/ window = OS.GTK_WIDGET_WINDOW (paintHandle ()); - if (window != 0) OS.gdk_window_set_back_pixmap (window, 0, false); - } - return result; -} - -boolean hasBorder () { - return (style & SWT.BORDER) != 0; -} - -void hookEvents () { - super.hookEvents (); - if ((state & CANVAS) != 0) { - OS.gtk_widget_add_events (handle, OS.GDK_POINTER_MOTION_HINT_MASK); - if (scrolledHandle != 0) { - OS.g_signal_connect_closure (scrolledHandle, OS.scroll_child, display.closures [SCROLL_CHILD], false); - } - } -} - -boolean hooksKeys () { - return hooks (SWT.KeyDown) || hooks (SWT.KeyUp); -} - -int /*long*/ imHandle () { - return imHandle; -} - -/** - * 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 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); - } - } -} - -void moveAbove (int /*long*/ child, int /*long*/ sibling) { - if (child == sibling) return; - int /*long*/ parentHandle = parentingHandle (); - GtkFixed fixed = new GtkFixed (); - OS.memmove (fixed, parentHandle); - int /*long*/ children = fixed.children; - if (children == 0) return; - int /*long*/ [] data = new int /*long*/ [1]; - int /*long*/ [] widget = new int /*long*/ [1]; - int /*long*/ childData = 0, childLink = 0, siblingLink = 0, temp = children; - while (temp != 0) { - OS.memmove (data, temp, OS.PTR_SIZEOF); - OS.memmove (widget, data [0], OS.PTR_SIZEOF); - if (child == widget [0]) { - childLink = temp; - childData = data [0]; - } else if (sibling == widget [0]) { - siblingLink = temp; - } - if (childData != 0 && (sibling == 0 || siblingLink != 0)) break; - temp = OS.g_list_next (temp); - } - children = OS.g_list_remove_link (children, childLink); - if (siblingLink == 0 || OS.g_list_previous (siblingLink) == 0) { - OS.g_list_free_1 (childLink); - children = OS.g_list_prepend (children, childData); - } else { - temp = OS.g_list_previous (siblingLink); - OS.g_list_set_previous (childLink, temp); - OS.g_list_set_next (temp, childLink); - OS.g_list_set_next (childLink, siblingLink); - OS.g_list_set_previous (siblingLink, childLink); - } - fixed.children = children; - OS.memmove (parentHandle, fixed); -} - -void moveBelow (int /*long*/ child, int /*long*/ sibling) { - if (child == sibling) return; - int /*long*/ parentHandle = parentingHandle (); - if (sibling == 0 && parentHandle == fixedHandle) { - moveAbove (child, scrolledHandle != 0 ? scrolledHandle : handle); - return; - } - GtkFixed fixed = new GtkFixed (); - OS.memmove (fixed, parentHandle); - int /*long*/ children = fixed.children; - if (children == 0) return; - int /*long*/ [] data = new int /*long*/ [1]; - int /*long*/ [] widget = new int /*long*/ [1]; - int /*long*/ childData = 0, childLink = 0, siblingLink = 0, temp = children; - while (temp != 0) { - OS.memmove (data, temp, OS.PTR_SIZEOF); - OS.memmove (widget, data [0], OS.PTR_SIZEOF); - if (child == widget [0]) { - childLink = temp; - childData = data [0]; - } else if (sibling == widget [0]) { - siblingLink = temp; - } - if (childData != 0 && (sibling == 0 || siblingLink != 0)) break; - temp = OS.g_list_next (temp); - } - children = OS.g_list_remove_link (children, childLink); - if (siblingLink == 0 || OS.g_list_next (siblingLink) == 0) { - OS.g_list_free_1 (childLink); - children = OS.g_list_append (children, childData); - } else { - temp = OS.g_list_next (siblingLink); - OS.g_list_set_next (childLink, temp); - OS.g_list_set_previous (temp, childLink); - OS.g_list_set_previous (childLink, siblingLink); - OS.g_list_set_next (siblingLink, childLink); - } - fixed.children = children; - OS.memmove (parentHandle, fixed); -} - -void moveChildren(int oldWidth) { - Control[] children = _getChildren (); - for (int i = 0; i < children.length; i++) { - Control child = children[i]; - int /*long*/ topHandle = child.topHandle (); - int x = OS.GTK_WIDGET_X (topHandle); - int y = OS.GTK_WIDGET_Y (topHandle); - int controlWidth = (child.state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle); - x = oldWidth - controlWidth - x; - int clientWidth = getClientWidth (); - x = clientWidth - controlWidth - x; - if (child.enableWindow != 0) { - OS.gdk_window_move (child.enableWindow, x, y); - } - child.moveHandle (x, y); - /* - * Cause a size allocation this widget's topHandle. Note that - * all calls to gtk_widget_size_allocate() must be preceded by - * a call to gtk_widget_size_request(). - */ - GtkRequisition requisition = new GtkRequisition (); - gtk_widget_size_request (topHandle, requisition); - GtkAllocation allocation = new GtkAllocation (); - allocation.x = x; - allocation.y = y; - allocation.width = OS.GTK_WIDGET_WIDTH (topHandle); - allocation.height = OS.GTK_WIDGET_HEIGHT (topHandle); - OS.gtk_widget_size_allocate (topHandle, allocation); - Control control = child.findBackgroundControl (); - if (control != null && control.backgroundImage != null) { - if (child.isVisible ()) child.redrawWidget (0, 0, 0, 0, true, true, true); - } - } -} - -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); -} - -int /*long*/ parentingHandle () { - if ((state & CANVAS) != 0) return handle; - return fixedHandle != 0 ? fixedHandle : handle; -} - -void printWidget (GC gc, int /*long*/ drawable, int depth, int x, int y) { - Region oldClip = new Region (gc.getDevice ()); - Region newClip = new Region (gc.getDevice ()); - gc.getClipping (oldClip); - Rectangle rect = getBounds (); - newClip.add (oldClip); - newClip.intersect (x, y, rect.width, rect.height); - gc.setClipping (newClip); - super.printWidget (gc, drawable, depth, x, y); - Rectangle clientRect = getClientArea (); - Point pt = display.map (this, parent, clientRect.x, clientRect.y); - clientRect.x = x + pt.x - rect.x; - clientRect.y = y + pt.y - rect.y; - newClip.intersect (clientRect); - gc.setClipping (newClip); - Control [] children = _getChildren (); - for (int i=children.length-1; i>=0; --i) { - Control child = children [i]; - if (child.getVisible ()) { - Point location = child.getLocation (); - child.printWidget (gc, drawable, depth, x + location.x, y + location.y); - } - } - gc.setClipping (oldClip); - oldClip.dispose (); - newClip.dispose (); -} - -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 (socketHandle != 0) display.addWidget (socketHandle, this); -} - -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 (); - socketHandle = embeddedHandle = 0; -} - -void releaseWidget () { - super.releaseWidget (); - if (imHandle != 0) OS.g_object_unref (imHandle); - imHandle = 0; - layout = null; - tabList = null; -} - -void removeControl (Control control) { - fixTabList (control); -} - -void resizeHandle (int width, int height) { - super.resizeHandle (width, height); - if (socketHandle != 0) OS.gtk_widget_set_size_request (socketHandle, width, height); -} - -/** - * 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 (); - } -} - -int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - int result = super.setBounds (x, y, width, height, move, resize); - if ((result & RESIZED) != 0 && layout != null) { - markLayout (false, false); - updateLayout (false); - } - return result; -} - -public boolean setFocus () { - checkWidget(); - Control [] children = _getChildren (); - for (int i=0; i<children.length; i++) { - Control child = children [i]; - if (child.getVisible () && child.setFocus ()) return true; - } - return super.setFocus (); -} - -/** - * 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++; - } -} - -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 (socketHandle != 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 (socketHandle != 0) { - int direction = next ? OS.GTK_DIR_TAB_FORWARD : OS.GTK_DIR_TAB_BACKWARD; - OS.GTK_WIDGET_UNSET_FLAGS (socketHandle, OS.GTK_HAS_FOCUS); - OS.gtk_widget_child_focus (socketHandle, direction); - OS.GTK_WIDGET_SET_FLAGS (socketHandle, OS.GTK_HAS_FOCUS); - } - return true; -} - -/** - * 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 showWidget () { - super.showWidget (); - if (socketHandle != 0) { - OS.gtk_widget_show (socketHandle); - embeddedHandle = OS.gtk_socket_get_id (socketHandle); - } - if (scrolledHandle == 0) fixStyle (handle); -} - -boolean checkSubwindow () { - return true; -} - -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; -} - -int traversalCode(int key, GdkEventKey event) { - if ((state & CANVAS) != 0) { - if ((style & SWT.NO_FOCUS) != 0) return 0; - if (hooksKeys ()) return 0; - } - return super.traversalCode (key, event); -} - -boolean translateTraversal (GdkEventKey keyEvent) { - if (socketHandle != 0) return false; - return super.translateTraversal (keyEvent); -} - -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); - } - } -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java deleted file mode 100644 index dbfbda20e1..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java +++ /dev/null @@ -1,4588 +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.accessibility.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.accessibility.gtk.*; -import org.eclipse.swt.internal.cairo.*; -import org.eclipse.swt.internal.gtk.*; - -/** - * 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 /*long*/ fixedHandle; - int /*long*/ redrawWindow, enableWindow; - int drawCount; - Composite parent; - Cursor cursor; - Menu menu; - Image backgroundImage; - Font font; - Region region; - String toolTipText; - Object layoutData; - Accessible accessible; - - static final String IS_ACTIVE = "org.eclipse.swt.internal.control.isactive"; //$NON-NLS-1$ - -Control () { -} - -/** - * 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); -} - -Font defaultFont () { - return display.getSystemFont (); -} - -void deregister () { - super.deregister (); - if (fixedHandle != 0) display.removeWidget (fixedHandle); - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) display.removeWidget (imHandle); -} - -boolean drawGripper (int x, int y, int width, int height, boolean vertical) { - int /*long*/ paintHandle = paintHandle (); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (paintHandle); - if (window == 0) return false; - int orientation = vertical ? OS.GTK_ORIENTATION_HORIZONTAL : OS.GTK_ORIENTATION_VERTICAL; - if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - width - x; - OS.gtk_paint_handle (OS.gtk_widget_get_style (paintHandle), window, OS.GTK_STATE_NORMAL, OS.GTK_SHADOW_OUT, null, paintHandle, new byte [1], x, y, width, height, orientation); - return true; -} - -void enableWidget (boolean enabled) { - OS.gtk_widget_set_sensitive (handle, enabled); -} - -int /*long*/ enterExitHandle () { - return eventHandle (); -} - -int /*long*/ eventHandle () { - return handle; -} - -int /*long*/ eventWindow () { - int /*long*/ eventHandle = eventHandle (); - OS.gtk_widget_realize (eventHandle); - return OS.GTK_WIDGET_WINDOW (eventHandle); -} - -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 /*long*/ focusHandle = shell.vboxHandle; - OS.GTK_WIDGET_SET_FLAGS (focusHandle, OS.GTK_CAN_FOCUS); - OS.gtk_widget_grab_focus (focusHandle); - OS.GTK_WIDGET_UNSET_FLAGS (focusHandle, OS.GTK_CAN_FOCUS); -} - -void fixStyle () { - if (fixedHandle != 0) fixStyle (fixedHandle); -} - -void fixStyle (int /*long*/ handle) { - /* - * Feature in GTK. Some GTK themes apply a different background to - * the contents of a GtkNotebook. However, in an SWT TabFolder, the - * children are not parented below the GtkNotebook widget, and usually - * have their own GtkFixed. The fix is to look up the correct style - * for a child of a GtkNotebook and apply its background to any GtkFixed - * widgets that are direct children of an SWT TabFolder. - * - * Note that this has to be when the theme settings changes and that it - * should not override the application background. - */ - if ((state & BACKGROUND) != 0) return; - if ((state & THEME_BACKGROUND) == 0) return; - int /*long*/ childStyle = parent.childStyle (); - if (childStyle != 0) { - GdkColor color = new GdkColor(); - OS.gtk_style_get_bg (childStyle, 0, color); - setBackgroundColor (color); - } -} - -int /*long*/ focusHandle () { - return handle; -} - -int /*long*/ fontHandle () { - return handle; -} - -boolean hasFocus () { - return this == display.getFocusControl(); -} - -void hookEvents () { - /* Connect the keyboard signals */ - int /*long*/ focusHandle = focusHandle (); - int focusMask = OS.GDK_KEY_PRESS_MASK | OS.GDK_KEY_RELEASE_MASK | OS.GDK_FOCUS_CHANGE_MASK; - OS.gtk_widget_add_events (focusHandle, focusMask); - OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [POPUP_MENU], 0, display.closures [POPUP_MENU], false); - OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [SHOW_HELP], 0, display.closures [SHOW_HELP], false); - OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [KEY_PRESS_EVENT], 0, display.closures [KEY_PRESS_EVENT], false); - OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [KEY_RELEASE_EVENT], 0, display.closures [KEY_RELEASE_EVENT], false); - OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [FOCUS], 0, display.closures [FOCUS], false); - OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [FOCUS_IN_EVENT], 0, display.closures [FOCUS_IN_EVENT], false); - OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [FOCUS_OUT_EVENT], 0, display.closures [FOCUS_OUT_EVENT], false); - - /* Connect the mouse signals */ - int /*long*/ eventHandle = eventHandle (); - int eventMask = OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_PRESS_MASK | OS.GDK_BUTTON_RELEASE_MASK; - OS.gtk_widget_add_events (eventHandle, eventMask); - OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false); - OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT], false); - OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [MOTION_NOTIFY_EVENT], 0, display.closures [MOTION_NOTIFY_EVENT], false); - OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [SCROLL_EVENT], 0, display.closures [SCROLL_EVENT], false); - - /* Connect enter/exit signals */ - int /*long*/ enterExitHandle = enterExitHandle (); - int enterExitMask = OS.GDK_ENTER_NOTIFY_MASK | OS.GDK_LEAVE_NOTIFY_MASK; - OS.gtk_widget_add_events (enterExitHandle, enterExitMask); - OS.g_signal_connect_closure_by_id (enterExitHandle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false); - OS.g_signal_connect_closure_by_id (enterExitHandle, display.signalIds [LEAVE_NOTIFY_EVENT], 0, display.closures [LEAVE_NOTIFY_EVENT], false); - - /* - * Feature in GTK. Events such as mouse move are propagate up - * the widget hierarchy and are seen by the parent. This is the - * correct GTK behavior but not correct for SWT. The fix is to - * hook a signal after and stop the propagation using a negative - * event number to distinguish this case. - * - * The signal is hooked to the fixedHandle to catch events sent to - * lightweight widgets. - */ - int /*long*/ blockHandle = fixedHandle != 0 ? fixedHandle : eventHandle; - OS.g_signal_connect_closure_by_id (blockHandle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT_INVERSE], true); - OS.g_signal_connect_closure_by_id (blockHandle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT_INVERSE], true); - OS.g_signal_connect_closure_by_id (blockHandle, display.signalIds [MOTION_NOTIFY_EVENT], 0, display.closures [MOTION_NOTIFY_EVENT_INVERSE], true); - - /* Connect the event_after signal for both key and mouse */ - OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [EVENT_AFTER], 0, display.closures [EVENT_AFTER], false); - if (focusHandle != eventHandle) { - OS.g_signal_connect_closure_by_id (focusHandle, display.signalIds [EVENT_AFTER], 0, display.closures [EVENT_AFTER], false); - } - - /* Connect the paint signal */ - int /*long*/ paintHandle = paintHandle (); - int paintMask = OS.GDK_EXPOSURE_MASK | OS.GDK_VISIBILITY_NOTIFY_MASK; - OS.gtk_widget_add_events (paintHandle, paintMask); - OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [EXPOSE_EVENT], 0, display.closures [EXPOSE_EVENT_INVERSE], false); - OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [VISIBILITY_NOTIFY_EVENT], 0, display.closures [VISIBILITY_NOTIFY_EVENT], false); - OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [EXPOSE_EVENT], 0, display.closures [EXPOSE_EVENT], true); - - /* Connect the Input Method signals */ - OS.g_signal_connect_closure_by_id (handle, display.signalIds [REALIZE], 0, display.closures [REALIZE], true); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [UNREALIZE], 0, display.closures [UNREALIZE], false); - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) { - OS.g_signal_connect_closure (imHandle, OS.commit, display.closures [COMMIT], false); - OS.g_signal_connect_closure (imHandle, OS.preedit_changed, display.closures [PREEDIT_CHANGED], false); - } - - OS.g_signal_connect_closure_by_id (paintHandle, display.signalIds [STYLE_SET], 0, display.closures [STYLE_SET], false); - - int /*long*/ topHandle = topHandle (); - OS.g_signal_connect_closure_by_id (topHandle, display.signalIds [MAP], 0, display.closures [MAP], true); -} - -int /*long*/ hoverProc (int /*long*/ widget) { - int [] x = new int [1], y = new int [1], mask = new int [1]; - OS.gdk_window_get_pointer (0, x, y, mask); - sendMouseEvent (SWT.MouseHover, 0, /*time*/0, x [0], y [0], false, mask [0]); - /* Always return zero in order to cancel the hover timer */ - return 0; -} - -int /*long*/ topHandle() { - if (fixedHandle != 0) return fixedHandle; - return super.topHandle (); -} - -int /*long*/ paintHandle () { - int /*long*/ topHandle = topHandle (); - int /*long*/ paintHandle = handle; - while (paintHandle != topHandle) { - if ((OS.GTK_WIDGET_FLAGS (paintHandle) & OS.GTK_NO_WINDOW) == 0) break; - paintHandle = OS.gtk_widget_get_parent (paintHandle); - } - return paintHandle; -} - -int /*long*/ paintWindow () { - int /*long*/ paintHandle = paintHandle (); - OS.gtk_widget_realize (paintHandle); - return OS.GTK_WIDGET_WINDOW (paintHandle); -} - -/** - * 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); - int /*long*/ topHandle = topHandle (); - OS.gtk_widget_realize (topHandle); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (topHandle); - GCData data = gc.getGCData (); - OS.gdk_window_process_updates (window, true); - printWidget (gc, data.drawable, OS.gdk_drawable_get_depth (data.drawable), 0, 0); - return true; -} - -void printWidget (GC gc, int /*long*/ drawable, int depth, int x, int y) { - boolean obscured = (state & OBSCURED) != 0; - state &= ~OBSCURED; - int /*long*/ topHandle = topHandle (); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (topHandle); - printWindow (true, this, gc, drawable, depth, window, x, y); - if (obscured) state |= OBSCURED; -} - -void printWindow (boolean first, Control control, GC gc, int /*long*/ drawable, int depth, int /*long*/ window, int x, int y) { - if (OS.gdk_drawable_get_depth (window) != depth) return; - GdkRectangle rect = new GdkRectangle (); - int [] width = new int [1], height = new int [1]; - OS.gdk_drawable_get_size (window, width, height); - rect.width = width [0]; - rect.height = height [0]; - OS.gdk_window_begin_paint_rect (window, rect); - int /*long*/ [] real_drawable = new int /*long*/ [1]; - int [] x_offset = new int [1], y_offset = new int [1]; - OS.gdk_window_get_internal_paint_info (window, real_drawable, x_offset, y_offset); - int /*long*/ [] userData = new int /*long*/ [1]; - OS.gdk_window_get_user_data (window, userData); - if (userData [0] != 0) { - int /*long*/ eventPtr = OS.gdk_event_new (OS.GDK_EXPOSE); - GdkEventExpose event = new GdkEventExpose (); - event.type = OS.GDK_EXPOSE; - event.window = OS.g_object_ref (window); - event.area_width = rect.width; - event.area_height = rect.height; - event.region = OS.gdk_region_rectangle (rect); - OS.memmove (eventPtr, event, GdkEventExpose.sizeof); - OS.gtk_widget_send_expose (userData [0], eventPtr); - OS.gdk_event_free (eventPtr); - } - int srcX = x_offset [0], srcY = y_offset [0]; - int destX = x, destY = y, destWidth = width [0], destHeight = height [0]; - if (!first) { - int [] cX = new int [1], cY = new int [1]; - OS.gdk_window_get_position (window, cX, cY); - int /*long*/ parentWindow = OS.gdk_window_get_parent (window); - int [] pW = new int [1], pH = new int [1]; - OS.gdk_drawable_get_size (parentWindow, pW, pH); - srcX = x_offset [0] - cX [0]; - srcY = y_offset [0] - cY [0]; - destX = x - cX [0]; - destY = y - cY [0]; - destWidth = Math.min (cX [0] + width [0], pW [0]); - destHeight = Math.min (cY [0] + height [0], pH [0]); - } - GCData gcData = gc.getGCData(); - int /*long*/ cairo = gcData.cairo; - if (cairo != 0) { - int /*long*/ xDisplay = OS.GDK_DISPLAY(); - int /*long*/ xVisual = OS.gdk_x11_visual_get_xvisual(OS.gdk_visual_get_system()); - int /*long*/ xDrawable = OS.GDK_PIXMAP_XID(real_drawable [0]); - int /*long*/ surface = Cairo.cairo_xlib_surface_create(xDisplay, xDrawable, xVisual, width [0], height [0]); - if (surface == 0) SWT.error(SWT.ERROR_NO_HANDLES); - Cairo.cairo_save(cairo); - Cairo.cairo_rectangle(cairo, destX , destY, destWidth, destHeight); - Cairo.cairo_clip(cairo); - Cairo.cairo_translate(cairo, destX, destY); - int /*long*/ pattern = Cairo.cairo_pattern_create_for_surface(surface); - if (pattern == 0) SWT.error(SWT.ERROR_NO_HANDLES); - Cairo.cairo_pattern_set_filter(pattern, Cairo.CAIRO_FILTER_BEST); - Cairo.cairo_set_source(cairo, pattern); - if (gcData.alpha != 0xFF) { - Cairo.cairo_paint_with_alpha(cairo, gcData.alpha / (float)0xFF); - } else { - Cairo.cairo_paint(cairo); - } - Cairo.cairo_restore(cairo); - Cairo.cairo_pattern_destroy(pattern); - Cairo.cairo_surface_destroy(surface); - } else { - OS.gdk_draw_drawable (drawable, gc.handle, real_drawable [0], srcX, srcY, destX, destY, destWidth, destHeight); - } - OS.gdk_window_end_paint (window); - int /*long*/ children = OS.gdk_window_get_children (window); - if (children != 0) { - int /*long*/ windows = children; - while (windows != 0) { - int /*long*/ child = OS.g_list_data (windows); - if (OS.gdk_window_is_visible (child)) { - int /*long*/ [] data = new int /*long*/ [1]; - OS.gdk_window_get_user_data (child, data); - if (data [0] != 0) { - Widget widget = display.findWidget (data [0]); - if (widget == null || widget == control) { - int [] x_pos = new int [1], y_pos = new int [1]; - OS.gdk_window_get_position (child, x_pos, y_pos); - printWindow (false, control, gc, drawable, depth, child, x + x_pos [0], y + y_pos [0]); - } - } - } - windows = OS.g_list_next (windows); - } - OS.g_list_free (children); - } -} - -/** - * 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); -} - -Widget computeTabGroup () { - if (isTabGroup()) return this; - return parent.computeTabGroup (); -} - -Widget[] computeTabList() { - if (isTabGroup()) { - if (getVisible() && getEnabled()) { - return new Widget[] {this}; - } - } - return new Widget[0]; -} - -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 (); -} - -void checkBuffered () { - style |= SWT.DOUBLE_BUFFERED; -} - -void checkBackground () { - Shell shell = getShell (); - if (this == shell) return; - state &= ~PARENT_BACKGROUND; - Composite composite = parent; - do { - int mode = composite.backgroundMode; - if (mode != SWT.INHERIT_NONE) { - 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 checkBorder () { - if (getBorderWidth () == 0) style &= ~SWT.BORDER; -} - -void checkMirrored () { - if ((style & SWT.RIGHT_TO_LEFT) != 0) style |= SWT.MIRRORED; -} - -int /*long*/ childStyle () { - return parent.childStyle (); -} - -void createWidget (int index) { - state |= DRAG_DETECT; - checkOrientation (parent); - super.createWidget (index); - checkBackground (); - if ((state & PARENT_BACKGROUND) != 0) setBackground (); - checkBuffered (); - showWidget (); - setInitialBounds (); - setZOrder (null, false, false); - setRelations (); - checkMirrored (); - checkBorder (); -} - -/** - * 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(); - if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; - if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; - return computeNativeSize (handle, wHint, hHint, changed); -} - -Point computeNativeSize (int /*long*/ h, int wHint, int hHint, boolean changed) { - int width = wHint, height = hHint; - if (wHint == SWT.DEFAULT && hHint == SWT.DEFAULT) { - GtkRequisition requisition = new GtkRequisition (); - gtk_widget_size_request (h, requisition); - width = OS.GTK_WIDGET_REQUISITION_WIDTH (h); - height = OS.GTK_WIDGET_REQUISITION_HEIGHT (h); - } else if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) { - int [] reqWidth = new int [1], reqHeight = new int [1]; - OS.gtk_widget_get_size_request (h, reqWidth, reqHeight); - OS.gtk_widget_set_size_request (h, wHint, hHint); - GtkRequisition requisition = new GtkRequisition (); - gtk_widget_size_request (h, requisition); - OS.gtk_widget_set_size_request (h, reqWidth [0], reqHeight [0]); - width = wHint == SWT.DEFAULT ? requisition.width : wHint; - height = hHint == SWT.DEFAULT ? requisition.height : hHint; - } - return new Point (width, height); -} - -void forceResize () { - /* - * Force size allocation on all children of this widget's - * topHandle. Note that all calls to gtk_widget_size_allocate() - * must be preceded by a call to gtk_widget_size_request(). - */ - int /*long*/ topHandle = topHandle (); - GtkRequisition requisition = new GtkRequisition (); - gtk_widget_size_request (topHandle, requisition); - GtkAllocation allocation = new GtkAllocation (); - allocation.x = OS.GTK_WIDGET_X (topHandle); - allocation.y = OS.GTK_WIDGET_Y (topHandle); - allocation.width = OS.GTK_WIDGET_WIDTH (topHandle); - allocation.height = OS.GTK_WIDGET_HEIGHT (topHandle); - OS.gtk_widget_size_allocate (topHandle, allocation); -} - -/** - * 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 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 /*long*/ topHandle = topHandle (); - int x = OS.GTK_WIDGET_X (topHandle); - int y = OS.GTK_WIDGET_Y (topHandle); - int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle); - int height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (topHandle); - if ((parent.style & SWT.MIRRORED) != 0) x = parent.getClientWidth () - width - x; - return new Rectangle (x, y, width, height); -} - -/** - * 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, Math.max (0, rect.width), Math.max (0, rect.height), true, true); -} - -/** - * 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); -} - -void markLayout (boolean changed, boolean all) { - /* Do nothing */ -} - -void modifyStyle (int /*long*/ handle, int /*long*/ style) { - super.modifyStyle(handle, style); - /* - * Bug in GTK. When changing the style of a control that - * has had a region set on it, the region is lost. The - * fix is to set the region again. - */ - if (region != null) OS.gdk_window_shape_combine_region (OS.GTK_WIDGET_WINDOW (topHandle ()), region.handle, 0, 0); -} - -void moveHandle (int x, int y) { - int /*long*/ topHandle = topHandle (); - int /*long*/ parentHandle = parent.parentingHandle (); - /* - * Feature in GTK. Calling gtk_fixed_move() to move a child causes - * the whole parent to redraw. This is a performance problem. The - * fix is temporarily make the parent not visible during the move. - * - * NOTE: Because every widget in SWT has an X window, the new and - * old bounds of the child are correctly redrawn. - */ - int flags = OS.GTK_WIDGET_FLAGS (parentHandle); - OS.GTK_WIDGET_UNSET_FLAGS (parentHandle, OS.GTK_VISIBLE); - OS.gtk_fixed_move (parentHandle, topHandle, x, y); - if ((flags & OS.GTK_VISIBLE) != 0) { - OS.GTK_WIDGET_SET_FLAGS (parentHandle, OS.GTK_VISIBLE); - } -} - -void resizeHandle (int width, int height) { - int /*long*/ topHandle = topHandle (); - OS.gtk_widget_set_size_request (topHandle, width, height); - if (topHandle != handle) OS.gtk_widget_set_size_request (handle, width, height); -} - -int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - int /*long*/ topHandle = topHandle (); - boolean sendMove = move; - if ((parent.style & SWT.MIRRORED) != 0) { - int clientWidth = parent.getClientWidth (); - int oldWidth = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle); - int oldX = clientWidth - oldWidth - OS.GTK_WIDGET_X (topHandle); - if (move) { - sendMove &= x != oldX; - x = clientWidth - (resize ? width : oldWidth) - x; - } else { - move = true; - x = clientWidth - (resize ? width : oldWidth) - oldX; - y = OS.GTK_WIDGET_Y (topHandle); - } - } - boolean sameOrigin = true, sameExtent = true; - if (move) { - int oldX = OS.GTK_WIDGET_X (topHandle); - int oldY = OS.GTK_WIDGET_Y (topHandle); - sameOrigin = x == oldX && y == oldY; - if (!sameOrigin) { - if (enableWindow != 0) { - OS.gdk_window_move (enableWindow, x, y); - } - moveHandle (x, y); - } - } - int clientWidth = 0; - if (resize) { - int oldWidth = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle); - int oldHeight = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (topHandle); - sameExtent = width == oldWidth && height == oldHeight; - if (!sameExtent && (style & SWT.MIRRORED) != 0) clientWidth = getClientWidth (); - if (!sameExtent && !(width == 0 && height == 0)) { - int newWidth = Math.max (1, width); - int newHeight = Math.max (1, height); - if (redrawWindow != 0) { - OS.gdk_window_resize (redrawWindow, newWidth, newHeight); - } - if (enableWindow != 0) { - OS.gdk_window_resize (enableWindow, newWidth, newHeight); - } - resizeHandle (newWidth, newHeight); - } - } - if (!sameOrigin || !sameExtent) { - /* - * Cause a size allocation this widget's topHandle. Note that - * all calls to gtk_widget_size_allocate() must be preceded by - * a call to gtk_widget_size_request(). - */ - GtkRequisition requisition = new GtkRequisition (); - gtk_widget_size_request (topHandle, requisition); - GtkAllocation allocation = new GtkAllocation (); - if (move) { - allocation.x = x; - allocation.y = y; - } else { - allocation.x = OS.GTK_WIDGET_X (topHandle); - allocation.y = OS.GTK_WIDGET_Y (topHandle); - } - if (resize) { - allocation.width = width; - allocation.height = height; - } else { - allocation.width = OS.GTK_WIDGET_WIDTH (topHandle); - allocation.height = OS.GTK_WIDGET_HEIGHT (topHandle); - } - OS.gtk_widget_size_allocate (topHandle, allocation); - } - /* - * Bug in GTK. Widgets cannot be sized smaller than 1x1. - * The fix is to hide zero-sized widgets and show them again - * when they are resized larger. - */ - if (!sameExtent) { - state = (width == 0) ? state | ZERO_WIDTH : state & ~ZERO_WIDTH; - state = (height == 0) ? state | ZERO_HEIGHT : state & ~ZERO_HEIGHT; - if ((state & (ZERO_WIDTH | ZERO_HEIGHT)) != 0) { - if (enableWindow != 0) { - OS.gdk_window_hide (enableWindow); - } - OS.gtk_widget_hide (topHandle); - } else { - if ((state & HIDDEN) == 0) { - if (enableWindow != 0) { - OS.gdk_window_show_unraised (enableWindow); - } - OS.gtk_widget_show (topHandle); - } - } - if ((style & SWT.MIRRORED) != 0) moveChildren (clientWidth); - } - int result = 0; - if (move && !sameOrigin) { - Control control = findBackgroundControl (); - if (control != null && control.backgroundImage != null) { - if (isVisible ()) redrawWidget (0, 0, 0, 0, true, true, true); - } - if (sendMove) sendEvent (SWT.Move); - result |= MOVED; - } - if (resize && !sameExtent) { - sendEvent (SWT.Resize); - result |= RESIZED; - } - return result; -} - -/** - * 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 /*long*/ topHandle = topHandle (); - int x = OS.GTK_WIDGET_X (topHandle); - int y = OS.GTK_WIDGET_Y (topHandle); - if ((parent.style & SWT.MIRRORED) != 0) { - int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle); - x = parent.getClientWidth () - width - x; - } - return new Point (x, y); -} - -/** - * 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 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); -} - -/** - * 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 /*long*/ topHandle = topHandle (); - int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle); - int height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (topHandle); - return new Point (width, height); -} - -/** - * 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, Math.max (0, size.x), Math.max (0, size.y), false, true); -} - -/** - * 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 /*long*/ window = OS.GTK_WIDGET_WINDOW (topHandle ()); - int /*long*/ shape_region = (region == null) ? 0 : region.handle; - OS.gdk_window_shape_combine_region (window, shape_region, 0, 0); - this.region = region; -} - -void setRelations () { - int /*long*/ parentHandle = parent.parentingHandle (); - int /*long*/ list = OS.gtk_container_get_children (parentHandle); - if (list == 0) return; - int count = OS.g_list_length (list); - if (count > 1) { - /* - * the receiver is the last item in the list, so its predecessor will - * be the second-last item in the list - */ - int /*long*/ handle = OS.g_list_nth_data (list, count - 2); - if (handle != 0) { - Widget widget = display.getWidget (handle); - if (widget != null && widget != this) { - if (widget instanceof Control) { - Control sibling = (Control)widget; - sibling.addRelation (this); - } - } - } - } - OS.g_list_free (list); -} - -/** - * 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); -} - - -boolean isActive () { - return getShell ().getModalShell () == null && display.getModalDialog () == null; -} - -/* - * Answers a boolean indicating whether a Label that precedes the receiver in - * a layout should be read by screen readers as the recevier's label. - */ -boolean isDescribedByLabel () { - return true; -} - -boolean isFocusHandle (int /*long*/ widget) { - return widget == focusHandle (); -} - -/** - * 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, 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, true); -} - -void moveChildren (int oldWidth) { -} - -/** - * 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 () { - 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) { - setSize (computeSize (SWT.DEFAULT, SWT.DEFAULT, changed)); -} - -/** - * 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; -} - -/** - * 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 (); - int /*long*/ window = eventWindow (); - int [] origin_x = new int [1], origin_y = new int [1]; - OS.gdk_window_get_origin (window, origin_x, origin_y); - x -= origin_x [0]; - y -= origin_y [0]; - if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x; - return new Point (x, y); -} - -/** - * 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(); - int /*long*/ window = eventWindow (); - int [] origin_x = new int [1], origin_y = new int [1]; - OS.gdk_window_get_origin (window, origin_x, origin_y); - if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x; - x += origin_x [0]; - y += origin_y [0]; - return new Point (x, 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 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); -} - -/** - * 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); -} - -void addRelation (Control control) { -} - -/** - * 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); -} - -/** - * 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); -} - -/* - * Remove "Labelled by" relations from the receiver. - */ -void removeRelation () { - if (!isDescribedByLabel ()) return; /* there will not be any */ - int /*long*/ accessible = OS.gtk_widget_get_accessible (handle); - if (accessible == 0) return; - int /*long*/ set = ATK.atk_object_ref_relation_set (accessible); - int count = ATK.atk_relation_set_get_n_relations (set); - for (int i = 0; i < count; i++) { - int /*long*/ relation = ATK.atk_relation_set_get_relation (set, 0); - ATK.atk_relation_set_remove (set, relation); - } - OS.g_object_unref (set); -} - -/** - * 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); -} - -/** - * 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 != 1 || 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 filter, boolean [] consume) { - boolean quit = false, dragging = false; - while (!quit) { - int /*long*/ eventPtr = 0; - /* - * There should be an event on the queue already, but - * in cases where there isn't one, stop trying after - * half a second. - */ - long timeout = System.currentTimeMillis() + 500; - while (System.currentTimeMillis() < timeout) { - eventPtr = OS.gdk_event_get (); - if (eventPtr != 0) { - break; - } else { - try {Thread.sleep(50);} catch (Exception ex) {} - } - } - if (eventPtr == 0) return false; - switch (OS.GDK_EVENT_TYPE (eventPtr)) { - case OS.GDK_MOTION_NOTIFY: { - GdkEventMotion gdkMotionEvent = new GdkEventMotion (); - OS.memmove (gdkMotionEvent, eventPtr, GdkEventMotion.sizeof); - if ((gdkMotionEvent.state & OS.GDK_BUTTON1_MASK) != 0) { - if (OS.gtk_drag_check_threshold (handle, x, y, (int) gdkMotionEvent.x, (int) gdkMotionEvent.y)) { - dragging = true; - quit = true; - } - } else { - quit = true; - } - int [] newX = new int [1], newY = new int [1]; - OS.gdk_window_get_pointer (gdkMotionEvent.window, newX, newY, null); - break; - } - case OS.GDK_KEY_PRESS: - case OS.GDK_KEY_RELEASE: { - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof); - if (gdkEvent.keyval == OS.GDK_Escape) quit = true; - break; - } - case OS.GDK_BUTTON_RELEASE: - case OS.GDK_BUTTON_PRESS: - case OS.GDK_2BUTTON_PRESS: - case OS.GDK_3BUTTON_PRESS: { - OS.gdk_event_put (eventPtr); - quit = true; - break; - } - default: - OS.gtk_main_do_event (eventPtr); - } - OS.gdk_event_free (eventPtr); - } - return dragging; -} - -boolean filterKey (int keyval, int /*long*/ event) { - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) { - return OS.gtk_im_context_filter_keypress (imHandle, event); - } - return false; -} - -Control findBackgroundControl () { - if ((state & BACKGROUND) != 0 || backgroundImage != null) return this; - return (state & PARENT_BACKGROUND) != 0 ? parent.findBackgroundControl () : null; -} - -Menu [] findMenus (Control control) { - if (menu != null && this != control) return new Menu [] {menu}; - return new Menu [0]; -} - -void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) { - oldShell.fixShell (newShell, this); - oldDecorations.fixDecorations (newDecorations, this, menus); -} - -int /*long*/ fixedMapProc (int /*long*/ widget) { - OS.GTK_WIDGET_SET_FLAGS (widget, OS.GTK_MAPPED); - int /*long*/ widgetList = OS.gtk_container_get_children (widget); - if (widgetList != 0) { - int /*long*/ widgets = widgetList; - while (widgets != 0) { - int /*long*/ child = OS.g_list_data (widgets); - if (OS.GTK_WIDGET_VISIBLE (child) && OS.gtk_widget_get_child_visible (child) && !OS.GTK_WIDGET_MAPPED (child)) { - OS.gtk_widget_map (child); - } - widgets = OS.g_list_next (widgets); - } - OS.g_list_free (widgetList); - } - if ((OS.GTK_WIDGET_FLAGS (widget) & OS.GTK_NO_WINDOW) == 0) { - OS.gdk_window_show_unraised (OS.GTK_WIDGET_WINDOW (widget)); - } - return 0; -} - -void fixModal(int /*long*/ group, int /*long*/ modalGroup) { -} - -/** - * 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; - Shell shell = getShell (); - shell.setSavedFocus (this); - if (!isEnabled () || !isVisible ()) return false; - shell.bringToTop (false); - return forceFocus (focusHandle ()); -} - -boolean forceFocus (int /*long*/ focusHandle) { - if (OS.GTK_WIDGET_HAS_FOCUS (focusHandle)) return true; - /* When the control is zero sized it must be realized */ - OS.gtk_widget_realize (focusHandle); - OS.gtk_widget_grab_focus (focusHandle); - Shell shell = getShell (); - int /*long*/ shellHandle = shell.shellHandle; - int /*long*/ handle = OS.gtk_window_get_focus (shellHandle); - while (handle != 0) { - if (handle == focusHandle) { - /* Cancel any previous ignoreFocus requests */ - display.ignoreFocus = false; - return true; - } - Widget widget = display.getWidget (handle); - if (widget != null && widget instanceof Control) { - return widget == this; - } - handle = OS.gtk_widget_get_parent (handle); - } - return false; -} - -/** - * 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.gtk_new (display, control.getBackgroundColor ()); -} - -GdkColor getBackgroundColor () { - return getBgColor (); -} - -/** - * 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; -} - -GdkColor getBgColor () { - int /*long*/ fontHandle = fontHandle (); - OS.gtk_widget_realize (fontHandle); - GdkColor color = new GdkColor (); - OS.gtk_style_get_bg (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color); - return color; -} - -GdkColor getBaseColor () { - int /*long*/ fontHandle = fontHandle (); - OS.gtk_widget_realize (fontHandle); - GdkColor color = new GdkColor (); - OS.gtk_style_get_base (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color); - return color; -} - -/** - * 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(); - return 0; -} - -int getClientWidth () { - return 0; -} - -/** - * 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; -} - -public Object getData(String key) { - if (key.equals(IS_ACTIVE)) return new Boolean(isActive ()); - return super.getData(key); -} - -/** - * 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 (); - return (state & DISABLED) == 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 != null ? font : defaultFont (); -} - -int /*long*/ getFontDescription () { - int /*long*/ fontHandle = fontHandle (); - OS.gtk_widget_realize (fontHandle); - return OS.gtk_style_get_font_desc (OS.gtk_widget_get_style (fontHandle)); -} - -/** - * 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.gtk_new (display, getForegroundColor ()); -} - -GdkColor getForegroundColor () { - return getFgColor (); -} - -GdkColor getFgColor () { - int /*long*/ fontHandle = fontHandle (); - OS.gtk_widget_realize (fontHandle); - GdkColor color = new GdkColor (); - OS.gtk_style_get_fg (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color); - return color; -} - -Point getIMCaretPos () { - return new Point (0, 0); -} - -GdkColor getTextColor () { - int /*long*/ fontHandle = fontHandle (); - OS.gtk_widget_realize (fontHandle); - GdkColor color = new GdkColor (); - OS.gtk_style_get_text (OS.gtk_widget_get_style (fontHandle), OS.GTK_STATE_NORMAL, color); - return color; -} - -/** - * 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 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; -} - -/** - * Returns the receiver's monitor. - * - * @return the receiver's monitor - * - * @since 3.0 - */ -public Monitor getMonitor () { - checkWidget(); - Monitor monitor = null; - int /*long*/ screen = OS.gdk_screen_get_default (); - if (screen != 0) { - int monitorNumber = OS.gdk_screen_get_monitor_at_window (screen, paintWindow ()); - GdkRectangle dest = new GdkRectangle (); - OS.gdk_screen_get_monitor_geometry (screen, monitorNumber, dest); - monitor = new Monitor (); - monitor.handle = monitorNumber; - monitor.x = dest.x; - monitor.y = dest.y; - monitor.width = dest.width; - monitor.height = dest.height; - Rectangle workArea = null; - if (monitorNumber == 0) workArea = display.getWorkArea (); - if (workArea != null) { - monitor.clientX = workArea.x; - monitor.clientY = workArea.y; - monitor.clientWidth = workArea.width; - monitor.clientHeight = workArea.height; - } else { - monitor.clientX = monitor.x; - monitor.clientY = monitor.y; - monitor.clientWidth = monitor.width; - monitor.clientHeight = monitor.height; - } - } else { - monitor = display.getPrimaryMonitor (); - } - return monitor; -} - -/** - * 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 _getShell(); -} - -Shell _getShell() { - return parent._getShell(); -} - -/** - * 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(); - return (state & HIDDEN) == 0; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - return gtk_button_press_event (widget, event, true); -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event, boolean sendMouseDown) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, event, GdkEventButton.sizeof); - if (gdkEvent.type == OS.GDK_3BUTTON_PRESS) return 0; - - /* - * 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. - */ - Shell shell = _getShell (); - if (((shell.style & SWT.ON_TOP) != 0) && (((shell.style & SWT.NO_FOCUS) == 0) || ((style & SWT.NO_FOCUS) == 0))) { - shell.forceActive(); - } - int /*long*/ result = 0; - if (gdkEvent.type == OS.GDK_BUTTON_PRESS) { - display.clickCount = 1; - int /*long*/ nextEvent = OS.gdk_event_peek (); - if (nextEvent != 0) { - int eventType = OS.GDK_EVENT_TYPE (nextEvent); - if (eventType == OS.GDK_2BUTTON_PRESS) display.clickCount = 2; - if (eventType == OS.GDK_3BUTTON_PRESS) display.clickCount = 3; - OS.gdk_event_free (nextEvent); - } - boolean dragging = false; - if ((state & DRAG_DETECT) != 0 && hooks (SWT.DragDetect)) { - if (gdkEvent.button == 1) { - boolean [] consume = new boolean [1]; - if (dragDetect ((int) gdkEvent.x, (int) gdkEvent.y, true, consume)) { - dragging = true; - if (consume [0]) result = 1; - } - if (isDisposed ()) return 1; - } - } - if (sendMouseDown && !sendMouseEvent (SWT.MouseDown, gdkEvent.button, display.clickCount, 0, false, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state)) { - result = 1; - } - if (isDisposed ()) return 1; - if (dragging) { - sendDragEvent (gdkEvent.button, gdkEvent.state, (int) gdkEvent.x, (int) gdkEvent.y, false); - if (isDisposed ()) return 1; - } - /* - * Pop up the context menu in the button press event for widgets - * that have default operating system menus in order to stop the - * operating system from displaying the menu if necessary. - */ - if ((state & MENU) != 0) { - if (gdkEvent.button == 3) { - if (showMenu ((int)gdkEvent.x_root, (int)gdkEvent.y_root)) { - result = 1; - } - } - } - } else { - display.clickCount = 2; - result = sendMouseEvent (SWT.MouseDoubleClick, gdkEvent.button, display.clickCount, 0, false, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1; - if (isDisposed ()) return 1; - } - if (!shell.isDisposed ()) shell.setActiveControl (this); - return result; -} - -int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ event) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, event, GdkEventButton.sizeof); - /* - * Feature in GTK. When button 4, 5, 6, or 7 is released, GTK - * does not deliver a corresponding GTK event. Button 6 and 7 - * are mapped to buttons 4 and 5 in SWT. The fix is to change - * the button number of the event to a negative number so that - * it gets dispatched by GTK. SWT has been modified to look - * for negative button numbers. - */ - int button = gdkEvent.button; - switch (button) { - case -6: button = 4; break; - case -7: button = 5; break; - } - return sendMouseEvent (SWT.MouseUp, button, display.clickCount, 0, false, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1; -} - -int /*long*/ gtk_commit (int /*long*/ imcontext, int /*long*/ text) { - if (text == 0) return 0; - int length = OS.strlen (text); - if (length == 0) return 0; - byte [] buffer = new byte [length]; - OS.memmove (buffer, text, length); - char [] chars = Converter.mbcsToWcs (null, buffer); - sendIMKeyEvent (SWT.KeyDown, null, chars); - return 0; -} - -int /*long*/ gtk_enter_notify_event (int /*long*/ widget, int /*long*/ event) { - if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0)) { - /* - * Feature in GTK. Children of a shell will inherit and display the shell's - * tooltip if they do not have a tooltip of their own. The fix is to use the - * new tooltip API in GTK 2.12 to null the shell's tooltip when the control - * being entered does not have any tooltip text set. - */ - byte [] buffer = null; - if (toolTipText != null && toolTipText.length() != 0) { - char [] chars = fixMnemonic (toolTipText, false); - buffer = Converter.wcsToMbcs (null, chars, true); - } - int /*long*/ toolHandle = getShell().handle; - OS.gtk_widget_set_tooltip_text (toolHandle, buffer); - } - if (display.currentControl == this) return 0; - GdkEventCrossing gdkEvent = new GdkEventCrossing (); - OS.memmove (gdkEvent, event, GdkEventCrossing.sizeof); - /* - * It is possible to send out too many enter/exit events if entering a - * control through a subwindow. The fix is to return without sending any - * events if the GdkEventCrossing subwindow field is set and the control - * requests to check the field. - */ - if (gdkEvent.subwindow != 0 && checkSubwindow ()) return 0; - if (gdkEvent.mode != OS.GDK_CROSSING_NORMAL && gdkEvent.mode != OS.GDK_CROSSING_UNGRAB) return 0; - if ((gdkEvent.state & (OS.GDK_BUTTON1_MASK | OS.GDK_BUTTON2_MASK | OS.GDK_BUTTON3_MASK)) != 0) return 0; - if (display.currentControl != null && !display.currentControl.isDisposed ()) { - display.removeMouseHoverTimeout (display.currentControl.handle); - display.currentControl.sendMouseEvent (SWT.MouseExit, 0, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state); - } - if (!isDisposed ()) { - display.currentControl = this; - return sendMouseEvent (SWT.MouseEnter, 0, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1; - } - return 0; -} - -boolean checkSubwindow () { - return false; -} - -int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) { - GdkEvent event = new GdkEvent (); - OS.memmove (event, gdkEvent, GdkEvent.sizeof); - switch (event.type) { - case OS.GDK_BUTTON_PRESS: { - if (widget != eventHandle ()) break; - /* - * Pop up the context menu in the event_after signal to allow - * the widget to process the button press. This allows widgets - * such as GtkTreeView to select items before a menu is shown. - */ - if ((state & MENU) == 0) { - GdkEventButton gdkEventButton = new GdkEventButton (); - OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof); - if (gdkEventButton.button == 3) { - showMenu ((int) gdkEventButton.x_root, (int) gdkEventButton.y_root); - } - } - break; - } - case OS.GDK_FOCUS_CHANGE: { - if (!isFocusHandle (widget)) break; - GdkEventFocus gdkEventFocus = new GdkEventFocus (); - OS.memmove (gdkEventFocus, gdkEvent, GdkEventFocus.sizeof); - - /* - * Feature in GTK. The GTK combo box popup under some window managers - * is implemented as a GTK_MENU. When it pops up, it causes the combo - * box to lose focus when focus is received for the menu. The - * fix is to check the current grab handle and see if it is a GTK_MENU - * and ignore the focus event when the menu is both shown and hidden. - * - * NOTE: This code runs for all menus. - */ - Display display = this.display; - if (gdkEventFocus.in != 0) { - if (display.ignoreFocus) { - display.ignoreFocus = false; - break; - } - } else { - display.ignoreFocus = false; - int /*long*/ grabHandle = OS.gtk_grab_get_current (); - if (grabHandle != 0) { - if (OS.G_OBJECT_TYPE (grabHandle) == OS.GTK_TYPE_MENU ()) { - display.ignoreFocus = true; - break; - } - } - } - - sendFocusEvent (gdkEventFocus.in != 0 ? SWT.FocusIn : SWT.FocusOut); - break; - } - } - return 0; -} - -int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ eventPtr) { - if ((state & OBSCURED) != 0) return 0; - if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0; - GdkEventExpose gdkEvent = new GdkEventExpose (); - OS.memmove(gdkEvent, eventPtr, GdkEventExpose.sizeof); - Event event = new Event (); - event.count = gdkEvent.count; - event.x = gdkEvent.area_x; - event.y = gdkEvent.area_y; - event.width = gdkEvent.area_width; - event.height = gdkEvent.area_height; - if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.width - event.x; - GCData data = new GCData (); - data.damageRgn = gdkEvent.region; - GC gc = event.gc = GC.gtk_new (this, data); - OS.gdk_gc_set_clip_region (gc.handle, gdkEvent.region); - sendEvent (SWT.Paint, event); - gc.dispose (); - event.gc = null; - return 0; -} - -int /*long*/ gtk_focus (int /*long*/ widget, int /*long*/ directionType) { - /* Stop GTK traversal for every widget */ - return 1; -} - -int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) { - // widget could be disposed at this point - if (handle != 0) { - Control oldControl = display.imControl; - if (oldControl != this) { - if (oldControl != null && !oldControl.isDisposed ()) { - int /*long*/ oldIMHandle = oldControl.imHandle (); - if (oldIMHandle != 0) OS.gtk_im_context_reset (oldIMHandle); - } - } - if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) { - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) OS.gtk_im_context_focus_in (imHandle); - } - } - return 0; -} - -int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) { - // widget could be disposed at this point - if (handle != 0) { - if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) { - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) { - OS.gtk_im_context_focus_out (imHandle); - } - } - } - return 0; -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) { - if (!hasFocus ()) return 0; - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, event, GdkEventKey.sizeof); - - if (translateMnemonic (gdkEvent.keyval, gdkEvent)) return 1; - // widget could be disposed at this point - if (isDisposed ()) return 0; - - if (filterKey (gdkEvent.keyval, event)) return 1; - // widget could be disposed at this point - if (isDisposed ()) return 0; - - if (translateTraversal (gdkEvent)) return 1; - // widget could be disposed at this point - if (isDisposed ()) return 0; - return super.gtk_key_press_event (widget, event); -} - -int /*long*/ gtk_key_release_event (int /*long*/ widget, int /*long*/ event) { - if (!hasFocus ()) return 0; - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) { - if (OS.gtk_im_context_filter_keypress (imHandle, event)) return 1; - } - return super.gtk_key_release_event (widget, event); -} - -int /*long*/ gtk_leave_notify_event (int /*long*/ widget, int /*long*/ event) { - if (display.currentControl != this) return 0; - display.removeMouseHoverTimeout (handle); - int result = 0; - if (sendLeaveNotify () || display.getCursorControl () == null) { - GdkEventCrossing gdkEvent = new GdkEventCrossing (); - OS.memmove (gdkEvent, event, GdkEventCrossing.sizeof); - if (gdkEvent.mode != OS.GDK_CROSSING_NORMAL && gdkEvent.mode != OS.GDK_CROSSING_UNGRAB) return 0; - if ((gdkEvent.state & (OS.GDK_BUTTON1_MASK | OS.GDK_BUTTON2_MASK | OS.GDK_BUTTON3_MASK)) != 0) return 0; - result = sendMouseEvent (SWT.MouseExit, 0, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1; - display.currentControl = null; - } - return result; -} - -int /*long*/ gtk_mnemonic_activate (int /*long*/ widget, int /*long*/ arg1) { - int result = 0; - int /*long*/ eventPtr = OS.gtk_get_current_event (); - if (eventPtr != 0) { - GdkEventKey keyEvent = new GdkEventKey (); - OS.memmove (keyEvent, eventPtr, GdkEventKey.sizeof); - if (keyEvent.type == OS.GDK_KEY_PRESS) { - Control focusControl = display.getFocusControl (); - int /*long*/ focusHandle = focusControl != null ? focusControl.focusHandle () : 0; - if (focusHandle != 0) { - display.mnemonicControl = this; - OS.gtk_widget_event (focusHandle, eventPtr); - display.mnemonicControl = null; - } - result = 1; - } - OS.gdk_event_free (eventPtr); - } - return result; -} - -int /*long*/ gtk_motion_notify_event (int /*long*/ widget, int /*long*/ event) { - GdkEventMotion gdkEvent = new GdkEventMotion (); - OS.memmove (gdkEvent, event, GdkEventMotion.sizeof); - if (this == display.currentControl && (hooks (SWT.MouseHover) || filters (SWT.MouseHover))) { - display.addMouseHoverTimeout (handle); - } - double x = gdkEvent.x_root, y = gdkEvent.y_root; - int state = gdkEvent.state; - if (gdkEvent.is_hint != 0) { - int [] pointer_x = new int [1], pointer_y = new int [1], mask = new int [1]; - int /*long*/ window = eventWindow (); - OS.gdk_window_get_pointer (window, pointer_x, pointer_y, mask); - x = pointer_x [0]; - y = pointer_y [0]; - state = mask [0]; - } - int result = sendMouseEvent (SWT.MouseMove, 0, gdkEvent.time, x, y, gdkEvent.is_hint != 0, state) ? 0 : 1; - return result; -} - -int /*long*/ gtk_popup_menu (int /*long*/ widget) { - if (!hasFocus()) return 0; - int [] x = new int [1], y = new int [1]; - OS.gdk_window_get_pointer (0, x, y, null); - return showMenu (x [0], y [0]) ? 1 : 0; -} - -int /*long*/ gtk_preedit_changed (int /*long*/ imcontext) { - display.showIMWindow (this); - return 0; -} - -int /*long*/ gtk_realize (int /*long*/ widget) { - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) { - int /*long*/ window = OS.GTK_WIDGET_WINDOW (paintHandle ()); - OS.gtk_im_context_set_client_window (imHandle, window); - } - if (backgroundImage != null) { - int /*long*/ window = OS.GTK_WIDGET_WINDOW (paintHandle ()); - if (window != 0) OS.gdk_window_set_back_pixmap (window, backgroundImage.pixmap, false); - } - return 0; -} - -int /*long*/ gtk_scroll_event (int /*long*/ widget, int /*long*/ eventPtr) { - GdkEventScroll gdkEvent = new GdkEventScroll (); - OS.memmove (gdkEvent, eventPtr, GdkEventScroll.sizeof); - switch (gdkEvent.direction) { - case OS.GDK_SCROLL_UP: - return sendMouseEvent (SWT.MouseWheel, 0, 3, SWT.SCROLL_LINE, true, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1; - case OS.GDK_SCROLL_DOWN: - return sendMouseEvent (SWT.MouseWheel, 0, -3, SWT.SCROLL_LINE, true, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1; - case OS.GDK_SCROLL_LEFT: - return sendMouseEvent (SWT.MouseDown, 4, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1; - case OS.GDK_SCROLL_RIGHT: - return sendMouseEvent (SWT.MouseDown, 5, gdkEvent.time, gdkEvent.x_root, gdkEvent.y_root, false, gdkEvent.state) ? 0 : 1; - } - return 0; -} - -int /*long*/ gtk_show_help (int /*long*/ widget, int /*long*/ helpType) { - if (!hasFocus ()) return 0; - return sendHelpEvent (helpType) ? 1 : 0; -} - -int /*long*/ gtk_style_set (int /*long*/ widget, int /*long*/ previousStyle) { - if (backgroundImage != null) { - setBackgroundPixmap (backgroundImage.pixmap); - } - return 0; -} - -int /*long*/ gtk_unrealize (int /*long*/ widget) { - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) OS.gtk_im_context_set_client_window (imHandle, 0); - return 0; -} - -int /*long*/ gtk_visibility_notify_event (int /*long*/ widget, int /*long*/ event) { - GdkEventVisibility gdkEvent = new GdkEventVisibility (); - OS.memmove (gdkEvent, event, GdkEventVisibility.sizeof); - int /*long*/ paintWindow = paintWindow(); - int /*long*/ window = gdkEvent.window; - if (window == paintWindow) { - if (gdkEvent.state == OS.GDK_VISIBILITY_FULLY_OBSCURED) { - state |= OBSCURED; - } else { - if ((state & OBSCURED) != 0) { - int [] width = new int [1], height = new int [1]; - OS.gdk_drawable_get_size (window, width, height); - GdkRectangle rect = new GdkRectangle (); - rect.width = width [0]; - rect.height = height [0]; - OS.gdk_window_invalidate_rect (window, rect, false); - } - state &= ~OBSCURED; - } - } - return 0; -} - -void gtk_widget_size_request (int /*long*/ widget, GtkRequisition requisition) { - OS.gtk_widget_size_request (widget, requisition); -} - -/** - * 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 /*long*/ internal_new_GC (GCData data) { - checkWidget (); - int /*long*/ window = paintWindow (); - if (window == 0) SWT.error (SWT.ERROR_NO_HANDLES); - int /*long*/ gdkGC = OS.gdk_gc_new (window); - if (gdkGC == 0) 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 |= style & (mask | SWT.MIRRORED); - } else { - if ((data.style & SWT.RIGHT_TO_LEFT) != 0) { - data.style |= SWT.MIRRORED; - } - } - data.drawable = window; - data.device = display; - data.foreground = getForegroundColor (); - Control control = findBackgroundControl (); - if (control == null) control = this; - data.background = control.getBackgroundColor (); - data.font = font != null ? font : defaultFont (); - } - return gdkGC; -} - -int /*long*/ imHandle () { - return 0; -} - -/** - * 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 /*long*/ gdkGC, GCData data) { - checkWidget (); - OS.g_object_unref (gdkGC); -} - -/** - * 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 true; -} -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 == 0 || size.y == 0) { - 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 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(); - Control focusControl = display.focusControl; - if (focusControl != null && !focusControl.isDisposed ()) { - return this == focusControl; - } - return hasFocus (); -} - -/** - * 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 (); -} - -Decorations menuShell () { - return parent.menuShell (); -} - -boolean mnemonicHit (char key) { - return false; -} - -boolean mnemonicMatch (char key) { - return false; -} - -void register () { - super.register (); - if (fixedHandle != 0) display.addWidget (fixedHandle, this); - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) display.addWidget (imHandle, this); -} - -/** - * 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(); - redraw (false); -} - -void redraw (boolean all) { -// checkWidget(); - if (!OS.GTK_WIDGET_VISIBLE (topHandle ())) return; - redrawWidget (0, 0, 0, 0, true, all, 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 (!OS.GTK_WIDGET_VISIBLE (topHandle ())) return; - if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - width - x; - redrawWidget (x, y, width, height, false, all, false); -} - -void redrawChildren () { -} - -void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean all, boolean trim) { - if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_REALIZED) == 0) return; - int /*long*/ window = paintWindow (); - GdkRectangle rect = new GdkRectangle (); - if (redrawAll) { - int [] w = new int [1], h = new int [1]; - OS.gdk_drawable_get_size (window, w, h); - rect.width = w [0]; - rect.height = h [0]; - } else { - rect.x = x; - rect.y = y; - rect.width = width; - rect.height = height; - } - OS.gdk_window_invalidate_rect (window, rect, all); -} - -void release (boolean destroy) { - Control next = null, previous = null; - if (destroy && parent != null) { - Control[] children = parent._getChildren (); - int index = 0; - while (index < children.length) { - if (children [index] == this) break; - index++; - } - if (0 < index && (index + 1) < children.length) { - next = children [index + 1]; - previous = children [index - 1]; - } - } - super.release (destroy); - if (destroy) { - if (previous != null) previous.addRelation (next); - } -} - -void releaseHandle () { - super.releaseHandle (); - fixedHandle = 0; - parent = null; -} - -void releaseParent () { - parent.removeControl (this); -} - -void releaseWidget () { - super.releaseWidget (); - if (display.currentControl == this) display.currentControl = null; - display.removeMouseHoverTimeout (handle); - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) { - OS.gtk_im_context_reset (imHandle); - OS.gtk_im_context_set_client_window (imHandle, 0); - } - if (enableWindow != 0) { - OS.gdk_window_set_user_data (enableWindow, 0); - OS.gdk_window_destroy (enableWindow); - enableWindow = 0; - } - redrawWindow = 0; - if (menu != null && !menu.isDisposed ()) { - menu.dispose (); - } - menu = null; - cursor = null; - toolTipText = null; - layoutData = null; - accessible = null; - region = null; -} - -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 ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.x; - if (isStateMask) { - event.stateMask = stateMask; - } else { - setInputState (event, stateMask); - } - postEvent (SWT.DragDetect, event); - if (isDisposed ()) return false; - return event.doit; -} - -void sendFocusEvent (int type) { - Shell shell = _getShell (); - Display display = this.display; - display.focusControl = this; - display.focusEvent = type; - sendEvent (type); - display.focusControl = null; - display.focusEvent = SWT.None; - /* - * 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 ()) { - switch (type) { - case SWT.FocusIn: - shell.setActiveControl (this); - break; - case SWT.FocusOut: - if (shell != display.activeShell) { - shell.setActiveControl (null); - } - break; - } - } -} - -boolean sendHelpEvent (int /*long*/ helpType) { - Control control = this; - while (control != null) { - if (control.hooks (SWT.Help)) { - control.postEvent (SWT.Help); - return true; - } - control = control.parent; - } - return false; -} - -boolean sendLeaveNotify() { - return false; -} - -boolean sendMouseEvent (int type, int button, int time, double x, double y, boolean is_hint, int state) { - return sendMouseEvent (type, button, 0, 0, false, time, x, y, is_hint, state); -} - -boolean sendMouseEvent (int type, int button, int count, int detail, boolean send, int time, double x, double y, boolean is_hint, int state) { - if (!hooks (type) && !filters (type)) return true; - Event event = new Event (); - event.time = time; - event.button = button; - event.detail = detail; - event.count = count; - if (is_hint) { - event.x = (int)x; - event.y = (int)y; - } else { - int /*long*/ window = eventWindow (); - int [] origin_x = new int [1], origin_y = new int [1]; - OS.gdk_window_get_origin (window, origin_x, origin_y); - event.x = (int)x - origin_x [0]; - event.y = (int)y - origin_y [0]; - } - if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.x; - setInputState (event, state); - if (send) { - sendEvent (type, event); - if (isDisposed ()) return false; - } else { - postEvent (type, event); - } - return event.doit; -} - -void setBackground () { - if ((state & PARENT_BACKGROUND) != 0 && (state & BACKGROUND) == 0 && backgroundImage == null) { - setParentBackground (); - } else { - setWidgetBackground (); - } - 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 (((state & BACKGROUND) == 0) && color == null) return; - GdkColor gdkColor = null; - if (color != null) { - if (color.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - gdkColor = color.handle; - } - boolean set = false; - if (gdkColor == null) { - int /*long*/ style = OS.gtk_widget_get_modifier_style (handle); - set = (OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_NORMAL) & OS.GTK_RC_BG) != 0; - } else { - GdkColor oldColor = getBackgroundColor (); - set = oldColor.pixel != gdkColor.pixel; - } - if (set) { - if (color == null) { - state &= ~BACKGROUND; - } else { - state |= BACKGROUND; - } - setBackgroundColor (gdkColor); - redrawChildren (); - } -} - -void setBackgroundColor (int /*long*/ handle, GdkColor color) { - int index = OS.GTK_STATE_NORMAL; - int /*long*/ style = OS.gtk_widget_get_modifier_style (handle); - int /*long*/ ptr = OS.gtk_rc_style_get_bg_pixmap_name (style, index); - if (ptr != 0) OS.g_free (ptr); - String name = color == null ? "<parent>" : "<none>"; - byte[] buffer = Converter.wcsToMbcs (null, name, true); - ptr = OS.g_malloc (buffer.length); - OS.memmove (ptr, buffer, buffer.length); - OS.gtk_rc_style_set_bg_pixmap_name (style, index, ptr); - OS.gtk_rc_style_set_bg (style, index, color); - int flags = OS.gtk_rc_style_get_color_flags (style, index); - flags = (color == null) ? flags & ~OS.GTK_RC_BG : flags | OS.GTK_RC_BG; - OS.gtk_rc_style_set_color_flags (style, index, flags); - modifyStyle (handle, style); -} - -void setBackgroundColor (GdkColor color) { - setBackgroundColor (handle, color); -} - -/** - * 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; - if (backgroundImage != null) { - setBackgroundPixmap (backgroundImage.pixmap); - redrawWidget (0, 0, 0, 0, true, false, false); - } else { - setWidgetBackground (); - } - redrawChildren (); -} - -void setBackgroundPixmap (int /*long*/ pixmap) { - int /*long*/ window = OS.GTK_WIDGET_WINDOW (paintHandle ()); - if (window != 0) OS.gdk_window_set_back_pixmap (window, backgroundImage.pixmap, false); -} - -/** - * 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(); - /* FIXME !!!!! */ - /* - if (capture) { - OS.gtk_widget_grab_focus (handle); - } else { - OS.gtk_widget_grab_default (handle); - } - */ -} -/** - * 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; - setCursor (cursor != null ? cursor.handle : 0); -} - -void setCursor (int /*long*/ cursor) { - int /*long*/ window = eventWindow (); - if (window != 0) { - OS.gdk_window_set_cursor (window, cursor); - if (!OS.GDK_WINDOWING_X11 ()) { - OS.gdk_flush (); - } else { - int /*long*/ xDisplay = OS.GDK_DISPLAY (); - 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 (((state & DISABLED) == 0) == enabled) return; - Control control = null; - boolean fixFocus = false; - if (!enabled) { - if (display.focusEvent != SWT.FocusOut) { - control = display.getFocusControl (); - fixFocus = isFocusAncestor (control); - } - } - if (enabled) { - state &= ~DISABLED; - } else { - state |= DISABLED; - } - enableWidget (enabled); - if (isDisposed ()) return; - if (enabled) { - if (enableWindow != 0) { - OS.gdk_window_set_user_data (enableWindow, 0); - OS.gdk_window_destroy (enableWindow); - enableWindow = 0; - } - } else { - OS.gtk_widget_realize (handle); - int /*long*/ parentHandle = parent.eventHandle (); - int /*long*/ window = parent.eventWindow (); - int /*long*/ topHandle = topHandle (); - GdkWindowAttr attributes = new GdkWindowAttr (); - attributes.x = OS.GTK_WIDGET_X (topHandle); - attributes.y = OS.GTK_WIDGET_Y (topHandle); - attributes.width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle); - attributes.height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (topHandle); - attributes.event_mask = (0xFFFFFFFF & ~OS.ExposureMask); - attributes.wclass = OS.GDK_INPUT_ONLY; - attributes.window_type = OS.GDK_WINDOW_CHILD; - enableWindow = OS.gdk_window_new (window, attributes, OS.GDK_WA_X | OS.GDK_WA_Y); - if (enableWindow != 0) { - OS.gdk_window_set_user_data (enableWindow, parentHandle); - if (!OS.GDK_WINDOWING_X11 ()) { - OS.gdk_window_raise (enableWindow); - } else { - int /*long*/ topWindow = OS.GTK_WIDGET_WINDOW (topHandle); - int /*long*/ xDisplay = OS.gdk_x11_drawable_get_xdisplay (topWindow); - int /*long*/ xWindow = OS.gdk_x11_drawable_get_xid (enableWindow); - int xScreen = OS.XDefaultScreen (xDisplay); - int flags = OS.CWStackMode | OS.CWSibling; - XWindowChanges changes = new XWindowChanges (); - changes.sibling = OS.gdk_x11_drawable_get_xid (topWindow); - changes.stack_mode = OS.Above; - OS.XReconfigureWMWindow (xDisplay, xWindow, xScreen, flags, changes); - } - if (OS.GTK_WIDGET_VISIBLE (topHandle)) OS.gdk_window_show_unraised (enableWindow); - } - } - if (fixFocus) fixFocus (control); -} - -/** - * 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 (((state & FONT) == 0) && font == null) return; - this.font = font; - int /*long*/ fontDesc; - if (font == null) { - fontDesc = defaultFont ().handle; - } else { - if (font.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - fontDesc = font.handle; - } - if (font == null) { - state &= ~FONT; - } else { - state |= FONT; - } - setFontDescription (fontDesc); -} - -void setFontDescription (int /*long*/ font) { - OS.gtk_widget_modify_font (handle, font); -} - -/** - * 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 (((state & FOREGROUND) == 0) && color == null) return; - GdkColor gdkColor = null; - if (color != null) { - if (color.isDisposed ()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - gdkColor = color.handle; - } - boolean set = false; - if (gdkColor == null) { - int /*long*/ style = OS.gtk_widget_get_modifier_style (handle); - set = (OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_NORMAL) & OS.GTK_RC_FG) != 0; - } else { - GdkColor oldColor = getForegroundColor (); - set = oldColor.pixel != gdkColor.pixel; - } - if (set) { - if (color == null) { - state &= ~FOREGROUND; - } else { - state |= FOREGROUND; - } - setForegroundColor (gdkColor); - } -} - -void setForegroundColor (GdkColor color) { - setForegroundColor (handle, color); -} - -void setInitialBounds () { - if ((state & ZERO_WIDTH) != 0 && (state & ZERO_HEIGHT) != 0) { - /* - * Feature in GTK. On creation, each widget's allocation is - * initialized to a position of (-1, -1) until the widget is - * first sized. The fix is to set the value to (0, 0) as - * expected by SWT. - */ - int /*long*/ topHandle = topHandle (); - if ((parent.style & SWT.MIRRORED) != 0) { - OS.GTK_WIDGET_SET_X (topHandle, parent.getClientWidth ()); - } else { - OS.GTK_WIDGET_SET_X (topHandle, 0); - } - OS.GTK_WIDGET_SET_Y (topHandle, 0); - } else { - resizeHandle (1, 1); - forceResize (); - } -} - -/** - * 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.style & SWT.POP_UP) == 0) { - error (SWT.ERROR_MENU_NOT_POP_UP); - } - if (menu.parent != menuShell ()) { - error (SWT.ERROR_INVALID_PARENT); - } - } - this.menu = menu; -} - -void setOrientation () { - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - if (handle != 0) OS.gtk_widget_set_direction (handle, OS.GTK_TEXT_DIR_RTL); - if (fixedHandle != 0) OS.gtk_widget_set_direction (fixedHandle, OS.GTK_TEXT_DIR_RTL); - } -} - -/** - * 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 == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); - if (parent.isDisposed()) SWT.error (SWT.ERROR_INVALID_ARGUMENT); - if (this.parent == parent) return true; - if (!isReparentable ()) return false; - int /*long*/ topHandle = topHandle (); - int x = OS.GTK_WIDGET_X (topHandle); - int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (topHandle); - if ((this.parent.style & SWT.MIRRORED) != 0) { - x = this.parent.getClientWidth () - width - x; - } - if ((parent.style & SWT.MIRRORED) != 0) { - x = parent.getClientWidth () - width - x; - } - int y = OS.GTK_WIDGET_Y (topHandle); - releaseParent (); - Shell newShell = parent.getShell (), oldShell = getShell (); - Decorations newDecorations = parent.menuShell (), oldDecorations = menuShell (); - Menu [] menus = oldShell.findMenus (this); - if (oldShell != newShell || oldDecorations != newDecorations) { - fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus); - newDecorations.fixAccelGroup (); - oldDecorations.fixAccelGroup (); - } - int /*long*/ newParent = parent.parentingHandle(); - OS.gtk_widget_reparent (topHandle, newParent); - OS.gtk_fixed_move (newParent, topHandle, x, y); - this.parent = parent; - setZOrder (null, false, true); - return true; -} - -void setParentBackground () { - setBackgroundColor (handle, null); - if (fixedHandle != 0) setBackgroundColor (fixedHandle, null); -} - -void setParentWindow (int /*long*/ widget) { -} - -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 /*long*/ window = paintWindow (); - /* Explicitly hiding the window avoids flicker on GTK+ >= 2.6 */ - OS.gdk_window_hide (redrawWindow); - OS.gdk_window_destroy (redrawWindow); - OS.gdk_window_set_events (window, OS.gtk_widget_get_events (paintHandle ())); - redrawWindow = 0; - } - } - } else { - if (drawCount++ == 0) { - if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_REALIZED) != 0) { - int /*long*/ window = paintWindow (); - Rectangle rect = getBounds (); - GdkWindowAttr attributes = new GdkWindowAttr (); - attributes.width = rect.width; - attributes.height = rect.height; - attributes.event_mask = OS.GDK_EXPOSURE_MASK; - attributes.window_type = OS.GDK_WINDOW_CHILD; - redrawWindow = OS.gdk_window_new (window, attributes, 0); - if (redrawWindow != 0) { - int mouseMask = OS.GDK_BUTTON_PRESS_MASK | OS.GDK_BUTTON_RELEASE_MASK | - OS.GDK_ENTER_NOTIFY_MASK | OS.GDK_LEAVE_NOTIFY_MASK | - OS.GDK_POINTER_MOTION_MASK | OS.GDK_POINTER_MOTION_HINT_MASK | - OS.GDK_BUTTON_MOTION_MASK | OS.GDK_BUTTON1_MOTION_MASK | - OS.GDK_BUTTON2_MOTION_MASK | OS.GDK_BUTTON3_MOTION_MASK; - OS.gdk_window_set_events (window, OS.gdk_window_get_events (window) & ~mouseMask); - OS.gdk_window_set_back_pixmap (redrawWindow, 0, false); - OS.gdk_window_show (redrawWindow); - } - } - } - } -} - -boolean setTabItemFocus (boolean next) { - if (!isShowing ()) return false; - return forceFocus (); -} - -/** - * 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(); - setToolTipText (_getShell (), string); - toolTipText = string; -} - -void setToolTipText (Shell shell, String newString) { - if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0)) { - /* - * Feature in GTK. In order to prevent children widgets - * from inheriting their parent's tooltip, the tooltip is - * a set on a shell only. In order to force the shell tooltip - * to update when a new tip string is set, the existing string - * in the tooltip is set to null, followed by running a query. - * The real tip text can then be set. - * - * Note that this will only run if the control for which the - * tooltip is being set is the current control (i.e. the control - * under the pointer). - */ - if (display.currentControl == this) { - shell.setToolTipText (shell.handle, eventHandle (), newString); - } - } else { - shell.setToolTipText (eventHandle (), newString); - } -} - -/** - * 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 (((state & HIDDEN) == 0) == visible) return; - int /*long*/ topHandle = topHandle(); - if (visible) { - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in the show - * event. If this happens, just return. - */ - sendEvent (SWT.Show); - if (isDisposed ()) return; - state &= ~HIDDEN; - if ((state & (ZERO_WIDTH | ZERO_HEIGHT)) == 0) { - if (enableWindow != 0) OS.gdk_window_show_unraised (enableWindow); - OS.gtk_widget_show (topHandle); - } - } else { - /* - * Bug in GTK. Invoking gtk_widget_hide() on a widget that has - * focus causes a focus_out_event to be sent. If the client disposes - * the widget inside the event, GTK GP's. The fix is to reassign focus - * before hiding the widget. - * - * NOTE: In order to stop the same widget from taking focus, - * temporarily clear and set the GTK_VISIBLE flag. - */ - Control control = null; - boolean fixFocus = false; - if (display.focusEvent != SWT.FocusOut) { - control = display.getFocusControl (); - fixFocus = isFocusAncestor (control); - } - state |= HIDDEN; - if (fixFocus) { - OS.GTK_WIDGET_UNSET_FLAGS (topHandle, OS.GTK_VISIBLE); - fixFocus (control); - if (isDisposed ()) return; - OS.GTK_WIDGET_SET_FLAGS (topHandle, OS.GTK_VISIBLE); - } - OS.gtk_widget_hide (topHandle); - if (isDisposed ()) return; - if (enableWindow != 0) OS.gdk_window_hide (enableWindow); - sendEvent (SWT.Hide); - } -} - -void setZOrder (Control sibling, boolean above, boolean fixRelations) { - setZOrder (sibling, above, fixRelations, true); -} - -void setZOrder (Control sibling, boolean above, boolean fixRelations, boolean fixChildren) { - int index = 0, siblingIndex = 0, oldNextIndex = -1; - Control[] children = null; - if (fixRelations) { - /* determine the receiver's and sibling's indexes in the parent */ - children = parent._getChildren (); - while (index < children.length) { - if (children [index] == this) break; - index++; - } - if (sibling != null) { - while (siblingIndex < children.length) { - if (children [siblingIndex] == sibling) break; - siblingIndex++; - } - } - /* remove "Labelled by" relationships that will no longer be valid */ - removeRelation (); - if (index + 1 < children.length) { - oldNextIndex = index + 1; - children [oldNextIndex].removeRelation (); - } - if (sibling != null) { - if (above) { - sibling.removeRelation (); - } else { - if (siblingIndex + 1 < children.length) { - children [siblingIndex + 1].removeRelation (); - } - } - } - } - - int /*long*/ topHandle = topHandle (); - int /*long*/ siblingHandle = sibling != null ? sibling.topHandle () : 0; - int /*long*/ window = OS.GTK_WIDGET_WINDOW (topHandle); - if (window != 0) { - int /*long*/ siblingWindow = 0; - if (sibling != null) { - if (above && sibling.enableWindow != 0) { - siblingWindow = enableWindow; - } else { - siblingWindow = OS.GTK_WIDGET_WINDOW (siblingHandle); - } - } - int /*long*/ redrawWindow = fixChildren ? parent.redrawWindow : 0; - if (!OS.GDK_WINDOWING_X11 () || (siblingWindow == 0 && (!above || redrawWindow == 0))) { - if (above) { - OS.gdk_window_raise (window); - if (redrawWindow != 0) OS.gdk_window_raise (redrawWindow); - if (enableWindow != 0) OS.gdk_window_raise (enableWindow); - } else { - if (enableWindow != 0) OS.gdk_window_lower (enableWindow); - OS.gdk_window_lower (window); - } - } else { - XWindowChanges changes = new XWindowChanges (); - changes.sibling = OS.gdk_x11_drawable_get_xid (siblingWindow != 0 ? siblingWindow : redrawWindow); - changes.stack_mode = above ? OS.Above : OS.Below; - if (redrawWindow != 0 && siblingWindow == 0) changes.stack_mode = OS.Below; - int /*long*/ xDisplay = OS.gdk_x11_drawable_get_xdisplay (window); - int /*long*/ xWindow = OS.gdk_x11_drawable_get_xid (window); - int xScreen = OS.XDefaultScreen (xDisplay); - int flags = OS.CWStackMode | OS.CWSibling; - /* - * 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 (). - */ - OS.XReconfigureWMWindow (xDisplay, xWindow, xScreen, flags, changes); - if (enableWindow != 0) { - changes.sibling = OS.gdk_x11_drawable_get_xid (window); - changes.stack_mode = OS.Above; - xWindow = OS.gdk_x11_drawable_get_xid (enableWindow); - OS.XReconfigureWMWindow (xDisplay, xWindow, xScreen, flags, changes); - } - } - } - if (fixChildren) { - if (above) { - parent.moveAbove (topHandle, siblingHandle); - } else { - parent.moveBelow (topHandle, siblingHandle); - } - } - /* Make sure that the parent internal windows are on the bottom of the stack */ - if (!above && fixChildren) parent.fixZOrder (); - - if (fixRelations) { - /* determine the receiver's new index in the parent */ - if (sibling != null) { - if (above) { - index = siblingIndex - (index < siblingIndex ? 1 : 0); - } else { - index = siblingIndex + (siblingIndex < index ? 1 : 0); - } - } else { - if (above) { - index = 0; - } else { - index = children.length - 1; - } - } - - /* add new "Labelled by" relations as needed */ - children = parent._getChildren (); - if (0 < index) { - children [index - 1].addRelation (this); - } - if (index + 1 < children.length) { - addRelation (children [index + 1]); - } - if (oldNextIndex != -1) { - if (oldNextIndex <= index) oldNextIndex--; - /* the last two conditions below ensure that duplicate relations are not hooked */ - if (0 < oldNextIndex && oldNextIndex != index && oldNextIndex != index + 1) { - children [oldNextIndex - 1].addRelation (children [oldNextIndex]); - } - } - } -} - -void setWidgetBackground () { - if (fixedHandle != 0) { - int /*long*/ style = OS.gtk_widget_get_modifier_style (fixedHandle); - modifyStyle (fixedHandle, style); - } - int /*long*/ style = OS.gtk_widget_get_modifier_style (handle); - modifyStyle (handle, style); -} - -boolean showMenu (int x, int y) { - Event event = new Event (); - event.x = x; - event.y = y; - sendEvent (SWT.MenuDetect, event); - //widget could be disposed at this point - if (isDisposed ()) return false; - if (event.doit) { - if (menu != null && !menu.isDisposed ()) { - boolean hooksKeys = hooks (SWT.KeyDown) || hooks (SWT.KeyUp); - menu.createIMMenu (hooksKeys ? imHandle() : 0); - if (event.x != x || event.y != y) { - menu.setLocation (event.x, event.y); - } - menu.setVisible (true); - return true; - } - } - return false; -} - -void showWidget () { - // Comment this line to disable zero-sized widgets - state |= ZERO_WIDTH | ZERO_HEIGHT; - int /*long*/ topHandle = topHandle (); - int /*long*/ parentHandle = parent.parentingHandle (); - parent.setParentWindow (topHandle); - OS.gtk_container_add (parentHandle, topHandle); - if (handle != 0 && handle != topHandle) OS.gtk_widget_show (handle); - if ((state & (ZERO_WIDTH | ZERO_HEIGHT)) == 0) { - if (fixedHandle != 0) OS.gtk_widget_show (fixedHandle); - } - if (fixedHandle != 0) fixStyle (fixedHandle); -} - -void sort (int [] 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] <= items [j + gap]) { - int swap = items [j]; - items [j] = items [j + gap]; - items [j + gap] = swap; - } - } - } - } -} - -/** - * 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 translateMnemonic (Event event, Control control) { - if (control == this) return false; - if (!isVisible () || !isEnabled ()) return false; - event.doit = this == display.mnemonicControl || mnemonicMatch (event.character); - return traverse (event); -} - -boolean translateMnemonic (int keyval, GdkEventKey gdkEvent) { - int key = OS.gdk_keyval_to_unicode (keyval); - if (key < 0x20) return false; - if (gdkEvent.state == 0) { - int code = traversalCode (keyval, gdkEvent); - if ((code & SWT.TRAVERSE_MNEMONIC) == 0) return false; - } else { - Shell shell = _getShell (); - int mask = OS.GDK_CONTROL_MASK | OS.GDK_SHIFT_MASK | OS.GDK_MOD1_MASK; - if ((gdkEvent.state & mask) != OS.gtk_window_get_mnemonic_modifier (shell.shellHandle)) return false; - } - Decorations shell = menuShell (); - if (shell.isVisible () && shell.isEnabled ()) { - Event event = new Event (); - event.detail = SWT.TRAVERSE_MNEMONIC; - if (setKeyState (event, gdkEvent)) { - return translateMnemonic (event, null) || shell.translateMnemonic (event, this); - } - } - return false; -} - -boolean translateTraversal (GdkEventKey keyEvent) { - int detail = SWT.TRAVERSE_NONE; - int key = keyEvent.keyval; - int code = traversalCode (key, keyEvent); - boolean all = false; - switch (key) { - case OS.GDK_Escape: { - all = true; - detail = SWT.TRAVERSE_ESCAPE; - break; - } - case OS.GDK_KP_Enter: - case OS.GDK_Return: { - all = true; - detail = SWT.TRAVERSE_RETURN; - break; - } - case OS.GDK_ISO_Left_Tab: - case OS.GDK_Tab: { - boolean next = (keyEvent.state & OS.GDK_SHIFT_MASK) == 0; - detail = next ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS; - break; - } - case OS.GDK_Up: - case OS.GDK_Left: - case OS.GDK_Down: - case OS.GDK_Right: { - boolean next = key == OS.GDK_Down || key == OS.GDK_Right; - if (parent != null && (parent.style & SWT.MIRRORED) != 0) { - if (key == OS.GDK_Left || key == OS.GDK_Right) next = !next; - } - detail = next ? SWT.TRAVERSE_ARROW_NEXT : SWT.TRAVERSE_ARROW_PREVIOUS; - break; - } - case OS.GDK_Page_Up: - case OS.GDK_Page_Down: { - all = true; - if ((keyEvent.state & OS.GDK_CONTROL_MASK) == 0) return false; - detail = key == OS.GDK_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 = keyEvent.time; - if (!setKeyState (event, keyEvent)) 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, GdkEventKey event) { - 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; - return code; -} - -boolean traverse (Event event) { - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in the traverse - * event. If this happens, return true to stop further - * event processing. - */ - 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; -} - -boolean traverseEscape () { - return false; -} - -boolean traverseGroup (boolean next) { - Control root = computeTabRoot (); - Widget group = computeTabGroup (); - Widget [] 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) { - Widget widget = list [index]; - if (!widget.isDisposed () && widget.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 traverseReturn () { - return false; -} - -boolean traversePage (boolean next) { - return false; -} - -boolean traverseMnemonic (char key) { - return mnemonicHit (key); -} - -/** - * 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, true); -} - -void update (boolean all, boolean flush) { -// checkWidget(); - if (!OS.GTK_WIDGET_VISIBLE (topHandle ())) return; - if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_REALIZED) == 0) return; - int /*long*/ window = paintWindow (); - if (flush) display.flushExposes (window, all); - OS.gdk_window_process_updates (window, all); - OS.gdk_flush (); -} - -void updateBackgroundMode () { - int oldState = state & PARENT_BACKGROUND; - checkBackground (); - if (oldState != (state & PARENT_BACKGROUND)) { - setBackground (); - } -} - -void updateLayout (boolean all) { - /* Do nothing */ -} - -int /*long*/ windowProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { - switch ((int)/*64*/user_data) { - case EXPOSE_EVENT_INVERSE: { - if ((OS.GTK_VERSION < OS.VERSION (2, 8, 0)) && ((state & OBSCURED) == 0)) { - Control control = findBackgroundControl (); - if (control != null && control.backgroundImage != null) { - GdkEventExpose gdkEvent = new GdkEventExpose (); - OS.memmove (gdkEvent, arg0, GdkEventExpose.sizeof); - int /*long*/ paintWindow = paintWindow(); - int /*long*/ window = gdkEvent.window; - if (window != paintWindow) break; - int /*long*/ gdkGC = OS.gdk_gc_new (window); - OS.gdk_gc_set_clip_region (gdkGC, gdkEvent.region); - int[] dest_x = new int[1], dest_y = new int[1]; - OS.gtk_widget_translate_coordinates (paintHandle (), control.paintHandle (), 0, 0, dest_x, dest_y); - OS.gdk_gc_set_fill (gdkGC, OS.GDK_TILED); - OS.gdk_gc_set_ts_origin (gdkGC, -dest_x [0], -dest_y [0]); - OS.gdk_gc_set_tile (gdkGC, control.backgroundImage.pixmap); - OS.gdk_draw_rectangle (window, gdkGC, 1, gdkEvent.area_x, gdkEvent.area_y, gdkEvent.area_width, gdkEvent.area_height); - OS.g_object_unref (gdkGC); - } - } - break; - } - } - return super.windowProc (handle, arg0, user_data); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java deleted file mode 100644 index 11248e326d..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DateTime.java +++ /dev/null @@ -1,1103 +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 java.text.DateFormatSymbols; -import java.util.Calendar; - -import org.eclipse.swt.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.gtk.OS; - -/** - * Instances of this class are selectable user interface - * objects that allow the user to enter and modify date - * or time 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> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>DATE, TIME, CALENDAR, SHORT, MEDIUM, LONG, DROP_DOWN</dd> - * <dt><b>Events:</b></dt> - * <dd>DefaultSelection, Selection</dd> - * </dl> - * <p> - * Note: Only one of the styles DATE, TIME, or CALENDAR may be specified, - * and only one of the styles SHORT, MEDIUM, or LONG may be specified. - * The DROP_DOWN style is a <em>HINT</em>, and it is only valid with the DATE style. - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#datetime">DateTime 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.3 - * @noextend This class is not intended to be subclassed by clients. - */ -public class DateTime extends Composite { - int day, month, year, hours, minutes, seconds; - - static final int MIN_YEAR = 1752; // Gregorian switchover in North America: September 19, 1752 - static final int MAX_YEAR = 9999; - - /* Emulated DATE and TIME variables */ - Calendar calendar; - DateFormatSymbols formatSymbols; - Button down, up; - Text text; - String format; - Point[] fieldIndices; - int[] fieldNames; - int fieldCount, currentField = 0, characterCount = 0; - boolean ignoreVerify = false; - static final String DEFAULT_SHORT_DATE_FORMAT = "MM/YYYY"; - static final String DEFAULT_MEDIUM_DATE_FORMAT = "MM/DD/YYYY"; - static final String DEFAULT_LONG_DATE_FORMAT = "MM/DD/YYYY"; - static final String DEFAULT_SHORT_TIME_FORMAT = "HH:MM AM"; - static final String DEFAULT_MEDIUM_TIME_FORMAT = "HH:MM:SS AM"; - static final String DEFAULT_LONG_TIME_FORMAT = "HH:MM:SS AM"; - -/** - * 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#DATE - * @see SWT#TIME - * @see SWT#CALENDAR - * @see SWT#SHORT - * @see SWT#MEDIUM - * @see SWT#LONG - * @see SWT#DROP_DOWN - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public DateTime (Composite parent, int style) { - super (parent, checkStyle (style)); - if ((this.style & SWT.CALENDAR) == 0) { - /* SWT.DATE and SWT.TIME */ - calendar = Calendar.getInstance(); - formatSymbols = new DateFormatSymbols(); - text = new Text(this, SWT.SINGLE); - /* disable the native drag and drop for the date/time text field */ - OS.gtk_drag_dest_unset(text.handle); - if ((this.style & SWT.DATE) != 0) { - setFormat((this.style & SWT.SHORT) != 0 ? DEFAULT_SHORT_DATE_FORMAT : (this.style & SWT.LONG) != 0 ? DEFAULT_LONG_DATE_FORMAT : DEFAULT_MEDIUM_DATE_FORMAT); - } else { // SWT.TIME - setFormat((this.style & SWT.SHORT) != 0 ? DEFAULT_SHORT_TIME_FORMAT : (this.style & SWT.LONG) != 0 ? DEFAULT_LONG_TIME_FORMAT : DEFAULT_MEDIUM_TIME_FORMAT); - } - text.setText(getFormattedString(this.style)); - Listener listener = new Listener() { - public void handleEvent(Event event) { - switch(event.type) { - case SWT.KeyDown: onKeyDown(event); break; - case SWT.FocusIn: onFocusIn(event); break; - case SWT.FocusOut: onFocusOut(event); break; - case SWT.MouseDown: onMouseClick(event); break; - case SWT.MouseUp: onMouseClick(event); break; - case SWT.Verify: onVerify(event); break; - } - } - }; - text.addListener(SWT.KeyDown, listener); - text.addListener(SWT.FocusIn, listener); - text.addListener(SWT.FocusOut, listener); - text.addListener(SWT.MouseDown, listener); - text.addListener(SWT.MouseUp, listener); - text.addListener(SWT.Verify, listener); - up = new Button(this, SWT.ARROW | SWT.UP); - //up.setToolTipText(SWT.getMessage ("SWT_Up")); //$NON-NLS-1$ - down = new Button(this, SWT.ARROW | SWT.DOWN); - //down.setToolTipText(SWT.getMessage ("SWT_Down")); //$NON-NLS-1$ - up.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - incrementField(+1); - text.setFocus(); - } - }); - down.addListener(SWT.Selection, new Listener() { - public void handleEvent(Event event) { - incrementField(-1); - text.setFocus(); - } - }); - addListener(SWT.Resize, new Listener() { - public void handleEvent(Event event) { - onResize(event); - } - }); - } -} - -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. - */ - style &= ~(SWT.H_SCROLL | SWT.V_SCROLL); - style = checkBits (style, SWT.DATE, SWT.TIME, SWT.CALENDAR, 0, 0, 0); - return checkBits (style, SWT.MEDIUM, SWT.SHORT, SWT.LONG, 0, 0, 0); -} - -/** - * 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 user changes the control's value. - * <code>widgetDefaultSelected</code> is typically called when ENTER is pressed. - * </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); -} - -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - int width = 0, height = 0; - if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) { - if ((style & SWT.CALENDAR) != 0) { - // TODO: CALENDAR computeSize - width = 300; - height = 200; - } else { - /* SWT.DATE and SWT.TIME */ - GC gc = new GC(text); - Point textSize = gc.stringExtent(getComputeSizeString(style)); - gc.dispose(); - Rectangle trim = text.computeTrim(0, 0, textSize.x, textSize.y); - Point buttonSize = up.computeSize(SWT.DEFAULT, SWT.DEFAULT, changed); - width = trim.width + buttonSize.x; - height = Math.max(trim.height, buttonSize.y); - } - } - if (width == 0) width = DEFAULT_WIDTH; - if (height == 0) 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); -} - -void createHandle (int index) { - if ((style & SWT.CALENDAR) != 0) { - state |= HANDLE; - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - handle = OS.gtk_calendar_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (fixedHandle, handle); - if (OS.GTK_VERSION >= OS.VERSION(2, 4, 0)) { - OS.gtk_calendar_set_display_options(handle, OS.GTK_CALENDAR_SHOW_HEADING | OS.GTK_CALENDAR_SHOW_DAY_NAMES); - } else { - OS.gtk_calendar_display_options(handle, OS.GTK_CALENDAR_SHOW_HEADING | OS.GTK_CALENDAR_SHOW_DAY_NAMES); - } - } else { - super.createHandle(index); - } -} - -boolean checkSubwindow () { - return false; -} - -void createWidget (int index) { - super.createWidget (index); - if ((style & SWT.CALENDAR) != 0) { - getDate(); - } -} - -void commitCurrentField() { - if (characterCount > 0) { - characterCount = 0; - int fieldName = fieldNames[currentField]; - int start = fieldIndices[currentField].x; - int end = fieldIndices[currentField].y; - String value = text.getText(start, end - 1); - int s = value.lastIndexOf(' '); - if (s != -1) value = value.substring(s + 1); - int newValue = unformattedIntValue(fieldName, value, characterCount == 0, calendar.getActualMaximum(fieldName)); - if (newValue != -1) setTextField(fieldName, newValue, true, true); - } -} - -String formattedStringValue(int fieldName, int value, boolean adjust) { - if (fieldName == Calendar.AM_PM) { - String[] ampm = formatSymbols.getAmPmStrings(); - return ampm[value]; - } - if (adjust) { - if (fieldName == Calendar.HOUR && value == 0) { - return String.valueOf(12); - } - if (fieldName == Calendar.MONTH) { - return String.valueOf(value + 1); - } - } - return String.valueOf(value); -} - -String getComputeSizeString(int style) { - if ((style & SWT.DATE) != 0) { - return (style & SWT.SHORT) != 0 ? DEFAULT_SHORT_DATE_FORMAT : (style & SWT.LONG) != 0 ? DEFAULT_LONG_DATE_FORMAT : DEFAULT_MEDIUM_DATE_FORMAT; - } - // SWT.TIME - return (style & SWT.SHORT) != 0 ? DEFAULT_SHORT_TIME_FORMAT : (style & SWT.LONG) != 0 ? DEFAULT_LONG_TIME_FORMAT : DEFAULT_MEDIUM_TIME_FORMAT; -} - -int getFieldIndex(int fieldName) { - for (int i = 0; i < fieldCount; i++) { - if (fieldNames[i] == fieldName) { - return i; - } - } - return -1; -} - -String getFormattedString(int style) { - if ((style & SWT.TIME) != 0) { - String[] ampm = formatSymbols.getAmPmStrings(); - int h = calendar.get(Calendar.HOUR); if (h == 0) h = 12; - int m = calendar.get(Calendar.MINUTE); - int s = calendar.get(Calendar.SECOND); - int a = calendar.get(Calendar.AM_PM); - if ((style & SWT.SHORT) != 0) return "" + (h < 10 ? " " : "") + h + ":" + (m < 10 ? "0" : "") + m + " " + ampm[a]; - return "" + (h < 10 ? " " : "") + h + ":" + (m < 10 ? "0" : "") + m + ":" + (s < 10 ? "0" : "") + s + " " + ampm[a]; - } - /* SWT.DATE */ - int y = calendar.get(Calendar.YEAR); - int m = calendar.get(Calendar.MONTH) + 1; - int d = calendar.get(Calendar.DAY_OF_MONTH); - if ((style & SWT.SHORT) != 0) return "" + (m < 10 ? " " : "") + m + "/" + y; - return "" + (m < 10 ? " " : "") + m + "/" + (d < 10 ? " " : "") + d + "/" + y; -} - -void getDate() { - int [] y = new int [1]; - int [] m = new int [1]; - int [] d = new int [1]; - OS.gtk_calendar_get_date(handle, y, m, d); - year = y[0]; - month = m[0]; - day = d[0]; -} - -/** - * Returns the receiver's date, or day of the month. - * <p> - * The first day of the month is 1, and the last day depends on the month and year. - * </p> - * - * @return a positive integer beginning with 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 getDay () { - checkWidget (); - if ((style & SWT.CALENDAR) != 0) { - getDate(); - return day; - } else { - return calendar.get(Calendar.DAY_OF_MONTH); - } -} - -/** - * Returns the receiver's hours. - * <p> - * Hours is an integer between 0 and 23. - * </p> - * - * @return an integer between 0 and 23 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 getHours () { - checkWidget (); - if ((style & SWT.CALENDAR) != 0) { - return hours; - } else { - return calendar.get(Calendar.HOUR_OF_DAY); - } -} - -/** - * Returns the receiver's minutes. - * <p> - * Minutes is an integer between 0 and 59. - * </p> - * - * @return an integer between 0 and 59 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 getMinutes () { - checkWidget (); - if ((style & SWT.CALENDAR) != 0) { - return minutes; - } else { - return calendar.get(Calendar.MINUTE); - } -} - -/** - * Returns the receiver's month. - * <p> - * The first month of the year is 0, and the last month is 11. - * </p> - * - * @return an integer between 0 and 11 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 getMonth () { - checkWidget (); - if ((style & SWT.CALENDAR) != 0) { - getDate(); - return month; - } else { - return calendar.get(Calendar.MONTH); - } -} - -String getNameText() { - return (style & SWT.TIME) != 0 ? getHours() + ":" + getMinutes() + ":" + getSeconds() - : (getMonth() + 1) + "/" + getDay() + "/" + getYear(); -} - -/** - * Returns the receiver's seconds. - * <p> - * Seconds is an integer between 0 and 59. - * </p> - * - * @return an integer between 0 and 59 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 getSeconds () { - checkWidget (); - if ((style & SWT.CALENDAR) != 0) { - return seconds; - } else { - return calendar.get(Calendar.SECOND); - } -} - -/** - * Returns the receiver's year. - * <p> - * The first year is 1752 and the last year is 9999. - * </p> - * - * @return an integer between 1752 and 9999 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 getYear () { - checkWidget (); - if ((style & SWT.CALENDAR) != 0) { - getDate(); - return year; - } else { - return calendar.get(Calendar.YEAR); - } -} - -int /*long*/ gtk_day_selected (int /*long*/ widget) { - sendSelectionEvent (); - return 0; -} - -int /*long*/ gtk_day_selected_double_click (int /*long*/ widget) { - postEvent(SWT.DefaultSelection); - return 0; -} - -int /*long*/ gtk_month_changed (int /*long*/ widget) { - sendSelectionEvent (); - return 0; -} - -void hookEvents () { - super.hookEvents(); - if ((style & SWT.CALENDAR) != 0) { - OS.g_signal_connect_closure (handle, OS.day_selected, display.closures [DAY_SELECTED], false); - OS.g_signal_connect_closure (handle, OS.day_selected_double_click, display.closures [DAY_SELECTED_DOUBLE_CLICK], false); - OS.g_signal_connect_closure (handle, OS.month_changed, display.closures [MONTH_CHANGED], false); - } -} - -boolean isValidTime(int fieldName, int value) { - Calendar validCalendar; - if ((style & SWT.CALENDAR) != 0) { - validCalendar = Calendar.getInstance(); - } else { - validCalendar = calendar; - } - int min = validCalendar.getActualMinimum(fieldName); - int max = validCalendar.getActualMaximum(fieldName); - return value >= min && value <= max; -} - -boolean isValidDate(int year, int month, int day) { - if (year < MIN_YEAR || year > MAX_YEAR) return false; - Calendar valid = Calendar.getInstance(); - valid.set(year, month, day); - return valid.get(Calendar.YEAR) == year - && valid.get(Calendar.MONTH) == month - && valid.get(Calendar.DAY_OF_MONTH) == day; -} - -void incrementField(int amount) { - int fieldName = fieldNames[currentField]; - int value = calendar.get(fieldName); - if (fieldName == Calendar.HOUR) { - int max = calendar.getMaximum(Calendar.HOUR); - int min = calendar.getMinimum(Calendar.HOUR); - if ((value == max && amount == 1) || (value == min && amount == -1)) { - int temp = currentField; - currentField = getFieldIndex(Calendar.AM_PM); - setTextField(Calendar.AM_PM, (calendar.get(Calendar.AM_PM) + 1) % 2, true, true); - currentField = temp; - } - } - setTextField(fieldName, value + amount, true, true); -} - -void onKeyDown(Event event) { - int fieldName; - switch (event.keyCode) { - case SWT.ARROW_RIGHT: - case SWT.KEYPAD_DIVIDE: - // a right arrow or a valid separator navigates to the field on the right, with wraping - selectField((currentField + 1) % fieldCount); - break; - case SWT.ARROW_LEFT: - // navigate to the field on the left, with wrapping - int index = currentField - 1; - selectField(index < 0 ? fieldCount - 1 : index); - break; - case SWT.ARROW_UP: - case SWT.KEYPAD_ADD: - // set the value of the current field to value + 1, with wrapping - commitCurrentField(); - incrementField(+1); - break; - case SWT.ARROW_DOWN: - case SWT.KEYPAD_SUBTRACT: - // set the value of the current field to value - 1, with wrapping - commitCurrentField(); - incrementField(-1); - break; - case SWT.HOME: - // set the value of the current field to its minimum - fieldName = fieldNames[currentField]; - setTextField(fieldName, calendar.getActualMinimum(fieldName), true, true); - break; - case SWT.END: - // set the value of the current field to its maximum - fieldName = fieldNames[currentField]; - setTextField(fieldName, calendar.getActualMaximum(fieldName), true, true); - break; - case SWT.CR: - postEvent(SWT.DefaultSelection); - break; - default: - switch (event.character) { - case '/': - case ':': - case '-': - case '.': - // a valid separator navigates to the field on the right, with wraping - selectField((currentField + 1) % fieldCount); - break; - } - } -} - -void onFocusIn(Event event) { - selectField(currentField); -} - -void onFocusOut(Event event) { - commitCurrentField(); -} - -void onMouseClick(Event event) { - if (event.button != 1) return; - Point sel = text.getSelection(); - for (int i = 0; i < fieldCount; i++) { - if (fieldIndices[i].x <= sel.x && sel.x <= fieldIndices[i].y) { - selectField(i); - break; - } - } -} - -void onResize(Event event) { - Rectangle rect = getClientArea (); - int width = rect.width; - int height = rect.height; - Point buttonSize = up.computeSize(SWT.DEFAULT, height); - int buttonHeight = buttonSize.y / 2; - text.setBounds(0, 0, width - buttonSize.x, height); - up.setBounds(width - buttonSize.x, 0, buttonSize.x, buttonHeight); - down.setBounds(width - buttonSize.x, buttonHeight, buttonSize.x, buttonHeight); -} - -void onVerify(Event event) { - if (ignoreVerify) return; - event.doit = false; - int fieldName = fieldNames[currentField]; - int start = fieldIndices[currentField].x; - int end = fieldIndices[currentField].y; - int length = end - start; - String newText = event.text; - if (fieldName == Calendar.AM_PM) { - String[] ampm = formatSymbols.getAmPmStrings(); - if (newText.equalsIgnoreCase(ampm[Calendar.AM].substring(0, 1)) || newText.equalsIgnoreCase(ampm[Calendar.AM])) { - setTextField(fieldName, Calendar.AM, true, false); - } else if (newText.equalsIgnoreCase(ampm[Calendar.PM].substring(0, 1)) || newText.equalsIgnoreCase(ampm[Calendar.PM])) { - setTextField(fieldName, Calendar.PM, true, false); - } - return; - } - if (characterCount > 0) { - try { - Integer.parseInt(newText); - } catch (NumberFormatException ex) { - return; - } - String value = text.getText(start, end - 1); - int s = value.lastIndexOf(' '); - if (s != -1) value = value.substring(s + 1); - newText = "" + value + newText; - } - int newTextLength = newText.length(); - boolean first = characterCount == 0; - characterCount = (newTextLength < length) ? newTextLength : 0; - int max = calendar.getActualMaximum(fieldName); - int min = calendar.getActualMinimum(fieldName); - int newValue = unformattedIntValue(fieldName, newText, characterCount == 0, max); - if (newValue == -1) { - characterCount = 0; - return; - } - if (first && newValue == 0 && length > 1) { - setTextField(fieldName, newValue, false, false); - } else if (min <= newValue && newValue <= max) { - setTextField(fieldName, newValue, characterCount == 0, characterCount == 0); - } else { - if (newTextLength >= length) { - newText = newText.substring(newTextLength - length + 1); - newValue = unformattedIntValue(fieldName, newText, characterCount == 0, max); - if (newValue != -1) { - characterCount = length - 1; - if (min <= newValue && newValue <= max) { - setTextField(fieldName, newValue, characterCount == 0, true); - } - } - } - } -} - -void releaseWidget () { - super.releaseWidget(); - //TODO: need to do anything here? -} - -/** - * 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 selectField(int index) { - if (index != currentField) { - commitCurrentField(); - } - final int start = fieldIndices[index].x; - final int end = fieldIndices[index].y; - Point pt = text.getSelection(); - if (index == currentField && start == pt.x && end == pt.y) return; - currentField = index; - display.asyncExec(new Runnable() { - public void run() { - if (!text.isDisposed()) { - String value = text.getText(start, end - 1); - int s = value.lastIndexOf(' '); - if (s == -1) s = start; - else s = start + s + 1; - text.setSelection(s, end); - } - } - }); -} - -void sendSelectionEvent () { - int [] y = new int [1]; - int [] m = new int [1]; - int [] d = new int [1]; - OS.gtk_calendar_get_date(handle, y, m, d); - //TODO: hours, minutes, seconds? - if (d[0] != day || - m[0] != month || - y[0] != year) { - year = y[0]; - month = m[0]; - day = d[0]; - postEvent (SWT.Selection); - } -} - -public void setBackground(Color color) { - checkWidget(); - super.setBackground(color); - if (text != null) text.setBackground(color); -} - -public void setFont(Font font) { - checkWidget(); - super.setFont(font); - if (text != null) text.setFont(font); - redraw(); -} - -public void setForeground(Color color) { - checkWidget(); - super.setForeground(color); - if (text != null) text.setForeground(color); -} - -/*public*/ void setFormat(String string) { - checkWidget(); - // TODO: this needs to be locale sensitive - fieldCount = (style & SWT.DATE) != 0 ? ((style & SWT.SHORT) != 0 ? 2 : 3) : ((style & SWT.SHORT) != 0 ? 3 : 4); - fieldIndices = new Point[fieldCount]; - fieldNames = new int[fieldCount]; - if ((style & SWT.DATE) != 0) { - fieldNames[0] = Calendar.MONTH; - fieldIndices[0] = new Point(0, 2); - if ((style & SWT.SHORT) != 0) { - fieldNames[1] = Calendar.YEAR; - fieldIndices[1] = new Point(3, 7); - } else { - fieldNames[1] = Calendar.DAY_OF_MONTH; - fieldIndices[1] = new Point(3, 5); - fieldNames[2] = Calendar.YEAR; - fieldIndices[2] = new Point(6, 10); - } - } else { /* SWT.TIME */ - fieldNames[0] = Calendar.HOUR; - fieldIndices[0] = new Point(0, 2); - fieldNames[1] = Calendar.MINUTE; - fieldIndices[1] = new Point(3, 5); - if ((style & SWT.SHORT) != 0) { - fieldNames[2] = Calendar.AM_PM; - fieldIndices[2] = new Point(6, 8); - } else { - fieldNames[2] = Calendar.SECOND; - fieldIndices[2] = new Point(6, 8); - fieldNames[3] = Calendar.AM_PM; - fieldIndices[3] = new Point(9, 11); - } - } -} - -void setField(int fieldName, int value) { - if (calendar.get(fieldName) == value) return; - if (fieldName == Calendar.AM_PM) { - calendar.roll(Calendar.HOUR_OF_DAY, 12); // TODO: needs more work for setFormat and locale - } - calendar.set(fieldName, value); - postEvent(SWT.Selection); -} - -void setTextField(int fieldName, int value, boolean commit, boolean adjust) { - if (commit) { - int max = calendar.getActualMaximum(fieldName); - int min = calendar.getActualMinimum(fieldName); - if (fieldName == Calendar.YEAR) { - max = MAX_YEAR; - min = MIN_YEAR; - /* Special case: convert 1 or 2-digit years into reasonable 4-digit years. */ - int currentYear = Calendar.getInstance().get(Calendar.YEAR); - int currentCentury = (currentYear / 100) * 100; - if (value < (currentYear + 30) % 100) value += currentCentury; - else if (value < 100) value += currentCentury - 100; - } - if (value > max) value = min; // wrap - if (value < min) value = max; // wrap - } - int start = fieldIndices[currentField].x; - int end = fieldIndices[currentField].y; - text.setSelection(start, end); - String newValue = formattedStringValue(fieldName, value, adjust); - StringBuffer buffer = new StringBuffer(newValue); - /* Convert leading 0's into spaces. */ - int prependCount = end - start - buffer.length(); - for (int i = 0; i < prependCount; i++) { - switch (fieldName) { - case Calendar.MINUTE: - case Calendar.SECOND: - buffer.insert(0, 0); - break; - default: - buffer.insert(0, ' '); - break; - } - } - newValue = buffer.toString(); - ignoreVerify = true; - text.insert(newValue); - ignoreVerify = false; - selectField(currentField); - if (commit) setField(fieldName, value); -} - -/** - * Sets the receiver's year, month, and day in a single operation. - * <p> - * This is the recommended way to set the date, because setting the year, - * month, and day separately may result in invalid intermediate dates. - * </p> - * - * @param year an integer between 1752 and 9999 - * @param month an integer between 0 and 11 - * @param day a positive integer beginning with 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> - * - * @since 3.4 - */ -public void setDate (int year, int month, int day) { - checkWidget (); - if (!isValidDate(year, month, day)) return; - if ((style & SWT.CALENDAR) != 0) { - this.year = year; - this.month = month; - this.day = day; - OS.gtk_calendar_select_month(handle, month, year); - OS.gtk_calendar_select_day(handle, day); - } else { - calendar.set(year, month, day); - updateControl(); - } -} - -/** - * Sets the receiver's date, or day of the month, to the specified day. - * <p> - * The first day of the month is 1, and the last day depends on the month and year. - * If the specified day is not valid for the receiver's month and year, then it is ignored. - * </p> - * - * @param day a positive integer beginning with 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> - * - * @see #setDate - */ -public void setDay (int day) { - checkWidget (); - if (!isValidDate(getYear(), getMonth(), day)) return; - if ((style & SWT.CALENDAR) != 0) { - this.day = day; - OS.gtk_calendar_select_day(handle, day); - } else { - calendar.set(Calendar.DAY_OF_MONTH, day); - updateControl(); - } -} - -/** - * Sets the receiver's hours. - * <p> - * Hours is an integer between 0 and 23. - * </p> - * - * @param hours an integer between 0 and 23 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 setHours (int hours) { - checkWidget (); - if (!isValidTime(Calendar.HOUR_OF_DAY, hours)) return; - if ((style & SWT.CALENDAR) != 0) { - this.hours = hours; - } else { - calendar.set(Calendar.HOUR_OF_DAY, hours); - updateControl(); - } -} - -/** - * Sets the receiver's minutes. - * <p> - * Minutes is an integer between 0 and 59. - * </p> - * - * @param minutes an integer between 0 and 59 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 setMinutes (int minutes) { - checkWidget (); - if (!isValidTime(Calendar.MINUTE, minutes)) return; - if ((style & SWT.CALENDAR) != 0) { - this.minutes = minutes; - } else { - calendar.set(Calendar.MINUTE, minutes); - updateControl(); - } -} - -/** - * Sets the receiver's month. - * <p> - * The first month of the year is 0, and the last month is 11. - * If the specified month is not valid for the receiver's day and year, then it is ignored. - * </p> - * - * @param month an integer between 0 and 11 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 #setDate - */ -public void setMonth (int month) { - checkWidget (); - if (!isValidDate(getYear(), month, getDay())) return; - if ((style & SWT.CALENDAR) != 0) { - this.month = month; - OS.gtk_calendar_select_month(handle, month, year); - } else { - calendar.set(Calendar.MONTH, month); - updateControl(); - } -} - -/** - * Sets the receiver's seconds. - * <p> - * Seconds is an integer between 0 and 59. - * </p> - * - * @param seconds an integer between 0 and 59 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 setSeconds (int seconds) { - checkWidget (); - if (!isValidTime(Calendar.SECOND, seconds)) return; - if ((style & SWT.CALENDAR) != 0) { - this.seconds = seconds; - } else { - calendar.set(Calendar.SECOND, seconds); - updateControl(); - } -} - -/** - * Sets the receiver's hours, minutes, and seconds in a single operation. - * - * @param hours an integer between 0 and 23 - * @param minutes an integer between 0 and 59 - * @param seconds an integer between 0 and 59 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 setTime (int hours, int minutes, int seconds) { - checkWidget (); - if (!isValidTime(Calendar.HOUR_OF_DAY, hours)) return; - if (!isValidTime(Calendar.MINUTE, minutes)) return; - if (!isValidTime(Calendar.SECOND, seconds)) return; - if ((style & SWT.CALENDAR) != 0) { - this.hours = hours; - this.minutes = minutes; - this.seconds = seconds; - } else { - calendar.set(Calendar.HOUR_OF_DAY, hours); - calendar.set(Calendar.MINUTE, minutes); - calendar.set(Calendar.SECOND, seconds); - updateControl(); - } -} - -/** - * Sets the receiver's year. - * <p> - * The first year is 1752 and the last year is 9999. - * If the specified year is not valid for the receiver's day and month, then it is ignored. - * </p> - * - * @param year an integer between 1752 and 9999 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 #setDate - */ -public void setYear (int year) { - checkWidget (); - if (!isValidDate(year, getMonth(), getDay())) return; - if ((style & SWT.CALENDAR) != 0) { - this.year = year; - OS.gtk_calendar_select_month(handle, month, year); - } else { - calendar.set(Calendar.YEAR, year); - updateControl(); - } -} - -int unformattedIntValue(int fieldName, String newText, boolean adjust, int max) { - int newValue; - try { - newValue = Integer.parseInt(newText); - } catch (NumberFormatException ex) { - return -1; - } - if (fieldName == Calendar.MONTH && adjust) { - newValue--; - if (newValue == -1) newValue = max; - } - if (fieldName == Calendar.HOUR && adjust) { - if (newValue == 12) newValue = 0; // TODO: needs more work for setFormat and locale - } - return newValue; -} - -public void updateControl() { - if (text != null) { - String string = getFormattedString(style); - ignoreVerify = true; - text.setText(string); - ignoreVerify = false; - } - redraw(); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java deleted file mode 100644 index 38ed5a2f6a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Decorations.java +++ /dev/null @@ -1,752 +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.gtk.*; -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 text; - Image image; - Image [] images = new Image [0]; - boolean minimized, maximized; - Menu menuBar; - Menu [] menus; - Control savedFocus; - Button defaultButton, saveDefault; - int /*long*/ accelGroup, vboxHandle; - -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)); -} - -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); -} - -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; - } - int /*long*/ pixbufs = 0; - if (images != null) { - for (int i = 0; i < images.length; i++) { - Image image = images [i]; - int /*long*/ pixbuf = Display.createPixbuf (image); - pixbufs = OS.g_list_append (pixbufs, pixbuf); - } - } - OS.gtk_window_set_icon_list (topHandle (), pixbufs); - int /*long*/ [] data = new int /*long*/ [1]; - int /*long*/ temp = pixbufs; - while (temp != 0) { - OS.memmove (data, temp, OS.PTR_SIZEOF); - OS.g_object_unref (data [0]); - temp = OS.g_list_next (temp); - } - if (pixbufs != 0) OS.g_list_free (pixbufs); -} - -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; -} - -int compare (ImageData data1, ImageData data2) { - if (data1.width == data2.width && data1.height == data2.height) { - int transparent1 = data1.getTransparencyType (); - int transparent2 = data2.getTransparencyType (); - if (transparent1 == SWT.TRANSPARENCY_ALPHA) return -1; - if (transparent2 == SWT.TRANSPARENCY_ALPHA) return 1; - 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; -} - -Widget computeTabGroup () { - return this; -} - -Control computeTabRoot () { - return this; -} - -void createAccelGroup () { - if (accelGroup != 0) return; - accelGroup = OS.gtk_accel_group_new (); - if (accelGroup == 0) SWT.error (SWT.ERROR_NO_HANDLES); - //FIXME - what should we do for Decorations - int /*long*/ shellHandle = topHandle (); - OS.gtk_window_add_accel_group (shellHandle, accelGroup); -} - -void createWidget (int index) { - super.createWidget (index); - text = ""; -} - -void destroyAccelGroup () { - if (accelGroup == 0) return; - int /*long*/ shellHandle = topHandle (); - OS.gtk_window_remove_accel_group (shellHandle, accelGroup); - //TEMPORARY CODE -// OS.g_object_unref (accelGroup); - accelGroup = 0; -} - -void fixAccelGroup () { - if (menuBar == null) return; - destroyAccelGroup (); - createAccelGroup (); - menuBar.addAccelerators (accelGroup); -} - -void fixDecorations (Decorations newDecorations, Control control, Menu [] menus) { - if (this == newDecorations) return; - if (control == savedFocus) savedFocus = null; - if (control == defaultButton) defaultButton = null; - if (control == saveDefault) saveDefault = null; - if (menus == null) return; - Menu menu = control.menu; - if (menu != null) { - int index = 0; - while (index <menus.length) { - if (menus [index] == menu) { - control.setMenu (null); - return; - } - index++; - } - menu.fixMenus (newDecorations); - } -} - -/** - * 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 != null ? defaultButton : saveDefault; -} - -/** - * 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 text; -} - -public boolean isReparentable () { - checkWidget (); - return false; -} - -boolean isTabGroup () { - return true; -} - -boolean isTabItem () { - return false; -} - -Decorations menuShell () { - return this; -} - -void removeMenu (Menu menu) { - if (menus == null) return; - for (int i=0; i<menus.length; i++) { - if (menus [i] == menu) { - menus [i] = null; - return; - } - } -} - -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.dispose (); - } - } - menus = null; - } -} - -void releaseHandle () { - super.releaseHandle (); - vboxHandle = 0; -} - -void releaseWidget () { - super.releaseWidget (); - image = null; - images = null; - savedFocus = null; - defaultButton = saveDefault = 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; -} - -/** - * 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(); - int /*long*/ buttonHandle = 0; - if (button != null) { - if (button.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - if (button.menuShell () != this) error (SWT.ERROR_INVALID_PARENT); - buttonHandle = button.handle; - } - saveDefault = defaultButton = button; - OS.gtk_window_set_default (topHandle (), buttonHandle); -} - -/** - * 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 (); - 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.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR); - if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT); - } - menuBar = menu; -} - -/** - * 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); - text = 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 traverseItem (boolean next) { - return false; -} - -boolean traverseReturn () { - Button button = defaultButton != null ? defaultButton: saveDefault; - if (button == null || button.isDisposed ()) return false; - /* - * Bug in GTK. When a default button that is disabled is - * activated using the Enter key, GTK GP's. The fix is to - * detect this case and stop GTK from processing the Enter - * key. - */ - if (!button.isVisible () || !button.isEnabled ()) return true; - int /*long*/ shellHandle = _getShell ().topHandle (); - return OS.gtk_window_activate_default (shellHandle); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java deleted file mode 100644 index 8b31222fad..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/DirectoryDialog.java +++ /dev/null @@ -1,339 +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.gtk.*; - -/** - * 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 message = "", filterPath = ""; - static final String SEPARATOR = System.getProperty ("file.separator"); - -/** - * 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 (); -} -/** - * 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 () { - boolean useChooserDialog = OS.GTK_VERSION >= OS.VERSION (2, 4, 10); - if (useChooserDialog) { - return openChooserDialog (); - } else { - return openClassicDialog (); - } -} -String openChooserDialog () { - byte [] titleBytes = Converter.wcsToMbcs (null, title, true); - int /*long*/ shellHandle = parent.topHandle (); - Display display = parent != null ? parent.getDisplay (): Display.getCurrent (); - int /*long*/ handle = 0; - if (display.getDismissalAlignment() == SWT.RIGHT) { - handle = OS.gtk_file_chooser_dialog_new (titleBytes, shellHandle, OS.GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, OS.GTK_STOCK_CANCEL (), OS.GTK_RESPONSE_CANCEL, OS.GTK_STOCK_OK (), OS.GTK_RESPONSE_OK, 0); - } else { - handle = OS.gtk_file_chooser_dialog_new (titleBytes, shellHandle, OS.GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER, OS.GTK_STOCK_OK (), OS.GTK_RESPONSE_OK, OS.GTK_STOCK_CANCEL (), OS.GTK_RESPONSE_CANCEL, 0); - } - OS.gtk_window_set_modal (handle, true); - int /*long*/ pixbufs = OS.gtk_window_get_icon_list (shellHandle); - if (pixbufs != 0) { - OS.gtk_window_set_icon_list (handle, pixbufs); - OS.g_list_free (pixbufs); - } - if (filterPath != null && filterPath.length () > 0) { - StringBuffer stringBuffer = new StringBuffer (); - /* filename must be a full path */ - if (!filterPath.startsWith (SEPARATOR)) { - stringBuffer.append (SEPARATOR); - } - stringBuffer.append (filterPath); - byte [] buffer = Converter.wcsToMbcs (null, stringBuffer.toString (), true); - /* - * Bug in GTK. GtkFileChooser may crash on GTK versions 2.4.10 to 2.6 - * when setting a file name that is not a true canonical path. - * The fix is to use the canonical path. - */ - int /*long*/ ptr = OS.realpath (buffer, null); - if (ptr != 0) { - OS.gtk_file_chooser_set_current_folder (handle, ptr); - OS.g_free (ptr); - } - } - if (message.length () > 0) { - byte [] buffer = Converter.wcsToMbcs (null, message, true); - int /*long*/ box = OS.gtk_hbox_new (false, 0); - if (box == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ label = OS.gtk_label_new (buffer); - if (label == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (box, label); - OS.gtk_widget_show (label); - OS.gtk_label_set_line_wrap (label, true); - OS.gtk_label_set_justify (label, OS.GTK_JUSTIFY_CENTER); - OS.gtk_file_chooser_set_extra_widget (handle, box); - } - String answer = null; - display.addIdleProc (); - Dialog oldModal = null; - if (OS.gtk_window_get_modal (handle)) { - oldModal = display.getModalDialog (); - display.setModalDialog (this); - } - int signalId = 0; - int /*long*/ hookId = 0; - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - signalId = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET()); - hookId = OS.g_signal_add_emission_hook (signalId, 0, display.emissionProc, handle, 0); - } - int response = OS.gtk_dialog_run (handle); - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - OS.g_signal_remove_emission_hook (signalId, hookId); - } - if (OS.gtk_window_get_modal (handle)) { - display.setModalDialog (oldModal); - } - if (response == OS.GTK_RESPONSE_OK) { - int /*long*/ path = OS.gtk_file_chooser_get_filename (handle); - if (path != 0) { - int /*long*/ utf8Ptr = OS.g_filename_to_utf8 (path, -1, null, null, null); - OS.g_free (path); - if (utf8Ptr != 0) { - int /*long*/ [] items_written = new int /*long*/ [1]; - int /*long*/ utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null); - OS.g_free (utf8Ptr); - if (utf16Ptr != 0) { - int clength = (int)/*64*/items_written [0]; - char [] chars = new char [clength]; - OS.memmove (chars, utf16Ptr, clength * 2); - OS.g_free (utf16Ptr); - answer = new String (chars); - filterPath = answer; - } - } - } - } - display.removeIdleProc (); - OS.gtk_widget_destroy (handle); - return answer; -} -String openClassicDialog () { - byte [] titleBytes = Converter.wcsToMbcs (null, title, true); - int /*long*/ handle = OS.gtk_file_selection_new (titleBytes); - if (parent != null) { - int /*long*/ shellHandle = parent.topHandle (); - OS.gtk_window_set_transient_for (handle, shellHandle); - int /*long*/ pixbufs = OS.gtk_window_get_icon_list (shellHandle); - if (pixbufs != 0) { - OS.gtk_window_set_icon_list (handle, pixbufs); - OS.g_list_free (pixbufs); - } - } - OS.gtk_window_set_modal (handle, true); - String answer = null; - if (filterPath != null) { - String path = filterPath; - if (path.length () > 0 && !path.endsWith (SEPARATOR)) { - path += SEPARATOR; - } - int length = path.length (); - char [] buffer = new char [length + 1]; - path.getChars (0, length, buffer, 0); - int /*long*/ utf8Ptr = OS.g_utf16_to_utf8 (buffer, -1, null, null, null); - int /*long*/ fileNamePtr = OS.g_filename_from_utf8 (utf8Ptr, -1, null, null, null); - OS.gtk_file_selection_set_filename (handle, fileNamePtr); - OS.g_free (utf8Ptr); - OS.g_free (fileNamePtr); - } - GtkFileSelection selection = new GtkFileSelection (); - OS.memmove (selection, handle); - OS.gtk_file_selection_hide_fileop_buttons (handle); - int /*long*/ fileListParent = OS.gtk_widget_get_parent (selection.file_list); - OS.gtk_widget_hide (selection.file_list); - OS.gtk_widget_hide (fileListParent); - if (message.length () > 0) { - byte [] buffer = Converter.wcsToMbcs (null, message, true); - int /*long*/ labelHandle = OS.gtk_label_new (buffer); - OS.gtk_label_set_line_wrap (labelHandle, true); - OS.gtk_misc_set_alignment (labelHandle, 0.0f, 0.0f); - OS.gtk_container_add (selection.main_vbox, labelHandle); - OS.gtk_box_set_child_packing ( - selection.main_vbox, labelHandle, false, false, 0, OS.GTK_PACK_START); - OS.gtk_widget_show (labelHandle); - } - Display display = parent != null ? parent.getDisplay (): Display.getCurrent (); - display.addIdleProc (); - Dialog oldModal = null; - if (OS.gtk_window_get_modal (handle)) { - oldModal = display.getModalDialog (); - display.setModalDialog (this); - } - int signalId = 0; - int /*long*/ hookId = 0; - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - signalId = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET()); - hookId = OS.g_signal_add_emission_hook (signalId, 0, display.emissionProc, handle, 0); - } - int response = OS.gtk_dialog_run (handle); - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - OS.g_signal_remove_emission_hook (signalId, hookId); - } - if (OS.gtk_window_get_modal (handle)) { - display.setModalDialog (oldModal); - } - if (response == OS.GTK_RESPONSE_OK) { - int /*long*/ fileNamePtr = OS.gtk_file_selection_get_filename (handle); - int /*long*/ utf8Ptr = OS.g_filename_to_utf8 (fileNamePtr, -1, null, null, null); - if (utf8Ptr != 0) { - int /*long*/ [] items_written = new int /*long*/ [1]; - int /*long*/ utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null); - if (utf16Ptr != 0) { - int length = (int)/*64*/items_written [0]; - char [] buffer = new char [length]; - OS.memmove (buffer, utf16Ptr, length * 2); - String osAnswer = new String (buffer); - if (osAnswer != null) { - /* remove trailing separator, unless root directory */ - if (!osAnswer.equals (SEPARATOR) && osAnswer.endsWith (SEPARATOR)) { - osAnswer = osAnswer.substring (0, osAnswer.length () - 1); - } - answer = filterPath = osAnswer; - } - OS.g_free (utf16Ptr); - } - OS.g_free (utf8Ptr); - } - } - display.removeIdleProc (); - OS.gtk_widget_destroy (handle); - return answer; -} -/** - * 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/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java deleted file mode 100644 index 0e1945fe3e..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java +++ /dev/null @@ -1,4212 +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.gtk.*; -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 { - - /* Events Dispatching and Callback */ - int gdkEventCount; - int /*long*/ [] gdkEvents; - Widget [] gdkEventWidgets; - int [] dispatchEvents; - Event [] eventQueue; - int /*long*/ fds; - int allocated_nfds; - boolean wake; - int [] max_priority = new int [1], timeout = new int [1]; - Callback eventCallback, filterCallback; - int /*long*/ eventProc, filterProc, windowProc2, windowProc3, windowProc4, windowProc5; - Callback windowCallback2, windowCallback3, windowCallback4, windowCallback5; - EventTable eventTable, filterTable; - static String APP_NAME = "SWT"; //$NON-NLS-1$ - static final String DISPATCH_EVENT_KEY = "org.eclipse.swt.internal.gtk.dispatchEvent"; //$NON-NLS-1$ - static final String ADD_WIDGET_KEY = "org.eclipse.swt.internal.addWidget"; //$NON-NLS-1$ - int /*long*/ [] closures; - int [] signalIds; - int /*long*/ shellMapProcClosure; - - /* Widget Table */ - int [] indexTable; - int freeSlot; - int /*long*/ lastHandle; - Widget lastWidget; - Widget [] widgetTable; - final static int GROW_SIZE = 1024; - static final int SWT_OBJECT_INDEX; - static final int SWT_OBJECT_INDEX1; - static final int SWT_OBJECT_INDEX2; - static { - byte [] buffer = Converter.wcsToMbcs (null, "SWT_OBJECT_INDEX", true); //$NON-NLS-1$ - SWT_OBJECT_INDEX = OS.g_quark_from_string (buffer); - buffer = Converter.wcsToMbcs (null, "SWT_OBJECT_INDEX1", true); //$NON-NLS-1$ - SWT_OBJECT_INDEX1 = OS.g_quark_from_string (buffer); - buffer = Converter.wcsToMbcs (null, "SWT_OBJECT_INDEX2", true); //$NON-NLS-1$ - SWT_OBJECT_INDEX2 = OS.g_quark_from_string (buffer); - } - - /* Modality */ - Shell [] modalShells; - Dialog modalDialog; - static final String GET_MODAL_DIALOG = "org.eclipse.swt.internal.gtk.getModalDialog"; //$NON-NLS-1$ - static final String SET_MODAL_DIALOG = "org.eclipse.swt.internal.gtk.setModalDialog"; //$NON-NLS-1$ - - /* Focus */ - int focusEvent; - Control focusControl; - Shell activeShell; - boolean activePending; - boolean ignoreActivate, ignoreFocus; - - /* Input method resources */ - Control imControl; - int /*long*/ preeditWindow, preeditLabel; - - /* 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 /*long*/ timerProc; - Callback windowTimerCallback; - int /*long*/ windowTimerProc; - - /* Caret */ - Caret currentCaret; - Callback caretCallback; - int caretId; - int /*long*/ caretProc; - - /* Mnemonics */ - Control mnemonicControl; - - /* Mouse hover */ - int mouseHoverId; - int /*long*/ mouseHoverHandle, mouseHoverProc; - Callback mouseHoverCallback; - - /* Menu position callback */ - int /*long*/ menuPositionProc; - Callback menuPositionCallback; - - /* Tooltip size allocate callback */ - int /*long*/ sizeAllocateProc; - Callback sizeAllocateCallback; - int /*long*/ sizeRequestProc; - Callback sizeRequestCallback; - - /* Shell map callback */ - int /*long*/ shellMapProc; - Callback shellMapCallback; - - /* Idle proc callback */ - int /*long*/ idleProc; - int idleHandle; - Callback idleCallback; - static final String ADD_IDLE_PROC_KEY = "org.eclipse.swt.internal.gtk.addIdleProc"; //$NON-NLS-1$ - static final String REMOVE_IDLE_PROC_KEY = "org.eclipse.swt.internal.gtk.removeIdleProc"; //$NON-NLS-1$ - Object idleLock = new Object(); - boolean idleNeeded; - - /* GtkTreeView callbacks */ - int[] treeSelection; - int treeSelectionLength; - int /*long*/ treeSelectionProc; - Callback treeSelectionCallback; - int /*long*/ cellDataProc; - Callback cellDataCallback; - - /* Set direction callback */ - int /*long*/ setDirectionProc; - Callback setDirectionCallback; - static final String GET_DIRECTION_PROC_KEY = "org.eclipse.swt.internal.gtk.getDirectionProc"; //$NON-NLS-1$ - - /* Set emissionProc callback */ - int /*long*/ emissionProc; - Callback emissionProcCallback; - static final String GET_EMISSION_PROC_KEY = "org.eclipse.swt.internal.gtk.getEmissionProc"; //$NON-NLS-1$ - - /* Get all children callback */ - int /*long*/ allChildrenProc, allChildren; - Callback allChildrenCallback; - - /* Settings callbacks */ - int /*long*/ styleSetProc; - Callback styleSetCallback; - int /*long*/ shellHandle; - boolean settingsChanged, runSettings; - - /* Entry focus behaviour */ - boolean entrySelectOnFocus; - - /* Enter/Exit events */ - Control currentControl; - - /* Flush exposes */ - int /*long*/ checkIfEventProc; - Callback checkIfEventCallback; - int /*long*/ flushWindow; - boolean flushAll; - GdkRectangle flushRect = new GdkRectangle (); - XExposeEvent exposeEvent = new XExposeEvent (); - XVisibilityEvent visibilityEvent = new XVisibilityEvent (); - int /*long*/ [] flushData = new int /*long*/ [1]; - - /* System Resources */ - Font systemFont; - Image errorImage, infoImage, questionImage, warningImage; - Cursor [] cursors = new Cursor [SWT.CURSOR_HAND + 1]; - Resource [] resources; - static final int RESOURCE_SIZE = 1 + 4 + SWT.CURSOR_HAND + 1; - - /* Colors */ - GdkColor COLOR_WIDGET_DARK_SHADOW, COLOR_WIDGET_NORMAL_SHADOW, COLOR_WIDGET_LIGHT_SHADOW; - GdkColor COLOR_WIDGET_HIGHLIGHT_SHADOW, COLOR_WIDGET_BACKGROUND, COLOR_WIDGET_FOREGROUND, COLOR_WIDGET_BORDER; - GdkColor COLOR_LIST_FOREGROUND, COLOR_LIST_BACKGROUND, COLOR_LIST_SELECTION, COLOR_LIST_SELECTION_TEXT; - GdkColor COLOR_INFO_BACKGROUND, COLOR_INFO_FOREGROUND; - GdkColor COLOR_TITLE_FOREGROUND, COLOR_TITLE_BACKGROUND, COLOR_TITLE_BACKGROUND_GRADIENT; - GdkColor COLOR_TITLE_INACTIVE_FOREGROUND, COLOR_TITLE_INACTIVE_BACKGROUND, COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT; - - /* Popup Menus */ - Menu [] popups; - - /* Click count*/ - int clickCount = 1; - - /* Entry inner border */ - static final int INNER_BORDER = 2; - - /* Timestamp of the Last Received Events */ - int lastEventTime, lastUserEventTime; - - /* Pango layout constructor */ - int /*long*/ pangoLayoutNewProc, pangoLayoutNewDefaultProc; - Callback pangoLayoutNewCallback; - - /* Fixed Subclass */ - static int /*long*/ fixed_type; - static int /*long*/ fixed_info_ptr; - static Callback fixedClassInitCallback, fixedMapCallback, fixedSizeAllocateCallback; - static int /*long*/ fixedClassInitProc, fixedMapProc, fixedSizeAllocateProc, oldFixedSizeAllocateProc; - - /* Renderer Subclass */ - static int /*long*/ text_renderer_type, pixbuf_renderer_type, toggle_renderer_type; - static int /*long*/ text_renderer_info_ptr, pixbuf_renderer_info_ptr, toggle_renderer_info_ptr; - static Callback rendererClassInitCallback, rendererRenderCallback, rendererGetSizeCallback; - static int /*long*/ rendererClassInitProc, rendererRenderProc, rendererGetSizeProc; - - /* Key Mappings */ - static final int [] [] KeyTable = { - - /* Keyboard and Mouse Masks */ - {OS.GDK_Alt_L, SWT.ALT}, - {OS.GDK_Alt_R, SWT.ALT}, - {OS.GDK_Meta_L, SWT.ALT}, - {OS.GDK_Meta_R, SWT.ALT}, - {OS.GDK_Shift_L, SWT.SHIFT}, - {OS.GDK_Shift_R, SWT.SHIFT}, - {OS.GDK_Control_L, SWT.CONTROL}, - {OS.GDK_Control_R, SWT.CONTROL}, -// {OS.GDK_????, SWT.COMMAND}, -// {OS.GDK_????, SWT.COMMAND}, - - /* Non-Numeric Keypad Keys */ - {OS.GDK_Up, SWT.ARROW_UP}, - {OS.GDK_KP_Up, SWT.ARROW_UP}, - {OS.GDK_Down, SWT.ARROW_DOWN}, - {OS.GDK_KP_Down, SWT.ARROW_DOWN}, - {OS.GDK_Left, SWT.ARROW_LEFT}, - {OS.GDK_KP_Left, SWT.ARROW_LEFT}, - {OS.GDK_Right, SWT.ARROW_RIGHT}, - {OS.GDK_KP_Right, SWT.ARROW_RIGHT}, - {OS.GDK_Page_Up, SWT.PAGE_UP}, - {OS.GDK_KP_Page_Up, SWT.PAGE_UP}, - {OS.GDK_Page_Down, SWT.PAGE_DOWN}, - {OS.GDK_KP_Page_Down, SWT.PAGE_DOWN}, - {OS.GDK_Home, SWT.HOME}, - {OS.GDK_KP_Home, SWT.HOME}, - {OS.GDK_End, SWT.END}, - {OS.GDK_KP_End, SWT.END}, - {OS.GDK_Insert, SWT.INSERT}, - {OS.GDK_KP_Insert, SWT.INSERT}, - - /* Virtual and Ascii Keys */ - {OS.GDK_BackSpace, SWT.BS}, - {OS.GDK_Return, SWT.CR}, - {OS.GDK_Delete, SWT.DEL}, - {OS.GDK_KP_Delete, SWT.DEL}, - {OS.GDK_Escape, SWT.ESC}, - {OS.GDK_Linefeed, SWT.LF}, - {OS.GDK_Tab, SWT.TAB}, - {OS.GDK_ISO_Left_Tab, SWT.TAB}, - - /* Functions Keys */ - {OS.GDK_F1, SWT.F1}, - {OS.GDK_F2, SWT.F2}, - {OS.GDK_F3, SWT.F3}, - {OS.GDK_F4, SWT.F4}, - {OS.GDK_F5, SWT.F5}, - {OS.GDK_F6, SWT.F6}, - {OS.GDK_F7, SWT.F7}, - {OS.GDK_F8, SWT.F8}, - {OS.GDK_F9, SWT.F9}, - {OS.GDK_F10, SWT.F10}, - {OS.GDK_F11, SWT.F11}, - {OS.GDK_F12, SWT.F12}, - {OS.GDK_F13, SWT.F13}, - {OS.GDK_F14, SWT.F14}, - {OS.GDK_F15, SWT.F15}, - - /* Numeric Keypad Keys */ - {OS.GDK_KP_Multiply, SWT.KEYPAD_MULTIPLY}, - {OS.GDK_KP_Add, SWT.KEYPAD_ADD}, - {OS.GDK_KP_Enter, SWT.KEYPAD_CR}, - {OS.GDK_KP_Subtract, SWT.KEYPAD_SUBTRACT}, - {OS.GDK_KP_Decimal, SWT.KEYPAD_DECIMAL}, - {OS.GDK_KP_Divide, SWT.KEYPAD_DIVIDE}, - {OS.GDK_KP_0, SWT.KEYPAD_0}, - {OS.GDK_KP_1, SWT.KEYPAD_1}, - {OS.GDK_KP_2, SWT.KEYPAD_2}, - {OS.GDK_KP_3, SWT.KEYPAD_3}, - {OS.GDK_KP_4, SWT.KEYPAD_4}, - {OS.GDK_KP_5, SWT.KEYPAD_5}, - {OS.GDK_KP_6, SWT.KEYPAD_6}, - {OS.GDK_KP_7, SWT.KEYPAD_7}, - {OS.GDK_KP_8, SWT.KEYPAD_8}, - {OS.GDK_KP_9, SWT.KEYPAD_9}, - {OS.GDK_KP_Equal, SWT.KEYPAD_EQUAL}, - - /* Other keys */ - {OS.GDK_Caps_Lock, SWT.CAPS_LOCK}, - {OS.GDK_Num_Lock, SWT.NUM_LOCK}, - {OS.GDK_Scroll_Lock, SWT.SCROLL_LOCK}, - {OS.GDK_Pause, SWT.PAUSE}, - {OS.GDK_Break, SWT.BREAK}, - {OS.GDK_Print, SWT.PRINT_SCREEN}, - {OS.GDK_Help, SWT.HELP}, - - }; - - /* Multiple Displays. */ - static Display Default; - static Display [] Displays = new Display [4]; - - /* Package name */ - static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets."; //$NON-NLS-1$ - /* This code is intentionally commented. - * ".class" can not be used on CLDC. - */ -// static { -// String name = Display.class.getName (); -// int index = name.lastIndexOf ('.'); -// PACKAGE_NAME = name.substring (0, index + 1); -// } - - /* GTK Version */ - static final int MAJOR = 2; - static final int MINOR = 2; - static final int MICRO = 0; - - /* Display Data */ - Object data; - String [] keys; - Object [] values; - - /* Initial Guesses for Shell Trimmings. */ - int borderTrimWidth = 4, borderTrimHeight = 4; - int resizeTrimWidth = 6, resizeTrimHeight = 6; - int titleBorderTrimWidth = 5, titleBorderTrimHeight = 28; - int titleResizeTrimWidth = 6, titleResizeTrimHeight = 29; - int titleTrimWidth = 0, titleTrimHeight = 23; - boolean ignoreTrim; - - /* Window Manager */ - String windowManager; - - /* - * 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 (data); -} - -/** - * 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); -} - -void addGdkEvent (int /*long*/ event) { - if (gdkEvents == null) { - int length = GROW_SIZE; - gdkEvents = new int /*long*/ [length]; - gdkEventWidgets = new Widget [length]; - gdkEventCount = 0; - } - if (gdkEventCount == gdkEvents.length) { - int length = gdkEventCount + GROW_SIZE; - int /*long*/ [] newEvents = new int /*long*/ [length]; - System.arraycopy (gdkEvents, 0, newEvents, 0, gdkEventCount); - gdkEvents = newEvents; - Widget [] newWidgets = new Widget [length]; - System.arraycopy (gdkEventWidgets, 0, newWidgets, 0, gdkEventCount); - gdkEventWidgets = newWidgets; - } - Widget widget = null; - int /*long*/ handle = OS.gtk_get_event_widget (event); - if (handle != 0) { - do { - widget = getWidget (handle); - } while (widget == null && (handle = OS.gtk_widget_get_parent (handle)) != 0); - } - gdkEvents [gdkEventCount] = event; - gdkEventWidgets [gdkEventCount] = widget; - gdkEventCount++; -} - -void addIdleProc() { - synchronized (idleLock){ - this.idleNeeded = true; - if (idleHandle == 0) { - idleHandle = OS.g_idle_add (idleProc, 0); - } - } -} - -/** - * 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); -} - -int /*long*/ allChildrenProc (int /*long*/ widget, int /*long*/ recurse) { - allChildren = OS.g_list_append (allChildren, widget); - if (recurse != 0 && OS.GTK_IS_CONTAINER (widget)) { - OS.gtk_container_forall (widget, allChildrenProc, recurse); - } - return 0; -} - -void addMouseHoverTimeout (int /*long*/ handle) { - if (mouseHoverId != 0) OS.gtk_timeout_remove (mouseHoverId); - mouseHoverId = OS.gtk_timeout_add (400, mouseHoverProc, handle); - mouseHoverHandle = handle; -} - -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; -} - -void addWidget (int /*long*/ handle, Widget widget) { - if (handle == 0) 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; - } - int index = freeSlot + 1; - OS.g_object_set_qdata (handle, SWT_OBJECT_INDEX, index); - int oldSlot = freeSlot; - freeSlot = indexTable[oldSlot]; - indexTable [oldSlot] = -2; - widgetTable [oldSlot] = widget; -} - -/** - * 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); - synchronized (idleLock) { - if (idleNeeded && idleHandle == 0) { - //NOTE: calling unlocked function in OS - idleHandle = OS._g_idle_add (idleProc, 0); - } - } - 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - OS.gdk_beep(); - if (!OS.GDK_WINDOWING_X11 ()) { - OS.gdk_flush (); - } else { - int /*long*/ xDisplay = OS.GDK_DISPLAY (); - OS.XFlush (xDisplay); - } -} - -int /*long*/ cellDataProc (int /*long*/ tree_column, int /*long*/ cell, int /*long*/ tree_model, int /*long*/ iter, int /*long*/ data) { - Widget widget = getWidget (data); - if (widget == null) return 0; - return widget.cellDataProc (tree_column, cell, tree_model, iter, 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); -} - -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); - } - } - } -} - -int /*long*/ checkIfEventProc (int /*long*/ display, int /*long*/ xEvent, int /*long*/ userData) { - int type = OS.X_EVENT_TYPE (xEvent); - switch (type) { - case OS.VisibilityNotify: - case OS.Expose: - case OS.GraphicsExpose: - break; - default: - return 0; - } - int /*long*/ window = OS.gdk_window_lookup (OS.X_EVENT_WINDOW (xEvent)); - if (window == 0) return 0; - if (flushWindow != 0) { - if (flushAll) { - int /*long*/ tempWindow = window; - do { - if (tempWindow == flushWindow) break; - } while ((tempWindow = OS.gdk_window_get_parent (tempWindow)) != 0); - if (tempWindow != flushWindow) return 0; - } else { - if (window != flushWindow) return 0; - } - } - OS.memmove (exposeEvent, xEvent, XExposeEvent.sizeof); - switch (type) { - case OS.Expose: - case OS.GraphicsExpose: { - flushRect.x = exposeEvent.x; - flushRect.y = exposeEvent.y; - flushRect.width = exposeEvent.width; - flushRect.height = exposeEvent.height; - OS.gdk_window_invalidate_rect (window, flushRect, true); - exposeEvent.type = -1; - OS.memmove (xEvent, exposeEvent, XExposeEvent.sizeof); - break; - } - case OS.VisibilityNotify: { - OS.memmove (visibilityEvent, xEvent, XVisibilityEvent.sizeof); - OS.gdk_window_get_user_data (window, flushData); - int /*long*/ handle = flushData [0]; - Widget widget = handle != 0 ? getWidget (handle) : null; - if (widget != null && widget instanceof Control) { - Control control = (Control) widget; - if (window == control.paintWindow ()) { - if (visibilityEvent.state == OS.VisibilityFullyObscured) { - control.state |= Widget.OBSCURED; - } else { - control.state &= ~Widget.OBSCURED; - } - } - } - break; - } - } - return 0; -} - -/** - * 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 (!isValidClass (getClass ())) error (SWT.ERROR_INVALID_SUBCLASS); -} - -void clearModal (Shell shell) { - if (modalShells == null) return; - int index = 0, length = modalShells.length; - while (index < length) { - if (modalShells [index] == shell) break; - if (modalShells [index] == null) return; - index++; - } - if (index == length) return; - System.arraycopy (modalShells, index + 1, modalShells, index, --length - index); - modalShells [length] = null; - if (index == 0 && modalShells [0] == null) modalShells = null; - Shell [] shells = getShells (); - for (int i=0; i<shells.length; i++) shells [i].updateModal (); -} - -/** - * 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 (); -} - -/** - * 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 (), false); - createDisplay (data); - register (this); - if (Default == null) Default = this; -} - -void createDisplay (DeviceData data) { - /* Required for g_main_context_wakeup */ - if (!OS.g_thread_supported ()) { - OS.g_thread_init (0); - } - OS.gtk_set_locale(); - if (!OS.gtk_init_check (new int /*long*/ [] {0}, null)) { - SWT.error (SWT.ERROR_NO_HANDLES, null, " [gtk_init_check() failed]"); //$NON-NLS-1$ - } - if (OS.GDK_WINDOWING_X11 ()) xDisplay = OS.GDK_DISPLAY (); - int /*long*/ ptr = OS.gtk_check_version (MAJOR, MINOR, MICRO); - if (ptr != 0) { - int length = OS.strlen (ptr); - byte [] buffer = new byte [length]; - OS.memmove (buffer, ptr, length); - System.out.println ("***WARNING: " + new String (Converter.mbcsToWcs (null, buffer))); //$NON-NLS-1$ - System.out.println ("***WARNING: SWT requires GTK " + MAJOR+ "." + MINOR + "." + MICRO); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - int major = OS.gtk_major_version (), minor = OS.gtk_minor_version (), micro = OS.gtk_micro_version (); - System.out.println ("***WARNING: Detected: " + major + "." + minor + "." + micro); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - if (fixed_type == 0) { - byte [] type_name = Converter.wcsToMbcs (null, "SwtFixed", true); //$NON-NLS-1$ - fixedClassInitCallback = new Callback (getClass (), "fixedClassInitProc", 2); //$NON-NLS-1$ - fixedClassInitProc = fixedClassInitCallback.getAddress (); - if (fixedClassInitProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - fixedMapCallback = new Callback (getClass (), "fixedMapProc", 1); //$NON-NLS-1$ - fixedMapProc = fixedMapCallback.getAddress (); - if (fixedMapProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - fixedSizeAllocateCallback = new Callback (getClass (), "fixedSizeAllocateProc", 2); //$NON-NLS-1$ - fixedSizeAllocateProc = fixedSizeAllocateCallback.getAddress (); - if (fixedSizeAllocateProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - GTypeInfo fixed_info = new GTypeInfo (); - fixed_info.class_size = (short) OS.GtkFixedClass_sizeof (); - fixed_info.class_init = fixedClassInitProc; - fixed_info.instance_size = (short) OS.GtkFixed_sizeof (); - fixed_info_ptr = OS.g_malloc (GTypeInfo.sizeof); - OS.memmove (fixed_info_ptr, fixed_info, GTypeInfo.sizeof); - fixed_type = OS.g_type_register_static (OS.GTK_TYPE_FIXED (), type_name, fixed_info_ptr, 0); - } - if (rendererClassInitProc == 0) { - rendererClassInitCallback = new Callback (getClass (), "rendererClassInitProc", 2); //$NON-NLS-1$ - rendererClassInitProc = rendererClassInitCallback.getAddress (); - if (rendererClassInitProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - } - if (rendererRenderProc == 0) { - rendererRenderCallback = new Callback (getClass (), "rendererRenderProc", 7); //$NON-NLS-1$ - rendererRenderProc = rendererRenderCallback.getAddress (); - if (rendererRenderProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - } - if (rendererGetSizeProc == 0) { - rendererGetSizeCallback = new Callback (getClass (), "rendererGetSizeProc", 7); //$NON-NLS-1$ - rendererGetSizeProc = rendererGetSizeCallback.getAddress (); - if (rendererGetSizeProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - } - if (text_renderer_type == 0) { - GTypeInfo renderer_info = new GTypeInfo (); - renderer_info.class_size = (short) OS.GtkCellRendererTextClass_sizeof (); - renderer_info.class_init = rendererClassInitProc; - renderer_info.instance_size = (short) OS.GtkCellRendererText_sizeof (); - text_renderer_info_ptr = OS.g_malloc (GTypeInfo.sizeof); - OS.memmove (text_renderer_info_ptr, renderer_info, GTypeInfo.sizeof); - byte [] type_name = Converter.wcsToMbcs (null, "SwtTextRenderer", true); //$NON-NLS-1$ - text_renderer_type = OS.g_type_register_static (OS.GTK_TYPE_CELL_RENDERER_TEXT (), type_name, text_renderer_info_ptr, 0); - } - if (pixbuf_renderer_type == 0) { - GTypeInfo renderer_info = new GTypeInfo (); - renderer_info.class_size = (short) OS.GtkCellRendererPixbufClass_sizeof (); - renderer_info.class_init = rendererClassInitProc; - renderer_info.instance_size = (short) OS.GtkCellRendererPixbuf_sizeof (); - pixbuf_renderer_info_ptr = OS.g_malloc (GTypeInfo.sizeof); - OS.memmove (pixbuf_renderer_info_ptr, renderer_info, GTypeInfo.sizeof); - byte [] type_name = Converter.wcsToMbcs (null, "SwtPixbufRenderer", true); //$NON-NLS-1$ - pixbuf_renderer_type = OS.g_type_register_static (OS.GTK_TYPE_CELL_RENDERER_PIXBUF (), type_name, pixbuf_renderer_info_ptr, 0); - } - if (toggle_renderer_type == 0) { - GTypeInfo renderer_info = new GTypeInfo (); - renderer_info.class_size = (short) OS.GtkCellRendererToggleClass_sizeof (); - renderer_info.class_init = rendererClassInitProc; - renderer_info.instance_size = (short) OS.GtkCellRendererToggle_sizeof (); - toggle_renderer_info_ptr = OS.g_malloc (GTypeInfo.sizeof); - OS.memmove (toggle_renderer_info_ptr, renderer_info, GTypeInfo.sizeof); - byte [] type_name = Converter.wcsToMbcs (null, "SwtToggleRenderer", true); //$NON-NLS-1$ - toggle_renderer_type = OS.g_type_register_static (OS.GTK_TYPE_CELL_RENDERER_TOGGLE (), type_name, toggle_renderer_info_ptr, 0); - } - - OS.gtk_widget_set_default_direction (OS.GTK_TEXT_DIR_LTR); - OS.gdk_rgb_init (); - byte [] buffer = Converter.wcsToMbcs (null, APP_NAME, true); - OS.g_set_prgname (buffer); - OS.gdk_set_program_class (buffer); - byte [] flatStyle = Converter.wcsToMbcs (null, "style \"swt-flat\" { GtkToolbar::shadow-type = none } widget \"*.swt-toolbar-flat\" style : highest \"swt-flat\"", true); //$NON-NLS-1$ - OS.gtk_rc_parse_string (flatStyle); - - /* Initialize the hidden shell */ - shellHandle = OS.gtk_window_new (OS.GTK_WINDOW_TOPLEVEL); - if (shellHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gtk_widget_realize (shellHandle); - - /* Initialize the filter and event callback */ - eventCallback = new Callback (this, "eventProc", 2); //$NON-NLS-1$ - eventProc = eventCallback.getAddress (); - if (eventProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - OS.gdk_event_handler_set (eventProc, 0, 0); - filterCallback = new Callback (this, "filterProc", 3); //$NON-NLS-1$ - filterProc = filterCallback.getAddress (); - if (filterProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - OS.gdk_window_add_filter (0, filterProc, 0); -} - -Image createImage (String name) { - int /*long*/ style = OS.gtk_widget_get_default_style (); - byte[] buffer = Converter.wcsToMbcs (null, name, true); - int /*long*/ pixbuf = OS.gtk_icon_set_render_icon ( - OS.gtk_icon_factory_lookup_default (buffer), style, - OS.GTK_TEXT_DIR_NONE, OS.GTK_STATE_NORMAL, OS.GTK_ICON_SIZE_DIALOG, 0, 0); - if (pixbuf == 0) return null; - int width = OS.gdk_pixbuf_get_width (pixbuf); - int height = OS.gdk_pixbuf_get_height (pixbuf); - int stride = OS.gdk_pixbuf_get_rowstride (pixbuf); - boolean hasAlpha = OS.gdk_pixbuf_get_has_alpha (pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels (pixbuf); - byte [] data = new byte [stride * height]; - OS.memmove (data, pixels, data.length); - OS.g_object_unref (pixbuf); - ImageData imageData = null; - if (hasAlpha) { - PaletteData palette = new PaletteData (0xFF000000, 0xFF0000, 0xFF00); - imageData = new ImageData (width, height, 32, palette); - byte [] alpha = new byte [stride * height]; - for (int y=0; y<height; y++) { - for (int x=0; x<width; x++) { - alpha [y*width+x] = data [y*stride+x*4+3]; - data [y*stride+x*4+3] = 0; - } - } - imageData.setAlphas (0, 0, width * height, alpha, 0); - } else { - PaletteData palette = new PaletteData (0xFF0000, 0xFF00, 0xFF); - imageData = new ImageData (width, height, 24, palette); - } - imageData.data = data; - imageData.bytesPerLine = stride; - return new Image (this, imageData); -} - -static int /*long*/ createPixbuf(Image image) { - int [] w = new int [1], h = new int [1]; - OS.gdk_drawable_get_size (image.pixmap, w, h); - int /*long*/ colormap = OS.gdk_colormap_get_system (); - int /*long*/ pixbuf; - boolean hasMask = image.mask != 0 && OS.gdk_drawable_get_depth (image.mask) == 1; - if (hasMask) { - pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, true, 8, w [0], h [0]); - if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w [0], h [0]); - int /*long*/ maskPixbuf = OS.gdk_pixbuf_new(OS.GDK_COLORSPACE_RGB, false, 8, w [0], h [0]); - if (maskPixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gdk_pixbuf_get_from_drawable(maskPixbuf, image.mask, 0, 0, 0, 0, 0, w [0], h [0]); - int stride = OS.gdk_pixbuf_get_rowstride(pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels(pixbuf); - byte[] line = new byte[stride]; - int maskStride = OS.gdk_pixbuf_get_rowstride(maskPixbuf); - int /*long*/ maskPixels = OS.gdk_pixbuf_get_pixels(maskPixbuf); - byte[] maskLine = new byte[maskStride]; - for (int y=0; y<h[0]; y++) { - int /*long*/ offset = pixels + (y * stride); - OS.memmove(line, offset, stride); - int /*long*/ maskOffset = maskPixels + (y * maskStride); - OS.memmove(maskLine, maskOffset, maskStride); - for (int x=0; x<w[0]; x++) { - if (maskLine[x * 3] == 0) { - line[x * 4 + 3] = 0; - } - } - OS.memmove(offset, line, stride); - } - OS.g_object_unref(maskPixbuf); - } else { - ImageData data = image.getImageData (); - boolean hasAlpha = data.getTransparencyType () == SWT.TRANSPARENCY_ALPHA; - pixbuf = OS.gdk_pixbuf_new (OS.GDK_COLORSPACE_RGB, hasAlpha, 8, w [0], h [0]); - if (pixbuf == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gdk_pixbuf_get_from_drawable (pixbuf, image.pixmap, colormap, 0, 0, 0, 0, w [0], h [0]); - if (hasAlpha) { - byte [] alpha = data.alphaData; - int stride = OS.gdk_pixbuf_get_rowstride (pixbuf); - int /*long*/ pixels = OS.gdk_pixbuf_get_pixels (pixbuf); - byte [] line = new byte [stride]; - for (int y = 0; y < h [0]; y++) { - int /*long*/ offset = pixels + (y * stride); - OS.memmove (line, offset, stride); - for (int x = 0; x < w [0]; x++) { - line [x*4+3] = alpha [y*w [0]+x]; - } - OS.memmove (offset, line, stride); - } - } - } - return pixbuf; -} - -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 () { -} - -int /*long*/ emissionProc (int /*long*/ ihint, int /*long*/ n_param_values, int /*long*/ param_values, int /*long*/ data) { - if (OS.gtk_widget_get_toplevel (OS.g_value_peek_pointer(param_values)) == data) { - OS.gtk_widget_set_direction (OS.g_value_peek_pointer(param_values), OS.GTK_TEXT_DIR_RTL); - } - return 1; -} - -/** - * 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; - } -} - -/** - * 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; -} - -/** - * Does whatever display specific cleanup is required, and then - * uses the code in <code>SWTError.error</code> to handle the error. - * - * @param code the descriptive error code - * - * @see SWTError#error - */ -void error (int code) { - SWT.error (code); -} - -int /*long*/ eventProc (int /*long*/ event, int /*long*/ data) { - /* - * Use gdk_event_get_time() rather than event.time or - * gtk_get_current_event_time(). If the event does not - * have a time stamp, then the field will contain garbage. - * Note that calling gtk_get_current_event_time() from - * outside of gtk_main_do_event() seems to always - * return zero. - */ - int time = OS.gdk_event_get_time (event); - if (time != 0) lastEventTime = time; - - int eventType = OS.GDK_EVENT_TYPE (event); - switch (eventType) { - case OS.GDK_BUTTON_PRESS: - case OS.GDK_KEY_PRESS: - lastUserEventTime = time; - } - boolean dispatch = true; - if (dispatchEvents != null) { - dispatch = false; - for (int i = 0; i < dispatchEvents.length; i++) { - if (eventType == dispatchEvents [i]) { - dispatch = true; - break; - } - } - } - if (!dispatch) { - addGdkEvent (OS.gdk_event_copy (event)); - return 0; - } - OS.gtk_main_do_event (event); - if (dispatchEvents == null) putGdkEvents (); - return 0; -} - -/** - * 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 /*long*/ 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 /*long*/ handle, int /*long*/ 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 /*long*/ id) { - checkDevice (); - return null; -} - -static int /*long*/ fixedClassInitProc (int /*long*/ g_class, int /*long*/ class_data) { - GtkWidgetClass klass = new GtkWidgetClass (); - OS.memmove (klass, g_class); - klass.map = fixedMapProc; - oldFixedSizeAllocateProc = klass.size_allocate; - klass.size_allocate = fixedSizeAllocateProc; - OS.memmove (g_class, klass); - return 0; -} - -static int /*long*/ fixedMapProc (int /*long*/ handle) { - Display display = getCurrent (); - Widget widget = display.getWidget (handle); - if (widget != null) return widget.fixedMapProc (handle); - return 0; -} - -static int /*long*/ fixedSizeAllocateProc (int /*long*/ handle, int /*long*/ allocation) { - Display display = getCurrent (); - Widget widget = display.getWidget (handle); - if (widget != null) return widget.fixedSizeAllocateProc (handle, allocation); - return OS.Call (oldFixedSizeAllocateProc, handle, allocation); -} - -static int /*long*/ rendererClassInitProc (int /*long*/ g_class, int /*long*/ class_data) { - GtkCellRendererClass klass = new GtkCellRendererClass (); - OS.memmove (klass, g_class); - klass.render = rendererRenderProc; - klass.get_size = rendererGetSizeProc; - OS.memmove (g_class, klass); - return 0; -} - -static int /*long*/ rendererGetSizeProc (int /*long*/ cell, int /*long*/ handle, int /*long*/ cell_area, int /*long*/ x_offset, int /*long*/ y_offset, int /*long*/ width, int /*long*/ height) { - Display display = getCurrent (); - Widget widget = display.getWidget (handle); - if (widget != null) return widget.rendererGetSizeProc (cell, handle, cell_area, x_offset, y_offset, width, height); - return 0; -} - -static int /*long*/ rendererRenderProc (int /*long*/ cell, int /*long*/ window, int /*long*/ handle, int /*long*/ background_area, int /*long*/ cell_area, int /*long*/ expose_area, int /*long*/ flags) { - Display display = getCurrent (); - Widget widget = display.getWidget (handle); - if (widget != null) return widget.rendererRenderProc (cell, window, handle, background_area, cell_area, expose_area, flags); - return 0; -} - -void flushExposes (int /*long*/ window, boolean all) { - OS.gdk_flush (); - OS.gdk_flush (); - if (OS.GDK_WINDOWING_X11 ()) { - this.flushWindow = window; - this.flushAll = all; - int /*long*/ xDisplay = OS.GDK_DISPLAY (); - int /*long*/ xEvent = OS.g_malloc (XEvent.sizeof); - OS.XCheckIfEvent (xDisplay, xEvent, checkIfEventProc, 0); - OS.g_free (xEvent); - this.flushWindow = 0; - } -} - -/** - * 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 (); - return activeShell; -} - -/** - * Returns a rectangle describing the receiver's size and location. Note that - * on multi-monitor systems the origin can be negative. - * - * @return the bounding rectangle - * - * @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 Rectangle getBounds () { - checkDevice (); - return new Rectangle (0, 0, OS.gdk_screen_width (), OS.gdk_screen_height ()); -} - -/** - * 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 ()); -} - -int getCaretBlinkTime () { -// checkDevice (); - int /*long*/ settings = OS.gtk_settings_get_default (); - if (settings == 0) return 500; - int [] buffer = new int [1]; - OS.g_object_get (settings, OS.gtk_cursor_blink, buffer, 0); - if (buffer [0] == 0) return 0; - OS.g_object_get (settings, OS.gtk_cursor_blink_time, buffer, 0); - if (buffer [0] == 0) return 500; - /* - * By experimentation, GTK application don't use the whole - * blink cycle time. Instead, they divide up the time, using - * an effective blink rate of about 1/2 the total time. - */ - return buffer [0] / 2; -} - -/** - * 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[] x = new int[1], y = new int[1]; - int /*long*/ handle = 0; - int /*long*/ [] user_data = new int /*long*/ [1]; - int /*long*/ window = OS.gdk_window_at_pointer (x,y); - if (window != 0) { - OS.gdk_window_get_user_data (window, user_data); - handle = user_data [0]; - } else { - /* - * Feature in GTK. gdk_window_at_pointer() will not return a window - * if the pointer is over a foreign embedded window. The fix is to use - * XQueryPointer to find the containing GDK window. - */ - if (!OS.GDK_WINDOWING_X11 ()) return null; - OS.gdk_error_trap_push (); - int[] unusedInt = new int[1]; - int /*long*/[] unusedPtr = new int /*long*/[1], buffer = new int /*long*/[1]; - int /*long*/ xWindow, xParent = OS.XDefaultRootWindow (xDisplay); - do { - if (OS.XQueryPointer (xDisplay, xParent, unusedPtr, buffer, unusedInt, unusedInt, unusedInt, unusedInt, unusedInt) == 0) { - handle = 0; - break; - } - if ((xWindow = buffer [0]) != 0) { - xParent = xWindow; - int /*long*/ gdkWindow = OS.gdk_window_lookup (xWindow); - if (gdkWindow != 0) { - OS.gdk_window_get_user_data (gdkWindow, user_data); - if (user_data[0] != 0) handle = user_data[0]; - } - } - } while (xWindow != 0); - OS.gdk_error_trap_pop (); - } - 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.gtk_widget_get_parent (handle)) != 0); - return null; -} - -static GtkBorder getEntryInnerBorder (int /*long*/ handle) { - GtkBorder gtkBorder = new GtkBorder(); - if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) { - int /*long*/ border = OS.gtk_entry_get_inner_border (handle); - if (border != 0) { - OS.memmove (gtkBorder, border, GtkBorder.sizeof); - return gtkBorder; - } - int /*long*/ [] borderPtr = new int /*long*/ [1]; - OS.gtk_widget_style_get (handle, OS.inner_border, borderPtr,0); - if (borderPtr[0] != 0) { - OS.memmove (gtkBorder, borderPtr[0], GtkBorder.sizeof); - OS.gtk_border_free(borderPtr[0]); - return gtkBorder; - } - } - gtkBorder.left = INNER_BORDER; - gtkBorder.top = INNER_BORDER; - gtkBorder.right = INNER_BORDER; - gtkBorder.bottom = INNER_BORDER; - return gtkBorder; -} - -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); -} - -int /*long*/ filterProc (int /*long*/ xEvent, int /*long*/ gdkEvent, int /*long*/ data) { - if (data == 0) { - /* - * Feature in GTK. When button 4, 5, 6, or 7 is released, GTK - * does not deliver a corresponding GTK event. Button 6 and 7 - * are mapped to buttons 4 and 5 in SWT. The fix is to change - * the button number of the event to a negative number so that - * it gets dispatched by GTK. SWT has been modified to look - * for negative button numbers. - */ - XButtonEvent mouseEvent = new XButtonEvent (); - OS.memmove (mouseEvent, xEvent, 4); - if (mouseEvent.type == OS.ButtonRelease) { - OS.memmove (mouseEvent, xEvent, XButtonEvent.sizeof); - switch (mouseEvent.button) { - case 6: - case 7: - mouseEvent.button = -mouseEvent.button; - OS.memmove (xEvent, mouseEvent, XButtonEvent.sizeof); - break; - } - } - } - Widget widget = getWidget (data); - if (widget == null) return 0; - return widget.filterProc (xEvent, gdkEvent, data); -} - -/** - * 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 [] x = new int [1], y = new int [1]; - OS.gdk_window_get_pointer (0, x, y, null); - return new Point (x [0], y [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 (); - return new Point [] {new Point (16, 16), new Point (32, 32)}; -} - -/** - * 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 (DISPATCH_EVENT_KEY)) { - return dispatchEvents; - } - if (key.equals (GET_MODAL_DIALOG)) { - return modalDialog; - } - if (key.equals (GET_DIRECTION_PROC_KEY)) { - return new LONG (setDirectionProc); - } - if (key.equals (GET_EMISSION_PROC_KEY)) { - return new LONG (emissionProc); - } - 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 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_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Point getDPI () { - checkDevice (); - int widthMM = OS.gdk_screen_width_mm (); - int width = OS.gdk_screen_width (); - int dpi = Compatibility.round (254 * width, widthMM * 10); - return new Point (dpi, dpi); -} - -int /*long*/ gtk_fixed_get_type () { - return fixed_type; -} - -int /*long*/ gtk_cell_renderer_text_get_type () { - return text_renderer_type; -} - -int /*long*/ gtk_cell_renderer_pixbuf_get_type () { - return pixbuf_renderer_type; -} - -int /*long*/ gtk_cell_renderer_toggle_get_type () { - return toggle_renderer_type; -} - -/** - * 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; - } -} - -static boolean isValidClass (Class clazz) { - String name = clazz.getName (); - int index = name.lastIndexOf ('.'); - return name.substring (0, index + 1).equals (PACKAGE_PREFIX); -} - -/** - * 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 (); - int [] buffer = new int [1]; - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) { - int /*long*/ settings = OS.gtk_settings_get_default (); - OS.g_object_get (settings, OS.gtk_alternative_button_order, buffer, 0); - } - return buffer [0] == 1 ? SWT.LEFT : SWT.RIGHT; -} - -/** - * 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 (); - int /*long*/ settings = OS.gtk_settings_get_default (); - int [] buffer = new int [1]; - OS.g_object_get (settings, OS.gtk_double_click_time, buffer, 0); - return buffer [0]; -} - -/** - * 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 (); - if (focusControl != null && !focusControl.isDisposed ()) { - return focusControl; - } - if (activeShell == null) return null; - int /*long*/ shellHandle = activeShell.shellHandle; - int /*long*/ handle = OS.gtk_window_get_focus (shellHandle); - 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.gtk_widget_get_parent (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; -} - -public int getDepth () { - checkDevice (); - GdkVisual visual = new GdkVisual (); - OS.memmove (visual, OS.gdk_visual_get_system()); - return visual.depth; -} - -/** - * 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 () { - checkDevice (); - 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 (); - return new Point [] {new Point (16, 16), new Point (32, 32)}; -} - -int getLastEventTime () { - return lastEventTime; -} - -int getMessageCount () { - return synchronizer.getMessageCount (); -} - -Dialog getModalDialog () { - return modalDialog; -} - -/** - * Returns the work area, an EWMH property to store the size - * and position of the screen not covered by dock and panel - * windows. See http://freedesktop.org/Standards/wm-spec. - */ -Rectangle getWorkArea() { - byte[] name = Converter.wcsToMbcs (null, "_NET_WORKAREA", true); //$NON-NLS-1$ - int /*long*/ atom = OS.gdk_atom_intern (name, true); - if (atom == OS.GDK_NONE) return null; - int /*long*/[] actualType = new int /*long*/[1]; - int[] actualFormat = new int[1]; - int[] actualLength = new int[1]; - int /*long*/[] data = new int /*long*/[1]; - if (!OS.gdk_property_get (OS.GDK_ROOT_PARENT (), atom, OS.GDK_NONE, 0, 16, 0, actualType, actualFormat, actualLength, data)) { - return null; - } - Rectangle result = null; - if (data [0] != 0) { - if (actualLength [0] == 16) { - int values [] = new int [4]; - OS.memmove (values, data[0], 16); - result = new Rectangle (values [0],values [1],values [2],values [3]); - } else if (actualLength [0] == 32) { - long values [] = new long [4]; - OS.memmove (values, data[0], 32); - result = new Rectangle ((int)values [0],(int)values [1],(int)values [2],(int)values [3]); - } - OS.g_free (data [0]); - } - return result; -} - -/** - * Returns an array of monitors attached to the device. - * - * @return the array of monitors - * - * @since 3.0 - */ -public Monitor [] getMonitors () { - checkDevice (); - Monitor [] monitors = null; - Rectangle workArea = getWorkArea(); - int /*long*/ screen = OS.gdk_screen_get_default (); - if (screen != 0) { - int monitorCount = OS.gdk_screen_get_n_monitors (screen); - if (monitorCount > 0) { - monitors = new Monitor [monitorCount]; - GdkRectangle dest = new GdkRectangle (); - for (int i = 0; i < monitorCount; i++) { - OS.gdk_screen_get_monitor_geometry (screen, i, dest); - Monitor monitor = new Monitor (); - monitor.handle = i; - monitor.x = dest.x; - monitor.y = dest.y; - monitor.width = dest.width; - monitor.height = dest.height; - if (i == 0 && workArea != null) { - monitor.clientX = workArea.x; - monitor.clientY = workArea.y; - monitor.clientWidth = workArea.width; - monitor.clientHeight = workArea.height; - } else { - monitor.clientX = monitor.x; - monitor.clientY = monitor.y; - monitor.clientWidth = monitor.width; - monitor.clientHeight = monitor.height; - } - monitors [i] = monitor; - } - } - } - 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; - if (workArea != null) { - monitor.clientX = workArea.x; - monitor.clientY = workArea.y; - monitor.clientWidth = workArea.width; - monitor.clientHeight = workArea.height; - } else { - 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 [] monitors = getMonitors (); - return monitors [0]; -} - -/** - * 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 index = 0; - Shell [] result = new Shell [16]; - for (int i = 0; i < widgetTable.length; i++) { - Widget widget = widgetTable [i]; - if (widget != null && widget instanceof Shell) { - int j = 0; - while (j < index) { - if (result [j] == widget) break; - j++; - } - if (j == index) { - if (index == result.length) { - Shell [] newResult = new Shell [index + 16]; - System.arraycopy (result, 0, newResult, 0, index); - result = newResult; - } - result [index++] = (Shell) widget; - } - } - } - if (index == result.length) return result; - Shell [] newResult = new Shell [index]; - System.arraycopy (result, 0, newResult, 0, index); - return newResult; -} - -/** - * 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 (); - GdkColor gdkColor = null; - switch (id) { - case SWT.COLOR_INFO_FOREGROUND: gdkColor = COLOR_INFO_FOREGROUND; break; - case SWT.COLOR_INFO_BACKGROUND: gdkColor = COLOR_INFO_BACKGROUND; break; - case SWT.COLOR_TITLE_FOREGROUND: gdkColor = COLOR_TITLE_FOREGROUND; break; - case SWT.COLOR_TITLE_BACKGROUND: gdkColor = COLOR_TITLE_BACKGROUND; break; - case SWT.COLOR_TITLE_BACKGROUND_GRADIENT: gdkColor = COLOR_TITLE_BACKGROUND_GRADIENT; break; - case SWT.COLOR_TITLE_INACTIVE_FOREGROUND: gdkColor = COLOR_TITLE_INACTIVE_FOREGROUND; break; - case SWT.COLOR_TITLE_INACTIVE_BACKGROUND: gdkColor = COLOR_TITLE_INACTIVE_BACKGROUND; break; - case SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT: gdkColor = COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT; break; - case SWT.COLOR_WIDGET_DARK_SHADOW: gdkColor = COLOR_WIDGET_DARK_SHADOW; break; - case SWT.COLOR_WIDGET_NORMAL_SHADOW: gdkColor = COLOR_WIDGET_NORMAL_SHADOW; break; - case SWT.COLOR_WIDGET_LIGHT_SHADOW: gdkColor = COLOR_WIDGET_LIGHT_SHADOW; break; - case SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: gdkColor = COLOR_WIDGET_HIGHLIGHT_SHADOW; break; - case SWT.COLOR_WIDGET_BACKGROUND: gdkColor = COLOR_WIDGET_BACKGROUND; break; - case SWT.COLOR_WIDGET_FOREGROUND: gdkColor = COLOR_WIDGET_FOREGROUND; break; - case SWT.COLOR_WIDGET_BORDER: gdkColor = COLOR_WIDGET_BORDER; break; - case SWT.COLOR_LIST_FOREGROUND: gdkColor = COLOR_LIST_FOREGROUND; break; - case SWT.COLOR_LIST_BACKGROUND: gdkColor = COLOR_LIST_BACKGROUND; break; - case SWT.COLOR_LIST_SELECTION: gdkColor = COLOR_LIST_SELECTION; break; - case SWT.COLOR_LIST_SELECTION_TEXT: gdkColor = COLOR_LIST_SELECTION_TEXT; break; - default: - return super.getSystemColor (id); - } - if (gdkColor == null) return super.getSystemColor (SWT.COLOR_BLACK); - return Color.gtk_new (this, gdkColor); -} - -/** - * 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 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 id) { - checkDevice (); - switch (id) { - case SWT.ICON_ERROR: - if (errorImage == null) { - errorImage = createImage ("gtk-dialog-error"); //$NON-NLS-1$ - } - return errorImage; - case SWT.ICON_INFORMATION: - case SWT.ICON_WORKING: - if (infoImage == null) { - infoImage = createImage ("gtk-dialog-info"); //$NON-NLS-1$ - } - return infoImage; - case SWT.ICON_QUESTION: - if (questionImage == null) { - questionImage = createImage ("gtk-dialog-question"); //$NON-NLS-1$ - } - return questionImage; - case SWT.ICON_WARNING: - if (warningImage == null) { - warningImage = createImage ("gtk-dialog-warning"); //$NON-NLS-1$ - } - return warningImage; - } - return null; -} - -void initializeSystemColors () { - GdkColor gdkColor; - - /* Get Tooltip resources */ - int /*long*/ tooltipShellHandle = OS.gtk_window_new (OS.GTK_WINDOW_POPUP); - if (tooltipShellHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - byte[] gtk_tooltips = Converter.wcsToMbcs (null, "gtk-tooltips", true); //$NON-NLS-1$ - OS.gtk_widget_set_name (tooltipShellHandle, gtk_tooltips); - OS.gtk_widget_realize (tooltipShellHandle); - int /*long*/ tooltipStyle = OS.gtk_widget_get_style (tooltipShellHandle); - gdkColor = new GdkColor(); - OS.gtk_style_get_fg (tooltipStyle, OS.GTK_STATE_NORMAL, gdkColor); - COLOR_INFO_FOREGROUND = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_bg (tooltipStyle, OS.GTK_STATE_NORMAL, gdkColor); - COLOR_INFO_BACKGROUND = gdkColor; - OS.gtk_widget_destroy (tooltipShellHandle); - - /* Get Shell resources */ - int /*long*/ style = OS.gtk_widget_get_style (shellHandle); - gdkColor = new GdkColor(); - OS.gtk_style_get_black (style, gdkColor); - COLOR_WIDGET_DARK_SHADOW = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_dark (style, OS.GTK_STATE_NORMAL, gdkColor); - COLOR_WIDGET_NORMAL_SHADOW = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_bg (style, OS.GTK_STATE_NORMAL, gdkColor); - COLOR_WIDGET_LIGHT_SHADOW = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_light (style, OS.GTK_STATE_NORMAL, gdkColor); - COLOR_WIDGET_HIGHLIGHT_SHADOW = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_fg (style, OS.GTK_STATE_NORMAL, gdkColor); - COLOR_WIDGET_FOREGROUND = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_bg (style, OS.GTK_STATE_NORMAL, gdkColor); - COLOR_WIDGET_BACKGROUND = gdkColor; - //gdkColor = new GdkColor(); - //OS.gtk_style_get_text (style, OS.GTK_STATE_NORMAL, gdkColor); - //COLOR_TEXT_FOREGROUND = gdkColor; - //gdkColor = new GdkColor(); - //OS.gtk_style_get_base (style, OS.GTK_STATE_NORMAL, gdkColor); - //COLOR_TEXT_BACKGROUND = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_text (style, OS.GTK_STATE_NORMAL, gdkColor); - COLOR_LIST_FOREGROUND = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_base (style, OS.GTK_STATE_NORMAL, gdkColor); - COLOR_LIST_BACKGROUND = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_text (style, OS.GTK_STATE_SELECTED, gdkColor); - COLOR_LIST_SELECTION_TEXT = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_base (style, OS.GTK_STATE_SELECTED, gdkColor); - COLOR_LIST_SELECTION = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_bg (style, OS.GTK_STATE_SELECTED, gdkColor); - COLOR_TITLE_BACKGROUND = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_fg (style, OS.GTK_STATE_SELECTED, gdkColor); - COLOR_TITLE_FOREGROUND = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_light (style, OS.GTK_STATE_SELECTED, gdkColor); - COLOR_TITLE_BACKGROUND_GRADIENT = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_bg (style, OS.GTK_STATE_INSENSITIVE, gdkColor); - COLOR_TITLE_INACTIVE_BACKGROUND = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_fg (style, OS.GTK_STATE_INSENSITIVE, gdkColor); - COLOR_TITLE_INACTIVE_FOREGROUND = gdkColor; - gdkColor = new GdkColor(); - OS.gtk_style_get_light (style, OS.GTK_STATE_INSENSITIVE, gdkColor); - COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT = gdkColor; -} - -/** - * 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 (); - if (systemFont != null) return systemFont; - int /*long*/ style = OS.gtk_widget_get_style (shellHandle); - int /*long*/ defaultFont = OS.pango_font_description_copy (OS.gtk_style_get_font_desc (style)); - return systemFont = Font.gtk_new (this, defaultFont); -} - -/** - * 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 (); - if (tray != null) return tray; - return tray = new Tray (this, SWT.NONE); -} - -/** - * 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 /*long*/ handle) { - if (handle == 0) return null; - if (lastWidget != null && lastHandle == handle) return lastWidget; - int /*long*/ index = OS.g_object_get_qdata (handle, SWT_OBJECT_INDEX) - 1; - if (0 <= index && index < widgetTable.length) { - lastHandle = handle; - return lastWidget = widgetTable [(int)/*64*/index]; - } - return null; -} - -int /*long*/ idleProc (int /*long*/ data) { - boolean result = runAsyncMessages (false); - if (!result) { - synchronized (idleLock) { - idleHandle = 0; - } - } - return result ? 1 : 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 (); - initializeCallbacks (); - initializeSubclasses (); - initializeSystemColors (); - initializeSystemSettings (); - initializeWidgetTable (); - initializeWindowManager (); -} - -void initializeCallbacks () { - closures = new int /*long*/ [Widget.LAST_SIGNAL]; - signalIds = new int [Widget.LAST_SIGNAL]; - - /* Cache signals for GtkWidget */ - signalIds [Widget.BUTTON_PRESS_EVENT] = OS.g_signal_lookup (OS.button_press_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.BUTTON_RELEASE_EVENT] = OS.g_signal_lookup (OS.button_release_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.CONFIGURE_EVENT] = OS.g_signal_lookup (OS.configure_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.DELETE_EVENT] = OS.g_signal_lookup (OS.delete_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.ENTER_NOTIFY_EVENT] = OS.g_signal_lookup (OS.enter_notify_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.EVENT] = OS.g_signal_lookup (OS.event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.EVENT_AFTER] = OS.g_signal_lookup (OS.event_after, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.EXPOSE_EVENT] = OS.g_signal_lookup (OS.expose_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.FOCUS] = OS.g_signal_lookup (OS.focus, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.FOCUS_IN_EVENT] = OS.g_signal_lookup (OS.focus_in_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.FOCUS_OUT_EVENT] = OS.g_signal_lookup (OS.focus_out_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.GRAB_FOCUS] = OS.g_signal_lookup (OS.grab_focus, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.HIDE] = OS.g_signal_lookup (OS.hide, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.KEY_PRESS_EVENT] = OS.g_signal_lookup (OS.key_press_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.KEY_RELEASE_EVENT] = OS.g_signal_lookup (OS.key_release_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.LEAVE_NOTIFY_EVENT] = OS.g_signal_lookup (OS.leave_notify_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.MAP] = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.MAP_EVENT] = OS.g_signal_lookup (OS.map_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.MNEMONIC_ACTIVATE] = OS.g_signal_lookup (OS.mnemonic_activate, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.MOTION_NOTIFY_EVENT] = OS.g_signal_lookup (OS.motion_notify_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.POPUP_MENU] = OS.g_signal_lookup (OS.popup_menu, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.REALIZE] = OS.g_signal_lookup (OS.realize, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.SCROLL_EVENT] = OS.g_signal_lookup (OS.scroll_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.SHOW] = OS.g_signal_lookup (OS.show, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.SHOW_HELP] = OS.g_signal_lookup (OS.show_help, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.SIZE_ALLOCATE] = OS.g_signal_lookup (OS.size_allocate, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.STYLE_SET] = OS.g_signal_lookup (OS.style_set, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.UNMAP] = OS.g_signal_lookup (OS.unmap, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.UNMAP_EVENT] = OS.g_signal_lookup (OS.unmap_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.UNREALIZE] = OS.g_signal_lookup (OS.realize, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.VISIBILITY_NOTIFY_EVENT] = OS.g_signal_lookup (OS.visibility_notify_event, OS.GTK_TYPE_WIDGET ()); - signalIds [Widget.WINDOW_STATE_EVENT] = OS.g_signal_lookup (OS.window_state_event, OS.GTK_TYPE_WIDGET ()); - - windowCallback2 = new Callback (this, "windowProc", 2); //$NON-NLS-1$ - windowProc2 = windowCallback2.getAddress (); - if (windowProc2 == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - - closures [Widget.ACTIVATE] = OS.g_cclosure_new (windowProc2, Widget.ACTIVATE, 0); - closures [Widget.ACTIVATE_INVERSE] = OS.g_cclosure_new (windowProc2, Widget.ACTIVATE_INVERSE, 0); - closures [Widget.CHANGED] = OS.g_cclosure_new (windowProc2, Widget.CHANGED, 0); - closures [Widget.CLICKED] = OS.g_cclosure_new (windowProc2, Widget.CLICKED, 0); - closures [Widget.DAY_SELECTED] = OS.g_cclosure_new (windowProc2, Widget.DAY_SELECTED, 0); - closures [Widget.DAY_SELECTED_DOUBLE_CLICK] = OS.g_cclosure_new (windowProc2, Widget.DAY_SELECTED_DOUBLE_CLICK, 0); - closures [Widget.HIDE] = OS.g_cclosure_new (windowProc2, Widget.HIDE, 0); - closures [Widget.GRAB_FOCUS] = OS.g_cclosure_new (windowProc2, Widget.GRAB_FOCUS, 0); - closures [Widget.MAP] = OS.g_cclosure_new (windowProc2, Widget.MAP, 0); - closures [Widget.MONTH_CHANGED] = OS.g_cclosure_new (windowProc2, Widget.MONTH_CHANGED, 0); - closures [Widget.OUTPUT] = OS.g_cclosure_new (windowProc2, Widget.OUTPUT, 0); - closures [Widget.POPUP_MENU] = OS.g_cclosure_new (windowProc2, Widget.POPUP_MENU, 0); - closures [Widget.PREEDIT_CHANGED] = OS.g_cclosure_new (windowProc2, Widget.PREEDIT_CHANGED, 0); - closures [Widget.REALIZE] = OS.g_cclosure_new (windowProc2, Widget.REALIZE, 0); - closures [Widget.SELECT] = OS.g_cclosure_new (windowProc2, Widget.SELECT, 0); - closures [Widget.SHOW] = OS.g_cclosure_new (windowProc2, Widget.SHOW, 0); - closures [Widget.VALUE_CHANGED] = OS.g_cclosure_new (windowProc2, Widget.VALUE_CHANGED, 0); - closures [Widget.UNMAP] = OS.g_cclosure_new (windowProc2, Widget.UNMAP, 0); - closures [Widget.UNREALIZE] = OS.g_cclosure_new (windowProc2, Widget.UNREALIZE, 0); - - windowCallback3 = new Callback (this, "windowProc", 3); //$NON-NLS-1$ - windowProc3 = windowCallback3.getAddress (); - if (windowProc3 == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - - closures [Widget.BUTTON_PRESS_EVENT] = OS.g_cclosure_new (windowProc3, Widget.BUTTON_PRESS_EVENT, 0); - closures [Widget.BUTTON_PRESS_EVENT_INVERSE] = OS.g_cclosure_new (windowProc3, Widget.BUTTON_PRESS_EVENT_INVERSE, 0); - closures [Widget.BUTTON_RELEASE_EVENT] = OS.g_cclosure_new (windowProc3, Widget.BUTTON_RELEASE_EVENT, 0); - closures [Widget.BUTTON_RELEASE_EVENT_INVERSE] = OS.g_cclosure_new (windowProc3, Widget.BUTTON_RELEASE_EVENT_INVERSE, 0); - closures [Widget.COMMIT] = OS.g_cclosure_new (windowProc3, Widget.COMMIT, 0); - closures [Widget.CONFIGURE_EVENT] = OS.g_cclosure_new (windowProc3, Widget.CONFIGURE_EVENT, 0); - closures [Widget.DELETE_EVENT] = OS.g_cclosure_new (windowProc3, Widget.DELETE_EVENT, 0); - closures [Widget.ENTER_NOTIFY_EVENT] = OS.g_cclosure_new (windowProc3, Widget.ENTER_NOTIFY_EVENT, 0); - closures [Widget.EVENT] = OS.g_cclosure_new (windowProc3, Widget.EVENT, 0); - closures [Widget.EVENT_AFTER] = OS.g_cclosure_new (windowProc3, Widget.EVENT_AFTER, 0); - closures [Widget.EXPOSE_EVENT] = OS.g_cclosure_new (windowProc3, Widget.EXPOSE_EVENT, 0); - closures [Widget.EXPOSE_EVENT_INVERSE] = OS.g_cclosure_new (windowProc3, Widget.EXPOSE_EVENT_INVERSE, 0); - closures [Widget.FOCUS] = OS.g_cclosure_new (windowProc3, Widget.FOCUS, 0); - closures [Widget.FOCUS_IN_EVENT] = OS.g_cclosure_new (windowProc3, Widget.FOCUS_IN_EVENT, 0); - closures [Widget.FOCUS_OUT_EVENT] = OS.g_cclosure_new (windowProc3, Widget.FOCUS_OUT_EVENT, 0); - closures [Widget.KEY_PRESS_EVENT] = OS.g_cclosure_new (windowProc3, Widget.KEY_PRESS_EVENT, 0); - closures [Widget.KEY_RELEASE_EVENT] = OS.g_cclosure_new (windowProc3, Widget.KEY_RELEASE_EVENT, 0); - closures [Widget.INPUT] = OS.g_cclosure_new (windowProc3, Widget.INPUT, 0); - closures [Widget.LEAVE_NOTIFY_EVENT] = OS.g_cclosure_new (windowProc3, Widget.LEAVE_NOTIFY_EVENT, 0); - closures [Widget.MAP_EVENT] = OS.g_cclosure_new (windowProc3, Widget.MAP_EVENT, 0); - closures [Widget.MNEMONIC_ACTIVATE] = OS.g_cclosure_new (windowProc3, Widget.MNEMONIC_ACTIVATE, 0); - closures [Widget.MOTION_NOTIFY_EVENT] = OS.g_cclosure_new (windowProc3, Widget.MOTION_NOTIFY_EVENT, 0); - closures [Widget.MOTION_NOTIFY_EVENT_INVERSE] = OS.g_cclosure_new (windowProc3, Widget.MOTION_NOTIFY_EVENT_INVERSE, 0); - closures [Widget.MOVE_FOCUS] = OS.g_cclosure_new (windowProc3, Widget.MOVE_FOCUS, 0); - closures [Widget.POPULATE_POPUP] = OS.g_cclosure_new (windowProc3, Widget.POPULATE_POPUP, 0); - closures [Widget.SCROLL_EVENT] = OS.g_cclosure_new (windowProc3, Widget.SCROLL_EVENT, 0); - closures [Widget.SHOW_HELP] = OS.g_cclosure_new (windowProc3, Widget.SHOW_HELP, 0); - closures [Widget.SIZE_ALLOCATE] = OS.g_cclosure_new (windowProc3, Widget.SIZE_ALLOCATE, 0); - closures [Widget.STYLE_SET] = OS.g_cclosure_new (windowProc3, Widget.STYLE_SET, 0); - closures [Widget.TOGGLED] = OS.g_cclosure_new (windowProc3, Widget.TOGGLED, 0); - closures [Widget.UNMAP_EVENT] = OS.g_cclosure_new (windowProc3, Widget.UNMAP_EVENT, 0); - closures [Widget.VISIBILITY_NOTIFY_EVENT] = OS.g_cclosure_new (windowProc3, Widget.VISIBILITY_NOTIFY_EVENT, 0); - closures [Widget.WINDOW_STATE_EVENT] = OS.g_cclosure_new (windowProc3, Widget.WINDOW_STATE_EVENT, 0); - closures [Widget.ROW_DELETED] = OS.g_cclosure_new (windowProc3, Widget.ROW_DELETED, 0); - - windowCallback4 = new Callback (this, "windowProc", 4); //$NON-NLS-1$ - windowProc4 = windowCallback4.getAddress (); - if (windowProc4 == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - - closures [Widget.DELETE_RANGE] = OS.g_cclosure_new (windowProc4, Widget.DELETE_RANGE, 0); - closures [Widget.DELETE_TEXT] = OS.g_cclosure_new (windowProc4, Widget.DELETE_TEXT, 0); - closures [Widget.ROW_ACTIVATED] = OS.g_cclosure_new (windowProc4, Widget.ROW_ACTIVATED, 0); - closures [Widget.SCROLL_CHILD] = OS.g_cclosure_new (windowProc4, Widget.SCROLL_CHILD, 0); - closures [Widget.STATUS_ICON_POPUP_MENU] = OS.g_cclosure_new (windowProc4, Widget.STATUS_ICON_POPUP_MENU, 0); - closures [Widget.SWITCH_PAGE] = OS.g_cclosure_new (windowProc4, Widget.SWITCH_PAGE, 0); - closures [Widget.TEST_COLLAPSE_ROW] = OS.g_cclosure_new (windowProc4, Widget.TEST_COLLAPSE_ROW, 0); - closures [Widget.TEST_EXPAND_ROW] = OS.g_cclosure_new (windowProc4, Widget.TEST_EXPAND_ROW, 0); - closures [Widget.ROW_INSERTED] = OS.g_cclosure_new (windowProc4, Widget.ROW_INSERTED, 0); - - windowCallback5 = new Callback (this, "windowProc", 5); //$NON-NLS-1$ - windowProc5 = windowCallback5.getAddress (); - if (windowProc5 == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - - closures [Widget.CHANGE_VALUE] = OS.g_cclosure_new (windowProc5, Widget.CHANGE_VALUE, 0); - closures [Widget.EXPAND_COLLAPSE_CURSOR_ROW] = OS.g_cclosure_new (windowProc5, Widget.EXPAND_COLLAPSE_CURSOR_ROW, 0); - closures [Widget.INSERT_TEXT] = OS.g_cclosure_new (windowProc5, Widget.INSERT_TEXT, 0); - closures [Widget.TEXT_BUFFER_INSERT_TEXT] = OS.g_cclosure_new (windowProc5, Widget.TEXT_BUFFER_INSERT_TEXT, 0); - - for (int i = 0; i < Widget.LAST_SIGNAL; i++) { - if (closures [i] != 0) OS.g_closure_ref (closures [i]); - } - - timerCallback = new Callback (this, "timerProc", 1); //$NON-NLS-1$ - timerProc = timerCallback.getAddress (); - if (timerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - windowTimerCallback = new Callback (this, "windowTimerProc", 1); //$NON-NLS-1$ - windowTimerProc = windowTimerCallback.getAddress (); - if (windowTimerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - mouseHoverCallback = new Callback (this, "mouseHoverProc", 1); //$NON-NLS-1$ - mouseHoverProc = mouseHoverCallback.getAddress (); - if (mouseHoverProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - caretCallback = new Callback(this, "caretProc", 1); //$NON-NLS-1$ - caretProc = caretCallback.getAddress(); - if (caretProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - menuPositionCallback = new Callback(this, "menuPositionProc", 5); //$NON-NLS-1$ - menuPositionProc = menuPositionCallback.getAddress(); - if (menuPositionProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - sizeAllocateCallback = new Callback(this, "sizeAllocateProc", 3); //$NON-NLS-1$ - sizeAllocateProc = sizeAllocateCallback.getAddress(); - if (sizeAllocateProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - sizeRequestCallback = new Callback(this, "sizeRequestProc", 3); //$NON-NLS-1$ - sizeRequestProc = sizeRequestCallback.getAddress(); - if (sizeRequestProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - shellMapCallback = new Callback(this, "shellMapProc", 3); //$NON-NLS-1$ - shellMapProc = shellMapCallback.getAddress(); - if (shellMapProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - shellMapProcClosure = OS.g_cclosure_new (shellMapProc, 0, 0); - OS.g_closure_ref (shellMapProcClosure); - - treeSelectionCallback = new Callback(this, "treeSelectionProc", 4); //$NON-NLS-1$ - treeSelectionProc = treeSelectionCallback.getAddress(); - if (treeSelectionProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - cellDataCallback = new Callback (this, "cellDataProc", 5); //$NON-NLS-1$ - cellDataProc = cellDataCallback.getAddress (); - if (cellDataProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - setDirectionCallback = new Callback (this, "setDirectionProc", 2); //$NON-NLS-1$ - setDirectionProc = setDirectionCallback.getAddress (); - if (setDirectionProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - emissionProcCallback = new Callback (this, "emissionProc", 4); //$NON-NLS-1$ - emissionProc = emissionProcCallback.getAddress (); - if (emissionProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - allChildrenCallback = new Callback (this, "allChildrenProc", 2); //$NON-NLS-1$ - allChildrenProc = allChildrenCallback.getAddress (); - if (allChildrenProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - checkIfEventCallback = new Callback (this, "checkIfEventProc", 3); //$NON-NLS-1$ - checkIfEventProc = checkIfEventCallback.getAddress (); - if (checkIfEventProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - idleCallback = new Callback (this, "idleProc", 1); //$NON-NLS-1$ - idleProc = idleCallback.getAddress (); - if (idleProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); -} - -void initializeSubclasses () { - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - pangoLayoutNewCallback = new Callback (this, "pangoLayoutNewProc", 3); //$NON-NLS-1$ - pangoLayoutNewProc = pangoLayoutNewCallback.getAddress (); - if (pangoLayoutNewProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - int /*long*/ pangoLayoutType = OS.PANGO_TYPE_LAYOUT (); - int /*long*/ pangoLayoutClass = OS.g_type_class_ref (pangoLayoutType); - pangoLayoutNewDefaultProc = OS.G_OBJECT_CLASS_CONSTRUCTOR (pangoLayoutClass); - OS.G_OBJECT_CLASS_SET_CONSTRUCTOR (pangoLayoutClass, pangoLayoutNewProc); - OS.g_type_class_unref (pangoLayoutClass); - } -} - -void initializeSystemSettings () { - styleSetCallback = new Callback (this, "styleSetProc", 3); //$NON-NLS-1$ - styleSetProc = styleSetCallback.getAddress (); - if (styleSetProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - OS.g_signal_connect (shellHandle, OS.style_set, styleSetProc, 0); - - /* - * Feature in GTK. Despite the fact that the - * gtk-entry-select-on-focus property is a global - * setting, it is initialized when the GtkEntry - * is initialized. This means that it cannot be - * accessed before a GtkEntry is created. The - * fix is to for the initializaion by creating - * a temporary GtkEntry. - */ - int /*long*/ entry = OS.gtk_entry_new (); - OS.gtk_widget_destroy (entry); - int [] buffer2 = new int [1]; - int /*long*/ settings = OS.gtk_settings_get_default (); - OS.g_object_get (settings, OS.gtk_entry_select_on_focus, buffer2, 0); - entrySelectOnFocus = buffer2 [0] != 0; -} - -void initializeWidgetTable () { - indexTable = new int [GROW_SIZE]; - widgetTable = new Widget [GROW_SIZE]; - for (int i=0; i<GROW_SIZE-1; i++) indexTable [i] = i + 1; - indexTable [GROW_SIZE - 1] = -1; -} - -void initializeWindowManager () { - /* Get the window manager name */ - windowManager = ""; //$NON-NLS-1$ - if (OS.GTK_VERSION >= OS.VERSION (2, 2, 0)) { - int /*long*/ screen = OS.gdk_screen_get_default (); - if (screen != 0) { - int /*long*/ ptr2 = OS.gdk_x11_screen_get_window_manager_name (screen); - if (ptr2 != 0) { - int length = OS.strlen (ptr2); - if (length > 0) { - byte [] buffer2 = new byte [length]; - OS.memmove (buffer2, ptr2, length); - windowManager = new String (Converter.mbcsToWcs (null, buffer2)); - } - } - } - } -} - -/** - * 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 /*long*/ gdkGC, GCData data) { - OS.g_object_unref (gdkGC); -} - -/** - * 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 /*long*/ internal_new_GC (GCData data) { - if (isDisposed()) SWT.error(SWT.ERROR_DEVICE_DISPOSED); - int /*long*/ root = OS.GDK_ROOT_PARENT (); - int /*long*/ gdkGC = OS.gdk_gc_new (root); - if (gdkGC == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gdk_gc_set_subwindow (gdkGC, OS.GDK_INCLUDE_INFERIORS); - 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.drawable = root; - data.background = getSystemColor (SWT.COLOR_WHITE).handle; - data.foreground = getSystemColor (SWT.COLOR_BLACK).handle; - data.font = getSystemFont (); - } - return gdkGC; -} - -boolean isValidThread () { - return thread == Thread.currentThread (); -} - -/** - * 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) { - int /*long*/ window = from.eventWindow (); - int [] origin_x = new int [1], origin_y = new int [1]; - OS.gdk_window_get_origin (window, origin_x, origin_y); - if ((from.style & SWT.MIRRORED) != 0) point.x = from.getClientWidth () - point.x; - point.x += origin_x [0]; - point.y += origin_y [0]; - } - if (to != null) { - int /*long*/ window = to.eventWindow (); - int [] origin_x = new int [1], origin_y = new int [1]; - OS.gdk_window_get_origin (window, origin_x, origin_y); - point.x -= origin_x [0]; - point.y -= origin_y [0]; - if ((to.style & SWT.MIRRORED) != 0) point.x = to.getClientWidth () - point.x; - } - 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); -} - -static char mbcsToWcs (char ch) { - int key = ch & 0xFFFF; - if (key <= 0x7F) return ch; - byte [] buffer; - if (key <= 0xFF) { - buffer = new byte [1]; - buffer [0] = (byte) key; - } else { - buffer = new byte [2]; - buffer [0] = (byte) ((key >> 8) & 0xFF); - buffer [1] = (byte) (key & 0xFF); - } - char [] result = Converter.mbcsToWcs (null, buffer); - if (result.length == 0) return 0; - return result [0]; -} - -int /*long*/ menuPositionProc (int /*long*/ menu, int /*long*/ x, int /*long*/ y, int /*long*/ push_in, int /*long*/ user_data) { - Widget widget = getWidget (menu); - if (widget == null) return 0; - return widget.menuPositionProc (menu, x, y, push_in, user_data); -} - -/** - * 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; - boolean fromRTL = false, toRTL = false; - if (from != null) { - int /*long*/ window = from.eventWindow (); - int [] origin_x = new int [1], origin_y = new int [1]; - OS.gdk_window_get_origin (window, origin_x, origin_y); - if (fromRTL = (from.style & SWT.MIRRORED) != 0) rect.x = from.getClientWidth() - rect.x; - rect.x += origin_x [0]; - rect.y += origin_y [0]; - } - if (to != null) { - int /*long*/ window = to.eventWindow (); - int [] origin_x = new int [1], origin_y = new int [1]; - OS.gdk_window_get_origin (window, origin_x, origin_y); - rect.x -= origin_x [0]; - rect.y -= origin_y [0]; - if (toRTL = (to.style & SWT.MIRRORED) != 0) rect.x = to.getClientWidth () - rect.x; - } - if (fromRTL != toRTL) rect.x -= rect.width; - return rect; -} - -int /*long*/ mouseHoverProc (int /*long*/ handle) { - Widget widget = getWidget (handle); - if (widget == null) return 0; - return widget.hoverProc (handle); -} - -int /*long*/ pangoLayoutNewProc (int /*long*/ type, int /*long*/ n_construct_properties, int /*long*/ construct_properties) { - int /*long*/ layout = OS.Call (pangoLayoutNewDefaultProc, type, (int)/*64*/n_construct_properties, construct_properties); - OS.pango_layout_set_auto_dir (layout, false); - return layout; -} - -/** - * 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); - if (!OS.GDK_WINDOWING_X11()) return false; - int /*long*/ xDisplay = OS.GDK_DISPLAY (); - int type = event.type; - switch (type) { - case SWT.KeyDown: - case SWT.KeyUp: { - int keyCode = 0; - int /*long*/ 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.GDK_BackSpace; break; - case SWT.CR: keysym = OS.GDK_Return; break; - case SWT.DEL: keysym = OS.GDK_Delete; break; - case SWT.ESC: keysym = OS.GDK_Escape; break; - case SWT.TAB: keysym = OS.GDK_Tab; break; - case SWT.LF: keysym = OS.GDK_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); - } else { - int button = event.button; - switch (button) { - case 1: - case 2: - case 3: break; - case 4: button = 6; break; - case 5: button = 7; break; - default: return false; - } - OS.XTestFakeButtonEvent (xDisplay, button, type == SWT.MouseDown, 0); - } - return true; - } - /* - * This code is intentionally commented. After posting a - * mouse wheel event the system may respond unpredictably - * to subsequent mouse actions. - */ -// case SWT.MouseWheel: { -// if (event.count == 0) return false; -// int button = event.count < 0 ? 5 : 4; -// OS.XTestFakeButtonEvent (xDisplay, button, type == SWT.MouseWheel, 0); -// } - } - 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; -} - -void putGdkEvents () { - if (gdkEventCount != 0) { - for (int i = 0; i < gdkEventCount; i++) { - int /*long*/ event = gdkEvents [i]; - Widget widget = gdkEventWidgets [i]; - if (widget == null || !widget.isDisposed ()) { - OS.gdk_event_put (event); - } - OS.gdk_event_free (event); - gdkEvents [i] = 0; - gdkEventWidgets [i] = null; - } - gdkEventCount = 0; - } -} - -/** - * 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 = false; - events |= runSettings (); - events |= runPopups (); - events |= OS.g_main_context_iteration (0, false); - 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 () { - windowCallback2.dispose (); windowCallback2 = null; - windowCallback3.dispose (); windowCallback3 = null; - windowCallback4.dispose (); windowCallback4 = null; - windowCallback5.dispose (); windowCallback5 = null; - windowProc2 = windowProc3 = windowProc4 = windowProc5 = 0; - - /* Dispose xfilter callback */ - if (filterProc != 0) { - OS.gdk_window_remove_filter(0, filterProc, 0); - } - filterCallback.dispose(); filterCallback = null; - filterProc = 0; - - /* Dispose checkIfEvent callback */ - checkIfEventCallback.dispose(); checkIfEventCallback = null; - checkIfEventProc = 0; - - /* Dispose preedit window */ - if (preeditWindow != 0) OS.gtk_widget_destroy (preeditWindow); - imControl = null; - - /* Dispose the menu callback */ - menuPositionCallback.dispose (); menuPositionCallback = null; - menuPositionProc = 0; - - /* Dispose the tooltip map callback */ - sizeAllocateCallback.dispose (); sizeAllocateCallback = null; - sizeAllocateProc = 0; - sizeRequestCallback.dispose (); sizeRequestCallback = null; - sizeRequestProc = 0; - - /* Dispose the shell map callback */ - shellMapCallback.dispose (); shellMapCallback = null; - shellMapProc = 0; - - /* Dispose the run async messages callback */ - idleCallback.dispose (); idleCallback = null; - idleProc = 0; - if (idleHandle != 0) OS.g_source_remove (idleHandle); - idleHandle = 0; - - /* Dispose GtkTreeView callbacks */ - treeSelectionCallback.dispose (); treeSelectionCallback = null; - treeSelectionProc = 0; - cellDataCallback.dispose (); cellDataCallback = null; - cellDataProc = 0; - - /* Dispose the set direction callback */ - setDirectionCallback.dispose (); setDirectionCallback = null; - setDirectionProc = 0; - - /* Dispose the emission proc callback */ - emissionProcCallback.dispose (); emissionProcCallback = null; - emissionProc = 0; - - /* Dispose the set direction callback */ - allChildrenCallback.dispose (); allChildrenCallback = null; - allChildrenProc = 0; - - /* Dispose the caret callback */ - if (caretId != 0) OS.gtk_timeout_remove (caretId); - caretId = 0; - caretProc = 0; - caretCallback.dispose (); - caretCallback = null; - - /* Release closures */ - for (int i = 0; i < Widget.LAST_SIGNAL; i++) { - if (closures [i] != 0) OS.g_closure_unref (closures [i]); - } - if (shellMapProcClosure != 0) OS.g_closure_unref (shellMapProcClosure); - - /* Dispose the timer callback */ - if (timerIds != null) { - for (int i=0; i<timerIds.length; i++) { - if (timerIds [i] != 0) OS.gtk_timeout_remove (timerIds [i]); - } - } - timerIds = null; - timerList = null; - timerProc = 0; - timerCallback.dispose (); - timerCallback = null; - windowTimerProc = 0; - windowTimerCallback.dispose (); - windowTimerCallback = null; - - /* Dispose mouse hover callback */ - if (mouseHoverId != 0) OS.gtk_timeout_remove (mouseHoverId); - mouseHoverId = 0; - mouseHoverHandle = mouseHoverProc = 0; - mouseHoverCallback.dispose (); - mouseHoverCallback = null; - - /* Dispose the default font */ - if (systemFont != null) systemFont.dispose (); - systemFont = null; - - /* Dispose the System Images */ - if (errorImage != null) errorImage.dispose(); - if (infoImage != null) infoImage.dispose(); - if (questionImage != null) questionImage.dispose(); - if (warningImage != null) warningImage.dispose(); - errorImage = infoImage = questionImage = warningImage = null; - - /* Release the System Cursors */ - for (int i = 0; i < cursors.length; i++) { - if (cursors [i] != null) cursors [i].dispose (); - } - cursors = null; - - /* Release Acquired Resources */ - if (resources != null) { - for (int i=0; i<resources.length; i++) { - if (resources [i] != null) resources [i].dispose (); - } - resources = null; - } - - /* Release the System Colors */ - COLOR_WIDGET_DARK_SHADOW = COLOR_WIDGET_NORMAL_SHADOW = COLOR_WIDGET_LIGHT_SHADOW = - COLOR_WIDGET_HIGHLIGHT_SHADOW = COLOR_WIDGET_BACKGROUND = COLOR_WIDGET_BORDER = - COLOR_LIST_FOREGROUND = COLOR_LIST_BACKGROUND = COLOR_LIST_SELECTION = COLOR_LIST_SELECTION_TEXT = - COLOR_WIDGET_FOREGROUND = COLOR_TITLE_FOREGROUND = COLOR_TITLE_BACKGROUND = COLOR_TITLE_BACKGROUND_GRADIENT = - COLOR_TITLE_INACTIVE_FOREGROUND = COLOR_TITLE_INACTIVE_BACKGROUND = COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT = - COLOR_INFO_BACKGROUND = COLOR_INFO_FOREGROUND = null; - - /* Dispose the event callback */ - OS.gdk_event_handler_set (0, 0, 0); - eventCallback.dispose (); eventCallback = null; - - /* Dispose the hidden shell */ - if (shellHandle != 0) OS.gtk_widget_destroy (shellHandle); - shellHandle = 0; - - /* Dispose the settings callback */ - styleSetCallback.dispose(); styleSetCallback = null; - styleSetProc = 0; - - /* Dispose subclass */ - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - int /*long*/ pangoLayoutType = OS.PANGO_TYPE_LAYOUT (); - int /*long*/ pangoLayoutClass = OS.g_type_class_ref (pangoLayoutType); - OS.G_OBJECT_CLASS_SET_CONSTRUCTOR (pangoLayoutClass, pangoLayoutNewDefaultProc); - OS.g_type_class_unref (pangoLayoutClass); - pangoLayoutNewCallback.dispose (); - pangoLayoutNewCallback = null; - pangoLayoutNewDefaultProc = pangoLayoutNewProc = 0; - } - - /* Release the sleep resources */ - max_priority = timeout = null; - if (fds != 0) OS.g_free (fds); - fds = 0; - - /* Release references */ - popups = null; - thread = null; - lastWidget = activeShell = null; - flushData = closures = null; - indexTable = signalIds = treeSelection = null; - widgetTable = modalShells = null; - data = null; - values = keys = null; - windowManager = null; - eventTable = filterTable = null; - modalDialog = null; - flushRect = null; - exposeEvent = null; - visibilityEvent = null; - idleLock = null; -} - -/** - * 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; -} - -int /*long*/ removeGdkEvent () { - if (gdkEventCount == 0) return 0; - int /*long*/ event = gdkEvents [0]; - --gdkEventCount; - System.arraycopy (gdkEvents, 1, gdkEvents, 0, gdkEventCount); - System.arraycopy (gdkEventWidgets, 1, gdkEventWidgets, 0, gdkEventCount); - gdkEvents [gdkEventCount] = 0; - gdkEventWidgets [gdkEventCount] = null; - if (gdkEventCount == 0) { - gdkEvents = null; - gdkEventWidgets = null; - } - return event; -} - -void removeIdleProc () { - synchronized (idleLock) { - if (idleHandle != 0) OS.g_source_remove (idleHandle); - idleNeeded = false; - idleHandle = 0; - } -} -/** - * 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); -} - -void removeMouseHoverTimeout (int /*long*/ handle) { - if (handle != mouseHoverHandle) return; - if (mouseHoverId != 0) OS.gtk_timeout_remove (mouseHoverId); - mouseHoverId = 0; - mouseHoverHandle = 0; -} - -void removePopup (Menu menu) { - if (popups == null) return; - for (int i=0; i<popups.length; i++) { - if (popups [i] == menu) { - popups [i] = null; - return; - } - } -} - -Widget removeWidget (int /*long*/ handle) { - if (handle == 0) return null; - lastWidget = null; - Widget widget = null; - int index = (int)/*64*/ OS.g_object_get_qdata (handle, SWT_OBJECT_INDEX) - 1; - if (0 <= index && index < widgetTable.length) { - widget = widgetTable [index]; - widgetTable [index] = null; - indexTable [index] = freeSlot; - freeSlot = index; - OS.g_object_set_qdata (handle, SWT_OBJECT_INDEX, 0); - } - return widget; -} - -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 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; -} - -boolean runSettings () { - if (!runSettings) return false; - runSettings = false; - saveResources (); - initializeSystemColors (); - sendEvent (SWT.Settings, null); - Shell [] shells = getShells (); - for (int i=0; i<shells.length; i++) { - Shell shell = shells [i]; - if (!shell.isDisposed ()) { - shell.fixStyle (); - shell.redraw (true); - shell.layout (true, true); - } - } - return true; -} - -/** - * 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; -} - -/** - * 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 (); - if (OS.GDK_WINDOWING_X11 ()) { - int /*long*/ xDisplay = OS.GDK_DISPLAY (); - int /*long*/ 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); -} - -/** - * 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); - - if (key.equals (DISPATCH_EVENT_KEY)) { - if (value == null || value instanceof int []) { - dispatchEvents = (int []) value; - if (value == null) putGdkEvents (); - return; - } - } - if (key.equals (SET_MODAL_DIALOG)) { - setModalDialog ((Dialog) value); - return; - } - if (key.equals (ADD_WIDGET_KEY)) { - Object [] data = (Object []) value; - int /*long*/ handle = ((LONG) data [0]).value; - Widget widget = (Widget) data [1]; - if (widget != null) { - addWidget (handle, widget); - } else { - removeWidget (handle); - } - } - if (key.equals (ADD_IDLE_PROC_KEY)) { - addIdleProc (); - return; - } - if (key.equals (REMOVE_IDLE_PROC_KEY)) { - removeIdleProc (); - return; - } - - /* 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; -} - -int /*long*/ setDirectionProc (int /*long*/ widget, int /*long*/ direction) { - OS.gtk_widget_set_direction (widget, (int)/*64*/ direction); - if (OS.GTK_IS_MENU_ITEM (widget)) { - int /*long*/ submenu = OS.gtk_menu_item_get_submenu (widget); - if (submenu != 0) { - OS.gtk_widget_set_direction (submenu, (int)/*64*/ direction); - OS.gtk_container_forall (submenu, setDirectionProc, direction); - } - } - if (OS.GTK_IS_CONTAINER (widget)) { - OS.gtk_container_forall (widget, setDirectionProc, direction); - } - return 0; -} - -void setModalDialog (Dialog modalDailog) { - this.modalDialog = modalDailog; - Shell [] shells = getShells (); - for (int i=0; i<shells.length; i++) shells [i].updateModal (); -} - -void setModalShell (Shell shell) { - if (modalShells == null) modalShells = new Shell [4]; - int index = 0, length = modalShells.length; - while (index < length) { - if (modalShells [index] == shell) return; - if (modalShells [index] == null) break; - index++; - } - if (index == length) { - Shell [] newModalShells = new Shell [length + 4]; - System.arraycopy (modalShells, 0, newModalShells, 0, length); - modalShells = newModalShells; - } - modalShells [index] = shell; - Shell [] shells = getShells (); - for (int i=0; i<shells.length; i++) shells [i].updateModal (); -} - -/** - * 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 showIMWindow (Control control) { - imControl = control; - if (preeditWindow == 0) { - preeditWindow = OS.gtk_window_new (OS.GTK_WINDOW_POPUP); - if (preeditWindow == 0) error (SWT.ERROR_NO_HANDLES); - preeditLabel = OS.gtk_label_new (null); - if (preeditLabel == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (preeditWindow, preeditLabel); - OS.gtk_widget_show (preeditLabel); - } - int /*long*/ [] preeditString = new int /*long*/ [1]; - int /*long*/ [] pangoAttrs = new int /*long*/ [1]; - int /*long*/ imHandle = control.imHandle (); - OS.gtk_im_context_get_preedit_string (imHandle, preeditString, pangoAttrs, null); - if (preeditString [0] != 0 && OS.strlen (preeditString [0]) > 0) { - Control widget = control.findBackgroundControl (); - if (widget == null) widget = control; - OS.gtk_widget_modify_bg (preeditWindow, OS.GTK_STATE_NORMAL, widget.getBackgroundColor ()); - widget.setForegroundColor (preeditLabel, control.getForegroundColor()); - OS.gtk_widget_modify_font (preeditLabel, control.getFontDescription ()); - if (pangoAttrs [0] != 0) OS.gtk_label_set_attributes (preeditLabel, pangoAttrs[0]); - OS.gtk_label_set_text (preeditLabel, preeditString [0]); - Point point = control.toDisplay (control.getIMCaretPos ()); - OS.gtk_window_move (preeditWindow, point.x, point.y); - GtkRequisition requisition = new GtkRequisition (); - OS.gtk_widget_size_request (preeditLabel, requisition); - OS.gtk_window_resize (preeditWindow, requisition.width, requisition.height); - OS.gtk_widget_show (preeditWindow); - } else { - OS.gtk_widget_hide (preeditWindow); - } - if (preeditString [0] != 0) OS.g_free (preeditString [0]); - if (pangoAttrs [0] != 0) OS.pango_attr_list_unref (pangoAttrs [0]); -} - -/** - * 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 (gdkEventCount == 0) { - gdkEvents = null; - gdkEventWidgets = null; - } - if (settingsChanged) { - settingsChanged = false; - runSettings = true; - return false; - } - if (getMessageCount () != 0) return true; - if (fds == 0) { - allocated_nfds = 2; - fds = OS.g_malloc (OS.GPollFD_sizeof () * allocated_nfds); - } - max_priority [0] = timeout [0] = 0; - int /*long*/ context = OS.g_main_context_default (); - boolean result = false; - do { - if (OS.g_main_context_acquire (context)) { - result = OS.g_main_context_prepare (context, max_priority); - int nfds; - while ((nfds = OS.g_main_context_query (context, max_priority [0], timeout, fds, allocated_nfds)) > allocated_nfds) { - OS.g_free (fds); - allocated_nfds = nfds; - fds = OS.g_malloc (OS.GPollFD_sizeof() * allocated_nfds); - } - int /*long*/ poll = OS.g_main_context_get_poll_func (context); - if (poll != 0) { - if (nfds > 0 || timeout [0] != 0) { - /* - * Bug in GTK. For some reason, g_main_context_wakeup() may - * fail to wake up the UI thread from the polling function. - * The fix is to sleep for a maximum of 50 milliseconds. - */ - if (timeout [0] < 0) timeout [0] = 50; - - /* Exit the OS lock to allow other threads to enter GTK */ - Lock lock = OS.lock; - int count = lock.lock (); - for (int i = 0; i < count; i++) lock.unlock (); - try { - wake = false; - OS.Call (poll, fds, nfds, timeout [0]); - } finally { - for (int i = 0; i < count; i++) lock.lock (); - lock.unlock (); - } - } - } - OS.g_main_context_check (context, max_priority [0], fds, nfds); - OS.g_main_context_release (context); - } - } while (!result && getMessageCount () == 0 && !wake); - wake = false; - return true; -} - -/** - * 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.gtk_timeout_remove (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 timerId = OS.gtk_timeout_add (milliseconds, timerProc, index); - if (timerId != 0) { - timerIds [index] = timerId; - timerList [index] = runnable; - } -} - -int /*long*/ timerProc (int /*long*/ i) { - if (timerList == null) return 0; - int index = (int)/*64*/i; - if (0 <= index && index < timerList.length) { - Runnable runnable = timerList [index]; - timerList [index] = null; - timerIds [index] = 0; - if (runnable != null) runnable.run (); - } - return 0; -} - -int /*long*/ caretProc (int /*long*/ clientData) { - caretId = 0; - if (currentCaret == null) { - return 0; - } - if (currentCaret.blinkCaret()) { - int blinkRate = currentCaret.blinkRate; - if (blinkRate == 0) return 0; - caretId = OS.gtk_timeout_add (blinkRate, caretProc, 0); - } else { - currentCaret = null; - } - return 0; -} - -int /*long*/ sizeAllocateProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { - Widget widget = getWidget (user_data); - if (widget == null) return 0; - return widget.sizeAllocateProc (handle, arg0, user_data); -} - -int /*long*/ sizeRequestProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { - Widget widget = getWidget (user_data); - if (widget == null) return 0; - return widget.sizeRequestProc (handle, arg0, user_data); -} - -int /*long*/ treeSelectionProc (int /*long*/ model, int /*long*/ path, int /*long*/ iter, int /*long*/ data) { - Widget widget = getWidget (data); - if (widget == null) return 0; - return widget.treeSelectionProc (model, path, iter, treeSelection, treeSelectionLength++); -} - -void saveResources () { - int resourceCount = 0; - if (resources == null) { - resources = new Resource [RESOURCE_SIZE]; - } else { - resourceCount = resources.length; - Resource [] newResources = new Resource [resourceCount + RESOURCE_SIZE]; - System.arraycopy (resources, 0, newResources, 0, resourceCount); - resources = newResources; - } - if (systemFont != null) { - resources [resourceCount++] = systemFont; - systemFont = null; - } - if (errorImage != null) resources [resourceCount++] = errorImage; - if (infoImage != null) resources [resourceCount++] = infoImage; - if (questionImage != null) resources [resourceCount++] = questionImage; - if (warningImage != null) resources [resourceCount++] = warningImage; - errorImage = infoImage = questionImage = warningImage = null; - for (int i=0; i<cursors.length; i++) { - if (cursors [i] != null) resources [resourceCount++] = cursors [i]; - cursors [i] = null; - } - if (resourceCount < RESOURCE_SIZE) { - Resource [] newResources = new Resource [resourceCount]; - System.arraycopy (resources, 0, newResources, 0, resourceCount); - resources = newResources; - } -} - -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 setCurrentCaret (Caret caret) { - if (caretId != 0) OS.gtk_timeout_remove(caretId); - caretId = 0; - currentCaret = caret; - if (caret == null) return; - int blinkRate = currentCaret.blinkRate; - caretId = OS.gtk_timeout_add (blinkRate, caretProc, 0); -} - -int /*long*/ shellMapProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { - Widget widget = getWidget (handle); - if (widget == null) return 0; - return widget.shellMapProc (handle, arg0, user_data); -} - -int /*long*/ styleSetProc (int /*long*/ gobject, int /*long*/ arg1, int /*long*/ user_data) { - settingsChanged = true; - return 0; -} - -/** - * 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; - synchronized (idleLock) { - if (idleNeeded && idleHandle == 0) { - //NOTE: calling unlocked function in OS - idleHandle = OS._g_idle_add (idleProc, 0); - } - } - } - synchronizer.syncExec (runnable); -} - -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 (); - flushExposes (0, true); - OS.gdk_window_process_all_updates (); -} - -/** - * 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 () { - OS.g_main_context_wakeup (0); - wake = true; -} - -static char wcsToMbcs (char ch) { - int key = ch & 0xFFFF; - if (key <= 0x7F) return ch; - byte [] buffer = Converter.wcsToMbcs (null, 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 /*long*/ windowProc (int /*long*/ handle, int /*long*/ user_data) { - Widget widget = getWidget (handle); - if (widget == null) return 0; - return widget.windowProc (handle, user_data); -} - -int /*long*/ windowProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { - Widget widget = getWidget (handle); - if (widget == null) return 0; - return widget.windowProc (handle, arg0, user_data); -} - -int /*long*/ windowProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ user_data) { - Widget widget = getWidget (handle); - if (widget == null) return 0; - return widget.windowProc (handle, arg0, arg1, user_data); -} - -int /*long*/ windowProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2, int /*long*/ user_data) { - Widget widget = getWidget (handle); - if (widget == null) return 0; - return widget.windowProc (handle, arg0, arg1, arg2, user_data); -} - -int /*long*/ windowTimerProc (int /*long*/ handle) { - Widget widget = getWidget (handle); - if (widget == null) return 0; - return widget.timerProc (handle); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.java deleted file mode 100644 index b3584f8586..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandBar.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.*; -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class support the layout of selectable - * expand bar items. - * <p> - * The item children that may be added to instances of this class - * must be of type <code>ExpandItem</code>. - * </p><p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>V_SCROLL</dd> - * <dt><b>Events:</b></dt> - * <dd>Expand, Collapse</dd> - * </dl> - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see ExpandItem - * @see ExpandEvent - * @see ExpandListener - * @see ExpandAdapter - * @see <a href="http://www.eclipse.org/swt/snippets/#expandbar">ExpandBar 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.2 - * @noextend This class is not intended to be subclassed by clients. - */ -public class ExpandBar extends Composite { - ExpandItem [] items; - ExpandItem lastFocus; - int itemCount; - int spacing; - int yCurrentScroll; - -/** - * 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#V_SCROLL - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public ExpandBar (Composite parent, int style) { - super (parent, style); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when an item in the receiver is expanded or collapsed - * by sending it one of the messages defined in the <code>ExpandListener</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 ExpandListener - * @see #removeExpandListener - */ -public void addExpandListener (ExpandListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Expand, typedListener); - addListener (SWT.Collapse, typedListener); -} - -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; - if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; - Point size = computeNativeSize (handle, wHint, hHint, changed); - int border = OS.gtk_container_get_border_width (handle); - size.x += 2 * border; - size.y += 2 * border; - return size; - } else { - int height = 0, width = 0; - if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) { - if (itemCount > 0) { - height += spacing; - GC gc = new GC (this); - for (int i = 0; i < itemCount; i++) { - ExpandItem item = items [i]; - height += item.getHeaderHeight (); - if (item.expanded) height += item.height; - height += spacing; - width = Math.max (width, item.getPreferredWidth (gc)); - } - gc.dispose (); - } - } - if (width == 0) width = DEFAULT_WIDTH; - if (height == 0) height = DEFAULT_HEIGHT; - if (wHint != SWT.DEFAULT) width = wHint; - if (hHint != SWT.DEFAULT) height = hHint; - return new Point (width, height); - } -} - -void createHandle (int index) { - state |= HANDLE; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - handle = OS.gtk_vbox_new (false, 0); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - if ((style & SWT.V_SCROLL) != 0) { - scrolledHandle = OS.gtk_scrolled_window_new (0, 0); - if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_scrolled_window_set_policy (scrolledHandle, OS.GTK_POLICY_NEVER, OS.GTK_POLICY_AUTOMATIC); - OS.gtk_container_add (fixedHandle, scrolledHandle); - OS.gtk_scrolled_window_add_with_viewport (scrolledHandle, handle); - int /*long*/ viewport = OS.gtk_bin_get_child (scrolledHandle); - OS.gtk_viewport_set_shadow_type (viewport, OS.GTK_SHADOW_NONE); - } else { - OS.gtk_container_add (fixedHandle, handle); - } - OS.gtk_container_set_border_width (handle, 0); - } else { - int /*long*/ topHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (topHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (topHandle, true); - if ((style & SWT.V_SCROLL) != 0) { - fixedHandle = topHandle; - scrolledHandle = OS.gtk_scrolled_window_new (0, 0); - if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES); - handle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (handle, true); - OS.gtk_container_add (fixedHandle, scrolledHandle); - - /* - * Force the scrolledWindow to have a single child that is - * not scrolled automatically. Calling gtk_container_add() - * seems to add the child correctly but cause a warning. - */ - boolean warnings = display.getWarnings (); - display.setWarnings (false); - OS.gtk_container_add (scrolledHandle, handle); - display.setWarnings (warnings); - } else { - handle = topHandle; - } - OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS); - } -} - -void createItem (ExpandItem item, int style, int index) { - if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE); - if (itemCount == items.length) { - ExpandItem [] newItems = new ExpandItem [itemCount + 4]; - System.arraycopy (items, 0, newItems, 0, items.length); - items = newItems; - } - System.arraycopy (items, index, items, index + 1, itemCount - index); - items [index] = item; - itemCount++; - if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) { - if (lastFocus == null) lastFocus = item; - } - item.width = Math.max (0, getClientArea ().width - spacing * 2); - layoutItems (index, true); -} - -void createWidget (int index) { - super.createWidget (index); - items = new ExpandItem [4]; -} - -void destroyItem (ExpandItem item) { - int index = 0; - while (index < itemCount) { - if (items [index] == item) break; - index++; - } - if (index == itemCount) return; - if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) { - if (item == lastFocus) { - int focusIndex = index > 0 ? index - 1 : 1; - if (focusIndex < itemCount) { - lastFocus = items [focusIndex]; - lastFocus.redraw (); - } else { - lastFocus = null; - } - } - } - System.arraycopy (items, index + 1, items, index, --itemCount - index); - items [itemCount] = null; - item.redraw (); - layoutItems (index, true); -} - -int /*long*/ eventHandle () { - return OS.GTK_VERSION >= OS.VERSION (2, 4, 0) ? fixedHandle : handle; -} - -boolean forceFocus (int /*long*/ focusHandle) { - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (lastFocus != null && lastFocus.setFocus ()) return true; - for (int i = 0; i < itemCount; i++) { - ExpandItem item = items [i]; - if (item.setFocus ()) return true; - } - } - return super.forceFocus (focusHandle); -} - -boolean hasFocus () { - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - for (int i=0; i<itemCount; i++) { - ExpandItem item = items [i]; - if (item.hasFocus ()) return true; - } - } - return super.hasFocus(); -} - -void hookEvents () { - super.hookEvents (); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (scrolledHandle != 0) { - OS.g_signal_connect_closure (scrolledHandle, OS.size_allocate, display.closures [SIZE_ALLOCATE], true); - } - } -} - -int getBandHeight () { - if (font == null) return ExpandItem.CHEVRON_SIZE; - GC gc = new GC (this); - FontMetrics metrics = gc.getFontMetrics (); - gc.dispose (); - return Math.max (ExpandItem.CHEVRON_SIZE, metrics.getHeight ()); -} - -GdkColor getForegroundColor () { - if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) { - if ((state & FOREGROUND) == 0) { - return display.getSystemColor (SWT.COLOR_TITLE_FOREGROUND).handle; - } - } - return super.getForegroundColor (); -} - -/** - * 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 ExpandItem getItem (int index) { - checkWidget(); - if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE); - return items [index]; -} - -/** - * 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>ExpandItem</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 ExpandItem [] getItems () { - checkWidget (); - ExpandItem [] result = new ExpandItem [itemCount]; - System.arraycopy (items, 0, result, 0, itemCount); - return result; -} - -/** - * Returns the receiver's spacing. - * - * @return the spacing - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 getSpacing () { - checkWidget (); - return spacing; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, event, GdkEventButton.sizeof); - int x = (int)gdkEvent.x; - int y = (int)gdkEvent.y; - for (int i = 0; i < itemCount; i++) { - ExpandItem item = items[i]; - boolean hover = item.x <= x && x < (item.x + item.width) && item.y <= y && y < (item.y + getBandHeight ()); - if (hover && item != lastFocus) { - lastFocus.redraw (); - lastFocus = item; - lastFocus.redraw (); - forceFocus (); - break; - } - } - } - return super.gtk_button_press_event (widget, event); -} - -int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ event) { - if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) { - if (lastFocus != null) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, event, GdkEventButton.sizeof); - int x = (int)gdkEvent.x; - int y = (int)gdkEvent.y; - boolean hover = lastFocus.x <= x && x < (lastFocus.x + lastFocus.width) && lastFocus.y <= y && y < (lastFocus.y + getBandHeight ()); - if (hover) { - Event ev = new Event (); - ev.item = lastFocus; - notifyListeners (lastFocus.expanded ? SWT.Collapse : SWT.Expand, ev); - lastFocus.expanded = !lastFocus.expanded; - showItem (lastFocus); - } - } - } - return super.gtk_button_release_event (widget, event); -} - -int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ eventPtr) { - if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) { - GdkEventExpose gdkEvent = new GdkEventExpose (); - OS.memmove(gdkEvent, eventPtr, GdkEventExpose.sizeof); - GCData data = new GCData (); - data.damageRgn = gdkEvent.region; - GC gc = GC.gtk_new (this, data); - OS.gdk_gc_set_clip_region (gc.handle, gdkEvent.region); - boolean hasFocus = isFocusControl (); - for (int i = 0; i < itemCount; i++) { - ExpandItem item = items [i]; - item.drawItem (gc, hasFocus && item == lastFocus); - } - gc.dispose (); - } - return super.gtk_expose_event (widget, eventPtr); -} - -int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) { - if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) { - if (lastFocus != null) lastFocus.redraw (); - } - return super.gtk_focus_in_event(widget, event); -} - -int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) { - if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) { - if (lastFocus != null) lastFocus.redraw (); - } - return super.gtk_focus_out_event (widget, event); -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) { - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (!hasFocus ()) return 0; - int /*long*/ result = super.gtk_key_press_event (widget, event); - if (result != 0) return result; - int index = 0; - while (index < itemCount) { - if (items [index].hasFocus ()) break; - index++; - } - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, event, GdkEventKey.sizeof); - boolean next = false; - switch (gdkEvent.keyval) { - case OS.GDK_Up: - case OS.GDK_Left: next = false; break; - case OS.GDK_Down: - case OS.GDK_Right: next = true; break; - default: return result; - } - int start = index, offset = next ? 1 : -1; - while ((index = (index + offset + itemCount) % itemCount) != start) { - ExpandItem item = items [index]; - if (item.setFocus ()) return result; - } - return result; - } else { - if (lastFocus != null) { - GdkEventKey keyEvent = new GdkEventKey (); - OS.memmove (keyEvent, event, GdkEventKey.sizeof); - switch (keyEvent.keyval) { - case OS.GDK_Return: - case OS.GDK_space: - Event ev = new Event (); - ev.item = lastFocus; - sendEvent (lastFocus.expanded ? SWT.Collapse :SWT.Expand, ev); - lastFocus.expanded = !lastFocus.expanded; - showItem (lastFocus); - break; - case OS.GDK_Up: - case OS.GDK_KP_Up: { - int focusIndex = indexOf (lastFocus); - if (focusIndex > 0) { - lastFocus.redraw (); - lastFocus = items [focusIndex - 1]; - lastFocus.redraw (); - } - break; - } - case OS.GDK_Down: - case OS.GDK_KP_Down: { - int focusIndex = indexOf (lastFocus); - if (focusIndex < itemCount - 1) { - lastFocus.redraw (); - lastFocus = items [focusIndex + 1]; - lastFocus.redraw (); - } - break; - } - } - } - } - return super.gtk_key_press_event (widget, event); -} - -/** - * 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> - * <li>ERROR_INVALID_ARGUMENT - if the 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 (ExpandItem item) { - checkWidget(); - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - for (int i = 0; i < itemCount; i++) { - if (items [i] == item) return i; - } - return -1; -} - -void layoutItems (int index, boolean setScrollbar) { - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - for (int i = 0; i < itemCount; i++) { - ExpandItem item = items [i]; - if (item != null) item.resizeControl (yCurrentScroll); - } - } else { - if (index < itemCount) { - int y = spacing - yCurrentScroll; - for (int i = 0; i < index; i++) { - ExpandItem item = items [i]; - if (item.expanded) y += item.height; - y += item.getHeaderHeight() + spacing; - } - for (int i = index; i < itemCount; i++) { - ExpandItem item = items [i]; - item.setBounds (spacing, y, 0, 0, true, false); - if (item.expanded) y += item.height; - y += item.getHeaderHeight() + spacing; - } - } - if (setScrollbar) setScrollbar (); - } -} - -int /*long*/ gtk_size_allocate (int /*long*/ widget, int /*long*/ allocation) { - int /*long*/ result = super.gtk_size_allocate (widget, allocation); - layoutItems (0, false); - return result; -} - -int /*long*/ parentingHandle () { - return OS.GTK_VERSION >= OS.VERSION (2, 4, 0) ? fixedHandle : handle; -} - -void releaseChildren (boolean destroy) { - for (int i = 0; i < itemCount; i++) { - ExpandItem item = items [i]; - if (item != null && !item.isDisposed ()) { - item.release (false); - } - } - super.releaseChildren (destroy); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when items in the receiver are expanded or collapsed. - * - * @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 ExpandListener - * @see #addExpandListener - */ -public void removeExpandListener (ExpandListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Expand, listener); - eventTable.unhook (SWT.Collapse, listener); -} - -int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - int result = super.setBounds (x, y, width, height, move, resize); - if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) { - if (resize) { - if ((style & SWT.V_SCROLL) != 0) { - setScrollbar (); - } else { - for (int i = 0; i < itemCount; i++) { - ExpandItem item = items [i]; - int newWidth = Math.max (0, getClientArea ().width - spacing * 2); - if (item.width != newWidth) { - item.setBounds (0, 0, newWidth, item.height, false, true); - } - } - } - } - } - return result; -} - -void setFontDescription (int /*long*/ font) { - super.setFontDescription (font); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - for (int i = 0; i < itemCount; i++) { - items[i].setFontDescription (font); - } - layoutItems (0, true); - } -} - -void setForegroundColor (GdkColor color) { - super.setForegroundColor (color); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - for (int i = 0; i < itemCount; i++) { - items[i].setForegroundColor (color); - } - } -} - -void setScrollbar () { - if (itemCount == 0) return; - if ((style & SWT.V_SCROLL) == 0) return; - int height = getClientArea ().height; - ExpandItem item = items [itemCount - 1]; - int maxHeight = item.y + getBandHeight () + spacing; - if (item.expanded) maxHeight += item.height; - int /*long*/ adjustmentHandle = OS.gtk_scrolled_window_get_vadjustment (scrolledHandle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, adjustmentHandle); - yCurrentScroll = (int)adjustment.value; - - //claim bottom free space - if (yCurrentScroll > 0 && height > maxHeight) { - yCurrentScroll = Math.max (0, yCurrentScroll + maxHeight - height); - layoutItems (0, false); - } - maxHeight += yCurrentScroll; - adjustment.value = Math.min (yCurrentScroll, maxHeight); - adjustment.upper = maxHeight; - adjustment.page_size = height; - OS.memmove (adjustmentHandle, adjustment); - OS.gtk_adjustment_changed (adjustmentHandle); - int policy = maxHeight > height ? OS.GTK_POLICY_ALWAYS : OS.GTK_POLICY_NEVER; - OS.gtk_scrolled_window_set_policy (scrolledHandle, OS.GTK_POLICY_NEVER, policy); - int width = OS.GTK_WIDGET_WIDTH (fixedHandle) - spacing * 2; - if (policy == OS.GTK_POLICY_ALWAYS) { - int /*long*/ vHandle = OS.GTK_SCROLLED_WINDOW_VSCROLLBAR (scrolledHandle); - GtkRequisition requisition = new GtkRequisition (); - OS.gtk_widget_size_request (vHandle, requisition); - width -= requisition.width; - } - width = Math.max (0, width); - for (int i = 0; i < itemCount; i++) { - ExpandItem item2 = items[i]; - item2.setBounds (0, 0, width, item2.height, false, true); - } -} - -/** - * Sets the receiver's spacing. Spacing specifies the number of pixels allocated around - * each item. - * - * @param spacing the spacing around each 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 setSpacing (int spacing) { - checkWidget (); - if (spacing < 0) return; - if (spacing == this.spacing) return; - this.spacing = spacing; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.gtk_box_set_spacing (handle, spacing); - OS.gtk_container_set_border_width (handle, spacing); - } else { - if ((style & SWT.V_SCROLL) == 0) { - int width = Math.max (0, getClientArea ().width - spacing * 2); - for (int i = 0; i < itemCount; i++) { - ExpandItem item = items [i]; - if (item.width != width) item.setBounds (0, 0, width, item.height, false, true); - } - } - layoutItems (0, true); - redraw (); - } -} - -void showItem (ExpandItem item) { - Control control = item.control; - if (control != null && !control.isDisposed ()) { - control.setVisible (item.expanded); - } - item.redraw (); - int index = indexOf (item); - layoutItems (index + 1, true); -} - -void updateScrollBarValue (ScrollBar bar) { - yCurrentScroll = bar.getSelection(); - layoutItems (0, false); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java deleted file mode 100644 index e141b605cb..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ExpandItem.java +++ /dev/null @@ -1,631 +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.gtk.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class represent a selectable user interface object - * that represents a expandable item in a expand bar. - * <p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * </p><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see ExpandBar - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 3.2 - * @noextend This class is not intended to be subclassed by clients. - */ -public class ExpandItem extends Item { - ExpandBar parent; - Control control; - ImageList imageList; - int /*long*/ clientHandle, boxHandle, labelHandle, imageHandle; - boolean expanded; - int x, y, width, height; - int imageHeight, imageWidth; - static final int TEXT_INSET = 6; - static final int BORDER = 1; - static final int CHEVRON_SIZE = 24; - -/** - * 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 ExpandItem (ExpandBar parent, int style) { - super (parent, style); - this.parent = parent; - createWidget (parent.getItemCount ()); -} - -/** - * Constructs a new instance of this class given its parent, 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 Widget#checkSubclass - * @see Widget#getStyle - */ -public ExpandItem (ExpandBar parent, int style, int index) { - super (parent, style); - this.parent = parent; - createWidget (index); -} - -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} - -void createHandle (int index) { - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - state |= HANDLE; - handle = OS.gtk_expander_new (null); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - clientHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (clientHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (handle, clientHandle); - boxHandle = OS.gtk_hbox_new (false, 4); - if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES); - labelHandle = OS.gtk_label_new (null); - if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES); - imageHandle = OS.gtk_image_new (); - if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (boxHandle, imageHandle); - OS.gtk_container_add (boxHandle, labelHandle); - OS.gtk_expander_set_label_widget (handle, boxHandle); - OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS); - } -} - -void createWidget (int index) { - super.createWidget (index); - showWidget (index); - parent.createItem (this, style, index); -} - -void deregister() { - super.deregister(); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - display.removeWidget (clientHandle); - display.removeWidget (boxHandle); - display.removeWidget (labelHandle); - display.removeWidget (imageHandle); - } -} - -void destroyWidget () { - parent.destroyItem (this); - super.destroyWidget (); -} - -void drawChevron (GC gc, int x, int y) { - int [] polyline1, polyline2; - if (expanded) { - int px = x + 4 + 5; - int py = y + 4 + 7; - polyline1 = new int [] { - px,py, px+1,py, px+1,py-1, px+2,py-1, px+2,py-2, px+3,py-2, px+3,py-3, - px+3,py-2, px+4,py-2, px+4,py-1, px+5,py-1, px+5,py, px+6,py}; - py += 4; - polyline2 = new int [] { - px,py, px+1,py, px+1,py-1, px+2,py-1, px+2,py-2, px+3,py-2, px+3,py-3, - px+3,py-2, px+4,py-2, px+4,py-1, px+5,py-1, px+5,py, px+6,py}; - } else { - int px = x + 4 + 5; - int py = y + 4 + 4; - polyline1 = new int[] { - px,py, px+1,py, px+1,py+1, px+2,py+1, px+2,py+2, px+3,py+2, px+3,py+3, - px+3,py+2, px+4,py+2, px+4,py+1, px+5,py+1, px+5,py, px+6,py}; - py += 4; - polyline2 = new int [] { - px,py, px+1,py, px+1,py+1, px+2,py+1, px+2,py+2, px+3,py+2, px+3,py+3, - px+3,py+2, px+4,py+2, px+4,py+1, px+5,py+1, px+5,py, px+6,py}; - } - gc.setForeground (display.getSystemColor (SWT.COLOR_TITLE_FOREGROUND)); - gc.drawPolyline (polyline1); - gc.drawPolyline (polyline2); -} - -void drawItem (GC gc, boolean drawFocus) { - int headerHeight = parent.getBandHeight (); - Display display = getDisplay (); - gc.setForeground (display.getSystemColor (SWT.COLOR_TITLE_BACKGROUND)); - gc.setBackground (display.getSystemColor (SWT.COLOR_TITLE_BACKGROUND_GRADIENT)); - gc.fillGradientRectangle (x, y, width, headerHeight, true); - if (expanded) { - gc.setForeground (display.getSystemColor (SWT.COLOR_TITLE_BACKGROUND_GRADIENT)); - gc.drawLine (x, y + headerHeight, x, y + headerHeight + height - 1); - gc.drawLine (x, y + headerHeight + height - 1, x + width - 1, y + headerHeight + height - 1); - gc.drawLine (x + width - 1, y + headerHeight + height - 1, x + width - 1, y + headerHeight); - } - int drawX = x; - if (image != null) { - drawX += ExpandItem.TEXT_INSET; - if (imageHeight > headerHeight) { - gc.drawImage (image, drawX, y + headerHeight - imageHeight); - } else { - gc.drawImage (image, drawX, y + (headerHeight - imageHeight) / 2); - } - drawX += imageWidth; - } - if (text.length() > 0) { - drawX += ExpandItem.TEXT_INSET; - Point size = gc.stringExtent (text); - gc.setForeground (parent.getForeground ()); - gc.drawString (text, drawX, y + (headerHeight - size.y) / 2, true); - } - int chevronSize = ExpandItem.CHEVRON_SIZE; - drawChevron (gc, x + width - chevronSize, y + (headerHeight - chevronSize) / 2); - if (drawFocus) { - gc.drawFocus (x + 1, y + 1, width - 2, headerHeight - 2); - } -} - -/** - * Returns the control that is shown when the item is expanded. - * If no control has been set, return <code>null</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 <code>true</code> if the receiver is expanded, - * and false otherwise. - * - * @return the expanded 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 getExpanded () { - checkWidget (); - return expanded; -} - -/** - * Returns the height of the receiver's header - * - * @return the height of the header - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 getHeaderHeight () { - checkWidget (); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - return OS.GTK_WIDGET_HEIGHT (handle) - (expanded ? height : 0); - } - return Math.max (parent.getBandHeight (), imageHeight); -} - -/** - * Gets the height of the receiver. - * - * @return the 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 getHeight () { - checkWidget (); - return height; -} - -/** - * Returns the receiver's parent, which must be a <code>ExpandBar</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 ExpandBar getParent () { - checkWidget(); - return parent; -} - -int getPreferredWidth (GC gc) { - int width = ExpandItem.TEXT_INSET * 2 + ExpandItem.CHEVRON_SIZE; - if (image != null) { - width += ExpandItem.TEXT_INSET + imageWidth; - } - if (text.length() > 0) { - width += gc.stringExtent (text).x; - } - return width; -} - -int /*long*/ gtk_activate (int /*long*/ widget) { - Event event = new Event (); - event.item = this; - int type = OS.gtk_expander_get_expanded (handle) ? SWT.Collapse : SWT.Expand; - parent.sendEvent (type, event); - return 0; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - setFocus (); - return 0; -} - -int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) { - OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS); - parent.lastFocus = this; - return 0; -} - -int /*long*/ gtk_size_allocate (int /*long*/ widget, int /*long*/ allocation) { - parent.layoutItems (0, false); - return 0; -} - -int /*long*/ gtk_enter_notify_event (int /*long*/ widget, int /*long*/ event) { - parent.gtk_enter_notify_event(widget, event); - return 0; -} - -boolean hasFocus () { - return OS.GTK_WIDGET_HAS_FOCUS (handle); -} - -void hookEvents () { - super.hookEvents (); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.g_signal_connect_closure (handle, OS.activate, display.closures [ACTIVATE], false); - OS.g_signal_connect_closure (handle, OS.activate, display.closures [ACTIVATE_INVERSE], true); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [FOCUS_OUT_EVENT], 0, display.closures [FOCUS_OUT_EVENT], false); - OS.g_signal_connect_closure (clientHandle, OS.size_allocate, display.closures [SIZE_ALLOCATE], true); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false); - } -} - -void redraw () { - if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) { - int headerHeight = parent.getBandHeight (); - if (imageHeight > headerHeight) { - parent.redraw (x + ExpandItem.TEXT_INSET, y + headerHeight - imageHeight, imageWidth, imageHeight, false); - } - parent.redraw (x, y, width, headerHeight + height, false); - } -} - -void register () { - super.register (); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - display.addWidget (clientHandle, this); - display.addWidget (boxHandle, this); - display.addWidget (labelHandle, this); - display.addWidget (imageHandle, this); - } -} - -void releaseHandle () { - super.releaseHandle (); - clientHandle = boxHandle = labelHandle = imageHandle = 0; - parent = null; -} - -void releaseWidget () { - super.releaseWidget (); - if (imageList != null) imageList.dispose (); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (parent.lastFocus == this) parent.lastFocus = null; - } - imageList = null; - control = null; -} - -void resizeControl (int yScroll) { - if (control != null && !control.isDisposed ()) { - boolean visible = OS.gtk_expander_get_expanded (handle); - if (visible) { - int x = OS.GTK_WIDGET_X (clientHandle); - int y = OS.GTK_WIDGET_Y (clientHandle); - if (x != -1 && y != -1) { - int width = OS.GTK_WIDGET_WIDTH (clientHandle); - int height = OS.GTK_WIDGET_HEIGHT (clientHandle); - int [] property = new int [1]; - OS.gtk_widget_style_get (handle, OS.focus_line_width, property, 0); - y += property [0] * 2; - height -= property [0] * 2; - - /* - * Feature in GTK. When the ExpandBar is resize too small the control - * shows up on top of the vertical scrollbar. This happen because the - * GtkExpander does not set the size of child smaller than the request - * size of its parent and because the control is not parented in the - * hierarchy of the GtkScrolledWindow. - * The fix is calculate the width ourselves when the scrollbar is visible. - */ - ScrollBar vBar = parent.verticalBar; - if (vBar != null) { - if (OS.GTK_WIDGET_VISIBLE (vBar.handle)) { - width = OS.GTK_WIDGET_WIDTH (parent.scrolledHandle) - parent.vScrollBarWidth () - 2 * parent.spacing; - } - } - control.setBounds (x, y - yScroll, width, Math.max (0, height), true, true); - } - } - control.setVisible (visible); - } -} - -void setBounds (int x, int y, int width, int height, boolean move, boolean size) { - redraw (); - int headerHeight = parent.getBandHeight (); - if (move) { - if (imageHeight > headerHeight) { - y += (imageHeight - headerHeight); - } - this.x = x; - this.y = y; - redraw (); - } - if (size) { - this.width = width; - this.height = height; - redraw (); - } - if (control != null && !control.isDisposed ()) { - if (move) control.setLocation (x + BORDER, y + headerHeight); - if (size) control.setSize (Math.max (0, width - 2 * BORDER), Math.max (0, height - BORDER)); - } -} - -/** - * Sets the control that is shown when the item is expanded. - * - * @param control the new control (or null) - * - * @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 (this.control == control) return; - this.control = control; - if (control != null) { - control.setVisible (expanded); - if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) { - int headerHeight = parent.getBandHeight (); - control.setBounds (x + BORDER, y + headerHeight, Math.max (0, width - 2 * BORDER), Math.max (0, height - BORDER)); - } - } - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - parent.layoutItems (0, true); - } -} - -/** - * Sets the expanded state of the receiver. - * - * @param expanded the new expanded 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 setExpanded (boolean expanded) { - checkWidget (); - this.expanded = expanded; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.gtk_expander_set_expanded (handle, expanded); - parent.layoutItems (0, true); - } else { - parent.showItem (this); - } -} - -boolean setFocus () { - if (!OS.gtk_widget_get_child_visible (handle)) return false; - OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS); - OS.gtk_widget_grab_focus (handle); - boolean result = OS.gtk_widget_is_focus (handle); - if (!result) OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS); - return result; -} - -void setFontDescription (int /*long*/ font) { - OS.gtk_widget_modify_font (handle, font); - if (labelHandle != 0) OS.gtk_widget_modify_font (labelHandle, font); - if (imageHandle != 0) OS.gtk_widget_modify_font (imageHandle, font); -} - -void setForegroundColor (GdkColor color) { - setForegroundColor (handle, color); - if (labelHandle != 0) setForegroundColor (labelHandle, color); - if (imageHandle != 0) setForegroundColor (imageHandle, color); -} - -/** - * Sets the height of the receiver. This is height of the item when it is expanded, - * excluding the height of the header. - * - * @param height the new 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 void setHeight (int height) { - checkWidget (); - if (height < 0) return; - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - this.height = height; - OS.gtk_widget_set_size_request (clientHandle, -1, height); - parent.layoutItems (0, false); - } else { - setBounds (0, 0, width, height, false, true); - if (expanded) parent.layoutItems (parent.indexOf (this) + 1, true); - } -} - -public void setImage (Image image) { - super.setImage (image); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - if (imageList != null) imageList.dispose (); - imageList = null; - if (image != null) { - if (image.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - imageList = new ImageList (); - int imageIndex = imageList.add (image); - int /*long*/ pixbuf = imageList.getPixbuf (imageIndex); - OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); - if (text.length () == 0) OS.gtk_widget_hide (labelHandle); - OS.gtk_widget_show (imageHandle); - } else { - OS.gtk_image_set_from_pixbuf (imageHandle, 0); - OS.gtk_widget_show (labelHandle); - OS.gtk_widget_hide (imageHandle); - } - } else { - int oldImageHeight = imageHeight; - if (image != null) { - Rectangle bounds = image.getBounds (); - imageHeight = bounds.height; - imageWidth = bounds.width; - } else { - imageHeight = imageWidth = 0; - } - if (oldImageHeight != imageHeight) { - parent.layoutItems (parent.indexOf (this), true); - } else { - redraw (); - } - } -} - -void setOrientation() { - super.setOrientation (); - if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) { - OS.gtk_widget_set_direction (handle, OS.GTK_TEXT_DIR_RTL); - OS.gtk_container_forall (handle, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL); - } -} - -public void setText (String string) { - super.setText (string); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - byte [] buffer = Converter.wcsToMbcs (null, string, true); - OS.gtk_label_set_text (labelHandle, buffer); - } else { - redraw (); - } -} - -void showWidget (int index) { - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.gtk_widget_show (handle); - OS.gtk_widget_show (clientHandle); - OS.gtk_container_add (parent.handle, handle); - OS.gtk_box_set_child_packing (parent.handle, handle, false, false, 0, OS.GTK_PACK_START); - if (boxHandle != 0) OS.gtk_widget_show (boxHandle); - if (labelHandle != 0) OS.gtk_widget_show (labelHandle); - } -} - -int /*long*/ windowProc (int /*long*/ handle, int /*long*/ user_data) { - switch ((int)/*64*/user_data) { - case ACTIVATE_INVERSE: { - expanded = OS.gtk_expander_get_expanded (handle); - parent.layoutItems (0, false); - return 0; - } - } - return super.windowProc (handle, user_data); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java deleted file mode 100644 index 6cbca2156c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FileDialog.java +++ /dev/null @@ -1,731 +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.gtk.*; - -/** - * 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 { - String [] filterNames = new String [0]; - String [] filterExtensions = new String [0]; - String filterPath = ""; - String fileName = ""; - String[] fileNames = new String [0]; - String fullPath = ""; - int filterIndex = -1; - boolean overwrite = false; - boolean uriMode; - int /*long*/ handle; - static final char SEPARATOR = System.getProperty ("file.separator").charAt (0); - static final char EXTENSION_SEPARATOR = ';'; - -/** - * 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 (); -} -String computeResultChooserDialog () { - /* MULTI is only valid if the native dialog's action is Open */ - fullPath = null; - if ((style & (SWT.SAVE | SWT.MULTI)) == SWT.MULTI) { - int /*long*/ list = 0; - if (uriMode) { - list = OS.gtk_file_chooser_get_uris (handle); - } else { - list = OS.gtk_file_chooser_get_filenames (handle); - } - int listLength = OS.g_slist_length (list); - fileNames = new String [listLength]; - int /*long*/ current = list; - int writePos = 0; - for (int i = 0; i < listLength; i++) { - int /*long*/ name = OS.g_slist_data (current); - int /*long*/ utf8Ptr = 0; - if (uriMode) { - utf8Ptr = name; - } else { - utf8Ptr = OS.g_filename_to_utf8 (name, -1, null, null, null); - OS.g_free (name); - } - if (utf8Ptr != 0) { - int /*long*/ [] items_written = new int /*long*/ [1]; - int /*long*/ utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null); - OS.g_free (utf8Ptr); - if (utf16Ptr != 0) { - int clength = (int)/*64*/items_written [0]; - char [] chars = new char [clength]; - OS.memmove (chars, utf16Ptr, clength * 2); - OS.g_free (utf16Ptr); - fullPath = new String (chars); - fileNames [writePos++] = fullPath.substring (fullPath.lastIndexOf (SEPARATOR) + 1); - } - } - current = OS.g_slist_next (current); - } - if (writePos != 0 && writePos != listLength) { - String [] validFileNames = new String [writePos]; - System.arraycopy (fileNames, 0, validFileNames, 0, writePos); - fileNames = validFileNames; - } - OS.g_slist_free (list); - } else { - int /*long*/ utf8Ptr = 0; - if (uriMode) { - utf8Ptr = OS.gtk_file_chooser_get_uri (handle); - } else { - int /*long*/ path = OS.gtk_file_chooser_get_filename (handle); - if (path != 0) { - utf8Ptr = OS.g_filename_to_utf8 (path, -1, null, null, null); - OS.g_free (path); - } - } - if (utf8Ptr != 0) { - int /*long*/ [] items_written = new int /*long*/ [1]; - int /*long*/ utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null); - OS.g_free (utf8Ptr); - if (utf16Ptr != 0) { - int clength = (int)/*64*/items_written [0]; - char [] chars = new char [clength]; - OS.memmove (chars, utf16Ptr, clength * 2); - OS.g_free (utf16Ptr); - fullPath = new String (chars); - fileNames = new String [1]; - fileNames[0] = fullPath.substring (fullPath.lastIndexOf (SEPARATOR) + 1); - } - } - } - filterIndex = -1; - int /*long*/ filter = OS.gtk_file_chooser_get_filter (handle); - if (filter != 0) { - int /*long*/ filterNamePtr = OS.gtk_file_filter_get_name (filter); - if (filterNamePtr != 0) { - int length = OS.strlen (filterNamePtr); - byte[] buffer = new byte [length]; - OS.memmove (buffer, filterNamePtr, length); - //OS.g_free (filterNamePtr); //GTK owns this pointer - do not free - String filterName = new String (Converter.mbcsToWcs (null, buffer)); - for (int i = 0; i < filterExtensions.length; i++) { - if (filterNames.length > 0) { - if (filterNames[i].equals(filterName)) { - filterIndex = i; - break; - } - } else { - if (filterExtensions[i].equals(filterName)) { - filterIndex = i; - break; - } - } - } - } - } - if (fullPath != null) { - int separatorIndex = fullPath.lastIndexOf (SEPARATOR); - fileName = fullPath.substring (separatorIndex + 1); - filterPath = fullPath.substring (0, separatorIndex); - } - return fullPath; -} -String computeResultClassicDialog () { - filterIndex = -1; - GtkFileSelection selection = new GtkFileSelection (); - OS.memmove (selection, handle); - int /*long*/ entry = selection.selection_entry; - int /*long*/ entryText = OS.gtk_entry_get_text (entry); - int entryLength = OS.strlen (entryText); - if (entryLength == 0) { - int /*long*/ fileList = selection.file_list; - int /*long*/ listSelection = OS.gtk_tree_view_get_selection (fileList); - int /*long*/[] model = new int /*long*/[1]; - int /*long*/ selectedList = OS.gtk_tree_selection_get_selected_rows (listSelection, model); - if (selectedList == 0) return null; - int listLength = OS.g_list_length (selectedList); - if (listLength == 0) { - OS.g_list_free (selectedList); - return null; - } - int /*long*/ path = OS.g_list_nth_data (selectedList, 0); - int /*long*/ [] ptr = new int /*long*/[1]; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (OS.gtk_tree_model_get_iter (model [0], iter, path)) { - OS.gtk_tree_model_get (model [0], iter, 0, ptr, -1); - } - OS.g_free (iter); - for (int i = 0; i < listLength; i++) { - OS.gtk_tree_path_free (OS.g_list_nth_data (selectedList, i)); - } - OS.g_list_free (selectedList); - if (ptr [0] == 0) return null; - int length = OS.strlen (ptr [0]); - byte [] buffer = new byte [length]; - OS.memmove (buffer, ptr [0], length); - OS.g_free (ptr [0]); - OS.gtk_entry_set_text (entry, buffer); - } - - int /*long*/ fileNamePtr = OS.gtk_file_selection_get_filename (handle); - int /*long*/ utf8Ptr = OS.g_filename_to_utf8 (fileNamePtr, -1, null, null, null); - int /*long*/ [] items_written = new int /*long*/ [1]; - int /*long*/ utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null); - entryLength = (int)/*64*/items_written [0]; - char [] buffer = new char [entryLength]; - OS.memmove (buffer, utf16Ptr, entryLength * 2); - String osAnswer = new String (buffer); - OS.g_free (utf16Ptr); - OS.g_free (utf8Ptr); - - if (osAnswer == null) return null; - int separatorIndex = osAnswer.lastIndexOf (SEPARATOR); - if (separatorIndex+1 == osAnswer.length ()) return null; - - String answer = fullPath = osAnswer; - fileName = fullPath.substring (separatorIndex+1); - filterPath = fullPath.substring (0, separatorIndex); - if ((style & SWT.MULTI) == 0) { - fileNames = new String[] {fileName}; - } else { - int /*long*/ namesPtr = OS.gtk_file_selection_get_selections (handle); - int /*long*/ namesPtr1 = namesPtr; - int /*long*/ [] namePtr = new int /*long*/ [1]; - OS.memmove (namePtr, namesPtr1, OS.PTR_SIZEOF); - int length = 0; - while (namePtr[0] != 0) { - length++; - namesPtr1+=OS.PTR_SIZEOF; - OS.memmove(namePtr, namesPtr1, OS.PTR_SIZEOF); - } - fileNames = new String [length]; - namePtr = new int /*long*/ [length]; - OS.memmove (namePtr, namesPtr, length * OS.PTR_SIZEOF); - for (int i = 0; i < length; i++) { - utf8Ptr = OS.g_filename_to_utf8 (namePtr [i], -1, null, null, null); - items_written = new int /*long*/ [1]; - utf16Ptr = OS.g_utf8_to_utf16 (utf8Ptr, -1, null, items_written, null); - buffer = new char [(int)/*64*/items_written [0]]; - OS.memmove (buffer, utf16Ptr, items_written [0] * 2); - String name = new String (buffer); - fileNames [i] = name.substring (name.lastIndexOf (SEPARATOR) + 1); - OS.g_free (utf16Ptr); - OS.g_free (utf8Ptr); - } - OS.g_strfreev (namesPtr); - } - return answer; -} -/** - * 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; -} -/** - * 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 () { - boolean useChooserDialog = OS.GTK_VERSION >= OS.VERSION (2, 4, 10); - if (useChooserDialog) { - return openChooserDialog (); - } else { - return openClassicDialog (); - } -} -String openChooserDialog () { - byte [] titleBytes = Converter.wcsToMbcs (null, title, true); - int action = (style & SWT.SAVE) != 0 ? - OS.GTK_FILE_CHOOSER_ACTION_SAVE : - OS.GTK_FILE_CHOOSER_ACTION_OPEN; - int /*long*/ shellHandle = parent.topHandle (); - Display display = parent != null ? parent.getDisplay (): Display.getCurrent (); - if (display.getDismissalAlignment() == SWT.RIGHT) { - handle = OS.gtk_file_chooser_dialog_new (titleBytes, shellHandle, action, OS.GTK_STOCK_CANCEL (), OS.GTK_RESPONSE_CANCEL, OS.GTK_STOCK_OK (), OS.GTK_RESPONSE_OK, 0); - } else { - handle = OS.gtk_file_chooser_dialog_new (titleBytes, shellHandle, action, OS.GTK_STOCK_OK (), OS.GTK_RESPONSE_OK, OS.GTK_STOCK_CANCEL (), OS.GTK_RESPONSE_CANCEL, 0); - } - OS.gtk_window_set_modal (handle, true); - int /*long*/ pixbufs = OS.gtk_window_get_icon_list (shellHandle); - if (pixbufs != 0) { - OS.gtk_window_set_icon_list (handle, pixbufs); - OS.g_list_free (pixbufs); - } - if (uriMode) { - OS.gtk_file_chooser_set_local_only (handle, false); - } - presetChooserDialog (); - display.addIdleProc (); - String answer = null; - Dialog oldModal = null; - if (OS.gtk_window_get_modal (handle)) { - oldModal = display.getModalDialog (); - display.setModalDialog (this); - } - int signalId = 0; - int /*long*/ hookId = 0; - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - signalId = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET()); - hookId = OS.g_signal_add_emission_hook (signalId, 0, display.emissionProc, handle, 0); - } - int response = OS.gtk_dialog_run (handle); - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - OS.g_signal_remove_emission_hook (signalId, hookId); - } - if (OS.gtk_window_get_modal (handle)) { - display.setModalDialog (oldModal); - } - if (response == OS.GTK_RESPONSE_OK) { - answer = computeResultChooserDialog (); - } - display.removeIdleProc (); - OS.gtk_widget_destroy (handle); - return answer; -} -String openClassicDialog () { - byte [] titleBytes = Converter.wcsToMbcs (null, title, true); - handle = OS.gtk_file_selection_new (titleBytes); - if (parent != null) { - int /*long*/ shellHandle = parent.topHandle (); - OS.gtk_window_set_transient_for (handle, shellHandle); - int /*long*/ pixbufs = OS.gtk_window_get_icon_list (shellHandle); - if (pixbufs != 0) { - OS.gtk_window_set_icon_list (handle, pixbufs); - OS.g_list_free (pixbufs); - } - } - OS.gtk_window_set_modal (handle, true); - presetClassicDialog (); - Display display = parent != null ? parent.getDisplay (): Display.getCurrent (); - display.addIdleProc (); - String answer = null; - Dialog oldModal = null; - if (OS.gtk_window_get_modal (handle)) { - oldModal = display.getModalDialog (); - display.setModalDialog (this); - } - int signalId = 0; - int /*long*/ hookId = 0; - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - signalId = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET()); - hookId = OS.g_signal_add_emission_hook (signalId, 0, display.emissionProc, handle, 0); - } - int response = OS.gtk_dialog_run (handle); - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - OS.g_signal_remove_emission_hook (signalId, hookId); - } - if (OS.gtk_window_get_modal (handle)) { - display.setModalDialog (oldModal); - } - if (response == OS.GTK_RESPONSE_OK) { - answer = computeResultClassicDialog (); - } - display.removeIdleProc (); - OS.gtk_widget_destroy (handle); - return answer; -} -void presetChooserDialog () { - /* MULTI is only valid if the native dialog's action is Open */ - if ((style & (SWT.SAVE | SWT.MULTI)) == SWT.MULTI) { - OS.gtk_file_chooser_set_select_multiple (handle, true); - } - if (filterPath == null) filterPath = ""; - if (fileName == null) fileName = ""; - if ((style & SWT.SAVE) != 0) { - if (filterPath.length () > 0) { - if (uriMode) { - byte [] buffer = Converter.wcsToMbcs (null, filterPath, true); - OS.gtk_file_chooser_set_current_folder_uri (handle, buffer); - } else { - /* filename must be a full path */ - byte [] buffer = Converter.wcsToMbcs (null, SEPARATOR + filterPath, true); - - /* - * Bug in GTK. GtkFileChooser may crash on GTK versions 2.4.10 to 2.6 - * when setting a file name that is not a true canonical path. - * The fix is to use the canonical path. - */ - int /*long*/ ptr = OS.realpath (buffer, null); - OS.gtk_file_chooser_set_current_folder (handle, ptr); - OS.g_free (ptr); - } - } - if (fileName.length () > 0) { - byte [] buffer = Converter.wcsToMbcs (null, fileName, true); - OS.gtk_file_chooser_set_current_name (handle, buffer); - } - } else { - StringBuffer stringBuffer = new StringBuffer(); - if (filterPath.length () > 0) { - if (!uriMode) { - /* filename must be a full path */ - stringBuffer.append(SEPARATOR); - } - stringBuffer.append(filterPath); - stringBuffer.append(SEPARATOR); - } - if (fileName.length () > 0) { - stringBuffer.append(fileName); - } - byte [] buffer = Converter.wcsToMbcs (null, stringBuffer.toString(), true); - if (uriMode) { - OS.gtk_file_chooser_set_uri (handle, buffer); - } else { - /* - * Bug in GTK. GtkFileChooser may crash on GTK versions 2.4.10 to 2.6 - * when setting a file name that is not a true canonical path. - * The fix is to use the canonical path. - */ - int /*long*/ ptr = OS.realpath (buffer, null); - if (ptr != 0) { - OS.gtk_file_chooser_set_filename (handle, ptr); - OS.g_free (ptr); - } - } - } - - /* Set overwrite mode */ - if ((style & SWT.SAVE) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 8, 0)) { - OS.gtk_file_chooser_set_do_overwrite_confirmation (handle, overwrite); - } - } - - /* Set the extension filters */ - if (filterNames == null) filterNames = new String [0]; - if (filterExtensions == null) filterExtensions = new String [0]; - int /*long*/ initialFilter = 0; - for (int i = 0; i < filterExtensions.length; i++) { - if (filterExtensions [i] != null) { - int /*long*/ filter = OS.gtk_file_filter_new (); - if (filterNames.length > i && filterNames [i] != null) { - byte [] name = Converter.wcsToMbcs (null, filterNames [i], true); - OS.gtk_file_filter_set_name (filter, name); - } else { - byte [] name = Converter.wcsToMbcs (null, filterExtensions [i], true); - OS.gtk_file_filter_set_name (filter, name); - } - int start = 0; - int index = filterExtensions [i].indexOf (EXTENSION_SEPARATOR); - while (index != -1) { - String current = filterExtensions [i].substring (start, index); - byte [] filterString = Converter.wcsToMbcs (null, current, true); - OS.gtk_file_filter_add_pattern (filter, filterString); - start = index + 1; - index = filterExtensions [i].indexOf (EXTENSION_SEPARATOR, start); - } - String current = filterExtensions [i].substring (start); - byte [] filterString = Converter.wcsToMbcs (null, current, true); - OS.gtk_file_filter_add_pattern (filter, filterString); - OS.gtk_file_chooser_add_filter (handle, filter); - if (i == filterIndex) { - initialFilter = filter; - } - } - } - if (initialFilter != 0) { - OS.gtk_file_chooser_set_filter(handle, initialFilter); - } - fullPath = null; - fileNames = new String [0]; -} -void presetClassicDialog () { - OS.gtk_file_selection_set_select_multiple(handle, (style & SWT.MULTI) != 0); - - /* Calculate the fully-specified file name and convert to bytes */ - StringBuffer stringBuffer = new StringBuffer (); - if (filterPath == null) { - filterPath = ""; - } else { - if (filterPath.length () > 0) { - stringBuffer.append (filterPath); - if (filterPath.charAt (filterPath.length () - 1) != SEPARATOR) { - stringBuffer.append (SEPARATOR); - } - } - } - if (fileName == null) { - fileName = ""; - } else { - stringBuffer.append (fileName); - } - fullPath = stringBuffer.toString (); - int length = fullPath.length (); - char [] buffer = new char [length + 1]; - fullPath.getChars (0, length, buffer, 0); - int /*long*/ utf8Ptr = OS.g_utf16_to_utf8 (buffer, -1, null, null, null); - int /*long*/ fileNamePtr = OS.g_filename_from_utf8 (utf8Ptr, -1, null, null, null); - OS.gtk_file_selection_set_filename (handle, fileNamePtr); - OS.g_free (utf8Ptr); - OS.g_free (fileNamePtr); - - if (filterNames == null) filterNames = new String [0]; - if (filterExtensions == null) filterExtensions = new String [0]; - fullPath = null; - fileNames = new String [0]; -} -/** - * 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; -} -/* Sets URI Mode. - * - * When the FileDialog is in URI mode it returns - * a URI (instead of a file name) for the following - * methods: open() and getFilterPath(). - * The input argment for setFilterPath() should also - * be a URI. - */ -/*public*/ void setURIMode (boolean uriMode) { - this.uriMode = uriMode; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java deleted file mode 100644 index d2c7d32698..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/FontDialog.java +++ /dev/null @@ -1,243 +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.gtk.*; -import org.eclipse.swt.graphics.*; - -/** - * 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 { - FontData fontData; - RGB rgb; -/** - * 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 (); -} - -/** - * 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 () { - return fontData; -} - -/** - * 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 () { - if (fontData == null) return null; - FontData [] result = new FontData [1]; - result [0] = fontData; - return result; -} - -/** - * 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; -} - -/** - * 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 () { - int /*long*/ handle; - byte [] titleBytes; - titleBytes = Converter.wcsToMbcs (null, title, true); - Display display = parent != null ? parent.getDisplay (): Display.getCurrent (); - handle = OS.gtk_font_selection_dialog_new (titleBytes); - if (parent!=null) { - int /*long*/ shellHandle = parent.topHandle (); - OS.gtk_window_set_transient_for(handle, shellHandle); - int /*long*/ pixbufs = OS.gtk_window_get_icon_list (shellHandle); - if (pixbufs != 0) { - OS.gtk_window_set_icon_list (handle, pixbufs); - OS.g_list_free (pixbufs); - } - } - OS.gtk_window_set_modal (handle, true); - if (fontData != null) { - Font font = new Font (display, fontData); - int /*long*/ fontName = OS.pango_font_description_to_string (font.handle); - int length = OS.strlen (fontName); - byte [] buffer = new byte [length + 1]; - OS.memmove (buffer, fontName, length); - font.dispose(); - OS.g_free (fontName); - OS.gtk_font_selection_dialog_set_font_name (handle, buffer); - } - display.addIdleProc (); - Dialog oldModal = null; - if (OS.gtk_window_get_modal (handle)) { - oldModal = display.getModalDialog (); - display.setModalDialog (this); - } - int signalId = 0; - int /*long*/ hookId = 0; - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - signalId = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET()); - hookId = OS.g_signal_add_emission_hook (signalId, 0, display.emissionProc, handle, 0); - } - int response = OS.gtk_dialog_run (handle); - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - OS.g_signal_remove_emission_hook (signalId, hookId); - } - if (OS.gtk_window_get_modal (handle)) { - display.setModalDialog (oldModal); - } - boolean success = response == OS.GTK_RESPONSE_OK; - if (success) { - int /*long*/ fontName = OS.gtk_font_selection_dialog_get_font_name (handle); - int length = OS.strlen (fontName); - byte [] buffer = new byte [length + 1]; - OS.memmove (buffer, fontName, length); - OS.g_free (fontName); - int /*long*/ fontDesc = OS.pango_font_description_from_string (buffer); - Font font = Font.gtk_new (display, fontDesc); - fontData = font.getFontData () [0]; - OS.pango_font_description_free (fontDesc); - } - display.removeIdleProc (); - OS.gtk_widget_destroy(handle); - if (!success) return null; - return fontData; -} -/** - * 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) { - this.fontData = 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) { - if (fontData != null && fontData.length > 0) { - this.fontData = fontData [0]; - } else { - this.fontData = null; - } -} -/** - * 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; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java deleted file mode 100644 index f2b75d007c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Group.java +++ /dev/null @@ -1,292 +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.gtk.*; -import org.eclipse.swt.graphics.*; - -/** - * 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 /*long*/ clientHandle, 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); -} - -int /*long*/ clientHandle () { - return clientHandle; -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - Point size = super.computeSize(wHint, hHint, changed); - int width = computeNativeSize (handle, SWT.DEFAULT, SWT.DEFAULT, false).x; - size.x = Math.max (size.x, width); - return size; -} -public Rectangle computeTrim (int x, int y, int width, int height) { - checkWidget(); - forceResize (); - int clientX = OS.GTK_WIDGET_X (clientHandle); - int clientY = OS.GTK_WIDGET_Y (clientHandle); - x -= clientX; - y -= clientY; - width += clientX + clientX; - height += clientX + clientY; - return new Rectangle (x, y, width, height); -} - -void createHandle(int index) { - state |= HANDLE | THEME_BACKGROUND; - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - handle = OS.gtk_frame_new (null); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - labelHandle = OS.gtk_label_new (null); - if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.g_object_ref (labelHandle); - OS.gtk_object_sink (labelHandle); - clientHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (clientHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (fixedHandle, handle); - OS.gtk_container_add (handle, clientHandle); - if ((style & SWT.SHADOW_IN) != 0) { - OS.gtk_frame_set_shadow_type (handle, OS.GTK_SHADOW_IN); - } - if ((style & SWT.SHADOW_OUT) != 0) { - OS.gtk_frame_set_shadow_type (handle, OS.GTK_SHADOW_OUT); - } - if ((style & SWT.SHADOW_ETCHED_IN) != 0) { - OS.gtk_frame_set_shadow_type (handle, OS.GTK_SHADOW_ETCHED_IN); - } - if ((style & SWT.SHADOW_ETCHED_OUT) != 0) { - OS.gtk_frame_set_shadow_type (handle, OS.GTK_SHADOW_ETCHED_OUT); - } -} - -void deregister () { - super.deregister (); - display.removeWidget (clientHandle); - display.removeWidget (labelHandle); -} - -void enableWidget (boolean enabled) { - OS.gtk_widget_set_sensitive (labelHandle, enabled); -} - -int /*long*/ eventHandle () { - return fixedHandle; -} - -String getNameText () { - return getText (); -} - -/** - * 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(); - if (labelHandle != 0) { - OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false); - } -} - -boolean mnemonicHit (char key) { - if (labelHandle == 0) return false; - boolean result = super.mnemonicHit (labelHandle, key); - if (result) setFocus (); - return result; -} - -boolean mnemonicMatch (char key) { - if (labelHandle == 0) return false; - return mnemonicMatch (labelHandle, key); -} - -int /*long*/ parentingHandle() { - return fixedHandle; -} - -void register () { - super.register (); - display.addWidget (clientHandle, this); - display.addWidget (labelHandle, this); -} - -void releaseHandle () { - super.releaseHandle (); - clientHandle = labelHandle = 0; -} - -void releaseWidget () { - super.releaseWidget (); - if (labelHandle != 0) OS.g_object_unref (labelHandle); - text = null; -} - -void setBackgroundColor (GdkColor color) { - super.setBackgroundColor (color); - setBackgroundColor(fixedHandle, color); -} - -void setFontDescription (int /*long*/ font) { - super.setFontDescription (font); - OS.gtk_widget_modify_font (labelHandle, font); -} - -void setForegroundColor (GdkColor color) { - super.setForegroundColor (color); - setForegroundColor (labelHandle, color); -} - -void setOrientation () { - super.setOrientation (); - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - OS.gtk_widget_set_direction (labelHandle, OS.GTK_TEXT_DIR_RTL); - } -} - -/** - * 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 [] chars = fixMnemonic (string); - byte [] buffer = Converter.wcsToMbcs (null, chars, true); - OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer); - if (string.length () != 0) { - if (OS.gtk_frame_get_label_widget (handle) == 0) { - OS.gtk_frame_set_label_widget (handle, labelHandle); - } - } else { - OS.gtk_frame_set_label_widget (handle, 0); - } -} - -void showWidget () { - super.showWidget (); - if (clientHandle != 0) OS.gtk_widget_show (clientHandle); - if (labelHandle != 0) OS.gtk_widget_show (labelHandle); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/IME.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/IME.java deleted file mode 100644 index cc0036e7c9..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/IME.java +++ /dev/null @@ -1,443 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 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.internal.*; -import org.eclipse.swt.internal.gtk.*; - - -/** - * Instances of this class represent input method editors. - * These are typically in-line pre-edit text areas that allow - * the user to compose characters from Far Eastern languages - * such as Japanese, Chinese or Korean. - * - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>ImeComposition</dd> - * </dl> - * <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> - * - * @since 3.4 - * @noextend This class is not intended to be subclassed by clients. - */ -public class IME extends Widget { - Canvas parent; - int caretOffset; - int startOffset; - int commitCount; - String text; - int [] ranges; - TextStyle [] styles; - boolean inComposition; - -/** - * Prevents uninitialized instances from being created outside the package. - */ -IME () { -} - -/** - * 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 canvas 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 IME (Canvas parent, int style) { - super (parent, style); - this.parent = parent; - createWidget (); -} - -void createWidget () { - text = ""; - startOffset = -1; - if (parent.getIME () == null) { - parent.setIME (this); - } -} - -/** - * Returns the offset of the caret from the start of the document. - * The caret is within the current composition. - * - * @return the caret offset - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 getCaretOffset () { - checkWidget (); - return startOffset + caretOffset; -} - -/** - * Returns the commit count of the composition. This is the - * number of characters that have been composed. When the - * commit count is equal to the length of the composition - * text, then the in-line edit operation is complete. - * - * @return the commit count - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 IME#getText - */ -public int getCommitCount () { - checkWidget (); - return commitCount; -} - -/** - * Returns the offset of the composition from the start of the document. - * This is the start offset of the composition within the document and - * in not changed by the input method editor itself during the in-line edit - * session. - * - * @return the offset of the composition - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 getCompositionOffset () { - checkWidget (); - return startOffset; -} - -/** - * Returns the ranges for the style that should be applied during the - * in-line edit session. - * <p> - * The ranges array contains start and end pairs. Each pair refers to - * the corresponding style in the styles array. For example, the pair - * that starts at ranges[n] and ends at ranges[n+1] uses the style - * at styles[n/2] returned by <code>getStyles()</code>. - * </p> - * @return the ranges for the styles - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 IME#getStyles - */ -public int [] getRanges () { - checkWidget (); - if (ranges == null) return new int [0]; - int [] result = new int [ranges.length]; - for (int i = 0; i < result.length; i++) { - result [i] = ranges [i] + startOffset; - } - return result; -} - -/** - * Returns the styles for the ranges. - * <p> - * The ranges array contains start and end pairs. Each pair refers to - * the corresponding style in the styles array. For example, the pair - * that starts at ranges[n] and ends at ranges[n+1] uses the style - * at styles[n/2]. - * </p> - * - * @return the ranges for the styles - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 IME#getRanges - */ -public TextStyle [] getStyles () { - checkWidget (); - if (styles == null) return new TextStyle [0]; - TextStyle [] result = new TextStyle [styles.length]; - System.arraycopy (styles, 0, result, 0, styles.length); - return result; -} - -/** - * Returns the composition text. - * <p> - * The text for an IME is the characters in the widget that - * are in the current composition. When the commit count is - * equal to the length of the composition text, then the - * in-line edit operation is complete. - * </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 (); - return text; -} - -/** - * Returns <code>true</code> if the caret should be wide, and - * <code>false</code> otherwise. In some languages, for example - * Korean, the caret is typically widened to the width of the - * current character in the in-line edit session. - * - * @return the wide caret 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 getWideCaret () { - checkWidget (); - return false; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - if (!isInlineEnabled ()) return 0; - int /*long*/ imHandle = imHandle (); - if (imHandle != 0) OS.gtk_im_context_reset (imHandle); - return 0; -} - -int /*long*/ gtk_commit (int /*long*/ imcontext, int /*long*/ textPtr) { - if (!isInlineEnabled ()) return 0; - boolean doit = true; - ranges = null; - styles = null; - caretOffset = commitCount = 0; - if (textPtr != 0 && inComposition) { - int length = OS.strlen (textPtr); - if (length != 0) { - byte [] buffer = new byte [length]; - OS.memmove (buffer, textPtr, length); - char [] chars = Converter.mbcsToWcs (null, buffer); - Event event = new Event(); - event.detail = SWT.COMPOSITION_CHANGED; - event.start = startOffset; - event.end = startOffset + text.length (); - event.text = text = chars != null ? new String (chars) : ""; - commitCount = text.length(); - sendEvent (SWT.ImeComposition, event); - doit = event.doit; - text = ""; - startOffset = -1; - commitCount = 0; - } - } - inComposition = false; - return doit ? 0 : 1; -} - -int /*long*/ gtk_preedit_changed (int /*long*/ imcontext) { - if (!isInlineEnabled ()) return 0; - ranges = null; - styles = null; - commitCount = 0; - int /*long*/ imHandle = imHandle (); - int /*long*/ [] preeditString = new int /*long*/ [1]; - int /*long*/ [] pangoAttrs = new int /*long*/ [1]; - int [] cursorPos = new int [1]; - OS.gtk_im_context_get_preedit_string (imHandle, preeditString, pangoAttrs, cursorPos); - caretOffset = cursorPos [0]; - char [] chars = null; - if (preeditString [0] != 0) { - int length = OS.strlen (preeditString [0]); - byte [] buffer = new byte [length]; - OS.memmove (buffer, preeditString [0], length); - chars = Converter.mbcsToWcs (null, buffer); - if (pangoAttrs [0] != 0) { - int count = 0; - int /*long*/ iterator = OS.pango_attr_list_get_iterator (pangoAttrs [0]); - while (OS.pango_attr_iterator_next (iterator)) count++; - OS.pango_attr_iterator_destroy (iterator); - ranges = new int [count * 2]; - styles = new TextStyle [count]; - iterator = OS.pango_attr_list_get_iterator (pangoAttrs [0]); - PangoAttrColor attrColor = new PangoAttrColor (); - PangoAttrInt attrInt = new PangoAttrInt (); - int [] start = new int [1]; - int [] end = new int [1]; - for (int i = 0; i < count; i++) { - OS.pango_attr_iterator_range (iterator, start, end); - ranges [i * 2] = (int)/*64*/OS.g_utf8_pointer_to_offset (preeditString [0], preeditString [0] + start [0]); - ranges [i * 2 + 1] = (int)/*64*/OS.g_utf8_pointer_to_offset (preeditString [0], preeditString [0] + end [0]) - 1; - styles [i] = new TextStyle (null, null, null); - int /*long*/ attr = OS.pango_attr_iterator_get (iterator, OS.PANGO_ATTR_FOREGROUND); - if (attr != 0) { - OS.memmove (attrColor, attr, PangoAttrColor.sizeof); - GdkColor color = new GdkColor (); - color.red = attrColor.color_red; - color.green = attrColor.color_green; - color.blue = attrColor.color_blue; - styles [i].foreground = Color.gtk_new (display, color); - } - attr = OS.pango_attr_iterator_get (iterator, OS.PANGO_ATTR_BACKGROUND); - if (attr != 0) { - OS.memmove (attrColor, attr, PangoAttrColor.sizeof); - GdkColor color = new GdkColor (); - color.red = attrColor.color_red; - color.green = attrColor.color_green; - color.blue = attrColor.color_blue; - styles [i].background = Color.gtk_new (display, color); - } - attr = OS.pango_attr_iterator_get (iterator, OS.PANGO_ATTR_UNDERLINE); - if (attr != 0) { - OS.memmove (attrInt, attr, PangoAttrInt.sizeof); - styles [i].underline = attrInt.value != OS.PANGO_UNDERLINE_NONE;; - styles [i].underlineStyle = SWT.UNDERLINE_SINGLE; - switch (attrInt.value) { - case OS.PANGO_UNDERLINE_DOUBLE: - styles [i].underlineStyle = SWT.UNDERLINE_DOUBLE; - break; - case OS.PANGO_UNDERLINE_ERROR: - styles [i].underlineStyle = SWT.UNDERLINE_ERROR; - break; - } - if (styles [i].underline) { - attr = OS.pango_attr_iterator_get(iterator, OS.PANGO_ATTR_UNDERLINE_COLOR); - if (attr != 0) { - OS.memmove (attrColor, attr, PangoAttrColor.sizeof); - GdkColor color = new GdkColor (); - color.red = attrColor.color_red; - color.green = attrColor.color_green; - color.blue = attrColor.color_blue; - styles [i].underlineColor = Color.gtk_new (display, color); - } - } - } - OS.pango_attr_iterator_next (iterator); - } - OS.pango_attr_iterator_destroy (iterator); - OS.pango_attr_list_unref (pangoAttrs [0]); - } - OS.g_free (preeditString [0]); - } - if (chars != null) { - if (text.length() == 0) { - /* - * Bug in GTK. In Solaris, the IME sends multiple - * preedit_changed signals with an empty text. - * This behavior is not correct for SWT and can - * cause the editor to replace its current selection - * with an empty string. The fix is to ignore any - * preedit_changed signals with an empty text when - * the preedit buffer is already empty. - */ - if (chars.length == 0) return 0; - startOffset = -1; - } - int end = startOffset + text.length(); - if (startOffset == -1) { - Event event = new Event (); - event.detail = SWT.COMPOSITION_SELECTION; - sendEvent (SWT.ImeComposition, event); - startOffset = event.start; - end = event.end; - } - inComposition = true; - Event event = new Event (); - event.detail = SWT.COMPOSITION_CHANGED; - event.start = startOffset; - event.end = end; - event.text = text = chars != null ? new String (chars) : ""; - sendEvent (SWT.ImeComposition, event); - } - return 1; -} - -int /*long*/ imHandle () { - return parent.imHandle (); -} - -boolean isInlineEnabled () { - return hooks (SWT.ImeComposition); -} - -void releaseParent () { - super.releaseParent (); - if (this == parent.getIME ()) parent.setIME (null); -} - -void releaseWidget () { - super.releaseWidget (); - parent = null; - text = null; - styles = null; - ranges = null; -} - -/** - * Sets the offset of the composition from the start of the document. - * This is the start offset of the composition within the document and - * in not changed by the input method editor itself during the in-line edit - * session but may need to be changed by clients of the IME. For example, - * if during an in-line edit operation, a text editor inserts characters - * above the IME, then the IME must be informed that the composition - * offset has changed. - * - * @param offset the offset of the composition - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 setCompositionOffset (int offset) { - checkWidget (); - if (offset < 0) return; - if (startOffset != -1) { - startOffset = offset; - } -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ImageList.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ImageList.java deleted file mode 100644 index cab405e065..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ImageList.java +++ /dev/null @@ -1,154 +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.widgets; - - -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.graphics.*; - -class ImageList { - int /*long*/ [] pixbufs; - int width = -1, height = -1; - Image [] images; - -public ImageList() { - images = new Image [4]; - pixbufs = new int /*long*/ [4]; -} - -public int add (Image image) { - int index = 0; - while (index < images.length) { - if (images [index] != null) { - if (images [index].isDisposed ()) { - OS.g_object_unref (pixbufs [index]); - images [index] = null; - pixbufs [index] = 0; - } - } - if (images [index] == null) break; - index++; - } - if (index == images.length) { - Image [] newImages = new Image [images.length + 4]; - System.arraycopy (images, 0, newImages, 0, images.length); - images = newImages; - int /*long*/ [] newPixbufs = new int /*long*/ [pixbufs.length + 4]; - System.arraycopy (pixbufs, 0, newPixbufs, 0, pixbufs.length); - pixbufs = newPixbufs; - } - set (index, image); - return index; -} - -public void dispose () { - if (pixbufs == null) return; - for (int index=0; index<pixbufs.length; index++) { - if (pixbufs [index] != 0) OS.g_object_unref (pixbufs [index]); - } - images = null; - pixbufs = null; -} - -public Image get (int index) { - return images [index]; -} - -int /*long*/ getPixbuf (int index) { - return pixbufs [index]; -} - -public int indexOf (Image image) { - if (image == null) return -1; - for (int index=0; index<images.length; index++) { - if (image == images [index]) return index; - } - return -1; -} - -int indexOf (int /*long*/ pixbuf) { - if (pixbuf == 0) return -1; - for (int index=0; index<images.length; index++) { - if (pixbuf == pixbufs [index]) return index; - } - return -1; -} - -public boolean isDisposed () { - return images == null; -} - -public void put (int index, Image image) { - int count = images.length; - if (!(0 <= index && index < count)) return; - if (image != null) { - set (index, image); - } else { - images [index] = null; - if (pixbufs [index] != 0) OS.g_object_unref (pixbufs [index]); - pixbufs [index] = 0; - } -} - -public void remove (Image image) { - if (image == null) return; - for (int index=0; index<images.length; index++) { - if (image == images [index]){ - OS.g_object_unref (pixbufs [index]); - images [index] = null; - pixbufs [index] = 0; - } - } -} - -void set (int index, Image image) { - int [] w = new int [1], h = new int [1]; - OS.gdk_drawable_get_size (image.pixmap, w, h); - int /*long*/ pixbuf = Display.createPixbuf (image); - if (width == -1 || height == -1) { - width = w [0]; - height = h [0]; - } - if (w [0] != width || h [0] != height) { - int /*long*/ scaledPixbuf = OS.gdk_pixbuf_scale_simple(pixbuf, width, height, OS.GDK_INTERP_BILINEAR); - OS.g_object_unref (pixbuf); - pixbuf = scaledPixbuf; - } - int /*long*/ oldPixbuf = pixbufs [index]; - if (oldPixbuf != 0) { - if (images [index] == image) { - OS.gdk_pixbuf_copy_area (pixbuf, 0, 0, width, height, oldPixbuf, 0, 0); - OS.g_object_unref (pixbuf); - pixbuf = oldPixbuf; - } else { - OS.g_object_unref (oldPixbuf); - } - } - pixbufs [index] = pixbuf; - images [index] = image; -} - -public int size () { - int result = 0; - for (int index=0; index<images.length; index++) { - if (images [index] != null) { - if (images [index].isDisposed ()) { - OS.g_object_unref (pixbufs [index]); - images [index] = null; - pixbufs [index] = 0; - } - if (images [index] != null) result++; - } - } - return result; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java deleted file mode 100644 index 82ec5be7ad..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Label.java +++ /dev/null @@ -1,589 +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.gtk.*; -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 /*long*/ frameHandle, labelHandle, imageHandle; - ImageList imageList; - Image image; - 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#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 addRelation (Control control) { - if (!control.isDescribedByLabel ()) return; - if (labelHandle == 0) return; - int /*long*/ accessible = OS.gtk_widget_get_accessible (labelHandle); - int /*long*/ controlAccessible = OS.gtk_widget_get_accessible (control.handle); - if (accessible != 0 && controlAccessible != 0) { - OS.atk_object_add_relationship (controlAccessible, OS.ATK_RELATION_LABELLED_BY, accessible); - } -} - -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; - if ((style & SWT.SEPARATOR) != 0) { - if ((style & SWT.HORIZONTAL) != 0) { - if (wHint == SWT.DEFAULT) wHint = DEFAULT_WIDTH; - } else { - if (hHint == SWT.DEFAULT) hHint = DEFAULT_HEIGHT; - } - } - Point size; - /* - * Feature in GTK. GTK has a predetermined maximum width for wrapping text. - * The fix is to use pango layout directly instead of the label size request - * to calculate its preferred size. - */ - boolean fixWrap = labelHandle != 0 && (style & SWT.WRAP) != 0 && (OS.GTK_WIDGET_FLAGS (labelHandle) & OS.GTK_VISIBLE) != 0; - if (fixWrap || frameHandle != 0) forceResize (); - if (fixWrap) { - int /*long*/ labelLayout = OS.gtk_label_get_layout (labelHandle); - int pangoWidth = OS.pango_layout_get_width (labelLayout); - if (wHint != SWT.DEFAULT) { - OS.pango_layout_set_width (labelLayout, wHint * OS.PANGO_SCALE); - } else { - OS.pango_layout_set_width (labelLayout, -1); - } - int [] w = new int [1], h = new int [1]; - OS.pango_layout_get_size (labelLayout, w, h); - OS.pango_layout_set_width (labelLayout, pangoWidth); - if (frameHandle != 0) { - int [] labelWidth = new int [1], labelHeight = new int [1]; - OS.gtk_widget_get_size_request (labelHandle, labelWidth, labelHeight); - OS.gtk_widget_set_size_request (labelHandle, 1, 1); - size = computeNativeSize (frameHandle, -1, -1, changed); - OS.gtk_widget_set_size_request (labelHandle, labelWidth [0], labelHeight [0]); - size.x = size.x - 1; - size.y = size.y - 1; - } else { - size = new Point (0,0); - } - size.x += wHint == SWT.DEFAULT ? OS.PANGO_PIXELS(w [0]) : wHint; - size.y += hHint == SWT.DEFAULT ? OS.PANGO_PIXELS(h [0]) : hHint; - } else { - if (frameHandle != 0) { - int [] reqWidth = new int [1], reqHeight = new int [1]; - OS.gtk_widget_get_size_request (handle, reqWidth, reqHeight); - OS.gtk_widget_set_size_request (handle, wHint, hHint); - size = computeNativeSize (frameHandle, -1, -1, changed); - OS.gtk_widget_set_size_request (handle, reqWidth [0], reqHeight [0]); - } else { - size = computeNativeSize (handle, wHint, hHint, changed); - } - } - /* - * Feature in GTK. Instead of using the font height to determine - * the preferred height of the widget, GTK uses the text metrics. - * The fix is to ensure that the preferred height is at least as - * tall as the font height. - * - * NOTE: This work around does not fix the case when there are - * muliple lines of text. - */ - if (hHint == SWT.DEFAULT && labelHandle != 0) { - int /*long*/ layout = OS.gtk_label_get_layout (labelHandle); - int /*long*/ context = OS.pango_layout_get_context (layout); - int /*long*/ lang = OS.pango_context_get_language (context); - int /*long*/ font = getFontDescription (); - int /*long*/ metrics = OS.pango_context_get_metrics (context, font, lang); - int ascent = OS.PANGO_PIXELS (OS.pango_font_metrics_get_ascent (metrics)); - int descent = OS.PANGO_PIXELS (OS.pango_font_metrics_get_descent (metrics)); - OS.pango_font_metrics_unref (metrics); - int fontHeight = ascent + descent; - int [] buffer = new int [1]; - OS.g_object_get (labelHandle, OS.ypad, buffer, 0); - fontHeight += 2 * buffer [0]; - if (frameHandle != 0) { - int /*long*/ style = OS.gtk_widget_get_style (frameHandle); - fontHeight += 2 * OS.gtk_style_get_ythickness (style); - fontHeight += 2 * OS.gtk_container_get_border_width (frameHandle); - } - size.y = Math.max (size.y, fontHeight); - } - return size; -} - -void createHandle (int index) { - state |= HANDLE | THEME_BACKGROUND; - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - if ((style & SWT.SEPARATOR) != 0) { - if ((style & SWT.HORIZONTAL)!= 0) { - handle = OS.gtk_hseparator_new (); - } else { - handle = OS.gtk_vseparator_new (); - } - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - } else { - handle = OS.gtk_hbox_new (false, 0); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - labelHandle = OS.gtk_label_new_with_mnemonic (null); - if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES); - imageHandle = OS.gtk_image_new (); - if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (handle, labelHandle); - OS.gtk_container_add (handle, imageHandle); - } - if ((style & SWT.BORDER) != 0) { - frameHandle = OS.gtk_frame_new (null); - if (frameHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (fixedHandle, frameHandle); - OS.gtk_container_add (frameHandle, handle); - OS.gtk_frame_set_shadow_type (frameHandle, OS.GTK_SHADOW_ETCHED_IN); - } else { - OS.gtk_container_add (fixedHandle, handle); - } - if ((style & SWT.SEPARATOR) != 0) return; - if ((style & SWT.WRAP) != 0) { - OS.gtk_label_set_line_wrap (labelHandle, true); - if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) { - OS.gtk_label_set_line_wrap_mode (labelHandle, OS.PANGO_WRAP_WORD_CHAR); - } - } - setAlignment (); -} - -void createWidget (int index) { - super.createWidget (index); - text = ""; -} - -void deregister () { - super.deregister (); - if (frameHandle != 0) display.removeWidget (frameHandle); - if (labelHandle != 0) display.removeWidget (labelHandle); - if (imageHandle != 0) display.removeWidget (imageHandle); -} - -int /*long*/ eventHandle () { - return fixedHandle; -} - -/** - * 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 0; - if ((style & SWT.LEFT) != 0) return SWT.LEFT; - if ((style & SWT.CENTER) != 0) return SWT.CENTER; - if ((style & SWT.RIGHT) != 0) return SWT.RIGHT; - return SWT.LEFT; -} - -public int getBorderWidth () { - checkWidget(); - if (frameHandle != 0) { - return OS.gtk_style_get_xthickness (OS.gtk_widget_get_style (frameHandle)); - } - return 0; -} - -/** - * 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 (labelHandle != 0) { - OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false); - } -} - -boolean isDescribedByLabel () { - return false; -} - -boolean mnemonicHit (char key) { - if (labelHandle == 0) return false; - boolean result = super.mnemonicHit (labelHandle, key); - if (result) { - 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 result; - } - control = control.parent; - } - } - return result; -} - -boolean mnemonicMatch (char key) { - if (labelHandle == 0) return false; - return mnemonicMatch (labelHandle, key); -} - -void register () { - super.register (); - if (frameHandle != 0) display.addWidget (frameHandle, this); - if (labelHandle != 0) display.addWidget (labelHandle, this); - if (imageHandle != 0) display.addWidget (imageHandle, this); -} - -void releaseHandle () { - super.releaseHandle (); - frameHandle = imageHandle = labelHandle = 0; -} - -void releaseWidget () { - super.releaseWidget (); - if (imageList != null) imageList.dispose (); - imageList = null; - image = null; - text = null; -} - -void resizeHandle (int width, int height) { - OS.gtk_widget_set_size_request (fixedHandle, width, height); - OS.gtk_widget_set_size_request (frameHandle != 0 ? frameHandle : handle, width, height); -} - -/** - * 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; - if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return; - style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER); - style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER); - setAlignment (); -} - -void setAlignment () { - if ((style & SWT.LEFT) != 0) { - OS.gtk_misc_set_alignment (labelHandle, 0.0f, 0.0f); - OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_LEFT); - OS.gtk_misc_set_alignment (imageHandle, 0.0f, 0.5f); - return; - } - if ((style & SWT.CENTER) != 0) { - OS.gtk_misc_set_alignment (labelHandle, 0.5f, 0.0f); - OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_CENTER); - OS.gtk_misc_set_alignment (imageHandle, 0.5f, 0.5f); - return; - } - if ((style & SWT.RIGHT) != 0) { - OS.gtk_misc_set_alignment (labelHandle, 1.0f, 0.0f); - OS.gtk_label_set_justify (labelHandle, OS.GTK_JUSTIFY_RIGHT); - OS.gtk_misc_set_alignment (imageHandle, 1.0f, 0.5f); - return; - } -} - -void setBackgroundColor (GdkColor color) { - super.setBackgroundColor (color); - setBackgroundColor(fixedHandle, color); - if (labelHandle != 0) setBackgroundColor(labelHandle, color); - if (imageHandle != 0) setBackgroundColor(imageHandle, color); -} - -int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - /* - * Bug in GTK. For some reason, when the label is - * wrappable and its container is resized, it does not - * cause the label to be wrapped. The fix is to - * determine the size that will wrap the label - * and expilictly set that size to force the label - * to wrap. - * - * This part of the fix causes the label to be - * resized to the preferred size but it still - * won't draw properly. - */ - boolean fixWrap = resize && labelHandle != 0 && (style & SWT.WRAP) != 0; - if (fixWrap) OS.gtk_widget_set_size_request (labelHandle, -1, -1); - int result = super.setBounds (x, y, width, height, move, resize); - /* - * Bug in GTK. For some reason, when the label is - * wrappable and its container is resized, it does not - * cause the label to be wrapped. The fix is to - * determine the size that will wrap the label - * and expilictly set that size to force the label - * to wrap. - * - * This part of the fix forces the label to be - * resized so that it will draw wrapped. - */ - if (fixWrap) { - int labelWidth = OS.GTK_WIDGET_WIDTH (handle); - int labelHeight = OS.GTK_WIDGET_HEIGHT (handle); - OS.gtk_widget_set_size_request (labelHandle, labelWidth, labelHeight); - /* - * Bug in GTK. Setting the size request should invalidate the label's - * layout, but it does not. The fix is to resize the label directly. - */ - GtkRequisition requisition = new GtkRequisition (); - OS.gtk_widget_size_request (labelHandle, requisition); - GtkAllocation allocation = new GtkAllocation (); - allocation.x = OS.GTK_WIDGET_X (labelHandle); - allocation.y = OS.GTK_WIDGET_Y (labelHandle); - allocation.width = labelWidth; - allocation.height = labelHeight; - OS.gtk_widget_size_allocate (labelHandle, allocation); - } - return result; -} - -void setFontDescription (int /*long*/ font) { - super.setFontDescription (font); - if (labelHandle != 0) OS.gtk_widget_modify_font (labelHandle, font); - if (imageHandle != 0) OS.gtk_widget_modify_font (imageHandle, font); -} - -void setForegroundColor (GdkColor color) { - super.setForegroundColor (color); - setForegroundColor (fixedHandle, color); - if (labelHandle != 0) setForegroundColor (labelHandle, color); - if (imageHandle != 0) setForegroundColor (imageHandle, color); -} - -void setOrientation () { - super.setOrientation (); - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - if (labelHandle != 0) OS.gtk_widget_set_direction (labelHandle, OS.GTK_TEXT_DIR_RTL); - if (imageHandle != 0) OS.gtk_widget_set_direction (imageHandle, OS.GTK_TEXT_DIR_RTL); - } -} - -/** - * 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; - this.image = image; - if (imageList != null) imageList.dispose (); - imageList = null; - if (image != null) { - imageList = new ImageList (); - int imageIndex = imageList.add (image); - int /*long*/ pixbuf = imageList.getPixbuf (imageIndex); - OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); - OS.gtk_widget_hide (labelHandle); - OS.gtk_widget_show (imageHandle); - } else { - OS.gtk_image_set_from_pixbuf (imageHandle, 0); - OS.gtk_widget_show (labelHandle); - OS.gtk_widget_hide (imageHandle); - } -} - -/** - * 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; - text = string; - char [] chars = fixMnemonic (string); - byte [] buffer = Converter.wcsToMbcs (null, chars, true); - OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer); - OS.gtk_widget_hide (imageHandle); - OS.gtk_widget_show (labelHandle); -} - -void showWidget () { - super.showWidget (); - if (frameHandle != 0) OS.gtk_widget_show (frameHandle); - if (labelHandle != 0) OS.gtk_widget_show (labelHandle); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java deleted file mode 100644 index 265b3dcd9c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Link.java +++ /dev/null @@ -1,740 +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.gtk.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; -import org.eclipse.swt.accessibility.*; - -/** - * 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 |= HANDLE | THEME_BACKGROUND; - handle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (handle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (handle, true); - OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS); - layout = new TextLayout (display); - layout.setOrientation((style & SWT.RIGHT_TO_LEFT) != 0? SWT.RIGHT_TO_LEFT : SWT.LEFT_TO_RIGHT); - 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); - layout.setFont (getFont ()); - text = ""; - initAccessible (); -} - -void enableWidget (boolean enabled) { - super.enableWidget (enabled); - if (isDisposed ()) return; - 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 (); -} - -void fixStyle () { - fixStyle (handle); -} - -void initAccessible () { - Accessible accessible = getAccessible (); - accessible.addAccessibleListener (new AccessibleAdapter () { - public void getName (AccessibleEvent e) { - e.result = parse (text); - } - }); - - accessible.addAccessibleControlListener (new AccessibleControlAdapter () { - public void getChildAtPoint (AccessibleControlEvent e) { - e.childID = ACC.CHILDID_SELF; - } - - public void getLocation (AccessibleControlEvent e) { - Rectangle rect = display.map (getParent (), null, getBounds ()); - e.x = rect.x; - e.y = rect.y; - e.width = rect.width; - e.height = rect.height; - } - - public void getChildCount (AccessibleControlEvent e) { - e.detail = 0; - } - - public void getRole (AccessibleControlEvent e) { - e.detail = ACC.ROLE_LINK; - } - - public void getState (AccessibleControlEvent e) { - e.detail = ACC.STATE_FOCUSABLE; - if (hasFocus ()) e.detail |= ACC.STATE_FOCUSED; - } - - public void getDefaultAction (AccessibleControlEvent e) { - e.result = SWT.getMessage ("SWT_Press"); //$NON-NLS-1$ - } - - public void getSelection (AccessibleControlEvent e) { - if (hasFocus ()) e.childID = ACC.CHILDID_SELF; - } - - public void getFocus (AccessibleControlEvent e) { - if (hasFocus ()) e.childID = ACC.CHILDID_SELF; - } - }); -} - -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; -} - -int getClientWidth () { - return (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (handle); -} - -/** - * 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; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_button_press_event (widget, event); - if (result != 0) return result; - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, event, GdkEventButton.sizeof); - if (gdkEvent.button == 1 && gdkEvent.type == OS.GDK_BUTTON_PRESS) { - if (focusIndex != -1) setFocus (); - int x = (int) gdkEvent.x; - int y = (int) gdkEvent.y; - if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x; - int offset = layout.getOffset (x, 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 (x, y)) { - focusIndex = j; - redraw (); - return result; - } - } - } - } - return result; -} - -int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_button_release_event (widget, event); - if (result != 0) return result; - if (focusIndex == -1) return result; - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, event, GdkEventButton.sizeof); - if (gdkEvent.button == 1) { - int x = (int) gdkEvent.x; - int y = (int) gdkEvent.y; - if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x; - Rectangle [] rects = getRectangles (focusIndex); - for (int i = 0; i < rects.length; i++) { - Rectangle rect = rects [i]; - if (rect.contains (x, y)) { - Event ev = new Event (); - ev.text = ids [focusIndex]; - sendEvent (SWT.Selection, ev); - return result; - } - } - } - return result; -} - -int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) { - int /*long*/ result = super.gtk_event_after (widget, gdkEvent); - GdkEvent event = new GdkEvent (); - OS.memmove (event, gdkEvent, GdkEvent.sizeof); - switch (event.type) { - case OS.GDK_FOCUS_CHANGE: - redraw (); - break; - } - return result; -} - -int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ eventPtr) { - if ((state & OBSCURED) != 0) return 0; - GdkEventExpose gdkEvent = new GdkEventExpose (); - OS.memmove (gdkEvent, eventPtr, GdkEventExpose.sizeof); - GCData data = new GCData (); - data.damageRgn = gdkEvent.region; - GC gc = GC.gtk_new (this, data); - OS.gdk_gc_set_clip_region (gc.handle, gdkEvent.region); - 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; - if ((state & DISABLED) != 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); - } - } - if (hooks (SWT.Paint) || filters (SWT.Paint)) { - Event event = new Event (); - event.count = gdkEvent.count; - event.x = gdkEvent.area_x; - event.y = gdkEvent.area_y; - event.width = gdkEvent.area_width; - event.height = gdkEvent.area_height; - if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - event.width - event.x; - event.gc = gc; - sendEvent (SWT.Paint, event); - event.gc = null; - } - gc.dispose (); - return 0; -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ eventPtr) { - int /*long*/ result = super.gtk_key_press_event (widget, eventPtr); - if (result != 0) return result; - if (focusIndex == -1) return result; - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof); - switch (gdkEvent.keyval) { - case OS.GDK_Return: - case OS.GDK_KP_Enter: - case OS.GDK_space: - Event event = new Event (); - event.text = ids [focusIndex]; - sendEvent (SWT.Selection, event); - break; - case OS.GDK_Tab: - if (focusIndex < offsets.length - 1) { - focusIndex++; - redraw (); - } - break; - case OS.GDK_ISO_Left_Tab: - if (focusIndex > 0) { - focusIndex--; - redraw (); - } - break; - } - return result; -} - -int /*long*/ gtk_motion_notify_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_motion_notify_event (widget, event); - if (result != 0) return result; - GdkEventMotion gdkEvent = new GdkEventMotion (); - OS.memmove (gdkEvent, event, GdkEventMotion.sizeof); - int x = (int) gdkEvent.x; - int y = (int) gdkEvent.y; - if ((style & SWT.MIRRORED) != 0) x = getClientWidth () - x; - if ((gdkEvent.state & OS.GDK_BUTTON1_MASK) != 0) { - int oldSelection = selection.y; - selection.y = layout.getOffset (x, 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); - } - } else { - 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 (x, y)) { - setCursor (display.getSystemCursor (SWT.CURSOR_HAND)); - return result; - } - } - } - setCursor (null); - } - return result; -} - -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; -} - -int setBounds(int x, int y, int width, int height, boolean move, boolean resize) { - int result = super.setBounds (x, y, width,height, move, resize); - if ((result & RESIZED) != 0) { - layout.setWidth (width > 0 ? width : -1); - redraw (); - } - return result; -} - -void setFontDescription (int /*long*/ font) { - super.setFontDescription (font); - layout.setFont (Font.gtk_new (display, font)); -} - -/** - * 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; - boolean enabled = (state & DISABLED) == 0; - TextStyle linkStyle = new TextStyle (null, enabled ? linkColor : disabledColor, null); - linkStyle.underline = true; - int [] bidiSegments = new int [offsets.length*2]; - for (int i = 0; i < offsets.length; i++) { - Point point = offsets [i]; - layout.setStyle (linkStyle, point.x, point.y); - bidiSegments[i*2] = point.x; - bidiSegments[i*2+1] = point.y+1; - } - layout.setSegments (bidiSegments); - 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 (); -} - -void showWidget () { - super.showWidget (); - fixStyle (handle); -} - -int traversalCode (int key, GdkEventKey event) { - if (offsets.length == 0) return 0; - int bits = super.traversalCode (key, event); - if (key == OS.GDK_Tab && focusIndex < offsets.length - 1) { - return bits & ~SWT.TRAVERSE_TAB_NEXT; - } - if (key == OS.GDK_ISO_Left_Tab && focusIndex > 0) { - return bits & ~SWT.TRAVERSE_TAB_PREVIOUS; - } - return bits; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java deleted file mode 100644 index b1df97fd18..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/List.java +++ /dev/null @@ -1,1594 +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.gtk.*; -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 { - int /*long*/ modelHandle; - - static final int TEXT_COLUMN = 0; - -/** - * 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) { - 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 (null, string, true); - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (iter == 0) error (SWT.ERROR_ITEM_NOT_ADDED); - OS.gtk_list_store_append (modelHandle, iter); - OS.gtk_list_store_set (modelHandle, iter, TEXT_COLUMN, buffer, -1); - OS.g_free (iter); -} - -/** - * 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); - int count = OS.gtk_tree_model_iter_n_children (modelHandle, 0); - if (!(0 <= index && index <= count)) { - error (SWT.ERROR_INVALID_RANGE); - } - byte [] buffer = Converter.wcsToMbcs (null, string, true); - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (iter == 0) error (SWT.ERROR_ITEM_NOT_ADDED); - /* - * Feature in GTK. It is much faster to append to a list store - * than to insert at the end using gtk_list_store_insert(). - */ - if (index == count) { - OS.gtk_list_store_append (modelHandle, iter); - } else { - OS.gtk_list_store_insert (modelHandle, iter, index); - } - OS.gtk_list_store_set (modelHandle, iter, TEXT_COLUMN, buffer, -1); - OS.g_free (iter); -} - -/** - * 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); -} - -void createHandle (int index) { - state |= HANDLE; - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - scrolledHandle = OS.gtk_scrolled_window_new (0, 0); - if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES); - /* - * Columns: - * 0 - text - */ - int /*long*/ [] types = new int /*long*/ [] {OS.G_TYPE_STRING ()}; - modelHandle = OS.gtk_list_store_newv (types.length, types); - if (modelHandle == 0) error (SWT.ERROR_NO_HANDLES); - handle = OS.gtk_tree_view_new_with_model (modelHandle); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ textRenderer = OS.gtk_cell_renderer_text_new (); - if (textRenderer == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ columnHandle = OS.gtk_tree_view_column_new (); - if (columnHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_tree_view_column_pack_start (columnHandle, textRenderer, true); - OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.text, TEXT_COLUMN); - OS.gtk_tree_view_insert_column (handle, columnHandle, index); - OS.gtk_container_add (fixedHandle, scrolledHandle); - OS.gtk_container_add (scrolledHandle, handle); - - int mode = (style & SWT.MULTI) != 0 ? OS.GTK_SELECTION_MULTIPLE : OS.GTK_SELECTION_BROWSE; - int /*long*/ selectionHandle = OS.gtk_tree_view_get_selection (handle); - OS.gtk_tree_selection_set_mode (selectionHandle, mode); - OS.gtk_tree_view_set_headers_visible (handle, false); - int hsp = (style & SWT.H_SCROLL) != 0 ? OS.GTK_POLICY_AUTOMATIC : OS.GTK_POLICY_NEVER; - int vsp = (style & SWT.V_SCROLL) != 0 ? OS.GTK_POLICY_AUTOMATIC : OS.GTK_POLICY_NEVER; - OS.gtk_scrolled_window_set_policy (scrolledHandle, hsp, vsp); - if ((style & SWT.BORDER) != 0) OS.gtk_scrolled_window_set_shadow_type (scrolledHandle, OS.GTK_SHADOW_ETCHED_IN); - /* - * Bug in GTK. When a treeview is the child of an override shell, - * and if the user has ever invokes the interactive search field, - * and the treeview is disposed on a focus out event, it segment - * faults. The fix is to disable the search field in an override - * shell. - */ - if ((getShell ().style & SWT.ON_TOP) != 0) { - /* - * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE) - * would prevent the user from being able to type in text to search the tree. - * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive - * search. This meant that even if FALSE was passed to enable_search, the user - * can still bring up the search pop up using the keybinding. GTK also introduced - * the notion of passing a -1 to gtk_set_search_column to disable searching - * (including the search key binding). The fix is to use the right calls - * for the right version. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 5)) { - OS.gtk_tree_view_set_search_column (handle, -1); - } else { - OS.gtk_tree_view_set_enable_search (handle, false); - } - } -} - -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; - Point size = computeNativeSize (handle, wHint, hHint, changed); - Rectangle trim = computeTrim (0, 0, size.x, size.y); - size.x = trim.width; - size.y = trim.height; - return size; -} - -void deregister() { - super.deregister (); - display.removeWidget (OS.gtk_tree_view_get_selection (handle)); -} - -/** - * 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(); - if (!(0 <= index && index < OS.gtk_tree_model_iter_n_children (modelHandle, 0))) return; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - OS.gtk_tree_selection_unselect_iter (selection, iter); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_free (iter); -} - -/** - * 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 < 0 && end < 0) return; - int count = OS.gtk_tree_model_iter_n_children (modelHandle, 0); - if (start >= count && end >= count) return; - start = Math.min (count - 1, Math.max (0, start)); - end = Math.min (count - 1, Math.max (0, end)); - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - for (int index=start; index<=end; index++) { - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - OS.gtk_tree_selection_unselect_iter (selection, iter); - } - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_free (iter); -} - -/** - * 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); - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - int count = OS.gtk_tree_model_iter_n_children (modelHandle, 0); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - for (int i=0; i<indices.length; i++) { - int index = indices [i]; - if (index < 0 || index > count - 1) continue; - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - OS.gtk_tree_selection_unselect_iter (selection, iter); - } - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_free (iter); -} - -/** - * 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(); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_selection_unselect_all (selection); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); -} - -boolean dragDetect (int x, int y, boolean filter, boolean [] consume) { - boolean selected = false; - if (filter) { - int /*long*/ [] path = new int /*long*/ [1]; - if (OS.gtk_tree_view_get_path_at_pos (handle, x, y, path, null, null, null)) { - if (path [0] != 0) { - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - if (OS.gtk_tree_selection_path_is_selected (selection, path [0])) selected = true; - OS.gtk_tree_path_free (path [0]); - } - } else { - return false; - } - } - boolean dragDetect = super.dragDetect (x, y, filter, consume); - if (dragDetect && selected && consume != null) consume [0] = true; - return dragDetect; -} - -int /*long*/ eventWindow () { - return paintWindow (); -} - -GdkColor getBackgroundColor () { - return getBaseColor (); -} - -/** - * 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(); - int /*long*/ [] path = new int /*long*/ [1]; - OS.gtk_tree_view_get_cursor (handle, path, null); - if (path [0] == 0) return -1; - int /*long*/ indices = OS.gtk_tree_path_get_indices (path [0]); - int [] index = new int []{-1}; - if (indices != 0) OS.memmove (index, indices, 4); - OS.gtk_tree_path_free (path [0]); - return index [0]; -} - -GdkColor getForegroundColor () { - return getTextColor (); -} - -/** - * 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(); - if (!(0 <= index && index < OS.gtk_tree_model_iter_n_children (modelHandle, 0))) { - error (SWT.ERROR_INVALID_RANGE); - } - int /*long*/ [] ptr = new int /*long*/ [1]; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - OS.gtk_tree_model_get (modelHandle, iter, 0, ptr, -1); - OS.g_free (iter); - if (ptr [0] == 0) return null; - int length = OS.strlen (ptr [0]); - byte[] buffer2 = new byte [length]; - OS.memmove (buffer2, ptr [0], length); - OS.g_free (ptr [0]); - return new String (Converter.mbcsToWcs (null, buffer2)); -} - -/** - * 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 OS.gtk_tree_model_iter_n_children (modelHandle, 0); -} - -/** - * 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 itemCount = OS.gtk_tree_model_iter_n_children (modelHandle, 0); - int /*long*/ column = OS.gtk_tree_view_get_column (handle, 0); - if (itemCount == 0) { - int [] w = new int [1], h = new int [1]; - OS.gtk_tree_view_column_cell_get_size (column, null, null, null, w, h); - return h [0]; - } else { - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - OS.gtk_tree_model_get_iter_first (modelHandle, iter); - OS.gtk_tree_view_column_cell_set_cell_data (column, modelHandle, iter, false, false); - int [] w = new int [1], h = new int [1]; - OS.gtk_tree_view_column_cell_get_size (column, null, null, null, w, h); - OS.g_free (iter); - return h [0]; - } -} - -/** - * 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 count = OS.gtk_tree_model_iter_n_children (modelHandle, 0); - int /*long*/ [] ptr = new int /*long*/ [1]; - String [] result = new String [count]; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - for (int index=0; index<count; index++) { - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - OS.gtk_tree_model_get (modelHandle, iter, 0, ptr, -1); - if (ptr [0] != 0) { - int length = OS.strlen (ptr [0]); - byte[] buffer = new byte [length]; - OS.memmove (buffer, ptr [0], length); - OS.g_free (ptr [0]); - result [index] = new String (Converter.mbcsToWcs (null, buffer)); - } - } - OS.g_free (iter); - 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 [] indices = getSelectionIndices (); - String [] result = new String [indices.length]; - for (int i=0; i<indices.length; i++) { - result [i] = getItem (indices [i]); - } - 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 /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) { - display.treeSelectionLength = 0; - display.treeSelection = null; - OS.gtk_tree_selection_selected_foreach (selection, display.treeSelectionProc, handle); - return display.treeSelectionLength; - } - return OS.gtk_tree_selection_count_selected_rows (selection); -} - -/** - * 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 /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) { - int itemCount = OS.gtk_tree_model_iter_n_children (modelHandle, 0); - display.treeSelectionLength = 0; - display.treeSelection = new int [itemCount]; - OS.gtk_tree_selection_selected_foreach (selection, display.treeSelectionProc, handle); - if (display.treeSelectionLength == 0) return -1; - return display.treeSelection [0]; - } - /* - * Bug in GTK. gtk_tree_selection_get_selected_rows() segmentation faults - * in versions smaller than 2.2.4 if the model is NULL. The fix is - * to give a valid pointer instead. - */ - int /*long*/ [] model = OS.GTK_VERSION < OS.VERSION (2, 2, 4) ? new int /*long*/ [1] : null; - int /*long*/ list = OS.gtk_tree_selection_get_selected_rows (selection, model); - if (list != 0) { - int count = OS.g_list_length (list); - int [] index = new int [1]; - for (int i=0; i<count; i++) { - int /*long*/ data = OS.g_list_nth_data (list, i); - int /*long*/ indices = OS.gtk_tree_path_get_indices (data); - if (indices != 0) { - OS.memmove (index, indices, 4); - break; - } - } - OS.g_list_free (list); - return index [0]; - } - return -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 /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) { - int itemCount = OS.gtk_tree_model_iter_n_children (modelHandle, 0); - display.treeSelectionLength = 0; - display.treeSelection = new int [itemCount]; - OS.gtk_tree_selection_selected_foreach (selection, display.treeSelectionProc, handle); - if (display.treeSelectionLength == display.treeSelection.length) return display.treeSelection; - int [] result = new int [display.treeSelectionLength]; - System.arraycopy (display.treeSelection, 0, result, 0, display.treeSelectionLength); - return result; - } - /* - * Bug in GTK. gtk_tree_selection_get_selected_rows() segmentation faults - * in versions smaller than 2.2.4 if the model is NULL. The fix is - * to give a valid pointer instead. - */ - int /*long*/ [] model = OS.GTK_VERSION < OS.VERSION (2, 2, 4) ? new int /*long*/ [1] : null; - int /*long*/ list = OS.gtk_tree_selection_get_selected_rows (selection, model); - if (list != 0) { - int count = OS.g_list_length (list); - int [] treeSelection = new int [count]; - int length = 0; - for (int i=0; i<count; i++) { - int /*long*/ data = OS.g_list_nth_data (list, i); - int /*long*/ indices = OS.gtk_tree_path_get_indices (data); - if (indices != 0) { - int [] index = new int [1]; - OS.memmove (index, indices, 4); - treeSelection [length] = index [0]; - length++; - } - } - OS.g_list_free (list); - int [] result = new int [length]; - System.arraycopy (treeSelection, 0, result, 0, length); - return result; - } - return new int [0]; -} - -/** - * 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 /*long*/ [] path = new int /*long*/ [1]; - OS.gtk_widget_realize (handle); - if (!OS.gtk_tree_view_get_path_at_pos (handle, 1, 1, path, null, null, null)) return 0; - if (path [0] == 0) return 0; - int /*long*/ indices = OS.gtk_tree_path_get_indices (path[0]); - int[] index = new int [1]; - if (indices != 0) OS.memmove (index, indices, 4); - OS.gtk_tree_path_free (path [0]); - return index [0]; -} - -int /*long*/ gtk_changed (int /*long*/ widget) { - postEvent (SWT.Selection); - return 0; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_button_press_event (widget, event); - if (result != 0) return result; - /* - * Feature in GTK. In a multi-select list view, when multiple items are already - * selected, the selection state of the item is toggled and the previous selection - * is cleared. This is not the desired behaviour when bringing up a popup menu. - * Also, when an item is reselected with the right button, the tree view issues - * an unwanted selection event. The workaround is to detect that case and not - * run the default handler when the item is already part of the current selection. - */ - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, event, GdkEventButton.sizeof); - int button = gdkEvent.button; - if (button == 3 && gdkEvent.type == OS.GDK_BUTTON_PRESS) { - int /*long*/ [] path = new int /*long*/ [1]; - if (OS.gtk_tree_view_get_path_at_pos (handle, (int)gdkEvent.x, (int)gdkEvent.y, path, null, null, null)) { - if (path [0] != 0) { - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - if (OS.gtk_tree_selection_path_is_selected (selection, path [0])) result = 1; - OS.gtk_tree_path_free (path [0]); - } - } - } - - /* - * Feature in GTK. When the user clicks in a single selection GtkTreeView - * and there are no selected items, the first item is selected automatically - * before the click is processed, causing two selection events. The is fix - * is the set the cursor item to be same as the clicked item to stop the - * widget from automatically selecting the first item. - */ - if ((style & SWT.SINGLE) != 0 && getSelectionCount () == 0) { - int /*long*/ [] path = new int /*long*/ [1]; - if (OS.gtk_tree_view_get_path_at_pos (handle, (int)gdkEvent.x, (int)gdkEvent.y, path, null, null, null)) { - if (path [0] != 0) { - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_view_set_cursor (handle, path [0], 0, false); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_path_free (path [0]); - } - } - } - /* - * Bug in GTK. GTK segments fault, if the GtkTreeView widget is - * not in focus and all items in the widget are disposed before - * it finishes processing a button press. The fix is to give - * focus to the widget before it starts processing the event. - */ - if (!OS.GTK_WIDGET_HAS_FOCUS (handle)) { - OS.gtk_widget_grab_focus (handle); - } - return result; -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_key_press_event (widget, event); - if (result != 0) return result; - if (OS.GTK_VERSION < OS.VERSION (2, 2 ,0)) { - /* - * Feature in GTK 2.0.x. When an item is default selected using - * the return key, GTK does not issue notification. The fix is - * to issue this notification when the return key is pressed. - */ - GdkEventKey keyEvent = new GdkEventKey (); - OS.memmove (keyEvent, event, GdkEventKey.sizeof); - int key = keyEvent.keyval; - switch (key) { - case OS.GDK_Return: - case OS.GDK_KP_Enter: { - postEvent (SWT.DefaultSelection); - break; - } - } - } - return result; -} - -int /*long*/ gtk_popup_menu (int /*long*/ widget) { - int /*long*/ result = super.gtk_popup_menu (widget); - /* - * Bug in GTK. The context menu for the typeahead in GtkTreeViewer - * opens in the bottom right corner of the screen when Shift+F10 - * is pressed and the typeahead window was not visible. The fix is - * to prevent the context menu from opening by stopping the default - * handler. - * - * NOTE: The bug only happens in GTK 2.6.5 and lower. - */ - return OS.GTK_VERSION < OS.VERSION (2, 6, 5) ? 1 : result; -} - -int /*long*/ gtk_row_activated (int /*long*/ tree, int /*long*/ path, int /*long*/ column) { - postEvent (SWT.DefaultSelection); - return 0; -} - -void hookEvents () { - super.hookEvents(); - int /*long*/ selection = OS.gtk_tree_view_get_selection(handle); - OS.g_signal_connect_closure (selection, OS.changed, display.closures [CHANGED], false); - OS.g_signal_connect_closure (handle, OS.row_activated, display.closures [ROW_ACTIVATED], false); -} - -/** - * 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(); - return indexOf (string, 0); -} - -/** - * 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); - String [] items = getItems (); - for (int i=start; i<items.length; i++) { - if (items [i].equals (string)) return i; - } - return -1; -} - -/** - * 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(); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - byte [] buffer = Converter.wcsToMbcs (null, Integer.toString (index), true); - int /*long*/ path = OS.gtk_tree_path_new_from_string (buffer); - boolean answer = OS.gtk_tree_selection_path_is_selected (selection, path); - OS.gtk_tree_path_free (path); - return answer; -} - -int /*long*/ paintWindow () { - OS.gtk_widget_realize (handle); - return OS.gtk_tree_view_get_bin_window (handle); -} - -void register () { - super.register (); - display.addWidget (OS.gtk_tree_view_get_selection (handle), this); -} - -void releaseWidget () { - super.releaseWidget (); - if (modelHandle != 0) OS.g_object_unref (modelHandle); - modelHandle = 0; -} - -/** - * 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 (!(0 <= index && index < OS.gtk_tree_model_iter_n_children (modelHandle, 0))) { - error (SWT.ERROR_INVALID_RANGE); - } - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_list_store_remove (modelHandle, iter); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_free (iter); -} - -/** - * 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 count = OS.gtk_tree_model_iter_n_children (modelHandle, 0); - if (!(0 <= start && start <= end && end < count)) { - error (SWT.ERROR_INVALID_RANGE); - } - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - for (int index=end; index>=start; index--) { - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - OS.gtk_list_store_remove (modelHandle, iter); - } - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_free (iter); -} - -/** - * 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); - int index = indexOf (string, 0); - if (index == -1) error (SWT.ERROR_INVALID_ARGUMENT); - remove (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 [] newIndices = new int [indices.length]; - System.arraycopy (indices, 0, newIndices, 0, indices.length); - sort (newIndices); - int start = newIndices [newIndices.length - 1], end = newIndices [0]; - int count = getItemCount(); - if (!(0 <= start && start <= end && end < count)) { - error (SWT.ERROR_INVALID_RANGE); - } - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - int last = -1; - for (int i=0; i<newIndices.length; i++) { - int index = newIndices [i]; - if (index != last) { - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - OS.gtk_list_store_remove (modelHandle, iter); - last = index; - } - } - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_free (iter); -} - -/** - * 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(); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_list_store_clear (modelHandle); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); -} - -/** - * 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 (!(0 <= index && index < OS.gtk_tree_model_iter_n_children (modelHandle, 0))) return; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - OS.gtk_tree_selection_select_iter (selection, iter); - if ((style & SWT.SINGLE) != 0) { - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter); - OS.gtk_tree_view_set_cursor (handle, path, 0, false); - OS.gtk_tree_path_free (path); - } - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_free (iter); -} - -/** - * 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 count = OS.gtk_tree_model_iter_n_children (modelHandle, 0); - if (count == 0 || start >= count) return; - start = Math.max (0, start); - end = Math.min (end, count - 1); - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - for (int index=start; index<=end; index++) { - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - OS.gtk_tree_selection_select_iter (selection, iter); - if ((style & SWT.SINGLE) != 0) { - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter); - OS.gtk_tree_view_set_cursor (handle, path, 0, false); - OS.gtk_tree_path_free (path); - } - } - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_free (iter); -} - -/** - * 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; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - int count = OS.gtk_tree_model_iter_n_children (modelHandle, 0); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - for (int i=0; i<length; i++) { - int index = indices [i]; - if (!(0 <= index && index < count)) continue; - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - OS.gtk_tree_selection_select_iter (selection, iter); - if ((style & SWT.SINGLE) != 0) { - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter); - OS.gtk_tree_view_set_cursor (handle, path, 0, false); - OS.gtk_tree_path_free (path); - } - } - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_free (iter); -} - -/** - * 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; - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_selection_select_all (selection); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); -} - -void selectFocusIndex (int index) { - /* - * Note that this method both selects and sets the focus to the - * specified index, so any previous selection in the list will be lost. - * gtk does not provide a way to just set focus to a specified list item. - */ - int count = OS.gtk_tree_model_iter_n_children (modelHandle, 0); - if (!(0 <= index && index < count)) return; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_view_set_cursor (handle, path, 0, false); - /* - * Bug in GTK. For some reason, when an event loop is run from - * within a key pressed handler and a dialog is displayed that - * contains a GtkTreeView, gtk_tree_view_set_cursor() does - * not set the cursor or select the item. The fix is to select the - * item with gtk_tree_selection_select_iter() as well. - * - * NOTE: This happens in GTK 2.2.1 and is fixed in GTK 2.2.4. - */ - OS.gtk_tree_selection_select_iter (selection, iter); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_path_free (path); - OS.g_free (iter); -} - -void setBackgroundColor (GdkColor color) { - super.setBackgroundColor (color); - OS.gtk_widget_modify_base (handle, 0, color); -} - -int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - int result = super.setBounds (x, y, width, height, move, resize); - /* - * Bug on GTK. The tree view sometimes does not get a paint - * event or resizes to a one pixel square when resized in a new - * shell that is not visible after any event loop has been run. The - * problem is intermittent. It doesn't seem to happen the first time - * a new shell is created. The fix is to ensure the tree view is realized - * after it has been resized. - */ - OS.gtk_widget_realize (handle); - /* - * Bug in GTK. An empty GtkTreeView fails to repaint the focus rectangle - * correctly when resized on versions before 2.6.0. The fix is to force - * the widget to redraw. - */ - if (OS.GTK_VERSION < OS.VERSION (2, 6, 0) && OS.gtk_tree_model_iter_n_children (modelHandle, 0) == 0) { - redraw (false); - } - return result; -} - -/** - * 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 (!(0 <= index && index < OS.gtk_tree_model_iter_n_children (modelHandle, 0))) { - error (SWT.ERROR_INVALID_RANGE); - } - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - byte [] buffer = Converter.wcsToMbcs (null, string, true); - OS.gtk_list_store_set (modelHandle, iter, TEXT_COLUMN, buffer, -1); - OS.g_free (iter); -} - -/** - * 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); - } - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_list_store_clear (modelHandle); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (iter == 0) error (SWT.ERROR_ITEM_NOT_ADDED); - for (int i=0; i<items.length; i++) { - String string = items [i]; - byte [] buffer = Converter.wcsToMbcs (null, string, true); - OS.gtk_list_store_append (modelHandle, iter); - OS.gtk_list_store_set (modelHandle, iter, TEXT_COLUMN, buffer, -1); - } - OS.g_free (iter); -} - -/** - * 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 (); - selectFocusIndex (index); - showSelection (); -} - -/** - * 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 (); - deselectAll (); - if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return; - int count = OS.gtk_tree_model_iter_n_children (modelHandle, 0); - if (count == 0 || start >= count) return; - start = Math.max (0, start); - end = Math.min (end, count - 1); - selectFocusIndex (start); - if ((style & SWT.MULTI) != 0) { - select (start, end); - } - showSelection (); -} - -/** - * 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; - selectFocusIndex (indices [0]); - if ((style & SWT.MULTI) != 0) { - select (indices); - } - showSelection (); -} - -/** - * 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); - deselectAll (); - int length = items.length; - if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return; - boolean first = true; - for (int i = 0; i < length; i++) { - int index = 0; - String string = items [i]; - if (string != null) { - while ((index = indexOf (string, index)) != -1) { - if ((style & SWT.MULTI) != 0) { - if (first) { - first = false; - selectFocusIndex (index); - } else { - select (index); - } - } else { - selectFocusIndex (index); - break; - } - index++; - } - } - } - 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(); - if (!(0 <= index && index < OS.gtk_tree_model_iter_n_children (modelHandle, 0))) return; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter); - OS.gtk_tree_view_scroll_to_cell (handle, path, 0, true, 0, 0); - if (OS.GTK_VERSION < OS.VERSION (2, 8, 0)) { - /* - * Bug in GTK. According to the documentation, gtk_tree_view_scroll_to_cell - * should vertically scroll the cell to the top if use_align is true and row_align is 0. - * However, prior to version 2.8 it does not scroll at all. The fix is to determine - * the new location and use gtk_tree_view_scroll_to_point. - * If the widget is a pinhead, calling gtk_tree_view_scroll_to_point - * will have no effect. Therefore, it is still neccessary to call - * gtk_tree_view_scroll_to_cell. - */ - OS.gtk_widget_realize (handle); - GdkRectangle cellRect = new GdkRectangle (); - OS.gtk_tree_view_get_cell_area (handle, path, 0, cellRect); - int[] tx = new int[1], ty = new int[1]; - OS.gtk_tree_view_widget_to_tree_coords(handle, cellRect.x, cellRect.y, tx, ty); - OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0]); - } - OS.gtk_tree_path_free (path); - OS.g_free (iter); -} - -/** - * 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 index = getSelectionIndex (); - if (index == -1) return; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter); - /* - * This code intentionally commented. - * Bug in GTK. According to the documentation, gtk_tree_view_scroll_to_cell - * should scroll the minimum amount to show the cell if use_align is false. - * However, what actually happens is the cell is scrolled to the top. - * The fix is to determine the new location and use gtk_tree_view_scroll_to_point. - * If the widget is a pinhead, calling gtk_tree_view_scroll_to_point - * will have no effect. Therefore, it is still neccessary to - * call gtk_tree_view_scroll_to_cell. - */ -// OS.gtk_tree_view_scroll_to_cell (handle, path, 0, false, 0, 0); - OS.gtk_widget_realize (handle); - GdkRectangle visibleRect = new GdkRectangle (); - OS.gtk_tree_view_get_visible_rect (handle, visibleRect); - GdkRectangle cellRect = new GdkRectangle (); - OS.gtk_tree_view_get_cell_area (handle, path, 0, cellRect); - int[] tx = new int[1], ty = new int[1]; - OS.gtk_tree_view_widget_to_tree_coords(handle, cellRect.x, cellRect.y, tx, ty); - if (ty[0] < visibleRect.y ) { - OS.gtk_tree_view_scroll_to_cell (handle, path, 0, true, 0f, 0f); - OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0]); - } else { - int height = Math.min (visibleRect.height, cellRect.height); - if (ty[0] + height > visibleRect.y + visibleRect.height) { - OS.gtk_tree_view_scroll_to_cell (handle, path, 0, true, 1f, 0f); - ty[0] += cellRect.height - visibleRect.height; - OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0]); - } - } - OS.gtk_tree_path_free (path); - OS.g_free (iter); -} - -int /*long*/ treeSelectionProc (int /*long*/ model, int /*long*/ path, int /*long*/ iter, int[] selection, int length) { - if (selection != null) { - int /*long*/ indices = OS.gtk_tree_path_get_indices (path); - if (indices != 0) { - int [] index = new int [1]; - OS.memmove (index, indices, 4); - selection [length] = index [0]; - } - } - return 0; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java deleted file mode 100644 index 5e042a67b5..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java +++ /dev/null @@ -1,981 +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.gtk.*; -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 { - int x, y; - boolean hasLocation; - MenuItem cascade, selectedItem; - Decorations parent; - int /*long*/ imItem, imSeparator, imHandle; - ImageList imageList; - -/** - * 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); -} - -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; -} - -static int checkStyle (int style) { - return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0); -} - -void _setVisible (boolean visible) { - if (visible == OS.GTK_WIDGET_MAPPED (handle)) return; - if (visible) { - sendEvent (SWT.Show); - if (getItemCount () != 0) { - if ((OS.GTK_VERSION >= OS.VERSION (2, 8, 0))) { - /* - * Feature in GTK. ON_TOP shells will send out - * SWT.Deactivate whenever a context menu is shown. - * The fix is to prevent the menu from taking focus - * when it is being shown in an ON_TOP shell. - */ - if ((parent._getShell ().style & SWT.ON_TOP) != 0) { - OS.gtk_menu_shell_set_take_focus (handle, false); - } - } - int /*long*/ address = hasLocation ? display.menuPositionProc: 0; - /* - * Bug in GTK. The timestamp passed into gtk_menu_popup is used - * to perform an X pointer grab. It cannot be zero, else the grab - * will fail. The fix is to ensure that the timestamp of the last - * event processed is used. - */ - OS.gtk_menu_popup (handle, 0, 0, address, 0, 0, display.getLastEventTime ()); - } else { - sendEvent (SWT.Hide); - } - } else { - OS.gtk_menu_popdown (handle); - } -} - -void addAccelerators (int /*long*/ accelGroup) { - MenuItem [] items = getItems (); - for (int i = 0; i < items.length; i++) { - MenuItem item = items[i]; - item.addAccelerators (accelGroup); - } -} - -/** - * 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); -} - -/** - * 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); -} - -void createHandle (int index) { - state |= HANDLE; - if ((style & SWT.BAR) != 0) { - handle = OS.gtk_menu_bar_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ vboxHandle = parent.vboxHandle; - OS.gtk_container_add (vboxHandle, handle); - OS.gtk_box_set_child_packing (vboxHandle, handle, false, true, 0, OS.GTK_PACK_START); - } else { - handle = OS.gtk_menu_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - } -} - -void createIMMenu (int /*long*/ imHandle) { - if (this.imHandle == imHandle) return; - this.imHandle = imHandle; - if (imHandle == 0) { - if (imItem != 0) { - OS.gtk_widget_destroy (imItem); - imItem = 0; - } - if (imSeparator != 0) { - OS.gtk_widget_destroy (imSeparator); - imSeparator = 0; - } - return; - } - if (imSeparator == 0) { - imSeparator = OS.gtk_separator_menu_item_new (); - OS.gtk_widget_show (imSeparator); - OS.gtk_menu_shell_insert (handle, imSeparator, -1); - } - if (imItem == 0) { - byte[] buffer = Converter.wcsToMbcs (null, SWT.getMessage("SWT_InputMethods"), true); - imItem = OS.gtk_image_menu_item_new_with_label (buffer); - OS.gtk_widget_show (imItem); - OS.gtk_menu_shell_insert (handle, imItem, -1); - } - int /*long*/ imSubmenu = OS.gtk_menu_new (); - OS.gtk_im_multicontext_append_menuitems (imHandle, imSubmenu); - OS.gtk_menu_item_set_submenu (imItem, imSubmenu); -} - -void createWidget (int index) { - checkOrientation (parent); - super.createWidget (index); - parent.addMenu (this); -} - -void fixMenus (Decorations newParent) { - MenuItem [] items = getItems (); - for (int i=0; i<items.length; i++) { - items [i].fixMenus (newParent); - } - parent.removeMenu (this); - newParent.addMenu (this); - this.parent = newParent; -} - -/*public*/ Rectangle getBounds () { - checkWidget(); - if (!OS.GTK_WIDGET_MAPPED (handle)) { - return new Rectangle (0, 0, 0, 0); - } - int /*long*/ window = OS.GTK_WIDGET_WINDOW (handle); - int [] origin_x = new int [1], origin_y = new int [1]; - OS.gdk_window_get_origin (window, origin_x, origin_y); - int x = origin_x [0] + OS.GTK_WIDGET_X (handle); - int y = origin_y [0] + OS.GTK_WIDGET_Y (handle); - int width = OS.GTK_WIDGET_WIDTH (handle); - int height = OS.GTK_WIDGET_HEIGHT (handle); - return new Rectangle (x, y, width, height); -} - -/** - * 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 null; -} - -/** - * 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(); - return OS.GTK_WIDGET_SENSITIVE (handle); -} - -/** - * 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 /*long*/ list = OS.gtk_container_get_children (handle); - if (list == 0) error (SWT.ERROR_CANNOT_GET_ITEM); - int count = OS.g_list_length (list); - if (imSeparator != 0) count--; - if (imItem != 0) count--; - if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE); - int /*long*/ data = OS.g_list_nth_data (list, index); - OS.g_list_free (list); - if (data == 0) error (SWT.ERROR_CANNOT_GET_ITEM); - return (MenuItem) display.getWidget (data); -} - -/** - * 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 /*long*/ list = OS.gtk_container_get_children (handle); - if (list == 0) return 0; - int count = OS.g_list_length (list); - OS.g_list_free (list); - if (imSeparator != 0) count--; - if (imItem != 0) 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 /*long*/ list = OS.gtk_container_get_children (handle); - if (list == 0) return new MenuItem [0]; - int count = OS.g_list_length (list); - if (imSeparator != 0) count--; - if (imItem != 0) count--; - MenuItem [] items = new MenuItem [count]; - int index = 0; - for (int i=0; i<count; i++) { - int /*long*/ data = OS.g_list_nth_data (list, i); - MenuItem item = (MenuItem) display.getWidget (data); - if (item != null) items [index++] = item; - } - OS.g_list_free (list); - if (index != items.length) { - MenuItem [] newItems = new MenuItem[index]; - System.arraycopy(items, 0, newItems, 0, index); - items = newItems; - } - return items; -} - -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 null; - return cascade.getParent (); -} - -/** - * 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.GTK_WIDGET_MAPPED (handle); -} - -int /*long*/ gtk_hide (int /*long*/ widget) { - if ((style & SWT.POP_UP) != 0) { - if (display.activeShell != null) display.activeShell = getShell (); - } - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) { - sendEvent (SWT.Hide); - } else { - /* - * Bug in GTK. In GTK 2.4 and earlier - * a crash could occur if a menu item - * was disposed within gtk_hide. The - * workaroud is to post the event instead - * of send it on these platforms - */ - postEvent (SWT.Hide); - } - return 0; -} - -int /*long*/ gtk_show (int /*long*/ widget) { - if ((style & SWT.POP_UP) != 0) { - if (display.activeShell != null) display.activeShell = getShell (); - return 0; - } - sendEvent (SWT.Show); - return 0; -} - - -int /*long*/ gtk_show_help (int /*long*/ widget, int /*long*/ helpType) { - if (sendHelpEvent (helpType)) { - OS.gtk_menu_shell_deactivate (handle); - return 1; - } - return 0; -} - -void hookEvents () { - super.hookEvents (); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [SHOW], 0, display.closures [SHOW], false); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [HIDE], 0, display.closures [HIDE], false); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [SHOW_HELP], 0, display.closures [SHOW_HELP], false); -} - -/** - * 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(); - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - MenuItem [] items = getItems (); - for (int i=0; i<items.length; i++) { - if (items [i] == item) return i; - } - 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 (); -} - -int /*long*/ menuPositionProc (int /*long*/ menu, int /*long*/ x, int /*long*/ y, int /*long*/ push_in, int /*long*/ user_data) { - /* - * Feature in GTK. The menu position function sets the position of the - * top-left pixel of the menu. If the menu would be off-screen, GTK will - * add a scroll arrow at the bottom and position the first menu entry at - * the specified position. The fix is to flip the menu location to be - * completely inside the screen. - * - * NOTE: This code doesn't work for multiple monitors. - */ - GtkRequisition requisition = new GtkRequisition (); - OS.gtk_widget_size_request (menu, requisition); - int screenHeight = OS.gdk_screen_height (); - int reqy = this.y; - if (reqy + requisition.height > screenHeight) { - reqy = Math.max (0, reqy - requisition.height); - } - int screenWidth = OS.gdk_screen_width (); - int reqx = this.x; - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - if (reqx - requisition.width >= 0) reqx -= requisition.width; - } else { - if (reqx + requisition.width > screenWidth) reqx -= requisition.width; - } - if (x != 0) OS.memmove (x, new int [] {reqx}, 4); - if (y != 0) OS.memmove (y, new int [] {reqy}, 4); - if (push_in != 0) OS.memmove (push_in, new int [] {1}, 4); - return 0; -} - -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); - } else { - if ((style & SWT.POP_UP) != 0) { - display.removePopup (this); - } - } -} - -void releaseWidget () { - super.releaseWidget (); - if (parent != null) parent.removeMenu (this); - parent = null; - cascade = null; - imItem = imSeparator = imHandle = 0; - if (imageList != null) imageList.dispose (); - imageList = null; -} - -/** - * 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 removeAccelerators (int /*long*/ accelGroup) { - MenuItem [] items = getItems (); - for (int i = 0; i < items.length; i++) { - MenuItem item = items[i]; - item.removeAccelerators (accelGroup); - } -} - -/** - * 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); -} - -boolean sendHelpEvent (int /*long*/ helpType) { - if (selectedItem != null && !selectedItem.isDisposed()) { - if (selectedItem.hooks (SWT.Help)) { - selectedItem.postEvent (SWT.Help); - return true; - } - } - if (hooks (SWT.Help)) { - postEvent (SWT.Help); - return true; - } - return parent.sendHelpEvent (helpType); -} - -/** - * 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(); -} - -/** - * 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(); - if (enabled) { - OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_SENSITIVE); - } else { - OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_SENSITIVE); - } -} - -/** - * 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; - this.x = x; - this.y = y; - 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); -} - -void setOrientation() { - if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) { - if (handle != 0) OS.gtk_widget_set_direction (handle, OS.GTK_TEXT_DIR_RTL); - } -} - -/** - * 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); - } -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java deleted file mode 100644 index d676e46e4a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MenuItem.java +++ /dev/null @@ -1,883 +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.gtk.*; -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 { - Menu parent, menu; - int /*long*/ groupHandle; - int accelerator; - -/** - * 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 (parent.getItemCount ()); -} - -/** - * 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; - int count = parent.getItemCount (); - if (!(0 <= index && index <= count)) { - error (SWT.ERROR_INVALID_RANGE); - } - createWidget (index); -} - -void addAccelerator (int /*long*/ accelGroup) { - updateAccelerator (accelGroup, true); -} - -void addAccelerators (int /*long*/ accelGroup) { - addAccelerator (accelGroup); - if (menu != null) menu.addAccelerators (accelGroup); -} - -/** - * 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) { - state |= HANDLE; - byte [] buffer = new byte [1]; - int bits = SWT.CHECK | SWT.RADIO | SWT.PUSH | SWT.SEPARATOR; - switch (style & bits) { - case SWT.SEPARATOR: - handle = OS.gtk_separator_menu_item_new (); - break; - case SWT.RADIO: - /* - * Feature in GTK. In GTK, radio button must always be part of - * a radio button group. In a GTK radio group, one button is always - * selected. This means that it is not possible to have a single - * radio button that is unselected. This is necessary to allow - * applications to implement their own radio behavior or use radio - * buttons outside of radio groups. The fix is to create a hidden - * radio button for each radio button we create and add them - * to the same group. This allows the visible button to be - * unselected. - */ - groupHandle = OS.gtk_radio_menu_item_new (0); - if (groupHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.g_object_ref (groupHandle); - OS.gtk_object_sink (groupHandle); - int /*long*/ group = OS.gtk_radio_menu_item_get_group (groupHandle); - handle = OS.gtk_radio_menu_item_new_with_label (group, buffer); - break; - case SWT.CHECK: - handle = OS.gtk_check_menu_item_new_with_label (buffer); - break; - case SWT.PUSH: - default: - handle = OS.gtk_image_menu_item_new_with_label (buffer); - break; - } - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - if ((style & SWT.SEPARATOR) == 0) { - int /*long*/ label = OS.gtk_bin_get_child (handle); - OS.gtk_accel_label_set_accel_widget (label, 0); - } - int /*long*/ parentHandle = parent.handle; - boolean enabled = OS.GTK_WIDGET_SENSITIVE (parentHandle); - if (!enabled) OS.GTK_WIDGET_SET_FLAGS (parentHandle, OS.GTK_SENSITIVE); - OS.gtk_menu_shell_insert (parentHandle, handle, index); - if (!enabled) OS.GTK_WIDGET_UNSET_FLAGS (parentHandle, OS.GTK_SENSITIVE); - OS.gtk_widget_show (handle); -} - -void fixMenus (Decorations newParent) { - if (menu != null) menu.fixMenus (newParent); -} - -/** - * 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; -} - -int /*long*/ getAccelGroup () { - Menu menu = parent; - while (menu != null && menu.cascade != null) { - menu = menu.cascade.parent; - } - if (menu == null) return 0; - Decorations shell = menu.parent; - return shell.menuBar == menu ? shell.accelGroup : 0; -} - -/*public*/ Rectangle getBounds () { - checkWidget(); - if (!OS.GTK_WIDGET_MAPPED (handle)) { - return new Rectangle (0, 0, 0, 0); - } - int x = OS.GTK_WIDGET_X (handle); - int y = OS.GTK_WIDGET_Y (handle); - int width = OS.GTK_WIDGET_WIDTH (handle); - int height = OS.GTK_WIDGET_HEIGHT (handle); - return new Rectangle (x, y, width, height); -} - -/** - * 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(); - return OS.GTK_WIDGET_SENSITIVE (handle); -} - -/** - * 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; - return OS.gtk_check_menu_item_get_active(handle); -} - -int /*long*/ gtk_activate (int /*long*/ widget) { - if ((style & SWT.CASCADE) != 0 && menu != null) return 0; - /* - * Bug in GTK. When an ancestor menu is disabled and - * the user types an accelerator key, GTK delivers the - * the activate signal even though the menu item cannot - * be invoked using the mouse. The fix is to ignore - * activate signals when an ancestor menu is disabled. - */ - if (!isEnabled ()) return 0; - Event event = new Event (); - int /*long*/ ptr = OS.gtk_get_current_event (); - if (ptr != 0) { - GdkEvent gdkEvent = new GdkEvent (); - OS.memmove (gdkEvent, ptr, GdkEvent.sizeof); - switch (gdkEvent.type) { - case OS.GDK_KEY_PRESS: - case OS.GDK_KEY_RELEASE: - case OS.GDK_BUTTON_PRESS: - case OS.GDK_2BUTTON_PRESS: - case OS.GDK_BUTTON_RELEASE: { - int [] state = new int [1]; - OS.gdk_event_get_state (ptr, state); - setInputState (event, state [0]); - break; - } - } - OS.gdk_event_free (ptr); - } - if ((style & SWT.RADIO) != 0) { - if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) { - selectRadio (); - } - } - postEvent (SWT.Selection, event); - return 0; -} - -int /*long*/ gtk_select (int /*long*/ item) { - parent.selectedItem = this; - sendEvent (SWT.Arm); - return 0; -} - -int /*long*/ gtk_show_help (int /*long*/ widget, int /*long*/ helpType) { - boolean handled = hooks (SWT.Help); - if (handled) { - postEvent (SWT.Help); - } else { - handled = parent.sendHelpEvent (helpType); - } - if (handled) { - OS.gtk_menu_shell_deactivate (parent.handle); - return 1; - } - return 0; -} - -void hookEvents () { - super.hookEvents (); - OS.g_signal_connect_closure (handle, OS.activate, display.closures [ACTIVATE], false); - OS.g_signal_connect_closure (handle, OS.select, display.closures [SELECT], false); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [SHOW_HELP], 0, display.closures [SHOW_HELP], false); -} - -/** - * 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 (); -} - -void releaseChildren (boolean destroy) { - if (menu != null) { - menu.release (false); - menu = null; - } - super.releaseChildren (destroy); -} - -void releaseParent () { - super.releaseParent (); - if (menu != null) { - if (menu.selectedItem == this) menu.selectedItem = null; - menu.dispose (); - } - menu = null; -} - -void releaseWidget () { - super.releaseWidget (); - int /*long*/ accelGroup = getAccelGroup (); - if (accelGroup != 0) removeAccelerator (accelGroup); - if (groupHandle != 0) OS.g_object_unref (groupHandle); - groupHandle = 0; - accelerator = 0; - parent = null; -} - -void removeAccelerator (int /*long*/ accelGroup) { - updateAccelerator (accelGroup, false); -} - -void removeAccelerators (int /*long*/ accelGroup) { - removeAccelerator (accelGroup); - if (menu != null) menu.removeAccelerators (accelGroup); -} - -/** - * 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; - int /*long*/ accelGroup = getAccelGroup (); - if (accelGroup != 0) removeAccelerator (accelGroup); - this.accelerator = accelerator; - if (accelGroup != 0) addAccelerator (accelGroup); -} - -/** - * 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 (OS.GTK_WIDGET_SENSITIVE (handle) == enabled) return; - int /*long*/ accelGroup = getAccelGroup (); - if (accelGroup != 0) removeAccelerator (accelGroup); - OS.gtk_widget_set_sensitive (handle, enabled); - if (accelGroup != 0) addAccelerator (accelGroup); -} - -/** - * Sets the image the receiver will display to the argument. - * <p> - * Note: This operation is a hint and is not supported on - * platforms that do not have this concept (for example, Windows NT). - * Furthermore, some platforms (such as GTK), cannot display both - * a check box and an image at the same time. Instead, they hide - * the image and display the check box. - * </p> - * - * @param image the image 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 setImage (Image image) { - checkWidget(); - if ((style & SWT.SEPARATOR) != 0) return; - super.setImage (image); - if (!OS.GTK_IS_IMAGE_MENU_ITEM (handle)) return; - if (image != null) { - ImageList imageList = parent.imageList; - if (imageList == null) imageList = parent.imageList = new ImageList (); - int imageIndex = imageList.indexOf (image); - if (imageIndex == -1) { - imageIndex = imageList.add (image); - } else { - imageList.put (imageIndex, image); - } - int /*long*/ pixbuf = imageList.getPixbuf (imageIndex); - int /*long*/ imageHandle = OS.gtk_image_new_from_pixbuf (pixbuf); - OS.gtk_image_menu_item_set_image (handle, imageHandle); - OS.gtk_widget_show (imageHandle); - } else { - OS.gtk_image_menu_item_set_image (handle, 0); - } -} - -/** - * 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.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; - int /*long*/ accelGroup = getAccelGroup (); - if (accelGroup != 0) removeAccelerators (accelGroup); - if (oldMenu != null) { - oldMenu.cascade = null; - /* - * Add a reference to the menu we are about - * to replace or GTK will destroy it. - */ - OS.g_object_ref (oldMenu.handle); - OS.gtk_menu_item_remove_submenu (handle); - } - if ((this.menu = menu) != null) { - menu.cascade = this; - OS.gtk_menu_item_set_submenu (handle, menu.handle); - } - if (accelGroup != 0) addAccelerators (accelGroup); -} - -void setOrientation() { - if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) { - if (handle != 0) { - OS.gtk_widget_set_direction (handle, OS.GTK_TEXT_DIR_RTL); - OS.gtk_container_forall (handle, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL); - } - } -} - -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; - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, ACTIVATE); - OS.gtk_check_menu_item_set_active (handle, selected); - if ((style & SWT.RADIO) != 0) OS.gtk_check_menu_item_set_active (groupHandle, !selected); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, ACTIVATE); -} - -/** - * 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); - if ((style & SWT.SEPARATOR) != 0) return; - if (text.equals (string)) return; - super.setText (string); - String accelString = ""; - int index = string.indexOf ('\t'); - if (index != -1) { - boolean isRTL = (parent.style & SWT.RIGHT_TO_LEFT) != 0; - accelString = (isRTL? "" : " ") + string.substring (index+1, string.length()) + (isRTL? " " : ""); - string = string.substring (0, index); - } - char [] chars = fixMnemonic (string); - byte [] buffer = Converter.wcsToMbcs (null, chars, true); - int /*long*/ label = OS.gtk_bin_get_child (handle); - OS.gtk_label_set_text_with_mnemonic (label, buffer); - buffer = Converter.wcsToMbcs (null, accelString, true); - int /*long*/ ptr = OS.g_malloc (buffer.length); - OS.memmove (ptr, buffer, buffer.length); - int /*long*/ oldPtr = OS.GTK_ACCEL_LABEL_GET_ACCEL_STRING (label); - OS.GTK_ACCEL_LABEL_SET_ACCEL_STRING (label, ptr); - if (oldPtr != 0) OS.g_free (oldPtr); -} - -void updateAccelerator (int /*long*/ accelGroup, boolean add) { - if (accelerator == 0 || !getEnabled ()) return; - if ((accelerator & SWT.COMMAND) != 0) return; - int mask = 0; - if ((accelerator & SWT.ALT) != 0) mask |= OS.GDK_MOD1_MASK; - if ((accelerator & SWT.SHIFT) != 0) mask |= OS.GDK_SHIFT_MASK; - if ((accelerator & SWT.CONTROL) != 0) mask |= OS.GDK_CONTROL_MASK; - int keysym = accelerator & SWT.KEY_MASK; - int newKey = Display.untranslateKey (keysym); - if (newKey != 0) { - keysym = newKey; - } else { - switch (keysym) { - case '\r': keysym = OS.GDK_Return; break; - default: keysym = Display.wcsToMbcs ((char) keysym); - } - } - /* When accel_key is zero, it causes GTK warnings */ - if (keysym != 0) { - if (add) { - OS.gtk_widget_add_accelerator (handle, OS.activate, accelGroup, keysym, mask, OS.GTK_ACCEL_VISIBLE); - } else { - OS.gtk_widget_remove_accelerator (handle, accelGroup, keysym, mask); - } - } -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MessageBox.java deleted file mode 100644 index 3d1cfd10e4..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/MessageBox.java +++ /dev/null @@ -1,238 +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.gtk.*; - -/** - * 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 { - - String message = ""; - int /*long*/ handle; -/** - * 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 (); -} - -/** - * 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; -} - -/** - * 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; -} - -/** - * 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 () { - int /*long*/ parentHandle = (parent != null) ? parent.topHandle() : 0; - int dialogFlags = OS.GTK_DIALOG_DESTROY_WITH_PARENT; - if ((style & (SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) != 0) { - dialogFlags |= OS.GTK_DIALOG_MODAL; - } - int messageType = OS.GTK_MESSAGE_INFO; - if ((style & (SWT.ICON_WARNING)) != 0) messageType = OS.GTK_MESSAGE_WARNING; - if ((style & (SWT.ICON_QUESTION)) != 0) messageType = OS.GTK_MESSAGE_QUESTION; - if ((style & (SWT.ICON_ERROR)) != 0) messageType = OS.GTK_MESSAGE_ERROR; - - byte [] buffer = Converter.wcsToMbcs (null, fixPercent (message), true); - handle = OS.gtk_message_dialog_new(parentHandle, dialogFlags, messageType, 0, buffer); - if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); - if (parentHandle != 0) { - int /*long*/ pixbufs = OS.gtk_window_get_icon_list (parentHandle); - if (pixbufs != 0) { - OS.gtk_window_set_icon_list (handle, pixbufs); - OS.g_list_free (pixbufs); - } - } - Display display = parent != null ? parent.getDisplay (): Display.getCurrent (); - createButtons (display.getDismissalAlignment ()); - buffer = Converter.wcsToMbcs(null, title, true); - OS.gtk_window_set_title(handle,buffer); - display.addIdleProc (); - Dialog oldModal = null; - if (OS.gtk_window_get_modal (handle)) { - oldModal = display.getModalDialog (); - display.setModalDialog (this); - } - int signalId = 0; - int /*long*/ hookId = 0; - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - signalId = OS.g_signal_lookup (OS.map, OS.GTK_TYPE_WIDGET()); - hookId = OS.g_signal_add_emission_hook (signalId, 0, display.emissionProc, handle, 0); - } - int response = OS.gtk_dialog_run (handle); - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - OS.g_signal_remove_emission_hook (signalId, hookId); - } - if (OS.gtk_window_get_modal (handle)) { - display.setModalDialog (oldModal); - } - display.removeIdleProc (); - OS.gtk_widget_destroy (handle); - return response; -} - -private void createButtons (int alignment) { - if (alignment == SWT.LEFT) { - if ((style & SWT.OK) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, "gtk-ok", true), SWT.OK); - if ((style & SWT.ABORT) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, SWT.getMessage("SWT_Abort"), true), SWT.ABORT); - if ((style & SWT.RETRY) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, SWT.getMessage("SWT_Retry"), true), SWT.RETRY); - if ((style & SWT.YES) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, "gtk-yes", true), SWT.YES); - if ((style & SWT.NO) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, "gtk-no", true), SWT.NO); - if ((style & SWT.IGNORE) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, SWT.getMessage("SWT_Ignore"), true), SWT.IGNORE); - if ((style & SWT.CANCEL) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, "gtk-cancel", true), SWT.CANCEL); - } else { - if ((style & SWT.CANCEL) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, "gtk-cancel", true), SWT.CANCEL); - if ((style & SWT.OK) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, "gtk-ok", true), SWT.OK); - if ((style & SWT.NO) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, "gtk-no", true), SWT.NO); - if ((style & SWT.YES) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, "gtk-yes", true), SWT.YES); - if ((style & SWT.IGNORE) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, SWT.getMessage("SWT_Ignore"), true), SWT.IGNORE); - if ((style & SWT.RETRY) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, SWT.getMessage("SWT_Retry"), true), SWT.RETRY); - if ((style & SWT.ABORT) != 0) OS.gtk_dialog_add_button(handle, Converter.wcsToMbcs (null, SWT.getMessage("SWT_Abort"), true), SWT.ABORT); - } -} - -private 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; -} - -char[] fixPercent (String string) { - int length = string.length (); - char [] text = new char [length]; - string.getChars (0, length, text, 0); - int i = 0, j = 0; - char [] result = new char [length * 2]; - while (i < length) { - switch (text [i]) { - case '%': - result [j++] = '%'; - break; - } - result [j++] = text [i++]; - } - return result; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ProgressBar.java deleted file mode 100644 index 34f3886d1f..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ProgressBar.java +++ /dev/null @@ -1,302 +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.gtk.*; - -/** - * 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, minimum = 0, maximum = 100, selection = 0; - static final int DELAY = 100; - -/** - * 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) { - super (parent, checkStyle(style)); -} - -static int checkStyle (int style) { - style |= SWT.NO_FOCUS; - return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0); -} - -void createHandle (int index) { - state |= HANDLE; - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - handle = OS.gtk_progress_bar_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (fixedHandle, handle); - int orientation = (style & SWT.VERTICAL) != 0 ? OS.GTK_PROGRESS_BOTTOM_TO_TOP : OS.GTK_PROGRESS_LEFT_TO_RIGHT; - OS.gtk_progress_bar_set_orientation (handle, orientation); - if ((style & SWT.INDETERMINATE) != 0) { - timerId = OS.gtk_timeout_add (DELAY, display.windowTimerProc, handle); - } -} - -/** - * 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 (); - return maximum; -} - -/** - * 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 (); - return minimum; -} - -/** - * 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 (); - return selection; -} - -/** - * 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; -} - -int /*long*/ gtk_realize (int /*long*/ widget) { - int /*long*/ result = super.gtk_realize (widget); - if (result != 0) return result; - /* - * Bug in GTK. When a progress bar has been unrealized after being - * realized at least once, gtk_progress_bar_set_fraction() GP's. The - * fix is to update the progress bar state only when realized and restore - * the state when the progress bar becomes realized. - */ - updateBar (selection, minimum, maximum); - return 0; -} - -void releaseWidget () { - super.releaseWidget (); - if (timerId != 0) OS.gtk_timeout_remove (timerId); - timerId = 0; -} - -void setParentBackground () { - /* - * Bug in GTK. For some reason, some theme managers will crash - * when the progress bar is inheriting the background from a parent. - * The fix is to stop inheriting the background. This is acceptable - * since progress bars do not use the inherited background. - */ -} - -/** - * 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 <= minimum) return; - maximum = value; - selection = Math.min (selection, maximum); - updateBar (selection, minimum, maximum); -} - -/** - * 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 || value >= maximum) return; - minimum = value; - selection = Math.max (selection, minimum); - updateBar (selection, minimum, maximum); -} - -/** - * 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 (); - selection = Math.max (minimum, Math.min (maximum, value)); - updateBar (selection, minimum, maximum); -} - -/** - * 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 -} - -int /*long*/ timerProc (int /*long*/ widget) { - if (isVisible ()) OS.gtk_progress_bar_pulse (handle); - return 1; -} - -void updateBar (int selection, int minimum, int maximum) { - /* - * Bug in GTK. When a progress bar has been unrealized after being - * realized at least once, gtk_progress_bar_set_fraction() GP's. The - * fix is to update the progress bar state only when realized and restore - * the state when the progress bar becomes realized. - */ - if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_REALIZED) == 0) return; - - double fraction = minimum == maximum ? 1 : (double)(selection - minimum) / (maximum - minimum); - OS.gtk_progress_bar_set_fraction (handle, fraction); - /* - * Feature in GTK. The progress bar does - * not redraw right away when a value is - * changed. This is not strictly incorrect - * but unexpected. The fix is to force all - * outstanding redraws to be delivered. - */ - int /*long*/ window = paintWindow (); - OS.gdk_window_process_updates (window, false); - OS.gdk_flush (); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java deleted file mode 100644 index 4c5d29ce0a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Sash.java +++ /dev/null @@ -1,441 +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.gtk.*; -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 /*long*/ defaultCursor; - - 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 (); - if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; - if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; - 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 |= HANDLE | THEME_BACKGROUND; - handle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (handle, true); - OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS); - int type = (style & SWT.VERTICAL) != 0 ? OS.GDK_SB_H_DOUBLE_ARROW : OS.GDK_SB_V_DOUBLE_ARROW; - defaultCursor = OS.gdk_cursor_new (type); -} - -void drawBand (int x, int y, int width, int height) { - if ((style & SWT.SMOOTH) != 0) return; - int /*long*/ window = OS.GTK_WIDGET_WINDOW (parent.paintHandle()); - if (window == 0) return; - byte [] bits = {-86, 85, -86, 85, -86, 85, -86, 85}; - int /*long*/ stipplePixmap = OS.gdk_bitmap_create_from_data (window, bits, 8, 8); - int /*long*/ gc = OS.gdk_gc_new (window); - int /*long*/ colormap = OS.gdk_colormap_get_system(); - GdkColor color = new GdkColor (); - OS.gdk_color_white (colormap, color); - OS.gdk_gc_set_foreground (gc, color); - OS.gdk_gc_set_stipple (gc, stipplePixmap); - OS.gdk_gc_set_subwindow (gc, OS.GDK_INCLUDE_INFERIORS); - OS.gdk_gc_set_fill (gc, OS.GDK_STIPPLED); - OS.gdk_gc_set_function (gc, OS.GDK_XOR); - OS.gdk_draw_rectangle (window, gc, 1, x, y, width, height); - OS.g_object_unref (stipplePixmap); - OS.g_object_unref (gc); -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ eventPtr) { - int /*long*/ result = super.gtk_button_press_event (widget, eventPtr); - if (result != 0) return result; - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, eventPtr, GdkEventButton.sizeof); - int button = gdkEvent.button; - if (button != 1) return 0; - if (gdkEvent.type == OS.GDK_2BUTTON_PRESS) return 0; - if (gdkEvent.type == OS.GDK_3BUTTON_PRESS) return 0; - int /*long*/ window = OS.GTK_WIDGET_WINDOW (widget); - int [] origin_x = new int [1], origin_y = new int [1]; - OS.gdk_window_get_origin (window, origin_x, origin_y); - startX = (int) (gdkEvent.x_root - origin_x [0]); - startY = (int) (gdkEvent.y_root - origin_y [0]); - int x = OS.GTK_WIDGET_X (handle); - int y = OS.GTK_WIDGET_Y (handle); - int width = OS.GTK_WIDGET_WIDTH (handle); - int height = OS.GTK_WIDGET_HEIGHT (handle); - lastX = x; - lastY = y; - Event event = new Event (); - event.time = gdkEvent.time; - event.x = lastX; - event.y = lastY; - event.width = width; - event.height = height; - if ((style & SWT.SMOOTH) == 0) { - event.detail = SWT.DRAG; - } - if ((parent.style & SWT.MIRRORED) != 0) event.x = parent.getClientWidth () - width - event.x; - sendEvent (SWT.Selection, event); - if (isDisposed ()) return 0; - if (event.doit) { - dragging = true; - lastX = event.x; - lastY = event.y; - if ((parent.style & SWT.MIRRORED) != 0) lastX = parent.getClientWidth () - width - lastX; - parent.update (true, (style & SWT.SMOOTH) == 0); - drawBand (lastX, 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 /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ eventPtr) { - int /*long*/ result = super.gtk_button_release_event (widget, eventPtr); - if (result != 0) return result; - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, eventPtr, GdkEventButton.sizeof); - int button = gdkEvent.button; - if (button != 1) return 0; - if (!dragging) return 0; - dragging = false; - int width = OS.GTK_WIDGET_WIDTH (handle); - int height = OS.GTK_WIDGET_HEIGHT (handle); - Event event = new Event (); - event.time = gdkEvent.time; - event.x = lastX; - event.y = lastY; - event.width = width; - event.height = height; - drawBand (lastX, lastY, width, height); - if ((parent.style & SWT.MIRRORED) != 0) event.x = parent.getClientWidth () - width - event.x; - 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 /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_focus_in_event (widget, event); - if (result != 0) return result; - // widget could be disposed at this point - if (handle != 0) { - lastX = OS.GTK_WIDGET_X (handle); - lastY = OS.GTK_WIDGET_Y (handle); - } - return 0; -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ eventPtr) { - int /*long*/ result = super.gtk_key_press_event (widget, eventPtr); - if (result != 0) return result; - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof); - int keyval = gdkEvent.keyval; - switch (keyval) { - case OS.GDK_Left: - case OS.GDK_Right: - case OS.GDK_Up: - case OS.GDK_Down: - int xChange = 0, yChange = 0; - int stepSize = PAGE_INCREMENT; - if ((gdkEvent.state & OS.GDK_CONTROL_MASK) != 0) stepSize = INCREMENT; - if ((style & SWT.VERTICAL) != 0) { - if (keyval == OS.GDK_Up || keyval == OS.GDK_Down) break; - xChange = keyval == OS.GDK_Left ? -stepSize : stepSize; - } else { - if (keyval == OS.GDK_Left ||keyval == OS.GDK_Right) break; - yChange = keyval == OS.GDK_Up ? -stepSize : stepSize; - } - - int width = OS.GTK_WIDGET_WIDTH (handle); - int height = OS.GTK_WIDGET_HEIGHT (handle); - int parentBorder = 0; - int parentWidth = OS.GTK_WIDGET_WIDTH (parent.handle); - int parentHeight = OS.GTK_WIDGET_HEIGHT (parent.handle); - 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 /*long*/ window = OS.GTK_WIDGET_WINDOW (handle); - int grabMask = OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_RELEASE_MASK; - int /*long*/ gdkCursor = cursor != null ? cursor.handle : defaultCursor; - int ptrGrabResult = OS.gdk_pointer_grab (window, false, grabMask, window, gdkCursor, OS.GDK_CURRENT_TIME); - - /* The event must be sent because its doit flag is used. */ - Event event = new Event (); - event.time = gdkEvent.time; - event.x = newX; - event.y = newY; - event.width = width; - event.height = height; - if ((parent.style & SWT.MIRRORED) != 0) event.x = parent.getClientWidth () - width - event.x; - sendEvent (SWT.Selection, event); - if (ptrGrabResult == OS.GDK_GRAB_SUCCESS) OS.gdk_pointer_ungrab (OS.GDK_CURRENT_TIME); - if (isDisposed ()) break; - - if (event.doit) { - lastX = event.x; - lastY = event.y; - if ((parent.style & SWT.MIRRORED) != 0) lastX = parent.getClientWidth () - width - lastX; - 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; - } - display.setCursorLocation (parent.toDisplay (cursorX, cursorY)); - } - break; - } - - return result; -} - -int /*long*/ gtk_motion_notify_event (int /*long*/ widget, int /*long*/ eventPtr) { - int /*long*/ result = super.gtk_motion_notify_event (widget, eventPtr); - if (result != 0) return result; - if (!dragging) return 0; - GdkEventMotion gdkEvent = new GdkEventMotion (); - OS.memmove (gdkEvent, eventPtr, GdkEventButton.sizeof); - int eventX, eventY, eventState; - if (gdkEvent.is_hint != 0) { - int [] pointer_x = new int [1], pointer_y = new int [1], mask = new int [1]; - OS.gdk_window_get_pointer (gdkEvent.window, pointer_x, pointer_y, mask); - eventX = pointer_x [0]; - eventY = pointer_y [0]; - eventState = mask [0]; - } else { - int [] origin_x = new int [1], origin_y = new int [1]; - OS.gdk_window_get_origin (gdkEvent.window, origin_x, origin_y); - eventX = (int) (gdkEvent.x_root - origin_x [0]); - eventY = (int) (gdkEvent.y_root - origin_y [0]); - eventState = gdkEvent.state; - } - if ((eventState & OS.GDK_BUTTON1_MASK) == 0) return 0; - int x = OS.GTK_WIDGET_X (handle); - int y = OS.GTK_WIDGET_Y (handle); - int width = OS.GTK_WIDGET_WIDTH (handle); - int height = OS.GTK_WIDGET_HEIGHT (handle); - int parentBorder = 0; - int parentWidth = OS.GTK_WIDGET_WIDTH (parent.handle); - int parentHeight = OS.GTK_WIDGET_HEIGHT (parent.handle); - 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 0; - drawBand (lastX, lastY, width, height); - - Event event = new Event (); - event.time = gdkEvent.time; - event.x = newX; - event.y = newY; - event.width = width; - event.height = height; - if ((style & SWT.SMOOTH) == 0) { - event.detail = SWT.DRAG; - } - if ((parent.style & SWT.MIRRORED) != 0) event.x = parent.getClientWidth() - width - event.x; - sendEvent (SWT.Selection, event); - if (isDisposed ()) return 0; - if (event.doit) { - lastX = event.x; - lastY = event.y; - if ((parent.style & SWT.MIRRORED) != 0) lastX = parent.getClientWidth () - width - lastX; - } - parent.update (true, (style & SWT.SMOOTH) == 0); - drawBand (lastX, lastY, width, height); - if ((style & SWT.SMOOTH) != 0) { - setBounds (event.x, lastY, width, height); - // widget could be disposed at this point - } - return result; -} - -int /*long*/ gtk_realize (int /*long*/ widget) { - setCursor (cursor != null ? cursor.handle : 0); - return super.gtk_realize (widget); -} - -void hookEvents () { - super.hookEvents (); - OS.gtk_widget_add_events (handle, OS.GDK_POINTER_MOTION_HINT_MASK); -} - -void releaseWidget () { - super.releaseWidget (); - if (defaultCursor != 0) OS.gdk_cursor_destroy (defaultCursor); - defaultCursor = 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); -} - -void setCursor (int /*long*/ cursor) { - super.setCursor (cursor != 0 ? cursor : defaultCursor); -} - -int traversalCode (int key, GdkEventKey event) { - return 0; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java deleted file mode 100644 index 47e6ebbf5c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scale.java +++ /dev/null @@ -1,377 +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.gtk.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * 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 { - -/** - * 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(); - if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; - if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; - Point size = computeNativeSize(handle, wHint, hHint, changed); - if ((style & SWT.HORIZONTAL) != 0) { - if (wHint == SWT.DEFAULT) size.x = 2 * size.x; - } else { - if (hHint == SWT.DEFAULT) size.y = 2 * size.y; - } - return size; -} - -void createHandle (int index) { - state |= HANDLE | THEME_BACKGROUND; - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - int /*long*/ hAdjustment = OS.gtk_adjustment_new (0, 0, 100, 1, 10, 0); - if (hAdjustment == 0) error (SWT.ERROR_NO_HANDLES); - if ((style & SWT.HORIZONTAL) != 0) { - handle = OS.gtk_hscale_new (hAdjustment); - } else { - handle = OS.gtk_vscale_new (hAdjustment); - } - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (fixedHandle, handle); - OS.gtk_scale_set_digits (handle, 0); - OS.gtk_scale_set_draw_value (handle, false); -} - -void hookEvents () { - super.hookEvents (); - OS.g_signal_connect_closure (handle, OS.value_changed, display.closures [VALUE_CHANGED], false); -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - return (int) adjustment.step_increment; -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - return (int) adjustment.upper; -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - return (int) adjustment.lower; -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - return (int) adjustment.page_increment; -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - return (int) adjustment.value; -} - -int /*long*/ gtk_value_changed (int /*long*/ adjustment) { - postEvent (SWT.Selection); - return 0; -} - -/** - * 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 value) { - checkWidget (); - if (value < 1) return; - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_range_set_increments (handle, value, getPageIncrement ()); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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 minimum = getMinimum(); - if (value <= minimum) return; - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_range_set_range (handle, minimum, value); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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 maximum = getMaximum (); - if (value >= maximum) return; - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_range_set_range (handle, value, maximum); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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 value) { - checkWidget (); - if (value < 1) return; - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_range_set_increments (handle, getIncrement (), value); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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 (); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_range_set_value (handle, value); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java deleted file mode 100644 index b2fcd24553..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ScrollBar.java +++ /dev/null @@ -1,768 +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.gtk.*; -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; - int /*long*/ adjustmentHandle; - int detail; - boolean dragSent; - -ScrollBar () { -} - -/** -* Creates a new instance of the widget. -*/ -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 deregister () { - super.deregister (); - if (adjustmentHandle != 0) display.removeWidget (adjustmentHandle); -} - -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 (); - if (handle != 0) return OS.GTK_WIDGET_SENSITIVE (handle); - return true; -} - -/** - * 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 (); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, adjustmentHandle); - return (int) adjustment.step_increment; -} - -/** - * 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 (); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, adjustmentHandle); - return (int) adjustment.upper; -} - -/** - * 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 (); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, adjustmentHandle); - return (int) adjustment.lower; -} - -/** - * 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 (); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, adjustmentHandle); - return (int) adjustment.page_increment; -} - -/** - * 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 (); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, adjustmentHandle); - return (int) adjustment.value; -} - -/** - * 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 (); - if (handle == 0) return new Point (0,0); - GtkRequisition requisition = new GtkRequisition (); - OS.gtk_widget_size_request (handle, requisition); - return new Point (requisition.width, requisition.height); -} - -/** - * 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 (); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, adjustmentHandle); - return (int) adjustment.page_size; -} - -/** - * 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 /*long*/ scrolledHandle = parent.scrolledHandle; - int [] hsp = new int [1], vsp = new int [1]; - OS.gtk_scrolled_window_get_policy (scrolledHandle, hsp, vsp); - if ((style & SWT.HORIZONTAL) != 0) { - return hsp [0] != OS.GTK_POLICY_NEVER; - } else { - return vsp [0] != OS.GTK_POLICY_NEVER; - } -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ eventPtr) { - int /*long*/ result = super.gtk_button_press_event (widget, eventPtr); - if (result != 0) return result; - detail = OS.GTK_SCROLL_NONE; - dragSent = false; - return result; -} - -int /*long*/ gtk_change_value (int /*long*/ widget, int /*long*/ scroll, int /*long*/ value1, int /*long*/ value2) { - detail = (int)/*64*/scroll; - return 0; -} - -int /*long*/ gtk_value_changed (int /*long*/ adjustment) { - Event event = new Event (); - dragSent = detail == OS.GTK_SCROLL_JUMP; - switch (detail) { - case OS.GTK_SCROLL_NONE: event.detail = SWT.NONE; break; - case OS.GTK_SCROLL_JUMP: event.detail = SWT.DRAG; break; - case OS.GTK_SCROLL_START: event.detail = SWT.HOME; break; - case OS.GTK_SCROLL_END: event.detail = SWT.END; break; - case OS.GTK_SCROLL_PAGE_DOWN: - case OS.GTK_SCROLL_PAGE_RIGHT: - case OS.GTK_SCROLL_PAGE_FORWARD: event.detail = SWT.PAGE_DOWN; break; - case OS.GTK_SCROLL_PAGE_UP: - case OS.GTK_SCROLL_PAGE_LEFT: - case OS.GTK_SCROLL_PAGE_BACKWARD: event.detail = SWT.PAGE_UP; break; - case OS.GTK_SCROLL_STEP_DOWN: - case OS.GTK_SCROLL_STEP_RIGHT: - case OS.GTK_SCROLL_STEP_FORWARD: event.detail = SWT.ARROW_DOWN; break; - case OS.GTK_SCROLL_STEP_UP: - case OS.GTK_SCROLL_STEP_LEFT: - case OS.GTK_SCROLL_STEP_BACKWARD: event.detail = SWT.ARROW_UP; break; - } - detail = OS.GTK_SCROLL_NONE; - if (!dragSent) detail = OS.GTK_SCROLL_NONE; - postEvent (SWT.Selection, event); - parent.updateScrollBarValue (this); - return 0; -} - -int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) { - GdkEvent gtkEvent = new GdkEvent (); - OS.memmove (gtkEvent, gdkEvent, GdkEvent.sizeof); - switch (gtkEvent.type) { - case OS.GDK_BUTTON_RELEASE: { - GdkEventButton gdkEventButton = new GdkEventButton (); - OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof); - if (gdkEventButton.button == 1 && detail == SWT.DRAG) { - if (!dragSent) { - Event event = new Event (); - event.detail = SWT.DRAG; - postEvent (SWT.Selection, event); - } - postEvent (SWT.Selection); - } - detail = OS.GTK_SCROLL_NONE; - dragSent = false; - break; - } - } - return super.gtk_event_after (widget, gdkEvent); -} - -void hookEvents () { - super.hookEvents (); - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) { - OS.g_signal_connect_closure (handle, OS.change_value, display.closures [CHANGE_VALUE], false); - } - OS.g_signal_connect_closure (adjustmentHandle, OS.value_changed, display.closures [VALUE_CHANGED], false); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [EVENT_AFTER], 0, display.closures [EVENT_AFTER], false); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false); -} - -/** - * 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 () && getParent ().getEnabled (); -} - -/** - * 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 () && getParent ().isVisible (); -} - -void register () { - super.register (); - if (adjustmentHandle != 0) display.addWidget (adjustmentHandle, this); -} - -void releaseHandle () { - super.releaseHandle (); - parent = null; -} - -void releaseParent () { - super.releaseParent (); - if (parent.horizontalBar == this) parent.horizontalBar = null; - if (parent.verticalBar == this) parent.verticalBar = null; -} - -void releaseWidget () { - super.releaseWidget (); - //parent = 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); -} - -/** - * 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 (handle != 0) OS.gtk_widget_set_sensitive (handle, enabled); -} - -/** - * 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; - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, adjustmentHandle); - adjustment.step_increment = (float) value; - OS.memmove (adjustmentHandle, adjustment); - OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_adjustment_changed (adjustmentHandle); - OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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 (); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, adjustmentHandle); - int minimum = (int) adjustment.lower; - if (value <= minimum) return; - adjustment.upper = value; - adjustment.page_size = Math.min ((int)adjustment.page_size, value - minimum); - adjustment.value = Math.min ((int)adjustment.value, (int)(value - adjustment.page_size)); - OS.memmove (adjustmentHandle, adjustment); - OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_adjustment_changed (adjustmentHandle); - OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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; - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, adjustmentHandle); - int maximum = (int) adjustment.upper; - if (value >= maximum) return; - adjustment.lower = value; - adjustment.page_size = Math.min ((int)adjustment.page_size, maximum - value); - adjustment.value = Math.max ((int)adjustment.value, value); - OS.memmove (adjustmentHandle, adjustment); - OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_adjustment_changed (adjustmentHandle); - OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -void setOrientation () { - super.setOrientation (); - if ((parent.style & SWT.MIRRORED) != 0) { - if ((parent.state & CANVAS) != 0) { - if ((style & SWT.HORIZONTAL) != 0) { - OS.gtk_range_set_inverted (handle, true); - } - } - } -} - -/** - * 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; - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, adjustmentHandle); - adjustment.page_increment = (float) value; - OS.memmove (adjustmentHandle, adjustment); - OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_adjustment_changed (adjustmentHandle); - OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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 value) { - checkWidget (); - value = Math.min (value, getMaximum() - getThumb()); - OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_adjustment_set_value (adjustmentHandle, value); - OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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; - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, adjustmentHandle); - value = (int) Math.min (value, (int)(adjustment.upper - adjustment.lower)); - adjustment.page_size = (double) value; - adjustment.value = Math.min ((int)adjustment.value, (int)(adjustment.upper - value)); - OS.memmove (adjustmentHandle, adjustment); - OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_adjustment_changed (adjustmentHandle); - OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, adjustmentHandle); - adjustment.lower = minimum; - adjustment.upper = maximum; - adjustment.step_increment = increment; - adjustment.page_increment = pageIncrement; - adjustment.page_size = thumb; - adjustment.value = Math.min (Math.max (selection, minimum), maximum - thumb); - OS.memmove (adjustmentHandle, adjustment); - OS.g_signal_handlers_block_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_adjustment_changed (adjustmentHandle); - OS.gtk_adjustment_value_changed (adjustmentHandle); - OS.g_signal_handlers_unblock_matched (adjustmentHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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); - } -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java deleted file mode 100644 index ab3304558a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Scrollable.java +++ /dev/null @@ -1,384 +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.gtk.*; -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 /*long*/ scrolledHandle; - ScrollBar horizontalBar, verticalBar; - -/** - * Prevents uninitialized instances from being created outside the package. - */ -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#H_SCROLL - * @see SWT#V_SCROLL - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Scrollable (Composite parent, int style) { - super (parent, style); -} - -int /*long*/ clientHandle () { - return handle; -} - -/** - * 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 = 0; - if (fixedHandle != 0) border += OS.gtk_container_get_border_width (fixedHandle); - if (scrolledHandle != 0) border += OS.gtk_container_get_border_width (scrolledHandle); - int trimX = x - border, trimY = y - border; - int trimWidth = width + (border * 2), trimHeight = height + (border * 2); - trimHeight += hScrollBarWidth (); - trimWidth += vScrollBarWidth (); - if (scrolledHandle != 0) { - if (OS.gtk_scrolled_window_get_shadow_type (scrolledHandle) != OS.GTK_SHADOW_NONE) { - int /*long*/ style = OS.gtk_widget_get_style (scrolledHandle); - int xthickness = OS.gtk_style_get_xthickness (style); - int ythickness = OS.gtk_style_get_ythickness (style); - trimX -= xthickness; - trimY -= ythickness; - trimWidth += xthickness * 2; - trimHeight += ythickness * 2; - } - } - return new Rectangle (trimX, trimY, trimWidth, trimHeight); -} - -ScrollBar createScrollBar (int style) { - if (scrolledHandle == 0) return null; - ScrollBar bar = new ScrollBar (); - bar.parent = this; - bar.style = style; - bar.display = display; - bar.state |= HANDLE; - if ((style & SWT.H_SCROLL) != 0) { - bar.handle = OS.GTK_SCROLLED_WINDOW_HSCROLLBAR (scrolledHandle); - bar.adjustmentHandle = OS.gtk_scrolled_window_get_hadjustment (scrolledHandle); - } else { - bar.handle = OS.GTK_SCROLLED_WINDOW_VSCROLLBAR (scrolledHandle); - bar.adjustmentHandle = OS.gtk_scrolled_window_get_vadjustment (scrolledHandle); - } - bar.setOrientation(); - 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 deregister () { - super.deregister (); - if (scrolledHandle != 0) display.removeWidget (scrolledHandle); -} - -void destroyScrollBar (ScrollBar bar) { - setScrollBarVisible (bar, false); - //This code is intentionally commented - //bar.destroyHandle (); -} - -public int getBorderWidth () { - checkWidget(); - int border = 0; - if (fixedHandle != 0) border += OS.gtk_container_get_border_width (fixedHandle); - if (scrolledHandle != 0) { - border += OS.gtk_container_get_border_width (scrolledHandle); - if (OS.gtk_scrolled_window_get_shadow_type (scrolledHandle) != OS.GTK_SHADOW_NONE) { - border += OS.gtk_style_get_xthickness (OS.gtk_widget_get_style (scrolledHandle)); - } - } - return border; -} - -/** - * 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 (); - forceResize (); - int /*long*/ clientHandle = clientHandle (); - int x = OS.GTK_WIDGET_X (clientHandle); - int y = OS.GTK_WIDGET_Y (clientHandle); - int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (clientHandle); - int height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (clientHandle); - return new Rectangle (x, y, width, height); -} -/** - * 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; -} - -int /*long*/ gtk_scroll_event (int /*long*/ widget, int /*long*/ eventPtr) { - int /*long*/ result = super.gtk_scroll_event (widget, eventPtr); - - /* - * Feature in GTK. Scrolled windows do not scroll if the scrollbars - * are hidden. This is not a bug, but is inconsistent with other platforms. - * The fix is to set the adjustment values directly. - */ - if ((state & CANVAS) != 0) { - ScrollBar scrollBar; - GdkEventScroll gdkEvent = new GdkEventScroll (); - OS.memmove (gdkEvent, eventPtr, GdkEventScroll.sizeof); - if (gdkEvent.direction == OS.GDK_SCROLL_UP || gdkEvent.direction == OS.GDK_SCROLL_DOWN) { - scrollBar = verticalBar; - } else { - scrollBar = horizontalBar; - } - if (scrollBar != null && !OS.GTK_WIDGET_VISIBLE (scrollBar.handle) && scrollBar.getEnabled()) { - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, scrollBar.adjustmentHandle); - /* Calculate wheel delta to match GTK+ 2.4 and higher */ - int wheel_delta = (int) Math.pow(adjustment.page_size, 2.0 / 3.0); - if (gdkEvent.direction == OS.GDK_SCROLL_UP || gdkEvent.direction == OS.GDK_SCROLL_LEFT) - wheel_delta = -wheel_delta; - int value = (int) Math.max(adjustment.lower, - Math.min(adjustment.upper - adjustment.page_size, adjustment.value + wheel_delta)); - OS.gtk_adjustment_set_value (scrollBar.adjustmentHandle, value); - return 1; - } - } - return result; -} - -int hScrollBarWidth() { - if (horizontalBar==null) return 0; - int /*long*/ hBarHandle = OS.GTK_SCROLLED_WINDOW_HSCROLLBAR(scrolledHandle); - if (hBarHandle==0) return 0; - GtkRequisition requisition = new GtkRequisition(); - OS.gtk_widget_size_request(hBarHandle, requisition); - int spacing = OS.GTK_SCROLLED_WINDOW_SCROLLBAR_SPACING(scrolledHandle); - return requisition.height + spacing; -} - -boolean sendLeaveNotify () { - return scrolledHandle != 0; -} - -void setOrientation () { - super.setOrientation (); - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - if (scrolledHandle != 0) { - OS.gtk_widget_set_direction (scrolledHandle, OS.GTK_TEXT_DIR_RTL); - } - } -} - -boolean setScrollBarVisible (ScrollBar bar, boolean visible) { - if (scrolledHandle == 0) return false; - int [] hsp = new int [1], vsp = new int [1]; - OS.gtk_scrolled_window_get_policy (scrolledHandle, hsp, vsp); - int policy = visible ? OS.GTK_POLICY_ALWAYS : OS.GTK_POLICY_NEVER; - if ((bar.style & SWT.HORIZONTAL) != 0) { - if (hsp [0] == policy) return false; - hsp [0] = policy; - } else { - if (vsp [0] == policy) return false; - vsp [0] = policy; - } - OS.gtk_scrolled_window_set_policy (scrolledHandle, hsp [0], vsp [0]); - return true; -} - -void redrawBackgroundImage () { -} - -void redrawWidget (int x, int y, int width, int height, boolean redrawAll, boolean all, boolean trim) { - super.redrawWidget (x, y, width, height, redrawAll, all, trim); - if ((OS.GTK_WIDGET_FLAGS (handle) & OS.GTK_REALIZED) == 0) return; - if (!trim) return; - int /*long*/ topHandle = topHandle (), paintHandle = paintHandle (); - if (topHandle == paintHandle) return; - int /*long*/ window = OS.GTK_WIDGET_WINDOW (topHandle); - GdkRectangle rect = new GdkRectangle (); - if (redrawAll) { - rect.width = OS.GTK_WIDGET_WIDTH (topHandle); - rect.height = OS.GTK_WIDGET_HEIGHT (topHandle); - } else { - int [] destX = new int [1], destY = new int [1]; - OS.gtk_widget_translate_coordinates (paintHandle, topHandle, x, y, destX, destY); - rect.x = destX [0]; - rect.y = destY [0]; - rect.width = width; - rect.height = height; - } - OS.gdk_window_invalidate_rect (window, rect, all); -} - -void register () { - super.register (); - if (scrolledHandle != 0) display.addWidget (scrolledHandle, this); -} - -void releaseHandle () { - super.releaseHandle (); - scrolledHandle = 0; -} - -void releaseChildren (boolean destroy) { - if (horizontalBar != null) { - horizontalBar.release (false); - horizontalBar = null; - } - if (verticalBar != null) { - verticalBar.release (false); - verticalBar = null; - } - super.releaseChildren (destroy); -} - -void resizeHandle (int width, int height) { - if (fixedHandle != 0) OS.gtk_widget_set_size_request (fixedHandle, width, height); - OS.gtk_widget_set_size_request (scrolledHandle != 0 ? scrolledHandle : handle, width, height); -} - -void showWidget () { - super.showWidget (); - if (scrolledHandle != 0) OS.gtk_widget_show (scrolledHandle); -} - -int /*long*/ topHandle () { - if (fixedHandle != 0) return fixedHandle; - if (scrolledHandle != 0) return scrolledHandle; - return super.topHandle (); -} - -void updateScrollBarValue (ScrollBar bar) { - redrawBackgroundImage (); -} - -int vScrollBarWidth() { - if (verticalBar == null) return 0; - int /*long*/ vBarHandle = OS.GTK_SCROLLED_WINDOW_VSCROLLBAR(scrolledHandle); - if (vBarHandle == 0) return 0; - GtkRequisition requisition = new GtkRequisition(); - OS.gtk_widget_size_request (vBarHandle, requisition); - int spacing = OS.GTK_SCROLLED_WINDOW_SCROLLBAR_SPACING(scrolledHandle); - return requisition.width + spacing; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java deleted file mode 100644 index 9e3a131b63..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java +++ /dev/null @@ -1,2195 +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.gtk.*; -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 /*long*/ shellHandle, tooltipsHandle, tooltipWindow, group, modalGroup; - boolean mapped, moved, resized, opened, fullScreen, showWithParent, modified, center; - int oldX, oldY, oldWidth, oldHeight; - int minWidth, minHeight; - Control lastActive; - ToolTip [] toolTips; - - static final int MAXIMUM_TRIM = 128; - -/** - * 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 /*long*/ 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 { - 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); -} - -public static Shell gtk_new (Display display, int /*long*/ 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 /*long*/ handle) { - return new Shell (display, null, SWT.NO_TRIM, handle, 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; -} - -/** - * 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.Close,typedListener); - addListener (SWT.Iconify,typedListener); - addListener (SWT.Deiconify,typedListener); - addListener (SWT.Activate, typedListener); - addListener (SWT.Deactivate, typedListener); -} - -void addToolTip (ToolTip toolTip) { - if (toolTips == null) toolTips = new ToolTip [4]; - for (int i=0; i<toolTips.length; i++) { - if (toolTips [i] == null) { - toolTips [i] = toolTip; - return; - } - } - ToolTip [] newToolTips = new ToolTip [toolTips.length + 4]; - newToolTips [toolTips.length] = toolTip; - System.arraycopy (toolTips, 0, newToolTips, 0, toolTips.length); - toolTips = newToolTips; -} - -void adjustTrim () { - if (display.ignoreTrim) return; - int width = OS.GTK_WIDGET_WIDTH (shellHandle); - int height = OS.GTK_WIDGET_HEIGHT (shellHandle); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle); - GdkRectangle rect = new GdkRectangle (); - OS.gdk_window_get_frame_extents (window, rect); - int trimWidth = Math.max (0, rect.width - width); - int trimHeight = Math.max (0, rect.height - height); - /* - * Bug in GTK. gdk_window_get_frame_extents() fails for various window - * managers, causing a large incorrect value to be returned as the trim. - * The fix is to ignore the returned trim values if they are too large. - */ - if (trimWidth > MAXIMUM_TRIM || trimHeight > MAXIMUM_TRIM) { - display.ignoreTrim = true; - return; - } - 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.titleResizeTrimWidth = trimWidth; - display.titleResizeTrimHeight = trimHeight; - return; - } - if (hasBorder) { - display.titleBorderTrimWidth = trimWidth; - display.titleBorderTrimHeight = trimHeight; - return; - } - display.titleTrimWidth = trimWidth; - display.titleTrimHeight = trimHeight; - return; - } - if (hasResize) { - display.resizeTrimWidth = trimWidth; - display.resizeTrimHeight = trimHeight; - return; - } - if (hasBorder) { - display.borderTrimWidth = trimWidth; - display.borderTrimHeight = trimHeight; - return; - } -} - -void bringToTop (boolean force) { - if (!OS.GTK_WIDGET_VISIBLE (shellHandle)) return; - Display display = this.display; - Shell activeShell = display.activeShell; - if (activeShell == this) return; - if (!force) { - if (activeShell == null) return; - if (!display.activePending) { - int /*long*/ focusHandle = OS.gtk_window_get_focus (activeShell.shellHandle); - if (focusHandle != 0 && !OS.GTK_WIDGET_HAS_FOCUS (focusHandle)) return; - } - } - /* - * Bug in GTK. When a shell that is not managed by the window - * manage is given focus, GTK gets stuck in "focus follows pointer" - * mode when the pointer is within the shell and its parent when - * the shell is hidden or disposed. The fix is to use XSetInputFocus() - * to assign focus when ever the active shell has not managed by - * the window manager. - * - * NOTE: This bug is fixed in GTK+ 2.6.8 and above. - */ - boolean xFocus = false; - if (activeShell != null) { - if (OS.GTK_VERSION < OS.VERSION (2, 6, 8)) { - xFocus = activeShell.isUndecorated (); - } - display.activeShell = null; - display.activePending = true; - } - /* - * Feature in GTK. When the shell is an override redirect - * window, gdk_window_focus() does not give focus to the - * window. The fix is to use XSetInputFocus() to force - * the focus. - */ - int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle); - if ((xFocus || (style & SWT.ON_TOP) != 0) && OS.GDK_WINDOWING_X11 ()) { - int /*long*/ xDisplay = OS.gdk_x11_drawable_get_xdisplay (window); - int /*long*/ xWindow = OS.gdk_x11_drawable_get_xid (window); - OS.gdk_error_trap_push (); - /* Use CurrentTime instead of the last event time to ensure that the shell becomes active */ - OS.XSetInputFocus (xDisplay, xWindow, OS.RevertToParent, OS.CurrentTime); - OS.gdk_error_trap_pop (); - } else { - /* - * Bug in metacity. Calling gdk_window_focus() with a timestamp more - * recent than the last user interaction time can cause windows not - * to come forward in versions > 2.10.0. The fix is to use the last - * user event time. - */ - if (display.windowManager.toLowerCase ().equals ("metacity")) { - OS.gdk_window_focus (window, display.lastUserEventTime); - } else { - OS.gdk_window_focus (window, OS.GDK_CURRENT_TIME); - } - } - display.activeShell = this; - display.activePending = true; -} - -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 checkBorder () { - /* Do nothing */ -} - -void checkOpen () { - if (!opened) resized = false; -} - -int /*long*/ childStyle () { - return 0; -} - -/** - * 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); - int border = 0; - if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) { - border = OS.gtk_container_get_border_width (shellHandle); - } - int trimWidth = trimWidth (), trimHeight = trimHeight (); - trim.x -= (trimWidth / 2) + border; - trim.y -= trimHeight - (trimWidth / 2) + border; - trim.width += trimWidth + border * 2; - trim.height += trimHeight + border * 2; - if (menuBar != null) { - forceResize (); - int menuBarHeight = OS.GTK_WIDGET_HEIGHT (menuBar.handle); - trim.y -= menuBarHeight; - trim.height += menuBarHeight; - } - return trim; -} - -void createHandle (int index) { - state |= HANDLE | CANVAS; - if (shellHandle == 0) { - if (handle == 0) { - int type = OS.GTK_WINDOW_TOPLEVEL; - if ((style & SWT.ON_TOP) != 0) type = OS.GTK_WINDOW_POPUP; - shellHandle = OS.gtk_window_new (type); - } else { - shellHandle = OS.gtk_plug_new (handle); - } - if (shellHandle == 0) error (SWT.ERROR_NO_HANDLES); - if (parent != null) { - OS.gtk_window_set_transient_for (shellHandle, parent.topHandle ()); - OS.gtk_window_set_destroy_with_parent (shellHandle, true); - if (!isUndecorated ()) { - OS.gtk_window_set_type_hint (shellHandle, OS.GDK_WINDOW_TYPE_HINT_DIALOG); - } else { - if (OS.GTK_VERSION >= OS.VERSION (2, 2, 0)) { - OS.gtk_window_set_skip_taskbar_hint (shellHandle, true); - } - } - } - /* - * Feature in GTK. The window size must be set when the window - * is created or it will not be allowed to be resized smaller that the - * initial size by the user. The fix is to set the size to zero. - */ - if ((style & SWT.RESIZE) != 0) { - OS.gtk_widget_set_size_request (shellHandle, 0, 0); - OS.gtk_window_set_resizable (shellHandle, true); - } else { - OS.gtk_window_set_resizable (shellHandle, false); - } - vboxHandle = OS.gtk_vbox_new (false, 0); - if (vboxHandle == 0) error (SWT.ERROR_NO_HANDLES); - createHandle (index, false, true); - OS.gtk_container_add (vboxHandle, scrolledHandle); - OS.gtk_box_set_child_packing (vboxHandle, scrolledHandle, true, true, 0, OS.GTK_PACK_END); - OS.gtk_window_set_title (shellHandle, new byte [1]); - if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) { - OS.gtk_container_set_border_width (shellHandle, 1); - GdkColor color = new GdkColor (); - OS.gtk_style_get_black (OS.gtk_widget_get_style (shellHandle), color); - OS.gtk_widget_modify_bg (shellHandle, OS.GTK_STATE_NORMAL, color); - } - } else { - vboxHandle = OS.gtk_bin_get_child (shellHandle); - if (vboxHandle == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ children = OS.gtk_container_get_children (vboxHandle); - if (OS.g_list_length (children) > 0) { - scrolledHandle = OS.g_list_data (children); - } - OS.g_list_free (children); - if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES); - handle = OS.gtk_bin_get_child (scrolledHandle); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - } - group = OS.gtk_window_group_new (); - if (group == 0) error (SWT.ERROR_NO_HANDLES); - /* - * Feature in GTK. Realizing the shell triggers a size allocate event, - * which may be confused for a resize event from the window manager if - * received too late. The fix is to realize the window during creation - * to avoid confusion. - */ - OS.gtk_widget_realize (shellHandle); -} - -int /*long*/ filterProc (int /*long*/ xEvent, int /*long*/ gdkEvent, int /*long*/ data2) { - int eventType = OS.X_EVENT_TYPE (xEvent); - if (eventType != OS.FocusOut && eventType != OS.FocusIn) return 0; - XFocusChangeEvent xFocusEvent = new XFocusChangeEvent(); - OS.memmove (xFocusEvent, xEvent, XFocusChangeEvent.sizeof); - switch (eventType) { - case OS.FocusIn: - if (xFocusEvent.mode == OS.NotifyNormal || xFocusEvent.mode == OS.NotifyWhileGrabbed) { - switch (xFocusEvent.detail) { - case OS.NotifyNonlinear: - case OS.NotifyNonlinearVirtual: - case OS.NotifyAncestor: - if (tooltipsHandle != 0) OS.gtk_tooltips_enable (tooltipsHandle); - display.activeShell = this; - display.activePending = false; - sendEvent (SWT.Activate); - break; - } - } - break; - case OS.FocusOut: - if (xFocusEvent.mode == OS.NotifyNormal || xFocusEvent.mode == OS.NotifyWhileGrabbed) { - switch (xFocusEvent.detail) { - case OS.NotifyNonlinear: - case OS.NotifyNonlinearVirtual: - case OS.NotifyVirtual: - if (tooltipsHandle != 0) OS.gtk_tooltips_disable (tooltipsHandle); - Display display = this.display; - sendEvent (SWT.Deactivate); - setActiveControl (null); - if (display.activeShell == this) { - display.activeShell = null; - display.activePending = false; - } - break; - } - } - break; - } - return 0; -} - -Control findBackgroundControl () { - return (state & BACKGROUND) != 0 || backgroundImage != null ? this : null; -} - -Composite findDeferredControl () { - return layoutCount > 0 ? this : null; -} - -boolean hasBorder () { - return false; -} - -void hookEvents () { - super.hookEvents (); - OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [KEY_PRESS_EVENT], 0, display.closures [KEY_PRESS_EVENT], false); - OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [WINDOW_STATE_EVENT], 0, display.closures [WINDOW_STATE_EVENT], false); - OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [SIZE_ALLOCATE], 0, display.closures [SIZE_ALLOCATE], false); - OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [CONFIGURE_EVENT], 0, display.closures [CONFIGURE_EVENT], false); - OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [DELETE_EVENT], 0, display.closures [DELETE_EVENT], false); - OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [MAP_EVENT], 0, display.shellMapProcClosure, false); - OS.g_signal_connect_closure_by_id (shellHandle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false); - OS.g_signal_connect_closure (shellHandle, OS.move_focus, display.closures [MOVE_FOCUS], false); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle); - OS.gdk_window_add_filter (window, display.filterProc, shellHandle); -} - -public boolean isEnabled () { - checkWidget (); - return getEnabled (); -} - -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 register () { - super.register (); - display.addWidget (shellHandle, this); -} - -void releaseParent () { - /* Do nothing */ -} - -int /*long*/ topHandle () { - return shellHandle; -} - -void fixActiveShell () { - if (display.activeShell == this) { - Shell shell = null; - if (parent != null && parent.isVisible ()) shell = parent.getShell (); - if (shell == null && isUndecorated ()) { - Shell [] shells = display.getShells (); - for (int i = 0; i < shells.length; i++) { - if (shells [i] != null && shells [i].isVisible ()) { - shell = shells [i]; - break; - } - } - } - if (shell != null) shell.bringToTop (false); - } -} - -void fixShell (Shell newShell, Control control) { - if (this == newShell) return; - if (control == lastActive) setActiveControl (null); - String toolTipText = control.toolTipText; - if (toolTipText != null) { - control.setToolTipText (this, null); - control.setToolTipText (newShell, toolTipText); - } -} - -int /*long*/ fixedSizeAllocateProc(int /*long*/ widget, int /*long*/ allocationPtr) { - int clientWidth = 0; - if ((style & SWT.MIRRORED) != 0) clientWidth = getClientWidth (); - int /*long*/ result = super.fixedSizeAllocateProc (widget, allocationPtr); - if ((style & SWT.MIRRORED) != 0) moveChildren (clientWidth); - return result; -} - -void fixStyle (int /*long*/ handle) { -} - -void forceResize () { - forceResize (OS.GTK_WIDGET_WIDTH (vboxHandle), OS.GTK_WIDGET_HEIGHT (vboxHandle)); -} - -void forceResize (int width, int height) { - GtkRequisition requisition = new GtkRequisition (); - OS.gtk_widget_size_request (vboxHandle, requisition); - GtkAllocation allocation = new GtkAllocation (); - int border = OS.gtk_container_get_border_width (shellHandle); - allocation.x = border; - allocation.y = border; - allocation.width = width; - allocation.height = height; - OS.gtk_widget_size_allocate (vboxHandle, allocation); -} - -/** - * 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 (); - if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0)) { - if (OS.gtk_widget_is_composited (shellHandle)) { - return (int) (OS.gtk_window_get_opacity (shellHandle) * 255); - } - } - return 255; -} - -/** - * 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(); - return fullScreen; -} - -public Point getLocation () { - checkWidget (); - int [] x = new int [1], y = new int [1]; - OS.gtk_window_get_position (shellHandle, x,y); - return new Point (x [0], y [0]); -} - -public boolean getMaximized () { - checkWidget(); - return !fullScreen && 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 width = Math.max (1, minWidth + trimWidth ()); - int height = Math.max (1, minHeight + trimHeight ()); - return new Point (width, height); -} - -Shell getModalShell () { - Shell shell = null; - Shell [] modalShells = display.modalShells; - if (modalShells != null) { - int bits = SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL; - int index = modalShells.length; - while (--index >= 0) { - Shell modal = modalShells [index]; - if (modal != null) { - if ((modal.style & bits) != 0) { - Control control = this; - while (control != null) { - if (control == modal) break; - control = control.parent; - } - if (control != modal) return modal; - break; - } - if ((modal.style & SWT.PRIMARY_MODAL) != 0) { - if (shell == null) shell = getShell (); - if (modal.parent == shell) return modal; - } - } - } - } - return null; -} - -/** - * 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; -} - -public Point getSize () { - checkWidget (); - int width = OS.GTK_WIDGET_WIDTH (vboxHandle); - int height = OS.GTK_WIDGET_HEIGHT (vboxHandle); - int border = 0; - if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) { - border = OS.gtk_container_get_border_width (shellHandle); - } - return new Point (width + trimWidth () + 2*border, height + trimHeight () + 2*border); -} - -public boolean getVisible () { - checkWidget(); - return OS.GTK_WIDGET_VISIBLE (shellHandle); -} - -/** - * 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 @since 3.0 Javadoc */ - checkWidget (); - return region; -} - -/** - * 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; -} - -Shell _getShell () { - 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.getParent (); - } 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.getParent (); - } while (shell != null && shell != this); - if (shell == this) { - result [index++] = shells [i]; - } - } - return result; -} - -int /*long*/ gtk_configure_event (int /*long*/ widget, int /*long*/ event) { - int [] x = new int [1], y = new int [1]; - OS.gtk_window_get_position (shellHandle, x, y); - if (!moved || oldX != x [0] || oldY != y [0]) { - moved = true; - oldX = x [0]; - oldY = y [0]; - sendEvent (SWT.Move); - // widget could be disposed at this point - } - return 0; -} - -int /*long*/ gtk_delete_event (int /*long*/ widget, int /*long*/ event) { - if (isEnabled()) closeWidget (); - return 1; -} - -int /*long*/ gtk_enter_notify_event (int /*long*/ widget, int /*long*/ event) { - if (widget != shellHandle) { - return super.gtk_enter_notify_event (widget, event); - } - return 0; -} - -int /*long*/ gtk_focus (int /*long*/ widget, int /*long*/ directionType) { - switch ((int)/*64*/directionType) { - case OS.GTK_DIR_TAB_FORWARD: - case OS.GTK_DIR_TAB_BACKWARD: - Control control = display.getFocusControl (); - if (control != null) { - if ((control.state & CANVAS) != 0 && (control.style & SWT.EMBEDDED) != 0) { - int traversal = directionType == OS.GTK_DIR_TAB_FORWARD ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS; - control.traverse (traversal); - return 1; - } - } - break; - } - return super.gtk_focus (widget, directionType); -} - -int /*long*/ gtk_move_focus (int /*long*/ widget, int /*long*/ directionType) { - Control control = display.getFocusControl (); - if (control != null) { - int /*long*/ focusHandle = control.focusHandle (); - OS.gtk_widget_child_focus (focusHandle, (int)/*64*/directionType); - } - OS.g_signal_stop_emission_by_name (shellHandle, OS.move_focus); - return 1; -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) { - /* Stop menu mnemonics when the shell is disabled */ - if (widget == shellHandle) { - return (state & DISABLED) != 0 ? 1 : 0; - } - return super.gtk_key_press_event (widget, event); -} - -int /*long*/ gtk_size_allocate (int /*long*/ widget, int /*long*/ allocation) { - int width = OS.GTK_WIDGET_WIDTH (shellHandle); - int height = OS.GTK_WIDGET_HEIGHT (shellHandle); - if (!resized || oldWidth != width || oldHeight != height) { - oldWidth = width; - oldHeight = height; - resizeBounds (width, height, true); - } - return 0; -} - -int /*long*/ gtk_realize (int /*long*/ widget) { - int /*long*/ result = super.gtk_realize (widget); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle); - if ((style & SWT.SHELL_TRIM) != SWT.SHELL_TRIM) { - int decorations = 0; - if ((style & SWT.NO_TRIM) == 0) { - if ((style & SWT.MIN) != 0) decorations |= OS.GDK_DECOR_MINIMIZE; - if ((style & SWT.MAX) != 0) decorations |= OS.GDK_DECOR_MAXIMIZE; - if ((style & SWT.RESIZE) != 0) decorations |= OS.GDK_DECOR_RESIZEH; - if ((style & SWT.BORDER) != 0) decorations |= OS.GDK_DECOR_BORDER; - if ((style & SWT.MENU) != 0) decorations |= OS.GDK_DECOR_MENU; - if ((style & SWT.TITLE) != 0) decorations |= OS.GDK_DECOR_TITLE; - /* - * Feature in GTK. Under some Window Managers (Sawmill), in order - * to get any border at all from the window manager it is necessary to - * set GDK_DECOR_BORDER. The fix is to force these bits when any - * kind of border is requested. - */ - if ((style & SWT.RESIZE) != 0) decorations |= OS.GDK_DECOR_BORDER; - } - OS.gdk_window_set_decorations (window, decorations); - } - if ((style & SWT.ON_TOP) != 0) { - OS.gdk_window_set_override_redirect (window, true); - } - return result; -} - -int /*long*/ gtk_window_state_event (int /*long*/ widget, int /*long*/ event) { - GdkEventWindowState gdkEvent = new GdkEventWindowState (); - OS.memmove (gdkEvent, event, GdkEventWindowState.sizeof); - minimized = (gdkEvent.new_window_state & OS.GDK_WINDOW_STATE_ICONIFIED) != 0; - maximized = (gdkEvent.new_window_state & OS.GDK_WINDOW_STATE_MAXIMIZED) != 0; - fullScreen = (gdkEvent.new_window_state & OS.GDK_WINDOW_STATE_FULLSCREEN) != 0; - if ((gdkEvent.changed_mask & OS.GDK_WINDOW_STATE_ICONIFIED) != 0) { - if (minimized) { - sendEvent (SWT.Iconify); - } else { - sendEvent (SWT.Deiconify); - } - updateMinimized (minimized); - } - return 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; -} - -/** - * 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.Close, listener); - eventTable.unhook (SWT.Iconify,listener); - eventTable.unhook (SWT.Deiconify,listener); - eventTable.unhook (SWT.Activate, listener); - eventTable.unhook (SWT.Deactivate, listener); -} - -void removeTooTip (ToolTip toolTip) { - if (toolTips == null) return; - for (int i=0; i<toolTips.length; i++) { - if (toolTips [i] == toolTip) { - toolTips [i] = null; - return; - } - } -} - -/** - * 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 ()) { - 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 (); - if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0)) { - if (OS.gtk_widget_is_composited (shellHandle)) { - alpha &= 0xFF; - OS.gtk_window_set_opacity (shellHandle, alpha / 255f); - } - } -} - -void resizeBounds (int width, int height, boolean notify) { - if (redrawWindow != 0) { - OS.gdk_window_resize (redrawWindow, width, height); - } - if (enableWindow != 0) { - OS.gdk_window_resize (enableWindow, width, height); - } - int border = OS.gtk_container_get_border_width (shellHandle); - int boxWidth = width - 2*border; - int boxHeight = height - 2*border; - OS.gtk_widget_set_size_request (vboxHandle, boxWidth, boxHeight); - forceResize (boxWidth, boxHeight); - if (notify) { - resized = true; - sendEvent (SWT.Resize); - if (isDisposed ()) return; - if (layout != null) { - markLayout (false, false); - updateLayout (false); - } - } -} - -int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - if (fullScreen) setFullScreen (false); - /* - * Bug in GTK. When either of the location or size of - * a shell is changed while the shell is maximized, the - * shell is moved to (0, 0). The fix is to explicitly - * unmaximize the shell before setting the bounds to - * anything different from the current bounds. - */ - 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 0; - setMaximized (false); - } - int result = 0; - if (move) { - int [] x_pos = new int [1], y_pos = new int [1]; - OS.gtk_window_get_position (shellHandle, x_pos, y_pos); - OS.gtk_window_move (shellHandle, x, y); - if (x_pos [0] != x || y_pos [0] != y) { - moved = true; - oldX = x; - oldY = y; - sendEvent (SWT.Move); - if (isDisposed ()) return 0; - result |= MOVED; - } - } - if (resize) { - width = Math.max (1, Math.max (minWidth, width - trimWidth ())); - height = Math.max (1, Math.max (minHeight, height - trimHeight ())); - if ((style & SWT.RESIZE) != 0) OS.gtk_window_resize (shellHandle, width, height); - boolean changed = width != oldWidth || height != oldHeight; - if (changed) { - oldWidth = width; - oldHeight = height; - result |= RESIZED; - } - resizeBounds (width, height, changed); - } - return result; -} - -void setCursor (int /*long*/ cursor) { - if (enableWindow != 0) { - OS.gdk_window_set_cursor (enableWindow, cursor); - if (!OS.GDK_WINDOWING_X11 ()) { - OS.gdk_flush (); - } else { - int /*long*/ xDisplay = OS.GDK_DISPLAY (); - OS.XFlush (xDisplay); - } - } - super.setCursor (cursor); -} - -public void setEnabled (boolean enabled) { - checkWidget(); - if (((state & DISABLED) == 0) == enabled) return; - Display display = this.display; - Control control = null; - boolean fixFocus = false; - if (!enabled) { - if (display.focusEvent != SWT.FocusOut) { - control = display.getFocusControl (); - fixFocus = isFocusAncestor (control); - } - } - if (enabled) { - state &= ~DISABLED; - } else { - state |= DISABLED; - } - enableWidget (enabled); - if (isDisposed ()) return; - if (enabled) { - if (enableWindow != 0) { - OS.gdk_window_set_user_data (enableWindow, 0); - OS.gdk_window_destroy (enableWindow); - enableWindow = 0; - } - } else { - int /*long*/ parentHandle = shellHandle; - OS.gtk_widget_realize (parentHandle); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (parentHandle); - Rectangle rect = getBounds (); - GdkWindowAttr attributes = new GdkWindowAttr (); - attributes.width = rect.width; - attributes.height = rect.height; - attributes.event_mask = (0xFFFFFFFF & ~OS.ExposureMask); - attributes.wclass = OS.GDK_INPUT_ONLY; - attributes.window_type = OS.GDK_WINDOW_CHILD; - enableWindow = OS.gdk_window_new (window, attributes, 0); - if (enableWindow != 0) { - if (cursor != null) { - OS.gdk_window_set_cursor (enableWindow, cursor.handle); - if (!OS.GDK_WINDOWING_X11 ()) { - OS.gdk_flush (); - } else { - int /*long*/ xDisplay = OS.GDK_DISPLAY (); - OS.XFlush (xDisplay); - } - } - OS.gdk_window_set_user_data (enableWindow, parentHandle); - OS.gdk_window_show (enableWindow); - } - } - if (fixFocus) fixFocus (control); - if (enabled && display.activeShell == this) { - 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 (fullScreen) { - OS.gtk_window_fullscreen (shellHandle); - } else { - OS.gtk_window_unfullscreen (shellHandle); - if (maximized) { - setMaximized (true); - } - } - this.fullScreen = fullScreen; -} - -/** - * 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(); -} - -void setInitialBounds () { - if ((state & FOREIGN_HANDLE) != 0) return; - int width = OS.gdk_screen_width () * 5 / 8; - int height = OS.gdk_screen_height () * 5 / 8; - int /*long*/ screen = OS.gdk_screen_get_default (); - if (screen != 0) { - if (OS.gdk_screen_get_n_monitors (screen) > 1) { - int monitorNumber = OS.gdk_screen_get_monitor_at_window (screen, paintWindow ()); - GdkRectangle dest = new GdkRectangle (); - OS.gdk_screen_get_monitor_geometry (screen, monitorNumber, dest); - width = dest.width * 5 / 8; - height = dest.height * 5 / 8; - } - } - if ((style & SWT.RESIZE) != 0) { - OS.gtk_window_resize (shellHandle, width, height); - } - resizeBounds (width, height, false); -} - -public void setMaximized (boolean maximized) { - checkWidget(); - super.setMaximized (maximized); - if (maximized) { - OS.gtk_window_maximize (shellHandle); - } else { - OS.gtk_window_unmaximize (shellHandle); - } -} - -public void setMenuBar (Menu menu) { - checkWidget(); - if (menuBar == menu) return; - boolean both = menu != null && menuBar != null; - if (menu != null) { - if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR); - if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT); - } - if (menuBar != null) { - int /*long*/ menuHandle = menuBar.handle; - OS.gtk_widget_hide (menuHandle); - destroyAccelGroup (); - } - menuBar = menu; - if (menuBar != null) { - int /*long*/ menuHandle = menu.handle; - OS.gtk_widget_show (menuHandle); - createAccelGroup (); - menuBar.addAccelerators (accelGroup); - } - int width = OS.GTK_WIDGET_WIDTH (vboxHandle); - int height = OS.GTK_WIDGET_HEIGHT (vboxHandle); - resizeBounds (width, height, !both); -} - -public void setMinimized (boolean minimized) { - checkWidget(); - if (this.minimized == minimized) return; - super.setMinimized (minimized); - if (minimized) { - OS.gtk_window_iconify (shellHandle); - } else { - OS.gtk_window_deiconify (shellHandle); - bringToTop (false); - } -} - -/** - * 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 (); - GdkGeometry geometry = new GdkGeometry (); - minWidth = geometry.min_width = Math.max (width, trimWidth ()) - trimWidth (); - minHeight = geometry.min_height = Math.max (height, trimHeight ()) - trimHeight (); - OS.gtk_window_set_geometry_hints (shellHandle, 0, geometry, OS.GDK_HINT_MIN_SIZE); -} - -/** - * 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; -} - -/** - * 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; - super.setRegion (region); -} - -/* - * Shells are never labelled by other widgets, so no initialization is needed. - */ -void setRelations() { -} - -public void setText (String string) { - super.setText (string); - - /* - * GTK bug 82013. For some reason, if the title string - * is less than 7 bytes long and is not terminated by - * a space, some window managers occasionally draw - * garbage after the last character in the title. - * The fix is to pad the title. - */ - int length = string.length (); - char [] chars = new char [Math.max (6, length) + 1]; - string.getChars (0, length , chars, 0); - for (int i=length; i<chars.length; i++) chars [i] = ' '; - byte [] buffer = Converter.wcsToMbcs (null, chars, true); - OS.gtk_window_set_title (shellHandle, buffer); -} - -public void setVisible (boolean visible) { - checkWidget(); - int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL; - if ((style & mask) != 0) { - if (visible) { - display.setModalShell (this); - OS.gtk_window_set_modal (shellHandle, true); - } else { - display.clearModal (this); - OS.gtk_window_set_modal (shellHandle, false); - } - } else { - updateModal (); - } - showWithParent = visible; - if ((OS.GTK_WIDGET_MAPPED (shellHandle) == visible)) return; - if (visible) { - if (center && !moved) { - center (); - if (isDisposed ()) return; - } - sendEvent (SWT.Show); - if (isDisposed ()) return; - - /* - * In order to ensure that the shell is visible - * and fully painted, dispatch events such as - * GDK_MAP and GDK_CONFIGURE, until the GDK_MAP - * event for the shell is received. - * - * Note that if the parent is minimized or withdrawn - * from the desktop, this should not be done since - * the shell not will be mapped until the parent is - * unminimized or shown on the desktop. - */ - OS.gtk_widget_show (shellHandle); - if (enableWindow != 0) OS.gdk_window_raise (enableWindow); - if (!OS.GTK_IS_PLUG (shellHandle)) { - mapped = false; - if (isDisposed ()) return; - display.dispatchEvents = new int [] { - OS.GDK_EXPOSE, - OS.GDK_FOCUS_CHANGE, - OS.GDK_CONFIGURE, - OS.GDK_MAP, - OS.GDK_UNMAP, - OS.GDK_NO_EXPOSE, - }; - Display display = this.display; - display.putGdkEvents(); - boolean iconic = false; - Shell shell = parent != null ? parent.getShell() : null; - do { - OS.g_main_context_iteration (0, false); - if (isDisposed ()) break; - iconic = minimized || (shell != null && shell.minimized); - } while (!mapped && !iconic); - display.dispatchEvents = null; - if (isDisposed ()) return; - if (!iconic) { - update (true, true); - if (isDisposed ()) return; - adjustTrim (); - } - } - mapped = true; - - if ((style & mask) != 0) { - OS.gdk_pointer_ungrab (OS.GDK_CURRENT_TIME); - } - opened = true; - if (!moved) { - moved = true; - Point location = getLocation(); - oldX = location.x; - oldY = location.y; - 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 { - fixActiveShell (); - OS.gtk_widget_hide (shellHandle); - sendEvent (SWT.Hide); - } -} - -void setZOrder (Control sibling, boolean above, boolean fixRelations) { - /* - * Bug in GTK+. Changing the toplevel window Z-order causes - * X to send a resize event. Before the shell is mapped, these - * resize events always have a size of 200x200, causing extra - * layout work to occur. The fix is to modify the Z-order only - * if the shell has already been mapped at least once. - */ - /* Shells are never included in labelled-by relations */ - if (mapped) setZOrder (sibling, above, false, false); -} - -int /*long*/ shellMapProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { - mapped = true; - display.dispatchEvents = null; - return 0; -} - -void showWidget () { - if ((state & FOREIGN_HANDLE) != 0) return; - OS.gtk_container_add (shellHandle, vboxHandle); - if (scrolledHandle != 0) OS.gtk_widget_show (scrolledHandle); - if (handle != 0) OS.gtk_widget_show (handle); - if (vboxHandle != 0) OS.gtk_widget_show (vboxHandle); -} - -int /*long*/ sizeAllocateProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { - int offset = 16; - int [] x = new int [1], y = new int [1]; - OS.gdk_window_get_pointer (0, x, y, null); - y [0] += offset; - int /*long*/ screen = OS.gdk_screen_get_default (); - if (screen != 0) { - int monitorNumber = OS.gdk_screen_get_monitor_at_point (screen, x[0], y[0]); - GdkRectangle dest = new GdkRectangle (); - OS.gdk_screen_get_monitor_geometry (screen, monitorNumber, dest); - int width = OS.GTK_WIDGET_WIDTH (handle); - int height = OS.GTK_WIDGET_HEIGHT (handle); - if (x[0] + width > dest.x + dest.width) { - x [0] = (dest.x + dest.width) - width; - } - if (y[0] + height > dest.y + dest.height) { - y[0] = (dest.y + dest.height) - height; - } - } - OS.gtk_window_move (handle, x [0], y [0]); - return 0; -} - -int /*long*/ sizeRequestProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { - OS.gtk_widget_hide (handle); - return 0; -} - -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; - if (fullScreen) 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.titleResizeTrimHeight; - if (hasBorder) return display.titleBorderTrimHeight; - return display.titleTrimHeight; - } - if (hasResize) return display.resizeTrimHeight; - if (hasBorder) return display.borderTrimHeight; - return 0; -} - -int trimWidth () { - if ((style & SWT.NO_TRIM) != 0) return 0; - if (fullScreen) 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.titleResizeTrimWidth; - if (hasBorder) return display.titleBorderTrimWidth; - return display.titleTrimWidth; - } - if (hasResize) return display.resizeTrimWidth; - if (hasBorder) return display.borderTrimWidth; - return 0; -} - -void updateModal () { - int /*long*/ group = 0; - if (display.getModalDialog () == null) { - Shell modal = getModalShell (); - int mask = SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL; - Composite shell = null; - if (modal == null) { - if ((style & mask) != 0) shell = this; - } else { - shell = modal; - } - while (shell != null) { - if ((shell.style & mask) == 0) { - group = shell.getShell ().group; - break; - } - shell = shell.parent; - } - } - if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0) && group == 0) { - /* - * Feature in GTK. Starting with GTK version 2.10, GTK - * doesn't assign windows to a default group. The fix is to - * get the handle of the default group and add windows to the - * group. - */ - group = OS.gtk_window_get_group(0); - } - if (group != 0) { - OS.gtk_window_group_add_window (group, shellHandle); - } else { - if (modalGroup != 0) { - OS.gtk_window_group_remove_window (modalGroup, shellHandle); - } - } - if (OS.GTK_VERSION < OS.VERSION (2, 4, 0)) { - fixModal (group, modalGroup); - } - modalGroup = group; -} - -void updateMinimized (boolean minimized) { - Shell[] shells = getShells (); - for (int i = 0; i < shells.length; i++) { - boolean update = false; - Shell shell = shells[i]; - while (shell != null && shell != this && !shell.isUndecorated ()) { - shell = (Shell) shell.getParent (); - } - if (shell != null && shell != this) update = true; - if (update) { - if (minimized) { - if (shells[i].isVisible ()) { - shells[i].showWithParent = true; - OS.gtk_widget_hide(shells[i].shellHandle); - } - } else { - if (shells[i].showWithParent) { - shells[i].showWithParent = false; - OS.gtk_widget_show(shells[i].shellHandle); - } - } - } - } -} - -void deregister () { - super.deregister (); - display.removeWidget (shellHandle); -} - -public void dispose () { - /* - * Note: It is valid to attempt to dispose a widget - * more than once. If this happens, fail silently. - */ - if (isDisposed()) return; - fixActiveShell (); - OS.gtk_widget_hide (shellHandle); - super.dispose (); -} - -/** - * 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); -} - -public Rectangle getBounds () { - checkWidget (); - int [] x = new int [1], y = new int [1]; - OS.gtk_window_get_position (shellHandle, x, y); - int width = OS.GTK_WIDGET_WIDTH (vboxHandle); - int height = OS.GTK_WIDGET_HEIGHT (vboxHandle); - int border = 0; - if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.SHELL_TRIM)) == 0) { - border = OS.gtk_container_get_border_width (shellHandle); - } - return new Rectangle (x [0], y [0], width + trimWidth () + 2*border, height + trimHeight () + 2*border); -} - -void releaseHandle () { - super.releaseHandle (); - shellHandle = 0; -} - -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); - } - } - if (toolTips != null) { - for (int i=0; i<toolTips.length; i++) { - ToolTip toolTip = toolTips [i]; - if (toolTip != null && !toolTip.isDisposed ()) { - toolTip.dispose (); - } - } - toolTips = null; - } - super.releaseChildren (destroy); -} - -void releaseWidget () { - super.releaseWidget (); - destroyAccelGroup (); - display.clearModal (this); - if (display.activeShell == this) display.activeShell = null; - if (tooltipsHandle != 0) OS.g_object_unref (tooltipsHandle); - tooltipsHandle = 0; - if (group != 0) OS.g_object_unref (group); - group = modalGroup = 0; - int /*long*/ window = OS.GTK_WIDGET_WINDOW (shellHandle); - OS.gdk_window_remove_filter(window, display.filterProc, shellHandle); - lastActive = null; -} - -void setToolTipText (int /*long*/ tipWidget, String string) { - setToolTipText (tipWidget, tipWidget, string); -} - -void setToolTipText (int /*long*/ rootWidget, int /*long*/ tipWidget, String string) { - if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0)) { - byte [] buffer = null; - if (string != null && string.length () > 0) { - char [] chars = fixMnemonic (string, false); - buffer = Converter.wcsToMbcs (null, chars, true); - } - OS.gtk_widget_set_tooltip_text (rootWidget, null); - /* - * Bug in GTK. In GTK 2.12, due to a miscalculation of window - * coordinates, using gtk_tooltip_trigger_tooltip_query () - * to update an existing a tooltip will result in the tooltip - * being displayed at a wrong position. The fix is to send out - * 2 fake GDK_MOTION_NOTIFY events (to mimic the GTK call) which - * contain the proper x and y coordinates. - */ - int /*long*/ eventPtr = 0; - int /*long*/ tipWindow = OS.GTK_WIDGET_WINDOW (rootWidget); - if (tipWindow != 0) { - int [] x = new int [1], y = new int [1]; - int /*long*/ window = OS.gdk_window_at_pointer (x, y); - int /*long*/ [] user_data = new int /*long*/ [1]; - if (window != 0) OS.gdk_window_get_user_data (window, user_data); - if (tipWidget == user_data [0]) { - eventPtr = OS.gdk_event_new (OS.GDK_MOTION_NOTIFY); - GdkEventMotion event = new GdkEventMotion (); - event.type = OS.GDK_MOTION_NOTIFY; - event.window = OS.g_object_ref (tipWindow); - event.x = x [0]; - event.y = y [0]; - OS.gdk_window_get_origin (window, x, y); - event.x_root = event.x + x [0]; - event.y_root = event.y + y [0]; - OS.memmove (eventPtr, event, GdkEventMotion.sizeof); - OS.gtk_main_do_event (eventPtr); - } - } - OS.gtk_widget_set_tooltip_text (rootWidget, buffer); - if (eventPtr != 0) { - OS.gtk_main_do_event (eventPtr); - OS.gdk_event_free (eventPtr); - } - } else { - byte [] buffer = null; - if (string != null && string.length () > 0) { - char [] chars = fixMnemonic (string, false); - buffer = Converter.wcsToMbcs (null, chars, true); - } - if (tooltipsHandle == 0) { - tooltipsHandle = OS.gtk_tooltips_new (); - if (tooltipsHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.g_object_ref (tooltipsHandle); - OS.gtk_object_sink (tooltipsHandle); - } - - /* - * Feature in GTK. There is no API to position a tooltip. - * The fix is to connect to the size_allocate signal for - * the tooltip window and position it before it is mapped. - * - * Bug in Solaris-GTK. Invoking gtk_tooltips_force_window() - * can cause a crash in older versions of GTK. The fix is - * to avoid this call if the GTK version is older than 2.2.x. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 2, 1)) { - OS.gtk_tooltips_force_window (tooltipsHandle); - } - int /*long*/ tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (tooltipsHandle); - if (tipWindow != 0 && tipWindow != tooltipWindow) { - OS.g_signal_connect (tipWindow, OS.size_allocate, display.sizeAllocateProc, shellHandle); - tooltipWindow = tipWindow; - } - - /* - * Bug in GTK. If the cursor is inside the window when a new - * tooltip is set and the old tooltip is hidden, the new tooltip - * is not displayed until the mouse re-enters the window. The - * fix is force the new tooltip to be active. - */ - boolean set = true; - if (tipWindow != 0) { - if ((OS.GTK_WIDGET_FLAGS (tipWidget) & (OS.GTK_REALIZED | OS.GTK_VISIBLE)) != 0) { - int [] x = new int [1], y = new int [1]; - int /*long*/ window = OS.gdk_window_at_pointer (x, y); - if (window != 0) { - int /*long*/ [] user_data = new int /*long*/ [1]; - OS.gdk_window_get_user_data (window, user_data); - if (tipWidget == user_data [0]) { - /* - * Feature in GTK. Calling gtk_tooltips_set_tip() positions and - * shows the tooltip. If the tooltip is already visible, moving - * it to a new location in the size_allocate signal causes flashing. - * The fix is to hide the tip window in the size_request signal - * and before the new tooltip is forced to be active. - */ - set = false; - int handler_id = OS.g_signal_connect (tipWindow, OS.size_request, display.sizeRequestProc, shellHandle); - OS.gtk_tooltips_set_tip (tooltipsHandle, tipWidget, buffer, null); - OS.gtk_widget_hide (tipWindow); - int /*long*/ data = OS.gtk_tooltips_data_get (tipWidget); - OS.GTK_TOOLTIPS_SET_ACTIVE (tooltipsHandle, data); - OS.gtk_tooltips_set_tip (tooltipsHandle, tipWidget, buffer, null); - if (handler_id != 0) OS.g_signal_handler_disconnect (tipWindow, handler_id); - } - } - } - } - if (set) OS.gtk_tooltips_set_tip (tooltipsHandle, tipWidget, buffer, null); - } - -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java deleted file mode 100644 index 61d636b946..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Slider.java +++ /dev/null @@ -1,614 +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.gtk.*; -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 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 { - int detail; - boolean dragSent; -/** - * 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); -} - -void createHandle (int index) { - state |= HANDLE; - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - int /*long*/ hAdjustment = OS.gtk_adjustment_new (0, 0, 100, 1, 10, 10); - if (hAdjustment == 0) error (SWT.ERROR_NO_HANDLES); - if ((style & SWT.HORIZONTAL) != 0) { - handle = OS.gtk_hscrollbar_new (hAdjustment); - } else { - handle = OS.gtk_vscrollbar_new (hAdjustment); - } - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - /* - * Bug in GTK. In GTK 2.10, the buttons on either end of - * a horizontal slider are created taller then the slider bar - * when the GTK_CAN_FOCUS flag is set. The fix is not to set - * the flag for horizontal bars in all versions of 2.10. Note - * that a bug has been logged with GTK about this issue. - * (http://bugzilla.gnome.org/show_bug.cgi?id=475909) - */ - if (OS.GTK_VERSION < OS.VERSION (2, 10, 0) || (style & SWT.VERTICAL) != 0) { - OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS); - } - OS.gtk_container_add (fixedHandle, handle); -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ eventPtr) { - int /*long*/ result = super.gtk_button_press_event (widget, eventPtr); - if (result != 0) return result; - detail = OS.GTK_SCROLL_NONE; - dragSent = false; - return result; -} - -int /*long*/ gtk_change_value (int /*long*/ widget, int /*long*/ scroll, int /*long*/ value1, int /*long*/ value2) { - detail = (int)/*64*/scroll; - return 0; -} - -int /*long*/ gtk_value_changed (int /*long*/ adjustment) { - Event event = new Event (); - dragSent = detail == OS.GTK_SCROLL_JUMP; - switch (detail) { - case OS.GTK_SCROLL_NONE: event.detail = SWT.NONE; break; - case OS.GTK_SCROLL_JUMP: event.detail = SWT.DRAG; break; - case OS.GTK_SCROLL_START: event.detail = SWT.HOME; break; - case OS.GTK_SCROLL_END: event.detail = SWT.END; break; - case OS.GTK_SCROLL_PAGE_DOWN: - case OS.GTK_SCROLL_PAGE_RIGHT: - case OS.GTK_SCROLL_PAGE_FORWARD: event.detail = SWT.PAGE_DOWN; break; - case OS.GTK_SCROLL_PAGE_UP: - case OS.GTK_SCROLL_PAGE_LEFT: - case OS.GTK_SCROLL_PAGE_BACKWARD: event.detail = SWT.PAGE_UP; break; - case OS.GTK_SCROLL_STEP_DOWN: - case OS.GTK_SCROLL_STEP_RIGHT: - case OS.GTK_SCROLL_STEP_FORWARD: event.detail = SWT.ARROW_DOWN; break; - case OS.GTK_SCROLL_STEP_UP: - case OS.GTK_SCROLL_STEP_LEFT: - case OS.GTK_SCROLL_STEP_BACKWARD: event.detail = SWT.ARROW_UP; break; - } - if (!dragSent) detail = OS.GTK_SCROLL_NONE; - postEvent (SWT.Selection, event); - return 0; -} - -int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) { - GdkEvent gtkEvent = new GdkEvent (); - OS.memmove (gtkEvent, gdkEvent, GdkEvent.sizeof); - switch (gtkEvent.type) { - case OS.GDK_BUTTON_RELEASE: { - GdkEventButton gdkEventButton = new GdkEventButton (); - OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof); - if (gdkEventButton.button == 1 && detail == SWT.DRAG) { - if (!dragSent) { - Event event = new Event (); - event.detail = SWT.DRAG; - postEvent (SWT.Selection, event); - } - postEvent (SWT.Selection); - } - detail = OS.GTK_SCROLL_NONE; - dragSent = false; - break; - } - } - return super.gtk_event_after (widget, gdkEvent); -} - -void hookEvents () { - super.hookEvents (); - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) { - OS.g_signal_connect_closure (handle, OS.change_value, display.closures [CHANGE_VALUE], false); - } - OS.g_signal_connect_closure (handle, OS.value_changed, display.closures [VALUE_CHANGED], false); -} - -void register () { - super.register (); - int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle); - display.addWidget (hAdjustment, this); -} - -void deregister () { - super.deregister (); - int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle); - display.removeWidget (hAdjustment); -} - -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; - Point size = computeNativeSize(handle, wHint, hHint, changed); - if ((style & SWT.HORIZONTAL) != 0) { - if (wHint == SWT.DEFAULT) size.x = 2 * size.x; - } else { - if (hHint == SWT.DEFAULT) size.y = 2 * size.y; - } - return size; -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - return (int) adjustment.step_increment; -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - return (int) adjustment.upper; -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - return (int) adjustment.lower; -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - return (int) adjustment.page_increment; -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - return (int) adjustment.value; -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - return (int) adjustment.page_size; -} - -/** - * 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 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; - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_range_set_increments (handle, value, getPageIncrement ()); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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 (); - int /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - int minimum = (int) adjustment.lower; - if (value <= minimum) return; - adjustment.upper = value; - adjustment.page_size = Math.min ((int)adjustment.page_size, value - minimum); - adjustment.value = Math.min ((int)adjustment.value, (int)(value - adjustment.page_size)); - OS.memmove (hAdjustment, adjustment); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_adjustment_changed (hAdjustment); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - int maximum = (int) adjustment.upper; - if (value >= maximum) return; - adjustment.lower = value; - adjustment.page_size = Math.min ((int)adjustment.page_size, maximum - value); - adjustment.value = Math.max ((int)adjustment.value, value); - OS.memmove (hAdjustment, adjustment); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_adjustment_changed (hAdjustment); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -void setOrientation () { - super.setOrientation (); - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - if ((style & SWT.HORIZONTAL) != 0) { - OS.gtk_range_set_inverted (handle, true); - } - } -} - -/** - * 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; - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_range_set_increments (handle, getIncrement (), value); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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 (); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_range_set_value (handle, value); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - value = (int) Math.min (value, (int)(adjustment.upper - adjustment.lower)); - adjustment.page_size = (double) value; - adjustment.value = Math.min ((int)adjustment.value, (int)(adjustment.upper - value)); - OS.memmove (hAdjustment, adjustment); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_adjustment_changed (hAdjustment); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - adjustment.value = Math.min (Math.max (selection, minimum), maximum - thumb); - adjustment.lower = (double) minimum; - adjustment.upper = (double) maximum; - adjustment.page_size = (double) thumb; - adjustment.step_increment = (double) increment; - adjustment.page_increment = (double) pageIncrement; - OS.memmove (hAdjustment, adjustment); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_adjustment_changed (hAdjustment); - OS.gtk_adjustment_value_changed (hAdjustment); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java deleted file mode 100644 index b08c147222..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Spinner.java +++ /dev/null @@ -1,1203 +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.gtk.*; -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 { - static final int MIN_ARROW_WIDTH = 6; - int lastEventTime = 0; - int /*long*/ gdkEventKey = 0; - int fixStart = -1, fixEnd = -1; - - /** - * 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 final static 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[] w = new int [1], h = new int [1]; - OS.gtk_widget_realize (handle); - int /*long*/ layout = OS.gtk_entry_get_layout (handle); - int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - int digits = OS.gtk_spin_button_get_digits (handle); - for (int i = 0; i < digits; i++) adjustment.upper *= 10; - String string = String.valueOf ((int) adjustment.upper); - if (digits > 0) { - StringBuffer buffer = new StringBuffer (); - buffer.append (string); - buffer.append (getDecimalSeparator ()); - int count = digits - string.length (); - while (count >= 0) { - buffer.append ("0"); - count--; - } - string = buffer.toString (); - } - byte [] buffer1 = Converter.wcsToMbcs (null, string, false); - int /*long*/ ptr = OS.pango_layout_get_text (layout); - int length = OS.strlen (ptr); - byte [] buffer2 = new byte [length]; - OS.memmove (buffer2, ptr, length); - OS.pango_layout_set_text (layout, buffer1, buffer1.length); - OS.pango_layout_get_size (layout, w, h); - OS.pango_layout_set_text (layout, buffer2, buffer2.length); - int width = OS.PANGO_PIXELS (w [0]); - int height = OS.PANGO_PIXELS (h [0]); - width = wHint == SWT.DEFAULT ? width : wHint; - height = hHint == SWT.DEFAULT ? height : hHint; - 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 (); - int xborder = 0, yborder = 0; - int /*long*/ style = OS.gtk_widget_get_style (handle); - if ((this.style & SWT.BORDER) != 0) { - xborder += OS.gtk_style_get_xthickness (style); - yborder += OS.gtk_style_get_ythickness (style); - } - int [] property = new int [1]; - OS.gtk_widget_style_get (handle, OS.interior_focus, property, 0); - if (property [0] == 0) { - OS.gtk_widget_style_get (handle, OS.focus_line_width, property, 0); - xborder += property [0]; - yborder += property [0]; - } - int /*long*/ fontDesc = OS.gtk_style_get_font_desc (style); - int fontSize = OS.pango_font_description_get_size (fontDesc); - int arrowSize = Math.max (OS.PANGO_PIXELS (fontSize), MIN_ARROW_WIDTH); - arrowSize = arrowSize - arrowSize % 2; - Rectangle trim = super.computeTrim (x, y, width, height); - trim.x -= xborder; - trim.y -= yborder; - trim.width += 2 * xborder; - trim.height += 2 * yborder; - trim.width += arrowSize + (2 * OS.gtk_style_get_xthickness (style)); - GtkBorder innerBorder = Display.getEntryInnerBorder (handle); - trim.x -= innerBorder.left; - trim.y -= innerBorder.top; - trim.width += innerBorder.left + innerBorder.right; - trim.height += innerBorder.top + innerBorder.bottom; - return new Rectangle (trim.x, trim.y, trim.width, trim.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 (); - OS.gtk_editable_copy_clipboard (handle); -} - -void createHandle (int index) { - state |= HANDLE | MENU; - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - int /*long*/ adjustment = OS.gtk_adjustment_new (0, 0, 100, 1, 10, 0); - if (adjustment == 0) error (SWT.ERROR_NO_HANDLES); - handle = OS.gtk_spin_button_new (adjustment, 1, 0); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (fixedHandle, handle); - OS.gtk_editable_set_editable (handle, (style & SWT.READ_ONLY) == 0); - OS.gtk_entry_set_has_frame (handle, (style & SWT.BORDER) != 0); - OS.gtk_spin_button_set_wrap (handle, (style & SWT.WRAP) != 0); -} - -/** - * 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 (); - OS.gtk_editable_cut_clipboard (handle); -} - -void deregister () { - super.deregister (); - int /*long*/ imContext = imContext (); - if (imContext != 0) display.removeWidget (imContext); -} - -int /*long*/ eventWindow () { - return paintWindow (); -} - -int /*long*/ enterExitHandle () { - return fixedHandle; -} - -boolean filterKey (int keyval, int /*long*/ event) { - int time = OS.gdk_event_get_time (event); - if (time != lastEventTime) { - lastEventTime = time; - int /*long*/ imContext = imContext (); - if (imContext != 0) { - return OS.gtk_im_context_filter_keypress (imContext, event); - } - } - gdkEventKey = event; - return false; -} - -void fixIM () { - /* - * The IM filter has to be called one time for each key press event. - * When the IM is open the key events are duplicated. The first event - * is filtered by SWT and the second event is filtered by GTK. In some - * cases the GTK handler does not run (the widget is destroyed, the - * application code consumes the event, etc), for these cases the IM - * filter has to be called by SWT. - */ - if (gdkEventKey != 0 && gdkEventKey != -1) { - int /*long*/ imContext = imContext (); - if (imContext != 0) { - OS.gtk_im_context_filter_keypress (imContext, gdkEventKey); - gdkEventKey = -1; - return; - } - } - gdkEventKey = 0; -} - -GdkColor getBackgroundColor () { - return getBaseColor (); -} - -public int getBorderWidth () { - checkWidget(); - int /*long*/ style = OS.gtk_widget_get_style (handle); - if ((this.style & SWT.BORDER) != 0) { - return OS.gtk_style_get_xthickness (style); - } - return 0; -} - -GdkColor getForegroundColor () { - return getTextColor (); -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - int digits = OS.gtk_spin_button_get_digits (handle); - double value = adjustment.step_increment; - for (int i = 0; i < digits; i++) value *= 10; - return (int) (value > 0 ? value + 0.5 : value - 0.5); -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - int digits = OS.gtk_spin_button_get_digits (handle); - double value = adjustment.upper; - for (int i = 0; i < digits; i++) value *= 10; - return (int) (value > 0 ? value + 0.5 : value - 0.5); -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - int digits = OS.gtk_spin_button_get_digits (handle); - double value = adjustment.lower; - for (int i = 0; i < digits; i++) value *= 10; - return (int) (value > 0 ? value + 0.5 : value - 0.5); -} - -/** - * 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 (); - int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - int digits = OS.gtk_spin_button_get_digits (handle); - double value = adjustment.page_increment; - for (int i = 0; i < digits; i++) value *= 10; - return (int) (value > 0 ? value + 0.5 : value - 0.5); -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - int digits = OS.gtk_spin_button_get_digits (handle); - double value = adjustment.value; - for (int i = 0; i < digits; i++) value *= 10; - return (int) (value > 0 ? value + 0.5 : value - 0.5); -} - -/** - * 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 /*long*/ str = OS.gtk_entry_get_text (handle); - if (str == 0) return ""; - int length = OS.strlen (str); - byte [] buffer = new byte [length]; - OS.memmove (buffer, str, length); - return new String (Converter.mbcsToWcs (null, 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 limit = OS.gtk_entry_get_max_length (handle); - return limit == 0 ? 0xFFFF : limit; -} - -/** - * 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 (); - return OS.gtk_spin_button_get_digits (handle); -} - -String getDecimalSeparator () { - int /*long*/ 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)); -} - -int /*long*/ gtk_activate (int /*long*/ widget) { - postEvent (SWT.DefaultSelection); - return 0; -} - -int /*long*/ gtk_changed (int /*long*/ widget) { - int /*long*/ str = OS.gtk_entry_get_text (handle); - int length = OS.strlen (str); - if (length > 0) { - int /*long*/ [] endptr = new int /*long*/ [1]; - double value = OS.g_strtod (str, endptr); - if (endptr [0] == str + length) { - int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - if (value != adjustment.value && adjustment.lower <= value && value <= adjustment.upper) { - OS.gtk_spin_button_update (handle); - } - } - } - - /* - * Feature in GTK. When the user types, GTK positions - * the caret after sending the changed signal. This - * means that application code that attempts to position - * the caret during a changed signal will fail. The fix - * is to post the modify event when the user is typing. - */ - boolean keyPress = false; - int /*long*/ eventPtr = OS.gtk_get_current_event (); - if (eventPtr != 0) { - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof); - switch (gdkEvent.type) { - case OS.GDK_KEY_PRESS: - keyPress = true; - break; - } - OS.gdk_event_free (eventPtr); - } - if (keyPress) { - postEvent (SWT.Modify); - } else { - sendEvent (SWT.Modify); - } - return 0; -} - -int /*long*/ gtk_commit (int /*long*/ imContext, int /*long*/ text) { - if (text == 0) return 0; - if (!OS.gtk_editable_get_editable (handle)) return 0; - int length = OS.strlen (text); - if (length == 0) return 0; - byte [] buffer = new byte [length]; - OS.memmove (buffer, text, length); - char [] chars = Converter.mbcsToWcs (null, buffer); - char [] newChars = sendIMKeyEvent (SWT.KeyDown, null, chars); - if (newChars == null) return 0; - /* - * Feature in GTK. For a GtkEntry, during the insert-text signal, - * GTK allows the programmer to change only the caret location, - * not the selection. If the programmer changes the selection, - * the new selection is lost. The fix is to detect a selection - * change and set it after the insert-text signal has completed. - */ - fixStart = fixEnd = -1; - OS.g_signal_handlers_block_matched (imContext, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, COMMIT); - int id = OS.g_signal_lookup (OS.commit, OS.gtk_im_context_get_type ()); - int mask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID; - OS.g_signal_handlers_unblock_matched (imContext, mask, id, 0, 0, 0, handle); - if (newChars == chars) { - OS.g_signal_emit_by_name (imContext, OS.commit, text); - } else { - buffer = Converter.wcsToMbcs (null, newChars, true); - OS.g_signal_emit_by_name (imContext, OS.commit, buffer); - } - OS.g_signal_handlers_unblock_matched (imContext, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, COMMIT); - OS.g_signal_handlers_block_matched (imContext, mask, id, 0, 0, 0, handle); - if (fixStart != -1 && fixEnd != -1) { - OS.gtk_editable_set_position (handle, fixStart); - OS.gtk_editable_select_region (handle, fixStart, fixEnd); - } - fixStart = fixEnd = -1; - return 0; -} - -int /*long*/ gtk_delete_text (int /*long*/ widget, int /*long*/ start_pos, int /*long*/ end_pos) { - if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0; - String newText = verifyText ("", (int)/*64*/start_pos, (int)/*64*/end_pos); - if (newText == null) { - OS.g_signal_stop_emission_by_name (handle, OS.delete_text); - } else { - if (newText.length () > 0) { - int [] pos = new int [1]; - pos [0] = (int)/*64*/end_pos; - byte [] buffer = Converter.wcsToMbcs (null, newText, false); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - OS.gtk_editable_insert_text (handle, buffer, buffer.length, pos); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_editable_set_position (handle, pos [0]); - } - } - return 0; -} - -int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) { - if (cursor != null) setCursor (cursor.handle); - return super.gtk_event_after (widget, gdkEvent); -} - -int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) { - fixIM (); - return super.gtk_focus_out_event (widget, event); -} - -int /*long*/ gtk_insert_text (int /*long*/ widget, int /*long*/ new_text, int /*long*/ new_text_length, int /*long*/ position) { -// if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0; - if (new_text == 0 || new_text_length == 0) return 0; - byte [] buffer = new byte [(int)/*64*/new_text_length]; - OS.memmove (buffer, new_text, buffer.length); - String oldText = new String (Converter.mbcsToWcs (null, buffer)); - int [] pos = new int [1]; - OS.memmove (pos, position, 4); - if (pos [0] == -1) { - int /*long*/ ptr = OS.gtk_entry_get_text (handle); - pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1); - } - String newText = verifyText (oldText, pos [0], pos [0]); - if (newText != oldText) { - int [] newStart = new int [1], newEnd = new int [1]; - OS.gtk_editable_get_selection_bounds (handle, newStart, newEnd); - if (newText != null) { - if (newStart [0] != newEnd [0]) { - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_editable_delete_selection (handle); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - } - byte [] buffer3 = Converter.wcsToMbcs (null, newText, false); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - OS.gtk_editable_insert_text (handle, buffer3, buffer3.length, pos); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - newStart [0] = newEnd [0] = pos [0]; - } - pos [0] = newEnd [0]; - if (newStart [0] != newEnd [0]) { - fixStart = newStart [0]; - fixEnd = newEnd [0]; - } - OS.memmove (position, pos, 4); - OS.g_signal_stop_emission_by_name (handle, OS.insert_text); - } - return 0; -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_key_press_event (widget, event); - if (result != 0) fixIM (); - if (gdkEventKey == -1) result = 1; - gdkEventKey = 0; - return result; -} - -int /*long*/ gtk_populate_popup (int /*long*/ widget, int /*long*/ menu) { - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - OS.gtk_widget_set_direction (menu, OS.GTK_TEXT_DIR_RTL); - OS.gtk_container_forall (menu, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL); - } - return 0; -} - -int /*long*/ gtk_value_changed (int /*long*/ widget) { - postEvent (SWT.Selection); - return 0; -} - -void hookEvents () { - super.hookEvents(); - OS.g_signal_connect_closure (handle, OS.changed, display.closures [CHANGED], true); - OS.g_signal_connect_closure (handle, OS.insert_text, display.closures [INSERT_TEXT], false); - OS.g_signal_connect_closure (handle, OS.delete_text, display.closures [DELETE_TEXT], false); - OS.g_signal_connect_closure (handle, OS.value_changed, display.closures [VALUE_CHANGED], false); - OS.g_signal_connect_closure (handle, OS.activate, display.closures [ACTIVATE], false); - OS.g_signal_connect_closure (handle, OS.populate_popup, display.closures [POPULATE_POPUP], false); - int /*long*/ imContext = imContext (); - if (imContext != 0) { - OS.g_signal_connect_closure (imContext, OS.commit, display.closures [COMMIT], false); - int id = OS.g_signal_lookup (OS.commit, OS.gtk_im_context_get_type ()); - int mask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID; - OS.g_signal_handlers_block_matched (imContext, mask, id, 0, 0, 0, handle); - } -} - -int /*long*/ imContext () { - return OS.GTK_ENTRY_IM_CONTEXT (handle); -} - -int /*long*/ paintWindow () { - int /*long*/ window = super.paintWindow (); - int /*long*/ children = OS.gdk_window_get_children (window); - if (children != 0) window = OS.g_list_data (children); - OS.g_list_free (children); - return window; -} - -/** - * 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 (); - OS.gtk_editable_paste_clipboard (handle); -} - -void register () { - super.register (); - int /*long*/ imContext = imContext (); - if (imContext != 0) display.addWidget (imContext, this); -} - -void releaseWidget () { - super.releaseWidget (); - fixIM (); -} - -/** - * 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 setBackgroundColor (GdkColor color) { - super.setBackgroundColor (color); - OS.gtk_widget_modify_base (handle, 0, color); -} - -void setCursor (int /*long*/ cursor) { - int /*long*/ defaultCursor = 0; - if (cursor == 0) defaultCursor = OS.gdk_cursor_new (OS.GDK_XTERM); - super.setCursor (cursor != 0 ? cursor : defaultCursor); - if (cursor == 0) OS.gdk_cursor_destroy (defaultCursor); -} - -void setFontDescription (int /*long*/ font) { - super.setFontDescription (font); -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - double newValue = value; - int digits = OS.gtk_spin_button_get_digits (handle); - for (int i = 0; i < digits; i++) newValue /= 10; - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_spin_button_set_increments (handle, newValue, adjustment.page_increment); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - double newValue = value; - int digits = OS.gtk_spin_button_get_digits (handle); - for (int i = 0; i < digits; i++) newValue /= 10; - if (newValue <= adjustment.lower) return; - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_spin_button_set_range (handle, adjustment.lower, newValue); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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 /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - double newValue = value; - int digits = OS.gtk_spin_button_get_digits (handle); - for (int i = 0; i < digits; i++) newValue /= 10; - if (newValue >= adjustment.upper) return; - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_spin_button_set_range (handle, newValue, adjustment.upper); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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; - int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - double newValue = value; - int digits = OS.gtk_spin_button_get_digits (handle); - for (int i = 0; i < digits; i++) newValue /= 10; - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_spin_button_set_increments (handle, adjustment.step_increment, newValue); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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 (); - double newValue = value; - int digits = OS.gtk_spin_button_get_digits (handle); - for (int i = 0; i < digits; i++) newValue /= 10; - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_spin_button_set_value (handle, newValue); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -/** - * 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); - OS.gtk_entry_set_max_length (handle, limit); -} - -/** - * 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 digits = OS.gtk_spin_button_get_digits (handle); - if (value == digits) return; - int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - int diff = Math.abs (value - digits); - int factor = 1; - for (int i = 0; i < diff; i++) factor *= 10; - if (digits > value) { - adjustment.value *= factor; - adjustment.upper *= factor; - adjustment.lower *= factor; - adjustment.step_increment *= factor; - adjustment.page_increment *= factor; - } else { - adjustment.value /= factor; - adjustment.upper /= factor; - adjustment.lower /= factor; - adjustment.step_increment /= factor; - adjustment.page_increment /= factor; - } - OS.memmove (hAdjustment, adjustment); - OS.gtk_spin_button_set_digits (handle, value); -} - -/** - * 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); - double factor = 1; - for (int i = 0; i < digits; i++) factor *= 10; - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); - OS.gtk_spin_button_set_range (handle, minimum / factor, maximum / factor); - OS.gtk_spin_button_set_increments (handle, increment / factor, pageIncrement / factor); - OS.gtk_spin_button_set_value (handle, selection / factor); - OS.gtk_spin_button_set_digits (handle, digits); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, VALUE_CHANGED); -} - -boolean checkSubwindow () { - return false; -} - -boolean translateTraversal (GdkEventKey keyEvent) { - int key = keyEvent.keyval; - switch (key) { - case OS.GDK_KP_Enter: - case OS.GDK_Return: { - int /*long*/ imContext = imContext (); - if (imContext != 0) { - int /*long*/ [] preeditString = new int /*long*/ [1]; - OS.gtk_im_context_get_preedit_string (imContext, preeditString, null, null); - if (preeditString [0] != 0) { - int length = OS.strlen (preeditString [0]); - OS.g_free (preeditString [0]); - if (length != 0) return false; - } - } - } - } - return super.translateTraversal (keyEvent); -} - -String verifyText (String string, int start, int end) { - if (string.length () == 0 && start == end) return null; - Event event = new Event (); - event.text = string; - event.start = start; - event.end = end; - int /*long*/ eventPtr = OS.gtk_get_current_event (); - if (eventPtr != 0) { - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof); - switch (gdkEvent.type) { - case OS.GDK_KEY_PRESS: - setKeyState (event, gdkEvent); - break; - } - OS.gdk_event_free (eventPtr); - } - int index = 0; - if (OS.gtk_spin_button_get_digits (handle) > 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) { - int /*long*/ hAdjustment = OS.gtk_spin_button_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment); - if (adjustment.lower < 0 && string.charAt (0) == '-') index++; - } - while (index < string.length ()) { - if (!Character.isDigit (string.charAt (index))) break; - index++; - } - event.doit = index == string.length (); - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in the verify - * event. If this happens, answer null to cancel - * the operation. - */ - sendEvent (SWT.Verify, event); - if (!event.doit || isDisposed ()) return null; - return event.text; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java deleted file mode 100644 index 68ddc4b10b..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabFolder.java +++ /dev/null @@ -1,733 +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.gtk.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class implement the notebook user interface - * metaphor. It allows the user to select a notebook page from - * set of pages. - * <p> - * The item children that may be added to instances of this class - * must be of type <code>TabItem</code>. - * <code>Control</code> children are created and then set into a - * tab item using <code>TabItem#setControl</code>. - * </p><p> - * Note that although this class is a subclass of <code>Composite</code>, - * it does not make sense to set a layout on it. - * </p><p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>TOP, BOTTOM</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection</dd> - * </dl> - * <p> - * Note: Only one of the styles TOP and BOTTOM 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/#tabfolder">TabFolder, TabItem 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 TabFolder extends Composite { - TabItem [] items; - ImageList imageList; - -/** - * 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 SWT#TOP - * @see SWT#BOTTOM - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TabFolder (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -static int checkStyle (int style) { - style = checkBits (style, SWT.TOP, SWT.BOTTOM, 0, 0, 0, 0); - /* - * 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); -} - -int /*long*/ childStyle () { - int /*long*/ rcStyle = OS.gtk_widget_get_modifier_style (handle); - if ((OS.gtk_rc_style_get_color_flags (rcStyle, 0) & OS.GTK_RC_BG) != 0) return 0; - OS.gtk_widget_realize (handle); - return OS.gtk_widget_get_style (handle); -} - -/** - * 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> - * When <code>widgetSelected</code> is called, the item field of the event object is valid. - * <code>widgetDefaultSelected</code> is not called. - * </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); -} - -int /*long*/ clientHandle () { - int index = OS.gtk_notebook_get_current_page (handle); - if (index != -1 && items [index] != null) { - return items [index].pageHandle; - } - return handle; -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - Point size = super.computeSize (wHint, hHint, changed); - if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; - if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; - boolean scrollable = OS.gtk_notebook_get_scrollable (handle); - OS.gtk_notebook_set_scrollable (handle, false); - Point notebookSize = computeNativeSize (handle, wHint, hHint, changed); - OS.gtk_notebook_set_scrollable (handle, scrollable); - size.x = Math.max (notebookSize.x, size.x); - size.y = Math.max (notebookSize.y, size.y); - return size; -} - -public Rectangle computeTrim (int x, int y, int width, int height) { - checkWidget(); - forceResize (); - int /*long*/ clientHandle = clientHandle (); - int clientX = OS.GTK_WIDGET_X (clientHandle); - int clientY = OS.GTK_WIDGET_Y (clientHandle); - x -= clientX; - y -= clientY; - width += clientX + clientX; - if ((style & SWT.BOTTOM) != 0) { - int parentHeight = OS.GTK_WIDGET_HEIGHT (handle); - int clientHeight = OS.GTK_WIDGET_HEIGHT (clientHandle); - height += parentHeight - clientHeight; - } else { - height += clientX + clientY; - } - return new Rectangle (x, y, width, height); -} - -void createHandle (int index) { - state |= HANDLE; - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - handle = OS.gtk_notebook_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (fixedHandle, handle); - OS.gtk_notebook_set_scrollable (handle, true); - OS.gtk_notebook_set_show_tabs (handle, true); - if ((style & SWT.BOTTOM) != 0) { - OS.gtk_notebook_set_tab_pos (handle, OS.GTK_POS_BOTTOM); - } -} - -void createWidget (int index) { - super.createWidget(index); - items = new TabItem [4]; -} - -void createItem (TabItem item, int index) { - int /*long*/ list = OS.gtk_container_get_children (handle); - int itemCount = 0; - if (list != 0) { - itemCount = OS.g_list_length (list); - OS.g_list_free (list); - } - if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE); - if (itemCount == items.length) { - TabItem [] newItems = new TabItem [items.length + 4]; - System.arraycopy (items, 0, newItems, 0, items.length); - items = newItems; - } - int /*long*/ boxHandle = OS.gtk_hbox_new (false, 0); - if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ labelHandle = OS.gtk_label_new_with_mnemonic (null); - if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ imageHandle = OS.gtk_image_new (); - if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (boxHandle, imageHandle); - OS.gtk_container_add (boxHandle, labelHandle); - int /*long*/ pageHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (pageHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE); - OS.gtk_notebook_insert_page (handle, pageHandle, boxHandle, index); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE); - OS.gtk_widget_show (boxHandle); - OS.gtk_widget_show (labelHandle); - OS.gtk_widget_show (pageHandle); - item.state |= HANDLE; - item.handle = boxHandle; - item.labelHandle = labelHandle; - item.imageHandle = imageHandle; - item.pageHandle = pageHandle; - System.arraycopy (items, index, items, index + 1, itemCount++ - index); - items [index] = item; - if ((state & FOREGROUND) != 0) { - item.setForegroundColor (getForegroundColor()); - } - if ((state & FONT) != 0) { - item.setFontDescription (getFontDescription()); - } - if (itemCount == 1) { - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE); - OS.gtk_notebook_set_current_page (handle, 0); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE); - Event event = new Event(); - event.item = items[0]; - sendEvent (SWT.Selection, event); - // the widget could be destroyed at this point - } -} - -void destroyItem (TabItem item) { - int index = 0; - int itemCount = getItemCount(); - while (index < itemCount) { - if (items [index] == item) break; - index++; - } - if (index == itemCount) error (SWT.ERROR_ITEM_NOT_REMOVED); - int oldIndex = OS.gtk_notebook_get_current_page (handle); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE); - OS.gtk_notebook_remove_page (handle, index); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE); - System.arraycopy (items, index + 1, items, index, --itemCount - index); - items [itemCount] = null; - if (index == oldIndex) { - int newIndex = OS.gtk_notebook_get_current_page (handle); - if (newIndex != -1) { - Control control = items [newIndex].getControl (); - if (control != null && !control.isDisposed ()) { - control.setBounds (getClientArea()); - control.setVisible (true); - } - Event event = new Event (); - event.item = items [newIndex]; - sendEvent (SWT.Selection, event); - // the widget could be destroyed at this point - } - } -} - -int /*long*/ eventHandle () { - return handle; -} - -/** - * 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 TabItem getItem (int index) { - checkWidget(); - if (!(0 <= index && index < getItemCount())) error (SWT.ERROR_INVALID_RANGE); - int /*long*/ list = OS.gtk_container_get_children (handle); - if (list == 0) error (SWT.ERROR_CANNOT_GET_ITEM); - int itemCount = OS.g_list_length (list); - OS.g_list_free (list); - if (!(0 <= index && index < itemCount)) error (SWT.ERROR_CANNOT_GET_ITEM); - return items [index]; -} - -/** - * Returns the tab 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 tab item at the given point, or null if the point is not in a tab item - * - * @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.4 - */ -public TabItem getItem(Point point) { - checkWidget(); - if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - int /*long*/ list = OS.gtk_container_get_children (handle); - if (list == 0) return null; - int itemCount = OS.g_list_length (list); - OS.g_list_free (list); - for (int i = 0; i < itemCount; i++) { - TabItem item = items[i]; - Rectangle rect = item.getBounds(); - if (rect.contains(point)) return item; - } - 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(); - int /*long*/ list = OS.gtk_container_get_children (handle); - if (list == 0) return 0; - int itemCount = OS.g_list_length (list); - OS.g_list_free (list); - return itemCount; -} - -/** - * Returns an array of <code>TabItem</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 TabItem [] getItems () { - checkWidget(); - int count = getItemCount (); - TabItem [] result = new TabItem [count]; - System.arraycopy (items, 0, result, 0, count); - return result; -} - -/** - * Returns an array of <code>TabItem</code>s that are currently - * selected in the receiver. 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 TabItem [] getSelection () { - checkWidget(); - int index = OS.gtk_notebook_get_current_page (handle); - if (index == -1) return new TabItem [0]; - return new TabItem [] {items [index]}; -} - -/** - * 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 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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(); - return OS.gtk_notebook_get_current_page (handle); -} - -int /*long*/ gtk_focus (int /*long*/ widget, int /*long*/ directionType) { - return 0; -} - -int /*long*/ gtk_switch_page (int /*long*/ widget, int /*long*/ page, int /*long*/ page_num) { - int index = OS.gtk_notebook_get_current_page (handle); - if (index != -1) { - Control control = items [index].getControl (); - if (control != null && !control.isDisposed ()) { - control.setVisible (false); - } - } - TabItem item = items [(int)/*64*/page_num]; - Control control = item.getControl (); - if (control != null && !control.isDisposed ()) { - control.setBounds(getClientArea()); - control.setVisible (true); - } - Event event = new Event(); - event.item = item; - postEvent(SWT.Selection, event); - return 0; -} - -void hookEvents () { - super.hookEvents (); - OS.g_signal_connect_closure (handle, OS.switch_page, display.closures [SWITCH_PAGE], false); -} - -/** - * 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 (TabItem item) { - checkWidget(); - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - int /*long*/ list = OS.gtk_container_get_children (handle); - if (list == 0) return -1; - int count = OS.g_list_length (list); - OS.g_list_free (list); - for (int i=0; i<count; i++) { - if (items [i] == item) return i; - } - return -1; -} - -Point minimumSize (int wHint, int hHint, boolean flushCache) { - Control [] children = _getChildren (); - int width = 0, height = 0; - for (int i=0; i<children.length; i++) { - Control child = children [i]; - int index = 0; - int count = 0; - int /*long*/ list = OS.gtk_container_get_children (handle); - if (list != 0) { - count = OS.g_list_length (list); - OS.g_list_free (list); - } - while (index < count) { - if (items [index].control == child) break; - index++; - } - if (index == count) { - Rectangle rect = child.getBounds (); - width = Math.max (width, rect.x + rect.width); - height = Math.max (height, rect.y + rect.height); - } else { - Point size = child.computeSize (wHint, hHint, flushCache); - width = Math.max (width, size.x); - height = Math.max (height, size.y); - } - } - return new Point (width, height); -} - -boolean mnemonicHit (char key) { - int itemCount = getItemCount (); - for (int i=0; i<itemCount; i++) { - int /*long*/ labelHandle = items [i].labelHandle; - if (labelHandle != 0 && mnemonicHit (labelHandle, key)) return true; - } - return false; -} - -boolean mnemonicMatch (char key) { - int itemCount = getItemCount (); - for (int i=0; i<itemCount; i++) { - int /*long*/ labelHandle = items [i].labelHandle; - if (labelHandle != 0 && mnemonicHit (labelHandle, key)) return true; - } - return false; -} - -void releaseChildren (boolean destroy) { - if (items != null) { - for (int i=0; i<items.length; i++) { - TabItem item = items [i]; - if (item != null && !item.isDisposed ()) { - item.release (false); - } - } - items = null; - } - super.releaseChildren (destroy); -} - -void releaseWidget () { - super.releaseWidget (); - if (imageList != null) imageList.dispose (); - imageList = null; -} - -void removeControl (Control control) { - super.removeControl (control); - int count = getItemCount (); - for (int i=0; i<count; i++) { - TabItem item = items [i]; - if (item.control == control) item.setControl (null); - } -} - -/** - * 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); -} - -int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - int result = super.setBounds (x, y, width, height, move, resize); - if ((result & RESIZED) != 0) { - int index = getSelectionIndex (); - if (index != -1) { - TabItem item = items [index]; - Control control = item.control; - if (control != null && !control.isDisposed ()) { - control.setBounds (getClientArea ()); - } - } - } - return result; -} - -void setFontDescription (int /*long*/ font) { - super.setFontDescription (font); - TabItem [] items = getItems (); - for (int i = 0; i < items.length; i++) { - if (items[i] != null) { - items[i].setFontDescription (font); - } - } -} - -void setForegroundColor (GdkColor color) { - super.setForegroundColor (color); - TabItem [] items = getItems (); - for (int i = 0; i < items.length; i++) { - if (items[i] != null) { - items[i].setForegroundColor (color); - } - } -} - -/** - * 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 items are - * 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 setSelection (int index) { - checkWidget (); - if (!(0 <= index && index < getItemCount ())) return; - setSelection (index, false); -} - -void setSelection (int index, boolean notify) { - if (index < 0) return; - int oldIndex = OS.gtk_notebook_get_current_page (handle); - if (oldIndex == index) return; - if (oldIndex != -1) { - TabItem item = items [oldIndex]; - Control control = item.control; - if (control != null && !control.isDisposed ()) { - control.setVisible (false); - } - } - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE); - OS.gtk_notebook_set_current_page (handle, index); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE); - int newIndex = OS.gtk_notebook_get_current_page (handle); - if (newIndex != -1) { - TabItem item = items [newIndex]; - Control control = item.control; - if (control != null && !control.isDisposed ()) { - control.setBounds (getClientArea ()); - control.setVisible (true); - } - if (notify) { - Event event = new Event (); - event.item = item; - sendEvent (SWT.Selection, event); - } - } -} - -/** - * Sets the receiver's selection to the given item. - * The current selected is first cleared, then the new item is - * selected. - * - * @param item the item to select - * - * @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> - * - * @since 3.2 - */ -public void setSelection (TabItem item) { - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - setSelection (new TabItem [] {item}); -} - -/** - * Sets the receiver's selection to be the given array of items. - * The current selected is first cleared, then the new items are - * selected. - * - * @param items the array of items - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if 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 setSelection (TabItem [] items) { - checkWidget(); - if (items == null) error (SWT.ERROR_NULL_ARGUMENT); - if (items.length == 0) { - setSelection (-1, false); - } else { - for (int i=items.length-1; i>=0; --i) { - int index = indexOf (items [i]); - if (index != -1) setSelection (index, false); - } - } -} - -boolean traversePage (final boolean next) { - if (next) { - OS.gtk_notebook_next_page (handle); - } else { - OS.gtk_notebook_prev_page (handle); - } - return true; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java deleted file mode 100644 index a19d175727..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TabItem.java +++ /dev/null @@ -1,390 +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.gtk.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class represent a selectable user interface object - * corresponding to a tab for a page in a tab folder. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#tabfolder">TabFolder, TabItem 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 TabItem extends Item { - int /*long*/ labelHandle, imageHandle, pageHandle; - Control control; - TabFolder parent; - String toolTipText; - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>TabFolder</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 - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TabItem (TabFolder parent, int style) { - super (parent, style); - this.parent = parent; - createWidget (parent.getItemCount ()); -} - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>TabFolder</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 - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TabItem (TabFolder parent, int style, int index) { - super (parent, style); - this.parent = parent; - createWidget (index); -} - -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} - -void createWidget (int index) { - parent.createItem (this, index); - setOrientation (); - hookEvents (); - register (); - text = ""; -} - -void deregister() { - super.deregister (); - if (labelHandle != 0) display.removeWidget (labelHandle); -} - -void destroyWidget () { - parent.destroyItem (this); - releaseHandle (); -} - -/** - * 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> - * - * @since 3.4 - */ -public Rectangle getBounds () { - checkWidget(); - int x = OS.GTK_WIDGET_X (handle); - int y = OS.GTK_WIDGET_Y (handle); - int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (handle); - int height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (handle); - if ((parent.style & SWT.MIRRORED) != 0) x = parent.getClientWidth () - width - x; - return new Rectangle (x, y, width, height); -} - -/** - * Returns the control that is used to fill the client area of - * the tab folder when the user selects the tab item. If no - * control has been set, return <code>null</code>. - * <p> - * @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 parent, which must be a <code>TabFolder</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 TabFolder getParent () { - checkWidget (); - return parent; -} - -/** - * 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; -} - -int /*long*/ gtk_enter_notify_event (int /*long*/ widget, int /*long*/ event) { - parent.gtk_enter_notify_event (widget, event); - return 0; -} - -int /*long*/ gtk_mnemonic_activate (int /*long*/ widget, int /*long*/ arg1) { - return parent.gtk_mnemonic_activate (widget, arg1); -} - -void hookEvents () { - super.hookEvents (); - if (labelHandle != 0) OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false); -} - -void register () { - super.register (); - if (labelHandle != 0) display.addWidget (labelHandle, this); -} - -void releaseHandle () { - super.releaseHandle (); - pageHandle = labelHandle = imageHandle = 0; - parent = null; -} - -void releaseParent () { - super.releaseParent (); - int index = parent.indexOf (this); - if (index == parent.getSelectionIndex ()) { - if (control != null) control.setVisible (false); - } -} - -/** - * Sets the control that is used to fill the client area of - * the tab folder when the user selects the tab item. - * <p> - * @param control the new control (or null) - * - * @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); - } - Control oldControl = this.control, newControl = control; - this.control = control; - int index = parent.indexOf (this), selectionIndex = parent.getSelectionIndex(); - if (index != selectionIndex) { - if (newControl != null) { - if (selectionIndex != -1) { - Control selectedControl = parent.getItem(selectionIndex).getControl(); - if (selectedControl == newControl) return; - } - newControl.setVisible(false); - return; - } - } - if (newControl != null) { - newControl.setBounds (parent.getClientArea ()); - newControl.setVisible (true); - } - if (oldControl != null) oldControl.setVisible (false); -} - -void setFontDescription (int /*long*/ font) { - OS.gtk_widget_modify_font (labelHandle, font); - OS.gtk_widget_modify_font (imageHandle, font); -} - -void setForegroundColor (GdkColor color) { - /* Don't set the color in vbox handle (it doesn't draw) */ - setForegroundColor (labelHandle, color); - setForegroundColor (imageHandle, color); -} - -public void setImage (Image image) { - checkWidget (); - super.setImage (image); - if (image != null) { - ImageList imageList = parent.imageList; - if (imageList == null) imageList = parent.imageList = new ImageList (); - int imageIndex = imageList.indexOf (image); - if (imageIndex == -1) { - imageIndex = imageList.add (image); - } else { - imageList.put (imageIndex, image); - } - int /*long*/ pixbuf = imageList.getPixbuf (imageIndex); - OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); - OS.gtk_widget_show (imageHandle); - } else { - OS.gtk_image_set_from_pixbuf (imageHandle, 0); - OS.gtk_widget_hide (imageHandle); - } -} - -void setOrientation () { - if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) { - if (handle != 0) OS.gtk_widget_set_direction (handle, OS.GTK_TEXT_DIR_RTL); - if (labelHandle != 0) OS.gtk_widget_set_direction (labelHandle, OS.GTK_TEXT_DIR_RTL); - if (imageHandle != 0) OS.gtk_widget_set_direction (imageHandle, OS.GTK_TEXT_DIR_RTL); - if (pageHandle != 0) OS.gtk_widget_set_direction (pageHandle, OS.GTK_TEXT_DIR_RTL); - } -} - -/** - * 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); - super.setText (string); - char [] chars = fixMnemonic (string); - byte [] buffer = Converter.wcsToMbcs (null, chars, true); - OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer); - if (string.length () != 0) { - OS.gtk_widget_show (labelHandle); - } else { - OS.gtk_widget_hide (labelHandle); - } -} - -/** - * 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; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java deleted file mode 100644 index 451650d509..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java +++ /dev/null @@ -1,3543 +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.gtk.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class implement a selectable user interface - * object that displays a list of images and strings and issues - * notification when selected. - * <p> - * The item children that may be added to instances of this class - * must be of type <code>TableItem</code>. - * </p><p> - * Style <code>VIRTUAL</code> is used to create a <code>Table</code> whose - * <code>TableItem</code>s are to be populated by the client on an on-demand basis - * instead of up-front. This can provide significant performance improvements for - * tables that are very large or for which <code>TableItem</code> population is - * expensive (for example, retrieving values from an external source). - * </p><p> - * Here is an example of using a <code>Table</code> with style <code>VIRTUAL</code>: - * <code><pre> - * final Table table = new Table (parent, SWT.VIRTUAL | SWT.BORDER); - * table.setItemCount (1000000); - * table.addListener (SWT.SetData, new Listener () { - * public void handleEvent (Event event) { - * TableItem item = (TableItem) event.item; - * int index = table.indexOf (item); - * item.setText ("Item " + index); - * System.out.println (item.getText ()); - * } - * }); - * </pre></code> - * </p><p> - * Note that although this class is a subclass of <code>Composite</code>, - * it does not normally make sense to add <code>Control</code> children to - * it, or set a layout on it, unless implementing something like a cell - * editor. - * </p><p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, HIDE_SELECTION, VIRTUAL, NO_SCROLL</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection, DefaultSelection, SetData, MeasureItem, EraseItem, PaintItem</dd> - * </dl> - * </p><p> - * Note: Only one of the styles 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/#table">Table, TableItem, TableColumn 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 Table extends Composite { - int /*long*/ modelHandle, checkRenderer; - int itemCount, columnCount, lastIndexOf, sortDirection; - int /*long*/ ignoreCell; - TableItem [] items; - TableColumn [] columns; - TableItem currentItem; - TableColumn sortColumn; - ImageList imageList, headerImageList; - boolean firstCustomDraw; - int drawState, drawFlags; - GdkColor drawForeground; - boolean ownerDraw, ignoreSize, ignoreAccessibility; - - static final int CHECKED_COLUMN = 0; - static final int GRAYED_COLUMN = 1; - static final int FOREGROUND_COLUMN = 2; - static final int BACKGROUND_COLUMN = 3; - static final int FONT_COLUMN = 4; - static final int FIRST_COLUMN = FONT_COLUMN + 1; - static final int CELL_PIXBUF = 0; - static final int CELL_TEXT = 1; - static final int CELL_FOREGROUND = 2; - static final int CELL_BACKGROUND = 3; - static final int CELL_FONT = 4; - static final int CELL_TYPES = CELL_FONT + 1; - -/** - * 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#CHECK - * @see SWT#FULL_SELECTION - * @see SWT#HIDE_SELECTION - * @see SWT#VIRTUAL - * @see SWT#NO_SCROLL - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Table (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -void _addListener (int eventType, Listener listener) { - super._addListener (eventType, listener); - if (!ownerDraw) { - switch (eventType) { - case SWT.MeasureItem: - case SWT.EraseItem: - case SWT.PaintItem: - ownerDraw = true; - recreateRenderers (); - break; - } - } -} - -TableItem _getItem (int index) { - if ((style & SWT.VIRTUAL) == 0) return items [index]; - if (items [index] != null) return items [index]; - return items [index] = new TableItem (this, SWT.NONE, index, false); -} - -static int checkStyle (int style) { - /* - * Feature in Windows. Even when WS_HSCROLL or - * WS_VSCROLL is not specified, Windows creates - * trees and tables with scroll bars. The fix - * is to set H_SCROLL and V_SCROLL. - * - * NOTE: This code appears on all platforms so that - * applications have consistent scroll bar behavior. - */ - if ((style & SWT.NO_SCROLL) == 0) { - style |= SWT.H_SCROLL | SWT.V_SCROLL; - } - /* GTK is always FULL_SELECTION */ - style |= SWT.FULL_SELECTION; - return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0); -} - -int /*long*/ cellDataProc (int /*long*/ tree_column, int /*long*/ cell, int /*long*/ tree_model, int /*long*/ iter, int /*long*/ data) { - if (cell == ignoreCell) return 0; - int /*long*/ path = OS.gtk_tree_model_get_path (tree_model, iter); - int [] index = new int [1]; - OS.memmove (index, OS.gtk_tree_path_get_indices (path), 4); - TableItem item = _getItem (index[0]); - OS.gtk_tree_path_free (path); - if (item != null) OS.g_object_set_qdata (cell, Display.SWT_OBJECT_INDEX2, item.handle); - boolean isPixbuf = OS.GTK_IS_CELL_RENDERER_PIXBUF (cell); - if (!(isPixbuf || OS.GTK_IS_CELL_RENDERER_TEXT (cell))) return 0; - int modelIndex = -1; - boolean customDraw = false; - if (columnCount == 0) { - modelIndex = Table.FIRST_COLUMN; - customDraw = firstCustomDraw; - } else { - TableColumn column = (TableColumn) display.getWidget (tree_column); - if (column != null) { - modelIndex = column.modelIndex; - customDraw = column.customDraw; - } - } - if (modelIndex == -1) return 0; - boolean setData = false; - if ((style & SWT.VIRTUAL) != 0) { - /* - * Feature in GTK. On GTK before 2.4, fixed_height_mode is not - * supported, and the tree asks for the data of all items. The - * fix is to only provide the data if the row is visible. - */ - if (OS.GTK_VERSION < OS.VERSION (2, 3, 2)) { - OS.gtk_widget_realize (handle); - GdkRectangle visible = new GdkRectangle (); - OS.gtk_tree_view_get_visible_rect (handle, visible); - GdkRectangle area = new GdkRectangle (); - path = OS.gtk_tree_model_get_path (tree_model, iter); - OS.gtk_tree_view_get_cell_area (handle, path, tree_column, area); - OS.gtk_tree_path_free (path); - if (area.y + area.height < 0 || area.y + visible.y > visible.y + visible.height) { - /* Give an image from the image list to make sure the row has - * the correct height. - */ - if (imageList != null && imageList.pixbufs.length > 0) { - if (isPixbuf) OS.g_object_set (cell, OS.pixbuf, imageList.pixbufs [0], 0); - } - return 0; - } - } - if (!item.cached) { - lastIndexOf = index[0]; - setData = checkData (item); - } - } - int /*long*/ [] ptr = new int /*long*/ [1]; - if (setData) { - ptr [0] = 0; - if (isPixbuf) { - OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_PIXBUF, ptr, -1); - OS.g_object_set (cell, OS.pixbuf, ptr [0], 0); - } else { - OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_TEXT, ptr, -1); - if (ptr [0] != 0) { - OS.g_object_set (cell, OS.text, ptr [0], 0); - OS.g_free (ptr [0]); - } - } - } - if (customDraw) { - /* - * Bug on GTK. Gtk renders the background on top of the checkbox and pixbuf. - * This only happens in version 2.2.1 and earlier. The fix is not to set the background. - */ - if (OS.GTK_VERSION > OS.VERSION (2, 2, 1)) { - if (!ownerDraw) { - ptr [0] = 0; - OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_BACKGROUND, ptr, -1); - if (ptr [0] != 0) { - OS.g_object_set (cell, OS.cell_background_gdk, ptr [0], 0); - } - } - } - if (!isPixbuf) { - ptr [0] = 0; - OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_FOREGROUND, ptr, -1); - if (ptr [0] != 0) { - OS.g_object_set (cell, OS.foreground_gdk, ptr [0], 0); - } - ptr [0] = 0; - OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_FONT, ptr, -1); - if (ptr [0] != 0) { - OS.g_object_set (cell, OS.font_desc, ptr [0], 0); - } - } - } - if (setData) { - ignoreCell = cell; - setScrollWidth (tree_column, item); - ignoreCell = 0; - } - return 0; -} - -boolean checkData (TableItem item) { - if (item.cached) return true; - if ((style & SWT.VIRTUAL) != 0) { - item.cached = true; - Event event = new Event (); - event.item = item; - event.index = indexOf (item); - int mask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID; - int signal_id = OS.g_signal_lookup (OS.row_changed, OS.gtk_tree_model_get_type ()); - OS.g_signal_handlers_block_matched (modelHandle, mask, signal_id, 0, 0, 0, handle); - currentItem = item; - sendEvent (SWT.SetData, event); - //widget could be disposed at this point - currentItem = null; - if (isDisposed ()) return false; - OS.g_signal_handlers_unblock_matched (modelHandle, mask, signal_id, 0, 0, 0, handle); - if (item.isDisposed ()) return false; - } - return true; -} - -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} - -/** - * 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> - * When <code>widgetSelected</code> is called, the item field of the event object is valid. - * If the receiver has the <code>SWT.CHECK</code> style and the check selection changes, - * the event object detail field contains the value <code>SWT.CHECK</code>. - * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked. - * The item field of the event object is valid for default selection, but the detail field is not used. - * </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); -} - -int calculateWidth (int /*long*/ column, int /*long*/ iter) { - OS.gtk_tree_view_column_cell_set_cell_data (column, modelHandle, iter, false, false); - /* - * Bug in GTK. The width calculated by gtk_tree_view_column_cell_get_size() - * always grows in size regardless of the text or images in the table. - * The fix is to determine the column width from the cell renderers. - */ - // Code intentionally commented - //int [] width = new int [1]; - //OS.gtk_tree_view_column_cell_get_size (column, null, null, null, width, null); - //return width [0]; - - int width = 0; - int [] w = new int [1]; - OS.gtk_widget_style_get(handle, OS.focus_line_width, w, 0); - width += 2 * w [0]; - int /*long*/ list = OS.gtk_tree_view_column_get_cell_renderers (column); - if (list == 0) return 0; - int /*long*/ temp = list; - while (temp != 0) { - int /*long*/ renderer = OS.g_list_data (temp); - if (renderer != 0) { - OS.gtk_cell_renderer_get_size (renderer, handle, null, null, null, w, null); - width += w [0]; - } - temp = OS.g_list_next (temp); - } - OS.g_list_free (list); - if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0) && OS.gtk_tree_view_get_rules_hint (handle)) { - OS.gtk_widget_style_get (handle, OS.grid_line_width, w, 0) ; - width += 2 * w [0]; - } - return width; -} - -/** - * Clears the item at the given zero-relative index in the receiver. - * The text, icon and other attributes of the item are set to the default - * value. If the table was created with the <code>SWT.VIRTUAL</code> style, - * these attributes are requested again as needed. - * - * @param index the index of the item to clear - * - * @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> - * - * @see SWT#VIRTUAL - * @see SWT#SetData - * - * @since 3.0 - */ -public void clear (int index) { - checkWidget (); - if (!(0 <= index && index < itemCount)) { - error(SWT.ERROR_INVALID_RANGE); - } - TableItem item = items [index]; - if (item != null) item.clear (); -} - -/** - * Removes the items from the receiver which are between the given - * zero-relative start and end indices (inclusive). The text, icon - * and other attributes of the items are set to their default values. - * If the table was created with the <code>SWT.VIRTUAL</code> style, - * these attributes are requested again as needed. - * - * @param start the start index of the item to clear - * @param end the end index of the item to clear - * - * @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> - * - * @see SWT#VIRTUAL - * @see SWT#SetData - * - * @since 3.0 - */ -public void clear (int start, int end) { - checkWidget (); - if (start > end) return; - if (!(0 <= start && start <= end && end < itemCount)) { - error (SWT.ERROR_INVALID_RANGE); - } - if (start == 0 && end == itemCount - 1) { - clearAll(); - } else { - for (int i=start; i<=end; i++) { - TableItem item = items [i]; - if (item != null) item.clear(); - } - } -} - -/** - * Clears the items at the given zero-relative indices in the receiver. - * The text, icon and other attributes of the items are set to their default - * values. If the table was created with the <code>SWT.VIRTUAL</code> style, - * these attributes are requested again as needed. - * - * @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> - * - * @see SWT#VIRTUAL - * @see SWT#SetData - * - * @since 3.0 - */ -public void clear (int [] indices) { - checkWidget (); - if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); - if (indices.length == 0) return; - for (int i=0; i<indices.length; i++) { - if (!(0 <= indices [i] && indices [i] < itemCount)) { - error (SWT.ERROR_INVALID_RANGE); - } - } - for (int i=0; i<indices.length; i++) { - TableItem item = items [indices [i]]; - if (item != null) item.clear(); - } -} - -/** - * Clears all the items in the receiver. The text, icon and other - * attributes of the items are set to their default values. If the - * table was created with the <code>SWT.VIRTUAL</code> style, these - * attributes are requested again as needed. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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#VIRTUAL - * @see SWT#SetData - * - * @since 3.0 - */ -public void clearAll () { - checkWidget (); - for (int i=0; i<itemCount; i++) { - TableItem item = items [i]; - if (item != null) item.clear(); - } -} - -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; - Point size = computeNativeSize (handle, wHint, hHint, changed); - Rectangle trim = computeTrim (0, 0, size.x, size.y); - size.x = trim.width; - size.y = trim.height; - return size; -} - -void createColumn (TableColumn column, int index) { - int modelIndex = FIRST_COLUMN; - if (columnCount != 0) { - int modelLength = OS.gtk_tree_model_get_n_columns (modelHandle); - boolean [] usedColumns = new boolean [modelLength]; - for (int i=0; i<columnCount; i++) { - int columnIndex = columns [i].modelIndex; - for (int j = 0; j < CELL_TYPES; j++) { - usedColumns [columnIndex + j] = true; - } - } - while (modelIndex < modelLength) { - if (!usedColumns [modelIndex]) break; - modelIndex++; - } - if (modelIndex == modelLength) { - int /*long*/ oldModel = modelHandle; - int /*long*/[] types = getColumnTypes (columnCount + 4); // grow by 4 rows at a time - int /*long*/ newModel = OS.gtk_list_store_newv (types.length, types); - if (newModel == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ [] ptr = new int /*long*/ [1]; - for (int i=0; i<itemCount; i++) { - int /*long*/ newItem = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (newItem == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_list_store_append (newModel, newItem); - TableItem item = items [i]; - if (item != null) { - int /*long*/ oldItem = item.handle; - for (int j=0; j<modelLength; j++) { - OS.gtk_tree_model_get (oldModel, oldItem, j, ptr, -1); - OS.gtk_list_store_set (newModel, newItem, j, ptr [0], -1); - if (types [j] == OS.G_TYPE_STRING ()) OS.g_free ((ptr [0])); - } - OS.gtk_list_store_remove (oldModel, oldItem); - OS.g_free (oldItem); - item.handle = newItem; - } else { - OS.g_free (newItem); - } - } - OS.gtk_tree_view_set_model (handle, newModel); - OS.g_object_unref (oldModel); - modelHandle = newModel; - } - } - int /*long*/ columnHandle = OS.gtk_tree_view_column_new (); - if (columnHandle == 0) error (SWT.ERROR_NO_HANDLES); - if (index == 0 && columnCount > 0) { - TableColumn checkColumn = columns [0]; - createRenderers (checkColumn.handle, checkColumn.modelIndex, false, checkColumn.style); - } - createRenderers (columnHandle, modelIndex, index == 0, column == null ? 0 : column.style); - /* - * Use GTK_TREE_VIEW_COLUMN_GROW_ONLY on GTK versions < 2.3.2 - * because fixed_height_mode is not supported. - */ - boolean useVirtual = (style & SWT.VIRTUAL) != 0 && OS.GTK_VERSION >= OS.VERSION (2, 3, 2); - if (!useVirtual && columnCount == 0) { - OS.gtk_tree_view_column_set_sizing (columnHandle, OS.GTK_TREE_VIEW_COLUMN_GROW_ONLY); - } else { - OS.gtk_tree_view_column_set_sizing (columnHandle, OS.GTK_TREE_VIEW_COLUMN_FIXED); - if (columnCount != 0) OS.gtk_tree_view_column_set_visible (columnHandle, false); - } - OS.gtk_tree_view_column_set_resizable (columnHandle, true); - OS.gtk_tree_view_column_set_clickable (columnHandle, true); - OS.gtk_tree_view_column_set_min_width (columnHandle, 0); - OS.gtk_tree_view_insert_column (handle, columnHandle, index); - if (column != null) { - column.handle = columnHandle; - column.modelIndex = modelIndex; - } - /* Disable searching when using VIRTUAL */ - if ((style & SWT.VIRTUAL) != 0) { - /* - * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE) - * would prevent the user from being able to type in text to search the tree. - * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive - * search. This meant that even if FALSE was passed to enable_search, the user - * can still bring up the search pop up using the keybinding. GTK also introduced - * the notion of passing a -1 to gtk_set_search_column to disable searching - * (including the search key binding). The fix is to use the right calls - * for the right version. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 5)) { - OS.gtk_tree_view_set_search_column (handle, -1); - } else { - OS.gtk_tree_view_set_enable_search (handle, false); - } - } else { - /* Set the search column whenever the model changes */ - int firstColumn = columnCount == 0 ? FIRST_COLUMN : columns [0].modelIndex; - OS.gtk_tree_view_set_search_column (handle, firstColumn + CELL_TEXT); - } -} - -void createHandle (int index) { - state |= HANDLE; - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - scrolledHandle = OS.gtk_scrolled_window_new (0, 0); - if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ [] types = getColumnTypes (1); - modelHandle = OS.gtk_list_store_newv (types.length, types); - if (modelHandle == 0) error (SWT.ERROR_NO_HANDLES); - handle = OS.gtk_tree_view_new_with_model (modelHandle); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - if ((style & SWT.CHECK) != 0) { - checkRenderer = OS.gtk_cell_renderer_toggle_new (); - if (checkRenderer == 0) error (SWT.ERROR_NO_HANDLES); - OS.g_object_ref (checkRenderer); - } - createColumn (null, 0); - OS.gtk_container_add (fixedHandle, scrolledHandle); - OS.gtk_container_add (scrolledHandle, handle); - - int mode = (style & SWT.MULTI) != 0 ? OS.GTK_SELECTION_MULTIPLE : OS.GTK_SELECTION_BROWSE; - int /*long*/ selectionHandle = OS.gtk_tree_view_get_selection (handle); - OS.gtk_tree_selection_set_mode (selectionHandle, mode); - OS.gtk_tree_view_set_headers_visible (handle, false); - int hsp = (style & SWT.H_SCROLL) != 0 ? OS.GTK_POLICY_AUTOMATIC : OS.GTK_POLICY_NEVER; - int vsp = (style & SWT.V_SCROLL) != 0 ? OS.GTK_POLICY_AUTOMATIC : OS.GTK_POLICY_NEVER; - OS.gtk_scrolled_window_set_policy (scrolledHandle, hsp, vsp); - if ((style & SWT.BORDER) != 0) OS.gtk_scrolled_window_set_shadow_type (scrolledHandle, OS.GTK_SHADOW_ETCHED_IN); - /* Disable searching when using VIRTUAL */ - if ((style & SWT.VIRTUAL) != 0) { - /* The fixed_height_mode property only exists in GTK 2.3.2 and greater */ - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2)) { - OS.g_object_set (handle, OS.fixed_height_mode, true, 0); - } - /* - * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE) - * would prevent the user from being able to type in text to search the tree. - * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive - * search. This meant that even if FALSE was passed to enable_search, the user - * can still bring up the search pop up using the keybinding. GTK also introduced - * the notion of passing a -1 to gtk_set_search_column to disable searching - * (including the search key binding). The fix is to use the right calls - * for the right version. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 5)) { - OS.gtk_tree_view_set_search_column (handle, -1); - } else { - OS.gtk_tree_view_set_enable_search (handle, false); - } - } -} - -void createItem (TableColumn column, int index) { - if (!(0 <= index && index <= columnCount)) error (SWT.ERROR_INVALID_RANGE); - if (columnCount == 0) { - column.handle = OS.gtk_tree_view_get_column (handle, 0); - OS.gtk_tree_view_column_set_sizing (column.handle, OS.GTK_TREE_VIEW_COLUMN_FIXED); - OS.gtk_tree_view_column_set_visible (column.handle, false); - column.modelIndex = FIRST_COLUMN; - createRenderers (column.handle, column.modelIndex, true, column.style); - column.customDraw = firstCustomDraw; - firstCustomDraw = false; - } else { - createColumn (column, index); - } - int /*long*/ boxHandle = OS.gtk_hbox_new (false, 3); - if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ labelHandle = OS.gtk_label_new_with_mnemonic (null); - if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ imageHandle = OS.gtk_image_new (); - if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (boxHandle, imageHandle); - OS.gtk_container_add (boxHandle, labelHandle); - OS.gtk_widget_show (boxHandle); - OS.gtk_widget_show (labelHandle); - column.labelHandle = labelHandle; - column.imageHandle = imageHandle; - OS.gtk_tree_view_column_set_widget (column.handle, boxHandle); - int /*long*/ widget = OS.gtk_widget_get_parent (boxHandle); - while (widget != handle) { - if (OS.GTK_IS_BUTTON (widget)) { - column.buttonHandle = widget; - break; - } - widget = OS.gtk_widget_get_parent (widget); - } - if (columnCount == columns.length) { - TableColumn [] newColumns = new TableColumn [columns.length + 4]; - System.arraycopy (columns, 0, newColumns, 0, columns.length); - columns = newColumns; - } - System.arraycopy (columns, index, columns, index + 1, columnCount++ - index); - columns [index] = column; - if ((state & FONT) != 0) { - column.setFontDescription (getFontDescription ()); - } - if (columnCount >= 1) { - for (int i=0; i<itemCount; i++) { - TableItem item = items [i]; - if (item != null) { - Font [] cellFont = item.cellFont; - if (cellFont != null) { - Font [] temp = new Font [columnCount]; - System.arraycopy (cellFont, 0, temp, 0, index); - System.arraycopy (cellFont, index, temp, index+1, columnCount-index-1); - item.cellFont = temp; - } - } - } - } - /* - * Feature in GTK. The tree view does not resize immediately if a table - * column is created when the table is not visible. If the width of the - * new column is queried, GTK returns an incorrect value. The fix is to - * ensure that the columns are resized before any queries. - */ - if(!isVisible ()) { - OS.gtk_container_resize_children (handle); - } -} - -void createItem (TableItem item, int index) { - if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE); - if (itemCount == items.length) { - int length = drawCount <= 0 ? items.length + 4 : Math.max (4, items.length * 3 / 2); - TableItem [] newItems = new TableItem [length]; - System.arraycopy (items, 0, newItems, 0, items.length); - items = newItems; - } - item.handle = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (item.handle == 0) error (SWT.ERROR_NO_HANDLES); - /* - * Feature in GTK. It is much faster to append to a list store - * than to insert at the end using gtk_list_store_insert(). - */ - if (index == itemCount) { - OS.gtk_list_store_append (modelHandle, item.handle); - } else { - OS.gtk_list_store_insert (modelHandle, item.handle, index); - } - System.arraycopy (items, index, items, index + 1, itemCount++ - index); - items [index] = item; -} - -void createRenderers (int /*long*/ columnHandle, int modelIndex, boolean check, int columnStyle) { - OS.gtk_tree_view_column_clear (columnHandle); - if ((style & SWT.CHECK) != 0 && check) { - OS.gtk_tree_view_column_pack_start (columnHandle, checkRenderer, false); - OS.gtk_tree_view_column_add_attribute (columnHandle, checkRenderer, OS.active, CHECKED_COLUMN); - /* - * Feature in GTK. The inconsistent property only exists in GTK 2.2.x. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 2, 0)) { - OS.gtk_tree_view_column_add_attribute (columnHandle, checkRenderer, OS.inconsistent, GRAYED_COLUMN); - } - /* - * Bug in GTK. GTK renders the background on top of the checkbox. - * This only happens in version 2.2.1 and earlier. The fix is not to set the background. - */ - if (OS.GTK_VERSION > OS.VERSION (2, 2, 1)) { - if (!ownerDraw) OS.gtk_tree_view_column_add_attribute (columnHandle, checkRenderer, OS.cell_background_gdk, BACKGROUND_COLUMN); - } - if (ownerDraw) { - OS.gtk_tree_view_column_set_cell_data_func (columnHandle, checkRenderer, display.cellDataProc, handle, 0); - OS.g_object_set_qdata (checkRenderer, Display.SWT_OBJECT_INDEX1, columnHandle); - } - } - int /*long*/ pixbufRenderer = ownerDraw ? OS.g_object_new (display.gtk_cell_renderer_pixbuf_get_type (), 0) : OS.gtk_cell_renderer_pixbuf_new (); - if (pixbufRenderer == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ textRenderer = ownerDraw ? OS.g_object_new (display.gtk_cell_renderer_text_get_type (), 0) : OS.gtk_cell_renderer_text_new (); - if (textRenderer == 0) error (SWT.ERROR_NO_HANDLES); - - if (ownerDraw) { - OS.g_object_set_qdata (pixbufRenderer, Display.SWT_OBJECT_INDEX1, columnHandle); - OS.g_object_set_qdata (textRenderer, Display.SWT_OBJECT_INDEX1, columnHandle); - } - - /* - * Feature in GTK. When a tree view column contains only one activatable - * cell renderer such as a toggle renderer, mouse clicks anywhere in a cell - * activate that renderer. The workaround is to set a second cell renderer - * to be activatable. - */ - if ((style & SWT.CHECK) != 0 && check) { - OS.g_object_set (pixbufRenderer, OS.mode, OS.GTK_CELL_RENDERER_MODE_ACTIVATABLE, 0); - } - - /* Set alignment */ - if ((columnStyle & SWT.RIGHT) != 0) { - OS.g_object_set(textRenderer, OS.xalign, 1f, 0); - OS.gtk_tree_view_column_pack_end (columnHandle, textRenderer, true); - OS.gtk_tree_view_column_pack_end (columnHandle, pixbufRenderer, false); - OS.gtk_tree_view_column_set_alignment (columnHandle, 1f); - } else if ((columnStyle & SWT.CENTER) != 0) { - OS.g_object_set(textRenderer, OS.xalign, 0.5f, 0); - OS.gtk_tree_view_column_pack_start (columnHandle, pixbufRenderer, false); - OS.gtk_tree_view_column_pack_end (columnHandle, textRenderer, true); - OS.gtk_tree_view_column_set_alignment (columnHandle, 0.5f); - } else { - OS.gtk_tree_view_column_pack_start (columnHandle, pixbufRenderer, false); - OS.gtk_tree_view_column_pack_start (columnHandle, textRenderer, true); - OS.gtk_tree_view_column_set_alignment (columnHandle, 0f); - } - - /* Add attributes */ - OS.gtk_tree_view_column_add_attribute (columnHandle, pixbufRenderer, OS.pixbuf, modelIndex + CELL_PIXBUF); - /* - * Bug on GTK. Gtk renders the background on top of the pixbuf. - * This only happens in version 2.2.1 and earlier. The fix is not to set the background. - */ - if (OS.GTK_VERSION > OS.VERSION (2, 2, 1)) { - if (!ownerDraw) { - OS.gtk_tree_view_column_add_attribute (columnHandle, pixbufRenderer, OS.cell_background_gdk, BACKGROUND_COLUMN); - OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.cell_background_gdk, BACKGROUND_COLUMN); - } - } - OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.text, modelIndex + CELL_TEXT); - OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.foreground_gdk, FOREGROUND_COLUMN); - OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.font_desc, FONT_COLUMN); - - boolean customDraw = firstCustomDraw; - if (columnCount != 0) { - for (int i=0; i<columnCount; i++) { - if (columns [i].handle == columnHandle) { - customDraw = columns [i].customDraw; - break; - } - } - } - if ((style & SWT.VIRTUAL) != 0 || customDraw || ownerDraw) { - OS.gtk_tree_view_column_set_cell_data_func (columnHandle, textRenderer, display.cellDataProc, handle, 0); - OS.gtk_tree_view_column_set_cell_data_func (columnHandle, pixbufRenderer, display.cellDataProc, handle, 0); - } -} - -void createWidget (int index) { - super.createWidget (index); - items = new TableItem [4]; - columns = new TableColumn [4]; - itemCount = columnCount = 0; -} - -GdkColor defaultBackground () { - return display.COLOR_LIST_BACKGROUND; -} - -GdkColor defaultForeground () { - return display.COLOR_LIST_FOREGROUND; -} - -void deregister () { - super.deregister (); - display.removeWidget (OS.gtk_tree_view_get_selection (handle)); - if (checkRenderer != 0) display.removeWidget (checkRenderer); - display.removeWidget (modelHandle); -} - -/** - * 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(); - if (index < 0 || index >= itemCount) return; - boolean fixColumn = showFirstColumn (); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_selection_unselect_iter (selection, _getItem (index).handle); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if (fixColumn) hideFirstColumn (); -} - -/** - * 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(); - boolean fixColumn = showFirstColumn (); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - for (int index=start; index<=end; index++) { - if (index < 0 || index >= itemCount) continue; - OS.gtk_tree_selection_unselect_iter (selection, _getItem (index).handle); - } - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if (fixColumn) hideFirstColumn (); -} - -/** - * 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); - boolean fixColumn = showFirstColumn (); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - for (int i=0; i<indices.length; i++) { - int index = indices[i]; - if (index < 0 || index >= itemCount) continue; - OS.gtk_tree_selection_unselect_iter (selection, _getItem (index).handle); - } - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if (fixColumn) hideFirstColumn (); -} - -/** - * 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(); - boolean fixColumn = showFirstColumn (); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_selection_unselect_all (selection); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if (fixColumn) hideFirstColumn (); -} - -void destroyItem (TableColumn column) { - int index = 0; - while (index < columnCount) { - if (columns [index] == column) break; - index++; - } - if (index == columnCount) return; - int /*long*/ columnHandle = column.handle; - if (columnCount == 1) { - firstCustomDraw = column.customDraw; - } - System.arraycopy (columns, index + 1, columns, index, --columnCount - index); - columns [columnCount] = null; - OS.gtk_tree_view_remove_column (handle, columnHandle); - if (columnCount == 0) { - int /*long*/ oldModel = modelHandle; - int /*long*/[] types = getColumnTypes (1); - int /*long*/ newModel = OS.gtk_list_store_newv (types.length, types); - if (newModel == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ [] ptr = new int /*long*/ [1]; - for (int i=0; i<itemCount; i++) { - int /*long*/ newItem = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (newItem == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_list_store_append (newModel, newItem); - TableItem item = items [i]; - if (item != null) { - int /*long*/ oldItem = item.handle; - for (int j=0; j<FIRST_COLUMN; j++) { - OS.gtk_tree_model_get (oldModel, oldItem, j, ptr, -1); - OS.gtk_list_store_set (newModel, newItem, j, ptr [0], -1); - } - OS.gtk_tree_model_get (oldModel, oldItem, column.modelIndex + CELL_PIXBUF, ptr, -1); - OS.gtk_list_store_set (newModel, newItem, FIRST_COLUMN + CELL_PIXBUF, ptr [0], -1); - OS.gtk_tree_model_get (oldModel, oldItem, column.modelIndex + CELL_TEXT, ptr, -1); - OS.gtk_list_store_set (newModel, newItem, FIRST_COLUMN + CELL_TEXT, ptr [0], -1); - OS.g_free (ptr [0]); - OS.gtk_tree_model_get (oldModel, oldItem, column.modelIndex + CELL_FOREGROUND, ptr, -1); - OS.gtk_list_store_set (newModel, newItem, FIRST_COLUMN + CELL_FOREGROUND, ptr [0], -1); - OS.gtk_tree_model_get (oldModel, oldItem, column.modelIndex + CELL_BACKGROUND, ptr, -1); - OS.gtk_list_store_set (newModel, newItem, FIRST_COLUMN + CELL_BACKGROUND, ptr [0], -1); - OS.gtk_tree_model_get (oldModel, oldItem, column.modelIndex + CELL_FONT, ptr, -1); - OS.gtk_list_store_set (newModel, newItem, FIRST_COLUMN + CELL_FONT, ptr [0], -1); - OS.gtk_list_store_remove (oldModel, oldItem); - OS.g_free (oldItem); - item.handle = newItem; - } else { - OS.g_free (newItem); - } - } - OS.gtk_tree_view_set_model (handle, newModel); - OS.g_object_unref (oldModel); - modelHandle = newModel; - createColumn (null, 0); - } else { - for (int i=0; i<itemCount; i++) { - TableItem item = items [i]; - if (item != null) { - int /*long*/ iter = item.handle; - int modelIndex = column.modelIndex; - OS.gtk_list_store_set (modelHandle, iter, modelIndex + CELL_PIXBUF, 0, -1); - OS.gtk_list_store_set (modelHandle, iter, modelIndex + CELL_TEXT, 0, -1); - OS.gtk_list_store_set (modelHandle, iter, modelIndex + CELL_FOREGROUND, 0, -1); - OS.gtk_list_store_set (modelHandle, iter, modelIndex + CELL_BACKGROUND, 0, -1); - OS.gtk_list_store_set (modelHandle, iter, modelIndex + CELL_FONT, 0, -1); - - Font [] cellFont = item.cellFont; - if (cellFont != null) { - if (columnCount == 0) { - item.cellFont = null; - } else { - Font [] temp = new Font [columnCount]; - System.arraycopy (cellFont, 0, temp, 0, index); - System.arraycopy (cellFont, index + 1, temp, index, columnCount - index); - item.cellFont = temp; - } - } - } - } - if (index == 0) { - TableColumn checkColumn = columns [0]; - createRenderers (checkColumn.handle, checkColumn.modelIndex, true, checkColumn.style); - } - } - /* Disable searching when using VIRTUAL */ - if ((style & SWT.VIRTUAL) != 0) { - /* - * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE) - * would prevent the user from being able to type in text to search the tree. - * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive - * search. This meant that even if FALSE was passed to enable_search, the user - * can still bring up the search pop up using the keybinding. GTK also introduced - * the notion of passing a -1 to gtk_set_search_column to disable searching - * (including the search key binding). The fix is to use the right calls - * for the right version. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 5)) { - OS.gtk_tree_view_set_search_column (handle, -1); - } else { - OS.gtk_tree_view_set_enable_search (handle, false); - } - } else { - /* Set the search column whenever the model changes */ - int firstColumn = columnCount == 0 ? FIRST_COLUMN : columns [0].modelIndex; - OS.gtk_tree_view_set_search_column (handle, firstColumn + CELL_TEXT); - } -} - -void destroyItem (TableItem item) { - int index = 0; - while (index < itemCount) { - if (items [index] == item) break; - index++; - } - if (index == itemCount) return; - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_list_store_remove (modelHandle, item.handle); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - System.arraycopy (items, index + 1, items, index, --itemCount - index); - items [itemCount] = null; - if (itemCount == 0) resetCustomDraw (); -} - -boolean dragDetect (int x, int y, boolean filter, boolean [] consume) { - boolean selected = false; - if (filter) { - int /*long*/ [] path = new int /*long*/ [1]; - if (OS.gtk_tree_view_get_path_at_pos (handle, x, y, path, null, null, null)) { - if (path [0] != 0) { - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - if (OS.gtk_tree_selection_path_is_selected (selection, path [0])) selected = true; - OS.gtk_tree_path_free (path [0]); - } - } else { - return false; - } - } - boolean dragDetect = super.dragDetect (x, y, filter, consume); - if (dragDetect && selected && consume != null) consume [0] = true; - return dragDetect; -} - -int /*long*/ eventWindow () { - return paintWindow (); -} - -boolean fixAccessibility () { - /* - * Bug in GTK. With GTK 2.12, when assistive technologies is on, the time - * it takes to add or remove several rows to the model is very long. This - * happens because the accessible object asks each row for its data, including - * the rows that are not visible. The the fix is to block the accessible object - * from receiving row_added and row_removed signals and, at the end, send only - * a notify signal with the "model" detail. - * - * Note: The test bellow has to be updated when the real problem is fixed in - * the accessible object. - */ - return OS.GTK_VERSION >= OS.VERSION (2, 12, 0); -} - -void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) { - super.fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus); - for (int i=0; i<columnCount; i++) { - TableColumn column = columns [i]; - if (column.toolTipText != null) { - column.setToolTipText(oldShell, null); - column.setToolTipText(newShell, column.toolTipText); - } - } -} - -GdkColor getBackgroundColor () { - return getBaseColor (); -} - -public Rectangle getClientArea () { - checkWidget (); - forceResize (); - OS.gtk_widget_realize (handle); - int /*long*/ fixedWindow = OS.GTK_WIDGET_WINDOW (fixedHandle); - int /*long*/ binWindow = OS.gtk_tree_view_get_bin_window (handle); - int [] binX = new int [1], binY = new int [1]; - OS.gdk_window_get_origin (binWindow, binX, binY); - int [] fixedX = new int [1], fixedY = new int [1]; - OS.gdk_window_get_origin (fixedWindow, fixedX, fixedY); - int /*long*/ clientHandle = clientHandle (); - int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (clientHandle); - int height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (clientHandle); - return new Rectangle (fixedX [0] - binX [0], fixedY [0] - binY [0], width, height); -} - -int getClientWidth () { - int [] w = new int [1], h = new int [1]; - OS.gtk_widget_realize (handle); - OS.gdk_drawable_get_size(OS.gtk_tree_view_get_bin_window(handle), w, h); - return w[0]; -} - -/** - * Returns the column at the given, zero-relative index in the - * receiver. Throws an exception if the index is out of range. - * Columns are returned in the order that they were created. - * If no <code>TableColumn</code>s were created by the programmer, - * this method will throw <code>ERROR_INVALID_RANGE</code> despite - * the fact that a single column of data may be visible in the table. - * This occurs when the programmer uses the table like a list, adding - * items but never creating a column. - * - * @param index the index of the column to return - * @return the column 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> - * - * @see Table#getColumnOrder() - * @see Table#setColumnOrder(int[]) - * @see TableColumn#getMoveable() - * @see TableColumn#setMoveable(boolean) - * @see SWT#Move - */ -public TableColumn getColumn (int index) { - checkWidget(); - if (!(0 <= index && index < columnCount)) error (SWT.ERROR_INVALID_RANGE); - return columns [index]; -} - -/** - * Returns the number of columns contained in the receiver. - * If no <code>TableColumn</code>s were created by the programmer, - * this value is zero, despite the fact that visually, one column - * of items may be visible. This occurs when the programmer uses - * the table like a list, adding items but never creating a column. - * - * @return the number of columns - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 getColumnCount () { - checkWidget(); - return columnCount; -} - -int /*long*/[] getColumnTypes (int columnCount) { - int /*long*/[] types = new int /*long*/ [FIRST_COLUMN + (columnCount * CELL_TYPES)]; - // per row data - types [CHECKED_COLUMN] = OS.G_TYPE_BOOLEAN (); - types [GRAYED_COLUMN] = OS.G_TYPE_BOOLEAN (); - types [FOREGROUND_COLUMN] = OS.GDK_TYPE_COLOR (); - types [BACKGROUND_COLUMN] = OS.GDK_TYPE_COLOR (); - types [FONT_COLUMN] = OS.PANGO_TYPE_FONT_DESCRIPTION (); - // per cell data - for (int i=FIRST_COLUMN; i<types.length; i+=CELL_TYPES) { - types [i + CELL_PIXBUF] = OS.GDK_TYPE_PIXBUF (); - types [i + CELL_TEXT] = OS.G_TYPE_STRING (); - types [i + CELL_FOREGROUND] = OS.GDK_TYPE_COLOR (); - types [i + CELL_BACKGROUND] = OS.GDK_TYPE_COLOR (); - types [i + CELL_FONT] = OS.PANGO_TYPE_FONT_DESCRIPTION (); - } - return types; -} - -/** - * Returns an array of zero-relative integers that map - * the creation order of the receiver's items to the - * order in which they are currently being displayed. - * <p> - * Specifically, the indices of the returned array represent - * the current visual order of the items, and the contents - * of the array represent the creation order of the items. - * </p><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 current visual order of the receiver's 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> - * - * @see Table#setColumnOrder(int[]) - * @see TableColumn#getMoveable() - * @see TableColumn#setMoveable(boolean) - * @see SWT#Move - * - * @since 3.1 - */ -public int [] getColumnOrder () { - checkWidget (); - if (columnCount == 0) return new int [0]; - int /*long*/ list = OS.gtk_tree_view_get_columns (handle); - if (list == 0) return new int [0]; - int i = 0, count = OS.g_list_length (list); - int [] order = new int [count]; - int /*long*/ temp = list; - while (temp != 0) { - int /*long*/ column = OS.g_list_data (temp); - if (column != 0) { - for (int j=0; j<columnCount; j++) { - if (columns [j].handle == column) { - order [i++] = j; - break; - } - } - } - temp = OS.g_list_next (temp); - } - OS.g_list_free (list); - return order; -} - -/** - * Returns an array of <code>TableColumn</code>s which are the - * columns in the receiver. Columns are returned in the order - * that they were created. If no <code>TableColumn</code>s were - * created by the programmer, the array is empty, despite the fact - * that visually, one column of items may be visible. This occurs - * when the programmer uses the table like a list, adding items but - * never creating a column. - * <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> - * - * @see Table#getColumnOrder() - * @see Table#setColumnOrder(int[]) - * @see TableColumn#getMoveable() - * @see TableColumn#setMoveable(boolean) - * @see SWT#Move - */ -public TableColumn [] getColumns () { - checkWidget(); - TableColumn [] result = new TableColumn [columnCount]; - System.arraycopy (columns, 0, result, 0, columnCount); - return result; -} - -TableItem getFocusItem () { - int /*long*/ [] path = new int /*long*/ [1]; - OS.gtk_tree_view_get_cursor (handle, path, null); - if (path [0] == 0) return null; - TableItem item = null; - int /*long*/ indices = OS.gtk_tree_path_get_indices (path [0]); - if (indices != 0) { - int [] index = new int []{-1}; - OS.memmove (index, indices, 4); - item = _getItem (index [0]); - } - OS.gtk_tree_path_free (path [0]); - return item; -} - -GdkColor getForegroundColor () { - return getTextColor (); -} - -/** - * Returns the width in pixels of a grid line. - * - * @return the width of a grid line in pixels - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 getGridLineWidth () { - checkWidget(); - return 0; -} - -/** - * Returns the height of the receiver's header - * - * @return the height of the header or zero if the header is not 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 2.0 - */ -public int getHeaderHeight () { - checkWidget (); - if (!OS.gtk_tree_view_get_headers_visible (handle)) return 0; - if (columnCount > 0) { - GtkRequisition requisition = new GtkRequisition (); - int height = 0; - for (int i=0; i<columnCount; i++) { - int /*long*/ buttonHandle = columns [i].buttonHandle; - if (buttonHandle != 0) { - OS.gtk_widget_size_request (buttonHandle, requisition); - height = Math.max (height, requisition.height); - } - } - return height; - } - OS.gtk_widget_realize (handle); - int /*long*/ fixedWindow = OS.GTK_WIDGET_WINDOW (fixedHandle); - int /*long*/ binWindow = OS.gtk_tree_view_get_bin_window (handle); - int [] binY = new int [1]; - OS.gdk_window_get_origin (binWindow, null, binY); - int [] fixedY = new int [1]; - OS.gdk_window_get_origin (fixedWindow, null, fixedY); - return binY [0] - fixedY [0]; -} - -/** - * Returns <code>true</code> if the receiver's header 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 header'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 getHeaderVisible () { - checkWidget(); - return OS.gtk_tree_view_get_headers_visible (handle); -} - -/** - * 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 TableItem getItem (int index) { - checkWidget(); - if (!(0 <= index && index < itemCount)) error (SWT.ERROR_INVALID_RANGE); - return _getItem (index); -} - -/** - * 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. - * <p> - * The item that is returned represents an item that could be selected by the user. - * For example, if selection only occurs in items in the first column, then null is - * returned if the point is outside of the item. - * Note that the SWT.FULL_SELECTION style hint, which specifies the selection policy, - * determines the extent of the selection. - * </p> - * - * @param point the point used to locate the item - * @return the item at the given point, or null if the point is not in a selectable item - * - * @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 TableItem getItem (Point point) { - checkWidget(); - if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - int /*long*/ [] path = new int /*long*/ [1]; - OS.gtk_widget_realize (handle); - if (!OS.gtk_tree_view_get_path_at_pos (handle, point.x, point.y, path, null, null, null)) return null; - if (path [0] == 0) return null; - int /*long*/ indices = OS.gtk_tree_path_get_indices (path [0]); - TableItem item = null; - if (indices != 0) { - int [] index = new int [1]; - OS.memmove (index, indices, 4); - item = _getItem (index [0]); - } - OS.gtk_tree_path_free (path [0]); - return item; -} - -/** - * 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 the height of the area which would be used to - * display <em>one</em> of the items in the receiver. - * - * @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(); - if (itemCount == 0) { - int /*long*/ column = OS.gtk_tree_view_get_column (handle, 0); - int [] w = new int [1], h = new int [1]; - ignoreSize = true; - OS.gtk_tree_view_column_cell_get_size (column, null, null, null, w, h); - ignoreSize = false; - return h [0]; - } else { - int height = 0; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - OS.gtk_tree_model_get_iter_first (modelHandle, iter); - int columnCount = Math.max (1, this.columnCount); - for (int i=0; i<columnCount; i++) { - int /*long*/ column = OS.gtk_tree_view_get_column (handle, i); - OS.gtk_tree_view_column_cell_set_cell_data (column, modelHandle, iter, false, false); - int [] w = new int [1], h = new int [1]; - OS.gtk_tree_view_column_cell_get_size (column, null, null, null, w, h); - height = Math.max (height, h [0]); - } - OS.g_free (iter); - return height; - } -} - -/** - * Returns a (possibly empty) array of <code>TableItem</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 TableItem [] getItems () { - checkWidget(); - TableItem [] result = new TableItem [itemCount]; - if ((style & SWT.VIRTUAL) != 0) { - for (int i=0; i<itemCount; i++) { - result [i] = _getItem (i); - } - } else { - System.arraycopy (items, 0, result, 0, itemCount); - } - return result; -} - -/** - * Returns <code>true</code> if the receiver's lines are visible, - * and <code>false</code> otherwise. Note that some platforms draw - * grid lines while others may draw alternating row colors. - * <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 visibility state of the lines - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 getLinesVisible() { - checkWidget(); - return OS.gtk_tree_view_get_rules_hint (handle); -} - -int /*long*/ getPixbufRenderer (int /*long*/ column) { - int /*long*/ list = OS.gtk_tree_view_column_get_cell_renderers (column); - if (list == 0) return 0; - int count = OS.g_list_length (list); - int /*long*/ pixbufRenderer = 0; - int i = 0; - while (i < count) { - int /*long*/ renderer = OS.g_list_nth_data (list, i); - if (OS.GTK_IS_CELL_RENDERER_PIXBUF (renderer)) { - pixbufRenderer = renderer; - break; - } - i++; - } - OS.g_list_free (list); - return pixbufRenderer; -} - -/** - * Returns an array of <code>TableItem</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 TableItem [] getSelection () { - checkWidget(); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) { - display.treeSelectionLength = 0; - display.treeSelection = new int [itemCount]; - OS.gtk_tree_selection_selected_foreach (selection, display.treeSelectionProc, handle); - TableItem [] result = new TableItem [display.treeSelectionLength]; - for (int i=0; i<result.length; i++) result [i] = _getItem (display.treeSelection [i]); - return result; - } - /* - * Bug in GTK. gtk_tree_selection_get_selected_rows() segmentation faults - * in versions smaller than 2.2.4 if the model is NULL. The fix is - * to give a valid pointer instead. - */ - int /*long*/ [] model = OS.GTK_VERSION < OS.VERSION (2, 2, 4) ? new int /*long*/ [1] : null; - int /*long*/ list = OS.gtk_tree_selection_get_selected_rows (selection, model); - if (list != 0) { - int count = OS.g_list_length (list); - int [] treeSelection = new int [count]; - int length = 0; - for (int i=0; i<count; i++) { - int /*long*/ data = OS.g_list_nth_data (list, i); - int /*long*/ indices = OS.gtk_tree_path_get_indices (data); - if (indices != 0) { - int [] index = new int [1]; - OS.memmove (index, indices, 4); - treeSelection [length] = index [0]; - length++; - } - } - OS.g_list_free (list); - TableItem [] result = new TableItem [length]; - for (int i=0; i<result.length; i++) result [i] = _getItem (treeSelection [i]); - return result; - } - return new TableItem [0]; -} - -/** - * 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 /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) { - display.treeSelectionLength = 0; - display.treeSelection = null; - OS.gtk_tree_selection_selected_foreach (selection, display.treeSelectionProc, handle); - return display.treeSelectionLength; - } - return OS.gtk_tree_selection_count_selected_rows (selection); -} - -/** - * 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 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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(); - if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) { - display.treeSelectionLength = 0; - display.treeSelection = new int [itemCount]; - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.gtk_tree_selection_selected_foreach (selection, display.treeSelectionProc, handle); - if (display.treeSelectionLength == 0) return -1; - return display.treeSelection [0]; - } - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - /* - * Bug in GTK. gtk_tree_selection_get_selected_rows() segmentation faults - * in versions smaller than 2.2.4 if the model is NULL. The fix is - * to give a valid pointer instead. - */ - int /*long*/ [] model = OS.GTK_VERSION < OS.VERSION (2, 2, 4) ? new int /*long*/ [1] : null; - int /*long*/ list = OS.gtk_tree_selection_get_selected_rows (selection, model); - if (list != 0) { - int count = OS.g_list_length (list); - int [] index = new int [1]; - for (int i=0; i<count; i++) { - int /*long*/ data = OS.g_list_nth_data (list, i); - int /*long*/ indices = OS.gtk_tree_path_get_indices (data); - if (indices != 0) { - OS.memmove (index, indices, 4); - break; - } - } - OS.g_list_free (list); - return index [0]; - } - return -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 /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) { - display.treeSelectionLength = 0; - display.treeSelection = new int [itemCount]; - OS.gtk_tree_selection_selected_foreach (selection, display.treeSelectionProc, handle); - if (display.treeSelectionLength == display.treeSelection.length) return display.treeSelection; - int [] result = new int [display.treeSelectionLength]; - System.arraycopy (display.treeSelection, 0, result, 0, display.treeSelectionLength); - return result; - } - /* - * Bug in GTK. gtk_tree_selection_get_selected_rows() segmentation faults - * in versions smaller than 2.2.4 if the model is NULL. The fix is - * to give a valid pointer instead. - */ - int /*long*/ [] model = OS.GTK_VERSION < OS.VERSION (2, 2, 4) ? new int /*long*/ [1] : null; - int /*long*/ list = OS.gtk_tree_selection_get_selected_rows (selection, model); - if (list != 0) { - int count = OS.g_list_length (list); - int [] treeSelection = new int [count]; - int length = 0; - for (int i=0; i<count; i++) { - int /*long*/ data = OS.g_list_nth_data (list, i); - int /*long*/ indices = OS.gtk_tree_path_get_indices (data); - if (indices != 0) { - int [] index = new int [1]; - OS.memmove (index, indices, 4); - treeSelection [length] = index [0]; - length++; - } - } - OS.g_list_free (list); - int [] result = new int [length]; - System.arraycopy (treeSelection, 0, result, 0, length); - return result; - } - return new int [0]; -} - -/** - * Returns the column which shows the sort indicator for - * the receiver. The value may be null if no column shows - * the sort indicator. - * - * @return the sort indicator - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 #setSortColumn(TableColumn) - * - * @since 3.2 - */ -public TableColumn getSortColumn () { - checkWidget (); - return sortColumn; -} - -/** - * Returns the direction of the sort indicator for the receiver. - * The value will be one of <code>UP</code>, <code>DOWN</code> - * or <code>NONE</code>. - * - * @return the sort direction - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 #setSortDirection(int) - * - * @since 3.2 - */ -public int getSortDirection () { - checkWidget (); - return sortDirection; -} - -int /*long*/ getTextRenderer (int /*long*/ column) { - int /*long*/ list = OS.gtk_tree_view_column_get_cell_renderers (column); - if (list == 0) return 0; - int count = OS.g_list_length (list); - int /*long*/ textRenderer = 0; - int i = 0; - while (i < count) { - int /*long*/ renderer = OS.g_list_nth_data (list, i); - if (OS.GTK_IS_CELL_RENDERER_TEXT (renderer)) { - textRenderer = renderer; - break; - } - i++; - } - OS.g_list_free (list); - return textRenderer; -} - -/** - * 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 /*long*/ [] path = new int /*long*/ [1]; - OS.gtk_widget_realize (handle); - if (!OS.gtk_tree_view_get_path_at_pos (handle, 1, 1, path, null, null, null)) return 0; - if (path [0] == 0) return 0; - int /*long*/ indices = OS.gtk_tree_path_get_indices (path[0]); - int[] index = new int [1]; - if (indices != 0) OS.memmove (index, indices, 4); - OS.gtk_tree_path_free (path [0]); - return index [0]; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, event, GdkEventButton.sizeof); - if (gdkEvent.window != OS.gtk_tree_view_get_bin_window (handle)) return 0; - int /*long*/ result = super.gtk_button_press_event (widget, event); - if (result != 0) return result; - /* - * Feature in GTK. In a multi-select table view, when multiple items are already - * selected, the selection state of the item is toggled and the previous selection - * is cleared. This is not the desired behaviour when bringing up a popup menu. - * Also, when an item is reselected with the right button, the tree view issues - * an unwanted selection event. The workaround is to detect that case and not - * run the default handler when the item is already part of the current selection. - */ - int button = gdkEvent.button; - if (button == 3 && gdkEvent.type == OS.GDK_BUTTON_PRESS) { - int /*long*/ [] path = new int /*long*/ [1]; - if (OS.gtk_tree_view_get_path_at_pos (handle, (int)gdkEvent.x, (int)gdkEvent.y, path, null, null, null)) { - if (path [0] != 0) { - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - if (OS.gtk_tree_selection_path_is_selected (selection, path [0])) result = 1; - OS.gtk_tree_path_free (path [0]); - } - } - } - - /* - * Feature in GTK. When the user clicks in a single selection GtkTreeView - * and there are no selected items, the first item is selected automatically - * before the click is processed, causing two selection events. The is fix - * is the set the cursor item to be same as the clicked item to stop the - * widget from automatically selecting the first item. - */ - if ((style & SWT.SINGLE) != 0 && getSelectionCount () == 0) { - int /*long*/ [] path = new int /*long*/ [1]; - if (OS.gtk_tree_view_get_path_at_pos (handle, (int)gdkEvent.x, (int)gdkEvent.y, path, null, null, null)) { - if (path [0] != 0) { - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_view_set_cursor (handle, path [0], 0, false); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_path_free (path [0]); - } - } - } - /* - * Bug in GTK. GTK segments fault, if the GtkTreeView widget is - * not in focus and all items in the widget are disposed before - * it finishes processing a button press. The fix is to give - * focus to the widget before it starts processing the event. - */ - if (!OS.GTK_WIDGET_HAS_FOCUS (handle)) { - OS.gtk_widget_grab_focus (handle); - } - return result; -} - -int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ window = OS.GDK_EVENT_WINDOW (event); - if (window != OS.gtk_tree_view_get_bin_window (handle)) return 0; - return super.gtk_button_release_event (widget, event); -} - -int /*long*/ gtk_changed (int /*long*/ widget) { - TableItem item = getFocusItem (); - if (item != null) { - Event event = new Event (); - event.item = item; - postEvent (SWT.Selection, event); - } - return 0; -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ eventPtr) { - int /*long*/ result = super.gtk_key_press_event (widget, eventPtr); - if (result != 0) return result; - if (OS.GTK_VERSION < OS.VERSION (2, 2 ,0)) { - /* - * Feature in GTK 2.0.x. When an item is default selected using - * the return key, GTK does not issue notification. The fix is - * to issue this notification when the return key is pressed. - */ - GdkEventKey keyEvent = new GdkEventKey (); - OS.memmove (keyEvent, eventPtr, GdkEventKey.sizeof); - int key = keyEvent.keyval; - switch (key) { - case OS.GDK_Return: - case OS.GDK_KP_Enter: { - Event event = new Event (); - event.item = getFocusItem (); - postEvent (SWT.DefaultSelection, event); - break; - } - } - } - return result; -} - -int /*long*/ gtk_popup_menu (int /*long*/ widget) { - int /*long*/ result = super.gtk_popup_menu (widget); - /* - * Bug in GTK. The context menu for the typeahead in GtkTreeViewer - * opens in the bottom right corner of the screen when Shift+F10 - * is pressed and the typeahead window was not visible. The fix is - * to prevent the context menu from opening by stopping the default - * handler. - * - * NOTE: The bug only happens in GTK 2.6.5 and lower. - */ - return OS.GTK_VERSION < OS.VERSION (2, 6, 5) ? 1 : result; -} - -int /*long*/ gtk_motion_notify_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ window = OS.GDK_EVENT_WINDOW (event); - if (window != OS.gtk_tree_view_get_bin_window (handle)) return 0; - return super.gtk_motion_notify_event (widget, event); -} - -int /*long*/ gtk_row_activated (int /*long*/ tree, int /*long*/ path, int /*long*/ column) { - TableItem item = null; - int /*long*/ indices = OS.gtk_tree_path_get_indices (path); - if (indices != 0) { - int [] index = new int []{-1}; - OS.memmove (index, indices, 4); - item = _getItem (index [0]); - } - Event event = new Event (); - event.item = item; - postEvent (SWT.DefaultSelection, event); - return 0; -} - -int gtk_row_deleted (int model, int path) { - if (ignoreAccessibility) { - OS.g_signal_stop_emission_by_name (model, OS.row_deleted); - } - return 0; -} - -int gtk_row_inserted (int model, int path, int iter) { - if (ignoreAccessibility) { - OS.g_signal_stop_emission_by_name (model, OS.row_inserted); - } - return 0; -} - -int /*long*/ gtk_toggled (int /*long*/ renderer, int /*long*/ pathStr) { - int /*long*/ path = OS.gtk_tree_path_new_from_string (pathStr); - if (path == 0) return 0; - int /*long*/ indices = OS.gtk_tree_path_get_indices (path); - if (indices != 0) { - int [] index = new int [1]; - OS.memmove (index, indices, 4); - TableItem item = _getItem (index [0]); - item.setChecked (!item.getChecked ()); - Event event = new Event (); - event.detail = SWT.CHECK; - event.item = item; - postEvent (SWT.Selection, event); - } - OS.gtk_tree_path_free (path); - return 0; -} - -void gtk_widget_size_request (int /*long*/ widget, GtkRequisition requisition) { - /* - * Bug in GTK. For some reason, gtk_widget_size_request() fails - * to include the height of the tree view items when there are - * no columns visible. The fix is to temporarily make one column - * visible. - */ - if (columnCount == 0) { - super.gtk_widget_size_request (widget, requisition); - return; - } - int /*long*/ columns = OS.gtk_tree_view_get_columns (handle), list = columns; - boolean fixVisible = columns != 0; - while (list != 0) { - int /*long*/ column = OS.g_list_data (list); - if (OS.gtk_tree_view_column_get_visible (column)) { - fixVisible = false; - break; - } - list = OS.g_list_next (list); - } - int /*long*/ columnHandle = 0; - if (fixVisible) { - columnHandle = OS.g_list_data (columns); - OS.gtk_tree_view_column_set_visible (columnHandle, true); - } - super.gtk_widget_size_request (widget, requisition); - if (fixVisible) { - OS.gtk_tree_view_column_set_visible (columnHandle, false); - } - if (columns != 0) OS.g_list_free (columns); -} - -void hideFirstColumn () { - int /*long*/ firstColumn = OS.gtk_tree_view_get_column (handle, 0); - OS.gtk_tree_view_column_set_visible (firstColumn, false); -} - -void hookEvents () { - super.hookEvents (); - int /*long*/ selection = OS.gtk_tree_view_get_selection(handle); - OS.g_signal_connect_closure (selection, OS.changed, display.closures [CHANGED], false); - OS.g_signal_connect_closure (handle, OS.row_activated, display.closures [ROW_ACTIVATED], false); - if (checkRenderer != 0) { - OS.g_signal_connect_closure (checkRenderer, OS.toggled, display.closures [TOGGLED], false); - } - if (fixAccessibility ()) { - OS.g_signal_connect_closure (modelHandle, OS.row_inserted, display.closures [ROW_INSERTED], true); - OS.g_signal_connect_closure (modelHandle, OS.row_deleted, display.closures [ROW_DELETED], true); - } -} - -/** - * Searches the receiver's list starting at the first column - * (index 0) until a column is found that is equal to the - * argument, and returns the index of that column. If no column - * is found, returns -1. - * - * @param column the search column - * @return the index of the column - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the column 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 (TableColumn column) { - checkWidget(); - if (column == null) error (SWT.ERROR_NULL_ARGUMENT); - for (int i=0; i<columnCount; i++) { - if (columns [i] == column) return i; - } - return -1; -} - -/** - * 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 (TableItem item) { - checkWidget(); - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - if (1 <= lastIndexOf && lastIndexOf < itemCount - 1) { - if (items [lastIndexOf] == item) return lastIndexOf; - if (items [lastIndexOf + 1] == item) return ++lastIndexOf; - if (items [lastIndexOf - 1] == item) return --lastIndexOf; - } - if (lastIndexOf < itemCount / 2) { - for (int i=0; i<itemCount; i++) { - if (items [i] == item) return lastIndexOf = i; - } - } else { - for (int i=itemCount - 1; i>=0; --i) { - if (items [i] == item) return lastIndexOf = i; - } - } - return -1; -} - -/** - * 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(); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - byte [] buffer = Converter.wcsToMbcs (null, Integer.toString (index), true); - int /*long*/ path = OS.gtk_tree_path_new_from_string (buffer); - boolean answer = OS.gtk_tree_selection_path_is_selected (selection, path); - OS.gtk_tree_path_free (path); - return answer; -} - -boolean mnemonicHit (char key) { - for (int i=0; i<columnCount; i++) { - int /*long*/ labelHandle = columns [i].labelHandle; - if (labelHandle != 0 && mnemonicHit (labelHandle, key)) return true; - } - return false; -} - -boolean mnemonicMatch (char key) { - for (int i=0; i<columnCount; i++) { - int /*long*/ labelHandle = columns [i].labelHandle; - if (labelHandle != 0 && mnemonicMatch (labelHandle, key)) return true; - } - return false; -} - -int /*long*/ paintWindow () { - OS.gtk_widget_realize (handle); - return OS.gtk_tree_view_get_bin_window (handle); -} - -void recreateRenderers () { - if (checkRenderer != 0) { - display.removeWidget (checkRenderer); - OS.g_object_unref (checkRenderer); - checkRenderer = ownerDraw ? OS.g_object_new (display.gtk_cell_renderer_toggle_get_type(), 0) : OS.gtk_cell_renderer_toggle_new (); - if (checkRenderer == 0) error (SWT.ERROR_NO_HANDLES); - OS.g_object_ref (checkRenderer); - display.addWidget (checkRenderer, this); - OS.g_signal_connect_closure (checkRenderer, OS.toggled, display.closures [TOGGLED], false); - } - if (columnCount == 0) { - createRenderers (OS.gtk_tree_view_get_column (handle, 0), Table.FIRST_COLUMN, true, 0); - } else { - for (int i = 0; i < columnCount; i++) { - TableColumn column = columns [i]; - createRenderers (column.handle, column.modelIndex, i == 0, column.style); - } - } -} - -void redrawBackgroundImage () { - Control control = findBackgroundControl (); - if (control != null && control.backgroundImage != null) { - redrawWidget (0, 0, 0, 0, true, false, false); - } -} - -void register () { - super.register (); - display.addWidget (OS.gtk_tree_view_get_selection (handle), this); - if (checkRenderer != 0) display.addWidget (checkRenderer, this); - display.addWidget (modelHandle, this); -} - -void releaseChildren (boolean destroy) { - if (items != null) { - for (int i=0; i<itemCount; i++) { - TableItem item = items [i]; - if (item != null && !item.isDisposed ()) { - item.release (false); - } - } - items = null; - } - if (columns != null) { - for (int i=0; i<columnCount; i++) { - TableColumn column = columns [i]; - if (column != null && !column.isDisposed ()) { - column.release (false); - } - } - columns = null; - } - super.releaseChildren (destroy); -} - -void releaseWidget () { - super.releaseWidget (); - if (modelHandle != 0) OS.g_object_unref (modelHandle); - modelHandle = 0; - if (checkRenderer != 0) OS.g_object_unref (checkRenderer); - checkRenderer = 0; - if (imageList != null) imageList.dispose (); - if (headerImageList != null) headerImageList.dispose (); - imageList = headerImageList = null; - currentItem = null; -} - -/** - * 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 (!(0 <= index && index < itemCount)) error (SWT.ERROR_ITEM_NOT_REMOVED); - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - TableItem item = items [index]; - boolean disposed = false; - if (item != null) { - disposed = item.isDisposed (); - if (!disposed) { - OS.memmove (iter, item.handle, OS.GtkTreeIter_sizeof ()); - item.release (false); - } - } else { - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - } - if (!disposed) { - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_list_store_remove (modelHandle, iter); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - System.arraycopy (items, index + 1, items, index, --itemCount - index); - items [itemCount] = null; - } - OS.g_free (iter); -} - -/** - * 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; - if (!(0 <= start && start <= end && end < itemCount)) { - error (SWT.ERROR_INVALID_RANGE); - } - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (iter == 0) error (SWT.ERROR_NO_HANDLES); - if (fixAccessibility ()) { - ignoreAccessibility = true; - } - int index = end; - while (index >= start) { - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - TableItem item = items [index]; - if (item != null && !item.isDisposed ()) item.release (false); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_list_store_remove (modelHandle, iter); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - index--; - } - if (fixAccessibility ()) { - ignoreAccessibility = false; - OS.g_object_notify (handle, OS.model); - } - OS.g_free (iter); - index = end + 1; - System.arraycopy (items, index, items, start, itemCount - index); - for (int i=itemCount-(index-start); i<itemCount; i++) items [i] = null; - itemCount = itemCount - (index - start); -} - -/** - * Removes the items from the receiver's list 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 [] newIndices = new int [indices.length]; - System.arraycopy (indices, 0, newIndices, 0, indices.length); - sort (newIndices); - int start = newIndices [newIndices.length - 1], end = newIndices [0]; - if (!(0 <= start && start <= end && end < itemCount)) { - error (SWT.ERROR_INVALID_RANGE); - } - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - int last = -1; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (iter == 0) error (SWT.ERROR_NO_HANDLES); - if (fixAccessibility ()) { - ignoreAccessibility = true; - } - for (int i=0; i<newIndices.length; i++) { - int index = newIndices [i]; - if (index != last) { - TableItem item = items [index]; - boolean disposed = false; - if (item != null) { - disposed = item.isDisposed (); - if (!disposed) { - OS.memmove (iter, item.handle, OS.GtkTreeIter_sizeof ()); - item.release (false); - } - } else { - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, 0, index); - } - if (!disposed) { - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_list_store_remove (modelHandle, iter); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - System.arraycopy (items, index + 1, items, index, --itemCount - index); - items [itemCount] = null; - } - last = index; - } - } - if (fixAccessibility ()) { - ignoreAccessibility = false; - OS.g_object_notify (handle, OS.model); - } - OS.g_free (iter); -} - -/** - * Removes all of the items from 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 removeAll () { - checkWidget(); - int index = itemCount - 1; - while (index >= 0) { - TableItem item = items [index]; - if (item != null && !item.isDisposed ()) item.release (false); - --index; - } - items = new TableItem [4]; - itemCount = 0; - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if (fixAccessibility ()) { - ignoreAccessibility = true; - } - OS.gtk_list_store_clear (modelHandle); - if (fixAccessibility ()) { - ignoreAccessibility = false; - OS.g_object_notify (handle, OS.model); - } - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - - resetCustomDraw (); - /* Disable searching when using VIRTUAL */ - if ((style & SWT.VIRTUAL) != 0) { - /* - * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE) - * would prevent the user from being able to type in text to search the tree. - * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive - * search. This meant that even if FALSE was passed to enable_search, the user - * can still bring up the search pop up using the keybinding. GTK also introduced - * the notion of passing a -1 to gtk_set_search_column to disable searching - * (including the search key binding). The fix is to use the right calls - * for the right version. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 5)){ - OS.gtk_tree_view_set_search_column (handle, -1); - } else { - OS.gtk_tree_view_set_enable_search (handle, false); - } - } else { - /* Set the search column whenever the model changes */ - int firstColumn = columnCount == 0 ? FIRST_COLUMN : columns [0].modelIndex; - OS.gtk_tree_view_set_search_column (handle, firstColumn + CELL_TEXT); - } -} - -/** - * 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(SelectionListener) - */ -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); -} - -int /*long*/ rendererGetSizeProc (int /*long*/ cell, int /*long*/ widget, int /*long*/ cell_area, int /*long*/ x_offset, int /*long*/ y_offset, int /*long*/ width, int /*long*/ height) { - int /*long*/ g_class = OS.g_type_class_peek_parent (OS.G_OBJECT_GET_CLASS (cell)); - GtkCellRendererClass klass = new GtkCellRendererClass (); - OS.memmove (klass, g_class); - int /*long*/ result = OS.call (klass.get_size, cell, handle, cell_area, x_offset, y_offset, width, height); - if (!ignoreSize && OS.GTK_IS_CELL_RENDERER_TEXT (cell)) { - int /*long*/ iter = OS.g_object_get_qdata (cell, Display.SWT_OBJECT_INDEX2); - TableItem item = null; - if (iter != 0) { - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter); - int [] buffer = new int [1]; - OS.memmove (buffer, OS.gtk_tree_path_get_indices (path), 4); - int index = buffer [0]; - item = _getItem (index); - OS.gtk_tree_path_free (path); - } - if (item != null) { - int columnIndex = 0; - if (columnCount > 0) { - int /*long*/ columnHandle = OS.g_object_get_qdata (cell, Display.SWT_OBJECT_INDEX1); - for (int i = 0; i < columnCount; i++) { - if (columns [i].handle == columnHandle) { - columnIndex = i; - break; - } - } - } - if (hooks (SWT.MeasureItem)) { - int [] contentWidth = new int [1], contentHeight = new int [1]; - if (width != 0) OS.memmove (contentWidth, width, 4); - if (height != 0) OS.memmove (contentHeight, height, 4); - Image image = item.getImage (columnIndex); - int imageWidth = 0; - if (image != null) { - Rectangle bounds = image.getBounds (); - imageWidth = bounds.width; - } - contentWidth [0] += imageWidth; - GC gc = new GC (this); - gc.setFont (item.getFont (columnIndex)); - Event event = new Event (); - event.item = item; - event.index = columnIndex; - event.gc = gc; - event.width = contentWidth [0]; - event.height = contentHeight [0]; - sendEvent (SWT.MeasureItem, event); - gc.dispose (); - contentWidth [0] = event.width - imageWidth; - if (contentHeight [0] < event.height) contentHeight [0] = event.height; - if (width != 0) OS.memmove (width, contentWidth, 4); - if (height != 0) OS.memmove (height, contentHeight, 4); - } - } - } - return result; -} - -int /*long*/ rendererRenderProc (int /*long*/ cell, int /*long*/ window, int /*long*/ widget, int /*long*/ background_area, int /*long*/ cell_area, int /*long*/ expose_area, int /*long*/ flags) { - TableItem item = null; - int /*long*/ iter = OS.g_object_get_qdata (cell, Display.SWT_OBJECT_INDEX2); - if (iter != 0) { - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter); - int [] buffer = new int [1]; - OS.memmove (buffer, OS.gtk_tree_path_get_indices (path), 4); - int index = buffer [0]; - item = _getItem (index); - OS.gtk_tree_path_free (path); - } - int /*long*/ columnHandle = OS.g_object_get_qdata (cell, Display.SWT_OBJECT_INDEX1); - int columnIndex = 0; - if (columnCount > 0) { - for (int i = 0; i < columnCount; i++) { - if (columns [i].handle == columnHandle) { - columnIndex = i; - break; - } - } - } - if (item != null) { - if (OS.GTK_IS_CELL_RENDERER_TOGGLE (cell) || (OS.GTK_IS_CELL_RENDERER_PIXBUF (cell) && (columnIndex != 0 || (style & SWT.CHECK) == 0))) { - drawFlags = (int)/*64*/flags; - drawState = SWT.FOREGROUND; - int /*long*/ [] ptr = new int /*long*/ [1]; - OS.gtk_tree_model_get (modelHandle, item.handle, Table.BACKGROUND_COLUMN, ptr, -1); - if (ptr [0] == 0) { - int modelIndex = columnCount == 0 ? Table.FIRST_COLUMN : columns [columnIndex].modelIndex; - OS.gtk_tree_model_get (modelHandle, item.handle, modelIndex + Table.CELL_BACKGROUND, ptr, -1); - } - if (ptr [0] != 0) drawState |= SWT.BACKGROUND; - if ((flags & OS.GTK_CELL_RENDERER_SELECTED) != 0) drawState |= SWT.SELECTED; - if ((flags & OS.GTK_CELL_RENDERER_FOCUSED) != 0) drawState |= SWT.FOCUSED; - - GdkRectangle rect = new GdkRectangle (); - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter); - OS.gtk_tree_view_get_background_area (handle, path, columnHandle, rect); - OS.gtk_tree_path_free (path); - - if ((drawState & SWT.SELECTED) == 0) { - Control control = findBackgroundControl (); - if (control != null && control.backgroundImage != null) { - OS.gdk_window_clear_area (window, rect.x, rect.y, rect.width, rect.height); - } - } - - if (hooks (SWT.EraseItem)) { - boolean wasSelected = false; - if ((drawState & SWT.SELECTED) != 0) { - wasSelected = true; - OS.gdk_window_clear_area (window, rect.x, rect.y, rect.width, rect.height); - } - GC gc = new GC (this); - if ((drawState & SWT.SELECTED) != 0) { - gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION)); - gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT)); - } else { - gc.setBackground (item.getBackground (columnIndex)); - gc.setForeground (item.getForeground (columnIndex)); - } - gc.setFont (item.getFont (columnIndex)); - if ((style & SWT.MIRRORED) != 0) rect.x = getClientWidth () - rect.width - rect.x; - gc.setClipping (rect.x, rect.y, rect.width, rect.height); - Event event = new Event (); - event.item = item; - event.index = columnIndex; - event.gc = gc; - event.x = rect.x; - event.y = rect.y; - event.width = rect.width; - event.height = rect.height; - event.detail = drawState; - sendEvent (SWT.EraseItem, event); - drawForeground = null; - drawState = event.doit ? event.detail : 0; - drawFlags &= ~(OS.GTK_CELL_RENDERER_FOCUSED | OS.GTK_CELL_RENDERER_SELECTED); - if ((drawState & SWT.SELECTED) != 0) drawFlags |= OS.GTK_CELL_RENDERER_SELECTED; - if ((drawState & SWT.FOCUSED) != 0) drawFlags |= OS.GTK_CELL_RENDERER_FOCUSED; - if ((drawState & SWT.SELECTED) != 0) { - int /*long*/ style = OS.gtk_widget_get_style (widget); - //TODO - parity and sorted - byte[] detail = Converter.wcsToMbcs (null, "cell_odd", true); - OS.gtk_paint_flat_box (style, window, OS.GTK_STATE_SELECTED, OS.GTK_SHADOW_NONE, rect, widget, detail, rect.x, rect.y, rect.width, rect.height); - } else { - if (wasSelected) drawForeground = gc.getForeground ().handle; - } - gc.dispose(); - } - } - } - int /*long*/ result = 0; - if ((drawState & SWT.BACKGROUND) != 0 && (drawState & SWT.SELECTED) == 0) { - GC gc = new GC (this); - gc.setBackground (item.getBackground (columnIndex)); - GdkRectangle rect = new GdkRectangle (); - OS.memmove (rect, background_area, GdkRectangle.sizeof); - gc.fillRectangle (rect.x, rect.y, rect.width, rect.height); - gc.dispose (); - } - if ((drawState & SWT.FOREGROUND) != 0 || OS.GTK_IS_CELL_RENDERER_TOGGLE (cell)) { - int /*long*/ g_class = OS.g_type_class_peek_parent (OS.G_OBJECT_GET_CLASS (cell)); - GtkCellRendererClass klass = new GtkCellRendererClass (); - OS.memmove (klass, g_class); - if (drawForeground != null && OS.GTK_IS_CELL_RENDERER_TEXT (cell)) { - OS.g_object_set (cell, OS.foreground_gdk, drawForeground, 0); - } - result = OS.call (klass.render, cell, window, handle, background_area, cell_area, expose_area, drawFlags); - } - if (item != null) { - if (OS.GTK_IS_CELL_RENDERER_TEXT (cell)) { - if (hooks (SWT.PaintItem)) { - GdkRectangle rect = new GdkRectangle (); - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter); - OS.gtk_tree_view_get_background_area (handle, path, columnHandle, rect); - OS.gtk_tree_path_free (path); - ignoreSize = true; - int [] contentX = new int [1], contentWidth = new int [1]; - OS.gtk_cell_renderer_get_size (cell, handle, null, null, null, contentWidth, null); - OS.gtk_tree_view_column_cell_get_position (columnHandle, cell, contentX, null); - ignoreSize = false; - Image image = item.getImage (columnIndex); - int imageWidth = 0; - if (image != null) { - Rectangle bounds = image.getBounds (); - imageWidth = bounds.width; - } - contentX [0] -= imageWidth; - contentWidth [0] += imageWidth; - GC gc = new GC (this); - if ((drawState & SWT.SELECTED) != 0) { - gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION)); - gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT)); - } else { - gc.setBackground (item.getBackground (columnIndex)); - Color foreground = drawForeground != null ? Color.gtk_new (display, drawForeground) : item.getForeground (columnIndex); - gc.setForeground (foreground); - } - gc.setFont (item.getFont (columnIndex)); - if ((style & SWT.MIRRORED) != 0) rect.x = getClientWidth () - rect.width - rect.x; - gc.setClipping (rect.x, rect.y, rect.width, rect.height); - Event event = new Event (); - event.item = item; - event.index = columnIndex; - event.gc = gc; - event.x = rect.x + contentX [0]; - event.y = rect.y; - event.width = contentWidth [0]; - event.height = rect.height; - event.detail = drawState; - sendEvent (SWT.PaintItem, event); - gc.dispose(); - } - } - } - return result; -} - -void resetCustomDraw () { - if ((style & SWT.VIRTUAL) != 0 || ownerDraw) return; - int end = Math.max (1, columnCount); - for (int i=0; i<end; i++) { - boolean customDraw = columnCount != 0 ? columns [i].customDraw : firstCustomDraw; - if (customDraw) { - int /*long*/ column = OS.gtk_tree_view_get_column (handle, i); - int /*long*/ textRenderer = getTextRenderer (column); - OS.gtk_tree_view_column_set_cell_data_func (column, textRenderer, 0, 0, 0); - if (columnCount != 0) columns [i].customDraw = false; - } - } - firstCustomDraw = false; -} - -/** - * Selects the item at the given zero-relative index in the receiver. - * 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 (!(0 <= index && index < itemCount)) return; - boolean fixColumn = showFirstColumn (); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - TableItem item = _getItem (index); - OS.gtk_tree_selection_select_iter (selection, item.handle); - if ((style & SWT.SINGLE) != 0) { - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, item.handle); - OS.gtk_tree_view_set_cursor (handle, path, 0, false); - OS.gtk_tree_path_free (path); - } - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if (fixColumn) hideFirstColumn (); -} - -/** - * 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. - * </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> - * - * @see Table#setSelection(int,int) - */ -public void select (int start, int end) { - checkWidget (); - if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return; - if (itemCount == 0 || start >= itemCount) return; - start = Math.max (0, start); - end = Math.min (end, itemCount - 1); - boolean fixColumn = showFirstColumn (); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - for (int index=start; index<=end; index++) { - TableItem item = _getItem (index); - OS.gtk_tree_selection_select_iter (selection, item.handle); - if ((style & SWT.SINGLE) != 0) { - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, item.handle); - OS.gtk_tree_view_set_cursor (handle, path, 0, false); - OS.gtk_tree_path_free (path); - } - } - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if (fixColumn) hideFirstColumn (); -} - -/** - * 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. - * </p> - * - * @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 Table#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; - boolean fixColumn = showFirstColumn (); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - for (int i=0; i<length; i++) { - int index = indices [i]; - if (!(0 <= index && index < itemCount)) continue; - TableItem item = _getItem (index); - OS.gtk_tree_selection_select_iter (selection, item.handle); - if ((style & SWT.SINGLE) != 0) { - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, item.handle); - OS.gtk_tree_view_set_cursor (handle, path, 0, false); - OS.gtk_tree_path_free (path); - } - } - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if (fixColumn) hideFirstColumn (); -} - -/** - * Selects all of the items in the receiver. - * <p> - * If the receiver is single-select, do nothing. - * </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 selectAll () { - checkWidget(); - if ((style & SWT.SINGLE) != 0) return; - boolean fixColumn = showFirstColumn (); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_selection_select_all (selection); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if (fixColumn) hideFirstColumn (); -} - -void selectFocusIndex (int index) { - /* - * Note that this method both selects and sets the focus to the - * specified index, so any previous selection in the list will be lost. - * gtk does not provide a way to just set focus to a specified list item. - */ - if (!(0 <= index && index < itemCount)) return; - TableItem item = _getItem (index); - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, item.handle); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_view_set_cursor (handle, path, 0, false); - /* - * Bug in GTK. For some reason, when an event loop is run from - * within a key pressed handler and a dialog is displayed that - * contains a GtkTreeView, gtk_tree_view_set_cursor() does - * not set the cursor or select the item. The fix is to select the - * item with gtk_tree_selection_select_iter() as well. - * - * NOTE: This happens in GTK 2.2.1 and is fixed in GTK 2.2.4. - */ - OS.gtk_tree_selection_select_iter (selection, item.handle); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_path_free (path); -} - -void setBackgroundColor (GdkColor color) { - super.setBackgroundColor (color); - OS.gtk_widget_modify_base (handle, 0, color); -} - -void setBackgroundPixmap (int /*long*/ pixmap) { - super.setBackgroundPixmap (pixmap); - int /*long*/ window = paintWindow (); - if (window != 0) OS.gdk_window_set_back_pixmap (window, 0, true); -} - -int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - int result = super.setBounds (x, y, width, height, move, resize); - /* - * Bug on GTK. The tree view sometimes does not get a paint - * event or resizes to a one pixel square when resized in a new - * shell that is not visible after any event loop has been run. The - * problem is intermittent. It doesn't seem to happen the first time - * a new shell is created. The fix is to ensure the tree view is realized - * after it has been resized. - */ - OS.gtk_widget_realize (handle); - /* - * Bug in GTK. An empty GtkTreeView fails to repaint the focus rectangle - * correctly when resized on versions before 2.6.0. The fix is to force - * the widget to redraw. - */ - if (OS.GTK_VERSION < OS.VERSION (2, 6, 0) && itemCount == 0) redraw (false); - return result; -} - -/** - * Sets the order that the items in the receiver should - * be displayed in to the given argument which is described - * in terms of the zero-relative ordering of when the items - * were added. - * - * @param order the new order to display the 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> - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the item order is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li> - * </ul> - * - * @see Table#getColumnOrder() - * @see TableColumn#getMoveable() - * @see TableColumn#setMoveable(boolean) - * @see SWT#Move - * - * @since 3.1 - */ -public void setColumnOrder (int [] order) { - checkWidget (); - if (order == null) error (SWT.ERROR_NULL_ARGUMENT); - if (columnCount == 0) { - if (order.length > 0) error (SWT.ERROR_INVALID_ARGUMENT); - return; - } - if (order.length != columnCount) error (SWT.ERROR_INVALID_ARGUMENT); - boolean [] seen = new boolean [columnCount]; - for (int i = 0; i<order.length; i++) { - int index = order [i]; - if (index < 0 || index >= columnCount) error (SWT.ERROR_INVALID_RANGE); - if (seen [index]) error (SWT.ERROR_INVALID_ARGUMENT); - seen [index] = true; - } - for (int i=0; i<order.length; i++) { - int /*long*/ column = columns [order [i]].handle; - int /*long*/ baseColumn = i == 0 ? 0 : columns [order [i-1]].handle; - OS.gtk_tree_view_move_column_after (handle, column, baseColumn); - } -} - -void setFontDescription (int /*long*/ font) { - super.setFontDescription (font); - TableColumn[] columns = getColumns (); - for (int i = 0; i < columns.length; i++) { - if (columns[i] != null) { - columns[i].setFontDescription (font); - } - } -} - -/** - * Marks the receiver's header 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 show 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 setHeaderVisible (boolean show) { - checkWidget (); - OS.gtk_tree_view_set_headers_visible (handle, show); -} - -/** - * Sets the number of items contained in the receiver. - * - * @param count 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> - * - * @since 3.0 - */ -public void setItemCount (int count) { - checkWidget (); - count = Math.max (0, count); - if (count == itemCount) return; - boolean isVirtual = (style & SWT.VIRTUAL) != 0; - if (!isVirtual) setRedraw (false); - remove (count, itemCount - 1); - int length = Math.max (4, (count + 3) / 4 * 4); - TableItem [] newItems = new TableItem [length]; - System.arraycopy (items, 0, newItems, 0, itemCount); - items = newItems; - if (isVirtual) { - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (iter == 0) error (SWT.ERROR_NO_HANDLES); - if (fixAccessibility ()) { - ignoreAccessibility = true; - } - for (int i=itemCount; i<count; i++) { - OS.gtk_list_store_append (modelHandle, iter); - } - if (fixAccessibility ()) { - ignoreAccessibility = false; - OS.g_object_notify (handle, OS.model); - } - OS.g_free (iter); - itemCount = count; - } else { - for (int i=itemCount; i<count; i++) { - new TableItem (this, SWT.NONE, i, true); - } - } - if (!isVirtual) setRedraw (true); -} - -/** - * Marks the receiver's lines as visible if the argument is <code>true</code>, - * and marks it invisible otherwise. Note that some platforms draw grid lines - * while others may draw alternating row colors. - * <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 show 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 setLinesVisible (boolean show) { - checkWidget(); - OS.gtk_tree_view_set_rules_hint (handle, show); - if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0)) { - OS.gtk_tree_view_set_grid_lines (handle, show ? OS.GTK_TREE_VIEW_GRID_LINES_VERTICAL : OS.GTK_TREE_VIEW_GRID_LINES_NONE); - } -} - -void setParentBackground () { - super.setParentBackground (); - int /*long*/ window = paintWindow (); - if (window != 0) OS.gdk_window_set_back_pixmap (window, 0, true); -} - -void setParentWindow (int /*long*/ widget) { - int /*long*/ window = eventWindow (); - OS.gtk_widget_set_parent_window (widget, window); -} - -public void setRedraw (boolean redraw) { - checkWidget(); - super.setRedraw (redraw); - if (redraw && drawCount == 0) { - /* Resize the item array to match the item count */ - if (items.length > 4 && items.length - itemCount > 3) { - int length = Math.max (4, (itemCount + 3) / 4 * 4); - TableItem [] newItems = new TableItem [length]; - System.arraycopy (items, 0, newItems, 0, itemCount); - items = newItems; - } - } -} - -void setScrollWidth (int /*long*/ column, TableItem item) { - if (columnCount != 0 || currentItem == item) return; - /* - * Use GTK_TREE_VIEW_COLUMN_GROW_ONLY on GTK versions < 2.3.2 - * because fixed_height_mode is not supported. - */ - if (((style & SWT.VIRTUAL) != 0) && OS.GTK_VERSION < OS.VERSION (2, 3, 2)) return; - int width = OS.gtk_tree_view_column_get_fixed_width (column); - int itemWidth = calculateWidth (column, item.handle); - if (width < itemWidth) { - OS.gtk_tree_view_column_set_fixed_width (column, itemWidth); - } -} - -/** - * Sets the column used by the sort indicator for the receiver. A null - * value will clear the sort indicator. The current sort column is cleared - * before the new column is set. - * - * @param column the column used by the sort indicator or <code>null</code> - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the column is 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 setSortColumn (TableColumn column) { - checkWidget (); - if (column != null && column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - if (sortColumn != null && !sortColumn.isDisposed()) { - OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, false); - } - sortColumn = column; - if (sortColumn != null && sortDirection != SWT.NONE) { - OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, true); - OS.gtk_tree_view_column_set_sort_order (sortColumn.handle, sortDirection == SWT.DOWN ? 0 : 1); - } -} - -/** - * Sets the direction of the sort indicator for the receiver. The value - * can be one of <code>UP</code>, <code>DOWN</code> or <code>NONE</code>. - * - * @param direction the direction of the sort indicator - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 setSortDirection (int direction) { - checkWidget (); - if (direction != SWT.UP && direction != SWT.DOWN && direction != SWT.NONE) return; - sortDirection = direction; - if (sortColumn == null || sortColumn.isDisposed ()) return; - if (sortDirection == SWT.NONE) { - OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, false); - } else { - OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, true); - OS.gtk_tree_view_column_set_sort_order (sortColumn.handle, sortDirection == SWT.DOWN ? 0 : 1); - } -} - -/** - * Selects the item at the given zero-relative index in the receiver. - * The current selection is first cleared, then the new item is selected. - * - * @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 Table#deselectAll() - * @see Table#select(int) - */ -public void setSelection (int index) { - checkWidget (); - boolean fixColumn = showFirstColumn (); - deselectAll (); - selectFocusIndex (index); - showSelection (); - if (fixColumn) hideFirstColumn (); -} - -/** - * 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. - * </p> - * - * @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 Table#deselectAll() - * @see Table#select(int,int) - */ -public void setSelection (int start, int end) { - checkWidget (); - deselectAll(); - if (end < 0 || start > end || ((style & SWT.SINGLE) != 0 && start != end)) return; - if (itemCount == 0 || start >= itemCount) return; - boolean fixColumn = showFirstColumn (); - start = Math.max (0, start); - end = Math.min (end, itemCount - 1); - selectFocusIndex (start); - if ((style & SWT.MULTI) != 0) { - select (start, end); - } - showSelection (); - if (fixColumn) hideFirstColumn (); -} - -/** - * 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. - * </p> - * - * @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 Table#deselectAll() - * @see Table#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; - boolean fixColumn = showFirstColumn (); - selectFocusIndex (indices [0]); - if ((style & SWT.MULTI) != 0) { - select (indices); - } - showSelection (); - if (fixColumn) hideFirstColumn (); -} - -/** - * Sets the receiver's selection to the given item. - * The current selection is cleared before the new item is selected. - * <p> - * If the item is not in the receiver, then it is ignored. - * </p> - * - * @param item the item to select - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the item is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the 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> - * - * @since 3.2 - */ -public void setSelection (TableItem item) { - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - setSelection (new TableItem [] {item}); -} - - -/** - * 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. - * </p> - * - * @param items the array of items - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li> - * <li>ERROR_INVALID_ARGUMENT - if one of the items 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 Table#deselectAll() - * @see Table#select(int[]) - * @see Table#setSelection(int[]) - */ -public void setSelection (TableItem [] items) { - checkWidget (); - if (items == null) error (SWT.ERROR_NULL_ARGUMENT); - boolean fixColumn = showFirstColumn (); - deselectAll (); - int length = items.length; - if (!(length == 0 || ((style & SWT.SINGLE) != 0 && length > 1))) { - boolean first = true; - for (int i = 0; i < length; i++) { - int index = indexOf (items [i]); - if (index != -1) { - if (first) { - first = false; - selectFocusIndex (index); - } else { - select (index); - } - } - } - showSelection (); - } - if (fixColumn) hideFirstColumn (); -} - -/** - * 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(); - if (!(0 <= index && index < itemCount)) return; - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, _getItem (index).handle); - OS.gtk_tree_view_scroll_to_cell (handle, path, 0, true, 0f, 0f); - if (OS.GTK_VERSION < OS.VERSION (2, 8, 0)) { - /* - * Bug in GTK. According to the documentation, gtk_tree_view_scroll_to_cell - * should vertically scroll the cell to the top if use_align is true and row_align is 0. - * However, prior to version 2.8 it does not scroll at all. The fix is to determine - * the new location and use gtk_tree_view_scroll_to_point. - * If the widget is a pinhead, calling gtk_tree_view_scroll_to_point - * will have no effect. Therefore, it is still neccessary to call - * gtk_tree_view_scroll_to_cell. - */ - OS.gtk_widget_realize (handle); - GdkRectangle cellRect = new GdkRectangle (); - OS.gtk_tree_view_get_cell_area (handle, path, 0, cellRect); - int[] tx = new int[1], ty = new int[1]; - OS.gtk_tree_view_widget_to_tree_coords(handle, cellRect.x, cellRect.y, tx, ty); - OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0]); - } - OS.gtk_tree_path_free (path); -} - -/** - * Shows the column. If the column is already showing in the receiver, - * this method simply returns. Otherwise, the columns are scrolled until - * the column is visible. - * - * @param column the column to be shown - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the column is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the column 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 showColumn (TableColumn column) { - checkWidget (); - if (column == null) error (SWT.ERROR_NULL_ARGUMENT); - if (column.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - if (column.parent != this) return; - /* - * This code is intentionally commented. According to the - * documentation, gtk_tree_view_scroll_to_cell should scroll the - * minimum amount to show the column but instead it scrolls strangely. - */ - //OS.gtk_tree_view_scroll_to_cell (handle, 0, column.handle, false, 0, 0); - OS.gtk_widget_realize (handle); - GdkRectangle cellRect = new GdkRectangle (); - OS.gtk_tree_view_get_cell_area (handle, 0, column.handle, cellRect); - GdkRectangle visibleRect = new GdkRectangle (); - OS.gtk_tree_view_get_visible_rect (handle, visibleRect); - if (cellRect.x < visibleRect.x) { - OS.gtk_tree_view_scroll_to_point (handle, cellRect.x, -1); - } else { - int width = Math.min (visibleRect.width, cellRect.width); - if (cellRect.x + width > visibleRect.x + visibleRect.width) { - int tree_x = cellRect.x + width - visibleRect.width; - OS.gtk_tree_view_scroll_to_point (handle, tree_x, -1); - } - } -} - -boolean showFirstColumn () { - /* - * Bug in GTK. If no columns are visible, changing the selection - * will fail. The fix is to temporarily make a column visible. - */ - int columnCount = Math.max (1, this.columnCount); - for (int i=0; i<columnCount; i++) { - int /*long*/ column = OS.gtk_tree_view_get_column (handle, i); - if (OS.gtk_tree_view_column_get_visible (column)) return false; - } - int /*long*/ firstColumn = OS.gtk_tree_view_get_column (handle, 0); - OS.gtk_tree_view_column_set_visible (firstColumn, true); - return true; -} - -/** - * Shows the item. If the item is already showing in the receiver, - * this method simply returns. Otherwise, the items are scrolled until - * the item is visible. - * - * @param item the item to be shown - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the item is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the 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> - * - * @see Table#showSelection() - */ -public void showItem (TableItem item) { - checkWidget (); - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - if (item.parent != this) return; - showItem (item.handle); -} - -void showItem (int /*long*/ iter) { - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter); - /* - * This code intentionally commented. - * Bug in GTK. According to the documentation, gtk_tree_view_scroll_to_cell - * should scroll the minimum amount to show the cell if use_align is false. - * However, what actually happens is the cell is scrolled to the top. - * The fix is to determine the new location and use gtk_tree_view_scroll_to_point. - * If the widget is a pinhead, calling gtk_tree_view_scroll_to_point - * will have no effect. Therefore, it is still neccessary to - * call gtk_tree_view_scroll_to_cell. - */ -// OS.gtk_tree_view_scroll_to_cell (handle, path, 0, false, 0, 0); - OS.gtk_widget_realize (handle); - GdkRectangle visibleRect = new GdkRectangle (); - OS.gtk_tree_view_get_visible_rect (handle, visibleRect); - GdkRectangle cellRect = new GdkRectangle (); - OS.gtk_tree_view_get_cell_area (handle, path, 0, cellRect); - int[] tx = new int[1], ty = new int[1]; - OS.gtk_tree_view_widget_to_tree_coords(handle, cellRect.x, cellRect.y, tx, ty); - if (ty[0] < visibleRect.y ) { - OS.gtk_tree_view_scroll_to_cell (handle, path, 0, true, 0f, 0f); - OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0]); - } else { - int height = Math.min (visibleRect.height, cellRect.height); - if (ty[0] + height > visibleRect.y + visibleRect.height) { - OS.gtk_tree_view_scroll_to_cell (handle, path, 0, true, 1f, 0f); - ty[0] += cellRect.height - visibleRect.height; - OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0]); - } - } - OS.gtk_tree_path_free (path); -} - -/** - * 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> - * - * @see Table#showItem(TableItem) - */ -public void showSelection () { - checkWidget(); - TableItem [] selection = getSelection (); - if (selection.length == 0) return; - TableItem item = selection [0]; - showItem (item.handle); -} - -int /*long*/ treeSelectionProc (int /*long*/ model, int /*long*/ path, int /*long*/ iter, int[] selection, int length) { - if (selection != null) { - int /*long*/ indices = OS.gtk_tree_path_get_indices (path); - if (indices != 0) { - int [] index = new int [1]; - OS.memmove (index, indices, 4); - selection [(int)/*64*/length] = index [0]; - } - } - return 0; -} - -void updateScrollBarValue (ScrollBar bar) { - super.updateScrollBarValue (bar); - /* - * Bug in GTK. Scrolling changes the XWindow position - * and makes the child widgets appear to scroll even - * though when queried their position is unchanged. - * The fix is to queue a resize event for each child to - * force the position to be corrected. - */ - int /*long*/ parentHandle = parentingHandle (); - int /*long*/ list = OS.gtk_container_get_children (parentHandle); - if (list == 0) return; - int /*long*/ temp = list; - while (temp != 0) { - int /*long*/ widget = OS.g_list_data (temp); - if (widget != 0) OS.gtk_widget_queue_resize (widget); - temp = OS.g_list_next (temp); - } - OS.g_list_free (list); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java deleted file mode 100644 index 4a62dfef8c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java +++ /dev/null @@ -1,702 +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.gtk.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class represent a column in a table widget. - * <p><dl> - * <dt><b>Styles:</b></dt> - * <dd>LEFT, RIGHT, CENTER</dd> - * <dt><b>Events:</b></dt> - * <dd> Move, Resize, Selection</dd> - * </dl> - * </p><p> - * Note: Only one of the styles LEFT, RIGHT and CENTER 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/#table">Table, TableItem, TableColumn 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 TableColumn extends Item { - int /*long*/ labelHandle, imageHandle, buttonHandle; - Table parent; - int modelIndex, lastButton, lastTime, lastX, lastWidth; - boolean customDraw, useFixedWidth; - String toolTipText; - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Table</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#LEFT - * @see SWT#RIGHT - * @see SWT#CENTER - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TableColumn (Table parent, int style) { - super (parent, checkStyle (style)); - this.parent = parent; - createWidget (parent.getColumnCount ()); -} - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Table</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> - * <p> - * Note that due to a restriction on some platforms, the first column - * is always left aligned. - * </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#LEFT - * @see SWT#RIGHT - * @see SWT#CENTER - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TableColumn (Table parent, int style, int index) { - super (parent, checkStyle (style)); - this.parent = parent; - createWidget (index); -} - -/** - * 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 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 column header is selected. - * <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.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0); -} - -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} - -void createWidget (int index) { - parent.createItem (this, index); - setOrientation (); - hookEvents (); - register (); - text = ""; -} - -void deregister() { - super.deregister (); - display.removeWidget (handle); - if (buttonHandle != 0) display.removeWidget (buttonHandle); - if (labelHandle != 0) display.removeWidget (labelHandle); -} - -void destroyWidget () { - parent.destroyItem (this); - releaseHandle (); -} - -/** - * 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>. - * - * @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.LEFT) != 0) return SWT.LEFT; - if ((style & SWT.CENTER) != 0) return SWT.CENTER; - if ((style & SWT.RIGHT) != 0) return SWT.RIGHT; - return SWT.LEFT; -} - -/** - * Gets the moveable attribute. A column that is - * not moveable cannot be reordered by the user - * by dragging the header but may be reordered - * by the programmer. - * - * @return the moveable attribute - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 Table#getColumnOrder() - * @see Table#setColumnOrder(int[]) - * @see TableColumn#setMoveable(boolean) - * @see SWT#Move - * - * @since 3.1 - */ -public boolean getMoveable() { - checkWidget(); - return OS.gtk_tree_view_column_get_reorderable (handle); -} - -/** - * Returns the receiver's parent, which must be a <code>Table</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 Table getParent () { - checkWidget(); - return parent; -} - -/** - * Gets the resizable attribute. A column that is - * not resizable cannot be dragged by the user but - * may be resized by the programmer. - * - * @return the resizable attribute - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 getResizable () { - checkWidget(); - return OS.gtk_tree_view_column_get_resizable (handle); -} - -/** - * 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> - * - * @since 3.2 - */ -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(); - if (!OS.gtk_tree_view_column_get_visible (handle)) { - return 0; - } - if (useFixedWidth) return OS.gtk_tree_view_column_get_fixed_width (handle); - return OS.gtk_tree_view_column_get_width (handle); -} - -int /*long*/ gtk_clicked (int /*long*/ widget) { - /* - * There is no API to get a double click on a table column. Normally, when - * the mouse is double clicked, this is indicated by GDK_2BUTTON_PRESS - * but the table column sends the click signal on button release. The fix is to - * test for double click by remembering the last click time and mouse button - * and testing for the double click interval. - */ - boolean doubleClick = false; - boolean postEvent = true; - int /*long*/ eventPtr = OS.gtk_get_current_event (); - if (eventPtr != 0) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, eventPtr, GdkEventButton.sizeof); - OS.gdk_event_free (eventPtr); - switch (gdkEvent.type) { - case OS.GDK_BUTTON_RELEASE: { - int clickTime = display.getDoubleClickTime (); - int eventTime = gdkEvent.time, eventButton = gdkEvent.button; - if (lastButton == eventButton && lastTime != 0 && Math.abs (lastTime - eventTime) <= clickTime) { - doubleClick = true; - } - lastTime = eventTime == 0 ? 1: eventTime; - lastButton = eventButton; - break; - } - case OS.GDK_MOTION_NOTIFY: { - /* - * Bug in GTK. Dragging a column in a GtkTreeView causes a clicked - * signal to be emitted even though the mouse button was never released. - * The fix to ignore the signal if the current GDK event is a motion notify. - * The GTK bug was fixed in version 2.6 - */ - if (OS.GTK_VERSION < OS.VERSION (2, 6, 0)) postEvent = false; - break; - } - } - } - if (postEvent) postEvent (doubleClick ? SWT.DefaultSelection : SWT.Selection); - return 0; -} - -int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) { - GdkEvent event = new GdkEvent (); - OS.memmove (event, gdkEvent, GdkEvent.sizeof); - switch (event.type) { - case OS.GDK_BUTTON_PRESS: { - GdkEventButton gdkEventButton = new GdkEventButton (); - OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof); - if (gdkEventButton.button == 3) { - parent.showMenu ((int) gdkEventButton.x_root, (int) gdkEventButton.y_root); - } - break; - } - } - return 0; -} - -int /*long*/ gtk_mnemonic_activate (int /*long*/ widget, int /*long*/ arg1) { - return parent.gtk_mnemonic_activate (widget, arg1); -} - -int /*long*/ gtk_size_allocate (int /*long*/ widget, int /*long*/ allocation) { - useFixedWidth = false; - int x = OS.GTK_WIDGET_X (widget); - int width = OS.GTK_WIDGET_WIDTH (widget); - if (x != lastX) { - lastX = x; - sendEvent (SWT.Move); - } - if (width != lastWidth) { - lastWidth = width; - sendEvent (SWT.Resize); - } - return 0; -} - -void hookEvents () { - super.hookEvents (); - OS.g_signal_connect_closure (handle, OS.clicked, display.closures [CLICKED], false); - if (buttonHandle != 0) { - OS.g_signal_connect_closure_by_id (buttonHandle, display.signalIds [SIZE_ALLOCATE], 0, display.closures [SIZE_ALLOCATE], false); - OS.g_signal_connect_closure_by_id (buttonHandle, display.signalIds [EVENT_AFTER], 0, display.closures [EVENT_AFTER], false); - } - if (labelHandle != 0) OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false); -} - -/** - * 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> - * - */ -public void pack () { - checkWidget(); - int width = 0; - if (buttonHandle != 0) { - GtkRequisition requisition = new GtkRequisition (); - OS.gtk_widget_size_request (buttonHandle, requisition); - width = requisition.width; - } - if ((parent.style & SWT.VIRTUAL) != 0) { - for (int i=0; i<parent.items.length; i++) { - TableItem item = parent.items [i]; - if (item != null && item.cached) { - width = Math.max (width, parent.calculateWidth (handle, item.handle)); - } - } - } else { - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (OS.gtk_tree_model_get_iter_first (parent.modelHandle, iter)) { - do { - width = Math.max (width, parent.calculateWidth (handle, iter)); - } while (OS.gtk_tree_model_iter_next(parent.modelHandle, iter)); - } - OS.g_free (iter); - } - setWidth(width); -} - -void register () { - super.register (); - display.addWidget (handle, this); - if (buttonHandle != 0) display.addWidget (buttonHandle, this); - if (labelHandle != 0) display.addWidget (labelHandle, this); -} - -void releaseHandle () { - super.releaseHandle (); - handle = buttonHandle = labelHandle = imageHandle = 0; - modelIndex = -1; - parent = null; -} - -void releaseParent () { - super.releaseParent (); - if (parent.sortColumn == this) { - parent.sortColumn = 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 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); -} - -/** - * 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>. - * <p> - * Note that due to a restriction on some platforms, the first column - * is always left aligned. - * </p> - * @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 ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return; - int index = parent.indexOf (this); - if (index == -1 || index == 0) return; - style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER); - style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER); - parent.createRenderers (handle, modelIndex, index == 0, style); -} - -void setFontDescription (int /*long*/ font) { - OS.gtk_widget_modify_font (labelHandle, font); - OS.gtk_widget_modify_font (imageHandle, font); -} - -public void setImage (Image image) { - checkWidget (); - super.setImage (image); - if (image != null) { - ImageList headerImageList = parent.headerImageList; - if (headerImageList == null) { - headerImageList = parent.headerImageList = new ImageList (); - } - int imageIndex = headerImageList.indexOf (image); - if (imageIndex == -1) imageIndex = headerImageList.add (image); - int /*long*/ pixbuf = headerImageList.getPixbuf (imageIndex); - OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); - OS.gtk_widget_show (imageHandle); - } else { - OS.gtk_image_set_from_pixbuf (imageHandle, 0); - OS.gtk_widget_hide (imageHandle); - } -} - -/** - * Sets the resizable attribute. A column that is - * resizable can be resized by the user dragging the - * edge of the header. A column that is not resizable - * cannot be dragged by the user but may be resized - * by the programmer. - * - * @param resizable the resize attribute - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 setResizable (boolean resizable) { - checkWidget(); - OS.gtk_tree_view_column_set_resizable (handle, resizable); -} - -/** - * Sets the moveable attribute. A column that is - * moveable can be reordered by the user by dragging - * the header. A column that is not moveable cannot be - * dragged by the user but may be reordered - * by the programmer. - * - * @param moveable the moveable attribute - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 Table#setColumnOrder(int[]) - * @see Table#getColumnOrder() - * @see TableColumn#getMoveable() - * @see SWT#Move - * - * @since 3.1 - */ -public void setMoveable (boolean moveable) { - checkWidget(); - OS.gtk_tree_view_column_set_reorderable (handle, moveable); -} - -void setOrientation() { - if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) { - if (buttonHandle != 0) { - OS.gtk_widget_set_direction (buttonHandle, OS.GTK_TEXT_DIR_RTL); - OS.gtk_container_forall (buttonHandle, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL); - } - } -} - -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - super.setText (string); - char [] chars = fixMnemonic (string); - byte [] buffer = Converter.wcsToMbcs (null, chars, true); - OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer); - if (string.length () != 0) { - OS.gtk_widget_show (labelHandle); - } else { - OS.gtk_widget_hide (labelHandle); - } -} - -/** - * 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> - * - * @since 3.2 - */ -public void setToolTipText (String string) { - checkWidget(); - Shell shell = parent._getShell (); - setToolTipText (shell, string); - toolTipText = string; -} - -void setToolTipText (Shell shell, String newString) { - shell.setToolTipText (buttonHandle, newString); -} - -/** - * Sets the width of the receiver. - * - * @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 (width < 0) return; - if (width == lastWidth) return; - if (width > 0) { - useFixedWidth = true; - OS.gtk_tree_view_column_set_fixed_width (handle, width); - } - /* - * Bug in GTK. For some reason, calling gtk_tree_view_column_set_visible() - * when the parent is not realized fails to show the column. The fix is to - * ensure that the table has been realized. - */ - if (width != 0) OS.gtk_widget_realize (parent.handle); - OS.gtk_tree_view_column_set_visible (handle, width != 0); - lastWidth = width; - sendEvent (SWT.Resize); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java deleted file mode 100644 index f34843751d..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java +++ /dev/null @@ -1,1324 +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.gtk.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class represent a selectable user interface object - * that represents an item in a table. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#table">Table, TableItem, TableColumn 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 TableItem extends Item { - Table parent; - Font font; - Font[] cellFont; - boolean cached, grayed; - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Table</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 - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TableItem (Table parent, int style, int index) { - this (parent, style, index, true); -} - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Table</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 - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TableItem (Table parent, int style) { - this (parent, style, checkNull (parent).getItemCount (), true); -} - - -TableItem (Table parent, int style, int index, boolean create) { - super (parent, style); - this.parent = parent; - if (create) { - parent.createItem (this, index); - } else { - handle = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - OS.gtk_tree_model_iter_nth_child (parent.modelHandle, handle, 0, index); - } -} - -static Table checkNull (Table control) { - if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); - return control; -} - -Color _getBackground () { - int /*long*/ [] ptr = new int /*long*/ [1]; - OS.gtk_tree_model_get (parent.modelHandle, handle, Table.BACKGROUND_COLUMN, ptr, -1); - if (ptr [0] == 0) return parent.getBackground (); - GdkColor gdkColor = new GdkColor (); - OS.memmove (gdkColor, ptr [0], GdkColor.sizeof); - return Color.gtk_new (display, gdkColor); -} - -Color _getBackground (int index) { - int count = Math.max (1, parent.columnCount); - if (0 > index || index > count - 1) return _getBackground (); - int /*long*/ [] ptr = new int /*long*/ [1]; - int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex; - OS.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Table.CELL_BACKGROUND, ptr, -1); - if (ptr [0] == 0) return _getBackground (); - GdkColor gdkColor = new GdkColor (); - OS.memmove (gdkColor, ptr [0], GdkColor.sizeof); - return Color.gtk_new (display, gdkColor); -} - -boolean _getChecked () { - int /*long*/ [] ptr = new int /*long*/ [1]; - OS.gtk_tree_model_get (parent.modelHandle, handle, Table.CHECKED_COLUMN, ptr, -1); - return ptr [0] != 0; -} - -Color _getForeground () { - int /*long*/ [] ptr = new int /*long*/ [1]; - OS.gtk_tree_model_get (parent.modelHandle, handle, Table.FOREGROUND_COLUMN, ptr, -1); - if (ptr [0] == 0) return parent.getForeground (); - GdkColor gdkColor = new GdkColor (); - OS.memmove (gdkColor, ptr [0], GdkColor.sizeof); - return Color.gtk_new (display, gdkColor); -} - -Color _getForeground (int index) { - int count = Math.max (1, parent.columnCount); - if (0 > index || index > count - 1) return _getForeground (); - int /*long*/ [] ptr = new int /*long*/ [1]; - int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex; - OS.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Table.CELL_FOREGROUND, ptr, -1); - if (ptr [0] == 0) return _getForeground (); - GdkColor gdkColor = new GdkColor (); - OS.memmove (gdkColor, ptr [0], GdkColor.sizeof); - return Color.gtk_new (display, gdkColor); -} - -Image _getImage (int index) { - int count = Math.max (1, parent.getColumnCount ()); - if (0 > index || index > count - 1) return null; - int /*long*/ [] ptr = new int /*long*/ [1]; - int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex; - OS.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Table.CELL_PIXBUF, ptr, -1); - if (ptr [0] == 0) return null; - ImageList imageList = parent.imageList; - int imageIndex = imageList.indexOf (ptr [0]); - if (imageIndex == -1) return null; - return imageList.get (imageIndex); -} - -String _getText (int index) { - int count = Math.max (1, parent.getColumnCount ()); - if (0 > index || index > count - 1) return ""; - int /*long*/ [] ptr = new int /*long*/ [1]; - int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex; - OS.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Table.CELL_TEXT, ptr, -1); - if (ptr [0] == 0) return ""; - int length = OS.strlen (ptr [0]); - byte[] buffer = new byte [length]; - OS.memmove (buffer, ptr [0], length); - OS.g_free (ptr [0]); - return new String (Converter.mbcsToWcs (null, buffer)); -} - -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} - -void clear () { - if (parent.currentItem == this) return; - if (cached || (parent.style & SWT.VIRTUAL) == 0) { - int columnCount = OS.gtk_tree_model_get_n_columns (parent.modelHandle); - for (int i=0; i<columnCount; i++) { - OS.gtk_list_store_set (parent.modelHandle, handle, i, 0, -1); - } - /* - * Bug in GTK. When using fixed-height-mode, - * row changes do not cause the row to be repainted. The fix is to - * invalidate the row when it is cleared. - */ - if ((parent.style & SWT.VIRTUAL) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) { - redraw (); - } - } - } - cached = false; - font = null; - cellFont = null; -} - -void destroyWidget () { - parent.destroyItem (this); - releaseHandle (); -} - -/** - * Returns the receiver's background color. - * - * @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> - * - * @since 2.0 - */ -public Color getBackground () { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return _getBackground (); -} - -/** - * 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> - * - * @since 3.2 - */ -public Rectangle getBounds () { - // TODO fully test on early and later versions of GTK - // shifted a bit too far right on later versions of GTK - however, old Tree also had this problem - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - int /*long*/ parentHandle = parent.handle; - int /*long*/ column = OS.gtk_tree_view_get_column (parentHandle, 0); - if (column == 0) return new Rectangle (0, 0, 0, 0); - int /*long*/ textRenderer = parent.getTextRenderer (column); - int /*long*/ pixbufRenderer = parent.getPixbufRenderer (column); - if (textRenderer == 0 || pixbufRenderer == 0) return new Rectangle (0, 0, 0, 0); - - int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); - OS.gtk_widget_realize (parentHandle); - - boolean isExpander = OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle) > 0; - boolean isExpanded = OS.gtk_tree_view_row_expanded (parentHandle, path); - OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, isExpander, isExpanded); - - GdkRectangle rect = new GdkRectangle (); - OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect); - OS.gtk_tree_path_free (path); - if ((parent.getStyle () & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth () - rect.width - rect.x; - int right = rect.x + rect.width; - - int [] x = new int [1], w = new int [1]; - parent.ignoreSize = true; - OS.gtk_cell_renderer_get_size (textRenderer, parentHandle, null, null, null, w, null); - parent.ignoreSize = false; - rect.width = w [0]; - int [] buffer = new int [1]; - if (OS.gtk_tree_view_get_expander_column (parentHandle) == column) { - OS.gtk_widget_style_get (parentHandle, OS.expander_size, buffer, 0); - rect.x += buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING; - } - OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0); - int horizontalSeparator = buffer[0]; - rect.x += horizontalSeparator; - - if (OS.GTK_VERSION >= OS.VERSION (2, 1, 3)) { - OS.gtk_tree_view_column_cell_get_position (column, textRenderer, x, null); - rect.x += x [0]; - } else { - if ((parent.style & SWT.CHECK) != 0) { - OS.gtk_cell_renderer_get_size (parent.checkRenderer, parentHandle, null, null, null, w, null); - rect.x += w [0] + horizontalSeparator; - } - OS.gtk_cell_renderer_get_size (pixbufRenderer, parentHandle, null, null, null, w, null); - rect.x += w [0] + horizontalSeparator; - } - if (parent.columnCount > 0) { - if (rect.x + rect.width > right) { - rect.width = Math.max (0, right - rect.x); - } - } - int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0; - return new Rectangle (rect.x, rect.y, width, rect.height + 1); -} - -/** - * Returns the background color at the given column index in the receiver. - * - * @param index the column index - * @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> - * - * @since 3.0 - */ -public Color getBackground (int index) { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return _getBackground (index); -} - -/** - * Returns a rectangle describing the receiver's size and location - * relative to its parent at a column in the table. - * - * @param index the index that specifies the column - * @return the receiver's bounding column 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 (int index) { - checkWidget(); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - int /*long*/ parentHandle = parent.handle; - int /*long*/ column = 0; - if (index >= 0 && index < parent.columnCount) { - column = parent.columns [index].handle; - } else { - column = OS.gtk_tree_view_get_column (parentHandle, index); - } - if (column == 0) return new Rectangle (0, 0, 0, 0); - int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); - OS.gtk_widget_realize (parentHandle); - GdkRectangle rect = new GdkRectangle (); - OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect); - OS.gtk_tree_path_free (path); - if ((parent.getStyle () & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth () - rect.width - rect.x; - - if (index == 0 && (parent.style & SWT.CHECK) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 1, 3)) { - int [] x = new int [1], w = new int [1]; - OS.gtk_tree_view_column_cell_get_position (column, parent.checkRenderer, x, w); - rect.x += x [0] + w [0]; - rect.width -= x [0] + w [0]; - } else { - int [] w = new int [1]; - OS.gtk_cell_renderer_get_size (parent.checkRenderer, parentHandle, null, null, null, w, null); - int [] buffer = new int [1]; - OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0); - rect.x += w [0] + buffer [0]; - rect.width -= w [0] + buffer [0]; - } - } - int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0; - return new Rectangle (rect.x, rect.y, width, rect.height + 1); -} - -/** - * Returns <code>true</code> if the receiver is checked, - * and false otherwise. When the parent does not have - * the <code>CHECK</code> style, return false. - * - * @return the checked 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> - */ -public boolean getChecked () { - checkWidget(); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - if ((parent.style & SWT.CHECK) == 0) return false; - return _getChecked (); -} - -/** - * Returns the font that the receiver will use to paint textual information for this item. - * - * @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> - * - * @since 3.0 - */ -public Font getFont () { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return font != null ? font : parent.getFont (); -} - -/** - * Returns the font that the receiver will use to paint textual information - * for the specified cell in this item. - * - * @param index the column index - * @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> - * - * @since 3.0 - */ -public Font getFont (int index) { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - int count = Math.max (1, parent.columnCount); - if (0 > index || index > count - 1) return getFont (); - if (cellFont == null || cellFont [index] == null) return getFont (); - return cellFont [index]; -} - -/** - * 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> - * - * @since 2.0 - */ -public Color getForeground () { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return _getForeground (); -} - -/** - * - * Returns the foreground color at the given column index in the receiver. - * - * @param index the column index - * @return the 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> - * - * @since 3.0 - */ -public Color getForeground (int index) { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return _getForeground (index); -} - -/** - * Returns <code>true</code> if the receiver is grayed, - * and false otherwise. When the parent 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> - */ -public boolean getGrayed () { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - if ((parent.style & SWT.CHECK) == 0) return false; - return grayed; -} - -public Image getImage () { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return getImage (0); -} - -/** - * Returns the image stored at the given column index in the receiver, - * or null if the image has not been set or if the column does not exist. - * - * @param index the column index - * @return the image stored at the given column index 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 Image getImage (int index) { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return _getImage (index); -} - -/** - * Returns a rectangle describing the size and location - * relative to its parent of an image at a column in the - * table. An empty rectangle is returned if index exceeds - * the index of the table's last column. - * - * @param index the index that specifies the column - * @return the receiver's bounding image 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 getImageBounds (int index) { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - int /*long*/ parentHandle = parent.handle; - int /*long*/ column = 0; - if (index >= 0 && index < parent.columnCount) { - column = parent.columns [index].handle; - } else { - column = OS.gtk_tree_view_get_column (parentHandle, index); - } - if (column == 0) return new Rectangle (0, 0, 0, 0); - int /*long*/ pixbufRenderer = parent.getPixbufRenderer (column); - if (pixbufRenderer == 0) return new Rectangle (0, 0, 0, 0); - GdkRectangle rect = new GdkRectangle (); - int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); - OS.gtk_widget_realize (parentHandle); - OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect); - OS.gtk_tree_path_free (path); - if ((parent.getStyle () & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth () - rect.width - rect.x; - /* - * The OS call gtk_cell_renderer_get_size() provides the width of image to be drawn - * by the cell renderer. If there is no image in the cell, the width is zero. If the table contains - * images of varying widths, gtk_cell_renderer_get_size() will return the width of the image, - * not the width of the area in which the image is drawn. - * New API was added in GTK 2.1.3 for determining the full width of the renderer area. - * For earlier versions of GTK, the result is only correct if all rows have images of the same - * width. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 1, 3)) { - int [] x = new int [1], w = new int[1]; - OS.gtk_tree_view_column_cell_get_position (column, pixbufRenderer, x, w); - rect.x += x [0]; - rect.width = w [0]; - } else { - int [] w = new int [1]; - OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, false, false); - OS.gtk_cell_renderer_get_size (pixbufRenderer, parentHandle, null, null, null, w, null); - rect.width = w [0]; - } - int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width : 0; - return new Rectangle (rect.x, rect.y, width, rect.height + 1); -} - -/** - * Gets the image indent. - * - * @return the indent - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 getImageIndent () { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - /* Image indent is not supported on GTK */ - return 0; -} - -String getNameText () { - if ((parent.style & SWT.VIRTUAL) != 0) { - if (!cached) return "*virtual*"; //$NON-NLS-1$ - } - return super.getNameText (); -} - -/** - * Returns the receiver's parent, which must be a <code>Table</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 Table getParent () { - checkWidget (); - return parent; -} - -public String getText () { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return getText (0); -} - -/** - * Returns the text stored at the given column index in the receiver, - * or empty string if the text has not been set. - * - * @param index the column index - * @return the text stored at the given column index 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 String getText (int index) { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return _getText (index); -} - -/** - * Returns a rectangle describing the size and location - * relative to its parent of the text at a column in the - * table. An empty rectangle is returned if index exceeds - * the index of the table's last column. - * - * @param index the index that specifies the column - * @return the receiver's bounding text 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> - * - * @since 3.3 - */ -public Rectangle getTextBounds (int index) { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - int count = Math.max (1, parent.getColumnCount ()); - if (0 > index || index > count - 1) return new Rectangle (0, 0, 0, 0); - // TODO fully test on early and later versions of GTK - // shifted a bit too far right on later versions of GTK - however, old Tree also had this problem - int /*long*/ parentHandle = parent.handle; - int /*long*/ column = 0; - if (index >= 0 && index < parent.columnCount) { - column = parent.columns [index].handle; - } else { - column = OS.gtk_tree_view_get_column (parentHandle, index); - } - if (column == 0) return new Rectangle (0, 0, 0, 0); - int /*long*/ textRenderer = parent.getTextRenderer (column); - int /*long*/ pixbufRenderer = parent.getPixbufRenderer (column); - if (textRenderer == 0 || pixbufRenderer == 0) return new Rectangle (0, 0, 0, 0); - - int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); - OS.gtk_widget_realize (parentHandle); - - boolean isExpander = OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle) > 0; - boolean isExpanded = OS.gtk_tree_view_row_expanded (parentHandle, path); - OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, isExpander, isExpanded); - - GdkRectangle rect = new GdkRectangle (); - OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect); - OS.gtk_tree_path_free (path); - if ((parent.getStyle () & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth () - rect.width - rect.x; - int right = rect.x + rect.width; - - int [] x = new int [1], w = new int [1]; - parent.ignoreSize = true; - OS.gtk_cell_renderer_get_size (textRenderer, parentHandle, null, null, null, w, null); - parent.ignoreSize = false; - int [] buffer = new int [1]; - if (OS.gtk_tree_view_get_expander_column (parentHandle) == column) { - OS.gtk_widget_style_get (parentHandle, OS.expander_size, buffer, 0); - rect.x += buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING; - } - OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0); - int horizontalSeparator = buffer[0]; - rect.x += horizontalSeparator; - - if (OS.GTK_VERSION >= OS.VERSION (2, 1, 3)) { - OS.gtk_tree_view_column_cell_get_position (column, textRenderer, x, null); - rect.x += x [0]; - } else { - if ((parent.style & SWT.CHECK) != 0) { - OS.gtk_cell_renderer_get_size (parent.checkRenderer, parentHandle, null, null, null, w, null); - rect.x += w [0] + horizontalSeparator; - } - OS.gtk_cell_renderer_get_size (pixbufRenderer, parentHandle, null, null, null, w, null); - rect.x += w [0] + horizontalSeparator; - } - if (parent.columnCount > 0) { - if (rect.x + rect.width > right) { - rect.width = Math.max (0, right - rect.x); - } - } - int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0; - return new Rectangle (rect.x, rect.y, width, rect.height + 1); -} - -void redraw () { - if ((OS.GTK_WIDGET_FLAGS (parent.handle) & OS.GTK_REALIZED) != 0) { - int /*long*/ parentHandle = parent.handle; - int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); - GdkRectangle rect = new GdkRectangle (); - OS.gtk_tree_view_get_cell_area (parentHandle, path, 0, rect); - OS.gtk_tree_path_free (path); - int /*long*/ window = OS.gtk_tree_view_get_bin_window (parentHandle); - rect.x = 0; - int [] w = new int [1], h = new int [1]; - OS.gdk_drawable_get_size (window, w, h); - rect.width = w [0]; - OS.gdk_window_invalidate_rect (window, rect, false); - } -} - -void releaseHandle () { - if (handle != 0) OS.g_free (handle); - handle = 0; - super.releaseHandle (); - parent = null; -} - -void releaseWidget () { - super.releaseWidget (); - font = null; - cellFont = null; -} - -/** - * Sets the receiver's background color to the color specified - * by the argument, or to the default system color for the item - * if the argument is null. - * - * @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> - * - * @since 2.0 - */ -public void setBackground (Color color) { - checkWidget (); - if (color != null && color.isDisposed ()) { - SWT.error (SWT.ERROR_INVALID_ARGUMENT); - } - if (_getBackground ().equals (color)) return; - GdkColor gdkColor = color != null ? color.handle : null; - OS.gtk_list_store_set (parent.modelHandle, handle, Table.BACKGROUND_COLUMN, gdkColor, -1); - /* - * Bug in GTK. When using fixed-height-mode, - * row changes do not cause the row to be repainted. The fix is to - * invalidate the row when it is cleared. - */ - if ((parent.style & SWT.VIRTUAL) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) { - redraw (); - } - } - cached = true; -} - -/** - * Sets the background color at the given column index in the receiver - * to the color specified by the argument, or to the default system color for the item - * if the argument is null. - * - * @param index the column index - * @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> - * - * @since 3.0 - */ -public void setBackground (int index, Color color) { - checkWidget (); - if (color != null && color.isDisposed ()) { - SWT.error (SWT.ERROR_INVALID_ARGUMENT); - } - if (_getBackground (index).equals (color)) return; - int count = Math.max (1, parent.getColumnCount ()); - if (0 > index || index > count - 1) return; - int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex; - GdkColor gdkColor = color != null ? color.handle : null; - OS.gtk_list_store_set (parent.modelHandle, handle, modelIndex + Table.CELL_BACKGROUND, gdkColor, -1); - /* - * Bug in GTK. When using fixed-height-mode, - * row changes do not cause the row to be repainted. The fix is to - * invalidate the row when it is cleared. - */ - if ((parent.style & SWT.VIRTUAL) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) { - redraw (); - } - } - cached = true; - - if (color != null) { - boolean customDraw = (parent.columnCount == 0) ? parent.firstCustomDraw : parent.columns [index].customDraw; - if (!customDraw) { - if ((parent.style & SWT.VIRTUAL) == 0) { - int /*long*/ parentHandle = parent.handle; - int /*long*/ column = 0; - if (parent.columnCount > 0) { - column = parent.columns [index].handle; - } else { - column = OS.gtk_tree_view_get_column (parentHandle, index); - } - if (column == 0) return; - int /*long*/ textRenderer = parent.getTextRenderer (column); - int /*long*/ imageRenderer = parent.getPixbufRenderer (column); - OS.gtk_tree_view_column_set_cell_data_func (column, textRenderer, display.cellDataProc, parentHandle, 0); - OS.gtk_tree_view_column_set_cell_data_func (column, imageRenderer, display.cellDataProc, parentHandle, 0); - } - if (parent.columnCount == 0) { - parent.firstCustomDraw = true; - } else { - parent.columns [index].customDraw = true; - } - } - } -} - -/** - * Sets the checked state of the checkbox for this item. This state change - * only applies if the Table was created with the SWT.CHECK style. - * - * @param checked the new checked 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> - */ -public void setChecked (boolean checked) { - checkWidget(); - if ((parent.style & SWT.CHECK) == 0) return; - if (_getChecked () == checked) return; - OS.gtk_list_store_set (parent.modelHandle, handle, Table.CHECKED_COLUMN, checked, -1); - /* - * GTK+'s "inconsistent" state does not match SWT's concept of grayed. To - * show checked+grayed differently from unchecked+grayed, we must toggle the - * grayed state on check and uncheck. - */ - OS.gtk_list_store_set (parent.modelHandle, handle, Table.GRAYED_COLUMN, !checked ? false : grayed, -1); - cached = true; -} - -/** - * Sets the font that the receiver will use to paint textual information - * for this item 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> - * - * @since 3.0 - */ -public void setFont (Font font){ - checkWidget (); - 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; - int /*long*/ fontHandle = font != null ? font.handle : 0; - OS.gtk_list_store_set (parent.modelHandle, handle, Table.FONT_COLUMN, fontHandle, -1); - /* - * Bug in GTK. When using fixed-height-mode, - * row changes do not cause the row to be repainted. The fix is to - * invalidate the row when it is cleared. - */ - if ((parent.style & SWT.VIRTUAL) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) { - redraw (); - } - } - cached = true; -} - -/** - * Sets the font that the receiver will use to paint textual information - * for the specified cell in this item to the font specified by the - * argument, or to the default font for that kind of control if the - * argument is null. - * - * @param index the column index - * @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> - * - * @since 3.0 - */ -public void setFont (int index, Font font) { - checkWidget (); - if (font != null && font.isDisposed ()) { - SWT.error (SWT.ERROR_INVALID_ARGUMENT); - } - int count = Math.max (1, parent.getColumnCount ()); - if (0 > index || index > count - 1) return; - if (cellFont == null) { - if (font == null) return; - cellFont = new Font [count]; - } - Font oldFont = cellFont [index]; - if (oldFont == font) return; - cellFont [index] = font; - if (oldFont != null && oldFont.equals (font)) return; - - int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex; - int /*long*/ fontHandle = font != null ? font.handle : 0; - OS.gtk_list_store_set (parent.modelHandle, handle, modelIndex + Table.CELL_FONT, fontHandle, -1); - /* - * Bug in GTK. When using fixed-height-mode, - * row changes do not cause the row to be repainted. The fix is to - * invalidate the row when it is cleared. - */ - if ((parent.style & SWT.VIRTUAL) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) { - redraw (); - } - } - cached = true; - - if (font != null) { - boolean customDraw = (parent.columnCount == 0) ? parent.firstCustomDraw : parent.columns [index].customDraw; - if (!customDraw) { - if ((parent.style & SWT.VIRTUAL) == 0) { - int /*long*/ parentHandle = parent.handle; - int /*long*/ column = 0; - if (parent.columnCount > 0) { - column = parent.columns [index].handle; - } else { - column = OS.gtk_tree_view_get_column (parentHandle, index); - } - if (column == 0) return; - int /*long*/ textRenderer = parent.getTextRenderer (column); - int /*long*/ imageRenderer = parent.getPixbufRenderer (column); - OS.gtk_tree_view_column_set_cell_data_func (column, textRenderer, display.cellDataProc, parentHandle, 0); - OS.gtk_tree_view_column_set_cell_data_func (column, imageRenderer, display.cellDataProc, parentHandle, 0); - } - if (parent.columnCount == 0) { - parent.firstCustomDraw = true; - } else { - parent.columns [index].customDraw = true; - } - } - } -} - -/** - * Sets the receiver's foreground color to the color specified - * by the argument, or to the default system color for the item - * if the argument is null. - * - * @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> - * - * @since 2.0 - */ -public void setForeground (Color color){ - checkWidget (); - if (color != null && color.isDisposed ()) { - SWT.error (SWT.ERROR_INVALID_ARGUMENT); - } - if (_getForeground ().equals (color)) return; - GdkColor gdkColor = color != null ? color.handle : null; - OS.gtk_list_store_set (parent.modelHandle, handle, Table.FOREGROUND_COLUMN, gdkColor, -1); - /* - * Bug in GTK. When using fixed-height-mode, - * row changes do not cause the row to be repainted. The fix is to - * invalidate the row when it is cleared. - */ - if ((parent.style & SWT.VIRTUAL) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) { - redraw (); - } - } - cached = true; -} - -/** - * Sets the foreground color at the given column index in the receiver - * to the color specified by the argument, or to the default system color for the item - * if the argument is null. - * - * @param index the column index - * @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> - * - * @since 3.0 - */ -public void setForeground (int index, Color color){ - checkWidget (); - if (color != null && color.isDisposed ()) { - SWT.error (SWT.ERROR_INVALID_ARGUMENT); - } - if (_getForeground (index).equals (color)) return; - int count = Math.max (1, parent.getColumnCount ()); - if (0 > index || index > count - 1) return; - int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex; - GdkColor gdkColor = color != null ? color.handle : null; - OS.gtk_list_store_set (parent.modelHandle, handle, modelIndex + Table.CELL_FOREGROUND, gdkColor, -1); - /* - * Bug in GTK. When using fixed-height-mode, - * row changes do not cause the row to be repainted. The fix is to - * invalidate the row when it is cleared. - */ - if ((parent.style & SWT.VIRTUAL) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) { - redraw (); - } - } - cached = true; - - if (color != null) { - boolean customDraw = (parent.columnCount == 0) ? parent.firstCustomDraw : parent.columns [index].customDraw; - if (!customDraw) { - if ((parent.style & SWT.VIRTUAL) == 0) { - int /*long*/ parentHandle = parent.handle; - int /*long*/ column = 0; - if (parent.columnCount > 0) { - column = parent.columns [index].handle; - } else { - column = OS.gtk_tree_view_get_column (parentHandle, index); - } - if (column == 0) return; - int /*long*/ textRenderer = parent.getTextRenderer (column); - int /*long*/ imageRenderer = parent.getPixbufRenderer (column); - OS.gtk_tree_view_column_set_cell_data_func (column, textRenderer, display.cellDataProc, parentHandle, 0); - OS.gtk_tree_view_column_set_cell_data_func (column, imageRenderer, display.cellDataProc, parentHandle, 0); - } - if (parent.columnCount == 0) { - parent.firstCustomDraw = true; - } else { - parent.columns [index].customDraw = true; - } - } - } -} - -/** - * Sets the grayed state of the checkbox for this item. This state change - * only applies if the Table was created with the SWT.CHECK style. - * - * @param grayed the new 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> - */ -public void setGrayed (boolean grayed) { - checkWidget(); - if ((parent.style & SWT.CHECK) == 0) return; - if (this.grayed == grayed) return; - this.grayed = grayed; - /* - * GTK+'s "inconsistent" state does not match SWT's concept of grayed. - * Render checked+grayed as "inconsistent", unchecked+grayed as blank. - */ - int /*long*/ [] ptr = new int /*long*/ [1]; - OS.gtk_tree_model_get (parent.modelHandle, handle, Table.CHECKED_COLUMN, ptr, -1); - OS.gtk_list_store_set (parent.modelHandle, handle, Table.GRAYED_COLUMN, ptr [0] == 0 ? false : grayed, -1); - cached = true; -} - -/** - * Sets the receiver's image at a column. - * - * @param index the column index - * @param image the new image - * - * @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 (int index, Image image) { - checkWidget (); - if (image != null && image.isDisposed ()) { - error(SWT.ERROR_INVALID_ARGUMENT); - } - if (image != null && image.type == SWT.ICON) { - if (image.equals (_getImage (index))) return; - } - int count = Math.max (1, parent.getColumnCount ()); - if (0 > index || index > count - 1) return; - int /*long*/ pixbuf = 0; - if (image != null) { - ImageList imageList = parent.imageList; - if (imageList == null) imageList = parent.imageList = new ImageList (); - int imageIndex = imageList.indexOf (image); - if (imageIndex == -1) imageIndex = imageList.add (image); - pixbuf = imageList.getPixbuf (imageIndex); - } - int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex; - OS.gtk_list_store_set (parent.modelHandle, handle, modelIndex + Table.CELL_PIXBUF, pixbuf, -1); - /* - * Bug in GTK. When using fixed-height-mode, - * row changes do not cause the row to be repainted. The fix is to - * invalidate the row when it is cleared. - */ - if ((parent.style & SWT.VIRTUAL) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) { - redraw (); - } - } - /* - * Bug in GTK. When in fixed height mode, GTK does not recalculate the cell renderer width - * when the image is changed in the model. The fix is to force it to recalculate the width if - * more space is required. - */ - if ((parent.style & SWT.VIRTUAL) != 0 && parent.currentItem == null) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2)) { - if (image != null) { - int /*long*/parentHandle = parent.handle; - int /*long*/ column = OS.gtk_tree_view_get_column (parentHandle, index); - int [] w = new int [1]; - int /*long*/ pixbufRenderer = parent.getPixbufRenderer(column); - OS.gtk_tree_view_column_cell_get_position (column, pixbufRenderer, null, w); - if (w[0] < image.getBounds().width) { - /* - * There is no direct way to clear the cell renderer width so we - * are relying on the fact that it is done as part of modifying - * the style. - */ - int /*long*/ style = OS.gtk_widget_get_modifier_style (parentHandle); - parent.modifyStyle (parentHandle, style); - } - } - } - } - cached = true; -} - -public void setImage (Image image) { - checkWidget (); - setImage (0, image); -} - -/** - * Sets the image for multiple columns in the table. - * - * @param images the array of new images - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li> - * <li>ERROR_INVALID_ARGUMENT - if one of the images 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 [] images) { - checkWidget (); - if (images == null) error (SWT.ERROR_NULL_ARGUMENT); - for (int i=0; i<images.length; i++) { - setImage (i, images [i]); - } -} - -/** - * Sets the indent of the first column's image, expressed in terms of the image's width. - * - * @param indent the new indent - * - * </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> - * - * @deprecated this functionality is not supported on most platforms - */ -public void setImageIndent (int indent) { - checkWidget (); - if (indent < 0) return; - /* Image indent is not supported on GTK */ - cached = true; -} - -/** - * Sets the receiver's text at a column - * - * @param index the column index - * @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 (int index, String string) { - checkWidget (); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if (_getText (index).equals (string)) return; - int count = Math.max (1, parent.getColumnCount ()); - if (0 > index || index > count - 1) return; - byte[] buffer = Converter.wcsToMbcs (null, string, true); - int modelIndex = parent.columnCount == 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex; - OS.gtk_list_store_set (parent.modelHandle, handle, modelIndex + Table.CELL_TEXT, buffer, -1); - /* - * Bug in GTK. When using fixed-height-mode, - * row changes do not cause the row to be repainted. The fix is to - * invalidate the row when it is cleared. - */ - if ((parent.style & SWT.VIRTUAL) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) { - redraw (); - } - } - cached = true; -} - -public void setText (String string) { - checkWidget (); - setText (0, string); -} - -/** - * Sets the text for multiple columns in the table. - * - * @param strings the array of new strings - * - * @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 [] strings) { - checkWidget (); - if (strings == null) error (SWT.ERROR_NULL_ARGUMENT); - for (int i=0; i<strings.length; i++) { - String string = strings [i]; - if (string != null) setText (i, string); - } -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java deleted file mode 100644 index 0973f06da6..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Text.java +++ /dev/null @@ -1,2152 +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.gtk.*; -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 { - int /*long*/ bufferHandle; - int tabs = 8, lastEventTime = 0; - int /*long*/ gdkEventKey = 0; - int fixStart = -1, fixEnd = -1; - boolean doubleClick; - String message = ""; - - static final int ITER_SIZEOF = OS.GtkTextIter_sizeof(); - static final int SPACE_FOR_CURSOR = 1; - - /** - * 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 final static 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 final static String DELIMITER; - /* - * 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"; - } - -/** - * 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)); -} - -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; -} - -void createHandle (int index) { - state |= HANDLE | MENU; - if ((style & SWT.READ_ONLY) != 0) { - if ((style & (SWT.BORDER | SWT.H_SCROLL | SWT.V_SCROLL)) == 0) { - state |= THEME_BACKGROUND; - } - } - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - if ((style & SWT.SINGLE) != 0) { - handle = OS.gtk_entry_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (fixedHandle, handle); - OS.gtk_editable_set_editable (handle, (style & SWT.READ_ONLY) == 0); - OS.gtk_entry_set_has_frame (handle, (style & SWT.BORDER) != 0); - OS.gtk_entry_set_visibility (handle, (style & SWT.PASSWORD) == 0); - float alignment = 0.0f; - if ((style & SWT.CENTER) != 0) alignment = 0.5f; - if ((style & SWT.RIGHT) != 0) alignment = 1.0f; - if (alignment > 0.0f) { - OS.gtk_entry_set_alignment (handle, alignment); - } - } else { - scrolledHandle = OS.gtk_scrolled_window_new (0, 0); - if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES); - handle = OS.gtk_text_view_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - bufferHandle = OS.gtk_text_view_get_buffer (handle); - if (bufferHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (fixedHandle, scrolledHandle); - OS.gtk_container_add (scrolledHandle, handle); - OS.gtk_text_view_set_editable (handle, (style & SWT.READ_ONLY) == 0); - if ((style & SWT.WRAP) != 0) OS.gtk_text_view_set_wrap_mode (handle, OS.GTK_VERSION < OS.VERSION (2, 4, 0) ? OS.GTK_WRAP_WORD : OS.GTK_WRAP_WORD_CHAR); - int hsp = (style & SWT.H_SCROLL) != 0 ? OS.GTK_POLICY_ALWAYS : OS.GTK_POLICY_NEVER; - int vsp = (style & SWT.V_SCROLL) != 0 ? OS.GTK_POLICY_ALWAYS : OS.GTK_POLICY_NEVER; - OS.gtk_scrolled_window_set_policy (scrolledHandle, hsp, vsp); - if ((style & SWT.BORDER) != 0) { - OS.gtk_scrolled_window_set_shadow_type (scrolledHandle, OS.GTK_SHADOW_ETCHED_IN); - } - int just = OS.GTK_JUSTIFY_LEFT; - if ((style & SWT.CENTER) != 0) just = OS.GTK_JUSTIFY_CENTER; - if ((style & SWT.RIGHT) != 0) just = OS.GTK_JUSTIFY_RIGHT; - OS.gtk_text_view_set_justification (handle, just); - } -} - -void createWidget (int index) { - super.createWidget (index); - doubleClick = true; -} - -/** - * 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); - byte [] buffer = Converter.wcsToMbcs (null, string, false); - if ((style & SWT.SINGLE) != 0) { - OS.gtk_editable_insert_text (handle, buffer, buffer.length, new int[]{-1}); - OS.gtk_editable_set_position (handle, -1); - } else { - byte [] position = new byte [ITER_SIZEOF]; - OS.gtk_text_buffer_get_end_iter (bufferHandle, position); - OS.gtk_text_buffer_insert (bufferHandle, position, buffer, buffer.length); - OS.gtk_text_buffer_place_cursor (bufferHandle, position); - int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle); - OS.gtk_text_view_scroll_mark_onscreen (handle, mark); - } -} - -/** - * 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 (); - if ((style & SWT.SINGLE) != 0) { - int position = OS.gtk_editable_get_position (handle); - OS.gtk_editable_select_region (handle, position, position); - } else { - byte [] position = new byte [ITER_SIZEOF]; - int /*long*/ insertMark = OS.gtk_text_buffer_get_insert (bufferHandle); - int /*long*/ selectionMark = OS.gtk_text_buffer_get_selection_bound (bufferHandle); - OS.gtk_text_buffer_get_iter_at_mark (bufferHandle, position, insertMark); - OS.gtk_text_buffer_move_mark (bufferHandle, selectionMark, position); - OS.gtk_text_buffer_move_mark (bufferHandle, insertMark, position); - } -} - -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[] w = new int [1], h = new int [1]; - if ((style & SWT.SINGLE) != 0) { - OS.gtk_widget_realize (handle); - int /*long*/ layout = OS.gtk_entry_get_layout (handle); - OS.pango_layout_get_size (layout, w, h); - } else { - byte [] start = new byte [ITER_SIZEOF], end = new byte [ITER_SIZEOF]; - OS.gtk_text_buffer_get_bounds (bufferHandle, start, end); - int /*long*/ text = OS.gtk_text_buffer_get_text (bufferHandle, start, end, true); - int /*long*/ layout = OS.gtk_widget_create_pango_layout (handle, text); - OS.g_free (text); - OS.pango_layout_set_width (layout, wHint * OS.PANGO_SCALE); - OS.pango_layout_get_size (layout, w, h); - OS.g_object_unref (layout); - } - int width = OS.PANGO_PIXELS (w [0]); - int height = OS.PANGO_PIXELS (h [0]); - if ((style & SWT.SINGLE) != 0 && message.length () > 0) { - byte [] buffer = Converter.wcsToMbcs (null, message, true); - int /*long*/ layout = OS.gtk_widget_create_pango_layout (handle, buffer); - OS.pango_layout_get_size (layout, w, h); - OS.g_object_unref (layout); - width = Math.max (width, OS.PANGO_PIXELS (w [0])); - } - if (width == 0) width = DEFAULT_WIDTH; - if (height == 0) height = DEFAULT_HEIGHT; - width = wHint == SWT.DEFAULT ? width : wHint; - height = hHint == SWT.DEFAULT ? height : hHint; - 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 (); - Rectangle trim = super.computeTrim (x, y, width, height); - int xborder = 0, yborder = 0; - if ((style & SWT.SINGLE) != 0) { - if ((style & SWT.BORDER) != 0) { - int /*long*/ style = OS.gtk_widget_get_style (handle); - xborder += OS.gtk_style_get_xthickness (style); - yborder += OS.gtk_style_get_ythickness (style); - } - GtkBorder innerBorder = Display.getEntryInnerBorder (handle); - trim.x -= innerBorder.left; - trim.y -= innerBorder.top; - trim.width += innerBorder.left + innerBorder.right; - trim.height += innerBorder.top + innerBorder.bottom; - } else { - int borderWidth = OS.gtk_container_get_border_width (handle); - xborder += borderWidth; - yborder += borderWidth; - } - int [] property = new int [1]; - OS.gtk_widget_style_get (handle, OS.interior_focus, property, 0); - if (property [0] == 0) { - OS.gtk_widget_style_get (handle, OS.focus_line_width, property, 0); - xborder += property [0]; - yborder += property [0]; - } - trim.x -= xborder; - trim.y -= yborder; - trim.width += 2 * xborder; - trim.height += 2 * yborder; - trim.width += SPACE_FOR_CURSOR; - return new Rectangle (trim.x, trim.y, trim.width, trim.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 (); - if ((style & SWT.SINGLE) != 0) { - OS.gtk_editable_copy_clipboard (handle); - } else { - int /*long*/ clipboard = OS.gtk_clipboard_get (OS.GDK_NONE); - OS.gtk_text_buffer_copy_clipboard (bufferHandle, clipboard); - } -} - -/** - * 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 (); - if ((style & SWT.SINGLE) != 0) { - OS.gtk_editable_cut_clipboard (handle); - } else { - int /*long*/ clipboard = OS.gtk_clipboard_get (OS.GDK_NONE); - OS.gtk_text_buffer_cut_clipboard (bufferHandle, clipboard, OS.gtk_text_view_get_editable (handle)); - } -} - -void deregister () { - super.deregister (); - if (bufferHandle != 0) display.removeWidget (bufferHandle); - int /*long*/ imContext = imContext (); - if (imContext != 0) display.removeWidget (imContext); -} - -boolean dragDetect (int x, int y, boolean filter, boolean [] consume) { - if (filter) { - int start = 0, end = 0; - if ((style & SWT.SINGLE) != 0) { - int [] s = new int [1], e = new int [1]; - OS.gtk_editable_get_selection_bounds (handle, s, e); - start = s [0]; - end = e [0]; - } else { - byte [] s = new byte [ITER_SIZEOF], e = new byte [ITER_SIZEOF]; - OS.gtk_text_buffer_get_selection_bounds (bufferHandle, s, e); - start = OS.gtk_text_iter_get_offset (s); - end = OS.gtk_text_iter_get_offset (e); - } - if (start != end) { - if (end < start) { - int temp = end; - end = start; - start = temp; - } - int position = -1; - if ((style & SWT.SINGLE) != 0) { - int [] index = new int [1]; - int [] trailing = new int [1]; - int /*long*/ layout = OS.gtk_entry_get_layout (handle); - OS.pango_layout_xy_to_index (layout, x * OS.PANGO_SCALE, y * OS.PANGO_SCALE, index, trailing); - int /*long*/ ptr = OS.pango_layout_get_text (layout); - position = (int)/*64*/OS.g_utf8_pointer_to_offset (ptr, ptr + index[0]) + trailing[0]; - } else { - byte [] p = new byte [ITER_SIZEOF]; - OS.gtk_text_view_get_iter_at_location (handle, p, x, y); - position = OS.gtk_text_iter_get_offset (p); - } - if (start <= position && position < end) { - if (super.dragDetect (x, y, filter, consume)) { - if (consume != null) consume [0] = true; - return true; - } - } - } - return false; - } - return super.dragDetect (x, y, filter, consume); -} - -int /*long*/ eventWindow () { - return paintWindow (); -} - -boolean filterKey (int keyval, int /*long*/ event) { - int time = OS.gdk_event_get_time (event); - if (time != lastEventTime) { - lastEventTime = time; - int /*long*/ imContext = imContext (); - if (imContext != 0) { - return OS.gtk_im_context_filter_keypress (imContext, event); - } - } - gdkEventKey = event; - return false; -} - -void fixIM () { - /* - * The IM filter has to be called one time for each key press event. - * When the IM is open the key events are duplicated. The first event - * is filtered by SWT and the second event is filtered by GTK. In some - * cases the GTK handler does not run (the widget is destroyed, the - * application code consumes the event, etc), for these cases the IM - * filter has to be called by SWT. - */ - if (gdkEventKey != 0 && gdkEventKey != -1) { - int /*long*/ imContext = imContext (); - if (imContext != 0) { - OS.gtk_im_context_filter_keypress (imContext, gdkEventKey); - gdkEventKey = -1; - return; - } - } - gdkEventKey = 0; -} - -GdkColor getBackgroundColor () { - return getBaseColor (); -} - -public int getBorderWidth () { - checkWidget(); - if ((style & SWT.MULTI) != 0) return super.getBorderWidth (); - int /*long*/ style = OS.gtk_widget_get_style (handle); - if ((this.style & SWT.BORDER) != 0) { - return OS.gtk_style_get_xthickness (style); - } - return 0; -} - -/** - * 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 (); - if ((style & SWT.SINGLE) != 0) return 0; - byte [] position = new byte [ITER_SIZEOF]; - int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle); - OS.gtk_text_buffer_get_iter_at_mark (bufferHandle, position, mark); - return OS.gtk_text_iter_get_line (position); -} - -/** - * 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 (); - if ((style & SWT.SINGLE) != 0) { - int index = OS.gtk_editable_get_position (handle); - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) { - index = OS.gtk_entry_text_index_to_layout_index (handle, index); - } - int [] offset_x = new int [1], offset_y = new int [1]; - OS.gtk_entry_get_layout_offsets (handle, offset_x, offset_y); - int /*long*/ layout = OS.gtk_entry_get_layout (handle); - PangoRectangle pos = new PangoRectangle (); - OS.pango_layout_index_to_pos (layout, index, pos); - int x = offset_x [0] + OS.PANGO_PIXELS (pos.x) - getBorderWidth (); - int y = offset_y [0] + OS.PANGO_PIXELS (pos.y); - return new Point (x, y); - } - byte [] position = new byte [ITER_SIZEOF]; - int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle); - OS.gtk_text_buffer_get_iter_at_mark (bufferHandle, position, mark); - GdkRectangle rect = new GdkRectangle (); - OS.gtk_text_view_get_iter_location (handle, position, rect); - int [] x = new int [1]; - int [] y = new int [1]; - OS.gtk_text_view_buffer_to_window_coords (handle, OS.GTK_TEXT_WINDOW_TEXT, rect.x, rect.y, x, y); - return new Point (x [0], y [0]); -} - -/** - * 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 (); - if ((style & SWT.SINGLE) != 0) { - return OS.gtk_editable_get_position (handle); - } - byte [] position = new byte [ITER_SIZEOF]; - int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle); - OS.gtk_text_buffer_get_iter_at_mark (bufferHandle, position, mark); - return OS.gtk_text_iter_get_offset (position); -} - -/** - * 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 (); - if ((style & SWT.SINGLE) != 0) { - int /*long*/ ptr = OS.gtk_entry_get_text (handle); - return (int)/*64*/OS.g_utf8_strlen (ptr, -1); - } - return OS.gtk_text_buffer_get_char_count (bufferHandle); -} - -/** - * 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 (); - return doubleClick; -} - -/** - * 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 (); - if ((style & SWT.SINGLE) != 0) { - if (!OS.gtk_entry_get_visibility (handle)) { - return OS.gtk_entry_get_invisible_char (handle); - } - } - return '\0'; -} - -/** - * 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 (); - if ((style & SWT.SINGLE) != 0) { - return OS.gtk_editable_get_editable (handle); - } - return OS.gtk_text_view_get_editable (handle); -} - -GdkColor getForegroundColor () { - return getTextColor (); -} - -/** - * 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; - return OS.gtk_text_buffer_get_line_count (bufferHandle); -} - -/** - * 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 fontHeight (getFontDescription (), handle); -} - -/** - * 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; -} - -/** - * 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); - int position = -1; - if ((style & SWT.SINGLE) != 0) { - int [] index = new int [1]; - int [] trailing = new int [1]; - int /*long*/ layout = OS.gtk_entry_get_layout (handle); - OS.pango_layout_xy_to_index (layout, point.x * OS.PANGO_SCALE, point.y * OS.PANGO_SCALE, index, trailing); - int /*long*/ ptr = OS.pango_layout_get_text (layout); - position = (int)/*64*/OS.g_utf8_pointer_to_offset (ptr, ptr + index[0]) + trailing[0]; - } else { - byte [] p = new byte [ITER_SIZEOF]; - OS.gtk_text_view_get_iter_at_location (handle, p, point.x, point.y); - position = OS.gtk_text_iter_get_offset (p); - } - return position; -} - -/** - * 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 (); - if ((style & SWT.SINGLE) != 0) { - int [] start = new int [1]; - int [] end = new int [1]; - OS.gtk_editable_get_selection_bounds (handle, start, end); - return new Point (start [0], end [0]); - } - byte [] start = new byte [ITER_SIZEOF]; - byte [] end = new byte [ITER_SIZEOF]; - OS.gtk_text_buffer_get_selection_bounds (bufferHandle, start, end); - return new Point (OS.gtk_text_iter_get_offset (start), OS.gtk_text_iter_get_offset (end)); -} - -/** - * 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 (); - Point selection = getSelection (); - return Math.abs (selection.y - selection.x); -} - -/** - * 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 (); - Point selection = getSelection (); - return getText ().substring(selection.x, selection.y); -} - -/** - * 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 (); - return tabs; -} - -int getTabWidth (int tabs) { - byte[] buffer = Converter.wcsToMbcs(null, " ", true); - int /*long*/ layout = OS.gtk_widget_create_pango_layout (handle, buffer); - int [] width = new int [1]; - int [] height = new int [1]; - OS.pango_layout_get_size (layout, width, height); - OS.g_object_unref (layout); - return width [0] * tabs; -} - -/** - * 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 (); - int /*long*/ address; - if ((style & SWT.SINGLE) != 0) { - address = OS.gtk_entry_get_text (handle); - } else { - byte [] start = new byte [ITER_SIZEOF]; - byte [] end = new byte [ITER_SIZEOF]; - OS.gtk_text_buffer_get_bounds (bufferHandle, start, end); - address = OS.gtk_text_buffer_get_text (bufferHandle, start, end, true); - } - if (address == 0) return ""; - int length = OS.strlen (address); - byte [] buffer = new byte [length]; - OS.memmove (buffer, address, length); - if ((style & SWT.MULTI) != 0) OS.g_free (address); - return new String (Converter.mbcsToWcs (null, 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 ""; - int /*long*/ address; - if ((style & SWT.SINGLE) != 0) { - start = Math.max (0, start); - address = OS.gtk_editable_get_chars (handle, start, end + 1); - } else { - int length = OS.gtk_text_buffer_get_char_count (bufferHandle); - end = Math.min (end, length - 1); - if (start > end) return ""; - start = Math.max (0, start); - byte [] startIter = new byte [ITER_SIZEOF]; - byte [] endIter = new byte [ITER_SIZEOF]; - OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, startIter, start); - OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, endIter, end + 1); - address = OS.gtk_text_buffer_get_text (bufferHandle, startIter, endIter, true); - } - if (address == 0) error (SWT.ERROR_CANNOT_GET_TEXT); - int length = OS.strlen (address); - byte [] buffer = new byte [length]; - OS.memmove (buffer, address, length); - OS.g_free (address); - return new String (Converter.mbcsToWcs (null, buffer)); -} - -/** - * 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 (); - if ((style & SWT.MULTI) != 0) return LIMIT; - int limit = OS.gtk_entry_get_max_length (handle); - return limit == 0 ? 0xFFFF : limit; -} - -/** - * 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; - byte [] position = new byte [ITER_SIZEOF]; - GdkRectangle rect = new GdkRectangle (); - OS.gtk_text_view_get_visible_rect (handle, rect); - OS.gtk_text_view_get_line_at_y (handle, position, rect.y, null); - return OS.gtk_text_iter_get_line (position); -} - -/** - * 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 (); - if ((style & SWT.SINGLE) != 0) return 0; - byte [] position = new byte [ITER_SIZEOF]; - GdkRectangle rect = new GdkRectangle (); - OS.gtk_text_view_get_visible_rect (handle, rect); - int [] lineTop = new int[1]; - OS.gtk_text_view_get_line_at_y (handle, position, rect.y, lineTop); - return lineTop [0]; -} - -int /*long*/ gtk_activate (int /*long*/ widget) { - postEvent (SWT.DefaultSelection); - return 0; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_button_press_event (widget, event); - if (result != 0) return result; - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, event, GdkEventButton.sizeof); - if (!doubleClick) { - switch (gdkEvent.type) { - case OS.GDK_2BUTTON_PRESS: - case OS.GDK_3BUTTON_PRESS: - return 1; - } - } - return result; -} - - -int /*long*/ gtk_changed (int /*long*/ widget) { - /* - * Feature in GTK. When the user types, GTK positions - * the caret after sending the changed signal. This - * means that application code that attempts to position - * the caret during a changed signal will fail. The fix - * is to post the modify event when the user is typing. - */ - boolean keyPress = false; - int /*long*/ eventPtr = OS.gtk_get_current_event (); - if (eventPtr != 0) { - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof); - switch (gdkEvent.type) { - case OS.GDK_KEY_PRESS: - keyPress = true; - break; - } - OS.gdk_event_free (eventPtr); - } - if (keyPress) { - postEvent (SWT.Modify); - } else { - sendEvent (SWT.Modify); - } - return 0; -} - -int /*long*/ gtk_commit (int /*long*/ imContext, int /*long*/ text) { - if (text == 0) return 0; - if ((style & SWT.SINGLE) != 0) { - if (!OS.gtk_editable_get_editable (handle)) return 0; - } - int length = OS.strlen (text); - if (length == 0) return 0; - byte [] buffer = new byte [length]; - OS.memmove (buffer, text, length); - char [] chars = Converter.mbcsToWcs (null, buffer); - char [] newChars = sendIMKeyEvent (SWT.KeyDown, null, chars); - if (newChars == null) return 0; - /* - * Feature in GTK. For a GtkEntry, during the insert-text signal, - * GTK allows the programmer to change only the caret location, - * not the selection. If the programmer changes the selection, - * the new selection is lost. The fix is to detect a selection - * change and set it after the insert-text signal has completed. - */ - fixStart = fixEnd = -1; - OS.g_signal_handlers_block_matched (imContext, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, COMMIT); - int id = OS.g_signal_lookup (OS.commit, OS.gtk_im_context_get_type ()); - int mask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID; - OS.g_signal_handlers_unblock_matched (imContext, mask, id, 0, 0, 0, handle); - if (newChars == chars) { - OS.g_signal_emit_by_name (imContext, OS.commit, text); - } else { - buffer = Converter.wcsToMbcs (null, newChars, true); - OS.g_signal_emit_by_name (imContext, OS.commit, buffer); - } - OS.g_signal_handlers_unblock_matched (imContext, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, COMMIT); - OS.g_signal_handlers_block_matched (imContext, mask, id, 0, 0, 0, handle); - if ((style & SWT.SINGLE) != 0) { - if (fixStart != -1 && fixEnd != -1) { - OS.gtk_editable_set_position (handle, fixStart); - OS.gtk_editable_select_region (handle, fixStart, fixEnd); - } - } - fixStart = fixEnd = -1; - return 0; -} - -int /*long*/ gtk_delete_range (int /*long*/ widget, int /*long*/ iter1, int /*long*/ iter2) { - if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0; - byte [] startIter = new byte [ITER_SIZEOF]; - byte [] endIter = new byte [ITER_SIZEOF]; - OS.memmove (startIter, iter1, startIter.length); - OS.memmove (endIter, iter2, endIter.length); - int start = OS.gtk_text_iter_get_offset (startIter); - int end = OS.gtk_text_iter_get_offset (endIter); - String newText = verifyText ("", start, end); - if (newText == null) { - /* Remember the selection when the text was deleted */ - OS.gtk_text_buffer_get_selection_bounds (bufferHandle, startIter, endIter); - start = OS.gtk_text_iter_get_offset (startIter); - end = OS.gtk_text_iter_get_offset (endIter); - if (start != end) { - fixStart = start; - fixEnd = end; - } - OS.g_signal_stop_emission_by_name (bufferHandle, OS.delete_range); - } else { - if (newText.length () > 0) { - byte [] buffer = Converter.wcsToMbcs (null, newText, false); - OS.g_signal_handlers_block_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_signal_handlers_block_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_RANGE); - OS.gtk_text_buffer_delete (bufferHandle, startIter, endIter); - OS.g_signal_handlers_unblock_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_RANGE); - OS.g_signal_handlers_unblock_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_signal_handlers_block_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEXT_BUFFER_INSERT_TEXT); - OS.gtk_text_buffer_insert (bufferHandle, startIter, buffer, buffer.length); - OS.g_signal_handlers_unblock_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEXT_BUFFER_INSERT_TEXT); - OS.g_signal_stop_emission_by_name (bufferHandle, OS.delete_range); - } - } - return 0; -} - -int /*long*/ gtk_delete_text (int /*long*/ widget, int /*long*/ start_pos, int /*long*/ end_pos) { - if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0; - String newText = verifyText ("", (int)/*64*/start_pos, (int)/*64*/end_pos); - if (newText == null) { - /* Remember the selection when the text was deleted */ - int [] newStart = new int [1], newEnd = new int [1]; - OS.gtk_editable_get_selection_bounds (handle, newStart, newEnd); - if (newStart [0] != newEnd [0]) { - fixStart = newStart [0]; - fixEnd = newEnd [0]; - } - OS.g_signal_stop_emission_by_name (handle, OS.delete_text); - } else { - if (newText.length () > 0) { - int [] pos = new int [1]; - pos [0] = (int)/*64*/end_pos; - byte [] buffer = Converter.wcsToMbcs (null, newText, false); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - OS.gtk_editable_insert_text (handle, buffer, buffer.length, pos); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_editable_set_position (handle, pos [0]); - } - } - return 0; -} - -int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) { - if (cursor != null) setCursor (cursor.handle); - /* - * Feature in GTK. The gtk-entry-select-on-focus property is a global - * setting. Return it to its default value after the GtkEntry has done - * its focus in processing so that other widgets (such as the combo) - * use the correct value. - */ - if ((style & SWT.SINGLE) != 0 && display.entrySelectOnFocus) { - GdkEvent event = new GdkEvent (); - OS.memmove (event, gdkEvent, GdkEvent.sizeof); - switch (event.type) { - case OS.GDK_FOCUS_CHANGE: - GdkEventFocus gdkEventFocus = new GdkEventFocus (); - OS.memmove (gdkEventFocus, gdkEvent, GdkEventFocus.sizeof); - if (gdkEventFocus.in == 0) { - int /*long*/ settings = OS.gtk_settings_get_default (); - OS.g_object_set (settings, OS.gtk_entry_select_on_focus, true, 0); - } - break; - } - } - return super.gtk_event_after (widget, gdkEvent); -} - -int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ event) { - if ((state & OBSCURED) != 0) return 0; - int /*long*/ result = super.gtk_expose_event (widget, event); - if ((style & SWT.SINGLE) != 0 && message.length () > 0) { - int /*long*/ str = OS.gtk_entry_get_text (handle); - if (!OS.GTK_WIDGET_HAS_FOCUS (handle) && OS.strlen (str) == 0) { - GdkEventExpose gdkEvent = new GdkEventExpose (); - OS.memmove (gdkEvent, event, GdkEventExpose.sizeof); - int /*long*/ window = paintWindow (); - int [] w = new int [1], h = new int [1]; - OS.gdk_drawable_get_size (window, w, h); - GtkBorder innerBorder = Display.getEntryInnerBorder (handle); - int width = w [0] - innerBorder.left - innerBorder.right; - int height = h [0] - innerBorder.top - innerBorder.bottom; - int /*long*/ context = OS.gtk_widget_get_pango_context (handle); - int /*long*/ lang = OS.pango_context_get_language (context); - int /*long*/ metrics = OS.pango_context_get_metrics (context, getFontDescription (), lang); - int ascent = OS.PANGO_PIXELS (OS.pango_font_metrics_get_ascent (metrics)); - int descent = OS.PANGO_PIXELS (OS.pango_font_metrics_get_descent (metrics)); - OS.pango_font_metrics_unref (metrics); - byte [] buffer = Converter.wcsToMbcs (null, message, true); - int /*long*/ layout = OS.gtk_widget_create_pango_layout (handle, buffer); - int /*long*/ line = OS.pango_layout_get_line (layout, 0); - PangoRectangle rect = new PangoRectangle (); - OS.pango_layout_line_get_extents (line, null, rect); - rect.y = OS.PANGO_PIXELS (rect.y); - rect.height = OS.PANGO_PIXELS (rect.height); - rect.width = OS.PANGO_PIXELS (rect.width); - int y = (height - ascent - descent) / 2 + ascent + rect.y; - if (rect.height > height) { - y = (height - rect.height) / 2; - } else if (y < 0) { - y = 0; - } else if (y + rect.height > height) { - y = height - rect.height; - } - y += innerBorder.top; - int x = innerBorder.left; - boolean rtl = (style & SWT.RIGHT_TO_LEFT) != 0; - int alignment = style & (SWT.LEFT | SWT.CENTER | SWT.RIGHT); - switch (alignment) { - case SWT.LEFT: x = rtl ? width - rect.width: innerBorder.left; break; - case SWT.CENTER: x = (width - rect.width) / 2; break; - case SWT.RIGHT: x = rtl ? innerBorder.left : width - rect.width; break; - } - int /*long*/ gc = OS.gdk_gc_new (window); - int /*long*/ style = OS.gtk_widget_get_style (handle); - GdkColor textColor = new GdkColor (); - OS.gtk_style_get_text (style, OS.GTK_STATE_INSENSITIVE, textColor); - GdkColor baseColor = new GdkColor (); - OS.gtk_style_get_base (style, OS.GTK_STATE_NORMAL, baseColor); - OS.gdk_draw_layout_with_colors (window, gc, x, y, layout, textColor, baseColor); - OS.g_object_unref (gc); - OS.g_object_unref (layout); - } - } - return result; -} - -int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) { - fixIM (); - return super.gtk_focus_out_event (widget, event); -} - -int /*long*/ gtk_grab_focus (int /*long*/ widget) { - int /*long*/ result = super.gtk_grab_focus (widget); - /* - * Feature in GTK. GtkEntry widgets select their text on focus in, - * clearing the previous selection. This behavior is controlled by - * the gtk-entry-select-on-focus property. The fix is to disable - * this property when a GtkEntry is given focus and restore it after - * the entry has done focus in processing. - */ - if ((style & SWT.SINGLE) != 0 && display.entrySelectOnFocus) { - int /*long*/ settings = OS.gtk_settings_get_default (); - OS.g_object_set (settings, OS.gtk_entry_select_on_focus, false, 0); - } - return result; -} - -int /*long*/ gtk_insert_text (int /*long*/ widget, int /*long*/ new_text, int /*long*/ new_text_length, int /*long*/ position) { - if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0; - if (new_text == 0 || new_text_length == 0) return 0; - byte [] buffer = new byte [(int)/*64*/new_text_length]; - OS.memmove (buffer, new_text, buffer.length); - String oldText = new String (Converter.mbcsToWcs (null, buffer)); - int [] pos = new int [1]; - OS.memmove (pos, position, 4); - if (pos [0] == -1) { - int /*long*/ ptr = OS.gtk_entry_get_text (handle); - pos [0] = (int)/*64*/OS.g_utf8_strlen (ptr, -1); - } - /* Use the selection when the text was deleted */ - int start = pos [0], end = pos [0]; - if (fixStart != -1 && fixEnd != -1) { - start = pos [0] = fixStart; - end = fixEnd; - fixStart = fixEnd = -1; - } - String newText = verifyText (oldText, start, end); - if (newText != oldText) { - int [] newStart = new int [1], newEnd = new int [1]; - OS.gtk_editable_get_selection_bounds (handle, newStart, newEnd); - if (newText != null) { - if (newStart [0] != newEnd [0]) { - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_editable_delete_selection (handle); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - } - byte [] buffer3 = Converter.wcsToMbcs (null, newText, false); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - OS.gtk_editable_insert_text (handle, buffer3, buffer3.length, pos); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - newStart [0] = newEnd [0] = pos [0]; - } - pos [0] = newEnd [0]; - if (newStart [0] != newEnd [0]) { - fixStart = newStart [0]; - fixEnd = newEnd [0]; - } - OS.memmove (position, pos, 4); - OS.g_signal_stop_emission_by_name (handle, OS.insert_text); - } - return 0; -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ result = super.gtk_key_press_event (widget, event); - if (result != 0) fixIM (); - if (gdkEventKey == -1) result = 1; - gdkEventKey = 0; - return result; -} - -int /*long*/ gtk_populate_popup (int /*long*/ widget, int /*long*/ menu) { - if ((style & SWT.RIGHT_TO_LEFT) != 0) { - OS.gtk_widget_set_direction (menu, OS.GTK_TEXT_DIR_RTL); - OS.gtk_container_forall (menu, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL); - } - return 0; -} - -int /*long*/ gtk_text_buffer_insert_text (int /*long*/ widget, int /*long*/ iter, int /*long*/ text, int /*long*/ length) { - if (!hooks (SWT.Verify) && !filters (SWT.Verify)) return 0; - byte [] position = new byte [ITER_SIZEOF]; - OS.memmove (position, iter, position.length); - /* Use the selection when the text was deleted */ - int start = OS.gtk_text_iter_get_offset (position), end = start; - if (fixStart != -1 && fixEnd != -1) { - start = fixStart; - end = fixEnd; - fixStart = fixEnd = -1; - } - byte [] buffer = new byte [(int)/*64*/length]; - OS.memmove (buffer, text, buffer.length); - String oldText = new String (Converter.mbcsToWcs (null, buffer)); - String newText = verifyText (oldText, start, end); - if (newText == null) { - OS.g_signal_stop_emission_by_name (bufferHandle, OS.insert_text); - } else { - if (newText != oldText) { - byte [] buffer1 = Converter.wcsToMbcs (null, newText, false); - OS.g_signal_handlers_block_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEXT_BUFFER_INSERT_TEXT); - OS.gtk_text_buffer_insert (bufferHandle, iter, buffer1, buffer1.length); - OS.g_signal_handlers_unblock_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEXT_BUFFER_INSERT_TEXT); - OS.g_signal_stop_emission_by_name (bufferHandle, OS.insert_text); - } - } - return 0; -} - -void hookEvents () { - super.hookEvents(); - if ((style & SWT.SINGLE) != 0) { - OS.g_signal_connect_closure (handle, OS.changed, display.closures [CHANGED], true); - OS.g_signal_connect_closure (handle, OS.insert_text, display.closures [INSERT_TEXT], false); - OS.g_signal_connect_closure (handle, OS.delete_text, display.closures [DELETE_TEXT], false); - OS.g_signal_connect_closure (handle, OS.activate, display.closures [ACTIVATE], false); - OS.g_signal_connect_closure (handle, OS.grab_focus, display.closures [GRAB_FOCUS], false); - OS.g_signal_connect_closure (handle, OS.populate_popup, display.closures [POPULATE_POPUP], false); - } else { - OS.g_signal_connect_closure (bufferHandle, OS.changed, display.closures [CHANGED], false); - OS.g_signal_connect_closure (bufferHandle, OS.insert_text, display.closures [TEXT_BUFFER_INSERT_TEXT], false); - OS.g_signal_connect_closure (bufferHandle, OS.delete_range, display.closures [DELETE_RANGE], false); - OS.g_signal_connect_closure (handle, OS.populate_popup, display.closures [POPULATE_POPUP], false); - } - int /*long*/ imContext = imContext (); - if (imContext != 0) { - OS.g_signal_connect_closure (imContext, OS.commit, display.closures [COMMIT], false); - int id = OS.g_signal_lookup (OS.commit, OS.gtk_im_context_get_type ()); - int mask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID; - OS.g_signal_handlers_block_matched (imContext, mask, id, 0, 0, 0, handle); - } -} - -int /*long*/ imContext () { - if ((style & SWT.SINGLE) != 0) { - return OS.gtk_editable_get_editable (handle) ? OS.GTK_ENTRY_IM_CONTEXT (handle) : 0; - } - return OS.GTK_TEXTVIEW_IM_CONTEXT (handle); -} - -/** - * 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); - byte [] buffer = Converter.wcsToMbcs (null, string, false); - if ((style & SWT.SINGLE) != 0) { - int [] start = new int [1], end = new int [1]; - OS.gtk_editable_get_selection_bounds (handle, start, end); - OS.gtk_editable_delete_selection (handle); - OS.gtk_editable_insert_text (handle, buffer, buffer.length, start); - OS.gtk_editable_set_position (handle, start [0]); - } else { - byte [] start = new byte [ITER_SIZEOF]; - byte [] end = new byte [ITER_SIZEOF]; - if (OS.gtk_text_buffer_get_selection_bounds (bufferHandle, start, end)) { - OS.gtk_text_buffer_delete (bufferHandle, start, end); - } - OS.gtk_text_buffer_insert (bufferHandle, start, buffer, buffer.length); - OS.gtk_text_buffer_place_cursor (bufferHandle, start); - int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle); - OS.gtk_text_view_scroll_mark_onscreen (handle, mark); - } -} - -int /*long*/ paintWindow () { - if ((style & SWT.SINGLE) != 0) { - int /*long*/ window = super.paintWindow (); - int /*long*/ children = OS.gdk_window_get_children (window); - if (children != 0) window = OS.g_list_data (children); - OS.g_list_free (children); - return window; - } - OS.gtk_widget_realize (handle); - return OS.gtk_text_view_get_window (handle, OS.GTK_TEXT_WINDOW_TEXT); -} - -/** - * 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 (); - if ((style & SWT.SINGLE) != 0) { - OS.gtk_editable_paste_clipboard (handle); - } else { - int /*long*/ clipboard = OS.gtk_clipboard_get (OS.GDK_NONE); - OS.gtk_text_buffer_paste_clipboard (bufferHandle, clipboard, null, OS.gtk_text_view_get_editable (handle)); - } -} - -void register () { - super.register (); - if (bufferHandle != 0) display.addWidget (bufferHandle, this); - int /*long*/ imContext = imContext (); - if (imContext != 0) display.addWidget (imContext, this); -} - -void releaseWidget () { - super.releaseWidget (); - fixIM (); - if (OS.GTK_VERSION < OS.VERSION (2, 6, 0)) { - /* - * Bug in GTK. Any text copied into the clipboard will be lost when - * the GtkTextView is destroyed. The fix is to paste the contents as - * the widget is being destroyed to reference the text buffer, keeping - * it around until ownership of the clipboard is lost. - */ - if ((style & SWT.MULTI) != 0) { - int /*long*/ clipboard = OS.gtk_clipboard_get (OS.GDK_NONE); - OS.gtk_text_buffer_paste_clipboard (bufferHandle, clipboard, null, OS.gtk_text_view_get_editable (handle)); - } - } - message = 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); -} - -/** - * 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 (); - if ((style & SWT.SINGLE) != 0) { - OS.gtk_editable_select_region (handle, 0, -1); - } else { - byte [] start = new byte [ITER_SIZEOF]; - byte [] end = new byte [ITER_SIZEOF]; - OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, start, 0); - OS.gtk_text_buffer_get_end_iter (bufferHandle, end); - int /*long*/ insertMark = OS.gtk_text_buffer_get_insert (bufferHandle); - int /*long*/ selectionMark = OS.gtk_text_buffer_get_selection_bound (bufferHandle); - OS.gtk_text_buffer_move_mark (bufferHandle, selectionMark, start); - OS.gtk_text_buffer_move_mark (bufferHandle, insertMark, end); - } -} - -void setBackgroundColor (GdkColor color) { - super.setBackgroundColor (color); - OS.gtk_widget_modify_base (handle, 0, color); -} - -void setCursor (int /*long*/ cursor) { - int /*long*/ defaultCursor = 0; - if (cursor == 0) defaultCursor = OS.gdk_cursor_new (OS.GDK_XTERM); - super.setCursor (cursor != 0 ? cursor : defaultCursor); - if (cursor == 0) OS.gdk_cursor_destroy (defaultCursor); -} - -/** - * 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 (); - this.doubleClick = doubleClick; -} - -/** - * 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.SINGLE) != 0) { - OS.gtk_entry_set_visibility (handle, echo == '\0'); - OS.gtk_entry_set_invisible_char (handle, echo); - } -} - -/** - * 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 (); - style &= ~SWT.READ_ONLY; - if (!editable) style |= SWT.READ_ONLY; - if ((style & SWT.SINGLE) != 0) { - OS.gtk_editable_set_editable (handle, editable); - } else { - OS.gtk_text_view_set_editable (handle, editable); - } -} - -void setFontDescription (int /*long*/ font) { - super.setFontDescription (font); - setTabStops (tabs); -} - -/** - * 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; - redraw (false); -} - -/** - * 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(); -} - -/** - * 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 (); - if ((style & SWT.SINGLE) != 0) { - OS.gtk_editable_set_position (handle, start); - } else { - byte [] position = new byte [ITER_SIZEOF]; - OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, position, start); - OS.gtk_text_buffer_place_cursor (bufferHandle, position); - int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle); - OS.gtk_text_view_scroll_mark_onscreen (handle, mark); - } -} - -/** - * 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 (); - if ((style & SWT.SINGLE) != 0) { - OS.gtk_editable_set_position (handle, start); - OS.gtk_editable_select_region (handle, start, end); - } else { - byte [] startIter = new byte [ITER_SIZEOF]; - byte [] endIter = new byte [ITER_SIZEOF]; - OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, startIter, start); - OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, endIter, end); - int /*long*/ insertMark = OS.gtk_text_buffer_get_insert (bufferHandle); - int /*long*/ selectionMark = OS.gtk_text_buffer_get_selection_bound (bufferHandle); - OS.gtk_text_buffer_move_mark (bufferHandle, selectionMark, startIter); - OS.gtk_text_buffer_move_mark (bufferHandle, insertMark, endIter); - } -} - -/** - * 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 (); - if (tabs < 0) return; - setTabStops (this.tabs = tabs); -} - -void setTabStops (int tabs) { - if ((style & SWT.SINGLE) != 0) return; - int tabWidth = getTabWidth (tabs); - int /*long*/ tabArray = OS.pango_tab_array_new (1, false); - OS.pango_tab_array_set_tab (tabArray, 0, OS.PANGO_TAB_LEFT, tabWidth); - OS.gtk_text_view_set_tabs (handle, tabArray); - OS.pango_tab_array_free (tabArray); -} - -/** - * 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); - /* - * Feature in gtk. When text is set in gtk, separate events are fired for the deletion and - * insertion of the text. This is not wrong, but is inconsistent with other platforms. The - * fix is to block the firing of these events and fire them ourselves in a consistent manner. - */ - if (hooks (SWT.Verify) || filters (SWT.Verify)) { - string = verifyText (string, 0, getCharCount ()); - if (string == null) return; - } - if ((style & SWT.SINGLE) != 0) { - byte [] buffer = Converter.wcsToMbcs (null, string, true); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT); - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - OS.gtk_entry_set_text (handle, buffer); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_TEXT); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, INSERT_TEXT); - } else { - byte [] buffer = Converter.wcsToMbcs (null, string, false); - byte [] position = new byte [ITER_SIZEOF]; - OS.g_signal_handlers_block_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_signal_handlers_block_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_RANGE); - OS.g_signal_handlers_block_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEXT_BUFFER_INSERT_TEXT); - OS.gtk_text_buffer_set_text (bufferHandle, buffer, buffer.length); - OS.g_signal_handlers_unblock_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.g_signal_handlers_unblock_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, DELETE_RANGE); - OS.g_signal_handlers_unblock_matched (bufferHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEXT_BUFFER_INSERT_TEXT); - OS.gtk_text_buffer_get_iter_at_offset (bufferHandle, position, 0); - OS.gtk_text_buffer_place_cursor (bufferHandle, position); - int /*long*/ mark = OS.gtk_text_buffer_get_insert (bufferHandle); - OS.gtk_text_view_scroll_mark_onscreen (handle, mark); - } - sendEvent (SWT.Modify); -} - -/** - * 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); - if ((style & SWT.SINGLE) != 0) OS.gtk_entry_set_max_length (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; - byte [] position = new byte [ITER_SIZEOF]; - OS.gtk_text_buffer_get_iter_at_line (bufferHandle, position, index); - OS.gtk_text_view_scroll_to_iter (handle, position, 0, true, 0, 0); -} - -/** - * 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 (); - if ((style & SWT.SINGLE) != 0) return; - int /*long*/ mark = OS.gtk_text_buffer_get_selection_bound (bufferHandle); - OS.gtk_text_view_scroll_mark_onscreen (handle, mark); - mark = OS.gtk_text_buffer_get_insert (bufferHandle); - OS.gtk_text_view_scroll_mark_onscreen (handle, mark); -} - -boolean translateTraversal (GdkEventKey keyEvent) { - int key = keyEvent.keyval; - switch (key) { - case OS.GDK_KP_Enter: - case OS.GDK_Return: { - int /*long*/ imContext = imContext (); - if (imContext != 0) { - int /*long*/ [] preeditString = new int /*long*/ [1]; - OS.gtk_im_context_get_preedit_string (imContext, preeditString, null, null); - if (preeditString [0] != 0) { - int length = OS.strlen (preeditString [0]); - OS.g_free (preeditString [0]); - if (length != 0) return false; - } - } - } - } - return super.translateTraversal (keyEvent); -} - -int traversalCode (int key, GdkEventKey event) { - int bits = super.traversalCode (key, event); - if ((style & SWT.READ_ONLY) != 0) return bits; - if ((style & SWT.MULTI) != 0) { - bits &= ~SWT.TRAVERSE_RETURN; - if (key == OS.GDK_Tab && event != null) { - boolean next = (event.state & OS.GDK_SHIFT_MASK) == 0; - if (next && (event.state & OS.GDK_CONTROL_MASK) == 0) { - bits &= ~(SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS); - } - } - } - return bits; -} - -String verifyText (String string, int start, int end) { - if (string.length () == 0 && start == end) return null; - Event event = new Event (); - event.text = string; - event.start = start; - event.end = end; - int /*long*/ eventPtr = OS.gtk_get_current_event (); - if (eventPtr != 0) { - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof); - switch (gdkEvent.type) { - case OS.GDK_KEY_PRESS: - setKeyState (event, gdkEvent); - break; - } - OS.gdk_event_free (eventPtr); - } - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in the verify - * event. If this happens, answer null to cancel - * the operation. - */ - sendEvent (SWT.Verify, event); - if (!event.doit || isDisposed ()) return null; - return event.text; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java deleted file mode 100644 index 2d7306e76c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java +++ /dev/null @@ -1,551 +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.gtk.*; -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 { - ToolItem lastFocus; - ToolItem [] tabItemList; - ImageList imageList; - -/** - * 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 of 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; - } - int orientation = (style & SWT.VERTICAL) != 0 ? OS.GTK_ORIENTATION_VERTICAL : OS.GTK_ORIENTATION_HORIZONTAL; - OS.gtk_toolbar_set_orientation (handle, orientation); -} - -static int checkStyle (int style) { - /* - * Feature in GTK. It is not possible to create - * a toolbar that wraps. Therefore, no matter what - * style bits are specified, clear the WRAP bits so - * that the style matches the behavior. - */ - if ((style & SWT.WRAP) != 0) style &= ~SWT.WRAP; - /* - * 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); -} - -void createHandle (int index) { - state |= HANDLE | THEME_BACKGROUND; - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - handle = OS.gtk_toolbar_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (fixedHandle, handle); - if ((style & SWT.FLAT) != 0) { - byte [] swt_toolbar_flat = Converter.wcsToMbcs (null, "swt-toolbar-flat", true); - OS.gtk_widget_set_name (handle, swt_toolbar_flat); - } -} - -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; - return computeNativeSize (handle, wHint, hHint, changed); -} - -Widget computeTabGroup () { - ToolItem [] items = _getItems (); - if (tabItemList == null) { - int i = 0; - while (i < items.length && items [i].control == null) i++; - if (i == items.length) return super.computeTabGroup (); - } - int index = 0; - while (index < items.length) { - if (items[index].hasFocus ()) break; - index++; - } - while (index >= 0) { - ToolItem item = items [index]; - if (item.isTabGroup ()) return item; - index--; - } - return super.computeTabGroup (); -} - -Widget [] computeTabList () { - ToolItem [] items = _getItems (); - if (tabItemList == null) { - int i = 0; - while (i < items.length && items [i].control == null) i++; - if (i == items.length) return super.computeTabList (); - } - Widget result [] = {}; - if (!isTabGroup () || !isEnabled () || !isVisible ()) return result; - ToolItem [] list = tabList != null ? _getTabItemList () : items; - for (int i=0; i<list.length; i++) { - ToolItem child = list [i]; - Widget [] childList = child.computeTabList (); - if (childList.length != 0) { - Widget [] newResult = new Widget [result.length + childList.length]; - System.arraycopy (result, 0, newResult, 0, result.length); - System.arraycopy (childList, 0, newResult, result.length, childList.length); - result = newResult; - } - } - if (result.length == 0) result = new Widget [] {this}; - return result; -} - -int /*long*/ eventHandle () { - return fixedHandle; -} - -int /*long*/ enterExitHandle() { - return handle; -} - -void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) { - super.fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus); - ToolItem [] items = getItems (); - if (toolTipText == null) { - for (int i = 0; i < items.length; i++) { - ToolItem item = items [i]; - if (item.toolTipText != null) { - item.setToolTipText(oldShell, null); - item.setToolTipText(newShell, item.toolTipText); - } - } - } -} - -boolean forceFocus (int /*long*/ focusHandle) { - if (lastFocus != null && lastFocus.setFocus ()) return true; - ToolItem [] items = getItems (); - for (int i = 0; i < items.length; i++) { - ToolItem item = items [i]; - if (item.setFocus ()) return true; - } - return super.forceFocus (focusHandle); -} - -/** - * 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 < getItemCount())) error (SWT.ERROR_INVALID_RANGE); - return getItems()[index]; -} - -/** - * 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 point) { - checkWidget(); - if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - ToolItem[] items = getItems(); - for (int i=0; i<items.length; i++) { - if (items[i].getBounds().contains(point)) 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(); - int /*long*/ list = OS.gtk_container_get_children (handle); - if (list == 0) return 0; - int itemCount = OS.g_list_length (list); - OS.g_list_free (list); - 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(); - return _getItems (); -} - -ToolItem [] _getItems () { - int /*long*/ list = OS.gtk_container_get_children (handle); - if (list == 0) return new ToolItem [0]; - int count = OS.g_list_length (list); - ToolItem [] items = new ToolItem [count]; - int index = 0; - for (int i=0; i<count; i++) { - int /*long*/ data = OS.g_list_nth_data (list, i); - Widget widget = display.getWidget (data); - if (widget != null) items [index++] = (ToolItem) widget; - } - OS.g_list_free (list); - if (index != items.length) { - ToolItem [] newItems = new ToolItem [index]; - System.arraycopy (items, 0, newItems, 0, index); - items = newItems; - } - return items; -} - -/** - * 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(); - /* On GTK, toolbars cannot wrap */ - return 1; -} - -ToolItem [] _getTabItemList () { - if (tabItemList == null) return tabItemList; - int count = 0; - for (int i=0; i<tabItemList.length; i++) { - if (!tabItemList [i].isDisposed ()) count++; - } - if (count == tabItemList.length) return tabItemList; - ToolItem [] newList = new ToolItem [count]; - int index = 0; - for (int i=0; i<tabItemList.length; i++) { - if (!tabItemList [i].isDisposed ()) { - newList [index++] = tabItemList [i]; - } - } - tabItemList = newList; - return tabItemList; -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ eventPtr) { - if (!hasFocus ()) return 0; - int /*long*/ result = super.gtk_key_press_event (widget, eventPtr); - if (result != 0) return result; - ToolItem [] items = getItems (); - int length = items.length; - int index = 0; - while (index < length) { - if (items [index].hasFocus ()) break; - index++; - } - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof); - boolean next = false; - switch (gdkEvent.keyval) { - case OS.GDK_Up: - case OS.GDK_Left: next = false; break; - case OS.GDK_Down: { - if (0 <= index && index < length) { - ToolItem item = items [index]; - if ((item.style & SWT.DROP_DOWN) != 0) { - Event event = new Event (); - event.detail = SWT.ARROW; - int /*long*/ topHandle = item.topHandle (); - event.x = OS.GTK_WIDGET_X (topHandle); - event.y = OS.GTK_WIDGET_Y (topHandle) + OS.GTK_WIDGET_HEIGHT (topHandle); - if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth() - OS.GTK_WIDGET_WIDTH(topHandle) - event.x; - item.postEvent (SWT.Selection, event); - return result; - } - } - //FALL THROUGH - } - case OS.GDK_Right: next = true; break; - default: return result; - } - if ((style & SWT.MIRRORED) != 0) next= !next; - int start = index, offset = next ? 1 : -1; - while ((index = (index + offset + length) % length) != start) { - ToolItem item = items [index]; - if (item.setFocus ()) return result; - } - return result; -} - -boolean hasFocus () { - ToolItem [] items = getItems (); - for (int i=0; i<items.length; i++) { - ToolItem item = items [i]; - if (item.hasFocus ()) return true; - } - return super.hasFocus(); -} - -/** - * 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); - ToolItem [] items = getItems (); - for (int i=0; i<items.length; i++) { - if (item == items[i]) return i; - } - return -1; -} - -boolean mnemonicHit (char key) { - ToolItem [] items = getItems (); - for (int i=0; i<items.length; i++) { - int /*long*/ labelHandle = items [i].labelHandle; - if (labelHandle != 0 && mnemonicHit (labelHandle, key)) return true; - } - return false; -} - -boolean mnemonicMatch (char key) { - ToolItem [] items = getItems (); - for (int i=0; i<items.length; i++) { - int /*long*/ labelHandle = items [i].labelHandle; - if (labelHandle != 0 && mnemonicMatch (labelHandle, key)) return true; - } - return false; -} - -void relayout () { - ToolItem [] items = getItems (); - for (int i=0; i<items.length; i++) { - ToolItem item = items [i]; - if (item != null) item.resizeControl (); - } -} - -void releaseChildren (boolean destroy) { - ToolItem [] items = getItems (); - for (int i=0; i<items.length; i++) { - ToolItem item = items [i]; - if (item != null && !item.isDisposed ()) { - item.release (false); - } - } - super.releaseChildren (destroy); -} - -void releaseWidget () { - super.releaseWidget (); - if (imageList != null) imageList.dispose (); - imageList = null; -} - -void removeControl (Control control) { - super.removeControl (control); - ToolItem [] items = getItems (); - for (int i=0; i<items.length; i++) { - ToolItem item = items [i]; - if (item.control == control) item.setControl (null); - } -} - -int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - int result = super.setBounds (x, y, width, height, move, resize); - if ((result & RESIZED) != 0) relayout (); - return result; -} - -void setFontDescription (int /*long*/ font) { - super.setFontDescription (font); - ToolItem [] items = getItems (); - for (int i = 0; i < items.length; i++) { - items[i].setFontDescription (font); - } - relayout (); -} - -void setForegroundColor (GdkColor color) { - super.setForegroundColor (color); - ToolItem [] items = getItems (); - for (int i = 0; i < items.length; i++) { - items[i].setForegroundColor (color); - } -} - -/*public*/ void setTabItemList (ToolItem [] tabList) { - checkWidget (); - if (tabList != null) { - for (int i=0; i<tabList.length; i++) { - ToolItem item = tabList [i]; - if (item == null) error (SWT.ERROR_INVALID_ARGUMENT); - if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - if (item.parent != this) error (SWT.ERROR_INVALID_PARENT); - } - ToolItem [] newList = new ToolItem [tabList.length]; - System.arraycopy (tabList, 0, newList, 0, tabList.length); - tabList = newList; - } - this.tabItemList = tabList; -} - -public void setToolTipText (String string) { - checkWidget(); - super.setToolTipText (string); - Shell shell = _getShell (); - ToolItem [] items = getItems (); - for (int i = 0; i < items.length; i++) { - String newString = string != null ? null : items [i].toolTipText; - shell.setToolTipText (items [i].handle, newString); - } -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java deleted file mode 100644 index 6013cfc10a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java +++ /dev/null @@ -1,1091 +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.gtk.*; -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 { - int /*long*/ boxHandle, arrowHandle, arrowBoxHandle, separatorHandle, labelHandle, imageHandle; - ToolBar parent; - Control control; - Image hotImage, disabledImage; - String toolTipText; - boolean drawHotImage; - -/** - * 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; - createWidget (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; - int count = parent.getItemCount (); - if (!(0 <= index && index <= count)) { - error (SWT.ERROR_INVALID_RANGE); - } - createWidget (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) { - state |= HANDLE; - if ((style & SWT.SEPARATOR) == 0) { - boxHandle = (parent.style & SWT.RIGHT) != 0 ? OS.gtk_hbox_new (false, 0) : OS.gtk_vbox_new (false, 0); - if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES); - labelHandle = OS.gtk_label_new_with_mnemonic (null); - if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES); - imageHandle = OS.gtk_image_new (); - if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (boxHandle, imageHandle); - OS.gtk_container_add (boxHandle, labelHandle); - if ((parent.style & SWT.VERTICAL) != 0) { - // Align text and images to the left - OS.gtk_box_set_child_packing (boxHandle, imageHandle, false, false, 0, OS.GTK_PACK_START); - OS.gtk_box_set_child_packing (boxHandle, labelHandle, false, false, 2, OS.GTK_PACK_START); - } - } - int bits = SWT.SEPARATOR | SWT.RADIO | SWT.CHECK | SWT.PUSH | SWT.DROP_DOWN; - switch (style & bits) { - case SWT.SEPARATOR: - handle = OS.gtk_hbox_new (false, 0); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - boolean isVertical = (parent.style & SWT.VERTICAL) != 0; - separatorHandle = isVertical ? OS.gtk_hseparator_new() : OS.gtk_vseparator_new(); - if (separatorHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_widget_set_size_request (separatorHandle, isVertical ? 15 : 6, isVertical ? 6 : 15); - OS.gtk_widget_set_size_request (handle, isVertical ? 15 : 6, isVertical ? 6 : 15); - OS.gtk_container_add (handle, separatorHandle); - break; - case SWT.DROP_DOWN: - handle = OS.gtk_button_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - arrowBoxHandle = OS.gtk_hbox_new (false, 0); - if (arrowBoxHandle == 0) error(SWT.ERROR_NO_HANDLES); - arrowHandle = OS.gtk_arrow_new (OS.GTK_ARROW_DOWN, OS.GTK_SHADOW_NONE); - if (arrowHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_widget_set_size_request (arrowHandle, 8, 6); - OS.gtk_container_add (handle, arrowBoxHandle); - OS.gtk_container_add (arrowBoxHandle, boxHandle); - OS.gtk_container_add (arrowBoxHandle, arrowHandle); - break; - case SWT.RADIO: - /* - * This code is intentionally commented. Because GTK - * enforces radio behavior in a button group a radio group - * is not created for each set of contiguous buttons, each - * radio button will not draw unpressed. The fix is to use - * toggle buttons instead. - */ -// handle = OS.gtk_radio_button_new (0); -// if (handle == 0) error (SWT.ERROR_NO_HANDLES); -// OS.gtk_toggle_button_set_mode (handle, false); -// OS.gtk_container_add (handle, boxHandle); -// break; - case SWT.CHECK: - handle = OS.gtk_toggle_button_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_toggle_button_set_mode (handle, false); - OS.gtk_container_add (handle, boxHandle); - break; - case SWT.PUSH: - default: - handle = OS.gtk_button_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (handle, boxHandle); - break; - } - if ((style & SWT.SEPARATOR) == 0) { - int [] relief = new int [1]; - OS.gtk_widget_style_get (parent.handle, OS.button_relief, relief, 0); - OS.gtk_button_set_relief (handle, relief [0]); - } - OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS); -// This code is intentionally commented. -// int /*long*/ fontHandle = parent.fontHandle (); -// GdkColor color = new GdkColor (); -// int /*long*/ style = OS.gtk_widget_get_style (fontHandle); -// OS.gtk_style_get_fg (style, OS.GTK_STATE_NORMAL, color); -// int /*long*/ font = OS.gtk_style_get_font_desc (style); -// setForegroundColor (color); -// setFontDescription (font); - if ((parent.state & FOREGROUND) != 0) { - setForegroundColor (parent.getForegroundColor()); - } - if ((parent.state & FONT) != 0) { - setFontDescription (parent.getFontDescription()); - } -} - -void createWidget (int index) { - super.createWidget (index); - showWidget (index); - parent.relayout (); -} - -Widget [] computeTabList () { - if (isTabGroup ()) { - if (getEnabled ()) { - if ((style & SWT.SEPARATOR) != 0) { - if (control != null) return control.computeTabList(); - } else { - return new Widget [] {this}; - } - } - } - return new Widget [0]; -} - -void deregister() { - super.deregister (); - if (labelHandle != 0) display.removeWidget (labelHandle); -} - -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(); - parent.forceResize (); - int /*long*/ topHandle = topHandle (); - int x, y, width, height; - /* - * Bug in GTK. Toolbar items are only allocated their minimum size - * in versions before 2.4.0. The fix is to use the total size - * available minus any borders. - */ - if (OS.GTK_VERSION < OS.VERSION (2, 4, 0) && control != null && !control.isDisposed ()) { - int border = OS.gtk_container_get_border_width (parent.handle); - byte [] shadowType = Converter.wcsToMbcs (null, "shadow_type", true); - int [] shadow = new int [1]; - OS.gtk_widget_style_get (parent.handle, shadowType, shadow, 0); - if (shadow [0] != OS.GTK_SHADOW_NONE) { - border += OS.gtk_style_get_xthickness (OS.gtk_widget_get_style (parent.handle)); - } - if ((parent.style & SWT.VERTICAL) != 0) { - x = border; - y = OS.GTK_WIDGET_Y (topHandle) + border; - width = OS.GTK_WIDGET_WIDTH (parent.handle) - border*2; - height = OS.GTK_WIDGET_HEIGHT (topHandle); - } else { - x = OS.GTK_WIDGET_X (topHandle) + border; - y = border; - width = OS.GTK_WIDGET_WIDTH (topHandle); - height = OS.GTK_WIDGET_HEIGHT (parent.handle) - border*2; - } - } else { - x = OS.GTK_WIDGET_X (topHandle); - y = OS.GTK_WIDGET_Y (topHandle); - width = OS.GTK_WIDGET_WIDTH (topHandle); - height = OS.GTK_WIDGET_HEIGHT (topHandle); - } - if ((parent.style & SWT.MIRRORED) != 0) x = parent.getClientWidth () - width - x; - if ((style & SWT.SEPARATOR) != 0 && control != null) height = Math.max (height, 23); - return new Rectangle (x, y, width, height); -} - -/** - * 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 /*long*/ topHandle = topHandle (); - return OS.GTK_WIDGET_SENSITIVE (topHandle); -} - -/** - * 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(); - if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED); - 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 OS.gtk_toggle_button_get_active (handle); -} - -/** - * 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(); - parent.forceResize (); - int /*long*/ topHandle = topHandle (); - return OS.GTK_WIDGET_WIDTH (topHandle); -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, event, GdkEventButton.sizeof); - double x = gdkEvent.x; - gdkEvent.x += OS.GTK_WIDGET_X (handle); - double y = gdkEvent.y; - gdkEvent.y += OS.GTK_WIDGET_Y (handle); - OS.memmove (event, gdkEvent, GdkEventButton.sizeof); - int /*long*/ result = parent.gtk_button_press_event (widget, event); - gdkEvent.x = x; - gdkEvent.y = y; - OS.memmove (event, gdkEvent, GdkEventButton.sizeof); - return result; -} - -int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ event) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, event, GdkEventButton.sizeof); - double x = gdkEvent.x; - gdkEvent.x += OS.GTK_WIDGET_X (handle); - double y = gdkEvent.y; - gdkEvent.y += OS.GTK_WIDGET_Y (handle); - OS.memmove (event, gdkEvent, GdkEventButton.sizeof); - int /*long*/ result = parent.gtk_button_release_event (widget, event); - gdkEvent.x = x; - gdkEvent.y = y; - OS.memmove(event, gdkEvent, GdkEventButton.sizeof); - return result; -} - -int /*long*/ gtk_clicked (int /*long*/ widget) { - Event event = new Event (); - if ((style & SWT.DROP_DOWN) != 0) { - int /*long*/ eventPtr = OS.gtk_get_current_event (); - if (eventPtr != 0) { - GdkEvent gdkEvent = new GdkEvent (); - OS.memmove (gdkEvent, eventPtr, GdkEvent.sizeof); - switch (gdkEvent.type) { - case OS.GDK_BUTTON_PRESS: - case OS.GDK_2BUTTON_PRESS: - case OS.GDK_BUTTON_RELEASE: { - double [] x_win = new double [1]; - double [] y_win = new double [1]; - OS.gdk_event_get_coords (eventPtr, x_win, y_win); - int x = OS.GTK_WIDGET_X (arrowHandle) - OS.GTK_WIDGET_X (handle); - int width = OS.GTK_WIDGET_WIDTH (arrowHandle); - if ((((parent.style & SWT.RIGHT_TO_LEFT) == 0) && x <= (int)x_win [0]) - || (((parent.style & SWT.RIGHT_TO_LEFT) != 0) && (int)x_win [0] <= x + width)) { - event.detail = SWT.ARROW; - int /*long*/ topHandle = topHandle (); - event.x = OS.GTK_WIDGET_X (topHandle); - if ((parent.style & SWT.MIRRORED) != 0) event.x = parent.getClientWidth () - OS.GTK_WIDGET_WIDTH (topHandle) - event.x; - event.y = OS.GTK_WIDGET_Y (topHandle) + OS.GTK_WIDGET_HEIGHT (topHandle); - } - break; - } - } - OS.gdk_event_free (eventPtr); - } - } - if ((style & SWT.RADIO) != 0) { - if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) { - selectRadio (); - } - } - postEvent (SWT.Selection, event); - return 0; -} - -int /*long*/ gtk_enter_notify_event (int /*long*/ widget, int /*long*/ event) { - parent.gtk_enter_notify_event (widget, event); - drawHotImage = (parent.style & SWT.FLAT) != 0 && hotImage != null; - if (drawHotImage && imageHandle != 0) { - ImageList imageList = parent.imageList; - if (imageList != null) { - int index = imageList.indexOf (hotImage); - if (index != -1) { - int /*long*/ pixbuf = imageList.getPixbuf (index); - OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); - } - } - } - return 0; -} - -int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) { - GdkEvent event = new GdkEvent (); - OS.memmove (event, gdkEvent, GdkEvent.sizeof); - switch (event.type) { - case OS.GDK_BUTTON_PRESS: { - GdkEventButton gdkEventButton = new GdkEventButton (); - OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof); - if (gdkEventButton.button == 3) { - parent.showMenu ((int) gdkEventButton.x_root, (int) gdkEventButton.y_root); - } - break; - } - } - return 0; -} - -int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) { - OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS); - parent.lastFocus = this; - return 0; -} - -int /*long*/ gtk_leave_notify_event (int /*long*/ widget, int /*long*/ event) { - parent.gtk_leave_notify_event (widget, event); - if (drawHotImage) { - drawHotImage = false; - if (imageHandle != 0 && image != null) { - ImageList imageList = parent.imageList; - if (imageList != null) { - int index = imageList.indexOf (image); - if (index != -1) { - int /*long*/ pixbuf = imageList.getPixbuf (index); - OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); - } - } - } - } - return 0; -} - -int /*long*/ gtk_map (int /*long*/ widget) { - parent.fixZOrder (); - return 0; -} - -int /*long*/ gtk_mnemonic_activate (int /*long*/ widget, int /*long*/ arg1) { - return parent.gtk_mnemonic_activate (widget, arg1); -} - -boolean hasFocus () { - return OS.GTK_WIDGET_HAS_FOCUS (handle); -} - -void hookEvents () { - super.hookEvents (); - if ((style & SWT.SEPARATOR) != 0) return; - OS.g_signal_connect_closure (handle, OS.clicked, display.closures [CLICKED], false); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [LEAVE_NOTIFY_EVENT], 0, display.closures [LEAVE_NOTIFY_EVENT], false); - if (labelHandle != 0) OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false); - - OS.g_signal_connect_closure_by_id (handle, display.signalIds [FOCUS_OUT_EVENT], 0, display.closures [FOCUS_OUT_EVENT], false); - - /* - * Feature in GTK. Usually, GTK widgets propagate all events to their - * parent when they are done their own processing. However, in contrast - * to other widgets, the buttons that make up the tool items, do not propagate - * the mouse up/down events. It is interesting to note that they DO propagate - * mouse motion events. The fix is to explicitly forward mouse up/down events - * to the parent. - */ - int mask = - OS.GDK_EXPOSURE_MASK | OS.GDK_POINTER_MOTION_MASK | - OS.GDK_BUTTON_PRESS_MASK | OS.GDK_BUTTON_RELEASE_MASK | - OS.GDK_ENTER_NOTIFY_MASK | OS.GDK_LEAVE_NOTIFY_MASK | - OS.GDK_KEY_PRESS_MASK | OS.GDK_KEY_RELEASE_MASK | - OS.GDK_FOCUS_CHANGE_MASK; - OS.gtk_widget_add_events (handle, mask); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT], false); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [EVENT_AFTER], 0, display.closures[EVENT_AFTER], false); - - int /*long*/ topHandle = topHandle (); - OS.g_signal_connect_closure_by_id (topHandle, display.signalIds [MAP], 0, display.closures [MAP], true); -} - -/** - * 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 (); -} - -boolean isTabGroup () { - ToolItem [] tabList = parent._getTabItemList (); - if (tabList != null) { - for (int i=0; i<tabList.length; i++) { - if (tabList [i] == this) return true; - } - } - if ((style & SWT.SEPARATOR) != 0) return true; - int index = parent.indexOf (this); - if (index == 0) return true; - ToolItem previous = parent.getItem (index - 1); - return (previous.getStyle () & SWT.SEPARATOR) != 0; -} - -void register () { - super.register (); - if (labelHandle != 0) display.addWidget (labelHandle, this); -} - -void releaseHandle () { - super.releaseHandle (); - boxHandle = arrowHandle = separatorHandle = labelHandle = imageHandle = 0; -} - -void releaseWidget () { - super.releaseWidget (); - if (parent.lastFocus == this) parent.lastFocus = null; - parent = null; - control = null; - hotImage = disabledImage = null; - toolTipText = 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 resizeControl () { - if (control != null && !control.isDisposed ()) { - if (separatorHandle != 0) OS.gtk_widget_hide (separatorHandle); - /* - * Set the size and location of the control - * separately to minimize flashing in the - * case where the control does not resize - * to the size that was requested. This - * case can occur when the control is a - * combo box. - */ - Rectangle itemRect = getBounds (); - control.setSize (itemRect.width, itemRect.height); - OS.gtk_widget_set_size_request (handle, itemRect.width, itemRect.height); - Rectangle rect = control.getBounds (); - rect.x = itemRect.x + (itemRect.width - rect.width) / 2; - rect.y = itemRect.y + (itemRect.height - rect.height) / 2; - control.setLocation (rect.x, rect.y); - } else { - if (separatorHandle != 0) OS.gtk_widget_show (separatorHandle); - } -} - -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); -} - -/** - * 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; - parent.relayout (); -} - -/** - * 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 ((style & SWT.SEPARATOR) != 0) return; - disabledImage = image; -} - -/** - * 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 /*long*/ topHandle = topHandle (); - OS.gtk_widget_set_sensitive (topHandle, enabled); - if (enabled) { - /* - * Bug in GTK. GtkButton requires an enter notify before it - * allows the button to be pressed, but events are dropped when - * widgets are insensitive. The fix is to hide and show the - * button if the pointer is within its bounds. - */ - int [] x = new int [1], y = new int [1]; - OS.gdk_window_get_pointer (parent.paintWindow (), x, y, null); - if (getBounds ().contains (x [0], y [0])) { - OS.gtk_widget_hide (handle); - OS.gtk_widget_show (handle); - } - } -} - -boolean setFocus () { - if ((style & SWT.SEPARATOR) != 0) return false; - if (!OS.gtk_widget_get_child_visible (handle)) return false; - OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS); - OS.gtk_widget_grab_focus (handle); - boolean result = OS.gtk_widget_is_focus (handle); - if (!result) OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS); - return result; -} - -void setFontDescription (int /*long*/ font) { - OS.gtk_widget_modify_font (handle, font); - if (labelHandle != 0) OS.gtk_widget_modify_font (labelHandle, font); - if (imageHandle != 0) OS.gtk_widget_modify_font (imageHandle, font); -} - -void setForegroundColor (GdkColor color) { - setForegroundColor (handle, color); - if (labelHandle != 0) setForegroundColor (labelHandle, color); - if (imageHandle != 0) setForegroundColor (imageHandle, color); -} - -/** - * 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 ((style & SWT.SEPARATOR) != 0) return; - hotImage = image; - if (image != null) { - ImageList imageList = parent.imageList; - if (imageList == null) imageList = parent.imageList = new ImageList (); - int imageIndex = imageList.indexOf (image); - if (imageIndex == -1) { - imageIndex = imageList.add (image); - } else { - imageList.put (imageIndex, image); - } - } -} - -public void setImage (Image image) { - checkWidget(); - if ((style & SWT.SEPARATOR) != 0) return; - super.setImage (image); - if (imageHandle == 0) return; - if (image != null) { - ImageList imageList = parent.imageList; - if (imageList == null) imageList = parent.imageList = new ImageList (); - int imageIndex = imageList.indexOf (image); - if (imageIndex == -1) { - imageIndex = imageList.add (image); - } else { - imageList.put (imageIndex, image); - } - int /*long*/ pixbuf = imageList.getPixbuf (imageIndex); - OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); - OS.gtk_widget_show (imageHandle); - } else { - OS.gtk_image_set_from_pixbuf (imageHandle, 0); - OS.gtk_widget_hide (imageHandle); - } - parent.relayout (); -} - -void setOrientation () { - if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) { - if (handle != 0) OS.gtk_widget_set_direction (handle, OS.GTK_TEXT_DIR_RTL); - if (labelHandle != 0) OS.gtk_widget_set_direction (labelHandle, OS.GTK_TEXT_DIR_RTL); - if (imageHandle != 0) OS.gtk_widget_set_direction (imageHandle, OS.GTK_TEXT_DIR_RTL); - if (separatorHandle != 0) OS.gtk_widget_set_direction (separatorHandle, OS.GTK_TEXT_DIR_RTL); - if (arrowHandle != 0) OS.gtk_widget_set_direction (arrowHandle, OS.GTK_TEXT_DIR_RTL); - if (boxHandle != 0) OS.gtk_widget_set_direction (boxHandle, OS.GTK_TEXT_DIR_RTL); - if (arrowBoxHandle != 0) OS.gtk_widget_set_direction (arrowBoxHandle, OS.GTK_TEXT_DIR_RTL); - } -} - -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; - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED); - OS.gtk_toggle_button_set_active (handle, selected); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED); -} - -boolean setTabItemFocus (boolean next) { - return setFocus (); -} - -/** - * 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); - if (labelHandle == 0) return; - char [] chars = fixMnemonic (string); - byte [] buffer = Converter.wcsToMbcs (null, chars, true); - OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer); - if (string.length () != 0) { - OS.gtk_widget_show (labelHandle); - } else { - OS.gtk_widget_hide (labelHandle); - } - parent.relayout (); -} - -/** - * 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(); - if (parent.toolTipText == null) { - Shell shell = parent._getShell (); - setToolTipText (shell, string); - } - toolTipText = string; -} - -void setToolTipText (Shell shell, String newString) { - shell.setToolTipText (handle, newString); -} - -/** - * 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) return; - boolean isVertical = (parent.style & SWT.VERTICAL) != 0; - OS.gtk_widget_set_size_request (separatorHandle, width, isVertical ? 6 : 15); - OS.gtk_widget_set_size_request (handle, width, isVertical ? 6 : 15); - parent.relayout (); -} - -void showWidget (int index) { - if (handle != 0) OS.gtk_widget_show (handle); - if (boxHandle != 0) OS.gtk_widget_show (boxHandle); - if (separatorHandle != 0) OS.gtk_widget_show (separatorHandle); - if (arrowBoxHandle != 0) OS.gtk_widget_show (arrowBoxHandle); - if (arrowHandle != 0) OS.gtk_widget_show (arrowHandle); - OS.gtk_toolbar_insert_widget (parent.handle, handle, null, null, index); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java deleted file mode 100644 index a106744329..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolTip.java +++ /dev/null @@ -1,818 +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.gtk.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class represent popup windows that are used - * to inform or warn the user. - * <p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>BALLOON, ICON_ERROR, ICON_INFORMATION, ICON_WARNING</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection</dd> - * </dl> - * </p><p> - * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION, - * and ICON_WARNING 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/#tooltips">Tool Tips 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.2 - * @noextend This class is not intended to be subclassed by clients. - */ -public class ToolTip extends Widget { - Shell parent; - String text, message; - TrayItem item; - int x, y, timerId; - int /*long*/ layoutText = 0, layoutMessage = 0; - int [] borderPolygon; - boolean spikeAbove, autohide; - - static final int BORDER = 5; - static final int PADDING = 5; - static final int INSET = 4; - static final int TIP_HEIGHT = 20; - static final int IMAGE_SIZE = 16; - static final int DELAY = 8000; - -/** - * 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#BALLOON - * @see SWT#ICON_ERROR - * @see SWT#ICON_INFORMATION - * @see SWT#ICON_WARNING - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public ToolTip (Shell parent, int style) { - super (parent, checkStyle (style)); - this.parent = parent; - createWidget (0); - parent.addToolTip (this); -} - -static int checkStyle (int style) { - int mask = SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING; - if ((style & mask) == 0) return style; - return checkBits (style, SWT.ICON_INFORMATION, SWT.ICON_WARNING, SWT.ICON_ERROR, 0, 0, 0); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver 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 receiver is selected. - * <code>widgetDefaultSelected</code> is not called. - * </p> - * - * @param listener the listener which should be notified when the receiver 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); -} - -void configure () { - int /*long*/ screen = OS.gdk_screen_get_default (); - OS.gtk_widget_realize (handle); - int monitorNumber = OS.gdk_screen_get_monitor_at_window (screen, OS.GTK_WIDGET_WINDOW (handle)); - GdkRectangle dest = new GdkRectangle (); - OS.gdk_screen_get_monitor_geometry (screen, monitorNumber, dest); - Point point = getSize (dest.width / 4); - int w = point.x; - int h = point.y; - point = getLocation (); - int x = point.x; - int y = point.y; - OS.gtk_window_resize (handle, w, h + TIP_HEIGHT); - int[] polyline; - spikeAbove = dest.height >= y + h + TIP_HEIGHT; - if (dest.width >= x + w) { - if (dest.height >= y + h + TIP_HEIGHT) { - int t = TIP_HEIGHT; - polyline = new int[] { - 0, 5+t, 1, 5+t, 1, 3+t, 3, 1+t, 5, 1+t, 5, t, - 16, t, 16, 0, 35, t, - w-5, t, w-5, 1+t, w-3, 1+t, w-1, 3+t, w-1, 5+t, w, 5+t, - w, h-5+t, w-1, h-5+t, w-1, h-3+t, w-2, h-3+t, w-2, h-2+t, w-3, h-2+t, w-3, h-1+t, w-5, h-1+t, w-5, h+t, - 5, h+t, 5, h-1+t, 3, h-1+t, 3, h-2+t, 2, h-2+t, 2, h-3+t, 1, h-3+t, 1, h-5+t, 0, h-5+t, - 0, 5+t}; - borderPolygon = new int[] { - 0, 5+t, 1, 4+t, 1, 3+t, 3, 1+t, 4, 1+t, 5, t, - 16, t, 16, 1, 35, t, - w-6, 0+t, w-5, 1+t, w-4, 1+t, w-2, 3+t, w-2, 4+t, w-1, 5+t, - w-1, h-6+t, w-2, h-5+t, w-2, h-4+t, w-4, h-2+t, w-5, h-2+t, w-6, h-1+t, - 5, h-1+t, 4, h-2+t, 3, h-2+t, 1, h-4+t, 1, h-5+t, 0, h-6+t, - 0, 5+t}; - if ((parent.style & SWT.MIRRORED) != 0) { - x -= w - 36; - polyline[12] = w-36; - polyline[14] = w-16; - polyline[16] = w-15; - borderPolygon[12] = w-35; - borderPolygon[14] = borderPolygon[16] = w-16; - } - OS.gtk_window_move (handle, Math.max(0, x - 17), y); - } else { - polyline = new int[] { - 0, 5, 1, 5, 1, 3, 3, 1, 5, 1, 5, 0, - w-5, 0, w-5, 1, w-3, 1, w-1, 3, w-1, 5, w, 5, - w, h-5, w-1, h-5, w-1, h-3, w-2, h-3, w-2, h-2, w-3, h-2, w-3, h-1, w-5, h-1, w-5, h, - 35, h, 16, h+TIP_HEIGHT, 16, h, - 5, h, 5, h-1, 3, h-1, 3, h-2, 2, h-2, 2, h-3, 1, h-3, 1, h-5, 0, h-5, - 0, 5}; - borderPolygon = new int[] { - 0, 5, 1, 4, 1, 3, 3, 1, 4, 1, 5, 0, - w-6, 0, w-5, 1, w-4, 1, w-2, 3, w-2, 4, w-1, 5, - w-1, h-6, w-2, h-5, w-2, h-4, w-4, h-2, w-5, h-2, w-6, h-1, - 35, h-1, 17, h+TIP_HEIGHT-2, 17, h-1, - 5, h-1, 4, h-2, 3, h-2, 1, h-4, 1, h-5, 0, h-6, - 0, 5}; - if ((parent.style & SWT.MIRRORED) != 0) { - x -= w - 36; - polyline [42] = polyline [44] = w-16; - polyline [46] = w-35; - borderPolygon[36] = borderPolygon[38] = w-17; - borderPolygon [40] = w-35; - } - OS.gtk_window_move (handle, Math.max(0, x - 17), y - h - TIP_HEIGHT); - } - } else { - if (dest.height >= y + h + TIP_HEIGHT) { - int t = TIP_HEIGHT; - polyline = new int[] { - 0, 5+t, 1, 5+t, 1, 3+t, 3, 1+t, 5, 1+t, 5, t, - w-35, t, w-16, 0, w-16, t, - w-5, t, w-5, 1+t, w-3, 1+t, w-1, 3+t, w-1, 5+t, w, 5+t, - w, h-5+t, w-1, h-5+t, w-1, h-3+t, w-2, h-3+t, w-2, h-2+t, w-3, h-2+t, w-3, h-1+t, w-5, h-1+t, w-5, h+t, - 5, h+t, 5, h-1+t, 3, h-1+t, 3, h-2+t, 2, h-2+t, 2, h-3+t, 1, h-3+t, 1, h-5+t, 0, h-5+t, - 0, 5+t}; - borderPolygon = new int[] { - 0, 5+t, 1, 4+t, 1, 3+t, 3, 1+t, 4, 1+t, 5, t, - w-35, t, w-17, 2, w-17, t, - w-6, t, w-5, 1+t, w-4, 1+t, w-2, 3+t, w-2, 4+t, w-1, 5+t, - w-1, h-6+t, w-2, h-5+t, w-2, h-4+t, w-4, h-2+t, w-5, h-2+t, w-6, h-1+t, - 5, h-1+t, 4, h-2+t, 3, h-2+t, 1, h-4+t, 1, h-5+t, 0, h-6+t, - 0, 5+t}; - if ((parent.style & SWT.MIRRORED) != 0) { - x += w - 35; - polyline [12] = polyline [14] = 16; - polyline [16] = 35; - borderPolygon[12] = borderPolygon[14] = 16; - borderPolygon [16] = 35; - } - OS.gtk_window_move (handle, Math.min(dest.width - w, x - w + 17), y); - } else { - polyline = new int[] { - 0, 5, 1, 5, 1, 3, 3, 1, 5, 1, 5, 0, - w-5, 0, w-5, 1, w-3, 1, w-1, 3, w-1, 5, w, 5, - w, h-5, w-1, h-5, w-1, h-3, w-2, h-3, w-2, h-2, w-3, h-2, w-3, h-1, w-5, h-1, w-5, h, - w-16, h, w-16, h+TIP_HEIGHT, w-35, h, - 5, h, 5, h-1, 3, h-1, 3, h-2, 2, h-2, 2, h-3, 1, h-3, 1, h-5, 0, h-5, - 0, 5}; - borderPolygon = new int[] { - 0, 5, 1, 4, 1, 3, 3, 1, 4, 1, 5, 0, - w-6, 0, w-5, 1, w-4, 1, w-2, 3, w-2, 4, w-1, 5, - w-1, h-6, w-2, h-5, w-2, h-4, w-4, h-2, w-5, h-2, w-6, h-1, - w-17, h-1, w-17, h+TIP_HEIGHT-2, w-36, h-1, - 5, h-1, 4, h-2, 3, h-2, 1, h-4, 1, h-5, 0, h-6, - 0, 5}; - if ((parent.style & SWT.MIRRORED) != 0) { - x += w - 35; - polyline [42] = 35; - polyline [44] = polyline [46] = 16; - borderPolygon[36] = 35; - borderPolygon[38] = borderPolygon [40] = 17; - } - OS.gtk_window_move (handle, Math.min(dest.width - w, x - w + 17), y - h - TIP_HEIGHT); - } - } - int /*long*/ rgn = OS.gdk_region_polygon (polyline, polyline.length / 2, OS.GDK_EVEN_ODD_RULE); - OS.gtk_widget_realize (handle); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (handle); - OS.gdk_window_shape_combine_region (window, rgn, 0, 0); - OS.gdk_region_destroy (rgn); -} - -void createHandle (int index) { - state |= HANDLE; - if ((style & SWT.BALLOON) != 0) { - handle = OS.gtk_window_new (OS.GTK_WINDOW_POPUP); - Color background = display.getSystemColor (SWT.COLOR_INFO_BACKGROUND); - OS.gtk_widget_modify_bg (handle, OS.GTK_STATE_NORMAL, background.handle); - OS.gtk_widget_set_app_paintable (handle, true); - OS.gtk_window_set_type_hint (handle, OS.GDK_WINDOW_TYPE_HINT_TOOLTIP); - } else { - handle = OS.gtk_tooltips_new (); - if (handle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - /* - * Bug in Solaris-GTK. Invoking gtk_tooltips_force_window() - * can cause a crash in older versions of GTK. The fix is - * to avoid this call if the GTK version is older than 2.2.x. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 2, 1)) { - OS.gtk_tooltips_force_window (handle); - } - OS.g_object_ref (handle); - OS.gtk_object_sink (handle); - } -} - -void createWidget (int index) { - super.createWidget (index); - text = ""; - message = ""; - x = y = -1; - autohide = true; -} - -void deregister () { - super.deregister (); - if ((style & SWT.BALLOON) == 0) { - int /*long*/ tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (handle); - if (tipWindow != 0) display.removeWidget (tipWindow); - } -} - -void destroyWidget () { - int /*long*/ topHandle = topHandle (); - if (parent != null) parent.removeTooTip (this); - releaseHandle (); - if (topHandle != 0 && (state & HANDLE) != 0) { - if ((style & SWT.BALLOON) != 0) { - OS.gtk_widget_destroy (topHandle); - } else { - OS.g_object_unref (topHandle); - } - } -} - -/** - * Returns <code>true</code> if the receiver is automatically - * hidden by the platform, and <code>false</code> otherwise. - * - * @return the receiver's auto hide 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 getAutoHide () { - checkWidget (); - return autohide; -} - -Point getLocation () { - int x = this.x; - int y = this.y; - if (item != null) { - int /*long*/ itemHandle = item.handle; - if(OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) { - GdkRectangle area = new GdkRectangle (); - OS.gtk_status_icon_get_geometry (itemHandle, 0, area, 0); - x = area.x + area.width / 2; - y = area.y + area.height / 2; - } else { - OS.gtk_widget_realize (itemHandle); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (itemHandle); - int [] px = new int [1], py = new int [1]; - OS.gdk_window_get_origin (window, px, py); - x = px [0] + OS.GTK_WIDGET_WIDTH (itemHandle) / 2; - y = py [0] + OS.GTK_WIDGET_HEIGHT (itemHandle) / 2; - } - } - if (x == -1 || y == -1) { - int [] px = new int [1], py = new int [1]; - OS.gdk_window_get_pointer (0, px, py, null); - x = px [0]; - y = py [0]; - } - return new Point(x, y); -} - -/** - * Returns the receiver's message, which will be an empty - * string if it has never been set. - * - * @return the receiver's 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> - */ -public String getMessage () { - checkWidget (); - return message; -} - -String getNameText () { - return getText (); -} - -/** - * Returns the receiver's parent, which must be a <code>Shell</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 Shell getParent () { - checkWidget (); - return parent; -} - -Point getSize (int maxWidth) { - int textWidth = 0, messageWidth = 0; - int [] w = new int [1], h = new int [1]; - if (layoutText != 0) { - OS.pango_layout_set_width (layoutText, -1); - OS.pango_layout_get_size (layoutText, w, h); - textWidth = OS.PANGO_PIXELS (w [0]); - } - if (layoutMessage != 0) { - OS.pango_layout_set_width (layoutMessage, -1); - OS.pango_layout_get_size (layoutMessage, w, h); - messageWidth = OS.PANGO_PIXELS (w [0]); - } - int messageTrim = 2 * INSET + 2 * BORDER + 2 * PADDING; - boolean hasImage = layoutText != 0 && (style & (SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING)) != 0; - int textTrim = messageTrim + (hasImage ? IMAGE_SIZE : 0); - int width = Math.min (maxWidth, Math.max (textWidth + textTrim, messageWidth + messageTrim)); - int textHeight = 0, messageHeight = 0; - if (layoutText != 0) { - OS.pango_layout_set_width (layoutText, (maxWidth - textTrim) * OS.PANGO_SCALE); - OS.pango_layout_get_size (layoutText, w, h); - textHeight = OS.PANGO_PIXELS (h [0]); - } - if (layoutMessage != 0) { - OS.pango_layout_set_width (layoutMessage, (maxWidth - messageTrim) * OS.PANGO_SCALE); - OS.pango_layout_get_size (layoutMessage, w, h); - messageHeight = OS.PANGO_PIXELS (h [0]); - } - int height = 2 * BORDER + 2 * PADDING + messageHeight; - if (layoutText != 0) height += Math.max (IMAGE_SIZE, textHeight) + 2 * PADDING; - return new Point(width, height); -} - -/** - * 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; -} - -/** - * 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.BALLOON) != 0) return OS.GTK_WIDGET_VISIBLE (handle); - int /*long*/ tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (handle); - return OS.GTK_WIDGET_VISIBLE (tipWindow); -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - notifyListeners (SWT.Selection, new Event ()); - setVisible (false); - return 0; -} - -int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ eventPtr) { - int /*long*/ window = OS.GTK_WIDGET_WINDOW (handle); - int /*long*/ gdkGC = OS.gdk_gc_new (window); - OS.gdk_draw_polygon (window, gdkGC, 0, borderPolygon, borderPolygon.length / 2); - int x = BORDER + PADDING; - int y = BORDER + PADDING; - if (spikeAbove) y += TIP_HEIGHT; - if (layoutText != 0) { - byte[] buffer = null; - int id = style & (SWT.ICON_ERROR | SWT.ICON_INFORMATION | SWT.ICON_WARNING); - switch (id) { - case SWT.ICON_ERROR: buffer = Converter.wcsToMbcs (null, "gtk-dialog-error", true); break; - case SWT.ICON_INFORMATION: buffer = Converter.wcsToMbcs (null, "gtk-dialog-info", true); break; - case SWT.ICON_WARNING: buffer = Converter.wcsToMbcs (null, "gtk-dialog-warning", true); break; - } - if (buffer != null) { - int /*long*/ style = OS.gtk_widget_get_default_style (); - int /*long*/ pixbuf = OS.gtk_icon_set_render_icon ( - OS.gtk_icon_factory_lookup_default (buffer), - style, - OS.GTK_TEXT_DIR_NONE, - OS.GTK_STATE_NORMAL, - OS.GTK_ICON_SIZE_MENU, - 0, - 0); - OS.gdk_draw_pixbuf (window, gdkGC, pixbuf, 0, 0, x, y, IMAGE_SIZE, IMAGE_SIZE, OS.GDK_RGB_DITHER_NORMAL, 0, 0); - OS.g_object_unref (pixbuf); - x += IMAGE_SIZE; - } - x += INSET; - OS.gdk_draw_layout (window, gdkGC, x, y, layoutText); - int [] w = new int [1], h = new int [1]; - OS.pango_layout_get_size (layoutText, w, h); - y += 2 * PADDING + Math.max (IMAGE_SIZE, OS.PANGO_PIXELS (h [0])); - } - if (layoutMessage != 0) { - x = BORDER + PADDING + INSET; - OS.gdk_draw_layout (window, gdkGC, x, y, layoutMessage); - } - OS.g_object_unref (gdkGC); - return 0; -} - -int /*long*/ gtk_size_allocate (int /*long*/ widget, int /*long*/ allocation) { - Point point = getLocation (); - int x = point.x; - int y = point.y; - int /*long*/ screen = OS.gdk_screen_get_default (); - OS.gtk_widget_realize (widget); - int monitorNumber = OS.gdk_screen_get_monitor_at_window (screen, OS.GTK_WIDGET_WINDOW (widget)); - GdkRectangle dest = new GdkRectangle (); - OS.gdk_screen_get_monitor_geometry (screen, monitorNumber, dest); - int w = OS.GTK_WIDGET_WIDTH (widget); - int h = OS.GTK_WIDGET_HEIGHT (widget); - if (dest.height < y + h) y -= h; - if (dest.width < x + w) x -= w; - OS.gtk_window_move (widget, x, y); - return 0; -} - -void hookEvents () { - if ((style & SWT.BALLOON) != 0) { - OS.g_signal_connect_closure (handle, OS.expose_event, display.closures [EXPOSE_EVENT], false); - OS.gtk_widget_add_events (handle, OS.GDK_BUTTON_PRESS_MASK); - OS.g_signal_connect_closure (handle, OS.button_press_event, display.closures [BUTTON_PRESS_EVENT], false); - } else { - int /*long*/ tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (handle); - if (tipWindow != 0) { - OS.g_signal_connect_closure (tipWindow, OS.size_allocate, display.closures [SIZE_ALLOCATE], false); - OS.gtk_widget_add_events (tipWindow, OS.GDK_BUTTON_PRESS_MASK); - OS.g_signal_connect_closure (tipWindow, OS.button_press_event, display.closures [BUTTON_PRESS_EVENT], false); - } - } -} - -/** - * 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 register () { - super.register (); - if ((style & SWT.BALLOON) == 0) { - int /*long*/ tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (handle); - if (tipWindow != 0) display.addWidget (tipWindow, this); - } -} - -void releaseWidget () { - super.releaseWidget (); - if (layoutText != 0) OS.g_object_unref (layoutText); - layoutText = 0; - if (layoutMessage != 0) OS.g_object_unref (layoutMessage); - layoutMessage = 0; - if (timerId != 0) OS.gtk_timeout_remove(timerId); - timerId = 0; - text = null; - message = null; - borderPolygon = null; -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver 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); -} - -/** - * Makes the receiver hide automatically when <code>true</code>, - * and remain visible when <code>false</code>. - * - * @param autoHide the auto hide 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 - * @see #setVisible - */ -public void setAutoHide (boolean autohide) { - checkWidget (); - this.autohide = autohide; - //TODO - update when visible -} - -/** - * Sets the location of the receiver, which must be a tooltip, - * 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> - * - * @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 (); - this.x = x; - this.y = y; - if ((style & SWT.BALLOON) != 0) { - if (OS.GTK_WIDGET_VISIBLE (handle)) configure (); - } else { - int /*long*/ tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (handle); - if (OS.GTK_WIDGET_VISIBLE (tipWindow)) { - OS.gtk_window_move (tipWindow, x, y); - } - } -} - -/** - * Sets the location of the receiver, which must be a tooltip, - * 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 tooltips. - * </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> - */ -public void setLocation (Point location) { - checkWidget (); - if (location == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); - setLocation (location.x, location.y); -} - -/** - * Sets the receiver's message. - * - * @param string the new message - * - * @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 setMessage (String string) { - checkWidget (); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - message = string; - if ((style & SWT.BALLOON) == 0) return; - if (layoutMessage != 0) OS.g_object_unref (layoutMessage); - layoutMessage = 0; - if (message.length () != 0) { - byte [] buffer = Converter.wcsToMbcs (null, message, true); - layoutMessage = OS.gtk_widget_create_pango_layout (handle, buffer); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.pango_layout_set_auto_dir (layoutMessage, false); - } - OS.pango_layout_set_wrap (layoutMessage, OS.PANGO_WRAP_WORD_CHAR); - } - if (OS.GTK_WIDGET_VISIBLE (handle)) configure (); -} - -/** - * Sets the receiver's text. - * - * @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; - if ((style & SWT.BALLOON) == 0) return; - if (layoutText != 0) OS.g_object_unref (layoutText); - layoutText = 0; - if (text.length () != 0) { - byte [] buffer = Converter.wcsToMbcs (null, text, true); - layoutText = OS.gtk_widget_create_pango_layout (handle, buffer); - if (OS.GTK_VERSION >= OS.VERSION (2, 4, 0)) { - OS.pango_layout_set_auto_dir (layoutText, false); - } - int /*long*/ boldAttr = OS.pango_attr_weight_new (OS.PANGO_WEIGHT_BOLD); - PangoAttribute attribute = new PangoAttribute (); - OS.memmove (attribute, boldAttr, PangoAttribute.sizeof); - attribute.start_index = 0; - attribute.end_index = buffer.length; - OS.memmove (boldAttr, attribute, PangoAttribute.sizeof); - int /*long*/ attrList = OS.pango_attr_list_new (); - OS.pango_attr_list_insert (attrList, boldAttr); - OS.pango_layout_set_attributes (layoutText, attrList); - OS.pango_attr_list_unref (attrList); - OS.pango_layout_set_wrap (layoutText, OS.PANGO_WRAP_WORD_CHAR); - } - if (OS.GTK_WIDGET_VISIBLE (handle)) configure (); -} - -/** - * 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 (timerId != 0) OS.gtk_timeout_remove(timerId); - timerId = 0; - if (visible) { - if ((style & SWT.BALLOON) != 0) { - configure (); - OS.gtk_widget_show (handle); - } else { - int /*long*/ vboxHandle = parent.vboxHandle; - StringBuffer string = new StringBuffer (text); - if (text.length () > 0) string.append ("\n\n"); - string.append (message); - byte [] buffer = Converter.wcsToMbcs (null, string.toString(), true); - OS.gtk_tooltips_set_tip (handle, vboxHandle, buffer, null); - int /*long*/ data = OS.gtk_tooltips_data_get (vboxHandle); - OS.GTK_TOOLTIPS_SET_ACTIVE (handle, data); - OS.gtk_tooltips_set_tip (handle, vboxHandle, buffer, null); - } - if (autohide) timerId = OS.gtk_timeout_add (DELAY, display.windowTimerProc, handle); - } else { - if ((style & SWT.BALLOON) != 0) { - OS.gtk_widget_hide (handle); - } else { - int /*long*/ tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (handle); - OS.gtk_widget_hide (tipWindow); - } - } -} - -int /*long*/ timerProc (int /*long*/ widget) { - if ((style & SWT.BALLOON) != 0) { - OS.gtk_widget_hide (handle); - } else { - int /*long*/ tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (handle); - OS.gtk_widget_hide (tipWindow); - } - return 0; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java deleted file mode 100644 index e5729d3980..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tracker.java +++ /dev/null @@ -1,996 +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.gtk.*; -import org.eclipse.swt.graphics.*; -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; - Cursor cursor; - int /*long*/ lastCursor, window; - boolean tracking, cancelled, grabbed, stippled; - Rectangle [] rectangles = new Rectangle [0], proportions = rectangles; - Rectangle bounds; - int cursorOrientation = SWT.NONE; - int 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; - int newX = bounds.x + bounds.width / 2; - int newY = bounds.y; - - Point point = display.map (parent, null, newX, newY); - display.setCursorLocation (point); - - /* - * 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. - */ - int [] actualX = new int [1], actualY = new int [1], state = new int [1]; - OS.gdk_window_get_pointer (window, actualX, actualY, state); - 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; - } - - Point point = display.map (parent, null, newX, newY); - display.setCursorLocation (point); - - /* - * 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. - */ - int [] actualX = new int [1], actualY = new int [1], state = new int [1]; - OS.gdk_window_get_pointer (window, actualX, actualY, state); - return new Point (actualX [0], actualY [0]); -} - - -/** - * 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; -} - -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; -} - -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) { - int /*long*/ window = OS.GDK_ROOT_PARENT (); - if (parent != null) { - window = OS.GTK_WIDGET_WINDOW (parent.paintHandle()); - } - if (window == 0) return; - int /*long*/ gc = OS.gdk_gc_new (window); - if (gc == 0) return; - int /*long*/ colormap = OS.gdk_colormap_get_system (); - GdkColor color = new GdkColor (); - OS.gdk_color_white (colormap, color); - OS.gdk_gc_set_foreground (gc, color); - OS.gdk_gc_set_subwindow (gc, OS.GDK_INCLUDE_INFERIORS); - OS.gdk_gc_set_function (gc, OS.GDK_XOR); - for (int i=0; i<rects.length; i++) { - Rectangle rect = rects [i]; - int x = rect.x; - if (parent != null && (parent.style & SWT.MIRRORED) != 0) x = parent.getClientWidth () - rect.width - x; - OS.gdk_draw_rectangle (window, gc, 0, x, rect.y, rect.width, rect.height); - } - OS.g_object_unref (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; -} - -boolean grab () { - int /*long*/ cursor = this.cursor != null ? this.cursor.handle : 0; - int result = OS.gdk_pointer_grab (window, false, OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_RELEASE_MASK, window, cursor, OS.GDK_CURRENT_TIME); - return result == OS.GDK_GRAB_SUCCESS; -} - -int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ event) { - return gtk_mouse (OS.GDK_BUTTON_RELEASE, widget, event); -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ eventPtr) { - int /*long*/ result = super.gtk_key_press_event (widget, eventPtr); - if (result != 0) return result; - GdkEventKey keyEvent = new GdkEventKey (); - OS.memmove (keyEvent, eventPtr, GdkEventKey.sizeof); - int stepSize = ((keyEvent.state & OS.GDK_CONTROL_MASK) != 0) ? STEPSIZE_SMALL : STEPSIZE_LARGE; - int xChange = 0, yChange = 0; - switch (keyEvent.keyval) { - case OS.GDK_Escape: - cancelled = true; - // fallthrough - case OS.GDK_Return: - tracking = false; - break; - case OS.GDK_Left: - xChange = -stepSize; - break; - case OS.GDK_Right: - xChange = stepSize; - break; - case OS.GDK_Up: - yChange = -stepSize; - break; - case OS.GDK_Down: - yChange = stepSize; - break; - } - if (xChange != 0 || yChange != 0) { - Rectangle [] oldRectangles = rectangles; - 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; - if (parent != null && (parent.style & SWT.MIRRORED) != 0) { - event.x = parent.getClientWidth () - event.width - event.x; - } - 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 return false to indicate - * that the tracking has 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); - update (); - drawRectangles (rectangles); - } - Point cursorPos = adjustResizeCursor (); - if (cursorPos != null) { - oldX = cursorPos.x; - oldY = cursorPos.y; - } - } 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 return false to indicate - * that the tracking has 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); - update (); - drawRectangles (rectangles); - } - Point cursorPos = adjustMoveCursor (); - if (cursorPos != null) { - oldX = cursorPos.x; - oldY = cursorPos.y; - } - } - } - return result; -} - -int /*long*/ gtk_motion_notify_event (int /*long*/ widget, int /*long*/ eventPtr) { - int /*long*/ cursor = this.cursor != null ? this.cursor.handle : 0; - if (cursor != lastCursor) { - ungrab (); - grabbed = grab (); - lastCursor = cursor; - } - return gtk_mouse (OS.GDK_MOTION_NOTIFY, widget, eventPtr); -} - -int /*long*/ gtk_mouse (int eventType, int /*long*/ widget, int /*long*/ eventPtr) { - int [] newX = new int [1], newY = new int [1]; - OS.gdk_window_get_pointer (window, newX, newY, null); - if (oldX != newX [0] || oldY != newY [0]) { - Rectangle [] oldRectangles = rectangles; - 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 (); - if (parent == null) { - event.x = newX [0]; - event.y = newY [0]; - } else { - Point screenCoord = display.map (parent, null, newX [0], newY [0]); - event.x = screenCoord.x; - event.y = screenCoord.y; - } - 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, return false to indicate - * that the tracking has 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); - update (); - drawRectangles (rectangles); - } - 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, return false to indicate - * that the tracking has 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); - update (); - drawRectangles (rectangles); - } - } - oldX = newX [0]; - oldY = newY [0]; - } - tracking = eventType != OS.GDK_BUTTON_RELEASE; - return 0; -} - -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; - if (parent != null && (parent.style & SWT.MIRRORED) != 0) xChange *= -1; - 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(); - window = OS.GDK_ROOT_PARENT (); - if (parent != null) { - window = OS.GTK_WIDGET_WINDOW (parent.paintHandle()); - } - if (window == 0) return false; - cancelled = false; - tracking = true; - update (); - drawRectangles (rectangles); - int [] oldX = new int [1], oldY = new int [1], state = new int [1]; - OS.gdk_window_get_pointer (window, oldX, oldY, state); - - /* - * 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 mask = OS.GDK_BUTTON1_MASK | OS.GDK_BUTTON2_MASK | OS.GDK_BUTTON3_MASK; - boolean mouseDown = (state [0] & mask) != 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]; - - grabbed = grab (); - lastCursor = this.cursor != null ? this.cursor.handle : 0; - - /* Tracker behaves like a Dialog with its own OS event loop. */ - GdkEvent gdkEvent = new GdkEvent(); - while (tracking) { - if (parent != null && parent.isDisposed ()) break; - int /*long*/ eventPtr; - while (true) { - eventPtr = OS.gdk_event_get (); - if (eventPtr != 0) { - break; - } else { - try { Thread.sleep(50); } catch (Exception ex) {} - } - } - OS.memmove (gdkEvent, eventPtr, GdkEvent.sizeof); - int /*long*/ widget = OS.gtk_get_event_widget (eventPtr); - switch (gdkEvent.type) { - case OS.GDK_MOTION_NOTIFY: gtk_motion_notify_event (widget, eventPtr); break; - case OS.GDK_BUTTON_RELEASE: gtk_button_release_event (widget, eventPtr); break; - case OS.GDK_KEY_PRESS: gtk_key_press_event (widget, eventPtr); break; - case OS.GDK_KEY_RELEASE: gtk_key_release_event (widget, eventPtr); break; - case OS.GDK_BUTTON_PRESS: - case OS.GDK_2BUTTON_PRESS: - case OS.GDK_3BUTTON_PRESS: - case OS.GDK_ENTER_NOTIFY: - case OS.GDK_LEAVE_NOTIFY: - /* Do not dispatch these */ - break; - case OS.GDK_EXPOSE: - update (); - drawRectangles (rectangles); - OS.gtk_main_do_event (eventPtr); - drawRectangles (rectangles); - break; - default: - OS.gtk_main_do_event (eventPtr); - } - OS.gdk_event_free (eventPtr); - } - if (!isDisposed ()) { - update (); - drawRectangles (rectangles); - } - ungrab (); - window = 0; - return !cancelled; -} - -void releaseWidget () { - super.releaseWidget (); - parent = null; - rectangles = proportions = null; - bounds = 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.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 resizeRectangles (int xChange, int yChange) { - if (bounds == null) return; - if (parent != null && (parent.style & SWT.MIRRORED) != 0) xChange *= -1; - /* - * 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); - int length = rectangles.length; - this.rectangles = new Rectangle [length]; - for (int i = 0; i < 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 ungrab () { - if (grabbed) OS.gdk_pointer_ungrab (OS.GDK_CURRENT_TIME); -} - -void update () { - if (parent != null) { - if (parent.isDisposed ()) return; - parent.getShell ().update (); - } else { - display.update (); - } -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java deleted file mode 100644 index 7d1fb1f17b..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TrayItem.java +++ /dev/null @@ -1,591 +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.events.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.gtk.*; - -/** - * Instances of this class represent icons that can be placed on the - * system tray or task bar status area. - * <p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>DefaultSelection, MenuDetect, Selection</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/#tray">Tray, TrayItem snippets</a> - * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> - * - * @since 3.0 - * @noextend This class is not intended to be subclassed by clients. - */ -public class TrayItem extends Item { - Tray parent; - ToolTip toolTip; - String toolTipText; - int /*long*/ imageHandle; - int /*long*/ tooltipsHandle; - ImageList imageList; - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Tray</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 - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TrayItem (Tray parent, int style) { - super (parent, style); - this.parent = parent; - createWidget (parent.getItemCount ()); -} - -/** - * 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 the receiver 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 receiver is selected - * <code>widgetDefaultSelected</code> is called when the receiver is double-clicked - * </p> - * - * @param listener the listener which should be notified when the receiver 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); -} - -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} - -void createWidget (int index) { - super.createWidget (index); - parent.createItem (this, index); -} - -void createHandle (int index) { - state |= HANDLE; - if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) { - handle = OS.gtk_status_icon_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - imageHandle = OS.gtk_image_new (); - OS.gtk_status_icon_set_visible (handle,true); - } else { - handle = OS.gtk_plug_new (0); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - imageHandle = OS.gtk_image_new (); - if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (handle, imageHandle); - OS.gtk_widget_show (handle); - OS.gtk_widget_show (imageHandle); - int /*long*/ id = OS.gtk_plug_get_id (handle); - int monitor = 0; - int /*long*/ screen = OS.gdk_screen_get_default (); - if (screen != 0) { - monitor = OS.gdk_screen_get_number (screen); - } - byte [] trayBuffer = Converter.wcsToMbcs (null, "_NET_SYSTEM_TRAY_S" + monitor, true); - int /*long*/ trayAtom = OS.gdk_atom_intern (trayBuffer, true); - int /*long*/ xTrayAtom = OS.gdk_x11_atom_to_xatom (trayAtom); - int /*long*/ xDisplay = OS.GDK_DISPLAY (); - int /*long*/ trayWindow = OS.XGetSelectionOwner (xDisplay, xTrayAtom); - byte [] messageBuffer = Converter.wcsToMbcs (null, "_NET_SYSTEM_TRAY_OPCODE", true); - int /*long*/ messageAtom = OS.gdk_atom_intern (messageBuffer, true); - int /*long*/ xMessageAtom = OS.gdk_x11_atom_to_xatom (messageAtom); - XClientMessageEvent event = new XClientMessageEvent (); - event.type = OS.ClientMessage; - event.window = trayWindow; - event.message_type = xMessageAtom; - event.format = 32; - event.data [0] = OS.GDK_CURRENT_TIME; - event.data [1] = OS.SYSTEM_TRAY_REQUEST_DOCK; - event.data [2] = id; - int /*long*/ clientEvent = OS.g_malloc (XClientMessageEvent.sizeof); - OS.memmove (clientEvent, event, XClientMessageEvent.sizeof); - OS.XSendEvent (xDisplay, trayWindow, false, OS.NoEventMask, clientEvent); - OS.g_free (clientEvent); - } -} - -void deregister () { - super.deregister (); - display.removeWidget (imageHandle); -} - -void destroyWidget () { - parent.destroyItem (this); - releaseHandle (); -} - -/** - * Returns the receiver's parent, which must be a <code>Tray</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> - * - * @since 3.2 - */ -public Tray getParent () { - checkWidget (); - return parent; -} - -/** - * Returns the receiver's tool tip, 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> - * - * @since 3.2 - */ -public ToolTip getToolTip () { - checkWidget (); - return toolTip; -} - -/** - * 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; -} - -int /*long*/ gtk_activate (int /*long*/ widget) { - postEvent (SWT.Selection); - /* - * Feature in GTK. GTK will generate a single-click event before sending - * a double-click event. To know when to send a DefaultSelection, look for - * the single-click as the current event and for the double-click in the - * event queue. - */ - int /*long*/ nextEvent = OS.gdk_event_peek (); - if (nextEvent != 0) { - int nextEventType = OS.GDK_EVENT_TYPE (nextEvent); - int /*long*/ currEvent = OS.gtk_get_current_event (); - int currEventType = 0; - if (currEvent != 0) { - currEventType = OS.GDK_EVENT_TYPE (currEvent); - OS.gdk_event_free (currEvent); - } - OS.gdk_event_free (nextEvent); - if (currEventType == OS.GDK_BUTTON_PRESS && nextEventType == OS.GDK_2BUTTON_PRESS) { - postEvent (SWT.DefaultSelection); - } - } - return 0; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ eventPtr) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, eventPtr, GdkEventButton.sizeof); - if (gdkEvent.type == OS.GDK_3BUTTON_PRESS) return 0; - if (gdkEvent.button == 3 && gdkEvent.type == OS.GDK_BUTTON_PRESS) { - sendEvent (SWT.MenuDetect); - return 0; - } - if (gdkEvent.type == OS.GDK_2BUTTON_PRESS) { - postEvent (SWT.DefaultSelection); - } else { - postEvent (SWT.Selection); - } - return 0; -} - -int /*long*/ gtk_size_allocate (int /*long*/ widget, int /*long*/ allocation) { - if (image != null && image.mask != 0) { - if (OS.gdk_drawable_get_depth (image.mask) == 1) { - int xoffset = (int) Math.floor (OS.GTK_WIDGET_X (widget) + ((OS.GTK_WIDGET_WIDTH (widget) - OS.GTK_WIDGET_REQUISITION_WIDTH (widget)) * 0.5) + 0.5); - int yoffset = (int) Math.floor (OS.GTK_WIDGET_Y (widget) + ((OS.GTK_WIDGET_HEIGHT (widget) - OS.GTK_WIDGET_REQUISITION_HEIGHT (widget)) * 0.5) + 0.5); - Rectangle b = image.getBounds(); - int /*long*/ gdkImagePtr = OS.gdk_drawable_get_image (image.mask, 0, 0, b.width, b.height); - if (gdkImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES); - GdkImage gdkImage = new GdkImage(); - OS.memmove (gdkImage, gdkImagePtr); - byte[] maskData = new byte [gdkImage.bpl * gdkImage.height]; - OS.memmove (maskData, gdkImage.mem, maskData.length); - OS.g_object_unref (gdkImagePtr); - Region region = new Region (display); - for (int y = 0; y < b.height; y++) { - for (int x = 0; x < b.width; x++) { - int index = (y * gdkImage.bpl) + (x >> 3); - int theByte = maskData [index] & 0xFF; - int mask = 1 << (x & 0x7); - if ((theByte & mask) != 0) { - region.add (xoffset + x, yoffset + y, 1, 1); - } - } - } - OS.gtk_widget_realize (handle); - int /*long*/ window = OS.GTK_WIDGET_WINDOW (handle); - OS.gdk_window_shape_combine_region (window, region.handle, 0, 0); - region.dispose (); - } - } - return 0; -} - -int /*long*/ gtk_status_icon_popup_menu (int /*long*/ widget, int /*long*/ button, int /*long*/ activate_time) { - sendEvent (SWT.MenuDetect); - return 0; -} - -void hookEvents () { - if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) { - OS.g_signal_connect_closure (handle, OS.activate, display.closures [ACTIVATE], false); - OS.g_signal_connect_closure (handle, OS.popup_menu, display.closures [STATUS_ICON_POPUP_MENU], false); - } else { - int eventMask = OS.GDK_BUTTON_PRESS_MASK; - OS.gtk_widget_add_events (handle, eventMask); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false); - OS.g_signal_connect_closure_by_id (imageHandle, display.signalIds [SIZE_ALLOCATE], 0, display.closures [SIZE_ALLOCATE], false); - } -} - -/** - * Returns <code>true</code> if the receiver is visible and - * <code>false</code> otherwise. - * - * @return the receiver's visibility - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) { - return OS.gtk_status_icon_get_visible (handle); - } - return OS.GTK_WIDGET_VISIBLE (handle); -} - -void register () { - super.register (); - display.addWidget (imageHandle, this); -} - -void releaseHandle () { - if (handle != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) { - OS.g_object_unref (handle); - } else { - OS.gtk_widget_destroy (handle); - } - } - handle = imageHandle = 0; - super.releaseHandle (); - parent = null; -} - -void releaseWidget () { - super.releaseWidget (); - if (tooltipsHandle != 0) OS.g_object_unref (tooltipsHandle); - tooltipsHandle = 0; - if (imageList != null) imageList.dispose (); - imageList = null; - toolTipText = null; -} - -/** - * 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 the receiver 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); -} - -/** - * Sets the receiver's image. - * - * @param image the new image - * - * @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; - if (image != null) { - if (imageList == null) imageList = new ImageList (); - int imageIndex = imageList.indexOf (image); - if (imageIndex == -1) { - imageIndex = imageList.add (image); - } else { - imageList.put (imageIndex, image); - } - int /*long*/ pixbuf = imageList.getPixbuf (imageIndex); - if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) { - OS.gtk_status_icon_set_from_pixbuf (handle, pixbuf); - OS.gtk_status_icon_set_visible (handle, true); - } else { - Rectangle rect = image.getBounds (); - OS.gtk_widget_set_size_request (handle, rect.width, rect.height); - OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); - OS.gtk_widget_show (imageHandle); - } - } else { - OS.gtk_widget_set_size_request (handle, 1, 1); - if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) { - OS.gtk_status_icon_set_from_pixbuf (handle, 0); - OS.gtk_status_icon_set_visible (handle, false); - } else { - OS.gtk_image_set_from_pixbuf (imageHandle, 0); - OS.gtk_widget_hide (imageHandle); - } - } -} - -/** - * Sets the receiver's tool tip to the argument, which - * may be null indicating that no tool tip should be shown. - * - * @param toolTip the new tool tip (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.2 - */ -public void setToolTip (ToolTip toolTip) { - checkWidget (); - ToolTip oldTip = this.toolTip, newTip = toolTip; - if (oldTip != null) oldTip.item = null; - this.toolTip = newTip; - if (newTip != null) newTip.item = this; -} - -/** - * 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; - byte [] buffer = null; - if (string != null && string.length () > 0) { - buffer = Converter.wcsToMbcs (null, string, true); - } - if (tooltipsHandle == 0) { - tooltipsHandle = OS.gtk_tooltips_new (); - if (tooltipsHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.g_object_ref (tooltipsHandle); - OS.gtk_object_sink (tooltipsHandle); - } - if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) { - OS.gtk_status_icon_set_tooltip (handle, buffer); - } else - OS.gtk_tooltips_set_tip (tooltipsHandle, handle, buffer, null); -} - -/** - * Makes the receiver visible if the argument is <code>true</code>, - * and makes it invisible otherwise. - * - * @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 (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) { - if(OS.gtk_status_icon_get_visible (handle) == visible) return; - } else { - if (OS.GTK_WIDGET_VISIBLE (handle) == visible) return; - } - if (visible) { - /* - * It is possible (but unlikely), that application - * code could have disposed the widget in the show - * event. If this happens, just return. - */ - sendEvent (SWT.Show); - if (isDisposed ()) return; - if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) { - OS.gtk_status_icon_set_visible (handle, visible); - } else - OS.gtk_widget_show (handle); - } else { - if (OS.GTK_VERSION >= OS.VERSION (2, 10, 0)) { - OS.gtk_status_icon_set_visible (handle, visible); - } else - OS.gtk_widget_hide (handle); - sendEvent (SWT.Hide); - } -} -}
\ No newline at end of file diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java deleted file mode 100644 index e6a26ce1b0..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java +++ /dev/null @@ -1,3385 +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.gtk.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class provide a selectable user interface object - * that displays a hierarchy of items and issues notification when an - * item in the hierarchy is selected. - * <p> - * The item children that may be added to instances of this class - * must be of type <code>TreeItem</code>. - * </p><p> - * Style <code>VIRTUAL</code> is used to create a <code>Tree</code> whose - * <code>TreeItem</code>s are to be populated by the client on an on-demand basis - * instead of up-front. This can provide significant performance improvements for - * trees that are very large or for which <code>TreeItem</code> population is - * expensive (for example, retrieving values from an external source). - * </p><p> - * Here is an example of using a <code>Tree</code> with style <code>VIRTUAL</code>: - * <code><pre> - * final Tree tree = new Tree(parent, SWT.VIRTUAL | SWT.BORDER); - * tree.setItemCount(20); - * tree.addListener(SWT.SetData, new Listener() { - * public void handleEvent(Event event) { - * TreeItem item = (TreeItem)event.item; - * TreeItem parentItem = item.getParentItem(); - * String text = null; - * if (parentItem == null) { - * text = "node " + tree.indexOf(item); - * } else { - * text = parentItem.getText() + " - " + parentItem.indexOf(item); - * } - * item.setText(text); - * System.out.println(text); - * item.setItemCount(10); - * } - * }); - * </pre></code> - * </p><p> - * Note that although this class is a subclass of <code>Composite</code>, - * it does not normally make sense to add <code>Control</code> children to - * it, or set a layout on it, unless implementing something like a cell - * editor. - * </p><p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>SINGLE, MULTI, CHECK, FULL_SELECTION, VIRTUAL, NO_SCROLL</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection, DefaultSelection, Collapse, Expand, SetData, MeasureItem, EraseItem, PaintItem</dd> - * </dl> - * </p><p> - * Note: Only one of the styles 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/#tree">Tree, TreeItem, TreeColumn 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 Tree extends Composite { - int /*long*/ modelHandle, checkRenderer; - int columnCount, sortDirection; - int /*long*/ ignoreCell; - TreeItem[] items; - TreeColumn [] columns; - TreeColumn sortColumn; - TreeItem currentItem; - ImageList imageList, headerImageList; - boolean firstCustomDraw; - boolean modelChanged; - boolean expandAll; - int drawState, drawFlags; - GdkColor drawForeground; - boolean ownerDraw, ignoreSize, ignoreAccessibility; - - static final int ID_COLUMN = 0; - static final int CHECKED_COLUMN = 1; - static final int GRAYED_COLUMN = 2; - static final int FOREGROUND_COLUMN = 3; - static final int BACKGROUND_COLUMN = 4; - static final int FONT_COLUMN = 5; - static final int FIRST_COLUMN = FONT_COLUMN + 1; - static final int CELL_PIXBUF = 0; - static final int CELL_TEXT = 1; - static final int CELL_FOREGROUND = 2; - static final int CELL_BACKGROUND = 3; - static final int CELL_FONT = 4; - static final int CELL_TYPES = CELL_FONT + 1; - -/** - * 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#CHECK - * @see SWT#FULL_SELECTION - * @see SWT#VIRTUAL - * @see SWT#NO_SCROLL - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Tree (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -void _addListener (int eventType, Listener listener) { - super._addListener (eventType, listener); - if (!ownerDraw) { - switch (eventType) { - case SWT.MeasureItem: - case SWT.EraseItem: - case SWT.PaintItem: - ownerDraw = true; - recreateRenderers (); - break; - } - } -} - -TreeItem _getItem (int /*long*/ iter) { - int id = getId (iter, true); - if (items [id] != null) return items [id]; - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter); - int depth = OS.gtk_tree_path_get_depth (path); - int [] indices = new int [depth]; - OS.memmove (indices, OS.gtk_tree_path_get_indices (path), 4*depth); - int /*long*/ parentIter = 0; - if (depth > 1) { - OS.gtk_tree_path_up (path); - parentIter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - OS.gtk_tree_model_get_iter (modelHandle, parentIter, path); - } - items [id] = new TreeItem (this, parentIter, SWT.NONE, indices [indices.length -1], false); - OS.gtk_tree_path_free (path); - if (parentIter != 0) OS.g_free (parentIter); - return items [id]; -} - -TreeItem _getItem (int /*long*/ parentIter, int index) { - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - OS.gtk_tree_model_iter_nth_child(modelHandle, iter, parentIter, index); - int id = getId (iter, true); - OS.g_free (iter); - if (items [id] != null) return items [id]; - return items [id] = new TreeItem (this, parentIter, SWT.NONE, index, false); -} - -int getId (int /*long*/ iter, boolean queryModel) { - if (queryModel) { - int[] value = new int[1]; - OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, value, -1); - if (value [0] != -1) return value [0]; - } - // find next available id - int id = 0; - while (id < items.length && items [id] != null) id++; - if (id == items.length) { - TreeItem [] newItems = new TreeItem [items.length + 4]; - System.arraycopy (items, 0, newItems, 0, items.length); - items = newItems; - } - OS.gtk_tree_store_set (modelHandle, iter, ID_COLUMN, id, -1); - return id; -} - -static int checkStyle (int style) { - /* - * Feature in Windows. Even when WS_HSCROLL or - * WS_VSCROLL is not specified, Windows creates - * trees and tables with scroll bars. The fix - * is to set H_SCROLL and V_SCROLL. - * - * NOTE: This code appears on all platforms so that - * applications have consistent scroll bar behavior. - */ - if ((style & SWT.NO_SCROLL) == 0) { - style |= SWT.H_SCROLL | SWT.V_SCROLL; - } - /* GTK is always FULL_SELECTION */ - style |= SWT.FULL_SELECTION; - return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0); -} - -int /*long*/ cellDataProc (int /*long*/ tree_column, int /*long*/ cell, int /*long*/ tree_model, int /*long*/ iter, int /*long*/ data) { - if (cell == ignoreCell) return 0; - TreeItem item = _getItem (iter); - if (item != null) OS.g_object_set_qdata (cell, Display.SWT_OBJECT_INDEX2, item.handle); - boolean isPixbuf = OS.GTK_IS_CELL_RENDERER_PIXBUF (cell); - if (!(isPixbuf || OS.GTK_IS_CELL_RENDERER_TEXT (cell))) return 0; - int modelIndex = -1; - boolean customDraw = false; - if (columnCount == 0) { - modelIndex = Tree.FIRST_COLUMN; - customDraw = firstCustomDraw; - } else { - TreeColumn column = (TreeColumn) display.getWidget (tree_column); - if (column != null) { - modelIndex = column.modelIndex; - customDraw = column.customDraw; - } - } - if (modelIndex == -1) return 0; - boolean setData = false; - if ((style & SWT.VIRTUAL) != 0) { - /* - * Feature in GTK. On GTK before 2.4, fixed_height_mode is not - * supported, and the tree asks for the data of all items. The - * fix is to only provide the data if the row is visible. - */ - if (OS.GTK_VERSION < OS.VERSION (2, 3, 2)) { - int /*long*/ path = OS.gtk_tree_model_get_path (tree_model, iter); - OS.gtk_widget_realize (handle); - GdkRectangle visible = new GdkRectangle (); - OS.gtk_tree_view_get_visible_rect (handle, visible); - GdkRectangle area = new GdkRectangle (); - OS.gtk_tree_view_get_cell_area (handle, path, tree_column, area); - OS.gtk_tree_path_free (path); - if (area.y + area.height < 0 || area.y + visible.y > visible.y + visible.height ) { - /* Give an image from the image list to make sure the row has - * the correct height. - */ - if (imageList != null && imageList.pixbufs.length > 0) { - if (isPixbuf) OS.g_object_set (cell, OS.pixbuf, imageList.pixbufs [0], 0); - } - return 0; - } - } - if (!item.cached) { - //lastIndexOf = index [0]; - setData = checkData (item); - } - } - int /*long*/ [] ptr = new int /*long*/ [1]; - if (setData) { - if (isPixbuf) { - ptr [0] = 0; - OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_PIXBUF, ptr, -1); - OS.g_object_set (cell, OS.pixbuf, ptr[0], 0); - } else { - ptr [0] = 0; - OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_TEXT, ptr, -1); - if (ptr [0] != 0) { - OS.g_object_set (cell, OS.text, ptr[0], 0); - OS.g_free (ptr[0]); - } - } - } - if (customDraw) { - /* - * Bug on GTK. Gtk renders the background on top of the checkbox and pixbuf. - * This only happens in version 2.2.1 and earlier. The fix is not to set the background. - */ - if (OS.GTK_VERSION > OS.VERSION (2, 2, 1)) { - if (!ownerDraw) { - ptr [0] = 0; - OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_BACKGROUND, ptr, -1); - if (ptr [0] != 0) { - OS.g_object_set (cell, OS.cell_background_gdk, ptr[0], 0); - } - } - } - if (!isPixbuf) { - ptr [0] = 0; - OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_FOREGROUND, ptr, -1); - if (ptr [0] != 0) { - OS.g_object_set (cell, OS.foreground_gdk, ptr[0], 0); - } - ptr [0] = 0; - OS.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_FONT, ptr, -1); - if (ptr [0] != 0) { - OS.g_object_set (cell, OS.font_desc, ptr[0], 0); - } - } - } - if (setData) { - ignoreCell = cell; - setScrollWidth (tree_column, item); - ignoreCell = 0; - } - return 0; -} - -boolean checkData (TreeItem item) { - if (item.cached) return true; - if ((style & SWT.VIRTUAL) != 0) { - item.cached = true; - TreeItem parentItem = item.getParentItem (); - Event event = new Event (); - event.item = item; - event.index = parentItem == null ? indexOf (item) : parentItem.indexOf (item); - int mask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID; - int signal_id = OS.g_signal_lookup (OS.row_changed, OS.gtk_tree_model_get_type ()); - OS.g_signal_handlers_block_matched (modelHandle, mask, signal_id, 0, 0, 0, handle); - currentItem = item; - sendEvent (SWT.SetData, event); - currentItem = null; - //widget could be disposed at this point - if (isDisposed ()) return false; - OS.g_signal_handlers_unblock_matched (modelHandle, mask, signal_id, 0, 0, 0, handle); - if (item.isDisposed ()) return false; - } - return true; -} - -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} - -/** - * 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> - * When <code>widgetSelected</code> is called, the item field of the event object is valid. - * If the receiver has the <code>SWT.CHECK</code> style and the check selection changes, - * the event object detail field contains the value <code>SWT.CHECK</code>. - * <code>widgetDefaultSelected</code> is typically called when an item is double-clicked. - * The item field of the event object is valid for default selection, but the detail field is not used. - * </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); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when an item in the receiver is expanded or collapsed - * by sending it one of the messages defined in the <code>TreeListener</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 TreeListener - * @see #removeTreeListener - */ -public void addTreeListener(TreeListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Expand, typedListener); - addListener (SWT.Collapse, typedListener); -} - -int calculateWidth (int /*long*/ column, int /*long*/ iter, boolean recurse) { - OS.gtk_tree_view_column_cell_set_cell_data (column, modelHandle, iter, false, false); - /* - * Bug in GTK. The width calculated by gtk_tree_view_column_cell_get_size() - * always grows in size regardless of the text or images in the table. - * The fix is to determine the column width from the cell renderers. - */ - // Code intentionally commented - //int [] width = new int [1]; - //OS.gtk_tree_view_column_cell_get_size (column, null, null, null, width, null); - //return width [0]; - - int width = 0; - int [] w = new int [1]; - int /*long*/ path = 0; - - if (OS.gtk_tree_view_get_expander_column (handle) == column) { - /* indent */ - GdkRectangle rect = new GdkRectangle (); - OS.gtk_widget_realize (handle); - path = OS.gtk_tree_model_get_path (modelHandle, iter); - OS.gtk_tree_view_get_cell_area (handle, path, column, rect); - width += rect.x; - /* expander */ - OS.gtk_widget_style_get (handle, OS.expander_size, w, 0); - width += w [0] + TreeItem.EXPANDER_EXTRA_PADDING; - } - OS.gtk_widget_style_get(handle, OS.focus_line_width, w, 0); - width += 2 * w [0]; - int /*long*/ list = OS.gtk_tree_view_column_get_cell_renderers (column); - if (list == 0) return 0; - int /*long*/ temp = list; - while (temp != 0) { - int /*long*/ renderer = OS.g_list_data (temp); - if (renderer != 0) { - OS.gtk_cell_renderer_get_size (renderer, handle, null, null, null, w, null); - width += w [0]; - } - temp = OS.g_list_next (temp); - } - OS.g_list_free (list); - - if (recurse) { - if (path == 0) path = OS.gtk_tree_model_get_path (modelHandle, iter); - boolean expanded = OS.gtk_tree_view_row_expanded (handle, path); - if (expanded) { - int /*long*/ childIter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - boolean valid = OS.gtk_tree_model_iter_children (modelHandle, childIter, iter); - while (valid) { - width = Math.max (width, calculateWidth (column, childIter, true)); - valid = OS.gtk_tree_model_iter_next (modelHandle, childIter); - } - OS.g_free (childIter); - } - } - - if (path != 0) OS.gtk_tree_path_free (path); - if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0) && OS.gtk_tree_view_get_rules_hint (handle)) { - OS.gtk_widget_style_get (handle, OS.grid_line_width, w, 0) ; - width += 2 * w [0]; - } - return width; -} - -/** - * Clears the item at the given zero-relative index in the receiver. - * The text, icon and other attributes of the item are set to the default - * value. If the tree was created with the <code>SWT.VIRTUAL</code> style, - * these attributes are requested again as needed. - * - * @param index the index of the item to clear - * @param all <code>true</code> if all child items of the indexed item should be - * cleared recursively, and <code>false</code> otherwise - * - * @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> - * - * @see SWT#VIRTUAL - * @see SWT#SetData - * - * @since 3.2 - */ -public void clear(int index, boolean all) { - checkWidget (); - clear (0, index, all); -} - -void clear (int /*long*/ parentIter, int index, boolean all) { - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - OS.gtk_tree_model_iter_nth_child(modelHandle, iter, parentIter, index); - int[] value = new int[1]; - OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, value, -1); - if (value [0] != -1) { - TreeItem item = items [value [0]]; - item.clear (); - } - if (all) clearAll (all, iter); - OS.g_free (iter); -} - -/** - * Clears all the items in the receiver. The text, icon and other - * attributes of the items are set to their default values. If the - * tree was created with the <code>SWT.VIRTUAL</code> style, these - * attributes are requested again as needed. - * - * @param all <code>true</code> if all child items should be cleared - * recursively, 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 SWT#VIRTUAL - * @see SWT#SetData - * - * @since 3.2 - */ -public void clearAll (boolean all) { - checkWidget (); - clearAll (all, 0); -} -void clearAll (boolean all, int /*long*/ parentIter) { - int length = OS.gtk_tree_model_iter_n_children (modelHandle, parentIter); - if (length == 0) return; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - boolean valid = OS.gtk_tree_model_iter_children (modelHandle, iter, parentIter); - int[] value = new int[1]; - while (valid) { - OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, value, -1); - if (value [0] != -1) { - TreeItem item = items [value [0]]; - item.clear (); - } - if (all) clearAll (all, iter); - valid = OS.gtk_tree_model_iter_next (modelHandle, iter); - } - OS.g_free (iter); -} - -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; - Point size = computeNativeSize (handle, wHint, hHint, changed); - Rectangle trim = computeTrim (0, 0, size.x, size.y); - size.x = trim.width; - size.y = trim.height; - return size; -} - -void copyModel (int /*long*/ oldModel, int oldStart, int /*long*/ newModel, int newStart, int /*long*/ [] types, int /*long*/ oldParent, int /*long*/ newParent, int modelLength) { - int /*long*/ iter = OS.g_malloc(OS.GtkTreeIter_sizeof ()); - if (OS.gtk_tree_model_iter_children (oldModel, iter, oldParent)) { - int /*long*/ [] oldItems = new int /*long*/ [OS.gtk_tree_model_iter_n_children (oldModel, oldParent)]; - int oldIndex = 0; - do { - int /*long*/ newItem = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (newItem == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_tree_store_append (newModel, newItem, newParent); - int [] index = new int [1]; - OS.gtk_tree_model_get (oldModel, iter, ID_COLUMN, index, -1); - TreeItem item = null; - if (index [0] != -1) { - item = items [index [0]]; - if (item != null) { - int /*long*/ oldItem = item.handle; - oldItems[oldIndex++] = oldItem; - int /*long*/ [] ptr = new int /*long*/ [1]; - for (int j = 0; j < FIRST_COLUMN; j++) { - OS.gtk_tree_model_get (oldModel, oldItem, j, ptr, -1); - OS.gtk_tree_store_set (newModel, newItem, j, ptr [0], -1); - if (types [j] == OS.G_TYPE_STRING ()) OS.g_free ((ptr [0])); - } - for (int j= 0; j<modelLength - FIRST_COLUMN; j++) { - OS.gtk_tree_model_get (oldModel, oldItem, oldStart + j, ptr, -1); - OS.gtk_tree_store_set (newModel, newItem, newStart + j, ptr [0], -1); - if (types [j] == OS.G_TYPE_STRING ()) OS.g_free ((ptr [0])); - } - } - } else { - OS.gtk_tree_store_set (newModel, newItem, ID_COLUMN, -1, -1); - } - // recurse through children - copyModel(oldModel, oldStart, newModel, newStart, types, iter, newItem, modelLength); - - if (item!= null) { - item.handle = newItem; - } else { - OS.g_free (newItem); - } - } while (OS.gtk_tree_model_iter_next(oldModel, iter)); - for (int i = 0; i < oldItems.length; i++) { - int /*long*/ oldItem = oldItems [i]; - if (oldItem != 0) { - OS.gtk_tree_store_remove (oldModel, oldItem); - OS.g_free (oldItem); - } - } - } - OS.g_free (iter); -} - -void createColumn (TreeColumn column, int index) { -/* -* Bug in ATK. For some reason, ATK segments fault if -* the GtkTreeView has a column and does not have items. -* The fix is to insert the column only when an item is -* created. -*/ - - int modelIndex = FIRST_COLUMN; - if (columnCount != 0) { - int modelLength = OS.gtk_tree_model_get_n_columns (modelHandle); - boolean [] usedColumns = new boolean [modelLength]; - for (int i=0; i<columnCount; i++) { - int columnIndex = columns [i].modelIndex; - for (int j = 0; j < CELL_TYPES; j++) { - usedColumns [columnIndex + j] = true; - } - } - while (modelIndex < modelLength) { - if (!usedColumns [modelIndex]) break; - modelIndex++; - } - if (modelIndex == modelLength) { - int /*long*/ oldModel = modelHandle; - int /*long*/[] types = getColumnTypes (columnCount + 4); // grow by 4 rows at a time - int /*long*/ newModel = OS.gtk_tree_store_newv (types.length, types); - if (newModel == 0) error (SWT.ERROR_NO_HANDLES); - copyModel (oldModel, FIRST_COLUMN, newModel, FIRST_COLUMN, types, (int /*long*/)0, (int /*long*/)0, modelLength); - OS.gtk_tree_view_set_model (handle, newModel); - OS.g_object_unref (oldModel); - modelHandle = newModel; - } - } - int /*long*/ columnHandle = OS.gtk_tree_view_column_new (); - if (columnHandle == 0) error (SWT.ERROR_NO_HANDLES); - if (index == 0 && columnCount > 0) { - TreeColumn checkColumn = columns [0]; - createRenderers (checkColumn.handle, checkColumn.modelIndex, false, checkColumn.style); - } - createRenderers (columnHandle, modelIndex, index == 0, column == null ? 0 : column.style); - /* - * Use GTK_TREE_VIEW_COLUMN_GROW_ONLY on GTK versions < 2.3.2 - * because fixed_height_mode is not supported. - */ - boolean useVirtual = (style & SWT.VIRTUAL) != 0 && OS.GTK_VERSION >= OS.VERSION (2, 3, 2); - if (!useVirtual && columnCount == 0) { - OS.gtk_tree_view_column_set_sizing (columnHandle, OS.GTK_TREE_VIEW_COLUMN_GROW_ONLY); - } else { - OS.gtk_tree_view_column_set_sizing (columnHandle, OS.GTK_TREE_VIEW_COLUMN_FIXED); - if (columnCount != 0) OS.gtk_tree_view_column_set_visible (columnHandle, false); - } - OS.gtk_tree_view_column_set_resizable (columnHandle, true); - OS.gtk_tree_view_column_set_clickable (columnHandle, true); - OS.gtk_tree_view_column_set_min_width (columnHandle, 0); - OS.gtk_tree_view_insert_column (handle, columnHandle, index); - if (column != null) { - column.handle = columnHandle; - column.modelIndex = modelIndex; - } - /* Disable searching when using VIRTUAL */ - if ((style & SWT.VIRTUAL) != 0) { - /* - * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE) - * would prevent the user from being able to type in text to search the tree. - * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive - * search. This meant that even if FALSE was passed to enable_search, the user - * can still bring up the search pop up using the keybinding. GTK also introduced - * the notion of passing a -1 to gtk_set_search_column to disable searching - * (including the search key binding). The fix is to use the right calls - * for the right version. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 5)) { - OS.gtk_tree_view_set_search_column (handle, -1); - } else { - OS.gtk_tree_view_set_enable_search (handle, false); - } - } else { - /* Set the search column whenever the model changes */ - int firstColumn = columnCount == 0 ? FIRST_COLUMN : columns [0].modelIndex; - OS.gtk_tree_view_set_search_column (handle, firstColumn + CELL_TEXT); - } -} - -void createHandle (int index) { - state |= HANDLE; - fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_fixed_set_has_window (fixedHandle, true); - scrolledHandle = OS.gtk_scrolled_window_new (0, 0); - if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ [] types = getColumnTypes (1); - modelHandle = OS.gtk_tree_store_newv (types.length, types); - if (modelHandle == 0) error (SWT.ERROR_NO_HANDLES); - handle = OS.gtk_tree_view_new_with_model (modelHandle); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - if ((style & SWT.CHECK) != 0) { - checkRenderer = OS.gtk_cell_renderer_toggle_new (); - if (checkRenderer == 0) error (SWT.ERROR_NO_HANDLES); - OS.g_object_ref (checkRenderer); - } - createColumn (null, 0); - OS.gtk_container_add (fixedHandle, scrolledHandle); - OS.gtk_container_add (scrolledHandle, handle); - - int mode = (style & SWT.MULTI) != 0 ? OS.GTK_SELECTION_MULTIPLE : OS.GTK_SELECTION_BROWSE; - int /*long*/ selectionHandle = OS.gtk_tree_view_get_selection (handle); - OS.gtk_tree_selection_set_mode (selectionHandle, mode); - OS.gtk_tree_view_set_headers_visible (handle, false); - int hsp = (style & SWT.H_SCROLL) != 0 ? OS.GTK_POLICY_AUTOMATIC : OS.GTK_POLICY_NEVER; - int vsp = (style & SWT.V_SCROLL) != 0 ? OS.GTK_POLICY_AUTOMATIC : OS.GTK_POLICY_NEVER; - OS.gtk_scrolled_window_set_policy (scrolledHandle, hsp, vsp); - if ((style & SWT.BORDER) != 0) OS.gtk_scrolled_window_set_shadow_type (scrolledHandle, OS.GTK_SHADOW_ETCHED_IN); - /* Disable searching when using VIRTUAL */ - if ((style & SWT.VIRTUAL) != 0) { - /* The fixed_height_mode property only exists in GTK 2.3.2 and greater */ - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2)) { - OS.g_object_set (handle, OS.fixed_height_mode, true, 0); - } - /* - * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE) - * would prevent the user from being able to type in text to search the tree. - * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive - * search. This meant that even if FALSE was passed to enable_search, the user - * can still bring up the search pop up using the keybinding. GTK also introduced - * the notion of passing a -1 to gtk_set_search_column to disable searching - * (including the search key binding). The fix is to use the right calls - * for the right version. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 5)) { - OS.gtk_tree_view_set_search_column (handle, -1); - } else { - OS.gtk_tree_view_set_enable_search (handle, false); - }; - } -} - -void createItem (TreeColumn column, int index) { - if (!(0 <= index && index <= columnCount)) error (SWT.ERROR_INVALID_RANGE); - if (index == 0) { - // first column must be left aligned - column.style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER); - column.style |= SWT.LEFT; - } - if (columnCount == 0) { - column.handle = OS.gtk_tree_view_get_column (handle, 0); - OS.gtk_tree_view_column_set_sizing (column.handle, OS.GTK_TREE_VIEW_COLUMN_FIXED); - OS.gtk_tree_view_column_set_visible (column.handle, false); - column.modelIndex = FIRST_COLUMN; - createRenderers (column.handle, column.modelIndex, true, column.style); - column.customDraw = firstCustomDraw; - firstCustomDraw = false; - } else { - createColumn (column, index); - } - int /*long*/ boxHandle = OS.gtk_hbox_new (false, 3); - if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ labelHandle = OS.gtk_label_new_with_mnemonic (null); - if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ imageHandle = OS.gtk_image_new (); - if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (boxHandle, imageHandle); - OS.gtk_container_add (boxHandle, labelHandle); - OS.gtk_widget_show (boxHandle); - OS.gtk_widget_show (labelHandle); - column.labelHandle = labelHandle; - column.imageHandle = imageHandle; - OS.gtk_tree_view_column_set_widget (column.handle, boxHandle); - int /*long*/ widget = OS.gtk_widget_get_parent (boxHandle); - while (widget != handle) { - if (OS.GTK_IS_BUTTON (widget)) { - column.buttonHandle = widget; - break; - } - widget = OS.gtk_widget_get_parent (widget); - } - if (columnCount == columns.length) { - TreeColumn [] newColumns = new TreeColumn [columns.length + 4]; - System.arraycopy (columns, 0, newColumns, 0, columns.length); - columns = newColumns; - } - System.arraycopy (columns, index, columns, index + 1, columnCount++ - index); - columns [index] = column; - if ((state & FONT) != 0) { - column.setFontDescription (getFontDescription ()); - } - if (columnCount >= 1) { - for (int i=0; i<items.length; i++) { - TreeItem item = items [i]; - if (item != null) { - Font [] cellFont = item.cellFont; - if (cellFont != null) { - Font [] temp = new Font [columnCount]; - System.arraycopy (cellFont, 0, temp, 0, index); - System.arraycopy (cellFont, index, temp, index+1, columnCount-index-1); - item.cellFont = temp; - } - } - } - } -} - -void createItem (TreeItem item, int /*long*/ parentIter, int index) { - int count = OS.gtk_tree_model_iter_n_children (modelHandle, parentIter); - if (index == -1) index = count; - if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE); - item.handle = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (item.handle == 0) error(SWT.ERROR_NO_HANDLES); - /* - * Feature in GTK. It is much faster to append to a tree store - * than to insert at the end using gtk_tree_store_insert(). - */ - if (index == count) { - OS.gtk_tree_store_append (modelHandle, item.handle, parentIter); - } else { - OS.gtk_tree_store_insert (modelHandle, item.handle, parentIter, index); - } - int id = getId (item.handle, false); - items [id] = item; - modelChanged = true; -} - -void createRenderers (int /*long*/ columnHandle, int modelIndex, boolean check, int columnStyle) { - OS.gtk_tree_view_column_clear (columnHandle); - if ((style & SWT.CHECK) != 0 && check) { - OS.gtk_tree_view_column_pack_start (columnHandle, checkRenderer, false); - OS.gtk_tree_view_column_add_attribute (columnHandle, checkRenderer, OS.active, CHECKED_COLUMN); - /* - * Feature in GTK. The inconsistent property only exists in GTK 2.2.x. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 2, 0)) { - OS.gtk_tree_view_column_add_attribute (columnHandle, checkRenderer, OS.inconsistent, GRAYED_COLUMN); - } - /* - * Bug in GTK. GTK renders the background on top of the checkbox. - * This only happens in version 2.2.1 and earlier. The fix is not to set the background. - */ - if (OS.GTK_VERSION > OS.VERSION (2, 2, 1)) { - if (!ownerDraw) OS.gtk_tree_view_column_add_attribute (columnHandle, checkRenderer, OS.cell_background_gdk, BACKGROUND_COLUMN); - } - if (ownerDraw) { - OS.gtk_tree_view_column_set_cell_data_func (columnHandle, checkRenderer, display.cellDataProc, handle, 0); - OS.g_object_set_qdata (checkRenderer, Display.SWT_OBJECT_INDEX1, columnHandle); - } - } - int /*long*/ pixbufRenderer = ownerDraw ? OS.g_object_new (display.gtk_cell_renderer_pixbuf_get_type (), 0) : OS.gtk_cell_renderer_pixbuf_new (); - if (pixbufRenderer == 0) error (SWT.ERROR_NO_HANDLES); - int /*long*/ textRenderer = ownerDraw ? OS.g_object_new (display.gtk_cell_renderer_text_get_type (), 0) : OS.gtk_cell_renderer_text_new (); - if (textRenderer == 0) error (SWT.ERROR_NO_HANDLES); - - if (ownerDraw) { - OS.g_object_set_qdata (pixbufRenderer, Display.SWT_OBJECT_INDEX1, columnHandle); - OS.g_object_set_qdata (textRenderer, Display.SWT_OBJECT_INDEX1, columnHandle); - } - - /* - * Feature in GTK. When a tree view column contains only one activatable - * cell renderer such as a toggle renderer, mouse clicks anywhere in a cell - * activate that renderer. The workaround is to set a second cell renderer - * to be activatable. - */ - if ((style & SWT.CHECK) != 0 && check) { - OS.g_object_set (pixbufRenderer, OS.mode, OS.GTK_CELL_RENDERER_MODE_ACTIVATABLE, 0); - } - - /* Set alignment */ - if ((columnStyle & SWT.RIGHT) != 0) { - OS.g_object_set(textRenderer, OS.xalign, 1f, 0); - OS.gtk_tree_view_column_pack_end (columnHandle, textRenderer, true); - OS.gtk_tree_view_column_pack_end (columnHandle, pixbufRenderer, false); - OS.gtk_tree_view_column_set_alignment (columnHandle, 1f); - } else if ((columnStyle & SWT.CENTER) != 0) { - OS.g_object_set(textRenderer, OS.xalign, 0.5f, 0); - OS.gtk_tree_view_column_pack_start (columnHandle, pixbufRenderer, false); - OS.gtk_tree_view_column_pack_end (columnHandle, textRenderer, true); - OS.gtk_tree_view_column_set_alignment (columnHandle, 0.5f); - } else { - OS.gtk_tree_view_column_pack_start (columnHandle, pixbufRenderer, false); - OS.gtk_tree_view_column_pack_start (columnHandle, textRenderer, true); - OS.gtk_tree_view_column_set_alignment (columnHandle, 0f); - } - - /* Add attributes */ - OS.gtk_tree_view_column_add_attribute (columnHandle, pixbufRenderer, OS.pixbuf, modelIndex + CELL_PIXBUF); - /* - * Bug on GTK. Gtk renders the background on top of the pixbuf. - * This only happens in version 2.2.1 and earlier. The fix is not to set the background. - */ - if (OS.GTK_VERSION > OS.VERSION (2, 2, 1)) { - if (!ownerDraw) { - OS.gtk_tree_view_column_add_attribute (columnHandle, pixbufRenderer, OS.cell_background_gdk, BACKGROUND_COLUMN); - OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.cell_background_gdk, BACKGROUND_COLUMN); - } - } - OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.text, modelIndex + CELL_TEXT); - OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.foreground_gdk, FOREGROUND_COLUMN); - OS.gtk_tree_view_column_add_attribute (columnHandle, textRenderer, OS.font_desc, FONT_COLUMN); - - boolean customDraw = firstCustomDraw; - if (columnCount != 0) { - for (int i=0; i<columnCount; i++) { - if (columns [i].handle == columnHandle) { - customDraw = columns [i].customDraw; - break; - } - } - } - if ((style & SWT.VIRTUAL) != 0 || customDraw || ownerDraw) { - OS.gtk_tree_view_column_set_cell_data_func (columnHandle, textRenderer, display.cellDataProc, handle, 0); - OS.gtk_tree_view_column_set_cell_data_func (columnHandle, pixbufRenderer, display.cellDataProc, handle, 0); - } -} - -void createWidget (int index) { - super.createWidget (index); - items = new TreeItem [4]; - columns = new TreeColumn [4]; - columnCount = 0; -} - -GdkColor defaultBackground () { - return display.COLOR_LIST_BACKGROUND; -} - -GdkColor defaultForeground () { - return display.COLOR_LIST_FOREGROUND; -} - -void deregister () { - super.deregister (); - display.removeWidget (OS.gtk_tree_view_get_selection (handle)); - if (checkRenderer != 0) display.removeWidget (checkRenderer); - display.removeWidget (modelHandle); -} - -/** - * Deselects an item in the receiver. If the item was already - * deselected, it remains deselected. - * - * @param item the item to be deselected - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the item is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the 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> - * - * @since 3.4 - */ -public void deselect (TreeItem item) { - checkWidget (); - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - boolean fixColumn = showFirstColumn (); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_selection_unselect_iter (selection, item.handle); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if (fixColumn) hideFirstColumn (); -} - -/** - * 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(); - boolean fixColumn = showFirstColumn (); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_selection_unselect_all (selection); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if (fixColumn) hideFirstColumn (); -} - -void destroyItem (TreeColumn column) { - int index = 0; - while (index < columnCount) { - if (columns [index] == column) break; - index++; - } - if (index == columnCount) return; - int /*long*/ columnHandle = column.handle; - if (columnCount == 1) { - firstCustomDraw = column.customDraw; - } - System.arraycopy (columns, index + 1, columns, index, --columnCount - index); - columns [columnCount] = null; - OS.gtk_tree_view_remove_column (handle, columnHandle); - if (columnCount == 0) { - int /*long*/ oldModel = modelHandle; - int /*long*/[] types = getColumnTypes (1); - int /*long*/ newModel = OS.gtk_tree_store_newv (types.length, types); - if (newModel == 0) error (SWT.ERROR_NO_HANDLES); - copyModel(oldModel, column.modelIndex, newModel, FIRST_COLUMN, types, (int /*long*/)0, (int /*long*/)0, FIRST_COLUMN + CELL_TYPES); - OS.gtk_tree_view_set_model (handle, newModel); - OS.g_object_unref (oldModel); - modelHandle = newModel; - createColumn (null, 0); - - } else { - for (int i=0; i<items.length; i++) { - TreeItem item = items [i]; - if (item != null) { - int /*long*/ iter = item.handle; - int modelIndex = column.modelIndex; - OS.gtk_tree_store_set (modelHandle, iter, modelIndex + CELL_PIXBUF, 0, -1); - OS.gtk_tree_store_set (modelHandle, iter, modelIndex + CELL_TEXT, 0, -1); - OS.gtk_tree_store_set (modelHandle, iter, modelIndex + CELL_FOREGROUND, 0, -1); - OS.gtk_tree_store_set (modelHandle, iter, modelIndex + CELL_BACKGROUND, 0, -1); - OS.gtk_tree_store_set (modelHandle, iter, modelIndex + CELL_FONT, 0, -1); - - Font [] cellFont = item.cellFont; - if (cellFont != null) { - if (columnCount == 0) { - item.cellFont = null; - } else { - Font [] temp = new Font [columnCount]; - System.arraycopy (cellFont, 0, temp, 0, index); - System.arraycopy (cellFont, index + 1, temp, index, columnCount - index); - item.cellFont = temp; - } - } - } - } - if (index == 0) { - // first column must be left aligned and must show check box - TreeColumn firstColumn = columns [0]; - firstColumn.style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER); - firstColumn.style |= SWT.LEFT; - createRenderers (firstColumn.handle, firstColumn.modelIndex, true, firstColumn.style); - } - } - /* Disable searching when using VIRTUAL */ - if ((style & SWT.VIRTUAL) != 0) { - /* - * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE) - * would prevent the user from being able to type in text to search the tree. - * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive - * search. This meant that even if FALSE was passed to enable_search, the user - * can still bring up the search pop up using the keybinding. GTK also introduced - * the notion of passing a -1 to gtk_set_search_column to disable searching - * (including the search key binding). The fix is to use the right calls - * for the right version. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 5)) { - OS.gtk_tree_view_set_search_column (handle, -1); - } else { - OS.gtk_tree_view_set_enable_search (handle, false); - } - } else { - /* Set the search column whenever the model changes */ - int firstColumn = columnCount == 0 ? FIRST_COLUMN : columns [0].modelIndex; - OS.gtk_tree_view_set_search_column (handle, firstColumn + CELL_TEXT); - } -} - - -void destroyItem (TreeItem item) { - /* - * Bug in GTK. GTK segment faults when a root tree item - * is destroyed when the tree is expanded and the last leaf of - * the root is selected. This only happens in versions earlier - * than 2.0.6. The fix is to collapse the tree item being destroyed - * when it is a root, before it is destroyed. - */ - if (OS.GTK_VERSION < OS.VERSION (2, 0, 6)) { - int length = OS.gtk_tree_model_iter_n_children (modelHandle, 0); - if (length > 0) { - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - boolean valid = OS.gtk_tree_model_iter_children (modelHandle, iter, 0); - while (valid) { - if (item.handle == iter) { - item.setExpanded (false); - break; - } - valid = OS.gtk_tree_model_iter_next (modelHandle, iter); - } - OS.g_free (iter); - } - } - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_store_remove (modelHandle, item.handle); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - modelChanged = true; -} - -boolean dragDetect (int x, int y, boolean filter, boolean [] consume) { - boolean selected = false; - if (filter) { - int /*long*/ [] path = new int /*long*/ [1]; - if (OS.gtk_tree_view_get_path_at_pos (handle, x, y, path, null, null, null)) { - if (path [0] != 0) { - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - if (OS.gtk_tree_selection_path_is_selected (selection, path [0])) selected = true; - OS.gtk_tree_path_free (path [0]); - } - } else { - return false; - } - } - boolean dragDetect = super.dragDetect (x, y, filter, consume); - if (dragDetect && selected && consume != null) consume [0] = true; - return dragDetect; -} - -int /*long*/ eventWindow () { - return paintWindow (); -} - -boolean fixAccessibility () { - /* - * Bug in GTK. With GTK 2.12, when assistive technologies is on, the time - * it takes to add or remove several rows to the model is very long. This - * happens because the accessible object asks each row for its data, including - * the rows that are not visible. The the fix is to block the accessible object - * from receiving row_added and row_removed signals and, at the end, send only - * a notify signal with the "model" detail. - * - * Note: The test bellow has to be updated when the real problem is fixed in - * the accessible object. - */ - return OS.GTK_VERSION >= OS.VERSION (2, 12, 0); -} - -void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, Decorations oldDecorations, Menu [] menus) { - super.fixChildren (newShell, oldShell, newDecorations, oldDecorations, menus); - for (int i=0; i<columnCount; i++) { - TreeColumn column = columns [i]; - if (column.toolTipText != null) { - column.setToolTipText(oldShell, null); - column.setToolTipText(newShell, column.toolTipText); - } - } -} - -GdkColor getBackgroundColor () { - return getBaseColor (); -} - -public Rectangle getClientArea () { - checkWidget (); - forceResize (); - OS.gtk_widget_realize (handle); - int /*long*/ fixedWindow = OS.GTK_WIDGET_WINDOW (fixedHandle); - int /*long*/ binWindow = OS.gtk_tree_view_get_bin_window (handle); - int [] binX = new int [1], binY = new int [1]; - OS.gdk_window_get_origin (binWindow, binX, binY); - int [] fixedX = new int [1], fixedY = new int [1]; - OS.gdk_window_get_origin (fixedWindow, fixedX, fixedY); - int /*long*/ clientHandle = clientHandle (); - int width = (state & ZERO_WIDTH) != 0 ? 0 : OS.GTK_WIDGET_WIDTH (clientHandle); - int height = (state & ZERO_HEIGHT) != 0 ? 0 : OS.GTK_WIDGET_HEIGHT (clientHandle); - return new Rectangle (fixedX [0] - binX [0], fixedY [0] - binY [0], width, height); -} - -int getClientWidth () { - int [] w = new int [1], h = new int [1]; - OS.gtk_widget_realize (handle); - OS.gdk_drawable_get_size(OS.gtk_tree_view_get_bin_window(handle), w, h); - return w[0]; -} - -/** - * Returns the column at the given, zero-relative index in the - * receiver. Throws an exception if the index is out of range. - * Columns are returned in the order that they were created. - * If no <code>TreeColumn</code>s were created by the programmer, - * this method will throw <code>ERROR_INVALID_RANGE</code> despite - * the fact that a single column of data may be visible in the tree. - * This occurs when the programmer uses the tree like a list, adding - * items but never creating a column. - * - * @param index the index of the column to return - * @return the column 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> - * - * @see Tree#getColumnOrder() - * @see Tree#setColumnOrder(int[]) - * @see TreeColumn#getMoveable() - * @see TreeColumn#setMoveable(boolean) - * @see SWT#Move - * - * @since 3.1 - */ -public TreeColumn getColumn (int index) { - checkWidget(); - if (!(0 <= index && index < columnCount)) error (SWT.ERROR_INVALID_RANGE); - return columns [index]; -} - -/** - * Returns the number of columns contained in the receiver. - * If no <code>TreeColumn</code>s were created by the programmer, - * this value is zero, despite the fact that visually, one column - * of items may be visible. This occurs when the programmer uses - * the tree like a list, adding items but never creating a column. - * - * @return the number of columns - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 int getColumnCount () { - checkWidget(); - return columnCount; -} - -/** - * Returns an array of zero-relative integers that map - * the creation order of the receiver's items to the - * order in which they are currently being displayed. - * <p> - * Specifically, the indices of the returned array represent - * the current visual order of the items, and the contents - * of the array represent the creation order of the items. - * </p><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 current visual order of the receiver's 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> - * - * @see Tree#setColumnOrder(int[]) - * @see TreeColumn#getMoveable() - * @see TreeColumn#setMoveable(boolean) - * @see SWT#Move - * - * @since 3.2 - */ -public int [] getColumnOrder () { - checkWidget (); - if (columnCount == 0) return new int [0]; - int /*long*/ list = OS.gtk_tree_view_get_columns (handle); - if (list == 0) return new int [0]; - int i = 0, count = OS.g_list_length (list); - int [] order = new int [count]; - int /*long*/ temp = list; - while (temp != 0) { - int /*long*/ column = OS.g_list_data (temp); - if (column != 0) { - for (int j=0; j<columnCount; j++) { - if (columns [j].handle == column) { - order [i++] = j; - break; - } - } - } - temp = OS.g_list_next (temp); - } - OS.g_list_free (list); - return order; -} - -int /*long*/[] getColumnTypes (int columnCount) { - int /*long*/[] types = new int /*long*/ [FIRST_COLUMN + (columnCount * CELL_TYPES)]; - // per row data - types [ID_COLUMN] = OS.G_TYPE_INT (); - types [CHECKED_COLUMN] = OS.G_TYPE_BOOLEAN (); - types [GRAYED_COLUMN] = OS.G_TYPE_BOOLEAN (); - types [FOREGROUND_COLUMN] = OS.GDK_TYPE_COLOR (); - types [BACKGROUND_COLUMN] = OS.GDK_TYPE_COLOR (); - types [FONT_COLUMN] = OS.PANGO_TYPE_FONT_DESCRIPTION (); - // per cell data - for (int i=FIRST_COLUMN; i<types.length; i+=CELL_TYPES) { - types [i + CELL_PIXBUF] = OS.GDK_TYPE_PIXBUF (); - types [i + CELL_TEXT] = OS.G_TYPE_STRING (); - types [i + CELL_FOREGROUND] = OS.GDK_TYPE_COLOR (); - types [i + CELL_BACKGROUND] = OS.GDK_TYPE_COLOR (); - types [i + CELL_FONT] = OS.PANGO_TYPE_FONT_DESCRIPTION (); - } - return types; -} - -/** - * Returns an array of <code>TreeColumn</code>s which are the - * columns in the receiver. Columns are returned in the order - * that they were created. If no <code>TreeColumn</code>s were - * created by the programmer, the array is empty, despite the fact - * that visually, one column of items may be visible. This occurs - * when the programmer uses the tree like a list, adding items but - * never creating a column. - * <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> - * - * @see Tree#getColumnOrder() - * @see Tree#setColumnOrder(int[]) - * @see TreeColumn#getMoveable() - * @see TreeColumn#setMoveable(boolean) - * @see SWT#Move - * - * @since 3.1 - */ -public TreeColumn [] getColumns () { - checkWidget(); - TreeColumn [] result = new TreeColumn [columnCount]; - System.arraycopy (columns, 0, result, 0, columnCount); - return result; -} - -TreeItem getFocusItem () { - int /*long*/ [] path = new int /*long*/ [1]; - OS.gtk_tree_view_get_cursor (handle, path, null); - if (path [0] == 0) return null; - TreeItem item = null; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (OS.gtk_tree_model_get_iter (modelHandle, iter, path [0])) { - int [] index = new int [1]; - OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, index, -1); - if (index [0] != -1) item = items [index [0]]; //TODO should we be creating this item when index is -1? - } - OS.g_free (iter); - OS.gtk_tree_path_free (path [0]); - return item; -} - -GdkColor getForegroundColor () { - return getTextColor (); -} - -/** - * Returns the width in pixels of a grid line. - * - * @return the width of a grid line in pixels - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 int getGridLineWidth () { - checkWidget(); - return 0; -} - -/** - * Returns the height of the receiver's header - * - * @return the height of the header or zero if the header is not 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.1 - */ -public int getHeaderHeight () { - checkWidget (); - if (!OS.gtk_tree_view_get_headers_visible (handle)) return 0; - if (columnCount > 0) { - GtkRequisition requisition = new GtkRequisition (); - int height = 0; - for (int i=0; i<columnCount; i++) { - int /*long*/ buttonHandle = columns [i].buttonHandle; - if (buttonHandle != 0) { - OS.gtk_widget_size_request (buttonHandle, requisition); - height = Math.max (height, requisition.height); - } - } - return height; - } - OS.gtk_widget_realize (handle); - int /*long*/ fixedWindow = OS.GTK_WIDGET_WINDOW (fixedHandle); - int /*long*/ binWindow = OS.gtk_tree_view_get_bin_window (handle); - int [] binY = new int [1]; - OS.gdk_window_get_origin (binWindow, null, binY); - int [] fixedY = new int [1]; - OS.gdk_window_get_origin (fixedWindow, null, fixedY); - return binY [0] - fixedY [0]; -} - -/** - * Returns <code>true</code> if the receiver's header 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 header'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.1 - */ -public boolean getHeaderVisible () { - checkWidget(); - return OS.gtk_tree_view_get_headers_visible (handle); -} - -/** - * 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> - * - * @since 3.1 - */ -public TreeItem getItem (int index) { - checkWidget(); - if (!(0 <= index && index < OS.gtk_tree_model_iter_n_children (modelHandle, 0))) { - error (SWT.ERROR_INVALID_RANGE); - } - return _getItem (0, index); -} - -/** - * 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. - * <p> - * The item that is returned represents an item that could be selected by the user. - * For example, if selection only occurs in items in the first column, then null is - * returned if the point is outside of the item. - * Note that the SWT.FULL_SELECTION style hint, which specifies the selection policy, - * determines the extent of the selection. - * </p> - * - * @param point the point used to locate the item - * @return the item at the given point, or null if the point is not in a selectable item - * - * @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 TreeItem getItem (Point point) { - checkWidget (); - if (point == null) error (SWT.ERROR_NULL_ARGUMENT); - int /*long*/ [] path = new int /*long*/ [1]; - OS.gtk_widget_realize (handle); - int /*long*/ [] columnHandle = new int /*long*/ [1]; - if (!OS.gtk_tree_view_get_path_at_pos (handle, point.x, point.y, path, columnHandle, null, null)) return null; - if (path [0] == 0) return null; - TreeItem item = null; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (OS.gtk_tree_model_get_iter (modelHandle, iter, path [0])) { - boolean overExpander = false; - if (OS.gtk_tree_view_get_expander_column (handle) == columnHandle [0]) { - int [] buffer = new int [1]; - GdkRectangle rect = new GdkRectangle (); - OS.gtk_tree_view_get_cell_area (handle, path [0], columnHandle [0], rect); - if (OS.GTK_VERSION < OS.VERSION (2, 8, 18)) { - OS.gtk_widget_style_get (handle, OS.expander_size, buffer, 0); - int expanderSize = buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING; - overExpander = point.x < rect.x + expanderSize; - } else { - overExpander = point.x < rect.x; - } - } - if (!overExpander) { - item = _getItem (iter); - } - } - OS.g_free (iter); - OS.gtk_tree_path_free (path [0]); - return item; -} - -/** - * Returns the number of items contained in the receiver - * that are direct item children of the receiver. The - * number that is returned is the number of roots in the - * tree. - * - * @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 OS.gtk_tree_model_iter_n_children (modelHandle, 0); -} - -/** - * Returns the height of the area which would be used to - * display <em>one</em> of the items in the tree. - * - * @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 itemCount = OS.gtk_tree_model_iter_n_children (modelHandle, 0); - if (itemCount == 0) { - int /*long*/ column = OS.gtk_tree_view_get_column (handle, 0); - int [] w = new int [1], h = new int [1]; - ignoreSize = true; - OS.gtk_tree_view_column_cell_get_size (column, null, null, null, w, h); - ignoreSize = false; - return h [0]; - } else { - int height = 0; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - OS.gtk_tree_model_get_iter_first (modelHandle, iter); - int columnCount = Math.max (1, this.columnCount); - for (int i=0; i<columnCount; i++) { - int /*long*/ column = OS.gtk_tree_view_get_column (handle, i); - OS.gtk_tree_view_column_cell_set_cell_data (column, modelHandle, iter, false, false); - int [] w = new int [1], h = new int [1]; - OS.gtk_tree_view_column_cell_get_size (column, null, null, null, w, h); - height = Math.max (height, h [0]); - } - OS.g_free (iter); - return height; - } -} - -/** - * Returns a (possibly empty) array of items contained in the - * receiver that are direct item children of the receiver. These - * are the roots of the tree. - * <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 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public TreeItem [] getItems () { - checkWidget(); - return getItems (0); -} - -TreeItem [] getItems (int /*long*/ parent) { - int length = OS.gtk_tree_model_iter_n_children (modelHandle, parent); - TreeItem[] result = new TreeItem [length]; - if (length == 0) return result; - if ((style & SWT.VIRTUAL) != 0) { - for (int i=0; i<length; i++) { - result [i] = _getItem (parent, i); - } - } else { - int i = 0; - int[] index = new int [1]; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - boolean valid = OS.gtk_tree_model_iter_children (modelHandle, iter, parent); - while (valid) { - OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, index, -1); - result [i++] = items [index [0]]; - valid = OS.gtk_tree_model_iter_next (modelHandle, iter); - } - OS.g_free (iter); - } - return result; -} - -/** - * Returns <code>true</code> if the receiver's lines are visible, - * and <code>false</code> otherwise. Note that some platforms draw - * grid lines while others may draw alternating row colors. - * <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 visibility state of the lines - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 boolean getLinesVisible() { - checkWidget(); - return OS.gtk_tree_view_get_rules_hint (handle); -} - -/** - * Returns the receiver's parent item, which must be a - * <code>TreeItem</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 TreeItem getParentItem () { - checkWidget (); - return null; -} - -int /*long*/ getPixbufRenderer (int /*long*/ column) { - int /*long*/ list = OS.gtk_tree_view_column_get_cell_renderers (column); - if (list == 0) return 0; - int count = OS.g_list_length (list); - int /*long*/ pixbufRenderer = 0; - int i = 0; - while (i < count) { - int /*long*/ renderer = OS.g_list_nth_data (list, i); - if (OS.GTK_IS_CELL_RENDERER_PIXBUF (renderer)) { - pixbufRenderer = renderer; - break; - } - i++; - } - OS.g_list_free (list); - return pixbufRenderer; -} - -/** - * Returns an array of <code>TreeItem</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 TreeItem[] getSelection () { - checkWidget(); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) { - display.treeSelectionLength = 0; - display.treeSelection = new int [items.length]; - OS.gtk_tree_selection_selected_foreach (selection, display.treeSelectionProc, handle); - TreeItem [] result = new TreeItem [display.treeSelectionLength]; - for (int i=0; i<result.length; i++) result [i] = items [display.treeSelection [i]]; - return result; - } - /* - * Bug in GTK. gtk_tree_selection_get_selected_rows() segmentation faults - * in versions smaller than 2.2.4 if the model is NULL. The fix is - * to give a valid pointer instead. - */ - int /*long*/ [] model = OS.GTK_VERSION < OS.VERSION (2, 2, 4) ? new int /*long*/ [1] : null; - int /*long*/ list = OS.gtk_tree_selection_get_selected_rows (selection, model); - if (list != 0) { - int count = OS.g_list_length (list); - TreeItem [] treeSelection = new TreeItem [count]; - int length = 0; - for (int i=0; i<count; i++) { - int /*long*/ data = OS.g_list_nth_data (list, i); - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (OS.gtk_tree_model_get_iter (modelHandle, iter, data)) { - treeSelection [length] = _getItem (iter); - length++; - } - OS.g_free (iter); - } - OS.g_list_free (list); - if (length < count) { - TreeItem [] temp = new TreeItem [length]; - System.arraycopy(treeSelection, 0, temp, 0, length); - treeSelection = temp; - } - return treeSelection; - } - return new TreeItem [0]; -} - -/** - * 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 /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - if (OS.GTK_VERSION < OS.VERSION (2, 2, 0)) { - display.treeSelectionLength = 0; - display.treeSelection = null; - OS.gtk_tree_selection_selected_foreach (selection, display.treeSelectionProc, handle); - return display.treeSelectionLength; - } - return OS.gtk_tree_selection_count_selected_rows (selection); -} - -/** - * Returns the column which shows the sort indicator for - * the receiver. The value may be null if no column shows - * the sort indicator. - * - * @return the sort indicator - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 #setSortColumn(TreeColumn) - * - * @since 3.2 - */ -public TreeColumn getSortColumn () { - checkWidget (); - return sortColumn; -} - -/** - * Returns the direction of the sort indicator for the receiver. - * The value will be one of <code>UP</code>, <code>DOWN</code> - * or <code>NONE</code>. - * - * @return the sort direction - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 #setSortDirection(int) - * - * @since 3.2 - */ -public int getSortDirection () { - checkWidget (); - return sortDirection; -} - -int /*long*/ getTextRenderer (int /*long*/ column) { - int /*long*/ list = OS.gtk_tree_view_column_get_cell_renderers (column); - if (list == 0) return 0; - int count = OS.g_list_length (list); - int /*long*/ textRenderer = 0; - int i = 0; - while (i < count) { - int /*long*/ renderer = OS.g_list_nth_data (list, i); - if (OS.GTK_IS_CELL_RENDERER_TEXT (renderer)) { - textRenderer = renderer; - break; - } - i++; - } - OS.g_list_free (list); - return textRenderer; -} - -/** - * Returns the item which is currently at the top of the receiver. - * This item can change when items are expanded, collapsed, scrolled - * or new items are added or removed. - * - * @return the item at the top of 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 2.1 - */ -public TreeItem getTopItem () { - checkWidget (); - int /*long*/ [] path = new int /*long*/ [1]; - OS.gtk_widget_realize (handle); - if (!OS.gtk_tree_view_get_path_at_pos (handle, 1, 1, path, null, null, null)) return null; - if (path [0] == 0) return null; - TreeItem item = null; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof()); - if (OS.gtk_tree_model_get_iter (modelHandle, iter, path [0])) { - item = _getItem (iter); - } - OS.g_free (iter); - OS.gtk_tree_path_free (path [0]); - return item; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, event, GdkEventButton.sizeof); - if (gdkEvent.window != OS.gtk_tree_view_get_bin_window (handle)) return 0; - int /*long*/ result = super.gtk_button_press_event (widget, event); - if (result != 0) return result; - /* - * Feature in GTK. In a multi-select tree view, when multiple items are already - * selected, the selection state of the item is toggled and the previous selection - * is cleared. This is not the desired behaviour when bringing up a popup menu. - * Also, when an item is reselected with the right button, the tree view issues - * an unwanted selection event. The workaround is to detect that case and not - * run the default handler when the item is already part of the current selection. - */ - int button = gdkEvent.button; - if (button == 3 && gdkEvent.type == OS.GDK_BUTTON_PRESS) { - int /*long*/ [] path = new int /*long*/ [1]; - if (OS.gtk_tree_view_get_path_at_pos (handle, (int)gdkEvent.x, (int)gdkEvent.y, path, null, null, null)) { - if (path [0] != 0) { - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - if (OS.gtk_tree_selection_path_is_selected (selection, path [0])) result = 1; - OS.gtk_tree_path_free (path [0]); - } - } - } - - /* - * Feature in GTK. When the user clicks in a single selection GtkTreeView - * and there are no selected items, the first item is selected automatically - * before the click is processed, causing two selection events. The is fix - * is the set the cursor item to be same as the clicked item to stop the - * widget from automatically selecting the first item. - */ - if ((style & SWT.SINGLE) != 0 && getSelectionCount () == 0) { - int /*long*/ [] path = new int /*long*/ [1]; - if (OS.gtk_tree_view_get_path_at_pos (handle, (int)gdkEvent.x, (int)gdkEvent.y, path, null, null, null)) { - if (path [0] != 0) { - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_view_set_cursor (handle, path [0], 0, false); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_path_free (path [0]); - } - } - } - /* - * Bug in GTK. GTK segments fault, if the GtkTreeView widget is - * not in focus and all items in the widget are disposed before - * it finishes processing a button press. The fix is to give - * focus to the widget before it starts processing the event. - */ - if (!OS.GTK_WIDGET_HAS_FOCUS (handle)) { - OS.gtk_widget_grab_focus (handle); - } - return result; -} - -int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ window = OS.GDK_EVENT_WINDOW (event); - if (window != OS.gtk_tree_view_get_bin_window (handle)) return 0; - return super.gtk_button_release_event (widget, event); -} - -int /*long*/ gtk_changed (int /*long*/ widget) { - TreeItem item = getFocusItem (); - if (item != null) { - Event event = new Event (); - event.item = item; - postEvent (SWT.Selection, event); - } - return 0; -} - -int /*long*/ gtk_expand_collapse_cursor_row (int /*long*/ widget, int /*long*/ logical, int /*long*/ expand, int /*long*/ open_all) { - // FIXME - this flag is never cleared. It should be cleared when the expand all operation completes. - if (expand != 0 && open_all != 0) expandAll = true; - return 0; -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ eventPtr) { - int /*long*/ result = super.gtk_key_press_event (widget, eventPtr); - if (result != 0) return result; - if (OS.GTK_VERSION < OS.VERSION (2, 2 ,0)) { - /* - * Feature in GTK 2.0.x. When an item is default selected using - * the return key, GTK does not issue notification. The fix is - * to issue this notification when the return key is pressed. - */ - GdkEventKey keyEvent = new GdkEventKey (); - OS.memmove (keyEvent, eventPtr, GdkEventKey.sizeof); - int key = keyEvent.keyval; - switch (key) { - case OS.GDK_Return: - case OS.GDK_KP_Enter: { - Event event = new Event (); - event.item = getFocusItem (); - postEvent (SWT.DefaultSelection, event); - break; - } - } - } - return result; -} - -int /*long*/ gtk_motion_notify_event (int /*long*/ widget, int /*long*/ event) { - int /*long*/ window = OS.GDK_EVENT_WINDOW (event); - if (window != OS.gtk_tree_view_get_bin_window (handle)) return 0; - return super.gtk_motion_notify_event (widget, event); -} - -int /*long*/ gtk_popup_menu (int /*long*/ widget) { - int /*long*/ result = super.gtk_popup_menu (widget); - /* - * Bug in GTK. The context menu for the typeahead in GtkTreeViewer - * opens in the bottom right corner of the screen when Shift+F10 - * is pressed and the typeahead window was not visible. The fix is - * to prevent the context menu from opening by stopping the default - * handler. - * - * NOTE: The bug only happens in GTK 2.6.5 and lower. - */ - return OS.GTK_VERSION < OS.VERSION (2, 6, 5) ? 1 : result; -} - -int /*long*/ gtk_row_activated (int /*long*/ tree, int /*long*/ path, int /*long*/ column) { - if (path == 0) return 0; - TreeItem item = null; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (OS.gtk_tree_model_get_iter (modelHandle, iter, path)) { - int [] index = new int [1]; - OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, index, -1); - item = items [index [0]]; - } - OS.g_free (iter); - Event event = new Event (); - event.item = item; - postEvent (SWT.DefaultSelection, event); - return 0; -} - -int gtk_row_deleted (int model, int path) { - if (ignoreAccessibility) { - OS.g_signal_stop_emission_by_name (model, OS.row_deleted); - } - return 0; -} - -int gtk_row_inserted (int model, int path, int iter) { - if (ignoreAccessibility) { - OS.g_signal_stop_emission_by_name (model, OS.row_inserted); - } - return 0; -} - -int /*long*/ gtk_test_collapse_row (int /*long*/ tree, int /*long*/ iter, int /*long*/ path) { - int [] index = new int [1]; - OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, index, -1); - TreeItem item = items [index [0]]; - Event event = new Event (); - event.item = item; - boolean oldModelChanged = modelChanged; - modelChanged = false; - sendEvent (SWT.Collapse, event); - /* - * Bug in GTK. Collapsing the target row during the test_collapse_row - * handler will cause a segmentation fault if the animation code is allowed - * to run. The fix is to block the animation if the row is already - * collapsed. - */ - boolean changed = modelChanged || !OS.gtk_tree_view_row_expanded (handle, path); - modelChanged = oldModelChanged; - if (isDisposed () || item.isDisposed ()) return 1; - /* - * Bug in GTK. Expanding or collapsing a row which has no more - * children causes the model state to become invalid, causing - * GTK to give warnings and behave strangely. Other changes to - * the model can cause expansion to fail when using the multiple - * expansion keys (such as *). The fix is to stop the expansion - * if there are model changes. - * - * Note: This callback must return 0 for the collapsing - * animation to occur. - */ - if (changed) { - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_COLLAPSE_ROW); - OS.gtk_tree_view_collapse_row (handle, path); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_COLLAPSE_ROW); - return 1; - } - return 0; -} - -int /*long*/ gtk_test_expand_row (int /*long*/ tree, int /*long*/ iter, int /*long*/ path) { - int [] index = new int [1]; - OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, index, -1); - TreeItem item = items [index [0]]; - Event event = new Event (); - event.item = item; - boolean oldModelChanged = modelChanged; - modelChanged = false; - sendEvent (SWT.Expand, event); - /* - * Bug in GTK. Expanding the target row during the test_expand_row - * handler will cause a segmentation fault if the animation code is allowed - * to run. The fix is to block the animation if the row is already - * expanded. - */ - boolean changed = modelChanged || OS.gtk_tree_view_row_expanded (handle, path); - modelChanged = oldModelChanged; - if (isDisposed () || item.isDisposed ()) return 1; - /* - * Bug in GTK. Expanding or collapsing a row which has no more - * children causes the model state to become invalid, causing - * GTK to give warnings and behave strangely. Other changes to - * the model can cause expansion to fail when using the multiple - * expansion keys (such as *). The fix is to stop the expansion - * if there are model changes. - * - * Bug in GTK. test-expand-row does not get called for each row - * in an expand all operation. The fix is to block the initial - * expansion and only expand a single level. - * - * Note: This callback must return 0 for the collapsing - * animation to occur. - */ - if (changed || expandAll) { - OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_EXPAND_ROW); - OS.gtk_tree_view_expand_row (handle, path, false); - OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_EXPAND_ROW); - return 1; - } - return 0; -} - -int /*long*/ gtk_toggled (int /*long*/ renderer, int /*long*/ pathStr) { - int /*long*/ path = OS.gtk_tree_path_new_from_string (pathStr); - if (path == 0) return 0; - TreeItem item = null; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof()); - if (OS.gtk_tree_model_get_iter (modelHandle, iter, path)) { - item = _getItem (iter); - } - OS.g_free (iter); - OS.gtk_tree_path_free (path); - if (item != null) { - item.setChecked (!item.getChecked ()); - Event event = new Event (); - event.detail = SWT.CHECK; - event.item = item; - postEvent (SWT.Selection, event); - } - return 0; -} - -void gtk_widget_size_request (int /*long*/ widget, GtkRequisition requisition) { - /* - * Bug in GTK. For some reason, gtk_widget_size_request() fails - * to include the height of the tree view items when there are - * no columns visible. The fix is to temporarily make one column - * visible. - */ - if (columnCount == 0) { - super.gtk_widget_size_request (widget, requisition); - return; - } - int /*long*/ columns = OS.gtk_tree_view_get_columns (handle), list = columns; - boolean fixVisible = columns != 0; - while (list != 0) { - int /*long*/ column = OS.g_list_data (list); - if (OS.gtk_tree_view_column_get_visible (column)) { - fixVisible = false; - break; - } - list = OS.g_list_next (list); - } - int /*long*/ columnHandle = 0; - if (fixVisible) { - columnHandle = OS.g_list_data (columns); - OS.gtk_tree_view_column_set_visible (columnHandle, true); - } - super.gtk_widget_size_request (widget, requisition); - if (fixVisible) { - OS.gtk_tree_view_column_set_visible (columnHandle, false); - } - if (columns != 0) OS.g_list_free (columns); -} - -void hideFirstColumn () { - int /*long*/ firstColumn = OS.gtk_tree_view_get_column (handle, 0); - OS.gtk_tree_view_column_set_visible (firstColumn, false); -} - -void hookEvents () { - super.hookEvents (); - int /*long*/ selection = OS.gtk_tree_view_get_selection(handle); - OS.g_signal_connect_closure (selection, OS.changed, display.closures [CHANGED], false); - OS.g_signal_connect_closure (handle, OS.row_activated, display.closures [ROW_ACTIVATED], false); - OS.g_signal_connect_closure (handle, OS.test_expand_row, display.closures [TEST_EXPAND_ROW], false); - OS.g_signal_connect_closure (handle, OS.test_collapse_row, display.closures [TEST_COLLAPSE_ROW], false); - OS.g_signal_connect_closure (handle, OS.expand_collapse_cursor_row, display.closures [EXPAND_COLLAPSE_CURSOR_ROW], false); - if (checkRenderer != 0) { - OS.g_signal_connect_closure (checkRenderer, OS.toggled, display.closures [TOGGLED], false); - } - if (fixAccessibility ()) { - OS.g_signal_connect_closure (modelHandle, OS.row_inserted, display.closures [ROW_INSERTED], true); - OS.g_signal_connect_closure (modelHandle, OS.row_deleted, display.closures [ROW_DELETED], true); - } -} - -/** - * Searches the receiver's list starting at the first column - * (index 0) until a column is found that is equal to the - * argument, and returns the index of that column. If no column - * is found, returns -1. - * - * @param column the search column - * @return the index of the column - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the column 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 int indexOf (TreeColumn column) { - checkWidget(); - if (column == null) error (SWT.ERROR_NULL_ARGUMENT); - for (int i=0; i<columnCount; i++) { - if (columns [i] == column) return i; - } - return -1; -} - -/** - * 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> - * <li>ERROR_INVALID_ARGUMENT - if the 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> - * - * @since 3.1 - */ -public int indexOf (TreeItem item) { - checkWidget(); - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - int index = -1; - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, item.handle); - int depth = OS.gtk_tree_path_get_depth (path); - if (depth == 1) { - int /*long*/ indices = OS.gtk_tree_path_get_indices (path); - if (indices != 0) { - int[] temp = new int[1]; - OS.memmove (temp, indices, 4); - index = temp[0]; - } - } - OS.gtk_tree_path_free (path); - return index; -} - -boolean mnemonicHit (char key) { - for (int i=0; i<columnCount; i++) { - int /*long*/ labelHandle = columns [i].labelHandle; - if (labelHandle != 0 && mnemonicHit (labelHandle, key)) return true; - } - return false; -} - -boolean mnemonicMatch (char key) { - for (int i=0; i<columnCount; i++) { - int /*long*/ labelHandle = columns [i].labelHandle; - if (labelHandle != 0 && mnemonicMatch (labelHandle, key)) return true; - } - return false; -} - -int /*long*/ paintWindow () { - OS.gtk_widget_realize (handle); - return OS.gtk_tree_view_get_bin_window (handle); -} - -void recreateRenderers () { - if (checkRenderer != 0) { - display.removeWidget (checkRenderer); - OS.g_object_unref (checkRenderer); - checkRenderer = ownerDraw ? OS.g_object_new (display.gtk_cell_renderer_toggle_get_type(), 0) : OS.gtk_cell_renderer_toggle_new (); - if (checkRenderer == 0) error (SWT.ERROR_NO_HANDLES); - OS.g_object_ref (checkRenderer); - display.addWidget (checkRenderer, this); - OS.g_signal_connect_closure (checkRenderer, OS.toggled, display.closures [TOGGLED], false); - } - if (columnCount == 0) { - createRenderers (OS.gtk_tree_view_get_column (handle, 0), Tree.FIRST_COLUMN, true, 0); - } else { - for (int i = 0; i < columnCount; i++) { - TreeColumn column = columns [i]; - createRenderers (column.handle, column.modelIndex, i == 0, column.style); - } - } -} - -void redrawBackgroundImage () { - Control control = findBackgroundControl (); - if (control != null && control.backgroundImage != null) { - redrawWidget (0, 0, 0, 0, true, false, false); - } -} - -void register () { - super.register (); - display.addWidget (OS.gtk_tree_view_get_selection (handle), this); - if (checkRenderer != 0) display.addWidget (checkRenderer, this); - display.addWidget (modelHandle, this); -} - -void releaseItem (TreeItem item, boolean release) { - int [] index = new int [1]; - OS.gtk_tree_model_get (modelHandle, item.handle, ID_COLUMN, index, -1); - if (index [0] == -1) return; - if (release) item.release (false); - items [index [0]] = null; -} - -void releaseItems (int /*long*/ parentIter) { - int[] index = new int [1]; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - boolean valid = OS.gtk_tree_model_iter_children (modelHandle, iter, parentIter); - while (valid) { - releaseItems (iter); - if (!isDisposed ()) { - OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, index, -1); - if (index [0] != -1) { - TreeItem item = items [index [0]]; - if (item != null) releaseItem (item, true); - } - } - valid = OS.gtk_tree_model_iter_next (modelHandle, iter); - } - OS.g_free (iter); -} - -void releaseChildren (boolean destroy) { - if (items != null) { - for (int i=0; i<items.length; i++) { - TreeItem item = items [i]; - if (item != null && !item.isDisposed ()) { - item.release (false); - } - } - items = null; - } - if (columns != null) { - for (int i=0; i<columnCount; i++) { - TreeColumn column = columns [i]; - if (column != null && !column.isDisposed ()) { - column.release (false); - } - } - columns = null; - } - super.releaseChildren (destroy); -} - -void releaseWidget () { - super.releaseWidget (); - if (modelHandle != 0) OS.g_object_unref (modelHandle); - modelHandle = 0; - if (checkRenderer != 0) OS.g_object_unref (checkRenderer); - checkRenderer = 0; - if (imageList != null) imageList.dispose (); - if (headerImageList != null) headerImageList.dispose (); - imageList = headerImageList = null; - currentItem = null; -} - -void remove (int /*long*/ parentIter, int start, int end) { - if (start > end) return; - int itemCount = OS.gtk_tree_model_iter_n_children (modelHandle, parentIter); - if (!(0 <= start && start <= end && end < itemCount)) { - error (SWT.ERROR_INVALID_RANGE); - } - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (iter == 0) error (SWT.ERROR_NO_HANDLES); - if (fixAccessibility ()) { - ignoreAccessibility = true; - } - for (int i = start; i <= end; i++) { - OS.gtk_tree_model_iter_nth_child (modelHandle, iter, parentIter, start); - int[] value = new int[1]; - OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, value, -1); - TreeItem item = value [0] != -1 ? items [value [0]] : null; - if (item != null && !item.isDisposed ()) { - item.dispose (); - } else { - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_store_remove (modelHandle, iter); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - } - } - if (fixAccessibility ()) { - ignoreAccessibility = false; - OS.g_object_notify (handle, OS.model); - } - OS.g_free (iter); -} - -/** - * Removes all of the items from 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 removeAll () { - checkWidget (); - for (int i=0; i<items.length; i++) { - TreeItem item = items [i]; - if (item != null && !item.isDisposed ()) item.release (false); - } - items = new TreeItem[4]; - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if (fixAccessibility ()) { - ignoreAccessibility = true; - } - OS.gtk_tree_store_clear (modelHandle); - if (fixAccessibility ()) { - ignoreAccessibility = false; - OS.g_object_notify (handle, OS.model); - } - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - - /* Disable searching when using VIRTUAL */ - if ((style & SWT.VIRTUAL) != 0) { - /* - * Bug in GTK. Until GTK 2.6.5, calling gtk_tree_view_set_enable_search(FALSE) - * would prevent the user from being able to type in text to search the tree. - * After 2.6.5, GTK introduced Ctrl+F as being the key binding for interactive - * search. This meant that even if FALSE was passed to enable_search, the user - * can still bring up the search pop up using the keybinding. GTK also introduced - * the notion of passing a -1 to gtk_set_search_column to disable searching - * (including the search key binding). The fix is to use the right calls - * for the right version. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 6, 5)) { - OS.gtk_tree_view_set_search_column (handle, -1); - } else { - OS.gtk_tree_view_set_enable_search (handle, false); - } - } else { - /* Set the search column whenever the model changes */ - int firstColumn = columnCount == 0 ? FIRST_COLUMN : columns [0].modelIndex; - OS.gtk_tree_view_set_search_column (handle, firstColumn + CELL_TEXT); - } -} - -/** - * 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); - eventTable.unhook (SWT.Selection, listener); - eventTable.unhook (SWT.DefaultSelection, listener); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when items in the receiver are expanded or collapsed. - * - * @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 TreeListener - * @see #addTreeListener - */ -public void removeTreeListener(TreeListener listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Expand, listener); - eventTable.unhook (SWT.Collapse, listener); -} - -int /*long*/ rendererGetSizeProc (int /*long*/ cell, int /*long*/ widget, int /*long*/ cell_area, int /*long*/ x_offset, int /*long*/ y_offset, int /*long*/ width, int /*long*/ height) { - int /*long*/ g_class = OS.g_type_class_peek_parent (OS.G_OBJECT_GET_CLASS (cell)); - GtkCellRendererClass klass = new GtkCellRendererClass (); - OS.memmove (klass, g_class); - int /*long*/ result = OS.call (klass.get_size, cell, handle, cell_area, x_offset, y_offset, width, height); - if (!ignoreSize && OS.GTK_IS_CELL_RENDERER_TEXT (cell)) { - int /*long*/ iter = OS.g_object_get_qdata (cell, Display.SWT_OBJECT_INDEX2); - TreeItem item = null; - if (iter != 0) item = _getItem (iter); - if (item != null) { - int columnIndex = 0; - if (columnCount > 0) { - int /*long*/ columnHandle = OS.g_object_get_qdata (cell, Display.SWT_OBJECT_INDEX1); - for (int i = 0; i < columnCount; i++) { - if (columns [i].handle == columnHandle) { - columnIndex = i; - break; - } - } - } - if (hooks (SWT.MeasureItem)) { - int [] contentWidth = new int [1], contentHeight = new int [1]; - if (width != 0) OS.memmove (contentWidth, width, 4); - if (height != 0) OS.memmove (contentHeight, height, 4); - Image image = item.getImage (columnIndex); - int imageWidth = 0; - if (image != null) { - Rectangle bounds = image.getBounds (); - imageWidth = bounds.width; - } - contentWidth [0] += imageWidth; - GC gc = new GC (this); - gc.setFont (item.getFont (columnIndex)); - Event event = new Event (); - event.item = item; - event.index = columnIndex; - event.gc = gc; - event.width = contentWidth [0]; - event.height = contentHeight [0]; - sendEvent (SWT.MeasureItem, event); - gc.dispose (); - contentWidth [0] = event.width - imageWidth; - if (contentHeight [0] < event.height) contentHeight [0] = event.height; - if (width != 0) OS.memmove (width, contentWidth, 4); - if (height != 0) OS.memmove (height, contentHeight, 4); - } - } - } - return result; -} - -int /*long*/ rendererRenderProc (int /*long*/ cell, int /*long*/ window, int /*long*/ widget, int /*long*/ background_area, int /*long*/ cell_area, int /*long*/ expose_area, int /*long*/ flags) { - TreeItem item = null; - int /*long*/ iter = OS.g_object_get_qdata (cell, Display.SWT_OBJECT_INDEX2); - if (iter != 0) item = _getItem (iter); - int /*long*/ columnHandle = OS.g_object_get_qdata (cell, Display.SWT_OBJECT_INDEX1); - int columnIndex = 0; - if (columnCount > 0) { - for (int i = 0; i < columnCount; i++) { - if (columns [i].handle == columnHandle) { - columnIndex = i; - break; - } - } - } - if (item != null) { - if (OS.GTK_IS_CELL_RENDERER_TOGGLE (cell) || (OS.GTK_IS_CELL_RENDERER_PIXBUF (cell) && (columnIndex != 0 || (style & SWT.CHECK) == 0))) { - drawFlags = (int)/*64*/flags; - drawState = SWT.FOREGROUND; - int /*long*/ [] ptr = new int /*long*/ [1]; - OS.gtk_tree_model_get (modelHandle, item.handle, Tree.BACKGROUND_COLUMN, ptr, -1); - if (ptr [0] == 0) { - int modelIndex = columnCount == 0 ? Tree.FIRST_COLUMN : columns [columnIndex].modelIndex; - OS.gtk_tree_model_get (modelHandle, item.handle, modelIndex + Tree.CELL_BACKGROUND, ptr, -1); - } - if (ptr [0] != 0) drawState |= SWT.BACKGROUND; - if ((flags & OS.GTK_CELL_RENDERER_SELECTED) != 0) drawState |= SWT.SELECTED; - if ((flags & OS.GTK_CELL_RENDERER_FOCUSED) != 0) drawState |= SWT.FOCUSED; - - GdkRectangle rect = new GdkRectangle (); - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter); - OS.gtk_tree_view_get_background_area (handle, path, columnHandle, rect); - OS.gtk_tree_path_free (path); - - if ((drawState & SWT.SELECTED) == 0) { - Control control = findBackgroundControl (); - if (control != null && control.backgroundImage != null) { - OS.gdk_window_clear_area (window, rect.x, rect.y, rect.width, rect.height); - } - } - - if (hooks (SWT.EraseItem)) { - boolean wasSelected = false; - if ((drawState & SWT.SELECTED) != 0) { - wasSelected = true; - OS.gdk_window_clear_area (window, rect.x, rect.y, rect.width, rect.height); - } - GC gc = new GC (this); - if ((drawState & SWT.SELECTED) != 0) { - gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION)); - gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT)); - } else { - gc.setBackground (item.getBackground (columnIndex)); - gc.setForeground (item.getForeground (columnIndex)); - } - gc.setFont (item.getFont (columnIndex)); - if ((style & SWT.MIRRORED) != 0) rect.x = getClientWidth () - rect.width - rect.x; - gc.setClipping (rect.x, rect.y, rect.width, rect.height); - Event event = new Event (); - event.item = item; - event.index = columnIndex; - event.gc = gc; - event.x = rect.x; - event.y = rect.y; - event.width = rect.width; - event.height = rect.height; - event.detail = drawState; - sendEvent (SWT.EraseItem, event); - drawForeground = null; - drawState = event.doit ? event.detail : 0; - drawFlags &= ~(OS.GTK_CELL_RENDERER_FOCUSED | OS.GTK_CELL_RENDERER_SELECTED); - if ((drawState & SWT.SELECTED) != 0) drawFlags |= OS.GTK_CELL_RENDERER_SELECTED; - if ((drawState & SWT.FOCUSED) != 0) drawFlags |= OS.GTK_CELL_RENDERER_FOCUSED; - if ((drawState & SWT.SELECTED) != 0) { - int /*long*/ style = OS.gtk_widget_get_style (widget); - //TODO - parity and sorted - byte[] detail = Converter.wcsToMbcs (null, "cell_odd", true); - OS.gtk_paint_flat_box (style, window, OS.GTK_STATE_SELECTED, OS.GTK_SHADOW_NONE, rect, widget, detail, rect.x, rect.y, rect.width, rect.height); - } else { - if (wasSelected) drawForeground = gc.getForeground ().handle; - } - gc.dispose(); - } - } - } - int /*long*/ result = 0; - if ((drawState & SWT.BACKGROUND) != 0 && (drawState & SWT.SELECTED) == 0) { - GC gc = new GC (this); - gc.setBackground (item.getBackground (columnIndex)); - GdkRectangle rect = new GdkRectangle (); - OS.memmove (rect, background_area, GdkRectangle.sizeof); - gc.fillRectangle (rect.x, rect.y, rect.width, rect.height); - gc.dispose (); - } - if ((drawState & SWT.FOREGROUND) != 0 || OS.GTK_IS_CELL_RENDERER_TOGGLE (cell)) { - int /*long*/ g_class = OS.g_type_class_peek_parent (OS.G_OBJECT_GET_CLASS (cell)); - GtkCellRendererClass klass = new GtkCellRendererClass (); - OS.memmove (klass, g_class); - if (drawForeground != null && OS.GTK_IS_CELL_RENDERER_TEXT (cell)) { - OS.g_object_set (cell, OS.foreground_gdk, drawForeground, 0); - } - result = OS.call (klass.render, cell, window, handle, background_area, cell_area, expose_area, drawFlags); - } - if (item != null) { - if (OS.GTK_IS_CELL_RENDERER_TEXT (cell)) { - if (hooks (SWT.PaintItem)) { - GdkRectangle rect = new GdkRectangle (); - GdkRectangle clipRect = new GdkRectangle (); - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, iter); - OS.gtk_tree_view_get_cell_area (handle, path, columnHandle, rect); - OS.gtk_tree_view_get_background_area (handle, path, columnHandle, clipRect); - OS.gtk_tree_path_free (path); - if (OS.GTK_VERSION < OS.VERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (handle) == columnHandle) { - int [] buffer = new int [1]; - OS.gtk_widget_style_get (handle, OS.expander_size, buffer, 0); - rect.x += buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING; - rect.width -= buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING; - //OS.gtk_widget_style_get (handle, OS.horizontal_separator, buffer, 0); - //rect.x += buffer[0]; - //rect.width -= buffer [0]; // TODO Is this required for some versions? - } - ignoreSize = true; - int [] contentX = new int [1], contentWidth = new int [1]; - OS.gtk_cell_renderer_get_size (cell, handle, null, null, null, contentWidth, null); - OS.gtk_tree_view_column_cell_get_position (columnHandle, cell, contentX, null); - ignoreSize = false; - Image image = item.getImage (columnIndex); - int imageWidth = 0; - if (image != null) { - Rectangle bounds = image.getBounds (); - imageWidth = bounds.width; - } - contentX [0] -= imageWidth; - contentWidth [0] += imageWidth; - GC gc = new GC (this); - if ((drawState & SWT.SELECTED) != 0) { - gc.setBackground (display.getSystemColor (SWT.COLOR_LIST_SELECTION)); - gc.setForeground (display.getSystemColor (SWT.COLOR_LIST_SELECTION_TEXT)); - } else { - gc.setBackground (item.getBackground (columnIndex)); - Color foreground = drawForeground != null ? Color.gtk_new (display, drawForeground) : item.getForeground (columnIndex); - gc.setForeground (foreground); - } - gc.setFont (item.getFont (columnIndex)); - if ((style & SWT.MIRRORED) != 0) { - rect.x = getClientWidth () - rect.width - rect.x; - clipRect.x = getClientWidth () - clipRect.width - clipRect.x; - } - gc.setClipping (clipRect.x, clipRect.y, clipRect.width, clipRect.height); - Event event = new Event (); - event.item = item; - event.index = columnIndex; - event.gc = gc; - event.x = rect.x + contentX [0]; - event.y = rect.y; - event.width = contentWidth [0]; - event.height = rect.height; - event.detail = drawState; - sendEvent (SWT.PaintItem, event); - gc.dispose(); - } - } - } - return result; -} - -void resetCustomDraw () { - if ((style & SWT.VIRTUAL) != 0 || ownerDraw) return; - int end = Math.max (1, columnCount); - for (int i=0; i<end; i++) { - boolean customDraw = columnCount != 0 ? columns [i].customDraw : firstCustomDraw; - if (customDraw) { - int /*long*/ column = OS.gtk_tree_view_get_column (handle, i); - int /*long*/ textRenderer = getTextRenderer (column); - OS.gtk_tree_view_column_set_cell_data_func (column, textRenderer, 0, 0, 0); - if (columnCount != 0) columns [i].customDraw = false; - } - } - firstCustomDraw = false; -} - -/** - * Display a mark indicating the point at which an item will be inserted. - * The drop insert item has a visual hint to show where a dragged item - * will be inserted when dropped on the tree. - * - * @param item the insert item. Null will clear the insertion mark. - * @param before true places the insert mark above 'item'. false places - * the insert mark below 'item'. - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the 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 setInsertMark (TreeItem item, boolean before) { - checkWidget (); - if (item == null) { - OS.gtk_tree_view_set_drag_dest_row(handle, 0, OS.GTK_TREE_VIEW_DROP_BEFORE); - return; - } - if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - if (item.parent != this) return; - Rectangle rect = item.getBounds(); - int /*long*/ [] path = new int /*long*/ [1]; - OS.gtk_widget_realize (handle); - if (!OS.gtk_tree_view_get_path_at_pos(handle, rect.x, rect.y, path, null, null, null)) return; - if (path [0] == 0) return; - int position = before ? OS.GTK_TREE_VIEW_DROP_BEFORE : OS.GTK_TREE_VIEW_DROP_AFTER; - OS.gtk_tree_view_set_drag_dest_row(handle, path[0], position); - OS.gtk_tree_path_free (path [0]); -} - -void setItemCount (int /*long*/ parentIter, int count) { - int itemCount = OS.gtk_tree_model_iter_n_children (modelHandle, parentIter); - if (count == itemCount) return; - boolean isVirtual = (style & SWT.VIRTUAL) != 0; - if (!isVirtual) setRedraw (false); - remove (parentIter, count, itemCount - 1); - if (isVirtual) { - if (fixAccessibility ()) { - ignoreAccessibility = true; - } - for (int i=itemCount; i<count; i++) { - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (iter == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_tree_store_append (modelHandle, iter, parentIter); - OS.gtk_tree_store_set (modelHandle, iter, ID_COLUMN, -1, -1); - OS.g_free (iter); - } - if (fixAccessibility ()) { - ignoreAccessibility = false; - OS.g_object_notify (handle, OS.model); - } - } else { - for (int i=itemCount; i<count; i++) { - new TreeItem (this, parentIter, SWT.NONE, i, true); - } - } - if (!isVirtual) setRedraw (true); - modelChanged = true; -} - -/** - * Sets the number of root-level items contained in the receiver. - * - * @param count 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> - * - * @since 3.2 - */ -public void setItemCount (int count) { - checkWidget (); - count = Math.max (0, count); - setItemCount (0, count); -} - -/** - * Selects an item in the receiver. If the item was already - * selected, it remains selected. - * - * @param item the item to be selected - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the item is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the 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> - * - * @since 3.4 - */ -public void select (TreeItem item) { - checkWidget (); - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - boolean fixColumn = showFirstColumn (); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_selection_select_iter (selection, item.handle); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if (fixColumn) hideFirstColumn (); -} - -/** - * Selects all of the items in the receiver. - * <p> - * If the receiver is single-select, do nothing. - * </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 selectAll () { - checkWidget(); - if ((style & SWT.SINGLE) != 0) return; - boolean fixColumn = showFirstColumn (); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_selection_select_all (selection); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if (fixColumn) hideFirstColumn (); -} - -void setBackgroundColor (GdkColor color) { - super.setBackgroundColor (color); - OS.gtk_widget_modify_base (handle, 0, color); -} - -void setBackgroundPixmap (int /*long*/ pixmap) { - super.setBackgroundPixmap (pixmap); - int /*long*/ window = paintWindow (); - if (window != 0) OS.gdk_window_set_back_pixmap (window, 0, true); -} - -int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { - int result = super.setBounds (x, y, width, height, move, resize); - /* - * Bug on GTK. The tree view sometimes does not get a paint - * event or resizes to a one pixel square when resized in a new - * shell that is not visible after any event loop has been run. The - * problem is intermittent. It doesn't seem to happen the first time - * a new shell is created. The fix is to ensure the tree view is realized - * after it has been resized. - */ - OS.gtk_widget_realize (handle); - /* - * Bug in GTK. An empty GtkTreeView fails to repaint the focus rectangle - * correctly when resized on versions before 2.6.0. The fix is to force - * the widget to redraw. - */ - if (OS.GTK_VERSION < OS.VERSION (2, 6, 0) && OS.gtk_tree_model_iter_n_children (modelHandle, 0) == 0) { - redraw (false); - } - return result; -} - -/** - * Sets the order that the items in the receiver should - * be displayed in to the given argument which is described - * in terms of the zero-relative ordering of when the items - * were added. - * - * @param order the new order to display the 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> - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the item order is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the item order is not the same length as the number of items</li> - * </ul> - * - * @see Tree#getColumnOrder() - * @see TreeColumn#getMoveable() - * @see TreeColumn#setMoveable(boolean) - * @see SWT#Move - * - * @since 3.2 - */ -public void setColumnOrder (int [] order) { - checkWidget (); - if (order == null) error (SWT.ERROR_NULL_ARGUMENT); - if (columnCount == 0) { - if (order.length > 0) error (SWT.ERROR_INVALID_ARGUMENT); - return; - } - if (order.length != columnCount) error (SWT.ERROR_INVALID_ARGUMENT); - boolean [] seen = new boolean [columnCount]; - for (int i = 0; i<order.length; i++) { - int index = order [i]; - if (index < 0 || index >= columnCount) error (SWT.ERROR_INVALID_RANGE); - if (seen [index]) error (SWT.ERROR_INVALID_ARGUMENT); - seen [index] = true; - } - int /*long*/ baseColumn = 0; - for (int i=0; i<order.length; i++) { - int /*long*/ column = columns [order [i]].handle; - OS.gtk_tree_view_move_column_after (handle, column, baseColumn); - baseColumn = column; - } -} - -void setFontDescription (int /*long*/ font) { - super.setFontDescription (font); - TreeColumn[] columns = getColumns (); - for (int i = 0; i < columns.length; i++) { - if (columns[i] != null) { - columns[i].setFontDescription (font); - } - } -} - -/** - * Marks the receiver's header 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 show 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.1 - */ -public void setHeaderVisible (boolean show) { - checkWidget (); - OS.gtk_tree_view_set_headers_visible (handle, show); -} - -/** - * Marks the receiver's lines as visible if the argument is <code>true</code>, - * and marks it invisible otherwise. Note that some platforms draw - * grid lines while others may draw alternating row colors. - * <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 show 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.1 - */ -public void setLinesVisible (boolean show) { - checkWidget(); - OS.gtk_tree_view_set_rules_hint (handle, show); - if (OS.GTK_VERSION >= OS.VERSION (2, 12, 0)) { - OS.gtk_tree_view_set_grid_lines (handle, show ? OS.GTK_TREE_VIEW_GRID_LINES_VERTICAL : OS.GTK_TREE_VIEW_GRID_LINES_NONE); - } -} - -void setParentBackground () { - super.setParentBackground (); - int /*long*/ window = paintWindow (); - if (window != 0) OS.gdk_window_set_back_pixmap (window, 0, true); -} - -void setParentWindow (int /*long*/ widget) { - int /*long*/ window = eventWindow (); - OS.gtk_widget_set_parent_window (widget, window); -} - -void setScrollWidth (int /*long*/ column, TreeItem item) { - if (columnCount != 0 || currentItem == item) return; - /* - * Use GTK_TREE_VIEW_COLUMN_GROW_ONLY on GTK versions < 2.3.2 - * because fixed_height_mode is not supported. - */ - if (((style & SWT.VIRTUAL) != 0) && OS.GTK_VERSION < OS.VERSION (2, 3, 2)) return; - int width = OS.gtk_tree_view_column_get_fixed_width (column); - int itemWidth = calculateWidth (column, item.handle, true); - if (width < itemWidth) { - OS.gtk_tree_view_column_set_fixed_width (column, itemWidth); - } -} - -/** - * Sets the receiver's selection to the given item. - * The current selection is cleared before the new item is selected. - * <p> - * If the item is not in the receiver, then it is ignored. - * </p> - * - * @param item the item to select - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the item is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the 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> - * - * @since 3.2 - */ -public void setSelection (TreeItem item) { - checkWidget (); - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - setSelection (new TreeItem [] {item}); -} - -/** - * 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. - * </p> - * - * @param items the array of items - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the array of items is null</li> - * <li>ERROR_INVALID_ARGUMENT - if one of the items 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 Tree#deselectAll() - */ -public void setSelection (TreeItem [] items) { - checkWidget (); - if (items == null) error (SWT.ERROR_NULL_ARGUMENT); - deselectAll (); - int length = items.length; - if (length == 0 || ((style & SWT.SINGLE) != 0 && length > 1)) return; - boolean fixColumn = showFirstColumn (); - int /*long*/ selection = OS.gtk_tree_view_get_selection (handle); - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - boolean first = true; - for (int i = 0; i < length; i++) { - TreeItem item = items [i]; - if (item == null) continue; - if (item.isDisposed ()) break; - if (item.parent != this) continue; - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, item.handle); - showItem (path, false); - if (first) { - OS.gtk_tree_view_set_cursor (handle, path, 0, false); - } - OS.gtk_tree_selection_select_iter (selection, item.handle); - OS.gtk_tree_path_free (path); - first = false; - } - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - if (fixColumn) hideFirstColumn (); -} - -/** - * Sets the column used by the sort indicator for the receiver. A null - * value will clear the sort indicator. The current sort column is cleared - * before the new column is set. - * - * @param column the column used by the sort indicator or <code>null</code> - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the column is 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 setSortColumn (TreeColumn column) { - checkWidget (); - if (column != null && column.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); - if (sortColumn != null && !sortColumn.isDisposed()) { - OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, false); - } - sortColumn = column; - if (sortColumn != null && sortDirection != SWT.NONE) { - OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, true); - OS.gtk_tree_view_column_set_sort_order (sortColumn.handle, sortDirection == SWT.DOWN ? 0 : 1); - } -} - -/** - * Sets the direction of the sort indicator for the receiver. The value - * can be one of <code>UP</code>, <code>DOWN</code> or <code>NONE</code>. - * - * @param direction the direction of the sort indicator - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 setSortDirection (int direction) { - checkWidget (); - if (direction != SWT.UP && direction != SWT.DOWN && direction != SWT.NONE) return; - sortDirection = direction; - if (sortColumn == null || sortColumn.isDisposed ()) return; - if (sortDirection == SWT.NONE) { - OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, false); - } else { - OS.gtk_tree_view_column_set_sort_indicator (sortColumn.handle, true); - OS.gtk_tree_view_column_set_sort_order (sortColumn.handle, sortDirection == SWT.DOWN ? 0 : 1); - } -} - -/** - * Sets the item which is currently at the top of the receiver. - * This item can change when items are expanded, collapsed, scrolled - * or new items are added or removed. - * - * @param item the item to be shown - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the item is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the 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> - * - * @see Tree#getTopItem() - * - * @since 2.1 - */ -public void setTopItem (TreeItem item) { - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - if (item.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT); - if (item.parent != this) return; - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, item.handle); - showItem (path, false); - OS.gtk_tree_view_scroll_to_cell (handle, path, 0, true, 0f, 0f); - if (OS.GTK_VERSION < OS.VERSION (2, 8, 0)) { - /* - * Bug in GTK. According to the documentation, gtk_tree_view_scroll_to_cell - * should vertically scroll the cell to the top if use_align is true and row_align is 0. - * However, prior to version 2.8 it does not scroll at all. The fix is to determine - * the new location and use gtk_tree_view_scroll_to_point. - * If the widget is a pinhead, calling gtk_tree_view_scroll_to_point - * will have no effect. Therefore, it is still neccessary to call - * gtk_tree_view_scroll_to_cell. - */ - OS.gtk_widget_realize (handle); - GdkRectangle cellRect = new GdkRectangle (); - OS.gtk_tree_view_get_cell_area (handle, path, 0, cellRect); - int[] tx = new int[1], ty = new int[1]; - OS.gtk_tree_view_widget_to_tree_coords(handle, cellRect.x, cellRect.y, tx, ty); - OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0]); - } - OS.gtk_tree_path_free (path); -} - -/** - * Shows the column. If the column is already showing in the receiver, - * this method simply returns. Otherwise, the columns are scrolled until - * the column is visible. - * - * @param column the column to be shown - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the item is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the 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> - * - * @since 3.1 - */ -public void showColumn (TreeColumn column) { - checkWidget (); - if (column == null) error (SWT.ERROR_NULL_ARGUMENT); - if (column.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); - if (column.parent != this) return; - /* - * This code is intentionally commented. According to the - * documentation, gtk_tree_view_scroll_to_cell should scroll the - * minimum amount to show the column but instead it scrolls strangely. - */ - //OS.gtk_tree_view_scroll_to_cell (handle, 0, column.handle, false, 0, 0); - OS.gtk_widget_realize (handle); - GdkRectangle cellRect = new GdkRectangle (); - OS.gtk_tree_view_get_cell_area (handle, 0, column.handle, cellRect); - GdkRectangle visibleRect = new GdkRectangle (); - OS.gtk_tree_view_get_visible_rect (handle, visibleRect); - if (cellRect.x < visibleRect.x) { - OS.gtk_tree_view_scroll_to_point (handle, cellRect.x, -1); - } else { - int width = Math.min (visibleRect.width, cellRect.width); - if (cellRect.x + width > visibleRect.x + visibleRect.width) { - int tree_x = cellRect.x + width - visibleRect.width; - OS.gtk_tree_view_scroll_to_point (handle, tree_x, -1); - } - } -} - -boolean showFirstColumn () { - /* - * Bug in GTK. If no columns are visible, changing the selection - * will fail. The fix is to temporarily make a column visible. - */ - int columnCount = Math.max (1, this.columnCount); - for (int i=0; i<columnCount; i++) { - int /*long*/ column = OS.gtk_tree_view_get_column (handle, i); - if (OS.gtk_tree_view_column_get_visible (column)) return false; - } - int /*long*/ firstColumn = OS.gtk_tree_view_get_column (handle, 0); - OS.gtk_tree_view_column_set_visible (firstColumn, true); - return true; -} - -/** - * 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> - * - * @see Tree#showItem(TreeItem) - */ -public void showSelection () { - checkWidget(); - TreeItem [] items = getSelection (); - if (items.length != 0 && items [0] != null) showItem (items [0]); -} - -void showItem (int /*long*/ path, boolean scroll) { - int depth = OS.gtk_tree_path_get_depth (path); - if (depth > 1) { - int [] indices = new int [depth - 1]; - int /*long*/ indicesPtr = OS.gtk_tree_path_get_indices (path); - OS.memmove (indices, indicesPtr, indices.length * 4); - int /*long*/ tempPath = OS.gtk_tree_path_new (); - for (int i=0; i<indices.length; i++) { - OS.gtk_tree_path_append_index (tempPath, indices [i]); - OS.gtk_tree_view_expand_row (handle, tempPath, false); - } - OS.gtk_tree_path_free (tempPath); - } - if (scroll) { - OS.gtk_widget_realize (handle); - GdkRectangle cellRect = new GdkRectangle (); - OS.gtk_tree_view_get_cell_area (handle, path, 0, cellRect); - boolean isHidden = cellRect.y == 0 && cellRect.height == 0; - int [] tx = new int [1], ty = new int [1]; - OS.gtk_tree_view_widget_to_tree_coords (handle, cellRect.x, cellRect.y, tx, ty); - GdkRectangle visibleRect = new GdkRectangle (); - OS.gtk_tree_view_get_visible_rect (handle, visibleRect); - if (!isHidden) { - if (ty[0] < visibleRect.y || ty[0] + cellRect.height > visibleRect.y + visibleRect.height) { - isHidden = true; - } - } - if (isHidden) { - /* - * This code intentionally commented. - * Bug in GTK. According to the documentation, gtk_tree_view_scroll_to_cell - * should scroll the minimum amount to show the cell if use_align is false. - * However, what actually happens is the cell is scrolled to the top. - * The fix is to determine the new location and use gtk_tree_view_scroll_to_point. - * If the widget is a pinhead, calling gtk_tree_view_scroll_to_point - * will have no effect. Therefore, it is still neccessary to - * call gtk_tree_view_scroll_to_cell. - */ - // OS.gtk_tree_view_scroll_to_cell (handle, path, 0, depth != 1, 0.5f, 0.0f); - if (depth != 1) { - OS.gtk_tree_view_scroll_to_cell (handle, path, 0, true, 0.5f, 0.0f); - } else { - if (ty[0] < visibleRect.y ) { - OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0]); - } else { - int height = Math.min (visibleRect.height, cellRect.height); - if (ty[0] + height > visibleRect.y + visibleRect.height) { - OS.gtk_tree_view_scroll_to_point (handle, -1, ty[0] + cellRect.height - visibleRect.height); - } - } - } - } - } -} - -/** - * Shows the item. If the item is already showing in the receiver, - * this method simply returns. Otherwise, the items are scrolled - * and expanded until the item is visible. - * - * @param item the item to be shown - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the item is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the 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> - * - * @see Tree#showSelection() - */ -public void showItem (TreeItem item) { - checkWidget (); - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - if (item.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT); - if (item.parent != this) return; - int /*long*/ path = OS.gtk_tree_model_get_path (modelHandle, item.handle); - showItem (path, true); - OS.gtk_tree_path_free (path); -} - -int /*long*/ treeSelectionProc (int /*long*/ model, int /*long*/ path, int /*long*/ iter, int[] selection, int length) { - if (selection != null) { - int [] index = new int [1]; - OS.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, index, -1); - selection [(int)/*64*/length] = index [0]; - } - return 0; -} - -void updateScrollBarValue (ScrollBar bar) { - super.updateScrollBarValue (bar); - /* - * Bug in GTK. Scrolling changes the XWindow position - * and makes the child widgets appear to scroll even - * though when queried their position is unchanged. - * The fix is to queue a resize event for each child to - * force the position to be corrected. - */ - int /*long*/ parentHandle = parentingHandle (); - int /*long*/ list = OS.gtk_container_get_children (parentHandle); - if (list == 0) return; - int /*long*/ temp = list; - while (temp != 0) { - int /*long*/ widget = OS.g_list_data (temp); - if (widget != 0) OS.gtk_widget_queue_resize (widget); - temp = OS.g_list_next (temp); - } - OS.g_list_free (list); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java deleted file mode 100644 index a3b6ee52ff..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java +++ /dev/null @@ -1,697 +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.gtk.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Instances of this class represent a column in a tree widget. - * <p><dl> - * <dt><b>Styles:</b></dt> - * <dd>LEFT, RIGHT, CENTER</dd> - * <dt><b>Events:</b></dt> - * <dd> Move, Resize, Selection</dd> - * </dl> - * </p><p> - * Note: Only one of the styles LEFT, RIGHT and CENTER 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/#tree">Tree, TreeItem, TreeColumn snippets</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 TreeColumn extends Item { - int /*long*/ labelHandle, imageHandle, buttonHandle; - Tree parent; - int modelIndex, lastButton, lastTime, lastX, lastWidth; - boolean customDraw, useFixedWidth; - String toolTipText; - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Tree</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#LEFT - * @see SWT#RIGHT - * @see SWT#CENTER - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TreeColumn (Tree parent, int style) { - super (parent, checkStyle (style)); - this.parent = parent; - createWidget (parent.getColumnCount ()); -} - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Tree</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> - * <p> - * Note that due to a restriction on some platforms, the first column - * is always left aligned. - * </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#LEFT - * @see SWT#RIGHT - * @see SWT#CENTER - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TreeColumn (Tree parent, int style, int index) { - super (parent, checkStyle (style)); - this.parent = parent; - createWidget (index); -} - -/** - * 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 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 column header is selected. - * <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.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0); -} - -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} - -void createWidget (int index) { - parent.createItem (this, index); - setOrientation (); - hookEvents (); - register (); - text = ""; -} - -void deregister() { - super.deregister (); - display.removeWidget (handle); - if (buttonHandle != 0) display.removeWidget (buttonHandle); - if (labelHandle != 0) display.removeWidget (labelHandle); -} - -void destroyWidget () { - parent.destroyItem (this); - releaseHandle (); -} - -/** - * 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>. - * - * @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.LEFT) != 0) return SWT.LEFT; - if ((style & SWT.CENTER) != 0) return SWT.CENTER; - if ((style & SWT.RIGHT) != 0) return SWT.RIGHT; - return SWT.LEFT; -} - -/** - * Gets the moveable attribute. A column that is - * not moveable cannot be reordered by the user - * by dragging the header but may be reordered - * by the programmer. - * - * @return the moveable attribute - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 Tree#getColumnOrder() - * @see Tree#setColumnOrder(int[]) - * @see TreeColumn#setMoveable(boolean) - * @see SWT#Move - * - * @since 3.2 - */ -public boolean getMoveable() { - checkWidget(); - return OS.gtk_tree_view_column_get_reorderable (handle); -} - -/** - * Returns the receiver's parent, which must be a <code>Tree</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 Tree getParent () { - checkWidget(); - return parent; -} - -/** - * Gets the resizable attribute. A column that is - * not resizable cannot be dragged by the user but - * may be resized by the programmer. - * - * @return the resizable attribute - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 getResizable () { - checkWidget(); - return OS.gtk_tree_view_column_get_resizable (handle); -} - -/** - * 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> - * - * @since 3.2 - */ -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(); - if (!OS.gtk_tree_view_column_get_visible (handle)) { - return 0; - } - if (useFixedWidth) return OS.gtk_tree_view_column_get_fixed_width (handle); - return OS.gtk_tree_view_column_get_width (handle); -} - -int /*long*/ gtk_clicked (int /*long*/ widget) { - /* - * There is no API to get a double click on a table column. Normally, when - * the mouse is double clicked, this is indicated by GDK_2BUTTON_PRESS - * but the table column sends the click signal on button release. The fix is to - * test for double click by remembering the last click time and mouse button - * and testing for the double click interval. - */ - boolean doubleClick = false; - boolean postEvent = true; - int /*long*/ eventPtr = OS.gtk_get_current_event (); - if (eventPtr != 0) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, eventPtr, GdkEventButton.sizeof); - OS.gdk_event_free (eventPtr); - switch (gdkEvent.type) { - case OS.GDK_BUTTON_RELEASE: { - int clickTime = display.getDoubleClickTime (); - int eventTime = gdkEvent.time, eventButton = gdkEvent.button; - if (lastButton == eventButton && lastTime != 0 && Math.abs (lastTime - eventTime) <= clickTime) { - doubleClick = true; - } - lastTime = eventTime == 0 ? 1: eventTime; - lastButton = eventButton; - break; - } - case OS.GDK_MOTION_NOTIFY: { - /* - * Bug in GTK. Dragging a column in a GtkTreeView causes a clicked - * signal to be emitted even though the mouse button was never released. - * The fix to ignore the signal if the current GDK event is a motion notify. - * The GTK bug was fixed in version 2.6 - */ - if (OS.GTK_VERSION < OS.VERSION (2, 6, 0)) postEvent = false; - break; - } - } - } - if (postEvent) postEvent (doubleClick ? SWT.DefaultSelection : SWT.Selection); - return 0; -} - -int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) { - GdkEvent event = new GdkEvent (); - OS.memmove (event, gdkEvent, GdkEvent.sizeof); - switch (event.type) { - case OS.GDK_BUTTON_PRESS: { - GdkEventButton gdkEventButton = new GdkEventButton (); - OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof); - if (gdkEventButton.button == 3) { - parent.showMenu ((int) gdkEventButton.x_root, (int) gdkEventButton.y_root); - } - break; - } - } - return 0; -} - -int /*long*/ gtk_mnemonic_activate (int /*long*/ widget, int /*long*/ arg1) { - return parent.gtk_mnemonic_activate (widget, arg1); -} - -int /*long*/ gtk_size_allocate (int /*long*/ widget, int /*long*/ allocation) { - useFixedWidth = false; - int x = OS.GTK_WIDGET_X (widget); - int width = OS.GTK_WIDGET_WIDTH (widget); - if (x != lastX) { - lastX = x; - sendEvent (SWT.Move); - } - if (width != lastWidth) { - lastWidth = width; - sendEvent (SWT.Resize); - } - return 0; -} - -void hookEvents () { - super.hookEvents (); - OS.g_signal_connect_closure (handle, OS.clicked, display.closures [CLICKED], false); - if (buttonHandle != 0) { - OS.g_signal_connect_closure_by_id (buttonHandle, display.signalIds [SIZE_ALLOCATE], 0, display.closures [SIZE_ALLOCATE], false); - OS.g_signal_connect_closure_by_id (buttonHandle, display.signalIds [EVENT_AFTER], 0, display.closures [EVENT_AFTER], false); - } - if (labelHandle != 0) OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false); -} - -/** - * 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> - * - */ -public void pack () { - checkWidget(); - int width = 0; - if (buttonHandle != 0) { - GtkRequisition requisition = new GtkRequisition (); - OS.gtk_widget_size_request (buttonHandle, requisition); - width = requisition.width; - } - if ((parent.style & SWT.VIRTUAL) != 0) { - //NOT DONE - } else { - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (OS.gtk_tree_model_get_iter_first (parent.modelHandle, iter)) { - do { - width = Math.max (width, parent.calculateWidth (handle, iter, true)); - } while (OS.gtk_tree_model_iter_next(parent.modelHandle, iter)); - } - OS.g_free (iter); - } - setWidth(width); -} - -void register () { - super.register (); - display.addWidget (handle, this); - if (buttonHandle != 0) display.addWidget (buttonHandle, this); - if (labelHandle != 0) display.addWidget (labelHandle, this); -} - -void releaseHandle () { - super.releaseHandle (); - handle = buttonHandle = labelHandle = imageHandle = 0; - modelIndex = -1; - parent = null; -} - -void releaseParent () { - super.releaseParent (); - if (parent.sortColumn == this) { - parent.sortColumn = 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 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); -} - -/** - * 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>. - * <p> - * Note that due to a restriction on some platforms, the first column - * is always left aligned. - * </p> - * @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 ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return; - int index = parent.indexOf (this); - if (index == -1 || index == 0) return; - style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER); - style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER); - parent.createRenderers (handle, modelIndex, index == 0, style); -} - -void setFontDescription (int /*long*/ font) { - OS.gtk_widget_modify_font (labelHandle, font); - OS.gtk_widget_modify_font (imageHandle, font); -} - -public void setImage (Image image) { - checkWidget (); - super.setImage (image); - if (image != null) { - ImageList headerImageList = parent.headerImageList; - if (headerImageList == null) { - headerImageList = parent.headerImageList = new ImageList (); - } - int imageIndex = headerImageList.indexOf (image); - if (imageIndex == -1) imageIndex = headerImageList.add (image); - int /*long*/ pixbuf = headerImageList.getPixbuf (imageIndex); - OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); - OS.gtk_widget_show (imageHandle); - } else { - OS.gtk_image_set_from_pixbuf (imageHandle, 0); - OS.gtk_widget_hide (imageHandle); - } -} - -/** - * Sets the moveable attribute. A column that is - * moveable can be reordered by the user by dragging - * the header. A column that is not moveable cannot be - * dragged by the user but may be reordered - * by the programmer. - * - * @param moveable the moveable attribute - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 Tree#setColumnOrder(int[]) - * @see Tree#getColumnOrder() - * @see TreeColumn#getMoveable() - * @see SWT#Move - * - * @since 3.2 - */ -public void setMoveable (boolean moveable) { - checkWidget(); - OS.gtk_tree_view_column_set_reorderable (handle, moveable); -} - -void setOrientation() { - if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) { - if (buttonHandle != 0) { - OS.gtk_widget_set_direction (buttonHandle, OS.GTK_TEXT_DIR_RTL); - OS.gtk_container_forall (buttonHandle, display.setDirectionProc, OS.GTK_TEXT_DIR_RTL); - } - } -} - -/** - * Sets the resizable attribute. A column that is - * not resizable cannot be dragged by the user but - * may be resized by the programmer. - * - * @param resizable the resize attribute - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 setResizable (boolean resizable) { - checkWidget(); - OS.gtk_tree_view_column_set_resizable (handle, resizable); -} - -public void setText (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - super.setText (string); - char [] chars = fixMnemonic (string); - byte [] buffer = Converter.wcsToMbcs (null, chars, true); - OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer); - if (string.length () != 0) { - OS.gtk_widget_show (labelHandle); - } else { - OS.gtk_widget_hide (labelHandle); - } -} - -/** - * 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> - * - * @since 3.2 - */ -public void setToolTipText (String string) { - checkWidget(); - Shell shell = parent._getShell (); - setToolTipText (shell, string); - toolTipText = string; -} - -void setToolTipText (Shell shell, String newString) { - shell.setToolTipText (buttonHandle, newString); -} - -/** - * Sets the width of the receiver. - * - * @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 (width < 0) return; - if (width == lastWidth) return; - if (width > 0) { - useFixedWidth = true; - OS.gtk_tree_view_column_set_fixed_width (handle, width); - } - /* - * Bug in GTK. For some reason, calling gtk_tree_view_column_set_visible() - * when the parent is not realized fails to show the column. The fix is to - * ensure that the table has been realized. - */ - if (width != 0) OS.gtk_widget_realize (parent.handle); - OS.gtk_tree_view_column_set_visible (handle, width != 0); - lastWidth = width; - sendEvent (SWT.Resize); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java deleted file mode 100644 index 1102499b31..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeItem.java +++ /dev/null @@ -1,1769 +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.gtk.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class represent a selectable user interface object - * that represents a hierarchy of tree items in a tree widget. - * - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see <a href="http://www.eclipse.org/swt/snippets/#tree">Tree, TreeItem, TreeColumn 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 TreeItem extends Item { - Tree parent; - Font font; - Font[] cellFont; - boolean cached, grayed; - static final int EXPANDER_EXTRA_PADDING = 4; - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Tree</code> or a <code>TreeItem</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 tree 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 TreeItem (Tree parent, int style) { - this (checkNull (parent), 0, style, -1, true); -} - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Tree</code> or a <code>TreeItem</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 tree 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 - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TreeItem (Tree parent, int style, int index) { - this (checkNull (parent), 0, style, checkIndex (index), true); -} - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Tree</code> or a <code>TreeItem</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 parentItem a tree 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 TreeItem (TreeItem parentItem, int style) { - this (checkNull (parentItem).parent, parentItem.handle, style, -1, true); -} - -/** - * Constructs a new instance of this class given its parent - * (which must be a <code>Tree</code> or a <code>TreeItem</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 parentItem a tree 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 - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public TreeItem (TreeItem parentItem, int style, int index) { - this (checkNull (parentItem).parent, parentItem.handle, style, checkIndex (index), true); -} - -TreeItem (Tree parent, int /*long*/ parentIter, int style, int index, boolean create) { - super (parent, style); - this.parent = parent; - if (create) { - parent.createItem (this, parentIter, index); - } else { - handle = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - OS.gtk_tree_model_iter_nth_child (parent.modelHandle, handle, parentIter, index); - } -} - -static int checkIndex (int index) { - if (index < 0) SWT.error (SWT.ERROR_INVALID_RANGE); - return index; -} - -static TreeItem checkNull (TreeItem item) { - if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); - return item; -} - -static Tree checkNull (Tree control) { - if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); - return control; -} - -protected void checkSubclass () { - if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); -} - -Color _getBackground () { - int /*long*/ [] ptr = new int /*long*/ [1]; - OS.gtk_tree_model_get (parent.modelHandle, handle, Tree.BACKGROUND_COLUMN, ptr, -1); - if (ptr [0] == 0) return parent.getBackground (); - GdkColor gdkColor = new GdkColor (); - OS.memmove (gdkColor, ptr [0], GdkColor.sizeof); - return Color.gtk_new (display, gdkColor); -} - -Color _getBackground (int index) { - int count = Math.max (1, parent.columnCount); - if (0 > index || index > count - 1) return _getBackground (); - int /*long*/ [] ptr = new int /*long*/ [1]; - int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; - OS.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Tree.CELL_BACKGROUND, ptr, -1); - if (ptr [0] == 0) return _getBackground (); - GdkColor gdkColor = new GdkColor (); - OS.memmove (gdkColor, ptr [0], GdkColor.sizeof); - return Color.gtk_new (display, gdkColor); -} - -boolean _getChecked () { - int /*long*/ [] ptr = new int /*long*/ [1]; - OS.gtk_tree_model_get (parent.modelHandle, handle, Tree.CHECKED_COLUMN, ptr, -1); - return ptr [0] != 0; -} - -Color _getForeground () { - int /*long*/ [] ptr = new int /*long*/ [1]; - OS.gtk_tree_model_get (parent.modelHandle, handle, Tree.FOREGROUND_COLUMN, ptr, -1); - if (ptr [0] == 0) return parent.getForeground (); - GdkColor gdkColor = new GdkColor (); - OS.memmove (gdkColor, ptr [0], GdkColor.sizeof); - return Color.gtk_new (display, gdkColor); -} - -Color _getForeground (int index) { - int count = Math.max (1, parent.columnCount); - if (0 > index || index > count - 1) return _getForeground (); - int /*long*/ [] ptr = new int /*long*/ [1]; - int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; - OS.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Tree.CELL_FOREGROUND, ptr, -1); - if (ptr [0] == 0) return _getForeground (); - GdkColor gdkColor = new GdkColor (); - OS.memmove (gdkColor, ptr [0], GdkColor.sizeof); - return Color.gtk_new (display, gdkColor); -} - -Image _getImage (int index) { - int count = Math.max (1, parent.getColumnCount ()); - if (0 > index || index > count - 1) return null; - int /*long*/ [] ptr = new int /*long*/ [1]; - int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; - OS.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Tree.CELL_PIXBUF, ptr, -1); - if (ptr [0] == 0) return null; - ImageList imageList = parent.imageList; - int imageIndex = imageList.indexOf (ptr [0]); - if (imageIndex == -1) return null; - return imageList.get (imageIndex); -} - -String _getText (int index) { - int count = Math.max (1, parent.getColumnCount ()); - if (0 > index || index > count - 1) return ""; - int /*long*/ [] ptr = new int /*long*/ [1]; - int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; - OS.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Tree.CELL_TEXT, ptr, -1); - if (ptr [0] == 0) return ""; //$NON-NLS-1$ - int length = OS.strlen (ptr [0]); - byte[] buffer = new byte [length]; - OS.memmove (buffer, ptr [0], length); - OS.g_free (ptr [0]); - return new String (Converter.mbcsToWcs (null, buffer)); -} - -void clear () { - if (parent.currentItem == this) return; - if (cached || (parent.style & SWT.VIRTUAL) == 0) { - int columnCount = OS.gtk_tree_model_get_n_columns (parent.modelHandle); - for (int i=Tree.CHECKED_COLUMN; i<columnCount; i++) { - OS.gtk_tree_store_set (parent.modelHandle, handle, i, 0, -1); - } - /* - * Bug in GTK. When using fixed-height-mode, - * row changes do not cause the row to be repainted. The fix is to - * invalidate the row when it is cleared. - */ - if ((parent.style & SWT.VIRTUAL) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) { - redraw (); - } - } - } - cached = false; - font = null; - cellFont = null; -} - -/** - * Clears the item at the given zero-relative index in the receiver. - * The text, icon and other attributes of the item are set to the default - * value. If the tree was created with the <code>SWT.VIRTUAL</code> style, - * these attributes are requested again as needed. - * - * @param index the index of the item to clear - * @param all <code>true</code> if all child items of the indexed item should be - * cleared recursively, and <code>false</code> otherwise - * - * @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> - * - * @see SWT#VIRTUAL - * @see SWT#SetData - * - * @since 3.2 - */ -public void clear (int index, boolean all) { - checkWidget (); - parent.clear (handle, index, all); -} - -/** - * Clears all the items in the receiver. The text, icon and other - * attributes of the items are set to their default values. If the - * tree was created with the <code>SWT.VIRTUAL</code> style, these - * attributes are requested again as needed. - * - * @param all <code>true</code> if all child items should be cleared - * recursively, 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 SWT#VIRTUAL - * @see SWT#SetData - * - * @since 3.2 - */ -public void clearAll (boolean all) { - checkWidget (); - parent.clearAll (all, handle); -} - -void destroyWidget () { - parent.releaseItem (this, false); - parent.destroyItem (this); - releaseHandle (); -} - -/** - * Returns the receiver's background color. - * - * @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> - * - * @since 2.0 - * - */ -public Color getBackground () { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return _getBackground (); -} - -/** - * Returns the background color at the given column index in the receiver. - * - * @param index the column index - * @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> - * - * @since 3.1 - */ -public Color getBackground (int index) { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return _getBackground (index); -} - -/** - * Returns a rectangle describing the receiver's size and location - * relative to its parent at a column in the tree. - * - * @param index the index that specifies the column - * @return the receiver's bounding column 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> - * - * @since 3.1 - */ -public Rectangle getBounds (int index) { - // TODO fully test on early and later versions of GTK - checkWidget(); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - int /*long*/ parentHandle = parent.handle; - int /*long*/ column = 0; - if (index >= 0 && index < parent.columnCount) { - column = parent.columns [index].handle; - } else { - column = OS.gtk_tree_view_get_column (parentHandle, index); - } - if (column == 0) return new Rectangle (0, 0, 0, 0); - int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); - OS.gtk_widget_realize (parentHandle); - GdkRectangle rect = new GdkRectangle (); - OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect); - if ((parent.getStyle () & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth () - rect.width - rect.x; - - if (OS.GTK_VERSION < OS.VERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) == column) { - int [] buffer = new int [1]; - OS.gtk_widget_style_get (parentHandle, OS.expander_size, buffer, 0); - rect.x += buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING; - rect.width -= buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING; - OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0); - rect.x += buffer [0]; - //rect.width -= buffer [0]; // TODO Is this required for some versions? - } - /* - * Bug in GTK. In GTK 2.8.x, the cell area is left aligned even - * when the widget is mirrored. The fix is to sum up the indentation - * of the expanders. - */ - if ((parent.getStyle () & SWT.MIRRORED) != 0 && (OS.GTK_VERSION < OS.VERSION (2, 10, 0))) { - int depth = OS.gtk_tree_path_get_depth (path); - int [] expanderSize = new int [1]; - OS.gtk_widget_style_get (parentHandle, OS.expander_size, expanderSize, 0); - rect.x += depth * (expanderSize[0] + TreeItem.EXPANDER_EXTRA_PADDING); - } - OS.gtk_tree_path_free (path); - - if (index == 0 && (parent.style & SWT.CHECK) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 1, 3)) { - int [] x = new int [1], w = new int [1]; - OS.gtk_tree_view_column_cell_get_position (column, parent.checkRenderer, x, w); - rect.x += x [0] + w [0]; - rect.width -= x [0] + w [0]; - } else { - int [] w = new int [1]; - OS.gtk_cell_renderer_get_size (parent.checkRenderer, parentHandle, null, null, null, w, null); - int [] buffer = new int [1]; - OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0); - rect.x += w [0] + buffer [0]; - rect.width -= w [0] + buffer [0]; - } - } - int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0; - return new Rectangle (rect.x, rect.y, width, rect.height + 1); -} - -/** - * 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 () { - // TODO fully test on early and later versions of GTK - // shifted a bit too far right on later versions of GTK - however, old Tree also had this problem - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - int /*long*/ parentHandle = parent.handle; - int /*long*/ column = OS.gtk_tree_view_get_column (parentHandle, 0); - if (column == 0) return new Rectangle (0, 0, 0, 0); - int /*long*/ textRenderer = parent.getTextRenderer (column); - int /*long*/ pixbufRenderer = parent.getPixbufRenderer (column); - if (textRenderer == 0 || pixbufRenderer == 0) return new Rectangle (0, 0, 0, 0); - - int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); - OS.gtk_widget_realize (parentHandle); - - boolean isExpander = OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle) > 0; - boolean isExpanded = OS.gtk_tree_view_row_expanded (parentHandle, path); - OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, isExpander, isExpanded); - - GdkRectangle rect = new GdkRectangle (); - OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect); - if ((parent.getStyle () & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth () - rect.width - rect.x; - int right = rect.x + rect.width; - - int [] x = new int [1], w = new int [1]; - parent.ignoreSize = true; - OS.gtk_cell_renderer_get_size (textRenderer, parentHandle, null, null, null, w, null); - parent.ignoreSize = false; - rect.width = w [0]; - int [] buffer = new int [1]; - if (OS.GTK_VERSION < OS.VERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) == column) { - OS.gtk_widget_style_get (parentHandle, OS.expander_size, buffer, 0); - rect.x += buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING; - } - /* - * Bug in GTK. In GTK 2.8.x, the cell area is left aligned even - * when the widget is mirrored. The fix is to sum up the indentation - * of the expanders. - */ - if ((parent.getStyle () & SWT.MIRRORED) != 0 && (OS.GTK_VERSION < OS.VERSION (2, 10, 0))) { - int depth = OS.gtk_tree_path_get_depth (path); - int [] expanderSize = new int [1]; - OS.gtk_widget_style_get (parentHandle, OS.expander_size, expanderSize, 0); - rect.x += depth * (expanderSize[0] + TreeItem.EXPANDER_EXTRA_PADDING); - } - OS.gtk_tree_path_free (path); - - OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0); - int horizontalSeparator = buffer[0]; - rect.x += horizontalSeparator; - - if (OS.GTK_VERSION >= OS.VERSION (2, 1, 3)) { - OS.gtk_tree_view_column_cell_get_position (column, textRenderer, x, null); - rect.x += x [0]; - } else { - if ((parent.style & SWT.CHECK) != 0) { - OS.gtk_cell_renderer_get_size (parent.checkRenderer, parentHandle, null, null, null, w, null); - rect.x += w [0] + horizontalSeparator; - } - OS.gtk_cell_renderer_get_size (pixbufRenderer, parentHandle, null, null, null, w, null); - rect.x += w [0] + horizontalSeparator; - } - if (parent.columnCount > 0) { - if (rect.x + rect.width > right) { - rect.width = Math.max (0, right - rect.x); - } - } - int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0; - return new Rectangle (rect.x, rect.y, width, rect.height + 1); -} - -/** - * Returns <code>true</code> if the receiver is checked, - * and false otherwise. When the parent does not have - * the <code>CHECK style, return false. - * <p> - * - * @return the checked 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 getChecked () { - checkWidget(); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - if ((parent.style & SWT.CHECK) == 0) return false; - return _getChecked (); -} - -/** - * Returns <code>true</code> if the receiver is expanded, - * and false otherwise. - * <p> - * - * @return the expanded 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 getExpanded () { - checkWidget(); - int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); - boolean answer = OS.gtk_tree_view_row_expanded (parent.handle, path); - OS.gtk_tree_path_free (path); - return answer; -} - -/** - * Returns the font that the receiver will use to paint textual information for this item. - * - * @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> - * - * @since 3.0 - */ -public Font getFont () { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return font != null ? font : parent.getFont (); -} - -/** - * Returns the font that the receiver will use to paint textual information - * for the specified cell in this item. - * - * @param index the column index - * @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> - * - * @since 3.1 - */ -public Font getFont (int index) { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - int count = Math.max (1, parent.columnCount); - if (0 > index || index > count - 1) return getFont (); - if (cellFont == null || cellFont [index] == null) return getFont (); - return cellFont [index]; -} - - -/** - * 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> - * - * @since 2.0 - * - */ -public Color getForeground () { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return _getForeground (); -} - -/** - * - * Returns the foreground color at the given column index in the receiver. - * - * @param index the column index - * @return the 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> - * - * @since 3.1 - */ -public Color getForeground (int index) { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return _getForeground (index); -} - -/** - * Returns <code>true</code> if the receiver is grayed, - * and false otherwise. When the parent does not have - * the <code>CHECK style, return false. - * <p> - * - * @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> - */ -public boolean getGrayed () { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - if ((parent.style & SWT.CHECK) == 0) return false; - return grayed; -} - -public Image getImage () { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return getImage (0); -} - -/** - * Returns the image stored at the given column index in the receiver, - * or null if the image has not been set or if the column does not exist. - * - * @param index the column index - * @return the image stored at the given column index 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> - * - * @since 3.1 - */ -public Image getImage (int index) { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return _getImage (index); -} - -/** - * Returns a rectangle describing the size and location - * relative to its parent of an image at a column in the - * tree. - * - * @param index the index that specifies the column - * @return the receiver's bounding image 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> - * - * @since 3.1 - */ -public Rectangle getImageBounds (int index) { - // TODO fully test on early and later versions of GTK - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - int /*long*/ parentHandle = parent.handle; - int /*long*/ column = 0; - if (index >= 0 && index < parent.getColumnCount ()) { - column = parent.columns [index].handle; - } else { - column = OS.gtk_tree_view_get_column (parentHandle, index); - } - if (column == 0) return new Rectangle (0, 0, 0, 0); - int /*long*/ pixbufRenderer = parent.getPixbufRenderer (column); - if (pixbufRenderer == 0) return new Rectangle (0, 0, 0, 0); - GdkRectangle rect = new GdkRectangle (); - int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); - OS.gtk_widget_realize (parentHandle); - OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect); - if ((parent.getStyle () & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth () - rect.width - rect.x; - if (OS.GTK_VERSION < OS.VERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) == column) { - int [] buffer = new int [1]; - OS.gtk_widget_style_get (parentHandle, OS.expander_size, buffer, 0); - rect.x += buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING; - rect.width -= buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING; - //OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0); - //int horizontalSeparator = buffer[0]; - //rect.x += horizontalSeparator; - } - /* - * Bug in GTK. In GTK 2.8.x, the cell area is left aligned even - * when the widget is mirrored. The fix is to sum up the indentation - * of the expanders. - */ - if ((parent.getStyle () & SWT.MIRRORED) != 0 && (OS.GTK_VERSION < OS.VERSION (2, 10, 0))) { - int depth = OS.gtk_tree_path_get_depth (path); - int [] expanderSize = new int [1]; - OS.gtk_widget_style_get (parentHandle, OS.expander_size, expanderSize, 0); - rect.x += depth * (expanderSize[0] + TreeItem.EXPANDER_EXTRA_PADDING); - } - OS.gtk_tree_path_free (path); - - /* - * The OS call gtk_cell_renderer_get_size() provides the width of image to be drawn - * by the cell renderer. If there is no image in the cell, the width is zero. If the table contains - * images of varying widths, gtk_cell_renderer_get_size() will return the width of the image, - * not the width of the area in which the image is drawn. - * New API was added in GTK 2.1.3 for determining the full width of the renderer area. - * For earlier versions of GTK, the result is only correct if all rows have images of the same - * width. - */ - if (OS.GTK_VERSION >= OS.VERSION (2, 1, 3)) { - int [] x = new int [1], w = new int[1]; - OS.gtk_tree_view_column_cell_get_position (column, pixbufRenderer, x, w); - rect.x += x [0]; - rect.width = w [0]; - } else { - int [] w = new int [1]; - OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, false, false); - OS.gtk_cell_renderer_get_size (pixbufRenderer, parentHandle, null, null, null, w, null); - rect.width = w [0]; - } - int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width : 0; - return new Rectangle (rect.x, rect.y, width, rect.height + 1); -} - -/** - * Returns the number of items contained in the receiver - * that are direct item children of 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(); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle); -} - -/** - * 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> - * - * @since 3.1 - */ -public TreeItem getItem (int index) { - checkWidget(); - if (index < 0) error (SWT.ERROR_INVALID_RANGE); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - int itemCount = OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle); - if (index >= itemCount) error (SWT.ERROR_INVALID_RANGE); - return parent._getItem (handle, index); -} - -/** - * Returns a (possibly empty) array of <code>TreeItem</code>s which - * are the direct item children of 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 receiver's 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 TreeItem [] getItems () { - checkWidget(); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return parent.getItems (handle); -} - -String getNameText () { - if ((parent.style & SWT.VIRTUAL) != 0) { - if (!cached) return "*virtual*"; //$NON-NLS-1$ - } - return super.getNameText (); -} - -/** - * Returns the receiver's parent, which must be a <code>Tree</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 Tree getParent () { - checkWidget (); - return parent; -} - -/** - * Returns the receiver's parent item, which must be a - * <code>TreeItem</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 TreeItem getParentItem () { - checkWidget(); - int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); - TreeItem item = null; - int depth = OS.gtk_tree_path_get_depth (path); - if (depth > 1) { - OS.gtk_tree_path_up (path); - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (OS.gtk_tree_model_get_iter (parent.modelHandle, iter, path)) { - item = parent._getItem (iter); - } - OS.g_free (iter); - } - OS.gtk_tree_path_free (path); - return item; -} - -public String getText () { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return getText (0); -} - -/** - * Returns the text stored at the given column index in the receiver, - * or empty string if the text has not been set. - * - * @param index the column index - * @return the text stored at the given column index 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> - * - * @since 3.1 - */ -public String getText (int index) { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - return _getText (index); -} - -/** - * Returns a rectangle describing the size and location - * relative to its parent of the text at a column in the - * tree. - * - * @param index the index that specifies the column - * @return the receiver's bounding text 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> - * - * @since 3.3 - */ -public Rectangle getTextBounds (int index) { - checkWidget (); - if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); - int count = Math.max (1, parent.getColumnCount ()); - if (0 > index || index > count - 1) return new Rectangle (0, 0, 0, 0); - // TODO fully test on early and later versions of GTK - // shifted a bit too far right on later versions of GTK - however, old Tree also had this problem - int /*long*/ parentHandle = parent.handle; - int /*long*/ column = 0; - if (index >= 0 && index < parent.columnCount) { - column = parent.columns [index].handle; - } else { - column = OS.gtk_tree_view_get_column (parentHandle, index); - } - if (column == 0) return new Rectangle (0, 0, 0, 0); - int /*long*/ textRenderer = parent.getTextRenderer (column); - int /*long*/ pixbufRenderer = parent.getPixbufRenderer (column); - if (textRenderer == 0 || pixbufRenderer == 0) return new Rectangle (0, 0, 0, 0); - - int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); - OS.gtk_widget_realize (parentHandle); - - boolean isExpander = OS.gtk_tree_model_iter_n_children (parent.modelHandle, handle) > 0; - boolean isExpanded = OS.gtk_tree_view_row_expanded (parentHandle, path); - OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, isExpander, isExpanded); - - GdkRectangle rect = new GdkRectangle (); - OS.gtk_tree_view_get_cell_area (parentHandle, path, column, rect); - if ((parent.getStyle () & SWT.MIRRORED) != 0) rect.x = parent.getClientWidth () - rect.width - rect.x; - int right = rect.x + rect.width; - - int [] x = new int [1], w = new int [1]; - parent.ignoreSize = true; - OS.gtk_cell_renderer_get_size (textRenderer, parentHandle, null, null, null, w, null); - parent.ignoreSize = false; - int [] buffer = new int [1]; - if (OS.GTK_VERSION < OS.VERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) == column) { - OS.gtk_widget_style_get (parentHandle, OS.expander_size, buffer, 0); - rect.x += buffer [0] + TreeItem.EXPANDER_EXTRA_PADDING; - } - /* - * Bug in GTK. In GTK 2.8.x, the cell area is left aligned even - * when the widget is mirrored. The fix is to sum up the indentation - * of the expanders. - */ - if ((parent.getStyle () & SWT.MIRRORED) != 0 && (OS.GTK_VERSION < OS.VERSION (2, 10, 0))) { - int depth = OS.gtk_tree_path_get_depth (path); - int [] expanderSize = new int [1]; - OS.gtk_widget_style_get (parentHandle, OS.expander_size, expanderSize, 0); - rect.x += depth * (expanderSize[0] + TreeItem.EXPANDER_EXTRA_PADDING); - } - OS.gtk_tree_path_free (path); - - OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0); - int horizontalSeparator = buffer[0]; - rect.x += horizontalSeparator; - if (OS.GTK_VERSION >= OS.VERSION (2, 1, 3)) { - OS.gtk_tree_view_column_cell_get_position (column, textRenderer, x, null); - rect.x += x [0]; - } else { - if ((parent.style & SWT.CHECK) != 0) { - OS.gtk_cell_renderer_get_size (parent.checkRenderer, parentHandle, null, null, null, w, null); - rect.x += w [0] + horizontalSeparator; - } - OS.gtk_cell_renderer_get_size (pixbufRenderer, parentHandle, null, null, null, w, null); - rect.x += w [0] + horizontalSeparator; - } - if (parent.columnCount > 0) { - if (rect.x + rect.width > right) { - rect.width = Math.max (0, right - rect.x); - } - } - int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0; - return new Rectangle (rect.x, rect.y, width, rect.height + 1); -} - -/** - * 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> - * <li>ERROR_INVALID_ARGUMENT - if the 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> - * - * @since 3.1 - */ -public int indexOf (TreeItem item) { - checkWidget(); - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); - int index = -1; - boolean isParent = false; - int /*long*/ currentPath = OS.gtk_tree_model_get_path (parent.modelHandle, handle); - int /*long*/ parentPath = OS.gtk_tree_model_get_path (parent.modelHandle, item.handle); - int depth = OS.gtk_tree_path_get_depth (parentPath); - if (depth > 1 && OS.gtk_tree_path_up(parentPath)) { - if (OS.gtk_tree_path_compare(currentPath, parentPath) == 0) isParent = true; - } - OS.gtk_tree_path_free (currentPath); - OS.gtk_tree_path_free (parentPath); - if (!isParent) return index; - int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, item.handle); - if (depth > 1) { - int /*long*/ indices = OS.gtk_tree_path_get_indices (path); - if (indices != 0) { - int[] temp = new int[depth]; - OS.memmove (temp, indices, 4 * temp.length); - index = temp[temp.length - 1]; - } - } - OS.gtk_tree_path_free (path); - return index; -} - -void redraw () { - int /*long*/ parentHandle = parent.handle; - if ((OS.GTK_WIDGET_FLAGS (parentHandle) & OS.GTK_REALIZED) != 0) { - int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); - GdkRectangle rect = new GdkRectangle (); - OS.gtk_tree_view_get_cell_area (parentHandle, path, 0, rect); - OS.gtk_tree_path_free (path); - int /*long*/ window = OS.gtk_tree_view_get_bin_window (parentHandle); - rect.x = 0; - int [] w = new int [1], h = new int [1]; - OS.gdk_drawable_get_size (window, w, h); - rect.width = w [0]; - OS.gdk_window_invalidate_rect (window, rect, false); - } -} - -void releaseChildren (boolean destroy) { - if (destroy) { - parent.releaseItems (handle); - } - super.releaseChildren (destroy); -} - -void releaseHandle () { - if (handle != 0) OS.g_free (handle); - handle = 0; - super.releaseHandle (); - parent = null; -} - -void releaseWidget () { - super.releaseWidget (); - font = null; - cellFont = null; -} - -/** - * 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> - * - * @since 3.1 - */ -public void removeAll () { - checkWidget (); - int /*long*/ modelHandle = parent.modelHandle; - int length = OS.gtk_tree_model_iter_n_children (modelHandle, handle); - if (length == 0) return; - int /*long*/ iter = OS.g_malloc (OS.GtkTreeIter_sizeof ()); - if (iter == 0) error (SWT.ERROR_NO_HANDLES); - if (parent.fixAccessibility ()) { - parent.ignoreAccessibility = true; - } - int /*long*/ selection = OS.gtk_tree_view_get_selection (parent.handle); - int [] value = new int [1]; - while (OS.gtk_tree_model_iter_children (modelHandle, iter, handle)) { - OS.gtk_tree_model_get (modelHandle, iter, Tree.ID_COLUMN, value, -1); - TreeItem item = value [0] != -1 ? parent.items [value [0]] : null; - if (item != null && !item.isDisposed ()) { - item.dispose (); - } else { - OS.g_signal_handlers_block_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - OS.gtk_tree_store_remove (modelHandle, iter); - OS.g_signal_handlers_unblock_matched (selection, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CHANGED); - } - } - if (parent.fixAccessibility ()) { - parent.ignoreAccessibility = false; - OS.g_object_notify (parent.handle, OS.model); - } - OS.g_free (iter); -} - -/** - * Sets the receiver's background color to the color specified - * by the argument, or to the default system color for the item - * if the argument is null. - * - * @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> - * - * @since 2.0 - * - */ -public void setBackground (Color color) { - checkWidget (); - if (color != null && color.isDisposed ()) { - SWT.error (SWT.ERROR_INVALID_ARGUMENT); - } - if (_getBackground ().equals (color)) return; - GdkColor gdkColor = color != null ? color.handle : null; - OS.gtk_tree_store_set (parent.modelHandle, handle, Tree.BACKGROUND_COLUMN, gdkColor, -1); - /* - * Bug in GTK. When using fixed-height-mode, - * row changes do not cause the row to be repainted. The fix is to - * invalidate the row when it is cleared. - */ - if ((parent.style & SWT.VIRTUAL) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) { - redraw (); - } - } - cached = true; -} - -/** - * Sets the background color at the given column index in the receiver - * to the color specified by the argument, or to the default system color for the item - * if the argument is null. - * - * @param index the column index - * @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> - * - * @since 3.1 - * - */ -public void setBackground (int index, Color color) { - checkWidget (); - if (color != null && color.isDisposed ()) { - SWT.error (SWT.ERROR_INVALID_ARGUMENT); - } - if (_getBackground (index).equals (color)) return; - int count = Math.max (1, parent.getColumnCount ()); - if (0 > index || index > count - 1) return; - int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; - GdkColor gdkColor = color != null ? color.handle : null; - OS.gtk_tree_store_set (parent.modelHandle, handle, modelIndex + Tree.CELL_BACKGROUND, gdkColor, -1); - /* - * Bug in GTK. When using fixed-height-mode, - * row changes do not cause the row to be repainted. The fix is to - * invalidate the row when it is cleared. - */ - if ((parent.style & SWT.VIRTUAL) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) { - redraw (); - } - } - cached = true; - - if (color != null) { - boolean customDraw = (parent.columnCount == 0) ? parent.firstCustomDraw : parent.columns [index].customDraw; - if (!customDraw) { - if ((parent.style & SWT.VIRTUAL) == 0) { - int /*long*/ parentHandle = parent.handle; - int /*long*/ column = 0; - if (parent.columnCount > 0) { - column = parent.columns [index].handle; - } else { - column = OS.gtk_tree_view_get_column (parentHandle, index); - } - if (column == 0) return; - int /*long*/ textRenderer = parent.getTextRenderer (column); - int /*long*/ imageRenderer = parent.getPixbufRenderer (column); - OS.gtk_tree_view_column_set_cell_data_func (column, textRenderer, display.cellDataProc, parentHandle, 0); - OS.gtk_tree_view_column_set_cell_data_func (column, imageRenderer, display.cellDataProc, parentHandle, 0); - } - if (parent.columnCount == 0) { - parent.firstCustomDraw = true; - } else { - parent.columns [index].customDraw = true; - } - } - } -} - -/** - * Sets the checked state of the receiver. - * <p> - * - * @param checked the new checked 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 setChecked (boolean checked) { - checkWidget(); - if ((parent.style & SWT.CHECK) == 0) return; - if (_getChecked () == checked) return; - OS.gtk_tree_store_set (parent.modelHandle, handle, Tree.CHECKED_COLUMN, checked, -1); - /* - * GTK+'s "inconsistent" state does not match SWT's concept of grayed. To - * show checked+grayed differently from unchecked+grayed, we must toggle the - * grayed state on check and uncheck. - */ - OS.gtk_tree_store_set (parent.modelHandle, handle, Tree.GRAYED_COLUMN, !checked ? false : grayed, -1); - cached = true; -} - -/** - * Sets the expanded state of the receiver. - * <p> - * - * @param expanded the new expanded 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 setExpanded (boolean expanded) { - checkWidget(); - int /*long*/ path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); - if (expanded) { - OS.g_signal_handlers_block_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_EXPAND_ROW); - OS.gtk_tree_view_expand_row (parent.handle, path, false); - OS.g_signal_handlers_unblock_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_EXPAND_ROW); - } else { - OS.g_signal_handlers_block_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_COLLAPSE_ROW); - OS.gtk_widget_realize (parent.handle); - OS.gtk_tree_view_collapse_row (parent.handle, path); - OS.g_signal_handlers_unblock_matched (parent.handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, TEST_COLLAPSE_ROW); - } - OS.gtk_tree_path_free (path); - cached = true; -} - - -/** - * Sets the font that the receiver will use to paint textual information - * for this item 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> - * - * @since 3.0 - */ -public void setFont (Font font){ - checkWidget (); - 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; - int /*long*/ fontHandle = font != null ? font.handle : 0; - OS.gtk_tree_store_set (parent.modelHandle, handle, Tree.FONT_COLUMN, fontHandle, -1); - /* - * Bug in GTK. When using fixed-height-mode, - * row changes do not cause the row to be repainted. The fix is to - * invalidate the row when it is cleared. - */ - if ((parent.style & SWT.VIRTUAL) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) { - redraw (); - } - } - cached = true; -} - -/** - * Sets the font that the receiver will use to paint textual information - * for the specified cell in this item to the font specified by the - * argument, or to the default font for that kind of control if the - * argument is null. - * - * @param index the column index - * @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> - * - * @since 3.1 - */ -public void setFont (int index, Font font) { - checkWidget (); - if (font != null && font.isDisposed ()) { - SWT.error (SWT.ERROR_INVALID_ARGUMENT); - } - int count = Math.max (1, parent.getColumnCount ()); - if (0 > index || index > count - 1) return; - if (cellFont == null) { - if (font == null) return; - cellFont = new Font [count]; - } - Font oldFont = cellFont [index]; - if (oldFont == font) return; - cellFont [index] = font; - if (oldFont != null && oldFont.equals (font)) return; - - int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; - int /*long*/ fontHandle = font != null ? font.handle : 0; - OS.gtk_tree_store_set (parent.modelHandle, handle, modelIndex + Tree.CELL_FONT, fontHandle, -1); - /* - * Bug in GTK. When using fixed-height-mode, - * row changes do not cause the row to be repainted. The fix is to - * invalidate the row when it is cleared. - */ - if ((parent.style & SWT.VIRTUAL) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) { - redraw (); - } - } - cached = true; - - if (font != null) { - boolean customDraw = (parent.columnCount == 0) ? parent.firstCustomDraw : parent.columns [index].customDraw; - if (!customDraw) { - if ((parent.style & SWT.VIRTUAL) == 0) { - int /*long*/ parentHandle = parent.handle; - int /*long*/ column = 0; - if (parent.columnCount > 0) { - column = parent.columns [index].handle; - } else { - column = OS.gtk_tree_view_get_column (parentHandle, index); - } - if (column == 0) return; - int /*long*/ textRenderer = parent.getTextRenderer (column); - int /*long*/ imageRenderer = parent.getPixbufRenderer (column); - OS.gtk_tree_view_column_set_cell_data_func (column, textRenderer, display.cellDataProc, parentHandle, 0); - OS.gtk_tree_view_column_set_cell_data_func (column, imageRenderer, display.cellDataProc, parentHandle, 0); - } - if (parent.columnCount == 0) { - parent.firstCustomDraw = true; - } else { - parent.columns [index].customDraw = true; - } - } - } -} - -/** - * Sets the receiver's foreground color to the color specified - * by the argument, or to the default system color for the item - * if the argument is null. - * - * @param color the new color (or null) - * - * @since 2.0 - * - * @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> - * - * @since 2.0 - * - */ -public void setForeground (Color color){ - checkWidget (); - if (color != null && color.isDisposed ()) { - SWT.error (SWT.ERROR_INVALID_ARGUMENT); - } - if (_getForeground ().equals (color)) return; - GdkColor gdkColor = color != null ? color.handle : null; - OS.gtk_tree_store_set (parent.modelHandle, handle, Tree.FOREGROUND_COLUMN, gdkColor, -1); - /* - * Bug in GTK. When using fixed-height-mode, - * row changes do not cause the row to be repainted. The fix is to - * invalidate the row when it is cleared. - */ - if ((parent.style & SWT.VIRTUAL) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) { - redraw (); - } - } - cached = true; -} - -/** - * Sets the foreground color at the given column index in the receiver - * to the color specified by the argument, or to the default system color for the item - * if the argument is null. - * - * @param index the column index - * @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> - * - * @since 3.1 - * - */ -public void setForeground (int index, Color color){ - checkWidget (); - if (color != null && color.isDisposed ()) { - SWT.error (SWT.ERROR_INVALID_ARGUMENT); - } - if (_getForeground (index).equals (color)) return; - int count = Math.max (1, parent.getColumnCount ()); - if (0 > index || index > count - 1) return; - int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; - GdkColor gdkColor = color != null ? color.handle : null; - OS.gtk_tree_store_set (parent.modelHandle, handle, modelIndex + Tree.CELL_FOREGROUND, gdkColor, -1); - /* - * Bug in GTK. When using fixed-height-mode, - * row changes do not cause the row to be repainted. The fix is to - * invalidate the row when it is cleared. - */ - if ((parent.style & SWT.VIRTUAL) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) { - redraw (); - } - } - cached = true; - - if (color != null) { - boolean customDraw = (parent.columnCount == 0) ? parent.firstCustomDraw : parent.columns [index].customDraw; - if (!customDraw) { - if ((parent.style & SWT.VIRTUAL) == 0) { - int /*long*/ parentHandle = parent.handle; - int /*long*/ column = 0; - if (parent.columnCount > 0) { - column = parent.columns [index].handle; - } else { - column = OS.gtk_tree_view_get_column (parentHandle, index); - } - if (column == 0) return; - int /*long*/ textRenderer = parent.getTextRenderer (column); - int /*long*/ imageRenderer = parent.getPixbufRenderer (column); - OS.gtk_tree_view_column_set_cell_data_func (column, textRenderer, display.cellDataProc, parentHandle, 0); - OS.gtk_tree_view_column_set_cell_data_func (column, imageRenderer, display.cellDataProc, parentHandle, 0); - } - if (parent.columnCount == 0) { - parent.firstCustomDraw = true; - } else { - parent.columns [index].customDraw = true; - } - } - } -} - -/** - * Sets the grayed state of the checkbox for this item. This state change - * only applies if the Tree was created with the SWT.CHECK style. - * - * @param grayed the new 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> - */ -public void setGrayed (boolean grayed) { - checkWidget(); - if ((parent.style & SWT.CHECK) == 0) return; - if (this.grayed == grayed) return; - this.grayed = grayed; - /* - * GTK+'s "inconsistent" state does not match SWT's concept of grayed. - * Render checked+grayed as "inconsistent", unchecked+grayed as blank. - */ - int /*long*/ [] ptr = new int /*long*/ [1]; - OS.gtk_tree_model_get (parent.modelHandle, handle, Tree.CHECKED_COLUMN, ptr, -1); - OS.gtk_tree_store_set (parent.modelHandle, handle, Tree.GRAYED_COLUMN, ptr [0] == 0 ? false : grayed, -1); - cached = true; -} - -/** - * Sets the receiver's image at a column. - * - * @param index the column index - * @param image the new image - * - * @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> - * - * @since 3.1 - */ -public void setImage (int index, Image image) { - checkWidget (); - if (image != null && image.isDisposed()) { - error(SWT.ERROR_INVALID_ARGUMENT); - } - if (image != null && image.type == SWT.ICON) { - if (image.equals (_getImage (index))) return; - } - int count = Math.max (1, parent.getColumnCount ()); - if (0 > index || index > count - 1) return; - int /*long*/ pixbuf = 0; - if (image != null) { - ImageList imageList = parent.imageList; - if (imageList == null) imageList = parent.imageList = new ImageList (); - int imageIndex = imageList.indexOf (image); - if (imageIndex == -1) imageIndex = imageList.add (image); - pixbuf = imageList.getPixbuf (imageIndex); - } - int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; - OS.gtk_tree_store_set (parent.modelHandle, handle, modelIndex + Tree.CELL_PIXBUF, pixbuf, -1); - /* - * Bug in GTK. When using fixed-height-mode, - * row changes do not cause the row to be repainted. The fix is to - * invalidate the row when the image changes. - */ - if ((parent.style & SWT.VIRTUAL) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) { - if (parent.columnCount == 0) { - redraw (); - } - } - } - /* - * Bug in GTK. When using fixed-height-mode, GTK does not recalculate the cell renderer width - * when the image is changed in the model. The fix is to force it to recalculate the width if - * more space is required. - */ - if ((parent.style & SWT.VIRTUAL) != 0 && parent.currentItem == null) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2)) { - if (image != null) { - int /*long*/parentHandle = parent.handle; - int /*long*/ column = OS.gtk_tree_view_get_column (parentHandle, index); - int [] w = new int [1]; - int /*long*/ pixbufRenderer = parent.getPixbufRenderer(column); - OS.gtk_tree_view_column_cell_get_position (column, pixbufRenderer, null, w); - if (w[0] < image.getBounds().width) { - /* - * There is no direct way to clear the cell renderer width so we - * are relying on the fact that it is done as part of modifying - * the style. - */ - int /*long*/ style = OS.gtk_widget_get_modifier_style (parentHandle); - parent.modifyStyle (parentHandle, style); - } - } - } - } - cached = true; -} - -public void setImage (Image image) { - checkWidget (); - setImage (0, image); -} - -/** - * Sets the image for multiple columns in the tree. - * - * @param images the array of new images - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the array of images is null</li> - * <li>ERROR_INVALID_ARGUMENT - if one of the images 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.1 - */ -public void setImage (Image [] images) { - checkWidget (); - if (images == null) error (SWT.ERROR_NULL_ARGUMENT); - for (int i=0; i<images.length; i++) { - setImage (i, images [i]); - } -} - -/** - * Sets the number of child items contained in the receiver. - * - * @param count 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> - * - * @since 3.2 - */ -public void setItemCount (int count) { - checkWidget (); - count = Math.max (0, count); - parent.setItemCount (handle, count); -} - -/** - * Sets the receiver's text at a column - * - * @param index the column index - * @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> - * - * @since 3.1 - */ -public void setText (int index, String string) { - checkWidget (); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if (_getText (index).equals (string)) return; - int count = Math.max (1, parent.getColumnCount ()); - if (0 > index || index > count - 1) return; - byte[] buffer = Converter.wcsToMbcs (null, string, true); - int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; - OS.gtk_tree_store_set (parent.modelHandle, handle, modelIndex + Tree.CELL_TEXT, buffer, -1); - /* - * Bug in GTK. When using fixed-height-mode, - * row changes do not cause the row to be repainted. The fix is to - * invalidate the row when the text changes. - */ - if ((parent.style & SWT.VIRTUAL) != 0) { - if (OS.GTK_VERSION >= OS.VERSION (2, 3, 2) && OS.GTK_VERSION < OS.VERSION (2, 6, 3)) { - redraw (); - } - } - cached = true; -} - -public void setText (String string) { - checkWidget (); - setText (0, string); -} - -/** - * Sets the text for multiple columns in the tree. - * - * @param strings the array of new strings - * - * @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> - * - * @since 3.1 - */ -public void setText (String [] strings) { - checkWidget (); - if (strings == null) error (SWT.ERROR_NULL_ARGUMENT); - for (int i=0; i<strings.length; i++) { - String string = strings [i]; - if (string != null) setText (i, string); - } -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java deleted file mode 100644 index a391ca1933..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java +++ /dev/null @@ -1,1617 +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.gtk.*; -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 /*long*/ 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 HANDLE = 1<<3; - static final int DISABLED = 1<<4; - static final int MENU = 1<<5; - static final int OBSCURED = 1<<6; - static final int MOVED = 1<<7; - static final int RESIZED = 1<<8; - static final int ZERO_WIDTH = 1<<9; - static final int ZERO_HEIGHT = 1<<10; - static final int HIDDEN = 1<<11; - static final int FOREGROUND = 1<<12; - static final int BACKGROUND = 1<<13; - static final int FONT = 1<<14; - static final int PARENT_BACKGROUND = 1<<15; - static final int THEME_BACKGROUND = 1<<16; - - /* A layout was requested on this widget */ - static final int LAYOUT_NEEDED = 1<<17; - - /* The preferred size of a child has changed */ - static final int LAYOUT_CHANGED = 1<<18; - - /* A layout was requested in this widget hierachy */ - static final int LAYOUT_CHILD = 1<<19; - - /* More global state flags */ - static final int RELEASED = 1<<20; - static final int DISPOSE_SENT = 1<<21; - static final int FOREIGN_HANDLE = 1<<22; - static final int DRAG_DETECT = 1<<23; - - /* Default size for widgets */ - static final int DEFAULT_WIDTH = 64; - static final int DEFAULT_HEIGHT = 64; - - /* GTK signals data */ - static final int ACTIVATE = 1; - static final int BUTTON_PRESS_EVENT = 2; - static final int BUTTON_PRESS_EVENT_INVERSE = 3; - static final int BUTTON_RELEASE_EVENT = 4; - static final int BUTTON_RELEASE_EVENT_INVERSE = 5; - static final int CHANGED = 6; - static final int CHANGE_VALUE = 7; - static final int CLICKED = 8; - static final int COMMIT = 9; - static final int CONFIGURE_EVENT = 10; - static final int DELETE_EVENT = 11; - static final int DELETE_RANGE = 12; - static final int DELETE_TEXT = 13; - static final int ENTER_NOTIFY_EVENT = 14; - static final int EVENT = 15; - static final int EVENT_AFTER = 16; - static final int EXPAND_COLLAPSE_CURSOR_ROW = 17; - static final int EXPOSE_EVENT = 18; - static final int EXPOSE_EVENT_INVERSE = 19; - static final int FOCUS = 20; - static final int FOCUS_IN_EVENT = 21; - static final int FOCUS_OUT_EVENT = 22; - static final int GRAB_FOCUS = 23; - static final int HIDE = 24; - static final int INPUT = 25; - static final int INSERT_TEXT = 26; - static final int KEY_PRESS_EVENT = 27; - static final int KEY_RELEASE_EVENT = 28; - static final int LEAVE_NOTIFY_EVENT = 29; - static final int MAP = 30; - static final int MAP_EVENT = 31; - static final int MNEMONIC_ACTIVATE = 32; - static final int MOTION_NOTIFY_EVENT = 33; - static final int MOTION_NOTIFY_EVENT_INVERSE = 34; - static final int MOVE_FOCUS = 35; - static final int OUTPUT = 36; - static final int POPULATE_POPUP = 37; - static final int POPUP_MENU = 38; - static final int PREEDIT_CHANGED = 39; - static final int REALIZE = 40; - static final int ROW_ACTIVATED = 41; - static final int SCROLL_CHILD = 42; - static final int SCROLL_EVENT = 43; - static final int SELECT = 44; - static final int SHOW = 45; - static final int SHOW_HELP = 46; - static final int SIZE_ALLOCATE = 47; - static final int STYLE_SET = 48; - static final int SWITCH_PAGE = 49; - static final int TEST_COLLAPSE_ROW = 50; - static final int TEST_EXPAND_ROW = 51; - static final int TEXT_BUFFER_INSERT_TEXT = 52; - static final int TOGGLED = 53; - static final int UNMAP = 54; - static final int UNMAP_EVENT = 55; - static final int UNREALIZE = 56; - static final int VALUE_CHANGED = 57; - static final int VISIBILITY_NOTIFY_EVENT = 58; - static final int WINDOW_STATE_EVENT = 59; - static final int ACTIVATE_INVERSE = 60; - static final int DAY_SELECTED = 61; - static final int MONTH_CHANGED = 62; - static final int STATUS_ICON_POPUP_MENU = 63; - static final int ROW_INSERTED = 64; - static final int ROW_DELETED = 65; - static final int DAY_SELECTED_DOUBLE_CLICK = 66; - static final int LAST_SIGNAL = 67; - -/** - * Prevents uninitialized instances from being created outside the package. - */ -Widget () {} - -/** - * 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; -} - -void _addListener (int eventType, Listener listener) { - if (eventTable == null) eventTable = new EventTable (); - eventTable.hook (eventType, listener); -} - -/** - * 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 listener) { - checkWidget (); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - _addListener (eventType, listener); -} - -/** - * 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); -} - -int /*long*/ paintWindow () { - return 0; -} - -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; -} - -int /*long*/ cellDataProc (int /*long*/ tree_column, int /*long*/ cell, int /*long*/ tree_model, int /*long*/ iter, int /*long*/ data) { - return 0; -} - -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); - /* Versions of GTK prior to 2.8 do not render RTL text properly */ - if (OS.GTK_VERSION < OS.VERSION (2, 8, 0)) { - style &= ~SWT.RIGHT_TO_LEFT; - style |= SWT.LEFT_TO_RIGHT; - } -} - -/** - * Throws an exception if the specified widget can not be - * used as a parent for the receiver. - * - * @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> - * </ul> - */ -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) { -} - -void createWidget (int index) { - createHandle (index); - setOrientation (); - hookEvents (); - register (); -} - -void deregister () { - if (handle == 0) return; - if ((state & HANDLE) != 0) display.removeWidget (handle); -} - -void destroyWidget () { - int /*long*/ topHandle = topHandle (); - releaseHandle (); - if (topHandle != 0 && (state & HANDLE) != 0) { - OS.gtk_widget_destroy (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 error (int code) { - SWT.error (code); -} - -/** - * 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; - String string = getClass ().getName (); - int index = string.length (); - while ((--index > 0) && (string.charAt (index) != '.')) {} - 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; -} - - -int /*long*/ gtk_activate (int /*long*/ widget) { - return 0; -} - -int /*long*/ gtk_button_press_event (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int /*long*/ gtk_button_release_event (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int /*long*/ gtk_changed (int /*long*/ widget) { - return 0; -} - -int /*long*/ gtk_change_value (int /*long*/ widget, int /*long*/ scroll, int /*long*/ value1, int /*long*/ value2) { - return 0; -} - -int /*long*/ gtk_clicked (int /*long*/ widget) { - return 0; -} - -int /*long*/ gtk_commit (int /*long*/ imcontext, int /*long*/ text) { - return 0; -} - -int /*long*/ gtk_configure_event (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int /*long*/ gtk_day_selected (int /*long*/ widget) { - return 0; -} - -int /*long*/ gtk_day_selected_double_click (int /*long*/ widget) { - return 0; -} - -int /*long*/ gtk_delete_event (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int /*long*/ gtk_delete_range (int /*long*/ widget, int /*long*/ iter1, int /*long*/ iter2) { - return 0; -} - -int /*long*/ gtk_delete_text (int /*long*/ widget, int /*long*/ start_pos, int /*long*/ end_pos) { - return 0; -} - -int /*long*/ gtk_enter_notify_event (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int /*long*/ gtk_event (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int /*long*/ gtk_expand_collapse_cursor_row (int /*long*/ widget, int /*long*/ logical, int /*long*/ expand, int /*long*/ open_all) { - return 0; -} - -int /*long*/ gtk_expose_event (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int /*long*/ gtk_focus (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int /*long*/ gtk_grab_focus (int /*long*/ widget) { - return 0; -} - -int /*long*/ gtk_hide (int /*long*/ widget) { - return 0; -} - -int /*long*/ gtk_input (int /*long*/ widget, int /*long*/ arg1) { - return 0; -} - -int /*long*/ gtk_insert_text (int /*long*/ widget, int /*long*/ new_text, int /*long*/ new_text_length, int /*long*/ position) { - return 0; -} - -int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ event) { - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, event, GdkEventKey.sizeof); - return sendKeyEvent (SWT.KeyDown, gdkEvent) ? 0 : 1; -} - -int /*long*/ gtk_key_release_event (int /*long*/ widget, int /*long*/ event) { - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, event, GdkEventKey.sizeof); - return sendKeyEvent (SWT.KeyUp, gdkEvent) ? 0 : 1; -} - -int /*long*/ gtk_leave_notify_event (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int /*long*/ gtk_map (int /*long*/ widget) { - return 0; -} - -int /*long*/ gtk_map_event (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int /*long*/ gtk_mnemonic_activate (int /*long*/ widget, int /*long*/ arg1) { - return 0; -} - -int /*long*/ gtk_month_changed (int /*long*/ widget) { - return 0; -} - -int /*long*/ gtk_motion_notify_event (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int /*long*/ gtk_move_focus (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int /*long*/ gtk_output (int /*long*/ widget) { - return 0; -} - -int /*long*/ gtk_populate_popup (int /*long*/ widget, int /*long*/ menu) { - return 0; -} - -int /*long*/ gtk_popup_menu (int /*long*/ widget) { - return 0; -} - -int /*long*/ gtk_preedit_changed (int /*long*/ imcontext) { - return 0; -} - -int /*long*/ gtk_realize (int /*long*/ widget) { - return 0; -} - -int /*long*/ gtk_row_activated (int /*long*/ tree, int /*long*/ path, int /*long*/ column) { - return 0; -} - -int /*long*/ gtk_row_deleted (int /*long*/ model, int /*long*/ path) { - return 0; -} - -int /*long*/ gtk_row_inserted (int /*long*/ model, int /*long*/ path, int /*long*/ iter) { - return 0; -} - -int /*long*/ gtk_scroll_child (int /*long*/ widget, int /*long*/ scrollType, int /*long*/ horizontal) { - return 0; -} - -int /*long*/ gtk_scroll_event (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int /*long*/ gtk_select (int /*long*/ item) { - return 0; -} - -int /*long*/ gtk_show (int /*long*/ widget) { - return 0; -} - -int /*long*/ gtk_show_help (int /*long*/ widget, int /*long*/ helpType) { - return 0; -} - -int /*long*/ gtk_size_allocate (int /*long*/ widget, int /*long*/ allocation) { - return 0; -} - -int /*long*/ gtk_status_icon_popup_menu (int /*long*/ handle, int /*long*/ button, int /*long*/ activate_time) { - return 0; -} - -int /*long*/ gtk_style_set (int /*long*/ widget, int /*long*/ previousStyle) { - return 0; -} - -int /*long*/ gtk_switch_page (int /*long*/ widget, int /*long*/ page, int /*long*/ page_num) { - return 0; -} - -int /*long*/ gtk_test_collapse_row (int /*long*/ tree, int /*long*/ iter, int /*long*/ path) { - return 0; -} - -int /*long*/ gtk_test_expand_row (int /*long*/ tree, int /*long*/ iter, int /*long*/ path) { - return 0; -} - -int /*long*/ gtk_text_buffer_insert_text (int /*long*/ widget, int /*long*/ iter, int /*long*/ text, int /*long*/ length) { - return 0; -} - -int /*long*/ gtk_timer () { - return 0; -} - -int /*long*/ gtk_toggled (int /*long*/ renderer, int /*long*/ pathStr) { - return 0; -} - -int /*long*/ gtk_unmap (int /*long*/ widget) { - return 0; -} - -int /*long*/ gtk_unmap_event (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int /*long*/ gtk_unrealize (int /*long*/ widget) { - return 0; -} - -int /*long*/ gtk_value_changed (int /*long*/ adjustment) { - return 0; -} - -int /*long*/ gtk_visibility_notify_event (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int /*long*/ gtk_window_state_event (int /*long*/ widget, int /*long*/ event) { - return 0; -} - -int fontHeight (int /*long*/ font, int /*long*/ widgetHandle) { - int /*long*/ context = OS.gtk_widget_get_pango_context (widgetHandle); - int /*long*/ lang = OS.pango_context_get_language (context); - int /*long*/ metrics = OS.pango_context_get_metrics (context, font, lang); - int ascent = OS.pango_font_metrics_get_ascent (metrics); - int descent = OS.pango_font_metrics_get_descent (metrics); - OS.pango_font_metrics_unref (metrics); - return OS.PANGO_PIXELS (ascent + descent); -} - -int /*long*/ filterProc(int /*long*/ xEvent, int /*long*/ gdkEvent, int /*long*/ data2) { - return 0; -} - -boolean filters (int eventType) { - return display.filters (eventType); -} - -int /*long*/ fixedMapProc (int /*long*/ widget) { - return 0; -} - -int /*long*/ fixedSizeAllocateProc(int /*long*/ widget, int /*long*/ allocationPtr) { - return OS.Call (Display.oldFixedSizeAllocateProc, widget, allocationPtr); -} - -char [] fixMnemonic (String string) { - return fixMnemonic (string, true); -} - -char [] fixMnemonic (String string, boolean replace) { - int length = string.length (); - char [] text = new char [length]; - string.getChars (0, length, text, 0); - int i = 0, j = 0; - char [] result = new char [length * 2]; - while (i < length) { - switch (text [i]) { - case '&': - if (i + 1 < length && text [i + 1] == '&') { - result [j++] = text [i++]; - } else { - if (replace) result [j++] = '_'; - } - i++; - break; - case '_': - if (replace) result [j++] = '_'; - //FALL THROUGH - default: - result [j++] = text [i++]; - } - } - return result; -} - -/** - * 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 isValidThread () { - return getDisplay ().isValidThread (); -} - -boolean isValidSubclass() { - return Display.isValidClass(getClass()); -} - -void hookEvents () { -} - -/* - * Returns <code>true</code> if the specified eventType is - * hooked, and <code>false</code> otherwise. Implementations - * of SWT can avoid creating objects and sending events - * when an event happens in the operating system but - * there are no listeners hooked for the event. - * - * @param eventType the event to be checked - * - * @return <code>true</code> when the eventType is hooked and <code>false</code> otherwise - * - * @see #isListening - */ -boolean hooks (int eventType) { - if (eventTable == null) return false; - return eventTable.hooks (eventType); -} - -int /*long*/ hoverProc (int /*long*/ widget) { - return 0; -} - -int /*long*/ menuPositionProc (int /*long*/ menu, int /*long*/ x, int /*long*/ y, int /*long*/ push_in, int /*long*/ user_data) { - return 0; -} - -boolean mnemonicHit (int /*long*/ mnemonicHandle, char key) { - if (!mnemonicMatch (mnemonicHandle, key)) return false; - OS.g_signal_handlers_block_matched (mnemonicHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, MNEMONIC_ACTIVATE); - boolean result = OS.gtk_widget_mnemonic_activate (mnemonicHandle, false); - OS.g_signal_handlers_unblock_matched (mnemonicHandle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, MNEMONIC_ACTIVATE); - return result; -} - -boolean mnemonicMatch (int /*long*/ mnemonicHandle, char key) { - int keyval1 = OS.gdk_keyval_to_lower (OS.gdk_unicode_to_keyval (key)); - int keyval2 = OS.gdk_keyval_to_lower (OS.gtk_label_get_mnemonic_keyval (mnemonicHandle)); - return keyval1 == keyval2; -} - -void modifyStyle (int /*long*/ handle, int /*long*/ style) { - OS.gtk_widget_modify_style (handle, style); -} - -/** - * 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 register () { - if (handle == 0) return; - if ((state & HANDLE) != 0) 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); -} - -int /*long*/ rendererGetSizeProc (int /*long*/ cell, int /*long*/ handle, int /*long*/ cell_area, int /*long*/ x_offset, int /*long*/ y_offset, int /*long*/ width, int /*long*/ height) { - return 0; -} - -int /*long*/ rendererRenderProc (int /*long*/ cell, int /*long*/ window, int /*long*/ handle, int /*long*/ background_area, int /*long*/ cell_area, int /*long*/ expose_area, int /*long*/ flags) { - return 0; -} - -/** - * 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); -} - -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 sendKeyEvent (int type, GdkEventKey keyEvent) { - int length = keyEvent.length; - if (keyEvent.string == 0 || OS.g_utf8_strlen (keyEvent.string, length) <= 1) { - Event event = new Event (); - event.time = keyEvent.time; - if (!setKeyState (event, keyEvent)) return true; - 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; - } - byte [] buffer = new byte [length]; - OS.memmove (buffer, keyEvent.string, length); - char [] chars = Converter.mbcsToWcs (null, buffer); - return sendIMKeyEvent (type, keyEvent, chars) != null; -} - -char [] sendIMKeyEvent (int type, GdkEventKey keyEvent, char [] chars) { - int index = 0, count = 0, state = 0; - int /*long*/ ptr = 0; - if (keyEvent == null) { - ptr = OS.gtk_get_current_event (); - if (ptr != 0) { - keyEvent = new GdkEventKey (); - OS.memmove (keyEvent, ptr, GdkEventKey.sizeof); - switch (keyEvent.type) { - case OS.GDK_KEY_PRESS: - case OS.GDK_KEY_RELEASE: - state = keyEvent.state; - break; - default: - keyEvent = null; - break; - } - } - } - if (keyEvent == null) { - int [] buffer = new int [1]; - OS.gtk_get_current_event_state (buffer); - state = buffer [0]; - } - while (index < chars.length) { - Event event = new Event (); - if (keyEvent != null && chars.length <= 1) { - setKeyState (event, keyEvent); - } else { - setInputState (event, state); - } - event.character = chars [index]; - sendEvent (type, event); - - /* - * 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 null. - */ - if (isDisposed ()) { - if (ptr != 0) OS.gdk_event_free (ptr); - return null; - } - if (event.doit) chars [count++] = chars [index]; - index++; - } - if (ptr != 0) OS.gdk_event_free (ptr); - if (count == 0) return null; - if (index != count) { - char [] result = new char [count]; - System.arraycopy (chars, 0, result, 0, count); - return result; - } - return chars; -} - -/** - * 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; - } - } - } - } -} - -void setForegroundColor (int /*long*/ handle, GdkColor color) { - int /*long*/ style = OS.gtk_widget_get_modifier_style (handle); - OS.gtk_rc_style_set_fg (style, OS.GTK_STATE_NORMAL, color); - OS.gtk_rc_style_set_fg (style, OS.GTK_STATE_ACTIVE, color); - OS.gtk_rc_style_set_fg (style, OS.GTK_STATE_PRELIGHT, color); - int flags = OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_NORMAL); - flags = (color == null) ? flags & ~OS.GTK_RC_FG: flags | OS.GTK_RC_FG; - OS.gtk_rc_style_set_color_flags (style, OS.GTK_STATE_NORMAL, flags); - flags = OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_ACTIVE); - flags = (color == null) ? flags & ~OS.GTK_RC_FG: flags | OS.GTK_RC_FG; - OS.gtk_rc_style_set_color_flags (style, OS.GTK_STATE_ACTIVE, flags); - flags = OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_PRELIGHT); - flags = (color == null) ? flags & ~OS.GTK_RC_FG: flags | OS.GTK_RC_FG; - OS.gtk_rc_style_set_color_flags (style, OS.GTK_STATE_PRELIGHT, flags); - - OS.gtk_rc_style_set_text (style, OS.GTK_STATE_NORMAL, color); - OS.gtk_rc_style_set_text (style, OS.GTK_STATE_ACTIVE, color); - OS.gtk_rc_style_set_text (style, OS.GTK_STATE_PRELIGHT, color); - flags = OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_NORMAL); - flags = (color == null) ? flags & ~OS.GTK_RC_TEXT: flags | OS.GTK_RC_TEXT; - OS.gtk_rc_style_set_color_flags (style, OS.GTK_STATE_NORMAL, flags); - flags = OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_PRELIGHT); - flags = (color == null) ? flags & ~OS.GTK_RC_TEXT: flags | OS.GTK_RC_TEXT; - OS.gtk_rc_style_set_color_flags (style, OS.GTK_STATE_PRELIGHT, flags); - flags = OS.gtk_rc_style_get_color_flags (style, OS.GTK_STATE_ACTIVE); - flags = (color == null) ? flags & ~OS.GTK_RC_TEXT: flags | OS.GTK_RC_TEXT; - OS.gtk_rc_style_set_color_flags (style, OS.GTK_STATE_ACTIVE, flags); - modifyStyle (handle, style); -} - -boolean setInputState (Event event, int state) { - if ((state & OS.GDK_MOD1_MASK) != 0) event.stateMask |= SWT.ALT; - if ((state & OS.GDK_SHIFT_MASK) != 0) event.stateMask |= SWT.SHIFT; - if ((state & OS.GDK_CONTROL_MASK) != 0) event.stateMask |= SWT.CONTROL; - if ((state & OS.GDK_BUTTON1_MASK) != 0) event.stateMask |= SWT.BUTTON1; - if ((state & OS.GDK_BUTTON2_MASK) != 0) event.stateMask |= SWT.BUTTON2; - if ((state & OS.GDK_BUTTON3_MASK) != 0) event.stateMask |= SWT.BUTTON3; - return true; -} - -boolean setKeyState (Event event, GdkEventKey keyEvent) { - if (keyEvent.string != 0 && OS.g_utf8_strlen (keyEvent.string, keyEvent.length) > 1) return false; - boolean isNull = false; - event.keyCode = Display.translateKey (keyEvent.keyval); - switch (keyEvent.keyval) { - case OS.GDK_BackSpace: event.character = SWT.BS; break; - case OS.GDK_Linefeed: event.character = SWT.LF; break; - case OS.GDK_KP_Enter: - case OS.GDK_Return: event.character = SWT.CR; break; - case OS.GDK_KP_Delete: - case OS.GDK_Delete: event.character = SWT.DEL; break; - case OS.GDK_Escape: event.character = SWT.ESC; break; - case OS.GDK_Tab: - case OS.GDK_ISO_Left_Tab: event.character = SWT.TAB; break; - default: { - if (event.keyCode == 0) { - int [] keyval = new int [1], effective_group= new int [1], level = new int [1], consumed_modifiers = new int [1]; - if (OS.gdk_keymap_translate_keyboard_state(OS.gdk_keymap_get_default (), keyEvent.hardware_keycode, 0, keyEvent.group, keyval, effective_group, level, consumed_modifiers)) { - event.keyCode = OS.gdk_keyval_to_unicode (keyval [0]); - } - } - int key = keyEvent.keyval; - if ((keyEvent.state & OS.GDK_CONTROL_MASK) != 0 && (0 <= key && key <= 0x7F)) { - if ('a' <= key && key <= 'z') key -= 'a' - 'A'; - if (64 <= key && key <= 95) key -= 64; - event.character = (char) key; - isNull = keyEvent.keyval == '@' && key == 0; - } else { - event.character = (char) OS.gdk_keyval_to_unicode (key); - } - } - } - if (event.keyCode == 0 && event.character == 0) { - if (!isNull) return false; - } - return setInputState (event, keyEvent.state); -} - -void setOrientation () { -} - -boolean setTabGroupFocus (boolean next) { - return setTabItemFocus (next); -} - -boolean setTabItemFocus (boolean next) { - return false; -} - -int /*long*/ shellMapProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { - return 0; -} - -int /*long*/ sizeAllocateProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { - return 0; -} - -int /*long*/ sizeRequestProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { - return 0; -} - -/** - * 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 /*long*/ topHandle () { - return handle; -} - -int /*long*/ timerProc (int /*long*/ widget) { - return 0; -} - -int /*long*/ treeSelectionProc (int /*long*/ model, int /*long*/ path, int /*long*/ iter, int [] selection, int length) { - return 0; -} - -boolean translateTraversal (int event) { - return false; -} - -int /*long*/ windowProc (int /*long*/ handle, int /*long*/ user_data) { - switch ((int)/*64*/user_data) { - case ACTIVATE: return gtk_activate (handle); - case CHANGED: return gtk_changed (handle); - case CLICKED: return gtk_clicked (handle); - case DAY_SELECTED: return gtk_day_selected (handle); - case DAY_SELECTED_DOUBLE_CLICK: return gtk_day_selected_double_click (handle); - case HIDE: return gtk_hide (handle); - case GRAB_FOCUS: return gtk_grab_focus (handle); - case MAP: return gtk_map (handle); - case MONTH_CHANGED: return gtk_month_changed (handle); - case OUTPUT: return gtk_output (handle); - case POPUP_MENU: return gtk_popup_menu (handle); - case PREEDIT_CHANGED: return gtk_preedit_changed (handle); - case REALIZE: return gtk_realize (handle); - case SELECT: return gtk_select (handle); - case SHOW: return gtk_show (handle); - case VALUE_CHANGED: return gtk_value_changed (handle); - case UNMAP: return gtk_unmap (handle); - case UNREALIZE: return gtk_unrealize (handle); - default: return 0; - } -} - -int /*long*/ windowProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { - switch ((int)/*64*/user_data) { - case EXPOSE_EVENT_INVERSE: { - GdkEventExpose gdkEvent = new GdkEventExpose (); - OS.memmove (gdkEvent, arg0, GdkEventExpose.sizeof); - int /*long*/ paintWindow = paintWindow(); - int /*long*/ window = gdkEvent.window; - if (window != paintWindow) return 0; - return (state & OBSCURED) != 0 ? 1 : 0; - } - case BUTTON_PRESS_EVENT_INVERSE: - case BUTTON_RELEASE_EVENT_INVERSE: - case MOTION_NOTIFY_EVENT_INVERSE: { - return 1; - } - case BUTTON_PRESS_EVENT: return gtk_button_press_event (handle, arg0); - case BUTTON_RELEASE_EVENT: return gtk_button_release_event (handle, arg0); - case COMMIT: return gtk_commit (handle, arg0); - case CONFIGURE_EVENT: return gtk_configure_event (handle, arg0); - case DELETE_EVENT: return gtk_delete_event (handle, arg0); - case ENTER_NOTIFY_EVENT: return gtk_enter_notify_event (handle, arg0); - case EVENT: return gtk_event (handle, arg0); - case EVENT_AFTER: return gtk_event_after (handle, arg0); - case EXPOSE_EVENT: return gtk_expose_event (handle, arg0); - case FOCUS: return gtk_focus (handle, arg0); - case FOCUS_IN_EVENT: return gtk_focus_in_event (handle, arg0); - case FOCUS_OUT_EVENT: return gtk_focus_out_event (handle, arg0); - case KEY_PRESS_EVENT: return gtk_key_press_event (handle, arg0); - case KEY_RELEASE_EVENT: return gtk_key_release_event (handle, arg0); - case INPUT: return gtk_input (handle, arg0); - case LEAVE_NOTIFY_EVENT: return gtk_leave_notify_event (handle, arg0); - case MAP_EVENT: return gtk_map_event (handle, arg0); - case MNEMONIC_ACTIVATE: return gtk_mnemonic_activate (handle, arg0); - case MOTION_NOTIFY_EVENT: return gtk_motion_notify_event (handle, arg0); - case MOVE_FOCUS: return gtk_move_focus (handle, arg0); - case POPULATE_POPUP: return gtk_populate_popup (handle, arg0); - case SCROLL_EVENT: return gtk_scroll_event (handle, arg0); - case SHOW_HELP: return gtk_show_help (handle, arg0); - case SIZE_ALLOCATE: return gtk_size_allocate (handle, arg0); - case STYLE_SET: return gtk_style_set (handle, arg0); - case TOGGLED: return gtk_toggled (handle, arg0); - case UNMAP_EVENT: return gtk_unmap_event (handle, arg0); - case VISIBILITY_NOTIFY_EVENT: return gtk_visibility_notify_event (handle, arg0); - case WINDOW_STATE_EVENT: return gtk_window_state_event (handle, arg0); - case ROW_DELETED: return gtk_row_deleted (handle, arg0); - default: return 0; - } -} - -int /*long*/ windowProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ user_data) { - switch ((int)/*64*/user_data) { - case DELETE_RANGE: return gtk_delete_range (handle, arg0, arg1); - case DELETE_TEXT: return gtk_delete_text (handle, arg0, arg1); - case ROW_ACTIVATED: return gtk_row_activated (handle, arg0, arg1); - case SCROLL_CHILD: return gtk_scroll_child (handle, arg0, arg1); - case STATUS_ICON_POPUP_MENU: return gtk_status_icon_popup_menu (handle, arg0, arg1); - case SWITCH_PAGE: return gtk_switch_page (handle, arg0, arg1); - case TEST_COLLAPSE_ROW: return gtk_test_collapse_row (handle, arg0, arg1); - case TEST_EXPAND_ROW: return gtk_test_expand_row(handle, arg0, arg1); - case ROW_INSERTED: return gtk_row_inserted (handle, arg0, arg1); - default: return 0; - } -} - -int /*long*/ windowProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ arg1, int /*long*/ arg2, int /*long*/ user_data) { - switch ((int)/*64*/user_data) { - case CHANGE_VALUE: return gtk_change_value (handle, arg0, arg1, arg2); - case EXPAND_COLLAPSE_CURSOR_ROW: return gtk_expand_collapse_cursor_row (handle, arg0, arg1, arg2); - case INSERT_TEXT: return gtk_insert_text (handle, arg0, arg1, arg2); - case TEXT_BUFFER_INSERT_TEXT: return gtk_text_buffer_insert_text (handle, arg0, arg1, arg2); - default: return 0; - } -} - -} |