Commit b663f3a0 authored by Michael Natterer's avatar Michael Natterer Committed by Michael Natterer

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.
parent 0955a595
......@@ -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;
......
......@@ -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;
}
......
......@@ -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;
......
......@@ -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;
}
......
......@@ -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);
......
......@@ -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;
}
......@@ -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);
}
......
......@@ -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);
......
......@@ -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__ */
......@@ -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;
......
......@@ -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;
}
......
......@@ -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) &&
......
......@@ -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;
......
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