diff dwt/widgets/Widget.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents 642f460a0908
children cfa563df4fdd
line wrap: on
line diff
--- a/dwt/widgets/Widget.d	Tue Oct 21 15:20:04 2008 +0200
+++ b/dwt/widgets/Widget.d	Mon Dec 01 17:07:00 2008 +0100
@@ -1,5 +1,5 @@
-/*******************************************************************************
- * Copyright (c) 2000, 2007 IBM Corporation and others.
+/*******************************************************************************
+ * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
  * which accompanies this distribution, and is available at
@@ -9,7 +9,7 @@
  *     IBM Corporation - initial API and implementation
  *     
  * Port to the D programming language:
- *     Jacob Carlborg <jacob.carlborg@gmail.com>
+ *     Jacob Carlborg <doob@me.com>
  *******************************************************************************/
 module dwt.widgets.Widget;
 
@@ -20,8 +20,16 @@
 import dwt.DWTException;
 import dwt.events.DisposeListener;
 import dwt.internal.DWTEventListener;
+import dwt.internal.cocoa.NSArray;
+import dwt.internal.cocoa.NSBezierPath;
 import dwt.internal.cocoa.NSEvent;
+import dwt.internal.cocoa.NSGraphicsContext;
+import dwt.internal.cocoa.NSPasteboard;
+import dwt.internal.cocoa.NSPoint;
+import dwt.internal.cocoa.NSRange;
 import dwt.internal.cocoa.NSRect;
+import dwt.internal.cocoa.NSSize;
+import dwt.internal.cocoa.NSString;
 import dwt.internal.cocoa.OS;
 import dwt.internal.cocoa.objc_super;
 
@@ -34,7 +42,6 @@
 import dwt.widgets.EventTable;
 import dwt.widgets.Listener;
 import dwt.widgets.TypedListener;
-
 /**
  * This class is the abstract superclass of all user interface objects.  
  * Widgets are created, disposed and issue notification to listeners
@@ -60,6 +67,7 @@
  * </p>
  *
  * @see #checkSubclass
+ * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public abstract class Widget {
     int style, state;
@@ -67,7 +75,7 @@
     EventTable eventTable;
     Object data;
 
-    NSInteger jniRef;
+    char* jniRef;
 
     /* Global state flags */
     static const int DISPOSED         = 1 << 0;
@@ -146,23 +154,136 @@
     display = parent.display;
 }
 
-void callSuper(objc.id id, String selector, objc.id arg0) {
-    objc_super super_struct;
+int accessibilityActionDescription(objc.id id, objc.SEL sel, objc.id arg0) {
+    return callSuperObject(id, sel, arg0);
+}
+
+int accessibilityActionNames(int /*long*/ id, int /*long*/ sel) {
+    return callSuperObject(id, sel);
+}
+
+int accessibilityAttributeNames(int /*long*/ id, int /*long*/ sel) {
+    return callSuperObject(id, sel);
+}
+
+int accessibilityAttributeValue(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
+    return callSuperObject(id, sel, arg0);
+}
+
+int accessibilityAttributeValue_forParameter(int id, int sel, int /*long*/ arg0, int /*long*/ arg1) {
+    super_struct.receiver = id;
+    super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
+    return OS.objc_msgSendSuper(super_struct, sel, arg0, arg1);
+}
+
+int accessibilityFocusedUIElement(int /*long*/ id, int /*long*/ sel) {
+    return callSuperObject(id, sel);
+}
+
+int accessibilityHitTest(int /*long*/ id, int /*long*/ sel, NSPoint point) {
+    objc_super super_struct = new objc_super();
     super_struct.receiver = id;
-    super_struct.cls = cast(objc.Class) OS.objc_msgSend(id, OS.sel_superclass);
-    OS.objc_msgSendSuper(&super_struct, selector, arg0);
+    super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
+    return OS.objc_msgSendSuper(super_struct, sel, point);
+}
+
+bool accessibilityIsAttributeSettable(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
+    return callSuperBoolean(id, sel, arg0);
+}
+
+bool accessibilityIsIgnored(int /*long*/ id, int /*long*/ sel) {
+    return callSuperBoolean(id, sel);
+}
+
+int accessibilityParameterizedAttributeNames(int /*long*/ id, int /*long*/ sel) {
+    return callSuperObject(id, sel);
+}
+
+void accessibilityPerformAction(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
+    callSuper(id, sel, arg0);
+}
+
+String getClipboardText () {
+    NSPasteboard pasteboard = NSPasteboard.generalPasteboard ();
+    NSString string = pasteboard.stringForType (OS.NSStringPboardType);
+    return string !is null ? string.getString () : null;
+}
+
+NSBezierPath getClipping () {
+    return null;
+}
+
+int /*long*/ attributedSubstringFromRange (int /*long*/ id, int /*long*/ sel, int /*long*/ range) {
+    return 0;
 }
 
-bool acceptsFirstResponder () {
-    return false;
+void callSuper(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
+    objc_super super_struct = new objc_super();
+    super_struct.receiver = id;
+    super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
+    OS.objc_msgSendSuper(super_struct, sel, arg0);
+}
+
+void callSuper(int /*long*/ id, int /*long*/ sel, NSRect arg0) {
+    objc_super super_struct = new objc_super();
+    super_struct.receiver = id;
+    super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
+    OS.objc_msgSendSuper(super_struct, sel, arg0);
+}
+
+void callSuper(int /*long*/ id, int /*long*/ sel, NSRect arg0, int /*long*/ arg1) {
+    objc_super super_struct = new objc_super();
+    super_struct.receiver = id;
+    super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
+    OS.objc_msgSendSuper(super_struct, sel, arg0, arg1);
+}
+
+bool callSuperBoolean(int /*long*/ id, int /*long*/ sel) {
+    objc_super super_struct = new objc_super();
+    super_struct.receiver = id;
+    super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
+    return OS.objc_msgSendSuper(super_struct, sel) !is 0;
+}
+
+bool canBecomeKeyWindow (int /*long*/ id, int /*long*/ sel) {
+    return callSuperBoolean (id, sel);
 }
 
-bool becomeFirstResponder () {
-    return true;
+bool callSuperBoolean(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
+    objc_super super_struct = new objc_super();
+    super_struct.receiver = id;
+    super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
+    return OS.objc_msgSendSuper(super_struct, sel, arg0) !is 0;
+}
+
+int callSuperObject(int /*long*/ id, int /*long*/ sel) {
+    objc_super super_struct = new objc_super();
+    super_struct.receiver = id;
+    super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
+    return OS.objc_msgSendSuper(super_struct, sel);
 }
 
-bool resignFirstResponder () {
-    return true;
+int callSuperObject(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
+    objc_super super_struct = new objc_super();
+    super_struct.receiver = id;
+    super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
+    return OS.objc_msgSendSuper(super_struct, sel, arg0);
+}
+
+int /*long*/ characterIndexForPoint (int /*long*/ id, int /*long*/ sel, int /*long*/ point) {
+    return OS.NSNotFound;
+}
+
+bool acceptsFirstResponder (int /*long*/ id, int /*long*/ sel) {
+    return callSuperBoolean(id, sel);
+}
+
+bool becomeFirstResponder (int /*long*/ id, int /*long*/ sel) {
+    return callSuperBoolean(id, sel);
+}
+
+bool resignFirstResponder (int /*long*/ id, int /*long*/ sel) {
+    return callSuperBoolean(id, sel);
 }
 
 /**
@@ -185,6 +306,7 @@
  *
  * @see Listener
  * @see DWT
+ * @see #getListeners(int)
  * @see #removeListener(int, Listener)
  * @see #notifyListeners
  */
@@ -317,15 +439,22 @@
 public void checkWidget () {
     Display display = this.display;
     if (display is null) error (DWT.ERROR_WIDGET_DISPOSED);
-    if (display.thread !is Thread.getThis ()) error (DWT.ERROR_THREAD_INVALID_ACCESS);
+    if (display.thread !is Thread.getThis () && !display.isEmbedded) error (DWT.ERROR_THREAD_INVALID_ACCESS);
     if ((state & DISPOSED) !is 0) error (DWT.ERROR_WIDGET_DISPOSED);
 }
 
-bool clickOnLink(int textView, int link, int charIndex) {
+bool textView_clickOnLink_atIndex(int /*long*/ id, int /*long*/ sel, int /*long*/ textView, int /*long*/ link, int /*long*/ charIndex) {
     return true;
 }
 
-void comboBoxSelectionDidChange(int notification) {
+void comboBoxSelectionDidChange(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
+}
+
+void copyToClipboard (char [] buffer) {
+    if (buffer.length is 0) return;
+    NSPasteboard pasteboard = NSPasteboard.generalPasteboard ();
+    pasteboard.declareTypes (NSArray.arrayWithObject (OS.NSStringPboardType), null);
+    pasteboard.setString (NSString.stringWithCharacters (buffer, buffer.length), OS.NSStringPboardType);
 }
 
 void createHandle () {
@@ -339,6 +468,15 @@
 void createWidget () {
     createJNIRef ();
     createHandle ();
+    register ();
+}
+    
+void deregister () {
+}
+
+void destroyJNIRef () {
+    if (jniRef !is 0) OS.DeleteGlobalRef (jniRef);
+    jniRef = 0;
 }
 
 void destroyWidget () {
@@ -378,18 +516,36 @@
     release (true);
 }
 
+void doCommandBySelector (int /*long*/ id, int /*long*/ sel, int /*long*/ aSelector) {
+    callSuper (id, sel, aSelector);
+}
+
 void drawBackground (int control, int context) {
     /* Do nothing */
 }
 
-void drawRect(objc.id id, NSRect rect) {
-    objc_super super_struct;
-    super_struct.receiver = id;
-    super_struct.cls = cast(objc.Class) OS.objc_msgSend(id, OS.sel_superclass);
-    OS.objc_msgSendSuper(&super_struct, OS.sel_drawRect_1, rect);
+void drawInteriorWithFrame_inView (int /*long*/ id, int /*long*/ sel, int /*long*/ cellFrame, int /*long*/ view) {
 }
 
-void drawWidget (int control, int context, int damageRgn, int visibleRgn, int theEvent) {
+void drawRect (int /*long*/ id, int /*long*/ sel, NSRect rect) {
+    //TODO offset region to view coordinates
+    //TODO use region from control as well shell region
+    NSGraphicsContext current = NSGraphicsContext.currentContext();
+    NSBezierPath path = getClipping ();
+    if (path !is null) {
+        current.saveGraphicsState();
+        path.addClip ();
+    }
+    super_struct.receiver = id;
+    super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
+    OS.objc_msgSendSuper(super_struct, sel, rect);
+    drawWidget (id, rect);
+    if (path !is null) {
+        current.restoreGraphicsState();
+    }
+}
+
+void drawWidget (int /*long*/ id, NSRect rect) {
 }
 
 void error (int code) {
@@ -400,8 +556,10 @@
     return display.filters (eventType);
 }
 
-NSUInteger fixMnemonic (char [] buffer) {
-    NSUInteger i=0, j=0;
+NSRect firstRectForCharacterRange(int /*long*/ id, int /*long*/ sel, int /*long*/ range) {
+    return new NSRect ();
+}
+
     while (i < buffer.length) {
         if ((buffer [j++] = buffer [i++]) is '&') {
             if (i is buffer.length) {continue;}
@@ -560,7 +718,21 @@
     return style;
 }
 
-void helpRequested(int theEvent) {
+bool hasMarkedText (int /*long*/ id, int /*long*/ sel) {
+    return false;
+}
+
+void helpRequested(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+}
+
+void highlightSelectionInClipRect(int /*long*/ id, int /*long*/ sel, int /*long*/ rect) {   
+}
+
+int /*long*/ hitTest (int /*long*/ id, int /*long*/ sel, NSPoint point) {
+    objc_super super_struct = new objc_super();
+    super_struct.receiver = id;
+    super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
+    return OS.objc_msgSendSuper(super_struct, sel, point);
 }
 
 bool hooks (int eventType) {
@@ -568,6 +740,11 @@
     return eventTable.hooks (eventType);
 }
 
+bool insertText (int /*long*/ id, int /*long*/ sel, int /*long*/ string) {
+    callSuper (id, sel, string);
+    return true;
+}
+
 /**
  * Returns <code>true</code> if the widget has been disposed,
  * and <code>false</code> otherwise.
@@ -583,7 +760,7 @@
     return (state & DISPOSED) !is 0;
 }
 
-bool isFlipped () {
+bool isFlipped (int /*long*/ id, int /*long*/ sel) {
     return true;
 }
 
@@ -608,7 +785,7 @@
     return hooks (eventType);
 }
 
-bool isTrimHandle (int trimHandle) {
+bool isOpaque(int /*long*/ id, int /*long*/ sel) {
     return false;
 }
 
@@ -620,75 +797,136 @@
     return getDisplay ().isValidThread ();
 }
 
-void flagsChanged(int event) {
+void flagsChanged (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+    callSuper (id, sel, theEvent);
+}
+
+void keyDown (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+    callSuper(id, sel, theEvent);
+}
+
+void keyUp (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+    callSuper(id, sel, theEvent);
+}
+
+void mouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+    callSuper(id, sel, theEvent);
 }
 
-void mouseDragged(int event) {
+void mouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+    callSuper(id, sel, theEvent);
+}
+
+void rightMouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+    callSuper(id, sel, theEvent);
 }
 
-void mouseDown(int event) {
+void rightMouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+    callSuper(id, sel, theEvent);
+}
+
+void otherMouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+    callSuper(id, sel, theEvent);
+}
+
+void otherMouseUp(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+    callSuper(id, sel, theEvent);
+}
+
+void mouseMoved(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+    callSuper(id, sel, theEvent);
 }
 
-void rightMouseDown(int event) {
+void mouseDragged(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+    callSuper(id, sel, theEvent);
+}
+
+void mouseEntered(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+    callSuper(id, sel, theEvent);
+}
+
+void mouseExited(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+    callSuper(id, sel, theEvent);
+}
+
+bool menuHasKeyEquivalent_forEvent_target_action(int /*long*/ id, int /*long*/ sel, int /*long*/ menu, int /*long*/ event, int /*long*/ target, int /*long*/ action) {
+    return true;
 }
 
-void mouseEntered(int event) {
+int /*long*/ menuForEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+    objc_super super_struct = new objc_super();
+    super_struct.receiver = id;
+    super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
+    return OS.objc_msgSendSuper(super_struct, sel, theEvent);
+}
+
+void menuNeedsUpdate(int /*long*/ id, int /*long*/ sel, int /*long*/ menu) {
+}
+
+bool makeFirstResponder(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
+    return callSuperBoolean(id, sel, notification);
 }
 
-void mouseUp(int event) {
+NSRange markedRange (int /*long*/ id, int /*long*/ sel) {
+    return new NSRange ();
+}
+
+void menu_willHighlightItem(int /*long*/ id, int /*long*/ sel, int /*long*/ menu, int /*long*/ item) {
 }
 
-int menuForEvent (int event) {
+void menuDidClose(int /*long*/ id, int /*long*/ sel, int /*long*/ menu) {
+}
+
+void menuWillOpen(int /*long*/ id, int /*long*/ sel, int /*long*/ menu) {
+}
+
+int /*long*/ numberOfRowsInTableView(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView) {
     return 0;
 }
 
-void menuNeedsUpdate(int menu) {
-}
-
-void menu_willHighlightItem(int menu, int item) {
-}
-
-void menuWillClose(int menu) {
-}
-
-void menuWillOpen(int menu) {
-}
-
-int numberOfRowsInTableView(int aTableView) {
+int /*long*/ outlineView_child_ofItem(int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ index, int /*long*/ item) {
     return 0;
 }
 
-int outlineView_child_ofItem(int outlineView, int index, int item) {
+void outlineView_didClickTableColumn(int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ tableColumn) {
+}
+
+int /*long*/ outlineView_objectValueForTableColumn_byItem(int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ tableColumn, int /*long*/ item) {
     return 0;
 }
 
-int outlineView_objectValueForTableColumn_byItem(int outlineView, int tableColumn, int item) {
+bool outlineView_isItemExpandable(int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ item) {
+    return false;
+}
+
+int /*long*/ outlineView_numberOfChildrenOfItem(int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ item) {
     return 0;
 }
 
-bool outlineView_isItemExpandable(int outlineView, int item) {
+void outlineView_willDisplayCell_forTableColumn_item(int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ cell, int /*long*/ tableColumn, int /*long*/ item) {
+}
+
+bool outlineView_shouldCollapseItem(int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ item) {
+    return false;
+}
+
+bool outlineView_shouldExpandItem(int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ item) {
     return false;
 }
 
-int outlineView_numberOfChildrenOfItem(int outlineView, int item) {
-    return 0;
+void outlineViewColumnDidMove (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
 }
 
-void outlineView_willDisplayCell_forTableColumn_item(int outlineView, int cell, int tableColumn, int item) {
+void outlineViewColumnDidResize (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
 }
 
-bool outlineView_shouldCollapseItem(int outlineView, int item) {
-    return false;
+void outlineViewItemDidExpand(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
 }
 
-bool outlineView_shouldExpandItem(int outlineView, int item) {
-    return false;
+void outlineViewSelectionDidChange(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
 }
 
-void outlineViewSelectionDidChange(int notification) {
-}
-
-void outlineView_setObjectValue_forTableColumn_byItem(int outlineView, int object, int tableColumn, int item) {
+void outlineView_setObjectValue_forTableColumn_byItem(int /*long*/ id, int /*long*/ sel, int /*long*/ outlineView, int /*long*/ object, int /*long*/ tableColumn, int /*long*/ item) {
 }
 
 /**
@@ -708,6 +946,7 @@
  * 
  * @see DWT
  * @see #addListener
+ * @see #getListeners(int)
  * @see #removeListener(int, Listener)
  */
 public void notifyListeners (int eventType, Event event) {
@@ -716,6 +955,14 @@
     sendEvent (eventType, event);
 }
 
+void pageDown (int /*long*/ id, int /*long*/ sel, int /*long*/ sender) {
+    callSuper(id, sel, sender);
+}
+
+void pageUp (int /*long*/ id, int /*long*/ sel, int /*long*/ sender) {
+    callSuper(id, sel, sender);
+}
+
 void postEvent (int eventType) {
     sendEvent (eventType, null, false);
 }
@@ -724,6 +971,13 @@
     sendEvent (eventType, event, false);
 }
 
+void reflectScrolledClipView (int /*long*/ id, int /*long*/ sel, int /*long*/ aClipView) {
+    callSuper (id, sel, aClipView);
+}
+
+void register () {
+}
+
 void release (bool destroy) {
     if ((state & DISPOSE_SENT) is 0) {
         state |= DISPOSE_SENT;
@@ -751,8 +1005,7 @@
 void releaseHandle () {
     state |= DISPOSED;
     display = null;
-    if (jniRef !is 0) OS.DeleteGlobalRef(jniRef);
-    jniRef = 0;
+    destroyJNIRef ();
 }
 
 void releaseParent () {
@@ -760,6 +1013,7 @@
 }
 
 void releaseWidget () {
+    deregister ();
     eventTable = null;
     data = null;
 }
@@ -770,7 +1024,7 @@
  * type is one of the event constants defined in class <code>DWT</code>.
  *
  * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified when the event occurs
+ * @param listener the listener which should no longer be notified
  *
  * @exception IllegalArgumentException <ul>
  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
@@ -783,6 +1037,7 @@
  * @see Listener
  * @see DWT
  * @see #addListener
+ * @see #getListeners(int)
  * @see #notifyListeners
  */
 public void removeListener (int eventType, Listener handler) {
@@ -803,7 +1058,7 @@
  * </p>
  *
  * @param eventType the type of event to listen for
- * @param listener the listener which should no longer be notified when the event occurs
+ * @param listener the listener which should no longer be notified
  *
  * @exception IllegalArgumentException <ul>
  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
@@ -827,7 +1082,7 @@
  * Removes the listener from the collection of listeners who will
  * be notified when the widget is disposed.
  *
- * @param listener the listener which should no longer be notified when the receiver is disposed
+ * @param listener the listener which should no longer be notified
  *
  * @exception IllegalArgumentException <ul>
  *    <li>ERROR_NULL_ARGUMENT - if the listener is null</li>
@@ -847,7 +1102,15 @@
     eventTable.unhook (DWT.Dispose, listener);
 }
 
-void sendArrowSelection () {
+void scrollWheel (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+    callSuper(id, sel, theEvent);
+}
+
+NSRange selectedRange (int /*long*/ id, int /*long*/ sel) {
+    return new NSRange ();
+}
+
+void sendDoubleSelection() {
 }
 
 void sendEvent (Event event) {
@@ -883,34 +1146,11 @@
     }
 }
 
-bool sendKeyEvent (int type, int theEvent) {
-//  int [] length = new int [1];
-//  int status = OS.GetEventParameter (theEvent, OS.kEventParamKeyUnicodes, OS.typeUnicodeText, null, 4, length, (char[])null);
-//  if (status is OS.noErr && length [0] > 2) {
-//      int count = 0;
-//      int [] chord = new int [1];
-//      OS.GetEventParameter (theEvent, OS.kEventParamMouseChord, OS.typeUInt32, null, 4, null, chord);
-//      int [] modifiers = new int [1];
-//      OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
-//      char [] chars = new char [length [0] / 2];
-//      OS.GetEventParameter (theEvent, OS.kEventParamKeyUnicodes, OS.typeUnicodeText, null, chars.length * 2, null, chars);
-//      for (int i=0; i<chars.length; i++) {
-//          Event event = new Event ();
-//          event.character = chars [i];
-//          setInputState (event, type, chord [0], modifiers [0]);
-//          if (sendKeyEvent (type, event)) chars [count++] = chars [i];
-//      }
-//      if (count is 0) return false;
-//      if (count !is chars.length - 1) {
-//          OS.SetEventParameter (theEvent, OS.kEventParamKeyUnicodes, OS.typeUnicodeText, count * 2, chars);
-//      }
-//      return true;
-//  } else {
-//      Event event = new Event ();
-//      if (!setKeyState (event, type, theEvent)) return true;
-//      return sendKeyEvent (type, event);
-//  }
-    return false;
+bool sendKeyEvent (NSEvent nsEvent, int type) {
+    if ((state & SAFARI_EVENTS_FIX) !is 0) return true;
+    Event event = new Event ();
+    if (!setKeyState (event, type, nsEvent)) return true;
+    return sendKeyEvent (type, event);
 }
 
 bool sendKeyEvent (int type, Event event) {
@@ -927,9 +1167,6 @@
     return event.doit;
 }
 
-void sendDoubleSelection() {
-}
-
 void sendHorizontalSelection () {
 }
 
@@ -1045,200 +1282,161 @@
     }
 }
 
-bool setInputState (Event event, int type, int chord, int modifiers) {
-//  if ((chord & 0x01) !is 0) event.stateMask |= DWT.BUTTON1;
-//  if ((chord & 0x02) !is 0) event.stateMask |= DWT.BUTTON3;
-//  if ((chord & 0x04) !is 0) event.stateMask |= DWT.BUTTON2;
-//  if ((chord & 0x08) !is 0) event.stateMask |= DWT.BUTTON4;
-//  if ((chord & 0x10) !is 0) event.stateMask |= DWT.BUTTON5;
-//  
-//  if ((modifiers & OS.optionKey) !is 0) event.stateMask |= DWT.ALT;
-//  if ((modifiers & OS.shiftKey) !is 0) event.stateMask |= DWT.SHIFT;
-//  if ((modifiers & OS.controlKey) !is 0) event.stateMask |= DWT.CONTROL;
-//  if ((modifiers & OS.cmdKey) !is 0) event.stateMask |= DWT.COMMAND;
-//  switch (type) {
-//      case DWT.MouseDown:
-//      case DWT.MouseDoubleClick:
-//          if (event.button is 1) event.stateMask &= ~DWT.BUTTON1;
-//          if (event.button is 2) event.stateMask &= ~DWT.BUTTON2;
-//          if (event.button is 3)  event.stateMask &= ~DWT.BUTTON3;
-//          if (event.button is 4)  event.stateMask &= ~DWT.BUTTON4;
-//          if (event.button is 5)  event.stateMask &= ~DWT.BUTTON5;
-//          break;
-//      case DWT.MouseUp:
-//          if (event.button is 1) event.stateMask |= DWT.BUTTON1;
-//          if (event.button is 2) event.stateMask |= DWT.BUTTON2;
-//          if (event.button is 3) event.stateMask |= DWT.BUTTON3;
-//          if (event.button is 4) event.stateMask |= DWT.BUTTON4;
-//          if (event.button is 5) event.stateMask |= DWT.BUTTON5;
-//          break;
-//      case DWT.KeyDown:
-//      case DWT.Traverse: {
-//          if (event.keyCode !is 0 || event.character !is 0) return true;
-//          int lastModifiers = display.lastModifiers;
-//          if ((modifiers & OS.alphaLock) !is 0 && (lastModifiers & OS.alphaLock) is 0) {
-//              event.keyCode = DWT.CAPS_LOCK;
-//              return true;
-//          }
-//          if ((modifiers & OS.shiftKey) !is 0 && (lastModifiers & OS.shiftKey) is 0) {
-//              event.stateMask &= ~DWT.SHIFT;
-//              event.keyCode = DWT.SHIFT;
-//              return true;
-//          }
-//          if ((modifiers & OS.controlKey) !is 0 && (lastModifiers & OS.controlKey) is 0) {
-//              event.stateMask &= ~DWT.CONTROL;
-//              event.keyCode = DWT.CONTROL;
-//              return true;
-//          }
-//          if ((modifiers & OS.cmdKey) !is 0 && (lastModifiers & OS.cmdKey) is 0) {
-//              event.stateMask &= ~DWT.COMMAND;
-//              event.keyCode = DWT.COMMAND;
-//              return true;
-//          }   
-//          if ((modifiers & OS.optionKey) !is 0 && (lastModifiers & OS.optionKey) is 0) {
-//              event.stateMask &= ~DWT.ALT;
-//              event.keyCode = DWT.ALT;
-//              return true;
-//          }
-//          break;
-//      }
-//      case DWT.KeyUp: {
-//          if (event.keyCode !is 0 || event.character !is 0) return true;
-//          int lastModifiers = display.lastModifiers;
-//          if ((modifiers & OS.alphaLock) is 0 && (lastModifiers & OS.alphaLock) !is 0) {
-//              event.keyCode = DWT.CAPS_LOCK;
-//              return true;
-//          }
-//          if ((modifiers & OS.shiftKey) is 0 && (lastModifiers & OS.shiftKey) !is 0) {
-//              event.stateMask |= DWT.SHIFT;
-//              event.keyCode = DWT.SHIFT;
-//              return true;
-//          }
-//          if ((modifiers & OS.controlKey) is 0 && (lastModifiers & OS.controlKey) !is 0) {
-//              event.stateMask |= DWT.CONTROL;
-//              event.keyCode = DWT.CONTROL;
-//              return true;
-//          }
-//          if ((modifiers & OS.cmdKey) is 0 && (lastModifiers & OS.cmdKey) !is 0) {
-//              event.stateMask |= DWT.COMMAND;
-//              event.keyCode = DWT.COMMAND;
-//              return true;
-//          }
-//          if ((modifiers & OS.optionKey) is 0 && (lastModifiers & OS.optionKey) !is 0) {
-//              event.stateMask |= DWT.ALT;
-//              event.keyCode = DWT.ALT;
-//              return true;
-//          }
-//          break;
-//      }
-//  }
-    return true; 
+void setFrameOrigin (int /*long*/ id, int /*long*/ sel, NSPoint point) {
+    objc_super super_struct = new objc_super();
+    super_struct.receiver = id;
+    super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
+    OS.objc_msgSendSuper(super_struct, sel, point);
+}
+
+void setFrameSize (int /*long*/ id, int /*long*/ sel, NSSize size) {
+    objc_super super_struct = new objc_super();
+    super_struct.receiver = id;
+    super_struct.super_class = OS.objc_msgSend(id, OS.sel_superclass);
+    OS.objc_msgSendSuper(super_struct, sel, size);
+}
+
+bool setInputState (Event event, NSEvent nsEvent, int type) {
+    if (nsEvent is null) return true;
+    int /*long*/ modifierFlags = nsEvent.modifierFlags();
+    if ((modifierFlags & OS.NSAlternateKeyMask) !is 0) event.stateMask |= DWT.ALT;
+    if ((modifierFlags & OS.NSShiftKeyMask) !is 0) event.stateMask |= DWT.SHIFT;
+    if ((modifierFlags & OS.NSControlKeyMask) !is 0) event.stateMask |= DWT.CONTROL;
+    if ((modifierFlags & OS.NSCommandKeyMask) !is 0) event.stateMask |= DWT.COMMAND;
+    //TODO multiple mouse buttons pressed
+    switch ((int)/*64*/nsEvent.type()) {
+        case OS.NSLeftMouseDragged:
+        case OS.NSRightMouseDragged:
+        case OS.NSOtherMouseDragged:
+            switch ((int)/*64*/nsEvent.buttonNumber()) {
+                case 0: event.stateMask |= DWT.BUTTON1; break;
+                case 1: event.stateMask |= DWT.BUTTON3; break;
+                case 2: event.stateMask |= DWT.BUTTON2; break;
+                case 3: event.stateMask |= DWT.BUTTON4; break;
+                case 4: event.stateMask |= DWT.BUTTON5; break;
+            }
+            break;
+        case OS.NSScrollWheel:
+        case OS.NSKeyDown:
+        case OS.NSKeyUp:
+            int state = OS.GetCurrentButtonState ();
+            if ((state & 0x1) !is 0) event.stateMask |= DWT.BUTTON1;
+            if ((state & 0x2) !is 0) event.stateMask |= DWT.BUTTON3;
+            if ((state & 0x4) !is 0) event.stateMask |= DWT.BUTTON2;
+            if ((state & 0x8) !is 0) event.stateMask |= DWT.BUTTON4;
+            if ((state & 0x10) !is 0) event.stateMask |= DWT.BUTTON5;
+            break;
+    }
+    switch (type) {
+        case DWT.MouseDown:
+        case DWT.MouseDoubleClick:
+            if (event.button is 1) event.stateMask &= ~DWT.BUTTON1;
+            if (event.button is 2) event.stateMask &= ~DWT.BUTTON2;
+            if (event.button is 3) event.stateMask &= ~DWT.BUTTON3;
+            if (event.button is 4) event.stateMask &= ~DWT.BUTTON4;
+            if (event.button is 5) event.stateMask &= ~DWT.BUTTON5;
+            break;
+        case DWT.MouseUp:
+            if (event.button is 1) event.stateMask |= DWT.BUTTON1;
+            if (event.button is 2) event.stateMask |= DWT.BUTTON2;
+            if (event.button is 3) event.stateMask |= DWT.BUTTON3;
+            if (event.button is 4) event.stateMask |= DWT.BUTTON4;
+            if (event.button is 5) event.stateMask |= DWT.BUTTON5;
+            break;
+        case DWT.KeyDown:
+        case DWT.Traverse:
+            if (event.keyCode is DWT.ALT) event.stateMask &= ~DWT.ALT;
+            if (event.keyCode is DWT.SHIFT) event.stateMask &= ~DWT.SHIFT;
+            if (event.keyCode is DWT.CONTROL) event.stateMask &= ~DWT.CONTROL;
+            if (event.keyCode is DWT.COMMAND) event.stateMask &= ~DWT.COMMAND;
+            break;
+        case DWT.KeyUp:
+            if (event.keyCode is DWT.ALT) event.stateMask |= DWT.ALT;
+            if (event.keyCode is DWT.SHIFT) event.stateMask |= DWT.SHIFT;
+            if (event.keyCode is DWT.CONTROL) event.stateMask |= DWT.CONTROL;
+            if (event.keyCode is DWT.COMMAND) event.stateMask |= DWT.COMMAND;
+            break;
+    }       
+    return true;
 }
 
 bool setKeyState (Event event, int type, NSEvent nsEvent) {
-//  bool isNull = false;
-//  int [] keyCode = new int [1];
-//  OS.GetEventParameter (theEvent, OS.kEventParamKeyCode, OS.typeUInt32, null, keyCode.length * 4, null, keyCode);
-//  event.keyCode = Display.translateKey (keyCode [0]);
+    bool isNull = false;
+    int keyCode = nsEvent.keyCode ();
+    event.keyCode = Display.translateKey (keyCode);
     switch (event.keyCode) {
-//      case DWT.LF: {
-//          /*
-//          * Feature in the Macintosh.  When the numeric key pad
-//          * Enter key is pressed, it generates '\n'.  This is the
-//          * correct platform behavior but is not portable.  The
-//          * fix is to convert the '\n' into '\r'.
-//          */
-//          event.keyCode = DWT.KEYPAD_CR;
-//          event.character = '\r';
-//          break;
-//      }
+        case DWT.LF: {
+            /*
+            * Feature in the Macintosh.  When the numeric key pad
+            * Enter key is pressed, it generates '\n'.  This is the
+            * correct platform behavior but is not portable.  The
+            * fix is to convert the '\n' into '\r'.
+            */
+            event.keyCode = DWT.KEYPAD_CR;
+            event.character = '\r';
+            break;
+        }
         case DWT.BS: event.character = '\b'; break;
-//      case DWT.CR: event.character = '\r'; break;
+        case DWT.CR: event.character = '\r'; break;
         case DWT.DEL: event.character = 0x7F; break;
-//      case DWT.ESC: event.character = 0x1B; break;
-//      case DWT.TAB: event.character = '\t'; break;
-//      default: {
-//          if (event.keyCode is 0 || (DWT.KEYPAD_MULTIPLY <= event.keyCode && event.keyCode <= DWT.KEYPAD_CR)) {
-//              int [] length = new int [1];
-//              int status = OS.GetEventParameter (theEvent, OS.kEventParamKeyUnicodes, OS.typeUnicodeText, null, 4, length, (char[])null);
-//              if (status is OS.noErr && length [0] !is 0) {
-//                  char [] chars = new char [1];
-//                  OS.GetEventParameter (theEvent, OS.kEventParamKeyUnicodes, OS.typeUnicodeText, null, 2, null, chars);
-//                  event.character = chars [0];
-//              }
-//              /*
-//              * Bug in the Mactonish.  For some reason, Ctrl+Shift+'2' and Ctrl+Shift+'6'
-//              * fail to give 0x0 (^@ or ASCII NUL) and 0x1e (^^).  Other control character
-//              * key sequences such as ^A or even Ctrl+Shift+'-' (^_ or 0x1f) are correctly
-//              * translated to control characters.  Since it is not possible to know which
-//              * key combination gives '@' on an international keyboard, there is no way to
-//              * test for either character and convert it to a control character (Shift+'2'
-//              * gives '@' only on an English keyboard) to work around the problem.
-//              *
-//              * There is no fix at this time.
-//              */
-//          }
-//          if (event.keyCode is 0) {
-//              int kchrPtr = OS.GetScriptManagerVariable (cast(short) OS.smKCHRCache);
-//              if (display.kchrPtr !is kchrPtr) {
-//                  display.kchrPtr = kchrPtr;
-//                  display.kchrState [0] = 0;
-//              }
-//              int result = OS.KeyTranslate (display.kchrPtr, cast(short)keyCode [0], display.kchrState);
-//              if (result <= 0x7f) {
-//                  event.keyCode = result & 0x7f;
-//              } else {
-//                  int [] encoding = new int [1];
-//                  short keyScript = cast(short) OS.GetScriptManagerVariable (cast(short) OS.smKeyScript);
-//                  short regionCode = cast(short) OS.GetScriptManagerVariable (cast(short) OS.smRegionCode);
-//                  if (OS.UpgradeScriptInfoToTextEncoding (keyScript, cast(short) OS.kTextLanguageDontCare, regionCode, null, encoding) is OS.paramErr) {
-//                      if (OS.UpgradeScriptInfoToTextEncoding (keyScript, cast(short) OS.kTextLanguageDontCare, cast(short) OS.kTextRegionDontCare, null, encoding) is OS.paramErr) {
-//                          encoding [0] = OS.kTextEncodingMacRoman;
-//                      }
-//                  }
-//                  int [] encodingInfo = new int [1];
-//                  OS.CreateTextToUnicodeInfoByEncoding (encoding [0], encodingInfo);
-//                  if (encodingInfo [0] !is 0) {
-//                      char [] chars = new char [1];
-//                      int [] nchars = new int [1];
-//                      byte [] buffer = new byte [2];
-//                      buffer [0] = 1;
-//                      buffer [1] = cast(byte) (result & 0xFF);
-//                      OS.ConvertFromPStringToUnicode (encodingInfo [0], buffer, chars.length * 2, nchars, chars);
-//                      OS.DisposeTextToUnicodeInfo (encodingInfo);
-//                      event.keyCode = chars [0];
-//                  }
-//              }
-//          }
-//          break;
-//      }
+        case DWT.ESC: event.character = 0x1B; break;
+        case DWT.TAB: event.character = '\t'; break;
+        default:
+            if (event.keyCode is 0 || (DWT.KEYPAD_MULTIPLY <= event.keyCode && event.keyCode <= DWT.KEYPAD_CR)) {
+                NSString chars = nsEvent.characters ();
+                if (chars.length() > 0) event.character = (char)chars.characterAtIndex (0);
+            }
+            if (event.keyCode is 0) {
+                //TODO this is wrong for shifted keys like ';', '1' and non-english keyboards
+                NSString unmodifiedChars = nsEvent.charactersIgnoringModifiers ().lowercaseString();
+                if (unmodifiedChars.length() > 0) event.keyCode = (char)unmodifiedChars.characterAtIndex(0);
+            }
     }
-//  if (event.keyCode is 0 && event.character is 0) {
-//      if (!isNull) return false;
-//  }
-//  int [] chord = new int [1];
-//  OS.GetEventParameter (theEvent, OS.kEventParamMouseChord, OS.typeUInt32, null, 4, null, chord);
-//  int [] modifiers = new int [1];
-//  OS.GetEventParameter (theEvent, OS.kEventParamKeyModifiers, OS.typeUInt32, null, 4, null, modifiers);
-//  return setInputState (event, type, chord [0], modifiers [0]);
+    if (event.keyCode is 0 && event.character is 0) {
+        if (!isNull) return false;
+    }
+    setInputState (event, nsEvent, type);
     return true;
 }
 
-void tableViewSelectionDidChange (int aNotification) {
+bool setMarkedText_selectedRange (int /*long*/ id, int /*long*/ sel, int /*long*/ string, int /*long*/ range) {
+    return true;
+}
+
+void tableViewColumnDidMove (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
 }
 
-int tableView_objectValueForTableColumn_row(int aTableView, int aTableColumn, int rowIndex) {
+void tableViewColumnDidResize (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
+}
+
+void tableViewSelectionDidChange (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
+}
+
+void tableView_didClickTableColumn(int /*long*/ id, int /*long*/ sel, int /*long*/ tableView, int /*long*/ tableColumn) {
+}
+
+int /*long*/ tableView_objectValueForTableColumn_row(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ aTableColumn, int /*long*/ rowIndex) {
     return 0;
 }
 
-void tableView_setObjectValue_forTableColumn_row(int aTableView, int anObject, int aTableColumn, int rowIndex) {    
+void tableView_setObjectValue_forTableColumn_row(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ anObject, int /*long*/ aTableColumn, int /*long*/ rowIndex) { 
 }
 
-bool tableView_shouldEditTableColumn_row(int aTableView, int aTableColumn, int rowIndex) {
+bool tableView_shouldEditTableColumn_row(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ aTableColumn, int /*long*/ rowIndex) {
     return true;
 }
 
-void tableView_willDisplayCell_forTableColumn_row(int aTableView, int aCell, int aTableColumn, int rowIndex) {
+void tableView_willDisplayCell_forTableColumn_row(int /*long*/ id, int /*long*/ sel, int /*long*/ aTableView, int /*long*/ aCell, int /*long*/ aTableColumn, int /*long*/ rowIndex) {
+}
+
+void textViewDidChangeSelection(int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
+}
+
+void textDidChange(int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
+}
+
+NSRange textView_willChangeSelectionFromCharacterRange_toCharacterRange(int /*long*/ id, int /*long*/ sel, int /*long*/ aTextView, int /*long*/ oldSelectedCharRange, int /*long*/ newSelectedCharRange) {
+    return new NSRange();
 }
 
 /**
@@ -1256,30 +1454,37 @@
     return getName () ~ " {" ~ string ~ "}";
 }
 
-void willSelectTabViewItem(int tabView, int tabViewItem) {
+int /*long*/ validAttributesForMarkedText (int /*long*/ id, int /*long*/ sel) {
+    return 0;
 }
 
-void windowDidMove(int notification) {
+void tabView_didSelectTabViewItem(int /*long*/ id, int /*long*/ sel, int /*long*/ tabView, int /*long*/ tabViewItem) {
 }
 
-void windowDidResize(int notification) {
+void tabView_willSelectTabViewItem(int /*long*/ id, int /*long*/ sel, int /*long*/ tabView, int /*long*/ tabViewItem) {
+}
+
+void windowDidMove(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
 }
 
-void windowDidResignKey(int notification) {
+void windowDidResize(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
 }
 
-void windowDidBecomeKey(int notification) {
+void windowDidResignKey(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
 }
 
-void windowSendEvent(objc.id id, objc.id event) {
-    callSuper(id, OS.sel_sendEvent_1, event);
+void windowDidBecomeKey(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
 }
 
-bool windowShouldClose(int window) {
+void windowSendEvent(int /*long*/ id, int /*long*/ sel, int /*long*/ event) {
+    callSuper(id, sel, event);
+}
+
+bool windowShouldClose(int /*long*/ id, int /*long*/ sel, int /*long*/ window) {
     return false;
 }
 
-void windowWillClose(int notification) {
+void windowWillClose(int /*long*/ id, int /*long*/ sel, int /*long*/ notification) {
 }
 
 }