diff options
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/motif')
44 files changed, 27526 insertions, 27526 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java index bfb0a3d75d..704ff260d2 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Color.java @@ -1,15 +1,15 @@ -package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; + /** * Instances of this class manage the operating system resources that * implement SWT's RGB color model. To create a color you can either @@ -23,20 +23,20 @@ import org.eclipse.swt.*; * * @see RGB */ -public final class Color {
+public final class Color { /** * the handle to the OS color resource * (Warning: This field is platform dependent) */ - public XColor handle;
-
- /**
- * The device where this image was created.
+ public XColor handle; + + /** + * The device where this image was created. */ - Device device;
-
-Color() {
-}
+ Device device; + +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 @@ -61,12 +61,12 @@ Color() { * * @see #dispose */ -public Color (Device device, int red, int green, int blue) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, red, green, blue);
- if (device.tracking) device.new_Object(this);
-}
+public Color (Device device, int red, int green, int blue) { + if (device == null) device = Device.getDevice(); + if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + init(device, red, green, blue); + if (device.tracking) device.new_Object(this); +} /** * Constructs a new instance of this class given a device and an * <code>RGB</code> describing the desired red, green and blue values. @@ -89,35 +89,35 @@ public Color (Device device, int red, int green, int blue) { * * @see #dispose */ -public Color (Device device, RGB rgb) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (rgb == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, rgb.red, rgb.green, rgb.blue);
- if (device.tracking) device.new_Object(this);
-}
+public Color (Device device, RGB rgb) { + if (device == null) device = Device.getDevice(); + if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (rgb == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + init(device, rgb.red, rgb.green, rgb.blue); + if (device.tracking) device.new_Object(this); +} /** * Disposes of the operating system resources associated with * the color. Applications must dispose of all colors which * they allocate. */ -public void dispose() {
+public void dispose() { if (handle == null) return; - if (device.isDisposed()) return;
+ if (device.isDisposed()) return; int xDisplay = device.xDisplay; - int pixel = handle.pixel;
- if (device.colorRefCount != null) {
- /* If this was the last reference, remove the color from the list */
- if (--device.colorRefCount[pixel] == 0) {
- device.xcolors[pixel] = null;
- }
- }
- int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay));
- OS.XFreeColors(xDisplay, colormap, new int[] { pixel }, 1, 0);
- handle = null;
- if (device.tracking) device.dispose_Object(this);
- device = null;
-}
+ int pixel = handle.pixel; + if (device.colorRefCount != null) { + /* If this was the last reference, remove the color from the list */ + if (--device.colorRefCount[pixel] == 0) { + device.xcolors[pixel] = null; + } + } + int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay)); + OS.XFreeColors(xDisplay, colormap, new int[] { pixel }, 1, 0); + handle = null; + if (device.tracking) device.dispose_Object(this); + device = null; +} /** * Compares the argument to the receiver, and returns true * if they represent the <em>same</em> object using a class @@ -128,15 +128,15 @@ public void dispose() { * * @see #hashCode */ -public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Color)) return false;
- Color color = (Color)object;
- XColor xColor = color.handle;
- if (handle == xColor) return true;
- return device == color.device && handle.red == xColor.red &&
- handle.green == xColor.green && handle.blue == xColor.blue;
-}
+public boolean equals (Object object) { + if (object == this) return true; + if (!(object instanceof Color)) return false; + Color color = (Color)object; + XColor xColor = color.handle; + if (handle == xColor) return true; + return device == color.device && handle.red == xColor.red && + handle.green == xColor.green && handle.blue == xColor.blue; +} /** * Returns the amount of blue in the color, from 0 to 255. * @@ -146,10 +146,10 @@ public boolean equals (Object object) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public int getBlue () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (handle.blue >> 8) & 0xFF;
-}
+public int getBlue () { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return (handle.blue >> 8) & 0xFF; +} /** * Returns the amount of green in the color, from 0 to 255. * @@ -159,10 +159,10 @@ public int getBlue () { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public int getGreen () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (handle.green >> 8) & 0xFF;
-}
+public int getGreen () { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return (handle.green >> 8) & 0xFF; +} /** * Returns the amount of red in the color, from 0 to 255. * @@ -172,10 +172,10 @@ public int getGreen () { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public int getRed () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return (handle.red >> 8) & 0xFF;
-}
+public int getRed () { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return (handle.red >> 8) & 0xFF; +} /** * Returns an <code>RGB</code> representing the receiver. * @@ -183,10 +183,10 @@ public int getRed () { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public RGB getRGB () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return new RGB((handle.red >> 8) & 0xFF, (handle.green >> 8) & 0xFF, (handle.blue >> 8) & 0xFF);
-}
+public RGB getRGB () { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return new RGB((handle.red >> 8) & 0xFF, (handle.green >> 8) & 0xFF, (handle.blue >> 8) & 0xFF); +} /** * Returns an integer hash code for the receiver. Any two * objects which return <code>true</code> when passed to @@ -197,117 +197,117 @@ public RGB getRGB () { * * @see #equals */ -public int hashCode () {
- if (isDisposed()) return 0;
- return handle.red ^ handle.green ^ handle.blue;
-}
-void init(Device device, int red, int green, int blue) {
- this.device = device;
- if ((red > 255) || (red < 0) ||
- (green > 255) || (green < 0) ||
- (blue > 255) || (blue < 0)) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- XColor xColor = new XColor();
- xColor.red = (short)((red & 0xFF) | ((red & 0xFF) << 8));
- xColor.green = (short)((green & 0xFF) | ((green & 0xFF) << 8));
- xColor.blue = (short)((blue & 0xFF) | ((blue & 0xFF) << 8));
- handle = xColor;
- int xDisplay = device.xDisplay;
- int screen = OS.XDefaultScreen(xDisplay);
- int colormap = OS.XDefaultColormap(xDisplay, screen);
- /* 1. Try to allocate the color */
- if (OS.XAllocColor(xDisplay, colormap, xColor) != 0) {
- if (device.colorRefCount != null) {
- /* Make a copy of the color to put in the colors array */
- XColor colorCopy = new XColor();
- colorCopy.red = xColor.red;
- colorCopy.green = xColor.green;
- colorCopy.blue = xColor.blue;
- colorCopy.pixel = xColor.pixel;
- device.xcolors[colorCopy.pixel] = colorCopy;
- device.colorRefCount[xColor.pixel]++;
- }
- return;
- }
- /*
- * 2. Allocation failed. Query the entire colormap and
- * find the closest match which can be allocated.
- * This should never occur on a truecolor display.
+public int hashCode () { + if (isDisposed()) return 0; + return handle.red ^ handle.green ^ handle.blue; +} +void init(Device device, int red, int green, int blue) { + this.device = device; + if ((red > 255) || (red < 0) || + (green > 255) || (green < 0) || + (blue > 255) || (blue < 0)) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + XColor xColor = new XColor(); + xColor.red = (short)((red & 0xFF) | ((red & 0xFF) << 8)); + xColor.green = (short)((green & 0xFF) | ((green & 0xFF) << 8)); + xColor.blue = (short)((blue & 0xFF) | ((blue & 0xFF) << 8)); + handle = xColor; + int xDisplay = device.xDisplay; + int screen = OS.XDefaultScreen(xDisplay); + int colormap = OS.XDefaultColormap(xDisplay, screen); + /* 1. Try to allocate the color */ + if (OS.XAllocColor(xDisplay, colormap, xColor) != 0) { + if (device.colorRefCount != null) { + /* Make a copy of the color to put in the colors array */ + XColor colorCopy = new XColor(); + colorCopy.red = xColor.red; + colorCopy.green = xColor.green; + colorCopy.blue = xColor.blue; + colorCopy.pixel = xColor.pixel; + device.xcolors[colorCopy.pixel] = colorCopy; + device.colorRefCount[xColor.pixel]++; + } + return; + } + /* + * 2. Allocation failed. Query the entire colormap and + * find the closest match which can be allocated. + * This should never occur on a truecolor display. */ - Visual visual = new Visual();
- OS.memmove(visual, OS.XDefaultVisual(xDisplay, screen), Visual.sizeof);
- int mapEntries = visual.map_entries;
- XColor[] queried = new XColor[mapEntries];
- int[] distances = new int[mapEntries];
- /*
- * Query all colors in the colormap and calculate the distance
- * from each to the desired color.
+ Visual visual = new Visual(); + OS.memmove(visual, OS.XDefaultVisual(xDisplay, screen), Visual.sizeof); + int mapEntries = visual.map_entries; + XColor[] queried = new XColor[mapEntries]; + int[] distances = new int[mapEntries]; + /* + * Query all colors in the colormap and calculate the distance + * from each to the desired color. */ - for (int i = 0; i < mapEntries; i++) {
- XColor color = new XColor();
- color.pixel = i;
- queried[i] = color;
- OS.XQueryColor(xDisplay, colormap, color);
- int r = red - ((color.red >> 8) & 0xFF);
- int g = green - ((color.green >> 8) & 0xFF);
- int b = blue - ((color.blue >> 8) & 0xFF);
- distances[i] = r*r + g*g + b*b;
- }
- /*
- * Try to allocate closest matching queried color.
- * The allocation can fail if the closest matching
- * color is allocated privately, so go through them
- * in order of increasing distance.
+ for (int i = 0; i < mapEntries; i++) { + XColor color = new XColor(); + color.pixel = i; + queried[i] = color; + OS.XQueryColor(xDisplay, colormap, color); + int r = red - ((color.red >> 8) & 0xFF); + int g = green - ((color.green >> 8) & 0xFF); + int b = blue - ((color.blue >> 8) & 0xFF); + distances[i] = r*r + g*g + b*b; + } + /* + * Try to allocate closest matching queried color. + * The allocation can fail if the closest matching + * color is allocated privately, so go through them + * in order of increasing distance. */ - for (int i = 0; i < mapEntries; i++) {
- int minDist = 0x30000;
- int minIndex = 0;
- for (int j = 0; j < mapEntries; j++) {
- if (distances[j] < minDist) {
- minDist = distances[j];
- minIndex = j;
- }
- }
- XColor queriedColor = queried[minIndex];
- XColor osColor = new XColor();
- osColor.red = queriedColor.red;
- osColor.green = queriedColor.green;
- osColor.blue = queriedColor.blue;
- if (OS.XAllocColor(xDisplay, colormap, osColor) != 0) {
- /* Allocation succeeded. Copy the fields into the handle */
- xColor.red = osColor.red;
- xColor.green = osColor.green;
- xColor.blue = osColor.blue;
- xColor.pixel = osColor.pixel;
- if (device.colorRefCount != null) {
- /* Put osColor in the colors array */
- device.xcolors[osColor.pixel] = osColor;
- device.colorRefCount[osColor.pixel]++;
- }
- return;
- }
- /* The allocation failed; matching color is allocated privately */
- distances[minIndex] = 0x30000;
- }
- /*
- * 3. Couldn't allocate any of the colors in the colormap.
- * This means all colormap entries were allocated privately
- * by other applications. Give up and allocate black.
+ for (int i = 0; i < mapEntries; i++) { + int minDist = 0x30000; + int minIndex = 0; + for (int j = 0; j < mapEntries; j++) { + if (distances[j] < minDist) { + minDist = distances[j]; + minIndex = j; + } + } + XColor queriedColor = queried[minIndex]; + XColor osColor = new XColor(); + osColor.red = queriedColor.red; + osColor.green = queriedColor.green; + osColor.blue = queriedColor.blue; + if (OS.XAllocColor(xDisplay, colormap, osColor) != 0) { + /* Allocation succeeded. Copy the fields into the handle */ + xColor.red = osColor.red; + xColor.green = osColor.green; + xColor.blue = osColor.blue; + xColor.pixel = osColor.pixel; + if (device.colorRefCount != null) { + /* Put osColor in the colors array */ + device.xcolors[osColor.pixel] = osColor; + device.colorRefCount[osColor.pixel]++; + } + return; + } + /* The allocation failed; matching color is allocated privately */ + distances[minIndex] = 0x30000; + } + /* + * 3. Couldn't allocate any of the colors in the colormap. + * This means all colormap entries were allocated privately + * by other applications. Give up and allocate black. */ - XColor osColor = new XColor();
- OS.XAllocColor(xDisplay, colormap, osColor);
- /* Copy the fields into the handle */
- xColor.red = osColor.red;
- xColor.green = osColor.green;
- xColor.blue = osColor.blue;
- xColor.pixel = osColor.pixel;
- if (device.colorRefCount != null) {
- /* Put osColor in the colors array */
- device.xcolors[osColor.pixel] = osColor;
- device.colorRefCount[osColor.pixel]++;
- }
-}
+ XColor osColor = new XColor(); + OS.XAllocColor(xDisplay, colormap, osColor); + /* Copy the fields into the handle */ + xColor.red = osColor.red; + xColor.green = osColor.green; + xColor.blue = osColor.blue; + xColor.pixel = osColor.pixel; + if (device.colorRefCount != null) { + /* Put osColor in the colors array */ + device.xcolors[osColor.pixel] = osColor; + device.colorRefCount[osColor.pixel]++; + } +} /** * Returns <code>true</code> if the color has been disposed, * and <code>false</code> otherwise. @@ -318,24 +318,24 @@ void init(Device device, int red, int green, int blue) { * * @return <code>true</code> when the color is disposed and <code>false</code> otherwise */ -public boolean isDisposed() {
- return handle == null;
-}
-public static Color motif_new(Device device, XColor xColor) {
- if (device == null) device = Device.getDevice();
- Color color = new Color();
- color.handle = xColor;
- color.device = device;
- return color;
-}
+public boolean isDisposed() { + return handle == null; +} +public static Color motif_new(Device device, XColor xColor) { + if (device == null) device = Device.getDevice(); + Color color = new Color(); + color.handle = xColor; + color.device = device; + return color; +} /** * Returns a string containing a concise, human-readable * description of the receiver. * * @return a string representation of the receiver */ -public String toString () {
- if (isDisposed()) return "Color {*DISPOSED*}";
- return "Color {" + getRed() + ", " + getGreen() + ", " + getBlue() + "}";
-}
-}
+public String toString () { + if (isDisposed()) return "Color {*DISPOSED*}"; + return "Color {" + getRed() + ", " + getGreen() + ", " + getBlue() + "}"; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Cursor.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Cursor.java index d08bbf56dc..faf2c8696d 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Cursor.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Cursor.java @@ -1,15 +1,15 @@ -package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; + /** * Instances of this class manage operating system resources that * specify the appearance of the on-screen pointer. To create a @@ -34,20 +34,20 @@ import org.eclipse.swt.*; * Note: Only one of the above styles may be specified. * </p> */ -public final class Cursor {
+public final class Cursor { /** * the handle to the OS cursor resource * (Warning: This field is platform dependent) */ - public int handle;
-
- /**
- * The device where this image was created.
+ public int handle; + + /** + * The device where this image was created. */ - Device device;
-
-Cursor () {
-}
+ Device device; + +Cursor () { +} /** * Constructs a new cursor given a device and a style * constant describing the desired cursor appearance. @@ -89,40 +89,40 @@ Cursor () { * @see SWT#CURSOR_NO * @see SWT#CURSOR_HAND */ -public Cursor (Device device, int style) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = device;
- int shape = 0;
- switch (style) {
- case SWT.CURSOR_ARROW: shape = OS.XC_left_ptr; break;
- case SWT.CURSOR_WAIT: shape = OS.XC_watch; break;
- case SWT.CURSOR_HAND: shape = OS.XC_hand2; break;
- case SWT.CURSOR_CROSS: shape = OS.XC_cross; break;
- case SWT.CURSOR_APPSTARTING: shape = OS.XC_watch; break;
- case SWT.CURSOR_HELP: shape = OS.XC_question_arrow; break;
- case SWT.CURSOR_SIZEALL: shape = OS.XC_diamond_cross; break;
- case SWT.CURSOR_SIZENESW: shape = OS.XC_sizing; break;
- case SWT.CURSOR_SIZENS: shape = OS.XC_double_arrow; break;
- case SWT.CURSOR_SIZENWSE: shape = OS.XC_sizing; break;
- case SWT.CURSOR_SIZEWE: shape = OS.XC_sb_h_double_arrow; break;
- case SWT.CURSOR_SIZEN: shape = OS.XC_top_side; break;
- case SWT.CURSOR_SIZES: shape = OS.XC_bottom_side; break;
- case SWT.CURSOR_SIZEE: shape = OS.XC_right_side; break;
- case SWT.CURSOR_SIZEW: shape = OS.XC_left_side; break;
- case SWT.CURSOR_SIZENE: shape = OS.XC_top_right_corner; break;
- case SWT.CURSOR_SIZESE: shape = OS.XC_bottom_right_corner; break;
- case SWT.CURSOR_SIZESW: shape = OS.XC_bottom_left_corner; break;
- case SWT.CURSOR_SIZENW: shape = OS.XC_top_left_corner; break;
- case SWT.CURSOR_UPARROW: shape = OS.XC_sb_up_arrow; break;
- case SWT.CURSOR_IBEAM: shape = OS.XC_xterm; break;
- case SWT.CURSOR_NO: shape = OS.XC_X_cursor; break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- this.handle = OS.XCreateFontCursor(device.xDisplay, shape);
- if (device.tracking) device.new_Object(this);
-}
+public Cursor (Device device, int style) { + if (device == null) device = Device.getDevice(); + if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + this.device = device; + int shape = 0; + switch (style) { + case SWT.CURSOR_ARROW: shape = OS.XC_left_ptr; break; + case SWT.CURSOR_WAIT: shape = OS.XC_watch; break; + case SWT.CURSOR_HAND: shape = OS.XC_hand2; break; + case SWT.CURSOR_CROSS: shape = OS.XC_cross; break; + case SWT.CURSOR_APPSTARTING: shape = OS.XC_watch; break; + case SWT.CURSOR_HELP: shape = OS.XC_question_arrow; break; + case SWT.CURSOR_SIZEALL: shape = OS.XC_diamond_cross; break; + case SWT.CURSOR_SIZENESW: shape = OS.XC_sizing; break; + case SWT.CURSOR_SIZENS: shape = OS.XC_double_arrow; break; + case SWT.CURSOR_SIZENWSE: shape = OS.XC_sizing; break; + case SWT.CURSOR_SIZEWE: shape = OS.XC_sb_h_double_arrow; break; + case SWT.CURSOR_SIZEN: shape = OS.XC_top_side; break; + case SWT.CURSOR_SIZES: shape = OS.XC_bottom_side; break; + case SWT.CURSOR_SIZEE: shape = OS.XC_right_side; break; + case SWT.CURSOR_SIZEW: shape = OS.XC_left_side; break; + case SWT.CURSOR_SIZENE: shape = OS.XC_top_right_corner; break; + case SWT.CURSOR_SIZESE: shape = OS.XC_bottom_right_corner; break; + case SWT.CURSOR_SIZESW: shape = OS.XC_bottom_left_corner; break; + case SWT.CURSOR_SIZENW: shape = OS.XC_top_left_corner; break; + case SWT.CURSOR_UPARROW: shape = OS.XC_sb_up_arrow; break; + case SWT.CURSOR_IBEAM: shape = OS.XC_xterm; break; + case SWT.CURSOR_NO: shape = OS.XC_X_cursor; break; + default: + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + this.handle = OS.XCreateFontCursor(device.xDisplay, shape); + if (device.tracking) device.new_Object(this); +} /** * Constructs a new cursor given a device, image and mask * data describing the desired cursor appearance, and the x @@ -155,92 +155,92 @@ public Cursor (Device device, int style) { * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li> * </ul> */ -public Cursor (Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- this.device = device;
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (mask == null) {
- if (source.getTransparencyType() != SWT.TRANSPARENCY_MASK) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- mask = source.getTransparencyMask();
- }
- /* Check the bounds. Mask must be the same size as source */
- if (mask.width != source.width || mask.height != source.height) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- /* Check depths */
- if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (source.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- /* Check the hotspots */
- if (hotspotX >= source.width || hotspotX < 0 ||
- hotspotY >= source.height || hotspotY < 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- /* 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 xDisplay = device.xDisplay;
- int drawable = OS.XDefaultRootWindow(xDisplay);
- int sourcePixmap = OS.XCreateBitmapFromData(xDisplay, drawable, sourceData, source.width, source.height);
- int maskPixmap = OS.XCreateBitmapFromData(xDisplay, drawable, maskData, source.width, source.height);
- /* Get the colors */
- int screenNum = OS.XDefaultScreen(xDisplay);
- XColor foreground = new XColor();
- foreground.pixel = OS.XBlackPixel(xDisplay, screenNum);
- foreground.red = foreground.green = foreground.blue = 0;
- XColor background = new XColor();
- background.pixel = OS.XWhitePixel(xDisplay, screenNum);
- background.red = background.green = background.blue = (short)0xFFFF;
- /* Create the cursor */
- handle = OS.XCreatePixmapCursor(xDisplay, maskPixmap, sourcePixmap, foreground, background, hotspotX, hotspotY);
- /* Dispose the pixmaps */
- OS.XFreePixmap(xDisplay, sourcePixmap);
- OS.XFreePixmap(xDisplay, maskPixmap);
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (device.tracking) device.new_Object(this);
-}
+public Cursor (Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) { + if (device == null) device = Device.getDevice(); + if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + this.device = device; + if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (mask == null) { + if (source.getTransparencyType() != SWT.TRANSPARENCY_MASK) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + mask = source.getTransparencyMask(); + } + /* Check the bounds. Mask must be the same size as source */ + if (mask.width != source.width || mask.height != source.height) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + /* Check depths */ + if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + if (source.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + /* Check the hotspots */ + if (hotspotX >= source.width || hotspotX < 0 || + hotspotY >= source.height || hotspotY < 0) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + /* 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 xDisplay = device.xDisplay; + int drawable = OS.XDefaultRootWindow(xDisplay); + int sourcePixmap = OS.XCreateBitmapFromData(xDisplay, drawable, sourceData, source.width, source.height); + int maskPixmap = OS.XCreateBitmapFromData(xDisplay, drawable, maskData, source.width, source.height); + /* Get the colors */ + int screenNum = OS.XDefaultScreen(xDisplay); + XColor foreground = new XColor(); + foreground.pixel = OS.XBlackPixel(xDisplay, screenNum); + foreground.red = foreground.green = foreground.blue = 0; + XColor background = new XColor(); + background.pixel = OS.XWhitePixel(xDisplay, screenNum); + background.red = background.green = background.blue = (short)0xFFFF; + /* Create the cursor */ + handle = OS.XCreatePixmapCursor(xDisplay, maskPixmap, sourcePixmap, foreground, background, hotspotX, hotspotY); + /* Dispose the pixmaps */ + OS.XFreePixmap(xDisplay, sourcePixmap); + OS.XFreePixmap(xDisplay, maskPixmap); + if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); + if (device.tracking) device.new_Object(this); +} /** * Disposes of the operating system resources associated with * the cursor. Applications must dispose of all cursors which * they allocate. */ -public void dispose () {
+public void dispose () { if (handle == 0) return; if (device.isDisposed()) return; - OS.XFreeCursor(device.xDisplay, handle);
- handle = 0;
- if (device.tracking) device.dispose_Object(this);
- device = null;
-}
+ OS.XFreeCursor(device.xDisplay, handle); + handle = 0; + if (device.tracking) device.dispose_Object(this); + device = null; +} /** * Compares the argument to the receiver, and returns true * if they represent the <em>same</em> object using a class @@ -251,12 +251,12 @@ public void dispose () { * * @see #hashCode */ -public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Cursor)) return false;
- Cursor cursor = (Cursor)object;
- return device == cursor.device && handle == cursor.handle;
-}
+public boolean equals (Object object) { + if (object == this) return true; + if (!(object instanceof Cursor)) return false; + Cursor cursor = (Cursor)object; + return device == cursor.device && handle == cursor.handle; +} /** * Returns an integer hash code for the receiver. Any two * objects which return <code>true</code> when passed to @@ -267,9 +267,9 @@ public boolean equals (Object object) { * * @see #equals */ -public int hashCode () {
- return handle;
-}
+public int hashCode () { + return handle; +} /** * Returns <code>true</code> if the cursor has been disposed, * and <code>false</code> otherwise. @@ -280,24 +280,24 @@ public int hashCode () { * * @return <code>true</code> when the cursor is disposed and <code>false</code> otherwise */ -public boolean isDisposed() {
- return handle == 0;
-}
-public static Cursor motif_new(Device device, int handle) {
- if (device == null) device = Device.getDevice();
- Cursor cursor = new Cursor();
- cursor.device = device;
- cursor.handle = handle;
- return cursor;
-}
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
+public boolean isDisposed() { + return handle == 0; +} +public static Cursor motif_new(Device device, int handle) { + if (device == null) device = Device.getDevice(); + Cursor cursor = new Cursor(); + cursor.device = device; + cursor.handle = handle; + return cursor; +} +/** + * Returns a string containing a concise, human-readable + * description of the receiver. + * + * @return a string representation of the receiver */ -public String toString () {
- if (isDisposed()) return "Cursor {*DISPOSED*}";
- return "Cursor {" + handle + "}";
-}
-}
+public String toString () { + if (isDisposed()) return "Cursor {*DISPOSED*}"; + return "Cursor {" + handle + "}"; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java index 091c2cdf36..b8d8bc4d6c 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Device.java @@ -1,100 +1,100 @@ -package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.*; +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.motif.*; + /** * This class is the abstract superclass of all device objects, * such as the Display device and the Printer device. Devices * can have a graphics context (GC) created for them, and they * can be drawn on by sending messages to the associated GC. */ -public abstract class Device implements Drawable {
- /**
- * the handle to the X Display
- * (Warning: This field is platform dependent)
+public abstract class Device implements Drawable { + /** + * the handle to the X Display + * (Warning: This field is platform dependent) + */ + public int xDisplay; + + /** + * whether the XLFD resolution should match the + * resolution of the device when fonts are created + * (Warning: This field is platform dependent) */ - public int xDisplay;
-
- /**
- * whether the XLFD resolution should match the
- * resolution of the device when fonts are created
- * (Warning: This field is platform dependent)
- */
- // TEMPORARY CODE
- public boolean setDPI;
-
- /* Debugging */
- public static boolean DEBUG;
- boolean debug = DEBUG;
- boolean tracking = DEBUG;
- Error [] errors;
- Object [] objects;
-
- /* Arguments for XtOpenDisplay */
- String display_name;
- String application_name;
- String application_class;
-
- /* Colormap and reference count for this display */
- XColor [] xcolors;
- int [] colorRefCount;
-
- /* System Colors */
- Color COLOR_BLACK, COLOR_DARK_RED, COLOR_DARK_GREEN, COLOR_DARK_YELLOW, COLOR_DARK_BLUE;
- Color COLOR_DARK_MAGENTA, COLOR_DARK_CYAN, COLOR_GRAY, COLOR_DARK_GRAY, COLOR_RED;
+ // TEMPORARY CODE + public boolean setDPI; + + /* Debugging */ + public static boolean DEBUG; + boolean debug = DEBUG; + boolean tracking = DEBUG; + Error [] errors; + Object [] objects; + + /* Arguments for XtOpenDisplay */ + String display_name; + String application_name; + String application_class; + + /* Colormap and reference count for this display */ + XColor [] xcolors; + int [] colorRefCount; + + /* System Colors */ + Color COLOR_BLACK, COLOR_DARK_RED, COLOR_DARK_GREEN, COLOR_DARK_YELLOW, COLOR_DARK_BLUE; + Color COLOR_DARK_MAGENTA, COLOR_DARK_CYAN, COLOR_GRAY, COLOR_DARK_GRAY, COLOR_RED; Color COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE; /* System Font */ - Font systemFont;
-
- /* Warning and Error Handlers */
- boolean warnings = true;
- Callback xErrorCallback, xtWarningCallback, xIOErrorCallback, xtErrorCallback;
- int xErrorProc, xtWarningProc, xIOErrorProc, xtErrorProc;
- int xNullErrorProc, xtNullWarningProc, xNullIOErrorProc, xtNullErrorProc;
-
- /* Parsing Tables */
- int tabMapping, crMapping, tabPointer, crPointer;
-
- /*
- * 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;
-}
-
+ Font systemFont; + + /* Warning and Error Handlers */ + boolean warnings = true; + Callback xErrorCallback, xtWarningCallback, xIOErrorCallback, xtErrorCallback; + int xErrorProc, xtWarningProc, xIOErrorProc, xtErrorProc; + int xNullErrorProc, xtNullWarningProc, xNullIOErrorProc, xtNullErrorProc; + + /* Parsing Tables */ + int tabMapping, crMapping, tabPointer, crPointer; + + /* + * 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> @@ -107,35 +107,35 @@ static Device getDevice () { * @see #init * @see DeviceData */ -public Device(DeviceData data) {
- if (data != null) {
- display_name = data.display_name;
- application_name = data.application_name;
- application_class = data.application_class;
- tracking = data.tracking;
- debug = data.debug;
- }
- if (tracking) {
- errors = new Error [128];
- objects = new Object [128];
- }
- create (data);
- init ();
+public Device(DeviceData data) { + if (data != null) { + display_name = data.display_name; + application_name = data.application_name; + application_class = data.application_class; + tracking = data.tracking; + debug = data.debug; + } + if (tracking) { + errors = new Error [128]; + objects = new Object [128]; + } + create (data); + init (); - /* Initialize the system font slot */
- systemFont = getSystemFont ();
-}
-
-protected void checkDevice () {
- if (xDisplay == 0) SWT.error (SWT.ERROR_DEVICE_DISPOSED);
-}
-
-protected void create (DeviceData data) {
-}
-
-protected void destroy () {
-}
-
+ /* Initialize the system font slot */ + systemFont = getSystemFont (); +} + +protected void checkDevice () { + if (xDisplay == 0) SWT.error (SWT.ERROR_DEVICE_DISPOSED); +} + +protected void create (DeviceData data) { +} + +protected void destroy () { +} + /** * Disposes of the operating system resources associated with * the receiver. After this method has been invoked, the receiver @@ -146,28 +146,28 @@ protected void destroy () { * @see #destroy * @see #checkDevice */ -public void dispose () {
- if (isDisposed()) return;
- checkDevice ();
- release ();
- destroy ();
- xDisplay = 0;
- 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;
- }
- }
-}
-
+public void dispose () { + if (isDisposed()) return; + checkDevice (); + release (); + destroy (); + xDisplay = 0; + 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; + } + } +} + /** * Returns a rectangle describing the receiver's size and location. * @@ -177,14 +177,14 @@ void dispose_Object (Object object) { * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public Rectangle getBounds () {
- checkDevice ();
- int screen = OS.XDefaultScreen (xDisplay);
- int width = OS.XDisplayWidth (xDisplay, screen);
- int height = OS.XDisplayHeight (xDisplay, screen);
- return new Rectangle (0, 0, width, height);
-}
-
+public Rectangle getBounds () { + checkDevice (); + int screen = OS.XDefaultScreen (xDisplay); + int width = OS.XDisplayWidth (xDisplay, screen); + int height = OS.XDisplayHeight (xDisplay, screen); + return new Rectangle (0, 0, width, height); +} + /** * Returns a rectangle which describes the area of the * receiver which is capable of displaying data. @@ -197,10 +197,10 @@ public Rectangle getBounds () { * * @see #getBounds */ -public Rectangle getClientArea () {
- return getBounds ();
-}
-
+public Rectangle getClientArea () { + return getBounds (); +} + /** * Returns the bit depth of the screen, which is the number of * bits it takes to represent the number of unique colors that @@ -213,12 +213,12 @@ public Rectangle getClientArea () { * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public int getDepth () {
- checkDevice ();
- int xScreenPtr = OS.XDefaultScreenOfDisplay (xDisplay);
- return OS.XDefaultDepthOfScreen (xScreenPtr);
-}
-
+public int getDepth () { + checkDevice (); + int xScreenPtr = OS.XDefaultScreenOfDisplay (xDisplay); + return OS.XDefaultDepthOfScreen (xScreenPtr); +} + /** * Returns a <code>DeviceData</code> based on the receiver. * Modifications made to this <code>DeviceData</code> will not @@ -232,32 +232,32 @@ public int getDepth () { * * @see DeviceData */ -public DeviceData getDeviceData () {
- checkDevice ();
- DeviceData data = new DeviceData ();
- data.display_name = display_name;
- data.application_name = application_name;
- data.application_class = application_class;
- data.debug = debug;
- data.tracking = tracking;
- 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;
-}
-
+public DeviceData getDeviceData () { + checkDevice (); + DeviceData data = new DeviceData (); + data.display_name = display_name; + data.application_name = application_name; + data.application_class = application_class; + data.debug = debug; + data.tracking = tracking; + 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 point whose x coordinate is the horizontal * dots per inch of the display, and whose y coordinate @@ -269,21 +269,21 @@ public DeviceData getDeviceData () { * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public Point getDPI () {
- checkDevice ();
- int xScreenNum = OS.XDefaultScreen (xDisplay);
- int width = OS.XDisplayWidth (xDisplay, xScreenNum);
- int height = OS.XDisplayHeight (xDisplay, xScreenNum);
- int mmX = OS.XDisplayWidthMM (xDisplay, xScreenNum);
- int mmY = OS.XDisplayHeightMM (xDisplay, xScreenNum);
- /* 0.03937 mm/inch */
- double inchesX = mmX * 0.03937;
- double inchesY = mmY * 0.03937;
- int x = (int)((width / inchesX) + 0.5);
- int y = (int)((height / inchesY) + 0.5);
- return new Point (x, y);
-}
-
+public Point getDPI () { + checkDevice (); + int xScreenNum = OS.XDefaultScreen (xDisplay); + int width = OS.XDisplayWidth (xDisplay, xScreenNum); + int height = OS.XDisplayHeight (xDisplay, xScreenNum); + int mmX = OS.XDisplayWidthMM (xDisplay, xScreenNum); + int mmY = OS.XDisplayHeightMM (xDisplay, xScreenNum); + /* 0.03937 mm/inch */ + double inchesX = mmX * 0.03937; + double inchesY = mmY * 0.03937; + int x = (int)((width / inchesX) + 0.5); + int y = (int)((height / inchesY) + 0.5); + return new Point (x, y); +} + /** * Returns <code>FontData</code> objects which describe * the fonts that match the given arguments. If the @@ -297,49 +297,49 @@ public Point getDPI () { * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public FontData [] getFontList (String faceName, boolean scalable) {
- checkDevice ();
- String xlfd;
- if (faceName == null) {
- xlfd = "-*-*-*-*-*-*-*-*-*-*-*-*-*-*";
- } else {
- int dashIndex = faceName.indexOf('-');
- if (dashIndex < 0) {
- xlfd = "-*-" + faceName + "-*-*-*-*-*-*-*-*-*-*-*-*";
- } else {
- xlfd = "-" + faceName + "-*-*-*-*-*-*-*-*-*-*-*-*";
- }
- }
- /* Use the character encoding for the default locale */
- byte [] buffer1 = Converter.wcsToMbcs (null, xlfd, true);
- int [] ret = new int [1];
- int listPtr = OS.XListFonts (xDisplay, buffer1, 65535, ret);
- int ptr = listPtr;
- int [] intBuf = new int [1];
- FontData [] fd = new FontData [ret [0]];
- int fdIndex = 0;
- for (int i = 0; i < ret [0]; i++) {
- OS.memmove (intBuf, ptr, 4);
- int charPtr = intBuf [0];
- int length = OS.strlen (charPtr);
- byte [] buffer2 = new byte [length];
- OS.memmove (buffer2, charPtr, length);
- /* Use the character encoding for the default locale */
- char [] chars = Converter.mbcsToWcs (null, buffer2);
- FontData data = FontData.motif_new (new String (chars));
- boolean isScalable = data.averageWidth == 0 && data.pixels == 0 && data.points == 0;
- if (isScalable == scalable) {
- fd [fdIndex++] = data;
- }
- ptr += 4;
- }
- OS.XFreeFontNames (listPtr);
- if (fdIndex == ret [0]) return fd;
- FontData [] result = new FontData [fdIndex];
- System.arraycopy (fd, 0, result, 0, fdIndex);
- return result;
-}
-
+public FontData [] getFontList (String faceName, boolean scalable) { + checkDevice (); + String xlfd; + if (faceName == null) { + xlfd = "-*-*-*-*-*-*-*-*-*-*-*-*-*-*"; + } else { + int dashIndex = faceName.indexOf('-'); + if (dashIndex < 0) { + xlfd = "-*-" + faceName + "-*-*-*-*-*-*-*-*-*-*-*-*"; + } else { + xlfd = "-" + faceName + "-*-*-*-*-*-*-*-*-*-*-*-*"; + } + } + /* Use the character encoding for the default locale */ + byte [] buffer1 = Converter.wcsToMbcs (null, xlfd, true); + int [] ret = new int [1]; + int listPtr = OS.XListFonts (xDisplay, buffer1, 65535, ret); + int ptr = listPtr; + int [] intBuf = new int [1]; + FontData [] fd = new FontData [ret [0]]; + int fdIndex = 0; + for (int i = 0; i < ret [0]; i++) { + OS.memmove (intBuf, ptr, 4); + int charPtr = intBuf [0]; + int length = OS.strlen (charPtr); + byte [] buffer2 = new byte [length]; + OS.memmove (buffer2, charPtr, length); + /* Use the character encoding for the default locale */ + char [] chars = Converter.mbcsToWcs (null, buffer2); + FontData data = FontData.motif_new (new String (chars)); + boolean isScalable = data.averageWidth == 0 && data.pixels == 0 && data.points == 0; + if (isScalable == scalable) { + fd [fdIndex++] = data; + } + ptr += 4; + } + OS.XFreeFontNames (listPtr); + if (fdIndex == ret [0]) return fd; + FontData [] result = new FontData [fdIndex]; + System.arraycopy (fd, 0, result, 0, fdIndex); + return result; +} + /** * Returns the matching standard color for the given * constant, which should be one of the color constants @@ -358,31 +358,31 @@ public FontData [] getFontList (String faceName, boolean scalable) { * * @see SWT */ -public Color getSystemColor (int id) {
- checkDevice ();
- XColor xColor = null;
- 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;
- }
- if (xColor == null) return COLOR_BLACK;
- return Color.motif_new (this, xColor);
-}
-
+public Color getSystemColor (int id) { + checkDevice (); + XColor xColor = null; + 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; + } + if (xColor == null) return COLOR_BLACK; + return Color.motif_new (this, xColor); +} + /** * Returns a reasonable font for applications to use. * On some platforms, this will match the "default font" @@ -403,11 +403,11 @@ public Color getSystemColor (int id) { * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public Font getSystemFont () {
- checkDevice ();
- return systemFont;
-}
-
+public Font getSystemFont () { + checkDevice (); + return systemFont; +} + /** * Returns <code>true</code> if the underlying window system prints out * warning messages on the console, and <code>setWarnings</code> @@ -419,93 +419,93 @@ public Font getSystemFont () { * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public boolean getWarnings () {
- checkDevice ();
- return warnings;
-}
-
-protected void init () {
-
- /* Create the warning and error callbacks */
- xErrorCallback = new Callback (this, "xErrorProc", 2);
- xNullErrorProc = xErrorCallback.getAddress ();
- if (xNullErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- xtWarningCallback = new Callback (this, "xtWarningProc", 1);
- xtNullWarningProc = xtWarningCallback.getAddress ();
- if (xtNullWarningProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- xIOErrorCallback = new Callback (this, "xIOErrorProc", 1);
- xNullIOErrorProc = xIOErrorCallback.getAddress ();
- if (xNullIOErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
- xtErrorCallback = new Callback (this, "xtErrorProc", 1);
- xtNullErrorProc = xtErrorCallback.getAddress ();
- if (xtNullErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- /* Set the warning and error handlers */
- if (debug) OS.XSynchronize (xDisplay, true);
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- xErrorProc = OS.XSetErrorHandler (xNullErrorProc);
- if (!debug) OS.XSetErrorHandler (xErrorProc);
- xtWarningProc = OS.XtAppSetWarningHandler (xtContext, xtNullWarningProc);
- if (!debug) OS.XtAppSetWarningHandler (xtContext, xtWarningProc);
- xIOErrorProc = OS.XSetIOErrorHandler (xNullIOErrorProc);
- if (!debug) OS.XSetIOErrorHandler (xIOErrorProc);
- xtErrorProc = OS.XtAppSetErrorHandler (xtContext, xtNullErrorProc);
- if (!debug) OS.XtAppSetErrorHandler (xtContext, xtErrorProc);
-
- /* Only use palettes for <= 8 bpp default visual */
- int xScreenPtr = OS.XDefaultScreenOfDisplay (xDisplay);
- int defaultDepth = OS.XDefaultDepthOfScreen (xScreenPtr);
- if (defaultDepth <= 8) {
- int numColors = 1 << defaultDepth;
- colorRefCount = new int [numColors];
- xcolors = new XColor [numColors];
- }
-
- /*
- * The following colors are listed in the Windows
- * Programmer's Reference as the colors in the default
- * palette.
- */
- COLOR_BLACK = new Color (this, 0,0,0);
- COLOR_DARK_RED = new Color (this, 0x80,0,0);
- COLOR_DARK_GREEN = new Color (this, 0,0x80,0);
- COLOR_DARK_YELLOW = new Color (this, 0x80,0x80,0);
- COLOR_DARK_BLUE = new Color (this, 0,0,0x80);
- COLOR_DARK_MAGENTA = new Color (this, 0x80,0,0x80);
- COLOR_DARK_CYAN = new Color (this, 0,0x80,0x80);
- COLOR_GRAY = new Color (this, 0xC0,0xC0,0xC0);
- COLOR_DARK_GRAY = new Color (this, 0x80,0x80,0x80);
- COLOR_RED = new Color (this, 0xFF,0,0);
- COLOR_GREEN = new Color (this, 0,0xFF,0);
- COLOR_YELLOW = new Color (this, 0xFF,0xFF,0);
- COLOR_BLUE = new Color (this, 0,0,0xFF);
- COLOR_MAGENTA = new Color (this, 0xFF,0,0xFF);
- COLOR_CYAN = new Color (this, 0,0xFF,0xFF);
- COLOR_WHITE = new Color (this, 0xFF,0xFF,0xFF);
-
- /* Create the parsing tables */
- byte[] tabBuffer = {(byte) '\t', 0};
- tabPointer = OS.XtMalloc (tabBuffer.length);
- OS.memmove (tabPointer, tabBuffer, tabBuffer.length);
- int tabString = OS.XmStringComponentCreate(OS.XmSTRING_COMPONENT_TAB, 0, null);
- int [] argList = {
- OS.XmNpattern, tabPointer,
- OS.XmNsubstitute, tabString,
- };
- tabMapping = OS.XmParseMappingCreate(argList, argList.length / 2);
- OS.XmStringFree(tabString);
- byte[] crBuffer = {(byte) '\n', 0};
- crPointer = OS.XtMalloc (crBuffer.length);
- OS.memmove (crPointer, crBuffer, crBuffer.length);
- int crString = OS.XmStringComponentCreate(OS.XmSTRING_COMPONENT_SEPARATOR, 0, null);
- argList = new int[] {
- OS.XmNpattern, crPointer,
- OS.XmNsubstitute, crString,
- };
- crMapping = OS.XmParseMappingCreate(argList, argList.length / 2);
- OS.XmStringFree(crString);
-}
-
+public boolean getWarnings () { + checkDevice (); + return warnings; +} + +protected void init () { + + /* Create the warning and error callbacks */ + xErrorCallback = new Callback (this, "xErrorProc", 2); + xNullErrorProc = xErrorCallback.getAddress (); + if (xNullErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); + xtWarningCallback = new Callback (this, "xtWarningProc", 1); + xtNullWarningProc = xtWarningCallback.getAddress (); + if (xtNullWarningProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); + xIOErrorCallback = new Callback (this, "xIOErrorProc", 1); + xNullIOErrorProc = xIOErrorCallback.getAddress (); + if (xNullIOErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); + xtErrorCallback = new Callback (this, "xtErrorProc", 1); + xtNullErrorProc = xtErrorCallback.getAddress (); + if (xtNullErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS); + + /* Set the warning and error handlers */ + if (debug) OS.XSynchronize (xDisplay, true); + int xtContext = OS.XtDisplayToApplicationContext (xDisplay); + xErrorProc = OS.XSetErrorHandler (xNullErrorProc); + if (!debug) OS.XSetErrorHandler (xErrorProc); + xtWarningProc = OS.XtAppSetWarningHandler (xtContext, xtNullWarningProc); + if (!debug) OS.XtAppSetWarningHandler (xtContext, xtWarningProc); + xIOErrorProc = OS.XSetIOErrorHandler (xNullIOErrorProc); + if (!debug) OS.XSetIOErrorHandler (xIOErrorProc); + xtErrorProc = OS.XtAppSetErrorHandler (xtContext, xtNullErrorProc); + if (!debug) OS.XtAppSetErrorHandler (xtContext, xtErrorProc); + + /* Only use palettes for <= 8 bpp default visual */ + int xScreenPtr = OS.XDefaultScreenOfDisplay (xDisplay); + int defaultDepth = OS.XDefaultDepthOfScreen (xScreenPtr); + if (defaultDepth <= 8) { + int numColors = 1 << defaultDepth; + colorRefCount = new int [numColors]; + xcolors = new XColor [numColors]; + } + + /* + * The following colors are listed in the Windows + * Programmer's Reference as the colors in the default + * palette. + */ + COLOR_BLACK = new Color (this, 0,0,0); + COLOR_DARK_RED = new Color (this, 0x80,0,0); + COLOR_DARK_GREEN = new Color (this, 0,0x80,0); + COLOR_DARK_YELLOW = new Color (this, 0x80,0x80,0); + COLOR_DARK_BLUE = new Color (this, 0,0,0x80); + COLOR_DARK_MAGENTA = new Color (this, 0x80,0,0x80); + COLOR_DARK_CYAN = new Color (this, 0,0x80,0x80); + COLOR_GRAY = new Color (this, 0xC0,0xC0,0xC0); + COLOR_DARK_GRAY = new Color (this, 0x80,0x80,0x80); + COLOR_RED = new Color (this, 0xFF,0,0); + COLOR_GREEN = new Color (this, 0,0xFF,0); + COLOR_YELLOW = new Color (this, 0xFF,0xFF,0); + COLOR_BLUE = new Color (this, 0,0,0xFF); + COLOR_MAGENTA = new Color (this, 0xFF,0,0xFF); + COLOR_CYAN = new Color (this, 0,0xFF,0xFF); + COLOR_WHITE = new Color (this, 0xFF,0xFF,0xFF); + + /* Create the parsing tables */ + byte[] tabBuffer = {(byte) '\t', 0}; + tabPointer = OS.XtMalloc (tabBuffer.length); + OS.memmove (tabPointer, tabBuffer, tabBuffer.length); + int tabString = OS.XmStringComponentCreate(OS.XmSTRING_COMPONENT_TAB, 0, null); + int [] argList = { + OS.XmNpattern, tabPointer, + OS.XmNsubstitute, tabString, + }; + tabMapping = OS.XmParseMappingCreate(argList, argList.length / 2); + OS.XmStringFree(tabString); + byte[] crBuffer = {(byte) '\n', 0}; + crPointer = OS.XtMalloc (crBuffer.length); + OS.memmove (crPointer, crBuffer, crBuffer.length); + int crString = OS.XmStringComponentCreate(OS.XmSTRING_COMPONENT_SEPARATOR, 0, null); + argList = new int[] { + OS.XmNpattern, crPointer, + OS.XmNsubstitute, crString, + }; + crMapping = OS.XmParseMappingCreate(argList, argList.length / 2); + OS.XmStringFree(crString); +} + /** * Invokes platform specific functionality to allocate a new GC handle. * <p> @@ -521,8 +521,8 @@ protected void init () { * * @private */ -public abstract int internal_new_GC (GCData data);
-
+public abstract int internal_new_GC (GCData data); + /** * Invokes platform specific functionality to dispose a GC handle. * <p> @@ -538,8 +538,8 @@ public abstract int internal_new_GC (GCData data); * * @private */ -public abstract void internal_dispose_GC (int handle, GCData data);
-
+public abstract void internal_dispose_GC (int handle, GCData data); + /** * Returns <code>true</code> if the device has been disposed, * and <code>false</code> otherwise. @@ -550,61 +550,61 @@ public abstract void internal_dispose_GC (int handle, GCData data); * * @return <code>true</code> when the device is disposed and <code>false</code> otherwise */ -public boolean isDisposed () {
- return xDisplay == 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 () {
- /* Free the parsing tables */
- OS.XtFree(tabPointer);
- OS.XtFree(crPointer);
- OS.XmParseMappingFree(tabMapping);
- OS.XmParseMappingFree(crMapping);
- tabPointer = crPointer = tabMapping = crMapping = 0;
-
- /*
- * Free the palette. Note that this disposes all colors on
- * the display that were allocated using the Color constructor.
- */
- if (xcolors != null) {
- int xScreen = OS.XDefaultScreen (xDisplay);
- int xColormap = OS.XDefaultColormap (xDisplay, xScreen);
- int [] pixel = new int [1];
- for (int i = 0; i < xcolors.length; i++) {
- XColor color = xcolors [i];
- if (color != null) {
- pixel [0] = color.pixel;
- while (colorRefCount [i] > 0) {
- OS.XFreeColors (xDisplay, xColormap, pixel, 1, 0);
- --colorRefCount [i];
- }
- }
- }
- }
- xcolors = null;
- colorRefCount = null;
-
- 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;
+public boolean isDisposed () { + return xDisplay == 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 () { + /* Free the parsing tables */ + OS.XtFree(tabPointer); + OS.XtFree(crPointer); + OS.XmParseMappingFree(tabMapping); + OS.XmParseMappingFree(crMapping); + tabPointer = crPointer = tabMapping = crMapping = 0; + + /* + * Free the palette. Note that this disposes all colors on + * the display that were allocated using the Color constructor. + */ + if (xcolors != null) { + int xScreen = OS.XDefaultScreen (xDisplay); + int xColormap = OS.XDefaultColormap (xDisplay, xScreen); + int [] pixel = new int [1]; + for (int i = 0; i < xcolors.length; i++) { + XColor color = xcolors [i]; + if (color != null) { + pixel [0] = color.pixel; + while (colorRefCount [i] > 0) { + OS.XFreeColors (xDisplay, xColormap, pixel, 1, 0); + --colorRefCount [i]; + } + } + } + } + xcolors = null; + colorRefCount = null; + + COLOR_BLACK = COLOR_DARK_RED = COLOR_DARK_GREEN = COLOR_DARK_YELLOW = + COLOR_DARK_BLUE = COLOR_DARK_MAGENTA = COLOR_DARK_CYAN = COLOR_GRAY = COLOR_DARK_GRAY = COLOR_RED = + COLOR_GREEN = COLOR_YELLOW = COLOR_BLUE = COLOR_MAGENTA = COLOR_CYAN = COLOR_WHITE = null; /* Free the Xt error handler */ int xtContext = OS.XtDisplayToApplicationContext (xDisplay); @@ -637,9 +637,9 @@ protected void release () { OS.XSetErrorHandler (xNullErrorProc); // OS.XSetErrorHandler (xErrorProc); // xErrorCallback.dispose (); xErrorCallback = null; -// xNullErrorProc = xErrorProc = 0;
-}
-
+// xNullErrorProc = xErrorProc = 0; +} + /** * If the underlying window system supports printing warning messages * to the console, setting warnings to <code>true</code> prevents these @@ -652,50 +652,50 @@ protected void release () { * <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void setWarnings (boolean warnings) {
- checkDevice ();
- this.warnings = warnings;
- if (debug) return;
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- if (warnings) {
- OS.XSetErrorHandler (xErrorProc);
- OS.XtAppSetWarningHandler (xtContext, xtWarningProc);
- } else {
- OS.XSetErrorHandler (xNullErrorProc);
- OS.XtAppSetWarningHandler (xtContext, xtNullWarningProc);
- }
-}
-
-int xErrorProc (int xDisplay, int xErrorEvent) {
- if (DEBUG || (debug && warnings)) {
- new SWTError ().printStackTrace ();
- OS.Call (xErrorProc, xDisplay, xErrorEvent);
- }
- return 0;
-}
-
-int xIOErrorProc (int xDisplay) {
- if (DEBUG || debug) {
- new SWTError ().printStackTrace ();
- OS.Call (xIOErrorProc, xDisplay, 0);
- }
- return 0;
-}
-
-int xtErrorProc (int message) {
- if (DEBUG || debug) {
- new SWTError ().printStackTrace ();
- OS.Call (xtErrorProc, message, 0);
- }
- return 0;
-}
-
-int xtWarningProc (int message) {
- if (DEBUG || (debug && warnings)) {
- new SWTError ().printStackTrace ();
- OS.Call (xtWarningProc, message, 0);
- }
- return 0;
-}
-
+public void setWarnings (boolean warnings) { + checkDevice (); + this.warnings = warnings; + if (debug) return; + int xtContext = OS.XtDisplayToApplicationContext (xDisplay); + if (warnings) { + OS.XSetErrorHandler (xErrorProc); + OS.XtAppSetWarningHandler (xtContext, xtWarningProc); + } else { + OS.XSetErrorHandler (xNullErrorProc); + OS.XtAppSetWarningHandler (xtContext, xtNullWarningProc); + } +} + +int xErrorProc (int xDisplay, int xErrorEvent) { + if (DEBUG || (debug && warnings)) { + new SWTError ().printStackTrace (); + OS.Call (xErrorProc, xDisplay, xErrorEvent); + } + return 0; +} + +int xIOErrorProc (int xDisplay) { + if (DEBUG || debug) { + new SWTError ().printStackTrace (); + OS.Call (xIOErrorProc, xDisplay, 0); + } + return 0; +} + +int xtErrorProc (int message) { + if (DEBUG || debug) { + new SWTError ().printStackTrace (); + OS.Call (xtErrorProc, message, 0); + } + return 0; +} + +int xtWarningProc (int message) { + if (DEBUG || (debug && warnings)) { + new SWTError ().printStackTrace (); + OS.Call (xtWarningProc, message, 0); + } + return 0; +} + } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/DeviceData.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/DeviceData.java index ed4d6ba458..aad8e1fe72 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/DeviceData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/DeviceData.java @@ -1,26 +1,26 @@ -package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-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;
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +public class DeviceData { + /* + * Motif only fields. + */ + public String display_name; + public String application_name; + public String application_class; + + /* + * Debug fields - may not be honoured + * on some SWT platforms. + */ + public boolean debug; + public boolean tracking; + public Error [] errors; + public Object [] objects; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Font.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Font.java index 837fbe51d9..dcaab66578 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Font.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Font.java @@ -1,16 +1,16 @@ -package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; + /** * Instances of this class manage operating system resources that * define how text looks when it is displayed. Fonts may be constructed @@ -24,29 +24,29 @@ import org.eclipse.swt.*; * * @see FontData */ -public final class Font {
+public final class Font { /** * the handle to the OS font resource * (Warning: This field is platform dependent) */ - public int handle;
-
- /**
- * the code page of the font
- * (Warning: This field is platform dependent)
- *
- * @since 2.0
+ public int handle; + + /** + * the code page of the font + * (Warning: This field is platform dependent) + * + * @since 2.0 */ - public String codePage;
-
- /**
- * The device where this image was created.
+ public String codePage; + + /** + * The device where this image was created. */ - Device device;
-
-Font () {
-}
-
+ Device device; + +Font () { +} + /** * Constructs a new font given a device and font data * which describes the desired font's appearance. @@ -65,46 +65,46 @@ Font () { * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li> * </ul> */ -public Font (Device device, FontData fd) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (fd == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, new FontData[] {fd});
- if (device.tracking) device.new_Object(this);
-}
-
-/**
- * Constructs a new font given a device and font datas
- * which describes the desired font's appearance.
- * <p>
- * You must dispose the font when it is no longer required.
- * </p>
- *
- * @param device the device to create the font on
- * @param fds the array of FontData that describes the desired font (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li>
- * <li>ERROR_NULL_ARGUMENT - if the fds argument is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the length of fds is zero</li>
- * <li>ERROR_NULL_ARGUMENT - if any fd in the array is null</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li>
- * </ul>
- */
-public Font (Device device, FontData[] fds) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (fds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (fds.length == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- for (int i=0; i<fds.length; i++) {
- if (fds[i] == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
- init(device, fds);
- if (device.tracking) device.new_Object(this);
-}
-
+public Font (Device device, FontData fd) { + if (device == null) device = Device.getDevice(); + if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (fd == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + init(device, new FontData[] {fd}); + if (device.tracking) device.new_Object(this); +} + +/** + * Constructs a new font given a device and font datas + * which describes the desired font's appearance. + * <p> + * You must dispose the font when it is no longer required. + * </p> + * + * @param device the device to create the font on + * @param fds the array of FontData that describes the desired font (must not be null) + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> + * <li>ERROR_NULL_ARGUMENT - if the fds argument is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the length of fds is zero</li> + * <li>ERROR_NULL_ARGUMENT - if any fd in the array is null</li> + * </ul> + * @exception SWTError <ul> + * <li>ERROR_NO_HANDLES - if a font could not be created from the given font data</li> + * </ul> + */ +public Font (Device device, FontData[] fds) { + if (device == null) device = Device.getDevice(); + if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (fds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (fds.length == 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + for (int i=0; i<fds.length; i++) { + if (fds[i] == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + } + init(device, fds); + if (device.tracking) device.new_Object(this); +} + /** * Constructs a new font given a device, a font name, * the height of the desired font in points, and a font @@ -127,29 +127,29 @@ public Font (Device device, FontData[] fds) { * <li>ERROR_NO_HANDLES - if a font could not be created from the given arguments</li> * </ul> */ -public Font (Device device, String name, int height, int style) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, new FontData[]{new FontData(name, height, style)});
- if (device.tracking) device.new_Object(this);
-}
-
+public Font (Device device, String name, int height, int style) { + if (device == null) device = Device.getDevice(); + if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + init(device, new FontData[]{new FontData(name, height, style)}); + if (device.tracking) device.new_Object(this); +} + /** * Disposes of the operating system resources associated with * the font. Applications must dispose of all fonts which * they allocate. */ -public void dispose () {
+public void dispose () { if (handle == 0) return; - if (device.isDisposed()) return;
+ if (device.isDisposed()) return; if (handle == device.systemFont.handle) return; - OS.XmFontListFree (handle);
- handle = 0;
+ OS.XmFontListFree (handle); + handle = 0; if (device.tracking) device.dispose_Object(this); - device = null;
-}
-
+ device = null; +} + /** * Compares the argument to the receiver, and returns true * if they represent the <em>same</em> object using a class @@ -160,87 +160,87 @@ public void dispose () { * * @see #hashCode */ -public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Font)) return false;
- Font font = (Font)object;
- return device == font.device && handle == font.handle;
-}
-
-/**
- * Returns the code page for the specified font list.
- *
- * @return the code page for the font list
- */
-static String getCodePage (int xDisplay, int fontList) {
- int[] buffer = new int[1];
- if (!OS.XmFontListInitFontContext(buffer, fontList)) return null;
- int context = buffer[0];
- XFontStruct fontStruct = new XFontStruct();
- int fontListEntry;
- String codePage = null;
- /* Go through each entry in the font list */
- while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer);
- if (buffer[0] == OS.XmFONT_IS_FONT) {
- /* FontList contains a single font */
- OS.memmove(fontStruct,fontPtr,20 * 4);
- int propPtr = fontStruct.properties;
- for (int i = 0; i < fontStruct.n_properties; i++) {
- /* Reef through properties looking for XAFONT */
- int[] prop = new int[2];
- OS.memmove(prop, propPtr, 8);
- if (prop[0] == OS.XA_FONT) {
- /* Found it, prop[1] points to the string */
- int ptr = OS.XmGetAtomName(xDisplay, prop[1]);
- int length = OS.strlen(ptr);
- byte[] nameBuf = new byte[length];
- OS.memmove(nameBuf, ptr, length);
- /* Use the character encoding for the default locale */
- String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase();
- int start = xlfd.lastIndexOf ('-');
- if (start != -1 && start > 0) {
- start = xlfd.lastIndexOf ('-', start - 1);
- if (start != -1) {
- codePage = xlfd.substring (start + 1, xlfd.length ());
- if (codePage.indexOf ("iso") == 0) {
- if (OS.IsLinux) {
- codePage = "ISO-" + codePage.substring (3, codePage.length ());
- }
- }
- }
- }
- OS.XtFree(ptr);
- break;
- }
- propPtr += 8;
- }
- }
- else {
- /* FontList contains a fontSet */
-
- /* Get the font set locale */
- int localePtr = OS.XLocaleOfFontSet(fontPtr);
- int length = OS.strlen (localePtr);
- byte [] locale = new byte [length + 1];
- OS.memmove (locale, localePtr, length);
-
- /* Get code page for the font set locale */
- OS.setlocale (OS.LC_CTYPE, locale);
- int codesetPtr = OS.nl_langinfo (OS.CODESET);
- length = OS.strlen (codesetPtr);
- byte [] codeset = new byte [length];
- OS.memmove (codeset, codesetPtr, length);
- codePage = new String(Converter.mbcsToWcs(null, codeset));
-
- /* Reset the locale */
- OS.setlocale (OS.LC_CTYPE, new byte[1]);
- }
- }
- OS.XmFontListFreeFontContext(context);
- return codePage;
-}
-
+public boolean equals (Object object) { + if (object == this) return true; + if (!(object instanceof Font)) return false; + Font font = (Font)object; + return device == font.device && handle == font.handle; +} + +/** + * Returns the code page for the specified font list. + * + * @return the code page for the font list + */ +static String getCodePage (int xDisplay, int fontList) { + int[] buffer = new int[1]; + if (!OS.XmFontListInitFontContext(buffer, fontList)) return null; + int context = buffer[0]; + XFontStruct fontStruct = new XFontStruct(); + int fontListEntry; + String codePage = null; + /* Go through each entry in the font list */ + while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) { + int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer); + if (buffer[0] == OS.XmFONT_IS_FONT) { + /* FontList contains a single font */ + OS.memmove(fontStruct,fontPtr,20 * 4); + int propPtr = fontStruct.properties; + for (int i = 0; i < fontStruct.n_properties; i++) { + /* Reef through properties looking for XAFONT */ + int[] prop = new int[2]; + OS.memmove(prop, propPtr, 8); + if (prop[0] == OS.XA_FONT) { + /* Found it, prop[1] points to the string */ + int ptr = OS.XmGetAtomName(xDisplay, prop[1]); + int length = OS.strlen(ptr); + byte[] nameBuf = new byte[length]; + OS.memmove(nameBuf, ptr, length); + /* Use the character encoding for the default locale */ + String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase(); + int start = xlfd.lastIndexOf ('-'); + if (start != -1 && start > 0) { + start = xlfd.lastIndexOf ('-', start - 1); + if (start != -1) { + codePage = xlfd.substring (start + 1, xlfd.length ()); + if (codePage.indexOf ("iso") == 0) { + if (OS.IsLinux) { + codePage = "ISO-" + codePage.substring (3, codePage.length ()); + } + } + } + } + OS.XtFree(ptr); + break; + } + propPtr += 8; + } + } + else { + /* FontList contains a fontSet */ + + /* Get the font set locale */ + int localePtr = OS.XLocaleOfFontSet(fontPtr); + int length = OS.strlen (localePtr); + byte [] locale = new byte [length + 1]; + OS.memmove (locale, localePtr, length); + + /* Get code page for the font set locale */ + OS.setlocale (OS.LC_CTYPE, locale); + int codesetPtr = OS.nl_langinfo (OS.CODESET); + length = OS.strlen (codesetPtr); + byte [] codeset = new byte [length]; + OS.memmove (codeset, codesetPtr, length); + codePage = new String(Converter.mbcsToWcs(null, codeset)); + + /* Reset the locale */ + OS.setlocale (OS.LC_CTYPE, new byte[1]); + } + } + OS.XmFontListFreeFontContext(context); + return codePage; +} + /** * Returns an array of <code>FontData</code>s representing the receiver. * On Windows, only one FontData will be returned per font. On X however, @@ -253,102 +253,102 @@ static String getCodePage (int xDisplay, int fontList) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public FontData[] getFontData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int xDisplay = device.xDisplay;
- /*
- * Create a font context to iterate over each element in the font list.
- * If a font context can not be created, return null.
+public FontData[] getFontData() { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + int xDisplay = device.xDisplay; + /* + * Create a font context to iterate over each element in the font list. + * If a font context can not be created, return null. */ - int[] buffer = new int[1];
- if (!OS.XmFontListInitFontContext(buffer, handle)) return null;
- int context = buffer[0];
- XFontStruct fontStruct = new XFontStruct();
- int fontListEntry;
- int[] fontStructPtr = new int[1];
- int[] fontNamePtr = new int[1];
- String[] xlfds = new String[0];
- /* Go through each entry in the font list */
- while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer);
- if (buffer[0] == OS.XmFONT_IS_FONT) {
- /* FontList contains a single font */
- OS.memmove(fontStruct,fontPtr,20 * 4);
- int propPtr = fontStruct.properties;
- for (int i = 0; i < fontStruct.n_properties; i++) {
- /* Reef through properties looking for XAFONT */
- int[] prop = new int[2];
- OS.memmove(prop, propPtr, 8);
- if (prop[0] == OS.XA_FONT) {
- /* Found it, prop[1] points to the string */
- int ptr = OS.XmGetAtomName(xDisplay, prop[1]);
- int length = OS.strlen(ptr);
- byte[] nameBuf = new byte[length];
- OS.memmove(nameBuf, ptr, length);
- /* Use the character encoding for the default locale */
- String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase();
- /* Add the xlfd to the array */
- String[] newXlfds = new String[xlfds.length + 1];
- System.arraycopy(xlfds, 0, newXlfds, 0, xlfds.length);
- newXlfds[newXlfds.length - 1] = xlfd;
- xlfds = newXlfds;
- OS.XtFree(ptr);
- break;
- }
- propPtr += 8;
- }
- }
- else {
- /* FontList contains a fontSet */
- int nFonts = OS.XFontsOfFontSet(fontPtr,fontStructPtr,fontNamePtr);
- int [] fontStructs = new int[nFonts];
- OS.memmove(fontStructs,fontStructPtr[0],nFonts * 4);
- for (int i = 0; i < nFonts; i++) { // Go through each fontStruct in the font set.
- OS.memmove(fontStruct,fontStructs[i],20 * 4);
- int propPtr = fontStruct.properties;
- for (int j = 0; j < fontStruct.n_properties; j++) {
- // Reef through properties looking for XAFONT
- int[] prop = new int[2];
- OS.memmove(prop, propPtr, 8);
- if (prop[0] == OS.XA_FONT) {
- /* Found it, prop[1] points to the string */
- int ptr = OS.XmGetAtomName(xDisplay, prop[1]);
- int length = OS.strlen(ptr);
- byte[] nameBuf = new byte[length];
- OS.memmove(nameBuf, ptr, length);
- String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase();
- /* Add the xlfd to the array */
- String[] newXlfds = new String[xlfds.length + 1];
- System.arraycopy(xlfds, 0, newXlfds, 0, xlfds.length);
- newXlfds[newXlfds.length - 1] = xlfd;
- xlfds = newXlfds;
- OS.XFree(ptr);
- break;
- }
- propPtr += 8;
- }
- }
- }
- }
- OS.XmFontListFreeFontContext(context);
- if (xlfds.length == 0) return null;
- FontData[] fontData = new FontData[xlfds.length];
- /* Construct each fontData out of the xlfd */
- try {
- for (int i = 0; i < xlfds.length; i++) {
- fontData[i] = FontData.motif_new(xlfds[i]);
- }
- } catch (Exception e) {
- /*
- * Some font servers, for example, xfstt, do not pass
- * reasonable font properties to the client, so we
- * cannot construct a FontData for these. Return null.
+ int[] buffer = new int[1]; + if (!OS.XmFontListInitFontContext(buffer, handle)) return null; + int context = buffer[0]; + XFontStruct fontStruct = new XFontStruct(); + int fontListEntry; + int[] fontStructPtr = new int[1]; + int[] fontNamePtr = new int[1]; + String[] xlfds = new String[0]; + /* Go through each entry in the font list */ + while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) { + int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer); + if (buffer[0] == OS.XmFONT_IS_FONT) { + /* FontList contains a single font */ + OS.memmove(fontStruct,fontPtr,20 * 4); + int propPtr = fontStruct.properties; + for (int i = 0; i < fontStruct.n_properties; i++) { + /* Reef through properties looking for XAFONT */ + int[] prop = new int[2]; + OS.memmove(prop, propPtr, 8); + if (prop[0] == OS.XA_FONT) { + /* Found it, prop[1] points to the string */ + int ptr = OS.XmGetAtomName(xDisplay, prop[1]); + int length = OS.strlen(ptr); + byte[] nameBuf = new byte[length]; + OS.memmove(nameBuf, ptr, length); + /* Use the character encoding for the default locale */ + String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase(); + /* Add the xlfd to the array */ + String[] newXlfds = new String[xlfds.length + 1]; + System.arraycopy(xlfds, 0, newXlfds, 0, xlfds.length); + newXlfds[newXlfds.length - 1] = xlfd; + xlfds = newXlfds; + OS.XtFree(ptr); + break; + } + propPtr += 8; + } + } + else { + /* FontList contains a fontSet */ + int nFonts = OS.XFontsOfFontSet(fontPtr,fontStructPtr,fontNamePtr); + int [] fontStructs = new int[nFonts]; + OS.memmove(fontStructs,fontStructPtr[0],nFonts * 4); + for (int i = 0; i < nFonts; i++) { // Go through each fontStruct in the font set. + OS.memmove(fontStruct,fontStructs[i],20 * 4); + int propPtr = fontStruct.properties; + for (int j = 0; j < fontStruct.n_properties; j++) { + // Reef through properties looking for XAFONT + int[] prop = new int[2]; + OS.memmove(prop, propPtr, 8); + if (prop[0] == OS.XA_FONT) { + /* Found it, prop[1] points to the string */ + int ptr = OS.XmGetAtomName(xDisplay, prop[1]); + int length = OS.strlen(ptr); + byte[] nameBuf = new byte[length]; + OS.memmove(nameBuf, ptr, length); + String xlfd = new String(Converter.mbcsToWcs(null, nameBuf)).toLowerCase(); + /* Add the xlfd to the array */ + String[] newXlfds = new String[xlfds.length + 1]; + System.arraycopy(xlfds, 0, newXlfds, 0, xlfds.length); + newXlfds[newXlfds.length - 1] = xlfd; + xlfds = newXlfds; + OS.XFree(ptr); + break; + } + propPtr += 8; + } + } + } + } + OS.XmFontListFreeFontContext(context); + if (xlfds.length == 0) return null; + FontData[] fontData = new FontData[xlfds.length]; + /* Construct each fontData out of the xlfd */ + try { + for (int i = 0; i < xlfds.length; i++) { + fontData[i] = FontData.motif_new(xlfds[i]); + } + } catch (Exception e) { + /* + * Some font servers, for example, xfstt, do not pass + * reasonable font properties to the client, so we + * cannot construct a FontData for these. Return null. */ - return null;
- }
- return fontData;
-}
-
+ return null; + } + return fontData; +} + /** * Returns an integer hash code for the receiver. Any two * objects which return <code>true</code> when passed to @@ -359,93 +359,93 @@ public FontData[] getFontData() { * * @see #equals */ -public int hashCode () {
- return handle;
-}
-
-void init (Device device, FontData[] fds) {
- this.device = device;
-
- /* Change current locale if needed. Note: only the first font data is used */
- FontData firstFd = fds[0];
- if (firstFd.lang != null) {
- String lang = firstFd.lang;
- String country = firstFd.country;
- String variant = firstFd.variant;
- String osLocale = lang;
- if (country != null) osLocale += "_" + country;
- if (variant != null) osLocale += "." + variant;
- int length = osLocale.length();
- byte [] buffer = new byte[length + 1];
- for (int i=0; i<length; i++) {
- buffer[i] = (byte)osLocale.charAt(i);
- }
- OS.setlocale (OS.LC_CTYPE, buffer);
- }
-
- /* Generate desire font name */
- Point dpi = null;
- if (device.setDPI) dpi = device.getDPI();
- StringBuffer stringBuffer = new StringBuffer();
- for (int i = 0; i < fds.length; i++) {
- FontData fd = fds[i];
- int hRes = fd.horizontalResolution, vRes = fd.verticalResolution;
- if (dpi != null) {
- fd.horizontalResolution = dpi.x;
- fd.verticalResolution = dpi.y;
- }
- stringBuffer.append(fd.getXlfd());
- stringBuffer.append(',');
- fd.horizontalResolution = hRes;
- fd.verticalResolution = vRes;
- }
-
- /* Append simplified font name */
- FontData newFd = new FontData();
- newFd.points = firstFd.points;
- /*
- * Bug in Motif. In Japanese AIX only, in some cases loading a bold Japanese
- * font takes a very long time (10 minutes) when there are no Japanese bold
- * fonts available. The fix is to wildcard the field weight.
- */
- if (OS.IsAIX && OS.IsDBLocale) {
- stringBuffer.append(newFd.getXlfd());
- } else {
- newFd.weight = firstFd.weight;
- newFd.slant = firstFd.slant;
- stringBuffer.append(newFd.getXlfd());
- newFd.weight = null;
- newFd.slant = null;
- stringBuffer.append(',');
- stringBuffer.append(newFd.getXlfd());
- }
-
- /* Load font list entry */
- boolean warnings = device.getWarnings ();
- device.setWarnings (false);
- byte[] buffer = Converter.wcsToMbcs(null, stringBuffer.toString() , true);
- int fontListEntry = OS.XmFontListEntryLoad(device.xDisplay, buffer, OS.XmFONT_IS_FONTSET, OS.XmFONTLIST_DEFAULT_TAG);
- device.setWarnings (warnings);
- if (fontListEntry != 0) {
- handle = OS.XmFontListAppendEntry(0, fontListEntry);
- OS.XmFontListEntryFree(new int[]{fontListEntry});
- int codesetPtr = OS.nl_langinfo(OS.CODESET);
- int length = OS.strlen(codesetPtr);
- byte[] codeset = new byte[length];
- OS.memmove(codeset, codesetPtr, length);
- codePage = new String(Converter.mbcsToWcs(null, codeset));
- } else {
- Font systemFont = device.systemFont;
- handle = systemFont.handle;
- codePage = systemFont.codePage;
- }
-
- /* Reset current locale if needed */
- if (firstFd.lang != null) OS.setlocale(OS.LC_CTYPE, new byte[0]);
-
- if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
-}
-
+public int hashCode () { + return handle; +} + +void init (Device device, FontData[] fds) { + this.device = device; + + /* Change current locale if needed. Note: only the first font data is used */ + FontData firstFd = fds[0]; + if (firstFd.lang != null) { + String lang = firstFd.lang; + String country = firstFd.country; + String variant = firstFd.variant; + String osLocale = lang; + if (country != null) osLocale += "_" + country; + if (variant != null) osLocale += "." + variant; + int length = osLocale.length(); + byte [] buffer = new byte[length + 1]; + for (int i=0; i<length; i++) { + buffer[i] = (byte)osLocale.charAt(i); + } + OS.setlocale (OS.LC_CTYPE, buffer); + } + + /* Generate desire font name */ + Point dpi = null; + if (device.setDPI) dpi = device.getDPI(); + StringBuffer stringBuffer = new StringBuffer(); + for (int i = 0; i < fds.length; i++) { + FontData fd = fds[i]; + int hRes = fd.horizontalResolution, vRes = fd.verticalResolution; + if (dpi != null) { + fd.horizontalResolution = dpi.x; + fd.verticalResolution = dpi.y; + } + stringBuffer.append(fd.getXlfd()); + stringBuffer.append(','); + fd.horizontalResolution = hRes; + fd.verticalResolution = vRes; + } + + /* Append simplified font name */ + FontData newFd = new FontData(); + newFd.points = firstFd.points; + /* + * Bug in Motif. In Japanese AIX only, in some cases loading a bold Japanese + * font takes a very long time (10 minutes) when there are no Japanese bold + * fonts available. The fix is to wildcard the field weight. + */ + if (OS.IsAIX && OS.IsDBLocale) { + stringBuffer.append(newFd.getXlfd()); + } else { + newFd.weight = firstFd.weight; + newFd.slant = firstFd.slant; + stringBuffer.append(newFd.getXlfd()); + newFd.weight = null; + newFd.slant = null; + stringBuffer.append(','); + stringBuffer.append(newFd.getXlfd()); + } + + /* Load font list entry */ + boolean warnings = device.getWarnings (); + device.setWarnings (false); + byte[] buffer = Converter.wcsToMbcs(null, stringBuffer.toString() , true); + int fontListEntry = OS.XmFontListEntryLoad(device.xDisplay, buffer, OS.XmFONT_IS_FONTSET, OS.XmFONTLIST_DEFAULT_TAG); + device.setWarnings (warnings); + if (fontListEntry != 0) { + handle = OS.XmFontListAppendEntry(0, fontListEntry); + OS.XmFontListEntryFree(new int[]{fontListEntry}); + int codesetPtr = OS.nl_langinfo(OS.CODESET); + int length = OS.strlen(codesetPtr); + byte[] codeset = new byte[length]; + OS.memmove(codeset, codesetPtr, length); + codePage = new String(Converter.mbcsToWcs(null, codeset)); + } else { + Font systemFont = device.systemFont; + handle = systemFont.handle; + codePage = systemFont.codePage; + } + + /* Reset current locale if needed */ + if (firstFd.lang != null) OS.setlocale(OS.LC_CTYPE, new byte[0]); + + if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); +} + /** * Returns <code>true</code> if the font has been disposed, * and <code>false</code> otherwise. @@ -456,27 +456,27 @@ void init (Device device, FontData[] fds) { * * @return <code>true</code> when the font is disposed and <code>false</code> otherwise */ -public boolean isDisposed() {
- return handle == 0;
-}
-
-public static Font motif_new(Device device, int handle) {
- if (device == null) device = Device.getDevice();
- Font font = new Font();
- font.device = device;
- font.handle = handle;
- font.codePage = getCodePage(device.xDisplay, handle);
- return font;
-}
-
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
+public boolean isDisposed() { + return handle == 0; +} + +public static Font motif_new(Device device, int handle) { + if (device == null) device = Device.getDevice(); + Font font = new Font(); + font.device = device; + font.handle = handle; + font.codePage = getCodePage(device.xDisplay, handle); + return font; +} + +/** + * Returns a string containing a concise, human-readable + * description of the receiver. + * + * @return a string representation of the receiver */ -public String toString () {
- if (isDisposed()) return "Font {*DISPOSED*}";
- return "Font {" + handle + "}";
-}
-}
+public String toString () { + if (isDisposed()) return "Font {*DISPOSED*}"; + return "Font {" + handle + "}"; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java index d6dfc76f5e..32fd6df6c9 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontData.java @@ -1,14 +1,14 @@ -package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.*; + /** * Instances of this class describe operating system fonts. * Only the public API of this type is platform independent. @@ -34,88 +34,88 @@ import org.eclipse.swt.*; * * @see Font */ -public final class FontData {
- /**
- * The company that produced the font
- * Warning: This field is platform dependent.
+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 foundry; + /** + * The common name of the font + * Warning: This field is platform dependent. */ - public String fontFamily;
- /**
- * The weight ("medium", "bold")
- * Warning: This field is platform dependent.
+ public String fontFamily; + /** + * The weight ("medium", "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 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 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 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 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 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 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 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 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 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 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 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)
+ public String characterSetName; + + /** + * The locales of the font + * (Warning: These fields are platform dependent) */ - String lang, country, variant;
+ String lang, country, variant; /** * Constructs a new un-initialized font data. */ -public FontData () {
-}
+public FontData () { +} /** * Constructs a new FontData given a string representation * in the form generated by the <code>FontData.toString</code> @@ -135,80 +135,80 @@ public FontData () { * * @see #toString */ -public FontData(String string) {
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int start = 0;
- int end = string.indexOf('|');
- if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- String version1 = string.substring(start, end);
- try {
- if (Integer.parseInt(version1) != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- String name = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int height = 0;
- try {
- height = Integer.parseInt(string.substring(start, end));
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int style = 0;
- try {
- style = Integer.parseInt(string.substring(start, end));
- } catch (NumberFormatException e) {
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- }
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) {
- setName(name);
- setHeight(height);
- setStyle(style);
- return;
- }
- String platform = string.substring(start, end);
-
- start = end + 1;
- end = string.indexOf('|', start);
- if (end == -1) {
- setName(name);
- setHeight(height);
- setStyle(style);
- return;
- }
- String version2 = string.substring(start, end);
-
- if (platform.equals("MOTIF") && version2.equals("1")) {
- start = end + 1;
- end = string.length();
- if (end == -1) {
- setName(name);
- setHeight(height);
- setStyle(style);
- return;
- }
- String xlfd = string.substring(start, end);
- setXlfd(xlfd);
- return;
- }
- setName(name);
- setHeight(height);
- setStyle(style);
-}
+public FontData(String string) { + if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + int start = 0; + int end = string.indexOf('|'); + if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT); + String version1 = string.substring(start, end); + try { + if (Integer.parseInt(version1) != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } catch (NumberFormatException e) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + + start = end + 1; + end = string.indexOf('|', start); + if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT); + String name = string.substring(start, end); + + start = end + 1; + end = string.indexOf('|', start); + if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT); + int height = 0; + try { + height = Integer.parseInt(string.substring(start, end)); + } catch (NumberFormatException e) { + SWT.error(SWT.ERROR_NULL_ARGUMENT); + } + + start = end + 1; + end = string.indexOf('|', start); + if (end == -1) SWT.error(SWT.ERROR_NULL_ARGUMENT); + int style = 0; + try { + style = Integer.parseInt(string.substring(start, end)); + } catch (NumberFormatException e) { + SWT.error(SWT.ERROR_NULL_ARGUMENT); + } + + start = end + 1; + end = string.indexOf('|', start); + if (end == -1) { + setName(name); + setHeight(height); + setStyle(style); + return; + } + String platform = string.substring(start, end); + + start = end + 1; + end = string.indexOf('|', start); + if (end == -1) { + setName(name); + setHeight(height); + setStyle(style); + return; + } + String version2 = string.substring(start, end); + + if (platform.equals("MOTIF") && version2.equals("1")) { + start = end + 1; + end = string.length(); + if (end == -1) { + setName(name); + setHeight(height); + setStyle(style); + return; + } + String xlfd = string.substring(start, end); + setXlfd(xlfd); + return; + } + setName(name); + setHeight(height); + setStyle(style); +} /** * Constructs a new font data given a font name, * the height of the desired font in points, @@ -223,20 +223,20 @@ public FontData(String string) { * <li>ERROR_INVALID_ARGUMENT - if the height is negative</li> * </ul> */ -public FontData (String name, int height, int style) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int dash = name.indexOf('-');
- if (dash != -1) {
- foundry = name.substring(0, dash);
- fontFamily = name.substring(dash + 1);
- } else {
- fontFamily = name;
- }
- points = height * 10;
- weight = (style & SWT.BOLD) != 0 ? "bold" : "medium";
- slant = (style & SWT.ITALIC) != 0 ? "i" : "r";
-}
+public FontData (String name, int height, int style) { + if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + int dash = name.indexOf('-'); + if (dash != -1) { + foundry = name.substring(0, dash); + fontFamily = name.substring(dash + 1); + } else { + fontFamily = name; + } + points = height * 10; + weight = (style & SWT.BOLD) != 0 ? "bold" : "medium"; + slant = (style & SWT.ITALIC) != 0 ? "i" : "r"; +} /** * Compares the argument to the receiver, and returns true * if they represent the <em>same</em> object using a class @@ -247,10 +247,10 @@ public FontData (String name, int height, int style) { * * @see #hashCode */ -public boolean equals (Object object) {
- return (object == this) || ((object instanceof FontData) &&
- getXlfd().equals(((FontData)object).getXlfd()));
-}
+public boolean equals (Object object) { + return (object == this) || ((object instanceof FontData) && + getXlfd().equals(((FontData)object).getXlfd())); +} /** * Returns the height of the receiver in points. * @@ -258,9 +258,9 @@ public boolean equals (Object object) { * * @see #setHeight */ -public int getHeight() {
- return points / 10;
-}
+public int getHeight() { + return points / 10; +} /** * Returns the name of the receiver. * On platforms that support font foundries, the return value will @@ -270,15 +270,15 @@ public int getHeight() { * * @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();
-}
+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 @@ -288,34 +288,34 @@ public String getName() { * * @see #setStyle */ -public int getStyle() {
- int style = 0;
- if (weight != null && weight.equals("bold")) style |= SWT.BOLD;
- if (slant != null && slant.equals("i")) style |= SWT.ITALIC;
- return style;
-}
-String getXlfd() {
- String s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14;
- s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = s9 = s10 = s11 = s12 = s13 = s14 = "*";
-
- if (foundry != null) s1 = foundry;
- if (fontFamily != null) s2 = fontFamily;
- if (weight != null) s3 = weight;
- if (slant != null) s4 = slant;
- if (setWidth != null) s5 = setWidth;
- if (addStyle != null) s6 = addStyle;
- if (pixels != 0) s7 = Integer.toString(pixels);
- if (points != 0) s8 = Integer.toString(points);
- if (horizontalResolution != 0) s9 = Integer.toString(horizontalResolution);
- if (verticalResolution != 0) s10 = Integer.toString(verticalResolution);
- if (spacing != null) s11 = spacing;
- if (averageWidth != 0) s12 = Integer.toString(averageWidth);
- if (characterSetRegistry != null) s13 = characterSetRegistry;
- if (characterSetName != null) s14 = characterSetName;
-
- return "-" + s1+ "-" + s2 + "-" + s3 + "-" + s4 + "-" + s5 + "-" + s6 + "-" + s7 + "-" + s8 + "-"
- + s9 + "-" + s10 + "-" + s11 + "-" + s12 + "-" + s13 + "-" + s14;
-}
+public int getStyle() { + int style = 0; + if (weight != null && weight.equals("bold")) style |= SWT.BOLD; + if (slant != null && slant.equals("i")) style |= SWT.ITALIC; + return style; +} +String getXlfd() { + String s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14; + s1 = s2 = s3 = s4 = s5 = s6 = s7 = s8 = s9 = s10 = s11 = s12 = s13 = s14 = "*"; + + if (foundry != null) s1 = foundry; + if (fontFamily != null) s2 = fontFamily; + if (weight != null) s3 = weight; + if (slant != null) s4 = slant; + if (setWidth != null) s5 = setWidth; + if (addStyle != null) s6 = addStyle; + if (pixels != 0) s7 = Integer.toString(pixels); + if (points != 0) s8 = Integer.toString(points); + if (horizontalResolution != 0) s9 = Integer.toString(horizontalResolution); + if (verticalResolution != 0) s10 = Integer.toString(verticalResolution); + if (spacing != null) s11 = spacing; + if (averageWidth != 0) s12 = Integer.toString(averageWidth); + if (characterSetRegistry != null) s13 = characterSetRegistry; + if (characterSetName != null) s14 = characterSetName; + + return "-" + s1+ "-" + s2 + "-" + s3 + "-" + s4 + "-" + s5 + "-" + s6 + "-" + s7 + "-" + s8 + "-" + + s9 + "-" + s10 + "-" + s11 + "-" + s12 + "-" + s13 + "-" + s14; +} /** * Returns an integer hash code for the receiver. Any two * objects which return <code>true</code> when passed to @@ -326,14 +326,14 @@ String getXlfd() { * * @see #equals */ -public int hashCode () {
- return getXlfd().hashCode();
-}
-public static FontData motif_new(String xlfd) {
- FontData fontData = new FontData();
- fontData.setXlfd(xlfd);
- return fontData;
-}
+public int hashCode () { + return getXlfd().hashCode(); +} +public static FontData motif_new(String xlfd) { + FontData fontData = new FontData(); + fontData.setXlfd(xlfd); + return fontData; +} /** * Sets the height of the receiver. The parameter is * specified in terms of points, where a point is one @@ -347,10 +347,10 @@ public static FontData motif_new(String xlfd) { * * @see #getHeight */ -public void setHeight(int height) {
- if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- points = height * 10;
-}
+public void setHeight(int height) { + if (height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + points = height * 10; +} /** * Sets the name of the receiver. * <p> @@ -376,52 +376,52 @@ public void setHeight(int height) { * * @see #getName */ -public void setName(String name) {
- if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int dash = name.indexOf('-');
- if (dash != -1) {
- foundry = name.substring(0, dash);
- fontFamily = name.substring(dash + 1);
- } else {
- fontFamily = name;
- }
-}
-/**
- * Sets the locale of the receiver.
- * <p>
- * The locale determines which platform character set this
- * font is going to use. Widgets and graphics operations that
- * use this font will convert UNICODE strings to the platform
- * character set of the specified locale.
- * </p>
- * <p>
- * On platforms 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 setName(String name) { + if (name == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + int dash = name.indexOf('-'); + if (dash != -1) { + foundry = name.substring(0, dash); + fontFamily = name.substring(dash + 1); + } else { + fontFamily = name; + } +} +/** + * Sets the locale of the receiver. + * <p> + * The locale determines which platform character set this + * font is going to use. Widgets and graphics operations that + * use this font will convert UNICODE strings to the platform + * character set of the specified locale. + * </p> + * <p> + * On platforms 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);
- }
-}
+public void setLocale(String locale) { + lang = country = variant = null; + if (locale != null) { + char sep = '_'; + int length = locale.length(); + int firstSep, secondSep; + + firstSep = locale.indexOf(sep); + if (firstSep == -1) { + firstSep = secondSep = length; + } else { + secondSep = locale.indexOf(sep, firstSep + 1); + if (secondSep == -1) secondSep = length; + } + if (firstSep > 0) lang = locale.substring(0, firstSep); + if (secondSep > firstSep + 1) country = locale.substring(firstSep + 1, secondSep); + if (length > secondSep + 1) variant = locale.substring(secondSep + 1); + } +} /** * Sets the style of the receiver to the argument which must * be a bitwise OR of one or more of the <code>SWT</code> @@ -431,74 +431,74 @@ public void setLocale(String locale) { * * @see #getStyle */ -public void setStyle(int style) {
- weight = (style & SWT.BOLD) != 0 ? "bold" : "medium";
- slant = (style & SWT.ITALIC) != 0 ? "i" : "r";
- averageWidth = 0;
-}
-void setXlfd(String xlfd) {
- int start, stop;
- start = 1;
- stop = xlfd.indexOf ("-", start);
- foundry = xlfd.substring(start, stop);
- if (foundry.equals("*")) foundry = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- fontFamily = xlfd.substring(start, stop);
- if (fontFamily.equals("*")) fontFamily = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- weight = xlfd.substring(start, stop);
- if (weight.equals("*")) weight = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- slant = xlfd.substring(start, stop);
- if (slant.equals("*")) slant = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- setWidth = xlfd.substring(start, stop);
- if (setWidth.equals("*")) setWidth = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- addStyle = xlfd.substring(start, stop);
- if (addStyle.equals("*")) addStyle = null;
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- String s = xlfd.substring(start, stop);
- if (!s.equals("") && !s.equals("*"))
- pixels = Integer.parseInt(s);
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- s = xlfd.substring(start, stop);
- if (!s.equals("") && !s.equals("*"))
- points = Integer.parseInt(s);
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- s = xlfd.substring(start, stop);
- if (!s.equals("") && !s.equals("*"))
- horizontalResolution = Integer.parseInt(s);
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- s = xlfd.substring(start, stop);
- if (!s.equals("") && !s.equals("*"))
- verticalResolution = Integer.parseInt(s);
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- spacing = xlfd.substring(start, stop);
- start = stop + 1;
- stop = xlfd.indexOf ("-", start);
- s = xlfd.substring(start, stop);
- if (!s.equals("") && !s.equals("*"))
- 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;
-}
+public void setStyle(int style) { + weight = (style & SWT.BOLD) != 0 ? "bold" : "medium"; + slant = (style & SWT.ITALIC) != 0 ? "i" : "r"; + averageWidth = 0; +} +void setXlfd(String xlfd) { + int start, stop; + start = 1; + stop = xlfd.indexOf ("-", start); + foundry = xlfd.substring(start, stop); + if (foundry.equals("*")) foundry = null; + start = stop + 1; + stop = xlfd.indexOf ("-", start); + fontFamily = xlfd.substring(start, stop); + if (fontFamily.equals("*")) fontFamily = null; + start = stop + 1; + stop = xlfd.indexOf ("-", start); + weight = xlfd.substring(start, stop); + if (weight.equals("*")) weight = null; + start = stop + 1; + stop = xlfd.indexOf ("-", start); + slant = xlfd.substring(start, stop); + if (slant.equals("*")) slant = null; + start = stop + 1; + stop = xlfd.indexOf ("-", start); + setWidth = xlfd.substring(start, stop); + if (setWidth.equals("*")) setWidth = null; + start = stop + 1; + stop = xlfd.indexOf ("-", start); + addStyle = xlfd.substring(start, stop); + if (addStyle.equals("*")) addStyle = null; + start = stop + 1; + stop = xlfd.indexOf ("-", start); + String s = xlfd.substring(start, stop); + if (!s.equals("") && !s.equals("*")) + pixels = Integer.parseInt(s); + start = stop + 1; + stop = xlfd.indexOf ("-", start); + s = xlfd.substring(start, stop); + if (!s.equals("") && !s.equals("*")) + points = Integer.parseInt(s); + start = stop + 1; + stop = xlfd.indexOf ("-", start); + s = xlfd.substring(start, stop); + if (!s.equals("") && !s.equals("*")) + horizontalResolution = Integer.parseInt(s); + start = stop + 1; + stop = xlfd.indexOf ("-", start); + s = xlfd.substring(start, stop); + if (!s.equals("") && !s.equals("*")) + verticalResolution = Integer.parseInt(s); + start = stop + 1; + stop = xlfd.indexOf ("-", start); + spacing = xlfd.substring(start, stop); + start = stop + 1; + stop = xlfd.indexOf ("-", start); + s = xlfd.substring(start, stop); + if (!s.equals("") && !s.equals("*")) + 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 @@ -508,8 +508,8 @@ void setXlfd(String xlfd) { * * @see FontData */ -public String toString() {
- return "1|" + fontFamily + "|" + getHeight() + "|" + getStyle() + "|" +
- "MOTIF|1|" + getXlfd();
-}
-}
+public String toString() { + return "1|" + fontFamily + "|" + getHeight() + "|" + getStyle() + "|" + + "MOTIF|1|" + getXlfd(); +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontMetrics.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontMetrics.java index 8deaa41af6..2a04827982 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontMetrics.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/FontMetrics.java @@ -1,25 +1,25 @@ -package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-/**
- * 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
+ * http://www.eclipse.org/legal/cpl-v10.html */ -public final class FontMetrics {
- int ascent, descent, averageCharWidth, leading, height;
-FontMetrics() {
-}
+ +/** + * 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 @@ -30,14 +30,14 @@ FontMetrics() { * * @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;
-}
+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 @@ -46,18 +46,18 @@ public boolean equals (Object object) { * * @return the ascent of the font */ -public int getAscent() {
- return ascent;
-}
+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;
-}
+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 @@ -66,9 +66,9 @@ public int getAverageCharWidth() { * * @return the descent of the font */ -public int getDescent() {
- return descent;
-}
+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 @@ -80,9 +80,9 @@ public int getDescent() { * @see #getDescent * @see #getLeading */ -public int getHeight() {
- return height;
-}
+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 @@ -90,9 +90,9 @@ public int getHeight() { * * @return the leading space of the font */ -public int getLeading() {
- return leading;
-}
+public int getLeading() { + return leading; +} /** * Returns an integer hash code for the receiver. Any two * objects which return <code>true</code> when passed to @@ -103,16 +103,16 @@ public int getLeading() { * * @see #equals */ -public int hashCode() {
- return ascent ^ descent ^ averageCharWidth ^ leading ^ height;
-}
-public static FontMetrics motif_new(int ascent, int descent, int averageCharWidth, int leading, int height) {
- FontMetrics fontMetrics = new FontMetrics();
- fontMetrics.ascent = ascent;
- fontMetrics.descent = descent;
- fontMetrics.averageCharWidth = averageCharWidth;
- fontMetrics.leading = leading;
- fontMetrics.height = height;
- return fontMetrics;
-}
-}
+public int hashCode() { + return ascent ^ descent ^ averageCharWidth ^ leading ^ height; +} +public static FontMetrics motif_new(int ascent, int descent, int averageCharWidth, int leading, int height) { + FontMetrics fontMetrics = new FontMetrics(); + fontMetrics.ascent = ascent; + fontMetrics.descent = descent; + fontMetrics.averageCharWidth = averageCharWidth; + fontMetrics.leading = leading; + fontMetrics.height = height; + return fontMetrics; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java index 7e604386c8..d09e66a986 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GC.java @@ -1,16 +1,16 @@ -package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; + /** * Class <code>GC</code> is where all of the drawing capabilities that are * supported by SWT are located. Instances are used to draw on either an @@ -25,18 +25,18 @@ import org.eclipse.swt.*; * * @see org.eclipse.swt.events.PaintEvent */ -public final class GC {
+public final class GC { /** * the handle to the OS device context * (Warning: This field is platform dependent) */ - public int handle;
-
- Drawable drawable;
- GCData data;
-
-GC() {
-}
+ public int handle; + + Drawable drawable; + GCData data; + +GC() { +} /** * Constructs a new instance of this class which has been * configured to draw on the specified drawable. Sets the @@ -58,18 +58,18 @@ GC() { * <li>ERROR_NO_HANDLES if a handle could not be obtained for gc creation</li> * </ul> */ -public GC (Drawable drawable) {
- if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- GCData data = new GCData();
- int xGC = drawable.internal_new_GC(data);
- Device device = data.device;
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- data.device = device;
- init(drawable, data, xGC);
- if (device.tracking) device.new_Object(this);
-}
-
+public GC (Drawable drawable) { + if (drawable == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + GCData data = new GCData(); + int xGC = drawable.internal_new_GC(data); + Device device = data.device; + if (device == null) device = Device.getDevice(); + if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + data.device = device; + init(drawable, data, xGC); + if (device.tracking) device.new_Object(this); +} + /** * Copies a rectangular area of the receiver at the source * position onto the receiver at the destination position. @@ -85,33 +85,33 @@ public GC (Drawable drawable) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void copyArea(int x, int y, int width, int height, int destX, int destY) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width <= 0 || height <= 0) return;
- int deltaX = destX - x, deltaY = destY - y;
- if (deltaX == 0 && deltaY == 0) return;
- int xDisplay = data.display;
- int xDrawable = data.drawable;
- OS.XSetGraphicsExposures (xDisplay, handle, true);
- OS.XCopyArea(xDisplay, xDrawable, xDrawable, handle, x, y, width, height, destX, destY);
- OS.XSetGraphicsExposures (xDisplay, handle, false);
- if (data.image != null) return;
- boolean disjoint = (destX + width < x) || (x + width < destX) || (destY + height < y) || (y + height < destY);
- if (disjoint) {
- OS.XClearArea (xDisplay, xDrawable, x, y, width, height, true);
- } else {
- if (deltaX != 0) {
- int newX = destX - deltaX;
- if (deltaX < 0) newX = destX + width;
- OS.XClearArea (xDisplay, xDrawable, newX, y, Math.abs (deltaX), height, true);
- }
- if (deltaY != 0) {
- int newY = destY - deltaY;
- if (deltaY < 0) newY = destY + height;
- OS.XClearArea (xDisplay, xDrawable, x, newY, width, Math.abs (deltaY), true);
- }
- }
-}
+public void copyArea(int x, int y, int width, int height, int destX, int destY) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (width <= 0 || height <= 0) return; + int deltaX = destX - x, deltaY = destY - y; + if (deltaX == 0 && deltaY == 0) return; + int xDisplay = data.display; + int xDrawable = data.drawable; + OS.XSetGraphicsExposures (xDisplay, handle, true); + OS.XCopyArea(xDisplay, xDrawable, xDrawable, handle, x, y, width, height, destX, destY); + OS.XSetGraphicsExposures (xDisplay, handle, false); + if (data.image != null) return; + boolean disjoint = (destX + width < x) || (x + width < destX) || (destY + height < y) || (y + height < destY); + if (disjoint) { + OS.XClearArea (xDisplay, xDrawable, x, y, width, height, true); + } else { + if (deltaX != 0) { + int newX = destX - deltaX; + if (deltaX < 0) newX = destX + width; + OS.XClearArea (xDisplay, xDrawable, newX, y, Math.abs (deltaX), height, true); + } + if (deltaY != 0) { + int newY = destY - deltaY; + if (deltaY < 0) newY = destY + height; + OS.XClearArea (xDisplay, xDrawable, x, newY, width, Math.abs (deltaY), true); + } + } +} /** * Copies a rectangular area of the receiver at the specified * position into the image, which must be of type <code>SWT.BITMAP</code>. @@ -127,53 +127,53 @@ public void copyArea(int x, int y, int width, int height, int destX, int destY) * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void copyArea(Image image, int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- Rectangle rect = image.getBounds();
- int xDisplay = data.display;
- int xGC = OS.XCreateGC(xDisplay, image.pixmap, 0, null);
- if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.XSetSubwindowMode (xDisplay, xGC, OS.IncludeInferiors);
- OS.XCopyArea(xDisplay, data.drawable, image.pixmap, xGC, x, y, rect.width, rect.height, 0, 0);
- OS.XFreeGC(xDisplay, xGC);
-}
+public void copyArea(Image image, int x, int y) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (image.type != SWT.BITMAP || image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + Rectangle rect = image.getBounds(); + int xDisplay = data.display; + int xGC = OS.XCreateGC(xDisplay, image.pixmap, 0, null); + if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES); + OS.XSetSubwindowMode (xDisplay, xGC, OS.IncludeInferiors); + OS.XCopyArea(xDisplay, data.drawable, image.pixmap, xGC, x, y, rect.width, rect.height, 0, 0); + OS.XFreeGC(xDisplay, xGC); +} /** * Disposes of the operating system resources associated with * the graphics context. Applications must dispose of all GCs * which they allocate. */ -public void dispose () {
+public void dispose () { if (handle == 0) return; - if (data.device.isDisposed()) return;
-
- /* Free resources */
- int clipRgn = data.clipRgn;
- if (clipRgn != 0) OS.XDestroyRegion(clipRgn);
- Image image = data.image;
- if (image != null) {
- image.memGC = null;
- if (image.transparentPixel != -1) image.createMask();
- }
-
- int renderTable = data.renderTable;
- if (renderTable != 0) OS.XmRenderTableFree(renderTable);
-
- /* Dispose the GC */
- Device device = data.device;
- drawable.internal_dispose_GC(handle, data);
-
- data.display = data.drawable = data.colormap = data.fontList =
- data.clipRgn = data.renderTable = 0;
- drawable = null;
- handle = 0;
- data.image = null;
- data.codePage = null;
- if (device.tracking) device.dispose_Object(this);
- data.device = null;
- data = null;
-}
+ if (data.device.isDisposed()) return; + + /* Free resources */ + int clipRgn = data.clipRgn; + if (clipRgn != 0) OS.XDestroyRegion(clipRgn); + Image image = data.image; + if (image != null) { + image.memGC = null; + if (image.transparentPixel != -1) image.createMask(); + } + + int renderTable = data.renderTable; + if (renderTable != 0) OS.XmRenderTableFree(renderTable); + + /* Dispose the GC */ + Device device = data.device; + drawable.internal_dispose_GC(handle, data); + + data.display = data.drawable = data.colormap = data.fontList = + data.clipRgn = data.renderTable = 0; + drawable = null; + handle = 0; + data.image = null; + data.codePage = null; + if (device.tracking) device.dispose_Object(this); + data.device = null; + data = null; +} /** * Draws the outline of a circular or elliptical arc * within the specified rectangular area. @@ -206,21 +206,21 @@ public void dispose () { * <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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || endAngle == 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- OS.XDrawArc(data.display,data.drawable,handle,x,y,width,height,startAngle * 64 ,endAngle * 64);
-}
+public void drawArc(int x, int y, int width, int height, int startAngle, int endAngle) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (width < 0) { + x = x + width; + width = -width; + } + if (height < 0) { + y = y + height; + height = -height; + } + if (width == 0 || height == 0 || endAngle == 0) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + OS.XDrawArc(data.display,data.drawable,handle,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 @@ -238,37 +238,37 @@ public void drawArc(int x, int y, int width, int height, int startAngle, int end * * @see #drawRectangle */ -public void drawFocus (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- /*
- * When the drawable is not a widget, the highlight
- * color is zero.
- */
- int xDisplay = data.display;
- int xDrawable = data.drawable;
- int highlightColor = 0;
- int widget = OS.XtWindowToWidget (xDisplay, xDrawable);
- if (widget != 0) {
- int [] argList = {OS.XmNhighlightColor, 0};
- OS.XtGetValues (widget, argList, argList.length / 2);
- highlightColor = argList [1];
- }
-
- /* Draw the focus rectangle */
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- XGCValues values = new XGCValues ();
- OS.XGetGCValues (xDisplay, handle, OS.GCForeground, values);
- OS.XSetForeground (xDisplay, handle, highlightColor);
- OS.XDrawRectangle (xDisplay, xDrawable, handle, x, y, width - 1, height - 1);
- OS.XSetForeground (xDisplay, handle, values.foreground);
-}
+public void drawFocus (int x, int y, int width, int height) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + /* + * When the drawable is not a widget, the highlight + * color is zero. + */ + int xDisplay = data.display; + int xDrawable = data.drawable; + int highlightColor = 0; + int widget = OS.XtWindowToWidget (xDisplay, xDrawable); + if (widget != 0) { + int [] argList = {OS.XmNhighlightColor, 0}; + OS.XtGetValues (widget, argList, argList.length / 2); + highlightColor = argList [1]; + } + + /* Draw the focus rectangle */ + if (width < 0) { + x = x + width; + width = -width; + } + if (height < 0) { + y = y + height; + height = -height; + } + XGCValues values = new XGCValues (); + OS.XGetGCValues (xDisplay, handle, OS.GCForeground, values); + OS.XSetForeground (xDisplay, handle, highlightColor); + OS.XDrawRectangle (xDisplay, xDrawable, handle, x, y, width - 1, height - 1); + OS.XSetForeground (xDisplay, handle, values.foreground); +} /** * Draws the given image in the receiver at the specified * coordinates. @@ -288,329 +288,329 @@ public void drawFocus (int x, int y, int width, int height) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void drawImage(Image image, int x, int y) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- drawImage(image, 0, 0, -1, -1, x, y, -1, -1, true);
-}
-
-/**
- * Copies a rectangular area from the source image into a (potentially
- * different sized) rectangular area in the receiver. If the source
- * and destination areas are of differing sizes, then the source
- * area will be stretched or shrunk to fit the destination area
- * as it is copied. The copy fails if any part of the source rectangle
- * lies outside the bounds of the source image, or if any of the width
- * or height arguments are negative.
- *
- * @param image the source image
- * @param srcX the x coordinate in the source image to copy from
- * @param srcY the y coordinate in the source image to copy from
- * @param srcWidth the width in pixels to copy from the source
- * @param srcHeight the height in pixels to copy from the source
- * @param destX the x coordinate in the destination to copy to
- * @param destY the y coordinate in the destination to copy to
- * @param destWidth the width in pixels of the destination rectangle
- * @param destHeight the height in pixels of the destination rectangle
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the image is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * <li>ERROR_INVALID_ARGUMENT - if any of the width or height arguments are negative.
- * <li>ERROR_INVALID_ARGUMENT - if the source rectangle is not contained within the bounds of the source image</li>
- * </ul>
- * @exception 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 (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + drawImage(image, 0, 0, -1, -1, x, y, -1, -1, true); +} + +/** + * Copies a rectangular area from the source image into a (potentially + * different sized) rectangular area in the receiver. If the source + * and destination areas are of differing sizes, then the source + * area will be stretched or shrunk to fit the destination area + * as it is copied. The copy fails if any part of the source rectangle + * lies outside the bounds of the source image, or if any of the width + * or height arguments are negative. + * + * @param image the source image + * @param srcX the x coordinate in the source image to copy from + * @param srcY the y coordinate in the source image to copy from + * @param srcWidth the width in pixels to copy from the source + * @param srcHeight the height in pixels to copy from the source + * @param destX the x coordinate in the destination to copy to + * @param destY the y coordinate in the destination to copy to + * @param destWidth the width in pixels of the destination rectangle + * @param destHeight the height in pixels of the destination rectangle + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the image is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> + * <li>ERROR_INVALID_ARGUMENT - if any of the width or height arguments are negative. + * <li>ERROR_INVALID_ARGUMENT - if the source rectangle is not contained within the bounds of the source image</li> + * </ul> + * @exception 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 srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (srcWidth == 0 || srcHeight == 0 || destWidth == 0 || destHeight == 0) return;
- if (srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 || destWidth < 0 || destHeight < 0) {
- SWT.error (SWT.ERROR_INVALID_ARGUMENT);
- }
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- drawImage(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false);
-}
-void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) {
- int[] width = new int[1];
- int[] height = new int[1];
- int[] depth = new int[1];
- int[] unused = new int[1];
- OS.XGetGeometry(data.display, srcImage.pixmap, unused, unused, unused, width, height, unused, depth);
- int imgWidth = width[0];
- int imgHeight = height[0];
- if (simple) {
- srcWidth = destWidth = imgWidth;
- srcHeight = destHeight = imgHeight;
- } else {
- simple = srcX == 0 && srcY == 0 &&
- srcWidth == destWidth && destWidth == imgWidth &&
- srcHeight == destHeight && destHeight == imgHeight;
- if (srcX + srcWidth > imgWidth || srcY + srcHeight > imgHeight) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- }
- if (srcImage.alpha != -1 || srcImage.alphaData != null) {
- drawImageAlpha(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth[0]);
- } else if (srcImage.transparentPixel != -1 || srcImage.mask != 0) {
- drawImageMask(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth[0]);
- } else {
- drawImage(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth[0]);
- }
-}
-void drawImageAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int depth) {
- /* Simple cases */
- if (srcImage.alpha == 0) return;
- if (srcImage.alpha == 255) {
- drawImage(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth);
- return;
- }
-
- /* Check the clipping */
- Rectangle rect = getClipping();
- rect = rect.intersection(new Rectangle(destX, destY, destWidth, destHeight));
- if (rect.isEmpty()) return;
-
- /* Optimization. Recalculate the src and dest rectangles so that
- * only the clipping area is drawn.
- */
- int sx1 = srcX + (((rect.x - destX) * srcWidth) / destWidth);
- int sx2 = srcX + ((((rect.x + rect.width) - destX) * srcWidth) / destWidth);
- int sy1 = srcY + (((rect.y - destY) * srcHeight) / destHeight);
- int sy2 = srcY + ((((rect.y + rect.height) - destY) * srcHeight) / destHeight);
- destX = rect.x;
- destY = rect.y;
- destWidth = rect.width;
- destHeight = rect.height;
- srcX = sx1;
- srcY = sy1;
- srcWidth = Math.max(1, sx2 - sx1);
- srcHeight = Math.max(1, sy2 - sy1);
-
- int xDisplay = data.display;
- int xDrawable = data.drawable;
- int xDestImagePtr = 0, xSrcImagePtr = 0;
- try {
- /* Get the background pixels */
- xDestImagePtr = OS.XGetImage(xDisplay, xDrawable, destX, destY, destWidth, destHeight, OS.AllPlanes, OS.ZPixmap);
- if (xDestImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- XImage xDestImage = new XImage();
- OS.memmove(xDestImage, xDestImagePtr, XImage.sizeof);
- byte[] destData = new byte[xDestImage.bytes_per_line * xDestImage.height];
- OS.memmove(destData, xDestImage.data, destData.length);
-
- /* Get the foreground pixels */
- xSrcImagePtr = OS.XGetImage(xDisplay, srcImage.pixmap, srcX, srcY, srcWidth, srcHeight, OS.AllPlanes, OS.ZPixmap);
- if (xSrcImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- XImage xSrcImage = new XImage();
- OS.memmove(xSrcImage, xSrcImagePtr, XImage.sizeof);
- byte[] srcData = new byte[xSrcImage.bytes_per_line * xSrcImage.height];
- OS.memmove(srcData, xSrcImage.data, srcData.length);
-
- /* Compose the pixels */
- if (xSrcImage.depth <= 8) {
- XColor[] xcolors = data.device.xcolors;
- if (xcolors == null) SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- byte[] reds = new byte[xcolors.length];
- byte[] greens = new byte[xcolors.length];
- byte[] blues = new byte[xcolors.length];
- for (int i = 0; i < xcolors.length; i++) {
- XColor color = xcolors[i];
- if (color == null) continue;
- reds[i] = (byte)((color.red >> 8) & 0xFF);
- greens[i] = (byte)((color.green >> 8) & 0xFF);
- blues[i] = (byte)((color.blue >> 8) & 0xFF);
- }
- ImageData.blit(ImageData.BLIT_ALPHA,
- srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, xSrcImage.byte_order, 0, 0, srcWidth, srcHeight, reds, greens, blues,
- srcImage.alpha, srcImage.alphaData, imgWidth, srcX, srcY,
- destData, xDestImage.bits_per_pixel, xDestImage.bytes_per_line, xDestImage.byte_order, 0, 0, destWidth, destHeight, reds, greens, blues,
- false, false);
- } else {
- int srcRedMask = xSrcImage.red_mask;
- int srcGreenMask = xSrcImage.green_mask;
- int srcBlueMask = xSrcImage.blue_mask;
- int destRedMask = xDestImage.red_mask;
- int destGreenMask = xDestImage.green_mask;
- int destBlueMask = xDestImage.blue_mask;
-
- /*
- * Feature in X. XGetImage does not retrieve the RGB masks if the drawable
- * is a Pixmap. The fix is to detect that the masks are not valid and use
- * the default visual masks instead.
- *
- * NOTE: It is safe to use the default Visual masks, since we always
- * create images with these masks.
- */
- int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay));
- Visual xVisual = new Visual();
- OS.memmove(xVisual, visual, Visual.sizeof);
- if (srcRedMask == 0 && srcGreenMask == 0 && srcBlueMask == 0) {
- srcRedMask = xVisual.red_mask;
- srcGreenMask = xVisual.green_mask;
- srcBlueMask = xVisual.blue_mask;
- }
- if (destRedMask == 0 && destGreenMask == 0 && destBlueMask == 0) {
- destRedMask = xVisual.red_mask;
- destGreenMask = xVisual.green_mask;
- destBlueMask = xVisual.blue_mask;
- }
-
- ImageData.blit(ImageData.BLIT_ALPHA,
- srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, xSrcImage.byte_order, 0, 0, srcWidth, srcHeight, srcRedMask, srcGreenMask, srcBlueMask,
- srcImage.alpha, srcImage.alphaData, imgWidth, srcX, srcY,
- destData, xDestImage.bits_per_pixel, xDestImage.bytes_per_line, xDestImage.byte_order, 0, 0, destWidth, destHeight, destRedMask, destGreenMask, destBlueMask,
- false, false);
- }
-
- /* Draw the composed pixels */
- OS.memmove(xDestImage.data, destData, destData.length);
- OS.XPutImage(xDisplay, xDrawable, handle, xDestImagePtr, 0, 0, destX, destY, destWidth, destHeight);
- } finally {
- if (xSrcImagePtr != 0) OS.XDestroyImage(xSrcImagePtr);
- if (xDestImagePtr != 0) OS.XDestroyImage(xDestImagePtr);
- }
-}
-void drawImageMask(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int depth) {
- int xDisplay = data.display;
- int xDrawable = data.drawable;
- int colorPixmap = srcImage.pixmap;
- /* Generate the mask if necessary. */
- if (srcImage.transparentPixel != -1) srcImage.createMask();
- int maskPixmap = srcImage.mask;
- int foreground = 0x00000000;
- if (!(simple || (srcWidth == destWidth && srcHeight == destHeight))) {
- /* Stretch the color and mask*/
- int xImagePtr = scalePixmap(xDisplay, colorPixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false);
- int xMaskPtr = scalePixmap(xDisplay, maskPixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false);
-
- /* Create color scaled pixmaps */
- colorPixmap = OS.XCreatePixmap(xDisplay, xDrawable, destWidth, destHeight, depth);
- int tempGC = OS.XCreateGC(xDisplay, colorPixmap, 0, null);
- OS.XPutImage(xDisplay, colorPixmap, tempGC, xImagePtr, 0, 0, 0, 0, destWidth, destHeight);
- OS.XDestroyImage(xImagePtr);
- OS.XFreeGC(xDisplay, tempGC);
-
- /* Create mask scaled pixmaps */
- maskPixmap = OS.XCreatePixmap(xDisplay, xDrawable, destWidth, destHeight, 1);
- tempGC = OS.XCreateGC(xDisplay, maskPixmap, 0, null);
- OS.XPutImage(xDisplay, maskPixmap, tempGC, xMaskPtr, 0, 0, 0, 0, destWidth, destHeight);
- OS.XDestroyImage(xMaskPtr);
- OS.XFreeGC(xDisplay, tempGC);
-
- /* Change the source rectangle */
- srcX = srcY = 0;
- srcWidth = destWidth;
- srcHeight = destHeight;
-
- foreground = ~foreground;
- }
-
- /* Do the blts */
- XGCValues values = new XGCValues();
- OS.XGetGCValues(xDisplay, handle, OS.GCForeground | OS. GCBackground | OS.GCFunction, values);
- OS.XSetFunction(xDisplay, handle, OS.GXxor);
- OS.XCopyArea(xDisplay, colorPixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY);
- OS.XSetForeground(xDisplay, handle, foreground);
- OS.XSetBackground(xDisplay, handle, ~foreground);
- OS.XSetFunction(xDisplay, handle, OS.GXand);
- OS.XCopyPlane(xDisplay, maskPixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY, 1);
- OS.XSetFunction(xDisplay, handle, OS.GXxor);
- OS.XCopyArea(xDisplay, colorPixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY);
- OS.XSetForeground(xDisplay, handle, values.foreground);
- OS.XSetBackground(xDisplay, handle, values.background);
- OS.XSetFunction(xDisplay, handle, values.function);
-
- /* Destroy scaled pixmaps */
- if (srcImage.pixmap != colorPixmap) OS.XFreePixmap(xDisplay, colorPixmap);
- if (srcImage.mask != maskPixmap) OS.XFreePixmap(xDisplay, maskPixmap);
- /* Destroy the image mask if the there is a GC created on the image */
- if (srcImage.transparentPixel != -1 && srcImage.memGC != null) srcImage.destroyMask();
-}
-void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int depth) {
- int xDisplay = data.display;
- int xDrawable = data.drawable;
- /* Simple case: no stretching */
- if ((srcWidth == destWidth) && (srcHeight == destHeight)) {
- OS.XCopyArea(xDisplay, srcImage.pixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY);
- return;
- }
-
- /* Streching case */
- int xImagePtr = scalePixmap(xDisplay, srcImage.pixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false);
- OS.XPutImage(xDisplay, xDrawable, handle, xImagePtr, 0, 0, destX, destY, destWidth, destHeight);
- OS.XDestroyImage(xImagePtr);
-}
-static int scalePixmap(int display, int pixmap, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean flipX, boolean flipY) {
- int xSrcImagePtr = OS.XGetImage(display, pixmap, srcX, srcY, srcWidth, srcHeight, OS.AllPlanes, OS.ZPixmap);
- if (xSrcImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- XImage xSrcImage = new XImage();
- OS.memmove(xSrcImage, xSrcImagePtr, XImage.sizeof);
- byte[] srcData = new byte[xSrcImage.bytes_per_line * xSrcImage.height];
- OS.memmove(srcData, xSrcImage.data, srcData.length);
- int error = 0, xImagePtr = 0;
- int visual = OS.XDefaultVisual(display, OS.XDefaultScreen(display));
- switch (xSrcImage.bits_per_pixel) {
- case 1:
- case 4:
- case 8: {
- int format = xSrcImage.bits_per_pixel == 1 ? OS.XYBitmap : OS.ZPixmap;
- xImagePtr = OS.XCreateImage(display, visual, xSrcImage.depth, format, 0, 0, destWidth, destHeight, xSrcImage.bitmap_pad, 0);
- if (xImagePtr == 0) break;
- XImage xImage = new XImage();
- OS.memmove(xImage, xImagePtr, XImage.sizeof);
- int bufSize = xImage.bytes_per_line * xImage.height;
- int bufPtr = OS.XtMalloc(bufSize);
- xImage.data = bufPtr;
- OS.memmove(xImagePtr, xImage, XImage.sizeof);
- byte[] buf = new byte[bufSize];
- int srcOrder = xSrcImage.bits_per_pixel == 1 ? xSrcImage.bitmap_bit_order : xSrcImage.byte_order;
- int destOrder = xImage.bits_per_pixel == 1 ? xImage.bitmap_bit_order : xImage.byte_order;
- ImageData.blit(ImageData.BLIT_SRC,
- srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, srcOrder, 0, 0, srcWidth, srcHeight, null, null, null,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- buf, xImage.bits_per_pixel, xImage.bytes_per_line, destOrder, 0, 0, destWidth, destHeight, null, null, null,
- flipX, flipY);
- OS.memmove(bufPtr, buf, bufSize);
- break;
- }
- case 16:
- case 24:
- case 32: {
- xImagePtr = OS.XCreateImage(display, visual, xSrcImage.depth, OS.ZPixmap, 0, 0, destWidth, destHeight, xSrcImage.bitmap_pad, 0);
- if (xImagePtr == 0) break;
- XImage xImage = new XImage();
- OS.memmove(xImage, xImagePtr, XImage.sizeof);
- int bufSize = xImage.bytes_per_line * xImage.height;
- int bufPtr = OS.XtMalloc(bufSize);
- xImage.data = bufPtr;
- OS.memmove(xImagePtr, xImage, XImage.sizeof);
- byte[] buf = new byte[bufSize];
- ImageData.blit(ImageData.BLIT_SRC,
- srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, xSrcImage.byte_order, 0, 0, srcWidth, srcHeight, 0, 0, 0,
- ImageData.ALPHA_OPAQUE, null, 0, 0, 0,
- buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, 0, 0, 0,
- flipX, flipY);
- OS.memmove(bufPtr, buf, bufSize);
- break;
- }
- default:
- error = SWT.ERROR_UNSUPPORTED_DEPTH;
- }
- OS.XDestroyImage(xSrcImagePtr);
- if (xImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (error != 0) {
- if (xImagePtr != 0) OS.XDestroyImage(xImagePtr);
- SWT.error(error);
- }
- return xImagePtr;
-}
+public void drawImage(Image image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (srcWidth == 0 || srcHeight == 0 || destWidth == 0 || destHeight == 0) return; + if (srcX < 0 || srcY < 0 || srcWidth < 0 || srcHeight < 0 || destWidth < 0 || destHeight < 0) { + SWT.error (SWT.ERROR_INVALID_ARGUMENT); + } + if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (image.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + drawImage(image, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false); +} +void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple) { + int[] width = new int[1]; + int[] height = new int[1]; + int[] depth = new int[1]; + int[] unused = new int[1]; + OS.XGetGeometry(data.display, srcImage.pixmap, unused, unused, unused, width, height, unused, depth); + int imgWidth = width[0]; + int imgHeight = height[0]; + if (simple) { + srcWidth = destWidth = imgWidth; + srcHeight = destHeight = imgHeight; + } else { + simple = srcX == 0 && srcY == 0 && + srcWidth == destWidth && destWidth == imgWidth && + srcHeight == destHeight && destHeight == imgHeight; + if (srcX + srcWidth > imgWidth || srcY + srcHeight > imgHeight) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + } + if (srcImage.alpha != -1 || srcImage.alphaData != null) { + drawImageAlpha(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth[0]); + } else if (srcImage.transparentPixel != -1 || srcImage.mask != 0) { + drawImageMask(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth[0]); + } else { + drawImage(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth[0]); + } +} +void drawImageAlpha(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int depth) { + /* Simple cases */ + if (srcImage.alpha == 0) return; + if (srcImage.alpha == 255) { + drawImage(srcImage, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, simple, imgWidth, imgHeight, depth); + return; + } + + /* Check the clipping */ + Rectangle rect = getClipping(); + rect = rect.intersection(new Rectangle(destX, destY, destWidth, destHeight)); + if (rect.isEmpty()) return; + + /* Optimization. Recalculate the src and dest rectangles so that + * only the clipping area is drawn. + */ + int sx1 = srcX + (((rect.x - destX) * srcWidth) / destWidth); + int sx2 = srcX + ((((rect.x + rect.width) - destX) * srcWidth) / destWidth); + int sy1 = srcY + (((rect.y - destY) * srcHeight) / destHeight); + int sy2 = srcY + ((((rect.y + rect.height) - destY) * srcHeight) / destHeight); + destX = rect.x; + destY = rect.y; + destWidth = rect.width; + destHeight = rect.height; + srcX = sx1; + srcY = sy1; + srcWidth = Math.max(1, sx2 - sx1); + srcHeight = Math.max(1, sy2 - sy1); + + int xDisplay = data.display; + int xDrawable = data.drawable; + int xDestImagePtr = 0, xSrcImagePtr = 0; + try { + /* Get the background pixels */ + xDestImagePtr = OS.XGetImage(xDisplay, xDrawable, destX, destY, destWidth, destHeight, OS.AllPlanes, OS.ZPixmap); + if (xDestImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES); + XImage xDestImage = new XImage(); + OS.memmove(xDestImage, xDestImagePtr, XImage.sizeof); + byte[] destData = new byte[xDestImage.bytes_per_line * xDestImage.height]; + OS.memmove(destData, xDestImage.data, destData.length); + + /* Get the foreground pixels */ + xSrcImagePtr = OS.XGetImage(xDisplay, srcImage.pixmap, srcX, srcY, srcWidth, srcHeight, OS.AllPlanes, OS.ZPixmap); + if (xSrcImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES); + XImage xSrcImage = new XImage(); + OS.memmove(xSrcImage, xSrcImagePtr, XImage.sizeof); + byte[] srcData = new byte[xSrcImage.bytes_per_line * xSrcImage.height]; + OS.memmove(srcData, xSrcImage.data, srcData.length); + + /* Compose the pixels */ + if (xSrcImage.depth <= 8) { + XColor[] xcolors = data.device.xcolors; + if (xcolors == null) SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH); + byte[] reds = new byte[xcolors.length]; + byte[] greens = new byte[xcolors.length]; + byte[] blues = new byte[xcolors.length]; + for (int i = 0; i < xcolors.length; i++) { + XColor color = xcolors[i]; + if (color == null) continue; + reds[i] = (byte)((color.red >> 8) & 0xFF); + greens[i] = (byte)((color.green >> 8) & 0xFF); + blues[i] = (byte)((color.blue >> 8) & 0xFF); + } + ImageData.blit(ImageData.BLIT_ALPHA, + srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, xSrcImage.byte_order, 0, 0, srcWidth, srcHeight, reds, greens, blues, + srcImage.alpha, srcImage.alphaData, imgWidth, srcX, srcY, + destData, xDestImage.bits_per_pixel, xDestImage.bytes_per_line, xDestImage.byte_order, 0, 0, destWidth, destHeight, reds, greens, blues, + false, false); + } else { + int srcRedMask = xSrcImage.red_mask; + int srcGreenMask = xSrcImage.green_mask; + int srcBlueMask = xSrcImage.blue_mask; + int destRedMask = xDestImage.red_mask; + int destGreenMask = xDestImage.green_mask; + int destBlueMask = xDestImage.blue_mask; + + /* + * Feature in X. XGetImage does not retrieve the RGB masks if the drawable + * is a Pixmap. The fix is to detect that the masks are not valid and use + * the default visual masks instead. + * + * NOTE: It is safe to use the default Visual masks, since we always + * create images with these masks. + */ + int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay)); + Visual xVisual = new Visual(); + OS.memmove(xVisual, visual, Visual.sizeof); + if (srcRedMask == 0 && srcGreenMask == 0 && srcBlueMask == 0) { + srcRedMask = xVisual.red_mask; + srcGreenMask = xVisual.green_mask; + srcBlueMask = xVisual.blue_mask; + } + if (destRedMask == 0 && destGreenMask == 0 && destBlueMask == 0) { + destRedMask = xVisual.red_mask; + destGreenMask = xVisual.green_mask; + destBlueMask = xVisual.blue_mask; + } + + ImageData.blit(ImageData.BLIT_ALPHA, + srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, xSrcImage.byte_order, 0, 0, srcWidth, srcHeight, srcRedMask, srcGreenMask, srcBlueMask, + srcImage.alpha, srcImage.alphaData, imgWidth, srcX, srcY, + destData, xDestImage.bits_per_pixel, xDestImage.bytes_per_line, xDestImage.byte_order, 0, 0, destWidth, destHeight, destRedMask, destGreenMask, destBlueMask, + false, false); + } + + /* Draw the composed pixels */ + OS.memmove(xDestImage.data, destData, destData.length); + OS.XPutImage(xDisplay, xDrawable, handle, xDestImagePtr, 0, 0, destX, destY, destWidth, destHeight); + } finally { + if (xSrcImagePtr != 0) OS.XDestroyImage(xSrcImagePtr); + if (xDestImagePtr != 0) OS.XDestroyImage(xDestImagePtr); + } +} +void drawImageMask(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int depth) { + int xDisplay = data.display; + int xDrawable = data.drawable; + int colorPixmap = srcImage.pixmap; + /* Generate the mask if necessary. */ + if (srcImage.transparentPixel != -1) srcImage.createMask(); + int maskPixmap = srcImage.mask; + int foreground = 0x00000000; + if (!(simple || (srcWidth == destWidth && srcHeight == destHeight))) { + /* Stretch the color and mask*/ + int xImagePtr = scalePixmap(xDisplay, colorPixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false); + int xMaskPtr = scalePixmap(xDisplay, maskPixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false); + + /* Create color scaled pixmaps */ + colorPixmap = OS.XCreatePixmap(xDisplay, xDrawable, destWidth, destHeight, depth); + int tempGC = OS.XCreateGC(xDisplay, colorPixmap, 0, null); + OS.XPutImage(xDisplay, colorPixmap, tempGC, xImagePtr, 0, 0, 0, 0, destWidth, destHeight); + OS.XDestroyImage(xImagePtr); + OS.XFreeGC(xDisplay, tempGC); + + /* Create mask scaled pixmaps */ + maskPixmap = OS.XCreatePixmap(xDisplay, xDrawable, destWidth, destHeight, 1); + tempGC = OS.XCreateGC(xDisplay, maskPixmap, 0, null); + OS.XPutImage(xDisplay, maskPixmap, tempGC, xMaskPtr, 0, 0, 0, 0, destWidth, destHeight); + OS.XDestroyImage(xMaskPtr); + OS.XFreeGC(xDisplay, tempGC); + + /* Change the source rectangle */ + srcX = srcY = 0; + srcWidth = destWidth; + srcHeight = destHeight; + + foreground = ~foreground; + } + + /* Do the blts */ + XGCValues values = new XGCValues(); + OS.XGetGCValues(xDisplay, handle, OS.GCForeground | OS. GCBackground | OS.GCFunction, values); + OS.XSetFunction(xDisplay, handle, OS.GXxor); + OS.XCopyArea(xDisplay, colorPixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY); + OS.XSetForeground(xDisplay, handle, foreground); + OS.XSetBackground(xDisplay, handle, ~foreground); + OS.XSetFunction(xDisplay, handle, OS.GXand); + OS.XCopyPlane(xDisplay, maskPixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY, 1); + OS.XSetFunction(xDisplay, handle, OS.GXxor); + OS.XCopyArea(xDisplay, colorPixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY); + OS.XSetForeground(xDisplay, handle, values.foreground); + OS.XSetBackground(xDisplay, handle, values.background); + OS.XSetFunction(xDisplay, handle, values.function); + + /* Destroy scaled pixmaps */ + if (srcImage.pixmap != colorPixmap) OS.XFreePixmap(xDisplay, colorPixmap); + if (srcImage.mask != maskPixmap) OS.XFreePixmap(xDisplay, maskPixmap); + /* Destroy the image mask if the there is a GC created on the image */ + if (srcImage.transparentPixel != -1 && srcImage.memGC != null) srcImage.destroyMask(); +} +void drawImage(Image srcImage, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean simple, int imgWidth, int imgHeight, int depth) { + int xDisplay = data.display; + int xDrawable = data.drawable; + /* Simple case: no stretching */ + if ((srcWidth == destWidth) && (srcHeight == destHeight)) { + OS.XCopyArea(xDisplay, srcImage.pixmap, xDrawable, handle, srcX, srcY, srcWidth, srcHeight, destX, destY); + return; + } + + /* Streching case */ + int xImagePtr = scalePixmap(xDisplay, srcImage.pixmap, srcX, srcY, srcWidth, srcHeight, destX, destY, destWidth, destHeight, false, false); + OS.XPutImage(xDisplay, xDrawable, handle, xImagePtr, 0, 0, destX, destY, destWidth, destHeight); + OS.XDestroyImage(xImagePtr); +} +static int scalePixmap(int display, int pixmap, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, boolean flipX, boolean flipY) { + int xSrcImagePtr = OS.XGetImage(display, pixmap, srcX, srcY, srcWidth, srcHeight, OS.AllPlanes, OS.ZPixmap); + if (xSrcImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES); + XImage xSrcImage = new XImage(); + OS.memmove(xSrcImage, xSrcImagePtr, XImage.sizeof); + byte[] srcData = new byte[xSrcImage.bytes_per_line * xSrcImage.height]; + OS.memmove(srcData, xSrcImage.data, srcData.length); + int error = 0, xImagePtr = 0; + int visual = OS.XDefaultVisual(display, OS.XDefaultScreen(display)); + switch (xSrcImage.bits_per_pixel) { + case 1: + case 4: + case 8: { + int format = xSrcImage.bits_per_pixel == 1 ? OS.XYBitmap : OS.ZPixmap; + xImagePtr = OS.XCreateImage(display, visual, xSrcImage.depth, format, 0, 0, destWidth, destHeight, xSrcImage.bitmap_pad, 0); + if (xImagePtr == 0) break; + XImage xImage = new XImage(); + OS.memmove(xImage, xImagePtr, XImage.sizeof); + int bufSize = xImage.bytes_per_line * xImage.height; + int bufPtr = OS.XtMalloc(bufSize); + xImage.data = bufPtr; + OS.memmove(xImagePtr, xImage, XImage.sizeof); + byte[] buf = new byte[bufSize]; + int srcOrder = xSrcImage.bits_per_pixel == 1 ? xSrcImage.bitmap_bit_order : xSrcImage.byte_order; + int destOrder = xImage.bits_per_pixel == 1 ? xImage.bitmap_bit_order : xImage.byte_order; + ImageData.blit(ImageData.BLIT_SRC, + srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, srcOrder, 0, 0, srcWidth, srcHeight, null, null, null, + ImageData.ALPHA_OPAQUE, null, 0, 0, 0, + buf, xImage.bits_per_pixel, xImage.bytes_per_line, destOrder, 0, 0, destWidth, destHeight, null, null, null, + flipX, flipY); + OS.memmove(bufPtr, buf, bufSize); + break; + } + case 16: + case 24: + case 32: { + xImagePtr = OS.XCreateImage(display, visual, xSrcImage.depth, OS.ZPixmap, 0, 0, destWidth, destHeight, xSrcImage.bitmap_pad, 0); + if (xImagePtr == 0) break; + XImage xImage = new XImage(); + OS.memmove(xImage, xImagePtr, XImage.sizeof); + int bufSize = xImage.bytes_per_line * xImage.height; + int bufPtr = OS.XtMalloc(bufSize); + xImage.data = bufPtr; + OS.memmove(xImagePtr, xImage, XImage.sizeof); + byte[] buf = new byte[bufSize]; + ImageData.blit(ImageData.BLIT_SRC, + srcData, xSrcImage.bits_per_pixel, xSrcImage.bytes_per_line, xSrcImage.byte_order, 0, 0, srcWidth, srcHeight, 0, 0, 0, + ImageData.ALPHA_OPAQUE, null, 0, 0, 0, + buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, 0, 0, 0, + flipX, flipY); + OS.memmove(bufPtr, buf, bufSize); + break; + } + default: + error = SWT.ERROR_UNSUPPORTED_DEPTH; + } + OS.XDestroyImage(xSrcImagePtr); + if (xImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES); + if (error != 0) { + if (xImagePtr != 0) OS.XDestroyImage(xImagePtr); + SWT.error(error); + } + return xImagePtr; +} /** * Draws a line, using the foreground color, between the points * (<code>x1</code>, <code>y1</code>) and (<code>x2</code>, <code>y2</code>). @@ -624,10 +624,10 @@ static int scalePixmap(int display, int pixmap, int srcX, int srcY, int srcWidth * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void drawLine (int x1, int y1, int x2, int y2) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- OS.XDrawLine (data.display, data.drawable, handle, x1, y1, x2, y2);
-}
+public void drawLine (int x1, int y1, int x2, int y2) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + OS.XDrawLine (data.display, data.drawable, handle, x1, y1, x2, y2); +} /** * Draws the outline of an oval, using the foreground color, * within the specified rectangular area. @@ -649,18 +649,18 @@ public void drawLine (int x1, int y1, int x2, int y2) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void drawOval(int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- OS.XDrawArc(data.display, data.drawable, handle, x, y, width, height, 0, 23040);
-}
+public void drawOval(int x, int y, int width, int height) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (width < 0) { + x = x + width; + width = -width; + } + if (height < 0) { + y = y + height; + height = -height; + } + OS.XDrawArc(data.display, data.drawable, handle, 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 @@ -678,48 +678,48 @@ public void drawOval(int x, int y, int width, int height) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void drawPolygon(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
-
- // Motif does not have a native drawPolygon() call. Instead we ensure
- // that the first and last points are the same and call drawPolyline().
-
- int length = pointArray.length;
-
- // Need at least 3 points to define the polygon. If 2 or fewer points
- // passed in, it is either a line or point so just call drawPolyline().
- // Check what happens when XOR is implemented. We may not be able to
- // do this optimization.
-
- if (length < 4) {
- drawPolyline(pointArray);
- return;
- }
-
- // If first and last points are the same, the polygon is already closed.
- // Just call drawPolyline().
- //
- // Check what happens when XOR is implemented. We may not be able to
- // do this optimization.
-
- if (pointArray[0] == pointArray[length - 2] && (pointArray[1] == pointArray[length - 1])) {
- drawPolyline(pointArray);
- return;
- }
-
- // Grow the list of points by one element and make sure the first and last
- // points are the same. This will close the polygon and we can use the
- // drawPolyline() call.
-
- int newPoints[] = new int[length + 2];
- for (int i = 0; i < length ; i++)
- newPoints[i] = pointArray[i];
- newPoints[length] = pointArray[0];
- newPoints[length + 1] = pointArray[1];
-
- drawPolyline(newPoints);
-}
+public void drawPolygon(int[] pointArray) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + + // Motif does not have a native drawPolygon() call. Instead we ensure + // that the first and last points are the same and call drawPolyline(). + + int length = pointArray.length; + + // Need at least 3 points to define the polygon. If 2 or fewer points + // passed in, it is either a line or point so just call drawPolyline(). + // Check what happens when XOR is implemented. We may not be able to + // do this optimization. + + if (length < 4) { + drawPolyline(pointArray); + return; + } + + // If first and last points are the same, the polygon is already closed. + // Just call drawPolyline(). + // + // Check what happens when XOR is implemented. We may not be able to + // do this optimization. + + if (pointArray[0] == pointArray[length - 2] && (pointArray[1] == pointArray[length - 1])) { + drawPolyline(pointArray); + return; + } + + // Grow the list of points by one element and make sure the first and last + // points are the same. This will close the polygon and we can use the + // drawPolyline() call. + + int newPoints[] = new int[length + 2]; + for (int i = 0; i < length ; i++) + newPoints[i] = pointArray[i]; + newPoints[length] = pointArray[0]; + newPoints[length + 1] = pointArray[1]; + + drawPolyline(newPoints); +} /** * Draws the polyline which is defined by the specified array * of integer coordinates, using the receiver's foreground color. The array @@ -737,15 +737,15 @@ public void drawPolygon(int[] pointArray) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void drawPolyline(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- short[] xPoints = new short[pointArray.length];
- for (int i = 0; i<pointArray.length;i++) {
- xPoints[i] = (short) pointArray[i];
- }
- OS.XDrawLines(data.display,data.drawable,handle,xPoints,xPoints.length / 2, OS.CoordModeOrigin);
-}
+public void drawPolyline(int[] pointArray) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + short[] xPoints = new short[pointArray.length]; + for (int i = 0; i<pointArray.length;i++) { + xPoints[i] = (short) pointArray[i]; + } + OS.XDrawLines(data.display,data.drawable,handle,xPoints,xPoints.length / 2, OS.CoordModeOrigin); +} /** * Draws the outline of the rectangle specified by the arguments, * using the receiver's foreground color. The left and right edges @@ -761,18 +761,18 @@ public void drawPolyline(int[] pointArray) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void drawRectangle (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- OS.XDrawRectangle (data.display, data.drawable, handle, x, y, width, height);
-}
+public void drawRectangle (int x, int y, int width, int height) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (width < 0) { + x = x + width; + width = -width; + } + if (height < 0) { + y = y + height; + height = -height; + } + OS.XDrawRectangle (data.display, data.drawable, handle, x, y, width, height); +} /** * Draws the outline of the specified rectangle, using the receiver's * foreground color. The left and right edges of the rectangle are at @@ -789,10 +789,10 @@ public void drawRectangle (int x, int y, int width, int height) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void drawRectangle (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- drawRectangle (rect.x, rect.y, rect.width, rect.height);
-}
+public void drawRectangle (Rectangle rect) { + if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + drawRectangle (rect.x, rect.y, rect.width, rect.height); +} /** * Draws the outline of the round-cornered rectangle specified by * the arguments, using the receiver's foreground color. The left and @@ -812,65 +812,65 @@ public void drawRectangle (Rectangle rect) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void drawRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
-
- // X does not have a native for drawing round rectangles. Do the work in Java
- // and use drawLine() drawArc() calls.
-
- 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 = naw / 2;
- int nah2 = nah / 2;
-
- int xDisplay = data.display;
- int xDrawable = data.drawable;
-
- if (nw > naw) {
- if (nh > nah) {
- OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny, naw, nah, 5760, 5760);
- OS.XDrawLine(xDisplay, xDrawable, handle, nx + naw2, ny, nx + nw - naw2, ny);
- OS.XDrawArc(xDisplay, xDrawable, handle, nx + nw - naw, ny, naw, nah, 0, 5760);
- OS.XDrawLine(xDisplay, xDrawable, handle, nx + nw, ny + nah2, nx + nw, ny + nh - nah2);
- OS.XDrawArc(xDisplay, xDrawable, handle, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760);
- OS.XDrawLine(xDisplay,xDrawable,handle, nx + naw2, ny + nh, nx + nw - naw2, ny + nh);
- OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny + nh - nah, naw, nah, 11520, 5760);
- OS.XDrawLine(xDisplay, xDrawable, handle, nx, ny + nah2, nx, ny + nh - nah2);
- } else {
- OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny, naw, nh, 5760, 11520);
- OS.XDrawLine(xDisplay, xDrawable, handle, nx + naw2, ny, nx + nw - naw2, ny);
- OS.XDrawArc(xDisplay, xDrawable, handle, nx + nw - naw, ny, naw, nh, 17280, 11520);
- OS.XDrawLine(xDisplay,xDrawable,handle, nx + naw2, ny + nh, nx + nw - naw2, ny + nh);
- }
- } else {
- if (nh > nah) {
- OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny, nw, nah, 0, 11520);
- OS.XDrawLine(xDisplay, xDrawable, handle, nx + nw, ny + nah2, nx + nw, ny + nh - nah2);
- OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny + nh - nah, nw, nah, 11520, 11520);
- OS.XDrawLine(xDisplay,xDrawable,handle, nx, ny + nah2, nx, ny + nh - nah2);
- } else {
- OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny, nw, nh, 0, 23040);
- }
- }
-}
+public void drawRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + + // X does not have a native for drawing round rectangles. Do the work in Java + // and use drawLine() drawArc() calls. + + 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 = naw / 2; + int nah2 = nah / 2; + + int xDisplay = data.display; + int xDrawable = data.drawable; + + if (nw > naw) { + if (nh > nah) { + OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny, naw, nah, 5760, 5760); + OS.XDrawLine(xDisplay, xDrawable, handle, nx + naw2, ny, nx + nw - naw2, ny); + OS.XDrawArc(xDisplay, xDrawable, handle, nx + nw - naw, ny, naw, nah, 0, 5760); + OS.XDrawLine(xDisplay, xDrawable, handle, nx + nw, ny + nah2, nx + nw, ny + nh - nah2); + OS.XDrawArc(xDisplay, xDrawable, handle, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760); + OS.XDrawLine(xDisplay,xDrawable,handle, nx + naw2, ny + nh, nx + nw - naw2, ny + nh); + OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny + nh - nah, naw, nah, 11520, 5760); + OS.XDrawLine(xDisplay, xDrawable, handle, nx, ny + nah2, nx, ny + nh - nah2); + } else { + OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny, naw, nh, 5760, 11520); + OS.XDrawLine(xDisplay, xDrawable, handle, nx + naw2, ny, nx + nw - naw2, ny); + OS.XDrawArc(xDisplay, xDrawable, handle, nx + nw - naw, ny, naw, nh, 17280, 11520); + OS.XDrawLine(xDisplay,xDrawable,handle, nx + naw2, ny + nh, nx + nw - naw2, ny + nh); + } + } else { + if (nh > nah) { + OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny, nw, nah, 0, 11520); + OS.XDrawLine(xDisplay, xDrawable, handle, nx + nw, ny + nah2, nx + nw, ny + nh - nah2); + OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny + nh - nah, nw, nah, 11520, 11520); + OS.XDrawLine(xDisplay,xDrawable,handle, nx, ny + nah2, nx, ny + nh - nah2); + } else { + OS.XDrawArc(xDisplay, xDrawable, handle, nx, ny, nw, nh, 0, 23040); + } + } +} /** * Draws the given string, using the receiver's current font and * foreground color. No tab expansion or carriage return processing @@ -889,9 +889,9 @@ public void drawRoundRectangle (int x, int y, int width, int height, int arcWidt * <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);
-}
+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 @@ -912,71 +912,71 @@ public void drawString (String string, int x, int y) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void drawString (String string, int x, int y, boolean isTransparent) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- int xmString = OS.XmStringCreate (buffer, OS.XmFONTLIST_DEFAULT_TAG);
- if (isTransparent) {
- OS.XmStringDraw (data.display, data.drawable, data.fontList, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
- } else {
- OS.XmStringDrawImage (data.display, data.drawable, data.fontList, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
- }
-// OS.XmStringDrawUnderline (display, drawable, fontList, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null, 0);
- OS.XmStringFree (xmString);
-}
-void createRenderTable() {
- int xDisplay = data.display;
- int fontList = data.fontList;
- /* Get the width of the tabs */
- byte[] buffer = {(byte)' ', 0};
- int xmString = OS.XmStringCreate(buffer, OS.XmFONTLIST_DEFAULT_TAG);
- int tabWidth = OS.XmStringWidth(fontList, xmString) * 8;
- OS.XmStringFree(xmString);
-
- /* Create the tab list */
- int [] tabs = new int[16];
- int tab = OS.XmTabCreate(tabWidth, (byte) OS.XmPIXELS, (byte) OS.XmRELATIVE, (byte) OS.XmALIGNMENT_BEGINNING, null);
- for (int i = 0; i < tabs.length; i++) tabs[i] = tab;
- int tabList = OS.XmTabListInsertTabs(0, tabs, tabs.length, 0);
-
- /* Create a font context to iterate over the elements in the font list */
- int[] fontBuffer = new int[1];
- if (!OS.XmFontListInitFontContext(fontBuffer, fontList)) {
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- int context = fontBuffer[0], fontListEntry = 0;
- int widgetClass = OS.TopLevelShellWidgetClass ();
- int[] renditions = new int[4]; int renditionCount = 0;
-
- /* Create a rendition for each entry in the font list */
- int shellHandle = OS.XtAppCreateShell (null, null, widgetClass, xDisplay, null, 0);
- while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, fontBuffer);
- int fontType = (fontBuffer [0] == 0) ? OS.XmFONT_IS_FONT : OS.XmFONT_IS_FONTSET;
- if (fontPtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int [] argList = {
- OS.XmNtabList, tabList,
- OS.XmNfont, fontPtr,
- OS.XmNfontType, fontType,
- };
- int rendition = OS.XmRenditionCreate(shellHandle, OS.XmFONTLIST_DEFAULT_TAG, argList, argList.length / 2);
- renditions[renditionCount++] = rendition;
- if (renditionCount == renditions.length) {
- int[] newArray = new int[renditions.length + 4];
- System.arraycopy(newArray, 0, renditions, 0, renditionCount);
- renditions = newArray;
- }
- }
- OS.XmFontListFreeFontContext(context);
- OS.XmTabFree(tab);
- OS.XmTabListFree(tabList);
- OS.XtDestroyWidget (shellHandle);
-
- /* Create the render table from the renditions */
- data.renderTable = OS.XmRenderTableAddRenditions(0, renditions, renditionCount, OS.XmMERGE_REPLACE);
- for (int i = 0; i < renditionCount; i++) OS.XmRenditionFree(renditions[i]);
-}
+public void drawString (String string, int x, int y, boolean isTransparent) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); + int xmString = OS.XmStringCreate (buffer, OS.XmFONTLIST_DEFAULT_TAG); + if (isTransparent) { + OS.XmStringDraw (data.display, data.drawable, data.fontList, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null); + } else { + OS.XmStringDrawImage (data.display, data.drawable, data.fontList, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null); + } +// OS.XmStringDrawUnderline (display, drawable, fontList, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null, 0); + OS.XmStringFree (xmString); +} +void createRenderTable() { + int xDisplay = data.display; + int fontList = data.fontList; + /* Get the width of the tabs */ + byte[] buffer = {(byte)' ', 0}; + int xmString = OS.XmStringCreate(buffer, OS.XmFONTLIST_DEFAULT_TAG); + int tabWidth = OS.XmStringWidth(fontList, xmString) * 8; + OS.XmStringFree(xmString); + + /* Create the tab list */ + int [] tabs = new int[16]; + int tab = OS.XmTabCreate(tabWidth, (byte) OS.XmPIXELS, (byte) OS.XmRELATIVE, (byte) OS.XmALIGNMENT_BEGINNING, null); + for (int i = 0; i < tabs.length; i++) tabs[i] = tab; + int tabList = OS.XmTabListInsertTabs(0, tabs, tabs.length, 0); + + /* Create a font context to iterate over the elements in the font list */ + int[] fontBuffer = new int[1]; + if (!OS.XmFontListInitFontContext(fontBuffer, fontList)) { + SWT.error(SWT.ERROR_NO_HANDLES); + } + int context = fontBuffer[0], fontListEntry = 0; + int widgetClass = OS.TopLevelShellWidgetClass (); + int[] renditions = new int[4]; int renditionCount = 0; + + /* Create a rendition for each entry in the font list */ + int shellHandle = OS.XtAppCreateShell (null, null, widgetClass, xDisplay, null, 0); + while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) { + int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, fontBuffer); + int fontType = (fontBuffer [0] == 0) ? OS.XmFONT_IS_FONT : OS.XmFONT_IS_FONTSET; + if (fontPtr == 0) SWT.error(SWT.ERROR_NO_HANDLES); + int [] argList = { + OS.XmNtabList, tabList, + OS.XmNfont, fontPtr, + OS.XmNfontType, fontType, + }; + int rendition = OS.XmRenditionCreate(shellHandle, OS.XmFONTLIST_DEFAULT_TAG, argList, argList.length / 2); + renditions[renditionCount++] = rendition; + if (renditionCount == renditions.length) { + int[] newArray = new int[renditions.length + 4]; + System.arraycopy(newArray, 0, renditions, 0, renditionCount); + renditions = newArray; + } + } + OS.XmFontListFreeFontContext(context); + OS.XmTabFree(tab); + OS.XmTabListFree(tabList); + OS.XtDestroyWidget (shellHandle); + + /* Create the render table from the renditions */ + data.renderTable = OS.XmRenderTableAddRenditions(0, renditions, renditionCount, OS.XmMERGE_REPLACE); + for (int i = 0; i < renditionCount; i++) OS.XmRenditionFree(renditions[i]); +} /** * Draws the given string, using the receiver's current font and * foreground color. Tab expansion and carriage return processing @@ -995,9 +995,9 @@ void createRenderTable() { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void drawText (String string, int x, int y) {
- drawText(string, x, y, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
-}
+public void drawText (String string, int x, int y) { + drawText(string, x, y, SWT.DRAW_DELIMITER | SWT.DRAW_TAB); +} /** * Draws the given string, using the receiver's current font and * foreground color. Tab expansion and carriage return processing @@ -1018,78 +1018,78 @@ public void drawText (String string, int x, int y) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void drawText (String string, int x, int y, boolean isTransparent) {
- int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB;
- if (isTransparent) flags |= SWT.DRAW_TRANSPARENT;
- drawText(string, x, y, flags);
-}
-/**
- * Draws the given string, using the receiver's current font and
- * foreground color. Tab expansion, line delimiter and mnemonic
- * processing are performed according to the specified flags. If
- * <code>flags</code> includes <code>DRAW_TRANSPARENT</code>,
- * then the background of the rectangular area where the text is being
- * drawn will not be modified, otherwise it will be filled with the
- * receiver's background color.
- * <p>
- * The parameter <code>flags</code> may be a combination of:
- * <dl>
- * <dt><b>DRAW_DELIMITER</b></dt>
- * <dd>draw multiple lines</dd>
- * <dt><b>DRAW_TAB</b></dt>
- * <dd>expand tabs</dd>
- * <dt><b>DRAW_MNEMONIC</b></dt>
- * <dd>underline the mnemonic character</dd>
- * <dt><b>DRAW_TRANSPARENT</b></dt>
- * <dd>transparent background</dd>
- * </dl>
- * </p>
- *
- * @param string the string to be drawn
- * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn
- * @param flags the flags 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, boolean isTransparent) { + int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB; + if (isTransparent) flags |= SWT.DRAW_TRANSPARENT; + drawText(string, x, y, flags); +} +/** + * Draws the given string, using the receiver's current font and + * foreground color. Tab expansion, line delimiter and mnemonic + * processing are performed according to the specified flags. If + * <code>flags</code> includes <code>DRAW_TRANSPARENT</code>, + * then the background of the rectangular area where the text is being + * drawn will not be modified, otherwise it will be filled with the + * receiver's background color. + * <p> + * The parameter <code>flags</code> may be a combination of: + * <dl> + * <dt><b>DRAW_DELIMITER</b></dt> + * <dd>draw multiple lines</dd> + * <dt><b>DRAW_TAB</b></dt> + * <dd>expand tabs</dd> + * <dt><b>DRAW_MNEMONIC</b></dt> + * <dd>underline the mnemonic character</dd> + * <dt><b>DRAW_TRANSPARENT</b></dt> + * <dd>transparent background</dd> + * </dl> + * </p> + * + * @param string the string to be drawn + * @param x the x coordinate of the top left corner of the rectangular area where the text is to be drawn + * @param y the y coordinate of the top left corner of the rectangular area where the text is to be drawn + * @param flags the flags 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) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (data.renderTable == 0) createRenderTable();
- int renderTable = data.renderTable;
-
- char mnemonic=0;
- int tableLength = 0;
- Device device = data.device;
- int[] parseTable = new int[2];
- char[] text = new char[string.length()];
- string.getChars(0, text.length, text, 0);
- if ((flags & SWT.DRAW_DELIMITER) != 0) parseTable[tableLength++] = device.crMapping;
- if ((flags & SWT.DRAW_TAB) != 0) parseTable[tableLength++] = device.tabMapping;
- if ((flags & SWT.DRAW_MNEMONIC) != 0) mnemonic = stripMnemonic(text);
-
- String codePage = getCodePage();
- byte[] buffer = Converter.wcsToMbcs(codePage, text, true);
- int xmString = OS.XmStringParseText(buffer, 0, OS.XmFONTLIST_DEFAULT_TAG, OS.XmCHARSET_TEXT, parseTable, tableLength, 0);
- if (mnemonic != 0) {
- byte [] buffer1 = Converter.wcsToMbcs(codePage, new char[]{mnemonic}, true);
- int xmStringUnderline = OS.XmStringCreate (buffer1, OS.XmFONTLIST_DEFAULT_TAG);
- OS.XmStringDrawUnderline(data.display, data.drawable, renderTable, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null, xmStringUnderline);
- OS.XmStringFree(xmStringUnderline);
- } else {
- if ((flags & SWT.DRAW_TRANSPARENT) != 0) {
- OS.XmStringDraw(data.display, data.drawable, renderTable, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
- } else {
- OS.XmStringDrawImage(data.display, data.drawable, renderTable, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null);
- }
- }
- OS.XmStringFree(xmString);
-}
+public void drawText (String string, int x, int y, int flags) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (data.renderTable == 0) createRenderTable(); + int renderTable = data.renderTable; + + char mnemonic=0; + int tableLength = 0; + Device device = data.device; + int[] parseTable = new int[2]; + char[] text = new char[string.length()]; + string.getChars(0, text.length, text, 0); + if ((flags & SWT.DRAW_DELIMITER) != 0) parseTable[tableLength++] = device.crMapping; + if ((flags & SWT.DRAW_TAB) != 0) parseTable[tableLength++] = device.tabMapping; + if ((flags & SWT.DRAW_MNEMONIC) != 0) mnemonic = stripMnemonic(text); + + String codePage = getCodePage(); + byte[] buffer = Converter.wcsToMbcs(codePage, text, true); + int xmString = OS.XmStringParseText(buffer, 0, OS.XmFONTLIST_DEFAULT_TAG, OS.XmCHARSET_TEXT, parseTable, tableLength, 0); + if (mnemonic != 0) { + byte [] buffer1 = Converter.wcsToMbcs(codePage, new char[]{mnemonic}, true); + int xmStringUnderline = OS.XmStringCreate (buffer1, OS.XmFONTLIST_DEFAULT_TAG); + OS.XmStringDrawUnderline(data.display, data.drawable, renderTable, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null, xmStringUnderline); + OS.XmStringFree(xmStringUnderline); + } else { + if ((flags & SWT.DRAW_TRANSPARENT) != 0) { + OS.XmStringDraw(data.display, data.drawable, renderTable, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null); + } else { + OS.XmStringDrawImage(data.display, data.drawable, renderTable, xmString, handle, x, y, 0x7FFFFFFF, OS.XmALIGNMENT_BEGINNING, 0, null); + } + } + OS.XmStringFree(xmString); +} /** * Compares the argument to the receiver, and returns true * if they represent the <em>same</em> object using a class @@ -1100,11 +1100,11 @@ public void drawText (String string, int x, int y, int flags) { * * @see #hashCode */ -public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof GC)) return false;
- return handle == ((GC)object).handle;
-}
+public boolean equals (Object object) { + if (object == this) return true; + if (!(object instanceof GC)) return false; + return handle == ((GC)object).handle; +} /** * Fills the interior of a circular or elliptical arc within * the specified rectangular area, with the receiver's background @@ -1140,125 +1140,125 @@ public boolean equals (Object object) { * * @see #drawArc */ -public void fillArc(int x, int y, int width, int height, int startAngle, int endAngle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- if (width == 0 || height == 0 || endAngle == 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int xDisplay = data.display;
- XGCValues values = new XGCValues ();
- OS.XGetGCValues (xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
- OS.XSetForeground (xDisplay, handle, values.background);
- OS.XFillArc(xDisplay,data.drawable,handle,x,y,width,height,startAngle * 64 ,endAngle * 64);
- OS.XSetForeground (xDisplay, handle, values.foreground);
-}
-
-/**
- * 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 fillArc(int x, int y, int width, int height, int startAngle, int endAngle) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (width < 0) { + x = x + width; + width = -width; + } + if (height < 0) { + y = y + height; + height = -height; + } + if (width == 0 || height == 0 || endAngle == 0) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + int xDisplay = data.display; + XGCValues values = new XGCValues (); + OS.XGetGCValues (xDisplay, handle, OS.GCForeground | OS.GCBackground, values); + OS.XSetForeground (xDisplay, handle, values.background); + OS.XFillArc(xDisplay,data.drawable,handle,x,y,width,height,startAngle * 64 ,endAngle * 64); + OS.XSetForeground (xDisplay, handle, values.foreground); +} + +/** + * 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;
- int xDisplay = data.display;
- int xScreenNum = OS.XDefaultScreen(xDisplay);
- XGCValues values = new XGCValues();
- int fromColor, toColor;
- OS.XGetGCValues(xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
- fromColor = values.foreground;
- toColor = values.background;
- boolean swapColors = false;
- if (width < 0) {
- x += width; width = -width;
- if (! vertical) swapColors = true;
- }
- if (height < 0) {
- y += height; height = -height;
- if (vertical) swapColors = true;
- }
- if (swapColors) {
- final int t = fromColor;
- fromColor = toColor;
- toColor = t;
- }
- if (fromColor == toColor) {
- OS.XFillRectangle(xDisplay, data.drawable, handle, x, y, width, height);
- return;
- }
- /* X Window deals with a virtually limitless array of color formats
- * but we only distinguish between paletted and direct modes
- */
- final int xScreen = OS.XDefaultScreenOfDisplay(xDisplay);
- final int xVisual = OS.XDefaultVisual(xDisplay, xScreenNum);
- Visual visual = new Visual();
- OS.memmove(visual, xVisual, Visual.sizeof);
- final int depth = OS.XDefaultDepthOfScreen(xScreen);
- final boolean directColor = (depth > 8);
-
- // This code is intentionally commented since elsewhere in SWT we
- // assume that depth <= 8 means we are in a paletted mode though
- // this is not always the case.
- //final boolean directColor = (visual.c_class == OS.TrueColor) || (visual.c_class == OS.DirectColor);
-
- XColor xColor = new XColor();
- xColor.pixel = fromColor;
- OS.XQueryColor(xDisplay, data.colormap, xColor);
- final RGB fromRGB = new RGB((xColor.red & 0xffff) >>> 8, (xColor.green & 0xffff) >>> 8, (xColor.blue & 0xffff) >>> 8);
- xColor.pixel = toColor;
- OS.XQueryColor(xDisplay, data.colormap, xColor);
- final RGB toRGB = new RGB((xColor.red & 0xffff) >>> 8, (xColor.green & 0xffff) >>> 8, (xColor.blue & 0xffff) >>> 8);
-
- final int redBits, greenBits, blueBits;
- if (directColor) {
- // RGB mapped display
- redBits = getChannelWidth(visual.red_mask);
- greenBits = getChannelWidth(visual.green_mask);
- blueBits = getChannelWidth(visual.blue_mask);
- } else {
- // Index display
- redBits = greenBits = blueBits = 0;
- }
- ImageData.fillGradientRectangle(this, data.device,
- x, y, width, height, vertical, fromRGB, toRGB,
- redBits, greenBits, blueBits);
-}
-
-/**
- * Computes the required channel width (depth) from a mask.
+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; + int xDisplay = data.display; + int xScreenNum = OS.XDefaultScreen(xDisplay); + XGCValues values = new XGCValues(); + int fromColor, toColor; + OS.XGetGCValues(xDisplay, handle, OS.GCForeground | OS.GCBackground, values); + fromColor = values.foreground; + toColor = values.background; + boolean swapColors = false; + if (width < 0) { + x += width; width = -width; + if (! vertical) swapColors = true; + } + if (height < 0) { + y += height; height = -height; + if (vertical) swapColors = true; + } + if (swapColors) { + final int t = fromColor; + fromColor = toColor; + toColor = t; + } + if (fromColor == toColor) { + OS.XFillRectangle(xDisplay, data.drawable, handle, x, y, width, height); + return; + } + /* X Window deals with a virtually limitless array of color formats + * but we only distinguish between paletted and direct modes + */ + final int xScreen = OS.XDefaultScreenOfDisplay(xDisplay); + final int xVisual = OS.XDefaultVisual(xDisplay, xScreenNum); + Visual visual = new Visual(); + OS.memmove(visual, xVisual, Visual.sizeof); + final int depth = OS.XDefaultDepthOfScreen(xScreen); + final boolean directColor = (depth > 8); + + // This code is intentionally commented since elsewhere in SWT we + // assume that depth <= 8 means we are in a paletted mode though + // this is not always the case. + //final boolean directColor = (visual.c_class == OS.TrueColor) || (visual.c_class == OS.DirectColor); + + XColor xColor = new XColor(); + xColor.pixel = fromColor; + OS.XQueryColor(xDisplay, data.colormap, xColor); + final RGB fromRGB = new RGB((xColor.red & 0xffff) >>> 8, (xColor.green & 0xffff) >>> 8, (xColor.blue & 0xffff) >>> 8); + xColor.pixel = toColor; + OS.XQueryColor(xDisplay, data.colormap, xColor); + final RGB toRGB = new RGB((xColor.red & 0xffff) >>> 8, (xColor.green & 0xffff) >>> 8, (xColor.blue & 0xffff) >>> 8); + + final int redBits, greenBits, blueBits; + if (directColor) { + // RGB mapped display + redBits = getChannelWidth(visual.red_mask); + greenBits = getChannelWidth(visual.green_mask); + blueBits = getChannelWidth(visual.blue_mask); + } else { + // Index display + redBits = greenBits = blueBits = 0; + } + ImageData.fillGradientRectangle(this, data.device, + x, y, width, height, vertical, fromRGB, toRGB, + redBits, greenBits, blueBits); +} + +/** + * Computes the required channel width (depth) from a mask. */ -static int getChannelWidth(int mask) {
- int width = 0;
- while (mask != 0) {
- width += (mask & 1);
- mask >>>= 1;
- }
- return width;
-}
-
+static int getChannelWidth(int mask) { + int width = 0; + while (mask != 0) { + width += (mask & 1); + mask >>>= 1; + } + return width; +} + /** * Fills the interior of an oval, within the specified * rectangular area, with the receiver's background @@ -1275,23 +1275,23 @@ static int getChannelWidth(int mask) { * * @see #drawOval */ -public void fillOval (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int display = data.display;
- XGCValues values = new XGCValues ();
- OS.XGetGCValues (display, handle, OS.GCForeground | OS.GCBackground, values);
- OS.XSetForeground (display, handle, values.background);
- OS.XFillArc (display, data.drawable, handle, x, y, width, height, 0, 23040);
- OS.XSetForeground (display, handle, values.foreground);
-}
+public void fillOval (int x, int y, int width, int height) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (width < 0) { + x = x + width; + width = -width; + } + if (height < 0) { + y = y + height; + height = -height; + } + int display = data.display; + XGCValues values = new XGCValues (); + OS.XGetGCValues (display, handle, OS.GCForeground | OS.GCBackground, values); + OS.XSetForeground (display, handle, values.background); + OS.XFillArc (display, data.drawable, handle, x, y, width, height, 0, 23040); + OS.XSetForeground (display, handle, values.foreground); +} /** * Fills the interior of the closed polygon which is defined by the * specified array of integer coordinates, using the receiver's @@ -1311,20 +1311,20 @@ public void fillOval (int x, int y, int width, int height) { * * @see #drawPolygon */ -public void fillPolygon(int[] pointArray) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- short[] xPoints = new short[pointArray.length];
- for (int i = 0; i<pointArray.length;i++) {
- xPoints[i] = (short) pointArray[i];
- }
- int xDisplay = data.display;
- XGCValues values = new XGCValues ();
- OS.XGetGCValues (xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
- OS.XSetForeground (xDisplay, handle, values.background);
- OS.XFillPolygon(xDisplay, data.drawable, handle,xPoints, xPoints.length / 2, OS.Complex, OS.CoordModeOrigin);
- OS.XSetForeground (xDisplay, handle, values.foreground);
-}
+public void fillPolygon(int[] pointArray) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (pointArray == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + short[] xPoints = new short[pointArray.length]; + for (int i = 0; i<pointArray.length;i++) { + xPoints[i] = (short) pointArray[i]; + } + int xDisplay = data.display; + XGCValues values = new XGCValues (); + OS.XGetGCValues (xDisplay, handle, OS.GCForeground | OS.GCBackground, values); + OS.XSetForeground (xDisplay, handle, values.background); + OS.XFillPolygon(xDisplay, data.drawable, handle,xPoints, xPoints.length / 2, OS.Complex, OS.CoordModeOrigin); + OS.XSetForeground (xDisplay, handle, values.foreground); +} /** * Fills the interior of the rectangle specified by the arguments, * using the receiver's background color. @@ -1340,23 +1340,23 @@ public void fillPolygon(int[] pointArray) { * * @see #drawRectangle */ -public void fillRectangle (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (width < 0) {
- x = x + width;
- width = -width;
- }
- if (height < 0) {
- y = y + height;
- height = -height;
- }
- int xDisplay = data.display;
- XGCValues values = new XGCValues ();
- OS.XGetGCValues (xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
- OS.XSetForeground (xDisplay, handle, values.background);
- OS.XFillRectangle (xDisplay, data.drawable, handle, x, y, width, height);
- OS.XSetForeground (xDisplay, handle, values.foreground);
-}
+public void fillRectangle (int x, int y, int width, int height) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (width < 0) { + x = x + width; + width = -width; + } + if (height < 0) { + y = y + height; + height = -height; + } + int xDisplay = data.display; + XGCValues values = new XGCValues (); + OS.XGetGCValues (xDisplay, handle, OS.GCForeground | OS.GCBackground, values); + OS.XSetForeground (xDisplay, handle, values.background); + OS.XFillRectangle (xDisplay, data.drawable, handle, x, y, width, height); + OS.XSetForeground (xDisplay, handle, values.foreground); +} /** * Fills the interior of the specified rectangle, using the receiver's * background color. @@ -1372,10 +1372,10 @@ public void fillRectangle (int x, int y, int width, int height) { * * @see #drawRectangle */ -public void fillRectangle (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- fillRectangle(rect.x, rect.y, rect.width, rect.height);
-}
+public void fillRectangle (Rectangle rect) { + if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + fillRectangle(rect.x, rect.y, rect.width, rect.height); +} /** * Fills the interior of the round-cornered rectangle specified by * the arguments, using the receiver's background color. @@ -1393,62 +1393,62 @@ public void fillRectangle (Rectangle rect) { * * @see #drawRoundRectangle */ -public void fillRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- 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 = naw / 2;
- int nah2 = nah / 2;
-
- int xDisplay = data.display;
- int xDrawable = data.drawable;
- XGCValues values = new XGCValues ();
- OS.XGetGCValues(xDisplay, handle, OS.GCForeground | OS.GCBackground, values);
- OS.XSetForeground(xDisplay, handle, values.background);
-
- if (nw > naw) {
- if (nh > nah) {
- OS.XFillArc(xDisplay, xDrawable, handle, nx, ny, naw, nah, 5760, 5760);
- OS.XFillRectangle(xDisplay, xDrawable, handle, nx + naw2, ny, nw - naw, nah2);
- OS.XFillArc(xDisplay, xDrawable, handle, nx + nw - naw, ny, naw, nah, 0, 5760);
- OS.XFillRectangle(xDisplay, xDrawable, handle, nx, ny + nah2, nw, nh - nah);
- OS.XFillArc(xDisplay, xDrawable, handle, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760);
- OS.XFillRectangle(xDisplay, xDrawable, handle, nx + naw2, ny + nh - nah2, nw - naw, nah2);
- OS.XFillArc(xDisplay, xDrawable, handle, nx, ny + nh - nah, naw, nah, 11520, 5760);
- } else {
- OS.XFillArc(xDisplay, xDrawable, handle, nx, ny, naw, nh, 5760, 11520);
- OS.XFillRectangle(xDisplay, xDrawable, handle, nx + naw2, ny, nw - naw, nh);
- OS.XFillArc(xDisplay, xDrawable, handle, nx + nw - naw, ny, naw, nh, 17280, 11520);
- }
- } else {
- if (nh > nah) {
- OS.XFillArc(xDisplay, xDrawable, handle, nx, ny, nw, nah, 0, 11520);
- OS.XFillRectangle(xDisplay, xDrawable, handle, nx, ny + nah2, nw, nh - nah);
- OS.XFillArc(xDisplay, xDrawable, handle, nx, ny + nh - nah, nw, nah, 11520, 11520);
- } else {
- OS.XFillArc(xDisplay, xDrawable, handle, nx, ny, nw, nh, 0, 23040);
- }
- }
- OS.XSetForeground(xDisplay, handle, values.foreground);
-}
+public void fillRoundRectangle (int x, int y, int width, int height, int arcWidth, int arcHeight) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + 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 = naw / 2; + int nah2 = nah / 2; + + int xDisplay = data.display; + int xDrawable = data.drawable; + XGCValues values = new XGCValues (); + OS.XGetGCValues(xDisplay, handle, OS.GCForeground | OS.GCBackground, values); + OS.XSetForeground(xDisplay, handle, values.background); + + if (nw > naw) { + if (nh > nah) { + OS.XFillArc(xDisplay, xDrawable, handle, nx, ny, naw, nah, 5760, 5760); + OS.XFillRectangle(xDisplay, xDrawable, handle, nx + naw2, ny, nw - naw, nah2); + OS.XFillArc(xDisplay, xDrawable, handle, nx + nw - naw, ny, naw, nah, 0, 5760); + OS.XFillRectangle(xDisplay, xDrawable, handle, nx, ny + nah2, nw, nh - nah); + OS.XFillArc(xDisplay, xDrawable, handle, nx + nw - naw, ny + nh - nah, naw, nah, 17280, 5760); + OS.XFillRectangle(xDisplay, xDrawable, handle, nx + naw2, ny + nh - nah2, nw - naw, nah2); + OS.XFillArc(xDisplay, xDrawable, handle, nx, ny + nh - nah, naw, nah, 11520, 5760); + } else { + OS.XFillArc(xDisplay, xDrawable, handle, nx, ny, naw, nh, 5760, 11520); + OS.XFillRectangle(xDisplay, xDrawable, handle, nx + naw2, ny, nw - naw, nh); + OS.XFillArc(xDisplay, xDrawable, handle, nx + nw - naw, ny, naw, nh, 17280, 11520); + } + } else { + if (nh > nah) { + OS.XFillArc(xDisplay, xDrawable, handle, nx, ny, nw, nah, 0, 11520); + OS.XFillRectangle(xDisplay, xDrawable, handle, nx, ny + nah2, nw, nh - nah); + OS.XFillArc(xDisplay, xDrawable, handle, nx, ny + nh - nah, nw, nah, 11520, 11520); + } else { + OS.XFillArc(xDisplay, xDrawable, handle, nx, ny, nw, nh, 0, 23040); + } + } + OS.XSetForeground(xDisplay, handle, values.foreground); +} /** * Returns the <em>advance width</em> of the specified character in * the font which is currently selected into the receiver. @@ -1464,94 +1464,94 @@ public void fillRoundRectangle (int x, int y, int width, int height, int arcWidt * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public int getAdvanceWidth(char ch) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int fontList = data.fontList;
- byte[] charBuffer = Converter.wcsToMbcs(getCodePage (), new char[] { ch }, false);
- int val = charBuffer[0] & 0xFF;
- /* Create a font context to iterate over each element in the font list */
- int[] buffer = new int[1];
- if (!OS.XmFontListInitFontContext(buffer, fontList)) {
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- int context = buffer[0];
- XFontStruct fontStruct = new XFontStruct();
- XCharStruct charStruct = new XCharStruct();
- int fontListEntry;
- int[] fontStructPtr = new int[1];
- int[] fontNamePtr = new int[1];
- /* Go through each entry in the font list. */
- while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer);
- if (buffer[0] == 0) {
- OS.memmove(fontStruct, fontPtr, XFontStruct.sizeof);
- /* FontList contains a single font */
- if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) {
- /* Single byte fontStruct */
- if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) {
- /* The font contains the character */
- OS.memmove(charStruct, fontStruct.per_char + ((val - fontStruct.min_char_or_byte2) * XCharStruct.sizeof), XCharStruct.sizeof);
- if (charStruct.width != 0) {
- OS.XmFontListFreeFontContext(context);
- return charStruct.width;
- }
- }
- } else {
- /* Double byte fontStruct */
- int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
- int row = 0;
- if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1;
- int col = charBuffer[0] - fontStruct.min_char_or_byte2;
- if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) {
- /* The font contains the character */
- int offset = row * charsPerRow + col;
- OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof);
- if (charStruct.width != 0) {
- OS.XmFontListFreeFontContext(context);
- return charStruct.width;
- }
- }
- }
- } else {
- /* FontList contains a fontSet */
- int nFonts = OS.XFontsOfFontSet(fontPtr, fontStructPtr, fontNamePtr);
- int [] fontStructs = new int[nFonts];
- OS.memmove(fontStructs, fontStructPtr[0], nFonts * 4);
- /* Go through each fontStruct in the font set */
- for (int i = 0; i < nFonts; i++) {
- OS.memmove(fontStruct, fontStructs[i], XFontStruct.sizeof);
- if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) {
- /* Single byte fontStruct */
- if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) {
- /* The font contains the character */
- OS.memmove(charStruct, fontStruct.per_char + (val - fontStruct.min_char_or_byte2 * XCharStruct.sizeof), XCharStruct.sizeof);
- if (charStruct.width != 0) {
- OS.XmFontListFreeFontContext(context);
- return charStruct.width;
- }
- }
- } else {
- /* Double byte fontStruct */
- int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
- int row = 0;
- if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1;
- int col = charBuffer[0] - fontStruct.min_char_or_byte2;
- if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) {
- /* The font contains the character */
- int offset = row * charsPerRow + col;
- OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof);
- if (charStruct.width != 0) {
- OS.XmFontListFreeFontContext(context);
- return charStruct.width;
- }
- }
- }
- }
- }
- }
- OS.XmFontListFreeFontContext(context);
- return 0;
-}
+public int getAdvanceWidth(char ch) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + int fontList = data.fontList; + byte[] charBuffer = Converter.wcsToMbcs(getCodePage (), new char[] { ch }, false); + int val = charBuffer[0] & 0xFF; + /* Create a font context to iterate over each element in the font list */ + int[] buffer = new int[1]; + if (!OS.XmFontListInitFontContext(buffer, fontList)) { + SWT.error(SWT.ERROR_NO_HANDLES); + } + int context = buffer[0]; + XFontStruct fontStruct = new XFontStruct(); + XCharStruct charStruct = new XCharStruct(); + int fontListEntry; + int[] fontStructPtr = new int[1]; + int[] fontNamePtr = new int[1]; + /* Go through each entry in the font list. */ + while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) { + int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer); + if (buffer[0] == 0) { + OS.memmove(fontStruct, fontPtr, XFontStruct.sizeof); + /* FontList contains a single font */ + if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) { + /* Single byte fontStruct */ + if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) { + /* The font contains the character */ + OS.memmove(charStruct, fontStruct.per_char + ((val - fontStruct.min_char_or_byte2) * XCharStruct.sizeof), XCharStruct.sizeof); + if (charStruct.width != 0) { + OS.XmFontListFreeFontContext(context); + return charStruct.width; + } + } + } else { + /* Double byte fontStruct */ + int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1; + int row = 0; + if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1; + int col = charBuffer[0] - fontStruct.min_char_or_byte2; + if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) { + /* The font contains the character */ + int offset = row * charsPerRow + col; + OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof); + if (charStruct.width != 0) { + OS.XmFontListFreeFontContext(context); + return charStruct.width; + } + } + } + } else { + /* FontList contains a fontSet */ + int nFonts = OS.XFontsOfFontSet(fontPtr, fontStructPtr, fontNamePtr); + int [] fontStructs = new int[nFonts]; + OS.memmove(fontStructs, fontStructPtr[0], nFonts * 4); + /* Go through each fontStruct in the font set */ + for (int i = 0; i < nFonts; i++) { + OS.memmove(fontStruct, fontStructs[i], XFontStruct.sizeof); + if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) { + /* Single byte fontStruct */ + if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) { + /* The font contains the character */ + OS.memmove(charStruct, fontStruct.per_char + (val - fontStruct.min_char_or_byte2 * XCharStruct.sizeof), XCharStruct.sizeof); + if (charStruct.width != 0) { + OS.XmFontListFreeFontContext(context); + return charStruct.width; + } + } + } else { + /* Double byte fontStruct */ + int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1; + int row = 0; + if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1; + int col = charBuffer[0] - fontStruct.min_char_or_byte2; + if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) { + /* The font contains the character */ + int offset = row * charsPerRow + col; + OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof); + if (charStruct.width != 0) { + OS.XmFontListFreeFontContext(context); + return charStruct.width; + } + } + } + } + } + } + OS.XmFontListFreeFontContext(context); + return 0; +} /** * Returns the background color. * @@ -1561,17 +1561,17 @@ public int getAdvanceWidth(char ch) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public Color getBackground() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int xDisplay = data.display;
- XGCValues values = new XGCValues();
- OS.XGetGCValues(xDisplay, handle, OS.GCBackground, values);
- XColor xColor = new XColor();
- xColor.pixel = values.background;
- OS.XQueryColor(xDisplay,data.colormap,xColor);
- return Color.motif_new(data.device, xColor);
-
-}
+public Color getBackground() { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + int xDisplay = data.display; + XGCValues values = new XGCValues(); + OS.XGetGCValues(xDisplay, handle, OS.GCBackground, values); + XColor xColor = new XColor(); + xColor.pixel = values.background; + OS.XQueryColor(xDisplay,data.colormap,xColor); + return Color.motif_new(data.device, xColor); + +} /** * Returns the width of the specified character in the font * selected into the receiver. @@ -1588,94 +1588,94 @@ public Color getBackground() { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public int getCharWidth(char ch) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int fontList = data.fontList;
- byte[] charBuffer = Converter.wcsToMbcs(getCodePage (), new char[] { ch }, false);
- int val = charBuffer[0] & 0xFF;
- /* Create a font context to iterate over each element in the font list */
- int[] buffer = new int[1];
- if (!OS.XmFontListInitFontContext(buffer, fontList)) {
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- int context = buffer[0];
- XFontStruct fontStruct = new XFontStruct();
- XCharStruct charStruct = new XCharStruct();
- int fontListEntry;
- int[] fontStructPtr = new int[1];
- int[] fontNamePtr = new int[1];
- /* Go through each entry in the font list. */
- while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer);
- if (buffer[0] == 0) {
- OS.memmove(fontStruct, fontPtr, XFontStruct.sizeof);
- /* FontList contains a single font */
- if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) {
- /* Single byte fontStruct */
- if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) {
- /* The font contains the character */
- OS.memmove(charStruct, fontStruct.per_char + ((val - fontStruct.min_char_or_byte2) * XCharStruct.sizeof), XCharStruct.sizeof);
- if (charStruct.width != 0) {
- OS.XmFontListFreeFontContext(context);
- return charStruct.rbearing - charStruct.lbearing;
- }
- }
- } else {
- /* Double byte fontStruct */
- int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
- int row = 0;
- if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1;
- int col = charBuffer[0] - fontStruct.min_char_or_byte2;
- if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) {
- /* The font contains the character */
- int offset = row * charsPerRow + col;
- OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof);
- if (charStruct.width != 0) {
- OS.XmFontListFreeFontContext(context);
- return charStruct.rbearing - charStruct.lbearing;
- }
- }
- }
- } else {
- /* FontList contains a fontSet */
- int nFonts = OS.XFontsOfFontSet(fontPtr, fontStructPtr, fontNamePtr);
- int [] fontStructs = new int[nFonts];
- OS.memmove(fontStructs, fontStructPtr[0], nFonts * 4);
- /* Go through each fontStruct in the font set */
- for (int i = 0; i < nFonts; i++) {
- OS.memmove(fontStruct, fontStructs[i], XFontStruct.sizeof);
- if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) {
- /* Single byte fontStruct */
- if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) {
- /* The font contains the character */
- OS.memmove(charStruct, fontStruct.per_char + (val - fontStruct.min_char_or_byte2 * XCharStruct.sizeof), XCharStruct.sizeof);
- if (charStruct.width != 0) {
- OS.XmFontListFreeFontContext(context);
- return charStruct.rbearing - charStruct.lbearing;
- }
- }
- } else {
- /* Double byte fontStruct */
- int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
- int row = 0;
- if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1;
- int col = charBuffer[0] - fontStruct.min_char_or_byte2;
- if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) {
- /* The font contains the character */
- int offset = row * charsPerRow + col;
- OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof);
- if (charStruct.width != 0) {
- OS.XmFontListFreeFontContext(context);
- return charStruct.rbearing - charStruct.lbearing;
- }
- }
- }
- }
- }
- }
- OS.XmFontListFreeFontContext(context);
- return 0;
-}
+public int getCharWidth(char ch) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + int fontList = data.fontList; + byte[] charBuffer = Converter.wcsToMbcs(getCodePage (), new char[] { ch }, false); + int val = charBuffer[0] & 0xFF; + /* Create a font context to iterate over each element in the font list */ + int[] buffer = new int[1]; + if (!OS.XmFontListInitFontContext(buffer, fontList)) { + SWT.error(SWT.ERROR_NO_HANDLES); + } + int context = buffer[0]; + XFontStruct fontStruct = new XFontStruct(); + XCharStruct charStruct = new XCharStruct(); + int fontListEntry; + int[] fontStructPtr = new int[1]; + int[] fontNamePtr = new int[1]; + /* Go through each entry in the font list. */ + while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) { + int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer); + if (buffer[0] == 0) { + OS.memmove(fontStruct, fontPtr, XFontStruct.sizeof); + /* FontList contains a single font */ + if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) { + /* Single byte fontStruct */ + if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) { + /* The font contains the character */ + OS.memmove(charStruct, fontStruct.per_char + ((val - fontStruct.min_char_or_byte2) * XCharStruct.sizeof), XCharStruct.sizeof); + if (charStruct.width != 0) { + OS.XmFontListFreeFontContext(context); + return charStruct.rbearing - charStruct.lbearing; + } + } + } else { + /* Double byte fontStruct */ + int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1; + int row = 0; + if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1; + int col = charBuffer[0] - fontStruct.min_char_or_byte2; + if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) { + /* The font contains the character */ + int offset = row * charsPerRow + col; + OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof); + if (charStruct.width != 0) { + OS.XmFontListFreeFontContext(context); + return charStruct.rbearing - charStruct.lbearing; + } + } + } + } else { + /* FontList contains a fontSet */ + int nFonts = OS.XFontsOfFontSet(fontPtr, fontStructPtr, fontNamePtr); + int [] fontStructs = new int[nFonts]; + OS.memmove(fontStructs, fontStructPtr[0], nFonts * 4); + /* Go through each fontStruct in the font set */ + for (int i = 0; i < nFonts; i++) { + OS.memmove(fontStruct, fontStructs[i], XFontStruct.sizeof); + if (fontStruct.min_byte1 == 0 && fontStruct.max_byte1 == 0) { + /* Single byte fontStruct */ + if (fontStruct.min_char_or_byte2 <= val && val <= fontStruct.max_char_or_byte2) { + /* The font contains the character */ + OS.memmove(charStruct, fontStruct.per_char + (val - fontStruct.min_char_or_byte2 * XCharStruct.sizeof), XCharStruct.sizeof); + if (charStruct.width != 0) { + OS.XmFontListFreeFontContext(context); + return charStruct.rbearing - charStruct.lbearing; + } + } + } else { + /* Double byte fontStruct */ + int charsPerRow = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1; + int row = 0; + if (charBuffer.length > 1) row = charBuffer[1] - fontStruct.min_byte1; + int col = charBuffer[0] - fontStruct.min_char_or_byte2; + if (row <= fontStruct.max_byte1 && col <= fontStruct.max_char_or_byte2) { + /* The font contains the character */ + int offset = row * charsPerRow + col; + OS.memmove(charStruct, fontStruct.per_char + offset * XCharStruct.sizeof, XCharStruct.sizeof); + if (charStruct.width != 0) { + OS.XmFontListFreeFontContext(context); + return charStruct.rbearing - charStruct.lbearing; + } + } + } + } + } + } + OS.XmFontListFreeFontContext(context); + return 0; +} /** * Returns the bounding rectangle of the receiver's clipping * region. If no clipping region is set, the return value @@ -1688,19 +1688,19 @@ public int getCharWidth(char ch) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public Rectangle getClipping() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int clipRgn = data.clipRgn;
- if (clipRgn == 0) {
- int[] width = new int[1]; int[] height = new int[1];
- int[] unused = new int[1];
- OS.XGetGeometry(data.display, data.drawable, unused, unused, unused, width, height, unused, unused);
- return new Rectangle(0, 0, width[0], height[0]);
- }
- XRectangle rect = new XRectangle();
- OS.XClipBox(clipRgn, rect);
- return new Rectangle(rect.x, rect.y, rect.width, rect.height);
-}
+public Rectangle getClipping() { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + int clipRgn = data.clipRgn; + if (clipRgn == 0) { + int[] width = new int[1]; int[] height = new int[1]; + int[] unused = new int[1]; + OS.XGetGeometry(data.display, data.drawable, unused, unused, unused, width, height, unused, unused); + return new Rectangle(0, 0, width[0], height[0]); + } + XRectangle rect = new XRectangle(); + OS.XClipBox(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. @@ -1714,28 +1714,28 @@ public Rectangle getClipping() { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void getClipping(Region region) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int hRegion = region.handle;
- int clipRgn = data.clipRgn;
- if (clipRgn == 0) {
- int[] width = new int[1]; int[] height = new int[1];
- int[] unused = new int[1];
- OS.XGetGeometry(data.display, data.drawable, unused, unused, unused, width, height, unused, unused);
- OS.XSubtractRegion (hRegion, hRegion, hRegion);
- XRectangle rect = new XRectangle();
- rect.x = 0; rect.y = 0;
- rect.width = (short)width[0]; rect.height = (short)height[0];
- OS.XUnionRectWithRegion(rect, hRegion, hRegion);
- return;
- }
- OS.XSubtractRegion (hRegion, hRegion, hRegion);
- OS.XUnionRegion (clipRgn, hRegion, hRegion);
-}
-String getCodePage () {
- return data.codePage;
-}
+public void getClipping(Region region) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + int hRegion = region.handle; + int clipRgn = data.clipRgn; + if (clipRgn == 0) { + int[] width = new int[1]; int[] height = new int[1]; + int[] unused = new int[1]; + OS.XGetGeometry(data.display, data.drawable, unused, unused, unused, width, height, unused, unused); + OS.XSubtractRegion (hRegion, hRegion, hRegion); + XRectangle rect = new XRectangle(); + rect.x = 0; rect.y = 0; + rect.width = (short)width[0]; rect.height = (short)height[0]; + OS.XUnionRectWithRegion(rect, hRegion, hRegion); + return; + } + OS.XSubtractRegion (hRegion, hRegion, hRegion); + OS.XUnionRegion (clipRgn, hRegion, hRegion); +} +String getCodePage () { + return data.codePage; +} /** * Returns the font currently being used by the receiver * to draw and measure text. @@ -1746,52 +1746,52 @@ String getCodePage () { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public Font getFont () {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return Font.motif_new(data.device, data.fontList);
-}
-int getFontHeight () {
- int fontList = data.fontList;
- /* Create a font context to iterate over each element in the font list */
- int [] buffer = new int [1];
- if (!OS.XmFontListInitFontContext (buffer, fontList)) {
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- int context = buffer [0];
-
- /* Values discovering during iteration */
- int height = 0;
- XFontStruct fontStruct = new XFontStruct ();
- int fontListEntry;
- int [] fontStructPtr = new int [1];
- int [] fontNamePtr = new int [1];
-
- /* Go through each entry in the font list. */
- while ((fontListEntry = OS.XmFontListNextEntry (context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer);
- if (buffer [0] == 0) {
- /* FontList contains a single font */
- OS.memmove (fontStruct, fontPtr, XFontStruct.sizeof);
- int fontHeight = fontStruct.ascent + fontStruct.descent;
- if (fontHeight > height) height = fontHeight;
- } else {
- /* FontList contains a fontSet */
- int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr);
- int [] fontStructs = new int [nFonts];
- OS.memmove (fontStructs, fontStructPtr [0], nFonts * 4);
-
- /* Go through each fontStruct in the font set */
- for (int i=0; i<nFonts; i++) {
- OS.memmove (fontStruct, fontStructs[i], XFontStruct.sizeof);
- int fontHeight = fontStruct.ascent + fontStruct.descent;
- if (fontHeight > height) height = fontHeight;
- }
- }
- }
-
- OS.XmFontListFreeFontContext (context);
- return height;
-}
+public Font getFont () { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return Font.motif_new(data.device, data.fontList); +} +int getFontHeight () { + int fontList = data.fontList; + /* Create a font context to iterate over each element in the font list */ + int [] buffer = new int [1]; + if (!OS.XmFontListInitFontContext (buffer, fontList)) { + SWT.error(SWT.ERROR_NO_HANDLES); + } + int context = buffer [0]; + + /* Values discovering during iteration */ + int height = 0; + XFontStruct fontStruct = new XFontStruct (); + int fontListEntry; + int [] fontStructPtr = new int [1]; + int [] fontNamePtr = new int [1]; + + /* Go through each entry in the font list. */ + while ((fontListEntry = OS.XmFontListNextEntry (context)) != 0) { + int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer); + if (buffer [0] == 0) { + /* FontList contains a single font */ + OS.memmove (fontStruct, fontPtr, XFontStruct.sizeof); + int fontHeight = fontStruct.ascent + fontStruct.descent; + if (fontHeight > height) height = fontHeight; + } else { + /* FontList contains a fontSet */ + int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr); + int [] fontStructs = new int [nFonts]; + OS.memmove (fontStructs, fontStructPtr [0], nFonts * 4); + + /* Go through each fontStruct in the font set */ + for (int i=0; i<nFonts; i++) { + OS.memmove (fontStruct, fontStructs[i], XFontStruct.sizeof); + int fontHeight = fontStruct.ascent + fontStruct.descent; + if (fontHeight > height) height = fontHeight; + } + } + } + + OS.XmFontListFreeFontContext (context); + return height; +} /** * Returns a FontMetrics which contains information * about the font currently being used by the receiver @@ -1803,158 +1803,158 @@ int getFontHeight () { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public FontMetrics getFontMetrics() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int xDisplay = data.display;
- int fontList = data.fontList;
- /* Create a font context to iterate over each element in the font list */
- int[] buffer = new int[1];
- if (!OS.XmFontListInitFontContext(buffer, fontList)) {
- SWT.error(SWT.ERROR_NO_HANDLES);
- }
- int context = buffer[0];
- /* Values discovering during iteration */
- int ascent = 0;
- int descent = 0;
- int averageCharWidth = 0, numAverageCharWidth = 0;
- int leading = 0;
- int height = 0;
-
- XFontStruct fontStruct = new XFontStruct();
- int fontListEntry;
- int[] fontStructPtr = new int[1];
- int[] fontNamePtr = new int[1];
- /* Go through each entry in the font list. */
- while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer);
- if (buffer[0] == 0) {
- /* FontList contains a single font */
- OS.memmove(fontStruct, fontPtr, XFontStruct.sizeof);
- ascent = ascent > fontStruct.max_bounds_ascent ? ascent : fontStruct.max_bounds_ascent;
- descent = descent > fontStruct.descent ? descent : fontStruct.descent;
- int tmp = fontStruct.ascent + fontStruct.descent;
- height = height > tmp ? height : tmp;
- tmp = fontStruct.ascent - fontStruct.max_bounds_ascent;
- leading = leading > tmp ? leading : tmp;
- /* Calculate average character width */
- int propPtr = fontStruct.properties;
- for (int i = 0; i < fontStruct.n_properties; i++) {
- /* Reef through properties looking for XAFONT */
- int[] prop = new int[2];
- OS.memmove(prop, propPtr, 8);
- if (prop[0] == OS.XA_FONT) {
- /* Found it, prop[1] points to the string */
- StringBuffer stringBuffer = new StringBuffer();
- int ptr = OS.XmGetAtomName(xDisplay, prop[1]);
- int strPtr = ptr;
- byte[] c = new byte[1];
- OS.memmove(c, strPtr, 1);
- while (c[0] != 0) {
- stringBuffer.append((char)c[0]);
- strPtr++;
- OS.memmove(c, strPtr, 1);
- }
- String xlfd = stringBuffer.toString().toLowerCase();
- int avg = FontData.motif_new(xlfd).averageWidth / 10;
- OS.XtFree(ptr);
- if (avg == 0) {
- /*
- * Not all fonts have average character width encoded
- * in the xlfd. This one doesn't, so do it the hard
- * way by averaging all the character widths.
+public FontMetrics getFontMetrics() { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + int xDisplay = data.display; + int fontList = data.fontList; + /* Create a font context to iterate over each element in the font list */ + int[] buffer = new int[1]; + if (!OS.XmFontListInitFontContext(buffer, fontList)) { + SWT.error(SWT.ERROR_NO_HANDLES); + } + int context = buffer[0]; + /* Values discovering during iteration */ + int ascent = 0; + int descent = 0; + int averageCharWidth = 0, numAverageCharWidth = 0; + int leading = 0; + int height = 0; + + XFontStruct fontStruct = new XFontStruct(); + int fontListEntry; + int[] fontStructPtr = new int[1]; + int[] fontNamePtr = new int[1]; + /* Go through each entry in the font list. */ + while ((fontListEntry = OS.XmFontListNextEntry(context)) != 0) { + int fontPtr = OS.XmFontListEntryGetFont(fontListEntry, buffer); + if (buffer[0] == 0) { + /* FontList contains a single font */ + OS.memmove(fontStruct, fontPtr, XFontStruct.sizeof); + ascent = ascent > fontStruct.max_bounds_ascent ? ascent : fontStruct.max_bounds_ascent; + descent = descent > fontStruct.descent ? descent : fontStruct.descent; + int tmp = fontStruct.ascent + fontStruct.descent; + height = height > tmp ? height : tmp; + tmp = fontStruct.ascent - fontStruct.max_bounds_ascent; + leading = leading > tmp ? leading : tmp; + /* Calculate average character width */ + int propPtr = fontStruct.properties; + for (int i = 0; i < fontStruct.n_properties; i++) { + /* Reef through properties looking for XAFONT */ + int[] prop = new int[2]; + OS.memmove(prop, propPtr, 8); + if (prop[0] == OS.XA_FONT) { + /* Found it, prop[1] points to the string */ + StringBuffer stringBuffer = new StringBuffer(); + int ptr = OS.XmGetAtomName(xDisplay, prop[1]); + int strPtr = ptr; + byte[] c = new byte[1]; + OS.memmove(c, strPtr, 1); + while (c[0] != 0) { + stringBuffer.append((char)c[0]); + strPtr++; + OS.memmove(c, strPtr, 1); + } + String xlfd = stringBuffer.toString().toLowerCase(); + int avg = FontData.motif_new(xlfd).averageWidth / 10; + OS.XtFree(ptr); + if (avg == 0) { + /* + * Not all fonts have average character width encoded + * in the xlfd. This one doesn't, so do it the hard + * way by averaging all the character widths. */ - int sum = 0, count = 0;
- int cols = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
- int perCharPtr = fontStruct.per_char;
- XCharStruct struct = new XCharStruct();
- for (int index = 0; index < cols; index++) {
- OS.memmove(struct, perCharPtr + (index * XCharStruct.sizeof), XCharStruct.sizeof);
- int w = struct.width;
- if (w != 0) {
- sum += w;
- count++;
- }
- }
- averageCharWidth += sum / count;
- } else {
- /* Average character width was in the xlfd */
- averageCharWidth += avg;
- }
- numAverageCharWidth++;
- break;
- }
- propPtr += 8;
- }
- }
- else {
- /* FontList contains a fontSet */
- int nFonts = OS.XFontsOfFontSet(fontPtr, fontStructPtr, fontNamePtr);
- int [] fontStructs = new int[nFonts];
- OS.memmove(fontStructs, fontStructPtr[0], nFonts * 4);
- /* Go through each fontStruct in the font set */
- for (int i = 0; i < nFonts; i++) {
- OS.memmove(fontStruct, fontStructs[i], XFontStruct.sizeof);
- ascent = ascent > fontStruct.max_bounds_ascent ? ascent : fontStruct.max_bounds_ascent;
- descent = descent > fontStruct.descent ? descent : fontStruct.descent;
- int tmp = fontStruct.ascent + fontStruct.descent;
- height = height > tmp ? height : tmp;
- tmp = fontStruct.ascent - fontStruct.max_bounds_ascent;
- leading = leading > tmp ? leading : tmp;
- /* Calculate average character width */
- int propPtr = fontStruct.properties;
- for (int j = 0; j < fontStruct.n_properties; j++) {
- /* Reef through properties looking for XAFONT */
- int[] prop = new int[2];
- OS.memmove(prop, propPtr, 8);
- if (prop[0] == OS.XA_FONT) {
- /* Found it, prop[1] points to the string */
- StringBuffer stringBuffer = new StringBuffer();
- int ptr = OS.XmGetAtomName(xDisplay, prop[1]);
- int strPtr = ptr;
- byte[] c = new byte[1];
- OS.memmove(c, strPtr, 1);
- while (c[0] != 0) {
- stringBuffer.append((char)c[0]);
- strPtr++;
- OS.memmove(c, strPtr, 1);
- }
- String xlfd = stringBuffer.toString().toLowerCase();
- int avg = FontData.motif_new(xlfd).averageWidth / 10;
- OS.XFree(ptr);
- if (avg == 0) {
- /*
- * Not all fonts have average character width encoded
- * in the xlfd. This one doesn't, so do it the hard
- * way by averaging all the character widths.
+ int sum = 0, count = 0; + int cols = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1; + int perCharPtr = fontStruct.per_char; + XCharStruct struct = new XCharStruct(); + for (int index = 0; index < cols; index++) { + OS.memmove(struct, perCharPtr + (index * XCharStruct.sizeof), XCharStruct.sizeof); + int w = struct.width; + if (w != 0) { + sum += w; + count++; + } + } + averageCharWidth += sum / count; + } else { + /* Average character width was in the xlfd */ + averageCharWidth += avg; + } + numAverageCharWidth++; + break; + } + propPtr += 8; + } + } + else { + /* FontList contains a fontSet */ + int nFonts = OS.XFontsOfFontSet(fontPtr, fontStructPtr, fontNamePtr); + int [] fontStructs = new int[nFonts]; + OS.memmove(fontStructs, fontStructPtr[0], nFonts * 4); + /* Go through each fontStruct in the font set */ + for (int i = 0; i < nFonts; i++) { + OS.memmove(fontStruct, fontStructs[i], XFontStruct.sizeof); + ascent = ascent > fontStruct.max_bounds_ascent ? ascent : fontStruct.max_bounds_ascent; + descent = descent > fontStruct.descent ? descent : fontStruct.descent; + int tmp = fontStruct.ascent + fontStruct.descent; + height = height > tmp ? height : tmp; + tmp = fontStruct.ascent - fontStruct.max_bounds_ascent; + leading = leading > tmp ? leading : tmp; + /* Calculate average character width */ + int propPtr = fontStruct.properties; + for (int j = 0; j < fontStruct.n_properties; j++) { + /* Reef through properties looking for XAFONT */ + int[] prop = new int[2]; + OS.memmove(prop, propPtr, 8); + if (prop[0] == OS.XA_FONT) { + /* Found it, prop[1] points to the string */ + StringBuffer stringBuffer = new StringBuffer(); + int ptr = OS.XmGetAtomName(xDisplay, prop[1]); + int strPtr = ptr; + byte[] c = new byte[1]; + OS.memmove(c, strPtr, 1); + while (c[0] != 0) { + stringBuffer.append((char)c[0]); + strPtr++; + OS.memmove(c, strPtr, 1); + } + String xlfd = stringBuffer.toString().toLowerCase(); + int avg = FontData.motif_new(xlfd).averageWidth / 10; + OS.XFree(ptr); + if (avg == 0) { + /* + * Not all fonts have average character width encoded + * in the xlfd. This one doesn't, so do it the hard + * way by averaging all the character widths. */ - int sum = 0, count = 0;
- int cols = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1;
- int perCharPtr = fontStruct.per_char;
- XCharStruct struct = new XCharStruct();
- for (int index = 0; index < cols; index++) {
- OS.memmove(struct, perCharPtr + (index * XCharStruct.sizeof), XCharStruct.sizeof);
- int w = struct.width;
- if (w != 0) {
- sum += w;
- count++;
- }
- }
- averageCharWidth += sum / count;
- } else {
- /* Average character width was in the xlfd */
- averageCharWidth += avg;
- }
- numAverageCharWidth++;
- break;
- }
- propPtr += 8;
- }
- }
- }
- }
- OS.XmFontListFreeFontContext(context);
- return FontMetrics.motif_new(ascent, descent, averageCharWidth / numAverageCharWidth, leading, height);
-}
+ int sum = 0, count = 0; + int cols = fontStruct.max_char_or_byte2 - fontStruct.min_char_or_byte2 + 1; + int perCharPtr = fontStruct.per_char; + XCharStruct struct = new XCharStruct(); + for (int index = 0; index < cols; index++) { + OS.memmove(struct, perCharPtr + (index * XCharStruct.sizeof), XCharStruct.sizeof); + int w = struct.width; + if (w != 0) { + sum += w; + count++; + } + } + averageCharWidth += sum / count; + } else { + /* Average character width was in the xlfd */ + averageCharWidth += avg; + } + numAverageCharWidth++; + break; + } + propPtr += 8; + } + } + } + } + OS.XmFontListFreeFontContext(context); + return FontMetrics.motif_new(ascent, descent, averageCharWidth / numAverageCharWidth, leading, height); +} /** * Returns the receiver's foreground color. * @@ -1964,17 +1964,17 @@ public FontMetrics getFontMetrics() { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public Color getForeground() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int xDisplay = data.display;
- XGCValues values = new XGCValues();
- OS.XGetGCValues(xDisplay, handle, OS.GCForeground, values);
- XColor xColor = new XColor();
- xColor.pixel = values.foreground;
- OS.XQueryColor(xDisplay,data.colormap,xColor);
- return Color.motif_new(data.device, xColor);
-
-}
+public Color getForeground() { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + int xDisplay = data.display; + XGCValues values = new XGCValues(); + OS.XGetGCValues(xDisplay, handle, OS.GCForeground, values); + XColor xColor = new XColor(); + xColor.pixel = values.foreground; + OS.XQueryColor(xDisplay,data.colormap,xColor); + return Color.motif_new(data.device, xColor); + +} /** * Returns the receiver's line style, which will be one * of the constants <code>SWT.LINE_SOLID</code>, <code>SWT.LINE_DASH</code>, @@ -1987,10 +1987,10 @@ public Color getForeground() { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public int getLineStyle() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.lineStyle;
-}
+public int getLineStyle() { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return data.lineStyle; +} /** * Returns the width that will be used when drawing lines * for all of the figure drawing operations (that is, @@ -2003,12 +2003,12 @@ public int getLineStyle() { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public int getLineWidth() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- XGCValues values = new XGCValues();
- OS.XGetGCValues(data.display, handle, OS.GCLineWidth, values);
- return values.line_width;
-}
+public int getLineWidth() { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + XGCValues values = new XGCValues(); + OS.XGetGCValues(data.display, handle, OS.GCLineWidth, 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 @@ -2023,12 +2023,12 @@ public int getLineWidth() { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public boolean getXORMode() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- XGCValues values = new XGCValues ();
- OS.XGetGCValues (data.display, handle, OS.GCFunction, values);
- return values.function == OS.GXxor;
-}
+public boolean getXORMode() { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + XGCValues values = new XGCValues (); + OS.XGetGCValues (data.display, handle, OS.GCFunction, values); + return values.function == OS.GXxor; +} /** * Returns an integer hash code for the receiver. Any two * objects which return <code>true</code> when passed to @@ -2043,29 +2043,29 @@ public boolean getXORMode() { * * @see #equals */ -public int hashCode () {
- return handle;
-}
-void init(Drawable drawable, GCData data, int xGC) {
- int xDisplay = data.display;
- int foreground = data.foreground;
- if (foreground != -1) OS.XSetForeground (xDisplay, xGC, foreground);
- int background = data.background;
- if (background != -1) OS.XSetBackground (xDisplay, xGC, background);
- Image image = data.image;
- if (image != null) {
- image.memGC = this;
- /*
- * The transparent pixel mask might change when drawing on
- * the image. Destroy it so that it is regenerated when
- * necessary.
- */
- if (image.transparentPixel != -1) image.destroyMask();
- }
- this.drawable = drawable;
- this.data = data;
- handle = xGC;
-}
+public int hashCode () { + return handle; +} +void init(Drawable drawable, GCData data, int xGC) { + int xDisplay = data.display; + int foreground = data.foreground; + if (foreground != -1) OS.XSetForeground (xDisplay, xGC, foreground); + int background = data.background; + if (background != -1) OS.XSetBackground (xDisplay, xGC, background); + Image image = data.image; + if (image != null) { + image.memGC = this; + /* + * The transparent pixel mask might change when drawing on + * the image. Destroy it so that it is regenerated when + * necessary. + */ + if (image.transparentPixel != -1) image.destroyMask(); + } + this.drawable = drawable; + this.data = data; + handle = xGC; +} /** * Returns <code>true</code> if the receiver has a clipping * region set into it, and <code>false</code> otherwise. @@ -2080,10 +2080,10 @@ void init(Drawable drawable, GCData data, int xGC) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public boolean isClipped() {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return data.clipRgn != 0;
-}
+public boolean isClipped() { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return data.clipRgn != 0; +} /** * Returns <code>true</code> if the GC has been disposed, * and <code>false</code> otherwise. @@ -2094,15 +2094,15 @@ public boolean isClipped() { * * @return <code>true</code> when the GC is disposed and <code>false</code> otherwise */ -public boolean isDisposed() {
- return handle == 0;
-}
-public static GC motif_new(Drawable drawable, GCData data) {
- GC gc = new GC();
- int xGC = drawable.internal_new_GC(data);
- gc.init(drawable, data, xGC);
- return gc;
-}
+public boolean isDisposed() { + return handle == 0; +} +public static GC motif_new(Drawable drawable, GCData data) { + GC gc = new GC(); + int xGC = drawable.internal_new_GC(data); + gc.init(drawable, data, xGC); + return gc; +} /** * Sets the background color. The background color is used * for fill operations and as the background color when text @@ -2118,12 +2118,12 @@ public static GC motif_new(Drawable drawable, GCData data) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void setBackground (Color color) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.XSetBackground(data.display, handle, color.handle.pixel);
-}
+public void setBackground (Color color) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + OS.XSetBackground(data.display, handle, color.handle.pixel); +} /** * Sets the area of the receiver which can be changed * by drawing operations to the rectangular area specified @@ -2138,20 +2138,20 @@ public void setBackground (Color color) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void setClipping (int x, int y, int width, int height) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int clipRgn = data.clipRgn;
- if (clipRgn == 0) {
- data.clipRgn = clipRgn = OS.XCreateRegion ();
- } else {
- OS.XSubtractRegion (clipRgn, clipRgn, clipRgn);
- }
- XRectangle rect = new XRectangle ();
- rect.x = (short) x; rect.y = (short) y;
- rect.width = (short) width; rect.height = (short) height;
- OS.XSetClipRectangles (data.display, handle, 0, 0, rect, 1, OS.Unsorted);
- OS.XUnionRectWithRegion(rect, clipRgn, clipRgn);
-}
+public void setClipping (int x, int y, int width, int height) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + int clipRgn = data.clipRgn; + if (clipRgn == 0) { + data.clipRgn = clipRgn = OS.XCreateRegion (); + } else { + OS.XSubtractRegion (clipRgn, clipRgn, clipRgn); + } + XRectangle rect = new XRectangle (); + rect.x = (short) x; rect.y = (short) y; + rect.width = (short) width; rect.height = (short) height; + OS.XSetClipRectangles (data.display, handle, 0, 0, rect, 1, OS.Unsorted); + OS.XUnionRectWithRegion(rect, clipRgn, clipRgn); +} /** * Sets the area of the receiver which can be changed * by drawing operations to the rectangular area specified @@ -2163,19 +2163,19 @@ public void setClipping (int x, int y, int width, int height) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void setClipping (Rectangle rect) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) {
- OS.XSetClipMask (data.display, handle, OS.None);
- int clipRgn = data.clipRgn;
- if (clipRgn != 0) {
- OS.XDestroyRegion (clipRgn);
- data.clipRgn = 0;
- }
- return;
- }
- setClipping (rect.x, rect.y, rect.width, rect.height);
-}
+public void setClipping (Rectangle rect) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (rect == null) { + OS.XSetClipMask (data.display, handle, OS.None); + int clipRgn = data.clipRgn; + if (clipRgn != 0) { + OS.XDestroyRegion (clipRgn); + data.clipRgn = 0; + } + return; + } + 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 @@ -2187,25 +2187,25 @@ public void setClipping (Rectangle rect) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void setClipping (Region region) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int clipRgn = data.clipRgn;
- if (region == null) {
- OS.XSetClipMask (data.display, handle, OS.None);
- if (clipRgn != 0) {
- OS.XDestroyRegion (clipRgn);
- data.clipRgn = 0;
- }
- } else {
- if (clipRgn == 0) {
- data.clipRgn = clipRgn = OS.XCreateRegion ();
- } else {
- OS.XSubtractRegion (clipRgn, clipRgn, clipRgn);
- }
- OS.XUnionRegion (region.handle, clipRgn, clipRgn);
- OS.XSetRegion (data.display, handle, region.handle);
- }
-}
+public void setClipping (Region region) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + int clipRgn = data.clipRgn; + if (region == null) { + OS.XSetClipMask (data.display, handle, OS.None); + if (clipRgn != 0) { + OS.XDestroyRegion (clipRgn); + data.clipRgn = 0; + } + } else { + if (clipRgn == 0) { + data.clipRgn = clipRgn = OS.XCreateRegion (); + } else { + OS.XSubtractRegion (clipRgn, clipRgn, clipRgn); + } + OS.XUnionRegion (region.handle, clipRgn, clipRgn); + OS.XSetRegion (data.display, handle, region.handle); + } +} /** * Sets the font which will be used by the receiver * to draw and measure text to the argument. If the @@ -2222,14 +2222,14 @@ public void setClipping (Region region) { * </ul> */ public void setFont (Font font) { - if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
+ if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); if (font == null) font = data.device.systemFont; - if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- data.fontList = font.handle;
- data.codePage = font.codePage;
- if (data.renderTable != 0) OS.XmRenderTableFree(data.renderTable);
- data.renderTable = 0;
-}
+ if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + data.fontList = font.handle; + data.codePage = font.codePage; + if (data.renderTable != 0) OS.XmRenderTableFree(data.renderTable); + data.renderTable = 0; +} /** * Sets the foreground color. The foreground color is used * for drawing operations including when text is drawn. @@ -2244,12 +2244,12 @@ public void setFont (Font font) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void setForeground (Color color) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.XSetForeground(data.display, handle, color.handle.pixel);
-}
+public void setForeground (Color color) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + OS.XSetForeground(data.display, handle, color.handle.pixel); +} /** * 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>, @@ -2262,33 +2262,33 @@ public void setForeground (Color color) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void setLineStyle(int lineStyle) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int xDisplay = data.display;
- switch (lineStyle) {
- case SWT.LINE_SOLID:
- data.lineStyle = lineStyle;
- OS.XSetLineAttributes(xDisplay, handle, 0, OS.LineSolid, OS.CapButt, OS.JoinMiter);
- return;
- case SWT.LINE_DASH:
- OS.XSetDashes(xDisplay,handle,0, new byte[] {6, 2},2);
- break;
- case SWT.LINE_DOT:
- OS.XSetDashes(xDisplay,handle,0, new byte[] {3, 1},2);
- break;
- case SWT.LINE_DASHDOT:
- OS.XSetDashes(xDisplay,handle,0, new byte[] {6, 2, 3, 1},4);
- break;
- case SWT.LINE_DASHDOTDOT:
- OS.XSetDashes(xDisplay,handle,0, new byte[] {6, 2, 3, 1, 3, 1},6);
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- data.lineStyle = lineStyle;
- OS.XSetLineAttributes(xDisplay, handle, 0, OS.LineOnOffDash, OS.CapButt, OS.JoinMiter);
-
-}
+public void setLineStyle(int lineStyle) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + int xDisplay = data.display; + switch (lineStyle) { + case SWT.LINE_SOLID: + data.lineStyle = lineStyle; + OS.XSetLineAttributes(xDisplay, handle, 0, OS.LineSolid, OS.CapButt, OS.JoinMiter); + return; + case SWT.LINE_DASH: + OS.XSetDashes(xDisplay,handle,0, new byte[] {6, 2},2); + break; + case SWT.LINE_DOT: + OS.XSetDashes(xDisplay,handle,0, new byte[] {3, 1},2); + break; + case SWT.LINE_DASHDOT: + OS.XSetDashes(xDisplay,handle,0, new byte[] {6, 2, 3, 1},4); + break; + case SWT.LINE_DASHDOTDOT: + OS.XSetDashes(xDisplay,handle,0, new byte[] {6, 2, 3, 1, 3, 1},6); + break; + default: + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + data.lineStyle = lineStyle; + OS.XSetLineAttributes(xDisplay, handle, 0, OS.LineOnOffDash, OS.CapButt, OS.JoinMiter); + +} /** * Sets the width that will be used when drawing lines * for all of the figure drawing operations (that is, @@ -2301,14 +2301,14 @@ public void setLineStyle(int lineStyle) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void setLineWidth(int width) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (data.lineStyle == SWT.LINE_SOLID) {
- OS.XSetLineAttributes(data.display, handle, width, OS.LineSolid, OS.CapButt, OS.JoinMiter);
- } else {
- OS.XSetLineAttributes(data.display, handle, width, OS.LineDoubleDash, OS.CapButt, OS.JoinMiter);
- }
-}
+public void setLineWidth(int width) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (data.lineStyle == SWT.LINE_SOLID) { + OS.XSetLineAttributes(data.display, handle, width, OS.LineSolid, OS.CapButt, OS.JoinMiter); + } else { + OS.XSetLineAttributes(data.display, handle, width, OS.LineDoubleDash, OS.CapButt, OS.JoinMiter); + } +} /** * If the argument is <code>true</code>, puts the receiver * in a drawing mode where the resulting color in the destination @@ -2323,13 +2323,13 @@ public void setLineWidth(int width) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void setXORMode(boolean xor) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (xor)
- OS.XSetFunction(data.display, handle, OS.GXxor);
- else
- OS.XSetFunction(data.display, handle, OS.GXcopy);
-}
+public void setXORMode(boolean xor) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (xor) + OS.XSetFunction(data.display, handle, OS.GXxor); + else + OS.XSetFunction(data.display, handle, OS.GXcopy); +} /** * Returns the extent of the given string. No tab * expansion or carriage return processing will be performed. @@ -2349,32 +2349,32 @@ public void setXORMode(boolean xor) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public Point stringExtent(String string) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (string.length () == 0) return new Point(0, getFontHeight());
- byte[] buffer = Converter.wcsToMbcs(getCodePage (), string, true);
- int xmString = OS.XmStringCreate(buffer, OS.XmFONTLIST_DEFAULT_TAG);
- int fontList = data.fontList;
- int width = OS.XmStringWidth(fontList, xmString);
- int height = OS.XmStringHeight(fontList, xmString);
- OS.XmStringFree(xmString);
- return new Point(width, height);
-}
-char stripMnemonic(char[] text) {
- char mnemonic=0;
- int i=0, j=0;
- while (i < text.length) {
- if ((text [j++] = text [i++]) == '&') {
- if (i == text.length) {continue;}
- if (text [i] == '&') {i++; continue;}
- if (mnemonic == 0) mnemonic = text [i];
- j--;
- }
- }
- while (j < text.length) text [j++] = 0;
- return mnemonic;
-}
+public Point stringExtent(String string) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (string.length () == 0) return new Point(0, getFontHeight()); + byte[] buffer = Converter.wcsToMbcs(getCodePage (), string, true); + int xmString = OS.XmStringCreate(buffer, OS.XmFONTLIST_DEFAULT_TAG); + int fontList = data.fontList; + int width = OS.XmStringWidth(fontList, xmString); + int height = OS.XmStringHeight(fontList, xmString); + OS.XmStringFree(xmString); + return new Point(width, height); +} +char stripMnemonic(char[] text) { + char mnemonic=0; + int i=0, j=0; + while (i < text.length) { + if ((text [j++] = text [i++]) == '&') { + if (i == text.length) {continue;} + if (text [i] == '&') {i++; continue;} + if (mnemonic == 0) mnemonic = text [i]; + j--; + } + } + while (j < text.length) text [j++] = 0; + return mnemonic; +} /** * Returns the extent of the given string. Tab expansion and * carriage return processing are performed. @@ -2394,71 +2394,71 @@ char stripMnemonic(char[] text) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public Point textExtent(String string) {
- return textExtent(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB);
-}
-/**
- * Returns the extent of the given string. Tab expansion, line
- * delimiter and mnemonic processing are performed according to
- * the specified flags, which can be a combination of:
- * <dl>
- * <dt><b>DRAW_DELIMITER</b></dt>
- * <dd>draw multiple lines</dd>
- * <dt><b>DRAW_TAB</b></dt>
- * <dd>expand tabs</dd>
- * <dt><b>DRAW_MNEMONIC</b></dt>
- * <dd>underline the mnemonic character</dd>
- * <dt><b>DRAW_TRANSPARENT</b></dt>
- * <dd>transparent background</dd>
- * </dl>
- * <p>
- * The <em>extent</em> of a string is the width and height of
- * the rectangular area it would cover if drawn in a particular
- * font (in this case, the current font in the receiver).
- * </p>
- *
- * @param string the string to measure
- * @param flags the flags 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) { + return textExtent(string, SWT.DRAW_DELIMITER | SWT.DRAW_TAB); +} +/** + * Returns the extent of the given string. Tab expansion, line + * delimiter and mnemonic processing are performed according to + * the specified flags, which can be a combination of: + * <dl> + * <dt><b>DRAW_DELIMITER</b></dt> + * <dd>draw multiple lines</dd> + * <dt><b>DRAW_TAB</b></dt> + * <dd>expand tabs</dd> + * <dt><b>DRAW_MNEMONIC</b></dt> + * <dd>underline the mnemonic character</dd> + * <dt><b>DRAW_TRANSPARENT</b></dt> + * <dd>transparent background</dd> + * </dl> + * <p> + * The <em>extent</em> of a string is the width and height of + * the rectangular area it would cover if drawn in a particular + * font (in this case, the current font in the receiver). + * </p> + * + * @param string the string to measure + * @param flags the flags 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) {
- if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (string.length () == 0) return new Point(0, getFontHeight());
- if (data.renderTable == 0) createRenderTable();
- int renderTable = data.renderTable;
-
- int tableLength = 0;
- Device device = data.device;
- int[] parseTable = new int[2];
- char[] text = new char[string.length()];
- string.getChars(0, text.length, text, 0);
- if ((flags & SWT.DRAW_DELIMITER) != 0) parseTable[tableLength++] = device.crMapping;
- if ((flags & SWT.DRAW_TAB) != 0) parseTable[tableLength++] = device.tabMapping;
- if ((flags & SWT.DRAW_MNEMONIC) != 0) stripMnemonic(text);
-
- byte[] buffer = Converter.wcsToMbcs(getCodePage(), text, true);
- int xmString = OS.XmStringParseText(buffer, 0, OS.XmFONTLIST_DEFAULT_TAG, OS.XmCHARSET_TEXT, parseTable, tableLength, 0);
- int width = OS.XmStringWidth(renderTable, xmString);
- int height = OS.XmStringHeight(renderTable, xmString);
- OS.XmStringFree(xmString);
- return new Point(width, height);
-}
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
+public Point textExtent(String string, int flags) { + if (handle == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (string == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (string.length () == 0) return new Point(0, getFontHeight()); + if (data.renderTable == 0) createRenderTable(); + int renderTable = data.renderTable; + + int tableLength = 0; + Device device = data.device; + int[] parseTable = new int[2]; + char[] text = new char[string.length()]; + string.getChars(0, text.length, text, 0); + if ((flags & SWT.DRAW_DELIMITER) != 0) parseTable[tableLength++] = device.crMapping; + if ((flags & SWT.DRAW_TAB) != 0) parseTable[tableLength++] = device.tabMapping; + if ((flags & SWT.DRAW_MNEMONIC) != 0) stripMnemonic(text); + + byte[] buffer = Converter.wcsToMbcs(getCodePage(), text, true); + int xmString = OS.XmStringParseText(buffer, 0, OS.XmFONTLIST_DEFAULT_TAG, OS.XmCHARSET_TEXT, parseTable, tableLength, 0); + int width = OS.XmStringWidth(renderTable, xmString); + int height = OS.XmStringHeight(renderTable, xmString); + OS.XmStringFree(xmString); + return new Point(width, height); +} +/** + * Returns a string containing a concise, human-readable + * description of the receiver. + * + * @return a string representation of the receiver */ -public String toString () {
- if (isDisposed()) return "GC {*DISPOSED*}";
- return "GC {" + handle + "}";
-}
-}
+public String toString () { + if (isDisposed()) return "GC {*DISPOSED*}"; + return "GC {" + handle + "}"; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GCData.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GCData.java index 4fb1992908..24a3018664 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GCData.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/GCData.java @@ -1,14 +1,14 @@ -package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.*; + /** * Instances of this class are descriptions of GCs in terms * of unallocated platform-specific data fields. @@ -21,17 +21,17 @@ import org.eclipse.swt.*; * * @private */ -public final class GCData {
- public Device device;
- public Image image;
- public int display;
- public int drawable;
- public int foreground = -1;
- public int background = -1;
- public int fontList;
- public String codePage;
- public int colormap;
- public int clipRgn;
- public int lineStyle = SWT.LINE_SOLID;
- public int renderTable;
+public final class GCData { + public Device device; + public Image image; + public int display; + public int drawable; + public int foreground = -1; + public int background = -1; + public int fontList; + public String codePage; + public int colormap; + public int clipRgn; + public int lineStyle = SWT.LINE_SOLID; + public int renderTable; } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java index 351184f934..3016d74a47 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Image.java @@ -1,16 +1,16 @@ -package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import java.io.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import java.io.*; + /** * Instances of this class are graphics which have been prepared * for display on a specific device. That is, they are ready @@ -58,62 +58,62 @@ import java.io.*; * @see ImageData * @see ImageLoader */ -public final class Image implements Drawable {
+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 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 pixmap; + + /** + * The handle to the OS mask resource. + * Warning: This field is platform dependent. */ - public int mask;
-
- /**
- * The device where this image was created.
+ public int mask; + + /** + * The device where this image was created. */ - Device device;
-
- /**
- * specifies the transparent pixel
- * (Warning: This field is platform dependent)
+ 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.
+ 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.
+ 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.
+ 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.
+ int alpha = -1; + + /** + * Specifies the default scanline padding. + * Warning: This field is platform dependent. */ - static final int DEFAULT_SCANLINE_PAD = 4;
-
-Image() {
-}
+ static final int DEFAULT_SCANLINE_PAD = 4; + +Image() { +} /** * Constructs an empty instance of this class with the * specified width and height. The result may be drawn upon @@ -144,12 +144,12 @@ Image() { * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> * </ul> */ -public Image(Device device, int width, int height) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, width, height);
- if (device.tracking) device.new_Object(this);
-}
+public Image(Device device, int width, int height) { + if (device == null) device = Device.getDevice(); + if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + init(device, width, height); + if (device.tracking) device.new_Object(this); +} /** * Constructs a new instance of this class based on the * provided image, with an appearance that varies depending @@ -181,280 +181,280 @@ public Image(Device device, int width, int height) { * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> * </ul> */ -public Image(Device device, Image srcImage, int flag) {
- 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);
- int xDisplay = device.xDisplay;
- this.type = srcImage.type;
- this.mask = 0;
- int[] unused = new int[1];
- int[] w = new int[1];
- int[] h = new int[1];
- OS.XGetGeometry(xDisplay, srcImage.pixmap, unused, unused, unused, w, h, unused, unused);
- int width = w[0];
- int height = h[0];
- int drawable = OS.XDefaultRootWindow(xDisplay);
- /* Don't create the mask here if flag is SWT.IMAGE_GRAY. See below.*/
- if (flag != SWT.IMAGE_GRAY && (srcImage.mask != 0 || srcImage.transparentPixel != -1)) {
- /* Generate the mask if necessary. */
- if (srcImage.transparentPixel != -1) srcImage.createMask();
- int mask = OS.XCreatePixmap(xDisplay, drawable, width, height, 1);
- int gc = OS.XCreateGC(xDisplay, mask, 0, null);
- OS.XCopyArea(xDisplay, srcImage.mask, mask, gc, 0, 0, width, height, 0, 0);
- OS.XFreeGC(xDisplay, gc);
- this.mask = mask;
- /* Destroy the image mask if the there is a GC created on the image */
- if (srcImage.transparentPixel != -1 && srcImage.memGC != null) srcImage.destroyMask();
- }
- switch (flag) {
- case SWT.IMAGE_COPY:
- int[] depth = new int[1];
- OS.XGetGeometry(xDisplay, srcImage.pixmap, unused, unused, unused, unused, unused, unused, depth);
- int pixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, depth[0]);
- int gc = OS.XCreateGC(xDisplay, pixmap, 0, null);
- OS.XCopyArea(xDisplay, srcImage.pixmap, pixmap, gc, 0, 0, width, height, 0, 0);
- OS.XFreeGC(xDisplay, gc);
- this.pixmap = pixmap;
- transparentPixel = srcImage.transparentPixel;
- alpha = srcImage.alpha;
- if (srcImage.alphaData != null) {
- alphaData = new byte[srcImage.alphaData.length];
- System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length);
- }
- if (device.tracking) device.new_Object(this);
- return;
- case SWT.IMAGE_DISABLE:
- /* Get src image data */
- XImage srcXImage = new XImage();
- int srcXImagePtr = OS.XGetImage(xDisplay, srcImage.pixmap, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap);
- OS.memmove(srcXImage, srcXImagePtr, XImage.sizeof);
- byte[] srcData = new byte[srcXImage.bytes_per_line * srcXImage.height];
- OS.memmove(srcData, srcXImage.data, srcData.length);
- /* Create destination image */
- int destPixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, srcXImage.depth);
- XImage destXImage = new XImage();
- int destXImagePtr = OS.XGetImage(xDisplay, drawable, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap);
- OS.memmove(destXImage, destXImagePtr, XImage.sizeof);
- byte[] destData = new byte[destXImage.bytes_per_line * destXImage.height];
- /* Find the colors to map to */
- Color zeroColor = device.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
- Color oneColor = device.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
- int zeroPixel = zeroColor.handle.pixel;
- int onePixel = oneColor.handle.pixel;
- switch (srcXImage.bits_per_pixel) {
- case 1:
- /*
- * Nothing we can reasonably do here except copy
- * the bitmap; we can't make it a higher color depth.
- * Short-circuit the rest of the code and return.
+public Image(Device device, Image srcImage, int flag) { + 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); + int xDisplay = device.xDisplay; + this.type = srcImage.type; + this.mask = 0; + int[] unused = new int[1]; + int[] w = new int[1]; + int[] h = new int[1]; + OS.XGetGeometry(xDisplay, srcImage.pixmap, unused, unused, unused, w, h, unused, unused); + int width = w[0]; + int height = h[0]; + int drawable = OS.XDefaultRootWindow(xDisplay); + /* Don't create the mask here if flag is SWT.IMAGE_GRAY. See below.*/ + if (flag != SWT.IMAGE_GRAY && (srcImage.mask != 0 || srcImage.transparentPixel != -1)) { + /* Generate the mask if necessary. */ + if (srcImage.transparentPixel != -1) srcImage.createMask(); + int mask = OS.XCreatePixmap(xDisplay, drawable, width, height, 1); + int gc = OS.XCreateGC(xDisplay, mask, 0, null); + OS.XCopyArea(xDisplay, srcImage.mask, mask, gc, 0, 0, width, height, 0, 0); + OS.XFreeGC(xDisplay, gc); + this.mask = mask; + /* Destroy the image mask if the there is a GC created on the image */ + if (srcImage.transparentPixel != -1 && srcImage.memGC != null) srcImage.destroyMask(); + } + switch (flag) { + case SWT.IMAGE_COPY: + int[] depth = new int[1]; + OS.XGetGeometry(xDisplay, srcImage.pixmap, unused, unused, unused, unused, unused, unused, depth); + int pixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, depth[0]); + int gc = OS.XCreateGC(xDisplay, pixmap, 0, null); + OS.XCopyArea(xDisplay, srcImage.pixmap, pixmap, gc, 0, 0, width, height, 0, 0); + OS.XFreeGC(xDisplay, gc); + this.pixmap = pixmap; + transparentPixel = srcImage.transparentPixel; + alpha = srcImage.alpha; + if (srcImage.alphaData != null) { + alphaData = new byte[srcImage.alphaData.length]; + System.arraycopy(srcImage.alphaData, 0, alphaData, 0, alphaData.length); + } + if (device.tracking) device.new_Object(this); + return; + case SWT.IMAGE_DISABLE: + /* Get src image data */ + XImage srcXImage = new XImage(); + int srcXImagePtr = OS.XGetImage(xDisplay, srcImage.pixmap, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap); + OS.memmove(srcXImage, srcXImagePtr, XImage.sizeof); + byte[] srcData = new byte[srcXImage.bytes_per_line * srcXImage.height]; + OS.memmove(srcData, srcXImage.data, srcData.length); + /* Create destination image */ + int destPixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, srcXImage.depth); + XImage destXImage = new XImage(); + int destXImagePtr = OS.XGetImage(xDisplay, drawable, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap); + OS.memmove(destXImage, destXImagePtr, XImage.sizeof); + byte[] destData = new byte[destXImage.bytes_per_line * destXImage.height]; + /* Find the colors to map to */ + Color zeroColor = device.getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW); + Color oneColor = device.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND); + int zeroPixel = zeroColor.handle.pixel; + int onePixel = oneColor.handle.pixel; + switch (srcXImage.bits_per_pixel) { + case 1: + /* + * Nothing we can reasonably do here except copy + * the bitmap; we can't make it a higher color depth. + * Short-circuit the rest of the code and return. */ - gc = OS.XCreateGC(xDisplay, drawable, 0, null);
- pixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, 1);
- OS.XCopyArea(xDisplay, srcImage.pixmap, pixmap, gc, 0, 0, width, height, 0, 0);
- OS.XDestroyImage(srcXImagePtr);
- OS.XDestroyImage(destXImagePtr);
- OS.XFreeGC(xDisplay, gc);
- return;
- case 4:
- SWT.error(SWT.ERROR_NOT_IMPLEMENTED);
- break;
- case 8:
- int index = 0;
- int srcPixel, r, g, b;
- XColor[] colors = new XColor[256];
- int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay));
- for (int y = 0; y < srcXImage.height; y++) {
- for (int x = 0; x < srcXImage.bytes_per_line; x++) {
- srcPixel = srcData[index + x] & 0xFF;
- /* Get the RGB values of srcPixel */
- if (colors[srcPixel] == null) {
- XColor color = new XColor();
- color.pixel = srcPixel;
- OS.XQueryColor(xDisplay, colormap, color);
- colors[srcPixel] = color;
- }
- XColor xColor = colors[srcPixel];
- r = (xColor.red >> 8) & 0xFF;
- g = (xColor.green >> 8) & 0xFF;
- b = (xColor.blue >> 8) & 0xFF;
- /* See if the rgb maps to 0 or 1 */
- if ((r * r + g * g + b * b) < 98304) {
- /* Map down to 0 */
- destData[index + x] = (byte)zeroPixel;
- } else {
- /* Map up to 1 */
- destData[index + x] = (byte)onePixel;
- }
- }
- index += srcXImage.bytes_per_line;
- }
- break;
- case 16:
- index = 0;
- /* Get masks */
- Visual visual = new Visual();
- int screenNum = OS.XDefaultScreen(xDisplay);
- int visualPtr = OS.XDefaultVisual(xDisplay, screenNum);
- OS.memmove(visual, visualPtr, Visual.sizeof);
- int redMask = visual.red_mask;
- int greenMask = visual.green_mask;
- int blueMask = visual.blue_mask;
- /* Calculate mask shifts */
- int[] shift = new int[1];
- getOffsetForMask(16, redMask, srcXImage.byte_order, shift);
- int rShift = 24 - shift[0];
- getOffsetForMask(16, greenMask, srcXImage.byte_order, shift);
- int gShift = 24 - shift[0];
- getOffsetForMask(16, blueMask, srcXImage.byte_order, shift);
- int bShift = 24 - shift[0];
- byte zeroLow = (byte)(zeroPixel & 0xFF);
- byte zeroHigh = (byte)((zeroPixel >> 8) & 0xFF);
- byte oneLow = (byte)(onePixel & 0xFF);
- byte oneHigh = (byte)((onePixel >> 8) & 0xFF);
- for (int y = 0; y < srcXImage.height; y++) {
- int xIndex = 0;
- for (int x = 0; x < srcXImage.bytes_per_line; x += 2) {
- srcPixel = ((srcData[index + xIndex + 1] & 0xFF) << 8) | (srcData[index + xIndex] & 0xFF);
- r = (srcPixel & redMask) << rShift >> 16;
- g = (srcPixel & greenMask) << gShift >> 16;
- b = (srcPixel & blueMask) << bShift >> 16;
- /* See if the rgb maps to 0 or 1 */
- if ((r * r + g * g + b * b) < 98304) {
- /* Map down to 0 */
- destData[index + xIndex] = zeroLow;
- destData[index + xIndex + 1] = zeroHigh;
- } else {
- /* Map up to 1 */
- destData[index + xIndex] = oneLow;
- destData[index + xIndex + 1] = oneHigh;
- }
- xIndex += srcXImage.bits_per_pixel / 8;
- }
- index += srcXImage.bytes_per_line;
- }
- break;
- case 24:
- case 32:
- index = 0;
- /* Get masks */
- visual = new Visual();
- screenNum = OS.XDefaultScreen(xDisplay);
- visualPtr = OS.XDefaultVisual(xDisplay, screenNum);
- OS.memmove(visual, visualPtr, Visual.sizeof);
- redMask = visual.red_mask;
- greenMask = visual.green_mask;
- blueMask = visual.blue_mask;
- /* Calculate mask shifts */
- shift = new int[1];
- getOffsetForMask(srcXImage.bits_per_pixel, redMask, srcXImage.byte_order, shift);
- rShift = shift[0];
- getOffsetForMask(srcXImage.bits_per_pixel, greenMask, srcXImage.byte_order, shift);
- gShift = shift[0];
- getOffsetForMask(srcXImage.bits_per_pixel, blueMask, srcXImage.byte_order, shift);
- bShift = shift[0];
- byte zeroR = (byte)zeroColor.getRed();
- byte zeroG = (byte)zeroColor.getGreen();
- byte zeroB = (byte)zeroColor.getBlue();
- byte oneR = (byte)oneColor.getRed();
- byte oneG = (byte)oneColor.getGreen();
- byte oneB = (byte)oneColor.getBlue();
- for (int y = 0; y < srcXImage.height; y++) {
- int xIndex = 0;
- for (int x = 0; x < srcXImage.width; x++) {
- r = srcData[index + xIndex + rShift] & 0xFF;
- g = srcData[index + xIndex + gShift] & 0xFF;
- b = srcData[index + xIndex + bShift] & 0xFF;
- /* See if the rgb maps to 0 or 1 */
- if ((r * r + g * g + b * b) < 98304) {
- /* Map down to 0 */
- destData[index + xIndex + rShift] = zeroR;
- destData[index + xIndex + gShift] = zeroG;
- destData[index + xIndex + bShift] = zeroB;
- } else {
- /* Map up to 1 */
- destData[index + xIndex + rShift] = oneR;
- destData[index + xIndex + gShift] = oneG;
- destData[index + xIndex + bShift] = oneB;
- }
- xIndex += destXImage.bits_per_pixel / 8;
- }
- index += srcXImage.bytes_per_line;
- }
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_IMAGE);
- }
- OS.memmove(destXImage.data, destData, destData.length);
- gc = OS.XCreateGC(xDisplay, destPixmap, 0, null);
- OS.XPutImage(xDisplay, destPixmap, gc, destXImagePtr, 0, 0, 0, 0, width, height);
- OS.XDestroyImage(destXImagePtr);
- OS.XDestroyImage(srcXImagePtr);
- OS.XFreeGC(xDisplay, gc);
- this.pixmap = destPixmap;
- if (device.tracking) device.new_Object(this);
- return;
- case SWT.IMAGE_GRAY:
- ImageData data = srcImage.getImageData();
- PaletteData palette = data.palette;
- ImageData newData = data;
- if (!palette.isDirect) {
- /* Convert the palette entries to gray. */
- RGB [] rgbs = palette.getRGBs();
- for (int i=0; i<rgbs.length; i++) {
- if (data.transparentPixel != i) {
- RGB color = rgbs [i];
- int red = color.red;
- int green = color.green;
- int blue = color.blue;
- int intensity = (red+red+green+green+green+green+green+blue) >> 3;
- color.red = color.green = color.blue = intensity;
- }
- }
- newData.palette = new PaletteData(rgbs);
- } else {
- /* Create a 8 bit depth image data with a gray palette. */
- RGB[] rgbs = new RGB[256];
- for (int i=0; i<rgbs.length; i++) {
- rgbs[i] = new RGB(i, i, i);
- }
- newData = new ImageData(width, height, 8, new PaletteData(rgbs));
- newData.maskData = data.maskData;
- newData.maskPad = data.maskPad;
-
- /* Convert the pixels. */
- int[] scanline = new int[width];
- int redMask = palette.redMask;
- int greenMask = palette.greenMask;
- int blueMask = palette.blueMask;
- int redShift = palette.redShift;
- int greenShift = palette.greenShift;
- int blueShift = palette.blueShift;
- for (int y=0; y<height; y++) {
- int offset = y * newData.bytesPerLine;
- data.getPixels(0, y, width, scanline, 0);
- for (int x=0; x<width; x++) {
- int pixel = scanline[x];
- int red = pixel & redMask;
- red = (redShift < 0) ? red >>> -redShift : red << redShift;
- int green = pixel & greenMask;
- green = (greenShift < 0) ? green >>> -greenShift : green << greenShift;
- int blue = pixel & blueMask;
- blue = (blueShift < 0) ? blue >>> -blueShift : blue << blueShift;
- newData.data[offset++] =
- (byte)((red+red+green+green+green+green+green+blue) >> 3);
- }
- }
- }
- init (device, newData);
- break;
- default:
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (device.tracking) device.new_Object(this);
-}
+ gc = OS.XCreateGC(xDisplay, drawable, 0, null); + pixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, 1); + OS.XCopyArea(xDisplay, srcImage.pixmap, pixmap, gc, 0, 0, width, height, 0, 0); + OS.XDestroyImage(srcXImagePtr); + OS.XDestroyImage(destXImagePtr); + OS.XFreeGC(xDisplay, gc); + return; + case 4: + SWT.error(SWT.ERROR_NOT_IMPLEMENTED); + break; + case 8: + int index = 0; + int srcPixel, r, g, b; + XColor[] colors = new XColor[256]; + int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay)); + for (int y = 0; y < srcXImage.height; y++) { + for (int x = 0; x < srcXImage.bytes_per_line; x++) { + srcPixel = srcData[index + x] & 0xFF; + /* Get the RGB values of srcPixel */ + if (colors[srcPixel] == null) { + XColor color = new XColor(); + color.pixel = srcPixel; + OS.XQueryColor(xDisplay, colormap, color); + colors[srcPixel] = color; + } + XColor xColor = colors[srcPixel]; + r = (xColor.red >> 8) & 0xFF; + g = (xColor.green >> 8) & 0xFF; + b = (xColor.blue >> 8) & 0xFF; + /* See if the rgb maps to 0 or 1 */ + if ((r * r + g * g + b * b) < 98304) { + /* Map down to 0 */ + destData[index + x] = (byte)zeroPixel; + } else { + /* Map up to 1 */ + destData[index + x] = (byte)onePixel; + } + } + index += srcXImage.bytes_per_line; + } + break; + case 16: + index = 0; + /* Get masks */ + Visual visual = new Visual(); + int screenNum = OS.XDefaultScreen(xDisplay); + int visualPtr = OS.XDefaultVisual(xDisplay, screenNum); + OS.memmove(visual, visualPtr, Visual.sizeof); + int redMask = visual.red_mask; + int greenMask = visual.green_mask; + int blueMask = visual.blue_mask; + /* Calculate mask shifts */ + int[] shift = new int[1]; + getOffsetForMask(16, redMask, srcXImage.byte_order, shift); + int rShift = 24 - shift[0]; + getOffsetForMask(16, greenMask, srcXImage.byte_order, shift); + int gShift = 24 - shift[0]; + getOffsetForMask(16, blueMask, srcXImage.byte_order, shift); + int bShift = 24 - shift[0]; + byte zeroLow = (byte)(zeroPixel & 0xFF); + byte zeroHigh = (byte)((zeroPixel >> 8) & 0xFF); + byte oneLow = (byte)(onePixel & 0xFF); + byte oneHigh = (byte)((onePixel >> 8) & 0xFF); + for (int y = 0; y < srcXImage.height; y++) { + int xIndex = 0; + for (int x = 0; x < srcXImage.bytes_per_line; x += 2) { + srcPixel = ((srcData[index + xIndex + 1] & 0xFF) << 8) | (srcData[index + xIndex] & 0xFF); + r = (srcPixel & redMask) << rShift >> 16; + g = (srcPixel & greenMask) << gShift >> 16; + b = (srcPixel & blueMask) << bShift >> 16; + /* See if the rgb maps to 0 or 1 */ + if ((r * r + g * g + b * b) < 98304) { + /* Map down to 0 */ + destData[index + xIndex] = zeroLow; + destData[index + xIndex + 1] = zeroHigh; + } else { + /* Map up to 1 */ + destData[index + xIndex] = oneLow; + destData[index + xIndex + 1] = oneHigh; + } + xIndex += srcXImage.bits_per_pixel / 8; + } + index += srcXImage.bytes_per_line; + } + break; + case 24: + case 32: + index = 0; + /* Get masks */ + visual = new Visual(); + screenNum = OS.XDefaultScreen(xDisplay); + visualPtr = OS.XDefaultVisual(xDisplay, screenNum); + OS.memmove(visual, visualPtr, Visual.sizeof); + redMask = visual.red_mask; + greenMask = visual.green_mask; + blueMask = visual.blue_mask; + /* Calculate mask shifts */ + shift = new int[1]; + getOffsetForMask(srcXImage.bits_per_pixel, redMask, srcXImage.byte_order, shift); + rShift = shift[0]; + getOffsetForMask(srcXImage.bits_per_pixel, greenMask, srcXImage.byte_order, shift); + gShift = shift[0]; + getOffsetForMask(srcXImage.bits_per_pixel, blueMask, srcXImage.byte_order, shift); + bShift = shift[0]; + byte zeroR = (byte)zeroColor.getRed(); + byte zeroG = (byte)zeroColor.getGreen(); + byte zeroB = (byte)zeroColor.getBlue(); + byte oneR = (byte)oneColor.getRed(); + byte oneG = (byte)oneColor.getGreen(); + byte oneB = (byte)oneColor.getBlue(); + for (int y = 0; y < srcXImage.height; y++) { + int xIndex = 0; + for (int x = 0; x < srcXImage.width; x++) { + r = srcData[index + xIndex + rShift] & 0xFF; + g = srcData[index + xIndex + gShift] & 0xFF; + b = srcData[index + xIndex + bShift] & 0xFF; + /* See if the rgb maps to 0 or 1 */ + if ((r * r + g * g + b * b) < 98304) { + /* Map down to 0 */ + destData[index + xIndex + rShift] = zeroR; + destData[index + xIndex + gShift] = zeroG; + destData[index + xIndex + bShift] = zeroB; + } else { + /* Map up to 1 */ + destData[index + xIndex + rShift] = oneR; + destData[index + xIndex + gShift] = oneG; + destData[index + xIndex + bShift] = oneB; + } + xIndex += destXImage.bits_per_pixel / 8; + } + index += srcXImage.bytes_per_line; + } + break; + default: + SWT.error(SWT.ERROR_INVALID_IMAGE); + } + OS.memmove(destXImage.data, destData, destData.length); + gc = OS.XCreateGC(xDisplay, destPixmap, 0, null); + OS.XPutImage(xDisplay, destPixmap, gc, destXImagePtr, 0, 0, 0, 0, width, height); + OS.XDestroyImage(destXImagePtr); + OS.XDestroyImage(srcXImagePtr); + OS.XFreeGC(xDisplay, gc); + this.pixmap = destPixmap; + if (device.tracking) device.new_Object(this); + return; + case SWT.IMAGE_GRAY: + ImageData data = srcImage.getImageData(); + PaletteData palette = data.palette; + ImageData newData = data; + if (!palette.isDirect) { + /* Convert the palette entries to gray. */ + RGB [] rgbs = palette.getRGBs(); + for (int i=0; i<rgbs.length; i++) { + if (data.transparentPixel != i) { + RGB color = rgbs [i]; + int red = color.red; + int green = color.green; + int blue = color.blue; + int intensity = (red+red+green+green+green+green+green+blue) >> 3; + color.red = color.green = color.blue = intensity; + } + } + newData.palette = new PaletteData(rgbs); + } else { + /* Create a 8 bit depth image data with a gray palette. */ + RGB[] rgbs = new RGB[256]; + for (int i=0; i<rgbs.length; i++) { + rgbs[i] = new RGB(i, i, i); + } + newData = new ImageData(width, height, 8, new PaletteData(rgbs)); + newData.maskData = data.maskData; + newData.maskPad = data.maskPad; + + /* Convert the pixels. */ + int[] scanline = new int[width]; + int redMask = palette.redMask; + int greenMask = palette.greenMask; + int blueMask = palette.blueMask; + int redShift = palette.redShift; + int greenShift = palette.greenShift; + int blueShift = palette.blueShift; + for (int y=0; y<height; y++) { + int offset = y * newData.bytesPerLine; + data.getPixels(0, y, width, scanline, 0); + for (int x=0; x<width; x++) { + int pixel = scanline[x]; + int red = pixel & redMask; + red = (redShift < 0) ? red >>> -redShift : red << redShift; + int green = pixel & greenMask; + green = (greenShift < 0) ? green >>> -greenShift : green << greenShift; + int blue = pixel & blueMask; + blue = (blueShift < 0) ? blue >>> -blueShift : blue << blueShift; + newData.data[offset++] = + (byte)((red+red+green+green+green+green+green+blue) >> 3); + } + } + } + init (device, newData); + break; + default: + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + if (device.tracking) device.new_Object(this); +} /** * Constructs an empty instance of this class with the * width and height of the specified rectangle. The result @@ -485,13 +485,13 @@ public Image(Device device, Image srcImage, int flag) { * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> * </ul> */ -public Image(Device device, Rectangle bounds) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, bounds.width, bounds.height);
- if (device.tracking) device.new_Object(this);
-}
+public Image(Device device, Rectangle bounds) { + if (device == null) device = Device.getDevice(); + if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (bounds == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + init(device, bounds.width, bounds.height); + if (device.tracking) device.new_Object(this); +} /** * Constructs an instance of this class from the given * <code>ImageData</code>. @@ -507,12 +507,12 @@ public Image(Device device, Rectangle bounds) { * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> * </ul> */ -public Image(Device device, ImageData image) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, image);
- if (device.tracking) device.new_Object(this);
-}
+public Image(Device device, ImageData image) { + if (device == null) device = Device.getDevice(); + if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + init(device, image); + if (device.tracking) device.new_Object(this); +} /** * Constructs an instance of this class, whose type is * <code>SWT.ICON</code>, from the two given <code>ImageData</code> @@ -542,21 +542,21 @@ public Image(Device device, ImageData image) { * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> * </ul> */ -public Image(Device device, ImageData source, ImageData mask) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (mask == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (source.width != mask.width || source.height != mask.height) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- ImageData image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad, source.data);
- image.maskPad = mask.scanlinePad;
- image.maskData = mask.data;
- init(device, image);
- if (device.tracking) device.new_Object(this);
-}
+public Image(Device device, ImageData source, ImageData mask) { + if (device == null) device = Device.getDevice(); + if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (mask == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (source.width != mask.width || source.height != mask.height) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + ImageData image = new ImageData(source.width, source.height, source.depth, source.palette, source.scanlinePad, source.data); + image.maskPad = mask.scanlinePad; + image.maskData = mask.data; + init(device, image); + if (device.tracking) device.new_Object(this); +} /** * Constructs an instance of this class by loading its representation * from the specified input stream. Throws an error if an error @@ -589,12 +589,12 @@ public Image(Device device, ImageData source, ImageData mask) { * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> * </ul> */ -public Image(Device device, InputStream stream) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, new ImageData(stream));
- if (device.tracking) device.new_Object(this);
-}
+public Image(Device device, InputStream stream) { + if (device == null) device = Device.getDevice(); + if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + init(device, new ImageData(stream)); + if (device.tracking) device.new_Object(this); +} /** * Constructs an instance of this class by loading its representation * from the file with the specified name. Throws an error if an error @@ -620,53 +620,53 @@ public Image(Device device, InputStream stream) { * <li>ERROR_NO_HANDLES if a handle could not be obtained for image creation</li> * </ul> */ -public Image(Device device, String filename) {
- if (device == null) device = Device.getDevice();
- if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- init(device, new ImageData(filename));
- if (device.tracking) device.new_Object(this);
-}
-/**
- * Create the receiver's mask if necessary.
+public Image(Device device, String filename) { + if (device == null) device = Device.getDevice(); + if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + init(device, new ImageData(filename)); + if (device.tracking) device.new_Object(this); +} +/** + * Create the receiver's mask if necessary. */ -void createMask() {
- if (mask != 0) return;
- int xDisplay = device.xDisplay;
- int drawable = OS.XDefaultRootWindow(xDisplay);
- int screenDepth = OS.XDefaultDepthOfScreen(OS.XDefaultScreenOfDisplay(xDisplay));
- int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay));
- ImageData maskImage = getImageData().getTransparencyMask();
- int maskPixmap = OS.XCreatePixmap(xDisplay, drawable, maskImage.width, maskImage.height, 1);
- XColor[] xcolors = device.xcolors;
- int gc = OS.XCreateGC(xDisplay, maskPixmap, 0, null);
- Image.putImage(maskImage, 0, 0, maskImage.width, maskImage.height, 0, 0, maskImage.width, maskImage.height, xDisplay, visual, screenDepth, xcolors, null, true, maskPixmap, gc);
- OS.XFreeGC(xDisplay, gc);
- this.mask = maskPixmap;
-}
+void createMask() { + if (mask != 0) return; + int xDisplay = device.xDisplay; + int drawable = OS.XDefaultRootWindow(xDisplay); + int screenDepth = OS.XDefaultDepthOfScreen(OS.XDefaultScreenOfDisplay(xDisplay)); + int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay)); + ImageData maskImage = getImageData().getTransparencyMask(); + int maskPixmap = OS.XCreatePixmap(xDisplay, drawable, maskImage.width, maskImage.height, 1); + XColor[] xcolors = device.xcolors; + int gc = OS.XCreateGC(xDisplay, maskPixmap, 0, null); + Image.putImage(maskImage, 0, 0, maskImage.width, maskImage.height, 0, 0, maskImage.width, maskImage.height, xDisplay, visual, screenDepth, xcolors, null, true, maskPixmap, gc); + OS.XFreeGC(xDisplay, gc); + this.mask = maskPixmap; +} /** * 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) return;
+public void dispose () { + if (pixmap == 0) return; if (device.isDisposed()) return; - int xDisplay = device.xDisplay;
- if (pixmap != 0) OS.XFreePixmap (xDisplay, pixmap);
- if (mask != 0) OS.XFreePixmap (xDisplay, mask);
- memGC = null;
- pixmap = mask = 0;
- if (device.tracking) device.dispose_Object(this);
- device = null;
-}
-/**
- * Destroy the receiver's mask if it exists.
+ int xDisplay = device.xDisplay; + if (pixmap != 0) OS.XFreePixmap (xDisplay, pixmap); + if (mask != 0) OS.XFreePixmap (xDisplay, mask); + memGC = null; + pixmap = mask = 0; + if (device.tracking) device.dispose_Object(this); + device = null; +} +/** + * Destroy the receiver's mask if it exists. */ -void destroyMask() {
- if (mask == 0) return;
- OS.XFreePixmap (device.xDisplay, mask);
- mask = 0;
-}
+void destroyMask() { + if (mask == 0) return; + OS.XFreePixmap (device.xDisplay, mask); + mask = 0; +} /** * Compares the argument to the receiver, and returns true * if they represent the <em>same</em> object using a class @@ -677,12 +677,12 @@ void destroyMask() { * * @see #hashCode */ -public boolean equals (Object object) {
- if (object == this) return true;
- if (!(object instanceof Image)) return false;
- Image image = (Image)object;
- return device == image.device && pixmap == image.pixmap;
-}
+public boolean equals (Object object) { + if (object == this) return true; + if (!(object instanceof Image)) return false; + Image image = (Image)object; + return device == image.device && pixmap == image.pixmap; +} /** * Returns the color to which to map the transparent pixel, or null if * the receiver has no transparent pixel. @@ -701,16 +701,16 @@ public boolean equals (Object object) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public Color getBackground() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (transparentPixel == -1) return null;
- XColor xColor = new XColor();
- xColor.pixel = transparentPixel;
- int xDisplay = device.xDisplay;
- int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay));
- OS.XQueryColor(xDisplay, colormap, xColor);
- return Color.motif_new(device, xColor);
-}
+public Color getBackground() { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (transparentPixel == -1) return null; + XColor xColor = new XColor(); + xColor.pixel = transparentPixel; + int xDisplay = device.xDisplay; + int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay)); + OS.XQueryColor(xDisplay, colormap, xColor); + return Color.motif_new(device, xColor); +} /** * Returns the bounds of the receiver. The rectangle will always * have x and y values of 0, and the width and height of the @@ -723,12 +723,12 @@ public Color getBackground() { * <li>ERROR_INVALID_IMAGE - if the image is not a bitmap or an icon</li> * </ul> */ -public Rectangle getBounds () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- int [] unused = new int [1]; int [] width = new int [1]; int [] height = new int [1];
- OS.XGetGeometry (device.xDisplay, pixmap, unused, unused, unused, width, height, unused, unused);
- return new Rectangle(0, 0, width [0], height [0]);
-}
+public Rectangle getBounds () { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + int [] unused = new int [1]; int [] width = new int [1]; int [] height = new int [1]; + OS.XGetGeometry (device.xDisplay, pixmap, unused, unused, unused, width, height, unused, unused); + 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 @@ -743,205 +743,205 @@ public Rectangle getBounds () { * * @see ImageData */ -public ImageData getImageData() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- Rectangle srcBounds = getBounds();
- int width = srcBounds.width;
- int height = srcBounds.height;
- int xDisplay = device.xDisplay;
- int xSrcImagePtr = OS.XGetImage(xDisplay, pixmap, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap);
- if (xSrcImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- XImage xSrcImage = new XImage();
- OS.memmove(xSrcImage, xSrcImagePtr, XImage.sizeof);
-
- /* Get the data and palette of the source image. */
- PaletteData palette = null;
- int length = xSrcImage.bytes_per_line * xSrcImage.height;
- byte[] srcData = new byte[length];
- OS.memmove(srcData, xSrcImage.data, length);
- switch (xSrcImage.bits_per_pixel) {
- case 1:
- palette = new PaletteData(new RGB[] {
- new RGB(0, 0, 0),
- new RGB(255, 255, 255)
- });
- break;
- case 4:
- /*
- * We currently don't run on a 4-bit server, so 4-bit images
- * should not exist.
- */
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- case 8:
- /* Normalize the pixels in the source image data (by making the
- * pixel values sequential starting at pixel 0). Reserve normalized
- * pixel 0 so that it maps to real pixel 0. This assumes pixel 0 is
- * always used in the image.
- */
- byte[] normPixel = new byte[256];
- for (int index = 0; index < normPixel.length; index++) {
- normPixel[index] = 0;
- }
- int numPixels = 1;
- int index = 0;
- for (int y = 0; y < xSrcImage.height; y++) {
- for (int x = 0; x < xSrcImage.bytes_per_line; x++) {
- int srcPixel = srcData[index + x] & 0xFF;
- if (srcPixel != 0 && normPixel[srcPixel] == 0) {
- normPixel[srcPixel] = (byte)numPixels++;
- }
- srcData[index + x] = normPixel[srcPixel];
- }
- index += xSrcImage.bytes_per_line;
- }
-
- /* Create a palette with only the RGB values used in the image. */
- int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay));
- RGB[] rgbs = new RGB[numPixels];
- XColor color = new XColor();
- for (int srcPixel = 0; srcPixel < normPixel.length; srcPixel++) {
- /* If the pixel value was used in the image, get its RGB values. */
- if (srcPixel == 0 || normPixel[srcPixel] != 0) {
- color.pixel = srcPixel;
- OS.XQueryColor(xDisplay, colormap, color);
- int rgbIndex = normPixel[srcPixel] & 0xFF;
- rgbs[rgbIndex] = new RGB((color.red >> 8) & 0xFF, (color.green >> 8) & 0xFF, (color.blue >> 8) & 0xFF);
- }
- }
- palette = new PaletteData(rgbs);
- break;
- case 16:
- /* Byte swap the data if necessary */
- if (xSrcImage.byte_order == OS.MSBFirst) {
- for (int i = 0; i < srcData.length; i += 2) {
- byte b = srcData[i];
- srcData[i] = srcData[i+1];
- srcData[i+1] = b;
- }
- }
- break;
- case 24:
- break;
- case 32:
- /* Byte swap the data if necessary */
- if (xSrcImage.byte_order == OS.LSBFirst) {
- for (int i = 0; i < srcData.length; i += 4) {
- byte b = srcData[i];
- srcData[i] = srcData[i+3];
- srcData[i+3] = b;
- b = srcData[i+1];
- srcData[i+1] = srcData[i+2];
- srcData[i+2] = b;
- }
- }
- break;
- default:
- SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH);
- }
- if (palette == null) {
- /*
- * For some reason, the XImage does not have the mask information.
- * We must get it from the defualt visual.
- */
- int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay));
- Visual v = new Visual();
- OS.memmove(v, visual, Visual.sizeof);
- palette = new PaletteData(v.red_mask, v.green_mask, v.blue_mask);
- }
- ImageData data = new ImageData(width, height, xSrcImage.bits_per_pixel, palette);
- data.data = srcData;
- if (transparentPixel == -1 && type == SWT.ICON && mask != 0) {
- /* Get the icon mask data */
- int xMaskPtr = OS.XGetImage(xDisplay, mask, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap);
- if (xMaskPtr == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- XImage xMask = new XImage();
- OS.memmove(xMask, xMaskPtr, XImage.sizeof);
- byte[] maskData = data.maskData = new byte[xMask.bytes_per_line * xMask.height];
- data.maskPad = xMask.bitmap_pad / 8;
- OS.memmove(maskData, xMask.data, maskData.length);
- OS.XDestroyImage(xMaskPtr);
- /* Bit swap the mask data if necessary */
- if (xMask.bitmap_bit_order == OS.LSBFirst) {
- for (int i = 0; i < maskData.length; i++) {
- byte b = maskData[i];
- maskData[i] = (byte)(((b & 0x01) << 7) | ((b & 0x02) << 5) |
- ((b & 0x04) << 3) | ((b & 0x08) << 1) | ((b & 0x10) >> 1) |
- ((b & 0x20) >> 3) | ((b & 0x40) >> 5) | ((b & 0x80) >> 7));
- }
- }
- }
- data.transparentPixel = transparentPixel;
- data.alpha = alpha;
- if (alpha == -1 && alphaData != null) {
- data.alphaData = new byte[alphaData.length];
- System.arraycopy(alphaData, 0, data.alphaData, 0, alphaData.length);
- }
- OS.XDestroyImage(xSrcImagePtr);
- return data;
-}
-/**
- * Get the offset for the given mask.
- *
- * For 24 and 32-bit masks, the offset indicates which byte holds the
- * data for the given mask (indexed from 0).
- * For example, in 0x0000FF00, the byte offset is 1.
- *
- * For 16-bit masks, the offset indicates which bit holds the most significant
- * data for the given mask (indexed from 1).
- * For example, in 0x7E0, the bit offset is 11.
- *
- * The different semantics are necessary because 24- and 32-bit images
- * have their color components aligned on byte boundaries, and 16-bit images
- * do not.
+public ImageData getImageData() { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + Rectangle srcBounds = getBounds(); + int width = srcBounds.width; + int height = srcBounds.height; + int xDisplay = device.xDisplay; + int xSrcImagePtr = OS.XGetImage(xDisplay, pixmap, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap); + if (xSrcImagePtr == 0) SWT.error(SWT.ERROR_NO_HANDLES); + XImage xSrcImage = new XImage(); + OS.memmove(xSrcImage, xSrcImagePtr, XImage.sizeof); + + /* Get the data and palette of the source image. */ + PaletteData palette = null; + int length = xSrcImage.bytes_per_line * xSrcImage.height; + byte[] srcData = new byte[length]; + OS.memmove(srcData, xSrcImage.data, length); + switch (xSrcImage.bits_per_pixel) { + case 1: + palette = new PaletteData(new RGB[] { + new RGB(0, 0, 0), + new RGB(255, 255, 255) + }); + break; + case 4: + /* + * We currently don't run on a 4-bit server, so 4-bit images + * should not exist. + */ + SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH); + case 8: + /* Normalize the pixels in the source image data (by making the + * pixel values sequential starting at pixel 0). Reserve normalized + * pixel 0 so that it maps to real pixel 0. This assumes pixel 0 is + * always used in the image. + */ + byte[] normPixel = new byte[256]; + for (int index = 0; index < normPixel.length; index++) { + normPixel[index] = 0; + } + int numPixels = 1; + int index = 0; + for (int y = 0; y < xSrcImage.height; y++) { + for (int x = 0; x < xSrcImage.bytes_per_line; x++) { + int srcPixel = srcData[index + x] & 0xFF; + if (srcPixel != 0 && normPixel[srcPixel] == 0) { + normPixel[srcPixel] = (byte)numPixels++; + } + srcData[index + x] = normPixel[srcPixel]; + } + index += xSrcImage.bytes_per_line; + } + + /* Create a palette with only the RGB values used in the image. */ + int colormap = OS.XDefaultColormap(xDisplay, OS.XDefaultScreen(xDisplay)); + RGB[] rgbs = new RGB[numPixels]; + XColor color = new XColor(); + for (int srcPixel = 0; srcPixel < normPixel.length; srcPixel++) { + /* If the pixel value was used in the image, get its RGB values. */ + if (srcPixel == 0 || normPixel[srcPixel] != 0) { + color.pixel = srcPixel; + OS.XQueryColor(xDisplay, colormap, color); + int rgbIndex = normPixel[srcPixel] & 0xFF; + rgbs[rgbIndex] = new RGB((color.red >> 8) & 0xFF, (color.green >> 8) & 0xFF, (color.blue >> 8) & 0xFF); + } + } + palette = new PaletteData(rgbs); + break; + case 16: + /* Byte swap the data if necessary */ + if (xSrcImage.byte_order == OS.MSBFirst) { + for (int i = 0; i < srcData.length; i += 2) { + byte b = srcData[i]; + srcData[i] = srcData[i+1]; + srcData[i+1] = b; + } + } + break; + case 24: + break; + case 32: + /* Byte swap the data if necessary */ + if (xSrcImage.byte_order == OS.LSBFirst) { + for (int i = 0; i < srcData.length; i += 4) { + byte b = srcData[i]; + srcData[i] = srcData[i+3]; + srcData[i+3] = b; + b = srcData[i+1]; + srcData[i+1] = srcData[i+2]; + srcData[i+2] = b; + } + } + break; + default: + SWT.error(SWT.ERROR_UNSUPPORTED_DEPTH); + } + if (palette == null) { + /* + * For some reason, the XImage does not have the mask information. + * We must get it from the defualt visual. + */ + int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay)); + Visual v = new Visual(); + OS.memmove(v, visual, Visual.sizeof); + palette = new PaletteData(v.red_mask, v.green_mask, v.blue_mask); + } + ImageData data = new ImageData(width, height, xSrcImage.bits_per_pixel, palette); + data.data = srcData; + if (transparentPixel == -1 && type == SWT.ICON && mask != 0) { + /* Get the icon mask data */ + int xMaskPtr = OS.XGetImage(xDisplay, mask, 0, 0, width, height, OS.AllPlanes, OS.ZPixmap); + if (xMaskPtr == 0) SWT.error(SWT.ERROR_NO_HANDLES); + XImage xMask = new XImage(); + OS.memmove(xMask, xMaskPtr, XImage.sizeof); + byte[] maskData = data.maskData = new byte[xMask.bytes_per_line * xMask.height]; + data.maskPad = xMask.bitmap_pad / 8; + OS.memmove(maskData, xMask.data, maskData.length); + OS.XDestroyImage(xMaskPtr); + /* Bit swap the mask data if necessary */ + if (xMask.bitmap_bit_order == OS.LSBFirst) { + for (int i = 0; i < maskData.length; i++) { + byte b = maskData[i]; + maskData[i] = (byte)(((b & 0x01) << 7) | ((b & 0x02) << 5) | + ((b & 0x04) << 3) | ((b & 0x08) << 1) | ((b & 0x10) >> 1) | + ((b & 0x20) >> 3) | ((b & 0x40) >> 5) | ((b & 0x80) >> 7)); + } + } + } + data.transparentPixel = transparentPixel; + data.alpha = alpha; + if (alpha == -1 && alphaData != null) { + data.alphaData = new byte[alphaData.length]; + System.arraycopy(alphaData, 0, data.alphaData, 0, alphaData.length); + } + OS.XDestroyImage(xSrcImagePtr); + return data; +} +/** + * Get the offset for the given mask. + * + * For 24 and 32-bit masks, the offset indicates which byte holds the + * data for the given mask (indexed from 0). + * For example, in 0x0000FF00, the byte offset is 1. + * + * For 16-bit masks, the offset indicates which bit holds the most significant + * data for the given mask (indexed from 1). + * For example, in 0x7E0, the bit offset is 11. + * + * The different semantics are necessary because 24- and 32-bit images + * have their color components aligned on byte boundaries, and 16-bit images + * do not. */ -static boolean getOffsetForMask(int bitspp, int mask, int byteOrder, int[] poff) {
- if (bitspp % 8 != 0) {
- return false;
- }
- switch (mask) {
- /* 24-bit and 32-bit masks */
- case 0x000000FF:
- poff[0] = 0;
- break;
- case 0x0000FF00:
- poff[0] = 1;
- break;
- case 0x00FF0000:
- poff[0] = 2;
- break;
- case 0xFF000000:
- poff[0] = 3;
- break;
- /* 16-bit masks */
- case 0x001F:
- poff[0] = 5;
- break;
- case 0x03E0:
- poff[0] = 10;
- break;
- case 0x07E0:
- poff[0] = 11;
- break;
- case 0x7C00:
- poff[0] = 15;
- break;
- case 0xF800:
- poff[0] = 16;
- break;
- default:
- return false;
- }
- if (bitspp == 16) {
- return true;
- }
- if (poff[0] >= bitspp / 8) {
- return false;
- }
- if (byteOrder == OS.MSBFirst) {
- poff[0] = (bitspp/8 - 1) - poff[0];
- }
- return true;
-}
+static boolean getOffsetForMask(int bitspp, int mask, int byteOrder, int[] poff) { + if (bitspp % 8 != 0) { + return false; + } + switch (mask) { + /* 24-bit and 32-bit masks */ + case 0x000000FF: + poff[0] = 0; + break; + case 0x0000FF00: + poff[0] = 1; + break; + case 0x00FF0000: + poff[0] = 2; + break; + case 0xFF000000: + poff[0] = 3; + break; + /* 16-bit masks */ + case 0x001F: + poff[0] = 5; + break; + case 0x03E0: + poff[0] = 10; + break; + case 0x07E0: + poff[0] = 11; + break; + case 0x7C00: + poff[0] = 15; + break; + case 0xF800: + poff[0] = 16; + break; + default: + return false; + } + if (bitspp == 16) { + return true; + } + if (poff[0] >= bitspp / 8) { + return false; + } + if (byteOrder == OS.MSBFirst) { + poff[0] = (bitspp/8 - 1) - poff[0]; + } + return true; +} /** * Returns an integer hash code for the receiver. Any two * objects which return <code>true</code> when passed to @@ -952,78 +952,78 @@ static boolean getOffsetForMask(int bitspp, int mask, int byteOrder, int[] poff) * * @see #equals */ -public int hashCode () {
- return pixmap;
-}
-void init(Device device, int width, int height) {
- this.device = device;
- if (width <= 0 | height <= 0) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
-
- /* Create the pixmap */
- this.type = SWT.BITMAP;
- int xDisplay = device.xDisplay;
- int screen = OS.XDefaultScreenOfDisplay(xDisplay);
- int depth = OS.XDefaultDepthOfScreen(screen);
- int screenNum = OS.XDefaultScreen(xDisplay);
- int drawable = OS.XDefaultRootWindow(xDisplay);
- int pixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, depth);
- if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- /* Fill the bitmap with white */
- int xGC = OS.XCreateGC(xDisplay, drawable, 0, null);
- OS.XSetForeground(xDisplay, xGC, OS.XWhitePixel(xDisplay, screenNum));
- OS.XFillRectangle(xDisplay, pixmap, xGC, 0, 0, width, height);
- OS.XFreeGC(xDisplay, xGC);
- this.pixmap = pixmap;
-}
-void init(Device device, ImageData image) {
- this.device = device;
- if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- int xDisplay = device.xDisplay;
- int drawable = OS.XDefaultRootWindow(xDisplay);
- int screenDepth = OS.XDefaultDepthOfScreen(OS.XDefaultScreenOfDisplay(xDisplay));
- int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay));
- int pixmap = OS.XCreatePixmap(xDisplay, drawable, image.width, image.height, screenDepth);
- if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int gc = OS.XCreateGC(xDisplay, pixmap, 0, null);
- int[] transPixel = null;
- if (image.transparentPixel != -1) transPixel = new int[]{image.transparentPixel};
- int error = putImage(image, 0, 0, image.width, image.height, 0, 0, image.width, image.height, xDisplay, visual, screenDepth, device.xcolors, transPixel, false, pixmap, gc);
- OS.XFreeGC(xDisplay, gc);
- if (error != 0) {
- OS.XFreePixmap (xDisplay, pixmap);
- SWT.error(error);
- }
- if (image.getTransparencyType() == SWT.TRANSPARENCY_MASK || image.transparentPixel != -1) {
- if (image.transparentPixel != -1) transparentPixel = transPixel[0];
- ImageData maskImage = image.getTransparencyMask();
- int mask = OS.XCreatePixmap(xDisplay, drawable, image.width, image.height, 1);
- gc = OS.XCreateGC(xDisplay, mask, 0, null);
- error = putImage(maskImage, 0, 0, maskImage.width, maskImage.height, 0, 0, maskImage.width, maskImage.height, xDisplay, visual, screenDepth, device.xcolors, null, true, mask, gc);
- OS.XFreeGC(xDisplay, gc);
- if (error != 0) {
- OS.XFreePixmap (xDisplay, pixmap);
- OS.XFreePixmap (xDisplay, mask);
- SWT.error(error);
- }
- this.mask = mask;
- if (image.getTransparencyType() == SWT.TRANSPARENCY_MASK) {
- this.type = SWT.ICON;
- } else {
- this.type = SWT.BITMAP;
- }
- } else {
- this.type = SWT.BITMAP;
- this.mask = 0;
- this.alpha = image.alpha;
- if (image.alpha == -1 && image.alphaData != null) {
- this.alphaData = new byte[image.alphaData.length];
- System.arraycopy(image.alphaData, 0, this.alphaData, 0, alphaData.length);
- }
- }
- this.pixmap = pixmap;
-}
+public int hashCode () { + return pixmap; +} +void init(Device device, int width, int height) { + this.device = device; + if (width <= 0 | height <= 0) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + + /* Create the pixmap */ + this.type = SWT.BITMAP; + int xDisplay = device.xDisplay; + int screen = OS.XDefaultScreenOfDisplay(xDisplay); + int depth = OS.XDefaultDepthOfScreen(screen); + int screenNum = OS.XDefaultScreen(xDisplay); + int drawable = OS.XDefaultRootWindow(xDisplay); + int pixmap = OS.XCreatePixmap(xDisplay, drawable, width, height, depth); + if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES); + /* Fill the bitmap with white */ + int xGC = OS.XCreateGC(xDisplay, drawable, 0, null); + OS.XSetForeground(xDisplay, xGC, OS.XWhitePixel(xDisplay, screenNum)); + OS.XFillRectangle(xDisplay, pixmap, xGC, 0, 0, width, height); + OS.XFreeGC(xDisplay, xGC); + this.pixmap = pixmap; +} +void init(Device device, ImageData image) { + this.device = device; + if (image == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + int xDisplay = device.xDisplay; + int drawable = OS.XDefaultRootWindow(xDisplay); + int screenDepth = OS.XDefaultDepthOfScreen(OS.XDefaultScreenOfDisplay(xDisplay)); + int visual = OS.XDefaultVisual(xDisplay, OS.XDefaultScreen(xDisplay)); + int pixmap = OS.XCreatePixmap(xDisplay, drawable, image.width, image.height, screenDepth); + if (pixmap == 0) SWT.error(SWT.ERROR_NO_HANDLES); + int gc = OS.XCreateGC(xDisplay, pixmap, 0, null); + int[] transPixel = null; + if (image.transparentPixel != -1) transPixel = new int[]{image.transparentPixel}; + int error = putImage(image, 0, 0, image.width, image.height, 0, 0, image.width, image.height, xDisplay, visual, screenDepth, device.xcolors, transPixel, false, pixmap, gc); + OS.XFreeGC(xDisplay, gc); + if (error != 0) { + OS.XFreePixmap (xDisplay, pixmap); + SWT.error(error); + } + if (image.getTransparencyType() == SWT.TRANSPARENCY_MASK || image.transparentPixel != -1) { + if (image.transparentPixel != -1) transparentPixel = transPixel[0]; + ImageData maskImage = image.getTransparencyMask(); + int mask = OS.XCreatePixmap(xDisplay, drawable, image.width, image.height, 1); + gc = OS.XCreateGC(xDisplay, mask, 0, null); + error = putImage(maskImage, 0, 0, maskImage.width, maskImage.height, 0, 0, maskImage.width, maskImage.height, xDisplay, visual, screenDepth, device.xcolors, null, true, mask, gc); + OS.XFreeGC(xDisplay, gc); + if (error != 0) { + OS.XFreePixmap (xDisplay, pixmap); + OS.XFreePixmap (xDisplay, mask); + SWT.error(error); + } + this.mask = mask; + if (image.getTransparencyType() == SWT.TRANSPARENCY_MASK) { + this.type = SWT.ICON; + } else { + this.type = SWT.BITMAP; + } + } else { + this.type = SWT.BITMAP; + this.mask = 0; + this.alpha = image.alpha; + if (image.alpha == -1 && image.alphaData != null) { + this.alphaData = new byte[image.alphaData.length]; + System.arraycopy(image.alphaData, 0, this.alphaData, 0, alphaData.length); + } + } + this.pixmap = pixmap; +} /** * Invokes platform specific functionality to allocate a new GC handle. * <p> @@ -1039,25 +1039,25 @@ void init(Device device, ImageData image) { * * @private */ -public int internal_new_GC (GCData data) {
- if (pixmap == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (type != SWT.BITMAP || memGC != null) {
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- }
- int xDisplay = device.xDisplay;
- int xGC = OS.XCreateGC (xDisplay, pixmap, 0, null);
- if (xGC == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- if (data != null) {
- data.device = device;
- data.display = xDisplay;
- data.drawable = pixmap;
- data.fontList = device.systemFont.handle;
- data.codePage = device.systemFont.codePage;
- data.colormap = OS.XDefaultColormap (xDisplay, OS.XDefaultScreen (xDisplay));
- data.image = this;
- }
- return xGC;
-}
+public int internal_new_GC (GCData data) { + if (pixmap == 0) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (type != SWT.BITMAP || memGC != null) { + SWT.error(SWT.ERROR_INVALID_ARGUMENT); + } + int xDisplay = device.xDisplay; + int xGC = OS.XCreateGC (xDisplay, pixmap, 0, null); + if (xGC == 0) SWT.error (SWT.ERROR_NO_HANDLES); + if (data != null) { + data.device = device; + data.display = xDisplay; + data.drawable = pixmap; + data.fontList = device.systemFont.handle; + data.codePage = device.systemFont.codePage; + data.colormap = OS.XDefaultColormap (xDisplay, OS.XDefaultScreen (xDisplay)); + data.image = this; + } + return xGC; +} /** * Invokes platform specific functionality to dispose a GC handle. * <p> @@ -1073,13 +1073,13 @@ public int internal_new_GC (GCData data) { * * @private */ -public void internal_dispose_GC (int gc, GCData data) {
+public void internal_dispose_GC (int gc, GCData data) { int xDisplay = 0; if (data != null) xDisplay = data.display; if (xDisplay == 0 && device != null) xDisplay = device.xDisplay; - if (xDisplay == 0) SWT.error (SWT.ERROR_NO_HANDLES);;
- OS.XFreeGC(xDisplay, gc);
-}
+ if (xDisplay == 0) SWT.error (SWT.ERROR_NO_HANDLES);; + OS.XFreeGC(xDisplay, gc); +} /** * Returns <code>true</code> if the image has been disposed, * and <code>false</code> otherwise. @@ -1090,250 +1090,250 @@ public void internal_dispose_GC (int gc, GCData data) { * * @return <code>true</code> when the image is disposed and <code>false</code> otherwise */ -public boolean isDisposed() {
- return pixmap == 0;
-}
-public static Image motif_new(Device device, int type, int pixmap, int mask) {
- if (device == null) device = Device.getDevice();
- Image image = new Image();
- image.device = device;
- image.type = type;
- image.pixmap = pixmap;
- image.mask = mask;
- return image;
-}
-/**
- * Put a device-independent image of any depth into a drawable of any depth,
- * stretching if necessary.
+public boolean isDisposed() { + return pixmap == 0; +} +public static Image motif_new(Device device, int type, int pixmap, int mask) { + if (device == null) device = Device.getDevice(); + Image image = new Image(); + image.device = device; + image.type = type; + image.pixmap = pixmap; + image.mask = mask; + return image; +} +/** + * Put a device-independent image of any depth into a drawable of any depth, + * stretching if necessary. */ -static int putImage(ImageData image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, int display, int visual, int screenDepth, XColor[] xcolors, int[] transparentPixel, boolean isMask, int drawable, int gc) {
- PaletteData palette = image.palette;
- if (!(((image.depth == 1 || image.depth == 2 || image.depth == 4 || image.depth == 8) && !palette.isDirect) ||
- ((image.depth == 8) || (image.depth == 16 || image.depth == 24 || image.depth == 32) && palette.isDirect)))
- return SWT.ERROR_UNSUPPORTED_DEPTH;
-
- boolean flipX = destWidth < 0;
- boolean flipY = destHeight < 0;
- if (flipX) {
- destWidth = -destWidth;
- destX = destX - destWidth;
- }
- if (flipY) {
- destHeight = -destHeight;
- destY = destY - destHeight;
- }
- byte[] srcReds = null, srcGreens = null, srcBlues = null;
- if (!palette.isDirect) {
- RGB[] rgbs = palette.getRGBs();
- int length = rgbs.length;
- srcReds = new byte[length];
- srcGreens = new byte[length];
- srcBlues = new byte[length];
- for (int i = 0; i < rgbs.length; i++) {
- RGB rgb = rgbs[i];
- if (rgb == null) continue;
- srcReds[i] = (byte)rgb.red;
- srcGreens[i] = (byte)rgb.green;
- srcBlues[i] = (byte)rgb.blue;
- }
- }
- byte[] destReds = null, destGreens = null, destBlues = null;
- int destRedMask = 0, destGreenMask = 0, destBlueMask = 0;
- final boolean screenDirect;
- if (screenDepth <= 8) {
- if (xcolors == null) return SWT.ERROR_UNSUPPORTED_DEPTH;
- destReds = new byte[xcolors.length];
- destGreens = new byte[xcolors.length];
- destBlues = new byte[xcolors.length];
- for (int i = 0; i < xcolors.length; i++) {
- XColor color = xcolors[i];
- if (color == null) continue;
- destReds[i] = (byte)((color.red >> 8) & 0xFF);
- destGreens[i] = (byte)((color.green >> 8) & 0xFF);
- destBlues[i] = (byte)((color.blue >> 8) & 0xFF);
- }
- screenDirect = false;
- } else {
- Visual xVisual = new Visual();
- OS.memmove(xVisual, visual, Visual.sizeof);
- destRedMask = xVisual.red_mask;
- destGreenMask = xVisual.green_mask;
- destBlueMask = xVisual.blue_mask;
- screenDirect = true;
- }
- if (transparentPixel != null) {
- int transRed = 0, transGreen = 0, transBlue = 0;
- if (palette.isDirect) {
- RGB rgb = palette.getRGB(transparentPixel[0]);
- transRed = rgb.red;
- transGreen = rgb.green;
- transBlue = rgb.blue;
- } else {
- RGB[] rgbs = palette.getRGBs();
- if (transparentPixel[0] < rgbs.length) {
- RGB rgb = rgbs[transparentPixel[0]];
- transRed = rgb.red;
- transGreen = rgb.green;
- transBlue = rgb.blue;
- }
- }
- transparentPixel[0] = ImageData.closestMatch(screenDepth, (byte)transRed, (byte)transGreen, (byte)transBlue,
- destRedMask, destGreenMask, destBlueMask, destReds, destGreens, destBlues);
- }
-
- /* Depth 1 */
- if (image.depth == 1) {
- int xImagePtr = OS.XCreateImage(display, visual, 1, OS.XYBitmap, 0, 0, destWidth, destHeight, image.scanlinePad * 8, 0);
- if (xImagePtr == 0) return SWT.ERROR_NO_HANDLES;
- XImage xImage = new XImage();
- OS.memmove(xImage, xImagePtr, XImage.sizeof);
- int bufSize = xImage.bytes_per_line * xImage.height;
- int bufPtr = OS.XtMalloc(bufSize);
- xImage.data = bufPtr;
- OS.memmove(xImagePtr, xImage, XImage.sizeof);
- byte[] buf = new byte[bufSize];
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, null, null, null,
- ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY,
- buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.bitmap_bit_order, 0, 0, destWidth, destHeight, null, null, null,
- flipX, flipY);
- OS.memmove(xImage.data, buf, bufSize);
-
- int foreground = 1, background = 0;
- if (!isMask) {
- foreground = 0;
- if (srcReds.length > 1) {
- foreground = ImageData.closestMatch(screenDepth, srcReds[1], srcGreens[1], srcBlues[1],
- destRedMask, destGreenMask, destBlueMask, destReds, destGreens, destBlues);
- }
- if (srcReds.length > 0) {
- background = ImageData.closestMatch(screenDepth, srcReds[0], srcGreens[0], srcBlues[0],
- destRedMask, destGreenMask, destBlueMask, destReds, destGreens, destBlues);
- }
- }
- XGCValues values = new XGCValues();
- OS.XGetGCValues(display, gc, OS.GCForeground | OS.GCBackground, values);
- OS.XSetForeground(display, gc, foreground);
- OS.XSetBackground(display, gc, background);
- OS.XPutImage(display, drawable, gc, xImagePtr, 0, 0, destX, destY, destWidth, destHeight);
- OS.XSetForeground(display, gc, values.foreground);
- OS.XSetBackground(display, gc, values.background);
- OS.XDestroyImage(xImagePtr);
- return 0;
- }
-
- /* Depths other than 1 */
- int xImagePtr = OS.XCreateImage(display, visual, screenDepth, OS.ZPixmap, 0, 0, destWidth, destHeight, image.scanlinePad * 8, 0);
- if (xImagePtr == 0) return SWT.ERROR_NO_HANDLES;
- XImage xImage = new XImage();
- OS.memmove(xImage, xImagePtr, XImage.sizeof);
- int bufSize = xImage.bytes_per_line * xImage.height;
- int bufPtr = OS.XtMalloc(bufSize);
- xImage.data = bufPtr;
- OS.memmove(xImagePtr, xImage, XImage.sizeof);
- byte[] buf = new byte[bufSize];
- if (palette.isDirect) {
- if (screenDirect) {
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, palette.redMask, palette.greenMask, palette.blueMask,
- ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY,
- buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, xImage.red_mask, xImage.green_mask, xImage.blue_mask,
- flipX, flipY);
- } else {
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, palette.redMask, palette.greenMask, palette.blueMask,
- ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY,
- buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, destReds, destGreens, destBlues,
- flipX, flipY);
- }
- } else {
- if (screenDirect) {
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, srcReds, srcGreens, srcBlues,
- ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY,
- buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, xImage.red_mask, xImage.green_mask, xImage.blue_mask,
- flipX, flipY);
- } else {
- ImageData.blit(ImageData.BLIT_SRC,
- image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, srcReds, srcGreens, srcBlues,
- ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY,
- buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, destReds, destGreens, destBlues,
- flipX, flipY);
- }
- }
- OS.memmove(xImage.data, buf, bufSize);
- OS.XPutImage(display, drawable, gc, xImagePtr, 0, 0, destX, destY, destWidth, destHeight);
- OS.XDestroyImage(xImagePtr);
- return 0;
-}
-/**
- * Sets the color to which to map the transparent pixel.
- * <p>
- * There are certain uses of <code>Images</code> that do not support
- * transparency (for example, setting an image into a button or label).
- * In these cases, it may be desired to simulate transparency by using
- * the background color of the widget to paint the transparent pixels
- * of the image. This method specifies the color that will be used in
- * these cases. For example:
- * <pre>
- * Button b = new Button();
- * image.setBackground(b.getBackground());>
- * b.setImage(image);
- * </pre>
- * </p><p>
- * The image may be modified by this operation (in effect, the
- * transparent regions may be filled with the supplied color). Hence
- * this operation is not reversible and it is not legal to call
- * this function twice or with a null argument.
- * </p><p>
- * This method has no effect if the receiver does not have a transparent
- * pixel value.
- * </p>
- *
- * @param color the color to use when a transparent pixel is specified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the color is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li>
- * </ul>
+static int putImage(ImageData image, int srcX, int srcY, int srcWidth, int srcHeight, int destX, int destY, int destWidth, int destHeight, int display, int visual, int screenDepth, XColor[] xcolors, int[] transparentPixel, boolean isMask, int drawable, int gc) { + PaletteData palette = image.palette; + if (!(((image.depth == 1 || image.depth == 2 || image.depth == 4 || image.depth == 8) && !palette.isDirect) || + ((image.depth == 8) || (image.depth == 16 || image.depth == 24 || image.depth == 32) && palette.isDirect))) + return SWT.ERROR_UNSUPPORTED_DEPTH; + + boolean flipX = destWidth < 0; + boolean flipY = destHeight < 0; + if (flipX) { + destWidth = -destWidth; + destX = destX - destWidth; + } + if (flipY) { + destHeight = -destHeight; + destY = destY - destHeight; + } + byte[] srcReds = null, srcGreens = null, srcBlues = null; + if (!palette.isDirect) { + RGB[] rgbs = palette.getRGBs(); + int length = rgbs.length; + srcReds = new byte[length]; + srcGreens = new byte[length]; + srcBlues = new byte[length]; + for (int i = 0; i < rgbs.length; i++) { + RGB rgb = rgbs[i]; + if (rgb == null) continue; + srcReds[i] = (byte)rgb.red; + srcGreens[i] = (byte)rgb.green; + srcBlues[i] = (byte)rgb.blue; + } + } + byte[] destReds = null, destGreens = null, destBlues = null; + int destRedMask = 0, destGreenMask = 0, destBlueMask = 0; + final boolean screenDirect; + if (screenDepth <= 8) { + if (xcolors == null) return SWT.ERROR_UNSUPPORTED_DEPTH; + destReds = new byte[xcolors.length]; + destGreens = new byte[xcolors.length]; + destBlues = new byte[xcolors.length]; + for (int i = 0; i < xcolors.length; i++) { + XColor color = xcolors[i]; + if (color == null) continue; + destReds[i] = (byte)((color.red >> 8) & 0xFF); + destGreens[i] = (byte)((color.green >> 8) & 0xFF); + destBlues[i] = (byte)((color.blue >> 8) & 0xFF); + } + screenDirect = false; + } else { + Visual xVisual = new Visual(); + OS.memmove(xVisual, visual, Visual.sizeof); + destRedMask = xVisual.red_mask; + destGreenMask = xVisual.green_mask; + destBlueMask = xVisual.blue_mask; + screenDirect = true; + } + if (transparentPixel != null) { + int transRed = 0, transGreen = 0, transBlue = 0; + if (palette.isDirect) { + RGB rgb = palette.getRGB(transparentPixel[0]); + transRed = rgb.red; + transGreen = rgb.green; + transBlue = rgb.blue; + } else { + RGB[] rgbs = palette.getRGBs(); + if (transparentPixel[0] < rgbs.length) { + RGB rgb = rgbs[transparentPixel[0]]; + transRed = rgb.red; + transGreen = rgb.green; + transBlue = rgb.blue; + } + } + transparentPixel[0] = ImageData.closestMatch(screenDepth, (byte)transRed, (byte)transGreen, (byte)transBlue, + destRedMask, destGreenMask, destBlueMask, destReds, destGreens, destBlues); + } + + /* Depth 1 */ + if (image.depth == 1) { + int xImagePtr = OS.XCreateImage(display, visual, 1, OS.XYBitmap, 0, 0, destWidth, destHeight, image.scanlinePad * 8, 0); + if (xImagePtr == 0) return SWT.ERROR_NO_HANDLES; + XImage xImage = new XImage(); + OS.memmove(xImage, xImagePtr, XImage.sizeof); + int bufSize = xImage.bytes_per_line * xImage.height; + int bufPtr = OS.XtMalloc(bufSize); + xImage.data = bufPtr; + OS.memmove(xImagePtr, xImage, XImage.sizeof); + byte[] buf = new byte[bufSize]; + ImageData.blit(ImageData.BLIT_SRC, + image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, null, null, null, + ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY, + buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.bitmap_bit_order, 0, 0, destWidth, destHeight, null, null, null, + flipX, flipY); + OS.memmove(xImage.data, buf, bufSize); + + int foreground = 1, background = 0; + if (!isMask) { + foreground = 0; + if (srcReds.length > 1) { + foreground = ImageData.closestMatch(screenDepth, srcReds[1], srcGreens[1], srcBlues[1], + destRedMask, destGreenMask, destBlueMask, destReds, destGreens, destBlues); + } + if (srcReds.length > 0) { + background = ImageData.closestMatch(screenDepth, srcReds[0], srcGreens[0], srcBlues[0], + destRedMask, destGreenMask, destBlueMask, destReds, destGreens, destBlues); + } + } + XGCValues values = new XGCValues(); + OS.XGetGCValues(display, gc, OS.GCForeground | OS.GCBackground, values); + OS.XSetForeground(display, gc, foreground); + OS.XSetBackground(display, gc, background); + OS.XPutImage(display, drawable, gc, xImagePtr, 0, 0, destX, destY, destWidth, destHeight); + OS.XSetForeground(display, gc, values.foreground); + OS.XSetBackground(display, gc, values.background); + OS.XDestroyImage(xImagePtr); + return 0; + } + + /* Depths other than 1 */ + int xImagePtr = OS.XCreateImage(display, visual, screenDepth, OS.ZPixmap, 0, 0, destWidth, destHeight, image.scanlinePad * 8, 0); + if (xImagePtr == 0) return SWT.ERROR_NO_HANDLES; + XImage xImage = new XImage(); + OS.memmove(xImage, xImagePtr, XImage.sizeof); + int bufSize = xImage.bytes_per_line * xImage.height; + int bufPtr = OS.XtMalloc(bufSize); + xImage.data = bufPtr; + OS.memmove(xImagePtr, xImage, XImage.sizeof); + byte[] buf = new byte[bufSize]; + if (palette.isDirect) { + if (screenDirect) { + ImageData.blit(ImageData.BLIT_SRC, + image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, palette.redMask, palette.greenMask, palette.blueMask, + ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY, + buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, xImage.red_mask, xImage.green_mask, xImage.blue_mask, + flipX, flipY); + } else { + ImageData.blit(ImageData.BLIT_SRC, + image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, palette.redMask, palette.greenMask, palette.blueMask, + ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY, + buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, destReds, destGreens, destBlues, + flipX, flipY); + } + } else { + if (screenDirect) { + ImageData.blit(ImageData.BLIT_SRC, + image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, srcReds, srcGreens, srcBlues, + ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY, + buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, xImage.red_mask, xImage.green_mask, xImage.blue_mask, + flipX, flipY); + } else { + ImageData.blit(ImageData.BLIT_SRC, + image.data, image.depth, image.bytesPerLine, image.getByteOrder(), srcX, srcY, srcWidth, srcHeight, srcReds, srcGreens, srcBlues, + ImageData.ALPHA_OPAQUE, null, 0, srcX, srcY, + buf, xImage.bits_per_pixel, xImage.bytes_per_line, xImage.byte_order, 0, 0, destWidth, destHeight, destReds, destGreens, destBlues, + flipX, flipY); + } + } + OS.memmove(xImage.data, buf, bufSize); + OS.XPutImage(display, drawable, gc, xImagePtr, 0, 0, destX, destY, destWidth, destHeight); + OS.XDestroyImage(xImagePtr); + return 0; +} +/** + * Sets the color to which to map the transparent pixel. + * <p> + * There are certain uses of <code>Images</code> that do not support + * transparency (for example, setting an image into a button or label). + * In these cases, it may be desired to simulate transparency by using + * the background color of the widget to paint the transparent pixels + * of the image. This method specifies the color that will be used in + * these cases. For example: + * <pre> + * Button b = new Button(); + * image.setBackground(b.getBackground());> + * b.setImage(image); + * </pre> + * </p><p> + * The image may be modified by this operation (in effect, the + * transparent regions may be filled with the supplied color). Hence + * this operation is not reversible and it is not legal to call + * this function twice or with a null argument. + * </p><p> + * This method has no effect if the receiver does not have a transparent + * pixel value. + * </p> + * + * @param color the color to use when a transparent pixel is specified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the color is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the color has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> + * </ul> */ -public void setBackground(Color color) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if (transparentPixel == -1) return;
- /* Generate the mask if necessary. */
- if (mask == 0) createMask();
- Rectangle bounds = getBounds();
- int[] unused = new int[1];
- int[] depth = new int[1];
- int xDisplay = device.xDisplay;
- OS.XGetGeometry(xDisplay, pixmap, unused, unused, unused, unused, unused, unused, depth);
- int drawable = OS.XDefaultRootWindow(xDisplay);
- int tempPixmap = OS.XCreatePixmap(xDisplay, drawable, bounds.width, bounds.height, depth[0]);
- int xGC = OS.XCreateGC(xDisplay, tempPixmap, 0, null);
- OS.XSetForeground(xDisplay, xGC, color.handle.pixel);
- OS.XFillRectangle(xDisplay, tempPixmap, xGC, 0, 0, bounds.width, bounds.height);
- OS.XSetClipMask(xDisplay, xGC, mask);
- OS.XCopyArea(xDisplay, pixmap, tempPixmap, xGC, 0, 0, bounds.width, bounds.height, 0, 0);
- OS.XSetClipMask(xDisplay, xGC, OS.None);
- OS.XCopyArea(xDisplay, tempPixmap, pixmap, xGC, 0, 0, bounds.width, bounds.height, 0, 0);
- OS.XFreePixmap(xDisplay, tempPixmap);
- OS.XFreeGC(xDisplay, xGC);
- /* Destroy the receiver's mask if the there is a GC created on it */
- if (memGC != null) destroyMask();
-}
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
+public void setBackground(Color color) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (color == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + if (transparentPixel == -1) return; + /* Generate the mask if necessary. */ + if (mask == 0) createMask(); + Rectangle bounds = getBounds(); + int[] unused = new int[1]; + int[] depth = new int[1]; + int xDisplay = device.xDisplay; + OS.XGetGeometry(xDisplay, pixmap, unused, unused, unused, unused, unused, unused, depth); + int drawable = OS.XDefaultRootWindow(xDisplay); + int tempPixmap = OS.XCreatePixmap(xDisplay, drawable, bounds.width, bounds.height, depth[0]); + int xGC = OS.XCreateGC(xDisplay, tempPixmap, 0, null); + OS.XSetForeground(xDisplay, xGC, color.handle.pixel); + OS.XFillRectangle(xDisplay, tempPixmap, xGC, 0, 0, bounds.width, bounds.height); + OS.XSetClipMask(xDisplay, xGC, mask); + OS.XCopyArea(xDisplay, pixmap, tempPixmap, xGC, 0, 0, bounds.width, bounds.height, 0, 0); + OS.XSetClipMask(xDisplay, xGC, OS.None); + OS.XCopyArea(xDisplay, tempPixmap, pixmap, xGC, 0, 0, bounds.width, bounds.height, 0, 0); + OS.XFreePixmap(xDisplay, tempPixmap); + OS.XFreeGC(xDisplay, xGC); + /* Destroy the receiver's mask if the there is a GC created on it */ + if (memGC != null) destroyMask(); +} +/** + * Returns a string containing a concise, human-readable + * description of the receiver. + * + * @return a string representation of the receiver */ -public String toString () {
- if (isDisposed()) return "Image {*DISPOSED*}";
- return "Image {" + pixmap + "}";
-}
-}
+public String toString () { + if (isDisposed()) return "Image {*DISPOSED*}"; + return "Image {" + pixmap + "}"; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java index 09ed1152da..e96a080d69 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/graphics/Region.java @@ -1,15 +1,15 @@ -package org.eclipse.swt.graphics;
-
-/*
+package org.eclipse.swt.graphics; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; + /** * Instances of this class represent areas of an x-y coordinate * system that are aggregates of the areas covered by a number @@ -20,12 +20,12 @@ import org.eclipse.swt.*; * when those instances are no longer required. * </p> */ -public final class Region {
+public final class Region { /** * the OS resource for the region * (Warning: This field is platform dependent) */ - public int handle;
+ public int handle; /** * Constructs a new empty region. * @@ -33,12 +33,12 @@ public final class Region { * <li>ERROR_NO_HANDLES if a handle could not be obtained for region creation</li> * </ul> */ -public Region () {
- handle = OS.XCreateRegion ();
-}
-Region (int handle) {
- this.handle = handle;
-}
+public Region () { + handle = OS.XCreateRegion (); +} +Region (int handle) { + this.handle = handle; +} /** * Adds the given rectangle to the collection of rectangles * the receiver maintains to describe its area. @@ -53,18 +53,18 @@ Region (int handle) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void add (Rectangle rect) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (rect.width < 0 || rect.height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-
- XRectangle xRect = new XRectangle();
- xRect.x = (short)rect.x;
- xRect.y = (short)rect.y;
- xRect.width = (short)rect.width;
- xRect.height = (short)rect.height;
- OS.XUnionRectWithRegion(xRect, handle, handle);
-}
+public void add (Rectangle rect) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (rect.width < 0 || rect.height < 0) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + + XRectangle xRect = new XRectangle(); + xRect.x = (short)rect.x; + xRect.y = (short)rect.y; + xRect.width = (short)rect.width; + xRect.height = (short)rect.height; + OS.XUnionRectWithRegion(xRect, handle, handle); +} /** * Adds all of the rectangles which make up the area covered * by the argument to the collection of rectangles the receiver @@ -80,12 +80,12 @@ public void add (Rectangle rect) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public void add (Region region) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- OS.XUnionRegion(handle, region.handle, handle);
-}
+public void add (Region region) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + if (region == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if (region.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + OS.XUnionRegion(handle, region.handle, handle); +} /** * Returns <code>true</code> if the point specified by the * arguments is inside the area specified by the receiver, @@ -99,10 +99,10 @@ public void add (Region region) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public boolean contains (int x, int y) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return OS.XPointInRegion(handle, x, y);
-}
+public boolean contains (int x, int y) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return OS.XPointInRegion(handle, x, y); +} /** * Returns <code>true</code> if the given point is inside the * area specified by the receiver, and <code>false</code> @@ -118,19 +118,19 @@ public boolean contains (int x, int y) { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public boolean contains (Point pt) {
- if (pt == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return contains(pt.x, pt.y);
-}
+public boolean contains (Point pt) { + if (pt == null) SWT.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.XDestroyRegion(handle);
- handle = 0;
-}
+public void dispose () { + if (handle != 0) OS.XDestroyRegion(handle); + handle = 0; +} /** * Compares the argument to the receiver, and returns true * if they represent the <em>same</em> object using a class @@ -141,12 +141,12 @@ public void dispose () { * * @see #hashCode */ -public boolean equals (Object object) {
- if (this == object) return true;
- if (!(object instanceof Region)) return false;
- Region region = (Region)object;
- return handle == region.handle;
-}
+public boolean equals (Object object) { + if (this == object) return true; + if (!(object instanceof Region)) return false; + Region region = (Region)object; + return handle == region.handle; +} /** * Returns a rectangle which represents the rectangular * union of the collection of rectangles the receiver @@ -160,12 +160,12 @@ public boolean equals (Object object) { * * @see Rectangle#union */ -public Rectangle getBounds() {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- XRectangle rect = new XRectangle();
- OS.XClipBox(handle, rect);
- return new Rectangle(rect.x, rect.y, rect.width, rect.height);
-}
+public Rectangle getBounds() { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + XRectangle rect = new XRectangle(); + OS.XClipBox(handle, rect); + return new Rectangle(rect.x, rect.y, rect.width, rect.height); +} /** * Returns an integer hash code for the receiver. Any two * objects which return <code>true</code> when passed to @@ -176,9 +176,9 @@ public Rectangle getBounds() { * * @see #equals */ -public int hashCode () {
- return handle;
-}
+public int hashCode () { + return handle; +} /** * Returns <code>true</code> if the rectangle described by the * arguments intersects with any of the rectangles the receiver @@ -196,10 +196,10 @@ public int hashCode () { * * @see Rectangle#intersects */ -public boolean intersects (int x, int y, int width, int height) {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return OS.XRectInRegion (handle, x, y, width, height) != OS.RectangleOut;
-}
+public boolean intersects (int x, int y, int width, int height) { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return OS.XRectInRegion (handle, x, y, width, height) != OS.RectangleOut; +} /** * Returns <code>true</code> if the given rectangle intersects * with any of the rectangles the receiver mainains to describe @@ -217,10 +217,10 @@ public boolean intersects (int x, int y, int width, int height) { * * @see Rectangle#intersects */ -public boolean intersects (Rectangle rect) {
- if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT);
- return intersects(rect.x, rect.y, rect.width, rect.height);
-}
+public boolean intersects (Rectangle rect) { + if (rect == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + return intersects(rect.x, rect.y, rect.width, rect.height); +} /** * Returns <code>true</code> if the region has been disposed, * and <code>false</code> otherwise. @@ -231,9 +231,9 @@ public boolean intersects (Rectangle rect) { * * @return <code>true</code> when the region is disposed, and <code>false</code> otherwise */ -public boolean isDisposed() {
- return handle == 0;
-}
+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 @@ -245,21 +245,21 @@ public boolean isDisposed() { * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> * </ul> */ -public boolean isEmpty () {
- if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
- return OS.XEmptyRegion(handle);
-}
-public static Region motif_new(int handle) {
- return new Region(handle);
-}
-/**
- * Returns a string containing a concise, human-readable
- * description of the receiver.
- *
- * @return a string representation of the receiver
+public boolean isEmpty () { + if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); + return OS.XEmptyRegion(handle); +} +public static Region motif_new(int handle) { + return new Region(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 + "}";
-}
-}
+public String toString () { + if (isDisposed()) return "Region {*DISPOSED*}"; + return "Region {" + handle + "}"; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java index 49dd363819..8d48870665 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/internal/Converter.java @@ -1,14 +1,14 @@ -package org.eclipse.swt.internal;
-
-/*
+package org.eclipse.swt.internal; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.motif.*; + /** * This class implements the conversions between unicode characters * and the <em>platform supported</em> representation for characters. @@ -16,300 +16,300 @@ import org.eclipse.swt.internal.motif.*; * Note that, unicode characters which can not be found in the platform * encoding will be converted to an arbitrary platform specific character. * </p> - */
-
-public final class Converter {
-
- static final byte [] NULL_BYTE_ARRAY = new byte [1];
- static final byte [] EMPTY_BYTE_ARRAY = new byte [0];
- static final char [] EMPTY_CHAR_ARRAY = new char [0];
-
- static String CodePage;
- static byte[] Unicode;
-
- static final Object LOCK = new Object ();
-
- /* Converter cache */
- static String LastMBToWCCodePage;
- static String LastWCToMBCodePage;
- static int LastWCToMB;
- static int LastMBToWC;
-
- /* Buffers cache */
- static int BufferSize;
- static int BufferTimes2;
- static int BufferTimes4;
-
- static {
- Unicode = getAsciiBytes("UCS-2");
-
- int length, item = OS.nl_langinfo (OS.CODESET);
- if (item != 0 && (length = OS.strlen (item)) > 0) {
- byte [] buffer = new byte [length];
- OS.memmove (buffer, item, length);
- CodePage = new String (buffer);
- if (OS.IsSunOS) {
- if (length > 3 && CodePage.indexOf ("ISO") == 0) {
- CodePage = CodePage.substring (3, length);
- }
- }
- } else {
- if (OS.IsLinux) CodePage = "ISO-8859-1";
- else if (OS.IsAIX) CodePage = "ISO8859-1";
- else if (OS.IsSunOS) CodePage = "8859-1";
- else CodePage = "iso8859_1";
- }
-
- BufferSize = 512;
- BufferTimes2 = OS.XtMalloc (BufferSize * 2);
- BufferTimes4 = OS.XtMalloc (BufferSize * 4);
- }
-
-/**
- * Returns the default code page for the platform where the
- * application is currently running.
- *
- * @return the default code page
- */
-public static String defaultCodePage () {
- return CodePage;
-}
-
-static byte[] getAsciiBytes (String str) {
- int length = str.length ();
- byte [] buffer = new byte [length + 1];
- for (int i=0; i<length; i++) {
- buffer [i] = (byte)str.charAt (i);
- }
- return buffer;
-}
-
-static String getAsciiString (byte [] buffer) {
- int length = buffer.length;
- char [] chars = new char [length];
- for (int i=0; i<length; i++) {
- chars [i] = (char)buffer [i];
- }
- return new String (chars);
-}
-
-/**
- * Converts an array of bytes representing the platform's encoding,
- * in the given code page, of some character data into an array of
- * matching unicode characters.
- *
- * @param codePage the code page to use for conversion
- * @param buffer the array of bytes to be converted
- * @return the unicode conversion
- */
-public static char [] mbcsToWcs (String codePage, byte [] buffer) {
-
- /* Check for the simple cases */
- if (buffer == null) {
- return EMPTY_CHAR_ARRAY;
- }
- int length = buffer.length;
- if (length == 0) {
- return EMPTY_CHAR_ARRAY;
- }
-
- /*
- * Optimize for English ASCII encoding. If no conversion is
- * performed, it is safe to return any object that will also not
- * be converted if this routine is called again with the result.
- * This ensures that double conversion will not be performed
- * on the same bytes. Note that this relies on the fact that
- * lead bytes are never in the range 0..0x7F.
- */
- char [] wideCharStr = new char [length];
- for (int i=0; i<length; i++) {
- if ((buffer [i] & 0xFF) <= 0x7F) {
- wideCharStr [i] = (char) buffer [i]; // all bytes <= 0x7F, so no ((char) (buffer[i]&0xFF)) needed
- } else {
- synchronized (LOCK) {
- String cp = codePage != null ? codePage : CodePage;
- if (LastMBToWC != 0 && !cp.equals (LastMBToWCCodePage)) {
- OS.iconv_close (LastMBToWC);
- LastMBToWC = 0;
- }
- if (LastMBToWC == 0) {
- LastMBToWCCodePage = cp;
- LastMBToWC = OS.iconv_open (Unicode, getAsciiBytes (cp));
- if (LastMBToWC == -1) LastMBToWC = 0;
- }
- int cd = LastMBToWC;
- if (cd == 0) return EMPTY_CHAR_ARRAY;
- int inBytes = length;
- int outBytes = length * 2;
- int ptr1, ptr2;
- if (length <= BufferSize * 2) {
- ptr1 = BufferTimes2;
- ptr2 = BufferTimes4;
- } else {
- ptr1 = OS.XtMalloc (inBytes);
- ptr2 = OS.XtMalloc (outBytes);
- }
- int [] inBuf = {ptr1};
- int [] inBytesLeft = {inBytes};
- int [] outBuf = {ptr2};
- int [] outBytesLeft = {outBytes};
- OS.memmove (ptr1, buffer, inBytes);
- OS.iconv (cd, inBuf, inBytesLeft, outBuf, outBytesLeft);
- outBytes = outBuf [0] - ptr2;
- wideCharStr = new char [outBytes / 2];
- OS.memmove (wideCharStr, ptr2, outBytes);
- if (ptr1 != BufferTimes2) OS.XtFree (ptr1);
- if (ptr2 != BufferTimes4) OS.XtFree (ptr2);
- }
- return wideCharStr;
- }
- }
- return wideCharStr;
-}
-
-/**
- * Free any cached resources.
- */
-public static void release () {
- synchronized (LOCK) {
- if (BufferTimes2 != 0) OS.XtFree (BufferTimes2);
- if (BufferTimes4 != 0) OS.XtFree (BufferTimes4);
- if (LastWCToMB != 0) OS.iconv_close (LastWCToMB);
- if (LastMBToWC != 0) OS.iconv_close (LastMBToWC);
- LastMBToWC = LastWCToMB = BufferTimes4 = BufferTimes2 = 0;
- }
-}
-
-/**
- * Converts an array of chars (containing unicode data) to an array
- * of bytes representing the platform's encoding, of those characters
- * in the given code page.
- *
- * @param codePage the code page to use for conversion
- * @param buffer the array of chars to be converted
- * @return the platform encoding
- */
-public static byte [] wcsToMbcs (String codePage, char [] buffer) {
- return wcsToMbcs (codePage, buffer, false);
-}
-
-/**
- * Converts an array of chars (containing unicode data) to an array
- * of bytes representing the platform's encoding, of those characters
- * in the given code page. If the termination flag is true, the resulting
- * byte data will be null (zero) terminated.
- *
- * @param codePage the code page to use for conversion
- * @param buffer the array of chars to be converted
- * @param terminate <code>true</code> if the result should be null terminated and false otherwise.
- * @return the platform encoding
- */
-public static byte [] wcsToMbcs (String codePage, char [] buffer, boolean terminate) {
-
- /* Check for the simple cases */
- if (buffer == null) {
- return (terminate) ? NULL_BYTE_ARRAY : EMPTY_BYTE_ARRAY;
- }
- int length = buffer.length;
- if (length == 0) {
- return (terminate) ? NULL_BYTE_ARRAY : EMPTY_BYTE_ARRAY;
- }
-
- /*
- * Optimize for English ASCII encoding. This optimization
- * relies on the fact that lead bytes can never be in the
- * range 0..0x7F.
- */
- byte [] mbcs = new byte [(terminate) ? length + 1 : length];
- for (int i=0; i<length; i++) {
- if ((buffer [i] & 0xFFFF) <= 0x7F) {
- mbcs [i] = (byte) buffer [i];
- } else {
- synchronized (LOCK) {
- String cp = codePage != null ? codePage : CodePage;
- if (LastWCToMB != 0 && !cp.equals (LastWCToMBCodePage)) {
- OS.iconv_close (LastWCToMB);
- LastWCToMB = 0;
- }
- if (LastWCToMB == 0) {
- LastWCToMBCodePage = cp;
- LastWCToMB = OS.iconv_open (getAsciiBytes (cp), Unicode);
- if (LastWCToMB == -1) LastWCToMB = 0;
- }
- int cd = LastWCToMB;
- if (cd == 0) return (terminate) ? NULL_BYTE_ARRAY : EMPTY_BYTE_ARRAY;
- int inBytes = length * 2;
- int outBytes = length * 4;
- int ptr1, ptr2;
- if (length <= BufferSize) {
- ptr1 = BufferTimes2;
- ptr2 = BufferTimes4;
- } else {
- ptr1 = OS.XtMalloc (inBytes);
- ptr2 = OS.XtMalloc (outBytes);
- }
- int [] inBuf = {ptr1};
- int [] inBytesLeft = {inBytes};
- int [] outBuf = {ptr2};
- int [] outBytesLeft = {outBytes};
- OS.memmove (ptr1, buffer, inBytes);
- while (inBytesLeft [0] > 0) {
- OS.iconv (cd, inBuf, inBytesLeft, outBuf, outBytesLeft);
- if (inBytesLeft [0] != 0) {
- inBuf [0] += 2;
- inBytesLeft [0] -= 2;
- }
- }
- outBytes = outBuf [0] - ptr2;
- mbcs = new byte [terminate ? outBytes + 1 : outBytes];
- OS.memmove (mbcs, ptr2, outBytes);
- if (ptr1 != BufferTimes2) OS.XtFree (ptr1);
- if (ptr2 != BufferTimes4) OS.XtFree (ptr2);
- }
- return mbcs;
- }
- }
- return mbcs;
-}
-
-/**
- * Converts a String (containing unicode data) to an array
- * of bytes representing the platform's encoding, of those characters
- * in the given code page.
- *
- * @param codePage the code page to use for conversion
- * @param string the string to be converted
- * @return the platform encoding
- */
-public static byte [] wcsToMbcs (String codePage, String string) {
- return wcsToMbcs (codePage, string, false);
-}
-
-/**
- * Converts a String (containing unicode data) to an array
- * of bytes representing the platform's encoding, of those characters
- * in the given code page. If the termination flag is true, the resulting
- * byte data will be null (zero) terminated.
- *
- * @param codePage the code page to use for conversion
- * @param string the string to be converted
- * @param terminate <code>true</code> if the result should be null terminated and false otherwise.
- * @return the platform encoding
- */
-public static byte [] wcsToMbcs (String codePage, String string, boolean terminate) {
- if (terminate) {
- if (string == null) return NULL_BYTE_ARRAY;
- int count = string.length ();
- char [] buffer = new char [count + 1];
- string.getChars (0, count, buffer, 0);
- return wcsToMbcs (codePage, buffer, false);
- } else {
- if (string == null) return EMPTY_BYTE_ARRAY;
- int count = string.length ();
- char [] buffer = new char [count];
- string.getChars (0, count, buffer, 0);
- return wcsToMbcs (codePage, buffer, false);
- }
-}
-
-}
+ */ + +public final class Converter { + + static final byte [] NULL_BYTE_ARRAY = new byte [1]; + static final byte [] EMPTY_BYTE_ARRAY = new byte [0]; + static final char [] EMPTY_CHAR_ARRAY = new char [0]; + + static String CodePage; + static byte[] Unicode; + + static final Object LOCK = new Object (); + + /* Converter cache */ + static String LastMBToWCCodePage; + static String LastWCToMBCodePage; + static int LastWCToMB; + static int LastMBToWC; + + /* Buffers cache */ + static int BufferSize; + static int BufferTimes2; + static int BufferTimes4; + + static { + Unicode = getAsciiBytes("UCS-2"); + + int length, item = OS.nl_langinfo (OS.CODESET); + if (item != 0 && (length = OS.strlen (item)) > 0) { + byte [] buffer = new byte [length]; + OS.memmove (buffer, item, length); + CodePage = new String (buffer); + if (OS.IsSunOS) { + if (length > 3 && CodePage.indexOf ("ISO") == 0) { + CodePage = CodePage.substring (3, length); + } + } + } else { + if (OS.IsLinux) CodePage = "ISO-8859-1"; + else if (OS.IsAIX) CodePage = "ISO8859-1"; + else if (OS.IsSunOS) CodePage = "8859-1"; + else CodePage = "iso8859_1"; + } + + BufferSize = 512; + BufferTimes2 = OS.XtMalloc (BufferSize * 2); + BufferTimes4 = OS.XtMalloc (BufferSize * 4); + } + +/** + * Returns the default code page for the platform where the + * application is currently running. + * + * @return the default code page + */ +public static String defaultCodePage () { + return CodePage; +} + +static byte[] getAsciiBytes (String str) { + int length = str.length (); + byte [] buffer = new byte [length + 1]; + for (int i=0; i<length; i++) { + buffer [i] = (byte)str.charAt (i); + } + return buffer; +} + +static String getAsciiString (byte [] buffer) { + int length = buffer.length; + char [] chars = new char [length]; + for (int i=0; i<length; i++) { + chars [i] = (char)buffer [i]; + } + return new String (chars); +} + +/** + * Converts an array of bytes representing the platform's encoding, + * in the given code page, of some character data into an array of + * matching unicode characters. + * + * @param codePage the code page to use for conversion + * @param buffer the array of bytes to be converted + * @return the unicode conversion + */ +public static char [] mbcsToWcs (String codePage, byte [] buffer) { + + /* Check for the simple cases */ + if (buffer == null) { + return EMPTY_CHAR_ARRAY; + } + int length = buffer.length; + if (length == 0) { + return EMPTY_CHAR_ARRAY; + } + + /* + * Optimize for English ASCII encoding. If no conversion is + * performed, it is safe to return any object that will also not + * be converted if this routine is called again with the result. + * This ensures that double conversion will not be performed + * on the same bytes. Note that this relies on the fact that + * lead bytes are never in the range 0..0x7F. + */ + char [] wideCharStr = new char [length]; + for (int i=0; i<length; i++) { + if ((buffer [i] & 0xFF) <= 0x7F) { + wideCharStr [i] = (char) buffer [i]; // all bytes <= 0x7F, so no ((char) (buffer[i]&0xFF)) needed + } else { + synchronized (LOCK) { + String cp = codePage != null ? codePage : CodePage; + if (LastMBToWC != 0 && !cp.equals (LastMBToWCCodePage)) { + OS.iconv_close (LastMBToWC); + LastMBToWC = 0; + } + if (LastMBToWC == 0) { + LastMBToWCCodePage = cp; + LastMBToWC = OS.iconv_open (Unicode, getAsciiBytes (cp)); + if (LastMBToWC == -1) LastMBToWC = 0; + } + int cd = LastMBToWC; + if (cd == 0) return EMPTY_CHAR_ARRAY; + int inBytes = length; + int outBytes = length * 2; + int ptr1, ptr2; + if (length <= BufferSize * 2) { + ptr1 = BufferTimes2; + ptr2 = BufferTimes4; + } else { + ptr1 = OS.XtMalloc (inBytes); + ptr2 = OS.XtMalloc (outBytes); + } + int [] inBuf = {ptr1}; + int [] inBytesLeft = {inBytes}; + int [] outBuf = {ptr2}; + int [] outBytesLeft = {outBytes}; + OS.memmove (ptr1, buffer, inBytes); + OS.iconv (cd, inBuf, inBytesLeft, outBuf, outBytesLeft); + outBytes = outBuf [0] - ptr2; + wideCharStr = new char [outBytes / 2]; + OS.memmove (wideCharStr, ptr2, outBytes); + if (ptr1 != BufferTimes2) OS.XtFree (ptr1); + if (ptr2 != BufferTimes4) OS.XtFree (ptr2); + } + return wideCharStr; + } + } + return wideCharStr; +} + +/** + * Free any cached resources. + */ +public static void release () { + synchronized (LOCK) { + if (BufferTimes2 != 0) OS.XtFree (BufferTimes2); + if (BufferTimes4 != 0) OS.XtFree (BufferTimes4); + if (LastWCToMB != 0) OS.iconv_close (LastWCToMB); + if (LastMBToWC != 0) OS.iconv_close (LastMBToWC); + LastMBToWC = LastWCToMB = BufferTimes4 = BufferTimes2 = 0; + } +} + +/** + * Converts an array of chars (containing unicode data) to an array + * of bytes representing the platform's encoding, of those characters + * in the given code page. + * + * @param codePage the code page to use for conversion + * @param buffer the array of chars to be converted + * @return the platform encoding + */ +public static byte [] wcsToMbcs (String codePage, char [] buffer) { + return wcsToMbcs (codePage, buffer, false); +} + +/** + * Converts an array of chars (containing unicode data) to an array + * of bytes representing the platform's encoding, of those characters + * in the given code page. If the termination flag is true, the resulting + * byte data will be null (zero) terminated. + * + * @param codePage the code page to use for conversion + * @param buffer the array of chars to be converted + * @param terminate <code>true</code> if the result should be null terminated and false otherwise. + * @return the platform encoding + */ +public static byte [] wcsToMbcs (String codePage, char [] buffer, boolean terminate) { + + /* Check for the simple cases */ + if (buffer == null) { + return (terminate) ? NULL_BYTE_ARRAY : EMPTY_BYTE_ARRAY; + } + int length = buffer.length; + if (length == 0) { + return (terminate) ? NULL_BYTE_ARRAY : EMPTY_BYTE_ARRAY; + } + + /* + * Optimize for English ASCII encoding. This optimization + * relies on the fact that lead bytes can never be in the + * range 0..0x7F. + */ + byte [] mbcs = new byte [(terminate) ? length + 1 : length]; + for (int i=0; i<length; i++) { + if ((buffer [i] & 0xFFFF) <= 0x7F) { + mbcs [i] = (byte) buffer [i]; + } else { + synchronized (LOCK) { + String cp = codePage != null ? codePage : CodePage; + if (LastWCToMB != 0 && !cp.equals (LastWCToMBCodePage)) { + OS.iconv_close (LastWCToMB); + LastWCToMB = 0; + } + if (LastWCToMB == 0) { + LastWCToMBCodePage = cp; + LastWCToMB = OS.iconv_open (getAsciiBytes (cp), Unicode); + if (LastWCToMB == -1) LastWCToMB = 0; + } + int cd = LastWCToMB; + if (cd == 0) return (terminate) ? NULL_BYTE_ARRAY : EMPTY_BYTE_ARRAY; + int inBytes = length * 2; + int outBytes = length * 4; + int ptr1, ptr2; + if (length <= BufferSize) { + ptr1 = BufferTimes2; + ptr2 = BufferTimes4; + } else { + ptr1 = OS.XtMalloc (inBytes); + ptr2 = OS.XtMalloc (outBytes); + } + int [] inBuf = {ptr1}; + int [] inBytesLeft = {inBytes}; + int [] outBuf = {ptr2}; + int [] outBytesLeft = {outBytes}; + OS.memmove (ptr1, buffer, inBytes); + while (inBytesLeft [0] > 0) { + OS.iconv (cd, inBuf, inBytesLeft, outBuf, outBytesLeft); + if (inBytesLeft [0] != 0) { + inBuf [0] += 2; + inBytesLeft [0] -= 2; + } + } + outBytes = outBuf [0] - ptr2; + mbcs = new byte [terminate ? outBytes + 1 : outBytes]; + OS.memmove (mbcs, ptr2, outBytes); + if (ptr1 != BufferTimes2) OS.XtFree (ptr1); + if (ptr2 != BufferTimes4) OS.XtFree (ptr2); + } + return mbcs; + } + } + return mbcs; +} + +/** + * Converts a String (containing unicode data) to an array + * of bytes representing the platform's encoding, of those characters + * in the given code page. + * + * @param codePage the code page to use for conversion + * @param string the string to be converted + * @return the platform encoding + */ +public static byte [] wcsToMbcs (String codePage, String string) { + return wcsToMbcs (codePage, string, false); +} + +/** + * Converts a String (containing unicode data) to an array + * of bytes representing the platform's encoding, of those characters + * in the given code page. If the termination flag is true, the resulting + * byte data will be null (zero) terminated. + * + * @param codePage the code page to use for conversion + * @param string the string to be converted + * @param terminate <code>true</code> if the result should be null terminated and false otherwise. + * @return the platform encoding + */ +public static byte [] wcsToMbcs (String codePage, String string, boolean terminate) { + if (terminate) { + if (string == null) return NULL_BYTE_ARRAY; + int count = string.length (); + char [] buffer = new char [count + 1]; + string.getChars (0, count, buffer, 0); + return wcsToMbcs (codePage, buffer, false); + } else { + if (string == null) return EMPTY_BYTE_ARRAY; + int count = string.length (); + char [] buffer = new char [count]; + string.getChars (0, count, buffer, 0); + return wcsToMbcs (codePage, buffer, false); + } +} + +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java index b79ce639ca..8fe272413f 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Button.java @@ -1,18 +1,18 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.events.*; + /** * Instances of this class represent a selectable user interface object that * issues notification when pressed and released. @@ -36,20 +36,20 @@ import org.eclipse.swt.events.*; * within the SWT implementation. * </p> */ -public class Button extends Control {
- Image image, bitmap, disabled;
- static final byte [] ARM_AND_ACTIVATE;
- static {
- String name = "ArmAndActivate";
- int length = name.length();
- char [] unicode = new char [length];
- name.getChars (0, length, unicode, 0);
- byte [] buffer = new byte [length + 1];
- for (int i = 0; i < length; i++) {
- buffer[i] = (byte) unicode[i];
- }
- ARM_AND_ACTIVATE = buffer;
- }
+public class Button extends Control { + Image image, bitmap, disabled; + static final byte [] ARM_AND_ACTIVATE; + static { + String name = "ArmAndActivate"; + int length = name.length(); + char [] unicode = new char [length]; + name.getChars (0, length, unicode, 0); + byte [] buffer = new byte [length + 1]; + for (int i = 0; i < length; i++) { + buffer[i] = (byte) unicode[i]; + } + ARM_AND_ACTIVATE = buffer; + } /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -86,234 +86,234 @@ public class Button extends Control { * @see Widget#checkSubclass * @see Widget#getStyle */ -public Button (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected, by 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 Button (Composite parent, int style) { + super (parent, checkStyle (style)); +} +/** + * Adds the listener to the collection of listeners who will + * be notified when the control is selected, by 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);
-}
-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;
-}
-void click () {
- OS.XtCallActionProc (handle, ARM_AND_ACTIVATE, new XAnyEvent (), null, 0);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- if ((style & SWT.ARROW) != 0) {
- Display display = getDisplay ();
- width += display.scrolledMarginX;
- height += display.scrolledMarginY;
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
- }
- XtWidgetGeometry result = new XtWidgetGeometry ();
- result.request_mode = OS.CWWidth | OS.CWHeight;
- int [] argList2 = {OS.XmNrecomputeSize, 1};
- OS.XtSetValues(handle, argList2, argList2.length / 2);
- OS.XtQueryGeometry (handle, null, result);
- int [] argList3 = {OS.XmNrecomputeSize, 0};
- OS.XtSetValues(handle, argList3, argList3.length / 2);
- width += result.width;
- height += result.height;
- /*
- * Feature in Motif. If a button's labelType is XmSTRING but it
- * has no label set into it yet, recomputing the size will
- * not take into account the height of the font, as we would
- * like it to. Take care of this case.
+public void addSelectionListener(SelectionListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener(listener); + addListener(SWT.Selection,typedListener); + addListener(SWT.DefaultSelection,typedListener); +} +static int checkStyle (int style) { + style = checkBits (style, SWT.PUSH, SWT.ARROW, SWT.CHECK, SWT.RADIO, SWT.TOGGLE, 0); + if ((style & SWT.PUSH) != 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; +} +void click () { + OS.XtCallActionProc (handle, ARM_AND_ACTIVATE, new XAnyEvent (), null, 0); +} +public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget(); + int border = getBorderWidth (); + int width = border * 2, height = border * 2; + if ((style & SWT.ARROW) != 0) { + Display display = getDisplay (); + width += display.scrolledMarginX; + height += display.scrolledMarginY; + if (wHint != SWT.DEFAULT) width = wHint + (border * 2); + if (hHint != SWT.DEFAULT) height = hHint + (border * 2); + return new Point (width, height); + } + XtWidgetGeometry result = new XtWidgetGeometry (); + result.request_mode = OS.CWWidth | OS.CWHeight; + int [] argList2 = {OS.XmNrecomputeSize, 1}; + OS.XtSetValues(handle, argList2, argList2.length / 2); + OS.XtQueryGeometry (handle, null, result); + int [] argList3 = {OS.XmNrecomputeSize, 0}; + OS.XtSetValues(handle, argList3, argList3.length / 2); + width += result.width; + height += result.height; + /* + * Feature in Motif. If a button's labelType is XmSTRING but it + * has no label set into it yet, recomputing the size will + * not take into account the height of the font, as we would + * like it to. Take care of this case. */ - int [] argList = {OS.XmNlabelType, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] == OS.XmSTRING) {
- int [] argList1 = {OS.XmNlabelString, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int xmString = argList1 [1];
- if (OS.XmStringEmpty (xmString)) height += getFontHeight ();
- if (xmString != 0) OS.XmStringFree (xmString);
- }
- if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) {
- int [] argList4 = new int [] {OS.XmNmarginLeft, 0, OS.XmNmarginRight, 0, OS.XmNmarginTop, 0, OS.XmNmarginBottom, 0};
- OS.XtGetValues (handle, argList4, argList4.length / 2);
- if (wHint != SWT.DEFAULT) width = wHint + argList4 [1] + argList4 [3] + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + argList4 [5] + argList4 [7] + (border * 2);
- }
- return new Point (width, height);
-}
-void createHandle (int index) {
- state |= HANDLE;
- int borderWidth = (style & SWT.BORDER) != 0 ? 1 : 0;
- int parentHandle = parent.handle;
-
- /* ARROW button */
- if ((style & SWT.ARROW) != 0) {
- int alignment = OS.XmARROW_UP;
- if ((style & SWT.UP) != 0) alignment = OS.XmARROW_UP;
- if ((style & SWT.DOWN) != 0) alignment = OS.XmARROW_DOWN;
- if ((style & SWT.LEFT) != 0) alignment = OS.XmARROW_LEFT;
- if ((style & SWT.RIGHT) != 0) alignment = OS.XmARROW_RIGHT;
- int [] argList = {
- OS.XmNtraversalOn, 0,
- OS.XmNarrowDirection, alignment,
- OS.XmNborderWidth, borderWidth,
- OS.XmNancestorSensitive, 1,
- };
- handle = OS.XmCreateArrowButton (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.FLAT) != 0) {
- int [] argList1 = {OS.XmNbottomShadowColor, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int [] argList2 = {
- OS.XmNshadowThickness, 1,
- OS.XmNtopShadowColor, argList1 [1],
- };
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- }
- return;
- }
-
- /* Compute alignment */
- int alignment = OS.XmALIGNMENT_BEGINNING;
- if ((style & SWT.CENTER) != 0) alignment = OS.XmALIGNMENT_CENTER;
- if ((style & SWT.RIGHT) != 0) alignment = OS.XmALIGNMENT_END;
-
- /* TOGGLE button */
- if ((style & SWT.TOGGLE) != 0) {
- /*
- * Bug in Motif. When XmNindicatorOn is set to false,
- * Motif doesn't reset the shadow thickness to give a
- * push button look. The fix is to set the shadow
- * thickness when ever this resource is changed.
- */
- Display display = getDisplay ();
- int thickness = display.buttonShadowThickness;
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNrecomputeSize, 0,
- OS.XmNindicatorOn, 0,
- OS.XmNshadowThickness, (style & SWT.FLAT) != 0 ? 1 : thickness,
- OS.XmNalignment, alignment,
- OS.XmNborderWidth, borderWidth,
- };
- handle = OS.XmCreateToggleButton (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.FLAT) != 0) {
- int [] argList1 = {OS.XmNbottomShadowColor, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int [] argList2 = {OS.XmNtopShadowColor, argList1 [1]};
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- }
- return;
- }
-
- /* CHECK or RADIO button */
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- /*
- * Bug in Motif. For some reason, a toggle button
- * with XmNindicatorType XmONE_OF_MANY must have this
- * value set at creation or the highlight color will
- * not be correct. The fix is to set these values
- * on create.
- */
- int indicatorType = OS.XmONE_OF_MANY;
- if ((style & SWT.CHECK) != 0) indicatorType = OS.XmN_OF_MANY;
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNrecomputeSize, 0,
- OS.XmNindicatorType, indicatorType,
- OS.XmNalignment, alignment,
- OS.XmNborderWidth, borderWidth,
- };
- handle = OS.XmCreateToggleButton (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- return;
- }
-
- /* PUSH button */
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNrecomputeSize, 0,
- OS.XmNalignment, alignment,
- OS.XmNborderWidth, borderWidth,
- /*
- * This code is intentionally commented. On some
- * platforms, the standard behavior is that push
- * buttons are tab groups, traversed with the tab
- * key. On Motif, push buttons are tab items,
- * that are traversed with the arrow keys. This
- * behavior is unspecifed so the line remains
- * commented.
- */
-// OS.XmNnavigationType, OS.XmTAB_GROUP,
- };
- handle = OS.XmCreatePushButton (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.FLAT) != 0) {
- int [] argList1 = {OS.XmNbottomShadowColor, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int [] argList2 = {
- OS.XmNshadowThickness, 1,
- OS.XmNtopShadowColor, argList1 [1],
- };
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- }
-}
-void createWidget (int index) {
- super.createWidget (index);
- if ((style & SWT.PUSH) == 0) return;
- if (getShell ().parent == null) return;
- int [] argList = new int [] {OS.XmNdefaultButtonShadowThickness, 1};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-int defaultBackground () {
- return getDisplay ().buttonBackground;
-}
-Font defaultFont () {
- return getDisplay ().buttonFont;
-}
-int defaultForeground () {
- return getDisplay ().buttonForeground;
-}
+ int [] argList = {OS.XmNlabelType, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (argList [1] == OS.XmSTRING) { + int [] argList1 = {OS.XmNlabelString, 0}; + OS.XtGetValues (handle, argList1, argList1.length / 2); + int xmString = argList1 [1]; + if (OS.XmStringEmpty (xmString)) height += getFontHeight (); + if (xmString != 0) OS.XmStringFree (xmString); + } + if (wHint != SWT.DEFAULT || hHint != SWT.DEFAULT) { + int [] argList4 = new int [] {OS.XmNmarginLeft, 0, OS.XmNmarginRight, 0, OS.XmNmarginTop, 0, OS.XmNmarginBottom, 0}; + OS.XtGetValues (handle, argList4, argList4.length / 2); + if (wHint != SWT.DEFAULT) width = wHint + argList4 [1] + argList4 [3] + (border * 2); + if (hHint != SWT.DEFAULT) height = hHint + argList4 [5] + argList4 [7] + (border * 2); + } + return new Point (width, height); +} +void createHandle (int index) { + state |= HANDLE; + int borderWidth = (style & SWT.BORDER) != 0 ? 1 : 0; + int parentHandle = parent.handle; + + /* ARROW button */ + if ((style & SWT.ARROW) != 0) { + int alignment = OS.XmARROW_UP; + if ((style & SWT.UP) != 0) alignment = OS.XmARROW_UP; + if ((style & SWT.DOWN) != 0) alignment = OS.XmARROW_DOWN; + if ((style & SWT.LEFT) != 0) alignment = OS.XmARROW_LEFT; + if ((style & SWT.RIGHT) != 0) alignment = OS.XmARROW_RIGHT; + int [] argList = { + OS.XmNtraversalOn, 0, + OS.XmNarrowDirection, alignment, + OS.XmNborderWidth, borderWidth, + OS.XmNancestorSensitive, 1, + }; + handle = OS.XmCreateArrowButton (parentHandle, null, argList, argList.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + if ((style & SWT.FLAT) != 0) { + int [] argList1 = {OS.XmNbottomShadowColor, 0}; + OS.XtGetValues (handle, argList1, argList1.length / 2); + int [] argList2 = { + OS.XmNshadowThickness, 1, + OS.XmNtopShadowColor, argList1 [1], + }; + OS.XtSetValues (handle, argList2, argList2.length / 2); + } + return; + } + + /* Compute alignment */ + int alignment = OS.XmALIGNMENT_BEGINNING; + if ((style & SWT.CENTER) != 0) alignment = OS.XmALIGNMENT_CENTER; + if ((style & SWT.RIGHT) != 0) alignment = OS.XmALIGNMENT_END; + + /* TOGGLE button */ + if ((style & SWT.TOGGLE) != 0) { + /* + * Bug in Motif. When XmNindicatorOn is set to false, + * Motif doesn't reset the shadow thickness to give a + * push button look. The fix is to set the shadow + * thickness when ever this resource is changed. + */ + Display display = getDisplay (); + int thickness = display.buttonShadowThickness; + int [] argList = { + OS.XmNancestorSensitive, 1, + OS.XmNrecomputeSize, 0, + OS.XmNindicatorOn, 0, + OS.XmNshadowThickness, (style & SWT.FLAT) != 0 ? 1 : thickness, + OS.XmNalignment, alignment, + OS.XmNborderWidth, borderWidth, + }; + handle = OS.XmCreateToggleButton (parentHandle, null, argList, argList.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + if ((style & SWT.FLAT) != 0) { + int [] argList1 = {OS.XmNbottomShadowColor, 0}; + OS.XtGetValues (handle, argList1, argList1.length / 2); + int [] argList2 = {OS.XmNtopShadowColor, argList1 [1]}; + OS.XtSetValues (handle, argList2, argList2.length / 2); + } + return; + } + + /* CHECK or RADIO button */ + if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { + /* + * Bug in Motif. For some reason, a toggle button + * with XmNindicatorType XmONE_OF_MANY must have this + * value set at creation or the highlight color will + * not be correct. The fix is to set these values + * on create. + */ + int indicatorType = OS.XmONE_OF_MANY; + if ((style & SWT.CHECK) != 0) indicatorType = OS.XmN_OF_MANY; + int [] argList = { + OS.XmNancestorSensitive, 1, + OS.XmNrecomputeSize, 0, + OS.XmNindicatorType, indicatorType, + OS.XmNalignment, alignment, + OS.XmNborderWidth, borderWidth, + }; + handle = OS.XmCreateToggleButton (parentHandle, null, argList, argList.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + return; + } + + /* PUSH button */ + int [] argList = { + OS.XmNancestorSensitive, 1, + OS.XmNrecomputeSize, 0, + OS.XmNalignment, alignment, + OS.XmNborderWidth, borderWidth, + /* + * This code is intentionally commented. On some + * platforms, the standard behavior is that push + * buttons are tab groups, traversed with the tab + * key. On Motif, push buttons are tab items, + * that are traversed with the arrow keys. This + * behavior is unspecifed so the line remains + * commented. + */ +// OS.XmNnavigationType, OS.XmTAB_GROUP, + }; + handle = OS.XmCreatePushButton (parentHandle, null, argList, argList.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + if ((style & SWT.FLAT) != 0) { + int [] argList1 = {OS.XmNbottomShadowColor, 0}; + OS.XtGetValues (handle, argList1, argList1.length / 2); + int [] argList2 = { + OS.XmNshadowThickness, 1, + OS.XmNtopShadowColor, argList1 [1], + }; + OS.XtSetValues (handle, argList2, argList2.length / 2); + } +} +void createWidget (int index) { + super.createWidget (index); + if ((style & SWT.PUSH) == 0) return; + if (getShell ().parent == null) return; + int [] argList = new int [] {OS.XmNdefaultButtonShadowThickness, 1}; + OS.XtSetValues (handle, argList, argList.length / 2); +} +int defaultBackground () { + return getDisplay ().buttonBackground; +} +Font defaultFont () { + return getDisplay ().buttonFont; +} +int defaultForeground () { + return getDisplay ().buttonForeground; +} /** * Returns a value which describes the position of the * text or image in the receiver. The value will be one of @@ -330,50 +330,50 @@ int defaultForeground () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public int getAlignment () {
- checkWidget();
- if ((style & SWT.ARROW) != 0) {
- int [] argList = {OS.XmNarrowDirection, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int direction = argList [1];
- if (direction == OS.XmARROW_UP) return SWT.UP;
- if (direction == OS.XmARROW_DOWN) return SWT.DOWN;
- if (direction == OS.XmARROW_LEFT) return SWT.LEFT;
- if (direction == OS.XmARROW_RIGHT) return SWT.RIGHT;
- return SWT.UP;
- }
- int [] argList = {OS.XmNalignment, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int alignment = argList [1];
- if (alignment == OS.XmALIGNMENT_BEGINNING) return SWT.LEFT;
- if (alignment == OS.XmALIGNMENT_CENTER) return SWT.CENTER;
- if (alignment == OS.XmALIGNMENT_END)return SWT.RIGHT;
- return SWT.CENTER;
-}
-boolean getDefault () {
- if ((style & SWT.PUSH) == 0) return false;
- int [] argList = {OS.XmNshowAsDefault, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] != 0;
-}
-/**
- * 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 int getAlignment () { + checkWidget(); + if ((style & SWT.ARROW) != 0) { + int [] argList = {OS.XmNarrowDirection, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int direction = argList [1]; + if (direction == OS.XmARROW_UP) return SWT.UP; + if (direction == OS.XmARROW_DOWN) return SWT.DOWN; + if (direction == OS.XmARROW_LEFT) return SWT.LEFT; + if (direction == OS.XmARROW_RIGHT) return SWT.RIGHT; + return SWT.UP; + } + int [] argList = {OS.XmNalignment, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int alignment = argList [1]; + if (alignment == OS.XmALIGNMENT_BEGINNING) return SWT.LEFT; + if (alignment == OS.XmALIGNMENT_CENTER) return SWT.CENTER; + if (alignment == OS.XmALIGNMENT_END)return SWT.RIGHT; + return SWT.CENTER; +} +boolean getDefault () { + if ((style & SWT.PUSH) == 0) return false; + int [] argList = {OS.XmNshowAsDefault, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1] != 0; +} +/** + * 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 ();
-}
+public Image getImage () { + checkWidget(); + return image; +} +String getNameText () { + return getText (); +} /** * Returns <code>true</code> if the receiver is selected, * and false otherwise. @@ -390,148 +390,148 @@ String getNameText () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public boolean getSelection () {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false;
- int [] argList = {OS.XmNset, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] != OS.XmUNSET;
-}
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set.
- *
- * @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 boolean getSelection () { + checkWidget(); + if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return false; + int [] argList = {OS.XmNset, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1] != OS.XmUNSET; +} +/** + * Returns the receiver's text, which will be an empty + * string if it has never been set. + * + * @return the receiver's text + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public String getText () {
- checkWidget();
- if ((style & SWT.ARROW) != 0) return "";
- int [] argList = {OS.XmNlabelString, 0, OS.XmNmnemonic, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int xmString = argList [1];
- int mnemonic = argList [3];
- if (mnemonic == OS.XK_VoidSymbol) mnemonic = 0;
- if (xmString == 0) error (SWT.ERROR_CANNOT_GET_TEXT);
- char [] result = null;
- int address = OS.XmStringUnparse (
- xmString,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- OS.XmOUTPUT_ALL);
- if (address != 0) {
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- OS.XtFree (address);
- result = Converter.mbcsToWcs (getCodePage (), buffer);
- }
- OS.XmStringFree (xmString);
- int count = 0;
- if (mnemonic != 0) count++;
- for (int i=0; i<result.length-1; i++)
- if (result [i] == Mnemonic) count++;
- char [] newResult = result;
- if ((count != 0) || (mnemonic != 0)) {
- newResult = new char [result.length + count];
- int i = 0, j = 0;
- while (i < result.length) {
- if ((mnemonic != 0) && (result [i] == mnemonic)) {
- if (j < newResult.length) newResult [j++] = Mnemonic;
- mnemonic = 0;
- }
- if ((newResult [j++] = result [i++]) == Mnemonic)
- if (j < newResult.length) newResult [j++] = Mnemonic;
- }
- }
- return new String (newResult);
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = getDisplay ().windowProc;
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) != 0) {
- OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
- } else {
- OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK);
- }
-
-}
-boolean mnemonicHit (char key) {
- if (!setFocus ()) return false;
- click ();
- return true;
-}
-boolean mnemonicMatch (char key) {
- char mnemonic = findMnemonic (getText ());
- if (mnemonic == '\0') return false;
- return Character.toUpperCase (key) == Character.toUpperCase (mnemonic);
-}
-void releaseWidget () {
- super.releaseWidget ();
- int [] argList = {
- OS.XmNlabelPixmap, OS.XmUNSPECIFIED_PIXMAP,
- OS.XmNlabelInsensitivePixmap, OS.XmUNSPECIFIED_PIXMAP,
- };
- OS.XtSetValues (handle, argList, argList.length / 2);
- if (bitmap != null) bitmap.dispose ();
- if (disabled != null) disabled.dispose ();
- image = bitmap = disabled = null;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected.
- *
- * @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 String getText () { + checkWidget(); + if ((style & SWT.ARROW) != 0) return ""; + int [] argList = {OS.XmNlabelString, 0, OS.XmNmnemonic, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int xmString = argList [1]; + int mnemonic = argList [3]; + if (mnemonic == OS.XK_VoidSymbol) mnemonic = 0; + if (xmString == 0) error (SWT.ERROR_CANNOT_GET_TEXT); + char [] result = null; + int address = OS.XmStringUnparse ( + xmString, + null, + OS.XmCHARSET_TEXT, + OS.XmCHARSET_TEXT, + null, + 0, + OS.XmOUTPUT_ALL); + if (address != 0) { + int length = OS.strlen (address); + byte [] buffer = new byte [length]; + OS.memmove (buffer, address, length); + OS.XtFree (address); + result = Converter.mbcsToWcs (getCodePage (), buffer); + } + OS.XmStringFree (xmString); + int count = 0; + if (mnemonic != 0) count++; + for (int i=0; i<result.length-1; i++) + if (result [i] == Mnemonic) count++; + char [] newResult = result; + if ((count != 0) || (mnemonic != 0)) { + newResult = new char [result.length + count]; + int i = 0, j = 0; + while (i < result.length) { + if ((mnemonic != 0) && (result [i] == mnemonic)) { + if (j < newResult.length) newResult [j++] = Mnemonic; + mnemonic = 0; + } + if ((newResult [j++] = result [i++]) == Mnemonic) + if (j < newResult.length) newResult [j++] = Mnemonic; + } + } + return new String (newResult); +} +void hookEvents () { + super.hookEvents (); + int windowProc = getDisplay ().windowProc; + if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) != 0) { + OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK); + } else { + OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK); + } + +} +boolean mnemonicHit (char key) { + if (!setFocus ()) return false; + click (); + return true; +} +boolean mnemonicMatch (char key) { + char mnemonic = findMnemonic (getText ()); + if (mnemonic == '\0') return false; + return Character.toUpperCase (key) == Character.toUpperCase (mnemonic); +} +void releaseWidget () { + super.releaseWidget (); + int [] argList = { + OS.XmNlabelPixmap, OS.XmUNSPECIFIED_PIXMAP, + OS.XmNlabelInsensitivePixmap, OS.XmUNSPECIFIED_PIXMAP, + }; + OS.XtSetValues (handle, argList, argList.length / 2); + if (bitmap != null) bitmap.dispose (); + if (disabled != null) disabled.dispose (); + image = bitmap = disabled = null; +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the control is selected. + * + * @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);
-}
-void selectRadio () {
- /*
- * This code is intentionally commented. When two groups
- * of radio buttons with the same parent are separated by
- * another control, the correct behavior should be that
- * the two groups act independently. This is consistent
- * with radio tool and menu items. The commented code
- * implements this behavior.
- */
-// int index = 0;
-// Control [] children = parent._getChildren ();
-// while (index < children.length && children [index] != this) index++;
-// int i = index - 1;
-// while (i >= 0 && children [i].setRadioSelection (false)) --i;
-// int j = index + 1;
-// while (j < children.length && children [j].setRadioSelection (false)) j++;
-// setSelection (true);
- Control [] children = parent._getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (this != child) child.setRadioSelection (false);
- }
- setSelection (true);
-}
+public void removeSelectionListener(SelectionListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook(SWT.Selection, listener); + eventTable.unhook(SWT.DefaultSelection,listener); +} +void selectRadio () { + /* + * This code is intentionally commented. When two groups + * of radio buttons with the same parent are separated by + * another control, the correct behavior should be that + * the two groups act independently. This is consistent + * with radio tool and menu items. The commented code + * implements this behavior. + */ +// int index = 0; +// Control [] children = parent._getChildren (); +// while (index < children.length && children [index] != this) index++; +// int i = index - 1; +// while (i >= 0 && children [i].setRadioSelection (false)) --i; +// int j = index + 1; +// while (j < children.length && children [j].setRadioSelection (false)) j++; +// setSelection (true); + Control [] children = parent._getChildren (); + for (int i=0; i<children.length; i++) { + Control child = children [i]; + if (this != child) child.setRadioSelection (false); + } + setSelection (true); +} /** * Controls how text, images and arrows will be displayed * in the receiver. The argument should be one of @@ -548,99 +548,99 @@ void selectRadio () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setAlignment (int alignment) {
- checkWidget();
- if ((style & SWT.ARROW) != 0) {
- int [] argList = {OS.XmNarrowDirection, OS.XmARROW_UP};
- if ((alignment & SWT.UP) != 0) argList [1] = OS.XmARROW_UP;
- if ((alignment & SWT.DOWN) != 0) argList [1] = OS.XmARROW_DOWN;
- if ((alignment & SWT.LEFT) != 0) argList [1] = OS.XmARROW_LEFT;
- if ((alignment & SWT.RIGHT) != 0) argList [1] = OS.XmARROW_RIGHT;
- OS.XtSetValues (handle, argList, argList.length / 2);
- return;
- }
- if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return;
- int [] argList = {OS.XmNalignment, OS.XmALIGNMENT_BEGINNING};
- if ((alignment & SWT.CENTER) != 0) argList [1] = OS.XmALIGNMENT_CENTER;
- if ((alignment & SWT.RIGHT) != 0) argList [1] = OS.XmALIGNMENT_END;
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- int [] argList = {OS.XmNlabelType, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] == OS.XmPIXMAP) setBitmap (image);
-}
-void setBitmap (Image image) {
- int labelPixmap = OS.XmUNSPECIFIED_PIXMAP;
- int labelInsensitivePixmap = OS.XmUNSPECIFIED_PIXMAP;
- if (bitmap != null) bitmap.dispose ();
- if (disabled != null) disabled.dispose ();
- bitmap = disabled = null;
- if (image != null) {
- if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- Display display = getDisplay ();
- switch (image.type) {
- case SWT.BITMAP:
- labelPixmap = image.pixmap;
- disabled = new Image (display, image, SWT.IMAGE_DISABLE);
- labelInsensitivePixmap = disabled.pixmap;
- break;
- case SWT.ICON:
- Rectangle rect = image.getBounds ();
- bitmap = new Image (display, rect.width, rect.height);
- GC gc = new GC (bitmap);
- gc.setBackground (getBackground ());
- gc.fillRectangle (rect);
- gc.drawImage (image, 0, 0);
- gc.dispose ();
- labelPixmap = bitmap.pixmap;
- disabled = new Image (display, bitmap, SWT.IMAGE_DISABLE);
- labelInsensitivePixmap = disabled.pixmap;
- break;
- default:
- error (SWT.ERROR_NOT_IMPLEMENTED);
- }
- }
- int [] argList = {
- OS.XmNlabelType, OS.XmPIXMAP,
- OS.XmNlabelPixmap, labelPixmap,
- OS.XmNlabelInsensitivePixmap, labelInsensitivePixmap,
- };
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-void setDefault (boolean value) {
- if ((style & SWT.PUSH) == 0) return;
- if (getShell ().parent == null) return;
- int [] argList = {OS.XmNshowAsDefault, (value ? 1 : 0)};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * 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 setAlignment (int alignment) { + checkWidget(); + if ((style & SWT.ARROW) != 0) { + int [] argList = {OS.XmNarrowDirection, OS.XmARROW_UP}; + if ((alignment & SWT.UP) != 0) argList [1] = OS.XmARROW_UP; + if ((alignment & SWT.DOWN) != 0) argList [1] = OS.XmARROW_DOWN; + if ((alignment & SWT.LEFT) != 0) argList [1] = OS.XmARROW_LEFT; + if ((alignment & SWT.RIGHT) != 0) argList [1] = OS.XmARROW_RIGHT; + OS.XtSetValues (handle, argList, argList.length / 2); + return; + } + if ((alignment & (SWT.LEFT | SWT.RIGHT | SWT.CENTER)) == 0) return; + int [] argList = {OS.XmNalignment, OS.XmALIGNMENT_BEGINNING}; + if ((alignment & SWT.CENTER) != 0) argList [1] = OS.XmALIGNMENT_CENTER; + if ((alignment & SWT.RIGHT) != 0) argList [1] = OS.XmALIGNMENT_END; + OS.XtSetValues (handle, argList, argList.length / 2); +} +void setBackgroundPixel (int pixel) { + super.setBackgroundPixel (pixel); + int [] argList = {OS.XmNlabelType, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (argList [1] == OS.XmPIXMAP) setBitmap (image); +} +void setBitmap (Image image) { + int labelPixmap = OS.XmUNSPECIFIED_PIXMAP; + int labelInsensitivePixmap = OS.XmUNSPECIFIED_PIXMAP; + if (bitmap != null) bitmap.dispose (); + if (disabled != null) disabled.dispose (); + bitmap = disabled = null; + if (image != null) { + if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); + Display display = getDisplay (); + switch (image.type) { + case SWT.BITMAP: + labelPixmap = image.pixmap; + disabled = new Image (display, image, SWT.IMAGE_DISABLE); + labelInsensitivePixmap = disabled.pixmap; + break; + case SWT.ICON: + Rectangle rect = image.getBounds (); + bitmap = new Image (display, rect.width, rect.height); + GC gc = new GC (bitmap); + gc.setBackground (getBackground ()); + gc.fillRectangle (rect); + gc.drawImage (image, 0, 0); + gc.dispose (); + labelPixmap = bitmap.pixmap; + disabled = new Image (display, bitmap, SWT.IMAGE_DISABLE); + labelInsensitivePixmap = disabled.pixmap; + break; + default: + error (SWT.ERROR_NOT_IMPLEMENTED); + } + } + int [] argList = { + OS.XmNlabelType, OS.XmPIXMAP, + OS.XmNlabelPixmap, labelPixmap, + OS.XmNlabelInsensitivePixmap, labelInsensitivePixmap, + }; + OS.XtSetValues (handle, argList, argList.length / 2); +} +void setDefault (boolean value) { + if ((style & SWT.PUSH) == 0) return; + if (getShell ().parent == null) return; + int [] argList = {OS.XmNshowAsDefault, (value ? 1 : 0)}; + OS.XtSetValues (handle, argList, argList.length / 2); +} +/** + * 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();
- setBitmap (this.image = image);
-}
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
+public void setImage (Image image) { + checkWidget(); + setBitmap (this.image = image); +} +boolean setRadioSelection (boolean value) { + if ((style & SWT.RADIO) == 0) return false; + if (getSelection () != value) { + setSelection (value); + postEvent (SWT.Selection); + } + return true; +} /** * Sets the selection state of the receiver, if it is of type <code>CHECK</code>, * <code>RADIO</code>, or <code>TOGGLE</code>. @@ -657,108 +657,108 @@ boolean setRadioSelection (boolean value) { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setSelection (boolean selected) {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return;
- int [] argList = {OS.XmNset, selected ? OS.XmSET : OS.XmUNSET};
- OS.XtSetValues (handle, argList, argList.length / 2);
- updateShadows ();
-}
-/**
- * Sets the receiver's text.
- * <p>
- * This method sets the button label. The label may include
- * the mnemonic character but must not contain line delimiters.
- * </p>
- *
- * @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 setSelection (boolean selected) { + checkWidget(); + if ((style & (SWT.CHECK | SWT.RADIO | SWT.TOGGLE)) == 0) return; + int [] argList = {OS.XmNset, selected ? OS.XmSET : OS.XmUNSET}; + OS.XtSetValues (handle, argList, argList.length / 2); + updateShadows (); +} +/** + * Sets the receiver's text. + * <p> + * This method sets the button label. The label may include + * the mnemonic character but must not contain line delimiters. + * </p> + * + * @param string the new text + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the text is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.ARROW) != 0) return;
- char [] text = new char [string.length ()];
- string.getChars (0, text.length, text, 0);
- int i=0, j=0, mnemonic=0;
- while (i < text.length) {
- if ((text [j++] = text [i++]) == Mnemonic) {
- if (i == text.length) {continue;}
- if (text [i] == Mnemonic) {i++; continue;}
- if (mnemonic == 0) mnemonic = text [i];
- j--;
- }
- }
- while (j < text.length) text [j++] = 0;
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), text, true);
- int xmString = OS.XmStringParseText (
- buffer,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- if (xmString == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- if (mnemonic == 0) mnemonic = OS.XK_VoidSymbol;
- int [] argList = {
- OS.XmNlabelType, OS.XmSTRING,
- OS.XmNlabelString, xmString,
- OS.XmNmnemonic, mnemonic,
- };
- OS.XtSetValues (handle, argList, argList.length / 2);
- if (xmString != 0) OS.XmStringFree (xmString);
-}
-int traversalCode (int key, XKeyEvent xEvent) {
- return super.traversalCode (key, xEvent) | SWT.TRAVERSE_MNEMONIC;
-}
-void updateShadows () {
- if ((style & SWT.FLAT) != 0 && (style & SWT.TOGGLE) != 0) {
- int [] argList1 = {OS.XmNset, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- Display display = getDisplay ();
- int pixel = argList1 [1] == OS.XmUNSET ? display.compositeBottomShadow : display.compositeTopShadow;
- int [] argList2 = {OS.XmNtopShadowColor, pixel};
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- }
-}
-int xFocusIn () {
- super.xFocusIn ();
- // widget could be disposed at this point
- if (handle == 0) return 0;
- if ((style & SWT.PUSH) != 0) {
- menuShell ().setDefaultButton (this, false);
- }
- return 0;
-}
-int xFocusOut () {
- super.xFocusOut ();
- // widget could be disposed at this point
- if (handle == 0) return 0;
- if ((style & SWT.PUSH) != 0 && getDefault ()) {
- menuShell ().setDefaultButton (null, false);
- }
- return 0;
-}
-int XmNactivateCallback (int w, int client_data, int call_data) {
- postEvent (SWT.Selection);
- return 0;
-}
-int XmNvalueChangedCallback (int w, int client_data, int call_data) {
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) {
- selectRadio ();
- }
- }
- updateShadows ();
- postEvent (SWT.Selection);
- return 0;
-}
+public void setText (String string) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + if ((style & SWT.ARROW) != 0) return; + char [] text = new char [string.length ()]; + string.getChars (0, text.length, text, 0); + int i=0, j=0, mnemonic=0; + while (i < text.length) { + if ((text [j++] = text [i++]) == Mnemonic) { + if (i == text.length) {continue;} + if (text [i] == Mnemonic) {i++; continue;} + if (mnemonic == 0) mnemonic = text [i]; + j--; + } + } + while (j < text.length) text [j++] = 0; + byte [] buffer = Converter.wcsToMbcs (getCodePage (), text, true); + int xmString = OS.XmStringParseText ( + buffer, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + if (xmString == 0) error (SWT.ERROR_CANNOT_SET_TEXT); + if (mnemonic == 0) mnemonic = OS.XK_VoidSymbol; + int [] argList = { + OS.XmNlabelType, OS.XmSTRING, + OS.XmNlabelString, xmString, + OS.XmNmnemonic, mnemonic, + }; + OS.XtSetValues (handle, argList, argList.length / 2); + if (xmString != 0) OS.XmStringFree (xmString); +} +int traversalCode (int key, XKeyEvent xEvent) { + return super.traversalCode (key, xEvent) | SWT.TRAVERSE_MNEMONIC; +} +void updateShadows () { + if ((style & SWT.FLAT) != 0 && (style & SWT.TOGGLE) != 0) { + int [] argList1 = {OS.XmNset, 0}; + OS.XtGetValues (handle, argList1, argList1.length / 2); + Display display = getDisplay (); + int pixel = argList1 [1] == OS.XmUNSET ? display.compositeBottomShadow : display.compositeTopShadow; + int [] argList2 = {OS.XmNtopShadowColor, pixel}; + OS.XtSetValues (handle, argList2, argList2.length / 2); + } +} +int xFocusIn () { + super.xFocusIn (); + // widget could be disposed at this point + if (handle == 0) return 0; + if ((style & SWT.PUSH) != 0) { + menuShell ().setDefaultButton (this, false); + } + return 0; +} +int xFocusOut () { + super.xFocusOut (); + // widget could be disposed at this point + if (handle == 0) return 0; + if ((style & SWT.PUSH) != 0 && getDefault ()) { + menuShell ().setDefaultButton (null, false); + } + return 0; +} +int XmNactivateCallback (int w, int client_data, int call_data) { + postEvent (SWT.Selection); + return 0; +} +int XmNvalueChangedCallback (int w, int client_data, int call_data) { + if ((style & SWT.RADIO) != 0) { + if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) { + selectRadio (); + } + } + updateShadows (); + postEvent (SWT.Selection); + return 0; +} }
\ No newline at end of file diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java index 3bb6190123..04a8f715d1 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Canvas.java @@ -1,41 +1,41 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide a surface for drawing
- * arbitrary graphics.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * This class may be subclassed by custom control implementors
- * who are building controls that are <em>not</em> constructed
- * from aggregates of other controls. That is, they are either
- * painted using SWT graphics calls or are handled by native
- * methods.
- * </p>
- *
- * @see Composite
+ * http://www.eclipse.org/legal/cpl-v10.html */ -public class Canvas extends Composite {
- Caret caret;
-
-Canvas () {
- /* Do nothing */
-}
+ +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; + +/** + * Instances of this class provide a surface for drawing + * arbitrary graphics. + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>(none)</dd> + * <dt><b>Events:</b></dt> + * <dd>(none)</dd> + * </dl> + * <p> + * This class may be subclassed by custom control implementors + * who are building controls that are <em>not</em> constructed + * from aggregates of other controls. That is, they are either + * painted using SWT graphics calls or are handled by native + * methods. + * </p> + * + * @see Composite + */ +public class Canvas extends Composite { + Caret caret; + +Canvas () { + /* Do nothing */ +} /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -64,188 +64,188 @@ Canvas () { * @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 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;
-}
-
-short [] getIMCaretPos () {
- if (caret == null) return super.getIMCaretPos ();
- int width = caret.width;
- if (width <= 0) width = 2;
- return new short[]{(short) (caret.x + width), (short) (caret.y + caret.height)};
-}
-void redrawWidget (int x, int y, int width, int height, boolean all) {
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- super.redrawWidget (x, y, width, height, all);
- if (isFocus) caret.setFocus ();
-}
-
-void releaseWidget () {
- if (caret != null) caret.releaseResources ();
- caret = null;
- super.releaseWidget();
-}
-
-/**
- * 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 Caret getCaret () { + checkWidget(); + return caret; +} + +short [] getIMCaretPos () { + if (caret == null) return super.getIMCaretPos (); + int width = caret.width; + if (width <= 0) width = 2; + return new short[]{(short) (caret.x + width), (short) (caret.y + caret.height)}; +} +void redrawWidget (int x, int y, int width, int height, boolean all) { + boolean isFocus = caret != null && caret.isFocusCaret (); + if (isFocus) caret.killFocus (); + super.redrawWidget (x, y, width, height, all); + if (isFocus) caret.setFocus (); +} + +void releaseWidget () { + if (caret != null) caret.releaseResources (); + caret = null; + super.releaseWidget(); +} + +/** + * Scrolls a rectangular area of the receiver by first copying + * the source area to the destination and then causing the area + * of the source which is not covered by the destination to + * be repainted. Children that intersect the rectangle are + * optionally moved during the operation. In addition, outstanding + * paint events are flushed before the source area is copied to + * ensure that the contents of the canvas are drawn correctly. + * + * @param destX the x coordinate of the destination + * @param destY the y coordinate of the destination + * @param x the x coordinate of the source + * @param y the y coordinate of the source + * @param width the width of the area + * @param height the height of the area + * @param all <code>true</code>if children should be scrolled, and <code>false</code> otherwise + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) {
- checkWidget();
- if (width <= 0 || height <= 0) return;
- int deltaX = destX - x, deltaY = destY - y;
- if (deltaX == 0 && deltaY == 0) return;
- if (!isVisible ()) return;
-
- /* Hide the caret */
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
-
- /* Flush outstanding exposes */
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- XAnyEvent xEvent = new XAnyEvent ();
- OS.XSync (xDisplay, false); OS.XSync (xDisplay, false);
- while (OS.XCheckWindowEvent (xDisplay, xWindow, OS.ExposureMask, xEvent)) {
- OS.XtDispatchEvent (xEvent);
- }
-
- /* Scroll the window */
- int xGC = OS.XCreateGC (xDisplay, xWindow, 0, null);
- OS.XCopyArea (xDisplay, xWindow, xWindow, xGC, x, y, width, height, destX, destY);
- OS.XFreeGC (xDisplay, xGC);
- boolean disjoint = (destX + width < x) || (x + width < destX) || (destY + height < y) || (y + height < destY);
- if (disjoint) {
- OS.XClearArea (xDisplay, xWindow, x, y, width, height, true);
- } else {
- if (deltaX != 0) {
- int newX = destX - deltaX;
- if (deltaX < 0) newX = destX + width;
- OS.XClearArea (xDisplay, xWindow, newX, y, Math.abs (deltaX), height, true);
- }
- if (deltaY != 0) {
- int newY = destY - deltaY;
- if (deltaY < 0) newY = destY + height;
- OS.XClearArea (xDisplay, xWindow, x, newY, width, Math.abs (deltaY), true);
- }
- }
-
- /* Show the caret */
- if (isFocus) caret.setFocus ();
-}
-/**
- * Sets the receiver's caret.
- * <p>
- * The caret for the control is automatically hidden
- * and shown when the control is painted or resized,
- * when focus is gained or lost and when an the control
- * is scrolled. To avoid drawing on top of the caret,
- * the programmer must hide and show the caret when
- * drawing in the window any other time.
- * </p>
- * @param caret the new caret for the receiver, may be null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the caret has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void scroll (int destX, int destY, int x, int y, int width, int height, boolean all) { + checkWidget(); + if (width <= 0 || height <= 0) return; + int deltaX = destX - x, deltaY = destY - y; + if (deltaX == 0 && deltaY == 0) return; + if (!isVisible ()) return; + + /* Hide the caret */ + boolean isFocus = caret != null && caret.isFocusCaret (); + if (isFocus) caret.killFocus (); + + /* Flush outstanding exposes */ + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return; + int xWindow = OS.XtWindow (handle); + if (xWindow == 0) return; + XAnyEvent xEvent = new XAnyEvent (); + OS.XSync (xDisplay, false); OS.XSync (xDisplay, false); + while (OS.XCheckWindowEvent (xDisplay, xWindow, OS.ExposureMask, xEvent)) { + OS.XtDispatchEvent (xEvent); + } + + /* Scroll the window */ + int xGC = OS.XCreateGC (xDisplay, xWindow, 0, null); + OS.XCopyArea (xDisplay, xWindow, xWindow, xGC, x, y, width, height, destX, destY); + OS.XFreeGC (xDisplay, xGC); + boolean disjoint = (destX + width < x) || (x + width < destX) || (destY + height < y) || (y + height < destY); + if (disjoint) { + OS.XClearArea (xDisplay, xWindow, x, y, width, height, true); + } else { + if (deltaX != 0) { + int newX = destX - deltaX; + if (deltaX < 0) newX = destX + width; + OS.XClearArea (xDisplay, xWindow, newX, y, Math.abs (deltaX), height, true); + } + if (deltaY != 0) { + int newY = destY - deltaY; + if (deltaY < 0) newY = destY + height; + OS.XClearArea (xDisplay, xWindow, x, newY, width, Math.abs (deltaY), true); + } + } + + /* Show the caret */ + if (isFocus) caret.setFocus (); +} +/** + * Sets the receiver's caret. + * <p> + * The caret for the control is automatically hidden + * and shown when the control is painted or resized, + * when focus is gained or lost and when an the control + * is scrolled. To avoid drawing on top of the caret, + * the programmer must hide and show the caret when + * drawing in the window any other time. + * </p> + * @param caret the new caret for the receiver, may be null + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the caret has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setCaret (Caret caret) {
- checkWidget();
- Caret newCaret = caret;
- Caret oldCaret = this.caret;
- this.caret = newCaret;
- if (hasFocus ()) {
- if (oldCaret != null) oldCaret.killFocus ();
- if (newCaret != null) {
- if (newCaret.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- newCaret.setFocus ();
- }
- }
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- boolean changed = super.setBounds (x, y, width, height, move, resize);
- if (isFocus) caret.setFocus ();
- return changed;
-}
-public void setFont (Font font) {
- checkWidget();
- super.setFont (font);
- if (caret != null) caret.setFont (font);
-}
-void updateCaret () {
- if (caret == null) return;
- if (!OS.IsDBLocale) return;
- short [] point = getIMCaretPos ();
- int ptr = OS.XtMalloc (4);
- OS.memmove (ptr, point, 4);
- int[] argList = {OS.XmNspotLocation, ptr};
- OS.XmImSetValues (handle, argList, argList.length / 2);
- if (ptr != 0) OS.XtFree (ptr);
-}
-int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) {
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- int result = super.XExposure (w, client_data, call_data, continue_to_dispatch);
- if (isFocus) caret.setFocus ();
- return result;
-}
-int xFocusIn () {
- int result = super.xFocusIn ();
- if (caret != null) caret.setFocus ();
- return result;
-}
-int xFocusOut () {
- int result = super.xFocusOut ();
- if (caret != null) caret.killFocus ();
- return result;
-}
-}
+public void setCaret (Caret caret) { + checkWidget(); + Caret newCaret = caret; + Caret oldCaret = this.caret; + this.caret = newCaret; + if (hasFocus ()) { + if (oldCaret != null) oldCaret.killFocus (); + if (newCaret != null) { + if (newCaret.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); + newCaret.setFocus (); + } + } +} +boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { + boolean isFocus = caret != null && caret.isFocusCaret (); + if (isFocus) caret.killFocus (); + boolean changed = super.setBounds (x, y, width, height, move, resize); + if (isFocus) caret.setFocus (); + return changed; +} +public void setFont (Font font) { + checkWidget(); + super.setFont (font); + if (caret != null) caret.setFont (font); +} +void updateCaret () { + if (caret == null) return; + if (!OS.IsDBLocale) return; + short [] point = getIMCaretPos (); + int ptr = OS.XtMalloc (4); + OS.memmove (ptr, point, 4); + int[] argList = {OS.XmNspotLocation, ptr}; + OS.XmImSetValues (handle, argList, argList.length / 2); + if (ptr != 0) OS.XtFree (ptr); +} +int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) { + boolean isFocus = caret != null && caret.isFocusCaret (); + if (isFocus) caret.killFocus (); + int result = super.XExposure (w, client_data, call_data, continue_to_dispatch); + if (isFocus) caret.setFocus (); + return result; +} +int xFocusIn () { + int result = super.xFocusIn (); + if (caret != null) caret.setFocus (); + return result; +} +int xFocusOut () { + int result = super.xFocusOut (); + if (caret != null) caret.killFocus (); + return result; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java index bf3179bf36..cfd6c68efd 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Caret.java @@ -1,37 +1,37 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class provide an i-beam that is typically used
- * as the insertion point for text.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html */ -public class Caret extends Widget {
- Canvas parent;
- int x, y, width, height;
- boolean isVisible, isShowing;
- int blinkRate = 500;
- Image image;
- Font font;
+ +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; + +/** + * Instances of this class provide an i-beam that is typically used + * as the insertion point for text. + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>(none)</dd> + * <dt><b>Events:</b></dt> + * <dd>(none)</dd> + * </dl> + * <p> + * IMPORTANT: This class is intended to be subclassed <em>only</em> + * within the SWT implementation. + * </p> + */ +public class Caret extends Widget { + Canvas parent; + int x, y, width, height; + boolean isVisible, isShowing; + int blinkRate = 500; + Image image; + Font font; /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -60,424 +60,424 @@ public class Caret extends Widget { * @see Widget#checkSubclass * @see Widget#getStyle */ -public Caret (Canvas parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget (0);
-}
-boolean blinkCaret () {
- if (!isVisible) return true;
- if (!isShowing) return showCaret ();
- if (blinkRate == 0) return true;
- return hideCaret ();
-}
-void createWidget (int index) {
- super.createWidget (index);
- isVisible = true;
- if (parent.getCaret () == null) {
- parent.setCaret (this);
- }
-}
-boolean drawCaret () {
- if (parent == null) return false;
- if (parent.isDisposed ()) return false;
- int handle = parent.handle;
- int window = OS.XtWindow (handle);
- if (window == 0) return false;
- int xDisplay = OS.XtDisplay (handle);
- int gc = OS.XCreateGC (xDisplay, window, 0, null);
- int color;
- if (OS.IsSunOS) {
- int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int foreground = argList [1];
- int background = argList [3];
- color = foreground ^ background;
- } else {
- int screenNum = OS.XDefaultScreen (xDisplay);
- color = OS.XWhitePixel(xDisplay, screenNum);
- }
- OS.XSetForeground (xDisplay, gc, color);
- OS.XSetFunction (xDisplay, gc, OS.GXxor);
- int nWidth = width, nHeight = height;
- if (image != null) {
- Rectangle rect = image.getBounds ();
- nWidth = rect.width;
- nHeight = rect.height;
- }
- if (nWidth <= 0) nWidth = 2;
- OS.XFillRectangle (xDisplay, window, gc, x, y, nWidth, nHeight);
- OS.XFreeGC (xDisplay, gc);
- return true;
-}
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null).
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public Caret (Canvas parent, int style) { + super (parent, style); + this.parent = parent; + createWidget (0); +} +boolean blinkCaret () { + if (!isVisible) return true; + if (!isShowing) return showCaret (); + if (blinkRate == 0) return true; + return hideCaret (); +} +void createWidget (int index) { + super.createWidget (index); + isVisible = true; + if (parent.getCaret () == null) { + parent.setCaret (this); + } +} +boolean drawCaret () { + if (parent == null) return false; + if (parent.isDisposed ()) return false; + int handle = parent.handle; + int window = OS.XtWindow (handle); + if (window == 0) return false; + int xDisplay = OS.XtDisplay (handle); + int gc = OS.XCreateGC (xDisplay, window, 0, null); + int color; + if (OS.IsSunOS) { + int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int foreground = argList [1]; + int background = argList [3]; + color = foreground ^ background; + } else { + int screenNum = OS.XDefaultScreen (xDisplay); + color = OS.XWhitePixel(xDisplay, screenNum); + } + OS.XSetForeground (xDisplay, gc, color); + OS.XSetFunction (xDisplay, gc, OS.GXxor); + int nWidth = width, nHeight = height; + if (image != null) { + Rectangle rect = image.getBounds (); + nWidth = rect.width; + nHeight = rect.height; + } + if (nWidth <= 0) nWidth = 2; + OS.XFillRectangle (xDisplay, window, gc, x, y, nWidth, nHeight); + OS.XFreeGC (xDisplay, gc); + return true; +} +/** + * Returns a rectangle describing the receiver's size and location + * relative to its parent (or its display if its parent is null). + * + * @return the receiver's bounding rectangle + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public Rectangle getBounds () {
- checkWidget();
- if (image != null) {
- Rectangle rect = image.getBounds ();
- return new Rectangle (x, y, rect.width, rect.height);
- }
- return new Rectangle (x, y, width, height);
-}
-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 Rectangle getBounds () { + checkWidget(); + if (image != null) { + Rectangle rect = image.getBounds (); + return new Rectangle (x, y, rect.width, rect.height); + } + return new Rectangle (x, y, width, height); +} +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 () {
- checkWidget();
- if (font != null) return font;
- return parent.getFont ();
-}
-/**
- * Returns the image that the receiver will use to paint the caret.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public Font getFont () { + checkWidget(); + if (font != null) return font; + return parent.getFont (); +} +/** + * Returns the image that the receiver will use to paint the caret. + * + * @return the receiver's image + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public Image getImage () {
- checkWidget();
- return image;
-}
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null).
- *
- * @return the receiver's location
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public Image getImage () { + checkWidget(); + return image; +} +/** + * Returns a point describing the receiver's location relative + * to its parent (or its display if its parent is null). + * + * @return the receiver's location + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public Point getLocation () {
- checkWidget();
- return new Point (x, y);
-}
-/**
- * Returns the receiver's parent, which must be a <code>Canvas</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public Point getLocation () { + checkWidget(); + return new Point (x, y); +} +/** + * Returns the receiver's parent, which must be a <code>Canvas</code>. + * + * @return the receiver's parent + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public Canvas getParent () {
- checkWidget();
- return parent;
-}
-/**
- * Returns a point describing the receiver's size.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public Canvas getParent () { + checkWidget(); + return parent; +} +/** + * Returns a point describing the receiver's size. + * + * @return the receiver's size + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public Point getSize () {
- checkWidget();
- if (image != null) {
- Rectangle rect = image.getBounds ();
- return new Point (rect.width, rect.height);
- }
- return new Point (width, height);
-}
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public Point getSize () { + checkWidget(); + if (image != null) { + Rectangle rect = image.getBounds (); + return new Point (rect.width, rect.height); + } + return new Point (width, height); +} +/** + * Returns <code>true</code> if the receiver is visible, and + * <code>false</code> otherwise. + * <p> + * If one of the receiver's ancestors is not visible or some + * other condition makes the receiver not visible, this method + * may still indicate that it is considered visible even though + * it may not actually be showing. + * </p> + * + * @return the receiver's visibility state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public boolean getVisible () {
- checkWidget();
- return isVisible;
-}
-boolean hideCaret () {
- if (!isShowing) return true;
- isShowing = false;
- return drawCaret ();
-}
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
+public boolean getVisible () { + checkWidget(); + return isVisible; +} +boolean hideCaret () { + if (!isShowing) return true; + isShowing = false; + return drawCaret (); +} +/** + * Returns <code>true</code> if the receiver is visible and all + * of the receiver's ancestors are visible and <code>false</code> + * otherwise. + * + * @return the receiver's visibility state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #getVisible */ -public boolean isVisible () {
- checkWidget();
- return isVisible && parent.isVisible () && parent.hasFocus ();
-}
-boolean isFocusCaret () {
- Display display = getDisplay ();
- return this == display.currentCaret;
-}
-void killFocus () {
- Display display = getDisplay ();
- if (display.currentCaret != this) return;
- display.setCurrentCaret (null);
- if (isVisible) hideCaret ();
-}
-void releaseChild () {
- super.releaseChild ();
- if (this == parent.getCaret ()) parent.setCaret (null);
-}
-void releaseWidget () {
- super.releaseWidget ();
- Display display = getDisplay ();
- if (display.currentCaret == this) {
- hideCaret ();
- display.setCurrentCaret (null);
- }
- parent = null;
- image = null;
-}
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the arguments. The <code>x</code> and
- * <code>y</code> arguments are relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public boolean isVisible () { + checkWidget(); + return isVisible && parent.isVisible () && parent.hasFocus (); +} +boolean isFocusCaret () { + Display display = getDisplay (); + return this == display.currentCaret; +} +void killFocus () { + Display display = getDisplay (); + if (display.currentCaret != this) return; + display.setCurrentCaret (null); + if (isVisible) hideCaret (); +} +void releaseChild () { + super.releaseChild (); + if (this == parent.getCaret ()) parent.setCaret (null); +} +void releaseWidget () { + super.releaseWidget (); + Display display = getDisplay (); + if (display.currentCaret == this) { + hideCaret (); + display.setCurrentCaret (null); + } + parent = null; + image = null; +} +/** + * Sets the receiver's size and location to the rectangular + * area specified by the arguments. The <code>x</code> and + * <code>y</code> arguments are relative to the receiver's + * parent (or its display if its parent is null). + * + * @param x the new x coordinate for the receiver + * @param y the new y coordinate for the receiver + * @param width the new width for the receiver + * @param height the new height for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setBounds (int x, int y, int width, int height) {
- checkWidget();
- if (this.x == x && this.y == y && this.width == width && this.height == height) return;
- boolean isFocus = isFocusCaret ();
- if (isFocus) hideCaret ();
- this.x = x; this.y = y;
- this.width = width; this.height = height;
- parent.updateCaret ();
- if (isFocus) 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 (int x, int y, int width, int height) { + checkWidget(); + if (this.x == x && this.y == y && this.width == width && this.height == height) return; + boolean isFocus = isFocusCaret (); + if (isFocus) hideCaret (); + this.x = x; this.y = y; + this.width = width; this.height = height; + parent.updateCaret (); + if (isFocus) showCaret (); +} +/** + * Sets the receiver's size and location to the rectangular + * area specified by the argument. The <code>x</code> and + * <code>y</code> fields of the rectangle are relative to + * the receiver's parent (or its display if its parent is null). + * + * @param rect the new bounds for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setBounds (Rectangle rect) {
- checkWidget();
- if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (rect.x, rect.y, rect.width, rect.height);
-}
-void setFocus () {
- 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 setBounds (Rectangle rect) { + checkWidget(); + 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) {
- checkWidget();
- if (font != null && font.isDisposed ()) {
- error (SWT.ERROR_INVALID_ARGUMENT);
- }
- this.font = font;
- if (isVisible && parent.hasFocus()) {
- int handle = parent.handle;
- int [] argList = {OS.XmNfontList, font.handle};
- OS.XmImSetValues (handle, argList, argList.length / 2);
- }
-}
-/**
- * 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 setFont (Font font) { + checkWidget(); + if (font != null && font.isDisposed ()) { + error (SWT.ERROR_INVALID_ARGUMENT); + } + this.font = font; + if (isVisible && parent.hasFocus()) { + int handle = parent.handle; + int [] argList = {OS.XmNfontList, font.handle}; + OS.XmImSetValues (handle, argList, argList.length / 2); + } +} +/** + * 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);
- }
- boolean isFocus = isFocusCaret ();
- if (isFocus) hideCaret ();
- this.image = image;
- if (isFocus) 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 setImage (Image image) { + checkWidget(); + if (image != null && image.isDisposed ()) { + error (SWT.ERROR_INVALID_ARGUMENT); + } + boolean isFocus = isFocusCaret (); + if (isFocus) hideCaret (); + this.image = image; + if (isFocus) showCaret (); +} +/** + * Sets the receiver's location to the point specified by + * the arguments which are relative to the receiver's + * parent (or its display if its parent is null). + * + * @param x the new x coordinate for the receiver + * @param y the new y coordinate for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setLocation (int x, int y) {
- checkWidget();
- setBounds (x, y, width, height);
-}
-/**
- * Sets the receiver's location to the point specified by
- * the argument which is relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param location the new location for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void setLocation (int x, int y) { + checkWidget(); + setBounds (x, y, width, height); +} +/** + * Sets the receiver's location to the point specified by + * the argument which is relative to the receiver's + * parent (or its display if its parent is null). + * + * @param location the new location for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setLocation (Point location) {
- checkWidget();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-/**
- * Sets the receiver's size to the point specified by the arguments.
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void setLocation (Point location) { + checkWidget(); + if (location == null) error (SWT.ERROR_NULL_ARGUMENT); + setLocation (location.x, location.y); +} +/** + * Sets the receiver's size to the point specified by the arguments. + * + * @param width the new width for the receiver + * @param height the new height for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setSize (int width, int height) {
- checkWidget();
- setBounds (x, y, width, height);
-}
-/**
- * Sets the receiver's size to the point specified by the argument.
- *
- * @param size the new extent for the receiver
- * @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 (int width, int height) { + checkWidget(); + setBounds (x, y, width, height); +} +/** + * Sets the receiver's size to the point specified by the argument. + * + * @param size the new extent for the receiver + * @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) {
- checkWidget();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSize (size.x, size.y);
-}
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void setSize (Point size) { + checkWidget(); + if (size == null) error (SWT.ERROR_NULL_ARGUMENT); + setSize (size.x, size.y); +} +/** + * Marks the receiver as visible if the argument is <code>true</code>, + * and marks it invisible otherwise. + * <p> + * If one of the receiver's ancestors is not visible or some + * other condition makes the receiver not visible, marking + * it visible may not actually cause it to be displayed. + * </p> + * + * @param visible the new visibility state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setVisible (boolean visible) {
- checkWidget();
- if (visible == isVisible) return;
- isVisible = visible;
- if (!isFocusCaret ()) return;
- if (isVisible) {
- showCaret ();
- } else {
- hideCaret ();
- }
-}
-boolean showCaret () {
- if (isShowing) return true;
- isShowing = true;
- return drawCaret ();
-}
-}
+public void setVisible (boolean visible) { + checkWidget(); + if (visible == isVisible) return; + isVisible = visible; + if (!isFocusCaret ()) return; + if (isVisible) { + showCaret (); + } else { + hideCaret (); + } +} +boolean showCaret () { + if (isShowing) return true; + isShowing = true; + return drawCaret (); +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java index 3661875923..0c9ec0e7a3 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ColorDialog.java @@ -1,68 +1,68 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.layout.*;
-
-/**
- * Instances of this class allow the user to select a color
- * from a predefined set of available colors.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html */ -public class ColorDialog extends Dialog {
- private static final int COLORSWATCH_SIZE_DEPTH4 = 40;
- private static final int COLORSWATCH_SIZE_DEPTH8 = 15;
- private static final int COLORSWATCH_SIZE_DEPTH16 = 10;
- private static final int COLORSWATCH_BORDER = 1; // border between each color pad
-
- private Shell shell; // the dialog shell
- private Canvas colorsCanvas;
- private Label sampleLabel, selectionLabel;
- private Canvas sampleCanvas, selectionCanvas;
- private Button okButton, cancelButton;
-
- private boolean okSelected;
- private RGB rgb;
- private int colorDepth; // color depth of the display
- private int colorSwatchExtent; // the size of each color square
- private Color colorGrid[][]; // the colors displayed in the dialog
-
-/**
- * Constructs a new instance of this class given only its parent.
- *
- * @param parent a composite control which will be the parent of the new instance (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
+ +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.layout.*; + +/** + * Instances of this class allow the user to select a color + * from a predefined set of available colors. + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>(none)</dd> + * <dt><b>Events:</b></dt> + * <dd>(none)</dd> + * </dl> + * <p> + * IMPORTANT: This class is intended to be subclassed <em>only</em> + * within the SWT implementation. + * </p> + */ +public class ColorDialog extends Dialog { + private static final int COLORSWATCH_SIZE_DEPTH4 = 40; + private static final int COLORSWATCH_SIZE_DEPTH8 = 15; + private static final int COLORSWATCH_SIZE_DEPTH16 = 10; + private static final int COLORSWATCH_BORDER = 1; // border between each color pad + + private Shell shell; // the dialog shell + private Canvas colorsCanvas; + private Label sampleLabel, selectionLabel; + private Canvas sampleCanvas, selectionCanvas; + private Button okButton, cancelButton; + + private boolean okSelected; + private RGB rgb; + private int colorDepth; // color depth of the display + private int colorSwatchExtent; // the size of each color square + private Color colorGrid[][]; // the colors displayed in the dialog + +/** + * Constructs a new instance of this class given only its parent. + * + * @param parent a composite control which will be the parent of the new instance (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);
-}
+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. @@ -91,357 +91,357 @@ public ColorDialog(Shell parent) { * @see Widget#checkSubclass * @see Widget#getStyle */ -public ColorDialog(Shell parent, int style) {
- super(parent, style | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
- checkSubclass ();
-}
-void createChildren() {
- Shell dialog = shell;
- GridLayout layout = new GridLayout (2, false);
- dialog.setLayout(layout);
-
- int colorChooserWidth = colorSwatchExtent * colorGrid.length;
- int colorChooserHeight = colorSwatchExtent * colorGrid[0].length;
- colorsCanvas = new Canvas(dialog, SWT.BORDER);
- GridData data = new GridData ();
- data.widthHint = colorChooserWidth;
- data.heightHint = colorChooserHeight;
- colorsCanvas.setLayoutData(data);
-
- Composite buttonsGroup = new Composite (dialog, SWT.NONE);
- buttonsGroup.setLayout(new GridLayout());
- buttonsGroup.setLayoutData(new GridData(GridData.BEGINNING));
- createOkCancel(buttonsGroup);
-
- Composite bottomGroup = new Composite (dialog,SWT.NONE);
- layout = new GridLayout(2, true);
- layout.marginHeight = 0;
- layout.marginWidth = 0;
- bottomGroup.setLayout(layout);
- bottomGroup.setLayoutData(new GridData(GridData.FILL_BOTH));
-
- createSampleGroup(bottomGroup);
- createSelectionGroup(bottomGroup);
-}
-void createOkCancel(Composite parent) {
- okButton = new Button(parent, SWT.PUSH);
- okButton.setText(SWT.getMessage("SWT_OK"));
- shell.setDefaultButton(okButton);
- GridData data = new GridData(GridData.FILL_HORIZONTAL);
- okButton.setLayoutData(data);
-
- cancelButton = new Button(parent, SWT.PUSH);
- cancelButton.setText(SWT.getMessage("SWT_Cancel"));
- data = new GridData(GridData.FILL_HORIZONTAL);
- cancelButton.setLayoutData(data);
-}
-void createSampleGroup(Composite parent) {
- Group sampleGroup = new Group(parent, SWT.NULL);
- GridData data = new GridData(GridData.FILL_BOTH);
- data.grabExcessHorizontalSpace = true;
- sampleGroup.setLayout(new GridLayout());
- sampleGroup.setLayoutData(data);
- sampleGroup.setText(SWT.getMessage("SWT_Sample"));
-
- sampleLabel = new Label(sampleGroup, SWT.CENTER | SWT.BORDER);
- sampleLabel.setAlignment(SWT.CENTER);
- sampleLabel.setText(SWT.getMessage("SWT_A_Sample_Text"));
- data = new GridData(GridData.FILL_HORIZONTAL);
- sampleLabel.setLayoutData(data);
-
- sampleCanvas = new Canvas(sampleGroup, SWT.BORDER);
- data = new GridData(GridData.FILL_HORIZONTAL);
- data.heightHint = 15;
- sampleCanvas.setLayoutData(data);
-}
-void createSelectionGroup(Composite parent) {
- Group selectionGroup = new Group(parent, SWT.NULL);
- GridData data = new GridData(GridData.FILL_BOTH);
- data.grabExcessHorizontalSpace = true;
- selectionGroup.setLayout(new GridLayout());
- selectionGroup.setLayoutData(data);
- selectionGroup.setText(SWT.getMessage("SWT_Selection"));
-
- selectionLabel = new Label(selectionGroup, SWT.CENTER | SWT.BORDER);
- selectionLabel.setAlignment(SWT.CENTER);
- selectionLabel.setText(SWT.getMessage("SWT_Current_Selection"));
- data = new GridData(GridData.FILL_HORIZONTAL);
- data.grabExcessHorizontalSpace = true;
- selectionLabel.setLayoutData(data);
-
- selectionCanvas = new Canvas(selectionGroup, SWT.BORDER);
- data = new GridData(GridData.FILL_HORIZONTAL);
- data.grabExcessHorizontalSpace = true;
- data.heightHint = 15;
- selectionCanvas.setLayoutData(data);
-}
-void disposeColors() {
- for (int row = 0; row < colorGrid.length; row++) {
- for (int column = 0; column < colorGrid[row].length; column++) {
- colorGrid[row][column].dispose();
- }
- }
-}
-void drawColor(int xIndex, int yIndex, Color color, GC gc) {
- int colorExtent = colorSwatchExtent - COLORSWATCH_BORDER;
- gc.setBackground(color);
- gc.fillRectangle(
- xIndex * colorSwatchExtent,
- yIndex * colorSwatchExtent,
- colorExtent, colorExtent);
-}
-/**
- * Returns the currently selected color in the receiver.
- *
- * @return the RGB value for the selected color, may be null
- * @see PaletteData#getRGBs
+public ColorDialog(Shell parent, int style) { + super(parent, style | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL); + checkSubclass (); +} +void createChildren() { + Shell dialog = shell; + GridLayout layout = new GridLayout (2, false); + dialog.setLayout(layout); + + int colorChooserWidth = colorSwatchExtent * colorGrid.length; + int colorChooserHeight = colorSwatchExtent * colorGrid[0].length; + colorsCanvas = new Canvas(dialog, SWT.BORDER); + GridData data = new GridData (); + data.widthHint = colorChooserWidth; + data.heightHint = colorChooserHeight; + colorsCanvas.setLayoutData(data); + + Composite buttonsGroup = new Composite (dialog, SWT.NONE); + buttonsGroup.setLayout(new GridLayout()); + buttonsGroup.setLayoutData(new GridData(GridData.BEGINNING)); + createOkCancel(buttonsGroup); + + Composite bottomGroup = new Composite (dialog,SWT.NONE); + layout = new GridLayout(2, true); + layout.marginHeight = 0; + layout.marginWidth = 0; + bottomGroup.setLayout(layout); + bottomGroup.setLayoutData(new GridData(GridData.FILL_BOTH)); + + createSampleGroup(bottomGroup); + createSelectionGroup(bottomGroup); +} +void createOkCancel(Composite parent) { + okButton = new Button(parent, SWT.PUSH); + okButton.setText(SWT.getMessage("SWT_OK")); + shell.setDefaultButton(okButton); + GridData data = new GridData(GridData.FILL_HORIZONTAL); + okButton.setLayoutData(data); + + cancelButton = new Button(parent, SWT.PUSH); + cancelButton.setText(SWT.getMessage("SWT_Cancel")); + data = new GridData(GridData.FILL_HORIZONTAL); + cancelButton.setLayoutData(data); +} +void createSampleGroup(Composite parent) { + Group sampleGroup = new Group(parent, SWT.NULL); + GridData data = new GridData(GridData.FILL_BOTH); + data.grabExcessHorizontalSpace = true; + sampleGroup.setLayout(new GridLayout()); + sampleGroup.setLayoutData(data); + sampleGroup.setText(SWT.getMessage("SWT_Sample")); + + sampleLabel = new Label(sampleGroup, SWT.CENTER | SWT.BORDER); + sampleLabel.setAlignment(SWT.CENTER); + sampleLabel.setText(SWT.getMessage("SWT_A_Sample_Text")); + data = new GridData(GridData.FILL_HORIZONTAL); + sampleLabel.setLayoutData(data); + + sampleCanvas = new Canvas(sampleGroup, SWT.BORDER); + data = new GridData(GridData.FILL_HORIZONTAL); + data.heightHint = 15; + sampleCanvas.setLayoutData(data); +} +void createSelectionGroup(Composite parent) { + Group selectionGroup = new Group(parent, SWT.NULL); + GridData data = new GridData(GridData.FILL_BOTH); + data.grabExcessHorizontalSpace = true; + selectionGroup.setLayout(new GridLayout()); + selectionGroup.setLayoutData(data); + selectionGroup.setText(SWT.getMessage("SWT_Selection")); + + selectionLabel = new Label(selectionGroup, SWT.CENTER | SWT.BORDER); + selectionLabel.setAlignment(SWT.CENTER); + selectionLabel.setText(SWT.getMessage("SWT_Current_Selection")); + data = new GridData(GridData.FILL_HORIZONTAL); + data.grabExcessHorizontalSpace = true; + selectionLabel.setLayoutData(data); + + selectionCanvas = new Canvas(selectionGroup, SWT.BORDER); + data = new GridData(GridData.FILL_HORIZONTAL); + data.grabExcessHorizontalSpace = true; + data.heightHint = 15; + selectionCanvas.setLayoutData(data); +} +void disposeColors() { + for (int row = 0; row < colorGrid.length; row++) { + for (int column = 0; column < colorGrid[row].length; column++) { + colorGrid[row][column].dispose(); + } + } +} +void drawColor(int xIndex, int yIndex, Color color, GC gc) { + int colorExtent = colorSwatchExtent - COLORSWATCH_BORDER; + gc.setBackground(color); + gc.fillRectangle( + xIndex * colorSwatchExtent, + yIndex * colorSwatchExtent, + colorExtent, colorExtent); +} +/** + * Returns the currently selected color in the receiver. + * + * @return the RGB value for the selected color, may be null + * @see PaletteData#getRGBs */ -public RGB getRGB() {
- return rgb;
-}
-void handleEvents(Event event) {
- if (event.type == SWT.Paint) {
- paint(event);
- }
- else
- if (event.type == SWT.MouseDown) {
- mouseDown(event);
- }
- else
- if (event.type == SWT.MouseMove) {
- mouseMove(event);
- }
- else
- if (event.type == SWT.Selection) {
- if (event.widget == okButton) {
- okSelected = true;
- shell.setVisible(false);
- }
- else
- if (event.widget == cancelButton) {
- okSelected = false;
- shell.setVisible(false);
- }
- }
-}
-void initialize4BitColors() {
- Display display = shell.getDisplay();
-
- colorGrid[0][0] = new Color(display, 0, 0, 0);
- colorGrid[0][1] = new Color(display, 255, 255, 255);
- colorGrid[1][0] = new Color(display, 128, 128, 128);
- colorGrid[1][1] = new Color(display, 192, 192, 192);
-
- colorGrid[2][0] = new Color(display, 0, 0, 128);
- colorGrid[2][1] = new Color(display, 0, 0, 255);
- colorGrid[3][0] = new Color(display, 0, 128, 128);
- colorGrid[3][1] = new Color(display, 0, 255, 255);
-
- colorGrid[4][0] = new Color(display, 0, 128, 0);
- colorGrid[4][1] = new Color(display, 0, 255, 0);
- colorGrid[5][0] = new Color(display, 128, 128, 0);
- colorGrid[5][1] = new Color(display, 255, 255, 0);
-
- colorGrid[6][0] = new Color(display, 128, 0, 0);
- colorGrid[6][1] = new Color(display, 255, 0, 0);
- colorGrid[7][0] = new Color(display, 128, 0, 128);
- colorGrid[7][1] = new Color(display, 255, 0, 255);
-}
-void initialize8BitColors() {
- Display display = shell.getDisplay();
- int numRows = colorGrid[0].length;
- int iterationStep = 64;
- int row = 0, column = 0;
- int red, green, blue;
- // run the loops from 0 to 256 inclusive since this is easiest for the step
- // size, then adjust the 256 case to the proper 255 value when needed
- for (red = 0; red <= 256; red += iterationStep) {
- for (blue = 0; blue <= 256; blue += iterationStep) {
- for (green = 0; green <= 256; green += iterationStep) {
- if (row == numRows) {
- row = 0;
- column++;
- }
- if (red == 256) red = 255;
- if (blue == 256) blue = 255;
- if (green == 256) green = 255;
- colorGrid[column][row++] = new Color(display, red, green, blue);
- }
- }
- }
-}
-void initialize16BitColors() {
- Display display = shell.getDisplay();
- int numRows = colorGrid[0].length;
- int iterationStep = 51;
- int row = 0, column = 0;
- int red, green, blue;
-
- for (red = 0; red <= 255; red += iterationStep) {
- for (blue = 0; blue <= 255; blue += iterationStep) {
- if (blue == iterationStep && column < 20) { // hack to evenly distribute 256 colors on 32 columns
- blue += iterationStep;
- }
- for (green = 0; green <= 255; green += iterationStep) {
- if (row == 2 || row == 5) { // hack to evenly distribute 256 colors on 8 rows
- colorGrid[column][row++] = new Color(display, red, green - iterationStep / 2, blue);
- }
- if (row == numRows) {
- row = 0;
- column++;
- }
- colorGrid[column][row++] = new Color(display, red, green, blue);
- }
- }
- }
-}
-void initializeWidgets() {
- Display display = shell.getDisplay();
- if (rgb != null) {
- Color selectionColor = new Color(display, rgb);
- selectionCanvas.setBackground(selectionColor);
- selectionLabel.setBackground(selectionColor);
- selectionColor.dispose();
- }
-}
-void installListeners() {
- Listener listener = new Listener() {
- public void handleEvent(Event event) {handleEvents(event);}
- };
- okButton.addListener(SWT.Selection, listener);
- cancelButton.addListener(SWT.Selection, listener);
- colorsCanvas.addListener(SWT.Paint, listener);
- colorsCanvas.addListener(SWT.MouseDown, listener);
- colorsCanvas.addListener(SWT.MouseMove, listener);
-}
-void mouseDown(Event event) {
- int swatchExtent = colorSwatchExtent;
- Color color = colorGrid[event.x / swatchExtent][event.y / swatchExtent];
- selectionCanvas.setBackground(color);
- selectionLabel.setBackground(color);
-}
-void mouseMove(Event event) {
- int swatchExtent = colorSwatchExtent;
- // adjust for events received from moving over the Canvas' border
- int xgrid = Math.min(colorGrid.length - 1, event.x / swatchExtent);
- int ygrid = Math.min(colorGrid[0].length - 1, event.y / swatchExtent);
- Color color = colorGrid[xgrid][ygrid];
- sampleCanvas.setBackground(color);
- sampleLabel.setBackground(color);
-}
-/**
- * Makes the receiver visible and brings it to the front
- * of the display.
- *
- * @return the selected color, or null if the dialog was
- * cancelled, no color was selected, or an error
- * occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public RGB getRGB() { + return rgb; +} +void handleEvents(Event event) { + if (event.type == SWT.Paint) { + paint(event); + } + else + if (event.type == SWT.MouseDown) { + mouseDown(event); + } + else + if (event.type == SWT.MouseMove) { + mouseMove(event); + } + else + if (event.type == SWT.Selection) { + if (event.widget == okButton) { + okSelected = true; + shell.setVisible(false); + } + else + if (event.widget == cancelButton) { + okSelected = false; + shell.setVisible(false); + } + } +} +void initialize4BitColors() { + Display display = shell.getDisplay(); + + colorGrid[0][0] = new Color(display, 0, 0, 0); + colorGrid[0][1] = new Color(display, 255, 255, 255); + colorGrid[1][0] = new Color(display, 128, 128, 128); + colorGrid[1][1] = new Color(display, 192, 192, 192); + + colorGrid[2][0] = new Color(display, 0, 0, 128); + colorGrid[2][1] = new Color(display, 0, 0, 255); + colorGrid[3][0] = new Color(display, 0, 128, 128); + colorGrid[3][1] = new Color(display, 0, 255, 255); + + colorGrid[4][0] = new Color(display, 0, 128, 0); + colorGrid[4][1] = new Color(display, 0, 255, 0); + colorGrid[5][0] = new Color(display, 128, 128, 0); + colorGrid[5][1] = new Color(display, 255, 255, 0); + + colorGrid[6][0] = new Color(display, 128, 0, 0); + colorGrid[6][1] = new Color(display, 255, 0, 0); + colorGrid[7][0] = new Color(display, 128, 0, 128); + colorGrid[7][1] = new Color(display, 255, 0, 255); +} +void initialize8BitColors() { + Display display = shell.getDisplay(); + int numRows = colorGrid[0].length; + int iterationStep = 64; + int row = 0, column = 0; + int red, green, blue; + // run the loops from 0 to 256 inclusive since this is easiest for the step + // size, then adjust the 256 case to the proper 255 value when needed + for (red = 0; red <= 256; red += iterationStep) { + for (blue = 0; blue <= 256; blue += iterationStep) { + for (green = 0; green <= 256; green += iterationStep) { + if (row == numRows) { + row = 0; + column++; + } + if (red == 256) red = 255; + if (blue == 256) blue = 255; + if (green == 256) green = 255; + colorGrid[column][row++] = new Color(display, red, green, blue); + } + } + } +} +void initialize16BitColors() { + Display display = shell.getDisplay(); + int numRows = colorGrid[0].length; + int iterationStep = 51; + int row = 0, column = 0; + int red, green, blue; + + for (red = 0; red <= 255; red += iterationStep) { + for (blue = 0; blue <= 255; blue += iterationStep) { + if (blue == iterationStep && column < 20) { // hack to evenly distribute 256 colors on 32 columns + blue += iterationStep; + } + for (green = 0; green <= 255; green += iterationStep) { + if (row == 2 || row == 5) { // hack to evenly distribute 256 colors on 8 rows + colorGrid[column][row++] = new Color(display, red, green - iterationStep / 2, blue); + } + if (row == numRows) { + row = 0; + column++; + } + colorGrid[column][row++] = new Color(display, red, green, blue); + } + } + } +} +void initializeWidgets() { + Display display = shell.getDisplay(); + if (rgb != null) { + Color selectionColor = new Color(display, rgb); + selectionCanvas.setBackground(selectionColor); + selectionLabel.setBackground(selectionColor); + selectionColor.dispose(); + } +} +void installListeners() { + Listener listener = new Listener() { + public void handleEvent(Event event) {handleEvents(event);} + }; + okButton.addListener(SWT.Selection, listener); + cancelButton.addListener(SWT.Selection, listener); + colorsCanvas.addListener(SWT.Paint, listener); + colorsCanvas.addListener(SWT.MouseDown, listener); + colorsCanvas.addListener(SWT.MouseMove, listener); +} +void mouseDown(Event event) { + int swatchExtent = colorSwatchExtent; + Color color = colorGrid[event.x / swatchExtent][event.y / swatchExtent]; + selectionCanvas.setBackground(color); + selectionLabel.setBackground(color); +} +void mouseMove(Event event) { + int swatchExtent = colorSwatchExtent; + // adjust for events received from moving over the Canvas' border + int xgrid = Math.min(colorGrid.length - 1, event.x / swatchExtent); + int ygrid = Math.min(colorGrid[0].length - 1, event.y / swatchExtent); + Color color = colorGrid[xgrid][ygrid]; + sampleCanvas.setBackground(color); + sampleLabel.setBackground(color); +} +/** + * Makes the receiver visible and brings it to the front + * of the display. + * + * @return the selected color, or null if the dialog was + * cancelled, no color was selected, or an error + * occurred + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public RGB open() {
- shell = new Shell(parent, getStyle() | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
- setColorDepth(shell.getDisplay().getDepth());
- createChildren();
- installListeners();
- openModal();
- if (okSelected) {
- Color selectionColor = selectionCanvas.getBackground();
- rgb = new RGB(
- selectionColor.getRed(),
- selectionColor.getGreen(),
- selectionColor.getBlue());
- }
- disposeColors();
- if (shell.isDisposed() == false) {
- shell.dispose();
- }
- if (!okSelected) return null;
- return rgb;
-}
-/**
- * Open the receiver and set its size to the size calculated by
- * the layout manager.
- */
-void openDialog() {
- Shell dialog = shell;
-
- // Start everything off by setting the shell size to its computed size.
- Point pt = dialog.computeSize(-1, -1, false);
-
- // Ensure that the width of the shell fits the display.
- Rectangle displayRect = dialog.getDisplay().getBounds();
- int widthLimit = displayRect.width * 7 / 8;
- int heightLimit = displayRect.height * 7 / 8;
- if (pt.x > widthLimit) {
- pt = dialog.computeSize (widthLimit, -1, false);
- }
-
- // centre the dialog on its parent, and ensure that the
- // whole dialog appears within the screen bounds
- Rectangle parentBounds = getParent ().getBounds ();
- int originX = (parentBounds.width - pt.x) / 2 + parentBounds.x;
- originX = Math.max (originX, 0);
- originX = Math.min (originX, widthLimit - pt.x);
- int originY = (parentBounds.height - pt.y) / 2 + parentBounds.y;
- originY = Math.max (originY, 0);
- originY = Math.min (originY, heightLimit - pt.y);
- dialog.setBounds (originX, originY, pt.x, pt.y);
-
- String title = getText ();
- if (title.length () == 0) title = SWT.getMessage ("SWT_ColorDialog_Title");
- shell.setText(title);
-
- dialog.open();
-}
-void openModal() {
- Display display = shell.getDisplay();
- initializeWidgets();
- openDialog();
- while (shell.isDisposed() == false && shell.getVisible() == true) {
- if (display.readAndDispatch() == false) {
- display.sleep();
- }
- }
-}
-void paint(Event event) {
- for (int column = 0; column < colorGrid.length; column++) {
- for (int row = 0; row < colorGrid[0].length; row++) {
- drawColor(column, row, colorGrid[column][row], event.gc);
- }
- }
-}
-void setColorDepth(int bits) {
- colorDepth = bits;
- if (bits == 4) {
- colorSwatchExtent = COLORSWATCH_SIZE_DEPTH4;
- colorGrid = new Color[8][2];
- initialize4BitColors();
- return;
- }
- if (bits == 8) {
- colorSwatchExtent = COLORSWATCH_SIZE_DEPTH8;
- colorGrid = new Color[25][5];
- initialize8BitColors();
- return;
- }
- // default case: 16, 24 or 32 bits
- colorSwatchExtent = COLORSWATCH_SIZE_DEPTH16;
- colorGrid = new Color[32][8];
- initialize16BitColors();
-}
-/**
- * Sets the receiver's selected color to be the argument.
- *
- * @param rgb the new RGB value for the selected color, may be
- * null to let the platform to select a default when
- * open() is called
- * @see PaletteData#getRGBs
+public RGB open() { + shell = new Shell(parent, getStyle() | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL); + setColorDepth(shell.getDisplay().getDepth()); + createChildren(); + installListeners(); + openModal(); + if (okSelected) { + Color selectionColor = selectionCanvas.getBackground(); + rgb = new RGB( + selectionColor.getRed(), + selectionColor.getGreen(), + selectionColor.getBlue()); + } + disposeColors(); + if (shell.isDisposed() == false) { + shell.dispose(); + } + if (!okSelected) return null; + return rgb; +} +/** + * Open the receiver and set its size to the size calculated by + * the layout manager. + */ +void openDialog() { + Shell dialog = shell; + + // Start everything off by setting the shell size to its computed size. + Point pt = dialog.computeSize(-1, -1, false); + + // Ensure that the width of the shell fits the display. + Rectangle displayRect = dialog.getDisplay().getBounds(); + int widthLimit = displayRect.width * 7 / 8; + int heightLimit = displayRect.height * 7 / 8; + if (pt.x > widthLimit) { + pt = dialog.computeSize (widthLimit, -1, false); + } + + // centre the dialog on its parent, and ensure that the + // whole dialog appears within the screen bounds + Rectangle parentBounds = getParent ().getBounds (); + int originX = (parentBounds.width - pt.x) / 2 + parentBounds.x; + originX = Math.max (originX, 0); + originX = Math.min (originX, widthLimit - pt.x); + int originY = (parentBounds.height - pt.y) / 2 + parentBounds.y; + originY = Math.max (originY, 0); + originY = Math.min (originY, heightLimit - pt.y); + dialog.setBounds (originX, originY, pt.x, pt.y); + + String title = getText (); + if (title.length () == 0) title = SWT.getMessage ("SWT_ColorDialog_Title"); + shell.setText(title); + + dialog.open(); +} +void openModal() { + Display display = shell.getDisplay(); + initializeWidgets(); + openDialog(); + while (shell.isDisposed() == false && shell.getVisible() == true) { + if (display.readAndDispatch() == false) { + display.sleep(); + } + } +} +void paint(Event event) { + for (int column = 0; column < colorGrid.length; column++) { + for (int row = 0; row < colorGrid[0].length; row++) { + drawColor(column, row, colorGrid[column][row], event.gc); + } + } +} +void setColorDepth(int bits) { + colorDepth = bits; + if (bits == 4) { + colorSwatchExtent = COLORSWATCH_SIZE_DEPTH4; + colorGrid = new Color[8][2]; + initialize4BitColors(); + return; + } + if (bits == 8) { + colorSwatchExtent = COLORSWATCH_SIZE_DEPTH8; + colorGrid = new Color[25][5]; + initialize8BitColors(); + return; + } + // default case: 16, 24 or 32 bits + colorSwatchExtent = COLORSWATCH_SIZE_DEPTH16; + colorGrid = new Color[32][8]; + initialize16BitColors(); +} +/** + * Sets the receiver's selected color to be the argument. + * + * @param rgb the new RGB value for the selected color, may be + * null to let the platform to select a default when + * open() is called + * @see PaletteData#getRGBs */ -public void setRGB(RGB rgb) {
- this.rgb = rgb;
-}
-}
+public void setRGB(RGB rgb) { + this.rgb = rgb; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java index 5c681bcfda..f8a799d641 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Combo.java @@ -1,71 +1,71 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class are controls that allow the user
- * to choose an item from a list of items, or optionally
- * enter a new value by typing it into an editable text
- * field. Often, <code>Combo</code>s are used in the same place
- * where a single selection <code>List</code> widget could
- * be used but space is limited. A <code>Combo</code> takes
- * less space than a <code>List</code> widget and shows
- * similar information.
- * <p>
- * Note: Since <code>Combo</code>s can contain both a list
- * and an editable text field, it is possible to confuse methods
- * which access one versus the other (compare for example,
- * <code>clearSelection()</code> and <code>deselectAll()</code>).
- * The API documentation is careful to indicate either "the
- * receiver's list" or the "the receiver's text field" to
- * distinguish between the two cases.
- * </p><p>
- * Note that although this class is a subclass of <code>Composite</code>,
- * it does not make sense to add children to it, or set a layout on it.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>DROP_DOWN, READ_ONLY, SIMPLE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>DefaultSelection, Modify, Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles DROP_DOWN and SIMPLE
- * may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see List
+ * http://www.eclipse.org/legal/cpl-v10.html */ -public class Combo extends Composite {
- /**
- * the operating system limit for the number of characters
- * that the text field in an instance of this class can hold
+ +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.events.*; + +/** + * Instances of this class are controls that allow the user + * to choose an item from a list of items, or optionally + * enter a new value by typing it into an editable text + * field. Often, <code>Combo</code>s are used in the same place + * where a single selection <code>List</code> widget could + * be used but space is limited. A <code>Combo</code> takes + * less space than a <code>List</code> widget and shows + * similar information. + * <p> + * Note: Since <code>Combo</code>s can contain both a list + * and an editable text field, it is possible to confuse methods + * which access one versus the other (compare for example, + * <code>clearSelection()</code> and <code>deselectAll()</code>). + * The API documentation is careful to indicate either "the + * receiver's list" or the "the receiver's text field" to + * distinguish between the two cases. + * </p><p> + * Note that although this class is a subclass of <code>Composite</code>, + * it does not make sense to add children to it, or set a layout on it. + * </p> + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>DROP_DOWN, READ_ONLY, SIMPLE</dd> + * <dt><b>Events:</b></dt> + * <dd>DefaultSelection, Modify, Selection</dd> + * </dl> + * <p> + * Note: Only one of the styles DROP_DOWN and SIMPLE + * may be specified. + * </p><p> + * IMPORTANT: This class is <em>not</em> intended to be subclassed. + * </p> + * + * @see List + */ +public class Combo extends Composite { + /** + * the operating system limit for the number of characters + * that the text field in an instance of this class can hold */ - public static final int LIMIT;
-
- /*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
- static {
- LIMIT = 0x7FFFFFFF;
- }
-
- boolean ignoreSelect;
+ public static final int LIMIT; + + /* + * These values can be different on different platforms. + * Therefore they are not initialized in the declaration + * to stop the compiler from inlining. + */ + static { + LIMIT = 0x7FFFFFFF; + } + + boolean ignoreSelect; /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -96,1345 +96,1345 @@ public class Combo extends Composite { * @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 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);
-
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- OS.XmComboBoxAddItem(handle, xmString, -1, false);
- OS.XmStringFree (xmString);
-}
-/**
- * Adds the argument to the receiver's list at the given
- * zero-relative index.
- * <p>
- * Note: To add an item at the end of the list, use the
- * result of calling <code>getItemCount()</code> as the
- * index or use <code>add(String)</code>.
- * </p>
- *
- * @param string the new item
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @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) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + + byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true); + int xmString = OS.XmStringCreateLocalized (buffer); + if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED); + OS.XmComboBoxAddItem(handle, xmString, -1, false); + OS.XmStringFree (xmString); +} +/** + * Adds the argument to the receiver's list at the given + * zero-relative index. + * <p> + * Note: To add an item at the end of the list, use the + * result of calling <code>getItemCount()</code> as the + * index or use <code>add(String)</code>. + * </p> + * + * @param string the new item + * @param index the index for the item + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the string is null</li> + * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @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_INVALID_RANGE);
-
- /*
- * Feature in Motif. When an index is out of range,
- * the list widget adds the item at the end. This
- * behavior is not wrong but it is unwanted. The
- * fix is to check the range before adding the item.
- */
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= index && index <= argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- OS.XmComboBoxAddItem(handle, xmString, index + 1, false);
- OS.XmStringFree (xmString);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
+public void add (String string, int index) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + if (index == -1) error (SWT.ERROR_INVALID_RANGE); + + /* + * Feature in Motif. When an index is out of range, + * the list widget adds the item at the end. This + * behavior is not wrong but it is unwanted. The + * fix is to check the range before adding the item. + */ + int [] argList = {OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (!(0 <= index && index <= argList [1])) { + error (SWT.ERROR_INVALID_RANGE); + } + byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true); + int xmString = OS.XmStringCreateLocalized (buffer); + if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED); + OS.XmComboBoxAddItem(handle, xmString, index + 1, false); + OS.XmStringFree (xmString); +} +/** + * Adds the listener to the collection of listeners who will + * be notified when the receiver's text is modified, by sending + * it one of the messages defined in the <code>ModifyListener</code> + * interface. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see ModifyListener + * @see #removeModifyListener */ -public void addModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the 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 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;
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-/**
- * Sets the selection in the receiver's text field to an empty
- * selection starting just before the first character. If the
- * text field is editable, this has the effect of placing the
- * i-beam at the start of the text.
- * <p>
- * Note: To clear the selected items in the receiver's list,
- * use <code>deselectAll()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #deselectAll
+public void 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; +} +protected void checkSubclass () { + if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); +} +/** + * Sets the selection in the receiver's text field to an empty + * selection starting just before the first character. If the + * text field is editable, this has the effect of placing the + * i-beam at the start of the text. + * <p> + * Note: To clear the selected items in the receiver's list, + * use <code>deselectAll()</code>. + * </p> + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #deselectAll */ -public void clearSelection () {
- checkWidget();
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmTextClearSelection (argList[1], OS.XtLastTimestampProcessed (xDisplay));
-}
-
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int [] argList = {
- OS.XmNlist, 0,
- OS.XmNtextField, 0,
- OS.XmNitemCount, 0,
- OS.XmNmarginWidth, 0,
- OS.XmNshadowThickness, 0,
- OS.XmNhighlightThickness, 0,
- OS.XmNarrowSize, 0,
- OS.XmNarrowSpacing, 0,
- };
- OS.XtGetValues(handle, argList, argList.length / 2);
- XtWidgetGeometry result = new XtWidgetGeometry ();
- result.request_mode = OS.CWWidth;
- OS.XtQueryGeometry (argList[1], null, result);
- int width = result.width, height = getTextHeight();
- int[] argList2 = {OS.XmNmarginWidth, 0, OS.XmNshadowThickness, 0};
- OS.XtGetValues(argList[3], argList2, argList2.length / 2);
- if ((style & SWT.READ_ONLY) == 0) width += (2 * argList[7]);
- if ((style & SWT.DROP_DOWN) != 0) {
- width += argList[13] + argList[15];
- } else {
- int itemCount = (argList[5] == 0) ? 5 : argList[5];
- height += (getItemHeight () * itemCount);
- }
- width += (2 * argList[9])
- + (2 * argList[11])
- + (2 * argList2[1])
- + (2 * argList2[3]);
- if (argList[5] == 0) width = DEFAULT_WIDTH;
- if (hHint != SWT.DEFAULT) height = hHint;
- if (wHint != SWT.DEFAULT) width = wHint;
- Rectangle rect = computeTrim (0, 0, width, height);
- return new Point (rect.width, rect.height);
-}
-/**
- * Copies the selected text.
- * <p>
- * The current selection is copied to the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void copy () {
- checkWidget();
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmTextCopy (argList [1], OS.XtLastTimestampProcessed (xDisplay));
-}
-void createHandle (int index) {
- state |= HANDLE;
-
- /*
- * Feature in Motif. When items are added or removed
- * from a combo, it may request and be granted, a new
- * preferred size. This behavior is unwanted. The fix
- * is to create a parent for the list that will disallow
- * geometry requests.
- */
- int parentHandle = parent.handle;
- int [] argList1 = {OS.XmNancestorSensitive, 1};
- formHandle = OS.XmCreateForm (parentHandle, null, argList1, argList1.length / 2);
- if (formHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int comboBoxType = OS.XmDROP_DOWN_COMBO_BOX;
- if ((style & SWT.SIMPLE) != 0) {
- comboBoxType = OS.XmCOMBO_BOX;
- } else if ((style & SWT.READ_ONLY) != 0) {
- comboBoxType = OS.XmDROP_DOWN_LIST;
- }
- int [] argList2 = {
- OS.XmNcomboBoxType, comboBoxType,
- OS.XmNtopAttachment, OS.XmATTACH_FORM,
- OS.XmNbottomAttachment, OS.XmATTACH_FORM,
- OS.XmNleftAttachment, OS.XmATTACH_FORM,
- OS.XmNrightAttachment, OS.XmATTACH_FORM,
- OS.XmNresizable, 0,
- };
- handle = OS.XmCreateComboBox (formHandle, null, argList2, argList2.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-/**
- * 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>
- *
- * @since 2.1
- */
-public void cut () {
- checkWidget();
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmTextCut (argList [1], OS.XtLastTimestampProcessed (xDisplay));
-}
-/**
- * Deselects the item at the given zero-relative index in the receiver's
- * list. If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void clearSelection () { + checkWidget(); + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return; + int [] argList = {OS.XmNtextField, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + OS.XmTextClearSelection (argList[1], OS.XtLastTimestampProcessed (xDisplay)); +} + +public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget(); + int [] argList = { + OS.XmNlist, 0, + OS.XmNtextField, 0, + OS.XmNitemCount, 0, + OS.XmNmarginWidth, 0, + OS.XmNshadowThickness, 0, + OS.XmNhighlightThickness, 0, + OS.XmNarrowSize, 0, + OS.XmNarrowSpacing, 0, + }; + OS.XtGetValues(handle, argList, argList.length / 2); + XtWidgetGeometry result = new XtWidgetGeometry (); + result.request_mode = OS.CWWidth; + OS.XtQueryGeometry (argList[1], null, result); + int width = result.width, height = getTextHeight(); + int[] argList2 = {OS.XmNmarginWidth, 0, OS.XmNshadowThickness, 0}; + OS.XtGetValues(argList[3], argList2, argList2.length / 2); + if ((style & SWT.READ_ONLY) == 0) width += (2 * argList[7]); + if ((style & SWT.DROP_DOWN) != 0) { + width += argList[13] + argList[15]; + } else { + int itemCount = (argList[5] == 0) ? 5 : argList[5]; + height += (getItemHeight () * itemCount); + } + width += (2 * argList[9]) + + (2 * argList[11]) + + (2 * argList2[1]) + + (2 * argList2[3]); + if (argList[5] == 0) width = DEFAULT_WIDTH; + if (hHint != SWT.DEFAULT) height = hHint; + if (wHint != SWT.DEFAULT) width = wHint; + Rectangle rect = computeTrim (0, 0, width, height); + return new Point (rect.width, rect.height); +} +/** + * Copies the selected text. + * <p> + * The current selection is copied to the clipboard. + * </p> + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 2.1 */ -public void deselect (int index) {
- checkWidget();
- if (index == -1) return;
- int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
-
- if (OS.XmListPosSelected (argList[3], index + 1)) {
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetString (argList[1], new byte[1]);
- display.setWarnings (warnings);
- OS.XmListDeselectAllItems (argList[3]);
- }
-}
-/**
- * Deselects all selected items in the receiver's list.
- * <p>
- * Note: To clear the selection in the receiver's text field,
- * use <code>clearSelection()</code>.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #clearSelection
+public void copy () { + checkWidget(); + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return; + int [] argList = {OS.XmNtextField, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + OS.XmTextCopy (argList [1], OS.XtLastTimestampProcessed (xDisplay)); +} +void createHandle (int index) { + state |= HANDLE; + + /* + * Feature in Motif. When items are added or removed + * from a combo, it may request and be granted, a new + * preferred size. This behavior is unwanted. The fix + * is to create a parent for the list that will disallow + * geometry requests. + */ + int parentHandle = parent.handle; + int [] argList1 = {OS.XmNancestorSensitive, 1}; + formHandle = OS.XmCreateForm (parentHandle, null, argList1, argList1.length / 2); + if (formHandle == 0) error (SWT.ERROR_NO_HANDLES); + int comboBoxType = OS.XmDROP_DOWN_COMBO_BOX; + if ((style & SWT.SIMPLE) != 0) { + comboBoxType = OS.XmCOMBO_BOX; + } else if ((style & SWT.READ_ONLY) != 0) { + comboBoxType = OS.XmDROP_DOWN_LIST; + } + int [] argList2 = { + OS.XmNcomboBoxType, comboBoxType, + OS.XmNtopAttachment, OS.XmATTACH_FORM, + OS.XmNbottomAttachment, OS.XmATTACH_FORM, + OS.XmNleftAttachment, OS.XmATTACH_FORM, + OS.XmNrightAttachment, OS.XmATTACH_FORM, + OS.XmNresizable, 0, + }; + handle = OS.XmCreateComboBox (formHandle, null, argList2, argList2.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); +} +/** + * 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> + * + * @since 2.1 + */ +public void cut () { + checkWidget(); + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return; + int [] argList = {OS.XmNtextField, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + OS.XmTextCut (argList [1], OS.XtLastTimestampProcessed (xDisplay)); +} +/** + * Deselects the item at the given zero-relative index in the receiver's + * list. If the item at the index was already deselected, it remains + * deselected. Indices that are out of range are ignored. + * + * @param index the index of the item to deselect + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void deselect (int index) { + checkWidget(); + if (index == -1) return; + int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + + if (OS.XmListPosSelected (argList[3], index + 1)) { + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XmTextSetString (argList[1], new byte[1]); + display.setWarnings (warnings); + OS.XmListDeselectAllItems (argList[3]); + } +} +/** + * Deselects all selected items in the receiver's list. + * <p> + * Note: To clear the selection in the receiver's text field, + * use <code>clearSelection()</code>. + * </p> + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #clearSelection */ -public void deselectAll () {
- checkWidget();
- int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetString (argList[1], new byte[1]);
- display.setWarnings(warnings);
- OS.XmListDeselectAllItems (argList[3]);
-}
-
-
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver's list. Throws an exception if the index is out
- * of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li>
- * </ul>
+public void deselectAll () { + checkWidget(); + int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XmTextSetString (argList[1], new byte[1]); + display.setWarnings(warnings); + OS.XmListDeselectAllItems (argList[3]); +} + + +/** + * Returns the item at the given, zero-relative index in the + * receiver's list. Throws an exception if the index is out + * of range. + * + * @param index the index of the item to return + * @return the item at the given index + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @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 [] argList = {OS.XmNitemCount, 0, OS.XmNitems, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (!(0 <= index && index < argList [1])) { + error (SWT.ERROR_INVALID_RANGE); + } + if (argList [3] == 0) error (SWT.ERROR_CANNOT_GET_ITEM); + int ptr = argList [3] + (index * 4); + int [] buffer1 = new int [1]; + OS.memmove (buffer1, ptr, 4); + ptr = buffer1 [0]; + int address = OS.XmStringUnparse ( + ptr, + null, + OS.XmCHARSET_TEXT, + OS.XmCHARSET_TEXT, + null, + 0, + OS.XmOUTPUT_ALL); + if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM); + int length = OS.strlen (address); + byte [] buffer = new byte [length]; + OS.memmove (buffer, address, length); + OS.XtFree (address); + return decodeString(new String (Converter.mbcsToWcs (getCodePage (), buffer))); +} +/** + * Returns the number of items contained in the receiver's list. + * + * @return the number of items + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @exception SWTError <ul> + * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li> + * </ul> */ -public String getItem (int index) {
- checkWidget();
- int [] argList = {OS.XmNitemCount, 0, OS.XmNitems, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= index && index < argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- if (argList [3] == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- int ptr = argList [3] + (index * 4);
- int [] buffer1 = new int [1];
- OS.memmove (buffer1, ptr, 4);
- ptr = buffer1 [0];
- int address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- OS.XmOUTPUT_ALL);
- if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- OS.XtFree (address);
- return decodeString(new String (Converter.mbcsToWcs (getCodePage (), buffer)));
-}
-/**
- * Returns the number of items contained in the receiver's list.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li>
- * </ul>
+public int getItemCount () { + checkWidget(); + int [] argList = {OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns the height of the area which would be used to + * display <em>one</em> of the items in the receiver's list. + * + * @return the height of one item + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @exception SWTError <ul> + * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</li> + * </ul> */ -public int getItemCount () {
- checkWidget();
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the receiver's list.
- *
- * @return the height of one item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @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(); + int [] listHandleArgs = {OS.XmNlist, 0}; + OS.XtGetValues (handle, listHandleArgs, listHandleArgs.length / 2); + int [] argList = {OS.XmNlistSpacing, 0, OS.XmNhighlightThickness, 0}; + OS.XtGetValues (listHandleArgs[1], argList, argList.length / 2); + int spacing = argList [1], highlight = argList [3]; + /* Result is from empirical analysis on Linux and AIX */ + return getFontHeight () + spacing + (2 * highlight); +} +/** + * 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 int getItemHeight () {
- checkWidget();
- int [] listHandleArgs = {OS.XmNlist, 0};
- OS.XtGetValues (handle, listHandleArgs, listHandleArgs.length / 2);
- int [] argList = {OS.XmNlistSpacing, 0, OS.XmNhighlightThickness, 0};
- OS.XtGetValues (listHandleArgs[1], argList, argList.length / 2);
- int spacing = argList [1], highlight = argList [3];
- /* Result is from empirical analysis on Linux and AIX */
- return getFontHeight () + spacing + (2 * highlight);
-}
-/**
- * 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(); + int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int items = argList [1], itemCount = argList [3]; + int [] buffer1 = new int [1]; + String [] result = new String [itemCount]; + String codePage = getCodePage (); + for (int i = 0; i < itemCount; i++) { + OS.memmove (buffer1, items, 4); + int ptr = buffer1 [0]; + int address = OS.XmStringUnparse ( + ptr, + null, + OS.XmCHARSET_TEXT, + OS.XmCHARSET_TEXT, + null, + 0, + OS.XmOUTPUT_ALL); + if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM); + int length = OS.strlen (address); + byte [] buffer = new byte [length]; + OS.memmove (buffer, address, length); + OS.XtFree (address); + result[i] = decodeString(new String (Converter.mbcsToWcs (codePage, buffer))); + items += 4; + } + return result; +} + +String getNameText () { + return getText (); +} + +/** + * 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 String [] getItems () {
- checkWidget();
- int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int items = argList [1], itemCount = argList [3];
- int [] buffer1 = new int [1];
- String [] result = new String [itemCount];
- String codePage = getCodePage ();
- for (int i = 0; i < itemCount; i++) {
- OS.memmove (buffer1, items, 4);
- int ptr = buffer1 [0];
- int address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- OS.XmOUTPUT_ALL);
- if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- OS.XtFree (address);
- result[i] = decodeString(new String (Converter.mbcsToWcs (codePage, buffer)));
- items += 4;
- }
- return result;
-}
-
-String getNameText () {
- return getText ();
-}
-
-/**
- * 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(); + int [] start = new int [1], end = new int [1]; + int [] argList = {OS.XmNtextField, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + OS.XmTextGetSelectionPosition (argList[1], start, end); + if (start [0] == end [0]) { + start [0] = end [0] = OS.XmTextGetInsertionPosition (argList[1]); + } + return new Point (start [0], end [0]); +} +/** + * Returns the zero-relative index of the item which is currently + * selected in the receiver's list, or -1 if no item is selected. + * + * @return the index of the selected item + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public Point getSelection () {
- checkWidget();
- int [] start = new int [1], end = new int [1];
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmTextGetSelectionPosition (argList[1], start, end);
- if (start [0] == end [0]) {
- start [0] = end [0] = OS.XmTextGetInsertionPosition (argList[1]);
- }
- return new Point (start [0], end [0]);
-}
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver's list, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getSelectionIndex () { + checkWidget(); + int [] argList = {OS.XmNlist, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + + int index = OS.XmListGetKbdItemPos (argList[1]); + if (OS.XmListPosSelected (argList[1], index)) return index - 1; + int [] count = new int [1], positions = new int [1]; + if (!OS.XmListGetSelectedPos (argList[1], positions, count)) return -1; + if (count [0] == 0) return -1; + int address = positions [0]; + int [] indices = new int [1]; + OS.memmove (indices, address, 4); + OS.XtFree (address); + return indices [0] - 1; +} +/** + * Returns a string containing a copy of the contents of the + * receiver's text field. + * + * @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 int getSelectionIndex () {
- checkWidget();
- int [] argList = {OS.XmNlist, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
-
- int index = OS.XmListGetKbdItemPos (argList[1]);
- if (OS.XmListPosSelected (argList[1], index)) return index - 1;
- int [] count = new int [1], positions = new int [1];
- if (!OS.XmListGetSelectedPos (argList[1], positions, count)) return -1;
- if (count [0] == 0) return -1;
- int address = positions [0];
- int [] indices = new int [1];
- OS.memmove (indices, address, 4);
- OS.XtFree (address);
- return indices [0] - 1;
-}
-/**
- * Returns a string containing a copy of the contents of the
- * receiver's text field.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public String getText () { + checkWidget(); + int [] argList = {OS.XmNtextField, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + + int ptr = OS.XmTextGetString (argList[1]); + if (ptr == 0) return ""; + int length = OS.strlen (ptr); + byte [] buffer = new byte [length]; + OS.memmove (buffer, ptr, length); + OS.XtFree (ptr); + return decodeString(new String (Converter.mbcsToWcs (getCodePage (), buffer))); +} +/** + * Returns the height of the receivers's text field. + * + * @return the text height + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @exception SWTError <ul> + * <li>ERROR_CANNOT_GET_ITEM_HEIGHT - if the operation fails because of an operating system failure</li> + * </ul> */ -public String getText () {
- checkWidget();
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
-
- int ptr = OS.XmTextGetString (argList[1]);
- if (ptr == 0) return "";
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, length);
- OS.XtFree (ptr);
- return decodeString(new String (Converter.mbcsToWcs (getCodePage (), buffer)));
-}
-/**
- * Returns the height of the receivers's text field.
- *
- * @return the text height
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @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(); + if ((style & SWT.DROP_DOWN) != 0) { + /* + * Bug in MOTIF. For some reason, XtQueryGeometry () + * returns the wrong height when the combo is not realized. + * The fix is to force the combo to be realized by forcing + * the shell to be realized. + */ + if (!OS.XtIsRealized (handle)) getShell ().realizeWidget (); + XtWidgetGeometry result = new XtWidgetGeometry (); + result.request_mode = OS.CWHeight; + OS.XtQueryGeometry (handle, null, result); + return result.height; + } else { + /* Calculate text field height. */ + int [] argList = {OS.XmNtextField, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int [] argList2 = {OS.XmNmarginHeight, 0}; + OS.XtGetValues (argList[1], argList2, argList2.length / 2); + int height = getFontHeight (); + XRectangle rect = new XRectangle (); + OS.XmWidgetGetDisplayRect (argList[1], rect); + height += (rect.y * 2) + (2 * argList2[1]); + + /* Add in combo box margins. */ + int [] argList3 = {OS.XmNmarginHeight, 0, OS.XmNshadowThickness, 0, OS.XmNhighlightThickness, 0}; + OS.XtGetValues(handle, argList3, argList3.length / 2); + height += (2 * argList3[1]) + (2 * argList3[3]) + (2 * argList3[5]); + + return height; + } +} +/** + * Returns the maximum number of characters that the receiver's + * text field is capable of holding. If this has not been changed + * by <code>setTextLimit()</code>, it will be the constant + * <code>Combo.LIMIT</code>. + * + * @return the text limit + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getTextHeight () {
- checkWidget();
- if ((style & SWT.DROP_DOWN) != 0) {
- /*
- * Bug in MOTIF. For some reason, XtQueryGeometry ()
- * returns the wrong height when the combo is not realized.
- * The fix is to force the combo to be realized by forcing
- * the shell to be realized.
- */
- if (!OS.XtIsRealized (handle)) getShell ().realizeWidget ();
- XtWidgetGeometry result = new XtWidgetGeometry ();
- result.request_mode = OS.CWHeight;
- OS.XtQueryGeometry (handle, null, result);
- return result.height;
- } else {
- /* Calculate text field height. */
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int [] argList2 = {OS.XmNmarginHeight, 0};
- OS.XtGetValues (argList[1], argList2, argList2.length / 2);
- int height = getFontHeight ();
- XRectangle rect = new XRectangle ();
- OS.XmWidgetGetDisplayRect (argList[1], rect);
- height += (rect.y * 2) + (2 * argList2[1]);
-
- /* Add in combo box margins. */
- int [] argList3 = {OS.XmNmarginHeight, 0, OS.XmNshadowThickness, 0, OS.XmNhighlightThickness, 0};
- OS.XtGetValues(handle, argList3, argList3.length / 2);
- height += (2 * argList3[1]) + (2 * argList3[3]) + (2 * argList3[5]);
-
- return height;
- }
-}
-/**
- * Returns the maximum number of characters that the receiver's
- * text field is capable of holding. If this has not been changed
- * by <code>setTextLimit()</code>, it will be the constant
- * <code>Combo.LIMIT</code>.
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getTextLimit () { + checkWidget(); + int [] argList = {OS.XmNtextField, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return OS.XmTextGetMaxLength (argList[1]); +} +void hookEvents () { + super.hookEvents (); + int windowProc = getDisplay ().windowProc; + OS.XtAddCallback (handle, OS.XmNselectionCallback, windowProc, SELECTION_CALLBACK); + int [] argList = {OS.XmNtextField, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + OS.XtAddCallback (argList[1], OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK); + OS.XtAddCallback (argList[1], OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK); + OS.XtAddEventHandler (argList[1], OS.KeyPressMask, false, windowProc, KEY_PRESS); + OS.XtAddEventHandler (argList[1], OS.KeyReleaseMask, false, windowProc, KEY_RELEASE); + OS.XtInsertEventHandler (argList[1], OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail); +} +/** + * Searches the receiver's list starting at the first item + * (index 0) until an item is found that is equal to the + * argument, and returns the index of that item. If no item + * is found, returns -1. + * + * @param string the search item + * @return the index of the item + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the string is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getTextLimit () {
- checkWidget();
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return OS.XmTextGetMaxLength (argList[1]);
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = getDisplay ().windowProc;
- OS.XtAddCallback (handle, OS.XmNselectionCallback, windowProc, SELECTION_CALLBACK);
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XtAddCallback (argList[1], OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK);
- OS.XtAddCallback (argList[1], OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
- OS.XtAddEventHandler (argList[1], OS.KeyPressMask, false, windowProc, KEY_PRESS);
- OS.XtAddEventHandler (argList[1], OS.KeyReleaseMask, false, windowProc, KEY_RELEASE);
- OS.XtInsertEventHandler (argList[1], OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail);
-}
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param string the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int indexOf (String string) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + + byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true); + int xmString = OS.XmStringCreateLocalized (buffer); + if (xmString == 0) return -1; + + int [] argList = {OS.XmNlist, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + + int index = OS.XmListItemPos (argList[1], xmString); + OS.XmStringFree (xmString); + return index - 1; +} +/** + * Searches the receiver's list starting at the given, + * zero-relative index until an item is found that is equal + * to the argument, and returns the index of that item. If + * no item is found or the starting index is out of range, + * returns -1. + * + * @param string the search item + * @return the index of the item + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the string is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int indexOf (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
-
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) return -1;
-
- int [] argList = {OS.XmNlist, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
-
- int index = OS.XmListItemPos (argList[1], xmString);
- OS.XmStringFree (xmString);
- return index - 1;
-}
-/**
- * Searches the receiver's list starting at the given,
- * zero-relative index until an item is found that is equal
- * to the argument, and returns the index of that item. If
- * no item is found or the starting index is out of range,
- * returns -1.
- *
- * @param string the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int indexOf (String string, int start) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int items = argList [1], itemCount = argList [3]; + if (!((0 <= start) && (start < itemCount))) return -1; + byte [] buffer1 = Converter.wcsToMbcs (getCodePage (), encodeString(string), true); + int xmString = OS.XmStringCreateLocalized (buffer1); + if (xmString == 0) return -1; + int index = start; + items += start * 4; + int [] buffer2 = new int [1]; + while (index < itemCount) { + OS.memmove (buffer2, items, 4); + if (OS.XmStringCompare (buffer2 [0], xmString)) break; + items += 4; index++; + } + OS.XmStringFree (xmString); + if (index == itemCount) return -1; + return index; +} +/** + * Pastes text from clipboard. + * <p> + * The selected text is deleted from the widget + * and new text inserted from the clipboard. + * </p> + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 2.1 */ -public int indexOf (String string, int start) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int items = argList [1], itemCount = argList [3];
- if (!((0 <= start) && (start < itemCount))) return -1;
- byte [] buffer1 = Converter.wcsToMbcs (getCodePage (), encodeString(string), true);
- int xmString = OS.XmStringCreateLocalized (buffer1);
- if (xmString == 0) return -1;
- int index = start;
- items += start * 4;
- int [] buffer2 = new int [1];
- while (index < itemCount) {
- OS.memmove (buffer2, items, 4);
- if (OS.XmStringCompare (buffer2 [0], xmString)) break;
- items += 4; index++;
- }
- OS.XmStringFree (xmString);
- if (index == itemCount) return -1;
- return index;
-}
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.1
- */
-public void paste () {
- checkWidget();
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmTextFieldPaste (argList [1]);
- display.setWarnings (warnings);
-}
-/**
- * Removes the item from the receiver's list at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
+public void paste () { + checkWidget(); + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + int [] argList = {OS.XmNtextField, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + OS.XmTextFieldPaste (argList [1]); + display.setWarnings (warnings); +} +/** + * Removes the item from the receiver's list at the given + * zero-relative index. + * + * @param index the index for the item + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @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 (index == -1) error (SWT.ERROR_INVALID_RANGE);
- /*
- * Feature in Motif. An index out of range handled
- * correctly by the list widget but causes an unwanted
- * Xm Warning. The fix is to check the range before
- * deleting an item.
- */
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= index && index < argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- OS.XmComboBoxDeletePos (handle, index + 1);
-}
-/**
- * Removes the items from the receiver's list which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @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 (index == -1) error (SWT.ERROR_INVALID_RANGE); + /* + * Feature in Motif. An index out of range handled + * correctly by the list widget but causes an unwanted + * Xm Warning. The fix is to check the range before + * deleting an item. + */ + int [] argList = {OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (!(0 <= index && index < argList [1])) { + error (SWT.ERROR_INVALID_RANGE); + } + OS.XmComboBoxDeletePos (handle, index + 1); +} +/** + * Removes the items from the receiver's list which are + * between the given zero-relative start and end + * indices (inclusive). + * + * @param start the start of the range + * @param end the end of the range + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @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 (start > end) return;
- /*
- * Feature in Motif. An index out of range handled
- * correctly by the list widget but causes an unwanted
- * Xm Warning. The fix is to check the range before
- * deleting an item.
- */
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= start && start < argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- int newEnd = Math.min (end, argList [1] - 1);
- for (int i = start; i <= newEnd; i++) {
- OS.XmComboBoxDeletePos (handle, start + 1);
- }
- if (end >= argList [1]) error (SWT.ERROR_INVALID_RANGE);
-}
-void register () {
- super.register ();
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- WidgetTable.put(argList[1], this);
-}
-/**
- * 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 (int start, int end) { + checkWidget(); + if (start > end) return; + /* + * Feature in Motif. An index out of range handled + * correctly by the list widget but causes an unwanted + * Xm Warning. The fix is to check the range before + * deleting an item. + */ + int [] argList = {OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (!(0 <= start && start < argList [1])) { + error (SWT.ERROR_INVALID_RANGE); + } + int newEnd = Math.min (end, argList [1] - 1); + for (int i = start; i <= newEnd; i++) { + OS.XmComboBoxDeletePos (handle, start + 1); + } + if (end >= argList [1]) error (SWT.ERROR_INVALID_RANGE); +} +void register () { + super.register (); + int [] argList = {OS.XmNtextField, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + WidgetTable.put(argList[1], this); +} +/** + * 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();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
-
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
-
- int [] argList = {OS.XmNlist, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int index = OS.XmListItemPos (argList[1], xmString);
-
- OS.XmStringFree (xmString);
- if (index == 0) error (SWT.ERROR_INVALID_ARGUMENT);
- OS.XmComboBoxDeletePos (handle, 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 remove (String string) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + + byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true); + int xmString = OS.XmStringCreateLocalized (buffer); + if (xmString == 0) error (SWT.ERROR_ITEM_NOT_REMOVED); + + int [] argList = {OS.XmNlist, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int index = OS.XmListItemPos (argList[1], xmString); + + OS.XmStringFree (xmString); + if (index == 0) error (SWT.ERROR_INVALID_ARGUMENT); + OS.XmComboBoxDeletePos (handle, 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();
- int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0, OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
-
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetString (argList[1], new byte[1]);
- display.setWarnings(warnings);
- OS.XmListDeselectAllItems (argList[3]);
-
- for (int i = 0; i < argList[5]; i++) {
- OS.XmComboBoxDeletePos(handle, 1);
- }
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
+public void removeAll () { + checkWidget(); + int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0, OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XmTextSetString (argList[1], new byte[1]); + display.setWarnings(warnings); + OS.XmListDeselectAllItems (argList[3]); + + for (int i = 0; i < argList[5]; i++) { + OS.XmComboBoxDeletePos(handle, 1); + } +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the receiver's text is modified. + * + * @param listener the listener which should no longer be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see ModifyListener + * @see #addModifyListener */ -public void removeModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the 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 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 removeSelectionListener (SelectionListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook (SWT.Selection, listener); + eventTable.unhook (SWT.DefaultSelection,listener); +} +/** + * Selects the item at the given zero-relative index in the receiver's + * list. If the item at the index was already selected, it remains + * selected. Indices that are out of range are ignored. + * + * @param index the index of the item to select + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void select (int index) {
- checkWidget();
- if (index == -1) {
- int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetString (argList[1], new byte[1]);
- display.setWarnings (warnings);
- OS.XmListDeselectAllItems (argList[3]);
- } else {
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= index && index < argList [1])) return;
- int [] argList2 = {OS.XmNselectedPosition, index};
- ignoreSelect = true;
- OS.XtSetValues(handle, argList2, argList2.length / 2);
- ignoreSelect = false;
- }
-}
-byte [] sendIMKeyEvent (int type, XKeyEvent xEvent) {
- /*
- * Bug in Motif. On Solaris and Linux, XmImMbLookupString() clears
- * the characters from the IME. This causes the characters to be
- * stolen from the text widget. The fix is to detect that the IME
- * has been cleared and use XmTextInsert() to insert the stolen
- * characters. This problem does not happen on AIX.
- */
- byte [] mbcs = super.sendIMKeyEvent (type, xEvent);
- if (mbcs == null || xEvent.keycode != 0) return null;
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int textHandle = argList[1];
- int [] unused = new int [1];
- byte [] buffer = new byte [2];
- int length = OS.XmImMbLookupString (textHandle, xEvent, buffer, buffer.length, unused, unused);
- if (length != 0) return null;
- int [] start = new int [1], end = new int [1];
- OS.XmTextGetSelectionPosition (textHandle, start, end);
- if (start [0] == end [0]) {
- start [0] = end [0] = OS.XmTextGetInsertionPosition (textHandle);
- }
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextReplace (textHandle, start [0], end [0], mbcs);
- int position = start [0] + mbcs.length - 1;
- OS.XmTextSetInsertionPosition (textHandle, position);
- display.setWarnings (warnings);
- return mbcs;
-}
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- int [] argList1 = {OS.XmNtextField, 0, OS.XmNlist, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int text = argList1 [1], list = argList1 [3];
- int [] argList2 = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0};
- OS.XtGetValues (text, argList2, argList2.length / 2);
- OS.XmChangeColor (text, pixel);
- OS.XtSetValues (text, argList2, argList2.length / 2);
- int [] argList3 = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0};
- OS.XtGetValues (list, argList3, argList3.length / 2);
- OS.XmChangeColor (list, pixel);
- OS.XtSetValues (list, argList3, argList3.length / 2);
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- checkWidget();
- int newHeight = (resize && (style & SWT.DROP_DOWN) != 0) ? getTextHeight() : height;
- return super.setBounds (x, y, width, newHeight, move, resize);
-}
-public void setFont (Font font) {
- checkWidget();
- super.setFont (font);
-
- /*
- * Bug in Motif. When a font is set in a combo box after the widget
- * is realized, the combo box does not lay out properly. For example,
- * the drop down arrow may be positioned in the middle of the text
- * field or may be invisible, positioned outside the bounds of the
- * widget. The fix is to detect these cases and force the combo box
- * to be layed out properly by temporarily growing and then shrinking
- * the widget.
- *
- * NOTE: This problem also occurs for simple combo boxes.
- */
- if (OS.XtIsRealized (handle)) {
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XtResizeWidget (handle, argList [1], argList [3] + 1, argList [5]);
- OS.XtResizeWidget (handle, argList [1], argList [3], argList [5]);
- }
-}
-void setForegroundPixel (int pixel) {
- int [] argList1 = {OS.XmNtextField, 0, OS.XmNlist, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int [] argList2 = {OS.XmNforeground, pixel};
- OS.XtSetValues (argList1 [1], argList2, argList2.length / 2);
- OS.XtSetValues (argList1 [3], argList2, argList2.length / 2);
- super.setForegroundPixel (pixel);
-}
-/**
- * Sets the text of the item in the receiver's list at the given
- * zero-relative index to the string argument. 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 select (int index) { + checkWidget(); + if (index == -1) { + int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XmTextSetString (argList[1], new byte[1]); + display.setWarnings (warnings); + OS.XmListDeselectAllItems (argList[3]); + } else { + int [] argList = {OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (!(0 <= index && index < argList [1])) return; + int [] argList2 = {OS.XmNselectedPosition, index}; + ignoreSelect = true; + OS.XtSetValues(handle, argList2, argList2.length / 2); + ignoreSelect = false; + } +} +byte [] sendIMKeyEvent (int type, XKeyEvent xEvent) { + /* + * Bug in Motif. On Solaris and Linux, XmImMbLookupString() clears + * the characters from the IME. This causes the characters to be + * stolen from the text widget. The fix is to detect that the IME + * has been cleared and use XmTextInsert() to insert the stolen + * characters. This problem does not happen on AIX. + */ + byte [] mbcs = super.sendIMKeyEvent (type, xEvent); + if (mbcs == null || xEvent.keycode != 0) return null; + int [] argList = {OS.XmNtextField, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int textHandle = argList[1]; + int [] unused = new int [1]; + byte [] buffer = new byte [2]; + int length = OS.XmImMbLookupString (textHandle, xEvent, buffer, buffer.length, unused, unused); + if (length != 0) return null; + int [] start = new int [1], end = new int [1]; + OS.XmTextGetSelectionPosition (textHandle, start, end); + if (start [0] == end [0]) { + start [0] = end [0] = OS.XmTextGetInsertionPosition (textHandle); + } + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XmTextReplace (textHandle, start [0], end [0], mbcs); + int position = start [0] + mbcs.length - 1; + OS.XmTextSetInsertionPosition (textHandle, position); + display.setWarnings (warnings); + return mbcs; +} +void setBackgroundPixel (int pixel) { + super.setBackgroundPixel (pixel); + int [] argList1 = {OS.XmNtextField, 0, OS.XmNlist, 0}; + OS.XtGetValues (handle, argList1, argList1.length / 2); + int text = argList1 [1], list = argList1 [3]; + int [] argList2 = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0}; + OS.XtGetValues (text, argList2, argList2.length / 2); + OS.XmChangeColor (text, pixel); + OS.XtSetValues (text, argList2, argList2.length / 2); + int [] argList3 = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0}; + OS.XtGetValues (list, argList3, argList3.length / 2); + OS.XmChangeColor (list, pixel); + OS.XtSetValues (list, argList3, argList3.length / 2); +} +boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { + checkWidget(); + int newHeight = (resize && (style & SWT.DROP_DOWN) != 0) ? getTextHeight() : height; + return super.setBounds (x, y, width, newHeight, move, resize); +} +public void setFont (Font font) { + checkWidget(); + super.setFont (font); + + /* + * Bug in Motif. When a font is set in a combo box after the widget + * is realized, the combo box does not lay out properly. For example, + * the drop down arrow may be positioned in the middle of the text + * field or may be invisible, positioned outside the bounds of the + * widget. The fix is to detect these cases and force the combo box + * to be layed out properly by temporarily growing and then shrinking + * the widget. + * + * NOTE: This problem also occurs for simple combo boxes. + */ + if (OS.XtIsRealized (handle)) { + int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + OS.XtResizeWidget (handle, argList [1], argList [3] + 1, argList [5]); + OS.XtResizeWidget (handle, argList [1], argList [3], argList [5]); + } +} +void setForegroundPixel (int pixel) { + int [] argList1 = {OS.XmNtextField, 0, OS.XmNlist, 0}; + OS.XtGetValues (handle, argList1, argList1.length / 2); + int [] argList2 = {OS.XmNforeground, pixel}; + OS.XtSetValues (argList1 [1], argList2, argList2.length / 2); + OS.XtSetValues (argList1 [3], argList2, argList2.length / 2); + super.setForegroundPixel (pixel); +} +/** + * Sets the text of the item in the receiver's list at the given + * zero-relative index to the string argument. 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 (index == -1) error (SWT.ERROR_INVALID_RANGE);
- int [] argList = {OS.XmNlist, 0, OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= index && index < argList [3])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- boolean isSelected = OS.XmListPosSelected (argList[1], index + 1);
- OS.XmListReplaceItemsPosUnselected (argList[1], new int [] {xmString}, 1, index + 1);
- if (isSelected) OS.XmListSelectPos (argList[1], index + 1, false);
- OS.XmStringFree (xmString);
-}
-/**
- * Sets the receiver's list to be the given array of items.
- *
- * @param items the array of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 setItem (int index, String string) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + if (index == -1) error (SWT.ERROR_INVALID_RANGE); + int [] argList = {OS.XmNlist, 0, OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (!(0 <= index && index < argList [3])) { + error (SWT.ERROR_INVALID_RANGE); + } + byte [] buffer = Converter.wcsToMbcs (getCodePage (), encodeString(string), true); + int xmString = OS.XmStringCreateLocalized (buffer); + if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED); + boolean isSelected = OS.XmListPosSelected (argList[1], index + 1); + OS.XmListReplaceItemsPosUnselected (argList[1], new int [] {xmString}, 1, index + 1); + if (isSelected) OS.XmListSelectPos (argList[1], index + 1, false); + OS.XmStringFree (xmString); +} +/** + * Sets the receiver's list to be the given array of items. + * + * @param items the array of items + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - 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);
-
- if (items.length == 0) {
- removeAll();
- return;
- }
-
- int index = 0;
- int [] table = new int [items.length];
- String codePage = getCodePage ();
- while (index < items.length) {
- String string = items [index];
- if (string == null) break;
- byte [] buffer = Converter.wcsToMbcs (codePage, encodeString(string), true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) break;
- table [index++] = xmString;
- }
- int ptr = OS.XtMalloc (index * 4);
- OS.memmove (ptr, table, index * 4);
- int [] argList1 = {OS.XmNitems, ptr, OS.XmNitemCount, index};
- OS.XtSetValues (handle, argList1, argList1.length / 2);
- for (int i=0; i<index; i++) OS.XmStringFree (table [i]);
- OS.XtFree (ptr);
- if (index < items.length) error (SWT.ERROR_ITEM_NOT_ADDED);
-
- int [] argList2 = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList2, argList2.length / 2);
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetString (argList2[1], new byte[1]);
- display.setWarnings(warnings);
- int [] argList3 = {OS.XmNlist, 0};
- OS.XtGetValues (handle, argList3, argList3.length / 2);
- int [] argList4 = {OS.XmNselectedItemCount, 0, OS.XmNselectedItems, 0};
- OS.XtSetValues (argList3 [1], argList4, argList4.length / 2);
-}
-/**
- * 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 setItems (String [] items) { + checkWidget(); + if (items == null) error (SWT.ERROR_NULL_ARGUMENT); + + if (items.length == 0) { + removeAll(); + return; + } + + int index = 0; + int [] table = new int [items.length]; + String codePage = getCodePage (); + while (index < items.length) { + String string = items [index]; + if (string == null) break; + byte [] buffer = Converter.wcsToMbcs (codePage, encodeString(string), true); + int xmString = OS.XmStringCreateLocalized (buffer); + if (xmString == 0) break; + table [index++] = xmString; + } + int ptr = OS.XtMalloc (index * 4); + OS.memmove (ptr, table, index * 4); + int [] argList1 = {OS.XmNitems, ptr, OS.XmNitemCount, index}; + OS.XtSetValues (handle, argList1, argList1.length / 2); + for (int i=0; i<index; i++) OS.XmStringFree (table [i]); + OS.XtFree (ptr); + if (index < items.length) error (SWT.ERROR_ITEM_NOT_ADDED); + + int [] argList2 = {OS.XmNtextField, 0}; + OS.XtGetValues (handle, argList2, argList2.length / 2); + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XmTextSetString (argList2[1], new byte[1]); + display.setWarnings(warnings); + int [] argList3 = {OS.XmNlist, 0}; + OS.XtGetValues (handle, argList3, argList3.length / 2); + int [] argList4 = {OS.XmNselectedItemCount, 0, OS.XmNselectedItems, 0}; + OS.XtSetValues (argList3 [1], argList4, argList4.length / 2); +} +/** + * 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();
-
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
-
- /* Clear the highlight before setting the selection. */
- int position = OS.XmTextGetLastPosition (argList[1]);
-
- /*
- * Bug in MOTIF. XmTextSetSelection () fails to set the
- * selection when the receiver is not realized. The fix
- * is to force the receiver to be realized by forcing the
- * shell to be realized. If the receiver is realized before
- * the shell, MOTIF fails to draw the text widget and issues
- * lots of X BadDrawable errors.
- */
- if (!OS.XtIsRealized (handle)) getShell ().realizeWidget ();
-
- /* Set the selection. */
- int xDisplay = OS.XtDisplay (argList[1]);
- if (xDisplay == 0) return;
- int nStart = Math.min (Math.max (Math.min (selection.x, selection.y), 0), position);
- int nEnd = Math.min (Math.max (Math.max (selection.x, selection.y), 0), position);
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetSelection (argList[1], nStart, nEnd, OS.XtLastTimestampProcessed (xDisplay));
-
- /* Force the i-beam to follow the highlight/selection. */
- OS.XmTextSetInsertionPosition (argList[1], nEnd);
- display.setWarnings(warnings);
-}
-/**
- * Sets the contents of the receiver's text field to the
- * given string.
- * <p>
- * 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 setSelection (Point selection) { + checkWidget(); + + int [] argList = {OS.XmNtextField, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + + /* Clear the highlight before setting the selection. */ + int position = OS.XmTextGetLastPosition (argList[1]); + + /* + * Bug in MOTIF. XmTextSetSelection () fails to set the + * selection when the receiver is not realized. The fix + * is to force the receiver to be realized by forcing the + * shell to be realized. If the receiver is realized before + * the shell, MOTIF fails to draw the text widget and issues + * lots of X BadDrawable errors. + */ + if (!OS.XtIsRealized (handle)) getShell ().realizeWidget (); + + /* Set the selection. */ + int xDisplay = OS.XtDisplay (argList[1]); + if (xDisplay == 0) return; + int nStart = Math.min (Math.max (Math.min (selection.x, selection.y), 0), position); + int nEnd = Math.min (Math.max (Math.max (selection.x, selection.y), 0), position); + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XmTextSetSelection (argList[1], nStart, nEnd, OS.XtLastTimestampProcessed (xDisplay)); + + /* Force the i-beam to follow the highlight/selection. */ + OS.XmTextSetInsertionPosition (argList[1], nEnd); + display.setWarnings(warnings); +} +/** + * Sets the contents of the receiver's text field to the + * given string. + * <p> + * 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);
-
- /*
- * The read-only and non-read-only cases must be handled
- * separately here because the platform will allow the
- * text of a read-only combo to be set to any value,
- * regardless of whether it appears in the combo's item
- * list or not.
- */
- if ((style & SWT.READ_ONLY) != 0) {
- int index = indexOf (string);
- if (index != -1) select (index);
- } else {
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) return;
- int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int index = OS.XmListItemPos (argList[3], xmString);
- if (index > 0) {
- /* The list contains the item. */
- OS.XmComboBoxSelectItem(handle, xmString);
- } else {
- /* The list does not contain the item. */
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetString (argList[1], buffer);
- OS.XmTextSetInsertionPosition (argList[1], 0);
- display.setWarnings(warnings);
- }
- OS.XmStringFree (xmString);
- }
-}
-/**
- * Sets the maximum number of characters that the receiver's
- * text field is capable of holding to be the argument.
- *
- * @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 setText (String string) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + + /* + * The read-only and non-read-only cases must be handled + * separately here because the platform will allow the + * text of a read-only combo to be set to any value, + * regardless of whether it appears in the combo's item + * list or not. + */ + if ((style & SWT.READ_ONLY) != 0) { + int index = indexOf (string); + if (index != -1) select (index); + } else { + byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); + int xmString = OS.XmStringCreateLocalized (buffer); + if (xmString == 0) return; + int [] argList = {OS.XmNtextField, 0, OS.XmNlist, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int index = OS.XmListItemPos (argList[3], xmString); + if (index > 0) { + /* The list contains the item. */ + OS.XmComboBoxSelectItem(handle, xmString); + } else { + /* The list does not contain the item. */ + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XmTextSetString (argList[1], buffer); + OS.XmTextSetInsertionPosition (argList[1], 0); + display.setWarnings(warnings); + } + OS.XmStringFree (xmString); + } +} +/** + * Sets the maximum number of characters that the receiver's + * text field is capable of holding to be the argument. + * + * @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);
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmTextSetMaxLength (argList[1], limit);
-}
-
-void deregister () {
- super.deregister ();
- int [] argList = {OS.XmNtextField, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- WidgetTable.remove (argList[1]);
-}
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- int [] argList = {
- OS.XmNlist, 0,
- OS.XmNtextField, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- enableHandle (enabled, argList [1]);
- enableHandle (enabled, argList [3]);
-}
-/**
- * Bug in Motif.
- * Empty strings in the combo will cause GPFs if a) they
- * are the only items in the combo or b) if they are
- * included in an array which is set as the value of the
- * combo's items resource. To protect against these GPFs,
- * make sure that no empty strings are added to the combo.
- * The solution is to add a space to empty strings or
- * strings which are all spaces. This space is removed
- * when answering the text of items which are all spaces.
+public void setTextLimit (int limit) { + checkWidget(); + if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO); + int [] argList = {OS.XmNtextField, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + OS.XmTextSetMaxLength (argList[1], limit); +} + +void deregister () { + super.deregister (); + int [] argList = {OS.XmNtextField, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + WidgetTable.remove (argList[1]); +} +void enableWidget (boolean enabled) { + super.enableWidget (enabled); + int [] argList = { + OS.XmNlist, 0, + OS.XmNtextField, 0, + }; + OS.XtGetValues (handle, argList, argList.length / 2); + enableHandle (enabled, argList [1]); + enableHandle (enabled, argList [3]); +} +/** + * Bug in Motif. + * Empty strings in the combo will cause GPFs if a) they + * are the only items in the combo or b) if they are + * included in an array which is set as the value of the + * combo's items resource. To protect against these GPFs, + * make sure that no empty strings are added to the combo. + * The solution is to add a space to empty strings or + * strings which are all spaces. This space is removed + * when answering the text of items which are all spaces. */ -String encodeString(String string) {
- for (int i = 0; i < string.length(); i++) {
- if (string.charAt(i) != ' ') {
- return string;
- }
- }
- return string + ' ';
-}
-/**
- * Bug in Motif.
- * Empty strings in the combo will cause GPFs if a) they
- * are the only items in the combo or b) if they are
- * included in an array which is set as the value of the
- * combo's items resource. To protect against these GPFs,
- * make sure that no empty strings are added to the combo.
- * The solution is to add a space to empty strings or
- * strings which include only spaces. A space is removed
- * when answering the text of items which are all spaces.
+String encodeString(String string) { + for (int i = 0; i < string.length(); i++) { + if (string.charAt(i) != ' ') { + return string; + } + } + return string + ' '; +} +/** + * Bug in Motif. + * Empty strings in the combo will cause GPFs if a) they + * are the only items in the combo or b) if they are + * included in an array which is set as the value of the + * combo's items resource. To protect against these GPFs, + * make sure that no empty strings are added to the combo. + * The solution is to add a space to empty strings or + * strings which include only spaces. A space is removed + * when answering the text of items which are all spaces. */ -String decodeString(String string) {
- if (string.length() == 0) return string;
-
- for (int i = 0; i < string.length(); i++) {
- if (string.charAt(i) != ' ') {
- return string;
- }
- }
- return string.substring(0, string.length() - 1);
-}
-int XmNactivateCallback (int w, int client_data, int call_data) {
- postEvent (SWT.DefaultSelection);
- return 0;
-}
-int XmNselectionCallback (int w, int client_data, int call_data) {
- /*
- * Bug in MOTIF. If items have been added and removed from a
- * combo then users are able to select an empty drop-down item
- * in the combo once and force a resulting callback. In such
- * cases we want to eat this callback so that listeners are not
- * notified.
- */
- if (ignoreSelect || getSelectionIndex() == -1) return 0;
- postEvent (SWT.Selection);
- return 0;
-}
-int XmNvalueChangedCallback (int w, int client_data, int call_data) {
- sendEvent (SWT.Modify);
- return 0;
-}
-}
+String decodeString(String string) { + if (string.length() == 0) return string; + + for (int i = 0; i < string.length(); i++) { + if (string.charAt(i) != ' ') { + return string; + } + } + return string.substring(0, string.length() - 1); +} +int XmNactivateCallback (int w, int client_data, int call_data) { + postEvent (SWT.DefaultSelection); + return 0; +} +int XmNselectionCallback (int w, int client_data, int call_data) { + /* + * Bug in MOTIF. If items have been added and removed from a + * combo then users are able to select an empty drop-down item + * in the combo once and force a resulting callback. In such + * cases we want to eat this callback so that listeners are not + * notified. + */ + if (ignoreSelect || getSelectionIndex() == -1) return 0; + postEvent (SWT.Selection); + return 0; +} +int XmNvalueChangedCallback (int w, int client_data, int call_data) { + sendEvent (SWT.Modify); + return 0; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java index 05c80050d1..9c03f3471b 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Composite.java @@ -1,16 +1,16 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; + /** * Instances of this class are controls which are capable * of containing other controls. @@ -34,14 +34,14 @@ import org.eclipse.swt.graphics.*; * * @see Canvas */ -public class Composite extends Scrollable {
- Layout layout;
- int damagedRegion;
- Control [] tabList;
-
-Composite () {
- /* Do nothing */
-}
+public class Composite extends Scrollable { + Layout layout; + int damagedRegion; + Control [] tabList; + +Composite () { + /* Do nothing */ +} /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -72,232 +72,232 @@ Composite () { * @see SWT#NO_RADIO_GROUP * @see Widget#getStyle */ -public Composite (Composite parent, int style) {
- super (parent, style);
-}
-Control [] _getChildren () {
- int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int ptr = argList [1], count = argList [3];
- if (count == 0 || ptr == 0) return new Control [0];
- int [] handles = new int [count];
- OS.memmove (handles, ptr, count * 4);
- Control [] children = new Control [count];
- int i = 0, j = 0;
- while (i < count) {
- int handle = handles [i];
- if (handle != 0) {
- Widget widget = WidgetTable.get (handle);
- if (widget != null && widget != this) {
- if (widget instanceof Control) {
- children [j++] = (Control) widget;
- }
- }
- }
- i++;
- }
- if (i == j) return children;
- Control [] newChildren = new Control [j];
- System.arraycopy (children, 0, newChildren, 0, j);
- return newChildren;
-}
-Control [] _getTabList () {
- if (tabList == null) return tabList;
- int count = 0;
- for (int i=0; i<tabList.length; i++) {
- if (!tabList [i].isDisposed ()) count++;
- }
- if (count == tabList.length) return tabList;
- Control [] newList = new Control [count];
- int index = 0;
- for (int i=0; i<tabList.length; i++) {
- if (!tabList [i].isDisposed ()) {
- newList [index++] = tabList [i];
- }
- }
- tabList = newList;
- return tabList;
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- Point size;
- if (layout != null) {
- if ((wHint == SWT.DEFAULT) || (hHint == SWT.DEFAULT)) {
- 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);
-}
-Control [] computeTabList () {
- Control result [] = super.computeTabList ();
- if (result.length == 0) return result;
- Control [] list = tabList != null ? _getTabList () : _getChildren ();
- for (int i=0; i<list.length; i++) {
- Control child = list [i];
- Control [] childList = child.computeTabList ();
- if (childList.length != 0) {
- Control [] newResult = new Control [result.length + childList.length];
- System.arraycopy (result, 0, newResult, 0, result.length);
- System.arraycopy (childList, 0, newResult, result.length, childList.length);
- result = newResult;
- }
- }
- return result;
-}
-protected void checkSubclass () {
- /* Do nothing - Subclassing is allowed */
-}
-void createHandle (int index) {
- state |= HANDLE | CANVAS;
- int parentHandle = parent.handle;
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
- int border = (style & SWT.BORDER) != 0 ? 1 : 0;
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNborderWidth, border,
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNtraversalOn, (style & SWT.NO_FOCUS) != 0 ? 0 : 1,
- };
- handle = OS.XmCreateDrawingArea (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- } else {
- createScrolledHandle (parentHandle);
- }
-}
-void createScrolledHandle (int topHandle) {
- int [] argList = {OS.XmNancestorSensitive, 1};
- scrolledHandle = OS.XmCreateMainWindow (topHandle, null, argList, argList.length / 2);
- if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) {
- Display display = getDisplay ();
- int thickness = display.buttonShadowThickness;
- int [] argList1 = {
- OS.XmNmarginWidth, 3,
- OS.XmNmarginHeight, 3,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNshadowType, OS.XmSHADOW_IN,
- OS.XmNshadowThickness, thickness,
- };
- formHandle = OS.XmCreateForm (scrolledHandle, null, argList1, argList1.length / 2);
- if (formHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int [] argList2 = {
- OS.XmNtopAttachment, OS.XmATTACH_FORM,
- OS.XmNbottomAttachment, OS.XmATTACH_FORM,
- OS.XmNleftAttachment, OS.XmATTACH_FORM,
- OS.XmNrightAttachment, OS.XmATTACH_FORM,
- OS.XmNresizable, 0,
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- };
- handle = OS.XmCreateDrawingArea (formHandle, null, argList2, argList2.length / 2);
- } else {
- int [] argList3 = {
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNtraversalOn, (style & SWT.NO_FOCUS) != 0 ? 0 : 1,
- };
- handle = OS.XmCreateDrawingArea (scrolledHandle, null, argList3, argList3.length / 2);
- }
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-int defaultBackground () {
- return getDisplay ().compositeBackground;
-}
-int defaultForeground () {
- return getDisplay ().compositeForeground;
-}
-public boolean forceFocus () {
- checkWidget();
- /*
- * Bug in Motif. When XtDestroyWidget() is called from
- * within a FocusOut event handler, Motif GP's. The fix
- * is to post focus events and run them when the handler
- * has returned.
- */
- Display display = getDisplay ();
- boolean oldFocusOut = display.postFocusOut;
- Control [] children = _getChildren ();
- int [] traversals = new int [children.length];
- int [] argList = new int [] {OS.XmNtraversalOn, 0};
- for (int i=0; i<children.length; i++) {
- int childHandle = children [i].topHandle ();
- OS.XtGetValues (childHandle, argList, argList.length / 2);
- if ((traversals [i] = argList [1]) != 0) {
- argList [1] = 0;
- display.postFocusOut = true;
- OS.XtSetValues (childHandle, argList, argList.length / 2);
- }
- }
- boolean result = super.forceFocus ();
- for (int i=0; i<children.length; i++) {
- argList [1] = traversals [i];
- Control control = children [i];
- if (!control.isDisposed ()) {
- int childHandle = control.topHandle ();
- OS.XtSetValues (childHandle, argList, argList.length / 2);
- if (argList [1] != 0) control.overrideTranslations ();
- }
- }
- display.postFocusOut = oldFocusOut;
- if (!display.postFocusOut) display.runFocusOutEvents ();
- return result;
-}
-/**
- * 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 Composite (Composite parent, int style) { + super (parent, style); +} +Control [] _getChildren () { + int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int ptr = argList [1], count = argList [3]; + if (count == 0 || ptr == 0) return new Control [0]; + int [] handles = new int [count]; + OS.memmove (handles, ptr, count * 4); + Control [] children = new Control [count]; + int i = 0, j = 0; + while (i < count) { + int handle = handles [i]; + if (handle != 0) { + Widget widget = WidgetTable.get (handle); + if (widget != null && widget != this) { + if (widget instanceof Control) { + children [j++] = (Control) widget; + } + } + } + i++; + } + if (i == j) return children; + Control [] newChildren = new Control [j]; + System.arraycopy (children, 0, newChildren, 0, j); + return newChildren; +} +Control [] _getTabList () { + if (tabList == null) return tabList; + int count = 0; + for (int i=0; i<tabList.length; i++) { + if (!tabList [i].isDisposed ()) count++; + } + if (count == tabList.length) return tabList; + Control [] newList = new Control [count]; + int index = 0; + for (int i=0; i<tabList.length; i++) { + if (!tabList [i].isDisposed ()) { + newList [index++] = tabList [i]; + } + } + tabList = newList; + return tabList; +} +public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget(); + Point size; + if (layout != null) { + if ((wHint == SWT.DEFAULT) || (hHint == SWT.DEFAULT)) { + 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); +} +Control [] computeTabList () { + Control result [] = super.computeTabList (); + if (result.length == 0) return result; + Control [] list = tabList != null ? _getTabList () : _getChildren (); + for (int i=0; i<list.length; i++) { + Control child = list [i]; + Control [] childList = child.computeTabList (); + if (childList.length != 0) { + Control [] newResult = new Control [result.length + childList.length]; + System.arraycopy (result, 0, newResult, 0, result.length); + System.arraycopy (childList, 0, newResult, result.length, childList.length); + result = newResult; + } + } + return result; +} +protected void checkSubclass () { + /* Do nothing - Subclassing is allowed */ +} +void createHandle (int index) { + state |= HANDLE | CANVAS; + int parentHandle = parent.handle; + if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) { + int border = (style & SWT.BORDER) != 0 ? 1 : 0; + int [] argList = { + OS.XmNancestorSensitive, 1, + OS.XmNborderWidth, border, + OS.XmNmarginWidth, 0, + OS.XmNmarginHeight, 0, + OS.XmNresizePolicy, OS.XmRESIZE_NONE, + OS.XmNtraversalOn, (style & SWT.NO_FOCUS) != 0 ? 0 : 1, + }; + handle = OS.XmCreateDrawingArea (parentHandle, null, argList, argList.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + } else { + createScrolledHandle (parentHandle); + } +} +void createScrolledHandle (int topHandle) { + int [] argList = {OS.XmNancestorSensitive, 1}; + scrolledHandle = OS.XmCreateMainWindow (topHandle, null, argList, argList.length / 2); + if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES); + if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) { + Display display = getDisplay (); + int thickness = display.buttonShadowThickness; + int [] argList1 = { + OS.XmNmarginWidth, 3, + OS.XmNmarginHeight, 3, + OS.XmNresizePolicy, OS.XmRESIZE_NONE, + OS.XmNshadowType, OS.XmSHADOW_IN, + OS.XmNshadowThickness, thickness, + }; + formHandle = OS.XmCreateForm (scrolledHandle, null, argList1, argList1.length / 2); + if (formHandle == 0) error (SWT.ERROR_NO_HANDLES); + int [] argList2 = { + OS.XmNtopAttachment, OS.XmATTACH_FORM, + OS.XmNbottomAttachment, OS.XmATTACH_FORM, + OS.XmNleftAttachment, OS.XmATTACH_FORM, + OS.XmNrightAttachment, OS.XmATTACH_FORM, + OS.XmNresizable, 0, + OS.XmNmarginWidth, 0, + OS.XmNmarginHeight, 0, + OS.XmNresizePolicy, OS.XmRESIZE_NONE, + }; + handle = OS.XmCreateDrawingArea (formHandle, null, argList2, argList2.length / 2); + } else { + int [] argList3 = { + OS.XmNmarginWidth, 0, + OS.XmNmarginHeight, 0, + OS.XmNresizePolicy, OS.XmRESIZE_NONE, + OS.XmNtraversalOn, (style & SWT.NO_FOCUS) != 0 ? 0 : 1, + }; + handle = OS.XmCreateDrawingArea (scrolledHandle, null, argList3, argList3.length / 2); + } + if (handle == 0) error (SWT.ERROR_NO_HANDLES); +} +int defaultBackground () { + return getDisplay ().compositeBackground; +} +int defaultForeground () { + return getDisplay ().compositeForeground; +} +public boolean forceFocus () { + checkWidget(); + /* + * Bug in Motif. When XtDestroyWidget() is called from + * within a FocusOut event handler, Motif GP's. The fix + * is to post focus events and run them when the handler + * has returned. + */ + Display display = getDisplay (); + boolean oldFocusOut = display.postFocusOut; + Control [] children = _getChildren (); + int [] traversals = new int [children.length]; + int [] argList = new int [] {OS.XmNtraversalOn, 0}; + for (int i=0; i<children.length; i++) { + int childHandle = children [i].topHandle (); + OS.XtGetValues (childHandle, argList, argList.length / 2); + if ((traversals [i] = argList [1]) != 0) { + argList [1] = 0; + display.postFocusOut = true; + OS.XtSetValues (childHandle, argList, argList.length / 2); + } + } + boolean result = super.forceFocus (); + for (int i=0; i<children.length; i++) { + argList [1] = traversals [i]; + Control control = children [i]; + if (!control.isDisposed ()) { + int childHandle = control.topHandle (); + OS.XtSetValues (childHandle, argList, argList.length / 2); + if (argList [1] != 0) control.overrideTranslations (); + } + } + display.postFocusOut = oldFocusOut; + if (!display.postFocusOut) display.runFocusOutEvents (); + return result; +} +/** + * 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 ();
-}
-int getChildrenCount () {
- /*
- * NOTE: The current implementation will count
- * non-registered children.
- * */
- int [] argList = {OS.XmNnumChildren, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns layout which is associated with the receiver, or
- * null if one has not been set.
- *
- * @return the receiver's layout or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public Control [] getChildren () { + checkWidget(); + return _getChildren (); +} +int getChildrenCount () { + /* + * NOTE: The current implementation will count + * non-registered children. + * */ + int [] argList = {OS.XmNnumChildren, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns layout which is associated with the receiver, or + * null if one has not been set. + * + * @return the receiver's layout or null + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public Layout getLayout () {
- checkWidget();
- return layout;
-}
+public Layout getLayout () { + checkWidget(); + return layout; +} /** * Gets the last specified tabbing order for the control. * @@ -310,235 +310,235 @@ public Layout getLayout () { * * @see #setTabList */ -public Control [] getTabList () {
- checkWidget ();
- Control [] tabList = _getTabList ();
- if (tabList == null) {
- int count = 0;
- Control [] list =_getChildren ();
- for (int i=0; i<list.length; i++) {
- if (list [i].isTabGroup ()) count++;
- }
- tabList = new Control [count];
- int index = 0;
- for (int i=0; i<list.length; i++) {
- if (list [i].isTabGroup ()) {
- tabList [index++] = list [i];
- }
- }
- }
- return tabList;
-}
-void hookEvents () {
- super.hookEvents ();
- if ((state & CANVAS) != 0) {
- int windowProc = getDisplay ().windowProc;
- OS.XtInsertEventHandler (handle, 0, true, windowProc, NON_MASKABLE, OS.XtListTail);
- }
-}
-
-boolean hooksKeys () {
- return hooks (SWT.KeyDown) || hooks (SWT.KeyUp);
-}
-
-/**
- * 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 Control [] getTabList () { + checkWidget (); + Control [] tabList = _getTabList (); + if (tabList == null) { + int count = 0; + Control [] list =_getChildren (); + for (int i=0; i<list.length; i++) { + if (list [i].isTabGroup ()) count++; + } + tabList = new Control [count]; + int index = 0; + for (int i=0; i<list.length; i++) { + if (list [i].isTabGroup ()) { + tabList [index++] = list [i]; + } + } + } + return tabList; +} +void hookEvents () { + super.hookEvents (); + if ((state & CANVAS) != 0) { + int windowProc = getDisplay ().windowProc; + OS.XtInsertEventHandler (handle, 0, true, windowProc, NON_MASKABLE, OS.XtListTail); + } +} + +boolean hooksKeys () { + return hooks (SWT.KeyDown) || hooks (SWT.KeyUp); +} + +/** + * 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 () {
- checkWidget();
- layout (true);
-}
-/**
- * If the receiver has a layout, asks the layout to <em>lay out</em>
- * (that is, set the size and location of) the receiver's children.
- * If the 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 () { + checkWidget(); + layout (true); +} +/** + * If the receiver has a layout, asks the layout to <em>lay out</em> + * (that is, set the size and location of) the receiver's children. + * If the 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) {
- checkWidget();
- if (layout == null) return;
- int count = getChildrenCount ();
- if (count == 0) 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);
-}
-void moveAbove (int handle1, int handle2) {
- if (handle1 == handle2) return;
- int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int ptr = argList [1], count = argList [3];
- if (count == 0 || ptr == 0) return;
- int [] handles = new int [count];
- OS.memmove (handles, ptr, count * 4);
- if (handle2 == 0) handle2 = handles [0];
- int i = 0, index1 = -1, index2 = -1;
- while (i < count) {
- int handle = handles [i];
- if (handle == handle1) index1 = i;
- if (handle == handle2) index2 = i;
- if (index1 != -1 && index2 != -1) break;
- i++;
- }
- if (index1 == -1 || index2 == -1) return;
- if (index1 == index2) return;
- if (index1 < index2) {
- System.arraycopy (handles, index1 + 1, handles, index1, index2 - index1 - 1);
- handles [index2 - 1] = handle1;
- } else {
- System.arraycopy (handles, index2, handles, index2 + 1, index1 - index2);
- handles [index2] = handle1;
- }
- OS.memmove (ptr, handles, count * 4);
-}
-void moveBelow (int handle1, int handle2) {
- if (handle1 == handle2) return;
- int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int ptr = argList [1], count = argList [3];
- if (count == 0 || ptr == 0) return;
- int [] handles = new int [count];
- OS.memmove (handles, ptr, count * 4);
- if (handle2 == 0) handle2 = handles [count - 1];
- int i = 0, index1 = -1, index2 = -1;
- while (i < count) {
- int handle = handles [i];
- if (handle == handle1) index1 = i;
- if (handle == handle2) index2 = i;
- if (index1 != -1 && index2 != -1) break;
- i++;
- }
- if (index1 == -1 || index2 == -1) return;
- if (index1 == index2) return;
- if (index1 < index2) {
- System.arraycopy (handles, index1 + 1, handles, index1, index2 - index1);
- handles [index2] = handle1;
- } else {
- System.arraycopy (handles, index2 + 1, handles, index2 + 2, index1 - index2 - 1);
- handles [index2 + 1] = handle1;
- }
- OS.memmove (ptr, handles, count * 4);
-}
-void propagateChildren (boolean enabled) {
- super.propagateChildren (enabled);
- Control [] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- Control child = children [i];
- if (child.getEnabled ()) {
- child.propagateChildren (enabled);
- }
- }
-}
-void realizeChildren () {
- super.realizeChildren ();
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- children [i].realizeChildren ();
- }
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_BACKGROUND) == 0 && (style & SWT.NO_REDRAW_RESIZE) != 0) return;
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- int flags = 0;
- XSetWindowAttributes attributes = new XSetWindowAttributes ();
- if ((style & SWT.NO_BACKGROUND) != 0) {
- flags |= OS.CWBackPixmap;
- attributes.background_pixmap = OS.None;
- }
- if ((style & SWT.NO_REDRAW_RESIZE) == 0) {
- flags |= OS.CWBitGravity;
- attributes.bit_gravity = OS.ForgetGravity;
- }
- if (flags != 0) {
- OS.XChangeWindowAttributes (xDisplay, xWindow, flags, attributes);
- }
- }
-}
-void redrawWidget (int x, int y, int width, int height, boolean all) {
- super.redrawWidget (x, y, width, height, all);
- if (!all) return;
- Control [] children = _getChildren ();
- for (int i = 0; i < children.length; i++) {
- Control child = children [i];
- Point location = child.getClientLocation ();
- child.redrawWidget (x - location.x, y - location.y, width, height, all);
- }
-}
-void releaseChildren () {
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (!child.isDisposed ()) child.releaseResources ();
- }
-}
-void releaseWidget () {
- releaseChildren ();
- super.releaseWidget ();
- layout = null;
- tabList = null;
- if (damagedRegion != 0) OS.XDestroyRegion (damagedRegion);
- damagedRegion = 0;
-}
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_BACKGROUND) != 0) {
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- XSetWindowAttributes attributes = new XSetWindowAttributes ();
- attributes.background_pixmap = OS.None;
- OS.XChangeWindowAttributes (xDisplay, xWindow, OS.CWBackPixmap, attributes);
- }
- }
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- boolean changed = super.setBounds (x, y, width, height, move, resize);
- if (changed && resize && layout != null) layout.layout (this, false);
- return changed;
-}
-public boolean setFocus () {
- checkWidget ();
- if ((style & SWT.NO_FOCUS) != 0) return false;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.setFocus ()) return true;
- }
- return forceFocus ();
-}
+public void layout (boolean changed) { + checkWidget(); + if (layout == null) return; + int count = getChildrenCount (); + if (count == 0) 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); +} +void moveAbove (int handle1, int handle2) { + if (handle1 == handle2) return; + int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int ptr = argList [1], count = argList [3]; + if (count == 0 || ptr == 0) return; + int [] handles = new int [count]; + OS.memmove (handles, ptr, count * 4); + if (handle2 == 0) handle2 = handles [0]; + int i = 0, index1 = -1, index2 = -1; + while (i < count) { + int handle = handles [i]; + if (handle == handle1) index1 = i; + if (handle == handle2) index2 = i; + if (index1 != -1 && index2 != -1) break; + i++; + } + if (index1 == -1 || index2 == -1) return; + if (index1 == index2) return; + if (index1 < index2) { + System.arraycopy (handles, index1 + 1, handles, index1, index2 - index1 - 1); + handles [index2 - 1] = handle1; + } else { + System.arraycopy (handles, index2, handles, index2 + 1, index1 - index2); + handles [index2] = handle1; + } + OS.memmove (ptr, handles, count * 4); +} +void moveBelow (int handle1, int handle2) { + if (handle1 == handle2) return; + int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int ptr = argList [1], count = argList [3]; + if (count == 0 || ptr == 0) return; + int [] handles = new int [count]; + OS.memmove (handles, ptr, count * 4); + if (handle2 == 0) handle2 = handles [count - 1]; + int i = 0, index1 = -1, index2 = -1; + while (i < count) { + int handle = handles [i]; + if (handle == handle1) index1 = i; + if (handle == handle2) index2 = i; + if (index1 != -1 && index2 != -1) break; + i++; + } + if (index1 == -1 || index2 == -1) return; + if (index1 == index2) return; + if (index1 < index2) { + System.arraycopy (handles, index1 + 1, handles, index1, index2 - index1); + handles [index2] = handle1; + } else { + System.arraycopy (handles, index2 + 1, handles, index2 + 2, index1 - index2 - 1); + handles [index2 + 1] = handle1; + } + OS.memmove (ptr, handles, count * 4); +} +void propagateChildren (boolean enabled) { + super.propagateChildren (enabled); + Control [] children = _getChildren (); + for (int i = 0; i < children.length; i++) { + Control child = children [i]; + if (child.getEnabled ()) { + child.propagateChildren (enabled); + } + } +} +void realizeChildren () { + super.realizeChildren (); + Control [] children = _getChildren (); + for (int i=0; i<children.length; i++) { + children [i].realizeChildren (); + } + if ((state & CANVAS) != 0) { + if ((style & SWT.NO_BACKGROUND) == 0 && (style & SWT.NO_REDRAW_RESIZE) != 0) return; + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return; + int xWindow = OS.XtWindow (handle); + if (xWindow == 0) return; + int flags = 0; + XSetWindowAttributes attributes = new XSetWindowAttributes (); + if ((style & SWT.NO_BACKGROUND) != 0) { + flags |= OS.CWBackPixmap; + attributes.background_pixmap = OS.None; + } + if ((style & SWT.NO_REDRAW_RESIZE) == 0) { + flags |= OS.CWBitGravity; + attributes.bit_gravity = OS.ForgetGravity; + } + if (flags != 0) { + OS.XChangeWindowAttributes (xDisplay, xWindow, flags, attributes); + } + } +} +void redrawWidget (int x, int y, int width, int height, boolean all) { + super.redrawWidget (x, y, width, height, all); + if (!all) return; + Control [] children = _getChildren (); + for (int i = 0; i < children.length; i++) { + Control child = children [i]; + Point location = child.getClientLocation (); + child.redrawWidget (x - location.x, y - location.y, width, height, all); + } +} +void releaseChildren () { + Control [] children = _getChildren (); + for (int i=0; i<children.length; i++) { + Control child = children [i]; + if (!child.isDisposed ()) child.releaseResources (); + } +} +void releaseWidget () { + releaseChildren (); + super.releaseWidget (); + layout = null; + tabList = null; + if (damagedRegion != 0) OS.XDestroyRegion (damagedRegion); + damagedRegion = 0; +} +void setBackgroundPixel (int pixel) { + super.setBackgroundPixel (pixel); + if ((state & CANVAS) != 0) { + if ((style & SWT.NO_BACKGROUND) != 0) { + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return; + int xWindow = OS.XtWindow (handle); + if (xWindow == 0) return; + XSetWindowAttributes attributes = new XSetWindowAttributes (); + attributes.background_pixmap = OS.None; + OS.XChangeWindowAttributes (xDisplay, xWindow, OS.CWBackPixmap, attributes); + } + } +} +boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { + boolean changed = super.setBounds (x, y, width, height, move, resize); + if (changed && resize && layout != null) layout.layout (this, false); + return changed; +} +public boolean setFocus () { + checkWidget (); + if ((style & SWT.NO_FOCUS) != 0) return false; + Control [] children = _getChildren (); + for (int i=0; i<children.length; i++) { + Control child = children [i]; + if (child.setFocus ()) return true; + } + return forceFocus (); +} /** * Sets the layout which is associated with the receiver to be * the argument which may be null. @@ -550,182 +550,182 @@ public boolean setFocus () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setLayout (Layout layout) {
- checkWidget();
- this.layout = layout;
-}
-/**
- * Sets the tabbing order for the specified controls to
- * match the order that they occur in the argument list.
- *
- * @param tabList the ordered list of controls representing the tab order or null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if a widget in the tabList is null or has been disposed</li>
- * <li>ERROR_INVALID_PARENT - if widget in the tabList is not in the same widget tree</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void setLayout (Layout layout) { + checkWidget(); + this.layout = layout; +} +/** + * Sets the tabbing order for the specified controls to + * match the order that they occur in the argument list. + * + * @param tabList the ordered list of controls representing the tab order or null + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if a widget in the tabList is null or has been disposed</li> + * <li>ERROR_INVALID_PARENT - if widget in the tabList is not in the same widget tree</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setTabList (Control [] tabList) {
- checkWidget ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- Control control = tabList [i];
- if (control == null) error (SWT.ERROR_INVALID_ARGUMENT);
- if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT);
- /*
- * This code is intentionally commented.
- * Tab lists are currently only supported
- * for the direct children of a composite.
- */
-// Shell shell = control.getShell ();
-// while (control != shell && control != this) {
-// control = control.parent;
-// }
-// if (control != this) error (SWT.ERROR_INVALID_PARENT);
- if (control.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
- Control [] newList = new Control [tabList.length];
- System.arraycopy (tabList, 0, newList, 0, tabList.length);
- tabList = newList;
- }
- this.tabList = tabList;
-}
-boolean setTabGroupFocus () {
- if (isTabItem ()) return setTabItemFocus ();
- if ((style & SWT.NO_FOCUS) == 0) {
- boolean takeFocus = true;
- if ((state & CANVAS) != 0) takeFocus = hooksKeys ();
- if (takeFocus && setTabItemFocus ()) return true;
- }
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.isTabItem () && child.setTabItemFocus ()) return true;
- }
- return false;
-}
-boolean setTabItemFocus () {
- if ((style & SWT.NO_FOCUS) == 0) {
- boolean takeFocus = true;
- if ((state & CANVAS) != 0) takeFocus = hooksKeys ();
- if (takeFocus) {
- if (!isShowing ()) return false;
- if (forceFocus ()) return true;
- }
- }
- return super.setTabItemFocus ();
-}
-void setScrollbarVisible (int barHandle, boolean visible) {
- /*
- * Bug in Motif. When XtDestroyWidget() is called from
- * within a FocusOut event handler, Motif GP's. The fix
- * is to post focus events and run them when the handler
- * has returned.
- */
- Display display = getDisplay ();
- boolean oldFocusOut = display.postFocusOut;
- Control [] children = _getChildren ();
- int [] traversals = new int [children.length];
- int [] argList = new int [] {OS.XmNtraversalOn, 0};
- for (int i=0; i<children.length; i++) {
- int childHandle = children [i].topHandle ();
- OS.XtGetValues (childHandle, argList, argList.length / 2);
- if ((traversals [i] = argList [1]) != 0) {
- argList [1] = 0;
- display.postFocusOut = true;
- OS.XtSetValues (children [i].handle, argList, argList.length / 2);
- }
- }
- super.setScrollbarVisible(barHandle, visible);
- for (int i=0; i<children.length; i++) {
- argList [1] = traversals [i];
- Control control = children [i];
- if (!control.isDisposed ()) {
- int childHandle = control.topHandle ();
- OS.XtSetValues (childHandle, argList, argList.length / 2);
- if (argList [1] != 0) control.overrideTranslations ();
- }
- }
- display.postFocusOut = oldFocusOut;
- if (!display.postFocusOut) display.runFocusOutEvents ();
-}
-int traversalCode (int key, XKeyEvent xEvent) {
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_FOCUS) != 0) return 0;
- if (hooksKeys ()) return 0;
- }
- return super.traversalCode (key, xEvent);
-}
-boolean translateMnemonic (char key, XKeyEvent xEvent) {
- if (super.translateMnemonic (key, xEvent)) return true;
- Control [] children = _getChildren ();
- for (int i=0; i<children.length; i++) {
- Control child = children [i];
- if (child.translateMnemonic (key, xEvent)) return true;
- }
- return false;
-}
-int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) {
- if ((state & CANVAS) == 0) {
- return super.XExposure (w, client_data, call_data, continue_to_dispatch);
- }
- if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0;
- if ((style & SWT.NO_MERGE_PAINTS) != 0) {
- return super.XExposure (w, client_data, call_data, continue_to_dispatch);
- }
- XExposeEvent xEvent = new XExposeEvent ();
- OS.memmove (xEvent, call_data, XExposeEvent.sizeof);
- int exposeCount = xEvent.count;
- if (exposeCount == 0) {
- if (OS.XEventsQueued (xEvent.display, OS.QueuedAfterReading) != 0) {
- XAnyEvent xAnyEvent = new XAnyEvent ();
- Display display = getDisplay ();
- display.exposeCount = display.lastExpose = 0;
- int checkExposeProc = display.checkExposeProc;
- OS.XCheckIfEvent (xEvent.display, xAnyEvent, checkExposeProc, xEvent.window);
- exposeCount = display.exposeCount;
- int lastExpose = display.lastExpose;
- if (exposeCount != 0 && lastExpose != 0) {
- XExposeEvent xExposeEvent = display.xExposeEvent;
- OS.memmove (xExposeEvent, lastExpose, XExposeEvent.sizeof);
- xExposeEvent.count = 0;
- OS.memmove (lastExpose, xExposeEvent, XExposeEvent.sizeof);
- }
- }
- }
- if (exposeCount == 0 && damagedRegion == 0) {
- return super.XExposure (w, client_data, call_data, continue_to_dispatch);
- }
- if (damagedRegion == 0) damagedRegion = OS.XCreateRegion ();
- OS.XtAddExposureToRegion (call_data, damagedRegion);
- if (exposeCount != 0) return 0;
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return 0;
- Event event = new Event ();
- GC gc = event.gc = new GC (this);
- Region region = Region.motif_new (damagedRegion);
- gc.setClipping (region);
- XRectangle rect = new XRectangle ();
- OS.XClipBox (damagedRegion, rect);
- event.x = rect.x; event.y = rect.y;
- event.width = rect.width; event.height = rect.height;
- sendEvent (SWT.Paint, event);
- gc.dispose ();
- event.gc = null;
- OS.XDestroyRegion (damagedRegion);
- damagedRegion = 0;
- return 0;
-}
-int XNonMaskable (int w, int client_data, int call_data, int continue_to_dispatch) {
- if ((state & CANVAS) != 0) {
- XExposeEvent xEvent = new XExposeEvent ();
- OS.memmove (xEvent, call_data, XExposeEvent.sizeof);
- if (xEvent.type == OS.GraphicsExpose) return XExposure (w, client_data, call_data, continue_to_dispatch);
- }
- return 0;
-}
-}
+public void setTabList (Control [] tabList) { + checkWidget (); + if (tabList != null) { + for (int i=0; i<tabList.length; i++) { + Control control = tabList [i]; + if (control == null) error (SWT.ERROR_INVALID_ARGUMENT); + if (control.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); + /* + * This code is intentionally commented. + * Tab lists are currently only supported + * for the direct children of a composite. + */ +// Shell shell = control.getShell (); +// while (control != shell && control != this) { +// control = control.parent; +// } +// if (control != this) error (SWT.ERROR_INVALID_PARENT); + if (control.parent != this) error (SWT.ERROR_INVALID_PARENT); + } + Control [] newList = new Control [tabList.length]; + System.arraycopy (tabList, 0, newList, 0, tabList.length); + tabList = newList; + } + this.tabList = tabList; +} +boolean setTabGroupFocus () { + if (isTabItem ()) return setTabItemFocus (); + if ((style & SWT.NO_FOCUS) == 0) { + boolean takeFocus = true; + if ((state & CANVAS) != 0) takeFocus = hooksKeys (); + if (takeFocus && setTabItemFocus ()) return true; + } + Control [] children = _getChildren (); + for (int i=0; i<children.length; i++) { + Control child = children [i]; + if (child.isTabItem () && child.setTabItemFocus ()) return true; + } + return false; +} +boolean setTabItemFocus () { + if ((style & SWT.NO_FOCUS) == 0) { + boolean takeFocus = true; + if ((state & CANVAS) != 0) takeFocus = hooksKeys (); + if (takeFocus) { + if (!isShowing ()) return false; + if (forceFocus ()) return true; + } + } + return super.setTabItemFocus (); +} +void setScrollbarVisible (int barHandle, boolean visible) { + /* + * Bug in Motif. When XtDestroyWidget() is called from + * within a FocusOut event handler, Motif GP's. The fix + * is to post focus events and run them when the handler + * has returned. + */ + Display display = getDisplay (); + boolean oldFocusOut = display.postFocusOut; + Control [] children = _getChildren (); + int [] traversals = new int [children.length]; + int [] argList = new int [] {OS.XmNtraversalOn, 0}; + for (int i=0; i<children.length; i++) { + int childHandle = children [i].topHandle (); + OS.XtGetValues (childHandle, argList, argList.length / 2); + if ((traversals [i] = argList [1]) != 0) { + argList [1] = 0; + display.postFocusOut = true; + OS.XtSetValues (children [i].handle, argList, argList.length / 2); + } + } + super.setScrollbarVisible(barHandle, visible); + for (int i=0; i<children.length; i++) { + argList [1] = traversals [i]; + Control control = children [i]; + if (!control.isDisposed ()) { + int childHandle = control.topHandle (); + OS.XtSetValues (childHandle, argList, argList.length / 2); + if (argList [1] != 0) control.overrideTranslations (); + } + } + display.postFocusOut = oldFocusOut; + if (!display.postFocusOut) display.runFocusOutEvents (); +} +int traversalCode (int key, XKeyEvent xEvent) { + if ((state & CANVAS) != 0) { + if ((style & SWT.NO_FOCUS) != 0) return 0; + if (hooksKeys ()) return 0; + } + return super.traversalCode (key, xEvent); +} +boolean translateMnemonic (char key, XKeyEvent xEvent) { + if (super.translateMnemonic (key, xEvent)) return true; + Control [] children = _getChildren (); + for (int i=0; i<children.length; i++) { + Control child = children [i]; + if (child.translateMnemonic (key, xEvent)) return true; + } + return false; +} +int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) { + if ((state & CANVAS) == 0) { + return super.XExposure (w, client_data, call_data, continue_to_dispatch); + } + if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0; + if ((style & SWT.NO_MERGE_PAINTS) != 0) { + return super.XExposure (w, client_data, call_data, continue_to_dispatch); + } + XExposeEvent xEvent = new XExposeEvent (); + OS.memmove (xEvent, call_data, XExposeEvent.sizeof); + int exposeCount = xEvent.count; + if (exposeCount == 0) { + if (OS.XEventsQueued (xEvent.display, OS.QueuedAfterReading) != 0) { + XAnyEvent xAnyEvent = new XAnyEvent (); + Display display = getDisplay (); + display.exposeCount = display.lastExpose = 0; + int checkExposeProc = display.checkExposeProc; + OS.XCheckIfEvent (xEvent.display, xAnyEvent, checkExposeProc, xEvent.window); + exposeCount = display.exposeCount; + int lastExpose = display.lastExpose; + if (exposeCount != 0 && lastExpose != 0) { + XExposeEvent xExposeEvent = display.xExposeEvent; + OS.memmove (xExposeEvent, lastExpose, XExposeEvent.sizeof); + xExposeEvent.count = 0; + OS.memmove (lastExpose, xExposeEvent, XExposeEvent.sizeof); + } + } + } + if (exposeCount == 0 && damagedRegion == 0) { + return super.XExposure (w, client_data, call_data, continue_to_dispatch); + } + if (damagedRegion == 0) damagedRegion = OS.XCreateRegion (); + OS.XtAddExposureToRegion (call_data, damagedRegion); + if (exposeCount != 0) return 0; + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return 0; + Event event = new Event (); + GC gc = event.gc = new GC (this); + Region region = Region.motif_new (damagedRegion); + gc.setClipping (region); + XRectangle rect = new XRectangle (); + OS.XClipBox (damagedRegion, rect); + event.x = rect.x; event.y = rect.y; + event.width = rect.width; event.height = rect.height; + sendEvent (SWT.Paint, event); + gc.dispose (); + event.gc = null; + OS.XDestroyRegion (damagedRegion); + damagedRegion = 0; + return 0; +} +int XNonMaskable (int w, int client_data, int call_data, int continue_to_dispatch) { + if ((state & CANVAS) != 0) { + XExposeEvent xEvent = new XExposeEvent (); + OS.memmove (xEvent, call_data, XExposeEvent.sizeof); + if (xEvent.type == OS.GraphicsExpose) return XExposure (w, client_data, call_data, continue_to_dispatch); + } + return 0; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java index 34ec2e8925..818fa23e41 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Control.java @@ -1,45 +1,45 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.accessibility.*;
-
-/**
- * Control is the abstract superclass of all windowed user interface classes.
- * <p>
- * <dl>
- * <dt><b>Styles:</b>
- * <dd>BORDER</dd>
- * <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;
- Font font;
- Menu menu;
- String toolTipText;
- Object layoutData;
- Accessible accessible;
-
-Control () {
- /* Do nothing */
-}
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.*; +import org.eclipse.swt.events.*; +import org.eclipse.swt.accessibility.*; + +/** + * Control is the abstract superclass of all windowed user interface classes. + * <p> + * <dl> + * <dt><b>Styles:</b> + * <dd>BORDER</dd> + * <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; + Font font; + Menu menu; + String toolTipText; + Object layoutData; + Accessible accessible; + +Control () { + /* Do nothing */ +} /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -68,63 +68,63 @@ Control () { * @see Widget#checkSubclass * @see Widget#getStyle */ -public Control (Composite parent, int style) {
- super (parent, style);
- this.parent = parent;
- createWidget (0);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
- */ -public void addControlListener(ControlListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Resize,typedListener);
- addListener (SWT.Move,typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when 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);
-}
+public Control (Composite parent, int style) { + super (parent, style); + this.parent = parent; + createWidget (0); +} +/** + * Adds the listener to the collection of listeners who will + * be notified when the control is moved or resized, by sending + * it one of the messages defined in the <code>ControlListener</code> + * interface. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see ControlListener + * @see #removeControlListener + */ +public void addControlListener(ControlListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener (listener); + addListener (SWT.Resize,typedListener); + addListener (SWT.Move,typedListener); +} +/** + * Adds the listener to the collection of listeners who will + * be notified when the control gains or loses focus, by sending + * it one of the messages defined in the <code>FocusListener</code> + * interface. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see FocusListener + * @see #removeFocusListener + */ +public void addFocusListener(FocusListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener (listener); + addListener(SWT.FocusIn,typedListener); + addListener(SWT.FocusOut,typedListener); +} /** * Adds the listener to the collection of listeners who will * be notified when help events are generated for the control, @@ -144,167 +144,167 @@ public void addFocusListener(FocusListener listener) { * @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 passes or hovers over controls, by sending
- * it one of the messages defined in the <code>MouseTrackListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseTrackListener
- * @see #removeMouseTrackListener
- */ -public void addMouseTrackListener (MouseTrackListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.MouseEnter,typedListener);
- addListener (SWT.MouseExit,typedListener);
- addListener (SWT.MouseHover,typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the mouse 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 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);
-}
+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 passes or hovers over controls, by sending + * it one of the messages defined in the <code>MouseTrackListener</code> + * interface. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see MouseTrackListener + * @see #removeMouseTrackListener + */ +public void addMouseTrackListener (MouseTrackListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener (listener); + addListener (SWT.MouseEnter,typedListener); + addListener (SWT.MouseExit,typedListener); + addListener (SWT.MouseHover,typedListener); +} +/** + * Adds the listener to the collection of listeners who will + * be notified when the mouse 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 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); +} /** * Returns the preferred size of the receiver. * <p> @@ -332,9 +332,9 @@ public void addTraverseListener (TraverseListener listener) { * @see #pack * @see "computeTrim, getClientArea for controls that implement them" */ -public Point computeSize (int wHint, int hHint) {
- return computeSize (wHint, hHint, true);
-}
+public Point computeSize (int wHint, int hHint) { + return computeSize (wHint, hHint, true); +} /** * Returns the preferred size of the receiver. * <p> @@ -369,165 +369,165 @@ public Point computeSize (int wHint, int hHint) { * @see #pack * @see "computeTrim, getClientArea for controls that implement them" */ -public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = DEFAULT_WIDTH;
- int height = DEFAULT_HEIGHT;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- int border = getBorderWidth ();
- width += border * 2;
- height += border * 2;
- return new Point (width, height);
-}
-
-Control computeTabGroup () {
- if (isTabGroup ()) return this;
- return parent.computeTabGroup ();
-}
-
-Control computeTabRoot () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- int index = 0;
- while (index < tabList.length) {
- if (tabList [index] == this) break;
- index++;
- }
- if (index == tabList.length) {
- if (isTabGroup ()) return this;
- }
- }
- return parent.computeTabRoot ();
-}
-
-Control [] computeTabList () {
- if (isTabGroup ()) {
- if (getVisible () && getEnabled ()) {
- return new Control [] {this};
- }
- }
- return new Control [0];
-}
-
-void createWidget (int index) {
- checkOrientation (parent);
- super.createWidget (index);
- setParentTraversal ();
-
- /*
- * Register for the IME. This is necessary on single byte
- * platforms as well as double byte platforms in order to
- * get composed characters. For example, accented characters
- * on a German locale.
- */
- if (!hasIMSupport()) {
- OS.XmImRegister (handle, 0);
- }
-
- /*
- * Feature in MOTIF. When a widget is created before the
- * parent has been realized, the widget is created behind
- * all siblings in the Z-order. When a widget is created
- * after the parent has been realized, it is created in
- * front of all siblings. This is not incorrect but is
- * unexpected. The fix is to force all widgets to always
- * be created behind their siblings.
- */
- int topHandle = topHandle ();
- if (OS.XtIsRealized (topHandle)) {
- int window = OS.XtWindow (topHandle);
- if (window != 0) {
- int display = OS.XtDisplay (topHandle);
- if (display != 0) OS.XLowerWindow (display, window);
- }
- /*
- * Make that the widget has been properly realized
- * because the widget was created after the parent
- * has been realized. This is not part of the fix
- * for Z-order in the code above.
- */
- realizeChildren ();
- }
-
- /*
- * Bug in Motif. Under certain circumstances, when a
- * text widget is created as a child of another control
- * that has drag and drop, starting a drag in the text
- * widget causes a protection fault. The fix is to
- * disable the built in drag and drop for all widgets
- * by overriding the drag start traslation.
- */
- Display display = getDisplay ();
- OS.XtOverrideTranslations (handle, display.dragTranslations);
-
- /*
- * Feature in Motif. When the XmNfontList resource is set for
- * a widget, Motif creates a copy of the fontList and disposes
- * the copy when the widget is disposed. This means that when
- * the programmer queries the font, not only will the handle be
- * different but the font will be unexpectedly disposed when
- * the widget is disposed. This can cause GP's when the font
- * is set in another widget. The fix is to cache the font that
- * the programmer provides. The initial value of the cache is
- * the default font for the widget.
- */
- font = defaultFont ();
-}
-int defaultBackground () {
- return getDisplay ().defaultBackground;
-}
-Font defaultFont () {
- return getDisplay ().defaultFont;
-}
-int defaultForeground () {
- return getDisplay ().defaultForeground;
-}
-void enableWidget (boolean enabled) {
- enableHandle (enabled, handle);
-}
-char findMnemonic (String string) {
- int index = 0;
- int length = string.length ();
- do {
- while (index < length && string.charAt (index) != Mnemonic) index++;
- if (++index >= length) return '\0';
- if (string.charAt (index) != Mnemonic) return string.charAt (index);
- index++;
- } while (index < length);
- return '\0';
-}
-void fixFocus () {
- Shell shell = getShell ();
- Control control = this;
- while ((control = control.parent) != null) {
- if (control.setFocus () || control == shell) return;
- }
-}
-int fontHandle () {
- return handle;
-}
-/**
- * Forces the receiver to have the <em>keyboard focus</em>, causing
- * all keyboard events to be delivered to it.
- *
- * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setFocus
- */ -public boolean forceFocus () {
- checkWidget();
- Decorations shell = menuShell ();
- shell.setSavedFocus (this);
- shell.bringToTop (false);
- return XmProcessTraversal (handle, OS.XmTRAVERSE_CURRENT);
-}
-
+public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget(); + int width = DEFAULT_WIDTH; + int height = DEFAULT_HEIGHT; + if (wHint != SWT.DEFAULT) width = wHint; + if (hHint != SWT.DEFAULT) height = hHint; + int border = getBorderWidth (); + width += border * 2; + height += border * 2; + return new Point (width, height); +} + +Control computeTabGroup () { + if (isTabGroup ()) return this; + return parent.computeTabGroup (); +} + +Control computeTabRoot () { + Control [] tabList = parent._getTabList (); + if (tabList != null) { + int index = 0; + while (index < tabList.length) { + if (tabList [index] == this) break; + index++; + } + if (index == tabList.length) { + if (isTabGroup ()) return this; + } + } + return parent.computeTabRoot (); +} + +Control [] computeTabList () { + if (isTabGroup ()) { + if (getVisible () && getEnabled ()) { + return new Control [] {this}; + } + } + return new Control [0]; +} + +void createWidget (int index) { + checkOrientation (parent); + super.createWidget (index); + setParentTraversal (); + + /* + * Register for the IME. This is necessary on single byte + * platforms as well as double byte platforms in order to + * get composed characters. For example, accented characters + * on a German locale. + */ + if (!hasIMSupport()) { + OS.XmImRegister (handle, 0); + } + + /* + * Feature in MOTIF. When a widget is created before the + * parent has been realized, the widget is created behind + * all siblings in the Z-order. When a widget is created + * after the parent has been realized, it is created in + * front of all siblings. This is not incorrect but is + * unexpected. The fix is to force all widgets to always + * be created behind their siblings. + */ + int topHandle = topHandle (); + if (OS.XtIsRealized (topHandle)) { + int window = OS.XtWindow (topHandle); + if (window != 0) { + int display = OS.XtDisplay (topHandle); + if (display != 0) OS.XLowerWindow (display, window); + } + /* + * Make that the widget has been properly realized + * because the widget was created after the parent + * has been realized. This is not part of the fix + * for Z-order in the code above. + */ + realizeChildren (); + } + + /* + * Bug in Motif. Under certain circumstances, when a + * text widget is created as a child of another control + * that has drag and drop, starting a drag in the text + * widget causes a protection fault. The fix is to + * disable the built in drag and drop for all widgets + * by overriding the drag start traslation. + */ + Display display = getDisplay (); + OS.XtOverrideTranslations (handle, display.dragTranslations); + + /* + * Feature in Motif. When the XmNfontList resource is set for + * a widget, Motif creates a copy of the fontList and disposes + * the copy when the widget is disposed. This means that when + * the programmer queries the font, not only will the handle be + * different but the font will be unexpectedly disposed when + * the widget is disposed. This can cause GP's when the font + * is set in another widget. The fix is to cache the font that + * the programmer provides. The initial value of the cache is + * the default font for the widget. + */ + font = defaultFont (); +} +int defaultBackground () { + return getDisplay ().defaultBackground; +} +Font defaultFont () { + return getDisplay ().defaultFont; +} +int defaultForeground () { + return getDisplay ().defaultForeground; +} +void enableWidget (boolean enabled) { + enableHandle (enabled, handle); +} +char findMnemonic (String string) { + int index = 0; + int length = string.length (); + do { + while (index < length && string.charAt (index) != Mnemonic) index++; + if (++index >= length) return '\0'; + if (string.charAt (index) != Mnemonic) return string.charAt (index); + index++; + } while (index < length); + return '\0'; +} +void fixFocus () { + Shell shell = getShell (); + Control control = this; + while ((control = control.parent) != null) { + if (control.setFocus () || control == shell) return; + } +} +int fontHandle () { + return handle; +} +/** + * Forces the receiver to have the <em>keyboard focus</em>, causing + * all keyboard events to be delivered to it. + * + * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #setFocus + */ +public boolean forceFocus () { + checkWidget(); + Decorations shell = menuShell (); + shell.setSavedFocus (this); + shell.bringToTop (false); + return XmProcessTraversal (handle, OS.XmTRAVERSE_CURRENT); +} + /** * Returns the accessible object for the receiver. * If this is the first time this object is requested, @@ -545,2310 +545,2310 @@ public boolean forceFocus () { * * @since 2.0 */ -public Accessible getAccessible () {
- checkWidget ();
- if (accessible == null) {
- accessible = Accessible.internal_new_Accessible (this);
- }
- return accessible;
-}
-
-/**
- * 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.motif_new (getDisplay (), getXColor (getBackgroundPixel ()));
-}
-int getBackgroundPixel () {
- int [] argList = {OS.XmNbackground, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the receiver's border width.
- *
- * @return the border width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public int getBorderWidth () {
- checkWidget();
- int topHandle = topHandle ();
- int [] argList = {OS.XmNborderWidth, 0};
- OS.XtGetValues (topHandle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent (or its display if its parent is null).
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public Rectangle getBounds () {
- checkWidget();
- int topHandle = topHandle ();
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (topHandle, argList, argList.length / 2);
- int borders = argList [9] * 2;
- return new Rectangle ((short) argList [1], (short) argList [3], argList [5] + borders, argList [7] + borders);
-}
-Point getClientLocation () {
- short [] handle_x = new short [1], handle_y = new short [1];
- OS.XtTranslateCoords (handle, (short) 0, (short) 0, handle_x, handle_y);
- short [] topHandle_x = new short [1], topHandle_y = new short [1];
- OS.XtTranslateCoords (parent.handle, (short) 0, (short) 0, topHandle_x, topHandle_y);
- return new Point (handle_x [0] - topHandle_x [0], handle_y [0] - topHandle_y [0]);
-}
-String getCodePage () {
- return font.codePage;
-}
-/**
- * Returns the 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 () {
- Composite 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 () {
- checkWidget();
- int [] argList = {OS.XmNsensitive, 0};
- OS.XtGetValues (topHandle (), argList, argList.length / 2);
- return argList [1] != 0;
-}
-/**
- * Returns the font that the receiver will use to paint textual information.
- *
- * @return the receiver's font
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public Font getFont () {
- checkWidget();
- return font;
-}
-
-int getFontAscent () {
-
- /* Create a font context to iterate over each element in the font list */
- int [] buffer = new int [1];
- if (!OS.XmFontListInitFontContext (buffer, font.handle)) {
- error (SWT.ERROR_NO_HANDLES);
- }
- int context = buffer [0];
-
- /* Values discovering during iteration */
- int ascent = 0;
- XFontStruct fontStruct = new XFontStruct ();
- int fontListEntry;
- int [] fontStructPtr = new int [1];
- int [] fontNamePtr = new int [1];
-
- /* Go through each entry in the font list. */
- while ((fontListEntry = OS.XmFontListNextEntry (context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer);
- if (buffer [0] == 0) {
- /* FontList contains a single font */
- OS.memmove (fontStruct, fontPtr, XFontStruct.sizeof);
- int fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent);
- if (fontAscent > ascent) ascent = fontAscent;
- } else {
- /* FontList contains a fontSet */
- int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr);
- int [] fontStructs = new int [nFonts];
- OS.memmove (fontStructs, fontStructPtr [0], nFonts * 4);
-
- /* Go through each fontStruct in the font set */
- for (int i=0; i<nFonts; i++) {
- OS.memmove (fontStruct, fontStructs[i], XFontStruct.sizeof);
- int fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent);
- if (fontAscent > ascent) ascent = fontAscent;
- }
- }
- }
-
- OS.XmFontListFreeFontContext (context);
- return ascent;
-}
-
-int getFontHeight () {
-
- /* Create a font context to iterate over each element in the font list */
- int [] buffer = new int [1];
- if (!OS.XmFontListInitFontContext (buffer, font.handle)) {
- error (SWT.ERROR_NO_HANDLES);
- }
- int context = buffer [0];
-
- /* Values discovering during iteration */
- int height = 0;
- XFontStruct fontStruct = new XFontStruct ();
- int fontListEntry;
- int [] fontStructPtr = new int [1];
- int [] fontNamePtr = new int [1];
-
- /* Go through each entry in the font list. */
- while ((fontListEntry = OS.XmFontListNextEntry (context)) != 0) {
- int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer);
- if (buffer [0] == 0) {
- /* FontList contains a single font */
- OS.memmove (fontStruct, fontPtr, XFontStruct.sizeof);
- int fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent);
- int fontDescent = Math.max (fontStruct.descent, fontStruct.max_bounds_descent);
- int fontHeight = fontAscent + fontDescent;
- if (fontHeight > height) height = fontHeight;
- } else {
- /* FontList contains a fontSet */
- int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr);
- int [] fontStructs = new int [nFonts];
- OS.memmove (fontStructs, fontStructPtr [0], nFonts * 4);
-
- /* Go through each fontStruct in the font set */
- for (int i=0; i<nFonts; i++) {
- OS.memmove (fontStruct, fontStructs[i], XFontStruct.sizeof);
- int fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent);
- int fontDescent = Math.max (fontStruct.descent, fontStruct.max_bounds_descent);
- int fontHeight = fontAscent + fontDescent;
- if (fontHeight > height) height = fontHeight;
- }
- }
- }
-
- OS.XmFontListFreeFontContext (context);
- return height;
-}
-//int getFontList () {
-// int fontHandle = fontHandle ();
-// int [] argList = {OS.XmNfontList, 0};
-// OS.XtGetValues (fontHandle, argList, argList.length / 2);
-// if (argList [1] != 0) return argList [1];
-// if (fontList == 0) fontList = defaultFont ();
-// return fontList;
-//}
-/**
- * Returns the foreground color that the receiver will use to draw.
- *
- * @return the receiver's foreground color
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public Color getForeground () {
- checkWidget();
- return Color.motif_new (getDisplay (), getXColor (getForegroundPixel ()));
-}
-int getForegroundPixel () {
- int [] argList = {OS.XmNforeground, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-short [] getIMCaretPos () {
- return new short[]{0, 0};
-}
-/**
- * Returns layout data which is associated with the receiver.
- *
- * @return the receiver's layout data
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public Object getLayoutData () {
- checkWidget();
- return layoutData;
-}
-/**
- * Returns a point describing the receiver's location relative
- * to its parent (or its display if its parent is null).
- *
- * @return the receiver's location
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public Point getLocation () {
- checkWidget();
- int topHandle = topHandle ();
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0};
- OS.XtGetValues (topHandle, argList, argList.length / 2);
- return new Point ((short) argList [1], (short) argList [3]);
-}
-/**
- * Returns the receiver's pop up menu if it has one, or null
- * if it does not. All controls may optionally have a pop up
- * menu that is displayed when the user requests one for
- * the control. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pop up
- * menu is platform specific.
- *
- * @return the receiver's menu
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public Menu getMenu () {
- checkWidget();
- return menu;
-}
-int getNavigationType () {
- int [] argList = {OS.XmNnavigationType, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the receiver's parent, which must be a <code>Composite</code>
- * or null when the receiver is a shell that was created with null or
- * a display for a parent.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public Composite getParent () {
- checkWidget();
- return parent;
-}
-Control [] getPath () {
- int count = 0;
- Shell shell = getShell ();
- Control control = this;
- while (control != shell) {
- count++;
- control = control.parent;
- }
- control = this;
- Control [] result = new Control [count];
- while (control != shell) {
- result [--count] = control;
- control = control.parent;
- }
- return result;
-}
-/**
- * Returns the receiver's shell. For all controls other than
- * shells, this simply returns the control's nearest ancestor
- * shell. Shells return themselves, even if they are children
- * of other shells.
- *
- * @return the receiver's shell
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getParent
- */ -public Shell getShell () {
- checkWidget();
- return parent.getShell ();
-}
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public Point getSize () {
- checkWidget();
- int topHandle = topHandle ();
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (topHandle, argList, argList.length / 2);
- int borders = argList [5] * 2;
- return new Point (argList [1] + borders, argList [3] + borders);
-}
-/**
- * Returns the receiver's tool tip text, or null if it has
- * not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public boolean getVisible () {
- checkWidget();
- int topHandle = topHandle ();
- int [] argList = {OS.XmNmappedWhenManaged, 0};
- OS.XtGetValues (topHandle, argList, argList.length / 2);
- return argList [1] != 0;
-}
-XColor getXColor (int pixel) {
- int display = OS.XtDisplay (handle);
- if (display == 0) return null;
- int [] argList = {OS.XmNcolormap, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int colormap = argList [1];
- if (colormap == 0) return null;
- XColor color = new XColor ();
- color.pixel = pixel;
- OS.XQueryColor (display, colormap, color);
- return color;
-}
-boolean hasFocus () {
- return this == getDisplay ().getFocusControl ();
-}
-/**
- * Returns true if the widget has native IM support
- */
-boolean hasIMSupport() {
- return false;
-}
-void hookEvents () {
- int windowProc = getDisplay ().windowProc;
- OS.XtAddEventHandler (handle, OS.KeyPressMask, false, windowProc, KEY_PRESS);
- OS.XtAddEventHandler (handle, OS.KeyReleaseMask, false, windowProc, KEY_RELEASE);
- OS.XtAddEventHandler (handle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS);
- OS.XtAddEventHandler (handle, OS.ButtonReleaseMask, false, windowProc, BUTTON_RELEASE);
- OS.XtAddEventHandler (handle, OS.PointerMotionMask, false, windowProc, POINTER_MOTION);
- OS.XtAddEventHandler (handle, OS.EnterWindowMask, false, windowProc, ENTER_WINDOW);
- OS.XtAddEventHandler (handle, OS.LeaveWindowMask, false, windowProc, LEAVE_WINDOW);
- OS.XtInsertEventHandler (handle, OS.ExposureMask, false, windowProc, EXPOSURE, OS.XtListTail);
- OS.XtInsertEventHandler (handle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail);
- OS.XtAddCallback (handle, OS.XmNhelpCallback, windowProc, HELP_CALLBACK);
-}
-int hoverProc (int id) {
- return hoverProc (id, true);
-}
-int hoverProc (int id, boolean showTip) {
- Display display = getDisplay ();
- if (showTip) display.showToolTip (handle, toolTipText);
- sendMouseEvent (SWT.MouseHover, 0);
- return 0;
-}
-/**
- * Invokes platform specific functionality to allocate a new GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Control</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param data the platform specific GC data
- * @return the platform specific GC handle
- *
- * @private
- */ -public int internal_new_GC (GCData data) {
- checkWidget();
- if (!OS.XtIsRealized (handle)) {
- Shell shell = getShell ();
- shell.realizeWidget ();
- }
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- int xGC = OS.XCreateGC (xDisplay, xWindow, 0, null);
- if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.XSetGraphicsExposures (xDisplay, xGC, false);
- int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNcolormap, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (data != null) {
- data.device = getDisplay ();
- data.display = xDisplay;
- data.drawable = xWindow;
- data.foreground = argList [1];
- data.background = argList [3];
- data.fontList = font.handle;
- data.codePage = font.codePage;
- data.colormap = argList [5];
- }
- return xGC;
-}
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Control</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param handle the platform specific GC handle
- * @param data the platform specific GC data
- *
- * @private
- */ -public void internal_dispose_GC (int xGC, GCData data) {
- checkWidget ();
- int xDisplay = 0;
- if (data != null) xDisplay = data.display;
- if (xDisplay == 0 && handle != 0) xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- OS.XFreeGC (xDisplay, xGC);
-}
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
- */ -public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-boolean isFocusAncestor () {
- Display display = getDisplay ();
- Control control = display.getFocusControl ();
- while (control != null && control != this) {
- control = control.parent;
- }
- return control == this;
-}
-/**
- * Returns <code>true</code> if the receiver has the user-interface
- * focus, and <code>false</code> otherwise.
- *
- * @return the receiver's focus state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public boolean isFocusControl () {
- checkWidget();
- return hasFocus ();
-}
-/**
- * Returns <code>true</code> if the underlying operating
- * system supports this reparenting, otherwise <code>false</code>
- *
- * @return <code>true</code> if the widget can be reparented, otherwise <code>false</code>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public boolean isReparentable () {
- checkWidget();
- return false;
-}
-boolean isShowing () {
- /*
- * This is not complete. Need to check if the
- * widget is obscurred by a parent or sibling.
- */
- if (!isVisible ()) return false;
- Control control = this;
- while (control != null) {
- Point size = control.getSize ();
- if (size.x == 1 || size.y == 1) {
- return false;
- }
- control = control.parent;
- }
- return true;
-}
-boolean isTabGroup () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == this) return true;
- }
- }
- int code = traversalCode (0, null);
- if ((code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) != 0) return false;
- return (code & (SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_TAB_NEXT)) != 0;
-}
-boolean isTabItem () {
- Control [] tabList = parent._getTabList ();
- if (tabList != null) {
- for (int i=0; i<tabList.length; i++) {
- if (tabList [i] == this) return false;
- }
- }
- int code = traversalCode (0, null);
- return (code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) != 0;
-}
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
- */ -public boolean isVisible () {
- checkWidget();
- return getVisible () && parent.isVisible ();
-}
-void manageChildren () {
- OS.XtSetMappedWhenManaged (handle, false);
- /*
- * Feature in Motif. When a widget is managed and an
- * ancestor in the widget hierarchy has focus, Motif
- * assigns focus to another widget in the shell. This
- * happens because Motif does not expect a non-leaf
- * widget to have the focus. The fix is to save the
- * current value of XmNtraversalOn, set the new value
- * to false, then manage the widget and restore the
- * value. This relies on the fact that Motif will
- * not reassign focus when the new widget is not
- * traversable.
- *
- * NOTE: This code currently does not work when a
- * sibling will take focus.
- */
- int topHandle = topHandle ();
- int [] argList1 = {OS.XmNtraversalOn, 0};
- OS.XtGetValues (topHandle, argList1, argList1.length / 2);
- if (argList1 [1] != 0) {
- int [] argList2 = {OS.XmNtraversalOn, 0};
- OS.XtSetValues (topHandle, argList2, argList2.length / 2);
- }
- OS.XtManageChild (handle);
- if (argList1 [1] != 0) {
- OS.XtSetValues (topHandle, argList1, argList1.length / 2);
- }
- overrideTranslations ();
- int [] argList3 = {OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList3, argList3.length / 2);
- OS.XtResizeWidget (handle, 1, 1, argList3 [1]);
- OS.XtSetMappedWhenManaged (handle, true);
-}
-Decorations menuShell () {
- return parent.menuShell ();
-}
-boolean mnemonicHit (char key) {
- return false;
-}
-boolean mnemonicMatch (char key) {
- return false;
-}
-/**
- * Moves the receiver above the specified control in the
- * drawing order. If the argument is null, then the receiver
- * is moved to the top of the drawing order. The control at
- * the top of the drawing order will not be covered by other
- * controls even if they occupy intersecting areas.
- *
- * @param 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();
- if (control != null) {
- if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- }
- setZOrder (control, true);
-}
-/**
- * Moves the receiver below the specified control in the
- * drawing order. If the argument is null, then the receiver
- * is moved to the bottom of the drawing order. The control at
- * the bottom of the drawing order will be covered by all other
- * controls which occupy intersecting areas.
- *
- * @param 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();
- if (control != null) {
- if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
- if (parent != control.parent) return;
- }
- setZOrder (control, false);
-}
-void overrideTranslations () {
- Display display = getDisplay ();
- OS.XtOverrideTranslations (handle, display.tabTranslations);
- OS.XtOverrideTranslations (handle, display.arrowTranslations);
-}
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #computeSize
- */ -public void pack () {
- checkWidget();
- pack (true);
-}
-/**
- * Causes the receiver to be resized to its preferred size.
- * For a composite, this involves computing the preferred size
- * from its layout, if there is one.
- * <p>
- * If the changed flag is <code>true</code>, it indicates that the receiver's
- * <em>contents</em> have changed, therefore any caches that a layout manager
- * containing the control may have been keeping need to be flushed. When the
- * control is resized, the changed flag will be <code>false</code>, so layout
- * manager caches can be retained.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if 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));
-}
-void propagateChildren (boolean enabled) {
- propagateWidget (enabled);
-}
-void propagateWidget (boolean enabled) {
- propagateHandle (enabled, handle);
-}
-void realizeChildren () {
- if (!isEnabled ()) propagateWidget (false);
-}
-/**
- * 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 () {
- checkWidget();
- redrawWidget (0, 0, 0, 0, false);
-}
-/**
- * Causes the rectangular area of the receiver specified by
- * the arguments to be marked as needing to be redrawn.
- * The next time a paint request is processed, that area of
- * the receiver will be painted. 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) {
- checkWidget ();
- if (width <= 0 || height <= 0) return;
- redrawWidget (x, y, width, height, all);
-}
-void redrawWidget (int x, int y, int width, int height, boolean all) {
- redrawHandle (x, y, width, height, handle);
-}
-void releaseWidget () {
- /*
- * Restore the default font for the widget in case the
- * application disposes the widget font in the dispose
- * callback. If a font is disposed while it is still
- * in use in the widget, Motif GP's.
- */
- int fontList = defaultFont ().handle;
- if (font.handle != fontList) {
- int fontHandle = fontHandle ();
- int [] argList2 = {OS.XmNfontList, fontList};
- OS.XtSetValues (fontHandle, argList2, argList2.length / 2);
- }
- super.releaseWidget ();
- Display display = getDisplay ();
- display.releaseToolTipHandle (handle);
- toolTipText = null;
- if (menu != null && !menu.isDisposed ()) {
- menu.dispose ();
- }
- menu = null;
- if (!hasIMSupport()) {
- OS.XmImUnregister (handle);
- }
- parent = null;
- layoutData = 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) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
- eventTable.unhook (SWT.Resize, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control 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) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.FocusIn, listener);
- eventTable.unhook(SWT.FocusOut, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #addHelpListener
- */ -public void removeHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when keys are pressed and released on the system keyboard.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see KeyListener
- * @see #addKeyListener
- */ -public void removeKeyListener(KeyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.KeyUp, listener);
- eventTable.unhook(SWT.KeyDown, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when 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) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.MouseDown, listener);
- eventTable.unhook(SWT.MouseUp, listener);
- eventTable.unhook(SWT.MouseDoubleClick, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse moves.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseMoveListener
- * @see #addMouseMoveListener
- */ -public void removeMouseMoveListener(MouseMoveListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.MouseMove, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the mouse passes or hovers over controls.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see MouseTrackListener
- * @see #addMouseTrackListener
- */ -public void removeMouseTrackListener(MouseTrackListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.MouseEnter, listener);
- eventTable.unhook (SWT.MouseExit, listener);
- eventTable.unhook (SWT.MouseHover, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the 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) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Paint, listener);
-}/**
- * Removes the listener from the collection of listeners who will
- * be notified when traversal events occur.
- *
- * @param listener the listener which should 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);
-}
-void sendHelpEvent (int callData) {
- Control control = this;
- while (control != null) {
- if (control.hooks (SWT.Help)) {
- control.postEvent (SWT.Help);
- return;
- }
- control = control.parent;
- }
-}
-byte [] sendIMKeyEvent (int type, XKeyEvent xEvent) {
- /*
- * Bug in Motif. On Linux only, XmImMbLookupString () does not return
- * XBufferOverflow as the status if the buffer is too small. The fix
- * is to pass a large buffer.
- */
- byte [] buffer = new byte [512];
- int [] status = new int [1], unused = new int [1];
- int length = OS.XmImMbLookupString (handle, xEvent, buffer, buffer.length, unused, status);
- if (status [0] == OS.XBufferOverflow) {
- buffer = new byte [length];
- length = OS.XmImMbLookupString (handle, xEvent, buffer, length, unused, status);
- }
- if (length == 0) return null;
-
- /* Convert from MBCS to UNICODE and send the event */
- /* Use the character encoding for the default locale */
- char [] result = Converter.mbcsToWcs (null, buffer);
- int index = 0;
- while (index < result.length) {
- if (result [index] == 0) break;
- Event event = new Event ();
- event.time = xEvent.time;
- event.character = result [index];
- setInputState (event, xEvent);
- postEvent (type, event);
- index++;
- }
- return buffer;
-}
-void sendKeyEvent (int type, XKeyEvent xEvent) {
- Event event = new Event ();
- event.time = xEvent.time;
- setKeyState (event, xEvent);
- Control control = this;
- if ((state & CANVAS) != 0) {
- if ((style & SWT.NO_FOCUS) != 0) {
- Display display = getDisplay ();
- control = display.getFocusControl ();
- }
- }
- if (control != null) {
- control.postEvent (type, event);
- }
-}
-void sendMouseEvent (int type, int button) {
- int xDisplay = OS.XtDisplay (handle);
- int xWindow = OS.XtWindow (handle);
- int [] windowX = new int [1], windowY = new int [1], mask = new int [1], unused = new int [1];
- OS.XQueryPointer (xDisplay, xWindow, unused, unused, unused, unused, windowX, windowY, mask);
- Event event = new Event ();
- event.x = windowX [0];
- event.y = windowY [0];
- setInputState (event, mask [0]);
- postEvent (type, event);
-}
-void sendMouseEvent (int type, int button, XCrossingEvent xEvent) {
- Event event = new Event ();
- event.time = xEvent.time;
- event.button = button;
- event.x = xEvent.x;
- event.y = xEvent.y;
- int [] unused = new int [1], mask = new int [1];
- OS.XQueryPointer (xEvent.display, xEvent.window, unused, unused, unused, unused, unused, unused, mask);
- setInputState (event, mask [0]);
- postEvent (type, event);
-}
-void sendMouseEvent (int type, int button, XInputEvent xEvent) {
- Event event = new Event ();
- event.time = xEvent.time;
- event.button = button;
- event.x = xEvent.x;
- event.y = xEvent.y;
- setInputState (event, xEvent);
- 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) {
- checkWidget();
- if (color == null) {
- setBackgroundPixel (defaultBackground ());
- } else {
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- setBackgroundPixel (color.handle.pixel);
- }
-}
-void setBackgroundPixel (int pixel) {
- int [] argList = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmChangeColor (handle, pixel);
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- int topHandle = topHandle ();
- if (move && resize) {
- int [] argList = {
- OS.XmNx, 0, /* 1 */
- OS.XmNy, 0, /* 3 */
- OS.XmNwidth, 0, /* 5 */
- OS.XmNheight, 0, /* 7 */
- OS.XmNborderWidth, 0, /* 9 */
- };
- OS.XtGetValues (topHandle, argList, argList.length / 2);
- /*
- * Feature in Motif. Motif will not allow a window
- * to have a zero width or zero height. The fix is
- * to ensure these values are never zero.
- */
- width = Math.max (width - (argList [9] * 2), 1);
- height = Math.max (height - (argList [9] * 2), 1);
- boolean sameOrigin = (x == (short) argList [1]) && (y == (short) argList [3]);
- boolean sameExtent = (width == argList [5]) && (height == argList [7]);
- if (sameOrigin && sameExtent) return false;
- OS.XtConfigureWidget (topHandle, x, y, width, height, argList [9]);
- if (!sameOrigin) sendEvent (SWT.Move);
- if (!sameExtent) sendEvent (SWT.Resize);
- return true;
- }
- if (move) {
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0};
- OS.XtGetValues (topHandle, argList, argList.length / 2);
- if (x == (short) argList [1] && y == (short) argList [3]) return false;
- OS.XtMoveWidget (topHandle, x, y);
- sendEvent (SWT.Move);
- return true;
- }
- if (resize) {
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (topHandle, argList, argList.length / 2);
- /*
- * Feature in Motif. Motif will not allow a window
- * to have a zero width or zero height. The fix is
- * to ensure these values are never zero.
- */
- width = Math.max (width - (argList [5] * 2), 1);
- height = Math.max (height - (argList [5] * 2), 1);
- if (width == argList [1] && height == argList [3]) return false;
- OS.XtResizeWidget (topHandle, width, height, argList [5]);
- sendEvent (SWT.Resize);
- return true;
- }
- return false;
-}
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the arguments. The <code>x</code> and
- * <code>y</code> arguments are relative to the receiver's
- * parent (or its display if its parent is null).
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public void setBounds (int x, int y, int width, int height) {
- checkWidget();
- setBounds (x, y, width, height, true, true);
-}
-/**
- * Sets the receiver's size and location to the rectangular
- * area specified by the argument. The <code>x</code> and
- * <code>y</code> fields of the rectangle are relative to
- * the receiver's parent (or its display if its parent is null).
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param rect the new bounds for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public void setBounds (Rectangle rect) {
- checkWidget ();
- if (rect == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (rect.x, rect.y, rect.width, rect.height, true, true);
-}
-/**
- * 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) {
- checkWidget();
- int display = OS.XtDisplay (handle);
- if (display == 0) return;
- if (capture) {
- int window = OS.XtWindow (handle);
- if (window == 0) return;
- OS.XGrabPointer (
- display,
- window,
- 0,
- OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask,
- OS.GrabModeAsync,
- OS.GrabModeAsync,
- OS.None,
- OS.None,
- OS.CurrentTime);
- } else {
- OS.XUngrabPointer (display, OS.CurrentTime);
- }
-}
-/**
- * Sets the receiver's cursor to the cursor specified by the
- * argument, or to the default cursor for that kind of control
- * if the argument is null.
- * <p>
- * When the mouse pointer passes over a control its appearance
- * is changed to match the control's cursor.
- * </p>
- *
- * @param cursor the new cursor (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public void setCursor (Cursor cursor) {
- checkWidget();
- int display = OS.XtDisplay (handle);
- if (display == 0) return;
- int window = OS.XtWindow (handle);
- if (window == 0) {
- if (!OS.XtIsRealized (handle)) getShell ().realizeWidget ();
- window = OS.XtWindow (handle);
- if (window == 0) return;
- }
- if (cursor == null) {
- OS.XUndefineCursor (display, window);
- } else {
- if (cursor.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- int xCursor = cursor.handle;
- OS.XDefineCursor (display, window, xCursor);
- OS.XFlush (display);
- }
-}
-/**
- * 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();
- boolean fixFocus = false;
- if (!enabled) fixFocus = isFocusAncestor ();
- enableWidget (enabled);
- if (fixFocus) fixFocus ();
- if (!enabled || (isEnabled () && enabled)) {
- propagateChildren (enabled);
- }
-}
-/**
- * Causes the receiver to have the <em>keyboard focus</em>,
- * such that all keyboard events will be delivered to it.
- *
- * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #forceFocus
- */ -public boolean setFocus () {
- checkWidget();
- Decorations shell = menuShell ();
- shell.setSavedFocus (this);
- shell.bringToTop (false);
- return XmProcessTraversal (handle, OS.XmTRAVERSE_CURRENT);
-}
-/**
- * Sets the font that the receiver will use to paint textual information
- * to the font specified by the argument, or to the default font for that
- * kind of control if the argument is null.
- *
- * @param font the new font (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public void setFont (Font font) {
- checkWidget();
- if (font == null) font = defaultFont ();
- if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- this.font = font;
-
- /*
- * Feature in Motif. Setting the font in a widget
- * can cause the widget to automatically resize in
- * the OS. This behavior is unwanted. The fix is
- * to force the widget to resize to original size
- * after every font change.
- */
- int [] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
-
- /* Set the font list */
- int fontHandle = fontHandle ();
- int [] argList2 = {OS.XmNfontList, font.handle};
- OS.XtSetValues (fontHandle, argList2, argList2.length / 2);
- if (!hasIMSupport()) {
- OS.XmImSetValues (handle, argList2, argList2.length / 2);
- }
-
- /* Restore the widget size */
- OS.XtSetValues (handle, argList1, argList1.length / 2);
-}
-/**
- * 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) {
- checkWidget();
- if (color == null) {
- setForegroundPixel (defaultForeground ());
- } else {
- if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- setForegroundPixel (color.handle.pixel);
- }
-}
-void setForegroundPixel (int pixel) {
- int [] argList = {OS.XmNforeground, pixel};
- OS.XtSetValues (handle, argList, argList.length / 2);
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- OS.XClearArea (xDisplay, xWindow, 0, 0, 0, 0, true);
-}
-/**
- * Sets the layout data associated with the receiver to the argument.
- *
- * @param layoutData the new layout data for the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public void setLayoutData (Object layoutData) {
- checkWidget();
- this.layoutData = layoutData;
-}
-/**
- * Sets the receiver's location to the point specified by
- * the arguments which are relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param x the new x coordinate for the receiver
- * @param y the new y coordinate for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public void setLocation (int x, int y) {
- checkWidget();
- setBounds (x, y, 0, 0, true, false);
-}
-/**
- * Sets the receiver's location to the point specified by
- * the argument which is relative to the receiver's
- * parent (or its display if its parent is null).
- *
- * @param location the new location for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public void setLocation (Point location) {
- checkWidget ();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (location.x, location.y, 0, 0, true, false);
-}
-/**
- * Sets the receiver's pop up menu to the argument.
- * All controls may optionally have a pop up
- * menu that is displayed when the user requests one for
- * the control. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pop up
- * menu is platform specific.
- *
- * @param menu the new pop up menu
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu</li>
- * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li>
- * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public void setMenu (Menu menu) {
- checkWidget();
- if (menu != null) {
- if (menu.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.POP_UP) == 0) {
- error (SWT.ERROR_MENU_NOT_POP_UP);
- }
- if (menu.parent != menuShell ()) {
- error (SWT.ERROR_INVALID_PARENT);
- }
- }
- this.menu = menu;
-}
-/**
- * Changes the parent of the widget to be the one provided if
- * the underlying operating system supports this feature.
- * 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;
-}
-void setParentTraversal () {
- /*
- * When the parent was created with NO_FOCUS, XmNtraversalOn was
- * set to false disallowing focus in the parent and all children.
- * In order to allow the new child to take focus like other platforms,
- * set XmNtraversalOn to true in the parent.
- */
- if ((parent.style & SWT.NO_FOCUS) != 0) {
- int parentHandle = parent.handle;
- int [] argList = {OS.XmNtraversalOn, 0};
- OS.XtGetValues (parentHandle, argList, argList.length / 2);
- if (argList [1] == 0) {
- argList [1] = 1;
- OS.XtSetValues (parentHandle, argList, argList.length / 2);
- parent.overrideTranslations ();
- }
- }
-}
-boolean setRadioSelection (boolean value) {
- return false;
-}
-/**
- * If the argument is <code>false</code>, causes subsequent drawing
- * operations in the receiver to be ignored. No drawing of any kind
- * can occur in the receiver until the flag is set to true.
- * Graphics operations that occurred while the flag was
- * <code>false</code> are lost. When the flag is set to <code>true</code>,
- * the entire widget is marked as needing to be redrawn.
- * <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) {
- checkWidget();
-}
-boolean setTabGroupFocus () {
- return setTabItemFocus ();
-}
-boolean setTabItemFocus () {
- if (!isShowing ()) return false;
- return setFocus ();
-}
-/**
- * Sets the receiver's size to the point specified by the arguments.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause that
- * value to be set to zero instead.
- * </p>
- *
- * @param width the new width for the receiver
- * @param height the new height for the receiver
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public void setSize (int width, int height) {
- checkWidget();
- setBounds (0, 0, width, height, false, true);
-}
-/**
- * Sets the receiver's size to the point specified by the argument.
- * <p>
- * Note: Attempting to set the width or height of the
- * receiver to a negative number will cause them to be
- * set to zero instead.
- * </p>
- *
- * @param size the new size for the receiver
- * @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) {
- checkWidget();
- if (size == null) error (SWT.ERROR_NULL_ARGUMENT);
- setBounds (0, 0, size.x, size.y, false, true);
-}
-/**
- * Sets the receiver's tool tip text to the argument, which
- * may be null indicating that 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) {
- checkWidget();
- Display display = getDisplay ();
- display.setToolTipText (handle, toolTipText = string);
-}
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public void setVisible (boolean visible) {
- checkWidget();
- int topHandle = topHandle ();
- int [] argList = {OS.XmNmappedWhenManaged, 0};
- OS.XtGetValues (topHandle, argList, argList.length / 2);
- if ((argList [1] != 0) == visible) return;
- boolean fixFocus = false;
- if (!visible) fixFocus = isFocusAncestor ();
- OS.XtSetMappedWhenManaged (topHandle, visible);
- if (fixFocus) fixFocus ();
- sendEvent (visible ? SWT.Show : SWT.Hide);
-}
-void setZOrder (Control control, boolean above) {
- setZOrder (control, above, true);
-}
-void setZOrder (Control control, boolean above, boolean fixChildren) {
- /*
- * Feature in Xt. We cannot use XtMakeGeometryRequest() to
- * restack widgets because this call can fail under certain
- * conditions. For example, XtMakeGeometryRequest() answers
- * XtGeometryNo when attempting to bring a child widget that
- * is larger than the parent widget to the front. The fix
- * is to use X calls instead.
- */
- int topHandle1 = topHandle ();
- int display = OS.XtDisplay (topHandle1);
- if (display == 0) return;
- if (!OS.XtIsRealized (topHandle1)) {
- Shell shell = this.getShell ();
- shell.realizeWidget ();
- }
- int window1 = OS.XtWindow (topHandle1);
- if (window1 == 0) return;
- if (control == null) {
- if (above) {
- OS.XRaiseWindow (display, window1);
- if (fixChildren) parent.moveAbove (topHandle1, 0);
- } else {
- OS.XLowerWindow (display, window1);
- if (fixChildren) parent.moveBelow (topHandle1, 0);
- }
- return;
- }
- int topHandle2 = control.topHandle ();
- if (display != OS.XtDisplay (topHandle2)) return;
- if (!OS.XtIsRealized (topHandle2)) {
- Shell shell = control.getShell ();
- shell.realizeWidget ();
- }
- int window2 = OS.XtWindow (topHandle2);
- if (window2 == 0) return;
- XWindowChanges struct = new XWindowChanges ();
- struct.sibling = window2;
- struct.stack_mode = above ? OS.Above : OS.Below;
- /*
- * Feature in X. If the receiver is a top level, XConfigureWindow ()
- * will fail (with a BadMatch error) for top level shells because top
- * level shells are reparented by the window manager and do not share
- * the same X window parent. This is the correct behavior but it is
- * unexpected. The fix is to use XReconfigureWMWindow () instead.
- * When the receiver is not a top level shell, XReconfigureWMWindow ()
- * behaves the same as XConfigureWindow ().
- */
- int screen = OS.XDefaultScreen (display);
- int flags = OS.CWStackMode | OS.CWSibling;
- OS.XReconfigureWMWindow (display, window1, screen, flags, struct);
- if (above) {
- if (fixChildren) parent.moveAbove (topHandle1, topHandle2);
- } else {
- if (fixChildren) parent.moveBelow (topHandle1, topHandle2);
- }
-} -public Point toControl (int x, int y) {
- checkWidget();
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (handle, (short) 0, (short) 0, root_x, root_y);
- return new Point (x - root_x [0], y - root_y [0]);
-}
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in display relative coordinates,
- * to coordinates relative to the receiver.
- * <p>
- * @param point the point to be translated (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public Point toControl (Point point) {
- checkWidget();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return toControl (point.x, point.y);
-}
-public Point toDisplay (int x, int y) {
- checkWidget();
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (handle, (short) x, (short) y, root_x, root_y);
- return new Point (root_x [0], root_y [0]);
-}
-/**
- * Returns a point which is the result of converting the
- * argument, which is specified in coordinates relative to
- * the receiver, to display relative coordinates.
- * <p>
- * @param point the point to be translated (must not be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the point is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public Point toDisplay (Point point) {
- checkWidget();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- return toDisplay (point.x, point.y);
-}
-boolean translateAccelerator (int key, int keysym, XKeyEvent xEvent) {
- return menuShell ().translateAccelerator (key, keysym, xEvent);
-}
-boolean translateMnemonic (char key, XKeyEvent xEvent) {
- if (!isVisible () || !isEnabled ()) return false;
- Event event = new Event();
- event.doit = mnemonicMatch (key);
- event.detail = SWT.TRAVERSE_MNEMONIC;
- event.time = xEvent.time;
- setKeyState (event, xEvent);
- return traverse (event);
-}
-boolean translateMnemonic (int key, XKeyEvent xEvent) {
- if (xEvent.state == 0) {
- int code = traversalCode (key, xEvent);
- if ((code & SWT.TRAVERSE_MNEMONIC) == 0) return false;
- } else {
- if (xEvent.state != OS.Mod1Mask) return false;
- }
- Decorations shell = menuShell ();
- if (shell.isVisible () && shell.isEnabled ()) {
- char ch = mbcsToWcs (key);
- return ch >= 0x20 && shell.translateMnemonic (ch, xEvent);
- }
- return false;
-}
-boolean translateTraversal (int key, XKeyEvent xEvent) {
- int detail = SWT.TRAVERSE_NONE;
- int code = traversalCode (key, xEvent);
- boolean all = false;
- switch (key) {
- case OS.XK_Escape:
- case OS.XK_Cancel: {
- all = true;
- detail = SWT.TRAVERSE_ESCAPE;
- break;
- }
- case OS.XK_KP_Enter:
- case OS.XK_Return: {
- all = true;
- detail = SWT.TRAVERSE_RETURN;
- break;
- }
- case OS.XK_Tab: {
- boolean next = (xEvent.state & OS.ShiftMask) == 0;
- /*
- * NOTE: This code causes Shift+Tab and Ctrl+Tab to
- * always attempt traversal which is not correct.
- * The default should be the same as a plain Tab key.
- * This behavior is currently relied on by StyledText.
- *
- * The correct behavior is to give every key to any
- * control that wants to see every key. The default
- * behavior for a Canvas should be to see every key.
- */
- switch (xEvent.state) {
- case OS.ControlMask:
- case OS.ShiftMask:
- code |= SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_TAB_NEXT;
- }
- detail = next ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS;
- break;
- }
- case OS.XK_Up:
- case OS.XK_Left:
- case OS.XK_Down:
- case OS.XK_Right: {
- boolean next = key == OS.XK_Down || key == OS.XK_Right;
- detail = next ? SWT.TRAVERSE_ARROW_NEXT : SWT.TRAVERSE_ARROW_PREVIOUS;
- break;
- }
- case OS.XK_Page_Up:
- case OS.XK_Page_Down: {
- all = true;
- if ((xEvent.state & OS.ControlMask) == 0) return false;
- /*
- * NOTE: This code causes Ctrl+PgUp and Ctrl+PgDn to always
- * attempt traversal which is not correct. This behavior is
- * currently relied on by StyledText.
- *
- * The correct behavior is to give every key to any
- * control that wants to see every key. The default
- * behavior for a Canvas should be to see every key.
- */
- code |= SWT.TRAVERSE_PAGE_NEXT | SWT.TRAVERSE_PAGE_PREVIOUS;
- detail = key == OS.XK_Page_Down ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS;
- break;
- }
- default:
- return false;
- }
- Event event = new Event ();
- event.doit = (code & detail) != 0;
- event.detail = detail;
- event.time = xEvent.time;
- setKeyState (event, xEvent);
- Shell shell = getShell ();
- Control control = this;
- do {
- if (control.traverse (event)) return true;
- if (!event.doit && control.hooks (SWT.Traverse)) {
- return false;
- }
- if (control == shell) return false;
- control = control.parent;
- } while (all && control != null);
- return false;
-}
-int traversalCode (int key, XKeyEvent xEvent) {
- int [] argList = new int [] {OS.XmNtraversalOn, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] == 0) return 0;
- int code = SWT.TRAVERSE_RETURN | SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS;
- Shell shell = getShell ();
- if (shell.parent != null) code |= SWT.TRAVERSE_ESCAPE;
- if (getNavigationType () == OS.XmNONE) {
- code |= SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS;
- }
- return code;
-}
-boolean traverse (Event event) {
- sendEvent (SWT.Traverse, event);
- if (isDisposed ()) return 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);
- }
- return false;
-}
-/**
- * Based on the argument, perform one of the expected platform
- * traversal action. The argument should be one of the constants:
- * <code>SWT.TRAVERSE_ESCAPE</code>, <code>SWT.TRAVERSE_RETURN</code>,
- * <code>SWT.TRAVERSE_TAB_NEXT</code>, <code>SWT.TRAVERSE_TAB_PREVIOUS</code>,
- * <code>SWT.TRAVERSE_ARROW_NEXT</code> and <code>SWT.TRAVERSE_ARROW_PREVIOUS</code>.
- *
- * @param traversal the type of traversal
- * @return true if the traversal succeeded
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */ -public boolean traverse (int traversal) {
- checkWidget();
- if (!isFocusControl () && !setFocus ()) return false;
- Event event = new Event ();
- event.doit = true;
- event.detail = traversal;
- return traverse (event);
-}
-boolean traverseEscape () {
- return false;
-}
-boolean traverseGroup (boolean next) {
- Control root = computeTabRoot ();
- Control group = computeTabGroup ();
- Control [] list = root.computeTabList ();
- int length = list.length;
- int index = 0;
- while (index < length) {
- if (list [index] == group) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- if (index == length) return false;
- int start = index, offset = (next) ? 1 : -1;
- while ((index = ((index + offset + length) % length)) != start) {
- Control control = list [index];
- if (!control.isDisposed () && control.setTabGroupFocus ()) {
- if (!isDisposed () && !isFocusControl ()) return true;
- }
- }
- if (group.isDisposed ()) return false;
- return group.setTabGroupFocus ();
-}
-boolean traverseItem (boolean next) {
- Control [] children = parent._getChildren ();
- int length = children.length;
- int index = 0;
- while (index < length) {
- if (children [index] == this) break;
- index++;
- }
- /*
- * It is possible (but unlikely), that application
- * code could have disposed the widget in focus in
- * or out events. Ensure that a disposed widget is
- * not accessed.
- */
- int start = index, offset = (next) ? 1 : -1;
- while ((index = (index + offset + length) % length) != start) {
- Control child = children [index];
- if (!child.isDisposed () && child.isTabItem ()) {
- if (child.setTabItemFocus ()) return true;
- }
- }
- return false;
-}
-boolean traversePage (boolean next) {
- return false;
-}
-boolean traverseMnemonic (char key) {
- return mnemonicHit (key);
-}
-boolean traverseReturn () {
- return false;
-}
-/**
- * Forces all outstanding paint requests for the widget 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();
- update (false);
-}
-void update (boolean all) {
-// checkWidget();
- if (all) {
- Display display = getDisplay ();
- display.update ();
- } else {
- int display = OS.XtDisplay (handle);
- if (display == 0) return;
- int window = OS.XtWindow (handle);
- if (window == 0) return;
- XAnyEvent event = new XAnyEvent ();
- OS.XSync (display, false); OS.XSync (display, false);
- while (OS.XCheckWindowEvent (display, window, OS.ExposureMask, event)) {
- OS.XtDispatchEvent (event);
- }
- }
-}
-int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- Display display = getDisplay ();
- Shell shell = getShell ();
- display.hideToolTip ();
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- sendMouseEvent (SWT.MouseDown, xEvent.button, xEvent);
- if (xEvent.button == 2 && hooks (SWT.DragDetect)) {
- postEvent (SWT.DragDetect);
- }
- if (xEvent.button == 3 && menu != null) {
- setFocus ();
-// menu.setLocation (xEvent.x_root, xEvent.y_root);
- menu.setVisible (true);
- }
- int clickTime = display.getDoubleClickTime ();
- int lastTime = display.lastTime, eventTime = xEvent.time;
- int lastButton = display.lastButton, eventButton = xEvent.button;
- if (lastButton == eventButton && lastTime != 0 && Math.abs (lastTime - eventTime) <= clickTime) {
- sendMouseEvent (SWT.MouseDoubleClick, eventButton, xEvent);
- }
- display.lastTime = eventTime == 0 ? 1 : eventTime;
- display.lastButton = eventButton;
-
- /*
- * It is possible that the shell may be
- * disposed at this point. If this happens
- * don't send the activate and deactivate
- * events.
- */
- if (!shell.isDisposed ()) {
- shell.setActiveControl (this);
- }
- return 0;
-}
-int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- Display display = getDisplay ();
- display.hideToolTip ();
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- sendMouseEvent (SWT.MouseUp, xEvent.button, xEvent);
- return 0;
-}
-int XEnterWindow (int w, int client_data, int call_data, int continue_to_dispatch) {
- XCrossingEvent xEvent = new XCrossingEvent ();
- OS.memmove (xEvent, call_data, XCrossingEvent.sizeof);
- if (xEvent.mode != OS.NotifyNormal) return 0;
- if (xEvent.subwindow != 0) return 0;
- sendMouseEvent (SWT.MouseEnter, 0, xEvent);
- return 0;
-}
-int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) {
- if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0;
- XExposeEvent xEvent = new XExposeEvent ();
- OS.memmove (xEvent, call_data, XExposeEvent.sizeof);
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return 0;
- Event event = new Event ();
- event.count = xEvent.count;
- event.x = xEvent.x; event.y = xEvent.y;
- event.width = xEvent.width; event.height = xEvent.height;
- GC gc = event.gc = new GC (this);
- gc.setClipping (event.x, event.y, event.width, event.height);
- sendEvent (SWT.Paint, event);
- if (!gc.isDisposed ()) gc.dispose ();
- event.gc = null;
- return 0;
-}
-int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatch) {
-
- /* Get the focus change event */
- XFocusChangeEvent xEvent = new XFocusChangeEvent ();
- OS.memmove (xEvent, call_data, XFocusChangeEvent.sizeof);
-
- /* Ignore focus changes caused by grabbing and ungrabing */
- if (xEvent.mode != OS.NotifyNormal) return 0;
-
- /* Only process focus callbacks between windows */
- if (xEvent.detail != OS.NotifyAncestor &&
- xEvent.detail != OS.NotifyInferior &&
- xEvent.detail != OS.NotifyNonlinear) return 0;
-
- /*
- * Ignore focus change events when the window getting or losing
- * focus is a menu. Because XmGetFocusWidget() does not answer
- * the menu shell (it answers the menu parent), it is necessary
- * to use XGetInputFocus() to get the real X focus window.
- */
- int xDisplay = xEvent.display;
- if (xDisplay == 0) return 0;
- int [] unused = new int [1], xWindow = new int [1];
- OS.XGetInputFocus (xDisplay, xWindow, unused);
- if (xWindow [0] != 0) {
- int widget = OS.XtWindowToWidget (xDisplay, xWindow [0]);
- if (widget != 0 && OS.XtClass (widget) == OS.XmMenuShellWidgetClass ()) return 0;
- }
-
- /* Process the focus change for the widget */
- switch (xEvent.type) {
- case OS.FocusIn: {
- Shell shell = getShell ();
- xFocusIn ();
- // widget could be disposed at this point
-
- /*
- * It is possible that the shell may be
- * disposed at this point. If this happens
- * don't send the activate and deactivate
- * events.
- */
- if (!shell.isDisposed ()) {
- shell.setActiveControl (this);
- }
- break;
- }
- case OS.FocusOut: {
- Shell shell = getShell ();
- Display display = getDisplay ();
-
- xFocusOut ();
- // widget could be disposed at this point
-
- /*
- * It is possible that the shell may be
- * disposed at this point. If this happens
- * don't send the activate and deactivate
- * events.
- */
- if (!shell.isDisposed ()) {
- Control control = display.getFocusControl ();
- if (control == null || shell != control.getShell () ) {
- shell.setActiveControl (null);
- }
- }
- break;
- }
- }
- return 0;
-}
-int xFocusIn () {
- sendEvent (SWT.FocusIn);
- // widget could be disposed at this point
- if (handle == 0) return 0;
- if (!hasIMSupport()) {
- if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) {
- short [] point = getIMCaretPos ();
- int ptr = OS.XtMalloc (4);
- OS.memmove (ptr, point, 4);
- /*
- * Bug in Motif. On Linux Japanese only, XmImSetFocusValues() causes
- * a GP when the XmNfontList resources does not containt a FontSet.
- * The fix is to call XmImSetValues() to set the values and then call
- * XmImSetFocusValues() with no parameters to set the IME focus.
- */
- int[] argList = {
-// OS.XmNforeground, getForegroundPixel(),
-// OS.XmNbackground, getBackgroundPixel(),
- OS.XmNspotLocation, ptr,
- OS.XmNfontList, font.handle,
- };
- OS.XmImSetValues (handle, argList, argList.length / 2);
- OS.XmImSetFocusValues (handle, null, 0);
- if (ptr != 0) OS.XtFree (ptr);
- }
- }
- return 0;
-}
-int xFocusOut () {
- Display display = getDisplay ();
- if (display.postFocusOut) {
- postEvent (SWT.FocusOut);
- } else {
- sendEvent (SWT.FocusOut);
- // widget could be disposed at this point
- if (handle == 0) return 0;
- }
- if (!hasIMSupport()) {
- if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) {
- OS.XmImUnsetFocus (handle);
- }
- }
- return 0;
-}
-int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- XKeyEvent xEvent = new XKeyEvent ();
- OS.memmove (xEvent, call_data, XKeyEvent.sizeof);
- if (xEvent.keycode != 0) {
- sendKeyEvent (SWT.KeyDown, xEvent);
- } else {
- sendIMKeyEvent (SWT.KeyDown, xEvent);
- }
- return 0;
-}
-int XKeyRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- XKeyEvent xEvent = new XKeyEvent ();
- OS.memmove (xEvent, call_data, XKeyEvent.sizeof);
- if (menu != null && xEvent.state == OS.ShiftMask) {
- byte [] buffer = new byte [1];
- int [] keysym = new int [1];
- OS.XLookupString (xEvent, buffer, buffer.length, keysym, null);
- if (keysym [0] == OS.XK_F10) {
- menu.setVisible (true);
- return 0;
- }
- }
- sendKeyEvent (SWT.KeyUp, xEvent);
- return 0;
-}
-int XLeaveWindow (int w, int client_data, int call_data, int continue_to_dispatch) {
- Display display = getDisplay ();
- display.removeMouseHoverTimeOut ();
- display.hideToolTip ();
- XCrossingEvent xEvent = new XCrossingEvent ();
- OS.memmove (xEvent, call_data, XCrossingEvent.sizeof);
- if (xEvent.mode != OS.NotifyNormal) return 0;
- if (xEvent.subwindow != 0) return 0;
- sendMouseEvent (SWT.MouseExit, 0, xEvent);
- return 0;
-}
-int XmNhelpCallback (int w, int client_data, int call_data) {
- sendHelpEvent (call_data);
- return 0;
-}
-int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) {
- Display display = getDisplay ();
- display.addMouseHoverTimeOut (handle);
- XMotionEvent xEvent = new XMotionEvent ();
- OS.memmove (xEvent, call_data, XMotionEvent.sizeof);
- sendMouseEvent (SWT.MouseMove, 0, xEvent);
- return 0;
-}
+public Accessible getAccessible () { + checkWidget (); + if (accessible == null) { + accessible = Accessible.internal_new_Accessible (this); + } + return accessible; +} + +/** + * 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.motif_new (getDisplay (), getXColor (getBackgroundPixel ())); +} +int getBackgroundPixel () { + int [] argList = {OS.XmNbackground, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns the receiver's border width. + * + * @return the border width + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public int getBorderWidth () { + checkWidget(); + int topHandle = topHandle (); + int [] argList = {OS.XmNborderWidth, 0}; + OS.XtGetValues (topHandle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns a rectangle describing the receiver's size and location + * relative to its parent (or its display if its parent is null). + * + * @return the receiver's bounding rectangle + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public Rectangle getBounds () { + checkWidget(); + int topHandle = topHandle (); + int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; + OS.XtGetValues (topHandle, argList, argList.length / 2); + int borders = argList [9] * 2; + return new Rectangle ((short) argList [1], (short) argList [3], argList [5] + borders, argList [7] + borders); +} +Point getClientLocation () { + short [] handle_x = new short [1], handle_y = new short [1]; + OS.XtTranslateCoords (handle, (short) 0, (short) 0, handle_x, handle_y); + short [] topHandle_x = new short [1], topHandle_y = new short [1]; + OS.XtTranslateCoords (parent.handle, (short) 0, (short) 0, topHandle_x, topHandle_y); + return new Point (handle_x [0] - topHandle_x [0], handle_y [0] - topHandle_y [0]); +} +String getCodePage () { + return font.codePage; +} +/** + * Returns the 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 () { + Composite 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 () { + checkWidget(); + int [] argList = {OS.XmNsensitive, 0}; + OS.XtGetValues (topHandle (), argList, argList.length / 2); + return argList [1] != 0; +} +/** + * Returns the font that the receiver will use to paint textual information. + * + * @return the receiver's font + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public Font getFont () { + checkWidget(); + return font; +} + +int getFontAscent () { + + /* Create a font context to iterate over each element in the font list */ + int [] buffer = new int [1]; + if (!OS.XmFontListInitFontContext (buffer, font.handle)) { + error (SWT.ERROR_NO_HANDLES); + } + int context = buffer [0]; + + /* Values discovering during iteration */ + int ascent = 0; + XFontStruct fontStruct = new XFontStruct (); + int fontListEntry; + int [] fontStructPtr = new int [1]; + int [] fontNamePtr = new int [1]; + + /* Go through each entry in the font list. */ + while ((fontListEntry = OS.XmFontListNextEntry (context)) != 0) { + int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer); + if (buffer [0] == 0) { + /* FontList contains a single font */ + OS.memmove (fontStruct, fontPtr, XFontStruct.sizeof); + int fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent); + if (fontAscent > ascent) ascent = fontAscent; + } else { + /* FontList contains a fontSet */ + int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr); + int [] fontStructs = new int [nFonts]; + OS.memmove (fontStructs, fontStructPtr [0], nFonts * 4); + + /* Go through each fontStruct in the font set */ + for (int i=0; i<nFonts; i++) { + OS.memmove (fontStruct, fontStructs[i], XFontStruct.sizeof); + int fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent); + if (fontAscent > ascent) ascent = fontAscent; + } + } + } + + OS.XmFontListFreeFontContext (context); + return ascent; +} + +int getFontHeight () { + + /* Create a font context to iterate over each element in the font list */ + int [] buffer = new int [1]; + if (!OS.XmFontListInitFontContext (buffer, font.handle)) { + error (SWT.ERROR_NO_HANDLES); + } + int context = buffer [0]; + + /* Values discovering during iteration */ + int height = 0; + XFontStruct fontStruct = new XFontStruct (); + int fontListEntry; + int [] fontStructPtr = new int [1]; + int [] fontNamePtr = new int [1]; + + /* Go through each entry in the font list. */ + while ((fontListEntry = OS.XmFontListNextEntry (context)) != 0) { + int fontPtr = OS.XmFontListEntryGetFont (fontListEntry, buffer); + if (buffer [0] == 0) { + /* FontList contains a single font */ + OS.memmove (fontStruct, fontPtr, XFontStruct.sizeof); + int fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent); + int fontDescent = Math.max (fontStruct.descent, fontStruct.max_bounds_descent); + int fontHeight = fontAscent + fontDescent; + if (fontHeight > height) height = fontHeight; + } else { + /* FontList contains a fontSet */ + int nFonts = OS.XFontsOfFontSet (fontPtr, fontStructPtr, fontNamePtr); + int [] fontStructs = new int [nFonts]; + OS.memmove (fontStructs, fontStructPtr [0], nFonts * 4); + + /* Go through each fontStruct in the font set */ + for (int i=0; i<nFonts; i++) { + OS.memmove (fontStruct, fontStructs[i], XFontStruct.sizeof); + int fontAscent = Math.max (fontStruct.ascent, fontStruct.max_bounds_ascent); + int fontDescent = Math.max (fontStruct.descent, fontStruct.max_bounds_descent); + int fontHeight = fontAscent + fontDescent; + if (fontHeight > height) height = fontHeight; + } + } + } + + OS.XmFontListFreeFontContext (context); + return height; +} +//int getFontList () { +// int fontHandle = fontHandle (); +// int [] argList = {OS.XmNfontList, 0}; +// OS.XtGetValues (fontHandle, argList, argList.length / 2); +// if (argList [1] != 0) return argList [1]; +// if (fontList == 0) fontList = defaultFont (); +// return fontList; +//} +/** + * Returns the foreground color that the receiver will use to draw. + * + * @return the receiver's foreground color + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public Color getForeground () { + checkWidget(); + return Color.motif_new (getDisplay (), getXColor (getForegroundPixel ())); +} +int getForegroundPixel () { + int [] argList = {OS.XmNforeground, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +short [] getIMCaretPos () { + return new short[]{0, 0}; +} +/** + * Returns layout data which is associated with the receiver. + * + * @return the receiver's layout data + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public Object getLayoutData () { + checkWidget(); + return layoutData; +} +/** + * Returns a point describing the receiver's location relative + * to its parent (or its display if its parent is null). + * + * @return the receiver's location + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public Point getLocation () { + checkWidget(); + int topHandle = topHandle (); + int [] argList = {OS.XmNx, 0, OS.XmNy, 0}; + OS.XtGetValues (topHandle, argList, argList.length / 2); + return new Point ((short) argList [1], (short) argList [3]); +} +/** + * Returns the receiver's pop up menu if it has one, or null + * if it does not. All controls may optionally have a pop up + * menu that is displayed when the user requests one for + * the control. The sequence of key strokes, button presses + * and/or button releases that are used to request a pop up + * menu is platform specific. + * + * @return the receiver's menu + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public Menu getMenu () { + checkWidget(); + return menu; +} +int getNavigationType () { + int [] argList = {OS.XmNnavigationType, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns the receiver's parent, which must be a <code>Composite</code> + * or null when the receiver is a shell that was created with null or + * a display for a parent. + * + * @return the receiver's parent + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public Composite getParent () { + checkWidget(); + return parent; +} +Control [] getPath () { + int count = 0; + Shell shell = getShell (); + Control control = this; + while (control != shell) { + count++; + control = control.parent; + } + control = this; + Control [] result = new Control [count]; + while (control != shell) { + result [--count] = control; + control = control.parent; + } + return result; +} +/** + * Returns the receiver's shell. For all controls other than + * shells, this simply returns the control's nearest ancestor + * shell. Shells return themselves, even if they are children + * of other shells. + * + * @return the receiver's shell + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #getParent + */ +public Shell getShell () { + checkWidget(); + return parent.getShell (); +} +/** + * Returns a point describing the receiver's size. The + * x coordinate of the result is the width of the receiver. + * The y coordinate of the result is the height of the + * receiver. + * + * @return the receiver's size + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public Point getSize () { + checkWidget(); + int topHandle = topHandle (); + int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; + OS.XtGetValues (topHandle, argList, argList.length / 2); + int borders = argList [5] * 2; + return new Point (argList [1] + borders, argList [3] + borders); +} +/** + * Returns the receiver's tool tip text, or null if it has + * not been set. + * + * @return the receiver's tool tip text + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public String getToolTipText () { + checkWidget(); + return toolTipText; +} +/** + * Returns <code>true</code> if the receiver is visible, and + * <code>false</code> otherwise. + * <p> + * If one of the receiver's ancestors is not visible or some + * other condition makes the receiver not visible, this method + * may still indicate that it is considered visible even though + * it may not actually be showing. + * </p> + * + * @return the receiver's visibility state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public boolean getVisible () { + checkWidget(); + int topHandle = topHandle (); + int [] argList = {OS.XmNmappedWhenManaged, 0}; + OS.XtGetValues (topHandle, argList, argList.length / 2); + return argList [1] != 0; +} +XColor getXColor (int pixel) { + int display = OS.XtDisplay (handle); + if (display == 0) return null; + int [] argList = {OS.XmNcolormap, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int colormap = argList [1]; + if (colormap == 0) return null; + XColor color = new XColor (); + color.pixel = pixel; + OS.XQueryColor (display, colormap, color); + return color; +} +boolean hasFocus () { + return this == getDisplay ().getFocusControl (); +} +/** + * Returns true if the widget has native IM support + */ +boolean hasIMSupport() { + return false; +} +void hookEvents () { + int windowProc = getDisplay ().windowProc; + OS.XtAddEventHandler (handle, OS.KeyPressMask, false, windowProc, KEY_PRESS); + OS.XtAddEventHandler (handle, OS.KeyReleaseMask, false, windowProc, KEY_RELEASE); + OS.XtAddEventHandler (handle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS); + OS.XtAddEventHandler (handle, OS.ButtonReleaseMask, false, windowProc, BUTTON_RELEASE); + OS.XtAddEventHandler (handle, OS.PointerMotionMask, false, windowProc, POINTER_MOTION); + OS.XtAddEventHandler (handle, OS.EnterWindowMask, false, windowProc, ENTER_WINDOW); + OS.XtAddEventHandler (handle, OS.LeaveWindowMask, false, windowProc, LEAVE_WINDOW); + OS.XtInsertEventHandler (handle, OS.ExposureMask, false, windowProc, EXPOSURE, OS.XtListTail); + OS.XtInsertEventHandler (handle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail); + OS.XtAddCallback (handle, OS.XmNhelpCallback, windowProc, HELP_CALLBACK); +} +int hoverProc (int id) { + return hoverProc (id, true); +} +int hoverProc (int id, boolean showTip) { + Display display = getDisplay (); + if (showTip) display.showToolTip (handle, toolTipText); + sendMouseEvent (SWT.MouseHover, 0); + return 0; +} +/** + * Invokes platform specific functionality to allocate a new GC handle. + * <p> + * <b>IMPORTANT:</b> This method is <em>not</em> part of the public + * API for <code>Control</code>. It is marked public only so that it + * can be shared within the packages provided by SWT. It is not + * available on all platforms, and should never be called from + * application code. + * </p> + * + * @param data the platform specific GC data + * @return the platform specific GC handle + * + * @private + */ +public int internal_new_GC (GCData data) { + checkWidget(); + if (!OS.XtIsRealized (handle)) { + Shell shell = getShell (); + shell.realizeWidget (); + } + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) SWT.error(SWT.ERROR_NO_HANDLES); + int xWindow = OS.XtWindow (handle); + if (xWindow == 0) SWT.error(SWT.ERROR_NO_HANDLES); + int xGC = OS.XCreateGC (xDisplay, xWindow, 0, null); + if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES); + OS.XSetGraphicsExposures (xDisplay, xGC, false); + int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNcolormap, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (data != null) { + data.device = getDisplay (); + data.display = xDisplay; + data.drawable = xWindow; + data.foreground = argList [1]; + data.background = argList [3]; + data.fontList = font.handle; + data.codePage = font.codePage; + data.colormap = argList [5]; + } + return xGC; +} +/** + * Invokes platform specific functionality to dispose a GC handle. + * <p> + * <b>IMPORTANT:</b> This method is <em>not</em> part of the public + * API for <code>Control</code>. It is marked public only so that it + * can be shared within the packages provided by SWT. It is not + * available on all platforms, and should never be called from + * application code. + * </p> + * + * @param handle the platform specific GC handle + * @param data the platform specific GC data + * + * @private + */ +public void internal_dispose_GC (int xGC, GCData data) { + checkWidget (); + int xDisplay = 0; + if (data != null) xDisplay = data.display; + if (xDisplay == 0 && handle != 0) xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) SWT.error(SWT.ERROR_NO_HANDLES); + OS.XFreeGC (xDisplay, xGC); +} +/** + * Returns <code>true</code> if the receiver is enabled and all + * of the receiver's ancestors are enabled, and <code>false</code> + * otherwise. A disabled control is typically not selectable from the + * user interface and draws with an inactive or "grayed" look. + * + * @return the receiver's enabled state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #getEnabled + */ +public boolean isEnabled () { + checkWidget(); + return getEnabled () && parent.isEnabled (); +} +boolean isFocusAncestor () { + Display display = getDisplay (); + Control control = display.getFocusControl (); + while (control != null && control != this) { + control = control.parent; + } + return control == this; +} +/** + * Returns <code>true</code> if the receiver has the user-interface + * focus, and <code>false</code> otherwise. + * + * @return the receiver's focus state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public boolean isFocusControl () { + checkWidget(); + return hasFocus (); +} +/** + * Returns <code>true</code> if the underlying operating + * system supports this reparenting, otherwise <code>false</code> + * + * @return <code>true</code> if the widget can be reparented, otherwise <code>false</code> + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public boolean isReparentable () { + checkWidget(); + return false; +} +boolean isShowing () { + /* + * This is not complete. Need to check if the + * widget is obscurred by a parent or sibling. + */ + if (!isVisible ()) return false; + Control control = this; + while (control != null) { + Point size = control.getSize (); + if (size.x == 1 || size.y == 1) { + return false; + } + control = control.parent; + } + return true; +} +boolean isTabGroup () { + Control [] tabList = parent._getTabList (); + if (tabList != null) { + for (int i=0; i<tabList.length; i++) { + if (tabList [i] == this) return true; + } + } + int code = traversalCode (0, null); + if ((code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) != 0) return false; + return (code & (SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_TAB_NEXT)) != 0; +} +boolean isTabItem () { + Control [] tabList = parent._getTabList (); + if (tabList != null) { + for (int i=0; i<tabList.length; i++) { + if (tabList [i] == this) return false; + } + } + int code = traversalCode (0, null); + return (code & (SWT.TRAVERSE_ARROW_PREVIOUS | SWT.TRAVERSE_ARROW_NEXT)) != 0; +} +/** + * Returns <code>true</code> if the receiver is visible and all + * of the receiver's ancestors are visible and <code>false</code> + * otherwise. + * + * @return the receiver's visibility state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #getVisible + */ +public boolean isVisible () { + checkWidget(); + return getVisible () && parent.isVisible (); +} +void manageChildren () { + OS.XtSetMappedWhenManaged (handle, false); + /* + * Feature in Motif. When a widget is managed and an + * ancestor in the widget hierarchy has focus, Motif + * assigns focus to another widget in the shell. This + * happens because Motif does not expect a non-leaf + * widget to have the focus. The fix is to save the + * current value of XmNtraversalOn, set the new value + * to false, then manage the widget and restore the + * value. This relies on the fact that Motif will + * not reassign focus when the new widget is not + * traversable. + * + * NOTE: This code currently does not work when a + * sibling will take focus. + */ + int topHandle = topHandle (); + int [] argList1 = {OS.XmNtraversalOn, 0}; + OS.XtGetValues (topHandle, argList1, argList1.length / 2); + if (argList1 [1] != 0) { + int [] argList2 = {OS.XmNtraversalOn, 0}; + OS.XtSetValues (topHandle, argList2, argList2.length / 2); + } + OS.XtManageChild (handle); + if (argList1 [1] != 0) { + OS.XtSetValues (topHandle, argList1, argList1.length / 2); + } + overrideTranslations (); + int [] argList3 = {OS.XmNborderWidth, 0}; + OS.XtGetValues (handle, argList3, argList3.length / 2); + OS.XtResizeWidget (handle, 1, 1, argList3 [1]); + OS.XtSetMappedWhenManaged (handle, true); +} +Decorations menuShell () { + return parent.menuShell (); +} +boolean mnemonicHit (char key) { + return false; +} +boolean mnemonicMatch (char key) { + return false; +} +/** + * Moves the receiver above the specified control in the + * drawing order. If the argument is null, then the receiver + * is moved to the top of the drawing order. The control at + * the top of the drawing order will not be covered by other + * controls even if they occupy intersecting areas. + * + * @param 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(); + if (control != null) { + if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT); + if (parent != control.parent) return; + } + setZOrder (control, true); +} +/** + * Moves the receiver below the specified control in the + * drawing order. If the argument is null, then the receiver + * is moved to the bottom of the drawing order. The control at + * the bottom of the drawing order will be covered by all other + * controls which occupy intersecting areas. + * + * @param 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(); + if (control != null) { + if (control.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT); + if (parent != control.parent) return; + } + setZOrder (control, false); +} +void overrideTranslations () { + Display display = getDisplay (); + OS.XtOverrideTranslations (handle, display.tabTranslations); + OS.XtOverrideTranslations (handle, display.arrowTranslations); +} +/** + * Causes the receiver to be resized to its preferred size. + * For a composite, this involves computing the preferred size + * from its layout, if there is one. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #computeSize + */ +public void pack () { + checkWidget(); + pack (true); +} +/** + * Causes the receiver to be resized to its preferred size. + * For a composite, this involves computing the preferred size + * from its layout, if there is one. + * <p> + * If the changed flag is <code>true</code>, it indicates that the receiver's + * <em>contents</em> have changed, therefore any caches that a layout manager + * containing the control may have been keeping need to be flushed. When the + * control is resized, the changed flag will be <code>false</code>, so layout + * manager caches can be retained. + * </p> + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if 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)); +} +void propagateChildren (boolean enabled) { + propagateWidget (enabled); +} +void propagateWidget (boolean enabled) { + propagateHandle (enabled, handle); +} +void realizeChildren () { + if (!isEnabled ()) propagateWidget (false); +} +/** + * 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 () { + checkWidget(); + redrawWidget (0, 0, 0, 0, false); +} +/** + * Causes the rectangular area of the receiver specified by + * the arguments to be marked as needing to be redrawn. + * The next time a paint request is processed, that area of + * the receiver will be painted. 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) { + checkWidget (); + if (width <= 0 || height <= 0) return; + redrawWidget (x, y, width, height, all); +} +void redrawWidget (int x, int y, int width, int height, boolean all) { + redrawHandle (x, y, width, height, handle); +} +void releaseWidget () { + /* + * Restore the default font for the widget in case the + * application disposes the widget font in the dispose + * callback. If a font is disposed while it is still + * in use in the widget, Motif GP's. + */ + int fontList = defaultFont ().handle; + if (font.handle != fontList) { + int fontHandle = fontHandle (); + int [] argList2 = {OS.XmNfontList, fontList}; + OS.XtSetValues (fontHandle, argList2, argList2.length / 2); + } + super.releaseWidget (); + Display display = getDisplay (); + display.releaseToolTipHandle (handle); + toolTipText = null; + if (menu != null && !menu.isDisposed ()) { + menu.dispose (); + } + menu = null; + if (!hasIMSupport()) { + OS.XmImUnregister (handle); + } + parent = null; + layoutData = 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) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook (SWT.Move, listener); + eventTable.unhook (SWT.Resize, listener); +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the control 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) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook(SWT.FocusIn, listener); + eventTable.unhook(SWT.FocusOut, listener); +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the help events are generated for the control. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see HelpListener + * @see #addHelpListener + */ +public void removeHelpListener (HelpListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook (SWT.Help, listener); +} +/** + * Removes the listener from the collection of listeners who will + * be notified when keys are pressed and released on the system keyboard. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see KeyListener + * @see #addKeyListener + */ +public void removeKeyListener(KeyListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook(SWT.KeyUp, listener); + eventTable.unhook(SWT.KeyDown, listener); +} +/** + * Removes the listener from the collection of listeners who will + * be notified when 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) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook(SWT.MouseDown, listener); + eventTable.unhook(SWT.MouseUp, listener); + eventTable.unhook(SWT.MouseDoubleClick, listener); +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the mouse moves. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see MouseMoveListener + * @see #addMouseMoveListener + */ +public void removeMouseMoveListener(MouseMoveListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook(SWT.MouseMove, listener); +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the mouse passes or hovers over controls. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see MouseTrackListener + * @see #addMouseTrackListener + */ +public void removeMouseTrackListener(MouseTrackListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook (SWT.MouseEnter, listener); + eventTable.unhook (SWT.MouseExit, listener); + eventTable.unhook (SWT.MouseHover, listener); +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the 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) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook(SWT.Paint, listener); +}/** + * Removes the listener from the collection of listeners who will + * be notified when traversal events occur. + * + * @param listener the listener which should 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); +} +void sendHelpEvent (int callData) { + Control control = this; + while (control != null) { + if (control.hooks (SWT.Help)) { + control.postEvent (SWT.Help); + return; + } + control = control.parent; + } +} +byte [] sendIMKeyEvent (int type, XKeyEvent xEvent) { + /* + * Bug in Motif. On Linux only, XmImMbLookupString () does not return + * XBufferOverflow as the status if the buffer is too small. The fix + * is to pass a large buffer. + */ + byte [] buffer = new byte [512]; + int [] status = new int [1], unused = new int [1]; + int length = OS.XmImMbLookupString (handle, xEvent, buffer, buffer.length, unused, status); + if (status [0] == OS.XBufferOverflow) { + buffer = new byte [length]; + length = OS.XmImMbLookupString (handle, xEvent, buffer, length, unused, status); + } + if (length == 0) return null; + + /* Convert from MBCS to UNICODE and send the event */ + /* Use the character encoding for the default locale */ + char [] result = Converter.mbcsToWcs (null, buffer); + int index = 0; + while (index < result.length) { + if (result [index] == 0) break; + Event event = new Event (); + event.time = xEvent.time; + event.character = result [index]; + setInputState (event, xEvent); + postEvent (type, event); + index++; + } + return buffer; +} +void sendKeyEvent (int type, XKeyEvent xEvent) { + Event event = new Event (); + event.time = xEvent.time; + setKeyState (event, xEvent); + Control control = this; + if ((state & CANVAS) != 0) { + if ((style & SWT.NO_FOCUS) != 0) { + Display display = getDisplay (); + control = display.getFocusControl (); + } + } + if (control != null) { + control.postEvent (type, event); + } +} +void sendMouseEvent (int type, int button) { + int xDisplay = OS.XtDisplay (handle); + int xWindow = OS.XtWindow (handle); + int [] windowX = new int [1], windowY = new int [1], mask = new int [1], unused = new int [1]; + OS.XQueryPointer (xDisplay, xWindow, unused, unused, unused, unused, windowX, windowY, mask); + Event event = new Event (); + event.x = windowX [0]; + event.y = windowY [0]; + setInputState (event, mask [0]); + postEvent (type, event); +} +void sendMouseEvent (int type, int button, XCrossingEvent xEvent) { + Event event = new Event (); + event.time = xEvent.time; + event.button = button; + event.x = xEvent.x; + event.y = xEvent.y; + int [] unused = new int [1], mask = new int [1]; + OS.XQueryPointer (xEvent.display, xEvent.window, unused, unused, unused, unused, unused, unused, mask); + setInputState (event, mask [0]); + postEvent (type, event); +} +void sendMouseEvent (int type, int button, XInputEvent xEvent) { + Event event = new Event (); + event.time = xEvent.time; + event.button = button; + event.x = xEvent.x; + event.y = xEvent.y; + setInputState (event, xEvent); + 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) { + checkWidget(); + if (color == null) { + setBackgroundPixel (defaultBackground ()); + } else { + if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + setBackgroundPixel (color.handle.pixel); + } +} +void setBackgroundPixel (int pixel) { + int [] argList = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + OS.XmChangeColor (handle, pixel); + OS.XtSetValues (handle, argList, argList.length / 2); +} +boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { + int topHandle = topHandle (); + if (move && resize) { + int [] argList = { + OS.XmNx, 0, /* 1 */ + OS.XmNy, 0, /* 3 */ + OS.XmNwidth, 0, /* 5 */ + OS.XmNheight, 0, /* 7 */ + OS.XmNborderWidth, 0, /* 9 */ + }; + OS.XtGetValues (topHandle, argList, argList.length / 2); + /* + * Feature in Motif. Motif will not allow a window + * to have a zero width or zero height. The fix is + * to ensure these values are never zero. + */ + width = Math.max (width - (argList [9] * 2), 1); + height = Math.max (height - (argList [9] * 2), 1); + boolean sameOrigin = (x == (short) argList [1]) && (y == (short) argList [3]); + boolean sameExtent = (width == argList [5]) && (height == argList [7]); + if (sameOrigin && sameExtent) return false; + OS.XtConfigureWidget (topHandle, x, y, width, height, argList [9]); + if (!sameOrigin) sendEvent (SWT.Move); + if (!sameExtent) sendEvent (SWT.Resize); + return true; + } + if (move) { + int [] argList = {OS.XmNx, 0, OS.XmNy, 0}; + OS.XtGetValues (topHandle, argList, argList.length / 2); + if (x == (short) argList [1] && y == (short) argList [3]) return false; + OS.XtMoveWidget (topHandle, x, y); + sendEvent (SWT.Move); + return true; + } + if (resize) { + int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; + OS.XtGetValues (topHandle, argList, argList.length / 2); + /* + * Feature in Motif. Motif will not allow a window + * to have a zero width or zero height. The fix is + * to ensure these values are never zero. + */ + width = Math.max (width - (argList [5] * 2), 1); + height = Math.max (height - (argList [5] * 2), 1); + if (width == argList [1] && height == argList [3]) return false; + OS.XtResizeWidget (topHandle, width, height, argList [5]); + sendEvent (SWT.Resize); + return true; + } + return false; +} +/** + * Sets the receiver's size and location to the rectangular + * area specified by the arguments. The <code>x</code> and + * <code>y</code> arguments are relative to the receiver's + * parent (or its display if its parent is null). + * <p> + * Note: Attempting to set the width or height of the + * receiver to a negative number will cause that + * value to be set to zero instead. + * </p> + * + * @param x the new x coordinate for the receiver + * @param y the new y coordinate for the receiver + * @param width the new width for the receiver + * @param height the new height for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setBounds (int x, int y, int width, int height) { + checkWidget(); + setBounds (x, y, width, height, true, true); +} +/** + * Sets the receiver's size and location to the rectangular + * area specified by the argument. The <code>x</code> and + * <code>y</code> fields of the rectangle are relative to + * the receiver's parent (or its display if its parent is null). + * <p> + * Note: Attempting to set the width or height of the + * receiver to a negative number will cause that + * value to be set to zero instead. + * </p> + * + * @param rect the new bounds for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setBounds (Rectangle rect) { + checkWidget (); + if (rect == null) error (SWT.ERROR_NULL_ARGUMENT); + setBounds (rect.x, rect.y, rect.width, rect.height, true, true); +} +/** + * 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) { + checkWidget(); + int display = OS.XtDisplay (handle); + if (display == 0) return; + if (capture) { + int window = OS.XtWindow (handle); + if (window == 0) return; + OS.XGrabPointer ( + display, + window, + 0, + OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask, + OS.GrabModeAsync, + OS.GrabModeAsync, + OS.None, + OS.None, + OS.CurrentTime); + } else { + OS.XUngrabPointer (display, OS.CurrentTime); + } +} +/** + * Sets the receiver's cursor to the cursor specified by the + * argument, or to the default cursor for that kind of control + * if the argument is null. + * <p> + * When the mouse pointer passes over a control its appearance + * is changed to match the control's cursor. + * </p> + * + * @param cursor the new cursor (or null) + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setCursor (Cursor cursor) { + checkWidget(); + int display = OS.XtDisplay (handle); + if (display == 0) return; + int window = OS.XtWindow (handle); + if (window == 0) { + if (!OS.XtIsRealized (handle)) getShell ().realizeWidget (); + window = OS.XtWindow (handle); + if (window == 0) return; + } + if (cursor == null) { + OS.XUndefineCursor (display, window); + } else { + if (cursor.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + int xCursor = cursor.handle; + OS.XDefineCursor (display, window, xCursor); + OS.XFlush (display); + } +} +/** + * 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(); + boolean fixFocus = false; + if (!enabled) fixFocus = isFocusAncestor (); + enableWidget (enabled); + if (fixFocus) fixFocus (); + if (!enabled || (isEnabled () && enabled)) { + propagateChildren (enabled); + } +} +/** + * Causes the receiver to have the <em>keyboard focus</em>, + * such that all keyboard events will be delivered to it. + * + * @return <code>true</code> if the control got focus, and <code>false</code> if it was unable to. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #forceFocus + */ +public boolean setFocus () { + checkWidget(); + Decorations shell = menuShell (); + shell.setSavedFocus (this); + shell.bringToTop (false); + return XmProcessTraversal (handle, OS.XmTRAVERSE_CURRENT); +} +/** + * Sets the font that the receiver will use to paint textual information + * to the font specified by the argument, or to the default font for that + * kind of control if the argument is null. + * + * @param font the new font (or null) + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setFont (Font font) { + checkWidget(); + if (font == null) font = defaultFont (); + if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + this.font = font; + + /* + * Feature in Motif. Setting the font in a widget + * can cause the widget to automatically resize in + * the OS. This behavior is unwanted. The fix is + * to force the widget to resize to original size + * after every font change. + */ + int [] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; + OS.XtGetValues (handle, argList1, argList1.length / 2); + + /* Set the font list */ + int fontHandle = fontHandle (); + int [] argList2 = {OS.XmNfontList, font.handle}; + OS.XtSetValues (fontHandle, argList2, argList2.length / 2); + if (!hasIMSupport()) { + OS.XmImSetValues (handle, argList2, argList2.length / 2); + } + + /* Restore the widget size */ + OS.XtSetValues (handle, argList1, argList1.length / 2); +} +/** + * 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) { + checkWidget(); + if (color == null) { + setForegroundPixel (defaultForeground ()); + } else { + if (color.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + setForegroundPixel (color.handle.pixel); + } +} +void setForegroundPixel (int pixel) { + int [] argList = {OS.XmNforeground, pixel}; + OS.XtSetValues (handle, argList, argList.length / 2); + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return; + int xWindow = OS.XtWindow (handle); + if (xWindow == 0) return; + OS.XClearArea (xDisplay, xWindow, 0, 0, 0, 0, true); +} +/** + * Sets the layout data associated with the receiver to the argument. + * + * @param layoutData the new layout data for the receiver. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setLayoutData (Object layoutData) { + checkWidget(); + this.layoutData = layoutData; +} +/** + * Sets the receiver's location to the point specified by + * the arguments which are relative to the receiver's + * parent (or its display if its parent is null). + * + * @param x the new x coordinate for the receiver + * @param y the new y coordinate for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setLocation (int x, int y) { + checkWidget(); + setBounds (x, y, 0, 0, true, false); +} +/** + * Sets the receiver's location to the point specified by + * the argument which is relative to the receiver's + * parent (or its display if its parent is null). + * + * @param location the new location for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setLocation (Point location) { + checkWidget (); + if (location == null) error (SWT.ERROR_NULL_ARGUMENT); + setBounds (location.x, location.y, 0, 0, true, false); +} +/** + * Sets the receiver's pop up menu to the argument. + * All controls may optionally have a pop up + * menu that is displayed when the user requests one for + * the control. The sequence of key strokes, button presses + * and/or button releases that are used to request a pop up + * menu is platform specific. + * + * @param menu the new pop up menu + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_MENU_NOT_POP_UP - the menu is not a pop up menu</li> + * <li>ERROR_INVALID_PARENT - if the menu is not in the same widget tree</li> + * <li>ERROR_INVALID_ARGUMENT - if the menu has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setMenu (Menu menu) { + checkWidget(); + if (menu != null) { + if (menu.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); + if ((menu.style & SWT.POP_UP) == 0) { + error (SWT.ERROR_MENU_NOT_POP_UP); + } + if (menu.parent != menuShell ()) { + error (SWT.ERROR_INVALID_PARENT); + } + } + this.menu = menu; +} +/** + * Changes the parent of the widget to be the one provided if + * the underlying operating system supports this feature. + * 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; +} +void setParentTraversal () { + /* + * When the parent was created with NO_FOCUS, XmNtraversalOn was + * set to false disallowing focus in the parent and all children. + * In order to allow the new child to take focus like other platforms, + * set XmNtraversalOn to true in the parent. + */ + if ((parent.style & SWT.NO_FOCUS) != 0) { + int parentHandle = parent.handle; + int [] argList = {OS.XmNtraversalOn, 0}; + OS.XtGetValues (parentHandle, argList, argList.length / 2); + if (argList [1] == 0) { + argList [1] = 1; + OS.XtSetValues (parentHandle, argList, argList.length / 2); + parent.overrideTranslations (); + } + } +} +boolean setRadioSelection (boolean value) { + return false; +} +/** + * If the argument is <code>false</code>, causes subsequent drawing + * operations in the receiver to be ignored. No drawing of any kind + * can occur in the receiver until the flag is set to true. + * Graphics operations that occurred while the flag was + * <code>false</code> are lost. When the flag is set to <code>true</code>, + * the entire widget is marked as needing to be redrawn. + * <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) { + checkWidget(); +} +boolean setTabGroupFocus () { + return setTabItemFocus (); +} +boolean setTabItemFocus () { + if (!isShowing ()) return false; + return setFocus (); +} +/** + * Sets the receiver's size to the point specified by the arguments. + * <p> + * Note: Attempting to set the width or height of the + * receiver to a negative number will cause that + * value to be set to zero instead. + * </p> + * + * @param width the new width for the receiver + * @param height the new height for the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setSize (int width, int height) { + checkWidget(); + setBounds (0, 0, width, height, false, true); +} +/** + * Sets the receiver's size to the point specified by the argument. + * <p> + * Note: Attempting to set the width or height of the + * receiver to a negative number will cause them to be + * set to zero instead. + * </p> + * + * @param size the new size for the receiver + * @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) { + checkWidget(); + if (size == null) error (SWT.ERROR_NULL_ARGUMENT); + setBounds (0, 0, size.x, size.y, false, true); +} +/** + * Sets the receiver's tool tip text to the argument, which + * may be null indicating that 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) { + checkWidget(); + Display display = getDisplay (); + display.setToolTipText (handle, toolTipText = string); +} +/** + * Marks the receiver as visible if the argument is <code>true</code>, + * and marks it invisible otherwise. + * <p> + * If one of the receiver's ancestors is not visible or some + * other condition makes the receiver not visible, marking + * it visible may not actually cause it to be displayed. + * </p> + * + * @param visible the new visibility state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setVisible (boolean visible) { + checkWidget(); + int topHandle = topHandle (); + int [] argList = {OS.XmNmappedWhenManaged, 0}; + OS.XtGetValues (topHandle, argList, argList.length / 2); + if ((argList [1] != 0) == visible) return; + boolean fixFocus = false; + if (!visible) fixFocus = isFocusAncestor (); + OS.XtSetMappedWhenManaged (topHandle, visible); + if (fixFocus) fixFocus (); + sendEvent (visible ? SWT.Show : SWT.Hide); +} +void setZOrder (Control control, boolean above) { + setZOrder (control, above, true); +} +void setZOrder (Control control, boolean above, boolean fixChildren) { + /* + * Feature in Xt. We cannot use XtMakeGeometryRequest() to + * restack widgets because this call can fail under certain + * conditions. For example, XtMakeGeometryRequest() answers + * XtGeometryNo when attempting to bring a child widget that + * is larger than the parent widget to the front. The fix + * is to use X calls instead. + */ + int topHandle1 = topHandle (); + int display = OS.XtDisplay (topHandle1); + if (display == 0) return; + if (!OS.XtIsRealized (topHandle1)) { + Shell shell = this.getShell (); + shell.realizeWidget (); + } + int window1 = OS.XtWindow (topHandle1); + if (window1 == 0) return; + if (control == null) { + if (above) { + OS.XRaiseWindow (display, window1); + if (fixChildren) parent.moveAbove (topHandle1, 0); + } else { + OS.XLowerWindow (display, window1); + if (fixChildren) parent.moveBelow (topHandle1, 0); + } + return; + } + int topHandle2 = control.topHandle (); + if (display != OS.XtDisplay (topHandle2)) return; + if (!OS.XtIsRealized (topHandle2)) { + Shell shell = control.getShell (); + shell.realizeWidget (); + } + int window2 = OS.XtWindow (topHandle2); + if (window2 == 0) return; + XWindowChanges struct = new XWindowChanges (); + struct.sibling = window2; + struct.stack_mode = above ? OS.Above : OS.Below; + /* + * Feature in X. If the receiver is a top level, XConfigureWindow () + * will fail (with a BadMatch error) for top level shells because top + * level shells are reparented by the window manager and do not share + * the same X window parent. This is the correct behavior but it is + * unexpected. The fix is to use XReconfigureWMWindow () instead. + * When the receiver is not a top level shell, XReconfigureWMWindow () + * behaves the same as XConfigureWindow (). + */ + int screen = OS.XDefaultScreen (display); + int flags = OS.CWStackMode | OS.CWSibling; + OS.XReconfigureWMWindow (display, window1, screen, flags, struct); + if (above) { + if (fixChildren) parent.moveAbove (topHandle1, topHandle2); + } else { + if (fixChildren) parent.moveBelow (topHandle1, topHandle2); + } +} +public Point toControl (int x, int y) { + checkWidget(); + short [] root_x = new short [1], root_y = new short [1]; + OS.XtTranslateCoords (handle, (short) 0, (short) 0, root_x, root_y); + return new Point (x - root_x [0], y - root_y [0]); +} +/** + * Returns a point which is the result of converting the + * argument, which is specified in display relative coordinates, + * to coordinates relative to the receiver. + * <p> + * @param point the point to be translated (must not be null) + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the point is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public Point toControl (Point point) { + checkWidget(); + if (point == null) error (SWT.ERROR_NULL_ARGUMENT); + return toControl (point.x, point.y); +} +public Point toDisplay (int x, int y) { + checkWidget(); + short [] root_x = new short [1], root_y = new short [1]; + OS.XtTranslateCoords (handle, (short) x, (short) y, root_x, root_y); + return new Point (root_x [0], root_y [0]); +} +/** + * Returns a point which is the result of converting the + * argument, which is specified in coordinates relative to + * the receiver, to display relative coordinates. + * <p> + * @param point the point to be translated (must not be null) + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the point is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public Point toDisplay (Point point) { + checkWidget(); + if (point == null) error (SWT.ERROR_NULL_ARGUMENT); + return toDisplay (point.x, point.y); +} +boolean translateAccelerator (int key, int keysym, XKeyEvent xEvent) { + return menuShell ().translateAccelerator (key, keysym, xEvent); +} +boolean translateMnemonic (char key, XKeyEvent xEvent) { + if (!isVisible () || !isEnabled ()) return false; + Event event = new Event(); + event.doit = mnemonicMatch (key); + event.detail = SWT.TRAVERSE_MNEMONIC; + event.time = xEvent.time; + setKeyState (event, xEvent); + return traverse (event); +} +boolean translateMnemonic (int key, XKeyEvent xEvent) { + if (xEvent.state == 0) { + int code = traversalCode (key, xEvent); + if ((code & SWT.TRAVERSE_MNEMONIC) == 0) return false; + } else { + if (xEvent.state != OS.Mod1Mask) return false; + } + Decorations shell = menuShell (); + if (shell.isVisible () && shell.isEnabled ()) { + char ch = mbcsToWcs (key); + return ch >= 0x20 && shell.translateMnemonic (ch, xEvent); + } + return false; +} +boolean translateTraversal (int key, XKeyEvent xEvent) { + int detail = SWT.TRAVERSE_NONE; + int code = traversalCode (key, xEvent); + boolean all = false; + switch (key) { + case OS.XK_Escape: + case OS.XK_Cancel: { + all = true; + detail = SWT.TRAVERSE_ESCAPE; + break; + } + case OS.XK_KP_Enter: + case OS.XK_Return: { + all = true; + detail = SWT.TRAVERSE_RETURN; + break; + } + case OS.XK_Tab: { + boolean next = (xEvent.state & OS.ShiftMask) == 0; + /* + * NOTE: This code causes Shift+Tab and Ctrl+Tab to + * always attempt traversal which is not correct. + * The default should be the same as a plain Tab key. + * This behavior is currently relied on by StyledText. + * + * The correct behavior is to give every key to any + * control that wants to see every key. The default + * behavior for a Canvas should be to see every key. + */ + switch (xEvent.state) { + case OS.ControlMask: + case OS.ShiftMask: + code |= SWT.TRAVERSE_TAB_PREVIOUS | SWT.TRAVERSE_TAB_NEXT; + } + detail = next ? SWT.TRAVERSE_TAB_NEXT : SWT.TRAVERSE_TAB_PREVIOUS; + break; + } + case OS.XK_Up: + case OS.XK_Left: + case OS.XK_Down: + case OS.XK_Right: { + boolean next = key == OS.XK_Down || key == OS.XK_Right; + detail = next ? SWT.TRAVERSE_ARROW_NEXT : SWT.TRAVERSE_ARROW_PREVIOUS; + break; + } + case OS.XK_Page_Up: + case OS.XK_Page_Down: { + all = true; + if ((xEvent.state & OS.ControlMask) == 0) return false; + /* + * NOTE: This code causes Ctrl+PgUp and Ctrl+PgDn to always + * attempt traversal which is not correct. This behavior is + * currently relied on by StyledText. + * + * The correct behavior is to give every key to any + * control that wants to see every key. The default + * behavior for a Canvas should be to see every key. + */ + code |= SWT.TRAVERSE_PAGE_NEXT | SWT.TRAVERSE_PAGE_PREVIOUS; + detail = key == OS.XK_Page_Down ? SWT.TRAVERSE_PAGE_NEXT : SWT.TRAVERSE_PAGE_PREVIOUS; + break; + } + default: + return false; + } + Event event = new Event (); + event.doit = (code & detail) != 0; + event.detail = detail; + event.time = xEvent.time; + setKeyState (event, xEvent); + Shell shell = getShell (); + Control control = this; + do { + if (control.traverse (event)) return true; + if (!event.doit && control.hooks (SWT.Traverse)) { + return false; + } + if (control == shell) return false; + control = control.parent; + } while (all && control != null); + return false; +} +int traversalCode (int key, XKeyEvent xEvent) { + int [] argList = new int [] {OS.XmNtraversalOn, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (argList [1] == 0) return 0; + int code = SWT.TRAVERSE_RETURN | SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS; + Shell shell = getShell (); + if (shell.parent != null) code |= SWT.TRAVERSE_ESCAPE; + if (getNavigationType () == OS.XmNONE) { + code |= SWT.TRAVERSE_ARROW_NEXT | SWT.TRAVERSE_ARROW_PREVIOUS; + } + return code; +} +boolean traverse (Event event) { + sendEvent (SWT.Traverse, event); + if (isDisposed ()) return 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); + } + return false; +} +/** + * Based on the argument, perform one of the expected platform + * traversal action. The argument should be one of the constants: + * <code>SWT.TRAVERSE_ESCAPE</code>, <code>SWT.TRAVERSE_RETURN</code>, + * <code>SWT.TRAVERSE_TAB_NEXT</code>, <code>SWT.TRAVERSE_TAB_PREVIOUS</code>, + * <code>SWT.TRAVERSE_ARROW_NEXT</code> and <code>SWT.TRAVERSE_ARROW_PREVIOUS</code>. + * + * @param traversal the type of traversal + * @return true if the traversal succeeded + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public boolean traverse (int traversal) { + checkWidget(); + if (!isFocusControl () && !setFocus ()) return false; + Event event = new Event (); + event.doit = true; + event.detail = traversal; + return traverse (event); +} +boolean traverseEscape () { + return false; +} +boolean traverseGroup (boolean next) { + Control root = computeTabRoot (); + Control group = computeTabGroup (); + Control [] list = root.computeTabList (); + int length = list.length; + int index = 0; + while (index < length) { + if (list [index] == group) break; + index++; + } + /* + * It is possible (but unlikely), that application + * code could have disposed the widget in focus in + * or out events. Ensure that a disposed widget is + * not accessed. + */ + if (index == length) return false; + int start = index, offset = (next) ? 1 : -1; + while ((index = ((index + offset + length) % length)) != start) { + Control control = list [index]; + if (!control.isDisposed () && control.setTabGroupFocus ()) { + if (!isDisposed () && !isFocusControl ()) return true; + } + } + if (group.isDisposed ()) return false; + return group.setTabGroupFocus (); +} +boolean traverseItem (boolean next) { + Control [] children = parent._getChildren (); + int length = children.length; + int index = 0; + while (index < length) { + if (children [index] == this) break; + index++; + } + /* + * It is possible (but unlikely), that application + * code could have disposed the widget in focus in + * or out events. Ensure that a disposed widget is + * not accessed. + */ + int start = index, offset = (next) ? 1 : -1; + while ((index = (index + offset + length) % length) != start) { + Control child = children [index]; + if (!child.isDisposed () && child.isTabItem ()) { + if (child.setTabItemFocus ()) return true; + } + } + return false; +} +boolean traversePage (boolean next) { + return false; +} +boolean traverseMnemonic (char key) { + return mnemonicHit (key); +} +boolean traverseReturn () { + return false; +} +/** + * Forces all outstanding paint requests for the widget 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(); + update (false); +} +void update (boolean all) { +// checkWidget(); + if (all) { + Display display = getDisplay (); + display.update (); + } else { + int display = OS.XtDisplay (handle); + if (display == 0) return; + int window = OS.XtWindow (handle); + if (window == 0) return; + XAnyEvent event = new XAnyEvent (); + OS.XSync (display, false); OS.XSync (display, false); + while (OS.XCheckWindowEvent (display, window, OS.ExposureMask, event)) { + OS.XtDispatchEvent (event); + } + } +} +int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) { + Display display = getDisplay (); + Shell shell = getShell (); + display.hideToolTip (); + XButtonEvent xEvent = new XButtonEvent (); + OS.memmove (xEvent, call_data, XButtonEvent.sizeof); + sendMouseEvent (SWT.MouseDown, xEvent.button, xEvent); + if (xEvent.button == 2 && hooks (SWT.DragDetect)) { + postEvent (SWT.DragDetect); + } + if (xEvent.button == 3 && menu != null) { + setFocus (); +// menu.setLocation (xEvent.x_root, xEvent.y_root); + menu.setVisible (true); + } + int clickTime = display.getDoubleClickTime (); + int lastTime = display.lastTime, eventTime = xEvent.time; + int lastButton = display.lastButton, eventButton = xEvent.button; + if (lastButton == eventButton && lastTime != 0 && Math.abs (lastTime - eventTime) <= clickTime) { + sendMouseEvent (SWT.MouseDoubleClick, eventButton, xEvent); + } + display.lastTime = eventTime == 0 ? 1 : eventTime; + display.lastButton = eventButton; + + /* + * It is possible that the shell may be + * disposed at this point. If this happens + * don't send the activate and deactivate + * events. + */ + if (!shell.isDisposed ()) { + shell.setActiveControl (this); + } + return 0; +} +int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) { + Display display = getDisplay (); + display.hideToolTip (); + XButtonEvent xEvent = new XButtonEvent (); + OS.memmove (xEvent, call_data, XButtonEvent.sizeof); + sendMouseEvent (SWT.MouseUp, xEvent.button, xEvent); + return 0; +} +int XEnterWindow (int w, int client_data, int call_data, int continue_to_dispatch) { + XCrossingEvent xEvent = new XCrossingEvent (); + OS.memmove (xEvent, call_data, XCrossingEvent.sizeof); + if (xEvent.mode != OS.NotifyNormal) return 0; + if (xEvent.subwindow != 0) return 0; + sendMouseEvent (SWT.MouseEnter, 0, xEvent); + return 0; +} +int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) { + if (!hooks (SWT.Paint) && !filters (SWT.Paint)) return 0; + XExposeEvent xEvent = new XExposeEvent (); + OS.memmove (xEvent, call_data, XExposeEvent.sizeof); + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return 0; + Event event = new Event (); + event.count = xEvent.count; + event.x = xEvent.x; event.y = xEvent.y; + event.width = xEvent.width; event.height = xEvent.height; + GC gc = event.gc = new GC (this); + gc.setClipping (event.x, event.y, event.width, event.height); + sendEvent (SWT.Paint, event); + if (!gc.isDisposed ()) gc.dispose (); + event.gc = null; + return 0; +} +int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatch) { + + /* Get the focus change event */ + XFocusChangeEvent xEvent = new XFocusChangeEvent (); + OS.memmove (xEvent, call_data, XFocusChangeEvent.sizeof); + + /* Ignore focus changes caused by grabbing and ungrabing */ + if (xEvent.mode != OS.NotifyNormal) return 0; + + /* Only process focus callbacks between windows */ + if (xEvent.detail != OS.NotifyAncestor && + xEvent.detail != OS.NotifyInferior && + xEvent.detail != OS.NotifyNonlinear) return 0; + + /* + * Ignore focus change events when the window getting or losing + * focus is a menu. Because XmGetFocusWidget() does not answer + * the menu shell (it answers the menu parent), it is necessary + * to use XGetInputFocus() to get the real X focus window. + */ + int xDisplay = xEvent.display; + if (xDisplay == 0) return 0; + int [] unused = new int [1], xWindow = new int [1]; + OS.XGetInputFocus (xDisplay, xWindow, unused); + if (xWindow [0] != 0) { + int widget = OS.XtWindowToWidget (xDisplay, xWindow [0]); + if (widget != 0 && OS.XtClass (widget) == OS.XmMenuShellWidgetClass ()) return 0; + } + + /* Process the focus change for the widget */ + switch (xEvent.type) { + case OS.FocusIn: { + Shell shell = getShell (); + xFocusIn (); + // widget could be disposed at this point + + /* + * It is possible that the shell may be + * disposed at this point. If this happens + * don't send the activate and deactivate + * events. + */ + if (!shell.isDisposed ()) { + shell.setActiveControl (this); + } + break; + } + case OS.FocusOut: { + Shell shell = getShell (); + Display display = getDisplay (); + + xFocusOut (); + // widget could be disposed at this point + + /* + * It is possible that the shell may be + * disposed at this point. If this happens + * don't send the activate and deactivate + * events. + */ + if (!shell.isDisposed ()) { + Control control = display.getFocusControl (); + if (control == null || shell != control.getShell () ) { + shell.setActiveControl (null); + } + } + break; + } + } + return 0; +} +int xFocusIn () { + sendEvent (SWT.FocusIn); + // widget could be disposed at this point + if (handle == 0) return 0; + if (!hasIMSupport()) { + if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) { + short [] point = getIMCaretPos (); + int ptr = OS.XtMalloc (4); + OS.memmove (ptr, point, 4); + /* + * Bug in Motif. On Linux Japanese only, XmImSetFocusValues() causes + * a GP when the XmNfontList resources does not containt a FontSet. + * The fix is to call XmImSetValues() to set the values and then call + * XmImSetFocusValues() with no parameters to set the IME focus. + */ + int[] argList = { +// OS.XmNforeground, getForegroundPixel(), +// OS.XmNbackground, getBackgroundPixel(), + OS.XmNspotLocation, ptr, + OS.XmNfontList, font.handle, + }; + OS.XmImSetValues (handle, argList, argList.length / 2); + OS.XmImSetFocusValues (handle, null, 0); + if (ptr != 0) OS.XtFree (ptr); + } + } + return 0; +} +int xFocusOut () { + Display display = getDisplay (); + if (display.postFocusOut) { + postEvent (SWT.FocusOut); + } else { + sendEvent (SWT.FocusOut); + // widget could be disposed at this point + if (handle == 0) return 0; + } + if (!hasIMSupport()) { + if (hooks (SWT.KeyDown) || hooks (SWT.KeyUp)) { + OS.XmImUnsetFocus (handle); + } + } + return 0; +} +int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) { + XKeyEvent xEvent = new XKeyEvent (); + OS.memmove (xEvent, call_data, XKeyEvent.sizeof); + if (xEvent.keycode != 0) { + sendKeyEvent (SWT.KeyDown, xEvent); + } else { + sendIMKeyEvent (SWT.KeyDown, xEvent); + } + return 0; +} +int XKeyRelease (int w, int client_data, int call_data, int continue_to_dispatch) { + XKeyEvent xEvent = new XKeyEvent (); + OS.memmove (xEvent, call_data, XKeyEvent.sizeof); + if (menu != null && xEvent.state == OS.ShiftMask) { + byte [] buffer = new byte [1]; + int [] keysym = new int [1]; + OS.XLookupString (xEvent, buffer, buffer.length, keysym, null); + if (keysym [0] == OS.XK_F10) { + menu.setVisible (true); + return 0; + } + } + sendKeyEvent (SWT.KeyUp, xEvent); + return 0; +} +int XLeaveWindow (int w, int client_data, int call_data, int continue_to_dispatch) { + Display display = getDisplay (); + display.removeMouseHoverTimeOut (); + display.hideToolTip (); + XCrossingEvent xEvent = new XCrossingEvent (); + OS.memmove (xEvent, call_data, XCrossingEvent.sizeof); + if (xEvent.mode != OS.NotifyNormal) return 0; + if (xEvent.subwindow != 0) return 0; + sendMouseEvent (SWT.MouseExit, 0, xEvent); + return 0; +} +int XmNhelpCallback (int w, int client_data, int call_data) { + sendHelpEvent (call_data); + return 0; +} +int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) { + Display display = getDisplay (); + display.addMouseHoverTimeOut (handle); + XMotionEvent xEvent = new XMotionEvent (); + OS.memmove (xEvent, call_data, XMotionEvent.sizeof); + sendMouseEvent (SWT.MouseMove, 0, xEvent); + return 0; +} }
\ No newline at end of file diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java index 74a4f6e6df..820b62cbe8 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Decorations.java @@ -1,16 +1,16 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; + /** * Instances of this class provide the appearance and * behavior of <code>Shells</code>, but are not top @@ -83,18 +83,18 @@ import org.eclipse.swt.graphics.*; * @see Shell * @see SWT */ -public class Decorations extends Canvas {
- String label;
- Image image;
- int dialogHandle;
- boolean minimized, maximized;
- Menu menuBar;
- Menu [] menus;
- Control savedFocus;
- Button defaultButton, saveDefault;
-Decorations () {
- /* Do nothing */
-}
+public class Decorations extends Canvas { + String label; + Image image; + int dialogHandle; + boolean minimized, maximized; + Menu menuBar; + Menu [] menus; + Control savedFocus; + Button defaultButton, saveDefault; +Decorations () { + /* Do nothing */ +} /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -133,352 +133,352 @@ Decorations () { * @see Widget#checkSubclass * @see Widget#getStyle */ -public Decorations (Composite parent, int style) {
- super (parent, checkStyle (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 bringToTop (boolean force) {
- moveAbove (null);
-}
-static int checkStyle (int style) {
- if ((style & (SWT.MENU | SWT.MIN | SWT.MAX | SWT.CLOSE)) != 0) {
- style |= SWT.TITLE;
- }
- return style;
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-
-Control computeTabGroup () {
- return this;
-}
-
-Control computeTabRoot () {
- return this;
-}
-
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- Rectangle trim = super.computeTrim (x, y, width, height);
- if (menuBar != null) {
- XtWidgetGeometry request = new XtWidgetGeometry ();
- XtWidgetGeometry result = new XtWidgetGeometry ();
- request.request_mode = OS.CWWidth;
- request.width = trim.width;
- OS.XtQueryGeometry (menuBar.handle, request, result);
- trim.height += result.height;
- }
- return trim;
-}
-void createHandle (int index) {
- state |= HANDLE | CANVAS;
- createScrolledHandle (parent.handle);
-}
-void createWidget (int index) {
- super.createWidget (index);
- label = "";
-}
-int dialogHandle () {
- if (dialogHandle != 0) return dialogHandle;
- return dialogHandle = OS.XmCreateDialogShell (handle, null, null, 0);
-}
-/**
- * Returns the receiver's default button if one had
- * previously been set, otherwise returns null.
- *
- * @return the default button or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setDefaultButton
+public Decorations (Composite parent, int style) { + super (parent, checkStyle (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 bringToTop (boolean force) { + moveAbove (null); +} +static int checkStyle (int style) { + if ((style & (SWT.MENU | SWT.MIN | SWT.MAX | SWT.CLOSE)) != 0) { + style |= SWT.TITLE; + } + return style; +} +protected void checkSubclass () { + if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); +} + +Control computeTabGroup () { + return this; +} + +Control computeTabRoot () { + return this; +} + +public Rectangle computeTrim (int x, int y, int width, int height) { + checkWidget(); + Rectangle trim = super.computeTrim (x, y, width, height); + if (menuBar != null) { + XtWidgetGeometry request = new XtWidgetGeometry (); + XtWidgetGeometry result = new XtWidgetGeometry (); + request.request_mode = OS.CWWidth; + request.width = trim.width; + OS.XtQueryGeometry (menuBar.handle, request, result); + trim.height += result.height; + } + return trim; +} +void createHandle (int index) { + state |= HANDLE | CANVAS; + createScrolledHandle (parent.handle); +} +void createWidget (int index) { + super.createWidget (index); + label = ""; +} +int dialogHandle () { + if (dialogHandle != 0) return dialogHandle; + return dialogHandle = OS.XmCreateDialogShell (handle, null, null, 0); +} +/** + * Returns the receiver's default button if one had + * previously been set, otherwise returns null. + * + * @return the default button or null + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #setDefaultButton */ -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 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 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 maximized;
-}
-/**
- * Returns the receiver's menu bar if one had previously
- * been set, otherwise returns null.
- *
- * @return the menu bar or null
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public boolean getMaximized () { + checkWidget(); + return maximized; +} +/** + * Returns the receiver's menu bar if one had previously + * been set, otherwise returns null. + * + * @return the menu bar or null + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public Menu getMenuBar () {
- checkWidget();
- return menuBar;
-}
-/**
- * Returns <code>true</code> if the receiver is currently
- * minimized, and false otherwise.
- * <p>
- *
- * @return the minimized state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setMinimized
+public Menu getMenuBar () { + checkWidget(); + return menuBar; +} +/** + * Returns <code>true</code> if the receiver is currently + * minimized, and false otherwise. + * <p> + * + * @return the minimized state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #setMinimized */ -public boolean getMinimized () {
- checkWidget();
- return minimized;
-}
-String getNameText () {
- return getText ();
-}
-/**
- * Returns the receiver's text, which is the string that the
- * window manager will typically display as the receiver's
- * <em>title</em>. If the text has not previously been set,
- * returns an empty string.
- *
- * @return the text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public boolean getMinimized () { + checkWidget(); + return minimized; +} +String getNameText () { + return getText (); +} +/** + * Returns the receiver's text, which is the string that the + * window manager will typically display as the receiver's + * <em>title</em>. If the text has not previously been set, + * returns an empty string. + * + * @return the text + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public String getText () {
- checkWidget();
- return label;
-}
-boolean isTabGroup () {
- return true;
-}
-boolean isTabItem () {
- return false;
-}
-Decorations menuShell () {
- return this;
-}
-void propagateWidget (boolean enabled) {
- super.propagateWidget (enabled);
- int [] argList = {OS.XmNmenuBar, 0};
- OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
- if (argList [1] != 0) propagateHandle (enabled, argList [1]);
-}
-void releaseHandle () {
- super.releaseHandle ();
- dialogHandle = 0;
-}
-void releaseWidget () {
- if (menus != null) {
- for (int i=0; i<menus.length; i++) {
- Menu menu = menus [i];
- if (menu != null && !menu.isDisposed ()) menu.releaseResources ();
- }
- }
- menuBar = null;
- menus = null;
- super.releaseWidget ();
- defaultButton = saveDefault = null;
- label = null;
-}
-boolean restoreFocus () {
- if (savedFocus != null && savedFocus.isDisposed ()) savedFocus = null;
- boolean restored = savedFocus != null && savedFocus.setFocus ();
- savedFocus = null;
- /*
- * This code is intentionally commented. When no widget
- * has been given focus, some platforms give focus to the
- * default button. Motif doesn't do this.
- */
-// if (restored) return true;
-// if (defaultButton != null && !defaultButton.isDisposed ()) {
-// if (defaultButton.setFocus ()) return true;
-// }
-// return false;
- return restored;
-}
-void remove (Menu menu) {
- if (menus == null) return;
- for (int i=0; i<menus.length; i++) {
- if (menus [i] == menu) {
- menus [i] = null;
- return;
- }
- }
-}
-/**
- * If the argument is not null, sets the receiver's default
- * button to the argument, and if the argument is null, sets
- * the receiver's default button to the first button which
- * was set as the receiver's default button (called the
- * <em>saved default button</em>). If no default button had
- * previously been set, or the saved default button was
- * disposed, the receiver's default button will be set to
- * null.
- *
- * @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 String getText () { + checkWidget(); + return label; +} +boolean isTabGroup () { + return true; +} +boolean isTabItem () { + return false; +} +Decorations menuShell () { + return this; +} +void propagateWidget (boolean enabled) { + super.propagateWidget (enabled); + int [] argList = {OS.XmNmenuBar, 0}; + OS.XtGetValues (scrolledHandle, argList, argList.length / 2); + if (argList [1] != 0) propagateHandle (enabled, argList [1]); +} +void releaseHandle () { + super.releaseHandle (); + dialogHandle = 0; +} +void releaseWidget () { + if (menus != null) { + for (int i=0; i<menus.length; i++) { + Menu menu = menus [i]; + if (menu != null && !menu.isDisposed ()) menu.releaseResources (); + } + } + menuBar = null; + menus = null; + super.releaseWidget (); + defaultButton = saveDefault = null; + label = null; +} +boolean restoreFocus () { + if (savedFocus != null && savedFocus.isDisposed ()) savedFocus = null; + boolean restored = savedFocus != null && savedFocus.setFocus (); + savedFocus = null; + /* + * This code is intentionally commented. When no widget + * has been given focus, some platforms give focus to the + * default button. Motif doesn't do this. + */ +// if (restored) return true; +// if (defaultButton != null && !defaultButton.isDisposed ()) { +// if (defaultButton.setFocus ()) return true; +// } +// return false; + return restored; +} +void remove (Menu menu) { + if (menus == null) return; + for (int i=0; i<menus.length; i++) { + if (menus [i] == menu) { + menus [i] = null; + return; + } + } +} +/** + * If the argument is not null, sets the receiver's default + * button to the argument, and if the argument is null, sets + * the receiver's default button to the first button which + * was set as the receiver's default button (called the + * <em>saved default button</em>). If no default button had + * previously been set, or the saved default button was + * disposed, the receiver's default button will be set to + * null. + * + * @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();
- setDefaultButton (button, true);
-}
-void setDefaultButton (Button button, boolean save) {
- if (button == null) {
- if (defaultButton == saveDefault) {
- if (save) saveDefault = null;
- return;
- }
- } else {
- if (button.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((button.style & SWT.PUSH) == 0) return;
- if (button == defaultButton) return;
- }
- if (defaultButton != null) {
- if (!defaultButton.isDisposed ()) defaultButton.setDefault (false);
- }
- if ((defaultButton = button) == null) defaultButton = saveDefault;
- if (defaultButton != null) {
- if (!defaultButton.isDisposed ()) defaultButton.setDefault (true);
- }
- if (save) saveDefault = defaultButton;
- if (saveDefault != null && saveDefault.isDisposed ()) saveDefault = null;
-}
-/**
- * Sets the receiver's image to the argument, which may
- * be null. The image is typically displayed by the window
- * manager when the instance is marked as iconified, and
- * may also be displayed somewhere in the trim when the
- * instance is in normal or maximized states.
- *
- * @param image the new image (or null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void setDefaultButton (Button button) { + checkWidget(); + setDefaultButton (button, true); +} +void setDefaultButton (Button button, boolean save) { + if (button == null) { + if (defaultButton == saveDefault) { + if (save) saveDefault = null; + return; + } + } else { + if (button.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); + if ((button.style & SWT.PUSH) == 0) return; + if (button == defaultButton) return; + } + if (defaultButton != null) { + if (!defaultButton.isDisposed ()) defaultButton.setDefault (false); + } + if ((defaultButton = button) == null) defaultButton = saveDefault; + if (defaultButton != null) { + if (!defaultButton.isDisposed ()) defaultButton.setDefault (true); + } + if (save) saveDefault = defaultButton; + if (saveDefault != null && saveDefault.isDisposed ()) saveDefault = null; +} +/** + * Sets the receiver's image to the argument, which may + * be null. The image is typically displayed by the window + * manager when the instance is marked as iconified, and + * may also be displayed somewhere in the trim when the + * instance is in normal or maximized states. + * + * @param image the new image (or null) + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setImage (Image image) {
- checkWidget();
- int pixmap = 0, mask = 0;
- if (image != null) {
- if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- switch (image.type) {
- case SWT.BITMAP:
- pixmap = image.pixmap;
- break;
- case SWT.ICON:
- pixmap = image.pixmap;
- mask = image.mask;
- break;
- default:
- error (SWT.ERROR_INVALID_IMAGE);
- }
- }
- this.image = image;
- int [] argList = {
- OS.XmNiconPixmap, pixmap,
- OS.XmNiconMask, mask,
- };
- int topHandle = topHandle ();
- OS.XtSetValues (topHandle, argList, argList.length / 2);
-}
-/**
- * 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 setImage (Image image) { + checkWidget(); + int pixmap = 0, mask = 0; + if (image != null) { + if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); + switch (image.type) { + case SWT.BITMAP: + pixmap = image.pixmap; + break; + case SWT.ICON: + pixmap = image.pixmap; + mask = image.mask; + break; + default: + error (SWT.ERROR_INVALID_IMAGE); + } + } + this.image = image; + int [] argList = { + OS.XmNiconPixmap, pixmap, + OS.XmNiconMask, mask, + }; + int topHandle = topHandle (); + OS.XtSetValues (topHandle, argList, argList.length / 2); +} +/** + * 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();
- this.maximized = maximized;
-}
+public void setMaximized (boolean maximized) { + checkWidget(); + this.maximized = maximized; +} /** * Sets the receiver's menu bar to the argument, which * may be null. @@ -494,207 +494,207 @@ public void setMaximized (boolean maximized) { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setMenuBar (Menu menu) {
- checkWidget();
- if (menuBar == menu) return;
- if (menu != null) {
- if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR);
- if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT);
- }
-
- /* Ensure the new menu bar is correctly enabled */
- if (menuBar != null) {
- if (!isEnabled () && menuBar.getEnabled ()) {
- propagateHandle (true, menuBar.handle);
- }
- menuBar.removeAccelerators ();
- }
- if (menu != null) {
- if (!isEnabled ()) {
- propagateHandle (false, menu.handle);
- }
- menu.addAccelerators ();
- }
-
- /* Save the old client area */
- int [] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
-
- /*
- * Bug in Motif. When a XmMainWindowSetAreas () is used
- * to replace an existing menu, both menus must be managed
- * before the call to XmMainWindowSetAreas () or the new
- * menu will not be layed out properly.
- */
- int newHandle = (menu != null) ? menu.handle : 0;
- int oldHandle = (menuBar != null) ? menuBar.handle : 0;
- menuBar = menu;
- int hHandle = (horizontalBar != null) ? horizontalBar.handle : 0;
- int vHandle = (verticalBar != null) ? verticalBar.handle : 0;
- if (newHandle != 0) {
- OS.XtSetMappedWhenManaged (newHandle, false);
- OS.XtManageChild (newHandle);
- }
- int clientHandle = formHandle != 0 ? formHandle : handle;
- OS.XmMainWindowSetAreas (scrolledHandle, newHandle, 0, hHandle, vHandle, clientHandle);
- if (oldHandle != 0) OS.XtUnmanageChild (oldHandle);
- if (newHandle != 0) {
- OS.XtSetMappedWhenManaged (newHandle, true);
- }
-
- /*
- * Bug in Motif. When a menu bar is removed after the
- * main window has been realized, the main window does
- * not layout the new menu bar or the work window.
- * The fix is to force a layout by temporarily resizing
- * the main window.
- */
- if (newHandle == 0 && OS.XtIsRealized (scrolledHandle)) {
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
- OS.XtResizeWidget (scrolledHandle, argList [1] + 1, argList [3], argList [5]);
- OS.XtResizeWidget (scrolledHandle, argList [1], argList [3], argList [5]);
- }
-
- /*
- * Compare the old client area with the new client area.
- * If the client area has changed, send a resize event
- * and layout.
- */
- int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList2, argList2.length / 2);
- if (argList1 [1] != argList2 [1] || argList1 [3] != argList2 [3]) {
- sendEvent (SWT.Resize);
- if (layout != null) layout (false);
- }
-}
-/**
- * Sets the minimized stated of the receiver.
- * If the argument is <code>true</code> causes the receiver
- * to switch to the minimized state, and if the argument is
- * <code>false</code> and the receiver was previously minimized,
- * causes the receiver to switch back to either the maximized
- * or normal states.
- * <p>
- * Note: The result of intermixing calls to<code>setMaximized(true)</code>
- * and <code>setMinimized(true)</code> will vary by platform. Typically,
- * the behavior will match the platform user's expectations, but not
- * always. This should be avoided if possible.
- * </p>
- *
- * @param 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 setMenuBar (Menu menu) { + checkWidget(); + if (menuBar == menu) return; + if (menu != null) { + if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); + if ((menu.style & SWT.BAR) == 0) error (SWT.ERROR_MENU_NOT_BAR); + if (menu.parent != this) error (SWT.ERROR_INVALID_PARENT); + } + + /* Ensure the new menu bar is correctly enabled */ + if (menuBar != null) { + if (!isEnabled () && menuBar.getEnabled ()) { + propagateHandle (true, menuBar.handle); + } + menuBar.removeAccelerators (); + } + if (menu != null) { + if (!isEnabled ()) { + propagateHandle (false, menu.handle); + } + menu.addAccelerators (); + } + + /* Save the old client area */ + int [] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0}; + OS.XtGetValues (handle, argList1, argList1.length / 2); + + /* + * Bug in Motif. When a XmMainWindowSetAreas () is used + * to replace an existing menu, both menus must be managed + * before the call to XmMainWindowSetAreas () or the new + * menu will not be layed out properly. + */ + int newHandle = (menu != null) ? menu.handle : 0; + int oldHandle = (menuBar != null) ? menuBar.handle : 0; + menuBar = menu; + int hHandle = (horizontalBar != null) ? horizontalBar.handle : 0; + int vHandle = (verticalBar != null) ? verticalBar.handle : 0; + if (newHandle != 0) { + OS.XtSetMappedWhenManaged (newHandle, false); + OS.XtManageChild (newHandle); + } + int clientHandle = formHandle != 0 ? formHandle : handle; + OS.XmMainWindowSetAreas (scrolledHandle, newHandle, 0, hHandle, vHandle, clientHandle); + if (oldHandle != 0) OS.XtUnmanageChild (oldHandle); + if (newHandle != 0) { + OS.XtSetMappedWhenManaged (newHandle, true); + } + + /* + * Bug in Motif. When a menu bar is removed after the + * main window has been realized, the main window does + * not layout the new menu bar or the work window. + * The fix is to force a layout by temporarily resizing + * the main window. + */ + if (newHandle == 0 && OS.XtIsRealized (scrolledHandle)) { + int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; + OS.XtGetValues (scrolledHandle, argList, argList.length / 2); + OS.XtResizeWidget (scrolledHandle, argList [1] + 1, argList [3], argList [5]); + OS.XtResizeWidget (scrolledHandle, argList [1], argList [3], argList [5]); + } + + /* + * Compare the old client area with the new client area. + * If the client area has changed, send a resize event + * and layout. + */ + int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0}; + OS.XtGetValues (handle, argList2, argList2.length / 2); + if (argList1 [1] != argList2 [1] || argList1 [3] != argList2 [3]) { + sendEvent (SWT.Resize); + if (layout != null) layout (false); + } +} +/** + * Sets the minimized stated of the receiver. + * If the argument is <code>true</code> causes the receiver + * to switch to the minimized state, and if the argument is + * <code>false</code> and the receiver was previously minimized, + * causes the receiver to switch back to either the maximized + * or normal states. + * <p> + * Note: The result of intermixing calls to<code>setMaximized(true)</code> + * and <code>setMinimized(true)</code> will vary by platform. Typically, + * the behavior will match the platform user's expectations, but not + * always. This should be avoided if possible. + * </p> + * + * @param the new maximized state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #setMaximized */ -public void setMinimized (boolean minimized) {
- checkWidget();
- this.minimized = minimized;
-}
-void setSavedFocus (Control control) {
- if (this == control) return;
- savedFocus = control;
-}
-/**
- * Sets the receiver's text, which is the string that the
- * window manager will typically display as the receiver's
- * <em>title</em>, to the argument, which 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 setMinimized (boolean minimized) { + checkWidget(); + this.minimized = minimized; +} +void setSavedFocus (Control control) { + if (this == control) return; + savedFocus = control; +} +/** + * Sets the receiver's text, which is the string that the + * window manager will typically display as the receiver's + * <em>title</em>, to the argument, which 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);
- label = string;
-}
-boolean translateAccelerator (int key, int keysym, XKeyEvent xEvent) {
- /*
- * Bug in Solaris. When accelerators are set more
- * than once in the same menu bar, the time it takes
- * to set the accelerator increases exponentially.
- * The fix is to implement our own accelerator table
- * on Solaris.
- */
- if (OS.IsSunOS) {
- if (menuBar != null && menuBar.getEnabled ()) {
- /* Ignore modifiers. */
- switch (keysym) {
- case OS.XK_Control_L:
- case OS.XK_Control_R:
- case OS.XK_Alt_L:
- case OS.XK_Alt_R:
- case OS.XK_Shift_L:
- case OS.XK_Shift_R:
- return false;
- }
-
- /*
- * Bug in MOTIF. On Solaris only, XK_F11 and XK_F12 are not
- * translated correctly by XLookupString(). They are mapped
- * to 0x1005FF10 and 0x1005FF11 respectively. The fix is to
- * look for these values explicitly and correct them.
- */
- if (keysym != 0) {
- switch (keysym) {
- case 0x1005FF10:
- keysym = OS.XK_F11;
- key = 0;
- break;
- case 0x1005FF11:
- keysym = OS.XK_F12;
- key = 0;
- break;
- }
- /*
- * Bug in MOTIF. On Solaris only, there is garbage in the
- * high 16-bits for Keysyms such as XK_Down. Since Keysyms
- * must be 16-bits to fit into a Character, mask away the
- * high 16-bits on all platforms.
- */
- keysym &= 0xFFFF;
- }
-
- /*
- * Bug in Motif. There are some keycodes for which
- * XLookupString() does not translate the character.
- * Some of examples are Shift+Tab and Ctrl+Space.
- */
- switch (keysym) {
- case OS.XK_ISO_Left_Tab: key = '\t'; break;
- case OS.XK_space: key = ' '; break;
- }
-
- int accelerator = Display.translateKey (keysym);
- if (accelerator == 0) accelerator = key;
- if (accelerator == 0) return false;
- if ((xEvent.state & OS.Mod1Mask) != 0) accelerator |= SWT.ALT;
- if ((xEvent.state & OS.ShiftMask) != 0) accelerator |= SWT.SHIFT;
- if ((xEvent.state & OS.ControlMask) != 0) accelerator |= SWT.CONTROL;
- return menuBar.translateAccelerator (accelerator);
- }
- }
- return false;
-}
-boolean traverseItem (boolean next) {
- return false;
-}
-boolean traverseReturn () {
- if (defaultButton == null || defaultButton.isDisposed ()) return false;
- if (!defaultButton.isVisible () || !defaultButton.isEnabled ()) return false;
- defaultButton.click ();
- return true;
-}
-}
+public void setText (String string) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + label = string; +} +boolean translateAccelerator (int key, int keysym, XKeyEvent xEvent) { + /* + * Bug in Solaris. When accelerators are set more + * than once in the same menu bar, the time it takes + * to set the accelerator increases exponentially. + * The fix is to implement our own accelerator table + * on Solaris. + */ + if (OS.IsSunOS) { + if (menuBar != null && menuBar.getEnabled ()) { + /* Ignore modifiers. */ + switch (keysym) { + case OS.XK_Control_L: + case OS.XK_Control_R: + case OS.XK_Alt_L: + case OS.XK_Alt_R: + case OS.XK_Shift_L: + case OS.XK_Shift_R: + return false; + } + + /* + * Bug in MOTIF. On Solaris only, XK_F11 and XK_F12 are not + * translated correctly by XLookupString(). They are mapped + * to 0x1005FF10 and 0x1005FF11 respectively. The fix is to + * look for these values explicitly and correct them. + */ + if (keysym != 0) { + switch (keysym) { + case 0x1005FF10: + keysym = OS.XK_F11; + key = 0; + break; + case 0x1005FF11: + keysym = OS.XK_F12; + key = 0; + break; + } + /* + * Bug in MOTIF. On Solaris only, there is garbage in the + * high 16-bits for Keysyms such as XK_Down. Since Keysyms + * must be 16-bits to fit into a Character, mask away the + * high 16-bits on all platforms. + */ + keysym &= 0xFFFF; + } + + /* + * Bug in Motif. There are some keycodes for which + * XLookupString() does not translate the character. + * Some of examples are Shift+Tab and Ctrl+Space. + */ + switch (keysym) { + case OS.XK_ISO_Left_Tab: key = '\t'; break; + case OS.XK_space: key = ' '; break; + } + + int accelerator = Display.translateKey (keysym); + if (accelerator == 0) accelerator = key; + if (accelerator == 0) return false; + if ((xEvent.state & OS.Mod1Mask) != 0) accelerator |= SWT.ALT; + if ((xEvent.state & OS.ShiftMask) != 0) accelerator |= SWT.SHIFT; + if ((xEvent.state & OS.ControlMask) != 0) accelerator |= SWT.CONTROL; + return menuBar.translateAccelerator (accelerator); + } + } + return false; +} +boolean traverseItem (boolean next) { + return false; +} +boolean traverseReturn () { + if (defaultButton == null || defaultButton.isDisposed ()) return false; + if (!defaultButton.isVisible () || !defaultButton.isEnabled ()) return false; + defaultButton.click (); + return true; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java index 2ce65c05c3..d83c444350 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/DirectoryDialog.java @@ -1,53 +1,53 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class allow the user to navigate
- * the file system and select a directory.
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html */ -public class DirectoryDialog extends Dialog {
- String filterPath = "";
- boolean cancel = true;
- String message = "";
-/**
- * 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>
+ +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; + +/** + * Instances of this class allow the user to navigate + * the file system and select a directory. + * <p> + * IMPORTANT: This class is intended to be subclassed <em>only</em> + * within the SWT implementation. + * </p> + */ +public class DirectoryDialog extends Dialog { + String filterPath = ""; + boolean cancel = true; + String message = ""; +/** + * 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);
-}
+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. @@ -78,241 +78,241 @@ public DirectoryDialog (Shell parent) { * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> * </ul> */ -public DirectoryDialog (Shell parent, int style) {
- super (parent, style);
- checkSubclass ();
-}
-int activate (int widget, int client, int call) {
- cancel = client == OS.XmDIALOG_CANCEL_BUTTON;
- OS.XtUnmanageChild (widget);
- return 0;
-}
-/**
- * Returns the path which the dialog will use to filter
- * the directories it shows.
- *
- * @return the filter path
+public DirectoryDialog (Shell parent, int style) { + super (parent, style); + checkSubclass (); +} +int activate (int widget, int client, int call) { + cancel = client == OS.XmDIALOG_CANCEL_BUTTON; + OS.XtUnmanageChild (widget); + return 0; +} +/** + * Returns the path which the dialog will use to filter + * the directories it shows. + * + * @return the filter path */ -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 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 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 () {
-
- /* Get the parent */
- boolean destroyContext;
- Display appContext = Display.getCurrent ();
- if (destroyContext = (appContext == null)) appContext = new Display ();
- int display = appContext.xDisplay;
- int parentHandle = appContext.shellHandle;
- if ((parent != null) && (parent.getDisplay () == appContext)) {
- if (OS.IsAIX) parent.realizeWidget (); /* Fix for bug 17507 */
- parentHandle = parent.shellHandle;
- }
-
- /* Compute the dialog title */
- /*
- * Feature in Motif. It is not possible to set a shell
- * title to an empty string. The fix is to set the title
- * to be a single space.
- */
- String string = title;
- if (string.length () == 0) string = " ";
-
- /* Use the character encoding for the default locale */
- byte [] buffer1 = Converter.wcsToMbcs (null, string, true);
- int xmStringPtr1 = OS.XmStringParseText (
- buffer1,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
-
- /* Compute the filter */
- /* Use the character encoding for the default locale */
- byte [] buffer2 = Converter.wcsToMbcs (null, "*", true);
- int xmStringPtr2 = OS.XmStringParseText (
- buffer2,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
-
- /* Compute the filter path */
- if (filterPath == null) filterPath = "";
- /* Use the character encoding for the default locale */
- byte [] buffer3 = Converter.wcsToMbcs (null, filterPath, true);
- int xmStringPtr3 = OS.XmStringParseText (
- buffer3,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
-
- /* Use the character encoding for the default locale */
- byte [] buffer7 = Converter.wcsToMbcs (null, "Selection", true);
- int xmStringPtr4 = OS.XmStringParseText (
- buffer7,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
-
- /* Create the dialog */
- int [] argList1 = {
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNdialogStyle, OS.XmDIALOG_PRIMARY_APPLICATION_MODAL,
- OS.XmNwidth, OS.XDisplayWidth (display, OS.XDefaultScreen (display)) * 4 / 9,
- OS.XmNdialogTitle, xmStringPtr1,
- OS.XmNpattern, xmStringPtr2,
- OS.XmNdirectory, xmStringPtr3,
- OS.XmNpathMode, OS.XmPATH_MODE_FULL,
- OS.XmNfilterLabelString, xmStringPtr4
- };
-
- /*
- * Feature in Linux. For some reason, the XmCreateFileSelectionDialog()
- * will not accept NULL for the widget name. This works fine on the other
- * Motif platforms and in the other XmCreate calls on Linux. The fix is
- * to pass in a NULL terminated string, not a NULL pointer.
- */
- byte [] name = new byte [] {0};
- int dialog = OS.XmCreateFileSelectionDialog (parentHandle, name, argList1, argList1.length / 2);
- int child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_HELP_BUTTON);
- if (child != 0) OS.XtUnmanageChild (child);
- child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST);
- if (child != 0) {
- int parent2 = OS.XtParent(child);
- if (parent2 !=0) OS.XtUnmanageChild (parent2);
- }
- child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST_LABEL);
- if (child != 0) OS.XtUnmanageChild (child);
- child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_TEXT);
- if (child != 0) OS.XtUnmanageChild (child);
- child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_SELECTION_LABEL);
- if (child != 0) OS.XtUnmanageChild (child);
- OS.XmStringFree (xmStringPtr1);
- OS.XmStringFree (xmStringPtr2);
- OS.XmStringFree (xmStringPtr3);
- OS.XmStringFree (xmStringPtr4);
-
- // Add label widget for message text.
- /* Use the character encoding for the default locale */
- byte [] buffer4 = Converter.wcsToMbcs (null, message, true);
- int xmString1 = OS.XmStringGenerate(buffer4, null, OS.XmCHARSET_TEXT, null);
- int [] argList = {
- OS.XmNlabelType, OS.XmSTRING,
- OS.XmNlabelString, xmString1
- };
- int textArea = OS.XmCreateLabel(dialog, name, argList, argList.length/2);
- OS.XtManageChild(textArea);
- OS.XmStringFree (xmString1);
-
- /* Hook the callbacks. */
- Callback callback = new Callback (this, "activate", 3);
- int address = callback.getAddress ();
- OS.XtAddCallback (dialog, OS.XmNokCallback, address, OS.XmDIALOG_OK_BUTTON);
- OS.XtAddCallback (dialog, OS.XmNcancelCallback, address, OS.XmDIALOG_CANCEL_BUTTON);
-
- /* Open the dialog and dispatch events. */
- cancel = true;
- OS.XtManageChild (dialog);
-
- // Should be a pure OS message loop (no SWT AppContext)
- while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog))
- if (!appContext.readAndDispatch ()) appContext.sleep ();
-
- /* Set the new path, file name and filter. */
- String directoryPath="";
- if (!cancel) {
- int [] argList2 = {OS.XmNdirMask, 0};
- OS.XtGetValues (dialog, argList2, argList2.length / 2);
- int xmString3 = argList2 [1];
- int ptr = OS.XmStringUnparse (
- xmString3,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- OS.XmOUTPUT_ALL);
- if (ptr != 0) {
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, length);
- OS.XtFree (ptr);
- /* Use the character encoding for the default locale */
- directoryPath = new String (Converter.mbcsToWcs (null, buffer));
- }
- OS.XmStringFree (xmString3);
- int length = directoryPath.length ();
- if (length != 0) {
- if (directoryPath.charAt (length -1) == '/') {
- directoryPath = directoryPath.substring (0, length - 1);
- } else {
- if (length > 1 && directoryPath.charAt (length - 2) == '/' && directoryPath.charAt (length - 1) == '*') {
- directoryPath = directoryPath.substring (0, length - 2);
- }
- }
- }
- filterPath = directoryPath;
- }
-
- /* Destroy the dialog and update the display. */
- if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog);
- if (destroyContext) appContext.dispose ();
- callback.dispose ();
-
- if (cancel) return null;
- return directoryPath;
-}
-/**
- * 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 String open () { + + /* Get the parent */ + boolean destroyContext; + Display appContext = Display.getCurrent (); + if (destroyContext = (appContext == null)) appContext = new Display (); + int display = appContext.xDisplay; + int parentHandle = appContext.shellHandle; + if ((parent != null) && (parent.getDisplay () == appContext)) { + if (OS.IsAIX) parent.realizeWidget (); /* Fix for bug 17507 */ + parentHandle = parent.shellHandle; + } + + /* Compute the dialog title */ + /* + * Feature in Motif. It is not possible to set a shell + * title to an empty string. The fix is to set the title + * to be a single space. + */ + String string = title; + if (string.length () == 0) string = " "; + + /* Use the character encoding for the default locale */ + byte [] buffer1 = Converter.wcsToMbcs (null, string, true); + int xmStringPtr1 = OS.XmStringParseText ( + buffer1, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + + /* Compute the filter */ + /* Use the character encoding for the default locale */ + byte [] buffer2 = Converter.wcsToMbcs (null, "*", true); + int xmStringPtr2 = OS.XmStringParseText ( + buffer2, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + + /* Compute the filter path */ + if (filterPath == null) filterPath = ""; + /* Use the character encoding for the default locale */ + byte [] buffer3 = Converter.wcsToMbcs (null, filterPath, true); + int xmStringPtr3 = OS.XmStringParseText ( + buffer3, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + + /* Use the character encoding for the default locale */ + byte [] buffer7 = Converter.wcsToMbcs (null, "Selection", true); + int xmStringPtr4 = OS.XmStringParseText ( + buffer7, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + + /* Create the dialog */ + int [] argList1 = { + OS.XmNresizePolicy, OS.XmRESIZE_NONE, + OS.XmNdialogStyle, OS.XmDIALOG_PRIMARY_APPLICATION_MODAL, + OS.XmNwidth, OS.XDisplayWidth (display, OS.XDefaultScreen (display)) * 4 / 9, + OS.XmNdialogTitle, xmStringPtr1, + OS.XmNpattern, xmStringPtr2, + OS.XmNdirectory, xmStringPtr3, + OS.XmNpathMode, OS.XmPATH_MODE_FULL, + OS.XmNfilterLabelString, xmStringPtr4 + }; + + /* + * Feature in Linux. For some reason, the XmCreateFileSelectionDialog() + * will not accept NULL for the widget name. This works fine on the other + * Motif platforms and in the other XmCreate calls on Linux. The fix is + * to pass in a NULL terminated string, not a NULL pointer. + */ + byte [] name = new byte [] {0}; + int dialog = OS.XmCreateFileSelectionDialog (parentHandle, name, argList1, argList1.length / 2); + int child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_HELP_BUTTON); + if (child != 0) OS.XtUnmanageChild (child); + child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST); + if (child != 0) { + int parent2 = OS.XtParent(child); + if (parent2 !=0) OS.XtUnmanageChild (parent2); + } + child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST_LABEL); + if (child != 0) OS.XtUnmanageChild (child); + child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_TEXT); + if (child != 0) OS.XtUnmanageChild (child); + child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_SELECTION_LABEL); + if (child != 0) OS.XtUnmanageChild (child); + OS.XmStringFree (xmStringPtr1); + OS.XmStringFree (xmStringPtr2); + OS.XmStringFree (xmStringPtr3); + OS.XmStringFree (xmStringPtr4); + + // Add label widget for message text. + /* Use the character encoding for the default locale */ + byte [] buffer4 = Converter.wcsToMbcs (null, message, true); + int xmString1 = OS.XmStringGenerate(buffer4, null, OS.XmCHARSET_TEXT, null); + int [] argList = { + OS.XmNlabelType, OS.XmSTRING, + OS.XmNlabelString, xmString1 + }; + int textArea = OS.XmCreateLabel(dialog, name, argList, argList.length/2); + OS.XtManageChild(textArea); + OS.XmStringFree (xmString1); + + /* Hook the callbacks. */ + Callback callback = new Callback (this, "activate", 3); + int address = callback.getAddress (); + OS.XtAddCallback (dialog, OS.XmNokCallback, address, OS.XmDIALOG_OK_BUTTON); + OS.XtAddCallback (dialog, OS.XmNcancelCallback, address, OS.XmDIALOG_CANCEL_BUTTON); + + /* Open the dialog and dispatch events. */ + cancel = true; + OS.XtManageChild (dialog); + + // Should be a pure OS message loop (no SWT AppContext) + while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog)) + if (!appContext.readAndDispatch ()) appContext.sleep (); + + /* Set the new path, file name and filter. */ + String directoryPath=""; + if (!cancel) { + int [] argList2 = {OS.XmNdirMask, 0}; + OS.XtGetValues (dialog, argList2, argList2.length / 2); + int xmString3 = argList2 [1]; + int ptr = OS.XmStringUnparse ( + xmString3, + null, + OS.XmCHARSET_TEXT, + OS.XmCHARSET_TEXT, + null, + 0, + OS.XmOUTPUT_ALL); + if (ptr != 0) { + int length = OS.strlen (ptr); + byte [] buffer = new byte [length]; + OS.memmove (buffer, ptr, length); + OS.XtFree (ptr); + /* Use the character encoding for the default locale */ + directoryPath = new String (Converter.mbcsToWcs (null, buffer)); + } + OS.XmStringFree (xmString3); + int length = directoryPath.length (); + if (length != 0) { + if (directoryPath.charAt (length -1) == '/') { + directoryPath = directoryPath.substring (0, length - 1); + } else { + if (length > 1 && directoryPath.charAt (length - 2) == '/' && directoryPath.charAt (length - 1) == '*') { + directoryPath = directoryPath.substring (0, length - 2); + } + } + } + filterPath = directoryPath; + } + + /* Destroy the dialog and update the display. */ + if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog); + if (destroyContext) appContext.dispose (); + callback.dispose (); + + if (cancel) return null; + return directoryPath; +} +/** + * 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 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;
-}
-}
+public void setMessage (String string) { + message = string; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java index fba8edb639..389bbf0213 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Display.java @@ -1,17 +1,17 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; + /** * Instances of this class are responsible for managing the * connection between SWT and the underlying operating @@ -87,2266 +87,2266 @@ import org.eclipse.swt.graphics.*; * @see #sleep * @see #dispose */ -public class Display extends Device {
-
- /* Motif Only Public Fields */
- public XAnyEvent xEvent = new XAnyEvent ();
- int lastSerial;
-
- /* Windows, Events and Callbacks */
- Callback windowCallback;
- int windowProc, shellHandle;
- static boolean XtInitialized;
- static Object XInitLock = new Object ();
- static String APP_NAME = "SWT";
- byte [] displayName, appName, appClass;
- Event [] eventQueue;
- XKeyEvent keyEvent = new XKeyEvent ();
- EventTable eventTable, filterTable;
- boolean postFocusOut;
-
- /* Default Fonts, Colors, Insets, Widths and Heights. */
- Font defaultFont;
- Font listFont, textFont, buttonFont, labelFont;
- int dialogBackground, dialogForeground;
- int buttonBackground, buttonForeground, buttonShadowThickness;
- int compositeBackground, compositeForeground;
- int compositeTopShadow, compositeBottomShadow, compositeBorder;
- int listBackground, listForeground, listSelect, textBackground, textForeground;
- int labelBackground, labelForeground, scrollBarBackground, scrollBarForeground;
- int scrolledInsetX, scrolledInsetY, scrolledMarginX, scrolledMarginY;
- int defaultBackground, defaultForeground;
- int textHighlightThickness;
-
- /* System Colors */
- XColor COLOR_WIDGET_DARK_SHADOW, COLOR_WIDGET_NORMAL_SHADOW, COLOR_WIDGET_LIGHT_SHADOW;
- XColor COLOR_WIDGET_HIGHLIGHT_SHADOW, COLOR_WIDGET_FOREGROUND, COLOR_WIDGET_BACKGROUND, COLOR_WIDGET_BORDER;
- XColor COLOR_LIST_FOREGROUND, COLOR_LIST_BACKGROUND, COLOR_LIST_SELECTION, COLOR_LIST_SELECTION_TEXT;
- Color COLOR_INFO_BACKGROUND;
-
- /* Initial Guesses for Shell Trimmings. */
- int leftBorderWidth = 2, rightBorderWidth = 2;
- int topBorderHeight = 2, bottomBorderHeight = 2;
- int leftResizeWidth = 3, rightResizeWidth = 3;
- int topResizeHeight = 3, bottomResizeHeight = 3;
- int leftTitleBorderWidth = 3, rightTitleBorderWidth = 2;
- int topTitleBorderHeight = 26, bottomTitleBorderHeight = 2;
- int leftTitleResizeWidth = 3, rightTitleResizeWidth = 3;
- int topTitleResizeHeight = 26, bottomTitleResizeHeight = 3;
- int leftTitleWidth = 0, rightTitleWidth = 0;
- int topTitleHeight = 23, bottomTitleHeight = 0;
-
- /* Sync/Async Widget Communication */
- Synchronizer synchronizer = new Synchronizer (this);
- Thread thread;
-
- /* Display Shutdown */
- Runnable [] disposeList;
-
- /* Timers */
- int [] timerIds;
- Runnable [] timerList;
- Callback timerCallback;
- int timerProc;
-
- /* Widget Timers */
- Callback windowTimerCallback;
- int windowTimerProc;
-
- /* Key Mappings. */
- static int [] [] KeyTable = {
-
- /* Keyboard and Mouse Masks */
- {OS.XK_Alt_L, SWT.ALT},
- {OS.XK_Alt_R, SWT.ALT},
- {OS.XK_Shift_L, SWT.SHIFT},
- {OS.XK_Shift_R, SWT.SHIFT},
- {OS.XK_Control_L, SWT.CONTROL},
- {OS.XK_Control_R, SWT.CONTROL},
-
-// {OS.VK_LBUTTON, SWT.BUTTON1},
-// {OS.VK_MBUTTON, SWT.BUTTON3},
-// {OS.VK_RBUTTON, SWT.BUTTON2},
-
- /* Non-Numeric Keypad Keys */
- {OS.XK_Up, SWT.ARROW_UP},
- {OS.XK_Down, SWT.ARROW_DOWN},
- {OS.XK_Left, SWT.ARROW_LEFT},
- {OS.XK_Right, SWT.ARROW_RIGHT},
- {OS.XK_Page_Up, SWT.PAGE_UP},
- {OS.XK_Page_Down, SWT.PAGE_DOWN},
- {OS.XK_Home, SWT.HOME},
- {OS.XK_End, SWT.END},
- {OS.XK_Insert, SWT.INSERT},
-
- /* Virtual and Ascii Keys */
- {OS.XK_BackSpace, SWT.BS},
- {OS.XK_Return, SWT.CR},
- {OS.XK_KP_Enter, SWT.CR},
- {OS.XK_Delete, SWT.DEL},
- {OS.XK_Escape, SWT.ESC},
- {OS.XK_Cancel, SWT.ESC},
- {OS.XK_Linefeed, SWT.LF},
- {OS.XK_Tab, SWT.TAB},
- {OS.XK_ISO_Left_Tab,SWT.TAB},
-
- /* Functions Keys */
- {OS.XK_F1, SWT.F1},
- {OS.XK_F2, SWT.F2},
- {OS.XK_F3, SWT.F3},
- {OS.XK_F4, SWT.F4},
- {OS.XK_F5, SWT.F5},
- {OS.XK_F6, SWT.F6},
- {OS.XK_F7, SWT.F7},
- {OS.XK_F8, SWT.F8},
- {OS.XK_F9, SWT.F9},
- {OS.XK_F10, SWT.F10},
- {OS.XK_F11, SWT.F11},
- {OS.XK_F12, SWT.F12},
-
- /* Numeric Keypad Constants */
- /*
- {OS.XK_KP_Add, SWT.KP_PLUS},
- {OS.XK_KP_Subtract, SWT.KP_MINUS},
- {OS.XK_KP_Multiply, SWT.KP_TIMES},
- {OS.XK_KP_Divide, SWT.KP_DIVIDE},
- {OS.XK_KP_Decimal, SWT.KP_PERIOD},
- {OS.XK_KP_Enter, SWT.KP_ENTER},
- {OS.XK_KP_0, SWT.KP_0},
- {OS.XK_KP_1, SWT.KP_1},
- {OS.XK_KP_2, SWT.KP_2},
- {OS.XK_KP_3, SWT.KP_3},
- {OS.XK_KP_4, SWT.KP_4},
- {OS.XK_KP_5, SWT.KP_5},
- {OS.XK_KP_6, SWT.KP_6},
- {OS.XK_KP_7, SWT.KP_7},
- {OS.XK_KP_8, SWT.KP_8},
- {OS.XK_KP_9, SWT.KP_9},
- */
- };
-
- /* Multiple Displays. */
- static Display Default;
- static Display [] Displays = new Display [4];
-
- /* Double Click */
- int lastTime, lastButton;
-
- /* Current caret */
- Caret currentCaret;
- Callback caretCallback;
- int caretID, caretProc;
-
- /* Workaround for GP when disposing a display */
- static boolean DisplayDisposed;
-
- /* Package Name */
- static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets.";
- /*
- * This code is intentionally commented. In order
- * to support CLDC, .class cannot be used because
- * it does not compile on some Java compilers when
- * they are targeted for CLDC.
- */
-// static {
-// String name = Display.class.getName ();
-// int index = name.lastIndexOf ('.');
-// PACKAGE_PREFIX = name.substring (0, index + 1);
-// }
-
- /* Mouse Hover */
- Callback mouseHoverCallback;
- int mouseHoverID, mouseHoverProc;
- int mouseHoverHandle, toolTipHandle;
-
- /* Xt Translations */
- int dragTranslations;
- int arrowTranslations, tabTranslations;
-
- /* Check Expose Proc */
- Callback checkExposeCallback;
- int checkExposeProc, exposeCount, lastExpose;
- XExposeEvent xExposeEvent = new XExposeEvent ();
-
- /* Check Resize Proc */
- Callback checkResizeCallback;
- int checkResizeProc, resizeWidth, resizeHeight, resizeCount, resizeWindow;
- XConfigureEvent xConfigureEvent = new XConfigureEvent ();
-
- /* Wake and Sleep */
- Callback wakeCallback;
- int wakeProc, read_fd, write_fd, inputID;
- byte [] wake_buffer = new byte [1];
- int [] timeout = new int [2];
- byte [] fd_set;
-
- /* Display Data */
- Object data;
- String [] keys;
- Object [] values;
-
- /*
- * TEMPORARY CODE. Install the runnable that
- * gets the current display. This code will
- * be removed in the future.
- */
- static {
- DeviceFinder = new Runnable () {
- public void run () {
- Device device = getCurrent ();
- if (device == null) {
- device = getDefault ();
- }
- setDevice (device);
- }
- };
- }
-
-/*
-* TEMPORARY CODE.
-*/
-static void setDevice (Device device) {
- CurrentDevice = device;
-}
-
-/**
- * Constructs a new instance of this class.
- * <p>
- * Note: The resulting display is marked as the <em>current</em>
- * display. If this is the first display which has been
- * constructed since the application started, it is also
- * marked as the <em>default</em> display.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if 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 class Display extends Device { + + /* Motif Only Public Fields */ + public XAnyEvent xEvent = new XAnyEvent (); + int lastSerial; + + /* Windows, Events and Callbacks */ + Callback windowCallback; + int windowProc, shellHandle; + static boolean XtInitialized; + static Object XInitLock = new Object (); + static String APP_NAME = "SWT"; + byte [] displayName, appName, appClass; + Event [] eventQueue; + XKeyEvent keyEvent = new XKeyEvent (); + EventTable eventTable, filterTable; + boolean postFocusOut; + + /* Default Fonts, Colors, Insets, Widths and Heights. */ + Font defaultFont; + Font listFont, textFont, buttonFont, labelFont; + int dialogBackground, dialogForeground; + int buttonBackground, buttonForeground, buttonShadowThickness; + int compositeBackground, compositeForeground; + int compositeTopShadow, compositeBottomShadow, compositeBorder; + int listBackground, listForeground, listSelect, textBackground, textForeground; + int labelBackground, labelForeground, scrollBarBackground, scrollBarForeground; + int scrolledInsetX, scrolledInsetY, scrolledMarginX, scrolledMarginY; + int defaultBackground, defaultForeground; + int textHighlightThickness; + + /* System Colors */ + XColor COLOR_WIDGET_DARK_SHADOW, COLOR_WIDGET_NORMAL_SHADOW, COLOR_WIDGET_LIGHT_SHADOW; + XColor COLOR_WIDGET_HIGHLIGHT_SHADOW, COLOR_WIDGET_FOREGROUND, COLOR_WIDGET_BACKGROUND, COLOR_WIDGET_BORDER; + XColor COLOR_LIST_FOREGROUND, COLOR_LIST_BACKGROUND, COLOR_LIST_SELECTION, COLOR_LIST_SELECTION_TEXT; + Color COLOR_INFO_BACKGROUND; + + /* Initial Guesses for Shell Trimmings. */ + int leftBorderWidth = 2, rightBorderWidth = 2; + int topBorderHeight = 2, bottomBorderHeight = 2; + int leftResizeWidth = 3, rightResizeWidth = 3; + int topResizeHeight = 3, bottomResizeHeight = 3; + int leftTitleBorderWidth = 3, rightTitleBorderWidth = 2; + int topTitleBorderHeight = 26, bottomTitleBorderHeight = 2; + int leftTitleResizeWidth = 3, rightTitleResizeWidth = 3; + int topTitleResizeHeight = 26, bottomTitleResizeHeight = 3; + int leftTitleWidth = 0, rightTitleWidth = 0; + int topTitleHeight = 23, bottomTitleHeight = 0; + + /* Sync/Async Widget Communication */ + Synchronizer synchronizer = new Synchronizer (this); + Thread thread; + + /* Display Shutdown */ + Runnable [] disposeList; + + /* Timers */ + int [] timerIds; + Runnable [] timerList; + Callback timerCallback; + int timerProc; + + /* Widget Timers */ + Callback windowTimerCallback; + int windowTimerProc; + + /* Key Mappings. */ + static int [] [] KeyTable = { + + /* Keyboard and Mouse Masks */ + {OS.XK_Alt_L, SWT.ALT}, + {OS.XK_Alt_R, SWT.ALT}, + {OS.XK_Shift_L, SWT.SHIFT}, + {OS.XK_Shift_R, SWT.SHIFT}, + {OS.XK_Control_L, SWT.CONTROL}, + {OS.XK_Control_R, SWT.CONTROL}, + +// {OS.VK_LBUTTON, SWT.BUTTON1}, +// {OS.VK_MBUTTON, SWT.BUTTON3}, +// {OS.VK_RBUTTON, SWT.BUTTON2}, + + /* Non-Numeric Keypad Keys */ + {OS.XK_Up, SWT.ARROW_UP}, + {OS.XK_Down, SWT.ARROW_DOWN}, + {OS.XK_Left, SWT.ARROW_LEFT}, + {OS.XK_Right, SWT.ARROW_RIGHT}, + {OS.XK_Page_Up, SWT.PAGE_UP}, + {OS.XK_Page_Down, SWT.PAGE_DOWN}, + {OS.XK_Home, SWT.HOME}, + {OS.XK_End, SWT.END}, + {OS.XK_Insert, SWT.INSERT}, + + /* Virtual and Ascii Keys */ + {OS.XK_BackSpace, SWT.BS}, + {OS.XK_Return, SWT.CR}, + {OS.XK_KP_Enter, SWT.CR}, + {OS.XK_Delete, SWT.DEL}, + {OS.XK_Escape, SWT.ESC}, + {OS.XK_Cancel, SWT.ESC}, + {OS.XK_Linefeed, SWT.LF}, + {OS.XK_Tab, SWT.TAB}, + {OS.XK_ISO_Left_Tab,SWT.TAB}, + + /* Functions Keys */ + {OS.XK_F1, SWT.F1}, + {OS.XK_F2, SWT.F2}, + {OS.XK_F3, SWT.F3}, + {OS.XK_F4, SWT.F4}, + {OS.XK_F5, SWT.F5}, + {OS.XK_F6, SWT.F6}, + {OS.XK_F7, SWT.F7}, + {OS.XK_F8, SWT.F8}, + {OS.XK_F9, SWT.F9}, + {OS.XK_F10, SWT.F10}, + {OS.XK_F11, SWT.F11}, + {OS.XK_F12, SWT.F12}, + + /* Numeric Keypad Constants */ + /* + {OS.XK_KP_Add, SWT.KP_PLUS}, + {OS.XK_KP_Subtract, SWT.KP_MINUS}, + {OS.XK_KP_Multiply, SWT.KP_TIMES}, + {OS.XK_KP_Divide, SWT.KP_DIVIDE}, + {OS.XK_KP_Decimal, SWT.KP_PERIOD}, + {OS.XK_KP_Enter, SWT.KP_ENTER}, + {OS.XK_KP_0, SWT.KP_0}, + {OS.XK_KP_1, SWT.KP_1}, + {OS.XK_KP_2, SWT.KP_2}, + {OS.XK_KP_3, SWT.KP_3}, + {OS.XK_KP_4, SWT.KP_4}, + {OS.XK_KP_5, SWT.KP_5}, + {OS.XK_KP_6, SWT.KP_6}, + {OS.XK_KP_7, SWT.KP_7}, + {OS.XK_KP_8, SWT.KP_8}, + {OS.XK_KP_9, SWT.KP_9}, + */ + }; + + /* Multiple Displays. */ + static Display Default; + static Display [] Displays = new Display [4]; + + /* Double Click */ + int lastTime, lastButton; + + /* Current caret */ + Caret currentCaret; + Callback caretCallback; + int caretID, caretProc; + + /* Workaround for GP when disposing a display */ + static boolean DisplayDisposed; + + /* Package Name */ + static final String PACKAGE_PREFIX = "org.eclipse.swt.widgets."; + /* + * This code is intentionally commented. In order + * to support CLDC, .class cannot be used because + * it does not compile on some Java compilers when + * they are targeted for CLDC. + */ +// static { +// String name = Display.class.getName (); +// int index = name.lastIndexOf ('.'); +// PACKAGE_PREFIX = name.substring (0, index + 1); +// } + + /* Mouse Hover */ + Callback mouseHoverCallback; + int mouseHoverID, mouseHoverProc; + int mouseHoverHandle, toolTipHandle; + + /* Xt Translations */ + int dragTranslations; + int arrowTranslations, tabTranslations; + + /* Check Expose Proc */ + Callback checkExposeCallback; + int checkExposeProc, exposeCount, lastExpose; + XExposeEvent xExposeEvent = new XExposeEvent (); + + /* Check Resize Proc */ + Callback checkResizeCallback; + int checkResizeProc, resizeWidth, resizeHeight, resizeCount, resizeWindow; + XConfigureEvent xConfigureEvent = new XConfigureEvent (); + + /* Wake and Sleep */ + Callback wakeCallback; + int wakeProc, read_fd, write_fd, inputID; + byte [] wake_buffer = new byte [1]; + int [] timeout = new int [2]; + byte [] fd_set; + + /* Display Data */ + Object data; + String [] keys; + Object [] values; + + /* + * TEMPORARY CODE. Install the runnable that + * gets the current display. This code will + * be removed in the future. + */ + static { + DeviceFinder = new Runnable () { + public void run () { + Device device = getCurrent (); + if (device == null) { + device = getDefault (); + } + setDevice (device); + } + }; + } + +/* +* TEMPORARY CODE. +*/ +static void setDevice (Device device) { + CurrentDevice = device; +} + +/** + * Constructs a new instance of this class. + * <p> + * Note: The resulting display is marked as the <em>current</em> + * display. If this is the first display which has been + * constructed since the application started, it is also + * marked as the <em>default</em> display. + * </p> + * + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if 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 (checkNull (data));
-}
-static DeviceData checkNull (DeviceData data) {
- if (data == null) data = new DeviceData ();
- if (data.application_name == null) {
- data.application_name = APP_NAME;
- }
- if (data.application_class == null) {
- data.application_class = APP_NAME;
- }
- return data;
-}
-protected void checkDevice () {
- if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
-}
-void addMouseHoverTimeOut (int handle) {
- if (mouseHoverID != 0) OS.XtRemoveTimeOut (mouseHoverID);
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- mouseHoverID = OS.XtAppAddTimeOut (xtContext, 400, mouseHoverProc, handle);
- mouseHoverHandle = handle;
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notifed when an event of the given type occurs anywhere
- * in SWT. When the event does occur, the listener is notified
- * by sending it the <code>handleEvent()</code> message.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see #removeFilter
- * @see #removeListener
- *
- * @since 2.1
- */
-void addFilter (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (filterTable == null) filterTable = new EventTable ();
- filterTable.hook (eventType, listener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notifed when an event of the given type occurs. When the
- * event does occur in the display, the listener is notified by
- * sending it the <code>handleEvent()</code> message.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see #removeListener
- *
- * @since 2.0
+public Display () { + this (null); +} +public Display (DeviceData data) { + super (checkNull (data)); +} +static DeviceData checkNull (DeviceData data) { + if (data == null) data = new DeviceData (); + if (data.application_name == null) { + data.application_name = APP_NAME; + } + if (data.application_class == null) { + data.application_class = APP_NAME; + } + return data; +} +protected void checkDevice () { + if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); + if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); +} +void addMouseHoverTimeOut (int handle) { + if (mouseHoverID != 0) OS.XtRemoveTimeOut (mouseHoverID); + int xtContext = OS.XtDisplayToApplicationContext (xDisplay); + mouseHoverID = OS.XtAppAddTimeOut (xtContext, 400, mouseHoverProc, handle); + mouseHoverHandle = handle; +} +/** + * Adds the listener to the collection of listeners who will + * be notifed when an event of the given type occurs anywhere + * in SWT. When the event does occur, the listener is notified + * by sending it the <code>handleEvent()</code> message. + * + * @param eventType the type of event to listen for + * @param listener the listener which should be notified when the event occurs + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see Listener + * @see #removeFilter + * @see #removeListener + * + * @since 2.1 */ -public void addListener (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) eventTable = new EventTable ();
- eventTable.hook (eventType, listener);
-}
-/**
- * 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
+void addFilter (int eventType, Listener listener) { + checkDevice (); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (filterTable == null) filterTable = new EventTable (); + filterTable.hook (eventType, listener); +} +/** + * Adds the listener to the collection of listeners who will + * be notifed when an event of the given type occurs. When the + * event does occur in the display, the listener is notified by + * sending it the <code>handleEvent()</code> message. + * + * @param eventType the type of event to listen for + * @param listener the listener which should be notified when the event occurs + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see Listener + * @see #removeListener + * + * @since 2.0 */ -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 addListener (int eventType, Listener listener) { + checkDevice (); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) eventTable = new EventTable (); + eventTable.hook (eventType, listener); +} +/** + * 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 beep () {
- checkDevice ();
- OS.XBell (xDisplay, 100);
- OS.XFlush (xDisplay);
-}
-int caretProc (int clientData, int id) {
- caretID = 0;
- if (currentCaret == null) return 0;
- if (currentCaret.blinkCaret ()) {
- int blinkRate = currentCaret.blinkRate;
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- caretID = OS.XtAppAddTimeOut (xtContext, blinkRate, caretProc, 0);
- } else {
- currentCaret = null;
- }
- return 0;
-}
-
-int checkExposeProc (int display, int event, int window) {
- OS.memmove (xExposeEvent, event, XExposeEvent.sizeof);
- if (xExposeEvent.window != window) return 0;
- switch (xExposeEvent.type) {
- case OS.Expose:
- case OS.GraphicsExpose:
- exposeCount++;
- lastExpose = event;
- xExposeEvent.count = 1;
- OS.memmove (event, xExposeEvent, XExposeEvent.sizeof);
- break;
- }
- return 0;
-}
-int checkResizeProc (int display, int event, int arg) {
- OS.memmove (xConfigureEvent, event, XConfigureEvent.sizeof);
- if (xConfigureEvent.window != resizeWindow) return 0;
- switch (xConfigureEvent.type) {
- case OS.ConfigureNotify:
- int width = xConfigureEvent.width;
- int height = xConfigureEvent.height;
- if (width != resizeWidth || height != resizeHeight) {
- resizeCount++;
- }
- break;
- }
- return 0;
-}
-static 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 (!Display.isValidClass (getClass ())) {
- error (SWT.ERROR_INVALID_SUBCLASS);
- }
-}
-/**
- * Requests that the connection between SWT and the underlying
- * operating system be closed.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #dispose
- *
- * @since 2.0
+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 close () {
- checkDevice ();
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- if (event.doit) dispose ();
-}
-String convertToLf(String text) {
- char Cr = '\r';
- char Lf = '\n';
- int length = text.length ();
- if (length == 0) return text;
-
- /* Check for an LF or CR/LF. Assume the rest of the string
- * is formated that way. This will not work if the string
- * contains mixed delimiters. */
- int i = text.indexOf (Lf, 0);
- if (i == -1 || i == 0) return text;
- if (text.charAt (i - 1) != Cr) return text;
-
- /* The string is formatted with CR/LF.
- * Create a new string with the LF line delimiter. */
- i = 0;
- StringBuffer result = new StringBuffer ();
- while (i < length) {
- int j = text.indexOf (Cr, i);
- if (j == -1) j = length;
- String s = text.substring (i, j);
- result.append (s);
- i = j + 2;
- result.append (Lf);
- }
- return result.toString ();
-}
-protected void create (DeviceData data) {
- checkSubclass ();
- checkDisplay (thread = Thread.currentThread ());
- createDisplay (data);
- register (this);
- if (Default == null) Default = this;
-}
-void createDisplay (DeviceData data) {
-
- /* Initialize X and Xt */
- synchronized (XInitLock) {
- if (!XtInitialized) {
- /*
- * This code is intentionally commented.
- */
-// OS.XInitThreads ();
-// OS.XtToolkitThreadInitialize ();
- OS.XtToolkitInitialize ();
- }
- XtInitialized = true;
- }
-
- /* Create the AppContext */
- int [] argc = new int [] {0};
- int xtContext = OS.XtCreateApplicationContext ();
- OS.XtSetLanguageProc (xtContext, 0, 0);
-
- /*
- * Feature in Linux. On some DBCS Linux platforms, the default
- * font is not be properly initialized to contain a font set.
- * This causes the IME to fail. The fix is to set a fallback
- * resource with an appropriated font to ensure a font set is
- * found.
*/
- int ptr1 = 0, ptr2 = 0;
- if (OS.IsLinux && OS.IsDBLocale) {
- String resource = "*fontList: -*-*-medium-r-*-*-*-120-*-*-*-*-*-*:";
- byte [] buffer = Converter.wcsToMbcs (null, resource, true);
- ptr1 = OS.XtMalloc (buffer.length);
- if (ptr1 != 0) OS.memmove (ptr1, buffer, buffer.length);
- int [] spec = new int[]{ptr1, 0};
- ptr2 = OS.XtMalloc (spec.length * 4);
- if (ptr2 != 0)OS.memmove (ptr2, spec, spec.length * 4);
- OS.XtAppSetFallbackResources(xtContext, ptr2);
- }
-
- /* Compute the display name, application name and class */
- String display_name = null;
- String application_name = APP_NAME;
- String application_class = APP_NAME;
- if (data != null) {
- if (data.display_name != null) display_name = data.display_name;
- if (data.application_name != null) application_name = data.application_name;
- if (data.application_class != null) application_class = data.application_class;
- }
- /* Use the character encoding for the default locale */
- if (display_name != null) displayName = Converter.wcsToMbcs (null, display_name, true);
- if (application_name != null) appName = Converter.wcsToMbcs (null, application_name, true);
- if (application_class != null) appClass = Converter.wcsToMbcs (null, application_class, true);
-
- /* Create the XDisplay */
- xDisplay = OS.XtOpenDisplay (xtContext, displayName, appName, appClass, 0, 0, argc, 0);
- DisplayDisposed = false;
-
- if (ptr2 != 0) {
- OS.XtAppSetFallbackResources (xtContext, 0);
- OS.XtFree (ptr2);
- }
- if (ptr1 != 0) OS.XtFree (ptr1);
-}
-synchronized static void deregister (Display display) {
- for (int i=0; i<Displays.length; i++) {
- if (display == Displays [i]) Displays [i] = null;
- }
-}
-protected void destroy () {
- if (this == Default) Default = null;
- deregister (this);
- destroyDisplay ();
-}
-void destroyDisplay () {
- /*
- * Bug in Motif. For some reason, XtAppCreateShell GP's when called
- * after an application context has been destroyed. The fix is to
- * destroy the default XmDisplay associated with the X Display for
- * the application context. The following code fragment GP's without
- * this work around:
- *
- * int xContext = OS.XtCreateApplicationContext();
- * int xDisplay = OS.XtOpenDisplay(xContext, null, null, null, null, 0, new int[1], null);
- * OS.XtAppCreateShell(null, null, OS.topLevelShellWidgetClass(), xDisplay, null, 0);
- * OS.XtDestroyApplicationContext(xContext);
- * xContext = OS.XtCreateApplicationContext();
- * xDisplay = OS.XtOpenDisplay(xContext, null, null, null, null, 0, new int[1], null);
- * OS.XtAppCreateShell(null, null, OS.topLevelShellWidgetClass(), xDisplay, null, 0);
- * OS.XtDestroyApplicationContext(xContext);
- */
- OS.XtDestroyWidget (OS.XmGetXmDisplay (xDisplay));
-
- /*
- * Destroy AppContext (this destroys the display)
- */
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- OS.XtDestroyApplicationContext (xtContext);
- DisplayDisposed = true;
-}
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread just before the
- * receiver is disposed.
- *
- * @param runnable code to run at dispose time.
+public void beep () { + checkDevice (); + OS.XBell (xDisplay, 100); + OS.XFlush (xDisplay); +} +int caretProc (int clientData, int id) { + caretID = 0; + if (currentCaret == null) return 0; + if (currentCaret.blinkCaret ()) { + int blinkRate = currentCaret.blinkRate; + int xtContext = OS.XtDisplayToApplicationContext (xDisplay); + caretID = OS.XtAppAddTimeOut (xtContext, blinkRate, caretProc, 0); + } else { + currentCaret = null; + } + return 0; +} + +int checkExposeProc (int display, int event, int window) { + OS.memmove (xExposeEvent, event, XExposeEvent.sizeof); + if (xExposeEvent.window != window) return 0; + switch (xExposeEvent.type) { + case OS.Expose: + case OS.GraphicsExpose: + exposeCount++; + lastExpose = event; + xExposeEvent.count = 1; + OS.memmove (event, xExposeEvent, XExposeEvent.sizeof); + break; + } + return 0; +} +int checkResizeProc (int display, int event, int arg) { + OS.memmove (xConfigureEvent, event, XConfigureEvent.sizeof); + if (xConfigureEvent.window != resizeWindow) return 0; + switch (xConfigureEvent.type) { + case OS.ConfigureNotify: + int width = xConfigureEvent.width; + int height = xConfigureEvent.height; + if (width != resizeWidth || height != resizeHeight) { + resizeCount++; + } + break; + } + return 0; +} +static 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 (!Display.isValidClass (getClass ())) { + error (SWT.ERROR_INVALID_SUBCLASS); + } +} +/** + * Requests that the connection between SWT and the underlying + * operating system be closed. + * + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #dispose + * + * @since 2.0 */ -public void disposeExec (Runnable runnable) {
- checkDevice ();
- if (disposeList == null) disposeList = new Runnable [4];
- for (int i=0; i<disposeList.length; i++) {
- if (disposeList [i] == null) {
- disposeList [i] = runnable;
- return;
- }
- }
- Runnable [] newDisposeList = new Runnable [disposeList.length + 4];
- System.arraycopy (disposeList, 0, newDisposeList, 0, disposeList.length);
- newDisposeList [disposeList.length] = runnable;
- disposeList = newDisposeList;
-}
-void error (int code) {
- SWT.error(code);
-}
-boolean filterEvent (Event event) {
- if (filterTable != null) filterTable.sendEvent (event);
- return false;
-}
-boolean filters (int eventType) {
- if (filterTable == null) return false;
- return filterTable.hooks (eventType);
-}
-boolean filterEvent (XAnyEvent event) {
-
- /* Check the event and find the widget */
- if (event.type != OS.KeyPress) return false;
- OS.memmove (keyEvent, event, XKeyEvent.sizeof);
- if (keyEvent.keycode == 0) return false;
- int xWindow = keyEvent.window;
- if (xWindow == 0) return false;
- int handle = OS.XtWindowToWidget (xDisplay, xWindow);
- if (handle == 0) return false;
- handle = OS.XmGetFocusWidget (handle);
- if (handle == 0) return false;
- Widget widget = WidgetTable.get (handle);
- if (widget == null) return false;
-
- /* Get the unaffected character and keysym */
- int oldState = keyEvent.state;
- keyEvent.state = 0;
- byte [] buffer1 = new byte [4];
- int [] buffer2 = new int [1];
- int key = 0;
- if (OS.XLookupString (keyEvent, buffer1, 1, buffer2, null) != 0) {
- key = buffer1 [0] & 0xFF;
- }
- int keysym = buffer2 [0] & 0xFFFF;
- keyEvent.state = oldState;
-
- /*
- * Bug in AIX. If XFilterEvent() is called for every key event, accelerators
- * do not work. XFilterEvent() is needed on AIX to invoke the default button.
- * The fix is to call XFilterEvent() only for return keys. This means that an
- * accelerator that is only a return key will not work.
- */
- if (keysym == OS.XK_Return || keysym == OS.XK_KP_Enter) {
- /*
- * Bug in Linux. If XFilter() is called more than once for the same
- * event, it causes an infinite loop. The fix to remember the serial
- * number and never call XFilterEvent() twice for the same event.
- */
- if (event.serial != lastSerial) {
- if (OS.XFilterEvent (event, OS.XtWindow (handle))) return true;
- lastSerial = event.serial;
- }
- }
-
- /* Check for an accelerator key */
- if (widget.translateAccelerator (key, keysym, keyEvent)) return true;
-
- /* Check for a mnemonic key */
- if (key != 0) {
- if (widget.translateMnemonic (key, keyEvent)) return true;
- }
-
- /* Check for a traversal key */
- if (keysym == 0) return false;
- switch (keysym) {
- case OS.XK_Escape:
- case OS.XK_Cancel:
- case OS.XK_Tab:
- case OS.XK_KP_Enter:
- case OS.XK_Return:
- case OS.XK_Up:
- case OS.XK_Down:
- case OS.XK_Left:
- case OS.XK_Right:
- case OS.XK_Page_Up:
- case OS.XK_Page_Down:
- if (widget.translateTraversal (keysym, keyEvent)) return true;
- }
-
- /* Answer false because the event was not processed */
- return false;
-}
-/**
- * Given the operating system handle for a widget, returns
- * the instance of the <code>Widget</code> subclass which
- * represents it in the currently running application, if
- * such exists, or null if no matching widget can be found.
- *
- * @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 void close () { + checkDevice (); + Event event = new Event (); + sendEvent (SWT.Close, event); + if (event.doit) dispose (); +} +String convertToLf(String text) { + char Cr = '\r'; + char Lf = '\n'; + int length = text.length (); + if (length == 0) return text; + + /* Check for an LF or CR/LF. Assume the rest of the string + * is formated that way. This will not work if the string + * contains mixed delimiters. */ + int i = text.indexOf (Lf, 0); + if (i == -1 || i == 0) return text; + if (text.charAt (i - 1) != Cr) return text; + + /* The string is formatted with CR/LF. + * Create a new string with the LF line delimiter. */ + i = 0; + StringBuffer result = new StringBuffer (); + while (i < length) { + int j = text.indexOf (Cr, i); + if (j == -1) j = length; + String s = text.substring (i, j); + result.append (s); + i = j + 2; + result.append (Lf); + } + return result.toString (); +} +protected void create (DeviceData data) { + checkSubclass (); + checkDisplay (thread = Thread.currentThread ()); + createDisplay (data); + register (this); + if (Default == null) Default = this; +} +void createDisplay (DeviceData data) { + + /* Initialize X and Xt */ + synchronized (XInitLock) { + if (!XtInitialized) { + /* + * This code is intentionally commented. + */ +// OS.XInitThreads (); +// OS.XtToolkitThreadInitialize (); + OS.XtToolkitInitialize (); + } + XtInitialized = true; + } + + /* Create the AppContext */ + int [] argc = new int [] {0}; + int xtContext = OS.XtCreateApplicationContext (); + OS.XtSetLanguageProc (xtContext, 0, 0); + + /* + * Feature in Linux. On some DBCS Linux platforms, the default + * font is not be properly initialized to contain a font set. + * This causes the IME to fail. The fix is to set a fallback + * resource with an appropriated font to ensure a font set is + * found.
*/ + int ptr1 = 0, ptr2 = 0; + if (OS.IsLinux && OS.IsDBLocale) { + String resource = "*fontList: -*-*-medium-r-*-*-*-120-*-*-*-*-*-*:"; + byte [] buffer = Converter.wcsToMbcs (null, resource, true); + ptr1 = OS.XtMalloc (buffer.length); + if (ptr1 != 0) OS.memmove (ptr1, buffer, buffer.length); + int [] spec = new int[]{ptr1, 0}; + ptr2 = OS.XtMalloc (spec.length * 4); + if (ptr2 != 0)OS.memmove (ptr2, spec, spec.length * 4); + OS.XtAppSetFallbackResources(xtContext, ptr2); + } + + /* Compute the display name, application name and class */ + String display_name = null; + String application_name = APP_NAME; + String application_class = APP_NAME; + if (data != null) { + if (data.display_name != null) display_name = data.display_name; + if (data.application_name != null) application_name = data.application_name; + if (data.application_class != null) application_class = data.application_class; + } + /* Use the character encoding for the default locale */ + if (display_name != null) displayName = Converter.wcsToMbcs (null, display_name, true); + if (application_name != null) appName = Converter.wcsToMbcs (null, application_name, true); + if (application_class != null) appClass = Converter.wcsToMbcs (null, application_class, true); + + /* Create the XDisplay */ + xDisplay = OS.XtOpenDisplay (xtContext, displayName, appName, appClass, 0, 0, argc, 0); + DisplayDisposed = false; + + if (ptr2 != 0) { + OS.XtAppSetFallbackResources (xtContext, 0); + OS.XtFree (ptr2); + } + if (ptr1 != 0) OS.XtFree (ptr1); +} +synchronized static void deregister (Display display) { + for (int i=0; i<Displays.length; i++) { + if (display == Displays [i]) Displays [i] = null; + } +} +protected void destroy () { + if (this == Default) Default = null; + deregister (this); + destroyDisplay (); +} +void destroyDisplay () { + /* + * Bug in Motif. For some reason, XtAppCreateShell GP's when called + * after an application context has been destroyed. The fix is to + * destroy the default XmDisplay associated with the X Display for + * the application context. The following code fragment GP's without + * this work around: + * + * int xContext = OS.XtCreateApplicationContext(); + * int xDisplay = OS.XtOpenDisplay(xContext, null, null, null, null, 0, new int[1], null); + * OS.XtAppCreateShell(null, null, OS.topLevelShellWidgetClass(), xDisplay, null, 0); + * OS.XtDestroyApplicationContext(xContext); + * xContext = OS.XtCreateApplicationContext(); + * xDisplay = OS.XtOpenDisplay(xContext, null, null, null, null, 0, new int[1], null); + * OS.XtAppCreateShell(null, null, OS.topLevelShellWidgetClass(), xDisplay, null, 0); + * OS.XtDestroyApplicationContext(xContext); + */ + OS.XtDestroyWidget (OS.XmGetXmDisplay (xDisplay)); + + /* + * Destroy AppContext (this destroys the display) + */ + int xtContext = OS.XtDisplayToApplicationContext (xDisplay); + OS.XtDestroyApplicationContext (xtContext); + DisplayDisposed = true; +} +/** + * Causes the <code>run()</code> method of the runnable to + * be invoked by the user-interface thread just before the + * receiver is disposed. + * + * @param runnable code to run at dispose time. */ -public Widget findWidget (int handle) {
- checkDevice ();
- return WidgetTable.get (handle);
-}
-/**
- * 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 void disposeExec (Runnable runnable) { + checkDevice (); + if (disposeList == null) disposeList = new Runnable [4]; + for (int i=0; i<disposeList.length; i++) { + if (disposeList [i] == null) { + disposeList [i] = runnable; + return; + } + } + Runnable [] newDisposeList = new Runnable [disposeList.length + 4]; + System.arraycopy (disposeList, 0, newDisposeList, 0, disposeList.length); + newDisposeList [disposeList.length] = runnable; + disposeList = newDisposeList; +} +void error (int code) { + SWT.error(code); +} +boolean filterEvent (Event event) { + if (filterTable != null) filterTable.sendEvent (event); + return false; +} +boolean filters (int eventType) { + if (filterTable == null) return false; + return filterTable.hooks (eventType); +} +boolean filterEvent (XAnyEvent event) { + + /* Check the event and find the widget */ + if (event.type != OS.KeyPress) return false; + OS.memmove (keyEvent, event, XKeyEvent.sizeof); + if (keyEvent.keycode == 0) return false; + int xWindow = keyEvent.window; + if (xWindow == 0) return false; + int handle = OS.XtWindowToWidget (xDisplay, xWindow); + if (handle == 0) return false; + handle = OS.XmGetFocusWidget (handle); + if (handle == 0) return false; + Widget widget = WidgetTable.get (handle); + if (widget == null) return false; + + /* Get the unaffected character and keysym */ + int oldState = keyEvent.state; + keyEvent.state = 0; + byte [] buffer1 = new byte [4]; + int [] buffer2 = new int [1]; + int key = 0; + if (OS.XLookupString (keyEvent, buffer1, 1, buffer2, null) != 0) { + key = buffer1 [0] & 0xFF; + } + int keysym = buffer2 [0] & 0xFFFF; + keyEvent.state = oldState; + + /* + * Bug in AIX. If XFilterEvent() is called for every key event, accelerators + * do not work. XFilterEvent() is needed on AIX to invoke the default button. + * The fix is to call XFilterEvent() only for return keys. This means that an + * accelerator that is only a return key will not work. + */ + if (keysym == OS.XK_Return || keysym == OS.XK_KP_Enter) { + /* + * Bug in Linux. If XFilter() is called more than once for the same + * event, it causes an infinite loop. The fix to remember the serial + * number and never call XFilterEvent() twice for the same event. + */ + if (event.serial != lastSerial) { + if (OS.XFilterEvent (event, OS.XtWindow (handle))) return true; + lastSerial = event.serial; + } + } + + /* Check for an accelerator key */ + if (widget.translateAccelerator (key, keysym, keyEvent)) return true; + + /* Check for a mnemonic key */ + if (key != 0) { + if (widget.translateMnemonic (key, keyEvent)) return true; + } + + /* Check for a traversal key */ + if (keysym == 0) return false; + switch (keysym) { + case OS.XK_Escape: + case OS.XK_Cancel: + case OS.XK_Tab: + case OS.XK_KP_Enter: + case OS.XK_Return: + case OS.XK_Up: + case OS.XK_Down: + case OS.XK_Left: + case OS.XK_Right: + case OS.XK_Page_Up: + case OS.XK_Page_Down: + if (widget.translateTraversal (keysym, keyEvent)) return true; + } + + /* Answer false because the event was not processed */ + return false; +} +/** + * Given the operating system handle for a widget, returns + * the instance of the <code>Widget</code> subclass which + * represents it in the currently running application, if + * such exists, or null if no matching widget can be found. + * + * @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 Shell getActiveShell () {
- checkDevice ();
- int [] buffer1 = new int [1], buffer2 = new int [1];
- OS.XGetInputFocus (xDisplay, buffer1, buffer2);
- int xWindow = buffer1 [0];
- if (xWindow == 0) return null;
- int handle = OS.XtWindowToWidget (xDisplay, xWindow);
- if (handle == 0) return null;
- do {
- if (OS.XtIsSubclass (handle, OS.ShellWidgetClass ())) {
- Widget widget = WidgetTable.get (handle);
- if (widget instanceof Shell) return (Shell) widget;
- return null;
- }
- } while ((handle = OS.XtParent (handle)) != 0);
- return null;
-}
-/**
- * Returns the display which the currently running thread is
- * the user-interface thread for, or null if the currently
- * running thread is not a user-interface thread for any display.
- *
- * @return the current display
+public Widget findWidget (int handle) { + checkDevice (); + return WidgetTable.get (handle); +} +/** + * 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 static synchronized Display getCurrent () {
- return findDisplay (Thread.currentThread ());
-}
-/**
- * Returns the display which the given thread is the
- * user-interface thread for, or null if the given thread
- * is not a user-interface thread for any display.
- *
- * @param thread the user-interface thread
- * @return the display for the given thread
+public Shell getActiveShell () { + checkDevice (); + int [] buffer1 = new int [1], buffer2 = new int [1]; + OS.XGetInputFocus (xDisplay, buffer1, buffer2); + int xWindow = buffer1 [0]; + if (xWindow == 0) return null; + int handle = OS.XtWindowToWidget (xDisplay, xWindow); + if (handle == 0) return null; + do { + if (OS.XtIsSubclass (handle, OS.ShellWidgetClass ())) { + Widget widget = WidgetTable.get (handle); + if (widget instanceof Shell) return (Shell) widget; + return null; + } + } while ((handle = OS.XtParent (handle)) != 0); + return null; +} +/** + * Returns the display which the currently running thread is + * the user-interface thread for, or null if the currently + * running thread is not a user-interface thread for any display. + * + * @return the current display */ -public static 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;
-}
-/**
- * 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 static synchronized Display getCurrent () { + return findDisplay (Thread.currentThread ()); +} +/** + * Returns the display which the given thread is the + * user-interface thread for, or null if the given thread + * is not a user-interface thread for any display. + * + * @param thread the user-interface thread + * @return the display for the given thread */ -public Control getCursorControl () {
- checkDevice ();
- int [] unused = new int [1], buffer = new int [1];
- int xWindow, xParent = OS.XDefaultRootWindow (xDisplay);
- do {
- if (OS.XQueryPointer (xDisplay, xParent, unused, buffer, unused, unused, unused, unused, unused) == 0) {
- return null;
- }
- if ((xWindow = buffer [0]) != 0) xParent = xWindow;
- } while (xWindow != 0);
- int handle = OS.XtWindowToWidget (xDisplay, xParent);
- if (handle == 0) return null;
- do {
- Widget widget = WidgetTable.get (handle);
- if (widget != null && widget instanceof Control) {
- Control control = (Control) widget;
- if (control.getEnabled ()) return control;
- }
- } while ((handle = OS.XtParent (handle)) != 0);
- return null;
-}
-/**
- * Returns the location of the on-screen pointer relative
- * to the top left corner of the screen.
- *
- * @return the cursor location
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+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; +} +/** + * 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 Point getCursorLocation () {
- checkDevice ();
- int window = OS.XDefaultRootWindow (xDisplay);
- int [] rootX = new int [1], rootY = new int [1], unused = new int [1];
- OS.XQueryPointer (xDisplay, window, unused, unused, rootX, rootY, unused, unused, unused);
- return new Point (rootX [0], rootY [0]);
-}
-/**
- * Returns 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 Control getCursorControl () { + checkDevice (); + int [] unused = new int [1], buffer = new int [1]; + int xWindow, xParent = OS.XDefaultRootWindow (xDisplay); + do { + if (OS.XQueryPointer (xDisplay, xParent, unused, buffer, unused, unused, unused, unused, unused) == 0) { + return null; + } + if ((xWindow = buffer [0]) != 0) xParent = xWindow; + } while (xWindow != 0); + int handle = OS.XtWindowToWidget (xDisplay, xParent); + if (handle == 0) return null; + do { + Widget widget = WidgetTable.get (handle); + if (widget != null && widget instanceof Control) { + Control control = (Control) widget; + if (control.getEnabled ()) return control; + } + } while ((handle = OS.XtParent (handle)) != 0); + return null; +} +/** + * Returns the location of the on-screen pointer relative + * to the top left corner of the screen. + * + * @return the cursor location + * + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public static synchronized Display getDefault () {
- if (Default == null) Default = new Display ();
- return Default;
-}
-/**
- * Returns the application defined property of the receiver
- * with the specified name, or null if it has not been set.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the display is disposed
- * of, it is the application's responsibility 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 Point getCursorLocation () { + checkDevice (); + int window = OS.XDefaultRootWindow (xDisplay); + int [] rootX = new int [1], rootY = new int [1], unused = new int [1]; + OS.XQueryPointer (xDisplay, window, unused, unused, rootX, rootY, unused, unused, unused); + return new Point (rootX [0], rootY [0]); +} +/** + * Returns 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 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 static synchronized Display getDefault () { + if (Default == null) Default = new Display (); + return Default; +} +/** + * Returns the application defined property of the receiver + * with the specified name, or null if it has not been set. + * <p> + * Applications may have associated arbitrary objects with the + * receiver in this fashion. If the objects stored in the + * properties need to be notified when the display is disposed + * of, it is the application's responsibility 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 () {
- checkDevice ();
- return data;
-}
-public int getDismissalAlignment () {
- checkDevice ();
- return SWT.LEFT;
-}
-/**
- * Returns the longest duration, in milliseconds, between
- * two mouse button clicks that will be considered a
- * <em>double click</em> by the underlying operating system.
- *
- * @return the double click time
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+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 int getDoubleClickTime () {
- checkDevice ();
- return OS.XtGetMultiClickTime (xDisplay);
-}
-/**
- * Returns the control which currently has keyboard focus,
- * or null if keyboard events are not currently going to
- * any of the controls built by the currently running
- * application.
- *
- * @return the control under the cursor
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public Object getData () { + checkDevice (); + return data; +} +public int getDismissalAlignment () { + checkDevice (); + return SWT.LEFT; +} +/** + * Returns the longest duration, in milliseconds, between + * two mouse button clicks that will be considered a + * <em>double click</em> by the underlying operating system. + * + * @return the double click time + * + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public Control getFocusControl () {
- checkDevice ();
- int [] buffer1 = new int [1], buffer2 = new int [1];
- OS.XGetInputFocus (xDisplay, buffer1, buffer2);
- int xWindow = buffer1 [0];
- if (xWindow == 0) return null;
- int handle = OS.XtWindowToWidget (xDisplay, xWindow);
- if (handle == 0) return null;
- handle = OS.XmGetFocusWidget (handle);
- if (handle == 0) return null;
- do {
- Widget widget = WidgetTable.get (handle);
- if (widget != null && widget instanceof Control) {
- Control window = (Control) widget;
- if (window.getEnabled ()) return window;
- }
- } while ((handle = OS.XtParent (handle)) != 0);
- return null;
-}
-/**
- * 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 getDoubleClickTime () { + checkDevice (); + return OS.XtGetMultiClickTime (xDisplay); +} +/** + * Returns the control which currently has keyboard focus, + * or null if keyboard events are not currently going to + * any of the controls built by the currently running + * application. + * + * @return the control under the cursor + * + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getIconDepth () {
- return getDepth ();
-}
-int getLastEventTime () {
- return OS.XtLastTimestampProcessed (xDisplay);
-}
-/**
- * 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 Control getFocusControl () { + checkDevice (); + int [] buffer1 = new int [1], buffer2 = new int [1]; + OS.XGetInputFocus (xDisplay, buffer1, buffer2); + int xWindow = buffer1 [0]; + if (xWindow == 0) return null; + int handle = OS.XtWindowToWidget (xDisplay, xWindow); + if (handle == 0) return null; + handle = OS.XmGetFocusWidget (handle); + if (handle == 0) return null; + do { + Widget widget = WidgetTable.get (handle); + if (widget != null && widget instanceof Control) { + Control window = (Control) widget; + if (window.getEnabled ()) return window; + } + } while ((handle = OS.XtParent (handle)) != 0); + return null; +} +/** + * 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 Shell [] getShells () {
- checkDevice ();
- /*
- * NOTE: Need to check that the shells that belong
- * to another display have not been disposed by the
- * other display's thread as the shells list is being
- * processed.
- */
- 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++;
- }
- }
- if (count == shells.length) return shells;
- 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 int getIconDepth () { + return getDepth (); +} +int getLastEventTime () { + return OS.XtLastTimestampProcessed (xDisplay); +} +/** + * 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 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 Shell [] getShells () { + checkDevice (); + /* + * NOTE: Need to check that the shells that belong + * to another display have not been disposed by the + * other display's thread as the shells list is being + * processed. + */ + 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++; + } + } + if (count == shells.length) return shells; + 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 Color getSystemColor (int id) {
- checkDevice ();
- XColor xColor = null;
- switch (id) {
- case SWT.COLOR_INFO_FOREGROUND: return super.getSystemColor (SWT.COLOR_BLACK);
- case SWT.COLOR_INFO_BACKGROUND: return COLOR_INFO_BACKGROUND;
- case SWT.COLOR_TITLE_FOREGROUND: return super.getSystemColor (SWT.COLOR_WHITE);
- case SWT.COLOR_TITLE_BACKGROUND: return super.getSystemColor (SWT.COLOR_DARK_BLUE);
- case SWT.COLOR_TITLE_BACKGROUND_GRADIENT: return super.getSystemColor (SWT.COLOR_BLUE);
- case SWT.COLOR_TITLE_INACTIVE_FOREGROUND: return super.getSystemColor (SWT.COLOR_BLACK);
- case SWT.COLOR_TITLE_INACTIVE_BACKGROUND: return super.getSystemColor (SWT.COLOR_DARK_GRAY);
- case SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT: return super.getSystemColor (SWT.COLOR_GRAY);
- case SWT.COLOR_WIDGET_DARK_SHADOW: xColor = COLOR_WIDGET_DARK_SHADOW; break;
- case SWT.COLOR_WIDGET_NORMAL_SHADOW: xColor = COLOR_WIDGET_NORMAL_SHADOW; break;
- case SWT.COLOR_WIDGET_LIGHT_SHADOW: xColor = COLOR_WIDGET_LIGHT_SHADOW; break;
- case SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: xColor = COLOR_WIDGET_HIGHLIGHT_SHADOW; break;
- case SWT.COLOR_WIDGET_BACKGROUND: xColor = COLOR_WIDGET_BACKGROUND; break;
- case SWT.COLOR_WIDGET_FOREGROUND: xColor = COLOR_WIDGET_FOREGROUND; break;
- case SWT.COLOR_WIDGET_BORDER: xColor = COLOR_WIDGET_BORDER; break;
- case SWT.COLOR_LIST_FOREGROUND: xColor = COLOR_LIST_FOREGROUND; break;
- case SWT.COLOR_LIST_BACKGROUND: xColor = COLOR_LIST_BACKGROUND; break;
- case SWT.COLOR_LIST_SELECTION: xColor = COLOR_LIST_SELECTION; break;
- case SWT.COLOR_LIST_SELECTION_TEXT: xColor = COLOR_LIST_SELECTION_TEXT; break;
- default:
- return super.getSystemColor (id);
- }
- if (xColor == null) return super.getSystemColor (SWT.COLOR_BLACK);
- return Color.motif_new (this, xColor);
-}
-/**
- * Returns 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 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 (); + XColor xColor = null; + switch (id) { + case SWT.COLOR_INFO_FOREGROUND: return super.getSystemColor (SWT.COLOR_BLACK); + case SWT.COLOR_INFO_BACKGROUND: return COLOR_INFO_BACKGROUND; + case SWT.COLOR_TITLE_FOREGROUND: return super.getSystemColor (SWT.COLOR_WHITE); + case SWT.COLOR_TITLE_BACKGROUND: return super.getSystemColor (SWT.COLOR_DARK_BLUE); + case SWT.COLOR_TITLE_BACKGROUND_GRADIENT: return super.getSystemColor (SWT.COLOR_BLUE); + case SWT.COLOR_TITLE_INACTIVE_FOREGROUND: return super.getSystemColor (SWT.COLOR_BLACK); + case SWT.COLOR_TITLE_INACTIVE_BACKGROUND: return super.getSystemColor (SWT.COLOR_DARK_GRAY); + case SWT.COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT: return super.getSystemColor (SWT.COLOR_GRAY); + case SWT.COLOR_WIDGET_DARK_SHADOW: xColor = COLOR_WIDGET_DARK_SHADOW; break; + case SWT.COLOR_WIDGET_NORMAL_SHADOW: xColor = COLOR_WIDGET_NORMAL_SHADOW; break; + case SWT.COLOR_WIDGET_LIGHT_SHADOW: xColor = COLOR_WIDGET_LIGHT_SHADOW; break; + case SWT.COLOR_WIDGET_HIGHLIGHT_SHADOW: xColor = COLOR_WIDGET_HIGHLIGHT_SHADOW; break; + case SWT.COLOR_WIDGET_BACKGROUND: xColor = COLOR_WIDGET_BACKGROUND; break; + case SWT.COLOR_WIDGET_FOREGROUND: xColor = COLOR_WIDGET_FOREGROUND; break; + case SWT.COLOR_WIDGET_BORDER: xColor = COLOR_WIDGET_BORDER; break; + case SWT.COLOR_LIST_FOREGROUND: xColor = COLOR_LIST_FOREGROUND; break; + case SWT.COLOR_LIST_BACKGROUND: xColor = COLOR_LIST_BACKGROUND; break; + case SWT.COLOR_LIST_SELECTION: xColor = COLOR_LIST_SELECTION; break; + case SWT.COLOR_LIST_SELECTION_TEXT: xColor = COLOR_LIST_SELECTION_TEXT; break; + default: + return super.getSystemColor (id); + } + if (xColor == null) return super.getSystemColor (SWT.COLOR_BLACK); + return Color.motif_new (this, xColor); +} +/** + * Returns 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 ();
- return defaultFont;
-}
-/**
- * Returns the user-interface thread for the receiver.
- *
- * @return the receiver's user-interface thread
+public Font getSystemFont () { + checkDevice (); + return defaultFont; +} +/** + * 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;
-}
-void hideToolTip () {
- if (toolTipHandle != 0) {
- int shellHandle = OS.XtParent(toolTipHandle);
- OS.XtDestroyWidget(shellHandle);
- }
- toolTipHandle = 0;
-}
-protected void init () {
- super.init ();
- initializeDisplay ();
- initializeButton ();
- initializeComposite ();
- initializeDialog ();
- initializeLabel ();
- initializeList ();
- initializeScrollBar ();
- initializeText ();
- initializeSystemColors ();
- initializeDefaults ();
- initializeTranslations ();
-}
-void initializeButton () {
-
- int shellHandle, widgetHandle;
- int widgetClass = OS.TopLevelShellWidgetClass ();
-
- /* Get the push button information */
- shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
- widgetHandle = OS.XmCreatePushButton (shellHandle, null, null, 0);
- OS.XtManageChild (widgetHandle);
- OS.XtSetMappedWhenManaged (shellHandle, false);
- OS.XtRealizeWidget (shellHandle);
- int [] argList = {
- OS.XmNforeground, 0, /* 1 */
- OS.XmNbackground, 0, /* 3 */
- OS.XmNshadowThickness, 0, /* 5 */
- OS.XmNfontList, 0, /* 7 */
- };
- OS.XtGetValues (widgetHandle, argList, argList.length / 2);
- buttonForeground = argList [1]; buttonBackground = argList [3];
- buttonShadowThickness = argList [5];
- /*
- * Feature in Motif. Querying the font list from the widget and
- * then destroying the shell (and the widget) could cause the
- * font list to be freed as well. The fix is to make a copy of
- * the font list, then to free it when the display is disposed.
+public Thread getThread () { + if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); + return thread; +} +void hideToolTip () { + if (toolTipHandle != 0) { + int shellHandle = OS.XtParent(toolTipHandle); + OS.XtDestroyWidget(shellHandle); + } + toolTipHandle = 0; +} +protected void init () { + super.init (); + initializeDisplay (); + initializeButton (); + initializeComposite (); + initializeDialog (); + initializeLabel (); + initializeList (); + initializeScrollBar (); + initializeText (); + initializeSystemColors (); + initializeDefaults (); + initializeTranslations (); +} +void initializeButton () { + + int shellHandle, widgetHandle; + int widgetClass = OS.TopLevelShellWidgetClass (); + + /* Get the push button information */ + shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0); + widgetHandle = OS.XmCreatePushButton (shellHandle, null, null, 0); + OS.XtManageChild (widgetHandle); + OS.XtSetMappedWhenManaged (shellHandle, false); + OS.XtRealizeWidget (shellHandle); + int [] argList = { + OS.XmNforeground, 0, /* 1 */ + OS.XmNbackground, 0, /* 3 */ + OS.XmNshadowThickness, 0, /* 5 */ + OS.XmNfontList, 0, /* 7 */ + }; + OS.XtGetValues (widgetHandle, argList, argList.length / 2); + buttonForeground = argList [1]; buttonBackground = argList [3]; + buttonShadowThickness = argList [5]; + /* + * Feature in Motif. Querying the font list from the widget and + * then destroying the shell (and the widget) could cause the + * font list to be freed as well. The fix is to make a copy of + * the font list, then to free it when the display is disposed. */ -
- buttonFont = Font.motif_new (this, OS.XmFontListCopy (argList [7]));
- OS.XtDestroyWidget (shellHandle);
-}
-void initializeComposite () {
- int widgetClass = OS.TopLevelShellWidgetClass ();
- int shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
- int scrolledHandle = OS.XmCreateMainWindow (shellHandle, null, null, 0);
- int [] argList1 = {OS.XmNorientation, OS.XmHORIZONTAL};
- int hScrollHandle = OS.XmCreateScrollBar (scrolledHandle, null, argList1, argList1.length / 2);
- OS.XtManageChild (hScrollHandle);
- int [] argList2 = {OS.XmNorientation, OS.XmVERTICAL};
- int vScrollHandle = OS.XmCreateScrollBar (scrolledHandle, null, argList2, argList2.length / 2);
- OS.XtManageChild (vScrollHandle);
- OS.XtManageChild (scrolledHandle);
- int [] argList5 = {
- OS.XmNmarginWidth, 3,
- OS.XmNmarginHeight, 3,
- };
- int formHandle = OS.XmCreateForm (scrolledHandle, null, argList5, argList5.length / 2);
- OS.XtManageChild (formHandle);
- int [] argList6 = {
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNtopAttachment, OS.XmATTACH_FORM,
- OS.XmNbottomAttachment, OS.XmATTACH_FORM,
- OS.XmNleftAttachment, OS.XmATTACH_FORM,
- OS.XmNrightAttachment, OS.XmATTACH_FORM,
- };
- int widgetHandle = OS.XmCreateDrawingArea (formHandle, null, argList6, argList6.length / 2);
- OS.XtManageChild (widgetHandle);
- OS.XmMainWindowSetAreas (scrolledHandle, 0, 0, hScrollHandle, vScrollHandle, formHandle);
- OS.XtSetMappedWhenManaged (shellHandle, false);
- int screen = OS.XDefaultScreen (xDisplay);
- OS.XtResizeWidget (shellHandle, OS.XDisplayWidth (xDisplay, screen), OS.XDisplayHeight (xDisplay, screen), 0);
- OS.XtRealizeWidget (shellHandle);
- int [] argList3 = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (scrolledHandle, argList3, argList3.length / 2);
- int [] argList8 = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (formHandle, argList8, argList8.length / 2);
- int [] argList4 = {
- OS.XmNx, 0, /* 1 */
- OS.XmNy, 0, /* 3 */
- OS.XmNwidth, 0, /* 5 */
- OS.XmNheight, 0, /* 7 */
- OS.XmNforeground, 0, /* 9 */
- OS.XmNbackground, 0, /* 11 */
- OS.XmNtopShadowColor, 0, /* 13 */
- OS.XmNbottomShadowColor, 0, /* 15 */
- OS.XmNborderColor, 0, /* 17 */
- };
- OS.XtGetValues (widgetHandle, argList4, argList4.length / 2);
- scrolledInsetX = argList4 [1] + argList8 [1];
- scrolledInsetY = argList4 [3] + argList8 [3];
- scrolledMarginX = argList3 [1] - argList8 [1] - argList4 [1] - argList4 [5];
- scrolledMarginY = argList3 [3] - argList8 [3] - argList4 [3] - argList4 [7];
- compositeForeground = argList4 [9]; compositeBackground = argList4 [11];
- compositeTopShadow = argList4 [13]; compositeBottomShadow = argList4 [15];
- compositeBorder = argList4 [17];
- OS.XtDestroyWidget (shellHandle);
-}
-void initializeDefaults () {
- defaultFont = labelFont;
- defaultForeground = compositeForeground;
- defaultBackground = compositeBackground;
-}
-void initializeDialog () {
- int shellHandle, widgetHandle;
- int widgetClass = OS.TopLevelShellWidgetClass ();
- shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
- widgetHandle = OS.XmCreateDialogShell (shellHandle, null, null, 0);
- OS.XtSetMappedWhenManaged (shellHandle, false);
- OS.XtRealizeWidget (shellHandle);
- int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0};
- OS.XtGetValues (widgetHandle, argList, argList.length / 2);
- dialogForeground = argList [1]; dialogBackground = argList [3];
- OS.XtDestroyWidget (shellHandle);
-}
-void initializeDisplay () {
-
- /* Create the callbacks */
- windowCallback = new Callback (this, "windowProc", 4);
- windowProc = windowCallback.getAddress ();
- if (windowProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- windowTimerCallback = new Callback (this, "windowTimerProc", 2);
- windowTimerProc = windowTimerCallback.getAddress ();
- if (windowTimerProc == 0) 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);
- mouseHoverCallback = new Callback (this, "mouseHoverProc", 2);
- mouseHoverProc = mouseHoverCallback.getAddress ();
- if (mouseHoverProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- checkExposeCallback = new Callback (this, "checkExposeProc", 3);
- checkExposeProc = checkExposeCallback.getAddress ();
- if (checkExposeProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- checkResizeCallback = new Callback (this, "checkResizeProc", 3);
- checkResizeProc = checkResizeCallback.getAddress ();
- if (checkResizeProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- wakeCallback = new Callback (this, "wakeProc", 3);
- wakeProc = wakeCallback.getAddress ();
- if (wakeProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
-
- /* Create and install the pipe used to wake up from sleep */
- int [] filedes = new int [2];
- if (OS.pipe (filedes) != 0) error (SWT.ERROR_NO_HANDLES);
- read_fd = filedes [0]; write_fd = filedes [1];
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- inputID = OS.XtAppAddInput (xtContext, read_fd, OS.XtInputReadMask, wakeProc, 0);
- fd_set = new byte [OS.fd_set_sizeof ()];
-
- /*
- * Use dynamic Drag and Drop Protocol styles.
- * Preregistered protocol is not supported.
- */
- int xmDisplay = OS.XmGetXmDisplay (xDisplay);
- int [] args = new int [] {
- OS.XmNenableThinThickness, 1,
- OS.XmNdragInitiatorProtocolStyle, OS.XmDRAG_DYNAMIC,
- OS.XmNdragReceiverProtocolStyle, OS.XmDRAG_DYNAMIC,
- };
- OS.XtSetValues (xmDisplay, args, args.length / 2);
-
- /* Create the hidden Override shell parent */
- int xScreen = OS.XDefaultScreen (xDisplay);
- int widgetClass = OS.TopLevelShellWidgetClass ();
- shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
- OS.XtSetMappedWhenManaged (shellHandle, false);
- OS.XtResizeWidget (shellHandle, OS.XDisplayWidth (xDisplay, xScreen), OS.XDisplayHeight (xDisplay, xScreen), 0);
- OS.XtRealizeWidget (shellHandle);
-
- /*
- * Bug in MOTIF. For some reason, calls to XmGetPixmap ()
- * and XmGetPixmapByDepth fail to find the pixmap unless at
- * least one message box has been created. The fix is to
- * create and destroy a message box.
- */
-// int dialog = OS.XmCreateInformationDialog (shellHandle, null, null, 0);
-// OS.XtDestroyWidget (dialog);
-}
-void initializeLabel () {
- int shellHandle, widgetHandle;
- int widgetClass = OS.TopLevelShellWidgetClass ();
- shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
-
- /*
- * Bug in Motif. When running on UTF-8, Motif becomes unstable and
- * GP's some time later when a label widget is created with empty
- * text. The fix is to create the label with a non-empty string.
- */
- byte [] buffer = Converter.wcsToMbcs(null, "string", true);
- widgetHandle = OS.XmCreateLabel (shellHandle, buffer, null, 0);
- OS.XtManageChild (widgetHandle);
- OS.XtSetMappedWhenManaged (shellHandle, false);
- OS.XtRealizeWidget (shellHandle);
- int [] argList2 = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNfontList, 0};
- OS.XtGetValues (widgetHandle, argList2, argList2.length / 2);
- labelForeground = argList2 [1]; labelBackground = argList2 [3];
- /*
- * Feature in Motif. Querying the font list from the widget and
- * then destroying the shell (and the widget) could cause the
- * font list to be freed as well. The fix is to make a copy of
- * the font list, then to free it when the display is disposed.
+ + buttonFont = Font.motif_new (this, OS.XmFontListCopy (argList [7])); + OS.XtDestroyWidget (shellHandle); +} +void initializeComposite () { + int widgetClass = OS.TopLevelShellWidgetClass (); + int shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0); + int scrolledHandle = OS.XmCreateMainWindow (shellHandle, null, null, 0); + int [] argList1 = {OS.XmNorientation, OS.XmHORIZONTAL}; + int hScrollHandle = OS.XmCreateScrollBar (scrolledHandle, null, argList1, argList1.length / 2); + OS.XtManageChild (hScrollHandle); + int [] argList2 = {OS.XmNorientation, OS.XmVERTICAL}; + int vScrollHandle = OS.XmCreateScrollBar (scrolledHandle, null, argList2, argList2.length / 2); + OS.XtManageChild (vScrollHandle); + OS.XtManageChild (scrolledHandle); + int [] argList5 = { + OS.XmNmarginWidth, 3, + OS.XmNmarginHeight, 3, + }; + int formHandle = OS.XmCreateForm (scrolledHandle, null, argList5, argList5.length / 2); + OS.XtManageChild (formHandle); + int [] argList6 = { + OS.XmNmarginWidth, 0, + OS.XmNmarginHeight, 0, + OS.XmNresizePolicy, OS.XmRESIZE_NONE, + OS.XmNtopAttachment, OS.XmATTACH_FORM, + OS.XmNbottomAttachment, OS.XmATTACH_FORM, + OS.XmNleftAttachment, OS.XmATTACH_FORM, + OS.XmNrightAttachment, OS.XmATTACH_FORM, + }; + int widgetHandle = OS.XmCreateDrawingArea (formHandle, null, argList6, argList6.length / 2); + OS.XtManageChild (widgetHandle); + OS.XmMainWindowSetAreas (scrolledHandle, 0, 0, hScrollHandle, vScrollHandle, formHandle); + OS.XtSetMappedWhenManaged (shellHandle, false); + int screen = OS.XDefaultScreen (xDisplay); + OS.XtResizeWidget (shellHandle, OS.XDisplayWidth (xDisplay, screen), OS.XDisplayHeight (xDisplay, screen), 0); + OS.XtRealizeWidget (shellHandle); + int [] argList3 = {OS.XmNwidth, 0, OS.XmNheight, 0}; + OS.XtGetValues (scrolledHandle, argList3, argList3.length / 2); + int [] argList8 = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0}; + OS.XtGetValues (formHandle, argList8, argList8.length / 2); + int [] argList4 = { + OS.XmNx, 0, /* 1 */ + OS.XmNy, 0, /* 3 */ + OS.XmNwidth, 0, /* 5 */ + OS.XmNheight, 0, /* 7 */ + OS.XmNforeground, 0, /* 9 */ + OS.XmNbackground, 0, /* 11 */ + OS.XmNtopShadowColor, 0, /* 13 */ + OS.XmNbottomShadowColor, 0, /* 15 */ + OS.XmNborderColor, 0, /* 17 */ + }; + OS.XtGetValues (widgetHandle, argList4, argList4.length / 2); + scrolledInsetX = argList4 [1] + argList8 [1]; + scrolledInsetY = argList4 [3] + argList8 [3]; + scrolledMarginX = argList3 [1] - argList8 [1] - argList4 [1] - argList4 [5]; + scrolledMarginY = argList3 [3] - argList8 [3] - argList4 [3] - argList4 [7]; + compositeForeground = argList4 [9]; compositeBackground = argList4 [11]; + compositeTopShadow = argList4 [13]; compositeBottomShadow = argList4 [15]; + compositeBorder = argList4 [17]; + OS.XtDestroyWidget (shellHandle); +} +void initializeDefaults () { + defaultFont = labelFont; + defaultForeground = compositeForeground; + defaultBackground = compositeBackground; +} +void initializeDialog () { + int shellHandle, widgetHandle; + int widgetClass = OS.TopLevelShellWidgetClass (); + shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0); + widgetHandle = OS.XmCreateDialogShell (shellHandle, null, null, 0); + OS.XtSetMappedWhenManaged (shellHandle, false); + OS.XtRealizeWidget (shellHandle); + int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0}; + OS.XtGetValues (widgetHandle, argList, argList.length / 2); + dialogForeground = argList [1]; dialogBackground = argList [3]; + OS.XtDestroyWidget (shellHandle); +} +void initializeDisplay () { + + /* Create the callbacks */ + windowCallback = new Callback (this, "windowProc", 4); + windowProc = windowCallback.getAddress (); + if (windowProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + windowTimerCallback = new Callback (this, "windowTimerProc", 2); + windowTimerProc = windowTimerCallback.getAddress (); + if (windowTimerProc == 0) 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); + mouseHoverCallback = new Callback (this, "mouseHoverProc", 2); + mouseHoverProc = mouseHoverCallback.getAddress (); + if (mouseHoverProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + checkExposeCallback = new Callback (this, "checkExposeProc", 3); + checkExposeProc = checkExposeCallback.getAddress (); + if (checkExposeProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + checkResizeCallback = new Callback (this, "checkResizeProc", 3); + checkResizeProc = checkResizeCallback.getAddress (); + if (checkResizeProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + wakeCallback = new Callback (this, "wakeProc", 3); + wakeProc = wakeCallback.getAddress (); + if (wakeProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + + /* Create and install the pipe used to wake up from sleep */ + int [] filedes = new int [2]; + if (OS.pipe (filedes) != 0) error (SWT.ERROR_NO_HANDLES); + read_fd = filedes [0]; write_fd = filedes [1]; + int xtContext = OS.XtDisplayToApplicationContext (xDisplay); + inputID = OS.XtAppAddInput (xtContext, read_fd, OS.XtInputReadMask, wakeProc, 0); + fd_set = new byte [OS.fd_set_sizeof ()]; + + /* + * Use dynamic Drag and Drop Protocol styles. + * Preregistered protocol is not supported. + */ + int xmDisplay = OS.XmGetXmDisplay (xDisplay); + int [] args = new int [] { + OS.XmNenableThinThickness, 1, + OS.XmNdragInitiatorProtocolStyle, OS.XmDRAG_DYNAMIC, + OS.XmNdragReceiverProtocolStyle, OS.XmDRAG_DYNAMIC, + }; + OS.XtSetValues (xmDisplay, args, args.length / 2); + + /* Create the hidden Override shell parent */ + int xScreen = OS.XDefaultScreen (xDisplay); + int widgetClass = OS.TopLevelShellWidgetClass (); + shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0); + OS.XtSetMappedWhenManaged (shellHandle, false); + OS.XtResizeWidget (shellHandle, OS.XDisplayWidth (xDisplay, xScreen), OS.XDisplayHeight (xDisplay, xScreen), 0); + OS.XtRealizeWidget (shellHandle); + + /* + * Bug in MOTIF. For some reason, calls to XmGetPixmap () + * and XmGetPixmapByDepth fail to find the pixmap unless at + * least one message box has been created. The fix is to + * create and destroy a message box. + */ +// int dialog = OS.XmCreateInformationDialog (shellHandle, null, null, 0); +// OS.XtDestroyWidget (dialog); +} +void initializeLabel () { + int shellHandle, widgetHandle; + int widgetClass = OS.TopLevelShellWidgetClass (); + shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0); + + /* + * Bug in Motif. When running on UTF-8, Motif becomes unstable and + * GP's some time later when a label widget is created with empty + * text. The fix is to create the label with a non-empty string. + */ + byte [] buffer = Converter.wcsToMbcs(null, "string", true); + widgetHandle = OS.XmCreateLabel (shellHandle, buffer, null, 0); + OS.XtManageChild (widgetHandle); + OS.XtSetMappedWhenManaged (shellHandle, false); + OS.XtRealizeWidget (shellHandle); + int [] argList2 = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNfontList, 0}; + OS.XtGetValues (widgetHandle, argList2, argList2.length / 2); + labelForeground = argList2 [1]; labelBackground = argList2 [3]; + /* + * Feature in Motif. Querying the font list from the widget and + * then destroying the shell (and the widget) could cause the + * font list to be freed as well. The fix is to make a copy of + * the font list, then to free it when the display is disposed. */ -
- labelFont = Font.motif_new (this, OS.XmFontListCopy (argList2 [5]));
- OS.XtDestroyWidget (shellHandle);
-}
-void initializeList () {
- int shellHandle, widgetHandle;
- int widgetClass = OS.TopLevelShellWidgetClass ();
- shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
- widgetHandle = OS.XmCreateScrolledList (shellHandle, new byte [0], null, 0);
- OS.XtManageChild (widgetHandle);
- OS.XtSetMappedWhenManaged (shellHandle, false);
- OS.XtRealizeWidget (shellHandle);
- int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNfontList, 0, OS.XmNselectColor, 0, OS.XmNhighlightColor, 0};
- OS.XtGetValues (widgetHandle, argList, argList.length / 2);
- listForeground = argList [1];
- listBackground = argList [3];
-
- /*
- * Feature in Motif. Querying the font list from the widget and
- * then destroying the shell (and the widget) could cause the
- * font list to be freed as well. The fix is to make a copy of
- * the font list, then to free it when the display is disposed.
+ + labelFont = Font.motif_new (this, OS.XmFontListCopy (argList2 [5])); + OS.XtDestroyWidget (shellHandle); +} +void initializeList () { + int shellHandle, widgetHandle; + int widgetClass = OS.TopLevelShellWidgetClass (); + shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0); + widgetHandle = OS.XmCreateScrolledList (shellHandle, new byte [0], null, 0); + OS.XtManageChild (widgetHandle); + OS.XtSetMappedWhenManaged (shellHandle, false); + OS.XtRealizeWidget (shellHandle); + int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNfontList, 0, OS.XmNselectColor, 0, OS.XmNhighlightColor, 0}; + OS.XtGetValues (widgetHandle, argList, argList.length / 2); + listForeground = argList [1]; + listBackground = argList [3]; + + /* + * Feature in Motif. Querying the font list from the widget and + * then destroying the shell (and the widget) could cause the + * font list to be freed as well. The fix is to make a copy of + * the font list, then to free it when the display is disposed. */ -
- listFont = Font.motif_new (this, OS.XmFontListCopy (argList [5]));
-
- /*
- * Feature in Motif. If the value of resource XmNselectColor is
- * XmDEFAULT_SELECT_COLOR then querying for this resource gives
- * the value of the selection color to use, which is between the
- * background and bottom shadow colors. If the resource value
- * that is returned is XmDEFAULT_SELECT_COLOR, and not the color,
- * since there is no API to query the color, use the list foreground
- * color.
- */
+ + listFont = Font.motif_new (this, OS.XmFontListCopy (argList [5])); + + /* + * Feature in Motif. If the value of resource XmNselectColor is + * XmDEFAULT_SELECT_COLOR then querying for this resource gives + * the value of the selection color to use, which is between the + * background and bottom shadow colors. If the resource value + * that is returned is XmDEFAULT_SELECT_COLOR, and not the color, + * since there is no API to query the color, use the list foreground + * color. + */ int selectColor = (byte) argList [7]; - switch (selectColor) {
- case OS.XmDEFAULT_SELECT_COLOR:
- case OS.XmREVERSED_GROUND_COLORS:
- listSelect = listForeground;
- break;
- case OS.XmHIGHLIGHT_COLOR:
- listSelect = argList [9];
- break;
- default:
- listSelect = argList [7]; // the middle color to use
- }
- OS.XtDestroyWidget (shellHandle);
-}
-void initializeScrollBar () {
- int shellHandle, widgetHandle;
- int widgetClass = OS.TopLevelShellWidgetClass ();
- shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
- widgetHandle = OS.XmCreateScrollBar (shellHandle, null, null, 0);
- OS.XtManageChild (widgetHandle);
- OS.XtSetMappedWhenManaged (shellHandle, false);
- OS.XtRealizeWidget (shellHandle);
- int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0};
- OS.XtGetValues (widgetHandle, argList, argList.length / 2);
- scrollBarForeground = argList [1]; scrollBarBackground = argList [3];
- OS.XtDestroyWidget (shellHandle);
-}
-void initializeSystemColors () {
- int [] argList = {OS.XmNcolormap, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- int colormap = argList [1];
-
- COLOR_WIDGET_DARK_SHADOW = new XColor();
- COLOR_WIDGET_DARK_SHADOW.pixel = compositeBottomShadow;
- OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_DARK_SHADOW);
-
- COLOR_WIDGET_NORMAL_SHADOW = new XColor();
- COLOR_WIDGET_NORMAL_SHADOW.pixel = compositeBottomShadow;
- OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_NORMAL_SHADOW);
-
- COLOR_WIDGET_LIGHT_SHADOW = new XColor();
- COLOR_WIDGET_LIGHT_SHADOW.pixel = compositeTopShadow;
- OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_LIGHT_SHADOW);
-
- COLOR_WIDGET_HIGHLIGHT_SHADOW = new XColor();
- COLOR_WIDGET_HIGHLIGHT_SHADOW.pixel = compositeTopShadow;
- OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_HIGHLIGHT_SHADOW);
-
- COLOR_WIDGET_FOREGROUND = new XColor();
- COLOR_WIDGET_FOREGROUND.pixel = textForeground;
- OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_FOREGROUND);
-
- COLOR_WIDGET_BACKGROUND = new XColor();
- COLOR_WIDGET_BACKGROUND.pixel = compositeBackground;
- OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_BACKGROUND);
-
- COLOR_WIDGET_BORDER = new XColor();
- COLOR_WIDGET_BORDER.pixel = compositeBorder;
- OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_BORDER);
-
- COLOR_LIST_FOREGROUND = new XColor();
- COLOR_LIST_FOREGROUND.pixel = listForeground;
- OS.XQueryColor (xDisplay, colormap, COLOR_LIST_FOREGROUND);
-
- COLOR_LIST_BACKGROUND = new XColor();
- COLOR_LIST_BACKGROUND.pixel = listBackground;
- OS.XQueryColor (xDisplay, colormap, COLOR_LIST_BACKGROUND);
-
- COLOR_LIST_SELECTION = new XColor();
- COLOR_LIST_SELECTION.pixel = listSelect;
- OS.XQueryColor (xDisplay, colormap, COLOR_LIST_SELECTION);
-
- COLOR_LIST_SELECTION_TEXT = new XColor();
- COLOR_LIST_SELECTION_TEXT.pixel = listBackground;
- OS.XQueryColor (xDisplay, colormap, COLOR_LIST_SELECTION_TEXT);
-
- COLOR_INFO_BACKGROUND = new Color (this, 0xFF, 0xFF, 0xE1);
-}
-void initializeText () {
- int shellHandle, widgetHandle;
- int widgetClass = OS.TopLevelShellWidgetClass ();
- shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0);
- widgetHandle = OS.XmCreateScrolledText (shellHandle, new byte [0], null, 0);
- OS.XtManageChild (widgetHandle);
- OS.XtSetMappedWhenManaged (shellHandle, false);
- OS.XtRealizeWidget (shellHandle);
- int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNfontList, 0, OS.XmNhighlightThickness, 0};
- OS.XtGetValues (widgetHandle, argList, argList.length / 2);
- textForeground = argList [1]; textBackground = argList [3];
- textHighlightThickness = argList[7];
- /*
- * Feature in Motif. Querying the font list from the widget and
- * then destroying the shell (and the widget) could cause the
- * font list to be freed as well. The fix is to make a copy of
- * the font list, then to free it when the display is disposed.
+ switch (selectColor) { + case OS.XmDEFAULT_SELECT_COLOR: + case OS.XmREVERSED_GROUND_COLORS: + listSelect = listForeground; + break; + case OS.XmHIGHLIGHT_COLOR: + listSelect = argList [9]; + break; + default: + listSelect = argList [7]; // the middle color to use + } + OS.XtDestroyWidget (shellHandle); +} +void initializeScrollBar () { + int shellHandle, widgetHandle; + int widgetClass = OS.TopLevelShellWidgetClass (); + shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0); + widgetHandle = OS.XmCreateScrollBar (shellHandle, null, null, 0); + OS.XtManageChild (widgetHandle); + OS.XtSetMappedWhenManaged (shellHandle, false); + OS.XtRealizeWidget (shellHandle); + int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0}; + OS.XtGetValues (widgetHandle, argList, argList.length / 2); + scrollBarForeground = argList [1]; scrollBarBackground = argList [3]; + OS.XtDestroyWidget (shellHandle); +} +void initializeSystemColors () { + int [] argList = {OS.XmNcolormap, 0}; + OS.XtGetValues (shellHandle, argList, argList.length / 2); + int colormap = argList [1]; + + COLOR_WIDGET_DARK_SHADOW = new XColor(); + COLOR_WIDGET_DARK_SHADOW.pixel = compositeBottomShadow; + OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_DARK_SHADOW); + + COLOR_WIDGET_NORMAL_SHADOW = new XColor(); + COLOR_WIDGET_NORMAL_SHADOW.pixel = compositeBottomShadow; + OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_NORMAL_SHADOW); + + COLOR_WIDGET_LIGHT_SHADOW = new XColor(); + COLOR_WIDGET_LIGHT_SHADOW.pixel = compositeTopShadow; + OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_LIGHT_SHADOW); + + COLOR_WIDGET_HIGHLIGHT_SHADOW = new XColor(); + COLOR_WIDGET_HIGHLIGHT_SHADOW.pixel = compositeTopShadow; + OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_HIGHLIGHT_SHADOW); + + COLOR_WIDGET_FOREGROUND = new XColor(); + COLOR_WIDGET_FOREGROUND.pixel = textForeground; + OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_FOREGROUND); + + COLOR_WIDGET_BACKGROUND = new XColor(); + COLOR_WIDGET_BACKGROUND.pixel = compositeBackground; + OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_BACKGROUND); + + COLOR_WIDGET_BORDER = new XColor(); + COLOR_WIDGET_BORDER.pixel = compositeBorder; + OS.XQueryColor (xDisplay, colormap, COLOR_WIDGET_BORDER); + + COLOR_LIST_FOREGROUND = new XColor(); + COLOR_LIST_FOREGROUND.pixel = listForeground; + OS.XQueryColor (xDisplay, colormap, COLOR_LIST_FOREGROUND); + + COLOR_LIST_BACKGROUND = new XColor(); + COLOR_LIST_BACKGROUND.pixel = listBackground; + OS.XQueryColor (xDisplay, colormap, COLOR_LIST_BACKGROUND); + + COLOR_LIST_SELECTION = new XColor(); + COLOR_LIST_SELECTION.pixel = listSelect; + OS.XQueryColor (xDisplay, colormap, COLOR_LIST_SELECTION); + + COLOR_LIST_SELECTION_TEXT = new XColor(); + COLOR_LIST_SELECTION_TEXT.pixel = listBackground; + OS.XQueryColor (xDisplay, colormap, COLOR_LIST_SELECTION_TEXT); + + COLOR_INFO_BACKGROUND = new Color (this, 0xFF, 0xFF, 0xE1); +} +void initializeText () { + int shellHandle, widgetHandle; + int widgetClass = OS.TopLevelShellWidgetClass (); + shellHandle = OS.XtAppCreateShell (appName, appClass, widgetClass, xDisplay, null, 0); + widgetHandle = OS.XmCreateScrolledText (shellHandle, new byte [0], null, 0); + OS.XtManageChild (widgetHandle); + OS.XtSetMappedWhenManaged (shellHandle, false); + OS.XtRealizeWidget (shellHandle); + int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0, OS.XmNfontList, 0, OS.XmNhighlightThickness, 0}; + OS.XtGetValues (widgetHandle, argList, argList.length / 2); + textForeground = argList [1]; textBackground = argList [3]; + textHighlightThickness = argList[7]; + /* + * Feature in Motif. Querying the font list from the widget and + * then destroying the shell (and the widget) could cause the + * font list to be freed as well. The fix is to make a copy of + * the font list, then to free it when the display is disposed. */ -
- textFont = Font.motif_new (this, OS.XmFontListCopy (argList [5]));
- OS.XtDestroyWidget (shellHandle);
-
-}
-void initializeTranslations () {
- byte [] buffer1 = Converter.wcsToMbcs (null, "<Key>osfUp:\n<Key>osfDown:\n<Key>osfLeft:\n<Key>osfRight:\0");
- arrowTranslations = OS.XtParseTranslationTable (buffer1);
- byte [] buffer2 = Converter.wcsToMbcs (null, "~Meta ~Alt <Key>Tab:\nShift ~Meta ~Alt <Key>Tab:\0");
- tabTranslations = OS.XtParseTranslationTable (buffer2);
- byte [] buffer3 = Converter.wcsToMbcs (null, "<Btn2Down>:\0");
- dragTranslations = OS.XtParseTranslationTable (buffer3);
-}
-/**
- * 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
+ + textFont = Font.motif_new (this, OS.XmFontListCopy (argList [5])); + OS.XtDestroyWidget (shellHandle); + +} +void initializeTranslations () { + byte [] buffer1 = Converter.wcsToMbcs (null, "<Key>osfUp:\n<Key>osfDown:\n<Key>osfLeft:\n<Key>osfRight:\0"); + arrowTranslations = OS.XtParseTranslationTable (buffer1); + byte [] buffer2 = Converter.wcsToMbcs (null, "~Meta ~Alt <Key>Tab:\nShift ~Meta ~Alt <Key>Tab:\0"); + tabTranslations = OS.XtParseTranslationTable (buffer2); + byte [] buffer3 = Converter.wcsToMbcs (null, "<Btn2Down>:\0"); + dragTranslations = OS.XtParseTranslationTable (buffer3); +} +/** + * 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 xDrawable = OS.XDefaultRootWindow (xDisplay);
- int xGC = OS.XCreateGC (xDisplay, xDrawable, 0, null);
- if (xGC == 0) SWT.error (SWT.ERROR_NO_HANDLES);
- OS.XSetSubwindowMode (xDisplay, xGC, OS.IncludeInferiors);
- if (data != null) {
- data.device = this;
- data.display = xDisplay;
- data.drawable = xDrawable;
- data.fontList = defaultFont.handle;
- data.codePage = defaultFont.codePage;
- data.colormap = OS.XDefaultColormap (xDisplay, OS.XDefaultScreen (xDisplay));
- }
- return xGC;
-}
-/**
- * Invokes platform specific functionality to dispose a GC handle.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the public
- * API for <code>Display</code>. It is marked public only so that it
- * can be shared within the packages provided by SWT. It is not
- * available on all platforms, and should never be called from
- * application code.
- * </p>
- *
- * @param handle the platform specific GC handle
- * @param data the platform specific GC data
- *
- * @private
+public int internal_new_GC (GCData data) { + if (isDisposed()) SWT.error(SWT.ERROR_DEVICE_DISPOSED); + int xDrawable = OS.XDefaultRootWindow (xDisplay); + int xGC = OS.XCreateGC (xDisplay, xDrawable, 0, null); + if (xGC == 0) SWT.error (SWT.ERROR_NO_HANDLES); + OS.XSetSubwindowMode (xDisplay, xGC, OS.IncludeInferiors); + if (data != null) { + data.device = this; + data.display = xDisplay; + data.drawable = xDrawable; + data.fontList = defaultFont.handle; + data.codePage = defaultFont.codePage; + data.colormap = OS.XDefaultColormap (xDisplay, OS.XDefaultScreen (xDisplay)); + } + return xGC; +} +/** + * Invokes platform specific functionality to dispose a GC handle. + * <p> + * <b>IMPORTANT:</b> This method is <em>not</em> part of the public + * API for <code>Display</code>. It is marked public only so that it + * can be shared within the packages provided by SWT. It is not + * available on all platforms, and should never be called from + * application code. + * </p> + * + * @param handle the platform specific GC handle + * @param data the platform specific GC data + * + * @private */ -public void internal_dispose_GC (int gc, GCData data) {
- OS.XFreeGC(xDisplay, gc);
-}
-boolean isValidThread () {
- return thread == Thread.currentThread ();
-}
-static boolean isValidClass (Class clazz) {
- String name = clazz.getName ();
- int index = name.lastIndexOf ('.');
- return name.substring (0, index + 1).equals (PACKAGE_PREFIX);
-}
-int mouseHoverProc (int handle, int id) {
- mouseHoverID = mouseHoverHandle = 0;
- Widget widget = WidgetTable.get (handle);
- if (widget == null) return 0;
- return widget.hoverProc (id);
-}
-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 void internal_dispose_GC (int gc, GCData data) { + OS.XFreeGC(xDisplay, gc); +} +boolean isValidThread () { + return thread == Thread.currentThread (); +} +static boolean isValidClass (Class clazz) { + String name = clazz.getName (); + int index = name.lastIndexOf ('.'); + return name.substring (0, index + 1).equals (PACKAGE_PREFIX); +} +int mouseHoverProc (int handle, int id) { + mouseHoverID = mouseHoverHandle = 0; + Widget widget = WidgetTable.get (handle); + if (widget == null) return 0; + return widget.hoverProc (id); +} +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 xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- int status = OS.XtAppPending (xtContext);
- if (status == 0) {
- OS.XtAppAddTimeOut (xtContext, 1, 0, 0);
- OS.XtAppProcessEvent (xtContext, OS.XtIMTimer);
- } else {
- if ((status & OS.XtIMTimer) != 0) {
- OS.XtAppProcessEvent (xtContext, OS.XtIMTimer);
- status = OS.XtAppPending (xtContext);
- }
- if ((status & OS.XtIMAlternateInput) != 0) {
- OS.XtAppProcessEvent (xtContext, OS.XtIMAlternateInput);
- status = OS.XtAppPending (xtContext);
- }
- if ((status & OS.XtIMXEvent) != 0) {
- OS.XtAppNextEvent (xtContext, xEvent);
- if (!filterEvent (xEvent)) OS.XtDispatchEvent (xEvent);
- }
- runDeferredEvents ();
- return true;
- }
- return runAsyncMessages ();
-}
-static synchronized void register (Display display) {
- for (int i=0; i<Displays.length; i++) {
- if (Displays [i] == null) {
- Displays [i] = display;
- return;
- }
- }
- Display [] newDisplays = new Display [Displays.length + 4];
- System.arraycopy (Displays, 0, newDisplays, 0, Displays.length);
- newDisplays [Displays.length] = display;
- Displays = newDisplays;
-}
-protected void release () {
- sendEvent (SWT.Dispose, new Event ());
- 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 ()) {};
- if (disposeList != null) {
- for (int i=0; i<disposeList.length; i++) {
- if (disposeList [i] != null) disposeList [i].run ();
- }
- }
- disposeList = null;
- synchronizer.releaseSynchronizer ();
- synchronizer = null;
- releaseDisplay ();
- super.release ();
-}
-void releaseDisplay () {
-
- /* Destroy the hidden Override shell parent */
- if (shellHandle != 0) OS.XtDestroyWidget (shellHandle);
- shellHandle = 0;
-
- /* Dispose the caret callback */
- if (caretID != 0) OS.XtRemoveTimeOut (caretID);
- caretID = caretProc = 0;
- caretCallback.dispose ();
- caretCallback = null;
-
- /* Dispose the timer callback */
- if (timerIds != null) {
- for (int i=0; i<timerIds.length; i++) {
- if (timerIds [i] != 0) OS.XtRemoveTimeOut (timerIds [i]);
- }
- }
- timerIds = null;
- timerList = null;
- timerProc = 0;
- timerCallback.dispose ();
- timerCallback = null;
-
- /* Dispose the window timer callback */
- windowTimerProc = 0;
- windowTimerCallback.dispose ();
- windowTimerCallback = null;
-
- /* Dispose the mouse hover callback */
- if (mouseHoverID != 0) OS.XtRemoveTimeOut (mouseHoverID);
- mouseHoverID = mouseHoverProc = mouseHoverHandle = toolTipHandle = 0;
- mouseHoverCallback.dispose ();
- mouseHoverCallback = null;
-
- /* Dispose window, expose and resize callbacks */
- windowCallback.dispose (); windowCallback = null;
- checkExposeCallback.dispose (); checkExposeCallback = null;
- checkExposeProc = 0;
- checkResizeCallback.dispose (); checkResizeCallback = null;
- checkResizeProc = 0;
-
- /* Dispose the wake callback, id and pipe */
- if (inputID != 0) OS.XtRemoveInput (inputID);
- wakeCallback.dispose (); wakeCallback = null;
- wakeProc = 0;
- OS.close (read_fd);
- OS.close (write_fd);
-
- /* Free the font lists */
- if (buttonFont != null) {
- OS.XmFontListFree (buttonFont.handle);
- buttonFont.handle = 0;
- }
- if (labelFont != null) {
- OS.XmFontListFree (labelFont.handle);
- labelFont.handle = 0;
- }
- if (textFont != null) {
- OS.XmFontListFree (textFont.handle);
- textFont.handle = 0;
- }
- if (listFont != null) {
- OS.XmFontListFree (listFont.handle);
- listFont.handle = 0;
- }
- listFont = textFont = labelFont = buttonFont = null;
- defaultFont = null;
-
- /* Free the translations (no documentation describes how to do this) */
- //OS.XtFree (arrowTranslations);
- //OS.XtFree (tabTranslations);
- //OS.XtFree (dragTranslations);
-
- /* Release references */
- thread = null;
- xEvent = null;
- buttonBackground = buttonForeground = 0;
- defaultBackground = defaultForeground = 0;
- COLOR_WIDGET_DARK_SHADOW = COLOR_WIDGET_NORMAL_SHADOW = COLOR_WIDGET_LIGHT_SHADOW =
- COLOR_WIDGET_HIGHLIGHT_SHADOW = COLOR_WIDGET_FOREGROUND = COLOR_WIDGET_BACKGROUND = COLOR_WIDGET_BORDER =
- COLOR_LIST_FOREGROUND = COLOR_LIST_BACKGROUND = COLOR_LIST_SELECTION = COLOR_LIST_SELECTION_TEXT = null;
- COLOR_INFO_BACKGROUND = null;
-}
-void releaseToolTipHandle (int handle) {
- if (mouseHoverHandle == handle) removeMouseHoverTimeOut ();
- if (toolTipHandle != 0) {
- int shellHandle = OS.XtParent(toolTipHandle);
- int shellParent = OS.XtParent(shellHandle);
- if (handle == shellParent) toolTipHandle = 0;
- }
-}
-void removeMouseHoverTimeOut () {
- if (mouseHoverID != 0) OS.XtRemoveTimeOut (mouseHoverID);
- mouseHoverID = mouseHoverHandle = 0;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notifed when an event of the given type occurs anywhere in SWT.
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified when the event occurs
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see #addFilter
- * @see #addListener
- *
- * @since 2.1
- */
-void removeFilter (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (filterTable == null) return;
- filterTable.unhook (eventType, listener);
- if (filterTable.size () == 0) filterTable = null;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be 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_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Listener
- * @see #addListener
- *
- * @since 2.0
+public boolean readAndDispatch () { + checkDevice (); + int xtContext = OS.XtDisplayToApplicationContext (xDisplay); + int status = OS.XtAppPending (xtContext); + if (status == 0) { + OS.XtAppAddTimeOut (xtContext, 1, 0, 0); + OS.XtAppProcessEvent (xtContext, OS.XtIMTimer); + } else { + if ((status & OS.XtIMTimer) != 0) { + OS.XtAppProcessEvent (xtContext, OS.XtIMTimer); + status = OS.XtAppPending (xtContext); + } + if ((status & OS.XtIMAlternateInput) != 0) { + OS.XtAppProcessEvent (xtContext, OS.XtIMAlternateInput); + status = OS.XtAppPending (xtContext); + } + if ((status & OS.XtIMXEvent) != 0) { + OS.XtAppNextEvent (xtContext, xEvent); + if (!filterEvent (xEvent)) OS.XtDispatchEvent (xEvent); + } + runDeferredEvents (); + return true; + } + return runAsyncMessages (); +} +static synchronized void register (Display display) { + for (int i=0; i<Displays.length; i++) { + if (Displays [i] == null) { + Displays [i] = display; + return; + } + } + Display [] newDisplays = new Display [Displays.length + 4]; + System.arraycopy (Displays, 0, newDisplays, 0, Displays.length); + newDisplays [Displays.length] = display; + Displays = newDisplays; +} +protected void release () { + sendEvent (SWT.Dispose, new Event ()); + 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 ()) {}; + if (disposeList != null) { + for (int i=0; i<disposeList.length; i++) { + if (disposeList [i] != null) disposeList [i].run (); + } + } + disposeList = null; + synchronizer.releaseSynchronizer (); + synchronizer = null; + releaseDisplay (); + super.release (); +} +void releaseDisplay () { + + /* Destroy the hidden Override shell parent */ + if (shellHandle != 0) OS.XtDestroyWidget (shellHandle); + shellHandle = 0; + + /* Dispose the caret callback */ + if (caretID != 0) OS.XtRemoveTimeOut (caretID); + caretID = caretProc = 0; + caretCallback.dispose (); + caretCallback = null; + + /* Dispose the timer callback */ + if (timerIds != null) { + for (int i=0; i<timerIds.length; i++) { + if (timerIds [i] != 0) OS.XtRemoveTimeOut (timerIds [i]); + } + } + timerIds = null; + timerList = null; + timerProc = 0; + timerCallback.dispose (); + timerCallback = null; + + /* Dispose the window timer callback */ + windowTimerProc = 0; + windowTimerCallback.dispose (); + windowTimerCallback = null; + + /* Dispose the mouse hover callback */ + if (mouseHoverID != 0) OS.XtRemoveTimeOut (mouseHoverID); + mouseHoverID = mouseHoverProc = mouseHoverHandle = toolTipHandle = 0; + mouseHoverCallback.dispose (); + mouseHoverCallback = null; + + /* Dispose window, expose and resize callbacks */ + windowCallback.dispose (); windowCallback = null; + checkExposeCallback.dispose (); checkExposeCallback = null; + checkExposeProc = 0; + checkResizeCallback.dispose (); checkResizeCallback = null; + checkResizeProc = 0; + + /* Dispose the wake callback, id and pipe */ + if (inputID != 0) OS.XtRemoveInput (inputID); + wakeCallback.dispose (); wakeCallback = null; + wakeProc = 0; + OS.close (read_fd); + OS.close (write_fd); + + /* Free the font lists */ + if (buttonFont != null) { + OS.XmFontListFree (buttonFont.handle); + buttonFont.handle = 0; + } + if (labelFont != null) { + OS.XmFontListFree (labelFont.handle); + labelFont.handle = 0; + } + if (textFont != null) { + OS.XmFontListFree (textFont.handle); + textFont.handle = 0; + } + if (listFont != null) { + OS.XmFontListFree (listFont.handle); + listFont.handle = 0; + } + listFont = textFont = labelFont = buttonFont = null; + defaultFont = null; + + /* Free the translations (no documentation describes how to do this) */ + //OS.XtFree (arrowTranslations); + //OS.XtFree (tabTranslations); + //OS.XtFree (dragTranslations); + + /* Release references */ + thread = null; + xEvent = null; + buttonBackground = buttonForeground = 0; + defaultBackground = defaultForeground = 0; + COLOR_WIDGET_DARK_SHADOW = COLOR_WIDGET_NORMAL_SHADOW = COLOR_WIDGET_LIGHT_SHADOW = + COLOR_WIDGET_HIGHLIGHT_SHADOW = COLOR_WIDGET_FOREGROUND = COLOR_WIDGET_BACKGROUND = COLOR_WIDGET_BORDER = + COLOR_LIST_FOREGROUND = COLOR_LIST_BACKGROUND = COLOR_LIST_SELECTION = COLOR_LIST_SELECTION_TEXT = null; + COLOR_INFO_BACKGROUND = null; +} +void releaseToolTipHandle (int handle) { + if (mouseHoverHandle == handle) removeMouseHoverTimeOut (); + if (toolTipHandle != 0) { + int shellHandle = OS.XtParent(toolTipHandle); + int shellParent = OS.XtParent(shellHandle); + if (handle == shellParent) toolTipHandle = 0; + } +} +void removeMouseHoverTimeOut () { + if (mouseHoverID != 0) OS.XtRemoveTimeOut (mouseHoverID); + mouseHoverID = mouseHoverHandle = 0; +} +/** + * Removes the listener from the collection of listeners who will + * be notifed when an event of the given type occurs anywhere in SWT. + * + * @param eventType the type of event to listen for + * @param listener the listener which should no longer be notified when the event occurs + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see Listener + * @see #addFilter + * @see #addListener + * + * @since 2.1 */ -public void removeListener (int eventType, Listener listener) {
- checkDevice ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, listener);
-}
-boolean runAsyncMessages () {
- return synchronizer.runAsyncMessages ();
-}
-boolean runDeferredEvents () {
- /*
- * Run deferred events. This code is always
- * called in the Display's thread so it must
- * be re-enterant but need not be synchronized.
- */
- while (eventQueue != null) {
-
- /* Take an event off the queue */
- Event event = eventQueue [0];
- if (event == null) break;
- int length = eventQueue.length;
- System.arraycopy (eventQueue, 1, eventQueue, 0, --length);
- eventQueue [length] = null;
-
- /* Run the event */
- Widget widget = event.widget;
- if (widget != null && !widget.isDisposed ()) {
- Widget item = event.item;
- if (item == null || !item.isDisposed ()) {
- widget.sendEvent (event);
- }
- }
-
- /*
- * At this point, the event queue could
- * be null due to a recursive invokation
- * when running the event.
- */
- }
-
- /* Clear the queue */
- eventQueue = null;
- return true;
-}
-boolean runFocusOutEvents () {
- if (eventQueue == null) return false;
- Event [] focusQueue = null;
- int index = 0, count = 0, length = eventQueue.length;
- while (index < length) {
- Event event = eventQueue [index];
- if (event != null && event.type == SWT.FocusOut) {
- if (focusQueue == null) focusQueue = new Event [length];
- focusQueue [count++] = event;
- System.arraycopy (eventQueue, index + 1, eventQueue, index, --length - index);
- eventQueue [length] = null;
- } else {
- index++;
- }
- }
- if (focusQueue == null) return false;
- for (int i=0; i<count; i++) {
- Event event = focusQueue [i];
- Widget widget = event.widget;
- if (widget != null && !widget.isDisposed ()) {
- Widget item = event.item;
- if (item == null || !item.isDisposed ()) {
- widget.sendEvent (event);
- }
- }
- }
- return true;
-}
-void sendEvent (int eventType, Event event) {
- if (eventTable == null && filterTable == null) {
- return;
- }
- if (event == null) event = new Event ();
- event.display = this;
- event.type = eventType;
- if (event.time == 0) event.time = getLastEventTime ();
- if (!filterEvent (event)) {
- if (eventTable != null) eventTable.sendEvent (event);
- }
-}
-public void setCursorLocation (int x, int y) {
- checkDevice ();
- int xWindow = OS.XDefaultRootWindow (xDisplay);
- OS.XWarpPointer (xDisplay, OS.None, xWindow, 0, 0, 0, 0, x, y);
-}
-/**
- * Sets the location of the on-screen pointer relative to the top left corner
- * of the screen. <b>Note: It is typically considered bad practice for a
- * program to move the on-screen pointer location.</b>
- *
- * @param point new position
- * @since 2.0
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * <li>ERROR_NULL_ARGUMENT - if the point is null
- * </ul>
+void removeFilter (int eventType, Listener listener) { + checkDevice (); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (filterTable == null) return; + filterTable.unhook (eventType, listener); + if (filterTable.size () == 0) filterTable = null; +} +/** + * Removes the listener from the collection of listeners who will + * be 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_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see Listener + * @see #addListener + * + * @since 2.0 */ -public void setCursorLocation (Point point) {
- checkDevice ();
- if (point == null) error (SWT.ERROR_NULL_ARGUMENT);
- setCursorLocation (point.x, point.y);
-}
-/**
- * On platforms which support it, sets the application name
- * to be the argument. On Motif, for example, this can be used
- * to set the name used for resource lookup.
- *
- * @param name the new app name
+public void removeListener (int eventType, Listener listener) { + checkDevice (); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook (eventType, listener); +} +boolean runAsyncMessages () { + return synchronizer.runAsyncMessages (); +} +boolean runDeferredEvents () { + /* + * Run deferred events. This code is always + * called in the Display's thread so it must + * be re-enterant but need not be synchronized. + */ + while (eventQueue != null) { + + /* Take an event off the queue */ + Event event = eventQueue [0]; + if (event == null) break; + int length = eventQueue.length; + System.arraycopy (eventQueue, 1, eventQueue, 0, --length); + eventQueue [length] = null; + + /* Run the event */ + Widget widget = event.widget; + if (widget != null && !widget.isDisposed ()) { + Widget item = event.item; + if (item == null || !item.isDisposed ()) { + widget.sendEvent (event); + } + } + + /* + * At this point, the event queue could + * be null due to a recursive invokation + * when running the event. + */ + } + + /* Clear the queue */ + eventQueue = null; + return true; +} +boolean runFocusOutEvents () { + if (eventQueue == null) return false; + Event [] focusQueue = null; + int index = 0, count = 0, length = eventQueue.length; + while (index < length) { + Event event = eventQueue [index]; + if (event != null && event.type == SWT.FocusOut) { + if (focusQueue == null) focusQueue = new Event [length]; + focusQueue [count++] = event; + System.arraycopy (eventQueue, index + 1, eventQueue, index, --length - index); + eventQueue [length] = null; + } else { + index++; + } + } + if (focusQueue == null) return false; + for (int i=0; i<count; i++) { + Event event = focusQueue [i]; + Widget widget = event.widget; + if (widget != null && !widget.isDisposed ()) { + Widget item = event.item; + if (item == null || !item.isDisposed ()) { + widget.sendEvent (event); + } + } + } + return true; +} +void sendEvent (int eventType, Event event) { + if (eventTable == null && filterTable == null) { + return; + } + if (event == null) event = new Event (); + event.display = this; + event.type = eventType; + if (event.time == 0) event.time = getLastEventTime (); + if (!filterEvent (event)) { + if (eventTable != null) eventTable.sendEvent (event); + } +} +public void setCursorLocation (int x, int y) { + checkDevice (); + int xWindow = OS.XDefaultRootWindow (xDisplay); + OS.XWarpPointer (xDisplay, OS.None, xWindow, 0, 0, 0, 0, x, y); +} +/** + * Sets the location of the on-screen pointer relative to the top left corner + * of the screen. <b>Note: It is typically considered bad practice for a + * program to move the on-screen pointer location.</b> + * + * @param point new position + * @since 2.0 + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * <li>ERROR_NULL_ARGUMENT - if the point is null + * </ul> */ -public static void setAppName (String name) {
- APP_NAME = name;
-}
-void setCurrentCaret (Caret caret) {
- if (caretID != 0) OS.XtRemoveTimeOut (caretID);
- caretID = 0;
- currentCaret = caret;
- if (currentCaret != null) {
- int blinkRate = currentCaret.blinkRate;
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- caretID = OS.XtAppAddTimeOut (xtContext, blinkRate, caretProc, 0);
- }
-}
-/**
- * Sets the application defined property of the receiver
- * with the specified name to the given argument.
- * <p>
- * Applications may have associated arbitrary objects with the
- * receiver in this fashion. If the objects stored in the
- * properties need to be notified when the display is disposed
- * of, it is the application's responsibility provide a
- * <code>disposeExec()</code> handler which does so.
- * </p>
- *
- * @param key the name of the property
- * @param value the new value for the property
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the key is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #setData
- * @see #disposeExec
+public void setCursorLocation (Point point) { + checkDevice (); + if (point == null) error (SWT.ERROR_NULL_ARGUMENT); + setCursorLocation (point.x, point.y); +} +/** + * On platforms which support it, sets the application name + * to be the argument. On Motif, for example, this can be used + * to set the name used for resource lookup. + * + * @param name the new app name */ -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 static void setAppName (String name) { + APP_NAME = name; +} +void setCurrentCaret (Caret caret) { + if (caretID != 0) OS.XtRemoveTimeOut (caretID); + caretID = 0; + currentCaret = caret; + if (currentCaret != null) { + int blinkRate = currentCaret.blinkRate; + int xtContext = OS.XtDisplayToApplicationContext (xDisplay); + caretID = OS.XtAppAddTimeOut (xtContext, blinkRate, caretProc, 0); + } +} +/** + * Sets the application defined property of the receiver + * with the specified name to the given argument. + * <p> + * Applications may have associated arbitrary objects with the + * receiver in this fashion. If the objects stored in the + * properties need to be notified when the display is disposed + * of, it is the application's responsibility provide a + * <code>disposeExec()</code> handler which does so. + * </p> + * + * @param key the name of the property + * @param value the new value for the property + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the key is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </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 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;
-}
-void setToolTipText (int handle, String toolTipText) {
- if (toolTipHandle == 0) return;
- int shellHandle = OS.XtParent (toolTipHandle);
- int shellParent = OS.XtParent (shellHandle);
- if (handle != shellParent) return;
- showToolTip (handle, toolTipText);
-}
-void showToolTip (int handle, String toolTipText) {
- int shellHandle = 0;
- /* Use the character encoding for the default locale */
- byte [] buffer = Converter.wcsToMbcs (null, toolTipText, true);
- if (toolTipHandle != 0) {
- shellHandle = OS.XtParent (toolTipHandle);
- int shellParent = OS.XtParent (shellHandle);
- if (handle != shellParent) return;
- int xmString = OS.XmStringGenerate (buffer, null, OS.XmCHARSET_TEXT, null);
- int [] argList = {OS.XmNlabelString, xmString};
- OS.XtSetValues (toolTipHandle, argList, argList.length / 2);
- if (xmString != 0) OS.XmStringFree (xmString);
- } else {
- int widgetClass = OS.OverrideShellWidgetClass ();
- int [] argList1 = {
- OS.XmNmwmDecorations, 0,
- OS.XmNborderWidth, 1,
- OS.XmNallowShellResize, 1,
- };
- shellHandle = OS.XtCreatePopupShell (null, widgetClass, handle, argList1, argList1.length / 2);
- Color infoForeground = getSystemColor (SWT.COLOR_INFO_FOREGROUND);
- Color infoBackground = getSystemColor (SWT.COLOR_INFO_BACKGROUND);
- int foregroundPixel = infoForeground.handle.pixel;
- int backgroundPixel = infoBackground.handle.pixel;
- int [] argList2 = {
- OS.XmNforeground, foregroundPixel,
- OS.XmNbackground, backgroundPixel,
- OS.XmNalignment, OS.XmALIGNMENT_BEGINNING,
- };
- toolTipHandle = OS.XmCreateLabel (shellHandle, buffer, argList2, argList2.length / 2);
- OS.XtManageChild (toolTipHandle);
- }
- if (toolTipText == null || toolTipText.length () == 0) {
- OS.XtPopdown (shellHandle);
- } else {
- /*
- * Feature in X. There is no way to query the size of a cursor.
- * The fix is to use the default cursor size which is 16x16.
- */
- int xWindow = OS.XDefaultRootWindow (xDisplay);
- int [] rootX = new int [1], rootY = new int [1], unused = new int [1], mask = new int [1];
- OS.XQueryPointer (xDisplay, xWindow, unused, unused, rootX, rootY, unused, unused, mask);
- int x = rootX [0] + 16, y = rootY [0] + 16;
-
- /*
- * Ensure that the tool tip is on the screen.
- */
- int screen = OS.XDefaultScreen (xDisplay);
- int width = OS.XDisplayWidth (xDisplay, screen);
- int height = OS.XDisplayHeight (xDisplay, screen);
- int [] argList4 = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (toolTipHandle, argList4, argList4.length / 2);
- x = Math.max (0, Math.min (x, width - argList4 [1]));
- y = Math.max (0, Math.min (y, height - argList4 [3]));
- OS.XtMoveWidget (shellHandle, x, y);
- int flags = OS.Button1Mask | OS.Button2Mask | OS.Button3Mask;
- if ((mask [0] & flags) == 0) OS.XtPopup (shellHandle, OS.XtGrabNone);
- }
-}
-/**
- * Causes the user-interface thread to <em>sleep</em> (that is,
- * to be put in a state where it does not consume CPU cycles)
- * until an event is received or it is otherwise awakened.
- *
- * @return <code>true</code> if an event requiring dispatching was placed on the queue.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #wake
+public void setSynchronizer (Synchronizer synchronizer) { + checkDevice (); + if (synchronizer == null) error (SWT.ERROR_NULL_ARGUMENT); + if (this.synchronizer != null) { + this.synchronizer.runAsyncMessages(); + } + this.synchronizer = synchronizer; +} +void setToolTipText (int handle, String toolTipText) { + if (toolTipHandle == 0) return; + int shellHandle = OS.XtParent (toolTipHandle); + int shellParent = OS.XtParent (shellHandle); + if (handle != shellParent) return; + showToolTip (handle, toolTipText); +} +void showToolTip (int handle, String toolTipText) { + int shellHandle = 0; + /* Use the character encoding for the default locale */ + byte [] buffer = Converter.wcsToMbcs (null, toolTipText, true); + if (toolTipHandle != 0) { + shellHandle = OS.XtParent (toolTipHandle); + int shellParent = OS.XtParent (shellHandle); + if (handle != shellParent) return; + int xmString = OS.XmStringGenerate (buffer, null, OS.XmCHARSET_TEXT, null); + int [] argList = {OS.XmNlabelString, xmString}; + OS.XtSetValues (toolTipHandle, argList, argList.length / 2); + if (xmString != 0) OS.XmStringFree (xmString); + } else { + int widgetClass = OS.OverrideShellWidgetClass (); + int [] argList1 = { + OS.XmNmwmDecorations, 0, + OS.XmNborderWidth, 1, + OS.XmNallowShellResize, 1, + }; + shellHandle = OS.XtCreatePopupShell (null, widgetClass, handle, argList1, argList1.length / 2); + Color infoForeground = getSystemColor (SWT.COLOR_INFO_FOREGROUND); + Color infoBackground = getSystemColor (SWT.COLOR_INFO_BACKGROUND); + int foregroundPixel = infoForeground.handle.pixel; + int backgroundPixel = infoBackground.handle.pixel; + int [] argList2 = { + OS.XmNforeground, foregroundPixel, + OS.XmNbackground, backgroundPixel, + OS.XmNalignment, OS.XmALIGNMENT_BEGINNING, + }; + toolTipHandle = OS.XmCreateLabel (shellHandle, buffer, argList2, argList2.length / 2); + OS.XtManageChild (toolTipHandle); + } + if (toolTipText == null || toolTipText.length () == 0) { + OS.XtPopdown (shellHandle); + } else { + /* + * Feature in X. There is no way to query the size of a cursor. + * The fix is to use the default cursor size which is 16x16. + */ + int xWindow = OS.XDefaultRootWindow (xDisplay); + int [] rootX = new int [1], rootY = new int [1], unused = new int [1], mask = new int [1]; + OS.XQueryPointer (xDisplay, xWindow, unused, unused, rootX, rootY, unused, unused, mask); + int x = rootX [0] + 16, y = rootY [0] + 16; + + /* + * Ensure that the tool tip is on the screen. + */ + int screen = OS.XDefaultScreen (xDisplay); + int width = OS.XDisplayWidth (xDisplay, screen); + int height = OS.XDisplayHeight (xDisplay, screen); + int [] argList4 = {OS.XmNwidth, 0, OS.XmNheight, 0}; + OS.XtGetValues (toolTipHandle, argList4, argList4.length / 2); + x = Math.max (0, Math.min (x, width - argList4 [1])); + y = Math.max (0, Math.min (y, height - argList4 [3])); + OS.XtMoveWidget (shellHandle, x, y); + int flags = OS.Button1Mask | OS.Button2Mask | OS.Button3Mask; + if ((mask [0] & flags) == 0) OS.XtPopup (shellHandle, OS.XtGrabNone); + } +} +/** + * Causes the user-interface thread to <em>sleep</em> (that is, + * to be put in a state where it does not consume CPU cycles) + * until an event is received or it is otherwise awakened. + * + * @return <code>true</code> if an event requiring dispatching was placed on the queue. + * + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #wake */ -public boolean sleep () {
- checkDevice ();
- /*
- * This code is intentionally commented.
- */
-// int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
-// /*
-// * Bug in Xt. Under certain circumstances Xt waits
-// * forever looking for X events, ignoring alternate
-// * inputs. The fix is to never sleep forever.
-// */
-// int sleepID = OS.XtAppAddTimeOut (xtContext, 100, 0, 0);
-// boolean result = OS.XtAppPeekEvent (xtContext, xEvent);
-// if (sleepID != 0) OS.XtRemoveTimeOut (sleepID);
-// return result;
-
- int display_fd = OS.ConnectionNumber (xDisplay);
- int max_fd = display_fd > read_fd ? display_fd : read_fd;
- OS.FD_ZERO (fd_set);
- OS.FD_SET (display_fd, fd_set);
- OS.FD_SET (read_fd, fd_set);
- timeout [0] = 0;
- timeout [1] = 100000;
- OS.select (max_fd + 1, fd_set, null, null, timeout);
- return OS.FD_ISSET (display_fd, fd_set);
-}
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread at the next
- * reasonable opportunity. The thread which calls this method
- * is suspended until the runnable completes.
- *
- * @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 boolean sleep () { + checkDevice (); + /* + * This code is intentionally commented. + */ +// int xtContext = OS.XtDisplayToApplicationContext (xDisplay); +// /* +// * Bug in Xt. Under certain circumstances Xt waits +// * forever looking for X events, ignoring alternate +// * inputs. The fix is to never sleep forever. +// */ +// int sleepID = OS.XtAppAddTimeOut (xtContext, 100, 0, 0); +// boolean result = OS.XtAppPeekEvent (xtContext, xEvent); +// if (sleepID != 0) OS.XtRemoveTimeOut (sleepID); +// return result; + + int display_fd = OS.ConnectionNumber (xDisplay); + int max_fd = display_fd > read_fd ? display_fd : read_fd; + OS.FD_ZERO (fd_set); + OS.FD_SET (display_fd, fd_set); + OS.FD_SET (read_fd, fd_set); + timeout [0] = 0; + timeout [1] = 100000; + OS.select (max_fd + 1, fd_set, null, null, timeout); + return OS.FD_ISSET (display_fd, fd_set); +} +/** + * Causes the <code>run()</code> method of the runnable to + * be invoked by the user-interface thread at the next + * reasonable opportunity. The thread which calls this method + * is suspended until the runnable completes. + * + * @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);
-}
-int textWidth (String string, Font font) {
- if (string.length () == 0) return 0;
- int fontList = font.handle;
- String codePage = font.codePage;
- byte [] textBuffer = Converter.wcsToMbcs (codePage, string, true);
- int xmString = OS.XmStringGenerate (textBuffer, null, OS.XmCHARSET_TEXT, null);
- int width = OS.XmStringWidth (fontList, xmString);
- OS.XmStringFree (xmString);
- return width;
-}
-/**
- * Causes the <code>run()</code> method of the runnable to
- * be invoked by the user-interface thread after the specified
- * number of milliseconds have elapsed. If milliseconds is less
- * than zero, the runnable is not executed.
- *
- * @param milliseconds the delay before running the runnable
- * @param runnable code to run on the user-interface thread
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #asyncExec
+public void syncExec (Runnable runnable) { + if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); + synchronizer.syncExec (runnable); +} +int textWidth (String string, Font font) { + if (string.length () == 0) return 0; + int fontList = font.handle; + String codePage = font.codePage; + byte [] textBuffer = Converter.wcsToMbcs (codePage, string, true); + int xmString = OS.XmStringGenerate (textBuffer, null, OS.XmCHARSET_TEXT, null); + int width = OS.XmStringWidth (fontList, xmString); + OS.XmStringFree (xmString); + return width; +} +/** + * Causes the <code>run()</code> method of the runnable to + * be invoked by the user-interface thread after the specified + * number of milliseconds have elapsed. If milliseconds is less + * than zero, the runnable is not executed. + * + * @param milliseconds the delay before running the runnable + * @param runnable code to run on the user-interface thread + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the runnable is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #asyncExec */ -public void timerExec (int milliseconds, Runnable runnable) {
- checkDevice ();
- if (runnable == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (timerList == null) timerList = new Runnable [4];
- if (timerIds == null) timerIds = new int [4];
- int index = 0;
- while (index < timerList.length) {
- if (timerList [index] == runnable) break;
- index++;
- }
- if (index != timerList.length) {
- OS.XtRemoveTimeOut (timerIds [index]);
- timerList [index] = null;
- timerIds [index] = 0;
- if (milliseconds < 0) return;
- } else {
- if (milliseconds < 0) return;
- index = 0;
- while (index < timerList.length) {
- if (timerList [index] == null) break;
- index++;
- }
- if (index == timerList.length) {
- Runnable [] newTimerList = new Runnable [timerList.length + 4];
- System.arraycopy (timerList, 0, newTimerList, 0, timerList.length);
- timerList = newTimerList;
- int [] newTimerIds = new int [timerIds.length + 4];
- System.arraycopy (timerIds, 0, newTimerIds, 0, timerIds.length);
- timerIds = newTimerIds;
- }
- }
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- int timerId = OS.XtAppAddTimeOut (xtContext, milliseconds, timerProc, index);
- if (timerId != 0) {
- timerIds [index] = timerId;
- timerList [index] = runnable;
- }
-}
-int timerProc (int index, int id) {
- if (timerList == null) return 0;
- if (0 <= index && index < timerList.length) {
- Runnable runnable = timerList [index];
- timerList [index] = null;
- timerIds [index] = 0;
- if (runnable != null) runnable.run ();
- }
- return 0;
-}
-static int translateKey (int key) {
- for (int i=0; i<KeyTable.length; i++) {
- if (KeyTable [i] [0] == key) return KeyTable [i] [1];
- }
- return 0;
-}
-static int untranslateKey (int key) {
- for (int i=0; i<KeyTable.length; i++) {
- if (KeyTable [i] [1] == key) return KeyTable [i] [0];
- }
- return 0;
-}
+public void timerExec (int milliseconds, Runnable runnable) { + checkDevice (); + if (runnable == null) error (SWT.ERROR_NULL_ARGUMENT); + if (timerList == null) timerList = new Runnable [4]; + if (timerIds == null) timerIds = new int [4]; + int index = 0; + while (index < timerList.length) { + if (timerList [index] == runnable) break; + index++; + } + if (index != timerList.length) { + OS.XtRemoveTimeOut (timerIds [index]); + timerList [index] = null; + timerIds [index] = 0; + if (milliseconds < 0) return; + } else { + if (milliseconds < 0) return; + index = 0; + while (index < timerList.length) { + if (timerList [index] == null) break; + index++; + } + if (index == timerList.length) { + Runnable [] newTimerList = new Runnable [timerList.length + 4]; + System.arraycopy (timerList, 0, newTimerList, 0, timerList.length); + timerList = newTimerList; + int [] newTimerIds = new int [timerIds.length + 4]; + System.arraycopy (timerIds, 0, newTimerIds, 0, timerIds.length); + timerIds = newTimerIds; + } + } + int xtContext = OS.XtDisplayToApplicationContext (xDisplay); + int timerId = OS.XtAppAddTimeOut (xtContext, milliseconds, timerProc, index); + if (timerId != 0) { + timerIds [index] = timerId; + timerList [index] = runnable; + } +} +int timerProc (int index, int id) { + if (timerList == null) return 0; + if (0 <= index && index < timerList.length) { + Runnable runnable = timerList [index]; + timerList [index] = null; + timerIds [index] = 0; + if (runnable != null) runnable.run (); + } + return 0; +} +static int translateKey (int key) { + for (int i=0; i<KeyTable.length; i++) { + if (KeyTable [i] [0] == key) return KeyTable [i] [1]; + } + return 0; +} +static int untranslateKey (int key) { + for (int i=0; i<KeyTable.length; i++) { + if (KeyTable [i] [1] == key) return KeyTable [i] [0]; + } + return 0; +} /** * Forces all outstanding paint requests for the display * to be processed before this method returns. * * @see Control#update */ -public void update () {
- checkDevice ();
- XAnyEvent event = new XAnyEvent ();
- int mask = OS.ExposureMask | OS.ResizeRedirectMask |
- OS.StructureNotifyMask | OS.SubstructureNotifyMask |
- OS.SubstructureRedirectMask;
- OS.XSync (xDisplay, false); OS.XSync (xDisplay, false);
- while (OS.XCheckMaskEvent (xDisplay, mask, event)) OS.XtDispatchEvent (event);
-}
-/**
- * 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 update () { + checkDevice (); + XAnyEvent event = new XAnyEvent (); + int mask = OS.ExposureMask | OS.ResizeRedirectMask | + OS.StructureNotifyMask | OS.SubstructureNotifyMask | + OS.SubstructureRedirectMask; + OS.XSync (xDisplay, false); OS.XSync (xDisplay, false); + while (OS.XCheckMaskEvent (xDisplay, mask, event)) OS.XtDispatchEvent (event); +} +/** + * 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 () {
- if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED);
- if (thread == Thread.currentThread ()) return;
- /* Write a single byte to the wake up pipe */
- while (OS.write (write_fd, wake_buffer, 1) != 1);
-}
-int wakeProc (int closure, int source, int id) {
- /* Read a single byte from the wake up pipe */
- while (OS.read (read_fd, wake_buffer, 1) != 1);
- return 0;
-}
-int windowTimerProc (int handle, int id) {
- Widget widget = WidgetTable.get (handle);
- if (widget == null) return 0;
- return widget.timerProc (id);
-}
-int windowProc (int w, int client_data, int call_data, int continue_to_dispatch) {
- Widget widget = WidgetTable.get (w);
- if (widget == null) return 0;
- return widget.windowProc (w, client_data, call_data, continue_to_dispatch);
-}
-String wrapText (String text, Font font, int width) {
- String Lf = "\n";
- text = convertToLf (text);
- int length = text.length ();
- if (width <= 0 || length == 0 || length == 1) return text;
- StringBuffer result = new StringBuffer ();
- int lineStart = 0, lineEnd = 0;
- while (lineStart < length) {
- lineEnd = text.indexOf (Lf, lineStart);
- boolean noLf = lineEnd == -1;
- if (noLf) lineEnd = length;
- int nextStart = lineEnd + Lf.length ();
- while (lineEnd > lineStart + 1 && Compatibility.isWhitespace (text.charAt (lineEnd - 1))) {
- lineEnd--;
- }
- int wordStart = lineStart, wordEnd = lineStart;
- int i = lineStart;
- while (i < lineEnd) {
- int lastStart = wordStart, lastEnd = wordEnd;
- wordStart = i;
- while (i < lineEnd && !Compatibility.isWhitespace (text.charAt (i))) {
- i++;
- }
- wordEnd = i - 1;
- String line = text.substring (lineStart, wordEnd + 1);
- int lineWidth = textWidth (line, font);
- while (i < lineEnd && Compatibility.isWhitespace (text.charAt (i))) {
- i++;
- }
- if (lineWidth > width) {
- if (lastStart == wordStart) {
- while (wordStart < wordEnd) {
- line = text.substring (lineStart, wordStart + 1);
- lineWidth = textWidth (line, font);
- if (lineWidth >= width) break;
- wordStart++;
- }
- if (wordStart == lastStart) wordStart++;
- lastEnd = wordStart - 1;
- }
- line = text.substring (lineStart, lastEnd + 1);
- result.append (line); result.append (Lf);
- i = wordStart; lineStart = wordStart; wordEnd = wordStart;
- }
- }
- if (lineStart < lineEnd) {
- result.append (text.substring (lineStart, lineEnd));
- }
- if (!noLf) {
- result.append (Lf);
- }
- lineStart = nextStart;
- }
- return result.toString ();
-}
-}
+public void wake () { + if (isDisposed ()) error (SWT.ERROR_DEVICE_DISPOSED); + if (thread == Thread.currentThread ()) return; + /* Write a single byte to the wake up pipe */ + while (OS.write (write_fd, wake_buffer, 1) != 1); +} +int wakeProc (int closure, int source, int id) { + /* Read a single byte from the wake up pipe */ + while (OS.read (read_fd, wake_buffer, 1) != 1); + return 0; +} +int windowTimerProc (int handle, int id) { + Widget widget = WidgetTable.get (handle); + if (widget == null) return 0; + return widget.timerProc (id); +} +int windowProc (int w, int client_data, int call_data, int continue_to_dispatch) { + Widget widget = WidgetTable.get (w); + if (widget == null) return 0; + return widget.windowProc (w, client_data, call_data, continue_to_dispatch); +} +String wrapText (String text, Font font, int width) { + String Lf = "\n"; + text = convertToLf (text); + int length = text.length (); + if (width <= 0 || length == 0 || length == 1) return text; + StringBuffer result = new StringBuffer (); + int lineStart = 0, lineEnd = 0; + while (lineStart < length) { + lineEnd = text.indexOf (Lf, lineStart); + boolean noLf = lineEnd == -1; + if (noLf) lineEnd = length; + int nextStart = lineEnd + Lf.length (); + while (lineEnd > lineStart + 1 && Compatibility.isWhitespace (text.charAt (lineEnd - 1))) { + lineEnd--; + } + int wordStart = lineStart, wordEnd = lineStart; + int i = lineStart; + while (i < lineEnd) { + int lastStart = wordStart, lastEnd = wordEnd; + wordStart = i; + while (i < lineEnd && !Compatibility.isWhitespace (text.charAt (i))) { + i++; + } + wordEnd = i - 1; + String line = text.substring (lineStart, wordEnd + 1); + int lineWidth = textWidth (line, font); + while (i < lineEnd && Compatibility.isWhitespace (text.charAt (i))) { + i++; + } + if (lineWidth > width) { + if (lastStart == wordStart) { + while (wordStart < wordEnd) { + line = text.substring (lineStart, wordStart + 1); + lineWidth = textWidth (line, font); + if (lineWidth >= width) break; + wordStart++; + } + if (wordStart == lastStart) wordStart++; + lastEnd = wordStart - 1; + } + line = text.substring (lineStart, lastEnd + 1); + result.append (line); result.append (Lf); + i = wordStart; lineStart = wordStart; wordEnd = wordStart; + } + } + if (lineStart < lineEnd) { + result.append (text.substring (lineStart, lineEnd)); + } + if (!noLf) { + result.append (Lf); + } + lineStart = nextStart; + } + return result.toString (); +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java index 753c673000..c41a948d6e 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FileDialog.java @@ -1,68 +1,68 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import java.io.*;
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class allow the user to navigate
- * the file system and select or enter a file name.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SAVE, OPEN, MULTI</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html */ -public class FileDialog extends Dialog {
- int dialog;
- String [] filterNames = new String [0];
- String [] filterExtensions = new String [0];
- String [] fileNames;
- String fileName = "";
- String filterPath = "";
- String fullPath;
- boolean cancel = false;
- static final String FILTER = "*";
-
-/**
- * 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>
+ +import java.io.*; +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; + +/** + * Instances of this class allow the user to navigate + * the file system and select or enter a file name. + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>SAVE, OPEN, MULTI</dd> + * <dt><b>Events:</b></dt> + * <dd>(none)</dd> + * </dl> + * <p> + * IMPORTANT: This class is intended to be subclassed <em>only</em> + * within the SWT implementation. + * </p> + */ +public class FileDialog extends Dialog { + int dialog; + String [] filterNames = new String [0]; + String [] filterExtensions = new String [0]; + String [] fileNames; + String fileName = ""; + String filterPath = ""; + String fullPath; + boolean cancel = false; + static final String FILTER = "*"; + +/** + * 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);
-}
-
+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. @@ -93,57 +93,57 @@ public FileDialog (Shell parent) { * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> * </ul> */ -public FileDialog (Shell parent, int style) {
- super (parent, style);
- checkSubclass ();
-}
-
-int cancelPressed (int widget, int client, int call) {
- cancel = true;
- OS.XtUnmanageChild (widget);
- return 0;
-}
+public FileDialog (Shell parent, int style) { + super (parent, style); + checkSubclass (); +} + +int cancelPressed (int widget, int client, int call) { + cancel = true; + OS.XtUnmanageChild (widget); + return 0; +} /** * Returns the path of the first file that was * selected in the dialog relative to the filter path * * @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 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 fileNames;
-}
-
-/**
- * Returns the file extensions which the dialog will
- * use to filter the files it shows.
- *
- * @return the file extensions filter
+public String [] getFileNames () { + return fileNames; +} + +/** + * Returns the file extensions which the dialog will + * use to filter the files it shows. + * + * @return the file extensions filter */ -public String [] getFilterExtensions () {
- return filterExtensions;
-}
-
-/**
- * Returns the file names which the dialog will
- * use to filter the files it shows.
- *
- * @return the file name 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;
-}
-
+public String [] getFilterNames () { + return filterNames; +} + /** * Returns the directory path that the dialog will use. * File names in this path will appear in the dialog, @@ -153,347 +153,347 @@ public String [] getFilterNames () { * * @see #setFilterExtensions */ -public String getFilterPath () {
- return filterPath;
-}
-
-int itemSelected (int widget, int client, int call) {
- /* this callback will only be hooked if the dialog style is MULTI */
- int fileList = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST);
- if (fileList == 0) return 0;
- int selectionText = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_TEXT);
- if (selectionText == 0) return 0;
-
- int [] argList = {OS.XmNselectedItems, 0, OS.XmNselectedItemCount, 0};
- OS.XtGetValues (fileList, argList, argList.length / 2);
- int items = argList [1], itemCount = argList [3];
- int ptr = 0;
- if (itemCount == 0) {
- int [] argList2 = {OS.XmNdirectory, 0};
- OS.XtGetValues (dialog, argList2, argList2.length / 2);
- ptr = argList2 [1];
- } else {
- int [] buffer = new int [1];
- OS.memmove (buffer, items, 4);
- ptr = buffer [0];
- }
- if (ptr == 0) return 0;
- int address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- OS.XmOUTPUT_ALL);
- if (itemCount == 0) OS.XmStringFree (ptr);
- if (address == 0) return 0;
- int length = OS.strlen (address);
- byte [] buffer = new byte [length + 1];
- OS.memmove (buffer, address, length);
- OS.XtFree (address);
-
- OS.XmTextSetString (selectionText, buffer);
- OS.XmTextSetInsertionPosition (selectionText, OS.XmTextGetLastPosition (selectionText));
- return 0;
-}
-
-int okPressed (int widget, int client, int call) {
- String fullPath = null, fileName = null;
- String [] fileNames = null;
-
- int [] argList = {OS.XmNdirSpec, 0, OS.XmNdirectory, 0};
- OS.XtGetValues (dialog, argList, argList.length / 2);
-
- int xmString1 = argList [1];
- int ptr = OS.XmStringUnparse (
- xmString1,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- OS.XmOUTPUT_ALL);
- if (ptr != 0) {
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, length);
- OS.XtFree (ptr);
- /* Use the character encoding for the default locale */
- fullPath = new String (Converter.mbcsToWcs (null, buffer)).trim();
- }
- OS.XmStringFree (xmString1);
-
- if ((style & SWT.MULTI) != 0) {
- int fileList = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST);
- if (fileList == 0) return 0;
- int [] argList2 = {OS.XmNselectedItems, 0, OS.XmNselectedItemCount, 0};
- OS.XtGetValues (fileList, argList2, argList2.length / 2);
- int items = argList2 [1], itemCount = argList2 [3];
- int [] buffer1 = new int [1];
- fileNames = new String [itemCount];
- boolean match = false;
- for (int i = 0; i < itemCount; i++) {
- OS.memmove (buffer1, items, 4);
- ptr = buffer1 [0];
- int address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- OS.XmOUTPUT_ALL);
- if (address != 0) {
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- OS.XtFree (address);
- /* Use the character encoding for the default locale */
- String fullFilename = new String (Converter.mbcsToWcs (null, buffer));
- int index = fullFilename.lastIndexOf ('/');
- fileNames [i] = fullFilename.substring (index + 1, fullFilename.length ());
- if (fullFilename.equals (fullPath)) match = true;
- }
- items += 4;
- }
- if (match) {
- fileName = fileNames [0];
- } else {
- /* The user has modified the text field such that it doesn't match any
- * of the selected files, so use this value instead
- */
- int index = fullPath.lastIndexOf ('/');
- fileName = fullPath.substring (index + 1, fullPath.length ());
- fileNames = new String [] {fileName};
- }
- } else {
- int index = fullPath.lastIndexOf ('/');
- fileName = fullPath.substring (index + 1, fullPath.length ());
- fileNames = new String [] {fileName};
- }
-
- // if no file selected then go into the current directory
- if (fileName.equals("")) {
- int [] argList1 = {OS.XmNdirMask, 0};
- OS.XtGetValues (dialog, argList1, argList1.length / 2);
- int directoryHandle = argList1[1];
- int [] argList2 = {OS.XmNpattern,directoryHandle};
- OS.XtSetValues (dialog, argList2, argList2.length / 2);
- OS.XmStringFree (directoryHandle);
- return 0;
- }
-
- int xmString2 = argList [3];
- ptr = OS.XmStringUnparse (
- xmString2,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- OS.XmOUTPUT_ALL);
- if (ptr != 0) {
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, length);
- OS.XtFree (ptr);
- /* Use the character encoding for the default locale */
- filterPath = new String (Converter.mbcsToWcs (null, buffer));
- }
- OS.XmStringFree (xmString2);
- if (filterPath.endsWith("/")) {
- filterPath = filterPath.substring (0, filterPath.length() - 1);
- }
-
- this.fullPath = fullPath;
- this.fileName = fileName;
- this.fileNames = fileNames;
- OS.XtUnmanageChild (widget);
- return 0;
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a string describing the absolute path of the first selected file,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
+public String getFilterPath () { + return filterPath; +} + +int itemSelected (int widget, int client, int call) { + /* this callback will only be hooked if the dialog style is MULTI */ + int fileList = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST); + if (fileList == 0) return 0; + int selectionText = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_TEXT); + if (selectionText == 0) return 0; + + int [] argList = {OS.XmNselectedItems, 0, OS.XmNselectedItemCount, 0}; + OS.XtGetValues (fileList, argList, argList.length / 2); + int items = argList [1], itemCount = argList [3]; + int ptr = 0; + if (itemCount == 0) { + int [] argList2 = {OS.XmNdirectory, 0}; + OS.XtGetValues (dialog, argList2, argList2.length / 2); + ptr = argList2 [1]; + } else { + int [] buffer = new int [1]; + OS.memmove (buffer, items, 4); + ptr = buffer [0]; + } + if (ptr == 0) return 0; + int address = OS.XmStringUnparse ( + ptr, + null, + OS.XmCHARSET_TEXT, + OS.XmCHARSET_TEXT, + null, + 0, + OS.XmOUTPUT_ALL); + if (itemCount == 0) OS.XmStringFree (ptr); + if (address == 0) return 0; + int length = OS.strlen (address); + byte [] buffer = new byte [length + 1]; + OS.memmove (buffer, address, length); + OS.XtFree (address); + + OS.XmTextSetString (selectionText, buffer); + OS.XmTextSetInsertionPosition (selectionText, OS.XmTextGetLastPosition (selectionText)); + return 0; +} + +int okPressed (int widget, int client, int call) { + String fullPath = null, fileName = null; + String [] fileNames = null; + + int [] argList = {OS.XmNdirSpec, 0, OS.XmNdirectory, 0}; + OS.XtGetValues (dialog, argList, argList.length / 2); + + int xmString1 = argList [1]; + int ptr = OS.XmStringUnparse ( + xmString1, + null, + OS.XmCHARSET_TEXT, + OS.XmCHARSET_TEXT, + null, + 0, + OS.XmOUTPUT_ALL); + if (ptr != 0) { + int length = OS.strlen (ptr); + byte [] buffer = new byte [length]; + OS.memmove (buffer, ptr, length); + OS.XtFree (ptr); + /* Use the character encoding for the default locale */ + fullPath = new String (Converter.mbcsToWcs (null, buffer)).trim(); + } + OS.XmStringFree (xmString1); + + if ((style & SWT.MULTI) != 0) { + int fileList = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST); + if (fileList == 0) return 0; + int [] argList2 = {OS.XmNselectedItems, 0, OS.XmNselectedItemCount, 0}; + OS.XtGetValues (fileList, argList2, argList2.length / 2); + int items = argList2 [1], itemCount = argList2 [3]; + int [] buffer1 = new int [1]; + fileNames = new String [itemCount]; + boolean match = false; + for (int i = 0; i < itemCount; i++) { + OS.memmove (buffer1, items, 4); + ptr = buffer1 [0]; + int address = OS.XmStringUnparse ( + ptr, + null, + OS.XmCHARSET_TEXT, + OS.XmCHARSET_TEXT, + null, + 0, + OS.XmOUTPUT_ALL); + if (address != 0) { + int length = OS.strlen (address); + byte [] buffer = new byte [length]; + OS.memmove (buffer, address, length); + OS.XtFree (address); + /* Use the character encoding for the default locale */ + String fullFilename = new String (Converter.mbcsToWcs (null, buffer)); + int index = fullFilename.lastIndexOf ('/'); + fileNames [i] = fullFilename.substring (index + 1, fullFilename.length ()); + if (fullFilename.equals (fullPath)) match = true; + } + items += 4; + } + if (match) { + fileName = fileNames [0]; + } else { + /* The user has modified the text field such that it doesn't match any + * of the selected files, so use this value instead + */ + int index = fullPath.lastIndexOf ('/'); + fileName = fullPath.substring (index + 1, fullPath.length ()); + fileNames = new String [] {fileName}; + } + } else { + int index = fullPath.lastIndexOf ('/'); + fileName = fullPath.substring (index + 1, fullPath.length ()); + fileNames = new String [] {fileName}; + } + + // if no file selected then go into the current directory + if (fileName.equals("")) { + int [] argList1 = {OS.XmNdirMask, 0}; + OS.XtGetValues (dialog, argList1, argList1.length / 2); + int directoryHandle = argList1[1]; + int [] argList2 = {OS.XmNpattern,directoryHandle}; + OS.XtSetValues (dialog, argList2, argList2.length / 2); + OS.XmStringFree (directoryHandle); + return 0; + } + + int xmString2 = argList [3]; + ptr = OS.XmStringUnparse ( + xmString2, + null, + OS.XmCHARSET_TEXT, + OS.XmCHARSET_TEXT, + null, + 0, + OS.XmOUTPUT_ALL); + if (ptr != 0) { + int length = OS.strlen (ptr); + byte [] buffer = new byte [length]; + OS.memmove (buffer, ptr, length); + OS.XtFree (ptr); + /* Use the character encoding for the default locale */ + filterPath = new String (Converter.mbcsToWcs (null, buffer)); + } + OS.XmStringFree (xmString2); + if (filterPath.endsWith("/")) { + filterPath = filterPath.substring (0, filterPath.length() - 1); + } + + this.fullPath = fullPath; + this.fileName = fileName; + this.fileNames = fileNames; + OS.XtUnmanageChild (widget); + return 0; +} + +/** + * Makes the dialog visible and brings it to the front + * of the display. + * + * @return a string describing the absolute path of the first selected file, + * or null if the dialog was cancelled or an error occurred + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li> + * </ul> */ -public String open () {
-
- /* Get the parent */
- boolean destroyContext;
- Display appContext = Display.getCurrent ();
- if (destroyContext = (appContext == null)) appContext = new Display ();
- int display = appContext.xDisplay;
- int parentHandle = appContext.shellHandle;
- if ((parent != null) && (parent.getDisplay () == appContext)) {
- if (OS.IsAIX) parent.realizeWidget (); /* Fix for bug 17507 */
- parentHandle = parent.shellHandle;
- }
-
- /* Compute the dialog title */
- /*
- * Feature in Motif. It is not possible to set a shell
- * title to an empty string. The fix is to set the title
- * to be a single space.
- */
- String string = title;
- if (string.length () == 0) string = " ";
- /* Use the character encoding for the default locale */
- byte [] buffer1 = Converter.wcsToMbcs (null, string, true);
- int xmStringPtr1 = OS.XmStringParseText (
- buffer1,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
-
- fullPath = null;
- fileNames = null;
-
- /* Compute the filter */
- String mask = FILTER;
- if (filterExtensions == null) filterExtensions = new String [0];
- if (filterNames == null) filterNames = new String [0];
- if (filterExtensions.length != 0) {
- /* Motif does not support multiple filters, so ignore them
- * if there are more than one, or if there is a ; separator.
- */
- if (filterExtensions.length == 1) {
- String filter = filterExtensions [0];
- if (filter.indexOf (';', 0) == -1) mask = filter;
- }
- }
- /* Use the character encoding for the default locale */
- byte [] buffer2 = Converter.wcsToMbcs (null, mask, true);
- int xmStringPtr2 = OS.XmStringParseText (
- buffer2,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
-
- /* Compute the filter path */
- if (filterPath == null) filterPath = "";
- if (!filterPath.endsWith ("/")) {
- File dir = new File (filterPath);
- if (dir.exists () && dir.isDirectory ()) filterPath += '/';
- }
- /* Use the character encoding for the default locale */
- byte [] buffer3 = Converter.wcsToMbcs (null, filterPath, true);
- int xmStringPtr3 = OS.XmStringParseText (
- buffer3,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
-
- /* Create the dialog */
- int [] argList1 = {
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNdialogStyle, OS.XmDIALOG_PRIMARY_APPLICATION_MODAL,
- OS.XmNwidth, OS.XDisplayWidth (display, OS.XDefaultScreen (display)) * 4 / 9,
- OS.XmNpathMode, OS.XmPATH_MODE_FULL,
- OS.XmNdialogTitle, xmStringPtr1,
- OS.XmNpattern, xmStringPtr2,
- OS.XmNdirMask, xmStringPtr3,
- };
- /*
- * Feature in Linux. For some reason, the XmCreateFileSelectionDialog()
- * will not accept NULL for the widget name. This works fine on the other
- * Motif platforms and in the other XmCreate calls on Linux. The fix is
- * to pass in a NULL terminated string, not a NULL pointer.
- */
- byte [] name = new byte [] {0};
- dialog = OS.XmCreateFileSelectionDialog (parentHandle, name, argList1, argList1.length / 2);
- int child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_HELP_BUTTON);
- if (child != 0) OS.XtUnmanageChild (child);
- OS.XmStringFree (xmStringPtr1);
- OS.XmStringFree (xmStringPtr2);
- OS.XmStringFree (xmStringPtr3);
-
- /* Hook the callbacks. */
- Callback cancelCallback = new Callback (this, "cancelPressed", 3);
- int cancelAddress = cancelCallback.getAddress ();
- OS.XtAddCallback (dialog, OS.XmNcancelCallback, cancelAddress, 0);
- Callback okCallback = new Callback (this, "okPressed", 3);
- int okAddress = okCallback.getAddress ();
- OS.XtAddCallback (dialog, OS.XmNokCallback, okAddress, 0);
- Callback selectCallback = null;
- if ((style & SWT.MULTI) != 0) {
- child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST);
- if (child != 0) {
- int [] argList2 = {OS.XmNselectionPolicy, OS.XmEXTENDED_SELECT};
- OS.XtSetValues(child, argList2, argList2.length / 2);
- selectCallback = new Callback (this, "itemSelected", 3);
- int selectAddress = selectCallback.getAddress ();
- if (selectAddress == 0) error (SWT.ERROR_NO_MORE_CALLBACKS);
- OS.XtAddCallback (child, OS.XmNextendedSelectionCallback, selectAddress, 0);
- }
- }
-
- OS.XtManageChild (dialog);
-
- // Should be a pure OS message loop (no SWT AppContext)
- while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog))
- if (!appContext.readAndDispatch ()) appContext.sleep ();
-
- /* Destroy the dialog and update the display. */
- if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog);
- if (destroyContext) appContext.dispose ();
- okCallback.dispose ();
- cancelCallback.dispose ();
- if (selectCallback != null) selectCallback.dispose ();
- return fullPath;
-}
-
-/**
- * Set the initial filename which the dialog will
- * select by default when opened to the argument,
- * which may be null. The name will be prefixed with
- * the filter path when one is supplied.
- *
- * @param string the file name
+public String open () { + + /* Get the parent */ + boolean destroyContext; + Display appContext = Display.getCurrent (); + if (destroyContext = (appContext == null)) appContext = new Display (); + int display = appContext.xDisplay; + int parentHandle = appContext.shellHandle; + if ((parent != null) && (parent.getDisplay () == appContext)) { + if (OS.IsAIX) parent.realizeWidget (); /* Fix for bug 17507 */ + parentHandle = parent.shellHandle; + } + + /* Compute the dialog title */ + /* + * Feature in Motif. It is not possible to set a shell + * title to an empty string. The fix is to set the title + * to be a single space. + */ + String string = title; + if (string.length () == 0) string = " "; + /* Use the character encoding for the default locale */ + byte [] buffer1 = Converter.wcsToMbcs (null, string, true); + int xmStringPtr1 = OS.XmStringParseText ( + buffer1, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + + fullPath = null; + fileNames = null; + + /* Compute the filter */ + String mask = FILTER; + if (filterExtensions == null) filterExtensions = new String [0]; + if (filterNames == null) filterNames = new String [0]; + if (filterExtensions.length != 0) { + /* Motif does not support multiple filters, so ignore them + * if there are more than one, or if there is a ; separator. + */ + if (filterExtensions.length == 1) { + String filter = filterExtensions [0]; + if (filter.indexOf (';', 0) == -1) mask = filter; + } + } + /* Use the character encoding for the default locale */ + byte [] buffer2 = Converter.wcsToMbcs (null, mask, true); + int xmStringPtr2 = OS.XmStringParseText ( + buffer2, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + + /* Compute the filter path */ + if (filterPath == null) filterPath = ""; + if (!filterPath.endsWith ("/")) { + File dir = new File (filterPath); + if (dir.exists () && dir.isDirectory ()) filterPath += '/'; + } + /* Use the character encoding for the default locale */ + byte [] buffer3 = Converter.wcsToMbcs (null, filterPath, true); + int xmStringPtr3 = OS.XmStringParseText ( + buffer3, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + + /* Create the dialog */ + int [] argList1 = { + OS.XmNresizePolicy, OS.XmRESIZE_NONE, + OS.XmNdialogStyle, OS.XmDIALOG_PRIMARY_APPLICATION_MODAL, + OS.XmNwidth, OS.XDisplayWidth (display, OS.XDefaultScreen (display)) * 4 / 9, + OS.XmNpathMode, OS.XmPATH_MODE_FULL, + OS.XmNdialogTitle, xmStringPtr1, + OS.XmNpattern, xmStringPtr2, + OS.XmNdirMask, xmStringPtr3, + }; + /* + * Feature in Linux. For some reason, the XmCreateFileSelectionDialog() + * will not accept NULL for the widget name. This works fine on the other + * Motif platforms and in the other XmCreate calls on Linux. The fix is + * to pass in a NULL terminated string, not a NULL pointer. + */ + byte [] name = new byte [] {0}; + dialog = OS.XmCreateFileSelectionDialog (parentHandle, name, argList1, argList1.length / 2); + int child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_HELP_BUTTON); + if (child != 0) OS.XtUnmanageChild (child); + OS.XmStringFree (xmStringPtr1); + OS.XmStringFree (xmStringPtr2); + OS.XmStringFree (xmStringPtr3); + + /* Hook the callbacks. */ + Callback cancelCallback = new Callback (this, "cancelPressed", 3); + int cancelAddress = cancelCallback.getAddress (); + OS.XtAddCallback (dialog, OS.XmNcancelCallback, cancelAddress, 0); + Callback okCallback = new Callback (this, "okPressed", 3); + int okAddress = okCallback.getAddress (); + OS.XtAddCallback (dialog, OS.XmNokCallback, okAddress, 0); + Callback selectCallback = null; + if ((style & SWT.MULTI) != 0) { + child = OS.XmFileSelectionBoxGetChild (dialog, OS.XmDIALOG_LIST); + if (child != 0) { + int [] argList2 = {OS.XmNselectionPolicy, OS.XmEXTENDED_SELECT}; + OS.XtSetValues(child, argList2, argList2.length / 2); + selectCallback = new Callback (this, "itemSelected", 3); + int selectAddress = selectCallback.getAddress (); + if (selectAddress == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + OS.XtAddCallback (child, OS.XmNextendedSelectionCallback, selectAddress, 0); + } + } + + OS.XtManageChild (dialog); + + // Should be a pure OS message loop (no SWT AppContext) + while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog)) + if (!appContext.readAndDispatch ()) appContext.sleep (); + + /* Destroy the dialog and update the display. */ + if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog); + if (destroyContext) appContext.dispose (); + okCallback.dispose (); + cancelCallback.dispose (); + if (selectCallback != null) selectCallback.dispose (); + return fullPath; +} + +/** + * Set the initial filename which the dialog will + * select by default when opened to the argument, + * which may be null. The name will be prefixed with + * the filter path when one is supplied. + * + * @param string the file name */ -public void setFileName (String string) {
- fileName = string;
-}
-
-/**
- * Set the file extensions which the dialog will
- * use to filter the files it shows to the argument,
- * which may be null.
- *
- * @param extensions the file extension filter
+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 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;
-}
-
+public void setFilterNames (String [] names) { + filterNames = names; +} + /** * Sets the directory path that the dialog will use * to the argument, which may be null. File names in this @@ -504,7 +504,7 @@ public void setFilterNames (String [] names) { * * @see #setFilterExtensions */ -public void setFilterPath (String string) {
- filterPath = string;
-}
-}
+public void setFilterPath (String string) { + filterPath = string; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java index 6ecb04481c..cb8df954fc 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/FontDialog.java @@ -1,118 +1,118 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.layout.*;
-
-import java.util.*;
-
-/**
- * Instances of this class allow the user to select a font
- * from all available fonts in the system.
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html */ -public class FontDialog extends Dialog {
-
- private FontData fontData;
- private Font sampleFont; // the current displayed sample font
- private RGB rgb;
- private Color sampleColor; // the current displayed sample color
-
- /*
- * Table containing all available fonts as FontData objects.
- * The table is structured as a series of embedded Hashtables as follows:
- * <br>characterRegistryName -> faceName -> extendedStyle -> size -> style
- */
- private Hashtable characterSets = new Hashtable ();
-
- private boolean okSelected = false;
- private boolean ignoreEvents = false;
-
- // widgets
- private Shell shell;
- private Combo charSetCombo;
- private Combo faceNameCombo;
- private Combo fontSizeCombo;
- private Combo fontStyleCombo;
- private Combo extStyleCombo;
- private Label sampleLabel;
- private Button okButton;
- private Button cancelButton;
- private Button colorButton;
-
- // constants
- private static final String TEXT_SAMPLE = "AaBbYyZz";
- private static final String SCALABLE_SIZES[] = new String[] {"8", "10", "11", "12", "14", "16", "18", "22", "24", "26"};
- private static final int DEFAULT_SIZE = 14;
- private static final String DEFAULT_STYLE = "medium";
- private static final Integer SCALABLE_KEY = new Integer (0);
- private static final Integer NO_SELECTION = new Integer (-1);
- private static final int COLUMN1_WIDTH = 200;
- private static final int COLUMN2_WIDTH = 150;
- private static final int COLUMN3_WIDTH = 100;
- private static final String PREFIX_ISO8859 = "iso8859";
- private static final String PREFIX_ISO646 = "iso646";
- private static final String PREFIX_UNICODE = "ucs";
- private static final String PREFIX_JAPANESE = "jis";
- private static final String PREFIX_SIMPLIFIEDCHINESE = "gb";
- private static final String PREFIX_TRADITIONALCHINESE = "cns";
- private static final String PREFIX_KOREAN = "ks";
- private static final String [] ISO_CHARSETS = new String [] {
- "", // 0 undefined
- SWT.getMessage ("SWT_Charset_Western"),
- SWT.getMessage ("SWT_Charset_EastEuropean"),
- SWT.getMessage ("SWT_Charset_SouthEuropean"),
- SWT.getMessage ("SWT_Charset_NorthEuropean"),
- SWT.getMessage ("SWT_Charset_Cyrillic"),
- SWT.getMessage ("SWT_Charset_Arabic"),
- SWT.getMessage ("SWT_Charset_Greek"),
- SWT.getMessage ("SWT_Charset_Hebrew"),
- SWT.getMessage ("SWT_Charset_Turkish"),
- SWT.getMessage ("SWT_Charset_Nordic"),
- SWT.getMessage ("SWT_Charset_Thai"),
- "", // 12 undefined
- SWT.getMessage ("SWT_Charset_BalticRim"),
- SWT.getMessage ("SWT_Charset_Celtic"),
- SWT.getMessage ("SWT_Charset_Euro"),
- SWT.getMessage ("SWT_Charset_Romanian")
- };
-
-/**
- * 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>
+ +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.layout.*; + +import java.util.*; + +/** + * Instances of this class allow the user to select a font + * from all available fonts in the system. + * <p> + * IMPORTANT: This class is intended to be subclassed <em>only</em> + * within the SWT implementation. + * </p> + */ +public class FontDialog extends Dialog { + + private FontData fontData; + private Font sampleFont; // the current displayed sample font + private RGB rgb; + private Color sampleColor; // the current displayed sample color + + /* + * Table containing all available fonts as FontData objects. + * The table is structured as a series of embedded Hashtables as follows: + * <br>characterRegistryName -> faceName -> extendedStyle -> size -> style + */ + private Hashtable characterSets = new Hashtable (); + + private boolean okSelected = false; + private boolean ignoreEvents = false; + + // widgets + private Shell shell; + private Combo charSetCombo; + private Combo faceNameCombo; + private Combo fontSizeCombo; + private Combo fontStyleCombo; + private Combo extStyleCombo; + private Label sampleLabel; + private Button okButton; + private Button cancelButton; + private Button colorButton; + + // constants + private static final String TEXT_SAMPLE = "AaBbYyZz"; + private static final String SCALABLE_SIZES[] = new String[] {"8", "10", "11", "12", "14", "16", "18", "22", "24", "26"}; + private static final int DEFAULT_SIZE = 14; + private static final String DEFAULT_STYLE = "medium"; + private static final Integer SCALABLE_KEY = new Integer (0); + private static final Integer NO_SELECTION = new Integer (-1); + private static final int COLUMN1_WIDTH = 200; + private static final int COLUMN2_WIDTH = 150; + private static final int COLUMN3_WIDTH = 100; + private static final String PREFIX_ISO8859 = "iso8859"; + private static final String PREFIX_ISO646 = "iso646"; + private static final String PREFIX_UNICODE = "ucs"; + private static final String PREFIX_JAPANESE = "jis"; + private static final String PREFIX_SIMPLIFIEDCHINESE = "gb"; + private static final String PREFIX_TRADITIONALCHINESE = "cns"; + private static final String PREFIX_KOREAN = "ks"; + private static final String [] ISO_CHARSETS = new String [] { + "", // 0 undefined + SWT.getMessage ("SWT_Charset_Western"), + SWT.getMessage ("SWT_Charset_EastEuropean"), + SWT.getMessage ("SWT_Charset_SouthEuropean"), + SWT.getMessage ("SWT_Charset_NorthEuropean"), + SWT.getMessage ("SWT_Charset_Cyrillic"), + SWT.getMessage ("SWT_Charset_Arabic"), + SWT.getMessage ("SWT_Charset_Greek"), + SWT.getMessage ("SWT_Charset_Hebrew"), + SWT.getMessage ("SWT_Charset_Turkish"), + SWT.getMessage ("SWT_Charset_Nordic"), + SWT.getMessage ("SWT_Charset_Thai"), + "", // 12 undefined + SWT.getMessage ("SWT_Charset_BalticRim"), + SWT.getMessage ("SWT_Charset_Celtic"), + SWT.getMessage ("SWT_Charset_Euro"), + SWT.getMessage ("SWT_Charset_Romanian") + }; + +/** + * 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.NONE);
-}
-
+public FontDialog (Shell parent) { + this (parent, SWT.NONE); +} + /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -143,845 +143,845 @@ public FontDialog (Shell parent) { * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> * </ul> */ -public FontDialog (Shell parent, int style) {
- super (parent, style | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
- checkSubclass ();
-}
-
-/**
- * Add the fonts found in 'fonts' to the list of fonts.
- * Fonts are stored by character set and face name. For each character
- * set/face name combination there is one FontExtStyles object that
- * captures the different extended styles and the sizes and styles
- * available for that extended style.
+public FontDialog (Shell parent, int style) { + super (parent, style | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL); + checkSubclass (); +} + +/** + * Add the fonts found in 'fonts' to the list of fonts. + * Fonts are stored by character set and face name. For each character + * set/face name combination there is one FontExtStyles object that + * captures the different extended styles and the sizes and styles + * available for that extended style. + */ +void addFonts (FontData fonts[]) { + + for (int i = 0; i < fonts.length; i++) { + FontData font = fonts [i]; + + String charSetName = getTranslatedCharSet (font); + Hashtable charSet = (Hashtable) characterSets.get (charSetName); + if (charSet == null) { + charSet = new Hashtable (9); + characterSets.put (charSetName, charSet); + } + + String faceName = getTranslatedFaceName (font); + Hashtable faceSet = (Hashtable) charSet.get (faceName); + if (faceSet == null) { + faceSet = new Hashtable (9); + charSet.put (faceName, faceSet); + } + + String extStyleName = font.addStyle; + Hashtable extStyleSet = (Hashtable) faceSet.get (extStyleName); + if (extStyleSet == null) { + extStyleSet = new Hashtable (9); + faceSet.put (extStyleName, extStyleSet); + } + + Integer sizeValue = new Integer (font.getHeight ()); + Hashtable sizeSet = (Hashtable) extStyleSet.get (sizeValue); + if (sizeSet == null) { + sizeSet = new Hashtable (9); + extStyleSet.put (sizeValue, sizeSet); + } + + String style = font.weight; + sizeSet.put (style,font); + } +} + +/** + * Create the widgets of the dialog. */ -void addFonts (FontData fonts[]) {
-
- for (int i = 0; i < fonts.length; i++) {
- FontData font = fonts [i];
-
- String charSetName = getTranslatedCharSet (font);
- Hashtable charSet = (Hashtable) characterSets.get (charSetName);
- if (charSet == null) {
- charSet = new Hashtable (9);
- characterSets.put (charSetName, charSet);
- }
-
- String faceName = getTranslatedFaceName (font);
- Hashtable faceSet = (Hashtable) charSet.get (faceName);
- if (faceSet == null) {
- faceSet = new Hashtable (9);
- charSet.put (faceName, faceSet);
- }
-
- String extStyleName = font.addStyle;
- Hashtable extStyleSet = (Hashtable) faceSet.get (extStyleName);
- if (extStyleSet == null) {
- extStyleSet = new Hashtable (9);
- faceSet.put (extStyleName, extStyleSet);
- }
-
- Integer sizeValue = new Integer (font.getHeight ());
- Hashtable sizeSet = (Hashtable) extStyleSet.get (sizeValue);
- if (sizeSet == null) {
- sizeSet = new Hashtable (9);
- extStyleSet.put (sizeValue, sizeSet);
- }
-
- String style = font.weight;
- sizeSet.put (style,font);
- }
-}
-
-/**
- * Create the widgets of the dialog.
+void createChildren () { + Label characterSetLabel = new Label (shell, SWT.NONE); + Label faceNameLabel = new Label (shell, SWT.NONE); + Label extendedStyleLabel = new Label (shell, SWT.NONE); + GridLayout layout = new GridLayout (); + + layout.numColumns = 4; + layout.marginWidth = 15; + layout.marginHeight = 15; + layout.horizontalSpacing = 10; + layout.verticalSpacing = 2; + shell.setLayout (layout); + + // row one + characterSetLabel.setText (SWT.getMessage ("SWT_Character_set") + ":"); + faceNameLabel.setText (SWT.getMessage ("SWT_Font") + ":"); + extendedStyleLabel.setText (SWT.getMessage ("SWT_Extended_style") + ":"); + + new Label (shell, SWT.NONE); + + // row two + charSetCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL); + GridData gridData = new GridData (); + gridData.widthHint = COLUMN1_WIDTH; + gridData.heightHint = 150; + gridData.verticalSpan = 3; + charSetCombo.setLayoutData (gridData); + charSetCombo.setData (NO_SELECTION); + + faceNameCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL); + gridData = new GridData (); + gridData.widthHint = COLUMN2_WIDTH; + gridData.heightHint = 150; + gridData.verticalSpan = 3; + gridData.verticalAlignment = GridData.FILL; + faceNameCombo.setLayoutData (gridData); + faceNameCombo.setData (NO_SELECTION); + + extStyleCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL); + gridData = new GridData (); + gridData.widthHint = COLUMN3_WIDTH; + gridData.heightHint = 150; + gridData.verticalSpan = 3; + gridData.verticalAlignment = GridData.FILL; + extStyleCombo.setLayoutData (gridData); + extStyleCombo.setData (NO_SELECTION); + + // create ok, cancel, and color buttons (row two, three, and four) + createButtons (); + + // row four + createEmptyRow (); + + // row five + Label fontSizeLabel = new Label (shell, SWT.NONE); + fontSizeLabel.setText (SWT.getMessage ("SWT_Size") + ":"); + Label fontStyleLabel = new Label (shell, SWT.NONE); + fontStyleLabel.setText (SWT.getMessage ("SWT_Style") + ":"); + + Label fillLabel = new Label (shell, SWT.NONE); + gridData = new GridData (); + gridData.horizontalSpan = 2; + fillLabel.setLayoutData (gridData); + + // row six + fontSizeCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL); + gridData = new GridData (); + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.FILL; + gridData.heightHint = 110; + fontSizeCombo.setLayoutData (gridData); + fontSizeCombo.setData (NO_SELECTION); + + fontStyleCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL); + gridData = new GridData (); + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.FILL; + fontStyleCombo.setLayoutData (gridData); + fontStyleCombo.setData (NO_SELECTION); + + fillLabel = new Label (shell, SWT.NONE); + gridData = new GridData (); + gridData.horizontalSpan = 2; + fillLabel.setLayoutData (gridData); + + // row seven + createEmptyRow (); + + // row eight + Group sampleGroup = new Group (shell, SWT.NONE); + sampleGroup.setText (SWT.getMessage ("SWT_Sample")); + gridData = new GridData (); + gridData.heightHint = 70; + gridData.horizontalSpan = 3; + gridData.horizontalAlignment = GridData.FILL; + sampleGroup.setLayoutData (gridData); + + // setup group box with sample text + layout = new GridLayout (); + layout.marginWidth = 10; + layout.marginHeight = 10; + sampleGroup.setLayout (layout); + + sampleLabel = new Label (sampleGroup, SWT.CENTER); + sampleLabel.setText (TEXT_SAMPLE); + gridData = new GridData (); + gridData.grabExcessHorizontalSpace = true; + gridData.grabExcessVerticalSpace = true; + gridData.verticalAlignment = GridData.FILL; + gridData.horizontalAlignment = GridData.FILL; + sampleLabel.setLayoutData (gridData); + shell.setSize (445, 410); +} + +/** + * Fill one row in the grid layout with empty widgets. + * Used to achieve a bigger vertical spacing between separate + * groups of widgets (ie. new rows of Text/Combo combinations). */ -void createChildren () {
- Label characterSetLabel = new Label (shell, SWT.NONE);
- Label faceNameLabel = new Label (shell, SWT.NONE);
- Label extendedStyleLabel = new Label (shell, SWT.NONE);
- GridLayout layout = new GridLayout ();
-
- layout.numColumns = 4;
- layout.marginWidth = 15;
- layout.marginHeight = 15;
- layout.horizontalSpacing = 10;
- layout.verticalSpacing = 2;
- shell.setLayout (layout);
-
- // row one
- characterSetLabel.setText (SWT.getMessage ("SWT_Character_set") + ":");
- faceNameLabel.setText (SWT.getMessage ("SWT_Font") + ":");
- extendedStyleLabel.setText (SWT.getMessage ("SWT_Extended_style") + ":");
-
- new Label (shell, SWT.NONE);
-
- // row two
- charSetCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL);
- GridData gridData = new GridData ();
- gridData.widthHint = COLUMN1_WIDTH;
- gridData.heightHint = 150;
- gridData.verticalSpan = 3;
- charSetCombo.setLayoutData (gridData);
- charSetCombo.setData (NO_SELECTION);
-
- faceNameCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL);
- gridData = new GridData ();
- gridData.widthHint = COLUMN2_WIDTH;
- gridData.heightHint = 150;
- gridData.verticalSpan = 3;
- gridData.verticalAlignment = GridData.FILL;
- faceNameCombo.setLayoutData (gridData);
- faceNameCombo.setData (NO_SELECTION);
-
- extStyleCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL);
- gridData = new GridData ();
- gridData.widthHint = COLUMN3_WIDTH;
- gridData.heightHint = 150;
- gridData.verticalSpan = 3;
- gridData.verticalAlignment = GridData.FILL;
- extStyleCombo.setLayoutData (gridData);
- extStyleCombo.setData (NO_SELECTION);
-
- // create ok, cancel, and color buttons (row two, three, and four)
- createButtons ();
-
- // row four
- createEmptyRow ();
-
- // row five
- Label fontSizeLabel = new Label (shell, SWT.NONE);
- fontSizeLabel.setText (SWT.getMessage ("SWT_Size") + ":");
- Label fontStyleLabel = new Label (shell, SWT.NONE);
- fontStyleLabel.setText (SWT.getMessage ("SWT_Style") + ":");
-
- Label fillLabel = new Label (shell, SWT.NONE);
- gridData = new GridData ();
- gridData.horizontalSpan = 2;
- fillLabel.setLayoutData (gridData);
-
- // row six
- fontSizeCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL);
- gridData = new GridData ();
- gridData.horizontalAlignment = GridData.FILL;
- gridData.verticalAlignment = GridData.FILL;
- gridData.heightHint = 110;
- fontSizeCombo.setLayoutData (gridData);
- fontSizeCombo.setData (NO_SELECTION);
-
- fontStyleCombo = new Combo (shell, SWT.SIMPLE | SWT.V_SCROLL);
- gridData = new GridData ();
- gridData.horizontalAlignment = GridData.FILL;
- gridData.verticalAlignment = GridData.FILL;
- fontStyleCombo.setLayoutData (gridData);
- fontStyleCombo.setData (NO_SELECTION);
-
- fillLabel = new Label (shell, SWT.NONE);
- gridData = new GridData ();
- gridData.horizontalSpan = 2;
- fillLabel.setLayoutData (gridData);
-
- // row seven
- createEmptyRow ();
-
- // row eight
- Group sampleGroup = new Group (shell, SWT.NONE);
- sampleGroup.setText (SWT.getMessage ("SWT_Sample"));
- gridData = new GridData ();
- gridData.heightHint = 70;
- gridData.horizontalSpan = 3;
- gridData.horizontalAlignment = GridData.FILL;
- sampleGroup.setLayoutData (gridData);
-
- // setup group box with sample text
- layout = new GridLayout ();
- layout.marginWidth = 10;
- layout.marginHeight = 10;
- sampleGroup.setLayout (layout);
-
- sampleLabel = new Label (sampleGroup, SWT.CENTER);
- sampleLabel.setText (TEXT_SAMPLE);
- gridData = new GridData ();
- gridData.grabExcessHorizontalSpace = true;
- gridData.grabExcessVerticalSpace = true;
- gridData.verticalAlignment = GridData.FILL;
- gridData.horizontalAlignment = GridData.FILL;
- sampleLabel.setLayoutData (gridData);
- shell.setSize (445, 410);
-}
-
-/**
- * Fill one row in the grid layout with empty widgets.
- * Used to achieve a bigger vertical spacing between separate
- * groups of widgets (ie. new rows of Text/Combo combinations).
+void createEmptyRow () { + Label fillLabel = new Label (shell, SWT.NONE); + GridData gridData = new GridData (); + + gridData.heightHint = 5; + gridData.horizontalSpan = ((GridLayout) shell.getLayout ()).numColumns; + fillLabel.setLayoutData (gridData); +} + +/** + * Create the widgets of the dialog. + */ +void createButtons () { + okButton = new Button (shell, SWT.PUSH); + okButton.setText (SWT.getMessage ("SWT_OK")); + shell.setDefaultButton (okButton); + GridData gridData = new GridData (); + gridData.horizontalAlignment = GridData.FILL; + gridData.widthHint = 70; + okButton.setLayoutData (gridData); + + cancelButton = new Button (shell, SWT.PUSH); + cancelButton.setText (SWT.getMessage ("SWT_Cancel")); + gridData = new GridData (); + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.BEGINNING; + cancelButton.setLayoutData (gridData); + + colorButton = new Button (shell, SWT.PUSH); + colorButton.setText (SWT.getMessage ("SWT_Color")); + gridData = new GridData (); + gridData.horizontalAlignment = GridData.FILL; + gridData.verticalAlignment = GridData.BEGINNING; + colorButton.setLayoutData (gridData); +} + +Hashtable getExtStyles (String charsetName, String faceName) { + Hashtable faces = getFaces (charsetName); + if (faces == null) return null; + return (Hashtable) faces.get (faceName); +} + +Hashtable getFaces (String charsetName) { + return (Hashtable) getFonts ().get (charsetName); +} + +/** + * Returns a FontData object describing the font that was + * selected in the dialog, or null if none is available. + * + * @return the FontData for the selected font, or null */ -void createEmptyRow () {
- Label fillLabel = new Label (shell, SWT.NONE);
- GridData gridData = new GridData ();
-
- gridData.heightHint = 5;
- gridData.horizontalSpan = ((GridLayout) shell.getLayout ()).numColumns;
- fillLabel.setLayoutData (gridData);
-}
-
-/**
- * Create the widgets of the dialog.
+public FontData getFontData () { + return fontData; +} + +FontData getFontData (String charsetName, String faceName, String extStyle, int size, String style) { + Hashtable styles = getStyles (charsetName, faceName, extStyle, size); + if (styles == null) return null; + return (FontData) styles.get (style); +} + +/** + * Returns the collection of fonts that are displayed by the + * receiver. + * See the class definition for an explanation of the structure + * of the returned Hashtable. */ -void createButtons () {
- okButton = new Button (shell, SWT.PUSH);
- okButton.setText (SWT.getMessage ("SWT_OK"));
- shell.setDefaultButton (okButton);
- GridData gridData = new GridData ();
- gridData.horizontalAlignment = GridData.FILL;
- gridData.widthHint = 70;
- okButton.setLayoutData (gridData);
-
- cancelButton = new Button (shell, SWT.PUSH);
- cancelButton.setText (SWT.getMessage ("SWT_Cancel"));
- gridData = new GridData ();
- gridData.horizontalAlignment = GridData.FILL;
- gridData.verticalAlignment = GridData.BEGINNING;
- cancelButton.setLayoutData (gridData);
-
- colorButton = new Button (shell, SWT.PUSH);
- colorButton.setText (SWT.getMessage ("SWT_Color"));
- gridData = new GridData ();
- gridData.horizontalAlignment = GridData.FILL;
- gridData.verticalAlignment = GridData.BEGINNING;
- colorButton.setLayoutData (gridData);
-}
-
-Hashtable getExtStyles (String charsetName, String faceName) {
- Hashtable faces = getFaces (charsetName);
- if (faces == null) return null;
- return (Hashtable) faces.get (faceName);
-}
-
-Hashtable getFaces (String charsetName) {
- return (Hashtable) getFonts ().get (charsetName);
-}
-
-/**
- * Returns a FontData object describing the font that was
- * selected in the dialog, or null if none is available.
- *
- * @return the FontData for the selected font, or null
+Hashtable getFonts () { + return characterSets; +} + +/** + * Returns the currently selected color in the receiver. + * + * @return the RGB value for the selected color, may be null + * + * @see PaletteData#getRGBs */ -public FontData getFontData () {
- return fontData;
-}
-
-FontData getFontData (String charsetName, String faceName, String extStyle, int size, String style) {
- Hashtable styles = getStyles (charsetName, faceName, extStyle, size);
- if (styles == null) return null;
- return (FontData) styles.get (style);
-}
-
-/**
- * Returns the collection of fonts that are displayed by the
- * receiver.
- * See the class definition for an explanation of the structure
- * of the returned Hashtable.
+public RGB getRGB () { + return rgb; +} + +/** + * Returns a FontData object that can be used to load the selected + * font. */ -Hashtable getFonts () {
- return characterSets;
-}
-
-/**
- * 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;
-}
-
-/**
- * Returns a FontData object that can be used to load the selected
- * font.
+FontData getSelectionFontData () { + String charSetName = charSetCombo.getText (); + String faceName = faceNameCombo.getText (); + String extStyle = extStyleCombo.getText (); + int size = DEFAULT_SIZE; + try { + size = Integer.valueOf (fontSizeCombo.getText ()).intValue (); + if (size < 1) size = DEFAULT_SIZE; + } catch (NumberFormatException e) { + /* + * This block is purposely left empty since a default + * value is already specified above. + */ + } + String style = fontStyleCombo.getText (); + FontData result = getFontData (charSetName, faceName, extStyle, size, style); + + if (result == null) { + /* + * One or more of the dialog's widgets contain custom typed values. + * Create a FontData that mirrors these values so that the Font created + * below will try to find the best match. + */ + result = new FontData (); + result.characterSetRegistry = charSetName; + result.setName(faceName); + result.addStyle = extStyle; + result.weight = style; + } + result.setHeight (size); + return result; +} + +Hashtable getSizes (String charsetName, String faceName, String extStyle) { + Hashtable extStyles = getExtStyles (charsetName, faceName); + if (extStyles == null) return null; + return (Hashtable) extStyles.get (extStyle); +} + +Hashtable getStyles (String charsetName, String faceName, String extStyle, int size) { + Hashtable sizes = getSizes (charsetName, faceName, extStyle); + if (sizes == null) return null; + Hashtable result = (Hashtable) sizes.get (new Integer (size)); + if (result == null) + result = (Hashtable) sizes.get (SCALABLE_KEY); + return result; +} + +/** + * Returns the character set found in 'fontData' prefixed + * with a string explaining the character set. */ -FontData getSelectionFontData () {
- String charSetName = charSetCombo.getText ();
- String faceName = faceNameCombo.getText ();
- String extStyle = extStyleCombo.getText ();
- int size = DEFAULT_SIZE;
- try {
- size = Integer.valueOf (fontSizeCombo.getText ()).intValue ();
- if (size < 1) size = DEFAULT_SIZE;
- } catch (NumberFormatException e) {
- /*
- * This block is purposely left empty since a default
- * value is already specified above.
- */
- }
- String style = fontStyleCombo.getText ();
- FontData result = getFontData (charSetName, faceName, extStyle, size, style);
-
- if (result == null) {
- /*
- * One or more of the dialog's widgets contain custom typed values.
- * Create a FontData that mirrors these values so that the Font created
- * below will try to find the best match.
- */
- result = new FontData ();
- result.characterSetRegistry = charSetName;
- result.setName(faceName);
- result.addStyle = extStyle;
- result.weight = style;
- }
- result.setHeight (size);
- return result;
-}
-
-Hashtable getSizes (String charsetName, String faceName, String extStyle) {
- Hashtable extStyles = getExtStyles (charsetName, faceName);
- if (extStyles == null) return null;
- return (Hashtable) extStyles.get (extStyle);
-}
-
-Hashtable getStyles (String charsetName, String faceName, String extStyle, int size) {
- Hashtable sizes = getSizes (charsetName, faceName, extStyle);
- if (sizes == null) return null;
- Hashtable result = (Hashtable) sizes.get (new Integer (size));
- if (result == null)
- result = (Hashtable) sizes.get (SCALABLE_KEY);
- return result;
-}
-
-/**
- * Returns the character set found in 'fontData' prefixed
- * with a string explaining the character set.
+String getTranslatedCharSet (FontData fontData) { + String characterSet = fontData.characterSetRegistry; + String translatedCharSet = null; + + if (characterSet.startsWith (PREFIX_ISO8859)) { + int charSetName = 1; + try { + charSetName = Integer.valueOf (fontData.characterSetName).intValue (); + } catch (NumberFormatException e) { + /* + * This block is purposely left empty since a default + * value is already specified above. + */ + } + characterSet += "-" + charSetName; + if (charSetName < ISO_CHARSETS.length) { + translatedCharSet = ISO_CHARSETS [charSetName]; + } + } + else + if (characterSet.startsWith (PREFIX_ISO646)) { + translatedCharSet = SWT.getMessage("SWT_Charset_ASCII"); + } + else + if (characterSet.startsWith (PREFIX_UNICODE)) { + translatedCharSet = SWT.getMessage("SWT_Charset_Unicode"); + } + else + if (characterSet.startsWith (PREFIX_JAPANESE)) { + translatedCharSet = SWT.getMessage("SWT_Charset_Japanese"); + } + else + if (characterSet.startsWith (PREFIX_SIMPLIFIEDCHINESE)) { + translatedCharSet = SWT.getMessage("SWT_Charset_SimplifiedChinese"); + } + else + if (characterSet.startsWith (PREFIX_TRADITIONALCHINESE)) { + translatedCharSet = SWT.getMessage("SWT_Charset_TraditionalChinese"); + } + else + if (characterSet.startsWith (PREFIX_KOREAN)) { + translatedCharSet = SWT.getMessage("SWT_Charset_Korean"); + } + if (translatedCharSet != null) { + translatedCharSet += " (" + characterSet + ')'; + } + else { + translatedCharSet = characterSet; + } + return translatedCharSet; +} + +/** + * Returns the face name as specified in FontData.familyName followed by + * the foundry set in parantheses if available. + * We display the face name first so that the list box sorts the fonts by + * face name, not by foundry. Users generally want to select fonts based + * on the face name and not by foundry. Once they've found the desired + * face name in the list they can compare the font variations from + * different foundries if available. */ -String getTranslatedCharSet (FontData fontData) {
- String characterSet = fontData.characterSetRegistry;
- String translatedCharSet = null;
-
- if (characterSet.startsWith (PREFIX_ISO8859)) {
- int charSetName = 1;
- try {
- charSetName = Integer.valueOf (fontData.characterSetName).intValue ();
- } catch (NumberFormatException e) {
- /*
- * This block is purposely left empty since a default
- * value is already specified above.
- */
- }
- characterSet += "-" + charSetName;
- if (charSetName < ISO_CHARSETS.length) {
- translatedCharSet = ISO_CHARSETS [charSetName];
- }
- }
- else
- if (characterSet.startsWith (PREFIX_ISO646)) {
- translatedCharSet = SWT.getMessage("SWT_Charset_ASCII");
- }
- else
- if (characterSet.startsWith (PREFIX_UNICODE)) {
- translatedCharSet = SWT.getMessage("SWT_Charset_Unicode");
- }
- else
- if (characterSet.startsWith (PREFIX_JAPANESE)) {
- translatedCharSet = SWT.getMessage("SWT_Charset_Japanese");
- }
- else
- if (characterSet.startsWith (PREFIX_SIMPLIFIEDCHINESE)) {
- translatedCharSet = SWT.getMessage("SWT_Charset_SimplifiedChinese");
- }
- else
- if (characterSet.startsWith (PREFIX_TRADITIONALCHINESE)) {
- translatedCharSet = SWT.getMessage("SWT_Charset_TraditionalChinese");
- }
- else
- if (characterSet.startsWith (PREFIX_KOREAN)) {
- translatedCharSet = SWT.getMessage("SWT_Charset_Korean");
- }
- if (translatedCharSet != null) {
- translatedCharSet += " (" + characterSet + ')';
- }
- else {
- translatedCharSet = characterSet;
- }
- return translatedCharSet;
-}
-
-/**
- * Returns the face name as specified in FontData.familyName followed by
- * the foundry set in parantheses if available.
- * We display the face name first so that the list box sorts the fonts by
- * face name, not by foundry. Users generally want to select fonts based
- * on the face name and not by foundry. Once they've found the desired
- * face name in the list they can compare the font variations from
- * different foundries if available.
+String getTranslatedFaceName (FontData fontData) { + StringBuffer faceNameBuffer; + + if (fontData.foundry != null && fontData.foundry.length () > 0) { + faceNameBuffer = new StringBuffer (fontData.fontFamily); + faceNameBuffer.append (" ("); + faceNameBuffer.append (fontData.foundry); + faceNameBuffer.append (')'); + } + else { + faceNameBuffer = new StringBuffer (fontData.getName ()); + } + return faceNameBuffer.toString (); +} + +/** + * Handle the events the receiver is listening to. + * Combo selections cause the downstream combos to be initialized + * with font data and the sample text to be updated. */ -String getTranslatedFaceName (FontData fontData) {
- StringBuffer faceNameBuffer;
-
- if (fontData.foundry != null && fontData.foundry.length () > 0) {
- faceNameBuffer = new StringBuffer (fontData.fontFamily);
- faceNameBuffer.append (" (");
- faceNameBuffer.append (fontData.foundry);
- faceNameBuffer.append (')');
- }
- else {
- faceNameBuffer = new StringBuffer (fontData.getName ());
- }
- return faceNameBuffer.toString ();
-}
-
-/**
- * Handle the events the receiver is listening to.
- * Combo selections cause the downstream combos to be initialized
- * with font data and the sample text to be updated.
+void handleEvent (Event event) { + if (ignoreEvents) return; + if (event.widget instanceof Combo) { + Combo combo = (Combo) event.widget; + int prevSelectIndex = ((Integer) combo.getData ()).intValue (); + String text = combo.getText (); + int newSelectIndex = combo.indexOf (text); + if (prevSelectIndex != newSelectIndex || newSelectIndex == -1) { + ignoreEvents = true; + combo.setData (new Integer (newSelectIndex)); + if (combo == charSetCombo) initFaceNameCombo (); + else if (combo == faceNameCombo) initExtStyleCombo (); + else if (combo == extStyleCombo) initSizeCombo (); + else if (combo == fontSizeCombo) initStyleCombo (); + updateSampleFont (); + if (newSelectIndex != -1) { + // in case it came by typing the name + combo.select (newSelectIndex); + } + ignoreEvents = false; + } + } + else + if (event.widget == okButton) { + okSelected = true; + shell.close (); + } + else + if (event.widget == cancelButton) { + okSelected = false; + shell.close (); + } + else + if (event.widget == colorButton) { + ColorDialog colorDialog = new ColorDialog (shell, SWT.NONE); + colorDialog.setRGB (rgb); + RGB newRgb = colorDialog.open (); + if (newRgb != null) { + rgb = newRgb; + updateSampleColor (); + } + } +} + +/** + * Initialize the extended styles combo with the extended styles + * available for the selected font. + * Downstream combos are initialized as well (style and size). */ -void handleEvent (Event event) {
- if (ignoreEvents) return;
- if (event.widget instanceof Combo) {
- Combo combo = (Combo) event.widget;
- int prevSelectIndex = ((Integer) combo.getData ()).intValue ();
- String text = combo.getText ();
- int newSelectIndex = combo.indexOf (text);
- if (prevSelectIndex != newSelectIndex || newSelectIndex == -1) {
- ignoreEvents = true;
- combo.setData (new Integer (newSelectIndex));
- if (combo == charSetCombo) initFaceNameCombo ();
- else if (combo == faceNameCombo) initExtStyleCombo ();
- else if (combo == extStyleCombo) initSizeCombo ();
- else if (combo == fontSizeCombo) initStyleCombo ();
- updateSampleFont ();
- if (newSelectIndex != -1) {
- // in case it came by typing the name
- combo.select (newSelectIndex);
- }
- ignoreEvents = false;
- }
- }
- else
- if (event.widget == okButton) {
- okSelected = true;
- shell.close ();
- }
- else
- if (event.widget == cancelButton) {
- okSelected = false;
- shell.close ();
- }
- else
- if (event.widget == colorButton) {
- ColorDialog colorDialog = new ColorDialog (shell, SWT.NONE);
- colorDialog.setRGB (rgb);
- RGB newRgb = colorDialog.open ();
- if (newRgb != null) {
- rgb = newRgb;
- updateSampleColor ();
- }
- }
-}
-
-/**
- * Initialize the extended styles combo with the extended styles
- * available for the selected font.
- * Downstream combos are initialized as well (style and size).
+void initExtStyleCombo () { + String oldSelect = extStyleCombo.getText (); + extStyleCombo.removeAll (); + + String characterSet = charSetCombo.getText (); + String faceName = faceNameCombo.getText (); + Hashtable extStyles = getExtStyles (characterSet, faceName); + setItemsSorted (extStyleCombo, extStyles); + + int selectIndex = extStyleCombo.indexOf (oldSelect); + selectIndex = Math.max (0, selectIndex); + extStyleCombo.select (selectIndex); + extStyleCombo.setData (new Integer (selectIndex)); + initSizeCombo (); +} + +/** + * Initialize the face name combo box with all font names + * available in the selected character set. + * Downstream combos are initialized as well (extended style). */ -void initExtStyleCombo () {
- String oldSelect = extStyleCombo.getText ();
- extStyleCombo.removeAll ();
-
- String characterSet = charSetCombo.getText ();
- String faceName = faceNameCombo.getText ();
- Hashtable extStyles = getExtStyles (characterSet, faceName);
- setItemsSorted (extStyleCombo, extStyles);
-
- int selectIndex = extStyleCombo.indexOf (oldSelect);
- selectIndex = Math.max (0, selectIndex);
- extStyleCombo.select (selectIndex);
- extStyleCombo.setData (new Integer (selectIndex));
- initSizeCombo ();
-}
-
-/**
- * Initialize the face name combo box with all font names
- * available in the selected character set.
- * Downstream combos are initialized as well (extended style).
+void initFaceNameCombo () { + String oldSelect = faceNameCombo.getText (); + faceNameCombo.removeAll (); + String charSetText = charSetCombo.getText (); + if (charSetText.length () == 0) return; + + Hashtable faceNames = getFaces (charSetText); + setItemsSorted (faceNameCombo, faceNames); + + int selectIndex = faceNameCombo.indexOf (oldSelect); + selectIndex = Math.max (0, selectIndex); + faceNameCombo.select (selectIndex); + faceNameCombo.setData (new Integer (selectIndex)); + initExtStyleCombo (); +} + +/** + * Initialize the widgets of the receiver with the data of + * all installed fonts. + * If the user specified a default font preselect that font in + * the combo boxes. */ -void initFaceNameCombo () {
- String oldSelect = faceNameCombo.getText ();
- faceNameCombo.removeAll ();
- String charSetText = charSetCombo.getText ();
- if (charSetText.length () == 0) return;
-
- Hashtable faceNames = getFaces (charSetText);
- setItemsSorted (faceNameCombo, faceNames);
-
- int selectIndex = faceNameCombo.indexOf (oldSelect);
- selectIndex = Math.max (0, selectIndex);
- faceNameCombo.select (selectIndex);
- faceNameCombo.setData (new Integer (selectIndex));
- initExtStyleCombo ();
-}
-
-/**
- * Initialize the widgets of the receiver with the data of
- * all installed fonts.
- * If the user specified a default font preselect that font in
- * the combo boxes.
+void initializeWidgets () { + Display display = shell.getDisplay (); + addFonts (display.getFontList (null, false)); // get all fonts availabe on the current display + addFonts (display.getFontList (null, true)); + setItemsSorted (charSetCombo, getFonts ()); + if (fontData != null) { + Font font = new Font (display, fontData); // verify that the initial font data is a valid font + ignoreEvents = true; + setFontCombos (font.getFontData ()[0]); + ignoreEvents = false; + font.dispose (); + } + updateSampleFont (); + updateSampleColor (); +} + +/** + * Initialize the size combo with the sizes the selected font + * is available in. + * If the selected font is scalable a selection of preset sizes + * is used. */ -void initializeWidgets () {
- Display display = shell.getDisplay ();
- addFonts (display.getFontList (null, false)); // get all fonts availabe on the current display
- addFonts (display.getFontList (null, true));
- setItemsSorted (charSetCombo, getFonts ());
- if (fontData != null) {
- Font font = new Font (display, fontData); // verify that the initial font data is a valid font
- ignoreEvents = true;
- setFontCombos (font.getFontData ()[0]);
- ignoreEvents = false;
- font.dispose ();
- }
- updateSampleFont ();
- updateSampleColor ();
-}
-
-/**
- * Initialize the size combo with the sizes the selected font
- * is available in.
- * If the selected font is scalable a selection of preset sizes
- * is used.
+void initSizeCombo () { + String oldSelect = fontSizeCombo.getText (); + fontSizeCombo.removeAll (); + + String characterSet = charSetCombo.getText (); + String faceName = faceNameCombo.getText (); + String extStyle = extStyleCombo.getText (); + Hashtable sizes = getSizes (characterSet, faceName, extStyle); + if (sizes != null) { + if (sizes.get (SCALABLE_KEY) == null) { + /* + * Font is not scalable so just present the provided sizes. + */ + setSizeItemsSorted (sizes.keys ()); + } else { + /* + * Font is scalable so present the provided sizes and scalable + * sizes for selection. + */ + Vector allSizes = new Vector (); + /* + * Add the scalable sizes. + */ + for (int i = 0; i < SCALABLE_SIZES.length; i++) { + allSizes.addElement (Integer.valueOf (SCALABLE_SIZES [i])); + } + /* + * Add the provided sizes. + */ + Enumeration providedSizes = sizes.keys (); + while (providedSizes.hasMoreElements ()) { + Integer size = (Integer) providedSizes.nextElement (); + if (!size.equals (SCALABLE_KEY) && !allSizes.contains (size)) { + allSizes.addElement (size); + } + } + setSizeItemsSorted (allSizes.elements ()); + } + } + + int selectIndex = fontSizeCombo.indexOf (oldSelect); + if (selectIndex == -1) { + selectIndex = fontSizeCombo.indexOf (String.valueOf (DEFAULT_SIZE)); + } + selectIndex = Math.max (0, selectIndex); + fontSizeCombo.select (selectIndex); + fontSizeCombo.setData (new Integer (selectIndex)); + initStyleCombo (); +} + +/** + * Initialize the styles combo with the styles the selected font + * is available in. */ -void initSizeCombo () {
- String oldSelect = fontSizeCombo.getText ();
- fontSizeCombo.removeAll ();
-
- String characterSet = charSetCombo.getText ();
- String faceName = faceNameCombo.getText ();
- String extStyle = extStyleCombo.getText ();
- Hashtable sizes = getSizes (characterSet, faceName, extStyle);
- if (sizes != null) {
- if (sizes.get (SCALABLE_KEY) == null) {
- /*
- * Font is not scalable so just present the provided sizes.
- */
- setSizeItemsSorted (sizes.keys ());
- } else {
- /*
- * Font is scalable so present the provided sizes and scalable
- * sizes for selection.
- */
- Vector allSizes = new Vector ();
- /*
- * Add the scalable sizes.
- */
- for (int i = 0; i < SCALABLE_SIZES.length; i++) {
- allSizes.addElement (Integer.valueOf (SCALABLE_SIZES [i]));
- }
- /*
- * Add the provided sizes.
- */
- Enumeration providedSizes = sizes.keys ();
- while (providedSizes.hasMoreElements ()) {
- Integer size = (Integer) providedSizes.nextElement ();
- if (!size.equals (SCALABLE_KEY) && !allSizes.contains (size)) {
- allSizes.addElement (size);
- }
- }
- setSizeItemsSorted (allSizes.elements ());
- }
- }
-
- int selectIndex = fontSizeCombo.indexOf (oldSelect);
- if (selectIndex == -1) {
- selectIndex = fontSizeCombo.indexOf (String.valueOf (DEFAULT_SIZE));
- }
- selectIndex = Math.max (0, selectIndex);
- fontSizeCombo.select (selectIndex);
- fontSizeCombo.setData (new Integer (selectIndex));
- initStyleCombo ();
-}
-
-/**
- * Initialize the styles combo with the styles the selected font
- * is available in.
+void initStyleCombo () { + String oldSelect = fontStyleCombo.getText (); + fontStyleCombo.removeAll (); + + String characterSet = charSetCombo.getText (); + String faceName = faceNameCombo.getText (); + String extStyle = extStyleCombo.getText (); + try { + int size = Integer.valueOf (fontSizeCombo.getText ()).intValue (); + if (size > 0) { + Hashtable styles = getStyles (characterSet, faceName, extStyle, size); + setItemsSorted (fontStyleCombo, styles); + } + } catch (NumberFormatException e) { + // fall through + } + + int selectIndex = fontStyleCombo.indexOf (oldSelect); + if (selectIndex == -1) { + selectIndex = fontStyleCombo.indexOf (String.valueOf (DEFAULT_STYLE)); + } + selectIndex = Math.max (0, selectIndex); + fontStyleCombo.select (selectIndex); + fontStyleCombo.setData (new Integer (selectIndex)); + fontStyleCombo.select (Math.max (0, selectIndex)); +} + +/** + * Register the receiver to receive events. */ -void initStyleCombo () {
- String oldSelect = fontStyleCombo.getText ();
- fontStyleCombo.removeAll ();
-
- String characterSet = charSetCombo.getText ();
- String faceName = faceNameCombo.getText ();
- String extStyle = extStyleCombo.getText ();
- try {
- int size = Integer.valueOf (fontSizeCombo.getText ()).intValue ();
- if (size > 0) {
- Hashtable styles = getStyles (characterSet, faceName, extStyle, size);
- setItemsSorted (fontStyleCombo, styles);
- }
- } catch (NumberFormatException e) {
- // fall through
- }
-
- int selectIndex = fontStyleCombo.indexOf (oldSelect);
- if (selectIndex == -1) {
- selectIndex = fontStyleCombo.indexOf (String.valueOf (DEFAULT_STYLE));
- }
- selectIndex = Math.max (0, selectIndex);
- fontStyleCombo.select (selectIndex);
- fontStyleCombo.setData (new Integer (selectIndex));
- fontStyleCombo.select (Math.max (0, selectIndex));
-}
-
-/**
- * Register the receiver to receive events.
+void installListeners () { + Listener listener = new Listener () { + public void handleEvent (Event event) { + FontDialog.this.handleEvent (event); + } + }; + okButton.addListener (SWT.Selection, listener); + cancelButton.addListener (SWT.Selection, listener); + colorButton.addListener (SWT.Selection, listener); + charSetCombo.addListener (SWT.Selection, listener); + charSetCombo.addListener (SWT.Modify, listener); + faceNameCombo.addListener (SWT.Modify, listener); + fontStyleCombo.addListener (SWT.Modify, listener); + extStyleCombo.addListener (SWT.Modify, listener); + fontSizeCombo.addListener (SWT.Modify, listener); +} + +/** + * 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> */ -void installListeners () {
- Listener listener = new Listener () {
- public void handleEvent (Event event) {
- FontDialog.this.handleEvent (event);
- }
- };
- okButton.addListener (SWT.Selection, listener);
- cancelButton.addListener (SWT.Selection, listener);
- colorButton.addListener (SWT.Selection, listener);
- charSetCombo.addListener (SWT.Selection, listener);
- charSetCombo.addListener (SWT.Modify, listener);
- faceNameCombo.addListener (SWT.Modify, listener);
- fontStyleCombo.addListener (SWT.Modify, listener);
- extStyleCombo.addListener (SWT.Modify, listener);
- fontSizeCombo.addListener (SWT.Modify, listener);
-}
-
-/**
- * Makes the dialog visible and brings it to the front
- * of the display.
- *
- * @return a FontData object describing the font that was selected,
- * or null if the dialog was cancelled or an error occurred
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li>
- * </ul>
+public FontData open () { + shell = new Shell (getParent (), getStyle () | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL); + createChildren (); + installListeners (); + + FontData originalFontData = fontData; + RGB originalRGB = rgb; + initializeWidgets (); + openDialog (); + Display display = shell.getDisplay (); + while (!shell.isDisposed ()) { + if (!display.readAndDispatch ()) display.sleep (); + } + + FontData result = null; + if (okSelected) { + result = fontData; + } else { + fontData = originalFontData; + rgb = originalRGB; + } + if (sampleFont != null) sampleFont.dispose (); + sampleFont = null; + if (sampleColor != null) sampleColor.dispose (); + sampleColor = null; + return result; +} + +/** + * Open the receiver and set its size to the size calculated by + * the layout manager. */ -public FontData open () {
- shell = new Shell (getParent (), getStyle () | SWT.TITLE | SWT.BORDER | SWT.APPLICATION_MODAL);
- createChildren ();
- installListeners ();
-
- FontData originalFontData = fontData;
- RGB originalRGB = rgb;
- initializeWidgets ();
- openDialog ();
- Display display = shell.getDisplay ();
- while (!shell.isDisposed ()) {
- if (!display.readAndDispatch ()) display.sleep ();
- }
-
- FontData result = null;
- if (okSelected) {
- result = fontData;
- } else {
- fontData = originalFontData;
- rgb = originalRGB;
- }
- if (sampleFont != null) sampleFont.dispose ();
- sampleFont = null;
- if (sampleColor != null) sampleColor.dispose ();
- sampleColor = null;
- return result;
-}
-
-/**
- * Open the receiver and set its size to the size calculated by
- * the layout manager.
+void openDialog () { + // Start everything off by setting the shell size to its computed size. + Point pt = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, false); + + // Ensure that the width of the shell fits the display. + Rectangle displayRect = shell.getDisplay().getBounds(); + int widthLimit = displayRect.width * 7 / 8; + int heightLimit = displayRect.height * 7 / 8; + if (pt.x > widthLimit) { + pt = shell.computeSize (widthLimit, SWT.DEFAULT, false); + } + + // centre the dialog on its parent, and ensure that the + // whole dialog appears within the screen bounds + Rectangle parentBounds = getParent ().getBounds (); + int originX = (parentBounds.width - pt.x) / 2 + parentBounds.x; + originX = Math.max (originX, 0); + originX = Math.min (originX, widthLimit - pt.x); + int originY = (parentBounds.height - pt.y) / 2 + parentBounds.y; + originY = Math.max (originY, 0); + originY = Math.min (originY, heightLimit - pt.y); + shell.setBounds (originX, originY, pt.x, pt.y); + + String title = getText (); + if (title.length () == 0) title = SWT.getMessage ("SWT_FontDialog_Title"); + shell.setText(title); + + // Open the window. + shell.open(); +} + +/** + * Initialize the combo boxes with the data of the preselected + * font specified by the user. */ -void openDialog () {
- // Start everything off by setting the shell size to its computed size.
- Point pt = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
-
- // Ensure that the width of the shell fits the display.
- Rectangle displayRect = shell.getDisplay().getBounds();
- int widthLimit = displayRect.width * 7 / 8;
- int heightLimit = displayRect.height * 7 / 8;
- if (pt.x > widthLimit) {
- pt = shell.computeSize (widthLimit, SWT.DEFAULT, false);
- }
-
- // centre the dialog on its parent, and ensure that the
- // whole dialog appears within the screen bounds
- Rectangle parentBounds = getParent ().getBounds ();
- int originX = (parentBounds.width - pt.x) / 2 + parentBounds.x;
- originX = Math.max (originX, 0);
- originX = Math.min (originX, widthLimit - pt.x);
- int originY = (parentBounds.height - pt.y) / 2 + parentBounds.y;
- originY = Math.max (originY, 0);
- originY = Math.min (originY, heightLimit - pt.y);
- shell.setBounds (originX, originY, pt.x, pt.y);
-
- String title = getText ();
- if (title.length () == 0) title = SWT.getMessage ("SWT_FontDialog_Title");
- shell.setText(title);
-
- // Open the window.
- shell.open();
-}
-
-/**
- * Initialize the combo boxes with the data of the preselected
- * font specified by the user.
+void setFontCombos (FontData fontData) { + String characterSet = getTranslatedCharSet (fontData); + String faceName = getTranslatedFaceName (fontData); + charSetCombo.setText (characterSet); + charSetCombo.setData (new Integer (charSetCombo.indexOf (characterSet))); + + initFaceNameCombo (); + faceNameCombo.setText (faceName); + faceNameCombo.setData (new Integer (faceNameCombo.indexOf (faceName))); + + initExtStyleCombo (); + extStyleCombo.setText (fontData.addStyle); + extStyleCombo.setData (new Integer (extStyleCombo.indexOf (fontData.addStyle))); + + initSizeCombo (); + String value = String.valueOf (fontData.getHeight ()); + fontSizeCombo.setText (value); + fontSizeCombo.setData (new Integer (fontSizeCombo.indexOf (value))); + + initStyleCombo (); + fontStyleCombo.setText (fontData.weight); + fontStyleCombo.setData (new Integer (fontStyleCombo.indexOf (fontData.weight))); +} + +/** + * 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 */ -void setFontCombos (FontData fontData) {
- String characterSet = getTranslatedCharSet (fontData);
- String faceName = getTranslatedFaceName (fontData);
- charSetCombo.setText (characterSet);
- charSetCombo.setData (new Integer (charSetCombo.indexOf (characterSet)));
-
- initFaceNameCombo ();
- faceNameCombo.setText (faceName);
- faceNameCombo.setData (new Integer (faceNameCombo.indexOf (faceName)));
-
- initExtStyleCombo ();
- extStyleCombo.setText (fontData.addStyle);
- extStyleCombo.setData (new Integer (extStyleCombo.indexOf (fontData.addStyle)));
-
- initSizeCombo ();
- String value = String.valueOf (fontData.getHeight ());
- fontSizeCombo.setText (value);
- fontSizeCombo.setData (new Integer (fontSizeCombo.indexOf (value)));
-
- initStyleCombo ();
- fontStyleCombo.setText (fontData.weight);
- fontStyleCombo.setData (new Integer (fontStyleCombo.indexOf (fontData.weight)));
-}
-
-/**
- * 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; +} + +/** + * 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 setFontData (FontData fontData) {
- this.fontData = fontData;
-}
-
-/**
- * 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;
-}
-
-/**
- * Set the contents of 'combo' to the keys of 'items'.
- * Keys are sorted in ascending order first and have to be Strings.
+public void setRGB (RGB rgb) { + this.rgb = rgb; +} + +/** + * Set the contents of 'combo' to the keys of 'items'. + * Keys are sorted in ascending order first and have to be Strings. */ -void setItemsSorted (Combo combo, Hashtable items) {
- if (items == null) return;
- Enumeration itemKeys = items.keys ();
- String [] sortedItems = new String[items.size ()];
- int index = 0;
- while (itemKeys.hasMoreElements ()) {
- String item = (String) itemKeys.nextElement ();
- if (item.length () != 0) sortedItems[index++] = item;
- }
- if (index != sortedItems.length) {
- String [] newItems = new String[index];
- System.arraycopy (sortedItems, 0, newItems, 0, index);
- sortedItems = newItems;
- }
- sort (sortedItems);
- combo.setItems (sortedItems);
-}
-
-/**
- * Set the contents of the size combo to the keys of 'items'.
- * Keys are sorted in ascending order first and have to be Integers.
+void setItemsSorted (Combo combo, Hashtable items) { + if (items == null) return; + Enumeration itemKeys = items.keys (); + String [] sortedItems = new String[items.size ()]; + int index = 0; + while (itemKeys.hasMoreElements ()) { + String item = (String) itemKeys.nextElement (); + if (item.length () != 0) sortedItems[index++] = item; + } + if (index != sortedItems.length) { + String [] newItems = new String[index]; + System.arraycopy (sortedItems, 0, newItems, 0, index); + sortedItems = newItems; + } + sort (sortedItems); + combo.setItems (sortedItems); +} + +/** + * Set the contents of the size combo to the keys of 'items'. + * Keys are sorted in ascending order first and have to be Integers. */ -void setSizeItemsSorted (Enumeration itemsEnum) {
- Vector items = new Vector ();
- while (itemsEnum.hasMoreElements ()) {
- items.addElement (itemsEnum.nextElement ());
- }
- Integer[] sortedItems = new Integer [items.size ()];
- items.copyInto (sortedItems);
- sort (sortedItems);
- String[] sortedItemStrings = new String [items.size ()];
- for (int i = 0; i < sortedItemStrings.length; i++) {
- sortedItemStrings [i] = String.valueOf (sortedItems [i].intValue ());
- }
- fontSizeCombo.setItems (sortedItemStrings);
-}
-
-/**
- * Sort 'items' in ascending order.
+void setSizeItemsSorted (Enumeration itemsEnum) { + Vector items = new Vector (); + while (itemsEnum.hasMoreElements ()) { + items.addElement (itemsEnum.nextElement ()); + } + Integer[] sortedItems = new Integer [items.size ()]; + items.copyInto (sortedItems); + sort (sortedItems); + String[] sortedItemStrings = new String [items.size ()]; + for (int i = 0; i < sortedItemStrings.length; i++) { + sortedItemStrings [i] = String.valueOf (sortedItems [i].intValue ()); + } + fontSizeCombo.setItems (sortedItemStrings); +} + +/** + * Sort 'items' in ascending order. */ -void sort (Integer[] items) {
- /* Shell Sort from K&R, pg 108 */
- int length = items.length;
- for (int gap = length / 2; gap > 0; gap /= 2) {
- for (int i = gap; i < length; i++) {
- for (int j = i - gap; j >= 0; j -= gap) {
- if (items [j].intValue () > items [j + gap].intValue ()) {
- Integer swap = items [j];
- items[j] = items [j + gap];
- items[j + gap] = swap;
- }
- }
- }
- }
-}
-
-/**
- * Sort 'items' in ascending order.
+void sort (Integer[] items) { + /* Shell Sort from K&R, pg 108 */ + int length = items.length; + for (int gap = length / 2; gap > 0; gap /= 2) { + for (int i = gap; i < length; i++) { + for (int j = i - gap; j >= 0; j -= gap) { + if (items [j].intValue () > items [j + gap].intValue ()) { + Integer swap = items [j]; + items[j] = items [j + gap]; + items[j + gap] = swap; + } + } + } + } +} + +/** + * Sort 'items' in ascending order. */ -void sort (String items[]) {
- /* Shell Sort from K&R, pg 108 */
- int length = items.length;
- for (int gap = length / 2; gap > 0; gap /= 2) {
- for (int i = gap; i < length; i++) {
- for (int j = i - gap; j >= 0; j -= gap) {
- if (items [j].compareTo (items [j + gap]) > 0) {
- String swap = items [j];
- items [j] = items[j + gap];
- items [j + gap] = swap;
- }
- }
- }
- }
-}
-
-/**
- * Set the font of the sample text to the selected font.
- * Display an error in place of the sample text if the selected
- * font could not be loaded.
+void sort (String items[]) { + /* Shell Sort from K&R, pg 108 */ + int length = items.length; + for (int gap = length / 2; gap > 0; gap /= 2) { + for (int i = gap; i < length; i++) { + for (int j = i - gap; j >= 0; j -= gap) { + if (items [j].compareTo (items [j + gap]) > 0) { + String swap = items [j]; + items [j] = items[j + gap]; + items [j + gap] = swap; + } + } + } + } +} + +/** + * Set the font of the sample text to the selected font. + * Display an error in place of the sample text if the selected + * font could not be loaded. */ -void updateSampleFont () {
- FontData selectionFontData = getSelectionFontData ();
- /*
- * sampleFont may not be the same as the one specified in selectionFontData.
- * This happens when selectionFontData specifies a font alias.
- */
- if (sampleFont != null) sampleFont.dispose ();
- sampleFont = new Font (shell.getDisplay (), selectionFontData);
- fontData = selectionFontData;
- sampleLabel.setFont (sampleFont);
-}
-
-void updateSampleColor() {
- if (rgb == null) {
- rgb = new RGB(0, 0, 0);
- }
- if (sampleColor != null) {
- if (sampleColor.getRGB ().equals (rgb)) return;
- sampleColor.dispose();
- }
- sampleColor = new Color (getParent ().getDisplay (), rgb);
- sampleLabel.setForeground (sampleColor);
-}
+void updateSampleFont () { + FontData selectionFontData = getSelectionFontData (); + /* + * sampleFont may not be the same as the one specified in selectionFontData. + * This happens when selectionFontData specifies a font alias. + */ + if (sampleFont != null) sampleFont.dispose (); + sampleFont = new Font (shell.getDisplay (), selectionFontData); + fontData = selectionFontData; + sampleLabel.setFont (sampleFont); +} + +void updateSampleColor() { + if (rgb == null) { + rgb = new RGB(0, 0, 0); + } + if (sampleColor != null) { + if (sampleColor.getRGB ().equals (rgb)) return; + sampleColor.dispose(); + } + sampleColor = new Color (getParent ().getDisplay (), rgb); + sampleLabel.setForeground (sampleColor); +} }
\ No newline at end of file diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java index 5f11b7872e..61eaa1672a 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Group.java @@ -1,40 +1,40 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.*;
-
-/**
- * Instances of this class provide an etched border
- * with an optional title.
- * <p>
- * Shadow styles are hints and may not be honoured
- * by the platform. To create a group with the
- * default shadow style for the platform, do not
- * specify a shadow style.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>SHADOW_ETCHED_IN, SHADOW_ETCHED_OUT, SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the above styles may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html */ -public class Group extends Composite {
- int labelHandle;
-
+ +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.*; + +/** + * Instances of this class provide an etched border + * with an optional title. + * <p> + * Shadow styles are hints and may not be honoured + * by the platform. To create a group with the + * default shadow style for the platform, do not + * specify a shadow style. + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>SHADOW_ETCHED_IN, SHADOW_ETCHED_OUT, SHADOW_IN, SHADOW_OUT, SHADOW_NONE</dd> + * <dt><b>Events:</b></dt> + * <dd>(none)</dd> + * </dl> + * <p> + * Note: Only one of the above styles may be specified. + * </p><p> + * IMPORTANT: This class is <em>not</em> intended to be subclassed. + * </p> + */ +public class Group extends Composite { + int labelHandle; + /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -67,242 +67,242 @@ public class Group extends Composite { * @see Widget#checkSubclass * @see Widget#getStyle */ -public Group (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-static int checkStyle (int style) {
- style |= SWT.NO_FOCUS;
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- int trimX, trimY, trimWidth, trimHeight;
- int [] argList = {
- OS.XmNshadowThickness, 0,
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int thickness = argList [1];
- int marginWidth = argList [3];
- int marginHeight = argList [5];
- int borderWidth = getBorderWidth ();
- trimX = x - marginWidth + thickness - borderWidth;
- trimY = y - marginHeight + thickness - borderWidth;
- trimWidth = width + ((marginWidth + thickness + borderWidth) * 2);
- trimHeight = height + ((marginHeight + thickness + borderWidth) * 2);
- if (OS.XtIsManaged (labelHandle)) {
- int [] argList2 = {OS.XmNy, 0, OS.XmNheight, 0, OS.XmNchildHorizontalSpacing, 0};
- OS.XtGetValues (labelHandle, argList2, argList2.length / 2);
- int titleHeight = ((short) argList2 [1]) + argList2 [3];
- trimY = y - titleHeight;
- trimHeight = height + titleHeight + (marginHeight + thickness + borderWidth);
- XtWidgetGeometry result = new XtWidgetGeometry ();
- OS.XtQueryGeometry (labelHandle, null, result);
- int titleWidth = result.width + 2 * (argList2 [5] + marginWidth + thickness + borderWidth);
- trimWidth = Math.max (trimWidth, titleWidth);
- }
- return new Rectangle (trimX, trimY, trimWidth, trimHeight);
-}
-void createHandle (int index) {
- state |= HANDLE;
-
- /*
- * Feature in Motif. When a widget is managed or unmanaged,
- * it may request and be granted, a new size in the OS. This
- * behavior is unwanted. The fix is to create a parent for
- * the list that will disallow geometry requests.
- */
- int border = (style & SWT.BORDER) != 0 ? 1 : 0;
- int [] argList1 = {
- OS.XmNancestorSensitive, 1,
- OS.XmNborderWidth, border,
- };
- int parentHandle = parent.handle;
- formHandle = OS.XmCreateForm (parentHandle, null, argList1, argList1.length / 2);
- if (formHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int [] argList2 = {
- OS.XmNshadowType, shadowType (),
- OS.XmNtopAttachment, OS.XmATTACH_FORM,
- OS.XmNbottomAttachment, OS.XmATTACH_FORM,
- OS.XmNleftAttachment, OS.XmATTACH_FORM,
- OS.XmNrightAttachment, OS.XmATTACH_FORM,
- OS.XmNresizable, 0,
- };
- handle = OS.XmCreateFrame (formHandle, null, argList2, argList2.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- int [] argList3 = {OS.XmNframeChildType, OS.XmFRAME_TITLE_CHILD};
- labelHandle = OS.XmCreateLabel (handle, null, argList3, argList3.length / 2);
- if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-void createWidget (int index) {
- super.createWidget (index);
- /*
- * Bug in Motif. For some reason, if a form has not been realized,
- * calling XtResizeWidget () on the form does not lay out properly.
- * The fix is to force the widget to be realized by forcing the shell
- * to be realized.
- */
- getShell ().realizeWidget ();
-}
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- enableHandle (enabled, labelHandle);
-}
-int fontHandle () {
- return labelHandle;
-}
-public Rectangle getClientArea () {
- checkWidget();
- int [] argList = {
- OS.XmNwidth, 0,
- OS.XmNheight, 0,
- OS.XmNshadowThickness, 0,
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int thickness = argList [5];
- int marginWidth = argList [7];
- int marginHeight = argList [9];
- int x = marginWidth + thickness;
- int y = marginHeight + thickness;
- int width = argList [1] - ((marginWidth + thickness) * 2) - 1;
- int height = argList [3] - ((marginHeight + thickness) * 2) - 1;
- if (OS.XtIsManaged (labelHandle)) {
- int [] argList2 = {OS.XmNy, 0, OS.XmNheight, 0};
- OS.XtGetValues (labelHandle, argList2, argList2.length / 2);
- y = ((short) argList2 [1]) + argList2 [3];
- height = argList [3] - y - (marginHeight + thickness) - 1;
- }
- return new Rectangle (x, y, width, height);
-}
-/**
- * Returns the receiver's text, which is the string that the
- * is used as the <em>title</em>. If the text has not previously
- * been set, returns an empty string.
- *
- * @return the text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public Group (Composite parent, int style) { + super (parent, checkStyle (style)); +} +static int checkStyle (int style) { + style |= SWT.NO_FOCUS; + /* + * Even though it is legal to create this widget + * with scroll bars, they serve no useful purpose + * because they do not automatically scroll the + * widget's client area. The fix is to clear + * the SWT style. + */ + return style & ~(SWT.H_SCROLL | SWT.V_SCROLL); +} +protected void checkSubclass () { + if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); +} +public Rectangle computeTrim (int x, int y, int width, int height) { + checkWidget(); + int trimX, trimY, trimWidth, trimHeight; + int [] argList = { + OS.XmNshadowThickness, 0, + OS.XmNmarginWidth, 0, + OS.XmNmarginHeight, 0 + }; + OS.XtGetValues (handle, argList, argList.length / 2); + int thickness = argList [1]; + int marginWidth = argList [3]; + int marginHeight = argList [5]; + int borderWidth = getBorderWidth (); + trimX = x - marginWidth + thickness - borderWidth; + trimY = y - marginHeight + thickness - borderWidth; + trimWidth = width + ((marginWidth + thickness + borderWidth) * 2); + trimHeight = height + ((marginHeight + thickness + borderWidth) * 2); + if (OS.XtIsManaged (labelHandle)) { + int [] argList2 = {OS.XmNy, 0, OS.XmNheight, 0, OS.XmNchildHorizontalSpacing, 0}; + OS.XtGetValues (labelHandle, argList2, argList2.length / 2); + int titleHeight = ((short) argList2 [1]) + argList2 [3]; + trimY = y - titleHeight; + trimHeight = height + titleHeight + (marginHeight + thickness + borderWidth); + XtWidgetGeometry result = new XtWidgetGeometry (); + OS.XtQueryGeometry (labelHandle, null, result); + int titleWidth = result.width + 2 * (argList2 [5] + marginWidth + thickness + borderWidth); + trimWidth = Math.max (trimWidth, titleWidth); + } + return new Rectangle (trimX, trimY, trimWidth, trimHeight); +} +void createHandle (int index) { + state |= HANDLE; + + /* + * Feature in Motif. When a widget is managed or unmanaged, + * it may request and be granted, a new size in the OS. This + * behavior is unwanted. The fix is to create a parent for + * the list that will disallow geometry requests. + */ + int border = (style & SWT.BORDER) != 0 ? 1 : 0; + int [] argList1 = { + OS.XmNancestorSensitive, 1, + OS.XmNborderWidth, border, + }; + int parentHandle = parent.handle; + formHandle = OS.XmCreateForm (parentHandle, null, argList1, argList1.length / 2); + if (formHandle == 0) error (SWT.ERROR_NO_HANDLES); + int [] argList2 = { + OS.XmNshadowType, shadowType (), + OS.XmNtopAttachment, OS.XmATTACH_FORM, + OS.XmNbottomAttachment, OS.XmATTACH_FORM, + OS.XmNleftAttachment, OS.XmATTACH_FORM, + OS.XmNrightAttachment, OS.XmATTACH_FORM, + OS.XmNresizable, 0, + }; + handle = OS.XmCreateFrame (formHandle, null, argList2, argList2.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + int [] argList3 = {OS.XmNframeChildType, OS.XmFRAME_TITLE_CHILD}; + labelHandle = OS.XmCreateLabel (handle, null, argList3, argList3.length / 2); + if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES); +} +void createWidget (int index) { + super.createWidget (index); + /* + * Bug in Motif. For some reason, if a form has not been realized, + * calling XtResizeWidget () on the form does not lay out properly. + * The fix is to force the widget to be realized by forcing the shell + * to be realized. + */ + getShell ().realizeWidget (); +} +void enableWidget (boolean enabled) { + super.enableWidget (enabled); + enableHandle (enabled, labelHandle); +} +int fontHandle () { + return labelHandle; +} +public Rectangle getClientArea () { + checkWidget(); + int [] argList = { + OS.XmNwidth, 0, + OS.XmNheight, 0, + OS.XmNshadowThickness, 0, + OS.XmNmarginWidth, 0, + OS.XmNmarginHeight, 0 + }; + OS.XtGetValues (handle, argList, argList.length / 2); + int thickness = argList [5]; + int marginWidth = argList [7]; + int marginHeight = argList [9]; + int x = marginWidth + thickness; + int y = marginHeight + thickness; + int width = argList [1] - ((marginWidth + thickness) * 2) - 1; + int height = argList [3] - ((marginHeight + thickness) * 2) - 1; + if (OS.XtIsManaged (labelHandle)) { + int [] argList2 = {OS.XmNy, 0, OS.XmNheight, 0}; + OS.XtGetValues (labelHandle, argList2, argList2.length / 2); + y = ((short) argList2 [1]) + argList2 [3]; + height = argList [3] - y - (marginHeight + thickness) - 1; + } + return new Rectangle (x, y, width, height); +} +/** + * Returns the receiver's text, which is the string that the + * is used as the <em>title</em>. If the text has not previously + * been set, returns an empty string. + * + * @return the text + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public String getText () {
- checkWidget();
- int [] argList = {OS.XmNlabelString, 0};
- OS.XtGetValues (labelHandle, argList, 1);
- int xmString = argList [1];
- int address = OS.XmStringUnparse (
- xmString,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- OS.XmOUTPUT_ALL);
- if (address == 0) return "";
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- OS.XtFree (address);
- OS.XmStringFree (xmString);
- return new String (Converter.mbcsToWcs (getCodePage (), buffer));
-}
-boolean mnemonicHit (char key) {
- return setFocus ();
-}
-boolean mnemonicMatch (char key) {
- char mnemonic = findMnemonic (getText ());
- if (mnemonic == '\0') return false;
- return Character.toUpperCase (key) == Character.toUpperCase (mnemonic);
-}
-void propagateWidget (boolean enabled) {
- super.propagateWidget (enabled);
- propagateHandle (enabled, labelHandle);
-}
-void redrawWidget (int x, int y, int width, int height, boolean all) {
- super.redrawWidget (x, y, width, height, all);
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (handle, (short) x, (short) y, root_x, root_y);
- short [] label_x = new short [1], label_y = new short [1];
- OS.XtTranslateCoords (labelHandle, (short) 0, (short) 0, label_x, label_y);
- redrawHandle (root_x [0] - label_x [0], root_y [0] - label_y [0], width, height, labelHandle);
-}
-void releaseHandle () {
- super.releaseHandle ();
- labelHandle = 0;
-}
-/**
- * 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 String getText () { + checkWidget(); + int [] argList = {OS.XmNlabelString, 0}; + OS.XtGetValues (labelHandle, argList, 1); + int xmString = argList [1]; + int address = OS.XmStringUnparse ( + xmString, + null, + OS.XmCHARSET_TEXT, + OS.XmCHARSET_TEXT, + null, + 0, + OS.XmOUTPUT_ALL); + if (address == 0) return ""; + int length = OS.strlen (address); + byte [] buffer = new byte [length]; + OS.memmove (buffer, address, length); + OS.XtFree (address); + OS.XmStringFree (xmString); + return new String (Converter.mbcsToWcs (getCodePage (), buffer)); +} +boolean mnemonicHit (char key) { + return setFocus (); +} +boolean mnemonicMatch (char key) { + char mnemonic = findMnemonic (getText ()); + if (mnemonic == '\0') return false; + return Character.toUpperCase (key) == Character.toUpperCase (mnemonic); +} +void propagateWidget (boolean enabled) { + super.propagateWidget (enabled); + propagateHandle (enabled, labelHandle); +} +void redrawWidget (int x, int y, int width, int height, boolean all) { + super.redrawWidget (x, y, width, height, all); + short [] root_x = new short [1], root_y = new short [1]; + OS.XtTranslateCoords (handle, (short) x, (short) y, root_x, root_y); + short [] label_x = new short [1], label_y = new short [1]; + OS.XtTranslateCoords (labelHandle, (short) 0, (short) 0, label_x, label_y); + redrawHandle (root_x [0] - label_x [0], root_y [0] - label_y [0], width, height, labelHandle); +} +void releaseHandle () { + super.releaseHandle (); + labelHandle = 0; +} +/** + * 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) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- char [] text = new char [string.length ()];
- string.getChars (0, text.length, text, 0);
- int i=0, j=0, mnemonic=0;
- while (i < text.length) {
- if ((text [j++] = text [i++]) == Mnemonic) {
- if (i == text.length) {continue;}
- if (text [i] == Mnemonic) {i++; continue;}
- if (mnemonic == 0) mnemonic = text [i];
- j--;
- }
- }
- while (j < text.length) text [j++] = 0;
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), text, true);
- int xmString = OS.XmStringParseText (
- buffer,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- if (xmString == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- if (mnemonic == 0) mnemonic = OS.XK_VoidSymbol;
- int [] argList = {
- OS.XmNlabelType, OS.XmSTRING,
- OS.XmNlabelString, xmString,
- OS.XmNmnemonic, mnemonic,
- };
- OS.XtSetValues (labelHandle, argList, argList.length / 2);
- if (xmString != 0) OS.XmStringFree (xmString);
- if (string.length () == 0) {
- OS.XtUnmanageChild (labelHandle);
- } else {
- OS.XtManageChild (labelHandle);
- }
-}
-int shadowType () {
- if ((style & SWT.SHADOW_IN) != 0) return OS.XmSHADOW_IN;
- if ((style & SWT.SHADOW_OUT) != 0) return OS.XmSHADOW_OUT;
- if ((style & SWT.SHADOW_ETCHED_IN) != 0) return OS.XmSHADOW_ETCHED_IN;
- if ((style & SWT.SHADOW_ETCHED_OUT) != 0) return OS.XmSHADOW_ETCHED_OUT;
- return OS.XmSHADOW_ETCHED_IN;
-}
-}
+public void setText (String string) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + char [] text = new char [string.length ()]; + string.getChars (0, text.length, text, 0); + int i=0, j=0, mnemonic=0; + while (i < text.length) { + if ((text [j++] = text [i++]) == Mnemonic) { + if (i == text.length) {continue;} + if (text [i] == Mnemonic) {i++; continue;} + if (mnemonic == 0) mnemonic = text [i]; + j--; + } + } + while (j < text.length) text [j++] = 0; + byte [] buffer = Converter.wcsToMbcs (getCodePage (), text, true); + int xmString = OS.XmStringParseText ( + buffer, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + if (xmString == 0) error (SWT.ERROR_CANNOT_SET_TEXT); + if (mnemonic == 0) mnemonic = OS.XK_VoidSymbol; + int [] argList = { + OS.XmNlabelType, OS.XmSTRING, + OS.XmNlabelString, xmString, + OS.XmNmnemonic, mnemonic, + }; + OS.XtSetValues (labelHandle, argList, argList.length / 2); + if (xmString != 0) OS.XmStringFree (xmString); + if (string.length () == 0) { + OS.XtUnmanageChild (labelHandle); + } else { + OS.XtManageChild (labelHandle); + } +} +int shadowType () { + if ((style & SWT.SHADOW_IN) != 0) return OS.XmSHADOW_IN; + if ((style & SWT.SHADOW_OUT) != 0) return OS.XmSHADOW_OUT; + if ((style & SWT.SHADOW_ETCHED_IN) != 0) return OS.XmSHADOW_ETCHED_IN; + if ((style & SWT.SHADOW_ETCHED_OUT) != 0) return OS.XmSHADOW_ETCHED_OUT; + return OS.XmSHADOW_ETCHED_IN; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java index 69a29cf108..a9628ee464 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Label.java @@ -1,18 +1,18 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.motif.*; + +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; + /** * Instances of this class represent a non-selectable * user interface object that displays a string or image. @@ -35,10 +35,10 @@ import org.eclipse.swt.graphics.*; * within the SWT implementation. * </p> */ -public class Label extends Control {
- String text = "";
- Image image, bitmap, disabled;
-
+public class Label extends Control { + String text = ""; + Image image, bitmap, disabled; + /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -76,402 +76,402 @@ public class Label extends Control { * @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);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- if ((style & SWT.SEPARATOR) != 0) {
- if ((style & SWT.HORIZONTAL) != 0) {
- width += DEFAULT_WIDTH; height += 3;
- } else {
- width += 3; height += DEFAULT_HEIGHT;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
- }
- int [] argList = {OS.XmNlabelType, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int labelType = argList [1];
- if (labelType == OS.XmSTRING && (style & SWT.WRAP) != 0 && wHint != SWT.DEFAULT) {
- /* If we are wrapping text, calculate the height based on wHint. */
- int [] argList4 = {
- OS.XmNmarginTop, 0, /* 1 */
- OS.XmNmarginBottom, 0, /* 3 */
- OS.XmNmarginHeight, 0, /* 5 */
- OS.XmNmarginWidth, 0, /* 7 */
- };
- OS.XtGetValues (handle, argList4, argList4.length / 2);
- int unavailable = 2 * (argList4 [7] + getBorderWidth());
- Display display = getDisplay ();
- String string = display.wrapText (text, font, wHint - unavailable);
- GC gc = new GC(this);
- Point extent = gc.textExtent(string);
- gc.dispose();
- height = extent.y + argList4 [1] + argList4 [3] + argList4 [5] * 2 + border * 2;
- } else {
- /* If we are not wrapping, ask the widget for its geometry. */
- XtWidgetGeometry result = new XtWidgetGeometry ();
- result.request_mode = OS.CWWidth | OS.CWHeight;
- int [] argList2 = {OS.XmNrecomputeSize, 1};
- OS.XtSetValues(handle, argList2, argList2.length / 2);
- OS.XtQueryGeometry (handle, null, result);
- int [] argList3 = {OS.XmNrecomputeSize, 0};
- OS.XtSetValues(handle, argList3, argList3.length / 2);
- width += result.width;
- height += result.height;
- }
-
- /*
- * Feature in Motif. If a label's labelType is XmSTRING but it
- * has no label set into it yet, recomputing the size will
- * not take into account the height of the font, as we would
- * like it to. Take care of this case.
- */
- if (labelType == OS.XmSTRING && text.length () == 0) {
- height += getFontHeight ();
- width = 0;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-void createHandle (int index) {
- state |= HANDLE;
- int parentHandle = parent.handle;
- int borderWidth = (style & SWT.BORDER) != 0 ? 1 : 0;
- if ((style & SWT.SEPARATOR) != 0) {
- int separatorType = separatorType ();
- int orientation = (style & SWT.HORIZONTAL) != 0 ? OS.XmHORIZONTAL : OS.XmVERTICAL;
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNborderWidth, borderWidth,
- OS.XmNorientation, orientation,
- OS.XmNseparatorType, separatorType,
- };
- handle = OS.XmCreateSeparator (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- return;
- }
- int alignment = OS.XmALIGNMENT_BEGINNING;
- if ((style & SWT.CENTER) != 0) alignment = OS.XmALIGNMENT_CENTER;
- if ((style & SWT.RIGHT) != 0) alignment = OS.XmALIGNMENT_END;
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNrecomputeSize, 0,
- OS.XmNalignment, alignment,
- OS.XmNborderWidth, borderWidth,
- };
- handle = OS.XmCreateLabel (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-int defaultBackground () {
- return getDisplay ().labelBackground;
-}
-Font defaultFont () {
- return getDisplay ().labelFont;
-}
-int defaultForeground () {
- return getDisplay ().labelForeground;
-}
-public boolean forceFocus () {
- checkWidget();
- int [] argList = new int [] {OS.XmNtraversalOn, 1};
- OS.XtSetValues (handle, argList, argList.length / 2);
- overrideTranslations ();
- if (super.forceFocus ()) return true;
- argList [1] = 0;
- OS.XtSetValues (handle, argList, argList.length / 2);
- return false;
-}
-/**
- * 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 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); +} +public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget(); + int border = getBorderWidth (); + int width = border * 2, height = border * 2; + if ((style & SWT.SEPARATOR) != 0) { + if ((style & SWT.HORIZONTAL) != 0) { + width += DEFAULT_WIDTH; height += 3; + } else { + width += 3; height += DEFAULT_HEIGHT; + } + if (wHint != SWT.DEFAULT) width = wHint + (border * 2); + if (hHint != SWT.DEFAULT) height = hHint + (border * 2); + return new Point (width, height); + } + int [] argList = {OS.XmNlabelType, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int labelType = argList [1]; + if (labelType == OS.XmSTRING && (style & SWT.WRAP) != 0 && wHint != SWT.DEFAULT) { + /* If we are wrapping text, calculate the height based on wHint. */ + int [] argList4 = { + OS.XmNmarginTop, 0, /* 1 */ + OS.XmNmarginBottom, 0, /* 3 */ + OS.XmNmarginHeight, 0, /* 5 */ + OS.XmNmarginWidth, 0, /* 7 */ + }; + OS.XtGetValues (handle, argList4, argList4.length / 2); + int unavailable = 2 * (argList4 [7] + getBorderWidth()); + Display display = getDisplay (); + String string = display.wrapText (text, font, wHint - unavailable); + GC gc = new GC(this); + Point extent = gc.textExtent(string); + gc.dispose(); + height = extent.y + argList4 [1] + argList4 [3] + argList4 [5] * 2 + border * 2; + } else { + /* If we are not wrapping, ask the widget for its geometry. */ + XtWidgetGeometry result = new XtWidgetGeometry (); + result.request_mode = OS.CWWidth | OS.CWHeight; + int [] argList2 = {OS.XmNrecomputeSize, 1}; + OS.XtSetValues(handle, argList2, argList2.length / 2); + OS.XtQueryGeometry (handle, null, result); + int [] argList3 = {OS.XmNrecomputeSize, 0}; + OS.XtSetValues(handle, argList3, argList3.length / 2); + width += result.width; + height += result.height; + } + + /* + * Feature in Motif. If a label's labelType is XmSTRING but it + * has no label set into it yet, recomputing the size will + * not take into account the height of the font, as we would + * like it to. Take care of this case. + */ + if (labelType == OS.XmSTRING && text.length () == 0) { + height += getFontHeight (); + width = 0; + } + if (wHint != SWT.DEFAULT) width = wHint + (border * 2); + if (hHint != SWT.DEFAULT) height = hHint + (border * 2); + return new Point (width, height); +} +void createHandle (int index) { + state |= HANDLE; + int parentHandle = parent.handle; + int borderWidth = (style & SWT.BORDER) != 0 ? 1 : 0; + if ((style & SWT.SEPARATOR) != 0) { + int separatorType = separatorType (); + int orientation = (style & SWT.HORIZONTAL) != 0 ? OS.XmHORIZONTAL : OS.XmVERTICAL; + int [] argList = { + OS.XmNancestorSensitive, 1, + OS.XmNborderWidth, borderWidth, + OS.XmNorientation, orientation, + OS.XmNseparatorType, separatorType, + }; + handle = OS.XmCreateSeparator (parentHandle, null, argList, argList.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + return; + } + int alignment = OS.XmALIGNMENT_BEGINNING; + if ((style & SWT.CENTER) != 0) alignment = OS.XmALIGNMENT_CENTER; + if ((style & SWT.RIGHT) != 0) alignment = OS.XmALIGNMENT_END; + int [] argList = { + OS.XmNancestorSensitive, 1, + OS.XmNrecomputeSize, 0, + OS.XmNalignment, alignment, + OS.XmNborderWidth, borderWidth, + }; + handle = OS.XmCreateLabel (parentHandle, null, argList, argList.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); +} +int defaultBackground () { + return getDisplay ().labelBackground; +} +Font defaultFont () { + return getDisplay ().labelFont; +} +int defaultForeground () { + return getDisplay ().labelForeground; +} +public boolean forceFocus () { + checkWidget(); + int [] argList = new int [] {OS.XmNtraversalOn, 1}; + OS.XtSetValues (handle, argList, argList.length / 2); + overrideTranslations (); + if (super.forceFocus ()) return true; + argList [1] = 0; + OS.XtSetValues (handle, argList, argList.length / 2); + return false; +} +/** + * Returns a value which describes the position of the + * text or image in the receiver. The value will be one of + * <code>LEFT</code>, <code>RIGHT</code> or <code>CENTER</code> + * unless the receiver is a <code>SEPARATOR</code> label, in + * which case, <code>NONE</code> is returned. + * + * @return the alignment + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getAlignment () {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return SWT.LEFT;
- int [] argList = {OS.XmNalignment, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int alignment = argList [1];
- if (alignment == OS.XmALIGNMENT_BEGINNING) return SWT.LEFT;
- if (alignment == OS.XmALIGNMENT_CENTER) return SWT.CENTER;
- if (alignment == OS.XmALIGNMENT_END)return SWT.RIGHT;
- return SWT.LEFT;
-}
-/**
- * Returns the receiver's image if it has one, or null
- * if it does not.
- *
- * @return the receiver's image
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getAlignment () { + checkWidget(); + if ((style & SWT.SEPARATOR) != 0) return SWT.LEFT; + int [] argList = {OS.XmNalignment, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int alignment = argList [1]; + if (alignment == OS.XmALIGNMENT_BEGINNING) return SWT.LEFT; + if (alignment == OS.XmALIGNMENT_CENTER) return SWT.CENTER; + if (alignment == OS.XmALIGNMENT_END)return SWT.RIGHT; + return SWT.LEFT; +} +/** + * Returns the receiver's image if it has one, or null + * if it does not. + * + * @return the receiver's image + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public Image getImage () {
- checkWidget();
- return image;
-}
-String getNameText () {
- return getText ();
-}
-/**
- * Returns the receiver's text, which will be an empty
- * string if it has never been set or if the receiver is
- * a <code>SEPARATOR</code> label.
- *
- * @return the receiver's text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public 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;
-}
-boolean mnemonicHit (char key) {
- Composite control = this.parent;
- while (control != null) {
- Control [] children = control._getChildren ();
- int index = 0;
- while (index < children.length) {
- if (children [index] == this) break;
- index++;
- }
- index++;
- if (index < children.length) {
- if (children [index].setFocus ()) return true;
- }
- control = control.parent;
- }
- return false;
-}
-boolean mnemonicMatch (char key) {
- char mnemonic = findMnemonic (getText ());
- if (mnemonic == '\0') return false;
- return Character.toUpperCase (key) == Character.toUpperCase (mnemonic);
-}
-void releaseWidget () {
- super.releaseWidget ();
- int [] argList = {
- OS.XmNlabelPixmap, OS.XmUNSPECIFIED_PIXMAP,
- OS.XmNlabelInsensitivePixmap, OS.XmUNSPECIFIED_PIXMAP,
- };
- OS.XtSetValues (handle, argList, argList.length / 2);
- if (bitmap != null) bitmap.dispose ();
- if (disabled != null) disabled.dispose ();
- image = bitmap = disabled = null;
-}
-int separatorType () {
- if ((style & (SWT.SHADOW_IN)) != 0) return OS.XmSHADOW_ETCHED_IN;
- if ((style & (SWT.SHADOW_OUT)) != 0) return OS.XmSHADOW_ETCHED_OUT;
- return OS.XmSHADOW_ETCHED_IN;
-}
-/**
- * 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 String getText () { + checkWidget(); + if ((style & SWT.SEPARATOR) != 0) return ""; + return text; +} +boolean mnemonicHit (char key) { + Composite control = this.parent; + while (control != null) { + Control [] children = control._getChildren (); + int index = 0; + while (index < children.length) { + if (children [index] == this) break; + index++; + } + index++; + if (index < children.length) { + if (children [index].setFocus ()) return true; + } + control = control.parent; + } + return false; +} +boolean mnemonicMatch (char key) { + char mnemonic = findMnemonic (getText ()); + if (mnemonic == '\0') return false; + return Character.toUpperCase (key) == Character.toUpperCase (mnemonic); +} +void releaseWidget () { + super.releaseWidget (); + int [] argList = { + OS.XmNlabelPixmap, OS.XmUNSPECIFIED_PIXMAP, + OS.XmNlabelInsensitivePixmap, OS.XmUNSPECIFIED_PIXMAP, + }; + OS.XtSetValues (handle, argList, argList.length / 2); + if (bitmap != null) bitmap.dispose (); + if (disabled != null) disabled.dispose (); + image = bitmap = disabled = null; +} +int separatorType () { + if ((style & (SWT.SHADOW_IN)) != 0) return OS.XmSHADOW_ETCHED_IN; + if ((style & (SWT.SHADOW_OUT)) != 0) return OS.XmSHADOW_ETCHED_OUT; + return OS.XmSHADOW_ETCHED_IN; +} +/** + * Controls how text and images will be displayed in the receiver. + * The argument should be one of <code>LEFT</code>, <code>RIGHT</code> + * or <code>CENTER</code>. If the receiver is a <code>SEPARATOR</code> + * label, the argument is ignored and the alignment is not changed. + * + * @param alignment the new alignment + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setAlignment (int alignment) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return;
- int [] argList = {OS.XmNalignment, OS.XmALIGNMENT_BEGINNING};
- if ((alignment & SWT.CENTER) != 0) argList [1] = OS.XmALIGNMENT_CENTER;
- if ((alignment & SWT.RIGHT) != 0) argList [1] = OS.XmALIGNMENT_END;
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- int [] argList = {OS.XmNlabelType, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] == OS.XmPIXMAP) setBitmap (image);
-}
-void setBitmap (Image image) {
- int labelPixmap = OS.XmUNSPECIFIED_PIXMAP;
- int labelInsensitivePixmap = OS.XmUNSPECIFIED_PIXMAP;
- if (bitmap != null) bitmap.dispose ();
- if (disabled != null) disabled.dispose ();
- bitmap = disabled = null;
- if (image != null) {
- if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- Display display = getDisplay ();
- switch (image.type) {
- case SWT.BITMAP:
- labelPixmap = image.pixmap;
- disabled = new Image (display, image, SWT.IMAGE_DISABLE);
- labelInsensitivePixmap = disabled.pixmap;
- break;
- case SWT.ICON:
- Rectangle rect = image.getBounds ();
- bitmap = new Image (display, rect.width, rect.height);
- GC gc = new GC (bitmap);
- gc.setBackground (getBackground ());
- gc.fillRectangle (rect);
- gc.drawImage (image, 0, 0);
- gc.dispose ();
- labelPixmap = bitmap.pixmap;
- disabled = new Image (display, bitmap, SWT.IMAGE_DISABLE);
- labelInsensitivePixmap = disabled.pixmap;
- break;
- default:
- error (SWT.ERROR_NOT_IMPLEMENTED);
- }
- }
- int [] argList = {
- OS.XmNlabelType, OS.XmPIXMAP,
- OS.XmNlabelPixmap, labelPixmap,
- OS.XmNlabelInsensitivePixmap, labelInsensitivePixmap,
- };
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- boolean changed = super.setBounds (x, y, width, height, move, resize);
- if (changed && resize && (style & SWT.WRAP) != 0) setText (text);
- return changed;
-}
-public void setFont (Font font) {
- super.setFont (font);
- if ((style & SWT.WRAP) != 0) setText (text);
-}
-/**
- * Sets the receiver's image to the argument, which may be
- * null indicating that no image should be displayed.
- *
- * @param image the image to display on the receiver (may be null)
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void setAlignment (int alignment) { + checkWidget(); + if ((style & SWT.SEPARATOR) != 0) return; + int [] argList = {OS.XmNalignment, OS.XmALIGNMENT_BEGINNING}; + if ((alignment & SWT.CENTER) != 0) argList [1] = OS.XmALIGNMENT_CENTER; + if ((alignment & SWT.RIGHT) != 0) argList [1] = OS.XmALIGNMENT_END; + OS.XtSetValues (handle, argList, argList.length / 2); +} +void setBackgroundPixel (int pixel) { + super.setBackgroundPixel (pixel); + int [] argList = {OS.XmNlabelType, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (argList [1] == OS.XmPIXMAP) setBitmap (image); +} +void setBitmap (Image image) { + int labelPixmap = OS.XmUNSPECIFIED_PIXMAP; + int labelInsensitivePixmap = OS.XmUNSPECIFIED_PIXMAP; + if (bitmap != null) bitmap.dispose (); + if (disabled != null) disabled.dispose (); + bitmap = disabled = null; + if (image != null) { + if (image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); + Display display = getDisplay (); + switch (image.type) { + case SWT.BITMAP: + labelPixmap = image.pixmap; + disabled = new Image (display, image, SWT.IMAGE_DISABLE); + labelInsensitivePixmap = disabled.pixmap; + break; + case SWT.ICON: + Rectangle rect = image.getBounds (); + bitmap = new Image (display, rect.width, rect.height); + GC gc = new GC (bitmap); + gc.setBackground (getBackground ()); + gc.fillRectangle (rect); + gc.drawImage (image, 0, 0); + gc.dispose (); + labelPixmap = bitmap.pixmap; + disabled = new Image (display, bitmap, SWT.IMAGE_DISABLE); + labelInsensitivePixmap = disabled.pixmap; + break; + default: + error (SWT.ERROR_NOT_IMPLEMENTED); + } + } + int [] argList = { + OS.XmNlabelType, OS.XmPIXMAP, + OS.XmNlabelPixmap, labelPixmap, + OS.XmNlabelInsensitivePixmap, labelInsensitivePixmap, + }; + OS.XtSetValues (handle, argList, argList.length / 2); +} +boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { + boolean changed = super.setBounds (x, y, width, height, move, resize); + if (changed && resize && (style & SWT.WRAP) != 0) setText (text); + return changed; +} +public void setFont (Font font) { + super.setFont (font); + if ((style & SWT.WRAP) != 0) setText (text); +} +/** + * Sets the receiver's image to the argument, which may be + * null indicating that no image should be displayed. + * + * @param image the image to display on the receiver (may be null) + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setImage (Image image) {
- checkWidget();
- if ((style & SWT.SEPARATOR) != 0) return;
- setBitmap (this.image = image);
-}
-/**
- * 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 setImage (Image image) { + checkWidget(); + if ((style & SWT.SEPARATOR) != 0) return; + setBitmap (this.image = image); +} +/** + * 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;
-
- /* Strip out mnemonic marker symbols, and remember the mnemonic. */
- char [] unicode = new char [string.length ()];
- string.getChars (0, unicode.length, unicode, 0);
- int i=0, j=0, mnemonic=0;
- while (i < unicode.length) {
- if ((unicode [j++] = unicode [i++]) == Mnemonic) {
- if (i == unicode.length) {continue;}
- if (unicode [i] == Mnemonic) {i++; continue;}
- if (mnemonic == 0) mnemonic = unicode [i];
- j--;
- }
- }
- while (j < unicode.length) unicode [j++] = 0;
-
- /* Wrap the text if necessary, and convert to mbcs. */
- byte [] buffer;
- if ((style & SWT.WRAP) != 0) {
- int [] argList = {
- OS.XmNwidth, 0, /* 1 */
- OS.XmNmarginLeft, 0, /* 3 */
- OS.XmNmarginRight, 0, /* 5 */
- OS.XmNborderWidth, 0, /* 7 */
- OS.XmNmarginWidth, 0, /* 9 */
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int width = argList [1] - argList [3] - argList [5] - argList [7] * 2 - argList [9] * 2;
- Display display = getDisplay ();
- if (mnemonic != 0) string = new String (unicode);
- string = display.wrapText (string, font, width);
- buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- } else {
- buffer = Converter.wcsToMbcs (getCodePage (), unicode, true);
- }
-
- int xmString = OS.XmStringGenerate(buffer, null, OS.XmCHARSET_TEXT, null);
- if (xmString == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
-
- /*
- * Bug in Solaris. If a mnemonic is defined to be a character
- * that appears in a string in a position that follows a '\n',
- * Solaris segment faults. For example, a label with text
- * "Hello\nthe&re" would GP since "r" appears after '\n'.
- *
- * The fix is to remove mnemonics from labels that contain
- * '\n', which is fine since such labels generally just act
- * as descriptive texts anyways.
- */
- if (mnemonic == 0 || string.indexOf ('\n') != -1) {
- mnemonic = OS.XK_VoidSymbol;
- }
- int [] argList = {
- OS.XmNlabelType, OS.XmSTRING,
- OS.XmNlabelString, xmString,
- OS.XmNmnemonic, mnemonic,
- };
- OS.XtSetValues (handle, argList, argList.length / 2);
- if (xmString != 0) OS.XmStringFree (xmString);
-}
-int xFocusOut () {
- int result = super.xFocusOut ();
- if (handle == 0) return result;
- int [] argList = new int [] {OS.XmNtraversalOn, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] != 0) {
- argList [1] = 0;
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
- return result;
-}
-}
+public void setText (String string) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + if ((style & SWT.SEPARATOR) != 0) return; + text = string; + + /* Strip out mnemonic marker symbols, and remember the mnemonic. */ + char [] unicode = new char [string.length ()]; + string.getChars (0, unicode.length, unicode, 0); + int i=0, j=0, mnemonic=0; + while (i < unicode.length) { + if ((unicode [j++] = unicode [i++]) == Mnemonic) { + if (i == unicode.length) {continue;} + if (unicode [i] == Mnemonic) {i++; continue;} + if (mnemonic == 0) mnemonic = unicode [i]; + j--; + } + } + while (j < unicode.length) unicode [j++] = 0; + + /* Wrap the text if necessary, and convert to mbcs. */ + byte [] buffer; + if ((style & SWT.WRAP) != 0) { + int [] argList = { + OS.XmNwidth, 0, /* 1 */ + OS.XmNmarginLeft, 0, /* 3 */ + OS.XmNmarginRight, 0, /* 5 */ + OS.XmNborderWidth, 0, /* 7 */ + OS.XmNmarginWidth, 0, /* 9 */ + }; + OS.XtGetValues (handle, argList, argList.length / 2); + int width = argList [1] - argList [3] - argList [5] - argList [7] * 2 - argList [9] * 2; + Display display = getDisplay (); + if (mnemonic != 0) string = new String (unicode); + string = display.wrapText (string, font, width); + buffer = Converter.wcsToMbcs (getCodePage (), string, true); + } else { + buffer = Converter.wcsToMbcs (getCodePage (), unicode, true); + } + + int xmString = OS.XmStringGenerate(buffer, null, OS.XmCHARSET_TEXT, null); + if (xmString == 0) error (SWT.ERROR_CANNOT_SET_TEXT); + + /* + * Bug in Solaris. If a mnemonic is defined to be a character + * that appears in a string in a position that follows a '\n', + * Solaris segment faults. For example, a label with text + * "Hello\nthe&re" would GP since "r" appears after '\n'. + * + * The fix is to remove mnemonics from labels that contain + * '\n', which is fine since such labels generally just act + * as descriptive texts anyways. + */ + if (mnemonic == 0 || string.indexOf ('\n') != -1) { + mnemonic = OS.XK_VoidSymbol; + } + int [] argList = { + OS.XmNlabelType, OS.XmSTRING, + OS.XmNlabelString, xmString, + OS.XmNmnemonic, mnemonic, + }; + OS.XtSetValues (handle, argList, argList.length / 2); + if (xmString != 0) OS.XmStringFree (xmString); +} +int xFocusOut () { + int result = super.xFocusOut (); + if (handle == 0) return result; + int [] argList = new int [] {OS.XmNtraversalOn, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (argList [1] != 0) { + argList [1] = 0; + OS.XtSetValues (handle, argList, argList.length / 2); + } + return result; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java index 628edf905a..c7a8f56b54 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/List.java @@ -1,37 +1,37 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-
-/**
- * Instances of this class represent a selectable user interface
- * object that displays a list of strings and issues 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>
- * Note: Only one of SINGLE and MULTI may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html */ -public class List extends Scrollable {
+ +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.events.*; + + +/** + * Instances of this class represent a selectable user interface + * object that displays a list of strings and issues 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> + * Note: Only one of SINGLE and MULTI may be specified. + * </p><p> + * IMPORTANT: This class is <em>not</em> intended to be subclassed. + * </p> + */ +public class List extends Scrollable { /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -61,1296 +61,1296 @@ public class List extends Scrollable { * @see Widget#checkSubclass * @see Widget#getStyle */ -public List (Composite parent, int style) {
- /*
- * Feature in Motif. It is not possible to create
- * scrolled list that will never show the vertical
- * scroll bar. Therefore, not matter what style
- * bits are specified, set the V_SCROLL bits to
- * match the widget Motif creates.
+public List (Composite parent, int style) { + /* + * Feature in Motif. It is not possible to create + * scrolled list that will never show the vertical + * scroll bar. Therefore, not matter what style + * bits are specified, set the V_SCROLL bits to + * match the widget Motif creates. */ - super (parent, checkStyle (style | SWT.V_SCROLL));
-}
-/**
- * Adds the argument to the end of the receiver's list.
- *
- * @param string the new item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_ADDED - if the operation fails because of an operating system failure</li>
- * </ul>
- *
- * @see #add(String,int)
+ super (parent, checkStyle (style | SWT.V_SCROLL)); +} +/** + * Adds the argument to the end of the receiver's list. + * + * @param string the new item + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the string is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @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 (getCodePage (), string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- OS.XmListAddItemUnselected (handle, xmString, 0);
- OS.XmStringFree (xmString);
-}
-/**
- * Adds the argument to the receiver's list at the given
- * zero-relative index.
- * <p>
- * Note: To add an item at the end of the list, use the
- * result of calling <code>getItemCount()</code> as the
- * index or use <code>add(String)</code>.
- * </p>
- *
- * @param string the new item
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @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) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); + int xmString = OS.XmStringCreateLocalized (buffer); + if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED); + OS.XmListAddItemUnselected (handle, xmString, 0); + OS.XmStringFree (xmString); +} +/** + * Adds the argument to the receiver's list at the given + * zero-relative index. + * <p> + * Note: To add an item at the end of the list, use the + * result of calling <code>getItemCount()</code> as the + * index or use <code>add(String)</code>. + * </p> + * + * @param string the new item + * @param index the index for the item + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the string is null</li> + * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list (inclusive)</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @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_INVALID_RANGE);
- /*
- * Feature in Motif. When an index is out of range,
- * the list widget adds the item at the end. This
- * behavior is not wrong but it is unwanted. The
- * fix is to check the range before adding the item.
- */
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= index && index <= argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- OS.XmListAddItemUnselected (handle, xmString, index + 1);
- OS.XmStringFree (xmString);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the 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 add (String string, int index) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + if (index == -1) error (SWT.ERROR_INVALID_RANGE); + /* + * Feature in Motif. When an index is out of range, + * the list widget adds the item at the end. This + * behavior is not wrong but it is unwanted. The + * fix is to check the range before adding the item. + */ + int [] argList = {OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (!(0 <= index && index <= argList [1])) { + error (SWT.ERROR_INVALID_RANGE); + } + byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); + int xmString = OS.XmStringCreateLocalized (buffer); + if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED); + OS.XmListAddItemUnselected (handle, xmString, index + 1); + OS.XmStringFree (xmString); +} +/** + * Adds the listener to the collection of listeners who will + * be notified when the 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);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- XtWidgetGeometry result = new XtWidgetGeometry ();
- result.request_mode = OS.CWWidth;
- OS.XtQueryGeometry (handle, null, result);
- int width = result.width, height = 0;
- if (wHint != SWT.DEFAULT) width = wHint;
- if (hHint != SWT.DEFAULT) height = hHint;
- if (hHint == SWT.DEFAULT || wHint == SWT.DEFAULT) {
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int count = argList [1];
- if (hHint == SWT.DEFAULT) {
- if (count == 0) {
- height = DEFAULT_HEIGHT;
- } else {
- height = getItemHeight () * count;
- }
- }
- if (wHint == SWT.DEFAULT && count == 0) {
- width = DEFAULT_WIDTH;
- }
- }
- Rectangle rect = computeTrim (0, 0, width, height);
- return new Point (rect.width, rect.height);
-}
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- Display display = getDisplay ();
- int border = getBorderWidth ();
- int trimX = x - border;
- int trimY = y - border;
- int trimWidth = width + (border * 2);
- int trimHeight = height + (border * 2);
- if (horizontalBar != null) {
- int [] argList = {OS.XmNheight, 0};
- OS.XtGetValues (horizontalBar.handle, argList, argList.length / 2);
- /*
- * Motif adds four pixels between the bottom of the
- * list and the horizontal scroll bar. Add those now.
+public void addSelectionListener(SelectionListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener(listener); + addListener(SWT.Selection,typedListener); + addListener(SWT.DefaultSelection,typedListener); +} +static int checkStyle (int style) { + return checkBits (style, SWT.SINGLE, SWT.MULTI, 0, 0, 0, 0); +} +public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget(); + XtWidgetGeometry result = new XtWidgetGeometry (); + result.request_mode = OS.CWWidth; + OS.XtQueryGeometry (handle, null, result); + int width = result.width, height = 0; + if (wHint != SWT.DEFAULT) width = wHint; + if (hHint != SWT.DEFAULT) height = hHint; + if (hHint == SWT.DEFAULT || wHint == SWT.DEFAULT) { + int [] argList = {OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int count = argList [1]; + if (hHint == SWT.DEFAULT) { + if (count == 0) { + height = DEFAULT_HEIGHT; + } else { + height = getItemHeight () * count; + } + } + if (wHint == SWT.DEFAULT && count == 0) { + width = DEFAULT_WIDTH; + } + } + Rectangle rect = computeTrim (0, 0, width, height); + return new Point (rect.width, rect.height); +} +public Rectangle computeTrim (int x, int y, int width, int height) { + checkWidget(); + Display display = getDisplay (); + int border = getBorderWidth (); + int trimX = x - border; + int trimY = y - border; + int trimWidth = width + (border * 2); + int trimHeight = height + (border * 2); + if (horizontalBar != null) { + int [] argList = {OS.XmNheight, 0}; + OS.XtGetValues (horizontalBar.handle, argList, argList.length / 2); + /* + * Motif adds four pixels between the bottom of the + * list and the horizontal scroll bar. Add those now. */ - trimHeight += argList [1] + 4;
- trimY -= display.scrolledInsetY;
- if (verticalBar != null) {
- trimX -= display.scrolledInsetX;
- }
- }
- if (verticalBar != null) {
- int [] argList = {OS.XmNwidth, 0};
- OS.XtGetValues (verticalBar.handle, argList, argList.length / 2);
- trimWidth += argList [1];
- trimX -= display.scrolledInsetX;
- if (horizontalBar != null) {
- trimY -= display.scrolledInsetY;
- }
- }
- int [] argList = {
- OS.XmNhighlightThickness, 0, /* 1 */
- OS.XmNshadowThickness, 0, /* 3 */
- OS.XmNlistMarginWidth, 0, /* 5 */
- OS.XmNlistMarginHeight, 0 /* 7 */
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int thickness = argList [1] + (argList [3] * 2);
- trimWidth += thickness + argList [5] + 1;
- trimHeight += thickness + argList [7] + 1;
- trimX -= argList [1] + argList [3] + argList [5];
- trimY -= argList [1] + argList [3] + argList [7];
- return new Rectangle (trimX, trimY, trimWidth, trimHeight);
-}
-void createHandle (int index) {
- state |= HANDLE;
-
- /*
- * Feature in Motif. When items are added or removed
- * from a list, it may request and be granted, a new
- * preferred size. This behavior is unwanted. The fix
- * is to create a parent for the list that will disallow
- * geometry requests.
- */
- int parentHandle = parent.handle;
- int [] argList1 = {OS.XmNancestorSensitive, 1};
- formHandle = OS.XmCreateForm (parentHandle, null, argList1, argList1.length / 2);
- if (formHandle == 0) error (SWT.ERROR_NO_HANDLES);
- int selectionPolicy = OS.XmBROWSE_SELECT, listSizePolicy = OS.XmCONSTANT;
- if ((style & SWT.MULTI) != 0) {
- selectionPolicy = OS.XmEXTENDED_SELECT;
- if ((style & SWT.SIMPLE) != 0) selectionPolicy = OS.XmMULTIPLE_SELECT;
- }
- if ((style & SWT.H_SCROLL) == 0) listSizePolicy = OS.XmVARIABLE;
- int [] argList2 = {
- OS.XmNlistSizePolicy, listSizePolicy,
- OS.XmNselectionPolicy, selectionPolicy,
- OS.XmNtopAttachment, OS.XmATTACH_FORM,
- OS.XmNbottomAttachment, OS.XmATTACH_FORM,
- OS.XmNleftAttachment, OS.XmATTACH_FORM,
- OS.XmNrightAttachment, OS.XmATTACH_FORM,
- OS.XmNresizable, 0,
-// OS.XmNmatchBehavior, OS.XmNONE,
- };
- if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) {
- handle = OS.XmCreateList (formHandle, null, argList2, argList2.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- } else {
- handle = OS.XmCreateScrolledList (formHandle, new byte [0], argList2, argList2.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- scrolledHandle = OS.XtParent (handle);
- }
-}
-ScrollBar createScrollBar (int type) {
- return createStandardBar (type);
-}
-int defaultBackground () {
- return getDisplay ().listBackground;
-}
-Font defaultFont () {
- return getDisplay ().listFont;
-}
-int defaultForeground () {
- return getDisplay ().listForeground;
-}
-/**
- * Deselects the item at the given zero-relative index in the receiver.
- * If the item at the index was already deselected, it remains
- * deselected. Indices that are out of range are ignored.
- *
- * @param index the index of the item to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+ trimHeight += argList [1] + 4; + trimY -= display.scrolledInsetY; + if (verticalBar != null) { + trimX -= display.scrolledInsetX; + } + } + if (verticalBar != null) { + int [] argList = {OS.XmNwidth, 0}; + OS.XtGetValues (verticalBar.handle, argList, argList.length / 2); + trimWidth += argList [1]; + trimX -= display.scrolledInsetX; + if (horizontalBar != null) { + trimY -= display.scrolledInsetY; + } + } + int [] argList = { + OS.XmNhighlightThickness, 0, /* 1 */ + OS.XmNshadowThickness, 0, /* 3 */ + OS.XmNlistMarginWidth, 0, /* 5 */ + OS.XmNlistMarginHeight, 0 /* 7 */ + }; + OS.XtGetValues (handle, argList, argList.length / 2); + int thickness = argList [1] + (argList [3] * 2); + trimWidth += thickness + argList [5] + 1; + trimHeight += thickness + argList [7] + 1; + trimX -= argList [1] + argList [3] + argList [5]; + trimY -= argList [1] + argList [3] + argList [7]; + return new Rectangle (trimX, trimY, trimWidth, trimHeight); +} +void createHandle (int index) { + state |= HANDLE; + + /* + * Feature in Motif. When items are added or removed + * from a list, it may request and be granted, a new + * preferred size. This behavior is unwanted. The fix + * is to create a parent for the list that will disallow + * geometry requests. + */ + int parentHandle = parent.handle; + int [] argList1 = {OS.XmNancestorSensitive, 1}; + formHandle = OS.XmCreateForm (parentHandle, null, argList1, argList1.length / 2); + if (formHandle == 0) error (SWT.ERROR_NO_HANDLES); + int selectionPolicy = OS.XmBROWSE_SELECT, listSizePolicy = OS.XmCONSTANT; + if ((style & SWT.MULTI) != 0) { + selectionPolicy = OS.XmEXTENDED_SELECT; + if ((style & SWT.SIMPLE) != 0) selectionPolicy = OS.XmMULTIPLE_SELECT; + } + if ((style & SWT.H_SCROLL) == 0) listSizePolicy = OS.XmVARIABLE; + int [] argList2 = { + OS.XmNlistSizePolicy, listSizePolicy, + OS.XmNselectionPolicy, selectionPolicy, + OS.XmNtopAttachment, OS.XmATTACH_FORM, + OS.XmNbottomAttachment, OS.XmATTACH_FORM, + OS.XmNleftAttachment, OS.XmATTACH_FORM, + OS.XmNrightAttachment, OS.XmATTACH_FORM, + OS.XmNresizable, 0, +// OS.XmNmatchBehavior, OS.XmNONE, + }; + if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) == 0) { + handle = OS.XmCreateList (formHandle, null, argList2, argList2.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + } else { + handle = OS.XmCreateScrolledList (formHandle, new byte [0], argList2, argList2.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + scrolledHandle = OS.XtParent (handle); + } +} +ScrollBar createScrollBar (int type) { + return createStandardBar (type); +} +int defaultBackground () { + return getDisplay ().listBackground; +} +Font defaultFont () { + return getDisplay ().listFont; +} +int defaultForeground () { + return getDisplay ().listForeground; +} +/** + * Deselects the item at the given zero-relative index in the receiver. + * If the item at the index was already deselected, it remains + * deselected. Indices that are out of range are ignored. + * + * @param index the index of the item to deselect + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void deselect (int index) {
- checkWidget();
- /*
- * Note: We rely on the fact that XmListDeselectPos ()
- * fails silently when the indices are out of range.
- */
- if (index != -1) OS.XmListDeselectPos (handle, index + 1);
-}
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. The range of the
- * indices is inclusive. Indices that are out of range are ignored.
- *
- * @param start the start index of the items to deselect
- * @param end the end index of the items to deselect
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void deselect (int index) { + checkWidget(); + /* + * Note: We rely on the fact that XmListDeselectPos () + * fails silently when the indices are out of range. + */ + if (index != -1) OS.XmListDeselectPos (handle, index + 1); +} +/** + * Deselects the items at the given zero-relative indices in the receiver. + * If the item at the given zero-relative index in the receiver + * is selected, it is deselected. If the item at the index + * was not selected, it remains deselected. The range of the + * indices is inclusive. Indices that are out of range are ignored. + * + * @param start the start index of the items to deselect + * @param end the end index of the items to deselect + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void deselect (int start, int end) {
- checkWidget();
- if (start > end) return;
- /*
- * Note: We rely on the fact that XmListDeselectPos ()
- * fails silently when the indices are out of range.
- */
- for (int i=start; i<=end; i++) {
- int index = i + 1;
- if (index != 0) OS.XmListDeselectPos (handle, index);
- }
-}
-/**
- * Deselects the items at the given zero-relative indices in the receiver.
- * If the item at the given zero-relative index in the receiver
- * is selected, it is deselected. If the item at the index
- * was not selected, it remains deselected. Indices that are out
- * of range and duplicate indices are ignored.
- *
- * @param indices the array of indices for the items to deselect
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void deselect (int start, int end) { + checkWidget(); + if (start > end) return; + /* + * Note: We rely on the fact that XmListDeselectPos () + * fails silently when the indices are out of range. + */ + for (int i=start; i<=end; i++) { + int index = i + 1; + if (index != 0) OS.XmListDeselectPos (handle, index); + } +} +/** + * Deselects the items at the given zero-relative indices in the receiver. + * If the item at the given zero-relative index in the receiver + * is selected, it is deselected. If the item at the index + * was not selected, it remains deselected. Indices that are out + * of range and duplicate indices are ignored. + * + * @param indices the array of indices for the items to deselect + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void deselect (int [] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- /*
- * Note: We rely on the fact that XmListDeselectPos ()
- * fails silently when the indices are out of range.
- */
- for (int i=0; i<indices.length; i++) {
- int index = indices [i] + 1;
- if (index != 0) OS.XmListDeselectPos (handle, index);
- }
-}
-/**
- * Deselects all selected items in the receiver.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void deselect (int [] indices) { + checkWidget(); + if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); + /* + * Note: We rely on the fact that XmListDeselectPos () + * fails silently when the indices are out of range. + */ + for (int i=0; i<indices.length; i++) { + int index = indices [i] + 1; + if (index != 0) OS.XmListDeselectPos (handle, index); + } +} +/** + * Deselects all selected items in the receiver. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void deselectAll () {
- checkWidget();
- OS.XmListDeselectAllItems (handle);
-}
-/**
- * Returns the zero-relative index of the item which 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 void deselectAll () { + checkWidget(); + OS.XmListDeselectAllItems (handle); +} +/** + * 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();
- return OS.XmListGetKbdItemPos (handle) - 1;
-}
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_ITEM - if the operation fails because of an operating system failure</li>
- * </ul>
+public int getFocusIndex () { + checkWidget(); + return OS.XmListGetKbdItemPos (handle) - 1; +} +/** + * Returns the item at the given, zero-relative index in the + * receiver. Throws an exception if the index is out of range. + * + * @param index the index of the item to return + * @return the item at the given index + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @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 [] argList = {OS.XmNitemCount, 0, OS.XmNitems, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= index && index < argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- if (argList [3] == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- int ptr = argList [3] + (index * 4);
- int [] buffer1 = new int [1];
- OS.memmove (buffer1, ptr, 4);
- ptr = buffer1 [0];
- int address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- OS.XmOUTPUT_ALL);
- if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- OS.XtFree (address);
- return new String (Converter.mbcsToWcs (getCodePage (), buffer));
-}
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li>
- * </ul>
+public String getItem (int index) { + checkWidget(); + int [] argList = {OS.XmNitemCount, 0, OS.XmNitems, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (!(0 <= index && index < argList [1])) { + error (SWT.ERROR_INVALID_RANGE); + } + if (argList [3] == 0) error (SWT.ERROR_CANNOT_GET_ITEM); + int ptr = argList [3] + (index * 4); + int [] buffer1 = new int [1]; + OS.memmove (buffer1, ptr, 4); + ptr = buffer1 [0]; + int address = OS.XmStringUnparse ( + ptr, + null, + OS.XmCHARSET_TEXT, + OS.XmCHARSET_TEXT, + null, + 0, + OS.XmOUTPUT_ALL); + if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM); + int length = OS.strlen (address); + byte [] buffer = new byte [length]; + OS.memmove (buffer, address, length); + OS.XtFree (address); + return new String (Converter.mbcsToWcs (getCodePage (), buffer)); +} +/** + * Returns the number of items contained in the receiver. + * + * @return the number of items + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @exception SWTError <ul> + * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li> + * </ul> */ -public int getItemCount () {
- checkWidget();
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the height of the area which would be used to
- * display <em>one</em> of the items in the 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 getItemCount () { + checkWidget(); + int [] argList = {OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns the height of the area which would be used to + * display <em>one</em> of the items in the 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();
- int [] argList = {
- OS.XmNlistSpacing, 0,
- OS.XmNhighlightThickness, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int spacing = argList [1], highlight = argList [3];
-
- /* Result is from empirical analysis on Linux and AIX */
- return getFontHeight () + spacing + highlight + 1;
-}
-/**
- * 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 int getItemHeight () { + checkWidget(); + int [] argList = { + OS.XmNlistSpacing, 0, + OS.XmNhighlightThickness, 0, + }; + OS.XtGetValues (handle, argList, argList.length / 2); + int spacing = argList [1], highlight = argList [3]; + + /* Result is from empirical analysis on Linux and AIX */ + return getFontHeight () + spacing + highlight + 1; +} +/** + * 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 [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int items = argList [1], itemCount = argList [3];
- int [] buffer1 = new int [1];
- String [] result = new String [itemCount];
- String codePage = getCodePage ();
- for (int i=0; i<itemCount; i++) {
- OS.memmove (buffer1, items, 4);
- int ptr = buffer1 [0];
- int address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- OS.XmOUTPUT_ALL);
- if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- OS.XtFree (address);
- result[i] = new String (Converter.mbcsToWcs (codePage, buffer));
- items += 4;
- }
- return result;
-}
-/**
- * Returns an array of <code>String</code>s that are currently
- * selected in the receiver. 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 [] getItems () { + checkWidget(); + int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int items = argList [1], itemCount = argList [3]; + int [] buffer1 = new int [1]; + String [] result = new String [itemCount]; + String codePage = getCodePage (); + for (int i=0; i<itemCount; i++) { + OS.memmove (buffer1, items, 4); + int ptr = buffer1 [0]; + int address = OS.XmStringUnparse ( + ptr, + null, + OS.XmCHARSET_TEXT, + OS.XmCHARSET_TEXT, + null, + 0, + OS.XmOUTPUT_ALL); + if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM); + int length = OS.strlen (address); + byte [] buffer = new byte [length]; + OS.memmove (buffer, address, length); + OS.XtFree (address); + result[i] = new String (Converter.mbcsToWcs (codePage, buffer)); + items += 4; + } + return result; +} +/** + * Returns an array of <code>String</code>s that are currently + * selected in the receiver. 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();
- int [] argList = {OS.XmNselectedItems, 0, OS.XmNselectedItemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int items = argList [1], itemCount = argList [3];
- int [] buffer1 = new int [1];
- String [] result = new String [itemCount];
- String codePage = getCodePage ();
- for (int i=0; i<itemCount; i++) {
- OS.memmove (buffer1, items, 4);
- int ptr = buffer1 [0];
- int address = OS.XmStringUnparse (
- ptr,
- null,
- OS.XmCHARSET_TEXT,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- OS.XmOUTPUT_ALL);
- if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- int length = OS.strlen (address);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, address, length);
- OS.XtFree (address);
- result[i] = new String (Converter.mbcsToWcs (codePage, buffer));
- items += 4;
- }
- return result;
-}
-/**
- * Returns the number of selected items contained in the receiver.
- *
- * @return the number of selected items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li>
- * </ul>
+public String [] getSelection () { + checkWidget(); + int [] argList = {OS.XmNselectedItems, 0, OS.XmNselectedItemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int items = argList [1], itemCount = argList [3]; + int [] buffer1 = new int [1]; + String [] result = new String [itemCount]; + String codePage = getCodePage (); + for (int i=0; i<itemCount; i++) { + OS.memmove (buffer1, items, 4); + int ptr = buffer1 [0]; + int address = OS.XmStringUnparse ( + ptr, + null, + OS.XmCHARSET_TEXT, + OS.XmCHARSET_TEXT, + null, + 0, + OS.XmOUTPUT_ALL); + if (address == 0) error (SWT.ERROR_CANNOT_GET_ITEM); + int length = OS.strlen (address); + byte [] buffer = new byte [length]; + OS.memmove (buffer, address, length); + OS.XtFree (address); + result[i] = new String (Converter.mbcsToWcs (codePage, buffer)); + items += 4; + } + return result; +} +/** + * Returns the number of selected items contained in the receiver. + * + * @return the number of selected items + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @exception SWTError <ul> + * <li>ERROR_CANNOT_GET_COUNT - if the operation fails because of an operating system failure</li> + * </ul> */ -public int getSelectionCount () {
- checkWidget();
- int [] argList = {OS.XmNselectedItemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the zero-relative index of the item which is currently
- * selected in the receiver, or -1 if no item is selected.
- *
- * @return the index of the selected item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 getSelectionCount () { + checkWidget(); + int [] argList = {OS.XmNselectedItemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns the zero-relative index of the item which is currently + * selected in the receiver, or -1 if no item is selected. + * + * @return the index of the selected item + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - 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();
- int index = OS.XmListGetKbdItemPos (handle);
- if (OS.XmListPosSelected (handle, index)) return index - 1;
- int [] count = new int [1], positions = new int [1];
- if (!OS.XmListGetSelectedPos (handle, positions, count)) return -1;
- if (count [0] == 0) return -1;
- int address = positions [0];
- int [] indices = new int [1];
- OS.memmove (indices, address, 4);
- OS.XtFree (address);
- return indices [0] - 1;
-}
-/**
- * Returns the zero-relative indices of the items which are currently
- * selected in the receiver. The 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 getSelectionIndex () { + checkWidget(); + int index = OS.XmListGetKbdItemPos (handle); + if (OS.XmListPosSelected (handle, index)) return index - 1; + int [] count = new int [1], positions = new int [1]; + if (!OS.XmListGetSelectedPos (handle, positions, count)) return -1; + if (count [0] == 0) return -1; + int address = positions [0]; + int [] indices = new int [1]; + OS.memmove (indices, address, 4); + OS.XtFree (address); + return indices [0] - 1; +} +/** + * Returns the zero-relative indices of the items which are currently + * selected in the receiver. The 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();
- int [] count = new int [1], positions = new int [1];
- OS.XmListGetSelectedPos (handle, positions, count);
- int [] result = new int [count [0]];
- OS.memmove (result, positions [0], count [0] * 4);
- if (positions [0] != 0) OS.XtFree (positions [0]);
- for (int i=0; i<result.length; i++) --result [i];
- return result;
-}
-/**
- * Returns the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items are
- * scrolled or new items are added or removed.
- *
- * @return the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int [] getSelectionIndices () { + checkWidget(); + int [] count = new int [1], positions = new int [1]; + OS.XmListGetSelectedPos (handle, positions, count); + int [] result = new int [count [0]]; + OS.memmove (result, positions [0], count [0] * 4); + if (positions [0] != 0) OS.XtFree (positions [0]); + for (int i=0; i<result.length; i++) --result [i]; + return result; +} +/** + * Returns the zero-relative index of the item which is currently + * at the top of the receiver. This index can change when items are + * scrolled or new items are added or removed. + * + * @return the index of the top item + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getTopIndex () {
- checkWidget();
- int [] argList = {OS.XmNtopItemPosition, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] - 1;
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = getDisplay ().windowProc;
- OS.XtAddCallback (handle, OS.XmNbrowseSelectionCallback, windowProc, BROWSE_SELECTION_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNextendedSelectionCallback, windowProc, EXTENDED_SELECTION_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNdefaultActionCallback, windowProc, DEFAULT_ACTION_CALLBACK);
-}
-/**
- * Gets the index of an item.
- * <p>
- * The list is searched starting at 0 until an
- * item is found that is equal to the search item.
- * If no item is found, -1 is returned. Indexing
- * is zero based.
- *
- * @param string the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the string is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getTopIndex () { + checkWidget(); + int [] argList = {OS.XmNtopItemPosition, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1] - 1; +} +void hookEvents () { + super.hookEvents (); + int windowProc = getDisplay ().windowProc; + OS.XtAddCallback (handle, OS.XmNbrowseSelectionCallback, windowProc, BROWSE_SELECTION_CALLBACK); + OS.XtAddCallback (handle, OS.XmNextendedSelectionCallback, windowProc, EXTENDED_SELECTION_CALLBACK); + OS.XtAddCallback (handle, OS.XmNdefaultActionCallback, windowProc, DEFAULT_ACTION_CALLBACK); +} +/** + * Gets the index of an item. + * <p> + * The list is searched starting at 0 until an + * item is found that is equal to the search item. + * If no item is found, -1 is returned. Indexing + * is zero based. + * + * @param string the search item + * @return the index of the item + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the string is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int indexOf (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) return -1;
- int index = OS.XmListItemPos (handle, xmString);
- OS.XmStringFree (xmString);
- return index - 1;
-}
-/**
- * Searches the receiver's list starting at the given,
- * zero-relative index until an item is found that is equal
- * to the argument, and returns the index of that item. If
- * no item is found or the starting index is out of range,
- * returns -1.
- *
- * @param string the search item
- * @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) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); + int xmString = OS.XmStringCreateLocalized (buffer); + if (xmString == 0) return -1; + int index = OS.XmListItemPos (handle, xmString); + OS.XmStringFree (xmString); + return index - 1; +} +/** + * Searches the receiver's list starting at the given, + * zero-relative index until an item is found that is equal + * to the argument, and returns the index of that item. If + * no item is found or the starting index is out of range, + * returns -1. + * + * @param string the search item + * @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);
- int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int items = argList [1], itemCount = argList [3];
- if (!((0 <= start) && (start < itemCount))) return -1;
- byte [] buffer1 = Converter.wcsToMbcs (getCodePage (), string, true);
- int xmString = OS.XmStringCreateLocalized (buffer1);
- if (xmString == 0) return -1;
- int index = start;
- items += start * 4;
- int [] buffer2 = new int [1];
- while (index < itemCount) {
- OS.memmove (buffer2, items, 4);
- if (OS.XmStringCompare (buffer2 [0], xmString)) break;
- items += 4; index++;
- }
- OS.XmStringFree (xmString);
- if (index == itemCount) return -1;
- return index;
-}
-/**
- * Returns <code>true</code> if the item is selected,
- * and <code>false</code> otherwise. Indices out of
- * range are ignored.
- *
- * @param index the index of the item
- * @return the 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 int indexOf (String string, int start) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + int [] argList = {OS.XmNitems, 0, OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int items = argList [1], itemCount = argList [3]; + if (!((0 <= start) && (start < itemCount))) return -1; + byte [] buffer1 = Converter.wcsToMbcs (getCodePage (), string, true); + int xmString = OS.XmStringCreateLocalized (buffer1); + if (xmString == 0) return -1; + int index = start; + items += start * 4; + int [] buffer2 = new int [1]; + while (index < itemCount) { + OS.memmove (buffer2, items, 4); + if (OS.XmStringCompare (buffer2 [0], xmString)) break; + items += 4; index++; + } + OS.XmStringFree (xmString); + if (index == itemCount) return -1; + return index; +} +/** + * Returns <code>true</code> if the item is selected, + * and <code>false</code> otherwise. Indices out of + * range are ignored. + * + * @param index the index of the item + * @return the 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();
- if (index == -1) return false;
- return OS.XmListPosSelected (handle, index + 1);
-}
-void overrideTranslations () {
- Display display = getDisplay ();
- OS.XtOverrideTranslations (handle, display.tabTranslations);
-}
-/**
- * Removes the item from the receiver at the given
- * zero-relative index.
- *
- * @param index the index for the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @exception SWTError <ul>
- * <li>ERROR_ITEM_NOT_REMOVED - if the operation fails because of an operating system failure</li>
- * </ul>
+public boolean isSelected (int index) { + checkWidget(); + if (index == -1) return false; + return OS.XmListPosSelected (handle, index + 1); +} +void overrideTranslations () { + Display display = getDisplay (); + OS.XtOverrideTranslations (handle, display.tabTranslations); +} +/** + * Removes the item from the receiver at the given + * zero-relative index. + * + * @param index the index for the item + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @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 (index == -1) error (SWT.ERROR_INVALID_RANGE);
- /*
- * Feature in Motif. An index out of range handled
- * correctly by the list widget but causes an unwanted
- * Xm Warning. The fix is to check the range before
- * deleting an item.
- */
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= index && index < argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- OS.XmListDeletePos (handle, index + 1);
-}
-/**
- * Removes the items from the receiver which are
- * between the given zero-relative start and end
- * indices (inclusive).
- *
- * @param start the start of the range
- * @param end the end of the range
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- * @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 (index == -1) error (SWT.ERROR_INVALID_RANGE); + /* + * Feature in Motif. An index out of range handled + * correctly by the list widget but causes an unwanted + * Xm Warning. The fix is to check the range before + * deleting an item. + */ + int [] argList = {OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (!(0 <= index && index < argList [1])) { + error (SWT.ERROR_INVALID_RANGE); + } + OS.XmListDeletePos (handle, index + 1); +} +/** + * Removes the items from the receiver which are + * between the given zero-relative start and end + * indices (inclusive). + * + * @param start the start of the range + * @param end the end of the range + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_RANGE - if either the start or end are not between 0 and the number of elements in the list minus 1 (inclusive)</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * @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 (start > end) return;
- int count = end - start + 1;
- /*
- * Feature in Motif. An index out of range is handled
- * correctly by the list widget but causes an unwanted
- * Xm warning. The fix is to check the range before
- * deleting an item.
- */
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= start && start < argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- OS.XmListDeleteItemsPos (handle, count, start + 1);
- if (end >= argList [1]) error (SWT.ERROR_INVALID_RANGE);
-}
-/**
- * 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 (int start, int end) { + checkWidget(); + if (start > end) return; + int count = end - start + 1; + /* + * Feature in Motif. An index out of range is handled + * correctly by the list widget but causes an unwanted + * Xm warning. The fix is to check the range before + * deleting an item. + */ + int [] argList = {OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (!(0 <= start && start < argList [1])) { + error (SWT.ERROR_INVALID_RANGE); + } + OS.XmListDeleteItemsPos (handle, count, start + 1); + if (end >= argList [1]) error (SWT.ERROR_INVALID_RANGE); +} +/** + * 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();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) error (SWT.ERROR_ITEM_NOT_REMOVED);
- int index = OS.XmListItemPos (handle, xmString);
- OS.XmStringFree (xmString);
- if (index == 0) error (SWT.ERROR_INVALID_ARGUMENT);
- OS.XmListDeletePos (handle, index);
-}
-/**
- * Removes the items from the receiver at the given
- * zero-relative indices.
- *
- * @param indices the array of indices of the items
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); + int xmString = OS.XmStringCreateLocalized (buffer); + if (xmString == 0) error (SWT.ERROR_ITEM_NOT_REMOVED); + int index = OS.XmListItemPos (handle, xmString); + OS.XmStringFree (xmString); + if (index == 0) error (SWT.ERROR_INVALID_ARGUMENT); + OS.XmListDeletePos (handle, index); +} +/** + * Removes the items from the receiver at the given + * zero-relative indices. + * + * @param indices the array of indices of the items + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - 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);
- /*
- * Feature in Motif. An index out of range handled
- * correctly by the list widget but causes an unwanted
- * Xm Warning. The fix is to check the range before
- * deleting an item.
- */
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int length = 0, count = argList [1];
- int [] newIndices = new int [indices.length];
- for (int i=0; i<indices.length; i++) {
- int index = indices [i];
- if (!(0 <= index && index < count)) break;
- newIndices [length++] = index + 1;
- }
- OS.XmListDeletePositions (handle, newIndices, length);
- if (length < indices.length) error (SWT.ERROR_INVALID_RANGE);
-}
-/**
- * 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 remove (int [] indices) { + checkWidget(); + if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); + /* + * Feature in Motif. An index out of range handled + * correctly by the list widget but causes an unwanted + * Xm Warning. The fix is to check the range before + * deleting an item. + */ + int [] argList = {OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int length = 0, count = argList [1]; + int [] newIndices = new int [indices.length]; + for (int i=0; i<indices.length; i++) { + int index = indices [i]; + if (!(0 <= index && index < count)) break; + newIndices [length++] = index + 1; + } + OS.XmListDeletePositions (handle, newIndices, length); + if (length < indices.length) error (SWT.ERROR_INVALID_RANGE); +} +/** + * Removes all of the items from the receiver. + * <p> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void removeAll () {
- checkWidget();
- OS.XmListDeselectAllItems (handle);
- OS.XmListDeleteAllItems (handle);
- /*
- * Bug in AIX. When all list items are deleted
- * from a scrolled list that is currently showing a
- * horizontal scroll bar, the horizontal scroll bar
- * is hidden, but the list does not grow to take up
- * the space once occupied by the bar. The fix is
- * of force a resize of the list.
- */
- if ((style & SWT.H_SCROLL) != 0) OS.XtResizeWindow (handle);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the 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 removeAll () { + checkWidget(); + OS.XmListDeselectAllItems (handle); + OS.XmListDeleteAllItems (handle); + /* + * Bug in AIX. When all list items are deleted + * from a scrolled list that is currently showing a + * horizontal scroll bar, the horizontal scroll bar + * is hidden, but the list does not grow to take up + * the space once occupied by the bar. The fix is + * of force a resize of the list. + */ + if ((style & SWT.H_SCROLL) != 0) OS.XtResizeWindow (handle); +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the 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 removeSelectionListener(SelectionListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook(SWT.Selection, listener); + eventTable.unhook(SWT.DefaultSelection,listener); +} +/** + * Selects the item at the given zero-relative index in the receiver's + * list. If the item at the index was already selected, it remains + * selected. Indices that are out of range are ignored. + * + * @param index the index of the item to select + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void select (int index) {
- checkWidget();
- if (index == -1) return;
- if (OS.XmListPosSelected (handle, index + 1)) return;
- /*
- * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos ()
- * in a XmEXTENDED_SELECT list widget will add the index to the selected
- * indices. The observed behavior does not match the spec. The fix is
- * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT
- * and then switch it back because XmListSelectPost () works as specified
- * for XmMULTIPLE_SELECT list widgets.
- */
- int [] argList = {OS.XmNselectionPolicy, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int oldPolicy = argList [1];
- if (oldPolicy == OS.XmEXTENDED_SELECT) {
- argList [1] = OS.XmMULTIPLE_SELECT;
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
- /*
- * Note: We rely on the fact that XmListSelectPos ()
- * fails silently when the indices are out of range.
- */
- OS.XmListSelectPos (handle, index + 1, false);
- if (oldPolicy == OS.XmEXTENDED_SELECT) {
- argList [1] = OS.XmEXTENDED_SELECT;
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
-}
-/**
- * Selects the items 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 index) { + checkWidget(); + if (index == -1) return; + if (OS.XmListPosSelected (handle, index + 1)) return; + /* + * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos () + * in a XmEXTENDED_SELECT list widget will add the index to the selected + * indices. The observed behavior does not match the spec. The fix is + * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT + * and then switch it back because XmListSelectPost () works as specified + * for XmMULTIPLE_SELECT list widgets. + */ + int [] argList = {OS.XmNselectionPolicy, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int oldPolicy = argList [1]; + if (oldPolicy == OS.XmEXTENDED_SELECT) { + argList [1] = OS.XmMULTIPLE_SELECT; + OS.XtSetValues (handle, argList, argList.length / 2); + } + /* + * Note: We rely on the fact that XmListSelectPos () + * fails silently when the indices are out of range. + */ + OS.XmListSelectPos (handle, index + 1, false); + if (oldPolicy == OS.XmEXTENDED_SELECT) { + argList [1] = OS.XmEXTENDED_SELECT; + OS.XtSetValues (handle, argList, argList.length / 2); + } +} +/** + * Selects the items 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();
- if (start > end) return;
- if ((style & SWT.SINGLE) != 0) {
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int index = Math.min (argList[1] - 1, end) + 1;
- if (index != 0 && index >= start + 1) OS.XmListSelectPos (handle, index, false);
- return;
- }
- /*
- * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos ()
- * in a XmEXTENDED_SELECT list widget will add the index to the selected
- * indices. The observed behavior does not match the spec. The fix is
- * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT
- * and then switch it back because XmListSelectPos () works as specified
- * for XmMULTIPLE_SELECT list widgets.
- */
- int [] argList = {OS.XmNselectionPolicy, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int oldPolicy = argList [1];
- if (oldPolicy == OS.XmEXTENDED_SELECT) {
- argList [1] = OS.XmMULTIPLE_SELECT;
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
- /*
- * Note: We rely on the fact that XmListSelectPos ()
- * fails silently when the indices are out of range.
- */
- for (int i=start; i<=end; i++) {
- int index = i + 1;
- if ((index != 0) && !OS.XmListPosSelected (handle, index)) {
- OS.XmListSelectPos (handle, index, false);
- }
- }
- if (oldPolicy == OS.XmEXTENDED_SELECT) {
- argList [1] = OS.XmEXTENDED_SELECT;
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
-}
-/**
- * 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 start, int end) { + checkWidget(); + if (start > end) return; + if ((style & SWT.SINGLE) != 0) { + int [] argList = {OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int index = Math.min (argList[1] - 1, end) + 1; + if (index != 0 && index >= start + 1) OS.XmListSelectPos (handle, index, false); + return; + } + /* + * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos () + * in a XmEXTENDED_SELECT list widget will add the index to the selected + * indices. The observed behavior does not match the spec. The fix is + * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT + * and then switch it back because XmListSelectPos () works as specified + * for XmMULTIPLE_SELECT list widgets. + */ + int [] argList = {OS.XmNselectionPolicy, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int oldPolicy = argList [1]; + if (oldPolicy == OS.XmEXTENDED_SELECT) { + argList [1] = OS.XmMULTIPLE_SELECT; + OS.XtSetValues (handle, argList, argList.length / 2); + } + /* + * Note: We rely on the fact that XmListSelectPos () + * fails silently when the indices are out of range. + */ + for (int i=start; i<=end; i++) { + int index = i + 1; + if ((index != 0) && !OS.XmListPosSelected (handle, index)) { + OS.XmListSelectPos (handle, index, false); + } + } + if (oldPolicy == OS.XmEXTENDED_SELECT) { + argList [1] = OS.XmEXTENDED_SELECT; + OS.XtSetValues (handle, argList, argList.length / 2); + } +} +/** + * 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);
- if ((style & SWT.SINGLE) != 0) {
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int count = argList [1];
- for (int i = 0; i < indices.length; i++) {
- int index = indices [i];
- if (0 <= index && index < count) {
- select (index);
- return;
- }
- }
- return;
- }
- /*
- * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos ()
- * in a XmEXTENDED_SELECT list widget will add the index to the selected
- * indices. The observed behavior does not match the spec. The fix is
- * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT
- * and then switch it back because XmListSelectPos () works as specified
- * for XmMULTIPLE_SELECT list widgets.
- */
- int [] argList = {OS.XmNselectionPolicy, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int oldPolicy = argList [1];
- if (oldPolicy == OS.XmEXTENDED_SELECT) {
- argList [1] = OS.XmMULTIPLE_SELECT;
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
- /*
- * Note: We rely on the fact that XmListSelectPos ()
- * fails silently when the indices are out of range.
- */
- for (int i=0; i<indices.length; i++) {
- int index = indices [i] + 1;
- if ((index != 0) && !OS.XmListPosSelected (handle, index)) {
- OS.XmListSelectPos (handle, index, false);
- }
- }
- if (oldPolicy == OS.XmEXTENDED_SELECT) {
- argList [1] = OS.XmEXTENDED_SELECT;
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
-}
-void select (String [] items) {
- checkWidget();
- int [] table = new int [items.length];
- String codePage = getCodePage ();
- for (int i=0; i<items.length; i++) {
- String string = items [i];
- byte [] buffer = Converter.wcsToMbcs (codePage, string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- table [i] = xmString;
- }
- int ptr = OS.XtMalloc (items.length * 4);
- OS.memmove (ptr, table, items.length * 4);
- int [] argList = {OS.XmNselectedItems, ptr, OS.XmNselectedItemCount, table.length};
- OS.XtSetValues (handle, argList, argList.length / 2);
- for (int i=0; i<table.length; i++) OS.XmStringFree (table [i]);
- OS.XtFree (ptr);
- OS.XmListUpdateSelectedList (handle);
-}
-/**
- * Selects all 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 select (int [] indices) { + checkWidget(); + if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); + if ((style & SWT.SINGLE) != 0) { + int [] argList = {OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int count = argList [1]; + for (int i = 0; i < indices.length; i++) { + int index = indices [i]; + if (0 <= index && index < count) { + select (index); + return; + } + } + return; + } + /* + * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos () + * in a XmEXTENDED_SELECT list widget will add the index to the selected + * indices. The observed behavior does not match the spec. The fix is + * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT + * and then switch it back because XmListSelectPos () works as specified + * for XmMULTIPLE_SELECT list widgets. + */ + int [] argList = {OS.XmNselectionPolicy, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int oldPolicy = argList [1]; + if (oldPolicy == OS.XmEXTENDED_SELECT) { + argList [1] = OS.XmMULTIPLE_SELECT; + OS.XtSetValues (handle, argList, argList.length / 2); + } + /* + * Note: We rely on the fact that XmListSelectPos () + * fails silently when the indices are out of range. + */ + for (int i=0; i<indices.length; i++) { + int index = indices [i] + 1; + if ((index != 0) && !OS.XmListPosSelected (handle, index)) { + OS.XmListSelectPos (handle, index, false); + } + } + if (oldPolicy == OS.XmEXTENDED_SELECT) { + argList [1] = OS.XmEXTENDED_SELECT; + OS.XtSetValues (handle, argList, argList.length / 2); + } +} +void select (String [] items) { + checkWidget(); + int [] table = new int [items.length]; + String codePage = getCodePage (); + for (int i=0; i<items.length; i++) { + String string = items [i]; + byte [] buffer = Converter.wcsToMbcs (codePage, string, true); + int xmString = OS.XmStringCreateLocalized (buffer); + table [i] = xmString; + } + int ptr = OS.XtMalloc (items.length * 4); + OS.memmove (ptr, table, items.length * 4); + int [] argList = {OS.XmNselectedItems, ptr, OS.XmNselectedItemCount, table.length}; + OS.XtSetValues (handle, argList, argList.length / 2); + for (int i=0; i<table.length; i++) OS.XmStringFree (table [i]); + OS.XtFree (ptr); + OS.XmListUpdateSelectedList (handle); +} +/** + * Selects all 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();
- if ((style & SWT.SINGLE) != 0) return;
- /*
- * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos ()
- * in a XmEXTENDED_SELECT list widget will add the index to the selected
- * indices. The observed behavior does not match the spec. The fix is
- * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT
- * and then switch it back because XmListSelectPos () works as specified
- * for XmMULTIPLE_SELECT list widgets.
- */
- int [] argList = {OS.XmNselectionPolicy, 0, OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int oldPolicy = argList [1];
- if (oldPolicy == OS.XmEXTENDED_SELECT) {
- argList [1] = OS.XmMULTIPLE_SELECT;
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
- for (int i=0; i<argList[3]; i++) {
- int index = i + 1;
- if (!OS.XmListPosSelected (handle, index)) {
- OS.XmListSelectPos (handle, index, false);
- }
- }
- if (oldPolicy == OS.XmEXTENDED_SELECT) {
- argList [1] = OS.XmEXTENDED_SELECT;
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- boolean changed = super.setBounds (x, y, width, height, move, resize);
- /*
- * Bug in AIX. When the receiver has a vertical scroll bar
- * that is currently not visible and no horizontal scroll bar
- * and is resized to be smaller in both the width and height
- * and goes from the state where the width of the longest item
- * is smaller than the width of the list to the state where the
- * width of the longest item is longer than the width of the
- * list, the list hides the vertical scroll bar and leaves a
- * blank space where it should be. This often happens when a
- * shell containing a list that matches the above criteria is
- * maximized and then restored. This is just one of a number
- * of repeatable cases where the scrolled window hides the
- * scroll bars but does not resize the list. The fix is to
- * detect these cases and force the scroll bars to be layed
- * out properly by growing and then shrinking the scrolled
- * window.
- */
-
- /* Grow and shrink the scrolled window by one pixel */
- if (changed && scrolledHandle != 0) {
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
- OS.XtResizeWidget (scrolledHandle, argList [1] + 1, argList [3], argList [5]);
- OS.XtResizeWidget (scrolledHandle, argList [1], argList [3], argList [5]);
- }
- return changed;
-}
-void setFocusIndex (int index) {
- OS.XmListSetKbdItemPos (handle, index + 1);
-}
-/**
- * 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 selectAll () { + checkWidget(); + if ((style & SWT.SINGLE) != 0) return; + /* + * Feature in MOTIF. The X/MOTIF 1.2 spec says that XmListSelectPos () + * in a XmEXTENDED_SELECT list widget will add the index to the selected + * indices. The observed behavior does not match the spec. The fix is + * to temporarily switch the XmNselectionPolicy to XmMULTIPLE_SELECT + * and then switch it back because XmListSelectPos () works as specified + * for XmMULTIPLE_SELECT list widgets. + */ + int [] argList = {OS.XmNselectionPolicy, 0, OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int oldPolicy = argList [1]; + if (oldPolicy == OS.XmEXTENDED_SELECT) { + argList [1] = OS.XmMULTIPLE_SELECT; + OS.XtSetValues (handle, argList, argList.length / 2); + } + for (int i=0; i<argList[3]; i++) { + int index = i + 1; + if (!OS.XmListPosSelected (handle, index)) { + OS.XmListSelectPos (handle, index, false); + } + } + if (oldPolicy == OS.XmEXTENDED_SELECT) { + argList [1] = OS.XmEXTENDED_SELECT; + OS.XtSetValues (handle, argList, argList.length / 2); + } +} +boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { + boolean changed = super.setBounds (x, y, width, height, move, resize); + /* + * Bug in AIX. When the receiver has a vertical scroll bar + * that is currently not visible and no horizontal scroll bar + * and is resized to be smaller in both the width and height + * and goes from the state where the width of the longest item + * is smaller than the width of the list to the state where the + * width of the longest item is longer than the width of the + * list, the list hides the vertical scroll bar and leaves a + * blank space where it should be. This often happens when a + * shell containing a list that matches the above criteria is + * maximized and then restored. This is just one of a number + * of repeatable cases where the scrolled window hides the + * scroll bars but does not resize the list. The fix is to + * detect these cases and force the scroll bars to be layed + * out properly by growing and then shrinking the scrolled + * window. + */ + + /* Grow and shrink the scrolled window by one pixel */ + if (changed && scrolledHandle != 0) { + int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; + OS.XtGetValues (scrolledHandle, argList, argList.length / 2); + OS.XtResizeWidget (scrolledHandle, argList [1] + 1, argList [3], argList [5]); + OS.XtResizeWidget (scrolledHandle, argList [1], argList [3], argList [5]); + } + return changed; +} +void setFocusIndex (int index) { + OS.XmListSetKbdItemPos (handle, index + 1); +} +/** + * 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 (index == -1) error (SWT.ERROR_INVALID_RANGE);
- int [] argList = {OS.XmNitemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (!(0 <= index && index < argList [1])) {
- error (SWT.ERROR_INVALID_RANGE);
- }
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED);
- boolean isSelected = OS.XmListPosSelected (handle, index + 1);
- OS.XmListReplaceItemsPosUnselected (handle, new int [] {xmString}, 1, index + 1);
- if (isSelected) OS.XmListSelectPos (handle, index + 1, false);
- OS.XmStringFree (xmString);
-}
-/**
- * Sets the receiver's items to be the given array of items.
- *
- * @param items the array of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - 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 setItem (int index, String string) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + if (index == -1) error (SWT.ERROR_INVALID_RANGE); + int [] argList = {OS.XmNitemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (!(0 <= index && index < argList [1])) { + error (SWT.ERROR_INVALID_RANGE); + } + byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); + int xmString = OS.XmStringCreateLocalized (buffer); + if (xmString == 0) error (SWT.ERROR_ITEM_NOT_ADDED); + boolean isSelected = OS.XmListPosSelected (handle, index + 1); + OS.XmListReplaceItemsPosUnselected (handle, new int [] {xmString}, 1, index + 1); + if (isSelected) OS.XmListSelectPos (handle, index + 1, false); + OS.XmStringFree (xmString); +} +/** + * Sets the receiver's items to be the given array of items. + * + * @param items the array of items + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - 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);
- /*
- * Bug in AIX. When all list items are replaced
- * in a scrolled list that is currently showing a
- * horizontal scroll bar, the horizontal scroll bar
- * is hidden, but the list does not grow to take up
- * the space once occupied by the bar. The fix is
- * of force the horizontal bar to be recomputed by
- * removing all items and resizing the list.
- */
- OS.XmListSetPos (handle, 0);
- OS.XmListDeselectAllItems (handle);
- if ((style & SWT.H_SCROLL) != 0) {
- OS.XmListDeleteAllItems (handle);
- }
- int index = 0;
- int [] table = new int [items.length];
- String codePage = getCodePage ();
- while (index < items.length) {
- String string = items [index];
- if (string == null) break;
- byte [] buffer = Converter.wcsToMbcs (codePage, string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString == 0) break;
- table [index++] = xmString;
- }
- int ptr = OS.XtMalloc (index * 4);
- OS.memmove (ptr, table, index * 4);
- int [] argList = {OS.XmNitems, ptr, OS.XmNitemCount, index};
- OS.XtSetValues (handle, argList, argList.length / 2);
- for (int i=0; i<index; i++) OS.XmStringFree (table [i]);
- OS.XtFree (ptr);
- /*
- * Bug in Motif. Resize the list to work around
- * the horizontal scroll bar display bug described
- * above.
- */
- if ((style & SWT.H_SCROLL) != 0) {
- OS.XtResizeWindow (handle);
- }
- if (index < items.length) error (SWT.ERROR_ITEM_NOT_ADDED);
-}
-/**
- * Selects the item at the given zero-relative index in the receiver.
- * If the item at the index was already selected, it remains selected.
- * The current 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 setItems (String [] items) { + checkWidget(); + if (items == null) error (SWT.ERROR_NULL_ARGUMENT); + /* + * Bug in AIX. When all list items are replaced + * in a scrolled list that is currently showing a + * horizontal scroll bar, the horizontal scroll bar + * is hidden, but the list does not grow to take up + * the space once occupied by the bar. The fix is + * of force the horizontal bar to be recomputed by + * removing all items and resizing the list. + */ + OS.XmListSetPos (handle, 0); + OS.XmListDeselectAllItems (handle); + if ((style & SWT.H_SCROLL) != 0) { + OS.XmListDeleteAllItems (handle); + } + int index = 0; + int [] table = new int [items.length]; + String codePage = getCodePage (); + while (index < items.length) { + String string = items [index]; + if (string == null) break; + byte [] buffer = Converter.wcsToMbcs (codePage, string, true); + int xmString = OS.XmStringCreateLocalized (buffer); + if (xmString == 0) break; + table [index++] = xmString; + } + int ptr = OS.XtMalloc (index * 4); + OS.memmove (ptr, table, index * 4); + int [] argList = {OS.XmNitems, ptr, OS.XmNitemCount, index}; + OS.XtSetValues (handle, argList, argList.length / 2); + for (int i=0; i<index; i++) OS.XmStringFree (table [i]); + OS.XtFree (ptr); + /* + * Bug in Motif. Resize the list to work around + * the horizontal scroll bar display bug described + * above. + */ + if ((style & SWT.H_SCROLL) != 0) { + OS.XtResizeWindow (handle); + } + if (index < items.length) error (SWT.ERROR_ITEM_NOT_ADDED); +} +/** + * Selects the item at the given zero-relative index in the receiver. + * If the item at the index was already selected, it remains selected. + * The current 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 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 ();
-}
+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. @@ -1368,153 +1368,153 @@ public void setSelection (int start, int end) { * @see List#deselectAll() * @see List#select(int[]) */ -public void setSelection(int[] indices) {
- checkWidget();
- if (indices == null) error (SWT.ERROR_NULL_ARGUMENT);
- 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(int[] indices) { + checkWidget(); + if (indices == null) error (SWT.ERROR_NULL_ARGUMENT); + 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);
- String codePage = getCodePage ();
- if ((style & SWT.SINGLE) != 0) {
- for (int i=items.length-1; i>=0; --i) {
- String string = items [i];
- if (string != null) {
- byte [] buffer = Converter.wcsToMbcs (codePage, string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString != 0) {
- int index = OS.XmListItemPos (handle, xmString);
- if (index != 0) OS.XmListSelectPos (handle, index, false);
- OS.XmStringFree (xmString);
- if (index != 0 && OS.XmListPosSelected (handle, index)) {
- showSelection ();
- return;
- }
- }
- }
- }
- OS.XmListDeselectAllItems (handle);
- return;
- }
- OS.XmListDeselectAllItems (handle);
- int length = 0;
- int [] table = new int [items.length];
- for (int i=0; i<items.length; i++) {
- String string = items [i];
- if (string != null) {
- byte [] buffer = Converter.wcsToMbcs (codePage, string, true);
- int xmString = OS.XmStringCreateLocalized (buffer);
- if (xmString != 0) table [length++] = xmString;
- }
- }
- int ptr = OS.XtMalloc (length * 4);
- OS.memmove (ptr, table, length * 4);
- int [] argList = {OS.XmNselectedItems, ptr, OS.XmNselectedItemCount, length};
- OS.XtSetValues (handle, argList, argList.length / 2);
- for (int i=0; i<length; i++) OS.XmStringFree (table [i]);
- OS.XtFree (ptr);
- OS.XmListUpdateSelectedList (handle);
- showSelection ();
-}
-/**
- * Sets the zero-relative index of the item which is currently
- * at the top of the receiver. This index can change when items
- * are scrolled or new items are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void setSelection (String [] items) { + checkWidget(); + if (items == null) error (SWT.ERROR_NULL_ARGUMENT); + String codePage = getCodePage (); + if ((style & SWT.SINGLE) != 0) { + for (int i=items.length-1; i>=0; --i) { + String string = items [i]; + if (string != null) { + byte [] buffer = Converter.wcsToMbcs (codePage, string, true); + int xmString = OS.XmStringCreateLocalized (buffer); + if (xmString != 0) { + int index = OS.XmListItemPos (handle, xmString); + if (index != 0) OS.XmListSelectPos (handle, index, false); + OS.XmStringFree (xmString); + if (index != 0 && OS.XmListPosSelected (handle, index)) { + showSelection (); + return; + } + } + } + } + OS.XmListDeselectAllItems (handle); + return; + } + OS.XmListDeselectAllItems (handle); + int length = 0; + int [] table = new int [items.length]; + for (int i=0; i<items.length; i++) { + String string = items [i]; + if (string != null) { + byte [] buffer = Converter.wcsToMbcs (codePage, string, true); + int xmString = OS.XmStringCreateLocalized (buffer); + if (xmString != 0) table [length++] = xmString; + } + } + int ptr = OS.XtMalloc (length * 4); + OS.memmove (ptr, table, length * 4); + int [] argList = {OS.XmNselectedItems, ptr, OS.XmNselectedItemCount, length}; + OS.XtSetValues (handle, argList, argList.length / 2); + for (int i=0; i<length; i++) OS.XmStringFree (table [i]); + OS.XtFree (ptr); + OS.XmListUpdateSelectedList (handle); + showSelection (); +} +/** + * Sets the zero-relative index of the item which is currently + * at the top of the receiver. This index can change when items + * are scrolled or new items are added and removed. + * + * @param index the index of the top item + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setTopIndex (int index) {
- checkWidget();
- int [] argList = {OS.XmNitemCount, 0, OS.XmNvisibleItemCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int newIndex = Math.max (1, Math.min (index + 1, argList [1]));
- int lastIndex = Math.max (1, argList [1] - argList [3] + 1);
- if (newIndex > lastIndex) newIndex = lastIndex;
- OS.XmListSetPos (handle, newIndex);
-}
-/**
- * Shows the selection. If the selection is already showing in the receiver,
- * this method simply returns. Otherwise, the items are scrolled until
- * the selection is visible.
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void setTopIndex (int index) { + checkWidget(); + int [] argList = {OS.XmNitemCount, 0, OS.XmNvisibleItemCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int newIndex = Math.max (1, Math.min (index + 1, argList [1])); + int lastIndex = Math.max (1, argList [1] - argList [3] + 1); + if (newIndex > lastIndex) newIndex = lastIndex; + OS.XmListSetPos (handle, newIndex); +} +/** + * Shows the selection. If the selection is already showing in the receiver, + * this method simply returns. Otherwise, the items are scrolled until + * the selection is visible. + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void showSelection () {
- checkWidget();
- int [] buffer = new int [1], positions = new int [1];
- if (!OS.XmListGetSelectedPos (handle, positions, buffer)) return;
- if (buffer [0] == 0) return;
- int address = positions [0];
- int [] indices = new int [1];
- OS.memmove (indices, address, 4);
- OS.XtFree (address);
- int index = indices [0];
- int [] argList = {
- OS.XmNtopItemPosition, 0,
- OS.XmNvisibleItemCount, 0,
- OS.XmNitemCount, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int topIndex = argList [1], visibleCount = argList [3], count = argList [5];
- int bottomIndex = Math.min (topIndex + visibleCount - 1, count);
- if ((topIndex <= index) && (index <= bottomIndex)) return;
- int lastIndex = Math.max (1, count - visibleCount + 1);
- int newTop = Math.min (Math.max (index - (visibleCount / 2), 1), lastIndex);
- OS.XmListSetPos (handle, newTop);
-}
-int topHandle () {
- /*
- * Normally, when a composite has both a form handle
- * and a scrolled handle, the scrolled handle is the
- * parent of the form handle. In the case of a list,
- * both handles are present but the form handle is
- * parent of the scrolled handle and therefore is
- * the top handle of the list.
- */
- return formHandle;
-}
-int XmNbrowseSelectionCallback (int w, int client_data, int call_data) {
- postEvent (SWT.Selection);
- return 0;
-}
-int XmNdefaultActionCallback (int w, int client_data, int call_data) {
- postEvent (SWT.DefaultSelection);
- return 0;
-}
-int XmNextendedSelectionCallback (int w, int client_data, int call_data) {
- postEvent (SWT.Selection);
- return 0;
-}
-}
+public void showSelection () { + checkWidget(); + int [] buffer = new int [1], positions = new int [1]; + if (!OS.XmListGetSelectedPos (handle, positions, buffer)) return; + if (buffer [0] == 0) return; + int address = positions [0]; + int [] indices = new int [1]; + OS.memmove (indices, address, 4); + OS.XtFree (address); + int index = indices [0]; + int [] argList = { + OS.XmNtopItemPosition, 0, + OS.XmNvisibleItemCount, 0, + OS.XmNitemCount, 0, + }; + OS.XtGetValues (handle, argList, argList.length / 2); + int topIndex = argList [1], visibleCount = argList [3], count = argList [5]; + int bottomIndex = Math.min (topIndex + visibleCount - 1, count); + if ((topIndex <= index) && (index <= bottomIndex)) return; + int lastIndex = Math.max (1, count - visibleCount + 1); + int newTop = Math.min (Math.max (index - (visibleCount / 2), 1), lastIndex); + OS.XmListSetPos (handle, newTop); +} +int topHandle () { + /* + * Normally, when a composite has both a form handle + * and a scrolled handle, the scrolled handle is the + * parent of the form handle. In the case of a list, + * both handles are present but the form handle is + * parent of the scrolled handle and therefore is + * the top handle of the list. + */ + return formHandle; +} +int XmNbrowseSelectionCallback (int w, int client_data, int call_data) { + postEvent (SWT.Selection); + return 0; +} +int XmNdefaultActionCallback (int w, int client_data, int call_data) { + postEvent (SWT.DefaultSelection); + return 0; +} +int XmNextendedSelectionCallback (int w, int client_data, int call_data) { + postEvent (SWT.Selection); + return 0; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java index 6936e67c53..e46db0de49 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Menu.java @@ -1,36 +1,36 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are user interface objects that contain
- * menu items.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>BAR, DROP_DOWN, POP_UP</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Help, Hide, Show </dd>
- * </dl>
- * <p>
- * Note: Only one of BAR, DROP_DOWN and POP_UP may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html */ -public class Menu extends Widget {
- boolean hasLocation;
- MenuItem cascade, defaultItem;
- Decorations parent;
+ +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.events.*; +import org.eclipse.swt.graphics.*; + +/** + * Instances of this class are user interface objects that contain + * menu items. + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>BAR, DROP_DOWN, POP_UP</dd> + * <dt><b>Events:</b></dt> + * <dd>Help, Hide, Show </dd> + * </dl> + * <p> + * Note: Only one of BAR, DROP_DOWN and POP_UP may be specified. + * </p><p> + * IMPORTANT: This class is <em>not</em> intended to be subclassed. + * </p> + */ +public class Menu extends Widget { + boolean hasLocation; + MenuItem cascade, defaultItem; + Decorations parent; /** * Constructs a new instance of this class given its parent, * and sets the style for the instance so that the instance @@ -50,9 +50,9 @@ public class Menu extends Widget { * @see Widget#checkSubclass * @see Widget#getStyle */ -public Menu (Control parent) {
- this (checkNull(parent).getShell (), SWT.POP_UP);
-}
+public Menu (Control parent) { + this (checkNull(parent).getShell (), SWT.POP_UP); +} /** * Constructs a new instance of this class given its parent * (which must be a <code>Decorations</code>) and a style value @@ -84,11 +84,11 @@ public Menu (Control parent) { * @see Widget#checkSubclass * @see Widget#getStyle */ -public Menu (Decorations parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (0);
-}
+public Menu (Decorations parent, int style) { + super (parent, checkStyle (style)); + this.parent = parent; + createWidget (0); +} /** * Constructs a new instance of this class given its parent * (which must be a <code>Menu</code>) and sets the style @@ -109,9 +109,9 @@ public Menu (Decorations parent, int style) { * @see Widget#checkSubclass * @see Widget#getStyle */ -public Menu (Menu parentMenu) {
- this (checkNull(parentMenu).parent, SWT.DROP_DOWN);
-}
+public Menu (Menu parentMenu) { + this (checkNull(parentMenu).parent, SWT.DROP_DOWN); +} /** * Constructs a new instance of this class given its parent * (which must be a <code>MenuItem</code>) and sets the style @@ -132,16 +132,16 @@ public Menu (Menu parentMenu) { * @see Widget#checkSubclass * @see Widget#getStyle */ -public Menu (MenuItem parentItem) {
- this (checkNull(parentItem).parent);
-}
-void addAccelerators () {
- MenuItem [] items = getItems ();
- for (int i = 0; i < items.length; i++) {
- MenuItem item = items[i];
- item.addAccelerators ();
- }
-}
+public Menu (MenuItem parentItem) { + this (checkNull(parentItem).parent); +} +void addAccelerators () { + MenuItem [] items = getItems (); + for (int i = 0; i < items.length; i++) { + MenuItem item = items[i]; + item.addAccelerators (); + } +} /** * Adds the listener to the collection of listeners who will * be notified when help events are generated for the control, @@ -161,12 +161,12 @@ void addAccelerators () { * @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);
-}
+public void addHelpListener (HelpListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener (listener); + addListener (SWT.Help, typedListener); +} /** * Adds the listener to the collection of listeners who will * be notified when menus are hidden or shown, by sending it @@ -186,656 +186,656 @@ public void addHelpListener (HelpListener listener) { * @see MenuListener * @see #removeMenuListener */ -public void addMenuListener(MenuListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.Hide,typedListener);
- addListener(SWT.Show,typedListener);
-}
-static int checkStyle (int style) {
- return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0);
-}
-static Control checkNull (Control control) {
- if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return control;
-}
-static Menu checkNull (Menu menu) {
- if (menu == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return menu;
-}
-static MenuItem checkNull (MenuItem item) {
- if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
- return item;
-}
-void createHandle (int index) {
- state |= HANDLE;
-
- /*
- * Bug in Motif. For some reason, creating a menu after any application context
- * and shell have been destroyed will segment fault unless a new application
- * context and shell have been created in the current thread. The fix is to
- * detect this case and create and destroy a temporary application context and
- * shell.
- */
- int xDisplay = 0, shellHandle = 0;
- if (Display.DisplayDisposed) {
- int [] argc = new int [] {0};
- int xtContext = OS.XtCreateApplicationContext ();
- xDisplay = OS.XtOpenDisplay (xtContext, null, null, null, 0, 0, argc, 0);
- shellHandle = OS.XtAppCreateShell (null, null, OS.TopLevelShellWidgetClass (), xDisplay, null, 0);
- }
-
- /* BAR menu */
- if ((style & SWT.BAR) != 0) {
- int parentHandle = parent.scrolledHandle;
- int [] argList = {OS.XmNancestorSensitive, 1};
- handle = OS.XmCreateMenuBar (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- return;
- }
-
- /* POPUP and PULLDOWN menus */
-
- /*
- * Bug in Motif. When an existing popup menu is destroyed just
- * before creating a new popup menu and the new menu is managed,
- * the cursor changes to the menu cursor but the new menu is not
- * displayed. Also, Motif fails to show a popup menu when the
- * mouse is released. Both problems stem from the fact that the
- * popup menu is in the widget tree of a visible shell. The fix
- * is to create all popup menus as children of a hidden dialog
- * shell. Menus created this way are automatically destroyed
- * when the shell is destroyed.
- */
- byte [] buffer = new byte [1];
- int [] argList = {OS.XmNancestorSensitive, 1};
- if ((style & SWT.POP_UP) != 0) {
- int parentHandle = parent.dialogHandle ();
- handle = OS.XmCreatePopupMenu (parentHandle, buffer, argList, argList.length / 2);
- } else {
- /*
- * Bug in Linux. For some reason, when the parent of the pulldown
- * menu is not the main window handle, XtDestroyWidget() occasionally
- * segment faults when the shell is destroyed. The fix is to ensure
- * that the parent is the main window.
- */
- int parentHandle = parent.scrolledHandle;
- handle = OS.XmCreatePulldownMenu (parentHandle, buffer, argList, argList.length / 2);
- }
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-
- /* Workaround for bug in Motif */
- if (Display.DisplayDisposed) {
- if (shellHandle != 0) OS.XtDestroyWidget (shellHandle);
- if (xDisplay != 0) {
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- OS.XtDestroyApplicationContext (xtContext);
- }
- }
-}
-void createWidget (int index) {
- checkOrientation (parent);
- super.createWidget (index);
- parent.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 void addMenuListener(MenuListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener (listener); + addListener(SWT.Hide,typedListener); + addListener(SWT.Show,typedListener); +} +static int checkStyle (int style) { + return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0); +} +static Control checkNull (Control control) { + if (control == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + return control; +} +static Menu checkNull (Menu menu) { + if (menu == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + return menu; +} +static MenuItem checkNull (MenuItem item) { + if (item == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + return item; +} +void createHandle (int index) { + state |= HANDLE; + + /* + * Bug in Motif. For some reason, creating a menu after any application context + * and shell have been destroyed will segment fault unless a new application + * context and shell have been created in the current thread. The fix is to + * detect this case and create and destroy a temporary application context and + * shell. + */ + int xDisplay = 0, shellHandle = 0; + if (Display.DisplayDisposed) { + int [] argc = new int [] {0}; + int xtContext = OS.XtCreateApplicationContext (); + xDisplay = OS.XtOpenDisplay (xtContext, null, null, null, 0, 0, argc, 0); + shellHandle = OS.XtAppCreateShell (null, null, OS.TopLevelShellWidgetClass (), xDisplay, null, 0); + } + + /* BAR menu */ + if ((style & SWT.BAR) != 0) { + int parentHandle = parent.scrolledHandle; + int [] argList = {OS.XmNancestorSensitive, 1}; + handle = OS.XmCreateMenuBar (parentHandle, null, argList, argList.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + return; + } + + /* POPUP and PULLDOWN menus */ + + /* + * Bug in Motif. When an existing popup menu is destroyed just + * before creating a new popup menu and the new menu is managed, + * the cursor changes to the menu cursor but the new menu is not + * displayed. Also, Motif fails to show a popup menu when the + * mouse is released. Both problems stem from the fact that the + * popup menu is in the widget tree of a visible shell. The fix + * is to create all popup menus as children of a hidden dialog + * shell. Menus created this way are automatically destroyed + * when the shell is destroyed. + */ + byte [] buffer = new byte [1]; + int [] argList = {OS.XmNancestorSensitive, 1}; + if ((style & SWT.POP_UP) != 0) { + int parentHandle = parent.dialogHandle (); + handle = OS.XmCreatePopupMenu (parentHandle, buffer, argList, argList.length / 2); + } else { + /* + * Bug in Linux. For some reason, when the parent of the pulldown + * menu is not the main window handle, XtDestroyWidget() occasionally + * segment faults when the shell is destroyed. The fix is to ensure + * that the parent is the main window. + */ + int parentHandle = parent.scrolledHandle; + handle = OS.XmCreatePulldownMenu (parentHandle, buffer, argList, argList.length / 2); + } + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + + /* Workaround for bug in Motif */ + if (Display.DisplayDisposed) { + if (shellHandle != 0) OS.XtDestroyWidget (shellHandle); + if (xDisplay != 0) { + int xtContext = OS.XtDisplayToApplicationContext (xDisplay); + OS.XtDestroyApplicationContext (xtContext); + } + } +} +void createWidget (int index) { + checkOrientation (parent); + super.createWidget (index); + parent.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 () {
- checkWidget();
- return defaultItem;
-}
-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 MenuItem getDefaultItem () { + checkWidget(); + return defaultItem; +} +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 () {
- checkWidget();
- int [] argList = {OS.XmNsensitive, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] != 0;
-}
-/**
- * Returns the item at the given, zero-relative index in the
- * receiver. Throws an exception if the index is out of range.
- *
- * @param index the index of the item to return
- * @return the item at the given index
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public boolean getEnabled () { + checkWidget(); + int [] argList = {OS.XmNsensitive, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1] != 0; +} +/** + * Returns the item at the given, zero-relative index in the + * receiver. Throws an exception if the index is out of range. + * + * @param index the index of the item to return + * @return the item at the given index + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public MenuItem getItem (int index) {
- checkWidget();
- int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] == 0) error (SWT.ERROR_CANNOT_GET_ITEM);
- int [] handles = new int [argList [3]];
- OS.memmove (handles, argList [1], argList[3] * 4);
- int i = 0, count = 0;
- while (i < argList [3]) {
- if (OS.XtIsManaged (handles [i])) {
- if (index == count) break;
- count++;
- }
- i++;
- }
- if (index != count) error (SWT.ERROR_INVALID_RANGE);
- Widget widget = WidgetTable.get (handles [i]);
- if (!(widget instanceof MenuItem)) error (SWT.ERROR_CANNOT_GET_ITEM);
- return (MenuItem) widget;
-}
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public MenuItem getItem (int index) { + checkWidget(); + int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (argList [1] == 0) error (SWT.ERROR_CANNOT_GET_ITEM); + int [] handles = new int [argList [3]]; + OS.memmove (handles, argList [1], argList[3] * 4); + int i = 0, count = 0; + while (i < argList [3]) { + if (OS.XtIsManaged (handles [i])) { + if (index == count) break; + count++; + } + i++; + } + if (index != count) error (SWT.ERROR_INVALID_RANGE); + Widget widget = WidgetTable.get (handles [i]); + if (!(widget instanceof MenuItem)) error (SWT.ERROR_CANNOT_GET_ITEM); + return (MenuItem) widget; +} +/** + * Returns the number of items contained in the receiver. + * + * @return the number of items + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getItemCount () {
- checkWidget();
- int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] == 0 || argList [3] == 0) return 0;
- int [] handles = new int [argList [3]];
- OS.memmove (handles, argList [1], argList [3] * 4);
- int count = 0;
- for (int i=0; i<argList [3]; i++) {
- if (OS.XtIsManaged (handles [i])) count++;
- }
- return count;
-}
-/**
- * Returns 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 int getItemCount () { + checkWidget(); + int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (argList [1] == 0 || argList [3] == 0) return 0; + int [] handles = new int [argList [3]]; + OS.memmove (handles, argList [1], argList [3] * 4); + int count = 0; + for (int i=0; i<argList [3]; i++) { + if (OS.XtIsManaged (handles [i])) count++; + } + return count; +} +/** + * Returns 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 () {
- checkWidget();
- int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int ptr = argList [1], count = argList [3];
- if (count == 0 || ptr == 0) return new MenuItem [0];
- int [] handles = new int [count];
- OS.memmove (handles, ptr, count * 4);
- MenuItem [] items = new MenuItem [count];
- int i = 0, j = 0;
- while (i < count) {
- Widget item = WidgetTable.get (handles [i]);
- if (item != null) items [j++] = (MenuItem) item;
- i++;
- }
- if (i == j) return items;
- MenuItem [] newItems = new MenuItem [j];
- System.arraycopy (items, 0, newItems, 0, j);
- return newItems;
-}
-String getNameText () {
- String result = "";
- MenuItem [] items = getItems ();
- int length = items.length;
- if (length > 0) {
- for (int i=0; i<length-1; i++) {
- result = result + items [i].getNameText() + ", ";
- }
- result = result + items [length-1].getNameText ();
- }
- return result;
-}
-/**
- * Returns the receiver's parent, which must be a <code>Decorations</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public MenuItem [] getItems () { + checkWidget(); + int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int ptr = argList [1], count = argList [3]; + if (count == 0 || ptr == 0) return new MenuItem [0]; + int [] handles = new int [count]; + OS.memmove (handles, ptr, count * 4); + MenuItem [] items = new MenuItem [count]; + int i = 0, j = 0; + while (i < count) { + Widget item = WidgetTable.get (handles [i]); + if (item != null) items [j++] = (MenuItem) item; + i++; + } + if (i == j) return items; + MenuItem [] newItems = new MenuItem [j]; + System.arraycopy (items, 0, newItems, 0, j); + return newItems; +} +String getNameText () { + String result = ""; + MenuItem [] items = getItems (); + int length = items.length; + if (length > 0) { + for (int i=0; i<length-1; i++) { + result = result + items [i].getNameText() + ", "; + } + result = result + items [length-1].getNameText (); + } + return result; +} +/** + * Returns the receiver's parent, which must be a <code>Decorations</code>. + * + * @return the receiver's parent + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public Decorations getParent () {
- checkWidget();
- return parent;
-}
-/**
- * Returns the receiver's parent item, which must be a
- * <code>MenuItem</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public Decorations getParent () { + checkWidget(); + return parent; +} +/** + * Returns the receiver's parent item, which must be a + * <code>MenuItem</code> or null when the receiver is a + * root. + * + * @return the receiver's parent item + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public MenuItem getParentItem () {
- checkWidget();
- return cascade;
-}
-/**
- * Returns the receiver's parent item, which must be a
- * <code>Menu</code> or null when the receiver is a
- * root.
- *
- * @return the receiver's parent item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public MenuItem getParentItem () { + checkWidget(); + return cascade; +} +/** + * Returns the receiver's parent item, which must be a + * <code>Menu</code> or null when the receiver is a + * root. + * + * @return the receiver's parent item + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public Menu getParentMenu () {
- checkWidget();
- if (cascade != null) return cascade.parent;
- return null;
-}
-/**
- * Returns the receiver's shell. For all controls other than
- * shells, this simply returns the control's nearest ancestor
- * shell. Shells return themselves, even if they are children
- * of other shells.
- *
- * @return the receiver's shell
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getParent
+public Menu getParentMenu () { + checkWidget(); + if (cascade != null) return cascade.parent; + return null; +} +/** + * Returns the receiver's shell. For all controls other than + * shells, this simply returns the control's nearest ancestor + * shell. Shells return themselves, even if they are children + * of other shells. + * + * @return the receiver's shell + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #getParent */ -public Shell getShell () {
- checkWidget();
- return parent.getShell ();
-}
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public Shell getShell () { + checkWidget(); + return parent.getShell (); +} +/** + * Returns <code>true</code> if the receiver is visible, and + * <code>false</code> otherwise. + * <p> + * If one of the receiver's ancestors is not visible or some + * other condition makes the receiver not visible, this method + * may still indicate that it is considered visible even though + * it may not actually be showing. + * </p> + * + * @return the receiver's visibility state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public boolean getVisible () {
- checkWidget();
- return OS.XtIsManaged (handle);
-}
-void hookEvents () {
- int windowProc = getDisplay ().windowProc;
- OS.XtAddCallback (handle, OS.XmNhelpCallback, windowProc, HELP_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNmapCallback, windowProc, MAP_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNunmapCallback, windowProc, UNMAP_CALLBACK);
-}
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the 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 boolean getVisible () { + checkWidget(); + return OS.XtIsManaged (handle); +} +void hookEvents () { + int windowProc = getDisplay ().windowProc; + OS.XtAddCallback (handle, OS.XmNhelpCallback, windowProc, HELP_CALLBACK); + OS.XtAddCallback (handle, OS.XmNmapCallback, windowProc, MAP_CALLBACK); + OS.XtAddCallback (handle, OS.XmNunmapCallback, windowProc, UNMAP_CALLBACK); +} +/** + * Searches the receiver's list starting at the first item + * (index 0) until an item is found that is equal to the + * argument, and returns the index of that item. If no item + * is found, returns -1. + * + * @param item the search item + * @return the index of the item + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the 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) {
- checkWidget();
- int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int [] handles = new int [argList [3]];
- OS.memmove (handles, argList [1], handles.length * 4);
- int index = 0;
- for (int i=0; i<handles.length; i++) {
- if (OS.XtIsManaged (handles [i])) {
- if (handles [i] == item.handle) return index;
- index++;
- }
- }
- return -1;
-}
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
+public int indexOf (MenuItem item) { + checkWidget(); + int [] argList = {OS.XmNchildren, 0, OS.XmNnumChildren, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int [] handles = new int [argList [3]]; + OS.memmove (handles, argList [1], handles.length * 4); + int index = 0; + for (int i=0; i<handles.length; i++) { + if (OS.XtIsManaged (handles [i])) { + if (handles [i] == item.handle) return index; + index++; + } + } + return -1; +} +/** + * Returns <code>true</code> if the receiver is enabled and all + * of the receiver's ancestors are enabled, and <code>false</code> + * otherwise. A disabled control is typically not selectable from the + * user interface and draws with an inactive or "grayed" look. + * + * @return the receiver's enabled state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #getEnabled */ -public boolean isEnabled () {
- checkWidget();
- Menu parentMenu = getParentMenu ();
- if (parentMenu == null) return getEnabled ();
- return getEnabled () && parentMenu.isEnabled ();
-}
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
+public boolean isEnabled () { + checkWidget(); + Menu parentMenu = getParentMenu (); + if (parentMenu == null) return getEnabled (); + return getEnabled () && parentMenu.isEnabled (); +} +/** + * Returns <code>true</code> if the receiver is visible and all + * of the receiver's ancestors are visible and <code>false</code> + * otherwise. + * + * @return the receiver's visibility state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #getVisible */ -public boolean isVisible () {
- checkWidget();
- return getVisible ();
-}
-void 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.releaseResources ();
- }
- super.releaseWidget ();
- if (parent != null) parent.remove (this);
- parent = null;
- cascade = defaultItem = null;
-}
-void removeAccelerators () {
- MenuItem [] items = getItems ();
- for (int i = 0; i < items.length; i++) {
- MenuItem item = items[i];
- item.removeAccelerators ();
- }
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should 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 boolean isVisible () { + checkWidget(); + 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.releaseResources (); + } + super.releaseWidget (); + if (parent != null) parent.remove (this); + parent = null; + cascade = defaultItem = null; +} +void removeAccelerators () { + MenuItem [] items = getItems (); + for (int i = 0; i < items.length; i++) { + MenuItem item = items[i]; + item.removeAccelerators (); + } +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the help events are generated for the control. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see HelpListener + * @see #addHelpListener */ -public void removeHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the menu events are generated for the control.
- *
- * @param listener the listener which should 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 removeHelpListener (HelpListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook (SWT.Help, listener); +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the menu events are generated for the control. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see MenuListener + * @see #addMenuListener */ -public void removeMenuListener(MenuListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Hide, listener);
- eventTable.unhook(SWT.Show, listener);
-}
-void sendHelpEvent (int callData) {
- if (hooks (SWT.Help)) {
- postEvent (SWT.Help);
- return;
- }
- parent.sendHelpEvent (callData);
-}
-/**
- * Sets the default menu item to the argument or removes
- * the default emphasis when the argument is <code>null</code>.
- *
- * @param item the default menu item or null
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_INVALID_ARGUMENT - if the menu item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void removeMenuListener(MenuListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook(SWT.Hide, listener); + eventTable.unhook(SWT.Show, listener); +} +void sendHelpEvent (int callData) { + if (hooks (SWT.Help)) { + postEvent (SWT.Help); + return; + } + parent.sendHelpEvent (callData); +} +/** + * Sets the default menu item to the argument or removes + * the default emphasis when the argument is <code>null</code>. + * + * @param item the default menu item or null + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the menu item has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setDefaultItem (MenuItem item) {
- checkWidget();
- if (item != null && item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- defaultItem = item;
-}
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled 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 setDefaultItem (MenuItem item) { + checkWidget(); + if (item != null && item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); + defaultItem = item; +} +/** + * Enables the receiver if the argument is <code>true</code>, + * and disables it otherwise. A disabled control is typically + * not selectable from the user interface and draws with an + * inactive or "grayed" look. + * + * @param enabled the new enabled state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setEnabled (boolean enabled) {
- checkWidget();
- int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * Sets the 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 setEnabled (boolean enabled) { + checkWidget(); + int [] argList = {OS.XmNsensitive, enabled ? 1 : 0}; + OS.XtSetValues (handle, argList, argList.length / 2); +} +/** + * 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) {
- checkWidget();
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- int [] argList = {OS.XmNx, x, OS.XmNy, y};
- OS.XtSetValues (handle, argList, argList.length / 2);
- hasLocation = true;
-}
-public void setLocation (Point location) {
- checkWidget();
- if (location == null) error (SWT.ERROR_NULL_ARGUMENT);
- setLocation (location.x, location.y);
-}
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void setLocation (int x, int y) { + checkWidget(); + if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return; + int [] argList = {OS.XmNx, x, OS.XmNy, y}; + OS.XtSetValues (handle, argList, argList.length / 2); + hasLocation = true; +} +public void setLocation (Point location) { + checkWidget(); + if (location == null) error (SWT.ERROR_NULL_ARGUMENT); + setLocation (location.x, location.y); +} +/** + * Marks the receiver as visible if the argument is <code>true</code>, + * and marks it invisible otherwise. + * <p> + * If one of the receiver's ancestors is not visible or some + * other condition makes the receiver not visible, marking + * it visible may not actually cause it to be displayed. + * </p> + * + * @param visible the new visibility state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setVisible (boolean visible) {
- checkWidget();
- if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- if (visible) {
- sendEvent (SWT.Show);
- if (getItemCount () != 0) {
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XDefaultRootWindow (xDisplay);
- if (xWindow == 0) return;
- int [] rootX = new int [1], rootY = new int [1], unused = new int [1], mask = new int [1];
- if (OS.XQueryPointer (xDisplay, xWindow, unused, unused, rootX, rootY, unused, unused, mask) == 0) {
- return;
- }
- if (!hasLocation) {
- /*
- * Bug in Motif. For some reason, when a menu is popped up
- * under the mouse, the menu will not highlight until the
- * mouse exits and then enters the menu again. The fix is
- * to pop the menu up outside the current mouse position
- * causing highlighting to work properly when the user
- * waits for the menu to appear.
- */
- rootX[0] += 1; rootY[0] += 1;
- int [] argList = {OS.XmNx, rootX [0], OS.XmNy, rootY [0]};
- OS.XtSetValues (handle, argList, argList.length / 2);
- }
- /*
- * Feature in Motif. If an X grab is active, then
- * the menu pops us but issues and error message an
- * fails to grab the pointer. The fix is to ensure
- * that no grab is active before showing the menu.
- */
- OS.XUngrabPointer (xDisplay, OS.CurrentTime);
- OS.XtManageChild (handle);
- /*
- * Feature in Motif. There is no API to force the menu
- * to accept keyboard traversal when popped up using
- * XtManageChild. The fix is to call undocumented API
- * to do this.
- */
- int flags = OS.Button1Mask | OS.Button2Mask | OS.Button3Mask;
- if ((mask [0] & flags) == 0) OS._XmSetMenuTraversal (handle, true);
- } else {
- sendEvent (SWT.Hide);
- }
- } else {
- OS.XtUnmanageChild (handle);
- }
-}
-boolean translateAccelerator (int accel) {
- if (!getEnabled ()) return false;
- MenuItem [] items = getItems ();
- for (int i = 0; i < items.length; i++) {
- MenuItem item = items [i];
- if (item.translateAccelerator (accel)) return true;
- }
- return false;
-}
-int XmNhelpCallback (int w, int client_data, int call_data) {
- sendHelpEvent (call_data);
- return 0;
-}
-int XmNmapCallback (int w, int client_data, int call_data) {
- if ((style & SWT.POP_UP) != 0) return 0;
- /*
- * SWT.Selection events are posted to allow stepping
- * in the VA/Java debugger. SWT.Show events are
- * sent to ensure that application event handler
- * code runs before the menu is displayed. This
- * means that SWT.Show events would normally occur
- * before SWT.Selection events. While this is not
- * strictly incorrect, applications often use the
- * SWT.Selection event to update the state of menu
- * items and would like the ordering of events to
- * be the other way around.
- *
- * The fix is to run the deferred events before
- * the menu is shown. This means that stepping
- * through a selection event that was caused by
- * a popup menu will fail in VA/Java.
- */
- Display display = getDisplay ();
- display.runDeferredEvents ();
- sendEvent (SWT.Show);
- return 0;
-}
-int XmNunmapCallback (int w, int client_data, int call_data) {
- sendEvent (SWT.Hide);
- return 0;
-}
-}
+public void setVisible (boolean visible) { + checkWidget(); + if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return; + if (visible) { + sendEvent (SWT.Show); + if (getItemCount () != 0) { + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return; + int xWindow = OS.XDefaultRootWindow (xDisplay); + if (xWindow == 0) return; + int [] rootX = new int [1], rootY = new int [1], unused = new int [1], mask = new int [1]; + if (OS.XQueryPointer (xDisplay, xWindow, unused, unused, rootX, rootY, unused, unused, mask) == 0) { + return; + } + if (!hasLocation) { + /* + * Bug in Motif. For some reason, when a menu is popped up + * under the mouse, the menu will not highlight until the + * mouse exits and then enters the menu again. The fix is + * to pop the menu up outside the current mouse position + * causing highlighting to work properly when the user + * waits for the menu to appear. + */ + rootX[0] += 1; rootY[0] += 1; + int [] argList = {OS.XmNx, rootX [0], OS.XmNy, rootY [0]}; + OS.XtSetValues (handle, argList, argList.length / 2); + } + /* + * Feature in Motif. If an X grab is active, then + * the menu pops us but issues and error message an + * fails to grab the pointer. The fix is to ensure + * that no grab is active before showing the menu. + */ + OS.XUngrabPointer (xDisplay, OS.CurrentTime); + OS.XtManageChild (handle); + /* + * Feature in Motif. There is no API to force the menu + * to accept keyboard traversal when popped up using + * XtManageChild. The fix is to call undocumented API + * to do this. + */ + int flags = OS.Button1Mask | OS.Button2Mask | OS.Button3Mask; + if ((mask [0] & flags) == 0) OS._XmSetMenuTraversal (handle, true); + } else { + sendEvent (SWT.Hide); + } + } else { + OS.XtUnmanageChild (handle); + } +} +boolean translateAccelerator (int accel) { + if (!getEnabled ()) return false; + MenuItem [] items = getItems (); + for (int i = 0; i < items.length; i++) { + MenuItem item = items [i]; + if (item.translateAccelerator (accel)) return true; + } + return false; +} +int XmNhelpCallback (int w, int client_data, int call_data) { + sendHelpEvent (call_data); + return 0; +} +int XmNmapCallback (int w, int client_data, int call_data) { + if ((style & SWT.POP_UP) != 0) return 0; + /* + * SWT.Selection events are posted to allow stepping + * in the VA/Java debugger. SWT.Show events are + * sent to ensure that application event handler + * code runs before the menu is displayed. This + * means that SWT.Show events would normally occur + * before SWT.Selection events. While this is not + * strictly incorrect, applications often use the + * SWT.Selection event to update the state of menu + * items and would like the ordering of events to + * be the other way around. + * + * The fix is to run the deferred events before + * the menu is shown. This means that stepping + * through a selection event that was caused by + * a popup menu will fail in VA/Java. + */ + Display display = getDisplay (); + display.runDeferredEvents (); + sendEvent (SWT.Show); + return 0; +} +int XmNunmapCallback (int w, int client_data, int call_data) { + sendEvent (SWT.Hide); + return 0; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java index fd62d8e11c..dd232c3970 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MenuItem.java @@ -1,17 +1,17 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.events.*; + /** * Instances of this class represent a selectable user interface object * that issues notification when pressed and released. @@ -28,10 +28,10 @@ import org.eclipse.swt.events.*; * IMPORTANT: This class is <em>not</em> intended to be subclassed. * </p> */ -public class MenuItem extends Item {
- int accelerator;
- Menu parent, menu;
-
+public class MenuItem extends Item { + int accelerator; + Menu parent, menu; + /** * Constructs a new instance of this class given its parent * (which must be a <code>Menu</code>) and a style value @@ -66,12 +66,12 @@ public class MenuItem extends Item { * @see Widget#checkSubclass * @see Widget#getStyle */ -public MenuItem (Menu parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (OS.XmLAST_POSITION);
-}
-
+public MenuItem (Menu parent, int style) { + super (parent, checkStyle (style)); + this.parent = parent; + createWidget (OS.XmLAST_POSITION); +} + /** * Constructs a new instance of this class given its parent * (which must be a <code>Menu</code>), a style value @@ -107,538 +107,538 @@ public MenuItem (Menu parent, int style) { * @see Widget#checkSubclass * @see Widget#getStyle */ -public MenuItem (Menu parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- if (index == OS.XmLAST_POSITION) error (SWT.ERROR_INVALID_RANGE);
- createWidget (index);
-}
-void addAccelerator () {
- if (accelerator == 0) return;
- /*
- * Bug in Solaris. When accelerators are set more
- * than once in the same menu bar, the time it takes
- * to set the accelerator increases exponentially.
- * The fix is to implement our own accelerator table
- * on Solaris.
- */
- if (OS.IsSunOS) return;
- String ctrl, alt, shift;
- ctrl = alt = shift = "";
- if ((accelerator & SWT.ALT) != 0) alt = "Meta ";
- if ((accelerator & SWT.SHIFT) != 0) shift = "Shift ";
- if ((accelerator & SWT.CONTROL) != 0) ctrl = "Ctrl ";
- int keysym = accelerator & SWT.KEY_MASK;
- int newKey = Display.untranslateKey (keysym);
- if (newKey != 0) {
- keysym = newKey;
- } else {
- keysym = wcsToMbcs ((char) keysym);
- }
- /*
- * Feature in Motif. Motif does not activate an accelerator
- * when the CapsLoc, NumLoc and NumLock+CapsLoc keys are pressed.
- * In order to activate accelerators when these keys are pressed,
- * it is necessary to look for all of these key sequences.
- */
- String key = ctrl + alt + shift + "<Key>" + keysymName (keysym);
- String allKeys = key + ",Lock " + key + ",Mod2 " + key + ",Lock Mod2 " + key;
- /* Use the character encoding for the default locale */
- byte [] buffer = Converter.wcsToMbcs (null, allKeys, true);
- int ptr = OS.XtMalloc (buffer.length);
- if (ptr != 0) OS.memmove (ptr, buffer, buffer.length);
-
- int [] argList = {OS.XmNaccelerator, ptr};
- OS.XtSetValues (handle, argList, argList.length / 2);
- if (ptr != 0) OS.XtFree (ptr);
-}
-void addAccelerators () {
- addAccelerator ();
- if (menu != null) menu.addAccelerators ();
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the arm events are generated for the control, by sending
- * it one of the messages defined in the <code>ArmListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ArmListener
- * @see #removeArmListener
+public MenuItem (Menu parent, int style, int index) { + super (parent, checkStyle (style)); + this.parent = parent; + if (index == OS.XmLAST_POSITION) error (SWT.ERROR_INVALID_RANGE); + createWidget (index); +} +void addAccelerator () { + if (accelerator == 0) return; + /* + * Bug in Solaris. When accelerators are set more + * than once in the same menu bar, the time it takes + * to set the accelerator increases exponentially. + * The fix is to implement our own accelerator table + * on Solaris. + */ + if (OS.IsSunOS) return; + String ctrl, alt, shift; + ctrl = alt = shift = ""; + if ((accelerator & SWT.ALT) != 0) alt = "Meta "; + if ((accelerator & SWT.SHIFT) != 0) shift = "Shift "; + if ((accelerator & SWT.CONTROL) != 0) ctrl = "Ctrl "; + int keysym = accelerator & SWT.KEY_MASK; + int newKey = Display.untranslateKey (keysym); + if (newKey != 0) { + keysym = newKey; + } else { + keysym = wcsToMbcs ((char) keysym); + } + /* + * Feature in Motif. Motif does not activate an accelerator + * when the CapsLoc, NumLoc and NumLock+CapsLoc keys are pressed. + * In order to activate accelerators when these keys are pressed, + * it is necessary to look for all of these key sequences. + */ + String key = ctrl + alt + shift + "<Key>" + keysymName (keysym); + String allKeys = key + ",Lock " + key + ",Mod2 " + key + ",Lock Mod2 " + key; + /* Use the character encoding for the default locale */ + byte [] buffer = Converter.wcsToMbcs (null, allKeys, true); + int ptr = OS.XtMalloc (buffer.length); + if (ptr != 0) OS.memmove (ptr, buffer, buffer.length); + + int [] argList = {OS.XmNaccelerator, ptr}; + OS.XtSetValues (handle, argList, argList.length / 2); + if (ptr != 0) OS.XtFree (ptr); +} +void addAccelerators () { + addAccelerator (); + if (menu != null) menu.addAccelerators (); +} +/** + * Adds the listener to the collection of listeners who will + * be notified when the arm events are generated for the control, by sending + * it one of the messages defined in the <code>ArmListener</code> + * interface. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see ArmListener + * @see #removeArmListener */ -public void addArmListener (ArmListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Arm, typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the help events are generated for the control, by sending
- * it one of the messages defined in the <code>HelpListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see HelpListener
- * @see #removeHelpListener
+public void addArmListener (ArmListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener (listener); + addListener (SWT.Arm, typedListener); +} +/** + * Adds the listener to the collection of listeners who will + * be notified when the help events are generated for the control, by sending + * it one of the messages defined in the <code>HelpListener</code> + * interface. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see HelpListener + * @see #removeHelpListener */ -public void addHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Help, typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the 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 addHelpListener (HelpListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener (listener); + addListener (SWT.Help, typedListener); +} +/** + * Adds the listener to the collection of listeners who will + * be notified when the 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) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-static int checkStyle (int style) {
- return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.CASCADE, 0);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-void createHandle (int index) {
- state |= HANDLE;
- int parentHandle = parent.handle;
- int [] argList1 = {OS.XmNchildren, 0, OS.XmNnumChildren, 0};
- OS.XtGetValues (parentHandle, argList1, argList1.length / 2);
- if (index != OS.XmLAST_POSITION && argList1 [1] != 0) {
- int [] handles = new int [argList1 [3]];
- OS.memmove (handles, argList1 [1], argList1 [3] * 4);
- int i = 0, count = 0;
- while (i < argList1 [3]) {
- if (OS.XtIsManaged (handles [i])) {
- if (index == count) break;
- count++;
- }
- i++;
- }
- if (index != count) error (SWT.ERROR_INVALID_RANGE);
- index = i;
- }
- if ((style & SWT.SEPARATOR) != 0) {
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNorientation, (parent.style & SWT.BAR) != 0 ? OS.XmVERTICAL : OS.XmHORIZONTAL,
- OS.XmNpositionIndex, index,
- };
- handle = OS.XmCreateSeparatorGadget (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- return;
- }
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNpositionIndex, index,
- };
- if ((style & SWT.PUSH) != 0) {
- handle = OS.XmCreatePushButtonGadget (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- return;
- }
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- handle = OS.XmCreateToggleButtonGadget (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- int indicatorType = OS.XmONE_OF_MANY;
- if ((style & SWT.CHECK) != 0) indicatorType = OS.XmN_OF_MANY;
- int [] argList2 = {OS.XmNindicatorType, indicatorType};
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- return;
- }
- handle = OS.XmCreateCascadeButtonGadget (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-void destroyWidget () {
- /*
- * Feature in Motif. When a popup menu item
- * is destroyed, the menu does not recompute
- * the menu size until the next time the menu
- * is managed. This means that the user can
- * watch the menu get updated as new items are
- * added and old ones deleted. The fix is to
- * unmanaged the item before destroying it to
- * force the menu to recompute the menu size.
- */
- OS.XtUnmanageChild (handle);
- super.destroyWidget ();
-}
-/**
- * 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 void addSelectionListener(SelectionListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener(listener); + addListener(SWT.Selection,typedListener); + addListener(SWT.DefaultSelection,typedListener); +} +static int checkStyle (int style) { + return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.CASCADE, 0); +} +protected void checkSubclass () { + if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); +} +void createHandle (int index) { + state |= HANDLE; + int parentHandle = parent.handle; + int [] argList1 = {OS.XmNchildren, 0, OS.XmNnumChildren, 0}; + OS.XtGetValues (parentHandle, argList1, argList1.length / 2); + if (index != OS.XmLAST_POSITION && argList1 [1] != 0) { + int [] handles = new int [argList1 [3]]; + OS.memmove (handles, argList1 [1], argList1 [3] * 4); + int i = 0, count = 0; + while (i < argList1 [3]) { + if (OS.XtIsManaged (handles [i])) { + if (index == count) break; + count++; + } + i++; + } + if (index != count) error (SWT.ERROR_INVALID_RANGE); + index = i; + } + if ((style & SWT.SEPARATOR) != 0) { + int [] argList = { + OS.XmNancestorSensitive, 1, + OS.XmNorientation, (parent.style & SWT.BAR) != 0 ? OS.XmVERTICAL : OS.XmHORIZONTAL, + OS.XmNpositionIndex, index, + }; + handle = OS.XmCreateSeparatorGadget (parentHandle, null, argList, argList.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + return; + } + int [] argList = { + OS.XmNancestorSensitive, 1, + OS.XmNpositionIndex, index, + }; + if ((style & SWT.PUSH) != 0) { + handle = OS.XmCreatePushButtonGadget (parentHandle, null, argList, argList.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + return; + } + if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { + handle = OS.XmCreateToggleButtonGadget (parentHandle, null, argList, argList.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + int indicatorType = OS.XmONE_OF_MANY; + if ((style & SWT.CHECK) != 0) indicatorType = OS.XmN_OF_MANY; + int [] argList2 = {OS.XmNindicatorType, indicatorType}; + OS.XtSetValues (handle, argList2, argList2.length / 2); + return; + } + handle = OS.XmCreateCascadeButtonGadget (parentHandle, null, argList, argList.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); +} +void destroyWidget () { + /* + * Feature in Motif. When a popup menu item + * is destroyed, the menu does not recompute + * the menu size until the next time the menu + * is managed. This means that the user can + * watch the menu get updated as new items are + * added and old ones deleted. The fix is to + * unmanaged the item before destroying it to + * force the menu to recompute the menu size. + */ + OS.XtUnmanageChild (handle); + super.destroyWidget (); +} +/** + * 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 () {
- checkWidget();
- 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 int getAccelerator () { + checkWidget(); + 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 () {
- checkWidget();
- int [] argList = {OS.XmNsensitive, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] != 0;
-}
-/**
- * Returns the receiver's cascade menu if it has one or null
- * if it does not. Only <code>CASCADE</code> menu items can have
- * a pull down menu. The sequence of key strokes, button presses
- * and/or button releases that are used to request a pull down
- * menu is platform specific.
- *
- * @return the receiver's menu
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public boolean getEnabled () { + checkWidget(); + int [] argList = {OS.XmNsensitive, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1] != 0; +} +/** + * Returns the receiver's cascade menu if it has one or null + * if it does not. Only <code>CASCADE</code> menu items can have + * a pull down menu. The sequence of key strokes, button presses + * and/or button releases that are used to request a pull down + * menu is platform specific. + * + * @return the receiver's menu + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public Menu getMenu () {
- checkWidget();
- return menu;
-}
-String getNameText () {
- if ((style & SWT.SEPARATOR) != 0) return "|";
- return super.getNameText ();
-}
-/**
- * Returns the receiver's parent, which must be a <code>Menu</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public Menu getMenu () { + checkWidget(); + return menu; +} +String getNameText () { + if ((style & SWT.SEPARATOR) != 0) return "|"; + return super.getNameText (); +} +/** + * Returns the receiver's parent, which must be a <code>Menu</code>. + * + * @return the receiver's parent + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public Menu getParent () {
- checkWidget();
- return parent;
-}
-/**
- * Returns <code>true</code> if the receiver is selected,
- * and false otherwise.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked.
- *
- * @return the selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public Menu getParent () { + checkWidget(); + return parent; +} +/** + * Returns <code>true</code> if the receiver is selected, + * and false otherwise. + * <p> + * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, + * it is selected when it is checked. + * + * @return the selection state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public boolean getSelection () {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
- int [] argList = {OS.XmNset, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] != OS.XmUNSET;
-}
-void hookEvents () {
- if ((style & SWT.SEPARATOR) != 0) return;
- int windowProc = getDisplay ().windowProc;
- OS.XtAddCallback (handle, OS.XmNhelpCallback, windowProc, HELP_CALLBACK);
- if ((style & SWT.CASCADE) != 0) {
- OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNcascadingCallback, windowProc, CASCADING_CALLBACK);
- } else {
- OS.XtAddCallback (handle, OS.XmNarmCallback, windowProc, ARM_CALLBACK);
- if ((style & (SWT.CHECK | SWT.RADIO)) != 0) {
- OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
- } else {
- OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK);
- }
- }
-}
-boolean isAccelActive () {
- Menu menu = parent;
- while (menu != null && menu.cascade != null) {
- menu = menu.cascade.parent;
- }
- Decorations shell = menu.parent;
- return shell.menuBar == menu;
-}
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
+public boolean getSelection () { + checkWidget(); + if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false; + int [] argList = {OS.XmNset, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1] != OS.XmUNSET; +} +void hookEvents () { + if ((style & SWT.SEPARATOR) != 0) return; + int windowProc = getDisplay ().windowProc; + OS.XtAddCallback (handle, OS.XmNhelpCallback, windowProc, HELP_CALLBACK); + if ((style & SWT.CASCADE) != 0) { + OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK); + OS.XtAddCallback (handle, OS.XmNcascadingCallback, windowProc, CASCADING_CALLBACK); + } else { + OS.XtAddCallback (handle, OS.XmNarmCallback, windowProc, ARM_CALLBACK); + if ((style & (SWT.CHECK | SWT.RADIO)) != 0) { + OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK); + } else { + OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK); + } + } +} +boolean isAccelActive () { + Menu menu = parent; + while (menu != null && menu.cascade != null) { + menu = menu.cascade.parent; + } + Decorations shell = menu.parent; + return shell.menuBar == menu; +} +/** + * Returns <code>true</code> if the receiver is enabled and all + * of the receiver's ancestors are enabled, and <code>false</code> + * otherwise. A disabled control is typically not selectable from the + * user interface and draws with an inactive or "grayed" look. + * + * @return the receiver's enabled state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #getEnabled */ -public boolean isEnabled () {
- return getEnabled () && parent.isEnabled ();
-}
-String keysymName (int keysym) {
- switch (keysym) {
- case 8: return "BackSpace";
- case 9: return "Tab";
- /*
- * Bug in Motif. For some reason, the XmNaccelerator
- * resource will not accept XK_Linefeed and prints Xt
- * warnings. The fix is to use XK_Return instead.
- */
-// case 10:
-// case OS.XK_Linefeed: return "Linefeed";
- case 10:
- case OS.XK_Linefeed:
- case 13: return "Return";
- case 27: return "Escape";
- case 127: return "Delete";
- }
- if (('0' <= keysym && keysym <= '9') ||
- ('a' <= keysym && keysym <= 'z') ||
- ('A' <= keysym && keysym <= 'Z')) {
- return new String (new char [] {(char) keysym});
- }
- /*
- * Note that XKeysymToString returns a value in a static
- * area which must not be modified or freed.
+public boolean isEnabled () { + return getEnabled () && parent.isEnabled (); +} +String keysymName (int keysym) { + switch (keysym) { + case 8: return "BackSpace"; + case 9: return "Tab"; + /* + * Bug in Motif. For some reason, the XmNaccelerator + * resource will not accept XK_Linefeed and prints Xt + * warnings. The fix is to use XK_Return instead. + */ +// case 10: +// case OS.XK_Linefeed: return "Linefeed"; + case 10: + case OS.XK_Linefeed: + case 13: return "Return"; + case 27: return "Escape"; + case 127: return "Delete"; + } + if (('0' <= keysym && keysym <= '9') || + ('a' <= keysym && keysym <= 'z') || + ('A' <= keysym && keysym <= 'Z')) { + return new String (new char [] {(char) keysym}); + } + /* + * Note that XKeysymToString returns a value in a static + * area which must not be modified or freed. */ - int ptr = OS.XKeysymToString (keysym);
- if (ptr == 0) return "";
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, buffer.length);
- /* Use the character encoding for the default locale */
- return new String (Converter.mbcsToWcs (null, buffer));
-}
-void manageChildren () {
- OS.XtManageChild (handle);
-}
-void releaseChild () {
- super.releaseChild ();
- if (menu != null) menu.dispose ();
- menu = null;
-}
-void releaseWidget () {
- if (menu != null && !menu.isDisposed ()) menu.releaseResources ();
- menu = null;
- super.releaseWidget ();
- accelerator = 0;
- if (this == parent.defaultItem) {
- parent.defaultItem = null;
- }
- parent = null;
-}
-void removeAccelerator () {
- if (accelerator == 0) return;
- /*
- * Bug in Solaris. When accelerators are set more
- * than once in the same menu bar, the time it takes
- * to set the accelerator increases exponentially.
- * The fix is to implement our own accelerator table
- * on Solaris.
- */
- if (OS.IsSunOS) return;
- int [] argList = {OS.XmNaccelerator, 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-void removeAccelerators () {
- removeAccelerator ();
- if (menu != null) menu.removeAccelerators ();
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the arm events are generated for the control.
- *
- * @param listener the listener which should 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
+ int ptr = OS.XKeysymToString (keysym); + if (ptr == 0) return ""; + int length = OS.strlen (ptr); + byte [] buffer = new byte [length]; + OS.memmove (buffer, ptr, buffer.length); + /* Use the character encoding for the default locale */ + return new String (Converter.mbcsToWcs (null, buffer)); +} +void manageChildren () { + OS.XtManageChild (handle); +} +void releaseChild () { + super.releaseChild (); + if (menu != null) menu.dispose (); + menu = null; +} +void releaseWidget () { + if (menu != null && !menu.isDisposed ()) menu.releaseResources (); + menu = null; + super.releaseWidget (); + accelerator = 0; + if (this == parent.defaultItem) { + parent.defaultItem = null; + } + parent = null; +} +void removeAccelerator () { + if (accelerator == 0) return; + /* + * Bug in Solaris. When accelerators are set more + * than once in the same menu bar, the time it takes + * to set the accelerator increases exponentially. + * The fix is to implement our own accelerator table + * on Solaris. + */ + if (OS.IsSunOS) return; + int [] argList = {OS.XmNaccelerator, 0}; + OS.XtSetValues (handle, argList, argList.length / 2); +} +void removeAccelerators () { + removeAccelerator (); + if (menu != null) menu.removeAccelerators (); +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the arm events are generated for the control. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see ArmListener + * @see #addArmListener */ -public void removeArmListener (ArmListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Arm, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the help events are generated for the control.
- *
- * @param listener the listener which should 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 removeArmListener (ArmListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook (SWT.Arm, listener); +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the help events are generated for the control. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see HelpListener + * @see #addHelpListener */ -public void removeHelpListener (HelpListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Help, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected.
- *
- * @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 removeHelpListener (HelpListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook (SWT.Help, listener); +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the control is selected. + * + * @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);
-}
-void selectRadio () {
- int index = 0;
- MenuItem [] items = parent.getItems ();
- while (index < items.length && items [index] != this) index++;
- int i = index - 1;
- while (i >= 0 && items [i].setRadioSelection (false)) --i;
- int j = index + 1;
- while (j < items.length && items [j].setRadioSelection (false)) j++;
- setSelection (true);
-}
-/**
- * Sets the widget accelerator. An accelerator is the bit-wise
- * OR of zero or more modifier masks and a key. Examples:
- * <code>SWT.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 removeSelectionListener(SelectionListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook(SWT.Selection, listener); + eventTable.unhook(SWT.DefaultSelection,listener); +} +void selectRadio () { + int index = 0; + MenuItem [] items = parent.getItems (); + while (index < items.length && items [index] != this) index++; + int i = index - 1; + while (i >= 0 && items [i].setRadioSelection (false)) --i; + int j = index + 1; + while (j < items.length && items [j].setRadioSelection (false)) j++; + setSelection (true); +} +/** + * Sets the widget accelerator. An accelerator is the bit-wise + * OR of zero or more modifier masks and a key. Examples: + * <code>SWT.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) {
- checkWidget();
- if (this.accelerator == accelerator) return;
- this.accelerator = accelerator;
- if (isAccelActive ()) {
- if (accelerator != 0) {
- addAccelerator ();
- } else {
- removeAccelerator ();
- }
- }
-}
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled 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 setAccelerator (int accelerator) { + checkWidget(); + if (this.accelerator == accelerator) return; + this.accelerator = accelerator; + if (isAccelActive ()) { + if (accelerator != 0) { + addAccelerator (); + } else { + removeAccelerator (); + } + } +} +/** + * Enables the receiver if the argument is <code>true</code>, + * and disables it otherwise. A disabled control is typically + * not selectable from the user interface and draws with an + * inactive or "grayed" look. + * + * @param enabled the new enabled state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setEnabled (boolean enabled) {
- checkWidget();
- int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
+public void setEnabled (boolean enabled) { + checkWidget(); + int [] argList = {OS.XmNsensitive, enabled ? 1 : 0}; + OS.XtSetValues (handle, argList, argList.length / 2); +} /** * Sets the receiver's pull down menu to the argument. * Only <code>CASCADE</code> menu items can have a @@ -659,236 +659,236 @@ public void setEnabled (boolean enabled) { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setMenu (Menu menu) {
- checkWidget();
- /* Check to make sure the new menu is valid */
- if ((style & SWT.CASCADE) == 0) {
- error (SWT.ERROR_MENUITEM_NOT_CASCADE);
- }
- if (menu != null) {
- if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((menu.style & SWT.DROP_DOWN) == 0) {
- error (SWT.ERROR_MENU_NOT_DROP_DOWN);
- }
- if (menu.parent != parent.parent) {
- error (SWT.ERROR_INVALID_PARENT);
- }
- }
-
- /* Assign the new menu */
- Menu oldMenu = this.menu;
- if (oldMenu == menu) return;
-
+public void setMenu (Menu menu) { + checkWidget(); + /* Check to make sure the new menu is valid */ + if ((style & SWT.CASCADE) == 0) { + error (SWT.ERROR_MENUITEM_NOT_CASCADE); + } + if (menu != null) { + if (menu.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); + if ((menu.style & SWT.DROP_DOWN) == 0) { + error (SWT.ERROR_MENU_NOT_DROP_DOWN); + } + if (menu.parent != parent.parent) { + error (SWT.ERROR_INVALID_PARENT); + } + } + + /* Assign the new menu */ + Menu oldMenu = this.menu; + if (oldMenu == menu) return; + /* * Bug in Motif. When XmNsubMenuId is set and the * previous menu has accelerators, the time it takes * to add any new accelerators increases exponentially. * The fix is to remove the accelerators from the previous * menu before setting the new one. - */
- boolean isActive = isAccelActive ();
+ */ + boolean isActive = isAccelActive (); if (isActive) removeAccelerators (); -
- if (oldMenu != null) oldMenu.cascade = null;
- this.menu = menu;
-
- /* Set the new menu in the OS */
- int menuHandle = 0;
- if (menu != null) {
- menu.cascade = this;
- menuHandle = menu.handle;
- }
- int [] argList = {OS.XmNsubMenuId, menuHandle};
+ + if (oldMenu != null) oldMenu.cascade = null; + this.menu = menu; + + /* Set the new menu in the OS */ + int menuHandle = 0; + if (menu != null) { + menu.cascade = this; + menuHandle = menu.handle; + } + int [] argList = {OS.XmNsubMenuId, menuHandle}; OS.XtSetValues (handle, argList, argList.length / 2); -
- if (isActive) addAccelerators ();
-}
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
-/**
- * Sets the selection state of the receiver.
- * <p>
- * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>,
- * it is selected when it is checked.
- *
- * @param selected the new selection state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+ + if (isActive) addAccelerators (); +} +boolean setRadioSelection (boolean value) { + if ((style & SWT.RADIO) == 0) return false; + if (getSelection () != value) { + setSelection (value); + postEvent (SWT.Selection); + } + return true; +} +/** + * Sets the selection state of the receiver. + * <p> + * When the receiver is of type <code>CHECK</code> or <code>RADIO</code>, + * it is selected when it is checked. + * + * @param selected the new selection state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setSelection (boolean selected) {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
- int [] argList = {OS.XmNset, selected ? OS.XmSET : OS.XmUNSET};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- /*
- * Feature in Motif. Motif does not optimize the case
- * when the same text is set into a menu item causing
- * it to flash. The fix is to test for equality and
- * do nothing.
- */
- if (text.equals (string)) return;
- super.setText (string);
- if ((style & (SWT.ARROW | SWT.SEPARATOR)) != 0) return;
-
- /*
- * Bug in Linux. In certain contexts setting the label of a
- * CHECK or RADIO menu item to the empty string can cause a
- * GP. The fix is to set the menu label to a space in such
- * cases since it displays equivalently.
- */
- if (OS.IsLinux && (style & (SWT.CHECK | SWT.RADIO)) != 0) {
- if (string.length () == 0) string = " ";
- }
- char [] text = new char [string.length ()];
- string.getChars (0, text.length, text, 0);
- boolean accel = false;
- int i=0, j=0, mnemonic=0;
- while (i < text.length) {
- if (text [i] == '\t') {accel = true; break;};
- if ((text [j++] = text [i++]) == Mnemonic) {
- if (i == text.length) {continue;}
- if (text [i] == Mnemonic) {i++; continue;}
- if (mnemonic == 0) mnemonic = text [i];
- j--;
- }
- }
- byte [] buffer2;
- if (accel && ++i < text.length) {
- char [] accelText = new char [text.length - i];
- System.arraycopy (text, i, accelText, 0, accelText.length);
- /* Use the character encoding for the default locale */
- buffer2 = Converter.wcsToMbcs (null, accelText, true);
- } else {
- buffer2 = new byte [1];
- }
- int xmString2 = OS.XmStringParseText (
- buffer2,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- if (xmString2 == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- while (j < text.length) text [j++] = 0;
- /* Use the character encoding for the default locale */
- byte [] buffer1 = Converter.wcsToMbcs (null, text, true);
- int xmString1 = OS.XmStringParseText (
- buffer1,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- if (xmString1 == 0) error (SWT.ERROR_CANNOT_SET_TEXT);
- if (mnemonic == 0) mnemonic = OS.XK_VoidSymbol;
- int [] argList = {
- OS.XmNlabelType, OS.XmSTRING,
- OS.XmNlabelString, xmString1,
- OS.XmNmnemonic, mnemonic,
- OS.XmNacceleratorText, xmString2,
- };
- OS.XtSetValues (handle, argList, argList.length / 2);
- if (xmString1 != 0) OS.XmStringFree (xmString1);
- if (xmString2 != 0) OS.XmStringFree (xmString2);
-}
-boolean translateAccelerator (int accel) {
- if (!getEnabled ()) return false;
- if (menu != null) return menu.translateAccelerator (accel);
- int accelerator = this.accelerator;
- if ((accelerator & SWT.KEYCODE_BIT) == 0) {
- int key = accelerator & SWT.KEY_MASK;
- if ('A' <= key && key <= 'Z') {
- key += 'a' - 'A';
- }
- int mods = accelerator & SWT.MODIFIER_MASK;
- accelerator = mods | key;
- }
- if (accelerator == accel) {
- postEvent (SWT.Selection);
- return true;
- }
- return false;
-}
-int XmNactivateCallback (int w, int client_data, int call_data) {
- if ((style & SWT.CASCADE) != 0) {
- postEvent (SWT.Arm);
- }
- if (!isEnabled ()) return 0;
- XmAnyCallbackStruct struct = new XmAnyCallbackStruct ();
- OS.memmove (struct, call_data, XmAnyCallbackStruct.sizeof);
- Event event = new Event ();
- if (struct.event != 0) {
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, struct.event, XAnyEvent.sizeof);
- event.time = xEvent.time;
- switch (xEvent.type) {
- case OS.ButtonPress:
- case OS.ButtonRelease:
- case OS.KeyPress:
- case OS.KeyRelease:
- setInputState (event, xEvent);
- break;
- }
- }
- postEvent (SWT.Selection, event);
- return 0;
-}
-int XmNarmCallback (int w, int client_data, int call_data) {
- postEvent (SWT.Arm);
- return 0;
-}
-int XmNcascadingCallback (int w, int client_data, int call_data) {
- postEvent (SWT.Arm);
- return 0;
-}
-int XmNhelpCallback (int w, int client_data, int call_data) {
- if (hooks (SWT.Help)) {
- postEvent (SWT.Help);
- return 0;
- }
- parent.sendHelpEvent (call_data);
- return 0;
-}
-int XmNvalueChangedCallback (int w, int client_data, int call_data) {
- if (!isEnabled ()) return 0;
- XmAnyCallbackStruct struct = new XmAnyCallbackStruct ();
- OS.memmove (struct, call_data, XmAnyCallbackStruct.sizeof);
- Event event = new Event ();
- if (struct.event != 0) {
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, struct.event, XAnyEvent.sizeof);
- event.time = xEvent.time;
- switch (xEvent.type) {
- case OS.ButtonPress:
- case OS.ButtonRelease:
- case OS.KeyPress:
- case OS.KeyRelease:
- setInputState (event, xEvent);
- break;
- }
- }
- if ((style & SWT.RADIO) != 0) {
- if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) {
- selectRadio ();
- }
- }
- postEvent (SWT.Selection, event);
- return 0;
-}
-
-}
+public void setSelection (boolean selected) { + checkWidget(); + if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return; + int [] argList = {OS.XmNset, selected ? OS.XmSET : OS.XmUNSET}; + OS.XtSetValues (handle, argList, argList.length / 2); +} +public void setText (String string) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + /* + * Feature in Motif. Motif does not optimize the case + * when the same text is set into a menu item causing + * it to flash. The fix is to test for equality and + * do nothing. + */ + if (text.equals (string)) return; + super.setText (string); + if ((style & (SWT.ARROW | SWT.SEPARATOR)) != 0) return; + + /* + * Bug in Linux. In certain contexts setting the label of a + * CHECK or RADIO menu item to the empty string can cause a + * GP. The fix is to set the menu label to a space in such + * cases since it displays equivalently. + */ + if (OS.IsLinux && (style & (SWT.CHECK | SWT.RADIO)) != 0) { + if (string.length () == 0) string = " "; + } + char [] text = new char [string.length ()]; + string.getChars (0, text.length, text, 0); + boolean accel = false; + int i=0, j=0, mnemonic=0; + while (i < text.length) { + if (text [i] == '\t') {accel = true; break;}; + if ((text [j++] = text [i++]) == Mnemonic) { + if (i == text.length) {continue;} + if (text [i] == Mnemonic) {i++; continue;} + if (mnemonic == 0) mnemonic = text [i]; + j--; + } + } + byte [] buffer2; + if (accel && ++i < text.length) { + char [] accelText = new char [text.length - i]; + System.arraycopy (text, i, accelText, 0, accelText.length); + /* Use the character encoding for the default locale */ + buffer2 = Converter.wcsToMbcs (null, accelText, true); + } else { + buffer2 = new byte [1]; + } + int xmString2 = OS.XmStringParseText ( + buffer2, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + if (xmString2 == 0) error (SWT.ERROR_CANNOT_SET_TEXT); + while (j < text.length) text [j++] = 0; + /* Use the character encoding for the default locale */ + byte [] buffer1 = Converter.wcsToMbcs (null, text, true); + int xmString1 = OS.XmStringParseText ( + buffer1, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + if (xmString1 == 0) error (SWT.ERROR_CANNOT_SET_TEXT); + if (mnemonic == 0) mnemonic = OS.XK_VoidSymbol; + int [] argList = { + OS.XmNlabelType, OS.XmSTRING, + OS.XmNlabelString, xmString1, + OS.XmNmnemonic, mnemonic, + OS.XmNacceleratorText, xmString2, + }; + OS.XtSetValues (handle, argList, argList.length / 2); + if (xmString1 != 0) OS.XmStringFree (xmString1); + if (xmString2 != 0) OS.XmStringFree (xmString2); +} +boolean translateAccelerator (int accel) { + if (!getEnabled ()) return false; + if (menu != null) return menu.translateAccelerator (accel); + int accelerator = this.accelerator; + if ((accelerator & SWT.KEYCODE_BIT) == 0) { + int key = accelerator & SWT.KEY_MASK; + if ('A' <= key && key <= 'Z') { + key += 'a' - 'A'; + } + int mods = accelerator & SWT.MODIFIER_MASK; + accelerator = mods | key; + } + if (accelerator == accel) { + postEvent (SWT.Selection); + return true; + } + return false; +} +int XmNactivateCallback (int w, int client_data, int call_data) { + if ((style & SWT.CASCADE) != 0) { + postEvent (SWT.Arm); + } + if (!isEnabled ()) return 0; + XmAnyCallbackStruct struct = new XmAnyCallbackStruct (); + OS.memmove (struct, call_data, XmAnyCallbackStruct.sizeof); + Event event = new Event (); + if (struct.event != 0) { + XButtonEvent xEvent = new XButtonEvent (); + OS.memmove (xEvent, struct.event, XAnyEvent.sizeof); + event.time = xEvent.time; + switch (xEvent.type) { + case OS.ButtonPress: + case OS.ButtonRelease: + case OS.KeyPress: + case OS.KeyRelease: + setInputState (event, xEvent); + break; + } + } + postEvent (SWT.Selection, event); + return 0; +} +int XmNarmCallback (int w, int client_data, int call_data) { + postEvent (SWT.Arm); + return 0; +} +int XmNcascadingCallback (int w, int client_data, int call_data) { + postEvent (SWT.Arm); + return 0; +} +int XmNhelpCallback (int w, int client_data, int call_data) { + if (hooks (SWT.Help)) { + postEvent (SWT.Help); + return 0; + } + parent.sendHelpEvent (call_data); + return 0; +} +int XmNvalueChangedCallback (int w, int client_data, int call_data) { + if (!isEnabled ()) return 0; + XmAnyCallbackStruct struct = new XmAnyCallbackStruct (); + OS.memmove (struct, call_data, XmAnyCallbackStruct.sizeof); + Event event = new Event (); + if (struct.event != 0) { + XButtonEvent xEvent = new XButtonEvent (); + OS.memmove (xEvent, struct.event, XAnyEvent.sizeof); + event.time = xEvent.time; + switch (xEvent.type) { + case OS.ButtonPress: + case OS.ButtonRelease: + case OS.KeyPress: + case OS.KeyRelease: + setInputState (event, xEvent); + break; + } + } + if ((style & SWT.RADIO) != 0) { + if ((parent.getStyle () & SWT.NO_RADIO_GROUP) == 0) { + selectRadio (); + } + } + postEvent (SWT.Selection, event); + return 0; +} + +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java index d9609a1cfa..b2a2b8d0ab 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/MessageBox.java @@ -1,67 +1,67 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are used used to inform or warn the user.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, ICON_WARNING, ICON_WORKING</dd>
- * <dd>OK, OK | CANCEL</dd>
- * <dd>YES | NO, YES | NO | CANCEL</dd>
- * <dd>RETRY | CANCEL</dd>
- * <dd>ABORT | RETRY | IGNORE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION, ICON_QUESTION,
- * ICON_WARNING and ICON_WORKING may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html */ -public class MessageBox extends Dialog {
- int button;
- String message = "";
-
-/**
- * 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>
+ +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; + +/** + * Instances of this class are used used to inform or warn the user. + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, ICON_WARNING, ICON_WORKING</dd> + * <dd>OK, OK | CANCEL</dd> + * <dd>YES | NO, YES | NO | CANCEL</dd> + * <dd>RETRY | CANCEL</dd> + * <dd>ABORT | RETRY | IGNORE</dd> + * <dt><b>Events:</b></dt> + * <dd>(none)</dd> + * </dl> + * <p> + * Note: Only one of the styles ICON_ERROR, ICON_INFORMATION, ICON_QUESTION, + * ICON_WARNING and ICON_WORKING may be specified. + * </p><p> + * IMPORTANT: This class is intended to be subclassed <em>only</em> + * within the SWT implementation. + * </p> + */ +public class MessageBox extends Dialog { + int button; + String message = ""; + +/** + * 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);
-}
-
+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. @@ -92,322 +92,322 @@ public MessageBox (Shell parent) { * <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 ();
-}
-int activate (int widget, int client, int call) {
- OS.XtUnmanageChild (widget);
- button = client;
- return 0;
-}
-static int checkStyle (int style) {
- if ((style & (SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) == 0) style |= SWT.APPLICATION_MODAL;
- int mask = (SWT.YES | SWT.NO | SWT.OK | SWT.CANCEL | SWT.ABORT | SWT.RETRY | SWT.IGNORE);
- int bits = style & mask;
- if (bits == SWT.OK || bits == SWT.CANCEL || bits == (SWT.OK | SWT.CANCEL)) return style;
- if (bits == SWT.YES || bits == SWT.NO || bits == (SWT.YES | SWT.NO) || bits == (SWT.YES | SWT.NO | SWT.CANCEL)) return style;
- if (bits == (SWT.RETRY | SWT.CANCEL) || bits == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) return style;
- style = (style & ~mask) | SWT.OK;
- return style;
-}
-int createHandle (int parentHandle, int [] argList) {
- if ((style & SWT.ICON_ERROR) != 0) return OS.XmCreateErrorDialog (parentHandle, null, argList, argList.length / 2);
- if ((style & SWT.ICON_INFORMATION) != 0) return OS.XmCreateInformationDialog (parentHandle, null, argList, argList.length / 2);
- if ((style & SWT.ICON_QUESTION) != 0) return OS.XmCreateQuestionDialog (parentHandle, null, argList, argList.length / 2);
- if ((style & SWT.ICON_WARNING) != 0) return OS.XmCreateWarningDialog (parentHandle, null, argList, argList.length / 2);
- return OS.XmCreateMessageDialog (parentHandle, null, argList, argList.length / 2);
-}
-
-/**
- * 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 MessageBox (Shell parent, int style) { + super (parent, checkStyle (style)); + checkSubclass (); +} +int activate (int widget, int client, int call) { + OS.XtUnmanageChild (widget); + button = client; + return 0; +} +static int checkStyle (int style) { + if ((style & (SWT.PRIMARY_MODAL | SWT.APPLICATION_MODAL | SWT.SYSTEM_MODAL)) == 0) style |= SWT.APPLICATION_MODAL; + int mask = (SWT.YES | SWT.NO | SWT.OK | SWT.CANCEL | SWT.ABORT | SWT.RETRY | SWT.IGNORE); + int bits = style & mask; + if (bits == SWT.OK || bits == SWT.CANCEL || bits == (SWT.OK | SWT.CANCEL)) return style; + if (bits == SWT.YES || bits == SWT.NO || bits == (SWT.YES | SWT.NO) || bits == (SWT.YES | SWT.NO | SWT.CANCEL)) return style; + if (bits == (SWT.RETRY | SWT.CANCEL) || bits == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) return style; + style = (style & ~mask) | SWT.OK; + return style; +} +int createHandle (int parentHandle, int [] argList) { + if ((style & SWT.ICON_ERROR) != 0) return OS.XmCreateErrorDialog (parentHandle, null, argList, argList.length / 2); + if ((style & SWT.ICON_INFORMATION) != 0) return OS.XmCreateInformationDialog (parentHandle, null, argList, argList.length / 2); + if ((style & SWT.ICON_QUESTION) != 0) return OS.XmCreateQuestionDialog (parentHandle, null, argList, argList.length / 2); + if ((style & SWT.ICON_WARNING) != 0) return OS.XmCreateWarningDialog (parentHandle, null, argList, argList.length / 2); + return OS.XmCreateMessageDialog (parentHandle, null, argList, argList.length / 2); +} + +/** + * 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 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 String getMessage () { + return message; +} + +/** + * Makes the dialog visible and brings it to the front + * of the display. + * + * @return the ID of the button that was selected to dismiss the + * message box (e.g. SWT.OK, SWT.CANCEL, etc...) + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the dialog has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the dialog</li> + * </ul> */ -public int open () {
-
- /* Create the dialog.*/
- boolean destroyContext;
- Display appContext = Display.getCurrent ();
- if (destroyContext = (appContext == null)) appContext = new Display ();
- int parentHandle = appContext.shellHandle;
- if (parent != null && parent.getDisplay () == appContext)
- parentHandle = parent.shellHandle;
-
- /* Compute the dialog title */
- /*
- * Feature in Motif. It is not possible to set a shell
- * title to an empty string. The fix is to set the title
- * to be a single space.
- */
- String string = title;
- if (string.length () == 0) string = " ";
- /* Use the character encoding for the default locale */
- byte [] buffer = Converter.wcsToMbcs (null, string, true);
- int xmStringPtr = OS.XmStringParseText (
- buffer,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- /*
- * Feature in Motif. The modal values are only hints
- * to the window manager. For example Enlightenment treats all modes
- * as SWT.APPLICATION_MODAL. The generic Motif
- * Window Manager honours all modes.
- */
- int dialogStyle = OS.XmDIALOG_MODELESS;
- if ((style & SWT.PRIMARY_MODAL) != 0) dialogStyle = OS.XmDIALOG_PRIMARY_APPLICATION_MODAL;
- if ((style & SWT.APPLICATION_MODAL) != 0) dialogStyle = OS.XmDIALOG_FULL_APPLICATION_MODAL;
- if ((style & SWT.SYSTEM_MODAL) != 0) dialogStyle = OS.XmDIALOG_SYSTEM_MODAL;
- if (parent != null && dialogStyle == OS.XmDIALOG_MODELESS) {
- dialogStyle = OS.XmDIALOG_PRIMARY_APPLICATION_MODAL;
- }
- int [] argList = {
- OS.XmNnoResize, 1,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNdialogStyle, dialogStyle,
- OS.XmNdialogTitle, xmStringPtr,
- };
- int dialog = createHandle (parentHandle, argList);
- OS.XmStringFree (xmStringPtr);
- setMessage (dialog);
- setButtons (dialog);
-
- /* Hook the callbacks. */
- Callback callback = new Callback (this, "activate", 3);
- int address = callback.getAddress ();
- OS.XtAddCallback (dialog, OS.XmNokCallback, address, OS.XmDIALOG_OK_BUTTON);
- OS.XtAddCallback (dialog, OS.XmNcancelCallback, address, OS.XmDIALOG_CANCEL_BUTTON);
- OS.XtAddCallback (dialog, OS.XmNhelpCallback, address, OS.XmDIALOG_HELP_BUTTON);
-
- /* Open the dialog and dispatch events. */
- OS.XtManageChild (dialog);
-
- // Should be a pure OS message loop (no SWT AppContext)
- while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog))
- if (!appContext.readAndDispatch()) appContext.sleep ();
-
- /* Destroy the dialog and update the display. */
- if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog);
- if (destroyContext) appContext.dispose ();
- callback.dispose ();
-
- if ((style & (SWT.YES | SWT.NO | SWT.CANCEL)) == (SWT.YES | SWT.NO | SWT.CANCEL)) {
- if (button == OS.XmDIALOG_OK_BUTTON) return SWT.YES;
- if (button == OS.XmDIALOG_CANCEL_BUTTON) return SWT.NO;
- return SWT.CANCEL;
- };
- if ((style & (SWT.YES | SWT.NO)) == (SWT.YES | SWT.NO)) {
- return (button == OS.XmDIALOG_OK_BUTTON) ? SWT.YES : SWT.NO;
- }
- if ((style & (SWT.OK | SWT.CANCEL)) == (SWT.OK | SWT.CANCEL)) {
- return (button == OS.XmDIALOG_OK_BUTTON) ? SWT.OK : SWT.CANCEL;
- }
- if ((style & SWT.OK) == SWT.OK) return SWT.OK;
- if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) {
- return (button == OS.XmDIALOG_OK_BUTTON) ? SWT.RETRY : SWT.CANCEL;
- }
- if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) {
- if (button == OS.XmDIALOG_OK_BUTTON) return SWT.ABORT;
- if (button == OS.XmDIALOG_CANCEL_BUTTON) return SWT.RETRY;
- return SWT.IGNORE;
- }
- return SWT.CANCEL;
-}
-void setButtons (int dialogHandle) {
-
- /* Get the button children */
- OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_OK_BUTTON);
- int cancel = OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_CANCEL_BUTTON);
- int help = OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_HELP_BUTTON);
- OS.XtUnmanageChild (help);
-
- /* Set the button labels */
- if ((style & (SWT.OK | SWT.CANCEL)) == (SWT.OK | SWT.CANCEL)) return;
- if ((style & SWT.OK) == SWT.OK) {
- OS.XtUnmanageChild (cancel);
- return;
- }
- if ((style & (SWT.YES | SWT.NO | SWT.CANCEL)) == (SWT.YES | SWT.NO | SWT.CANCEL)) {
- OS.XtManageChild (help);
- /* Use the character encoding for the default locale */
- byte [] buffer1 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Yes"), true);
- int xmString1 = OS.XmStringParseText (
- buffer1,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- /* Use the character encoding for the default locale */
- byte [] buffer2 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_No"), true);
- int xmString2 = OS.XmStringParseText (
- buffer2,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- /* Use the character encoding for the default locale */
- byte [] buffer3 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Cancel"), true);
- int xmString3 = OS.XmStringParseText (
- buffer3,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2, OS.XmNhelpLabelString, xmString3};
- OS.XtSetValues (dialogHandle, argList, argList.length / 2);
- OS.XmStringFree (xmString1); OS.XmStringFree (xmString2); OS.XmStringFree (xmString3);
- return;
- }
- if ((style & (SWT.YES | SWT.NO)) == (SWT.YES | SWT.NO)) {
- /* Use the character encoding for the default locale */
- byte [] buffer1 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Yes"), true);
- int xmString1 = OS.XmStringParseText (
- buffer1,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- /* Use the character encoding for the default locale */
- byte [] buffer2 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_No"), true);
- int xmString2 = OS.XmStringParseText (
- buffer2,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2};
- OS.XtSetValues (dialogHandle, argList, argList.length / 2);
- OS.XmStringFree (xmString1); OS.XmStringFree (xmString2);
- return;
- }
- if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) {
- /* Use the character encoding for the default locale */
- byte [] buffer1 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Retry"), true);
- int xmString1 = OS.XmStringParseText (
- buffer1,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- /* Use the character encoding for the default locale */
- byte [] buffer2 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Cancel"), true);
- int xmString2 = OS.XmStringParseText (
- buffer2,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2};
- OS.XtSetValues (dialogHandle, argList, argList.length / 2);
- OS.XmStringFree (xmString1); OS.XmStringFree (xmString2);
- return;
- }
- if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) {
- OS.XtManageChild (help);
- /* Use the character encoding for the default locale */
- byte [] buffer1 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Abort"), true);
- int xmString1 = OS.XmStringParseText (
- buffer1,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- /* Use the character encoding for the default locale */
- byte [] buffer2 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Retry"), true);
- int xmString2 = OS.XmStringParseText (
- buffer2,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- /* Use the character encoding for the default locale */
- byte [] buffer3 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Ignore"), true);
- int xmString3 = OS.XmStringParseText (
- buffer3,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2, OS.XmNhelpLabelString, xmString3};
- OS.XtSetValues (dialogHandle, argList, argList.length / 2);
- OS.XmStringFree (xmString1); OS.XmStringFree (xmString2); OS.XmStringFree (xmString3);
- return;
- }
-}
-void setMessage (int dialogHandle) {
- String text = message;
- int label = OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_MESSAGE_LABEL);
- if (label != 0) {
- int [] argList = {OS.XmNfontList, 0};
- OS.XtGetValues (label, argList, argList.length / 2);
- int fontList = argList [1];
- if (fontList != 0) {
- Display display = parent.getDisplay ();
- int xDisplay = display.xDisplay;
- int screen = OS.XDefaultScreen (xDisplay);
- int width = OS.XDisplayWidth (xDisplay, screen);
- Font font = Font.motif_new (display, fontList);
- text = display.wrapText (message, font, width * 3 / 5);
- }
- }
- /* Use the character encoding for the default locale */
- byte [] buffer = Converter.wcsToMbcs (null, text, true);
- int xmString = OS.XmStringGenerate(buffer, null, OS.XmCHARSET_TEXT, null);
- int [] argList = {OS.XmNmessageString, xmString};
- OS.XtSetValues (dialogHandle, argList, argList.length / 2);
- OS.XmStringFree (xmString);
-}
-
-/**
- * Sets the dialog's message, which is a description of
- * the purpose for which it was opened. This message will be
- * visible on the dialog while it is open.
- *
- * @param string the message
+public int open () { + + /* Create the dialog.*/ + boolean destroyContext; + Display appContext = Display.getCurrent (); + if (destroyContext = (appContext == null)) appContext = new Display (); + int parentHandle = appContext.shellHandle; + if (parent != null && parent.getDisplay () == appContext) + parentHandle = parent.shellHandle; + + /* Compute the dialog title */ + /* + * Feature in Motif. It is not possible to set a shell + * title to an empty string. The fix is to set the title + * to be a single space. + */ + String string = title; + if (string.length () == 0) string = " "; + /* Use the character encoding for the default locale */ + byte [] buffer = Converter.wcsToMbcs (null, string, true); + int xmStringPtr = OS.XmStringParseText ( + buffer, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + /* + * Feature in Motif. The modal values are only hints + * to the window manager. For example Enlightenment treats all modes + * as SWT.APPLICATION_MODAL. The generic Motif + * Window Manager honours all modes. + */ + int dialogStyle = OS.XmDIALOG_MODELESS; + if ((style & SWT.PRIMARY_MODAL) != 0) dialogStyle = OS.XmDIALOG_PRIMARY_APPLICATION_MODAL; + if ((style & SWT.APPLICATION_MODAL) != 0) dialogStyle = OS.XmDIALOG_FULL_APPLICATION_MODAL; + if ((style & SWT.SYSTEM_MODAL) != 0) dialogStyle = OS.XmDIALOG_SYSTEM_MODAL; + if (parent != null && dialogStyle == OS.XmDIALOG_MODELESS) { + dialogStyle = OS.XmDIALOG_PRIMARY_APPLICATION_MODAL; + } + int [] argList = { + OS.XmNnoResize, 1, + OS.XmNresizePolicy, OS.XmRESIZE_NONE, + OS.XmNdialogStyle, dialogStyle, + OS.XmNdialogTitle, xmStringPtr, + }; + int dialog = createHandle (parentHandle, argList); + OS.XmStringFree (xmStringPtr); + setMessage (dialog); + setButtons (dialog); + + /* Hook the callbacks. */ + Callback callback = new Callback (this, "activate", 3); + int address = callback.getAddress (); + OS.XtAddCallback (dialog, OS.XmNokCallback, address, OS.XmDIALOG_OK_BUTTON); + OS.XtAddCallback (dialog, OS.XmNcancelCallback, address, OS.XmDIALOG_CANCEL_BUTTON); + OS.XtAddCallback (dialog, OS.XmNhelpCallback, address, OS.XmDIALOG_HELP_BUTTON); + + /* Open the dialog and dispatch events. */ + OS.XtManageChild (dialog); + + // Should be a pure OS message loop (no SWT AppContext) + while (OS.XtIsRealized (dialog) && OS.XtIsManaged (dialog)) + if (!appContext.readAndDispatch()) appContext.sleep (); + + /* Destroy the dialog and update the display. */ + if (OS.XtIsRealized (dialog)) OS.XtDestroyWidget (dialog); + if (destroyContext) appContext.dispose (); + callback.dispose (); + + if ((style & (SWT.YES | SWT.NO | SWT.CANCEL)) == (SWT.YES | SWT.NO | SWT.CANCEL)) { + if (button == OS.XmDIALOG_OK_BUTTON) return SWT.YES; + if (button == OS.XmDIALOG_CANCEL_BUTTON) return SWT.NO; + return SWT.CANCEL; + }; + if ((style & (SWT.YES | SWT.NO)) == (SWT.YES | SWT.NO)) { + return (button == OS.XmDIALOG_OK_BUTTON) ? SWT.YES : SWT.NO; + } + if ((style & (SWT.OK | SWT.CANCEL)) == (SWT.OK | SWT.CANCEL)) { + return (button == OS.XmDIALOG_OK_BUTTON) ? SWT.OK : SWT.CANCEL; + } + if ((style & SWT.OK) == SWT.OK) return SWT.OK; + if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) { + return (button == OS.XmDIALOG_OK_BUTTON) ? SWT.RETRY : SWT.CANCEL; + } + if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) { + if (button == OS.XmDIALOG_OK_BUTTON) return SWT.ABORT; + if (button == OS.XmDIALOG_CANCEL_BUTTON) return SWT.RETRY; + return SWT.IGNORE; + } + return SWT.CANCEL; +} +void setButtons (int dialogHandle) { + + /* Get the button children */ + OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_OK_BUTTON); + int cancel = OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_CANCEL_BUTTON); + int help = OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_HELP_BUTTON); + OS.XtUnmanageChild (help); + + /* Set the button labels */ + if ((style & (SWT.OK | SWT.CANCEL)) == (SWT.OK | SWT.CANCEL)) return; + if ((style & SWT.OK) == SWT.OK) { + OS.XtUnmanageChild (cancel); + return; + } + if ((style & (SWT.YES | SWT.NO | SWT.CANCEL)) == (SWT.YES | SWT.NO | SWT.CANCEL)) { + OS.XtManageChild (help); + /* Use the character encoding for the default locale */ + byte [] buffer1 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Yes"), true); + int xmString1 = OS.XmStringParseText ( + buffer1, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + /* Use the character encoding for the default locale */ + byte [] buffer2 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_No"), true); + int xmString2 = OS.XmStringParseText ( + buffer2, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + /* Use the character encoding for the default locale */ + byte [] buffer3 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Cancel"), true); + int xmString3 = OS.XmStringParseText ( + buffer3, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2, OS.XmNhelpLabelString, xmString3}; + OS.XtSetValues (dialogHandle, argList, argList.length / 2); + OS.XmStringFree (xmString1); OS.XmStringFree (xmString2); OS.XmStringFree (xmString3); + return; + } + if ((style & (SWT.YES | SWT.NO)) == (SWT.YES | SWT.NO)) { + /* Use the character encoding for the default locale */ + byte [] buffer1 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Yes"), true); + int xmString1 = OS.XmStringParseText ( + buffer1, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + /* Use the character encoding for the default locale */ + byte [] buffer2 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_No"), true); + int xmString2 = OS.XmStringParseText ( + buffer2, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2}; + OS.XtSetValues (dialogHandle, argList, argList.length / 2); + OS.XmStringFree (xmString1); OS.XmStringFree (xmString2); + return; + } + if ((style & (SWT.RETRY | SWT.CANCEL)) == (SWT.RETRY | SWT.CANCEL)) { + /* Use the character encoding for the default locale */ + byte [] buffer1 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Retry"), true); + int xmString1 = OS.XmStringParseText ( + buffer1, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + /* Use the character encoding for the default locale */ + byte [] buffer2 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Cancel"), true); + int xmString2 = OS.XmStringParseText ( + buffer2, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2}; + OS.XtSetValues (dialogHandle, argList, argList.length / 2); + OS.XmStringFree (xmString1); OS.XmStringFree (xmString2); + return; + } + if ((style & (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) == (SWT.ABORT | SWT.RETRY | SWT.IGNORE)) { + OS.XtManageChild (help); + /* Use the character encoding for the default locale */ + byte [] buffer1 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Abort"), true); + int xmString1 = OS.XmStringParseText ( + buffer1, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + /* Use the character encoding for the default locale */ + byte [] buffer2 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Retry"), true); + int xmString2 = OS.XmStringParseText ( + buffer2, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + /* Use the character encoding for the default locale */ + byte [] buffer3 = Converter.wcsToMbcs (null, SWT.getMessage("SWT_Ignore"), true); + int xmString3 = OS.XmStringParseText ( + buffer3, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + int [] argList = {OS.XmNokLabelString, xmString1, OS.XmNcancelLabelString, xmString2, OS.XmNhelpLabelString, xmString3}; + OS.XtSetValues (dialogHandle, argList, argList.length / 2); + OS.XmStringFree (xmString1); OS.XmStringFree (xmString2); OS.XmStringFree (xmString3); + return; + } +} +void setMessage (int dialogHandle) { + String text = message; + int label = OS.XmMessageBoxGetChild (dialogHandle, OS.XmDIALOG_MESSAGE_LABEL); + if (label != 0) { + int [] argList = {OS.XmNfontList, 0}; + OS.XtGetValues (label, argList, argList.length / 2); + int fontList = argList [1]; + if (fontList != 0) { + Display display = parent.getDisplay (); + int xDisplay = display.xDisplay; + int screen = OS.XDefaultScreen (xDisplay); + int width = OS.XDisplayWidth (xDisplay, screen); + Font font = Font.motif_new (display, fontList); + text = display.wrapText (message, font, width * 3 / 5); + } + } + /* Use the character encoding for the default locale */ + byte [] buffer = Converter.wcsToMbcs (null, text, true); + int xmString = OS.XmStringGenerate(buffer, null, OS.XmCHARSET_TEXT, null); + int [] argList = {OS.XmNmessageString, xmString}; + OS.XtSetValues (dialogHandle, argList, argList.length / 2); + OS.XmStringFree (xmString); +} + +/** + * Sets the dialog's message, which is a description of + * the purpose for which it was opened. This message will be + * visible on the dialog while it is open. + * + * @param string the message */ -public void setMessage (String string) {
- message = string;
-}
-}
+public void setMessage (String string) { + message = string; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java index a49debf6f5..d1a5fca885 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ProgressBar.java @@ -1,38 +1,38 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-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>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html */ -public class ProgressBar extends Control {
- int timerId;
- static final int DELAY = 100;
- int lastForeground = defaultForeground ();
-
+ +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +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> + * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. + * </p><p> + * IMPORTANT: This class is intended to be subclassed <em>only</em> + * within the SWT implementation. + * </p> + */ +public class ProgressBar extends Control { + int timerId; + static final int DELAY = 100; + int lastForeground = defaultForeground (); + /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -63,329 +63,329 @@ public class ProgressBar extends Control { * @see Widget#checkSubclass * @see Widget#getStyle */ -public ProgressBar (Composite parent, int style) {
- /*
- * Feature in Motif. If you set the progress bar's value to 0,
- * the thumb does not disappear. In order to make this happen,
- * we hide the widget when the value is set to zero by changing
- * its colors to render it invisible, which means that it
- * would not visible unless a border is present. The fix is to
- * always ensure that there is a border, which will be drawn
- * even when the value is 0.
- */
- super (parent, checkStyle (style | SWT.BORDER));
-}
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- Display display = getDisplay ();
- int hScroll = display.scrolledMarginX;
- int vScroll = display.scrolledMarginY;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += hScroll * 10;
- height += vScroll;
- } else {
- width += hScroll;
- height += vScroll * 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-void createHandle (int index) {
- state |= HANDLE;
- int background = defaultBackground ();
- int parentHandle = parent.handle;
- int [] argList = {
- OS.XmNshowArrows, 0,
- OS.XmNsliderSize, 1,
- OS.XmNtraversalOn, 0,
- OS.XmNtroughColor, background,
- OS.XmNtopShadowColor, background,
- OS.XmNbottomShadowColor, background,
- OS.XmNforeground, background,
- OS.XmNshadowThickness, 1,
- OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0,
- OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL,
- OS.XmNprocessingDirection, ((style & SWT.H_SCROLL) != 0) ? OS.XmMAX_ON_RIGHT : OS.XmMAX_ON_TOP,
- OS.XmNancestorSensitive, 1,
- OS.XmNsliderVisual, OS.XmFOREGROUND_COLOR,
- };
- handle = OS.XmCreateScrollBar (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- if ((style & SWT.INDETERMINATE) != 0) createTimer ();
-}
-void createTimer () {
- Display display = getDisplay ();
- int xDisplay = display.xDisplay;
- int windowTimerProc = display.windowTimerProc;
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
- timerId = OS.XtAppAddTimeOut (xtContext, DELAY, windowTimerProc, handle);
-}
-void destroyTimer () {
- if (timerId != 0) OS.XtRemoveTimeOut (timerId);
- timerId = 0;
-}
-void disableButtonPress () {
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int event_mask = OS.XtBuildEventMask (handle);
- XSetWindowAttributes attributes = new XSetWindowAttributes ();
- attributes.event_mask = event_mask & ~OS.ButtonPressMask;
- OS.XChangeWindowAttributes (xDisplay, xWindow, OS.CWEventMask, attributes);
-}
-int getForegroundPixel () {
- boolean invisible = lastForeground != -1;
- if (invisible) return lastForeground;
- return super.getForegroundPixel ();
-}
-/**
- * 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 ProgressBar (Composite parent, int style) { + /* + * Feature in Motif. If you set the progress bar's value to 0, + * the thumb does not disappear. In order to make this happen, + * we hide the widget when the value is set to zero by changing + * its colors to render it invisible, which means that it + * would not visible unless a border is present. The fix is to + * always ensure that there is a border, which will be drawn + * even when the value is 0. + */ + super (parent, checkStyle (style | SWT.BORDER)); +} +static int checkStyle (int style) { + return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0); +} +public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget(); + int border = getBorderWidth (); + int width = border * 2, height = border * 2; + Display display = getDisplay (); + int hScroll = display.scrolledMarginX; + int vScroll = display.scrolledMarginY; + if ((style & SWT.HORIZONTAL) != 0) { + width += hScroll * 10; + height += vScroll; + } else { + width += hScroll; + height += vScroll * 10; + } + if (wHint != SWT.DEFAULT) width = wHint + (border * 2); + if (hHint != SWT.DEFAULT) height = hHint + (border * 2); + return new Point (width, height); +} +void createHandle (int index) { + state |= HANDLE; + int background = defaultBackground (); + int parentHandle = parent.handle; + int [] argList = { + OS.XmNshowArrows, 0, + OS.XmNsliderSize, 1, + OS.XmNtraversalOn, 0, + OS.XmNtroughColor, background, + OS.XmNtopShadowColor, background, + OS.XmNbottomShadowColor, background, + OS.XmNforeground, background, + OS.XmNshadowThickness, 1, + OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0, + OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL, + OS.XmNprocessingDirection, ((style & SWT.H_SCROLL) != 0) ? OS.XmMAX_ON_RIGHT : OS.XmMAX_ON_TOP, + OS.XmNancestorSensitive, 1, + OS.XmNsliderVisual, OS.XmFOREGROUND_COLOR, + }; + handle = OS.XmCreateScrollBar (parentHandle, null, argList, argList.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + if ((style & SWT.INDETERMINATE) != 0) createTimer (); +} +void createTimer () { + Display display = getDisplay (); + int xDisplay = display.xDisplay; + int windowTimerProc = display.windowTimerProc; + int xtContext = OS.XtDisplayToApplicationContext (xDisplay); + timerId = OS.XtAppAddTimeOut (xtContext, DELAY, windowTimerProc, handle); +} +void destroyTimer () { + if (timerId != 0) OS.XtRemoveTimeOut (timerId); + timerId = 0; +} +void disableButtonPress () { + int xWindow = OS.XtWindow (handle); + if (xWindow == 0) return; + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return; + int event_mask = OS.XtBuildEventMask (handle); + XSetWindowAttributes attributes = new XSetWindowAttributes (); + attributes.event_mask = event_mask & ~OS.ButtonPressMask; + OS.XChangeWindowAttributes (xDisplay, xWindow, OS.CWEventMask, attributes); +} +int getForegroundPixel () { + boolean invisible = lastForeground != -1; + if (invisible) return lastForeground; + return super.getForegroundPixel (); +} +/** + * Returns the maximum value which the receiver will allow. + * + * @return the maximum + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getMaximum () {
- checkWidget();
- int [] argList = {OS.XmNmaximum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getMaximum () { + checkWidget(); + int [] argList = {OS.XmNmaximum, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns the minimum value which the receiver will allow. + * + * @return the minimum + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public int getMinimum () { + checkWidget(); + int [] argList = {OS.XmNminimum, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns the single <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 [] argList = { + OS.XmNminimum, 0, + OS.XmNsliderSize, 0, + }; + OS.XtGetValues (handle, argList, argList.length / 2); + int minimum = argList [1], sliderSize = argList [3]; + boolean invisible = lastForeground != -1; + if (invisible) sliderSize = 0; + return minimum + sliderSize; +} +void propagateWidget (boolean enabled) { + super.propagateWidget (enabled); + if (enabled) disableButtonPress (); +} +void realizeChildren () { + super.realizeChildren (); + disableButtonPress (); +} +void releaseWidget () { + super.releaseWidget (); + destroyTimer (); +} +/** + * 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 int getMinimum () {
- checkWidget();
- int [] argList = {OS.XmNminimum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * 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 void setBackground (Color color) { + checkWidget(); + super.setBackground (color); + boolean invisible = lastForeground != -1; + if (invisible) { + int [] argList = { + OS.XmNtroughColor, 0 + }; + OS.XtGetValues (handle, argList, argList.length / 2); + setForegroundPixel (argList [1]); + } +} + +/** + * 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 int getSelection () {
- checkWidget();
- int [] argList = {
- OS.XmNminimum, 0,
- OS.XmNsliderSize, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int minimum = argList [1], sliderSize = argList [3];
- boolean invisible = lastForeground != -1;
- if (invisible) sliderSize = 0;
- return minimum + sliderSize;
-}
-void propagateWidget (boolean enabled) {
- super.propagateWidget (enabled);
- if (enabled) disableButtonPress ();
-}
-void realizeChildren () {
- super.realizeChildren ();
- disableButtonPress ();
-}
-void releaseWidget () {
- super.releaseWidget ();
- destroyTimer ();
-}
-/**
- * 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) {
- checkWidget();
- super.setBackground (color);
- boolean invisible = lastForeground != -1;
- if (invisible) {
- int [] argList = {
- OS.XmNtroughColor, 0
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- setForegroundPixel (argList [1]);
- }
-}
-
-/**
- * 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) {
- checkWidget();
- boolean invisible = lastForeground != -1;
- if (invisible) {
- lastForeground = color.handle.pixel;
- } else {
- super.setForeground (color);
- }
-}
-/**
- * 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 setForeground (Color color) { + checkWidget(); + boolean invisible = lastForeground != -1; + if (invisible) { + lastForeground = color.handle.pixel; + } else { + super.setForeground (color); + } +} +/** + * 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 [] argList = {OS.XmNmaximum, value, OS.XmNvalue, 0};
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * 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 setMaximum (int value) { + checkWidget(); + if (value < 0) return; + int [] argList = {OS.XmNmaximum, value, OS.XmNvalue, 0}; + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XtSetValues (handle, argList, argList.length / 2); + display.setWarnings (warnings); +} +/** + * 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 [] argList = {
- OS.XmNminimum, 0,
- OS.XmNmaximum, 0,
- OS.XmNsliderSize, 0,
- OS.XmNvalue, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int minimum = argList [1];
- int maximum = argList [3];
- int sliderSize = argList [5];
-
- if (value >= maximum) return;
- int selection = sliderSize + minimum;
- if (value > selection) selection = value;
- argList [1] = value;
- argList [7] = value;
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
- setThumb(selection - value);
-}
-/**
- * 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 setMinimum (int value) { + checkWidget(); + if (value < 0) return; + int [] argList = { + OS.XmNminimum, 0, + OS.XmNmaximum, 0, + OS.XmNsliderSize, 0, + OS.XmNvalue, 0, + }; + OS.XtGetValues (handle, argList, argList.length / 2); + int minimum = argList [1]; + int maximum = argList [3]; + int sliderSize = argList [5]; + + if (value >= maximum) return; + int selection = sliderSize + minimum; + if (value > selection) selection = value; + argList [1] = value; + argList [7] = value; + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XtSetValues (handle, argList, argList.length / 2); + display.setWarnings (warnings); + setThumb(selection - value); +} +/** + * 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 value) {
- checkWidget();
- int [] argList = {
- OS.XmNminimum, 0,
- OS.XmNmaximum, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int minimum = argList [1];
- int maximum = argList [3];
-
- int selection = value;
- if (selection < minimum) selection = minimum;
- if (selection > maximum) selection = maximum;
- setThumb(selection - minimum);
-}
-void setThumb (int sliderSize) {
- int [] argList1 = new int [] {
- OS.XmNtroughColor, 0,
- OS.XmNminimum, 0,
- };
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int troughColor = argList1 [1];
-
- boolean invisible = lastForeground != -1;
- if (sliderSize == 0) {
- if (!invisible) {
- lastForeground = getForegroundPixel ();
- setForegroundPixel (troughColor);
- }
- } else {
- if (invisible) {
- setForegroundPixel (lastForeground);
- lastForeground = -1;
- }
- }
- int [] argList2 = new int [] {
- OS.XmNsliderSize, (sliderSize == 0) ? 1 : sliderSize,
- OS.XmNvalue, argList1 [3]
- };
-
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- display.setWarnings (warnings);
-}
-int timerProc (int id) {
- int minimum = getMinimum ();
- int range = getMaximum () - minimum + 1;
- int value = getSelection () - minimum + 1;
- setSelection (minimum + (value % range));
- createTimer ();
- return 0;
-}
-}
+public void setSelection (int value) { + checkWidget(); + int [] argList = { + OS.XmNminimum, 0, + OS.XmNmaximum, 0, + }; + OS.XtGetValues (handle, argList, argList.length / 2); + int minimum = argList [1]; + int maximum = argList [3]; + + int selection = value; + if (selection < minimum) selection = minimum; + if (selection > maximum) selection = maximum; + setThumb(selection - minimum); +} +void setThumb (int sliderSize) { + int [] argList1 = new int [] { + OS.XmNtroughColor, 0, + OS.XmNminimum, 0, + }; + OS.XtGetValues (handle, argList1, argList1.length / 2); + int troughColor = argList1 [1]; + + boolean invisible = lastForeground != -1; + if (sliderSize == 0) { + if (!invisible) { + lastForeground = getForegroundPixel (); + setForegroundPixel (troughColor); + } + } else { + if (invisible) { + setForegroundPixel (lastForeground); + lastForeground = -1; + } + } + int [] argList2 = new int [] { + OS.XmNsliderSize, (sliderSize == 0) ? 1 : sliderSize, + OS.XmNvalue, argList1 [3] + }; + + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XtSetValues (handle, argList2, argList2.length / 2); + display.setWarnings (warnings); +} +int timerProc (int id) { + int minimum = getMinimum (); + int range = getMaximum () - minimum + 1; + int value = getSelection () - minimum + 1; + setSelection (minimum + (value % range)); + createTimer (); + return 0; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java index a6974f77c4..198d9fbbbe 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Sash.java @@ -1,17 +1,17 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.events.*; + /** * Instances of the receiver represent a selectable user interface object * that allows the user to drag a rubber banded outline of the sash within @@ -29,15 +29,15 @@ import org.eclipse.swt.events.*; * within the SWT implementation. * </p> */ -public class Sash extends Control {
- boolean dragging;
- int startX, startY, lastX, lastY;
- int cursor;
-
- // constants
- private final static int INCREMENT = 1;
- private final static int PAGE_INCREMENT = 9;
-
+public class Sash extends Control { + boolean dragging; + int startX, startY, lastX, lastY; + int cursor; + + // constants + private final static int INCREMENT = 1; + private final static int PAGE_INCREMENT = 9; + /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -67,344 +67,344 @@ public class Sash extends Control { * @see Widget#checkSubclass * @see Widget#getStyle */ -public Sash (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected, by 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 Sash (Composite parent, int style) { + super (parent, checkStyle (style)); +} + +/** + * Adds the listener to the collection of listeners who will + * be notified when the control is selected, by 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) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-static int checkStyle (int style) {
- return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += DEFAULT_WIDTH; height += 3;
- } else {
- width += 3; height += DEFAULT_HEIGHT;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-void createHandle (int index) {
- state |= HANDLE;
- int border = (style & SWT.BORDER) != 0 ? 1 : 0;
- int [] argList = {
- OS.XmNborderWidth, border,
- OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0,
- OS.XmNresizePolicy, OS.XmRESIZE_NONE,
- OS.XmNancestorSensitive, 1,
- OS.XmNtraversalOn, 0,
- };
- int parentHandle = parent.handle;
- handle = OS.XmCreateDrawingArea (parentHandle, null, argList, argList.length / 2);
-}
-void drawBand (int x, int y, int width, int height) {
- int display = OS.XtDisplay (parent.handle);
- if (display == 0) return;
- int window = OS.XtWindow (parent.handle);
- if (window == 0) return;
- int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0};
- OS.XtGetValues (parent.handle, argList, argList.length / 2);
- int color = argList [1] ^ argList [3];
- byte [] bits = {-86, 85, -86, 85, -86, 85, -86, 85};
- int stipplePixmap = OS.XCreateBitmapFromData (display, window, bits, 8, 8);
- int gc = OS.XCreateGC (display, window, 0, null);
- OS.XSetForeground (display, gc, color);
- OS.XSetStipple (display, gc, stipplePixmap);
- OS.XSetSubwindowMode (display, gc, OS.IncludeInferiors);
- OS.XSetFillStyle (display, gc, OS.FillStippled);
- OS.XSetFunction (display, gc, OS.GXxor);
- OS.XFillRectangle (display, window, gc, x, y, width, height);
- OS.XFreePixmap (display, stipplePixmap);
- OS.XFreeGC (display, gc);
-}
-void realizeChildren () {
- super.realizeChildren ();
- int window = OS.XtWindow (handle);
- if (window == 0) return;
- int display = OS.XtDisplay (handle);
- if (display == 0) return;
- if ((style & SWT.HORIZONTAL) != 0) {
- cursor = OS.XCreateFontCursor (display, OS.XC_sb_v_double_arrow);
- } else {
- cursor = OS.XCreateFontCursor (display, OS.XC_sb_h_double_arrow);
- }
- OS.XDefineCursor (display, window, cursor);
-}
-void releaseWidget () {
- super.releaseWidget ();
- if (cursor != 0) {
- int display = OS.XtDisplay (handle);
- if (display != 0) OS.XFreeCursor (display, cursor);
- }
- cursor = 0;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected.
- *
- * @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 addSelectionListener(SelectionListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener(listener); + addListener(SWT.Selection,typedListener); + addListener(SWT.DefaultSelection,typedListener); +} +static int checkStyle (int style) { + return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0); +} +public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget(); + int border = getBorderWidth (); + int width = border * 2, height = border * 2; + if ((style & SWT.HORIZONTAL) != 0) { + width += DEFAULT_WIDTH; height += 3; + } else { + width += 3; height += DEFAULT_HEIGHT; + } + if (wHint != SWT.DEFAULT) width = wHint + (border * 2); + if (hHint != SWT.DEFAULT) height = hHint + (border * 2); + return new Point (width, height); +} +void createHandle (int index) { + state |= HANDLE; + int border = (style & SWT.BORDER) != 0 ? 1 : 0; + int [] argList = { + OS.XmNborderWidth, border, + OS.XmNmarginWidth, 0, + OS.XmNmarginHeight, 0, + OS.XmNresizePolicy, OS.XmRESIZE_NONE, + OS.XmNancestorSensitive, 1, + OS.XmNtraversalOn, 0, + }; + int parentHandle = parent.handle; + handle = OS.XmCreateDrawingArea (parentHandle, null, argList, argList.length / 2); +} +void drawBand (int x, int y, int width, int height) { + int display = OS.XtDisplay (parent.handle); + if (display == 0) return; + int window = OS.XtWindow (parent.handle); + if (window == 0) return; + int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0}; + OS.XtGetValues (parent.handle, argList, argList.length / 2); + int color = argList [1] ^ argList [3]; + byte [] bits = {-86, 85, -86, 85, -86, 85, -86, 85}; + int stipplePixmap = OS.XCreateBitmapFromData (display, window, bits, 8, 8); + int gc = OS.XCreateGC (display, window, 0, null); + OS.XSetForeground (display, gc, color); + OS.XSetStipple (display, gc, stipplePixmap); + OS.XSetSubwindowMode (display, gc, OS.IncludeInferiors); + OS.XSetFillStyle (display, gc, OS.FillStippled); + OS.XSetFunction (display, gc, OS.GXxor); + OS.XFillRectangle (display, window, gc, x, y, width, height); + OS.XFreePixmap (display, stipplePixmap); + OS.XFreeGC (display, gc); +} +void realizeChildren () { + super.realizeChildren (); + int window = OS.XtWindow (handle); + if (window == 0) return; + int display = OS.XtDisplay (handle); + if (display == 0) return; + if ((style & SWT.HORIZONTAL) != 0) { + cursor = OS.XCreateFontCursor (display, OS.XC_sb_v_double_arrow); + } else { + cursor = OS.XCreateFontCursor (display, OS.XC_sb_h_double_arrow); + } + OS.XDefineCursor (display, window, cursor); +} +void releaseWidget () { + super.releaseWidget (); + if (cursor != 0) { + int display = OS.XtDisplay (handle); + if (display != 0) OS.XFreeCursor (display, cursor); + } + cursor = 0; +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the control is selected. + * + * @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);
-}
-public boolean setFocus () {
- checkWidget();
- int [] argList = new int [] {OS.XmNtraversalOn, 1};
- OS.XtSetValues (handle, argList, argList.length / 2);
- overrideTranslations ();
- if (super.setFocus ()) return true;
- argList [1] = 0;
- OS.XtSetValues (handle, argList, argList.length / 2);
- return false;
-}
-int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XButtonPress (w, client_data, call_data, continue_to_dispatch);
- if (result != 0) return result;
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- if (xEvent.button != 1) return result;
- startX = xEvent.x; startY = xEvent.y;
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int border = argList [9], width = argList [5] + (border * 2), height = argList [7] + (border * 2);
- lastX = ((short) argList [1]) - border; lastY = ((short) argList [3]) - border;
- /* The event must be sent because its doit flag is used. */
- Event event = new Event ();
- event.detail = SWT.DRAG;
- event.time = xEvent.time;
- event.x = lastX; event.y = lastY;
- event.width = width; event.height = height;
- /*
- * It is possible (but unlikely) that client code could have disposed
- * the widget in the selection event. If this happens end the processing
- * of this message by returning.
- */
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return result;
- if (event.doit) {
- dragging = true;
- OS.XmUpdateDisplay (handle);
- drawBand (lastX = event.x, lastY = event.y, width, height);
- }
- return result;
-}
-int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XButtonRelease (w, client_data, call_data, continue_to_dispatch);
- if (result != 0) return result;
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- if (xEvent.button != 1) return result;
- if (!dragging) return result;
- dragging = false;
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int border = argList [5];
- int width = argList [1] + (border * 2), height = argList [3] + (border * 2);
- /* The event must be sent because its doit flag is used. */
- Event event = new Event ();
- event.time = xEvent.time;
- event.x = lastX; event.y = lastY;
- event.width = width; event.height = height;
- drawBand (lastX, lastY, width, height);
- sendEvent (SWT.Selection, event);
- /* widget could be disposed here */
- return result;
-}
-int xFocusIn () {
- int result = super.xFocusIn ();
- if (handle == 0) return result;
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- lastX = argList [1];
- lastY = argList [3];
- return result;
-}
-
-int xFocusOut () {
- int result = super.xFocusOut ();
- if (handle == 0) return result;
- int [] argList = new int [] {OS.XmNtraversalOn, 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
- return result;
-}
-int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XKeyPress (w, client_data, call_data, continue_to_dispatch);
- if (result != 0) return result;
- XKeyEvent xEvent = new XKeyEvent ();
- OS.memmove (xEvent, call_data, XKeyEvent.sizeof);
- byte [] buffer = new byte [1];
- int [] keysym = new int [1];
- OS.XLookupString (xEvent, buffer, buffer.length, keysym, null);
-
- switch (keysym [0]) {
- case OS.XK_Left:
- case OS.XK_Right:
- case OS.XK_Up:
- case OS.XK_Down:
- int xChange = 0, yChange = 0;
- int stepSize = PAGE_INCREMENT;
- if ((xEvent.state & OS.ControlMask) != 0) stepSize = INCREMENT;
- if ((style & SWT.VERTICAL) != 0) {
- if (keysym [0] == OS.XK_Up || keysym [0] == OS.XK_Down) break;
- xChange = keysym [0] == OS.XK_Left ? -stepSize : stepSize;
- } else {
- if (keysym [0] == OS.XK_Left || keysym [0] == OS.XK_Right) break;
- yChange = keysym [0] == OS.XK_Up ? -stepSize : stepSize;
- }
-
- int [] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int border = argList1 [5];
- int width = argList1 [1] + (border * 2), height = argList1 [3] + (border * 2);
- int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (parent.handle, argList2, argList2.length / 2);
- int parentBorder = argList2 [5];
- int parentWidth = argList2 [1] + (parentBorder * 2);
- int parentHeight = argList2 [3] + (parentBorder * 2);
- int newX = lastX, newY = lastY;
- if ((style & SWT.VERTICAL) != 0) {
- newX = Math.min (Math.max (0, lastX + xChange - parentBorder - startX), parentWidth - width);
- } else {
- newY = Math.min (Math.max (0, lastY + yChange - parentBorder - startY), parentHeight - height);
- }
- if (newX == lastX && newY == lastY) return result;
-
- /* Ensure that the pointer image does not change */
- int xDisplay = getDisplay().xDisplay;
- int xWindow = OS.XtWindow (parent.handle);
- int ptrGrabResult = OS.XGrabPointer (
- xDisplay,
- xWindow,
- 1,
- OS.None,
- OS.GrabModeAsync,
- OS.GrabModeAsync,
- OS.None,
- cursor,
- OS.CurrentTime);
-
- /* The event must be sent because its doit flag is used. */
- Event event = new Event ();
- event.time = xEvent.time;
- event.x = newX; event.y = newY;
- event.width = width; event.height = height;
- sendEvent (SWT.Selection, event);
- if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime);
-
- /*
- * It is possible (but unlikely) that client code could have disposed
- * the widget in the selection event. If this happens end the processing
- * of this message by returning.
- */
- if (isDisposed ()) break;
- if (event.doit) {
- lastX = event.x; lastY = event.y;
- /* Adjust the pointer position */
- int cursorX = newX; int cursorY = newY;
- if ((style & SWT.VERTICAL) != 0) {
- cursorY += height / 2;
- } else {
- cursorX += width / 2;
- }
- OS.XWarpPointer (xDisplay, OS.None, xWindow, 0, 0, 0, 0, cursorX, cursorY);
- }
- break;
- }
-
- return result;
-}
-int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) {
- int result = super.XPointerMotion (w, client_data, call_data, continue_to_dispatch);
- if (result != 0) return result;
- XMotionEvent xEvent = new XMotionEvent ();
- OS.memmove (xEvent, call_data, XMotionEvent.sizeof);
- if (!dragging || (xEvent.state & OS.Button1Mask) == 0) return result;
- int [] argList1 = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList1, argList1.length / 2);
- int border = argList1 [9], x = ((short) argList1 [1]) - border, y = ((short) argList1 [3]) - border;
- int width = argList1 [5] + (border * 2), height = argList1 [7] + (border * 2);
- int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (parent.handle, argList2, argList2.length / 2);
- int parentBorder = argList2 [5];
- int parentWidth = argList2 [1] + (parentBorder * 2);
- int parentHeight = argList2 [3] + (parentBorder * 2);
- int newX = lastX, newY = lastY;
- if ((style & SWT.VERTICAL) != 0) {
- newX = Math.min (Math.max (0, xEvent.x + x - startX - parentBorder), parentWidth - width);
- } else {
- newY = Math.min (Math.max (0, xEvent.y + y - startY - parentBorder), parentHeight - height);
- }
- if (newX == lastX && newY == lastY) return result;
- drawBand (lastX, lastY, width, height);
- /* The event must be sent because its doit flag is used. */
- Event event = new Event ();
- event.detail = SWT.DRAG;
- event.time = xEvent.time;
- event.x = newX; event.y = newY;
- event.width = width; event.height = height;
- /*
- * It is possible (but unlikely) that client code could have disposed
- * the widget in the selection event. If this happens end the processing
- * of this message by returning.
- */
- sendEvent (SWT.Selection, event);
- if (isDisposed ()) return result;
- if (event.doit) {
- lastX = event.x; lastY = event.y;
- OS.XmUpdateDisplay (handle);
- drawBand (lastX, lastY, width, height);
- }
- return result;
-}
-}
+public void removeSelectionListener(SelectionListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook(SWT.Selection, listener); + eventTable.unhook(SWT.DefaultSelection,listener); +} +public boolean setFocus () { + checkWidget(); + int [] argList = new int [] {OS.XmNtraversalOn, 1}; + OS.XtSetValues (handle, argList, argList.length / 2); + overrideTranslations (); + if (super.setFocus ()) return true; + argList [1] = 0; + OS.XtSetValues (handle, argList, argList.length / 2); + return false; +} +int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) { + int result = super.XButtonPress (w, client_data, call_data, continue_to_dispatch); + if (result != 0) return result; + XButtonEvent xEvent = new XButtonEvent (); + OS.memmove (xEvent, call_data, XButtonEvent.sizeof); + if (xEvent.button != 1) return result; + startX = xEvent.x; startY = xEvent.y; + int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int border = argList [9], width = argList [5] + (border * 2), height = argList [7] + (border * 2); + lastX = ((short) argList [1]) - border; lastY = ((short) argList [3]) - border; + /* The event must be sent because its doit flag is used. */ + Event event = new Event (); + event.detail = SWT.DRAG; + event.time = xEvent.time; + event.x = lastX; event.y = lastY; + event.width = width; event.height = height; + /* + * It is possible (but unlikely) that client code could have disposed + * the widget in the selection event. If this happens end the processing + * of this message by returning. + */ + sendEvent (SWT.Selection, event); + if (isDisposed ()) return result; + if (event.doit) { + dragging = true; + OS.XmUpdateDisplay (handle); + drawBand (lastX = event.x, lastY = event.y, width, height); + } + return result; +} +int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) { + int result = super.XButtonRelease (w, client_data, call_data, continue_to_dispatch); + if (result != 0) return result; + XButtonEvent xEvent = new XButtonEvent (); + OS.memmove (xEvent, call_data, XButtonEvent.sizeof); + if (xEvent.button != 1) return result; + if (!dragging) return result; + dragging = false; + int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int border = argList [5]; + int width = argList [1] + (border * 2), height = argList [3] + (border * 2); + /* The event must be sent because its doit flag is used. */ + Event event = new Event (); + event.time = xEvent.time; + event.x = lastX; event.y = lastY; + event.width = width; event.height = height; + drawBand (lastX, lastY, width, height); + sendEvent (SWT.Selection, event); + /* widget could be disposed here */ + return result; +} +int xFocusIn () { + int result = super.xFocusIn (); + if (handle == 0) return result; + int [] argList = {OS.XmNx, 0, OS.XmNy, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + lastX = argList [1]; + lastY = argList [3]; + return result; +} + +int xFocusOut () { + int result = super.xFocusOut (); + if (handle == 0) return result; + int [] argList = new int [] {OS.XmNtraversalOn, 0}; + OS.XtSetValues (handle, argList, argList.length / 2); + return result; +} +int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) { + int result = super.XKeyPress (w, client_data, call_data, continue_to_dispatch); + if (result != 0) return result; + XKeyEvent xEvent = new XKeyEvent (); + OS.memmove (xEvent, call_data, XKeyEvent.sizeof); + byte [] buffer = new byte [1]; + int [] keysym = new int [1]; + OS.XLookupString (xEvent, buffer, buffer.length, keysym, null); + + switch (keysym [0]) { + case OS.XK_Left: + case OS.XK_Right: + case OS.XK_Up: + case OS.XK_Down: + int xChange = 0, yChange = 0; + int stepSize = PAGE_INCREMENT; + if ((xEvent.state & OS.ControlMask) != 0) stepSize = INCREMENT; + if ((style & SWT.VERTICAL) != 0) { + if (keysym [0] == OS.XK_Up || keysym [0] == OS.XK_Down) break; + xChange = keysym [0] == OS.XK_Left ? -stepSize : stepSize; + } else { + if (keysym [0] == OS.XK_Left || keysym [0] == OS.XK_Right) break; + yChange = keysym [0] == OS.XK_Up ? -stepSize : stepSize; + } + + int [] argList1 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; + OS.XtGetValues (handle, argList1, argList1.length / 2); + int border = argList1 [5]; + int width = argList1 [1] + (border * 2), height = argList1 [3] + (border * 2); + int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; + OS.XtGetValues (parent.handle, argList2, argList2.length / 2); + int parentBorder = argList2 [5]; + int parentWidth = argList2 [1] + (parentBorder * 2); + int parentHeight = argList2 [3] + (parentBorder * 2); + int newX = lastX, newY = lastY; + if ((style & SWT.VERTICAL) != 0) { + newX = Math.min (Math.max (0, lastX + xChange - parentBorder - startX), parentWidth - width); + } else { + newY = Math.min (Math.max (0, lastY + yChange - parentBorder - startY), parentHeight - height); + } + if (newX == lastX && newY == lastY) return result; + + /* Ensure that the pointer image does not change */ + int xDisplay = getDisplay().xDisplay; + int xWindow = OS.XtWindow (parent.handle); + int ptrGrabResult = OS.XGrabPointer ( + xDisplay, + xWindow, + 1, + OS.None, + OS.GrabModeAsync, + OS.GrabModeAsync, + OS.None, + cursor, + OS.CurrentTime); + + /* The event must be sent because its doit flag is used. */ + Event event = new Event (); + event.time = xEvent.time; + event.x = newX; event.y = newY; + event.width = width; event.height = height; + sendEvent (SWT.Selection, event); + if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime); + + /* + * It is possible (but unlikely) that client code could have disposed + * the widget in the selection event. If this happens end the processing + * of this message by returning. + */ + if (isDisposed ()) break; + if (event.doit) { + lastX = event.x; lastY = event.y; + /* Adjust the pointer position */ + int cursorX = newX; int cursorY = newY; + if ((style & SWT.VERTICAL) != 0) { + cursorY += height / 2; + } else { + cursorX += width / 2; + } + OS.XWarpPointer (xDisplay, OS.None, xWindow, 0, 0, 0, 0, cursorX, cursorY); + } + break; + } + + return result; +} +int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) { + int result = super.XPointerMotion (w, client_data, call_data, continue_to_dispatch); + if (result != 0) return result; + XMotionEvent xEvent = new XMotionEvent (); + OS.memmove (xEvent, call_data, XMotionEvent.sizeof); + if (!dragging || (xEvent.state & OS.Button1Mask) == 0) return result; + int [] argList1 = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; + OS.XtGetValues (handle, argList1, argList1.length / 2); + int border = argList1 [9], x = ((short) argList1 [1]) - border, y = ((short) argList1 [3]) - border; + int width = argList1 [5] + (border * 2), height = argList1 [7] + (border * 2); + int [] argList2 = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; + OS.XtGetValues (parent.handle, argList2, argList2.length / 2); + int parentBorder = argList2 [5]; + int parentWidth = argList2 [1] + (parentBorder * 2); + int parentHeight = argList2 [3] + (parentBorder * 2); + int newX = lastX, newY = lastY; + if ((style & SWT.VERTICAL) != 0) { + newX = Math.min (Math.max (0, xEvent.x + x - startX - parentBorder), parentWidth - width); + } else { + newY = Math.min (Math.max (0, xEvent.y + y - startY - parentBorder), parentHeight - height); + } + if (newX == lastX && newY == lastY) return result; + drawBand (lastX, lastY, width, height); + /* The event must be sent because its doit flag is used. */ + Event event = new Event (); + event.detail = SWT.DRAG; + event.time = xEvent.time; + event.x = newX; event.y = newY; + event.width = width; event.height = height; + /* + * It is possible (but unlikely) that client code could have disposed + * the widget in the selection event. If this happens end the processing + * of this message by returning. + */ + sendEvent (SWT.Selection, event); + if (isDisposed ()) return result; + if (event.doit) { + lastX = event.x; lastY = event.y; + OS.XmUpdateDisplay (handle); + drawBand (lastX, lastY, width, height); + } + return result; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java index 2c8baea84f..b346ac3429 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scale.java @@ -1,17 +1,17 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.events.*; +import org.eclipse.swt.graphics.*; + /** * Instances of the receiver represent a selectable user * interface object that present a range of continuous @@ -30,7 +30,7 @@ import org.eclipse.swt.graphics.*; * within the SWT implementation. * </p> */ -public class Scale extends Control {
+public class Scale extends Control { /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -60,296 +60,296 @@ public class Scale extends Control { * @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 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);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- Display display = getDisplay ();
- int hScroll = display.scrolledMarginX;
- int vScroll = display.scrolledMarginY;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += hScroll * 10;
- height += vScroll;
- } else {
- width += hScroll;
- height += vScroll * 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-void createHandle (int index) {
- state |= HANDLE;
- int [] argList = {
- OS.XmNtitleString, 0,
- OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0,
- OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL,
- OS.XmNprocessingDirection, ((style & SWT.H_SCROLL) != 0) ? OS.XmMAX_ON_RIGHT : OS.XmMAX_ON_BOTTOM,
- OS.XmNancestorSensitive, 1,
- };
- int parentHandle = parent.handle;
- handle = OS.XmCreateScale (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-/**
- * 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 void addSelectionListener(SelectionListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener(listener); + addListener(SWT.Selection,typedListener); + addListener(SWT.DefaultSelection,typedListener); +} +static int checkStyle (int style) { + return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0); +} +public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget(); + int border = getBorderWidth (); + int width = border * 2, height = border * 2; + Display display = getDisplay (); + int hScroll = display.scrolledMarginX; + int vScroll = display.scrolledMarginY; + if ((style & SWT.HORIZONTAL) != 0) { + width += hScroll * 10; + height += vScroll; + } else { + width += hScroll; + height += vScroll * 10; + } + if (wHint != SWT.DEFAULT) width = wHint + (border * 2); + if (hHint != SWT.DEFAULT) height = hHint + (border * 2); + return new Point (width, height); +} +void createHandle (int index) { + state |= HANDLE; + int [] argList = { + OS.XmNtitleString, 0, + OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0, + OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL, + OS.XmNprocessingDirection, ((style & SWT.H_SCROLL) != 0) ? OS.XmMAX_ON_RIGHT : OS.XmMAX_ON_BOTTOM, + OS.XmNancestorSensitive, 1, + }; + int parentHandle = parent.handle; + handle = OS.XmCreateScale (parentHandle, null, argList, argList.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); +} +/** + * Returns the amount that the receiver's value will be + * modified by when the up/down (or right/left) arrows + * are pressed. + * + * @return the increment + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getIncrement () {
- checkWidget();
- return 1;
-}
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getIncrement () { + checkWidget(); + return 1; +} +/** + * Returns the maximum value which the receiver will allow. + * + * @return the maximum + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getMaximum () {
- checkWidget();
- int [] argList = {OS.XmNmaximum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getMaximum () { + checkWidget(); + int [] argList = {OS.XmNmaximum, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns the minimum value which the receiver will allow. + * + * @return the minimum + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getMinimum () {
- checkWidget();
- int [] argList = {OS.XmNminimum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getMinimum () { + checkWidget(); + int [] argList = {OS.XmNminimum, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns the amount that the receiver's value will be + * modified by when the page increment/decrement areas + * are selected. + * + * @return the page increment + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getPageIncrement () {
- checkWidget();
- int [] argList = {OS.XmNscaleMultiple, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the 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 getPageIncrement () { + checkWidget(); + int [] argList = {OS.XmNscaleMultiple, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * 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 [] argList = {OS.XmNvalue, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = getDisplay ().windowProc;
- OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, DRAG_CALLBACK);
-}
-void overrideTranslations () {
- Display display = getDisplay ();
- OS.XtOverrideTranslations (handle, display.tabTranslations);
-}
-/**
- * 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 int getSelection () { + checkWidget(); + int [] argList = {OS.XmNvalue, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +void hookEvents () { + super.hookEvents (); + int windowProc = getDisplay ().windowProc; + OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK); + OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, DRAG_CALLBACK); +} +void overrideTranslations () { + Display display = getDisplay (); + OS.XtOverrideTranslations (handle, display.tabTranslations); +} +/** + * 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 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 increment) {
- checkWidget();
-}
-/**
- * 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 setIncrement (int increment) { + checkWidget(); +} +/** + * 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 [] argList = {OS.XmNmaximum, value};
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * 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 setMaximum (int value) { + checkWidget(); + if (value < 0) return; + int [] argList = {OS.XmNmaximum, value}; + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XtSetValues (handle, argList, argList.length / 2); + display.setWarnings (warnings); +} +/** + * 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 [] argList = {OS.XmNminimum, value};
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @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 setMinimum (int value) { + checkWidget(); + if (value < 0) return; + int [] argList = {OS.XmNminimum, value}; + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XtSetValues (handle, argList, argList.length / 2); + display.setWarnings (warnings); +} +/** + * Sets the amount that the receiver's value will be + * modified by when the page increment/decrement areas + * are selected to the argument, which must be at least + * one. + * + * @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 pageIncrement) {
- checkWidget();
- if (pageIncrement < 1) return;
- int [] argList = {OS.XmNscaleMultiple, pageIncrement};
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * 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 setPageIncrement (int pageIncrement) { + checkWidget(); + if (pageIncrement < 1) return; + int [] argList = {OS.XmNscaleMultiple, pageIncrement}; + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XtSetValues (handle, argList, argList.length / 2); + display.setWarnings (warnings); +} +/** + * 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 selection) {
- checkWidget();
- int [] argList = {OS.XmNvalue, selection};
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-int XmNdragCallback (int w, int client_data, int call_data) {
- postEvent (SWT.Selection);
- return 0;
-}
-int XmNvalueChangedCallback (int w, int client_data, int call_data) {
- postEvent (SWT.Selection);
- return 0;
-}
-}
+public void setSelection (int selection) { + checkWidget(); + int [] argList = {OS.XmNvalue, selection}; + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XtSetValues (handle, argList, argList.length / 2); + display.setWarnings (warnings); +} +int XmNdragCallback (int w, int client_data, int call_data) { + postEvent (SWT.Selection); + return 0; +} +int XmNvalueChangedCallback (int w, int client_data, int call_data) { + postEvent (SWT.Selection); + return 0; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java index aa747274b5..8887ae6463 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ScrollBar.java @@ -1,17 +1,17 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.events.*; + /** * Instances of this class are selectable user interface * objects that represent a range of positive, numeric values. @@ -75,608 +75,608 @@ import org.eclipse.swt.events.*; * @see Scrollable#getHorizontalBar * @see Scrollable#getVerticalBar */ -public class ScrollBar extends Widget {
- Scrollable parent;
-ScrollBar () {
- /* Do Nothing */
-}
-ScrollBar (Scrollable parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- createWidget (0);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the 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 class ScrollBar extends Widget { + Scrollable parent; +ScrollBar () { + /* Do Nothing */ +} +ScrollBar (Scrollable parent, int style) { + super (parent, checkStyle (style)); + this.parent = parent; + createWidget (0); +} +/** + * Adds the listener to the collection of listeners who will + * be notified when the 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 [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0,
- OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL,
- OS.XmNtraversalOn, 0,
- };
- int parentHandle = parent.scrolledHandle;
- handle = OS.XmCreateScrollBar (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-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 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 [] argList = { + OS.XmNancestorSensitive, 1, + OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0, + OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL, + OS.XmNtraversalOn, 0, + }; + int parentHandle = parent.scrolledHandle; + handle = OS.XmCreateScrollBar (parentHandle, null, argList, argList.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); +} +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();
- int [] argList = {OS.XmNsensitive, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] != 0;
-}
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public boolean getEnabled () { + checkWidget(); + int [] argList = {OS.XmNsensitive, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1] != 0; +} +/** + * Returns the amount that the receiver's value will be + * modified by when the up/down (or right/left) arrows + * are pressed. + * + * @return the increment + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getIncrement () {
- checkWidget();
- int [] argList = {OS.XmNincrement, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getIncrement () { + checkWidget(); + int [] argList = {OS.XmNincrement, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns the maximum value which the receiver will allow. + * + * @return the maximum + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getMaximum () {
- checkWidget();
- int [] argList = {OS.XmNmaximum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getMaximum () { + checkWidget(); + int [] argList = {OS.XmNmaximum, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns the minimum value which the receiver will allow. + * + * @return the minimum + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getMinimum () {
- checkWidget();
- int [] argList = {OS.XmNminimum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getMinimum () { + checkWidget(); + int [] argList = {OS.XmNminimum, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns the amount that the receiver's value will be + * modified by when the page increment/decrement areas + * are selected. + * + * @return the page increment + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getPageIncrement () {
- checkWidget();
- int [] argList = {OS.XmNpageIncrement, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the receiver's parent, which must be 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 int getPageIncrement () { + checkWidget(); + int [] argList = {OS.XmNpageIncrement, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns the receiver's parent, which must be 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 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();
- int [] argList = {OS.XmNvalue, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns a point describing the receiver's size. The
- * x coordinate of the result is the width of the receiver.
- * The y coordinate of the result is the height of the
- * receiver.
- *
- * @return the receiver's size
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getSelection () { + checkWidget(); + int [] argList = {OS.XmNvalue, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns a point describing the receiver's size. The + * x coordinate of the result is the width of the receiver. + * The y coordinate of the result is the height of the + * receiver. + * + * @return the receiver's size + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public Point getSize () {
- checkWidget();
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int borders = argList [5] * 2;
- return new Point (argList [1] + borders, argList [3] + borders);
-}
-/**
- * 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 Point getSize () { + checkWidget(); + int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int borders = argList [5] * 2; + return new Point (argList [1] + borders, argList [3] + borders); +} +/** + * 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();
- int [] argList = {OS.XmNsliderSize, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns <code>true</code> if the receiver is visible, and
- * <code>false</code> otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, this method
- * may still indicate that it is considered visible even though
- * it may not actually be showing.
- * </p>
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getThumb () { + checkWidget(); + int [] argList = {OS.XmNsliderSize, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns <code>true</code> if the receiver is visible, and + * <code>false</code> otherwise. + * <p> + * If one of the receiver's ancestors is not visible or some + * other condition makes the receiver not visible, this method + * may still indicate that it is considered visible even though + * it may not actually be showing. + * </p> + * + * @return the receiver's visibility state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public boolean getVisible () {
- checkWidget();
- return OS.XtIsManaged (handle);
-}
-void hookEvents () {
- int windowProc = getDisplay ().windowProc;
- OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, DRAG_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNtoBottomCallback, windowProc, TO_BOTTOM_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNtoTopCallback, windowProc, TO_TOP_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNincrementCallback, windowProc, INCREMENT_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNdecrementCallback, windowProc, DECREMENT_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNpageIncrementCallback, windowProc, PAGE_INCREMENT_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNpageDecrementCallback, windowProc, PAGE_DECREMENT_CALLBACK);
-}
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
+public boolean getVisible () { + checkWidget(); + return OS.XtIsManaged (handle); +} +void hookEvents () { + int windowProc = getDisplay ().windowProc; + OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK); + OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, DRAG_CALLBACK); + OS.XtAddCallback (handle, OS.XmNtoBottomCallback, windowProc, TO_BOTTOM_CALLBACK); + OS.XtAddCallback (handle, OS.XmNtoTopCallback, windowProc, TO_TOP_CALLBACK); + OS.XtAddCallback (handle, OS.XmNincrementCallback, windowProc, INCREMENT_CALLBACK); + OS.XtAddCallback (handle, OS.XmNdecrementCallback, windowProc, DECREMENT_CALLBACK); + OS.XtAddCallback (handle, OS.XmNpageIncrementCallback, windowProc, PAGE_INCREMENT_CALLBACK); + OS.XtAddCallback (handle, OS.XmNpageDecrementCallback, windowProc, PAGE_DECREMENT_CALLBACK); +} +/** + * Returns <code>true</code> if the receiver is enabled and all + * of the receiver's ancestors are enabled, and <code>false</code> + * otherwise. A disabled control is typically not selectable from the + * user interface and draws with an inactive or "grayed" look. + * + * @return the receiver's enabled state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #getEnabled */ -public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-/**
- * Returns <code>true</code> if the receiver is visible and all
- * of the receiver's ancestors are visible and <code>false</code>
- * otherwise.
- *
- * @return the receiver's visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getVisible
+public boolean isEnabled () { + checkWidget(); + return getEnabled () && parent.isEnabled (); +} +/** + * Returns <code>true</code> if the receiver is visible and all + * of the receiver's ancestors are visible and <code>false</code> + * otherwise. + * + * @return the receiver's visibility state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #getVisible */ -public boolean isVisible () {
- checkWidget();
- return getVisible () && parent.isVisible ();
-}
-void manageChildren () {
- OS.XtManageChild (handle);
-}
-void propagateWidget (boolean enabled) {
- propagateHandle (enabled, handle);
-}
-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 boolean isVisible () { + checkWidget(); + return getVisible () && parent.isVisible (); +} +void manageChildren () { + OS.XtManageChild (handle); +} +void propagateWidget (boolean enabled) { + propagateHandle (enabled, handle); +} +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);
-}
-void sendScrollEvent (int detail) {
- Event event = new Event ();
- event.detail = detail;
- sendEvent (SWT.Selection, event);
- /*
- * Feature in Motif. When a scroll bar is selected,
- * it does not make the shell active. The fix is to
- * make the shell active.
- */
- Shell shell = parent.getShell ();
- shell.bringToTop (true);
-}
-/**
- * Enables the receiver if the argument is <code>true</code>,
- * and disables it otherwise. A disabled control is typically
- * not selectable from the user interface and draws with an
- * inactive or "grayed" look.
- *
- * @param enabled the new enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void removeSelectionListener(SelectionListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook(SWT.Selection, listener); + eventTable.unhook(SWT.DefaultSelection,listener); +} +void sendScrollEvent (int detail) { + Event event = new Event (); + event.detail = detail; + sendEvent (SWT.Selection, event); + /* + * Feature in Motif. When a scroll bar is selected, + * it does not make the shell active. The fix is to + * make the shell active. + */ + Shell shell = parent.getShell (); + shell.bringToTop (true); +} +/** + * Enables the receiver if the argument is <code>true</code>, + * and disables it otherwise. A disabled control is typically + * not selectable from the user interface and draws with an + * inactive or "grayed" look. + * + * @param enabled the new enabled state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setEnabled (boolean enabled) {
- checkWidget();
- int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void setEnabled (boolean enabled) { + checkWidget(); + int [] argList = {OS.XmNsensitive, enabled ? 1 : 0}; + OS.XtSetValues (handle, argList, argList.length / 2); +} +/** + * Sets the amount that the receiver's value will be + * modified by when the up/down (or right/left) arrows + * are pressed to the argument, which must be at least + * one. + * + * @param value the new increment (must be greater than zero) + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- int [] argList = {OS.XmNincrement, value};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * Sets the maximum 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 setIncrement (int value) { + checkWidget(); + if (value < 1) return; + int [] argList = {OS.XmNincrement, value}; + OS.XtSetValues (handle, argList, argList.length / 2); +} +/** + * 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 [] argList = {OS.XmNmaximum, value};
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * 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 setMaximum (int value) { + checkWidget(); + if (value < 0) return; + int [] argList = {OS.XmNmaximum, value}; + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XtSetValues (handle, argList, argList.length / 2); + display.setWarnings (warnings); +} +/** + * 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 [] argList = {
- OS.XmNminimum, 0,
- OS.XmNmaximum, 0,
- OS.XmNsliderSize, 0,
- };
- /*
- * Feature in Motif. For some reason, when minimium
- * is set to be greater than or equal to maximum, Motif
- * does not set the minimum. Instead, the value is
- * changed and the minimum stays the same. This behavior
- * differs from setting the maximum where the slider size
- * is always decreased to make room for the new maximum.
- * The fix is to decrease the slider to make room for
- * the new minimum.
- */
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [3] - value - argList [5] < 0) {
- argList [5] = argList [3] - value;
- }
- argList [1] = value;
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @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 setMinimum (int value) { + checkWidget(); + if (value < 0) return; + int [] argList = { + OS.XmNminimum, 0, + OS.XmNmaximum, 0, + OS.XmNsliderSize, 0, + }; + /* + * Feature in Motif. For some reason, when minimium + * is set to be greater than or equal to maximum, Motif + * does not set the minimum. Instead, the value is + * changed and the minimum stays the same. This behavior + * differs from setting the maximum where the slider size + * is always decreased to make room for the new maximum. + * The fix is to decrease the slider to make room for + * the new minimum. + */ + OS.XtGetValues (handle, argList, argList.length / 2); + if (argList [3] - value - argList [5] < 0) { + argList [5] = argList [3] - value; + } + argList [1] = value; + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XtSetValues (handle, argList, argList.length / 2); + display.setWarnings (warnings); +} +/** + * Sets the amount that the receiver's value will be + * modified by when the page increment/decrement areas + * are selected to the argument, which must be at least + * one. + * + * @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 [] argList = {OS.XmNpageIncrement, value};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * Sets the single <em>selection</em> that is the receiver's
- * value to the argument which must be greater than or equal
- * to zero.
- *
- * @param 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 setPageIncrement (int value) { + checkWidget(); + if (value < 1) return; + int [] argList = {OS.XmNpageIncrement, value}; + OS.XtSetValues (handle, argList, argList.length / 2); +} +/** + * Sets the single <em>selection</em> that is the receiver's + * value to the argument which must be greater than or equal + * to zero. + * + * @param value the new selection (must be zero or greater) + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setSelection (int selection) {
- checkWidget();
- int [] argList = {OS.XmNvalue, selection};
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values 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 setSelection (int selection) { + checkWidget(); + int [] argList = {OS.XmNvalue, selection}; + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XtSetValues (handle, argList, argList.length / 2); + display.setWarnings (warnings); +} +/** + * Sets the size of the receiver's thumb relative to the + * difference between its maximum and minimum values 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 [] argList = {OS.XmNsliderSize, value};
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, thumb, increment and page increment all at once.
- * <p>
- * Note: This is 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 setThumb (int value) { + checkWidget(); + if (value < 1) return; + int [] argList = {OS.XmNsliderSize, value}; + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XtSetValues (handle, argList, argList.length / 2); + display.setWarnings (warnings); +} +/** + * Sets the receiver's selection, minimum value, maximum + * value, thumb, increment and page increment all at once. + * <p> + * Note: This is 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 (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 [] argList = {
- OS.XmNvalue, selection,
- OS.XmNminimum, minimum,
- OS.XmNmaximum, maximum,
- OS.XmNsliderSize, thumb,
- OS.XmNincrement, increment,
- OS.XmNpageIncrement, pageIncrement,
- };
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Marks the receiver as visible if the argument is <code>true</code>,
- * and marks it invisible otherwise.
- * <p>
- * If one of the receiver's ancestors is not visible or some
- * other condition makes the receiver not visible, marking
- * it visible may not actually cause it to be displayed.
- * </p>
- *
- * @param visible the new visibility state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) { + checkWidget(); + if (minimum < 0) return; + if (maximum < 0) return; + if (thumb < 1) return; + if (maximum - minimum - thumb < 0) return; + if (increment < 1) return; + if (pageIncrement < 1) return; + int [] argList = { + OS.XmNvalue, selection, + OS.XmNminimum, minimum, + OS.XmNmaximum, maximum, + OS.XmNsliderSize, thumb, + OS.XmNincrement, increment, + OS.XmNpageIncrement, pageIncrement, + }; + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XtSetValues (handle, argList, argList.length / 2); + display.setWarnings (warnings); +} +/** + * Marks the receiver as visible if the argument is <code>true</code>, + * and marks it invisible otherwise. + * <p> + * If one of the receiver's ancestors is not visible or some + * other condition makes the receiver not visible, marking + * it visible may not actually cause it to be displayed. + * </p> + * + * @param visible the new visibility state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setVisible (boolean visible) {
- checkWidget();
- parent.setScrollbarVisible (handle, visible);
-}
-int XmNdecrementCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.ARROW_UP);
- return 0;
-}
-int XmNdragCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.DRAG);
- return 0;
-}
-int XmNincrementCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.ARROW_DOWN);
- return 0;
-}
-int XmNpageDecrementCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.PAGE_UP);
- return 0;
-}
-int XmNpageIncrementCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.PAGE_DOWN);
- return 0;
-}
-int XmNtoBottomCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.END);
- return 0;
-}
-int XmNtoTopCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.HOME);
- return 0;
-}
-int XmNvalueChangedCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.NONE);
- return 0;
-}
+public void setVisible (boolean visible) { + checkWidget(); + parent.setScrollbarVisible (handle, visible); +} +int XmNdecrementCallback (int w, int client_data, int call_data) { + sendScrollEvent (SWT.ARROW_UP); + return 0; +} +int XmNdragCallback (int w, int client_data, int call_data) { + sendScrollEvent (SWT.DRAG); + return 0; +} +int XmNincrementCallback (int w, int client_data, int call_data) { + sendScrollEvent (SWT.ARROW_DOWN); + return 0; +} +int XmNpageDecrementCallback (int w, int client_data, int call_data) { + sendScrollEvent (SWT.PAGE_UP); + return 0; +} +int XmNpageIncrementCallback (int w, int client_data, int call_data) { + sendScrollEvent (SWT.PAGE_DOWN); + return 0; +} +int XmNtoBottomCallback (int w, int client_data, int call_data) { + sendScrollEvent (SWT.END); + return 0; +} +int XmNtoTopCallback (int w, int client_data, int call_data) { + sendScrollEvent (SWT.HOME); + return 0; +} +int XmNvalueChangedCallback (int w, int client_data, int call_data) { + sendScrollEvent (SWT.NONE); + return 0; +} }
\ No newline at end of file diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java index 7aa4a6a2a2..68f489b465 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Scrollable.java @@ -1,36 +1,36 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * This class is the abstract superclass of all classes which
- * represent controls that have standard scroll bars.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>H_SCROLL, V_SCROLL</dd>
- * <dt><b>Events:</b>
- * <dd>(none)</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html */ -public abstract class Scrollable extends Control {
- int scrolledHandle, formHandle;
- ScrollBar horizontalBar, verticalBar;
-Scrollable () {
- /* Do nothing */
-}
+ +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; + +/** + * This class is the abstract superclass of all classes which + * represent controls that have standard scroll bars. + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>H_SCROLL, V_SCROLL</dd> + * <dt><b>Events:</b> + * <dd>(none)</dd> + * </dl> + * <p> + * IMPORTANT: This class is intended to be subclassed <em>only</em> + * within the SWT implementation. + * </p> + */ +public abstract class Scrollable extends Control { + int scrolledHandle, formHandle; + ScrollBar horizontalBar, verticalBar; +Scrollable () { + /* Do nothing */ +} /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -60,268 +60,268 @@ Scrollable () { * @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 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) {
- checkWidget();
- int border = getBorderWidth ();
- int trimX = x - border, trimY = y - border;
- int trimWidth = width + (border * 2), trimHeight = height + (border * 2);
- if (horizontalBar != null) {
- Display display = getDisplay ();
- trimY -= display.scrolledInsetY;
- trimHeight += display.scrolledInsetY + display.scrolledMarginY;
- if (verticalBar == null) {
- trimX -= display.scrolledInsetX;
- trimWidth += display.scrolledInsetX * 2;
- trimHeight -= display.scrolledInsetY * 2;
- }
- }
- if (verticalBar != null) {
- Display display = getDisplay ();
- trimX -= display.scrolledInsetX;
- trimWidth += display.scrolledInsetX + display.scrolledMarginX;
- if (horizontalBar == null) {
- trimY -= display.scrolledInsetY;
- trimHeight += display.scrolledInsetY * 2;
- trimWidth -= display.scrolledInsetX * 2;
- }
- }
- return new Rectangle (trimX, trimY, trimWidth, trimHeight);
-}
-ScrollBar createScrollBar (int type) {
- return new ScrollBar (this, type);
-}
-ScrollBar createStandardBar (int style) {
- if (scrolledHandle == 0) return null;
- ScrollBar bar = new ScrollBar ();
- bar.parent = this;
- bar.style = style;
- bar.state |= HANDLE;
- int [] argList = {OS.XmNhorizontalScrollBar, 0, OS.XmNverticalScrollBar, 0};
- OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
- if (style == SWT.H_SCROLL) bar.handle = argList [1];
- if (style == SWT.V_SCROLL) bar.handle = argList [3];
- bar.hookEvents ();
- bar.register ();
- return bar;
-}
-void createWidget (int index) {
- super.createWidget (index);
- if ((style & SWT.H_SCROLL) != 0) horizontalBar = createScrollBar (SWT.H_SCROLL);
- if ((style & SWT.V_SCROLL) != 0) verticalBar = createScrollBar (SWT.V_SCROLL);
-}
-void deregister () {
- super.deregister ();
- if (formHandle != 0) WidgetTable.remove (formHandle);
- if (scrolledHandle != 0) WidgetTable.remove (scrolledHandle);
-}
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- if (formHandle != 0) enableHandle (enabled, formHandle);
- if (scrolledHandle != 0) {
- enableHandle (enabled, scrolledHandle);
- int [] argList = {
- OS.XmNhorizontalScrollBar, 0,
- OS.XmNverticalScrollBar, 0,
- };
- OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
- if (argList [1] != 0) enableHandle (enabled, argList [1]);
- if (argList [3] != 0) enableHandle (enabled, argList [3]);
- }
-}
-/**
- * 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 computeTrim (int x, int y, int width, int height) { + checkWidget(); + int border = getBorderWidth (); + int trimX = x - border, trimY = y - border; + int trimWidth = width + (border * 2), trimHeight = height + (border * 2); + if (horizontalBar != null) { + Display display = getDisplay (); + trimY -= display.scrolledInsetY; + trimHeight += display.scrolledInsetY + display.scrolledMarginY; + if (verticalBar == null) { + trimX -= display.scrolledInsetX; + trimWidth += display.scrolledInsetX * 2; + trimHeight -= display.scrolledInsetY * 2; + } + } + if (verticalBar != null) { + Display display = getDisplay (); + trimX -= display.scrolledInsetX; + trimWidth += display.scrolledInsetX + display.scrolledMarginX; + if (horizontalBar == null) { + trimY -= display.scrolledInsetY; + trimHeight += display.scrolledInsetY * 2; + trimWidth -= display.scrolledInsetX * 2; + } + } + return new Rectangle (trimX, trimY, trimWidth, trimHeight); +} +ScrollBar createScrollBar (int type) { + return new ScrollBar (this, type); +} +ScrollBar createStandardBar (int style) { + if (scrolledHandle == 0) return null; + ScrollBar bar = new ScrollBar (); + bar.parent = this; + bar.style = style; + bar.state |= HANDLE; + int [] argList = {OS.XmNhorizontalScrollBar, 0, OS.XmNverticalScrollBar, 0}; + OS.XtGetValues (scrolledHandle, argList, argList.length / 2); + if (style == SWT.H_SCROLL) bar.handle = argList [1]; + if (style == SWT.V_SCROLL) bar.handle = argList [3]; + bar.hookEvents (); + bar.register (); + return bar; +} +void createWidget (int index) { + super.createWidget (index); + if ((style & SWT.H_SCROLL) != 0) horizontalBar = createScrollBar (SWT.H_SCROLL); + if ((style & SWT.V_SCROLL) != 0) verticalBar = createScrollBar (SWT.V_SCROLL); +} +void deregister () { + super.deregister (); + if (formHandle != 0) WidgetTable.remove (formHandle); + if (scrolledHandle != 0) WidgetTable.remove (scrolledHandle); +} +void enableWidget (boolean enabled) { + super.enableWidget (enabled); + if (formHandle != 0) enableHandle (enabled, formHandle); + if (scrolledHandle != 0) { + enableHandle (enabled, scrolledHandle); + int [] argList = { + OS.XmNhorizontalScrollBar, 0, + OS.XmNverticalScrollBar, 0, + }; + OS.XtGetValues (scrolledHandle, argList, argList.length / 2); + if (argList [1] != 0) enableHandle (enabled, argList [1]); + if (argList [3] != 0) enableHandle (enabled, argList [3]); + } +} +/** + * Returns a rectangle which describes the area of the + * receiver which is capable of displaying data (that is, + * not covered by the "trimmings"). + * + * @return the client area + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #computeTrim */ -public Rectangle getClientArea () {
- checkWidget();
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return new Rectangle (0, 0, argList [1], argList [3]);
-}
-/**
- * Returns the receiver's horizontal scroll bar if it has
- * one, and null if it does not.
- *
- * @return the horizontal scroll bar (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public Rectangle getClientArea () { + checkWidget(); + int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return new Rectangle (0, 0, argList [1], argList [3]); +} +/** + * Returns the receiver's horizontal scroll bar if it has + * one, and null if it does not. + * + * @return the horizontal scroll bar (or null) + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public ScrollBar getHorizontalBar () {
- checkWidget();
- return horizontalBar;
-}
-/**
- * Returns the receiver's vertical scroll bar if it has
- * one, and null if it does not.
- *
- * @return the vertical scroll bar (or null)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public ScrollBar getHorizontalBar () { + checkWidget(); + return horizontalBar; +} +/** + * Returns the receiver's vertical scroll bar if it has + * one, and null if it does not. + * + * @return the vertical scroll bar (or null) + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public ScrollBar getVerticalBar () {
- checkWidget();
- return verticalBar;
-}
-boolean isTabGroup () {
- if ((state & CANVAS) != 0) return true;
- return super.isTabGroup ();
-}
-void manageChildren () {
- if (scrolledHandle != 0) {
- OS.XtSetMappedWhenManaged (scrolledHandle, false);
- OS.XtManageChild (scrolledHandle);
- }
- if (formHandle != 0) {
- OS.XtSetMappedWhenManaged (formHandle, false);
- OS.XtManageChild (formHandle);
- }
- super.manageChildren ();
- if (formHandle != 0) {
- int [] argList = {OS.XmNborderWidth, 0};
- OS.XtGetValues (formHandle, argList, argList.length / 2);
- OS.XtResizeWidget (formHandle, 1, 1, argList [1]);
- OS.XtSetMappedWhenManaged (formHandle, true);
- }
- if (scrolledHandle != 0) {
- int [] argList = {OS.XmNborderWidth, 0};
- OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
- OS.XtResizeWidget (scrolledHandle, 1, 1, argList [1]);
- OS.XtSetMappedWhenManaged (scrolledHandle, true);
- }
-}
-void propagateWidget (boolean enabled) {
- super.propagateWidget (enabled);
- if (formHandle != 0) propagateHandle (enabled, formHandle);
- if (scrolledHandle != 0) {
- propagateHandle (enabled, scrolledHandle);
- if (horizontalBar != null) horizontalBar.propagateWidget (enabled);
- if (verticalBar != null) verticalBar.propagateWidget (enabled);
- }
-}
-void redrawWidget (int x, int y, int width, int height, boolean all) {
- super.redrawWidget (x, y, width, height, all);
- /*
- * Uncomment this code to force the window trimmings to redraw.
- */
-// if (formHandle == 0 && scrolledHandle == 0) return;
-// short [] root_x = new short [1], root_y = new short [1];
-// OS.XtTranslateCoords (handle, (short) x, (short) y, root_x, root_y);
-// if (formHandle != 0) {
-// short [] form_x = new short [1], form_y = new short [1];
-// OS.XtTranslateCoords (formHandle, (short) 0, (short) 0, form_x, form_y);
-// redrawHandle (root_x [0] - form_x [0], root_y [0] - form_y [0], width, height, formHandle);
-// }
-// if (scrolledHandle != 0) {
-// short [] scrolled_x = new short [1], scrolled_y = new short [1];
-// OS.XtTranslateCoords (scrolledHandle, (short) 0, (short) 0, scrolled_x, scrolled_y);
-// redrawHandle (root_x [0] - scrolled_x [0], root_y [0] - scrolled_y [0], width, height, scrolledHandle);
-// if (horizontalBar != null && horizontalBar.getVisible ()) {
-// int horizontalHandle = horizontalBar.handle;
-// short [] hscroll_x = new short [1], hscroll_y = new short [1];
-// OS.XtTranslateCoords (horizontalHandle, (short) 0, (short) 0, hscroll_x, hscroll_y);
-// redrawHandle (root_x [0] - hscroll_x [0], root_y [0] - hscroll_y [0], width, height, horizontalHandle);
-// }
-// if (verticalBar != null && verticalBar.getVisible ()) {
-// int verticalHandle = verticalBar.handle;
-// short [] vscroll_x = new short [1], vscroll_y = new short [1];
-// OS.XtTranslateCoords (verticalHandle, (short) 0, (short) 0, vscroll_x, vscroll_y);
-// redrawHandle (root_x [0] - vscroll_x [0], root_y [0] - vscroll_y [0], width, height, verticalHandle);
-// }
-// }
-}
-void register () {
- super.register ();
- if (formHandle != 0) WidgetTable.put (formHandle, this);
- if (scrolledHandle != 0) WidgetTable.put (scrolledHandle, this);
-}
-void releaseHandle () {
- super.releaseHandle ();
- scrolledHandle = formHandle = 0;
-}
-void releaseWidget () {
- if (horizontalBar != null) horizontalBar.releaseResources ();
- if (verticalBar != null) verticalBar.releaseResources ();
- horizontalBar = verticalBar = null;
- super.releaseWidget ();
-}
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- if (scrolledHandle != 0) {
- int [] argList1 = {
- OS.XmNhorizontalScrollBar, 0,
- OS.XmNverticalScrollBar, 0,
- };
- OS.XtGetValues (scrolledHandle, argList1, argList1.length / 2);
- if (argList1 [1] != 0) OS.XmChangeColor (argList1 [1], pixel);
- if (argList1 [3] != 0) OS.XmChangeColor (argList1 [3], pixel);
- }
-}
-void setScrollbarVisible (int barHandle, boolean visible) {
- if (scrolledHandle == 0) return;
- /*
- * Feature in Motif. Hiding or showing a scroll bar
- * can cause the widget to automatically resize in
- * the OS. This behavior is unwanted. The fix is
- * to force the widget to resize to original size.
- */
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
-
- /* Hide or show the scroll bar */
- if (visible) {
- OS.XtManageChild (barHandle);
- } else {
- OS.XtUnmanageChild (barHandle);
- }
-
- /* Restore the size */
- OS.XtSetValues (scrolledHandle, argList, argList.length / 2);
-}
-int topHandle () {
- if (scrolledHandle != 0) return scrolledHandle;
- if (formHandle != 0) return formHandle;
- return handle;
-}
-}
+public ScrollBar getVerticalBar () { + checkWidget(); + return verticalBar; +} +boolean isTabGroup () { + if ((state & CANVAS) != 0) return true; + return super.isTabGroup (); +} +void manageChildren () { + if (scrolledHandle != 0) { + OS.XtSetMappedWhenManaged (scrolledHandle, false); + OS.XtManageChild (scrolledHandle); + } + if (formHandle != 0) { + OS.XtSetMappedWhenManaged (formHandle, false); + OS.XtManageChild (formHandle); + } + super.manageChildren (); + if (formHandle != 0) { + int [] argList = {OS.XmNborderWidth, 0}; + OS.XtGetValues (formHandle, argList, argList.length / 2); + OS.XtResizeWidget (formHandle, 1, 1, argList [1]); + OS.XtSetMappedWhenManaged (formHandle, true); + } + if (scrolledHandle != 0) { + int [] argList = {OS.XmNborderWidth, 0}; + OS.XtGetValues (scrolledHandle, argList, argList.length / 2); + OS.XtResizeWidget (scrolledHandle, 1, 1, argList [1]); + OS.XtSetMappedWhenManaged (scrolledHandle, true); + } +} +void propagateWidget (boolean enabled) { + super.propagateWidget (enabled); + if (formHandle != 0) propagateHandle (enabled, formHandle); + if (scrolledHandle != 0) { + propagateHandle (enabled, scrolledHandle); + if (horizontalBar != null) horizontalBar.propagateWidget (enabled); + if (verticalBar != null) verticalBar.propagateWidget (enabled); + } +} +void redrawWidget (int x, int y, int width, int height, boolean all) { + super.redrawWidget (x, y, width, height, all); + /* + * Uncomment this code to force the window trimmings to redraw. + */ +// if (formHandle == 0 && scrolledHandle == 0) return; +// short [] root_x = new short [1], root_y = new short [1]; +// OS.XtTranslateCoords (handle, (short) x, (short) y, root_x, root_y); +// if (formHandle != 0) { +// short [] form_x = new short [1], form_y = new short [1]; +// OS.XtTranslateCoords (formHandle, (short) 0, (short) 0, form_x, form_y); +// redrawHandle (root_x [0] - form_x [0], root_y [0] - form_y [0], width, height, formHandle); +// } +// if (scrolledHandle != 0) { +// short [] scrolled_x = new short [1], scrolled_y = new short [1]; +// OS.XtTranslateCoords (scrolledHandle, (short) 0, (short) 0, scrolled_x, scrolled_y); +// redrawHandle (root_x [0] - scrolled_x [0], root_y [0] - scrolled_y [0], width, height, scrolledHandle); +// if (horizontalBar != null && horizontalBar.getVisible ()) { +// int horizontalHandle = horizontalBar.handle; +// short [] hscroll_x = new short [1], hscroll_y = new short [1]; +// OS.XtTranslateCoords (horizontalHandle, (short) 0, (short) 0, hscroll_x, hscroll_y); +// redrawHandle (root_x [0] - hscroll_x [0], root_y [0] - hscroll_y [0], width, height, horizontalHandle); +// } +// if (verticalBar != null && verticalBar.getVisible ()) { +// int verticalHandle = verticalBar.handle; +// short [] vscroll_x = new short [1], vscroll_y = new short [1]; +// OS.XtTranslateCoords (verticalHandle, (short) 0, (short) 0, vscroll_x, vscroll_y); +// redrawHandle (root_x [0] - vscroll_x [0], root_y [0] - vscroll_y [0], width, height, verticalHandle); +// } +// } +} +void register () { + super.register (); + if (formHandle != 0) WidgetTable.put (formHandle, this); + if (scrolledHandle != 0) WidgetTable.put (scrolledHandle, this); +} +void releaseHandle () { + super.releaseHandle (); + scrolledHandle = formHandle = 0; +} +void releaseWidget () { + if (horizontalBar != null) horizontalBar.releaseResources (); + if (verticalBar != null) verticalBar.releaseResources (); + horizontalBar = verticalBar = null; + super.releaseWidget (); +} +void setBackgroundPixel (int pixel) { + super.setBackgroundPixel (pixel); + if (scrolledHandle != 0) { + int [] argList1 = { + OS.XmNhorizontalScrollBar, 0, + OS.XmNverticalScrollBar, 0, + }; + OS.XtGetValues (scrolledHandle, argList1, argList1.length / 2); + if (argList1 [1] != 0) OS.XmChangeColor (argList1 [1], pixel); + if (argList1 [3] != 0) OS.XmChangeColor (argList1 [3], pixel); + } +} +void setScrollbarVisible (int barHandle, boolean visible) { + if (scrolledHandle == 0) return; + /* + * Feature in Motif. Hiding or showing a scroll bar + * can cause the widget to automatically resize in + * the OS. This behavior is unwanted. The fix is + * to force the widget to resize to original size. + */ + int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0}; + OS.XtGetValues (scrolledHandle, argList, argList.length / 2); + + /* Hide or show the scroll bar */ + if (visible) { + OS.XtManageChild (barHandle); + } else { + OS.XtUnmanageChild (barHandle); + } + + /* Restore the size */ + OS.XtSetValues (scrolledHandle, argList, argList.length / 2); +} +int topHandle () { + if (scrolledHandle != 0) return scrolledHandle; + if (formHandle != 0) return formHandle; + return handle; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java index a1acacf8bc..d98b21a6c2 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Shell.java @@ -1,120 +1,120 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent the "windows"
- * which the desktop or "window manager" is managing.
- * Instances that do not have a parent (that is, they
- * are built using the constructor, which takes a
- * <code>Display</code> as the argument) are described
- * as <em>top level</em> shells. Instances that do have
- * a parent are described as <em>secondary</em> or
- * <em>dialog</em> shells.
- * <p>
- * Instances are always displayed in one of the maximized,
- * minimized or normal states:
- * <ul>
- * <li>
- * When an instance is marked as <em>maximized</em>, the
- * window manager will typically resize it to fill the
- * entire visible area of the display, and the instance
- * is usually put in a state where it can not be resized
- * (even if it has style <code>RESIZE</code>) until it is
- * no longer maximized.
- * </li><li>
- * When an instance is in the <em>normal</em> state (neither
- * maximized or minimized), its appearance is controlled by
- * the style constants which were specified when it was created
- * and the restrictions of the window manager (see below).
- * </li><li>
- * When an instance has been marked as <em>minimized</em>,
- * its contents (client area) will usually not be visible,
- * and depending on the window manager, it may be
- * "iconified" (that is, replaced on the desktop by a small
- * simplified representation of itself), relocated to a
- * distinguished area of the screen, or hidden. Combinations
- * of these changes are also possible.
- * </li>
- * </ul>
- * </p>
- * <p>
- * 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>
- * Note: Only one of the styles APPLICATION_MODAL, MODELESS,
- * PRIMARY_MODAL and SYSTEM_MODAL may be specified.
- * </p><p>
- * IMPORTANT: This class is not intended to be subclassed.
- * </p>
- *
- * @see Decorations
- * @see SWT
+ * http://www.eclipse.org/legal/cpl-v10.html */ -public class Shell extends Decorations {
- Display display;
- int shellHandle;
- boolean reparented, realized, configured;
- int oldX, oldY, oldWidth, oldHeight;
- Control lastActive;
-
- static final byte [] WM_DELETE_WINDOW = Converter.wcsToMbcs(null, "WM_DELETE_WINDOW\0");
-/**
- * Constructs a new instance of this class. This is equivalent
- * to calling <code>Shell((Display) null)</code>.
- *
- * @exception SWTException <ul>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
- * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
- * </ul>
+ +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.events.*; + +/** + * Instances of this class represent the "windows" + * which the desktop or "window manager" is managing. + * Instances that do not have a parent (that is, they + * are built using the constructor, which takes a + * <code>Display</code> as the argument) are described + * as <em>top level</em> shells. Instances that do have + * a parent are described as <em>secondary</em> or + * <em>dialog</em> shells. + * <p> + * Instances are always displayed in one of the maximized, + * minimized or normal states: + * <ul> + * <li> + * When an instance is marked as <em>maximized</em>, the + * window manager will typically resize it to fill the + * entire visible area of the display, and the instance + * is usually put in a state where it can not be resized + * (even if it has style <code>RESIZE</code>) until it is + * no longer maximized. + * </li><li> + * When an instance is in the <em>normal</em> state (neither + * maximized or minimized), its appearance is controlled by + * the style constants which were specified when it was created + * and the restrictions of the window manager (see below). + * </li><li> + * When an instance has been marked as <em>minimized</em>, + * its contents (client area) will usually not be visible, + * and depending on the window manager, it may be + * "iconified" (that is, replaced on the desktop by a small + * simplified representation of itself), relocated to a + * distinguished area of the screen, or hidden. Combinations + * of these changes are also possible. + * </li> + * </ul> + * </p> + * <p> + * 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> + * Note: Only one of the styles APPLICATION_MODAL, MODELESS, + * PRIMARY_MODAL and SYSTEM_MODAL may be specified. + * </p><p> + * IMPORTANT: This class is not intended to be subclassed. + * </p> + * + * @see Decorations + * @see SWT + */ +public class Shell extends Decorations { + Display display; + int shellHandle; + boolean reparented, realized, configured; + int oldX, oldY, oldWidth, oldHeight; + Control lastActive; + + static final byte [] WM_DELETE_WINDOW = Converter.wcsToMbcs(null, "WM_DELETE_WINDOW\0"); +/** + * Constructs a new instance of this class. This is equivalent + * to calling <code>Shell((Display) null)</code>. + * + * @exception SWTException <ul> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li> + * <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li> + * </ul> */ -public Shell () {
- this ((Display) null);
-}
+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 @@ -150,31 +150,31 @@ public Shell () { * @see SWT#APPLICATION_MODAL * @see SWT#SYSTEM_MODAL */ -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 (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);
-}
+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 @@ -218,48 +218,48 @@ public Shell (Display display) { * @see SWT#APPLICATION_MODAL * @see SWT#SYSTEM_MODAL */ -public Shell (Display display, int style) {
- this (display, null, style, 0);
-}
-Shell (Display display, Shell parent, int style, int handle) {
- super ();
- checkSubclass ();
- 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 (Display display, int style) { + this (display, null, style, 0); +} +Shell (Display display, Shell parent, int style, int handle) { + super (); + checkSubclass (); + 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.DIALOG_TRIM);
-}
+public Shell (Shell parent) { + this (parent, SWT.DIALOG_TRIM); +} /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -302,180 +302,180 @@ public Shell (Shell parent) { * @see SWT#APPLICATION_MODAL * @see SWT#SYSTEM_MODAL */ -public Shell (Shell parent, int style) {
- this (parent != null ? parent.getDisplay () : null, parent, style, 0);
-}
-
-static int checkStyle (int style) {
- style = Decorations.checkStyle (style);
- if ((style & SWT.ON_TOP) != 0) style &= ~SWT.SHELL_TRIM;
- int mask = SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.PRIMARY_MODAL;
- int bits = style & ~mask;
- if ((style & SWT.SYSTEM_MODAL) != 0) return bits | SWT.SYSTEM_MODAL;
- if ((style & SWT.APPLICATION_MODAL) != 0) return bits | SWT.APPLICATION_MODAL;
- if ((style & SWT.PRIMARY_MODAL) != 0) return bits | SWT.PRIMARY_MODAL;
- return bits;
-}
-
-public static Shell motif_new (Display display, int handle) {
- return new Shell (display, null, SWT.NO_TRIM, handle);
-}
-
-/**
- * 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 Shell (Shell parent, int style) { + this (parent != null ? parent.getDisplay () : null, parent, style, 0); +} + +static int checkStyle (int style) { + style = Decorations.checkStyle (style); + if ((style & SWT.ON_TOP) != 0) style &= ~SWT.SHELL_TRIM; + int mask = SWT.SYSTEM_MODAL | SWT.APPLICATION_MODAL | SWT.PRIMARY_MODAL; + int bits = style & ~mask; + if ((style & SWT.SYSTEM_MODAL) != 0) return bits | SWT.SYSTEM_MODAL; + if ((style & SWT.APPLICATION_MODAL) != 0) return bits | SWT.APPLICATION_MODAL; + if ((style & SWT.PRIMARY_MODAL) != 0) return bits | SWT.PRIMARY_MODAL; + return bits; +} + +public static Shell motif_new (Display display, int handle) { + return new Shell (display, null, SWT.NO_TRIM, handle); +} + +/** + * Adds the listener to the collection of listeners who will + * be notified when operations are performed on the receiver, + * by sending the listener one of the messages defined in the + * <code>ShellListener</code> interface. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see ShellListener + * @see #removeShellListener */ -public void addShellListener(ShellListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener(SWT.Activate,typedListener);
- addListener(SWT.Close,typedListener);
- addListener(SWT.Deactivate,typedListener);
- addListener(SWT.Iconify,typedListener);
- addListener(SWT.Deiconify,typedListener);
-}
-void adjustTrim () {
- if (OS.XtIsSubclass (shellHandle, OS.OverrideShellWidgetClass ())) {
- return;
- }
- int [] argList = {OS.XmNoverrideRedirect, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- if (argList [1] != 0) return;
-
- /* Query the trim insets */
- int shellWindow = OS.XtWindow (shellHandle);
- if (shellWindow == 0) return;
- int xDisplay = OS.XtDisplay (shellHandle);
- if (xDisplay == 0) return;
-
- /* Find the direct child of the root window */
- int [] unused = new int [1];
- int [] rootWindow = new int [1];
- int [] parent = new int [1];
- int [] ptr = new int [1];
- int trimWindow = shellWindow;
- OS.XQueryTree (xDisplay, trimWindow, rootWindow, parent, ptr, unused);
- if (ptr [0] != 0) OS.XFree (ptr [0]);
- if (parent [0] == 0) return;
- while (parent [0] != rootWindow [0]) {
- trimWindow = parent [0];
- OS.XQueryTree (xDisplay, trimWindow, unused, parent, ptr, unused);
- if (ptr [0] != 0) OS.XFree (ptr [0]);
- if (parent [0] == 0) return;
- }
-
- /*
- * Translate the coordinates of the shell window to the
- * coordinates of the direct child of the root window
+public void addShellListener(ShellListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener (listener); + addListener(SWT.Activate,typedListener); + addListener(SWT.Close,typedListener); + addListener(SWT.Deactivate,typedListener); + addListener(SWT.Iconify,typedListener); + addListener(SWT.Deiconify,typedListener); +} +void adjustTrim () { + if (OS.XtIsSubclass (shellHandle, OS.OverrideShellWidgetClass ())) { + return; + } + int [] argList = {OS.XmNoverrideRedirect, 0}; + OS.XtGetValues (shellHandle, argList, argList.length / 2); + if (argList [1] != 0) return; + + /* Query the trim insets */ + int shellWindow = OS.XtWindow (shellHandle); + if (shellWindow == 0) return; + int xDisplay = OS.XtDisplay (shellHandle); + if (xDisplay == 0) return; + + /* Find the direct child of the root window */ + int [] unused = new int [1]; + int [] rootWindow = new int [1]; + int [] parent = new int [1]; + int [] ptr = new int [1]; + int trimWindow = shellWindow; + OS.XQueryTree (xDisplay, trimWindow, rootWindow, parent, ptr, unused); + if (ptr [0] != 0) OS.XFree (ptr [0]); + if (parent [0] == 0) return; + while (parent [0] != rootWindow [0]) { + trimWindow = parent [0]; + OS.XQueryTree (xDisplay, trimWindow, unused, parent, ptr, unused); + if (ptr [0] != 0) OS.XFree (ptr [0]); + if (parent [0] == 0) return; + } + + /* + * Translate the coordinates of the shell window to the + * coordinates of the direct child of the root window */ - if (shellWindow == trimWindow) return;
-
- /* Query the border width of the direct child of the root window */
- int [] trimBorder = new int [1];
- int [] trimWidth = new int [1];
- int [] trimHeight = new int [1];
- int [] trimX = new int [1];
- int [] trimY = new int [1];
- OS.XGetGeometry (xDisplay, trimWindow, unused, trimX, trimY, trimWidth, trimHeight, trimBorder, unused);
-
- /* Query the border width of the direct child of the shell window */
- int [] shellBorder = new int [1];
- int [] shellWidth = new int [1];
- int [] shellHeight = new int [1];
- OS.XGetGeometry (xDisplay, shellWindow, unused, unused, unused, shellWidth, shellHeight, shellBorder, unused);
-
- /* Query the trim-adjusted position of the inner window */
- short [] inner_x = new short [1], inner_y = new short [1];
- OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, inner_x, inner_y);
-
- /* Calculate the trim */
- int width = (trimWidth [0] + (trimBorder [0] * 2)) - (shellWidth [0] + (shellBorder [0] * 2));
- int height = (trimHeight [0] + (trimBorder [0] * 2)) - (shellHeight [0] + (shellBorder [0] * 2));
- int leftInset = inner_x [0] - trimX [0];
- int topInset = inner_y [0] - trimY [0];
-
- /* Update the trim guesses to match the query */
- boolean hasTitle = false, hasResize = false, hasBorder = false;
- if ((style & SWT.NO_TRIM) == 0) {
- hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0;
- hasResize = (style & SWT.RESIZE) != 0;
- hasBorder = (style & SWT.BORDER) != 0;
- }
- if (hasTitle) {
- if (hasResize) {
- display.leftTitleResizeWidth = leftInset;
- display.rightTitleResizeWidth = width - leftInset;
- display.topTitleResizeHeight = topInset;
- display.bottomTitleResizeHeight = height - topInset;
- return;
- }
- if (hasBorder) {
- display.leftTitleBorderWidth = leftInset;
- display.rightTitleBorderWidth = width - leftInset;
- display.topTitleBorderHeight = topInset;
- display.bottomTitleBorderHeight = height - topInset;
- return;
- }
- display.leftTitleWidth = leftInset;
- display.rightTitleWidth = width - leftInset;
- display.topTitleHeight = topInset;
- display.bottomTitleHeight = height - topInset;
- return;
- }
- if (hasResize) {
- display.leftResizeWidth = leftInset;
- display.rightResizeWidth = width - leftInset;
- display.topResizeHeight = topInset;
- display.bottomResizeHeight = height - topInset;
- return;
- }
- if (hasBorder) {
- display.leftBorderWidth = leftInset;
- display.rightBorderWidth = width - leftInset;
- display.topBorderHeight = topInset;
- display.bottomBorderHeight = height - topInset;
- return;
- }
-}
-void bringToTop (boolean force) {
- /*
- * Feature in X. Calling XSetInputFocus() when the
- * widget is not viewable causes an X bad match error.
- * The fix is to call XSetInputFocus() when the widget
- * is viewable.
- */
- if ((style & SWT.ON_TOP) != 0) return;
- if (minimized) return;
- if (!isVisible ()) return;
- int xDisplay = OS.XtDisplay (shellHandle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (shellHandle);
- if (xWindow == 0) return;
- if (!force) {
- int [] buffer1 = new int [1], buffer2 = new int [1];
- OS.XGetInputFocus (xDisplay, buffer1, buffer2);
- if (buffer1 [0] == 0) return;
- int handle = OS.XtWindowToWidget (xDisplay, buffer1 [0]);
- if (handle == 0) return;
- }
- OS.XSetInputFocus (xDisplay, xWindow, OS.RevertToParent, OS.CurrentTime);
-}
+ if (shellWindow == trimWindow) return; + + /* Query the border width of the direct child of the root window */ + int [] trimBorder = new int [1]; + int [] trimWidth = new int [1]; + int [] trimHeight = new int [1]; + int [] trimX = new int [1]; + int [] trimY = new int [1]; + OS.XGetGeometry (xDisplay, trimWindow, unused, trimX, trimY, trimWidth, trimHeight, trimBorder, unused); + + /* Query the border width of the direct child of the shell window */ + int [] shellBorder = new int [1]; + int [] shellWidth = new int [1]; + int [] shellHeight = new int [1]; + OS.XGetGeometry (xDisplay, shellWindow, unused, unused, unused, shellWidth, shellHeight, shellBorder, unused); + + /* Query the trim-adjusted position of the inner window */ + short [] inner_x = new short [1], inner_y = new short [1]; + OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, inner_x, inner_y); + + /* Calculate the trim */ + int width = (trimWidth [0] + (trimBorder [0] * 2)) - (shellWidth [0] + (shellBorder [0] * 2)); + int height = (trimHeight [0] + (trimBorder [0] * 2)) - (shellHeight [0] + (shellBorder [0] * 2)); + int leftInset = inner_x [0] - trimX [0]; + int topInset = inner_y [0] - trimY [0]; + + /* Update the trim guesses to match the query */ + boolean hasTitle = false, hasResize = false, hasBorder = false; + if ((style & SWT.NO_TRIM) == 0) { + hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0; + hasResize = (style & SWT.RESIZE) != 0; + hasBorder = (style & SWT.BORDER) != 0; + } + if (hasTitle) { + if (hasResize) { + display.leftTitleResizeWidth = leftInset; + display.rightTitleResizeWidth = width - leftInset; + display.topTitleResizeHeight = topInset; + display.bottomTitleResizeHeight = height - topInset; + return; + } + if (hasBorder) { + display.leftTitleBorderWidth = leftInset; + display.rightTitleBorderWidth = width - leftInset; + display.topTitleBorderHeight = topInset; + display.bottomTitleBorderHeight = height - topInset; + return; + } + display.leftTitleWidth = leftInset; + display.rightTitleWidth = width - leftInset; + display.topTitleHeight = topInset; + display.bottomTitleHeight = height - topInset; + return; + } + if (hasResize) { + display.leftResizeWidth = leftInset; + display.rightResizeWidth = width - leftInset; + display.topResizeHeight = topInset; + display.bottomResizeHeight = height - topInset; + return; + } + if (hasBorder) { + display.leftBorderWidth = leftInset; + display.rightBorderWidth = width - leftInset; + display.topBorderHeight = topInset; + display.bottomBorderHeight = height - topInset; + return; + } +} +void bringToTop (boolean force) { + /* + * Feature in X. Calling XSetInputFocus() when the + * widget is not viewable causes an X bad match error. + * The fix is to call XSetInputFocus() when the widget + * is viewable. + */ + if ((style & SWT.ON_TOP) != 0) return; + if (minimized) return; + if (!isVisible ()) return; + int xDisplay = OS.XtDisplay (shellHandle); + if (xDisplay == 0) return; + int xWindow = OS.XtWindow (shellHandle); + if (xWindow == 0) return; + if (!force) { + int [] buffer1 = new int [1], buffer2 = new int [1]; + OS.XGetInputFocus (xDisplay, buffer1, buffer2); + if (buffer1 [0] == 0) return; + int handle = OS.XtWindowToWidget (xDisplay, buffer1 [0]); + if (handle == 0) return; + } + OS.XSetInputFocus (xDisplay, xWindow, OS.RevertToParent, OS.CurrentTime); +} /** * Requests that the window manager close the receiver in * the same way it would be closed when the user clicks on @@ -490,914 +490,914 @@ void bringToTop (boolean force) { * * @see #dispose */ -public void close () {
- checkWidget();
- closeWidget ();
-}
-void closeWidget () {
- if (!isEnabled ()) return;
- Control widget = parent;
- while (widget != null && !(widget.getShell ().isModal ())) {
- widget = widget.parent;
- }
- if (widget == null) {
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (shell != this && shell.isModal () && shell.isVisible ()) {
- shell.bringToTop (false);
- return;
- }
- }
- }
- Event event = new Event ();
- sendEvent (SWT.Close, event);
- if (event.doit && !isDisposed ()) dispose ();
-}
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- Rectangle trim = super.computeTrim (x, y, width, height);
- /*
- * Feature in Motif. There is no way to get the single pixel border
- * surrounding a TopLevelShell or a TransientShell. Attempts to set a
- * border on either the shell handle or the main window handle fail.
- * The fix is to set the border on the client area. Therefore, the
- * border must be added back into the trim.
- */
- int border = 0;
- if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.RESIZE)) == 0) {
- int [] argList = {OS.XmNborderWidth, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- border = argList [1];
- }
- trim.x -= trimLeft ();
- trim.y -= trimTop ();
- trim.width += trimWidth () + (border * 2);
- trim.height += trimHeight () + imeHeight () + (border * 2);
- return trim;
-}
-void createHandle (int index) {
- state |= HANDLE | CANVAS;
- int decorations = 0;
- if ((style & SWT.NO_TRIM) == 0) {
- if ((style & SWT.MIN) != 0) decorations |= OS.MWM_DECOR_MINIMIZE;
- if ((style & SWT.MAX) != 0) decorations |= OS.MWM_DECOR_MAXIMIZE;
- if ((style & SWT.RESIZE) != 0) decorations |= OS.MWM_DECOR_RESIZEH;
- if ((style & SWT.BORDER) != 0) decorations |= OS.MWM_DECOR_BORDER;
- if ((style & SWT.MENU) != 0) decorations |= OS.MWM_DECOR_MENU;
- if ((style & SWT.TITLE) != 0) decorations |= OS.MWM_DECOR_TITLE;
- /*
- * Feature in Motif. Under some Window Managers (Sawmill), in order
- * to get any border at all from the window manager it is necessary
- * to set MWM_DECOR_BORDER. The fix is to force these bits when any
- * kind of border is requested.
- */
- if ((style & SWT.RESIZE) != 0) decorations |= OS.MWM_DECOR_BORDER;
- }
-
- /*
- * Note: Motif treats the modal values as hints to the Window Manager.
- * For example, Enlightenment treats all modes except for SWT.MODELESS
- * as SWT.APPLICATION_MODAL. The Motif Window Manager honours all modes.
- */
- int inputMode = OS.MWM_INPUT_MODELESS;
- if ((style & SWT.PRIMARY_MODAL) != 0) inputMode = OS.MWM_INPUT_PRIMARY_APPLICATION_MODAL;
- if ((style & SWT.APPLICATION_MODAL) != 0) inputMode = OS.MWM_INPUT_FULL_APPLICATION_MODAL;
- if ((style & SWT.SYSTEM_MODAL) != 0) inputMode = OS.MWM_INPUT_SYSTEM_MODAL;
-
- /*
- * Bug in Motif. For some reason, if the title string
- * length is not a multiple of 4, Motif occasionally
- * draws garbage after the last character in the title.
- * The fix is to pad the title.
- */
- byte [] buffer = {(byte)' ', 0, 0, 0};
- int ptr = OS.XtMalloc (buffer.length);
- OS.memmove (ptr, buffer, buffer.length);
- int [] argList1 = {
- OS.XmNmwmInputMode, inputMode,
- OS.XmNmwmDecorations, decorations,
- OS.XmNoverrideRedirect, (style & SWT.ON_TOP) != 0 ? 1 : 0,
- OS.XmNtitle, ptr,
- };
-
- /*
- * Feature in Motif. On some Window Managers, when a top level
- * shell is created with no decorations, the Window Manager does
- * not reparent the window regardless of the XmNoverrideRedirect
- * resource. The fix is to treat the window as if it has been
- * reparented by the Window Manager despite the fact that this
- * has not really happened.
- */
- int orientations = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT;
- if ((style & ~orientations) == SWT.NONE || (style & (SWT.NO_TRIM | SWT.ON_TOP)) != 0) {
- reparented = true;
- }
-
- /*
- * Feature in Motif. When a top level shell has no parent and is
- * application modal, Motif does not honour the modality. The fix
- * is to create the shell as a child of a hidden shell handle, the
- * same way that XmNoverrideRedirect shells without parents are
- * created.
- */
- byte [] appClass = display.appClass;
- if (parent == null && (style & SWT.ON_TOP) == 0 && inputMode != OS.MWM_INPUT_FULL_APPLICATION_MODAL) {
- int xDisplay = display.xDisplay;
- int widgetClass = OS.TopLevelShellWidgetClass ();
- shellHandle = OS.XtAppCreateShell (display.appName, appClass, widgetClass, xDisplay, argList1, argList1.length / 2);
- } else {
- int widgetClass = OS.TransientShellWidgetClass ();
-// if ((style & SWT.ON_TOP) != 0) {
-// widgetClass = OS.OverrideShellWidgetClass ();
-// }
- int parentHandle = display.shellHandle;
- if (parent != null) parentHandle = parent.handle;
- shellHandle = OS.XtCreatePopupShell (appClass, widgetClass, parentHandle, argList1, argList1.length / 2);
- }
- OS.XtFree (ptr);
- if (shellHandle == 0) error (SWT.ERROR_NO_HANDLES);
-
- /* Create scrolled handle */
- createScrolledHandle (shellHandle);
-
- /*
- * Feature in Motif. There is no way to get the single pixel
- * border surrounding a TopLevelShell or a TransientShell.
- * Attempts to set a border on either the shell handle
- * or the main window handle fail. The fix is to set the border
- * on the client area.
- */
- if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.RESIZE)) == 0) {
- int [] argList2 = {OS.XmNborderWidth, 1};
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- }
-
- /*
- * Feature in Motif. There is no Motif API to negociate for the
- * status line. The fix is to force the status line to appear
- * by creating a hidden text widget. This is much safer than
- * using X API because this may conflict with Motif.
- *
- * Note that XmNtraversalOn must be set to FALSE or the shell
- * will not take focus when the user clicks on it.
- */
- if ((style & SWT.ON_TOP) == 0) {
- int [] argList3 = {OS.XmNtraversalOn, 0};
- int textHandle = OS.XmCreateTextField (handle, null, argList3, argList3.length / 2);
- if (textHandle == 0) error (SWT.ERROR_NO_HANDLES);
- }
-}
-void deregister () {
- super.deregister ();
- WidgetTable.remove (shellHandle);
-}
-void destroyWidget () {
- /*
- * Hide the shell before calling XtDestroyWidget ()
- * so that the shell will disappear without having
- * to dispatch events. Otherwise, the user will be
- * able to interact with the trimmings between the
- * time that the shell is destroyed and the next
- * event is dispatched.
- */
- if (OS.XtIsRealized (shellHandle)) {
- if (OS.XtIsTopLevelShell (shellHandle)) {
- OS.XtUnmapWidget (shellHandle);
- } else {
- OS.XtPopdown (shellHandle);
- }
- }
- super.destroyWidget ();
-}
-
-public void dispose () {
- /*
- * Note: It is valid to attempt to dispose a widget
- * more than once. If this happens, fail silently.
- */
- if (isDisposed()) return;
-
- /*
- * This code is intentionally commented. On some
- * platforms, the owner window is repainted right
- * away when the dialog window exits. This behavior
- * is currently unspecified.
- */
-// if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
-// Display oldDisplay = display;
-
- /*
- * Feature in Motif. When an override-redirected shell
- * is disposed, Motif does not assign a new active top
- * level shell. The parent shell appears to be active,
- * but XGetInputFocus returns the root window, not the
- * parent. The fix is to make the parent be the active
- * top level shell when the child shell is disposed.
- *
- * Feature in Motif. When the active shell is disposed,
- * Motif assigns focus temporarily to the root window
- * unless it has previously been told to do otherwise.
- * The fix is to make the parent be the active top level
- * shell when the child shell is disposed.
- */
- if (parent != null) {
- int [] argList = {OS.XmNoverrideRedirect, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- Shell activeShell = display.getActiveShell ();
- if (argList [1] != 0 || activeShell == this) {
- Shell shell = parent.getShell ();
- shell.bringToTop (false);
- }
- }
- super.dispose ();
-
- /*
- * This code intentionally commented.
- */
-// if (oldDisplay != null) oldDisplay.update ();
-}
-void enableWidget (boolean enabled) {
- super.enableWidget (enabled);
- enableHandle (enabled, shellHandle);
-}
-/**
- * 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) and forces the window
- * manager to make the shell active.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton
- * @see Shell#open
- * @see Shell#setActive
+public void close () { + checkWidget(); + closeWidget (); +} +void closeWidget () { + if (!isEnabled ()) return; + Control widget = parent; + while (widget != null && !(widget.getShell ().isModal ())) { + widget = widget.parent; + } + if (widget == null) { + Shell [] shells = getShells (); + for (int i=0; i<shells.length; i++) { + Shell shell = shells [i]; + if (shell != this && shell.isModal () && shell.isVisible ()) { + shell.bringToTop (false); + return; + } + } + } + Event event = new Event (); + sendEvent (SWT.Close, event); + if (event.doit && !isDisposed ()) dispose (); +} +public Rectangle computeTrim (int x, int y, int width, int height) { + checkWidget(); + Rectangle trim = super.computeTrim (x, y, width, height); + /* + * Feature in Motif. There is no way to get the single pixel border + * surrounding a TopLevelShell or a TransientShell. Attempts to set a + * border on either the shell handle or the main window handle fail. + * The fix is to set the border on the client area. Therefore, the + * border must be added back into the trim. + */ + int border = 0; + if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.RESIZE)) == 0) { + int [] argList = {OS.XmNborderWidth, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + border = argList [1]; + } + trim.x -= trimLeft (); + trim.y -= trimTop (); + trim.width += trimWidth () + (border * 2); + trim.height += trimHeight () + imeHeight () + (border * 2); + return trim; +} +void createHandle (int index) { + state |= HANDLE | CANVAS; + int decorations = 0; + if ((style & SWT.NO_TRIM) == 0) { + if ((style & SWT.MIN) != 0) decorations |= OS.MWM_DECOR_MINIMIZE; + if ((style & SWT.MAX) != 0) decorations |= OS.MWM_DECOR_MAXIMIZE; + if ((style & SWT.RESIZE) != 0) decorations |= OS.MWM_DECOR_RESIZEH; + if ((style & SWT.BORDER) != 0) decorations |= OS.MWM_DECOR_BORDER; + if ((style & SWT.MENU) != 0) decorations |= OS.MWM_DECOR_MENU; + if ((style & SWT.TITLE) != 0) decorations |= OS.MWM_DECOR_TITLE; + /* + * Feature in Motif. Under some Window Managers (Sawmill), in order + * to get any border at all from the window manager it is necessary + * to set MWM_DECOR_BORDER. The fix is to force these bits when any + * kind of border is requested. + */ + if ((style & SWT.RESIZE) != 0) decorations |= OS.MWM_DECOR_BORDER; + } + + /* + * Note: Motif treats the modal values as hints to the Window Manager. + * For example, Enlightenment treats all modes except for SWT.MODELESS + * as SWT.APPLICATION_MODAL. The Motif Window Manager honours all modes. + */ + int inputMode = OS.MWM_INPUT_MODELESS; + if ((style & SWT.PRIMARY_MODAL) != 0) inputMode = OS.MWM_INPUT_PRIMARY_APPLICATION_MODAL; + if ((style & SWT.APPLICATION_MODAL) != 0) inputMode = OS.MWM_INPUT_FULL_APPLICATION_MODAL; + if ((style & SWT.SYSTEM_MODAL) != 0) inputMode = OS.MWM_INPUT_SYSTEM_MODAL; + + /* + * Bug in Motif. For some reason, if the title string + * length is not a multiple of 4, Motif occasionally + * draws garbage after the last character in the title. + * The fix is to pad the title. + */ + byte [] buffer = {(byte)' ', 0, 0, 0}; + int ptr = OS.XtMalloc (buffer.length); + OS.memmove (ptr, buffer, buffer.length); + int [] argList1 = { + OS.XmNmwmInputMode, inputMode, + OS.XmNmwmDecorations, decorations, + OS.XmNoverrideRedirect, (style & SWT.ON_TOP) != 0 ? 1 : 0, + OS.XmNtitle, ptr, + }; + + /* + * Feature in Motif. On some Window Managers, when a top level + * shell is created with no decorations, the Window Manager does + * not reparent the window regardless of the XmNoverrideRedirect + * resource. The fix is to treat the window as if it has been + * reparented by the Window Manager despite the fact that this + * has not really happened. + */ + int orientations = SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT; + if ((style & ~orientations) == SWT.NONE || (style & (SWT.NO_TRIM | SWT.ON_TOP)) != 0) { + reparented = true; + } + + /* + * Feature in Motif. When a top level shell has no parent and is + * application modal, Motif does not honour the modality. The fix + * is to create the shell as a child of a hidden shell handle, the + * same way that XmNoverrideRedirect shells without parents are + * created. + */ + byte [] appClass = display.appClass; + if (parent == null && (style & SWT.ON_TOP) == 0 && inputMode != OS.MWM_INPUT_FULL_APPLICATION_MODAL) { + int xDisplay = display.xDisplay; + int widgetClass = OS.TopLevelShellWidgetClass (); + shellHandle = OS.XtAppCreateShell (display.appName, appClass, widgetClass, xDisplay, argList1, argList1.length / 2); + } else { + int widgetClass = OS.TransientShellWidgetClass (); +// if ((style & SWT.ON_TOP) != 0) { +// widgetClass = OS.OverrideShellWidgetClass (); +// } + int parentHandle = display.shellHandle; + if (parent != null) parentHandle = parent.handle; + shellHandle = OS.XtCreatePopupShell (appClass, widgetClass, parentHandle, argList1, argList1.length / 2); + } + OS.XtFree (ptr); + if (shellHandle == 0) error (SWT.ERROR_NO_HANDLES); + + /* Create scrolled handle */ + createScrolledHandle (shellHandle); + + /* + * Feature in Motif. There is no way to get the single pixel + * border surrounding a TopLevelShell or a TransientShell. + * Attempts to set a border on either the shell handle + * or the main window handle fail. The fix is to set the border + * on the client area. + */ + if ((style & (SWT.NO_TRIM | SWT.BORDER | SWT.RESIZE)) == 0) { + int [] argList2 = {OS.XmNborderWidth, 1}; + OS.XtSetValues (handle, argList2, argList2.length / 2); + } + + /* + * Feature in Motif. There is no Motif API to negociate for the + * status line. The fix is to force the status line to appear + * by creating a hidden text widget. This is much safer than + * using X API because this may conflict with Motif. + * + * Note that XmNtraversalOn must be set to FALSE or the shell + * will not take focus when the user clicks on it. + */ + if ((style & SWT.ON_TOP) == 0) { + int [] argList3 = {OS.XmNtraversalOn, 0}; + int textHandle = OS.XmCreateTextField (handle, null, argList3, argList3.length / 2); + if (textHandle == 0) error (SWT.ERROR_NO_HANDLES); + } +} +void deregister () { + super.deregister (); + WidgetTable.remove (shellHandle); +} +void destroyWidget () { + /* + * Hide the shell before calling XtDestroyWidget () + * so that the shell will disappear without having + * to dispatch events. Otherwise, the user will be + * able to interact with the trimmings between the + * time that the shell is destroyed and the next + * event is dispatched. + */ + if (OS.XtIsRealized (shellHandle)) { + if (OS.XtIsTopLevelShell (shellHandle)) { + OS.XtUnmapWidget (shellHandle); + } else { + OS.XtPopdown (shellHandle); + } + } + super.destroyWidget (); +} + +public void dispose () { + /* + * Note: It is valid to attempt to dispose a widget + * more than once. If this happens, fail silently. + */ + if (isDisposed()) return; + + /* + * This code is intentionally commented. On some + * platforms, the owner window is repainted right + * away when the dialog window exits. This behavior + * is currently unspecified. + */ +// if (!isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); +// Display oldDisplay = display; + + /* + * Feature in Motif. When an override-redirected shell + * is disposed, Motif does not assign a new active top + * level shell. The parent shell appears to be active, + * but XGetInputFocus returns the root window, not the + * parent. The fix is to make the parent be the active + * top level shell when the child shell is disposed. + * + * Feature in Motif. When the active shell is disposed, + * Motif assigns focus temporarily to the root window + * unless it has previously been told to do otherwise. + * The fix is to make the parent be the active top level + * shell when the child shell is disposed. + */ + if (parent != null) { + int [] argList = {OS.XmNoverrideRedirect, 0}; + OS.XtGetValues (shellHandle, argList, argList.length / 2); + Shell activeShell = display.getActiveShell (); + if (argList [1] != 0 || activeShell == this) { + Shell shell = parent.getShell (); + shell.bringToTop (false); + } + } + super.dispose (); + + /* + * This code intentionally commented. + */ +// if (oldDisplay != null) oldDisplay.update (); +} +void enableWidget (boolean enabled) { + super.enableWidget (enabled); + enableHandle (enabled, shellHandle); +} +/** + * 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) and forces the window + * manager to make the shell active. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 2.0 + * @see Control#moveAbove + * @see Control#setFocus + * @see Control#setVisible + * @see Display#getActiveShell + * @see Decorations#setDefaultButton + * @see Shell#open + * @see Shell#setActive */ -public void forceActive () {
- checkWidget ();
- bringToTop (true);
-}
-public int getBorderWidth () {
- checkWidget();
- int [] argList = {OS.XmNborderWidth, 0};
- OS.XtGetValues (scrolledHandle, argList, argList.length / 2);
- return argList [1];
-}
-public Rectangle getBounds () {
- checkWidget();
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, root_x, root_y);
- if (reparented) {
- root_x [0] -= trimLeft ();
- root_y [0] -= trimTop ();
- }
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- int border = argList [5];
- int trimWidth = trimWidth (), trimHeight = trimHeight ();
- int width = argList [1] + trimWidth + (border * 2);
- int height = argList [3] + trimHeight + (border * 2);
- return new Rectangle (root_x [0], root_y [0], width, height);
-}
-public Display getDisplay () {
- if (display == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return display;
-}
-/**
- * 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 void forceActive () { + checkWidget (); + bringToTop (true); +} +public int getBorderWidth () { + checkWidget(); + int [] argList = {OS.XmNborderWidth, 0}; + OS.XtGetValues (scrolledHandle, argList, argList.length / 2); + return argList [1]; +} +public Rectangle getBounds () { + checkWidget(); + short [] root_x = new short [1], root_y = new short [1]; + OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, root_x, root_y); + if (reparented) { + root_x [0] -= trimLeft (); + root_y [0] -= trimTop (); + } + int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; + OS.XtGetValues (shellHandle, argList, argList.length / 2); + int border = argList [5]; + int trimWidth = trimWidth (), trimHeight = trimHeight (); + int width = argList [1] + trimWidth + (border * 2); + int height = argList [3] + trimHeight + (border * 2); + return new Rectangle (root_x [0], root_y [0], width, height); +} +public Display getDisplay () { + if (display == null) error (SWT.ERROR_WIDGET_DISPOSED); + return display; +} +/** + * Returns the receiver's input method editor mode. This + * will be the result of bitwise OR'ing together one or + * more of the following constants defined in class + * <code>SWT</code>: + * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>, + * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>. + * + * @return the IME mode + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see SWT */ -public int getImeInputMode () {
- checkWidget();
- return SWT.NONE;
-}
-public Point getLocation () {
- checkWidget();
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, root_x, root_y);
- if (reparented) {
- root_x [0] -= trimLeft ();
- root_y [0] -= trimTop ();
- }
- return new Point (root_x [0], root_y [0]);
-}
-public Shell getShell () {
- checkWidget();
- 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 int getImeInputMode () { + checkWidget(); + return SWT.NONE; +} +public Point getLocation () { + checkWidget(); + short [] root_x = new short [1], root_y = new short [1]; + OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, root_x, root_y); + if (reparented) { + root_x [0] -= trimLeft (); + root_y [0] -= trimTop (); + } + return new Point (root_x [0], root_y [0]); +} +public Shell getShell () { + checkWidget(); + 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.parent;
- } while (shell != null && shell != this);
- if (shell == this) count++;
- }
- int index = 0;
- Shell [] result = new Shell [count];
- for (int i=0; i<shells.length; i++) {
- Control shell = shells [i];
- do {
- shell = shell.parent;
- } while (shell != null && shell != this);
- if (shell == this) {
- result [index++] = shells [i];
- }
- }
- return result;
-}
-public Point getSize () {
- checkWidget();
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- int border = argList [5];
- int trimWidth = trimWidth (), trimHeight = trimHeight ();
- int width = argList [1] + trimWidth + (border * 2);
- int height = argList [3] + trimHeight + (border * 2);
- return new Point (width, height);
-}
-public boolean getVisible () {
- checkWidget();
- if (!OS.XtIsRealized (handle)) return false;
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return false;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return false;
- XWindowAttributes attributes = new XWindowAttributes ();
- OS.XGetWindowAttributes (xDisplay, xWindow, attributes);
- if (attributes.map_state == OS.IsViewable && reparented) return true;
- int [] argList = {OS.XmNmappedWhenManaged, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- return minimized && attributes.map_state == OS.IsUnviewable && argList [1] != 0;
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = display.windowProc;
- OS.XtInsertEventHandler (shellHandle, OS.StructureNotifyMask, false, windowProc, STRUCTURE_NOTIFY, OS.XtListTail);
- if (OS.XtIsSubclass (shellHandle, OS.OverrideShellWidgetClass ())) return;
- OS.XtInsertEventHandler (shellHandle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail);
- int [] argList = {OS.XmNdeleteResponse, OS.XmDO_NOTHING};
- OS.XtSetValues (shellHandle, argList, argList.length / 2);
- int xDisplay = OS.XtDisplay (shellHandle);
- if (xDisplay != 0) {
- int atom = OS.XmInternAtom (xDisplay, WM_DELETE_WINDOW, false);
- OS.XmAddWMProtocolCallback (shellHandle, atom, windowProc, DELETE_WINDOW);
- }
-}
-int imeHeight () {
- if (!OS.IsDBLocale) return 0;
- int [] argList1 = {OS.XmNheight, 0};
- OS.XtGetValues (shellHandle, argList1, argList1.length / 2);
- int [] argList2 = {OS.XmNheight, 0};
- OS.XtGetValues (scrolledHandle, argList2, argList2.length / 2);
- return argList1 [1] - argList2 [1];
-}
-public boolean isEnabled () {
- checkWidget();
- return getEnabled ();
-}
-boolean isModal () {
- checkWidget();
- int [] argList = {OS.XmNmwmInputMode, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- return (argList [1] != -1 && argList [1] != OS.MWM_INPUT_MODELESS);
-}
-public boolean isVisible () {
- checkWidget();
- return getVisible ();
-}
-void manageChildren () {
- OS.XtSetMappedWhenManaged (shellHandle, false);
- super.manageChildren ();
- int xDisplay = OS.XtDisplay (shellHandle);
- if (xDisplay == 0) return;
- int width = OS.XDisplayWidth (xDisplay, OS.XDefaultScreen (xDisplay)) * 5 / 8;
- int height = OS.XDisplayHeight (xDisplay, OS.XDefaultScreen (xDisplay)) * 5 / 8;
- OS.XtResizeWidget (shellHandle, width, height, 0);
-}
-/**
- * Moves the receiver to the top of the drawing order for
- * the display on which it was created (so that all other
- * shells on that display, which are not the receiver's
- * children will be drawn behind it), marks it visible,
- * and sets focus to its default button (if it has one)
- * and asks the window manager to make the shell active.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton
- * @see Shell#setActive
- * @see Shell#forceActive
+public Shell [] getShells () { + checkWidget(); + int count = 0; + Shell [] shells = display.getShells (); + for (int i=0; i<shells.length; i++) { + Control shell = shells [i]; + do { + shell = shell.parent; + } while (shell != null && shell != this); + if (shell == this) count++; + } + int index = 0; + Shell [] result = new Shell [count]; + for (int i=0; i<shells.length; i++) { + Control shell = shells [i]; + do { + shell = shell.parent; + } while (shell != null && shell != this); + if (shell == this) { + result [index++] = shells [i]; + } + } + return result; +} +public Point getSize () { + checkWidget(); + int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0, OS.XmNborderWidth, 0}; + OS.XtGetValues (shellHandle, argList, argList.length / 2); + int border = argList [5]; + int trimWidth = trimWidth (), trimHeight = trimHeight (); + int width = argList [1] + trimWidth + (border * 2); + int height = argList [3] + trimHeight + (border * 2); + return new Point (width, height); +} +public boolean getVisible () { + checkWidget(); + if (!OS.XtIsRealized (handle)) return false; + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return false; + int xWindow = OS.XtWindow (handle); + if (xWindow == 0) return false; + XWindowAttributes attributes = new XWindowAttributes (); + OS.XGetWindowAttributes (xDisplay, xWindow, attributes); + if (attributes.map_state == OS.IsViewable && reparented) return true; + int [] argList = {OS.XmNmappedWhenManaged, 0}; + OS.XtGetValues (shellHandle, argList, argList.length / 2); + return minimized && attributes.map_state == OS.IsUnviewable && argList [1] != 0; +} +void hookEvents () { + super.hookEvents (); + int windowProc = display.windowProc; + OS.XtInsertEventHandler (shellHandle, OS.StructureNotifyMask, false, windowProc, STRUCTURE_NOTIFY, OS.XtListTail); + if (OS.XtIsSubclass (shellHandle, OS.OverrideShellWidgetClass ())) return; + OS.XtInsertEventHandler (shellHandle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail); + int [] argList = {OS.XmNdeleteResponse, OS.XmDO_NOTHING}; + OS.XtSetValues (shellHandle, argList, argList.length / 2); + int xDisplay = OS.XtDisplay (shellHandle); + if (xDisplay != 0) { + int atom = OS.XmInternAtom (xDisplay, WM_DELETE_WINDOW, false); + OS.XmAddWMProtocolCallback (shellHandle, atom, windowProc, DELETE_WINDOW); + } +} +int imeHeight () { + if (!OS.IsDBLocale) return 0; + int [] argList1 = {OS.XmNheight, 0}; + OS.XtGetValues (shellHandle, argList1, argList1.length / 2); + int [] argList2 = {OS.XmNheight, 0}; + OS.XtGetValues (scrolledHandle, argList2, argList2.length / 2); + return argList1 [1] - argList2 [1]; +} +public boolean isEnabled () { + checkWidget(); + return getEnabled (); +} +boolean isModal () { + checkWidget(); + int [] argList = {OS.XmNmwmInputMode, 0}; + OS.XtGetValues (shellHandle, argList, argList.length / 2); + return (argList [1] != -1 && argList [1] != OS.MWM_INPUT_MODELESS); +} +public boolean isVisible () { + checkWidget(); + return getVisible (); +} +void manageChildren () { + OS.XtSetMappedWhenManaged (shellHandle, false); + super.manageChildren (); + int xDisplay = OS.XtDisplay (shellHandle); + if (xDisplay == 0) return; + int width = OS.XDisplayWidth (xDisplay, OS.XDefaultScreen (xDisplay)) * 5 / 8; + int height = OS.XDisplayHeight (xDisplay, OS.XDefaultScreen (xDisplay)) * 5 / 8; + OS.XtResizeWidget (shellHandle, width, height, 0); +} +/** + * Moves the receiver to the top of the drawing order for + * the display on which it was created (so that all other + * shells on that display, which are not the receiver's + * children will be drawn behind it), marks it visible, + * and sets focus to its default button (if it has one) + * and asks the window manager to make the shell active. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see Control#moveAbove + * @see Control#setFocus + * @see Control#setVisible + * @see Display#getActiveShell + * @see Decorations#setDefaultButton + * @see Shell#setActive + * @see Shell#forceActive */ -public void open () {
- checkWidget();
- setVisible (true);
- if (!restoreFocus ()) traverseGroup (true);
-}
-void propagateWidget (boolean enabled) {
- super.propagateWidget (enabled);
- propagateHandle (enabled, shellHandle);
-}
-void realizeWidget () {
- if (realized) return;
- OS.XtRealizeWidget (shellHandle);
- realizeChildren ();
- realized = true;
-}
-void register () {
- super.register ();
- WidgetTable.put (shellHandle, this);
-}
-void releaseHandle () {
- super.releaseHandle ();
- shellHandle = 0;
-}
-void releaseShells () {
- Shell [] shells = getShells ();
- for (int i=0; i<shells.length; i++) {
- Shell shell = shells [i];
- if (!shell.isDisposed ()) shell.releaseResources ();
- }
-}
-void releaseWidget () {
- releaseShells ();
- super.releaseWidget ();
- display = null;
- lastActive = null;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when operations are performed on the receiver.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ShellListener
- * @see #addShellListener
+public void open () { + checkWidget(); + setVisible (true); + if (!restoreFocus ()) traverseGroup (true); +} +void propagateWidget (boolean enabled) { + super.propagateWidget (enabled); + propagateHandle (enabled, shellHandle); +} +void realizeWidget () { + if (realized) return; + OS.XtRealizeWidget (shellHandle); + realizeChildren (); + realized = true; +} +void register () { + super.register (); + WidgetTable.put (shellHandle, this); +} +void releaseHandle () { + super.releaseHandle (); + shellHandle = 0; +} +void releaseShells () { + Shell [] shells = getShells (); + for (int i=0; i<shells.length; i++) { + Shell shell = shells [i]; + if (!shell.isDisposed ()) shell.releaseResources (); + } +} +void releaseWidget () { + releaseShells (); + super.releaseWidget (); + display = null; + lastActive = null; +} +/** + * Removes the listener from the collection of listeners who will + * be notified when operations are performed on the receiver. + * + * @param listener the listener which should no longer be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see ShellListener + * @see #addShellListener */ -public void removeShellListener(ShellListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook(SWT.Activate, listener);
- eventTable.unhook(SWT.Close, listener);
- eventTable.unhook(SWT.Deactivate, listener);
- eventTable.unhook(SWT.Iconify,listener);
- eventTable.unhook(SWT.Deiconify,listener);
-}
-void saveBounds () {
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, root_x, root_y);
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- oldX = root_x [0];
- oldY = root_y [0];
- oldWidth = argList [1];
- oldHeight = argList [3];
-}
-
-/**
- * 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) and asks the window
- * manager to make the shell active.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @since 2.0
- * @see Control#moveAbove
- * @see Control#setFocus
- * @see Control#setVisible
- * @see Display#getActiveShell
- * @see Decorations#setDefaultButton
- * @see Shell#open
- * @see Shell#setActive
+public void removeShellListener(ShellListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook(SWT.Activate, listener); + eventTable.unhook(SWT.Close, listener); + eventTable.unhook(SWT.Deactivate, listener); + eventTable.unhook(SWT.Iconify,listener); + eventTable.unhook(SWT.Deiconify,listener); +} +void saveBounds () { + short [] root_x = new short [1], root_y = new short [1]; + OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, root_x, root_y); + int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0}; + OS.XtGetValues (shellHandle, argList, argList.length / 2); + oldX = root_x [0]; + oldY = root_y [0]; + oldWidth = argList [1]; + oldHeight = argList [3]; +} + +/** + * 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) and asks the window + * manager to make the shell active. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @since 2.0 + * @see Control#moveAbove + * @see Control#setFocus + * @see Control#setVisible + * @see Display#getActiveShell + * @see Decorations#setDefaultButton + * @see Shell#open + * @see Shell#setActive */ -public void setActive () {
- checkWidget ();
- bringToTop (false);
-}
-
-void setActiveControl (Control control) {
- if (control != null && control.isDisposed ()) control = null;
- if (lastActive != null && lastActive.isDisposed ()) lastActive = null;
- if (lastActive == control) return;
-
- /*
- * Compute the list of controls to be activated and
- * deactivated by finding the first common parent
- * control.
- */
- Control [] activate = (control == null) ? new Control[0] : control.getPath ();
- Control [] deactivate = (lastActive == null) ? new Control[0] : lastActive.getPath ();
- lastActive = control;
- int index = 0, length = Math.min (activate.length, deactivate.length);
- while (index < length) {
- if (activate [index] != deactivate [index]) break;
- index++;
- }
-
- /*
- * It is possible (but unlikely), that application
- * code could have destroyed some of the widgets. If
- * this happens, keep processing those widgets that
- * are not disposed.
- */
- for (int i=deactivate.length-1; i>=index; --i) {
- if (!deactivate [i].isDisposed ()) {
- if (display.postFocusOut) {
- deactivate [i].postEvent (SWT.Deactivate);
- } else {
- deactivate [i].sendEvent (SWT.Deactivate);
- }
- }
- }
- for (int i=activate.length-1; i>=index; --i) {
- if (!activate [i].isDisposed ()) {
- activate [i].sendEvent (SWT.Activate);
- }
- }
-}
-/**
- * Sets the 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 setActive () { + checkWidget (); + bringToTop (false); +} + +void setActiveControl (Control control) { + if (control != null && control.isDisposed ()) control = null; + if (lastActive != null && lastActive.isDisposed ()) lastActive = null; + if (lastActive == control) return; + + /* + * Compute the list of controls to be activated and + * deactivated by finding the first common parent + * control. + */ + Control [] activate = (control == null) ? new Control[0] : control.getPath (); + Control [] deactivate = (lastActive == null) ? new Control[0] : lastActive.getPath (); + lastActive = control; + int index = 0, length = Math.min (activate.length, deactivate.length); + while (index < length) { + if (activate [index] != deactivate [index]) break; + index++; + } + + /* + * It is possible (but unlikely), that application + * code could have destroyed some of the widgets. If + * this happens, keep processing those widgets that + * are not disposed. + */ + for (int i=deactivate.length-1; i>=index; --i) { + if (!deactivate [i].isDisposed ()) { + if (display.postFocusOut) { + deactivate [i].postEvent (SWT.Deactivate); + } else { + deactivate [i].sendEvent (SWT.Deactivate); + } + } + } + for (int i=activate.length-1; i>=index; --i) { + if (!activate [i].isDisposed ()) { + activate [i].sendEvent (SWT.Activate); + } + } +} +/** + * Sets the input method editor mode to the argument which + * should be the result of bitwise OR'ing together one or more + * of the following constants defined in class <code>SWT</code>: + * <code>NONE</code>, <code>ROMAN</code>, <code>DBCS</code>, + * <code>PHONETIC</code>, <code>NATIVE</code>, <code>ALPHA</code>. + * + * @param mode the new IME mode + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see SWT */ -public void setImeInputMode (int mode) {
- checkWidget();
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- if (resize) {
- /*
- * Feature in Motif. Motif will not allow a window
- * to have a zero width or zero height. The fix is
- * to ensure these values are never zero.
- */
- width = Math.max (width - trimWidth (), 1);
- height = Math.max (height - trimHeight (), 1);
- }
- if (!reparented || !OS.XtIsRealized (shellHandle)) {
- return super.setBounds (x, y, width, height, move, resize);
- }
- if (move) {
- x += trimLeft ();
- y += trimTop ();
- }
- if (!configured) saveBounds ();
- configured = true;
- boolean isFocus = caret != null && caret.isFocusCaret ();
- if (isFocus) caret.killFocus ();
- if (move && resize) {
- OS.XtConfigureWidget (shellHandle, x, y, width, height, 0);
- } else {
- if (move) OS.XtMoveWidget (shellHandle, x, y);
- if (resize) OS.XtResizeWidget (shellHandle, width, height, 0);
- }
- if (isFocus) caret.setFocus ();
- return move || resize;
-}
-public void setMinimized (boolean minimized) {
- checkWidget();
-
- /*
- * Bug in MOTIF. For some reason, the receiver does not keep the
- * value of the XmNiconic resource up to date when the user minimizes
- * and restores the window. As a result, a window that is minimized
- * by the user and then restored by the programmer is not restored.
- * This happens because the XmNiconic resource is unchanged when the
- * window is minimized by the user and subsequent attempts to set the
- * resource fail because the new value of the resource is the same as
- * the old value. The fix is to force XmNiconic to be up to date
- * before setting the desired value.
- */
- int [] argList = {OS.XmNiconic, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- if ((argList [1] != 0) != this.minimized) {
- argList [1] = this.minimized ? 1 : 0;
- OS.XtSetValues (shellHandle, argList, argList.length / 2);
- }
-
- /* Minimize or restore the shell */
- argList [1] = (this.minimized = minimized) ? 1 : 0;
- OS.XtSetValues (shellHandle, argList, argList.length / 2);
-
- /* Force the XWindowAttributes to be up to date */
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay != 0) OS.XSync (xDisplay, false);
-}
-void setParentTraversal () {
- /* Do nothing - Child shells do not affect the traversal of their parent shell */
-}
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- super.setText (string);
-
- /*
- * Feature in Motif. It is not possible to set a shell
- * title to an empty string. The fix is to set the title
- * to be a single space.
- */
- /* Use the character encoding for the default locale */
- if (string.length () == 0) string = " ";
- byte [] buffer1 = Converter.wcsToMbcs (null, string, true);
- int length = buffer1.length - 1;
-
- /*
- * Bug in Motif. For some reason, if the title string
- * length is not a multiple of 4, Motif occasionally
- * draws garbage after the last character in the title.
- * The fix is to pad the title.
- */
- byte [] buffer2 = buffer1;
- if ((length % 4) != 0) {
- buffer2 = new byte [(length + 3) / 4 * 4];
- System.arraycopy (buffer1, 0, buffer2, 0, length);
- }
-
- /* Set the title for the shell */
- int ptr = OS.XtMalloc (buffer2.length + 1);
- OS.memmove (ptr, buffer2, buffer2.length);
- int [] argList = {OS.XmNtitle, ptr};
- OS.XtSetValues (shellHandle, argList, argList.length / 2);
- OS.XtFree (ptr);
-}
-public void setVisible (boolean visible) {
- checkWidget();
- realizeWidget ();
-
- /* Show the shell */
- if (visible) {
-
- /* Map the widget */
- OS.XtSetMappedWhenManaged (shellHandle, true);
- if (OS.XtIsTopLevelShell (shellHandle)) {
- OS.XtMapWidget (shellHandle);
- } else {
- OS.XtPopup (shellHandle, OS.XtGrabNone);
- }
-
- /*
- * Force the shell to be fully exposed before returning.
- * This ensures that the shell coordinates are correct
- * when queried directly after showing the shell.
- */
- do {
- display.update ();
- } while (!isVisible ());
- adjustTrim ();
-
- sendEvent (SWT.Show);
- return;
- }
-
- /* Hide the shell */
- OS.XtSetMappedWhenManaged (shellHandle, false);
- if (OS.XtIsTopLevelShell (shellHandle)) {
- OS.XtUnmapWidget (shellHandle);
- } else {
- OS.XtPopdown (shellHandle);
- }
-
- /* If the shell is iconified, hide the icon */
- int xDisplay = OS.XtDisplay (shellHandle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (shellHandle);
- if (xWindow == 0) return;
- OS.XWithdrawWindow (xDisplay, xWindow, OS.XDefaultScreen (xDisplay));
-
- sendEvent (SWT.Hide);
-}
-void setZOrder (Control control, boolean above) {
- setZOrder (control, above, false);
-}
-int topHandle () {
- return shellHandle;
-}
-boolean traverseEscape () {
- if (parent == null) return false;
- if (!isVisible () || !isEnabled ()) return false;
- close ();
- return true;
-}
-int trimHeight () {
- if ((style & SWT.NO_TRIM) != 0) return 0;
- boolean hasTitle = false, hasResize = false, hasBorder = false;
- hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0;
- hasResize = (style & SWT.RESIZE) != 0;
- hasBorder = (style & SWT.BORDER) != 0;
- if (hasTitle) {
- if (hasResize) {
- return display.topTitleResizeHeight + display.bottomTitleResizeHeight;
- }
- if (hasBorder) {
- return display.topTitleBorderHeight + display.bottomTitleBorderHeight;
- }
- return display.topTitleHeight + display.bottomTitleHeight;
- }
- if (hasResize) {
- return display.topResizeHeight + display.bottomResizeHeight;
- }
- if (hasBorder) {
- return display.topBorderHeight + display.bottomBorderHeight;
- }
- return 0;
-}
-int trimLeft () {
- if ((style & SWT.NO_TRIM) != 0) return 0;
- boolean hasTitle = false, hasResize = false, hasBorder = false;
- hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0;
- hasResize = (style & SWT.RESIZE) != 0;
- hasBorder = (style & SWT.BORDER) != 0;
- if (hasTitle) {
- if (hasResize) return display.leftTitleResizeWidth;
- if (hasBorder) return display.leftTitleBorderWidth;
- return display.leftTitleWidth;
- }
- if (hasResize) return display.leftResizeWidth;
- if (hasBorder) return display.leftBorderWidth;
- return 0;
-}
-int trimTop () {
- if ((style & SWT.NO_TRIM) != 0) return 0;
- boolean hasTitle = false, hasResize = false, hasBorder = false;
- hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0;
- hasResize = (style & SWT.RESIZE) != 0;
- hasBorder = (style & SWT.BORDER) != 0;
- if (hasTitle) {
- if (hasResize) return display.topTitleResizeHeight;
- if (hasBorder) return display.topTitleBorderHeight;
- return display.topTitleHeight;
- }
- if (hasResize) return display.topResizeHeight;
- if (hasBorder) return display.topBorderHeight;
- return 0;
-}
-int trimWidth () {
- if ((style & SWT.NO_TRIM) != 0) return 0;
- boolean hasTitle = false, hasResize = false, hasBorder = false;
- hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0;
- hasResize = (style & SWT.RESIZE) != 0;
- hasBorder = (style & SWT.BORDER) != 0;
- if (hasTitle) {
- if (hasResize) {
- return display.leftTitleResizeWidth + display.rightTitleResizeWidth;
- }
- if (hasBorder) {
- return display.leftTitleBorderWidth + display.rightTitleBorderWidth;
- }
- return display.leftTitleWidth + display.rightTitleWidth;
- }
- if (hasResize) {
- return display.leftResizeWidth + display.rightResizeWidth;
- }
- if (hasBorder) {
- return display.leftBorderWidth + display.rightBorderWidth;
- }
- return 0;
-}
-int WM_DELETE_WINDOW (int w, int client_data, int call_data) {
- closeWidget ();
- return 0;
-}
-int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatch) {
- XFocusChangeEvent xEvent = new XFocusChangeEvent ();
- OS.memmove (xEvent, call_data, XFocusChangeEvent.sizeof);
- int handle = OS.XtWindowToWidget (xEvent.display, xEvent.window);
- if (handle != shellHandle) return super.XFocusChange (w, client_data, call_data, continue_to_dispatch);
- if (xEvent.mode != OS.NotifyNormal) return 0;
- switch (xEvent.detail) {
- case OS.NotifyNonlinear:
- case OS.NotifyNonlinearVirtual: {
- switch (xEvent.type) {
- case OS.FocusIn:
- postEvent (SWT.Activate);
- break;
- case OS.FocusOut:
- postEvent (SWT.Deactivate);
- break;
- }
- }
- }
- return 0;
-}
-int XStructureNotify (int w, int client_data, int call_data, int continue_to_dispatch) {
- XConfigureEvent xEvent = new XConfigureEvent ();
- OS.memmove (xEvent, call_data, XConfigureEvent.sizeof);
- switch (xEvent.type) {
- case OS.ReparentNotify: {
- if (reparented) return 0;
- reparented = true;
- short [] root_x = new short [1], root_y = new short [1];
- OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, root_x, root_y);
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- xEvent.x = root_x [0]; xEvent.y = root_y [0];
- xEvent.width = argList [1]; xEvent.height = argList [3];
- // FALL THROUGH
- }
- case OS.ConfigureNotify:
- if (!reparented) return 0;
- configured = false;
- if (oldX != xEvent.x || oldY != xEvent.y) sendEvent (SWT.Move);
- if (oldWidth != xEvent.width || oldHeight != xEvent.height) {
- XAnyEvent event = new XAnyEvent ();
- display.resizeWindow = xEvent.window;
- display.resizeWidth = xEvent.width;
- display.resizeHeight = xEvent.height;
- display.resizeCount = 0;
- int checkResizeProc = display.checkResizeProc;
- OS.XCheckIfEvent (xEvent.display, event, checkResizeProc, 0);
- if (display.resizeCount == 0) {
- sendEvent (SWT.Resize);
- if (layout != null) layout (false);
- }
- }
- if (xEvent.x != 0) oldX = xEvent.x;
- if (xEvent.y != 0) oldY = xEvent.y;
- oldWidth = xEvent.width;
- oldHeight = xEvent.height;
- return 0;
- case OS.UnmapNotify:
- int [] argList = {OS.XmNmappedWhenManaged, 0};
- OS.XtGetValues (shellHandle, argList, argList.length / 2);
- if (argList [1] != 0) {
- minimized = true;
- sendEvent (SWT.Iconify);
- }
- return 0;
- case OS.MapNotify:
- if (minimized) {
- minimized = false;
- sendEvent (SWT.Deiconify);
- }
- return 0;
- }
- return 0;
-}
+public void setImeInputMode (int mode) { + checkWidget(); +} +boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { + if (resize) { + /* + * Feature in Motif. Motif will not allow a window + * to have a zero width or zero height. The fix is + * to ensure these values are never zero. + */ + width = Math.max (width - trimWidth (), 1); + height = Math.max (height - trimHeight (), 1); + } + if (!reparented || !OS.XtIsRealized (shellHandle)) { + return super.setBounds (x, y, width, height, move, resize); + } + if (move) { + x += trimLeft (); + y += trimTop (); + } + if (!configured) saveBounds (); + configured = true; + boolean isFocus = caret != null && caret.isFocusCaret (); + if (isFocus) caret.killFocus (); + if (move && resize) { + OS.XtConfigureWidget (shellHandle, x, y, width, height, 0); + } else { + if (move) OS.XtMoveWidget (shellHandle, x, y); + if (resize) OS.XtResizeWidget (shellHandle, width, height, 0); + } + if (isFocus) caret.setFocus (); + return move || resize; +} +public void setMinimized (boolean minimized) { + checkWidget(); + + /* + * Bug in MOTIF. For some reason, the receiver does not keep the + * value of the XmNiconic resource up to date when the user minimizes + * and restores the window. As a result, a window that is minimized + * by the user and then restored by the programmer is not restored. + * This happens because the XmNiconic resource is unchanged when the + * window is minimized by the user and subsequent attempts to set the + * resource fail because the new value of the resource is the same as + * the old value. The fix is to force XmNiconic to be up to date + * before setting the desired value. + */ + int [] argList = {OS.XmNiconic, 0}; + OS.XtGetValues (shellHandle, argList, argList.length / 2); + if ((argList [1] != 0) != this.minimized) { + argList [1] = this.minimized ? 1 : 0; + OS.XtSetValues (shellHandle, argList, argList.length / 2); + } + + /* Minimize or restore the shell */ + argList [1] = (this.minimized = minimized) ? 1 : 0; + OS.XtSetValues (shellHandle, argList, argList.length / 2); + + /* Force the XWindowAttributes to be up to date */ + int xDisplay = OS.XtDisplay (handle); + if (xDisplay != 0) OS.XSync (xDisplay, false); +} +void setParentTraversal () { + /* Do nothing - Child shells do not affect the traversal of their parent shell */ +} +public void setText (String string) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + super.setText (string); + + /* + * Feature in Motif. It is not possible to set a shell + * title to an empty string. The fix is to set the title + * to be a single space. + */ + /* Use the character encoding for the default locale */ + if (string.length () == 0) string = " "; + byte [] buffer1 = Converter.wcsToMbcs (null, string, true); + int length = buffer1.length - 1; + + /* + * Bug in Motif. For some reason, if the title string + * length is not a multiple of 4, Motif occasionally + * draws garbage after the last character in the title. + * The fix is to pad the title. + */ + byte [] buffer2 = buffer1; + if ((length % 4) != 0) { + buffer2 = new byte [(length + 3) / 4 * 4]; + System.arraycopy (buffer1, 0, buffer2, 0, length); + } + + /* Set the title for the shell */ + int ptr = OS.XtMalloc (buffer2.length + 1); + OS.memmove (ptr, buffer2, buffer2.length); + int [] argList = {OS.XmNtitle, ptr}; + OS.XtSetValues (shellHandle, argList, argList.length / 2); + OS.XtFree (ptr); +} +public void setVisible (boolean visible) { + checkWidget(); + realizeWidget (); + + /* Show the shell */ + if (visible) { + + /* Map the widget */ + OS.XtSetMappedWhenManaged (shellHandle, true); + if (OS.XtIsTopLevelShell (shellHandle)) { + OS.XtMapWidget (shellHandle); + } else { + OS.XtPopup (shellHandle, OS.XtGrabNone); + } + + /* + * Force the shell to be fully exposed before returning. + * This ensures that the shell coordinates are correct + * when queried directly after showing the shell. + */ + do { + display.update (); + } while (!isVisible ()); + adjustTrim (); + + sendEvent (SWT.Show); + return; + } + + /* Hide the shell */ + OS.XtSetMappedWhenManaged (shellHandle, false); + if (OS.XtIsTopLevelShell (shellHandle)) { + OS.XtUnmapWidget (shellHandle); + } else { + OS.XtPopdown (shellHandle); + } + + /* If the shell is iconified, hide the icon */ + int xDisplay = OS.XtDisplay (shellHandle); + if (xDisplay == 0) return; + int xWindow = OS.XtWindow (shellHandle); + if (xWindow == 0) return; + OS.XWithdrawWindow (xDisplay, xWindow, OS.XDefaultScreen (xDisplay)); + + sendEvent (SWT.Hide); +} +void setZOrder (Control control, boolean above) { + setZOrder (control, above, false); +} +int topHandle () { + return shellHandle; +} +boolean traverseEscape () { + if (parent == null) return false; + if (!isVisible () || !isEnabled ()) return false; + close (); + return true; +} +int trimHeight () { + if ((style & SWT.NO_TRIM) != 0) return 0; + boolean hasTitle = false, hasResize = false, hasBorder = false; + hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0; + hasResize = (style & SWT.RESIZE) != 0; + hasBorder = (style & SWT.BORDER) != 0; + if (hasTitle) { + if (hasResize) { + return display.topTitleResizeHeight + display.bottomTitleResizeHeight; + } + if (hasBorder) { + return display.topTitleBorderHeight + display.bottomTitleBorderHeight; + } + return display.topTitleHeight + display.bottomTitleHeight; + } + if (hasResize) { + return display.topResizeHeight + display.bottomResizeHeight; + } + if (hasBorder) { + return display.topBorderHeight + display.bottomBorderHeight; + } + return 0; +} +int trimLeft () { + if ((style & SWT.NO_TRIM) != 0) return 0; + boolean hasTitle = false, hasResize = false, hasBorder = false; + hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0; + hasResize = (style & SWT.RESIZE) != 0; + hasBorder = (style & SWT.BORDER) != 0; + if (hasTitle) { + if (hasResize) return display.leftTitleResizeWidth; + if (hasBorder) return display.leftTitleBorderWidth; + return display.leftTitleWidth; + } + if (hasResize) return display.leftResizeWidth; + if (hasBorder) return display.leftBorderWidth; + return 0; +} +int trimTop () { + if ((style & SWT.NO_TRIM) != 0) return 0; + boolean hasTitle = false, hasResize = false, hasBorder = false; + hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0; + hasResize = (style & SWT.RESIZE) != 0; + hasBorder = (style & SWT.BORDER) != 0; + if (hasTitle) { + if (hasResize) return display.topTitleResizeHeight; + if (hasBorder) return display.topTitleBorderHeight; + return display.topTitleHeight; + } + if (hasResize) return display.topResizeHeight; + if (hasBorder) return display.topBorderHeight; + return 0; +} +int trimWidth () { + if ((style & SWT.NO_TRIM) != 0) return 0; + boolean hasTitle = false, hasResize = false, hasBorder = false; + hasTitle = (style & (SWT.MIN | SWT.MAX | SWT.TITLE | SWT.MENU)) != 0; + hasResize = (style & SWT.RESIZE) != 0; + hasBorder = (style & SWT.BORDER) != 0; + if (hasTitle) { + if (hasResize) { + return display.leftTitleResizeWidth + display.rightTitleResizeWidth; + } + if (hasBorder) { + return display.leftTitleBorderWidth + display.rightTitleBorderWidth; + } + return display.leftTitleWidth + display.rightTitleWidth; + } + if (hasResize) { + return display.leftResizeWidth + display.rightResizeWidth; + } + if (hasBorder) { + return display.leftBorderWidth + display.rightBorderWidth; + } + return 0; +} +int WM_DELETE_WINDOW (int w, int client_data, int call_data) { + closeWidget (); + return 0; +} +int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatch) { + XFocusChangeEvent xEvent = new XFocusChangeEvent (); + OS.memmove (xEvent, call_data, XFocusChangeEvent.sizeof); + int handle = OS.XtWindowToWidget (xEvent.display, xEvent.window); + if (handle != shellHandle) return super.XFocusChange (w, client_data, call_data, continue_to_dispatch); + if (xEvent.mode != OS.NotifyNormal) return 0; + switch (xEvent.detail) { + case OS.NotifyNonlinear: + case OS.NotifyNonlinearVirtual: { + switch (xEvent.type) { + case OS.FocusIn: + postEvent (SWT.Activate); + break; + case OS.FocusOut: + postEvent (SWT.Deactivate); + break; + } + } + } + return 0; +} +int XStructureNotify (int w, int client_data, int call_data, int continue_to_dispatch) { + XConfigureEvent xEvent = new XConfigureEvent (); + OS.memmove (xEvent, call_data, XConfigureEvent.sizeof); + switch (xEvent.type) { + case OS.ReparentNotify: { + if (reparented) return 0; + reparented = true; + short [] root_x = new short [1], root_y = new short [1]; + OS.XtTranslateCoords (shellHandle, (short) 0, (short) 0, root_x, root_y); + int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0}; + OS.XtGetValues (shellHandle, argList, argList.length / 2); + xEvent.x = root_x [0]; xEvent.y = root_y [0]; + xEvent.width = argList [1]; xEvent.height = argList [3]; + // FALL THROUGH + } + case OS.ConfigureNotify: + if (!reparented) return 0; + configured = false; + if (oldX != xEvent.x || oldY != xEvent.y) sendEvent (SWT.Move); + if (oldWidth != xEvent.width || oldHeight != xEvent.height) { + XAnyEvent event = new XAnyEvent (); + display.resizeWindow = xEvent.window; + display.resizeWidth = xEvent.width; + display.resizeHeight = xEvent.height; + display.resizeCount = 0; + int checkResizeProc = display.checkResizeProc; + OS.XCheckIfEvent (xEvent.display, event, checkResizeProc, 0); + if (display.resizeCount == 0) { + sendEvent (SWT.Resize); + if (layout != null) layout (false); + } + } + if (xEvent.x != 0) oldX = xEvent.x; + if (xEvent.y != 0) oldY = xEvent.y; + oldWidth = xEvent.width; + oldHeight = xEvent.height; + return 0; + case OS.UnmapNotify: + int [] argList = {OS.XmNmappedWhenManaged, 0}; + OS.XtGetValues (shellHandle, argList, argList.length / 2); + if (argList [1] != 0) { + minimized = true; + sendEvent (SWT.Iconify); + } + return 0; + case OS.MapNotify: + if (minimized) { + minimized = false; + sendEvent (SWT.Deiconify); + } + return 0; + } + return 0; +} }
\ No newline at end of file diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java index 97170862f0..b5fdfb91c7 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Slider.java @@ -1,66 +1,66 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-import org.eclipse.swt.graphics.*;
-
-/**
- * Instances of this class are selectable user interface
- * objects that represent a range of positive, numeric values.
- * <p>
- * At any given moment, a given slider will have a
- * single <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 a left facing button for decrementing the value and a
- * right facing button for incrementing it) or <code>VERTICAL</code>
- * (which have an upward facing button for decrementing the value
- * and a downward facing buttons for incrementing it).
- * </p><p>
- * On some platforms, the size of the slider's thumb can be
- * varied relative to the magnitude of the range of values it
- * represents (that is, relative to the difference between its
- * maximum and minimum values). Typically, this is used to
- * indicate some proportional value such as the ratio of the
- * visible area of a document to the total amount of space that
- * it would take to display it. SWT supports setting the thumb
- * size even if the underlying platform does not, but in this
- * case the appearance of the slider will not change.
- * </p>
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>HORIZONTAL, VERTICAL</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- *
- * @see ScrollBar
+ * http://www.eclipse.org/legal/cpl-v10.html */ -public class Slider extends Control {
+ +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.events.*; +import org.eclipse.swt.graphics.*; + +/** + * Instances of this class are selectable user interface + * objects that represent a range of positive, numeric values. + * <p> + * At any given moment, a given slider will have a + * single <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 a left facing button for decrementing the value and a + * right facing button for incrementing it) or <code>VERTICAL</code> + * (which have an upward facing button for decrementing the value + * and a downward facing buttons for incrementing it). + * </p><p> + * On some platforms, the size of the slider's thumb can be + * varied relative to the magnitude of the range of values it + * represents (that is, relative to the difference between its + * maximum and minimum values). Typically, this is used to + * indicate some proportional value such as the ratio of the + * visible area of a document to the total amount of space that + * it would take to display it. SWT supports setting the thumb + * size even if the underlying platform does not, but in this + * case the appearance of the slider will not change. + * </p> + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>HORIZONTAL, VERTICAL</dd> + * <dt><b>Events:</b></dt> + * <dd>Selection</dd> + * </dl> + * <p> + * Note: Only one of the styles HORIZONTAL and VERTICAL may be specified. + * </p><p> + * IMPORTANT: This class is <em>not</em> intended to be subclassed. + * </p> + * + * @see ScrollBar + */ +public class Slider extends Control { /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -90,447 +90,447 @@ public class Slider extends Control { * @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 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);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int border = getBorderWidth ();
- int width = border * 2, height = border * 2;
- Display display = getDisplay ();
- int hScroll = display.scrolledMarginX;
- int vScroll = display.scrolledMarginY;
- if ((style & SWT.HORIZONTAL) != 0) {
- width += hScroll * 10;
- height += vScroll;
- } else {
- width += hScroll;
- height += vScroll * 10;
- }
- if (wHint != SWT.DEFAULT) width = wHint + (border * 2);
- if (hHint != SWT.DEFAULT) height = hHint + (border * 2);
- return new Point (width, height);
-}
-void createHandle (int index) {
- state |= HANDLE;
- Display display = getDisplay ();
- int [] argList = {
- OS.XmNancestorSensitive, 1,
- OS.XmNhighlightThickness, display.textHighlightThickness,
- OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0,
- OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL,
- };
- int parentHandle = parent.handle;
- handle = OS.XmCreateScrollBar (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
-}
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed.
- *
- * @return the increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void addSelectionListener(SelectionListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener(listener); + addListener(SWT.Selection,typedListener); + addListener(SWT.DefaultSelection,typedListener); +} +static int checkStyle (int style) { + return checkBits (style, SWT.HORIZONTAL, SWT.VERTICAL, 0, 0, 0, 0); +} +public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget(); + int border = getBorderWidth (); + int width = border * 2, height = border * 2; + Display display = getDisplay (); + int hScroll = display.scrolledMarginX; + int vScroll = display.scrolledMarginY; + if ((style & SWT.HORIZONTAL) != 0) { + width += hScroll * 10; + height += vScroll; + } else { + width += hScroll; + height += vScroll * 10; + } + if (wHint != SWT.DEFAULT) width = wHint + (border * 2); + if (hHint != SWT.DEFAULT) height = hHint + (border * 2); + return new Point (width, height); +} +void createHandle (int index) { + state |= HANDLE; + Display display = getDisplay (); + int [] argList = { + OS.XmNancestorSensitive, 1, + OS.XmNhighlightThickness, display.textHighlightThickness, + OS.XmNborderWidth, (style & SWT.BORDER) != 0 ? 1 : 0, + OS.XmNorientation, ((style & SWT.H_SCROLL) != 0) ? OS.XmHORIZONTAL : OS.XmVERTICAL, + }; + int parentHandle = parent.handle; + handle = OS.XmCreateScrollBar (parentHandle, null, argList, argList.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); +} +/** + * Returns the amount that the receiver's value will be + * modified by when the up/down (or right/left) arrows + * are pressed. + * + * @return the increment + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getIncrement () {
- checkWidget();
- int [] argList = {OS.XmNincrement, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the maximum value which the receiver will allow.
- *
- * @return the maximum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getIncrement () { + checkWidget(); + int [] argList = {OS.XmNincrement, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns the maximum value which the receiver will allow. + * + * @return the maximum + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getMaximum () {
- checkWidget();
- int [] argList = {OS.XmNmaximum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the minimum value which the receiver will allow.
- *
- * @return the minimum
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getMaximum () { + checkWidget(); + int [] argList = {OS.XmNmaximum, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns the minimum value which the receiver will allow. + * + * @return the minimum + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getMinimum () {
- checkWidget();
- int [] argList = {OS.XmNminimum, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected.
- *
- * @return the page increment
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getMinimum () { + checkWidget(); + int [] argList = {OS.XmNminimum, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns the amount that the receiver's value will be + * modified by when the page increment/decrement areas + * are selected. + * + * @return the page increment + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getPageIncrement () {
- checkWidget();
- int [] argList = {OS.XmNpageIncrement, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the 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 getPageIncrement () { + checkWidget(); + int [] argList = {OS.XmNpageIncrement, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * 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 [] argList = {OS.XmNvalue, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-/**
- * Returns the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values.
- *
- * @return the thumb value
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getSelection () { + checkWidget(); + int [] argList = {OS.XmNvalue, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +/** + * Returns the size of the receiver's thumb relative to the + * difference between its maximum and minimum values. + * + * @return the thumb value + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getThumb () {
- checkWidget();
- int [] argList = {OS.XmNsliderSize, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = getDisplay ().windowProc;
- OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, DRAG_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNtoBottomCallback, windowProc, TO_BOTTOM_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNtoTopCallback, windowProc, TO_TOP_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNincrementCallback, windowProc, INCREMENT_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNdecrementCallback, windowProc, DECREMENT_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNpageIncrementCallback, windowProc, PAGE_INCREMENT_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNpageDecrementCallback, windowProc, PAGE_DECREMENT_CALLBACK);
-}
-void overrideTranslations () {
- Display display = getDisplay ();
- OS.XtOverrideTranslations (handle, display.tabTranslations);
-}
-/**
- * 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 int getThumb () { + checkWidget(); + int [] argList = {OS.XmNsliderSize, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +void hookEvents () { + super.hookEvents (); + int windowProc = getDisplay ().windowProc; + OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK); + OS.XtAddCallback (handle, OS.XmNdragCallback, windowProc, DRAG_CALLBACK); + OS.XtAddCallback (handle, OS.XmNtoBottomCallback, windowProc, TO_BOTTOM_CALLBACK); + OS.XtAddCallback (handle, OS.XmNtoTopCallback, windowProc, TO_TOP_CALLBACK); + OS.XtAddCallback (handle, OS.XmNincrementCallback, windowProc, INCREMENT_CALLBACK); + OS.XtAddCallback (handle, OS.XmNdecrementCallback, windowProc, DECREMENT_CALLBACK); + OS.XtAddCallback (handle, OS.XmNpageIncrementCallback, windowProc, PAGE_INCREMENT_CALLBACK); + OS.XtAddCallback (handle, OS.XmNpageDecrementCallback, windowProc, PAGE_DECREMENT_CALLBACK); +} +void overrideTranslations () { + Display display = getDisplay (); + OS.XtOverrideTranslations (handle, display.tabTranslations); +} +/** + * 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);
-}
-void sendScrollEvent (int detail) {
- Event event = new Event ();
- event.detail = detail;
- sendEvent (SWT.Selection, event);
-}
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the up/down (or right/left) arrows
- * are pressed to the argument, which must be at least
- * one.
- *
- * @param value the new increment (must be greater than zero)
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void removeSelectionListener(SelectionListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook(SWT.Selection, listener); + eventTable.unhook(SWT.DefaultSelection,listener); +} +void sendScrollEvent (int detail) { + Event event = new Event (); + event.detail = detail; + sendEvent (SWT.Selection, event); +} +/** + * Sets the amount that the receiver's value will be + * modified by when the up/down (or right/left) arrows + * are pressed to the argument, which must be at least + * one. + * + * @param value the new increment (must be greater than zero) + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setIncrement (int value) {
- checkWidget();
- if (value < 1) return;
- int [] argList = {OS.XmNincrement, value};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * Sets the maximum 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 setIncrement (int value) { + checkWidget(); + if (value < 1) return; + int [] argList = {OS.XmNincrement, value}; + OS.XtSetValues (handle, argList, argList.length / 2); +} +/** + * 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 [] argList = {OS.XmNmaximum, value};
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * 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 setMaximum (int value) { + checkWidget(); + if (value < 0) return; + int [] argList = {OS.XmNmaximum, value}; + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XtSetValues (handle, argList, argList.length / 2); + display.setWarnings (warnings); +} +/** + * 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 [] argList = {
- OS.XmNminimum, 0,
- OS.XmNmaximum, 0,
- OS.XmNsliderSize, 0,
- };
- /*
- * Feature in Motif. For some reason, when minimium
- * is set to be greater than or equal to maximum, Motif
- * does not set the minimum. Instead, the value is
- * changed and the minimum stays the same. This behavior
- * differs from setting the maximum where the slider size
- * is always decreased to make room for the new maximum.
- * The fix is to decrease the slider to make room for
- * the new minimum.
- */
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [3] - value - argList [5] < 0) {
- argList [5] = argList [3] - value;
- }
- argList [1] = value;
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the amount that the receiver's value will be
- * modified by when the page increment/decrement areas
- * are selected to the argument, which must be at least
- * one.
- *
- * @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 setMinimum (int value) { + checkWidget(); + if (value < 0) return; + int [] argList = { + OS.XmNminimum, 0, + OS.XmNmaximum, 0, + OS.XmNsliderSize, 0, + }; + /* + * Feature in Motif. For some reason, when minimium + * is set to be greater than or equal to maximum, Motif + * does not set the minimum. Instead, the value is + * changed and the minimum stays the same. This behavior + * differs from setting the maximum where the slider size + * is always decreased to make room for the new maximum. + * The fix is to decrease the slider to make room for + * the new minimum. + */ + OS.XtGetValues (handle, argList, argList.length / 2); + if (argList [3] - value - argList [5] < 0) { + argList [5] = argList [3] - value; + } + argList [1] = value; + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XtSetValues (handle, argList, argList.length / 2); + display.setWarnings (warnings); +} +/** + * Sets the amount that the receiver's value will be + * modified by when the page increment/decrement areas + * are selected to the argument, which must be at least + * one. + * + * @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 [] argList = {OS.XmNpageIncrement, value};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-/**
- * Sets the single <em>selection</em> that is the receiver's
- * value to the argument which must be greater than or equal
- * to zero.
- *
- * @param 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 setPageIncrement (int value) { + checkWidget(); + if (value < 1) return; + int [] argList = {OS.XmNpageIncrement, value}; + OS.XtSetValues (handle, argList, argList.length / 2); +} +/** + * Sets the single <em>selection</em> that is the receiver's + * value to the argument which must be greater than or equal + * to zero. + * + * @param value the new selection (must be zero or greater) + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setSelection (int value) {
- checkWidget();
- int [] argList = {OS.XmNvalue, value};
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the size of the receiver's thumb relative to the
- * difference between its maximum and minimum values 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 setSelection (int value) { + checkWidget(); + int [] argList = {OS.XmNvalue, value}; + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XtSetValues (handle, argList, argList.length / 2); + display.setWarnings (warnings); +} +/** + * Sets the size of the receiver's thumb relative to the + * difference between its maximum and minimum values 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 [] argList = {OS.XmNsliderSize, value};
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-/**
- * Sets the receiver's selection, minimum value, maximum
- * value, thumb, increment and page increment all at once.
- * <p>
- * Note: This is 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 setThumb (int value) { + checkWidget(); + if (value < 1) return; + int [] argList = {OS.XmNsliderSize, value}; + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XtSetValues (handle, argList, argList.length / 2); + display.setWarnings (warnings); +} +/** + * Sets the receiver's selection, minimum value, maximum + * value, thumb, increment and page increment all at once. + * <p> + * Note: This is 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 (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 [] argList = {
- OS.XmNvalue, selection,
- OS.XmNminimum, minimum,
- OS.XmNmaximum, maximum,
- OS.XmNsliderSize, thumb,
- OS.XmNincrement, increment,
- OS.XmNpageIncrement, pageIncrement,
- };
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XtSetValues (handle, argList, argList.length / 2);
- display.setWarnings (warnings);
-}
-int XmNdecrementCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.ARROW_UP);
- return 0;
-}
-int XmNdragCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.DRAG);
- return 0;
-}
-int XmNincrementCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.ARROW_DOWN);
- return 0;
-}
-int XmNpageDecrementCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.PAGE_UP);
- return 0;
-}
-int XmNpageIncrementCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.PAGE_DOWN);
- return 0;
-}
-int XmNtoBottomCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.END);
- return 0;
-}
-int XmNtoTopCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.HOME);
- return 0;
-}
-int XmNvalueChangedCallback (int w, int client_data, int call_data) {
- sendScrollEvent (SWT.NONE);
- return 0;
-}
-}
+public void setValues (int selection, int minimum, int maximum, int thumb, int increment, int pageIncrement) { + checkWidget(); + if (minimum < 0) return; + if (maximum < 0) return; + if (thumb < 1) return; + if (maximum - minimum - thumb < 0) return; + if (increment < 1) return; + if (pageIncrement < 1) return; + int [] argList = { + OS.XmNvalue, selection, + OS.XmNminimum, minimum, + OS.XmNmaximum, maximum, + OS.XmNsliderSize, thumb, + OS.XmNincrement, increment, + OS.XmNpageIncrement, pageIncrement, + }; + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XtSetValues (handle, argList, argList.length / 2); + display.setWarnings (warnings); +} +int XmNdecrementCallback (int w, int client_data, int call_data) { + sendScrollEvent (SWT.ARROW_UP); + return 0; +} +int XmNdragCallback (int w, int client_data, int call_data) { + sendScrollEvent (SWT.DRAG); + return 0; +} +int XmNincrementCallback (int w, int client_data, int call_data) { + sendScrollEvent (SWT.ARROW_DOWN); + return 0; +} +int XmNpageDecrementCallback (int w, int client_data, int call_data) { + sendScrollEvent (SWT.PAGE_UP); + return 0; +} +int XmNpageIncrementCallback (int w, int client_data, int call_data) { + sendScrollEvent (SWT.PAGE_DOWN); + return 0; +} +int XmNtoBottomCallback (int w, int client_data, int call_data) { + sendScrollEvent (SWT.END); + return 0; +} +int XmNtoTopCallback (int w, int client_data, int call_data) { + sendScrollEvent (SWT.HOME); + return 0; +} +int XmNvalueChangedCallback (int w, int client_data, int call_data) { + sendScrollEvent (SWT.NONE); + return 0; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java index 2c4cbb150d..6f07fdc41d 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Text.java @@ -1,18 +1,18 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.events.*; + /** * Instances of this class are selectable user interface * objects that allow the user to enter and modify text. @@ -29,28 +29,28 @@ import org.eclipse.swt.events.*; * IMPORTANT: This class is <em>not</em> intended to be subclassed. * </p> */ -public class Text extends Scrollable {
- char echoCharacter;
- boolean ignoreChange;
- String hiddenText;
- XmTextVerifyCallbackStruct textVerify;
- int drawCount;
-
- static final boolean IsGB18030;
- public static final int LIMIT;
- public static final 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";
- IsGB18030 = Converter.defaultCodePage ().endsWith ("18030");
- }
-
+public class Text extends Scrollable { + char echoCharacter; + boolean ignoreChange; + String hiddenText; + XmTextVerifyCallbackStruct textVerify; + int drawCount; + + static final boolean IsGB18030; + public static final int LIMIT; + public static final 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"; + IsGB18030 = Converter.defaultCodePage ().endsWith ("18030"); + } + /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -82,1030 +82,1030 @@ public class Text extends Scrollable { * @see Widget#checkSubclass * @see Widget#getStyle */ -public Text (Composite parent, int style) {
- super (parent, checkStyle (style));
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the receiver's text is modified, by sending
- * it one of the messages defined in the <code>ModifyListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #removeModifyListener
+public Text (Composite parent, int style) { + super (parent, checkStyle (style)); +} + +/** + * Adds the listener to the collection of listeners who will + * be notified when the receiver's text is modified, by sending + * it one of the messages defined in the <code>ModifyListener</code> + * interface. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see ModifyListener + * @see #removeModifyListener */ -public void addModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Modify, typedListener);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is selected, by 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 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 addSelectionListener(SelectionListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener(listener); + addListener(SWT.Selection,typedListener); + addListener(SWT.DefaultSelection,typedListener); +} +/** + * Adds the listener to the collection of listeners who will + * be notified when the receiver's text is verified, by sending + * it one of the messages defined in the <code>VerifyListener</code> + * interface. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see VerifyListener + * @see #removeVerifyListener */ -public void addVerifyListener (VerifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Verify, typedListener);
-}
-/**
- * Appends a string.
- * <p>
- * The new text is appended to the text at
- * the end of the widget.
- * </p>
- *
- * @param string the string to be appended
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void addVerifyListener (VerifyListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener (listener); + addListener (SWT.Verify, typedListener); +} +/** + * Appends a string. + * <p> + * The new text is appended to the text at + * the end of the widget. + * </p> + * + * @param string the string to be appended + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void append (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int position = OS.XmTextGetLastPosition (handle);
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetInsertionPosition (handle, position);
- OS.XmTextInsert (handle, position, buffer);
- position = OS.XmTextGetLastPosition (handle);
- OS.XmTextSetInsertionPosition (handle, position);
- display.setWarnings(warnings);
-}
-static int checkStyle (int style) {
- style = checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0);
- if ((style & SWT.SINGLE) != 0) style &= ~(SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP);
- if ((style & SWT.WRAP) != 0) style |= SWT.MULTI;
- 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 append (String string) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + int position = OS.XmTextGetLastPosition (handle); + byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XmTextSetInsertionPosition (handle, position); + OS.XmTextInsert (handle, position, buffer); + position = OS.XmTextGetLastPosition (handle); + OS.XmTextSetInsertionPosition (handle, position); + display.setWarnings(warnings); +} +static int checkStyle (int style) { + style = checkBits (style, SWT.LEFT, SWT.CENTER, SWT.RIGHT, 0, 0, 0); + if ((style & SWT.SINGLE) != 0) style &= ~(SWT.H_SCROLL | SWT.V_SCROLL | SWT.WRAP); + if ((style & SWT.WRAP) != 0) style |= SWT.MULTI; + if ((style & (SWT.SINGLE | SWT.MULTI)) != 0) return style; + if ((style & (SWT.H_SCROLL | SWT.V_SCROLL)) != 0) { + return style | SWT.MULTI; + } + return style | SWT.SINGLE; +} +/** + * Clears the selection. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void clearSelection () {
- checkWidget();
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- OS.XmTextClearSelection (handle, OS.XtLastTimestampProcessed (xDisplay));
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = wHint;
- int height = hHint;
- if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) {
- int ptr = OS.XmTextGetString (handle);
- if (ptr == 0) return new Point (0, 0);
- int size = OS.strlen (ptr);
- if (size == 0) {
- if (hHint == SWT.DEFAULT) {
- if ((style & SWT.SINGLE) != 0) {
- height = getLineHeight ();
- } else {
- height = DEFAULT_HEIGHT;
- }
- }
- if (wHint == SWT.DEFAULT) {
- width = DEFAULT_WIDTH;
- }
- } else {
- byte [] buffer = new byte [size + 1];
- OS.memmove (buffer, ptr, size);
- int xmString;
- if ((style & SWT.SINGLE) != 0) {
- xmString = OS.XmStringParseText (
- buffer,
- 0,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null,
- 0,
- 0);
- } else {
- xmString = OS.XmStringGenerate (
- buffer,
- OS.XmFONTLIST_DEFAULT_TAG,
- OS.XmCHARSET_TEXT,
- null);
- }
- int fontList = font.handle;
- if (hHint == SWT.DEFAULT) {
- if ((style & SWT.SINGLE) != 0) {
- height = getLineHeight ();
- } else {
- height = OS.XmStringHeight (fontList, xmString);
- }
- }
- if (wHint == SWT.DEFAULT) width = OS.XmStringWidth(fontList, xmString);
- OS.XmStringFree (xmString);
- }
- OS.XtFree (ptr);
- }
- if (horizontalBar != null) {
- int [] argList1 = {OS.XmNheight, 0};
- OS.XtGetValues (horizontalBar.handle, argList1, argList1.length / 2);
- height += argList1 [1] + 4;
- }
- if (verticalBar != null) {
- int [] argList1 = {OS.XmNwidth, 0};
- OS.XtGetValues (verticalBar.handle, argList1, argList1.length / 2);
- width += argList1 [1] + 4;
- }
- XRectangle rect = new XRectangle ();
- OS.XmWidgetGetDisplayRect (handle, rect);
- width += rect.x * 2; height += rect.y * 2;
- if ((style & (SWT.MULTI | SWT.BORDER)) != 0) height++;
- return new Point (width, height);
-}
-public Rectangle computeTrim (int x, int y, int width, int height) {
- checkWidget();
- Rectangle trim = super.computeTrim(x, y, width, height);
- XRectangle rect = new XRectangle ();
- OS.XmWidgetGetDisplayRect (handle, rect);
- trim.x -= rect.x;
- trim.y -= rect.y;
- trim.width += rect.x;
- trim.height += rect.y;
- if ((style & (SWT.MULTI | SWT.BORDER)) != 0) trim.height += 3;
- return trim;
-}
-/**
- * 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 clearSelection () { + checkWidget(); + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return; + OS.XmTextClearSelection (handle, OS.XtLastTimestampProcessed (xDisplay)); +} +public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget(); + int width = wHint; + int height = hHint; + if (wHint == SWT.DEFAULT || hHint == SWT.DEFAULT) { + int ptr = OS.XmTextGetString (handle); + if (ptr == 0) return new Point (0, 0); + int size = OS.strlen (ptr); + if (size == 0) { + if (hHint == SWT.DEFAULT) { + if ((style & SWT.SINGLE) != 0) { + height = getLineHeight (); + } else { + height = DEFAULT_HEIGHT; + } + } + if (wHint == SWT.DEFAULT) { + width = DEFAULT_WIDTH; + } + } else { + byte [] buffer = new byte [size + 1]; + OS.memmove (buffer, ptr, size); + int xmString; + if ((style & SWT.SINGLE) != 0) { + xmString = OS.XmStringParseText ( + buffer, + 0, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null, + 0, + 0); + } else { + xmString = OS.XmStringGenerate ( + buffer, + OS.XmFONTLIST_DEFAULT_TAG, + OS.XmCHARSET_TEXT, + null); + } + int fontList = font.handle; + if (hHint == SWT.DEFAULT) { + if ((style & SWT.SINGLE) != 0) { + height = getLineHeight (); + } else { + height = OS.XmStringHeight (fontList, xmString); + } + } + if (wHint == SWT.DEFAULT) width = OS.XmStringWidth(fontList, xmString); + OS.XmStringFree (xmString); + } + OS.XtFree (ptr); + } + if (horizontalBar != null) { + int [] argList1 = {OS.XmNheight, 0}; + OS.XtGetValues (horizontalBar.handle, argList1, argList1.length / 2); + height += argList1 [1] + 4; + } + if (verticalBar != null) { + int [] argList1 = {OS.XmNwidth, 0}; + OS.XtGetValues (verticalBar.handle, argList1, argList1.length / 2); + width += argList1 [1] + 4; + } + XRectangle rect = new XRectangle (); + OS.XmWidgetGetDisplayRect (handle, rect); + width += rect.x * 2; height += rect.y * 2; + if ((style & (SWT.MULTI | SWT.BORDER)) != 0) height++; + return new Point (width, height); +} +public Rectangle computeTrim (int x, int y, int width, int height) { + checkWidget(); + Rectangle trim = super.computeTrim(x, y, width, height); + XRectangle rect = new XRectangle (); + OS.XmWidgetGetDisplayRect (handle, rect); + trim.x -= rect.x; + trim.y -= rect.y; + trim.width += rect.x; + trim.height += rect.y; + if ((style & (SWT.MULTI | SWT.BORDER)) != 0) trim.height += 3; + return trim; +} +/** + * Copies the selected text. + * <p> + * The current selection is copied to the clipboard. + * </p> + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void copy () {
- checkWidget();
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- OS.XmTextCopy (handle, OS.XtLastTimestampProcessed (xDisplay));
-}
-void createHandle (int index) {
- state |= HANDLE;
- int [] argList1 = {
- OS.XmNverifyBell, 0,
- OS.XmNeditMode, (style & SWT.SINGLE) != 0 ? OS.XmSINGLE_LINE_EDIT : OS.XmMULTI_LINE_EDIT,
- OS.XmNscrollHorizontal, (style & SWT.H_SCROLL) != 0 ? 1 : 0,
- OS.XmNscrollVertical, (style & SWT.V_SCROLL) != 0 ? 1 : 0,
- OS.XmNwordWrap, !IsGB18030 && (style & SWT.WRAP) != 0 ? 1: 0,
- OS.XmNeditable, (style & SWT.READ_ONLY) != 0 ? 0 : 1,
- OS.XmNcursorPositionVisible, (style & SWT.READ_ONLY) != 0 && (style & SWT.SINGLE) != 0 ? 0 : 1,
-// OS.XmNmarginWidth, 3,
-// OS.XmNmarginHeight, 1,
- OS.XmNancestorSensitive, 1,
- };
- int parentHandle = parent.handle;
- if ((style & SWT.SINGLE) != 0) {
- handle = OS.XmCreateTextField (parentHandle, null, argList1, argList1.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- int [] argList2 = new int [] {OS.XmNcursorPositionVisible, 0};
- OS.XtSetValues (handle, argList2, argList2.length / 2);
- if ((style & SWT.BORDER) == 0) {
- int [] argList3 = new int [] {
- /*
- * Bug in Motif. Setting the margin width to zero for
- * a single line text field causes the field to draw
- * garbage when the caret is placed at the start of
- * the widget. The fix is to not set the margin width.
- */
-// OS.XmNmarginWidth, 0,
- OS.XmNmarginHeight, 0,
- OS.XmNshadowThickness, 0,
- };
- OS.XtSetValues (handle, argList3, argList3.length / 2);
- }
- } else {
- handle = OS.XmCreateScrolledText (parentHandle, new byte [0], argList1, argList1.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- scrolledHandle = OS.XtParent (handle);
- }
-}
-ScrollBar createScrollBar (int type) {
- return createStandardBar (type);
-}
-/**
- * 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 copy () { + checkWidget(); + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return; + OS.XmTextCopy (handle, OS.XtLastTimestampProcessed (xDisplay)); +} +void createHandle (int index) { + state |= HANDLE; + int [] argList1 = { + OS.XmNverifyBell, 0, + OS.XmNeditMode, (style & SWT.SINGLE) != 0 ? OS.XmSINGLE_LINE_EDIT : OS.XmMULTI_LINE_EDIT, + OS.XmNscrollHorizontal, (style & SWT.H_SCROLL) != 0 ? 1 : 0, + OS.XmNscrollVertical, (style & SWT.V_SCROLL) != 0 ? 1 : 0, + OS.XmNwordWrap, !IsGB18030 && (style & SWT.WRAP) != 0 ? 1: 0, + OS.XmNeditable, (style & SWT.READ_ONLY) != 0 ? 0 : 1, + OS.XmNcursorPositionVisible, (style & SWT.READ_ONLY) != 0 && (style & SWT.SINGLE) != 0 ? 0 : 1, +// OS.XmNmarginWidth, 3, +// OS.XmNmarginHeight, 1, + OS.XmNancestorSensitive, 1, + }; + int parentHandle = parent.handle; + if ((style & SWT.SINGLE) != 0) { + handle = OS.XmCreateTextField (parentHandle, null, argList1, argList1.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + int [] argList2 = new int [] {OS.XmNcursorPositionVisible, 0}; + OS.XtSetValues (handle, argList2, argList2.length / 2); + if ((style & SWT.BORDER) == 0) { + int [] argList3 = new int [] { + /* + * Bug in Motif. Setting the margin width to zero for + * a single line text field causes the field to draw + * garbage when the caret is placed at the start of + * the widget. The fix is to not set the margin width. + */ +// OS.XmNmarginWidth, 0, + OS.XmNmarginHeight, 0, + OS.XmNshadowThickness, 0, + }; + OS.XtSetValues (handle, argList3, argList3.length / 2); + } + } else { + handle = OS.XmCreateScrolledText (parentHandle, new byte [0], argList1, argList1.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + scrolledHandle = OS.XtParent (handle); + } +} +ScrollBar createScrollBar (int type) { + return createStandardBar (type); +} +/** + * 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();
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- OS.XmTextCut (handle, OS.XtLastTimestampProcessed (xDisplay));
-}
-int defaultBackground () {
- return getDisplay ().textBackground;
-}
-Font defaultFont () {
- return getDisplay ().textFont;
-}
-int defaultForeground () {
- return getDisplay ().textForeground;
-}
-/**
- * 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 void cut () { + checkWidget(); + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return; + OS.XmTextCut (handle, OS.XtLastTimestampProcessed (xDisplay)); +} +int defaultBackground () { + return getDisplay ().textBackground; +} +Font defaultFont () { + return getDisplay ().textFont; +} +int defaultForeground () { + return getDisplay ().textForeground; +} +/** + * 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();
- return getLineNumber (OS.XmTextGetInsertionPosition (handle));
-}
-/**
- * Gets the location of 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 int getCaretLineNumber () { + checkWidget(); + return getLineNumber (OS.XmTextGetInsertionPosition (handle)); +} +/** + * Gets the location of 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();
- int position;
- if (textVerify != null) {
- position = textVerify.currInsert;
- } else {
- position = OS.XmTextGetInsertionPosition (handle);
- }
- short [] x = new short [1], y = new short [1];
- OS.XmTextPosToXY (handle, position, x, y);
- return new Point (x [0], y [0] - getFontAscent ());
-}
-/**
- * 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 Point getCaretLocation () { + checkWidget(); + int position; + if (textVerify != null) { + position = textVerify.currInsert; + } else { + position = OS.XmTextGetInsertionPosition (handle); + } + short [] x = new short [1], y = new short [1]; + OS.XmTextPosToXY (handle, position, x, y); + return new Point (x [0], y [0] - getFontAscent ()); +} +/** + * 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.XmTextGetInsertionPosition (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 getCaretPosition () { + checkWidget(); + return OS.XmTextGetInsertionPosition (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();
- return OS.XmTextGetLastPosition (handle);
-}
-/**
- * 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 int getCharCount () { + checkWidget(); + return OS.XmTextGetLastPosition (handle); +} +/** + * 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();
- int [] argList = {OS.XmNselectionArrayCount, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] != 1;
-}
-/**
- * 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 boolean getDoubleClickEnabled () { + checkWidget(); + int [] argList = {OS.XmNselectionArrayCount, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1] != 1; +} +/** + * 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 echoCharacter;
-}
-/**
- * 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 char getEchoChar () { + checkWidget(); + return echoCharacter; +} +/** + * 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();
- /*
- * Bug in MOTIF. For some reason, when XmTextGetEditable () is called
- * from inside an XmNvalueChangedCallback or XmNModifyVerifyCallback,
- * it always returns TRUE. Calls to XmTextGetEditable () outside of
- * these callbacks return the correct value. The fix is to query the
- * resource directly instead of using the convenience function.
- */
- int [] argList = {OS.XmNeditable, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] != 0;
-}
-/**
- * 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 boolean getEditable () { + checkWidget(); + /* + * Bug in MOTIF. For some reason, when XmTextGetEditable () is called + * from inside an XmNvalueChangedCallback or XmNModifyVerifyCallback, + * it always returns TRUE. Calls to XmTextGetEditable () outside of + * these callbacks return the correct value. The fix is to query the + * resource directly instead of using the convenience function. + */ + int [] argList = {OS.XmNeditable, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1] != 0; +} +/** + * 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();
- if ((style & SWT.SINGLE) != 0) return 1;
- int lastChar = echoCharacter != '\0' ? hiddenText.length () : OS.XmTextGetLastPosition (handle);
- return getLineNumber (lastChar) + 1;
-}
-/**
- * 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 int getLineCount () { + checkWidget(); + if ((style & SWT.SINGLE) != 0) return 1; + int lastChar = echoCharacter != '\0' ? hiddenText.length () : OS.XmTextGetLastPosition (handle); + return getLineNumber (lastChar) + 1; +} +/** + * 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 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 String getLineDelimiter () { + checkWidget(); + return "\n"; +} +/** + * 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();
- return getFontHeight ();
-}
-int getLineNumber (int position) {
- if (position == 0) return 0;
- int count = 0, start = 0, page = 1024;
- char [] buffer = new char [page + 1];
- /*
- * Bug in Linux. For some reason, XmTextGetSubstringWcs () does
- * not copy wchar_t characters into the buffer. Instead, it
- * copies 4 bytes per character. This does not happen on other
- * platforms such as AIX. The fix is to call XmTextGetSubstring ()
- * instead on Linux and rely on the fact that Metrolink Motif 1.2
- * does not support multibyte locales.
- */
- byte [] buffer1 = null;
- if (OS.IsLinux) buffer1 = new byte [page + 1];
- int end = ((position + page - 1) / page) * page;
- while (start < end) {
- int length = page;
- if (start + page > position) length = position - start;
- if (echoCharacter != '\0') {
- hiddenText.getChars (start, start + length, buffer, 0);
- } else {
- if (OS.IsLinux) {
- OS.XmTextGetSubstring (handle, start, length, buffer1.length, buffer1);
- for (int i=0; i<length; i++) buffer [i] = (char) buffer1 [i];
- } else {
- OS.XmTextGetSubstringWcs (handle, start, length, buffer.length, buffer);
- }
- }
- for (int i=0; i<length; i++) {
- if (buffer [i] == '\n') count++;
- }
- start += page;
- }
- return count;
-}
-int getNavigationType () {
- /*
- * Bug in Motif. On Solaris only, the implementation
- * of XtGetValues for XmText does not check for a zero
- * pointer in the arg list and GP's. The fix is to
- * allocate and free memory for the arg list value.
- */
- if ((style & SWT.SINGLE) != 0) {
- return super.getNavigationType ();
- }
- int ptr = OS.XtMalloc (4);
- if (ptr == 0) return OS.XmNONE;
- int [] argList = {OS.XmNnavigationType, ptr};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int [] buffer = new int [1];
- OS.memmove (buffer, ptr, 4);
- OS.XtFree (ptr);
- return buffer [0];
-}
-/**
- * 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 int getLineHeight () { + checkWidget(); + return getFontHeight (); +} +int getLineNumber (int position) { + if (position == 0) return 0; + int count = 0, start = 0, page = 1024; + char [] buffer = new char [page + 1]; + /* + * Bug in Linux. For some reason, XmTextGetSubstringWcs () does + * not copy wchar_t characters into the buffer. Instead, it + * copies 4 bytes per character. This does not happen on other + * platforms such as AIX. The fix is to call XmTextGetSubstring () + * instead on Linux and rely on the fact that Metrolink Motif 1.2 + * does not support multibyte locales. + */ + byte [] buffer1 = null; + if (OS.IsLinux) buffer1 = new byte [page + 1]; + int end = ((position + page - 1) / page) * page; + while (start < end) { + int length = page; + if (start + page > position) length = position - start; + if (echoCharacter != '\0') { + hiddenText.getChars (start, start + length, buffer, 0); + } else { + if (OS.IsLinux) { + OS.XmTextGetSubstring (handle, start, length, buffer1.length, buffer1); + for (int i=0; i<length; i++) buffer [i] = (char) buffer1 [i]; + } else { + OS.XmTextGetSubstringWcs (handle, start, length, buffer.length, buffer); + } + } + for (int i=0; i<length; i++) { + if (buffer [i] == '\n') count++; + } + start += page; + } + return count; +} +int getNavigationType () { + /* + * Bug in Motif. On Solaris only, the implementation + * of XtGetValues for XmText does not check for a zero + * pointer in the arg list and GP's. The fix is to + * allocate and free memory for the arg list value. + */ + if ((style & SWT.SINGLE) != 0) { + return super.getNavigationType (); + } + int ptr = OS.XtMalloc (4); + if (ptr == 0) return OS.XmNONE; + int [] argList = {OS.XmNnavigationType, ptr}; + OS.XtGetValues (handle, argList, argList.length / 2); + int [] buffer = new int [1]; + OS.memmove (buffer, ptr, 4); + OS.XtFree (ptr); + return buffer [0]; +} +/** + * 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();
- if (textVerify != null) {
- return new Point (textVerify.startPos, textVerify.endPos);
- }
- int [] start = new int [1], end = new int [1];
- OS.XmTextGetSelectionPosition (handle, start, end);
- if (start [0] == end [0]) {
- start [0] = end [0] = OS.XmTextGetInsertionPosition (handle);
- }
- return new Point (start [0], end [0]);
-}
-/**
- * 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 Point getSelection () { + checkWidget(); + if (textVerify != null) { + return new Point (textVerify.startPos, textVerify.endPos); + } + int [] start = new int [1], end = new int [1]; + OS.XmTextGetSelectionPosition (handle, start, end); + if (start [0] == end [0]) { + start [0] = end [0] = OS.XmTextGetInsertionPosition (handle); + } + return new Point (start [0], end [0]); +} +/** + * 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();
- if (textVerify != null) {
- return textVerify.endPos - textVerify.startPos;
- }
- int [] start = new int [1], end = new int [1];
- OS.XmTextGetSelectionPosition (handle, start, end);
- return end [0] - start [0];
-}
-/**
- * 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 int getSelectionCount () { + checkWidget(); + if (textVerify != null) { + return textVerify.endPos - textVerify.startPos; + } + int [] start = new int [1], end = new int [1]; + OS.XmTextGetSelectionPosition (handle, start, end); + return end [0] - start [0]; +} +/** + * 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();
- if (echoCharacter != '\0' || textVerify != null) {
- Point selection = getSelection ();
- return getText (selection.x, selection.y);
- }
- int ptr = OS.XmTextGetSelection (handle);
- if (ptr == 0) return "";
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, length);
- OS.XtFree (ptr);
- return new String (Converter.mbcsToWcs (getCodePage (), buffer));
-}
-/**
- * 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 String getSelectionText () { + checkWidget(); + if (echoCharacter != '\0' || textVerify != null) { + Point selection = getSelection (); + return getText (selection.x, selection.y); + } + int ptr = OS.XmTextGetSelection (handle); + if (ptr == 0) return ""; + int length = OS.strlen (ptr); + byte [] buffer = new byte [length]; + OS.memmove (buffer, ptr, length); + OS.XtFree (ptr); + return new String (Converter.mbcsToWcs (getCodePage (), buffer)); +} +/** + * 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();
- /* Tabs are not supported in MOTIF. */
- return 8;
-}
-/**
- * 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 int getTabs () { + checkWidget(); + /* Tabs are not supported in MOTIF. */ + return 8; +} +/** + * 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();
- if (echoCharacter != '\0') return hiddenText;
- int ptr = OS.XmTextGetString (handle);
- if (ptr == 0) return "";
- int length = OS.strlen (ptr);
- byte [] buffer = new byte [length];
- OS.memmove (buffer, ptr, length);
- OS.XtFree (ptr);
- return new String (Converter.mbcsToWcs (getCodePage (), buffer));
-}
-/**
- * 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 () { + checkWidget(); + if (echoCharacter != '\0') return hiddenText; + int ptr = OS.XmTextGetString (handle); + if (ptr == 0) return ""; + int length = OS.strlen (ptr); + byte [] buffer = new byte [length]; + OS.memmove (buffer, ptr, length); + OS.XtFree (ptr); + return new String (Converter.mbcsToWcs (getCodePage (), buffer)); +} +/** + * 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 numChars = end - start + 1;
- if (numChars < 0 || start < 0) return "";
- if (echoCharacter != '\0') {
- return hiddenText.substring (start, Math.min (hiddenText.length (), end));
- }
- int length = (numChars * 4 /* MB_CUR_MAX */) + 1;
- byte [] buffer = new byte [length];
- int code = OS.XmTextGetSubstring (handle, start, numChars, length, buffer);
- if (code == OS.XmCOPY_FAILED) return "";
- char [] unicode = Converter.mbcsToWcs (getCodePage (), buffer);
- if (code == OS.XmCOPY_TRUNCATED) {
- numChars = OS.XmTextGetLastPosition (handle) - start;
- }
- return new String (unicode, 0, numChars);
-}
-/**
- * Returns the maximum number of characters that the receiver is capable of holding.
- * <p>
- * If this has not been changed by <code>setTextLimit()</code>,
- * it will be the constant <code>Text.LIMIT</code>.
- * </p>
- *
- * @return the text limit
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public String getText (int start, int end) { + checkWidget(); + int numChars = end - start + 1; + if (numChars < 0 || start < 0) return ""; + if (echoCharacter != '\0') { + return hiddenText.substring (start, Math.min (hiddenText.length (), end)); + } + int length = (numChars * 4 /* MB_CUR_MAX */) + 1; + byte [] buffer = new byte [length]; + int code = OS.XmTextGetSubstring (handle, start, numChars, length, buffer); + if (code == OS.XmCOPY_FAILED) return ""; + char [] unicode = Converter.mbcsToWcs (getCodePage (), buffer); + if (code == OS.XmCOPY_TRUNCATED) { + numChars = OS.XmTextGetLastPosition (handle) - start; + } + return new String (unicode, 0, numChars); +} +/** + * Returns the maximum number of characters that the receiver is capable of holding. + * <p> + * If this has not been changed by <code>setTextLimit()</code>, + * it will be the constant <code>Text.LIMIT</code>. + * </p> + * + * @return the text limit + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getTextLimit () {
- checkWidget();
- return OS.XmTextGetMaxLength (handle);
-}
-/**
- * Returns the zero-relative index of the line which is currently
- * at the top of the receiver.
- * <p>
- * This index can change when lines are scrolled or new lines are added or removed.
- * </p>
- *
- * @return the index of the top line
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getTextLimit () { + checkWidget(); + return OS.XmTextGetMaxLength (handle); +} +/** + * Returns the zero-relative index of the line which is currently + * at the top of the receiver. + * <p> + * This index can change when lines are scrolled or new lines are added or removed. + * </p> + * + * @return the index of the top line + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getTopIndex () {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return 0;
- if (scrolledHandle == 0) return 0;
- int [] argList1 = {OS.XmNverticalScrollBar, 0};
- OS.XtGetValues (scrolledHandle, argList1, argList1.length / 2);
- if (argList1 [1] == 0) return 0;
- int [] argList2 = {OS.XmNvalue, 0};
- OS.XtGetValues (argList1 [1], argList2, argList2.length / 2);
- return argList2 [1];
-}
-/**
- * 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 getTopIndex () { + checkWidget(); + if ((style & SWT.SINGLE) != 0) return 0; + if (scrolledHandle == 0) return 0; + int [] argList1 = {OS.XmNverticalScrollBar, 0}; + OS.XtGetValues (scrolledHandle, argList1, argList1.length / 2); + if (argList1 [1] == 0) return 0; + int [] argList2 = {OS.XmNvalue, 0}; + OS.XtGetValues (argList1 [1], argList2, argList2.length / 2); + return argList2 [1]; +} +/** + * 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();
- return getTopIndex () * getLineHeight ();
-}
-boolean hasIMSupport() {
- return true;
-}
-void hookEvents () {
- super.hookEvents ();
- int windowProc = getDisplay ().windowProc;
- OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK);
- OS.XtAddCallback (handle, OS.XmNmodifyVerifyCallback, windowProc, MODIFY_VERIFY_CALLBACK);
-}
-int inputContext () {
- /* Answer zero. The text widget uses the default MOTIF input context. */
- return 0;
-}
-/**
- * Inserts a string.
- * <p>
- * The old selection is replaced with the new text.
- * </p>
- *
- * @param string the string
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getTopPixel () { + checkWidget(); + return getTopIndex () * getLineHeight (); +} +boolean hasIMSupport() { + return true; +} +void hookEvents () { + super.hookEvents (); + int windowProc = getDisplay ().windowProc; + OS.XtAddCallback (handle, OS.XmNactivateCallback, windowProc, ACTIVATE_CALLBACK); + OS.XtAddCallback (handle, OS.XmNvalueChangedCallback, windowProc, VALUE_CHANGED_CALLBACK); + OS.XtAddCallback (handle, OS.XmNmodifyVerifyCallback, windowProc, MODIFY_VERIFY_CALLBACK); +} +int inputContext () { + /* Answer zero. The text widget uses the default MOTIF input context. */ + return 0; +} +/** + * Inserts a string. + * <p> + * The old selection is replaced with the new text. + * </p> + * + * @param string the string + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void insert (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- int [] start = new int [1], end = new int [1];
- OS.XmTextGetSelectionPosition (handle, start, end);
- if (start [0] == end [0]) {
- start [0] = end [0] = OS.XmTextGetInsertionPosition (handle);
- }
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextReplace (handle, start [0], end [0], buffer);
- int position = start [0] + buffer.length - 1;
- OS.XmTextSetInsertionPosition (handle, position);
- display.setWarnings (warnings);
-}
-void overrideTranslations () {
- if ((style & SWT.SINGLE) != 0) {
- Display display = getDisplay ();
- OS.XtOverrideTranslations (handle, display.tabTranslations);
- }
-}
-/**
- * Pastes text from clipboard.
- * <p>
- * The selected text is deleted from the widget
- * and new text inserted from the clipboard.
- * </p>
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void insert (String string) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + int [] start = new int [1], end = new int [1]; + OS.XmTextGetSelectionPosition (handle, start, end); + if (start [0] == end [0]) { + start [0] = end [0] = OS.XmTextGetInsertionPosition (handle); + } + byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XmTextReplace (handle, start [0], end [0], buffer); + int position = start [0] + buffer.length - 1; + OS.XmTextSetInsertionPosition (handle, position); + display.setWarnings (warnings); +} +void overrideTranslations () { + if ((style & SWT.SINGLE) != 0) { + Display display = getDisplay (); + OS.XtOverrideTranslations (handle, display.tabTranslations); + } +} +/** + * Pastes text from clipboard. + * <p> + * The selected text is deleted from the widget + * and new text inserted from the clipboard. + * </p> + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void paste () {
- checkWidget();
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- /*
- * Bug in Motif. Despite the fact that the documentation
- * claims that XmText functions work for XmTextFields, when
- * a text field is passed to XmTextPaste, Motif segment faults.
- * The fix is to call XmTextFieldPaste instead.
- */
- if ((style & SWT.SINGLE) != 0) {
- OS.XmTextFieldPaste (handle);
- } else {
- OS.XmTextPaste (handle);
- }
- display.setWarnings (warnings);
-}
-void releaseWidget () {
- super.releaseWidget ();
- hiddenText = null;
- textVerify = null;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the receiver's text is modified.
- *
- * @param listener the listener which should no longer be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ModifyListener
- * @see #addModifyListener
+public void paste () { + checkWidget(); + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + /* + * Bug in Motif. Despite the fact that the documentation + * claims that XmText functions work for XmTextFields, when + * a text field is passed to XmTextPaste, Motif segment faults. + * The fix is to call XmTextFieldPaste instead. + */ + if ((style & SWT.SINGLE) != 0) { + OS.XmTextFieldPaste (handle); + } else { + OS.XmTextPaste (handle); + } + display.setWarnings (warnings); +} +void releaseWidget () { + super.releaseWidget (); + hiddenText = null; + textVerify = null; +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the receiver's text is modified. + * + * @param listener the listener which should no longer be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see ModifyListener + * @see #addModifyListener */ -public void removeModifyListener (ModifyListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Modify, listener);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected.
- *
- * @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 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 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);
-}
-byte [] sendIMKeyEvent (int type, XKeyEvent xEvent) {
- /*
- * Bug in Motif. On Solaris and Linux, XmImMbLookupString() clears
- * the characters from the IME. This causes the characters to be
- * stolen from the text widget. The fix is to detect that the IME
- * has been cleared and use XmTextInsert() to insert the stolen
- * characters. This problem does not happen on AIX.
- */
- byte [] mbcs = super.sendIMKeyEvent (type, xEvent);
- if (mbcs == null || xEvent.keycode != 0) return null;
- int [] unused = new int [1];
- byte [] buffer = new byte [2];
- int length = OS.XmImMbLookupString (handle, xEvent, buffer, buffer.length, unused, unused);
- if (length != 0) return null;
- int [] start = new int [1], end = new int [1];
- OS.XmTextGetSelectionPosition (handle, start, end);
- if (start [0] == end [0]) {
- start [0] = end [0] = OS.XmTextGetInsertionPosition (handle);
- }
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextReplace (handle, start [0], end [0], mbcs);
- int position = start [0] + mbcs.length - 1;
- OS.XmTextSetInsertionPosition (handle, position);
- display.setWarnings (warnings);
- return mbcs;
-}
-/**
- * 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 removeVerifyListener (VerifyListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook (SWT.Verify, listener); +} +byte [] sendIMKeyEvent (int type, XKeyEvent xEvent) { + /* + * Bug in Motif. On Solaris and Linux, XmImMbLookupString() clears + * the characters from the IME. This causes the characters to be + * stolen from the text widget. The fix is to detect that the IME + * has been cleared and use XmTextInsert() to insert the stolen + * characters. This problem does not happen on AIX. + */ + byte [] mbcs = super.sendIMKeyEvent (type, xEvent); + if (mbcs == null || xEvent.keycode != 0) return null; + int [] unused = new int [1]; + byte [] buffer = new byte [2]; + int length = OS.XmImMbLookupString (handle, xEvent, buffer, buffer.length, unused, unused); + if (length != 0) return null; + int [] start = new int [1], end = new int [1]; + OS.XmTextGetSelectionPosition (handle, start, end); + if (start [0] == end [0]) { + start [0] = end [0] = OS.XmTextGetInsertionPosition (handle); + } + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XmTextReplace (handle, start [0], end [0], mbcs); + int position = start [0] + mbcs.length - 1; + OS.XmTextSetInsertionPosition (handle, position); + display.setWarnings (warnings); + return mbcs; +} +/** + * Selects all the text in the receiver. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void selectAll () {
- checkWidget();
- /* Clear the highlight before setting the selection. */
- int position = OS.XmTextGetLastPosition (handle);
-// OS.XmTextSetHighlight (handle, 0, position, OS.XmHIGHLIGHT_NORMAL);
-
- /*
- * Bug in MOTIF. XmTextSetSelection () fails to set the
- * selection when the receiver is not realized. The fix
- * is to force the receiver to be realized by forcing the
- * shell to be realized. If the receiver is realized before
- * the shell, MOTIF fails to draw the text widget and issues
- * lots of X BadDrawable errors.
- */
- if (!OS.XtIsRealized (handle)) getShell ().realizeWidget ();
-
- /* Set the selection. */
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetSelection (handle, 0, position, OS.XtLastTimestampProcessed (xDisplay));
-
- /* Force the i-beam to follow the highlight/selection. */
- OS.XmTextSetInsertionPosition (handle, 0);
- display.setWarnings (warnings);
-}
-boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) {
- /*
- * Bug in Motif. For some reason an Xm warning is
- * output whenever a Text widget's caret is beyond
- * the visible region during a resize. The fix is
- * to temporarily turn off warnings below.
- */
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- boolean changed = super.setBounds (x, y, width, height, move, resize);
- display.setWarnings(warnings);
-
- /*
- * Bug in Motif. When the receiver is a Text widget
- * (not a Text Field) and is resized to be smaller than
- * the inset that surrounds the text and the selection
- * is set, the receiver scrolls to the left. When the
- * receiver is resized larger, the text is not scrolled
- * back. The fix is to detect this case and scroll the
- * text back.
- */
-// inset := self inset.
-// nWidth := self dimensionAt: XmNwidth.
-// self noWarnings: [super resizeWidget].
-// nWidth > inset x ifTrue: [^self].
-// self showPosition: self topCharacter
- return changed;
-}
-/**
- * Sets the double click enabled flag.
- * <p>
- * The double click flag enables or disables the
- * default action of the text widget when the user
- * double clicks.
- * </p>
- *
- * @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 selectAll () { + checkWidget(); + /* Clear the highlight before setting the selection. */ + int position = OS.XmTextGetLastPosition (handle); +// OS.XmTextSetHighlight (handle, 0, position, OS.XmHIGHLIGHT_NORMAL); + + /* + * Bug in MOTIF. XmTextSetSelection () fails to set the + * selection when the receiver is not realized. The fix + * is to force the receiver to be realized by forcing the + * shell to be realized. If the receiver is realized before + * the shell, MOTIF fails to draw the text widget and issues + * lots of X BadDrawable errors. + */ + if (!OS.XtIsRealized (handle)) getShell ().realizeWidget (); + + /* Set the selection. */ + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return; + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XmTextSetSelection (handle, 0, position, OS.XtLastTimestampProcessed (xDisplay)); + + /* Force the i-beam to follow the highlight/selection. */ + OS.XmTextSetInsertionPosition (handle, 0); + display.setWarnings (warnings); +} +boolean setBounds (int x, int y, int width, int height, boolean move, boolean resize) { + /* + * Bug in Motif. For some reason an Xm warning is + * output whenever a Text widget's caret is beyond + * the visible region during a resize. The fix is + * to temporarily turn off warnings below. + */ + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + boolean changed = super.setBounds (x, y, width, height, move, resize); + display.setWarnings(warnings); + + /* + * Bug in Motif. When the receiver is a Text widget + * (not a Text Field) and is resized to be smaller than + * the inset that surrounds the text and the selection + * is set, the receiver scrolls to the left. When the + * receiver is resized larger, the text is not scrolled + * back. The fix is to detect this case and scroll the + * text back. + */ +// inset := self inset. +// nWidth := self dimensionAt: XmNwidth. +// self noWarnings: [super resizeWidget]. +// nWidth > inset x ifTrue: [^self]. +// self showPosition: self topCharacter + return changed; +} +/** + * Sets the double click enabled flag. + * <p> + * The double click flag enables or disables the + * default action of the text widget when the user + * double clicks. + * </p> + * + * @param doubleClick the new double click flag + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setDoubleClickEnabled (boolean doubleClick) {
- checkWidget();
- int [] argList = {OS.XmNselectionArrayCount, doubleClick ? 4 : 1};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
+public void setDoubleClickEnabled (boolean doubleClick) { + checkWidget(); + int [] argList = {OS.XmNselectionArrayCount, doubleClick ? 4 : 1}; + OS.XtSetValues (handle, argList, argList.length / 2); +} /** * Sets the echo character. * <p> @@ -1126,52 +1126,52 @@ public void setDoubleClickEnabled (boolean doubleClick) { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setEchoChar (char echo) {
- checkWidget();
- if (echoCharacter == echo) return;
- String newText;
- if (echo == 0) {
- newText = hiddenText;
- hiddenText = null;
- } else {
- newText = hiddenText = getText();
- }
- echoCharacter = echo;
- Point selection = getSelection();
- boolean oldValue = ignoreChange;
- ignoreChange = true;
- setText(newText);
- setSelection(selection);
- ignoreChange = oldValue;
-}
-/**
- * Sets the editable state.
- *
- * @param editable the new editable state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void setEchoChar (char echo) { + checkWidget(); + if (echoCharacter == echo) return; + String newText; + if (echo == 0) { + newText = hiddenText; + hiddenText = null; + } else { + newText = hiddenText = getText(); + } + echoCharacter = echo; + Point selection = getSelection(); + boolean oldValue = ignoreChange; + ignoreChange = true; + setText(newText); + setSelection(selection); + ignoreChange = oldValue; +} +/** + * Sets the editable state. + * + * @param editable the new editable state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setEditable (boolean editable) {
- checkWidget();
- OS.XmTextSetEditable (handle, editable);
- style &= ~SWT.READ_ONLY;
- if (!editable) style |= SWT.READ_ONLY;
- if ((style & SWT.MULTI) != 0) return;
- int [] argList = {OS.XmNcursorPositionVisible, editable && hasFocus () ? 1 : 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-public void setRedraw (boolean redraw) {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return;
- if (redraw) {
- if (--drawCount == 0) OS.XmTextEnableRedisplay(handle);
- } else {
- if (drawCount++ == 0) OS.XmTextDisableRedisplay(handle);
- }
-}
+public void setEditable (boolean editable) { + checkWidget(); + OS.XmTextSetEditable (handle, editable); + style &= ~SWT.READ_ONLY; + if (!editable) style |= SWT.READ_ONLY; + if ((style & SWT.MULTI) != 0) return; + int [] argList = {OS.XmNcursorPositionVisible, editable && hasFocus () ? 1 : 0}; + OS.XtSetValues (handle, argList, argList.length / 2); +} +public void setRedraw (boolean redraw) { + checkWidget(); + if ((style & SWT.SINGLE) != 0) return; + if (redraw) { + if (--drawCount == 0) OS.XmTextEnableRedisplay(handle); + } else { + if (drawCount++ == 0) OS.XmTextDisableRedisplay(handle); + } +} /** * Sets the selection. * <p> @@ -1195,23 +1195,23 @@ public void setRedraw (boolean redraw) { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setSelection (int start) {
- checkWidget();
- /* Clear the selection and highlight before moving the i-beam. */
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int position = OS.XmTextGetLastPosition (handle);
- int nStart = Math.min (Math.max (start, 0), position);
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
-// OS.XmTextSetHighlight (handle, 0, position, OS.XmHIGHLIGHT_NORMAL);
- OS.XmTextClearSelection (handle, OS.XtLastTimestampProcessed (xDisplay));
-
- /* Set the i-beam position. */
- OS.XmTextSetInsertionPosition (handle, nStart);
- display.setWarnings (warnings);
-}
+public void setSelection (int start) { + checkWidget(); + /* Clear the selection and highlight before moving the i-beam. */ + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return; + int position = OS.XmTextGetLastPosition (handle); + int nStart = Math.min (Math.max (start, 0), position); + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); +// OS.XmTextSetHighlight (handle, 0, position, OS.XmHIGHLIGHT_NORMAL); + OS.XmTextClearSelection (handle, OS.XtLastTimestampProcessed (xDisplay)); + + /* Set the i-beam position. */ + OS.XmTextSetInsertionPosition (handle, nStart); + display.setWarnings (warnings); +} /** * Sets the selection. * <p> @@ -1236,36 +1236,36 @@ public void setSelection (int start) { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setSelection (int start, int end) {
- checkWidget();
- /* Clear the highlight before setting the selection. */
- int position = OS.XmTextGetLastPosition (handle);
-// OS.XmTextSetHighlight (handle, 0, position, OS.XmHIGHLIGHT_NORMAL);
-
- /*
- * Bug in MOTIF. XmTextSetSelection () fails to set the
- * selection when the receiver is not realized. The fix
- * is to force the receiver to be realized by forcing the
- * shell to be realized. If the receiver is realized before
- * the shell, MOTIF fails to draw the text widget and issues
- * lots of X BadDrawable errors.
- */
- if (!OS.XtIsRealized (handle)) getShell ().realizeWidget ();
-
- /* Set the selection. */
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int nStart = Math.min (Math.max (Math.min (start, end), 0), position);
- int nEnd = Math.min (Math.max (Math.max (start, end), 0), position);
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetSelection (handle, nStart, nEnd, OS.XtLastTimestampProcessed (xDisplay));
-
- /* Force the i-beam to follow the highlight/selection. */
- OS.XmTextSetInsertionPosition (handle, nEnd);
- display.setWarnings (warnings);
-}
+public void setSelection (int start, int end) { + checkWidget(); + /* Clear the highlight before setting the selection. */ + int position = OS.XmTextGetLastPosition (handle); +// OS.XmTextSetHighlight (handle, 0, position, OS.XmHIGHLIGHT_NORMAL); + + /* + * Bug in MOTIF. XmTextSetSelection () fails to set the + * selection when the receiver is not realized. The fix + * is to force the receiver to be realized by forcing the + * shell to be realized. If the receiver is realized before + * the shell, MOTIF fails to draw the text widget and issues + * lots of X BadDrawable errors. + */ + if (!OS.XtIsRealized (handle)) getShell ().realizeWidget (); + + /* Set the selection. */ + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return; + int nStart = Math.min (Math.max (Math.min (start, end), 0), position); + int nEnd = Math.min (Math.max (Math.max (start, end), 0), position); + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XmTextSetSelection (handle, nStart, nEnd, OS.XtLastTimestampProcessed (xDisplay)); + + /* Force the i-beam to follow the highlight/selection. */ + OS.XmTextSetInsertionPosition (handle, nEnd); + display.setWarnings (warnings); +} /** * Sets the selection. * <p> @@ -1292,31 +1292,31 @@ public void setSelection (int start, int end) { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setSelection (Point selection) {
- checkWidget();
- if (selection == null) error (SWT.ERROR_NULL_ARGUMENT);
- setSelection (selection.x, selection.y);
-}
-/**
- * Sets the number of tabs.
- * <p>
- * Tab stop spacing is specified in terms of the
- * space (' ') character. The width of a single
- * tab stop is the pixel width of the spaces.
- * </p>
- *
- * @param tabs the number of tabs
- *
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void setSelection (Point selection) { + checkWidget(); + if (selection == null) error (SWT.ERROR_NULL_ARGUMENT); + setSelection (selection.x, selection.y); +} +/** + * Sets the number of tabs. + * <p> + * Tab stop spacing is specified in terms of the + * space (' ') character. The width of a single + * tab stop is the pixel width of the spaces. + * </p> + * + * @param tabs the number of tabs + * + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setTabs (int tabs) {
- checkWidget();
- /* Do nothing. Tabs are not supported in MOTIF. */
-}
+public void setTabs (int tabs) { + checkWidget(); + /* Do nothing. Tabs are not supported in MOTIF. */ +} /** * Sets the contents of the receiver to the given string. If the receiver has style * SINGLE and the argument contains multiple lines of text, the result of this @@ -1332,23 +1332,23 @@ public void setTabs (int tabs) { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true);
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- OS.XmTextSetString (handle, buffer);
- OS.XmTextSetInsertionPosition (handle, 0);
- display.setWarnings(warnings);
- /*
- * Bug in Linux. When the widget is multi-line
- * it does not send a Modify to notify the application
- * that the text has changed. The fix is to send the event.
- */
- if (OS.IsLinux && (style & SWT.MULTI) != 0) sendEvent (SWT.Modify);
-}
+public void setText (String string) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + byte [] buffer = Converter.wcsToMbcs (getCodePage (), string, true); + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + OS.XmTextSetString (handle, buffer); + OS.XmTextSetInsertionPosition (handle, 0); + display.setWarnings(warnings); + /* + * Bug in Linux. When the widget is multi-line + * it does not send a Modify to notify the application + * that the text has changed. The fix is to send the event. + */ + if (OS.IsLinux && (style & SWT.MULTI) != 0) sendEvent (SWT.Modify); +} /** * Sets the maximum number of characters that the receiver * is capable of holding to be the argument. @@ -1369,153 +1369,153 @@ public void setText (String string) { * <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);
- OS.XmTextSetMaxLength (handle, limit);
-}
-/**
- * Sets the zero-relative index of the line which is currently
- * at the top of the receiver. This index can change when lines
- * are scrolled or new lines are added and removed.
- *
- * @param index the index of the top item
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void setTextLimit (int limit) { + checkWidget(); + if (limit == 0) error (SWT.ERROR_CANNOT_BE_ZERO); + OS.XmTextSetMaxLength (handle, limit); +} +/** + * Sets the zero-relative index of the line which is currently + * at the top of the receiver. This index can change when lines + * are scrolled or new lines are added and removed. + * + * @param index the index of the top item + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setTopIndex (int index) {
- checkWidget();
- if ((style & SWT.SINGLE) != 0) return;
- if (scrolledHandle == 0) return;
- int [] argList1 = {OS.XmNverticalScrollBar, 0};
- OS.XtGetValues (scrolledHandle, argList1, argList1.length / 2);
- if (argList1 [1] == 0) return;
- int [] argList2 = {OS.XmNvalue, 0};
- OS.XtGetValues (argList1 [1], argList2, argList2.length / 2);
- OS.XmTextScroll (handle, index - argList2 [1]);
-}
-/**
- * Shows the selection.
- * <p>
- * If the selection is already showing
- * in the receiver, this method simply returns. Otherwise,
- * lines are scrolled until the selection is visible.
- * </p>
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void setTopIndex (int index) { + checkWidget(); + if ((style & SWT.SINGLE) != 0) return; + if (scrolledHandle == 0) return; + int [] argList1 = {OS.XmNverticalScrollBar, 0}; + OS.XtGetValues (scrolledHandle, argList1, argList1.length / 2); + if (argList1 [1] == 0) return; + int [] argList2 = {OS.XmNvalue, 0}; + OS.XtGetValues (argList1 [1], argList2, argList2.length / 2); + OS.XmTextScroll (handle, index - argList2 [1]); +} +/** + * Shows the selection. + * <p> + * If the selection is already showing + * in the receiver, this method simply returns. Otherwise, + * lines are scrolled until the selection is visible. + * </p> + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the 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();
- Display display = getDisplay ();
- boolean warnings = display.getWarnings ();
- display.setWarnings (false);
- int position = OS.XmTextGetInsertionPosition (handle);
- OS.XmTextShowPosition (handle, position);
- display.setWarnings (warnings);
-}
-int traversalCode (int key, XKeyEvent xEvent) {
- int bits = super.traversalCode (key, xEvent);
- if ((style & SWT.READ_ONLY) != 0) return bits;
- if ((style & SWT.MULTI) != 0) {
- bits &= ~SWT.TRAVERSE_RETURN;
- if (key == OS.XK_Tab && xEvent != null) {
- boolean next = (xEvent.state & OS.ShiftMask) == 0;
- if (next && (xEvent.state & OS.ControlMask) == 0) {
- bits &= ~(SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS);
- }
- }
- }
- return bits;
-}
-int xFocusIn () {
- super.xFocusIn ();
- // widget could be disposed at this point
- if (handle == 0) return 0;
- if ((style & SWT.READ_ONLY) != 0) return 0;
- if ((style & SWT.MULTI) != 0) return 0;
- int [] argList = {OS.XmNcursorPositionVisible, 1};
- OS.XtSetValues (handle, argList, argList.length / 2);
- return 0;
-}
-int xFocusOut () {
- super.xFocusOut ();
- // widget could be disposed at this point
- if (handle == 0) return 0;
- if ((style & SWT.READ_ONLY) != 0) return 0;
- if ((style & SWT.MULTI) != 0) return 0;
- int [] argList = {OS.XmNcursorPositionVisible, 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
- return 0;
-}
-int XmNactivateCallback (int w, int client_data, int call_data) {
- postEvent (SWT.DefaultSelection);
- return 0;
-}
-int XmNmodifyVerifyCallback (int w, int client_data, int call_data) {
- int result = super.XmNmodifyVerifyCallback (w, client_data, call_data);
- if (result != 0) return result;
- if (echoCharacter == '\0' && !hooks (SWT.Verify) && !filters (SWT.Verify)) return result;
- XmTextVerifyCallbackStruct textVerify = new XmTextVerifyCallbackStruct ();
- OS.memmove (textVerify, call_data, XmTextVerifyCallbackStruct.sizeof);
- XmTextBlockRec textBlock = new XmTextBlockRec ();
- OS.memmove (textBlock, textVerify.text, XmTextBlockRec.sizeof);
- byte [] buffer = new byte [textBlock.length];
- OS.memmove (buffer, textBlock.ptr, textBlock.length);
- String codePage = getCodePage ();
- String text = new String (Converter.mbcsToWcs (codePage, buffer));
- String newText = text;
- if (!ignoreChange) {
- Event event = new Event ();
- if (textVerify.event != 0) {
- XKeyEvent xEvent = new XKeyEvent ();
- OS.memmove (xEvent, textVerify.event, XKeyEvent.sizeof);
- event.time = xEvent.time;
- setKeyState (event, xEvent);
- }
- event.start = textVerify.startPos;
- event.end = textVerify.endPos;
- event.doit = textVerify.doit == 1;
- event.text = text;
- sendEvent (SWT.Verify, event);
- newText = event.text;
- textVerify.doit = (byte) ((event.doit && newText != null) ? 1 : 0);
- }
- if (newText != null) {
- if (echoCharacter != '\0' && (textVerify.doit != 0)) {
- String prefix = hiddenText.substring (0, textVerify.startPos);
- String suffix = hiddenText.substring (textVerify.endPos, hiddenText.length ());
- hiddenText = prefix + newText + suffix;
- char [] charBuffer = new char [newText.length ()];
- for (int i=0; i<charBuffer.length; i++) {
- charBuffer [i] = echoCharacter;
- }
- newText = new String (charBuffer);
- }
- if (newText != text) {
- byte [] buffer2 = Converter.wcsToMbcs (codePage, newText, true);
- int length = buffer2.length;
- int ptr = OS.XtMalloc (length);
- OS.memmove (ptr, buffer2, length);
- textBlock.ptr = ptr;
- textBlock.length = buffer2.length - 1;
- OS.memmove (textVerify.text, textBlock, XmTextBlockRec.sizeof);
- }
- }
- OS.memmove (call_data, textVerify, XmTextVerifyCallbackStruct.sizeof);
- textVerify = null;
- return result;
-}
-int XmNvalueChangedCallback (int w, int client_data, int call_data) {
- if (!ignoreChange) sendEvent (SWT.Modify);
- return 0;
-}
-}
+public void showSelection () { + checkWidget(); + Display display = getDisplay (); + boolean warnings = display.getWarnings (); + display.setWarnings (false); + int position = OS.XmTextGetInsertionPosition (handle); + OS.XmTextShowPosition (handle, position); + display.setWarnings (warnings); +} +int traversalCode (int key, XKeyEvent xEvent) { + int bits = super.traversalCode (key, xEvent); + if ((style & SWT.READ_ONLY) != 0) return bits; + if ((style & SWT.MULTI) != 0) { + bits &= ~SWT.TRAVERSE_RETURN; + if (key == OS.XK_Tab && xEvent != null) { + boolean next = (xEvent.state & OS.ShiftMask) == 0; + if (next && (xEvent.state & OS.ControlMask) == 0) { + bits &= ~(SWT.TRAVERSE_TAB_NEXT | SWT.TRAVERSE_TAB_PREVIOUS); + } + } + } + return bits; +} +int xFocusIn () { + super.xFocusIn (); + // widget could be disposed at this point + if (handle == 0) return 0; + if ((style & SWT.READ_ONLY) != 0) return 0; + if ((style & SWT.MULTI) != 0) return 0; + int [] argList = {OS.XmNcursorPositionVisible, 1}; + OS.XtSetValues (handle, argList, argList.length / 2); + return 0; +} +int xFocusOut () { + super.xFocusOut (); + // widget could be disposed at this point + if (handle == 0) return 0; + if ((style & SWT.READ_ONLY) != 0) return 0; + if ((style & SWT.MULTI) != 0) return 0; + int [] argList = {OS.XmNcursorPositionVisible, 0}; + OS.XtSetValues (handle, argList, argList.length / 2); + return 0; +} +int XmNactivateCallback (int w, int client_data, int call_data) { + postEvent (SWT.DefaultSelection); + return 0; +} +int XmNmodifyVerifyCallback (int w, int client_data, int call_data) { + int result = super.XmNmodifyVerifyCallback (w, client_data, call_data); + if (result != 0) return result; + if (echoCharacter == '\0' && !hooks (SWT.Verify) && !filters (SWT.Verify)) return result; + XmTextVerifyCallbackStruct textVerify = new XmTextVerifyCallbackStruct (); + OS.memmove (textVerify, call_data, XmTextVerifyCallbackStruct.sizeof); + XmTextBlockRec textBlock = new XmTextBlockRec (); + OS.memmove (textBlock, textVerify.text, XmTextBlockRec.sizeof); + byte [] buffer = new byte [textBlock.length]; + OS.memmove (buffer, textBlock.ptr, textBlock.length); + String codePage = getCodePage (); + String text = new String (Converter.mbcsToWcs (codePage, buffer)); + String newText = text; + if (!ignoreChange) { + Event event = new Event (); + if (textVerify.event != 0) { + XKeyEvent xEvent = new XKeyEvent (); + OS.memmove (xEvent, textVerify.event, XKeyEvent.sizeof); + event.time = xEvent.time; + setKeyState (event, xEvent); + } + event.start = textVerify.startPos; + event.end = textVerify.endPos; + event.doit = textVerify.doit == 1; + event.text = text; + sendEvent (SWT.Verify, event); + newText = event.text; + textVerify.doit = (byte) ((event.doit && newText != null) ? 1 : 0); + } + if (newText != null) { + if (echoCharacter != '\0' && (textVerify.doit != 0)) { + String prefix = hiddenText.substring (0, textVerify.startPos); + String suffix = hiddenText.substring (textVerify.endPos, hiddenText.length ()); + hiddenText = prefix + newText + suffix; + char [] charBuffer = new char [newText.length ()]; + for (int i=0; i<charBuffer.length; i++) { + charBuffer [i] = echoCharacter; + } + newText = new String (charBuffer); + } + if (newText != text) { + byte [] buffer2 = Converter.wcsToMbcs (codePage, newText, true); + int length = buffer2.length; + int ptr = OS.XtMalloc (length); + OS.memmove (ptr, buffer2, length); + textBlock.ptr = ptr; + textBlock.length = buffer2.length - 1; + OS.memmove (textVerify.text, textBlock, XmTextBlockRec.sizeof); + } + } + OS.memmove (call_data, textVerify, XmTextVerifyCallbackStruct.sizeof); + textVerify = null; + return result; +} +int XmNvalueChangedCallback (int w, int client_data, int call_data) { + if (!ignoreChange) sendEvent (SWT.Modify); + return 0; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java index bf9b6d4938..92ded275b6 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolBar.java @@ -1,16 +1,16 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; + /** * Instances of this class support the layout of selectable * tool bar items. @@ -34,9 +34,9 @@ import org.eclipse.swt.graphics.*; * IMPORTANT: This class is <em>not</em> intended to be subclassed. * </p> */ -public class ToolBar extends Composite {
- int drawCount, itemCount;
- ToolItem [] items;
+public class ToolBar extends Composite { + int drawCount, itemCount; + ToolItem [] items; /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -69,380 +69,380 @@ public class ToolBar extends Composite { * @see Widget#checkSubclass * @see Widget#getStyle */ -public ToolBar (Composite parent, int style) {
- super (parent, checkStyle (style));
-
- /*
- * Ensure that either of HORIZONTAL or VERTICAL is set.
- * NOTE: HORIZONTAL and VERTICAL have the same values
- * as H_SCROLL and V_SCROLL so it is necessary to first
- * clear these bits to avoid scroll bars and then reset
- * the bits using the original style supplied by the
- * programmer.
- */
- if ((style & SWT.VERTICAL) != 0) {
- this.style |= SWT.VERTICAL;
- } else {
- this.style |= SWT.HORIZONTAL;
- }
-}
-static int checkStyle (int style) {
- /*
- * Even though it is legal to create this widget
- * with scroll bars, they serve no useful purpose
- * because they do not automatically scroll the
- * widget's client area. The fix is to clear
- * the SWT style.
- */
- return style & ~(SWT.H_SCROLL | SWT.V_SCROLL);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-public Point computeSize (int wHint, int hHint, boolean changed) {
- checkWidget();
- int width = wHint, height = hHint;
- if (wHint == SWT.DEFAULT) width = 0x7FFFFFFF;
- if (hHint == SWT.DEFAULT) height = 0x7FFFFFFF;
- int [] result = layout (width, height, false);
- int border = getBorderWidth () * 2;
- Point extent = new Point (result [1], result [2]);
- if (wHint != SWT.DEFAULT) extent.x = wHint;
- if (hHint != SWT.DEFAULT) extent.y = hHint;
- extent.x += border;
- extent.y += border;
- return extent;
-}
-void createHandle (int index) {
- super.createHandle (index);
- state &= ~CANVAS;
-}
-void createItem (ToolItem item, int index) {
- if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE);
- if (itemCount == items.length) {
- ToolItem [] newItems = new ToolItem [itemCount + 4];
- System.arraycopy (items, 0, newItems, 0, items.length);
- items = newItems;
- }
- item.createWidget (index);
- System.arraycopy (items, index, items, index + 1, itemCount++ - index);
- items [index] = item;
-}
-void createWidget (int index) {
- super.createWidget (index);
- items = new ToolItem [4];
- itemCount = 0;
-}
-void destroyItem (ToolItem item) {
- int index = 0;
- while (index < itemCount) {
- if (items [index] == item) break;
- index++;
- }
- if (index == itemCount) return;
- System.arraycopy (items, index + 1, items, index, --itemCount - index);
- items [itemCount] = null;
-}
-/**
- * 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 ToolBar (Composite parent, int style) { + super (parent, checkStyle (style)); + + /* + * Ensure that either of HORIZONTAL or VERTICAL is set. + * NOTE: HORIZONTAL and VERTICAL have the same values + * as H_SCROLL and V_SCROLL so it is necessary to first + * clear these bits to avoid scroll bars and then reset + * the bits using the original style supplied by the + * programmer. + */ + if ((style & SWT.VERTICAL) != 0) { + this.style |= SWT.VERTICAL; + } else { + this.style |= SWT.HORIZONTAL; + } +} +static int checkStyle (int style) { + /* + * Even though it is legal to create this widget + * with scroll bars, they serve no useful purpose + * because they do not automatically scroll the + * widget's client area. The fix is to clear + * the SWT style. + */ + return style & ~(SWT.H_SCROLL | SWT.V_SCROLL); +} +protected void checkSubclass () { + if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); +} +public Point computeSize (int wHint, int hHint, boolean changed) { + checkWidget(); + int width = wHint, height = hHint; + if (wHint == SWT.DEFAULT) width = 0x7FFFFFFF; + if (hHint == SWT.DEFAULT) height = 0x7FFFFFFF; + int [] result = layout (width, height, false); + int border = getBorderWidth () * 2; + Point extent = new Point (result [1], result [2]); + if (wHint != SWT.DEFAULT) extent.x = wHint; + if (hHint != SWT.DEFAULT) extent.y = hHint; + extent.x += border; + extent.y += border; + return extent; +} +void createHandle (int index) { + super.createHandle (index); + state &= ~CANVAS; +} +void createItem (ToolItem item, int index) { + if (!(0 <= index && index <= itemCount)) error (SWT.ERROR_INVALID_RANGE); + if (itemCount == items.length) { + ToolItem [] newItems = new ToolItem [itemCount + 4]; + System.arraycopy (items, 0, newItems, 0, items.length); + items = newItems; + } + item.createWidget (index); + System.arraycopy (items, index, items, index + 1, itemCount++ - index); + items [index] = item; +} +void createWidget (int index) { + super.createWidget (index); + items = new ToolItem [4]; + itemCount = 0; +} +void destroyItem (ToolItem item) { + int index = 0; + while (index < itemCount) { + if (items [index] == item) break; + index++; + } + if (index == itemCount) return; + System.arraycopy (items, index + 1, items, index, --itemCount - index); + items [itemCount] = null; +} +/** + * Returns the item at the given, zero-relative index in the + * receiver. Throws an exception if the index is out of range. + * + * @param index the index of the item to return + * @return the item at the given index + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_RANGE - if the index is not between 0 and the number of elements in the list minus 1 (inclusive)</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public ToolItem getItem (int index) {
- checkWidget();
- ToolItem [] items = getItems ();
- if (0 <= index && index < items.length) return items [index];
- error (SWT.ERROR_INVALID_RANGE);
- return null;
-}
-
-/**
- * Returns the item at the given point in the receiver
- * or null if no such item exists. The point is in the
- * coordinate system of the receiver.
- *
- * @param point the point used to locate the item
- * @return the item at the given point
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public ToolItem getItem (int index) { + checkWidget(); + ToolItem [] items = getItems (); + if (0 <= index && index < items.length) return items [index]; + error (SWT.ERROR_INVALID_RANGE); + return null; +} + +/** + * Returns the item at the given point in the receiver + * or null if no such item exists. The point is in the + * coordinate system of the receiver. + * + * @param point the point used to locate the item + * @return the item at the given point + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public ToolItem getItem (Point pt) {
- checkWidget();
- ToolItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- Rectangle rect = items [i].getBounds ();
- if (rect.contains (pt)) return items [i];
- }
- return null;
-}
-
-/**
- * Returns the number of items contained in the receiver.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public ToolItem getItem (Point pt) { + checkWidget(); + ToolItem [] items = getItems (); + for (int i=0; i<items.length; i++) { + Rectangle rect = items [i].getBounds (); + if (rect.contains (pt)) return items [i]; + } + return null; +} + +/** + * Returns the number of items contained in the receiver. + * + * @return the number of items + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getItemCount () {
- checkWidget();
- return itemCount;
-}
-/**
- * Returns an array of <code>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 int getItemCount () { + checkWidget(); + return itemCount; +} +/** + * Returns an array of <code>TabItem</code>s which are the items + * in the receiver. + * <p> + * Note: This is not the actual structure used by the receiver + * to maintain its list of items, so modifying the array will + * not affect the receiver. + * </p> + * + * @return the items in the receiver + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public ToolItem [] getItems () {
- checkWidget();
- ToolItem [] result = new ToolItem [itemCount];
- System.arraycopy (items, 0, result, 0, itemCount);
- return result;
-}
-/**
- * Returns the number of rows in the receiver. When
- * the receiver has the <code>WRAP</code> style, the
- * number of rows can be greater than one. Otherwise,
- * the number of rows is always one.
- *
- * @return the number of items
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public ToolItem [] getItems () { + checkWidget(); + ToolItem [] result = new ToolItem [itemCount]; + System.arraycopy (items, 0, result, 0, itemCount); + return result; +} +/** + * Returns the number of rows in the receiver. When + * the receiver has the <code>WRAP</code> style, the + * number of rows can be greater than one. Otherwise, + * the number of rows is always one. + * + * @return the number of items + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getRowCount () {
- checkWidget();
- Rectangle rect = getClientArea ();
- return layout (rect.width, rect.height, false) [0];
-}
-/**
- * Searches the receiver's list starting at the first item
- * (index 0) until an item is found that is equal to the
- * argument, and returns the index of that item. If no item
- * is found, returns -1.
- *
- * @param item the search item
- * @return the index of the item
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the tool item is null</li>
- * <li>ERROR_INVALID_ARGUMENT - if the tool item has been disposed</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getRowCount () { + checkWidget(); + Rectangle rect = getClientArea (); + return layout (rect.width, rect.height, false) [0]; +} +/** + * Searches the receiver's list starting at the first item + * (index 0) until an item is found that is equal to the + * argument, and returns the index of that item. If no item + * is found, returns -1. + * + * @param item the search item + * @return the index of the item + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the tool item is null</li> + * <li>ERROR_INVALID_ARGUMENT - if the tool item has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int indexOf (ToolItem item) {
- checkWidget();
- if (item == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- ToolItem [] items = getItems ();
- for (int i=0; i<items.length; i++) {
- if (items [i] == item) return i;
- }
- return -1;
-}
-int [] layoutHorizontal (int nWidth, int nHeight, boolean resize) {
- int xSpacing = 0, ySpacing = (style & SWT.NO_FOCUS) != 0 ? 4 : 2;
- int marginWidth = 0, marginHeight = 0;
- ToolItem [] children = getItems ();
- int length = children.length;
- int x = marginWidth, y = marginHeight;
- int maxHeight = 0, maxX = 0, rows = 1;
- boolean wrap = (style & SWT.WRAP) != 0;
- for (int i=0; i<length; i++) {
- ToolItem child = children [i];
- Rectangle rect = child.getBounds ();
- if (wrap && i != 0 && x + rect.width > nWidth) {
- rows++;
- x = marginWidth; y += ySpacing + maxHeight;
- maxHeight = 0;
- }
- maxHeight = Math.max (maxHeight, rect.height);
- if (resize) {
- child.setBounds (x, y, rect.width, rect.height);
- }
- x += xSpacing + rect.width;
- maxX = Math.max (maxX, x);
- }
- return new int [] {rows, maxX, y + maxHeight};
-}
-int [] layoutVertical (int nWidth, int nHeight, boolean resize) {
- int xSpacing = (style & SWT.NO_FOCUS) != 0 ? 4 : 2, ySpacing = 0;
- int marginWidth = 0, marginHeight = 0;
- ToolItem [] children = getItems ();
- int length = children.length;
- int x = marginWidth, y = marginHeight;
- int maxWidth = 0, maxY = 0, cols = 1;
- boolean wrap = (style & SWT.WRAP) != 0;
- for (int i=0; i<length; i++) {
- ToolItem child = children [i];
- Rectangle rect = child.getBounds ();
- if (wrap && i != 0 && y + rect.height > nHeight) {
- cols++;
- x += xSpacing + maxWidth; y = marginHeight;
- maxWidth = 0;
- }
- maxWidth = Math.max (maxWidth, rect.width);
- if (resize) {
- child.setBounds (x, y, rect.width, rect.height);
- }
- y += ySpacing + rect.height;
- maxY = Math.max (maxY, y);
- }
- return new int [] {cols, x + maxWidth, maxY};
-}
-int [] layout (int nWidth, int nHeight, boolean resize) {
- if ((style & SWT.VERTICAL) != 0) {
- return layoutVertical (nWidth, nHeight, resize);
- } else {
- return layoutHorizontal (nWidth, nHeight, resize);
- }
-}
-boolean mnemonicHit (char key) {
- for (int i = 0; i < items.length; i++) {
- ToolItem item = items [i];
- if (item != null) {
- char mnemonic = findMnemonic (item.getText ());
- if (mnemonic != '\0') {
- if (Character.toUpperCase (key) == Character.toUpperCase (mnemonic)) {
- XmProcessTraversal (item.handle, OS.XmTRAVERSE_CURRENT);
- item.click (false, null);
- return true;
- }
- }
- }
- }
- return false;
-}
-boolean mnemonicMatch (char key) {
- for (int i = 0; i < items.length; i++) {
- ToolItem item = items [i];
- if (item != null && item.getEnabled ()) {
- char mnemonic = findMnemonic (item.getText ());
- if (mnemonic != '\0') {
- if (Character.toUpperCase (key) == Character.toUpperCase (mnemonic)) {
- return true;
- }
- }
- }
- }
- return false;
-}
-void propagateWidget (boolean enabled) {
- super.propagateWidget (enabled);
- for (int i=0; i<itemCount; i++) {
- items [i].propagateWidget (enabled);
- }
-}
-void relayout () {
- if (drawCount > 0) return;
- Rectangle rect = getClientArea ();
- layout (rect.width, rect.height, true);
-}
-void relayout (int width, int height) {
- if (drawCount > 0) return;
- layout (width, height, true);
-}
-void releaseWidget () {
- for (int i=0; i<itemCount; i++) {
- ToolItem item = items [i];
- if (!item.isDisposed ()) item.releaseResources ();
- }
- items = null;
- super.releaseWidget ();
-}
-void setBackgroundPixel (int pixel) {
- super.setBackgroundPixel (pixel);
- for (int i = 0; i < items.length; i++) {
- if (items[i] != null) {
- items[i].setBackgroundPixel (pixel);
- }
- }
-}
-public void setBounds (int x, int y, int width, int height) {
- super.setBounds (x, y, width, height);
- Rectangle rect = getClientArea ();
- relayout (rect.width, rect.height);
-}
-public void setFont (Font font) {
- checkWidget();
- super.setFont (font);
- for (int i=0; i<items.length; i++) {
- ToolItem item = items [i];
- if (item != null) {
- Point size = item.computeSize ();
- item.setSize (size.x, size.y, false);
- }
- }
- relayout ();
-}
-void setForegroundPixel (int pixel) {
- super.setForegroundPixel (pixel);
- for (int i = 0; i < items.length; i++) {
- if (items[i] != null) {
- items[i].setForegroundPixel (pixel);
- }
- }
-}
-public void setRedraw (boolean redraw) {
- checkWidget();
- if (redraw) {
- if (--drawCount == 0) relayout();
- } else {
- drawCount++;
- }
-}
-public void setSize (int width, int height) {
- super.setSize (width, height);
- Rectangle rect = getClientArea ();
- relayout (rect.width, rect.height);
-}
-boolean setTabItemFocus () {
- int index = 0;
- while (index < items.length) {
- ToolItem item = items [index];
- if (item != null && (item.style & SWT.SEPARATOR) == 0) {
- if (item.getEnabled ()) break;
- }
- index++;
- }
- if (index == items.length) return false;
- return super.setTabItemFocus ();
-}
-int traversalCode (int key, XKeyEvent xEvent) {
- return super.traversalCode (key, xEvent) | SWT.TRAVERSE_MNEMONIC;
-}
-}
+public int indexOf (ToolItem item) { + checkWidget(); + if (item == null) error (SWT.ERROR_NULL_ARGUMENT); + if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); + ToolItem [] items = getItems (); + for (int i=0; i<items.length; i++) { + if (items [i] == item) return i; + } + return -1; +} +int [] layoutHorizontal (int nWidth, int nHeight, boolean resize) { + int xSpacing = 0, ySpacing = (style & SWT.NO_FOCUS) != 0 ? 4 : 2; + int marginWidth = 0, marginHeight = 0; + ToolItem [] children = getItems (); + int length = children.length; + int x = marginWidth, y = marginHeight; + int maxHeight = 0, maxX = 0, rows = 1; + boolean wrap = (style & SWT.WRAP) != 0; + for (int i=0; i<length; i++) { + ToolItem child = children [i]; + Rectangle rect = child.getBounds (); + if (wrap && i != 0 && x + rect.width > nWidth) { + rows++; + x = marginWidth; y += ySpacing + maxHeight; + maxHeight = 0; + } + maxHeight = Math.max (maxHeight, rect.height); + if (resize) { + child.setBounds (x, y, rect.width, rect.height); + } + x += xSpacing + rect.width; + maxX = Math.max (maxX, x); + } + return new int [] {rows, maxX, y + maxHeight}; +} +int [] layoutVertical (int nWidth, int nHeight, boolean resize) { + int xSpacing = (style & SWT.NO_FOCUS) != 0 ? 4 : 2, ySpacing = 0; + int marginWidth = 0, marginHeight = 0; + ToolItem [] children = getItems (); + int length = children.length; + int x = marginWidth, y = marginHeight; + int maxWidth = 0, maxY = 0, cols = 1; + boolean wrap = (style & SWT.WRAP) != 0; + for (int i=0; i<length; i++) { + ToolItem child = children [i]; + Rectangle rect = child.getBounds (); + if (wrap && i != 0 && y + rect.height > nHeight) { + cols++; + x += xSpacing + maxWidth; y = marginHeight; + maxWidth = 0; + } + maxWidth = Math.max (maxWidth, rect.width); + if (resize) { + child.setBounds (x, y, rect.width, rect.height); + } + y += ySpacing + rect.height; + maxY = Math.max (maxY, y); + } + return new int [] {cols, x + maxWidth, maxY}; +} +int [] layout (int nWidth, int nHeight, boolean resize) { + if ((style & SWT.VERTICAL) != 0) { + return layoutVertical (nWidth, nHeight, resize); + } else { + return layoutHorizontal (nWidth, nHeight, resize); + } +} +boolean mnemonicHit (char key) { + for (int i = 0; i < items.length; i++) { + ToolItem item = items [i]; + if (item != null) { + char mnemonic = findMnemonic (item.getText ()); + if (mnemonic != '\0') { + if (Character.toUpperCase (key) == Character.toUpperCase (mnemonic)) { + XmProcessTraversal (item.handle, OS.XmTRAVERSE_CURRENT); + item.click (false, null); + return true; + } + } + } + } + return false; +} +boolean mnemonicMatch (char key) { + for (int i = 0; i < items.length; i++) { + ToolItem item = items [i]; + if (item != null && item.getEnabled ()) { + char mnemonic = findMnemonic (item.getText ()); + if (mnemonic != '\0') { + if (Character.toUpperCase (key) == Character.toUpperCase (mnemonic)) { + return true; + } + } + } + } + return false; +} +void propagateWidget (boolean enabled) { + super.propagateWidget (enabled); + for (int i=0; i<itemCount; i++) { + items [i].propagateWidget (enabled); + } +} +void relayout () { + if (drawCount > 0) return; + Rectangle rect = getClientArea (); + layout (rect.width, rect.height, true); +} +void relayout (int width, int height) { + if (drawCount > 0) return; + layout (width, height, true); +} +void releaseWidget () { + for (int i=0; i<itemCount; i++) { + ToolItem item = items [i]; + if (!item.isDisposed ()) item.releaseResources (); + } + items = null; + super.releaseWidget (); +} +void setBackgroundPixel (int pixel) { + super.setBackgroundPixel (pixel); + for (int i = 0; i < items.length; i++) { + if (items[i] != null) { + items[i].setBackgroundPixel (pixel); + } + } +} +public void setBounds (int x, int y, int width, int height) { + super.setBounds (x, y, width, height); + Rectangle rect = getClientArea (); + relayout (rect.width, rect.height); +} +public void setFont (Font font) { + checkWidget(); + super.setFont (font); + for (int i=0; i<items.length; i++) { + ToolItem item = items [i]; + if (item != null) { + Point size = item.computeSize (); + item.setSize (size.x, size.y, false); + } + } + relayout (); +} +void setForegroundPixel (int pixel) { + super.setForegroundPixel (pixel); + for (int i = 0; i < items.length; i++) { + if (items[i] != null) { + items[i].setForegroundPixel (pixel); + } + } +} +public void setRedraw (boolean redraw) { + checkWidget(); + if (redraw) { + if (--drawCount == 0) relayout(); + } else { + drawCount++; + } +} +public void setSize (int width, int height) { + super.setSize (width, height); + Rectangle rect = getClientArea (); + relayout (rect.width, rect.height); +} +boolean setTabItemFocus () { + int index = 0; + while (index < items.length) { + ToolItem item = items [index]; + if (item != null && (item.style & SWT.SEPARATOR) == 0) { + if (item.getEnabled ()) break; + } + index++; + } + if (index == items.length) return false; + return super.setTabItemFocus (); +} +int traversalCode (int key, XKeyEvent xEvent) { + return super.traversalCode (key, xEvent) | SWT.TRAVERSE_MNEMONIC; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolDrawable.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolDrawable.java index 519806e5eb..0315c71630 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolDrawable.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolDrawable.java @@ -1,39 +1,39 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.internal.motif.*;
-
-class ToolDrawable implements Drawable {
-
- Device device;
- int display;
- int drawable;
- Font font;
- int colormap;
-
-public int internal_new_GC (GCData data) {
- int xGC = OS.XCreateGC (display, drawable, 0, null);
- if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES);
- if (data != null) {
- data.device = device;
- data.display = display;
- data.drawable = drawable;
- data.fontList = font.handle;
- data.codePage = font.codePage;
- data.colormap = colormap;
- }
- return xGC;
-}
-
-public void internal_dispose_GC (int xGC, GCData data) {
- OS.XFreeGC (display, xGC);
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.internal.motif.*; + +class ToolDrawable implements Drawable { + + Device device; + int display; + int drawable; + Font font; + int colormap; + +public int internal_new_GC (GCData data) { + int xGC = OS.XCreateGC (display, drawable, 0, null); + if (xGC == 0) SWT.error(SWT.ERROR_NO_HANDLES); + if (data != null) { + data.device = device; + data.display = display; + data.drawable = drawable; + data.fontList = font.handle; + data.codePage = font.codePage; + data.colormap = colormap; + } + return xGC; +} + +public void internal_dispose_GC (int xGC, GCData data) { + OS.XFreeGC (display, xGC); +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java index 66cde49cf1..3b29933977 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/ToolItem.java @@ -1,44 +1,44 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class represent a selectable user interface object
- * that represents a button in a tool bar.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>PUSH, CHECK, RADIO, SEPARATOR, DROP_DOWN</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Selection</dd>
- * </dl>
- * <p>
- * Note: Only one of the styles CHECK, PUSH, RADIO, SEPARATOR and DROP_DOWN
- * may be specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
+ * http://www.eclipse.org/legal/cpl-v10.html */ -public class ToolItem extends Item {
- ToolBar parent;
- Image hotImage, disabledImage;
- String toolTipText;
- Control control;
- boolean set;
-
- static final int DEFAULT_WIDTH = 24;
- static final int DEFAULT_HEIGHT = 22;
- static final int DEFAULT_SEPARATOR_WIDTH = 8;
-
+ +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.events.*; + +/** + * Instances of this class represent a selectable user interface object + * that represents a button in a tool bar. + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>PUSH, CHECK, RADIO, SEPARATOR, DROP_DOWN</dd> + * <dt><b>Events:</b></dt> + * <dd>Selection</dd> + * </dl> + * <p> + * Note: Only one of the styles CHECK, PUSH, RADIO, SEPARATOR and DROP_DOWN + * may be specified. + * </p><p> + * IMPORTANT: This class is <em>not</em> intended to be subclassed. + * </p> + */ +public class ToolItem extends Item { + ToolBar parent; + Image hotImage, disabledImage; + String toolTipText; + Control control; + boolean set; + + static final int DEFAULT_WIDTH = 24; + static final int DEFAULT_HEIGHT = 22; + static final int DEFAULT_SEPARATOR_WIDTH = 8; + /** * Constructs a new instance of this class given its parent * (which must be a <code>ToolBar</code>) and a style value @@ -73,13 +73,13 @@ public class ToolItem extends Item { * @see Widget#checkSubclass * @see Widget#getStyle */ -public ToolItem (ToolBar parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, parent.getItemCount ());
- parent.relayout ();
-}
-
+public ToolItem (ToolBar parent, int style) { + super (parent, checkStyle (style)); + this.parent = parent; + parent.createItem (this, parent.getItemCount ()); + parent.relayout (); +} + /** * Constructs a new instance of this class given its parent * (which must be a <code>ToolBar</code>), a style value @@ -115,209 +115,209 @@ public ToolItem (ToolBar parent, int style) { * @see Widget#checkSubclass * @see Widget#getStyle */ -public ToolItem (ToolBar parent, int style, int index) {
- super (parent, checkStyle (style));
- this.parent = parent;
- parent.createItem (this, index);
- parent.relayout ();
-}
-
-/**
- * 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 ToolItem (ToolBar parent, int style, int index) { + super (parent, checkStyle (style)); + this.parent = parent; + parent.createItem (this, index); + parent.relayout (); +} + +/** + * 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) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener(listener);
- addListener(SWT.Selection,typedListener);
- addListener(SWT.DefaultSelection,typedListener);
-}
-static int checkStyle (int style) {
- return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.DROP_DOWN, 0);
-}
-protected void checkSubclass () {
- if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS);
-}
-void createHandle (int index) {
- state |= HANDLE;
- int parentHandle = parent.handle;
- if ((style & SWT.SEPARATOR) != 0) {
- int orientation = (parent.style & SWT.HORIZONTAL) != 0 ? OS.XmVERTICAL : OS.XmHORIZONTAL;
- int [] argList = {
- OS.XmNheight, orientation == OS.XmVERTICAL ? DEFAULT_HEIGHT : DEFAULT_SEPARATOR_WIDTH,
- OS.XmNwidth, orientation == OS.XmHORIZONTAL ? DEFAULT_WIDTH : DEFAULT_SEPARATOR_WIDTH,
- OS.XmNancestorSensitive, 1,
- OS.XmNpositionIndex, index,
- OS.XmNorientation, orientation,
- OS.XmNseparatorType, (parent.style & SWT.FLAT) != 0 ? OS.XmSHADOW_ETCHED_IN : OS.XmSHADOW_ETCHED_OUT,
- };
- handle = OS.XmCreateSeparator (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- return;
- }
- int [] argList = {
- OS.XmNwidth, DEFAULT_WIDTH,
- OS.XmNheight, DEFAULT_HEIGHT,
- OS.XmNrecomputeSize, 0,
- OS.XmNhighlightThickness, (parent.style & SWT.NO_FOCUS) != 0 ? 0 : 1,
- OS.XmNmarginWidth, 2,
- OS.XmNmarginHeight, 1,
- OS.XmNtraversalOn, (parent.style & SWT.NO_FOCUS) != 0 ? 0 : 1,
- OS.XmNpositionIndex, index,
- OS.XmNshadowType, OS.XmSHADOW_OUT,
- OS.XmNancestorSensitive, 1,
- };
- handle = OS.XmCreateDrawnButton (parentHandle, null, argList, argList.length / 2);
- if (handle == 0) error (SWT.ERROR_NO_HANDLES);
- int pixel = parent.getBackgroundPixel ();
- setBackgroundPixel (pixel);
-}
-
-void click (boolean dropDown, XInputEvent xEvent) {
- if ((style & SWT.RADIO) != 0) {
- selectRadio ();
- } else {
- if ((style & SWT.CHECK) != 0) setSelection(!set);
- }
- Event event = new Event ();
- if ((style & SWT.DROP_DOWN) != 0) {
- if (dropDown) {
- event.detail = SWT.ARROW;
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- event.x = (short) argList [1];
- event.y = (short) argList [3] + (short) argList [5];
- }
- }
- if (xEvent != null) setInputState (event, xEvent);
- postEvent (SWT.Selection, event);
-}
-
-Point computeSize () {
- if ((style & SWT.SEPARATOR) != 0) {
- int [] argList = {
- OS.XmNwidth, 0,
- OS.XmNheight, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int width = argList [1], height = argList [3];
- return new Point(width, height);
- }
- int [] argList = {
- OS.XmNmarginHeight, 0,
- OS.XmNmarginWidth, 0,
- OS.XmNshadowThickness, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int marginHeight = argList [1], marginWidth = argList [3];
- int shadowThickness = argList [5];
- if ((parent.style & SWT.FLAT) != 0) {
- Display display = getDisplay ();
- shadowThickness = Math.min (2, display.buttonShadowThickness);
- }
- int textWidth = 0, textHeight = 0;
- if (text.length () != 0) {
- GC gc = new GC (parent);
- int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC;
- Point textExtent = gc.textExtent (text, flags);
- textWidth = textExtent.x;
- textHeight = textExtent.y;
- gc.dispose ();
- }
- int imageWidth = 0, imageHeight = 0;
- if (image != null) {
- Rectangle rect = image.getBounds ();
- imageWidth = rect.width;
- imageHeight = rect.height;
- }
- int width = 0, height = 0;
- if ((parent.style & SWT.RIGHT) != 0) {
- width = imageWidth + textWidth;
- height = Math.max (imageHeight, textHeight);
- if (imageWidth != 0 && textWidth != 0) width += 2;
- } else {
- height = imageHeight + textHeight;
- if (imageHeight != 0 && textHeight != 0) height += 2;
- width = Math.max (imageWidth, textWidth);
- }
- if ((style & SWT.DROP_DOWN) != 0) width += 12;
-
- if (width != 0) {
- width += (marginWidth + shadowThickness) * 2 + 2;
- } else {
- width = DEFAULT_WIDTH;
- }
- if (height != 0) {
- height += (marginHeight + shadowThickness) * 2 + 2;
- } else {
- height = DEFAULT_HEIGHT;
- }
- return new Point (width, height);
-}
-void createWidget (int index) {
- super.createWidget (index);
- parent.relayout ();
-}
-public void dispose () {
- if (isDisposed()) return;
- ToolBar parent = this.parent;
- super.dispose ();
- parent.relayout ();
-}
-/**
- * Returns a rectangle describing the receiver's size and location
- * relative to its parent.
- *
- * @return the receiver's bounding rectangle
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void addSelectionListener(SelectionListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener(listener); + addListener(SWT.Selection,typedListener); + addListener(SWT.DefaultSelection,typedListener); +} +static int checkStyle (int style) { + return checkBits (style, SWT.PUSH, SWT.CHECK, SWT.RADIO, SWT.SEPARATOR, SWT.DROP_DOWN, 0); +} +protected void checkSubclass () { + if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); +} +void createHandle (int index) { + state |= HANDLE; + int parentHandle = parent.handle; + if ((style & SWT.SEPARATOR) != 0) { + int orientation = (parent.style & SWT.HORIZONTAL) != 0 ? OS.XmVERTICAL : OS.XmHORIZONTAL; + int [] argList = { + OS.XmNheight, orientation == OS.XmVERTICAL ? DEFAULT_HEIGHT : DEFAULT_SEPARATOR_WIDTH, + OS.XmNwidth, orientation == OS.XmHORIZONTAL ? DEFAULT_WIDTH : DEFAULT_SEPARATOR_WIDTH, + OS.XmNancestorSensitive, 1, + OS.XmNpositionIndex, index, + OS.XmNorientation, orientation, + OS.XmNseparatorType, (parent.style & SWT.FLAT) != 0 ? OS.XmSHADOW_ETCHED_IN : OS.XmSHADOW_ETCHED_OUT, + }; + handle = OS.XmCreateSeparator (parentHandle, null, argList, argList.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + return; + } + int [] argList = { + OS.XmNwidth, DEFAULT_WIDTH, + OS.XmNheight, DEFAULT_HEIGHT, + OS.XmNrecomputeSize, 0, + OS.XmNhighlightThickness, (parent.style & SWT.NO_FOCUS) != 0 ? 0 : 1, + OS.XmNmarginWidth, 2, + OS.XmNmarginHeight, 1, + OS.XmNtraversalOn, (parent.style & SWT.NO_FOCUS) != 0 ? 0 : 1, + OS.XmNpositionIndex, index, + OS.XmNshadowType, OS.XmSHADOW_OUT, + OS.XmNancestorSensitive, 1, + }; + handle = OS.XmCreateDrawnButton (parentHandle, null, argList, argList.length / 2); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + int pixel = parent.getBackgroundPixel (); + setBackgroundPixel (pixel); +} + +void click (boolean dropDown, XInputEvent xEvent) { + if ((style & SWT.RADIO) != 0) { + selectRadio (); + } else { + if ((style & SWT.CHECK) != 0) setSelection(!set); + } + Event event = new Event (); + if ((style & SWT.DROP_DOWN) != 0) { + if (dropDown) { + event.detail = SWT.ARROW; + int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNheight, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + event.x = (short) argList [1]; + event.y = (short) argList [3] + (short) argList [5]; + } + } + if (xEvent != null) setInputState (event, xEvent); + postEvent (SWT.Selection, event); +} + +Point computeSize () { + if ((style & SWT.SEPARATOR) != 0) { + int [] argList = { + OS.XmNwidth, 0, + OS.XmNheight, 0, + }; + OS.XtGetValues (handle, argList, argList.length / 2); + int width = argList [1], height = argList [3]; + return new Point(width, height); + } + int [] argList = { + OS.XmNmarginHeight, 0, + OS.XmNmarginWidth, 0, + OS.XmNshadowThickness, 0, + }; + OS.XtGetValues (handle, argList, argList.length / 2); + int marginHeight = argList [1], marginWidth = argList [3]; + int shadowThickness = argList [5]; + if ((parent.style & SWT.FLAT) != 0) { + Display display = getDisplay (); + shadowThickness = Math.min (2, display.buttonShadowThickness); + } + int textWidth = 0, textHeight = 0; + if (text.length () != 0) { + GC gc = new GC (parent); + int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC; + Point textExtent = gc.textExtent (text, flags); + textWidth = textExtent.x; + textHeight = textExtent.y; + gc.dispose (); + } + int imageWidth = 0, imageHeight = 0; + if (image != null) { + Rectangle rect = image.getBounds (); + imageWidth = rect.width; + imageHeight = rect.height; + } + int width = 0, height = 0; + if ((parent.style & SWT.RIGHT) != 0) { + width = imageWidth + textWidth; + height = Math.max (imageHeight, textHeight); + if (imageWidth != 0 && textWidth != 0) width += 2; + } else { + height = imageHeight + textHeight; + if (imageHeight != 0 && textHeight != 0) height += 2; + width = Math.max (imageWidth, textWidth); + } + if ((style & SWT.DROP_DOWN) != 0) width += 12; + + if (width != 0) { + width += (marginWidth + shadowThickness) * 2 + 2; + } else { + width = DEFAULT_WIDTH; + } + if (height != 0) { + height += (marginHeight + shadowThickness) * 2 + 2; + } else { + height = DEFAULT_HEIGHT; + } + return new Point (width, height); +} +void createWidget (int index) { + super.createWidget (index); + parent.relayout (); +} +public void dispose () { + if (isDisposed()) return; + ToolBar parent = this.parent; + super.dispose (); + parent.relayout (); +} +/** + * Returns a rectangle describing the receiver's size and location + * relative to its parent. + * + * @return the receiver's bounding rectangle + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public Rectangle getBounds () {
- checkWidget();
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return new Rectangle ((short) argList [1], (short) argList [3], argList [5], argList [7]);
-}
-/**
- * Returns the control that is used to fill the bounds of
- * the item when the 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 Rectangle getBounds () { + checkWidget(); + int [] argList = {OS.XmNx, 0, OS.XmNy, 0, OS.XmNwidth, 0, OS.XmNheight, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return new Rectangle ((short) argList [1], (short) argList [3], argList [5], argList [7]); +} +/** + * Returns the control that is used to fill the bounds of + * the item when the 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 () {
- checkWidget();
- return control;
-}
+public Control getControl () { + checkWidget(); + return control; +} /** * Returns the receiver's disabled image if it has one, or null * if it does not. @@ -332,68 +332,68 @@ public Control getControl () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public Image getDisabledImage () {
- checkWidget();
- return disabledImage;
-}
-/**
- * Returns <code>true</code> if the receiver is enabled, and
- * <code>false</code> otherwise.
- * <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 Image getDisabledImage () { + checkWidget(); + return disabledImage; +} +/** + * 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 () {
- checkWidget();
- int [] argList = {OS.XmNsensitive, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1] != 0;
-}
-public Display getDisplay () {
- Composite parent = this.parent;
- if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
- return parent.getDisplay ();
-}
-/**
- * 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 boolean getEnabled () { + checkWidget(); + int [] argList = {OS.XmNsensitive, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1] != 0; +} +public Display getDisplay () { + Composite parent = this.parent; + if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED); + return parent.getDisplay (); +} +/** + * Returns the receiver's hot image if it has one, or null + * if it does not. + * <p> + * The hot image is displayed when the mouse enters the receiver. + * </p> + * + * @return the receiver's hot image + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public Image getHotImage () {
- checkWidget();
- return hotImage;
-}
-/**
- * Returns the receiver's parent, which must be a <code>ToolBar</code>.
- *
- * @return the receiver's parent
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public Image getHotImage () { + checkWidget(); + return hotImage; +} +/** + * Returns the receiver's parent, which must be a <code>ToolBar</code>. + * + * @return the receiver's parent + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public ToolBar getParent () {
- checkWidget();
- return parent;
-}
+public ToolBar getParent () { + checkWidget(); + return parent; +} /** * Returns <code>true</code> if the receiver is selected, * and false otherwise. @@ -411,317 +411,317 @@ public ToolBar getParent () { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public boolean getSelection () {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false;
- return set;
-}
-/**
- * Returns the receiver's tool tip text, or null if it has not been set.
- *
- * @return the receiver's tool tip text
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public boolean getSelection () { + checkWidget(); + if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false; + return set; +} +/** + * Returns the receiver's tool tip text, or null if it has not been set. + * + * @return the receiver's tool tip text + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public String getToolTipText () {
- checkWidget();
- return toolTipText;
-}
-/**
- * Gets the width of the receiver.
- *
- * @return the width
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public String getToolTipText () { + checkWidget(); + return toolTipText; +} +/** + * Gets the width of the receiver. + * + * @return the width + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public int getWidth () {
- checkWidget();
- int [] argList = {OS.XmNwidth, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- return argList [1];
-}
-boolean hasCursor () {
- int [] unused = new int [1], buffer = new int [1];
- int xDisplay = OS.XtDisplay (handle);
- int xWindow, xParent = OS.XDefaultRootWindow (xDisplay);
- do {
- if (OS.XQueryPointer (
- xDisplay, xParent, unused, buffer,
- unused, unused, unused, unused, unused) == 0) return false;
- if ((xWindow = buffer [0]) != 0) xParent = xWindow;
- } while (xWindow != 0);
- return handle == OS.XtWindowToWidget (xDisplay, xParent);
-}
-void hookEvents () {
- super.hookEvents ();
- if ((style & SWT.SEPARATOR) != 0) return;
- int windowProc = getDisplay ().windowProc;
- OS.XtAddEventHandler (handle, OS.KeyPressMask, false, windowProc, KEY_PRESS);
- OS.XtAddEventHandler (handle, OS.KeyReleaseMask, false, windowProc, KEY_RELEASE);
- OS.XtAddEventHandler (handle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS);
- OS.XtAddEventHandler (handle, OS.ButtonReleaseMask, false, windowProc, BUTTON_RELEASE);
- OS.XtAddEventHandler (handle, OS.PointerMotionMask, false, windowProc, POINTER_MOTION);
- OS.XtAddEventHandler (handle, OS.EnterWindowMask, false, windowProc, ENTER_WINDOW);
- OS.XtAddEventHandler (handle, OS.LeaveWindowMask, false, windowProc, LEAVE_WINDOW);
- OS.XtAddCallback (handle, OS.XmNexposeCallback, windowProc, EXPOSURE_CALLBACK);
- OS.XtInsertEventHandler (handle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail);
-}
-int hoverProc (int id) {
- boolean showTip = toolTipText != null;
- parent.hoverProc (id, !showTip);
- if (showTip) {
- Display display = getDisplay ();
- display.showToolTip (handle, toolTipText);
- }
- return 0;
-}
-/**
- * Returns <code>true</code> if the receiver is enabled and all
- * of the receiver's ancestors are enabled, and <code>false</code>
- * otherwise. A disabled control is typically not selectable from the
- * user interface and draws with an inactive or "grayed" look.
- *
- * @return the receiver's enabled state
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see #getEnabled
+public int getWidth () { + checkWidget(); + int [] argList = {OS.XmNwidth, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + return argList [1]; +} +boolean hasCursor () { + int [] unused = new int [1], buffer = new int [1]; + int xDisplay = OS.XtDisplay (handle); + int xWindow, xParent = OS.XDefaultRootWindow (xDisplay); + do { + if (OS.XQueryPointer ( + xDisplay, xParent, unused, buffer, + unused, unused, unused, unused, unused) == 0) return false; + if ((xWindow = buffer [0]) != 0) xParent = xWindow; + } while (xWindow != 0); + return handle == OS.XtWindowToWidget (xDisplay, xParent); +} +void hookEvents () { + super.hookEvents (); + if ((style & SWT.SEPARATOR) != 0) return; + int windowProc = getDisplay ().windowProc; + OS.XtAddEventHandler (handle, OS.KeyPressMask, false, windowProc, KEY_PRESS); + OS.XtAddEventHandler (handle, OS.KeyReleaseMask, false, windowProc, KEY_RELEASE); + OS.XtAddEventHandler (handle, OS.ButtonPressMask, false, windowProc, BUTTON_PRESS); + OS.XtAddEventHandler (handle, OS.ButtonReleaseMask, false, windowProc, BUTTON_RELEASE); + OS.XtAddEventHandler (handle, OS.PointerMotionMask, false, windowProc, POINTER_MOTION); + OS.XtAddEventHandler (handle, OS.EnterWindowMask, false, windowProc, ENTER_WINDOW); + OS.XtAddEventHandler (handle, OS.LeaveWindowMask, false, windowProc, LEAVE_WINDOW); + OS.XtAddCallback (handle, OS.XmNexposeCallback, windowProc, EXPOSURE_CALLBACK); + OS.XtInsertEventHandler (handle, OS.FocusChangeMask, false, windowProc, FOCUS_CHANGE, OS.XtListTail); +} +int hoverProc (int id) { + boolean showTip = toolTipText != null; + parent.hoverProc (id, !showTip); + if (showTip) { + Display display = getDisplay (); + display.showToolTip (handle, toolTipText); + } + return 0; +} +/** + * Returns <code>true</code> if the receiver is enabled and all + * of the receiver's ancestors are enabled, and <code>false</code> + * otherwise. A disabled control is typically not selectable from the + * user interface and draws with an inactive or "grayed" look. + * + * @return the receiver's enabled state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see #getEnabled */ -public boolean isEnabled () {
- checkWidget();
- return getEnabled () && parent.isEnabled ();
-}
-void manageChildren () {
- OS.XtManageChild (handle);
-}
-void redraw () {
- int display = OS.XtDisplay (handle);
- if (display == 0) return;
- int window = OS.XtWindow (handle);
- if (window == 0) return;
- OS.XClearArea (display, window, 0, 0, 0, 0, true);
-}
-void releaseChild () {
- super.releaseChild ();
- parent.destroyItem (this);
-}
-void releaseWidget () {
- Display display = getDisplay ();
- display.releaseToolTipHandle (handle);
- super.releaseWidget ();
- parent = null;
- control = null;
- toolTipText = null;
- image = disabledImage = hotImage = null;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is selected.
- *
- * @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 boolean isEnabled () { + checkWidget(); + return getEnabled () && parent.isEnabled (); +} +void manageChildren () { + OS.XtManageChild (handle); +} +void redraw () { + int display = OS.XtDisplay (handle); + if (display == 0) return; + int window = OS.XtWindow (handle); + if (window == 0) return; + OS.XClearArea (display, window, 0, 0, 0, 0, true); +} +void releaseChild () { + super.releaseChild (); + parent.destroyItem (this); +} +void releaseWidget () { + Display display = getDisplay (); + display.releaseToolTipHandle (handle); + super.releaseWidget (); + parent = null; + control = null; + toolTipText = null; + image = disabledImage = hotImage = null; +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the control is selected. + * + * @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);
-}
-void selectRadio () {
- int index = 0;
- ToolItem [] items = parent.getItems ();
- while (index < items.length && items [index] != this) index++;
- int i = index - 1;
- while (i >= 0 && items [i].setRadioSelection (false)) --i;
- int j = index + 1;
- while (j < items.length && items [j].setRadioSelection (false)) j++;
- setSelection (true);
-}
-void setBackgroundPixel(int pixel) {
- int [] argList = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- OS.XmChangeColor (handle, pixel);
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-void setBounds (int x, int y, int width, int height) {
- if (control != null) control.setBounds(x, y, width, height);
- /*
- * Feature in Motif. Motif will not allow a window
- * to have a zero width or zero height. The fix is
- * to ensure these values are never zero.
- */
- int newWidth = Math.max (width, 1), newHeight = Math.max (height, 1);
- OS.XtConfigureWidget (handle, x, y, newWidth, newHeight, 0);
-}
-/**
- * Sets the control that is used to fill the bounds of
- * the item when the 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 removeSelectionListener(SelectionListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook(SWT.Selection, listener); + eventTable.unhook(SWT.DefaultSelection,listener); +} +void selectRadio () { + int index = 0; + ToolItem [] items = parent.getItems (); + while (index < items.length && items [index] != this) index++; + int i = index - 1; + while (i >= 0 && items [i].setRadioSelection (false)) --i; + int j = index + 1; + while (j < items.length && items [j].setRadioSelection (false)) j++; + setSelection (true); +} +void setBackgroundPixel(int pixel) { + int [] argList = {OS.XmNforeground, 0, OS.XmNhighlightColor, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + OS.XmChangeColor (handle, pixel); + OS.XtSetValues (handle, argList, argList.length / 2); +} +void setBounds (int x, int y, int width, int height) { + if (control != null) control.setBounds(x, y, width, height); + /* + * Feature in Motif. Motif will not allow a window + * to have a zero width or zero height. The fix is + * to ensure these values are never zero. + */ + int newWidth = Math.max (width, 1), newHeight = Math.max (height, 1); + OS.XtConfigureWidget (handle, x, y, newWidth, newHeight, 0); +} +/** + * Sets the control that is used to fill the bounds of + * the item when the 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;
- this.control = control;
- if (control != null && !control.isDisposed ()) {
- control.setBounds (getBounds ());
- /*
- * It is possible that the control was created with a
- * z-order below that of the current tool item. In this
- * case, the control is not visible because it is
- * obscured by the tool item. The fix is to move the
- * control above this tool item in the z-order.
- * The code below is similar to the code found in
- * setZOrder.
- */
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- if (!OS.XtIsRealized (handle)) {
- Shell shell = parent.getShell ();
- shell.realizeWidget ();
- }
- int topHandle1 = control.topHandle ();
- int window1 = OS.XtWindow (topHandle1);
- if (window1 == 0) return;
- int topHandle2 = this.topHandle ();
- int window2 = OS.XtWindow (topHandle2);
- if (window2 == 0) return;
- XWindowChanges struct = new XWindowChanges ();
- struct.sibling = window2;
- struct.stack_mode = OS.Above;
- int screen = OS.XDefaultScreen (xDisplay);
- int flags = OS.CWStackMode | OS.CWSibling;
- OS.XReconfigureWMWindow (xDisplay, window1, screen, flags, struct);
- }
-}
-/**
- * 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 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; + this.control = control; + if (control != null && !control.isDisposed ()) { + control.setBounds (getBounds ()); + /* + * It is possible that the control was created with a + * z-order below that of the current tool item. In this + * case, the control is not visible because it is + * obscured by the tool item. The fix is to move the + * control above this tool item in the z-order. + * The code below is similar to the code found in + * setZOrder. + */ + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return; + if (!OS.XtIsRealized (handle)) { + Shell shell = parent.getShell (); + shell.realizeWidget (); + } + int topHandle1 = control.topHandle (); + int window1 = OS.XtWindow (topHandle1); + if (window1 == 0) return; + int topHandle2 = this.topHandle (); + int window2 = OS.XtWindow (topHandle2); + if (window2 == 0) return; + XWindowChanges struct = new XWindowChanges (); + struct.sibling = window2; + struct.stack_mode = OS.Above; + int screen = OS.XDefaultScreen (xDisplay); + int flags = OS.CWStackMode | OS.CWSibling; + OS.XReconfigureWMWindow (xDisplay, window1, screen, flags, struct); + } +} +/** + * Enables the receiver if the argument is <code>true</code>, + * and disables it otherwise. + * <p> + * A disabled control is typically + * not selectable from the user interface and draws with an + * inactive or "grayed" look. + * </p> + * + * @param enabled the new enabled state + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setEnabled (boolean enabled) {
- checkWidget();
- int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
- OS.XtSetValues (handle, argList, argList.length / 2);
-}
-void setForegroundPixel(int pixel) {
- int [] argList = {OS.XmNforeground, pixel};
- OS.XtSetValues (handle, argList, argList.length / 2);
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return;
- OS.XClearArea (xDisplay, xWindow, 0, 0, 0, 0, true);
-}
-/**
- * Sets the receiver's 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 setEnabled (boolean enabled) { + checkWidget(); + int [] argList = {OS.XmNsensitive, enabled ? 1 : 0}; + OS.XtSetValues (handle, argList, argList.length / 2); +} +void setForegroundPixel(int pixel) { + int [] argList = {OS.XmNforeground, pixel}; + OS.XtSetValues (handle, argList, argList.length / 2); + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return; + int xWindow = OS.XtWindow (handle); + if (xWindow == 0) return; + OS.XClearArea (xDisplay, xWindow, 0, 0, 0, 0, true); +} +/** + * Sets the receiver's 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) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- disabledImage = image;
- if (!getEnabled ()) redraw ();
-}
-/**
- * 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 setDisabledImage (Image image) { + checkWidget(); + if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); + if ((style & SWT.SEPARATOR) != 0) return; + disabledImage = image; + if (!getEnabled ()) redraw (); +} +/** + * Sets the receiver's hot image to the argument, which may be + * null indicating that no hot image should be displayed. + * <p> + * The hot image is displayed when the mouse enters the receiver. + * </p> + * + * @param image the hot image to display on the receiver (may be null) + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setHotImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- hotImage = image;
- if ((parent.style & SWT.FLAT) != 0) redraw ();
-}
-public void setImage (Image image) {
- checkWidget();
- if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- super.setImage (image);
- Point size = computeSize ();
- setSize (size.x, size.y, true);
- redraw ();
-}
-boolean setRadioSelection (boolean value) {
- if ((style & SWT.RADIO) == 0) return false;
- if (getSelection () != value) {
- setSelection (value);
- postEvent (SWT.Selection);
- }
- return true;
-}
+public void setHotImage (Image image) { + checkWidget(); + if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); + if ((style & SWT.SEPARATOR) != 0) return; + hotImage = image; + if ((parent.style & SWT.FLAT) != 0) redraw (); +} +public void setImage (Image image) { + checkWidget(); + if (image != null && image.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT); + if ((style & SWT.SEPARATOR) != 0) return; + super.setImage (image); + Point size = computeSize (); + setSize (size.x, size.y, true); + redraw (); +} +boolean setRadioSelection (boolean value) { + if ((style & SWT.RADIO) == 0) return false; + if (getSelection () != value) { + setSelection (value); + postEvent (SWT.Selection); + } + return true; +} /** * Sets the selection state of the receiver. * <p> @@ -737,387 +737,387 @@ boolean setRadioSelection (boolean value) { * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> * </ul> */ -public void setSelection (boolean selected) {
- checkWidget();
- if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return;
- if (selected == set) return;
- set = selected;
- setDrawPressed (set);
-}
-
-void setSize (int width, int height, boolean layout) {
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- if (argList [1] != width || argList [3] != height) {
- OS.XtResizeWidget (handle, width, height, 0);
- if (layout) parent.relayout ();
- }
-}
-public void setText (String string) {
- checkWidget();
- if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
- if ((style & SWT.SEPARATOR) != 0) return;
- super.setText (string);
- Point size = computeSize ();
- setSize (size.x, size.y, true);
- redraw ();
-}
-
-/**
- * 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 setSelection (boolean selected) { + checkWidget(); + if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return; + if (selected == set) return; + set = selected; + setDrawPressed (set); +} + +void setSize (int width, int height, boolean layout) { + int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + if (argList [1] != width || argList [3] != height) { + OS.XtResizeWidget (handle, width, height, 0); + if (layout) parent.relayout (); + } +} +public void setText (String string) { + checkWidget(); + if (string == null) error (SWT.ERROR_NULL_ARGUMENT); + if ((style & SWT.SEPARATOR) != 0) return; + super.setText (string); + Point size = computeSize (); + setSize (size.x, size.y, true); + redraw (); +} + +/** + * 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) {
- checkWidget();
- toolTipText = string;
-}
-/**
- * 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 setToolTipText (String string) { + checkWidget(); + toolTipText = string; +} +/** + * Sets the width of the receiver. + * + * @param width the new width + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setWidth (int width) {
- checkWidget();
- if ((style & SWT.SEPARATOR) == 0) return;
- if (width < 0) return;
- int [] argList = {OS.XmNheight, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- setSize (width, argList [1], true);
- if (control != null && !control.isDisposed ()) {
- control.setBounds (getBounds ());
- }
-}
-void setDrawPressed (boolean value) {
- int shadowType = value ? OS.XmSHADOW_IN : OS.XmSHADOW_OUT;
- int [] argList = {OS.XmNshadowType, shadowType};
- OS.XtSetValues(handle, argList, argList.length / 2);
-}
-boolean translateAccelerator (int key, int keysym, XKeyEvent xEvent) {
- return parent.translateAccelerator (key, keysym, xEvent);
-}
-boolean translateMnemonic (int key, XKeyEvent xEvent) {
- return parent.translateMnemonic (key, xEvent);
-}
-boolean translateTraversal (int key, XKeyEvent xEvent) {
- return parent.translateTraversal (key, xEvent);
-}
-void propagateWidget (boolean enabled) {
- propagateHandle (enabled, handle);
-}
-int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- Display display = getDisplay ();
-// Shell shell = parent.getShell ();
- display.hideToolTip ();
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- if (xEvent.button == 1) {
- if (!set && (style & SWT.RADIO) == 0) {
- setDrawPressed (!set);
- }
- }
-
- /*
- * Forward the mouse event to the parent.
- * This is necessary so that mouse listeners
- * in the parent will be called, despite the
- * fact that the event did not really occur
- * in X in the parent. This is done to be
- * compatible with Windows.
- */
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- xEvent.window = OS.XtWindow (parent.handle);
- xEvent.x += argList [1]; xEvent.y += argList [3];
- OS.memmove (call_data, xEvent, XButtonEvent.sizeof);
- parent.XButtonPress (w, client_data, call_data, continue_to_dispatch);
-
- /*
- * It is possible that the shell may be
- * disposed at this point. If this happens
- * don't send the activate and deactivate
- * events.
- */
-// if (!shell.isDisposed()) {
-// shell.setActiveControl (parent);
-// }
- return 0;
-}
-int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- Display display = getDisplay ();
- display.hideToolTip();
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- if (xEvent.button == 1) {
- int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- int width = argList [1], height = argList [3];
- if (0 <= xEvent.x && xEvent.x < width && 0 <= xEvent.y && xEvent.y < height) {
- click (xEvent.x > width - 12, xEvent);
- }
- setDrawPressed(set);
- }
-
- /*
- * Forward the mouse event to the parent.
- * This is necessary so that mouse listeners
- * in the parent will be called, despite the
- * fact that the event did not really occur
- * in X in the parent. This is done to be
- * compatible with Windows.
- */
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- xEvent.window = OS.XtWindow (parent.handle);
- xEvent.x += argList [1]; xEvent.y += argList [3];
- OS.memmove (call_data, xEvent, XButtonEvent.sizeof);
- parent.XButtonRelease (w, client_data, call_data, continue_to_dispatch);
-
- return 0;
-}
-int XEnterWindow (int w, int client_data, int call_data, int continue_to_dispatch) {
- XCrossingEvent xEvent = new XCrossingEvent ();
- OS.memmove (xEvent, call_data, XCrossingEvent.sizeof);
- if ((xEvent.state & OS.Button1Mask) != 0) {
- setDrawPressed (!set);
- } else {
- if ((parent.style & SWT.FLAT) != 0) redraw ();
- }
- return 0;
-}
-int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatch) {
- /*
- * Forward the focus event to the parent.
- * This is necessary so that focus listeners
- * in the parent will be called, despite the
- * fact that the event did not really occur
- * in X in the parent. This is done to be
- * compatible with Windows.
- */
- XFocusChangeEvent xEvent = new XFocusChangeEvent ();
- OS.memmove (xEvent, call_data, XFocusChangeEvent.sizeof);
- xEvent.window = OS.XtWindow (parent.handle);
-// TEMPORARY CODE - need to fix the window field in xEvent
-// OS.memmove (callData, xEvent, XFocusChangeEvent.sizeof);
-
- /*
- * This code is intentionally commented.
- */
-// parent.processSetFocus (callData);
- return 0;
-}
-int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- XKeyEvent xEvent = new XKeyEvent ();
- OS.memmove (xEvent, call_data, XKeyEvent.sizeof);
- int [] keysym = new int [1];
- OS.XLookupString (xEvent, null, 0, keysym, null);
- keysym [0] &= 0xFFFF;
- switch (keysym [0]) {
- case OS.XK_space:
- click (false, xEvent);
- break;
- case OS.XK_KP_Enter:
- case OS.XK_Return:
- click (true, xEvent);
- break;
- }
- /*
- * Forward the key event to the parent.
- * This is necessary so that key listeners
- * in the parent will be called, despite the
- * fact that the event did not really occur
- * in X in the parent. This is done to be
- * compatible with Windows.
- */
- xEvent.window = OS.XtWindow (parent.handle);
-// OS.memmove (callData, xEvent, XKeyEvent.sizeof);
- parent.XKeyPress (w, client_data, call_data, continue_to_dispatch);
- return 0;
-}
-int XKeyRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- XKeyEvent xEvent = new XKeyEvent ();
- OS.memmove (xEvent, call_data, XKeyEvent.sizeof);
-
- /*
- * Forward the key event to the parent.
- * This is necessary so that key listeners
- * in the parent will be called, despite the
- * fact that the event did not really occur
- * in X in the parent. This is done to be
- * compatible with Windows.
- */
- xEvent.window = OS.XtWindow (parent.handle);
-// OS.memmove (callData, xEvent, XKeyEvent.sizeof);
- parent.XKeyRelease (w, client_data, call_data, continue_to_dispatch);
- return 0;
-}
-int XLeaveWindow (int w, int client_data, int call_data, int continue_to_dispatch) {
- Display display = getDisplay ();
- display.removeMouseHoverTimeOut ();
- display.hideToolTip ();
- XCrossingEvent xEvent = new XCrossingEvent ();
- OS.memmove (xEvent, call_data, XCrossingEvent.sizeof);
- if ((xEvent.state & OS.Button1Mask) != 0) {
- setDrawPressed (set);
- } else {
- if ((parent.style & SWT.FLAT) != 0) redraw ();
- }
- return 0;
-}
-int XmNexposureCallback (int w, int client_data, int call_data) {
- if ((style & SWT.SEPARATOR) != 0) return 0;
- int xDisplay = OS.XtDisplay (handle);
- if (xDisplay == 0) return 0;
- int xWindow = OS.XtWindow (handle);
- if (xWindow == 0) return 0;
- int [] argList = {
- OS.XmNcolormap, 0,
- OS.XmNwidth, 0,
- OS.XmNheight, 0,
- };
- OS.XtGetValues (handle, argList, argList.length / 2);
- int width = argList [3], height = argList [5];
-
- Image currentImage = image;
- boolean enabled = getEnabled();
-
- if ((parent.style & SWT.FLAT) != 0) {
- Display display = getDisplay ();
- boolean hasCursor = hasCursor ();
-
- /* Set the shadow thickness */
- int thickness = 0;
- if (set || (hasCursor && enabled)) {
- thickness = Math.min (2, display.buttonShadowThickness);
- }
- argList = new int [] {OS.XmNshadowThickness, thickness};
- OS.XtSetValues (handle, argList, argList.length / 2);
-
- /* Determine if hot image should be used */
- if (enabled && hasCursor && hotImage != null) {
- currentImage = hotImage;
- }
- }
-
- ToolDrawable wrapper = new ToolDrawable ();
- wrapper.device = getDisplay ();
- wrapper.display = xDisplay;
- wrapper.drawable = xWindow;
- wrapper.font = parent.font;
- wrapper.colormap = argList [1];
- GC gc = new GC (wrapper);
-
- XmAnyCallbackStruct cb = new XmAnyCallbackStruct ();
- OS.memmove (cb, call_data, XmAnyCallbackStruct.sizeof);
- if (cb.event != 0) {
- XExposeEvent xEvent = new XExposeEvent ();
- OS.memmove (xEvent, cb.event, XExposeEvent.sizeof);
- Rectangle rect = new Rectangle (xEvent.x, xEvent.y, xEvent.width, xEvent.height);
- gc.setClipping (rect);
- }
-
- if (!enabled) {
- Display display = getDisplay ();
- currentImage = disabledImage;
- if (currentImage == null && image != null) {
- currentImage = new Image (display, image, SWT.IMAGE_DISABLE);
- }
- Color disabledColor = display.getSystemColor (SWT.COLOR_WIDGET_NORMAL_SHADOW);
- gc.setForeground (disabledColor);
- } else {
- gc.setForeground (parent.getForeground ());
- }
- gc.setBackground (parent.getBackground ());
-
- int textX = 0, textY = 0, textWidth = 0, textHeight = 0;
- if (text.length () != 0) {
- int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC;
- Point textExtent = gc.textExtent (text, flags);
- textWidth = textExtent.x;
- textHeight = textExtent.y;
- }
- int imageX = 0, imageY = 0, imageWidth = 0, imageHeight = 0;
- if (currentImage != null) {
- Rectangle imageBounds = currentImage.getBounds ();
- imageWidth = imageBounds.width;
- imageHeight = imageBounds.height;
- }
-
- int spacing = 0;
- if (textWidth != 0 && imageWidth != 0) spacing = 2;
- if ((parent.style & SWT.RIGHT) != 0) {
- imageX = (width - imageWidth - textWidth - spacing) / 2;
- imageY = (height - imageHeight) / 2;
- textX = spacing + imageX + imageWidth;
- textY = (height - textHeight) / 2;
- } else {
- imageX = (width - imageWidth) / 2;
- imageY = (height - imageHeight - textHeight - spacing) / 2;
- textX = (width - textWidth) / 2;
- textY = spacing + imageY + imageHeight;
- }
-
- if ((style & SWT.DROP_DOWN) != 0) {
- textX -= 6; imageX -=6;
- }
- if (textWidth > 0) {
- int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC;
- gc.drawText(text, textX, textY, flags);
- }
- if (imageWidth > 0) gc.drawImage(currentImage, imageX, imageY);
- if ((style & SWT.DROP_DOWN) != 0) {
- int startX = width - 12, startY = (height - 2) / 2;
- int [] arrow = {startX, startY, startX + 3, startY + 3, startX + 6, startY};
- gc.setBackground (parent.getForeground ());
- gc.fillPolygon (arrow);
- gc.drawPolygon (arrow);
- }
- gc.dispose ();
-
- if (!enabled && disabledImage == null) {
- if (currentImage != null) currentImage.dispose ();
- }
- return 0;
-}
-int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) {
- Display display = getDisplay ();
- display.addMouseHoverTimeOut (handle);
-
- /*
- * Forward the mouse event to the parent.
- * This is necessary so that mouse listeners
- * in the parent will be called, despite the
- * fact that the event did not really occur
- * in X in the parent. This is done to be
- * compatible with Windows.
- */
- XButtonEvent xEvent = new XButtonEvent ();
- OS.memmove (xEvent, call_data, XButtonEvent.sizeof);
- int [] argList = {OS.XmNx, 0, OS.XmNy, 0};
- OS.XtGetValues (handle, argList, argList.length / 2);
- xEvent.window = OS.XtWindow (parent.handle);
- xEvent.x += argList [1]; xEvent.y += argList [3];
- /*
- * This code is intentionally commented.
- * Currently, the implementation of the
- * mouse move code in the parent interferes
- * with tool tips for tool items.
- */
-// OS.memmove (callData, xEvent, XButtonEvent.sizeof);
-// parent.XPointerMotion (w, client_data, call_data, continue_to_dispatch);
- parent.sendMouseEvent (SWT.MouseMove, 0, xEvent);
-
- return 0;
-}
-}
+public void setWidth (int width) { + checkWidget(); + if ((style & SWT.SEPARATOR) == 0) return; + if (width < 0) return; + int [] argList = {OS.XmNheight, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + setSize (width, argList [1], true); + if (control != null && !control.isDisposed ()) { + control.setBounds (getBounds ()); + } +} +void setDrawPressed (boolean value) { + int shadowType = value ? OS.XmSHADOW_IN : OS.XmSHADOW_OUT; + int [] argList = {OS.XmNshadowType, shadowType}; + OS.XtSetValues(handle, argList, argList.length / 2); +} +boolean translateAccelerator (int key, int keysym, XKeyEvent xEvent) { + return parent.translateAccelerator (key, keysym, xEvent); +} +boolean translateMnemonic (int key, XKeyEvent xEvent) { + return parent.translateMnemonic (key, xEvent); +} +boolean translateTraversal (int key, XKeyEvent xEvent) { + return parent.translateTraversal (key, xEvent); +} +void propagateWidget (boolean enabled) { + propagateHandle (enabled, handle); +} +int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) { + Display display = getDisplay (); +// Shell shell = parent.getShell (); + display.hideToolTip (); + XButtonEvent xEvent = new XButtonEvent (); + OS.memmove (xEvent, call_data, XButtonEvent.sizeof); + if (xEvent.button == 1) { + if (!set && (style & SWT.RADIO) == 0) { + setDrawPressed (!set); + } + } + + /* + * Forward the mouse event to the parent. + * This is necessary so that mouse listeners + * in the parent will be called, despite the + * fact that the event did not really occur + * in X in the parent. This is done to be + * compatible with Windows. + */ + int [] argList = {OS.XmNx, 0, OS.XmNy, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + xEvent.window = OS.XtWindow (parent.handle); + xEvent.x += argList [1]; xEvent.y += argList [3]; + OS.memmove (call_data, xEvent, XButtonEvent.sizeof); + parent.XButtonPress (w, client_data, call_data, continue_to_dispatch); + + /* + * It is possible that the shell may be + * disposed at this point. If this happens + * don't send the activate and deactivate + * events. + */ +// if (!shell.isDisposed()) { +// shell.setActiveControl (parent); +// } + return 0; +} +int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) { + Display display = getDisplay (); + display.hideToolTip(); + XButtonEvent xEvent = new XButtonEvent (); + OS.memmove (xEvent, call_data, XButtonEvent.sizeof); + if (xEvent.button == 1) { + int [] argList = {OS.XmNwidth, 0, OS.XmNheight, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + int width = argList [1], height = argList [3]; + if (0 <= xEvent.x && xEvent.x < width && 0 <= xEvent.y && xEvent.y < height) { + click (xEvent.x > width - 12, xEvent); + } + setDrawPressed(set); + } + + /* + * Forward the mouse event to the parent. + * This is necessary so that mouse listeners + * in the parent will be called, despite the + * fact that the event did not really occur + * in X in the parent. This is done to be + * compatible with Windows. + */ + int [] argList = {OS.XmNx, 0, OS.XmNy, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + xEvent.window = OS.XtWindow (parent.handle); + xEvent.x += argList [1]; xEvent.y += argList [3]; + OS.memmove (call_data, xEvent, XButtonEvent.sizeof); + parent.XButtonRelease (w, client_data, call_data, continue_to_dispatch); + + return 0; +} +int XEnterWindow (int w, int client_data, int call_data, int continue_to_dispatch) { + XCrossingEvent xEvent = new XCrossingEvent (); + OS.memmove (xEvent, call_data, XCrossingEvent.sizeof); + if ((xEvent.state & OS.Button1Mask) != 0) { + setDrawPressed (!set); + } else { + if ((parent.style & SWT.FLAT) != 0) redraw (); + } + return 0; +} +int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatch) { + /* + * Forward the focus event to the parent. + * This is necessary so that focus listeners + * in the parent will be called, despite the + * fact that the event did not really occur + * in X in the parent. This is done to be + * compatible with Windows. + */ + XFocusChangeEvent xEvent = new XFocusChangeEvent (); + OS.memmove (xEvent, call_data, XFocusChangeEvent.sizeof); + xEvent.window = OS.XtWindow (parent.handle); +// TEMPORARY CODE - need to fix the window field in xEvent +// OS.memmove (callData, xEvent, XFocusChangeEvent.sizeof); + + /* + * This code is intentionally commented. + */ +// parent.processSetFocus (callData); + return 0; +} +int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) { + XKeyEvent xEvent = new XKeyEvent (); + OS.memmove (xEvent, call_data, XKeyEvent.sizeof); + int [] keysym = new int [1]; + OS.XLookupString (xEvent, null, 0, keysym, null); + keysym [0] &= 0xFFFF; + switch (keysym [0]) { + case OS.XK_space: + click (false, xEvent); + break; + case OS.XK_KP_Enter: + case OS.XK_Return: + click (true, xEvent); + break; + } + /* + * Forward the key event to the parent. + * This is necessary so that key listeners + * in the parent will be called, despite the + * fact that the event did not really occur + * in X in the parent. This is done to be + * compatible with Windows. + */ + xEvent.window = OS.XtWindow (parent.handle); +// OS.memmove (callData, xEvent, XKeyEvent.sizeof); + parent.XKeyPress (w, client_data, call_data, continue_to_dispatch); + return 0; +} +int XKeyRelease (int w, int client_data, int call_data, int continue_to_dispatch) { + XKeyEvent xEvent = new XKeyEvent (); + OS.memmove (xEvent, call_data, XKeyEvent.sizeof); + + /* + * Forward the key event to the parent. + * This is necessary so that key listeners + * in the parent will be called, despite the + * fact that the event did not really occur + * in X in the parent. This is done to be + * compatible with Windows. + */ + xEvent.window = OS.XtWindow (parent.handle); +// OS.memmove (callData, xEvent, XKeyEvent.sizeof); + parent.XKeyRelease (w, client_data, call_data, continue_to_dispatch); + return 0; +} +int XLeaveWindow (int w, int client_data, int call_data, int continue_to_dispatch) { + Display display = getDisplay (); + display.removeMouseHoverTimeOut (); + display.hideToolTip (); + XCrossingEvent xEvent = new XCrossingEvent (); + OS.memmove (xEvent, call_data, XCrossingEvent.sizeof); + if ((xEvent.state & OS.Button1Mask) != 0) { + setDrawPressed (set); + } else { + if ((parent.style & SWT.FLAT) != 0) redraw (); + } + return 0; +} +int XmNexposureCallback (int w, int client_data, int call_data) { + if ((style & SWT.SEPARATOR) != 0) return 0; + int xDisplay = OS.XtDisplay (handle); + if (xDisplay == 0) return 0; + int xWindow = OS.XtWindow (handle); + if (xWindow == 0) return 0; + int [] argList = { + OS.XmNcolormap, 0, + OS.XmNwidth, 0, + OS.XmNheight, 0, + }; + OS.XtGetValues (handle, argList, argList.length / 2); + int width = argList [3], height = argList [5]; + + Image currentImage = image; + boolean enabled = getEnabled(); + + if ((parent.style & SWT.FLAT) != 0) { + Display display = getDisplay (); + boolean hasCursor = hasCursor (); + + /* Set the shadow thickness */ + int thickness = 0; + if (set || (hasCursor && enabled)) { + thickness = Math.min (2, display.buttonShadowThickness); + } + argList = new int [] {OS.XmNshadowThickness, thickness}; + OS.XtSetValues (handle, argList, argList.length / 2); + + /* Determine if hot image should be used */ + if (enabled && hasCursor && hotImage != null) { + currentImage = hotImage; + } + } + + ToolDrawable wrapper = new ToolDrawable (); + wrapper.device = getDisplay (); + wrapper.display = xDisplay; + wrapper.drawable = xWindow; + wrapper.font = parent.font; + wrapper.colormap = argList [1]; + GC gc = new GC (wrapper); + + XmAnyCallbackStruct cb = new XmAnyCallbackStruct (); + OS.memmove (cb, call_data, XmAnyCallbackStruct.sizeof); + if (cb.event != 0) { + XExposeEvent xEvent = new XExposeEvent (); + OS.memmove (xEvent, cb.event, XExposeEvent.sizeof); + Rectangle rect = new Rectangle (xEvent.x, xEvent.y, xEvent.width, xEvent.height); + gc.setClipping (rect); + } + + if (!enabled) { + Display display = getDisplay (); + currentImage = disabledImage; + if (currentImage == null && image != null) { + currentImage = new Image (display, image, SWT.IMAGE_DISABLE); + } + Color disabledColor = display.getSystemColor (SWT.COLOR_WIDGET_NORMAL_SHADOW); + gc.setForeground (disabledColor); + } else { + gc.setForeground (parent.getForeground ()); + } + gc.setBackground (parent.getBackground ()); + + int textX = 0, textY = 0, textWidth = 0, textHeight = 0; + if (text.length () != 0) { + int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC; + Point textExtent = gc.textExtent (text, flags); + textWidth = textExtent.x; + textHeight = textExtent.y; + } + int imageX = 0, imageY = 0, imageWidth = 0, imageHeight = 0; + if (currentImage != null) { + Rectangle imageBounds = currentImage.getBounds (); + imageWidth = imageBounds.width; + imageHeight = imageBounds.height; + } + + int spacing = 0; + if (textWidth != 0 && imageWidth != 0) spacing = 2; + if ((parent.style & SWT.RIGHT) != 0) { + imageX = (width - imageWidth - textWidth - spacing) / 2; + imageY = (height - imageHeight) / 2; + textX = spacing + imageX + imageWidth; + textY = (height - textHeight) / 2; + } else { + imageX = (width - imageWidth) / 2; + imageY = (height - imageHeight - textHeight - spacing) / 2; + textX = (width - textWidth) / 2; + textY = spacing + imageY + imageHeight; + } + + if ((style & SWT.DROP_DOWN) != 0) { + textX -= 6; imageX -=6; + } + if (textWidth > 0) { + int flags = SWT.DRAW_DELIMITER | SWT.DRAW_TAB | SWT.DRAW_MNEMONIC; + gc.drawText(text, textX, textY, flags); + } + if (imageWidth > 0) gc.drawImage(currentImage, imageX, imageY); + if ((style & SWT.DROP_DOWN) != 0) { + int startX = width - 12, startY = (height - 2) / 2; + int [] arrow = {startX, startY, startX + 3, startY + 3, startX + 6, startY}; + gc.setBackground (parent.getForeground ()); + gc.fillPolygon (arrow); + gc.drawPolygon (arrow); + } + gc.dispose (); + + if (!enabled && disabledImage == null) { + if (currentImage != null) currentImage.dispose (); + } + return 0; +} +int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) { + Display display = getDisplay (); + display.addMouseHoverTimeOut (handle); + + /* + * Forward the mouse event to the parent. + * This is necessary so that mouse listeners + * in the parent will be called, despite the + * fact that the event did not really occur + * in X in the parent. This is done to be + * compatible with Windows. + */ + XButtonEvent xEvent = new XButtonEvent (); + OS.memmove (xEvent, call_data, XButtonEvent.sizeof); + int [] argList = {OS.XmNx, 0, OS.XmNy, 0}; + OS.XtGetValues (handle, argList, argList.length / 2); + xEvent.window = OS.XtWindow (parent.handle); + xEvent.x += argList [1]; xEvent.y += argList [3]; + /* + * This code is intentionally commented. + * Currently, the implementation of the + * mouse move code in the parent interferes + * with tool tips for tool items. + */ +// OS.memmove (callData, xEvent, XButtonEvent.sizeof); +// parent.XPointerMotion (w, client_data, call_data, continue_to_dispatch); + parent.sendMouseEvent (SWT.MouseMove, 0, xEvent); + + return 0; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java index 60161f6cdc..446340ebe4 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Tracker.java @@ -1,46 +1,46 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.graphics.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
-/**
- * Instances of this class implement rubber banding rectangles that are
- * drawn onto a parent <code>Composite</code> or <code>Display</code>.
- * These rectangles can be specified to respond to mouse and key events
- * by either moving or resizing themselves accordingly. Trackers are
- * typically used to represent window geometries in a lightweight manner.
- *
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>LEFT, RIGHT, UP, DOWN, RESIZE</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Move, Resize</dd>
- * </dl>
- * <p>
- * Note: Rectangle move behavior is assumed unless RESIZE is specified.
- * </p><p>
- * IMPORTANT: This class is <em>not</em> intended to be subclassed.
- * </p>
- */
-public class Tracker extends Widget {
- Composite parent;
- Display display;
- boolean tracking, stippled;
- Rectangle [] rectangles, proportions;
- int cursorOrientation = SWT.NONE;
- int cursor;
- final static int STEPSIZE_SMALL = 1;
- final static int STEPSIZE_LARGE = 9;
-
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.graphics.*; +import org.eclipse.swt.*; +import org.eclipse.swt.events.*; + +/** + * Instances of this class implement rubber banding rectangles that are + * drawn onto a parent <code>Composite</code> or <code>Display</code>. + * These rectangles can be specified to respond to mouse and key events + * by either moving or resizing themselves accordingly. Trackers are + * typically used to represent window geometries in a lightweight manner. + * + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>LEFT, RIGHT, UP, DOWN, RESIZE</dd> + * <dt><b>Events:</b></dt> + * <dd>Move, Resize</dd> + * </dl> + * <p> + * Note: Rectangle move behavior is assumed unless RESIZE is specified. + * </p><p> + * IMPORTANT: This class is <em>not</em> intended to be subclassed. + * </p> + */ +public class Tracker extends Widget { + Composite parent; + Display display; + boolean tracking, stippled; + Rectangle [] rectangles, proportions; + int cursorOrientation = SWT.NONE; + int cursor; + final static int STEPSIZE_SMALL = 1; + final static int STEPSIZE_LARGE = 9; + /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -73,12 +73,12 @@ public class Tracker extends Widget { * @see Widget#checkSubclass * @see Widget#getStyle */ -public Tracker (Composite parent, int style) {
- super (parent, checkStyle (style));
- this.parent = parent;
- display = parent.getDisplay ();
-}
-
+public Tracker (Composite parent, int style) { + super (parent, checkStyle (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 @@ -113,530 +113,530 @@ public Tracker (Composite parent, int style) { * @see SWT#UP * @see SWT#DOWN */ -public Tracker (Display display, int style) {
- if (display == null) display = Display.getCurrent ();
- if (display == null) display = Display.getDefault ();
- if (!display.isValidThread ()) {
- error (SWT.ERROR_THREAD_INVALID_ACCESS);
- }
- this.style = checkStyle (style);
- this.display = display;
-}
-
-/**
- * Adds the listener to the collection of listeners who will
- * be notified when the control is moved or resized, by sending
- * it one of the messages defined in the <code>ControlListener</code>
- * interface.
- *
- * @param listener the listener which should be notified
- *
- * @exception IllegalArgumentException <ul>
- * <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
- * </ul>
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- *
- * @see ControlListener
- * @see #removeControlListener
+public Tracker (Display display, int style) { + if (display == null) display = Display.getCurrent (); + if (display == null) display = Display.getDefault (); + if (!display.isValidThread ()) { + error (SWT.ERROR_THREAD_INVALID_ACCESS); + } + this.style = checkStyle (style); + this.display = display; +} + +/** + * Adds the listener to the collection of listeners who will + * be notified when the control is moved or resized, by sending + * it one of the messages defined in the <code>ControlListener</code> + * interface. + * + * @param listener the listener which should be notified + * + * @exception IllegalArgumentException <ul> + * <li>ERROR_NULL_ARGUMENT - if the listener is null</li> + * </ul> + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + * + * @see ControlListener + * @see #removeControlListener */ -public void addControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Move,typedListener);
-}
-
-Point adjustMoveCursor (int xDisplay, int xWindow) {
- final int unused[] = new int[1];
- int actualX[] = new int[1];
- int actualY[] = new int[1];
-
- Rectangle bounds = computeBounds ();
- int newX = bounds.x + bounds.width / 2;
- int newY = bounds.y;
-
- OS.XWarpPointer (xDisplay, OS.None, xWindow, 0, 0, 0, 0, newX, newY);
- /*
- * The call to XWarpPointer does not always place the pointer on the
- * exact location that is specified, so do a query (below) to get the
- * actual location of the pointer after it has been moved.
- */
- OS.XQueryPointer (xDisplay, xWindow, unused, unused, actualX, actualY, unused, unused, unused);
- return new Point (actualX[0], actualY[0]);
-}
-Point adjustResizeCursor (int xDisplay, int xWindow) {
- int newX, newY;
- Rectangle bounds = computeBounds ();
-
- if ((cursorOrientation & SWT.LEFT) != 0) {
- newX = bounds.x;
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- newX = bounds.x + bounds.width;
- } else {
- newX = bounds.x + bounds.width / 2;
- }
-
- if ((cursorOrientation & SWT.UP) != 0) {
- newY = bounds.y;
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- newY = bounds.y + bounds.height;
- } else {
- newY = bounds.y + bounds.height / 2;
- }
-
- final int unused[] = new int[1];
- int actualX[] = new int[1];
- int actualY[] = new int[1];
- OS.XWarpPointer (xDisplay, 0, xWindow, 0, 0, 0, 0, newX, newY);
- /*
- * The call to XWarpPointer does not always place the pointer on the
- * exact location that is specified, so do a query (below) to get the
- * actual location of the pointer after it has been moved.
- */
- OS.XQueryPointer (xDisplay, xWindow, unused, unused, actualX, actualY, unused, unused, unused);
- return new Point (actualX[0], actualY[0]);
-}
-static int checkStyle (int style) {
- if ((style & (SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN)) == 0) {
- style |= SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN;
- }
- return style;
-}
-/**
- * Stops displaying the tracker rectangles. Note that this is not considered
- * to be a cancelation by the user.
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void close () {
- checkWidget ();
- tracking = false;
-}
-Rectangle computeBounds () {
- int xMin = rectangles [0].x;
- int yMin = rectangles [0].y;
- int xMax = rectangles [0].x + rectangles [0].width;
- int yMax = rectangles [0].y + rectangles [0].height;
-
- for (int i = 1; i < rectangles.length; i++) {
- if (rectangles [i].x < xMin) xMin = rectangles [i].x;
- if (rectangles [i].y < yMin) yMin = rectangles [i].y;
- int rectRight = rectangles [i].x + rectangles [i].width;
- if (rectRight > xMax) xMax = rectRight;
- int rectBottom = rectangles [i].y + rectangles [i].height;
- if (rectBottom > yMax) yMax = rectBottom;
- }
-
- return new Rectangle (xMin, yMin, xMax - xMin, yMax - yMin);
-}
-
-Rectangle [] computeProportions (Rectangle [] rects) {
- Rectangle [] result = new Rectangle [rects.length];
- Rectangle bounds = computeBounds ();
- for (int i = 0; i < rects.length; i++) {
- result[i] = new Rectangle (
- (rects[i].x - bounds.x) * 100 / bounds.width,
- (rects[i].y - bounds.y) * 100 / bounds.height,
- rects[i].width * 100 / bounds.width,
- rects[i].height * 100 / bounds.height);
- }
- return result;
-}
-
-void drawRectangles () {
- if (parent != null) {
- if (parent.isDisposed ()) return;
- parent.getShell ().update ();
- } else {
- display.update ();
- }
- int xDisplay = display.xDisplay;
- int color = OS.XWhitePixel (xDisplay, 0);
- int xWindow = OS.XDefaultRootWindow (xDisplay);
- if (parent != null) {
- xWindow = OS.XtWindow (parent.handle);
- if (xWindow == 0) return;
- int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0};
- OS.XtGetValues (parent.handle, argList, argList.length / 2);
- color = argList [1] ^ argList [3];
- }
- int gc = OS.XCreateGC (xDisplay, xWindow, 0, null);
- OS.XSetForeground (xDisplay, gc, color);
- OS.XSetSubwindowMode (xDisplay, gc, OS.IncludeInferiors);
- OS.XSetFunction (xDisplay, gc, OS.GXxor);
- int stipplePixmap = 0;
- if (stippled) {
- byte [] bits = {-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0};
- stipplePixmap = OS.XCreateBitmapFromData (xDisplay, xWindow, bits, 8, 8);
- OS.XSetStipple (xDisplay, gc, stipplePixmap);
- OS.XSetFillStyle (xDisplay, gc, OS.FillStippled);
- OS.XSetLineAttributes (xDisplay, gc, 3, OS.LineSolid, OS.CapButt, OS.JoinMiter);
- }
- for (int i=0; i<rectangles.length; i++) {
- Rectangle rect = rectangles [i];
- OS.XDrawRectangle (xDisplay, xWindow, gc, rect.x, rect.y, rect.width, rect.height);
- }
- if (stippled) {
- OS.XFreePixmap (xDisplay, stipplePixmap);
- }
- OS.XFreeGC (xDisplay, gc);
-}
-public Display getDisplay () {
- return display;
-}
-/**
- * Returns the bounds that are being drawn, expressed relative to the parent
- * widget. If the parent is a <code>Display</code> then these are screen
- * coordinates.
- *
- * @return the bounds of the Rectangles being drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public void addControlListener (ControlListener listener) { + checkWidget (); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener (listener); + addListener (SWT.Move,typedListener); +} + +Point adjustMoveCursor (int xDisplay, int xWindow) { + final int unused[] = new int[1]; + int actualX[] = new int[1]; + int actualY[] = new int[1]; + + Rectangle bounds = computeBounds (); + int newX = bounds.x + bounds.width / 2; + int newY = bounds.y; + + OS.XWarpPointer (xDisplay, OS.None, xWindow, 0, 0, 0, 0, newX, newY); + /* + * The call to XWarpPointer does not always place the pointer on the + * exact location that is specified, so do a query (below) to get the + * actual location of the pointer after it has been moved. + */ + OS.XQueryPointer (xDisplay, xWindow, unused, unused, actualX, actualY, unused, unused, unused); + return new Point (actualX[0], actualY[0]); +} +Point adjustResizeCursor (int xDisplay, int xWindow) { + int newX, newY; + Rectangle bounds = computeBounds (); + + if ((cursorOrientation & SWT.LEFT) != 0) { + newX = bounds.x; + } else if ((cursorOrientation & SWT.RIGHT) != 0) { + newX = bounds.x + bounds.width; + } else { + newX = bounds.x + bounds.width / 2; + } + + if ((cursorOrientation & SWT.UP) != 0) { + newY = bounds.y; + } else if ((cursorOrientation & SWT.DOWN) != 0) { + newY = bounds.y + bounds.height; + } else { + newY = bounds.y + bounds.height / 2; + } + + final int unused[] = new int[1]; + int actualX[] = new int[1]; + int actualY[] = new int[1]; + OS.XWarpPointer (xDisplay, 0, xWindow, 0, 0, 0, 0, newX, newY); + /* + * The call to XWarpPointer does not always place the pointer on the + * exact location that is specified, so do a query (below) to get the + * actual location of the pointer after it has been moved. + */ + OS.XQueryPointer (xDisplay, xWindow, unused, unused, actualX, actualY, unused, unused, unused); + return new Point (actualX[0], actualY[0]); +} +static int checkStyle (int style) { + if ((style & (SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN)) == 0) { + style |= SWT.LEFT | SWT.RIGHT | SWT.UP | SWT.DOWN; + } + return style; +} +/** + * Stops displaying the tracker rectangles. Note that this is not considered + * to be a cancelation by the user. + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public 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 void close () { + checkWidget (); + tracking = false; +} +Rectangle computeBounds () { + int xMin = rectangles [0].x; + int yMin = rectangles [0].y; + int xMax = rectangles [0].x + rectangles [0].width; + int yMax = rectangles [0].y + rectangles [0].height; + + for (int i = 1; i < rectangles.length; i++) { + if (rectangles [i].x < xMin) xMin = rectangles [i].x; + if (rectangles [i].y < yMin) yMin = rectangles [i].y; + int rectRight = rectangles [i].x + rectangles [i].width; + if (rectRight > xMax) xMax = rectRight; + int rectBottom = rectangles [i].y + rectangles [i].height; + if (rectBottom > yMax) yMax = rectBottom; + } + + return new Rectangle (xMin, yMin, xMax - xMin, yMax - yMin); +} + +Rectangle [] computeProportions (Rectangle [] rects) { + Rectangle [] result = new Rectangle [rects.length]; + Rectangle bounds = computeBounds (); + for (int i = 0; i < rects.length; i++) { + result[i] = new Rectangle ( + (rects[i].x - bounds.x) * 100 / bounds.width, + (rects[i].y - bounds.y) * 100 / bounds.height, + rects[i].width * 100 / bounds.width, + rects[i].height * 100 / bounds.height); + } + return result; +} + +void drawRectangles () { + if (parent != null) { + if (parent.isDisposed ()) return; + parent.getShell ().update (); + } else { + display.update (); + } + int xDisplay = display.xDisplay; + int color = OS.XWhitePixel (xDisplay, 0); + int xWindow = OS.XDefaultRootWindow (xDisplay); + if (parent != null) { + xWindow = OS.XtWindow (parent.handle); + if (xWindow == 0) return; + int [] argList = {OS.XmNforeground, 0, OS.XmNbackground, 0}; + OS.XtGetValues (parent.handle, argList, argList.length / 2); + color = argList [1] ^ argList [3]; + } + int gc = OS.XCreateGC (xDisplay, xWindow, 0, null); + OS.XSetForeground (xDisplay, gc, color); + OS.XSetSubwindowMode (xDisplay, gc, OS.IncludeInferiors); + OS.XSetFunction (xDisplay, gc, OS.GXxor); + int stipplePixmap = 0; + if (stippled) { + byte [] bits = {-86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0, -86, 0, 85, 0}; + stipplePixmap = OS.XCreateBitmapFromData (xDisplay, xWindow, bits, 8, 8); + OS.XSetStipple (xDisplay, gc, stipplePixmap); + OS.XSetFillStyle (xDisplay, gc, OS.FillStippled); + OS.XSetLineAttributes (xDisplay, gc, 3, OS.LineSolid, OS.CapButt, OS.JoinMiter); + } + for (int i=0; i<rectangles.length; i++) { + Rectangle rect = rectangles [i]; + OS.XDrawRectangle (xDisplay, xWindow, gc, rect.x, rect.y, rect.width, rect.height); + } + if (stippled) { + OS.XFreePixmap (xDisplay, stipplePixmap); + } + OS.XFreeGC (xDisplay, gc); +} +public Display getDisplay () { + return display; +} +/** + * Returns the bounds that are being drawn, expressed relative to the parent + * widget. If the parent is a <code>Display</code> then these are screen + * coordinates. + * + * @return the bounds of the Rectangles being drawn + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public boolean getStippled () {
- checkWidget ();
- return stippled;
-}
-
-void moveRectangles (int xChange, int yChange) {
- if (xChange < 0 && ((style & SWT.LEFT) == 0)) return;
- if (xChange > 0 && ((style & SWT.RIGHT) == 0)) return;
- if (yChange < 0 && ((style & SWT.UP) == 0)) return;
- if (yChange > 0 && ((style & SWT.DOWN) == 0)) return;
- for (int i = 0; i < rectangles.length; i++) {
- rectangles [i].x += xChange;
- rectangles [i].y += yChange;
- }
-}
-
-/**
- * Displays the Tracker rectangles for manipulation by the user. Returns when
- * the user has either finished manipulating the rectangles or has cancelled the
- * Tracker.
- *
- * @return <code>true</code> if the user did not cancel the Tracker, <code>false</code> otherwise
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public boolean open () {
- checkWidget ();
- if (rectangles == null) return false;
- int xDisplay = display.xDisplay;
- int xWindow = OS.XDefaultRootWindow (xDisplay);
- if (parent != null) {
- xWindow = OS.XtWindow (parent.handle);
- if (xWindow == 0) return false;
- }
- boolean cancelled = false;
- tracking = true;
- drawRectangles ();
- int [] oldX = new int [1], oldY = new int [1];
- int [] unused = new int [1], mask = new int [1];
- OS.XQueryPointer (xDisplay, xWindow, unused, unused, oldX, oldY, unused, unused, mask);
- Point cursorPos;
- int mouseMasks = OS.Button1Mask | OS.Button2Mask | OS.Button3Mask;
- boolean mouseDown = (mask [0] & mouseMasks) != 0;
- if (!mouseDown) {
- if ((style & SWT.RESIZE) != 0) {
- cursorPos = adjustResizeCursor (xDisplay, xWindow);
- } else {
- cursorPos = adjustMoveCursor (xDisplay, xWindow);
- }
- oldX [0] = cursorPos.x; oldY [0] = cursorPos.y;
- }
-
- XAnyEvent xEvent = new XAnyEvent ();
- int [] newX = new int [1], newY = new int [1];
- int xtContext = OS.XtDisplayToApplicationContext (xDisplay);
-
- int ptrGrabResult = OS.XGrabPointer (
- xDisplay,
- xWindow,
- 0,
- OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask,
- OS.GrabModeAsync,
- OS.GrabModeAsync,
- OS.None,
- OS.None,
- OS.CurrentTime);
- int kbdGrabResult = OS.XGrabKeyboard (
- xDisplay,
- xWindow,
- 0,
- OS.GrabModeAsync,
- OS.GrabModeAsync,
- OS.CurrentTime);
-
- /*
- * Tracker behaves like a Dialog with its own OS event loop.
- */
- while (tracking) {
- if (parent != null && parent.isDisposed ()) break;
- OS.XtAppNextEvent (xtContext, xEvent);
- switch (xEvent.type) {
- case OS.MotionNotify:
- if (cursor != 0) {
- OS.XChangeActivePointerGrab (
- xDisplay,
- OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask,
- cursor,
- OS.CurrentTime);
- }
- // fall through
- case OS.ButtonRelease:
- OS.XQueryPointer (xDisplay, xWindow, unused, unused, newX, newY, unused, unused, unused);
- if (oldX [0] != newX [0] || oldY [0] != newY [0]) {
- drawRectangles ();
- Event event = new Event ();
- event.x = newX [0];
- event.y = newY [0];
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (newX [0] - oldX [0], newY [0] - oldY [0]);
- sendEvent (SWT.Resize, event);
- cursorPos = adjustResizeCursor (xDisplay, xWindow);
- newX [0] = cursorPos.x; newY [0] = cursorPos.y;
- } else {
- moveRectangles (newX [0] - oldX [0], newY [0] - oldY [0]);
- sendEvent (SWT.Move, event);
- }
- /*
- * It is possible (but unlikely) that application code
- * could have disposed the widget in the move event.
- * If this happens then return false to indicate that
- * the move failed.
- */
- if (isDisposed ()) {
- if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime);
- if (kbdGrabResult == OS.GrabSuccess) OS.XUngrabKeyboard (xDisplay, OS.CurrentTime);
- return false;
- }
- drawRectangles ();
- oldX [0] = newX [0]; oldY [0] = newY [0];
- }
- tracking = xEvent.type != OS.ButtonRelease;
- break;
- case OS.KeyPress:
- 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;
- int xChange = 0, yChange = 0;
- int stepSize = ((keyEvent.state & OS.ControlMask) != 0) ? STEPSIZE_SMALL : STEPSIZE_LARGE;
- switch (keysym [0]) {
- case OS.XK_KP_Enter:
- case OS.XK_Return:
- tracking = false;
- /*
- * Eat the subsequent KeyRelease event
- */
- OS.XtAppNextEvent (xtContext, xEvent);
- break;
- case OS.XK_Escape:
- case OS.XK_Cancel:
- tracking = false;
- cancelled = true;
- /*
- * Eat the subsequent KeyRelease event
- */
- OS.XtAppNextEvent (xtContext, xEvent);
- break;
- case OS.XK_Left:
- xChange = -stepSize;
- break;
- case OS.XK_Right:
- xChange = stepSize;
- break;
- case OS.XK_Up:
- yChange = -stepSize;
- break;
- case OS.XK_Down:
- yChange = stepSize;
- break;
- }
- if (xChange != 0 || yChange != 0) {
- drawRectangles ();
- Event event = new Event ();
- event.x = oldX[0] + xChange;
- event.y = oldY[0] + yChange;
- if ((style & SWT.RESIZE) != 0) {
- resizeRectangles (xChange, yChange);
- sendEvent (SWT.Resize, event);
- cursorPos = adjustResizeCursor (xDisplay, xWindow);
- } else {
- moveRectangles (xChange, yChange);
- sendEvent (SWT.Move, event);
- cursorPos = adjustMoveCursor (xDisplay, xWindow);
- }
- /*
- * It is possible (but unlikely) that application code
- * could have disposed the widget in the move event.
- * If this happens then return false to indicate that
- * the move failed.
- */
- if (isDisposed ()) {
- if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime);
- if (kbdGrabResult == OS.GrabSuccess) OS.XUngrabKeyboard (xDisplay, OS.CurrentTime);
- return false;
- }
- drawRectangles ();
- oldX[0] = cursorPos.x; oldY[0] = cursorPos.y;
- }
- }
- break;
- case OS.EnterNotify:
- case OS.LeaveNotify:
- /*
- * Do not dispatch these
- */
- break;
- default:
- OS.XtDispatchEvent (xEvent);
- }
- }
- drawRectangles ();
- if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime);
- if (kbdGrabResult == OS.GrabSuccess) OS.XUngrabKeyboard (xDisplay, OS.CurrentTime);
- return !cancelled;
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notified when the control is moved or resized.
- *
- * @param listener the listener which should 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 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 void removeControlListener (ControlListener listener) {
- checkWidget ();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Move, listener);
-}
-void resizeRectangles (int xChange, int yChange) {
- /*
- * If the cursor orientation has not been set in the orientation of
- * this change then try to set it here.
- */
- if (xChange < 0 && ((style & SWT.LEFT) != 0) && ((cursorOrientation & SWT.RIGHT) == 0)) {
- cursorOrientation |= SWT.LEFT;
- } else if (xChange > 0 && ((style & SWT.RIGHT) != 0) && ((cursorOrientation & SWT.LEFT) == 0)) {
- cursorOrientation |= SWT.RIGHT;
- } else if (yChange < 0 && ((style & SWT.UP) != 0) && ((cursorOrientation & SWT.DOWN) == 0)) {
- cursorOrientation |= SWT.UP;
- } else if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) {
- cursorOrientation |= SWT.DOWN;
- }
- Rectangle bounds = computeBounds ();
- if ((cursorOrientation & SWT.LEFT) != 0) {
- bounds.x += xChange;
- bounds.width -= xChange;
- } else if ((cursorOrientation & SWT.RIGHT) != 0) {
- bounds.width += xChange;
- }
- if ((cursorOrientation & SWT.UP) != 0) {
- bounds.y += yChange;
- bounds.height -= yChange;
- } else if ((cursorOrientation & SWT.DOWN) != 0) {
- bounds.height += yChange;
- }
- /*
- * The following are conditions under which the resize should not be applied
- */
- if (bounds.width < 0 || bounds.height < 0) return;
-
- Rectangle [] newRects = new Rectangle [rectangles.length];
- for (int i = 0; i < rectangles.length; i++) {
- Rectangle proportion = proportions[i];
- newRects[i] = new Rectangle (
- proportion.x * bounds.width / 100 + bounds.x,
- proportion.y * bounds.height / 100 + bounds.y,
- proportion.width * bounds.width / 100,
- proportion.height * bounds.height / 100);
- }
- rectangles = newRects;
-}
-
-/**
- * Sets the <code>Cursor</code> of the Tracker. If this cursor is <code>null</code>
- * then the cursor reverts to the default.
- *
- * @param newCursor the new <code>Cursor</code> to display
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
- */
-public void setCursor (Cursor value) {
- checkWidget ();
- cursor = 0;
- if (value != null) cursor = value.handle;
-}
-/**
- * Specifies the rectangles that should be drawn, expressed relative to the parent
- * widget. If the parent is a Display then these are screen coordinates.
- *
- * @param rectangles the bounds of the rectangles to be drawn
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public boolean getStippled () { + checkWidget (); + return stippled; +} + +void moveRectangles (int xChange, int yChange) { + if (xChange < 0 && ((style & SWT.LEFT) == 0)) return; + if (xChange > 0 && ((style & SWT.RIGHT) == 0)) return; + if (yChange < 0 && ((style & SWT.UP) == 0)) return; + if (yChange > 0 && ((style & SWT.DOWN) == 0)) return; + for (int i = 0; i < rectangles.length; i++) { + rectangles [i].x += xChange; + rectangles [i].y += yChange; + } +} + +/** + * Displays the Tracker rectangles for manipulation by the user. Returns when + * the user has either finished manipulating the rectangles or has cancelled the + * Tracker. + * + * @return <code>true</code> if the user did not cancel the Tracker, <code>false</code> otherwise + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setRectangles (Rectangle [] rectangles) {
- checkWidget ();
- this.rectangles = rectangles;
- proportions = computeProportions (rectangles);
-}
-/**
- * Changes the appearance of the line used to draw the rectangles.
- *
- * @param stippled <code>true</code> if rectangle should appear stippled
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public boolean open () { + checkWidget (); + if (rectangles == null) return false; + int xDisplay = display.xDisplay; + int xWindow = OS.XDefaultRootWindow (xDisplay); + if (parent != null) { + xWindow = OS.XtWindow (parent.handle); + if (xWindow == 0) return false; + } + boolean cancelled = false; + tracking = true; + drawRectangles (); + int [] oldX = new int [1], oldY = new int [1]; + int [] unused = new int [1], mask = new int [1]; + OS.XQueryPointer (xDisplay, xWindow, unused, unused, oldX, oldY, unused, unused, mask); + Point cursorPos; + int mouseMasks = OS.Button1Mask | OS.Button2Mask | OS.Button3Mask; + boolean mouseDown = (mask [0] & mouseMasks) != 0; + if (!mouseDown) { + if ((style & SWT.RESIZE) != 0) { + cursorPos = adjustResizeCursor (xDisplay, xWindow); + } else { + cursorPos = adjustMoveCursor (xDisplay, xWindow); + } + oldX [0] = cursorPos.x; oldY [0] = cursorPos.y; + } + + XAnyEvent xEvent = new XAnyEvent (); + int [] newX = new int [1], newY = new int [1]; + int xtContext = OS.XtDisplayToApplicationContext (xDisplay); + + int ptrGrabResult = OS.XGrabPointer ( + xDisplay, + xWindow, + 0, + OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask, + OS.GrabModeAsync, + OS.GrabModeAsync, + OS.None, + OS.None, + OS.CurrentTime); + int kbdGrabResult = OS.XGrabKeyboard ( + xDisplay, + xWindow, + 0, + OS.GrabModeAsync, + OS.GrabModeAsync, + OS.CurrentTime); + + /* + * Tracker behaves like a Dialog with its own OS event loop. + */ + while (tracking) { + if (parent != null && parent.isDisposed ()) break; + OS.XtAppNextEvent (xtContext, xEvent); + switch (xEvent.type) { + case OS.MotionNotify: + if (cursor != 0) { + OS.XChangeActivePointerGrab ( + xDisplay, + OS.ButtonPressMask | OS.ButtonReleaseMask | OS.PointerMotionMask, + cursor, + OS.CurrentTime); + } + // fall through + case OS.ButtonRelease: + OS.XQueryPointer (xDisplay, xWindow, unused, unused, newX, newY, unused, unused, unused); + if (oldX [0] != newX [0] || oldY [0] != newY [0]) { + drawRectangles (); + Event event = new Event (); + event.x = newX [0]; + event.y = newY [0]; + if ((style & SWT.RESIZE) != 0) { + resizeRectangles (newX [0] - oldX [0], newY [0] - oldY [0]); + sendEvent (SWT.Resize, event); + cursorPos = adjustResizeCursor (xDisplay, xWindow); + newX [0] = cursorPos.x; newY [0] = cursorPos.y; + } else { + moveRectangles (newX [0] - oldX [0], newY [0] - oldY [0]); + sendEvent (SWT.Move, event); + } + /* + * It is possible (but unlikely) that application code + * could have disposed the widget in the move event. + * If this happens then return false to indicate that + * the move failed. + */ + if (isDisposed ()) { + if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime); + if (kbdGrabResult == OS.GrabSuccess) OS.XUngrabKeyboard (xDisplay, OS.CurrentTime); + return false; + } + drawRectangles (); + oldX [0] = newX [0]; oldY [0] = newY [0]; + } + tracking = xEvent.type != OS.ButtonRelease; + break; + case OS.KeyPress: + 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; + int xChange = 0, yChange = 0; + int stepSize = ((keyEvent.state & OS.ControlMask) != 0) ? STEPSIZE_SMALL : STEPSIZE_LARGE; + switch (keysym [0]) { + case OS.XK_KP_Enter: + case OS.XK_Return: + tracking = false; + /* + * Eat the subsequent KeyRelease event + */ + OS.XtAppNextEvent (xtContext, xEvent); + break; + case OS.XK_Escape: + case OS.XK_Cancel: + tracking = false; + cancelled = true; + /* + * Eat the subsequent KeyRelease event + */ + OS.XtAppNextEvent (xtContext, xEvent); + break; + case OS.XK_Left: + xChange = -stepSize; + break; + case OS.XK_Right: + xChange = stepSize; + break; + case OS.XK_Up: + yChange = -stepSize; + break; + case OS.XK_Down: + yChange = stepSize; + break; + } + if (xChange != 0 || yChange != 0) { + drawRectangles (); + Event event = new Event (); + event.x = oldX[0] + xChange; + event.y = oldY[0] + yChange; + if ((style & SWT.RESIZE) != 0) { + resizeRectangles (xChange, yChange); + sendEvent (SWT.Resize, event); + cursorPos = adjustResizeCursor (xDisplay, xWindow); + } else { + moveRectangles (xChange, yChange); + sendEvent (SWT.Move, event); + cursorPos = adjustMoveCursor (xDisplay, xWindow); + } + /* + * It is possible (but unlikely) that application code + * could have disposed the widget in the move event. + * If this happens then return false to indicate that + * the move failed. + */ + if (isDisposed ()) { + if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime); + if (kbdGrabResult == OS.GrabSuccess) OS.XUngrabKeyboard (xDisplay, OS.CurrentTime); + return false; + } + drawRectangles (); + oldX[0] = cursorPos.x; oldY[0] = cursorPos.y; + } + } + break; + case OS.EnterNotify: + case OS.LeaveNotify: + /* + * Do not dispatch these + */ + break; + default: + OS.XtDispatchEvent (xEvent); + } + } + drawRectangles (); + if (ptrGrabResult == OS.GrabSuccess) OS.XUngrabPointer (xDisplay, OS.CurrentTime); + if (kbdGrabResult == OS.GrabSuccess) OS.XUngrabKeyboard (xDisplay, OS.CurrentTime); + return !cancelled; +} +/** + * Removes the listener from the collection of listeners who will + * be notified when the control is moved or resized. + * + * @param listener the listener which should 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); +} +void resizeRectangles (int xChange, int yChange) { + /* + * If the cursor orientation has not been set in the orientation of + * this change then try to set it here. + */ + if (xChange < 0 && ((style & SWT.LEFT) != 0) && ((cursorOrientation & SWT.RIGHT) == 0)) { + cursorOrientation |= SWT.LEFT; + } else if (xChange > 0 && ((style & SWT.RIGHT) != 0) && ((cursorOrientation & SWT.LEFT) == 0)) { + cursorOrientation |= SWT.RIGHT; + } else if (yChange < 0 && ((style & SWT.UP) != 0) && ((cursorOrientation & SWT.DOWN) == 0)) { + cursorOrientation |= SWT.UP; + } else if (yChange > 0 && ((style & SWT.DOWN) != 0) && ((cursorOrientation & SWT.UP) == 0)) { + cursorOrientation |= SWT.DOWN; + } + Rectangle bounds = computeBounds (); + if ((cursorOrientation & SWT.LEFT) != 0) { + bounds.x += xChange; + bounds.width -= xChange; + } else if ((cursorOrientation & SWT.RIGHT) != 0) { + bounds.width += xChange; + } + if ((cursorOrientation & SWT.UP) != 0) { + bounds.y += yChange; + bounds.height -= yChange; + } else if ((cursorOrientation & SWT.DOWN) != 0) { + bounds.height += yChange; + } + /* + * The following are conditions under which the resize should not be applied + */ + if (bounds.width < 0 || bounds.height < 0) return; + + Rectangle [] newRects = new Rectangle [rectangles.length]; + for (int i = 0; i < rectangles.length; i++) { + Rectangle proportion = proportions[i]; + newRects[i] = new Rectangle ( + proportion.x * bounds.width / 100 + bounds.x, + proportion.y * bounds.height / 100 + bounds.y, + proportion.width * bounds.width / 100, + proportion.height * bounds.height / 100); + } + rectangles = newRects; +} + +/** + * Sets the <code>Cursor</code> of the Tracker. If this cursor is <code>null</code> + * then the cursor reverts to the default. + * + * @param newCursor the new <code>Cursor</code> to display + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> + */ +public void setCursor (Cursor value) { + checkWidget (); + cursor = 0; + if (value != null) cursor = value.handle; +} +/** + * Specifies the rectangles that should be drawn, expressed relative to the parent + * widget. If the parent is a Display then these are screen coordinates. + * + * @param rectangles the bounds of the rectangles to be drawn + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the 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; + proportions = computeProportions (rectangles); +} +/** + * Changes the appearance of the line used to draw the rectangles. + * + * @param stippled <code>true</code> if rectangle should appear stippled + * + * @exception SWTException <ul> + * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li> + * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> + * </ul> */ -public void setStippled (boolean stippled) {
- checkWidget ();
- this.stippled = stippled;
-}
-}
+public void setStippled (boolean stippled) { + checkWidget (); + this.stippled = stippled; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java index 5feb526856..b4a0452721 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/Widget.java @@ -1,109 +1,109 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.*;
-import org.eclipse.swt.internal.motif.*;
-import org.eclipse.swt.*;
-import org.eclipse.swt.events.*;
-
-/**
- * This class is the abstract superclass of all user interface objects.
- * Widgets are created, disposed and issue notification to listeners
- * when events occur which affect them.
- * <dl>
- * <dt><b>Styles:</b></dt>
- * <dd>(none)</dd>
- * <dt><b>Events:</b></dt>
- * <dd>Dispose</dd>
- * </dl>
- * <p>
- * IMPORTANT: This class is intended to be subclassed <em>only</em>
- * within the SWT implementation. However, it has not been marked
- * final to allow those outside of the SWT development team to implement
- * patched versions of the class in order to get around specific
- * limitations in advance of when those limitations can be addressed
- * by the team. Any class built using subclassing to access the internals
- * of this class will likely fail to compile or run between releases and
- * may be strongly platform specific. Subclassing should not be attempted
- * without an intimate and detailed understanding of the workings of the
- * hierarchy. No support is provided for user-written classes which are
- * implemented as subclasses of this class.
- * </p>
- *
- * @see #checkSubclass
+ * http://www.eclipse.org/legal/cpl-v10.html */ -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 = 0x00000001;
-// static final int ACTIVE = 0x00000002;
-// static final int AUTOGRAB = 0x00000004;
-// static final int MULTIEXPOSE = 0x00000008;
-// static final int RESIZEREDRAW = 0x00000010;
-// static final int WRAP = 0x00000020;
-// static final int DISABLED = 0x00000040;
-// static final int HIDDEN = 0x00000080;
-// static final int FOREGROUND = 0x00000100;
-// static final int BACKGROUND = 0x00000200;
- static final int DISPOSED = 0x00000400;
- static final int HANDLE = 0x00000800;
- static final int CANVAS = 0x00001000;
-
- static final int DEFAULT_WIDTH = 64;
- static final int DEFAULT_HEIGHT = 64;
-
- /* Global widget variables */
- static final char Mnemonic = '&';
-
- /* Events and Callback constants */
- static final int BUTTON_PRESS = 1;
- static final int BUTTON_RELEASE = 2;
- static final int EXPOSURE = 3;
- static final int ENTER_WINDOW = 4;
- static final int FOCUS_CHANGE = 5;
- static final int KEY_PRESS = 6;
- static final int KEY_RELEASE = 7;
- static final int LEAVE_WINDOW = 8;
- static final int ACTIVATE_CALLBACK = 9;
- static final int ARM_CALLBACK = 10;
- static final int BROWSE_SELECTION_CALLBACK = 11;
- static final int CASCADING_CALLBACK = 12;
- static final int DECREMENT_CALLBACK = 13;
- static final int DEFAULT_ACTION_CALLBACK = 14;
- static final int DRAG_CALLBACK = 15;
- static final int EXTENDED_SELECTION_CALLBACK = 16;
- static final int HELP_CALLBACK = 17;
- static final int INCREMENT_CALLBACK = 18;
- static final int MODIFY_VERIFY_CALLBACK = 19;
- static final int PAGE_DECREMENT_CALLBACK = 20;
- static final int PAGE_INCREMENT_CALLBACK = 21;
- static final int SELECTION_CALLBACK = 22;
- static final int TO_BOTTOM_CALLBACK = 23;
- static final int TO_TOP_CALLBACK = 24;
- static final int VALUE_CHANGED_CALLBACK = 25;
- static final int NON_MASKABLE = 26;
- static final int POINTER_MOTION = 27;
- static final int STRUCTURE_NOTIFY = 28;
- static final int MAP_CALLBACK = 29;
- static final int UNMAP_CALLBACK = 30;
- static final int DELETE_WINDOW = 31;
- static final int EXPOSURE_CALLBACK = 32;
-
-Widget () {
- /* Do nothing */
-}
+ +import org.eclipse.swt.internal.*; +import org.eclipse.swt.internal.motif.*; +import org.eclipse.swt.*; +import org.eclipse.swt.events.*; + +/** + * This class is the abstract superclass of all user interface objects. + * Widgets are created, disposed and issue notification to listeners + * when events occur which affect them. + * <dl> + * <dt><b>Styles:</b></dt> + * <dd>(none)</dd> + * <dt><b>Events:</b></dt> + * <dd>Dispose</dd> + * </dl> + * <p> + * IMPORTANT: This class is intended to be subclassed <em>only</em> + * within the SWT implementation. However, it has not been marked + * final to allow those outside of the SWT development team to implement + * patched versions of the class in order to get around specific + * limitations in advance of when those limitations can be addressed + * by the team. Any class built using subclassing to access the internals + * of this class will likely fail to compile or run between releases and + * may be strongly platform specific. Subclassing should not be attempted + * without an intimate and detailed understanding of the workings of the + * hierarchy. No support is provided for user-written classes which are + * implemented as subclasses of this class. + * </p> + * + * @see #checkSubclass + */ +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 = 0x00000001; +// static final int ACTIVE = 0x00000002; +// static final int AUTOGRAB = 0x00000004; +// static final int MULTIEXPOSE = 0x00000008; +// static final int RESIZEREDRAW = 0x00000010; +// static final int WRAP = 0x00000020; +// static final int DISABLED = 0x00000040; +// static final int HIDDEN = 0x00000080; +// static final int FOREGROUND = 0x00000100; +// static final int BACKGROUND = 0x00000200; + static final int DISPOSED = 0x00000400; + static final int HANDLE = 0x00000800; + static final int CANVAS = 0x00001000; + + static final int DEFAULT_WIDTH = 64; + static final int DEFAULT_HEIGHT = 64; + + /* Global widget variables */ + static final char Mnemonic = '&'; + + /* Events and Callback constants */ + static final int BUTTON_PRESS = 1; + static final int BUTTON_RELEASE = 2; + static final int EXPOSURE = 3; + static final int ENTER_WINDOW = 4; + static final int FOCUS_CHANGE = 5; + static final int KEY_PRESS = 6; + static final int KEY_RELEASE = 7; + static final int LEAVE_WINDOW = 8; + static final int ACTIVATE_CALLBACK = 9; + static final int ARM_CALLBACK = 10; + static final int BROWSE_SELECTION_CALLBACK = 11; + static final int CASCADING_CALLBACK = 12; + static final int DECREMENT_CALLBACK = 13; + static final int DEFAULT_ACTION_CALLBACK = 14; + static final int DRAG_CALLBACK = 15; + static final int EXTENDED_SELECTION_CALLBACK = 16; + static final int HELP_CALLBACK = 17; + static final int INCREMENT_CALLBACK = 18; + static final int MODIFY_VERIFY_CALLBACK = 19; + static final int PAGE_DECREMENT_CALLBACK = 20; + static final int PAGE_INCREMENT_CALLBACK = 21; + static final int SELECTION_CALLBACK = 22; + static final int TO_BOTTOM_CALLBACK = 23; + static final int TO_TOP_CALLBACK = 24; + static final int VALUE_CHANGED_CALLBACK = 25; + static final int NON_MASKABLE = 26; + static final int POINTER_MOTION = 27; + static final int STRUCTURE_NOTIFY = 28; + static final int MAP_CALLBACK = 29; + static final int UNMAP_CALLBACK = 30; + static final int DELETE_WINDOW = 31; + static final int EXPOSURE_CALLBACK = 32; + +Widget () { + /* Do nothing */ +} /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -132,538 +132,538 @@ Widget () { * @see #checkSubclass * @see #getStyle */ -public Widget (Widget parent, int style) {
- checkSubclass ();
- checkParent (parent);
- 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 Widget (Widget parent, int style) { + checkSubclass (); + checkParent (parent); + 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) {
- checkWidget();
- if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) eventTable = new EventTable ();
- eventTable.hook (eventType, handler);
-}
-/**
- * Adds the listener to the collection of listeners who will
- * be 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 addListener (int eventType, Listener handler) { + checkWidget(); + if (handler == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) eventTable = new EventTable (); + eventTable.hook (eventType, handler); +} +/** + * Adds the listener to the collection of listeners who will + * be 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) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- TypedListener typedListener = new TypedListener (listener);
- addListener (SWT.Dispose, typedListener);
-}
-static int checkBits (int style, int int0, int int1, int int2, int int3, int int4, int int5) {
- int mask = int0 | int1 | int2 | int3 | int4 | int5;
- if ((style & mask) == 0) style |= int0;
- if ((style & int0) != 0) style = (style & ~mask) | int0;
- if ((style & int1) != 0) style = (style & ~mask) | int1;
- if ((style & int2) != 0) style = (style & ~mask) | int2;
- if ((style & int3) != 0) style = (style & ~mask) | int3;
- if ((style & int4) != 0) style = (style & ~mask) | int4;
- if ((style & int5) != 0) style = (style & ~mask) | int5;
- return style;
-}
-void checkOrientation (Widget parent) {
- style &= ~SWT.MIRRORED;
- if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) {
- if (parent != null) {
- if ((parent.style & SWT.LEFT_TO_RIGHT) != 0) style |= SWT.LEFT_TO_RIGHT;
- if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) style |= SWT.RIGHT_TO_LEFT;
- }
- }
- style = checkBits (style, SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT, 0, 0, 0, 0);
-}
-void checkParent (Widget parent) {
- if (parent == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (!parent.isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS);
- if (parent.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT);
-}
-/**
- * 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 (isDisposed ()) error (SWT.ERROR_WIDGET_DISPOSED);
-}
-void createHandle (int index) {
- /* Do nothing */
-}
-void createWidget (int index) {
- createHandle (index);
- hookEvents ();
- register ();
- manageChildren ();
-}
-void deregister () {
- if (handle == 0) return;
- WidgetTable.remove (handle);
-}
-void destroyWidget () {
- int topHandle = topHandle ();
- releaseHandle ();
- if (topHandle != 0) {
- OS.XtDestroyWidget (topHandle);
- }
-}
-/**
- * Disposes of the operating system resources associated with
- * the receiver and all its 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 addDisposeListener (DisposeListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + TypedListener typedListener = new TypedListener (listener); + addListener (SWT.Dispose, typedListener); +} +static int checkBits (int style, int int0, int int1, int int2, int int3, int int4, int int5) { + int mask = int0 | int1 | int2 | int3 | int4 | int5; + if ((style & mask) == 0) style |= int0; + if ((style & int0) != 0) style = (style & ~mask) | int0; + if ((style & int1) != 0) style = (style & ~mask) | int1; + if ((style & int2) != 0) style = (style & ~mask) | int2; + if ((style & int3) != 0) style = (style & ~mask) | int3; + if ((style & int4) != 0) style = (style & ~mask) | int4; + if ((style & int5) != 0) style = (style & ~mask) | int5; + return style; +} +void checkOrientation (Widget parent) { + style &= ~SWT.MIRRORED; + if ((style & (SWT.LEFT_TO_RIGHT | SWT.RIGHT_TO_LEFT)) == 0) { + if (parent != null) { + if ((parent.style & SWT.LEFT_TO_RIGHT) != 0) style |= SWT.LEFT_TO_RIGHT; + if ((parent.style & SWT.RIGHT_TO_LEFT) != 0) style |= SWT.RIGHT_TO_LEFT; + } + } + style = checkBits (style, SWT.LEFT_TO_RIGHT, SWT.RIGHT_TO_LEFT, 0, 0, 0, 0); +} +void checkParent (Widget parent) { + if (parent == null) error (SWT.ERROR_NULL_ARGUMENT); + if (!parent.isValidThread ()) error (SWT.ERROR_THREAD_INVALID_ACCESS); + if (parent.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); +} +/** + * 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> */ -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 enableHandle (boolean enabled, int widgetHandle) {
- int [] argList = {OS.XmNsensitive, enabled ? 1 : 0};
- OS.XtSetValues (widgetHandle, argList, argList.length / 2);
-}
-void error (int code) {
- SWT.error(code);
-}
-boolean filters (int eventType) {
- Display display = getDisplay ();
- return display.filters (eventType);
-}
-/**
- * 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
+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 (isDisposed ()) error (SWT.ERROR_WIDGET_DISPOSED); +} +void createHandle (int index) { + /* Do nothing */ +} +void createWidget (int index) { + createHandle (index); + hookEvents (); + register (); + manageChildren (); +} +void deregister () { + if (handle == 0) return; + WidgetTable.remove (handle); +} +void destroyWidget () { + int topHandle = topHandle (); + releaseHandle (); + if (topHandle != 0) { + OS.XtDestroyWidget (topHandle); + } +} +/** + * Disposes of the operating system resources associated with + * the receiver and all its 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 Object getData () {
- checkWidget();
- 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 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 enableHandle (boolean enabled, int widgetHandle) { + int [] argList = {OS.XmNsensitive, enabled ? 1 : 0}; + OS.XtSetValues (widgetHandle, argList, argList.length / 2); +} +void error (int code) { + SWT.error(code); +} +boolean filters (int eventType) { + Display display = getDisplay (); + return display.filters (eventType); +} +/** + * 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 () { + checkWidget(); + 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) { + checkWidget(); + 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 Object getData (String key) {
- checkWidget();
- 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; + 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 abstract Display getDisplay ();
-String getName () {
- String string = getClass ().getName ();
- int index = string.lastIndexOf ('.');
- if (index == -1) return string;
- return string.substring (index + 1, string.length ());
-}
-String getNameText () {
- return "";
-}
-/**
- * Returns the receiver's style information.
- * <p>
- * Note that the value which is returned by this method <em>may
- * not match</em> the value which was provided to the constructor
- * when the receiver was created. This can occur when the underlying
- * operating system does not support a particular combination of
- * requested styles. For example, if the platform widget used to
- * implement a particular SWT widget always has scroll bars, the
- * result of calling this method would always have the
- * <code>SWT.H_SCROLL</code> and <code>SWT.V_SCROLL</code> bits set.
- * </p>
- *
- * @return the style bits
- *
- * @exception SWTException <ul>
- * <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
- * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
- * </ul>
+public int getStyle () { + checkWidget(); + return style; +} +void hookEvents () { + /* Do nothing */ +} +boolean hooks (int eventType) { + if (eventTable == null) return false; + return eventTable.hooks (eventType); +} +/** + * Returns <code>true</code> if the widget has been disposed, + * and <code>false</code> otherwise. + * <p> + * This method gets the dispose state for the widget. + * When a widget has been disposed, it is an error to + * invoke any other method using the widget. + * </p> + * + * @return <code>true</code> when the widget is disposed and <code>false</code> otherwise */ -public int getStyle () {
- checkWidget();
- return style;
-}
-void hookEvents () {
- /* Do nothing */
-}
-boolean hooks (int eventType) {
- if (eventTable == null) return false;
- return eventTable.hooks (eventType);
-}
-/**
- * Returns <code>true</code> if the widget has been disposed,
- * and <code>false</code> otherwise.
- * <p>
- * This method gets the dispose state for the widget.
- * When a widget has been disposed, it is an error to
- * invoke any other method using the widget.
- * </p>
- *
- * @return <code>true</code> when the widget is disposed and <code>false</code> otherwise
+public boolean isDisposed () { + if (handle != 0) return false; + if ((state & HANDLE) != 0) return true; + return (state & DISPOSED) != 0; +} +/** + * Return the listening state. + * <p> + * Returns true if there is a listener, listening for the eventType. + * Otherwise, returns false. + * + * @param eventType the type of event + * @return true if the event is hooked + * + * @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> + * <li>ERROR_NULL_ARGUMENT when the name is null</li> + * </ul> */ -public boolean isDisposed () {
- if (handle != 0) return false;
- if ((state & HANDLE) != 0) return true;
- return (state & DISPOSED) != 0;
-}
-/**
- * Return the listening state.
- * <p>
- * Returns true if there is a listener, listening for the eventType.
- * Otherwise, returns false.
- *
- * @param eventType the type of event
- * @return true if the event is hooked
- *
- * @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>
- * <li>ERROR_NULL_ARGUMENT when the name is null</li>
- * </ul>
+protected boolean isListening (int eventType) { + checkWidget(); + return hooks (eventType); +} +boolean isValidSubclass () { + return Display.isValidClass (getClass ()); +} +boolean isValidThread () { + return getDisplay ().isValidThread (); +} +void manageChildren () { + /* Do nothing */ +} +char mbcsToWcs (int ch) { + return mbcsToWcs (ch, null); +} +char mbcsToWcs (int ch, String codePage) { + int key = ch & 0xFFFF; + if (key <= 0x7F) return (char) 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 (codePage, 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> */ -protected boolean isListening (int eventType) {
- checkWidget();
- return hooks (eventType);
-}
-boolean isValidSubclass () {
- return Display.isValidClass (getClass ());
-}
-boolean isValidThread () {
- return getDisplay ().isValidThread ();
-}
-void manageChildren () {
- /* Do nothing */
-}
-char mbcsToWcs (int ch) {
- return mbcsToWcs (ch, null);
-}
-char mbcsToWcs (int ch, String codePage) {
- int key = ch & 0xFFFF;
- if (key <= 0x7F) return (char) 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 (codePage, 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); + sendEvent (eventType, event); +} +void postEvent (int eventType) { + sendEvent (eventType, null, false); +} +void postEvent (int eventType, Event event) { + sendEvent (eventType, event, false); +} +void propagateHandle (boolean enabled, int widgetHandle) { + int xDisplay = OS.XtDisplay (widgetHandle); + if (xDisplay == 0) return; + int xWindow = OS.XtWindow (widgetHandle); + if (xWindow == 0) return; + /* + * Get the event mask from the widget. The event mask + * returned by XtBuildEventMask () includes the masks + * associated with all callbacks and event handlers + * that have been hooked on the widget. + */ + int event_mask = OS.XtBuildEventMask (widgetHandle); + int do_not_propagate_mask = + OS.KeyPressMask | OS.KeyReleaseMask | OS.ButtonPressMask | + OS.ButtonReleaseMask | OS.PointerMotionMask; + if (!enabled) { + /* + * Attempting to propogate EnterWindowMask and LeaveWindowMask + * causes an X error so these must be specially cleared out from + * the event mask, not included in the propogate mask. + */ + event_mask &= ~(do_not_propagate_mask | OS.EnterWindowMask | OS.LeaveWindowMask); + do_not_propagate_mask = 0; + } + XSetWindowAttributes attributes = new XSetWindowAttributes (); + attributes.event_mask = event_mask; + attributes.do_not_propagate_mask = do_not_propagate_mask; + OS.XChangeWindowAttributes (xDisplay, xWindow, OS.CWDontPropagate | OS.CWEventMask, attributes); +} +void redrawHandle (int x, int y, int width, int height, int widgetHandle) { + int display = OS.XtDisplay (widgetHandle); + if (display == 0) return; + int window = OS.XtWindow (widgetHandle); + if (window == 0) return; + int [] argList = {OS.XmNborderWidth, 0, OS.XmNborderColor, 0}; + OS.XtGetValues (widgetHandle, argList, argList.length / 2); + if (argList [1] != 0) { + /* Force the border to repaint by setting the color */ + OS.XtSetValues (widgetHandle, argList, argList.length / 2); + } + OS.XClearArea (display, window, x, y, width, height, true); +} +void register () { + if (handle == 0) return; + WidgetTable.put (handle, this); +} +void releaseChild () { + /* Do nothing */ +} +void releaseHandle () { + handle = 0; + state |= DISPOSED; +} +void releaseResources () { + releaseWidget (); + releaseHandle (); +} +void releaseWidget () { + sendEvent (SWT.Dispose); + deregister (); + eventTable = null; + data = null; + keys = null; + values = 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 notifyListeners (int eventType, Event event) {
- checkWidget();
- if (event == null) error (SWT.ERROR_NULL_ARGUMENT);
- sendEvent (eventType, event);
-}
-void postEvent (int eventType) {
- sendEvent (eventType, null, false);
-}
-void postEvent (int eventType, Event event) {
- sendEvent (eventType, event, false);
-}
-void propagateHandle (boolean enabled, int widgetHandle) {
- int xDisplay = OS.XtDisplay (widgetHandle);
- if (xDisplay == 0) return;
- int xWindow = OS.XtWindow (widgetHandle);
- if (xWindow == 0) return;
- /*
- * Get the event mask from the widget. The event mask
- * returned by XtBuildEventMask () includes the masks
- * associated with all callbacks and event handlers
- * that have been hooked on the widget.
- */
- int event_mask = OS.XtBuildEventMask (widgetHandle);
- int do_not_propagate_mask =
- OS.KeyPressMask | OS.KeyReleaseMask | OS.ButtonPressMask |
- OS.ButtonReleaseMask | OS.PointerMotionMask;
- if (!enabled) {
- /*
- * Attempting to propogate EnterWindowMask and LeaveWindowMask
- * causes an X error so these must be specially cleared out from
- * the event mask, not included in the propogate mask.
- */
- event_mask &= ~(do_not_propagate_mask | OS.EnterWindowMask | OS.LeaveWindowMask);
- do_not_propagate_mask = 0;
- }
- XSetWindowAttributes attributes = new XSetWindowAttributes ();
- attributes.event_mask = event_mask;
- attributes.do_not_propagate_mask = do_not_propagate_mask;
- OS.XChangeWindowAttributes (xDisplay, xWindow, OS.CWDontPropagate | OS.CWEventMask, attributes);
-}
-void redrawHandle (int x, int y, int width, int height, int widgetHandle) {
- int display = OS.XtDisplay (widgetHandle);
- if (display == 0) return;
- int window = OS.XtWindow (widgetHandle);
- if (window == 0) return;
- int [] argList = {OS.XmNborderWidth, 0, OS.XmNborderColor, 0};
- OS.XtGetValues (widgetHandle, argList, argList.length / 2);
- if (argList [1] != 0) {
- /* Force the border to repaint by setting the color */
- OS.XtSetValues (widgetHandle, argList, argList.length / 2);
- }
- OS.XClearArea (display, window, x, y, width, height, true);
-}
-void register () {
- if (handle == 0) return;
- WidgetTable.put (handle, this);
-}
-void releaseChild () {
- /* Do nothing */
-}
-void releaseHandle () {
- handle = 0;
- state |= DISPOSED;
-}
-void releaseResources () {
- releaseWidget ();
- releaseHandle ();
-}
-void releaseWidget () {
- sendEvent (SWT.Dispose);
- deregister ();
- eventTable = null;
- data = null;
- keys = null;
- values = 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) { + checkWidget(); + if (handler == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook (eventType, handler); +} +/** + * Removes the listener from the collection of listeners who will + * be notifed when an event of the given type occurs. + * <p> + * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT + * public API. It is marked public only so that it can be shared + * within the packages provided by SWT. It should never be + * referenced from application code. + * </p> + * + * @param eventType the type of event to listen for + * @param listener the listener which should no longer be notified 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) {
- checkWidget();
- if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, handler);
-}
-/**
- * Removes the listener from the collection of listeners who will
- * be notifed when an event of the given type occurs.
- * <p>
- * <b>IMPORTANT:</b> This method is <em>not</em> part of the SWT
- * public API. It is marked public only so that it can be shared
- * within the packages provided by SWT. It should never be
- * referenced from application code.
- * </p>
- *
- * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified 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
- */
-protected void removeListener (int eventType, SWTEventListener handler) {
- checkWidget();
- if (handler == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (eventType, handler);
-}
+protected void removeListener (int eventType, SWTEventListener handler) { + checkWidget(); + if (handler == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook (eventType, handler); +} /** * Removes the listener from the collection of listeners who will * be notifed when the widget is disposed. @@ -681,443 +681,443 @@ protected void removeListener (int eventType, SWTEventListener handler) { * @see DisposeListener * @see #addDisposeListener */ -public void removeDisposeListener (DisposeListener listener) {
- checkWidget();
- if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
- if (eventTable == null) return;
- eventTable.unhook (SWT.Dispose, listener);
-}
-void setInputState (Event event, int state) {
- if ((state & OS.Mod1Mask) != 0) event.stateMask |= SWT.ALT;
- if ((state & OS.ShiftMask) != 0) event.stateMask |= SWT.SHIFT;
- if ((state & OS.ControlMask) != 0) event.stateMask |= SWT.CONTROL;
- if ((state & OS.Button1Mask) != 0) event.stateMask |= SWT.BUTTON1;
- if ((state & OS.Button2Mask) != 0) event.stateMask |= SWT.BUTTON2;
- if ((state & OS.Button3Mask) != 0) event.stateMask |= SWT.BUTTON3;
-}
-void setInputState (Event event, XInputEvent xEvent) {
- setInputState (event, xEvent.state);
-}
-void setKeyState (Event event, XKeyEvent xEvent) {
- if (xEvent.keycode != 0) {
- byte [] buffer = new byte [1];
- int [] keysym = new int [1];
- OS.XLookupString (xEvent, buffer, buffer.length, keysym, null);
-
- /*
- * Bug in MOTIF. On Solaris only, XK_F11 and XK_F12 are not
- * translated correctly by XLookupString(). They are mapped
- * to 0x1005FF10 and 0x1005FF11 respectively. The fix is to
- * look for these values explicitly and correct them.
- */
- if (OS.IsSunOS && keysym [0] != 0) {
- switch (keysym [0]) {
- case 0x1005FF10:
- keysym [0] = OS.XK_F11;
- buffer [0] = 0;
- break;
- case 0x1005FF11:
- keysym [0] = OS.XK_F12;
- buffer [0] = 0;
- break;
- }
- /*
- * Bug in MOTIF. On Solaris only, there is garbage in the
- * high 16-bits for Keysyms such as XK_Down. Since Keysyms
- * must be 16-bits to fit into a Character, mask away the
- * high 16-bits on all platforms.
- */
- keysym [0] &= 0xFFFF;
- }
-
- /*
- * Feature in MOTIF. For some reason, XLookupString() fails
- * to translate both the keysym and the character when the
- * control key is down. For example, Ctrl+2 has the correct
- * keysym value (50) but no character value, while Ctrl+/ has
- * the keysym value (2F) but an invalid character value
- * (1F). It seems that Motif is applying the algorithm to
- * convert a character to a control character for characters
- * that are not valid control characters. The fix is to test
- * for 7-bit ASCII keysym values that fall outside of the
- * the valid control character range and use the keysym value
- * as the character, not the incorrect value that XLookupString()
- * returns. Even though lower case values are not strictly
- * valid control characters, they are included in the range.
- *
- * Some other cases include Ctrl+3..Ctr+8, Ctrl+[.
- */
- if ((xEvent.state & OS.ControlMask) != 0) {
- int key = keysym [0];
- if (0 <= key && key <= 0x7F) {
- if ('a' <= key && key <= 'z') {
- key -= 'a' - 'A';
- }
- if (!(64 <= key && key <= 95)) {
- buffer [0] = (byte) key;
- }
- }
- }
-
- /*
- * Bug in Motif. On HP-UX only, Shift+F9, Shift+F10, Shift+F11
- * and Shift+F12 are not translated correctly by XLookupString.
- * The fix is to look for these values explicitly and correct them.
*/
- if (OS.IsHPUX && keysym [0] != 0) {
- switch (keysym [0]) {
- case 0xFF91:
- keysym [0] = OS.XK_F9;
- break;
- case 0xFF92:
- keysym [0] = OS.XK_F10;
- break;
- case 0xFF93:
- keysym [0] = OS.XK_F11;
- break;
- case 0xFF94:
- keysym [0] = OS.XK_F12;
- break;
- }
- }
-
- /*
- * Bug in Motif. There are some keycodes for which
- * XLookupString() does not translate the character.
- * Some of examples are Shift+Tab and Ctrl+Space.
- */
- switch (keysym [0]) {
- case OS.XK_ISO_Left_Tab: buffer [0] = '\t'; break;
- case OS.XK_space: buffer [0] = ' '; break;
- }
-
- /* Fill in the event keyCode or character */
- if (keysym [0] != 0) {
- event.keyCode = Display.translateKey (keysym [0]);
- }
- if (buffer [0] != 0) {
- event.character = mbcsToWcs (buffer [0] & 0xFF);
- }
- }
- setInputState (event, xEvent);
-}
-void sendEvent (Event event) {
- Display display = event.display;
- if (!display.filterEvent (event)) {
- if (eventTable != null) eventTable.sendEvent (event);
- }
-}
-void sendEvent (int eventType) {
- sendEvent (eventType, null, true);
-}
-void sendEvent (int eventType, Event event) {
- sendEvent (eventType, event, true);
-}
-void sendEvent (int eventType, Event event, boolean send) {
- Display display = getDisplay ();
- if (eventTable == null && !display.filters (eventType)) {
- return;
- }
- if (event == null) event = new Event ();
- event.type = eventType;
- event.display = display;
- event.widget = this;
- if (event.time == 0) {
- event.time = display.getLastEventTime ();
- }
- if (send) {
- sendEvent (event);
- } else {
- display.postEvent (event);
- }
-}
-/**
- * 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 removeDisposeListener (DisposeListener listener) { + checkWidget(); + if (listener == null) error (SWT.ERROR_NULL_ARGUMENT); + if (eventTable == null) return; + eventTable.unhook (SWT.Dispose, listener); +} +void setInputState (Event event, int state) { + if ((state & OS.Mod1Mask) != 0) event.stateMask |= SWT.ALT; + if ((state & OS.ShiftMask) != 0) event.stateMask |= SWT.SHIFT; + if ((state & OS.ControlMask) != 0) event.stateMask |= SWT.CONTROL; + if ((state & OS.Button1Mask) != 0) event.stateMask |= SWT.BUTTON1; + if ((state & OS.Button2Mask) != 0) event.stateMask |= SWT.BUTTON2; + if ((state & OS.Button3Mask) != 0) event.stateMask |= SWT.BUTTON3; +} +void setInputState (Event event, XInputEvent xEvent) { + setInputState (event, xEvent.state); +} +void setKeyState (Event event, XKeyEvent xEvent) { + if (xEvent.keycode != 0) { + byte [] buffer = new byte [1]; + int [] keysym = new int [1]; + OS.XLookupString (xEvent, buffer, buffer.length, keysym, null); + + /* + * Bug in MOTIF. On Solaris only, XK_F11 and XK_F12 are not + * translated correctly by XLookupString(). They are mapped + * to 0x1005FF10 and 0x1005FF11 respectively. The fix is to + * look for these values explicitly and correct them. + */ + if (OS.IsSunOS && keysym [0] != 0) { + switch (keysym [0]) { + case 0x1005FF10: + keysym [0] = OS.XK_F11; + buffer [0] = 0; + break; + case 0x1005FF11: + keysym [0] = OS.XK_F12; + buffer [0] = 0; + break; + } + /* + * Bug in MOTIF. On Solaris only, there is garbage in the + * high 16-bits for Keysyms such as XK_Down. Since Keysyms + * must be 16-bits to fit into a Character, mask away the + * high 16-bits on all platforms. + */ + keysym [0] &= 0xFFFF; + } + + /* + * Feature in MOTIF. For some reason, XLookupString() fails + * to translate both the keysym and the character when the + * control key is down. For example, Ctrl+2 has the correct + * keysym value (50) but no character value, while Ctrl+/ has + * the keysym value (2F) but an invalid character value + * (1F). It seems that Motif is applying the algorithm to + * convert a character to a control character for characters + * that are not valid control characters. The fix is to test + * for 7-bit ASCII keysym values that fall outside of the + * the valid control character range and use the keysym value + * as the character, not the incorrect value that XLookupString() + * returns. Even though lower case values are not strictly + * valid control characters, they are included in the range. + * + * Some other cases include Ctrl+3..Ctr+8, Ctrl+[. + */ + if ((xEvent.state & OS.ControlMask) != 0) { + int key = keysym [0]; + if (0 <= key && key <= 0x7F) { + if ('a' <= key && key <= 'z') { + key -= 'a' - 'A'; + } + if (!(64 <= key && key <= 95)) { + buffer [0] = (byte) key; + } + } + } + + /* + * Bug in Motif. On HP-UX only, Shift+F9, Shift+F10, Shift+F11 + * and Shift+F12 are not translated correctly by XLookupString. + * The fix is to look for these values explicitly and correct them.
*/ + if (OS.IsHPUX && keysym [0] != 0) { + switch (keysym [0]) { + case 0xFF91: + keysym [0] = OS.XK_F9; + break; + case 0xFF92: + keysym [0] = OS.XK_F10; + break; + case 0xFF93: + keysym [0] = OS.XK_F11; + break; + case 0xFF94: + keysym [0] = OS.XK_F12; + break; + } + } + + /* + * Bug in Motif. There are some keycodes for which + * XLookupString() does not translate the character. + * Some of examples are Shift+Tab and Ctrl+Space. + */ + switch (keysym [0]) { + case OS.XK_ISO_Left_Tab: buffer [0] = '\t'; break; + case OS.XK_space: buffer [0] = ' '; break; + } + + /* Fill in the event keyCode or character */ + if (keysym [0] != 0) { + event.keyCode = Display.translateKey (keysym [0]); + } + if (buffer [0] != 0) { + event.character = mbcsToWcs (buffer [0] & 0xFF); + } + } + setInputState (event, xEvent); +} +void sendEvent (Event event) { + Display display = event.display; + if (!display.filterEvent (event)) { + if (eventTable != null) eventTable.sendEvent (event); + } +} +void sendEvent (int eventType) { + sendEvent (eventType, null, true); +} +void sendEvent (int eventType, Event event) { + sendEvent (eventType, event, true); +} +void sendEvent (int eventType, Event event, boolean send) { + Display display = getDisplay (); + if (eventTable == null && !display.filters (eventType)) { + return; + } + if (event == null) event = new Event (); + event.type = eventType; + event.display = display; + event.widget = this; + if (event.time == 0) { + event.time = display.getLastEventTime (); + } + if (send) { + sendEvent (event); + } else { + display.postEvent (event); + } +} +/** + * 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 (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) {
- checkWidget();
- 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 void setData (String key, Object value) { + checkWidget(); + 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;
-}
-boolean translateAccelerator (int key, int keysym, XKeyEvent xEvent) {
- return false;
-}
-boolean translateMnemonic (int key, XKeyEvent xEvent) {
- return false;
-}
-boolean translateTraversal (int key, XKeyEvent xEvent) {
- return false;
-}
-boolean XmProcessTraversal (int widget, int direction) {
- /*
- * Bug in Motif. When XtDestroyWidget() is called from
- * within a FocusOut event handler, Motif GP's. The fix
- * is to post focus events and run them when the handler
- * has returned.
- */
- Display display = getDisplay ();
- boolean oldFocusOut = display.postFocusOut;
- display.postFocusOut = true;
- boolean result = OS.XmProcessTraversal (widget, direction);
- display.postFocusOut = oldFocusOut;
- if (!display.postFocusOut) display.runFocusOutEvents ();
- return result;
-}
-int wcsToMbcs (char ch) {
- return wcsToMbcs (ch, null);
-}
-int wcsToMbcs (char ch, String codePage) {
- int key = ch & 0xFFFF;
- if (key <= 0x7F) return ch;
- byte [] buffer = Converter.wcsToMbcs (codePage, new char [] {ch}, false);
- if (buffer.length == 1) return (char) buffer [0];
- if (buffer.length == 2) {
- return (char) (((buffer [0] & 0xFF) << 8) | (buffer [1] & 0xFF));
- }
- return 0;
-}
-int hoverProc (int widget) {
- return 0;
-}
-int timerProc (int id) {
- return 0;
-}
-int windowProc (int w, int client_data, int call_data, int continue_to_dispatch) {
- switch (client_data) {
- case BUTTON_PRESS: return XButtonPress (w, client_data, call_data, continue_to_dispatch);
- case BUTTON_RELEASE: return XButtonRelease (w, client_data, call_data, continue_to_dispatch);
- case ENTER_WINDOW: return XEnterWindow (w, client_data, call_data, continue_to_dispatch);
- case EXPOSURE: return XExposure (w, client_data, call_data, continue_to_dispatch);
- case FOCUS_CHANGE: return XFocusChange (w, client_data, call_data, continue_to_dispatch);
- case KEY_PRESS: return XKeyPress (w, client_data, call_data, continue_to_dispatch);
- case KEY_RELEASE: return XKeyRelease (w, client_data, call_data, continue_to_dispatch);
- case LEAVE_WINDOW: return XLeaveWindow (w, client_data, call_data, continue_to_dispatch);
- case ACTIVATE_CALLBACK: return XmNactivateCallback (w, client_data, call_data);
- case ARM_CALLBACK: return XmNarmCallback (w, client_data, call_data);
- case BROWSE_SELECTION_CALLBACK: return XmNbrowseSelectionCallback (w, client_data, call_data);
- case CASCADING_CALLBACK: return XmNcascadingCallback (w, client_data, call_data);
- case DECREMENT_CALLBACK: return XmNdecrementCallback (w, client_data, call_data);
- case DEFAULT_ACTION_CALLBACK: return XmNdefaultActionCallback (w, client_data, call_data);
- case DRAG_CALLBACK: return XmNdragCallback (w, client_data, call_data);
- case EXTENDED_SELECTION_CALLBACK: return XmNextendedSelectionCallback (w, client_data, call_data);
- case HELP_CALLBACK: return XmNhelpCallback (w, client_data, call_data);
- case INCREMENT_CALLBACK: return XmNincrementCallback (w, client_data, call_data);
- case MODIFY_VERIFY_CALLBACK: return XmNmodifyVerifyCallback (w, client_data, call_data);
- case PAGE_DECREMENT_CALLBACK: return XmNpageDecrementCallback (w, client_data, call_data);
- case PAGE_INCREMENT_CALLBACK: return XmNpageIncrementCallback (w, client_data, call_data);
- case SELECTION_CALLBACK: return XmNselectionCallback (w, client_data, call_data);
- case TO_BOTTOM_CALLBACK: return XmNtoBottomCallback (w, client_data, call_data);
- case TO_TOP_CALLBACK: return XmNtoTopCallback (w, client_data, call_data);
- case VALUE_CHANGED_CALLBACK: return XmNvalueChangedCallback (w, client_data, call_data);
- case NON_MASKABLE: return XNonMaskable (w, client_data, call_data, continue_to_dispatch);
- case POINTER_MOTION : return XPointerMotion (w, client_data, call_data, continue_to_dispatch);
- case STRUCTURE_NOTIFY: return XStructureNotify (w, client_data, call_data, continue_to_dispatch);
- case MAP_CALLBACK: return XmNmapCallback (w, client_data, call_data);
- case UNMAP_CALLBACK: return XmNunmapCallback (w, client_data, call_data);
- case DELETE_WINDOW: return WM_DELETE_WINDOW (w, client_data, call_data);
- case EXPOSURE_CALLBACK: return XmNexposureCallback (w, client_data, call_data);
- }
- return 0;
-}
-int WM_DELETE_WINDOW (int w, int client_data, int call_data) {
- return 0;
-}
-int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XEnterWindow (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XKeyRelease (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XLeaveWindow (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XmNactivateCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNarmCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNbrowseSelectionCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNcascadingCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNdecrementCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNdefaultActionCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNdragCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNexposureCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNextendedSelectionCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNhelpCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNincrementCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNmapCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNmodifyVerifyCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNpageDecrementCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNpageIncrementCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNselectionCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNtoBottomCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNtoTopCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNunmapCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XmNvalueChangedCallback (int w, int client_data, int call_data) {
- return 0;
-}
-int XNonMaskable (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-int XStructureNotify (int w, int client_data, int call_data, int continue_to_dispatch) {
- return 0;
-}
-}
+public String toString () { + String string = "*Disposed*"; + if (!isDisposed ()) { + string = "*Wrong Thread*"; + if (isValidThread ()) string = getNameText (); + } + return getName () + " {" + string + "}"; +} +int topHandle () { + return handle; +} +boolean translateAccelerator (int key, int keysym, XKeyEvent xEvent) { + return false; +} +boolean translateMnemonic (int key, XKeyEvent xEvent) { + return false; +} +boolean translateTraversal (int key, XKeyEvent xEvent) { + return false; +} +boolean XmProcessTraversal (int widget, int direction) { + /* + * Bug in Motif. When XtDestroyWidget() is called from + * within a FocusOut event handler, Motif GP's. The fix + * is to post focus events and run them when the handler + * has returned. + */ + Display display = getDisplay (); + boolean oldFocusOut = display.postFocusOut; + display.postFocusOut = true; + boolean result = OS.XmProcessTraversal (widget, direction); + display.postFocusOut = oldFocusOut; + if (!display.postFocusOut) display.runFocusOutEvents (); + return result; +} +int wcsToMbcs (char ch) { + return wcsToMbcs (ch, null); +} +int wcsToMbcs (char ch, String codePage) { + int key = ch & 0xFFFF; + if (key <= 0x7F) return ch; + byte [] buffer = Converter.wcsToMbcs (codePage, new char [] {ch}, false); + if (buffer.length == 1) return (char) buffer [0]; + if (buffer.length == 2) { + return (char) (((buffer [0] & 0xFF) << 8) | (buffer [1] & 0xFF)); + } + return 0; +} +int hoverProc (int widget) { + return 0; +} +int timerProc (int id) { + return 0; +} +int windowProc (int w, int client_data, int call_data, int continue_to_dispatch) { + switch (client_data) { + case BUTTON_PRESS: return XButtonPress (w, client_data, call_data, continue_to_dispatch); + case BUTTON_RELEASE: return XButtonRelease (w, client_data, call_data, continue_to_dispatch); + case ENTER_WINDOW: return XEnterWindow (w, client_data, call_data, continue_to_dispatch); + case EXPOSURE: return XExposure (w, client_data, call_data, continue_to_dispatch); + case FOCUS_CHANGE: return XFocusChange (w, client_data, call_data, continue_to_dispatch); + case KEY_PRESS: return XKeyPress (w, client_data, call_data, continue_to_dispatch); + case KEY_RELEASE: return XKeyRelease (w, client_data, call_data, continue_to_dispatch); + case LEAVE_WINDOW: return XLeaveWindow (w, client_data, call_data, continue_to_dispatch); + case ACTIVATE_CALLBACK: return XmNactivateCallback (w, client_data, call_data); + case ARM_CALLBACK: return XmNarmCallback (w, client_data, call_data); + case BROWSE_SELECTION_CALLBACK: return XmNbrowseSelectionCallback (w, client_data, call_data); + case CASCADING_CALLBACK: return XmNcascadingCallback (w, client_data, call_data); + case DECREMENT_CALLBACK: return XmNdecrementCallback (w, client_data, call_data); + case DEFAULT_ACTION_CALLBACK: return XmNdefaultActionCallback (w, client_data, call_data); + case DRAG_CALLBACK: return XmNdragCallback (w, client_data, call_data); + case EXTENDED_SELECTION_CALLBACK: return XmNextendedSelectionCallback (w, client_data, call_data); + case HELP_CALLBACK: return XmNhelpCallback (w, client_data, call_data); + case INCREMENT_CALLBACK: return XmNincrementCallback (w, client_data, call_data); + case MODIFY_VERIFY_CALLBACK: return XmNmodifyVerifyCallback (w, client_data, call_data); + case PAGE_DECREMENT_CALLBACK: return XmNpageDecrementCallback (w, client_data, call_data); + case PAGE_INCREMENT_CALLBACK: return XmNpageIncrementCallback (w, client_data, call_data); + case SELECTION_CALLBACK: return XmNselectionCallback (w, client_data, call_data); + case TO_BOTTOM_CALLBACK: return XmNtoBottomCallback (w, client_data, call_data); + case TO_TOP_CALLBACK: return XmNtoTopCallback (w, client_data, call_data); + case VALUE_CHANGED_CALLBACK: return XmNvalueChangedCallback (w, client_data, call_data); + case NON_MASKABLE: return XNonMaskable (w, client_data, call_data, continue_to_dispatch); + case POINTER_MOTION : return XPointerMotion (w, client_data, call_data, continue_to_dispatch); + case STRUCTURE_NOTIFY: return XStructureNotify (w, client_data, call_data, continue_to_dispatch); + case MAP_CALLBACK: return XmNmapCallback (w, client_data, call_data); + case UNMAP_CALLBACK: return XmNunmapCallback (w, client_data, call_data); + case DELETE_WINDOW: return WM_DELETE_WINDOW (w, client_data, call_data); + case EXPOSURE_CALLBACK: return XmNexposureCallback (w, client_data, call_data); + } + return 0; +} +int WM_DELETE_WINDOW (int w, int client_data, int call_data) { + return 0; +} +int XButtonPress (int w, int client_data, int call_data, int continue_to_dispatch) { + return 0; +} +int XButtonRelease (int w, int client_data, int call_data, int continue_to_dispatch) { + return 0; +} +int XEnterWindow (int w, int client_data, int call_data, int continue_to_dispatch) { + return 0; +} +int XExposure (int w, int client_data, int call_data, int continue_to_dispatch) { + return 0; +} +int XFocusChange (int w, int client_data, int call_data, int continue_to_dispatch) { + return 0; +} +int XKeyPress (int w, int client_data, int call_data, int continue_to_dispatch) { + return 0; +} +int XKeyRelease (int w, int client_data, int call_data, int continue_to_dispatch) { + return 0; +} +int XLeaveWindow (int w, int client_data, int call_data, int continue_to_dispatch) { + return 0; +} +int XPointerMotion (int w, int client_data, int call_data, int continue_to_dispatch) { + return 0; +} +int XmNactivateCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNarmCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNbrowseSelectionCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNcascadingCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNdecrementCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNdefaultActionCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNdragCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNexposureCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNextendedSelectionCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNhelpCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNincrementCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNmapCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNmodifyVerifyCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNpageDecrementCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNpageIncrementCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNselectionCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNtoBottomCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNtoTopCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNunmapCallback (int w, int client_data, int call_data) { + return 0; +} +int XmNvalueChangedCallback (int w, int client_data, int call_data) { + return 0; +} +int XNonMaskable (int w, int client_data, int call_data, int continue_to_dispatch) { + return 0; +} +int XStructureNotify (int w, int client_data, int call_data, int continue_to_dispatch) { + return 0; +} +} diff --git a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/WidgetTable.java b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/WidgetTable.java index ce5ac52d44..fec0c7d19e 100755 --- a/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/WidgetTable.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/motif/org/eclipse/swt/widgets/WidgetTable.java @@ -1,123 +1,123 @@ -package org.eclipse.swt.widgets;
-
-/*
+package org.eclipse.swt.widgets; + +/* * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. * This file is made available under the terms of the Common Public License v1.0 * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html
- */
-
-import org.eclipse.swt.internal.motif.*;
-
-class WidgetTable {
- static int FreeSlot = 0;
- static int GrowSize = 1024;
- static int [] IndexTable = new int [GrowSize];
- static Shell [] Shells = new Shell [GrowSize / 8];
- static Widget [] WidgetTable = new Widget [GrowSize];
- static int [] ArgList = {OS.XmNuserData, 0};
- 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;
- if (OS.XtIsSubclass (handle, OS.ShellWidgetClass ())) {
- for (int i=0; i<Shells.length; i++) {
- Widget shell = Shells [i];
- if ((shell != null) && (shell.topHandle () == handle)) return shell;
- }
- return null;
- }
- ArgList [1] = 0;
- OS.XtGetValues (handle, ArgList, ArgList.length / 2);
- if (ArgList [1] == 0) return null;
- int index = ArgList [1] - 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 (OS.XtIsSubclass (handle, OS.ShellWidgetClass ())) {
- for (int i=0; i<Shells.length; i++) {
- if (Shells [i] == null) {
- Shells [i] = (Shell) widget;
- return;
- }
- }
- Shell [] newShells = new Shell [Shells.length + GrowSize / 8];
- System.arraycopy (Shells, 0, newShells, 0, Shells.length);
- newShells [Shells.length] = (Shell) widget;
- Shells = newShells;
- 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;
- }
- ArgList [1] = FreeSlot + 1;
- OS.XtSetValues (handle, ArgList, ArgList.length / 2);
- int oldSlot = FreeSlot;
- FreeSlot = IndexTable [oldSlot];
- IndexTable [oldSlot] = -2;
- WidgetTable [oldSlot] = widget;
-}
-public static synchronized Widget remove (int handle) {
- if (handle == 0) return null;
- if (OS.XtIsSubclass (handle, OS.ShellWidgetClass ())) {
- for (int i=0; i<Shells.length; i++) {
- Widget shell = Shells [i];
- if ((shell != null) && (shell.topHandle () == handle)) {
- Shells [i] = null;
- return shell;
- }
- }
- return null;
- }
- ArgList [1] = 0;
- Widget widget = null;
- OS.XtGetValues (handle, ArgList, ArgList.length / 2);
- int index = ArgList [1] - 1;
- if (0 <= index && index < WidgetTable.length) {
- widget = WidgetTable [index];
- WidgetTable [index] = null;
- IndexTable [index] = FreeSlot;
- FreeSlot = index;
- ArgList [1] = 0;
- OS.XtSetValues (handle, ArgList, ArgList.length / 2);
- }
- return widget;
-}
-public static synchronized Shell [] shells () {
- int length = 0;
- for (int i=0; i<Shells.length; i++) {
- if (Shells [i] != null) length++;
- }
- int index = 0;
- Shell [] result = new Shell [length];
- for (int i=0; i<Shells.length; i++) {
- Shell widget = Shells [i];
- if (widget != null) result [index++] = widget;
- }
- return result;
-}
-public static synchronized int size () {
- int length = 0;
- for (int i=0; i<Shells.length; i++) {
- if (Shells [i] != null) length++;
- }
- for (int i=0; i<WidgetTable.length; i++) {
- if (WidgetTable [i] != null) length++;
- }
- return length;
-}
-}
+ * http://www.eclipse.org/legal/cpl-v10.html + */ + +import org.eclipse.swt.internal.motif.*; + +class WidgetTable { + static int FreeSlot = 0; + static int GrowSize = 1024; + static int [] IndexTable = new int [GrowSize]; + static Shell [] Shells = new Shell [GrowSize / 8]; + static Widget [] WidgetTable = new Widget [GrowSize]; + static int [] ArgList = {OS.XmNuserData, 0}; + 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; + if (OS.XtIsSubclass (handle, OS.ShellWidgetClass ())) { + for (int i=0; i<Shells.length; i++) { + Widget shell = Shells [i]; + if ((shell != null) && (shell.topHandle () == handle)) return shell; + } + return null; + } + ArgList [1] = 0; + OS.XtGetValues (handle, ArgList, ArgList.length / 2); + if (ArgList [1] == 0) return null; + int index = ArgList [1] - 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 (OS.XtIsSubclass (handle, OS.ShellWidgetClass ())) { + for (int i=0; i<Shells.length; i++) { + if (Shells [i] == null) { + Shells [i] = (Shell) widget; + return; + } + } + Shell [] newShells = new Shell [Shells.length + GrowSize / 8]; + System.arraycopy (Shells, 0, newShells, 0, Shells.length); + newShells [Shells.length] = (Shell) widget; + Shells = newShells; + 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; + } + ArgList [1] = FreeSlot + 1; + OS.XtSetValues (handle, ArgList, ArgList.length / 2); + int oldSlot = FreeSlot; + FreeSlot = IndexTable [oldSlot]; + IndexTable [oldSlot] = -2; + WidgetTable [oldSlot] = widget; +} +public static synchronized Widget remove (int handle) { + if (handle == 0) return null; + if (OS.XtIsSubclass (handle, OS.ShellWidgetClass ())) { + for (int i=0; i<Shells.length; i++) { + Widget shell = Shells [i]; + if ((shell != null) && (shell.topHandle () == handle)) { + Shells [i] = null; + return shell; + } + } + return null; + } + ArgList [1] = 0; + Widget widget = null; + OS.XtGetValues (handle, ArgList, ArgList.length / 2); + int index = ArgList [1] - 1; + if (0 <= index && index < WidgetTable.length) { + widget = WidgetTable [index]; + WidgetTable [index] = null; + IndexTable [index] = FreeSlot; + FreeSlot = index; + ArgList [1] = 0; + OS.XtSetValues (handle, ArgList, ArgList.length / 2); + } + return widget; +} +public static synchronized Shell [] shells () { + int length = 0; + for (int i=0; i<Shells.length; i++) { + if (Shells [i] != null) length++; + } + int index = 0; + Shell [] result = new Shell [length]; + for (int i=0; i<Shells.length; i++) { + Shell widget = Shells [i]; + if (widget != null) result [index++] = widget; + } + return result; +} +public static synchronized int size () { + int length = 0; + for (int i=0; i<Shells.length; i++) { + if (Shells [i] != null) length++; + } + for (int i=0; i<WidgetTable.length; i++) { + if (WidgetTable [i] != null) length++; + } + return length; +} +} |