changeset 85:844f65808a36

Ported dwt.widgets.ToolItem
author Jacob Carlborg <doob@me.com>
date Sun, 28 Dec 2008 19:47:54 +0100
parents 555527e6d914
children 102ff2adce19
files dwt/internal/cocoa/OS.d dwt/widgets/ToolBar.d dwt/widgets/ToolItem.d
diffstat 3 files changed, 42 insertions(+), 31 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/internal/cocoa/OS.d	Sun Dec 28 19:37:49 2008 +0100
+++ b/dwt/internal/cocoa/OS.d	Sun Dec 28 19:47:54 2008 +0100
@@ -3049,7 +3049,7 @@
 alias NSDatePickerElementFlags.NSHourMinuteSecondDatePickerElementFlag NSHourMinuteSecondDatePickerElementFlag;
 public static const int NSIdentityMappingCharacterCollection = 0;
 public static const int NSIllegalTextMovement = 0;
-public static const int NSImageAbove = 5;
+alias Cocoa.NSCellImagePosition.NSImageAbove NSImageAbove;
 public static const int NSImageAlignBottom = 5;
 public static const int NSImageAlignBottomLeft = 6;
 public static const int NSImageAlignBottomRight = 7;
@@ -3080,8 +3080,8 @@
 public static const int NSImageLoadStatusInvalidData = 2;
 public static const int NSImageLoadStatusReadError = 4;
 public static const int NSImageLoadStatusUnexpectedEOF = 3;
-public static const int NSImageOnly = 1;
-public static const int NSImageOverlaps = 6;
+alias Cocoa.NSCellImagePosition.NSImageOnly NSImageOnly;
+alias Cocoa.NSCellImagePosition.NSImageOverlaps NSImageOverlaps;
 public static const int NSImageRepLoadStatusCompleted = -6;
 public static const int NSImageRepLoadStatusInvalidData = -4;
 public static const int NSImageRepLoadStatusReadingHeader = -2;
@@ -3174,7 +3174,7 @@
 alias NSBorderType.NSNoBorder NSNoBorder;
 public static const int NSNoCellMask = 0;
 public static const int NSNoFontChangeAction = 0;
-public static const int NSNoImage = 0;
+alias Cocoa.NSCellImagePosition.NSNoImage NSNoImage;
 public static const int NSNoInterfaceStyle = 0;
 public static const int NSNoModeColorPanel = -1;
 public static const int NSNoScrollerParts = 0;
--- a/dwt/widgets/ToolBar.d	Sun Dec 28 19:37:49 2008 +0100
+++ b/dwt/widgets/ToolBar.d	Sun Dec 28 19:47:54 2008 +0100
@@ -187,7 +187,7 @@
     return super.accessibilityAttributeValue(id, sel, arg0);
 }
 
-bool accessibilityIsIgnored(objc.id id, objc.SELs sel) {
+bool accessibilityIsIgnored(objc.id id, objc.SEL sel) {
     // Toolbars aren't ignored.
     return false;   
 }
--- a/dwt/widgets/ToolItem.d	Sun Dec 28 19:37:49 2008 +0100
+++ b/dwt/widgets/ToolItem.d	Sun Dec 28 19:47:54 2008 +0100
@@ -7,6 +7,9 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <doob@me.com>
  *******************************************************************************/
 module dwt.widgets.ToolItem;
 
@@ -41,6 +44,14 @@
 import dwt.internal.cocoa.SWTButton;
 import dwt.internal.cocoa.SWTView;
 
+import objc = dwt.internal.objc.runtime;
+import dwt.widgets.Control;
+import dwt.widgets.Display;
+import dwt.widgets.Event;
+import dwt.widgets.Item;
+import dwt.widgets.ToolBar;
+import dwt.widgets.TypedListener;
+
 /**
  * Instances of this class represent a selectable user interface object
  * that represents a button in a tool bar.
@@ -70,11 +81,11 @@
     Control control;
     bool selection;
 
-    static final int DEFAULT_WIDTH = 24;
-    static final int DEFAULT_HEIGHT = 22;
-    static final int DEFAULT_SEPARATOR_WIDTH = 6;
-    static final int INSET = 3;
-    static final int ARROW_WIDTH = 5;
+    static const int DEFAULT_WIDTH = 24;
+    static const int DEFAULT_HEIGHT = 22;
+    static const int DEFAULT_SEPARATOR_WIDTH = 6;
+    static const int INSET = 3;
+    static const int ARROW_WIDTH = 5;
 
 /**
  * Constructs a new instance of this class given its parent
@@ -158,7 +169,7 @@
     parent.createItem (this, index);
 }
 
-int accessibilityAttributeValue(int /*long*/ id, int /*long*/ sel, int /*long*/ arg0) {
+objc.id accessibilityAttributeValue(objc.id id, objc.SEL sel, objc.id arg0) {
     NSString nsAttributeName = new NSString(arg0);
 
     if (nsAttributeName.isEqualToString (OS.NSAccessibilityRoleAttribute) || nsAttributeName.isEqualToString (OS.NSAccessibilityRoleDescriptionAttribute)) {
@@ -171,7 +182,7 @@
             if (nsAttributeName.isEqualToString (OS.NSAccessibilityRoleAttribute)) {
                 return roleText.id;
             } else { // NSAccessibilityRoleDescriptionAttribute
-                int /*long*/ description = OS.NSAccessibilityRoleDescription (roleText.id, 0);
+                objc.id description = OS.NSAccessibilityRoleDescription (roleText.id, null);
                 return description;
             }
         }
@@ -253,7 +264,7 @@
         }
     } else {
         if (text.length () !is 0 || image !is null) {
-            NSButton widget = (NSButton)button;
+            NSButton widget = cast(NSButton)button;
             NSRect oldFrame = widget.frame();
             widget.sizeToFit ();
             NSRect frame = button.frame();
@@ -275,15 +286,15 @@
 
 void createHandle () {
     if ((style & DWT.SEPARATOR) !is 0) {
-        NSBox widget = cast(NSBox)new SWTBox().alloc();
+        NSBox widget = cast(NSBox)(new SWTBox()).alloc();
         widget.initWithFrame(NSRect());
         widget.setBoxType(OS.NSBoxSeparator);
         view = widget;
     } else {
-        NSView widget = cast(NSView)new SWTView().alloc();
+        NSView widget = cast(NSView)(new SWTView()).alloc();
         widget.initWithFrame(NSRect());
         parent.contentView().addSubview(widget);
-        button = cast(NSButton)new SWTButton().alloc();
+        button = cast(NSButton)(new SWTButton()).alloc();
         button.initWithFrame(NSRect());
         button.setBordered(false);
         button.setAction(OS.sel_sendSelection);
@@ -314,13 +325,13 @@
     text.getChars (0, chars.length, chars, 0);
     int length = fixMnemonic (chars);
 
-    NSMutableParagraphStyle pStyle = (NSMutableParagraphStyle)new NSMutableParagraphStyle().alloc().init();
+    NSMutableParagraphStyle pStyle = cast(NSMutableParagraphStyle)(new NSMutableParagraphStyle()).alloc().init();
     pStyle.autorelease();
     pStyle.setAlignment(OS.NSCenterTextAlignment);
     dict.setObject(pStyle, OS.NSParagraphStyleAttributeName);
     
-    NSString str = NSString.stringWithCharacters(chars, length);
-    NSAttributedString attribStr = ((NSAttributedString)new NSAttributedString().alloc()).initWithString(str, dict);
+    NSString str = NSString.stringWithCharacters(chars.toString16().ptr, length);
+    NSAttributedString attribStr = (cast(NSAttributedString)(new NSAttributedString()).alloc()).initWithString(str, dict);
     attribStr.autorelease();
     return attribStr;
 }
@@ -340,7 +351,7 @@
     super.destroyWidget();
 }
 
-void drawWidget (int /*long*/ id, NSRect rect) {
+void drawWidget (objc.id id, NSRect rect) {
     if (id is view.id) {
         if (getSelection ()) {
             NSRect bounds = view.bounds();
@@ -349,10 +360,10 @@
             NSColor.colorWithDeviceRed(0.1f, 0.1f, 0.1f, 0.1f).setFill();
             NSColor.colorWithDeviceRed(0.2f, 0.2f, 0.2f, 0.2f).setStroke();
             NSBezierPath.fillRect(bounds);
-            bounds.x += 0.5f;
-            bounds.y += 0.5f;
-            bounds.width -= 1;
-            bounds.height -= 1;
+            bounds.origin.x += 0.5f;
+            bounds.origin.y += 0.5f;
+            bounds.size.width -= 1;
+            bounds.size.height -= 1;
             NSBezierPath.strokeRect(bounds);
             context.restoreGraphicsState();
         }
@@ -370,7 +381,7 @@
             path.lineToPoint(pt);
             path.closePath();
             NSAffineTransform transform = NSAffineTransform.transform();
-            transform.translateXBy((int)bounds.width - ARROW_WIDTH - INSET, (int)(bounds.height - ARROW_WIDTH / 2) / 2);
+            transform.translateXBy(cast(int)bounds.width - ARROW_WIDTH - INSET, cast(int)(bounds.height - ARROW_WIDTH / 2) / 2);
             transform.concat();
             NSColor color = isEnabled() ? NSColor.blackColor() : NSColor.disabledControlTextColor();
             color.set();
@@ -569,11 +580,11 @@
     return getEnabled () && parent.isEnabled ();
 }
 
-int /*long*/ menuForEvent (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+objc.id menuForEvent (objc.id id, objc.SEL sel, objc.id theEvent) {
     return parent.menuForEvent (id, sel, theEvent);
 }
 
-void mouseDown(int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+void mouseDown(objc.id id, objc.SEL sel, objc.id theEvent) {
     Display display = this.display;
     display.trackingControl = parent;
     super.mouseDown(id, sel, theEvent);
@@ -582,8 +593,8 @@
         NSRect frame = view.frame();
         Event event = new Event ();
         event.detail = DWT.ARROW;
-        event.x = (int)frame.x;
-        event.y = (int)(frame.y + frame.height);
+        event.x = cast(int)frame.x;
+        event.y = cast(int)(frame.y + frame.height);
         postEvent (DWT.Selection, event);
     }
 }
@@ -676,7 +687,7 @@
         rect.y = 0;
         rect.width = width;
         rect.height = height;
-        if ((style & DWT.DROP_DOWN) !is 0) rect.width -= ARROW_WIDTH + INSET;
+        if ((style & DWT.DROP_DOWN) !is 0) rect.size.width -= ARROW_WIDTH + INSET;
         button.setFrame(rect);
     }
 }
@@ -858,7 +869,7 @@
     if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
     if ((style & DWT.SEPARATOR) !is 0) return;
     super.setText (string);
-    NSButton widget = (NSButton)button;
+    NSButton widget = cast(NSButton)button;
     widget.setAttributedTitle(createString());
     if (text.length() !is 0 && image !is null) {
         if ((parent.style & DWT.RIGHT) !is 0) {