Skip to content

Commit 39f878c

Browse files
committed
Improve PopupList display performance.
IntelliSenseServer v 0.0.5
1 parent 6043896 commit 39f878c

File tree

6 files changed

+28
-33
lines changed

6 files changed

+28
-33
lines changed

Source/ExcelDna.IntelliSense/IntelliSenseDisplay.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,7 @@ void FunctionListHide()
309309
// Runs on the main thread
310310
void FunctionListSelectedItemChange(string selectedItemText, Rect selectedItemBounds)
311311
{
312-
Debug.Print($"IntelliSenseDisplay - PopupListSelectedItemChanged - New text - {selectedItemText}, Thread {Thread.CurrentThread.ManagedThreadId}");
312+
Logger.Display.Verbose($"IntelliSenseDisplay - PopupListSelectedItemChanged - New text - {selectedItemText}, Thread {Thread.CurrentThread.ManagedThreadId}");
313313

314314
IntelliSenseFunctionInfo functionInfo;
315315
if (_functionInfoMap.TryGetValue(selectedItemText, out functionInfo))

Source/ExcelDna.IntelliSense/IntelliSenseServer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ namespace ExcelDna.IntelliSense
4747
// REMEMBER: COM events are not necessarily safe macro contexts.
4848
public static class IntelliSenseServer
4949
{
50-
const string ServerVersion = "0.0.4"; // TODO: Define and manage this somewhere else
50+
const string ServerVersion = "0.0.5"; // TODO: Define and manage this somewhere else
5151

5252
// NOTE: Do not change these constants in custom versions.
5353
// They are part of the co-operative safety mechanism allowing different add-ins providing IntelliSense to work together safely.
@@ -121,7 +121,7 @@ private static void CurrentDomain_ProcessExit(object sender, EventArgs e)
121121
{
122122
Deactivate();
123123
}
124-
Logger.Initialization.Verbose("IntelliSenseServer PrcessExit End");
124+
Logger.Initialization.Verbose("IntelliSenseServer ProcessExit End");
125125

126126
}
127127

Source/ExcelDna.IntelliSense/ToolTipForm.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ class ToolTipForm : Form
1818
ToolTip tipDna;
1919
System.ComponentModel.IContainer components;
2020
Win32Window _owner;
21+
int _left;
22+
int _top;
2123

2224
public ToolTipForm(IntPtr hwndOwner)
2325
{
@@ -71,15 +73,15 @@ public void ShowToolTip(FormattedText text, int left, int top)
7173
Debug.Print($"Invalidating ToolTipForm: {_text.ToString()}");
7274
Invalidate();
7375
}
74-
Left = left;
75-
Top = top;
76+
_left = left;
77+
_top = top;
7678
}
7779

7880
public void MoveToolTip(int left, int top)
7981
{
8082
Invalidate();
81-
Left = left;
82-
Top = top;
83+
_left = left;
84+
_top = top;
8385
}
8486

8587
public IntPtr OwnerHandle
@@ -194,7 +196,8 @@ protected override void OnPaint(PaintEventArgs e)
194196
}
195197
}
196198

197-
Size = new Size(lineWidths.Max() + widthPadding, totalHeight + heightPadding);
199+
SetBounds(_left, _top, lineWidths.Max() + widthPadding, totalHeight + heightPadding);
200+
// Size = new Size(lineWidths.Max() + widthPadding, totalHeight + heightPadding);
198201
}
199202

200203
void DrawString(Graphics g, Brush brush, ref Rectangle rect, out Size used,

Source/ExcelDna.IntelliSense/UIMonitor/FormulaEditWatcher.cs

Lines changed: 8 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -430,35 +430,24 @@ void OnStateChanged(StateChangeEventArgs stateChangeEventArgs)
430430

431431
public void Dispose()
432432
{
433-
Logger.WindowWatcher.Verbose("FormulaEdit Disposing");
433+
Logger.WindowWatcher.Verbose("FormulaEdit Dispose Begin");
434434
XlCall.ShutdownStarted();
435435

436436
// Not sure we need this:
437437
_windowWatcher.FormulaBarWindowChanged -= _windowWatcher_FormulaBarWindowChanged;
438438
_windowWatcher.InCellEditWindowChanged -= _windowWatcher_InCellEditWindowChanged;
439439
// _windowWatcher.MainWindowChanged -= _windowWatcher_MainWindowChanged;
440440

441-
_formulaPollingTimer?.Dispose();
442-
_formulaPollingTimer = null;
443-
441+
// Forcing cleanup on the automation thread - not sure we need to ....
444442
_syncContextAuto.Send(delegate
445443
{
446-
if (_formulaBar != null)
447-
{
448-
UninstallTextChangeMonitor(_formulaBar);
449-
_formulaBar = null;
450-
}
451-
if (_inCellEdit != null)
452-
{
453-
UninstallTextChangeMonitor(_inCellEdit);
454-
_inCellEdit = null;
455-
}
456-
//if (_mainWindow != null)
457-
//{
458-
// Automation.RemoveAutomationPropertyChangedEventHandler(_mainWindow, LocationChanged);
459-
// _mainWindow = null;
460-
//}
444+
_enableFormulaPolling = false;
445+
_formulaPollingTimer?.Dispose();
446+
_formulaPollingTimer = null;
447+
_formulaBar = null;
448+
_inCellEdit = null;
461449
}, null);
450+
Logger.WindowWatcher.Verbose("FormulaEdit Dispose End");
462451
}
463452
}
464453
}

Source/ExcelDna.IntelliSense/UIMonitor/PopupListWatcher.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ void OnSelectedItemChanged()
365365

366366
public void Dispose()
367367
{
368-
Logger.WindowWatcher.Info($"PopupList Dispose");
368+
Logger.WindowWatcher.Info($"PopupList Dispose Begin");
369369
_windowWatcher.PopupListWindowChanged -= _windowWatcher_PopupListWindowChanged;
370370
_windowWatcher = null;
371371

@@ -374,11 +374,12 @@ public void Dispose()
374374
Debug.Print("Disposing PopupListWatcher - In Automation context");
375375
if (_popupList != null)
376376
{
377-
Automation.RemoveAutomationEventHandler(SelectionItemPattern.ElementSelectedEvent, _popupList, PopupListElementSelectedHandler);
378-
Automation.RemoveAutomationPropertyChangedEventHandler(_popupList, PopupListBoundsChanged);
377+
//Automation.RemoveAutomationEventHandler(SelectionItemPattern.ElementSelectedEvent, _popupList, PopupListElementSelectedHandler);
378+
//Automation.RemoveAutomationPropertyChangedEventHandler(_popupList, PopupListBoundsChanged);
379379
_popupList = null;
380380
}
381381
}, null);
382+
Logger.WindowWatcher.Info($"PopupList Dispose End");
382383
}
383384
}
384385
}

Source/ExcelDna.IntelliSense/UIMonitor/UIMonitor.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -621,12 +621,16 @@ void RaiseStateUpdates(object updates)
621621

622622
public void Dispose()
623623
{
624+
Logger.Monitor.Info($"UIMonitor Dispose Begin");
625+
624626
if (_syncContextAuto == null)
625627
return;
626628

627629
// Send is not supported on _syncContextAuto
628630
_syncContextAuto.Send(delegate
629631
{
632+
// Remove all event handlers ASAP
633+
Automation.RemoveAllEventHandlers();
630634
if (_windowWatcher != null)
631635
{
632636
// _windowWatcher.MainWindowChanged -= _windowWatcher_MainWindowChanged;
@@ -646,8 +650,6 @@ public void Dispose()
646650
_popupListWatcher.Dispose();
647651
_popupListWatcher = null;
648652
}
649-
// Try to clean up any stray event handlers too...
650-
Automation.RemoveAllEventHandlers();
651653

652654
}, null);
653655

@@ -658,7 +660,7 @@ public void Dispose()
658660
_syncContextAuto.Complete();
659661
_syncContextAuto = null;
660662
}, null);
661-
663+
Logger.Monitor.Info($"UIMonitor Dispose End");
662664
}
663665
}
664666
}

0 commit comments

Comments
 (0)