summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelipe Heidrich <fheidric>2003-07-11 21:27:19 +0000
committerFelipe Heidrich <fheidric>2003-07-11 21:27:19 +0000
commit5ee66b4e4aa7e3b16413042c7ed830ba82d7da9c (patch)
tree03af6ec5a8d379e2e20075f4b362dac738ecb56f
parente191140321c16422e44c47bc2f21064b253b3377 (diff)
downloadeclipse.platform.swt-5ee66b4e4aa7e3b16413042c7ed830ba82d7da9c.tar.gz
eclipse.platform.swt-5ee66b4e4aa7e3b16413042c7ed830ba82d7da9c.tar.xz
eclipse.platform.swt-5ee66b4e4aa7e3b16413042c7ed830ba82d7da9c.zip
37428
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Control.java23
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Display.java53
-rw-r--r--bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java55
3 files changed, 101 insertions, 30 deletions
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 234379b1b9..e9f51ef0fb 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
@@ -1575,6 +1575,12 @@ int gtk_button_press_event (int widget, int event) {
display.dragStartX = (int) gdkEvent.x;
display.dragStartY = (int) gdkEvent.y;
display.dragging = false;
+ int result = 0;
+ if (gdkEvent.button == 3 && gdkEvent.type == OS.GDK_BUTTON_PRESS) {
+ if (showMenu ((int)gdkEvent.x, (int)gdkEvent.y)) {
+ result = 1;
+ }
+ }
int button = gdkEvent.button;
int type = gdkEvent.type != OS.GDK_2BUTTON_PRESS ? SWT.MouseDown : SWT.MouseDoubleClick;
sendMouseEvent (type, button, event);
@@ -1588,7 +1594,7 @@ int gtk_button_press_event (int widget, int event) {
if (!shell.isDisposed ()) {
shell.setActiveControl (this);
}
- return 0;
+ return result;
}
int gtk_button_release_event (int widget, int event) {
@@ -1622,14 +1628,6 @@ int gtk_event_after (int widget, int gdkEvent) {
GdkEvent event = new GdkEvent ();
OS.memmove (event, gdkEvent, GdkEventButton.sizeof);
switch (event.type) {
- case OS.GDK_BUTTON_PRESS: {
- GdkEventButton gdkEventButton = new GdkEventButton ();
- OS.memmove (gdkEventButton, gdkEvent, GdkEventButton.sizeof);
- if (gdkEventButton.button == 3) {
- showMenu ((int) gdkEventButton.x_root, (int) gdkEventButton.y_root);
- }
- break;
- }
case OS.GDK_FOCUS_CHANGE: {
GdkEventFocus gdkEventFocus = new GdkEventFocus ();
OS.memmove (gdkEventFocus, gdkEvent, GdkEventFocus.sizeof);
@@ -1755,8 +1753,7 @@ int gtk_motion_notify_event (int widget, int event) {
int gtk_popup_menu (int widget) {
int [] x = new int [1], y = new int [1];
OS.gdk_window_get_pointer (0, x, y, null);
- showMenu (x [0], y [0]);
- return 0;
+ return showMenu (x [0], y [0]) ? 1 : 0;
}
int gtk_preedit_changed (int imcontext) {
@@ -2560,7 +2557,7 @@ void setZOrder (Control sibling, boolean above, boolean fixChildren) {
}
}
-void showMenu (int x, int y) {
+boolean showMenu (int x, int y) {
Event event = new Event ();
event.x = x;
event.y = y;
@@ -2572,8 +2569,10 @@ void showMenu (int x, int y) {
menu.setLocation (event.x, event.y);
}
menu.setVisible (true);
+ return true;
}
}
+ return false;
}
void sort (int [] items) {
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 e222c8212d..30303c63aa 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
@@ -150,7 +150,11 @@ public class Display extends Device {
GdkColor COLOR_TEXT_FOREGROUND, COLOR_TEXT_BACKGROUND, COLOR_INFO_BACKGROUND, COLOR_INFO_FOREGROUND;
GdkColor COLOR_TITLE_FOREGROUND, COLOR_TITLE_BACKGROUND, COLOR_TITLE_BACKGROUND_GRADIENT;
GdkColor COLOR_TITLE_INACTIVE_FOREGROUND, COLOR_TITLE_INACTIVE_BACKGROUND, COLOR_TITLE_INACTIVE_BACKGROUND_GRADIENT;
-
+
+ /* Popup Menus */
+ Menu [] popups;
+ int popupTime;
+
/* Key Mappings */
static final int [] [] KeyTable = {
@@ -345,6 +349,25 @@ void addMouseHoverTimeout (int handle) {
mouseHoverHandle = handle;
}
+void addPopup (Menu menu) {
+ if (popups == null) popups = new Menu [4];
+ int length = popups.length;
+ for (int i=0; i<length; i++) {
+ if (popups [i] == menu) return;
+ }
+ int index = 0;
+ while (index < length) {
+ if (popups [index] == null) break;
+ index++;
+ }
+ if (index == length) {
+ Menu [] newPopups = new Menu [length + 4];
+ System.arraycopy (popups, 0, newPopups, 0, length);
+ popups = newPopups;
+ }
+ popups [index] = menu;
+}
+
/**
* Causes the <code>run()</code> method of the runnable to
* be invoked by the user-interface thread at the next
@@ -1507,6 +1530,7 @@ void postEvent (Event event) {
*/
public boolean readAndDispatch () {
checkDevice ();
+ runPopups ();
int status = OS.gtk_events_pending ();
if (status != 0) {
OS.gtk_main_iteration ();
@@ -1674,6 +1698,16 @@ void removeMouseHoverTimeout (int handle) {
mouseHoverId = mouseHoverHandle = 0;
}
+void removePopup (Menu menu) {
+ if (popups == null) return;
+ for (int i=0; i<popups.length; i++) {
+ if (popups [i] == menu) {
+ popups [i] = null;
+ return;
+ }
+ }
+}
+
boolean runAsyncMessages () {
return synchronizer.runAsyncMessages ();
}
@@ -1719,6 +1753,23 @@ boolean runDeferredEvents () {
return true;
}
+boolean runPopups () {
+ if (popups == null) return false;
+ boolean result = false;
+ while (popups != null) {
+ Menu menu = popups [0];
+ if (menu == null) break;
+ int length = popups.length;
+ System.arraycopy (popups, 1, popups, 0, --length);
+ popups [length] = null;
+ runDeferredEvents ();
+ menu._setVisible (true);
+ result = true;
+ }
+ popups = null;
+ return result;
+}
+
/**
* On platforms which support it, sets the application name
* to be the argument. On Motif, for example, this can be used
diff --git a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java
index 82cd84c747..ad00d817d2 100644
--- a/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java
+++ b/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/Menu.java
@@ -153,6 +153,27 @@ static int checkStyle (int style) {
return checkBits (style, SWT.POP_UP, SWT.BAR, SWT.DROP_DOWN, 0, 0, 0);
}
+public void _setVisible (boolean visible) {
+ if (visible == OS.GTK_WIDGET_MAPPED (handle)) return;
+ if (visible) {
+ sendEvent (SWT.Show);
+ if (getItemCount () != 0) {
+ int address = 0;
+ Callback GtkMenuPositionFunc = null;
+ if (hasLocation) {
+ GtkMenuPositionFunc = new Callback (this, "GtkMenuPositionFunc", 5);
+ address = GtkMenuPositionFunc.getAddress ();
+ }
+ OS.gtk_menu_popup (handle, 0, 0, address, 0, 0, display.popupTime);
+ if (GtkMenuPositionFunc != null) GtkMenuPositionFunc.dispose ();
+ } else {
+ sendEvent (SWT.Hide);
+ }
+ } else {
+ OS.gtk_menu_popdown (handle);
+ }
+}
+
void addAccelerators (int accelGroup) {
MenuItem [] items = getItems ();
for (int i = 0; i < items.length; i++) {
@@ -484,7 +505,15 @@ public Shell getShell () {
*/
public boolean getVisible () {
checkWidget();
- return OS.GTK_WIDGET_MAPPED (handle);
+ if ((style & SWT.POP_UP) != 0) {
+ Menu [] popups = display.popups;
+ if (popups != null) {
+ for (int i=0; i<popups.length; i++) {
+ if (popups [i] == this) return true;
+ }
+ }
+ }
+ return OS.GTK_WIDGET_MAPPED (handle);
}
int GtkMenuPositionFunc (int menu, int x, int y, int push_in, int user_data) {
@@ -600,6 +629,10 @@ void releaseChild () {
if (cascade != null) cascade.setMenu (null);
if ((style & SWT.BAR) != 0 && this == parent.menuBar) {
parent.setMenuBar (null);
+ } else {
+ if ((style & SWT.POP_UP) != 0) {
+ display.removePopup (this);
+ }
}
}
@@ -796,24 +829,12 @@ public void setLocation (Point location) {
public void setVisible (boolean visible) {
checkWidget();
if ((style & (SWT.BAR | SWT.DROP_DOWN)) != 0) return;
- if (visible == OS.GTK_WIDGET_MAPPED (handle)) return;
if (visible) {
- display.runDeferredEvents ();
- sendEvent (SWT.Show);
- if (getItemCount () != 0) {
- int address = 0;
- Callback GtkMenuPositionFunc = null;
- if (hasLocation) {
- GtkMenuPositionFunc = new Callback (this, "GtkMenuPositionFunc", 5);
- address = GtkMenuPositionFunc.getAddress ();
- }
- OS.gtk_menu_popup (handle, 0, 0, address, 0, 0, OS.gtk_get_current_event_time());
- if (GtkMenuPositionFunc != null) GtkMenuPositionFunc.dispose ();
- } else {
- sendEvent (SWT.Hide);
- }
+ display.popupTime = OS.gtk_get_current_event_time();
+ display.addPopup (this);
} else {
- OS.gtk_menu_popdown (handle);
+ display.removePopup (this);
+ _setVisible (false);
}
}
}