diff options
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/gtk1x')
55 files changed, 0 insertions, 28121 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Color.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Color.java deleted file mode 100644 index e796d2151c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Color.java +++ /dev/null @@ -1,257 +0,0 @@ -package org.eclipse.swt.graphics; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.internal.gtk.*; - -/** - * 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 - */ -public final class Color { - /** - * the handle to the OS color resource - * (Warning: This field is platform dependent) - */ - public GdkColor handle; - Device display; -Color() { -} -/** - * 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_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255</li> - * </ul> - * - * @see #dispose - */ -public Color(Device display, int red, int green, int blue) { - init(display, red, green, blue); -} -/** - * 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_INVALID_ARGUMENT - if the red, green or blue components of the argument are not between 0 and 255</li> - * <li>ERROR_NULL_ARGUMENT - if the rgb argument is null</li> - * </ul> - * - * @see #dispose - */ -public Color(Device display, RGB rgb) { - if (rgb == null) error(SWT.ERROR_NULL_ARGUMENT); - init(display, rgb.red, rgb.green, rgb.blue); -} -/** - * Disposes of the operating system resources associated with - * the color. Applications must dispose of all colors which - * they allocate. - */ -public void dispose() { - /** - * If this is a palette-based display, - * Decrease the reference count for this color. - * If the reference count reaches 0, the slot may - * be reused when another color is allocated. - */ - if (display.colorRefCount != null) { - if (--display.colorRefCount[handle.pixel] == 0) { - display.gdkColors[handle.pixel] = null; - } - } - int colormap = OS.gdk_colormap_get_system(); - OS.gdk_colors_free(colormap, new int[] { handle.pixel }, 1, 0); - this.display = null; - this.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 xColor = color.handle; - return (handle.pixel == xColor.pixel)&&(handle.red == xColor.red) && (handle.green == xColor.green) && (handle.blue == xColor.blue) && (this.display == color.display); -} -void error(int code) { - throw new SWTError(code); -} -/** - * 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() { - 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() { - 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() { - return (handle.red >> 8) & 0xFF; -} - -/** - * Returns an integer hash code for the receiver. Any two - * objects which return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals - */ -public int hashCode() { - return handle.red ^ handle.green ^ handle.blue; -} -/** - * Returns an <code>RGB</code> representing the receiver. - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public RGB getRGB () { - return new RGB(getRed(), getGreen(), getBlue()); -} - -void init(Device display, int red, int green, int blue) { - if (display == null) display = Display.getDefault(); - this.display = display; - handle = new GdkColor(); - handle.red = (short)((red & 0xFF) | ((red & 0xFF) << 8)); - handle.green = (short)((green & 0xFF) | ((green & 0xFF) << 8)); - handle.blue = (short)((blue & 0xFF) | ((blue & 0xFF) << 8)); - int colormap = OS.gdk_colormap_get_system(); - OS.gdk_color_alloc(colormap, handle); - if (display.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; - display.gdkColors[colorCopy.pixel] = colorCopy; - display.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 () { - return "Color {" + getRed() + ", " + getGreen() + ", " + getBlue() + "}"; -} - -public static Color gtk_new(GdkColor gdkColor) { - Color color = new Color(null, gtk_getRGBIntensities(gdkColor)); - return color; -} - -static RGB gtk_getRGBIntensities(GdkColor gdkColor) { - boolean intensitiesAreZero = (gdkColor.red==0) && (gdkColor.green==0) && (gdkColor.blue==0); - if (!intensitiesAreZero) return new RGB ((gdkColor.red&0xFF00)>>8, - (gdkColor.green&0xFF00)>>8, - (gdkColor.blue&0xFF00)>>8 ); - GdkVisual visual = new GdkVisual(); - OS.memmove(visual, OS.gdk_visual_get_system(), GdkVisual.sizeof); - - int r = (gdkColor.pixel&visual.red_mask) >> visual.red_shift; - if (visual.red_prec<8) r = r << (8 - visual.red_prec); - else r = r >> (visual.red_prec - 8); - int g = (gdkColor.pixel&visual.green_mask) >> visual.green_shift; - if (visual.green_prec<8) g = g << (8 - visual.green_prec); - else g = g >> (visual.green_prec - 8); - int b = (gdkColor.pixel&visual.blue_mask) >> visual.blue_shift; - if (visual.blue_prec<8) b = b << (8 - visual.blue_prec); - else b = b >> (visual.blue_prec - 8); - - return new RGB(r, g, b); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Cursor.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Cursor.java deleted file mode 100644 index 52658518c6..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Cursor.java +++ /dev/null @@ -1,302 +0,0 @@ -package org.eclipse.swt.graphics; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.widgets.*; -import org.eclipse.swt.internal.image.*; - -/** - * 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> - */ -public final class Cursor { - /** - * the handle to the OS cursor resource - * (Warning: This field is platform dependent) - */ - public int handle; -Cursor () { -} -/** - * 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_INVALID_ARGUMENT - when an unknown style is specified</li> - * </ul> - * - * @see Cursor for the supported style values - */ -public Cursor(Device display, int style) { - int osFlag = 0; - switch (style) { - case SWT.CURSOR_ARROW: - osFlag = OS.GDK_LEFT_PTR; - break; - case SWT.CURSOR_WAIT: - osFlag = OS.GDK_WATCH; - break; - case SWT.CURSOR_CROSS: - osFlag = OS.GDK_CROSS; - break; - case SWT.CURSOR_APPSTARTING: - osFlag = OS.GDK_WATCH; - break; - case SWT.CURSOR_HAND: - osFlag = OS.GDK_HAND1; - break; - case SWT.CURSOR_HELP: - osFlag = OS.GDK_QUESTION_ARROW; - break; - case SWT.CURSOR_SIZEALL: - osFlag = OS.GDK_DIAMOND_CROSS; - break; - case SWT.CURSOR_SIZENESW: - osFlag = OS.GDK_SIZING; - break; - case SWT.CURSOR_SIZENS: - osFlag = OS.GDK_DOUBLE_ARROW; - break; - case SWT.CURSOR_SIZENWSE: - osFlag = OS.GDK_SIZING; - break; - case SWT.CURSOR_SIZEWE: - osFlag = OS.GDK_SB_H_DOUBLE_ARROW; - break; - case SWT.CURSOR_SIZEN: - osFlag = OS.GDK_TOP_SIDE; - break; - case SWT.CURSOR_SIZES: - osFlag = OS.GDK_BOTTOM_SIDE; - break; - case SWT.CURSOR_SIZEE: - osFlag = OS.GDK_RIGHT_SIDE; - break; - case SWT.CURSOR_SIZEW: - osFlag = OS.GDK_LEFT_SIDE; - break; - case SWT.CURSOR_SIZENE: - osFlag = OS.GDK_TOP_RIGHT_CORNER; - break; - case SWT.CURSOR_SIZESE: - osFlag = OS.GDK_BOTTOM_RIGHT_CORNER; - break; - case SWT.CURSOR_SIZESW: - osFlag = OS.GDK_BOTTOM_LEFT_CORNER; - break; - case SWT.CURSOR_SIZENW: - osFlag = OS.GDK_TOP_LEFT_CORNER; - break; - case SWT.CURSOR_UPARROW: - osFlag = OS.GDK_SB_UP_ARROW; - break; - case SWT.CURSOR_IBEAM: - osFlag = OS.GDK_XTERM; - break; - case SWT.CURSOR_NO: - osFlag = OS.GDK_X_CURSOR; - break; - default: - error(SWT.ERROR_INVALID_ARGUMENT); - } - this.handle = OS.gdk_cursor_new(osFlag); -} -/** - * Constructs a new cursor given a device, image and mask - * data describing the desired cursor appearance, and the x - * and y co-ordinates 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 - when a null argument is passed that is not allowed</li> - * <li>ERROR_INVALID_ARGUMENT - if the source and the mask are not the same - * size, or either is not of depth one, or if the hotspot is outside - * the bounds of the image</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES - if an error occurred constructing the cursor</li> - * </ul> - */ -public Cursor(Device display, ImageData source, ImageData mask, int hotspotX, int hotspotY) { - if (source == null) error(SWT.ERROR_NULL_ARGUMENT); - if (mask == null) { - if (!(source.getTransparencyType() == SWT.TRANSPARENCY_MASK)) 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) { - error(SWT.ERROR_INVALID_ARGUMENT); - } - /* Check depths */ - if (mask.depth != 1) error(SWT.ERROR_INVALID_ARGUMENT); - if (source.depth != 1) error(SWT.ERROR_INVALID_ARGUMENT); - /* Check the hotspots */ - if (hotspotX >= source.width || hotspotX < 0 || - hotspotY >= source.height || hotspotY < 0) { - error(SWT.ERROR_INVALID_ARGUMENT); - } - - /* Swap the bits if necessary */ - byte[] sourceData = new byte[source.data.length]; - byte[] maskData = new byte[mask.data.length]; - /* Swap the bits in each byte */ - 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]; - } - 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]; - } - - int sourcePixmap = OS.gdk_bitmap_create_from_data(0, sourceData, source.width, source.height); - if (sourcePixmap==0) SWT.error(SWT.ERROR_NO_HANDLES); - int maskPixmap = OS.gdk_bitmap_create_from_data(0, maskData, source.width, source.height); - if (maskPixmap==0) SWT.error(SWT.ERROR_NO_HANDLES); - - /* Get the colors */ - GdkColor foreground = new GdkColor(); - foreground.red = 0; - foreground.green = 0; - foreground.blue = 0; - GdkColor background = new GdkColor(); - background.red = (short)65535; - background.green = (short)65535; - background.blue = (short)65535; - - /* Create the cursor */ - /* For some reason, mask and source take reverse roles, both here and on Motif */ - handle = OS.gdk_cursor_new_from_pixmap (maskPixmap, sourcePixmap, foreground, background, hotspotX, hotspotY); - /* Dispose the pixmaps */ - OS.gdk_pixmap_unref (sourcePixmap); - OS.gdk_pixmap_unref (maskPixmap); - if (handle == 0) error(SWT.ERROR_NO_HANDLES); -} -/** - * Disposes of the operating system resources associated with - * the cursor. Applications must dispose of all cursors which - * they allocate. - */ -public void dispose() { - if (handle != 0) 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) { - return (object == this) || ((object instanceof Cursor) && (handle == ((Cursor)object).handle)); -} -void error(int code) { - throw new SWTError(code); -} -public static Cursor gtk_new(int handle) { - Cursor cursor = new Cursor(); - cursor.handle = handle; - return cursor; -} -/** - * Returns an integer hash code for the receiver. Any two - * objects which return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals - */ -public int hashCode() { - return handle; -} -/** - * Returns <code>true</code> if the cursor has been disposed, - * and <code>false</code> otherwise. - * <p> - * This method gets the dispose state for the cursor. - * When a cursor has been disposed, it is an error to - * invoke any other method using the cursor. - * - * @return <code>true</code> when the cursor is disposed and <code>false</code> otherwise - */ -public boolean isDisposed() { - return handle == 0; -} - -/** - * 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/gtk1x/org/eclipse/swt/graphics/DefaultGtkStyle.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/DefaultGtkStyle.java deleted file mode 100644 index 952fa9d404..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/DefaultGtkStyle.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.eclipse.swt.graphics;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.gtk.*;
-
-class DefaultGtkStyle {
-
- private static DefaultGtkStyle instance = null;
- private GtkStyle style = null;
- private int defaultFont;
-
- public Color foregroundColorNORMAL() {
- return new Color(null,
- ((short)0xFF00 & style.fg0_red)>>8,
- ((short)0xFF00 & style.fg0_green)>>8,
- ((short)0xFF00 & style.fg0_blue)>>8);
- }
-
- public Color backgroundColorNORMAL() {
- return new Color(null,
- ((short)0xFF00 & style.bg0_red)>>8,
- ((short)0xFF00 & style.bg0_green)>>8,
- ((short)0xFF00 & style.bg0_blue)>>8);
- }
-
- public Color foregroundColorACTIVE() {
- return new Color(null,
- ((short)0xFF00 & style.fg1_red)>>8,
- ((short)0xFF00 & style.fg1_green)>>8,
- ((short)0xFF00 & style.fg1_blue)>>8);
- }
-
- public Color backgroundColorACTIVE() {
- return new Color(null,
- ((short)0xFF00 & style.bg1_red)>>8,
- ((short)0xFF00 & style.bg1_green)>>8,
- ((short)0xFF00 & style.bg1_blue)>>8);
- }
-
- public Color foregroundColorPRELIGHT() {
- return new Color(null,
- ((short)0xFF00 & style.fg2_red)>>8,
- ((short)0xFF00 & style.fg2_green)>>8,
- ((short)0xFF00 & style.fg2_blue)>>8);
- }
-
- public Color backgroundColorPRELIGHT() {
- return new Color(null,
- ((short)0xFF00 & style.bg2_red)>>8,
- ((short)0xFF00 & style.bg2_green)>>8,
- ((short)0xFF00 & style.bg2_blue)>>8);
- }
-
- public Color foregroundColorSELECTED() {
- return new Color(null,
- ((short)0xFF00 & style.fg3_red)>>8,
- ((short)0xFF00 & style.fg3_green)>>8,
- ((short)0xFF00 & style.fg3_blue)>>8);
- }
-
- public Color backgroundColorSELECTED() {
- return new Color(null,
- ((short)0xFF00 & style.bg3_red)>>8,
- ((short)0xFF00 & style.bg3_green)>>8,
- ((short)0xFF00 & style.bg3_blue)>>8);
- }
-
- public Color foregroundColorINSENSITIVE() {
- return new Color(null,
- ((short)0xFF00 & style.fg4_red)>>8,
- ((short)0xFF00 & style.fg4_green)>>8,
- ((short)0xFF00 & style.fg4_blue)>>8);
- }
-
- public Color backgroundColorINSENSITIVE() {
- return new Color(null,
- ((short)0xFF00 & style.bg4_red)>>8,
- ((short)0xFF00 & style.bg4_green)>>8,
- ((short)0xFF00 & style.bg4_blue)>>8);
- }
-
- public int loadDefaultFont() {
- if (defaultFont == 0) {
- int fnames = Font.getFontNameList(style.font);
- int slength = OS.g_slist_length(fnames);
- if (slength < 1) SWT.error(SWT.ERROR_UNSPECIFIED);
- int name1 = OS.g_slist_nth_data(fnames, 0);
- int length = OS.strlen(name1);
- byte [] buffer1 = new byte[length];
- OS.memmove(buffer1, name1, length);
- defaultFont = OS.gdk_font_load(buffer1);
- if (defaultFont==0) SWT.error(SWT.ERROR_UNSPECIFIED);
- GdkFont gdkFont = new GdkFont();
- OS.memmove(gdkFont, defaultFont, GdkFont.sizeof);
- if (gdkFont.type != OS.GDK_FONT_FONT) SWT.error(SWT.ERROR_UNSPECIFIED);
- }
- return defaultFont;
- }
-
- public static DefaultGtkStyle instance() {
- if (instance==null) instance = new DefaultGtkStyle();
- return instance;
- }
-
- private DefaultGtkStyle() {
- style = new GtkStyle();
- OS.memmove(style, OS.gtk_widget_get_default_style(), GtkStyle.sizeof);
- }
-
-}
-
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Device.java deleted file mode 100644 index 5140074d6d..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Device.java +++ /dev/null @@ -1,556 +0,0 @@ -package org.eclipse.swt.graphics; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.gtk.*; - -public abstract class Device implements Drawable { - - /* Debugging */ - public static boolean DEBUG; - boolean debug = DEBUG; - boolean tracking = DEBUG; - Error [] errors; - Object [] objects; - - /* Colormap and reference count */ - GdkColor [] gdkColors; - int [] colorRefCount; - - /* Disposed flag */ - boolean disposed; - - /* Warning and Error Handlers */ - int logProc; - Callback logCallback; - String [] log_domains = {"Gtk", /*"Gdk", "GLib", "GdkPixbuf"*/}; - int [] handler_ids = new int [log_domains.length]; - boolean warnings = true; - - /* - * 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; - - /* - * 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. - * - * This code will be removed in the future. - */ - protected static Device CurrentDevice; - protected static Runnable DeviceFinder; - static { - try { - Class.forName ("org.eclipse.swt.widgets.Display"); - } catch (Throwable e) {} - } - -/* -* TEMPORARY CODE. -*/ -static 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> - * - * @param data the DeviceData which describes the receiver - * - * @see #create - * @see #init - * @see DeviceData - */ -public Device(DeviceData data) { - if (data != null) { - debug = data.debug; - tracking = data.tracking; - } - create (data); - init (); - if (tracking) { - errors = new Error [128]; - objects = new Object [128]; - } -} - -protected void checkDevice () { - if (disposed) SWT.error(SWT.ERROR_DEVICE_DISPOSED); -} - -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 () { - if (isDisposed()) return; - checkDevice (); - release (); - destroy (); - disposed = true; - if (tracking) { - objects = null; - errors = null; - } -} - -void dispose_Object (Object object) { - for (int i=0; i<objects.length; i++) { - if (objects [i] == object) { - objects [i] = null; - errors [i] = null; - return; - } - } -} - -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 (); - SWT.error (SWT.ERROR_NOT_IMPLEMENTED); - 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; - int count = 0, length = 0; - if (tracking) 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++; - } - } - 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 (); - SWT.error (SWT.ERROR_NOT_IMPLEMENTED); - 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 (); - SWT.error (SWT.ERROR_NOT_IMPLEMENTED); - return new Point (72, 72); -} - -/** - * Returns <code>FontData</code> objects which describe - * the fonts which 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 true if scalable fonts should be returned. - * @return the matching font data - * - * @exception SWTException <ul> - * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public FontData [] getFontList (String faceName, boolean scalable) { - checkDevice (); - String xlfd; - if (faceName == null) { - xlfd = "-*"; - } else { - int dashIndex = faceName.indexOf('-'); - if (dashIndex < 0) { - xlfd = "-*-" + faceName + "-*"; - } else { - xlfd = "-" + faceName + "-*"; - } - } - /* Use the character encoding for the default locale */ - byte [] buffer1 = Converter.wcsToMbcs (null, xlfd, true); - int [] ret = new int [1]; - int listPtr = OS.XListFonts (buffer1, 65535, ret); - int ptr = listPtr; - int [] intBuf = new int [1]; - FontData [] fd = new FontData [ret [0]]; - int fdIndex = 0; - for (int i = 0; i < ret [0]; i++) { - OS.memmove (intBuf, ptr, 4); - int charPtr = intBuf [0]; - int length = OS.strlen (charPtr); - byte [] buffer2 = new byte [length]; - OS.memmove (buffer2, charPtr, length); - /* Use the character encoding for the default locale */ - char [] chars = Converter.mbcsToWcs (null, buffer2); - FontData data = FontData.gtk_new (new String (chars)); - boolean isScalable = data.averageWidth == 0 && data.pixels == 0 && data.points == 0; - if (isScalable == scalable) { - fd [fdIndex++] = data; - } - ptr += 4; - } - // FIXME, leaking font list -// OS.XFreeFontNames (listPtr); - if (fdIndex == ret [0]) return fd; - FontData [] result = new FontData [fdIndex]; - System.arraycopy (fd, 0, result, 0, fdIndex); - return result; -} - -/** - * Returns the matching standard color for the given - * constant, which should be one of the color constants - * specified in class <code>SWT</code>. Any value other - * than one of the SWT color constants which is passed - * in will result in the color black. This color should - * not be 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_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 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_DEVICE_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Font getSystemFont () { - checkDevice (); - return null; -} - -/** - * 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 this.warnings; -} - -protected void init () { - - /* Create GTK warnings and error callbacks */ - 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); -} - -/** - * 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 - * - * @private - */ -public abstract int internal_new_GC (GCData data); - -/** - * Invokes platform specific functionality to dispose a GC handle. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>Device</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @param handle the platform specific GC handle - * @param data the platform specific GC data - * - * @private - */ -public abstract void internal_dispose_GC (int handle, GCData data); - -/** - * Returns <code>true</code> if the device has been disposed, - * and <code>false</code> otherwise. - * <p> - * This method gets the dispose state for the device. - * When a device has been disposed, it is an error to - * invoke any other method using the device. - * - * @return <code>true</code> when the device is disposed and <code>false</code> otherwise - */ -public boolean isDisposed () { - return disposed; -} - -int logProc (int log_domain, int log_level, int message, int user_data) { - if (DEBUG || (debug && warnings)) { - new Error ().printStackTrace (); - OS.g_log_default_handler (log_domain, log_level, message, 0); - } - return 0; -} - -void new_Object (Object object) { - 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; -} - -protected void release () { - if (gdkColors != null) { - int colormap = OS.gdk_colormap_get_system(); - int [] pixel = new int [1]; - for (int i = 0; i < gdkColors.length; i++) { - GdkColor color = gdkColors [i]; - if (color != null) { - while (colorRefCount [i] > 0) { - OS.gdk_color_free(color); - --colorRefCount [i]; - } - } - } - } - gdkColors = null; - colorRefCount = null; - COLOR_BLACK = COLOR_DARK_RED = COLOR_DARK_GREEN = COLOR_DARK_YELLOW = COLOR_DARK_BLUE = - COLOR_DARK_MAGENTA = COLOR_DARK_CYAN = COLOR_GRAY = COLOR_DARK_GRAY = COLOR_RED = - COLOR_GREEN = COLOR_YELLOW = COLOR_BLUE = COLOR_MAGENTA = COLOR_CYAN = COLOR_WHITE = null; - - /* Free the GTK error and warning handler */ - int flags = OS.G_LOG_LEVEL_MASK | OS.G_LOG_FLAG_FATAL | OS.G_LOG_FLAG_RECURSION; - 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]); - } - } - 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>true</code> prevents these - * messages from being printed. If the argument is <code>false</code> - * message printing is not blocked. - * - * @param warnings <code>true</code>if warnings should be handled, 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 (); - this.warnings = warnings; - if (debug) return; - 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]); - } - } - if (warnings) { - 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); - } - } -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/DeviceData.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/DeviceData.java deleted file mode 100644 index 4ed07ebc16..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/DeviceData.java +++ /dev/null @@ -1,24 +0,0 @@ -package org.eclipse.swt.graphics; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -public class DeviceData { - /* - * Motif only fields. - */ - public String display_name; - public String application_name; - public String application_class; - - /* - * Debug fields - may not be honoured - * on some SWT platforms. - */ - public boolean debug; - public boolean tracking; - public Error [] errors; - public Object [] objects; -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Font.java deleted file mode 100644 index b5a0c1e158..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Font.java +++ /dev/null @@ -1,221 +0,0 @@ -package org.eclipse.swt.graphics; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.widgets.*; - -/** - * 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 - */ -public final class Font { - /** - * the handle to the OS font resource - * (Warning: This field is platform dependent) - */ - public int handle; -Font() { -} -/** - * 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 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 display, FontData fd) { - if (fd == null) error(SWT.ERROR_NULL_ARGUMENT); - - String xlfd = fd.getXlfd(); - byte[] buffer = Converter.wcsToMbcs(null, xlfd, true); - handle = OS.gdk_font_load(buffer); - if (handle == 0) { - int hStyle = OS.gtk_widget_get_default_style(); - GtkStyle gtkStyle = new GtkStyle(); - OS.memmove(gtkStyle, hStyle, GtkStyle.sizeof); - handle = OS.gdk_font_ref(gtkStyle.font); - } -} -/** - * 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 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 display, String fontFamily, int height, int style) { - if (fontFamily == null) error(SWT.ERROR_NULL_ARGUMENT); - FontData fd = new FontData(fontFamily, height, style); - byte[] buffer = Converter.wcsToMbcs(null, fd.getXlfd(), true); - handle = OS.gdk_font_load(buffer); - if (handle == 0) { - int hStyle = OS.gtk_widget_get_default_style(); - GtkStyle gtkStyle = new GtkStyle(); - OS.memmove(gtkStyle, hStyle, GtkStyle.sizeof); - handle = OS.gdk_font_ref(gtkStyle.font); - } -} -/** - * Disposes of the operating system resources associated with - * the font. Applications must dispose of all fonts which - * they allocate. - */ -public void dispose() { - if (handle != 0) OS.gdk_font_unref(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 OS.gdk_font_equal(handle, ((Font)object).handle); -} -void error(int code) { - throw new SWTError (code); -} - -/** - * 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() { - int index=0; - int fnames = getFontNameList(handle); - int nfonts = OS.g_slist_length(fnames); - FontData[] answer = new FontData[nfonts]; - for (int i=0; i<nfonts; i++) { - FontData data = new FontData(); - - int name = OS.g_slist_nth_data(fnames, index); - int length = OS.strlen(name); - byte [] buffer1 = new byte[length]; - OS.memmove(buffer1, name, length); - char [] buffer2 = Converter.mbcsToWcs (null, buffer1); - String fontname = new String (buffer2, 0, buffer2.length); - data.setXlfd(fontname); - - // Wild guess, 'a' looks average enough - data.averageWidth = OS.gdk_char_width(handle, (byte)'a'); - - // Wild guess, a progressive font should probably have A wider than l - int widthA = OS.gdk_char_width(handle, (byte)'A'); - int widthl = OS.gdk_char_width(handle, (byte)'l'); - if (widthA == widthl) data.spacing = "m"; - else data.spacing = "p"; - - answer[i] = data; - } - return answer; -} -static int getFontNameList(int handle) { - int[] mem = new int[7]; - OS.memmove(mem, handle, 7*4); - int type = mem[0]; - int ascent = mem[1]; - int descent = mem[2]; - int xfont =mem [3]; - int xdisplay = mem[4]; - int ref_count = mem[5]; - int names = mem[6]; - return names; -} -public static Font gtk_new(int handle) { - Font font = new Font(); - font.handle = handle; - return font; -} -/** - * Returns an integer hash code for the receiver. Any two - * objects which return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals - */ -public int hashCode() { - return handle; -} -/** - * Returns <code>true</code> if the 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/gtk1x/org/eclipse/swt/graphics/FontData.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontData.java deleted file mode 100644 index 5915c07c64..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontData.java +++ /dev/null @@ -1,547 +0,0 @@ -package org.eclipse.swt.graphics;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class describe operating system fonts.
- * Only the public API of this type is platform independent.
- * <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
- */
-public final class FontData {
- /**
- * The company that produced the font
- * Warning: This field is platform dependent.
- */
- public String foundry;
- /**
- * The common name of the font
- * Warning: This field is platform dependent.
- */
- public String fontFamily;
- /**
- * The weight ("normal", "bold")
- * Warning: This field is platform dependent.
- */
- public String weight;
- /**
- * The slant ("o" for oblique, "i" for italic)
- * Warning: This field is platform dependent.
- */
- public String slant;
- /**
- * The set width of the font
- * Warning: This field is platform dependent.
- */
- public String setWidth;
- /**
- * Additional font styles
- * Warning: This field is platform dependent.
- */
- public String addStyle;
- /**
- * The height of the font in pixels
- * Warning: This field is platform dependent.
- */
- public int pixels;
- /**
- * The height of the font in tenths of a point
- * Warning: This field is platform dependent.
- */
- public int points;
- /**
- * The horizontal screen resolution for which the font was designed
- * Warning: This field is platform dependent.
- */
- public int horizontalResolution;
- /**
- * The vertical screen resolution for which the font was designed
- * Warning: This field is platform dependent.
- */
- public int verticalResolution;
- /**
- * The font spacing ("m" for monospace, "p" for proportional)
- * Warning: This field is platform dependent.
- */
- public String spacing;
- /**
- * The average character width for the font
- * Warning: This field is platform dependent.
- */
- public int averageWidth;
- /**
- * The ISO character set registry
- * Warning: This field is platform dependent.
- */
- public String characterSetRegistry;
- /**
- * The ISO character set name
- * Warning: This field is platform dependent.
- */
- public String characterSetName;
- /**
- * The locales of the font
- * (Warning: These fields are platform dependent)
- */
- String lang, country, variant;
-
-/** - * Constructs a new un-initialized font data. - */ -public FontData () {
-}
-/** - * Constructs a new FontData given a string representation - * in the form generated by the <code>FontData.toString</code> - * method. - * <p> - * Note that the representation varies between platforms, - * and a FontData can only be created from a string that was - * generated on the same platform. - * </p> - * - * @param string the string representation of a <code>FontData</code> (must not be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the argument is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the argument does not represent a valid description</li> - * </ul> - * - * @see #toString - */ -public FontData(String string) {
- if (string == null) error(SWT.ERROR_NULL_ARGUMENT);
- int start = 0;
- int end = string.indexOf('|');
- if (end == -1) error(SWT.ERROR_NULL_ARGUMENT);
- String version1 = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) error(SWT.ERROR_NULL_ARGUMENT);
- String name = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) error(SWT.ERROR_NULL_ARGUMENT);
- int height = 0;
- try {
- height = Integer.parseInt(string.substring(start, end));
- } catch (NumberFormatException e) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) error(SWT.ERROR_NULL_ARGUMENT);
- int style = 0;
- try {
- style = Integer.parseInt(string.substring(start, end));
- } catch (NumberFormatException e) {
- error(SWT.ERROR_NULL_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) {
- setName(name);
- setHeight(height);
- setStyle(style);
- return;
- }
- String platform = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) {
- setName(name);
- setHeight(height);
- setStyle(style);
- return;
- }
- String version2 = string.substring(start, end);
-
- if (platform.equals("MOTIF") && version2.equals("1")) {
- start = end + 1;
- end = string.length();
- if (end == -1) {
- setName(name);
- setHeight(height);
- setStyle(style);
- return;
- }
- String xlfd = string.substring(start, end);
- setXlfd(xlfd);
- return;
- }
- setName(name);
- setHeight(height);
- setStyle(style);
-}
-/** - * Constructs a new font data given a font name, - * the height of the desired font in points, - * and a font style. - * - * @param name the name of the font (must not be null) - * @param height the font height in points - * @param style a bit or combination of NORMAL, BOLD, ITALIC - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - when the font name is null</li> - * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li> - * </ul> - */ -public FontData(String name, int height, int style) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (height < 0) error(SWT.ERROR_INVALID_ARGUMENT);
- int dash = name.indexOf('-');
- if (dash != -1) {
- foundry = name.substring(0, dash);
- fontFamily = name.substring(dash + 1);
- } else {
- fontFamily = name;
- }
- points = height * 10;
- if ((style & SWT.BOLD) != 0) {
- weight = "bold";
- } else {
- weight = "medium";
- }
- if ((style & SWT.ITALIC) != 0) {
- slant = "i";
- } else {
- slant = "r";
- }
-}
-
-
-
-/*
- * Public getters
- */
-
-/**
- * Returns the height of the receiver in points.
- *
- * @return the height of this FontData
- *
- * @see #setHeight
- */
-public int getHeight() {
- return points / 10;
-}
-
-/**
- * Returns the name of the receiver.
- * On platforms that support font foundries, the return value will
- * be the foundry followed by a dash ("-") followed by the face name.
- *
- * @return the name of this <code>FontData</code>
- *
- * @see #setName
- */
-public String getName() {
- StringBuffer buffer = new StringBuffer();
- if (foundry != null) {
- buffer.append(foundry);
- buffer.append("-");
- }
- if (fontFamily != null) buffer.append(fontFamily);
- return buffer.toString();
-}
-
-/**
- * Returns the style of the receiver which is a bitwise OR of
- * one or more of the <code>SWT</code> constants NORMAL, BOLD
- * and ITALIC.
- *
- * @return the style of this <code>FontData</code>
- *
- * @see #setStyle
- */
-public int getStyle() {
- int style = 0;
- if (weight.equals("bold"))
- style |= SWT.BOLD;
- if (slant.equals("i"))
- style |= SWT.ITALIC;
- return style;
-}
-
-/**
- * We need this in FontDialog, so we can't just get rid of it or make it private.
- */
-public String gtk_getXlfd() { return getXlfd(); }
-
-String getXlfd() {
- String s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14;
- s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = s9 = s10 = s11 = s12 = s13 = s14 = "*";
-
- if (foundry != null) s1 = foundry;
- if (fontFamily != null) s2 = fontFamily;
- if (weight != null) s3 = weight;
- if (slant != null) s4 = slant;
- if (setWidth != null) s5 = setWidth;
- if (addStyle != null) s6 = addStyle;
- if (pixels != 0) s7 = Integer.toString(pixels);
- if (points != 0) s8 = Integer.toString(points);
- if (horizontalResolution != 0) s9 = Integer.toString(horizontalResolution);
- if (verticalResolution != 0) s10 = Integer.toString(verticalResolution);
- if (spacing != null) s11 = spacing;
-// The following line has been intentionally commented.
-// we don not know the exact average width as in the font definition,
-// so if someone tries to get a similar font, they'd get something weird
-// if (averageWidth != 0) s12 = Integer.toString(averageWidth);
- if (characterSetRegistry != null) s13 = characterSetRegistry;
- if (characterSetName != null) s14 = characterSetName;
-
- String xlfd = "-" + s1+ "-" + s2 + "-" + s3 + "-" + s4 + "-" + s5 + "-" + s6 + "-" + s7 + "-" + s8 + "-"
- + s9 + "-" + s10 + "-" + s11 + "-" + s12 + "-" + s13 + "-" + s14;
- return xlfd;
-}
-public static FontData gtk_new(String xlfd) {
- FontData fontData = new FontData();
- fontData.setXlfd(xlfd);
- return fontData;
-}
-/** - * Returns an integer hash code for the receiver. Any two - * objects which return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals - */ -public int hashCode () {
- return getXlfd().hashCode();
-}
-/** - * 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) error(SWT.ERROR_INVALID_ARGUMENT);
- points = height * 10;
-}
-
-/**
- * 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 which 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);
- int dash = name.indexOf('-');
- if (dash != -1) {
- foundry = name.substring(0, dash);
- fontFamily = name.substring(dash + 1);
- } else {
- fontFamily = name;
- }
-}
-/** - * 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. - * - * @param style the new style for this <code>FontData</code> - * - * @see #getStyle - */ -public void setStyle(int style) {
- if ((style & SWT.BOLD) == SWT.BOLD)
- weight = "bold";
- else
- weight = "medium";
- if ((style & SWT.ITALIC) == SWT.ITALIC)
- slant = "i";
- else
- slant = "r";
-}
-void setXlfd(String xlfd) {
- int start, stop;
- start = 1;
- stop = xlfd.indexOf ("-", start);
- foundry = xlfd.substring(start, stop);
- if (foundry.equals("*")) foundry = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- fontFamily = xlfd.substring(start, stop);
- if (fontFamily.equals("*")) fontFamily = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- weight = xlfd.substring(start, stop);
- if (weight.equals("*")) weight = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- slant = xlfd.substring(start, stop);
- if (slant.equals("*")) slant = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- setWidth = xlfd.substring(start, stop);
- if (setWidth.equals("*")) setWidth = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- addStyle = xlfd.substring(start, stop);
- if (addStyle.equals("*")) addStyle = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- String s = xlfd.substring(start, stop);
- if (!s.equals("") && !s.equals("*"))
- pixels = Integer.parseInt(s);
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- s = xlfd.substring(start, stop);
- if (!s.equals("") && !s.equals("*"))
- points = Integer.parseInt(s);
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- s = xlfd.substring(start, stop);
- if (!s.equals("") && !s.equals("*"))
- horizontalResolution = Integer.parseInt(s);
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- s = xlfd.substring(start, stop);
- if (!s.equals("") && !s.equals("*"))
- verticalResolution = Integer.parseInt(s);
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- spacing = xlfd.substring(start, stop);
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- s = xlfd.substring(start, stop);
- if (!s.equals("") && !s.equals("*"))
- averageWidth = Integer.parseInt(s);
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- characterSetRegistry = xlfd.substring(start, stop);
- if (characterSetRegistry.equals("*")) characterSetRegistry = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- characterSetName = xlfd.substring(start);
- if (characterSetName.equals("*")) characterSetName = null;
-}
-/** - * Returns a string representation of the receiver which is suitable - * for constructing an equivalent instance using the - * <code>FontData(String)</code> constructor. - * - * @return a string representation of the FontData - * - * @see FontData - */ -public String toString() {
- return "1|" + fontFamily + "|" + getHeight() + "|" + getStyle() + "|" +
- "GTK|1|" + getXlfd();
-}
-
-/** - * Compares the argument to the receiver, and returns true - * if they represent the <em>same</em> object using a class - * specific comparison. - * - * @param object the object to compare with this object - * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise - * - * @see #hashCode - */ -public boolean equals (Object object) {
- return (object == this) || ((object instanceof FontData) &&
- getXlfd().equals(((FontData)object).getXlfd()));
-}
-void error(int code) {
- throw new SWTError(code);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontMetrics.java deleted file mode 100644 index b1bd432690..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/FontMetrics.java +++ /dev/null @@ -1,122 +0,0 @@ -package org.eclipse.swt.graphics;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-import org.eclipse.swt.internal.gtk.*;
-
-/** - * 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 - */ -
-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 fontHandle) {
- GdkFont f = new GdkFont();
- OS.memmove (f, fontHandle, GdkFont.sizeof);
-
- FontMetrics fontMetrics = new FontMetrics();
- fontMetrics.ascent = f.ascent;
- fontMetrics.descent = f.descent;
- fontMetrics.averageCharWidth = OS.gdk_char_width(fontHandle, (byte)'a');
- fontMetrics.leading = 3;
- fontMetrics.height = fontMetrics.ascent+fontMetrics.descent+3;
- return fontMetrics;
-}
-/** - * Returns an integer hash code for the receiver. Any two - * objects which 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/gtk1x/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/GC.java deleted file mode 100644 index 24374928a3..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/GC.java +++ /dev/null @@ -1,1759 +0,0 @@ -package org.eclipse.swt.graphics; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -import org.eclipse.swt.widgets.*; -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>. - * <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> - * - * @see org.eclipse.swt.events.PaintEvent - */ -public final class GC { - /** - * the handle to the OS device context - * (Warning: This field is platform dependent) - */ - public int handle; - Drawable drawable; - GCData data; - - -/* - * === Constructors === - */ - -GC() { -} - -/** - * Constructs a new instance of this class which has been - * configured to draw on the specified drawable. Sets the - * foreground and background color in the GC to match those - * in the drawable. - * <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_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> - */ -public GC(Drawable drawable) { - if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - - data = new GCData(); - handle = drawable.internal_new_GC(data); - this.drawable = drawable; - - // The colors we get from the widget are not always right. - // Get the default GTK_STATE_NORMAL colors - setBackground( DefaultGtkStyle.instance().backgroundColorNORMAL() ); - setForeground( DefaultGtkStyle.instance().foregroundColorNORMAL() ); - - - // Feature in GDK. - // Sometimes, gdk_gc_new() doesn't get the font from the control, - // and also, some controls don't contain a font; so when the GC - // was created in internal_new_gc(), the font might or might not - // be set; if the font isn't there, just fall back to default. - GdkGCValues values = new GdkGCValues(); - OS.gdk_gc_get_values(handle, values); - if (values.font == 0) { - OS.gdk_gc_set_font(handle, DefaultGtkStyle.instance().loadDefaultFont() ); - } - - if (data.image != null) { - data.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(); - } - -} - - - -/** - * 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> - */ -/* - * === Access - Get/Set === - */ - -public Color getBackground() { - if (handle == 0) error(SWT.ERROR_WIDGET_DISPOSED); - GdkColor gdkColor = _getBackgroundGdkColor(); - return Color.gtk_new(gdkColor); -} -/** - * 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 (color == null) error(SWT.ERROR_NULL_ARGUMENT); - if (color.handle == null) error(SWT.ERROR_NULL_ARGUMENT); - if (handle == 0) error(SWT.ERROR_WIDGET_DISPOSED); - OS.gdk_gc_set_background(handle, color.handle); -} - -/** - * 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) error(SWT.ERROR_WIDGET_DISPOSED); - GdkColor gdkColor = _getForegroundGdkColor(); - return Color.gtk_new(gdkColor); -} - -/** - * 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) error(SWT.ERROR_WIDGET_DISPOSED); - if (color == null) error(SWT.ERROR_NULL_ARGUMENT); - if (color.handle == null) error(SWT.ERROR_NULL_ARGUMENT); - OS.gdk_gc_set_foreground(handle, color.handle); -} - - - - - - - -/** - * 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> - */ -/* - * === Access - Get - Calculated === - */ - -public int getAdvanceWidth(char ch) { - byte[] charBuffer = Converter.wcsToMbcs(null, new char[] { ch }); - return OS.gdk_char_width(_getGCFont(), charBuffer[0]); -} -/** - * 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) { - byte[] charBuffer = Converter.wcsToMbcs(null, new char[] { ch }); - int[] lbearing = new int[1]; - int[] rbearing = new int[1]; - int[] unused = new int[1]; - OS.gdk_string_extents(_getGCFont(), charBuffer, lbearing, rbearing, unused, unused, unused); - return rbearing[0] - lbearing[0]; -} -/** - * 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 (data.clipRgn == 0) { - int[] width = new int[1]; int[] height = new int[1]; - int[] unused = new int[1]; - OS.gdk_window_get_geometry(data.drawable, unused, unused, width, height, unused); - return new Rectangle(0, 0, width[0], height[0]); - } - GdkRectangle rect = new GdkRectangle(); - OS.gdk_region_get_clipbox(data.clipRgn, rect); - return new Rectangle(rect.x, rect.y, rect.width, rect.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> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void getClipping(Region region) { - if (region == null) error(SWT.ERROR_NULL_ARGUMENT); - int hRegion = region.handle; - if (data.clipRgn == 0) { - int[] width = new int[1]; int[] height = new int[1]; - int[] unused = new int[1]; - OS.gdk_window_get_geometry(data.drawable, unused, unused, width, height, unused); - hRegion = OS.gdk_region_new(); - GdkRectangle rect = new GdkRectangle(); - rect.x = 0; rect.y = 0; - rect.width = (short)width[0]; rect.height = (short)height[0]; - region.handle = OS.gdk_region_union_with_rect(hRegion, rect); - return; - } - hRegion = OS.gdk_region_new(); - region.handle = OS.gdk_regions_union(data.clipRgn, hRegion); -} -/** - * 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() { - return Font.gtk_new(_getGCFont()); -} -/** - * 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> - */ -// Not done -public FontMetrics getFontMetrics() { - int fontHandle = _getGCFont(); - if (fontHandle==0) { - error(SWT.ERROR_UNSPECIFIED); - } - GdkFont gdkFont = new GdkFont(); - OS.memmove(gdkFont, fontHandle, GdkFont.sizeof); - byte [] w = Converter.wcsToMbcs (null, "w", true); - return FontMetrics.gtk_new(fontHandle); -} - -/** - * 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() { - 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() { - GdkGCValues values = new GdkGCValues(); - OS.gdk_gc_get_values(handle, values); - return values.line_width; -} -/** - * 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() { - GdkGCValues values = new GdkGCValues(); - OS.gdk_gc_get_values(handle, values); - return values.function == OS.GDK_XOR; -} -/** - * 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() { - return data.clipRgn != 0; -} - - -/** - * 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 (data.clipRgn == 0) data.clipRgn = OS.gdk_region_new(); - GdkRectangle rect = new GdkRectangle(); - rect.x = (short)x; rect.y = (short)y; - rect.width = (short)width; rect.height = (short)height; - OS.gdk_gc_set_clip_rectangle(handle, rect); - data.clipRgn = OS.gdk_regions_subtract(data.clipRgn, data.clipRgn); - data.clipRgn = OS.gdk_region_union_with_rect(data.clipRgn, rect); -} -/** - * Sets the area of the receiver which can be changed - * by drawing operations to the rectangular area specified - * by the argument. - * - * @param rect the clipping rectangle - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setClipping(Rectangle rect) { - if (rect == null) error(SWT.ERROR_NULL_ARGUMENT); - 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. - * - * @param rect the clipping region. - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setClipping(Region region) { - if (data.clipRgn == 0) data.clipRgn = OS.gdk_region_new(); - if (region == null) { - data.clipRgn = OS.gdk_regions_subtract(data.clipRgn, data.clipRgn); - OS.gdk_gc_set_clip_mask(handle, OS.GDK_NONE); - } else { - data.clipRgn = OS.gdk_regions_subtract(data.clipRgn, data.clipRgn); - data.clipRgn = OS.gdk_regions_union(region.handle, data.clipRgn); - OS.gdk_gc_set_clip_region(handle, region.handle); - } -} -/** - * 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) { - int fontHandle = 0; - if (font == null) { - GtkStyle gtkStyle = new GtkStyle(); - int style = OS.gtk_widget_get_default_style(); - OS.memmove(gtkStyle, style, GtkStyle.sizeof); - fontHandle = gtkStyle.font; - } else { - fontHandle = font.handle; - } - OS.gdk_gc_set_font(handle, fontHandle); -} - -/** - * 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 SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void setLineStyle(int lineStyle) { - switch (lineStyle) { - case SWT.LINE_SOLID: - this.data.lineStyle = lineStyle; - OS.gdk_gc_set_line_attributes(handle, 0, OS.GDK_LINE_SOLID, OS.GDK_CAP_BUTT, OS.GDK_JOIN_MITER); - return; - case SWT.LINE_DASH: - OS.gdk_gc_set_dashes(handle, 0, new byte[] {6, 2}, 2); - break; - case SWT.LINE_DOT: - OS.gdk_gc_set_dashes(handle, 0, new byte[] {3, 1}, 2); - break; - case SWT.LINE_DASHDOT: - OS.gdk_gc_set_dashes(handle, 0, new byte[] {6, 2, 3, 1}, 4); - break; - case SWT.LINE_DASHDOTDOT: - OS.gdk_gc_set_dashes(handle, 0, new byte[] {6, 2, 3, 1, 3, 1}, 6); - break; - default: - error(SWT.ERROR_INVALID_ARGUMENT); - } - this.data.lineStyle = lineStyle; - OS.gdk_gc_set_line_attributes(handle, 0, OS.GDK_LINE_DOUBLE_DASH, OS.GDK_CAP_BUTT, OS.GDK_JOIN_MITER); -} -/** - * 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. - * - * @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 width) { - if (data.lineStyle == SWT.LINE_SOLID) { - OS.gdk_gc_set_line_attributes(handle, width, OS.GDK_LINE_SOLID, OS.GDK_CAP_BUTT, OS.GDK_JOIN_MITER); - } else { - OS.gdk_gc_set_line_attributes(handle, width, OS.GDK_LINE_DOUBLE_DASH, OS.GDK_CAP_BUTT, OS.GDK_JOIN_MITER); - } -} -/** - * 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. - * - * @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> - */ -public void setXORMode(boolean val) { - if (val) { - OS.gdk_gc_set_function(handle, OS.GDK_XOR); - } else { - OS.gdk_gc_set_function(handle, OS.GDK_COPY); - } -} -/** - * Returns the extent of the given string. No tab - * expansion or carriage return processing will be performed. - * <p> - * The <em>extent</em> of a string is the width and height of - * the rectangular area it would cover if drawn in a particular - * font (in this case, the current font in the receiver). - * </p> - * - * @param string the string to measure - * @return a point containing the extent of the string - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Point stringExtent(String string) { - if (string == null) error(SWT.ERROR_NULL_ARGUMENT); - byte[] buffer = Converter.wcsToMbcs(null, string, true); - int width = OS.gdk_string_width(_getGCFont(), buffer); - int height = OS.gdk_string_height(_getGCFont(), buffer); - return new Point(width, height); -} -/** - * Returns the extent of the given string. Tab expansion and - * carriage return processing are performed. - * <p> - * The <em>extent</em> of a string is the width and height of - * the rectangular area it would cover if drawn in a particular - * font (in this case, the current font in the receiver). - * </p> - * - * @param string the string to measure - * @return a point containing the extent of the string - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public Point textExtent(String string) { - if (string == null) error(SWT.ERROR_NULL_ARGUMENT); - byte[] buffer = Converter.wcsToMbcs(null, string, true); - int width = OS.gdk_string_width(_getGCFont(), buffer); - int height = OS.gdk_string_height(_getGCFont(), buffer); - return new Point(width, height); -} - - - -/* - * === Access - Internal utils === - */ - -private GdkGCValues _getGCValues() { - GdkGCValues values = new GdkGCValues(); - OS.gdk_gc_get_values(handle, values); - return values; -} -private GdkColor _getForegroundGdkColor() { - GdkGCValues values = _getGCValues(); - GdkColor color = new GdkColor(); - color.pixel = values.foreground_pixel; - color.red = values.foreground_red; - color.green = values.foreground_green; - color.blue = values.foreground_blue; - return color; -} -private GdkColor _getBackgroundGdkColor() { - GdkGCValues values = _getGCValues(); - GdkColor color = new GdkColor(); - color.pixel = values.background_pixel; - color.red = values.background_red; - color.green = values.background_green; - color.blue = values.background_blue; - return color; -} -private int _getGCFont() { - GdkGCValues values = _getGCValues(); - if (values.font==0) { - SWT.error(SWT.ERROR_UNSPECIFIED); - } - return values.font; -} - - - -/** - * 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> - */ -/* - * === Drawing operations proper === - */ - -/** - * Copies a rectangular area of the receiver at the specified - * position into the image, which must be of type <code>SWT.BITMAP</code>. - * - * @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 xGC = OS.gdk_gc_new(image.pixmap); - if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES); - // is it possible/necessary to set the subwindow mode?? - OS.gdk_window_copy_area (image.pixmap, // dest window - xGC, - 0, 0, // dest coords - image.pixmap, // src window - x, y, // src coords - rect.width, rect.height); - OS.gdk_gc_destroy(xGC); -} - -/** - * 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) { - OS.gdk_window_copy_area (data.drawable, handle, - destX, destY, - data.drawable, - srcX, srcY, width, height); -} - -/** - * 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 IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if any of the width, height or endAngle is zero.</li> - * </ul> - * @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 endAngle) { - if (width < 0) { - x = x + width; - width = -width; - } - if (height < 0) { - y = y + height; - height = -height; - } - if (width == 0 || height == 0 || endAngle == 0) { - error(SWT.ERROR_INVALID_ARGUMENT); - } - OS.gdk_draw_arc(data.drawable, handle, 0, x, y, width, height, startAngle * 64, endAngle * 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 forground 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 - */ -public void drawFocus(int x, int y, int width, int height) { - GtkStyle style = new GtkStyle(); - int hStyle = OS.gtk_widget_get_default_style(); - OS.memmove(style, hStyle, GtkStyle.sizeof); - GdkColor color = new GdkColor(); - color.pixel = style.fg0_pixel; - color.red = style.fg0_red; - color.green = style.fg0_green; - color.blue = style.fg0_blue; - GdkGCValues values = new GdkGCValues(); - OS.gdk_gc_get_values(handle, values); - OS.gdk_gc_set_foreground(handle, color); - OS.gdk_draw_rectangle(data.drawable, handle, 0, x, y, width, height); - color.pixel = values.foreground_pixel; - color.red = values.foreground_red; - color.green = values.foreground_green; - color.blue = values.foreground_blue; - OS.gdk_gc_set_foreground(handle, color); -} -/** - * 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 SWTError <ul> - * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawImage(Image image, int x, int y) { - if (image == null) error(SWT.ERROR_NULL_ARGUMENT); - int pixmap = image.pixmap; - int [] unused = new int [1]; int [] width = new int [1]; int [] height = new int [1]; - OS.gdk_window_get_geometry(pixmap, unused, unused, width, height, unused); - drawImage(image, 0, 0, width[0], height[0], x, y, width[0], height[0]); -} - -/** - * 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 of the given coordinates - * are negative or lie outside the bounds of their respective images. - * - * @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 the given coordinates are outside the bounds of their respective images</li> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_NO_HANDLES - if no handles are available to perform the operation</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) { - /* basic sanity checks */ - 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 (srcImage == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (srcImage.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - - /* source image properties */ - int[] width = new int[1]; - int[] height = new int[1]; - int[] unused = new int[1]; - OS.gdk_window_get_geometry(srcImage.pixmap, unused, unused, width, height, unused); - if ((srcY + srcWidth > width[0]) || - (srcY + srcHeight > height[0])) { - error(SWT.ERROR_INVALID_ARGUMENT); - } - - /* Special case: If we don't need to scale, and there is no alpha/mask, - * then we can just blit the image inside the X server - no net traffic - */ - boolean needScaling = (srcWidth != destWidth) || (srcHeight != destHeight); - boolean simple = !needScaling & (srcImage.mask == 0); - - if (simple) { - OS.gdk_draw_pixmap(data.drawable, handle, srcImage.pixmap, - srcX, srcY, - destX, destY, - width[0], height[0]); - return; - } - - - /* Fetch a local GdkPixbuf from server */ - Pixbuffer pixbuf = new Pixbuffer(srcImage); - - /* Scale if necessary */ - if ((srcWidth != destWidth) || (srcHeight != destHeight)) { - double scale_x = (double)destWidth / (double)srcWidth; - double scale_y = (double)destHeight / (double)srcHeight; - double offset_x = - srcX * scale_x; - double offset_y = - srcY * scale_y; - - int destSizePixbuf = GDKPIXBUF.gdk_pixbuf_new ( - GDKPIXBUF.GDK_COLORSPACE_RGB, - true, 8, destWidth, destHeight); - GDKPIXBUF.gdk_pixbuf_scale( - pixbuf.handle, // src, - destSizePixbuf, - 0, - 0, - destWidth, destHeight, - offset_x, offset_y, - scale_x, scale_y, - GDKPIXBUF.GDK_INTERP_BILINEAR); - pixbuf.handle = destSizePixbuf; - } - - /* Paint it */ - GDKPIXBUF.gdk_pixbuf_render_to_drawable_alpha( - pixbuf.handle, - data.drawable, - 0, 0, - destX, destY, - destWidth, destHeight, - GDKPIXBUF.GDK_PIXBUF_ALPHA_BILEVEL, 128, - GDKPIXBUF.GDK_RGB_DITHER_NORMAL, - 0, 0 - ); -} - -/** - * 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) { - 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 (width < 0) { - x = x + width; - width = -width; - } - if (height < 0) { - y = y + height; - height = -height; - } - OS.gdk_draw_arc(data.drawable, handle, 0, x, y, width, height, 0, 23040); -} -/** - * 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 (pointArray == null) error(SWT.ERROR_NULL_ARGUMENT); - short[] points = new short[pointArray.length]; - for (int i = 0; i < pointArray.length; i++) { - points[i] = (short)pointArray[i]; - } - OS.gdk_draw_polygon(data.drawable, handle, 0, points, points.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 (pointArray == null) error(SWT.ERROR_NULL_ARGUMENT); - short[] points = new short[pointArray.length]; - for (int i = 0; i < pointArray.length; i++) { - points[i] = (short)pointArray[i]; - } - OS.gdk_draw_lines(data.drawable, handle, points, points.length / 2); -} -/** - * 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 (width < 0) { - x = x + width; - width = -width; - } - if (height < 0) { - y = y + height; - height = -height; - } - 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) 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. - * - * @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 horizontal diameter of the arc at the four corners - * @param arcHeight the vertical diameter of the arc at the four corners - * - * @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) { - 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 naw2 = Compatibility.floor(naw, 2); - int nah2 = Compatibility.floor(nah, 2); - - OS.gdk_draw_arc(data.drawable, handle, 0, nx, ny, naw, nah, 5760, 5760); - OS.gdk_draw_arc(data.drawable, handle, 0, nx, ny + nh - nah, naw, nah, 11520, 5760); - OS.gdk_draw_arc(data.drawable, handle, 0, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760); - OS.gdk_draw_arc(data.drawable, handle, 0, nx + nw - naw, ny, naw, nah, 0, 5760); - OS.gdk_draw_line(data.drawable, handle, nx + naw2, ny, nx + nw - naw2, ny); - OS.gdk_draw_line(data.drawable, handle, nx,ny + nah2, nx, ny + nh - nah2); - OS.gdk_draw_line(data.drawable, handle, nx + naw2, ny + nh, nx + nw - naw2, ny + nh); - OS.gdk_draw_line(data.drawable, handle, nx + nw, ny + nah2, nx + nw, ny + nh - nah2); -} -/** - * Draws the given string, using the receiver's current font and - * foreground color. No tab expansion or carriage return processing - * will be performed. The background of the rectangular area where - * the string is being drawn will be filled with the receiver's - * background color. - * - * @param string the string to be drawn - * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn - * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawString (String string, int x, int y) { - drawString(string, x, y, false); -} -/** - * Draws the given string, using the receiver's current font and - * foreground color. No tab expansion or carriage return processing - * will be performed. If <code>isTransparent</code> is <code>true</code>, - * then the background of the rectangular area where the string is being - * drawn will not be modified, otherwise it will be filled with the - * receiver's background color. - * - * @param string the string to be drawn - * @param x the x coordinate of the top left corner of the rectangular area where the string is to be drawn - * @param y the y coordinate of the top left corner of the rectangular area where the string is to be drawn - * @param isTransparent if <code>true</code> the background will be transparent, otherwise it will be opaque - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the string is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - */ -public void drawString(String string, int x, int y, boolean isTransparent) { - if (string == null) error(SWT.ERROR_NULL_ARGUMENT); - byte[] buffer = Converter.wcsToMbcs(null, string, true); - byte[] buffer1 = Converter.wcsToMbcs(null, "Y", true); - int[] unused = new int[1]; - int[] width = new int[1]; - int[] ascent = new int[1]; - int[] average_ascent = new int [1]; - int fontHandle = _getGCFont(); - OS.gdk_string_extents(fontHandle, buffer, unused, unused, width, ascent, unused); - OS.gdk_string_extents(fontHandle, buffer1, unused, unused, unused, average_ascent, unused); - if (ascent[0]<average_ascent[0]) ascent[0] = average_ascent[0]; - if (!isTransparent) { - int height = OS.gdk_string_height(fontHandle, buffer); - GdkGCValues values = new GdkGCValues(); - OS.gdk_gc_get_values(handle, values); - GdkColor color = new GdkColor(); - color.pixel = values.background_pixel; - color.red = values.background_red; - color.green = values.background_green; - color.blue = values.background_blue; - OS.gdk_gc_set_foreground(handle, color); - OS.gdk_draw_rectangle(data.drawable, handle, 1, x, y, width[0], height); - color.pixel = values.foreground_pixel; - color.red = values.foreground_red; - color.green = values.foreground_green; - color.blue = values.foreground_blue; - OS.gdk_gc_set_foreground(handle, color); - } - OS.gdk_draw_string(data.drawable, fontHandle, handle, x, y + ascent[0], buffer); -} -/** - * 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, false); -} -/** - * 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) { - if (string == null) error(SWT.ERROR_NULL_ARGUMENT); - byte[] buffer = Converter.wcsToMbcs(null, string, true); - byte[] buffer1 = Converter.wcsToMbcs(null, "Y", true); - int fontHandle = _getGCFont(); - int[] unused = new int[1]; - int[] width = new int[1]; - int[] ascent = new int[1]; - int[] average_ascent = new int [1]; - OS.gdk_string_extents(fontHandle, buffer, unused, unused, width, ascent, unused); - OS.gdk_string_extents(fontHandle, buffer1, unused, unused, unused, average_ascent, unused); - if (ascent[0]<average_ascent[0]) ascent[0] = average_ascent[0]; - if (!isTransparent) { - int height = OS.gdk_string_height(fontHandle, buffer); - GdkGCValues values = new GdkGCValues(); - OS.gdk_gc_get_values(handle, values); - GdkColor color = new GdkColor(); - color.pixel = values.background_pixel; - color.red = values.background_red; - color.green = values.background_green; - color.blue = values.background_blue; - OS.gdk_gc_set_foreground(handle, color); - OS.gdk_draw_rectangle(data.drawable, handle, 1, x, y, width[0], height); - color.pixel = values.foreground_pixel; - color.red = values.foreground_red; - color.green = values.foreground_green; - color.blue = values.foreground_blue; - OS.gdk_gc_set_foreground(handle, color); - } - OS.gdk_draw_string(data.drawable, fontHandle, handle, x, y + ascent[0], buffer); -} - -/** - * 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 specifing 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) { - // NOT IMPLEMENTED - drawText(string, x, y, (flags & SWT.DRAW_TRANSPARENT) != 0); -} - -/** - * 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 IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if any of the width, height or endAngle is zero.</li> - * </ul> - * @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 endAngle) { - if (width < 0) { - x = x + width; - width = -width; - } - if (height < 0) { - y = y + height; - height = -height; - } - if (width == 0 || height == 0 || endAngle == 0) { - error(SWT.ERROR_INVALID_ARGUMENT); - } - GdkGCValues values = new GdkGCValues(); - OS.gdk_gc_get_values(handle, values); - GdkColor color = new GdkColor(); - color.pixel = values.background_pixel; - color.red = values.background_red; - color.green = values.background_green; - color.blue = values.background_blue; - OS.gdk_gc_set_foreground(handle, color); - OS.gdk_draw_arc(data.drawable, handle, 1, x, y, width, height, startAngle * 64, endAngle * 64); - color.pixel = values.foreground_pixel; - color.red = values.foreground_red; - color.green = values.foreground_green; - color.blue = values.foreground_blue; - OS.gdk_gc_set_foreground(handle, color); -} - -/** - * 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 - */ -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; - - GdkGCValues values = new GdkGCValues(); - OS.gdk_gc_get_values(handle, values); - GdkColor foregroundGdkColor = new GdkColor(); - - RGB backgroundRGB, foregroundRGB; - backgroundRGB = Color.gtk_getRGBIntensities(_getBackgroundGdkColor()); - foregroundRGB = Color.gtk_getRGBIntensities(_getForegroundGdkColor()); - - 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 == toRGB) { - fillRectangle(x, y, width, height); - return; - } - ImageData.fillGradientRectangle(this, Display.getCurrent(), - 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 (width < 0) { - x = x + width; - width = -width; - } - if (height < 0) { - y = y + height; - height = -height; - } - GdkGCValues values = new GdkGCValues(); - OS.gdk_gc_get_values(handle, values); - GdkColor color = new GdkColor(); - color.pixel = values.background_pixel; - color.red = values.background_red; - color.green = values.background_green; - color.blue = values.background_blue; - OS.gdk_gc_set_foreground(handle, color); - OS.gdk_draw_arc(data.drawable, handle, 1, x, y, width, height, 0, 23040); - color.pixel = values.foreground_pixel; - color.red = values.foreground_red; - color.green = values.foreground_green; - color.blue = values.foreground_blue; - OS.gdk_gc_set_foreground(handle, color); -} -/** - * 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 (pointArray == null) error(SWT.ERROR_NULL_ARGUMENT); - short[] points = new short[pointArray.length]; - for (int i = 0; i < pointArray.length; i++) { - points[i] = (short)pointArray[i]; - } - GdkGCValues values = new GdkGCValues(); - OS.gdk_gc_get_values(handle, values); - GdkColor color = new GdkColor(); - color.pixel = values.background_pixel; - color.red = values.background_red; - color.green = values.background_green; - color.blue = values.background_blue; - OS.gdk_gc_set_foreground(handle, color); - OS.gdk_draw_polygon(data.drawable, handle, 1, points, points.length / 2); - color.pixel = values.foreground_pixel; - color.red = values.foreground_red; - color.green = values.foreground_green; - color.blue = values.foreground_blue; - OS.gdk_gc_set_foreground(handle, color); -} -/** - * 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 - */ -public void fillRectangle(int x, int y, int width, int height) { - if (width < 0) { - x = x + width; - width = -width; - } - if (height < 0) { - y = y + height; - height = -height; - } - - GdkGCValues values = new GdkGCValues(); - OS.gdk_gc_get_values(handle, values); - GdkColor color = new GdkColor(); - color.pixel = values.background_pixel; - color.red = values.background_red; - color.green = values.background_green; - color.blue = values.background_blue; - OS.gdk_gc_set_foreground(handle, color); - OS.gdk_draw_rectangle(data.drawable, handle, 1, x, y, width, height); - color.pixel = values.foreground_pixel; - color.red = values.foreground_red; - color.green = values.foreground_green; - color.blue = values.foreground_blue; - OS.gdk_gc_set_foreground(handle, color); -} -/** - * Fills the interior of the specified rectangle, using the receiver's - * background color. - * - * @param rectangle 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 - */ -public void fillRectangle(Rectangle rect) { - if (rect == null) 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 horizontal diameter of the arc at the four corners - * @param arcHeight the vertical diameter of the arc at the four corners - * - * @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) { - 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; - - naw = Math.min(naw,nw); - nah = Math.min(nah, nh); - - int naw2 = Compatibility.round(naw, 2); - int nah2 = Compatibility.round(nah, 2); - - GdkGCValues values = new GdkGCValues(); - OS.gdk_gc_get_values(handle, values); - GdkColor color = new GdkColor(); - color.pixel = values.background_pixel; - color.red = values.background_red; - color.green = values.background_green; - color.blue = values.background_blue; - OS.gdk_gc_set_foreground(handle, color); - OS.gdk_draw_arc(data.drawable, handle, 1, nx, ny, naw, nah, 5760, 5760); - OS.gdk_draw_arc(data.drawable, handle, 1, nx, ny + nh - nah, naw, nah, 11520, 5760); - OS.gdk_draw_arc(data.drawable, handle, 1, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760); - OS.gdk_draw_arc(data.drawable, handle, 1, nx + nw - naw, ny, naw, nah, 0, 5760); - OS.gdk_draw_rectangle(data.drawable, handle, 1, nx + naw2, ny, nw - naw, nh); - OS.gdk_draw_rectangle(data.drawable, handle, 1, nx, ny + nah2, naw2, nh - nah); - OS.gdk_draw_rectangle(data.drawable, handle, 1, nx + nw - (naw / 2), ny + nah2, naw2, nh -nah); - color.pixel = values.foreground_pixel; - color.red = values.foreground_red; - color.green = values.foreground_green; - color.blue = values.foreground_blue; - OS.gdk_gc_set_foreground(handle, color); -} - -/** - * 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 - */ -/* - * === As yet unclassified === - */ - -public boolean equals(Object object) { - return (object == this) || ((object instanceof GC) && (handle == ((GC)object).handle)); -} -/** - * Returns an integer hash code for the receiver. Any two - * objects which return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @exception SWTException <ul> - * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> - * </ul> - * - * @see #equals - */ -public int hashCode() { - return handle; -} -void error(int code) { - throw new SWTError(code); -} -/** - * 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; -} -/** - * Disposes of the operating system resources associated with - * the graphics context. Applications must dispose of all GCs - * which they allocate. - */ -public void dispose() { - if (handle == 0) return; - - /* Free resources */ - int clipRgn = data.clipRgn; - if (clipRgn != 0) OS.gdk_region_destroy(clipRgn); - Image image = data.image; - if (image != null) image.memGC = null; - - /* Dispose the GC */ - if(drawable == null) - OS.gdk_gc_unref(handle); - else - drawable.internal_dispose_GC(handle, data); - - data.drawable = // data.colormap = data.fontList = - data.clipRgn = data.renderTable = 0; - drawable = null; - data.image = null; - data = null; - 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 "GC {*DISPOSED*}"; - return "GC {" + handle + "}"; -} - -/** - * 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 specifing 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) { - //NOT IMPLEMENTED - return textExtent(string); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/GCData.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/GCData.java deleted file mode 100644 index ad7b9c7fc2..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/GCData.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.eclipse.swt.graphics;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-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> - * - * @private - */ -public final class GCData {
- public Image image;
- public int drawable;
- public int clipRgn;
- public int lineStyle = SWT.LINE_SOLID;
- public int renderTable;
-} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Image.java deleted file mode 100644 index f733122bf4..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Image.java +++ /dev/null @@ -1,650 +0,0 @@ -package org.eclipse.swt.graphics; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.widgets.*; -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 explicitely 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 - */ -public final class Image implements Drawable{ - - /** - * specifies whether the receiver is a bitmap or an icon - * (one of <code>SWT.BITMAP</code>, <code>SWT.ICON</code>) - */ - public int type; - - /** - * The handle to the OS pixmap resource. - * Warning: This field is platform dependent. - */ - public int pixmap; - - /** - * The handle to the OS mask resource. - * Warning: This field is platform dependent. - */ - public int mask; - - /** - * The device where this image was created. - */ - Device device; - - /** - * specifies the transparent pixel - * (Warning: This field is platform dependent) - */ - int transparentPixel = -1; - - /** - * The GC the image is currently selected in. - * Warning: This field is platform dependent. - */ - GC memGC; - - /** - * The alpha data of the image. - * Warning: This field is platform dependent. - */ - byte[] alphaData; - - /** - * The global alpha value to be used for every pixel. - * Warning: This field is platform dependent. - */ - int alpha = -1; - - /** - * Specifies the default scanline padding. - * Warning: This field is platform dependent. - */ - static final int DEFAULT_SCANLINE_PAD = 4; - - - -/* - * CONSTRUCTORS - */ - -Image() { -} - -/** - * 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> - * - * @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_INVALID_ARGUMENT - if either the width or height is negative</li> - * </ul> - */ -public Image(Device display, int width, int height) { - init(display, width, height); -} - -/** - * 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>IMAGE_COPY</b></dt> - * <dd>the result is an identical copy of srcImage</dd> - * <dt><b>IMAGE_DISABLE</b></dt> - * <dd>the result is a copy of srcImage which has a <em>disabled</em> look</dd> - * <dt><b>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 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> - * </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) { - /* basic sanity */ - if (device == null) device = Device.getDevice(); - if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - this.device = device; - if (srcImage == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (srcImage.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - this.type = srcImage.type; - this.mask = 0; - - /* this is somewhat ugly, because this dilutes the encapsulation - * of knowledge about what the cloning operations do (e.g., the - * following lines assume graying and disabling don't change alpha) - */ - this.alphaData = srcImage.alphaData; - this.alpha = srcImage.alpha; - this.transparentPixel = srcImage.transparentPixel; - // bogus - are we sure about memGC? - - /* Special case: - * If all we want is just a clone of the existing pixmap, it can - * be done entirely in the X server, without copying across the net. - */ - if (flag == SWT.IMAGE_COPY) { - int[] unused = new int[1]; - int[] width = new int[1]; int[] height = new int[1]; - int[] depth = new int[1]; - OS.gdk_window_get_geometry(pixmap, unused, unused, width, height, depth); - pixmap = OS.gdk_pixmap_new (0, width[0], height[0], depth[0]); - int gc = OS.gdk_gc_new (pixmap); - OS.gdk_draw_pixmap(pixmap, gc, srcImage.pixmap, - 0,0,0,0, width[0], height[0]); - OS.gdk_gc_destroy(gc); - 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); - } - - /* we are not quite done yet. Need to copy the maskData */ - if (srcImage.mask != 0) { - /* Generate the mask if necessary. */ -// if (srcImage.transparentPixel != -1) srcImage.createMask(); - mask = OS.gdk_pixmap_new(0, width[0], height[0], 1); - gc = OS.gdk_gc_new(mask); - OS.gdk_draw_pixmap(mask, gc, srcImage.mask, - 0,0,0,0, width[0], height[0]); - OS.gdk_gc_destroy(gc); - /* Destroy the image mask if the there is a GC created on the image */ - if (srcImage.transparentPixel != -1 && srcImage.memGC != null) srcImage.destroyMask(); - } - - - return; - } - - - - - Pixbuffer pb = new Pixbuffer(srcImage); - Pixbuffer pb2 = new Pixbuffer(pb, flag); - pb2.toImage(this); - - -} - -/** - * 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> - * - * @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 the bounds rectangle is null</li> - * <li>ERROR_INVALID_ARGUMENT - if either the rectangle's width or height is negative</li> - * </ul> - */ -public Image(Device display, Rectangle bounds) { - if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - init(display, bounds.width, bounds.height); -} - -/** - * 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 the image data is null</li> - * </ul> - */ -public Image(Device display, ImageData image) { - if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (display == null) display = Display.getDefault(); - init(display, image); -} - -/** - * 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, and the mask image - * must have a color depth of 1. Pixel transparency in either image - * will be ignored. If either image is an icon to begin with, an - * exception is thrown. - * <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 either the source or mask is null </li> - * <li>ERROR_INVALID_ARGUMENT - if source and mask are different sizes or - * if the mask is not monochrome, or if either the source or mask - * is already an icon</li> - * </ul> - */ -public Image(Device display, ImageData source, ImageData mask) { - if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (mask == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (display == null) display = Display.getDefault(); - if (source.width != mask.width || source.height != mask.height) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - ImageData image; - if (source.depth != 1) - image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad, source.data); - else { - image = source.getTransparencyMask(); //create an imagedata with scanlinepad == 1 and invalid data - int[] row = new int[source.width]; - for (int y = 0; y < source.height; y++) { - source.getPixels(0, y, source.width, row, 0); - image.setPixels(0, y, source.width, row, 0); - }//change source data format from scanlinePad == 4 to scanlinePad == 1; - - } - image.type = SWT.ICON; - image.maskPad = mask.scanlinePad; - image.maskData = mask.data; - init(display, image); -} - -/** - * 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. - * <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> - * new Image(device, clazz.getResourceAsStream("file.gif")); - * </pre> - * - * @param device the device on which to create the image - * @param stream the input stream to load the image from - * - * @exception SWTException <ul> - * <li>ERROR_INVALID_IMAGE - if the image file contains invalid data </li> - * <li>ERROR_IO - if an IO error occurs while reading data</li> - * </ul> - */ -public Image(Device display, InputStream stream) { - if (stream == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (display == null) display = Display.getDefault(); - init(display, new ImageData(stream)); -} - -/** - * 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 SWTException <ul> - * <li>ERROR_INVALID_IMAGE - if the image file contains invalid data </li> - * <li>ERROR_IO - if an IO error occurs while reading data</li> - * </ul> - */ -public Image(Device display, String filename) { - if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (display == null) display = Display.getDefault(); - init(display, new ImageData(filename)); -} - -/** - * Destroy the receiver's mask if it exists. - */ -void destroyMask() { - if (mask == 0) return; - OS.gdk_bitmap_unref(mask); - mask = 0; -} - -/** - * Disposes of the operating system resources associated with - * the image. Applications must dispose of all images which - * they allocate. - */ -public void dispose () { - if (pixmap != 0) OS.gdk_pixmap_unref(pixmap); - if (mask != 0) OS.gdk_pixmap_unref(mask); - 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) { - return (object == this) || ((object instanceof Image) && - (pixmap == ((Image)object).pixmap) && - (mask == ((Image)object).mask)); -} - -/** - * 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() { - return null; -} - -/** - * 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 (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); -} - -/** - * 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() { - int[] unused = new int[1]; int[] width = new int[1]; int[] height = new int[1]; - OS.gdk_window_get_geometry(pixmap, unused, unused, width, height, unused); - return new Rectangle(0, 0, width[0], height[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() { - return new Pixbuffer(this).getImageData(); -} - -public static Image gtk_new(int type, int pixmap, int mask) { - Image image = new Image(); - image.type = type; - image.pixmap = pixmap; - image.mask = mask; - return image; -} -/** - * Returns an integer hash code for the receiver. Any two - * objects which return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals - */ -public int hashCode () { - return pixmap; -} -/** - * 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 - * - * @private - */ -public int internal_new_GC (GCData data) { - if (pixmap == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); - if (data == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); - if (type != SWT.BITMAP || memGC != null) { - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - - data.image = this; - int gc = OS.gdk_gc_new(pixmap); - data.drawable = pixmap; - return gc; -} -/** - * 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 handle the platform specific GC handle - * @param data the platform specific GC data - * - * @private - */ -public void internal_dispose_GC (int gc, GCData data) { - OS.gdk_gc_unref(gc); -} - -void init(Device display, int width, int height) { - device = display; - GdkVisual visual = new GdkVisual (); - OS.memmove(visual, OS.gdk_visual_get_system(), GdkVisual.sizeof); - this.pixmap = OS.gdk_pixmap_new(0, width, height, visual.depth); - if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES); - /* Fill the bitmap with white */ - GdkColor white = new GdkColor(); - int colormap = OS.gdk_colormap_get_system(); - OS.gdk_color_white(colormap, white); - int gc = OS.gdk_gc_new(pixmap); - OS.gdk_gc_set_foreground(gc, white); - OS.gdk_draw_rectangle(pixmap, gc, 1, 0, 0, width, height); - OS.gdk_gc_destroy(gc); - OS.gdk_colors_free(colormap, new int[] { white.pixel }, 1, 0); - this.type = SWT.BITMAP; -} - -void init(Device display, ImageData image) { - if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (display == null) display = Display.getCurrent(); - device = display; - - /* - * We don't really care about the real depth of the ImageData we are - * given. We stretch everything to 24bpp which is the native GdkPixbuffer - * depth. HOWEVER, there is one situation where this is not acceptable, - * namely bitmaps (1bpp), because they may be used in contexts that are - * sensitive to pixmap depth. - */ - Pixbuffer buff = new Pixbuffer(image); - buff.toImage(this); - return; -} - -/** - * 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; -} - -/** - * 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/gtk1x/org/eclipse/swt/graphics/Pixbuffer.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Pixbuffer.java deleted file mode 100644 index 460a3bbb6c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Pixbuffer.java +++ /dev/null @@ -1,492 +0,0 @@ -package org.eclipse.swt.graphics; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -import org.eclipse.swt.SWT; -import org.eclipse.swt.internal.gtk.*; - -/** - * This class is <strong>not</strong> part of the SWT API, - * and its existence is not relevant for application programmers. - * - * Pixbuffer represents local GdkPixbuf images on the client. - */ -final class Pixbuffer { - - /* the handle to the OS resource. - All state is kept in the OS */ - int handle; - - /* pointer to the actual pixel array */ - int data; - - /* whether the alpha data in the pixbuf is due to - a transparency mask or an alpha channel */ - boolean hasMask = false; - boolean hasAlpha = false; - int constantAlpha = -1; - int transparentPixel = -1; - - - /* - * Constructors. - * There are three ways to create a Pixbuffer: - * pull one from a Drawable, create from ImageData, - * or clone an existing Pixbuffer. - */ - - private Pixbuffer() {} - - /** - * Pull a Pixbuffer from an Image living on the X Server - * (making this operation expensive). - */ - Pixbuffer (Image src) { - if (src == null || src.pixmap == 0) SWT.error(SWT.ERROR_NULL_ARGUMENT); - - // get the geometry - int[] unused = new int[1]; - int[] w = new int[1]; - int[] h = new int[1]; - int[] d = new int[1]; - OS.gdk_window_get_geometry(src.pixmap, unused, unused, w, h, unused); - int width = w[0]; - int height = h[0]; - - // create the actual OS resource - createHandle(width, height); - - // pull the color data - int cmap = OS.gdk_colormap_get_system(); - GDKPIXBUF.gdk_pixbuf_get_from_drawable( - handle, - src.pixmap, - cmap, - 0,0,0,0, - width, height); - - // the tricky part is alpha - if (src.alphaData != null) fillAlphaFromAlphaBytes(src.alphaData); - else if (src.alpha != -1) fillConstantAlpha(src.alpha); - else if (src.mask != 0) fillAlphaFromPixmapMask(src.mask); - else if (src.transparentPixel != -1) fillAlphaFromTransparentPixel(src.pixmap, src.transparentPixel); - else fillOpaque(); - } - - /** - * Create a Pixbuffer from image data. - */ - Pixbuffer (ImageData src) { - if (src == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - - createHandle(src.width, src.height); - - // populate the pixbuf with data - int stride = GDKPIXBUF.gdk_pixbuf_get_rowstride(handle); - int dataSize = src.height*stride; - byte[] bytes = new byte[dataSize]; - switch (src.getTransparencyType()) { - case SWT.TRANSPARENCY_ALPHA: _blit2platformAlpha(bytes, src, src.width, src.height, stride); break; - case SWT.TRANSPARENCY_MASK: _blit2platformMask (bytes, src, src.width, src.height, stride); break; - case SWT.TRANSPARENCY_PIXEL: _blit2platformPixel(bytes, src, src.width, src.height, stride); break; - case SWT.TRANSPARENCY_NONE: _blit2platformNone (bytes, src, src.width, src.height, stride); break; - } - OS.memmove(data, bytes, dataSize); - } - - /** - * Clone an existing Pixbuffer (possibly making it look - * grayed out or disabled) - */ - Pixbuffer (Pixbuffer src, int flag) { - if (src == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - if (src.handle==0) SWT.error(SWT.ERROR_NULL_ARGUMENT); - this.hasAlpha = src.hasAlpha; - this.constantAlpha = src.constantAlpha; - this.hasMask = src.hasMask; - - /* First, get a copy all our own */ - handle = GDKPIXBUF.gdk_pixbuf_copy(src.handle); - data = GDKPIXBUF.gdk_pixbuf_get_pixels(this.handle); - - // simplest case - just clone what we have - if (flag==SWT.IMAGE_COPY) return; - - // gather some information we will need for disabling or graying - int width = getWidth(); - int height = getHeight(); - int stride = GDKPIXBUF.gdk_pixbuf_get_rowstride(this.handle); - int dataSize = height * stride; - byte[] bytes = new byte[dataSize]; - OS.memmove(bytes,data,dataSize); - int lineAddress = 0; - int pixelAddress; - - if (flag==SWT.IMAGE_DISABLE) { - for (int y=0; y<height; y++) { - for (int x=0; x<width; x++) { - pixelAddress = lineAddress+x*4; - - int intensity = - bytes[pixelAddress+0] * bytes[pixelAddress+0] + - bytes[pixelAddress+1] * bytes[pixelAddress+1] + - bytes[pixelAddress+2] * bytes[pixelAddress+2]; - byte value = (intensity < 9000)? - (byte)0 : (byte) 255; - bytes[pixelAddress+0] = bytes[pixelAddress+1] = bytes[pixelAddress+2] = value; - // no change to alpha - } - lineAddress += stride; - } - /* move it back */ - OS.memmove(data, bytes, dataSize); - return; - } - - if (flag==SWT.IMAGE_GRAY) { - for (int y=0; y<height; y++) { - for (int x=0; x<width; x++) { - pixelAddress = lineAddress+x*4; - int intensity = - (bytes[pixelAddress+0] + - bytes[pixelAddress+1] + - bytes[pixelAddress+2] ) / 3; - bytes[pixelAddress+0] = (byte)intensity; - bytes[pixelAddress+1] = (byte)intensity; - bytes[pixelAddress+2] = (byte)intensity; - // no change to alpha - } - lineAddress += stride; - } - /* move it back */ - OS.memmove(data, bytes, dataSize); - return; - } - - // flag is neither COPY nor DISABLE nor GRAY - SWT.error(SWT.ERROR_INVALID_ARGUMENT); - } - - - /** - * Push the pixbuf to the X Server - */ - void toImage (Image dest) { - if (dest==null) SWT.error(SWT.ERROR_NULL_ARGUMENT); - int w = getWidth(); - int h = getHeight(); - GdkVisual visual = new GdkVisual(); - OS.memmove(visual, OS.gdk_visual_get_system(), GdkVisual.sizeof); - dest.pixmap = OS.gdk_pixmap_new (0, w, h, visual.depth); - dest.mask = 0; // for now; we fill it later in this method - GDKPIXBUF.gdk_pixbuf_render_to_drawable_alpha(handle, // src - dest.pixmap, // dest drawable - 0,0, 0,0, - w, h, - GDKPIXBUF.GDK_PIXBUF_ALPHA_BILEVEL, 128, - GDKPIXBUF.GDK_RGB_DITHER_NORMAL, 0,0); - - // now the mask, if any - if (hasMask) { - // bring the pixel data into Java memory - int stride = GDKPIXBUF.gdk_pixbuf_get_rowstride(handle); - byte[] srcBytes = new byte[h*stride]; - OS.memmove(srcBytes, data, h*stride); - - // the mask lines are padded to 4 bytes, that is 32 pixels - int maskwpl = w/32; if (w%32!=0) maskwpl+=1; - int maskBpl = maskwpl*4; // Bytes per line for the mask - byte[] bytes = new byte[h * maskBpl]; - for (int y=0; y<h; y++) { - int lineAddress = y * maskBpl; - for (int x=0; x<w; x++) - if (srcBytes[y*stride + x*4 + 3] != 0) { - int byteAddress = lineAddress + x/8; - int bit = 1<<(x%8); - bytes[byteAddress] |= (byte)bit; - } // if - } // for y - dest.mask = OS.gdk_bitmap_create_from_data(0, bytes, maskBpl*8, h); - } // hasMask - - else if (hasAlpha) { - SWT.error(SWT.ERROR_NOT_IMPLEMENTED); - } - - else if (constantAlpha!=-1) { - SWT.error(SWT.ERROR_NOT_IMPLEMENTED); - } - } - - /** - * Return the ImageData for the receiver. - */ - ImageData getImageData() { - int width = getWidth(); - int height = getHeight(); - int stride = GDKPIXBUF.gdk_pixbuf_get_rowstride(handle); - byte[] bytes = _getDataBytes(); - ImageData answer = new ImageData(width, height, 24, new PaletteData(0xFF0000, 0x00FF00, 0x0000FF)); - - if (hasMask) { - answer.maskData = new byte[((width+7)/8)*height]; - answer.maskPad = 1; - } - - for (int y=0; y<height; y++) - for (int x=0; x<width; x++) { - int address = y*stride + x*4; - byte r = bytes[address+0]; - byte g = bytes[address+1]; - byte b = bytes[address+2]; - answer.setPixel(x,y, r<<16+g<<8+b); - byte alpha = bytes[address+3]; - if (hasAlpha) { - answer.setAlpha(x,y, alpha); - } - if (hasMask && (alpha!=0)) { - // Find out where to stab the bit - int mask_bytes_per_line = (width+7) / 8; - int x_inside_line = x / 8; - int shift_inside_byte = x - (x_inside_line*8); - answer.maskData[x_inside_line + (y*mask_bytes_per_line)] |= (128 >> shift_inside_byte); - } - } - if (constantAlpha!=-1) answer.alpha = constantAlpha; - return answer; - } - - int getWidth() { - return GDKPIXBUF.gdk_pixbuf_get_width (handle); - } - - int getHeight() { - return GDKPIXBUF.gdk_pixbuf_get_height (handle); - } - - - /** - * Actually create the OS resource. - * No matter what, the GdkPixbuf we create always has - * an alpha channel. - */ - private void createHandle(int width, int height) { - handle = GDKPIXBUF.gdk_pixbuf_new(GDKPIXBUF.GDK_COLORSPACE_RGB, - true, - 8, - width, height); - if (this.handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); - data = GDKPIXBUF.gdk_pixbuf_get_pixels(handle); - } - - private void fillAlphaFromPixmapMask(int mask) { - hasMask = true; - - /* pull the mask data from the X Server */ - // get the geometry - int[] unused = new int[1]; - int[] w = new int[1]; - int[] h = new int[1]; - int[] d = new int[1]; - OS.gdk_window_get_geometry(mask, unused, unused, w, h, unused); - int width = Math.min(w[0], getWidth()); - int height = Math.min(h[0], getHeight()); - /* Get the data */ - int xMaskPtr = OS.gdk_image_get(mask, 0, 0, width, height); - if (xMaskPtr == 0) SWT.error(SWT.ERROR_NO_HANDLES); - - /* stuff the alpha values */ - byte[] bytes = _getDataBytes(); - int stride = GDKPIXBUF.gdk_pixbuf_get_rowstride(handle); - for (int y=0; y<height; y++) - for (int x=0; x<width; x++) { - int pixel_value = OS.gdk_image_get_pixel(xMaskPtr, x, y); - if (pixel_value==0) bytes[y*stride + x*4 +3] = 0; - else if (pixel_value==1) bytes[y*stride + x*4 +3] = (byte)255; - else { System.out.println("GDK insanity: bitmap contains bits other than 0 or 1"); SWT.error(SWT.ERROR_UNSPECIFIED); } - } - /* move it back */ - OS.memmove(data, bytes, bytes.length); - } - - private void fillAlphaFromTransparentPixel(int pm, int pixel) { - transparentPixel = pixel; - - /* pull the data from the X Server */ - // get the geometry - int[] unused = new int[1]; - int[] w = new int[1]; - int[] h = new int[1]; - int[] d = new int[1]; - OS.gdk_window_get_geometry(pm, unused, unused, w, h, unused); - int width = Math.min(w[0], getWidth()); - int height = Math.min(h[0], getHeight()); - /* Get the data */ - int xImage = OS.gdk_image_get(pm, 0, 0, width, height); - if (xImage == 0) SWT.error(SWT.ERROR_NO_HANDLES); - - /* stuff the alpha values */ - byte[] bytes = _getDataBytes(); - int stride = GDKPIXBUF.gdk_pixbuf_get_rowstride(handle); - for (int y=0; y<height; y++) - for (int x=0; x<width; x++) { - int pixel_value = OS.gdk_image_get_pixel(xImage, x, y); - if (pixel_value==pixel) bytes[y*stride + x*4 +3] = 0; - else bytes[y*stride + x*4 +3] = (byte)255; - } - /* move it back */ - OS.memmove(data, bytes, bytes.length); - } - - private void fillAlphaFromAlphaBytes(byte[] alpha) { - hasAlpha = true; - SWT.error (SWT.ERROR_NOT_IMPLEMENTED); - } - - private void fillConstantAlpha(int alpha) { - if ((alpha<0)||(alpha>255)) SWT.error (SWT.ERROR_INVALID_ARGUMENT); - constantAlpha = alpha; - _fillConstantAlpha((byte)alpha); - } - - private void fillOpaque() { - _fillConstantAlpha((byte)255); - } - - /** - * Assume the handle represents a valid GdkPixbuf, - * and data is pointing to the correct location in memory. - * Fill all alpha bytes with the specified value. - */ - private void _fillConstantAlpha (byte value) { - // first, get some technical info - int width = getWidth(); - int height = getHeight(); - int stride = GDKPIXBUF.gdk_pixbuf_get_rowstride(this.handle); - int dataSize = height * stride; - byte[] bytes = new byte[dataSize]; - OS.memmove(bytes,data,dataSize); - int lineAddress = 0; - int pixelAddress; - - // set all alpha bytes to 255 - for (int y=0; y<height; y++) { - for (int x=0; x<width; x++) { - pixelAddress = lineAddress+x*4; - bytes[pixelAddress+3] = value; - } - lineAddress += stride; - } - /* move it back */ - OS.memmove(data, bytes, dataSize); - } - - private void _blit2platformNone (byte[] bytes, - ImageData source, - int width, - int height, - int stride) - { - int lineAddress = 0; - for (int y=0; y<height; y++) { - for (int x=0; x<width; x++) { - RGB rgb = source.palette.getRGB(source.getPixel(x,y)); - bytes[lineAddress + x*4 + 0] = (byte)rgb.red; - bytes[lineAddress + x*4 + 1] = (byte)rgb.green; - bytes[lineAddress + x*4 + 2] = (byte)rgb.blue; - bytes[lineAddress + x*4 + 3] = (byte)255; - } - lineAddress += stride; - } - } - - private void _blit2platformAlpha (byte[] bytes, - ImageData source, - int width, - int height, - int stride) - { - hasAlpha = true; - int lineAddress = 0; - for (int y=0; y<height; y++) { - for (int x=0; x<width; x++) { - RGB rgb = source.palette.getRGB(source.getPixel(x,y)); - bytes[lineAddress + x*4 + 0] = (byte)rgb.red; - bytes[lineAddress + x*4 + 1] = (byte)rgb.green; - bytes[lineAddress + x*4 + 2] = (byte)rgb.blue; - bytes[lineAddress + x*4 + 3] = (byte)source.getAlpha(x,y); - } - lineAddress += stride; - } - } - - private void _blit2platformPixel (byte[] bytes, - ImageData source, - int width, - int height, - int stride - ) - { - hasMask = true; - int lineAddress = 0; - for (int y=0; y<height; y++) { - for (int x=0; x<width; x++) { - int pixel = source.getPixel(x,y); - if (pixel==source.transparentPixel) { - bytes[lineAddress + x*4 + 0] = (byte)0; - bytes[lineAddress + x*4 + 1] = (byte)0; - bytes[lineAddress + x*4 + 2] = (byte)0; - bytes[lineAddress + x*4 + 3] = (byte)0; - } else { - RGB rgb = source.palette.getRGB(pixel); - bytes[lineAddress + x*4 + 0] = (byte)rgb.red; - bytes[lineAddress + x*4 + 1] = (byte)rgb.green; - bytes[lineAddress + x*4 + 2] = (byte)rgb.blue; - bytes[lineAddress + x*4 + 3] = (byte)255; - } - } - lineAddress += stride; - } - } - - private void _blit2platformMask (byte[] bytes, - ImageData source, - int width, - int height, - int stride - ) - { - hasMask = true; - ImageData maskData = source.getTransparencyMask(); - int lineAddress = 0; - for (int y=0; y<height; y++) { - for (int x=0; x<width; x++) { - RGB rgb = source.palette.getRGB(source.getPixel(x,y)); - bytes[lineAddress + x*4 + 0] = (byte)rgb.red; - bytes[lineAddress + x*4 + 1] = (byte)rgb.green; - bytes[lineAddress + x*4 + 2] = (byte)rgb.blue; - int alpha = 0; - if (maskData.getPixel(x,y) !=0) alpha=255; - bytes[lineAddress + x*4 + 3] = (byte)alpha; - } - lineAddress += stride; - } - } - - /** - * Transfer the pixel data from OS memory to Java memory - * and return the Java byte array - */ - private byte[] _getDataBytes() { - int height = GDKPIXBUF.gdk_pixbuf_get_height (handle); - int stride = GDKPIXBUF.gdk_pixbuf_get_rowstride(handle); - int size = height*stride; - byte[] bytes = new byte[size]; - OS.memmove(bytes, data, size); - return bytes; - } -} - diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Region.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Region.java deleted file mode 100644 index 150b55f0d0..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/graphics/Region.java +++ /dev/null @@ -1,273 +0,0 @@ -package org.eclipse.swt.graphics;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-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 rectangles. - * <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> - */ -public final class Region {
- /** - * the OS resource for the region - * (Warning: This field is platform dependent) - */ - public int handle;
-/** - * Constructs a new empty region. - */ -public Region() {
- handle = OS.gdk_region_new();
-}
-Region(int handle) {
- this.handle = handle;
-}
-/** - * Adds the given rectangle to the collection of rectangles - * 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 (rect == null) error(SWT.ERROR_NULL_ARGUMENT);
- if (rect.width < 0 || rect.height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- GdkRectangle gdkRect = new GdkRectangle();
- gdkRect.x = (short)rect.x;
- gdkRect.y = (short)rect.y;
- gdkRect.width = (short)rect.width;
- gdkRect.height = (short)rect.height;
- int hOld = handle;
- /**
- * Feature in GDK. Due to the way the GDK region calls work,
- * we have to reassign the handle and destroy the old one.
- */
- handle = OS.gdk_region_union_with_rect(handle, gdkRect);
- OS.gdk_region_destroy(hOld);
-}
-/** - * Adds all of the rectangles which make up the area covered - * by the argument to the collection of rectangles 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 (region == null) error(SWT.ERROR_NULL_ARGUMENT);
- /**
- * Feature in GDK. Due to the way the GDK region calls work,
- * we have to reassign the handle and destroy the old one.
- */
- int hOld = handle;
- handle = OS.gdk_regions_union(handle, region.handle);
- OS.gdk_region_destroy(hOld);
-}
-/** - * 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) {
- 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) error(SWT.ERROR_NULL_ARGUMENT);
- return contains(pt.x, pt.y);
-}
-/** - * Disposes of the operating system resources associated with - * the region. Applications must dispose of all regions which - * they allocate. - */ -public void dispose() {
- if (handle != 0) 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;
- int xRegion = ((Region)object).handle;
- if (handle == xRegion) return true;
- if (xRegion == 0) return false;
- return OS.gdk_region_equal(handle, xRegion);
-}
-void error(int code) {
- throw new SWTError(code);
-}
-/** - * Returns a rectangle which represents the rectangular - * union of the collection of rectangles 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() {
- GdkRectangle rect = new GdkRectangle();
- OS.gdk_region_get_clipbox(handle, rect);
- return new Rectangle(rect.x, rect.y, rect.width, rect.height);
-}
-public static Region gtk_new(int handle) {
- return new Region(handle);
-}
-/** - * Returns an integer hash code for the receiver. Any two - * objects which return <code>true</code> when passed to - * <code>equals</code> must return the same value for this - * method. - * - * @return the receiver's hash - * - * @see #equals - */ -public int hashCode() {
- return handle;
-}
-/** - * Returns <code>true</code> if the rectangle described by the - * arguments intersects with any of the rectangles the receiver - * mainains 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 - */ -public boolean intersects (int x, int y, int width, int height) {
- GdkRectangle osRect = new GdkRectangle();
- osRect.x = (short)x;
- osRect.y = (short)y;
- osRect.width = (short)width;
- osRect.height = (short)height;
- return OS.gdk_region_rect_in(handle, osRect) != OS.GDK_OVERLAP_RECTANGLE_OUT;
-}
-/** - * Returns <code>true</code> if the given rectangle intersects - * with any of the rectangles the receiver mainains 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 - */ -public boolean intersects(Rectangle rect) {
- if (rect == null) 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() {
- return OS.gdk_region_empty(handle);
-}
-/**
- * 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/gtk1x/org/eclipse/swt/internal/Converter.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/internal/Converter.java deleted file mode 100644 index 66d9149da7..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/internal/Converter.java +++ /dev/null @@ -1,85 +0,0 @@ -package org.eclipse.swt.internal;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-/** - * 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 char [] NullCharArray = new char [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 () {
- /*
- | ptr cp |
- DefaultCodePage == nil ifFalse: [^DefaultCodePage].
- cp := ''. "$NON-NLS$"
- (ptr := OSStringZ address: (NlLanginfo callWith: 49)) isNull
- ifFalse: [cp := String copyFromOSMemory: ptr].
- cp isEmpty ifFalse: [
- IsSunOS ifTrue: [
- (cp size > 3 and: [(cp copyFrom: 1 to: 3) = 'ISO'])
- ifTrue: [cp := cp copyFrom: 4 to: cp size]].
- ^DefaultCodePage := cp].
- IsAIX ifTrue: [^DefaultCodePage := 'ISO8859-1'].
- IsSunOS ifTrue: [^DefaultCodePage := '8859-1'].
- ^DefaultCodePage := 'iso8859_1'
- */
- return null;
-}
-static boolean is7BitAscii (byte [] buffer) {
- for (int i=0; i<buffer.length; i++) {
- if ((buffer [i] & 0xFF) > 0x7F) return false;
- }
- return true;
-}
-static boolean is7BitAscii (char [] buffer) {
- for (int i=0; i<buffer.length; i++) {
- if (buffer [i] > 0x7F) return false;
- }
- return true;
-}
-public static char [] mbcsToWcs (String codePage, byte [] buffer) {
- //SLOW AND BOGUS
- return new String (buffer).toCharArray ();
-}
-/* TEMPORARY CODE */
-public static byte [] wcsToMbcs (String codePage, String string) {
- return wcsToMbcs (codePage, string, false);
-}
-public static byte [] wcsToMbcs (String codePage, String string, boolean terminate) {
- //SLOW AND BOGUS
- int count = string.length ();
- if (terminate) count++;
- char [] buffer = new char [count];
- string.getChars (0, string.length (), buffer, 0);
- return wcsToMbcs (codePage, buffer, false);
-}
-/* TEMPORARY CODE */
-public static byte [] wcsToMbcs (String codePage, char [] buffer) {
- return wcsToMbcs (codePage, buffer, false);
-}
-public static byte [] wcsToMbcs (String codePage, char [] buffer, boolean terminate) {
- //SLOW AND BOGUS
- if (!terminate) return new String (buffer).getBytes ();
- byte [] buffer1 = new String (buffer).getBytes ();
- byte [] buffer2 = new byte [buffer1.length + 1];
- System.arraycopy (buffer1, 0, buffer2, 0, buffer1.length);
- return buffer2;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Button.java deleted file mode 100644 index c08b892a20..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Button.java +++ /dev/null @@ -1,493 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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>LEFT, RIGHT, CENTER</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection</dd> - * </dl> - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - */ -public class Button extends Control { - int boxHandle; - 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 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) != 0) { - return checkBits (style, SWT.CENTER, SWT.LEFT, SWT.RIGHT, 0, 0, 0); - } - if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) != 0) { - return checkBits (style, SWT.LEFT, SWT.RIGHT, SWT.CENTER, 0, 0, 0); - } - if ((style & SWT.ARROW) != 0) { - 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 sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * <code>widgetSelected</code> is called when the control is selected. - * <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); -} - -void createHandle (int index) { - state |= HANDLE; - int bits = SWT.ARROW | SWT.TOGGLE | SWT.CHECK | SWT.RADIO | SWT.PUSH; - - boxHandle = OS.gtk_event_box_new (); - if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES); - switch (style & bits) { - case SWT.ARROW: - handle = OS.gtk_button_new (); - int arrow = OS.gtk_arrow_new (OS.GTK_ARROW_UP, OS.GTK_SHADOW_OUT); - OS.gtk_container_add (handle, arrow); - OS.gtk_widget_show (arrow); - break; - case SWT.TOGGLE: - handle = OS.gtk_toggle_button_new (); - break; - case SWT.CHECK: - handle = OS.gtk_check_button_new (); - break; - case SWT.RADIO: - handle = OS.gtk_radio_button_new (parent.radioGroup()); - break; - case SWT.PUSH: - default: - handle = OS.gtk_button_new (); - break; - } - if (handle == 0) error (SWT.ERROR_NO_HANDLES); -} - -void setHandleStyle() {} - -void configure() { - _connectParent(); - OS.gtk_container_add (boxHandle, handle); -} - -void showHandle() { - OS.gtk_widget_show (boxHandle); - OS.gtk_widget_show (handle); - OS.gtk_widget_realize (handle); -} - -void hookEvents () { - super.hookEvents(); - /* - * Feature in GTK. For some reason, when the widget - * is a check or radio button, mouse move and key - * release events are not signaled. The fix is to - * look for them on the parent. - */ - if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { - int mask = OS.GDK_POINTER_MOTION_MASK | OS.GDK_KEY_RELEASE_MASK; - OS.gtk_widget_add_events (boxHandle, mask); - signal_connect_after (boxHandle, "motion_notify_event", SWT.MouseMove, 3); - signal_connect_after (boxHandle, "key_release_event", SWT.KeyUp, 3); - } - signal_connect (handle, "clicked", SWT.Selection, 2); -} - -void register () { - super.register (); - WidgetTable.put (boxHandle, this); -} - -void createWidget (int index) { - super.createWidget (index); - text = ""; -} - -int topHandle () { return boxHandle; } - -/** - * 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 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. 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); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is selected. - * - * @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 #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, images and arrows will be displayed - * in the receiver. The argument should be one of - * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code> - * unless the receiver is an <code>ARROW</code> button, in - * which case, the argument indicates the direction of - * the arrow (one of <code>LEFT</code>, <code>RIGHT</code>, - * <code>UP</code> or <code>DOWN</code>. - * - * @param alignment the new alignment - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setAlignment (int alignment) { - checkWidget (); - if ((style & SWT.ARROW) != 0) { - 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; - 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 = OS.GTK_ARROW_LEFT; - break; - case SWT.RIGHT: - arrow_type = OS.GTK_ARROW_RIGHT; - break; - } - int list = OS.gtk_container_children (handle); - int arrow = OS.g_list_nth_data (list, 0); - OS.gtk_arrow_set (arrow, 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); - int list = OS.gtk_container_children (handle); - int label = OS.g_list_nth_data (list, 0); - if (label == 0) return; - boolean isText = OS.GTK_WIDGET_TYPE (handle) == OS.gtk_label_get_type (); - if ((style & SWT.LEFT) != 0) { - OS.gtk_misc_set_alignment (label, 0.0f, 0.5f); - if (isText) OS.gtk_label_set_justify (label, OS.GTK_JUSTIFY_LEFT); - return; - } - if ((style & SWT.CENTER) != 0) { - OS.gtk_misc_set_alignment (label, 0.5f, 0.5f); - if (isText) OS.gtk_label_set_justify (label, OS.GTK_JUSTIFY_CENTER); - return; - } - if ((style & SWT.RIGHT) != 0) { - OS.gtk_misc_set_alignment (label, 1.0f, 0.5f); - if (isText) OS.gtk_label_set_justify (label, OS.GTK_JUSTIFY_RIGHT); - return; - } -} - -/** - * 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 (); - this.image = image; - if ((style & SWT.ARROW) != 0) return; - int list = OS.gtk_container_children (handle); - if (list != 0) { - int widget = OS.g_list_nth_data (list, 0); - if (widget != 0) OS.gtk_widget_destroy (widget); - } - if (image != null) { - int pixmap = OS.gtk_pixmap_new (image.pixmap, image.mask); - OS.gtk_container_add (handle, pixmap); - OS.gtk_widget_show (pixmap); - } -} - -/** - * 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; -} - -/** - * 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. - * - * @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.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_toggle_button_set_active (handle, selected); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * 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> - * - * @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.ARROW) != 0) return; - int length = string.length (); - char [] text = new char [length + 1]; - char [] pattern = new char [length + 1]; - string.getChars (0, length, text, 0); - int i = 0, j = 0; - while (i < length) { - pattern [j] = ' '; - if (text [i] == '&') { - i++; - if (i < length && text [i] != '&') { - pattern [j] = '_'; - } - } - text [j++] = text [i++]; - } - while (j < i) { - text [j] = pattern [j] = '\0'; - j++; - } - int list = OS.gtk_container_children (handle); - if (list != 0) { - int widget = OS.g_list_nth_data (list, 0); - if (widget != 0) OS.gtk_widget_destroy (widget); - } - byte [] buffer1 = Converter.wcsToMbcs (null, text); - int label = OS.gtk_label_new (buffer1); - byte [] buffer2 = Converter.wcsToMbcs (null, pattern); - OS.gtk_label_set_pattern (label, buffer2); - OS.gtk_container_add (handle, label); - OS.gtk_widget_show (label); -} - -int processSelection (int int0, int int1, int int2) { - postEvent(SWT.Selection); - return 0; -} - -void deregister () { - super.deregister (); - WidgetTable.remove (boxHandle); -} - -void releaseWidget () { - super.releaseWidget (); - image = null; - text = null; -} - -void releaseHandle () { - super.releaseHandle (); - boxHandle = 0; -} - -}
\ No newline at end of file diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Canvas.java deleted file mode 100644 index 3374e5cc65..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Canvas.java +++ /dev/null @@ -1,264 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of this class provide a surface for drawing - * arbitrary graphics. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>(none)</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * This class may be subclassed by custom control implementors - * who are building controls that are <em>not</em> constructed - * from aggregates of other controls. That is, they are either - * painted using SWT graphics calls or are handled by native - * methods. - * </p> - * - * @see Composite - */ -public class Canvas extends Composite { - - Caret caret; - -/* - * === CONSTRUCTORS === - */ - - -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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 Canvas (Composite parent, int style) { - super (parent, style); -} - -/** - * 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 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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; -} - -/** - * 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - - if (width <= 0 || height <= 0) return; - int deltaX = destX - x, deltaY = destY - y; - if (deltaX == 0 && deltaY == 0) return; - if (!isVisible ()) return; - - /* Hide the caret */ - boolean isVisible = (caret != null) && (caret.isVisible ()); - if (isVisible) caret.hideCaret (); - - GtkWidget widget = new GtkWidget(); - OS.memmove (widget, paintHandle(), GtkWidget.sizeof); - int window = widget.window; - if (window == 0) return; - - /* Emit a NoExpose Event */ - int gc = OS.gdk_gc_new (window); - OS.gdk_gc_set_exposures(gc, true); - OS.gdk_window_copy_area (window, gc, x, y, window, x, y, width, height); - OS.gdk_gc_destroy (gc); - - /* Flush outstanding Exposes */ - int eventHandle=0; - while ((eventHandle = OS.gdk_event_get_graphics_expose(window)) != 0) { - OS.gtk_widget_event(handle, eventHandle); - OS.gdk_event_free(eventHandle); - } - - /* Scroll the window */ - int gc1 = OS.gdk_gc_new (window); - OS.gdk_gc_set_exposures(gc1, true); - OS.gdk_window_copy_area (window, gc1, destX, destY, window, x, y, width, height); - OS.gdk_gc_destroy (gc1); - boolean disjoint = (destX + width < x) || (x + width < destX) || (destY + height < y) || (y + height < destY); - if (disjoint) { - OS.gdk_window_clear_area(window, x, y, width, height); - } else { - if (deltaX != 0) { - int newX = destX - deltaX; - if (deltaX < 0) newX = destX + width; - OS.gdk_window_clear_area_e(window, newX, y, Math.abs (deltaX), height); - } - if (deltaY != 0) { - int newY = destY - deltaY; - if (deltaY < 0) newY = destY + height; - OS.gdk_window_clear_area_e (window, x, newY, width, Math.abs (deltaY)); - } - } - - /* Show the caret */ - if (isVisible) caret.showCaret (); -} -/** - * 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - Caret newCaret = caret; - Caret oldCaret = this.caret; - this.caret = newCaret; - if (isFocusControl()) { - if (oldCaret != null) oldCaret.killFocus (); - if (newCaret != null) newCaret.setFocus (); - } -} -public boolean setFocus () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if ((style & SWT.NO_FOCUS) != 0) return false; - return super.setFocus (); -} -int processFocusIn (int int0, int int1, int int2) { - int result = super.processFocusIn (int0, int1, int2); - if (caret != null) caret.setFocus (); - return result; -} -int processFocusOut(int int0, int int1, int int2) { - int result = super.processFocusOut (int0, int1, int2); - if (caret != null) caret.killFocus (); - return result; -} -/* -int processMouseDown (int callData, int arg1, int int2) { - if ((UtilFuncs.GTK_WIDGET_GET_FLAGS(handle) & OS.GTK_HAS_FOCUS) == 0) - OS.gtk_widget_grab_focus(handle); - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, callData, GdkEventButton.sizeof); - int eventType = SWT.MouseDown; - if (gdkEvent.type == OS.GDK_2BUTTON_PRESS) eventType = SWT.MouseDoubleClick; - sendMouseEvent (eventType, gdkEvent.button, gdkEvent.state, gdkEvent.time, (int)gdkEvent.x, (int)gdkEvent.y); - if (gdkEvent.button == 3 && menu != null) { - menu.setVisible (true); - } - return 1; -} - -int processMouseUp (int callData, int arg1, int int2) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, callData, GdkEventButton.sizeof); - sendMouseEvent (SWT.MouseUp, gdkEvent.button, gdkEvent.state, gdkEvent.time, (int)gdkEvent.x, (int)gdkEvent.y); - return 1; -} -*/ -int processPaint (int callData, int arg1, int int2) { - //if (!hooks (SWT.Paint)) return 0; - - GdkEventExpose gdkEvent = new GdkEventExpose (); - OS.memmove (gdkEvent, callData, GdkEventExpose.sizeof); - Event event = new Event (); - event.count = gdkEvent.count; - event.x = gdkEvent.x; event.y = gdkEvent.y; - event.width = gdkEvent.width; event.height = gdkEvent.height; - GC gc = event.gc = new GC (this); - sendEvent (SWT.Paint, event); - gc.dispose (); - event.gc = null; - return 0; -} -void releaseWidget () { - if (caret != null) caret.releaseWidget (); - caret = null; - super.releaseWidget (); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Caret.java deleted file mode 100644 index 85c62c27b7..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Caret.java +++ /dev/null @@ -1,508 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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 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> - */ - -public class Caret extends Widget { - Canvas parent; - int x, y, width, height; - boolean moved, resized; - boolean isVisible,isShowing; - int blinkRate = 500; - Image image; - -/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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); -} -void createWidget (int index) { - super.createWidget (index); - isVisible = true; - if (parent.getCaret () == null) { - parent.setCaret (this); - } -} - -boolean blinkCaret () { - if (!isVisible) return true; - if (!isShowing) return showCaret(); - if (blinkRate==0) return true; - return hideCaret(); -} - -boolean drawCaret () { - if (parent == null) return false; - if (parent.isDisposed ()) return false; - - /* The parent is a Canvas; its handle is a GtkDrawingArea. - * Get the DA's GDK window to draw on. - */ - GtkWidget widget = new GtkWidget(); - OS.memmove (widget, parent.handle, GtkWidget.sizeof); - int window = widget.window; - - /* Create the GC, and set the working color and rop. */ - int gc = OS.gdk_gc_new(window); - GdkGCValues gcvalues = new GdkGCValues(); - OS.gdk_gc_get_values(gc, gcvalues); - /* Actually, we should look at the background and foreground colors. - * This would require distinguishing between the cases when the GC - * gives the color as RGB or Pixel, and in the case of Pixel, we - * would need to distinguish between direct and indexed color. - * In general, it's not easy to find out the RGB value of a GdkColor - * (somebody please correct me if I am wrong). - */ - GdkColor c = new GdkColor(); - c.red = c.green = c.blue = (short)0xFFFF; - OS.gdk_color_alloc(OS.gdk_colormap_get_system(), c); - OS.gdk_gc_set_foreground(gc, c); - OS.gdk_gc_set_function(gc, OS.GDK_XOR); - - /* Draw the caret */ - int nWidth = width; - if (nWidth <= 0) nWidth = 2; - OS.gdk_draw_rectangle(window, gc, 1, x, y, nWidth, height); - OS.gdk_gc_destroy(gc); - return true; -} -/** - * Returns a rectangle describing the receiver's size and location - * relative to its parent (or its display if its parent is null). - * - * @return the receiver's bounding rectangle - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Rectangle getBounds () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return new Rectangle (x, y, width, height); -} -public Display getDisplay () { - Composite parent = this.parent; - if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED); - return parent.getDisplay (); -} -/** - * 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return parent.getFont (); -} -/** - * 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return isVisible; -} -boolean hideCaret () { -// Display display = getDisplay (); -// if (display.currentCaret != this) return false; - if (!isShowing) return true; - isShowing = false; - return drawCaret (); -} -/** - * 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 isVisible () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return isVisible && parent.isVisible (); // && parent.hasFocus (); -} -void killFocus () { -// OS.DestroyCaret (); -// self restoreFont. -} -void move () { - showCaret(); - moved = false; -} -void releaseChild () { - super.releaseChild (); - if (this == parent.getCaret ()) parent.setCaret (null); -} -void releaseWidget () { - super.releaseWidget (); - parent = null; -} -void resize () { - int hwnd = parent.handle; - if (hwnd == 0) return; -// OS.DestroyCaret (); -// OS.CreateCaret (hwnd, 0, width, height); -// OS.SetCaretPos (x, y); -// OS.ShowCaret (hwnd); -// self move. -// showCaret(); - resized = false; -} -/** - * Sets the receiver's size and location to the rectangular - * area specified by the arguments. The <code>x</code> and - * <code>y</code> arguments are relative to the receiver's - * parent (or its display if its parent is null). - * - * @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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - boolean samePosition, sameExtent, showing; - samePosition = (this.x == x) && (this.y == y); - sameExtent = (this.width == width) && (this.height == height); - if (samePosition && sameExtent) return; - if (isShowing) hideCaret (); - this.x = x; this.y = y; - this.width = width; this.height = height; - if (sameExtent) { - moved = true; - if (isVisible ()) move (); - } else { - resized = true; - if (isVisible ()) resize (); - } - if(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) { - if (rect == null) error (SWT.ERROR_NULL_ARGUMENT); - setBounds (rect.x, rect.y, rect.width, rect.height); -} -void setFocus () { - Display display = getDisplay(); - 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (font != null && font.isDisposed ()) { - error (SWT.ERROR_INVALID_ARGUMENT); - } -} - -/** - * 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; -} -/** - * 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 font the new font (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); - } - if (isShowing) hideCaret (); - this.image = image; - if (isShowing) 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (this.width == width && this.height == height) return; - this.width = width; this.height = height; - resized = true; - if (isVisible ()) resize (); -} -/** - * Sets the receiver's size to the point specified by the argument. - * - * @param size the new extent for the receiver - * @param height the new height 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (visible == isVisible) return; - if (isVisible = visible) { - showCaret (); - } else { - hideCaret (); - } - -} -boolean showCaret () { -// if (getDisplay ().currentCaret != this) return false; - if (isShowing) return true; - isShowing = true; - return drawCaret (); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ColorDialog.java deleted file mode 100644 index ebe8093461..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ColorDialog.java +++ /dev/null @@ -1,167 +0,0 @@ -package org.eclipse.swt.widgets;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-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> - */
-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 (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 - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public ColorDialog (Shell parent) {
- this (parent, SWT.NULL);
-}
-/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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, style);
- checkSubclass ();
-}
-int cancelFunc (int widget, int callData) {
- OS.gtk_widget_destroy (callData);
- return 0;
-}
-int destroyFunc (int widget, int colorInfo) {
- OS.gtk_main_quit ();
- return 0;
-}
-/** - * 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;
-}
-int okFunc (int widget, int callData) {
- GtkColorSelectionDialog dialog = new GtkColorSelectionDialog ();
- OS.memmove (dialog, callData, GtkColorSelectionDialog.sizeof);
- double [] color = new double [4];
- OS.gtk_color_selection_get_color (dialog.colorsel, color);
- rgb = new RGB ((int)(color [0] * 256), (int)(color [1] * 256), (int)(color [2] * 256));
- OS.gtk_widget_destroy (callData);
- return 0;
-}
-/** - * 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 () {
- int handle;
- byte [] titleBytes;
- titleBytes = Converter.wcsToMbcs (null, title, true);
- handle = OS.gtk_color_selection_dialog_new (titleBytes);
- GtkColorSelectionDialog dialog = new GtkColorSelectionDialog ();
- OS.memmove (dialog, handle, GtkColorSelectionDialog.sizeof);
- OS.gtk_widget_hide (dialog.help_button);
- if (rgb != null) {
- double [] color = new double [4];
- color [0] = (double)rgb.red / 256;
- color [1] = (double)rgb.green / 256;
- color [2] = (double)rgb.blue / 256;
- OS.gtk_color_selection_set_color (dialog.colorsel, color);
- }
- Callback destroyCallback = new Callback (this, "destroyFunc", 2);
- int destroyFunc = destroyCallback.getAddress ();
- byte [] destroy = Converter.wcsToMbcs (null, "destroy", true);
- OS.gtk_signal_connect (handle, destroy, destroyFunc, handle);
- byte [] clicked = Converter.wcsToMbcs (null, "clicked", true);
- Callback okCallback = new Callback (this, "okFunc", 2);
- int okFunc = okCallback.getAddress ();
- Callback cancelCallback = new Callback (this, "cancelFunc", 2);
- int cancelFunc = cancelCallback.getAddress ();
- OS.gtk_signal_connect (dialog.ok_button, clicked, okFunc, handle);
- OS.gtk_signal_connect (dialog.cancel_button, clicked, cancelFunc, handle);
- rgb = null;
- OS.gtk_widget_show_now (handle);
- OS.gtk_main ();
- destroyCallback.dispose ();
- okCallback.dispose ();
- cancelCallback.dispose ();
- return rgb;
-}
-/** - * Returns 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 to 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/gtk1x/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Combo.java deleted file mode 100644 index b192c92336..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Combo.java +++ /dev/null @@ -1,1077 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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</dd> - * </dl> - * <p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see List - */ - -public class Combo extends Composite { - int padHandle, glist; - int textLimit = LIMIT; - 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 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> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li> - * </ul> - * - * @see #add(String,int) - */ -public void add (String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - String [] items = getItems (); - String [] newItems = new String [items.length + 1]; - System.arraycopy (items, 0, newItems, 0, items.length); - newItems [items.length] = string; - setItems (newItems); -} - -/** - * 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> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</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 <= getItemCount ())) { - error (SWT.ERROR_ITEM_NOT_ADDED); - } - String [] items = getItems (); - String [] newItems = new String [items.length + 1]; - System.arraycopy (items, 0, newItems, 0, items.length); - newItems [index] = string; - setItems (newItems); -} - -/** - * 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 receiver's selection changes, by sending - * it one of the messages defined in the <code>SelectionListener</code> - * interface. - * <p> - * <code>widgetSelected</code> is called when the combo's list selection changes. - * <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); -} - -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; -} - -/** - * 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(); - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - int position = OS.gtk_editable_get_position (combo.entry); - OS.gtk_editable_set_position (combo.entry, position); -} - -void createHandle (int index) { - state |= HANDLE; - eventBoxHandle = OS.gtk_event_box_new (); - if (eventBoxHandle == 0) error (SWT.ERROR_NO_HANDLES); - padHandle = OS.gtk_fixed_new (); - if (padHandle == 0) error (SWT.ERROR_NO_HANDLES); - handle = OS.gtk_combo_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - fixedHandle = OS.gtk_fixed_new(); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); -} - -void setHandleStyle() { - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - boolean isEditable = (style & SWT.READ_ONLY) == 0; - OS.gtk_entry_set_editable (combo.entry, isEditable); -} - -void configure () { - _connectParent(); - OS.gtk_container_add(eventBoxHandle, padHandle); - OS.gtk_fixed_put (padHandle, fixedHandle, (short)0, (short)0); - OS.gtk_fixed_put (padHandle, handle, (short)0, (short)0); -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - return _computeSize(wHint, hHint, changed); -} - -void showHandle() { - OS.gtk_widget_show(eventBoxHandle); - OS.gtk_widget_show(padHandle); - OS.gtk_widget_show(fixedHandle); - OS.gtk_widget_show(handle); - OS.gtk_widget_realize (handle); -} - -void deregister () { - super.deregister (); - WidgetTable.remove (padHandle); - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - WidgetTable.remove (combo.entry); - WidgetTable.remove (combo.list); - WidgetTable.remove (combo.button); -} - -void hookEvents () { - // TO DO - expose, enter/exit, focus in/out - super.hookEvents (); - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - // TO DO - fix multiple selection events for one user action - signal_connect (combo.list, "select_child", SWT.Selection, 3); - signal_connect_after (combo.entry, "changed", SWT.Modify, 2); - int mask = - OS.GDK_POINTER_MOTION_MASK | - OS.GDK_BUTTON_PRESS_MASK | OS.GDK_BUTTON_RELEASE_MASK | - OS.GDK_KEY_PRESS_MASK | OS.GDK_KEY_RELEASE_MASK; - int [] handles = new int [] {combo.entry, combo.list, combo.button}; - for (int i=0; i<handles.length; i++) { - int handle = handles [i]; - if (!OS.GTK_WIDGET_NO_WINDOW (handle)) { - OS.gtk_widget_add_events (handle, mask); - } - signal_connect_after (handle, "motion_notify_event", SWT.MouseMove, 3); - signal_connect_after (handle, "button_press_event", SWT.MouseDown, 3); - signal_connect_after (handle, "button_release_event", SWT.MouseUp, 3); - signal_connect_after (handle, "key_press_event", SWT.KeyDown, 3); - signal_connect_after (handle, "key_release_event", SWT.KeyUp, 3); - } -} - -int topHandle() { return eventBoxHandle; } -int parentingHandle() { return fixedHandle; } -boolean isMyHandle(int h) { - if (h==eventBoxHandle) return true; - if (h==padHandle) return true; - if (h==fixedHandle) return true; - if (h==handle) return true; - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - if (h== combo.entry) return true; - if (h== combo.list) return true; - if (h== combo.button) return true; - return false; -} - -void _connectChild (int h) { - OS.gtk_fixed_put (fixedHandle, h, (short)0, (short)0); -} - -Point _getClientAreaSize () { - return UtilFuncs.getSize(fixedHandle); -} - -boolean _setSize(int width, int height) { - boolean differentExtent = UtilFuncs.setSize(eventBoxHandle, width,height); - UtilFuncs.setSize (fixedHandle, width,height); - UtilFuncs.setSize (handle, width,height); - return differentExtent; -} - -/** - * 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(); - setItems (getItems ()); -} - -/** - * 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(); - setItems (getItems ()); -} - -/* - * FIXME -protected boolean hasFocus () { - return super.hasFocus(); -} -*/ - -/** - * 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> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li> - * </ul> - */ -public String getItem (int index) { - checkWidget(); - String [] items = getItems (); - if (!(0 <= index && index < items.length)) { - error (SWT.ERROR_CANNOT_GET_ITEM); - } - 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> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li> - * </ul> - */ -public int getItemCount () { - checkWidget(); - if (glist == 0) return 0; - return OS.g_list_length (glist); -} - -/** - * 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> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</li> - * </ul> - */ -public int getItemHeight () { - checkWidget(); - /* FIXME */ - return 0; -} - -/** - * Returns an 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> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li> - * </ul> - */ -public String [] getItems () { - checkWidget(); - if (glist == 0) return new String [0]; - int count = OS.g_list_length (glist); - String [] items = new String [count]; - for (int i=0; i<count; i++) { - int data = OS.g_list_nth_data (glist, i); - int length = OS.strlen (data); - byte [] buffer1 = new byte [length]; - OS.memmove (buffer1, data, length); - char [] buffer2 = Converter.mbcsToWcs (null, buffer1); - items [i] = new String (buffer2, 0, length); - } - return items; -} - -/** - * Returns a <code>Point</code> whose x coordinate is the start - * of the selection in the receiver's text field, and whose y - * coordinate is the end of the selection. The returned values - * are zero-relative. An "empty" selection as indicated by - * the the x and y coordinates having the same value. - * - * @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 (); - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - GtkEditable editable = new GtkEditable(); - OS.memmove (editable, combo.entry, GtkEditable.sizeof); - return new Point (editable.selection_start_pos, editable.selection_end_pos); -} - -/** - * 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(); - //NOT RIGHT FOR EDITABLE - return indexOf (getText ()); -} - -/** - * Returns a string containing a copy of the contents of the - * receiver's text field. - * - * @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(); - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - int address = OS.gtk_entry_get_text (combo.entry); - int length = OS.strlen (address); - byte [] buffer1 = new byte [length]; - OS.memmove (buffer1, address, length); - /* - * This code is intentionally commented. - * The GTK documentation explicitly states - * that this address should not be freed. - */ -// OS.g_free (address); - char [] buffer2 = Converter.mbcsToWcs (null, buffer1); - return new String (buffer2, 0, buffer2.length); -} - -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> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</li> - * </ul> - */ -public int getTextHeight () { - checkWidget(); - /* A native approach, just measuring the entry: - * return UtilFuncs.getSize(_entryHandle).y; - * does not work - the entry is the same size as - * the whole combo. - */ - error (SWT.ERROR_CANNOT_GET_ITEM_HEIGHT); - return 0; -} - -/** - * 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> - */ -public int getTextLimit () { - checkWidget(); - return textLimit; -} - -/** - * 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 - * @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 (string.equals(items [i])) return i; - } - return -1; -} - -int processModify (int arg0, int arg1, int int2) { - sendEvent (SWT.Modify); - return 0; -} - -int processSelection (int int0, int int1, int int2) { - postEvent (SWT.Selection); - return 0; -} - -void register () { - super.register (); - WidgetTable.put (padHandle, this); - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - WidgetTable.put (combo.entry, this); - WidgetTable.put (combo.list, this); - WidgetTable.put (combo.button, this); -} - -void releaseHandle () { - super.releaseHandle (); - int padHandle = 0; -} - -void releaseWidget () { - if (glist != 0) { - int count = OS.g_list_length (glist); - for (int i=0; i<count; i++) { - int data = OS.g_list_nth_data (glist, i); - if (data != 0) OS.g_free (data); - } - OS.g_list_free (glist); - } - glist = 0; - super.releaseWidget (); -} - -/** - * 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> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void remove (int index) { - checkWidget(); - if (!(0 <= index && index < getItemCount ())) { - error (SWT.ERROR_ITEM_NOT_REMOVED); - } - String [] oldItems = getItems (); - 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); - setItems (newItems); -} - -/** - * 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> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void remove (int start, int end) { - checkWidget(); - if (!(0 <= start && start <= end && end < getItemCount ())) { - error (SWT.ERROR_ITEM_NOT_REMOVED); - } - String [] oldItems = getItems (); - 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); - setItems (newItems); -} - -/** - * 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> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void remove (String string) { - checkWidget(); - int index = indexOf (string, 0); - if (index != -1) remove (index); -} - -/** - * Removes all of the items from the receiver's list. - * <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(); - setItems (new String [0]); -} - -/** - * 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 receiver's selection changes. - * - * @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(); - String [] items = getItems (); - if (index >= items.length) return; - String selectedText = items [index]; - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - OS.gtk_signal_handler_block_by_data (combo.entry, SWT.Modify); - OS.gtk_signal_handler_block_by_data (combo.list, SWT.Selection); - OS.gtk_list_select_item (combo.list, index); - OS.gtk_entry_set_text (combo.entry, Converter.wcsToMbcs (null, selectedText, true)); - OS.gtk_signal_handler_unblock_by_data (combo.entry, SWT.Modify); - OS.gtk_signal_handler_unblock_by_data (combo.list, SWT.Selection); -} - -/** - * Sets the text of the item in the receiver's list at the given - * zero-relative index to the string argument. This is equivalent - * to <code>remove</code>'ing the old item at the index, and then - * <code>add</code>'ing the new item at that index. - * - * @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> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the remove operation fails because of an operating system failure</li> - * <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</li> - * </ul> - */ -public void setItem (int index, String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if (!(0 <= index && index <= getItemCount ())) { - error (SWT.ERROR_INVALID_ARGUMENT); - } - String [] items = getItems (); - items [index] = string; - setItems (items); -} - -/** - * Sets the receiver's list to be the given array of items. - * - * @param items the array 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> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void setItems (String [] items) { - checkWidget(); - if (items == null) error (SWT.ERROR_NULL_ARGUMENT); - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - if (items.length == 0) { - OS.gtk_list_clear_items (combo.list, 0, -1); - //LEAK - glist = 0; - } else { - int new_glist = 0; - for (int i=0; i<items.length; i++) { - String string = items [i]; - // FIXME leaked strings and glist - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - byte [] buffer = Converter.wcsToMbcs (null, string, true); - int data = OS.g_malloc (buffer.length); - OS.memmove (data, buffer, buffer.length); - new_glist = OS.g_list_append (new_glist, data); - } - OS.gtk_signal_handler_block_by_data (combo.entry, SWT.Modify); - OS.gtk_signal_handler_block_by_data (combo.list, SWT.Selection); - OS.gtk_combo_set_popdown_strings (handle, new_glist); - OS.gtk_signal_handler_unblock_by_data (combo.entry, SWT.Modify); - OS.gtk_signal_handler_unblock_by_data (combo.list, SWT.Selection); - if (glist != 0) { - int count = OS.g_list_length (glist); - for (int i=0; i<count; i++) { - int data = OS.g_list_nth_data (glist, i); - if (data != 0) OS.g_free (data); - } - OS.g_list_free (glist); - } - glist = new_glist; - } - OS.gtk_signal_handler_block_by_data (combo.entry, SWT.Modify); - OS.gtk_editable_delete_text (combo.entry, 0, -1); - OS.gtk_signal_handler_unblock_by_data (combo.entry, SWT.Modify); -} - -/** - * 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 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); - GtkCombo gtkCombo = new GtkCombo (); - OS.memmove (gtkCombo, handle, GtkCombo.sizeof); - int entry = gtkCombo.entry; - OS.gtk_editable_set_position (entry, selection.x); - OS.gtk_editable_select_region (entry, selection.x, selection.y); -} - -protected boolean setTabGroupFocus () { - return setFocus (); -} - -/** - * Sets the contents of the receiver's text field to the - * given string. - * <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 text 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 (string == null) error (SWT.ERROR_NULL_ARGUMENT); - GtkCombo gtkCombo = new GtkCombo (); - OS.memmove (gtkCombo, handle, GtkCombo.sizeof); - int entry = gtkCombo.entry; - OS.gtk_editable_delete_text (entry, 0, -1); - int [] position = new int [1]; - byte [] buffer = Converter.wcsToMbcs (null, string); - OS.gtk_editable_insert_text (entry, buffer, buffer.length, position); - OS.gtk_editable_set_position (entry, 0); -} - -/** - * Sets the maximum number of characters that the receiver's - * text field is capable of holding to be the argument. - * - * @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> - */ -public void setTextLimit (int limit) { - checkWidget(); - if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO); - this.textLimit = (short) limit; - GtkCombo combo = new GtkCombo (); - OS.memmove (combo, handle, GtkCombo.sizeof); - OS.gtk_entry_set_max_length (combo.entry, (short) limit); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Composite.java deleted file mode 100644 index 7c1b9d83d7..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Composite.java +++ /dev/null @@ -1,504 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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 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</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 constructed from aggregates - * of other controls. - * </p> - * - * @see Canvas - */ -public class Composite extends Scrollable { - int topHandle, eventBoxHandle, fixedHandle, radioHandle; - Layout layout; - -/* - * === CONSTRUCTORS === - */ - -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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 - * @see Widget#checkSubclass - * @see Widget#getStyle - */ -public Composite (Composite parent, int style) { - super (parent, style); -} - -void createHandle (int index) { - state |= HANDLE | CANVAS; - - topHandle = OS.gtk_event_box_new(); - if (topHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - - scrolledHandle = OS.gtk_scrolled_window_new(0,0); - if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES); - - eventBoxHandle = OS.gtk_event_box_new(); - if (eventBoxHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - - fixedHandle = OS.gtk_fixed_new (); - if (fixedHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - - handle = OS.gtk_drawing_area_new(); - if (handle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - OS.GTK_WIDGET_SET_FLAGS(handle, OS.GTK_CAN_FOCUS); -} - -void configure() { - _connectParent(); - OS.gtk_container_add(topHandle, scrolledHandle); - _fillBin(scrolledHandle, eventBoxHandle); - OS.gtk_container_add(eventBoxHandle, fixedHandle); - OS.gtk_fixed_put(fixedHandle, handle, (short)0,(short)0); -} - -void setHandleStyle() { - setScrollingPolicy(); -} - -void showHandle() { - OS.gtk_widget_realize (topHandle); - OS.gtk_widget_show_now(topHandle); - - OS.gtk_widget_show (scrolledHandle); - - OS.gtk_widget_realize (eventBoxHandle); - OS.gtk_widget_show_now(eventBoxHandle); - - OS.gtk_widget_realize (fixedHandle); - OS.gtk_widget_show_now(fixedHandle); - - OS.gtk_widget_realize (handle); - OS.gtk_widget_show_now (handle); -} - -void register () { - super.register (); - if (topHandle != 0) WidgetTable.put (topHandle, this); - if (eventBoxHandle != 0) WidgetTable.put (eventBoxHandle, this); - if (fixedHandle != 0) WidgetTable.put (fixedHandle, this); -} - -void deregister () { - super.deregister (); - if (topHandle != 0) WidgetTable.remove (topHandle); - if (eventBoxHandle != 0) WidgetTable.remove (eventBoxHandle); - if (fixedHandle != 0) WidgetTable.remove (fixedHandle); -} - -int topHandle() { - return topHandle; -} - -int parentingHandle() { - return fixedHandle; -} - -/** - * Answer whether the argument points to an OS widget that is - * implementing the receiver, i.e., one of my own handles - */ -boolean isMyHandle(int h) { - if (h==topHandle) return true; - if (h==eventBoxHandle) return true; - if (h==scrolledHandle) return true; - if (h==fixedHandle) return true; - if (h==handle) return true; - if (h==radioHandle) return true; - return false; -} - - - - -/* - * === GEOMETRY - PHYSICAL === - */ - - -public void setBounds (int x, int y, int width, int height) { - super.setBounds (x, y, width, height); - layout(); -} - -public void setSize (int width, int height) { - super.setSize(width, height); - layout(); -} - -boolean _setSize(int width, int height) { - boolean differentExtent = UtilFuncs.setSize (topHandle(), width,height); - Point clientSize = UtilFuncs.getSize(fixedHandle); - OS.gtk_drawing_area_size(handle, width, height); - UtilFuncs.setSize (handle, clientSize.x, clientSize.y); - return differentExtent; -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - Point size; - if (layout != null) { - if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) { - size = layout.computeSize (this, wHint, hHint, changed); - } else { - size = new Point (wHint, hHint); - } - } else { - size = minimumSize (); - } - 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); -} - -void initializeTrim() { - /* Temporary implementation - I just measured the scrollbars - * with one particular theme. The fair thing to do is get - * the real dimensions from gtk. - */ - trim = new Trim(); - if ((style&SWT.H_SCROLL)!=0) trim.bottom=18; - if ((style&SWT.V_SCROLL)!=0) trim.right=18; -} - - -/* - * === GEOMETRY - LAYOUT === - */ - -/** - * 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; -} - -/** - * Gets the last specified 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 () { - return new Control [0]; -} - -/** - * 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - this.layout = layout; -} - -int _gdkWindow() { - int windowHandle = _gdkWindow(handle); - if (windowHandle==0) error(SWT.ERROR_UNSPECIFIED); - return windowHandle; -} - -/** - * Returns an array containing the receiver's children. - * <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 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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(); -} - -Control [] _getChildren () { - return _getChildren(parentingHandle()); -} - -/** - * Answer the array of the children of the specified handle, - * filtering out widgets we don't consider our children. - * That is, the OS may return some children that don't qualify - * as such under SWT terminology - e.g., Items are not children. - */ -Control [] _getChildren (int h) { - if (h==0) { - error(SWT.ERROR_UNSPECIFIED); - } - int list = OS.gtk_container_children (h); - int count = OS.g_list_length (list); - java.util.Vector children = new java.util.Vector(); - for (int i=0; i<count; i++) { - int data = OS.g_list_nth_data (list, i); - if (!isMyHandle(data)) { - Control child = _childFromHandle(data); - if (child != null) children.addElement(child); - } - } - Control[] answer = new Control[children.size()]; - children.copyInto(answer); - return answer; -} -/** - * Consider the argument a handle of one of the receiver's children. - * If the argument is not a handle to a widget, or the widget is - * not our child in SWT (not OS) terminology, return null. - */ -Control _childFromHandle(int h) { - Widget child = WidgetTable.get(h); - return (Control)child; -} - -public Rectangle getClientArea () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - - return _getClientArea (); -} - -public Rectangle _getClientArea () { - Point size = _getClientAreaSize (); - return new Rectangle (0, 0, size.x, size.y); -} - -Point _getClientAreaSize () { - return UtilFuncs.getSize(handle); -} - - -/** - * 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> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the 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 () { - 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 the argument is <code>true</code> the layout must not rely - * on any cached information it is keeping about the children. If it - * is <code>false</code> the layout may (potentially) simplify the - * work it is doing by assuming that the state of the none of the - * receiver's children has changed since the last layout. - * If the receiver does not have a layout, do nothing. - * - * @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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (layout == null) return; - layout.layout (this, changed); -} - -Point minimumSize () { - 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 processResize (int int0, int int1, int int2) { - sendEvent (SWT.Resize); - layout(); - return 0; -} -int radioGroup() { - if (radioHandle==0) _initializeRadioGroup(); - return OS.gtk_radio_button_group(radioHandle); -} - -public void redraw () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); -// Point size = _getSize(); -// GtkWidget widget = new GtkWidget(handle); -// _redraw(0, 0, size.x, size.y, true); -OS.gtk_widget_queue_draw(handle); -} - -void _initializeRadioGroup() { - radioHandle = OS.gtk_radio_button_new(0); -} - -/** - * Adopt the widget h as our child. - */ -void _connectChild (int h) { - OS.gtk_fixed_put (parentingHandle(), h, (short)0, (short)0); -} - -void releaseChildren () { - Control [] children = _getChildren (); - for (int i=0; i<children.length; i++) { - Control child = children [i]; - if (child != null && !child.isDisposed ()) { - child.releaseWidget (); - child.releaseHandle (); - } - } -} -void releaseWidget () { - releaseChildren (); - super.releaseWidget (); - layout = null; -} -void releaseHandle () { - super.releaseHandle (); - topHandle = eventBoxHandle = fixedHandle = radioHandle = 0; -} - -int processMouseDown (int callData, int arg1, int int2) { - //NOT DONE - only grab when not already grabbing - if ((state & CANVAS) != 0) OS.gtk_grab_add (handle); - return super.processMouseDown (callData, arg1, int2); -} - -int processMouseUp (int callData, int arg1, int int2) { - //NOT DONE - only release when last button goes up - if ((state & CANVAS) != 0) OS.gtk_grab_remove (handle); - return super.processMouseUp (callData, arg1, int2); -} - -int processFocusIn(int int0, int int1, int int2) { - OS.GTK_WIDGET_SET_FLAGS(handle, OS.GTK_HAS_FOCUS); - return super.processFocusIn(int0, int1, int2); -} -int processFocusOut(int int0, int int1, int int2) { - OS.GTK_WIDGET_UNSET_FLAGS(handle, OS.GTK_HAS_FOCUS); - return super.processFocusOut(int0, int1, int2); -} - -public boolean setFocus () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 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; must not be null - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the tabList is null</li> - * <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) { -} - -protected void checkSubclass () { - /* Do nothing - Subclassing is allowed */ -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Control.java deleted file mode 100644 index eedad44c27..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Control.java +++ /dev/null @@ -1,2229 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.internal.Converter; -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.events.*; - -/** - * Control is the abstract superclass of all windowed user interface classes. - * <p> - * <dl> - * <dt><b>Styles:</b> - * <dd>BORDER</dd> - * <dt><b>Events:</b> - * <dd>FocusIn, FocusOut, Help, KeyDown, KeyUp, MouseDoubleClick, MouseDown, MouseEnter, - * MouseExit, MouseHover, MouseUp, MouseMove, Move, Paint, Resize</dd> - * </dl> - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - */ -public abstract class Control extends Widget implements Drawable { - - Composite parent; - Menu menu; - String toolTipText; - Object layoutData; - -/* - * === CONSTRUCTORS === - */ - -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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 Control (Composite parent, int style) { - super (parent, style); - this.parent = parent; - createWidget (0); -} - -abstract void createHandle(int index); - -int eventHandle () { - return handle; -} - -/** - * Connect the appropriate signal handlers. - * - * At a minimum, we must connect - * <ul> - * <li>expose_event - * <li>button_press_event / button_release_event - * <li>motion_notify_event - * <li>enter_notify_event / leave_notify_event - * <li>key_press_event / key_release_event - * <li>focus_in_event / focus_out_event - * </ul> - * - * The possible mask bits are: - * <ul> - * GDK_EXPOSURE_MASK | - * GDK_POINTER_MOTION_MASK | - * GDK_POINTER_MOTION_HINT_MASK | - * GDK_ENTER_NOTIFY_MASK | - * GDK_LEAVE_NOTIFY_MASK | - * GDK_BUTTON_PRESS_MASK - * GDK_BUTTON_RELEASE_MASK - * GDK_KEY_PRESS_MASK - * GDK_KEY_RELEASE_MASK - * GDK_FOCUS_CHANGE_MASK - * </ul> - */ -void hookEvents () { - signal_connect (handle, "expose_event", SWT.Paint, 3); - int 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; - int eventHandle = eventHandle (); - if (!OS.GTK_WIDGET_NO_WINDOW (eventHandle)) { - OS.gtk_widget_add_events (eventHandle, mask); - } - signal_connect_after (eventHandle, "motion_notify_event", SWT.MouseMove, 3); - signal_connect_after (eventHandle, "button_press_event", SWT.MouseDown, 3); - signal_connect_after (eventHandle, "button_release_event", SWT.MouseUp, 3); - signal_connect_after (eventHandle, "enter_notify_event", SWT.MouseEnter, 3); - signal_connect_after (eventHandle, "leave_notify_event", SWT.MouseExit, 3); - signal_connect_after (eventHandle, "key_press_event", SWT.KeyDown, 3); - signal_connect_after (eventHandle, "key_release_event", SWT.KeyUp, 3); - signal_connect_after (eventHandle, "focus_in_event", SWT.FocusIn, 3); - signal_connect_after (eventHandle, "focus_out_event", SWT.FocusOut, 3); -} - -abstract void setHandleStyle (); -void setInitialSize() { UtilFuncs.setZeroSize(topHandle()); } -void configure () { - // Do NOT directly use gtk_fixed_put in configure(), - // because not all composites have GtkFixed as their - // parenting (bottom) handle. - _connectParent(); -} -void _connectParent() { - parent._connectChild(topHandle()); -} -/** - * Every Control must implement this to map the gtk widgets, - * and also realize those that have to be realized - this means - * create the actual X window so that there are no surprizes - * if the user calls a method expecting the X window to be there. - * Widgets normally do it by invoking gtk_widget_show() on all - * handles, and then doing gtk_widget_realize() on bottommost - * handle, which will realize everything above as well. - * An exception to this is the Shell, which we do NOT realize - * at this point. - */ -abstract void showHandle(); - -int topHandle() { - return handle; -} - -int paintHandle() { - return handle; -} - -/* - * === GEOMETRY === - */ - -int computeHandle () { - return handle; -} - -Point _computeSize (int wHint, int hHint, boolean changed) { - int handle = computeHandle (); - byte [] gtk_aux_info = Converter.wcsToMbcs (null, "gtk-aux-info", true); - int id = OS.g_quark_from_string (gtk_aux_info); - int aux_info = OS.gtk_object_get_data_by_id (handle, id); - OS.gtk_object_set_data_by_id (handle, id, 0); - GtkRequisition requisition = new GtkRequisition (); - OS.gtk_widget_size_request (handle, requisition); - OS.gtk_object_set_data_by_id (handle, id, aux_info); - int width = wHint == SWT.DEFAULT ? requisition.width : wHint; - int height = hHint == SWT.DEFAULT ? requisition.height : hHint; - return new Point (width, height); -} - -/** - * Returns the preferred size of the receiver. - * <p> - * The <em>prefered 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 - */ -public Point computeSize (int wHint, int hHint) { - return computeSize (wHint, hHint, true); -} - -/** - * Returns the preferred size of the receiver. - * <p> - * The <em>prefered 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 - */ -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget(); - return _computeSize (wHint, hHint, changed); -} - -/** - * 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(); - return _getBounds(); -} - -/** - * The actual implementation for getBounds(). - * Concrete controls implement their means to answer the location - * and size by overriding _getLocation() and _getSize(). - */ -final Rectangle _getBounds() { - Point location = _getLocation(); - Point size = _getSize(); - return new Rectangle(location.x, location.y, size.x, size.y); -} - -/** - * 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) { - if (rect == null) error (SWT.ERROR_NULL_ARGUMENT); - setBounds (rect.x, rect.y, rect.width, rect.height); -} - -/** - * 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). - * <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(); - boolean differentOrigin = _setLocation(x,y); - boolean differentExtent = _setSize (width,height); - if (differentOrigin) sendEvent (SWT.Move); - if (differentExtent) sendEvent (SWT.Resize); -} - -/** - * 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 _getLocation(); -} - -Point _getLocation () { - return UtilFuncs.getLocation(topHandle()); -} - -/** - * 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) { - if (location == null) error (SWT.ERROR_NULL_ARGUMENT); - setLocation (location.x, location.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). - * - * @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 (_setLocation(x,y)) sendEvent(SWT.Move); -} - -boolean _setLocation(int x, int y) { - return UtilFuncs.setLocation(parent.parentingHandle(), topHandle(), x,y); -} - -/** - * 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(); - return _getSize(); -} -Point _getSize() { - return UtilFuncs.getSize(topHandle()); -} - -/** - * 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 - * @param height the new height 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) { - if (size == null) error (SWT.ERROR_NULL_ARGUMENT); - setSize (size.x, size.y); -} - -/** - * 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(); - // Even though GTK+ will not let any widget be smaller - // than 3@3, we don't care about it here, as this kind - // of platform weirdness is handled in UtilFuncs. - width = Math.max(width, 0); - height = Math.max(height, 0); - if (_setSize(width, height)) sendEvent(SWT.Resize); -} -boolean _setSize(int width, int height) { return UtilFuncs.setSize(topHandle(), width, height); } - -/** - * 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 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> - */ -public void moveAbove (Control control) { - checkWidget(); - GtkWidget widget = new GtkWidget(); - OS.memmove (widget, topHandle(), GtkWidget.sizeof); - int topGdkWindow = widget.window; - if (topGdkWindow!=0) OS.gdk_window_raise (topGdkWindow); -} - -/** - * 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 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> - */ -public void moveBelow (Control control) { - checkWidget(); - GtkWidget widget = new GtkWidget(); - OS.memmove (widget, topHandle(), GtkWidget.sizeof); - int topGdkWindow = widget.window; - if (topGdkWindow!=0) OS.gdk_window_lower (topGdkWindow); -} - -/** - * 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 - */ -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> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 - */ -public void pack (boolean changed) { - checkWidget(); - 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 point the point to be translated (must not be null) - * - * @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(); - int[] x = new int[1], y = new int[1]; - OS.gdk_window_get_origin(_gdkWindow(), x,y); - int ctlX = point.x - x[0]; - int ctlY = point.y - y[0]; - return new Point (ctlX, ctlY); -} -/** - * 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) - * - * @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(); - int[] x = new int[1], y = new int[1]; - OS.gdk_window_get_origin(_gdkWindow(), x,y); - return new Point (x[0]+point.x, y[0]+point.y); -} -// === End of GEOMETRY Category === - - -/* - * == ADD/REMOVE LISTENERS == - */ - -/** - * 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 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 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 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); -} - -/** - * 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 receiver needs to be painted, by sending it - * one of the messages defined in the <code>PaintListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see PaintListener - * @see #removePaintListener - */ -public void addPaintListener(PaintListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener(SWT.Paint,typedListener); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when traversal events occur, by sending it - * one of the messages defined in the <code>TraverseListener</code> - * interface. - * - * @param listener the listener which should be notified - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see TraverseListener - * @see #removeTraverseListener - */ -public void addTraverseListener (TraverseListener listener) { - checkWidget(); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Traverse,typedListener); -} - -/** - * 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 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 gains or loses focus. - * - * @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 #addFocusListener - */ -public void removeFocusListener(FocusListener listener) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 mouse buttons are pressed and released. - * - * @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 #addMouseListener - */ -public void removeMouseListener (MouseListener listener) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 receiver needs to be painted. - * - * @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 #addPaintListener - */ -public void removePaintListener(PaintListener listener) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook(SWT.Paint, listener); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when traversal events occur. - * - * @param listener the listener which should 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); -} - - -/* - * Return (GTKWIDGET)h->window. - */ -final int _gdkWindow(int h) { - /* Temporary code. - * This check is not necessary as the (internal) callers - * always make sure h!=0. - */ - if (h==0) error(SWT.ERROR_CANNOT_BE_ZERO); - - GtkWidget widget = new GtkWidget(); - OS.memmove (widget, h, GtkWidget.sizeof); - return widget.window; -} - -int _gdkWindow() { - int windowHandle = _gdkWindow(handle); - if (windowHandle==0) error(SWT.ERROR_NO_HANDLES); - return windowHandle; -} - -/** - * 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - OS.gtk_widget_grab_focus (handle); - return true; -} - -/** - * 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> - */ -public Color getBackground () { - checkWidget(); - return Color.gtk_new (_getBackgroundGdkColor()); -} - -/* - * Subclasses should override this to pass a meaningful handle - */ -GdkColor _getBackgroundGdkColor() { - /* Override this */ - int h = paintHandle(); - - int hStyle = OS.gtk_widget_get_style (handle); - GtkStyle style = new GtkStyle (); - OS.memmove (style, hStyle, GtkStyle.sizeof); - GdkColor color = new GdkColor (); - color.pixel = style.bg0_pixel; - color.red = style.bg0_red; - color.green = style.bg0_green; - color.blue = style.bg0_blue; - 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return (style & SWT.BORDER) == 0 ? 0 : 1; -} - -/** - * Returns the display that the receiver was created on. - * - * @return the receiver's 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 Display getDisplay () { - if (parent == null) { - error (SWT.ERROR_WIDGET_DISPOSED); - } - return parent.getDisplay (); -} -/** - * 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> - */ -public boolean getEnabled () { - checkWidget (); - int topHandle = topHandle (); - return OS.GTK_WIDGET_SENSITIVE (topHandle); -} - -/** - * 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.gtk_new(_getFontHandle()); -} -/* - * Subclasses should override this, passing a meaningful handle - */ -int _getFontHandle () { - return UtilFuncs.getFont(handle); -} - -/** - * 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 (_getForegroundGdkColor()); -} - -/* - * Subclasses should override this to pass a meaningful handle - */ -GdkColor _getForegroundGdkColor() { - /* Override this */ - int h = paintHandle(); - - int hStyle = OS.gtk_widget_get_style (handle); - GtkStyle style = new GtkStyle (); - OS.memmove (style, hStyle, GtkStyle.sizeof); - GdkColor color = new GdkColor (); - color.pixel = style.fg0_pixel; - color.red = style.fg0_red; - color.green = style.fg0_green; - color.blue = style.fg0_blue; - 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return menu; -} -/** - * 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return parent; -} - -/** - * 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() { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 _getVisible(); -} -boolean _getVisible() { - return _getVisible(topHandle()); -} -boolean _getVisible(int h) { - return (OS.GTK_WIDGET_FLAGS(h) & OS.GTK_VISIBLE) != 0; -} - -/** - * Invokes platform specific functionality to allocate a new GC handle. - * <p> - * <b>IMPORTANT:</b> This method is <em>not</em> part of the public - * API for <code>Control</code>. It is marked public only so that it - * can be shared within the packages provided by SWT. It is not - * available on all platforms, and should never be called from - * application code. - * </p> - * - * @param data the platform specific GC data - * @return the platform specific GC handle - * - * @private - */ -public int internal_new_GC (GCData data) { - if (data == null) error (SWT.ERROR_NULL_ARGUMENT); - if (paintHandle() == 0) error(SWT.ERROR_UNSPECIFIED); - - // Create the GC with default values for this control - GtkWidget w = new GtkWidget(); - OS.memmove (w, paintHandle(), GtkWidget.sizeof); - - if (w.window == 0) error(SWT.ERROR_UNSPECIFIED); - int gc = OS.gdk_gc_new(w.window); - - OS.gdk_gc_set_font(gc, _getFontHandle()); - OS.gdk_gc_set_background(gc, _getBackgroundGdkColor()); - OS.gdk_gc_set_foreground(gc, _getForegroundGdkColor()); - - data.drawable = w.window; - return gc; -} - -/** - * 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 handle the platform specific GC handle - * @param data the platform specific GC data - * - * @private - */ -public void internal_dispose_GC (int xGC, GCData data) { - if(xGC == 0) error(SWT.ERROR_NO_HANDLES); - OS.gdk_gc_unref(xGC); -} - -/** - * Returns <code>true</code> if the underlying operating - * system supports this reparenting, otherwise <code>false</code> - * - * @return <code>true</code> if the widget can be reparented, otherwise <code>false</code> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public boolean isReparentable () { - checkWidget(); - return false; -} - -/** - * 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> - */ -public boolean isEnabled () { - checkWidget (); - int topHandle = topHandle (); - return OS.GTK_WIDGET_IS_SENSITIVE (topHandle); -} - -/** - * 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return (OS.GTK_WIDGET_FLAGS(handle)&OS.GTK_HAS_FOCUS)!=0; -} -/** - * 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 isVisible () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - boolean result = getVisible (); - if (parent != null) - result = result && parent.isVisible(); - return result; -} -Decorations menuShell () { - return parent.menuShell (); -} - -int processKeyDown (int callData, int arg1, int int2) { - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, callData, GdkEventKey.sizeof); - boolean accelResult = OS.gtk_accel_groups_activate(_getShell().topHandle, gdkEvent.keyval, gdkEvent.state); - if (!accelResult) sendKeyEvent (SWT.KeyDown, gdkEvent); - return 1; -} - -int processKeyUp (int callData, int arg1, int int2) { - GdkEventKey gdkEvent = new GdkEventKey (); - OS.memmove (gdkEvent, callData, GdkEventKey.sizeof); - sendKeyEvent (SWT.KeyUp, gdkEvent); - return 1; -} - -int processMouseDown (int callData, int arg1, int int2) { - OS.gtk_widget_grab_focus(handle); - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, callData, GdkEventButton.sizeof); - int eventType = SWT.MouseDown; - if (gdkEvent.type == OS.GDK_2BUTTON_PRESS) eventType = SWT.MouseDoubleClick; - sendMouseEvent (eventType, gdkEvent.button, gdkEvent.state, gdkEvent.time, (int)gdkEvent.x, (int)gdkEvent.y); - if (gdkEvent.button == 3 && menu != null) { - menu.setVisible (true); - } - return 1; -} - -int processMouseEnter (int arg0, int arg1, int int2) { - //NOT IMPLEMENTED - event state - sendEvent (SWT.MouseEnter); - return 1; -} -int processMouseExit (int arg0, int arg1, int int2) { - //NOT IMPLEMENTED - event state - sendEvent (SWT.MouseExit); - return 1; -} - -int processMouseUp (int callData, int arg1, int int2) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, callData, GdkEventButton.sizeof); - sendMouseEvent (SWT.MouseUp, gdkEvent.button, gdkEvent.state, gdkEvent.time, (int)gdkEvent.x, (int)gdkEvent.y); - return 1; -} - -int processMouseMove (int callData, int arg1, int int2) { - GdkEventMotion gdkEvent = new GdkEventMotion (); - OS.memmove (gdkEvent, callData, GdkEventMotion.sizeof); - Point where = _gdkWindowGetPointer(); - sendMouseEvent (SWT.MouseMove, 0, gdkEvent.state, gdkEvent.time, where.x, where.y); - return 1; -} -Point _gdkWindowGetPointer() { - int[] px = new int[1], py = new int[1]; - OS.gdk_window_get_pointer(_gdkWindow(), px, py, 0); - return new Point(px[0], py[0]); -} -int processFocusIn(int int0, int int1, int int2) { - postEvent(SWT.FocusIn); - return 0; -} -int processFocusOut(int int0, int int1, int int2) { - postEvent(SWT.FocusOut); - return 0; -} - -int processPaint (int callData, int int2, int int3) { - if (!hooks (SWT.Paint)) return 1; - - GdkEventExpose gdkEvent = new GdkEventExpose (); - OS.memmove (gdkEvent, callData, GdkEventExpose.sizeof); - Event event = new Event (); - event.count = gdkEvent.count; - event.x = gdkEvent.x; event.y = gdkEvent.y; - event.width = gdkEvent.width; event.height = gdkEvent.height; - GC gc = event.gc = new GC (this); - GdkRectangle rect = new GdkRectangle (); - rect.x = gdkEvent.x; rect.y = gdkEvent.y; - rect.width = gdkEvent.width; rect.height = gdkEvent.height; - OS.gdk_gc_set_clip_rectangle (gc.handle, rect); - gc.fillRectangle(rect.x, rect.y, rect.width, rect.height); - sendEvent (SWT.Paint, event); - gc.dispose (); - event.gc = null; - return 1; -} - -/** - * 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. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 - */ -public void redraw () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - Point size = _getSize(); - _redraw(0, 0, size.x, size.y, true); -//OS.gtk_widget_queue_draw(handle); -} -/** - * 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. 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 - */ -public void redraw (int x, int y, int width, int height, boolean all) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - _redraw(x, y, width, height, all); -} -protected void _redraw(int x, int y, int width, int height, boolean all) { - OS.gdk_window_clear_area_e (_gdkWindow(), x, y, width, height); - -GdkRectangle rect = new GdkRectangle(); -rect.x = (short)x; -rect.y = (short)y; -rect.width = (short)width; -rect.height =(short) height; -//OS.gtk_widget_draw(handle, rect); -OS.gtk_widget_queue_draw(handle); - -// OS.gtk_widget_queue_draw_area (handle, x, y, width, height); -} - -void releaseWidget () { - super.releaseWidget (); - toolTipText = null; - parent = null; - menu = null; - layoutData = null; -} -void sendKeyEvent (int type, GdkEventKey gdkEvent) { - /* Look up the keysym and character(s) */ - int size = gdkEvent.length; - if (gdkEvent.keyval == 0 && size == 0) return; - - /* If there is no composed string input by keypress, only send the keyvalue */ - if (size == 0 ) { - Event event = new Event (); - event.time = gdkEvent.time; -// event.character = (char) 0; //no character sent - event.keyCode = Display.translateKey (gdkEvent.keyval); - event.character = (char) event.keyCode; //no character sent - if ((gdkEvent.state & OS.GDK_MOD1_MASK) != 0) event.stateMask |= SWT.ALT; - if ((gdkEvent.state & OS.GDK_SHIFT_MASK) != 0) event.stateMask |= SWT.SHIFT; - if ((gdkEvent.state & OS.GDK_CONTROL_MASK) != 0) event.stateMask |= SWT.CONTROL; - if ((gdkEvent.state & OS.GDK_BUTTON1_MASK) != 0) event.stateMask |= SWT.BUTTON1; - if ((gdkEvent.state & OS.GDK_BUTTON2_MASK) != 0) event.stateMask |= SWT.BUTTON2; - if ((gdkEvent.state & OS.GDK_BUTTON3_MASK) != 0) event.stateMask |= SWT.BUTTON3; - postEvent (type, event); - } - else { - byte [] buffer = new byte [size]; - OS.memmove (buffer, gdkEvent.string, size); - /* Convert from MBCS to UNICODE and send the event */ - char [] result = Converter.mbcsToWcs (null, buffer); - for (int i=0; i<result.length; i++) { - Event event = new Event (); - event.time = gdkEvent.time; - event.character = result [i]; - event.keyCode = result [i]; //0; //no keyCode sent - if ((gdkEvent.state & OS.GDK_MOD1_MASK) != 0) event.stateMask |= SWT.ALT; - if ((gdkEvent.state & OS.GDK_SHIFT_MASK) != 0) event.stateMask |= SWT.SHIFT; - if ((gdkEvent.state & OS.GDK_CONTROL_MASK) != 0) event.stateMask |= SWT.CONTROL; - if ((gdkEvent.state & OS.GDK_BUTTON1_MASK) != 0) event.stateMask |= SWT.BUTTON1; - if ((gdkEvent.state & OS.GDK_BUTTON2_MASK) != 0) event.stateMask |= SWT.BUTTON2; - if ((gdkEvent.state & OS.GDK_BUTTON3_MASK) != 0) event.stateMask |= SWT.BUTTON3; - postEvent (type, event); - } - } -} -void sendMouseEvent (int type, int button, int mask, int time, int x, int y) { - Event event = new Event (); - event.time = time; - event.button = button; - event.x = x; event.y = y; - if ((mask & OS.GDK_MOD1_MASK) != 0) event.stateMask |= SWT.ALT; - if ((mask & OS.GDK_SHIFT_MASK) != 0) event.stateMask |= SWT.SHIFT; - if ((mask & OS.GDK_CONTROL_MASK) != 0) event.stateMask |= SWT.CONTROL; - if ((mask & OS.GDK_BUTTON1_MASK) != 0) event.stateMask |= SWT.BUTTON1; - if ((mask & OS.GDK_BUTTON2_MASK) != 0) event.stateMask |= SWT.BUTTON2; - if ((mask & OS.GDK_BUTTON3_MASK) != 0) event.stateMask |= SWT.BUTTON3; - postEvent (type, event); -} - -/** - * 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. - * - * @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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - int hDefaultStyle = OS.gtk_widget_get_default_style (); - int hStyle = OS.gtk_widget_get_style (handle); - boolean makeCopy = hStyle == hDefaultStyle; - hStyle = OS.gtk_style_copy (makeCopy ? hDefaultStyle : hStyle); - GtkStyle style = new GtkStyle (); - OS.memmove (style, hStyle, GtkStyle.sizeof); - if (color == null) { - GtkStyle defaultStyle = new GtkStyle (); - OS.memmove (defaultStyle, hDefaultStyle, GtkStyle.sizeof); - style.bg0_pixel = defaultStyle.bg0_pixel; - style.bg0_red = defaultStyle.bg0_red; - style.bg0_green = defaultStyle.bg0_green; - style.bg0_blue = defaultStyle.bg0_blue; - style.bg1_pixel = defaultStyle.bg1_pixel; - style.bg1_red = defaultStyle.bg1_red; - style.bg1_green = defaultStyle.bg1_green; - style.bg1_blue = defaultStyle.bg1_blue; - style.bg2_pixel = defaultStyle.bg2_pixel; - style.bg2_red = defaultStyle.bg2_red; - style.bg2_green = defaultStyle.bg2_green; - style.bg2_blue = defaultStyle.bg2_blue; - style.bg3_pixel = defaultStyle.bg3_pixel; - style.bg3_red = defaultStyle.bg3_red; - style.bg3_green = defaultStyle.bg3_green; - style.bg3_blue = defaultStyle.bg3_blue; - style.bg4_pixel = defaultStyle.bg4_pixel; - style.bg4_red = defaultStyle.bg4_red; - style.bg4_green = defaultStyle.bg4_green; - style.bg4_blue = defaultStyle.bg4_blue; - } else { - style.bg0_pixel = color.handle.pixel; - style.bg0_red = color.handle.red; - style.bg0_green = color.handle.green; - style.bg0_blue = color.handle.blue; - style.bg1_pixel = color.handle.pixel; - style.bg1_red = color.handle.red; - style.bg1_green = color.handle.green; - style.bg1_blue = color.handle.blue; - style.bg2_pixel = color.handle.pixel; - style.bg2_red = color.handle.red; - style.bg2_green = color.handle.green; - style.bg2_blue = color.handle.blue; - style.bg3_pixel = color.handle.pixel; - style.bg3_red = color.handle.red; - style.bg3_green = color.handle.green; - style.bg3_blue = color.handle.blue; - style.bg4_pixel = color.handle.pixel; - style.bg4_red = color.handle.red; - style.bg4_green = color.handle.green; - style.bg4_blue = color.handle.blue; - } - OS.memmove (hStyle, style, GtkStyle.sizeof); - OS.gtk_widget_set_style (handle, hStyle); - if (makeCopy) { - OS.gtk_style_unref (hStyle); - } -} - -/** - * 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. - * - * @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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - /* - 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(); - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, paintHandle(), GtkWidget.sizeof); - int window = widget.window; - if (window == 0) return; - int hCursor = 0; - if (cursor != null) hCursor = cursor.handle; - OS.gdk_window_set_cursor (window, hCursor); -} -/** - * 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - int topHandle = topHandle (); - OS.gtk_widget_set_sensitive (topHandle, enabled); - /* - * This code is intentionally commented - */ -// OS.gtk_widget_set_state (topHandle, enabled ? OS.GTK_STATE_NORMAL : OS.GTK_STATE_INSENSITIVE); -// if (enabled) { -// OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_SENSITIVE); -// } else { -// OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_SENSITIVE); -// } -} -/** - * Causes the receiver to have the <em>keyboard focus</em>, - * such that all keyboard events will 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 #forceFocus - */ -public boolean setFocus () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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(); - - /* The non-null font case */ - if (font != null) { - if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - int fontHandle = OS.gdk_font_ref(font.handle); - _setFontHandle(fontHandle); - return; - } - - /* The font argument is null, revert to default font */ - GtkStyle style = new GtkStyle(); - OS.memmove (style, OS.gtk_widget_get_default_style(), GtkStyle.sizeof); - int fontHandle = OS.gdk_font_ref(style.font); - if (fontHandle==0) error(SWT.ERROR_NO_HANDLES); - _setFontHandle(fontHandle); -} - -/** - * Actually set the receiver's font in the OS. - * Concrete subclasses may override this method to operate - * on a different handle. - */ -void _setFontHandle (int f) { - UtilFuncs.setFont(handle, f); -} - -/** - * 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. - * - * @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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - int hStyle = OS.gtk_widget_get_style (handle); - hStyle = OS.gtk_style_copy (hStyle); - GtkStyle style = new GtkStyle (); - OS.memmove (style, hStyle, GtkStyle.sizeof); - if (color == null) { - int hDefaultStyle = OS.gtk_widget_get_default_style (); - GtkStyle defaultStyle = new GtkStyle (); - OS.memmove (defaultStyle, hDefaultStyle, GtkStyle.sizeof); - style.fg0_pixel = defaultStyle.fg0_pixel; - style.fg0_red = defaultStyle.fg0_red; - style.fg0_green = defaultStyle.fg0_green; - style.fg0_blue = defaultStyle.fg0_blue; - style.fg1_pixel = defaultStyle.fg1_pixel; - style.fg1_red = defaultStyle.fg1_red; - style.fg1_green = defaultStyle.fg1_green; - style.fg1_blue = defaultStyle.fg1_blue; - style.fg2_pixel = defaultStyle.fg2_pixel; - style.fg2_red = defaultStyle.fg2_red; - style.fg2_green = defaultStyle.fg2_green; - style.fg2_blue = defaultStyle.fg2_blue; - style.fg3_pixel = defaultStyle.fg3_pixel; - style.fg3_red = defaultStyle.fg3_red; - style.fg3_green = defaultStyle.fg3_green; - style.fg3_blue = defaultStyle.fg3_blue; - style.fg4_pixel = defaultStyle.fg4_pixel; - style.fg4_red = defaultStyle.fg4_red; - style.fg4_green = defaultStyle.fg4_green; - style.fg4_blue = defaultStyle.fg4_blue; - } else { - style.fg0_pixel = color.handle.pixel; - style.fg0_red = color.handle.red; - style.fg0_green = color.handle.green; - style.fg0_blue = color.handle.blue; - style.fg1_pixel = color.handle.pixel; - style.fg1_red = color.handle.red; - style.fg1_green = color.handle.green; - style.fg1_blue = color.handle.blue; - style.fg2_pixel = color.handle.pixel; - style.fg2_red = color.handle.red; - style.fg2_green = color.handle.green; - style.fg2_blue = color.handle.blue; - style.fg3_pixel = color.handle.pixel; - style.fg3_red = color.handle.red; - style.fg3_green = color.handle.green; - style.fg3_blue = color.handle.blue; - style.fg4_pixel = color.handle.pixel; - style.fg4_red = color.handle.red; - style.fg4_green = color.handle.green; - style.fg4_blue = color.handle.blue; - } - OS.memmove (hStyle, style, GtkStyle.sizeof); - OS.gtk_widget_set_style (handle, hStyle); -} - -/** - * 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. - * - * @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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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; -} - -/** - * Changes the parent of the widget to be the one provided if - * the underlying operating system supports this feature. - * Answers <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> - * </ul> - * @exception SWTError <ul> - * <li>ERROR_THREAD_INVALID_ACCESS when called from the wrong thread</li> - * <li>ERROR_WIDGET_DISPOSED when the widget has been disposed</li> - * </ul> - */ -public boolean setParent (Composite parent) { - checkWidget(); - if (parent.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); - 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. - * <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 - * @see #update - */ -public void setRedraw (boolean redraw) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); -} -/** - * Sets the receiver's tool tip text to the argument, which - * may be null indicating that no tool tip text should be shown. - * - * @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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - toolTipText = string; -} -/** - * Marks the receiver as visible if the argument is <code>true</code>, - * and marks it invisible otherwise. - * <p> - * If one of the receiver's ancestors is not visible or some - * other condition makes the receiver not visible, marking - * it visible may not actually cause it to be displayed. - * </p> - * - * @param visible the new visibility state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setVisible (boolean visible) { - checkWidget(); - int topHandle = topHandle(); - if (visible) { - sendEvent (SWT.Show); - OS.gtk_widget_show (topHandle); - } else { - OS.gtk_widget_hide (topHandle); - sendEvent (SWT.Hide); - } -} -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 (); - if (!isFocusControl () && !setFocus ()) return false; - Event event = new Event (); - event.doit = true; - event.detail = traversal; - return traverse (event); -} - -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 false; - 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); - */ - } - error(SWT.ERROR_NOT_IMPLEMENTED); - return false; -} - - -/** - * Forces all outstanding paint requests for the widget tree - * to be processed before this method returns. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 - */ -public void update () { - checkWidget (); - //NOT DONE - should only dispatch paint events - OS.gdk_flush (); - while ((OS.gtk_events_pending()) != 0) { - OS.gtk_main_iteration (); - } -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Decorations.java deleted file mode 100644 index 1df146eab7..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Decorations.java +++ /dev/null @@ -1,447 +0,0 @@ -package org.eclipse.swt.widgets;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-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> - * 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</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 - */
-
-public class Decorations extends Canvas {
- String text;
- Image image;
- Menu menuBar;
- Menu [] menus;
- Button defaultButton, saveDefault;
-Decorations () {
- /* Do nothing */
-}
-/** - * Constructs a new instance of this class given its parent - * and a style value describing its behavior and appearance. - * <p> - * The style value is either one of the style constants defined in - * class <code>SWT</code> which is applicable to instances of this - * class, or must be built by <em>bitwise OR</em>'ing together - * (that is, using the <code>int</code> "|" operator) two or more - * of those <code>SWT</code> style constants. The class description - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 Decorations (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-static int checkStyle (int style) {
- if ((style & (SWT.MENU | SWT.MIN | SWT.MAX | SWT.CLOSE)) != 0) {
- style |= SWT.TITLE;
- }
- return style;
-}
-
-void add (Menu menu) {
- if (menus == null) menus = new Menu [4];
- for (int i=0; i<menus.length; i++) {
- if (menus [i] == null) {
- menus [i] = menu;
- return;
- }
- }
- Menu [] newMenus = new Menu [menus.length + 4];
- newMenus [menus.length] = menu;
- System.arraycopy (menus, 0, newMenus, 0, menus.length);
- menus = newMenus;
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- text = "";
-}
-
-/** - * 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 - */
-public Button getDefaultButton () {
- checkWidget();
- return defaultButton;
-}
-/** - * Returns the receiver's image if it had previously been - * set using <code>setImage()</code>. The image is typically - * displayed by the window manager when the instance is - * marked as iconified, and may also be displayed somewhere - * in the trim when the instance is in normal or maximized - * states. - * <p> - * Note: This method will return null if called before - * <code>setImage()</code> is called. It does not provide - * access to a window manager provided, "default" image - * even if one exists. - * </p> - * - * @return the image - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */
-public Image getImage () {
- checkWidget();
- return image;
-}
-/** - * Returns <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 false;
-}
-/** - * 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 false;
-}
-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;
-}
-Decorations menuShell () {
- return this;
-}
-
-void remove (Menu menu) {
- if (menus == null) return;
- for (int i=0; i<menus.length; i++) {
- if (menus [i] == menu) {
- menus [i] = null;
- return;
- }
- }
-}
-
-void releaseWidget () {
- if (menuBar != null) {
- menuBar.releaseWidget ();
- menuBar.releaseHandle ();
- }
- menuBar = null;
- if (menus != null) {
- for (int i=0; i<menus.length; i++) {
- Menu menu = menus [i];
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- }
- }
- menus = null;
- super.releaseWidget ();
- image = null;
- defaultButton = saveDefault = null;
-}
-/** - * 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. - * - * @param the new default button - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_ARGUMENT - if the button 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 setDefaultButton (Button button) {
- checkWidget();
-}
-/** - * 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;
- int pixmap = 0, mask = 0;
- if (image != null) {
- pixmap = image.pixmap;
- mask = image.mask;
- }
- GtkWidget widget = new GtkWidget ();
- OS.memmove(widget, topHandle(), GtkWidget.sizeof);
- OS.gdk_window_set_icon (widget.window, 0, pixmap, mask);
-}
-/** - * 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 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();
-}
-/** - * 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 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();
-}
-/** - * 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 may not be null. - * - * @param text the new text - * - * @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> - */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- text = string;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/DirectoryDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/DirectoryDialog.java deleted file mode 100644 index 261a6706e7..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/DirectoryDialog.java +++ /dev/null @@ -1,149 +0,0 @@ -package org.eclipse.swt.widgets;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.widgets.*;
-
-/** - * Instances of this class allow the user to navigate - * the file system and select a directory. - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - */
-
-public class DirectoryDialog extends GtkFileDialog {
- String message = "", filterPath = "";
- String directoryPath;
-
-/** - * Constructs a new instance of this class given only its - * parent. - * <p> - * Note: Currently, null can be passed in for the parent. - * This has the effect of creating the dialog on the currently active - * display if there is one. If there is no current display, the - * dialog 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_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.PRIMARY_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 - * for all SWT dialog classes should include a comment which - * describes the style constants which are applicable to the class. - * </p> - * Note: Currently, null can be passed in for the parent. - * This has the effect of creating the dialog on the currently active - * display if there is one. If there is no current display, the - * dialog 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_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, style);
- checkSubclass ();
-}
-/** - * Returns the path which the dialog will use to filter - * the directories it shows. - * - * @return the filter path - */ -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 () {
- return super.open();
-}
-
-/** - * Sets the path which the dialog will use to filter - * the directories it shows to the argument, which may be - * null. - * - * @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 - */ -public void setMessage (String string) {
- message = string;
-}
-
-boolean getAnswer() {
- String fileNameFromOS = getFileNameFromOS();
- int separatorIndex = calculateLastSeparatorIndex(fileNameFromOS);
- if (separatorIndex+1 != fileNameFromOS.length()) return false; // the user selected a file
- directoryPath = answer = fileNameFromOS;
- return true;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Display.java deleted file mode 100644 index 6512842431..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Display.java +++ /dev/null @@ -1,1516 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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><p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - * - * @see #syncExec - * @see #asyncExec - * @see #wake - * @see #readAndDispatch - * @see #sleep - * @see #dispose - */ - -public class Display extends Device { - - /* Events Dispatching and Callback */ - Event [] eventQueue; - int windowProc2, windowProc3, windowProc4, windowProc5; - Callback windowCallback2, windowCallback3, windowCallback4, windowCallback5; - - /* Sync/Async Widget Communication */ - Synchronizer synchronizer = new Synchronizer (this); - int messagesSize; - RunnableLock [] messages; - Object messageLock = new Object (); - Thread thread = Thread.currentThread (); - - /* Display Shutdown */ - Runnable [] disposeList; - - /* Timers */ - int [] timerIDs; - Runnable [] timerList; - Callback timerCallback; - int timerProc; - - /* Caret */ - Caret currentCaret; - Callback caretCallback; - int caretID, caretProc; - - /* Colors */ - Color NORMAL_fg, NORMAL_bg, NORMAL_dark, NORMAL_mid, NORMAL_light, NORMAL_text, NORMAL_base; - Color ACTIVE_fg, ACTIVE_bg, ACTIVE_dark, ACTIVE_mid, ACTIVE_light, ACTIVE_text, ACTIVE_base; - Color PRELIGHT_fg, PRELIGHT_bg, PRELIGHT_dark, PRELIGHT_mid, PRELIGHT_light, PRELIGHT_text, PRELIGHT_base; - Color SELECTED_fg, SELECTED_bg, SELECTED_dark, SELECTED_mid, SELECTED_light, SELECTED_text, SELECTED_base; - Color INSENSITIVE_fg, INSENSITIVE_bg, INSENSITIVE_dark, INSENSITIVE_mid, INSENSITIVE_light, INSENSITIVE_text, INSENSITIVE_base; - - /* Key Mappings */ - static final int [] [] KeyTable = { - - /* Keyboard and Mouse Masks */ - {OS.GDK_Alt_L, SWT.ALT}, - {OS.GDK_Alt_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}, - - /* Non-Numeric Keypad Constants */ - {OS.GDK_Up, SWT.ARROW_UP}, - {OS.GDK_Down, SWT.ARROW_DOWN}, - {OS.GDK_Left, SWT.ARROW_LEFT}, - {OS.GDK_Right, SWT.ARROW_RIGHT}, - {OS.GDK_Page_Up, SWT.PAGE_UP}, - {OS.GDK_Page_Down, SWT.PAGE_DOWN}, - {OS.GDK_Home, SWT.HOME}, - {OS.GDK_End, SWT.END}, - {OS.GDK_Insert, SWT.INSERT}, - - /* NOT CURRENTLY USED */ -// {OS.GDK_Delete, SWT.DELETE}, - {OS.GDK_Return, SWT.CR}, - - /* 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}, - - /* Numeric Keypad Constants */ - /* NOT CURRENTLY USED */ -// {OS.GDK_KP_Add, SWT.KP_PLUS}, -// {OS.GDK_KP_Subtract, SWT.KP_MINUS}, -// {OS.GDK_KP_Multiply, SWT.KP_TIMES}, -// {OS.GDK_KP_Divide, SWT.KP_DIVIDE}, -// {OS.GDK_KP_Decimal, SWT.KP_PERIOD}, -// {OS.GDK_KP_Enter, SWT.CR}, -// {OS.GDK_KP_0, SWT.KP_0}, -// {OS.GDK_KP_1, SWT.KP_1}, -// {OS.GDK_KP_2, SWT.KP_2}, -// {OS.GDK_KP_3, SWT.KP_3}, -// {OS.GDK_KP_4, SWT.KP_4}, -// {OS.GDK_KP_5, SWT.KP_5}, -// {OS.GDK_KP_6, SWT.KP_6}, -// {OS.GDK_KP_7, SWT.KP_7}, -// {OS.GDK_KP_8, SWT.KP_8}, -// {OS.GDK_KP_9, SWT.KP_9}, - - }; - - /* Multiple Displays. */ - static Display Default; - static Display [] Displays = new Display [4]; - - /* Package name */ - static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets."; - /* 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); - }*/ - - /* #define in gdkevents.h */ - static final int DOUBLE_CLICK_TIME = 250; - - /* Display Data */ - Object data; - String [] keys; - Object [] values; - - /* - * TEMPORARY CODE. Install the runnable that - * gets the current display. This code will - * be removed in the future. - */ - static { - DeviceFinder = new Runnable () { - public void run () { - Device device = getCurrent (); - if (device == null) { - device = getDefault (); - } - setDevice (device); - } - }; - } - -/* -* TEMPORARY CODE. -*/ -static void setDevice (Device device) { - CurrentDevice = device; -} - -/** - * Constructs a new instance of this class. - * <p> - * Note: The resulting display is marked as the <em>current</em> - * display. If this is the first display which has been - * constructed since the application started, it is also - * marked as the <em>default</em> display. - * </p> - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if 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 #getCurrent - * @see #getDefault - * @see Widget#checkSubclass - * @see Shell - */ -public Display () { - this (null); -} - -public Display (DeviceData data) { - super (data); -} - -void addLast (RunnableLock entry) { - synchronized (messageLock) { - if (messages == null) messages = new RunnableLock [4]; - if (messagesSize == messages.length) { - RunnableLock[] newMessages = new RunnableLock [messagesSize + 4]; - System.arraycopy (messages, 0, newMessages, 0, messagesSize); - messages = newMessages; - } - messages [messagesSize++] = entry; - } -} - -/** - * 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. - * - * @param runnable code to run on the user-interface thread. - * - * @see #syncExec - */ -public void asyncExec (Runnable runnable) { - if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); - synchronizer.asyncExec (runnable); -} - -/** - * Causes the system hardware to emit a short sound - * (if it supports this capability). - */ -public void beep () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - OS.gdk_beep(); - OS.gdk_flush(); -} - -protected void checkDevice () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); -} - -static synchronized void checkDisplay (Thread thread) { - for (int i=0; i<Displays.length; i++) { - if (Displays [i] != null && Displays [i].thread == thread) { - SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS); - } - } -} - -protected void checkSubclass () { - if (!isValidClass (getClass ())) error (SWT.ERROR_INVALID_SUBCLASS); -} - -protected void create (DeviceData data) { - checkSubclass (); - checkDisplay(thread = Thread.currentThread ()); - createDisplay (data); - register (); - if (Default == null) Default = this; -} - -synchronized void createDisplay (DeviceData data) { - if (!OS.gtk_init_check (new int [] {0}, null)) { - /* - * This code is intentionally commented. - */ -// disposed = true; -// SWT.error (SWT.ERROR_DEVICE_DISPOSED); - return; - } - OS.gdk_rgb_init (); - int ptr = OS.gtk_check_version (1, 2, 8); - if (ptr != 0) { - System.out.println ("***WARNING: SWT requires GTK version 1.2.8 or greater"); - 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))); - } -} - -synchronized void deregister () { - for (int i=0; i<Displays.length; i++) { - if (this == Displays [i]) Displays [i] = null; - } -} - -protected void destroy () { - if (this == Default) Default = null; - deregister (); - destroyDisplay (); -} - -void destroyDisplay () { -} - -/** - * 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. - * - * @param thread the user-interface thread - * @return the display for the given thread - */ -public static synchronized Display findDisplay (Thread thread) { - 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. - * - * @param runnable code to run at dispose time. - */ -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) { - throw new SWTError (code); -} - -/** - * 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. - * - * @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> - * </ul> - */ -public Widget findWidget (int handle) { - checkDevice (); - // In 0.058 and before, this used to go up the parent - // chain if the handle was not found in the widget - // table, up to the root. Now, we require that all - // widgets register ALL their handles. - // If somebody creates their own handles outside - // SWT, it's their problem. - return WidgetTable.get (handle); -} - -/* - * In SWT, we force all widgets to have real Gdk windows, - * thus getting rid of the concept of "lightweight" widgets. - * Given a GdkWindow, answer a handle to the GtkWidget realized - * through that window. - * If the argument is not the pointe rto a GdkWindow, the - * universe will be left in an inconsistent state. - */ -int findGtkWidgetByGdkWindow (int gdkWindow) { - int[] pwidget = new int[1]; - OS.gdk_window_get_user_data(gdkWindow, pwidget); - return pwidget[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> - * </ul> - */ -public Shell getActiveShell () { - checkDevice (); - Shell [] shells = getShells(); - for (int i=0; i<shells.length; i++) { - if (shells [i].hasFocus) return shells [i]; - } - return null; -} - -/** - * Returns a rectangle describing the receiver's size and location. - * - * @return the bounding rectangle - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</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 synchronized Display getCurrent () { - Thread current = Thread.currentThread (); - for (int i=0; i<Displays.length; i++) { - Display display = Displays [i]; - if (display != null && display.thread == current) return display; - } - return null; -} - -/** - * 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> - * </ul> - */ -public Control getCursorControl () { - checkDevice(); - int[] x = new int[1], y = new int[1]; - int cursorWindowHandle = OS.gdk_window_at_pointer(x,y); - if (cursorWindowHandle==0) return null; - int handle = findGtkWidgetByGdkWindow(cursorWindowHandle); - if (handle==0) return null; - return findControl(handle); -} - -Control findControl(int h) { - Widget w = findWidget(h); - if (w==null) return null; - if (w instanceof Control) return (Control)w; - // w is something like an Item. Go for the parent - - GtkWidget widget = new GtkWidget(); - OS.memmove(widget, h, GtkWidget.sizeof); - return findControl(widget.parent); -} - -/** - * 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> - * </ul> - */ -public Point getCursorLocation () { - checkDevice (); - int [] x = new int [1], y = new int [1]; - OS.gdk_window_get_pointer (0, x, y, 0); - return new Point (x [0], y [0]); -} - -/** - * 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 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> - * </ul> - * - * @see #setData - * @see #disposeExec - */ -public Object getData (String key) { - checkDevice (); - if (key == null) error (SWT.ERROR_NULL_ARGUMENT); - 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 provide a - * <code>disposeExec()</code> handler which does so. - * </p> - * - * @return the display specific data - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li> - * </ul> - * - * @see #setData - * @see #disposeExec - */ -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 (); - // compute round(25.4 * width / widthMM) - int dpi = Compatibility.round(254 * width, widthMM * 10); - return new Point (dpi, dpi); -} - -/** - * 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 synchronized Display getDefault () { - 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 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> - * </ul> - */ -public int getDoubleClickTime () { - checkDevice (); - return DOUBLE_CLICK_TIME; -} - -/** - * 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> - * </ul> - */ -public Control getFocusControl () { - checkDevice (); - Shell active = getActiveShell(); - if (active==null) return null; - return active.getFocusControl(); -} - -public int getDepth () { - checkDevice (); - GdkVisual visual = new GdkVisual (); - OS.memmove(visual, OS.gdk_visual_get_system(), GdkVisual.sizeof); - return visual.depth; -} - -/** - * Returns the maximum allowed depth of icons on this display. - * 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> - * </ul> - */ -public int getIconDepth () { - checkDevice (); - return getDepth (); -} - -/** - * Returns an 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> - * </ul> - */ -public Shell [] getShells () { - checkDevice (); - int count = 0; - Shell [] shells = WidgetTable.shells (); - for (int i=0; i<shells.length; i++) { - Shell shell = shells [i]; - if (!shell.isDisposed () && (this == shell.getDisplay ())) { - count++; - } - } - int index = 0; - Shell [] result = new Shell [count]; - for (int i=0; i<shells.length; i++) { - Shell shell = shells [i]; - if (!shell.isDisposed () && (this == shell.getDisplay ())) { - result [index++] = shell; - } - } - return result; -} - -/** - * 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 - */ -public Thread getSyncThread () { - 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> - * </ul> - * - * @see SWT - */ -public Color getSystemColor (int id) { - checkDevice (); - switch (id) { - case SWT.COLOR_INFO_FOREGROUND: return NORMAL_fg; - case SWT.COLOR_INFO_BACKGROUND: return NORMAL_bg; - - case SWT.COLOR_TITLE_FOREGROUND: return SELECTED_text; - case SWT.COLOR_TITLE_BACKGROUND: return SELECTED_bg; - case SWT.COLOR_TITLE_BACKGROUND_GRADIENT: return SELECTED_light; - case SWT.COLOR_TITLE_INACTIVE_FOREGROUND: return INSENSITIVE_fg; - case SWT.COLOR_TITLE_INACTIVE_BACKGROUND: return INSENSITIVE_bg; - case SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT: return INSENSITIVE_light; - - case SWT.COLOR_WIDGET_DARK_SHADOW: return NORMAL_dark; - case SWT.COLOR_WIDGET_NORMAL_SHADOW: return NORMAL_mid; - case SWT.COLOR_WIDGET_LIGHT_SHADOW: return NORMAL_light; - case SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: return NORMAL_light; - case SWT.COLOR_WIDGET_BACKGROUND: return NORMAL_bg; - case SWT.COLOR_WIDGET_FOREGROUND: return NORMAL_fg; - case SWT.COLOR_WIDGET_BORDER: return super.getSystemColor (SWT.COLOR_BLACK); - - case SWT.COLOR_LIST_FOREGROUND: return super.getSystemColor (SWT.COLOR_BLACK); - case SWT.COLOR_LIST_BACKGROUND: return super.getSystemColor (SWT.COLOR_WHITE); - case SWT.COLOR_LIST_SELECTION: return SELECTED_bg; - case SWT.COLOR_LIST_SELECTION_TEXT: return SELECTED_text; - } - return super.getSystemColor (id); -} - -void initializeSystemColors() { - - /* Get the theme colors */ - GtkStyle defaultStyle = new GtkStyle(); - OS.memmove (defaultStyle, OS.gtk_widget_get_default_style(), GtkStyle.sizeof); - - GdkColor gdk_NORMAL_dark = new GdkColor(); - gdk_NORMAL_dark.pixel = defaultStyle.dark0_pixel; - gdk_NORMAL_dark.red = defaultStyle.dark0_red; - gdk_NORMAL_dark.green = defaultStyle.dark0_green; - gdk_NORMAL_dark.blue = defaultStyle.dark0_blue; - NORMAL_dark = Color.gtk_new(gdk_NORMAL_dark); - - GdkColor gdk_NORMAL_mid = new GdkColor(); - gdk_NORMAL_mid.pixel = defaultStyle.mid0_pixel; - gdk_NORMAL_mid.red = defaultStyle.mid0_red; - gdk_NORMAL_mid.green = defaultStyle.mid0_green; - gdk_NORMAL_mid.blue = defaultStyle.mid0_blue; - NORMAL_mid = Color.gtk_new(gdk_NORMAL_mid); - - GdkColor gdk_NORMAL_light = new GdkColor(); - gdk_NORMAL_light.pixel = defaultStyle.light0_pixel; - gdk_NORMAL_light.red = defaultStyle.light0_red; - gdk_NORMAL_light.green = defaultStyle.light0_green; - gdk_NORMAL_light.blue = defaultStyle.light0_blue; - NORMAL_light = Color.gtk_new(gdk_NORMAL_light); - - GdkColor gdk_NORMAL_fg = new GdkColor(); - gdk_NORMAL_fg.pixel = defaultStyle.fg0_pixel; - gdk_NORMAL_fg.red = defaultStyle.fg0_red; - gdk_NORMAL_fg.green = defaultStyle.fg0_green; - gdk_NORMAL_fg.blue = defaultStyle.fg0_blue; - NORMAL_fg = Color.gtk_new(gdk_NORMAL_fg); - - GdkColor gdk_NORMAL_bg = new GdkColor(); - gdk_NORMAL_bg.pixel = defaultStyle.bg0_pixel; - gdk_NORMAL_bg.red = defaultStyle.bg0_red; - gdk_NORMAL_bg.green = defaultStyle.bg0_green; - gdk_NORMAL_bg.blue = defaultStyle.bg0_blue; - NORMAL_bg = Color.gtk_new(gdk_NORMAL_bg); - - GdkColor gdk_NORMAL_text = new GdkColor(); - gdk_NORMAL_text.pixel = defaultStyle.text0_pixel; - gdk_NORMAL_text.red = defaultStyle.text0_red; - gdk_NORMAL_text.green = defaultStyle.text0_green; - gdk_NORMAL_text.blue = defaultStyle.text0_blue; - NORMAL_text = Color.gtk_new(gdk_NORMAL_text); - - GdkColor gdk_NORMAL_base = new GdkColor(); - gdk_NORMAL_base.pixel = defaultStyle.base0_pixel; - gdk_NORMAL_base.red = defaultStyle.base0_red; - gdk_NORMAL_base.green = defaultStyle.base0_green; - gdk_NORMAL_base.blue = defaultStyle.base0_blue; - NORMAL_base = Color.gtk_new(gdk_NORMAL_base); - - GdkColor gdk_SELECTED_text = new GdkColor(); - gdk_SELECTED_text.pixel = defaultStyle.text3_pixel; - gdk_SELECTED_text.red = defaultStyle.text3_red; - gdk_SELECTED_text.green = defaultStyle.text3_green; - gdk_SELECTED_text.blue = defaultStyle.text3_blue; - SELECTED_text = Color.gtk_new(gdk_SELECTED_text); - - GdkColor gdk_SELECTED_bg = new GdkColor(); - gdk_SELECTED_bg.pixel = defaultStyle.bg3_pixel; - gdk_SELECTED_bg.red = defaultStyle.bg3_red; - gdk_SELECTED_bg.green = defaultStyle.bg3_green; - gdk_SELECTED_bg.blue = defaultStyle.bg3_blue; - SELECTED_bg = Color.gtk_new(gdk_SELECTED_bg); - - GdkColor gdk_SELECTED_base = new GdkColor(); - gdk_SELECTED_base.pixel = defaultStyle.base3_pixel; - gdk_SELECTED_base.red = defaultStyle.base3_red; - gdk_SELECTED_base.green = defaultStyle.base3_green; - gdk_SELECTED_base.blue = defaultStyle.base3_blue; - SELECTED_base = Color.gtk_new(gdk_SELECTED_base); - - GdkColor gdk_SELECTED_light = new GdkColor(); - gdk_SELECTED_light.pixel = defaultStyle.light3_pixel; - gdk_SELECTED_light.red = defaultStyle.light3_red; - gdk_SELECTED_light.green = defaultStyle.light3_green; - gdk_SELECTED_light.blue = defaultStyle.light3_blue; - SELECTED_light = Color.gtk_new(gdk_SELECTED_light); - - - GdkColor gdk_PRELIGHT_light = new GdkColor(); - gdk_PRELIGHT_light.pixel = defaultStyle.light2_pixel; - gdk_PRELIGHT_light.red = defaultStyle.light2_red; - gdk_PRELIGHT_light.green = defaultStyle.light2_green; - gdk_PRELIGHT_light.blue = defaultStyle.light2_blue; - PRELIGHT_light = Color.gtk_new(gdk_PRELIGHT_light); - - GdkColor gdk_INSENSITIVE_light = new GdkColor(); - gdk_INSENSITIVE_light.pixel = defaultStyle.light4_pixel; - gdk_INSENSITIVE_light.red = defaultStyle.light4_red; - gdk_INSENSITIVE_light.green = defaultStyle.light4_green; - gdk_INSENSITIVE_light.blue = defaultStyle.light4_blue; - INSENSITIVE_light = Color.gtk_new(gdk_INSENSITIVE_light); - - GdkColor gdk_INSENSITIVE_fg = new GdkColor(); - gdk_INSENSITIVE_fg.pixel = defaultStyle.fg4_pixel; - gdk_INSENSITIVE_fg.red = defaultStyle.fg4_red; - gdk_INSENSITIVE_fg.green = defaultStyle.fg4_green; - gdk_INSENSITIVE_fg.blue = defaultStyle.fg4_blue; - INSENSITIVE_fg = Color.gtk_new(gdk_INSENSITIVE_fg); - - GdkColor gdk_INSENSITIVE_bg = new GdkColor(); - gdk_INSENSITIVE_bg.pixel = defaultStyle.bg4_pixel; - gdk_INSENSITIVE_bg.red = defaultStyle.bg4_red; - gdk_INSENSITIVE_bg.green = defaultStyle.bg4_green; - gdk_INSENSITIVE_bg.blue = defaultStyle.bg4_blue; - INSENSITIVE_bg = Color.gtk_new(gdk_INSENSITIVE_bg); - - -} - -/** - * 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> - * </ul> - */ -public Font getSystemFont () { - checkDevice (); - GtkStyle style = new GtkStyle(); - OS.memmove (style, OS.gtk_widget_get_default_style(), GtkStyle.sizeof); - int gdkFont = style.font; // gives a GdkFont* - return Font.gtk_new (gdkFont); -} - -/** - * Returns the user-interface thread for the receiver. - * - * @return the receiver's user-interface thread - */ -public Thread getThread () { - if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); - return thread; -} - -protected void init () { - super.init (); - initializeCallbacks (); - initializeSystemColors (); -} - -void initializeCallbacks () { - windowCallback2 = new Callback (this, "windowProc", 2); - windowProc2 = windowCallback2.getAddress (); - if (windowProc2 == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - - windowCallback3 = new Callback (this, "windowProc", 3); - windowProc3 = windowCallback3.getAddress (); - if (windowProc3 == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - - windowCallback4 = new Callback (this, "windowProc", 4); - windowProc4 = windowCallback4.getAddress (); - if (windowProc4 == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - - windowCallback5 = new Callback (this, "windowProc", 5); - windowProc5 = windowCallback5.getAddress (); - if (windowProc5 == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); - - timerCallback = new Callback (this, "timerProc", 2); - timerProc = timerCallback.getAddress (); - if (timerProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - - caretCallback = new Callback(this, "caretProc", 2); - caretProc = caretCallback.getAddress(); - if (caretProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); -} - -/** - * 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 handle the platform specific GC handle - * @param data the platform specific GC data - * - * @private - */ -public void internal_dispose_GC (int handle, GCData data) { - OS.gdk_gc_destroy(handle); -} - -/** - * 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 - * - * @private - */ -public int internal_new_GC (GCData data) { - if (isDisposed()) SWT.error(SWT.ERROR_DEVICE_DISPOSED); - int root = OS.GDK_ROOT_PARENT(); - int gc = OS.gdk_gc_new(root); - data.drawable = root; - return gc; -} - -boolean isValidThread () { - return thread == Thread.currentThread (); -} - -void postEvent (Event event) { - /* - * Place the event at the end of the event queue. - * This code is always called in the Display's - * thread so it must be re-enterant but does not - * need to be synchronized. - */ - if (eventQueue == null) eventQueue = new Event [4]; - int index = 0; - int length = eventQueue.length; - while (index < length) { - if (eventQueue [index] == null) break; - index++; - } - if (index == length) { - Event [] newQueue = new Event [length + 4]; - System.arraycopy (eventQueue, 0, newQueue, 0, length); - eventQueue = newQueue; - } - eventQueue [index] = event; -} - -/** - * Reads an event from the operating system's event queue, - * dispatches it appropriately, and returns <code>true</code> - * if there is potentially more work to do, or <code>false</code> - * if the caller can sleep until another event is placed on - * the event queue. - * <p> - * In addition to checking the system event queue, this method also - * checks if any inter-thread messages (created by <code>syncExec()</code> - * or <code>asyncExec()</code>) are waiting to be processed, and if - * so handles them before returning. - * </p> - * - * @return <code>false</code> if the caller can sleep upon return from this method - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #sleep - * @see #wake - */ -public boolean readAndDispatch () { - checkDevice (); - int status = OS.gtk_events_pending (); - if (status != 0) { -// if ((status & OS.XtIMTimer) != 0) OS.XtAppProcessEvent (context, OS.XtIMTimer); -// if ((status & OS.XtIMAlternateInput) != 0) OS.XtAppProcessEvent (context, OS.XtIMAlternateInput); -// if ((status & OS.XtIMXEvent) != 0) { -// OS.XtAppNextEvent (context, event); -// OS.XtDispatchEvent (event); -// } -/* int eventPtr = OS.gdk_event_get(); - if (eventPtr != 0) { - OS.gtk_main_do_event(eventPtr); - }*/ - OS.gtk_main_iteration (); - runDeferredEvents (); - return true; - } - return runAsyncMessages (); -} - -synchronized void register () { - for (int i=0; i<Displays.length; i++) { - if (Displays [i] == null) { - Displays [i] = this; - return; - } - } - Display [] newDisplays = new Display [Displays.length + 4]; - System.arraycopy (Displays, 0, newDisplays, 0, Displays.length); - newDisplays [Displays.length] = this; - Displays = newDisplays; -} - -protected void release () { - - /* Release shells */ - Shell [] shells = WidgetTable.shells (); - for (int i=0; i<shells.length; i++) { - Shell shell = shells [i]; - if (!shell.isDisposed ()) { - if (this == shell.getDisplay ()) shell.dispose (); - } - } - while (readAndDispatch ()) {}; - - /* Run dispose list */ - if (disposeList != null) { - for (int i=0; i<disposeList.length; i++) { - if (disposeList [i] != null) disposeList [i].run (); - } - } - disposeList = null; - - /* Release synchronizer */ - 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; - - /* Dispose the caret callback */ - if (caretID != 0) OS.gtk_timeout_remove (caretID); - caretID = caretProc = 0; - caretCallback.dispose (); - caretCallback = null; - - /* Dispose the timer callback */ - if (timerIDs != null) { - for (int i=0; i<timerIDs.length; i++) { - if (timerIDs [i] != 0) OS.gtk_timeout_remove (timerIDs [i]); - } - } - timerIDs = null; - timerList = null; - timerProc = 0; - timerCallback.dispose (); - timerCallback = null; - - messages = null; messageLock = null; thread = null; - messagesSize = windowProc2 = windowProc3 = windowProc4 = windowProc5 = 0; - - NORMAL_fg = NORMAL_bg = NORMAL_dark = NORMAL_mid = NORMAL_light = NORMAL_text = NORMAL_base = - ACTIVE_fg = ACTIVE_bg = ACTIVE_dark = ACTIVE_mid = ACTIVE_light = ACTIVE_text = ACTIVE_base = - PRELIGHT_fg = PRELIGHT_bg = PRELIGHT_dark = PRELIGHT_mid = PRELIGHT_light = PRELIGHT_text = PRELIGHT_base = - SELECTED_fg = SELECTED_bg = SELECTED_dark = SELECTED_mid = SELECTED_light = SELECTED_text = SELECTED_base = - INSENSITIVE_fg = INSENSITIVE_bg = INSENSITIVE_dark = INSENSITIVE_mid = INSENSITIVE_light = INSENSITIVE_text = - INSENSITIVE_base = null; -} - -RunnableLock removeFirst () { - synchronized (messageLock) { - if (messagesSize == 0) return null; - RunnableLock lock = messages [0]; - System.arraycopy (messages, 1, messages, 0, --messagesSize); - messages [messagesSize] = null; - if (messagesSize == 0) messages = null; - return lock; - } -} - -boolean runAsyncMessages () { - return synchronizer.runAsyncMessages (); -} - -boolean runDeferredEvents () { - /* - * Run deferred events. This code is always - * called in the Display's thread so it must - * be re-enterant 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 ()) { - widget.notifyListeners (event.type, 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 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. - * - * @param name the new app name - */ -public static void setAppName (String name) { - /* Do nothing - Gtk doesn't have the concept of application name. */ -} - -/** - * 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> - * </ul> - * - * @see #setData - * @see #disposeExec - */ -public void setData (String key, Object value) { - checkDevice (); - if (key == null) error (SWT.ERROR_NULL_ARGUMENT); - - /* Remove the key/value pair */ - if (value == null) { - if (keys == null) return; - int index = 0; - while (index < keys.length && !keys [index].equals (key)) index++; - if (index == keys.length) return; - if (keys.length == 1) { - keys = null; - values = null; - } else { - String [] newKeys = new String [keys.length - 1]; - Object [] newValues = new Object [values.length - 1]; - System.arraycopy (keys, 0, newKeys, 0, index); - System.arraycopy (keys, index + 1, newKeys, index, newKeys.length - index); - System.arraycopy (values, 0, newValues, 0, index); - System.arraycopy (values, index + 1, newValues, index, newValues.length - index); - keys = newKeys; - values = newValues; - } - return; - } - - /* Add the key/value pair */ - if (keys == null) { - keys = new String [] {key}; - values = new Object [] {value}; - return; - } - for (int i=0; i<keys.length; i++) { - if (keys [i].equals (key)) { - values [i] = value; - return; - } - } - String [] newKeys = new String [keys.length + 1]; - Object [] newValues = new Object [values.length + 1]; - System.arraycopy (keys, 0, newKeys, 0, keys.length); - System.arraycopy (values, 0, newValues, 0, values.length); - newKeys [keys.length] = key; - newValues [values.length] = value; - keys = newKeys; - values = newValues; -} - -/** - * Sets the application defined, display specific data - * associated with the receiver, to the argument. - * The <em>display specific data</em> is a single, - * unnamed field that is stored with every display. - * <p> - * Applications may put arbitrary objects in this field. If - * the object stored in the display specific data needs to - * be notified when the display is disposed of, it is the - * application's responsibility provide a - * <code>disposeExec()</code> handler which does so. - * </p> - * - * @param data the new display specific data - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - when called from the wrong thread</li> - * </ul> - * - * @see #getData - * @see #disposeExec - */ -public void setData (Object data) { - checkDevice (); - this.data = data; -} - -/** - * Sets the synchronizer used by the display to be - * the argument, which can not be null. - * - * @param synchronizer the new synchronizer for the display (must not be null) - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the synchronizer is null</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setSynchronizer (Synchronizer synchronizer) { - checkDevice (); - if (synchronizer == null) error (SWT.ERROR_NULL_ARGUMENT); - if (this.synchronizer != null) { - this.synchronizer.runAsyncMessages(); - } - this.synchronizer = synchronizer; -} - -/** - * 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> - * </ul> - * - * @see #wake - */ - -public boolean sleep () { - checkDevice (); - /* Temporary code - need to sleep waiting for the next message */ - try { Thread.sleep(50); } catch (Exception e) {}; - 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. - * - * @param milliseconds the delay before running the runnable - * @param runnable code to run on the user-interface thread - * - * @exception SWTException <ul> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #asyncExec - */ -public void timerExec (int milliseconds, Runnable runnable) { - checkDevice (); - if (timerList == null) timerList = new Runnable [4]; - if (timerIDs == null) timerIDs = new int [4]; - int 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 timerProc (int index, int id) { - if (timerList == null) return 0; - if (0 <= index && index < timerList.length) { - Runnable runnable = timerList [index]; - timerList [index] = null; - timerIDs [index] = 0; - if (runnable != null) runnable.run (); - } - return 0; -} - -int caretProc (int clientData, int id) { - caretID = 0; - if (currentCaret == null) { - return 0; - } - if (currentCaret.blinkCaret()) { - int blinkRate = currentCaret.blinkRate; - caretID = OS.gtk_timeout_add (blinkRate, caretProc, 0); - } else { - currentCaret = null; - } - return 0; -} - -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); -} - -/** - * 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. - * - * @param runnable code to run on the user-interface thread. - * - * @exception SWTException <ul> - * <li>ERROR_FAILED_EXEC - if an exception occured when executing the runnable</li> - * </ul> - * - * @see #asyncExec - */ -public void syncExec (Runnable runnable) { - if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); - 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; -} - -public void update () { - checkDevice (); - /* NOT IMPLEMENTED - Need to flush only pending draws */ - OS.gdk_flush (); - while ((OS.gtk_events_pending ()) != 0) { - OS.gtk_main_iteration (); - } -} - -/** - * 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. - * - * @see #sleep - */ -public void wake () { - /* NOT IMPLEMENTED - Need to wake up the event loop */ - if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); -} - -int windowProc (int handle, int user_data) { - Widget widget = WidgetTable.get (handle); - if (widget == null) return 0; - return widget.processEvent (user_data, 0, 0, 0); -} - -int windowProc (int handle, int int0, int user_data) { - Widget widget = WidgetTable.get (handle); - if (widget == null) return 0; - return widget.processEvent (user_data, int0, 0, 0); -} - -int windowProc (int handle, int int0, int int1, int user_data) { - Widget widget = WidgetTable.get (handle); - if (widget == null) return 0; - return widget.processEvent (user_data, int0, int1, 0); -} - -int windowProc (int handle, int int0, int int1, int int2, int user_data) { - Widget widget = WidgetTable.get (handle); - if (widget == null) return 0; - return widget.processEvent (user_data, int0, int1, int2); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/FileDialog.java deleted file mode 100644 index 940b7427f4..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/FileDialog.java +++ /dev/null @@ -1,188 +0,0 @@ -package org.eclipse.swt.widgets;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-import org.eclipse.swt.*;
-
-/** - * Instances of this class allow the user to navigate - * the file system and select or enter a file name. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>SAVE, OPEN, MULTI</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - */
-public class FileDialog extends GtkFileDialog {
-
- String fullPath, fileName, filterPath;
- String[] filterNames, filterExtensions;
-
-/** - * Constructs a new instance of this class given only its - * parent. - * <p> - * Note: Currently, null can be passed in for the parent. - * This has the effect of creating the dialog on the currently active - * display if there is one. If there is no current display, the - * dialog 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_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.PRIMARY_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 - * for all SWT dialog classes should include a comment which - * describes the style constants which are applicable to the class. - * </p> - * Note: Currently, null can be passed in for the parent. - * This has the effect of creating the dialog on the currently active - * display if there is one. If there is no current display, the - * dialog 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_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, int style) {
- super (parent, style);
- checkSubclass ();
-}
-
-/** - * Returns the path of the first file that was - * selected in the dialog relative to the filter path, - * or null if none is available. - * - * @return the relative path of the file - */ -public String getFileName () {
- return fileName;
-}
-/**
- * Returns the paths of all files that were selected
- * in the dialog relative to the filter path, or null
- * if none are available.
- *
- * @return the relative paths of the files
- */
-public String [] getFileNames () {
- return new String[] {fileName};
-}
-/** - * 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;
-}
-/** - * Returns the file names which the dialog will - * use to filter the files it shows. - * - * @return the file name filter - */ -public String [] getFilterNames () {
- return filterNames;
-}
-/** - * Returns the path which the dialog will use to filter - * the files it shows. - * - * @return the filter path - */ -public String getFilterPath () {
- return filterPath;
-}
-
-/** - * 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. - * - * @param extensions the file extension filter - */ -public void setFilterExtensions (String [] extensions) {
- filterExtensions = extensions;
-}
-/** - * Sets the file names which the dialog will - * use to filter the files it shows to the argument, - * which may be null. - * - * @param names the file name filter - */ -public void setFilterNames (String [] names) {
- filterNames = names;
-}
-/** - * Sets the path which the dialog will use to filter - * the files it shows to the argument, which may be - * null. - * - * @param string the filter path - */ -public void setFilterPath (String string) {
- filterPath = string;
-}
-
-boolean getAnswer() {
- String fileNameFromOS = getFileNameFromOS();
- int separatorIndex = calculateLastSeparatorIndex(fileNameFromOS);
- if (separatorIndex+1 == fileNameFromOS.length()) return false; // the user selected a directory
- fullPath = answer = fileNameFromOS;
- fileName = fullPath.substring (separatorIndex + 1, fullPath.length ());
- filterPath = fullPath.substring (0, separatorIndex);
- return true;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/FontDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/FontDialog.java deleted file mode 100644 index 8f3a57f991..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/FontDialog.java +++ /dev/null @@ -1,166 +0,0 @@ -package org.eclipse.swt.widgets;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-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. - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - */
-
-public class FontDialog extends Dialog {
- FontData fontData;
-/** - * Constructs a new instance of this class given only its - * parent. - * <p> - * Note: Currently, null can be passed in for the parent. - * This has the effect of creating the dialog on the currently active - * display if there is one. If there is no current display, the - * dialog 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_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.PRIMARY_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 - * for all SWT dialog classes should include a comment which - * describes the style constants which are applicable to the class. - * </p> - * Note: Currently, null can be passed in for the parent. - * This has the effect of creating the dialog on the currently active - * display if there is one. If there is no current display, the - * dialog 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_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, style);
- checkSubclass ();
-}
-int cancelFunc (int widget, int callData) {
- OS.gtk_widget_destroy (callData);
- return 0;
-}
-int destroyFunc (int widget, int colorInfo) {
- OS.gtk_main_quit ();
- return 0;
-}
-/** - * 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 - */ -public FontData getFontData() {
- return fontData;
-}
-int okFunc (int widget, int callData) {
- int hFontName = OS.gtk_font_selection_dialog_get_font_name (callData);
- int fontSize = OS.strlen (hFontName);
- byte [] buffer = new byte [fontSize];
- OS.memmove (buffer, hFontName, fontSize);
- char [] fontName = Converter.mbcsToWcs (null, buffer);
- fontData = FontData.gtk_new(new String (fontName));
- OS.gtk_widget_destroy (callData);
- return 0;
-}
-/** - * 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 handle;
- byte [] titleBytes;
- titleBytes = Converter.wcsToMbcs (null, title, true);
- handle = OS.gtk_font_selection_dialog_new (titleBytes);
- GtkFontSelectionDialog dialog = new GtkFontSelectionDialog ();
- OS.memmove (dialog, handle, GtkFontSelectionDialog.sizeof);
- if (parent!=null) {
- OS.gtk_window_set_modal(handle, true);
- OS.gtk_window_set_transient_for(handle, parent.topHandle);
- }
- if (fontData != null) {
- byte[] buffer = Converter.wcsToMbcs(null, fontData.gtk_getXlfd(), true);
- OS.gtk_font_selection_set_font_name(dialog.fontsel, buffer);
- }
- Callback destroyCallback = new Callback (this, "destroyFunc", 2);
- int destroyFunc = destroyCallback.getAddress ();
- byte [] destroy = Converter.wcsToMbcs (null, "destroy", true);
- OS.gtk_signal_connect (handle, destroy, destroyFunc, handle);
- byte [] clicked = Converter.wcsToMbcs (null, "clicked", true);
- Callback okCallback = new Callback (this, "okFunc", 2);
- int okFunc = okCallback.getAddress ();
- Callback cancelCallback = new Callback (this, "cancelFunc", 2);
- int cancelFunc = cancelCallback.getAddress ();
- OS.gtk_signal_connect (dialog.ok_button, clicked, okFunc, handle);
- OS.gtk_signal_connect (dialog.cancel_button, clicked, cancelFunc, handle);
- fontData = null;
- OS.gtk_widget_show_now (handle);
- OS.gtk_main ();
- destroyCallback.dispose ();
- okCallback.dispose ();
- cancelCallback.dispose ();
- 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 - */ -public void setFontData (FontData fontData) {
- this.fontData = fontData;
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Group.java deleted file mode 100644 index b0d72d4e90..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Group.java +++ /dev/null @@ -1,253 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */ -public class Group extends Composite { - int frameHandle; - 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 Group (Composite parent, int style) { - super (parent, checkStyle (style)); -} -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); -} - -void createHandle(int index) { - state |= HANDLE; - - eventBoxHandle = OS.gtk_event_box_new (); - if (eventBoxHandle == 0) error (SWT.ERROR_NO_HANDLES); - - frameHandle = OS.gtk_frame_new(null); - if (frameHandle == 0) error (SWT.ERROR_NO_HANDLES); - - handle = OS.gtk_fixed_new(); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); -} - -void _setHandleStyle() { - int shadow = OS.GTK_SHADOW_IN; - if ((style & SWT.SHADOW_IN) != 0) shadow = OS.GTK_SHADOW_IN; - if ((style & SWT.SHADOW_OUT) != 0) shadow = OS.GTK_SHADOW_OUT; - if ((style & SWT.SHADOW_ETCHED_IN) != 0) shadow = OS.GTK_SHADOW_ETCHED_IN; - if ((style & SWT.SHADOW_ETCHED_OUT) != 0) shadow = OS.GTK_SHADOW_ETCHED_OUT; - OS.gtk_frame_set_shadow_type(frameHandle, shadow); -} - -void configure() { - _connectParent(); - OS.gtk_container_add(eventBoxHandle, frameHandle); - OS.gtk_container_add(frameHandle, handle); -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - int width = _computeSize(wHint, hHint, changed).x; - int height = 0; - Point size; - if (layout != null) { - size = layout.computeSize (this, wHint, hHint, changed); - } else { - size = minimumSize (); - } - 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; - width = Math.max (width, size.x); - height = Math.max (height, size.y); - Rectangle trim = computeTrim (0, 0, width, height); - width = trim.width; height = trim.height; - return new Point (width, height); -} - -void showHandle() { - OS.gtk_widget_show (eventBoxHandle); - OS.gtk_widget_show (frameHandle); - OS.gtk_widget_show (handle); - OS.gtk_widget_realize (handle); -} - -void register () { - super.register (); - WidgetTable.put (frameHandle, this); -} - -void releaseHandle () { - super.releaseHandle (); - frameHandle = 0; -} - -void releaseWidget () { - super.releaseWidget (); - text = null; -} - -void deregister () { - super.deregister (); - WidgetTable.remove (frameHandle); -} - -int topHandle () { return eventBoxHandle; } -int parentingHandle() { return handle; } - -/* - * === GEOMETRY === - */ - -public Rectangle _getClientArea () { - /* - * The Group coordinates originate at the client area - */ - int width, height; - Point size = _getSize(); - width = size.x - _getTrim().left - _getTrim().right; - height = size.y - _getTrim().top - _getTrim().bottom; - return new Rectangle(0,0, width, height); -} - -Trim _getTrim() { - trim = new Trim(); - - // set up the test widgets - int testWindowHandle = OS.gtk_window_new(0); - int testHandle = OS.gtk_frame_new(string2bytesConvertMnemonic("Test String")); - OS.gtk_container_add(testWindowHandle, testHandle); - OS.gtk_widget_realize(testHandle); - - // get info - GtkFrame frame = new GtkFrame(); - OS.memmove (frame, testHandle, GtkFrame.sizeof); - GtkStyle groupStyle = new GtkStyle(); - OS.memmove (groupStyle, frame.style, GtkStyle.sizeof); - GtkStyleClass styleClass = new GtkStyleClass(); - OS.memmove (styleClass, groupStyle.klass, GtkStyleClass.sizeof); - - // see gtk_frame_size_allocate() - trim.left = trim.right = frame.border_width + styleClass.xthickness; - trim.top = frame.border_width + Math.max(frame.label_height, styleClass.ythickness); - trim.bottom = frame.border_width + styleClass.ythickness; - - // clean up - OS.gtk_widget_destroy(testHandle); - OS.gtk_widget_destroy(testWindowHandle); - return trim; -} - -boolean _setSize(int width, int height) { - boolean differentExtent = UtilFuncs.setSize (topHandle(), width,height); - Point clientSize = UtilFuncs.getSize(frameHandle); - // WRONG but it's quite safe - the frame clips it - UtilFuncs.setSize (handle, clientSize.x, clientSize.y); - return differentExtent; -} -/* ========= Model Logic ========= */ - -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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return text; -} - - -/** - * 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. - * - * @param text the new text - * - * @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> - */ -public void setText (String string) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - OS.gtk_frame_set_label (frameHandle, string2bytesConvertMnemonic(string)); - text=string; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/GtkFileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/GtkFileDialog.java deleted file mode 100644 index 1cfabc222b..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/GtkFileDialog.java +++ /dev/null @@ -1,150 +0,0 @@ -package org.eclipse.swt.widgets; - -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.gtk.*; - -abstract class GtkFileDialog extends Dialog { - - String answer; - int handle, okButtonHandle, cancelButtonHandle; - char separator = System.getProperty ("file.separator").charAt (0); - -GtkFileDialog (Shell parent, int style) { - super (parent, style); -} - -/** - * Actually create the GtkFileSelection dialog widget. - * Set the correct title. - * Get the pointers to the buttons. - */ -void createGtkDialog() { - /* create */ - byte [] titleBytes = Converter.wcsToMbcs (null, title, true); - handle = OS.gtk_file_selection_new (titleBytes); - - /* buttons */ - GtkFileSelection dialog = new GtkFileSelection (); - OS.memmove (dialog, handle, GtkFileSelection.sizeof); - okButtonHandle = dialog.ok_button; - cancelButtonHandle = dialog.cancel_button; -} - -/** - * Deals with the filter. - */ -void setUpFilter() { - /* - // 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 (); - byte [] fullPathBytes = Converter.wcsToMbcs (null, fullPath, true); - OS.gtk_file_selection_set_filename (handle, fullPathBytes); - - // Set the extension - if (filterNames == null) filterNames = new String [0]; - if (filterExtensions == null) filterExtensions = new String [0]; - if (filterExtensions.length == 1) { - String ext = filterExtensions [0]; - byte [] extBytes = Converter.wcsToMbcs (null, ext, true); - OS.gtk_file_selection_complete (handle, extBytes); - } - */ -} - - -/** - * 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 () { - createGtkDialog(); - setUpFilter(); - - /* Hook callbacks */ - Callback destroyCallback = new Callback (this, "destroyFunc", 2); - int destroyFunc = destroyCallback.getAddress (); - byte [] destroy = Converter.wcsToMbcs (null, "destroy", true); - OS.gtk_signal_connect (handle, destroy, destroyFunc, handle); - byte [] clicked = Converter.wcsToMbcs (null, "clicked", true); - Callback okCallback = new Callback (this, "okFunc", 2); - int okFunc = okCallback.getAddress (); - Callback cancelCallback = new Callback (this, "cancelFunc", 2); - int cancelFunc = cancelCallback.getAddress (); - OS.gtk_signal_connect (okButtonHandle, clicked, okFunc, handle); - OS.gtk_signal_connect (cancelButtonHandle, clicked, cancelFunc, handle); - - /* Show the dialog */ - answer = null; - OS.gtk_widget_show_now (handle); - OS.gtk_main (); - - destroyCallback.dispose (); - okCallback.dispose (); - cancelCallback.dispose (); - return answer; -} - -abstract boolean getAnswer(); - -String getFileNameFromOS() { - int lpFilename = OS.gtk_file_selection_get_filename (handle); - int filenameLength = OS.strlen (lpFilename); - byte [] filenameBytes = new byte [filenameLength]; - OS.memmove (filenameBytes, lpFilename, filenameLength); - return new String (Converter.mbcsToWcs (null, filenameBytes)); -} - -int calculateLastSeparatorIndex(String x) { - int separatorIndex = x.indexOf (separator); - int index = separatorIndex; - while (index != -1) { - separatorIndex = index; - index = x.indexOf (separator, index + 1); - } - return separatorIndex; -} - - -/* - * The callback functions. - */ -int okFunc (int widget, int callData) { - if (getAnswer()) OS.gtk_widget_destroy (callData); - return 0; -} -int cancelFunc (int widget, int callData) { - answer = null; - OS.gtk_widget_destroy (callData); - return 0; -} -int destroyFunc (int widget, int callData) { - OS.gtk_main_quit (); - return 0; -} - -} - diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Label.java deleted file mode 100644 index 84f872b4a8..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Label.java +++ /dev/null @@ -1,365 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>SEPARATOR, HORIZONTAL, SHADOW_IN, SHADOW_OUT, VERTICAL</dd> - * <dd>CENTER, LEFT, RIGHT, WRAP</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> - */ - -public class Label extends Control { - int boxHandle, frameHandle; - 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 Label (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -static int checkStyle (int style) { - if ((style & SWT.SEPARATOR) != 0) return style; - return checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0); -} - -void createHandle (int index) { - state |= HANDLE; - - boxHandle = OS.gtk_event_box_new (); - if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES); - - frameHandle = OS.gtk_frame_new(null); - if (frameHandle == 0) error (SWT.ERROR_NO_HANDLES); - - handle = ((style&SWT.SEPARATOR) != 0)? (((style&SWT.HORIZONTAL)!= 0)? - OS.gtk_hseparator_new() : OS.gtk_vseparator_new()): - OS.gtk_label_new (new byte [1]); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); -} - -void createWidget (int index) { - super.createWidget (index); - text = ""; -} - -void setHandleStyle () { - int type = (style & SWT.BORDER) != 0 ? OS.GTK_SHADOW_ETCHED_IN : OS.GTK_SHADOW_NONE; - OS.gtk_frame_set_shadow_type (frameHandle, type); - if ((style & SWT.SEPARATOR) != 0) return; - if ((style & SWT.WRAP) != 0) OS.gtk_label_set_line_wrap (handle, true); - if ((style & SWT.LEFT) != 0) { - OS.gtk_misc_set_alignment (handle, 0.0f, 0.0f); - OS.gtk_label_set_justify (handle, OS.GTK_JUSTIFY_LEFT); - return; - } - if ((style & SWT.CENTER) != 0) { - OS.gtk_misc_set_alignment (handle, 0.5f, 0.0f); - OS.gtk_label_set_justify (handle, OS.GTK_JUSTIFY_CENTER); - return; - } - if ((style & SWT.RIGHT) != 0) { - OS.gtk_misc_set_alignment (handle, 1.0f, 0.0f); - OS.gtk_label_set_justify (handle, OS.GTK_JUSTIFY_RIGHT); - return; - } -} - -void configure() { - _connectParent(); - OS.gtk_container_add(boxHandle, frameHandle); - OS.gtk_container_add(frameHandle, handle); -} - -void showHandle() { - OS.gtk_widget_show (boxHandle); - OS.gtk_widget_show (frameHandle); - OS.gtk_widget_show (handle); - OS.gtk_widget_realize (handle); -} - -void register () { - super.register (); - WidgetTable.put (boxHandle, this); - WidgetTable.put (frameHandle, this); -} - -void deregister () { - super.deregister (); - WidgetTable.remove (boxHandle); - WidgetTable.remove (frameHandle); -} - -int eventHandle () { - return boxHandle; -} - -void releaseWidget () { - super.releaseWidget (); - image = null; - text = null; -} - -void releaseHandle () { - super.releaseHandle (); - boxHandle = frameHandle = 0; -} - -int topHandle () { - return boxHandle; -} - -int computeHandle () { - return frameHandle; -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - if ((style&SWT.SEPARATOR) != 0) { - int w, h; - if ((style&SWT.HORIZONTAL)!= 0) { - w = 45; - h = 6; - } else { // vertical - w = 6; - h = 45; - } - if (wHint != SWT.DEFAULT) w = wHint; - if (hHint != SWT.DEFAULT) h = hHint; - return new Point(w,h); - } - return super.computeSize(wHint, hHint, changed); -} - -/** - * 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; -} - -/** - * 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; -} - -/** - * 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); - boolean isText = OS.GTK_WIDGET_TYPE (handle) == OS.gtk_label_get_type (); - if ((style & SWT.LEFT) != 0) { - OS.gtk_misc_set_alignment (handle, 0.0f, 0.0f); - if (isText) OS.gtk_label_set_justify (handle, OS.GTK_JUSTIFY_LEFT); - return; - } - if ((style & SWT.CENTER) != 0) { - OS.gtk_misc_set_alignment (handle, 0.5f, 0.0f); - if (isText) OS.gtk_label_set_justify (handle, OS.GTK_JUSTIFY_CENTER); - return; - } - if ((style & SWT.RIGHT) != 0) { - OS.gtk_misc_set_alignment (handle, 1.0f, 0.0f); - if (isText) OS.gtk_label_set_justify (handle, OS.GTK_JUSTIFY_RIGHT); - return; - } -} - -/** - * 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 (); - this.image = image; - if ((style & SWT.SEPARATOR) != 0) return; - //NOT IMPLEMENTED - events and state of handle lost - WidgetTable.remove (handle); - OS.gtk_widget_destroy (handle); - if (image == null) { - handle = OS.gtk_label_new (new byte [1]); - } else { - handle = OS.gtk_pixmap_new (image.pixmap, image.mask); - } - OS.gtk_container_add (frameHandle, handle); - WidgetTable.put (handle, this); - int alignment = style & (SWT.LEFT | SWT.RIGHT | SWT.CENTER); - switch (alignment) { - case SWT.LEFT: OS.gtk_misc_set_alignment (handle, 0.0f, 0.0f); break; - case SWT.CENTER: OS.gtk_misc_set_alignment (handle, 0.5f, 0.0f); break; - case SWT.RIGHT: OS.gtk_misc_set_alignment (handle, 1.0f, 0.0f); break; - } - OS.gtk_widget_show (handle); -} - -/** - * Sets the receiver's text. - * <p> - * This method sets the widget label. The label may include - * the mnemonic characters and line delimiters. - * </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; - boolean isText = OS.GTK_WIDGET_TYPE (handle) == OS.gtk_label_get_type (); - if (!isText) { - //NOT IMPLEMENTED - events and state of handle lost - WidgetTable.remove (handle); - OS.gtk_widget_destroy (handle); - handle = OS.gtk_label_new (new byte [1]); - OS.gtk_container_add (frameHandle, handle); - WidgetTable.put (handle, this); - int alignment = style & (SWT.LEFT | SWT.RIGHT | SWT.CENTER); - switch (alignment) { - case SWT.LEFT: - OS.gtk_misc_set_alignment (handle, 0.0f, 0.0f); - OS.gtk_label_set_justify (handle, OS.GTK_JUSTIFY_LEFT); - break; - case SWT.CENTER: - OS.gtk_misc_set_alignment (handle, 0.5f, 0.0f); - OS.gtk_label_set_justify (handle, OS.GTK_JUSTIFY_CENTER); - break; - case SWT.RIGHT: - OS.gtk_misc_set_alignment (handle, 1.0f, 0.0f); - OS.gtk_label_set_justify (handle, OS.GTK_JUSTIFY_RIGHT); - break; - } - } - OS.gtk_label_parse_uline (handle, string2bytesConvertMnemonic(string)); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/List.java deleted file mode 100644 index 053ba6cc28..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/List.java +++ /dev/null @@ -1,1138 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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 notificiation - * when a string 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> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */ - -public class List extends Scrollable { - boolean selected; - -/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 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> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</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 ptr = OS.g_malloc (buffer.length); - OS.memmove (ptr, buffer, buffer.length); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - int result = OS.gtk_clist_append (handle, new int [] {ptr}); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); - OS.g_free (ptr); -} - -/** - * 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> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li> - * </ul> - * - * @see #add(String) - */ -public void add (String string, int index) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if (index == -1) error (SWT.ERROR_ITEM_NOT_ADDED); - byte [] buffer = Converter.wcsToMbcs (null, string, true); - int ptr = OS.g_malloc (buffer.length); - OS.memmove (ptr, buffer, buffer.length); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - int result = OS.gtk_clist_insert (handle, index, new int [] {ptr}); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); - OS.g_free (ptr); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's selection changes, 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 - * - * @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; - scrolledHandle = OS.gtk_scrolled_window_new (0, 0); - if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES); - handle = OS.gtk_clist_new (1); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); -} - -void setHandleStyle() { - int selectionMode = ((style & SWT.MULTI) != 0)? - OS.GTK_SELECTION_EXTENDED : - OS.GTK_SELECTION_BROWSE; - OS.gtk_clist_set_selection_mode (handle, selectionMode); - - int border = OS.GTK_SHADOW_NONE; - if ((style&SWT.BORDER)!=0) { - border = OS.GTK_SHADOW_ETCHED_IN; - if ((style&SWT.SHADOW_IN)!=0) border = OS.GTK_SHADOW_IN; - if ((style&SWT.SHADOW_OUT)!=0) border = OS.GTK_SHADOW_OUT; - if ((style&SWT.SHADOW_ETCHED_IN)!=0) border = OS.GTK_SHADOW_ETCHED_IN; - if ((style&SWT.SHADOW_ETCHED_OUT)!=0) border = OS.GTK_SHADOW_ETCHED_OUT; - } - OS.gtk_clist_set_shadow_type(handle, border); - setScrollingPolicy(); -} - -void configure() { - _connectParent(); - OS.gtk_container_add (scrolledHandle, handle); -} - -void hookEvents () { - //TO DO - get rid of enter/exit for mouse crossing border - super.hookEvents(); - signal_connect (handle, "select_row", SWT.Selection, 5); - signal_connect (handle, "unselect_row", SWT.Selection, 5); -} - -void showHandle() { - OS.gtk_widget_show (scrolledHandle); - OS.gtk_widget_show (handle); - OS.gtk_widget_realize (handle); -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - if (wHint == SWT.DEFAULT) wHint = 200; - return super.computeSize (wHint, hHint, changed); -} - -/** - * 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(); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_clist_unselect_row (handle, index, 0); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * 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(); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - for (int i=start; i<=end; i++) { - OS.gtk_clist_unselect_row (handle, i, 0); - } - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * 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 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> - */ -public void deselect (int [] indices) { - checkWidget(); - if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - for (int i=0; i<indices.length; i++) { - OS.gtk_clist_unselect_row (handle, indices [i], 0); - } - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * Deselects all selected items in the receiver. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void deselectAll () { - checkWidget(); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_clist_unselect_all (handle); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * Returns the zero-relative index of the item which is currently - * has the focus in the receiver, or -1 if no item is 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(); - GtkCList clist = new GtkCList(); - OS.memmove(clist, handle, GtkCList.sizeof); - return clist.focus_row; -} - -/** - * 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> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li> - * </ul> - */ -public String getItem (int index) { - checkWidget(); - int [] buffer = new int [1]; - int result = OS.gtk_clist_get_text (handle, index, 0, buffer); - int length = OS.strlen (buffer [0]); - byte [] buffer1 = new byte [length]; - OS.memmove (buffer1, buffer [0], length); - char [] buffer2 = Converter.mbcsToWcs (null, buffer1); - return new String (buffer2, 0, buffer2.length); -} - -/** - * 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> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li> - * </ul> - */ -public int getItemCount () { - checkWidget(); - GtkCList widget = new GtkCList (); - OS.memmove (widget, handle, GtkCList.sizeof); - return widget.rows; -} - -/** - * 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> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</li> - * </ul> - */ -public int getItemHeight () { - checkWidget(); - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); - return clist.row_height; -} - -/** - * Returns an 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> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</li> - * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure while getting the item count</li> - * </ul> - */ -public String [] getItems () { - checkWidget(); - int count = getItemCount (); - String [] result = new String [count]; - for (int i=0; i<count; i++) result [i] = getItem (i); - return result; -} - -/** - * Returns an array of <code>String</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> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure while getting the selection</li> - * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</li> - * </ul> - */ -public String [] getSelection () { - checkWidget(); - GtkCList widget = new GtkCList (); - OS.memmove (widget, handle, GtkCList.sizeof); - int list = widget.selection; - if (list==0) return new String[0]; - int length = OS.g_list_length (list); - String [] items = new String [length]; - int [] buffer = new int [1]; - for (int i=0; i<length; i++) { - int index = OS.g_list_nth_data (list, i); - int result = OS.gtk_clist_get_text (handle, index, 0, buffer); - int strlen = OS.strlen (buffer [0]); - byte [] buffer1 = new byte [strlen]; - OS.memmove (buffer1, buffer [0], strlen); - char [] buffer2 = Converter.mbcsToWcs (null, buffer1); - items [i] = new String (buffer2, 0, buffer2.length); - } - return items; -} - -/** - * 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> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li> - * </ul> - */ -public int getSelectionCount () { - checkWidget(); - GtkCList widget = new GtkCList (); - OS.memmove (widget, handle, GtkCList.sizeof); - return OS.g_list_length (widget.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> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure</li> - * </ul> - */ -public int getSelectionIndex () { - checkWidget(); - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); - int list = clist.selection; - if (OS.g_list_length (list) == 0) return -1; - return OS.g_list_nth_data (list, 0); -} - -/** - * Returns the zero-relative indices of the items which are currently - * selected in the receiver. 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> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_SELECTION - if the operation fails because of an operating system failure</li> - * </ul> - */ -public int [] getSelectionIndices () { - checkWidget(); - GtkCList widget = new GtkCList (); - OS.memmove (widget, handle, GtkCList.sizeof); - int list = widget.selection; - int length = OS.g_list_length (list); - int [] indices = new int [length]; - for (int i=0; i<length; i++) { - indices [i] = OS.g_list_nth_data (list, i); - } - return indices; -} - -/** - * 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(); - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); - return -clist.voffset / (clist.row_height + 1); -} - -/** - * 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 - * @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> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure while getting the item count</li> - * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure while getting an item</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 visibility 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(); - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); - int list = clist.selection; - if (list == 0) return false; - int length = OS.g_list_length (list); - for (int i=0; i<length; i++) { - if (index == OS.g_list_nth_data (list, i)) return true; - } - return false; -} - -int processMouseDown (int callData, int arg1, int int2) { - if ((style & SWT.MULTI) != 0) selected = true; - return super.processMouseDown (callData, arg1, int2); -} - -int processMouseUp (int callData, int arg1, int int2) { - int result = super.processMouseUp (callData, arg1, int2); - if ((style & SWT.MULTI) != 0) { - /* - * Feature in GTK. When an item is reselected, GTK - * does not issue notification. The fix is to detect - * that the mouse was released over a selected item when - * no selection signal was set and issue a fake selection - * event. - */ - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, callData, GdkEventButton.sizeof); - int x = (int) gdkEvent.x, y = (int) gdkEvent.y; - int [] row = new int [1], column = new int [1]; - int code = OS.gtk_clist_get_selection_info (handle, x, y, row, column); - if (code != 0) { - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); - if (selected && clist.selection != 0) { - int list = clist.selection; - int length = OS.g_list_length (list); - for (int i=0; i<length; i++) { - if (row [0] == OS.g_list_nth_data (list, i)) { - postEvent (SWT.Selection); - } - } - } - } - selected = false; - } - return result; -} - -int processSelection (int int0, int int1, int int2) { - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); - if (int0 != clist.focus_row) return 0; - if ((style & SWT.MULTI) != 0) selected = false; - boolean single = true; - if (int2 != 0) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, int2, GdkEventButton.sizeof); - single = gdkEvent.type != OS.GDK_2BUTTON_PRESS; - } - if (single) { - postEvent (SWT.Selection); - } else { - postEvent (SWT.DefaultSelection); - } - return 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> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void remove (int index) { - checkWidget(); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_clist_remove (handle, index); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * 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> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void remove (int start, int end) { - checkWidget(); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - int index = start; - while (index <= end) { - OS.gtk_clist_remove (handle, start); - index++; - } - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * 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> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void remove (String string) { - checkWidget(); - int index = indexOf (string, 0); - if (index == -1) error (SWT.ERROR_ITEM_NOT_REMOVED); - 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> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void remove (int [] indices) { - checkWidget(); - if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); - int [] newIndices = new int [indices.length]; - System.arraycopy (indices, 0, newIndices, 0, indices.length); - sort (newIndices); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - int last = -1; - for (int i=0; i<newIndices.length; i++) { - int index = newIndices [i]; - if (index != last || i == 0) { - OS.gtk_clist_remove (handle, index); - last = index; - } - } - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * Removes all of the items from the receiver. - * <p> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void removeAll () { - checkWidget(); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_clist_clear (handle); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's selection changes. - * - * @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(); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_clist_select_row (handle, index, 0); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * Selects the items at the given zero-relative indices in the receiver. - * If the item at the index was already selected, it remains - * selected. The range of the indices is inclusive. Indices that are - * out of range 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> - */ -public void select (int start, int end) { - checkWidget(); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - for (int i=start; i<=end; i++) { - OS.gtk_clist_select_row (handle, i, 0); - } - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * Selects the items at the given zero-relative indices in the receiver. - * If the item at the given zero-relative index in the receiver - * is not selected, it is selected. If the item at the index - * was selected, it remains selected. Indices that are out - * of range and duplicate indices are ignored. - * - * @param indices the array of indices for the items to select - * - * @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> - */ -public void select (int [] indices) { - checkWidget(); - if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - for (int i=0; i<indices.length; i++) { - OS.gtk_clist_select_row (handle, indices [i], 0); - } - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * Selects all 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 void selectAll () { - checkWidget(); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_clist_select_all (handle); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * Sets the text of the item in the receiver's list at the given - * zero-relative index to the string argument. This is equivalent - * to <code>remove</code>'ing the old item at the index, and then - * <code>add</code>'ing the new item at that index. - * - * @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> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the remove operation fails because of an operating system failure</li> - * <li>ERROR_ITEM_NOT_ADDED - if the add operation fails because of an operating system failure</li> - * </ul> - */ -public void setItem (int index, String string) { - checkWidget(); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - byte [] buffer = Converter.wcsToMbcs (null, string, true); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_clist_set_text (handle, index, 0, buffer); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * Sets the receiver's items to be the given array of items. - * - * @param items the array 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> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void setItems (String [] items) { - checkWidget(); - if (items == null) error (SWT.ERROR_NULL_ARGUMENT); - removeAll (); - for (int i=0; i<items.length; i++) { - add (items [i]); - } -} - -/** - * 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 selected 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> - * @see List#deselectAll() - * @see List#select(int) - */ -public void setSelection (int index) { - checkWidget(); - if ((style & SWT.MULTI) != 0) deselectAll (); - select (index); - showSelection (); -} - -/** - * Selects the items at the given zero-relative indices in the receiver. - * The current selected if first cleared, then the new items are selected. - * - * @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(); - if ((style & SWT.MULTI) != 0) deselectAll (); - select (start, end); - showSelection (); -} - -/** - * Selects the items at the given zero-relative indices in the receiver. - * The current selection is first cleared, then the new items are selected. - * - * @param indices the indices of the items to select - * - * @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 List#deselectAll() - * @see List#select(int[]) - */ -public void setSelection(int[] indices) { - checkWidget(); - if ((style & SWT.MULTI) != 0) deselectAll (); - select (indices); - showSelection (); -} - -/** - * 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 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 List#deselectAll() - * @see List#select(int) - */ -public void setSelection (String [] items) { - checkWidget(); - if (items == null) error (SWT.ERROR_NULL_ARGUMENT); - if ((style & SWT.MULTI) != 0) deselectAll (); - for (int i=items.length-1; i>=0; --i) { - int index = 0; - String string = items [i]; - if (string != null) { - while ((index = indexOf (string, index)) != -1) { - select (index); - if (((style & SWT.SINGLE) != 0) && isSelected (index)) { - showSelection (); - return; - } - index++; - } - } - } - if ((style & SWT.SINGLE) != 0) deselectAll (); - 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(); - //BUG IN GTK - doesn't scroll correctly before shell open - OS.gtk_clist_moveto (handle, index, 0, 0.0f, 0.0f); -} - -/** - * 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 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> - */ -public void showSelection () { - checkWidget(); - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); - int list = clist.selection; - if (OS.g_list_length (list) == 0) return; - int index = OS.g_list_nth_data (list, 0); - int visibility = OS.gtk_clist_row_is_visible (handle, index); - if (visibility == OS.GTK_VISIBILITY_FULL) return; - //BUG IN GTK - doesn't scroll correctly before shell open - OS.gtk_clist_moveto (handle, index, 0, 0.5f, 0.0f); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Menu.java deleted file mode 100644 index 7a77f50dc2..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Menu.java +++ /dev/null @@ -1,563 +0,0 @@ -package org.eclipse.swt.widgets;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-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 user interface objects that contain - * menu items. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>BAR, DROP_DOWN, POP_UP</dd> - * <dt><b>Events:</b></dt> - * <dd>Help, Hide, Show </dd> - * </dl> - * <p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */
-
-public class Menu extends Widget {
- MenuItem cascade;
- Decorations parent;
-/**
-* Creates a new instance of the widget.
-*/
-public Menu (Control parent) {
- this (parent.getShell (), SWT.POP_UP);
-}
-/**
-* Creates a new instance of the widget.
-*/
-public Menu (Decorations parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (0);
-}
-/**
-* Creates a new instance of the widget.
-*/
-public Menu (Menu parentMenu) {
- this (parentMenu.parent, SWT.DROP_DOWN);
-}
-/**
-* Creates a new instance of the widget.
-*/
-public Menu (MenuItem parentItem) {
- this (parentItem.parent);
-}
-/** - * 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>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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-
-static int checkStyle (int style) {
- return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0);
-}
-void createHandle (int index) {
- state |= HANDLE;
- if ((style & SWT.BAR) != 0) {
- handle = OS.gtk_menu_bar_new ();
- OS.gtk_widget_show (handle);
- } else {
- handle = OS.gtk_menu_new ();
- }
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-
-void createWidget (int index) {
- super.createWidget (index);
- parent.add (this);
-}
-
-/** - * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return null;
-}
-public Display getDisplay () {
- Decorations parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-/** - * 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> - */
-public boolean getEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- GtkWidget widget = new GtkWidget ();
- OS.memmove (widget, handle, GtkWidget.sizeof);
- return (widget.flags & OS.GTK_SENSITIVE) != 0;
-}
-/** - * Returns the item at the given, zero-relative index in the - * receiver. Throws an exception if the index is out of range. - * - * @param index the index of the item to return - * @return the item at the given index - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */
-public MenuItem getItem (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int list = OS.gtk_container_children (handle);
- int data = OS.g_list_nth_data (list, index);
- if (data == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- return (MenuItem) WidgetTable.get (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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int list = OS.gtk_container_children (handle);
- return OS.g_list_length (list);
-}
-/** - * Returns an 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int list = OS.gtk_container_children (handle);
- int count = OS.g_list_length (list);
- MenuItem [] items = new MenuItem [count];
- for (int i=0; i<count; i++) {
- int data = OS.g_list_nth_data (list, i);
- items [i] = (MenuItem) WidgetTable.get (data);
- }
- return items;
-}
-/** - * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- GtkWidget widget = new GtkWidget ();
- OS.memmove (widget, handle, GtkWidget.sizeof);
- return (widget.flags & OS.GTK_MAPPED) != 0;
-}
-/** - * Searches the receiver's list starting at the first item - * (index 0) until an item is found that is equal to the - * argument, and returns the index of that item. If no item - * is found, returns -1. - * - * @param item the search item - * @return the index of the item - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if the 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 (MenuItem item) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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 - * <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> - */
-public boolean isEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return getEnabled () && getParent ().getEnabled ();
-}
-/** - * 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 isVisible () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return getVisible ();
-}
-void releaseChild () {
- super.releaseChild ();
- if (cascade != null) cascade.setMenu (null);
- if ((style & SWT.BAR) != 0 && this == parent.menuBar) {
- parent.setMenuBar (null);
- }
-}
-void releaseWidget () {
- MenuItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- MenuItem item = items [i];
- if (!item.isDisposed ()) {
- item.releaseWidget ();
- item.releaseHandle ();
- }
- }
- if (parent != null) parent.remove (this);
- super.releaseWidget ();
- parent = null;
- cascade = 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 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Hide, listener);
- eventTable.unhook (SWT.Show, 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 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-
-/** - * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-}
-/** - * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- OS.gtk_widget_set_sensitive (handle, enabled);
-}
-
-/** - * Sets the receiver's location to the point specified by - * the arguments which are relative to the display. - * <p> - * Note: 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
-// OS.gtk_widget_set_uposition(handle, x, y);
-// OS.gtk_widget_set_uposition(handle, 0, 0);
- sendEvent(SWT.Move);
-}
-
-/** - * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((style & SWT.BAR) != 0) return;
- if (visible) {
- sendEvent(SWT.Show);
- OS.gtk_menu_popup (handle, 0, 0, 0, 0, 3, 0);
- } else {
- OS.gtk_menu_popdown (handle);
- sendEvent(SWT.Hide);
- }
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/MenuItem.java deleted file mode 100644 index 1de7188b22..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/MenuItem.java +++ /dev/null @@ -1,631 +0,0 @@ -package org.eclipse.swt.widgets;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-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> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */
-
-public class MenuItem extends Item {
- Menu parent, menu;
- 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 index to store the receiver in its parent - * - * @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 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_ITEM_NOT_ADDED);
- }
- createWidget (index);
-}
-void addAccelerator (int accel_group) {
- if (accel_group == 0) return;
- if (accelerator == 0) return;
- byte [] activate = Converter.wcsToMbcs (null, "activate", true);
- int mask = 0;
- if ((accelerator & SWT.CONTROL) != 0) mask |= OS.GDK_CONTROL_MASK;
- if ((accelerator & SWT.ALT) != 0) mask |= OS.GDK_MOD1_MASK;
- if ((accelerator & SWT.SHIFT) != 0) mask |= OS.GDK_SHIFT_MASK;
- int keysym = accelerator & ~(SWT.ALT | SWT.SHIFT | SWT.CTRL);
- int newKey = Display.untranslateKey (keysym);
- if (newKey != 0) {
- keysym = newKey;
- } else {
- keysym = wcsToMbcs ((char) keysym);
- }
- OS.gtk_widget_add_accelerator (handle, activate, accel_group, keysym, mask, OS.GTK_ACCEL_VISIBLE);
-}
-/** - * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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 control is selected, 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
- *
- * @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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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);
-}
-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_menu_item_new ();
- break;
- case SWT.RADIO:
-// handle = OS.gtk_radio_menu_item_new_with_label (0, buffer);
-// break;
- case SWT.CHECK:
- handle = OS.gtk_check_menu_item_new_with_label (buffer);
- break;
- case SWT.PUSH:
- default:
- handle = OS.gtk_menu_item_new_with_label (buffer);
- break;
- }
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- OS.gtk_check_menu_item_set_show_toggle (handle, true);
- }
- if ((parent.style & SWT.BAR) != 0) {
- OS.gtk_menu_bar_insert (parent.handle, handle, index);
- } else {
- OS.gtk_menu_insert (parent.handle, handle, index);
- }
- OS.gtk_widget_show (handle);
-}
-/** - * Return 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>. - * - * @return the accelerator - * - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return accelerator;
-}
-public Display getDisplay () {
- Menu parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-/** - * 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> - */
-public boolean getEnabled () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- GtkWidget widget = new GtkWidget ();
- OS.memmove (widget, handle, GtkWidget.sizeof);
- return (widget.flags & OS.GTK_SENSITIVE) != 0;
-}
-/** - * Returns the receiver's cascade menu if it has one or null - * if it does not. Only <code>CASCADE</code> menu items can have - * a pull down menu. The sequence of key strokes, button presses - * and/or button releases that are used to request a pull down - * menu is platform specific. - * - * @return the receiver's menu - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */
-public Menu getMenu () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return menu;
-}
-/** - * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) 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. - * - * @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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
- GtkCheckMenuItem menuItem = new GtkCheckMenuItem ();
- OS.memmove (menuItem, handle, GtkCheckMenuItem.sizeof);
- return menuItem.active != 0;
-}
-void hookEvents () {
- super.hookEvents ();
- Display display = getDisplay ();
- int windowProc2 = display.windowProc2;
- byte [] activate_event = Converter.wcsToMbcs (null, "activate", true);
- OS.gtk_signal_connect (handle, activate_event, windowProc2, SWT.Selection);
-}
-/** - * 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> - */
-public boolean isEnabled () {
- return getEnabled ();
-}
-int processSelection (int int0, int int1, int int2) {
- postEvent (SWT.Selection);
- return 0;
-}
-void releaseChild () {
- super.releaseChild ();
- if (menu != null) menu.dispose ();
- menu = null;
-}
-void releaseWidget () {
- if (menu != null) {
- menu.releaseWidget ();
- menu.releaseHandle ();
- }
- menu = null;
- super.releaseWidget ();
- int accel_group = parent.getShell ().accelGroup;
- removeAccelerator (accel_group);
- accelerator = 0;
- parent = null;
-}
-void removeAccelerator (int accel_group) {
- if (accel_group == 0) return;
- if (accelerator == 0) return;
- int mask = 0;
- if ((accelerator & SWT.CONTROL) != 0) mask |= OS.GDK_CONTROL_MASK;
- if ((accelerator & SWT.ALT) != 0) mask |= OS.GDK_MOD1_MASK;
- if ((accelerator & SWT.SHIFT) != 0) mask |= OS.GDK_SHIFT_MASK;
- int keysym = accelerator & ~(SWT.ALT | SWT.SHIFT | SWT.CTRL);
- int newKey = Display.untranslateKey (keysym);
- if (newKey != 0) {
- keysym = newKey;
- } else {
- keysym = wcsToMbcs ((char) keysym);
- }
- OS.gtk_widget_remove_accelerator (handle, accel_group, keysym, mask);
- accelerator = 0;
-}
-/** - * 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 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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. - * - * @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 #addSelectionListener - */
-public void removeSelectionListener (SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Selection, listener);
- eventTable.unhook (SWT.DefaultSelection,listener);
-}
-/** - * Sets 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>. - * - * @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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int accel_group = parent.getShell ().accelGroup;
- if (accelerator != 0) removeAccelerator (accel_group);
- this.accelerator = accelerator;
- if (accelerator != 0) addAccelerator (accel_group);
-}
-/** - * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- OS.gtk_widget_set_sensitive (handle, enabled);
-}
-
-
-
-/** - * 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. - * - * @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;
- if (oldMenu != null) {
- oldMenu.cascade = null;
- /*
- * Add a reference to the menu we are about
- * to replace or GTK will destroy it.
- */
- OS.gtk_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);
- }
-
-
-}
-/** - * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
- OS.gtk_signal_handler_block_by_data (handle, SWT.Selection);
- OS.gtk_check_menu_item_set_active (handle, selected);
- OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection);
-}
-public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- text = string;
- if ((style & SWT.ARROW) != 0) return;
- int length = string.length ();
- int index = string.indexOf('\t');
- if (index != -1) length = index;
- char [] text = new char [length + 1];
- char [] pattern = new char [length + 1];
- string.getChars (0, length, text, 0);
- int i = 0, j = 0;
- while (i < length) {
- pattern [j] = ' ';
- if (text [i] == '&') {
- i++;
- if (i < length && text [i] != '&') {
- pattern [j] = '_';
- }
- }
- text [j++] = text [i++];
- }
- while (j < i) {
- text [j] = pattern [j] = '\0';
- j++;
- }
- int list = OS.gtk_container_children (handle);
- int label = OS.g_list_nth_data (list, 0);
- byte [] buffer1 = Converter.wcsToMbcs (null, text);
- OS.gtk_label_set_text (label, buffer1);
- byte [] buffer2 = Converter.wcsToMbcs (null, pattern);
- OS.gtk_label_set_pattern (label, buffer2);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/MessageBox.java deleted file mode 100644 index ed3a745f1c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/MessageBox.java +++ /dev/null @@ -1,253 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.widgets.*; - -/** - * Instances of this class are used 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> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - */ -public class MessageBox extends Dialog { - - String message; - - // Handles - int handle; - int label; - int buttonOK, buttonCANCEL, buttonYES, buttonNO, buttonABORT, buttonRETRY, buttonIGNORE; - - int state; - -/* - * === CONSTRUCTORS === - */ - -/** - * Constructs a new instance of this class given only its - * parent. - * <p> - * Note: Currently, null can be passed in for the parent. - * This has the effect of creating the dialog on the currently active - * display if there is one. If there is no current display, the - * dialog 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_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 - * for all SWT dialog classes should include a comment which - * describes the style constants which are applicable to the class. - * </p> - * Note: Currently, null can be passed in for the parent. - * This has the effect of creating the dialog on the currently active - * display if there is one. If there is no current display, the - * dialog 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_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, int style) { - super(parent, checkStyle(style)); - checkSubclass (); -} - - - -/* - * === GET/SET MESSAGE; OPEN === - */ - -/** - * 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; -} - -/** - * 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 - */ -public void setMessage (String string) { - 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 () { - createHandle(); - createMessage(); // includes configuring - createActionButtons(); - state=0; - Callback destroyCallback = new Callback (this, "destroyFunc", 2); - int destroyFunc = destroyCallback.getAddress (); - byte [] destroy = Converter.wcsToMbcs (null, "delete_event", true); - OS.gtk_signal_connect_after (handle, destroy, destroyFunc, handle); - showHandle(); - while(state==0) OS.gtk_main_iteration(); - OS.gtk_widget_destroy(handle); - return state; -} - -/* - * === Actual handle operations === - */ - -private void createHandle() { - handle = OS.gtk_dialog_new(); - if (handle==0) SWT.error(SWT.ERROR_NO_HANDLES); - if ((style & (SWT.PRIMARY_MODAL|SWT.APPLICATION_MODAL|SWT.SYSTEM_MODAL)) != 0) { - OS.gtk_window_set_modal(handle, true); - } -} -private void createMessage() { - byte[] bytes = Converter.wcsToMbcs (null, getMessage(), true); - label = OS.gtk_label_new (bytes); - GtkDialog dialog = new GtkDialog(); - OS.memmove (dialog, handle, GtkDialog.sizeof); - OS.gtk_box_pack_start (dialog.vbox, label, true, true, 5); // FIXME should we use container_add?? -} -private void createActionButtons() { - if ((style & SWT.OK) != 0) buttonOK = createButton("OK"); - if ((style & SWT.CANCEL) != 0) buttonCANCEL = createButton("CANCEL"); - - if ((style & SWT.YES) != 0) buttonYES = createButton("YES"); - if ((style & SWT.NO) != 0) buttonNO = createButton("NO"); - - if ((style & SWT.ABORT) != 0) buttonABORT = createButton("ABORT"); - if ((style & SWT.RETRY) != 0) buttonRETRY = createButton("RETRY"); - if ((style & SWT.IGNORE) != 0) buttonIGNORE = createButton("IGNORE"); -} -private void showHandle() { - OS.gtk_widget_show_all (handle); - - boolean hasTitle=false; - String title = getText(); - if (title!=null) if (title.length()!=0) hasTitle=true; - - int decor = 0; - if (hasTitle) decor |= OS.GDK_DECOR_TITLE; - GtkWidget widget = new GtkWidget(); - OS.memmove(widget, handle, GtkWidget.sizeof); - int gdkWindow = widget.window; - OS.gdk_window_set_decorations(gdkWindow, decor); - if (hasTitle) { - byte[] bytes = Converter.wcsToMbcs (null, title, true); - OS.gtk_window_set_title(handle, bytes); - } -} -int createButton(String buttonName) { - System.out.println("Creating button "+buttonName); - byte[] bytes = Converter.wcsToMbcs (null, buttonName, true); - int buttonHandle = OS.gtk_button_new_with_label(bytes); - GtkDialog dialog = new GtkDialog(); - OS.memmove (dialog, handle, GtkDialog.sizeof); - OS.gtk_box_pack_start (dialog.action_area, buttonHandle, true, true, 0); - hookSelection(buttonHandle); - return buttonHandle; -} -private void hookSelection(int h) { - byte [] clicked = Converter.wcsToMbcs (null, "clicked", true); - - Callback okCallback = new Callback (this, "activateFunc", 2); - int okFunc = okCallback.getAddress (); - OS.gtk_signal_connect (h, clicked, okFunc, h); - -} -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; -} -int activateFunc(int widget, int callData) { - if (widget==buttonOK) { state=SWT.OK; return 0; } - if (widget==buttonCANCEL) { state=SWT.CANCEL; return 0; } - if (widget==buttonYES) { state=SWT.YES; return 0; } - if (widget==buttonNO) { state=SWT.NO; return 0; } - if (widget==buttonABORT) { state=SWT.ABORT; return 0; } - if (widget==buttonRETRY) { state=SWT.RETRY; return 0; } - if (widget==buttonIGNORE) { state=SWT.IGNORE; return 0; } - return 0; -} -/* - * We need this because some WMs will give us a cross even when - * we specifically ask it not to. - */ -int destroyFunc(int widget, int callData) { - return 1; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ProgressBar.java deleted file mode 100644 index b5b36ce79a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ProgressBar.java +++ /dev/null @@ -1,215 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.internal.*; -import org.eclipse.swt.internal.gtk.*; -import org.eclipse.swt.graphics.*; - -/** - * Instances of the receiver represent is 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</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> - */ - -public class ProgressBar extends Control { - int min = 0, max = 100, value = 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 ProgressBar (Composite parent, int style) { - super (parent, checkStyle(style)); -} - -static int checkStyle (int style) { - return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0); -} - -void createHandle (int index) { - state |= HANDLE; - handle = OS.gtk_progress_bar_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_progress_configure (handle, value, min, max); -} - -void setHandleStyle() { - int orientation = (style & SWT.VERTICAL) != 0 ? OS.GTK_PROGRESS_TOP_TO_BOTTOM : OS.GTK_PROGRESS_LEFT_TO_RIGHT; - OS.gtk_progress_bar_set_orientation (handle, orientation); - int style = (this.style & SWT.SMOOTH) == 0 ? OS.GTK_PROGRESS_DISCRETE : OS.GTK_PROGRESS_CONTINUOUS; - OS.gtk_progress_bar_set_bar_style (handle, style); -} - -void showHandle() { - OS.gtk_widget_show (handle); - OS.gtk_widget_realize (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 max; -} - -/** - * 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 min; -} - -/** - * Returns the single <em>selection</em> 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 value; -} - -/** - * Sets the maximum value which the receiver will allow - * to be the argument which must be greater than or - * equal to zero. - * - * @param value the new maximum (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 setMaximum (int maximum) { - checkWidget (); - if (maximum < 0) return; - max = maximum; - if (value > maximum) value = maximum; - OS.gtk_progress_configure (handle, value, min, max); - /* - * 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. - */ - update (); -} - -/** - * Sets the minimum value which the receiver will allow - * to be the argument which must be greater than or - * equal to zero. - * - * @param value the new minimum (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 setMinimum (int minimum) { - checkWidget (); - if (minimum < 0) return; - if (value < minimum) value = minimum; - min = minimum; - OS.gtk_progress_configure (handle, value, min, max); - /* - * 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. - */ - update (); -} - -/** - * Sets the single <em>selection</em> 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 x) { - checkWidget (); - if (x < 0) return; - value = x; - OS.gtk_progress_configure (handle, value, min, max); - /* - * 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. - */ - update (); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Sash.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Sash.java deleted file mode 100644 index cad77f4868..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Sash.java +++ /dev/null @@ -1,333 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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 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</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection</dd> - * </dl> - * <p> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - */ -public class Sash extends Control { - boolean dragging, drawing; - int startX, startY, lastX, lastY, drawX, drawY; - int start_root_x, start_root_y; - int last_root_x, last_root_y; - int cursor; - -/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 Sash (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -void createHandle (int index) { - state |= HANDLE; - handle=OS.gtk_drawing_area_new(); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); -} - -void setHandleStyle() {} - -void showHandle() { - createCursor(); - OS.gtk_widget_show(handle); - OS.gtk_widget_realize(handle); -} - -private void createCursor() { - int cursorType = ((style&SWT.VERTICAL)!=0)? - OS.GDK_SB_H_DOUBLE_ARROW:OS.GDK_SB_V_DOUBLE_ARROW; - cursor = OS.gdk_cursor_new(cursorType); - GtkWidget widget = new GtkWidget (); - OS.memmove(widget, handle, GtkWidget.sizeof); - OS.gdk_window_set_cursor(widget.window, cursor); -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - int border = getBorderWidth (); - int width = border * 2, height = border * 2; - if ((style & SWT.HORIZONTAL) != 0) { - width += DEFAULT_WIDTH; height += 3; - } else { - width += 3; height += DEFAULT_HEIGHT; - } - if (wHint != SWT.DEFAULT) width = wHint + (border * 2); - if (hHint != SWT.DEFAULT) height = hHint + (border * 2); - return new Point (width, height); -} - - - -/** - * Adds the listener to the collection of listeners who will - * be notified when the control is selected, 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 reciever 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 - * - * @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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Selection,typedListener); - addListener (SWT.MouseDoubleClick,typedListener); -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is selected. - * - * @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 #addSelectionListener - */ -public void removeSelectionListener(SelectionListener listener) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Selection, listener); - eventTable.unhook (SWT.MouseDoubleClick,listener); -} - -int processMouseDown (int callData, int arg1, int int2) { - OS.gtk_grab_add(handle); - dragging = true; - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, callData, GdkEventButton.sizeof); - if (gdkEvent.button != 1) return 0; - startX = (int)gdkEvent.x; startY = (int)gdkEvent.y; - start_root_x=(int)gdkEvent.x_root; start_root_y=(int)gdkEvent.y_root; - drawX=startX; drawY=startY; - GtkWidget gtkwidget = new GtkWidget(); - OS.memmove(gtkwidget, handle, GtkWidget.sizeof); - int border = 0, width = gtkwidget.alloc_width+border*2, height = gtkwidget.alloc_height+border*2; - lastX = gtkwidget.alloc_x - border; lastY = gtkwidget.alloc_y - border; - Event event = new Event (); - event.detail = SWT.DRAG; - event.time = gdkEvent.time; - event.x = lastX; event.y = lastY; - event.width = width; event.height = height; - sendEvent (SWT.MouseDown, event); - return 0; -} - -int processMouseMove (int callData, int arg1, int int2) { - GdkEventMotion gdkEvent = new GdkEventMotion (); - OS.memmove (gdkEvent, callData, GdkEventMotion.sizeof); - if (!dragging) return 0; - GtkWidget gtkwidget = new GtkWidget(); - OS.memmove(gtkwidget, handle, GtkWidget.sizeof); - int border = 0, width = gtkwidget.alloc_width+border*2, height = gtkwidget.alloc_height+border*2; - int x = gtkwidget.alloc_x - border, y = gtkwidget.alloc_y - border; - Rectangle rect = parent.getClientArea(); - int parentWidth = rect.width - 2; - int parentHeight = rect.height - 2; - last_root_x=(int)gdkEvent.x_root; last_root_y=(int)gdkEvent.y_root; - int newX = lastX, newY = lastY; - if ((style & SWT.VERTICAL) != 0) { - if (last_root_x<=start_root_x) - newX = Math.min (Math.max (0, x - (start_root_x-last_root_x) - startX ), parentWidth - width); - else - newX = Math.min (Math.max (0, x + (last_root_x-start_root_x) - startX ), parentWidth - width); - } else { - if (last_root_y<=start_root_y) - newY = Math.min (Math.max (0, y - (start_root_y-last_root_y) - startY ), parentHeight - height); - else - newY = Math.min (Math.max (0, y + (last_root_y-start_root_y) - startY ), parentHeight - height); - } - if ((newX == lastX) && (newY == lastY)) return 0; - drawBand(newX, newY, width, height); - return 0; -} -int processMouseUp (int callData, int arg1, int int2) { - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, callData, GdkEventButton.sizeof); - if (gdkEvent.button != 1) return 0; - if (!dragging) return 0; - GtkWidget gtkwidget = new GtkWidget(); - OS.memmove(gtkwidget, handle, GtkWidget.sizeof); - int border = 0, width = gtkwidget.alloc_width+border*2, height = gtkwidget.alloc_height+border*2; - int x = gtkwidget.alloc_x - border, y = gtkwidget.alloc_y - border; - Rectangle rect = parent.getClientArea(); - int parentWidth = rect.width - 2; - int parentHeight = rect.height - 2; - last_root_x=(int)gdkEvent.x_root; last_root_y=(int)gdkEvent.y_root; - int newX = lastX, newY = lastY; - if ((style & SWT.VERTICAL) != 0) { - if (last_root_x<=start_root_x) - newX = Math.min (Math.max (0, x - (start_root_x-last_root_x) - startX ), parentWidth - width); - else - newX = Math.min (Math.max (0, x + (last_root_x-start_root_x) - startX ), parentWidth - width); - } else { - if (last_root_y<=start_root_y) - newY = Math.min (Math.max (0, y - (start_root_y-last_root_y) - startY ), parentHeight - height); - else - newY = Math.min (Math.max (0, y + (last_root_y-start_root_y) - startY ), parentHeight - height); - } - if ((newX == lastX) && (newY == lastY)) return 0; - - Event event = new Event (); - event.time = gdkEvent.time; - event.x = newX; event.y = newY; - event.width = width; event.height = height; - dragging = false; - drawBand(newX, newY, width, height); - drawing = false; - OS.gtk_grab_remove(handle); - sendEvent (SWT.Selection, event); - return 0; -} -/* -int processMouseEnter (int callData, int arg1, int int2) { - GdkEventMotion gdkEvent = new GdkEventMotion (); - OS.memmove (gdkEvent, callData, GdkEventMotion.sizeof); - GtkWidget gtkwidget = new GtkWidget(); - OS.memmove(gtkwidget, handle, GtkWidget.sizeof); - int border = 0, width = gtkwidget.alloc_width+border*2, height = gtkwidget.alloc_height+border*2; - lastX = gtkwidget.alloc_x - border; lastY = gtkwidget.alloc_y - border; - Event event = new Event (); - event.time = gdkEvent.time; - event.detail = SWT.DRAG; - event.x = lastX; event.y = lastY; - event.width = width; event.height = height; - Cursor arrowCursor; - if ((style & SWT.HORIZONTAL) != 0) { - arrowCursor = new Cursor(parent.getDisplay(), SWT.CURSOR_SIZENS); - } else { - arrowCursor = new Cursor(parent.getDisplay(), SWT.CURSOR_SIZEWE); - } - setCursor(arrowCursor); - sendEvent (SWT.Selection, event); - return 0; -} -*/ -int processMouseExit (int callData, int arg1, int int2) { - GdkEventMotion gdkEvent = new GdkEventMotion (); - OS.memmove (gdkEvent, callData, GdkEventMotion.sizeof); - GtkWidget gtkwidget = new GtkWidget(); - OS.memmove(gtkwidget, handle, GtkWidget.sizeof); - int border = 0, width = gtkwidget.alloc_width+border*2, height = gtkwidget.alloc_height+border*2; - Event event = new Event (); - event.time = gdkEvent.time; - event.x = lastX; event.y = lastY; - event.width = width; event.height = height; - sendEvent (SWT.MouseExit, event); - return 0; - -} - -void drawBand (int x, int y, int width, int height) { - if (x == drawX && y == drawY) return; - Display display= parent.getDisplay (); - if (display == null) return; - GtkWidget gtkwidget = new GtkWidget(); - OS.memmove(gtkwidget, parent.topHandle(), GtkWidget.sizeof); - int window = gtkwidget.window; - if (window == 0) return; - byte [] bits = {-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0}; - int stipplePixmap = OS.gdk_bitmap_create_from_data (window, bits, 8, 8); - int gc = OS.gdk_gc_new(window); - Color color = new Color(display, 0xFF, 0, 0); - OS.gdk_gc_set_background(gc, color.handle); - Color color1 = new Color(display, 0, 0xFF, 0); - OS.gdk_gc_set_foreground(gc, color1.handle); - 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); - - if (drawing) - OS.gdk_draw_rectangle(window, gc, 1, drawX, drawY, width, height); - else - drawing = true; - drawX=x;drawY=y; - OS.gdk_draw_rectangle(window, gc, 1, x, y, width, height); - OS.gdk_bitmap_unref(stipplePixmap); - OS.gdk_gc_destroy(gc); -} -static int checkStyle (int style) { - return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0); -} - -void releaseWidget () { - super.releaseWidget (); - OS.gdk_cursor_destroy (cursor); - cursor = 0; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Scale.java deleted file mode 100644 index 7baf8ad787..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Scale.java +++ /dev/null @@ -1,389 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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 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> - * IMPORTANT: This class is intended to be subclassed <em>only</em> - * within the SWT implementation. - * </p> - */ - -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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 Scale (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's value changes, by sending - * it one of the messages defined in the <code>SelectionListener</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 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); -} - -void createHandle (int index) { - state |= HANDLE; - int 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); -} - -void setHandleStyle() { - OS.gtk_scale_set_digits (handle, 0); - OS.gtk_scale_set_draw_value (handle, false); -} - -void showHandle() { - OS.gtk_widget_show (handle); - OS.gtk_widget_realize (handle); -} - -void hookEvents () { - super.hookEvents (); - int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - signal_connect (hAdjustment, "value_changed", SWT.Selection, 2); -} - -void register () { - super.register (); - int hAdjustment = OS.gtk_range_get_adjustment (handle); - WidgetTable.put (hAdjustment, this); -} - -void deregister () { - super.deregister (); - int hAdjustment = OS.gtk_range_get_adjustment (handle); - WidgetTable.remove (hAdjustment); - /* - * This code is intentionally commented. - */ -// OS.gtk_object_unref (hAdjustment); -// OS.gtk_object_destroy (hAdjustment); -} - -/** - * 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 hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - 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 hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - 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 hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - 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 hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - return (int) adjustment.page_increment; -} - -/** - * Returns the single <em>selection</em> that is the receiver's position. - * - * @return the selection - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getSelection () { - checkWidget (); - int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - return (int) adjustment.value; -} - -int processSelection (int int0, int int1, int int2) { - postEvent (SWT.Selection); - return 0; -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's value changes. - * - * @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; - int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - adjustment.step_increment = (float) value; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); - OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); - OS.gtk_adjustment_changed (hAdjustment); - OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); -} - -/** - * Sets the maximum value which the receiver will allow - * to be the argument which must be greater than or - * equal to zero. - * - * @param value the new maximum (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 setMaximum (int value) { - checkWidget (); - if (value < 0) return; - int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - adjustment.upper = (float) value; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); - OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); - OS.gtk_adjustment_changed (hAdjustment); - OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); -} - -/** - * Sets the minimum value which the receiver will allow - * to be the argument which must be greater than or - * equal to zero. - * - * @param value the new minimum (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 setMinimum (int value) { - checkWidget (); - if (value < 0) return; - int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - adjustment.lower = (float) value; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); - OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); - OS.gtk_adjustment_changed (hAdjustment); - OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); -} - -/** - * 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. - * - * @return 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 hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - adjustment.page_increment = (float) value; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); - OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); - OS.gtk_adjustment_changed (hAdjustment); - OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); -} - -/** - * 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 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(); - if (value < 0) return; - int hAdjustment = OS.gtk_range_get_adjustment (handle); - OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); - OS.gtk_adjustment_set_value (hAdjustment, value); - OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ScrollBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ScrollBar.java deleted file mode 100644 index daba64bd09..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ScrollBar.java +++ /dev/null @@ -1,639 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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 represent a range of positive, numeric values. - * <p> - * At any given moment, a given scroll bar will have a - * single <em>selection</em> 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 left and right facing buttons for incrementing and - * decrementing the value) or <code>VERTICAL</code> (which have - * up and down facing buttons for incrementing and decrementing - * the value). - * </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> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * - * @see Slider - * @see Scrollable - * @see Scrollable#getHorizontalBar - * @see Scrollable#getVerticalBar - */ - -public class ScrollBar extends Widget { - Scrollable parent; - -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 receiver's value changes, 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>0</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 - * - * @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 Display getDisplay () { - Scrollable parent = this.parent; - if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED); - return parent.getDisplay (); -} - -/** - * 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 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 boolean getEnabled () { - checkWidget (); - 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, handle, GtkAdjustment.sizeof); - 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, handle, GtkAdjustment.sizeof); - 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, handle, GtkAdjustment.sizeof); - 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, handle, GtkAdjustment.sizeof); - return (int) adjustment.page_increment; -} - -/** - * Returns the receiver's parent, which must be 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 <em>selection</em> 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, handle, GtkAdjustment.sizeof); - return (int) adjustment.value; -} - -/** - * For horizontal scroll bars, returns the height of the - * instance, and for vertical scroll bars, returns the width - * of the instance. - * - * @return the scroll bar 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 (); - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - return new Point (widget.alloc_width, widget.alloc_height); -} - -/** - * Answers 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, handle, GtkAdjustment.sizeof); - 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 (); - return true; -} - -void hookEvents () { - signal_connect (handle, "value_changed", SWT.Selection, 2); -} - -/** - * 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. - * <p> - * Note: Because of the strong connection between a scroll bar - * and the widget which contains it (its parent), a scroll bar - * will not indicate that it is enabled if its parent is not. - * </p> - * - * @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> - */ -public boolean isEnabled () { - checkWidget (); - return getEnabled () && getParent ().getEnabled (); -} - -/** - * 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 isVisible () { - checkWidget (); - return getVisible () && getParent ().isVisible (); -} - -int processSelection (int int0, int int1, int int2) { - postEvent (SWT.Selection); - return 0; -} - -void releaseChild () { - super.releaseChild (); - 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 receiver's value changes. - * - * @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 (); -} - -/** - * 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, handle, GtkAdjustment.sizeof); - adjustment.step_increment = (float) value; - OS.memmove (handle, adjustment, GtkAdjustment.sizeof); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_adjustment_changed (handle); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * Sets the maximum value which the receiver will allow - * to be the argument which must be greater than or - * equal to zero. - * - * @param value the new maximum (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 setMaximum (int value) { - checkWidget (); - if (value < 0) return; - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, handle, GtkAdjustment.sizeof); - adjustment.upper = (float) value; - OS.memmove (handle, adjustment, GtkAdjustment.sizeof); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_adjustment_changed (handle); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * Sets the minimum value which the receiver will allow - * to be the argument which must be greater than or - * equal to zero. - * - * @param value the new minimum (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 setMinimum (int value) { - checkWidget (); - if (value < 0) return; - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, handle, GtkAdjustment.sizeof); - adjustment.lower = (float) value; - OS.memmove (handle, adjustment, GtkAdjustment.sizeof); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_adjustment_changed (handle); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * 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. - * - * @return 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, handle, GtkAdjustment.sizeof); - adjustment.page_increment = (float) value; - OS.memmove (handle, adjustment, GtkAdjustment.sizeof); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_adjustment_changed (handle); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * 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 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 (); - if (value < 0) return; - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_adjustment_set_value (handle, value); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * Sets the size of the receiver's thumb relative to the - * difference between its maximum and minimum values to the - * argument which must be at least one. - * - * @param value the new thumb value (must be at least 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 ScrollBar - */ -public void setThumb (int value) { - checkWidget (); - if (value < 1) return; - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, handle, GtkAdjustment.sizeof); - adjustment.page_size = (float) value; - OS.memmove (handle, adjustment, GtkAdjustment.sizeof); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_adjustment_changed (handle); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * Sets the receiver's selection, minimum value, maximum - * value, thumb, increment and page increment all at once. - * <p> - * Note: This is equivalent 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 (selection < 0) return; - if (minimum < 0) return; - if (maximum < 0) return; - if (thumb < 1) return; - if (maximum - minimum - thumb < 0) return; - if (increment < 1) return; - if (pageIncrement < 1) return; - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, handle, GtkAdjustment.sizeof); - adjustment.lower = minimum; - adjustment.upper = maximum; - adjustment.step_increment = increment; - adjustment.page_increment = pageIncrement; - adjustment.page_size = thumb; - adjustment.value = selection; - OS.memmove (handle, adjustment, GtkAdjustment.sizeof); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_adjustment_changed (handle); - OS.gtk_adjustment_value_changed (handle); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * 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 (); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Scrollable.java deleted file mode 100644 index a2405fca32..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Scrollable.java +++ /dev/null @@ -1,239 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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> - */ - -public abstract class Scrollable extends Control { - - int scrolledHandle; - ScrollBar horizontalBar, verticalBar; - static Trim trim; - -/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 Scrollable (Composite parent, int style) { - super (parent, style); -} - -/** - * Given a desired <em>client area</em> for the receiver - * (as described by the arguments), returns the bounding - * rectangle which would be required to produce that client - * area. - * <p> - * In other words, it returns a rectangle such that, if the - * receiver's bounds were set to that rectangle, the area - * of the receiver which is capable of displaying data - * (that is, not covered by the "trimmings") would be the - * rectangle described by the arguments (relative to the - * receiver's parent). - * </p> - * - * @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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - - Trim t = _getTrim(); - return new Rectangle (x-t.left, y-t.top, width+t.left+t.right, height+t.top+t.bottom); -} - -Trim _getTrim() { - if (trim==null) initializeTrim(); - return trim; -} - -void initializeTrim() { trim = new Trim(); } - -void _fillBin(int binHandle, int childHandle) { - GtkBin bin = new GtkBin(); - OS.memmove(bin, binHandle, GtkBin.sizeof); - bin.child = childHandle; - OS.memmove(binHandle, bin, GtkBin.sizeof); - OS.gtk_widget_set_parent(childHandle, binHandle); -} - -/* - * Subclasses must only use super.configure() - * to connect their topHandle to the parent. - * It is the responsibility of the conrete subclass - * to configure the scrolled handles. - */ -abstract void configure (); - -ScrollBar createScrollBar (int style) { - if (scrolledHandle == 0) return null; - ScrollBar bar = new ScrollBar (); - bar.parent = this; - bar.style = style; - bar.state |= HANDLE; - if ((style & SWT.H_SCROLL) != 0) { - bar.handle = OS.gtk_scrolled_window_get_hadjustment (scrolledHandle); - } else { - bar.handle = OS.gtk_scrolled_window_get_vadjustment (scrolledHandle); - } - 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) { - WidgetTable.remove (scrolledHandle); - } -} -/** - * Returns a rectangle which describes the area of the - * receiver which is capable of displaying data (that is, - * not covered by the "trimmings"). - * - * @return the client area - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - * - * @see #computeTrim - */ -public Rectangle getClientArea () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - return new Rectangle (0, 0, widget.alloc_width, widget.alloc_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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return verticalBar; -} - -void setScrollingPolicy() { - if (scrolledHandle==0) return; - int hsp = ((style&SWT.H_SCROLL)==0)? OS.GTK_POLICY_NEVER : OS.GTK_POLICY_ALWAYS; - int vsp = ((style&SWT.V_SCROLL)==0)? OS.GTK_POLICY_NEVER : OS.GTK_POLICY_ALWAYS; - OS.gtk_scrolled_window_set_policy(scrolledHandle, hsp,vsp); -} - -void register () { - super.register (); - if (scrolledHandle != 0) { - WidgetTable.put (scrolledHandle, this); - } -} - -void releaseHandle () { - super.releaseHandle (); - scrolledHandle = 0; -} - -void releaseWidget () { - if (horizontalBar != null) { - horizontalBar.releaseWidget (); - horizontalBar.releaseHandle (); - } - if (verticalBar != null) { - verticalBar.releaseWidget (); - verticalBar.releaseHandle (); - } - horizontalBar = verticalBar = null; - super.releaseWidget (); -} -int topHandle () { - if (scrolledHandle != 0) return scrolledHandle; - return handle; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Shell.java deleted file mode 100644 index d93c35d2f6..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Shell.java +++ /dev/null @@ -1,851 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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> - * 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 - * 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>. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>BORDER, CLOSE, MIN, MAX, NO_TRIM, RESIZE, TITLE</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> - * IMPORTANT: This class is not intended to be subclassed. - * </p> - * - * @see Decorations - * @see SWT - */ -public class Shell extends Decorations { - Display display; - int vboxHandle; - int modal; - int accelGroup; - Rectangle lastClientArea; - boolean hasFocus; - -/* - * === CONSTRUCTORS === - */ - -/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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> - */ -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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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> - */ -public Shell (Display display, int style) { - this (display, null, style); -} -Shell (Display display, Shell parent, int style) { - super (); - 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.parent = parent; - this.display = display; - this.handle = 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_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 Shell (Shell parent) { - this (parent, SWT.TITLE | SWT.CLOSE | SWT.BORDER); -} -/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 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, int style) { - this (null, parent, style); -} - - - -/** - * 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 bringToTop () { -// OS.gtk_window_activate_focus (shellHandle); -} -/** - * 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> - */ -public void close () { - checkWidget (); - closeWidget (); -} -void closeWidget () { - Event event = new Event (); - event.time = OS.gdk_time_get (); - sendEvent (SWT.Close, event); - if (event.doit && !isDisposed ()) dispose (); -} - - -/* - * === Handle code I: The createWidget() cycle. - */ - -void createHandle (int index) { - state |= HANDLE; - topHandle = OS.gtk_window_new((parent==null)? OS.GTK_WINDOW_TOPLEVEL:OS.GTK_WINDOW_DIALOG); - if (topHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - if (parent!=null) OS.gtk_window_set_transient_for(topHandle, parent.topHandle()); - - vboxHandle = OS.gtk_vbox_new(false,0); - if (vboxHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - eventBoxHandle = OS.gtk_event_box_new (); - if (eventBoxHandle == 0) error (SWT.ERROR_NO_HANDLES); - fixedHandle = OS.gtk_fixed_new (); - if (fixedHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - handle = OS.gtk_drawing_area_new(); - if (handle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - accelGroup = OS.gtk_accel_group_new (); - OS.gtk_window_add_accel_group (topHandle, accelGroup); - OS.gtk_window_set_title (topHandle, new byte [1]); -} - -void configure () { - OS.gtk_container_add (topHandle, vboxHandle); - OS.gtk_box_pack_end(vboxHandle, eventBoxHandle, true,true,0); - OS.gtk_container_add (eventBoxHandle, fixedHandle); - OS.gtk_fixed_put(fixedHandle, handle, (short)0,(short)0); -} - -void showHandle() { - OS.gtk_widget_realize (topHandle); // careful: NOT show - _setStyle(); - - OS.gtk_widget_realize (vboxHandle); - OS.gtk_widget_show_now (vboxHandle); - - OS.gtk_widget_realize (eventBoxHandle); - OS.gtk_widget_show_now (eventBoxHandle); - - OS.gtk_widget_realize (fixedHandle); - OS.gtk_widget_show_now (fixedHandle); - - OS.gtk_widget_realize (handle); - OS.gtk_widget_show_now (handle); -} - -void hookEvents () { - super.hookEvents (); - signal_connect(topHandle, "map_event", SWT.Deiconify, 3); - signal_connect(topHandle, "unmap_event", SWT.Iconify, 3); - signal_connect(topHandle, "size_allocate", SWT.Resize, 3); - signal_connect(topHandle, "delete_event", SWT.Dispose, 3); -} - -void register () { - super.register (); - WidgetTable.put (vboxHandle, this); -} - -private void _setStyle() { - boolean modal = ( - ((style&SWT.PRIMARY_MODAL) != 0) || - ((style&SWT.APPLICATION_MODAL) != 0) || - ((style&SWT.SYSTEM_MODAL) != 0)); - OS.gtk_window_set_modal(topHandle, modal); - - 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; - /* - * 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; - } - GtkWidget widget = new GtkWidget(); - OS.memmove(widget, topHandle, GtkWidget.sizeof); - int w = widget.window; - // PANIC - this must absolutely never happen, so it's not NO_HANDLES actually - if (w == 0) error(SWT.ERROR_NO_HANDLES); - OS.gdk_window_set_decorations(w, decorations); -} - -void _connectChild (int h) { - OS.gtk_fixed_put (fixedHandle, h, (short)0, (short)0); -} - -int topHandle () { - return topHandle; -} - -int parentingHandle() { - return fixedHandle; -} - -boolean isMyHandle(int h) { - if (h == topHandle) return true; - if (h == vboxHandle) return true; - if (h == eventBoxHandle) return true; - if (h == fixedHandle) return true; - if (h == handle) return true; - return false; -} - - -/* - * === GEOMETRY === - */ - -public Point _getLocation() { - GtkWidget widget = new GtkWidget(); - OS.memmove (widget, topHandle, GtkWidget.sizeof); - int [] x = new int [1], y = new int [1]; - OS.gdk_window_get_origin(widget.window, x,y); - return new Point(x[0], y[0]); -} - -public Point _getSize() { - return UtilFuncs.getSize(vboxHandle); -} - -public Rectangle _getClientArea () { - Point clientSize = UtilFuncs.getSize(eventBoxHandle); - return new Rectangle (0, 0, clientSize.x, clientSize.y); -} - -boolean _setSize(int width, int height) { - /* - * API deficiency in GTK 1.2 - lacking gtk_window_resize. - * We work around this by directly resizing the X window. - * - * First, we find out the GDK handle. - */ - GtkWidget gtkWidget = new GtkWidget(); - OS.memmove(gtkWidget, topHandle, GtkWidget.sizeof); - - OS.gtk_signal_handler_block_by_data (topHandle, SWT.Resize); - OS.gdk_window_resize(gtkWidget.window, width, height); - UtilFuncs.setSize(vboxHandle, width, height); - Point sz = UtilFuncs.getSize(eventBoxHandle); - UtilFuncs.setSize(fixedHandle, sz.x, sz.y); - UtilFuncs.setSize(handle, sz.x, sz.y); - OS.gtk_signal_handler_unblock_by_data (topHandle, SWT.Resize); - - return true; -} - -boolean _setLocation (int x, int y) { - GtkWidget gtkWidget = new GtkWidget(); - OS.memmove(gtkWidget, topHandle, GtkWidget.sizeof); - OS.gdk_window_move(gtkWidget.window, x, y); - return true; -} - -void setInitialSize() { - int width = OS.gdk_screen_width () * 5 / 8; - int height = OS.gdk_screen_height () * 5 / 8; - _setSize(width, height); - OS.gtk_window_set_policy (topHandle, 1,1,0); -} - -/* - * We can't setInitialSize() before showHandle() in the case of Shell, - * because we operate on the actual X window, so the shell must be - * realized by that time. - * This is a workaround until gtk_window_resize(). - */ -void createWidget (int index) { - createHandle (index); - hookEvents (); - configure (); - setHandleStyle (); - register (); - showHandle (); - setInitialSize (); -} - -public Display getDisplay () { - if (display == null) error (SWT.ERROR_WIDGET_DISPOSED); - return display; -} - -/* - * Return the control inside this shell that has the focus, - * if there is one. Return <code>null</code> if there is no - * such control - e.g., this shell is not active, or it is active - * but the user clicked in a no-entry widget (like Label). - */ -Control getFocusControl() { - GtkWindow shell = new GtkWindow(); - OS.memmove(shell, topHandle, GtkWindow.sizeof); - int focusHandle = shell.focus_widget; - if (focusHandle==0) return null; - return (Control)this.getDisplay().findWidget(focusHandle); -} - -/** - * 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; -} - -/** -* Get the modal state. -* <p> -* @return the modal state -* -* @exception SWTError(ERROR_ERROR_INVALID_PARENT) -* when the parent is invalid -* @exception SWTError(ERROR_THREAD_INVALID_ACCESS) -*/ -public int getModal () { - checkWidget(); - return modal; -} - -Shell _getShell () { - return this; -} -/** - * Returns an array containing all shells which are - * descendents 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; -} - -public void layout (boolean changed) { - checkWidget(); -// if (!resizedSinceLastLayout()) return; - lastClientArea=getClientArea(); - if (layout == null) return; - layout.layout (this, changed); -} - -/* - * Returns whether the shell has been resized since the last layout() - */ -boolean resizedSinceLastLayout() { - return !getClientArea().equals(lastClientArea); -} - -/** - * 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, - * and sets focus to its default button (if it has 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 Control#setVisible - * @see Decorations#setDefaultButton -*/ -public void open () { - checkWidget(); - setVisible (true); -} - -int processDispose (int int0, int int1, int int2) { - closeWidget (); - return 1; -} - -int processFocusIn(int int0, int int1, int int2) { - hasFocus=true; - postEvent(SWT.Activate); - return 0; -} - -int processFocusOut(int int0, int int1, int int2) { - hasFocus=false; - postEvent(SWT.Deactivate); - return 0; -} - -int processPaint (int callData, int int2, int int3) { - //if (!hooks (SWT.Paint)) return 1; - - GdkEventExpose gdkEvent = new GdkEventExpose (); - OS.memmove (gdkEvent, callData, GdkEventExpose.sizeof); - Event event = new Event (); - event.count = gdkEvent.count; - event.x = gdkEvent.x; event.y = gdkEvent.y; - event.width = gdkEvent.width; event.height = gdkEvent.height; - GC gc = event.gc = new GC (this); - GdkRectangle rect = new GdkRectangle (); - rect.x = gdkEvent.x; rect.y = gdkEvent.y; - rect.width = gdkEvent.width; rect.height = gdkEvent.height; - OS.gdk_gc_set_clip_rectangle (gc.handle, rect); - gc.fillRectangle(rect.x, rect.y, rect.width, rect.height); - sendEvent (SWT.Paint, event); - gc.dispose (); - event.gc = null; - return 1; -/*}else{ - GdkRectangle gdkEvent = new GdkRectangle (); - OS.memmove (gdkEvent, callData, GdkRectangle.sizeof); - Event event = new Event (); -// event.count = gdkEvent.count; - event.x = gdkEvent.x; event.y = gdkEvent.y; - event.width = gdkEvent.width; event.height = gdkEvent.height; - GC gc = event.gc = new GC (this); - OS.gdk_gc_set_clip_rectangle (gc.handle, gdkEvent); - sendEvent (SWT.Paint, event); - gc.dispose (); - event.gc = null; - return 1; -} */ -} - -/** - * 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); -} - -/** - * 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(); -} - -public void setMaximized (boolean maximized) { - checkWidget(); - - /* - * Out of luck on curent GDK. - */ -} - -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); - } - if (menu == null) { - if (menuBar != null) { - OS.gtk_object_ref (menuBar.handle); - OS.gtk_container_remove (vboxHandle, menuBar.handle); - } - } - menuBar = menu; - if (menuBar != null) { - int menuHandle = menu.handle; - OS.gtk_box_pack_start (vboxHandle, menuHandle, false, false, 0); - } -} - -public void setMinimized (boolean minimized) { - checkWidget(); - - /* - * In GDK, there is no way to iconify a shell. - * If we wanted it really badly, on pure X this is done - * by sending a client message - see ICCCM L.4.1.4. - */ - if (minimized) return; - - /* - * At least we can force a deiconify - */ - GtkWidget w = new GtkWidget(); - OS.memmove(w, topHandle, w.sizeof); - OS.gdk_window_show(w.window); -} - -/** -* Set the modal state. -* <p> -* @param modal the new modal state -* -* @exception SWTError(ERROR_ERROR_INVALID_PARENT) -* when the parent is invalid -* @exception SWTError(ERROR_THREAD_INVALID_ACCESS) -*/ -public void setModal (int modal) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - this.modal = modal; -} - -public void setText (String string) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - super.setText (string); - byte [] buffer = Converter.wcsToMbcs (null, string, true); - OS.gtk_window_set_title (topHandle, buffer); -} -public void setVisible (boolean visible) { - checkWidget(); - if (visible) { - OS.gtk_widget_show_now (topHandle); - display.update(); - sendEvent (SWT.Show); - } else { - OS.gtk_widget_hide (topHandle); - sendEvent (SWT.Hide); - } -} - - -/* - * === DESTRUCTION === - */ - -void deregister () { - super.deregister (); - WidgetTable.remove (vboxHandle); -} - -void releaseHandle () { - super.releaseHandle (); - vboxHandle = 0; -} - -void releaseShells () { - Shell [] shells = getShells (); - for (int i=0; i<shells.length; i++) { - Shell shell = shells [i]; - if (!shell.isDisposed ()) { - shell.releaseWidget (); - shell.releaseHandle (); - } - } -} -void releaseWidget () { - releaseShells (); - super.releaseWidget (); - if (accelGroup != 0) OS.gtk_accel_group_unref (accelGroup); - accelGroup = 0; -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Slider.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Slider.java deleted file mode 100644 index 2bad93913c..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Slider.java +++ /dev/null @@ -1,539 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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 represent a range of positive, numeric values. - * <p> - * At any given moment, a given slider will have a - * single <em>selection</em> 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 left and right facing buttons for incrementing and - * decrementing the value) or <code>VERTICAL</code> (which have - * up and down facing buttons for incrementing and decrementing - * the value). - * </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> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * - * @see ScrollBar - */ - -public class Slider 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 Slider (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's value changes, 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>0</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 - * - * @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; - int 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); -} - -void setHandleStyle() {} - -void showHandle() { - OS.gtk_widget_show (handle); - OS.gtk_widget_realize (handle); -} - -void hookEvents () { - super.hookEvents (); - int hAdjustment = OS.gtk_range_get_adjustment (handle); - signal_connect (hAdjustment, "value_changed", SWT.Selection, 2); -} - -void register () { - super.register (); - int hAdjustment = OS.gtk_range_get_adjustment (handle); - WidgetTable.put (hAdjustment, this); -} - -void deregister () { - super.deregister (); - int hAdjustment = OS.gtk_range_get_adjustment (handle); - WidgetTable.remove (hAdjustment); - /* - * This code is intentionally commented. - */ -// OS.gtk_object_unref (hAdjustment); -// OS.gtk_object_destroy (hAdjustment); -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - // We are interested in the preferred size. - // The native widget gives us what it thinks the minimum reasonable - // size; we'll say we prefer to be twice that long, and exactly - // that wide. - int x,y; - Point size = super.computeSize (wHint, hHint, changed); - if (hHint==SWT.DEFAULT) { - x = size.x; - if ((style & SWT.HORIZONTAL) != 0) x = 2*x; - } else x = hHint; - if (wHint==SWT.DEFAULT) { - y = size.y; - if ((style & SWT.VERTICAL) != 0) y = 2*y; - } else y = wHint; - - return new Point(x,y); -} - -/** - * 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 hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - 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 hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - 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 hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - 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 hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - return (int) adjustment.page_increment; -} - -/** - * Returns the single <em>selection</em> that is the receiver's value. - * - * @return the selection - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getSelection () { - checkWidget (); - int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - 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 hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - return (int) adjustment.page_size; -} - -int processSelection (int int0, int int1, int int2) { - postEvent (SWT.Selection); - return 0; -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's value changes. - * - * @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; - int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - adjustment.step_increment = (float) value; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); - OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); - OS.gtk_adjustment_changed (hAdjustment); - OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); -} - -/** - * Sets the maximum value which the receiver will allow - * to be the argument which must be greater than or - * equal to zero. - * - * @param value the new maximum (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 setMaximum (int value) { - checkWidget (); - if (value < 0) return; - int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - adjustment.upper = (float) value; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); - OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); - OS.gtk_adjustment_changed (hAdjustment); - OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); -} - -/** - * Sets the minimum value which the receiver will allow - * to be the argument which must be greater than or - * equal to zero. - * - * @param value the new minimum (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 setMinimum (int value) { - checkWidget (); - if (value < 0) return; - int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - adjustment.lower = (float) value; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); - OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); - OS.gtk_adjustment_changed (hAdjustment); - OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); -} - -/** - * 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. - * - * @return 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 hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - adjustment.page_increment = (float) value; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); - OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); - OS.gtk_adjustment_changed (hAdjustment); - OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); -} - -/** - * 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 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 (); - if (value < 0) return; - int hAdjustment = OS.gtk_range_get_adjustment (handle); - OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); - OS.gtk_adjustment_set_value (hAdjustment, value); - OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); -} - -/** - * Sets the size of the receiver's thumb relative to the - * difference between its maximum and minimum values to the - * argument which must be at least one. - * - * @param value the new thumb value (must be at least 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 ScrollBar - */ -public void setThumb (int value) { - checkWidget (); - if (value < 1) return; - int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - adjustment.page_size = (float) value; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); - OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); - OS.gtk_adjustment_changed (hAdjustment); - OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); -} - -/** - * Sets the receiver's selection, minimum value, maximum - * value, thumb, increment and page increment all at once. - * <p> - * Note: This is equivalent 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 (selection < 0) return; - if (minimum < 0) return; - if (maximum < 0) return; - if (thumb < 1) return; - if (maximum - minimum - thumb < 0) return; - if (increment < 1) return; - if (pageIncrement < 1) return; - int hAdjustment = OS.gtk_range_get_adjustment (handle); - GtkAdjustment adjustment = new GtkAdjustment (); - OS.memmove (adjustment, hAdjustment, GtkAdjustment.sizeof); - adjustment.value = (float) selection; - adjustment.lower = (float) minimum; - adjustment.upper = (float) maximum; - adjustment.page_size = (float) thumb; - adjustment.step_increment = (float) increment; - adjustment.page_increment = (float) pageIncrement; - OS.memmove (hAdjustment, adjustment, GtkAdjustment.sizeof); - OS.gtk_signal_handler_block_by_data (hAdjustment, SWT.Selection); - OS.gtk_adjustment_changed (hAdjustment); - OS.gtk_adjustment_value_changed (hAdjustment); - OS.gtk_signal_handler_unblock_by_data (hAdjustment, SWT.Selection); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TabFolder.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TabFolder.java deleted file mode 100644 index 4338e7e92e..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TabFolder.java +++ /dev/null @@ -1,554 +0,0 @@ -package org.eclipse.swt.widgets;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-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>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- */
-public class TabFolder extends Composite {
- int notebookHandle;
- TabItem [] items;
-
-
-/*
- * == CONSTRUCTORS ==
- */
-
-/**
- * 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
- * for all SWT widget classes should include a comment which
- * describes the style constants which are applicable to the class.
- * </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 TabFolder (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/*
- * == HANDLE DANCES, FIRST SPECIES ==
- */
-
-void createHandle (int index) {
- state |= HANDLE;
- eventBoxHandle = OS.gtk_event_box_new();
- fixedHandle = OS.gtk_fixed_new ();
- notebookHandle = OS.gtk_notebook_new ();
- handle = OS.gtk_fixed_new();
-}
-
-void configure () {
- _connectParent();
- OS.gtk_container_add(eventBoxHandle, fixedHandle);
- OS.gtk_fixed_put (fixedHandle, notebookHandle, (short)0, (short)0);
- OS.gtk_fixed_put (fixedHandle, handle, (short)2, (short)33);
-}
-
-void showHandle() {
- OS.gtk_widget_show(eventBoxHandle);
- OS.gtk_widget_show(fixedHandle);
- OS.gtk_widget_show(notebookHandle);
- OS.gtk_widget_show(handle);
- OS.gtk_widget_realize (notebookHandle);
- OS.gtk_widget_realize (handle);
-}
-
-void register () {
- super.register ();
- WidgetTable.put (notebookHandle, this);
-}
-
-void hookEvents () {
- super.hookEvents ();
- signal_connect (notebookHandle, "size_allocate", SWT.Resize, 3);
- signal_connect (notebookHandle, "switch_page", SWT.Selection, 4);
-}
-
-void createWidget (int index) {
- super.createWidget(index);
- items = new TabItem [4];
-}
-
-int topHandle () { return eventBoxHandle; }
-int paintHandle () { return notebookHandle; }
-int parentingHandle () { return handle; }
-boolean isMyHandle(int h) {
- if (h==eventBoxHandle) return true;
- if (h==notebookHandle) return true;
- if (h==fixedHandle) return true;
- if (h==handle) return true;
- return false;
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget ();
- //notebookHandle
- int width = _computeSize(wHint, hHint, changed).x;
- int height = 0;
- Point size;
- if (layout != null) {
- size = layout.computeSize (this, wHint, hHint, changed);
- } else {
- size = minimumSize ();
- }
- 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;
- width = Math.max (width, size.x);
- height = Math.max (height, size.y);
- Rectangle trim = computeTrim (0, 0, width, height);
- width = trim.width; height = trim.height;
- return new Point (width, height);
-}
-
-/**
-* Computes the widget trim.
-*/
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- return new Rectangle(x-2, y-33, width+4, height+35);
-}
-
-/*
- **** Layout code ****
- */
-
-boolean _setSize(int width, int height) {
- boolean differentExtent = UtilFuncs.setSize(eventBoxHandle, width,height);
- UtilFuncs.setSize (fixedHandle, width,height);
- UtilFuncs.setSize (notebookHandle, width,height);
- UtilFuncs.setSize (handle, width-4, height-35);
- layoutCurrent();
- return differentExtent;
-}
-
-public Rectangle _getClientArea () {
- org.eclipse.swt.graphics.Point size = _getSize();
- int x = Math.max(size.x-4, 3);
- int y = Math.max(size.y-35, 3);
- return new Rectangle(0,0, x, y);
-}
-
-void layoutCurrent() {
- int index=getSelectionIndex();
- if (index==-1) return;
- Control control = items[index].control;
- if (control==null) return;
- if (control.isDisposed()) return;
- control.setBounds(getClientArea());
-}
-
-void createItem (TabItem item, int index) {
- int list = OS.gtk_container_children (notebookHandle);
- int itemCount = OS.g_list_length (list);
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_ITEM_NOT_ADDED);
- if (itemCount == items.length) {
- TabItem [] newItems = new TabItem [items.length + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
-
- // create a new label
- byte [] buffer = new byte [] {0};
- int labelHandle = OS.gtk_label_new (buffer);
-
- // create a new fake page
- int stubPage = OS.gtk_fixed_new();
-
- // put the label and the fake page inside the notebook
- OS.gtk_signal_handler_block_by_data (notebookHandle, SWT.Selection);
- OS.gtk_notebook_append_page(notebookHandle, stubPage, labelHandle);
- OS.gtk_signal_handler_unblock_by_data (notebookHandle, SWT.Selection);
-
- OS.gtk_widget_show(labelHandle);
- OS.gtk_widget_show(stubPage);
-
- item.state |= HANDLE;
- item.handle = labelHandle;
- System.arraycopy (items, index, items, index + 1, itemCount++ - index);
- items [index] = item;
- OS.gtk_notebook_set_show_tabs (notebookHandle, true);
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's selection changes, 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
- *
- * @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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-
-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);
- OS.gtk_notebook_remove_page (notebookHandle, index);
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
- item.handle = 0;
-}
-/** - * Returns the item at the given, zero-relative index in the - * receiver. Throws an exception if the index is out of range. - * - * @param index the index of the item to return - * @return the item at the given index - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */
-
-public TabItem getItem (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int list = OS.gtk_container_children (notebookHandle);
- int itemCount = OS.g_list_length (list);
- if (!(0 <= index && index < itemCount)) error (SWT.ERROR_CANNOT_GET_ITEM);
- 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- //return itemCount;
- int list = OS.gtk_container_children (notebookHandle);
- return OS.g_list_length (list);
-}
-/** - * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int list = OS.gtk_container_children (notebookHandle);
- int itemCount = OS.g_list_length (list);
- TabItem [] result = new TabItem [itemCount];
- System.arraycopy (items, 0, result, 0, itemCount);
- 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int index = OS.gtk_notebook_get_current_page (notebookHandle);
- 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return OS.gtk_notebook_get_current_page (notebookHandle);
-}
-
-/** - * 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 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 (TabItem item) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- int list = OS.gtk_container_children (notebookHandle);
- int itemCount = OS.g_list_length (list);
- for (int i=0; i<itemCount; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-
-int processSelection (int int0, int int1, int int2) {
- int index = OS.gtk_notebook_get_current_page (notebookHandle);
- if (index != -1) {
- Control control = items [index].getControl ();
- if (control != null && !control.isDisposed ()) {
- control.setVisible (false);
- }
- }
- Control control = items [int1].getControl ();
- if (control != null && !control.isDisposed ()) {
- control.setBounds(getClientArea());
- control.setVisible (true);
- }
- Event event = new Event();
- event.item = items[int1];
- postEvent(SWT.Selection, event);
- return 0;
-}
-
-/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's selection changes. - * - * @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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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. - * If the item at the index was already selected, it remains selected. - * The current selected 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 (index == -1) return;
- OS.gtk_signal_handler_block_by_data (notebookHandle, SWT.Selection);
- OS.gtk_notebook_set_page (notebookHandle, index);
- OS.gtk_signal_handler_unblock_by_data (notebookHandle, SWT.Selection);
-}
-
-/** - * 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 SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (items == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (items.length == 0) {
- setSelection (-1);
- return;
- }
- for (int i=items.length-1; i>=0; --i) {
- int index = indexOf (items [i]);
- if (index != -1) setSelection (index);
- }
-}
-
-/*
- * == DESTRUCTION ===
- */
-
-void deregister () {
- super.deregister ();
- WidgetTable.remove (notebookHandle);
-}
-
-void releaseChildren() {
- int list = OS.gtk_container_children (notebookHandle);
- int itemCount = OS.g_list_length (list);
- for (int i=0; i<itemCount; i++) {
- TabItem item = items [i];
- if (!item.isDisposed ()) {
- item.releaseWidget ();
- item.releaseHandle ();
- }
- }
-
- // Now, the non-item children
- list = OS.gtk_container_children(parentingHandle());
- int childCount = OS.g_list_length (list);
- for (int i=0; i<childCount; i++) {
- int childHandle = OS.g_list_nth_data(list, i);
- if (!isMyHandle(childHandle)) {
- Widget w = WidgetTable.get(childHandle);
- if (!(w==null) && !(w.isDisposed())) {
- w.releaseWidget();
- w.releaseHandle();
- }
- }
- }
-}
-
-void releaseHandle () {
- super.releaseHandle ();
- notebookHandle = 0;
-}
-
-void releaseWidget () {
- super.releaseWidget();
- items = null;
-}
-
-/*
- * == AS YET UNCLASSIFIED ===
- */
-
-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);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TabItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TabItem.java deleted file mode 100644 index 8454cc3d3b..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TabItem.java +++ /dev/null @@ -1,218 +0,0 @@ -package org.eclipse.swt.widgets;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-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> - */
-
-public class TabItem extends Item {
- Control control;
- TabFolder parent;
-/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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;
- parent.createItem (this, 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 index to store the receiver in its parent - * - * @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, int index) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, index);
-}
-/** - * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return control;
-}
-public Display getDisplay () {
- TabFolder parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-/** - * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return "";
-}
-void releaseChild () {
- super.releaseChild ();
- parent.destroyItem (this);
-}
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
-}
-/** - * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- Control oldControl = this.control, newControl = control;
- this.control = control;
- int index = parent.indexOf (this);
- if (index != parent.getSelectionIndex ()) return;
- if (newControl != null) {
- newControl.setBounds (parent.getClientArea ());
- newControl.setVisible (true);
- }
- if (oldControl != null) oldControl.setVisible (false);
-}
-public void setImage (Image image) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- super.setImage (image);
-}
-public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- byte [] buffer = string2bytesConvertMnemonic(string);
- OS.gtk_label_parse_uline(handle, buffer);
-}
-/** - * Sets the receiver's tool tip text to the argument, which - * may be null indicating that no tool tip text should be shown. - * - * @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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Table.java deleted file mode 100644 index d45196a62b..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Table.java +++ /dev/null @@ -1,1411 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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 a selectable user interface - * object that displays a list of images and strings and issue - * notificiation when selected. - * <p> - * The item children that may be added to instances of this class - * must be of type <code>TableItem</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>SINGLE, MULTI, CHECK, FULL_SELECTION, HIDE_SELECTION</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection, DefaultSelection</dd> - * </dl> - * <p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */ -public class Table extends Composite { - int itemCount, columnCount; - TableItem [] items; - TableColumn [] columns; - TableItem itemBeingSelected; - TableItem[] selection = new TableItem[0]; - int check, uncheck; - int check_width, check_height; - public static int MAX_COLUMNS = 32; - - -/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 Table (Composite parent, int style) { - super (parent, checkStyle (style)); -} - - - - -/* - * === HANDLE CODE 1 === - */ - -void createHandle (int index) { - state |= HANDLE; - - eventBoxHandle = OS.gtk_event_box_new(); - if (eventBoxHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - - fixedHandle = OS.gtk_fixed_new(); - if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES); - - handle = OS.gtk_clist_new (MAX_COLUMNS); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - - scrolledHandle = OS.gtk_scrolled_window_new (0, 0); - if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES); -} -void setHandleStyle () { - /* Single or Multiple Selection */ - int selectionMode; - if ((style & SWT.MULTI) != 0) selectionMode = OS.GTK_SELECTION_EXTENDED; - else selectionMode = OS.GTK_SELECTION_BROWSE; - OS.gtk_clist_set_selection_mode (handle, selectionMode); - - /* We fake the number of columns, because we have to know beforehand. - * Initially all those fake columns are invisible - */ - byte [] buffer = new byte [1]; - OS.gtk_clist_set_column_title (handle, 0, buffer); - for (int i=1; i<MAX_COLUMNS; i++) { - OS.gtk_clist_set_column_visibility (handle, i, false); - } - - /* Scrolling policy */ - int hscrollbar_policy = (style & SWT.H_SCROLL) != 0 ? OS.GTK_POLICY_ALWAYS : OS.GTK_POLICY_AUTOMATIC; - int vscrollbar_policy = (style & SWT.V_SCROLL) != 0 ? OS.GTK_POLICY_ALWAYS : OS.GTK_POLICY_AUTOMATIC; - OS.gtk_scrolled_window_set_policy (scrolledHandle, hscrollbar_policy, vscrollbar_policy); -} -void configure() { - _connectParent(); - OS.gtk_container_add(eventBoxHandle, fixedHandle); - OS.gtk_fixed_put (fixedHandle, scrolledHandle, (short)0, (short)0); - OS.gtk_container_add (scrolledHandle, handle); -} - -static int checkStyle (int style) { - /* - * To be compatible with Windows, force the H_SCROLL - * and V_SCROLL style bits. On Windows, it is not - * possible to create a table without scroll bars. - */ - style |= SWT.H_SCROLL | SWT.V_SCROLL; - return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0); -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - if (wHint == SWT.DEFAULT) wHint = 200; - return _computeSize (wHint, hHint, changed); -} - -void showHandle() { - OS.gtk_widget_show (eventBoxHandle); - OS.gtk_widget_show (fixedHandle); - OS.gtk_widget_show (scrolledHandle); - OS.gtk_widget_show (handle); - OS.gtk_widget_realize (handle); - - if ((style & SWT.CHECK) != 0) { - uncheck = createCheckPixmap(false); - check = createCheckPixmap(true); - } -} - -int createCheckPixmap(boolean checked) { - /* - * The box will occupy the whole item width. - */ - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); - check_height = clist.row_height-1; - check_width = check_height; - - GdkVisual visual = new GdkVisual(); - OS.memmove(visual, OS.gdk_visual_get_system(), GdkVisual.sizeof); - int pixmap = OS.gdk_pixmap_new(0, check_width, check_height, visual.depth); - - int gc = OS.gdk_gc_new(pixmap); - - GdkColor fgcolor = new GdkColor(); - fgcolor.pixel = 0xFFFFFFFF; - fgcolor.red = (short) 0xFFFF; - fgcolor.green = (short) 0xFFFF; - fgcolor.blue = (short) 0xFFFF; - OS.gdk_gc_set_foreground(gc, fgcolor); - OS.gdk_draw_rectangle(pixmap, gc, 1, 0,0, check_width,check_height); - - fgcolor = new GdkColor(); - fgcolor.pixel = 0; - fgcolor.red = (short) 0; - fgcolor.green = (short) 0; - fgcolor.blue = (short) 0; - OS.gdk_gc_set_foreground(gc, fgcolor); - - OS.gdk_draw_line(pixmap, gc, 0,0, 0,check_height-1); - OS.gdk_draw_line(pixmap, gc, 0,check_height-1, check_width-1,check_height-1); - OS.gdk_draw_line(pixmap, gc, check_width-1,check_height-1, check_width-1,0); - OS.gdk_draw_line(pixmap, gc, check_width-1,0, 0,0); - - /* now the cross check */ - if (checked) { - OS.gdk_draw_line(pixmap, gc, 0,0, check_width-1,check_height-1); - OS.gdk_draw_line(pixmap, gc, 0,check_height-1, check_width-1,0); - } - - OS.gdk_gc_destroy(gc); - return pixmap; -} - -void hookEvents () { - //TO DO - get rid of enter/exit for mouse crossing border - super.hookEvents (); - signal_connect (handle, "select_row", SWT.Selection, 5); -} - -void createWidget (int index) { - super.createWidget (index); - items = new TableItem [4]; - columns = new TableColumn [4]; - itemCount = columnCount = 0; -} - -/* - * HANDLE CODE 2 - */ -int topHandle() { return eventBoxHandle; } -int parentingHandle() { return fixedHandle; } -boolean isMyHandle(int h) { - if (h==eventBoxHandle) return true; - if (h==scrolledHandle) return true; - if (h==fixedHandle) return true; - if (h==handle) return true; - return false; - -} - - - -/* - * === GEOMETRY === - */ - -boolean _setSize(int width, int height) { - boolean different = UtilFuncs.setSize(eventBoxHandle, width, height); - if (different) UtilFuncs.setSize(fixedHandle, width, height); - if (different) UtilFuncs.setSize(scrolledHandle, width, height); - return different; -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's selection changes, 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 reciever has <code>SWT.CHECK</code> style set 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 - * - * @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); -} - - -/* The real work to create a new column */ -void createItem (TableColumn column, int index) { - if (!(0 <= index && index <= columnCount)) error (SWT.ERROR_ITEM_NOT_ADDED); - if (columnCount == columns.length) { - TableColumn [] newColumns = new TableColumn [columns.length + 4]; - System.arraycopy (columns, 0, newColumns, 0, columns.length); - columns = newColumns; - } - OS.gtk_clist_set_column_visibility (handle, index, true); - OS.gtk_clist_column_titles_passive(handle); // paranoia - System.arraycopy (columns, index, columns, index + 1, columnCount++ - index); - columns [index] = column; -} -void createItem (TableItem item, int index) { - if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_ITEM_NOT_ADDED); - if (itemCount == items.length) { - TableItem [] newItems = new TableItem [items.length + 4]; - System.arraycopy (items, 0, newItems, 0, items.length); - items = newItems; - } -// int ptr = OS.g_malloc (1); - int [] strings = new int [MAX_COLUMNS]; -// for (int i=0; i<strings.length; i++) strings [i] = ptr; - for (int i=0; i<strings.length; i++) strings [i] = 0; - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - int result = OS.gtk_clist_insert (handle, index, strings); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -// OS.g_free (ptr); - System.arraycopy (items, index, items, index + 1, itemCount++ - index); - items [index] = item; -} - -/** - * 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(); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_clist_unselect_row (handle, index, 0); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); - selection = _getNativeSelection(); -} -/** - * 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(); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - for (int i=start; i<=end; i++) { - OS.gtk_clist_unselect_row (handle, i, 0); - } - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); - selection = _getNativeSelection(); -} -/** - * 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 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> - */ -public void deselect (int [] indices) { - checkWidget(); - if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - for (int i=0; i<indices.length; i++) { - OS.gtk_clist_unselect_row (handle, indices [i], 0); - } - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} -/** - * Deselects all selected items in the receiver. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void deselectAll () { - checkWidget(); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_clist_unselect_all (handle); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); - selection = new TableItem[0]; -} - -void destroyItem (TableColumn column) { - int index = 0; - while (index < columnCount) { - if (columns [index] == column) break; - index++; - } - if (index == columnCount) return; - OS.gtk_clist_set_column_visibility (handle, index, false); - OS.gtk_clist_set_column_title (handle, index, new byte [1]); - System.arraycopy (columns, index + 1, columns, index, --columnCount - index); - columns [columnCount] = null; -} -void destroyItem (TableItem item) { - int index = 0; - while (index < itemCount) { - if (items [index] == item) break; - index++; - } - if (index == itemCount) return; - OS.gtk_clist_remove (handle, index); - System.arraycopy (items, index + 1, items, index, --itemCount - index); - items [itemCount] = null; -} -/** - * Returns the column at the given, zero-relative index in the - * receiver. Throws an exception if the index is out of range. - * 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> - */ -public TableColumn getColumn (int index) { - checkWidget(); - if (!(0 <= index && index < columnCount)) error (SWT.ERROR_CANNOT_GET_ITEM); - 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 is 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> - * @exception SWTError <ul> - * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li> - * </ul> - */ -public int getColumnCount () { - checkWidget(); - return columnCount; -} -/** - * Returns an array of <code>TableColumn</code>s which are the - * columns in the receiver. 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> - */ -public TableColumn [] getColumns () { - checkWidget(); - TableColumn [] result = new TableColumn [columnCount]; - System.arraycopy (columns, 0, result, 0, columnCount); - return result; -} -/** - * Returns the width in pixels of a grid 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 getGridLineWidth () { - checkWidget(); - /* FIXME */ - return 0; -} - - - -/** - * Returns the item at the given, zero-relative index in the - * receiver. Throws an exception if the index is out of range. - * - * @param index the index of the item to return - * @return the item at the given index - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public TableItem getItem (int index) { - checkWidget(); - if (!(0 <= index && index < itemCount)) error (SWT.ERROR_CANNOT_GET_ITEM); - return items [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 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> - */ -public TableItem getItem (Point pt) { - checkWidget(); - - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); - int clientX = pt.x; - int clientY = pt.y - clist.column_title_area_height; - if (clientY <= 0) return null; - - int[] row = new int[1], column = new int[1]; - row[0] = -1; - OS.gtk_clist_get_selection_info(handle, clientX, clientY, row, column); - if (row[0] == -1) return null; - return items[row[0]]; -} - -/** - * 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return itemCount; -} -/** - * Returns the height of the area which would be used to - * display <em>one</em> of the items in the receiver's. - * - * @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(); - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); - return clist.row_height; -} -/** - * Returns an 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]; - System.arraycopy (items, 0, result, 0, itemCount); - return result; -} - - - -/* - * === SELECTION STORY === - */ - -/** - * Returns an array of <code>TableItem</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 TableItem[] getSelection () { - checkWidget(); - return selection; -} - -/** - * Get the selection from the OS. - */ -private TableItem[] _getNativeSelection () { - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); - switch (clist.selection_mode) { - case OS.GTK_SELECTION_SINGLE: return getSelection_single(); - case OS.GTK_SELECTION_BROWSE: return getSelection_browse(); - case OS.GTK_SELECTION_MULTIPLE: return getSelection_multiple(); - case OS.GTK_SELECTION_EXTENDED: return getSelection_extended(); - default: error(SWT.ERROR_UNSPECIFIED); - } - /* can never get here */ - return null; -} -private TableItem[] getSelection_single () { - GtkCList clist = new GtkCList(); - OS.memmove(clist, handle, GtkCList.sizeof); - if (clist.selection==0) return new TableItem[0]; - int length = OS.g_list_length (clist.selection); - if (length == 0) return new TableItem[0]; - int index = OS.g_list_nth_data (clist.selection, 0); - return new TableItem [] {items[index]}; -} -private TableItem[] getSelection_browse () { - /* same as single */ - GtkCList clist = new GtkCList(); - OS.memmove(clist, handle, GtkCList.sizeof); - if (clist.selection==0) return new TableItem[0]; - int length = OS.g_list_length (clist.selection); - if (length == 0) return new TableItem[0]; - int index = OS.g_list_nth_data (clist.selection, 0); - return new TableItem [] {items[index]}; -} -private TableItem[] getSelection_multiple () { - GtkCList clist = new GtkCList(); - OS.memmove(clist, handle, GtkCList.sizeof); - if (clist.selection==0) return new TableItem[0]; - int length = OS.g_list_length (clist.selection); - TableItem [] result = new TableItem [length]; - for (int i=0; i<length; i++) { - int index = OS.g_list_nth_data (clist.selection, i); - result [i] = items [index]; - } - return result; -} -private TableItem[] getSelection_extended () { - GtkCList clist = new GtkCList(); - OS.memmove(clist, handle, GtkCList.sizeof); - if (clist.selection==0) return new TableItem[0]; - int length = OS.g_list_length (clist.selection); - TableItem [] result = new TableItem [length]; - for (int i=0; i<length; i++) { - int index = OS.g_list_nth_data (clist.selection, i); - result [i] = items [index]; - } - 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(); - return selection.length; -} -private int _getNativeSelectionCount () { - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); - int selectionList = clist.selection; - if (selectionList==0) return 0; - return OS.g_list_length (clist.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(); - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); - int list = clist.selection; - if (OS.g_list_length (list) == 0) return -1; - return OS.g_list_nth_data (list, 0); -} -/** - * Returns the zero-relative indices of the items which are currently - * selected in the receiver. 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(); - GtkCList widget = new GtkCList (); - OS.memmove (widget, handle, GtkCList.sizeof); - int list = widget.selection; - int length = OS.g_list_length (list); - int [] indices = new int [length]; - for (int i=0; i<length; i++) { - indices [i] = OS.g_list_nth_data (list, i); - } - return indices; -} - -/** - * 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 visibility 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(); - GtkCList widget = new GtkCList (); - OS.memmove (widget, handle, GtkCList.sizeof); - int list = widget.selection; - int length = OS.g_list_length (list); - for (int i=0; i<length; i++) { - if (index == OS.g_list_nth_data (list, i)) return true; - } - return false; -} - - - - - -/** - * 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(); - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); - return -clist.voffset / (clist.row_height + 1); -} - -/** - * 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 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 (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 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 (TableItem 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 releaseWidget () { - int columnCount = 0; - for (int i=0; i<columnCount; i++) { - TableColumn column = columns [i]; -// if (!column.isDisposed ()) column.releaseWidget (); - if (column != null && !column.isDisposed ()) column.releaseWidget (); - } - columns = null; - int itemCount = 0; - for (int i=0; i<itemCount; i++) { - TableItem item = items [i]; - if (!item.isDisposed ()) item.releaseWidget (); - } - items = null; - itemBeingSelected = null; - if (check != 0) OS.gdk_pixmap_unref (check); - if (uncheck != 0) OS.gdk_pixmap_unref (uncheck); - check = uncheck = 0; - super.releaseWidget (); -} -/** - * 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> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void remove (int index) { - checkWidget(); - if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_ITEM_NOT_REMOVED); - OS.gtk_clist_remove (handle, index); - TableItem item = items [index]; - System.arraycopy (items, index + 1, items, index, --itemCount - index); - items [itemCount] = null; - item.releaseWidget (); -} -/** - * 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> - * @exception SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void remove (int start, int end) { - checkWidget(); - int index = end; - while (index >= start) { - OS.gtk_clist_remove (handle, index); - items [index].releaseWidget (); - --index; - } - int first = index + 1, last = end + 1; - System.arraycopy (items, last, items, first, itemCount - last); - for (int i=itemCount-(last-first); i<itemCount; i++) items [i] = null; - itemCount = itemCount - (last - first); - if (first > start) error (SWT.ERROR_ITEM_NOT_REMOVED); -} -/** - * 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> - * </ul> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - 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 SWTError <ul> - * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li> - * </ul> - */ -public void remove (int [] indices) { - checkWidget(); - if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); - int [] newIndices = new int [indices.length]; - System.arraycopy (indices, 0, newIndices, 0, indices.length); - sort (newIndices); - int last = -1; - for (int i=0; i<newIndices.length; i++) { - int index = newIndices [i]; - if (index != last || i == 0) { - OS.gtk_clist_remove (handle, index); - // BUG - disposed callback could remove an item - items [index].releaseWidget (); - System.arraycopy (items, index + 1, items, index, --itemCount - index); - items [itemCount] = null; - last = index; - } - } -} -/** - * Removes all of the items from the receiver. - * <p> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void removeAll () { - checkWidget(); - OS.gtk_clist_clear (handle); - items = new TableItem [4]; - itemCount = 0; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's selection changes. - * - * @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. - * 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(); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_clist_select_row (handle, index, 0); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); - selection = _getNativeSelection(); -} - -/** - * Selects the items at the given zero-relative indices in the receiver. - * If the item at the index was already selected, it remains - * selected. The range of the indices is inclusive. Indices that are - * out of range 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> - */ -public void select (int start, int end) { - checkWidget(); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - for (int i=start; i<=end; i++) { - OS.gtk_clist_select_row (handle, i, 0); - } - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); - selection = _getNativeSelection(); -} -/** - * Selects the items at the given zero-relative indices in the receiver. - * If the item at the given zero-relative index in the receiver - * is not selected, it is selected. If the item at the index - * was selected, it remains selected. Indices that are out - * of range and duplicate 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> - */ -public void select (int [] indices) { - checkWidget(); - if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - for (int i=0; i<indices.length; i++) { - OS.gtk_clist_select_row (handle, indices [i], 0); - } - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); - selection = _getNativeSelection(); -} -/** - * Selects all 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 void selectAll () { - checkWidget(); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_clist_select_all (handle); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); - selection = _getNativeSelection(); -} - -/** - * 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_WIDGET_FLAGS(handle)&OS.GTK_CLIST_SHOW_TITLES) != 0; -} - -/** - * 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 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 setHeaderVisible (boolean show) { - /* FIXME - * We should investigate why this optimization is not working. - */ -// boolean isVisibleNow = getHeaderVisible(); -// if (show==isVisibleNow) return; - if (show) { - OS.gtk_clist_column_titles_show (handle); - OS.gtk_clist_column_titles_passive(handle); - } else { - OS.gtk_clist_column_titles_hide (handle); - } -} -/** - * Returns <code>true</code> if the receiver's lines are 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 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 false; -} -/** - * Marks the receiver's lines 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 setLinesVisible (boolean show) { - checkWidget(); -} -/** - * Selects the item at the given zero-relative index in the receiver. - * The current selected 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) { - deselectAll (); - select (index); - selection = _getNativeSelection(); -} -/** - * Selects the items at the given zero-relative indices in the receiver. - * The current selected if first cleared, then the new items are selected. - * - * @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) { - deselectAll (); - select (start, end); - selection = _getNativeSelection(); -} -/** - * Selects the items at the given zero-relative indices in the receiver. - * The current selected is first cleared, then the new items are selected. - * - * @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) { - deselectAll (); - select (indices); - selection = _getNativeSelection(); -} -/** - * 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 array of items is null</li> - * <li>ERROR_INVALID_ARGUMENT - if one of 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#deselectAll() - * @see Table#select(int) - */ -public void setSelection (TableItem [] items) { - checkWidget(); - if (items == null) error (SWT.ERROR_NULL_ARGUMENT); - deselectAll (); - int length = items.length; - if (length == 0) return; - if ((style & SWT.SINGLE) != 0) length = 1; - for (int i=length-1; i>=0; --i) { - int index = indexOf (items [i]); - if (index != -1) select (index); - } - selection = items; /* FIXME */ -} -/** - * 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(); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_clist_moveto (handle, index, 0, 0.0f, 0.0f); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -/** - * 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) { -// error(SWT.ERROR_NOT_IMPLEMENTED); -} - -/** - * 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 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 Table#showItem(TableItem) - */ -public void showSelection () { - checkWidget(); - setTopIndex (getSelectionIndex ()); -} - -int processSelection (int int0, int int1, int int2) { - selection = _getNativeSelection(); - itemBeingSelected = items [int0]; - Event event = new Event (); - event.item = itemBeingSelected; - sendEvent (SWT.Selection, event); - return 0; -} - -int processMouseDown (int callData, int arg1, int int2) { - OS.gtk_widget_grab_focus(handle); - - // First, see if we have a single or double click - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, callData, GdkEventButton.sizeof); - boolean isDoubleClick = (gdkEvent.type == OS.GDK_2BUTTON_PRESS); - - // We can't just use the x and y coordinates from the Gdk event, - // because the actual items are drawn on a special X window - Point where = _gdkWindowGetPointer(); - int eventType; - if (isDoubleClick) { - eventType = SWT.MouseDoubleClick; - Event event = new Event (); - event.item=itemBeingSelected; - event.x = where.x; event.y = where.y; - sendEvent (SWT.DefaultSelection, event); - return 1; - } - - eventType = SWT.MouseDown; - sendMouseEvent (eventType, gdkEvent.button, gdkEvent.state, gdkEvent.time, where.x, where.y); - if (gdkEvent.button == 3 && menu != null) menu.setVisible (true); - - - if ((style&SWT.CHECK) != 0) { - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); - int clientX = where.x; - int clientY = where.y - clist.column_title_area_height; - if (clientY <= 0) return 1; - int[] row = new int[1], column = new int[1]; - row[0] = -1; - OS.gtk_clist_get_selection_info(handle, clientX, clientY, row, column); - if (row[0] == -1) return -1; - int leftmost = 2; - if (clientX < leftmost) return 1; - if (clientX > leftmost+check_width) return 1; - - TableItem item = items [row[0]]; - item._setChecked(!item._getChecked()); - Event event = new Event (); - event.detail = SWT.CHECK; - event.item = item; - postEvent (SWT.Selection, event); - } - return 1; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TableColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TableColumn.java deleted file mode 100644 index eab13dbec9..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TableColumn.java +++ /dev/null @@ -1,403 +0,0 @@ -package org.eclipse.swt.widgets;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-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. - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>LEFT, RIGHT, CENTER</dd> - * <dt><b>Events:</b></dt> - * <dd> Move, Resize, Selection</dd> - * </dl> - * <p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */
-
-public class TableColumn extends Item {
- Table parent;
-/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 index to store the receiver in its parent - * - * @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 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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 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
- *
- * @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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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);
-}
-void createWidget (int index) {
- parent.createItem (this, index);
- text = "";
-}
-/** - * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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 Display getDisplay () {
- Table parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-/** - * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int index = parent.indexOf (this);
- if (index == -1) return false;
- GtkCList gtkclist = new GtkCList();
- OS.memmove(gtkclist, parent.handle, GtkCList.sizeof);
- int chandle=gtkclist.column;
- GtkCListColumn gtkcolumn = new GtkCListColumn();
- OS.memmove(gtkcolumn, chandle+index*GtkCListColumn.sizeof, GtkCListColumn.sizeof);
- return (gtkcolumn.resizeable == 1) ? true : false;
-}
-/** - * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int index = parent.indexOf (this);
- if (index == -1) return 0;
- GtkCList gtkclist = new GtkCList();
- OS.memmove(gtkclist, parent.handle, GtkCList.sizeof);
- int chandle=gtkclist.column;
- GtkCListColumn gtkcolumn = new GtkCListColumn();
- OS.memmove(gtkcolumn, chandle+index*GtkCListColumn.sizeof, GtkCListColumn.sizeof);
- return gtkcolumn.width;
-}
-/** - * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-}
-void releaseChild () {
- super.releaseChild ();
- parent.destroyItem (this);
-}
-void releaseWidget () {
- super.releaseWidget ();
- text = null;
- parent = 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 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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. - * - * @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 #addSelectionListener - */
-public void removeSelectionListener(SelectionListener listener) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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>. - * - * @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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- int index = parent.indexOf (this);
- if (index == -1 || index == 0) return;
- int table = parent.handle;
- style &= ~(SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- style |= alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER);
- int justification = 0;
- if ((style & SWT.LEFT) == SWT.LEFT) justification |= OS.GTK_JUSTIFY_LEFT;
- if ((style & SWT.CENTER) == SWT.CENTER) justification |= OS.GTK_JUSTIFY_CENTER;
- if ((style & SWT.RIGHT) == SWT.RIGHT) justification |= OS.GTK_JUSTIFY_RIGHT;
- OS.gtk_clist_set_column_justification (table, index, justification);
-}
-/** - * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int index = parent.indexOf (this);
- if (index == -1) return;
- int table = parent.handle;
- OS.gtk_clist_set_column_resizeable (table, index, resizable);
-}
-public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- int index = parent.indexOf (this);
- if (index == -1) return;
- int table = parent.handle;
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- OS.gtk_clist_set_column_title (table, index, buffer);
-}
-/** - * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int index = parent.indexOf (this);
- if (index == -1) return;
- int table = parent.handle;
- OS.gtk_clist_set_column_width (table, index, width);
-}
-
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TableItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TableItem.java deleted file mode 100644 index 680b4e1961..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TableItem.java +++ /dev/null @@ -1,503 +0,0 @@ -package org.eclipse.swt.widgets;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.gtk.*;
-import org.eclipse.swt.graphics.*;
-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> - */
-
-public class TableItem extends Item {
- Table parent;
-/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
- _setChecked(false);
-}
-/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 index to store the receiver in its parent - * - * @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, int index) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, index);
- _setChecked(false);
-}
-/** - * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int CELL_SPACING=1;
- GtkCList table = new GtkCList();
- OS.memmove(table, parent.handle, GtkCList.sizeof);
- int columnHandle = table.column;
- columnHandle= columnHandle+index*GtkCListColumn.sizeof;
- GtkCListColumn column=new GtkCListColumn();
- OS.memmove(column, columnHandle, GtkCListColumn.sizeof);
- GtkAdjustment adjustment=new GtkAdjustment();
- OS.memmove(adjustment, table.vadjustment, GtkAdjustment.sizeof);
- float vaj = adjustment.value;
- OS.memmove(adjustment, table.hadjustment, GtkAdjustment.sizeof);
- float haj = adjustment.value;
- int x=(short)column.area_x+table.hoffset;
- int width=(short)column.area_width;
- int height=parent.getItemHeight();
- int row=parent.indexOf(this);
- int y=table.column_title_area_height+height*row+(row+2)*CELL_SPACING-(int)vaj;
- return new Rectangle (x, y, width, height);
-}
-
-/**
- * Return whether or not the receiver has a check box and can
- * be checked.
- */
-boolean isCheckable() {
- return (parent.style & SWT.CHECK) != 0;
-}
-
-/** - * Returns <code>true</code> if the receiver is checked, - * and false otherwise. When the parent does not have - * the <code>CHECK style, return false. - * - * @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.style & SWT.CHECK) == 0) return false;
- return _getChecked();
-}
-
-boolean _getChecked () {
- int row = parent.indexOf (this);
- if (row == -1) return false;
- int clist = parent.handle;
-
- int[] text = new int[1];
- int[] spacing = new int[1];
- int[] pixmap = new int[1];
- int[] mask = new int[1];
- OS.gtk_clist_get_pixtext(clist, row, 0, text, spacing, pixmap, mask);
-
- return pixmap[0]==parent.check;
-}
-
-public Display getDisplay () {
- Table parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-/** - * Returns <code>true</code> if the receiver is grayed, - * and false otherwise. When the parent does not have - * the <code>CHECK style, return false. - * - * @return the 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> - */
-public boolean getGrayed () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if ((parent.style & SWT.CHECK) == 0) return false;
- return false;
-}
-
-/**
-* Gets the image at an index.
-* <p>
-* Indexing is zero based.
-*
-* This operation will fail when the index is out
-* of range or an item could not be queried from
-* the OS.
-*
-* @param index the index of the image
-* @return the image
-*
-* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
-* when called from the wrong thread
-* @exception SWTError(ERROR_WIDGET_DISPOSED)
-* when the widget has been disposed
-*/
-public Image getImage (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return null;
-}
-/** - * Returns a rectangle describing the size and location - * relative to its parent of an image at a column in the - * table. - * - * @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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return new Rectangle (0, 0, 0, 0);
-}
-/** - * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return 0;
-}
-/** - * 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 () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent;
-}
-/**
-* Gets the item text at an index.
-* <p>
-* Indexing is zero based.
-*
-* This operation will fail when the index is out
-* of range or an item could not be queried from
-* the OS.
-*
-* @param index the index of the item
-* @return the item
-*
-* @exception SWTError(ERROR_THREAD_INVALID_ACCESS)
-* when called from the wrong thread
-* @exception SWTError(ERROR_WIDGET_DISPOSED)
-* when the widget has been disposed
-* @exception SWTError(ERROR_CANNOT_GET_TEXT)
-* when the operation fails
-*/
-public String getText (int index) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- return "";
-}
-void releaseChild () {
- super.releaseChild ();
- parent.destroyItem (this);
-}
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
-}
-/** - * Sets the checked state of the receiver. - * - * @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();
- _setChecked (checked);
-}
-void _setChecked (boolean checked) {
- if ((parent.style & SWT.CHECK) == 0) return; /* needed here because we don't verify in the constructor */
-
- int row = parent.indexOf (this);
- if (row == -1) return;
- int ctable = parent.handle;
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- if (checked) OS.gtk_clist_set_pixtext (ctable, row, 0, buffer, (byte) 2, parent.check, 0);
- else OS.gtk_clist_set_pixtext (ctable, row, 0, buffer, (byte) 2, parent.uncheck, 0);
-}
-
-/** - * Sets the grayed state of the receiver. - * - * @param checked 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> - */
-public void setGrayed (boolean grayed) {
- checkWidget();
-}
-/** - * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-// if (index == 0) {
-// setImage (image);
-// return;
-// }
- int row = parent.indexOf (this);
- if (row == -1) return;
- int pixmap = 0, mask = 0;
- if (image != null) {
- pixmap = image.pixmap;
- mask = image.mask;
- }
- int ctable = parent.handle;
- if (text != null) {
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- OS.gtk_clist_set_pixtext (ctable, row, index, buffer, (byte) 2, pixmap, mask);
- } else {
- OS.gtk_clist_set_pixmap (ctable, row, index, pixmap, mask);
- }
-}
-public void setImage (Image image) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- int row = parent.indexOf (this);
- if (row == -1) return;
- super.setImage (image);
- int ctable = parent.handle;
- int pixmap = 0, mask = 0;
- if (image != null) {
- pixmap = image.pixmap;
- mask = image.mask;
- }
- if (text != null) {
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- OS.gtk_clist_set_pixtext (ctable, row, 0, buffer, (byte) 2, pixmap, mask);
- } else {
- OS.gtk_clist_set_pixmap (ctable, row, 0, pixmap, mask);
- }
-}
-/** - * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (images == null) error (SWT.ERROR_NULL_ARGUMENT);
- for (int i=0; i<images.length; i++) {
- setImage (i, images [i]);
- }
-}
-/** - * Sets the image indent. - * - * @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> - */
-public void setImageIndent (int indent) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
-}
-/** - * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (index == 0) {
- setText (string);
- return;
- }
- int row = parent.indexOf (this);
- if (row == -1) return;
- int ctree = parent.handle;
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- if (image != null) {
- OS.gtk_clist_set_pixtext(ctree, row, index, buffer, (byte) 2, image.pixmap, image.mask);
- } else {
- OS.gtk_clist_set_text (ctree, row, index, buffer);
- }
-}
-public void setText (String string) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int row = parent.indexOf (this);
- if (row == -1) return;
- super.setText (string);
- int ctree = parent.handle;
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- if (image != null) {
- OS.gtk_clist_set_pixtext(ctree, row, 0, buffer, (byte) 2, image.pixmap, image.mask);
- } else {
- OS.gtk_clist_set_text (ctree, row, 0, buffer);
- }
-}
-/** - * 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) {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED);
- 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/gtk1x/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Text.java deleted file mode 100644 index b6f5f5c74e..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Text.java +++ /dev/null @@ -1,1226 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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. - * <p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>MULTI, SINGLE, READ_ONLY, WRAP</dd> - * <dt><b>Events:</b></dt> - * <dd>DefaultSelection, Modify, Verify</dd> - * </dl> - * </p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - */ - -public class Text extends Scrollable { - int textLimit = 0xFFFF; - boolean visibility = true; - public final static int LIMIT; - 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 Text (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -void createHandle (int index) { - state |= HANDLE; - if ((style & SWT.SINGLE) != 0) { - handle = OS.gtk_entry_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - } else { - scrolledHandle = OS.gtk_scrolled_window_new (0, 0); - if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES); - handle = OS.gtk_text_new (0, 0); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - } -} - -void setHandleStyle() { - OS.gtk_editable_set_editable (handle, (style & SWT.READ_ONLY) == 0); - if ((style & SWT.SINGLE) == 0) - OS.gtk_text_set_word_wrap (handle, (style & SWT.WRAP) != 0 ? 1 : 0); - if (scrolledHandle!=0) setScrollingPolicy(); - // When 2.0 arrives, we'll be able to set the flat appearance - -} - -void configure() { - _connectParent(); - if (scrolledHandle != 0) { - OS.gtk_container_add (scrolledHandle, handle); - } -} - -void showHandle() { - if (scrolledHandle != 0) OS.gtk_widget_show (scrolledHandle); - OS.gtk_widget_show (handle); - OS.gtk_widget_realize (handle); -} - -void hookEvents () { - //TO DO - get rid of enter/exit for mouse crossing border - super.hookEvents(); - signal_connect_after (handle, "changed", SWT.Modify, 2); - signal_connect (handle, "insert_text", SWT.Verify, 5); - signal_connect (handle, "delete_text", SWT.Verify, 4); - signal_connect (handle, "activate", SWT.Selection, 2); -} - -/** - * 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 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 - * - * @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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 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> - */ -public void append (String string) { - checkWidget (); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - byte [] buffer = Converter.wcsToMbcs (null, string); - if ((style & SWT.SINGLE) != 0) { - OS.gtk_entry_append_text(handle, buffer); - } else { - int length = getCharCount(); - int [] position = new int [] {length}; - OS.gtk_editable_insert_text (handle, buffer, buffer.length, position); - OS.gtk_editable_set_position (handle, position [0]); - } -} - -static int checkStyle (int style) { - if ((style & SWT.SINGLE) != 0) style &= ~(SWT.H_SCROLL | SWT.V_SCROLL); - if ((style & (SWT.SINGLE | SWT.MULTI)) != 0) return style; - if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) { - return style | SWT.MULTI; - } - return style | SWT.SINGLE; -} -/** - * Clears the selection. - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void clearSelection () { - checkWidget (); - int position = OS.gtk_editable_get_position (handle); - OS.gtk_editable_delete_selection(handle); - OS.gtk_editable_set_position (handle, position); -} - -/** - * 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 (); - byte [] clipboard = Converter.wcsToMbcs (null, "CLIPBOARD", true); - OS.gtk_selection_owner_set(handle, OS.gdk_atom_intern(clipboard, 0), 0); - GtkEditable widget = new GtkEditable (); - OS.memmove(widget, handle, GtkEditable.sizeof); - int start = Math.min(widget.selection_start_pos, widget.selection_end_pos); - int end = Math.max(widget.selection_start_pos, widget.selection_end_pos); - widget.clipboard_text = OS.gtk_editable_get_chars(handle, start, end); - OS.memmove (handle, widget, GtkEditable.sizeof); -} -/** - * Cuts the selected text. - * <p> - * The current selection is first copied to the - * clipboard and then deleted from the widget. - * </p> - * - * @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> - */ -public void cut () { - checkWidget (); - byte [] clipboard = Converter.wcsToMbcs (null, "CLIPBOARD", true); - OS.gtk_selection_owner_set(handle, OS.gdk_atom_intern(clipboard, 0), 0); - GtkEditable widget = new GtkEditable (); - OS.memmove (widget, handle, GtkEditable.sizeof); - int start = Math.min(widget.selection_start_pos, widget.selection_end_pos); - int end = Math.max(widget.selection_start_pos, widget.selection_end_pos); - widget.clipboard_text = OS.gtk_editable_get_chars(handle, start, end); - OS.memmove (handle, widget, GtkEditable.sizeof); - OS.gtk_editable_delete_text(handle, start, end); -} - -/** - * Gets the line number of the caret. - * <p> - * The line number of the caret is returned. - * </p> - * - * @return the line number - * - * @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> - */ -public int getCaretLineNumber () { - checkWidget (); - int addr_index=getCaretPosition(); - String tmpString= new String(getText(0,addr_index)); - return getLineNumberInString(tmpString,'\n'); -} - -/** - * Gets the location the caret. - * <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 (); - GtkText gtktext = new GtkText (); - OS.memmove (gtktext, handle, GtkText.sizeof); - return new Point (gtktext.cursor_pos_x, gtktext.cursor_pos_y); -} - -/** - * Gets the position of the caret. - * <p> - * The character position of the caret is returned. - * </p> - * - * @return the position of the caret - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public int getCaretPosition () { - checkWidget (); - //return OS.gtk_text_get_point (handle); - return OS.gtk_editable_get_position (handle); -} - - -/** - * Gets 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 address = OS.gtk_editable_get_chars (handle, 0, -1); - int length = OS.strlen (address); - OS.g_free (address); - return length; - } - return OS.gtk_text_get_length (handle); -} - -/** - * Gets 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> - */ -public String getLineDelimiter () { - checkWidget (); - return "\n"; -} -/** - * Gets 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> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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 true; -} -/** - * Gets 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> - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public char getEchoChar () { - checkWidget (); - return visibility ? '\0' : '*'; -} - -/** - * Gets the 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 boolean getEditable () { - checkWidget (); - GtkEditable widget = new GtkEditable (); - OS.memmove (widget, handle, GtkEditable.sizeof); - return widget.editable!=0; -} - -/** - * Gets 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 (); - return getLineNumberInString(new String(getText()),'\n') + 1; -} -/** - * Gets 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 (); - Font font = getFont(); - GdkFont gdkfont = new GdkFont(); - int fontHandle = font.handle; - OS.memmove(gdkfont, fontHandle, GdkFont.sizeof); - return gdkfont.ascent + gdkfont.descent; - -} -/** - * Gets the position of the selected text. - * <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 the start and end of 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 Point getSelection () { - checkWidget (); - GtkEditable widget = new GtkEditable (); - OS.memmove (widget, handle, GtkEditable.sizeof); - return new Point (widget.selection_start_pos, widget.selection_end_pos); -} -/** - * Gets 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 (); - GtkEditable widget = new GtkEditable (); - OS.memmove (widget, handle, GtkEditable.sizeof); - int start = Math.min(widget.selection_start_pos, widget.selection_end_pos); - int end = Math.max(widget.selection_start_pos, widget.selection_end_pos); - return end - start; -} -/** - * Gets the selected text. - * - * @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 (); - GtkEditable widget = new GtkEditable (); - OS.memmove (widget, handle, GtkEditable.sizeof); - int start = Math.min(widget.selection_start_pos,widget.selection_end_pos); - int end = Math.max(widget.selection_start_pos,widget.selection_end_pos); - int address = OS.gtk_editable_get_chars (handle, start, end); - int length = OS.strlen (address); - byte [] buffer1 = new byte [length]; - OS.memmove (buffer1, address, length); - OS.g_free (address); - char [] buffer2 = Converter.mbcsToWcs (null, buffer1); - return new String (buffer2, 0, buffer2.length); -} - -/** - * Gets 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 (); - GtkText widget= new GtkText(); - OS.memmove(widget, handle, GtkText.sizeof); - return widget.default_tab_width; -} - -/** - * Gets the widget text. - * <p> - * The text for a text widget is the characters in the widget. - * </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 address = OS.gtk_editable_get_chars (handle, 0, -1); - int length = OS.strlen (address); - byte [] buffer1 = new byte [length]; - OS.memmove (buffer1, address, length); - OS.g_free (address); - char [] buffer2 = Converter.mbcsToWcs (null, buffer1); - return new String (buffer2, 0, buffer2.length); -} - -/** - * Gets a range of text. - * <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 (); - int address = OS.gtk_editable_get_chars (handle, start, end); - if (address == 0) return null; - int length = OS.strlen (address); - byte [] buffer1 = new byte [length]; - OS.memmove (buffer1, address, length); - OS.g_free (address); - char [] buffer2 = Converter.mbcsToWcs (null, buffer1); - return new String (buffer2, 0, buffer2.length); -} - -/** - * 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> - */ -public int getTextLimit () { - checkWidget (); - if ((style & SWT.SINGLE) != 0) return textLimit; - return 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; - GtkText widget = new GtkText (); - OS.memmove (widget, handle, GtkText.sizeof); - int topCharIndex=widget.first_line_start_index; - return (getLineNumberInString(getText(0,topCharIndex), '\n')); - //Since getText uses substring (start, end + 1),so topCharIndex-1 -} - -/** - * Gets 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; - GtkText widget= new GtkText(); - OS.memmove(widget, handle, GtkText.sizeof); - return widget.first_onscreen_ver_pixel; -} - -boolean getWrap () { - checkWidget (); - return false; -} - -/** - * Inserts a string. - * <p> - * The old selection is replaced with the new text. - * </p> - * - * @param string the string - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the 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); - GtkEditable widget = new GtkEditable (); - OS.memmove (widget, handle, GtkEditable.sizeof); - int start = Math.min(widget.selection_start_pos, widget.selection_end_pos); - int end = Math.max(widget.selection_start_pos, widget.selection_end_pos); - OS.gtk_editable_delete_text (handle, start, end); - int [] position = new int [] {start}; - OS.gtk_editable_insert_text (handle, buffer, buffer.length, position); -} - -/** - * 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 (); - byte [] clipboard = Converter.wcsToMbcs (null, "CLIPBOARD", true); - byte [] compound = Converter.wcsToMbcs (null, "COMPOUND_TEXT", true); - int clipboard_atom = OS.gdk_atom_intern (clipboard, 0); - int compound_atom = OS.gdk_atom_intern (compound, 0); - OS.gtk_selection_convert(handle, clipboard_atom, compound_atom, 0); -} - -int processModify (int arg0, int arg1, int int2) { - sendEvent (SWT.Modify); - return 0; -} - -int processVerify (int int0, int int1, int int2) { - if (!hooks (SWT.Verify)) return 0; - if (int2 != 0) { - // Insert - if (int0 == 0 || int1==0){ - return 0; - } -// int length = OS.strlen (int0); - byte [] buffer1 = new byte [int1]; - OS.memmove (buffer1, int0, buffer1.length); - char [] buffer2 = Converter.mbcsToWcs (null, buffer1); - String oldText = new String (buffer2, 0, buffer2.length); - int [] position = new int [1]; - OS.memmove (position, int2, 4); - if (position [0] == -1) position [0] = OS.gtk_text_get_length (handle); - String newText = verifyText (oldText, position [0], position [0]); //WRONG POSITION - if (newText == null) { - byte [] insert_text = Converter.wcsToMbcs (null, "insert-text", true); - OS.gtk_signal_emit_stop_by_name (handle, insert_text); - return 0; - } - if (newText != oldText) { - int windowProc5 = getDisplay ().windowProc5; - byte [] buffer3 = Converter.wcsToMbcs (null, newText); - OS.gtk_signal_handler_block_by_func (handle, windowProc5, SWT.Verify); - OS.gtk_editable_insert_text (handle, buffer3, buffer3.length, position); - OS.gtk_signal_handler_unblock_by_func (handle, windowProc5, SWT.Verify); - byte [] insert_text = Converter.wcsToMbcs (null, "insert-text", true); - OS.gtk_signal_emit_stop_by_name (handle, insert_text); - return 0; - } - } else { - // Delete - int address = OS.gtk_editable_get_chars (handle, int0, int1); - int length = OS.strlen (address); - byte [] buffer1 = new byte [length]; - OS.memmove (buffer1, address, length); - OS.g_free (address); - char [] buffer2 = Converter.mbcsToWcs (null, buffer1); - String oldText = new String (buffer2, 0, buffer2.length); - String newText = verifyText (oldText, int0, int1); - if (newText == null) { - byte [] delete_text = Converter.wcsToMbcs (null, "delete-text", true); - OS.gtk_signal_emit_stop_by_name (handle, delete_text); - return 0; - } - } - return 0; -} - -int processSelection (int int0, int int1, int int2) { - postEvent (SWT.DefaultSelection); - return 0; -} - -/** - * 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. - * - * @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 #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 - */ -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 (); - OS.gtk_editable_select_region (handle, 0, -1); -} - -/** - * 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> - * - * @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 (); -} - -/** - * 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. - * </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, visibility = echo == '\0'); - } -} - -/** - * Sets the editable state. - * - * @param editable the new editable state - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setEditable (boolean editable) { - checkWidget (); - OS.gtk_editable_set_editable (handle, editable); -} - -/** - * 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 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 setSelection (int start) { - checkWidget (); - OS.gtk_editable_set_position (handle, start); -} - -/** - * 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 - * usual array indexing rules. - * </p> - * - * @param start the start of the range - * @param end the end of the range - * - * @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 setSelection (int start, int end) { - checkWidget (); - OS.gtk_editable_set_position (handle, start); - OS.gtk_editable_select_region (handle, start, end); -} - -/** - * 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 - * usual array indexing rules. - * </p> - * - * @param selection the point - * - * @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 setSelection (Point selection) { - checkWidget (); - if (selection == null) error (SWT.ERROR_NULL_ARGUMENT); - OS.gtk_editable_set_position (handle, selection.x); - OS.gtk_editable_select_region (handle, 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 (); - GtkText widget= new GtkText(); - widget.default_tab_width=tabs; - OS.memmove(handle, widget, GtkText.sizeof); -} - -/** - * Sets the contents of the receiver to the given string. - * - * @param text 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); - OS.gtk_editable_delete_text (handle, 0, -1); - int [] position = new int [1]; - byte [] buffer = Converter.wcsToMbcs (null, string); - OS.gtk_editable_insert_text (handle, buffer, buffer.length, position); - OS.gtk_editable_set_position (handle, 0); -} - -/** - * Sets the maximum number of characters that the receiver - * is capable of holding to be the argument. - * - * @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> - */ -public void setTextLimit (int limit) { - checkWidget (); - if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO); - if ((style & SWT.SINGLE) != 0) { - textLimit = (short) limit; - OS.gtk_entry_set_max_length (handle, (short) limit); - } -} - -/** - * Sets the zero-relative index of the line which is currently - * at the top of the receiver. This index can change when lines - * are scrolled or new lines are added and removed. - * - * @param index the index of the top item - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void setTopIndex (int index) { - checkWidget (); - if ((style & SWT.SINGLE) != 0) return; - if (index > getLineCount()) return; - GtkAdjustment adjustment = new GtkAdjustment(); - int adjustmentHandle = OS.gtk_scrolled_window_get_vadjustment(scrolledHandle); - OS.memmove(adjustment, adjustmentHandle, GtkAdjustment.sizeof); - int adjust = (int)(index*adjustment.upper/getLineCount()); - if (adjust <= 0) { - adjust = 0; - verticalBar.setSelection(0); - } else { - verticalBar.setSelection(adjust); - } - OS.gtk_adjustment_value_changed(verticalBar.handle); - int topindex=getTopIndex(); - int lineheight = getLineHeight(); - while( topindex != index) { - adjust=adjust+lineheight; - verticalBar.setSelection(adjust+lineheight); - OS.gtk_adjustment_value_changed(verticalBar.handle); - topindex=getTopIndex(); - } -} - -void setWrap (boolean wrap) { - checkWidget (); - OS.gtk_text_set_word_wrap(handle, wrap ? 1 : 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 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> - */ -public void showSelection () { - checkWidget (); - if ((style & SWT.SINGLE) != 0) return; - int start_pos, end_pos, pos; - pos = OS.gtk_editable_get_position (handle); - GtkEditable widget = new GtkEditable (); - OS.memmove (widget, handle, GtkEditable.sizeof); - start_pos = Math.min(widget.selection_start_pos, widget.selection_end_pos) ; - end_pos = Math.max(widget.selection_start_pos, widget.selection_end_pos) ; - GtkText gtktext = new GtkText (); - OS.memmove (gtktext, handle, GtkText.sizeof); - int topCharIndex=gtktext.first_line_start_index; - if ( (topCharIndex > start_pos && topCharIndex < end_pos) || topCharIndex==start_pos || - topCharIndex == end_pos) return; - if (pos < start_pos || pos > end_pos) { - GtkAdjustment adjustment = new GtkAdjustment(); - int adjustmentHandle = OS.gtk_scrolled_window_get_vadjustment(scrolledHandle); - OS.memmove(adjustment, adjustmentHandle, GtkAdjustment.sizeof); - String tmpString= new String(getText(0,start_pos)); - int currentln=getLineNumberInString(tmpString, '\n'); - int adjust = (int)(currentln*adjustment.upper/getLineCount()-adjustment.page_increment); - if (adjust <= 0) - OS.gtk_adjustment_set_value (verticalBar.handle, 0); - else - OS.gtk_adjustment_set_value (verticalBar.handle, adjust); - OS.gtk_adjustment_value_changed(verticalBar.handle); - OS.gtk_editable_set_position (handle, widget.selection_end_pos); - OS.gtk_editable_select_region (handle, widget.selection_start_pos, widget.selection_end_pos); - } - -} - -String verifyText (String string, int start, int end) { - Event event = new Event (); - event.text = string; - event.start = start; - event.end = end; - sendEvent (SWT.Verify, event); - if (!event.doit) return null; - return event.text; -} - -int getLineNumberInString( String string,char delimiter) { - int count=0; - for (int i=0; i<string.length (); i++) { - if (string.charAt (i) == delimiter) count++; - } - return count; -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ToolBar.java deleted file mode 100644 index e1e5bedcf0..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ToolBar.java +++ /dev/null @@ -1,351 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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</dd> - * <dt><b>Events:</b></dt> - * <dd>(none)</dd> - * </dl> - * <p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */ - -public class ToolBar extends Composite { - int boxHandle, tempHandle; - -/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 ToolBar (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -void createHandle (int index) { - state |= HANDLE; - - /* FIXME - * We do not need an event box here, as event boxes - * have real X windows. - */ - boxHandle = OS.gtk_event_box_new (); - if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES); - - int orientation = ((style&SWT.VERTICAL)!=0)? - OS.GTK_ORIENTATION_VERTICAL : OS.GTK_ORIENTATION_HORIZONTAL; - handle = OS.gtk_toolbar_new (orientation, OS.GTK_TOOLBAR_BOTH); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - - tempHandle = OS.gtk_fixed_new(); - if (tempHandle == 0) error (SWT.ERROR_NO_HANDLES); -} - -void setHandleStyle() { - int relief = ((style&SWT.FLAT)!=0)? OS.GTK_RELIEF_NONE : OS.GTK_RELIEF_NORMAL; - OS.gtk_toolbar_set_button_relief(handle, relief); -} - -void configure() { - _connectParent(); - OS.gtk_container_add (boxHandle, handle); - // invisible handle to temporarily hold control (non-item) items - OS.gtk_toolbar_insert_widget (handle,tempHandle,new byte[1], new byte[1],0); -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - if (layout != null) super.computeSize(wHint, hHint, changed); - return _computeSize (wHint, hHint, changed); -} - -int eventHandle () { - return boxHandle; -} - -void showHandle() { - OS.gtk_widget_show (boxHandle); - OS.gtk_widget_show (handle); - OS.gtk_widget_realize (handle); - // don't show the temp fixed -} - -void register() { - super.register (); - WidgetTable.put (boxHandle, this); -} - -void deregister() { - super.deregister (); - WidgetTable.remove (boxHandle); -} - -int topHandle() { return boxHandle; } -int parentingHandle() { return tempHandle; } - -/** - * Returns whether the argument points to an OS widget that is - * implementing the receiver, i.e., one of my own handles - */ -boolean isMyHandle(int h) { - if (h==handle) return true; - if (h==tempHandle) return true; - if (h==boxHandle) return true; - return false; -} -void _connectChild (int h) { - // When we put a widget as a tool item, we don't know which item it is, yet. - OS.gtk_fixed_put(tempHandle, h, (short)0, (short)0); -} - - -/* - * === GEOMETRY === - */ - -boolean _setSize (int width, int height) { UtilFuncs.setSize(boxHandle, width, height); return true; } - - - -/** - * 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 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> - */ -public ToolItem getItem (Point point) { - 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - /* FIXME - * This code will return the wrong count for items, - * as list includes Window children - */ -// int list = OS.gtk_container_children (handle); -// return OS.g_list_length (list); - // TEMPORARY CODE - return getItems ().length; -} -/** - * 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 ToolItem [] getItems () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - int count = 0; - int list = OS.gtk_container_children (handle); - int length = OS.g_list_length (list); - ToolItem [] result = new ToolItem [length]; - for (int i=0; i<length; i++) { - int data = OS.g_list_nth_data (list, i); - Widget widget = WidgetTable.get (data); - if (widget instanceof ToolItem) { - result [count++] = (ToolItem) widget; - } - } - if (length == count) return result; - ToolItem [] newResult = new ToolItem [count]; - System.arraycopy (result, 0, newResult, 0, count); - return newResult; -} -/** - * 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return 1; -} - -Control _childFromHandle(int h) { - Widget child = WidgetTable.get(h); - if (child==null) return null; - if (child instanceof ToolItem) return null; // ToolItems are not our children - return (Control)child; -} - -/** - * 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - - // TEMPORARY CODE - ToolItem [] items = getItems (); - for (int i=0; i<items.length; i++) {
- if (item == items[i]) return i;
- } - return -1; -} -int processResize (int int0, int int1, int int2) { - ToolItem [] items = getItems (); - for (int i=0; i<items.length; i++) { - Control control = items [i].control; - if (control != null && !control.isDisposed ()) { - control.setBounds (items [i].getBounds ()); - } - } - return 0; -} - -void releaseHandle () { - super.releaseHandle (); - boxHandle = tempHandle = 0; -} - -void releaseWidget () { - ToolItem [] items = getItems (); - for (int i=0; i<items.length; i++) { - ToolItem item = items [i]; - if (!item.isDisposed ()) { - item.releaseWidget (); - item.releaseHandle (); - } - } - items = null; - super.releaseWidget (); -} - -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); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ToolItem.java deleted file mode 100644 index e20c76f1c0..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/ToolItem.java +++ /dev/null @@ -1,744 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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. - * <p> - * <dl> - * <dt><b>Styles:</b></dt> - * <dd>PUSH, CHECK, RADIO, SEPARATOR, DROP_DOWN</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection</dd> - * </dl> - * </p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - */ - -public class ToolItem extends Item { - int boxHandle; - ToolBar parent; - Control control; - Image hotImage, disabledImage; - int currentpixmap; - boolean drawHotImage; - int position; - boolean configured=false; - boolean shown=false; - private int tooltipsHandle; - -/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 ToolItem (ToolBar parent, int style) { - super (parent, checkStyle (style)); - this.parent = parent; - position = parent.getItemCount (); - createWidget (position); -} -/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 index to store the receiver in its parent - * - * @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 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_ITEM_NOT_ADDED); - } - position = index; - createWidget (index); -} -/** - * Adds the listener to the collection of listeners who will - * be notified when the control is selected, 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 - * - * @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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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); -} - -void createHandle (int index) { - state |= HANDLE; - int bits = SWT.SEPARATOR | SWT.RADIO | SWT.CHECK | SWT.PUSH; - switch (style & bits) { - case SWT.RADIO: - case SWT.CHECK: - _createToggleHandle(index); return; - case SWT.SEPARATOR: - _createSeparatorHandle(index); return; - case SWT.PUSH: - default: - _createPushHandle(index); return; - } -} - -private void _createSeparatorHandle(int index) { - boxHandle = OS.gtk_event_box_new(); - if (boxHandle==0) error(SWT.ERROR_NO_HANDLES); - boolean isVertical = (parent.getStyle()&SWT.VERTICAL) != 0; - handle = isVertical? OS.gtk_hseparator_new() : OS.gtk_vseparator_new(); - if (handle==0) error(SWT.ERROR_NO_HANDLES); -} -private void _createPushHandle(int index) { - handle = OS.gtk_toolbar_insert_element (parent.handle, - OS.GTK_TOOLBAR_CHILD_BUTTON, - 0, new byte[1], null, null, - 0, 0, 0, - index); - configured=true; - shown=true; -} -private void _createToggleHandle(int index) { - handle = OS.gtk_toolbar_insert_element (parent.handle, - OS.GTK_TOOLBAR_CHILD_TOGGLEBUTTON, - 0, new byte[1], null, null, - 0, 0, 0, - index); - configured=true; - shown=true; -} - - -void configure() { - // configure is done for non-separators - if (configured) return; - OS.gtk_toolbar_insert_widget ( - parent.handle, - topHandle(), - new byte[1], new byte[1], - position); - OS.gtk_container_add(boxHandle, handle); -} - -void showHandle() { - if (shown) return; - if ((parent.getStyle()&SWT.VERTICAL)!=0) OS.gtk_widget_set_usize(handle, 15, 3); - else OS.gtk_widget_set_usize(handle, 3, 15); - OS.gtk_widget_show(boxHandle); - OS.gtk_widget_show(handle); -} - -void register() { - super.register (); - if (boxHandle != 0) WidgetTable.put (boxHandle, this); -} - -void releaseHandle () { - super.releaseHandle (); - boxHandle = 0; -} - -void deregister() { - super.deregister (); - if (boxHandle != 0) WidgetTable.remove (boxHandle); -} - -int topHandle() { - return (boxHandle==0)? handle : boxHandle; -} - - -/** - * 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - return new Rectangle (widget.alloc_x, widget.alloc_y, widget.alloc_width, widget.alloc_height); -} -/** - * Returns the control that is used to fill the bounds of - * the item when the items 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - error(SWT.ERROR_NOT_IMPLEMENTED); - return null; -} - -public Display getDisplay () { - ToolBar parent = this.parent; - if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED); - return parent.getDisplay (); -} -/** - * Returns <code>true</code> if the receiver is enabled, and - * <code>false</code> otherwise. - * <p> - * A disabled control is typically not selectable from the - * user interface and draws with an inactive or "grayed" look. - * </p> - * - * @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> - */ -public boolean getEnabled () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - return (widget.flags & OS.GTK_SENSITIVE) != 0; -} -/** - * Returns the receiver's hot image if it has one, or null - * if it does not. - * <p> - * The hot image is displayed when the mouse enters the receiver. - * </p> - * - * @return the receiver's hot image - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public Image getHotImage () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return null; -} -/** - * 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) 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. When it is of type <code>TOGGLE</code>, - * it is selected when it is pushed. - * </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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return ""; -} -/** - * 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - return widget.alloc_width; -} -void hookEvents () { - if ((style & SWT.SEPARATOR) != 0) return; - signal_connect(handle, "clicked", SWT.Selection, 2); - signal_connect(handle, "enter-notify-event", SWT.MouseEnter, 3); - signal_connect(handle, "leave-notify-event", SWT.MouseExit, 3); -} -/** - * Returns <code>true</code> if the receiver is enabled, and - * <code>false</code> otherwise. - * <p> - * A disabled control is typically not selectable from the - * user interface and draws with an inactive or "grayed" look. - * </p> - * - * @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> - */ -public boolean isEnabled () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return getEnabled () && parent.isEnabled (); -} - -int processMouseEnter (int int0, int int1, int int2) { - drawHotImage = (parent.style & SWT.FLAT) != 0 && hotImage != null; - if ( drawHotImage && (currentpixmap != 0) ) { - OS.gtk_pixmap_set (currentpixmap, hotImage.pixmap, hotImage.mask); - } - return 0; -} - -int processMouseExit (int int0, int int1, int int2) { - if (drawHotImage) { - drawHotImage = false; - if (currentpixmap != 0 && image != null){ - OS.gtk_pixmap_set (currentpixmap, image.pixmap, image.mask); - } - } - return 0; -} -/* -int processPaint (int int0, int int1, int int2) { - if (ignorePaint) return 0; - Image currentImage = drawHotImage ? hotImage : image; - if (!getEnabled()) { - Display display = getDisplay (); - currentImage = disabledImage; - if (currentImage == null) { - currentImage = new Image (display, image, SWT.IMAGE_DISABLE); - } - } - if (currentpixmap != 0 && currentImage != null) - OS.gtk_pixmap_set (currentpixmap, currentImage.pixmap, currentImage.mask); - return 0; -} -*/ -int processSelection (int int0, int int1, int int2) { - if ((style & SWT.RADIO) != 0) { - this.setSelection (true); - ToolItem [] items = parent.getItems (); - int index = 0; - while (index < items.length && items [index] != this) index++; - ToolItem item; - int i = index; - while (--i >= 0 && ((item = items [i]).style & SWT.RADIO) != 0) { - item.setSelection (false); - } - i = index; - while (++i < items.length && ((item = items [i]).style & SWT.RADIO) != 0) { - item.setSelection (false); - } - } - Event event = new Event (); - postEvent (SWT.Selection, event); - return 0; -} -void releaseWidget () { - super.releaseWidget (); - tooltipsHandle = 0; - parent = null; -} -/** - * Removes the listener from the collection of listeners who will - * be notified when the control is selected. - * - * @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 #addSelectionListener - */ -public void removeSelectionListener(SelectionListener listener) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Selection, listener); - eventTable.unhook (SWT.DefaultSelection,listener); -} -/** - * Sets the control that is used to fill the bounds of - * the item when the items 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; - Control newControl = control; - Control oldControl = this.control; - if (oldControl == newControl) return; - if (oldControl != null) { - int topHandle = control.topHandle (); - int tempHandle = parent.tempHandle; - OS.gtk_widget_reparent (topHandle, tempHandle); - } - this.control = newControl; - if (newControl != null) { - if (handle != boxHandle) { - WidgetTable.remove (handle); - OS.gtk_widget_destroy (handle); - handle = boxHandle; - } - int topHandle = control.topHandle (); - OS.gtk_widget_reparent (topHandle, boxHandle); - //OS.gtk_widget_show (topHandle); - } else { - boolean isVertical = (parent.getStyle () & SWT.VERTICAL) != 0; - handle = isVertical ? OS.gtk_hseparator_new () : OS.gtk_vseparator_new (); - if (handle == 0) error(SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (boxHandle, handle); - } -} -/** - * Sets the receiver's disabled image to the argument, which may be - * null indicating that no disabled image should be displayed. - * <p> - * The disbled 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - OS.gtk_widget_set_sensitive (handle, enabled); -} -/** - * 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if ((style & SWT.SEPARATOR) != 0) return; - hotImage = image; -} -public void setImage (Image image) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - super.setImage (image); - if ((style & SWT.SEPARATOR) != 0) return; - int list = OS.gtk_container_children (handle); - if (list != 0) { - int widget = OS.g_list_nth_data (list, 0); - if (widget != 0) OS.gtk_widget_destroy (widget); - } - if (image != null) { - int pixmap = OS.gtk_pixmap_new (image.pixmap, image.mask); - OS.gtk_container_add (handle, pixmap); - OS.gtk_widget_show (pixmap); - currentpixmap = pixmap; - } -} -/** - * 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. When it is of type <code>TOGGLE</code>, - * it is selected when it is pushed. - * </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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return; - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_toggle_button_set_active (handle, selected); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} -public void setText (String string) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if ((style & SWT.SEPARATOR) != 0) return; - text = string; - if ((style & SWT.ARROW) != 0) return; - int length = string.length (); - char [] text = new char [length + 1]; - char [] pattern = new char [length + 1]; - string.getChars (0, length, text, 0); - int i = 0, j = 0; - while (i < length) { - pattern [j] = ' '; - if (text [i] == '&') { - i++; - if (i < length && text [i] != '&') { - pattern [j] = '_'; - } - } - text [j++] = text [i++]; - } - while (j < i) { - text [j] = pattern [j] = '\0'; - j++; - } - int list = OS.gtk_container_children (handle); - if (list != 0) { - int widget = OS.g_list_nth_data (list, 0); - if (widget != 0) OS.gtk_widget_destroy (widget); - } - byte [] buffer1 = Converter.wcsToMbcs (null, text); - int label = OS.gtk_label_new (buffer1); - byte [] buffer2 = Converter.wcsToMbcs (null, pattern); - OS.gtk_label_set_pattern (label, buffer2); - OS.gtk_container_add (handle, label); - OS.gtk_widget_show (label); -} -/** - * Sets the receiver's tool tip text to the argument, which - * may be null indicating that no tool tip text should be shown. - * - * @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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (tooltipsHandle == 0) tooltipsHandle = OS.gtk_tooltips_new(); - byte [] buffer = Converter.wcsToMbcs (null, string, true); - OS.gtk_tooltips_set_tip(tooltipsHandle, handle, buffer, null); -} -/** - * 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if ((style & SWT.SEPARATOR) == 0) return; - - Point size = control.computeSize(width, SWT.DEFAULT); - control.setSize(size); -} -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Tracker.java deleted file mode 100644 index dfc7b30b0e..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Tracker.java +++ /dev/null @@ -1,388 +0,0 @@ -package org.eclipse.swt.widgets;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-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 rubber banding rectangles.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Move</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- */
-public class Tracker extends Widget {
- Composite parent;
- Display display;
- boolean tracking, stippled;
- Rectangle [] rectangles = new Rectangle [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
- * for all SWT widget classes should include a comment which
- * describes the style constants which are applicable to the class.
- * </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
- * @see Widget#checkSubclass
- * @see Widget#getStyle
- */
-public Tracker (Composite parent, int style) {
- super (parent, style);
- this.parent = parent;
- display = parent.getDisplay ();
-}
-
-/**
- * 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
- * for all SWT widget classes should include a comment which
- * describes the style constants which are applicable to the class.
- * </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>
- */
-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 = style;
- this.display = display;
-}
-
-
-
-/*
- * === ADD / REMOVE LISTENERS ===
- */
-
-/**
- * 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.Move,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 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);
-}
-
-
-
-
-/*
- * === PUBLIC ACCESSORS ===
- */
-
-public Display getDisplay () {
- return display;
-}
-
-/**
- * Returns the bounds of the Rectangles being drawn.
- *
- * @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();
- return rectangles;
-}
-
-/**
- * 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;
-}
-
-/**
- * Specify the rectangles that should be drawn.
- *
- * @param rectangles the bounds of the rectangles to be 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 void setRectangles (Rectangle [] rectangles) {
- checkWidget();
- this.rectangles = rectangles;
-}
-
-/**
- * Change 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;
-}
-
-
-
-/*
- * === PUBLIC FUNCTIONALITY ===
- */
-
-/**
- * Stop displaying the tracker 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 void close () {
- checkWidget();
- tracking = false;
-}
-
-/**
- * Start displaying the Tracker 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 open () {
- checkWidget();
- int xWindow = calculateWindow();
- boolean cancelled=false;
- tracking = true;
- drawRectangles ();
-
- int[] newX = new int[1];
- int[] newY = new int[1];
- int[] oldX = new int[1];
- int[] oldY = new int[1];
- OS.gdk_window_get_pointer(xWindow, oldX,oldY, 0);
-
- while (tracking) {
- if (parent != null && parent.isDisposed ()) break;
- int eventType = waitEvent();
- switch (eventType) {
- case OS.GDK_BUTTON_RELEASE:
- case OS.GDK_MOTION_NOTIFY:
- OS.gdk_window_get_pointer(xWindow, newX,newY, 0);
- if (oldX [0] != newX [0] || oldY [0] != newY [0]) {
- drawRectangles ();
- for (int i=0; i<rectangles.length; i++) {
- rectangles [i].x += newX [0] - oldX [0];
- rectangles [i].y += newY [0] - oldY [0];
- }
- Event event = new Event();
- event.x = newX[0];
- event.y = newY[0];
- sendEvent (SWT.Move,event);
- drawRectangles ();
- oldX [0] = newX [0]; oldY [0] = newY [0];
- }
- tracking = (eventType != OS.GDK_BUTTON_RELEASE);
- break;
- case OS.GDK_KEY_PRESS:
-// error(SWT.ERROR_NOT_IMPLEMENTED);
- /*
- XKeyEvent keyEvent = new XKeyEvent ();
- OS.memmove (keyEvent, xEvent, XKeyEvent.sizeof);
- if (keyEvent.keycode != 0) {
- int [] keysym = new int [1];
- OS.XLookupString (keyEvent, null, 0, keysym, null);
- keysym [0] &= 0xFFFF;
- tracking = keysym [0] != OS.XK_Escape && keysym [0] != OS.XK_Cancel;
- cancelled = !tracking;
- }*/
- break;
- } // switch
- } // while
- drawRectangles(); // clean up our mess
- tracking = false;
- return !cancelled;
-}
-
-
-
-private void drawRectangles () {
- int xWindow = calculateWindow();
- if (parent != null) {
- if (parent.isDisposed ()) return;
- parent.getShell ().update ();
- } else {
- display.update ();
- }
-
- int gc = OS.gdk_gc_new(xWindow);
- if (gc==0) error(SWT.ERROR_UNSPECIFIED);
-
- /* White foreground */
- int colormap = OS.gdk_colormap_get_system();
- GdkColor color = new GdkColor();
- OS.gdk_color_white(colormap, color);
- OS.gdk_gc_set_foreground(gc, color);
-
- /* Draw on top of inferior widgets */
- OS.gdk_gc_set_subwindow(gc, OS.GDK_INCLUDE_INFERIORS);
-
- /* XOR */
- OS.gdk_gc_set_function(gc, OS.GDK_XOR);
-
- for (int i=0; i<rectangles.length; i++) {
- Rectangle rect = rectangles [i];
- OS.gdk_draw_rectangle(xWindow, gc, 0, rect.x, rect.y, rect.width, rect.height);
- }
- OS.gdk_gc_destroy(gc);
-}
-/*
- * Wait for an event to show up.
- * Return the event's type as a GdkEventType.
- */
-private int waitEvent() {
- int[] eventType = new int[1];
- int eventPtr;
-
- while (true) {
- eventPtr = OS.gdk_event_get();
- if (eventPtr != 0) {
- // hack, must implement memmove properly
- // GdkEvent event = new GdkEvent(eventPtr);
- OS.memmove(eventType, eventPtr, 4);
- OS.gdk_event_free(eventPtr);
- return eventType[0];
- }
- else {
- try { Thread.sleep(50); } catch (Exception ex) {}
- }
- }
-}
-
-/*
- * Figure which GdkWindow we'll draw on.
- * That's normally the root X window, or the parent's GdkWindow if we have a parent.
- */
-private int calculateWindow() {
- int answer;
- if (parent == null) {
- answer = OS.GDK_ROOT_PARENT();
- } else {
- answer = parent._gdkWindow();
- }
- if (answer==0) error(SWT.ERROR_UNSPECIFIED);
- return answer;
-}
-
-public void setCursor (Cursor value) {
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Tree.java deleted file mode 100644 index 95833415cb..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Tree.java +++ /dev/null @@ -1,968 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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 issue notificiation 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> - * 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>SINGLE, MULTI, CHECK</dd> - * <dt><b>Events:</b></dt> - * <dd>Selection, DefaultSelection, Collapse, Expand</dd> - * </dl> - * <p> - * IMPORTANT: This class is <em>not</em> intended to be subclassed. - * </p> - */ -public class Tree extends Composite { - TreeItem [] items; - boolean selected, doubleSelected; - int check, uncheck; - static int CELL_SPACING = 1; - - /* - * NOT DONE - These need to be moved to display, - * they are not thread safe. Consider moving the - * methods that access them to Display. - */ - static TreeItem [] Items; - static int Index, Count, Sibling; - -/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 Tree (Composite parent, int style) { - super (parent, checkStyle (style)); -} - -static int checkStyle (int style) { - /* - * To be compatible with Windows, force the H_SCROLL - * and V_SCROLL style bits. On Windows, it is not - * possible to create a tree without scroll bars. - */ - style |= SWT.H_SCROLL | SWT.V_SCROLL; - return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0); -} - -Point _getClientAreaSize () { - return UtilFuncs.getSize(handle); -} - -boolean _setSize(int width, int height) { - if (!UtilFuncs.setSize (eventBoxHandle, width, height)) return false; - UtilFuncs.setSize (scrolledHandle, width, height); - return true; -} - -/** - * Adds the listener to the collection of listeners who will - * be notified when the receiver's selection changes, 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 reciever has <code>SWT.CHECK</code> style set 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. - * </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 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); -} - -public Point computeSize (int wHint, int hHint, boolean changed) { - checkWidget (); - if (wHint == SWT.DEFAULT) wHint = 200; - return _computeSize (wHint, hHint, changed); -} - -void configure() { - _connectParent(); - OS.gtk_container_add(eventBoxHandle, fixedHandle); - OS.gtk_fixed_put (fixedHandle, scrolledHandle, (short)0, (short)0); - OS.gtk_container_add (scrolledHandle, handle); -} - -void createHandle (int index) { - state |= HANDLE; - - eventBoxHandle = OS.gtk_event_box_new(); - if (eventBoxHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - - fixedHandle = OS.gtk_fixed_new (); - if (fixedHandle == 0) SWT.error (SWT.ERROR_NO_HANDLES); - - scrolledHandle = OS.gtk_scrolled_window_new(0,0); - if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES); - - handle = OS.gtk_ctree_new (1, 0); - if (handle == 0) SWT.error (SWT.ERROR_NO_HANDLES); -} - -int createCheckPixmap(boolean checked) { - /* - * The box will occupy the whole item width. - */ - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); - int check_height = clist.row_height-1; - int check_width = check_height; - - GdkVisual visual = new GdkVisual(); - OS.memmove(visual, OS.gdk_visual_get_system(), GdkVisual.sizeof); - int pixmap = OS.gdk_pixmap_new(0, check_width, check_height, visual.depth); - - int gc = OS.gdk_gc_new(pixmap); - - GdkColor fgcolor = new GdkColor(); - fgcolor.pixel = 0xFFFFFFFF; - fgcolor.red = (short) 0xFFFF; - fgcolor.green = (short) 0xFFFF; - fgcolor.blue = (short) 0xFFFF; - OS.gdk_gc_set_foreground(gc, fgcolor); - OS.gdk_draw_rectangle(pixmap, gc, 1, 0,0, check_width,check_height); - - fgcolor = new GdkColor(); - fgcolor.pixel = 0; - fgcolor.red = (short) 0; - fgcolor.green = (short) 0; - fgcolor.blue = (short) 0; - OS.gdk_gc_set_foreground(gc, fgcolor); - - OS.gdk_draw_line(pixmap, gc, 0,0, 0,check_height-1); - OS.gdk_draw_line(pixmap, gc, 0,check_height-1, check_width-1,check_height-1); - OS.gdk_draw_line(pixmap, gc, check_width-1,check_height-1, check_width-1,0); - OS.gdk_draw_line(pixmap, gc, check_width-1,0, 0,0); - - /* now the cross check */ - if (checked) { - OS.gdk_draw_line(pixmap, gc, 0,0, check_width-1,check_height-1); - OS.gdk_draw_line(pixmap, gc, 0,check_height-1, check_width-1,0); - } - - OS.gdk_gc_destroy(gc); - return pixmap; -} - -void createItem (TreeItem item, int node, int index) { - 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; - } - - /* Feature in GTK. - * When the selection policy is BROWSE (which is what we use for SINGLE), - * the first item added gets automatically selected. This leads to some - * nontrivial complications which one better avoid. The hack is to - * temporarily put a value other than GTK_SELECTION_BROWSE into the - * selectionMode field just for the insertion. Do not use the policy - * changing API because this will cause a selection callback. - */ -// GtkCTree ctree = new GtkCTree (); -// OS.memmove (ctree, handle, GtkCTree.sizeof); -// int selection_mode = ctree.selection_mode; -// ctree.selection_mode = OS.GTK_SELECTION_MULTIPLE; -// OS.memmove (handle, ctree, GtkCTree.sizeof); - int [] sm = new int [1]; - OS.memmove (sm, handle+148, 1); - int selectionMode = sm[0]; - sm [0] = OS.GTK_SELECTION_MULTIPLE; - OS.memmove (handle+148, sm, 1); -// FIXME - int sibling = index == -1 ? 0 : findSibling (node, index); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - item.handle = OS.gtk_ctree_insert_node (handle, node, sibling, null, (byte) 2, uncheck, 0, uncheck, 0, false, false); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); - if (item.handle == 0) error (SWT.ERROR_ITEM_NOT_ADDED); - OS.gtk_ctree_node_set_row_data (handle, item.handle, id + 1); - -// OS.memmove (ctree, handle, GtkCTree.sizeof); -// ctree.selection_mode = selection_mode; -// OS.memmove (handle, ctree, GtkCTree.sizeof); - sm [0] = selectionMode; - OS.memmove (handle+148, sm, 1); - items [id] = item; -} - -void createWidget (int index) { - super.createWidget (index); - items = new TreeItem [4]; -} - -/** - * 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 root = OS.gtk_ctree_node_nth (handle, 0); - if (root == 0) return; - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_ctree_unselect_recursive (handle, root); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -void destroyItem (TreeItem item) { - int node = item.handle; - Callback GtkCTreeFunc = new Callback (this, "GtkCTreeDispose", 3); - int address = GtkCTreeFunc.getAddress (); - OS.gtk_ctree_post_recursive (handle, node, address, 0); - GtkCTreeFunc.dispose (); - OS.gtk_signal_handler_block_by_data (handle, SWT.Collapse); - OS.gtk_ctree_remove_node (handle, node); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Collapse); -} - -int findSibling (int node, int index) { - int depth = 1; - if (node != 0) { - int data = OS.g_list_nth_data (node, 0); - GtkCTreeRow row = new GtkCTreeRow (); - OS.memmove (row, data, GtkCTreeRow.sizeof); - depth = row.level + 1; - } - Index = 0; - Sibling = 0; - Callback GtkCTreeCountItems = new Callback (this, "GtkCTreeFindSibling", 3); - int address0 = GtkCTreeCountItems.getAddress (); - OS.gtk_ctree_post_recursive_to_depth (handle, node, depth, address0, index); - GtkCTreeCountItems.dispose (); - if (Sibling == node) Sibling = 0; - return Sibling; -} - -public boolean forceFocus () { - checkWidget (); - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - boolean result = super.forceFocus (); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); - return result; -} - -/** - * 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 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> - */ -public TreeItem getItem (Point point) { - checkWidget (); - int [] row = new int [1], column = new int [1]; - int code = OS.gtk_clist_get_selection_info (handle, point.x, point.y, row, column); - if (code == 0) return null; - int node = OS.gtk_ctree_node_nth (handle, row [0]); - int index = OS.gtk_ctree_node_get_row_data (handle, node) - 1; - return items [index]; -} - -/** - * 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 getItemCount (0); -} - -int getItemCount (int node) { - int depth = 1; - if (node != 0) { - int data = OS.g_list_nth_data (node, 0); - GtkCTreeRow row = new GtkCTreeRow (); - OS.memmove (row, data, GtkCTreeRow.sizeof); - depth = row.level + 1; - } - Count = 0; - Callback GtkCTreeCountItems = new Callback (this, "GtkCTreeCountItems", 3); - int address0 = GtkCTreeCountItems.getAddress (); - OS.gtk_ctree_post_recursive_to_depth (handle, node, depth, address0, node); - GtkCTreeCountItems.dispose (); - return Count; -} - -/** - * 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 (); - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); - return clist.row_height + CELL_SPACING; -} - -/** - * Returns the number 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 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 TreeItem [] getItems () { - checkWidget(); - return getItems (0); -} - -TreeItem [] getItems (int node) { - int depth = 1; - if (node != 0) { - int data = OS.g_list_nth_data (node, 0); - GtkCTreeRow row = new GtkCTreeRow (); - OS.memmove (row, data, GtkCTreeRow.sizeof); - depth = row.level + 1; - } - Count = 0; - Callback GtkCTreeCountItems = new Callback (this, "GtkCTreeCountItems", 3); - int address0 = GtkCTreeCountItems.getAddress (); - OS.gtk_ctree_post_recursive_to_depth (handle, node, depth, address0, node); - GtkCTreeCountItems.dispose (); - Items = new TreeItem [Count]; - Count = 0; - Callback GtkCTreeGetItems = new Callback (this, "GtkCTreeGetItems", 3); - int address1 = GtkCTreeGetItems.getAddress (); - OS.gtk_ctree_post_recursive_to_depth (handle, node, depth, address1, node); - GtkCTreeGetItems.dispose (); - TreeItem [] result = Items; - Items = null; - return result; -} - -/** - * 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; -} - -/** - * Returns an array of <code>TreeItem</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 TreeItem[] getSelection () { - checkWidget(); - GtkCList clist = new GtkCList(); - OS.memmove (clist, handle, GtkCList.sizeof); - if (clist.selection == 0) return new TreeItem [0]; - int length = OS.g_list_length (clist.selection); - TreeItem [] result = new TreeItem [length]; - for (int i=0; i<length; i++) { - int node = OS.g_list_nth_data (clist.selection, i); - int index = OS.gtk_ctree_node_get_row_data (handle, node) - 1; - result [i] = items [index]; - } - 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(); - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); - if (clist.selection == 0) return 0; - return OS.g_list_length (clist.selection); -} - -int GtkCTreeCountItems (int ctree, int node, int data) { - if (data != node) Count++; - return 0; -} - -int GtkCTreeFindSibling (int ctree, int node, int data) { - if (Index == -1) return 0; - Index = data == Index ? -1 : Index + 1; - Sibling = node; - return 0; -} - -int GtkCTreeGetItems (int ctree, int node, int data) { - if (data != node) { - int index = OS.gtk_ctree_node_get_row_data (ctree, node) - 1; - Items [Count++] = items [index]; - } - return 0; -} - -int GtkCTreeDispose (int ctree, int node, int data) { - int index = OS.gtk_ctree_node_get_row_data (ctree, node) - 1; - OS.gtk_ctree_node_set_row_data (ctree, node, 0); - TreeItem item = items [index]; - item.releaseWidget (); - item.releaseHandle (); - items [index] = null; - return 0; -} - -void hookEvents () { - //TO DO - get rid of enter/exit for mouse crossing border - super.hookEvents (); - signal_connect (handle, "tree_select_row", SWT.Selection, 4); - signal_connect (handle, "tree_unselect_row", SWT.Selection, 4); - signal_connect (handle, "tree_expand", SWT.Expand, 3); - signal_connect (handle, "tree_collapse", SWT.Collapse, 3); -} - -int topHandle() { return eventBoxHandle; } -int parentingHandle() { return fixedHandle; } - -boolean isMyHandle(int h) { - if (h==fixedHandle) return true; - if (h==scrolledHandle) return true; - if (h==handle) return true; - return false; -} - -int processCollapse (int int0, int int1, int int2) { - int index = OS.gtk_ctree_node_get_row_data (handle, int0) - 1; - Event event = new Event (); - event.item = items [index]; - /* - * This code is intentionally commented. - * Not yet sure if freezing improves the - * look when a tree is collapsed. - */ -// OS.gtk_clist_freeze (handle); - sendEvent (SWT.Collapse, event); -// OS.gtk_clist_thaw (handle); - return 0; -} - -int processExpand (int int0, int int1, int int2) { - int index = OS.gtk_ctree_node_get_row_data (handle, int0) - 1; - Event event = new Event (); - event.item = items [index]; - OS.gtk_clist_freeze (handle); - sendEvent (SWT.Expand, event); - OS.gtk_clist_thaw (handle); - boolean [] expanded = new boolean [1]; - OS.gtk_ctree_get_node_info (handle, int0, null, null, null, null, null, null, null, expanded); - if (!expanded [0]) { - OS.gtk_signal_handler_block_by_data (handle, SWT.Expand); - OS.gtk_ctree_expand (handle, int0); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Expand); - } - return 0; -} - -int processMouseDown (int callData, int arg1, int int2) { - doubleSelected = false; - int result = super.processMouseDown (callData, arg1, int2); - if ((style & SWT.MULTI) != 0) selected = true; - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, callData, GdkEventButton.sizeof); - int x = (int) gdkEvent.x, y = (int) gdkEvent.y; - if ((style & SWT.CHECK) != 0) { - if (!OS.gtk_ctree_is_hot_spot (handle, x, y)) { - int [] row = new int [1], column = new int [1]; - int code = OS.gtk_clist_get_selection_info (handle, x, y, row, column); - if (code != 0) { - int node = OS.gtk_ctree_node_nth (handle, row [0]); - int crow = OS.g_list_nth_data (node, 0); - GtkCTreeRow row_data = new GtkCTreeRow (); - OS.memmove (row_data, crow, GtkCTreeRow.sizeof); - GtkCTree ctree = new GtkCTree(); - OS.memmove (ctree, handle, GtkCTree.sizeof); - int nX = ctree.hoffset + ctree.tree_indent * row_data.level - 2; - int nY = ctree.voffset + (ctree.row_height + 1) * row [0] + 2; - int [] unused = new int [1], check_width = new int [1], check_height = new int [1]; - OS.gdk_window_get_geometry (check, unused, unused, check_width, check_height, unused); - if (nX <= x && x <= nX + check_width [0]) { - if (nY <= y && y <= nY + check_height [0]) { - byte [] spacing = new byte [1]; - boolean [] is_leaf = new boolean [1], expanded = new boolean [1]; - int [] pixmap = new int [1], mask = new int [1]; - int index = OS.gtk_ctree_node_get_row_data (handle, node) - 1; - byte [] text = Converter.wcsToMbcs (null, items [index].getText (), true); - OS.gtk_ctree_get_node_info (handle, node, null, spacing, pixmap, mask, pixmap, mask, is_leaf, expanded); - pixmap [0] = pixmap [0] == check ? uncheck : check; - OS.gtk_ctree_set_node_info (handle, node, text, spacing [0], pixmap [0], mask [0], pixmap [0], mask [0], is_leaf [0], expanded [0]); - Event event = new Event (); - event.detail = SWT.CHECK; - event.item = items [index]; - postEvent (SWT.Selection, event); - } - } - } - } - } - if (gdkEvent.type == OS.GDK_2BUTTON_PRESS) { - if (!OS.gtk_ctree_is_hot_spot (handle, x, y)) { - int [] row = new int [1], column = new int [1]; - int code = OS.gtk_clist_get_selection_info (handle, x, y, row, column); - if (code != 0) doubleSelected = true; - } - } - return result; -} - -int processMouseUp (int callData, int arg1, int int2) { - int result = super.processMouseUp (callData, arg1, int2); - /* - * Feature in GTK. When an item is reselected in a - * mulit-select tree, GTK does not issue notification. - * The fix is to detect that the mouse was released over - * a selected item when no selection signal was set and - * issue a fake selection event. - * - * Feature in GTK. Double selection can only be implemented - * in a mouse up handler for a tree unlike the list,the event - * that caused the select signal is not included when the select - * signal is issued. - */ - GdkEventButton gdkEvent = new GdkEventButton (); - OS.memmove (gdkEvent, callData, GdkEventButton.sizeof); - int x = (int) gdkEvent.x, y = (int) gdkEvent.y; - if (!OS.gtk_ctree_is_hot_spot (handle, x, y)) { - if ((style & SWT.SINGLE) != 0) { - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); - int list = clist.selection; - if (list != 0 && OS.g_list_length (list) != 0) { - int node = OS.g_list_nth_data (list, 0); - int index = OS.gtk_ctree_node_get_row_data (handle, node) - 1; - Event event = new Event (); - event.item = items [index]; - if (doubleSelected) { - postEvent (SWT.DefaultSelection, event); - } else { - postEvent (SWT.Selection, event); - } - } - selected = false; - } - if ((style & SWT.MULTI) != 0) { - int [] row = new int [1], column = new int [1]; - int code = OS.gtk_clist_get_selection_info (handle, x, y, row, column); - if (code != 0) { - int focus = OS.gtk_ctree_node_nth (handle, row [0]); - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); - if (selected && clist.selection != 0) { - int length = OS.g_list_length (clist.selection); - for (int i=0; i<length; i++) { - int node = OS.g_list_nth_data (clist.selection, i); - if (node == focus) { - int index = OS.gtk_ctree_node_get_row_data (handle, node) - 1; - Event event = new Event (); - event.item = items [index]; - if (doubleSelected) { - postEvent (SWT.DefaultSelection, event); - } else { - postEvent (SWT.Selection, event); - } - } - } - } - } - selected = false; - } - } - doubleSelected = false; - return result; -} - -int processSelection (int int0, int int1, int int2) { - if ((style & SWT.SINGLE) != 0) { - selected = true; - return 0; - } - GtkCList clist = new GtkCList (); - OS.memmove (clist, handle, GtkCList.sizeof); - int focus = OS.gtk_ctree_node_nth (handle, clist.focus_row); - if (focus != int0) return 0; - if ((style & SWT.MULTI) != 0) selected = false; - int index = OS.gtk_ctree_node_get_row_data (handle, int0) - 1; - Event event = new Event (); - event.item = items [index]; - postEvent (SWT.Selection, event); - return 0; -} - -void releaseWidget () { - for (int i=0; i<items.length; i++) { - TreeItem item = items [i]; - if (item != null && !item.isDisposed ()) { - item.releaseWidget (); - item.releaseHandle (); - } - } - items = null; - if (check != 0) OS.gdk_pixmap_unref (check); - if (uncheck != 0) OS.gdk_pixmap_unref (uncheck); - check = uncheck = 0; - super.releaseWidget (); -} - -/** - * Removes all of the items from the receiver. - * <p> - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public void removeAll () { - checkWidget (); - OS.gtk_ctree_remove_node (handle, 0); - for (int i=0; i<items.length; i++) { - TreeItem item = items [i]; - if (item != null && !item.isDisposed ()) { - item.releaseWidget (); - item.releaseHandle (); - } - } - items = new TreeItem [4]; -} - -/** - * Removes the listener from the collection of listeners who will - * be notified when the receiver's selection changes. - * - * @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); -} - -/** - * Selects all 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 void selectAll () { - checkWidget(); - int root = OS.gtk_ctree_node_nth (handle, 0); - if (root == 0) return; - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_ctree_select_recursive (handle, root); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); -} - -void setHandleStyle () { - int mode = (style & SWT.MULTI) != 0 ? OS.GTK_SELECTION_EXTENDED : OS.GTK_SELECTION_BROWSE; - OS.gtk_clist_set_selection_mode (handle, mode); -} - -/** - * 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 array of items is null</li> - * <li>ERROR_INVALID_ARGUMENT - if one of 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#deselectAll() - */ -public void setSelection (TreeItem [] items) { - checkWidget(); - if (items == null) error (SWT.ERROR_NULL_ARGUMENT); - int root = OS.gtk_ctree_node_nth (handle, 0); - if (root == 0) return; - OS.gtk_signal_handler_block_by_data (handle, SWT.Selection); - OS.gtk_ctree_unselect_recursive (handle, root); - int index = 0, length = items.length; - while (index < length) { - TreeItem item = items [index]; - if (item != null) { - if (item.isDisposed ()) break; - OS.gtk_ctree_select (handle, item.handle); - } - index++; - } - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Selection); - if (index != length) error (SWT.ERROR_INVALID_ARGUMENT); -} - -void showHandle() { - OS.gtk_widget_show (eventBoxHandle); - OS.gtk_widget_show (fixedHandle); - OS.gtk_widget_show (scrolledHandle); - OS.gtk_widget_show (handle); - OS.gtk_widget_realize (handle); - - if ((style & SWT.CHECK) != 0) { - uncheck = createCheckPixmap(false); - check = createCheckPixmap(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 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 Tree#showItem(TreeItem) - */ -public void showSelection () { - checkWidget(); - GtkCList clist = new GtkCList (); - OS.memmove(clist, handle, GtkCList.sizeof); - if (clist.selection == 0) return; - if (OS.g_list_length (clist.selection) == 0) return; - int node = OS.g_list_nth_data (clist.selection, 0); - int index = OS.gtk_ctree_node_get_row_data (handle, node) - 1; - showItem (items [index]); -} - -/** - * 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); - int node = item.handle; - int visibility = OS.gtk_ctree_node_is_visible (handle, node); - if (visibility != OS.GTK_VISIBILITY_NONE) return; - if (!OS.gtk_ctree_is_viewable (handle, node)) { - int parent = node; - GtkCTreeRow row = new GtkCTreeRow (); - OS.gtk_signal_handler_block_by_data (handle, SWT.Expand); - do { - int data = OS.g_list_nth_data (parent, 0); - OS.memmove (row, data, GtkCTreeRow.sizeof); - if ((parent = row.parent) == 0) break; - OS.gtk_ctree_expand (handle, parent); - } while (true); - OS.gtk_signal_handler_unblock_by_data (handle, SWT.Expand); - } - OS.gtk_ctree_node_moveto (handle, node, 0, 0.0f, 0.0f); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TreeItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TreeItem.java deleted file mode 100644 index cafd7782d3..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/TreeItem.java +++ /dev/null @@ -1,496 +0,0 @@ -package org.eclipse.swt.widgets;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-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>
- */
-public class TreeItem extends Item {
- Tree parent;
- int index;
-
-/**
- * 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
- * for all SWT widget classes should include a comment which
- * describes the style constants which are applicable to the class.
- * </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 TreeItem (Tree parent, int style) {
- super (parent, style);
- this.parent = parent;
- parent.createItem (this, 0, -1);
-}
-
-/**
- * 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
- * for all SWT widget classes should include a comment which
- * describes the style constants which are applicable to the class.
- * </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 index to store the receiver in its parent
- *
- * @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, int index) {
- super (parent, style);
- if (index < 0) error (SWT.ERROR_INVALID_RANGE);
- this.parent = parent;
- parent.createItem (this, 0, index);
-}
-
-/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </p> - * - * @param parentItem 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 TreeItem (TreeItem parentItem, int style) {
- super (checkNull (parentItem).getParent(), style);
- this.parent = parentItem.getParent ();
- parent.createItem (this, parentItem.handle, -1);
-}
-
-/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </p> - * - * @param parentItem 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 index to store the receiver in its parent - * - * @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, int index) {
- super (checkNull (parentItem).getParent (), style);
- if (index < 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- this.parent = parentItem.getParent ();
- parent.createItem (this, parentItem.handle, index);
-}
-
-static TreeItem checkNull (TreeItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-
-/** - * 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 () {
- int ctree = parent.handle;
- GtkCTree tree = new GtkCTree();
- OS.memmove(tree, ctree, GtkCTree.sizeof);
-
- GtkAdjustment adjustment = new GtkAdjustment ();
- OS.memmove (adjustment, tree.vadjustment, GtkAdjustment.sizeof);
- float vaj = adjustment.value;
- OS.memmove (adjustment, tree.hadjustment, GtkAdjustment.sizeof);
- float haj = adjustment.value;
- int columnHandle = tree.column;
-
- int height=parent.getItemHeight();
-
- int row_list = tree.row_list; int level=0;
- int count = OS.g_list_length (row_list);
- int index=0;
- while (index<count) {
- int data = OS.g_list_nth (row_list, index);
- if (handle == data){
- int rowHandle = OS.g_list_nth_data (row_list, index);
- GtkCTreeRow row = new GtkCTreeRow();
- OS.memmove(row, rowHandle, GtkCTreeRow.sizeof);
- level = row.level;
- break;
- }
- index++;
- }
- int y = height*index + Tree.CELL_SPACING + tree.voffset + 2;
-
- int [] buffer = new int [1]; byte [] spacing = new byte [1];
- boolean [] is_leaf = new boolean [1], expanded = new boolean [1];
- int [] pixmap_closed = new int [1], mask_closed= new int [1], pixmap_opened= new int [1], mask_opened= new int [1];
- OS.gtk_ctree_get_node_info (ctree, handle, buffer, spacing, pixmap_closed, mask_closed, pixmap_opened, mask_opened, is_leaf, expanded);
- int length = OS.strlen (buffer[0]);
- byte [] buffer1 = new byte [length];
- OS.memmove (buffer1, buffer[0], length);
- int styleHandle = OS.gtk_ctree_node_get_row_style(ctree, handle);
- if (styleHandle == 0)
- styleHandle = OS.gtk_widget_get_style(ctree);
- GtkStyle style = new GtkStyle();
- OS.memmove(style, styleHandle, GtkStyle.sizeof);
- int width = OS.gdk_string_width(style.font, buffer1);
-
-// x = (short)column.area_x+tree.tree_indent*(level-1)+spacing[0]+tree.hoffset;
- int x = 33+tree.tree_indent*(level-1)+spacing[0]+tree.hoffset;
-
- return new Rectangle (x, y, width, height);
-}
-
-/** - * 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.style & SWT.CHECK) == 0) return false;
- int ctree = parent.handle;
- int [] pixmap = new int [1];
- OS.gtk_ctree_get_node_info (ctree, handle, null, null, pixmap, null, null, null, null, null);
- return pixmap [0] == parent.check;
-}
-
-public Display getDisplay () {
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-
-/** - * 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 ctree = parent.handle;
- boolean [] buffer = new boolean [1];
- OS.gtk_ctree_get_node_info (ctree, handle, null, null, null, null, null, null, null, buffer);
- return buffer [0];
-}
-
-/** - * 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 - * - * @exception SWTException <ul> - * <li>ERROR_WIDGET_DISPOSED - if 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();
- return false;
-}
-
-/** - * 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();
- return parent.getItemCount (handle);
-}
-
-/**
- * Returns an 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();
- return parent.getItems (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;
-}
-
-/** - * 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 data = OS.g_list_nth_data (handle, 0);
- GtkCTreeRow row = new GtkCTreeRow ();
- OS.memmove (row, data, GtkCTreeRow.sizeof);
- if (row.parent == 0) return null;
- int ctree = parent.handle;
- int index = OS.gtk_ctree_node_get_row_data (ctree, row.parent) - 1;
- return parent.items [index];
-}
-
-void releaseChild () {
- super.releaseChild ();
- parent.destroyItem (this);
-}
-
-void releaseWidget () {
- super.releaseWidget ();
- parent = null;
-}
-
-/** - * 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;
- int ctree = parent.handle;
- byte [] spacing = new byte [1];
- int [] pixmap = new int [1], mask = new int [1];
- boolean [] is_leaf = new boolean [1], expanded = new boolean [1];
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- OS.gtk_ctree_get_node_info (ctree, handle, null, spacing, pixmap, mask, pixmap, mask, is_leaf, expanded);
- if (checked && pixmap [0] == parent.check) return;
- if (!checked && pixmap [0] == parent.uncheck) return;
- pixmap [0] = checked ? parent.check : parent.uncheck;
- OS.gtk_ctree_set_node_info (ctree, handle, buffer, spacing [0], pixmap [0], mask [0], pixmap [0], mask [0], is_leaf [0], expanded [0]);
-}
-
-/** - * Sets the grayed state of the receiver. - * <p> - * - * @param checked 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> - */ -public void setGrayed (boolean grayed) {
- checkWidget();
-}
-
-/** - * 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 ctree = parent.handle;
- if (expanded) {
- OS.gtk_signal_handler_block_by_data (ctree, SWT.Expand);
- OS.gtk_ctree_expand (ctree, handle);
- OS.gtk_signal_handler_unblock_by_data (ctree, SWT.Expand);
- } else {
- OS.gtk_signal_handler_block_by_data (ctree, SWT.Collapse);
- OS.gtk_ctree_collapse (ctree, handle);
- OS.gtk_signal_handler_unblock_by_data (ctree, SWT.Collapse);
- }
-}
-
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((parent.style & SWT.CHECK) != 0) return;
- this.image = image;
- int pixmap = 0, mask = 0;
- if (image != null) {
- pixmap = image.pixmap;
- mask = image.mask;
- }
- int ctree = parent.handle;
- byte [] spacing = new byte [1];
- boolean [] is_leaf = new boolean [1], expanded = new boolean [1];
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- OS.gtk_ctree_get_node_info (ctree, handle, null, spacing, null, null, null, null, is_leaf, expanded);
- OS.gtk_ctree_set_node_info (ctree, handle, buffer, spacing [0], pixmap, mask, pixmap, mask, is_leaf [0], expanded [0]);
-}
-
-/** - * This label will be displayed to the right of the bitmap, - * or, if the receiver doesn't have a bitmap to the right of - * the horizontal hierarchy connector line. - */
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
- int ctree = parent.handle;
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- byte [] spacing = new byte [1];
- boolean [] is_leaf = new boolean [1], expanded = new boolean [1];
- int [] pixmap_closed = new int [1], mask_closed= new int [1], pixmap_opened= new int [1], mask_opened= new int [1];
- OS.gtk_ctree_get_node_info (ctree, handle, null, spacing, pixmap_closed, mask_closed, pixmap_opened, mask_opened, is_leaf, expanded);
- OS.gtk_ctree_set_node_info (ctree, handle, buffer, spacing [0], pixmap_closed [0], mask_closed [0], pixmap_opened [0], mask_opened [0], is_leaf [0], expanded [0]);
-}
-}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Trim.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Trim.java deleted file mode 100644 index 8f37202228..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Trim.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -class Trim { - int top=0, bottom=0, left=0, right=0; -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/UtilFuncs.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/UtilFuncs.java deleted file mode 100644 index a956c281ed..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/UtilFuncs.java +++ /dev/null @@ -1,141 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -import org.eclipse.swt.*; -import org.eclipse.swt.graphics.*; -import org.eclipse.swt.internal.gtk.*; - -/** - * This class contains static helpers wrapping some common - * widget-inspecific operations like get the size of a gtk widget. - */ -class UtilFuncs { - -/* - * === GEOMETRY === - */ - -static Point getLocation (int handle) { - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - return new Point (widget.alloc_x, widget.alloc_y); -} - -static boolean setLocation(int parentHandle, int handle, int x, int y) { - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - boolean sameOrigin = (widget.alloc_x == x && widget.alloc_y == y); - - // GtkFixed does not leave us alone. - // Instead, it maintains its own list of geometries for the children. - // Moreover, it will post a RESIZE on the queue that will cause - // disturbance to all our brother; to avoid that, we temporarily - // clear the VISIBLE flag, and do the synchronous update ourselves - GtkObject gtkChild = new GtkObject(); - OS.memmove (gtkChild, handle, GtkObject.sizeof); - OS.GTK_WIDGET_UNSET_FLAGS(handle, OS.GTK_VISIBLE); - OS.gtk_fixed_move(parentHandle, handle, (short)x, (short)y ); - OS.memmove(handle, gtkChild, GtkObject.sizeof); - - -// OS.gtk_widget_set_uposition(handle, (short)x, (short)y); - /* - byte[] aux_info_id = org.eclipse.swt.internal.Converter.wcsToMbcs (null, "gtk-aux-info", true); - int aux_info_key_id = OS.g_quark_from_static_string(aux_info_id); - if (aux_info_key_id == 0) SWT.error(SWT.ERROR_UNSPECIFIED); - int aux_info = OS.gtk_object_get_data_by_id(handle, aux_info_key_id); - int[] xy = new int[1]; - // ??? - OS.memmove(aux_info, xy, 4); - */ - - // force allocation update NOW - GtkAllocation alloc = new GtkAllocation(); - alloc.x = (short) x; - alloc.y = (short) y; - alloc.width = (short) widget.alloc_width; - alloc.height = (short) widget.alloc_height; - OS.memmove(handle, widget, GtkWidget.sizeof); - OS.gtk_widget_size_allocate(handle, alloc); - - return (!sameOrigin); -} - -static Point getSize (int handle) { - if (handle==0) { - SWT.error(SWT.ERROR_UNSPECIFIED); - } - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - return new Point (widget.alloc_width, widget.alloc_height); -} - - -static boolean setSize(int handle, int width, int height) { - if (handle==0) { - SWT.error(SWT.ERROR_UNSPECIFIED); - } - - /* Feature in Gtk. - * Gtk will refuse to set the size of any widget to anything smaller than 3x3. - */ - if (height <= 3) height = 3; - if (width <= 3) width = 3; - - // first, see if we actually need to change anything - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - int alloc_width = widget.alloc_width & 0xFFFF; - int alloc_height = widget.alloc_height & 0xFFFF; - if (alloc_width == width && alloc_height == height) { - return false; - } - - OS.gtk_widget_set_usize (handle, width, height); - // force child allocation update - GtkAllocation alloc = new GtkAllocation(); - alloc.x = (short) widget.alloc_x; - alloc.y = (short) widget.alloc_y; - alloc.width = (short) width; - alloc.height = (short) height; - OS.gtk_widget_size_allocate(handle, alloc); - return true; -} - -static void setZeroSize(int handle) { - // CHEATING. For some reason, - // the it will refuse to change its size to anything smaller - setSize(handle, 3,3); -} - -static int getFont(int widget) { - int hStyle = OS.gtk_widget_get_style(widget); - GtkStyle style = new GtkStyle(); - OS.memmove(style, hStyle, GtkStyle.sizeof); - return style.font; -} - -static void setFont(int handle, int font) { - OS.gtk_widget_ensure_style(handle); - // We can't just get the widget's style and set - // its font, because the style slot may point to the - // default font; therefore we have to obtain a clone - // of the style - GtkWidget widget = new GtkWidget (); - OS.memmove (widget, handle, GtkWidget.sizeof); - int hStyle = OS.gtk_style_copy(widget.style); - GtkStyle style = new GtkStyle(); - OS.memmove(style, hStyle, GtkStyle.sizeof); - - OS.gdk_font_unref(style.font); - style.font = font; - OS.memmove (hStyle, style, GtkStyle.sizeof); - OS.gtk_widget_set_style (handle, hStyle); -} - -} - diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Widget.java deleted file mode 100644 index 7ee66f7080..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/Widget.java +++ /dev/null @@ -1,921 +0,0 @@ -package org.eclipse.swt.widgets; - -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved - */ - -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 - */ - -public abstract class Widget { - - public int handle; - int style, state; - EventTable eventTable; - Object data; - String [] keys; - Object [] values; - - /* Global state flags */ -// static final int AUTOMATIC = 1<<0; -// static final int ACTIVE = 1<<1; -// static final int AUTOGRAB = 1<<2; -// static final int MULTIEXPOSE = 1<<3; -// static final int RESIZEREDRAW = 1<<4; -// static final int WRAP = 1<<5; -// static final int DISABLED = 1<<6; -// static final int HIDDEN = 1<<7; -// static final int FOREGROUND = 1<<8; -// static final int BACKGROUND = 1<<9; - static final int DISPOSED = 1<<10; - static final int HANDLE = 1<<11; - static final int CANVAS = 1<<12; - - /* Default widths for widgets */ - static final int DEFAULT_WIDTH = 64; - static final int DEFAULT_HEIGHT = 64; - static final char Mnemonic = '&'; - -/** - * 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 - * for all SWT widget classes should include a comment which - * describes the style constants which are applicable to the class. - * </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 - * @see #checkSubclass - * @see #getStyle - */ -public Widget (Widget parent, int style) { - if (parent == null) error (SWT.ERROR_NULL_ARGUMENT); - if (!parent.isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - this.style = style; -} -/** - * Adds the listener to the collection of listeners who will - * be notifed 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. - * - * @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 #removeListener - */ -public void addListener (int eventType, Listener handler) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (handler == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) eventTable = new EventTable (); - eventTable.hook (eventType, handler); -} -/** - * Adds the listener to the collection of listeners who will - * be notifed 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) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - TypedListener typedListener = new TypedListener (listener); - addListener (SWT.Dispose, typedListener); -} -static int checkBits (int style, int int0, int int1, int int2, int int3, int int4, int int5) { - int mask = int0 | int1 | int2 | int3 | int4 | int5; - if ((style & mask) == 0) style |= int0; - if ((style & int0) != 0) style = (style & ~mask) | int0; - if ((style & int1) != 0) style = (style & ~mask) | int1; - if ((style & int2) != 0) style = (style & ~mask) | int2; - if ((style & int3) != 0) style = (style & ~mask) | int3; - if ((style & int4) != 0) style = (style & ~mask) | int4; - if ((style & int5) != 0) style = (style & ~mask) | int5; - return style; -} - -/** - * 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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); -} - -/* - * HANDLE CODE - * - * HANDLE CODE 1: HANDLE CREATION CODE - The createWidget() cycle. - */ - -void createWidget (int index) { - createHandle (index); - hookEvents (); - configure (); - setHandleStyle (); - register (); - setInitialSize (); - showHandle (); -} - -void register () { - if (handle == 0) return; - if ((state & HANDLE) != 0) WidgetTable.put (handle, this); -} - -void createHandle (int index) {} -void configure () {} -void setHandleStyle () {} -void setInitialSize () {} -void hookEvents () {} -void showHandle () {} -int paintHandle () { return 0; } - -/* HANDLE CODE 3: - * Handle Destruction - */ - -void deregister () { - if (handle == 0) return; - if ((state & HANDLE) != 0) WidgetTable.remove (handle); -} -void destroyWidget () { - int 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 descendents. After this method has - * been invoked, the receiver and all descendents 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 descendents - * 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); - releaseChild (); - releaseWidget (); - destroyWidget (); -} - -void error (int code) { - throw new SWTError (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 - */ -public Object getData () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return 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 - */ -public Object getData (String key) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (key == null) error (SWT.ERROR_NULL_ARGUMENT); - 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 <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> - * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> - * </ul> - */ -public abstract Display getDisplay (); -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 () { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return style; -} - -/** - * 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 () { - if (handle != 0) return false; - if ((state & HANDLE) != 0) return true; - 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. - * - * @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> - */ -protected boolean isListening (int eventType) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - return hooks (eventType); -} - - -/* - * 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); -} - -boolean isValidThread () { - return getDisplay ().isValidThread (); -} -public boolean isValidWidget () { - if (handle != 0) return true; - if ((state & HANDLE) != 0) return false; - return (state & DISPOSED) == 0; -} - -boolean isValidSubclass() { - return Display.isValidClass(getClass()); -} - -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]; -} -/** - * 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. - * - * @param eventType the type of event which has occurred - * @param event the event data - * - * @exception IllegalArgumentException <ul> - * <li>ERROR_NULL_ARGUMENT - if 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> - */ -public void notifyListeners (int eventType, Event event) { - checkWidget(); - if (event == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - event.type = eventType; - event.widget = this; - eventTable.sendEvent (event); -} -void postEvent (int eventType) { - if (eventTable == null) return; - postEvent (eventType, new Event ()); -} -void postEvent (int eventType, Event event) { - if (eventTable == null) return; - event.type = eventType; - event.widget = this; - getDisplay ().postEvent (event); -} - -int processEvent (int eventNumber, int int0, int int1, int int2) { - switch (eventNumber) { - case SWT.Arm: return processArm (int0, int1, int2); - case SWT.Collapse: return processCollapse (int0, int1, int2); - case SWT.Expand: return processExpand (int0, int1, int2); - case SWT.Dispose: return processDispose (int0, int1, int2); - case SWT.DefaultSelection: return processDoubleSelection (int0, int1, int2); - case SWT.FocusIn: return processFocusIn (int0, int1, int2); - case SWT.FocusOut: return processFocusOut (int0, int1, int2); - case SWT.Help: return processHelp (int0, int1, int2); - case SWT.Hide: return processHide (int0, int1, int2); - case SWT.KeyDown: return processKeyDown (int0, int1, int2); - case SWT.KeyUp: return processKeyUp (int0, int1, int2); - case SWT.Iconify: return processIconify (int0, int1, int2); - case SWT.Deiconify: return processDeiconify (int0, int1, int2); - case SWT.Modify: return processModify (int0, int1, int2); - case SWT.MouseDown: return processMouseDown (int0, int1, int2); - case SWT.MouseEnter: return processMouseEnter (int0, int1, int2); - case SWT.MouseExit: return processMouseExit (int0, int1, int2); - case SWT.MouseHover: return processMouseHover (int0, int1, int2); - case SWT.MouseMove: return processMouseMove (int0, int1, int2); - case SWT.MouseUp: return processMouseUp (int0, int1, int2); - case SWT.Paint: return processPaint (int0, int1, int2); - case SWT.Resize: return processResize (int0, int1, int2); - case SWT.Show: return processShow (int0, int1, int2); - case SWT.Selection: return processSelection (int0, int1, int2); - case SWT.Verify: return processVerify (int0, int1, int2); - } - return 0; -} - -int processArm (int int0, int int1, int int2) { - return 0; -} - -/* - * Item expand/collapse in a tree. - */ -int processCollapse (int int0, int int1, int int2) { - return 1; // stop emission -} -int processExpand (int int0, int int1, int int2) { - return 1; // stop emission -} - -/* - * Close a Shell, triggered by delete_event - */ -int processDispose (int arg0, int arg1, int int2) { - return 1; -} - -/* - * The WM has Iconified/Deiconified a Shell. - * The Gtk event is map_event/unmap_event - */ -int processIconify (int int0, int int1, int int2) { - return 0; -} -int processDeiconify (int int0, int int1, int int2) { - return 0; -} - -int processHelp (int int0, int int1, int int2) { - return 0; -} -int processHide (int int0, int int1, int int2) { - return 0; -} -int processFocusIn(int int0, int int1, int int2) { - return 0; -} -int processFocusOut(int int0, int int1, int int2) { - return 0; -} -int processKeyDown (int arg0, int arg1, int int2) { - return 0; -} -int processKeyUp (int arg0, int arg1, int int2) { - return 0; -} -int processModify (int arg0, int arg1, int int2) { - return 0; -} -int processMouseDown (int arg0, int arg1, int int2) { - return 0; -} -int processMouseEnter (int arg0, int arg1, int int2) { - return 0; -} -int processMouseExit (int arg0, int arg1, int int2) { - /* Do nothing */ - return 0; -} -int processMouseHover (int arg0, int arg1, int int2) { - /* Do nothing */ - return 0; -} -int processMouseMove (int arg0, int arg1, int int2) { - /* Do nothing */ - /* Even though we do nothing, we still need to at least - * motify the X Server we are ready to process more events. - * However, only OS controls can receive this event. - */ - return 0; -} - -int processMouseUp (int arg0, int arg1, int int2) { - return 0; -} -int processPaint (int int0, int int1, int int2) { - return 0; -} -int processResize (int int0, int int1, int int2) { - return 0; -} -int processSelection (int int0, int int1, int int2) { - return 0; -} -int processShow (int int0, int int1, int int2) { - return 0; -} -int processDoubleSelection (int int0, int int1, int int2) { - return 0; -} -int processVerify (int int0, int int1, int int2) { - sendEvent (SWT.Verify); - return 0; -} - -void signal_connect (int handle, String eventName, int swtEvent, int numArgs) { - byte [] buffer = Converter.wcsToMbcs (null, eventName, true); - int proc=0; - switch (numArgs) { - case 2: proc=getDisplay().windowProc2; break; - case 3: proc=getDisplay().windowProc3; break; - case 4: proc=getDisplay().windowProc4; break; - case 5: proc=getDisplay().windowProc5; break; - default: error(SWT.ERROR_INVALID_ARGUMENT); - } - OS.gtk_signal_connect (handle, buffer, proc, swtEvent); -} -void signal_connect_after (int handle, String eventName, int swtEvent, int numArgs) { - byte [] buffer = Converter.wcsToMbcs (null, eventName, true); - int proc=0; - switch (numArgs) { - case 2: proc=getDisplay().windowProc2; break; - case 3: proc=getDisplay().windowProc3; break; - case 4: proc=getDisplay().windowProc4; break; - case 5: proc=getDisplay().windowProc5; break; - default: error(SWT.ERROR_INVALID_ARGUMENT); - } - OS.gtk_signal_connect_after (handle, buffer, proc, swtEvent); -} - -void releaseChild () { - /* Do nothing */ -} -void releaseHandle () { - handle = 0; - state |= DISPOSED; -} -void releaseWidget () { - sendEvent (SWT.Dispose); - deregister (); - eventTable = null; - data = null; -} -/** - * Removes the listener from the collection of listeners who will - * be notifed when an event of the given type occurs. - * - * @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_WIDGET_DISPOSED - if 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 - */ -public void removeListener (int eventType, Listener handler) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (handler == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (eventType, handler); -} -/** -* Warning: API under construction. -*/ -protected void removeListener (int eventType, SWTEventListener handler) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - 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 notifed when the widget is disposed. - * - * @param listener the listener which should no longer 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 removeDisposeListener (DisposeListener listener) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); - if (eventTable == null) return; - eventTable.unhook (SWT.Dispose, listener); -} -void sendEvent (int eventType) { - if (eventTable == null) return; - sendEvent (eventType, new Event ()); -} -void sendEvent (int eventType, Event event) { - if (eventTable == null) return; - event.widget = this; - event.type = eventType; - eventTable.sendEvent (event); -} -/** - * 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> - */ -public void setData (Object data) { - checkWidget(); - 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 - */ -public void setData (String key, Object value) { - if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); - if (!isValidWidget ()) error (SWT.ERROR_WIDGET_DISPOSED); - if (key == null) error (SWT.ERROR_NULL_ARGUMENT); - - /* Remove the key/value pair */ - if (value == null) { - if (keys == null) return; - int index = 0; - while (index < keys.length && !keys [index].equals (key)) index++; - if (index == keys.length) return; - if (keys.length == 1) { - keys = null; - values = null; - } else { - String [] newKeys = new String [keys.length - 1]; - Object [] newValues = new Object [values.length - 1]; - System.arraycopy (keys, 0, newKeys, 0, index); - System.arraycopy (keys, index + 1, newKeys, index, newKeys.length - index); - System.arraycopy (values, 0, newValues, 0, index); - System.arraycopy (values, index + 1, newValues, index, newValues.length - index); - keys = newKeys; - values = newValues; - } - return; - } - - /* Add the key/value pair */ - if (keys == null) { - keys = new String [] {key}; - values = new Object [] {value}; - return; - } - for (int i=0; i<keys.length; i++) { - if (keys [i].equals (key)) { - values [i] = value; - return; - } - } - String [] newKeys = new String [keys.length + 1]; - Object [] newValues = new Object [values.length + 1]; - System.arraycopy (keys, 0, newKeys, 0, keys.length); - System.arraycopy (values, 0, newValues, 0, values.length); - newKeys [keys.length] = key; - newValues [values.length] = value; - keys = newKeys; - values = newValues; -} -/** - * Returns a string containing a concise, human-readable - * description of the receiver. - * - * @return a string representation of the receiver - */ -public String toString () { - String string = "*Disposed*"; - if (!isDisposed ()) { - string = "*Wrong Thread*"; - if (isValidThread ()) string = getNameText (); - } - return getName () + " {" + string + "}"; -} -int topHandle () { - return handle; -} -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; -} - -byte[] string2bytesConvertMnemonic(String string) { - //FIXME need to double _'s - char [] t = new char [string.length ()]; - string.getChars (0, t.length, t, 0); - for (int i=0; i<t.length; i++) {if (t [i] == '&') t [i] = '_';} - return Converter.wcsToMbcs (null, t, true); -} - -} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/WidgetTable.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/WidgetTable.java deleted file mode 100644 index df5065116a..0000000000 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk1x/org/eclipse/swt/widgets/WidgetTable.java +++ /dev/null @@ -1,89 +0,0 @@ -package org.eclipse.swt.widgets;
-
-/*
- * (c) Copyright IBM Corp. 2000, 2001.
- * All Rights Reserved
- */
-
-import org.eclipse.swt.internal.gtk.*;
-
-class WidgetTable {
- static int FreeSlot = 0;
- static int GrowSize = 1024;
- static int [] IndexTable = new int [GrowSize];
- static Widget [] WidgetTable = new Widget [GrowSize];
- static {
- for (int i=0; i<GrowSize-1; i++) IndexTable [i] = i + 1;
- IndexTable [GrowSize - 1] = -1;
- }
-
-public static synchronized Widget get (int handle) {
- if (handle == 0) return null;
- int index = OS.gtk_object_get_user_data (handle) - 1;
- if (0 <= index && index < WidgetTable.length) return WidgetTable [index];
- return null;
-}
-
-public synchronized static void put(int handle, Widget widget) {
- if (handle == 0) return;
- if (FreeSlot == -1) {
- int length = (FreeSlot = IndexTable.length) + GrowSize;
- 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.gtk_object_set_user_data (handle, index);
- int oldSlot = FreeSlot;
- FreeSlot = IndexTable[oldSlot];
- IndexTable [oldSlot] = -2;
- WidgetTable [oldSlot] = widget;
-}
-
-public static synchronized Widget remove (int handle) {
- if (handle == 0) return null;
- Widget widget = null;
- int index = OS.gtk_object_get_user_data (handle) - 1;
- if (0 <= index && index < WidgetTable.length) {
- widget = WidgetTable [index];
- WidgetTable [index] = null;
- IndexTable [index] = FreeSlot;
- FreeSlot = index;
- OS.gtk_object_set_user_data (handle, 0);
- }
- return widget;
-}
-
-public static synchronized Shell [] shells () {
- int length = 0;
- for (int i=0; i<WidgetTable.length; i++) {
- Widget widget = WidgetTable [i];
- if (widget != null && widget instanceof Shell) length++;
- }
- int index = 0;
- Shell [] result = new Shell [length];
- for (int i=0; i<WidgetTable.length; i++) {
- Widget widget = WidgetTable [i];
- if (widget != null && widget instanceof Shell) {
- result [index++] = (Shell) widget;
- }
- }
- return result;
-}
-
-public static synchronized int size () {
- int size = 0;
- for (int i=0; i<WidgetTable.length; i++) {
- if (WidgetTable [i] != null) size++;
- }
- return size;
-}
-
-}
|