summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAnatoly Spektor <aspektor@redhat.com>2012-09-04 09:57:21 -0400
committerAnatoly Spektor <aspektor@redhat.com>2012-09-04 09:57:21 -0400
commit701a9c9f370c848f128ac2ab9ae7a599771e0cf7 (patch)
tree9601de19eb0961aea1d34f2b57246233b5ced876
parent1ed3903786f6bebf8409c53f08a88ae76e85baca (diff)
parent3ca06f3dce8760dd92c325183d782ac24428fc09 (diff)
downloadeclipse.platform.swt-701a9c9f370c848f128ac2ab9ae7a599771e0cf7.tar.gz
eclipse.platform.swt-701a9c9f370c848f128ac2ab9ae7a599771e0cf7.tar.xz
eclipse.platform.swt-701a9c9f370c848f128ac2ab9ae7a599771e0cf7.zip
Merge branch 'master' of http://git.eclipse.org/gitroot/platform/eclipse.platform.swt.git
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Combo.java119
-rw-r--r--tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java18
2 files changed, 87 insertions, 50 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 942aa0c249..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,37 +535,41 @@ 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;
+ 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;
- break;
+ int /*long*/ widget = OS.g_list_data (list);
+ if (OS.G_OBJECT_TYPE (widget) == OS.GTK_TYPE_MENU ()) {
+ result = widget;
+ break;
+ }
+ list = OS.g_list_next (list);
}
- list = OS.g_list_next (list);
- }
OS.g_list_free (display.allChildren);
display.allChildren = 0;
}
+ return result;
}
void fixModal (int /*long*/ group, int /*long*/ modalGroup) {
@@ -605,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 ();
}
@@ -627,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<handles.length; i++) {
int /*long*/ eventHandle = handles [i];
if (eventHandle != 0) {
@@ -653,17 +668,11 @@ void hookEvents () {
if (eventHandle != focusHandle ()) {
OS.g_signal_connect_closure_by_id (eventHandle, display.signalIds [EVENT_AFTER], 0, display.closures [EVENT_AFTER], false);
}
+ if (OS.G_OBJECT_TYPE (eventHandle) == OS.GTK_TYPE_MENU ()) {
+ OS.g_signal_connect_closure(eventHandle, OS.selection_done, display.closures[SELECTION_DONE], true);
+ }
}
}
- 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);
- }
-
- if (menuHandle != 0) OS.g_signal_connect_closure(menuHandle, OS.selection_done, display.closures[SELECTION_DONE], true);
}
int /*long*/ imContext () {
@@ -1224,19 +1233,6 @@ int /*long*/ gtk_event_after (int /*long*/ widget, int /*long*/ gdkEvent) {
OS.memmove (event, gdkEvent, GdkEvent.sizeof);
switch (event.type) {
case OS.GDK_BUTTON_PRESS: {
- if (OS.GTK_VERSION < OS.VERSION (2, 8, 0) && !selectionAdded) {
- int /*long*/ grabHandle = OS.gtk_grab_get_current ();
- if (grabHandle != 0) {
- if (OS.G_OBJECT_TYPE (grabHandle) == OS.GTK_TYPE_MENU ()) {
- menuHandle = grabHandle;
- OS.g_signal_connect_closure_by_id (menuHandle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT], false);
- OS.g_signal_connect_closure_by_id (menuHandle, display.signalIds [BUTTON_RELEASE_EVENT], 0, display.closures [BUTTON_RELEASE_EVENT_INVERSE], true);
- OS.g_signal_connect_closure (menuHandle, OS.selection_done, display.closures [SELECTION_DONE], false);
- display.addWidget (menuHandle, this);
- selectionAdded = true;
- }
- }
- }
GdkEventButton gdkEventButton = new GdkEventButton ();
OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof);
if (gdkEventButton.button == 1) {
@@ -1383,6 +1379,13 @@ int /*long*/ gtk_selection_done(int /*long*/ menushell) {
}
return 0;
}
+
+int /*long*/ gtk_style_set (int /*long*/ widget, int /*long*/ previousStyle) {
+ setButtonHandle (findButtonHandle ());
+ setMenuHandle (findMenuHandle ());
+ return super.gtk_style_set (widget, previousStyle);
+}
+
/**
* Searches the receiver's list starting at the first item
* (index 0) until an item is found that is equal to the
@@ -1486,7 +1489,13 @@ void register () {
void releaseHandle () {
super.releaseHandle ();
- buttonHandle = entryHandle = 0;
+ if (menuHandle != 0) {
+ OS.g_object_unref (menuHandle);
+ }
+ if (buttonHandle != 0) {
+ OS.g_object_unref (buttonHandle);
+ }
+ menuHandle = buttonHandle = entryHandle = 0;
}
void releaseWidget () {
@@ -1717,6 +1726,34 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize
return super.setBounds (x, y, width, newHeight, move, resize);
}
+void setButtonHandle (int /*long*/ widget) {
+ if (buttonHandle == widget) return;
+ if (buttonHandle != 0) {
+ display.removeWidget (buttonHandle);
+ OS.g_object_unref (buttonHandle);
+ }
+ buttonHandle = widget;
+ if (buttonHandle != 0) {
+ OS.g_object_ref (buttonHandle);
+ display.addWidget (buttonHandle, this);
+ hookEvents (new int /*long*/[]{buttonHandle});
+ }
+}
+
+void setMenuHandle (int /*long*/ widget) {
+ if (menuHandle == widget) return;
+ if (menuHandle != 0) {
+ display.removeWidget (menuHandle);
+ OS.g_object_unref (menuHandle);
+ }
+ menuHandle = widget;
+ if (menuHandle != 0) {
+ OS.g_object_ref (menuHandle);
+ display.addWidget (menuHandle, this);
+ hookEvents (new int /*long*/[]{menuHandle});
+ }
+}
+
void setFontDescription (int /*long*/ font) {
super.setFontDescription (font);
if (entryHandle != 0) OS.gtk_widget_modify_font (entryHandle, font);
diff --git a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java
index d087b17caa..5ef2020718 100644
--- a/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java
+++ b/tests/org.eclipse.swt.tests/JUnit Tests/org/eclipse/swt/tests/junit/Test_org_eclipse_swt_widgets_Display.java
@@ -719,15 +719,15 @@ public void test_postLorg_eclipse_swt_widgets_Event() {
// Test key events (down/up)
event = new Event();
- event.type = SWT.KeyDown;
- event.keyCode = -1; // bogus key code
- assertTrue(display.post(event)); // uses default 0 character
- // don't test KeyDown/KeyUp with a character to avoid sending to
- // random window if test shell looses focus
-
- event = new Event();
- event.type = SWT.KeyUp;
- assertTrue(display.post(event));
+// event.type = SWT.KeyDown;
+// event.keyCode = -1; // bogus key code
+// assertTrue(display.post(event)); // uses default 0 character
+// // don't test KeyDown/KeyUp with a character to avoid sending to
+// // random window if test shell looses focus
+//
+// event = new Event();
+// event.type = SWT.KeyUp;
+// assertTrue(display.post(event));
event.type = SWT.KeyDown;
event.keyCode = KEYCODE;