[beast: 135/144] BST: provide accessors to classify mouse button events for context/movement/etc



commit 20fcfe2e3482a88d1d4d70a4b8812d7c20b9513b
Author: Tim Janik <timj gnu org>
Date:   Thu Jan 17 03:49:01 2013 +0100

    BST: provide accessors to classify mouse button events for context/movement/etc

 beast-gtk/bstcanvaslink.cc   |    4 +-
 beast-gtk/bstcanvassource.cc |    4 +-
 beast-gtk/bstsnetrouter.cc   |   16 +++++++-------
 beast-gtk/bstutils.cc        |   44 ++++++++++++++++++++++++++++++++++++++++++
 beast-gtk/bstutils.hh        |   16 +++++++++++++++
 5 files changed, 72 insertions(+), 12 deletions(-)
---
diff --git a/beast-gtk/bstcanvaslink.cc b/beast-gtk/bstcanvaslink.cc
index 46e0a21..a51ba49 100644
--- a/beast-gtk/bstcanvaslink.cc
+++ b/beast-gtk/bstcanvaslink.cc
@@ -414,7 +414,7 @@ bst_canvas_link_event (GnomeCanvasItem *item,
   switch (event->type)
     {
     case GDK_BUTTON_PRESS:
-      if (event->button.button == 2)
+      if (bst_mouse_button_move (event))
 	{
 	  GdkCursor *fleur;
 	  if (clink->ocsource)
@@ -466,7 +466,7 @@ bst_canvas_link_event (GnomeCanvasItem *item,
 	}
       break;
     case GDK_BUTTON_RELEASE:
-      if (event->button.button == 2 && clink->in_move)
+      if (bst_mouse_button_move (event) && clink->in_move)
 	{
 	  clink->in_move = FALSE;
 	  gnome_canvas_item_ungrab (item, event->button.time);
diff --git a/beast-gtk/bstcanvassource.cc b/beast-gtk/bstcanvassource.cc
index c693ef6..68556db 100644
--- a/beast-gtk/bstcanvassource.cc
+++ b/beast-gtk/bstcanvassource.cc
@@ -811,7 +811,7 @@ bst_canvas_source_event (GnomeCanvasItem *item,
   switch (event->type)
     {
     case GDK_BUTTON_PRESS:
-      if (!csource->in_move && event->button.button == 2)
+      if (!csource->in_move && bst_mouse_button_move (event))
 	{
 	  GdkCursor *fleur = gdk_cursor_new (GDK_FLEUR);
 	  if (gnome_canvas_item_grab (item,
@@ -868,7 +868,7 @@ bst_canvas_source_event (GnomeCanvasItem *item,
 	}
       break;
     case GDK_BUTTON_RELEASE:
-      if (event->button.button == 2 && csource->in_move)
+      if (bst_mouse_button_move (event) && csource->in_move)
 	{
           bse_item_ungroup_undo (csource->source);
 	  csource->in_move = FALSE;
diff --git a/beast-gtk/bstsnetrouter.cc b/beast-gtk/bstsnetrouter.cc
index 401ea3c..be816b7 100644
--- a/beast-gtk/bstsnetrouter.cc
+++ b/beast-gtk/bstsnetrouter.cc
@@ -494,7 +494,7 @@ bst_snet_router_root_event (BstSNetRouter   *self,
         }
       at_channel = ochannel != ~uint (0) || ichannel != ~uint (0);
       if (event->type == GDK_BUTTON_PRESS &&
-          event->button.button == 1 &&
+          bst_mouse_button_activate (event) &&
           ROUTER_TOOL (self) == 0)                                      /* start link (or popup property dialog) */
         {
           g_return_val_if_fail (self->tmp_line == NULL, FALSE);
@@ -533,7 +533,7 @@ bst_snet_router_root_event (BstSNetRouter   *self,
             }
           else if (csource && csource->source != self->snet)
             {
-              if (event->button.state & GDK_SHIFT_MASK)
+              if (bst_mouse_button_activate2 (event))
                 bst_canvas_source_toggle_info (csource);
               else
                 bst_canvas_source_toggle_params (csource);
@@ -542,7 +542,7 @@ bst_snet_router_root_event (BstSNetRouter   *self,
             bst_canvas_link_toggle_view (clink);
           handled = TRUE;
         }
-      else if (event->button.button == 1 && ROUTER_TOOL (self) == ROUTER_TOOL_CREATE_LINK) /* finish link */
+      else if (bst_mouse_button_activate (event) && ROUTER_TOOL (self) == ROUTER_TOOL_CREATE_LINK) /* finish link */
         {
           if (event->type == GDK_BUTTON_RELEASE && csource == self->drag_csource &&
               self->drag_channel == (self->drag_is_input ? ichannel : ochannel))
@@ -552,7 +552,7 @@ bst_snet_router_root_event (BstSNetRouter   *self,
           else
             {
               BseErrorType error;
-              if (!csource || (self->drag_is_input ? ochannel : ichannel) == ~0)
+              if (!csource || (self->drag_is_input ? ochannel : ichannel) == ~uint (0))
                 error = self->drag_is_input ? BSE_ERROR_SOURCE_NO_SUCH_OCHANNEL : BSE_ERROR_SOURCE_NO_SUCH_ICHANNEL;
               else if (self->drag_is_input)
                 error = bse_source_set_input_by_id (self->drag_csource->source, self->drag_channel,
@@ -567,7 +567,7 @@ bst_snet_router_root_event (BstSNetRouter   *self,
             }
           handled = TRUE;
         }
-      else if (event->type == GDK_BUTTON_PRESS && event->button.button == 3)    /* module context menu */
+      else if (event->type == GDK_BUTTON_PRESS && bst_mouse_button_context (event))    /* module context menu */
         {
           if (csource)
             {
@@ -680,7 +680,7 @@ bst_snet_router_event (GtkWidget *widget,
   switch (event->type)
     {
     case GDK_BUTTON_PRESS:
-      if (event->button.button == 1 &&
+      if (bst_mouse_button_activate1 (event) &&
           ROUTER_TOOL (self) &&
           ROUTER_TOOL (self) != ROUTER_TOOL_CREATE_LINK) /* add new source */
         {
@@ -707,7 +707,7 @@ bst_snet_router_event (GtkWidget *widget,
           self->world_y = 0;
           bst_status_eprintf (error, _("Insert Module"));
         }
-      else if (event->button.button != 1 && ROUTER_TOOL (self) == ROUTER_TOOL_CREATE_LINK)
+      else if (!bst_mouse_button_activate1 (event) && ROUTER_TOOL (self) == ROUTER_TOOL_CREATE_LINK)
         {
           /* disturbing button presses, reset stuff */
           handled = TRUE;
@@ -743,7 +743,7 @@ bst_snet_router_button_press (GtkWidget      *widget,
   gboolean handled;
   /* chain parent class' handler */
   handled = GTK_WIDGET_CLASS (bst_snet_router_parent_class)->button_press_event (widget, event);
-  if (!handled && event->button == 3 && self->canvas_popup)
+  if (!handled && bst_mouse_button_context (event) && self->canvas_popup)
     gxk_menu_popup (self->canvas_popup,
                     event->x_root, event->y_root,
                     event->button, event->time);
diff --git a/beast-gtk/bstutils.cc b/beast-gtk/bstutils.cc
index 1099a3b..83e303e 100644
--- a/beast-gtk/bstutils.cc
+++ b/beast-gtk/bstutils.cc
@@ -152,6 +152,7 @@ bst_stock_register_icon (const gchar    *stock_id,
       gtk_icon_set_unref (iset);
     }
 }
+
 /* --- beast/bse specific extensions --- */
 void
 bst_status_eprintf (BseErrorType error,
@@ -1335,3 +1336,46 @@ bst_file_scan_find_key (const gchar *file,
   sfi_pspec_set_group (sfi_pspec_proxy (name, NULL, NULL, SFI_PARAM_STANDARD), group)
 /* --- generated type IDs and SFIDL types --- */
 #include "bstgentypes.cc"       /* type id defs */
+
+// == mouse button checks ==
+static bool
+shift_event (GdkEvent *event)
+{
+  return (event->button.state & GDK_SHIFT_MASK) != 0;
+}
+
+static bool
+button_event (GdkEvent *event)
+{
+  return event->type == GDK_BUTTON_PRESS || event->type == GDK_BUTTON_RELEASE;
+}
+
+bool
+bst_mouse_button_activate (GdkEvent *event)
+{
+  return button_event (event) && event->button.button == 1;
+}
+
+bool
+bst_mouse_button_activate1 (GdkEvent *event)
+{
+  return !shift_event (event) && button_event (event) && event->button.button == 1;
+}
+
+bool
+bst_mouse_button_activate2 (GdkEvent *event)
+{
+  return shift_event (event) && button_event (event) && event->button.button == 1;
+}
+
+bool
+bst_mouse_button_move (GdkEvent *event)
+{
+  return button_event (event) && event->button.button == 2;
+}
+
+bool
+bst_mouse_button_context (GdkEvent *event)
+{
+  return button_event (event) && event->button.button == 3;
+}
diff --git a/beast-gtk/bstutils.hh b/beast-gtk/bstutils.hh
index fef3683..ba8eef9 100644
--- a/beast-gtk/bstutils.hh
+++ b/beast-gtk/bstutils.hh
@@ -70,6 +70,7 @@ void       bst_stock_register_icon      (const gchar  *stock_id,
                                          guint         height,
                                          guint         rowstride,
                                          const guint8 *pixels);
+
 /* --- pixbuf shortcuts --- */
 #define bst_pixbuf_no_icon()    gxk_stock_fallback_pixbuf (BST_STOCK_NO_ICON)
 #define bst_pixbuf_ladspa()     gxk_stock_fallback_pixbuf (BST_STOCK_LADSPA)
@@ -197,4 +198,19 @@ BstGConfig*     bst_gconfig_get_global (void);
 void            _bst_init_utils         (void);
 void            _bst_init_radgets       (void);
 G_END_DECLS
+
+
+// == mouse button checks ==
+bool            bst_mouse_button_activate       (GdkEvent       *event);
+bool            bst_mouse_button_activate1      (GdkEvent       *event);
+bool            bst_mouse_button_activate2      (GdkEvent       *event);
+bool            bst_mouse_button_context        (GdkEvent       *event);
+bool            bst_mouse_button_move           (GdkEvent       *event);
+inline bool     bst_mouse_button_activate       (GdkEventButton *event) { return bst_mouse_button_activate ((GdkEvent*) event); }
+inline bool     bst_mouse_button_activate1      (GdkEventButton *event) { return bst_mouse_button_activate1 ((GdkEvent*) event); }
+inline bool     bst_mouse_button_activate2      (GdkEventButton *event) { return bst_mouse_button_activate2 ((GdkEvent*) event); }
+inline bool     bst_mouse_button_context        (GdkEventButton *event) { return bst_mouse_button_context ((GdkEvent*) event); }
+inline bool     bst_mouse_button_move           (GdkEventButton *event) { return bst_mouse_button_move ((GdkEvent*) event); }
+
+
 #endif /* __BST_UTILS_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]