MouseUp += new MouseEventHandler (OnMouseUpCB);
MouseMove += new MouseEventHandler (OnMouseMoveCB);
MouseWheel += new MouseEventHandler (OnMouseWheelCB);
+ MouseEnter += new EventHandler (OnMouseEnter);
MouseLeave += new EventHandler (OnMouseLeave);
KeyDown +=new KeyEventHandler(OnKeyDownCB);
}
if(auto_complete_custom_source != null)
auto_complete_custom_source.CollectionChanged += new CollectionChangeEventHandler (OnAutoCompleteCustomSourceChanged);
+
+ SetTextBoxAutoCompleteData ();
}
}
throw new InvalidEnumArgumentException (Locale.GetText ("Enum argument value '{0}' is not valid for AutoCompleteMode", value));
auto_complete_mode = value;
+ SetTextBoxAutoCompleteData ();
}
}
throw new InvalidEnumArgumentException (Locale.GetText ("Enum argument value '{0}' is not valid for AutoCompleteSource", value));
auto_complete_source = value;
+ SetTextBoxAutoCompleteData ();
+ }
+ }
+
+ void SetTextBoxAutoCompleteData ()
+ {
+ if (textbox_ctrl == null)
+ return;
+
+ textbox_ctrl.AutoCompleteMode = auto_complete_mode;
+
+ if (auto_complete_source == AutoCompleteSource.ListItems) {
+ textbox_ctrl.AutoCompleteSource = AutoCompleteSource.CustomSource;
+ textbox_ctrl.AutoCompleteCustomSource = null;
+ textbox_ctrl.AutoCompleteInternalSource = this;
+ } else {
+ textbox_ctrl.AutoCompleteSource = auto_complete_source;
+ textbox_ctrl.AutoCompleteCustomSource = auto_complete_custom_source;
+ textbox_ctrl.AutoCompleteInternalSource = null;
}
}
#endif
[DefaultValue ((string)null)]
[AttributeProvider (typeof (IListSource))]
[RefreshProperties (RefreshProperties.Repaint)]
+ [MWFCategory("Data")]
public new object DataSource {
get { return base.DataSource; }
set { base.DataSource = value; }
[RefreshProperties(RefreshProperties.Repaint)]
[DefaultValue (DrawMode.Normal)]
+ [MWFCategory("Behavior")]
public DrawMode DrawMode {
get { return draw_mode; }
set {
[Browsable (true)]
[DefaultValue (106)]
[EditorBrowsable (EditorBrowsableState.Always)]
+ [MWFCategory("Behavior")]
public int DropDownHeight {
get {
return drop_down_height;
[DefaultValue (ComboBoxStyle.DropDown)]
[RefreshProperties(RefreshProperties.Repaint)]
+ [MWFCategory("Appearance")]
public ComboBoxStyle DropDownStyle {
get { return dropdown_style; }
set {
if (IsHandleCreated == true)
Controls.AddImplicit (textbox_ctrl);
+#if NET_2_0
+ SetTextBoxAutoCompleteData ();
+#endif
}
ResumeLayout ();
}
}
+ [MWFCategory("Behavior")]
public int DropDownWidth {
get {
if (dropdown_width == -1)
if (value)
DropDownListBox ();
else
- listbox_ctrl.Hide ();
+ listbox_ctrl.HideWindow ();
}
}
#if NET_2_0
[DefaultValue (FlatStyle.Standard)]
[Localizable (true)]
+ [MWFCategory("Appearance")]
public FlatStyle FlatStyle {
get { return flat_style; }
set {
[DefaultValue (true)]
[Localizable (true)]
+ [MWFCategory("Behavior")]
public bool IntegralHeight {
get { return integral_height; }
set {
}
[Localizable (true)]
+ [MWFCategory("Behavior")]
public int ItemHeight {
get {
if (item_height == -1) {
#if NET_2_0
[MergableProperty (false)]
#endif
+ [MWFCategory("Data")]
public ComboBox.ObjectCollection Items {
get { return items; }
}
[DefaultValue (8)]
[Localizable (true)]
+ [MWFCategory("Behavior")]
public int MaxDropDownItems {
get { return maxdrop_items; }
set {
[DefaultValue (0)]
[Localizable (true)]
+ [MWFCategory("Behavior")]
public int MaxLength {
get { return max_length; }
set {
[DesignerSerializationVisibility (DesignerSerializationVisibility.Hidden)]
[Browsable (false)]
public int PreferredHeight {
- get {
- return ItemHeight + 6;
- }
+ get { return Font.Height + 8; }
}
[Browsable (false)]
if (dropdown_style != ComboBoxStyle.DropDownList) {
if (value == -1)
- SetControlText("");
+ SetControlText (string.Empty, false);
else
- SetControlText (GetItemText (Items [value]));
+ SetControlText (GetItemText (Items [value]), false);
}
if (DropDownStyle == ComboBoxStyle.DropDownList)
object item = selected_index == -1 ? null : Items [selected_index];
if (item == value)
return;
- SelectedIndex = Items.IndexOf (value);
+
+ if (value == null)
+ SelectedIndex = -1;
+ else
+ SelectedIndex = Items.IndexOf (value);
}
}
}
[DefaultValue (false)]
+ [MWFCategory("Behavior")]
public bool Sorted {
get { return sorted; }
set {
if (value == null) {
if (SelectedIndex == -1) {
if (dropdown_style != ComboBoxStyle.DropDownList)
- SetControlText ("");
+ SetControlText (string.Empty, false);
} else {
SelectedIndex = -1;
}
#endregion Public Properties
+ #region Internal Properties
+ internal Rectangle ButtonArea {
+ get { return button_area; }
+ }
+
+ internal Rectangle TextArea {
+ get { return text_area; }
+ }
+ #endregion
+
+ #region UIA Framework Properties
+
+ internal TextBox UIATextBox {
+ get { return textbox_ctrl; }
+ }
+
+ #endregion UIA Framework Properties
+
#region Public Methods
#if NET_2_0
[Obsolete ("This method has been deprecated")]
return;
if (selected_index != -1 && DropDownStyle != ComboBoxStyle.DropDownList)
- SetControlText (GetItemText (Items [selected_index]));
+ SetControlText (GetItemText (Items [selected_index]), true);
if (!IsHandleCreated)
return;
protected virtual void OnDrawItem (DrawItemEventArgs e)
{
+ DrawItemEventHandler eh = (DrawItemEventHandler)(Events [DrawItemEvent]);
+ if (eh != null)
+ eh (this, e);
+ }
+
+ internal void HandleDrawItem (DrawItemEventArgs e)
+ {
+ // Only raise OnDrawItem if we are in an OwnerDraw mode
switch (DrawMode) {
- case DrawMode.OwnerDrawFixed:
- case DrawMode.OwnerDrawVariable:
- DrawItemEventHandler eh = (DrawItemEventHandler)(Events [DrawItemEvent]);
- if (eh != null)
- eh (this, e);
- break;
- default:
- ThemeEngine.Current.DrawComboBoxItem (this, e);
- break;
+ case DrawMode.OwnerDrawFixed:
+ case DrawMode.OwnerDrawVariable:
+ OnDrawItem (e);
+ break;
+ default:
+ ThemeEngine.Current.DrawComboBoxItem (this, e);
+ break;
}
}
if (textbox_ctrl != null)
textbox_ctrl.Font = Font;
- if (!item_height_specified) {
- SizeF sz = TextRenderer.MeasureString ("The quick brown Fox", Font);
- item_height = (int) sz.Height;
- }
+ if (!item_height_specified)
+ item_height = Font.Height + 2;
if (IntegralHeight)
UpdateComboBoxBounds ();
{
base.OnHandleCreated (e);
- SetBounds (Left, Top, Width, PreferredHeight, BoundsSpecified.None);
+ SetBoundsInternal (Left, Top, Width, PreferredHeight, BoundsSpecified.None);
if (textbox_ctrl != null)
Controls.AddImplicit (textbox_ctrl);
for (int i = 0; i < Items.Count; i++) {
RefreshItem (i);
}
+
+ LayoutComboBox ();
+ Refresh ();
+
+ if (selected_index != -1 && DropDownStyle != ComboBoxStyle.DropDownList)
+ SetControlText (GetItemText (Items [selected_index]), false);
}
public override void ResetText ()
case Msg.WM_KEYUP:
case Msg.WM_KEYDOWN:
Keys keys = (Keys) m.WParam.ToInt32 ();
+#if NET_2_0
+ // Don't pass the message to base if auto complete is being used and available.
+ if (textbox_ctrl != null && textbox_ctrl.CanNavigateAutoCompleteList) {
+ XplatUI.SendMessage (textbox_ctrl.Handle, (Msg) m.Msg, m.WParam, m.LParam);
+ return;
+ }
+#endif
if (keys == Keys.Up || keys == Keys.Down)
break;
goto case Msg.WM_CHAR;
is_flat = style == FlatStyle.Flat || style == FlatStyle.Popup;
#endif
- if (!Enabled)
- dc.FillRectangle (theme.ResPool.GetSolidBrush (theme.ColorControl), bounds);
-
- if (DropDownStyle == ComboBoxStyle.Simple)
- dc.FillRectangle (theme.ResPool.GetSolidBrush (Parent.BackColor), ClientRectangle);
-
- if (style == FlatStyle.Popup && (is_entered || Focused)) {
- Rectangle area = text_area;
- area.Height -= 1;
- area.Width -= 1;
- dc.DrawRectangle (theme.ResPool.GetPen (SystemColors.ControlDark), area);
- dc.DrawLine (theme.ResPool.GetPen (SystemColors.ControlDark), button_area.X - 1, button_area.Top, button_area.X - 1, button_area.Bottom);
- }
- if (!is_flat && clip.IntersectsWith (text_area))
- ControlPaint.DrawBorder3D (dc, text_area, Border3DStyle.Sunken);
+ theme.ComboBoxDrawBackground (this, dc, clip, style);
int border = theme.Border3DSize.Width;
}
state |= DrawItemState.ComboBoxEdit;
- OnDrawItem (new DrawItemEventArgs (dc, Font, item_rect, SelectedIndex, state, ForeColor, BackColor));
+ HandleDrawItem (new DrawItemEventArgs (dc, Font, item_rect, SelectedIndex, state, ForeColor, BackColor));
}
if (show_dropdown_button) {
FindMatchOrSetIndex(SelectedIndex);
+#if NET_2_0
+ if (textbox_ctrl != null)
+ textbox_ctrl.HideAutoCompleteList ();
+#endif
+
if (listbox_ctrl.ShowWindow ())
dropped_down = true;
if (DropDownStyle == ComboBoxStyle.Simple)
return;
+ FindMatchOrSetIndex (SelectedIndex);
button_state = ButtonState.Normal;
Invalidate (button_area);
dropped_down = false;
if (SelectedIndex >= listbox_ctrl.LastVisibleItem ())
listbox_ctrl.Scroll (SelectedIndex - listbox_ctrl.LastVisibleItem () + 1);
break;
-
+
+ case Keys.Enter:
case Keys.Escape:
DropDownListBoxFinished ();
break;
Capture = true;
}
+ void OnMouseEnter (object sender, EventArgs e)
+ {
+ if (ThemeEngine.Current.CombBoxBackgroundHasHotElementStyle (this))
+ Invalidate ();
+ }
+
void OnMouseLeave (object sender, EventArgs e)
{
- if (show_dropdown_button)
- DropDownButtonEntered = false;
+ if (ThemeEngine.Current.CombBoxBackgroundHasHotElementStyle (this)) {
+ drop_down_button_entered = false;
+ Invalidate ();
+ } else {
+ if (show_dropdown_button)
+ DropDownButtonEntered = false;
+ }
}
void OnMouseMoveCB (object sender, MouseEventArgs e)
if (process_textchanged_event == false)
return;
- OnTextChanged (EventArgs.Empty);
-
int item = FindStringCaseInsensitive (textbox_ctrl.Text);
- if (item == -1)
+ if (item == -1) {
+ // Setting base.Text below will raise this event
+ // if we found something
+ OnTextChanged (EventArgs.Empty);
return;
-
+ }
+
// TODO: THIS IS BROKEN-ISH
// I don't think we should hilight, and setting the top item does weirdness
// when there is no scrollbar
selected_index = -1;
}
- internal void SetControlText (string s)
+ internal void SetControlText (string s, bool suppressTextChanged)
{
- process_textchanged_event = false;
+ if (suppressTextChanged)
+ process_textchanged_event = false;
+
textbox_ctrl.Text = s;
textbox_ctrl.SelectAll ();
process_textchanged_event = true;
if (DropDownStyle == ComboBoxStyle.Simple && height > PreferredHeight) {
if (IntegralHeight) {
int border = ThemeEngine.Current.Border3DSize.Height;
- int lb_height = height - PreferredHeight - 2;
- if (lb_height - 2 * border > ItemHeight) {
- int partial = (lb_height - 2 * border) % ItemHeight;
+ int lb_height = (height - PreferredHeight - 2) - border * 2;
+ if (lb_height > ItemHeight) {
+ int partial = (lb_height) % ItemHeight;
height -= partial;
- } else
+ } else if (lb_height < ItemHeight)
height = PreferredHeight;
}
} else
private ComboBox owner;
internal ArrayList object_items = new ArrayList ();
+
+ #region UIA Framework Events
+
+#if NET_2_0
+ //NOTE:
+ // We are using Reflection to add/remove internal events.
+ // Class ListProvider uses the events.
+ //
+ //Event used to generate UIA StructureChangedEvent
+ static object UIACollectionChangedEvent = new object ();
+
+ internal event CollectionChangeEventHandler UIACollectionChanged {
+ add { owner.Events.AddHandler (UIACollectionChangedEvent, value); }
+ remove { owner.Events.RemoveHandler (UIACollectionChangedEvent, value); }
+ }
+
+ internal void OnUIACollectionChangedEvent (CollectionChangeEventArgs args)
+ {
+ CollectionChangeEventHandler eh
+ = (CollectionChangeEventHandler) owner.Events [UIACollectionChangedEvent];
+ if (eh != null)
+ eh (owner, args);
+ }
+#endif
+
+ #endregion UIA Framework Events
public ObjectCollection (ComboBox owner)
{
if (value == null)
throw new ArgumentNullException ("value");
+#if NET_2_0
+ //UIA Framework event: Item Removed
+ OnUIACollectionChangedEvent (new CollectionChangeEventArgs (CollectionChangeAction.Remove, object_items [index]));
+#endif
+
object_items[index] = value;
+
+#if NET_2_0
+ //UIA Framework event: Item Added
+ OnUIACollectionChangedEvent (new CollectionChangeEventArgs (CollectionChangeAction.Add, value));
+#endif
+
if (owner.listbox_ctrl != null)
owner.listbox_ctrl.InvalidateItem (index);
if (index == owner.SelectedIndex) {
object_items.Clear ();
owner.UpdatedItems ();
owner.Refresh ();
+
+#if NET_2_0
+ //UIA Framework event: Items list cleared
+ OnUIACollectionChangedEvent (new CollectionChangeEventArgs (CollectionChangeAction.Refresh, null));
+#endif
}
public bool Contains (object value)
if (owner.Sorted)
AddItem (item);
- else
+ else {
object_items.Insert (index, item);
+#if NET_2_0
+ //UIA Framework event: Item added
+ OnUIACollectionChangedEvent (new CollectionChangeEventArgs (CollectionChangeAction.Add, item));
+#endif
+ }
owner.EndUpdate (); // Calls UpdatedItems
}
if (index == owner.SelectedIndex)
owner.SelectedIndex = -1;
+#if NET_2_0
+ object removed = object_items [index];
+#endif
+
+
object_items.RemoveAt (index);
owner.UpdatedItems ();
+
+#if NET_2_0
+ //UIA Framework event: Item removed
+ OnUIACollectionChangedEvent (new CollectionChangeEventArgs (CollectionChangeAction.Remove, removed));
+#endif
}
#endregion Public Methods
if (index <= owner.selected_index && owner.IsHandleCreated)
owner.selected_index++;
+#if NET_2_0
+ //UIA Framework event: Item added
+ OnUIACollectionChangedEvent (new CollectionChangeEventArgs (CollectionChangeAction.Add, item));
+#endif
+
return index;
}
index++;
}
}
object_items.Add (item);
+
+#if NET_2_0
+ //UIA Framework event: Item added
+ OnUIACollectionChangedEvent (new CollectionChangeEventArgs (CollectionChangeAction.Add, item));
+#endif
+
return object_items.Count - 1;
}
internal void Sort ()
{
- object_items.Sort ();
+ // If the objects the user put here don't have their own comparer,
+ // use one that compares based on the object's ToString
+ if (object_items.Count > 0 && object_items[0] is IComparer)
+ object_items.Sort ();
+ else
+ object_items.Sort (new ObjectComparer (owner));
}
+ private class ObjectComparer : IComparer
+ {
+ private ListControl owner;
+
+ public ObjectComparer (ListControl owner)
+ {
+ this.owner = owner;
+ }
+
+ #region IComparer Members
+ public int Compare (object x, object y)
+ {
+ return string.Compare (owner.GetItemText (x), owner.GetItemText (y));
+ }
+ #endregion
+ }
#endregion Private Methods
}
state |= DrawItemState.Focus;
}
}
-
- owner.OnDrawItem (new DrawItemEventArgs (dc, owner.Font, item_rect,
+
+ owner.HandleDrawItem (new DrawItemEventArgs (dc, owner.Font, item_rect,
i, state, owner.ForeColor, owner.BackColor));
}
}
return;
}
+ bool is_change = owner.SelectedIndex != index;
+
owner.SelectedIndex = index;
owner.OnSelectionChangeCommitted (new EventArgs ());
+
+ // If the user selected the already selected item, SelectedIndex
+ // won't fire these events, but .Net does, so we do it here
+ if (!is_change) {
+ owner.OnSelectedValueChanged (EventArgs.Empty);
+ owner.OnSelectedIndexChanged (EventArgs.Empty);
+ }
+
HideWindow ();
}