Changeset 238:380bad9f6852 for dwt/widgets/DateTime.d
- Timestamp:
- 05/04/08 18:42:55 (4 years ago)
- Files:
-
- dwt/widgets/DateTime.d (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
dwt/widgets/DateTime.d
r203 r238 279 279 280 280 private class DateFormatSymbols { 281 private const char[][] ampm = [ "AM"[], "PM" ];282 char[][] getAmPmStrings(){281 private const String[] ampm = [ "AM"[], "PM" ]; 282 String[] getAmPmStrings(){ 283 283 return ampm; 284 284 } … … 382 382 Button down, up; 383 383 Text text; 384 char[]format;384 String format; 385 385 Point[] fieldIndices; 386 386 int[] fieldNames; 387 387 int fieldCount, currentField = 0, characterCount = 0; 388 388 bool ignoreVerify = false; 389 static const char[]DEFAULT_SHORT_DATE_FORMAT = "MM/YYYY";390 static const char[]DEFAULT_MEDIUM_DATE_FORMAT = "MM/DD/YYYY";391 static const char[]DEFAULT_LONG_DATE_FORMAT = "MM/DD/YYYY";392 static const char[]DEFAULT_SHORT_TIME_FORMAT = "HH:MM AM";393 static const char[]DEFAULT_MEDIUM_TIME_FORMAT = "HH:MM:SS AM";394 static const char[]DEFAULT_LONG_TIME_FORMAT = "HH:MM:SS AM";389 static const String DEFAULT_SHORT_DATE_FORMAT = "MM/YYYY"; 390 static const String DEFAULT_MEDIUM_DATE_FORMAT = "MM/DD/YYYY"; 391 static const String DEFAULT_LONG_DATE_FORMAT = "MM/DD/YYYY"; 392 static const String DEFAULT_SHORT_TIME_FORMAT = "HH:MM AM"; 393 static const String DEFAULT_MEDIUM_TIME_FORMAT = "HH:MM:SS AM"; 394 static const String DEFAULT_LONG_TIME_FORMAT = "HH:MM:SS AM"; 395 395 396 396 … … 592 592 int start = fieldIndices[currentField].x; 593 593 int end = fieldIndices[currentField].y; 594 char[]value = text.getText(start, end - 1);594 String value = text.getText(start, end - 1); 595 595 int s = value.lastIndexOf(' '); 596 596 if (s !is -1) value = value.substring(s + 1); … … 600 600 } 601 601 602 char[]formattedStringValue(int fieldName, int value, bool adjust) {602 String formattedStringValue(int fieldName, int value, bool adjust) { 603 603 if (fieldName is Calendar.AM_PM) { 604 char[][] ampm = formatSymbols.getAmPmStrings();604 String[] ampm = formatSymbols.getAmPmStrings(); 605 605 return ampm[value]; 606 606 } 607 607 if (adjust) { 608 608 if (fieldName is Calendar.HOUR && value is 0) { 609 return to!( char[])(12);609 return to!(String)(12); 610 610 } 611 611 if (fieldName is Calendar.MONTH) { 612 return to!( char[])(value + 1);613 } 614 } 615 return to!( char[])(value);616 } 617 618 char[]getComputeSizeString(int style) {612 return to!(String)(value + 1); 613 } 614 } 615 return to!(String)(value); 616 } 617 618 String getComputeSizeString(int style) { 619 619 if ((style & DWT.DATE) !is 0) { 620 620 return (style & DWT.SHORT) !is 0 ? DEFAULT_SHORT_DATE_FORMAT : (style & DWT.LONG) !is 0 ? DEFAULT_LONG_DATE_FORMAT : DEFAULT_MEDIUM_DATE_FORMAT; … … 633 633 } 634 634 635 char[]getFormattedString(int style) {635 String getFormattedString(int style) { 636 636 if ((style & DWT.TIME) !is 0) { 637 char[][] ampm = formatSymbols.getAmPmStrings();637 String[] ampm = formatSymbols.getAmPmStrings(); 638 638 int h = calendar.get(Calendar.HOUR); if (h is 0) h = 12; 639 639 int m = calendar.get(Calendar.MINUTE); 640 640 int s = calendar.get(Calendar.SECOND); 641 641 int a = calendar.get(Calendar.AM_PM); 642 if ((style & DWT.SHORT) !is 0) return "" ~ (h < 10 ? " " : "") ~ to!( char[])(h) ~ ":" ~ (m < 10 ? " " : "") ~ to!(char[])(m) ~ " " ~ ampm[a];643 return "" ~ (h < 10 ? " " : "") ~ to!( char[])(h) ~ ":" ~ (m < 10 ? " " : "") ~ to!(char[])(m) ~ ":" ~ (s < 10 ? " " : "") ~ to!(char[])(s) ~ " " ~ ampm[a];642 if ((style & DWT.SHORT) !is 0) return "" ~ (h < 10 ? " " : "") ~ to!(String)(h) ~ ":" ~ (m < 10 ? " " : "") ~ to!(String)(m) ~ " " ~ ampm[a]; 643 return "" ~ (h < 10 ? " " : "") ~ to!(String)(h) ~ ":" ~ (m < 10 ? " " : "") ~ to!(String)(m) ~ ":" ~ (s < 10 ? " " : "") ~ to!(String)(s) ~ " " ~ ampm[a]; 644 644 } 645 645 /* DWT.DATE */ … … 647 647 int m = calendar.get(Calendar.MONTH) + 1; 648 648 int d = calendar.get(Calendar.DAY_OF_MONTH); 649 if ((style & DWT.SHORT) !is 0) return "" ~ (m < 10 ? " " : "") ~ to!( char[])(m) ~ "/" ~ to!(char[])(y);650 return "" ~ (m < 10 ? " " : "") ~ to!( char[])(m) ~ "/" ~ (d < 10 ? " " : "") ~ to!(char[])(d) ~ "/" ~ to!(char[])(y);649 if ((style & DWT.SHORT) !is 0) return "" ~ (m < 10 ? " " : "") ~ to!(String)(m) ~ "/" ~ to!(String)(y); 650 return "" ~ (m < 10 ? " " : "") ~ to!(String)(m) ~ "/" ~ (d < 10 ? " " : "") ~ to!(String)(d) ~ "/" ~ to!(String)(y); 651 651 } 652 652 … … 931 931 int end = fieldIndices[currentField].y; 932 932 int length_ = end - start; 933 char[]newText = event.text;933 String newText = event.text; 934 934 if (fieldName is Calendar.AM_PM) { 935 char[][] ampm = formatSymbols.getAmPmStrings();935 String[] ampm = formatSymbols.getAmPmStrings(); 936 936 if (newText.equalsIgnoreCase(ampm[Calendar.AM].substring(0, 1)) || newText.equalsIgnoreCase(ampm[Calendar.AM])) { 937 937 setTextField(fieldName, Calendar.AM, true, false); … … 947 947 return; 948 948 } 949 char[]value = text.getText(start, end - 1);949 String value = text.getText(start, end - 1); 950 950 int s = value.lastIndexOf(' '); 951 951 if (s !is -1) value = value.substring(s + 1); … … 1026 1026 public void run() { 1027 1027 if (!text.isDisposed()) { 1028 char[]value = text.getText(start, end - 1);1028 String value = text.getText(start, end - 1); 1029 1029 int s = value.lastIndexOf(' '); 1030 1030 if (s is -1 ) s = start; … … 1071 1071 } 1072 1072 1073 /*public*/ void setFormat( char[]string) {1073 /*public*/ void setFormat(String string) { 1074 1074 checkWidget(); 1075 1075 // TODO: this needs to be locale sensitive … … 1134 1134 int end = fieldIndices[currentField].y; 1135 1135 text.setSelection(start, end); 1136 char[]newValue = formattedStringValue(fieldName, value, adjust);1136 String newValue = formattedStringValue(fieldName, value, adjust); 1137 1137 TangoText buffer = new TangoText(newValue); 1138 1138 /* Convert leading 0's into spaces. */ … … 1297 1297 } 1298 1298 1299 int unformattedIntValue(int fieldName, char[]newText, bool adjust, int max) {1299 int unformattedIntValue(int fieldName, String newText, bool adjust, int max) { 1300 1300 int newValue; 1301 1301 try { … … 1316 1316 public void updateControl() { 1317 1317 if (text !is null) { 1318 char[]string = getFormattedString(style);1318 String string = getFormattedString(style); 1319 1319 ignoreVerify = true; 1320 1320 text.setText(string);
