diff dwt/widgets/DateTime.d @ 240:ce446666f5a2

Update to SWT 3.4M7
author Frank Benoit <benoit@tionex.de>
date Mon, 12 May 2008 19:13:01 +0200
parents 380bad9f6852
children c0d810de7093
line wrap: on
line diff
--- a/dwt/widgets/DateTime.d	Mon May 12 15:36:37 2008 +0200
+++ b/dwt/widgets/DateTime.d	Mon May 12 19:13:01 2008 +0200
@@ -190,7 +190,11 @@
         default: assert( false, Format( "no matching switch case for field {}.", field ));
         }
     }
-
+    void set( int year, int month, int day ){
+        this.year = year;
+        this.month = month;
+        this.dayofmonth = day;
+    }
     void set(int field, int value){
         switch( field ){
         case YEAR:
@@ -433,6 +437,8 @@
         formatSymbols = new DateFormatSymbols();
 
         text = new Text(this, DWT.SINGLE);
+        /* disable the native drag and drop for the date/time text field */
+        OS.gtk_drag_dest_unset(text.handle);
         if ((this.style & DWT.DATE) !is 0) {
             setFormat((this.style & DWT.SHORT) !is 0 ? DEFAULT_SHORT_DATE_FORMAT : (this.style & DWT.LONG) !is 0 ? DEFAULT_LONG_DATE_FORMAT : DEFAULT_MEDIUM_DATE_FORMAT);
         } else { // DWT.TIME
@@ -639,8 +645,8 @@
         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!(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];
+        if ((style & DWT.SHORT) !is 0) return "" ~ (h < 10 ? " " : "") ~ to!(String)(h) ~ ":" ~ (m < 10 ? "0" : "") ~ to!(String)(m) ~ " " ~ ampm[a];
+        return "" ~ (h < 10 ? " " : "") ~ to!(String)(h) ~ ":" ~ (m < 10 ? "0" : "") ~ to!(String)(m) ~ ":" ~ (s < 10 ? "0" : "") ~ to!(String)(s) ~ " " ~ ampm[a];
     }
     /* DWT.DATE */
     int y = calendar.get(Calendar.YEAR);
@@ -750,6 +756,15 @@
     }
 }
 
+String getNameText() {
+    if((style & DWT.TIME) !is 0){
+        return Format( "{}:{}:{}", getHours(), getMinutes(), getSeconds() );
+    }
+    else{
+        return Format( "{}/{}/{}", (getMonth() + 1), getDay(), getYear() );
+    }
+}
+
 /**
  * Returns the receiver's seconds.
  * <p>
@@ -827,6 +842,12 @@
     return value >= min && value <= max;
 }
 
+bool isValid(int year, int month, int day) {
+    Calendar valid = Calendar.getInstance();
+    valid.set(year, month, day);
+    return valid.get(Calendar.YEAR) is year && valid.get(Calendar.MONTH) is month && valid.get(Calendar.DAY_OF_MONTH) is day;
+}
+
 void incrementField(int amount) {
     int fieldName = fieldNames[currentField];
     int value = calendar.get(fieldName);
@@ -1111,7 +1132,7 @@
         calendar.roll(Calendar.HOUR_OF_DAY, 12); // TODO: needs more work for setFormat and locale
     }
     calendar.set(fieldName, value);
-    notifyListeners(DWT.Selection, new Event());
+    postEvent(DWT.Selection);
 }
 
 void setTextField(int fieldName, int value, bool commit, bool adjust) {
@@ -1138,7 +1159,15 @@
     /* Convert leading 0's into spaces. */
     int prependCount = end - start - buffer.length();
     for (int i = 0; i < prependCount; i++) {
-        buffer.prepend(' ');
+        switch (fieldName) {
+        case Calendar.MINUTE:
+        case Calendar.SECOND:
+            buffer.prepend('0');
+        break;
+        default:
+            buffer.prepend(' ');
+        break;
+        }
     }
     newValue = buffer.toString();
     ignoreVerify = true;
@@ -1149,6 +1178,41 @@
 }
 
 /**
+ * Sets the receiver's year, month, and day in a single operation.
+ * <p>
+ * This is the recommended way to set the date, because setting the year,
+ * month, and day separately may result in invalid intermediate dates.
+ * </p>
+ *
+ * @param year an integer between 1752 and 9999
+ * @param month an integer between 0 and 11
+ * @param day a positive integer beginning with 1
+ *
+ * @exception DWTException <ul>
+ *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ *
+ * @since 3.4
+ */
+public void setDate (int year, int month, int day) {
+    checkWidget ();
+    if (!isValid(year, month, day)) return;
+    if ((style & DWT.CALENDAR) !is 0) {
+        this.year = year;
+        this.month = month;
+        this.day = day;
+        OS.gtk_calendar_select_month(handle, month, year);
+        OS.gtk_calendar_select_day(handle, day);
+    } else {
+        calendar.set(Calendar.YEAR, year);
+        calendar.set(Calendar.MONTH, month);
+        calendar.set(Calendar.DAY_OF_MONTH, day);
+        updateControl();
+    }
+}
+
+/**
  * Sets the receiver's date, or day of the month, to the specified day.
  * <p>
  * The first day of the month is 1, and the last day depends on the month and year.
@@ -1271,6 +1335,37 @@
 }
 
 /**
+ * Sets the receiver's hours, minutes, and seconds in a single operation.
+ *
+ * @param hours an integer between 0 and 23
+ * @param minutes an integer between 0 and 59
+ * @param seconds an integer between 0 and 59
+ *
+ * @exception DWTException <ul>
+ *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
+ *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
+ * </ul>
+ *
+ * @since 3.4
+ */
+public void setTime (int hours, int minutes, int seconds) {
+    checkWidget ();
+    if (!isValid(Calendar.HOUR_OF_DAY, hours)) return;
+    if (!isValid(Calendar.MINUTE, minutes)) return;
+    if (!isValid(Calendar.SECOND, seconds)) return;
+    if ((style & DWT.CALENDAR) !is 0) {
+        this.hours = hours;
+        this.minutes = minutes;
+        this.seconds = seconds;
+    } else {
+        calendar.set(Calendar.HOUR_OF_DAY, hours);
+        calendar.set(Calendar.MINUTE, minutes);
+        calendar.set(Calendar.SECOND, seconds);
+        updateControl();
+    }
+}
+
+/**
  * Sets the receiver's year.
  * <p>
  * The first year is 1752 and the last year is 9999.