gnumeric r17272 - in trunk: . plugins/fn-financial plugins/lotus-123 src



Author: mortenw
Date: Wed Apr  1 13:58:58 2009
New Revision: 17272
URL: http://svn.gnome.org/viewvc/gnumeric?rev=17272&view=rev

Log:
2009-04-01  Morten Welinder  <terra gnome org>

	* src/sheet.c (sheet_new_with_type): Move most of this into a
	constructor.
	(gnm_sheet_class_init): Install new property "sheet-type".



Modified:
   trunk/ChangeLog
   trunk/plugins/fn-financial/functions.c
   trunk/plugins/lotus-123/lotus.c
   trunk/src/GNOME_Gnumeric-gtk.xml.in
   trunk/src/application.h
   trunk/src/preview-grid.c
   trunk/src/sheet-style.c
   trunk/src/sheet.c
   trunk/src/sheet.h

Modified: trunk/plugins/fn-financial/functions.c
==============================================================================
--- trunk/plugins/fn-financial/functions.c	(original)
+++ trunk/plugins/fn-financial/functions.c	Wed Apr  1 13:58:58 2009
@@ -1978,7 +1978,6 @@
 
 	status = goal_seek_newton (&xirr_npv, NULL, &data, &p, rate0);
 	if (status != GOAL_SEEK_OK) {
-		double r;
 		int i;
 
 		/* This is likely to be on the left side of the root. */

Modified: trunk/plugins/lotus-123/lotus.c
==============================================================================
--- trunk/plugins/lotus-123/lotus.c	(original)
+++ trunk/plugins/lotus-123/lotus.c	Wed Apr  1 13:58:58 2009
@@ -1463,8 +1463,8 @@
 static GnmCell *
 lotus_cell_fetch (LotusState *state, Sheet *sheet, guint32 col, guint32 row)
 {
-	if (col >= gnm_sheet_get_max_cols (sheet) ||
-	    row >= gnm_sheet_get_max_rows (sheet)) {
+	if (col >= (unsigned)gnm_sheet_get_max_cols (sheet) ||
+	    row >= (unsigned)gnm_sheet_get_max_rows (sheet)) {
 		if (!state->sheet_area_error) {
 			state->sheet_area_error = TRUE;
 			g_warning ("File is most likely corrupted.\n"

Modified: trunk/src/GNOME_Gnumeric-gtk.xml.in
==============================================================================
--- trunk/src/GNOME_Gnumeric-gtk.xml.in	(original)
+++ trunk/src/GNOME_Gnumeric-gtk.xml.in	Wed Apr  1 13:58:58 2009
@@ -97,7 +97,7 @@
       <menuitem action="InsertColumns"/>
       <menuitem action="InsertRows"/>
       <menuitem action="SheetInsert"/>
-      <menuitem action="SheetSizedInsert"/>
+<!--  <menuitem action="SheetSizedInsert"/> -->
       <separator/>
       <menuitem action="ChartGuru"/>
 <!-- These don't work yet for Gnome 2 

Modified: trunk/src/application.h
==============================================================================
--- trunk/src/application.h	(original)
+++ trunk/src/application.h	Wed Apr  1 13:58:58 2009
@@ -80,7 +80,7 @@
 	GnmActionHandler	handler;
 };
 typedef struct {
-	char const *group_name;
+	char *group_name;
 	GSList	   *actions;
 	char	   *layout;
 	char const *domain;

Modified: trunk/src/preview-grid.c
==============================================================================
--- trunk/src/preview-grid.c	(original)
+++ trunk/src/preview-grid.c	Wed Apr  1 13:58:58 2009
@@ -452,9 +452,10 @@
 	item->x2 = 0;
 	item->y2 = 0;
 
-	pg->sheet = g_object_new (GNM_SHEET_TYPE, NULL);
-	pg->sheet->index_in_wb = -1;
-	pg->sheet->workbook = NULL;
+	pg->sheet = g_object_new (GNM_SHEET_TYPE,
+				  "rows", 256,
+				  "columns", 256,
+				  NULL);
 	pg->gridlines = FALSE;
 	pg->defaults.col_width = 64;
 	pg->defaults.row_height = 17;

Modified: trunk/src/sheet-style.c
==============================================================================
--- trunk/src/sheet-style.c	(original)
+++ trunk/src/sheet-style.c	Wed Apr  1 13:58:58 2009
@@ -1962,7 +1962,7 @@
 	GnmRange r;
 
 	if (most_common_in_cols != NULL) {
-		unsigned i;
+		int i;
 		for (i = 0; i < gnm_sheet_get_max_cols (sheet); i++)
 			most_common_in_cols[i] = sheet_style_most_common_in_col (sheet, i);
 	}

Modified: trunk/src/sheet.c
==============================================================================
--- trunk/src/sheet.c	(original)
+++ trunk/src/sheet.c	Wed Apr  1 13:58:58 2009
@@ -85,6 +85,7 @@
 
 enum {
 	PROP_0,
+	PROP_SHEET_TYPE,
 	PROP_NAME,
 	PROP_RTL,
 	PROP_VISIBILITY,
@@ -283,12 +284,12 @@
 
 		parse_pos_init_sheet (&pp, sheet);
 		nexpr = expr_name_lookup (&pp, "Sheet_Title");
-
-		if (nexpr != NULL)
-			expr_name_set_expr (nexpr,
-					    gnm_expr_top_new_constant
-					    (value_new_string
-					     (sheet->name_unquoted)));
+		if (nexpr) {
+			GnmExprTop const *texpr =
+				gnm_expr_top_new_constant
+				(value_new_string (sheet->name_unquoted));
+			expr_name_set_expr (nexpr, texpr);
+		}
 	}
 }
 
@@ -368,6 +369,9 @@
 	Sheet *sheet = (Sheet *)object;
 
 	switch (property_id) {
+	case PROP_SHEET_TYPE:
+		sheet->sheet_type = g_value_get_enum (value);
+		break;
 	case PROP_NAME:
 		sheet_set_name (sheet, g_value_get_string (value));
 		break;
@@ -475,9 +479,11 @@
 		sheet_set_zoom_factor (sheet, g_value_get_double (value));
 		break;
 	case PROP_COLUMNS:
+		/* Construction-time only */
 		sheet->max_cols = g_value_get_int (value);
 		break;
 	case PROP_ROWS:
+		/* Construction-time only */
 		sheet->max_rows = g_value_get_int (value);
 		break;
 	default:
@@ -493,6 +499,9 @@
 	Sheet *sheet = (Sheet *)object;
 
 	switch (property_id) {
+	case PROP_SHEET_TYPE:
+		g_value_set_enum (value, sheet->sheet_type);
+		break;
 	case PROP_NAME:
 		g_value_set_string (value, sheet->name_unquoted);
 		break;
@@ -604,6 +613,70 @@
 	}
 }
 
+static GObject *
+gnm_sheet_constructor (GType type,
+		       guint n_construct_properties,
+		       GObjectConstructParam *construct_params)
+{
+	GObject *obj;
+	Sheet *sheet;
+	
+	obj = parent_class->constructor (type, n_construct_properties,
+					 construct_params);
+	sheet = SHEET (obj);
+
+	/* Now sheet_type, max_cols, and max_rows have been set.  */
+
+	sheet->priv->reposition_objects.col = sheet->max_cols;
+	g_ptr_array_set_size (sheet->cols.info,
+			      COLROW_SEGMENT_INDEX (sheet->max_cols - 1) + 1);
+
+	sheet->priv->reposition_objects.row = sheet->max_rows;
+	g_ptr_array_set_size (sheet->rows.info,
+			      COLROW_SEGMENT_INDEX (sheet->max_rows - 1) + 1);
+
+	range_init_full_sheet (&sheet->priv->unhidden_region);
+	sheet_style_init (sheet);
+
+	sheet->deps = gnm_dep_container_new (sheet);
+
+	switch (sheet->sheet_type) {
+	case GNM_SHEET_XLM:
+		sheet->display_formulas = TRUE;
+		break;
+	case GNM_SHEET_OBJECT:
+		sheet->hide_grid = TRUE;
+		sheet->hide_col_header = sheet->hide_row_header = TRUE;
+		colrow_compute_pixels_from_pts (&sheet->rows.default_style, sheet, FALSE);
+		colrow_compute_pixels_from_pts (&sheet->cols.default_style, sheet, TRUE);
+		break;
+	case GNM_SHEET_DATA: {
+		/* We have to add permanent names */
+		GnmRange r;
+		GnmExprTop const *texpr;
+
+		if (sheet->name_unquoted)
+			texpr =	gnm_expr_top_new_constant
+				(value_new_string (sheet->name_unquoted));
+		else
+			texpr = gnm_expr_top_new_constant
+				(value_new_error_REF (NULL));
+		expr_name_perm_add (sheet, "Sheet_Title",
+				    texpr, FALSE);
+
+		range_init_full_sheet (&r);
+		texpr = gnm_expr_top_new_constant (value_new_cellrange_r (sheet, &r));
+		expr_name_perm_add (sheet, "Print_Area",
+				    texpr, TRUE);
+		break;
+	}
+	default:
+		g_assert_not_reached ();
+	}
+
+	return obj;
+}
+
 static void
 gnm_sheet_init (Sheet *sheet)
 {
@@ -630,6 +703,7 @@
 	sheet->protected_allow.edit_pivottable		= FALSE;
 	sheet->protected_allow.select_unlocked_cells	=TRUE;
 
+	sheet->hide_zero = FALSE;
 	sheet->display_outlines = TRUE;
 	sheet->outline_symbols_below = TRUE;
 	sheet->outline_symbols_right = TRUE;
@@ -648,9 +722,11 @@
 	sheet->solver_parameters = solver_param_new ();
 
 	sheet->cols.max_used = -1;
+	sheet->cols.info = g_ptr_array_new ();
 	sheet_col_set_default_size_pts (sheet, 48);
 
 	sheet->rows.max_used = -1;
+	sheet->rows.info = g_ptr_array_new ();
 	sheet_row_set_default_size_pts (sheet, 12.75);
 
 	sheet->print_info = print_info_new (FALSE);
@@ -666,7 +742,6 @@
 
 	/* Init preferences */
 	sheet->convs = gnm_conventions_default;
-	sheet->hide_zero = FALSE;
 
 	/* FIXME: probably not here.  */
 	/* See also gtk_widget_create_pango_context ().  */
@@ -676,17 +751,15 @@
 	sheet->priv->enable_showhide_detail = TRUE;
 
 	sheet->names = NULL;
-	sheet->convs = gnm_conventions_default;
-
 	sheet->style_data = NULL;
 
+	sheet->index_in_wb = -1;
+
 	/*
 	 * "zoom-factor" is a construction parameter and will thus
 	 * override this.
 	 */
 	sheet->last_zoom_factor_used = -1;
-
-	sheet->deps	 = gnm_dep_container_new (sheet);
 }
 
 static void
@@ -697,7 +770,16 @@
 	gobject_class->set_property	= gnm_sheet_set_property;
 	gobject_class->get_property	= gnm_sheet_get_property;
 	gobject_class->finalize         = gnm_sheet_finalize;
+	gobject_class->constructor      = gnm_sheet_constructor;
 
+        g_object_class_install_property (gobject_class, PROP_SHEET_TYPE,
+		 g_param_spec_enum ("sheet-type", _("Sheet Type"),
+				    _("How type of sheet this is."),
+				    GNM_SHEET_TYPE_TYPE,
+				    GNM_SHEET_DATA,
+				    GSF_PARAM_STATIC |
+				    G_PARAM_READWRITE |
+				    G_PARAM_CONSTRUCT_ONLY));
         g_object_class_install_property (gobject_class, PROP_NAME,
 		 g_param_spec_string ("name", _("Name"),
 				      _("The name of the sheet."),
@@ -897,6 +979,22 @@
 /* ------------------------------------------------------------------------- */
 
 GType
+gnm_sheet_type_get_type (void)
+{
+  static GType etype = 0;
+  if (etype == 0) {
+	  static const GEnumValue values[] = {
+		  { GNM_SHEET_DATA,   (char *)"GNM_SHEET_DATA",   (char *)"data"   },
+		  { GNM_SHEET_OBJECT, (char *)"GNM_SHEET_OBJECT", (char *)"object" },
+		  { GNM_SHEET_XLM,    (char *)"GNM_SHEET_XLM",    (char *)"xlm"    },
+		  { 0, NULL, NULL }
+	  };
+	  etype = g_enum_register_static ("GnmSheetType", values);
+  }
+  return etype;
+}
+
+GType
 gnm_sheet_visibility_get_type (void)
 {
   static GType etype = 0;
@@ -934,56 +1032,14 @@
 
 	sheet = g_object_new (GNM_SHEET_TYPE,
 			      "zoom-factor", (double)gnm_app_prefs->zoom,
-			      "columns", columns, "rows", rows, NULL);
+			      "columns", columns,
+			      "rows", rows,
+			      "name", name,
+			      "sheet-type", type,
+			      NULL);
 
-	sheet_style_init (sheet);
-	sheet->priv->reposition_objects.row = gnm_sheet_get_max_rows (sheet);
-	sheet->priv->reposition_objects.col = gnm_sheet_get_max_cols (sheet);
-	range_init_full_sheet (&sheet->priv->unhidden_region);
-	g_ptr_array_set_size (sheet->cols.info = g_ptr_array_new (),
-			      COLROW_SEGMENT_INDEX (gnm_sheet_get_max_cols (sheet) - 1) + 1);
-	g_ptr_array_set_size (sheet->rows.info = g_ptr_array_new (),
-			      COLROW_SEGMENT_INDEX (gnm_sheet_get_max_rows (sheet) - 1) + 1);
-	sheet->deps	 = gnm_dep_container_new (sheet);
-	sheet->index_in_wb = -1;
 	sheet->workbook = wb;
-	sheet->name_unquoted = g_strdup (name);
-	sheet->name_quoted = g_string_free (gnm_expr_conv_quote (
-		gnm_conventions_default, name), FALSE);
-	sheet->name_unquoted_collate_key =
-		g_utf8_collate_key (sheet->name_unquoted, -1);
-	sheet->name_case_insensitive =
-		g_utf8_casefold (sheet->name_unquoted, -1);
-	sheet->sheet_type = type;
-
-	sheet->display_formulas = (type == GNM_SHEET_XLM);
-	sheet->hide_grid =
-	sheet->hide_col_header =
-	sheet->hide_row_header = (type == GNM_SHEET_OBJECT);
-
-	if (type == GNM_SHEET_OBJECT) {
-		colrow_compute_pixels_from_pts (&sheet->rows.default_style, sheet, FALSE);
-		colrow_compute_pixels_from_pts (&sheet->cols.default_style, sheet, TRUE);
-	}
-
-	if (type == GNM_SHEET_DATA) {
-		/* We have to add permanent names */
-		{
-			expr_name_perm_add (sheet, "Sheet_Title",
-				    gnm_expr_top_new_constant (value_new_string (sheet->name_unquoted)),
-				    FALSE);
-		}
-		{
-			GnmRange r;
-			range_init_full_sheet (&r);
-			expr_name_perm_add (sheet, "Print_Area",
-				gnm_expr_top_new_constant (value_new_cellrange_r (sheet, &r)),
-				TRUE);
-		}
-	}
 
-	sheet->max_cols = columns;
-	sheet->max_rows = rows;
 	return sheet;
 }
 

Modified: trunk/src/sheet.h
==============================================================================
--- trunk/src/sheet.h	(original)
+++ trunk/src/sheet.h	Wed Apr  1 13:58:58 2009
@@ -16,6 +16,8 @@
 	GNM_SHEET_OBJECT,
 	GNM_SHEET_XLM
 } GnmSheetType;
+GType gnm_sheet_type_get_type (void);
+#define GNM_SHEET_TYPE_TYPE (gnm_sheet_type_get_type ())
 
 GType gnm_sheet_visibility_get_type (void);
 #define GNM_SHEET_VISIBILITY_TYPE (gnm_sheet_visibility_get_type ())



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