MonthCalendar.cs, DateTimePicker.cs: Made monthcalendar dropdown
authorJohn BouAntoun <jba@mono-cvs.ximian.com>
Fri, 29 Apr 2005 07:31:47 +0000 (07:31 -0000)
committerJohn BouAntoun <jba@mono-cvs.ximian.com>
Fri, 29 Apr 2005 07:31:47 +0000 (07:31 -0000)
behave like combobox and comboboxlist (still not sure if this is
correct though).

svn path=/trunk/mcs/; revision=43773

mcs/class/Managed.Windows.Forms/System.Windows.Forms/ChangeLog
mcs/class/Managed.Windows.Forms/System.Windows.Forms/DateTimePicker.cs
mcs/class/Managed.Windows.Forms/System.Windows.Forms/MonthCalendar.cs

index 932cd49f88bf972bc9585f8ab2db8199893f060f..efdc3604feef504ad1aeb3bb19dbc3368c604f44 100644 (file)
@@ -1,3 +1,9 @@
+2005-04-29  John BouAntoun  <jba-mono@optusnet.com.au>
+
+       * MonthCalendar.cs, DateTimePicker.cs: Made monthcalendar dropdwon
+       behave like combobox and comboboxlist (still not sure if this is
+       correct though).
+
 2005-04-28  Jackson Harper  <jackson@ximian.com>
 
        * ThemeWin32Classic.cs: Don't fill the middle of progress
index fd696341029ef94c9cf44184746308d5bd2e3fdf..b15885e30966e6550e501fa5e49da47314da0949 100755 (executable)
@@ -45,7 +45,6 @@ namespace System.Windows.Forms {
                #region Public variables
                
                // this class has to have the specified hour, minute and second, as it says in msdn
-               //public static readonly DateTime MaxDateTime = DateTime.Parse ("31 December 9998");//, 23:59:59");
                public static readonly DateTime MaxDateTime = new DateTime (9998, 12, 31, 23, 59, 59);
                public static readonly DateTime MinDateTime = new DateTime (1753, 1, 1);
                
@@ -110,10 +109,11 @@ namespace System.Windows.Forms {
                        
                        month_calendar.DateSelected += new DateRangeEventHandler (MonthCalendarDateSelectedHandler);
                        KeyPress += new KeyPressEventHandler (KeyPressHandler);
-                       LostFocus += new EventHandler (LostFocusHandler);
+//                     LostFocus += new EventHandler (LostFocusHandler);
                        MouseDown += new MouseEventHandler (MouseDownHandler);                  
                        Paint += new PaintEventHandler (PaintHandler);
                        
+                       SetStyle (ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint, true);
                }
                
                #endregion
@@ -224,8 +224,7 @@ namespace System.Windows.Forms {
                                if (custom_format != value) {
                                        custom_format = value;
                                        if (this.Format == DateTimePickerFormat.Custom) {
-                                               // invalidate the value inside this control
-                                               this.Invalidate (date_area_rect);
+                                               // TODO: change the text value of the dtp                                               
                                        }
                                }
                        }
@@ -240,7 +239,7 @@ namespace System.Windows.Forms {
                public LeftRightAlignment DropDownAlign {
                        set {
                                if (drop_down_align != value) {
-                                       drop_down_align = value;                                        
+                                       drop_down_align = value;
                                }
                        }
                        get {
@@ -367,10 +366,12 @@ namespace System.Windows.Forms {
                [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
                public string Text {
                        set {
+                               // TODO: if the format is a custom format we need to do a custom parse here
                                DateTime parsed_value = DateTime.Parse (value);
                                if (date_value != parsed_value) {
                                        Value = parsed_value;
-                               } 
+                               }
+                               text = FormatValue (); 
                        }
                        get {
                                return text;
@@ -591,7 +592,7 @@ namespace System.Windows.Forms {
                                location.X = parent_control_rect.Right - child_size.Width;                              
                        }
                        
-                       Point screen_location = PointToScreen (location);
+                       Point screen_location = PointToScreen (location);                       
 // TODO: enable this part when screen comes into the classes
 /*                     
                        Rectangle working_area = Screen.FromControl(this).WorkingArea;
@@ -629,9 +630,9 @@ namespace System.Windows.Forms {
                                align_area,
                                month_calendar.Size,
                                (this.DropDownAlign == LeftRightAlignment.Left));
-                       
                        month_calendar.Show ();
                        month_calendar.Focus ();
+                       month_calendar.Capture = true;  
                        
                        // fire any registered events
                        if (this.DropDown != null) {
@@ -644,6 +645,7 @@ namespace System.Windows.Forms {
                {
                        this.is_drop_down_visible = false;
                Invalidate (drop_down_arrow_rect);
+               month_calendar.Capture = false;
                if (month_calendar.Visible) {
                        month_calendar.Hide ();
                }
@@ -658,21 +660,20 @@ namespace System.Windows.Forms {
                        e.Handled = true;
                }
                
-               // if we lose focus and the drop down is up, then close it
-               private void LostFocusHandler (object sender, EventArgs e) 
-               {
-                       if (is_drop_down_visible && !month_calendar.Focused) {
-                               this.HideMonthCalendar ();                              
-                       }                       
-               }
+//             // if we lose focus and the drop down is up, then close it
+//             private void LostFocusHandler (object sender, EventArgs e) 
+//             {
+//                     if (is_drop_down_visible && !month_calendar.Focused) {
+//                             this.HideMonthCalendar ();                              
+//                     }                       
+//             }
                
                // fired when a user clicks on the month calendar to select a date
                private void MonthCalendarDateSelectedHandler (object sender, DateRangeEventArgs e)
                {
                        this.Value = e.Start.Date.Add (this.Value.TimeOfDay);
                        this.HideMonthCalendar ();      
-                       this.Focus ();          
-                       System.Console.WriteLine("MonthCalendarDateSelectedHandler");
+                       this.Focus ();                  
                } 
 
                // to check if the mouse has come down on this control
@@ -688,8 +689,7 @@ namespace System.Windows.Forms {
                                        DropDownMonthCalendar ();
                        } else {
                                // mouse down on this control anywhere else collapses it
-                               if (is_drop_down_visible) {
-                               System.Console.WriteLine("hiding cause of mouse down");
+                               if (is_drop_down_visible) {                             
                                        HideMonthCalendar ();
                                }
                        } 
@@ -716,7 +716,7 @@ namespace System.Windows.Forms {
                                        ret_value = date_value.ToShortDateString ();
                                        break;
                                case DateTimePickerFormat.Time:
-                                       ret_value = date_value.ToShortDateString ();
+                                       ret_value = date_value.ToLongTimeString ();
                                        break;
                                default:
                                        ret_value = date_value.ToLongDateString ();
index 8b81925cc1fb980ad0ed280e37ac18b2a179849f..26dc7f4f1de672491e12d83a1df7a6da54ab1e87 100644 (file)
@@ -25,7 +25,6 @@
 // REMAINING TODO:
 //     - get the date_cell_size and title_size to be pixel perfect match of SWF
 //     - show the year spin control
-//     - remove comments around the "if (this.Capture) {" in the TimerHandler method
 
 using System;
 using System.Collections;
@@ -165,7 +164,7 @@ namespace System.Windows.Forms {
                        SetUpContextMenu ();
 
                        // event handlers
-                       LostFocus += new EventHandler (LostFocusHandler);
+//                     LostFocus += new EventHandler (LostFocusHandler);
                        timer.Tick += new EventHandler (TimerHandler);
                        MouseMove += new MouseEventHandler (MouseMoveHandler);
                        MouseDown += new MouseEventHandler (MouseDownHandler);
@@ -1400,9 +1399,7 @@ namespace System.Windows.Forms {
                
                // raised on the timer, for mouse hold clicks
                private void TimerHandler (object sender, EventArgs e) {
-// NOTE: i have diabled the if this.Capture because it doesn't work
-// when this.Capture works then need to renable the if in this section
-//                     // now find out which area was click
+                       // now find out which area was click
                        if (this.Capture) {
                                HitTestInfo hti = this.HitTest (this.PointToClient (MousePosition));
                                // see if it was clicked on the prev or next mouse 
@@ -1487,15 +1484,15 @@ namespace System.Windows.Forms {
                        this.is_date_clicked = false;
                }
                
-               // need when in windowed mode
-               private void LostFocusHandler (object sender, EventArgs e) 
-               {
-                       if (this.owner != null) {
-                               if (this.Visible) {
-                                       this.owner.HideMonthCalendar ();
-                               }
-                       }
-               }
+//             // need when in windowed mode
+//             private void LostFocusHandler (object sender, EventArgs e) 
+//             {
+//                     if (this.owner != null) {
+//                             if (this.Visible) {
+//                                     this.owner.HideMonthCalendar ();
+//                             }
+//                     }
+//             }
                
                // occurs when mouse moves around control, used for selection
                private void MouseMoveHandler (object sender, MouseEventArgs e) {
@@ -1533,8 +1530,18 @@ namespace System.Windows.Forms {
                                timer.Stop ();
                                timer.Enabled = false;
                        }
+                       
+                       Point point = new Point (e.X, e.Y);
+                       // figure out if we are in drop down mode and a click happened outside us
+                       if (this.owner != null) {
+                               if (!this.ClientRectangle.Contains (point)) {
+                                       this.owner.HideMonthCalendar ();
+                                       return;                                 
+                               }
+                       }
+                       
                        //establish where was hit
-                       HitTestInfo hti = this.HitTest(e.X, e.Y);
+                       HitTestInfo hti = this.HitTest(point);
                        switch (hti.HitArea) {\r
                                case HitArea.PrevMonthButton:
                                case HitArea.NextMonthButton:
@@ -1572,7 +1579,7 @@ namespace System.Windows.Forms {
                                default:
                                        this.is_previous_clicked = false;
                                        this.is_next_clicked = false;
-                                       this.is_date_clicked = false;
+                                       this.is_date_clicked = false;                           
                                        break;
                        }
                }