Skip to content

Commit 49b9a15

Browse files
committed
Attempt to hide Excel tool tip when our help shows
- does not suppress further Excel tool tip pop-ups
1 parent 9c1aaed commit 49b9a15

File tree

7 files changed

+106
-25
lines changed

7 files changed

+106
-25
lines changed

Source/ExcelDna.IntelliSense/IntelliSenseDisplay.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,10 @@ void StateUpdate(object sender, UIStateUpdate update)
179179
case UIStateUpdate.UpdateType.FormulaEditEnd:
180180
FormulaEditEnd();
181181
break;
182+
case UIStateUpdate.UpdateType.FormulaEditExcelToolTipChange:
183+
// No action (for now)
184+
// The ExcelToolTipWindow is hidden when we display our Arguments ToolTip
185+
break;
182186
case UIStateUpdate.UpdateType.SelectDataSourceShow:
183187
case UIStateUpdate.UpdateType.SelectDataSourceWindowChange:
184188
case UIStateUpdate.UpdateType.SelectDataSourceHide:
@@ -281,11 +285,31 @@ void FormulaEditTextChange(string formulaPrefix, Rect editWindowBounds, IntPtr e
281285
FunctionInfo functionInfo;
282286
if (_functionInfoMap.TryGetValue(functionName, out functionInfo))
283287
{
288+
// We have a function name and we want to show info
284289
if (_argumentsToolTip != null)
285290
{
286-
_argumentsToolTip.ShowToolTip(
287-
GetFunctionIntelliSense(functionInfo, currentArgIndex),
288-
(int)editWindowBounds.Left, (int)editWindowBounds.Bottom + 5);
291+
if (!_argumentsToolTip.Visible)
292+
{
293+
#if DEBUG
294+
// Fiddle a bit with the ExcelToolTip if it is already visible when we first show our FunctionEdit ToolTip
295+
if (excelToolTipWindow != IntPtr.Zero)
296+
{
297+
try
298+
{
299+
Win32Helper.HideWindow(excelToolTipWindow);
300+
//var currentBounds = Win32Helper.GetWindowBounds(excelToolTipWindow);
301+
//Win32Helper.MoveWindow(excelToolTipWindow, (int)currentBounds.X, (int)currentBounds.Y + 100, (int)currentBounds.Width, (int)currentBounds.Height, true);
302+
}
303+
catch (Exception ex)
304+
{
305+
Debug.Print("!!!!!!!!!!!!XXXXXXXXXXXXXXXXXXXXX!!!!!!!!!!!!!!!!!!!!!!!! " + ex.ToString());
306+
}
307+
308+
}
309+
#endif
310+
}
311+
var infoText = GetFunctionIntelliSense(functionInfo, currentArgIndex);
312+
_argumentsToolTip.ShowToolTip(infoText, (int)editWindowBounds.Left, (int)editWindowBounds.Bottom + 5);
289313
}
290314
else
291315
{

Source/ExcelDna.IntelliSense/Providers/XmlIntelliSenseProvider.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ public void Refresh()
5858
// Not in macro context - don't call Excel, could be any thread.
5959
public IEnumerable<FunctionInfo> GetFunctionInfos()
6060
{
61-
61+
if (_intelliSense == null || _intelliSense.XmlFunctionInfo == null)
62+
return Enumerable.Empty<FunctionInfo>();
6263

6364
return _intelliSense.XmlFunctionInfo.FunctionsList;
6465
}

Source/ExcelDna.IntelliSense/ToolTipForm.cs

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,66 @@ protected override void DefWndProc(ref Message m)
5959
{
6060
const int WM_MOUSEACTIVATE = 0x21;
6161
const int MA_NOACTIVATE = 0x0003;
62+
const int MA_NOACTIVATEANDEAT = 0x0004;
63+
const int WM_NCACTIVATE = 0x86;
64+
const int WM_NCHITTEST = 0x84;
65+
const int HTCLIENT = 0x1;
66+
const int HTCAPTION = 0x2;
67+
68+
69+
/* you must intercept the appropriate messages received from system (WM_SIZING and WM_MOVING) and set the position of the form with SetWindowPos() - this will force it to move!
70+
71+
In your Form's class:
72+
73+
public const int WM_SIZING = 0x0214;
74+
public const int WM_MOVING = 0x0216;
75+
76+
[StructLayout(LayoutKind.Sequential)]
77+
public struct RECT
78+
{
79+
public int Left;
80+
public int Top;
81+
public int Right;
82+
public int Bottom;
83+
}
84+
85+
[DllImport("user32.dll", SetLastError = true)]
86+
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInstertAfter, int x, int y, int cx, int cy, uint flags);
87+
88+
protected override void WndProc(ref Message m)
89+
{
90+
if (m.Msg == WM_SIZING || m.Msg == WM_MOVING)
91+
{
92+
RECT rect = (RECT)Marshal.PtrToStructure(m.LParam, typeof(RECT));
93+
SetWindowPos(this.Handle, IntPtr.Zero, rect.Left, rect.Top, rect.Right - rect.Left, rect.Bottom - rect.Top, 0);
94+
}
95+
else
96+
{
97+
base.WndProc(ref m);
98+
}
99+
} */
100+
62101

63102
switch (m.Msg)
64103
{
65-
case WM_MOUSEACTIVATE:
104+
//case WM_NCHITTEST:
105+
// // Behave as if the whole form is the caption - allowing mouse to move it.
106+
// base.DefWndProc(ref m);
107+
// if ((int)m.Result == HTCLIENT)
108+
// m.Result = (IntPtr)HTCAPTION;
109+
// return;
110+
//case WM_MOUSEACTIVATE:
111+
// m.Result = (IntPtr)MA_NOACTIVATEANDEAT;
112+
// base.DefWndProc(ref m); // Seems to still activate then...
113+
// return;
114+
case WM_NCACTIVATE:
66115
m.Result = (IntPtr)MA_NOACTIVATE;
116+
base.DefWndProc(ref m); // Seems to still activate then...
117+
return;
118+
default:
119+
base.DefWndProc(ref m);
67120
return;
68121
}
69-
base.DefWndProc(ref m);
70122
}
71123

72124
public void ShowToolTip()

Source/ExcelDna.IntelliSense/UIMonitor/ExcelToolTipWatcher.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Diagnostics;
34
using System.Threading;
45
using System.Windows;
56

@@ -32,9 +33,9 @@ public ToolTipChangeEventArgs(ToolTipChangeType changeType, IntPtr handle)
3233
public event EventHandler<ToolTipChangeEventArgs> ToolTipChanged; // Either text or location
3334

3435
// CONSIDER: What should this look like?
35-
public IEnumerable<IntPtr> GetToolTips() => _toolTips;
36+
public IntPtr GetLastToolTipOrZero() => _toolTips.Count > 0 ? _toolTips[_toolTips.Count - 1] : IntPtr.Zero;
3637
// CONSIDER: Rather a Stack? Check the assumption that Hide happens in reverse order
37-
HashSet<IntPtr> _toolTips = new HashSet<IntPtr>();
38+
List<IntPtr> _toolTips = new List<IntPtr>();
3839
SynchronizationContext _syncContextAuto; // Not used...
3940
WindowWatcher _windowWatcher;
4041

@@ -51,8 +52,11 @@ void _windowWatcher_ExcelToolTipWindowChanged(object sender, WindowWatcher.Windo
5152
switch (e.Type)
5253
{
5354
case WindowWatcher.WindowChangedEventArgs.ChangeType.Show:
54-
if (_toolTips.Add(e.WindowHandle))
55+
if (!_toolTips.Contains(e.WindowHandle))
56+
{
57+
_toolTips.Add(e.WindowHandle);
5558
ToolTipChanged?.Invoke(this, new ToolTipChangeEventArgs(ToolTipChangeType.Show, e.WindowHandle));
59+
}
5660
break;
5761
case WindowWatcher.WindowChangedEventArgs.ChangeType.Hide:
5862
case WindowWatcher.WindowChangedEventArgs.ChangeType.Destroy:

Source/ExcelDna.IntelliSense/UIMonitor/UIMonitor.cs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -581,7 +581,7 @@ void _excelToolTipWatcher_ToolTipChanged(object sender, ExcelToolTipWatcher.Tool
581581
else if (e.ChangeType == ExcelToolTipWatcher.ToolTipChangeType.Hide)
582582
{
583583
if (_lastExcelToolTipShown == e.Handle)
584-
_lastExcelToolTipShown = IntPtr.Zero;
584+
_lastExcelToolTipShown = _excelToolTipWatcher.GetLastToolTipOrZero();
585585

586586
var fe = CurrentState as UIState.FormulaEdit;
587587
if (fe != null)
@@ -597,18 +597,8 @@ void _excelToolTipWatcher_ToolTipChanged(object sender, ExcelToolTipWatcher.Tool
597597
}
598598
}
599599
}
600-
601-
// _syncContextAuto.Post(ProcessExcelToolTipChange, e);
602600
}
603601

604-
// void ProcessExcelToolTipChange(object /*ExcelToolTipWatcher.ToolTipChangeEventArgs*/ e)
605-
// {
606-
// var changeEventArgs = (ExcelToolTipWatcher.ToolTipChangeEventArgs)e;
607-
// Logger.Monitor.Verbose($"!> ExcelToolTip ToolTipChanged Process: {changeEventArgs} with state: {CurrentState.GetType().Name}");
608-
//// if (CurrentState is UIState.FunctionList)
609-
//// CurrentState.Wi
610-
// }
611-
612602
// Runs on our automation thread
613603
UIState ReadCurrentState()
614604
{
@@ -627,6 +617,7 @@ UIState ReadCurrentState()
627617
FunctionListBounds = _popupListWatcher.ListBounds,
628618
EditWindowBounds = _formulaEditWatcher.EditWindowBounds,
629619
FormulaPrefix = _formulaEditWatcher.CurrentPrefix ?? "", // TODO: Deal with nulls here... (we're not in FormulaEdit state anymore)
620+
ExcelToolTipWindow = _lastExcelToolTipShown // We also keep track here, since we'll by inferring the UIState change list using this too
630621
};
631622
}
632623
if (_formulaEditWatcher.IsEditingFormula)
@@ -653,7 +644,7 @@ UIState ReadCurrentState()
653644
void OnStateChanged(UIState newStateOrNull = null)
654645
{
655646
var oldState = CurrentState;
656-
// if (newStateOrNull == null)
647+
if (newStateOrNull == null)
657648
newStateOrNull = ReadCurrentState();
658649

659650
// Debug.Print($"NEWSTATE: {newStateOrNull.ToString()}");

Source/ExcelDna.IntelliSense/UIMonitor/WinEvents.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ void HandleWinEvent(IntPtr hWinEventHook, WinEvent eventType, IntPtr hWnd,
127127
void OnWinEventReceived(object winEventArgsObj)
128128
{
129129
var winEventArgs = (WinEventArgs)winEventArgsObj;
130-
#if DEBUG
131-
Logger.WinEvents.Verbose($"{winEventArgs.EventType} - Window {winEventArgs.WindowHandle:X} ({Win32Helper.GetClassName(winEventArgs.WindowHandle)} - Object/Child {winEventArgs.ObjectId} / {winEventArgs.ChildId} - Thread {winEventArgs.EventThreadId} at {winEventArgs.EventTimeMs}");
132-
#endif
130+
//#if DEBUG
131+
// Logger.WinEvents.Verbose($"{winEventArgs.EventType} - Window {winEventArgs.WindowHandle:X} ({Win32Helper.GetClassName(winEventArgs.WindowHandle)} - Object/Child {winEventArgs.ObjectId} / {winEventArgs.ChildId} - Thread {winEventArgs.EventThreadId} at {winEventArgs.EventTimeMs}");
132+
//#endif
133133
WinEventReceived?.Invoke(this, winEventArgs);
134134
}
135135

Source/ExcelDna.IntelliSense/Win32Helper.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,15 @@ public static string GetWindowTextRaw(IntPtr hwnd)
149149
return sb.ToString();
150150
}
151151

152-
static StringBuilder _buffer = new StringBuilder(65000);
152+
const int SW_HIDE = 0;
153+
154+
[DllImport("user32.dll")]
155+
static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);
156+
157+
public static bool HideWindow(IntPtr hWnd)
158+
{
159+
return ShowWindow(hWnd, SW_HIDE);
160+
}
153161

154162
public static string GetXllName()
155163
{
@@ -166,6 +174,7 @@ public static uint GetExcelProcessId()
166174
return GetCurrentProcessId();
167175
}
168176

177+
static StringBuilder _buffer = new StringBuilder(65000);
169178
public static string GetClassName(IntPtr hWnd)
170179
{
171180
_buffer.Length = 0;

0 commit comments

Comments
 (0)