Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java2
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolBar.java32
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/ToolItem.java26
3 files changed, 19 insertions, 41 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
index 2eaba195c0..9b1827f5c6 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/org/eclipse/swt/internal/gtk/OS.java
@@ -375,6 +375,8 @@ public class OS extends C {
public static final int GTK_TOOLBAR_CHILD_BUTTON = 0x1;
public static final int GTK_TOOLBAR_CHILD_RADIOBUTTON = 0x3;
public static final int GTK_TOOLBAR_CHILD_TOGGLEBUTTON = 0x2;
+ public static final int GTK_TOOLBAR_ICONS = 0;
+ public static final int GTK_TOOLBAR_TEXT = 1;
public static final int GTK_TOOLBAR_BOTH = 2;
public static final int GTK_TOOLBAR_BOTH_HORIZ = 3;
public static final int GTK_TREE_VIEW_COLUMN_GROW_ONLY = 0;
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 eacee0acc1..e470cd5ff9 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
@@ -138,19 +138,6 @@ void createHandle (int index) {
byte [] swt_toolbar_flat = Converter.wcsToMbcs (null, "swt-toolbar-flat", true);
OS.gtk_widget_set_name (handle, swt_toolbar_flat);
}
- /*
- * Feature in GTK. When the toolItems contain only image,
- * then GTK considers the toolItem to have both label
- * and image and thus, it sets an empty label. Due to
- * this, the toolItem appear bigger than the required size.
- * The fix is to modify the style which doesn't require the
- * label. If SWT.RIGHT is set, then toolItem will set the
- * "is_important" flag in order to display the text horizontally.
- * If any of the toolItem has set non-empty text, then the
- * the style shall be changed back to default in order to
- * display the text vertically.
- */
- OS.gtk_toolbar_set_style (handle, OS.GTK_TOOLBAR_BOTH_HORIZ);
}
public Point computeSize (int wHint, int hHint, boolean changed) {
@@ -509,15 +496,28 @@ boolean mnemonicMatch (char key) {
void relayout () {
ToolItem [] items = getItems ();
- boolean hasTextItems = false;
+ boolean hasText = false, hasImage = false;
for (int i=0; i<items.length; i++) {
ToolItem item = items [i];
if (item != null) {
item.resizeControl ();
- hasTextItems |= item.hasText;
+ hasText |= item.text != null && item.text.length() > 0;
+ hasImage |= item.image != null;
+ }
+ }
+ int type = OS.GTK_TOOLBAR_ICONS;
+ if (hasText && hasImage) {
+ if ((style & SWT.RIGHT) != 0) {
+ type = OS.GTK_TOOLBAR_BOTH_HORIZ;
+ } else {
+ type = OS.GTK_TOOLBAR_BOTH;
}
+ } else if (hasText) {
+ type = OS.GTK_TOOLBAR_TEXT;
+ } else if (hasImage) {
+ type = OS.GTK_TOOLBAR_ICONS;
}
- if (!hasTextItems) OS.gtk_toolbar_set_style (handle, OS.GTK_TOOLBAR_BOTH_HORIZ);
+ OS.gtk_toolbar_set_style (handle, type);
}
void releaseChildren (boolean destroy) {
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 fd5e94e36d..65cafc222e 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
@@ -44,7 +44,7 @@ public class ToolItem extends Item {
Control control;
Image hotImage, disabledImage;
String toolTipText;
- boolean drawHotImage, hasText;
+ boolean drawHotImage;
/**
* Constructs a new instance of this class given its parent
@@ -1096,30 +1096,6 @@ public void setText (String string) {
}
}
OS.gtk_tool_button_set_label (handle, buffer);
- /*
- * Feature in GTK. Toolitems with only image appear larger
- * than the preferred size. The fix is to set the style as
- * TOOLBAR_BOTH_HORIZ. If any of the child toolItem is set
- * text, then the style shall be set back to default.
- */
- if (string.length() != 0) {
- hasText = true;
- if ((parent.style & SWT.RIGHT) == 0) OS.gtk_toolbar_set_style (parent.handle, OS.GTK_TOOLBAR_BOTH);
- } else {
- /*
- * If the toolbar has any item containing text, then the style
- * should be TOOLBAR_BOTH. Otherwise, it should be set back to
- * BOTH_HORIZ in order to prevent the larger size consumed by item.
- */
- hasText = false;
- ToolItem[] items = parent._getItems();
- boolean hasTextItems = false;
- for (int i=0; i<items.length; i++) {
- ToolItem item = items[i];
- if (item != null) hasTextItems |= item.hasText;
- }
- if (!hasTextItems) OS.gtk_toolbar_set_style (parent.handle, OS.GTK_TOOLBAR_BOTH_HORIZ);
- }
if ((style & SWT.DROP_DOWN) != 0) {
proxyMenuItem = 0;
proxyMenuItem = OS.gtk_tool_item_retrieve_proxy_menu_item (handle);

Back to the top