diff dwt/graphics/Device.d @ 19:b73b14942338

Device
author Frank Benoit <benoit@tionex.de>
date Mon, 07 Jan 2008 07:47:32 +0100
parents 92223a4ecca7
children fc2b263b8a3f
line wrap: on
line diff
--- a/dwt/graphics/Device.d	Mon Jan 07 03:41:50 2008 +0100
+++ b/dwt/graphics/Device.d	Mon Jan 07 07:47:32 2008 +0100
@@ -10,8 +10,28 @@
  *******************************************************************************/
 module dwt.graphics.Device;
 
-import dwt.internal.gtk.c.gdktypes : GdkColor;
+import dwt.internal.gtk.c.gdktypes;
+import dwt.internal.gtk.c.gtktypes;
 import dwt.graphics.Color;
+import dwt.graphics.Font;
+import dwt.graphics.Drawable;
+import dwt.graphics.DeviceData;
+import dwt.graphics.Rectangle;
+import dwt.graphics.FontData;
+import dwt.graphics.Font;
+import dwt.graphics.GCData;
+import dwt.dwthelper.Runnable;
+import dwt.SWT;
+import dwt.SWTError;
+import dwt.internal.Compatibility;
+import dwt.internal.gtk.OS;
+import dwt.internal.gtk.c.gdktypes;
+
+import tango.core.Exception;
+import tango.stdc.stringz;
+import tango.io.Stdout;
+
+/+
 class Device{
     static Device getDevice(){
         return null;
@@ -30,13 +50,15 @@
     public Color getSystemColor (int id) {
         return null;
     }
+    Font systemFont;
+    Color COLOR_BLACK, COLOR_DARK_RED, COLOR_DARK_GREEN, COLOR_DARK_YELLOW, COLOR_DARK_BLUE;
+    Color COLOR_DARK_MAGENTA, COLOR_DARK_CYAN, COLOR_GRAY, COLOR_DARK_GRAY, COLOR_RED;
+    Color COLOR_GREEN, COLOR_YELLOW, COLOR_BLUE, COLOR_MAGENTA, COLOR_CYAN, COLOR_WHITE;
 }
 
-/++++
++/
 
-import dwt.*;
-import dwt.internal.*;
-import dwt.internal.gtk.*;
+
 
 /**
  * This class is the abstract superclass of all device objects,
@@ -44,7 +66,7 @@
  * can have a graphics context (GC) created for them, and they
  * can be drawn on by sending messages to the associated GC.
  */
-public abstract class Device implements Drawable {
+public abstract class Device : Drawable {
 	/**
 	 * the handle to the X Display
 	 * (Warning: This field is platform dependent)
@@ -55,35 +77,38 @@
 	 * platforms and should never be accessed from application code.
 	 * </p>
 	 */
-	protected int /*long*/ xDisplay;
-	int /*long*/ shellHandle;
+	protected dwt.internal.gtk.c.cairotypes.Display* xDisplay;
+	GtkWidget* shellHandle;
 
 	/* Debugging */
-	public static boolean DEBUG;
-	boolean debug = DEBUG;
-	boolean tracking = DEBUG;
-	Error [] errors;
+	public static bool DEBUG;
+	bool debugging;
+	bool tracking;
+	TracedException [] errors;
 	Object [] objects;
 
 	/* Colormap and reference count */
-	GdkColor [] gdkColors;
+	GdkColor *[] gdkColors;
 	int [] colorRefCount;
 
 	/* Disposed flag */
-	boolean disposed;
+	bool disposed;
 
 	/* Warning and Error Handlers */
-	int /*long*/ logProc;
-	Callback logCallback;
+	//int /*long*/ logProcFld;
+	//GLogFunc logCallback;
 	//NOT DONE - get list of valid names
-	String [] log_domains = {"GLib-GObject", "GLib", "GObject", "Pango", "ATK", "GdkPixbuf", "Gdk", "Gtk", "GnomeVFS"};
-	int [] handler_ids = new int [log_domains.length];
+	char[] [] log_domains = ["GLib-GObject"[], "GLib", "GObject", "Pango", "ATK", "GdkPixbuf", "Gdk", "Gtk", "GnomeVFS"];
+	int [] handler_ids;// = new int [log_domains.length];
 	int warningLevel;
 
 	/* X Warning and Error Handlers */
-	static Callback XErrorCallback, XIOErrorCallback;
+    static extern(C) int function(void *) mXIOErrorHandler;
+    static extern(C) int function(void *, XErrorEvent *) mXErrorHandler;
+	//static int mXErrorCallback, mXIOErrorCallback;
+
 	static int /*long*/ XErrorProc, XIOErrorProc, XNullErrorProc, XNullIOErrorProc;
-	static Device[] Devices = new Device[4];
+	static Device[] Devices;
 
 	/*
 	* The following colors are listed in the Windows
@@ -97,13 +122,13 @@
 	/* System Font */
 	Font systemFont;
 
-	int /*long*/ emptyTab;
+	PangoTabArray* emptyTab;
 
-	boolean useXRender;
+	bool useXRender;
 
-	static boolean CAIRO_LOADED;
+	static bool CAIRO_LOADED;
 
-	static final Object CREATE_LOCK = new Object();
+	static const Object CREATE_LOCK;
 
 	/*
 	* TEMPORARY CODE. When a graphics object is
@@ -119,17 +144,16 @@
 	*/
 	protected static Device CurrentDevice;
 	protected static Runnable DeviceFinder;
-	static {
-		try {
-			Class.forName ("dwt.widgets.Display");
-		} catch (Throwable e) {}
-	}
 
+static this(){
+    CREATE_LOCK = new Object();
+    Devices = new Device[4];
+}
 /*
 * TEMPORARY CODE.
 */
 static synchronized Device getDevice () {
-	if (DeviceFinder != null) DeviceFinder.run();
+	if (DeviceFinder !is null) DeviceFinder.run();
 	Device device = CurrentDevice;
 	CurrentDevice = null;
 	return device;
@@ -146,7 +170,7 @@
  *
  * @since 3.1
  */
-public Device() {
+public this() {
 	this(null);
 }
 
@@ -162,14 +186,18 @@
  * @see #init
  * @see DeviceData
  */
-public Device(DeviceData data) {
+public this(DeviceData data) {
+    handler_ids = new int [log_domains.length];
+    debugging = DEBUG;
+    tracking = DEBUG;
+
 	synchronized (CREATE_LOCK) {
 		if (data != null) {
-			debug = data.debug;
+			debugging = data.debugging;
 			tracking = data.tracking;
 		}
 		if (tracking) {
-			errors = new Error [128];
+			errors = new TracedException [128];
 			objects = new Object [128];
 		}
 		create (data);
@@ -182,25 +210,6 @@
 }
 
 void checkCairo() {
-	if (CAIRO_LOADED) return;
-	try {
-		/* Check if cairo is available on the system */
-		byte[] buffer = Converter.wcsToMbcs(null, "libcairo.so.2", true);
-		int /*long*/ libcairo = OS.dlopen(buffer, OS.RTLD_LAZY);
-		if (libcairo != 0) {
-			OS.dlclose(libcairo);
-		} else {
-			try {
-				System.loadLibrary("cairo-swt");
-			} catch (UnsatisfiedLinkError e) {
-				/* Ignore problems loading the fallback library */
-			}
-		}
-		Class.forName("dwt.internal.cairo.Cairo");
-		CAIRO_LOADED = true;
-	} catch (Throwable t) {
-		SWT.error(SWT.ERROR_NO_GRAPHICS_LIBRARY, t, " [Cairo is required]");
-	}
 }
 
 /**
@@ -260,7 +269,7 @@
 	release ();
 	destroy ();
 	deregister (this);
-	xDisplay = 0;
+	xDisplay = null;
 	disposed = true;
 	if (tracking) {
 		objects = null;
@@ -270,7 +279,7 @@
 
 void dispose_Object (Object object) {
 	for (int i=0; i<objects.length; i++) {
-		if (objects [i] == object) {
+		if (objects [i] is object) {
 			objects [i] = null;
 			errors [i] = null;
 			return;
@@ -278,10 +287,10 @@
 	}
 }
 
-static synchronized Device findDevice (int /*long*/ xDisplay) {
+static synchronized Device findDevice (dwt.internal.gtk.c.cairotypes.Display* xDisplay) {
 	for (int i=0; i<Devices.length; i++) {
 		Device device = Devices [i];
-		if (device != null && device.xDisplay == xDisplay) {
+		if (device !is null && device.xDisplay is xDisplay) {
 			return device;
 		}
 	}
@@ -290,7 +299,7 @@
 
 synchronized static void deregister (Device device) {
 	for (int i=0; i<Devices.length; i++) {
-		if (device == Devices [i]) Devices [i] = null;
+		if (device is Devices [i]) Devices [i] = null;
 	}
 }
 
@@ -341,7 +350,7 @@
 public DeviceData getDeviceData () {
 	checkDevice();
 	DeviceData data = new DeviceData ();
-	data.debug = debug;
+	data.debugging = debugging;
 	data.tracking = tracking;
 	int count = 0, length = 0;
 	if (tracking) length = objects.length;
@@ -350,7 +359,7 @@
 	}
 	int index = 0;
 	data.objects = new Object [count];
-	data.errors = new Error [count];
+	data.errors = new TracedException [count];
 	for (int i=0; i<length; i++) {
 		if (objects [i] != null) {
 			data.objects [index] = objects [i];
@@ -424,55 +433,47 @@
  *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
  * </ul>
  */
-public FontData[] getFontList (String faceName, boolean scalable) {
+public FontData[] getFontList (char[] faceName, bool scalable) {
 	checkDevice ();
 	if (!scalable) return new FontData[0];
-	int /*long*/[] family = new int /*long*/[1];
-	int /*long*/[] face = new int /*long*/[1];
-	int /*long*/[] families = new int /*long*/[1];
-	int[] n_families = new int[1];
-	int /*long*/[] faces = new int /*long*/[1];
-	int[] n_faces = new int[1];
-	int /*long*/ context = OS.gdk_pango_context_get();
-	OS.pango_context_list_families(context, families, n_families);
+	PangoFontFamily* family;
+	PangoFontFace * face;
+	PangoFontFamily** families;
+	int n_families;
+	PangoFontFace ** faces;
+	int n_faces;
+	auto context = OS.gdk_pango_context_get();
+	OS.pango_context_list_families(context, &families, &n_families);
 	int nFds = 0;
-	FontData[] fds = new FontData[faceName != null ? 4 : n_families[0]];
-	for (int i=0; i<n_families[0]; i++) {
-		OS.memmove(family, families[0] + i * OS.PTR_SIZEOF, OS.PTR_SIZEOF);
-		boolean match = true;
+	FontData[] fds = new FontData[faceName != null ? 4 : n_families];
+	for (int i=0; i<n_families; i++) {
+		family = families[i];
+		bool match = true;
 		if (faceName != null) {
-			int /*long*/ familyName = OS.pango_font_family_get_name(family[0]);
-			int length = OS.strlen(familyName);
-			byte[] buffer = new byte[length];
-			OS.memmove(buffer, familyName, length);
-			String name = new String(Converter.mbcsToWcs(null, buffer));
-			match = Compatibility.equalsIgnoreCase(faceName, name);
+			auto familyName = OS.pango_font_family_get_name(family);
+			match = Compatibility.equalsIgnoreCase(faceName, fromUtf8z( familyName ));
 		}
 		if (match) {
-		    OS.pango_font_family_list_faces(family[0], faces, n_faces);
-		    for (int j=0; j<n_faces[0]; j++) {
-		        OS.memmove(face, faces[0] + j * OS.PTR_SIZEOF, OS.PTR_SIZEOF);
-		        int /*long*/ fontDesc = OS.pango_font_face_describe(face[0]);
+		    OS.pango_font_family_list_faces(family, &faces, &n_faces);
+		    for (int j=0; j<n_faces; j++) {
+		        face = faces[j];
+		        auto fontDesc = OS.pango_font_face_describe(face);
 		        Font font = Font.gtk_new(this, fontDesc);
 		        FontData data = font.getFontData()[0];
 				if (nFds == fds.length) {
-					FontData[] newFds = new FontData[fds.length + n_families[0]];
-					System.arraycopy(fds, 0, newFds, 0, nFds);
-					fds = newFds;
+					fds.length = fds.length + n_families;
 				}
 				fds[nFds++] = data;
 				OS.pango_font_description_free(fontDesc);
 		    }
 		    OS.g_free(faces[0]);
-		    if (faceName != null) break;
+		    if (faceName !is null) break;
 		}
 	}
-	OS.g_free(families[0]);
+	OS.g_free(families);
 	OS.g_object_unref(context);
 	if (nFds == fds.length) return fds;
-	FontData[] result = new FontData[nFds];
-	System.arraycopy(fds, 0, result, 0, nFds);
-	return result;
+	return fds[ 0 .. nFds ].dup;
 }
 
 /**
@@ -552,7 +553,7 @@
  *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
  * </ul>
  */
-public boolean getWarnings () {
+public bool getWarnings () {
 	checkDevice ();
 	return warningLevel == 0;
 }
@@ -570,34 +571,27 @@
  * @see #create
  */
 protected void init () {
-	if (xDisplay != 0) {
-		int[] event_basep = new int[1], error_basep = new int [1];
-		if (OS.XRenderQueryExtension (xDisplay, event_basep, error_basep)) {
-			int[] major_versionp = new int[1], minor_versionp = new int [1];
-			OS.XRenderQueryVersion (xDisplay, major_versionp, minor_versionp);
-			useXRender = major_versionp[0] > 0 || (major_versionp[0] == 0 && minor_versionp[0] >= 8);
+	if (xDisplay !is null) {
+		int event_basep, error_basep;
+		if (OS.XRenderQueryExtension (xDisplay, &event_basep, &error_basep)) {
+			int major_version, minor_version;
+			OS.XRenderQueryVersion (xDisplay, &major_version, &minor_version);
+			useXRender = major_version > 0 || (major_version == 0 && minor_version >= 8);
 		}
 	}
 
-	if (debug) {
-		if (xDisplay != 0) {
+	if (debugging) {
+		if (xDisplay !is null) {
 			/* Create the warning and error callbacks */
-			Class clazz = getClass ();
-			synchronized (clazz) {
+			synchronized (CREATE_LOCK) {
 				int index = 0;
 				while (index < Devices.length) {
 					if (Devices [index] != null) break;
 					index++;
 				}
 				if (index == Devices.length) {
-					XErrorCallback = new Callback (clazz, "XErrorProc", 2);
-					XNullErrorProc = XErrorCallback.getAddress ();
-					if (XNullErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
-					XIOErrorCallback = new Callback (clazz, "XIOErrorProc", 1);
-					XNullIOErrorProc = XIOErrorCallback.getAddress ();
-					if (XNullIOErrorProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
-					XErrorProc = OS.XSetErrorHandler (XNullErrorProc);
-					XIOErrorProc = OS.XSetIOErrorHandler (XNullIOErrorProc);
+					OS.XSetErrorHandler ( & XErrorProcFunc );
+					OS.XSetIOErrorHandler ( & XIOErrorProcFunc );
 				}
 			}
 			OS.XSynchronize (xDisplay, true);
@@ -605,22 +599,17 @@
 	}
 
 	/* Create GTK warnings and error callbacks */
-	if (xDisplay != 0) {
-		logCallback = new Callback (this, "logProc", 4);
-		logProc = logCallback.getAddress ();
-		if (logProc == 0) SWT.error (SWT.ERROR_NO_MORE_CALLBACKS);
-
+	if (xDisplay !is null) {
 		/* Set GTK warning and error handlers */
-		if (debug) {
+		if (debugging) {
 			int flags = OS.G_LOG_LEVEL_MASK | OS.G_LOG_FLAG_FATAL | OS.G_LOG_FLAG_RECURSION;
 			for (int i=0; i<log_domains.length; i++) {
-				byte [] log_domain = Converter.wcsToMbcs (null, log_domains [i], true);
-				handler_ids [i] = OS.g_log_set_handler (log_domain, flags, logProc, 0);
+				handler_ids [i] = OS.g_log_set_handler (toStringz(log_domains [i]), cast(GLogLevelFlags)flags, & logFunction, cast(void*)this);
 			}
 		}
 	}
 
-	/* Create the standard colors */
+    /* Create the standard colors */
 	COLOR_BLACK = new Color (this, 0,0,0);
 	COLOR_DARK_RED = new Color (this, 0x80,0,0);
 	COLOR_DARK_GREEN = new Color (this, 0,0x80,0);
@@ -639,11 +628,11 @@
 	COLOR_WHITE = new Color (this, 0xFF,0xFF,0xFF);
 
 	emptyTab = OS.pango_tab_array_new(1, false);
-	if (emptyTab == 0) SWT.error(SWT.ERROR_NO_HANDLES);
-	OS.pango_tab_array_set_tab(emptyTab, 0, OS.PANGO_TAB_LEFT, 1);
+	if (emptyTab is null) SWT.error(SWT.ERROR_NO_HANDLES);
+	OS.pango_tab_array_set_tab(emptyTab, 0, cast(PangoTabAlign) OS.PANGO_TAB_LEFT, 1);
 
-	shellHandle = OS.gtk_window_new(OS.GTK_WINDOW_TOPLEVEL);
-	if (shellHandle == 0) SWT.error(SWT.ERROR_NO_HANDLES);
+	shellHandle = OS.gtk_window_new(cast(GtkWindowType)OS.GTK_WINDOW_TOPLEVEL);
+	if (shellHandle is null) SWT.error(SWT.ERROR_NO_HANDLES);
 	OS.gtk_widget_realize(shellHandle);
 }
 
@@ -660,7 +649,7 @@
  * @param data the platform specific GC data
  * @return the platform specific GC handle
  */
-public abstract int /*long*/ internal_new_GC (GCData data);
+public abstract GdkGC* internal_new_GC (GCData data);
 
 /**
  * Invokes platform specific functionality to dispose a GC handle.
@@ -675,7 +664,7 @@
  * @param hDC the platform specific GC handle
  * @param data the platform specific GC data
  */
-public abstract void internal_dispose_GC (int /*long*/ handle, GCData data);
+public abstract void internal_dispose_GC (GdkGC* handle, GCData data);
 
 /**
  * Returns <code>true</code> if the device has been disposed,
@@ -687,7 +676,7 @@
  *
  * @return <code>true</code> when the device is disposed and <code>false</code> otherwise
  */
-public boolean isDisposed () {
+public bool isDisposed () {
 	return disposed;
 }
 
@@ -707,52 +696,52 @@
  *
  * @since 3.3
  */
-public boolean loadFont (String path) {
+public bool loadFont (char[] path) {
 	checkDevice();
 	if (path == null) SWT.error (SWT.ERROR_NULL_ARGUMENT);
-	byte [] buffer = Converter.wcsToMbcs (null, path, true);
-	return OS.FcConfigAppFontAddFile (0, buffer);
+	return cast(bool) OS.FcConfigAppFontAddFile (null, toStringz(path));
 }
 
-int /*long*/ logProc (int /*long*/ log_domain, int /*long*/ log_level, int /*long*/ message, int /*long*/ user_data) {
-	if (warningLevel == 0) {
-		if (DEBUG || debug) {
-			new Error ().printStackTrace ();
+private static extern(C) void logFunction (char* log_domain, GLogLevelFlags log_level, char* message, void* user_data) {
+    Device dev = cast(Device)user_data;
+	if (dev.warningLevel == 0) {
+		if (DEBUG || dev.debugging) {
+            foreach( msg; new TracedException ("") ){
+                Stderr.formatln( "trc {}", msg );
+            }
 		}
-		OS.g_log_default_handler (log_domain, (int)/*64*/log_level, message, 0);
+		OS.g_log_default_handler (log_domain, log_level, message, user_data);
 	}
 	return 0;
 }
 
 void new_Object (Object object) {
 	for (int i=0; i<objects.length; i++) {
-		if (objects [i] == null) {
+		if (objects [i] is null) {
 			objects [i] = object;
-			errors [i] = new Error ();
+			errors [i] = new TracedException ("");
 			return;
 		}
 	}
-	Object [] newObjects = new Object [objects.length + 128];
-	System.arraycopy (objects, 0, newObjects, 0, objects.length);
-	newObjects [objects.length] = object;
-	objects = newObjects;
-	Error [] newErrors = new Error [errors.length + 128];
-	System.arraycopy (errors, 0, newErrors, 0, errors.length);
-	newErrors [errors.length] = new Error ();
-	errors = newErrors;
+    int oldLen = objects.length;
+    objects.length = objects.length + 128;
+    objects[ oldLen ] = object;
+
+    oldLen = errors.length;
+    errors.length = errors.length + 128;
+    errors[ oldLen ] = new TracedException ("");
 }
 
 static synchronized void register (Device device) {
 	for (int i=0; i<Devices.length; i++) {
-		if (Devices [i] == null) {
+		if (Devices [i] is null) {
 			Devices [i] = device;
 			return;
 		}
 	}
-	Device [] newDevices = new Device [Devices.length + 4];
-	System.arraycopy (Devices, 0, newDevices, 0, Devices.length);
-	newDevices [Devices.length] = device;
-	Devices = newDevices;
+    int oldLen = Devices.length;
+    Devices.length = Devices.length + 128;
+    Devices[ oldLen ] = device;
 }
 
 /**
@@ -779,14 +768,14 @@
  * @see #destroy
  */
 protected void release () {
-	if (shellHandle != 0) OS.gtk_widget_destroy(shellHandle);
-	shellHandle = 0;
+	if (shellHandle !is null) OS.gtk_widget_destroy(shellHandle);
+	shellHandle = null;
 
-	if (gdkColors != null) {
-		int /*long*/ colormap = OS.gdk_colormap_get_system();
+	if (gdkColors !is null) {
+		auto colormap = OS.gdk_colormap_get_system();
 		for (int i = 0; i < gdkColors.length; i++) {
-			GdkColor color = gdkColors [i];
-			if (color != null) {
+			GdkColor* color = gdkColors [i];
+			if (color !is null) {
 				while (colorRefCount [i] > 0) {
 					OS.gdk_colormap_free_colors(colormap, color, 1);
 					--colorRefCount [i];
@@ -800,21 +789,20 @@
 	COLOR_DARK_MAGENTA = COLOR_DARK_CYAN = COLOR_GRAY = COLOR_DARK_GRAY = COLOR_RED =
 	COLOR_GREEN = COLOR_YELLOW = COLOR_BLUE = COLOR_MAGENTA = COLOR_CYAN = COLOR_WHITE = null;
 
-	if (emptyTab != 0) OS.pango_tab_array_free(emptyTab);
-	emptyTab = 0;
+	if (emptyTab !is null ) OS.pango_tab_array_free(emptyTab);
+	emptyTab = null;
 
 	/* Free the GTK error and warning handler */
-	if (xDisplay != 0) {
+	if (xDisplay !is null) {
 		for (int i=0; i<handler_ids.length; i++) {
-			if (handler_ids [i] != 0) {
-				byte [] log_domain = Converter.wcsToMbcs (null, log_domains [i], true);
-				OS.g_log_remove_handler (log_domain, handler_ids [i]);
+			if (handler_ids [i] !is 0 ) {
+				OS.g_log_remove_handler (toStringz(log_domains [i]), handler_ids [i]);
 				handler_ids [i] = 0;
 			}
 		}
-		logCallback.dispose ();  logCallback = null;
+		//logCallback.dispose ();  logCallback = null;
 		handler_ids = null;  log_domains = null;
-		logProc = 0;
+		//logProcFld = 0;
 	}
 }
 
@@ -830,63 +818,67 @@
  *    <li>ERROR_DEVICE_DISPOSED - if the receiver has been disposed</li>
  * </ul>
  */
-public void setWarnings (boolean warnings) {
+public void setWarnings (bool warnings) {
 	checkDevice ();
 	if (warnings) {
 		if (--warningLevel == 0) {
-			if (debug) return;
-			if (logProc != 0) {
-				for (int i=0; i<handler_ids.length; i++) {
-					if (handler_ids [i] != 0) {
-						byte [] log_domain = Converter.wcsToMbcs (null, log_domains [i], true);
-						OS.g_log_remove_handler (log_domain, handler_ids [i]);
-						handler_ids [i] = 0;
-					}
-				}
-			}
+			if (debugging) return;
+            for (int i=0; i<handler_ids.length; i++) {
+                if (handler_ids [i] != 0) {
+                    OS.g_log_remove_handler (toStringz(log_domains [i]), handler_ids [i]);
+                    handler_ids [i] = 0;
+                }
+            }
 		}
 	} else {
 		if (warningLevel++ == 0) {
-			if (debug) return;
-			if (logProc != 0) {
-				int flags = OS.G_LOG_LEVEL_MASK | OS.G_LOG_FLAG_FATAL | OS.G_LOG_FLAG_RECURSION;
-				for (int i=0; i<log_domains.length; i++) {
-					byte [] log_domain = Converter.wcsToMbcs (null, log_domains [i], true);
-					handler_ids [i] = OS.g_log_set_handler (log_domain, flags, logProc, 0);
-				}
-			}
+			if (debugging) return;
+            int flags = OS.G_LOG_LEVEL_MASK | OS.G_LOG_FLAG_FATAL | OS.G_LOG_FLAG_RECURSION;
+            for (int i=0; i<log_domains.length; i++) {
+                handler_ids [i] = OS.g_log_set_handler (toStringz(log_domains [i]), cast(GLogLevelFlags)flags, & logFunction, cast(void*)this );
+            }
 		}
 	}
 }
 
-static int /*long*/ XErrorProc (int /*long*/ xDisplay, int /*long*/ xErrorEvent) {
+private static extern(C) int /*long*/ XErrorProcFunc (dwt.internal.gtk.c.cairotypes.Display* xDisplay, dwt.internal.gtk.OS.XErrorEvent* xErrorEvent) {
 	Device device = findDevice (xDisplay);
 	if (device != null) {
 		if (device.warningLevel == 0) {
-			if (DEBUG || device.debug) {
-				new SWTError ().printStackTrace ();
+			if (DEBUG || device.debugging) {
+                foreach( msg; new TracedException ("") ){
+                    Stderr.formatln( "trc {}", msg );
+                }
 			}
-			OS.Call (XErrorProc, xDisplay, xErrorEvent);
+            //PORTING_FIXME ??
+			//OS.Call (XErrorProc, xDisplay, xErrorEvent);
 		}
 	} else {
-		if (DEBUG) new SWTError ().printStackTrace ();
-		OS.Call (XErrorProc, xDisplay, xErrorEvent);
+		if (DEBUG) (new SWTError ()).printStackTrace ();
+        //PORTING_FIXME ??
+		//OS.Call (XErrorProc, xDisplay, xErrorEvent);
 	}
 	return 0;
 }
 
-static int /*long*/ XIOErrorProc (int /*long*/ xDisplay) {
+private static extern(C)  int /*long*/ XIOErrorProcFunc (dwt.internal.gtk.c.cairotypes.Display* xDisplay) {
 	Device device = findDevice (xDisplay);
 	if (device != null) {
-		if (DEBUG || device.debug) {
-			new SWTError ().printStackTrace ();
+		if (DEBUG || device.debugging) {
+            foreach( msg; new TracedException ("") ){
+                Stderr.formatln( "trc {}", msg );
+            }
 		}
 	} else {
-		if (DEBUG) new SWTError ().printStackTrace ();
+		if (DEBUG) {
+            foreach( msg; new TracedException ("") ){
+                Stderr.formatln( "trc {}", msg );
+            }
+        }
 	}
-	OS.Call (XIOErrorProc, xDisplay, 0);
+    //PORTING_FIXME ??
+	//OS.Call (XIOErrorProc, xDisplay, 0);
 	return 0;
 }
 
 }
-++++/
\ No newline at end of file