Skip to content

Commit d0333fc

Browse files
Merge pull request #2110 from Unity-Technologies/unity-6000.1-mbe-fix-uum-79065
[6000.1] Make sure tooltip window handle is being destroyed when parent window/control is destroyed
2 parents ac153c2 + d526a86 commit d0333fc

File tree

11 files changed

+50
-28
lines changed

11 files changed

+50
-28
lines changed

mcs/class/System.Windows.Forms/System.Windows.Forms/DataGridView.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6552,7 +6552,7 @@ private Timer ToolTipTimer {
65526552
private ToolTip ToolTipWindow {
65536553
get {
65546554
if (tooltip_window == null)
6555-
tooltip_window = new ToolTip ();
6555+
tooltip_window = new ToolTip (this);
65566556

65576557
return tooltip_window;
65586558
}

mcs/class/System.Windows.Forms/System.Windows.Forms/FileDialog.cs

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,10 +2296,6 @@ public MWFFileView (MWFVFS vfs)
22962296

22972297
contextMenu = new ContextMenu ();
22982298

2299-
toolTip = new ToolTip ();
2300-
toolTip.InitialDelay = 300;
2301-
toolTip.ReshowDelay = 0;
2302-
23032299
// contextMenu
23042300

23052301
// View menu item
@@ -2458,6 +2454,18 @@ public string SelectedFilesString {
24582454
return selectedFilesString;
24592455
}
24602456
}
2457+
2458+
private ToolTip ToolTipWindow {
2459+
get {
2460+
if (toolTip == null) {
2461+
toolTip = new ToolTip(this);
2462+
toolTip.InitialDelay = 300;
2463+
toolTip.ReshowDelay = 0;
2464+
}
2465+
2466+
return toolTip;
2467+
}
2468+
}
24612469

24622470
public void PushDir ()
24632471
{
@@ -2891,8 +2899,8 @@ protected override void OnMouseMove (MouseEventArgs e)
28912899
if (currentItemIndex != oldItemIndexForToolTip) {
28922900
oldItemIndexForToolTip = currentItemIndex;
28932901

2894-
if (toolTip != null && toolTip.Active)
2895-
toolTip.Active = false;
2902+
if (ToolTipWindow.Active)
2903+
ToolTipWindow.Active = false;
28962904

28972905
FSEntry fsEntry = item.FSEntry;
28982906

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

2910-
toolTip.SetToolTip (this, output);
2918+
ToolTipWindow.SetToolTip (this, output);
29112919

2912-
toolTip.Active = true;
2920+
ToolTipWindow.Active = true;
29132921
}
29142922
} else
2915-
toolTip.Active = false;
2923+
ToolTipWindow.Active = false;
29162924

29172925
base.OnMouseMove (e);
29182926
}

mcs/class/System.Windows.Forms/System.Windows.Forms/InternalWindowManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1072,7 +1072,7 @@ public void ToolTipShow (bool only_refresh)
10721072
}
10731073

10741074
if (tooltip == null)
1075-
tooltip = new ToolTip.ToolTipWindow ();
1075+
tooltip = new ToolTip.ToolTipWindow (form);
10761076
else if (tooltip.Text == text && tooltip.Visible)
10771077
return;
10781078
else if (tooltip.Visible)

mcs/class/System.Windows.Forms/System.Windows.Forms/ListView.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,8 +271,6 @@ public ListView ()
271271
items_location = new Point [16];
272272
items_matrix_location = new ItemMatrixLocation [16];
273273
reordered_items_indices = new int [16];
274-
item_tooltip = new ToolTip ();
275-
item_tooltip.Active = false;
276274
insertion_mark = new ListViewInsertionMark (this);
277275

278276
InternalBorderStyle = BorderStyle.Fixed3D;
@@ -316,7 +314,7 @@ public ListView ()
316314
}
317315
#endregion // Public Constructors
318316

319-
#region Private Internal Properties
317+
#region Private & Internal Properties
320318
internal Size CheckBoxSize {
321319
get {
322320
if (this.check_boxes) {
@@ -377,6 +375,16 @@ internal ColumnHeader EnteredColumnHeader {
377375
return header_control.EnteredColumnHeader;
378376
}
379377
}
378+
379+
private ToolTip ToolTipWindow {
380+
get {
381+
if (item_tooltip == null) {
382+
item_tooltip = new ToolTip(this);
383+
item_tooltip.Active = false;
384+
}
385+
return item_tooltip;
386+
}
387+
}
380388
#endregion // Private Internal Properties
381389

382390
#region Protected Properties
@@ -815,7 +823,7 @@ public bool ShowItemToolTips {
815823
}
816824
set {
817825
show_item_tooltips = value;
818-
item_tooltip.Active = false;
826+
ToolTipWindow.Active = false;
819827
}
820828
}
821829

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

27802788
if (owner.ShowItemToolTips) {
27812789
if (item == null) {
2782-
owner.item_tooltip.Active = false;
2790+
owner.ToolTipWindow.Active = false;
27832791
prev_tooltip_item = null;
27842792
} else if (item != prev_tooltip_item && item.ToolTipText.Length > 0) {
2785-
owner.item_tooltip.Active = true;
2786-
owner.item_tooltip.SetToolTip (owner, item.ToolTipText);
2793+
owner.ToolTipWindow.Active = true;
2794+
owner.ToolTipWindow.SetToolTip (owner, item.ToolTipText);
27872795
prev_tooltip_item = item;
27882796
}
27892797
}

mcs/class/System.Windows.Forms/System.Windows.Forms/StatusBar.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ private Timer ToolTipTimer {
466466
private ToolTip ToolTipWindow {
467467
get {
468468
if (tooltip_window == null)
469-
tooltip_window = new ToolTip ();
469+
tooltip_window = new ToolTip (this);
470470

471471
return tooltip_window;
472472
}

mcs/class/System.Windows.Forms/System.Windows.Forms/TabControl.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ void SetToolTip (string text)
15091509
}
15101510

15111511
if (tooltip == null) {
1512-
tooltip = new ToolTip ();
1512+
tooltip = new ToolTip (this);
15131513
tooltip_timer = new Timer ();
15141514
tooltip_timer.Tick += new EventHandler (ToolTipTimerTick);
15151515
}

mcs/class/System.Windows.Forms/System.Windows.Forms/ToolBar.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ private void ToolBar_MouseHover (object sender, EventArgs e)
899899
return;
900900

901901
if (tip_window == null)
902-
tip_window = new ToolTip ();
902+
tip_window = new ToolTip (this);
903903

904904
ToolBarItem item = ItemAtPoint (PointToClient (Control.MousePosition));
905905
current_item = item;

mcs/class/System.Windows.Forms/System.Windows.Forms/ToolStrip.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1572,7 +1572,7 @@ private Timer ToolTipTimer {
15721572
private ToolTip ToolTipWindow {
15731573
get {
15741574
if (tooltip_window == null)
1575-
tooltip_window = new ToolTip ();
1575+
tooltip_window = new ToolTip (this);
15761576

15771577
return tooltip_window;
15781578
}

mcs/class/System.Windows.Forms/System.Windows.Forms/ToolStripTextBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ private Timer ToolTipTimer {
568568
private ToolTip ToolTipWindow {
569569
get {
570570
if (tooltip_window == null)
571-
tooltip_window = new ToolTip ();
571+
tooltip_window = new ToolTip (this);
572572

573573
return tooltip_window;
574574
}

mcs/class/System.Windows.Forms/System.Windows.Forms/ToolTip.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ internal class ToolTipWindow : Control {
7575
#endregion // ToolTipWindow Class Local Variables
7676

7777
#region ToolTipWindow Class Constructor
78-
internal ToolTipWindow() {
78+
internal ToolTipWindow(Control owner = null) {
7979
Visible = false;
8080
Size = new Size(100, 20);
8181
ForeColor = ThemeEngine.Current.ColorInfoText;
@@ -94,9 +94,15 @@ internal ToolTipWindow() {
9494
} else
9595
SetStyle (ControlStyles.Opaque, true);
9696

97-
SetTopLevel (true);
97+
if (owner == null) {
98+
SetTopLevel (true);
99+
} else {
100+
SetTopLevel (false);
101+
owner.Controls.Add(this);
102+
}
98103
}
99104

105+
100106
#endregion // ToolTipWindow Class Constructor
101107

102108
#region ToolTipWindow Class Protected Instance Methods
@@ -288,7 +294,7 @@ internal event PopupEventHandler UnPopup {
288294
#endregion // ToolTipWindow Class
289295

290296
#region Public Constructors & Destructors
291-
public ToolTip() {
297+
public ToolTip(Control owner = null) {
292298

293299
// Defaults from MS
294300
is_active = true;
@@ -307,7 +313,7 @@ public ToolTip() {
307313
tooltip_strings = new Hashtable(5);
308314
controls = new ArrayList(5);
309315

310-
tooltip_window = new ToolTipWindow();
316+
tooltip_window = new ToolTipWindow(owner);
311317
tooltip_window.MouseLeave += new EventHandler(control_MouseLeave);
312318
tooltip_window.Draw += new DrawToolTipEventHandler (tooltip_window_Draw);
313319
tooltip_window.Popup += new PopupEventHandler (tooltip_window_Popup);

0 commit comments

Comments
 (0)