[gnumeric] Add auto expression menu item to add formula. Part of [#8872]
- From: Andreas J. Guelzow <guelzow src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnumeric] Add auto expression menu item to add formula. Part of [#8872]
- Date: Thu, 31 Dec 2009 20:55:57 +0000 (UTC)
commit 331b204bd1af2b9833c1061d69f2fe922dee9b59
Author: Andreas J. Guelzow <aguelzow pyrshep ca>
Date: Thu Dec 31 13:55:03 2009 -0700
Add auto expression menu item to add formula. Part of [#8872]
2009-12-31 Andreas J. Guelzow <aguelzow pyrshep ca>
* wbc-gtk.c (cb_auto_expr_insert_formula_below): new
(cb_select_auto_expr): add separator and menu item
2009-12-31 Andreas J. Guelzow <aguelzow pyrshep ca>
* analysis-auto-expression.c: new
* analysis-auto-expression.h: new
* Makefile.am: add the above
2009-12-31 Andreas J. Guelzow <aguelzow pyrshep ca>
* POTFILES.in: added src/tools/analysis-auto-expression.c
2009-12-31 Andreas J. Guelzow <aguelzow pyrshep ca>
* POTFILES.in: added src/tools/analysis-auto-expression.c
ChangeLog | 5 ++
NEWS | 3 +-
po-functions/ChangeLog | 4 +
po-functions/POTFILES.in | 1 +
po/ChangeLog | 4 +
po/POTFILES.in | 1 +
src/tools/ChangeLog | 6 ++
src/tools/Makefile.am | 2 +
src/tools/analysis-auto-expression.c | 106 ++++++++++++++++++++++++++++++++++
src/tools/analysis-auto-expression.h | 46 +++++++++++++++
src/wbc-gtk.c | 85 +++++++++++++++++++++++++++
11 files changed, 262 insertions(+), 1 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 738976e..c6acf46 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-12-31 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * wbc-gtk.c (cb_auto_expr_insert_formula_below): new
+ (cb_select_auto_expr): add separator and menu item
+
2009-12-30 Andreas J. Guelzow <aguelzow pyrshep ca>
* src/sheet-object-widget.c (sheet_widget_draw_cairo): only use
diff --git a/NEWS b/NEWS
index ba0dea8..4b75356 100644
--- a/NEWS
+++ b/NEWS
@@ -21,7 +21,8 @@ Andreas:
* Create default tip for hyperlinks. [#316974]
* Add GET.LINK. [#128534]
* Add "Don't change formulae" to paste special. [#123326]
- * Select pasted objects. [#604227]
+ * Select pasted objects. [#604227]
+ * Add auto expression menuitem to add formula. Part of [#8872]
Jean
* Fix import export of line type in scatter plots. [#605043]
diff --git a/po-functions/ChangeLog b/po-functions/ChangeLog
index da438a1..cbfe219 100644
--- a/po-functions/ChangeLog
+++ b/po-functions/ChangeLog
@@ -1,3 +1,7 @@
+2009-12-31 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * POTFILES.in: added src/tools/analysis-auto-expression.c
+
2009-12-26 Andreas J. Guelzow <aguelzow pyrshep ca>
* POTFILES.in: added src/dialogs/dialog-sheetobject-size.c
diff --git a/po-functions/POTFILES.in b/po-functions/POTFILES.in
index 237a28e..426538d 100644
--- a/po-functions/POTFILES.in
+++ b/po-functions/POTFILES.in
@@ -193,6 +193,7 @@ src/stf.c
src/style.c
src/test-pango.c
src/tools/analysis-anova.c
+src/tools/analysis-auto-expression.c
src/tools/analysis-chi-squared.c
src/tools/analysis-exp-smoothing.c
src/tools/analysis-frequency.c
diff --git a/po/ChangeLog b/po/ChangeLog
index 70289a3..921dca6 100644
--- a/po/ChangeLog
+++ b/po/ChangeLog
@@ -1,3 +1,7 @@
+2009-12-31 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * POTFILES.in: added src/tools/analysis-auto-expression.c
+
2009-12-26 Andreas J. Guelzow <aguelzow pyrshep ca>
* POTFILES.in: added src/dialogs/dialog-sheetobject-size.c and
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 24335fb..1d3d8ab 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -329,6 +329,7 @@ src/stf.c
src/style.c
src/test-pango.c
src/tools/analysis-anova.c
+src/tools/analysis-auto-expression.c
src/tools/analysis-chi-squared.c
src/tools/analysis-exp-smoothing.c
src/tools/analysis-frequency.c
diff --git a/src/tools/ChangeLog b/src/tools/ChangeLog
index a12080a..273cd4c 100644
--- a/src/tools/ChangeLog
+++ b/src/tools/ChangeLog
@@ -1,3 +1,9 @@
+2009-12-31 Andreas J. Guelzow <aguelzow pyrshep ca>
+
+ * analysis-auto-expression.c: new
+ * analysis-auto-expression.h: new
+ * Makefile.am: add the above
+
2009-12-24 Jean Brefort <jean brefort normalesup org>
* analysis-anova.c
diff --git a/src/tools/Makefile.am b/src/tools/Makefile.am
index da4dcc8..6e3de5f 100644
--- a/src/tools/Makefile.am
+++ b/src/tools/Makefile.am
@@ -17,6 +17,8 @@ noinst_LTLIBRARIES = libtools.la
libtools_la_SOURCES = \
analysis-anova.c \
analysis-anova.h \
+ analysis-auto-expression.c \
+ analysis-auto-expression.h \
analysis-chi-squared.c \
analysis-chi-squared.h \
analysis-exp-smoothing.c \
diff --git a/src/tools/analysis-auto-expression.c b/src/tools/analysis-auto-expression.c
new file mode 100644
index 0000000..7d7ce7a
--- /dev/null
+++ b/src/tools/analysis-auto-expression.c
@@ -0,0 +1,106 @@
+/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * analysis-auto-expression.c:
+ *
+ * Author:
+ * Andreas J. Guelzow <aguelzow pyrshep ca>
+ *
+ * (C) Copyright 2009 by Andreas J. Guelzow <aguelzow pyrshep ca>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gnumeric-config.h>
+#include <glib/gi18n-lib.h>
+#include "gnumeric.h"
+#include "analysis-auto-expression.h"
+#include "analysis-tools.h"
+#include "value.h"
+#include "ranges.h"
+#include "expr.h"
+#include "func.h"
+#include "numbers.h"
+
+static gboolean
+analysis_tool_auto_expression_engine_run (data_analysis_output_t *dao,
+ analysis_tools_data_auto_expression_t *info)
+{
+ guint col;
+ GSList *data = info->base.input;
+
+ for (col = 0; data != NULL; data = data->next, col++)
+ dao_set_cell_expr
+ (dao, col, 0,
+ gnm_expr_new_funcall1
+ (info->func,
+ gnm_expr_new_constant (value_dup (data->data))));
+
+ if (info->multiple)
+ dao_set_cell_expr
+ (dao, col, 0,
+ gnm_expr_new_funcall1
+ (info->func,
+ make_rangeref (-col,0,-1,0)));
+
+ dao_redraw_respan (dao);
+
+ return FALSE;
+}
+
+static gboolean
+analysis_tool_auto_expression_engine_clean (gpointer specs)
+{
+ analysis_tools_data_auto_expression_t *info = specs;
+
+ gnm_func_unref (info->func);
+ info->func = NULL;
+
+ return analysis_tool_generic_clean (specs);
+}
+
+gboolean
+analysis_tool_auto_expression_engine (data_analysis_output_t *dao, gpointer specs,
+ analysis_tool_engine_t selector, gpointer result)
+{
+ analysis_tools_data_auto_expression_t *info = specs;
+
+ switch (selector) {
+ case TOOL_ENGINE_UPDATE_DESCRIPTOR:
+ return (dao_command_descriptor
+ (dao, _("Auto Expression (%s)"), result)
+ == NULL);
+ case TOOL_ENGINE_UPDATE_DAO:
+ prepare_input_range (&info->base.input, info->base.group_by);
+ dao_adjust (dao,
+ (info->multiple ? 1 : 0) + g_slist_length (info->base.input),
+ 1);
+ return FALSE;
+ case TOOL_ENGINE_CLEAN_UP:
+ return analysis_tool_auto_expression_engine_clean (specs);
+ case TOOL_ENGINE_LAST_VALIDITY_CHECK:
+ return FALSE;
+ case TOOL_ENGINE_PREPARE_OUTPUT_RANGE:
+ dao_prepare_output (NULL, dao, _("Auto Expression"));
+ return FALSE;
+ case TOOL_ENGINE_FORMAT_OUTPUT_RANGE:
+ return dao_format_output (dao, _("Auto Expression"));
+ case TOOL_ENGINE_PERFORM_CALC:
+ default:
+ return analysis_tool_auto_expression_engine_run (dao, specs);
+ }
+ return TRUE;
+}
+
diff --git a/src/tools/analysis-auto-expression.h b/src/tools/analysis-auto-expression.h
new file mode 100644
index 0000000..602296f
--- /dev/null
+++ b/src/tools/analysis-auto-expression.h
@@ -0,0 +1,46 @@
+/* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
+/*
+ * analysis-auto-expression.h:
+ *
+ * Author:
+ * Andreas J. Guelzow <aguelzow pyrshep ca>
+ *
+ * (C) Copyright 2009 by Andreas J. Guelzow <aguelzow pyrshep ca>
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+
+#ifndef ANALYSIS_AUTO_EXPRESSION_H
+#define ANALYSIS_AUTO_EXPRESSION_H
+
+#include "gnumeric.h"
+#include "numbers.h"
+#include "dao.h"
+#include "tools.h"
+#include "analysis-tools.h"
+#include "sheet.h"
+
+typedef struct {
+ analysis_tools_data_generic_t base;
+ gboolean multiple;
+ GnmFunc *func;
+} analysis_tools_data_auto_expression_t;
+
+gboolean analysis_tool_auto_expression_engine (data_analysis_output_t *dao, gpointer specs,
+ analysis_tool_engine_t selector, gpointer result);
+
+#endif
diff --git a/src/wbc-gtk.c b/src/wbc-gtk.c
index 5364fd2..ca46e57 100644
--- a/src/wbc-gtk.c
+++ b/src/wbc-gtk.c
@@ -56,6 +56,8 @@
#include "graph.h"
#include "selection.h"
#include "file-autoft.h"
+#include "ranges.h"
+#include "tools/analysis-auto-expression.h"
#include <goffice/goffice.h>
#include <gsf/gsf-impl-utils.h>
@@ -4137,6 +4139,73 @@ cb_auto_expr_precision_toggled (GtkWidget *item, WBCGtk *wbcg)
go_object_toggle (wbv, "auto-expr-max-precision");
}
+static void
+cb_auto_expr_insert_formula_below (GtkWidget *item, WBCGtk *wbcg)
+{
+ SheetControlGUI *scg = wbcg_cur_scg (wbcg);
+ GnmRange const *selection = selection_first_range (scg_view (scg), NULL, NULL);
+ GnmRange output;
+ GnmRange *input;
+ gboolean multiple, use_last_row;
+ data_analysis_output_t *dao;
+ analysis_tools_data_auto_expression_t *specs;
+
+ if (selection == NULL || range_height (selection) < 2)
+ return;
+
+ multiple = (range_width (selection) > 1);
+ output = *selection;
+ range_normalize (&output);
+ output.start.row = output.end.row;
+
+ use_last_row = sheet_is_region_empty (scg_sheet (scg), &output);
+
+ if (!use_last_row) {
+ if (range_translate (&output, scg_sheet (scg), 0, 1))
+ return;
+ if (multiple &&
+ (gnm_sheet_get_last_col (scg_sheet (scg)) > output.end.col))
+ output.end.col++;
+ }
+
+ input = gnm_range_dup (selection);
+ range_normalize (input);
+ if (use_last_row)
+ input->end.row--;
+
+ dao = dao_init (NULL, RangeOutput);
+ dao->start_col = output.start.col;
+ dao->start_row = output.start.row;
+ dao->cols = range_width (&output);
+ dao->rows = range_height (&output);
+ dao->sheet = scg_sheet (scg);
+ dao->autofit_flag = FALSE;
+ dao->put_formulas = TRUE;
+
+ specs = g_new0 (analysis_tools_data_auto_expression_t, 1);
+ specs->base.wbc = WORKBOOK_CONTROL (wbcg);
+ specs->base.input = g_slist_prepend (NULL, value_new_cellrange_r (scg_sheet (scg), input));
+ g_free (input);
+ specs->base.group_by = GROUPED_BY_COL;
+ specs->base.labels = FALSE;
+ specs->multiple = multiple;
+ specs->func = NULL;
+ g_object_get (G_OBJECT (wb_control_view (WORKBOOK_CONTROL (wbcg))),
+ "auto-expr-func", &(specs->func), NULL);
+ if (specs->func == NULL)
+ specs->func = gnm_func_lookup_or_add_placeholder
+ ("sum", dao->sheet ? dao->sheet->workbook : NULL, FALSE);
+ gnm_func_ref (specs->func);
+
+ cmd_analysis_tool (WORKBOOK_CONTROL (wbcg), scg_sheet (scg),
+ dao, specs, analysis_tool_auto_expression_engine);
+}
+
+/* static void */
+/* cb_auto_expr_insert_formula_to_side (GtkWidget *item, WBCGtk *wbcg) */
+/* { */
+/* } */
+
static gboolean
cb_select_auto_expr (GtkWidget *widget, GdkEventButton *event, WBCGtk *wbcg)
@@ -4223,6 +4292,22 @@ cb_select_auto_expr (GtkWidget *widget, GdkEventButton *event, WBCGtk *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_menu_item_new_with_label (_("Insert formula below."));
+ g_signal_connect (G_OBJECT (item), "activate",
+ G_CALLBACK (cb_auto_expr_insert_formula_below), wbcg);
+ gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
+ gtk_widget_show (item);
+
+/* item = gtk_menu_item_new_with_label (_("Insert formula to side.")); */
+/* g_signal_connect (G_OBJECT (item), "activate", */
+/* G_CALLBACK (cb_auto_expr_insert_formula_to_side), wbcg); */
+/* gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); */
+/* gtk_widget_show (item); */
+
gnumeric_popup_menu (GTK_MENU (menu), event);
return TRUE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]