diff dwt/widgets/Text.d @ 90:c7f7f4d7091a

All widgets are ported
author Jacob Carlborg <doob@me.com>
date Tue, 30 Dec 2008 18:54:31 +0100
parents 681769fb5a7a
children 63a09873578e
line wrap: on
line diff
--- a/dwt/widgets/Text.d	Tue Dec 30 17:01:10 2008 +0100
+++ b/dwt/widgets/Text.d	Tue Dec 30 18:54:31 2008 +0100
@@ -50,10 +50,11 @@
 import dwt.internal.cocoa.SWTTextField;
 import dwt.internal.cocoa.SWTTextView;
 
-import dwt.internal.c.Carbon;
+import Carbon = dwt.internal.c.Carbon;
 import dwt.internal.objc.cocoa.Cocoa;
 import objc = dwt.internal.objc.runtime;
 import dwt.widgets.Composite;
+import dwt.widgets.Event;
 import dwt.widgets.Scrollable;
 import dwt.widgets.TypedListener;
 
@@ -86,11 +87,12 @@
  * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
  */
 public class Text : Scrollable {
-    int textLimit = LIMIT, tabs = 8;
+    int textLimit, tabs = 8;
     char echoCharacter;
     bool doubleClick, receivingFocus;
     String hiddenText, message;
-    NSRange selectionRange;
+    NSRange* selectionRange;
+    NSRange selectionRangeStruct;
     
     /**
     * The maximum number of characters that can be entered
@@ -152,6 +154,8 @@
  * @see Widget#getStyle
  */
 public this (Composite parent, int style) {
+    textLimit = LIMIT;
+    
     super (parent, checkStyle (style));
     if ((style & DWT.SEARCH) !is 0) {
 //      int inAttributesToSet = (style & DWT.CANCEL) !is 0 ? OS.kHISearchFieldAttributesCancel : 0;
@@ -1130,11 +1134,11 @@
         String oldText = getText ();
         if (textLimit !is LIMIT) {
             int charCount = oldText.length ();
-            if (charCount - (selection.y - selection.x) + length > textLimit) {
+            if (charCount - (selection.y - selection.x) + length_ > textLimit) {
                 string = string.substring(0, textLimit - charCount + (selection.y - selection.x));
             }
         }
-        String newText = oldText.substring (0, selection.x) + string + oldText.substring (selection.y);
+        String newText = oldText.substring (0, selection.x) ~ string ~ oldText.substring (selection.y);
         setEditText (newText);
         setSelection (selection.x + string.length ());
     }
@@ -1349,7 +1353,7 @@
             break;
         default:
             if (character !is '\t' && character < 0x20) return true;
-            oldText = new String ([character]);
+            oldText = new_String ([character]);
     }
     String newText = verifyText (oldText, start, end, nsEvent);
     if (newText is null) return false;
@@ -1371,7 +1375,7 @@
     return result;
 }
 
-void setBackground (CGFloat [] color) {
+void setBackground (Carbon.CGFloat [] color) {
     NSColor nsColor;
     if (color is null) {
         return; // TODO reset to OS default
@@ -1494,7 +1498,7 @@
     super.setFont (font);
 }
 
-void setForeground (CGFloat [] color) {
+void setForeground (Carbon.CGFloat [] color) {
     NSColor nsColor;
     if (color is null) {
         return; // TODO reset to OS default
@@ -1625,12 +1629,13 @@
         int length = cast(int)/*64*/str.length ();
         int selStart = Math.min (Math.max (Math.min (start, end), 0), length);
         int selEnd = Math.min (Math.max (Math.max (start, end), 0), length);
-        selectionRange = NSRange ();
+        selectionRangeStruct = NSRange ();
+        selectionRange = &selectionRangeStruct;
         selectionRange.location = selStart;
         selectionRange.length = selEnd - selStart;
         if (this is display.getFocusControl ()) {
             NSText editor = view.window ().fieldEditor (false, view);
-            editor.setSelectedRange (selectionRange);
+            editor.setSelectedRange (selectionRangeStruct);
         }
     } else {
         int length = cast(int)/*64*/(cast(NSTextView) view).textStorage ().length ();
@@ -1816,7 +1821,8 @@
 void textViewDidChangeSelection(objc.id id, objc.SEL sel, objc.id aNotification) {
     NSNotification notification = new NSNotification (aNotification);
     NSText editor = new NSText (notification.object ().id);
-    selectionRange = editor.selectedRange ();
+    selectionRangeStruct = editor.selectedRange ();
+    selectionRange = &selectionRangeStruct;
 }
 
 void textDidChange (objc.id id, objc.SEL sel, objc.id aNotification) {
@@ -1829,7 +1835,7 @@
     * then return the receiver's last selection range, otherwise the full
     * text will be automatically selected.
     */
-    if (receivingFocus && selectionRange !is null) return selectionRange;
+    if (receivingFocus && selectionRange !is null) return selectionRangeStruct;
 
     /* allow the selection change to proceed */
     NSRange result = NSRange ();