diff dwt/browser/MozillaDelegate.d @ 286:44258e0b6687

More fixes for xpcom
author John Reimer<terminal.node@gmail.com>
date Tue, 05 Aug 2008 10:11:58 -0700
parents 93409d9838c5
children 3f4a5c7d138f
line wrap: on
line diff
--- a/dwt/browser/MozillaDelegate.d	Thu Jul 31 21:56:03 2008 -0700
+++ b/dwt/browser/MozillaDelegate.d	Tue Aug 05 10:11:58 2008 -0700
@@ -7,6 +7,8 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ * Port to the D programming language:
+ *      John Reimer <terminal.node@gmail.com>
  *******************************************************************************/
 module dwt.browser.MozillaDelegate;
 
@@ -24,20 +26,21 @@
 
 class MozillaDelegate {
     Browser browser;
-    int /*long*/ mozillaHandle, embedHandle;
+    gpointer mozillaHandle;
+    GtkWidget* embedHandle;
     bool hasFocus;
     Listener listener;
-    static Callback eventCallback;
-    static int /*long*/ eventProc;
-    static final int STOP_PROPOGATE = 1;
+    //static Callback eventCallback;
+    // static int /*long*/ eventProc;
+    static const gpointer STOP_PROPOGATE = cast(gpointer)1;
 
     static bool IsLinux;
-    static {
-        String osName = System.getProperty ("os.name").toLowerCase (); //$NON-NLS-1$
-        IsLinux = osName.startsWith ("linux"); //$NON-NLS-1$
+    static this {
+        String osName = System.getProperty ("os.name"); //$NON-NLS-1$
+        IsLinux = tango.text.Util.containsPattern(osName, "linux"); //$NON-NLS-1$
     }
 
-MozillaDelegate (Browser browser) {
+this (Browser browser) {
     super ();
     if (!IsLinux) {
         browser.dispose ();
@@ -46,27 +49,27 @@
     this.browser = browser;
 }
 
-static int /*long*/ eventProc (int /*long*/ handle, int /*long*/ gdkEvent, int /*long*/ pointer) {
-    int /*long*/ parent = OS.gtk_widget_get_parent (handle);
+static extern(C) int eventProc (GtkWidget* handle, GdkEvent* gdkEvent, gpointer pointer) {
+    GtkWidget* parent = OS.gtk_widget_get_parent (handle);
     parent = OS.gtk_widget_get_parent (parent);
-    if (parent is 0) return 0;
+    if (parent is null) return 0;
     Widget widget = Display.getCurrent ().findWidget (parent);
-    if (widget !is null && widget instanceof Browser) {
-        return ((Mozilla)((Browser)widget).webBrowser).delegate.gtk_event (handle, gdkEvent, pointer);
+    if (widget !is null && (cast(Browser)widget !is null) {
+        return (cast(Mozilla)(cast(Browser)widget).webBrowser).mozDelegate.gtk_event (handle, gdkEvent, pointer);
     }
     return 0;
 }
 
-static Browser findBrowser (int /*long*/ handle) {
+static Browser findBrowser (GtkWidget* handle) {
     /*
     * Note.  On GTK, Mozilla is embedded into a GtkHBox handle
     * and not directly into the parent Composite handle.
     */
-    int /*long*/ parent = OS.gtk_widget_get_parent (handle);
+    GtkWidget* parent = OS.gtk_widget_get_parent (handle);
     Display display = Display.getCurrent ();
-    return (Browser)display.findWidget (parent); 
+    return cast(Browser)display.findWidget (parent); 
 }
-
+/*
 static char[] mbcsToWcs (String codePage, byte [] buffer) {
     return Converter.mbcsToWcs (codePage, buffer);
 }
@@ -74,8 +77,8 @@
 static byte[] wcsToMbcs (String codePage, String string, bool terminate) {
     return Converter.wcsToMbcs (codePage, string, terminate);
 }
-
-int /*long*/ getHandle () {
+*/
+GtkWidget* getHandle () {
     /*
     * Bug in Mozilla Linux GTK.  Embedding Mozilla into a GtkFixed
     * handle causes problems with some Mozilla plug-ins.  For some
@@ -96,13 +99,13 @@
     return "libxpcom.so"; //$NON-NLS-1$
 }
 
+/*
 String getSWTInitLibraryName () {
     return "swt-xpcominit"; //$NON-NLS-1$
 }
+*/
 
-int /*long*/ gtk_event (int /*long*/ handle, int /*long*/ gdkEvent, int /*long*/ pointer) {
-    GdkEvent event = new GdkEvent ();
-    OS.memmove (event, gdkEvent, GdkEvent.sizeof);
+int gtk_event (GtkWidget* handle, GdkEvent* event, gpointer pointer) {
     if (event.type is OS.GDK_BUTTON_PRESS) {
         if (!hasFocus) browser.setFocus ();
     }
@@ -121,7 +124,7 @@
     listener = new Listener () {
         public void handleEvent (Event event) {
             if (event.widget is browser) return;
-            ((Mozilla)browser.webBrowser).Deactivate ();
+            (cast(Mozilla)(browser.webBrowser)).Deactivate ();
             hasFocus = false;
             browser.getDisplay ().removeFilter (DWT.FocusIn, this);
             browser.getShell ().removeListener (DWT.Deactivate, this);
@@ -138,7 +141,7 @@
         browser.getDisplay ().asyncExec (new Runnable () {
             public void run () {
                 if (browser is null || browser.isDisposed ()) return;
-                ((Mozilla)browser.webBrowser).Activate ();
+                (cast(Mozilla)(browser.webBrowser)).Activate ();
             }
         });
     }
@@ -148,15 +151,15 @@
     return false;
 }
 
-void init () {
+void init () { /*
     if (eventCallback is null) {
         eventCallback = new Callback (getClass (), "eventProc", 3); //$NON-NLS-1$
         eventProc = eventCallback.getAddress ();
-        if (eventProc is 0) {
+        if (eventProc is null) {
             browser.dispose ();
             Mozilla.error (DWT.ERROR_NO_MORE_CALLBACKS);
         }
-    }
+    } */
 
     /*
     * Feature in Mozilla.  GtkEvents such as key down, key pressed may be consumed
@@ -166,14 +169,14 @@
     * forward the event to the parent embedder before Mozilla received and consumed
     * them.
     */
-    int /*long*/ list = OS.gtk_container_get_children (embedHandle);
-    if (list !is 0) {
+    GList* list = OS.gtk_container_get_children (embedHandle);
+    if (list !is null) {
         mozillaHandle = OS.g_list_data (list);
         OS.g_list_free (list);
         
-        if (mozillaHandle !is 0) {          
+        if (mozillaHandle !is null) {          
             /* Note. Callback to get events before Mozilla receives and consumes them. */
-            OS.g_signal_connect (mozillaHandle, OS.event, eventProc, 0);
+            OS.g_signal_connect (mozillaHandle, OS.event, cast(GCallback)&eventProc, null);
             
             /* 
             * Note.  Callback to get the events not consumed by Mozilla - and to block 
@@ -181,9 +184,9 @@
             * This hook is set after Mozilla and is therefore called after Mozilla's 
             * handler because GTK dispatches events in their order of registration.
             */
-            OS.g_signal_connect (mozillaHandle, OS.key_press_event, eventProc, STOP_PROPOGATE);
-            OS.g_signal_connect (mozillaHandle, OS.key_release_event, eventProc, STOP_PROPOGATE);
-            OS.g_signal_connect (mozillaHandle, OS.button_press_event, eventProc, STOP_PROPOGATE);
+            OS.g_signal_connect (mozillaHandle, OS.key_press_event, cast(GCallback)&eventProc, STOP_PROPOGATE);
+            OS.g_signal_connect (mozillaHandle, OS.key_release_event, cast(GCallback)&eventProc, STOP_PROPOGATE);
+            OS.g_signal_connect (mozillaHandle, OS.button_press_event, cast(GCallback)&eventProc, STOP_PROPOGATE);
         }
     }
 }
@@ -201,7 +204,7 @@
     browser = null;
 }
 
-void setSize (int /*long*/ embedHandle, int width, int height) {
+void setSize (GtkWidget* embedHandle, int width, int height) {
     OS.gtk_widget_set_size_request (embedHandle, width, height);
 }