diff dwt/widgets/Widget.d @ 14:762fbe6f17d3

Ported dwt.widgets.Widget
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Sat, 23 Aug 2008 13:49:00 +0200
parents f565d3a95c0a
children 5b53d338c709
line wrap: on
line diff
--- a/dwt/widgets/Widget.d	Fri Aug 22 16:46:34 2008 +0200
+++ b/dwt/widgets/Widget.d	Sat Aug 23 13:49:00 2008 +0200
@@ -13,8 +13,8 @@
  *******************************************************************************/
 module dwt.widgets.Widget;
 
-import dwt.dwthelper.utils;
 
+import tango.core.Thread;
 
 import dwt.DWT;
 import dwt.DWTException;
@@ -25,6 +25,14 @@
 import dwt.internal.cocoa.OS;
 import dwt.internal.cocoa.objc_super;
 
+import dwt.dwthelper.utils;
+import objc = dwt.internal.objc.runtime;
+
+import dwt.widgets.Display;
+import dwt.widgets.Event;
+import dwt.widgets.EventTable;
+import dwt.widgets.Listener;
+import dwt.widgets.TypedListener;
 
 /**
  * This class is the abstract superclass of all user interface objects.  
@@ -61,43 +69,43 @@
     int jniRef;
 
     /* Global state flags */
-    static final int DISPOSED         = 1 << 0;
-    static final int CANVAS           = 1 << 1;
-    static final int KEYED_DATA       = 1 << 2;
-    static final int DISABLED         = 1 << 3;
-    static final int HIDDEN           = 1 << 4;
-    static final int GRAB                = 1 << 5;
-    static final int MOVED            = 1 << 6;
-    static final int RESIZED          = 1 << 7;
-    static final int EXPANDING        = 1 << 8;
-    static final int IGNORE_WHEEL     = 1 << 9;
-    static final int PARENT_BACKGROUND = 1 << 10;
-    static final int THEME_BACKGROUND = 1 << 11;
+    static const int DISPOSED         = 1 << 0;
+    static const int CANVAS           = 1 << 1;
+    static const int KEYED_DATA       = 1 << 2;
+    static const int DISABLED         = 1 << 3;
+    static const int HIDDEN           = 1 << 4;
+    static const int GRAB                = 1 << 5;
+    static const int MOVED            = 1 << 6;
+    static const int RESIZED          = 1 << 7;
+    static const int EXPANDING        = 1 << 8;
+    static const int IGNORE_WHEEL     = 1 << 9;
+    static const int PARENT_BACKGROUND = 1 << 10;
+    static const int THEME_BACKGROUND = 1 << 11;
     
     /* A layout was requested on this widget */
-    static final int LAYOUT_NEEDED  = 1<<12;
-    
+    static const int LAYOUT_NEEDED  = 1<<12;
+
     /* The preferred size of a child has changed */
-    static final int LAYOUT_CHANGED = 1<<13;
-    
+    static const int LAYOUT_CHANGED = 1<<13;
+
     /* A layout was requested in this widget hierachy */
-    static final int LAYOUT_CHILD = 1<<14;
+    static const int LAYOUT_CHILD = 1<<14;
 
     /* More global state flags */
-    static final int RELEASED = 1<<15;
-    static final int DISPOSE_SENT = 1<<16;  
-    static final int FOREIGN_HANDLE = 1<<17;
-    static final int DRAG_DETECT = 1<<18;
+    static const int RELEASED = 1<<15;
+    static const int DISPOSE_SENT = 1<<16;  
+    static const int FOREIGN_HANDLE = 1<<17;
+    static const int DRAG_DETECT = 1<<18;
 
     /* Safari fixes */
-    static final int SAFARI_EVENTS_FIX = 1<<19;
-    static final String SAFARI_EVENTS_FIX_KEY = "dwt.internal.safariEventsFix"; //$NON-NLS-1$
+    static const int SAFARI_EVENTS_FIX = 1<<19;
+    static const String SAFARI_EVENTS_FIX_KEY = "dwt.internal.safariEventsFix"; //$NON-NLS-1$
 
     /* Default size for widgets */
-    static final int DEFAULT_WIDTH  = 64;
-    static final int DEFAULT_HEIGHT = 64;
+    static const int DEFAULT_WIDTH  = 64;
+    static const int DEFAULT_HEIGHT = 64;
 
-Widget () {
+this () {
     /* Do nothing */
 }
 
@@ -130,15 +138,15 @@
  * @see #checkSubclass
  * @see #getStyle
  */
-public Widget (Widget parent, int style) {
+public this (Widget parent, int style) {
     checkSubclass ();
     checkParent (parent);
     this.style = style;
     display = parent.display;
 }
 
-void callSuper(int id, int selector, int arg0) {
-    objc_super super_struct = new objc_super();
+void callSuper(objc.id id, int selector, int arg0) {
+    objc_super super_struct;
     super_struct.receiver = id;
     super_struct.cls = OS.objc_msgSend(id, OS.sel_superclass);
     OS.objc_msgSendSuper(super_struct, selector, arg0);
@@ -308,7 +316,7 @@
 protected void checkWidget () {
     Display display = this.display;
     if (display is null) error (DWT.ERROR_WIDGET_DISPOSED);
-    if (display.thread !is Thread.currentThread ()) error (DWT.ERROR_THREAD_INVALID_ACCESS);
+    if (display.thread !is Thread.getThis ()) error (DWT.ERROR_THREAD_INVALID_ACCESS);
     if ((state & DISPOSED) !is 0) error (DWT.ERROR_WIDGET_DISPOSED);
 }
 
@@ -322,13 +330,13 @@
 void createHandle () {
 }
 
-void createJNIRef () {
+/*void createJNIRef () {
     jniRef = OS.NewGlobalRef(this);
     if (jniRef is 0) error (DWT.ERROR_NO_HANDLES);
-}
+}*/
 
 void createWidget () {
-    createJNIRef ();
+    //createJNIRef ();
     createHandle ();
 }
 
@@ -373,8 +381,8 @@
     /* Do nothing */
 }
 
-void drawRect(int id, NSRect rect) {
-    objc_super super_struct = new objc_super();
+void drawRect(objc.id id, NSRect rect) {
+    objc_super super_struct;
     super_struct.receiver = id;
     super_struct.cls = OS.objc_msgSend(id, OS.sel_superclass);
     OS.objc_msgSendSuper(super_struct, OS.sel_drawRect_1, rect);
@@ -427,7 +435,7 @@
  */
 public Object getData () {
     checkWidget();
-    return (state & KEYED_DATA) !is 0 ? ((Object []) data) [0] : data;
+    return (state & KEYED_DATA) !is 0 ? (cast(ArrayWrapperObject) data).array [0] : data;
 }
 
 /**
@@ -456,11 +464,12 @@
  */
 public Object getData (String key) {
     checkWidget();
-    if (key is null) error (DWT.ERROR_NULL_ARGUMENT);
+    //if (key is null) error (DWT.ERROR_NULL_ARGUMENT);
     if ((state & KEYED_DATA) !is 0) {
-        Object [] table = (Object []) data;
+        Object [] table = (cast(ArrayWrapperObject) data).array;
         for (int i=1; i<table.length; i+=2) {
-            if (key.equals (table [i])) return table [i+1];
+            String tablekey = (cast(ArrayWrapperString) table[i]).array;
+            if (key.equals (tablekey)) return table [i+1];
         }
     }
     return null;
@@ -515,7 +524,7 @@
 }
 
 String getName () {
-    String string = getClass ().getName ();
+    String string = this.classinfo.name;
     int index = string.lastIndexOf ('.');
     if (index is -1) return string;
     return string.substring (index + 1, string.length ());
@@ -741,8 +750,8 @@
 void releaseHandle () {
     state |= DISPOSED;
     display = null;
-    if (jniRef !is 0) OS.DeleteGlobalRef(jniRef);
-    jniRef = 0;
+    //if (jniRef !is 0) OS.DeleteGlobalRef(jniRef);
+    //jniRef = 0;
 }
 
 void releaseParent () {
@@ -958,7 +967,7 @@
         return;
     }
     if ((state & KEYED_DATA) !is 0) {
-        ((Object []) this.data) [0] = data;
+        (cast(ArrayWrapperObject) this.data).array [0] = data;
     } else {
         this.data = data;
     }
@@ -990,11 +999,11 @@
  */
 public void setData (String key, Object value) {
     checkWidget();
-    if (key is null) error (DWT.ERROR_NULL_ARGUMENT);
+    //if (key is null) error (DWT.ERROR_NULL_ARGUMENT);
     int index = 1;
     Object [] table = null;
     if ((state & KEYED_DATA) !is 0) {
-        table = (Object []) data;
+        table = (cast(ArrayWrapperObject) data).array;
         while (index < table.length) {
             if (key.equals (table [index])) break;
             index += 2;
@@ -1259,8 +1268,8 @@
 void windowDidBecomeKey(int notification) {
 }
 
-void windowSendEvent(int id, int event) {
-    callSuper(id, OS.sel_sendEvent_1, event);
+void windowSendEvent(objc.id id, int event) {
+    callSuper(objc.id, OS.sel_sendEvent_1, event);
 }
 
 bool windowShouldClose(int window) {