changeset 71:3607217555f2

Ported dwt.widgets.Link
author Jacob Carlborg <doob@me.com>
date Tue, 23 Dec 2008 23:40:01 +0100
parents 2d5ef909b21d
children e08aaf7b6830
files dwt/widgets/Link.d dwt/widgets/List.d
diffstat 2 files changed, 27 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/dwt/widgets/Link.d	Tue Dec 23 23:30:38 2008 +0100
+++ b/dwt/widgets/Link.d	Tue Dec 23 23:40:01 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.Link;
 
@@ -30,6 +33,14 @@
 import dwt.internal.cocoa.SWTScrollView;
 import dwt.internal.cocoa.SWTTextView;
 
+static import tango.text.Text;
+
+import objc = dwt.internal.objc.runtime;
+import dwt.widgets.Composite;
+import dwt.widgets.Control;
+
+alias tango.text.Text.Text!(char) Text8;
+
 /**
  * Instances of this class represent a selectable
  * user interface object that displays a text with 
@@ -122,7 +133,7 @@
     addListener (DWT.DefaultSelection, typedListener);
 }
 
-bool textView_clickOnLink_atIndex(int /*long*/ id, int /*long*/ sel, int /*long*/ textView, int /*long*/ link, int /*long*/ charIndex) {
+bool textView_clickOnLink_atIndex(objc.id id, objc.SEL sel, objc.id  textView, objc.id  link, objc.id charIndex) {
     NSString str = new NSString (link);
     Event event = new Event ();
     event.text = str.getString();
@@ -165,7 +176,7 @@
     scrollWidget.setDrawsBackground(false);
     scrollWidget.setBorderType(hasBorder() ? OS.NSBezelBorder : OS.NSNoBorder);
 
-    NSTextView widget = cast(NSTextView)new SWTTextView().alloc();
+    NSTextView widget = cast(NSTextView)(new SWTTextView()).alloc();
     widget.initWithFrame(NSRect());
     widget.setEditable(false);
     widget.setDrawsBackground(false);
@@ -247,16 +258,16 @@
 }
 
 String parse (String string) {
-    int length = string.length ();
-    offsets = new Point [length / 4];
-    ids = new String [length / 4];
-    mnemonics = new int [length / 4 + 1];
-    StringBuffer result = new StringBuffer ();
-    char [] buffer = new char [length];
+    int length_ = string.length ();
+    offsets = new Point [length_ / 4];
+    ids = new String [length_ / 4];
+    mnemonics = new int [length_ / 4 + 1];
+    Text8 result = new Text8 ();
+    char [] buffer = new char [length_];
     string.getChars (0, string.length (), buffer, 0);
     int index = 0, state = 0, linkIndex = 0;
     int start = 0, tagStart = 0, linkStart = 0, endtagStart = 0, refStart = 0;
-    while (index < length) {
+    while (index < length_) {
         char c = Character.toLowerCase (buffer [index]);
         switch (state) {
             case 0: 
@@ -355,9 +366,9 @@
         }
         index++;
     }
-    if (start < length) {
+    if (start < length_) {
         int tmp = parseMnemonics (buffer, start, tagStart, result);
-        int mnemonic = parseMnemonics (buffer, Math.max (tagStart, linkStart), length, result);
+        int mnemonic = parseMnemonics (buffer, Math.max (tagStart, linkStart), length_, result);
         if (mnemonic is -1) mnemonic = tmp;
         mnemonics [linkIndex] = mnemonic;
     } else {
@@ -377,7 +388,7 @@
     return result.toString ();
 }
 
-int parseMnemonics (char[] buffer, int start, int end, StringBuffer result) {
+int parseMnemonics (char[] buffer, int start, int end, Text8 result) {
     int mnemonic = -1, index = start;
     while (index < end) {
         if (buffer [index] is '&') {
@@ -396,7 +407,7 @@
 }
 
 void setFont(NSFont font) {
-    ((NSTextView) view).setFont(font);
+    (cast(NSTextView) view).setFont(font);
 }
 
 /**
--- a/dwt/widgets/List.d	Tue Dec 23 23:30:38 2008 +0100
+++ b/dwt/widgets/List.d	Tue Dec 23 23:40:01 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.List;