Skip to content

Commit 9b6e718

Browse files
committed
Rework formula edit watcher and window handling
1 parent e078594 commit 9b6e718

File tree

5 files changed

+252
-273
lines changed

5 files changed

+252
-273
lines changed

Source/ExcelDna.IntelliSense/IntelliSenseDisplay.cs

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ void StateUpdate(object sender, UIStateUpdate update)
131131
FormulaEditMove(fem.EditWindowBounds, fem.ExcelTooltipBounds);
132132
break;
133133
case UIStateUpdate.UpdateType.FormulaEditWindowChange:
134-
UpdateFormulaEditWindow((update.NewState as UIState.FormulaEdit).FormulaEditWindow);
134+
var fewc = (UIState.FormulaEdit)update.NewState;
135+
UpdateFormulaEditWindow(fewc.FormulaEditWindow);
136+
FormulaEditTextChange(fewc.FormulaPrefix, fewc.EditWindowBounds, fewc.ExcelTooltipBounds);
135137
break;
136138
case UIStateUpdate.UpdateType.FormulaEditTextChange:
137139
var fetc = (UIState.FormulaEdit)update.NewState;
@@ -176,7 +178,13 @@ void UpdateFormulaEditWindow(IntPtr formulaEditWindow)
176178
_formulaEditWindow = formulaEditWindow;
177179
if (_argumentsToolTip != null)
178180
{
179-
_argumentsToolTip.OwnerHandle = _formulaEditWindow;
181+
_argumentsToolTip.Dispose();
182+
_argumentsToolTip = null;
183+
}
184+
if (_formulaEditWindow != IntPtr.Zero)
185+
{
186+
_argumentsToolTip = new ToolTipForm(_formulaEditWindow);
187+
//_argumentsToolTip.OwnerHandle = _formulaEditWindow;
180188
}
181189
}
182190
}
@@ -188,26 +196,33 @@ void UpdateFunctionListWindow(IntPtr functionListWindow)
188196
_functionListWindow = functionListWindow;
189197
if (_descriptionToolTip != null)
190198
{
191-
_descriptionToolTip.OwnerHandle = _functionListWindow;
199+
_descriptionToolTip.Dispose();
200+
_descriptionToolTip = null;
192201
}
202+
if (_functionListWindow != IntPtr.Zero)
203+
{
204+
_descriptionToolTip = new ToolTipForm(_functionListWindow);
205+
//_descriptionToolTip.OwnerHandle = _functionListWindow;
206+
}
207+
193208
}
194209
}
195210

196211
// Runs on the main thread
197212
void FormulaEditStart()
198213
{
199214
Debug.Print($"IntelliSenseDisplay - FormulaEditStart");
200-
if (_argumentsToolTip == null)
215+
if (_formulaEditWindow != IntPtr.Zero && _argumentsToolTip == null)
201216
_argumentsToolTip = new ToolTipForm(_formulaEditWindow);
202217
}
203218

204219
// Runs on the main thread
205220
void FormulaEditEnd()
206221
{
207222
Debug.Print($"IntelliSenseDisplay - FormulaEditEnd");
208-
_argumentsToolTip.Hide();
209-
//_argumentsToolTip.Dispose();
210-
//_argumentsToolTip = null;
223+
//_argumentsToolTip.Hide();
224+
_argumentsToolTip.Dispose();
225+
_argumentsToolTip = null;
211226
}
212227

213228
// Runs on the main thread
@@ -238,9 +253,12 @@ void FormulaEditTextChange(string formulaPrefix, Rect editWindowBounds, Rect exc
238253
}
239254

240255
// All other paths, we just clear the box
241-
_argumentsToolTip.Hide();
242-
//_argumentsToolTip.Dispose();
243-
//_argumentsToolTip = null;
256+
if (_argumentsToolTip != null)
257+
{
258+
//_argumentsToolTip.Hide();
259+
_argumentsToolTip.Dispose();
260+
_argumentsToolTip = null;
261+
}
244262
}
245263

246264

Source/ExcelDna.IntelliSense/ToolTipForm.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public ToolTipForm(IntPtr hwndOwner)
2424
Debug.Assert(hwndOwner != IntPtr.Zero);
2525
InitializeComponent();
2626
_owner = new Win32Window(hwndOwner);
27+
//Win32Helper.SetParent(this.Handle, hwndOwner);
28+
2729
// _owner = new NativeWindow();
2830
// _owner.AssignHandle(hwndParent); (...with ReleaseHandle in Dispose)
2931
Debug.Print($"Created ToolTipForm with owner {hwndOwner}");
@@ -92,6 +94,7 @@ public IntPtr OwnerHandle
9294
if (_owner == null || _owner.Handle != value)
9395
{
9496
_owner = new Win32Window(value);
97+
//Win32Helper.SetParent(this.Handle, value);
9598
if (Visible)
9699
{
97100
// Rather just change Owner....

Source/ExcelDna.IntelliSense/UIMonitor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ UIState ReadCurrentState()
508508
{
509509
return new UIState.FormulaEdit
510510
{
511-
FormulaEditWindow = _formulaEditWatcher.FormulaBarWindow,
511+
FormulaEditWindow = _formulaEditWatcher.FormulaEditWindow,
512512
EditWindowBounds = _formulaEditWatcher.EditWindowBounds,
513513
FormulaPrefix = _formulaEditWatcher.CurrentPrefix ?? "", // TODO: Deal with nulls here... (we're not in FormulaEdit state anymore)
514514
};

0 commit comments

Comments
 (0)