[gimp/metadata-browser] Add gimp_button_event_triggers_context_menu() and use it
- From: Roman Joost <romanofski src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp/metadata-browser] Add gimp_button_event_triggers_context_menu() and use it
- Date: Wed, 28 Sep 2011 10:49:21 +0000 (UTC)
commit 5cd5933d884bc682d0119922c2ca6b4815430701
Author: Michael Natterer <mitch gimp org>
Date: Mon Sep 19 00:45:36 2011 +0200
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.
app/display/gimpdisplayshell-callbacks.c | 6 ++--
app/display/gimpdisplayshell-tool-events.c | 5 +++-
app/widgets/gimpcolorpanel.c | 2 +-
app/widgets/gimpcomponenteditor.c | 26 +++++------------
app/widgets/gimpcontainergridview.c | 13 +++------
app/widgets/gimpcontainertreeview.c | 40 ++++++++++-----------------
app/widgets/gimperrorconsole.c | 2 +-
app/widgets/gimpgradienteditor.c | 15 +++-------
app/widgets/gimppaletteview.c | 24 +++++-----------
app/widgets/gimpview.c | 13 +++++---
libgimpwidgets/gimpcolorbutton.c | 3 +-
libgimpwidgets/gimpwidgets.c | 37 +++++++++++++++++++++++++
libgimpwidgets/gimpwidgets.def | 1 +
libgimpwidgets/gimpwidgets.h | 2 +
plug-ins/common/animation-play.c | 2 +-
plug-ins/common/colormap-remap.c | 2 +-
plug-ins/help-browser/dialog.c | 2 +-
plug-ins/ifs-compose/ifs-compose.c | 25 +++++++----------
plug-ins/imagemap/imap_main.c | 18 +++++++-----
19 files changed, 124 insertions(+), 114 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-callbacks.c b/app/display/gimpdisplayshell-callbacks.c
index 8415d5d..0397707 100644
--- a/app/display/gimpdisplayshell-callbacks.c
+++ b/app/display/gimpdisplayshell-callbacks.c
@@ -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);
}
diff --git a/app/display/gimpdisplayshell-tool-events.c b/app/display/gimpdisplayshell-tool-events.c
index f8bd67d..2593e19 100644
--- a/app/display/gimpdisplayshell-tool-events.c
+++ b/app/display/gimpdisplayshell-tool-events.c
@@ -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;
diff --git a/app/widgets/gimpcolorpanel.c b/app/widgets/gimpcolorpanel.c
index cedf82f..669a20a 100644
--- a/app/widgets/gimpcolorpanel.c
+++ b/app/widgets/gimpcolorpanel.c
@@ -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;
diff --git a/app/widgets/gimpcomponenteditor.c b/app/widgets/gimpcomponenteditor.c
index 155dee8..c440d83 100644
--- a/app/widgets/gimpcomponenteditor.c
+++ b/app/widgets/gimpcomponenteditor.c
@@ -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);
}
}
diff --git a/app/widgets/gimpcontainergridview.c b/app/widgets/gimpcontainergridview.c
index 8100ccc..e81b4fc 100644
--- a/app/widgets/gimpcontainergridview.c
+++ b/app/widgets/gimpcontainergridview.c
@@ -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;
diff --git a/app/widgets/gimpcontainertreeview.c b/app/widgets/gimpcontainertreeview.c
index e9ac6df..c745053 100644
--- a/app/widgets/gimpcontainertreeview.c
+++ b/app/widgets/gimpcontainertreeview.c
@@ -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;
diff --git a/app/widgets/gimperrorconsole.c b/app/widgets/gimperrorconsole.c
index 1f800e7..8d8002d 100644
--- a/app/widgets/gimperrorconsole.c
+++ b/app/widgets/gimperrorconsole.c
@@ -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);
}
diff --git a/app/widgets/gimpgradienteditor.c b/app/widgets/gimpgradienteditor.c
index d72cc04..c589a65 100644
--- a/app/widgets/gimpgradienteditor.c
+++ b/app/widgets/gimpgradienteditor.c
@@ -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;
diff --git a/app/widgets/gimppaletteview.c b/app/widgets/gimppaletteview.c
index aee96c2..cb4a7d6 100644
--- a/app/widgets/gimppaletteview.c
+++ b/app/widgets/gimppaletteview.c
@@ -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;
diff --git a/app/widgets/gimpview.c b/app/widgets/gimpview.c
index 22465dd..5e94061 100644
--- a/app/widgets/gimpview.c
+++ b/app/widgets/gimpview.c
@@ -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)
diff --git a/libgimpwidgets/gimpcolorbutton.c b/libgimpwidgets/gimpcolorbutton.c
index e9c67c7..a3aa25c 100644
--- a/libgimpwidgets/gimpcolorbutton.c
+++ b/libgimpwidgets/gimpcolorbutton.c
@@ -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");
diff --git a/libgimpwidgets/gimpwidgets.c b/libgimpwidgets/gimpwidgets.c
index 54ca1bf..e6251ec 100644
--- a/libgimpwidgets/gimpwidgets.c
+++ b/libgimpwidgets/gimpwidgets.c
@@ -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;
+}
diff --git a/libgimpwidgets/gimpwidgets.def b/libgimpwidgets/gimpwidgets.def
index e9dc898..eeb39d2 100644
--- a/libgimpwidgets/gimpwidgets.def
+++ b/libgimpwidgets/gimpwidgets.def
@@ -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
diff --git a/libgimpwidgets/gimpwidgets.h b/libgimpwidgets/gimpwidgets.h
index 51d5eb8..9b0dac5 100644
--- a/libgimpwidgets/gimpwidgets.h
+++ b/libgimpwidgets/gimpwidgets.h
@@ -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
diff --git a/plug-ins/common/animation-play.c b/plug-ins/common/animation-play.c
index 2c0940b..e4a40fc 100644
--- a/plug-ins/common/animation-play.c
+++ b/plug-ins/common/animation-play.c
@@ -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;
diff --git a/plug-ins/common/colormap-remap.c b/plug-ins/common/colormap-remap.c
index ce253c5..03e91cd 100644
--- a/plug-ins/common/colormap-remap.c
+++ b/plug-ins/common/colormap-remap.c
@@ -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;
diff --git a/plug-ins/help-browser/dialog.c b/plug-ins/help-browser/dialog.c
index be3d8b6..6fcd4e0 100644
--- a/plug-ins/help-browser/dialog.c
+++ b/plug-ins/help-browser/dialog.c
@@ -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;
diff --git a/plug-ins/ifs-compose/ifs-compose.c b/plug-ins/ifs-compose/ifs-compose.c
index f98986d..4bc7cf8 100644
--- a/plug-ins/ifs-compose/ifs-compose.c
+++ b/plug-ins/ifs-compose/ifs-compose.c
@@ -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;
diff --git a/plug-ins/imagemap/imap_main.c b/plug-ins/imagemap/imap_main.c
index 60f8069..5ff9f9c 100644
--- a/plug-ins/imagemap/imap_main.c
+++ b/plug-ins/imagemap/imap_main.c
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]