From 8a770faaa4942f4e1cde0428ab3348bcc4c88e3f Mon Sep 17 00:00:00 2001 From: Silenio Quarti Date: Fri, 31 Aug 2012 04:19:33 -0400 Subject: Bug 383189 - Warnings and Errors in the SWT Combo when running on Linux --- .../gtk/org/eclipse/swt/widgets/Combo.java | 104 +++++++++++++-------- 1 file changed, 66 insertions(+), 38 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 2199d28a60..a0fcb98f99 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 @@ -341,7 +341,7 @@ void clearText () { public Point computeSize (int wHint, int hHint, boolean changed) { checkWidget (); - if ((style & SWT.READ_ONLY) != 0 || menuHandle != 0) { + if ((style & SWT.READ_ONLY) != 0) { return computeNativeSize (handle, wHint, hHint, changed); } if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0; @@ -441,8 +441,10 @@ void createHandle (int index) { if (OS.GTK_VERSION < OS.VERSION (2, 8, 0)) { OS.gtk_widget_size_request(handle, new GtkRequisition()); } - if (popupHandle != 0) findMenuHandle (); - findButtonHandle (); + menuHandle = findMenuHandle (); + if (menuHandle != 0) OS.g_object_ref (menuHandle); + buttonHandle = findButtonHandle (); + if (buttonHandle != 0) OS.g_object_ref (buttonHandle); /* * Feature in GTK. By default, read only combo boxes * process the RETURN key rather than allowing the @@ -525,8 +527,7 @@ int /*long*/ findPopupHandle (int /*long*/ oldList) { return result; } - -void findButtonHandle() { +int /*long*/ findButtonHandle() { /* * Feature in GTK. There is no API to query the button * handle from a combo box although it is possible to get the @@ -534,32 +535,33 @@ void findButtonHandle() { * fix is to walk the combo tree and find the first child that is * an instance of button. */ + int /*long*/ result = 0; OS.gtk_container_forall (handle, display.allChildrenProc, 0); if (display.allChildren != 0) { int /*long*/ list = display.allChildren; while (list != 0) { int /*long*/ widget = OS.g_list_data (list); if (OS.GTK_IS_BUTTON (widget)) { - buttonHandle = widget; - OS.g_object_ref (buttonHandle); + result = widget; break; } - list = OS.g_list_next (list); } OS.g_list_free (display.allChildren); display.allChildren = 0; } + return result; } -void findMenuHandle() { +int /*long*/ findMenuHandle() { + if (popupHandle == 0) return 0; + int /*long*/ result = 0; OS.gtk_container_forall (popupHandle, display.allChildrenProc, 0); if (display.allChildren != 0) { int /*long*/ list = display.allChildren; while (list != 0) { int /*long*/ widget = OS.g_list_data (list); if (OS.G_OBJECT_TYPE (widget) == OS.GTK_TYPE_MENU ()) { - menuHandle = widget; - OS.g_object_ref (menuHandle); + result = widget; break; } list = OS.g_list_next (list); @@ -567,6 +569,7 @@ void findMenuHandle() { OS.g_list_free (display.allChildren); display.allChildren = 0; } + return result; } void fixModal (int /*long*/ group, int /*long*/ modalGroup) { @@ -607,7 +610,6 @@ int /*long*/ fontHandle () { } int /*long*/ focusHandle () { - if ((style & SWT.READ_ONLY) != 0 && buttonHandle != 0) return buttonHandle; if (entryHandle != 0) return entryHandle; return super.focusHandle (); } @@ -629,9 +631,20 @@ void hookEvents () { OS.g_signal_connect_closure (entryHandle, OS.activate, display.closures [ACTIVATE], false); OS.g_signal_connect_closure (entryHandle, OS.populate_popup, display.closures [POPULATE_POPUP], false); } - int eventMask = OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_PRESS_MASK | - OS.GDK_BUTTON_RELEASE_MASK; - int /*long*/ [] handles = new int /*long*/ [] {buttonHandle, entryHandle, menuHandle}; + + hookEvents(new int /*long*/ [] {buttonHandle, entryHandle, menuHandle}); + + int /*long*/ imContext = imContext (); + if (imContext != 0) { + OS.g_signal_connect_closure (imContext, OS.commit, display.closures [COMMIT], false); + int id = OS.g_signal_lookup (OS.commit, OS.gtk_im_context_get_type ()); + int blockMask = OS.G_SIGNAL_MATCH_DATA | OS.G_SIGNAL_MATCH_ID; + OS.g_signal_handlers_block_matched (imContext, blockMask, id, 0, 0, 0, entryHandle); + } +} + +void hookEvents(int /*long*/ [] handles) { + int eventMask = OS.GDK_POINTER_MOTION_MASK | OS.GDK_BUTTON_PRESS_MASK | OS.GDK_BUTTON_RELEASE_MASK; for (int i=0; i