Mercurial > projects > dwt-win
annotate dwt/graphics/Resource.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 | 684eed7589a0 |
children | 47b37f126740 |
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; | |
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
|
17 //import tango.util.log.Trace; |
14 | 18 |
19 /** | |
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
|
20 * This class is the abstract superclass of all graphics resource objects. |
14 | 21 * Resources created by the application must be disposed. |
22 * <p> | |
23 * IMPORTANT: This class is intended to be subclassed <em>only</em> | |
24 * within the DWT implementation. However, it has not been marked | |
25 * final to allow those outside of the DWT development team to implement | |
26 * patched versions of the class in order to get around specific | |
27 * limitations in advance of when those limitations can be addressed | |
28 * by the team. Any class built using subclassing to access the internals | |
29 * of this class will likely fail to compile or run between releases and | |
30 * may be strongly platform specific. Subclassing should not be attempted | |
31 * without an intimate and detailed understanding of the workings of the | |
32 * hierarchy. No support is provided for user-written classes which are | |
33 * implemented as subclasses of this class. | |
34 * </p> | |
35 * | |
36 * @see #dispose | |
37 * @see #isDisposed | |
246 | 38 * @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
|
39 * |
14 | 40 * @since 3.1 |
41 */ | |
42 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
|
43 |
334
c49e17d48b76
Fix problems at GC run at main()'s end.
Frank Benoit <benoit@tionex.de>
parents:
333
diff
changeset
|
44 /// DWT extension for D: do no dispose check |
c49e17d48b76
Fix problems at GC run at main()'s end.
Frank Benoit <benoit@tionex.de>
parents:
333
diff
changeset
|
45 bool disposeChecking = true; |
c49e17d48b76
Fix problems at GC run at main()'s end.
Frank Benoit <benoit@tionex.de>
parents:
333
diff
changeset
|
46 |
14 | 47 /** |
48 * the device where this resource was created | |
49 */ | |
50 Device device; | |
51 | |
246 | 52 public this() { |
213 | 53 } |
54 | |
55 this(Device device) { | |
56 if (device is null) device = Device.getDevice(); | |
57 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
58 this.device = device; | |
59 } | |
60 | |
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
|
61 ~this(){ |
334
c49e17d48b76
Fix problems at GC run at main()'s end.
Frank Benoit <benoit@tionex.de>
parents:
333
diff
changeset
|
62 if( disposeChecking && !isDisposed() ){ |
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
|
63 //Trace.formatln("{} {} {} Resource deleted, but is not yet disposed", __FILE__, __LINE__, this.classinfo.name ); |
334
c49e17d48b76
Fix problems at GC run at main()'s end.
Frank Benoit <benoit@tionex.de>
parents:
333
diff
changeset
|
64 DWT.error( 0, null, " Resource deleted, but is not yet disposed: (" ~ this.classinfo.name ~ ") " ~ 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
|
65 } |
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
|
66 } |
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
|
67 |
213 | 68 void destroy() { |
69 } | |
70 | |
14 | 71 /** |
72 * Disposes of the operating system resources associated with | |
73 * this resource. Applications must dispose of all resources | |
74 * which they allocate. | |
75 */ | |
213 | 76 public void dispose() { |
77 if (device is null) return; | |
78 if (device.isDisposed()) return; | |
79 destroy(); | |
80 if (device.tracking) device.dispose_Object(this); | |
81 device = null; | |
82 } | |
14 | 83 |
84 /** | |
85 * Returns the <code>Device</code> where this resource was | |
86 * created. | |
87 * | |
88 * @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
|
89 * |
14 | 90 * @since 3.2 |
91 */ | |
92 public Device getDevice() { | |
93 Device device = this.device; | |
94 if (device is null || isDisposed ()) DWT.error (DWT.ERROR_GRAPHIC_DISPOSED); | |
95 return device; | |
96 } | |
97 | |
213 | 98 void init_() { |
99 if (device.tracking) device.new_Object(this); | |
100 } | |
101 | |
14 | 102 /** |
103 * Returns <code>true</code> if the resource has been disposed, | |
104 * and <code>false</code> otherwise. | |
105 * <p> | |
106 * This method gets the dispose state for the resource. | |
107 * When a resource has been disposed, it is an error to | |
108 * invoke any other method using the resource. | |
109 * | |
110 * @return <code>true</code> when the resource is disposed and <code>false</code> otherwise | |
111 */ | |
112 public abstract bool isDisposed(); | |
113 | |
114 } |