diff options
Diffstat (limited to 'bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt')
11 files changed, 112 insertions, 33 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java index 2cc864905f..7a0f1c534e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java @@ -1594,9 +1594,9 @@ public void setTextLimit (int limit) { OS.gtk_entry_set_max_length (entryHandle, limit); } -void setToolTipText (Shell shell, String string) { - shell.setToolTipText (entryHandle, string); - shell.setToolTipText (arrowHandle, string); +void setToolTipText (Shell shell, String newString, String oldString) { + shell.setToolTipText (entryHandle, newString, oldString); + shell.setToolTipText (arrowHandle, newString, oldString); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java index d0690dc1a8..b2f4dc538e 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java @@ -3140,12 +3140,12 @@ boolean setTabItemFocus (boolean next) { */ public void setToolTipText (String string) { checkWidget(); - toolTipText = string; - setToolTipText (_getShell (), string); + setToolTipText (_getShell (), string, toolTipText); + toolTipText = string; } -void setToolTipText (Shell shell, String string) { - shell.setToolTipText (eventHandle (), string); +void setToolTipText (Shell shell, String newString, String oldString) { + shell.setToolTipText (eventHandle (), newString, oldString); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java index 971d79db42..14f82458d4 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java @@ -171,6 +171,10 @@ public class Display extends Device { int /*long*/ menuPositionProc; Callback menuPositionCallback; + /* Tooltip size allocate callback */ + int /*long*/ sizeAllocateProc; + Callback sizeAllocateCallback; + /* Shell map callback */ int /*long*/ shellMapProc; Callback shellMapCallback; @@ -2195,7 +2199,11 @@ void initializeCallbacks () { menuPositionCallback = new Callback(this, "menuPositionProc", 5); menuPositionProc = menuPositionCallback.getAddress(); if (menuPositionProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); - + + sizeAllocateCallback = new Callback(this, "sizeAllocateProc", 3); + sizeAllocateProc = sizeAllocateCallback.getAddress(); + if (sizeAllocateProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); + shellMapCallback = new Callback(this, "shellMapProc", 3); shellMapProc = shellMapCallback.getAddress(); if (shellMapProc == 0) error (SWT.ERROR_NO_MORE_CALLBACKS); @@ -2829,6 +2837,10 @@ void releaseDisplay () { menuPositionCallback.dispose (); menuPositionCallback = null; menuPositionProc = 0; + /* Dispose the tooltip map callback */ + sizeAllocateCallback.dispose (); sizeAllocateCallback = null; + sizeAllocateProc = 0; + /* Dispose the shell map callback */ shellMapCallback.dispose (); shellMapCallback = null; shellMapProc = 0; @@ -3527,6 +3539,12 @@ int /*long*/ textCellDataProc (int /*long*/ tree_column, int /*long*/ cell, int return widget.textCellDataProc (tree_column, cell, tree_model, iter, data); } +int /*long*/ sizeAllocateProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { + Widget widget = getWidget (user_data); + if (widget == null) return 0; + return widget.sizeAllocateProc (handle, arg0, user_data); +} + int /*long*/ treeSelectionProc (int /*long*/ model, int /*long*/ path, int /*long*/ iter, int /*long*/ data) { Widget widget = getWidget (data); if (widget == null) return 0; diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java index eb54c250f3..f6c32ec429 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Shell.java @@ -100,7 +100,7 @@ import org.eclipse.swt.events.*; * @see SWT */ public class Shell extends Decorations { - int /*long*/ shellHandle, tooltipsHandle; + int /*long*/ shellHandle, tooltipsHandle, tooltipWindow; boolean mapped, moved, resized, opened; int oldX, oldY, oldWidth, oldHeight; int minWidth, minHeight; @@ -666,8 +666,8 @@ void fixShell (Shell newShell, Control control) { if (control == lastActive) setActiveControl (null); String toolTipText = control.toolTipText; if (toolTipText != null) { - control.setToolTipText (this, null); - control.setToolTipText (newShell, toolTipText); + control.setToolTipText (this, null, toolTipText); + control.setToolTipText (newShell, toolTipText, null); } } @@ -1494,6 +1494,13 @@ void showWidget () { if (vboxHandle != 0) OS.gtk_widget_show (vboxHandle); } +int /*long*/ sizeAllocateProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { + int [] x = new int [1], y = new int [1]; + OS.gdk_window_get_pointer (0, x, y, null); + OS.gtk_window_move (handle, x [0], y [0] + 16); + return 0; +} + boolean traverseEscape () { if (parent == null) return false; if (!isVisible () || !isEnabled ()) return false; @@ -1626,10 +1633,10 @@ void releaseWidget () { lastActive = null; } -void setToolTipText (int /*long*/ widget, String string) { +void setToolTipText (int /*long*/ widget, String newString, String oldString) { byte [] buffer = null; - if (string != null && string.length () > 0) { - buffer = Converter.wcsToMbcs (null, string, true); + if (newString != null && newString.length () > 0) { + buffer = Converter.wcsToMbcs (null, newString, true); } if (tooltipsHandle == 0) { tooltipsHandle = OS.gtk_tooltips_new (); @@ -1637,6 +1644,54 @@ void setToolTipText (int /*long*/ widget, String string) { OS.g_object_ref (tooltipsHandle); OS.gtk_object_sink (tooltipsHandle); } + + /* + * Feature in GTK. There is no API to position a tooltip. + * The fix is to connect to the size_allocate signal for + * the tooltip window and position it before it is mapped. + */ + OS.gtk_tooltips_force_window (tooltipsHandle); + int /*long*/ tipWindow = OS.GTK_TOOLTIPS_TIP_WINDOW (tooltipsHandle); + if (tipWindow != tooltipWindow) { + OS.g_signal_connect (tipWindow, OS.size_allocate, display.sizeAllocateProc, shellHandle); + tooltipWindow = tipWindow; + } OS.gtk_tooltips_set_tip (tooltipsHandle, widget, buffer, null); + + /* + * Bug in GTK. If the cursor is inside the window when a new + * tooltip is set and the old tooltip is null, the new tooltip + * is not displayed until the mouse enters the window. The + * fix is to cause and enter/leave event to happen by creating + * a temporary INPUT_ONLY GDK window. + */ + if ((OS.GTK_WIDGET_FLAGS (widget) & OS.GTK_REALIZED) == 0) return; + if ((OS.GTK_WIDGET_FLAGS (widget) & OS.GTK_VISIBLE) == 0) return; + if (oldString == null || oldString.length () == 0) { + if (newString != null && newString.length () != 0) { + int[] x = new int [1], y = new int [1]; + int /*long*/ window = OS.gdk_window_at_pointer (x, y); + if (window != 0) { + int /*long*/ [] user_data = new int /*long*/ [1]; + OS.gdk_window_get_user_data (window, user_data); + if (widget == user_data [0]) { + int /*long*/ parentHandle = OS.gtk_widget_get_parent (widget); + int /*long*/ parentWindow = OS.GTK_WIDGET_WINDOW (parentHandle); + GdkWindowAttr attributes = new GdkWindowAttr (); + attributes.width = OS.GTK_WIDGET_WIDTH (parentHandle); + attributes.height = OS.GTK_WIDGET_HEIGHT (parentHandle); + attributes.event_mask = (0xFFFFFFFF & ~OS.ExposureMask); + attributes.wclass = OS.GDK_INPUT_ONLY; + attributes.window_type = OS.GDK_WINDOW_CHILD; + int enterWindow = OS.gdk_window_new (parentWindow, attributes, OS.GDK_WA_X | OS.GDK_WA_Y); + if (enterWindow != 0) { + OS.gdk_window_raise (enterWindow); + OS.gdk_window_show (enterWindow); + OS.gdk_window_destroy (enterWindow); + } + } + } + } + } } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java index 7f7dbb1eff..b90ef36f27 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Table.java @@ -873,8 +873,8 @@ void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, De for (int i=0; i<columnCount; i++) { TableColumn column = columns [i]; if (column.toolTipText != null) { - column.setToolTipText(oldShell, null); - column.setToolTipText(newShell, column.toolTipText); + column.setToolTipText(oldShell, null, column.toolTipText); + column.setToolTipText(newShell, column.toolTipText, null); } } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java index 70dfd114ec..1784368e94 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableColumn.java @@ -579,13 +579,13 @@ public void setText (String string) { public void setToolTipText (String string) { checkWidget(); - toolTipText = string; Shell shell = parent._getShell (); - setToolTipText (shell, toolTipText); + setToolTipText (shell, string, toolTipText); + toolTipText = string; } -void setToolTipText (Shell shell, String string) { - shell.setToolTipText (buttonHandle, string); +void setToolTipText (Shell shell, String newString, String oldString) { + shell.setToolTipText (buttonHandle, newString, oldString); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java index 10ddc94c20..a0b5b91217 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java @@ -149,8 +149,8 @@ void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, De for (int i = 0; i < items.length; i++) { ToolItem item = items [i]; if (item.toolTipText != null) { - item.setToolTipText(oldShell, null); - item.setToolTipText(newShell, item.toolTipText); + item.setToolTipText(oldShell, null, item.toolTipText); + item.setToolTipText(newShell, item.toolTipText, null); } } } @@ -443,7 +443,9 @@ public void setToolTipText (String string) { Shell shell = _getShell (); ToolItem [] items = getItems (); for (int i = 0; i < items.length; i++) { - shell.setToolTipText (items [i].handle, string != null ? null : items [i].toolTipText); + String newString = string != null ? null : items [i].toolTipText; + String oldString = string == null ? null : items [i].toolTipText; + shell.setToolTipText (items [i].handle, newString, oldString); } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java index 69f98b5961..f1799adc56 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java @@ -998,15 +998,15 @@ public void setText (String string) { */ public void setToolTipText (String string) { checkWidget(); - toolTipText = string; if (parent.toolTipText == null) { Shell shell = parent._getShell (); - setToolTipText (shell, toolTipText); + setToolTipText (shell, string, toolTipText); } + toolTipText = string; } -void setToolTipText (Shell shell, String string) { - shell.setToolTipText (handle, string); +void setToolTipText (Shell shell, String newString, String oldString) { + shell.setToolTipText (handle, newString, oldString); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java index ae2dcc4f66..6225e02b2b 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Tree.java @@ -801,8 +801,8 @@ void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, De for (int i=0; i<columnCount; i++) { TreeColumn column = columns [i]; if (column.toolTipText != null) { - column.setToolTipText(oldShell, null); - column.setToolTipText(newShell, column.toolTipText); + column.setToolTipText(oldShell, null, column.toolTipText); + column.setToolTipText(newShell, column.toolTipText, null); } } } diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java index 643b815bd6..5ef61cb015 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TreeColumn.java @@ -569,13 +569,13 @@ public void setText (String string) { public void setToolTipText (String string) { checkWidget(); - toolTipText = string; Shell shell = parent._getShell (); - setToolTipText (shell, toolTipText); + setToolTipText (shell, string, toolTipText); + toolTipText = string; } -void setToolTipText (Shell shell, String string) { - shell.setToolTipText (buttonHandle, string); +void setToolTipText (Shell shell, String newString, String oldString) { + shell.setToolTipText (buttonHandle, newString, oldString); } /** diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java index f20099bdb7..b6525b7645 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java +++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Widget.java @@ -1326,6 +1326,10 @@ int /*long*/ shellMapProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ return 0; } +int /*long*/ sizeAllocateProc (int /*long*/ handle, int /*long*/ arg0, int /*long*/ user_data) { + return 0; +} + /** * Returns a string containing a concise, human-readable * description of the receiver. |