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