diff options
author | Silenio Quarti | 2013-01-21 20:01:26 +0000 |
---|---|---|
committer | Silenio Quarti | 2013-01-21 20:02:29 +0000 |
commit | d3b70aad7149876ba42093794d2909bb52409b12 (patch) | |
tree | c74cc726ef0873872246aabfe3aa1c5f12353496 /bundles/org.eclipse.swt | |
parent | fbb292af69fce7799a14de7c3256ae3196bbbc23 (diff) | |
download | eclipse.platform.swt-d3b70aad7149876ba42093794d2909bb52409b12.tar.gz eclipse.platform.swt-d3b70aad7149876ba42093794d2909bb52409b12.tar.xz eclipse.platform.swt-d3b70aad7149876ba42093794d2909bb52409b12.zip |
Diffstat (limited to 'bundles/org.eclipse.swt')
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 152aa3bc5f..d1a6cf1457 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 3afeaa2038..042a3ec9eb 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 0da8f6f6fe..a3ddc1e006 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) { |