diff options
author | Michael Natterer <mitch@lanedo.com> | 2011-09-27 15:37:28 +0200 |
---|---|---|
committer | Michael Natterer <mitch@gimp.org> | 2011-09-27 15:45:18 +0200 |
commit | 2d3db3421fd8067dd9c59a0727da239936187cc5 (patch) | |
tree | c9668bfba51b4df9dd76b478cc3c1b10e51973cd | |
parent | 27cbbc4a7d8e8f010b5b83f7563b6cc36926c8cb (diff) | |
download | gtk+-2d3db3421fd8067dd9c59a0727da239936187cc5.tar.gz |
Bug 659406 - Abstract what triggers a context menu
Add gdk_event_triggers_context_menu(), using the new modifier
abstraction API. Remove _gtk_button_event_triggers_context_menu()
and port all callers.
-rw-r--r-- | gdk/gdkevents.c | 50 | ||||
-rw-r--r-- | gdk/gdkevents.h | 3 | ||||
-rw-r--r-- | gtk/gtkcolorsel.c | 2 | ||||
-rw-r--r-- | gtk/gtkentry.c | 2 | ||||
-rw-r--r-- | gtk/gtkfilechooserdefault.c | 4 | ||||
-rw-r--r-- | gtk/gtklabel.c | 4 | ||||
-rw-r--r-- | gtk/gtklinkbutton.c | 4 | ||||
-rw-r--r-- | gtk/gtkmain.c | 20 | ||||
-rw-r--r-- | gtk/gtkmountoperation.c | 2 | ||||
-rw-r--r-- | gtk/gtknotebook.c | 2 | ||||
-rw-r--r-- | gtk/gtkprivate.h | 2 | ||||
-rw-r--r-- | gtk/gtkrecentchooserdefault.c | 4 | ||||
-rw-r--r-- | gtk/gtkstatusicon.c | 2 | ||||
-rw-r--r-- | gtk/gtktextview.c | 2 | ||||
-rw-r--r-- | gtk/gtktoolbar.c | 2 |
15 files changed, 66 insertions, 39 deletions
diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c index ae42b4ffa4..eeaac2dccc 100644 --- a/gdk/gdkevents.c +++ b/gdk/gdkevents.c @@ -1448,6 +1448,56 @@ gdk_event_request_motions (const GdkEventMotion *event) } } +/** + * gdk_event_triggers_context_menu: + * @event: a #GdkEvent, currently only button events are meaningful values + * + * This function returns whether a #GdkEventButton should trigger a + * context menu, according to platform conventions. The right mouse + * button always triggers context menus. Additionally, if + * gdk_keymap_get_modifier_mask() returns a non-0 mask for + * %GDK_MODIFIER_INTENT_CONTEXT_MENU, then the left mouse button will + * also trigger a context menu if this modifier is pressed. + * + * This function should always be used instead of simply checking for + * event->button == 3. + * + * Returns: %TRUE if the event should trigger a context menu. + * + * Since: 3.4 + **/ +gboolean +gdk_event_triggers_context_menu (const GdkEvent *event) +{ + g_return_val_if_fail (event != NULL, FALSE); + + if (event->type == GDK_BUTTON_PRESS) + { + const GdkEventButton *bevent = (const GdkEventButton *) event; + GdkDisplay *display; + GdkModifierType modifier; + + g_return_val_if_fail (GDK_IS_WINDOW (bevent->window), FALSE); + + if (bevent->button == 3 && + ! (bevent->state & (GDK_BUTTON1_MASK | GDK_BUTTON2_MASK))) + return TRUE; + + display = gdk_window_get_display (bevent->window); + + modifier = gdk_keymap_get_modifier_mask (gdk_keymap_get_for_display (display), + GDK_MODIFIER_INTENT_CONTEXT_MENU); + + if (modifier != 0 && + bevent->button == 1 && + ! (bevent->state & (GDK_BUTTON2_MASK | GDK_BUTTON3_MASK)) && + (bevent->state & modifier)) + return TRUE; + } + + return FALSE; +} + static gboolean gdk_events_get_axis_distances (GdkEvent *event1, GdkEvent *event2, diff --git a/gdk/gdkevents.h b/gdk/gdkevents.h index 8bf7d565d6..24a3b8ea4b 100644 --- a/gdk/gdkevents.h +++ b/gdk/gdkevents.h @@ -1076,7 +1076,8 @@ GdkDevice* gdk_event_get_device (const GdkEvent *event); void gdk_event_set_source_device (GdkEvent *event, GdkDevice *device); GdkDevice* gdk_event_get_source_device (const GdkEvent *event); -void gdk_event_request_motions (const GdkEventMotion *event); +void gdk_event_request_motions (const GdkEventMotion *event); +gboolean gdk_event_triggers_context_menu (const GdkEvent *event); gboolean gdk_events_get_distance (GdkEvent *event1, GdkEvent *event2, diff --git a/gtk/gtkcolorsel.c b/gtk/gtkcolorsel.c index 3b8f048d08..d66067209b 100644 --- a/gtk/gtkcolorsel.c +++ b/gtk/gtkcolorsel.c @@ -1505,7 +1505,7 @@ palette_press (GtkWidget *drawing_area, gtk_widget_grab_focus (drawing_area); - if (_gtk_button_event_triggers_context_menu (event)) + if (gdk_event_triggers_context_menu ((GdkEvent *) event)) { do_popup (colorsel, drawing_area, event->time); return TRUE; diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c index c22cb0eaf8..180646425b 100644 --- a/gtk/gtkentry.c +++ b/gtk/gtkentry.c @@ -3774,7 +3774,7 @@ gtk_entry_button_press (GtkWidget *widget, tmp_pos = gtk_entry_find_position (entry, event->x + priv->scroll_offset); - if (_gtk_button_event_triggers_context_menu (event)) + if (gdk_event_triggers_context_menu ((GdkEvent *) event)) { gtk_entry_do_popup (entry, event); priv->button = 0; /* Don't wait for release, since the menu will gtk_grab_add */ diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c index 8c3db4cb94..896b8781d4 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 (!_gtk_button_event_triggers_context_menu (event)) + if (!gdk_event_triggers_context_menu ((GdkEvent *) event)) return FALSE; in_press = TRUE; @@ -4300,7 +4300,7 @@ list_button_press_event_cb (GtkWidget *widget, if (in_press) return FALSE; - if (!_gtk_button_event_triggers_context_menu (event)) + if (!gdk_event_triggers_context_menu ((GdkEvent *) event)) return FALSE; in_press = TRUE; diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c index 00422a5347..35467490fd 100644 --- a/gtk/gtklabel.c +++ b/gtk/gtklabel.c @@ -4715,7 +4715,7 @@ gtk_label_button_press (GtkWidget *widget, if (info->active_link) { - if (_gtk_button_event_triggers_context_menu (event)) + if (gdk_event_triggers_context_menu ((GdkEvent *) event)) { info->link_clicked = 1; gtk_label_do_popup (label, event); @@ -4734,7 +4734,7 @@ gtk_label_button_press (GtkWidget *widget, info->in_drag = FALSE; info->select_words = FALSE; - if (_gtk_button_event_triggers_context_menu (event)) + if (gdk_event_triggers_context_menu ((GdkEvent *) event)) { gtk_label_do_popup (label, event); diff --git a/gtk/gtklinkbutton.c b/gtk/gtklinkbutton.c index 0fdcbeab25..ffa89c086f 100644 --- a/gtk/gtklinkbutton.c +++ b/gtk/gtklinkbutton.c @@ -522,10 +522,10 @@ gtk_link_button_button_press (GtkWidget *widget, if (!gtk_widget_has_focus (widget)) gtk_widget_grab_focus (widget); - if (_gtk_button_event_triggers_context_menu (event)) + if (gdk_event_triggers_context_menu ((GdkEvent *) event)) { gtk_link_button_do_popup (GTK_LINK_BUTTON (widget), event); - + return TRUE; } diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c index e42f730392..a0ca89dfb5 100644 --- a/gtk/gtkmain.c +++ b/gtk/gtkmain.c @@ -2643,23 +2643,3 @@ _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 dea21f5491..c1ad3dac3d 100644 --- a/gtk/gtkmountoperation.c +++ b/gtk/gtkmountoperation.c @@ -1167,7 +1167,7 @@ on_button_press_event_for_process_tree_view (GtkWidget *widget, ret = FALSE; - if (_gtk_button_event_triggers_context_menu (event)) + 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 afc51d35c9..8ea2c6c9aa 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 (priv->menu && _gtk_button_event_triggers_context_menu (event)) + if (priv->menu && gdk_event_triggers_context_menu ((GdkEvent *) 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 0def8c12ee..458a4b95ae 100644 --- a/gtk/gtkprivate.h +++ b/gtk/gtkprivate.h @@ -83,8 +83,6 @@ 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 7adc1aebd6..160b37f0a4 100644 --- a/gtk/gtkrecentchooserdefault.c +++ b/gtk/gtkrecentchooserdefault.c @@ -74,8 +74,6 @@ #include "gtkrecentchooserutils.h" #include "gtkrecentchooserdefault.h" -#include "gtkprivate.h" - enum { @@ -1905,7 +1903,7 @@ recent_view_button_press_cb (GtkWidget *widget, { GtkRecentChooserDefault *impl = GTK_RECENT_CHOOSER_DEFAULT (user_data); - if (_gtk_button_event_triggers_context_menu (event)) + if (gdk_event_triggers_context_menu ((GdkEvent *) event)) { GtkTreePath *path; gboolean res; diff --git a/gtk/gtkstatusicon.c b/gtk/gtkstatusicon.c index 27a2b144d9..4f4dfb86aa 100644 --- a/gtk/gtkstatusicon.c +++ b/gtk/gtkstatusicon.c @@ -1810,7 +1810,7 @@ gtk_status_icon_button_press (GtkStatusIcon *status_icon, if (handled) return TRUE; - if (_gtk_button_event_triggers_context_menu (event)) + if (gdk_event_triggers_context_menu ((GdkEvent *) event)) { emit_popup_menu_signal (status_icon, event->button, event->time); return TRUE; diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c index e128c3a14d..a2e5020b3d 100644 --- a/gtk/gtktextview.c +++ b/gtk/gtktextview.c @@ -4545,7 +4545,7 @@ gtk_text_view_button_press_event (GtkWidget *widget, GdkEventButton *event) { gtk_text_view_reset_im_context (text_view); - if (_gtk_button_event_triggers_context_menu (event)) + if (gdk_event_triggers_context_menu ((GdkEvent *) event)) { gtk_text_view_do_popup (text_view, event); return TRUE; diff --git a/gtk/gtktoolbar.c b/gtk/gtktoolbar.c index dd3d05ef77..ba6ccb5c16 100644 --- a/gtk/gtktoolbar.c +++ b/gtk/gtktoolbar.c @@ -2748,7 +2748,7 @@ gtk_toolbar_button_press (GtkWidget *toolbar, { GtkWidget *window; - if (_gtk_button_event_triggers_context_menu (event)) + if (gdk_event_triggers_context_menu ((GdkEvent *) event)) { gboolean return_value; |