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