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