[gnumeric] Add cell view to auto expression.
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnumeric] Add cell view to auto expression.
- Date: Fri, 4 Nov 2011 15:31:07 +0000 (UTC)
commit 899927791706d576a5a37052b2badf1d5a4a05e4
Author: Andreas J Guelzow <aguelzow pyrshep ca>
Date: Fri Nov 4 09:30:35 2011 -0600
Add cell view to auto expression.
2011-11-04 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/wbc-gtk.c (cb_auto_expr_cell_changed): new
(cb_auto_expr_changed): set new auto-expr properties
(cb_select_auto_expr): create new auto-expression menu item
* src/workbook-view.c (wb_view_auto_expr_recalc): handle possible
cell formula
(wb_view_auto_expr_cell): new
(wb_view_auto_expr_sheet): new
(wb_view_set_property): handle new properties
(wb_view_get_property): handle new properties
(workbook_view_class_init): install new properties
* src/workbook-view.h (_WorkbookView): add new fields
ChangeLog | 14 ++++++++
NEWS | 1 +
src/wbc-gtk.c | 51 ++++++++++++++++++++++++++++
src/workbook-view.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++----
src/workbook-view.h | 2 +
5 files changed, 152 insertions(+), 8 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index c95d653..8fadaad 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2011-11-04 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * src/wbc-gtk.c (cb_auto_expr_cell_changed): new
+ (cb_auto_expr_changed): set new auto-expr properties
+ (cb_select_auto_expr): create new auto-expression menu item
+ * src/workbook-view.c (wb_view_auto_expr_recalc): handle possible
+ cell formula
+ (wb_view_auto_expr_cell): new
+ (wb_view_auto_expr_sheet): new
+ (wb_view_set_property): handle new properties
+ (wb_view_get_property): handle new properties
+ (workbook_view_class_init): install new properties
+ * src/workbook-view.h (_WorkbookView): add new fields
+
2011-11-03 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/workbook-view.c (wb_view_auto_expr_attrs): ref -> unref
diff --git a/NEWS b/NEWS
index 65ed37c..ee457a0 100644
--- a/NEWS
+++ b/NEWS
@@ -78,6 +78,7 @@ Morten:
* Embed ui files into the Gnumeric binary.
* Get rid of obsolete code.
* Add ODF.SUMPRODUCT compatibility function. [#662551]
+ * Add cell view to auto expression.
Valek:
* In xls import, set LABEL encoding based on FONT charset converted to
diff --git a/src/wbc-gtk.c b/src/wbc-gtk.c
index f0549e8..279e864 100644
--- a/src/wbc-gtk.c
+++ b/src/wbc-gtk.c
@@ -4511,6 +4511,30 @@ wbc_gtk_setup_icons (void)
/****************************************************************************/
static void
+cb_auto_expr_cell_changed (GtkWidget *item, WBCGtk *wbcg)
+{
+ const Sheet *sheet;
+ const char *descr;
+ const GnmRange *r;
+ WorkbookView *wbv = wb_control_view (WORKBOOK_CONTROL (wbcg));
+
+ if (wbcg->updating_ui)
+ return;
+
+ descr = g_object_get_data (G_OBJECT (item), "descr");
+ sheet = g_object_get_data (G_OBJECT (item), "sheet");
+ r = g_object_get_data (G_OBJECT (item), "cell");
+
+ g_object_set (wbv,
+ "auto-expr-func", NULL,
+ "auto-expr-descr", descr,
+ "auto-expr-cell", &r->start,
+ "auto-expr-sheet", sheet,
+ NULL);
+
+}
+
+static void
cb_auto_expr_changed (GtkWidget *item, WBCGtk *wbcg)
{
const GnmFunc *func;
@@ -4526,6 +4550,8 @@ cb_auto_expr_changed (GtkWidget *item, WBCGtk *wbcg)
g_object_set (wbv,
"auto-expr-func", func,
"auto-expr-descr", descr,
+ "auto-expr-cell", NULL,
+ "auto-expr-sheet", NULL,
NULL);
}
@@ -4663,6 +4689,9 @@ cb_select_auto_expr (GtkWidget *widget, GdkEventButton *event, WBCGtk *wbcg)
Sheet *sheet = wb_view_cur_sheet (wbv);
GtkWidget *item, *menu;
int i;
+ GnmRange *r = g_new (GnmRange, 1);
+ char const *rname;
+ char * cell_item;
if (event->button != 3)
return FALSE;
@@ -4707,6 +4736,28 @@ cb_select_auto_expr (GtkWidget *widget, GdkEventButton *event, WBCGtk *wbcg)
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
gtk_widget_show (item);
+ range_init_cellpos (r, &(scg_view (wbcg_cur_scg (wbcg)))->edit_pos);
+ rname = range_as_string (r);
+ cell_item = g_strdup_printf (_("Content of cell %s!%s"), sheet->name_unquoted, rname);
+ item = gtk_menu_item_new_with_label(cell_item);
+ g_free (cell_item);
+ g_object_set_data_full (G_OBJECT (item),
+ "descr", (gpointer)g_strdup (rname),
+ (GDestroyNotify)g_free);
+ g_object_set_data_full (G_OBJECT (item),
+ "cell", (gpointer)r,
+ (GDestroyNotify)g_free);
+ g_object_set_data (G_OBJECT (item),
+ "sheet", (gpointer)sheet);
+ g_signal_connect (G_OBJECT (item), "activate",
+ G_CALLBACK (cb_auto_expr_cell_changed), wbcg);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+
+ item = gtk_separator_menu_item_new ();
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+
item = gtk_check_menu_item_new_with_label (_("Use maximum precision"));
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (item),
wbv->auto_expr_use_max_precision);
diff --git a/src/workbook-view.c b/src/workbook-view.c
index 41e64df..4143e4e 100644
--- a/src/workbook-view.c
+++ b/src/workbook-view.c
@@ -77,6 +77,8 @@ enum {
PROP_AUTO_EXPR_MAX_PRECISION,
PROP_AUTO_EXPR_TEXT,
PROP_AUTO_EXPR_ATTRS,
+ PROP_AUTO_EXPR_CELL,
+ PROP_AUTO_EXPR_SHEET,
PROP_SHOW_HORIZONTAL_SCROLLBAR,
PROP_SHOW_VERTICAL_SCROLLBAR,
PROP_SHOW_NOTEBOOK_TABS,
@@ -501,25 +503,50 @@ wb_view_auto_expr_recalc (WorkbookView *wbv)
GnmValue *v;
SheetView *sv;
GnmExprTop const *texpr;
+ GnmRange r;
+ GString *str;
g_return_if_fail (IS_WORKBOOK_VIEW (wbv));
sv = wb_view_cur_sheet_view (wbv);
if (wbv->current_sheet == NULL ||
- wbv->auto_expr_func == NULL ||
sv == NULL)
return;
- sv_selection_apply (sv, &accumulate_regions, FALSE, &selection);
-
- texpr = gnm_expr_top_new
- (gnm_expr_new_funcall (wbv->auto_expr_func, selection));
+ if (wbv->auto_expr_sheet != NULL &&
+ wbv->auto_expr_descr != NULL &&
+ wbv->auto_expr_cell.row >= 0 &&
+ wbv->auto_expr_cell.col >= 0) {
+ /* We need to check that wbv->auto_expr_sheet is still valid */
+ GSList *sheets = workbook_sheets (wbv->wb);
+ if (g_slist_find (sheets, wbv->auto_expr_sheet) == NULL) {
+ v = value_new_error_REF (NULL);
+ str = g_string_new ("?!");
+ } else {
+ range_init_cellpos (&r, &wbv->auto_expr_cell);
+ v = value_new_cellrange_r (wbv->auto_expr_sheet, &r);
+ if (strlen (wbv->auto_expr_sheet->name_unquoted) < 8) {
+ str = g_string_new
+ (wbv->auto_expr_sheet->name_unquoted);
+ g_string_append_c (str, '!');
+ } else
+ str = g_string_new ("\342\200\246!");
+ }
+ texpr = gnm_expr_top_new_constant (v);
+ g_string_append (str, wbv->auto_expr_descr);
+ } else if (wbv->auto_expr_func != NULL &&
+ wbv->auto_expr_descr != NULL) {
+ sv_selection_apply (sv, &accumulate_regions, FALSE, &selection);
+ texpr = gnm_expr_top_new
+ (gnm_expr_new_funcall (wbv->auto_expr_func, selection));
+ str = g_string_new (wbv->auto_expr_descr);
+ } else
+ return;
eval_pos_init_sheet (&ep, wbv->current_sheet);
v = gnm_expr_top_eval (texpr, &ep, GNM_EXPR_EVAL_SCALAR_NON_EMPTY);
if (v) {
- GString *str = g_string_new (wbv->auto_expr_descr);
GOFormat const *format = NULL;
GOFormat const *tmp_format = NULL;
PangoAttrList *attrs = NULL;
@@ -575,7 +602,6 @@ wb_view_auto_expr_recalc (WorkbookView *wbv)
"auto-expr-text", str->str,
"auto-expr-attrs", attrs,
NULL);
- g_string_free (str, TRUE);
pango_attr_list_unref (attrs);
value_release (v);
} else {
@@ -584,7 +610,7 @@ wb_view_auto_expr_recalc (WorkbookView *wbv)
"auto-expr-attrs", NULL,
NULL);
}
-
+ g_string_free (str, TRUE);
gnm_expr_top_unref (texpr);
}
@@ -698,6 +724,28 @@ wb_view_auto_expr_attrs (WorkbookView *wbv, PangoAttrList *attrs)
}
static void
+wb_view_auto_expr_cell (WorkbookView *wbv, gpointer *cell)
+{
+ if (cell == NULL) {
+ wbv->auto_expr_cell.col = -1;
+ wbv->auto_expr_cell.row = -1;
+ } else {
+ wbv->auto_expr_cell = *((GnmCellPos *)cell);
+ wb_view_auto_expr_recalc (wbv);
+ }
+}
+
+static void
+wb_view_auto_expr_sheet (WorkbookView *wbv, gpointer *sheet)
+{
+ wbv->auto_expr_sheet = (Sheet *)sheet;
+
+ if (sheet != NULL)
+ wb_view_auto_expr_recalc (wbv);
+}
+
+
+static void
wb_view_set_property (GObject *object, guint property_id,
const GValue *value, GParamSpec *pspec)
{
@@ -719,6 +767,12 @@ wb_view_set_property (GObject *object, guint property_id,
case PROP_AUTO_EXPR_ATTRS:
wb_view_auto_expr_attrs (wbv, g_value_peek_pointer (value));
break;
+ case PROP_AUTO_EXPR_CELL:
+ wb_view_auto_expr_cell (wbv, g_value_get_pointer (value));
+ break;
+ case PROP_AUTO_EXPR_SHEET:
+ wb_view_auto_expr_sheet (wbv, g_value_get_pointer (value));
+ break;
case PROP_SHOW_HORIZONTAL_SCROLLBAR:
wbv->show_horizontal_scrollbar = !!g_value_get_boolean (value);
break;
@@ -778,6 +832,12 @@ wb_view_get_property (GObject *object, guint property_id,
case PROP_AUTO_EXPR_ATTRS:
g_value_set_boxed (value, wbv->auto_expr_attrs);
break;
+ case PROP_AUTO_EXPR_CELL:
+ g_value_set_pointer (value, &wbv->auto_expr_cell);
+ break;
+ case PROP_AUTO_EXPR_SHEET:
+ g_value_set_pointer (value, wbv->auto_expr_sheet);
+ break;
case PROP_SHOW_HORIZONTAL_SCROLLBAR:
g_value_set_boolean (value, wbv->show_horizontal_scrollbar);
break;
@@ -934,6 +994,22 @@ workbook_view_class_init (GObjectClass *gobject_class)
GSF_PARAM_STATIC | G_PARAM_READWRITE));
g_object_class_install_property
(gobject_class,
+ PROP_AUTO_EXPR_CELL,
+ g_param_spec_pointer ("auto-expr-cell",
+ _("Auto-expression Cell Position"),
+ _("The address of the cell to be shown."),
+ GSF_PARAM_STATIC |
+ G_PARAM_READWRITE));
+ g_object_class_install_property
+ (gobject_class,
+ PROP_AUTO_EXPR_SHEET,
+ g_param_spec_pointer ("auto-expr-sheet",
+ _("Auto-expression Sheet"),
+ _("The sheet on which the cell resides."),
+ GSF_PARAM_STATIC |
+ G_PARAM_READWRITE));
+ g_object_class_install_property
+ (gobject_class,
PROP_SHOW_HORIZONTAL_SCROLLBAR,
g_param_spec_boolean ("show-horizontal-scrollbar",
_("Show horizontal scrollbar"),
diff --git a/src/workbook-view.h b/src/workbook-view.h
index c74b7f6..4118fd8 100644
--- a/src/workbook-view.h
+++ b/src/workbook-view.h
@@ -35,6 +35,8 @@ struct _WorkbookView {
char *auto_expr_text;
PangoAttrList *auto_expr_attrs;
gboolean auto_expr_use_max_precision;
+ Sheet *auto_expr_sheet;
+ GnmCellPos auto_expr_cell;
/* selection */
char *selection_description;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]