diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/AcaciaZPushPlugin.csproj b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/AcaciaZPushPlugin.csproj
index d0e5f88..047bb47 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/AcaciaZPushPlugin.csproj
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/AcaciaZPushPlugin.csproj
@@ -241,6 +241,9 @@
Component
+
+ Component
+
Component
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KAbstractComboBox.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KAbstractComboBox.cs
index f57563b..71df804 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KAbstractComboBox.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KAbstractComboBox.cs
@@ -215,23 +215,14 @@ namespace Acacia.Controls
// Cannot use visibility of _dropDown to keep the open state, as clicking on the button already
// hides the popup before the event handler is shown.
private bool _isDroppedDown;
- private bool _clickedButton;
private void _dropDown_Closed(object sender, ToolStripDropDownClosedEventArgs e)
{
- /*if (_stateButton.IsMouseOver)
- {
- _clickedButton = true;
- }*/
_isDroppedDown = false;
}
private void Button_Clicked()
{
- /*if (_clickedButton)
- _clickedButton = false;
- else
- DroppedDown = true;*/
DroppedDown = !DroppedDown;
this._edit.Focus();
}
@@ -258,7 +249,6 @@ namespace Acacia.Controls
_dropControl.Height = Util.Bound(prefSize.Height, minHeight, maxHeight);
// Show the drop down below the current control
_dropDown.Show(this.PointToScreen(new Point(0, Height)));
- _dropDown.Capture = true;
}
else
{
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KComboBox.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KComboBox.cs
index 58017fc..ac0b30d 100644
--- a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KComboBox.cs
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KComboBox.cs
@@ -14,7 +14,7 @@ namespace Acacia.Controls
{
public class KComboBox : KAbstractComboBox
{
- private readonly ListBox _list;
+ protected readonly KListBox _list;
#region Items properties
@@ -45,10 +45,16 @@ namespace Acacia.Controls
public KComboBox()
{
MaxDropDownItems = 8;
- _list = new ListBox();
+ _list = new KListBox();
_list.IntegralHeight = true;
DropControl = _list;
_list.DisplayMember = "DisplayName"; // TODO: remove from here
+ _list.SelectedIndexChanged += _list_SelectedIndexChanged;
+ }
+
+ private void _list_SelectedIndexChanged(object sender, EventArgs e)
+ {
+ System.Diagnostics.Trace.WriteLine("SELECTED: " + _list.SelectedIndex);
}
public void BeginUpdate()
diff --git a/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KListBox.cs b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KListBox.cs
new file mode 100644
index 0000000..b22b389
--- /dev/null
+++ b/src/AcaciaZPushPlugin/AcaciaZPushPlugin/Controls/KListBox.cs
@@ -0,0 +1,78 @@
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Forms;
+
+namespace Acacia.Controls
+{
+ public class KListBox : ListBox
+ {
+ private int _hoverIndex = -1;
+
+ public KListBox()
+ {
+ SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
+ DrawMode = DrawMode.OwnerDrawFixed;
+ }
+
+ protected override void OnMouseMove(MouseEventArgs e)
+ {
+ Point point = PointToClient(Cursor.Position);
+ int newIndex = IndexFromPoint(point);
+ if (newIndex != _hoverIndex)
+ {
+ int oldIndex = _hoverIndex;
+ _hoverIndex = newIndex;
+ InvalidateItem(oldIndex);
+ InvalidateItem(_hoverIndex);
+ }
+ }
+
+ protected override void OnMouseLeave(EventArgs e)
+ {
+ base.OnMouseLeave(e);
+ _hoverIndex = -1;
+ }
+
+ protected override void OnVisibleChanged(EventArgs e)
+ {
+ base.OnVisibleChanged(e);
+ _hoverIndex = -1;
+ }
+
+ private void InvalidateItem(int index)
+ {
+ if (index < 0)
+ return;
+ Invalidate(GetItemRectangle(index));
+ }
+
+ protected override void OnDrawItem(DrawItemEventArgs e)
+ {
+ // Create a custom event instance to be able to set the selected state for mouse hover
+ DrawItemState state = e.State;
+ if (_hoverIndex >= 0)
+ {
+ state = _hoverIndex == e.Index ? DrawItemState.Selected : DrawItemState.None;
+ }
+ DrawItemEventArgs draw = new DrawItemEventArgs(e.Graphics, e.Font, e.Bounds, e.Index, state);
+ draw.DrawBackground();
+
+ string text = Items[draw.Index].ToString();
+ using (StringFormat format = new StringFormat())
+ {
+ format.LineAlignment = StringAlignment.Center;
+ using (Brush brush = new SolidBrush(draw.ForeColor))
+ {
+ draw.Graphics.DrawString(text,
+ draw.Font, brush,
+ draw.Bounds,
+ format);
+ }
+ }
+ }
+ }
+}