Skip to content

Commit 3cb4db7

Browse files
committed
Move argument window out of the way of Excel tool tip
rather than trying to hide Excel tool tip Fix a null formula prefix
1 parent d2dcaff commit 3cb4db7

File tree

4 files changed

+55
-28
lines changed

4 files changed

+55
-28
lines changed

Source/ExcelDna.IntelliSense/IntelliSenseDisplay.cs

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ void StateUpdatePreview(object sender, UIStateUpdate update)
9393
var fl = (UIState.FunctionList)update.NewState;
9494
enable = ShouldProcessFunctionListSelectedItemChange(fl.SelectedItemText);
9595
}
96+
else if (update.Update == UIStateUpdate.UpdateType.FormulaEditExcelToolTipChange)
97+
{
98+
// If if has just been hidden, we need no extra processing and can skip the Main thread call
99+
var fe = (UIState.FormulaEdit)update.NewState;
100+
enable = fe.ExcelToolTipWindow != IntPtr.Zero;
101+
}
96102
else
97103
{
98104
enable = true; // allow the update event to be raised by default
@@ -180,8 +186,8 @@ void StateUpdate(object sender, UIStateUpdate update)
180186
FormulaEditEnd();
181187
break;
182188
case UIStateUpdate.UpdateType.FormulaEditExcelToolTipChange:
183-
// No action (for now)
184-
// The ExcelToolTipWindow is hidden when we display our Arguments ToolTip
189+
//var fett = (UIState.FormulaEdit)update.NewState;
190+
//FormulaEditExcelToolTipShow(fett.ExcelToolTipWindow);
185191
break;
186192
case UIStateUpdate.UpdateType.SelectDataSourceShow:
187193
case UIStateUpdate.UpdateType.SelectDataSourceWindowChange:
@@ -288,28 +294,28 @@ void FormulaEditTextChange(string formulaPrefix, Rect editWindowBounds, IntPtr e
288294
// We have a function name and we want to show info
289295
if (_argumentsToolTip != null)
290296
{
291-
if (!_argumentsToolTip.Visible)
297+
// NOTE: Hiding just once doesn't help - the tooltip pops up again
298+
// TODO: Try to move it off-screen, behind or make invisible
299+
//if (!_argumentsToolTip.Visible)
300+
//{
301+
// // Fiddle a bit with the ExcelToolTip if it is already visible when we first show our FunctionEdit ToolTip
302+
// // At other times, the explicit UI update should catch and hide as appropriate
303+
// if (excelToolTipWindow != IntPtr.Zero)
304+
// {
305+
// Win32Helper.HideWindow(excelToolTipWindow);
306+
// }
307+
//}
308+
309+
// For now we try to keep out of its way...
310+
int moveDown = 0;
311+
if (excelToolTipWindow != IntPtr.Zero)
292312
{
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
313+
// TODO: Maybe get its height...?
314+
moveDown = 18;
310315
}
311-
var infoText = GetFunctionIntelliSense(functionInfo, currentArgIndex);
312-
_argumentsToolTip.ShowToolTip(infoText, (int)editWindowBounds.Left, (int)editWindowBounds.Bottom + 5);
316+
317+
var infoText = GetFunctionIntelliSense(functionInfo, currentArgIndex);
318+
_argumentsToolTip.ShowToolTip(infoText, (int)editWindowBounds.Left, (int)editWindowBounds.Bottom + 5 + moveDown);
313319
}
314320
else
315321
{
@@ -329,6 +335,15 @@ void FormulaEditTextChange(string formulaPrefix, Rect editWindowBounds, IntPtr e
329335
}
330336
}
331337

338+
//void FormulaEditExcelToolTipShow(IntPtr excelToolTipWindow)
339+
//{
340+
// // Excel tool tip has just been shown
341+
// // If we're showing the arguments dialog, hide the Excel tool tip
342+
// if (_argumentsToolTip != null && _argumentsToolTip.Visible)
343+
// {
344+
// Win32Helper.HideWindow(excelToolTipWindow);
345+
// }
346+
//}
332347

333348
// Runs on the main thread
334349
void FunctionListShow()

Source/ExcelDna.IntelliSense/UIMonitor/FormulaParser.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Diagnostics;
23
using System.Linq;
34
using System.Text.RegularExpressions;
45

@@ -15,6 +16,7 @@ static class FormulaParser
1516

1617
internal static bool TryGetFormulaInfo(string formulaPrefix, out string functionName, out int currentArgIndex)
1718
{
19+
Debug.Assert(formulaPrefix != null);
1820
formulaPrefix = Regex.Replace(formulaPrefix, "(\"[^\"]*\")|(\\([^\\(\\)]*\\))| ", string.Empty);
1921

2022
while (Regex.IsMatch(formulaPrefix, "\\([^\\(\\)]*\\)"))

Source/ExcelDna.IntelliSense/UIMonitor/UIMonitor.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class Ready : UIState { }
2020
public class FormulaEdit : UIState
2121
{
2222
public IntPtr FormulaEditWindow; // Window where text entry focus is - either the in-cell edit window, or the formula bar
23-
public string FormulaPrefix;
23+
public string FormulaPrefix; // Never null
2424
public Rect EditWindowBounds;
2525
public IntPtr ExcelToolTipWindow; // ExcelToolTipWindow is Zero or is _some_ visible tooltip (either for from the list or the function)
2626

@@ -40,7 +40,7 @@ public virtual FormulaEdit WithFormulaPrefix(string newFormulaPrefix)
4040
return new FormulaEdit
4141
{
4242
FormulaEditWindow = this.FormulaEditWindow,
43-
FormulaPrefix = newFormulaPrefix,
43+
FormulaPrefix = newFormulaPrefix ?? "",
4444
EditWindowBounds = this.EditWindowBounds,
4545
ExcelToolTipWindow = this.ExcelToolTipWindow
4646
};
@@ -114,7 +114,7 @@ public override FormulaEdit WithFormulaPrefix(string newFormulaPrefix)
114114
return new FunctionList
115115
{
116116
FormulaEditWindow = this.FormulaEditWindow,
117-
FormulaPrefix = newFormulaPrefix,
117+
FormulaPrefix = newFormulaPrefix ?? "",
118118
EditWindowBounds = this.EditWindowBounds,
119119
ExcelToolTipWindow = this.ExcelToolTipWindow,
120120

@@ -616,7 +616,7 @@ UIState ReadCurrentState()
616616
SelectedItemBounds = _popupListWatcher.SelectedItemBounds,
617617
FunctionListBounds = _popupListWatcher.ListBounds,
618618
EditWindowBounds = _formulaEditWatcher.EditWindowBounds,
619-
FormulaPrefix = _formulaEditWatcher.CurrentPrefix ?? "", // TODO: Deal with nulls here... (we're not in FormulaEdit state anymore)
619+
FormulaPrefix = _formulaEditWatcher.CurrentPrefix ?? "",
620620
ExcelToolTipWindow = _lastExcelToolTipShown // We also keep track here, since we'll by inferring the UIState change list using this too
621621
};
622622
}
@@ -626,7 +626,7 @@ UIState ReadCurrentState()
626626
{
627627
FormulaEditWindow = _formulaEditWatcher.FormulaEditWindow,
628628
EditWindowBounds = _formulaEditWatcher.EditWindowBounds,
629-
FormulaPrefix = _formulaEditWatcher.CurrentPrefix ?? "", // TODO: Deal with nulls here... (we're not in FormulaEdit state anymore)
629+
FormulaPrefix = _formulaEditWatcher.CurrentPrefix ?? "",
630630
ExcelToolTipWindow = _lastExcelToolTipShown
631631
};
632632
}

Source/ExcelDna.IntelliSense/Win32Helper.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.ComponentModel;
3+
using System.Diagnostics;
34
using System.Drawing;
45
using System.Runtime.InteropServices;
56
using System.Text;
@@ -156,7 +157,16 @@ public static string GetWindowTextRaw(IntPtr hwnd)
156157

157158
public static bool HideWindow(IntPtr hWnd)
158159
{
159-
return ShowWindow(hWnd, SW_HIDE);
160+
// Happy to suppress any errors here
161+
try
162+
{
163+
return ShowWindow(hWnd, SW_HIDE);
164+
}
165+
catch (Exception ex)
166+
{
167+
Debug.Print($"Win32Helper.HideWindow Error: {ex.ToString()}");
168+
return false;
169+
}
160170
}
161171

162172
public static string GetXllName()

0 commit comments

Comments
 (0)