Mercurial > projects > dwt-win
diff dwt/graphics/Device.d @ 213:36f5cb12e1a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 17 May 2008 17:34:28 +0200 |
parents | ab60f3309436 |
children | fd9c62a2998e |
line wrap: on
line diff
--- a/dwt/graphics/Device.d Mon May 05 00:12:38 2008 +0200 +++ b/dwt/graphics/Device.d Sat May 17 17:34:28 2008 +0200 @@ -17,6 +17,14 @@ import dwt.internal.gdip.Gdip; import dwt.internal.win32.OS; +import dwt.graphics.Cursor; +import dwt.graphics.GC; +import dwt.graphics.Image; +import dwt.graphics.Path; +import dwt.graphics.Pattern; +import dwt.graphics.Region; +import dwt.graphics.TextLayout; +import dwt.graphics.Transform; import dwt.graphics.Drawable; import dwt.graphics.DeviceData; import dwt.graphics.Rectangle; @@ -27,8 +35,11 @@ import dwt.dwthelper.Runnable; import dwt.dwthelper.System; + import dwt.dwthelper.utils; import tango.core.Exception; +import tango.util.Convert; +import tango.io.Stdout; /** * This class is the abstract superclass of all device objects, @@ -49,6 +60,7 @@ bool tracking; Exception [] errors; Object [] objects; + Object trackingLock; /** * Palette @@ -64,7 +76,7 @@ int [] colorRefCount; /* System Font */ - HFONT systemFont; + Font systemFont; /* Font Enumeration */ int nFonts = 256; @@ -74,6 +86,7 @@ /* Scripts */ SCRIPT_PROPERTIES*[] scripts; + LOGFONT* [] logFontsCache; /* Advanced Graphics */ ULONG_PTR gdipToken; @@ -134,22 +147,20 @@ * @see DeviceData */ public this(DeviceData data) { - synchronized (this.classinfo) { + synchronized (Device.classinfo) { debug_ = DEBUG; tracking = DEBUG; if (data !is null) { debug_ = data.debug_; tracking = data.tracking; } - create (data); - init_ (); if (tracking) { errors = new Exception [128]; objects = new Object [128]; + trackingLock = new Object (); } - - /* Initialize the system font slot */ - systemFont = getSystemFont().handle; + create (data); + init_ (); gdipToken = 0; } } @@ -179,8 +190,8 @@ void checkGDIP() { if (gdipToken) return; - static if (OS.IsWinCE) DWT.error(DWT.ERROR_NOT_IMPLEMENTED); - int oldErrorMode = OS.SetErrorMode (OS.SEM_FAILCRITICALERRORS); + int oldErrorMode = 0; + static if (!OS.IsWinCE) oldErrorMode = OS.SetErrorMode (OS.SEM_FAILCRITICALERRORS); try { ULONG_PTR token; GdiplusStartupInput input; @@ -191,7 +202,7 @@ } catch (Exception t) { DWT.error (DWT.ERROR_NO_GRAPHICS_LIBRARY, t, " [GDI+ is required]"); //$NON-NLS-1$ } finally { - OS.SetErrorMode (oldErrorMode); + if (!OS.IsWinCE) OS.SetErrorMode (oldErrorMode); } } @@ -272,23 +283,31 @@ * @see #checkDevice */ public void dispose () { - if (isDisposed()) return; - checkDevice (); - release (); - destroy (); - disposed = true; - if (tracking) { - objects = null; - errors = null; + synchronized (Device.classinfo) { + if (isDisposed()) return; + checkDevice (); + release (); + destroy (); + disposed = true; + if (tracking) { + synchronized (trackingLock) { + printErrors (); + objects = null; + errors = null; + trackingLock = null; + } + } } } void dispose_Object (Object object) { - for (int i=0; i<objects.length; i++) { - if (objects [i] is object) { - objects [i] = null; - errors [i] = null; - return; + synchronized (trackingLock) { + for (int i=0; i<objects.length; i++) { + if (objects [i] is object) { + objects [i] = null; + errors [i] = null; + return; + } } } } @@ -369,20 +388,26 @@ DeviceData data = new DeviceData (); data.debug_ = debug_; data.tracking = tracking; - int count = 0, length = 0; - if (tracking) length = objects.length; - for (int i=0; i<length; i++) { - if (objects [i] !is null) count++; - } - int index = 0; - data.objects = new Object [count]; - data.errors = new Exception [count]; - for (int i=0; i<length; i++) { - if (objects [i] !is null) { - data.objects [index] = objects [i]; - data.errors [index] = errors [i]; - index++; + if (tracking) { + synchronized (trackingLock) { + int count = 0, length = objects.length; + for (int i=0; i<length; i++) { + if (objects [i] !is null) count++; + } + int index = 0; + data.objects = new Object [count]; + data.errors = new Exception [count]; + for (int i=0; i<length; i++) { + if (objects [i] !is null) { + data.objects [index] = objects [i]; + data.errors [index] = errors [i]; + index++; + } + } } + } else { + data.objects = new Object [0]; + data.errors = new Exception [0]; } return data; } @@ -660,6 +685,9 @@ static if (!OS.IsWinCE) OS.GdiSetBatchLimit(1); } + /* Initialize the system font slot */ + systemFont = getSystemFont(); + /* Initialize scripts list */ static if (!OS.IsWinCE) { SCRIPT_PROPERTIES** ppSp; @@ -772,7 +800,9 @@ * @return <code>true</code> when the device is disposed and <code>false</code> otherwise */ public bool isDisposed () { - return disposed; + synchronized (Device.classinfo) { + return disposed; + } } /** @@ -802,21 +832,71 @@ } void new_Object (Object object) { - for (int i=0; i<objects.length; i++) { - if (objects [i] is null) { - objects [i] = object; - errors [i] = new Exception ( "" ); - return; + synchronized (trackingLock) { + for (int i=0; i<objects.length; i++) { + if (objects [i] is null) { + objects [i] = object; + errors [i] = new Exception ( "" ); + return; + } + } + Object [] newObjects = new Object [objects.length + 128]; + System.arraycopy (objects, 0, newObjects, 0, objects.length); + newObjects [objects.length] = object; + objects = newObjects; + Exception [] newErrors = new Exception [errors.length + 128]; + System.arraycopy (errors, 0, newErrors, 0, errors.length); + newErrors [errors.length] = new Exception (""); + errors = newErrors; + } +} + +void printErrors () { + if (!DEBUG) return; + if (tracking) { + synchronized (trackingLock) { + if (objects is null || errors is null) return; + int objectCount = 0; + int colors = 0, cursors = 0, fonts = 0, gcs = 0, images = 0; + int paths = 0, patterns = 0, regions = 0, textLayouts = 0, transforms = 0; + for (int i=0; i<objects.length; i++) { + Object object = objects [i]; + if (object !is null) { + objectCount++; + if (null !is cast(Color)object ) colors++; + if (null !is cast(Cursor)object ) cursors++; + if (null !is cast(Font)object ) fonts++; + if (null !is cast(GC)object ) gcs++; + if (null !is cast(Image)object ) images++; + if (null !is cast(Path)object ) paths++; + if (null !is cast(Pattern)object ) patterns++; + if (null !is cast(Region)object ) regions++; + if (null !is cast(TextLayout)object ) textLayouts++; + if (null !is cast(Transform)object ) transforms++; + } + } + if (objectCount !is 0) { + String string = "Summary: "; + if (colors !is 0) string ~= to!(String)(colors) ~ " Color(s), "; + if (cursors !is 0) string ~= to!(String)(cursors) ~ " Cursor(s), "; + if (fonts !is 0) string ~= to!(String)(fonts) ~ " Font(s), "; + if (gcs !is 0) string ~= to!(String)(gcs) ~ " GC(s), "; + if (images !is 0) string ~= to!(String)(images) ~ " Image(s), "; + if (paths !is 0) string ~= to!(String)(paths) ~ " Path(s), "; + if (patterns !is 0) string ~= to!(String)(patterns) ~ " Pattern(s), "; + if (regions !is 0) string ~= to!(String)(regions) ~ " Region(s), "; + if (textLayouts !is 0) string ~= to!(String)(textLayouts) ~ " TextLayout(s), "; + if (transforms !is 0) string ~= to!(String)(transforms) ~ " Transforms(s), "; + if (string.length !is 0) { + string = string.substring (0, string.length - 2); + Stderr.formatln ( "{}", string); + } + for (int i=0; i<errors.length; i++) { + if (errors [i] !is null) ExceptionPrintStackTrace( errors [i], Stderr); + } + } } } - Object [] newObjects = new Object [objects.length + 128]; - System.arraycopy (objects, 0, newObjects, 0, objects.length); - newObjects [objects.length] = object; - objects = newObjects; - Exception [] newErrors = new Exception [errors.length + 128]; - System.arraycopy (errors, 0, newErrors, 0, errors.length); - newErrors [errors.length] = new Exception (""); - errors = newErrors; } /** @@ -848,6 +928,7 @@ } gdipToken = 0; // TODO: assignment of 0 might not be valid for token scripts = null; + logFontsCache = null; if (hPalette !is null) OS.DeleteObject (hPalette); hPalette = null; colorRefCount = null;