Mercurial > projects > dwt-win
annotate dwt/graphics/Resource.d @ 335:47b37f126740
Global flag to disable the dispose checking
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 18 Feb 2009 17:10:51 +0100 |
parents | c49e17d48b76 |
children |
rev | line source |
---|---|
174
f906dbcacee5
Minor changes to be more compatible to dwt-linux, formatting in toString, Display.DEBUG=true
Frank Benoit <benoit@tionex.de>
parents:
14
diff
changeset
|
1 /******************************************************************************* |
246 | 2 * Copyright (c) 2000, 2008 IBM Corporation and others. |
14 | 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 | |
174
f906dbcacee5
Minor changes to be more compatible to dwt-linux, formatting in toString, Display.DEBUG=true
Frank Benoit <benoit@tionex.de>
parents:
14
diff
changeset
|
10 * Port to the D programming language: |
f906dbcacee5
Minor changes to be more compatible to dwt-linux, formatting in toString, Display.DEBUG=true
Frank Benoit <benoit@tionex.de>
parents:
14
diff
changeset
|
11 * Frank Benoit <benoit@tionex.de> |
14 | 12 *******************************************************************************/ |
13 module dwt.graphics.Resource; | |
14 | |
15 import dwt.DWT; | |
16 import dwt.graphics.Device; | |
17 | |
18 /** | |
174
f906dbcacee5
Minor changes to be more compatible to dwt-linux, formatting in toString, Display.DEBUG=true
Frank Benoit <benoit@tionex.de>
parents:
14
diff
changeset
|
19 * This class is the abstract superclass of all graphics resource objects. |
14 | 20 * Resources created by the application must be disposed. |
21 * <p> | |
22 * IMPORTANT: This class is intended to be subclassed <em>only</em> | |
23 * within the DWT implementation. However, it has not been marked | |
24 * final to allow those outside of the DWT development team to implement | |
25 * patched versions of the class in order to get around specific | |
26 * limitations in advance of when those limitations can be addressed | |
27 * by the team. Any class built using subclassing to access the internals | |
28 * of this class will likely fail to compile or run between releases and | |
29 * may be strongly platform specific. Subclassing should not be attempted | |
30 * without an intimate and detailed understanding of the workings of the | |
31 * hierarchy. No support is provided for user-written classes which are | |
32 * implemented as subclasses of this class. | |
33 * </p> | |
34 * | |
35 * @see #dispose | |
36 * @see #isDisposed | |
246 | 37 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> |
174
f906dbcacee5
Minor changes to be more compatible to dwt-linux, formatting in toString, Display.DEBUG=true
Frank Benoit <benoit@tionex.de>
parents:
14
diff
changeset
|
38 * |
14 | 39 * @since 3.1 |
40 */ | |
41 public abstract class Resource { | |
174
f906dbcacee5
Minor changes to be more compatible to dwt-linux, formatting in toString, Display.DEBUG=true
Frank Benoit <benoit@tionex.de>
parents:
14
diff
changeset
|
42 |
334
c49e17d48b76
Fix problems at GC run at main()'s end.
Frank Benoit <benoit@tionex.de>
parents:
333
diff
changeset
|
43 /// DWT extension for D: do no dispose check |
335
47b37f126740
Global flag to disable the dispose checking
Frank Benoit <benoit@tionex.de>
parents:
334
diff
changeset
|
44 public bool disposeChecking = true; |
47b37f126740
Global flag to disable the dispose checking
Frank Benoit <benoit@tionex.de>
parents:
334
diff
changeset
|
45 /// DWT extension for D: do no dispose check |
47b37f126740
Global flag to disable the dispose checking
Frank Benoit <benoit@tionex.de>
parents:
334
diff
changeset
|
46 public static bool globalDisposeChecking = true; |
334
c49e17d48b76
Fix problems at GC run at main()'s end.
Frank Benoit <benoit@tionex.de>
parents:
333
diff
changeset
|
47 |
14 | 48 /** |
49 * the device where this resource was created | |
50 */ | |
51 Device device; | |
52 | |
246 | 53 public this() { |
213 | 54 } |
55 | |
56 this(Device device) { | |
57 if (device is null) device = Device.getDevice(); | |
58 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
59 this.device = device; | |
60 } | |
61 | |
333
684eed7589a0
Generate error if a resource is deleted without disposal. Without that, is is very hard to find accidental deleted/scoped Color/Font/..
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
62 ~this(){ |
335
47b37f126740
Global flag to disable the dispose checking
Frank Benoit <benoit@tionex.de>
parents:
334
diff
changeset
|
63 if( globalDisposeChecking && disposeChecking && !isDisposed() ){ |
47b37f126740
Global flag to disable the dispose checking
Frank Benoit <benoit@tionex.de>
parents:
334
diff
changeset
|
64 DWT.error( 0, null, " Resource deleted, but is not yet disposed. " |
47b37f126740
Global flag to disable the dispose checking
Frank Benoit <benoit@tionex.de>
parents:
334
diff
changeset
|
65 "This check can be disabled with " |
47b37f126740
Global flag to disable the dispose checking
Frank Benoit <benoit@tionex.de>
parents:
334
diff
changeset
|
66 "\"import dwt.graphics.Resource; " |
47b37f126740
Global flag to disable the dispose checking
Frank Benoit <benoit@tionex.de>
parents:
334
diff
changeset
|
67 "Resource.globalDisposeChecking = false; \". " |
47b37f126740
Global flag to disable the dispose checking
Frank Benoit <benoit@tionex.de>
parents:
334
diff
changeset
|
68 "This problem occured with type " ~ this.classinfo.name ~ |
47b37f126740
Global flag to disable the dispose checking
Frank Benoit <benoit@tionex.de>
parents:
334
diff
changeset
|
69 " this.toString()=" ~ this.toString() ); |
333
684eed7589a0
Generate error if a resource is deleted without disposal. Without that, is is very hard to find accidental deleted/scoped Color/Font/..
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
70 } |
684eed7589a0
Generate error if a resource is deleted without disposal. Without that, is is very hard to find accidental deleted/scoped Color/Font/..
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
71 } |
684eed7589a0
Generate error if a resource is deleted without disposal. Without that, is is very hard to find accidental deleted/scoped Color/Font/..
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
72 |
213 | 73 void destroy() { |
74 } | |
75 | |
14 | 76 /** |
77 * Disposes of the operating system resources associated with | |
78 * this resource. Applications must dispose of all resources | |
79 * which they allocate. | |
80 */ | |
213 | 81 public void dispose() { |
82 if (device is null) return; | |
83 if (device.isDisposed()) return; | |
84 destroy(); | |
85 if (device.tracking) device.dispose_Object(this); | |
86 device = null; | |
87 } | |
14 | 88 |
89 /** | |
90 * Returns the <code>Device</code> where this resource was | |
91 * created. | |
92 * | |
93 * @return <code>Device</code> the device of the receiver | |
174
f906dbcacee5
Minor changes to be more compatible to dwt-linux, formatting in toString, Display.DEBUG=true
Frank Benoit <benoit@tionex.de>
parents:
14
diff
changeset
|
94 * |
14 | 95 * @since 3.2 |
96 */ | |
97 public Device getDevice() { | |
98 Device device = this.device; | |
99 if (device is null || isDisposed ()) DWT.error (DWT.ERROR_GRAPHIC_DISPOSED); | |
100 return device; | |
101 } | |
102 | |
213 | 103 void init_() { |
104 if (device.tracking) device.new_Object(this); | |
105 } | |
106 | |
14 | 107 /** |
108 * Returns <code>true</code> if the resource has been disposed, | |
109 * and <code>false</code> otherwise. | |
110 * <p> | |
111 * This method gets the dispose state for the resource. | |
112 * When a resource has been disposed, it is an error to | |
113 * invoke any other method using the resource. | |
114 * | |
115 * @return <code>true</code> when the resource is disposed and <code>false</code> otherwise | |
116 */ | |
117 public abstract bool isDisposed(); | |
118 | |
119 } |