// System.ComponentModel.Design.DateTimeEditor
//
// Authors:
-// Gert Driesen (drieseng@users.sourceforge.net)
+// Andreas Nahr (ClassDevelopment@A-SoftTech.com)
+// Gert Driesen (drieseng@users.sourceforge.net)
//
// (C) 2004 Novell
+// (C) 2007 Andreas Nahr
//
//
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
-using System.Windows.Forms;
+
+using System;
+using System.ComponentModel;
using System.Drawing.Design;
+using System.Windows.Forms;
+using System.Windows.Forms.Design;
namespace System.ComponentModel.Design
{
public class DateTimeEditor : UITypeEditor
{
+ private class EditorControl : MonthCalendar
+ {
+ public EditorControl ()
+ {
+ MaxSelectionCount = 1;
+ }
+ }
+
+ private IWindowsFormsEditorService editorService;
+ private EditorControl control = new EditorControl ();
+ private DateTime editContent;
+
public DateTimeEditor ()
{
+ control.DateSelected += new DateRangeEventHandler (control_DateSelected);
}
- [MonoTODO]
public override object EditValue (ITypeDescriptorContext context, IServiceProvider provider, object value)
{
- throw new NotImplementedException ();
+ if (context != null && provider != null)
+ {
+ editorService = (IWindowsFormsEditorService)provider.GetService (typeof (IWindowsFormsEditorService));
+ if (editorService != null)
+ {
+ if (!(value is DateTime))
+ return value;
+
+ editContent = (DateTime)value;
+ if (editContent > control.MaxDate || editContent < control.MinDate)
+ control.SelectionStart = DateTime.Today;
+ else
+ control.SelectionStart = editContent;
+
+ editorService.DropDownControl (control);
+
+ return editContent;
+ }
+ }
+ return base.EditValue (context, provider, value);
+ }
+
+ void control_DateSelected (object sender, DateRangeEventArgs e)
+ {
+ editContent = e.Start;
+ editorService.CloseDropDown ();
}
public override UITypeEditorEditStyle GetEditStyle (ITypeDescriptorContext context)