Commit 2d3db342 authored by Michael Natterer's avatar Michael Natterer Committed by Michael Natterer

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.
parent 27cbbc4a
......@@ -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,
......
......@@ -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,
......
......@@ -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;
......
......@@ -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 */
......
......@@ -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;
......
......@@ -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);
......
......@@ -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;
}
......
......@@ -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;
}
......@@ -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);
}
......
......@@ -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);
......
......@@ -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__ */
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment