Changeset 19
- Timestamp:
- 05/25/04 17:56:28 (4 years ago)
- Files:
-
- trunk/dwt/graphics/IDrawable.d (modified) (1 diff)
- trunk/dwt/graphics/IImageloaderlistener.d (modified) (1 diff)
- trunk/dwt/graphics/color.d (modified) (1 diff)
- trunk/dwt/graphics/cursor.d (modified) (1 diff)
- trunk/dwt/graphics/device.d (modified) (1 diff)
- trunk/dwt/graphics/devicedata.d (modified) (1 diff)
- trunk/dwt/graphics/font.d (modified) (1 diff)
- trunk/dwt/graphics/fontdata.d (modified) (1 diff)
- trunk/dwt/graphics/fontmetrics.d (modified) (1 diff)
- trunk/dwt/graphics/gc.d (modified) (1 diff)
- trunk/dwt/graphics/gcdata.d (modified) (1 diff)
- trunk/dwt/graphics/image.d (modified) (1 diff)
- trunk/dwt/graphics/imagedata.d (modified) (1 diff)
- trunk/dwt/graphics/imageloader.d (modified) (1 diff)
- trunk/dwt/graphics/imageloaderevent.d (modified) (1 diff)
- trunk/dwt/graphics/palettedata.d (modified) (1 diff)
- trunk/dwt/graphics/point.d (modified) (1 diff)
- trunk/dwt/graphics/readme.txt (deleted)
- trunk/dwt/graphics/rectangle.d (modified) (1 diff)
- trunk/dwt/graphics/region.d (modified) (1 diff)
- trunk/dwt/graphics/rgb.d (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/dwt/graphics/IDrawable.d
r4 r19 1 /*******************************************************************************2 * Copyright (c) 2000, 2003 IBM Corporation and others.3 * All rights reserved. This program and the accompanying materials4 * are made available under the terms of the Common Public License v1.05 * which accompanies this distribution, and is available at6 * http://www.eclipse.org/legal/cpl-v10.html7 *8 * Contributors:9 * IBM Corporation - initial API and implementation10 *******************************************************************************/11 12 /******************************************************************************13 * DWT : SWT Port for the D Language14 *15 * Contributers:16 * The DWT team at www.dsource.org17 *18 * DATE: 2004-04-2719 ******************************************************************************/20 21 1 module dwt.graphics.IDrawable; 22 2 23 3 public interface IDrawable { 24 private import dwt.graphics.gcdata; 25 public int internal_new_GC(GCData data); 26 public void internal_dispose_GC(int handle, GCData data); 27 } 28 4 5 private import dwt.graphics.gcdata; 6 /** 7 * Invokes platform specific functionality to allocate a new GC handle. 8 * <p> 9 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public 10 * API for <code>Drawable</code>. It is marked public only so that it 11 * can be shared within the packages provided by SWT. It is not 12 * available on all platforms, and should never be called from 13 * application code. 14 * </p> 15 * 16 * @param data the platform specific GC data 17 * @return the platform specific GC handle 18 */ 19 20 public int internal_new_GC (GCData data); 21 22 23 /** 24 * Invokes platform specific functionality to dispose a GC handle. 25 * <p> 26 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public 27 * API for <code>Drawable</code>. It is marked public only so that it 28 * can be shared within the packages provided by SWT. It is not 29 * available on all platforms, and should never be called from 30 * application code. 31 * </p> 32 * 33 * @param handle the platform specific GC handle 34 * @param data the platform specific GC data 35 */ 36 37 public void internal_dispose_GC (int handle, GCData data); 38 } trunk/dwt/graphics/IImageloaderlistener.d
r4 r19 22 22 23 23 // private import dwt.graphics; 24 private import dwt.internal. idwteventlistner;24 private import dwt.internal.IDWTEventlistener; 25 25 26 26 public interface IImageLoaderListener : IDWTEventListener { 27 private import imageloaderevent;27 private import dwt.graphics.imageloaderevent; 28 28 29 29 public void imageDataLoaded( ImageLoaderEvent e ); trunk/dwt/graphics/color.d
r4 r19 1 /******************************************************************************* 2 * Copyright (c) 2000, 2003 IBM Corporation and others. 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Common Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/cpl-v10.html 7 * 8 * Contributors: 9 * IBM Corporation - initial API and implementation 10 *******************************************************************************/ 11 12 /****************************************************************************** 13 * DWT : SWT Port for the D Language 14 * 15 * Contributers: 16 * The DWT team at www.dsource.org 17 * 18 * DATE: 2004-04-27 19 ******************************************************************************/ 1 20 2 21 3 module dwt.graphics.color; 22 4 23 // private import dwt.internal.win32; 24 // private import dwt.dwt; 5 /+ 6 import org.eclipse.swt.internal.win32.*; 7 import org.eclipse.swt.*; 8 +/ 9 10 private import dwt.dwt; 11 private import dwt.graphics.rgb; 12 private import dwt.graphics.device; 13 private import dwt.internal.win32.os; 14 private import std.string; 15 16 17 /** 18 * Instances of this class manage the operating system resources that 19 * implement DWT's RGB color model. To create a color you can either 20 * specify the individual color components as integers in the range 21 * 0 to 255 or provide an instance of an <code>RGB</code>. 22 * <p> 23 * Application code must explicitly invoke the <code>Color.dispose()</code> 24 * method to release the operating system resources managed by each instance 25 * when those instances are no longer required. 26 * </p> 27 * 28 * @see RGB 29 * @see Device#getSystemColor 30 */ 25 31 26 32 public final class Color { 27 28 /+ // The handle to the OS color resource 29 // (Warning: This field is platfrom dependent 33 34 /** 35 * the handle to the OS color resource 36 * (Warning: This field is platform dependent) 37 */ 30 38 public int handle; 31 32 // The device where the color was created 33 private import dwt.graphics.device; 39 40 /** 41 * the device where this color was created 42 */ 34 43 Device device; 35 36 // Prevents uninitialized instances from being created outside the package 37 this() {} 38 39 public this(Device device, int red, int green, int blue) { 40 if (device == null) device = Device.getDevice(); 41 if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 42 init(device, red, green, blue); 43 if (device.tracking) device.new_Object(this); 44 } 45 +/ 46 47 } 44 45 /** 46 * Prevents uninitialized instances from being created outside the package. 47 */ 48 this(){} 49 50 /** 51 * Constructs a new instance of this class given a device and the 52 * desired red, green and blue values expressed as ints in the range 53 * 0 to 255 (where 0 is black and 255 is full brightness). On limited 54 * color devices, the color instance created by this call may not have 55 * the same RGB values as the ones specified by the arguments. The 56 * RGB values on the returned instance will be the color values of 57 * the operating system color. 58 * <p> 59 * You must dispose the color when it is no longer required. 60 * </p> 61 * 62 * @param device the device on which to allocate the color 63 * @param red the amount of red in the color 64 * @param green the amount of green in the color 65 * @param blue the amount of blue in the color 66 * 67 * @exception IllegalArgumentException <ul> 68 * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> 69 * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255</li> 70 * </ul> 71 * 72 * @see #dispose 73 */ 74 public this(Device device, int red, int green, int blue) { 75 if (device == null) device = Device.getDevice(); 76 if (device == null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 77 init(device, red, green, blue); 78 if (device.tracking) device.new_Object(this); 79 } 80 81 /** 82 * Constructs a new instance of this class given a device and an 83 * <code>RGB</code> describing the desired red, green and blue values. 84 * On limited color devices, the color instance created by this call 85 * may not have the same RGB values as the ones specified by the 86 * argument. The RGB values on the returned instance will be the color 87 * values of the operating system color. 88 * <p> 89 * You must dispose the color when it is no longer required. 90 * </p> 91 * 92 * @param device the device on which to allocate the color 93 * @param RGB the RGB values of the desired color 94 * 95 * @exception IllegalArgumentException <ul> 96 * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> 97 * <li>ERROR_NULL_ARGUMENT - if the rgb argument is null</li> 98 * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue components of the argument are not between 0 and 255</li> 99 * </ul> 100 * 101 * @see #dispose 102 */ 103 public this(Device device, RGB rgb) { 104 if (device == null) device = Device.getDevice(); 105 if (device == null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 106 init(device, rgb.red, rgb.green, rgb.blue); 107 if (device.tracking) device.new_Object(this); 108 } 109 110 /** 111 * Disposes of the operating system resources associated with 112 * the color. Applications must dispose of all colors which 113 * they allocate. 114 */ 115 public void dispose() { 116 if (handle == -1) return; 117 if (device.isDisposed()) return; 118 119 /* 120 * If this is a palette-based device, 121 * Decrease the reference count for this color. 122 * If the reference count reaches 0, the slot may 123 * be reused when another color is allocated. 124 */ 125 int hPal = device.hPalette; 126 if (hPal != 0) { 127 int index = OS.GetNearestPaletteIndex(hPal, handle); 128 int[] colorRefCount = device.colorRefCount; 129 if (colorRefCount[index] > 0) { 130 colorRefCount[index]--; 131 } 132 } 133 handle = -1; 134 if (device.tracking) device.dispose_Object(this); 135 device = null; 136 } 137 138 /** 139 * Compares the argument to the receiver, and returns true 140 * if they represent the <em>same</em> object using a class 141 * specific comparison. 142 * 143 * @param object the object to compare with this object 144 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise 145 * 146 * @see #hashCode 147 */ 148 public bit equals (Object object) { 149 if (object == this) return true; 150 // TODO: deal with instanceof if (!(object instanceof Color)) return false; 151 Color color = (Color) object; 152 return device == color.device && (handle & 0xFFFFFF) == (color.handle & 0xFFFFFF); 153 } 154 155 /** 156 * Returns the amount of blue in the color, from 0 to 255. 157 * 158 * @return the blue component of the color 159 * 160 * @exception SWTException <ul> 161 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> 162 * </ul> 163 */ 164 public int getBlue () { 165 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 166 return (handle & 0xFF0000) >> 16; 167 } 168 169 /** 170 * Returns the amount of green in the color, from 0 to 255. 171 * 172 * @return the green component of the color 173 * 174 * @exception SWTException <ul> 175 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> 176 * </ul> 177 */ 178 public int getGreen () { 179 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 180 return (handle & 0xFF00) >> 8 ; 181 } 182 183 /** 184 * Returns the amount of red in the color, from 0 to 255. 185 * 186 * @return the red component of the color 187 * 188 * @exception SWTException <ul> 189 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> 190 * </ul> 191 */ 192 public int getRed () { 193 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 194 return handle & 0xFF; 195 } 196 197 /** 198 * Returns an <code>RGB</code> representing the receiver. 199 * 200 * @exception SWTException <ul> 201 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> 202 * </ul> 203 */ 204 public RGB getRGB () { 205 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); 206 return RGB(handle & 0xFF, (handle & 0xFF00) >> 8, (handle & 0xFF0000) >> 16); 207 } 208 209 /** 210 * Returns an integer hash code for the receiver. Any two 211 * objects which return <code>true</code> when passed to 212 * <code>equals</code> must return the same value for this 213 * method. 214 * 215 * @return the receiver's hash 216 * 217 * @see #equals 218 */ 219 public int hashCode () { 220 return handle; 221 } 222 223 /** 224 * Allocates the operating system resources associated 225 * with the receiver. 226 * 227 * @param device the device on which to allocate the color 228 * @param red the amount of red in the color 229 * @param green the amount of green in the color 230 * @param blue the amount of blue in the color 231 * 232 * @exception IllegalArgumentException <ul> 233 * <li>ERROR_INVALID_ARGUMENT - if the red, green or blue argument is not between 0 and 255</li> 234 * </ul> 235 * 236 * @see #dispose 237 */ 238 void init(Device device, int red, int green, int blue) { 239 if (red > 255 || red < 0 || green > 255 || green < 0 || blue > 255 || blue < 0) { 240 DWT.error(DWT.ERROR_INVALID_ARGUMENT); 241 } 242 this.device = device; 243 handle = 0x02000000 | (red & 0xFF) | ((green & 0xFF) << 8) | ((blue & 0xFF) << 16); 244 245 /* If this is not a palette-based device, return */ 246 int hPal = device.hPalette; 247 if (hPal == 0) return; 248 249 int[] colorRefCount = device.colorRefCount; 250 /* Add this color to the default palette now */ 251 /* First find out if the color already exists */ 252 int index = OS.GetNearestPaletteIndex(hPal, handle); 253 /* See if the nearest color actually is the color */ 254 byte[] entry = new byte[4]; 255 OS.GetPaletteEntries(hPal, index, 1, entry); 256 if ((entry[0] == (byte)red) && (entry[1] == (byte)green) && 257 (entry[2] == (byte)blue)) { 258 /* Found the color. Increment the ref count and return */ 259 colorRefCount[index]++; 260 return; 261 } 262 /* Didn't find the color, allocate it now. Find the first free entry */ 263 int i = 0; 264 while (i < colorRefCount.length) { 265 if (colorRefCount[i] == 0) { 266 index = i; 267 break; 268 } 269 i++; 270 } 271 if (i == colorRefCount.length) { 272 /* No free entries, use the closest one */ 273 /* Remake the handle from the actual rgbs */ 274 handle = (entry[0] & 0xFF) | ((entry[1] & 0xFF) << 8) | 275 ((entry[2] & 0xFF) << 16); 276 } else { 277 /* Found a free entry */ 278 entry = new byte[3];// [ cast(byte)(red & 0xFF), cast(byte)(green & 0xFF), cast(byte)(blue & 0xFF), 0 ]; 279 entry[0] = red & 0xff; 280 entry[1] = green & 0xff; 281 entry[2] = blue & 0xff; 282 OS.SetPaletteEntries(hPal, index, 1, entry); 283 } 284 colorRefCount[index]++; 285 } 286 287 /** 288 * Returns <code>true</code> if the color has been disposed, 289 * and <code>false</code> otherwise. 290 * <p> 291 * This method gets the dispose state for the color. 292 * When a color has been disposed, it is an error to 293 * invoke any other method using the color. 294 * 295 * @return <code>true</code> when the color is disposed and <code>false</code> otherwise 296 */ 297 public bit isDisposed() { 298 return handle == -1; 299 } 300 301 /** 302 * Returns a string containing a concise, human-readable 303 * description of the receiver. 304 * 305 * @return a string representation of the receiver 306 */ 307 public char[] toString () { 308 if (isDisposed()) return "Color {*DISPOSED*}"; //$NON-NLS-1$ 309 return "Color {" ~ .toString(getRed()) ~ ", " ~ .toString(getGreen()) ~ ", " ~ .toString(getBlue()) ~ "}"; //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ 310 } 311 312 /** 313 * Invokes platform specific functionality to allocate a new color. 314 * <p> 315 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public 316 * API for <code>Color</code>. It is marked public only so that it 317 * can be shared within the packages provided by DWT. It is not 318 * available on all platforms, and should never be called from 319 * application code. 320 * </p> 321 * 322 * @param device the device on which to allocate the color 323 * @param handle the handle for the color 324 */ 325 public static Color win32_new(Device device, int handle) { 326 if (device == null) device = Device.getDevice(); 327 Color color = new Color(); 328 color.handle = handle; 329 color.device = device; 330 return color; 331 } 332 333 } trunk/dwt/graphics/cursor.d
r4 r19 1 /******************************************************************************* 2 * Copyright (c) 2000, 2003 IBM Corporation and others. 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Common Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/cpl-v10.html 1 2 3 module dwt.graphics.cursor; 4 5 /+ 6 import org.eclipse.swt.internal.win32.*; 7 import org.eclipse.swt.*; 8 +/ 9 10 private import dwt.graphics.device; 11 12 13 /** 14 * Instances of this class manage operating system resources that 15 * specify the appearance of the on-screen pointer. To create a 16 * cursor you specify the device and either a simple cursor style 17 * describing one of the standard operating system provided cursors 18 * or the image and mask data for the desired appearance. 19 * <p> 20 * Application code must explicitly invoke the <code>Cursor.dispose()</code> 21 * method to release the operating system resources managed by each instance 22 * when those instances are no longer required. 23 * </p> 24 * <dl> 25 * <dt><b>Styles:</b></dt> 26 * <dd> 27 * CURSOR_ARROW, CURSOR_WAIT, CURSOR_CROSS, CURSOR_APPSTARTING, CURSOR_HELP, 28 * CURSOR_SIZEALL, CURSOR_SIZENESW, CURSOR_SIZENS, CURSOR_SIZENWSE, CURSOR_SIZEWE, 29 * CURSOR_SIZEN, CURSOR_SIZES, CURSOR_SIZEE, CURSOR_SIZEW, CURSOR_SIZENE, CURSOR_SIZESE, 30 * CURSOR_SIZESW, CURSOR_SIZENW, CURSOR_UPARROW, CURSOR_IBEAM, CURSOR_NO, CURSOR_HAND 31 * </dd> 32 * </dl> 33 * <p> 34 * Note: Only one of the above styles may be specified. 35 * </p> 36 */ 37 38 public final class Cursor { 39 40 /** 41 * the handle to the OS cursor resource 42 * (Warning: This field is platform dependent) 43 */ 44 public int handle; 45 46 /** 47 * the device where this cursor was created 48 */ 49 Device device; 50 51 bit isIcon; 52 53 /** 54 * data used to create a HAND cursor. 55 */ 56 static final byte[] HAND_SOURCE = [ 57 (byte)0xf9,(byte)0xff,(byte)0xff,(byte)0xff, 58 (byte)0xf0,(byte)0xff,(byte)0xff,(byte)0xff, 59 (byte)0xf0,(byte)0xff,(byte)0xff,(byte)0xff, 60 (byte)0xf0,(byte)0xff,(byte)0xff,(byte)0xff, 61 (byte)0xf0,(byte)0x3f,(byte)0xff,(byte)0xff, 62 (byte)0xf0,(byte)0x07,(byte)0xff,(byte)0xff, 63 (byte)0xf0,(byte)0x03,(byte)0xff,(byte)0xff, 64 (byte)0xf0,(byte)0x00,(byte)0xff,(byte)0xff, 65 66 (byte)0x10,(byte)0x00,(byte)0x7f,(byte)0xff, 67 (byte)0x00,(byte)0x00,(byte)0x7f,(byte)0xff, 68 (byte)0x80,(byte)0x00,(byte)0x7f,(byte)0xff, 69 (byte)0xc0,(byte)0x00,(byte)0x7f,(byte)0xff, 70 (byte)0xe0,(byte)0x00,(byte)0x7f,(byte)0xff, 71 (byte)0xf0,(byte)0x00,(byte)0x7f,(byte)0xff, 72 (byte)0xf8,(byte)0x00,(byte)0xff,(byte)0xff, 73 (byte)0xfc,(byte)0x01,(byte)0xff,(byte)0xff, 74 75 (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff, 76 (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff, 77 (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff, 78 (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff, 79 (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff, 80 (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff, 81 (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff, 82 (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff, 83 84 (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff, 85 (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff, 86 (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff, 87 (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff, 88 (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff, 89 (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff, 90 (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff, 91 (byte)0xff,(byte)0xff,(byte)0xff,(byte)0xff 92 ]; 93 static final byte[] HAND_MASK = [ 94 (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, 95 (byte)0x06,(byte)0x00,(byte)0x00,(byte)0x00, 96 (byte)0x06,(byte)0x00,(byte)0x00,(byte)0x00, 97 (byte)0x06,(byte)0x00,(byte)0x00,(byte)0x00, 98 (byte)0x06,(byte)0x00,(byte)0x00,(byte)0x00, 99 (byte)0x06,(byte)0xc0,(byte)0x00,(byte)0x00, 100 (byte)0x06,(byte)0xd8,(byte)0x00,(byte)0x00, 101 (byte)0x06,(byte)0xd8,(byte)0x00,(byte)0x00, 102 103 (byte)0x07,(byte)0xdb,(byte)0x00,(byte)0x00, 104 (byte)0x67,(byte)0xfb,(byte)0x00,(byte)0x00, 105 (byte)0x3f,(byte)0xff,(byte)0x00,(byte)0x00, 106 (byte)0x1f,(byte)0xff,(byte)0x00,(byte)0x00, 107 (byte)0x0f,(byte)0xff,(byte)0x00,(byte)0x00, 108 (byte)0x07,(byte)0xff,(byte)0x00,(byte)0x00, 109 (byte)0x03,(byte)0xfe,(byte)0x00,(byte)0x00, 110 (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, 111 112 (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, 113 (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, 114 (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, 115 (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, 116 (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, 117 (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, 118 (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, 119 (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, 120 121 (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, 122 (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, 123 (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, 124 (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, 125 (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, 126 (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, 127 (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00, 128 (byte)0x00,(byte)0x00,(byte)0x00,(byte)0x00 129 ]; 130 131 /** 132 * Prevents uninitialized instances from being created outside the package. 133 */ 134 this() { 135 } 136 137 /+ 138 139 /** 140 * Constructs a new cursor given a device and a style 141 * constant describing the desired cursor appearance. 142 * <p> 143 * You must dispose the cursor when it is no longer required. 144 * </p> 145 * 146 * @param device the device on which to allocate the cursor 147 * @param style the style of cursor to allocate 7 148 * 8 * Contributors: 9 * IBM Corporation - initial API and implementation 10 *******************************************************************************/ 11 12 /****************************************************************************** 13 * DWT : SWT Port for the D Language 149 * @exception IllegalArgumentException <ul> 150 * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> 151 * <li>ERROR_INVALID_ARGUMENT - when an unknown style is specified</li> 152 * </ul> 153 * @exception SWTError <ul> 154 * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li> 155 * </ul> 156 * 157 * @see SWT#CURSOR_ARROW 158 * @see SWT#CURSOR_WAIT 159 * @see SWT#CURSOR_CROSS 160 * @see SWT#CURSOR_APPSTARTING 161 * @see SWT#CURSOR_HELP 162 * @see SWT#CURSOR_SIZEALL 163 * @see SWT#CURSOR_SIZENESW 164 * @see SWT#CURSOR_SIZENS 165 * @see SWT#CURSOR_SIZENWSE 166 * @see SWT#CURSOR_SIZEWE 167 * @see SWT#CURSOR_SIZEN 168 * @see SWT#CURSOR_SIZES 169 * @see SWT#CURSOR_SIZEE 170 * @see SWT#CURSOR_SIZEW 171 * @see SWT#CURSOR_SIZENE 172 * @see SWT#CURSOR_SIZESE 173 * @see SWT#CURSOR_SIZESW 174 * @see SWT#CURSOR_SIZENW 175 * @see SWT#CURSOR_UPARROW 176 * @see SWT#CURSOR_IBEAM 177 * @see SWT#CURSOR_NO 178 * @see SWT#CURSOR_HAND 179 */ 180 public Cursor(Device device, int style) { 181 if (device == null) device = Device.getDevice(); 182 if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 183 this.device = device; 184 int lpCursorName = 0; 185 switch (style) { 186 case SWT.CURSOR_HAND: lpCursorName = OS.IDC_HAND; break; 187 case SWT.CURSOR_ARROW: lpCursorName = OS.IDC_ARROW; break; 188 case SWT.CURSOR_WAIT: lpCursorName = OS.IDC_WAIT; break; 189 case SWT.CURSOR_CROSS: lpCursorName = OS.IDC_CROSS; break; 190 case SWT.CURSOR_APPSTARTING: lpCursorName = OS.IDC_APPSTARTING; break; 191 case SWT.CURSOR_HELP: lpCursorName = OS.IDC_HELP; break; 192 case SWT.CURSOR_SIZEALL: lpCursorName = OS.IDC_SIZEALL; break; 193 case SWT.CURSOR_SIZENESW: lpCursorName = OS.IDC_SIZENESW; break; 194 case SWT.CURSOR_SIZENS: lpCursorName = OS.IDC_SIZENS; break; 195 case SWT.CURSOR_SIZENWSE: lpCursorName = OS.IDC_SIZENWSE; break; 196 case SWT.CURSOR_SIZEWE: lpCursorName = OS.IDC_SIZEWE; break; 197 case SWT.CURSOR_SIZEN: lpCursorName = OS.IDC_SIZENS; break; 198 case SWT.CURSOR_SIZES: lpCursorName = OS.IDC_SIZENS; break; 199 case SWT.CURSOR_SIZEE: lpCursorName = OS.IDC_SIZEWE; break; 200 case SWT.CURSOR_SIZEW: lpCursorName = OS.IDC_SIZEWE; break; 201 case SWT.CURSOR_SIZENE: lpCursorName = OS.IDC_SIZENESW; break; 202 case SWT.CURSOR_SIZESE: lpCursorName = OS.IDC_SIZENWSE; break; 203 case SWT.CURSOR_SIZESW: lpCursorName = OS.IDC_SIZENESW; break; 204 case SWT.CURSOR_SIZENW: lpCursorName = OS.IDC_SIZENWSE; break; 205 case SWT.CURSOR_UPARROW: lpCursorName = OS.IDC_UPARROW; break; 206 case SWT.CURSOR_IBEAM: lpCursorName = OS.IDC_IBEAM; break; 207 case SWT.CURSOR_NO: lpCursorName = OS.IDC_NO; break; 208 default: 209 SWT.error(SWT.ERROR_INVALID_ARGUMENT); 210 } 211 handle = OS.LoadCursor(0, lpCursorName); 212 /* 213 * IDC_HAND is supported only on Windows 2000 and Windows 98. 214 * Create a hand cursor if running in other Windows platforms. 215 */ 216 if (handle == 0 && style == SWT.CURSOR_HAND) { 217 int width = OS.GetSystemMetrics(OS.SM_CXCURSOR); 218 int height = OS.GetSystemMetrics(OS.SM_CYCURSOR); 219 if (width == 32 && height == 32) { 220 int hInst = OS.GetModuleHandle(null); 221 if (OS.IsWinCE) SWT.error(SWT.ERROR_NOT_IMPLEMENTED); 222 handle = OS.CreateCursor(hInst, 5, 0, 32, 32, HAND_SOURCE, HAND_MASK); 223 224 } 225 } 226 if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); 227 if (device.tracking) device.new_Object(this); 228 } 229 230 /** 231 * Constructs a new cursor given a device, image and mask 232 * data describing the desired cursor appearance, and the x 233 * and y coordinates of the <em>hotspot</em> (that is, the point 234 * within the area covered by the cursor which is considered 235 * to be where the on-screen pointer is "pointing"). 236 * <p> 237 * The mask data is allowed to be null, but in this case the source 238 * must be an ImageData representing an icon that specifies both 239 * color data and mask data. 240 * <p> 241 * You must dispose the cursor when it is no longer required. 242 * </p> 243 * 244 * @param device the device on which to allocate the cursor 245 * @param source the color data for the cursor 246 * @param mask the mask data for the cursor (or null) 247 * @param hotspotX the x coordinate of the cursor's hotspot 248 * @param hotspotY the y coordinate of the cursor's hotspot 249 * 250 * @exception IllegalArgumentException <ul> 251 * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> 252 * <li>ERROR_NULL_ARGUMENT - if the source is null</li> 253 * <li>ERROR_NULL_ARGUMENT - if the mask is null and the source does not have a mask</li> 254 * <li>ERROR_INVALID_ARGUMENT - if the source and the mask are not the same 255 * size, or either is not of depth one, or if the hotspot is outside 256 * the bounds of the image</li> 257 * </ul> 258 * @exception SWTError <ul> 259 * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li> 260 * </ul> 261 */ 262 public Cursor(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) { 263 if (device == null) device = Device.getDevice(); 264 if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 265 this.device = device; 266 if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 267 if (mask == null) { 268 if (source.getTransparencyType() != SWT.TRANSPARENCY_MASK) { 269 SWT.error(SWT.ERROR_NULL_ARGUMENT); 270 } 271 mask = source.getTransparencyMask(); 272 } 273 /* Check the bounds. Mask must be the same size as source */ 274 if (mask.width != source.width || mask.height != source.height) { 275 SWT.error(SWT.ERROR_INVALID_ARGUMENT); 276 } 277 /* Check color depths */ 278 if (mask.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); 279 if (source.depth != 1) SWT.error(SWT.ERROR_INVALID_ARGUMENT); 280 /* Check the hotspots */ 281 if (hotspotX >= source.width || hotspotX < 0 || 282 hotspotY >= source.height || hotspotY < 0) { 283 SWT.error(SWT.ERROR_INVALID_ARGUMENT); 284 } 285 /* Create the cursor */ 286 int hInst = OS.GetModuleHandle(null); 287 if (OS.IsWinCE) SWT.error (SWT.ERROR_NOT_IMPLEMENTED); 288 handle = OS.CreateCursor(hInst, hotspotX, hotspotY, source.width, source.height, source.data, mask.data); 289 if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); 290 if (device.tracking) device.new_Object(this); 291 } 292 293 /** 294 * Constructs a new cursor given a device, image data describing 295 * the desired cursor appearance, and the x and y coordinates of 296 * the <em>hotspot</em> (that is, the point within the area 297 * covered by the cursor which is considered to be where the 298 * on-screen pointer is "pointing"). 299 * <p> 300 * You must dispose the cursor when it is no longer required. 301 * </p> 302 * 303 * @param device the device on which to allocate the cursor 304 * @param image the color data for the cursor 305 * @param hotspotX the x coordinate of the cursor's hotspot 306 * @param hotspotY the y coordinate of the cursor's hotspot 307 * 308 * @exception IllegalArgumentException <ul> 309 * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> 310 * <li>ERROR_NULL_ARGUMENT - if the image is null</li> 311 * <li>ERROR_INVALID_ARGUMENT - if the hotspot is outside the bounds of the 312 * image</li> 313 * </ul> 314 * @exception SWTError <ul> 315 * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li> 316 * </ul> 14 317 * 15 * Contributers: 16 * The DWT team at www.dsource.org 17 * 18 * DATE: 2004-04-27 19 ******************************************************************************/ 20 21 module dwt.graphics.cursor; 22 23 // private import dwt.internal.win32; 24 // provate import dwt.dwt; 25 26 public final class Cursor { 27 28 private import dwt.graphics.device; 29 private import dwt.graphics.imagedata; 30 31 } 318 * @since 3.0 319 */ 320 public Cursor(Device device, ImageData source, int hotspotX, int hotspotY) { 321 if (device == null) device = Device.getDevice(); 322 if (device == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 323 this.device = device; 324 if (source == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); 325 /* Check the hotspots */ 326 if (hotspotX >= source.width || hotspotX < 0 || 327 hotspotY >= source.height || hotspotY < 0) { 328 SWT.error(SWT.ERROR_INVALID_ARGUMENT); 329 } 330 ImageData mask = source.getTransparencyMask(); 331 int[] result = Image.init(device, null, source, mask); 332 int hBitmap = result[0]; 333 int hMask = result[1]; 334 /* Create the icon */ 335 ICONINFO info = new ICONINFO(); 336 info.fIcon = true; 337 info.hbmColor = hBitmap; 338 info.hbmMask = hMask; 339 handle = OS.CreateIconIndirect(info); 340 if (handle == 0) SWT.error(SWT.ERROR_NO_HANDLES); 341 OS.DeleteObject(hBitmap); 342 OS.DeleteObject(hMask); 343 isIcon = true; 344 if (device.tracking) device.new_Object(this); 345 } 346 347 /** 348 * Disposes of the operating system resources associated with 349 * the cursor. Applications must dispose of all cursors which 350 * they allocate. 351 */ 352 public void dispose () { 353 if (handle == 0) return; 354 if (device.isDisposed()) return; 355 356 /* 357 * It is an error in Windows to destroy the current 358 * cursor. Check that the cursor that is about to 359 * be destroyed is the current cursor. If so, set 360 * the current cursor to be IDC_ARROW. Note that 361 * Windows shares predefined cursors so the call to 362 * LoadCursor() does not leak. 363 */ 364 // TEMPORARY CODE 365 // if (OS.GetCursor() == handle) { 366 // OS.SetCursor(OS.LoadCursor(0, OS.IDC_ARROW)); 367 // } 368 369 if (isIcon) { 370 OS.DestroyIcon(handle); 371 } else { 372 /* 373 * The MSDN states that one should not destroy a shared 374 * cursor, that is, one obtained from LoadCursor. 375 * However, it does not appear to do any harm, so rather 376 * than keep track of how a cursor was created, we just 377 * destroy them all. If this causes problems in the future, 378 * put the flag back in. 379 */ 380 if (!OS.IsWinCE) OS.DestroyCursor(handle); 381 } 382 handle = 0; 383 if (device.tracking) device.dispose_Object(this); 384 device = null; 385 } 386 387 /** 388 * Compares the argument to the receiver, and returns true 389 * if they represent the <em>same</em> object using a class 390 * specific comparison. 391 * 392 * @param object the object to compare with this object 393 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise 394 * 395 * @see #hashCode 396 */ 397 public boolean equals (Object object) { 398 if (object == this) return true; 399 if (!(object instanceof Cursor)) return false; 400 Cursor cursor = (Cursor) object; 401 return device == cursor.device && handle == cursor.handle; 402 } 403 404 /** 405 * Returns an integer hash code for the receiver. Any two 406 * objects which return <code>true</code> when passed to 407 * <code>equals</code> must return the same value for this 408 * method. 409 * 410 * @return the receiver's hash 411 * 412 * @see #equals 413 */ 414 public int hashCode () { 415 return handle; 416 } 417 418 /** 419 * Returns <code>true</code> if the cursor has been disposed, 420 * and <code>false</code> otherwise. 421 * <p> 422 * This method gets the dispose state for the cursor. 423 * When a cursor has been disposed, it is an error to 424 * invoke any other method using the cursor. 425 * 426 * @return <code>true</code> when the cursor is disposed and <code>false</code> otherwise 427 */ 428 public boolean isDisposed() { 429 return handle == 0; 430 } 431 432 /** 433 * Returns a string containing a concise, human-readable 434 * description of the receiver. 435 * 436 * @return a string representation of the receiver 437 */ 438 public String toString () { 439 if (isDisposed()) return "Cursor {*DISPOSED*}"; 440 return "Cursor {" + handle + "}"; 441 } 442 443 /** 444 * Invokes platform specific functionality to allocate a new cursor. 445 * <p> 446 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public 447 * API for <code>Cursor</code>. It is marked public only so that it 448 * can be shared within the packages provided by SWT. It is not 449 * available on all platforms, and should never be called from 450 * application code. 451 * </p> 452 * 453 * @param device the device on which to allocate the color 454 * @param handle the handle for the cursor 455 */ 456 public static Cursor win32_new(Device device, int handle) { 457 if (device == null) device = Device.getDevice(); 458 Cursor cursor = new Cursor(); 459 cursor.handle = handle; 460 cursor.device = device; 461 return cursor; 462 } 463 464 +/ 465 466 } trunk/dwt/graphics/device.d
r4 r19 1 /******************************************************************************* 2 * Copyright (c) 2000, 2003 IBM Corporation and others. 3 * All rights reserved. This program and the accompanying materials 4 * are made available under the terms of the Common Public License v1.0 5 * which accompanies this distribution, and is available at 6 * http://www.eclipse.org/legal/cpl-v10.html 7 * 8 * Contributors: 9 * IBM Corporation - initial API and implementation 10 *******************************************************************************/ 11 12 /****************************************************************************** 13 * DWT : SWT Port for the D Language 14 * 15 * Contributers: 16 * The DWT team at www.dsource.org 17 * 18 * DATE: 2004-04-27 19 ******************************************************************************/ 1 20 2 21 3 module dwt.graphics.device; 22 4 23 // private import dwt.internal.win32; 24 // private import dwt.dwt; 5 /+ 6 import org.eclipse.swt.internal.*; 7 import org.eclipse.swt.internal.win32.*; 8 import org.eclipse.swt.*; 9 +/ 10 private { 11 import dwt.dwt; 12 13 import dwt.graphics.color; 14 import dwt.graphics.IDrawable; 15 import dwt.graphics.devicedata; 16 import dwt.graphics.font; 17 import dwt.graphics.fontdata; 18 import dwt.graphics.rectangle; 19 import dwt.graphics.point; 20 21 import dwt.internal.compatibility; 22 23 import dwt.internal.win32.os; 24 import dwt.internal.win32.logfont; 25 import dwt.internal.win32.textmetric; 26 import dwt.internal.win32.tchar; 27 28 import dwt.utils.runnable; 29 } 30 31 /** 32 * This class is the abstract superclass of all device objects, 33 * such as the Display device and the Printer device. Devices 34 * can have a graphics context (GC) created for them, and they 35 * can be drawn on by sending messages to the associated GC. 36 */ 37 38 /+ TODO: this was an abstract class, but I was having difficulties 39 with no implementations allowed +/ 25 40 26 41 private import dwt.graphics.IDrawable; 27 42 28 // yet another abstract class29 30 43 public class Device : IDrawable { 31 private import dwt.graphics.color; 32 private import dwt.graphics.rectangle; 33 private import dwt.graphics.devicedata; 34 private import dwt.graphics.gcdata; 35 36 public abstract int internal_new_GC (GCData data); 37 public abstract void internal_dispose_GC (int hDC, GCData data); 38 39 } 44 import dwt.graphics.gcdata; 45 46 /* Debugging */ 47 // debug { 48 public const bit DBUG = true; 49 bit dbug = DBUG; 50 bit tracking = DBUG; 51 Error[] errors; 52 Object[] objects; 53 // } 54 55 56 /* Palette 57 * (Warning: This field is platform dependent) 58 */ 59 60 public int hPalette = 0; 61 int[] colorRefCount; 62 63 // System Font 64 int systemFont; 65 66 // Font Enumeration 67 int nFonts = 256; 68 LOGFONT*[] logFonts; 69 70 bit disposed; 71 72 73 74 /* 75 * TEMPORARY CODE. When a graphics object is 76 * created and the device parameter is null, 77 * the current Display is used. This presents 78 * a problem because DWT graphics does not 79 * reference classes in DWT widgets. The correct 80 * fix is to remove this feature. Unfortunately, 81 * too many application programs rely on this 82 * feature. 83 * 84 * This code will be removed in the future. 85 */ 86 protected static Device CurrentDevice; 87 protected static Runnable DeviceFinder; 88 /+ 89 static { 90 try { 91 Class.forName ("org.eclipse.swt.widgets.Display"); 92 } catch (Throwable e) {} 93 } 94 +/ 95 96 /* 97 * TEMPORARY CODE. 98 */ 99 static Device getDevice () { 100 if (DeviceFinder != null) DeviceFinder.run(); 101 Device device = CurrentDevice; 102 CurrentDevice = null; 103 return device; 104 } 105 106 107 /** 108 * Constructs a new instance of this class. 109 * <p> 110 * You must dispose the device when it is no longer required. 111 * </p> 112 * 113 * @param data the DeviceData which describes the receiver 114 * 115 * @see #create 116 * @see #init 117 * @see DeviceData 118 */ 119 120 this() {} 121 122 123 // TODO: not working when class was abstract due to no implementations 124 this(DeviceData data) { 125 126 create(data); 127 128
