changeset 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
files dwt/graphics/Color.d dwt/graphics/Cursor.d dwt/graphics/Font.d dwt/graphics/GC.d dwt/graphics/Image.d dwt/graphics/Region.d dwt/graphics/Resource.d
diffstat 7 files changed, 23 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/graphics/Color.d	Tue Feb 10 17:14:24 2009 +0100
+++ b/dwt/graphics/Color.d	Wed Feb 18 16:14:31 2009 +0100
@@ -332,6 +332,7 @@
  */
 public static Color win32_new(Device device, int handle) {
     Color color = new Color(device);
+    color.disposeChecking = false;
     color.handle = handle;
     return color;
 }
--- a/dwt/graphics/Cursor.d	Tue Feb 10 17:14:24 2009 +0100
+++ b/dwt/graphics/Cursor.d	Wed Feb 18 16:14:31 2009 +0100
@@ -468,6 +468,7 @@
  */
 public static Cursor win32_new(Device device, HCURSOR handle) {
     Cursor cursor = new Cursor(device);
+    cursor.disposeChecking = false;
     cursor.handle = handle;
     return cursor;
 }
--- a/dwt/graphics/Font.d	Tue Feb 10 17:14:24 2009 +0100
+++ b/dwt/graphics/Font.d	Wed Feb 18 16:14:31 2009 +0100
@@ -12,7 +12,6 @@
  *******************************************************************************/
 module dwt.graphics.Font;
 
-
 import dwt.DWT;
 import dwt.DWTError;
 import dwt.DWTException;
@@ -195,9 +194,9 @@
  */
 public FontData[] getFontData() {
     if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED);
-    LOGFONT* logFont = new LOGFONT();
-    OS.GetObject(handle, LOGFONT.sizeof, logFont);
-    return [ cast(FontData) FontData.win32_new(logFont, device.computePoints(logFont, handle))];
+    LOGFONT logFont;
+    OS.GetObject(handle, LOGFONT.sizeof, &logFont);
+    return [ cast(FontData) FontData.win32_new(&logFont, device.computePoints(&logFont, handle))];
 }
 
 /**
@@ -247,6 +246,12 @@
 override public String toString () {
     if (isDisposed()) return "Font {*DISPOSED*}";
     return Format( "Font {{{}}", handle );
+//
+//    LOGFONT logFont;
+//    OS.GetObject(handle, LOGFONT.sizeof, &logFont);
+//    char[] name = .TCHARzToStr( logFont.lfFaceName.ptr, -1 );
+//
+//    return Format( "Font {{{}, {}}", handle, name );
 }
 
 /**
@@ -265,6 +270,7 @@
  */
 public static Font win32_new(Device device, HFONT handle) {
     Font font = new Font(device);
+    font.disposeChecking = false;
     font.handle = handle;
     return font;
 }
--- a/dwt/graphics/GC.d	Tue Feb 10 17:14:24 2009 +0100
+++ b/dwt/graphics/GC.d	Wed Feb 18 16:14:31 2009 +0100
@@ -4893,6 +4893,7 @@
 public static GC win32_new(Drawable drawable, GCData data) {
     GC gc = new GC();
     auto hDC = drawable.internal_new_GC(data);
+    gc.disposeChecking = false;
     gc.device = data.device;
     gc.init_(drawable, data, hDC);
     return gc;
@@ -4915,6 +4916,7 @@
  */
 public static GC win32_new(HDC hDC, GCData data) {
     GC gc = new GC();
+    gc.disposeChecking = false;
     gc.device = data.device;
     data.style |= DWT.LEFT_TO_RIGHT;
     if (OS.WIN32_VERSION >= OS.VERSION (4, 10)) {
--- a/dwt/graphics/Image.d	Tue Feb 10 17:14:24 2009 +0100
+++ b/dwt/graphics/Image.d	Wed Feb 18 16:14:31 2009 +0100
@@ -2152,6 +2152,7 @@
  */
 public static Image win32_new(Device device, int type, HGDIOBJ handle) {
     Image image = new Image(device);
+    image.disposeChecking = false;
     image.type = type;
     image.handle = handle;
     return image;
--- a/dwt/graphics/Region.d	Tue Feb 10 17:14:24 2009 +0100
+++ b/dwt/graphics/Region.d	Wed Feb 18 16:14:31 2009 +0100
@@ -604,7 +604,9 @@
  * @return a new region object containing the specified device and handle
  */
 public static Region win32_new(Device device, HRGN handle) {
-    return new Region(device, handle);
+    auto region = new Region(device, handle);
+    region.disposeChecking = false;
+    return region;
 }
 
 }
--- a/dwt/graphics/Resource.d	Tue Feb 10 17:14:24 2009 +0100
+++ b/dwt/graphics/Resource.d	Wed Feb 18 16:14:31 2009 +0100
@@ -41,6 +41,9 @@
  */
 public abstract class Resource {
 
+    /// DWT extension for D: do no dispose check
+    bool disposeChecking = true;
+
     /**
      * the device where this resource was created
      */
@@ -56,9 +59,9 @@
 }
 
 ~this(){
-    if( !isDisposed ){
+    if( disposeChecking && !isDisposed() ){
         //Trace.formatln("{} {} {} Resource deleted, but is not yet disposed", __FILE__, __LINE__, this.classinfo.name );
-        DWT.error( 0, null, " Resource deleted, but is not yet disposed: (" ~ this.classinfo.name ~ ")" );
+        DWT.error( 0, null, " Resource deleted, but is not yet disposed: (" ~ this.classinfo.name ~ ") " ~ this.toString() );
     }
 }