Skip to content

Commit 9d3eb8a

Browse files
committed
Always manage custom tooltip in Tree in Win32 #62
The commit allows to always create custom tooltip handles in the Tree while creating items. The is necessary to always fit the tooltips inside a single monitor as there can be freezing problems while using per-monitor awareness if the tooltip spans over multiple monitors. contributes to #62 and #127
1 parent 4df99ba commit 9d3eb8a

File tree

1 file changed

+18
-39
lines changed
  • bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets

1 file changed

+18
-39
lines changed

bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Tree.java

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ void _addListener (int eventType, Listener listener) {
211211
case SWT.PaintItem: {
212212
customDraw = true;
213213
style |= SWT.DOUBLE_BUFFERED;
214-
if (isCustomToolTip ()) createItemToolTips ();
214+
createItemToolTips ();
215215
OS.SendMessage (handle, OS.TVM_SETSCROLLTIME, 0, 0);
216216
int bits = OS.GetWindowLong (handle, OS.GWL_STYLE);
217217
if (eventType == SWT.MeasureItem) {
@@ -2200,7 +2200,7 @@ void createItem (TreeItem item, long hParent, long hInsertAfter, long hItem) {
22002200
}
22012201
}
22022202
}
2203-
2203+
createItemToolTips ();
22042204
/*
22052205
Note: Don't update scrollbars when drawing is disabled.
22062206
This gives significant improvement for bulk insert scenarios.
@@ -2799,20 +2799,16 @@ boolean findCell (int x, int y, TreeItem [] item, int [] index, RECT [] cellRect
27992799
} else {
28002800
cellRect [0].right = Math.min (cellRect [0].right, rect.right);
28012801
if (OS.PtInRect (cellRect [0], pt)) {
2802-
if (isCustomToolTip ()) {
2803-
int state = (int)OS.SendMessage (handle, OS.TVM_GETITEMSTATE, lpht.hItem, OS.TVIS_SELECTED);
2804-
int detail = (state & OS.TVIS_SELECTED) != 0 ? SWT.SELECTED : 0;
2805-
Event event = sendMeasureItemEvent (item [0], order [index [0]], hDC, detail);
2806-
if (isDisposed () || item [0].isDisposed ()) break;
2807-
Rectangle boundsInPixels = DPIUtil.scaleUp(event.getBounds(), getZoom());
2808-
itemRect [0] = new RECT ();
2809-
itemRect [0].left = boundsInPixels.x;
2810-
itemRect [0].right = boundsInPixels.x + boundsInPixels.width;
2811-
itemRect [0].top = boundsInPixels.y;
2812-
itemRect [0].bottom = boundsInPixels.y + boundsInPixels.height;
2813-
} else {
2814-
itemRect [0] = item [0].getBounds (order [index [0]], true, false, false, false, false, hDC);
2815-
}
2802+
int state = (int)OS.SendMessage (handle, OS.TVM_GETITEMSTATE, lpht.hItem, OS.TVIS_SELECTED);
2803+
int detail = (state & OS.TVIS_SELECTED) != 0 ? SWT.SELECTED : 0;
2804+
Event event = sendMeasureItemEvent (item [0], order [index [0]], hDC, detail);
2805+
if (isDisposed () || item [0].isDisposed ()) break;
2806+
Rectangle boundsInPixels = DPIUtil.scaleUp(event.getBounds(), getZoom());
2807+
itemRect [0] = new RECT ();
2808+
itemRect [0].left = boundsInPixels.x;
2809+
itemRect [0].right = boundsInPixels.x + boundsInPixels.width;
2810+
itemRect [0].top = boundsInPixels.y;
2811+
itemRect [0].bottom = boundsInPixels.y + boundsInPixels.height;
28162812
if (itemRect [0].right > cellRect [0].right) found = true;
28172813
quit = true;
28182814
}
@@ -3837,10 +3833,6 @@ public int indexOf (TreeItem item) {
38373833
return hItem == 0 ? -1 : findIndex (hItem, item.handle);
38383834
}
38393835

3840-
boolean isCustomToolTip () {
3841-
return hooks (SWT.MeasureItem);
3842-
}
3843-
38443836
boolean isItemSelected (NMTVCUSTOMDRAW nmcd) {
38453837
boolean selected = false;
38463838
if (OS.IsWindowEnabled (handle)) {
@@ -5644,16 +5636,7 @@ String toolTipText (NMTTDISPINFO hdr) {
56445636
TreeItem [] item = new TreeItem [1];
56455637
RECT [] cellRect = new RECT [1], itemRect = new RECT [1];
56465638
if (findCell (pt.x, pt.y, item, index, cellRect, itemRect)) {
5647-
String text = null;
5648-
if (index [0] == 0) {
5649-
text = item [0].text;
5650-
} else {
5651-
String[] strings = item [0].strings;
5652-
if (strings != null) text = strings [index [0]];
5653-
}
5654-
//TEMPORARY CODE
5655-
if (isCustomToolTip ()) text = " ";
5656-
if (text != null) return text;
5639+
return " ";
56575640
}
56585641
}
56595642
return super.toolTipText (hdr);
@@ -8157,8 +8140,7 @@ LRESULT wmNotifyToolTip (NMHDR hdr, long wParam, long lParam) {
81578140
if (findCell (pt.x, pt.y, item, index, cellRect, itemRect)) {
81588141
RECT toolRect = toolTipRect (itemRect [0]);
81598142
OS.MapWindowPoints (handle, 0, toolRect, 2);
8160-
int flags = OS.SWP_NOACTIVATE | OS.SWP_NOZORDER | OS.SWP_NOSIZE;
8161-
if (isCustomToolTip ()) flags &= ~OS.SWP_NOSIZE;
8143+
int flags = OS.SWP_NOACTIVATE | OS.SWP_NOZORDER;
81628144
// Retrieve the monitor containing the cursor position, as tool tip placement
81638145
// must occur on the same monitor to avoid potential infinite loops. When a tool tip
81648146
// appears on a different monitor than the cursor, the operating system may
@@ -8225,13 +8207,10 @@ private Rectangle getContainingMonitorBoundsInMultiZoomCoordinateSystem(MonitorA
82258207
LRESULT wmNotifyToolTip (NMTTCUSTOMDRAW nmcd, long lParam) {
82268208
switch (nmcd.dwDrawStage) {
82278209
case OS.CDDS_PREPAINT: {
8228-
if (isCustomToolTip ()) {
8229-
//TEMPORARY CODE
8230-
//nmcd.uDrawFlags |= OS.DT_CALCRECT;
8231-
//OS.MoveMemory (lParam, nmcd, NMTTCUSTOMDRAW.sizeof);
8232-
return new LRESULT (OS.CDRF_NOTIFYPOSTPAINT | OS.CDRF_NEWFONT);
8233-
}
8234-
break;
8210+
//TEMPORARY CODE
8211+
//nmcd.uDrawFlags |= OS.DT_CALCRECT;
8212+
//OS.MoveMemory (lParam, nmcd, NMTTCUSTOMDRAW.sizeof);
8213+
return new LRESULT (OS.CDRF_NOTIFYPOSTPAINT | OS.CDRF_NEWFONT);
82358214
}
82368215
case OS.CDDS_POSTPAINT: {
82378216
if (OS.SendMessage (itemToolTipHandle, OS.TTM_GETCURRENTTOOL, 0, 0) != 0) {

0 commit comments

Comments
 (0)