comparison dwt/graphics/Cursor.d @ 213:36f5cb12e1a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Sat, 17 May 2008 17:34:28 +0200
parents ab60f3309436
children fd9c62a2998e
comparison
equal deleted inserted replaced
212:ab60f3309436 213:36f5cb12e1a2
51 * Note: Only one of the above styles may be specified. 51 * Note: Only one of the above styles may be specified.
52 * </p> 52 * </p>
53 */ 53 */
54 54
55 public final class Cursor : Resource { 55 public final class Cursor : Resource {
56
57 alias Resource.init_ init_;
56 58
57 /** 59 /**
58 * the handle to the OS cursor resource 60 * the handle to the OS cursor resource
59 * (Warning: This field is platform dependent) 61 * (Warning: This field is platform dependent)
60 * <p> 62 * <p>
147 ]; 149 ];
148 150
149 /** 151 /**
150 * Prevents uninitialized instances from being created outside the package. 152 * Prevents uninitialized instances from being created outside the package.
151 */ 153 */
152 this() { 154 this(Device device) {
155 super(device);
153 } 156 }
154 157
155 /** 158 /**
156 * Constructs a new cursor given a device and a style 159 * Constructs a new cursor given a device and a style
157 * constant describing the desired cursor appearance. 160 * constant describing the desired cursor appearance.
192 * @see DWT#CURSOR_IBEAM 195 * @see DWT#CURSOR_IBEAM
193 * @see DWT#CURSOR_NO 196 * @see DWT#CURSOR_NO
194 * @see DWT#CURSOR_HAND 197 * @see DWT#CURSOR_HAND
195 */ 198 */
196 public this(Device device, int style) { 199 public this(Device device, int style) {
197 if (device is null) device = Device.getDevice(); 200 super(device);
198 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 201 int /*long*/ lpCursorName = 0;
199 this.device = device;
200 int lpCursorName = 0;
201 switch (style) { 202 switch (style) {
202 case DWT.CURSOR_HAND: lpCursorName = OS.IDC_HAND; break; 203 case DWT.CURSOR_HAND: lpCursorName = OS.IDC_HAND; break;
203 case DWT.CURSOR_ARROW: lpCursorName = OS.IDC_ARROW; break; 204 case DWT.CURSOR_ARROW: lpCursorName = OS.IDC_ARROW; break;
204 case DWT.CURSOR_WAIT: lpCursorName = OS.IDC_WAIT; break; 205 case DWT.CURSOR_WAIT: lpCursorName = OS.IDC_WAIT; break;
205 case DWT.CURSOR_CROSS: lpCursorName = OS.IDC_CROSS; break; 206 case DWT.CURSOR_CROSS: lpCursorName = OS.IDC_CROSS; break;
238 handle = OS.CreateCursor(hInst, 5, 0, 32, 32, HAND_SOURCE.ptr, HAND_MASK.ptr); 239 handle = OS.CreateCursor(hInst, 5, 0, 32, 32, HAND_SOURCE.ptr, HAND_MASK.ptr);
239 240
240 } 241 }
241 } 242 }
242 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); 243 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES);
243 if (device.tracking) device.new_Object(this); 244 init_();
244 } 245 }
245 246
246 /** 247 /**
247 * Constructs a new cursor given a device, image and mask 248 * Constructs a new cursor given a device, image and mask
248 * data describing the desired cursor appearance, and the x 249 * data describing the desired cursor appearance, and the x
273 * @exception DWTError <ul> 274 * @exception DWTError <ul>
274 * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li> 275 * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li>
275 * </ul> 276 * </ul>
276 */ 277 */
277 public this(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) { 278 public this(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) {
278 if (device is null) device = Device.getDevice(); 279 super(device);
279 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
280 this.device = device;
281 if (source is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 280 if (source is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
282 if (mask is null) { 281 if (mask is null) {
283 if (source.getTransparencyType() !is DWT.TRANSPARENCY_MASK) { 282 if (source.getTransparencyType() !is DWT.TRANSPARENCY_MASK) {
284 DWT.error(DWT.ERROR_NULL_ARGUMENT); 283 DWT.error(DWT.ERROR_NULL_ARGUMENT);
285 } 284 }
305 /* Create the cursor */ 304 /* Create the cursor */
306 auto hInst = OS.GetModuleHandle(null); 305 auto hInst = OS.GetModuleHandle(null);
307 static if (OS.IsWinCE) DWT.error (DWT.ERROR_NOT_IMPLEMENTED); 306 static if (OS.IsWinCE) DWT.error (DWT.ERROR_NOT_IMPLEMENTED);
308 handle = OS.CreateCursor(hInst, hotspotX, hotspotY, source.width, source.height, sourceData.ptr, maskData.ptr); 307 handle = OS.CreateCursor(hInst, hotspotX, hotspotY, source.width, source.height, sourceData.ptr, maskData.ptr);
309 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); 308 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES);
310 if (device.tracking) device.new_Object(this); 309 init_();
311 } 310 }
312 311
313 /** 312 /**
314 * Constructs a new cursor given a device, image data describing 313 * Constructs a new cursor given a device, image data describing
315 * the desired cursor appearance, and the x and y coordinates of 314 * the desired cursor appearance, and the x and y coordinates of
336 * </ul> 335 * </ul>
337 * 336 *
338 * @since 3.0 337 * @since 3.0
339 */ 338 */
340 public this(Device device, ImageData source, int hotspotX, int hotspotY) { 339 public this(Device device, ImageData source, int hotspotX, int hotspotY) {
341 if (device is null) device = Device.getDevice(); 340 super(device);
342 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
343 this.device = device;
344 if (source is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 341 if (source is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
345 /* Check the hotspots */ 342 /* Check the hotspots */
346 if (hotspotX >= source.width || hotspotX < 0 || 343 if (hotspotX >= source.width || hotspotX < 0 ||
347 hotspotY >= source.height || hotspotY < 0) { 344 hotspotY >= source.height || hotspotY < 0) {
348 DWT.error(DWT.ERROR_INVALID_ARGUMENT); 345 DWT.error(DWT.ERROR_INVALID_ARGUMENT);
349 } 346 }
350 ImageData mask = source.getTransparencyMask(); 347 ImageData mask = source.getTransparencyMask();
351 int[] result = Image.init_(device, null, source, mask); 348 int[] result = Image.init_(this.device, null, source, mask);
352 auto hBitmap = cast(HBITMAP)result[0]; 349 auto hBitmap = cast(HBITMAP)result[0];
353 auto hMask = cast(HBITMAP)result[1]; 350 auto hMask = cast(HBITMAP)result[1];
354 /* Create the icon */ 351 /* Create the icon */
355 ICONINFO info; 352 ICONINFO info;
356 info.fIcon = false; 353 info.fIcon = false;
361 handle = OS.CreateIconIndirect(&info); 358 handle = OS.CreateIconIndirect(&info);
362 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); 359 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES);
363 OS.DeleteObject(hBitmap); 360 OS.DeleteObject(hBitmap);
364 OS.DeleteObject(hMask); 361 OS.DeleteObject(hMask);
365 isIcon = true; 362 isIcon = true;
366 if (device.tracking) device.new_Object(this); 363 init_();
367 } 364 }
368 365
369 /** 366 void destroy () {
370 * Disposes of the operating system resources associated with
371 * the cursor. Applications must dispose of all cursors which
372 * they allocate.
373 */
374 override public void dispose () {
375 if (handle is null) return;
376 if (device.isDisposed()) return;
377
378 /* 367 /*
379 * It is an error in Windows to destroy the current 368 * It is an error in Windows to destroy the current
380 * cursor. Check that the cursor that is about to 369 * cursor. Check that the cursor that is about to
381 * be destroyed is the current cursor. If so, set 370 * be destroyed is the current cursor. If so, set
382 * the current cursor to be IDC_ARROW. Note that 371 * the current cursor to be IDC_ARROW. Note that
400 * put the flag back in. 389 * put the flag back in.
401 */ 390 */
402 static if (!OS.IsWinCE) OS.DestroyCursor(handle); 391 static if (!OS.IsWinCE) OS.DestroyCursor(handle);
403 } 392 }
404 handle = null; 393 handle = null;
405 if (device.tracking) device.dispose_Object(this);
406 device = null;
407 } 394 }
408 395
409 /** 396 /**
410 * Compares the argument to the receiver, and returns true 397 * Compares the argument to the receiver, and returns true
411 * if they represent the <em>same</em> object using a class 398 * if they represent the <em>same</em> object using a class
475 * @param device the device on which to allocate the color 462 * @param device the device on which to allocate the color
476 * @param handle the handle for the cursor 463 * @param handle the handle for the cursor
477 * @return a new cursor object containing the specified device and handle 464 * @return a new cursor object containing the specified device and handle
478 */ 465 */
479 public static Cursor win32_new(Device device, HCURSOR handle) { 466 public static Cursor win32_new(Device device, HCURSOR handle) {
480 if (device is null) device = Device.getDevice(); 467 Cursor cursor = new Cursor(device);
481 Cursor cursor = new Cursor();
482 cursor.handle = handle; 468 cursor.handle = handle;
483 cursor.device = device;
484 return cursor; 469 return cursor;
485 } 470 }
486 471
487 } 472 }