diff dwt/widgets/DateTime.d @ 238:380bad9f6852

reverted char[] to String
author Frank Benoit <benoit@tionex.de>
date Mon, 05 May 2008 00:42:55 +0200
parents 4085a50170ab
children ce446666f5a2
line wrap: on
line diff
--- a/dwt/widgets/DateTime.d	Sat Apr 26 10:01:30 2008 +0200
+++ b/dwt/widgets/DateTime.d	Mon May 05 00:42:55 2008 +0200
@@ -278,8 +278,8 @@
 
 
 private class DateFormatSymbols {
-    private const char[][] ampm = [ "AM"[], "PM" ];
-    char[][] getAmPmStrings(){
+    private const String[] ampm = [ "AM"[], "PM" ];
+    String[] getAmPmStrings(){
         return ampm;
     }
 }
@@ -381,17 +381,17 @@
     DateFormatSymbols formatSymbols;
     Button down, up;
     Text text;
-    char[] format;
+    String format;
     Point[] fieldIndices;
     int[] fieldNames;
     int fieldCount, currentField = 0, characterCount = 0;
     bool ignoreVerify = false;
-    static const char[] DEFAULT_SHORT_DATE_FORMAT = "MM/YYYY";
-    static const char[] DEFAULT_MEDIUM_DATE_FORMAT = "MM/DD/YYYY";
-    static const char[] DEFAULT_LONG_DATE_FORMAT = "MM/DD/YYYY";
-    static const char[] DEFAULT_SHORT_TIME_FORMAT = "HH:MM AM";
-    static const char[] DEFAULT_MEDIUM_TIME_FORMAT = "HH:MM:SS AM";
-    static const char[] DEFAULT_LONG_TIME_FORMAT = "HH:MM:SS AM";
+    static const String DEFAULT_SHORT_DATE_FORMAT = "MM/YYYY";
+    static const String DEFAULT_MEDIUM_DATE_FORMAT = "MM/DD/YYYY";
+    static const String DEFAULT_LONG_DATE_FORMAT = "MM/DD/YYYY";
+    static const String DEFAULT_SHORT_TIME_FORMAT = "HH:MM AM";
+    static const String DEFAULT_MEDIUM_TIME_FORMAT = "HH:MM:SS AM";
+    static const String DEFAULT_LONG_TIME_FORMAT = "HH:MM:SS AM";
 
 
 
@@ -591,7 +591,7 @@
         int fieldName = fieldNames[currentField];
         int start = fieldIndices[currentField].x;
         int end = fieldIndices[currentField].y;
-        char[] value = text.getText(start, end - 1);
+        String value = text.getText(start, end - 1);
         int s = value.lastIndexOf(' ');
         if (s !is -1) value = value.substring(s + 1);
         int newValue = unformattedIntValue(fieldName, value, characterCount is 0, calendar.getActualMaximum(fieldName));
@@ -599,23 +599,23 @@
     }
 }
 
-char[] formattedStringValue(int fieldName, int value, bool adjust) {
+String formattedStringValue(int fieldName, int value, bool adjust) {
     if (fieldName is Calendar.AM_PM) {
-        char[][] ampm = formatSymbols.getAmPmStrings();
+        String[] ampm = formatSymbols.getAmPmStrings();
         return ampm[value];
     }
     if (adjust) {
         if (fieldName is Calendar.HOUR && value is 0) {
-            return to!(char[])(12);
+            return to!(String)(12);
         }
         if (fieldName is Calendar.MONTH) {
-            return to!(char[])(value + 1);
+            return to!(String)(value + 1);
         }
     }
-    return to!(char[])(value);
+    return to!(String)(value);
 }
 
-char[] getComputeSizeString(int style) {
+String getComputeSizeString(int style) {
     if ((style & DWT.DATE) !is 0) {
         return (style & DWT.SHORT) !is 0 ? DEFAULT_SHORT_DATE_FORMAT : (style & DWT.LONG) !is 0 ? DEFAULT_LONG_DATE_FORMAT : DEFAULT_MEDIUM_DATE_FORMAT;
     }
@@ -632,22 +632,22 @@
     return -1;
 }
 
-char[] getFormattedString(int style) {
+String getFormattedString(int style) {
     if ((style & DWT.TIME) !is 0) {
-        char[][] ampm = formatSymbols.getAmPmStrings();
+        String[] ampm = formatSymbols.getAmPmStrings();
         int h = calendar.get(Calendar.HOUR); if (h is 0) h = 12;
         int m = calendar.get(Calendar.MINUTE);
         int s = calendar.get(Calendar.SECOND);
         int a = calendar.get(Calendar.AM_PM);
-        if ((style & DWT.SHORT) !is 0) return "" ~ (h < 10 ? " " : "") ~ to!(char[])(h) ~ ":" ~ (m < 10 ? " " : "") ~ to!(char[])(m) ~ " " ~ ampm[a];
-        return "" ~ (h < 10 ? " " : "") ~ to!(char[])(h) ~ ":" ~ (m < 10 ? " " : "") ~ to!(char[])(m) ~ ":" ~ (s < 10 ? " " : "") ~ to!(char[])(s) ~ " " ~ ampm[a];
+        if ((style & DWT.SHORT) !is 0) return "" ~ (h < 10 ? " " : "") ~ to!(String)(h) ~ ":" ~ (m < 10 ? " " : "") ~ to!(String)(m) ~ " " ~ ampm[a];
+        return "" ~ (h < 10 ? " " : "") ~ to!(String)(h) ~ ":" ~ (m < 10 ? " " : "") ~ to!(String)(m) ~ ":" ~ (s < 10 ? " " : "") ~ to!(String)(s) ~ " " ~ ampm[a];
     }
     /* DWT.DATE */
     int y = calendar.get(Calendar.YEAR);
     int m = calendar.get(Calendar.MONTH) + 1;
     int d = calendar.get(Calendar.DAY_OF_MONTH);
-    if ((style & DWT.SHORT) !is 0) return "" ~ (m < 10 ? " " : "") ~ to!(char[])(m) ~ "/" ~ to!(char[])(y);
-    return "" ~ (m < 10 ? " " : "") ~ to!(char[])(m) ~ "/" ~ (d < 10 ? " " : "") ~ to!(char[])(d) ~ "/" ~ to!(char[])(y);
+    if ((style & DWT.SHORT) !is 0) return "" ~ (m < 10 ? " " : "") ~ to!(String)(m) ~ "/" ~ to!(String)(y);
+    return "" ~ (m < 10 ? " " : "") ~ to!(String)(m) ~ "/" ~ (d < 10 ? " " : "") ~ to!(String)(d) ~ "/" ~ to!(String)(y);
 }
 
 void getDate() {
@@ -930,9 +930,9 @@
     int start = fieldIndices[currentField].x;
     int end = fieldIndices[currentField].y;
     int length_ = end - start;
-    char[] newText = event.text;
+    String newText = event.text;
     if (fieldName is Calendar.AM_PM) {
-        char[][] ampm = formatSymbols.getAmPmStrings();
+        String[] ampm = formatSymbols.getAmPmStrings();
         if (newText.equalsIgnoreCase(ampm[Calendar.AM].substring(0, 1)) || newText.equalsIgnoreCase(ampm[Calendar.AM])) {
             setTextField(fieldName, Calendar.AM, true, false);
         } else if (newText.equalsIgnoreCase(ampm[Calendar.PM].substring(0, 1)) || newText.equalsIgnoreCase(ampm[Calendar.PM])) {
@@ -946,7 +946,7 @@
         } catch (ConversionException ex) {
             return;
         }
-        char[] value = text.getText(start, end - 1);
+        String value = text.getText(start, end - 1);
         int s = value.lastIndexOf(' ');
         if (s !is -1) value = value.substring(s + 1);
         newText = value ~ newText;
@@ -1025,7 +1025,7 @@
         }
         public void run() {
             if (!text.isDisposed()) {
-                char[] value = text.getText(start, end - 1);
+                String value = text.getText(start, end - 1);
                 int s = value.lastIndexOf(' ');
                 if (s is -1 ) s = start;
                 else s = start + s + 1;
@@ -1070,7 +1070,7 @@
     if (text !is null) text.setForeground(color);
 }
 
-/*public*/ void setFormat(char[] string) {
+/*public*/ void setFormat(String string) {
     checkWidget();
     // TODO: this needs to be locale sensitive
     fieldCount = (style & DWT.DATE) !is 0 ? ((style & DWT.SHORT) !is 0 ? 2 : 3) : ((style & DWT.SHORT) !is 0 ? 3 : 4);
@@ -1133,7 +1133,7 @@
     int start = fieldIndices[currentField].x;
     int end = fieldIndices[currentField].y;
     text.setSelection(start, end);
-    char[] newValue = formattedStringValue(fieldName, value, adjust);
+    String newValue = formattedStringValue(fieldName, value, adjust);
     TangoText buffer = new TangoText(newValue);
     /* Convert leading 0's into spaces. */
     int prependCount = end - start - buffer.length();
@@ -1296,7 +1296,7 @@
     }
 }
 
-int unformattedIntValue(int fieldName, char[] newText, bool adjust, int max) {
+int unformattedIntValue(int fieldName, String newText, bool adjust, int max) {
     int newValue;
     try {
         newValue = to!(int)(newText);
@@ -1315,7 +1315,7 @@
 
 public void updateControl() {
     if (text !is null) {
-        char[] string = getFormattedString(style);
+        String string = getFormattedString(style);
         ignoreVerify = true;
         text.setText(string);
         ignoreVerify = false;