Oh..Sorry. I attach the patch which is improvement from previous patch. This patch is include previous fixes and - When DropDownStyle is Simple, it doesn't show scrollbar. - it doesn't highlight when mouse over a last item.
review it please. -- Kazuki Oikawa
Index: ComboBox.cs
===================================================================
--- ComboBox.cs (revision 50212)
+++ ComboBox.cs (working copy)
@@ -1473,6 +1473,7 @@
int width, height;
int item_height = owner.ItemHeight;
bool show_scrollbar = false;
+ bool need_scrollbar = false;
if (owner.DropDownStyle ==
ComboBoxStyle.Simple) {
width =
owner.CBoxInfo.listbox_area.Width;
@@ -1488,6 +1489,17 @@
height -= remaining;
}
}
+
+ int height2 = 0;
+ if (owner.DrawMode ==
DrawMode.OwnerDrawVariable) {
+ for (int i = 0; i <
owner.Items.Count; i++) {
+ height2 +=
owner.GetItemHeight (i);
+ if (height2 > height)
break;
+ }
+ } else {
+ height2 = (item_height - 2) *
owner.Items.Count;
+ }
+ need_scrollbar = height < height2;
}
else { // DropDown or DropDownList
@@ -1507,9 +1519,10 @@
height +=
ThemeEngine.Current.DrawComboListBoxDecorationBottom (owner.DropDownStyle);
height +=
ThemeEngine.Current.DrawComboListBoxDecorationTop (owner.DropDownStyle);
+ need_scrollbar = owner.Items.Count >
owner.MaxDropDownItems;
}
- if (owner.Items.Count <=
owner.MaxDropDownItems) {
+ if (!need_scrollbar) {
/* Does not need vertical scrollbar*/
if (vscrollbar_ctrl != null) {
@@ -1534,8 +1547,7 @@
vscrollbar_ctrl.Location = new Point
(width - vscrollbar_ctrl.Width -
ThemeEngine.Current.DrawComboListBoxDecorationRight (owner.DropDownStyle),
ThemeEngine.Current.DrawComboListBoxDecorationTop (owner.DropDownStyle));
-
- vscrollbar_ctrl.Maximum =
owner.Items.Count - owner.MaxDropDownItems;
+
show_scrollbar =
vscrollbar_ctrl.Visible = true;
}
@@ -1557,7 +1569,11 @@
textarea_drawable.Width -=
vscrollbar_ctrl.Width;
last_item = LastVisibleItem ();
- page_size = textarea_drawable.Height /
(item_height - 2);
+ page_size = textarea_drawable.Height /
(item_height - 2);
+
+ if (need_scrollbar && show_scrollbar) {
+ vscrollbar_ctrl.Maximum =
owner.Items.Count - (owner.DropDownStyle == ComboBoxStyle.Simple ? page_size :
owner.maxdrop_items);
+ }
}
private void Draw (Rectangle clip, Graphics dc)
@@ -1776,7 +1792,7 @@
/* Previous item */
if (GetHighLightedIndex () != -1) {
invalidate = GetItemDisplayRectangle
(GetHighLightedIndex (), top_item);
- if (ClientRectangle.Contains
(invalidate))
+ if (ClientRectangle.IntersectsWith
(invalidate))
Invalidate (invalidate);
}
@@ -1785,7 +1801,7 @@
if (highlighted_item != null) {
/* Current item */
invalidate = GetItemDisplayRectangle
(GetHighLightedIndex (), top_item);
- if (ClientRectangle.Contains
(invalidate))
+ if (ClientRectangle.IntersectsWith
(invalidate))
Invalidate (invalidate);
}
@@ -1793,9 +1809,16 @@
public void SetTopItem (int item)
{
- top_item = item;
- UpdateLastVisibleItem ();
- Refresh ();
+ if (vscrollbar_ctrl != null) {
+ if (vscrollbar_ctrl.Maximum < item)
+ vscrollbar_ctrl.Value =
vscrollbar_ctrl.Maximum;
+ else
+ vscrollbar_ctrl.Value = item;
+ } else {
+ top_item = item;
+ UpdateLastVisibleItem ();
+ Refresh ();
+ }
}
private void OnMouseDownPUW (object sender,
MouseEventArgs e)
@@ -1848,9 +1871,6 @@
return;
}
- if (owner.DropDownStyle == ComboBoxStyle.Simple)
- return;
-
/* Reroute event to scrollbar */
if (vscrollbar_ctrl != null &&
vscrollbar_ctrl.Visible == true) {
Rectangle scrollbar_screenrect;
@@ -1906,8 +1926,16 @@
if (owner.DropDownStyle != ComboBoxStyle.Simple
&& owner.Items.Count == 0)
return false;
- SetTopItem (0);
- SetHighLightedItem (owner.SelectedItem);
+ if (owner.SelectedIndex >= 0) {
+ if (owner.SelectedIndex <=
owner.Items.Count - owner.MaxDropDownItems) {
+ SetTopItem
(owner.SelectedIndex);
+ } else if (owner.Items.Count >
owner.MaxDropDownItems) {
+ SetTopItem (owner.Items.Count -
owner.MaxDropDownItems);
+ } else {
+ SetTopItem (0);
+ }
+ SetHighLightedItem (owner.SelectedItem);
+ }
CalcListBoxArea ();
Show ();
_______________________________________________ Mono-winforms-list maillist - [email protected] http://lists.ximian.com/mailman/listinfo/mono-winforms-list
