[patch] middle button panning



This patch is supposed to make middle button pan (scroll) the viewing area, unless menu bar is turned off (when middle button is used for invoking the main menu). To implement that, I needed to add two functions: tool_get and tool_restore, which will need to be adjusted after adding more complex tools (complex = requiring any parameters, like create object tool).

What about this mode: pressing middle button = panning, mousewheel = zooming ? I'm sure I've seen it somewhere, although instant zoom function may be not as useful in Dia as it is in other apps.

Changelog entry:

2003-06-13  Krzysztof Foltman <kfoltman onet pl>

   * app/disp_callbacks.c: add middle button panning (scrolling)
* app/tool.[hc]: add tool_get (save current tool state) and tool_restore (restore the tool state)

Krzysztof

Index: app/disp_callbacks.c
===================================================================
RCS file: /cvs/gnome/dia/app/disp_callbacks.c,v
retrieving revision 1.67
diff -w -b -u -4 -r1.67 disp_callbacks.c
--- app/disp_callbacks.c        29 Apr 2003 20:20:57 -0000      1.67
+++ app/disp_callbacks.c        5 Jul 2003 09:53:08 -0000
@@ -365,8 +365,10 @@
       
   handle_key_event(ddisp, active_focus(), 0, str, g_utf8_strlen(str,-1));
 }
 
+
+
 void ddisplay_im_context_preedit_changed(GtkIMContext *context,
                                          DDisplay *ddisp) {
 /*  char *str;
   PangoAttrList *attrs;
@@ -382,8 +384,11 @@
   pango_attr_list_unref(attrs);
 */
 }
 
+static ToolState before_drag_state;
+static gboolean is_middle_panning = FALSE;
+
 gint
 ddisplay_canvas_events (GtkWidget *canvas,
                        GdkEvent  *event,
                        DDisplay *ddisp)
@@ -515,8 +520,16 @@
             case 2:
               if (ddisp->menu_bar == NULL) {
                 popup_object_menu(ddisp, bevent);
               }
+             else if (!is_middle_panning) {
+               gtk_widget_grab_focus(canvas);
+               tool_get (&before_drag_state);
+               tool_select(SCROLL_TOOL, NULL, NULL, NULL);
+               g_assert (*active_tool->button_press_func);
+               (*active_tool->button_press_func) (active_tool, bevent, ddisp);
+               is_middle_panning = TRUE;
+             }
               break;
 
             case 3:
               if (ddisp->menu_bar == NULL) {
@@ -550,8 +563,16 @@
                                                      bevent, ddisp);
               break;
 
             case 2:
+             if (is_middle_panning) {
+               g_assert(active_tool);
+               (*active_tool->button_release_func) (active_tool,
+                                                    bevent, ddisp);
+                                                               
+               tool_restore (&before_drag_state);
+               is_middle_panning = FALSE;
+             }
               break;
 
             case 3:
               break;
Index: app/tool.c
===================================================================
RCS file: /cvs/gnome/dia/app/tool.c,v
retrieving revision 1.8
diff -w -b -u -4 -r1.8 tool.c
--- app/tool.c  16 Aug 2001 12:18:19 -0000      1.8
+++ app/tool.c  5 Jul 2003 09:53:08 -0000
@@ -45,11 +45,34 @@
                          GTK_BUTTON(modify_tool_button), NULL);
 }
 
 void 
+tool_get(ToolState *state)
+{
+  state->type = active_tool->type;
+  state->button = active_button;
+  if (state->type == CREATE_OBJECT_TOOL) {
+    state->user_data = ((CreateObjectTool *)active_tool)->user_data;
+    state->extra_data = ((CreateObjectTool *)active_tool)->objtype->name;
+  }
+  else
+  {
+    state->user_data = NULL;
+    state->extra_data = NULL;
+  }
+}
+
+void
+tool_restore(const ToolState *state)
+{
+  tool_select(state->type, state->extra_data, state->user_data, state->button);
+}
+
+void 
 tool_select(ToolType type, gpointer extra_data, 
             gpointer user_data, GtkWidget *button)
 {
+  if (button)
   former_button = active_button;
 
   switch(active_tool->type) {
   case MODIFY_TOOL:
@@ -80,8 +103,9 @@
   case SCROLL_TOOL:
     active_tool = create_scroll_tool();
     break;
   }
+  if (button)
   active_button = button;
 }
 
 void
Index: app/tool.h
===================================================================
RCS file: /cvs/gnome/dia/app/tool.h,v
retrieving revision 1.7
diff -w -b -u -4 -r1.7 tool.h
--- app/tool.h  16 Aug 2001 12:18:19 -0000      1.7
+++ app/tool.h  5 Jul 2003 09:53:08 -0000
@@ -21,8 +21,9 @@
 #include <gdk/gdk.h>
 
 typedef struct _Tool Tool;
 typedef struct _ToolInfo ToolInfo;
+typedef struct _ToolState ToolState;
 
 typedef enum _ToolType ToolType;
 
 #include "display.h"
@@ -53,16 +54,23 @@
   ToolType type;
   char *tooltip;
 };
 
-extern Tool *active_tool;
+struct _ToolState {
+  ToolType type;
+  gpointer extra_data;
+  gpointer user_data;
+  GtkWidget *button;
+};
+
+extern Tool *active_tool, *scroll_tool;
 
+void tool_get(ToolState *state);
+void tool_restore(const ToolState *state);
 void tool_select(ToolType type, gpointer extra_data, gpointer user_date,
                  GtkWidget *button);
 void tool_select_former(void);
 void tool_reset(void);
 void tool_options_dialog_show(ToolType type, gpointer extra_data, 
                              gpointer user_data,GtkWidget *button);
 
 #endif /* TOOL_H */
-
-


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