diff dwt/widgets/Display.d @ 60:62202ce0039f

Updated and fixed many modules to 3.514
author Jacob Carlborg <doob@me.com>
date Mon, 22 Dec 2008 15:10:19 +0100
parents 9dd4a17513f9
children c74ba20de292
line wrap: on
line diff
--- a/dwt/widgets/Display.d	Tue Dec 09 21:52:21 2008 +0100
+++ b/dwt/widgets/Display.d	Mon Dec 22 15:10:19 2008 +0100
@@ -71,11 +71,12 @@
 import dwt.internal.cocoa.objc_super;
 
 import tango.core.Thread;
+import tango.stdc.stringz;
 
 import dwt.dwthelper.Runnable;
 import dwt.dwthelper.System;
 import dwt.dwthelper.utils;
-import dwt.internal.c.Carbon;
+import Carbon = dwt.internal.c.Carbon;
 import dwt.internal.objc.cocoa.Cocoa;
 import objc = dwt.internal.objc.runtime;
 import dwt.widgets.Caret;
@@ -95,6 +96,8 @@
 import dwt.widgets.Tray;
 import dwt.widgets.Widget;
 
+import mambo.io;
+
 /**
  * Instances of this class are responsible for managing the
  * connection between DWT and the underlying operating
@@ -209,7 +212,7 @@
     NSAutoreleasePool pool;
     int loopCounter = 0;
     bool idle;
-    static final short DWT_IDLE_TYPE = 1;
+    static const short SWT_IDLE_TYPE = 1;
 
     int[] screenID;
     NSPoint[] screenCascade;
@@ -354,15 +357,16 @@
     CurrentDevice = device;
 }
 
-static byte [] ascii (String name) {
-    int length = name.length ();
+static char* ascii (String name) {
+    /*int length = name.length ();
     char [] chars = new char [length];
     name.getChars (0, length, chars, 0);
     byte [] buffer = new byte [length + 1];
     for (int i=0; i<length; i++) {
         buffer [i] = cast(byte) chars [i];
     }
-    return buffer;
+    return buffer;*/
+    return name.toStringz();
 }
 
 static int translateKey (int key) {
@@ -555,12 +559,13 @@
     while (screenID[index] !is 0 && screenID[index] !is screenNumber) index++;
     screenID[index] = screenNumber;
     NSPoint cascade = screenCascade[index];
-    if (cascade is null) {
+    //FIXME Jacob Carlborg
+    /*if (cascade is null) {
         NSRect frame = screen.frame();
         cascade = NSPoint();
         cascade.x = frame.x;
         cascade.y = frame.y + frame.height;
-    }
+    }*/
     screenCascade[index] = window.cascadeTopLeftFromPoint(cascade);
 }
 
@@ -701,15 +706,15 @@
 
 void clearModal (Shell shell) {
     if (modalShells is null) return;
-    int index = 0, length = modalShells.length;
-    while (index < length) {
+    int index = 0, length_ = modalShells.length;
+    while (index < length_) {
         if (modalShells [index] is shell) break;
         if (modalShells [index] is null) return;
         index++;
     }
-    if (index is length) return;
-    System.arraycopy (modalShells, index + 1, modalShells, index, --length - index);
-    modalShells [length] = null;
+    if (index is length_) return;
+    System.arraycopy (modalShells, index + 1, modalShells, index, --length_ - index);
+    modalShells [length_] = null;
     if (index is 0 && modalShells [0] is null) modalShells = null;
     Shell [] shells = getShells ();
     for (int i=0; i<shells.length; i++) shells [i].updateModal ();
@@ -765,7 +770,7 @@
 
     NSThread nsthread = NSThread.currentThread();
     NSMutableDictionary dictionary = nsthread.threadDictionary();
-    NSString key = NSString.stringWith("DWT_NSAutoreleasePool");
+    NSString key = NSString.stringWith("SWT_NSAutoreleasePool");
     pool = new NSAutoreleasePool(dictionary.objectForKey(key));
 
     application = NSApplication.sharedApplication();
@@ -789,17 +794,17 @@
          * used) but both functions must be called in order for
          * windows to come to the front.
          */
-        ProcessSerialNumber* psn;
-        if (OS.GetCurrentProcess (psn) is OS.noErr) {
+        Carbon.ProcessSerialNumber psn;
+        if (OS.GetCurrentProcess (&psn) is OS.noErr) {
             int pid = OS.getpid ();
-            char* ptr = OS.getenv (ascii ("APP_NAME_" + pid));
+            char* ptr = OS.getenv (ascii ("APP_NAME_" ~ Integer.toString(pid)));
             if (ptr is null && APP_NAME !is null) {
                 ptr = NSString.stringWith(APP_NAME).UTF8String();   
             }
-            if (ptr !is null) OS.CPSSetProcessName (psn, ptr);
-            OS.TransformProcessType (psn, OS.kProcessTransformToForegroundApplication);
-            OS.SetFrontProcess (psn);
-            ptr = OS.getenv (ascii ("APP_ICON_" + pid));
+            if (ptr !is null) OS.CPSSetProcessName (&psn, ptr);
+            OS.TransformProcessType (&psn, OS.kProcessTransformToForegroundApplication);
+            OS.SetFrontProcess (&psn);
+            ptr = OS.getenv (ascii ("APP_ICON_" ~ Integer.toString(pid)));
             if (ptr !is null) {
                 NSString path = NSString.stringWithUTF8String (ptr);
                 NSImage image = cast(NSImage) (new NSImage()).alloc();
@@ -811,13 +816,18 @@
 
         String className = "SWTApplication";
         objc.Class cls;
-        if ((cls = OS.objc_lookUpClass (className)) is null) {
+        if ((cls = cast(objc.Class) OS.objc_lookUpClass (className)) is null) {
             objc.IMP proc2 = cast(objc.IMP) &applicationProc2;
             objc.IMP proc3 = cast(objc.IMP) &applicationProc3;
             objc.IMP proc6 = cast(objc.IMP) &applicationProc6;
-            cls = OS.objc_allocateClassPair(OS.class_NSApplication, className, 0);
+            cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSApplication, className, 0);
             OS.class_addMethod(cls, OS.sel_sendEvent_, proc3, "@:@");
-            OS.class_addMethod(cls, OS.sel_nextEventMatchingMask_untilDate_inMode_dequeue_, proc6, "@:i@@B");
+            
+            static if ((void*).sizeof > int.sizeof) // 64bit target
+                OS.class_addMethod(cls, OS.sel_nextEventMatchingMask_untilDate_inMode_dequeue_, proc6, "@:Q@@B");
+            else
+                OS.class_addMethod(cls, OS.sel_nextEventMatchingMask_untilDate_inMode_dequeue_, proc6, "@:I@@B");
+            
             OS.class_addMethod(cls, OS.sel_isRunning, proc2, "@:");
             OS.objc_registerClassPair(cls);
         }
@@ -828,7 +838,7 @@
 
     //  application = new NSApplication(OS.objc_msgSend(cls, OS.sel_sharedApplication));
 }
-
+    
 static void deregister (Display display) {
     synchronized (Device.classinfo) {
         for (int i=0; i<Displays.length; i++) {
@@ -1040,8 +1050,8 @@
 
 Rectangle getBounds (NSArray screens) {
     NSRect primaryFrame = (new NSScreen(screens.objectAtIndex(0))).frame();
-    CGFloat minX = Float.MAX_VALUE, maxX = Float.MIN_VALUE;
-    CGFloat minY = Float.MAX_VALUE, maxY = Float.MIN_VALUE;
+    CGFloat minX = CGFloat.max, maxX = CGFloat.min;
+    CGFloat minY = CGFloat.max, maxY = CGFloat.min;
     NSUInteger count = screens.count();
     for (NSUInteger i = 0; i < count; i++) {
         NSScreen screen = new NSScreen(screens.objectAtIndex(i));
@@ -1410,8 +1420,9 @@
     checkDevice ();
     NSArray screens = NSScreen.screens();
     NSRect primaryFrame = (new NSScreen(screens.objectAtIndex(0))).frame();
-    int count = cast(int)/*64*/screens.count();
-    for (int i=0; i<count; i++) {
+    NSUInteger count = screens.count();
+    dwt.widgets.Monitor.Monitor [] monitors = new dwt.widgets.Monitor.Monitor [count];
+    for (NSUInteger i=0; i<count; i++) {
         dwt.widgets.Monitor.Monitor monitor = new dwt.widgets.Monitor.Monitor ();
         NSScreen screen = new NSScreen(screens.objectAtIndex(i));
         NSRect frame = screen.frame();
@@ -1576,8 +1587,8 @@
     color = color.colorUsingColorSpace(NSColorSpace.deviceRGBColorSpace());
     if (color is null) return super.getSystemColor(id);
     CGFloat[] components = new CGFloat[color.numberOfComponents()];
-    color.getComponents(components);    
-    return Color.cocoa_new (this, [cast(float)/*64*/ components[0], cast(float)/*64*/ components[1], cast(float)/*64*/ components[2], cast(float)/*64*/ components[3]]);
+    color.getComponents(components.ptr);
+    return Color.cocoa_new (this, [components[0], components[1], components[2], components[3]]);
 }
 
 /**
@@ -1775,7 +1786,7 @@
     String className = "SWTApplicationDelegate";
     if (OS.objc_lookUpClass (className) is null) {
         objc.IMP appProc3 = cast(objc.IMP) &applicationDelegateProc;
-        objc.Class cls = OS.objc_allocateClassPair(OS.class_NSObject, className, 0);
+        objc.Class cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSObject, className, 0);
         OS.class_addMethod(cls, OS.sel_applicationWillFinishLaunching_, appProc3, "@:@");
         OS.class_addMethod(cls, OS.sel_terminate_, appProc3, "@:@");
         OS.class_addMethod(cls, OS.sel_orderFrontStandardAboutPanel_, appProc3, "@:@");
@@ -1833,7 +1844,7 @@
 
 objc.Class registerCellSubclass(objc.Class cellClass, int size, int align_, String types) {
     String cellClassName = OS.class_getName(cellClass);
-    objc.Class cls = OS.objc_allocateClassPair(cellClass, "DWT" + cellClassName, 0);   
+    objc.Class cls = OS.objc_allocateClassPair(cellClass, "SWT" ~ cellClassName, 0);   
     OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
     OS.objc_registerClassPair(cls);
     return cls;
@@ -1842,12 +1853,12 @@
 void initClasses () {
     if (OS.objc_lookUpClass ("SWTView") !is null) return;
     
-    objc.IMP dialogProc3 = &dialogProc3;
-    objc.IMP proc3 = &windowDelegateProc3;
-    objc.IMP proc2 = windowDelegateProc2.getAddress();
-    objc.IMP proc4 = windowDelegateProc4.getAddress();
-    objc.IMP proc5 = windowDelegateProc5.getAddress();
-    objc.IMP proc6 = windowDelegateProc6.getAddress();
+    objc.IMP dialogProc3 = cast(objc.IMP) &dialogProc;
+    objc.IMP proc3 = cast(objc.IMP) &windowDelegateProc3;
+    objc.IMP proc2 = cast(objc.IMP) &windowDelegateProc2;
+    objc.IMP proc4 = cast(objc.IMP) &windowDelegateProc4;
+    objc.IMP proc5 = cast(objc.IMP) &windowDelegateProc5;
+    objc.IMP proc6 = cast(objc.IMP) &windowDelegateProc6;
 
     objc.IMP drawRectProc = OS.drawRect_CALLBACK(proc3);
     objc.IMP drawInteriorWithFrameInViewProc = OS.drawInteriorWithFrame_inView_CALLBACK (proc4);
@@ -1868,7 +1879,7 @@
     size_t size = C.PTR_SIZEOF, align_ = C.PTR_SIZEOF is 4 ? 2 : 3;
 
     String className = "SWTWindowDelegate";
-    objc.Class cls = OS.objc_allocateClassPair(OS.class_NSObject, className, 0);
+    objc.Class cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSObject, className, 0);
     OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
     OS.class_addMethod(cls, OS.sel_windowDidResize_, proc3, "@:@");
     OS.class_addMethod(cls, OS.sel_windowDidMove_, proc3, "@:@");
@@ -1969,19 +1980,19 @@
     OS.objc_registerClassPair(cls);
 
     className = "SWTTableHeaderCell";
-    cls = OS.objc_allocateClassPair (OS.class_NSTableHeaderCell, className, 0);
+    cls = OS.objc_allocateClassPair (cast(objc.Class) OS.class_NSTableHeaderCell, className, 0);
     OS.class_addIvar (cls, SWT_OBJECT, size, cast(byte)align_, types);
     OS.class_addMethod (cls, OS.sel_drawInteriorWithFrame_inView_, drawInteriorWithFrameInViewProc, "@:{NSRect}@");
     OS.objc_registerClassPair (cls);
 
     className = "SWTBrowserCell";
-    cls = OS.objc_allocateClassPair (OS.class_NSBrowserCell, className, 0);
+    cls = OS.objc_allocateClassPair (cast(objc.Class) OS.class_NSBrowserCell, className, 0);
     OS.class_addIvar (cls, SWT_OBJECT, size, cast(byte)align_, types);
     OS.class_addMethod (cls, OS.sel_drawInteriorWithFrame_inView_, drawInteriorWithFrameInViewProc, "@:{NSRect}@");
     OS.objc_registerClassPair (cls);
 
     className = "SWTTableHeaderView";
-    cls = OS.objc_allocateClassPair(OS.class_NSTableHeaderView, className, 0);
+    cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSTableHeaderView, className, 0);
     OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
     OS.class_addMethod(cls, OS.sel_mouseDown_, proc3, "@:@");
     OS.objc_registerClassPair(cls);
@@ -2144,7 +2155,7 @@
     OS.objc_registerClassPair(cls);
     
     className = "SWTEditorView";
-    cls = OS.objc_allocateClassPair(OS.class_NSTextView, className, 0);
+    cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSTextView, className, 0);
     OS.class_addMethod(cls, OS.sel_keyDown_, proc3, "@:@");
     OS.class_addMethod(cls, OS.sel_keyUp_, proc3, "@:@");
     OS.class_addMethod(cls, OS.sel_insertText_, proc3, "@:@");
@@ -2167,7 +2178,7 @@
     NSTextField.setCellClass(cls);
 
     className = "SWTSearchField";
-    cls = OS.objc_allocateClassPair(OS.class_NSSearchField, className, 0);
+    cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSSearchField, className, 0);
     OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
     addEventMethods(cls, proc2, proc3, drawRectProc);
     addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
@@ -2182,7 +2193,7 @@
     NSSearchField.setCellClass(cls);
 
     className = "SWTSecureTextField";
-    cls = OS.objc_allocateClassPair(OS.class_NSSecureTextField, className, 0);
+    cls = OS.objc_allocateClassPair(cast(objc.Class) OS.class_NSSecureTextField, className, 0);
     OS.class_addIvar(cls, SWT_OBJECT, size, cast(byte)align_, types);
     addEventMethods(cls, proc2, proc3, drawRectProc);
     addFrameMethods(cls, setFrameOriginProc, setFrameSizeProc);
@@ -2250,7 +2261,7 @@
         data.foreground = getSystemColor(DWT.COLOR_BLACK).handle;
         data.font = getSystemFont();
     }
-    return context.id_;
+    return context.id;
 }
 
 /**  
@@ -2563,7 +2574,7 @@
     pt.y = y;
     NSWindow fromWindow = from !is null ? from.view.window() : null;
     NSWindow toWindow = to !is null ? to.view.window() : null;
-    if (toWindow !is null && fromWindow !is null && toWindow.id_ is fromWindow.id_) {
+    if (toWindow !is null && fromWindow !is null && toWindow.id is fromWindow.id) {
         pt = from.view.convertPoint_toView_(pt, to.view);
     } else {
         NSRect primaryFrame = getPrimaryFrame();
@@ -2676,7 +2687,7 @@
     pt.y = y;
     NSWindow fromWindow = from !is null ? from.view.window() : null;
     NSWindow toWindow = to !is null ? to.view.window() : null;
-    if (toWindow !is null && fromWindow !is null && toWindow.id_ is fromWindow.id_) {
+    if (toWindow !is null && fromWindow !is null && toWindow.id is fromWindow.id) {
         pt = from.view.convertPoint_toView_(pt, to.view);
     } else {
         NSRect primaryFrame = getPrimaryFrame();
@@ -2740,7 +2751,7 @@
         events = true;
         application.sendEvent(event);
     }
-//      NSEvent event = NSEvent.otherEventWithType(OS.NSApplicationDefined, NSPoint(), 0, 0, 0, null, DWT_IDLE_TYPE, 0, 0);
+//      NSEvent event = NSEvent.otherEventWithType(OS.NSApplicationDefined, NSPoint(), 0, 0, 0, null, SWT_IDLE_TYPE, 0, 0);
 //      application.postEvent(event, false);
 //      idle = true;
 //      application.run();
@@ -2868,11 +2879,11 @@
     if (pool !is null) pool.release();
     pool = null;
 
-    if (application !is null && applicationClass !is 0) {
+    if (application !is null && applicationClass !is null) {
         OS.object_setClass (application.id, applicationClass);
     }
     application = null;
-    applicationClass = 0;
+    applicationClass = null;
 }
 
 void removeContext (NSGraphicsContext context) {
@@ -2956,7 +2967,7 @@
     OS.object_getInstanceVariable(view.id, SWT_OBJECT, jniRef);
     if (jniRef is null) return null;
     Widget widget = cast(Widget)OS.JNIGetObject(jniRef);
-    OS.object_setInstanceVariable(view.id, SWT_OBJECT, 0);
+    OS.object_setInstanceVariable(view.id, SWT_OBJECT, null);
     return widget;
 }
 
@@ -3035,9 +3046,9 @@
     while (popups !is null) {
         Menu menu = popups [0];
         if (menu is null) break;
-        int length = popups.length;
-        System.arraycopy (popups, 1, popups, 0, --length);
-        popups [length] = null;
+        int length_ = popups.length;
+        System.arraycopy (popups, 1, popups, 0, --length_);
+        popups [length_] = null;
 //      clearMenuFlags ();
         runDeferredEvents ();
         if (!menu.isDisposed ()) menu._setVisible (true);
@@ -3182,10 +3193,15 @@
  */
 public void setData (String key, Object value) {
     checkDevice ();
-    //if (key is null) error (DWT.ERROR_NULL_ARGUMENT);
+    //if (key is null) error (DWT.ERROR_NULL_ARGUMENT);    
     
     if (key.equals (ADD_WIDGET_KEY)) {
-        Object [] data = cast(Object [])value;
+        auto wrap = cast(ArrayWrapperObject) value;
+        
+        if (wrap is null)
+            DWT.error(DWT.ERROR_INVALID_ARGUMENT, null, " []");
+        
+        Object [] data = wrap.array;
         NSObject object = cast(NSObject)data [0];
         Widget widget = cast(Widget)data [1];
         if (widget is null) {
@@ -3571,8 +3587,8 @@
 objc.id applicationNextEventMatchingMask (objc.id id, objc.SEL sel, objc.id mask, objc.id expiration, objc.id mode, objc.id dequeue) {
     objc_super super_struct = objc_super();
     super_struct.receiver = id;
-    super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
-    objc.id result = OS.objc_msgSendSuper(super_struct, sel, mask, expiration, mode, dequeue !is null);
+    super_struct.super_class = cast(objc.Class) OS.objc_msgSend(id, OS.sel_superclass);
+    objc.id result = OS.objc_msgSendSuper(&super_struct, sel, mask, expiration, mode, dequeue !is null);
     if (result !is null) {
         if (trackingControl !is null && dequeue !is null) {
             NSEvent nsEvent = new NSEvent(result);
@@ -3645,12 +3661,12 @@
 void applicationSendEvent (objc.id id, objc.SEL sel, objc.id event) {
     NSEvent nsEvent = new NSEvent(event);
     int type = nsEvent.type ();
-    bool beep = false;
+    bool beep_ = false;
     switch (type) {
         case OS.NSLeftMouseDown:
         case OS.NSRightMouseDown:
         case OS.NSOtherMouseDown:
-            beep = true;
+            beep_ = true;
         case OS.NSLeftMouseUp:
         case OS.NSRightMouseUp:
         case OS.NSMouseMoved:
@@ -3667,7 +3683,7 @@
             if (window !is null) {
                 Shell shell = cast(Shell) getWidget (window.id);
                 if (shell !is null && shell.getModalShell () !is null) {
-                    if (beep) beep ();  
+                    if (beep_) beep ();  
                     return;
                 }
             }
@@ -3676,9 +3692,9 @@
     applicationSendMouseEvent (nsEvent, false);
     objc_super super_struct = objc_super ();
     super_struct.receiver = id;
-    super_struct.super_class = OS.objc_msgSend (id, OS.sel_superclass);
-    OS.objc_msgSendSuper (super_struct, sel, event);
-//  if (nsEvent.type() is OS.NSApplicationDefined && nsEvent.subtype() is DWT_IDLE_TYPE) {
+    super_struct.super_class = cast(objc.Class) OS.objc_msgSend (id, OS.sel_superclass);
+    OS.objc_msgSendSuper (&super_struct, sel, event);
+//  if (nsEvent.type() is OS.NSApplicationDefined && nsEvent.subtype() is SWT_IDLE_TYPE) {
 //      idle = true;
 //  } else {
 //      idle = false;
@@ -3689,17 +3705,17 @@
 extern (C):
 
 // #245724: [NSApplication isRunning] must return true to allow the AWT to load correctly.
-static objc.id applicationProc2(objc.id id, objc.SEL sel) {
+static objc.id applicationProc2(objc.id id, objc.SEL sel) {println("applicationProc2");
     //TODO optimize getting the display
     Display display = getCurrent ();
     if (display is null) return null;
     if (sel is OS.sel_isRunning) {
-        return cast(objc.id) (display.isDisposed() ? null : 1);
+        return cast(objc.id) (display.isDisposed() ? null : cast(objc.id) 1);
     }
     return null;
 }
 
-static objc.id applicationProc3(objc.id id, objc.SEL sel, objc.id event) {
+static objc.id applicationProc3(objc.id id, objc.SEL sel, objc.id event) {println("applicationProc3");
     //TODO optimize getting the display
     Display display = getCurrent ();
     if (display is null) return null;
@@ -3710,7 +3726,7 @@
     return null;
 }
 
-static objc.id applicationProc6(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1, objc.id arg2, objc.id arg3) {
+static objc.id applicationProc6(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1, objc.id arg2, objc.id arg3) {println("applicationProc6");
     //TODO optimize getting the display
     Display display = getCurrent ();
     if (display is null) return null;
@@ -3724,14 +3740,14 @@
     //TODO optimize getting the display
     Display display = getCurrent ();
     if (display is null) return null;
-    id applicationDelegate = display.applicationDelegate;
+    cocoa.id applicationDelegate = display.applicationDelegate;
     NSApplication application = display.application;
     if (sel is OS.sel_applicationWillFinishLaunching_) {
         NSDictionary dict = NSDictionary.dictionaryWithObject(applicationDelegate, NSString.stringWith("NSOwner"));
         NSString nibFile = NSString.stringWith("/System/Library/Frameworks/JavaVM.framework/Resources/English.lproj/DefaultApp.nib");
-        if (!NSBundle.loadNibFile(nibFile, dict, 0)) {
+        if (!NSBundle.loadNibFile(nibFile, dict, null)) {
             nibFile = NSString.stringWith("/System/Library/Frameworks/JavaVM.framework/Versions/1.5.0/Resources/English.lproj/DefaultApp.nib");
-            NSBundle.loadNibFile(nibFile, dict, 0); 
+            NSBundle.loadNibFile(nibFile, dict, null); 
         }
         //replace %@ with application name
         NSMenu mainmenu = application.mainMenu();
@@ -3749,7 +3765,7 @@
         application.terminate(application);
     } else if (sel is OS.sel_orderFrontStandardAboutPanel_) {
 //      Event event = new Event ();
-//      sendEvent (SWT.ABORT, event);
+//      sendEvent (DWT.ABORT, event);
     } else if (sel is OS.sel_hideOtherApplications_) {
         application.hideOtherApplications(application);
     } else if (sel is OS.sel_hide_) {
@@ -3759,12 +3775,12 @@
     } else if (sel is OS.sel_applicationShouldTerminate_) {
         if (!display.disposing) {
             Event event = new Event ();
-            display.sendEvent (SWT.Close, event);
+            display.sendEvent (DWT.Close, event);
             if (event.doit) {
-                return OS.NSTerminateNow;
+                return cast(objc.id) OS.NSTerminateNow;
             }
         }
-        return OS.NSTerminateCancel;
+        return cast(objc.id) OS.NSTerminateCancel;
     } else if (sel is OS.sel_applicationWillTerminate_) {
         display.dispose();
     } else if (sel is OS.sel_applicationWillResignActive_) {
@@ -3776,19 +3792,19 @@
     return null;
 }
 
-static objc.id dialogProc(objc.id id, objc.SEL selector, objc.id arg0) { 
+static objc.id dialogProc(objc.id id, objc.SEL sel, objc.id arg0) { 
     void* jniRef;
     OS.object_getInstanceVariable(id, SWT_OBJECT, jniRef);
     if (jniRef is null) return null;
-    if (sel == OS.sel_changeColor_) {
+    if (sel is OS.sel_changeColor_) {
         ColorDialog dialog = cast(ColorDialog)OS.JNIGetObject(jniRef);
-    if (jniRef is null) return null;
+        if (jniRef is null) return null;
         dialog.changeColor(id, sel, arg0);
-    } else if (sel == OS.sel_changeFont_) {
+    } else if (sel is OS.sel_changeFont_) {
         FontDialog dialog = cast(FontDialog)OS.JNIGetObject(jniRef);
         if (dialog is null) return null;
         dialog.changeFont(id, sel, arg0);
-    } else if (sel == OS.sel_windowWillClose_) {
+    } else if (sel is OS.sel_windowWillClose_) {
         Object object = OS.JNIGetObject(jniRef);
         if (cast(FontDialog) object) {
             (cast(FontDialog)object).windowWillClose(id, sel, arg0);
@@ -3799,7 +3815,7 @@
     return null;
 }
 	
-static objc.id windowDelegateProc2(objc.id id, objc.SEL selector) {
+static objc.id windowDelegateProc2(objc.id id, objc.SEL sel) {
     Widget widget = GetWidget(id);
     if (widget is null) return null;
     if (sel is OS.sel_sendSelection) {
@@ -3827,14 +3843,14 @@
     } else if (sel is OS.sel_markedRange) {
         NSRange range = widget.markedRange (id, sel);
         /* NOTE that this is freed in C */
-        objc.id result = OS.malloc (NSRange.sizeof);
-        OS.memmove (result, range, NSRange.sizeof);
+        objc.id result = cast(objc.id) OS.malloc (NSRange.sizeof);
+        OS.memmove (result, &range, NSRange.sizeof);
         return result;
     } else if (sel is OS.sel_selectedRange) {
         NSRange range = widget.selectedRange (id, sel);
         /* NOTE that this is freed in C */
-        objc.id result = OS.malloc (NSRange.sizeof);
-        OS.memmove (result, range, NSRange.sizeof);
+        objc.id result = cast(objc.id) OS.malloc (NSRange.sizeof);
+        OS.memmove (result, &range, NSRange.sizeof);
         return result;
     } else if (sel is OS.sel_hasMarkedText) {
         return widget.hasMarkedText (id, sel) ? cast(objc.id) 1 : null;
@@ -3854,7 +3870,7 @@
     return null;
 }
 
-static objc.id windowDelegateProc3(objc.id ID, objc.SEL selector, objc.id arg0) {
+static objc.id windowDelegateProc3(objc.id id, objc.SEL sel, objc.id arg0) {
     if (sel is OS.sel_timerProc_) {
         //TODO optimize getting the display
         Display display = getCurrent ();
@@ -3865,24 +3881,24 @@
     if (widget is null && (sel is OS.sel_keyDown_ ||sel is OS.sel_keyUp_ ||sel is OS.sel_insertText_ ||sel is OS.sel_doCommandBySelector_))  {
         widget = GetFocusControl ((new NSView (id)).window ());
     }
-    if (widget is null) return 0;
+    if (widget is null) return null;
     if (sel is OS.sel_windowWillClose_) {
         widget.windowWillClose(id, sel, arg0);
     } else if (sel is OS.sel_drawRect_) {
-        NSRect rect = new NSRect();
-        OS.memmove(rect, arg0, NSRect.sizeof);
+        NSRect rect = NSRect();
+        OS.memmove(&rect, arg0, NSRect.sizeof);
         widget.drawRect(id, sel, rect);
     } else if (sel is OS.sel_setFrameOrigin_) {
-        NSPoint point = new NSPoint();
-        OS.memmove(point, arg0, NSPoint.sizeof);
+        NSPoint point = NSPoint();
+        OS.memmove(&point, arg0, NSPoint.sizeof);
         widget.setFrameOrigin(id, sel, point);
     } else if (sel is OS.sel_setFrameSize_) {
-        NSSize size = new NSSize();
-        OS.memmove(size, arg0, NSSize.sizeof);
+        NSSize size = NSSize();
+        OS.memmove(&size, arg0, NSSize.sizeof);
         widget.setFrameSize(id, sel, size);
     } else if (sel is OS.sel_hitTest_) {
-        NSPoint point = new NSPoint();
-        OS.memmove(point, arg0, NSPoint.sizeof);
+        NSPoint point = NSPoint();
+        OS.memmove(&point, arg0, NSPoint.sizeof);
         return widget.hitTest(id, sel, point);
     } else if (sel is OS.sel_windowShouldClose_) {
         return widget.windowShouldClose(id, sel, arg0) ? cast(objc.id) 1 : null;
@@ -3915,7 +3931,7 @@
     } else if (sel is OS.sel_menuForEvent_) {
         return widget.menuForEvent(id, sel, arg0);
     } else if (sel is OS.sel_numberOfRowsInTableView_) {
-        return widget.numberOfRowsInTableView(id, sel, arg0);
+        return cast(objc.id) widget.numberOfRowsInTableView(id, sel, arg0);
     } else if (sel is OS.sel_comboBoxSelectionDidChange_) {
         widget.comboBoxSelectionDidChange(id, sel, arg0);
     } else if (sel is OS.sel_tableViewSelectionDidChange_) {
@@ -3955,24 +3971,24 @@
     } else if (sel is OS.sel_attributedSubstringFromRange_) {
         return widget.attributedSubstringFromRange (id, sel, arg0);
     } else if (sel is OS.sel_characterIndexForPoint_) {
-        return widget.characterIndexForPoint (id, sel, arg0);
+        return cast(objc.id) widget.characterIndexForPoint (id, sel, arg0);
     } else if (sel is OS.sel_firstRectForCharacterRange_) {
         NSRect rect = widget.firstRectForCharacterRange (id, sel, arg0);
         /* NOTE that this is freed in C */
-        objc.id result = OS.malloc (NSRect.sizeof);
-        OS.memmove (result, rect, NSRect.sizeof);
+        objc.id result = cast(objc.id) OS.malloc (NSRect.sizeof);
+        OS.memmove (result, &rect, NSRect.sizeof);
         return result;
     } else if (sel is OS.sel_insertText_) {
         widget.insertText (id, sel, arg0);
     } else if (sel is OS.sel_doCommandBySelector_) {
-        widget.doCommandBySelector (id, sel, arg0);
+        widget.doCommandBySelector (id, sel, cast(char*) arg0);
     } else if (sel is OS.sel_highlightSelectionInClipRect_) {
         widget.highlightSelectionInClipRect (id, sel, arg0);
     } else if (sel is OS.sel_reflectScrolledClipView_) {
         widget.reflectScrolledClipView (id, sel, arg0);
     } else if (sel is OS.sel_accessibilityHitTest_) {
-        NSPoint point = new NSPoint();
-        OS.memmove(point, arg0, NSPoint.sizeof);
+        NSPoint point = NSPoint();
+        OS.memmove(&point, arg0, NSPoint.sizeof);
         return widget.accessibilityHitTest(id, sel, point);
     } else if (sel is OS.sel_accessibilityAttributeValue_) {
         return widget.accessibilityAttributeValue(id, sel, arg0);
@@ -3996,7 +4012,7 @@
     return null;
 }
 
-static objc.id windowDelegateProc4(objc.id id, objc.SEL selector, objc.id arg0, objc.id arg1) {
+static objc.id windowDelegateProc4(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1) {
     Widget widget = GetWidget(id);
     if (widget is null) return null;
     if (sel is OS.sel_tabView_willSelectTabViewItem_) {
@@ -4006,7 +4022,7 @@
     } else if (sel is OS.sel_outlineView_isItemExpandable_) {
         return widget.outlineView_isItemExpandable(id, sel, arg0, arg1) ? cast(objc.id) 1 : null;
     } else if (sel is OS.sel_outlineView_numberOfChildrenOfItem_) {
-        return widget.outlineView_numberOfChildrenOfItem(id, sel, arg0, arg1);
+        return cast(objc.id) widget.outlineView_numberOfChildrenOfItem(id, sel, arg0, arg1);
     } else if (sel is OS.sel_outlineView_shouldCollapseItem_) {
         return widget.outlineView_shouldCollapseItem(id, sel, arg0, arg1) ? cast(objc.id) 1 : null;
     } else if (sel is OS.sel_outlineView_shouldExpandItem_) {
@@ -4027,7 +4043,7 @@
     return null;
 }
 
-static objc.id windowDelegateProc5(objc.id id, objc.SEL selector, objc.id arg0, objc.id arg1, objc.id arg2) {
+static objc.id windowDelegateProc5(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1, objc.id arg2) {
     Widget widget = GetWidget(id);
     if (widget is null) return null;
     if (sel is OS.sel_tableView_objectValueForTableColumn_row_) {
@@ -4043,14 +4059,14 @@
     } else if (sel is OS.sel_textView_willChangeSelectionFromCharacterRange_toCharacterRange_) {
         NSRange range = widget.textView_willChangeSelectionFromCharacterRange_toCharacterRange(id, sel, arg0, arg1, arg2);
         /* NOTE that this is freed in C */
-        objc.id result = OS.malloc (NSRange.sizeof);
-        OS.memmove (result, range, NSRange.sizeof);
+        objc.id result = cast(objc.id) OS.malloc (NSRange.sizeof);
+        OS.memmove (result, &range, NSRange.sizeof);
         return result;
     }
     return null;
 }
 
-static objc.id windowDelegateProc6(objc.id id, objc.SEL selector, objc.id arg0, objc.id arg1, objc.id arg2, objc.id arg3) {
+static objc.id windowDelegateProc6(objc.id id, objc.SEL sel, objc.id arg0, objc.id arg1, objc.id arg2, objc.id arg3) {
     Widget widget = GetWidget(id);
     if (widget is null) return null;
     if (sel is OS.sel_tableView_willDisplayCell_forTableColumn_row_) {