[gnumeric] ItemEdit: fix breakage stemming from canvas construction changes.



commit aa5a619bb1c7d6fdbaf8fe111209c58cc6c8a3f5
Author: Morten Welinder <terra gnome org>
Date:   Thu Sep 17 10:49:55 2009 -0400

    ItemEdit: fix breakage stemming from canvas construction changes.

 ChangeLog       |    8 ++
 src/item-edit.c |  198 ++++++++++++++++++++++++++++---------------------------
 2 files changed, 109 insertions(+), 97 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 35dcfd3..bac78e1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2009-09-17  Morten Welinder  <terra gnome org>
+
+	* src/item-edit.c (item_edit_class_init): Don't set ::dispose.
+	(item_edit_unrealize): Merge item_edit_dispose into here.
+	(item_edit_dispose): Remove.
+	(item_edit_realize): Merge most of item_edit_set_property into
+	here.
+
 2009-09-16  Morten Welinder  <terra gnome org>
 
 	* Makefile.am (install-exec-local): Install gnumeric-features.h in
diff --git a/src/item-edit.c b/src/item-edit.c
index c6ead22..c227078 100644
--- a/src/item-edit.c
+++ b/src/item-edit.c
@@ -298,29 +298,22 @@ item_edit_update_bounds (GocItem *item)
 	}
 }
 
-static void
-item_edit_realize (GocItem *item)
+static int
+cb_entry_key_press (GocItem *item)
 {
-	ItemEdit *ie = ITEM_EDIT (item);
-	if (parent_class->realize)
-		(parent_class->realize) (item);
-
-	ie->layout = gtk_widget_create_pango_layout (GTK_WIDGET (item->canvas), NULL);
-	if (ie->scg)
-		pango_layout_set_alignment (ie->layout,
-			scg_sheet (ie->scg)->text_is_rtl ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT);
+	goc_item_bounds_changed (item);
+	return TRUE;
 }
 
-static void
-item_edit_unrealize (GocItem *item)
+static int
+cb_entry_cursor_event (GocItem *item)
 {
-	ItemEdit *ie = ITEM_EDIT (item);
-
-	g_object_unref (G_OBJECT (ie->layout));
-	ie->layout = NULL;
+	/* ensure we draw a cursor when moving quickly no matter what the
+	 * current state is */
+	ITEM_EDIT (item)->cursor_visible = TRUE;
+	goc_item_invalidate (item);
 
-	if (parent_class->unrealize)
-		(parent_class->unrealize) (item);
+	return TRUE;
 }
 
 static int
@@ -360,20 +353,75 @@ item_edit_cursor_blink_start (ItemEdit *ie)
 }
 
 static void
-item_edit_init (ItemEdit *ie)
+item_edit_realize (GocItem *item)
 {
-	ie->scg = NULL;
-	ie->pos.col = -1;
-	ie->pos.row = -1;
-	ie->gfont = NULL;
-	ie->style      = NULL;
-	ie->cursor_visible = TRUE;
+	ItemEdit *ie = ITEM_EDIT (item);
+	Sheet const *sheet;
+	GnmPane	*pane;
+	double scale;
+
+	parent_class->realize (item);
+
+	sheet = scg_sheet (ie->scg);
+
+	g_signal_connect_object (G_OBJECT (scg_wbcg (ie->scg)),
+		"markup-changed",
+		G_CALLBACK (goc_item_invalidate), G_OBJECT (ie),
+		G_CONNECT_SWAPPED);
+
+	g_signal_connect_object (G_OBJECT (gtk_widget_get_parent (GTK_WIDGET (ie->entry))),
+		"changed",
+		G_CALLBACK (goc_item_bounds_changed), G_OBJECT (ie),
+		G_CONNECT_SWAPPED);
+
+	g_signal_connect_object (G_OBJECT (ie->entry),
+		"key-press-event",
+		G_CALLBACK (cb_entry_key_press), G_OBJECT (ie),
+		G_CONNECT_AFTER|G_CONNECT_SWAPPED);
+
+	g_signal_connect_object (G_OBJECT (ie->entry),
+		"notify::cursor-position",
+		G_CALLBACK (cb_entry_cursor_event), G_OBJECT (ie),
+		G_CONNECT_AFTER|G_CONNECT_SWAPPED);
+
+	pane = GNM_PANE (item->canvas);
+	scale = item->canvas->pixels_per_unit;
+	ie->style = gnm_style_dup
+		(sheet_style_get (sheet, ie->pos.col, ie->pos.row));
+	ie->gfont = gnm_style_get_font (ie->style, sheet->context);
+	gnm_font_ref (ie->gfont);
+
+	if (gnm_style_get_align_h (ie->style) == HALIGN_GENERAL)
+		gnm_style_set_align_h (ie->style, HALIGN_LEFT);
+
+	/* move inwards 1 pixel from the grid line */
+	item->y0 = (1 + pane->first_offset.y +
+		    scg_colrow_distance_get (ie->scg, FALSE,
+					     pane->first.row,
+					     ie->pos.row)) / scale;
+	item->x0 = (1 + pane->first_offset.x +
+		    scg_colrow_distance_get (ie->scg, TRUE,
+					     pane->first.col,
+					     ie->pos.col)) / scale;
+
+	item->x1 = item->x0 + 1 / scale;
+	item->y1 = item->y0 + 1 / scale;
+
+	ie->layout = gtk_widget_create_pango_layout (GTK_WIDGET (item->canvas),
+						     NULL);
+
+	pango_layout_set_alignment (ie->layout,
+				    sheet->text_is_rtl
+				    ? PANGO_ALIGN_RIGHT
+				    : PANGO_ALIGN_LEFT);
+
+	item_edit_cursor_blink_start (ie);
 }
 
 static void
-item_edit_dispose (GObject *gobject)
+item_edit_unrealize (GocItem *item)
 {
-	ItemEdit *ie = ITEM_EDIT (gobject);
+	ItemEdit *ie = ITEM_EDIT (item);
 
 	item_edit_cursor_blink_stop (ie);
 
@@ -381,6 +429,11 @@ item_edit_dispose (GObject *gobject)
 	SCG_FOREACH_PANE (ie->scg, pane,
 		gnm_pane_expr_cursor_stop (pane););
 
+	if (ie->layout) {
+		g_object_unref (G_OBJECT (ie->layout));
+		ie->layout = NULL;
+	}
+
 	if (ie->gfont != NULL) {
 		gnm_font_unref (ie->gfont);
 		ie->gfont = NULL;
@@ -390,88 +443,40 @@ item_edit_dispose (GObject *gobject)
 		ie->style= NULL;
 	}
 
-	G_OBJECT_CLASS (parent_class)->dispose (gobject);
-}
-
-static int
-cb_entry_key_press (GocItem *item)
-{
-	goc_item_bounds_changed (item);
-	return TRUE;
+	parent_class->unrealize (item);
 }
 
-static int
-cb_entry_cursor_event (GocItem *item)
+static void
+item_edit_init (ItemEdit *ie)
 {
-	/* ensure we draw a cursor when moving quickly no matter what the
-	 * current state is */
-	ITEM_EDIT (item)->cursor_visible = TRUE;
-	goc_item_invalidate (item);
-
-	return TRUE;
+	ie->scg = NULL;
+	ie->pos.col = -1;
+	ie->pos.row = -1;
+	ie->gfont = NULL;
+	ie->style      = NULL;
+	ie->cursor_visible = TRUE;
 }
 
 static void
 item_edit_set_property (GObject *gobject, guint param_id,
 			GValue const *value, GParamSpec *pspec)
 {
-	GocItem *item      = GOC_ITEM (gobject);
-	ItemEdit        *ie = ITEM_EDIT (gobject);
-	GnmPane		*pane = GNM_PANE (item->canvas);
-	SheetView const	*sv;
-	double scale = item->canvas->pixels_per_unit;
-
-	/* We can only set the sheet-control-gui once */
-	g_return_if_fail (param_id == ARG_SHEET_CONTROL_GUI);
-	g_return_if_fail (ie->scg == NULL);
+	ItemEdit *ie = ITEM_EDIT (gobject);
 
-	ie->scg = SHEET_CONTROL_GUI (g_value_get_object (value));
+	switch (param_id) {
+	case ARG_SHEET_CONTROL_GUI: {
+		/* We can only set the sheet-control-gui once */
+		g_return_if_fail (ie->scg == NULL);
 
-	sv = scg_view (ie->scg);
-	ie->pos = sv->edit_pos;
-	ie->entry = wbcg_get_entry (scg_wbcg (ie->scg));
-	g_signal_connect_object (G_OBJECT (scg_wbcg (ie->scg)),
-		"markup-changed",
-		G_CALLBACK (goc_item_invalidate), G_OBJECT (ie), G_CONNECT_SWAPPED);
-	g_signal_connect_object (G_OBJECT (gtk_widget_get_parent (GTK_WIDGET (ie->entry))),
-		"changed",
-		G_CALLBACK (goc_item_bounds_changed), G_OBJECT (ie), G_CONNECT_SWAPPED);
-	g_signal_connect_object (G_OBJECT (ie->entry),
-		"key-press-event",
-		G_CALLBACK (cb_entry_key_press), G_OBJECT (ie), G_CONNECT_AFTER|G_CONNECT_SWAPPED);
-	g_signal_connect_object (G_OBJECT (ie->entry),
-		"notify::cursor-position",
-		G_CALLBACK (cb_entry_cursor_event), G_OBJECT (ie), G_CONNECT_AFTER|G_CONNECT_SWAPPED);
-
-	/* set the font and the upper left corner if this is the first pass */
-	if (ie->gfont == NULL) {
-		Sheet const *sheet = sv->sheet;
-		ie->style = gnm_style_dup (
-			sheet_style_get (sheet, ie->pos.col, ie->pos.row));
-		ie->gfont = gnm_style_get_font (ie->style,
-						sheet->context);
-		gnm_font_ref (ie->gfont);
-
-		if (gnm_style_get_align_h (ie->style) == HALIGN_GENERAL)
-			gnm_style_set_align_h (ie->style, HALIGN_LEFT);
-
-		/* move inwards 1 pixel from the grid line */
-		item->y0 = (1 + pane->first_offset.y +
-			scg_colrow_distance_get (ie->scg, FALSE,
-				pane->first.row, ie->pos.row)) / scale;
-		item->x0 = (1 + pane->first_offset.x +
-			scg_colrow_distance_get (ie->scg, TRUE,
-				pane->first.col, ie->pos.col)) / scale;
-
-		item->x1 = item->x0 + 1 / scale;
-		item->y1 = item->y0 + 1 / scale;
+		ie->scg = SHEET_CONTROL_GUI (g_value_get_object (value));
+		ie->pos = scg_view (ie->scg)->edit_pos;
+		ie->entry = wbcg_get_entry (scg_wbcg (ie->scg));
+		break;
 	}
 
-	if (ie->layout)
-		pango_layout_set_alignment (ie->layout,
-			scg_sheet (ie->scg)->text_is_rtl ? PANGO_ALIGN_RIGHT : PANGO_ALIGN_LEFT);
-
-	item_edit_cursor_blink_start (ie);
+	default: G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, param_id, pspec);
+		return; /* NOTE : RETURN */
+	}
 }
 
 static void
@@ -482,7 +487,6 @@ item_edit_class_init (GObjectClass *gobject_class)
 	parent_class = g_type_class_peek_parent (gobject_class);
 
 	gobject_class->set_property = item_edit_set_property;
-	gobject_class->dispose	   = item_edit_dispose;
 
 	g_object_class_install_property (gobject_class, ARG_SHEET_CONTROL_GUI,
 		g_param_spec_object ("SheetControlGUI", "SheetControlGUI",



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