[gnumeric] Cell Comments: avoid the use of gdk_window_get_pointer.



commit ced6391c06534323b428ba8ee1db952107a5a938
Author: Morten Welinder <terra gnome org>
Date:   Mon Mar 8 12:02:30 2010 -0500

    Cell Comments: avoid the use of gdk_window_get_pointer.

 ChangeLog                       |    2 +
 src/sheet-control-gui-priv.h    |    1 +
 src/sheet-control-gui.c         |   14 ++++++------
 src/sheet-control-gui.h         |    6 +++-
 src/sheet-object-cell-comment.c |   41 ++++++++++++++++++++++++++++++++++++--
 5 files changed, 52 insertions(+), 12 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 52fc580..7ad63db 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,8 @@
 2010-03-08  Morten Welinder  <terra gnome org>
 
 	* src/sheet-control-gui.c (scg_comment_select): Fix critical.
+	(scg_comment_display, scg_comment_select): Take window position
+	too.  All callers changed.  Fixes part of #573028.
 
 2010-03-06  Jean Brefort  <jean brefort normalesup org>
 
diff --git a/src/sheet-control-gui-priv.h b/src/sheet-control-gui-priv.h
index 5b3f444..67a72ea 100644
--- a/src/sheet-control-gui-priv.h
+++ b/src/sheet-control-gui-priv.h
@@ -54,6 +54,7 @@ struct _SheetControlGUI {
 		GnmComment *selected;
 		GtkWidget   *item;	/* TODO : make this a canvas item with an arrow */
 		int	     timer;
+		int          x, y;
 	} comment;
 
 	struct {
diff --git a/src/sheet-control-gui.c b/src/sheet-control-gui.c
index ac74280..e38ef7f 100644
--- a/src/sheet-control-gui.c
+++ b/src/sheet-control-gui.c
@@ -2534,10 +2534,9 @@ scg_object_anchor_to_coords (SheetControlGUI const *scg,
  *
  */
 void
-scg_comment_display (SheetControlGUI *scg, GnmComment *cc)
+scg_comment_display (SheetControlGUI *scg, GnmComment *cc,
+		     int x, int y)
 {
-	int x, y;
-
 	g_return_if_fail (IS_SHEET_CONTROL_GUI (scg));
 
 	scg_comment_timer_clear (scg);
@@ -2564,8 +2563,6 @@ scg_comment_display (SheetControlGUI *scg, GnmComment *cc)
 
 		scg->comment.item = gtk_window_new (GTK_WINDOW_POPUP);
 		gtk_window_set_screen (GTK_WINDOW (scg->comment.item), screen);
-		gdk_window_get_pointer (gdk_screen_get_root_window (screen),
-					&x, &y, NULL);
 		gtk_window_move (GTK_WINDOW (scg->comment.item), x+10, y+10);
 
 		text = gtk_text_view_new ();
@@ -2610,7 +2607,8 @@ cb_cell_comment_timer (SheetControlGUI *scg)
 	g_return_val_if_fail (scg->comment.timer != -1, FALSE);
 
 	scg->comment.timer = -1;
-	scg_comment_display (scg, scg->comment.selected);
+	scg_comment_display (scg, scg->comment.selected,
+			     scg->comment.x, scg->comment.y);
 	return FALSE;
 }
 
@@ -2622,7 +2620,7 @@ cb_cell_comment_timer (SheetControlGUI *scg)
  * Prepare @cc for display.
  */
 void
-scg_comment_select (SheetControlGUI *scg, GnmComment *cc)
+scg_comment_select (SheetControlGUI *scg, GnmComment *cc, int x, int y)
 {
 	g_return_if_fail (IS_SHEET_CONTROL_GUI (scg));
 
@@ -2634,6 +2632,8 @@ scg_comment_select (SheetControlGUI *scg, GnmComment *cc)
 	scg->comment.selected = cc;
 	scg->comment.timer = g_timeout_add (1000,
 		(GSourceFunc)cb_cell_comment_timer, scg);
+	scg->comment.x = x;
+	scg->comment.y = y;
 }
 
 /**
diff --git a/src/sheet-control-gui.h b/src/sheet-control-gui.h
index cd88523..19a29b4 100644
--- a/src/sheet-control-gui.h
+++ b/src/sheet-control-gui.h
@@ -42,8 +42,10 @@ void scg_object_select		(SheetControlGUI *scg, SheetObject *so);
 void scg_object_unselect	(SheetControlGUI *scg, SheetObject *so);
 void scg_object_select_next	(SheetControlGUI *scg, gboolean reverse);
 
-void scg_comment_select		(SheetControlGUI *scg, GnmComment *cc);
-void scg_comment_display	(SheetControlGUI *scg, GnmComment *cc);
+void scg_comment_select		(SheetControlGUI *scg, GnmComment *cc,
+				 int x, int y);
+void scg_comment_display	(SheetControlGUI *scg, GnmComment *cc,
+				 int x, int y);
 void scg_comment_unselect	(SheetControlGUI *scg, GnmComment *cc);
 
 void scg_select_all		(SheetControlGUI *scg);
diff --git a/src/sheet-object-cell-comment.c b/src/sheet-object-cell-comment.c
index e215e6f..32ea58c 100644
--- a/src/sheet-object-cell-comment.c
+++ b/src/sheet-object-cell-comment.c
@@ -98,14 +98,41 @@ 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)
 {
-	if (button !=1)
+	SheetObject *so;
+	int ix, iy;
+
+	if (button != 1)
 		return FALSE;
 
+	comment_view_get_xy (item, 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 (sheet_object_view_get_so (SHEET_OBJECT_VIEW (item))));
+	                     CELL_COMMENT (so),
+			     ix, iy);
+
 	return TRUE;
 }
 
@@ -134,9 +161,17 @@ comment_view_button2_pressed (GocItem *item, int button, double x, double y)
 static gboolean
 comment_view_enter_notify (GocItem *item, double x, double y)
 {
+	int ix, iy;
+	SheetObject *so;
+
 	gnm_widget_set_cursor_type (GTK_WIDGET (item->canvas), GDK_ARROW);
+
+	comment_view_get_xy (item, x, y, &ix, &iy);
+	so = sheet_object_view_get_so (SHEET_OBJECT_VIEW (item));
+
 	scg_comment_select (GNM_PANE (item->canvas)->simple.scg,
-	                     CELL_COMMENT (sheet_object_view_get_so (SHEET_OBJECT_VIEW (item))));
+			    CELL_COMMENT (so),
+			    ix, iy);
 	return TRUE;
 }
 



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