Skip to content

Commit

Permalink
Improve PopupList display performance.
Browse files Browse the repository at this point in the history
IntelliSenseServer v 0.0.5
  • Loading branch information
govert committed May 13, 2016
1 parent 6043896 commit 39f878c
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 33 deletions.
2 changes: 1 addition & 1 deletion Source/ExcelDna.IntelliSense/IntelliSenseDisplay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void FunctionListHide()
// Runs on the main thread
void FunctionListSelectedItemChange(string selectedItemText, Rect selectedItemBounds)
{
Debug.Print($"IntelliSenseDisplay - PopupListSelectedItemChanged - New text - {selectedItemText}, Thread {Thread.CurrentThread.ManagedThreadId}");
Logger.Display.Verbose($"IntelliSenseDisplay - PopupListSelectedItemChanged - New text - {selectedItemText}, Thread {Thread.CurrentThread.ManagedThreadId}");

IntelliSenseFunctionInfo functionInfo;
if (_functionInfoMap.TryGetValue(selectedItemText, out functionInfo))
Expand Down
4 changes: 2 additions & 2 deletions Source/ExcelDna.IntelliSense/IntelliSenseServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ namespace ExcelDna.IntelliSense
// REMEMBER: COM events are not necessarily safe macro contexts.
public static class IntelliSenseServer
{
const string ServerVersion = "0.0.4"; // TODO: Define and manage this somewhere else
const string ServerVersion = "0.0.5"; // TODO: Define and manage this somewhere else

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

}

Expand Down
13 changes: 8 additions & 5 deletions Source/ExcelDna.IntelliSense/ToolTipForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class ToolTipForm : Form
ToolTip tipDna;
System.ComponentModel.IContainer components;
Win32Window _owner;
int _left;
int _top;

public ToolTipForm(IntPtr hwndOwner)
{
Expand Down Expand Up @@ -71,15 +73,15 @@ public void ShowToolTip(FormattedText text, int left, int top)
Debug.Print($"Invalidating ToolTipForm: {_text.ToString()}");
Invalidate();
}
Left = left;
Top = top;
_left = left;
_top = top;
}

public void MoveToolTip(int left, int top)
{
Invalidate();
Left = left;
Top = top;
_left = left;
_top = top;
}

public IntPtr OwnerHandle
Expand Down Expand Up @@ -194,7 +196,8 @@ protected override void OnPaint(PaintEventArgs e)
}
}

Size = new Size(lineWidths.Max() + widthPadding, totalHeight + heightPadding);
SetBounds(_left, _top, lineWidths.Max() + widthPadding, totalHeight + heightPadding);
// Size = new Size(lineWidths.Max() + widthPadding, totalHeight + heightPadding);
}

void DrawString(Graphics g, Brush brush, ref Rectangle rect, out Size used,
Expand Down
27 changes: 8 additions & 19 deletions Source/ExcelDna.IntelliSense/UIMonitor/FormulaEditWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -430,35 +430,24 @@ void OnStateChanged(StateChangeEventArgs stateChangeEventArgs)

public void Dispose()
{
Logger.WindowWatcher.Verbose("FormulaEdit Disposing");
Logger.WindowWatcher.Verbose("FormulaEdit Dispose Begin");
XlCall.ShutdownStarted();

// Not sure we need this:
_windowWatcher.FormulaBarWindowChanged -= _windowWatcher_FormulaBarWindowChanged;
_windowWatcher.InCellEditWindowChanged -= _windowWatcher_InCellEditWindowChanged;
// _windowWatcher.MainWindowChanged -= _windowWatcher_MainWindowChanged;

_formulaPollingTimer?.Dispose();
_formulaPollingTimer = null;

// Forcing cleanup on the automation thread - not sure we need to ....
_syncContextAuto.Send(delegate
{
if (_formulaBar != null)
{
UninstallTextChangeMonitor(_formulaBar);
_formulaBar = null;
}
if (_inCellEdit != null)
{
UninstallTextChangeMonitor(_inCellEdit);
_inCellEdit = null;
}
//if (_mainWindow != null)
//{
// Automation.RemoveAutomationPropertyChangedEventHandler(_mainWindow, LocationChanged);
// _mainWindow = null;
//}
_enableFormulaPolling = false;
_formulaPollingTimer?.Dispose();
_formulaPollingTimer = null;
_formulaBar = null;
_inCellEdit = null;
}, null);
Logger.WindowWatcher.Verbose("FormulaEdit Dispose End");
}
}
}
7 changes: 4 additions & 3 deletions Source/ExcelDna.IntelliSense/UIMonitor/PopupListWatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ void OnSelectedItemChanged()

public void Dispose()
{
Logger.WindowWatcher.Info($"PopupList Dispose");
Logger.WindowWatcher.Info($"PopupList Dispose Begin");
_windowWatcher.PopupListWindowChanged -= _windowWatcher_PopupListWindowChanged;
_windowWatcher = null;

Expand All @@ -374,11 +374,12 @@ public void Dispose()
Debug.Print("Disposing PopupListWatcher - In Automation context");
if (_popupList != null)
{
Automation.RemoveAutomationEventHandler(SelectionItemPattern.ElementSelectedEvent, _popupList, PopupListElementSelectedHandler);
Automation.RemoveAutomationPropertyChangedEventHandler(_popupList, PopupListBoundsChanged);
//Automation.RemoveAutomationEventHandler(SelectionItemPattern.ElementSelectedEvent, _popupList, PopupListElementSelectedHandler);
//Automation.RemoveAutomationPropertyChangedEventHandler(_popupList, PopupListBoundsChanged);
_popupList = null;
}
}, null);
Logger.WindowWatcher.Info($"PopupList Dispose End");
}
}
}
8 changes: 5 additions & 3 deletions Source/ExcelDna.IntelliSense/UIMonitor/UIMonitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -621,12 +621,16 @@ void RaiseStateUpdates(object updates)

public void Dispose()
{
Logger.Monitor.Info($"UIMonitor Dispose Begin");

if (_syncContextAuto == null)
return;

// Send is not supported on _syncContextAuto
_syncContextAuto.Send(delegate
{
// Remove all event handlers ASAP
Automation.RemoveAllEventHandlers();
if (_windowWatcher != null)
{
// _windowWatcher.MainWindowChanged -= _windowWatcher_MainWindowChanged;
Expand All @@ -646,8 +650,6 @@ public void Dispose()
_popupListWatcher.Dispose();
_popupListWatcher = null;
}
// Try to clean up any stray event handlers too...
Automation.RemoveAllEventHandlers();

}, null);

Expand All @@ -658,7 +660,7 @@ public void Dispose()
_syncContextAuto.Complete();
_syncContextAuto = null;
}, null);

Logger.Monitor.Info($"UIMonitor Dispose End");
}
}
}
Expand Down

0 comments on commit 39f878c

Please sign in to comment.