# HG changeset patch # User Jacob Carlborg # Date 1230068998 -3600 # Node ID cda53a4e462f9c66c79b2cf61b3f14ac42565aaf # Parent a3f5118c8b377c19a5fcc9ad433ef3ef066c34cb Ported dwt.widgets.DateTime diff -r a3f5118c8b37 -r cda53a4e462f dwt/internal/cocoa/OS.d --- a/dwt/internal/cocoa/OS.d Tue Dec 23 22:38:33 2008 +0100 +++ b/dwt/internal/cocoa/OS.d Tue Dec 23 22:49:58 2008 +0100 @@ -51,6 +51,7 @@ import dwt.internal.cocoa.NSBitmapImageRep; import dwt.internal.cocoa.NSButtonCell; import dwt.internal.cocoa.NSCell; +import dwt.internal.cocoa.NSDatePicker; import dwt.internal.cocoa.NSEvent; import dwt.internal.cocoa.NSGradient; import dwt.internal.cocoa.NSGraphicsContext; @@ -3042,8 +3043,8 @@ public static const int NSHighlightModeMatrix = 1; public static const int NSHomeFunctionKey = 63273; public static const int NSHorizontalRuler = 0; -public static const int NSHourMinuteDatePickerElementFlag = 12; -public static const int NSHourMinuteSecondDatePickerElementFlag = 14; +alias NSDatePickerElementFlags.NSHourMinuteDatePickerElementFlag NSHourMinuteDatePickerElementFlag; +alias NSDatePickerElementFlags.NSHourMinuteSecondDatePickerElementFlag NSHourMinuteSecondDatePickerElementFlag; public static const int NSIdentityMappingCharacterCollection = 0; public static const int NSIllegalTextMovement = 0; public static const int NSImageAbove = 5; @@ -3488,7 +3489,7 @@ public static const int NSTextBlockTopAlignment = 0; public static const int NSTextBlockWidth = 0; public static const int NSTextCellType = 1; -public static const int NSTextFieldAndStepperDatePickerStyle = 0; +alias NSDatePickerStyle.NSTextFieldAndStepperDatePickerStyle NSTextFieldAndStepperDatePickerStyle; public static const int NSTextFieldDatePickerStyle = 2; public static const int NSTextFieldRoundedBezel = 1; public static const int NSTextFieldSquareBezel = 0; @@ -3618,8 +3619,8 @@ public static const int NSWritingDirectionLeftToRight = 0; public static const int NSWritingDirectionNatural = -1; public static const int NSWritingDirectionRightToLeft = 1; -public static const int NSYearMonthDatePickerElementFlag = 192; -public static const int NSYearMonthDayDatePickerElementFlag = 224; +alias NSDatePickerElementFlags.NSYearMonthDatePickerElementFlag NSYearMonthDatePickerElementFlag; +alias NSDatePickerElementFlags.NSYearMonthDayDatePickerElementFlag NSYearMonthDayDatePickerElementFlag; public static const int kCFStringEncodingUTF8 = 134217984; public static const int NSASCIIStringEncoding = 1; public static const int NSAdminApplicationDirectory = 4; diff -r a3f5118c8b37 -r cda53a4e462f dwt/widgets/DateTime.d --- a/dwt/widgets/DateTime.d Tue Dec 23 22:38:33 2008 +0100 +++ b/dwt/widgets/DateTime.d Tue Dec 23 22:49:58 2008 +0100 @@ -7,6 +7,9 @@ * * Contributors: * IBM Corporation - initial API and implementation + * + * Port to the D programming language: + * Jacob Carlborg *******************************************************************************/ module dwt.widgets.DateTime; @@ -26,6 +29,12 @@ import dwt.internal.cocoa.OS; import dwt.internal.cocoa.SWTDatePicker; +import tango.text.convert.Format; + +import dwt.internal.c.Carbon; +import dwt.widgets.Composite; +import dwt.widgets.TypedListener; + /** * Instances of this class are selectable user interface * objects that allow the user to enter and modify date @@ -158,10 +167,10 @@ } void createHandle () { - NSDatePicker widget = cast(NSDatePicker)new SWTDatePicker().alloc(); + NSDatePicker widget = cast(NSDatePicker)(new SWTDatePicker()).alloc(); widget.initWithFrame(NSRect()); - int pickerStyle = OS.NSTextFieldAndStepperDatePickerStyle; - int elementFlags = 0; + NSDatePickerStyle pickerStyle = OS.NSTextFieldAndStepperDatePickerStyle; + NSDatePickerElementFlags elementFlags; if ((style & DWT.CALENDAR) !is 0) { pickerStyle = OS.NSClockAndCalendarDatePickerStyle; elementFlags = OS.NSYearMonthDayDatePickerElementFlag; @@ -184,7 +193,7 @@ } NSCalendarDate getCalendarDate () { - NSDate date = ((NSDatePicker)view).dateValue(); + NSDate date = (cast(NSDatePicker)view).dateValue(); return date.dateWithCalendarFormat(null, null); } @@ -239,7 +248,7 @@ */ public int getMinutes () { checkWidget (); - return csat(int)/*64*/getCalendarDate().minuteOfHour(); + return cast(int)/*64*/getCalendarDate().minuteOfHour(); } /** @@ -257,12 +266,12 @@ */ public int getMonth () { checkWidget (); - return csat(int)/*64*/getCalendarDate().monthOfYear() - 1; + return cast(int)/*64*/getCalendarDate().monthOfYear() - 1; } String getNameText() { - return (style & DWT.TIME) !is 0 ? getHours() + ":" + getMinutes() + ":" + getSeconds() - : (getMonth() + 1) + "/" + getDay() + "/" + getYear(); + return (style & DWT.TIME) !is 0 ? Format("{}{}{}{}{}", getHours() , ":" + getMinutes() , ":" , getSeconds()) + : Format("{}{}{}{}{}", (getMonth() + 1) + "/" + getDay() + "/" + getYear()); } /** @@ -330,7 +339,7 @@ postEvent (DWT.Selection); } -void setBackground (float [] color) { +void setBackground (CGFloat [] color) { NSColor nsColor; if (color is null) { return; // TODO reset to OS default @@ -391,7 +400,7 @@ } } -void setForeground (float [] color) { +void setForeground (CGFloat [] color) { NSColor nsColor; if (color is null) { return; // TODO reset to OS default