Commit d92cd2f6 authored by Michael Natterer's avatar Michael Natterer 😴
Browse files

Add gimp_button_event_triggers_context_menu() and use it

instead of checking for event->button == 3, so context menus
work correctly on the Mac. Didn't change the image menu yet
because thet requires some more refactoring.
parent f8a2644b
......@@ -298,7 +298,7 @@ gimp_display_shell_origin_button_press (GtkWidget *widget,
{
if (! shell->display->gimp->busy)
{
if (event->button == 1)
if (event->type == GDK_BUTTON_PRESS && event->button == 1)
{
gboolean unused;
......@@ -320,7 +320,7 @@ gimp_display_shell_quick_mask_button_press (GtkWidget *widget,
if (! gimp_display_get_image (shell->display))
return TRUE;
if ((bevent->type == GDK_BUTTON_PRESS) && (bevent->button == 3))
if (gimp_button_event_triggers_context_menu (bevent))
{
GimpImageWindow *window = gimp_display_shell_get_window (shell);
......@@ -363,7 +363,7 @@ gimp_display_shell_navigation_button_press (GtkWidget *widget,
if (! gimp_display_get_image (shell->display))
return TRUE;
if ((bevent->type == GDK_BUTTON_PRESS) && (bevent->button == 1))
if (bevent->type == GDK_BUTTON_PRESS && bevent->button == 1)
{
gimp_navigation_editor_popup (shell, widget, bevent->x, bevent->y);
}
......
......@@ -21,6 +21,8 @@
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "libgimpwidgets/gimpwidgets.h"
#include "display-types.h"
#include "tools/tools-types.h"
......@@ -242,7 +244,7 @@ gimp_display_shell_canvas_no_image_events (GtkWidget *canvas,
{
GdkEventButton *bevent = (GdkEventButton *) event;
if (bevent->button == 3)
if (gimp_button_event_triggers_context_menu (bevent))
{
gimp_ui_manager_ui_popup (shell->popup_manager,
"/dummy-menubar/image-popup",
......@@ -534,6 +536,7 @@ gimp_display_shell_canvas_tool_events (GtkWidget *canvas,
gimp_display_shell_start_scrolling (shell, bevent->x, bevent->y);
break;
/* FIXME: use gimp_button_event_triggers_context_menu() */
case 3:
{
GimpUIManager *ui_manager;
......
......@@ -98,7 +98,7 @@ static gboolean
gimp_color_panel_button_press (GtkWidget *widget,
GdkEventButton *bevent)
{
if (bevent->button == 3)
if (gimp_button_event_triggers_context_menu (bevent))
{
GimpColorButton *color_button;
GimpColorPanel *color_panel;
......
......@@ -502,27 +502,17 @@ gimp_component_editor_button_press (GtkWidget *widget,
editor->clicked_component = channel;
switch (bevent->button)
if (gimp_button_event_triggers_context_menu (bevent))
{
case 1:
if (column != editor->eye_column && bevent->type == GDK_BUTTON_PRESS)
{
GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
gimp_image_set_component_active (image, channel, ! active);
gimp_image_flush (image);
}
break;
case 2:
break;
case 3:
gimp_editor_popup_menu (GIMP_EDITOR (editor), NULL, NULL);
break;
}
else if (bevent->type == GDK_BUTTON_PRESS && bevent->button == 1 &&
column != editor->eye_column)
{
GimpImage *image = GIMP_IMAGE_EDITOR (editor)->image;
default:
break;
gimp_image_set_component_active (image, channel, ! active);
gimp_image_flush (image);
}
}
......
......@@ -724,18 +724,13 @@ gimp_container_grid_view_viewport_resized (GtkWidget *widget,
}
static gboolean
gimp_container_grid_view_button_press (GtkWidget *widget,
GdkEventButton *bevent,
GimpContainerGridView *grid_view)
gimp_container_grid_view_button_press (GtkWidget *widget,
GdkEventButton *bevent,
GimpContainerGridView *grid_view)
{
switch (bevent->button)
if (gimp_button_event_triggers_context_menu (bevent))
{
case 3:
gimp_editor_popup_menu (GIMP_EDITOR (grid_view), NULL, NULL);
break;
default:
break;
}
return TRUE;
......
......@@ -1002,9 +1002,18 @@ gimp_container_tree_view_button_press (GtkWidget *widget,
g_object_ref (tree_view);
switch (bevent->button)
if (gimp_button_event_triggers_context_menu (bevent))
{
if (gimp_container_view_item_selected (container_view,
renderer->viewable))
{
if (gimp_container_view_get_container (container_view))
gimp_container_view_item_context (container_view,
renderer->viewable);
}
}
else if (bevent->button == 1)
{
case 1:
if (bevent->type == GDK_BUTTON_PRESS)
{
/* don't select item if a toggle was clicked */
......@@ -1111,9 +1120,9 @@ gimp_container_tree_view_button_press (GtkWidget *widget,
}
}
}
break;
case 2:
}
else if (bevent->button == 2)
{
if (bevent->type == GDK_BUTTON_PRESS)
{
if (clicked_cell)
......@@ -1127,20 +1136,6 @@ gimp_container_tree_view_button_press (GtkWidget *widget,
g_free (path_str);
}
}
break;
case 3:
if (gimp_container_view_item_selected (container_view,
renderer->viewable))
{
if (gimp_container_view_get_container (container_view))
gimp_container_view_item_context (container_view,
renderer->viewable);
}
break;
default:
break;
}
g_object_unref (tree_view);
......@@ -1152,14 +1147,9 @@ gimp_container_tree_view_button_press (GtkWidget *widget,
}
else
{
switch (bevent->button)
if (gimp_button_event_triggers_context_menu (bevent))
{
case 3:
gimp_editor_popup_menu (GIMP_EDITOR (tree_view), NULL, NULL);
break;
default:
break;
}
return TRUE;
......
......@@ -230,7 +230,7 @@ gimp_error_console_button_press (GtkWidget *widget,
GdkEventButton *bevent,
GimpErrorConsole *console)
{
if (bevent->button == 3 && bevent->type == GDK_BUTTON_PRESS)
if (gimp_button_event_triggers_context_menu (bevent))
{
return gimp_editor_popup_menu (GIMP_EDITOR (console), NULL, NULL);
}
......
......@@ -835,9 +835,12 @@ view_events (GtkWidget *widget,
{
GdkEventButton *bevent = (GdkEventButton *) event;
switch (bevent->button)
if (gimp_button_event_triggers_context_menu (bevent))
{
gimp_editor_popup_menu (GIMP_EDITOR (editor), NULL, NULL);
}
else if (bevent->button == 1)
{
case 1:
editor->view_last_x = bevent->x;
editor->view_button_down = TRUE;
......@@ -846,14 +849,6 @@ view_events (GtkWidget *widget,
GIMP_COLOR_PICK_MODE_BACKGROUND :
GIMP_COLOR_PICK_MODE_FOREGROUND,
bevent->x);
break;
case 3:
gimp_editor_popup_menu (GIMP_EDITOR (editor), NULL, NULL);
break;
default:
break;
}
}
break;
......
......@@ -234,9 +234,15 @@ gimp_palette_view_button_press (GtkWidget *widget,
g_signal_emit (view, view_signals[ENTRY_CLICKED], 0,
entry, bevent->state);
switch (bevent->button)
if (gimp_button_event_triggers_context_menu (bevent))
{
if (entry != view->selected)
gimp_palette_view_select_entry (view, entry);
g_signal_emit (view, view_signals[ENTRY_CONTEXT], 0, entry);
}
else if (bevent->button == 1)
{
case 1:
if (bevent->type == GDK_BUTTON_PRESS)
{
gimp_palette_view_select_entry (view, entry);
......@@ -245,20 +251,6 @@ gimp_palette_view_button_press (GtkWidget *widget,
{
g_signal_emit (view, view_signals[ENTRY_ACTIVATED], 0, entry);
}
break;
case 3:
if (bevent->type == GDK_BUTTON_PRESS)
{
if (entry != view->selected)
gimp_palette_view_select_entry (view, entry);
g_signal_emit (view, view_signals[ENTRY_CONTEXT], 0, entry);
}
break;
default:
break;
}
return TRUE;
......
......@@ -441,7 +441,13 @@ gimp_view_button_press_event (GtkWidget *widget,
if (bevent->type == GDK_BUTTON_PRESS)
{
if (bevent->button == 1)
if (gimp_button_event_triggers_context_menu (bevent))
{
view->press_state = 0;
g_signal_emit (widget, view_signals[CONTEXT], 0);
}
else if (bevent->button == 1)
{
gtk_grab_add (widget);
......@@ -470,10 +476,7 @@ gimp_view_button_press_event (GtkWidget *widget,
view->renderer->height,
view->renderer->dot_for_dot);
if (bevent->button == 3)
g_signal_emit (widget, view_signals[CONTEXT], 0);
else
return FALSE;
return FALSE;
}
}
else if (bevent->type == GDK_2BUTTON_PRESS)
......
......@@ -36,6 +36,7 @@
#include "gimpdialog.h"
#include "gimphelpui.h"
#include "gimpstock.h"
#include "gimpwidgets.h" /* remove in 3.0 */
#include "gimpwidgets-private.h"
#include "libgimp/libgimp-intl.h"
......@@ -487,7 +488,7 @@ gimp_color_button_button_press (GtkWidget *widget,
{
GimpColorButton *button = GIMP_COLOR_BUTTON (widget);
if (bevent->button == 3)
if (gimp_button_event_triggers_context_menu (bevent))
{
GtkWidget *menu = gtk_ui_manager_get_widget (button->popup_menu,
"/color-button-popup");
......
......@@ -1239,3 +1239,40 @@ gimp_label_set_attributes (GtkLabel *label,
gtk_label_set_attributes (label, attrs);
pango_attr_list_unref (attrs);
}
/**
* gimp_button_event_triggers_context_menu:
* @event: a #GdkEventButton
*
* Use this function instead of checking for event->button == 3.
*
* Note that this function is a temporary solution, GTK+ 3.4 will
* include a similar function which GIMP will use and this function
* will be deprecated/removed.
*
* Returns: #TRUE if the passed @event triggers a context menu, which
* is a platform-dependent decision.
*
* Since: GIMP 2.8
**/
gboolean
gimp_button_event_triggers_context_menu (GdkEventButton *event)
{
g_return_val_if_fail (event != NULL, FALSE);
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;
}
......@@ -5,6 +5,7 @@ EXPORTS
gimp_browser_new
gimp_browser_set_widget
gimp_browser_show_message
gimp_button_event_triggers_context_menu
gimp_button_extended_clicked
gimp_button_get_type
gimp_button_new
......
......@@ -262,6 +262,8 @@ GtkWidget * gimp_table_attach_aligned (GtkTable *table,
void gimp_label_set_attributes (GtkLabel *label,
...);
gboolean gimp_button_event_triggers_context_menu (GdkEventButton *event);
G_END_DECLS
......
......@@ -261,7 +261,7 @@ static gboolean
button_press (GtkWidget *widget,
GdkEventButton *event)
{
if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
if (gimp_button_event_triggers_context_menu (event))
return popup_menu (widget, event);
return FALSE;
......
......@@ -549,7 +549,7 @@ static gboolean
remap_button_press (GtkWidget *widget,
GdkEventButton *event)
{
if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
if (gimp_button_event_triggers_context_menu (event))
return remap_popup_menu (widget, event);
return FALSE;
......
......@@ -1078,7 +1078,7 @@ static gboolean
view_button_press (GtkWidget *widget,
GdkEventButton *event)
{
if (event->button == 3 && event->type == GDK_BUTTON_PRESS)
if (gimp_button_event_triggers_context_menu (event))
return view_popup_menu (widget, event);
return FALSE;
......
......@@ -1602,25 +1602,22 @@ design_area_button_press (GtkWidget *widget,
gtk_widget_grab_focus (widget);
if (event->button != 1 || (ifsDesign->button_state & GDK_BUTTON1_MASK))
if (gimp_button_event_triggers_context_menu (event))
{
if (event->button == 3)
{
GtkWidget *menu =
gtk_ui_manager_get_widget (ifsDesign->ui_manager,
"/dummy-menubar/ifs-compose-menu");
GtkWidget *menu =
gtk_ui_manager_get_widget (ifsDesign->ui_manager,
"/dummy-menubar/ifs-compose-menu");
if (GTK_IS_MENU_ITEM (menu))
menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu));
if (GTK_IS_MENU_ITEM (menu))
menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu));
gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (widget));
gtk_menu_set_screen (GTK_MENU (menu), gtk_widget_get_screen (widget));
gtk_menu_popup (GTK_MENU (menu),
NULL, NULL, NULL, NULL,
event->button, event->time);
gtk_menu_popup (GTK_MENU (menu),
NULL, NULL, NULL, NULL,
event->button, event->time);
return FALSE;
}
return FALSE;
}
old_current = ifsD->current_element;
......
......@@ -380,15 +380,19 @@ get_filename(void)
static gboolean
arrow_on_button_press(GtkWidget *widget, GdkEventButton *event, gpointer data)
{
if (event->button == 1) {
if (gimp_button_event_triggers_context_menu (event))
{
do_popup_menu (event);
}
else if (event->button == 1)
{
if (event->type == GDK_2BUTTON_PRESS)
edit_shape((gint) event->x, (gint) event->y);
edit_shape((gint) event->x, (gint) event->y);
else
select_shape(widget, event);
} else if (!(event->state & GDK_BUTTON1_MASK) && event->button == 3) {
do_popup_menu(event);
}
return FALSE;
select_shape(widget, event);
}
return FALSE;
}
static void
......
Supports Markdown
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