Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure tooltip window handle is being destroyed when parent window/control is destroyed #2094

Open
wants to merge 5 commits into
base: unity-main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6552,7 +6552,7 @@ private Timer ToolTipTimer {
private ToolTip ToolTipWindow {
get {
if (tooltip_window == null)
tooltip_window = new ToolTip ();
tooltip_window = new ToolTip (this);

return tooltip_window;
}
Expand Down
26 changes: 17 additions & 9 deletions mcs/class/System.Windows.Forms/System.Windows.Forms/FileDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2296,10 +2296,6 @@ public MWFFileView (MWFVFS vfs)

contextMenu = new ContextMenu ();

toolTip = new ToolTip ();
toolTip.InitialDelay = 300;
toolTip.ReshowDelay = 0;

// contextMenu

// View menu item
Expand Down Expand Up @@ -2458,6 +2454,18 @@ public string SelectedFilesString {
return selectedFilesString;
}
}

private ToolTip ToolTipWindow {
get {
if (toolTip == null) {
toolTip = new ToolTip(this);
toolTip.InitialDelay = 300;
toolTip.ReshowDelay = 0;
}

return toolTip;
}
}

public void PushDir ()
{
Expand Down Expand Up @@ -2891,8 +2899,8 @@ protected override void OnMouseMove (MouseEventArgs e)
if (currentItemIndex != oldItemIndexForToolTip) {
oldItemIndexForToolTip = currentItemIndex;

if (toolTip != null && toolTip.Active)
toolTip.Active = false;
if (ToolTipWindow.Active)
ToolTipWindow.Active = false;

FSEntry fsEntry = item.FSEntry;

Expand All @@ -2907,12 +2915,12 @@ protected override void OnMouseMove (MouseEventArgs e)
else
output = Locale.GetText("File: {0}", fsEntry.FullName);

toolTip.SetToolTip (this, output);
ToolTipWindow.SetToolTip (this, output);

toolTip.Active = true;
ToolTipWindow.Active = true;
}
} else
toolTip.Active = false;
ToolTipWindow.Active = false;

base.OnMouseMove (e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ public void ToolTipShow (bool only_refresh)
}

if (tooltip == null)
tooltip = new ToolTip.ToolTipWindow ();
tooltip = new ToolTip.ToolTipWindow (form);
else if (tooltip.Text == text && tooltip.Visible)
return;
else if (tooltip.Visible)
Expand Down
22 changes: 15 additions & 7 deletions mcs/class/System.Windows.Forms/System.Windows.Forms/ListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,6 @@ public ListView ()
items_location = new Point [16];
items_matrix_location = new ItemMatrixLocation [16];
reordered_items_indices = new int [16];
item_tooltip = new ToolTip ();
item_tooltip.Active = false;
insertion_mark = new ListViewInsertionMark (this);

InternalBorderStyle = BorderStyle.Fixed3D;
Expand Down Expand Up @@ -316,7 +314,7 @@ public ListView ()
}
#endregion // Public Constructors

#region Private Internal Properties
#region Private & Internal Properties
internal Size CheckBoxSize {
get {
if (this.check_boxes) {
Expand Down Expand Up @@ -377,6 +375,16 @@ internal ColumnHeader EnteredColumnHeader {
return header_control.EnteredColumnHeader;
}
}

private ToolTip ToolTipWindow {
get {
if (item_tooltip == null) {
item_tooltip = new ToolTip(this);
item_tooltip.Active = false;
}
return item_tooltip;
}
}
#endregion // Private Internal Properties

#region Protected Properties
Expand Down Expand Up @@ -815,7 +823,7 @@ public bool ShowItemToolTips {
}
set {
show_item_tooltips = value;
item_tooltip.Active = false;
ToolTipWindow.Active = false;
}
}

Expand Down Expand Up @@ -2779,11 +2787,11 @@ private void ItemsMouseMove (object sender, MouseEventArgs me)

if (owner.ShowItemToolTips) {
if (item == null) {
owner.item_tooltip.Active = false;
owner.ToolTipWindow.Active = false;
prev_tooltip_item = null;
} else if (item != prev_tooltip_item && item.ToolTipText.Length > 0) {
owner.item_tooltip.Active = true;
owner.item_tooltip.SetToolTip (owner, item.ToolTipText);
owner.ToolTipWindow.Active = true;
owner.ToolTipWindow.SetToolTip (owner, item.ToolTipText);
prev_tooltip_item = item;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ private Timer ToolTipTimer {
private ToolTip ToolTipWindow {
get {
if (tooltip_window == null)
tooltip_window = new ToolTip ();
tooltip_window = new ToolTip (this);

return tooltip_window;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ void SetToolTip (string text)
}

if (tooltip == null) {
tooltip = new ToolTip ();
tooltip = new ToolTip (this);
tooltip_timer = new Timer ();
tooltip_timer.Tick += new EventHandler (ToolTipTimerTick);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ private void ToolBar_MouseHover (object sender, EventArgs e)
return;

if (tip_window == null)
tip_window = new ToolTip ();
tip_window = new ToolTip (this);

ToolBarItem item = ItemAtPoint (PointToClient (Control.MousePosition));
current_item = item;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1572,7 +1572,7 @@ private Timer ToolTipTimer {
private ToolTip ToolTipWindow {
get {
if (tooltip_window == null)
tooltip_window = new ToolTip ();
tooltip_window = new ToolTip (this);

return tooltip_window;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ private Timer ToolTipTimer {
private ToolTip ToolTipWindow {
get {
if (tooltip_window == null)
tooltip_window = new ToolTip ();
tooltip_window = new ToolTip (this);

return tooltip_window;
}
Expand Down
14 changes: 10 additions & 4 deletions mcs/class/System.Windows.Forms/System.Windows.Forms/ToolTip.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal class ToolTipWindow : Control {
#endregion // ToolTipWindow Class Local Variables

#region ToolTipWindow Class Constructor
internal ToolTipWindow() {
internal ToolTipWindow(Control owner = null) {
Visible = false;
Size = new Size(100, 20);
ForeColor = ThemeEngine.Current.ColorInfoText;
Expand All @@ -94,9 +94,15 @@ internal ToolTipWindow() {
} else
SetStyle (ControlStyles.Opaque, true);

SetTopLevel (true);
if (owner == null) {
SetTopLevel (true);
} else {
SetTopLevel (false);
owner.Controls.Add(this);
}
}


#endregion // ToolTipWindow Class Constructor

#region ToolTipWindow Class Protected Instance Methods
Expand Down Expand Up @@ -288,7 +294,7 @@ internal event PopupEventHandler UnPopup {
#endregion // ToolTipWindow Class

#region Public Constructors & Destructors
public ToolTip() {
public ToolTip(Control owner = null) {

// Defaults from MS
is_active = true;
Expand All @@ -307,7 +313,7 @@ public ToolTip() {
tooltip_strings = new Hashtable(5);
controls = new ArrayList(5);

tooltip_window = new ToolTipWindow();
tooltip_window = new ToolTipWindow(owner);
tooltip_window.MouseLeave += new EventHandler(control_MouseLeave);
tooltip_window.Draw += new DrawToolTipEventHandler (tooltip_window_Draw);
tooltip_window.Popup += new PopupEventHandler (tooltip_window_Popup);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2232,7 +2232,7 @@ private void MouseLeftItem (TreeNode item)
private ToolTip ToolTipWindow {
get {
if (tooltip_window == null)
tooltip_window = new ToolTip ();
tooltip_window = new ToolTip (this);

return tooltip_window;
}
Expand Down