Mercurial > projects > dwt-win
annotate 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 |
rev | line source |
---|---|
28 | 1 /******************************************************************************* |
2 * Copyright (c) 2000, 2005 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
175 | 10 * Port to the D programming language: |
11 * Frank Benoit <benoit@tionex.de> | |
28 | 12 *******************************************************************************/ |
13 module dwt.graphics.Cursor; | |
14 | |
15 | |
16 import dwt.DWT; | |
17 import dwt.DWTError; | |
18 import dwt.internal.win32.OS; | |
19 | |
20 import dwt.graphics.Resource; | |
21 import dwt.graphics.Device; | |
22 import dwt.graphics.ImageData; | |
23 import dwt.graphics.RGB; | |
24 import dwt.graphics.PaletteData; | |
25 import dwt.graphics.Image; | |
26 | |
27 import tango.text.convert.Format; | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
28 import dwt.dwthelper.utils; |
28 | 29 |
30 /** | |
31 * Instances of this class manage operating system resources that | |
32 * specify the appearance of the on-screen pointer. To create a | |
33 * cursor you specify the device and either a simple cursor style | |
34 * describing one of the standard operating system provided cursors | |
35 * or the image and mask data for the desired appearance. | |
36 * <p> | |
37 * Application code must explicitly invoke the <code>Cursor.dispose()</code> | |
38 * method to release the operating system resources managed by each instance | |
39 * when those instances are no longer required. | |
40 * </p> | |
41 * <dl> | |
42 * <dt><b>Styles:</b></dt> | |
43 * <dd> | |
44 * CURSOR_ARROW, CURSOR_WAIT, CURSOR_CROSS, CURSOR_APPSTARTING, CURSOR_HELP, | |
45 * CURSOR_SIZEALL, CURSOR_SIZENESW, CURSOR_SIZENS, CURSOR_SIZENWSE, CURSOR_SIZEWE, | |
46 * CURSOR_SIZEN, CURSOR_SIZES, CURSOR_SIZEE, CURSOR_SIZEW, CURSOR_SIZENE, CURSOR_SIZESE, | |
47 * CURSOR_SIZESW, CURSOR_SIZENW, CURSOR_UPARROW, CURSOR_IBEAM, CURSOR_NO, CURSOR_HAND | |
48 * </dd> | |
49 * </dl> | |
50 * <p> | |
51 * Note: Only one of the above styles may be specified. | |
52 * </p> | |
53 */ | |
54 | |
55 public final class Cursor : Resource { | |
56 | |
213 | 57 alias Resource.init_ init_; |
58 | |
28 | 59 /** |
60 * the handle to the OS cursor resource | |
61 * (Warning: This field is platform dependent) | |
62 * <p> | |
63 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT | |
64 * public API. It is marked public only so that it can be shared | |
65 * within the packages provided by DWT. It is not available on all | |
66 * platforms and should never be accessed from application code. | |
67 * </p> | |
68 */ | |
69 public HCURSOR handle; | |
70 | |
71 bool isIcon; | |
72 | |
73 /** | |
74 * data used to create a HAND cursor. | |
75 */ | |
76 static const byte[] HAND_SOURCE = [ | |
77 cast(byte)0xf9,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
78 cast(byte)0xf0,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
79 cast(byte)0xf0,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
80 cast(byte)0xf0,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
81 cast(byte)0xf0,cast(byte)0x3f,cast(byte)0xff,cast(byte)0xff, | |
82 cast(byte)0xf0,cast(byte)0x07,cast(byte)0xff,cast(byte)0xff, | |
83 cast(byte)0xf0,cast(byte)0x03,cast(byte)0xff,cast(byte)0xff, | |
84 cast(byte)0xf0,cast(byte)0x00,cast(byte)0xff,cast(byte)0xff, | |
85 | |
86 cast(byte)0x10,cast(byte)0x00,cast(byte)0x7f,cast(byte)0xff, | |
87 cast(byte)0x00,cast(byte)0x00,cast(byte)0x7f,cast(byte)0xff, | |
88 cast(byte)0x80,cast(byte)0x00,cast(byte)0x7f,cast(byte)0xff, | |
89 cast(byte)0xc0,cast(byte)0x00,cast(byte)0x7f,cast(byte)0xff, | |
90 cast(byte)0xe0,cast(byte)0x00,cast(byte)0x7f,cast(byte)0xff, | |
91 cast(byte)0xf0,cast(byte)0x00,cast(byte)0x7f,cast(byte)0xff, | |
92 cast(byte)0xf8,cast(byte)0x00,cast(byte)0xff,cast(byte)0xff, | |
93 cast(byte)0xfc,cast(byte)0x01,cast(byte)0xff,cast(byte)0xff, | |
94 | |
95 cast(byte)0xff,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
96 cast(byte)0xff,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
97 cast(byte)0xff,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
98 cast(byte)0xff,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
99 cast(byte)0xff,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
100 cast(byte)0xff,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
101 cast(byte)0xff,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
102 cast(byte)0xff,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
103 | |
104 cast(byte)0xff,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
105 cast(byte)0xff,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
106 cast(byte)0xff,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
107 cast(byte)0xff,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
108 cast(byte)0xff,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
109 cast(byte)0xff,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
110 cast(byte)0xff,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff, | |
111 cast(byte)0xff,cast(byte)0xff,cast(byte)0xff,cast(byte)0xff | |
112 ]; | |
113 static const byte[] HAND_MASK = [ | |
114 cast(byte)0x00,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
115 cast(byte)0x06,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
116 cast(byte)0x06,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
117 cast(byte)0x06,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
118 cast(byte)0x06,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
119 cast(byte)0x06,cast(byte)0xc0,cast(byte)0x00,cast(byte)0x00, | |
120 cast(byte)0x06,cast(byte)0xd8,cast(byte)0x00,cast(byte)0x00, | |
121 cast(byte)0x06,cast(byte)0xd8,cast(byte)0x00,cast(byte)0x00, | |
122 | |
123 cast(byte)0x07,cast(byte)0xdb,cast(byte)0x00,cast(byte)0x00, | |
124 cast(byte)0x67,cast(byte)0xfb,cast(byte)0x00,cast(byte)0x00, | |
125 cast(byte)0x3f,cast(byte)0xff,cast(byte)0x00,cast(byte)0x00, | |
126 cast(byte)0x1f,cast(byte)0xff,cast(byte)0x00,cast(byte)0x00, | |
127 cast(byte)0x0f,cast(byte)0xff,cast(byte)0x00,cast(byte)0x00, | |
128 cast(byte)0x07,cast(byte)0xff,cast(byte)0x00,cast(byte)0x00, | |
129 cast(byte)0x03,cast(byte)0xfe,cast(byte)0x00,cast(byte)0x00, | |
130 cast(byte)0x00,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
131 | |
132 cast(byte)0x00,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
133 cast(byte)0x00,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
134 cast(byte)0x00,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
135 cast(byte)0x00,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
136 cast(byte)0x00,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
137 cast(byte)0x00,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
138 cast(byte)0x00,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
139 cast(byte)0x00,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
140 | |
141 cast(byte)0x00,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
142 cast(byte)0x00,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
143 cast(byte)0x00,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
144 cast(byte)0x00,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
145 cast(byte)0x00,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
146 cast(byte)0x00,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
147 cast(byte)0x00,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00, | |
148 cast(byte)0x00,cast(byte)0x00,cast(byte)0x00,cast(byte)0x00 | |
149 ]; | |
150 | |
151 /** | |
152 * Prevents uninitialized instances from being created outside the package. | |
153 */ | |
213 | 154 this(Device device) { |
155 super(device); | |
28 | 156 } |
157 | |
158 /** | |
159 * Constructs a new cursor given a device and a style | |
160 * constant describing the desired cursor appearance. | |
161 * <p> | |
162 * You must dispose the cursor when it is no longer required. | |
163 * </p> | |
164 * | |
165 * @param device the device on which to allocate the cursor | |
166 * @param style the style of cursor to allocate | |
167 * | |
168 * @exception IllegalArgumentException <ul> | |
169 * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> | |
170 * <li>ERROR_INVALID_ARGUMENT - when an unknown style is specified</li> | |
171 * </ul> | |
172 * @exception DWTError <ul> | |
173 * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li> | |
174 * </ul> | |
175 * | |
176 * @see DWT#CURSOR_ARROW | |
177 * @see DWT#CURSOR_WAIT | |
178 * @see DWT#CURSOR_CROSS | |
179 * @see DWT#CURSOR_APPSTARTING | |
180 * @see DWT#CURSOR_HELP | |
181 * @see DWT#CURSOR_SIZEALL | |
182 * @see DWT#CURSOR_SIZENESW | |
183 * @see DWT#CURSOR_SIZENS | |
184 * @see DWT#CURSOR_SIZENWSE | |
185 * @see DWT#CURSOR_SIZEWE | |
186 * @see DWT#CURSOR_SIZEN | |
187 * @see DWT#CURSOR_SIZES | |
188 * @see DWT#CURSOR_SIZEE | |
189 * @see DWT#CURSOR_SIZEW | |
190 * @see DWT#CURSOR_SIZENE | |
191 * @see DWT#CURSOR_SIZESE | |
192 * @see DWT#CURSOR_SIZESW | |
193 * @see DWT#CURSOR_SIZENW | |
194 * @see DWT#CURSOR_UPARROW | |
195 * @see DWT#CURSOR_IBEAM | |
196 * @see DWT#CURSOR_NO | |
197 * @see DWT#CURSOR_HAND | |
198 */ | |
199 public this(Device device, int style) { | |
213 | 200 super(device); |
201 int /*long*/ lpCursorName = 0; | |
28 | 202 switch (style) { |
203 case DWT.CURSOR_HAND: lpCursorName = OS.IDC_HAND; break; | |
204 case DWT.CURSOR_ARROW: lpCursorName = OS.IDC_ARROW; break; | |
205 case DWT.CURSOR_WAIT: lpCursorName = OS.IDC_WAIT; break; | |
206 case DWT.CURSOR_CROSS: lpCursorName = OS.IDC_CROSS; break; | |
207 case DWT.CURSOR_APPSTARTING: lpCursorName = OS.IDC_APPSTARTING; break; | |
208 case DWT.CURSOR_HELP: lpCursorName = OS.IDC_HELP; break; | |
209 case DWT.CURSOR_SIZEALL: lpCursorName = OS.IDC_SIZEALL; break; | |
210 case DWT.CURSOR_SIZENESW: lpCursorName = OS.IDC_SIZENESW; break; | |
211 case DWT.CURSOR_SIZENS: lpCursorName = OS.IDC_SIZENS; break; | |
212 case DWT.CURSOR_SIZENWSE: lpCursorName = OS.IDC_SIZENWSE; break; | |
213 case DWT.CURSOR_SIZEWE: lpCursorName = OS.IDC_SIZEWE; break; | |
214 case DWT.CURSOR_SIZEN: lpCursorName = OS.IDC_SIZENS; break; | |
215 case DWT.CURSOR_SIZES: lpCursorName = OS.IDC_SIZENS; break; | |
216 case DWT.CURSOR_SIZEE: lpCursorName = OS.IDC_SIZEWE; break; | |
217 case DWT.CURSOR_SIZEW: lpCursorName = OS.IDC_SIZEWE; break; | |
218 case DWT.CURSOR_SIZENE: lpCursorName = OS.IDC_SIZENESW; break; | |
219 case DWT.CURSOR_SIZESE: lpCursorName = OS.IDC_SIZENWSE; break; | |
220 case DWT.CURSOR_SIZESW: lpCursorName = OS.IDC_SIZENESW; break; | |
221 case DWT.CURSOR_SIZENW: lpCursorName = OS.IDC_SIZENWSE; break; | |
222 case DWT.CURSOR_UPARROW: lpCursorName = OS.IDC_UPARROW; break; | |
223 case DWT.CURSOR_IBEAM: lpCursorName = OS.IDC_IBEAM; break; | |
224 case DWT.CURSOR_NO: lpCursorName = OS.IDC_NO; break; | |
225 default: | |
226 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
227 } | |
228 handle = OS.LoadCursor(null, cast(wchar*)lpCursorName); | |
229 /* | |
230 * IDC_HAND is supported only on Windows 2000 and Windows 98. | |
231 * Create a hand cursor if running in other Windows platforms. | |
232 */ | |
233 if (handle is null && style is DWT.CURSOR_HAND) { | |
234 int width = OS.GetSystemMetrics(OS.SM_CXCURSOR); | |
235 int height = OS.GetSystemMetrics(OS.SM_CYCURSOR); | |
236 if (width is 32 && height is 32) { | |
237 auto hInst = OS.GetModuleHandle(null); | |
117 | 238 static if (OS.IsWinCE) DWT.error(DWT.ERROR_NOT_IMPLEMENTED); |
28 | 239 handle = OS.CreateCursor(hInst, 5, 0, 32, 32, HAND_SOURCE.ptr, HAND_MASK.ptr); |
240 | |
241 } | |
242 } | |
243 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); | |
213 | 244 init_(); |
28 | 245 } |
246 | |
247 /** | |
248 * Constructs a new cursor given a device, image and mask | |
249 * data describing the desired cursor appearance, and the x | |
250 * and y coordinates of the <em>hotspot</em> (that is, the point | |
251 * within the area covered by the cursor which is considered | |
252 * to be where the on-screen pointer is "pointing"). | |
253 * <p> | |
254 * The mask data is allowed to be null, but in this case the source | |
255 * must be an ImageData representing an icon that specifies both | |
256 * color data and mask data. | |
257 * <p> | |
258 * You must dispose the cursor when it is no longer required. | |
259 * </p> | |
260 * | |
261 * @param device the device on which to allocate the cursor | |
262 * @param source the color data for the cursor | |
263 * @param mask the mask data for the cursor (or null) | |
264 * @param hotspotX the x coordinate of the cursor's hotspot | |
265 * @param hotspotY the y coordinate of the cursor's hotspot | |
266 * | |
267 * @exception IllegalArgumentException <ul> | |
268 * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> | |
269 * <li>ERROR_NULL_ARGUMENT - if the source is null</li> | |
270 * <li>ERROR_NULL_ARGUMENT - if the mask is null and the source does not have a mask</li> | |
271 * <li>ERROR_INVALID_ARGUMENT - if the source and the mask are not the same | |
272 * size, or if the hotspot is outside the bounds of the image</li> | |
273 * </ul> | |
274 * @exception DWTError <ul> | |
275 * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li> | |
276 * </ul> | |
277 */ | |
278 public this(Device device, ImageData source, ImageData mask, int hotspotX, int hotspotY) { | |
213 | 279 super(device); |
28 | 280 if (source is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
281 if (mask is null) { | |
282 if (source.getTransparencyType() !is DWT.TRANSPARENCY_MASK) { | |
283 DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
284 } | |
285 mask = source.getTransparencyMask(); | |
286 } | |
287 /* Check the bounds. Mask must be the same size as source */ | |
288 if (mask.width !is source.width || mask.height !is source.height) { | |
289 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
290 } | |
291 /* Check the hotspots */ | |
292 if (hotspotX >= source.width || hotspotX < 0 || | |
293 hotspotY >= source.height || hotspotY < 0) { | |
294 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
295 } | |
296 /* Convert depth to 1 */ | |
297 mask = ImageData.convertMask(mask); | |
298 source = ImageData.convertMask(source); | |
299 | |
300 /* Make sure source and mask scanline pad is 2 */ | |
301 byte[] sourceData = ImageData.convertPad(source.data, source.width, source.height, source.depth, source.scanlinePad, 2); | |
302 byte[] maskData = ImageData.convertPad(mask.data, mask.width, mask.height, mask.depth, mask.scanlinePad, 2); | |
303 | |
304 /* Create the cursor */ | |
305 auto hInst = OS.GetModuleHandle(null); | |
117 | 306 static if (OS.IsWinCE) DWT.error (DWT.ERROR_NOT_IMPLEMENTED); |
28 | 307 handle = OS.CreateCursor(hInst, hotspotX, hotspotY, source.width, source.height, sourceData.ptr, maskData.ptr); |
308 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); | |
213 | 309 init_(); |
28 | 310 } |
311 | |
312 /** | |
313 * Constructs a new cursor given a device, image data describing | |
314 * the desired cursor appearance, and the x and y coordinates of | |
315 * the <em>hotspot</em> (that is, the point within the area | |
316 * covered by the cursor which is considered to be where the | |
317 * on-screen pointer is "pointing"). | |
318 * <p> | |
319 * You must dispose the cursor when it is no longer required. | |
320 * </p> | |
321 * | |
322 * @param device the device on which to allocate the cursor | |
323 * @param source the image data for the cursor | |
324 * @param hotspotX the x coordinate of the cursor's hotspot | |
325 * @param hotspotY the y coordinate of the cursor's hotspot | |
326 * | |
327 * @exception IllegalArgumentException <ul> | |
328 * <li>ERROR_NULL_ARGUMENT - if device is null and there is no current device</li> | |
329 * <li>ERROR_NULL_ARGUMENT - if the image is null</li> | |
330 * <li>ERROR_INVALID_ARGUMENT - if the hotspot is outside the bounds of the | |
331 * image</li> | |
332 * </ul> | |
333 * @exception DWTError <ul> | |
334 * <li>ERROR_NO_HANDLES - if a handle could not be obtained for cursor creation</li> | |
335 * </ul> | |
336 * | |
337 * @since 3.0 | |
338 */ | |
339 public this(Device device, ImageData source, int hotspotX, int hotspotY) { | |
213 | 340 super(device); |
28 | 341 if (source is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
342 /* Check the hotspots */ | |
343 if (hotspotX >= source.width || hotspotX < 0 || | |
344 hotspotY >= source.height || hotspotY < 0) { | |
345 DWT.error(DWT.ERROR_INVALID_ARGUMENT); | |
346 } | |
347 ImageData mask = source.getTransparencyMask(); | |
213 | 348 int[] result = Image.init_(this.device, null, source, mask); |
28 | 349 auto hBitmap = cast(HBITMAP)result[0]; |
350 auto hMask = cast(HBITMAP)result[1]; | |
351 /* Create the icon */ | |
352 ICONINFO info; | |
353 info.fIcon = false; | |
354 info.hbmColor = hBitmap; | |
355 info.hbmMask = hMask; | |
356 info.xHotspot = hotspotX; | |
357 info.yHotspot = hotspotY; | |
358 handle = OS.CreateIconIndirect(&info); | |
359 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); | |
360 OS.DeleteObject(hBitmap); | |
361 OS.DeleteObject(hMask); | |
362 isIcon = true; | |
213 | 363 init_(); |
28 | 364 } |
365 | |
213 | 366 void destroy () { |
28 | 367 /* |
368 * It is an error in Windows to destroy the current | |
369 * cursor. Check that the cursor that is about to | |
370 * be destroyed is the current cursor. If so, set | |
371 * the current cursor to be IDC_ARROW. Note that | |
372 * Windows shares predefined cursors so the call to | |
373 * LoadCursor() does not leak. | |
374 */ | |
375 // TEMPORARY CODE | |
376 // if (OS.GetCursor() is handle) { | |
377 // OS.SetCursor(OS.LoadCursor(0, OS.IDC_ARROW)); | |
378 // } | |
379 | |
380 if (isIcon) { | |
381 OS.DestroyIcon(handle); | |
382 } else { | |
383 /* | |
384 * The MSDN states that one should not destroy a shared | |
385 * cursor, that is, one obtained from LoadCursor. | |
386 * However, it does not appear to do any harm, so rather | |
387 * than keep track of how a cursor was created, we just | |
388 * destroy them all. If this causes problems in the future, | |
389 * put the flag back in. | |
390 */ | |
117 | 391 static if (!OS.IsWinCE) OS.DestroyCursor(handle); |
28 | 392 } |
393 handle = null; | |
394 } | |
395 | |
396 /** | |
397 * Compares the argument to the receiver, and returns true | |
398 * if they represent the <em>same</em> object using a class | |
399 * specific comparison. | |
400 * | |
401 * @param object the object to compare with this object | |
402 * @return <code>true</code> if the object is the same as this object and <code>false</code> otherwise | |
403 * | |
404 * @see #hashCode | |
405 */ | |
406 public override int opEquals (Object object) { | |
407 if (object is this) return true; | |
408 if (!(cast(Cursor)object)) return false; | |
409 Cursor cursor = cast(Cursor) object; | |
410 return device is cursor.device && handle is cursor.handle; | |
411 } | |
412 | |
413 /** | |
414 * Returns an integer hash code for the receiver. Any two | |
415 * objects that return <code>true</code> when passed to | |
416 * <code>equals</code> must return the same value for this | |
417 * method. | |
418 * | |
419 * @return the receiver's hash | |
420 * | |
421 * @see #equals | |
422 */ | |
423 public override hash_t toHash () { | |
424 return cast(hash_t)handle; | |
425 } | |
426 | |
427 /** | |
428 * Returns <code>true</code> if the cursor has been disposed, | |
429 * and <code>false</code> otherwise. | |
430 * <p> | |
431 * This method gets the dispose state for the cursor. | |
432 * When a cursor has been disposed, it is an error to | |
433 * invoke any other method using the cursor. | |
434 * | |
435 * @return <code>true</code> when the cursor is disposed and <code>false</code> otherwise | |
436 */ | |
48
9a64a7781bab
Added override and alias, first chunk. Thanks torhu for doing this patch.
Frank Benoit <benoit@tionex.de>
parents:
28
diff
changeset
|
437 override public bool isDisposed() { |
28 | 438 return handle is null; |
439 } | |
440 | |
441 /** | |
442 * Returns a string containing a concise, human-readable | |
443 * description of the receiver. | |
444 * | |
445 * @return a string representation of the receiver | |
446 */ | |
212
ab60f3309436
reverted the char[] to String and use the an alias.
Frank Benoit <benoit@tionex.de>
parents:
197
diff
changeset
|
447 override public String toString () { |
28 | 448 if (isDisposed()) return "Cursor {*DISPOSED*}"; |
449 return Format( "Cursor {{{}}", handle ); | |
450 } | |
451 | |
452 /** | |
453 * Invokes platform specific functionality to allocate a new cursor. | |
454 * <p> | |
455 * <b>IMPORTANT:</b> This method is <em>not</em> part of the public | |
456 * API for <code>Cursor</code>. It is marked public only so that it | |
457 * can be shared within the packages provided by DWT. It is not | |
458 * available on all platforms, and should never be called from | |
459 * application code. | |
460 * </p> | |
461 * | |
462 * @param device the device on which to allocate the color | |
463 * @param handle the handle for the cursor | |
464 * @return a new cursor object containing the specified device and handle | |
465 */ | |
466 public static Cursor win32_new(Device device, HCURSOR handle) { | |
213 | 467 Cursor cursor = new Cursor(device); |
28 | 468 cursor.handle = handle; |
469 return cursor; | |
470 } | |
471 | |
472 } |