[gnumeric] Objects: improve tooltip positioning a bit.



commit a7a266903e8afac99b60af0ddddc611e8affeb88
Author: Morten Welinder <terra gnome org>
Date:   Wed Mar 10 11:41:04 2010 -0500

    Objects: improve tooltip positioning a bit.

 ChangeLog                       |   11 +++++++++
 NEWS                            |    3 ++
 src/gnm-pane.c                  |   47 ++++++++++++++++++++------------------
 src/gui-util.c                  |   21 +++++++++++++++++
 src/gui-util.h                  |    3 ++
 src/sheet-object-cell-comment.c |   24 +------------------
 6 files changed, 65 insertions(+), 44 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index fb35fc2..411aa4c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2010-03-10  Morten Welinder  <terra gnome org>
+
+	* src/sheet-object-cell-comment.c (comment_view_button_released,
+	comment_view_enter_notify): Use gnm_canvas_get_screen_position.
+
+	* src/gui-util.c (gnm_canvas_get_screen_position): New function
+	extracted from comment_view_get_xy.
+
+	* src/gnm-pane.c (gnm_pane_display_obj_size_tip): Add
+	control-point as argument.  Use that for tooltip positioning.
+
 2010-03-08  Morten Welinder <terra gnome org>
 
 	* configure.in: Post-release bump.
diff --git a/NEWS b/NEWS
index 4af9277..e6c06f4 100644
--- a/NEWS
+++ b/NEWS
@@ -1,5 +1,8 @@
 Gnumeric 1.10.2
 
+Morten:
+	* Improve object sizing tooltip positioning a bit.
+
 --------------------------------------------------------------------------
 Gnumeric 1.10.1
 
diff --git a/src/gnm-pane.c b/src/gnm-pane.c
index 865eb3b..7346b42 100644
--- a/src/gnm-pane.c
+++ b/src/gnm-pane.c
@@ -54,7 +54,7 @@ static GocCanvasClass *parent_klass;
 
 static void cb_pane_popup_menu (GnmPane *pane);
 static void gnm_pane_clear_obj_size_tip (GnmPane *pane);
-static void gnm_pane_display_obj_size_tip (GnmPane *pane);
+static void gnm_pane_display_obj_size_tip (GnmPane *pane, GocItem *ctrl_pt);
 
 /**
  * For now, application/x-gnumeric is disabled. It handles neither
@@ -122,23 +122,19 @@ gnm_pane_object_key_press (GnmPane *pane, GdkEventKey *ev)
 
 	case GDK_KP_Left: case GDK_Left:
 		scg_objects_nudge (scg, pane, (alt ? 4 : (control ? 3 : 8)), -delta , 0, symmetric, shift);
-		if (pane->cur_object)
-			gnm_pane_display_obj_size_tip (pane);
+		gnm_pane_display_obj_size_tip (pane, NULL);
 		return TRUE;
 	case GDK_KP_Right: case GDK_Right:
 		scg_objects_nudge (scg, pane, (alt ? 4 : (control ? 3 : 8)), delta, 0, symmetric, shift);
-		if (pane->cur_object)
-			gnm_pane_display_obj_size_tip (pane);
+		gnm_pane_display_obj_size_tip (pane, NULL);
 		return TRUE;
 	case GDK_KP_Up: case GDK_Up:
 		scg_objects_nudge (scg, pane, (alt ? 6 : (control ? 1 : 8)), 0, -delta, symmetric, shift);
-		if (pane->cur_object)
-			gnm_pane_display_obj_size_tip (pane);
+		gnm_pane_display_obj_size_tip (pane, NULL);
 		return TRUE;
 	case GDK_KP_Down: case GDK_Down:
 		scg_objects_nudge (scg, pane, (alt ? 6 : (control ? 1 : 8)), 0, delta, symmetric, shift);
-		if (pane->cur_object)
-			gnm_pane_display_obj_size_tip (pane);
+		gnm_pane_display_obj_size_tip (pane, NULL);
 		return TRUE;
 
 	default:
@@ -1885,7 +1881,7 @@ gnm_pane_clear_obj_size_tip (GnmPane *pane)
 }
 
 static void
-gnm_pane_display_obj_size_tip (GnmPane *pane)
+gnm_pane_display_obj_size_tip (GnmPane *pane, GocItem *ctrl_pt)
 {
 	SheetControlGUI *scg = pane->simple.scg;
 	double const *coords = g_hash_table_lookup (scg->selected_objects, pane->cur_object);
@@ -1893,24 +1889,30 @@ gnm_pane_display_obj_size_tip (GnmPane *pane)
 	char *msg;
 	SheetObjectAnchor anchor;
 
-	g_return_if_fail (pane->cur_object != NULL);
-
 	if (pane->size_tip == NULL) {
 		GtkWidget *cw = GTK_WIDGET (pane);
 		GtkWidget *top;
 		int x, y;
-		GdkScreen *screen = gtk_widget_get_screen (cw);
+
+		if (ctrl_pt == NULL) {
+			/*
+			 * Keyboard navigation when we are not displaying
+			 * a tooltip already.
+			 */
+			return;
+		}
 
 		pane->size_tip = gnumeric_create_tooltip (cw);
 		top = gtk_widget_get_toplevel (pane->size_tip);
-		/* do not use gnumeric_position_tooltip because it places the tip
-		 * too close to the mouse and generates LEAVE events */
-		gdk_window_get_pointer (gdk_screen_get_root_window (screen),
-					&x, &y, NULL);
+
+		gnm_canvas_get_screen_position (ctrl_pt->canvas,
+						ctrl_pt->x1, ctrl_pt->y1,
+						&x, &y);
 		gtk_window_move (GTK_WINDOW (top), x + 10, y + 10);
 		gtk_widget_show_all (top);
 	}
 
+	g_return_if_fail (pane->cur_object != NULL);
 	g_return_if_fail (pane->size_tip != NULL);
 
 	anchor = *sheet_object_get_anchor (pane->cur_object);
@@ -2258,7 +2260,7 @@ gnm_pane_object_move (GnmPane *pane, GObject *ctrl_pt,
 	gnm_pane_objects_drag (pane, pane->cur_object, new_x, new_y, idx,
 			       symmetric, snap_to_grid);
 	if (idx != 8)
-		gnm_pane_display_obj_size_tip (pane);
+		gnm_pane_display_obj_size_tip (pane, GOC_ITEM (ctrl_pt));
 }
 
 static gboolean
@@ -2409,8 +2411,9 @@ cb_pane_popup_menu (GnmPane *pane)
 static void
 control_point_set_cursor (SheetControlGUI const *scg, GocItem *ctrl_pt)
 {
-	double const *coords = g_hash_table_lookup (scg->selected_objects,
-		g_object_get_data (G_OBJECT (ctrl_pt), "so"));
+	SheetObject *so = g_object_get_data (G_OBJECT (ctrl_pt), "so");
+	int idx = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (ctrl_pt), "index"));
+	double const *coords = g_hash_table_lookup (scg->selected_objects, so);
 	gboolean invert_h = coords [0] > coords [2];
 	gboolean invert_v = coords [1] > coords [3];
 	GdkCursorType cursor;
@@ -2418,7 +2421,7 @@ control_point_set_cursor (SheetControlGUI const *scg, GocItem *ctrl_pt)
 	if (goc_canvas_get_direction (ctrl_pt->canvas) == GOC_DIRECTION_RTL)
 		invert_h = !invert_h;
 
-	switch (GPOINTER_TO_INT (g_object_get_data (G_OBJECT (ctrl_pt), "index"))) {
+	switch (idx) {
 	case 1: invert_v = !invert_v;
 		/* fallthrough */
 	case 6: cursor = invert_v ? GDK_TOP_SIDE : GDK_BOTTOM_SIDE;
@@ -2699,7 +2702,7 @@ control_point_enter_notify (GocItem *item, G_GNUC_UNUSED double x, G_GNUC_UNUSED
 		GOStyle *style = go_styled_object_get_style (GO_STYLED_OBJECT (item));
 		style->fill.pattern.back = GO_COLOR_GREEN;
 		goc_item_invalidate (item);
-		gnm_pane_display_obj_size_tip (pane);
+		gnm_pane_display_obj_size_tip (pane, item);
 	}
 	return TRUE;
 }
diff --git a/src/gui-util.c b/src/gui-util.c
index ffdc8cb..8db4638 100644
--- a/src/gui-util.c
+++ b/src/gui-util.c
@@ -1378,6 +1378,27 @@ gnm_canvas_get_position (GocCanvas *canvas, int *x, int *y, gint64 px, gint64 py
 	*y = py + wy - oy;
 }
 
+/*
+ * Get the gdk position for canvas coordinates (x,y).  This is suitable
+ * for tooltip windows.
+ *
+ * It is possible that this does not work right for very large coordinates
+ * prior to gtk+ 2.18.  See the code and comments in gnm_canvas_get_position.
+ */
+void
+gnm_canvas_get_screen_position (GocCanvas *canvas,
+				double x, double y,
+				int *ix, int *iy)
+{
+	GdkWindow *cbw = GTK_LAYOUT (canvas)->bin_window;
+	int wx, wy;
+
+	gdk_window_get_origin (cbw, &wx, &wy);
+	goc_canvas_c2w (canvas, x, y, ix, iy);
+	(*ix) += wx;
+	(*iy) += wy;
+}
+
 
 gboolean
 gnm_check_for_plugins_missing (char const **ids, GtkWindow *parent)
diff --git a/src/gui-util.h b/src/gui-util.h
index e47a871..1ac8a9c 100644
--- a/src/gui-util.h
+++ b/src/gui-util.h
@@ -126,6 +126,9 @@ void gnm_dialog_setup_destroy_handlers (GtkDialog *dialog,
 
 void gnm_canvas_get_position (GocCanvas *canvas, int *x, int *y,
 			      gint64 px, gint64 py);
+void gnm_canvas_get_screen_position (GocCanvas *canvas,
+				     double x, double y,
+				     int *ix, int *iy);
 
 gboolean gnm_check_for_plugins_missing (char const **ids, GtkWindow *parent);
 
diff --git a/src/sheet-object-cell-comment.c b/src/sheet-object-cell-comment.c
index 32ea58c..b2bd99e 100644
--- a/src/sheet-object-cell-comment.c
+++ b/src/sheet-object-cell-comment.c
@@ -98,26 +98,6 @@ comment_view_set_bounds (SheetObjectView *sov, double const *coords, gboolean vi
 		goc_item_hide (GOC_ITEM (sov));
 }
 
-/*
- * Get the gdk position for canvas coordinates (x,y).  This is suitable
- * for tooltip windows.
- *
- * It is possible that this does not work right for very large coordinates
- * prior to gtk+ 2.18.  See the code and comments in gnm_canvas_get_position.
- */
-static void
-comment_view_get_xy (GocItem *item, double x, double y, int *ix, int *iy)
-{
-	GdkWindow *cbw = GTK_LAYOUT (item->canvas)->bin_window;
-	int wx, wy;
-
-	gdk_window_get_origin (cbw, &wx, &wy);
-	goc_canvas_c2w (item->canvas, x, y, ix, iy);
-	(*ix) += wx;
-	(*iy) += wy;
-}
-
-
 static gboolean
 comment_view_button_released (GocItem *item, int button, double x, double y)
 {
@@ -127,7 +107,7 @@ comment_view_button_released (GocItem *item, int button, double x, double y)
 	if (button != 1)
 		return FALSE;
 
-	comment_view_get_xy (item, x, y, &ix, &iy);
+	gnm_canvas_get_screen_position (item->canvas, x, y, &ix, &iy);
 	so = sheet_object_view_get_so (SHEET_OBJECT_VIEW (item));
 	scg_comment_display (GNM_PANE (item->canvas)->simple.scg,
 	                     CELL_COMMENT (so),
@@ -166,7 +146,7 @@ comment_view_enter_notify (GocItem *item, double x, double y)
 
 	gnm_widget_set_cursor_type (GTK_WIDGET (item->canvas), GDK_ARROW);
 
-	comment_view_get_xy (item, x, y, &ix, &iy);
+	gnm_canvas_get_screen_position (item->canvas, x, y, &ix, &iy);
 	so = sheet_object_view_get_so (SHEET_OBJECT_VIEW (item));
 
 	scg_comment_select (GNM_PANE (item->canvas)->simple.scg,



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