2008-02-20 Ivan N. Zlatev <contact@i-nz.net>
[mono.git] / mcs / class / Managed.Windows.Forms / System.Windows.Forms / PropertyGridView.cs
index e8c7e979ad26895e9bbe1a14bde55579362353f3..0b14141eaaf71821a56457a541f3813ff64e3b4a 100644 (file)
@@ -52,13 +52,13 @@ namespace System.Windows.Forms.PropertyGridInternal {
                private PropertyGridTextBox grid_textbox;
                private PropertyGrid property_grid;
                private bool resizing_grid;
-               private int skipped_grid_items;
                private PropertyGridDropDown dropdown_form;
                private Form dialog_form;
                private ImplicitVScrollBar vbar;
                private StringFormat string_format;
                private Font bold_font;
                private Brush inactive_text_brush;
+               private ListBox dropdown_list;
                #endregion
 
                #region Contructors
@@ -83,7 +83,6 @@ namespace System.Windows.Forms.PropertyGridInternal {
                        dialog_form.FormBorderStyle = FormBorderStyle.None;
                        dialog_form.ShowInTaskbar = false;
 
-                       skipped_grid_items = 0;
                        row_height = Font.Height + font_height_padding;
 
                        grid_textbox.Visible = false;
@@ -562,19 +561,20 @@ namespace System.Windows.Forms.PropertyGridInternal {
                                vbar.Value = 0;
                                vbar.Visible = false;
                        }
+                       UpdateGridTextBoxBounds ((GridEntry)property_grid.SelectedGridItem);
                }
 
-               private bool GetScrollBarVisible ()
-               {
-                       if (property_grid.RootGridItem == null)
-                               return false;
-
-                       int visibleRows = GetVisibleRowsCount ();
-                       int openedItems = GetVisibleItemsCount ((GridEntry)property_grid.RootGridItem);
-                       if (openedItems > visibleRows)
-                               return true;
-                       return false;
-               }
+               // private bool GetScrollBarVisible ()
+               // {
+               //      if (property_grid.RootGridItem == null)
+               //              return false;
+                // 
+               //      int visibleRows = GetVisibleRowsCount ();
+               //      int openedItems = GetVisibleItemsCount ((GridEntry)property_grid.RootGridItem);
+               //      if (openedItems > visibleRows)
+               //              return true;
+               //      return false;
+               // }
                #region Drawing Code
 
                private void DrawGridItems (GridItemCollection grid_items, PaintEventArgs pevent, int depth, ref int yLoc) {
@@ -735,6 +735,7 @@ namespace System.Windows.Forms.PropertyGridInternal {
                {
                        GridEntry entry = this.property_grid.SelectedGridItem as GridEntry;
                        if (entry != null) {
+                               grid_textbox.Text = (string) ((ListBox) sender).SelectedItem;
                                if (TrySetEntry (entry, (string) ((ListBox) sender).SelectedItem))
                                        UnfocusSelection ();
                        }
@@ -756,23 +757,25 @@ namespace System.Windows.Forms.PropertyGridInternal {
                                else {
                                        ICollection std_values = entry.AcceptedValues;
                                        if (std_values != null) {
-                                               ListBox listBox = new ListBox ();
-                                               listBox.BorderStyle = BorderStyle.FixedSingle;
+                                               if (dropdown_list == null)
+                                                       dropdown_list = new ListBox ();
+                                               dropdown_list.Items.Clear ();
+                                               dropdown_list.BorderStyle = BorderStyle.FixedSingle;
                                                int selected_index = 0;
                                                int i = 0;
                                                foreach (object obj in std_values) {
-                                                       listBox.Items.Add (obj);
+                                                       dropdown_list.Items.Add (obj);
                                                        if (entry.ValueText != null && entry.ValueText.Equals (obj))
                                                                selected_index = i;
                                                        i++;
                                                }
-                                               listBox.Height = row_height * Math.Min (listBox.Items.Count, 15);
-                                               listBox.Width = ClientRectangle.Width - SplitterLocation - (vbar.Visible ? vbar.Width : 0);
-                                               listBox.KeyDown += new KeyEventHandler (listBox_KeyDown);
-                                               listBox.MouseUp+=new MouseEventHandler (listBox_MouseUp);
+                                               dropdown_list.Height = row_height * Math.Min (dropdown_list.Items.Count, 15);
+                                               dropdown_list.Width = ClientRectangle.Width - SplitterLocation - (vbar.Visible ? vbar.Width : 0);
+                                               dropdown_list.KeyDown += new KeyEventHandler (listBox_KeyDown);
+                                               dropdown_list.MouseUp+=new MouseEventHandler (listBox_MouseUp);
                                                if (std_values.Count > 0)
-                                                       listBox.SelectedIndex = selected_index;
-                                               DropDownControl (listBox);
+                                                       dropdown_list.SelectedIndex = selected_index;
+                                               DropDownControl (dropdown_list);
                                        }
                                }
                        }
@@ -787,17 +790,6 @@ namespace System.Windows.Forms.PropertyGridInternal {
 
                private void VScrollBar_HandleValueChanged (object sender, EventArgs e) 
                {
-                       if (vbar.Value <= 0)
-                               vbar.Value = 0;
-                       if (vbar.Value > vbar.Maximum-ClientRectangle.Height/row_height)
-                               vbar.Value = vbar.Maximum-ClientRectangle.Height/row_height+1;
-
-                       int scroll_amount = (skipped_grid_items-vbar.Value)*row_height;
-
-                       if (scroll_amount == 0)
-                               return;
-
-                       skipped_grid_items = vbar.Value;
                        UpdateView ();
                }
 
@@ -841,13 +833,7 @@ namespace System.Windows.Forms.PropertyGridInternal {
                                        grid_textbox.ForeColor = SystemColors.ControlText;
                                        grid_textbox.ReadOnly = !entry.IsEditable;
                                }
-
-                               int y = -vbar.Value*row_height;
-                               CalculateItemY (entry, property_grid.RootGridItem.GridItems, ref y);
-                               int x = SplitterLocation + ENTRY_SPACING + (entry.PaintValueSupported ? VALUE_PAINT_INDENT : 0);
-                               grid_textbox.SetBounds (x + ENTRY_SPACING, y + ENTRY_SPACING,
-                                                       ClientRectangle.Width - ENTRY_SPACING - x - (vbar.Visible ? vbar.Width : 0),
-                                                       row_height - ENTRY_SPACING);
+                               UpdateGridTextBoxBounds (entry);
                                grid_textbox.Text = entry.IsMerged && !entry.HasMergedValue ? String.Empty : entry.ValueText;
                                grid_textbox.Visible = true;
                                InvalidateItem (entry);
@@ -857,6 +843,18 @@ namespace System.Windows.Forms.PropertyGridInternal {
                        }
                }
 
+               private void UpdateGridTextBoxBounds (GridEntry entry)
+               {
+                       if (entry == null)
+                               return;
+                       int y = -vbar.Value*row_height;
+                       CalculateItemY (entry, property_grid.RootGridItem.GridItems, ref y);
+                       int x = SplitterLocation + ENTRY_SPACING + (entry.PaintValueSupported ? VALUE_PAINT_INDENT : 0);
+                       grid_textbox.SetBounds (x + ENTRY_SPACING, y + ENTRY_SPACING,
+                                               ClientRectangle.Width - ENTRY_SPACING - x - (vbar.Visible ? vbar.Width : 0),
+                                               row_height - ENTRY_SPACING);
+               }
+
                // Calculates the sum of the heights of all items before the one
                //
                private bool CalculateItemY (GridEntry entry, GridItemCollection items, ref int y)
@@ -909,11 +907,13 @@ namespace System.Windows.Forms.PropertyGridInternal {
 
                internal void ExpandItem (GridEntry item)
                {
+                       UpdateItem ((GridEntry)property_grid.SelectedGridItem);
                        Invalidate (new Rectangle (0, item.Top, Width, Height - item.Top));
                }
 
                internal void CollapseItem (GridEntry item)
                {
+                       UpdateItem ((GridEntry)property_grid.SelectedGridItem);
                        Invalidate (new Rectangle (0, item.Top, Width, Height - item.Top));
                }