changeset 27:dfcc6c4c4317

Ported dwt.widgets.Button
author Jacob Carlborg <doob@me.com> <jacob.carlborg@gmail.com>
date Mon, 08 Sep 2008 18:15:39 +0200
parents 74a3be48bba8
children 71b49a659702
files dwt/widgets/Button.d dwt/widgets/Widget.d
diffstat 2 files changed, 21 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/widgets/Button.d	Mon Sep 08 17:55:37 2008 +0200
+++ b/dwt/widgets/Button.d	Mon Sep 08 18:15:39 2008 +0200
@@ -7,11 +7,12 @@
  *
  * Contributors:
  *     IBM Corporation - initial API and implementation
+ *     
+ * Port to the D programming language:
+ *     Jacob Carlborg <jacob.carlborg@gmail.com>
  *******************************************************************************/
 module dwt.widgets.Button;
 
-import dwt.dwthelper.utils;
-
 
 import dwt.DWT;
 import dwt.DWTException;
@@ -30,6 +31,14 @@
 import dwt.internal.cocoa.OS;
 import dwt.internal.cocoa.SWTButton;
 
+import dwt.dwthelper.utils;
+import dwt.internal.cocoa.CGFloat;
+import dwt.internal.cocoa.NSInteger;
+import dwt.widgets.Composite;
+import dwt.widgets.Decorations;
+import dwt.widgets.ImageList;
+import dwt.widgets.TypedListener;
+
 /**
  * Instances of this class represent a selectable user interface object that
  * issues notification when pressed and released. 
@@ -152,7 +161,7 @@
 NSAttributedString createString() {
     NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity(4);
     if (foreground !is null) {
-        NSColor color = NSColor.colorWithDeviceRed(foreground.handle[0], foreground.handle[1], foreground.handle[2], 1);
+        NSColor color = NSColor.colorWithDeviceRed(cast(CGFloat) foreground.handle[0], cast(CGFloat) foreground.handle[1], cast(CGFloat) foreground.handle[2], 1);
         dict.setObject(color, OS.NSForegroundColorAttributeName());
     }
     if (font !is null) {
@@ -166,22 +175,22 @@
     } else {
         alignment = OS.NSRightTextAlignment;
     }
-    NSMutableParagraphStyle pStyle = cast(NSMutableParagraphStyle)new NSMutableParagraphStyle().alloc().init();
+    NSMutableParagraphStyle pStyle = cast(NSMutableParagraphStyle)(new NSMutableParagraphStyle()).alloc().init();
     pStyle.autorelease();
     pStyle.setAlignment(alignment);
     dict.setObject(pStyle, OS.NSParagraphStyleAttributeName());
     char [] chars = new char [text.length ()];
     text.getChars (0, chars.length, chars, 0);
-    int length = fixMnemonic (chars);
-    NSString str = NSString.stringWithCharacters(chars, length);
-    NSAttributedString attribStr = (cast(NSAttributedString)new NSAttributedString().alloc()).initWithString_attributes_(str, dict);
+    NSUInteger length = fixMnemonic (chars);
+    NSString str = NSString.stringWithCharacters(chars.toString16().ptr, length);
+    NSAttributedString attribStr = (cast(NSAttributedString)(new NSAttributedString()).alloc()).initWithString_attributes_(str, dict);
     attribStr.autorelease();
     return attribStr;
 }
 
 void createHandle () {
-    NSButton widget = cast(NSButton)new SWTButton().alloc();
-    widget.initWithFrame(new NSRect());
+    NSButton widget = cast(NSButton)(new SWTButton()).alloc();
+    widget.initWithFrame(NSRect());
     int type = OS.NSMomentaryPushButton;
     if ((style & DWT.PUSH) !is 0) {
         widget.setBezelStyle(OS.NSRoundedBezelStyle);
@@ -451,7 +460,7 @@
     if (color is null) {
         return; // TODO set to OS default
     } else {
-        nsColor = NSColor.colorWithDeviceRed(color[0], color[1], color[2], 1);
+        nsColor = NSColor.colorWithDeviceRed(cast(CGFloat) color[0], cast(CGFloat) color[1], cast(CGFloat) color[2], 1);
     }
     NSButtonCell cell = new NSButtonCell((cast(NSButton)view).cell());
     cell.setBackgroundColor(nsColor);
--- a/dwt/widgets/Widget.d	Mon Sep 08 17:55:37 2008 +0200
+++ b/dwt/widgets/Widget.d	Mon Sep 08 18:15:39 2008 +0200
@@ -400,8 +400,8 @@
     return display.filters (eventType);
 }
 
-int fixMnemonic (char [] buffer) {
-    int i=0, j=0;
+NSUInteger fixMnemonic (char [] buffer) {
+    NSUInteger i=0, j=0;
     while (i < buffer.length) {
         if ((buffer [j++] = buffer [i++]) is '&') {
             if (i is buffer.length) {continue;}