1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
7 * Jukka-Pekka Iivonen <jiivonen@hutcs.cs.hut.fi>
8 * Andreas J. Guelzow <aguelzow@taliesin.ca>
10 * (C) Copyright 2000, 2001 by Jukka-Pekka Iivonen <jiivonen@hutcs.cs.hut.fi>
11 * (C) Copyright 2001, 2002 by Andreas J. Guelzow <aguelzow@taliesin.ca>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, see <https://www.gnu.org/licenses/>.
27 #include <gnumeric-config.h>
28 #include <tools/dao.h>
36 #include "sheet-style.h"
38 #include "workbook-view.h"
39 #include "workbook-control.h"
40 #include "command-context.h"
41 #include "gnm-format.h"
42 #include "sheet-merge.h"
43 #include "sheet-object-cell-comment.h"
44 #include "style-color.h"
45 #include "style-border.h"
47 #include <goffice/goffice.h>
50 #include <glib/gi18n-lib.h>
53 #include <parse-util.h>
60 * Initialize dao to given type.
64 data_analysis_output_t
*
65 dao_init (data_analysis_output_t
*dao
,
66 data_analysis_output_type_t type
)
69 dao
= g_new (data_analysis_output_t
, 1);
70 dao
->use_gfree
= TRUE
;
72 dao
->use_gfree
= FALSE
;
79 dao
->cols
= 1; /* Fixed in dao_prepare_output */
82 dao
->autofit_flag
= TRUE
;
83 dao
->autofit_noshrink
= TRUE
;
84 dao
->clear_outputrange
= TRUE
;
85 dao
->retain_format
= FALSE
;
86 dao
->retain_comments
= FALSE
;
87 dao
->put_formulas
= FALSE
;
96 * dao_init_new_sheet: (skip)
100 data_analysis_output_t
*
101 dao_init_new_sheet (data_analysis_output_t
*dao
)
103 return dao_init (dao
, NewSheetOutput
);
106 void dao_free (data_analysis_output_t
*dao
)
108 g_slist_free_full (dao
->sos
, g_object_unref
);
116 * dao_load_from_value: (skip)
121 data_analysis_output_t
*
122 dao_load_from_value (data_analysis_output_t
*dao
,
123 GnmValue
*output_range
)
125 g_return_val_if_fail (output_range
!= NULL
, dao
);
126 g_return_val_if_fail (VALUE_IS_CELLRANGE (output_range
), dao
);
128 dao
->start_col
= output_range
->v_range
.cell
.a
.col
;
129 dao
->start_row
= output_range
->v_range
.cell
.a
.row
;
130 dao
->cols
= output_range
->v_range
.cell
.b
.col
131 - output_range
->v_range
.cell
.a
.col
+ 1;
132 dao
->rows
= output_range
->v_range
.cell
.b
.row
133 - output_range
->v_range
.cell
.a
.row
+ 1;
134 dao
->sheet
= output_range
->v_range
.cell
.a
.sheet
;
143 * Provides the name of the output range
144 * The caller has to dispose of the name
149 dao_range_name (data_analysis_output_t
*dao
)
152 range_init (&range
, dao
->start_col
, dao
->start_row
,
153 dao
->start_col
+ dao
->cols
- 1,
154 dao
->start_row
+ dao
->rows
- 1);
156 return undo_range_name (dao
->sheet
, &range
);
160 * dao_command_descriptor:
165 * Uses format to provide a string to be used as command descriptor for
171 dao_command_descriptor (data_analysis_output_t
*dao
, char const *format
,
174 char *rangename
= NULL
;
175 char **text
= result
;
177 g_return_val_if_fail (result
!= NULL
, NULL
);
182 *text
= g_strdup_printf (format
, _("New Sheet"));
184 case NewWorkbookOutput
:
185 *text
= g_strdup_printf (format
, _("New Workbook"));
189 rangename
= dao_range_name (dao
);
190 *text
= g_strdup_printf (format
, rangename
);
203 * shrinks the dao to the given cols/rows
204 * (or enlarges it if dao was a singleton)
209 dao_adjust (data_analysis_output_t
*dao
, gint cols
, gint rows
)
211 int max_rows
, max_cols
;
213 if (dao
->cols
== 1 && dao
->rows
== 1) {
220 dao
->cols
= MIN (cols
, dao
->cols
);
222 dao
->rows
= MIN (rows
, dao
->rows
);
226 max_rows
= gnm_sheet_get_max_rows (dao
->sheet
) - dao
->start_row
;
227 max_cols
= gnm_sheet_get_max_cols (dao
->sheet
) - dao
->start_col
;
229 /* In case of NewSheetOutput and NewWorkbookOutput */
230 /* this is called before we actually create the */
231 /* new sheet and/or workbook */
232 Sheet
*old_sheet
= wb_control_cur_sheet (dao
->wbc
);
233 max_rows
= gnm_sheet_get_max_rows (old_sheet
) - dao
->start_row
;
234 max_cols
= gnm_sheet_get_max_cols (old_sheet
) - dao
->start_col
;
237 if (dao
->cols
> max_cols
)
238 dao
->cols
= max_cols
;
239 if (dao
->rows
> max_rows
)
240 dao
->rows
= max_rows
;
244 * dao_prepare_output:
248 * prepares the output by creating a new sheet or workbook as appropriate
253 dao_prepare_output (WorkbookControl
*wbc
, data_analysis_output_t
*dao
,
261 if (dao
->type
== NewSheetOutput
) {
262 Sheet
*old_sheet
= dao
->wbc
263 ? wb_control_cur_sheet (dao
->wbc
)
265 Workbook
*wb
= old_sheet
->workbook
;
266 char *name_with_counter
= g_strdup_printf ("%s (1)", name
);
267 unique_name
= workbook_sheet_get_free_name
268 (wb
, name_with_counter
, FALSE
, TRUE
);
269 g_free (name_with_counter
);
270 dao
->rows
= gnm_sheet_get_max_rows (old_sheet
);
271 dao
->cols
= gnm_sheet_get_max_cols (old_sheet
);
272 dao
->sheet
= sheet_new (wb
, unique_name
, dao
->cols
, dao
->rows
);
273 g_free (unique_name
);
274 dao
->start_col
= dao
->start_row
= 0;
275 workbook_sheet_attach (wb
, dao
->sheet
);
276 } else if (dao
->type
== NewWorkbookOutput
) {
277 Sheet
*old_sheet
= wb_control_cur_sheet (dao
->wbc
);
278 Workbook
*wb
= workbook_new ();
279 dao
->rows
= gnm_sheet_get_max_rows (old_sheet
);
280 dao
->cols
= gnm_sheet_get_max_cols (old_sheet
);
281 dao
->sheet
= sheet_new (wb
, name
, dao
->cols
, dao
->rows
);
282 dao
->start_col
= dao
->start_row
= 0;
283 workbook_sheet_attach (wb
, dao
->sheet
);
284 dao
->wbc
= workbook_control_new_wrapper (dao
->wbc
, NULL
, wb
, NULL
);
288 wb_view_sheet_focus (wb_control_view (dao
->wbc
), dao
->sheet
);
290 if (dao
->rows
== 0 || (dao
->rows
== 1 && dao
->cols
== 1))
291 dao
->rows
= gnm_sheet_get_max_rows (dao
->sheet
) - dao
->start_row
;
292 if (dao
->cols
== 0 || (dao
->rows
== 1 && dao
->cols
== 1))
293 dao
->cols
= gnm_sheet_get_max_cols (dao
->sheet
) - dao
->start_col
;
303 * format's the output range according to the settings
308 dao_format_output (data_analysis_output_t
*dao
, char const *cmd
)
313 range_init (&range
, dao
->start_col
, dao
->start_row
,
314 dao
->start_col
+ dao
->cols
- 1,
315 dao
->start_row
+ dao
->rows
- 1);
317 if (dao
->type
== RangeOutput
318 && sheet_range_splits_region (dao
->sheet
, &range
, NULL
,
319 GO_CMD_CONTEXT (dao
->wbc
), cmd
))
322 if (dao
->clear_outputrange
)
323 clear_flags
= CLEAR_VALUES
| CLEAR_RECALC_DEPS
;
324 if (!dao
->retain_format
)
325 clear_flags
|= CLEAR_FORMATS
;
326 if (!dao
->retain_comments
)
327 clear_flags
|= CLEAR_COMMENTS
;
329 sheet_clear_region (dao
->sheet
,
330 range
.start
.col
, range
.start
.row
,
331 range
.end
.col
, range
.end
.row
,
332 clear_flags
| CLEAR_NOCHECKARRAY
| CLEAR_MERGES
,
333 GO_CMD_CONTEXT (dao
->wbc
));
339 adjust_range (data_analysis_output_t
*dao
, GnmRange
*r
)
343 r
->start
.col
+= dao
->offset_col
+ dao
->start_col
;
344 r
->end
.col
+= dao
->offset_col
+ dao
->start_col
;
345 r
->start
.row
+= dao
->offset_row
+ dao
->start_row
;
346 r
->end
.row
+= dao
->offset_row
+ dao
->start_row
;
348 if (dao
->type
== RangeOutput
&& (dao
->cols
> 1 || dao
->rows
> 1)) {
349 if (r
->end
.col
>= dao
->start_col
+ dao
->cols
)
350 r
->end
.col
= dao
->start_col
+ dao
->cols
- 1;
351 if (r
->end
.row
>= dao
->start_row
+ dao
->rows
)
352 r
->end
.row
= dao
->start_row
+ dao
->rows
- 1;
355 range_ensure_sanity (r
, dao
->sheet
);
357 return ((r
->start
.col
<= r
->end
.col
) && (r
->start
.row
<= r
->end
.row
));
362 dao_cell_is_visible (data_analysis_output_t
*dao
, int col
, int row
)
364 col
+= dao
->offset_col
;
365 row
+= dao
->offset_row
;
367 if (dao
->type
== RangeOutput
&&
368 (dao
->cols
> 1 || dao
->rows
> 1) &&
369 (col
>= dao
->cols
|| row
>= dao
->rows
))
372 col
+= dao
->start_col
;
373 row
+= dao
->start_row
;
375 return (!(col
>= gnm_sheet_get_max_cols (dao
->sheet
) || row
>= gnm_sheet_get_max_rows (dao
->sheet
)));
380 * dao_set_cell_array_expr absorbs the reference for the expr.
384 dao_set_array_expr (data_analysis_output_t
*dao
,
385 int col
, int row
, int cols
, int rows
,
388 GnmExprTop
const *texpr
;
391 range_init (&r
, col
, row
, col
+ cols
- 1, row
+ rows
-1);
393 if (!adjust_range (dao
, &r
)) {
394 gnm_expr_free (expr
);
398 texpr
= gnm_expr_top_new (expr
);
399 gnm_cell_set_array_formula (dao
->sheet
,
400 r
.start
.col
, r
.start
.row
,
401 r
.end
.col
, r
.end
.row
,
405 * dao_set_cell_array_expr absorbs the reference for the expr.
409 dao_set_cell_array_expr (data_analysis_output_t
*dao
, int col
, int row
,
412 dao_set_array_expr (dao
, col
, row
, 1, 1, expr
);
416 * dao_set_cell_expr absorbs the reference for the expr.
421 dao_set_cell_expr (data_analysis_output_t
*dao
, int col
, int row
,
425 GnmExprTop
const *texpr
;
428 range_init (&r
, col
, row
, col
, row
);
430 if (!adjust_range (dao
, &r
)) {
431 gnm_expr_free (expr
);
435 cell
= sheet_cell_fetch (dao
->sheet
, r
.start
.col
, r
.start
.row
);
436 texpr
= gnm_expr_top_new (expr
);
437 gnm_cell_set_expr (cell
, texpr
);
438 gnm_expr_top_unref (texpr
);
443 * dao_set_cell_value:
449 * set cell to a value
451 * Note: the rows/cols specification for all dao_set_cell_...
452 * commands are relative to the location of the output
458 dao_set_cell_value (data_analysis_output_t
*dao
, int col
, int row
, GnmValue
*v
)
463 range_init (&r
, col
, row
, col
, row
);
465 if (!adjust_range (dao
, &r
)) {
470 cell
= sheet_cell_fetch (dao
->sheet
, r
.start
.col
, r
.start
.row
);
472 sheet_cell_set_value (cell
, v
);
482 * set cell to a string
487 dao_set_cell (data_analysis_output_t
*dao
, int col
, int row
, const char *text
)
490 /* FIXME: should we erase instead? */
491 dao_set_cell_value (dao
, col
, row
, value_new_empty ());
493 dao_set_cell_value (dao
, col
, row
, value_new_string (text
));
499 * dao_set_cell_printf:
506 * create format string and set cell.
510 dao_set_cell_printf (data_analysis_output_t
*dao
, int col
, int row
,
511 const char *fmt
, ...)
516 va_start (args
, fmt
);
517 buffer
= g_strdup_vprintf (fmt
, args
);
520 dao_set_cell_value (dao
, col
, row
, value_new_string (buffer
));
532 * set cell to a gnm_float
537 dao_set_cell_float (data_analysis_output_t
*dao
, int col
, int row
, gnm_float v
)
539 dao_set_cell_value (dao
, col
, row
, value_new_float (v
));
555 dao_set_cell_int (data_analysis_output_t
*dao
, int col
, int row
, int v
)
557 dao_set_cell_value (dao
, col
, row
, value_new_int (v
));
572 dao_set_cell_na (data_analysis_output_t
*dao
, int col
, int row
)
574 dao_set_cell_value (dao
, col
, row
, value_new_error_NA (NULL
));
578 * dao_set_cell_float_na:
585 * set cell to a gnm_float or NA as appropraite
590 dao_set_cell_float_na (data_analysis_output_t
*dao
, int col
, int row
,
591 gnm_float v
, gboolean is_valid
)
594 dao_set_cell_float (dao
, col
, row
, v
);
596 dao_set_cell_na (dao
, col
, row
);
601 * dao_set_cell_comment:
611 dao_set_cell_comment (data_analysis_output_t
*dao
, int col
, int row
,
614 char const *author
= NULL
;
617 range_init (&r
, col
, row
, col
, row
);
619 if (adjust_range (dao
, &r
))
620 cell_set_comment (dao
->sheet
, &r
.start
, author
, comment
, NULL
);
625 * dao_autofit_these_columns:
630 * Fits the specified columns to their content
633 dao_autofit_these_columns (data_analysis_output_t
*dao
, int from_col
, int to_col
)
637 if (!dao
->autofit_flag
)
640 range_init_cols (&r
, dao
->sheet
,
641 from_col
+ dao
->start_col
,
642 to_col
+ dao
->start_col
);
644 colrow_autofit (dao
->sheet
, &r
, TRUE
,
645 FALSE
, dao
->autofit_noshrink
, FALSE
,
650 * dao_autofit_columns:
653 * fits all columns to their content
656 dao_autofit_columns (data_analysis_output_t
*dao
)
658 dao_autofit_these_columns (dao
, 0, dao
->cols
- 1);
662 dao_autofit_these_rows (data_analysis_output_t
*dao
, int from_row
, int to_row
)
666 if (!dao
->autofit_flag
)
669 range_init_rows (&r
, dao
->sheet
,
670 from_row
+ dao
->start_row
,
671 to_row
+ dao
->start_row
);
673 colrow_autofit (dao
->sheet
, &r
, FALSE
,
674 FALSE
, dao
->autofit_noshrink
, FALSE
,
679 dao_autofit_rows (data_analysis_output_t
*dao
)
681 dao_autofit_these_rows (dao
, 0, dao
->rows
- 1);
692 * @style: (transfer full):
694 * Applies a partial style to the given region.
698 dao_set_style (data_analysis_output_t
*dao
, int col1
, int row1
,
699 int col2
, int row2
, GnmStyle
*mstyle
)
703 range_init (&r
, col1
, row1
, col2
, row2
);
705 if (!adjust_range (dao
, &r
)) {
706 gnm_style_unref (mstyle
);
710 sheet_style_apply_range (dao
->sheet
, &r
, mstyle
);
721 * sets the given cell range to bold
726 dao_set_bold (data_analysis_output_t
*dao
, int col1
, int row1
,
729 GnmStyle
*mstyle
= gnm_style_new ();
731 gnm_style_set_font_bold (mstyle
, TRUE
);
733 dao_set_style (dao
, col1
, row1
, col2
, row2
, mstyle
);
744 * sets the given cell range to italic
749 dao_set_italic (data_analysis_output_t
*dao
, int col1
, int row1
,
752 GnmStyle
*mstyle
= gnm_style_new ();
754 gnm_style_set_font_italic (mstyle
, TRUE
);
755 dao_set_style (dao
, col1
, row1
, col2
, row2
, mstyle
);
766 * set the given cell range to percent format
771 dao_set_percent (data_analysis_output_t
*dao
, int col1
, int row1
,
774 GnmStyle
*mstyle
= gnm_style_new ();
775 gnm_style_set_format (mstyle
, go_format_default_percentage ());
776 dao_set_style (dao
, col1
, row1
, col2
, row2
, mstyle
);
787 * set the given cell range to date format
792 dao_set_date (data_analysis_output_t
*dao
, int col1
, int row1
,
795 GnmStyle
*mstyle
= gnm_style_new ();
796 gnm_style_set_format (mstyle
, go_format_default_date ());
797 dao_set_style (dao
, col1
, row1
, col2
, row2
, mstyle
);
809 * set the given cell range to given format
814 dao_set_format (data_analysis_output_t
*dao
, int col1
, int row1
,
820 fmt
= go_format_new_from_XL (format
);
821 if (go_format_is_invalid (fmt
)) {
822 g_warning ("Ignoring invalid format [%s]", format
);
824 GnmStyle
*mstyle
= gnm_style_new ();
825 gnm_style_set_format (mstyle
, fmt
);
826 dao_set_style (dao
, col1
, row1
, col2
, row2
, mstyle
);
828 go_format_unref (fmt
);
840 * set the given cell range to given background and text colors
845 dao_set_colors (data_analysis_output_t
*dao
, int col1
, int row1
,
847 GnmColor
*fore
, GnmColor
*back
)
851 mstyle
= gnm_style_new ();
853 gnm_style_set_font_color (mstyle
, fore
);
855 gnm_style_set_back_color (mstyle
, back
);
856 gnm_style_set_pattern (mstyle
, 1);
858 dao_set_style (dao
, col1
, row1
, col2
, row2
, mstyle
);
869 * set the given horizontal and vertical alignment to a cell range
874 dao_set_align (data_analysis_output_t
*dao
, int col1
, int row1
,
876 GnmHAlign align_h
, GnmVAlign align_v
)
880 mstyle
= gnm_style_new ();
881 gnm_style_set_align_h (mstyle
, align_h
);
882 gnm_style_set_align_v (mstyle
, align_v
);
883 dao_set_style (dao
, col1
, row1
, col2
, row2
, mstyle
);
898 dao_set_border (data_analysis_output_t
*dao
, int col1
, int row1
,
900 GnmStyleElement elem
, GnmStyleBorderType border
,
902 GnmStyleBorderOrientation orientation
)
906 mstyle
= gnm_style_new ();
907 gnm_style_set_border (mstyle
, elem
,
908 gnm_style_border_fetch (border
,
911 dao_set_style (dao
, col1
, row1
, col2
, row2
, mstyle
);
917 * dao_get_colrow_state_list:
922 * Returns: (transfer full):
925 dao_get_colrow_state_list (data_analysis_output_t
*dao
, gboolean is_cols
)
929 case NewWorkbookOutput
:
933 return colrow_get_states
934 (dao
->sheet
, is_cols
, dao
->start_col
,
935 dao
->start_col
+ dao
->cols
- 1);
937 return colrow_get_states
938 (dao
->sheet
, is_cols
, dao
->start_row
,
939 dao
->start_row
+ dao
->rows
- 1);
946 * dao_set_colrow_state_list:
955 dao_set_colrow_state_list (data_analysis_output_t
*dao
, gboolean is_cols
,
956 ColRowStateList
*list
)
958 g_return_if_fail (list
);
960 if (dao
->type
== RangeOutput
)
961 colrow_set_states (dao
->sheet
, is_cols
,
962 is_cols
? dao
->start_col
: dao
->start_row
,
967 dao_append_date (GString
*buf
)
975 g_date_set_time_t (&date
, now
);
976 g_date_to_struct_tm (&date
, &tm_s
);
977 tm_s
.tm_sec
= now
% 60;
978 tm_s
.tm_min
= (now
/ 60) % 60;
979 tm_s
.tm_hour
= (now
/ 3600) % 24;
980 tmp
= asctime (&tm_s
);
981 g_string_append (buf
, tmp
);
987 * @toolname: name of the tool, like Solver or Risk simulation
991 * Writes the titles of a report.
995 dao_write_header (data_analysis_output_t
*dao
, const gchar
*toolname
,
996 const gchar
*title
, Sheet
*sheet
)
1001 buf
= g_string_new (NULL
);
1002 g_string_append_printf (buf
, "%s %s %s %s",
1003 _("Gnumeric "), toolname
, VERSION
, title
);
1004 dao_set_cell (dao
, 0, 0, buf
->str
);
1005 g_string_free (buf
, FALSE
);
1007 buf
= g_string_new (NULL
);
1008 uri
= go_doc_get_uri (GO_DOC (sheet
->workbook
));
1009 g_string_append_printf (buf
, "%s [%s]%s", _("Worksheet:"),
1011 sheet
->name_quoted
);
1012 dao_set_cell (dao
, 0, 1, buf
->str
);
1013 g_string_free (buf
, FALSE
);
1015 buf
= g_string_new (NULL
);
1016 g_string_append (buf
, _("Report Created: "));
1017 dao_append_date (buf
);
1018 dao_set_cell (dao
, 0, 2, buf
->str
);
1019 g_string_free (buf
, FALSE
);
1021 dao_set_bold (dao
, 0, 0, 0, 2);
1026 dao_find_name (Sheet
*sheet
, int col
, int row
)
1028 static char *str
= NULL
;
1029 const char *col_str
= "";
1030 const char *row_str
= "";
1033 for (col_n
= col
- 1; col_n
>= 0; col_n
--) {
1034 GnmCell
*cell
= sheet_cell_get (sheet
, col_n
, row
);
1035 if (cell
&& !VALUE_IS_NUMBER (cell
->value
)) {
1036 col_str
= value_peek_string (cell
->value
);
1041 for (row_n
= row
- 1; row_n
>= 0; row_n
--) {
1042 GnmCell
*cell
= sheet_cell_get (sheet
, col
, row_n
);
1043 if (cell
&& !VALUE_IS_NUMBER (cell
->value
)) {
1044 row_str
= value_peek_string (cell
->value
);
1049 if (*col_str
|| *row_str
) {
1050 str
= g_new (char, strlen (col_str
) + strlen (row_str
) + 2);
1053 sprintf (str
, "%s %s", col_str
, row_str
);
1055 sprintf (str
, "%s", row_str
);
1057 const char *tmp
= cell_coord_name (col
, row
);
1059 str
= g_new (char, strlen (tmp
) + 1);
1067 dao_put_formulas (data_analysis_output_t
*dao
)
1069 g_return_val_if_fail (dao
!= NULL
, FALSE
);
1070 return dao
->put_formulas
;
1074 cb_convert_to_value (GnmCellIter
const *iter
, G_GNUC_UNUSED gpointer user
)
1076 GnmCell
*cell
= iter
->cell
;
1077 if (!cell
|| !gnm_cell_has_expr (cell
))
1080 gnm_cell_eval (cell
);
1082 if (gnm_expr_top_is_array_elem (cell
->base
.texpr
, NULL
, NULL
))
1085 gnm_cell_convert_expr_to_value (cell
);
1091 dao_convert_to_values (data_analysis_output_t
*dao
)
1093 if (dao
->put_formulas
)
1096 sheet_foreach_cell_in_region (dao
->sheet
, CELL_ITER_IGNORE_BLANK
,
1097 dao
->start_col
, dao
->start_row
,
1098 dao
->start_col
+ dao
->cols
- 1,
1099 dao
->start_row
+ dao
->rows
- 1,
1100 cb_convert_to_value
,
1105 dao_redraw_respan (data_analysis_output_t
*dao
)
1109 range_init (&r
, dao
->start_col
, dao
->start_row
,
1110 dao
->start_col
+ dao
->cols
- 1,
1111 dao
->start_row
+ dao
->rows
- 1);
1112 sheet_range_calc_spans (dao
->sheet
, &r
,
1113 GNM_SPANCALC_RESIZE
| GNM_SPANCALC_RE_RENDER
);
1114 sheet_region_queue_recalc (dao
->sheet
, &r
);
1115 dao_convert_to_values (dao
);
1116 sheet_redraw_range (dao
->sheet
, &r
);
1120 static GnmExpr
const *
1121 dao_get_cellref_full (data_analysis_output_t
*dao
, int x
, int y
, Sheet
*sheet
)
1125 r
.col
= x
+ dao
->start_col
+ dao
->offset_col
;
1126 r
.col_relative
= FALSE
;
1127 r
.row
= y
+ dao
->start_row
+ dao
->offset_row
;
1128 r
.row_relative
= FALSE
;
1129 return gnm_expr_new_cellref (&r
);
1133 dao_get_cellref (data_analysis_output_t
*dao
, int x
, int y
)
1135 return dao_get_cellref_full (dao
, x
, y
, NULL
);
1138 static GnmExpr
const *
1139 dao_get_rangeref_full (data_analysis_output_t
*dao
, int ax
, int ay
, int bx
, int by
, Sheet
*sheet
)
1146 ar
.col
= ax
+ dao
->start_col
+ dao
->offset_col
;
1147 ar
.col_relative
= FALSE
;
1148 ar
.row
= ay
+ dao
->start_row
+ dao
->offset_row
;
1149 ar
.row_relative
= FALSE
;
1152 br
.col
= bx
+ dao
->start_col
+ dao
->offset_col
;
1153 br
.col_relative
= FALSE
;
1154 br
.row
= by
+ dao
->start_row
+ dao
->offset_row
;
1155 br
.row_relative
= FALSE
;
1157 v
= value_new_cellrange (&ar
, &br
, 0, 0);
1158 return gnm_expr_new_constant (v
);
1162 dao_get_rangeref (data_analysis_output_t
*dao
, int ax
, int ay
, int bx
, int by
)
1164 return dao_get_rangeref_full (dao
, ax
, ay
, bx
, by
, NULL
);
1168 dao_set_sheet_object (data_analysis_output_t
*dao
, int col
, int row
, SheetObject
* so
)
1170 SheetObjectAnchor anchor
;
1173 g_return_if_fail (so
!= NULL
);
1176 g_object_unref (so
);
1180 range_init (&anchor_r
, dao
->start_col
+ col
, dao
->start_row
+ row
,
1181 dao
->start_col
+ ((dao
->cols
< 5) ? dao
->cols
: 5),
1182 dao
->start_row
+ ((dao
->rows
< 20) ? dao
->rows
: 20));
1184 sheet_object_anchor_init (&anchor
, &anchor_r
, NULL
, GOD_ANCHOR_DIR_UNKNOWN
,
1185 GNM_SO_ANCHOR_TWO_CELLS
);
1186 sheet_object_set_anchor (so
, &anchor
);
1187 sheet_object_set_sheet (so
, dao
->sheet
);
1189 dao
->sos
= g_slist_prepend (dao
->sos
, so
);
1193 * dao_go_data_vector:
1200 * Returns: (transfer full):
1203 dao_go_data_vector (data_analysis_output_t
*dao
, int ax
, int ay
, int bx
, int by
)
1205 return gnm_go_data_vector_new_expr (dao
->sheet
, gnm_expr_top_new (dao_get_rangeref_full (dao
, ax
, ay
, bx
, by
, dao
->sheet
)));
1212 * Returns: (element-type GObject) (transfer full):
1215 dao_surrender_so (data_analysis_output_t
*dao
)
1217 GSList
*l
= dao
->sos
;
1224 dao_set_omit_so (data_analysis_output_t
*dao
, gboolean omit
)
1226 dao
->omit_so
= omit
;
1232 dao_set_merge (data_analysis_output_t
*dao
, int col1
, int row1
,
1237 range_init (&r
, col1
, row1
, col2
, row2
);
1238 if (adjust_range (dao
, &r
))
1239 gnm_sheet_merge_add (dao
->sheet
, &r
, TRUE
, NULL
);