dia r4260 - in trunk: . app



Author: hans
Date: Fri Feb  6 15:40:00 2009
New Revision: 4260
URL: http://svn.gnome.org/viewvc/dia?rev=4260&view=rev

Log:
2009-02-06  Hans Breuer  <hans breuer org>

	* app/disp_callbacks.c app/tool.h app/modify_tool.c : also allow
	TextEdit entry via Button Press and Hold - patch from  Robert Young
	fixing bug #570304






Modified:
   trunk/ChangeLog
   trunk/app/disp_callbacks.c
   trunk/app/modify_tool.c
   trunk/app/tool.h

Modified: trunk/app/disp_callbacks.c
==============================================================================
--- trunk/app/disp_callbacks.c	(original)
+++ trunk/app/disp_callbacks.c	Fri Feb  6 15:40:00 2009
@@ -52,6 +52,16 @@
 /* This contains the point that was clicked to get this menu */
 static Point object_menu_clicked_point;
 
+typedef struct {
+	GdkEvent *event; /* Button down event which may be holding */
+	DDisplay *ddisp; /* DDisplay where event occurred */
+	guint     tag;   /* Tag for timeout */
+} HoldTimeoutData;
+
+static HoldTimeoutData hold_data = {NULL, NULL, 0};
+
+	
+
 static void
 object_menu_proxy(GtkWidget *widget, gpointer data)
 {
@@ -480,6 +490,34 @@
   }
 }
 
+/** Cleanup/Remove Timeout Handler for Button Press and Hold
+ */
+static void 
+hold_remove_handler(void) 
+{
+  if (hold_data.tag != 0) {
+    g_source_remove(hold_data.tag);
+    hold_data.tag = 0;
+    gdk_event_free(hold_data.event);
+  }
+}
+
+/** Timeout Handler for Button Press and Hold
+ * If this function is called, then the button must still be down,
+ * indicating that the user has pressed and held the button, but not moved
+ * the pointer (mouse).
+ * Dynamic data is cleaned up in ddisplay_canvas_events
+ */
+static gboolean 
+hold_timeout_handler(gpointer data) 
+{
+  if (active_tool->button_hold_func)
+    (*active_tool->button_hold_func) (active_tool, (GdkEventButton *)(hold_data.event), hold_data.ddisp);
+  hold_remove_handler();
+  return FALSE;
+}
+
+
 /** Main input handler for a diagram canvas.
  */
 gint
@@ -583,6 +621,7 @@
 
       case GDK_FOCUS_CHANGE: {
 	GdkEventFocus *focus = (GdkEventFocus*)event;
+	hold_remove_handler();
 	if (focus->in) {
 	  display_set_active(ddisp);
 	  ddisplay_do_update_menu_sensitivity(ddisp);
@@ -591,6 +630,7 @@
       }
       case GDK_2BUTTON_PRESS:
         display_set_active(ddisp);
+	hold_remove_handler();
         bevent = (GdkEventButton *) event;
         state = bevent->state;
 
@@ -634,8 +674,15 @@
               gtk_widget_grab_focus(canvas);
               if (active_tool->button_press_func)
                 (*active_tool->button_press_func) (active_tool, bevent, ddisp);
-              break;
 
+			  /* Detect user holding down the button.
+			   * Set timeout for 1sec. If timeout is called, user must still
+			   * be holding. If user releases button, remove timeout. */
+			  hold_data.event = gdk_event_copy(event); /* need to free later */
+			  hold_data.ddisp = ddisp;
+			  hold_data.tag = g_timeout_add(1000, hold_timeout_handler, NULL);
+
+              break;
             case 2:
               if (ddisp->menu_bar == NULL && !is_integrated_ui()) {
                 popup_object_menu(ddisp, bevent);
@@ -681,6 +728,8 @@
               if (active_tool->button_release_func)
                 (*active_tool->button_release_func) (active_tool,
                                                      bevent, ddisp);
+	      /* Button Press and Hold - remove handler then deallocate memory */
+	      hold_remove_handler();
               break;
 
             case 2:
@@ -704,6 +753,7 @@
       case GDK_MOTION_NOTIFY:
 	/*  get the pointer position  */
 	gdk_window_get_pointer (canvas->window, &tx, &ty, &tmask);
+	hold_remove_handler();
 
         mevent = (GdkEventMotion *) event;
         state = mevent->state;

Modified: trunk/app/modify_tool.c
==============================================================================
--- trunk/app/modify_tool.c	(original)
+++ trunk/app/modify_tool.c	Fri Feb  6 15:40:00 2009
@@ -46,6 +46,8 @@
 				GdkEventButton *event);
 static void modify_button_press(ModifyTool *tool, GdkEventButton *event,
 				 DDisplay *ddisp);
+static void modify_button_hold(ModifyTool *tool, GdkEventButton *event,
+				 DDisplay *ddisp);
 static void modify_button_release(ModifyTool *tool, GdkEventButton *event,
 				  DDisplay *ddisp);
 static void modify_motion(ModifyTool *tool, GdkEventMotion *event,
@@ -66,6 +68,7 @@
   tool = g_new0(ModifyTool, 1);
   tool->tool.type = MODIFY_TOOL;
   tool->tool.button_press_func = (ButtonPressFunc) &modify_button_press;
+  tool->tool.button_hold_func = (ButtonHoldFunc) &modify_button_hold;
   tool->tool.button_release_func = (ButtonReleaseFunc) &modify_button_release;
   tool->tool.motion_func = (MotionFunc) &modify_motion;
   tool->tool.double_click_func = (DoubleClickFunc) &modify_double_click;
@@ -295,6 +298,43 @@
 
 
 static void
+modify_button_hold(ModifyTool *tool, GdkEventButton *event,
+		DDisplay *ddisp)
+{
+  Point clickedpoint;
+
+  switch (tool->state) {
+  case STATE_MOVE_OBJECT: 
+    /* A button hold is as if user was moving object - if it is
+     * a text object and can be edited, then the move is cancelled */
+    ddisplay_untransform_coords(ddisp,
+				(int)event->x, (int)event->y,
+				&clickedpoint.x, &clickedpoint.y);
+
+    if (tool->object != NULL &&
+	diagram_is_selected(ddisp->diagram, tool->object)) {
+      if (textedit_activate_object(ddisp, tool->object, &clickedpoint)) {
+	/* Return tool to normal state - object is text and is in edit */
+	gdk_pointer_ungrab (event->time);
+	tool->orig_pos = NULL;
+	tool->state = STATE_NONE;
+	/* Activate Text Edit */
+	gtk_action_activate (menus_get_action ("ToolsTextedit"));
+      }
+    } 
+    break;
+  case STATE_MOVE_HANDLE:
+    break;
+  case STATE_BOX_SELECT:
+    break;
+  case STATE_NONE:
+    break;
+  default:
+    message_error("Internal error: Strange state in modify_tool (button_hold)\n");
+  }
+}
+
+static void
 modify_double_click(ModifyTool *tool, GdkEventButton *event,
 		    DDisplay *ddisp)
 {

Modified: trunk/app/tool.h
==============================================================================
--- trunk/app/tool.h	(original)
+++ trunk/app/tool.h	Fri Feb  6 15:40:00 2009
@@ -28,6 +28,7 @@
 #include "display.h"
 
 typedef void (* ButtonPressFunc)   (Tool *, GdkEventButton *, DDisplay *ddisp);
+typedef void (* ButtonHoldFunc)    (Tool *, GdkEventButton *, DDisplay *ddisp);
 typedef void (* DoubleClickFunc)   (Tool *, GdkEventButton *, DDisplay *ddisp);
 typedef void (* ButtonReleaseFunc) (Tool *, GdkEventButton *, DDisplay *ddisp);
 typedef void (* MotionFunc)        (Tool *, GdkEventMotion *, DDisplay *ddisp);
@@ -45,6 +46,7 @@
   
   /*  Action functions  */
   ButtonPressFunc    button_press_func;
+  ButtonHoldFunc     button_hold_func;
   ButtonReleaseFunc  button_release_func;
   MotionFunc         motion_func;
   DoubleClickFunc    double_click_func;



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