changeset 77:990305995bc6

Ported dwt.widgets.Spinner
author Jacob Carlborg <doob@me.com>
date Wed, 24 Dec 2008 13:06:45 +0100
parents 3f1bfbd329c0
children d226cd03f84a
files dwt/dwthelper/utils.d dwt/internal/cocoa/OS.d dwt/widgets/Link.d dwt/widgets/Spinner.d
diffstat 4 files changed, 55 insertions(+), 35 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/dwthelper/utils.d	Wed Dec 24 12:32:20 2008 +0100
+++ b/dwt/dwthelper/utils.d	Wed Dec 24 13:06:45 2008 +0100
@@ -7,7 +7,6 @@
 public import Math = tango.math.Math;
 
 public import tango.core.Exception : IllegalArgumentException, IOException, PlatformException;
-public import tango.text.convert.Utf;
 
 import tango.io.Stdout;
 
@@ -414,8 +413,8 @@
     return res.length;
 }
 
-alias tango.text.convert.Utf.toString16 toString16;
-alias tango.text.convert.Utf.toString toString;
+public alias tango.text.convert.Utf.toString16 toString16;
+public alias tango.text.convert.Utf.toString toString;
 
 int getRelativeCodePointOffset( String str, int startIndex, int searchRelCp ){
     int ignore;
@@ -697,6 +696,19 @@
            "d" );
 }
 
+public alias tango.stdc.stringz.toStringz toStringz;
+public alias tango.stdc.stringz.toString16z toString16z;
+public alias tango.stdc.stringz.fromStringz fromStringz;
+public alias tango.stdc.stringz.fromString16z fromString16z;
+
+struct String_
+{
+    static String valueOf (int v)
+    {
+        return tango.text.convert.Integer.toString(v, 10);
+    }
+}
+
 class RuntimeException : Exception {
     this( String e = null){
         super(e);
--- a/dwt/internal/cocoa/OS.d	Wed Dec 24 12:32:20 2008 +0100
+++ b/dwt/internal/cocoa/OS.d	Wed Dec 24 13:06:45 2008 +0100
@@ -2880,7 +2880,7 @@
 public static const int NSDocModalWindowMask = 64;
 public static const int NSDockWindowLevel = 20;
 public static const int NSDoubleType = 6;
-public static const int NSDownArrowFunctionKey = 63233;
+public static const wchar NSDownArrowFunctionKey = 63233;
 public static const int NSDownTextMovement = 22;
 public static const int NSDragOperationAll = 15;
 public static const int NSDragOperationAll_Obsolete = 15;
@@ -2897,7 +2897,7 @@
 public static const int NSDrawerOpenState = 2;
 public static const int NSDrawerOpeningState = 1;
 public static const int NSEndFunctionKey = 63275;
-public static const int NSEnterCharacter = 3;
+public static const wchar NSEnterCharacter = 3;
 public static const int NSEraDatePickerElementFlag = 256;
 public static const int NSEraserPointingDevice = 3;
 alias Cocoa.NSWindingRule.NSEvenOddWindingRule NSEvenOddWindingRule;
@@ -3167,7 +3167,7 @@
 public static const int NSNarrowFontMask = 16;
 public static const int NSNativeShortGlyphPacking = 5;
 public static const int NSNaturalTextAlignment = 4;
-public static const int NSNewlineCharacter = 10;
+public static const wchar NSNewlineCharacter = 10;
 public static const int NSNextFunctionKey = 63296;
 public static const int NSNextStepInterfaceStyle = 1;
 alias NSBorderType.NSNoBorder NSNoBorder;
@@ -3250,8 +3250,8 @@
 public static const int NSOtherTextMovement = 0;
 public static const int NSOutlineViewDropOnItemIndex = -1;
 public static const int NSPNGFileType = 4;
-public static const int NSPageDownFunctionKey = 63277;
-public static const int NSPageUpFunctionKey = 63276;
+public static const wchar NSPageDownFunctionKey = 63277;
+public static const wchar NSPageUpFunctionKey = 63276;
 public static const int NSParagraphSeparatorCharacter = 8233;
 public static const int NSPathStyleNavigationBar = 1;
 public static const int NSPathStylePopUp = 2;
@@ -3568,7 +3568,7 @@
 public static const int NSUnknownPageOrder = 2;
 public static const int NSUnknownPointingDevice = 0;
 public static const int NSUnscaledWindowMask = 2048;
-public static const int NSUpArrowFunctionKey = 63232;
+public static const wchar NSUpArrowFunctionKey = 63232;
 public static const int NSUpTextMovement = 21;
 public static const int NSUpdateWindowsRunLoopOrdering = 500000;
 public static const int NSUserFunctionKey = 63286;
--- a/dwt/widgets/Link.d	Wed Dec 24 12:32:20 2008 +0100
+++ b/dwt/widgets/Link.d	Wed Dec 24 13:06:45 2008 +0100
@@ -39,7 +39,6 @@
 import dwt.widgets.Composite;
 import dwt.widgets.Control;
 
-alias tango.text.Text.Text!(char) Text8;
 
 /**
  * Instances of this class represent a selectable
@@ -262,7 +261,7 @@
     offsets = new Point [length_ / 4];
     ids = new String [length_ / 4];
     mnemonics = new int [length_ / 4 + 1];
-    Text8 result = new Text8 ();
+    StringBuffer result = new StringBuffer ();
     char [] buffer = new char [length_];
     string.getChars (0, string.length (), buffer, 0);
     int index = 0, state = 0, linkIndex = 0;
@@ -388,7 +387,7 @@
     return result.toString ();
 }
 
-int parseMnemonics (char[] buffer, int start, int end, Text8 result) {
+int parseMnemonics (char[] buffer, int start, int end, StringBuffer result) {
     int mnemonic = -1, index = start;
     while (index < end) {
         if (buffer [index] is '&') {
--- a/dwt/widgets/Spinner.d	Wed Dec 24 12:32:20 2008 +0100
+++ b/dwt/widgets/Spinner.d	Wed Dec 24 13:06:45 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.Spinner;
 
@@ -39,6 +42,12 @@
 import dwt.internal.cocoa.SWTTextField;
 import dwt.internal.cocoa.SWTView;
 
+import dwt.internal.c.Carbon;
+import objc = dwt.internal.objc.runtime;
+import dwt.widgets.Composite;
+import dwt.widgets.Event;
+import dwt.widgets.TypedListener;
+
 /**
  * Instances of this class are selectable user interface
  * objects that allow the user to enter and modify numeric
@@ -105,7 +114,7 @@
     super (parent, checkStyle (style));
 }
 
-bool acceptsFirstResponder(int /*long*/ id, int /*long*/ sel) {
+bool acceptsFirstResponder(objc.id id, objc.SEL sel) {
     if (id is view.id) return false;
     return super.acceptsFirstResponder (id, sel);
 }
@@ -211,19 +220,19 @@
 
 public Point computeSize (int wHint, int hHint, bool changed) {
     checkWidget ();
-    float width = 0, height = 0;
+    CGFloat width = 0, height = 0;
     String string = Double.toString (buttonView.maxValue ());
     NSMutableDictionary dict = NSMutableDictionary.dictionaryWithCapacity (1);
     dict.setObject(textView.font (), OS.NSFontAttributeName);
     int length = string.length ();
     char [] chars = new char [length];
     string.getChars (0, length, chars, 0);
-    NSString nsString = NSString.stringWithCharacters (chars, length);
-    NSAttributedString str = (cast(NSAttributedString) new NSAttributedString ().alloc ()).initWithString (nsString, dict);
+    NSString nsString = NSString.stringWithCharacters (chars.toString16().ptr, length);
+    NSAttributedString str = (cast(NSAttributedString) (new NSAttributedString ()).alloc ()).initWithString (nsString, dict);
     NSSize size = str.size ();
     str.release ();
-    width = (int)/*64*/size.width;
-    height = (int)/*64*/size.height;
+    width = size.width;
+    height = size.height;
     NSRect frameRect = textView.frame();
     NSCell cell = new NSCell (textView.cell ());
     NSRect cellRect = cell.drawingRectForBounds(frameRect);
@@ -235,7 +244,7 @@
     NSRect newRect = buttonView.frame ();
     buttonView.setFrame (oldRect);
     width += newRect.width;
-    height = Math.max (height, (int)/*64*/newRect.height);
+    height = Math.max (height, newRect.height);
     if (wHint !is DWT.DEFAULT) width = wHint;
     if (hHint !is DWT.DEFAULT) height = hHint;
     Rectangle trim = computeTrim (0, 0, cast(int) width, cast(int) height);
@@ -271,15 +280,15 @@
 }
 
 void createHandle () {
-    NSView widget = cast(NSView)new SWTView().alloc();
+    NSView widget = cast(NSView)(new SWTView()).alloc();
     widget.initWithFrame(NSRect());
 //  widget.setDrawsBackground(false);
-    NSStepper buttonWidget = cast(NSStepper)new SWTStepper().alloc();
+    NSStepper buttonWidget = cast(NSStepper)(new SWTStepper()).alloc();
     buttonWidget.initWithFrame(NSRect());
     buttonWidget.setValueWraps((style & DWT.WRAP) !is 0);
     buttonWidget.setTarget(buttonWidget);
     buttonWidget.setAction(OS.sel_sendSelection);
-    NSTextField textWidget = cast(NSTextField)new SWTTextField().alloc();
+    NSTextField textWidget = cast(NSTextField)(new SWTTextField()).alloc();
     textWidget.initWithFrame(NSRect());
 //  textWidget.setTarget(widget);
     textWidget.setEditable((style & DWT.READ_ONLY) is 0);
@@ -473,12 +482,12 @@
     return -1;
 }
 
-void keyDown (int /*long*/ id, int /*long*/ sel, int /*long*/ theEvent) {
+void keyDown (objc.id id, objc.SEL sel, objc.id theEvent) {
     NSEvent event = new NSEvent(theEvent);
     NSString chars = event.charactersIgnoringModifiers();
     
     int delta = 0;
-    int keyChar = 0;
+    wchar keyChar = 0;
 
     if (chars.length() !is 1) return;
     
@@ -496,7 +505,7 @@
         
         default: {
             NSCharacterSet numbers = new NSCharacterSet(NSCharacterSet.decimalDigitCharacterSet().id);
-            bool isANumber = numbers.characterIsMember((short) keyChar);
+            bool isANumber = numbers.characterIsMember(cast(short) keyChar);
             bool isSeparator = (keyChar is textFormatter.decimalSeparator().characterAtIndex(0));
             bool isMathSymbol = (keyChar is 0x2d || keyChar is 0x2b); // Minus sign, plus sign
             if (isANumber || (isSeparator && digits > 0) || isMathSymbol) super.keyDown(id, sel, theEvent);
@@ -507,11 +516,11 @@
         bool [] parseFail = new bool [1];
         int value = getSelectionText (parseFail);
         if (parseFail [0]) {
-            value = (int)buttonView.doubleValue();
+            value = cast(int)buttonView.doubleValue();
         }
         int newValue = value + delta;
-        int max = (int)buttonView.maxValue();
-        int min = (int)buttonView.minValue();
+        int max = cast(int)buttonView.maxValue();
+        int min = cast(int)buttonView.minValue();
         if ((style & DWT.WRAP) !is 0) {
             if (newValue > max) newValue = min;
             if (newValue < min) newValue = max;
@@ -523,7 +532,7 @@
         bool [] parseFail = new bool [1];
         int value = getSelectionText (parseFail);
         if (!parseFail [0]) {
-            int pos = (int)buttonView.doubleValue();
+            int pos = cast(int)buttonView.doubleValue();
             if (pos !is value) setSelection (value, true, false, true);
         }
     }
@@ -689,7 +698,7 @@
     if (value < 0) error (DWT.ERROR_INVALID_ARGUMENT);
     if (value is digits) return;
     digits = value;
-    int pos = (int)buttonView.doubleValue();    
+    int pos = cast(int)buttonView.doubleValue();    
     textFormatter.setMaximumFractionDigits(digits);
     setSelection (pos, false, true, false);
 }
@@ -808,7 +817,7 @@
         (cast(NSStepper)buttonView).setDoubleValue(value);
     }
     if (setText) {
-        String string = String.valueOf (value);
+        String string = String_.valueOf (value);
         if (digits > 0) {
             String decimalSeparator = textFormatter.decimalSeparator().getString();
             int index = string.length () - digits;
@@ -827,7 +836,7 @@
         }
         NSCell cell = new NSCell(textView.cell());
         if (hooks (DWT.Verify) || filters (DWT.Verify)) {
-            int length = (int)/*64*/cell.title().length();
+            int length = cast(int)/*64*/cell.title().length();
             string = verifyText (string, 0, length, null);
             if (string is null) return;
         }
@@ -876,15 +885,15 @@
     setSelection (selection, true, true, false);
 }
 
-void textDidChange (int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
+void textDidChange (objc.id id, objc.SEL sel, objc.id aNotification) {
     postEvent (DWT.Modify);
 }
 
-void textDidEndEditing(int /*long*/ id, int /*long*/ sel, int /*long*/ aNotification) {
+void textDidEndEditing(objc.id id, objc.SEL sel, objc.id aNotification) {
     bool [] parseFail = new bool [1];
     int value = getSelectionText (parseFail);
     if (parseFail [0]) {
-        value = (int)buttonView.doubleValue();
+        value = cast(int)buttonView.doubleValue();
         setSelection (value, false, true, false);
     }
 }