[gtk+] Bug 659406 - Abstract what triggers a context menu
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+] Bug 659406 - Abstract what triggers a context menu
- Date: Mon, 26 Sep 2011 14:03:17 +0000 (UTC)
commit b663f3a00bc3d9a5f1e17eebe742ee14504fdcac
Author: Michael Natterer <mitch lanedo com>
Date: Mon Sep 19 00:32:52 2011 +0200
Bug 659406 - Abstract what triggers a context menu
Add _gtk_button_event_triggers_context_menu() and use it instead
of checking for event->button == 3, so context menus are invoked
correctly on the Mac.
gtk/gtkcolorsel.c | 3 +--
gtk/gtkentry.c | 20 ++++++++++----------
gtk/gtkfilechooserdefault.c | 4 ++--
gtk/gtklabel.c | 23 ++++++++++++-----------
gtk/gtklinkbutton.c | 3 ++-
gtk/gtkmain.c | 20 ++++++++++++++++++++
gtk/gtkmountoperation.c | 3 +--
gtk/gtknotebook.c | 2 +-
gtk/gtkprivate.h | 2 ++
gtk/gtkrecentchooserdefault.c | 4 ++--
gtk/gtkstatusicon.c | 8 ++++----
gtk/gtktextview.c | 12 ++++++------
gtk/gtktoolbar.c | 2 +-
13 files changed, 64 insertions(+), 42 deletions(-)
---
diff --git a/gtk/gtkcolorsel.c b/gtk/gtkcolorsel.c
index a2ab2b4..3b8f048 100644
--- a/gtk/gtkcolorsel.c
+++ b/gtk/gtkcolorsel.c
@@ -1505,8 +1505,7 @@ palette_press (GtkWidget *drawing_area,
gtk_widget_grab_focus (drawing_area);
- if (event->button == 3 &&
- event->type == GDK_BUTTON_PRESS)
+ if (_gtk_button_event_triggers_context_menu (event))
{
do_popup (colorsel, drawing_area, event->time);
return TRUE;
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 21c0ee2..f9ad68a 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -3771,10 +3771,17 @@ gtk_entry_button_press (GtkWidget *widget,
gtk_widget_grab_focus (widget);
priv->in_click = FALSE;
}
-
+
tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset);
-
- if (event->button == 1)
+
+ if (_gtk_button_event_triggers_context_menu (event))
+ {
+ gtk_entry_do_popup (entry, event);
+ priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
+
+ return TRUE;
+ }
+ else if (event->button == 1)
{
gboolean have_selection = gtk_editable_get_selection_bounds (editable, &sel_start, &sel_end);
@@ -3895,13 +3902,6 @@ gtk_entry_button_press (GtkWidget *widget,
gtk_widget_error_bell (widget);
}
}
- else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
- {
- gtk_entry_do_popup (entry, event);
- priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */
-
- return TRUE;
- }
return FALSE;
}
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 07ed02c..5ea074d 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -3448,7 +3448,7 @@ shortcuts_button_press_event_cb (GtkWidget *widget,
if (in_press)
return FALSE;
- if (event->button != 3)
+ if (!_gtk_button_event_triggers_context_menu (event))
return FALSE;
in_press = TRUE;
@@ -4296,7 +4296,7 @@ list_button_press_event_cb (GtkWidget *widget,
if (in_press)
return FALSE;
- if (event->button != 3)
+ if (!_gtk_button_event_triggers_context_menu (event))
return FALSE;
in_press = TRUE;
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 70b513e..00422a5 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -4715,16 +4715,16 @@ gtk_label_button_press (GtkWidget *widget,
if (info->active_link)
{
- if (event->button == 1)
+ if (_gtk_button_event_triggers_context_menu (event))
{
info->link_clicked = 1;
- gtk_widget_queue_draw (widget);
+ gtk_label_do_popup (label, event);
+ return TRUE;
}
- else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
+ else if (event->button == 1)
{
info->link_clicked = 1;
- gtk_label_do_popup (label, event);
- return TRUE;
+ gtk_widget_queue_draw (widget);
}
}
@@ -4734,7 +4734,13 @@ gtk_label_button_press (GtkWidget *widget,
info->in_drag = FALSE;
info->select_words = FALSE;
- if (event->button == 1)
+ if (_gtk_button_event_triggers_context_menu (event))
+ {
+ gtk_label_do_popup (label, event);
+
+ return TRUE;
+ }
+ else if (event->button == 1)
{
if (!gtk_widget_has_focus (widget))
{
@@ -4808,12 +4814,7 @@ gtk_label_button_press (GtkWidget *widget,
return TRUE;
}
- else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
- {
- gtk_label_do_popup (label, event);
- return TRUE;
- }
return FALSE;
}
diff --git a/gtk/gtklinkbutton.c b/gtk/gtklinkbutton.c
index bd2ca65..0fdcbea 100644
--- a/gtk/gtklinkbutton.c
+++ b/gtk/gtklinkbutton.c
@@ -63,6 +63,7 @@
#include "gtkstock.h"
#include "gtkshow.h"
#include "gtktooltip.h"
+#include "gtkprivate.h"
#include "gtkintl.h"
#include "a11y/gtklinkbuttonaccessible.h"
@@ -521,7 +522,7 @@ gtk_link_button_button_press (GtkWidget *widget,
if (!gtk_widget_has_focus (widget))
gtk_widget_grab_focus (widget);
- if ((event->button == 3) && (event->type == GDK_BUTTON_PRESS))
+ if (_gtk_button_event_triggers_context_menu (event))
{
gtk_link_button_do_popup (GTK_LINK_BUTTON (widget), event);
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index a0ca89d..e42f730 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -2643,3 +2643,23 @@ _gtk_boolean_handled_accumulator (GSignalInvocationHint *ihint,
return continue_emission;
}
+
+gboolean
+_gtk_button_event_triggers_context_menu (GdkEventButton *event)
+{
+ if (event->type == GDK_BUTTON_PRESS)
+ {
+ if (event->button == 3 &&
+ ! (event->state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK)))
+ return TRUE;
+
+#ifdef GDK_WINDOWING_QUARTZ
+ if (event->button == 1 &&
+ ! (event->state & (GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)) &&
+ (event->state & GDK_CONTROL_MASK))
+ return TRUE;
+#endif
+ }
+
+ return FALSE;
+}
diff --git a/gtk/gtkmountoperation.c b/gtk/gtkmountoperation.c
index 2d022cc..dea21f5 100644
--- a/gtk/gtkmountoperation.c
+++ b/gtk/gtkmountoperation.c
@@ -1167,8 +1167,7 @@ on_button_press_event_for_process_tree_view (GtkWidget *widget,
ret = FALSE;
- /* Ignore double-clicks and triple-clicks */
- if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
+ if (_gtk_button_event_triggers_context_menu (event))
{
ret = do_popup_menu_for_process_tree_view (widget, event, op);
}
diff --git a/gtk/gtknotebook.c b/gtk/gtknotebook.c
index a518e9c..afc51d3 100644
--- a/gtk/gtknotebook.c
+++ b/gtk/gtknotebook.c
@@ -2858,7 +2858,7 @@ gtk_notebook_button_press (GtkWidget *widget,
if (arrow)
return gtk_notebook_arrow_button_press (notebook, arrow, event->button);
- if (event->button == 3 && priv->menu)
+ if (priv->menu && _gtk_button_event_triggers_context_menu (event))
{
gtk_menu_popup (GTK_MENU (priv->menu), NULL, NULL,
NULL, NULL, 3, event->time);
diff --git a/gtk/gtkprivate.h b/gtk/gtkprivate.h
index 00e9bbe..5778958 100644
--- a/gtk/gtkprivate.h
+++ b/gtk/gtkprivate.h
@@ -101,6 +101,8 @@ void _gtk_modules_init (gint *argc,
void _gtk_modules_settings_changed (GtkSettings *settings,
const gchar *modules);
+gboolean _gtk_button_event_triggers_context_menu (GdkEventButton *event);
+
G_END_DECLS
#endif /* __GTK_PRIVATE_H__ */
diff --git a/gtk/gtkrecentchooserdefault.c b/gtk/gtkrecentchooserdefault.c
index 20b66b5..7adc1ae 100644
--- a/gtk/gtkrecentchooserdefault.c
+++ b/gtk/gtkrecentchooserdefault.c
@@ -1904,8 +1904,8 @@ recent_view_button_press_cb (GtkWidget *widget,
gpointer user_data)
{
GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data);
-
- if (event->button == 3)
+
+ if (_gtk_button_event_triggers_context_menu (event))
{
GtkTreePath *path;
gboolean res;
diff --git a/gtk/gtkstatusicon.c b/gtk/gtkstatusicon.c
index 8d5a0ef..27a2b14 100644
--- a/gtk/gtkstatusicon.c
+++ b/gtk/gtkstatusicon.c
@@ -1810,14 +1810,14 @@ gtk_status_icon_button_press (GtkStatusIcon *status_icon,
if (handled)
return TRUE;
- if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
+ if (_gtk_button_event_triggers_context_menu (event))
{
- emit_activate_signal (status_icon);
+ emit_popup_menu_signal (status_icon, event->button, event->time);
return TRUE;
}
- else if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
+ else if (event->button == 1 && event->type == GDK_BUTTON_PRESS)
{
- emit_popup_menu_signal (status_icon, event->button, event->time);
+ emit_activate_signal (status_icon);
return TRUE;
}
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 3085966..9b07334 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -4545,7 +4545,12 @@ gtk_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
{
gtk_text_view_reset_im_context (text_view);
- if (event->button == 1)
+ if (_gtk_button_event_triggers_context_menu (event))
+ {
+ gtk_text_view_do_popup (text_view, event);
+ return TRUE;
+ }
+ else if (event->button == 1)
{
/* If we're in the selection, start a drag copy/move of the
* selection; otherwise, start creating a new selection.
@@ -4593,11 +4598,6 @@ gtk_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event)
priv->editable);
return TRUE;
}
- else if (event->button == 3)
- {
- gtk_text_view_do_popup (text_view, event);
- return TRUE;
- }
}
else if ((event->type == GDK_2BUTTON_PRESS ||
event->type == GDK_3BUTTON_PRESS) &&
diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c
index 5692b60..a8cb86d 100644
--- a/gtk/gtktoolbar.c
+++ b/gtk/gtktoolbar.c
@@ -2744,7 +2744,7 @@ gtk_toolbar_button_press (GtkWidget *toolbar,
{
GtkWidget *window;
- if (event->button == 3)
+ if (_gtk_button_event_triggers_context_menu (event))
{
gboolean return_value;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]