diff dwt/widgets/Text.d @ 138:3d9eb62cd2e3

Fixes #8
author Jacob Carlborg <doob@me.com>
date Wed, 03 Jun 2009 00:36:31 +0200
parents 07399639c0c8
children 86fc761a24ae
line wrap: on
line diff
--- a/dwt/widgets/Text.d	Sat May 30 23:40:34 2009 +0200
+++ b/dwt/widgets/Text.d	Wed Jun 03 00:36:31 2009 +0200
@@ -1,4 +1,4 @@
-/*******************************************************************************
+/*******************************************************************************
  * Copyright (c) 2000, 2008 IBM Corporation and others.
  * All rights reserved. This program and the accompanying materials
  * are made available under the terms of the Eclipse Public License v1.0
@@ -58,6 +58,8 @@
 import dwt.widgets.Scrollable;
 import dwt.widgets.TypedListener;
 
+import mambo.io;
+
 /**
  * Instances of this class are selectable user interface
  * objects that allow the user to enter and modify text.
@@ -98,37 +100,37 @@
     int textLimit, tabs = 8;
     char echoCharacter;
     bool doubleClick, receivingFocus;
-    String hiddenText, message;
+    wchar[] hiddenText, message;
     NSRange* selectionRange;
     NSRange selectionRangeStruct;
     
-/**
- * The maximum number of characters that can be entered
- * into a text widget.
- * <p>
- * Note that this value is platform dependent, based upon
- * the native widget implementation.
- * </p>
- */
-public static const int LIMIT;
+    /**
+    * The maximum number of characters that can be entered
+    * into a text widget.
+    * <p>
+    * Note that this value is platform dependent, based upon
+    * the native widget implementation.
+    * </p>
+    */
+	public static const int LIMIT;
 
-/**
- * The delimiter used by multi-line text widgets.  When text
- * is queried and from the widget, it will be delimited using
- * this delimiter.
- */
-public static const String DELIMITER;
-static const wchar PASSWORD = '\u2022';
+    /**
+    * The delimiter used by multi-line text widgets.  When text
+    * is queried and from the widget, it will be delimited using
+    * this delimiter.
+    */
+	public static const String DELIMITER;
+	static const wchar PASSWORD = '\u2022';
 
-/*
- * These values can be different on different platforms.
- * Therefore they are not initialized in the declaration
- * to stop the compiler from inlining.
- */
-static this () {
-    LIMIT = 0x7FFFFFFF;
-    DELIMITER = "\r";
-}
+	/*
+    * These values can be different on different platforms.
+    * Therefore they are not initialized in the declaration
+    * to stop the compiler from inlining.
+    */
+    static this () {
+        LIMIT = 0x7FFFFFFF;
+        DELIMITER = "\r";
+    }
 
 /**
  * Constructs a new instance of this class given its parent
@@ -436,8 +438,8 @@
         if ((style & DWT.CENTER) !is 0) align_ = OS.NSCenterTextAlignment;
         if ((style & DWT.RIGHT) !is 0) align_ = OS.NSRightTextAlignment;
         widget.setAlignment (align_);
-        //      widget.setTarget(widget);
-        //      widget.setAction(OS.sel_sendSelection);
+//      widget.setTarget(widget);
+//      widget.setAction(OS.sel_sendSelection);
         view = widget;
     } else {
         NSScrollView scrollWidget = cast(NSScrollView) (new SWTScrollView ()).alloc ();
@@ -455,7 +457,7 @@
         size.width = size.height = Float.MAX_VALUE;
         widget.setMaxSize (size);
         widget.setAutoresizingMask (OS.NSViewWidthSizable | OS.NSViewHeightSizable);
-        
+
         if ((style & DWT.WRAP) is 0) {
             NSTextContainer textContainer = widget.textContainer ();
             widget.setHorizontallyResizable (true);
@@ -464,14 +466,14 @@
             csize.width = csize.height = Float.MAX_VALUE;
             textContainer.setContainerSize (csize);
         }
-        
+
         NSTextAlignment align_ = OS.NSLeftTextAlignment;
         if ((style & DWT.CENTER) !is 0) align_ = OS.NSCenterTextAlignment;
         if ((style & DWT.RIGHT) !is 0) align_ = OS.NSRightTextAlignment;
         widget.setAlignment (align_);
-        
-        //      widget.setTarget(widget);
-        //      widget.setAction(OS.sel_sendSelection);
+
+//      widget.setTarget(widget);
+//      widget.setAction(OS.sel_sendSelection);
         widget.setRichText (false);
         widget.setDelegate(widget);
         
@@ -606,8 +608,8 @@
         //TODO - caret location for unicode text
         return new Point (0, 0);
     }
-    //  NSText
-    //  NSRange range = (cast(NSTextView)view).selectedRange();
+//  NSText
+//  NSRange range = (cast(NSTextView)view).selectedRange();
     return null;
 }
 
@@ -718,17 +720,17 @@
     } else {
         str = (cast(NSTextView)view).textStorage().string();
     }
-    
+
     NSUInteger length_ = str.length ();
-    char [] buffer = new char [length_];
+    wchar [] buffer = new wchar [length_];
     if (hiddenText !is null) {
         hiddenText.getChars (0, length_, buffer, 0);
     } else {
         NSRange range = NSRange ();
         range.length = length_;
-        str.getCharacters (buffer.toString16().ptr, range);
+        str.getCharacters (buffer.ptr, range);
     }
-    return buffer;
+    return dwt.dwthelper.utils.toString(buffer);
 }
 
 char [] getEditText (int start, int end) {
@@ -738,7 +740,7 @@
     } else {
         str = (cast(NSTextView)view).textStorage().string();
     }
-    
+
     int length = cast(int)/*64*/str.length ();
     end = Math.min (end, length - 1);
     if (start > end) return new char [0];
@@ -746,13 +748,13 @@
     NSRange range = NSRange ();
     range.location = start;
     range.length = Math.max (0, end - start + 1);
-    char [] buffer = new char [range.length];
+    wchar [] buffer = new wchar [range.length];
     if (hiddenText !is null) {
         hiddenText.getChars (cast(int)/*64*/range.location, cast(int)/*64*/(range.location + range.length), buffer, 0);
     } else {
-        str.getCharacters (buffer.toString16().ptr, range);
+        str.getCharacters (buffer.ptr, range);
     }
-    return buffer;
+    return dwt.dwthelper.utils.toString(buffer);
 }
 
 /**
@@ -843,11 +845,11 @@
  */
 public String getMessage () {
     checkWidget ();
-    return message;
+    return dwt.dwthelper.utils.toString(message);
 }
 
 int getPosition (int x, int y) {
-    //  checkWidget ();
+//  checkWidget ();
     //TODO 
     return 0;
 }
@@ -932,9 +934,9 @@
         NSTextView widget = cast(NSTextView) view;
         NSRange range = widget.selectedRange ();
         NSString str = widget.textStorage ().string ();
-        char[] buffer = new char [range.length];
-        str.getCharacters (buffer.toString16().ptr, range);
-        return new_String (buffer);
+        wchar[] buffer = new wchar [range.length];        
+        str.getCharacters (buffer.ptr, range);
+        return dwt.dwthelper.utils.toString(buffer);
     }
 }
 
@@ -1446,17 +1448,17 @@
 public void setEchoChar (char echo) {
     checkWidget ();
     if ((style & DWT.MULTI) !is 0) return;
-    //  if (txnObject is 0) {
-    //      if ((style & DWT.PASSWORD) is 0) {
-    //          Point selection = getSelection ();
-    //          String text = getText ();
-    //          echoCharacter = echo;
-    //          setEditText (text);
-    //          setSelection (selection);
-    //      }
-    //  } else {
-    //      OS.TXNEchoMode (txnObject, echo, OS.kTextEncodingMacUnicode, echo !is '\0');
-    //  }
+//  if (txnObject is 0) {
+//      if ((style & DWT.PASSWORD) is 0) {
+//          Point selection = getSelection ();
+//          String text = getText ();
+//          echoCharacter = echo;
+//          setEditText (text);
+//          setSelection (selection);
+//      }
+//  } else {
+//      OS.TXNEchoMode (txnObject, echo, OS.kTextEncodingMacUnicode, echo !is '\0');
+//  }
     echoCharacter = echo;
 }
 
@@ -1487,7 +1489,7 @@
 void setEditText (String string) {
     char [] buffer;
     if ((style & DWT.PASSWORD) is 0 && echoCharacter !is '\0') {
-        hiddenText = string;
+        hiddenText = string.toString16();
         buffer = new char [Math.min(hiddenText.length (), textLimit)];
         for (int i = 0; i < buffer.length; i++) buffer [i] = echoCharacter;
     } else {
@@ -1568,15 +1570,15 @@
 public void setMessage (String message) {
     checkWidget ();
     //if (message is null) error (DWT.ERROR_NULL_ARGUMENT);
-    this.message = message;
-    //  if ((style & DWT.SEARCH) !is 0) {
-    //      char [] buffer = new char [message.length ()];
-    //      message.getChars (0, buffer.length, buffer, 0);
-    //      int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
-    //      if (ptr is 0) error (DWT.ERROR_CANNOT_SET_TEXT);
-    //      OS.HISearchFieldSetDescriptiveText (handle, ptr);
-    //      OS.CFRelease (ptr);
-    //  }
+    this.message = message.toString16();
+//  if ((style & DWT.SEARCH) !is 0) {
+//      char [] buffer = new char [message.length ()];
+//      message.getChars (0, buffer.length, buffer, 0);
+//      int ptr = OS.CFStringCreateWithCharacters (OS.kCFAllocatorDefault, buffer, buffer.length);
+//      if (ptr is 0) error (DWT.ERROR_CANNOT_SET_TEXT);
+//      OS.HISearchFieldSetDescriptiveText (handle, ptr);
+//      OS.CFRelease (ptr);
+//  }
 }
 
 /**
@@ -1712,14 +1714,14 @@
 public void setTabs (int tabs) {
     checkWidget ();
     if (this.tabs is tabs) return;
-    //  if (txnObject is 0) return;
-    //  this.tabs = tabs;
-    //  TXNTab tab = new TXNTab ();
-    //  tab.value = cast(short) (textExtent (new char[]{' '}, 0).x * tabs);
-    //  int [] tags = new int [] {OS.kTXNTabSettingsTag};
-    //  int [] datas = new int [1];
-    //  OS.memmove (datas, tab, TXNTab.sizeof);
-    //  OS.TXNSetTXNObjectControls (txnObject, false, tags.length, tags, datas);
+//  if (txnObject is 0) return;
+//  this.tabs = tabs;
+//  TXNTab tab = new TXNTab ();
+//  tab.value = cast(short) (textExtent (new char[]{' '}, 0).x * tabs);
+//  int [] tags = new int [] {OS.kTXNTabSettingsTag};
+//  int [] datas = new int [1];
+//  OS.memmove (datas, tab, TXNTab.sizeof);
+//  OS.TXNSetTXNObjectControls (txnObject, false, tags.length, tags, datas);
 }
 
 /**
@@ -1799,10 +1801,10 @@
     checkWidget ();
     if ((style & DWT.SINGLE) !is 0) return;
     //TODO no working
-    //  NSTextView widget = cast(NSTextView) view;
-    //  NSRange range = NSRange ();
-    //  NSRect rect = widget.firstRectForCharacterRange (range);
-    //  view.scrollRectToVisible (rect);
+//  NSTextView widget = cast(NSTextView) view;
+//  NSRange range = NSRange ();
+//  NSRect rect = widget.firstRectForCharacterRange (range);
+//  view.scrollRectToVisible (rect);
 }
 
 /**
@@ -1841,12 +1843,12 @@
 
 NSRange textView_willChangeSelectionFromCharacterRange_toCharacterRange (objc.id id, objc.SEL sel, objc.id aTextView, objc.id oldSelectedCharRange, objc.id newSelectedCharRange) {
     /*
-     * If the selection is changing as a result of the receiver getting focus
-     * then return the receiver's last selection range, otherwise the full
-     * text will be automatically selected.
-     */
+    * If the selection is changing as a result of the receiver getting focus
+    * then return the receiver's last selection range, otherwise the full
+    * text will be automatically selected.
+    */
     if (receivingFocus && selectionRange !is null) return selectionRangeStruct;
-    
+
     /* allow the selection change to proceed */
     NSRange result = NSRange ();
     OS.memmove(&result, newSelectedCharRange, NSRange.sizeof);