diff options
| author | Arun Thondapu | 2012-02-27 15:21:04 +0000 |
|---|---|---|
| committer | Bogdan Gheorghe | 2012-04-26 21:00:10 +0000 |
| commit | 1c6100db3e7e2869dd9939a388c01ffe02266ae6 (patch) | |
| tree | 6b6ae0d31f19d4481470109fd1ecc6ebc93a88f9 | |
| parent | 9cc72cd00c181250b1f51b95a0528a6b993c1ed9 (diff) | |
| download | eclipse.platform.ui-1c6100db3e7e2869dd9939a388c01ffe02266ae6.tar.gz eclipse.platform.ui-1c6100db3e7e2869dd9939a388c01ffe02266ae6.tar.xz eclipse.platform.ui-1c6100db3e7e2869dd9939a388c01ffe02266ae6.zip | |
Bug 46025 - [Widgets] Toolbar does not support WRAP style (initial patch)
9 files changed, 837 insertions, 227 deletions
diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c index 53b22d110da..8767d6e3cff 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os.c @@ -10833,6 +10833,30 @@ JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1menu_1shell_1set_1take_1focus) } #endif +#ifndef NO__1gtk_1menu_1tool_1button_1new +JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1menu_1tool_1button_1new) + (JNIEnv *env, jclass that, jintLong arg0, jbyteArray arg1) +{ + jbyte *lparg1=NULL; + jintLong rc = 0; + OS_NATIVE_ENTER(env, that, _1gtk_1menu_1tool_1button_1new_FUNC); + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; +/* + rc = (jintLong)gtk_menu_tool_button_new(arg0, lparg1); +*/ + { + OS_LOAD_FUNCTION(fp, gtk_menu_tool_button_new) + if (fp) { + rc = (jintLong)((jintLong (CALLING_CONVENTION*)(jintLong, jbyte *))fp)(arg0, lparg1); + } + } +fail: + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); + OS_NATIVE_EXIT(env, that, _1gtk_1menu_1tool_1button_1new_FUNC); + return rc; +} +#endif + #ifndef NO__1gtk_1message_1dialog_1new JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1message_1dialog_1new) (JNIEnv *env, jclass that, jintLong arg0, jint arg1, jint arg2, jint arg3, jbyteArray arg4) @@ -13146,6 +13170,28 @@ JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1separator_1menu_1item_1new) } #endif +#ifndef NO__1gtk_1separator_1tool_1item_1new +JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1separator_1tool_1item_1new) + (JNIEnv *env, jclass that) +{ + jintLong rc = 0; + OS_NATIVE_ENTER(env, that, _1gtk_1separator_1tool_1item_1new_FUNC); + rc = (jintLong)gtk_separator_tool_item_new(); + OS_NATIVE_EXIT(env, that, _1gtk_1separator_1tool_1item_1new_FUNC); + return rc; +} +#endif + +#ifndef NO__1gtk_1separator_1tool_1item_1set_1draw +JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1separator_1tool_1item_1set_1draw) + (JNIEnv *env, jclass that, jintLong arg0, jboolean arg1) +{ + OS_NATIVE_ENTER(env, that, _1gtk_1separator_1tool_1item_1set_1draw_FUNC); + gtk_separator_tool_item_set_draw((GtkSeparatorToolItem *)arg0, (gboolean)arg1); + OS_NATIVE_EXIT(env, that, _1gtk_1separator_1tool_1item_1set_1draw_FUNC); +} +#endif + #ifndef NO__1gtk_1set_1locale JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1set_1locale) (JNIEnv *env, jclass that) @@ -14373,6 +14419,162 @@ JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1toggle_1button_1set_1mode) } #endif +#ifndef NO__1gtk_1toggle_1tool_1button_1get_1active +JNIEXPORT jboolean JNICALL OS_NATIVE(_1gtk_1toggle_1tool_1button_1get_1active) + (JNIEnv *env, jclass that, jintLong arg0) +{ + jboolean rc = 0; + OS_NATIVE_ENTER(env, that, _1gtk_1toggle_1tool_1button_1get_1active_FUNC); + rc = (jboolean)gtk_toggle_tool_button_get_active((GtkToggleToolButton *)arg0); + OS_NATIVE_EXIT(env, that, _1gtk_1toggle_1tool_1button_1get_1active_FUNC); + return rc; +} +#endif + +#ifndef NO__1gtk_1toggle_1tool_1button_1new +JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1toggle_1tool_1button_1new) + (JNIEnv *env, jclass that) +{ + jintLong rc = 0; + OS_NATIVE_ENTER(env, that, _1gtk_1toggle_1tool_1button_1new_FUNC); + rc = (jintLong)gtk_toggle_tool_button_new(); + OS_NATIVE_EXIT(env, that, _1gtk_1toggle_1tool_1button_1new_FUNC); + return rc; +} +#endif + +#ifndef NO__1gtk_1toggle_1tool_1button_1set_1active +JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1toggle_1tool_1button_1set_1active) + (JNIEnv *env, jclass that, jintLong arg0, jboolean arg1) +{ + OS_NATIVE_ENTER(env, that, _1gtk_1toggle_1tool_1button_1set_1active_FUNC); + gtk_toggle_tool_button_set_active((GtkToggleToolButton *)arg0, (gboolean)arg1); + OS_NATIVE_EXIT(env, that, _1gtk_1toggle_1tool_1button_1set_1active_FUNC); +} +#endif + +#ifndef NO__1gtk_1tool_1button_1new +JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1tool_1button_1new) + (JNIEnv *env, jclass that, jintLong arg0, jbyteArray arg1) +{ + jbyte *lparg1=NULL; + jintLong rc = 0; + OS_NATIVE_ENTER(env, that, _1gtk_1tool_1button_1new_FUNC); + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; + rc = (jintLong)gtk_tool_button_new((GtkWidget *)arg0, (const gchar *)lparg1); +fail: + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); + OS_NATIVE_EXIT(env, that, _1gtk_1tool_1button_1new_FUNC); + return rc; +} +#endif + +#ifndef NO__1gtk_1tool_1button_1set_1icon_1widget +JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1tool_1button_1set_1icon_1widget) + (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1) +{ + OS_NATIVE_ENTER(env, that, _1gtk_1tool_1button_1set_1icon_1widget_FUNC); + gtk_tool_button_set_icon_widget((GtkToolButton *)arg0, (GtkWidget *)arg1); + OS_NATIVE_EXIT(env, that, _1gtk_1tool_1button_1set_1icon_1widget_FUNC); +} +#endif + +#ifndef NO__1gtk_1tool_1button_1set_1label +JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1tool_1button_1set_1label) + (JNIEnv *env, jclass that, jintLong arg0, jbyteArray arg1) +{ + jbyte *lparg1=NULL; + OS_NATIVE_ENTER(env, that, _1gtk_1tool_1button_1set_1label_FUNC); + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; + gtk_tool_button_set_label((GtkToolButton *)arg0, (const gchar *)lparg1); +fail: + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); + OS_NATIVE_EXIT(env, that, _1gtk_1tool_1button_1set_1label_FUNC); +} +#endif + +#ifndef NO__1gtk_1tool_1button_1set_1label_1widget +JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1tool_1button_1set_1label_1widget) + (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1) +{ + OS_NATIVE_ENTER(env, that, _1gtk_1tool_1button_1set_1label_1widget_FUNC); + gtk_tool_button_set_label_widget((GtkToolButton *)arg0, (GtkWidget *)arg1); + OS_NATIVE_EXIT(env, that, _1gtk_1tool_1button_1set_1label_1widget_FUNC); +} +#endif + +#ifndef NO__1gtk_1tool_1button_1set_1use_1underline +JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1tool_1button_1set_1use_1underline) + (JNIEnv *env, jclass that, jintLong arg0, jboolean arg1) +{ + OS_NATIVE_ENTER(env, that, _1gtk_1tool_1button_1set_1use_1underline_FUNC); + gtk_tool_button_set_use_underline((GtkToolButton *)arg0, (gboolean)arg1); + OS_NATIVE_EXIT(env, that, _1gtk_1tool_1button_1set_1use_1underline_FUNC); +} +#endif + +#ifndef NO__1gtk_1tool_1item_1get_1proxy_1menu_1item +JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1tool_1item_1get_1proxy_1menu_1item) + (JNIEnv *env, jclass that, jintLong arg0, jbyteArray arg1) +{ + jbyte *lparg1=NULL; + jintLong rc = 0; + OS_NATIVE_ENTER(env, that, _1gtk_1tool_1item_1get_1proxy_1menu_1item_FUNC); + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; + rc = (jintLong)gtk_tool_item_get_proxy_menu_item((GtkToolItem *)arg0, (const gchar *)lparg1); +fail: + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); + OS_NATIVE_EXIT(env, that, _1gtk_1tool_1item_1get_1proxy_1menu_1item_FUNC); + return rc; +} +#endif + +#ifndef NO__1gtk_1tool_1item_1retrieve_1proxy_1menu_1item +JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1tool_1item_1retrieve_1proxy_1menu_1item) + (JNIEnv *env, jclass that, jintLong arg0) +{ + jintLong rc = 0; + OS_NATIVE_ENTER(env, that, _1gtk_1tool_1item_1retrieve_1proxy_1menu_1item_FUNC); + rc = (jintLong)gtk_tool_item_retrieve_proxy_menu_item((GtkToolItem *)arg0); + OS_NATIVE_EXIT(env, that, _1gtk_1tool_1item_1retrieve_1proxy_1menu_1item_FUNC); + return rc; +} +#endif + +#ifndef NO__1gtk_1tool_1item_1set_1is_1important +JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1tool_1item_1set_1is_1important) + (JNIEnv *env, jclass that, jintLong arg0, jboolean arg1) +{ + OS_NATIVE_ENTER(env, that, _1gtk_1tool_1item_1set_1is_1important_FUNC); + gtk_tool_item_set_is_important((GtkToolItem *)arg0, (gboolean)arg1); + OS_NATIVE_EXIT(env, that, _1gtk_1tool_1item_1set_1is_1important_FUNC); +} +#endif + +#ifndef NO__1gtk_1tool_1item_1set_1proxy_1menu_1item +JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1tool_1item_1set_1proxy_1menu_1item) + (JNIEnv *env, jclass that, jintLong arg0, jbyteArray arg1, jintLong arg2) +{ + jbyte *lparg1=NULL; + OS_NATIVE_ENTER(env, that, _1gtk_1tool_1item_1set_1proxy_1menu_1item_FUNC); + if (arg1) if ((lparg1 = (*env)->GetByteArrayElements(env, arg1, NULL)) == NULL) goto fail; + gtk_tool_item_set_proxy_menu_item((GtkToolItem *)arg0, (const gchar *)lparg1, (GtkWidget *)arg2); +fail: + if (arg1 && lparg1) (*env)->ReleaseByteArrayElements(env, arg1, lparg1, 0); + OS_NATIVE_EXIT(env, that, _1gtk_1tool_1item_1set_1proxy_1menu_1item_FUNC); +} +#endif + +#ifndef NO__1gtk_1toolbar_1insert +JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1toolbar_1insert) + (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jint arg2) +{ + OS_NATIVE_ENTER(env, that, _1gtk_1toolbar_1insert_FUNC); + gtk_toolbar_insert((GtkToolbar *)arg0, (GtkToolItem *)arg1, arg2); + OS_NATIVE_EXIT(env, that, _1gtk_1toolbar_1insert_FUNC); +} +#endif + #ifndef NO__1gtk_1toolbar_1insert_1widget JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1toolbar_1insert_1widget) (JNIEnv *env, jclass that, jintLong arg0, jintLong arg1, jbyteArray arg2, jbyteArray arg3, jint arg4) @@ -14420,6 +14622,26 @@ JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1toolbar_1set_1orientation) } #endif +#ifndef NO__1gtk_1toolbar_1set_1show_1arrow +JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1toolbar_1set_1show_1arrow) + (JNIEnv *env, jclass that, jintLong arg0, jboolean arg1) +{ + OS_NATIVE_ENTER(env, that, _1gtk_1toolbar_1set_1show_1arrow_FUNC); + gtk_toolbar_set_show_arrow((GtkToolbar *)arg0, (gboolean)arg1); + OS_NATIVE_EXIT(env, that, _1gtk_1toolbar_1set_1show_1arrow_FUNC); +} +#endif + +#ifndef NO__1gtk_1toolbar_1set_1style +JNIEXPORT void JNICALL OS_NATIVE(_1gtk_1toolbar_1set_1style) + (JNIEnv *env, jclass that, jintLong arg0, jint arg1) +{ + OS_NATIVE_ENTER(env, that, _1gtk_1toolbar_1set_1style_FUNC); + gtk_toolbar_set_style((GtkToolbar *)arg0, arg1); + OS_NATIVE_EXIT(env, that, _1gtk_1toolbar_1set_1style_FUNC); +} +#endif + #ifndef NO__1gtk_1tooltips_1data_1get JNIEXPORT jintLong JNICALL OS_NATIVE(_1gtk_1tooltips_1data_1get) (JNIEnv *env, jclass that, jintLong arg0) diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h index a91448c564f..2e537a9f6c0 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_custom.h @@ -125,6 +125,7 @@ #define gtk_icon_theme_get_default_LIB LIB_GTK #define gtk_menu_item_remove_submenu_LIB LIB_GTK #define gtk_menu_shell_set_take_focus_LIB LIB_GTK +#define gtk_menu_tool_button_new_LIB LIB_GTK #define gtk_window_set_keep_below_LIB LIB_GTK #define gtk_set_locale_LIB LIB_GTK #define gtk_toolbar_set_orientation_LIB LIB_GTK diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c index 37b7b07493e..c53a3435a44 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.c @@ -18,8 +18,8 @@ #ifdef NATIVE_STATS -int OS_nativeFunctionCount = 1383; -int OS_nativeFunctionCallCount[1383]; +int OS_nativeFunctionCount = 1401; +int OS_nativeFunctionCallCount[1401]; char * OS_nativeFunctionNames[] = { #ifndef JNI64 "Call__IIII", @@ -867,6 +867,7 @@ char * OS_nativeFunctionNames[] = { "_1gtk_1menu_1shell_1insert", "_1gtk_1menu_1shell_1select_1item", "_1gtk_1menu_1shell_1set_1take_1focus", + "_1gtk_1menu_1tool_1button_1new", "_1gtk_1message_1dialog_1new", "_1gtk_1micro_1version", "_1gtk_1minor_1version", @@ -1008,6 +1009,8 @@ char * OS_nativeFunctionNames[] = { "_1gtk_1selection_1data_1free", "_1gtk_1selection_1data_1set", "_1gtk_1separator_1menu_1item_1new", + "_1gtk_1separator_1tool_1item_1new", + "_1gtk_1separator_1tool_1item_1set_1draw", "_1gtk_1set_1locale", "_1gtk_1settings_1get_1default", "_1gtk_1settings_1set_1string_1property", @@ -1104,9 +1107,24 @@ char * OS_nativeFunctionNames[] = { "_1gtk_1toggle_1button_1set_1active", "_1gtk_1toggle_1button_1set_1inconsistent", "_1gtk_1toggle_1button_1set_1mode", + "_1gtk_1toggle_1tool_1button_1get_1active", + "_1gtk_1toggle_1tool_1button_1new", + "_1gtk_1toggle_1tool_1button_1set_1active", + "_1gtk_1tool_1button_1new", + "_1gtk_1tool_1button_1set_1icon_1widget", + "_1gtk_1tool_1button_1set_1label", + "_1gtk_1tool_1button_1set_1label_1widget", + "_1gtk_1tool_1button_1set_1use_1underline", + "_1gtk_1tool_1item_1get_1proxy_1menu_1item", + "_1gtk_1tool_1item_1retrieve_1proxy_1menu_1item", + "_1gtk_1tool_1item_1set_1is_1important", + "_1gtk_1tool_1item_1set_1proxy_1menu_1item", + "_1gtk_1toolbar_1insert", "_1gtk_1toolbar_1insert_1widget", "_1gtk_1toolbar_1new", "_1gtk_1toolbar_1set_1orientation", + "_1gtk_1toolbar_1set_1show_1arrow", + "_1gtk_1toolbar_1set_1style", "_1gtk_1tooltips_1data_1get", "_1gtk_1tooltips_1disable", "_1gtk_1tooltips_1enable", diff --git a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h index e0e8d4cb7c9..fc085b89b6d 100644 --- a/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h +++ b/bundles/org.eclipse.swt/Eclipse SWT PI/gtk/library/os_stats.h @@ -875,6 +875,7 @@ typedef enum { _1gtk_1menu_1shell_1insert_FUNC, _1gtk_1menu_1shell_1select_1item_FUNC, _1gtk_1menu_1shell_1set_1take_1focus_FUNC, + _1gtk_1menu_1tool_1button_1new_FUNC, _1gtk_1message_1dialog_1new_FUNC, _1gtk_1micro_1version_FUNC, _1gtk_1minor_1version_FUNC, @@ -1016,6 +1017,8 @@ typedef enum { _1gtk_1selection_1data_1free_FUNC, _1gtk_1selection_1data_1set_FUNC, _1gtk_1separator_1menu_1item_1new_FUNC, + _1gtk_1separator_1tool_1item_1new_FUNC, + _1gtk_1separator_1tool_1item_1set_1draw_FUNC, _1gtk_1set_1locale_FUNC, _1gtk_1settings_1get_1default_FUNC, _1gtk_1settings_1set_1string_1property_FUNC, @@ -1112,9 +1115,24 @@ typedef enum { _1gtk_1toggle_1button_1set_1active_FUNC, _1gtk_1toggle_1button_1set_1inconsistent_FUNC, _1gtk_1toggle_1button_1set_1mode_FUNC, + _1gtk_1toggle_1tool_1button_1get_1active_FUNC, + _1gtk_1toggle_1tool_1button_1new_FUNC, + _1gtk_1toggle_1tool_1button_1set_1active_FUNC, + _1gtk_1tool_1button_1new_FUNC, + _1gtk_1tool_1button_1set_1icon_1widget_FUNC, + _1gtk_1tool_1button_1set_1label_FUNC, + _1gtk_1tool_1button_1set_1label_1widget_FUNC, + _1gtk_1tool_1button_1set_1use_1underline_FUNC, + _1gtk_1tool_1item_1get_1proxy_1menu_1item_FUNC, + _1gtk_1tool_1item_1retrieve_1proxy_1menu_1item_FUNC, + _1gtk_1tool_1item_1set_1is_1important_FUNC, + _1gtk_1tool_1item_1set_1proxy_1menu_1item_FUNC, + _1gtk_1toolbar_1insert_FUNC, _1gtk_1toolbar_1insert_1widget_FUNC, _1gtk_1toolbar_1new_FUNC, _1gtk_1toolbar_1set_1orientation_FUNC, + _1gtk_1toolbar_1set_1show_1arrow_FUNC, + _1gtk_1toolbar_1set_1style_FUNC, _1gtk_1tooltips_1data_1get_FUNC, _1gtk_1tooltips_1disable_FUNC, _1gtk_1tooltips_1enable_FUNC, 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 9eb7de317cd..2eaba195c09 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_BOTH = 2; + public static final int GTK_TOOLBAR_BOTH_HORIZ = 3; public static final int GTK_TREE_VIEW_COLUMN_GROW_ONLY = 0; public static final int GTK_TREE_VIEW_COLUMN_AUTOSIZE = 1; public static final int GTK_TREE_VIEW_COLUMN_FIXED = 2; @@ -466,6 +468,7 @@ public class OS extends C { public static final byte[] configure_event = ascii("configure-event"); public static final byte[] copy_clipboard = ascii("copy-clipboard"); public static final byte[] cut_clipboard = ascii("cut-clipboard"); + public static final byte[] create_menu_proxy = ascii("create-menu-proxy"); public static final byte[] delete_event = ascii("delete-event"); public static final byte[] delete_from_cursor = ascii("delete-from-cursor"); public static final byte[] day_selected = ascii("day-selected"); @@ -8421,6 +8424,16 @@ public static final void gtk_menu_shell_set_take_focus(int /*long*/ menu_shell, lock.unlock(); } } +/** @method flags=dynamic */ +public static final native int /*long*/ _gtk_menu_tool_button_new(int /*long*/ icon_widget, byte[] label); +public static final int /*long*/ gtk_menu_tool_button_new(int /*long*/ icon_widget, byte[] label) { + lock.lock(); + try { + return _gtk_menu_tool_button_new(icon_widget, label); + } finally { + lock.unlock(); + } +} /** * @param parent cast=(GtkWindow *) * @param flags cast=(GtkDialogFlags) @@ -10061,6 +10074,28 @@ public static final int /*long*/ gtk_separator_menu_item_new() { lock.unlock(); } } +public static final native int /*long*/ _gtk_separator_tool_item_new(); +public static final int /*long*/ gtk_separator_tool_item_new() { + lock.lock(); + try { + return _gtk_separator_tool_item_new(); + } finally { + lock.unlock(); + } +} +/** + * @param item cast=(GtkSeparatorToolItem *) + * @param draw cast=(gboolean) + */ +public static final native void _gtk_separator_tool_item_set_draw(int /*long*/ item, boolean draw); +public static final void gtk_separator_tool_item_set_draw(int /*long*/ item, boolean draw) { + lock.lock(); + try { + _gtk_separator_tool_item_set_draw(item, draw); + } finally { + lock.unlock(); + } +} /** @method flags=dynamic */ public static final native int /*long*/ _gtk_set_locale(); public static final int /*long*/ gtk_set_locale() { @@ -11116,6 +11151,166 @@ public static final void gtk_toggle_button_set_mode(int /*long*/ toggle_button, lock.unlock(); } } +/** @param button cast=(GtkToggleToolButton *) */ +public static final native boolean _gtk_toggle_tool_button_get_active(int /*long*/ button); +public static final boolean gtk_toggle_tool_button_get_active(int /*long*/ button) { + lock.lock(); + try { + return _gtk_toggle_tool_button_get_active(button); + } finally { + lock.unlock(); + } +} +public static final native int /*long*/ _gtk_toggle_tool_button_new(); +public static final int /*long*/ gtk_toggle_tool_button_new() { + lock.lock(); + try { + return _gtk_toggle_tool_button_new(); + } finally { + lock.unlock(); + } +} +/** + * @param item cast=(GtkToggleToolButton *) + * @param selected cast=(gboolean) + */ +public static final native void _gtk_toggle_tool_button_set_active(int /*long*/ item, boolean selected); +public static final void gtk_toggle_tool_button_set_active(int /*long*/ item, boolean selected) { + lock.lock(); + try { + _gtk_toggle_tool_button_set_active(item, selected); + } finally { + lock.unlock(); + } +} +/** + * @param icon_widget cast=(GtkWidget *) + * @param label cast=(const gchar *) + */ +public static final native int /*long*/ _gtk_tool_button_new(int /*long*/ icon_widget, byte[] label); +public static final int /*long*/ gtk_tool_button_new(int /*long*/ icon_widget, byte[] label) { + lock.lock(); + try { + return _gtk_tool_button_new(icon_widget, label); + } finally { + lock.unlock(); + } +} +/** + * @param button cast=(GtkToolButton *) + * @param widget cast=(GtkWidget *) + */ +public static final native void _gtk_tool_button_set_icon_widget(int /*long*/ button, int /*long*/ widget); +public static final void gtk_tool_button_set_icon_widget(int /*long*/ button, int /*long*/ widget) { + lock.lock(); + try { + _gtk_tool_button_set_icon_widget(button, widget); + } finally { + lock.unlock(); + } +} +/** + * @param button cast=(GtkToolButton *) + * @param label cast=(const gchar *) + */ +public static final native void _gtk_tool_button_set_label(int /*long*/ button, byte[] label); +public static final void gtk_tool_button_set_label(int /*long*/ button, byte[] label) { + lock.lock(); + try { + _gtk_tool_button_set_label(button, label); + } finally { + lock.unlock(); + } +} +/** + * @param button cast=(GtkToolButton *) + * @param widget cast=(GtkWidget *) + */ +public static final native void _gtk_tool_button_set_label_widget(int /*long*/ button, int /*long*/ widget); +public static final void gtk_tool_button_set_label_widget(int /*long*/ button, int /*long*/ widget) { + lock.lock(); + try { + _gtk_tool_button_set_label_widget(button, widget); + } finally { + lock.unlock(); + } +} +/** + * @param item cast=(GtkToolButton *) + * @param underline cast=(gboolean) + */ +public static final native void _gtk_tool_button_set_use_underline(int /*long*/ item, boolean underline); +public static final void gtk_tool_button_set_use_underline(int /*long*/ item, boolean underline) { + lock.lock(); + try { + _gtk_tool_button_set_use_underline(item, underline); + } finally { + lock.unlock(); + } +} +/** + * @param item cast=(GtkToolItem *) + * @param menu_id cast=(const gchar *) + */ +public static final native int /*long*/ _gtk_tool_item_get_proxy_menu_item(int /*long*/ item, byte[] menu_id); +public static final int /*long*/ gtk_tool_item_get_proxy_menu_item(int /*long*/ item, byte[] menu_id) { + lock.lock(); + try { + return _gtk_tool_item_get_proxy_menu_item(item, menu_id); + } finally { + lock.unlock(); + } +} +/** @param item cast=(GtkToolItem *) */ +public static final native int /*long*/ _gtk_tool_item_retrieve_proxy_menu_item(int /*long*/ item); +public static final int /*long*/ gtk_tool_item_retrieve_proxy_menu_item(int /*long*/ item) { + lock.lock(); + try { + return _gtk_tool_item_retrieve_proxy_menu_item(item); + } finally { + lock.unlock(); + } +} +/** + * @param item cast=(GtkToolItem *) + * @param important cast=(gboolean) + */ +public static final native void _gtk_tool_item_set_is_important(int /*long*/ item, boolean important); +public static final void gtk_tool_item_set_is_important(int /*long*/ item, boolean important) { + lock.lock(); + try { + _gtk_tool_item_set_is_important(item, important); + } finally { + lock.unlock(); + } +} +/** + * @param item cast=(GtkToolItem *) + * @param menu_id cast=(const gchar *) + * @param widget cast=(GtkWidget *) + */ +public static final native void _gtk_tool_item_set_proxy_menu_item(int /*long*/ item, byte[] menu_id, int /*long*/ widget); +public static final void gtk_tool_item_set_proxy_menu_item(int /*long*/ item, byte[] menu_id, int /*long*/ widget) { + lock.lock(); + try { + _gtk_tool_item_set_proxy_menu_item(item, menu_id, widget); + } finally { + lock.unlock(); + } +} +/** + * @param toolbar cast=(GtkToolbar *) + * @param item cast=(GtkToolItem *) + */ +public static final native void _gtk_toolbar_insert(int /*long*/ toolbar, int /*long*/ item, int pos); +public static final void gtk_toolbar_insert(int /*long*/ toolbar, int /*long*/ item, int pos) { + lock.lock(); + try { + _gtk_toolbar_insert(toolbar, item, pos); + } finally { + lock.unlock(); + } +} /** * @param toolbar cast=(GtkToolbar *) * @param widget cast=(GtkWidget *) @@ -11155,6 +11350,31 @@ public static final void gtk_toolbar_set_orientation(int /*long*/ toolbar, int o lock.unlock(); } } +/** + * @param toolbar cast=(GtkToolbar *) + * @param show_arrow cast=(gboolean) + */ +public static final native void _gtk_toolbar_set_show_arrow(int /*long*/ toolbar, boolean show_arrow); +public static final void gtk_toolbar_set_show_arrow(int /*long*/ toolbar, boolean show_arrow) { + lock.lock(); + try { + _gtk_toolbar_set_show_arrow(toolbar, show_arrow); + } finally { + lock.unlock(); + } +} +/** @param toolbar cast=(GtkToolbar *) + * @param type cast=(GtkToolbarStyle) + */ +public static final native void _gtk_toolbar_set_style(int /*long*/ toolbar, int style); +public static final void gtk_toolbar_set_style(int /*long*/ toolbar, int style) { + lock.lock(); + try { + _gtk_toolbar_set_style(toolbar, style); + } finally { + lock.unlock(); + } +} /** @method flags=dynamic */ public static final native int /*long*/ _gtk_tooltips_data_get(int /*long*/ widget); public static final int /*long*/ gtk_tooltips_data_get(int /*long*/ widget) { 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 7de69b35748..4db8812fddf 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 @@ -2434,6 +2434,7 @@ void initializeCallbacks () { closures [Widget.ACTIVATE_INVERSE] = OS.g_cclosure_new (windowProc2, Widget.ACTIVATE_INVERSE, 0); closures [Widget.CHANGED] = OS.g_cclosure_new (windowProc2, Widget.CHANGED, 0); closures [Widget.CLICKED] = OS.g_cclosure_new (windowProc2, Widget.CLICKED, 0); + closures [Widget.CREATE_MENU_PROXY] = OS.g_cclosure_new (windowProc2, Widget.CREATE_MENU_PROXY, 0); closures [Widget.DAY_SELECTED] = OS.g_cclosure_new (windowProc2, Widget.DAY_SELECTED, 0); closures [Widget.DAY_SELECTED_DOUBLE_CLICK] = OS.g_cclosure_new (windowProc2, Widget.DAY_SELECTED_DOUBLE_CLICK, 0); closures [Widget.HIDE] = OS.g_cclosure_new (windowProc2, Widget.HIDE, 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 3d301248429..eacee0acc12 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 @@ -45,10 +45,16 @@ import org.eclipse.swt.graphics.*; * @noextend This class is not intended to be subclassed by clients. */ public class ToolBar extends Composite { - ToolItem lastFocus; + ToolItem currentFocusItem; ToolItem [] tabItemList; ImageList imageList; - + boolean hasChildFocus; + static Callback menuItemSelectedFunc; + static { + menuItemSelectedFunc = new Callback(ToolBar.class, "MenuItemSelectedProc", 2); + if (menuItemSelectedFunc.getAddress() == 0) SWT.error(SWT.ERROR_NO_MORE_CALLBACKS); + } + /** * Constructs a new instance of this class given its parent * and a style value describing its behavior and appearance. @@ -107,13 +113,6 @@ public ToolBar (Composite parent, int style) { static int checkStyle (int style) { /* - * Feature in GTK. It is not possible to create - * a toolbar that wraps. Therefore, no matter what - * style bits are specified, clear the WRAP bits so - * that the style matches the behavior. - */ - if ((style & SWT.WRAP) != 0) style &= ~SWT.WRAP; - /* * Even though it is legal to create this widget * with scroll bars, they serve no useful purpose * because they do not automatically scroll the @@ -139,13 +138,35 @@ 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) { checkWidget (); if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0; - return computeNativeSize (handle, wHint, hHint, changed); + /* + * Feature in GTK. Size of toolbar is calculated incorrectly + * and appears as just the overflow arrow, if the arrow is enabled + * to display. The fix is to disable it before the computation of + * size and enable it if WRAP style is set. + */ + OS.gtk_toolbar_set_show_arrow (handle, false); + Point size = computeNativeSize (handle, wHint, hHint, changed); + if ((style & SWT.WRAP) != 0) OS.gtk_toolbar_set_show_arrow (handle, true); + return size; } Widget computeTabGroup () { @@ -155,11 +176,8 @@ Widget computeTabGroup () { while (i < items.length && items [i].control == null) i++; if (i == items.length) return super.computeTabGroup (); } - int index = 0; - while (index < items.length) { - if (items[index].hasFocus ()) break; - index++; - } + int index = indexOf(currentFocusItem); + if (index == -1) index = items.length - 1; while (index >= 0) { ToolItem item = items [index]; if (item.isTabGroup ()) return item; @@ -215,12 +233,15 @@ void fixChildren (Shell newShell, Shell oldShell, Decorations newDecorations, De } boolean forceFocus (int /*long*/ focusHandle) { - if (lastFocus != null && lastFocus.setFocus ()) return true; - ToolItem [] items = getItems (); - for (int i = 0; i < items.length; i++) { - ToolItem item = items [i]; - if (item.setFocus ()) return true; - } + int dir = OS.GTK_DIR_TAB_FORWARD; + if ((style & SWT.MIRRORED) != 0) dir = OS.GTK_DIR_TAB_BACKWARD; + int /*long*/ childHandle = handle; + if (currentFocusItem != null) childHandle = currentFocusItem.handle; + /* + * Feature in GTK. GtkToolBar takes care of navigating through + * items by Up/Down arrow keys. + */ + if (OS.gtk_widget_child_focus (childHandle, dir)) return true; return super.forceFocus (focusHandle); } @@ -372,53 +393,35 @@ int /*long*/ gtk_key_press_event (int /*long*/ widget, int /*long*/ eventPtr) { if (!hasFocus ()) return 0; int /*long*/ result = super.gtk_key_press_event (widget, eventPtr); if (result != 0) return result; - ToolItem [] items = getItems (); - int length = items.length; - int index = 0; - while (index < length) { - if (items [index].hasFocus ()) break; - index++; - } GdkEventKey gdkEvent = new GdkEventKey (); OS.memmove (gdkEvent, eventPtr, GdkEventKey.sizeof); - boolean next = false; switch (gdkEvent.keyval) { - case OS.GDK_Up: - case OS.GDK_Left: next = false; break; case OS.GDK_Down: { - if (0 <= index && index < length) { - ToolItem item = items [index]; - if ((item.style & SWT.DROP_DOWN) != 0) { - Event event = new Event (); - event.detail = SWT.ARROW; - int /*long*/ topHandle = item.topHandle (); - event.x = OS.GTK_WIDGET_X (topHandle); - event.y = OS.GTK_WIDGET_Y (topHandle) + OS.GTK_WIDGET_HEIGHT (topHandle); - if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth() - OS.GTK_WIDGET_WIDTH(topHandle) - event.x; - item.sendSelectionEvent (SWT.Selection, event, false); - return result; - } + if (OS.GTK_VERSION < OS.VERSION (2, 6, 0) && (currentFocusItem != null) && (currentFocusItem.style & SWT.DROP_DOWN) != 0) { + Event event = new Event (); + event.detail = SWT.ARROW; + int /*long*/ topHandle = currentFocusItem.topHandle (); + event.x = OS.GTK_WIDGET_X (topHandle); + event.y = OS.GTK_WIDGET_Y (topHandle) + OS.GTK_WIDGET_HEIGHT (topHandle); + if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth() - OS.GTK_WIDGET_WIDTH(topHandle) - event.x; + currentFocusItem.sendSelectionEvent (SWT.Selection, event, false); + /* + * Stop GTK from processing the event further as key_down binding + * will move the focus to the next item. + */ + return 1; } - //FALL THROUGH } - case OS.GDK_Right: next = true; break; default: return result; } - if ((style & SWT.MIRRORED) != 0) next= !next; - int start = index, offset = next ? 1 : -1; - while ((index = (index + offset + length) % length) != start) { - ToolItem item = items [index]; - if (item.setFocus ()) return result; - } - return result; +} + +int /*long*/ gtk_focus (int /*long*/ widget, int /*long*/ directionType) { + return 0; } boolean hasFocus () { - ToolItem [] items = getItems (); - for (int i=0; i<items.length; i++) { - ToolItem item = items [i]; - if (item.hasFocus ()) return true; - } + if (hasChildFocus) return true; return super.hasFocus(); } @@ -450,6 +453,42 @@ public int indexOf (ToolItem item) { return -1; } +static int /*long*/ MenuItemSelectedProc (int /*long*/ widget, int /*long*/ user_data) { + Display display = Display.getCurrent (); + ToolItem item = (ToolItem) display.getWidget (user_data); + if (item != null) { + return item.getParent ().menuItemSelected (widget, item); + } + return 0; +} + +int /*long*/ menuItemSelected (int /*long*/ widget, ToolItem item) { + Event event = new Event (); + switch (item.style) { + case SWT.DROP_DOWN : + /* + * Feature in GTK. The DROP_DOWN item does not + * contain arrow button in the overflow menu. So, it + * is impossible to select the menu of that item. + * The fix is to consider the item selection + * as Arrow click, in order to popup the drop-down. + */ + event.detail = SWT.ARROW; + event.x = OS.GTK_WIDGET_X (widget); + if ((style & SWT.MIRRORED) != 0) event.x = getClientWidth () - OS.GTK_WIDGET_WIDTH (widget) - event.x; + event.y = OS.GTK_WIDGET_Y (widget) + OS.GTK_WIDGET_HEIGHT (widget); + break; + case SWT.RADIO : + if ((style & SWT.NO_RADIO_GROUP) == 0) item.selectRadio (); + break; + case SWT.CHECK : + boolean currentSelection = item.getSelection(); + item.setSelection (!currentSelection); + } + item.sendSelectionEvent (SWT.Selection, event, false); + return 0; +} + boolean mnemonicHit (char key) { ToolItem [] items = getItems (); for (int i=0; i<items.length; i++) { @@ -470,10 +509,15 @@ boolean mnemonicMatch (char key) { void relayout () { ToolItem [] items = getItems (); + boolean hasTextItems = false; for (int i=0; i<items.length; i++) { ToolItem item = items [i]; - if (item != null) item.resizeControl (); + if (item != null) { + item.resizeControl (); + hasTextItems |= item.hasText; + } } + if (!hasTextItems) OS.gtk_toolbar_set_style (handle, OS.GTK_TOOLBAR_BOTH_HORIZ); } void releaseChildren (boolean destroy) { @@ -514,8 +558,10 @@ void reskinChildren (int flags) { } int setBounds (int x, int y, int width, int height, boolean move, boolean resize) { + OS.gtk_toolbar_set_show_arrow (handle, false); int result = super.setBounds (x, y, width, height, move, resize); if ((result & RESIZED) != 0) relayout (); + if ((style & SWT.WRAP) != 0) OS.gtk_toolbar_set_show_arrow (handle, true); return result; } 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 ed861249f23..fd5e94e36d2 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 @@ -38,12 +38,13 @@ import org.eclipse.swt.events.*; * @noextend This class is not intended to be subclassed by clients. */ public class ToolItem extends Item { - int /*long*/ boxHandle, arrowHandle, arrowBoxHandle, separatorHandle, labelHandle, imageHandle; + int /*long*/ arrowHandle, arrowBoxHandle, labelHandle, imageHandle; + int /*long*/ eventHandle, proxyMenuItem; ToolBar parent; Control control; Image hotImage, disabledImage; String toolTipText; - boolean drawHotImage; + boolean drawHotImage, hasText; /** * Constructs a new instance of this class given its parent @@ -180,91 +181,83 @@ protected void checkSubclass () { void createHandle (int index) { state |= HANDLE; - if ((style & SWT.SEPARATOR) == 0) { - boxHandle = (parent.style & SWT.RIGHT) != 0 ? OS.gtk_hbox_new (false, 0) : OS.gtk_vbox_new (false, 0); - if (boxHandle == 0) error (SWT.ERROR_NO_HANDLES); - labelHandle = OS.gtk_label_new_with_mnemonic (null); - if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES); - imageHandle = OS.gtk_image_new (); - if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (boxHandle, imageHandle); - OS.gtk_container_add (boxHandle, labelHandle); - if ((parent.style & SWT.VERTICAL) != 0) { - // Align text and images to the left - OS.gtk_box_set_child_packing (boxHandle, imageHandle, false, false, 0, OS.GTK_PACK_START); - OS.gtk_box_set_child_packing (boxHandle, labelHandle, false, false, 2, OS.GTK_PACK_START); - } - } int bits = SWT.SEPARATOR | SWT.RADIO | SWT.CHECK | SWT.PUSH | SWT.DROP_DOWN; switch (style & bits) { case SWT.SEPARATOR: - handle = OS.gtk_hbox_new (false, 0); + handle = OS.gtk_separator_tool_item_new (); if (handle == 0) error (SWT.ERROR_NO_HANDLES); - boolean isVertical = (parent.style & SWT.VERTICAL) != 0; - separatorHandle = isVertical ? OS.gtk_hseparator_new() : OS.gtk_vseparator_new(); - if (separatorHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_widget_set_size_request (separatorHandle, isVertical ? 15 : 6, isVertical ? 6 : 15); - OS.gtk_widget_set_size_request (handle, isVertical ? 15 : 6, isVertical ? 6 : 15); - OS.gtk_container_add (handle, separatorHandle); + OS.gtk_separator_tool_item_set_draw (handle, true); break; case SWT.DROP_DOWN: - handle = OS.gtk_button_new (); - if (handle == 0) error (SWT.ERROR_NO_HANDLES); - arrowBoxHandle = OS.gtk_hbox_new (false, 0); - if (arrowBoxHandle == 0) error(SWT.ERROR_NO_HANDLES); - arrowHandle = OS.gtk_arrow_new (OS.GTK_ARROW_DOWN, OS.GTK_SHADOW_NONE); - if (arrowHandle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_widget_set_size_request (arrowHandle, 8, 6); - OS.gtk_container_add (handle, arrowBoxHandle); - OS.gtk_container_add (arrowBoxHandle, boxHandle); - OS.gtk_container_add (arrowBoxHandle, arrowHandle); + if (OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) { + handle = OS.gtk_menu_tool_button_new (0, null); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + /* + * Feature in GTK. The arrow button of DropDown tool-item is + * disabled when it does not contain menu. The fix is to + * find the arrow button handle and enable it. + */ + int /*long*/ child = OS.gtk_bin_get_child (handle); + int /*long*/ list = OS.gtk_container_get_children (child); + arrowHandle = OS.g_list_nth_data (list, 1); + OS.gtk_widget_set_sensitive (arrowHandle, true); + } else { + /* + * GTK does not support GtkMenuToolButton until 2.6. + * So, we try to emulate it on the un-supported version. + */ + handle = OS.gtk_tool_button_new (0, null); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + labelHandle = OS.gtk_label_new_with_mnemonic (null); + if (labelHandle == 0) error (SWT.ERROR_NO_HANDLES); + arrowBoxHandle = OS.gtk_hbox_new (false, 0); + if (arrowBoxHandle == 0) error(SWT.ERROR_NO_HANDLES); + arrowHandle = OS.gtk_arrow_new (OS.GTK_ARROW_DOWN, OS.GTK_SHADOW_NONE); + if (arrowHandle == 0) error (SWT.ERROR_NO_HANDLES); + OS.gtk_widget_set_size_request (arrowHandle, 8, 6); + OS.gtk_tool_button_set_label_widget (handle, arrowBoxHandle); + OS.gtk_container_add (arrowBoxHandle, labelHandle); + OS.gtk_container_add (arrowBoxHandle, arrowHandle); + /* + * As we are try to emulate GtkMenuToolButton and in order + * to display both the label and image, it is required + * the set the toolitem as important. This will entitle + * to display the label all the times. + */ + OS.gtk_tool_item_set_is_important (handle, true); + } break; case SWT.RADIO: /* - * This code is intentionally commented. Because GTK - * enforces radio behavior in a button group a radio group - * is not created for each set of contiguous buttons, each - * radio button will not draw unpressed. The fix is to use - * toggle buttons instead. + * Because GTK enforces radio behavior in a button group + * a radio group is not created for each set of contiguous + * buttons, each radio button will not draw unpressed. + * The fix is to use toggle buttons instead. */ -// handle = OS.gtk_radio_button_new (0); -// if (handle == 0) error (SWT.ERROR_NO_HANDLES); -// OS.gtk_toggle_button_set_mode (handle, false); -// OS.gtk_container_add (handle, boxHandle); -// break; case SWT.CHECK: - handle = OS.gtk_toggle_button_new (); + handle = OS.gtk_toggle_tool_button_new (); if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_toggle_button_set_mode (handle, false); - OS.gtk_container_add (handle, boxHandle); break; case SWT.PUSH: default: - handle = OS.gtk_button_new (); + handle = OS.gtk_tool_button_new (0, null); if (handle == 0) error (SWT.ERROR_NO_HANDLES); - OS.gtk_container_add (handle, boxHandle); + OS.gtk_tool_button_set_label (handle, null); break; } - if ((style & SWT.SEPARATOR) == 0) { - int [] relief = new int [1]; - OS.gtk_widget_style_get (parent.handle, OS.button_relief, relief, 0); - OS.gtk_button_set_relief (handle, relief [0]); - } - OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS); -// This code is intentionally commented. -// int /*long*/ fontHandle = parent.fontHandle (); -// GdkColor color = new GdkColor (); -// int /*long*/ style = OS.gtk_widget_get_style (fontHandle); -// OS.gtk_style_get_fg (style, OS.GTK_STATE_NORMAL, color); -// int /*long*/ font = OS.gtk_style_get_font_desc (style); -// setForegroundColor (color); -// setFontDescription (font); if ((parent.state & FOREGROUND) != 0) { setForegroundColor (parent.getForegroundColor()); } if ((parent.state & FONT) != 0) { setFontDescription (parent.getFontDescription()); } + /* + * Feature in GTK. GtkToolButton class uses this property to + * determine whether to show or hide its label when the toolbar + * style is GTK_TOOLBAR_BOTH_HORIZ (or SWT.RIGHT). + */ + if ((parent.style & SWT.RIGHT) != 0) OS.gtk_tool_item_set_is_important (handle, true); + if ((style & SWT.SEPARATOR) == 0) OS.gtk_tool_button_set_use_underline (handle, true); } void createWidget (int index) { @@ -288,7 +281,8 @@ Widget [] computeTabList () { void deregister() { super.deregister (); - if (labelHandle != 0) display.removeWidget (labelHandle); + if (eventHandle != 0) display.removeWidget (eventHandle); + if (arrowHandle != 0) display.removeWidget (arrowHandle); } public void dispose () { @@ -314,36 +308,10 @@ public Rectangle getBounds () { parent.forceResize (); int /*long*/ topHandle = topHandle (); int x, y, width, height; - /* - * Bug in GTK. Toolbar items are only allocated their minimum size - * in versions before 2.4.0. The fix is to use the total size - * available minus any borders. - */ - if (OS.GTK_VERSION < OS.VERSION (2, 4, 0) && control != null && !control.isDisposed ()) { - int border = OS.gtk_container_get_border_width (parent.handle); - byte [] shadowType = Converter.wcsToMbcs (null, "shadow_type", true); - int [] shadow = new int [1]; - OS.gtk_widget_style_get (parent.handle, shadowType, shadow, 0); - if (shadow [0] != OS.GTK_SHADOW_NONE) { - border += OS.gtk_style_get_xthickness (OS.gtk_widget_get_style (parent.handle)); - } - if ((parent.style & SWT.VERTICAL) != 0) { - x = border; - y = OS.GTK_WIDGET_Y (topHandle) + border; - width = OS.GTK_WIDGET_WIDTH (parent.handle) - border*2; - height = OS.GTK_WIDGET_HEIGHT (topHandle); - } else { - x = OS.GTK_WIDGET_X (topHandle) + border; - y = border; - width = OS.GTK_WIDGET_WIDTH (topHandle); - height = OS.GTK_WIDGET_HEIGHT (parent.handle) - border*2; - } - } else { - x = OS.GTK_WIDGET_X (topHandle); - y = OS.GTK_WIDGET_Y (topHandle); - width = OS.GTK_WIDGET_WIDTH (topHandle); - height = OS.GTK_WIDGET_HEIGHT (topHandle); - } + x = OS.GTK_WIDGET_X (topHandle); + y = OS.GTK_WIDGET_Y (topHandle); + width = OS.GTK_WIDGET_WIDTH (topHandle); + height = OS.GTK_WIDGET_HEIGHT (topHandle); if ((parent.style & SWT.MIRRORED) != 0) x = parent.getClientWidth () - width - x; if ((style & SWT.SEPARATOR) != 0 && control != null) height = Math.max (height, 23); return new Rectangle (x, y, width, height); @@ -460,7 +428,7 @@ public ToolBar getParent () { public boolean getSelection () { checkWidget(); if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return false; - return OS.gtk_toggle_button_get_active (handle); + return OS.gtk_toggle_tool_button_get_active (handle); } /** @@ -532,19 +500,36 @@ int /*long*/ gtk_clicked (int /*long*/ widget) { if (eventPtr != 0) { GdkEvent gdkEvent = new GdkEvent (); OS.memmove (gdkEvent, eventPtr, GdkEvent.sizeof); + int /*long*/ topHandle = topHandle(); switch (gdkEvent.type) { + case OS.GDK_KEY_RELEASE: //Fall Through.. case OS.GDK_BUTTON_PRESS: case OS.GDK_2BUTTON_PRESS: case OS.GDK_BUTTON_RELEASE: { - double [] x_win = new double [1]; - double [] y_win = new double [1]; - OS.gdk_event_get_coords (eventPtr, x_win, y_win); - int x = OS.GTK_WIDGET_X (arrowHandle) - OS.GTK_WIDGET_X (handle); - int width = OS.GTK_WIDGET_WIDTH (arrowHandle); - if ((((parent.style & SWT.RIGHT_TO_LEFT) == 0) && x <= (int)x_win [0]) - || (((parent.style & SWT.RIGHT_TO_LEFT) != 0) && (int)x_win [0] <= x + width)) { + boolean isArrow = false; + if (OS.GTK_VERSION < OS.VERSION (2, 6, 0)) { + double [] x_win = new double [1]; + double [] y_win = new double [1]; + OS.gdk_event_get_coords (eventPtr, x_win, y_win); + int x = OS.GTK_WIDGET_X (arrowHandle) - OS.GTK_WIDGET_X (handle); + int width = OS.GTK_WIDGET_WIDTH (arrowHandle); + if ((((parent.style & SWT.RIGHT_TO_LEFT) == 0) && x <= (int)x_win [0]) + || (((parent.style & SWT.RIGHT_TO_LEFT) != 0) && (int)x_win [0] <= x + width)) { + isArrow = true; + } + } else if (widget == arrowHandle) { + isArrow = true; + topHandle = widget; + /* + * Feature in GTK. ArrowButton stays in toggled state if there is no popup menu. + * It is required to set back the state of arrow to normal state after it is clicked. + */ + OS.g_signal_handlers_block_matched (widget, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED); + OS.gtk_toggle_button_set_active(widget, false); + OS.g_signal_handlers_unblock_matched (widget, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED); + } + if (isArrow) { event.detail = SWT.ARROW; - int /*long*/ topHandle = topHandle (); event.x = OS.GTK_WIDGET_X (topHandle); if ((parent.style & SWT.MIRRORED) != 0) event.x = parent.getClientWidth () - OS.GTK_WIDGET_WIDTH (topHandle) - event.x; event.y = OS.GTK_WIDGET_Y (topHandle) + OS.GTK_WIDGET_HEIGHT (topHandle); @@ -564,16 +549,73 @@ int /*long*/ gtk_clicked (int /*long*/ widget) { return 0; } +int /*long*/ gtk_create_menu_proxy (int /*long*/ widget) { + /* + * Feature in GTK. If the item is a radio/check button + * with only image, then that image does not appear in + * the overflow menu. + * The fix is to create and use the proxy menu for the + * items appearing in the overflow menu. + */ + byte [] buffer = Converter.wcsToMbcs (null, "menu-id", true); //$NON-NLS-1$ + if (proxyMenuItem != 0) { + /* + * The menuItem to appear in the overflow menu is cached + * for the tool-item. If the text/image of the item changes, + * then the proxyMenu is reset. + */ + OS.gtk_tool_item_set_proxy_menu_item (widget, buffer, proxyMenuItem); + return 1; + } + /* + * Since the arrow button does not appear in the drop_down + * item, we request the menu-item and then, hook the + * activate signal to send the Arrow selection signal. + */ + if ((style & SWT.DROP_DOWN) != 0) return 0; + if (image != null /*&& (text == null || text.length() == 0)*/) { + ImageList imageList = parent.imageList; + if (imageList != null) { + int index = imageList.indexOf (image); + if (index != -1) { + int /*long*/ pixbuf = imageList.getPixbuf (index); + byte[] label; + if (text == null || text.length() == 0) { + label = new byte[]{0}; + } + else { + label = Converter.wcsToMbcs(null, text, true); + } + /* + * Feature in GTK. If the menuItem is initialised only + * with the image, then the menu appears very sloppy. + * The fix is to initialise menu item with empty string. + */ + int /*long*/ menuItem = OS.gtk_image_menu_item_new_with_label (label); + int /*long*/ menuImage = OS.gtk_image_new_from_pixbuf (pixbuf); + OS.gtk_image_menu_item_set_image (menuItem, menuImage); + OS.gtk_tool_item_set_proxy_menu_item (widget, buffer, menuItem); + proxyMenuItem = OS.gtk_tool_item_get_proxy_menu_item (widget, buffer); + OS.g_signal_connect(menuItem, OS.activate, ToolBar.menuItemSelectedFunc.getAddress(), handle); + return 1; + } + } + } + return 0; +} + int /*long*/ gtk_enter_notify_event (int /*long*/ widget, int /*long*/ event) { parent.gtk_enter_notify_event (widget, event); drawHotImage = (parent.style & SWT.FLAT) != 0 && hotImage != null; - if (drawHotImage && imageHandle != 0) { + if (drawHotImage) { ImageList imageList = parent.imageList; if (imageList != null) { int index = imageList.indexOf (hotImage); if (index != -1) { int /*long*/ pixbuf = imageList.getPixbuf (index); - OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); + imageHandle = OS.gtk_image_new_from_pixbuf (pixbuf); + OS.gtk_widget_show (imageHandle); + OS.gtk_tool_button_set_icon_widget (handle, imageHandle); } } } @@ -596,9 +638,14 @@ int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) { return 0; } +int /*long*/ gtk_focus_in_event (int /*long*/ widget, int /*long*/ event) { + parent.hasChildFocus = true; + parent.currentFocusItem = this; + return 0; +} + int /*long*/ gtk_focus_out_event (int /*long*/ widget, int /*long*/ event) { - OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS); - parent.lastFocus = this; + parent.hasChildFocus = false; return 0; } @@ -606,13 +653,15 @@ int /*long*/ gtk_leave_notify_event (int /*long*/ widget, int /*long*/ event) { parent.gtk_leave_notify_event (widget, event); if (drawHotImage) { drawHotImage = false; - if (imageHandle != 0 && image != null) { + if (image != null) { ImageList imageList = parent.imageList; if (imageList != null) { int index = imageList.indexOf (image); if (index != -1) { int /*long*/ pixbuf = imageList.getPixbuf (index); - OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); + imageHandle = OS.gtk_image_new_from_pixbuf (pixbuf); + OS.gtk_widget_show (imageHandle); + OS.gtk_tool_button_set_icon_widget (handle, imageHandle); } } } @@ -629,20 +678,28 @@ int /*long*/ gtk_mnemonic_activate (int /*long*/ widget, int /*long*/ arg1) { return parent.gtk_mnemonic_activate (widget, arg1); } -boolean hasFocus () { - return OS.GTK_WIDGET_HAS_FOCUS (handle); -} - void hookEvents () { super.hookEvents (); if ((style & SWT.SEPARATOR) != 0) return; OS.g_signal_connect_closure (handle, OS.clicked, display.closures [CLICKED], false); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [LEAVE_NOTIFY_EVENT], 0, display.closures [LEAVE_NOTIFY_EVENT], false); - if (labelHandle != 0) OS.g_signal_connect_closure_by_id (labelHandle, display.signalIds [MNEMONIC_ACTIVATE], 0, display.closures [MNEMONIC_ACTIVATE], false); - - OS.g_signal_connect_closure_by_id (handle, display.signalIds [FOCUS_OUT_EVENT], 0, display.closures [FOCUS_OUT_EVENT], false); - + /* + * Feature in GTK. GtkToolItem does not respond to basic listeners + * such as button-press, enter-notify to it. The fix is to assign + * the listener to child (GtkButton) of the tool-item. + */ + eventHandle = OS.gtk_bin_get_child(handle); + if ((style & SWT.DROP_DOWN) != 0 && OS.GTK_VERSION >= OS.VERSION (2, 6, 0)) { + int /*long*/ list = OS.gtk_container_get_children(eventHandle); + eventHandle = OS.g_list_nth_data(list, 0); + if (arrowHandle != 0) OS.g_signal_connect_closure (arrowHandle, OS.clicked, display.closures [CLICKED], false); + } + if ((style & (SWT.CHECK | SWT.RADIO | SWT.DROP_DOWN)) != 0) { + OS.g_signal_connect_closure (handle, OS.create_menu_proxy, display.closures [CREATE_MENU_PROXY], false); + } + OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [ENTER_NOTIFY_EVENT], 0, display.closures [ENTER_NOTIFY_EVENT], false); + OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [LEAVE_NOTIFY_EVENT], 0, display.closures [LEAVE_NOTIFY_EVENT], false); + OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [FOCUS_IN_EVENT], 0, display.closures [FOCUS_IN_EVENT], false); + OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [FOCUS_OUT_EVENT], 0, display.closures [FOCUS_OUT_EVENT], false); /* * Feature in GTK. Usually, GTK widgets propagate all events to their * parent when they are done their own processing. However, in contrast @@ -657,10 +714,10 @@ void hookEvents () { OS.GDK_ENTER_NOTIFY_MASK | OS.GDK_LEAVE_NOTIFY_MASK | OS.GDK_KEY_PRESS_MASK | OS.GDK_KEY_RELEASE_MASK | OS.GDK_FOCUS_CHANGE_MASK; - OS.gtk_widget_add_events (handle, mask); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT], false); - OS.g_signal_connect_closure_by_id (handle, display.signalIds [EVENT_AFTER], 0, display.closures[EVENT_AFTER], false); + OS.gtk_widget_add_events (eventHandle, mask); + OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [BUTTON_PRESS_EVENT], 0, display.closures [BUTTON_PRESS_EVENT], false); + OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT], false); + OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [EVENT_AFTER], 0, display.closures[EVENT_AFTER], false); int /*long*/ topHandle = topHandle (); OS.g_signal_connect_closure_by_id (topHandle, display.signalIds [MAP], 0, display.closures [MAP], true); @@ -702,17 +759,18 @@ boolean isTabGroup () { void register () { super.register (); - if (labelHandle != 0) display.addWidget (labelHandle, this); + if (eventHandle != 0) display.addWidget (eventHandle, this); + if (arrowHandle != 0) display.addWidget (arrowHandle, this); } void releaseHandle () { super.releaseHandle (); - boxHandle = arrowHandle = separatorHandle = labelHandle = imageHandle = 0; + arrowHandle = labelHandle = imageHandle = eventHandle = 0; } void releaseWidget () { super.releaseWidget (); - if (parent.lastFocus == this) parent.lastFocus = null; + if (parent.currentFocusItem == this) parent.currentFocusItem = null; parent = null; control = null; hotImage = disabledImage = null; @@ -746,7 +804,6 @@ public void removeSelectionListener(SelectionListener listener) { void resizeControl () { if (control != null && !control.isDisposed ()) { - if (separatorHandle != 0) OS.gtk_widget_hide (separatorHandle); /* * Set the size and location of the control * separately to minimize flashing in the @@ -762,8 +819,6 @@ void resizeControl () { rect.x = itemRect.x + (itemRect.width - rect.width) / 2; rect.y = itemRect.y + (itemRect.height - rect.height) / 2; control.setLocation (rect.x, rect.y); - } else { - if (separatorHandle != 0) OS.gtk_widget_show (separatorHandle); } } @@ -877,27 +932,15 @@ public void setEnabled (boolean enabled) { } boolean setFocus () { - if ((style & SWT.SEPARATOR) != 0) return false; - if (!OS.gtk_widget_get_child_visible (handle)) return false; - OS.GTK_WIDGET_SET_FLAGS (handle, OS.GTK_CAN_FOCUS); - OS.gtk_widget_grab_focus (handle); - // widget could be disposed at this point - if (isDisposed ()) return false; - boolean result = OS.gtk_widget_is_focus (handle); - if (!result) OS.GTK_WIDGET_UNSET_FLAGS (handle, OS.GTK_CAN_FOCUS); - return result; + return OS.gtk_widget_child_focus (handle, OS.GTK_DIR_TAB_FORWARD); } void setFontDescription (int /*long*/ font) { OS.gtk_widget_modify_font (handle, font); - if (labelHandle != 0) OS.gtk_widget_modify_font (labelHandle, font); - if (imageHandle != 0) OS.gtk_widget_modify_font (imageHandle, font); } void setForegroundColor (GdkColor color) { - setForegroundColor (handle, color); - if (labelHandle != 0) setForegroundColor (labelHandle, color); - if (imageHandle != 0) setForegroundColor (imageHandle, color); + setForegroundColor (OS.gtk_bin_get_child(handle), color); } /** @@ -937,7 +980,6 @@ public void setImage (Image image) { checkWidget(); if ((style & SWT.SEPARATOR) != 0) return; super.setImage (image); - if (imageHandle == 0) return; if (image != null) { ImageList imageList = parent.imageList; if (imageList == null) imageList = parent.imageList = new ImageList (); @@ -948,11 +990,23 @@ public void setImage (Image image) { imageList.put (imageIndex, image); } int /*long*/ pixbuf = imageList.getPixbuf (imageIndex); - OS.gtk_image_set_from_pixbuf (imageHandle, pixbuf); + imageHandle = OS.gtk_image_new_from_pixbuf (pixbuf); OS.gtk_widget_show (imageHandle); } else { - OS.gtk_image_set_from_pixbuf (imageHandle, 0); - OS.gtk_widget_hide (imageHandle); + imageHandle = OS.gtk_image_new_from_pixbuf (0); + } + OS.gtk_tool_button_set_icon_widget (handle, imageHandle); + /* + * If Text/Image of a tool-item changes, then it is + * required to reset the proxy menu. Otherwise, the + * old menuItem appears in the overflow menu. + */ + if ((style & SWT.CHECK | SWT.RADIO | SWT.DROP_DOWN) != 0) { + proxyMenuItem = 0; + if ((style & SWT.DROP_DOWN) != 0) { + proxyMenuItem = OS.gtk_tool_item_retrieve_proxy_menu_item (handle); + OS.g_signal_connect(proxyMenuItem, OS.activate, ToolBar.menuItemSelectedFunc.getAddress(), handle); + } } parent.relayout (); } @@ -961,12 +1015,6 @@ void setOrientation (boolean create) { if ((parent.style & SWT.RIGHT_TO_LEFT) != 0 || !create) { int dir = (parent.style & SWT.RIGHT_TO_LEFT) != 0 ? OS.GTK_TEXT_DIR_RTL : OS.GTK_TEXT_DIR_LTR; if (handle != 0) OS.gtk_widget_set_direction (handle, dir); - if (labelHandle != 0) OS.gtk_widget_set_direction (labelHandle, dir); - if (imageHandle != 0) OS.gtk_widget_set_direction (imageHandle, dir); - if (separatorHandle != 0) OS.gtk_widget_set_direction (separatorHandle, dir); - if (arrowHandle != 0) OS.gtk_widget_set_direction (arrowHandle, dir); - if (boxHandle != 0) OS.gtk_widget_set_direction (boxHandle, dir); - if (arrowBoxHandle != 0) OS.gtk_widget_set_direction (arrowBoxHandle, dir); } } @@ -998,7 +1046,7 @@ public void setSelection (boolean selected) { checkWidget (); if ((style & (SWT.CHECK | SWT.RADIO)) == 0) return; OS.g_signal_handlers_block_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED); - OS.gtk_toggle_button_set_active (handle, selected); + OS.gtk_toggle_tool_button_set_active (handle, selected); OS.g_signal_handlers_unblock_matched (handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, CLICKED); } @@ -1034,17 +1082,48 @@ boolean setTabItemFocus (boolean next) { public void setText (String string) { checkWidget(); if (string == null) error (SWT.ERROR_NULL_ARGUMENT); - if ((style & SWT.SEPARATOR) != 0) return; + if (((style & SWT.SEPARATOR) != 0) || text.equals(string)) return; if (string.equals(this.text)) return; super.setText (string); - if (labelHandle == 0) return; char [] chars = fixMnemonic (string); byte [] buffer = Converter.wcsToMbcs (null, chars, true); - OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer); - if (string.length () != 0) { - OS.gtk_widget_show (labelHandle); + if ((style & SWT.DROP_DOWN) != 0 && OS.GTK_VERSION < OS.VERSION (2, 6, 0)) { + OS.gtk_label_set_text_with_mnemonic (labelHandle, buffer); + if (string.length () != 0) { + OS.gtk_widget_show (labelHandle); + } else { + OS.gtk_widget_hide (labelHandle); + } + } + 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 { - OS.gtk_widget_hide (labelHandle); + /* + * 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); + OS.g_signal_connect(proxyMenuItem, OS.activate, ToolBar.menuItemSelectedFunc.getAddress(), handle); } parent.relayout (); } @@ -1104,17 +1183,16 @@ public void setWidth (int width) { if ((style & SWT.SEPARATOR) == 0) return; if (width < 0) return; boolean isVertical = (parent.style & SWT.VERTICAL) != 0; - OS.gtk_widget_set_size_request (separatorHandle, width, isVertical ? 6 : 15); OS.gtk_widget_set_size_request (handle, width, isVertical ? 6 : 15); parent.relayout (); } void showWidget (int index) { if (handle != 0) OS.gtk_widget_show (handle); - if (boxHandle != 0) OS.gtk_widget_show (boxHandle); - if (separatorHandle != 0) OS.gtk_widget_show (separatorHandle); - if (arrowBoxHandle != 0) OS.gtk_widget_show (arrowBoxHandle); - if (arrowHandle != 0) OS.gtk_widget_show (arrowHandle); - OS.gtk_toolbar_insert_widget (parent.handle, handle, null, null, index); + if ((style & SWT.DROP_DOWN) != 0 && OS.GTK_VERSION < OS.VERSION (2, 6, 0)) { + if (arrowBoxHandle != 0) OS.gtk_widget_show (arrowBoxHandle); + if (arrowHandle != 0) OS.gtk_widget_show (arrowHandle); + } + OS.gtk_toolbar_insert(parent.handle, handle, index); } } 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 1357e371520..6d1b2cb2926 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 @@ -189,7 +189,8 @@ public abstract class Widget { static final int MOVE_CURSOR = 80; static final int MOVE_CURSOR_INVERSE = 81; static final int DIRECTION_CHANGED = 82; - static final int LAST_SIGNAL = 83; + static final int CREATE_MENU_PROXY = 83; + static final int LAST_SIGNAL = 84; static final String IS_ACTIVE = "org.eclipse.swt.internal.control.isactive"; //$NON-NLS-1$ static final String KEY_CHECK_SUBWINDOW = "org.eclipse.swt.internal.control.checksubwindow"; //$NON-NLS-1$ @@ -665,6 +666,10 @@ int /*long*/ gtk_configure_event (int /*long*/ widget, int /*long*/ event) { return 0; } +int /*long*/ gtk_create_menu_proxy (int /*long*/ widget) { + return 0; +} + int /*long*/ gtk_day_selected (int /*long*/ widget) { return 0; } @@ -1701,6 +1706,7 @@ int /*long*/ windowProc (int /*long*/ handle, int /*long*/ user_data) { case ACTIVATE: return gtk_activate (handle); case CHANGED: return gtk_changed (handle); case CLICKED: return gtk_clicked (handle); + case CREATE_MENU_PROXY: return gtk_create_menu_proxy (handle); case DAY_SELECTED: return gtk_day_selected (handle); case DAY_SELECTED_DOUBLE_CLICK: return gtk_day_selected_double_click (handle); case HIDE: return gtk_hide (handle); |
