comparison dwt/widgets/DateTime.d @ 45:d8635bb48c7c

Merge with SWT 3.5
author Jacob Carlborg <doob@me.com>
date Mon, 01 Dec 2008 17:07:00 +0100
parents e831403a80a9
children cfa563df4fdd
comparison
equal deleted inserted replaced
44:ca5e494f2bbf 45:d8635bb48c7c
1 /******************************************************************************* 1 /*******************************************************************************
2 * Copyright (c) 2000, 2007 IBM Corporation and others. 2 * Copyright (c) 2000, 2008 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials 3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Eclipse Public License v1.0 4 * are made available under the terms of the Eclipse Public License v1.0
5 * which accompanies this distribution, and is available at 5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/epl-v10.html 6 * http://www.eclipse.org/legal/epl-v10.html
7 * 7 *
44 * Note: Only one of the styles DATE, TIME, or CALENDAR may be specified, 44 * Note: Only one of the styles DATE, TIME, or CALENDAR may be specified,
45 * and only one of the styles SHORT, MEDIUM, or LONG may be specified. 45 * and only one of the styles SHORT, MEDIUM, or LONG may be specified.
46 * </p><p> 46 * </p><p>
47 * IMPORTANT: This class is <em>not</em> intended to be subclassed. 47 * IMPORTANT: This class is <em>not</em> intended to be subclassed.
48 * </p> 48 * </p>
49 *
50 * @see <a href="http://www.eclipse.org/swt/snippets/#datetime">DateTime snippets</a>
51 * @see <a href="http://www.eclipse.org/swt/examples.php">DWT Example: ControlExample</a>
52 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a>
49 * 53 *
50 * @since 3.3 54 * @since 3.3
51 */ 55 */
52 public class DateTime : Composite { 56 public class DateTime : Composite {
53 57
174 widget.setDatePickerElements(elementFlags); 178 widget.setDatePickerElements(elementFlags);
175 NSDate date = NSCalendarDate.calendarDate(); 179 NSDate date = NSCalendarDate.calendarDate();
176 widget.setDateValue(date); 180 widget.setDateValue(date);
177 widget.setTarget(widget); 181 widget.setTarget(widget);
178 widget.setAction(OS.sel_sendSelection); 182 widget.setAction(OS.sel_sendSelection);
179 widget.setTag(jniRef); 183 view = widget;
180 view = widget; 184 }
181 parent.contentView().addSubview_(widget); 185
186 NSCalendarDate getCalendarDate () {
187 NSDate date = ((NSDatePicker)view).dateValue();
188 return date.dateWithCalendarFormat(null, null);
182 } 189 }
183 190
184 /** 191 /**
185 * Returns the receiver's date, or day of the month. 192 * Returns the receiver's date, or day of the month.
186 * <p> 193 * <p>
194 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 201 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
195 * </ul> 202 * </ul>
196 */ 203 */
197 public int getDay () { 204 public int getDay () {
198 checkWidget (); 205 checkWidget ();
199 NSDate date = (cast(NSDatePicker)view).dateValue(); 206 return cast(int)/*64*/getCalendarDate().dayOfMonth();
200 NSCalendarDate calendarDate = date.dateWithCalendarFormat(null, null);
201 return calendarDate.dayOfMonth();
202 } 207 }
203 208
204 /** 209 /**
205 * Returns the receiver's hours. 210 * Returns the receiver's hours.
206 * <p> 211 * <p>
214 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 219 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
215 * </ul> 220 * </ul>
216 */ 221 */
217 public int getHours () { 222 public int getHours () {
218 checkWidget (); 223 checkWidget ();
219 return new NSCalendarDate((cast(NSDatePicker)view).dateValue().id).hourOfDay(); 224 return cast(int)/*64*/getCalendarDate().hourOfDay();
220 } 225 }
221 226
222 /** 227 /**
223 * Returns the receiver's minutes. 228 * Returns the receiver's minutes.
224 * <p> 229 * <p>
232 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 237 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
233 * </ul> 238 * </ul>
234 */ 239 */
235 public int getMinutes () { 240 public int getMinutes () {
236 checkWidget (); 241 checkWidget ();
237 return new NSCalendarDate((cast(NSDatePicker)view).dateValue().id).minuteOfHour(); 242 return csat(int)/*64*/getCalendarDate().minuteOfHour();
238 } 243 }
239 244
240 /** 245 /**
241 * Returns the receiver's month. 246 * Returns the receiver's month.
242 * <p> 247 * <p>
250 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 255 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
251 * </ul> 256 * </ul>
252 */ 257 */
253 public int getMonth () { 258 public int getMonth () {
254 checkWidget (); 259 checkWidget ();
255 return new NSCalendarDate((cast(NSDatePicker)view).dateValue().id).monthOfYear() - 1; 260 return csat(int)/*64*/getCalendarDate().monthOfYear() - 1;
256 } 261 }
257 262
258 String getNameText() { 263 String getNameText() {
259 return (style & DWT.TIME) !is 0 ? getHours() + ":" + getMinutes() + ":" + getSeconds() 264 return (style & DWT.TIME) !is 0 ? getHours() + ":" + getMinutes() + ":" + getSeconds()
260 : (getMonth() + 1) + "/" + getDay() + "/" + getYear(); 265 : (getMonth() + 1) + "/" + getDay() + "/" + getYear();
273 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 278 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
274 * </ul> 279 * </ul>
275 */ 280 */
276 public int getSeconds () { 281 public int getSeconds () {
277 checkWidget (); 282 checkWidget ();
278 return new NSCalendarDate((cast(NSDatePicker)view).dateValue().id).secondOfMinute(); 283 return cast(int)/*64*/getCalendarDate().secondOfMinute();
279 } 284 }
280 285
281 /** 286 /**
282 * Returns the receiver's year. 287 * Returns the receiver's year.
283 * <p> 288 * <p>
291 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 296 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
292 * </ul> 297 * </ul>
293 */ 298 */
294 public int getYear () { 299 public int getYear () {
295 checkWidget (); 300 checkWidget ();
296 return new NSCalendarDate((cast(NSDatePicker)view).dateValue().id).yearOfCommonEra(); 301 return cast(int)/*64*/getCalendarDate().yearOfCommonEra();
297 } 302 }
298 303
299 /** 304 /**
300 * Removes the listener from the collection of listeners who will 305 * Removes the listener from the collection of listeners who will
301 * be notified when the control is selected by the user. 306 * be notified when the control is selected by the user.
353 * 358 *
354 * @since 3.4 359 * @since 3.4
355 */ 360 */
356 public void setDate (int year, int month, int day) { 361 public void setDate (int year, int month, int day) {
357 checkWidget (); 362 checkWidget ();
358 NSCalendarDate date = new NSCalendarDate((cast(NSDatePicker)view).dateValue().id); 363 NSCalendarDate date = getCalendarDate();
359 NSCalendarDate newDate = NSCalendarDate.dateWithYear(year, month + 1, day, 364 NSCalendarDate newDate = NSCalendarDate.dateWithYear(year, month + 1, day,
360 date.hourOfDay(), date.minuteOfHour(), date.secondOfMinute(), date.timeZone()); 365 date.hourOfDay(), date.minuteOfHour(), date.secondOfMinute(), date.timeZone());
361 if (newDate.yearOfCommonEra() is year && newDate.monthOfYear() is month + 1 && newDate.dayOfMonth() is day) { 366 if (newDate.yearOfCommonEra() is year && newDate.monthOfYear() is month + 1 && newDate.dayOfMonth() is day) {
362 (cast(NSDatePicker)view).setDateValue(newDate); 367 (cast(NSDatePicker)view).setDateValue(newDate);
363 } 368 }
376 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 381 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
377 * </ul> 382 * </ul>
378 */ 383 */
379 public void setDay (int day) { 384 public void setDay (int day) {
380 checkWidget (); 385 checkWidget ();
381 NSCalendarDate date = new NSCalendarDate((cast(NSDatePicker)view).dateValue().id); 386 NSCalendarDate date = getCalendarDate();
382 NSCalendarDate newDate = NSCalendarDate.dateWithYear(date.yearOfCommonEra(), date.monthOfYear(), day, 387 NSCalendarDate newDate = NSCalendarDate.dateWithYear(date.yearOfCommonEra(), date.monthOfYear(), day,
383 date.hourOfDay(), date.minuteOfHour(), date.secondOfMinute(), date.timeZone()); 388 date.hourOfDay(), date.minuteOfHour(), date.secondOfMinute(), date.timeZone());
384 if (newDate.yearOfCommonEra() is date.yearOfCommonEra() && newDate.monthOfYear() is date.monthOfYear() && newDate.dayOfMonth() is day) { 389 if (newDate.yearOfCommonEra() is date.yearOfCommonEra() && newDate.monthOfYear() is date.monthOfYear() && newDate.dayOfMonth() is day) {
385 (cast(NSDatePicker)view).setDateValue(newDate); 390 (cast(NSDatePicker)view).setDateValue(newDate);
386 } 391 }
410 * </ul> 415 * </ul>
411 */ 416 */
412 public void setHours (int hours) { 417 public void setHours (int hours) {
413 checkWidget (); 418 checkWidget ();
414 if (hours < 0 || hours > 23) return; 419 if (hours < 0 || hours > 23) return;
415 NSCalendarDate date = new NSCalendarDate((cast(NSDatePicker)view).dateValue().id); 420 NSCalendarDate date = getCalendarDate();
416 NSCalendarDate newDate = NSCalendarDate.dateWithYear(date.yearOfCommonEra(), date.monthOfYear(), date.dayOfMonth(), 421 NSCalendarDate newDate = NSCalendarDate.dateWithYear(date.yearOfCommonEra(), date.monthOfYear(), date.dayOfMonth(),
417 hours, date.minuteOfHour(), date.secondOfMinute(), date.timeZone()); 422 hours, date.minuteOfHour(), date.secondOfMinute(), date.timeZone());
418 (cast(NSDatePicker)view).setDateValue(newDate); 423 (cast(NSDatePicker)view).setDateValue(newDate);
419 } 424 }
420 425
432 * </ul> 437 * </ul>
433 */ 438 */
434 public void setMinutes (int minutes) { 439 public void setMinutes (int minutes) {
435 checkWidget (); 440 checkWidget ();
436 if (minutes < 0 || minutes > 59) return; 441 if (minutes < 0 || minutes > 59) return;
437 NSCalendarDate date = new NSCalendarDate((cast(NSDatePicker)view).dateValue().id); 442 NSCalendarDate date = getCalendarDate();
438 NSCalendarDate newDate = NSCalendarDate.dateWithYear(date.yearOfCommonEra(), date.monthOfYear(), date.dayOfMonth(), 443 NSCalendarDate newDate = NSCalendarDate.dateWithYear(date.yearOfCommonEra(), date.monthOfYear(), date.dayOfMonth(),
439 date.hourOfDay(), minutes, date.secondOfMinute(), date.timeZone()); 444 date.hourOfDay(), minutes, date.secondOfMinute(), date.timeZone());
440 (cast(NSDatePicker)view).setDateValue(newDate); 445 (cast(NSDatePicker)view).setDateValue(newDate);
441 } 446 }
442 447
453 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 458 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
454 * </ul> 459 * </ul>
455 */ 460 */
456 public void setMonth (int month) { 461 public void setMonth (int month) {
457 checkWidget (); 462 checkWidget ();
458 NSCalendarDate date = new NSCalendarDate((cast(NSDatePicker)view).dateValue().id); 463 NSCalendarDate date = getCalendarDate();
459 NSCalendarDate newDate = NSCalendarDate.dateWithYear(date.yearOfCommonEra(), month + 1, date.dayOfMonth(), 464 NSCalendarDate newDate = NSCalendarDate.dateWithYear(date.yearOfCommonEra(), month + 1, date.dayOfMonth(),
460 date.hourOfDay(), date.minuteOfHour(), date.secondOfMinute(), date.timeZone()); 465 date.hourOfDay(), date.minuteOfHour(), date.secondOfMinute(), date.timeZone());
461 if (newDate.yearOfCommonEra() is date.yearOfCommonEra() && newDate.monthOfYear() is month + 1 && newDate.dayOfMonth() is date.dayOfMonth()) { 466 if (newDate.yearOfCommonEra() is date.yearOfCommonEra() && newDate.monthOfYear() is month + 1 && newDate.dayOfMonth() is date.dayOfMonth()) {
462 (cast(NSDatePicker)view).setDateValue(newDate); 467 (cast(NSDatePicker)view).setDateValue(newDate);
463 } 468 }
477 * </ul> 482 * </ul>
478 */ 483 */
479 public void setSeconds (int seconds) { 484 public void setSeconds (int seconds) {
480 checkWidget (); 485 checkWidget ();
481 if (seconds < 0 || seconds > 59) return; 486 if (seconds < 0 || seconds > 59) return;
482 NSCalendarDate date = new NSCalendarDate((cast(NSDatePicker)view).dateValue().id); 487 NSCalendarDate date = getCalendarDate();
483 NSCalendarDate newDate = NSCalendarDate.dateWithYear(date.yearOfCommonEra(), date.monthOfYear(), date.dayOfMonth(), 488 NSCalendarDate newDate = NSCalendarDate.dateWithYear(date.yearOfCommonEra(), date.monthOfYear(), date.dayOfMonth(),
484 date.hourOfDay(), date.minuteOfHour(), seconds, date.timeZone()); 489 date.hourOfDay(), date.minuteOfHour(), seconds, date.timeZone());
485 (cast(NSDatePicker)view).setDateValue(newDate); 490 (cast(NSDatePicker)view).setDateValue(newDate);
486 } 491 }
487 492
500 * @since 3.4 505 * @since 3.4
501 */ 506 */
502 public void setTime (int hours, int minutes, int seconds) { 507 public void setTime (int hours, int minutes, int seconds) {
503 checkWidget (); 508 checkWidget ();
504 if (hours < 0 || hours > 23 || minutes < 0 || minutes > 59 || seconds < 0 || seconds > 59) return; 509 if (hours < 0 || hours > 23 || minutes < 0 || minutes > 59 || seconds < 0 || seconds > 59) return;
505 NSCalendarDate date = new NSCalendarDate((cast(NSDatePicker)view).dateValue().id); 510 NSCalendarDate date = getCalendarDate();
506 NSCalendarDate newDate = NSCalendarDate.dateWithYear(date.yearOfCommonEra(), date.monthOfYear(), date.dayOfMonth(), 511 NSCalendarDate newDate = NSCalendarDate.dateWithYear(date.yearOfCommonEra(), date.monthOfYear(), date.dayOfMonth(),
507 hours, minutes, seconds, date.timeZone()); 512 hours, minutes, seconds, date.timeZone());
508 (cast(NSDatePicker)view).setDateValue(newDate); 513 (cast(NSDatePicker)view).setDateValue(newDate);
509 } 514 }
510 515
521 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li> 526 * <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
522 * </ul> 527 * </ul>
523 */ 528 */
524 public void setYear (int year) { 529 public void setYear (int year) {
525 checkWidget (); 530 checkWidget ();
526 NSCalendarDate date = new NSCalendarDate((cast(NSDatePicker)view).dateValue().id); 531 NSCalendarDate date = getCalendarDate();
527 NSCalendarDate newDate = NSCalendarDate.dateWithYear(year, date.monthOfYear(), date.dayOfMonth(), 532 NSCalendarDate newDate = NSCalendarDate.dateWithYear(year, date.monthOfYear(), date.dayOfMonth(),
528 date.hourOfDay(), date.minuteOfHour(), date.secondOfMinute(), date.timeZone()); 533 date.hourOfDay(), date.minuteOfHour(), date.secondOfMinute(), date.timeZone());
529 if (newDate.yearOfCommonEra() is year && newDate.monthOfYear() is date.monthOfYear() && newDate.dayOfMonth() is date.dayOfMonth()) { 534 if (newDate.yearOfCommonEra() is year && newDate.monthOfYear() is date.monthOfYear() && newDate.dayOfMonth() is date.dayOfMonth()) {
530 (cast(NSDatePicker)view).setDateValue(newDate); 535 (cast(NSDatePicker)view).setDateValue(newDate);
531 } 536 }