Skip to content

Commit 6de5e75

Browse files
committed
Added mouse wheel support to window list menu.
1 parent 6e32087 commit 6de5e75

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

PluginCore/DockPanelSuite/Customization/VS2005DockPaneStrip.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ public VS2005DockPaneStrip(DockPane pane) : base(pane)
569569
m_selectMenu.Font = PluginCore.PluginBase.Settings.DefaultFont;
570570
m_selectMenu.ImageScalingSize = ScaleHelper.Scale(new Size(16, 16));
571571
m_selectMenu.Renderer = new DockPanelStripRenderer(false);
572+
m_selectMenu.MouseWheel += ContextMenu_MouseWheel;
572573

573574
ResumeLayout();
574575
}
@@ -1441,6 +1442,51 @@ private void WindowList_Click(object sender, EventArgs e)
14411442
SelectMenu.Show(ButtonWindowList, x, y);
14421443
}
14431444

1445+
private static readonly Action<ToolStrip, int> ScrollInternal
1446+
= (Action<ToolStrip, int>)Delegate.CreateDelegate(typeof(Action<ToolStrip, int>),
1447+
typeof(ToolStrip).GetMethod("ScrollInternal",
1448+
System.Reflection.BindingFlags.NonPublic
1449+
| System.Reflection.BindingFlags.Instance));
1450+
1451+
private static readonly Action<ToolStripDropDownMenu> UpdateScrollButtonStatus
1452+
= (Action<ToolStripDropDownMenu>)Delegate.CreateDelegate(typeof(Action<ToolStripDropDownMenu>),
1453+
typeof(ToolStripDropDownMenu).GetMethod("UpdateScrollButtonStatus",
1454+
System.Reflection.BindingFlags.NonPublic
1455+
| System.Reflection.BindingFlags.Instance));
1456+
1457+
private void ContextMenu_MouseWheel(object sender, MouseEventArgs e)
1458+
{
1459+
/* Default size, can it be changed? if so we can get it with:
1460+
((ToolStripItem)typeof(ToolStripDropDownMenu).GetProperty ("DownScrollButton",
1461+
System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance ).GetValue(ts, null)).
1462+
GetPreferredSize(Size.Empty).Height
1463+
*/
1464+
const int scrollButtonHeight = 9;
1465+
1466+
var ts = (ContextMenuStrip)sender;
1467+
int delta = e.Delta;
1468+
if (ts.Items.Count == 0)
1469+
return;
1470+
var firstItem = ts.Items[0];
1471+
var lastItem = ts.Items[ts.Items.Count - 1];
1472+
if (lastItem.Bounds.Bottom < ts.Height && firstItem.Bounds.Top > 0)
1473+
return;
1474+
delta = delta / -4;
1475+
if (delta < 0 && firstItem.Bounds.Top - delta > scrollButtonHeight)
1476+
{
1477+
delta = firstItem.Bounds.Top - scrollButtonHeight;
1478+
}
1479+
else if (delta > 0 && delta > lastItem.Bounds.Bottom - ts.Height + scrollButtonHeight * 2)
1480+
{
1481+
delta = lastItem.Bounds.Bottom - ts.Height + scrollButtonHeight * 2;
1482+
}
1483+
if (delta != 0)
1484+
{
1485+
ScrollInternal(ts, delta);
1486+
UpdateScrollButtonStatus(ts);
1487+
}
1488+
}
1489+
14441490
private void ContextMenuItem_Up(object sender, MouseEventArgs e)
14451491
{
14461492
ToolStripMenuItem item = sender as ToolStripMenuItem;

0 commit comments

Comments
 (0)