aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSilenio Quarti2013-01-21 15:01:26 (EST)
committerCarolyn MacLeod2013-04-09 10:49:25 (EDT)
commit03196a964db2a2dfe82244a39d3591939a07fb8a (patch)
treefe54c32804f5962f2eebbdb6554747f922742215
parent7146453c875fe9ea3465402a156cc7acc15088c8 (diff)
downloadeclipse.platform.swt-03196a964db2a2dfe82244a39d3591939a07fb8a.zip
eclipse.platform.swt-03196a964db2a2dfe82244a39d3591939a07fb8a.tar.gz
eclipse.platform.swt-03196a964db2a2dfe82244a39d3591939a07fb8a.tar.bz2
Bug 398046 - ToolTip takes a very long time to show when tooltip message is very long
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java9
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java70
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolTip.java31
3 files changed, 97 insertions, 13 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java
index 567793c..ff810ab 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Composite.java
@@ -1167,6 +1167,15 @@ String toolTipText (NMTTDISPINFO hdr) {
if (toolTip != null) {
string = toolTip.message;
if (string == null || string.length () == 0) string = " ";
+ /*
+ * Bug in Windows. On Windows 7, tool tips hang when displaying large
+ * unwrapped strings. The fix is to wrap the string ourselves.
+ */
+ if (!OS.IsWinCE && OS.WIN32_VERSION >= OS.VERSION (6, 0)) {
+ if (string.length () > TOOLTIP_LIMIT / 4) {
+ string = display.wrapText (string, handle, toolTip.getWidth ());
+ }
+ }
}
return string;
}
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
index 3afeaa2..042a3ec 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/Display.java
@@ -4992,6 +4992,76 @@ long /*int*/ windowProc (long /*int*/ hwnd, long /*int*/ msg, long /*int*/ wPara
return OS.DefWindowProc (hwnd, (int)/*64*/msg, wParam, lParam);
}
+int textWidth (String text, long /*int*/ handle) {
+ long /*int*/ oldFont = 0;
+ RECT rect = new RECT ();
+ long /*int*/ hDC = OS.GetDC (handle);
+ long /*int*/ newFont = OS.SendMessage (handle, OS.WM_GETFONT, 0, 0);
+ if (newFont != 0) oldFont = OS.SelectObject (hDC, newFont);
+ int flags = OS.DT_CALCRECT | OS.DT_SINGLELINE | OS.DT_NOPREFIX;
+ TCHAR buffer = new TCHAR(0, text, false);
+ OS.DrawText (hDC, buffer, buffer.length (), rect, flags);
+ if (newFont != 0) OS.SelectObject (hDC, oldFont);
+ OS.ReleaseDC (handle, hDC);
+ return (rect.right - rect.left);
+}
+
+String wrapText (String text, long /*int*/ handle, int width) {
+ String Lf = "\r\n"; //$NON-NLS-1$
+ text = withCrLf (text);
+ int length = text.length ();
+ if (width <= 0 || length == 0 || length == 1) return text;
+ StringBuffer result = new StringBuffer ();
+ int lineStart = 0, lineEnd = 0;
+ while (lineStart < length) {
+ lineEnd = text.indexOf (Lf, lineStart);
+ boolean noLf = lineEnd == -1;
+ if (noLf) lineEnd = length;
+ int nextStart = lineEnd + Lf.length ();
+ while (lineEnd > lineStart + 1 && Compatibility.isWhitespace (text.charAt (lineEnd - 1))) {
+ lineEnd--;
+ }
+ int wordStart = lineStart, wordEnd = lineStart;
+ int i = lineStart;
+ while (i < lineEnd) {
+ int lastStart = wordStart, lastEnd = wordEnd;
+ wordStart = i;
+ while (i < lineEnd && !Compatibility.isWhitespace (text.charAt (i))) {
+ i++;
+ }
+ wordEnd = i - 1;
+ String line = text.substring (lineStart, wordEnd + 1);
+ int lineWidth = textWidth (line, handle);
+ while (i < lineEnd && Compatibility.isWhitespace (text.charAt (i))) {
+ i++;
+ }
+ if (lineWidth > width) {
+ if (lastStart == wordStart) {
+ while (wordStart < wordEnd) {
+ line = text.substring (lineStart, wordStart + 1);
+ lineWidth = textWidth (line, handle);
+ if (lineWidth >= width) break;
+ wordStart++;
+ }
+ if (wordStart == lastStart) wordStart++;
+ lastEnd = wordStart - 1;
+ }
+ line = text.substring (lineStart, lastEnd + 1);
+ result.append (line); result.append (Lf);
+ i = wordStart; lineStart = wordStart; wordEnd = wordStart;
+ }
+ }
+ if (lineStart < lineEnd) {
+ result.append (text.substring (lineStart, lineEnd));
+ }
+ if (!noLf) {
+ result.append (Lf);
+ }
+ lineStart = nextStart;
+ }
+ return result.toString ();
+}
+
static String withCrLf (String string) {
/* If the string is empty, return the string. */
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolTip.java b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolTip.java
index 0da8f6f..a3ddc1e 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolTip.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/win32/org/eclipse/swt/widgets/ToolTip.java
@@ -226,6 +226,23 @@ public boolean getVisible () {
return false;
}
+int getWidth () {
+ long /*int*/ hwnd = parent.handle;
+ int maxWidth = 0;
+ if (OS.IsWinCE || OS.WIN32_VERSION < OS.VERSION (4, 10)) {
+ RECT rect = new RECT ();
+ OS.SystemParametersInfo (OS.SPI_GETWORKAREA, 0, rect, 0);
+ maxWidth = rect.right - rect.left;
+ } else {
+ long /*int*/ hmonitor = OS.MonitorFromWindow (hwnd, OS.MONITOR_DEFAULTTONEAREST);
+ MONITORINFO lpmi = new MONITORINFO ();
+ lpmi.cbSize = MONITORINFO.sizeof;
+ OS.GetMonitorInfo (hmonitor, lpmi);
+ maxWidth = lpmi.rcWork_right - lpmi.rcWork_left;
+ }
+ return maxWidth /= 4;
+}
+
long /*int*/ hwndToolTip () {
return (style & SWT.BALLOON) != 0 ? parent.balloonTipHandle () : parent.toolTipHandle ();
}
@@ -459,19 +476,7 @@ public void setVisible (boolean visible) {
} else {
shell.setToolTipTitle (hwndToolTip, null, 0);
}
- int maxWidth = 0;
- if (OS.IsWinCE || OS.WIN32_VERSION < OS.VERSION (4, 10)) {
- RECT rect = new RECT ();
- OS.SystemParametersInfo (OS.SPI_GETWORKAREA, 0, rect, 0);
- maxWidth = (rect.right - rect.left) / 4;
- } else {
- long /*int*/ hmonitor = OS.MonitorFromWindow (hwnd, OS.MONITOR_DEFAULTTONEAREST);
- MONITORINFO lpmi = new MONITORINFO ();
- lpmi.cbSize = MONITORINFO.sizeof;
- OS.GetMonitorInfo (hmonitor, lpmi);
- maxWidth = (lpmi.rcWork_right - lpmi.rcWork_left) / 4;
- }
- OS.SendMessage (hwndToolTip, OS.TTM_SETMAXTIPWIDTH, 0, maxWidth);
+ OS.SendMessage (hwndToolTip, OS.TTM_SETMAXTIPWIDTH, 0, getWidth ());
if (visible) {
int nX = x, nY = y;
if (!hasLocation) {