[Feature] Mouse&Keyboard Selection #38, [Feature] Better colors handling #37, Version 0.9.2.0

This commit is contained in:
Markus Hofknecht 2020-03-15 16:06:18 +01:00
parent da92bd8a38
commit 68ce47fb09
5 changed files with 65 additions and 8 deletions

View file

@ -24,6 +24,8 @@ namespace SystemTrayMenu.Handler
public int iMenuKey = 0; public int iMenuKey = 0;
string KeySearchString = string.Empty; string KeySearchString = string.Empty;
public bool InUse = false;
public KeyboardInput(Menu[] menus) public KeyboardInput(Menu[] menus)
{ {
this.menus = menus; this.menus = menus;
@ -363,6 +365,16 @@ namespace SystemTrayMenu.Handler
return found; return found;
} }
public void Select(DataGridView dgv, int i)
{
iRowKey = i;
iMenuKey = ((Menu)dgv.TopLevelControl).Level;
DataGridViewRow row = dgv.Rows[i];
RowData rowData = (RowData)row.Tag;
rowData.IsSelectedByKeyboard = true;
row.Selected = true;
}
private bool Select(DataGridView dgv, int i, private bool Select(DataGridView dgv, int i,
string keyInput = "") string keyInput = "")
{ {

View file

@ -1,4 +1,5 @@
using System.Windows.Forms; using System.Drawing;
using System.Windows.Forms;
namespace SystemTrayMenu namespace SystemTrayMenu
{ {
@ -13,6 +14,8 @@ namespace SystemTrayMenu
public event EventHandler MouseMove; public event EventHandler MouseMove;
public event EventHandler ScrollBarMouseMove; public event EventHandler ScrollBarMouseMove;
Point cursorPosition = new Point();
public bool PreFilterMessage(ref Message message) public bool PreFilterMessage(ref Message message)
{ {
if (message.Msg == WM_MOUSELEAVE) if (message.Msg == WM_MOUSELEAVE)
@ -21,7 +24,12 @@ namespace SystemTrayMenu
} }
else if (message.Msg == WM_MOUSEMOVE) else if (message.Msg == WM_MOUSEMOVE)
{ {
MouseMove?.Invoke(); Point newCursorPosition = Cursor.Position;
if (!newCursorPosition.Equals(cursorPosition))
{
MouseMove?.Invoke();
}
cursorPosition = newCursorPosition;
} }
else if (message.Msg == WM_NCMOUSEMOVE) else if (message.Msg == WM_NCMOUSEMOVE)
{ {

View file

@ -14,7 +14,7 @@ namespace SystemTrayMenu
// windows explorer highlighted text // windows explorer highlighted text
public static Color FolderOpen = Color.FromArgb(229, 243, 255); public static Color FolderOpen = Color.FromArgb(229, 243, 255);
public static Color Background = Color.FromArgb(229, 243, 255); public static Color Background = Color.FromArgb(229, 243, 255);
internal static Color KeyBoardSelection = Color.Yellow; internal static Color KeyBoardSelection = Color.FromArgb(204, 232, 255);
internal static int KeySearchInterval = 1000; internal static int KeySearchInterval = 1000;
public const int MenuRowsHeight = 18; public const int MenuRowsHeight = 18;
public const int LengthMax = 37; public const int LengthMax = 37;

View file

@ -31,5 +31,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers // You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below: // by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")] // [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.9.1.260")] [assembly: AssemblyVersion("0.9.2.0")]
[assembly: AssemblyFileVersion("0.9.1.260")] [assembly: AssemblyFileVersion("0.9.2.0")]

View file

@ -39,6 +39,9 @@ namespace SystemTrayMenu
BackgroundWorker worker = new BackgroundWorker(); BackgroundWorker worker = new BackgroundWorker();
Screen screen = Screen.PrimaryScreen; Screen screen = Screen.PrimaryScreen;
DataGridView dgvFromLastMouseEvent = null;
DataGridViewCellEventArgs cellEventArgsFromLastMouseEvent = null;
public SystemTrayMenu(ref bool cancelAppRun) public SystemTrayMenu(ref bool cancelAppRun)
{ {
log.Info("Application Start " + log.Info("Application Start " +
@ -63,6 +66,7 @@ namespace SystemTrayMenu
keyboardInput.RowSelected += KeyboardInputRowSelected; keyboardInput.RowSelected += KeyboardInputRowSelected;
void KeyboardInputRowSelected(DataGridView dgv, int rowIndex) void KeyboardInputRowSelected(DataGridView dgv, int rowIndex)
{ {
keyboardInput.InUse = true;
FadeInIfNeeded(); FadeInIfNeeded();
CheckMenuOpenerStart(dgv, rowIndex); CheckMenuOpenerStart(dgv, rowIndex);
} }
@ -206,6 +210,23 @@ namespace SystemTrayMenu
} }
messageFilter.MouseMove += FadeInIfNeeded; messageFilter.MouseMove += FadeInIfNeeded;
messageFilter.MouseMove += MessageFilter_MouseMove;
void MessageFilter_MouseMove()
{
if (keyboardInput.InUse)
{
CheckMenuOpenerStop(keyboardInput.iMenuKey,
keyboardInput.iRowKey);
keyboardInput.ClearIsSelectedByKey();
keyboardInput.InUse = false;
if (dgvFromLastMouseEvent != null)
{
Dgv_MouseEnter(dgvFromLastMouseEvent,
cellEventArgsFromLastMouseEvent);
}
}
}
messageFilter.ScrollBarMouseMove += FadeInIfNeeded; messageFilter.ScrollBarMouseMove += FadeInIfNeeded;
messageFilter.MouseLeave += fastLeave.Start; messageFilter.MouseLeave += fastLeave.Start;
@ -570,7 +591,16 @@ namespace SystemTrayMenu
private void Dgv_MouseEnter(object sender, DataGridViewCellEventArgs e) private void Dgv_MouseEnter(object sender, DataGridViewCellEventArgs e)
{ {
DataGridView dgv = (DataGridView)sender; DataGridView dgv = (DataGridView)sender;
CheckMenuOpenerStart(dgv, e.RowIndex); dgvFromLastMouseEvent = dgv;
cellEventArgsFromLastMouseEvent = e;
if (!keyboardInput.InUse)
{
keyboardInput.ClearIsSelectedByKey();
keyboardInput.Select(dgv, e.RowIndex);
CheckMenuOpenerStart(dgv, e.RowIndex);
}
} }
private void CheckMenuOpenerStart(DataGridView dgv, int rowIndex) private void CheckMenuOpenerStart(DataGridView dgv, int rowIndex)
@ -611,8 +641,15 @@ namespace SystemTrayMenu
private void Dgv_MouseLeave(object sender, DataGridViewCellEventArgs e) private void Dgv_MouseLeave(object sender, DataGridViewCellEventArgs e)
{ {
DataGridView dgv = (DataGridView)sender; DataGridView dgv = (DataGridView)sender;
Menu menu = (Menu)dgv.FindForm();
CheckMenuOpenerStop(menu.Level, e.RowIndex, dgv); if (!keyboardInput.InUse)
{
Menu menu = (Menu)dgv.FindForm();
CheckMenuOpenerStop(menu.Level, e.RowIndex, dgv);
}
dgvFromLastMouseEvent = null;
cellEventArgsFromLastMouseEvent = null;
} }
private void CheckMenuOpenerStop(int menuIndex, int rowIndex, DataGridView dgv = null) private void CheckMenuOpenerStop(int menuIndex, int rowIndex, DataGridView dgv = null)