6 * Jukka-Pekka Iivonen <jiivonen@hutcs.cs.hut.fi>
7 * Andreas J. Guelzow <aguelzow@taliesin.ca>
9 * (C) Copyright 2000, 2001 by Jukka-Pekka Iivonen <jiivonen@hutcs.cs.hut.fi>
10 * (C) Copyright 2001, 2002 by Andreas J. Guelzow <aguelzow@taliesin.ca>
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses/>.
26 #include <gnumeric-config.h>
27 #include <tools/dao.h>
35 #include <sheet-style.h>
37 #include <workbook-view.h>
38 #include <workbook-control.h>
39 #include <command-context.h>
40 #include <gnm-format.h>
41 #include <sheet-merge.h>
42 #include <sheet-object-cell-comment.h>
43 #include <style-color.h>
44 #include <style-border.h>
46 #include <goffice/goffice.h>
49 #include <glib/gi18n-lib.h>
52 #include <parse-util.h>
59 * Initialize dao to given type.
63 data_analysis_output_t
*
64 dao_init (data_analysis_output_t
*dao
,
65 data_analysis_output_type_t type
)
68 dao
= g_new (data_analysis_output_t
, 1);
69 dao
->use_gfree
= TRUE
;
71 dao
->use_gfree
= FALSE
;
78 dao
->cols
= 1; /* Fixed in dao_prepare_output */
81 dao
->autofit_flag
= TRUE
;
82 dao
->autofit_noshrink
= TRUE
;
83 dao
->clear_outputrange
= TRUE
;
84 dao
->retain_format
= FALSE
;
85 dao
->retain_comments
= FALSE
;
86 dao
->put_formulas
= FALSE
;
95 * dao_init_new_sheet: (skip)
99 data_analysis_output_t
*
100 dao_init_new_sheet (data_analysis_output_t
*dao
)
102 return dao_init (dao
, NewSheetOutput
);
105 void dao_free (data_analysis_output_t
*dao
)
107 g_slist_free_full (dao
->sos
, g_object_unref
);
115 * dao_load_from_value: (skip)
120 data_analysis_output_t
*
121 dao_load_from_value (data_analysis_output_t
*dao
,
122 GnmValue
*output_range
)
124 g_return_val_if_fail (output_range
!= NULL
, dao
);
125 g_return_val_if_fail (VALUE_IS_CELLRANGE (output_range
), dao
);
127 dao
->start_col
= output_range
->v_range
.cell
.a
.col
;
128 dao
->start_row
= output_range
->v_range
.cell
.a
.row
;
129 dao
->cols
= output_range
->v_range
.cell
.b
.col
130 - output_range
->v_range
.cell
.a
.col
+ 1;
131 dao
->rows
= output_range
->v_range
.cell
.b
.row
132 - output_range
->v_range
.cell
.a
.row
+ 1;
133 dao
->sheet
= output_range
->v_range
.cell
.a
.sheet
;
142 * Provides the name of the output range
143 * The caller has to dispose of the name
148 dao_range_name (data_analysis_output_t
*dao
)
151 range_init (&range
, dao
->start_col
, dao
->start_row
,
152 dao
->start_col
+ dao
->cols
- 1,
153 dao
->start_row
+ dao
->rows
- 1);
155 return undo_range_name (dao
->sheet
, &range
);
159 * dao_command_descriptor:
164 * Uses format to provide a string to be used as command descriptor for
170 dao_command_descriptor (data_analysis_output_t
*dao
, char const *format
,
173 char *rangename
= NULL
;
174 char **text
= result
;
176 g_return_val_if_fail (result
!= NULL
, NULL
);
181 *text
= g_strdup_printf (format
, _("New Sheet"));
183 case NewWorkbookOutput
:
184 *text
= g_strdup_printf (format
, _("New Workbook"));
188 rangename
= dao_range_name (dao
);
189 *text
= g_strdup_printf (format
, rangename
);
202 * shrinks the dao to the given cols/rows
203 * (or enlarges it if dao was a singleton)
208 dao_adjust (data_analysis_output_t
*dao
, gint cols
, gint rows
)
210 int max_rows
, max_cols
;
212 if (dao
->cols
== 1 && dao
->rows
== 1) {
219 dao
->cols
= MIN (cols
, dao
->cols
);
221 dao
->rows
= MIN (rows
, dao
->rows
);
225 max_rows
= gnm_sheet_get_max_rows (dao
->sheet
) - dao
->start_row
;
226 max_cols
= gnm_sheet_get_max_cols (dao
->sheet
) - dao
->start_col
;
228 /* In case of NewSheetOutput and NewWorkbookOutput */
229 /* this is called before we actually create the */
230 /* new sheet and/or workbook */
231 Sheet
*old_sheet
= wb_control_cur_sheet (dao
->wbc
);
232 max_rows
= gnm_sheet_get_max_rows (old_sheet
) - dao
->start_row
;
233 max_cols
= gnm_sheet_get_max_cols (old_sheet
) - dao
->start_col
;
236 if (dao
->cols
> max_cols
)
237 dao
->cols
= max_cols
;
238 if (dao
->rows
> max_rows
)
239 dao
->rows
= max_rows
;
243 * dao_prepare_output:
247 * prepares the output by creating a new sheet or workbook as appropriate
252 dao_prepare_output (WorkbookControl
*wbc
, data_analysis_output_t
*dao
,
260 if (dao
->type
== NewSheetOutput
) {
261 Sheet
*old_sheet
= dao
->wbc
262 ? wb_control_cur_sheet (dao
->wbc
)
264 Workbook
*wb
= old_sheet
->workbook
;
265 char *name_with_counter
= g_strdup_printf ("%s (1)", name
);
266 unique_name
= workbook_sheet_get_free_name
267 (wb
, name_with_counter
, FALSE
, TRUE
);
268 g_free (name_with_counter
);
269 dao
->rows
= gnm_sheet_get_max_rows (old_sheet
);
270 dao
->cols
= gnm_sheet_get_max_cols (old_sheet
);
271 dao
->sheet
= sheet_new (wb
, unique_name
, dao
->cols
, dao
->rows
);
272 g_free (unique_name
);
273 dao
->start_col
= dao
->start_row
= 0;
274 workbook_sheet_attach (wb
, dao
->sheet
);
275 } else if (dao
->type
== NewWorkbookOutput
) {
276 Sheet
*old_sheet
= wb_control_cur_sheet (dao
->wbc
);
277 Workbook
*wb
= workbook_new ();
278 dao
->rows
= gnm_sheet_get_max_rows (old_sheet
);
279 dao
->cols
= gnm_sheet_get_max_cols (old_sheet
);
280 dao
->sheet
= sheet_new (wb
, name
, dao
->cols
, dao
->rows
);
281 dao
->start_col
= dao
->start_row
= 0;
282 workbook_sheet_attach (wb
, dao
->sheet
);
283 dao
->wbc
= workbook_control_new_wrapper (dao
->wbc
, NULL
, wb
, NULL
);
287 wb_view_sheet_focus (wb_control_view (dao
->wbc
), dao
->sheet
);
289 if (dao
->rows
== 0 || (dao
->rows
== 1 && dao
->cols
== 1))
290 dao
->rows
= gnm_sheet_get_max_rows (dao
->sheet
) - dao
->start_row
;
291 if (dao
->cols
== 0 || (dao
->rows
== 1 && dao
->cols
== 1))
292 dao
->cols
= gnm_sheet_get_max_cols (dao
->sheet
) - dao
->start_col
;
302 * format's the output range according to the settings
307 dao_format_output (data_analysis_output_t
*dao
, char const *cmd
)
312 range_init (&range
, dao
->start_col
, dao
->start_row
,
313 dao
->start_col
+ dao
->cols
- 1,
314 dao
->start_row
+ dao
->rows
- 1);
316 if (dao
->type
== RangeOutput
317 && sheet_range_splits_region (dao
->sheet
, &range
, NULL
,
318 GO_CMD_CONTEXT (dao
->wbc
), cmd
))
321 if (dao
->clear_outputrange
)
322 clear_flags
= CLEAR_VALUES
| CLEAR_RECALC_DEPS
;
323 if (!dao
->retain_format
)
324 clear_flags
|= CLEAR_FORMATS
;
325 if (!dao
->retain_comments
)
326 clear_flags
|= CLEAR_COMMENTS
;
328 sheet_clear_region (dao
->sheet
,
329 range
.start
.col
, range
.start
.row
,
330 range
.end
.col
, range
.end
.row
,
331 clear_flags
| CLEAR_NOCHECKARRAY
| CLEAR_MERGES
,
332 GO_CMD_CONTEXT (dao
->wbc
));
338 adjust_range (data_analysis_output_t
*dao
, GnmRange
*r
)
342 r
->start
.col
+= dao
->offset_col
+ dao
->start_col
;
343 r
->end
.col
+= dao
->offset_col
+ dao
->start_col
;
344 r
->start
.row
+= dao
->offset_row
+ dao
->start_row
;
345 r
->end
.row
+= dao
->offset_row
+ dao
->start_row
;
347 if (dao
->type
== RangeOutput
&& (dao
->cols
> 1 || dao
->rows
> 1)) {
348 if (r
->end
.col
>= dao
->start_col
+ dao
->cols
)
349 r
->end
.col
= dao
->start_col
+ dao
->cols
- 1;
350 if (r
->end
.row
>= dao
->start_row
+ dao
->rows
)
351 r
->end
.row
= dao
->start_row
+ dao
->rows
- 1;
354 range_ensure_sanity (r
, dao
->sheet
);
356 return ((r
->start
.col
<= r
->end
.col
) && (r
->start
.row
<= r
->end
.row
));
361 dao_cell_is_visible (data_analysis_output_t
*dao
, int col
, int row
)
363 col
+= dao
->offset_col
;
364 row
+= dao
->offset_row
;
366 if (dao
->type
== RangeOutput
&&
367 (dao
->cols
> 1 || dao
->rows
> 1) &&
368 (col
>= dao
->cols
|| row
>= dao
->rows
))
371 col
+= dao
->start_col
;
372 row
+= dao
->start_row
;
374 return (!(col
>= gnm_sheet_get_max_cols (dao
->sheet
) || row
>= gnm_sheet_get_max_rows (dao
->sheet
)));
379 * dao_set_array_expr: (skip)
381 * @col: starting column
383 * @cols: number of columns
384 * @rows: number of rows
385 * @expr: (transfer full): expression to set
389 dao_set_array_expr (data_analysis_output_t
*dao
,
390 int col
, int row
, int cols
, int rows
,
393 GnmExprTop
const *texpr
;
396 range_init (&r
, col
, row
, col
+ cols
- 1, row
+ rows
-1);
398 if (!adjust_range (dao
, &r
)) {
399 gnm_expr_free (expr
);
403 texpr
= gnm_expr_top_new (expr
);
404 gnm_cell_set_array_formula (dao
->sheet
,
405 r
.start
.col
, r
.start
.row
,
406 r
.end
.col
, r
.end
.row
,
411 * dao_set_cell_array_expr: (skip)
415 * @expr: (transfer full): expression to set
417 * Sets a singleton array expression.
420 dao_set_cell_array_expr (data_analysis_output_t
*dao
, int col
, int row
,
423 dao_set_array_expr (dao
, col
, row
, 1, 1, expr
);
427 * dao_set_cell_expr: (skip)
431 * @expr: (transfer full): expression to set
433 * Sets a singleton array expression.
436 dao_set_cell_expr (data_analysis_output_t
*dao
, int col
, int row
,
440 GnmExprTop
const *texpr
;
443 range_init (&r
, col
, row
, col
, row
);
445 if (!adjust_range (dao
, &r
)) {
446 gnm_expr_free (expr
);
450 cell
= sheet_cell_fetch (dao
->sheet
, r
.start
.col
, r
.start
.row
);
451 texpr
= gnm_expr_top_new (expr
);
452 gnm_cell_set_expr (cell
, texpr
);
453 gnm_expr_top_unref (texpr
);
458 * dao_set_cell_value:
462 * @v: (transfer full):
464 * set cell to a value
466 * Note: the rows/cols specification for all dao_set_cell_...
467 * commands are relative to the location of the output
470 dao_set_cell_value (data_analysis_output_t
*dao
, int col
, int row
, GnmValue
*v
)
475 range_init (&r
, col
, row
, col
, row
);
477 if (!adjust_range (dao
, &r
)) {
482 cell
= sheet_cell_fetch (dao
->sheet
, r
.start
.col
, r
.start
.row
);
484 sheet_cell_set_value (cell
, v
);
494 * set cell to a string
499 dao_set_cell (data_analysis_output_t
*dao
, int col
, int row
, const char *text
)
502 /* FIXME: should we erase instead? */
503 dao_set_cell_value (dao
, col
, row
, value_new_empty ());
505 dao_set_cell_value (dao
, col
, row
, value_new_string (text
));
511 * dao_set_cell_printf:
518 * create format string and set cell.
522 dao_set_cell_printf (data_analysis_output_t
*dao
, int col
, int row
,
523 const char *fmt
, ...)
528 va_start (args
, fmt
);
529 buffer
= g_strdup_vprintf (fmt
, args
);
532 dao_set_cell_value (dao
, col
, row
, value_new_string (buffer
));
544 * set cell to a gnm_float
549 dao_set_cell_float (data_analysis_output_t
*dao
, int col
, int row
, gnm_float v
)
551 dao_set_cell_value (dao
, col
, row
, value_new_float (v
));
567 dao_set_cell_int (data_analysis_output_t
*dao
, int col
, int row
, int v
)
569 dao_set_cell_value (dao
, col
, row
, value_new_int (v
));
584 dao_set_cell_na (data_analysis_output_t
*dao
, int col
, int row
)
586 dao_set_cell_value (dao
, col
, row
, value_new_error_NA (NULL
));
590 * dao_set_cell_float_na:
597 * set cell to a gnm_float or NA as appropraite
602 dao_set_cell_float_na (data_analysis_output_t
*dao
, int col
, int row
,
603 gnm_float v
, gboolean is_valid
)
606 dao_set_cell_float (dao
, col
, row
, v
);
608 dao_set_cell_na (dao
, col
, row
);
613 * dao_set_cell_comment:
623 dao_set_cell_comment (data_analysis_output_t
*dao
, int col
, int row
,
626 char const *author
= NULL
;
629 range_init (&r
, col
, row
, col
, row
);
631 if (adjust_range (dao
, &r
))
632 cell_set_comment (dao
->sheet
, &r
.start
, author
, comment
, NULL
);
637 * dao_autofit_these_columns:
642 * Fits the specified columns to their content
645 dao_autofit_these_columns (data_analysis_output_t
*dao
, int from_col
, int to_col
)
649 if (!dao
->autofit_flag
)
652 range_init_cols (&r
, dao
->sheet
,
653 from_col
+ dao
->start_col
,
654 to_col
+ dao
->start_col
);
656 colrow_autofit (dao
->sheet
, &r
, TRUE
,
657 FALSE
, dao
->autofit_noshrink
, FALSE
,
662 * dao_autofit_columns:
665 * fits all columns to their content
668 dao_autofit_columns (data_analysis_output_t
*dao
)
670 dao_autofit_these_columns (dao
, 0, dao
->cols
- 1);
674 dao_autofit_these_rows (data_analysis_output_t
*dao
, int from_row
, int to_row
)
678 if (!dao
->autofit_flag
)
681 range_init_rows (&r
, dao
->sheet
,
682 from_row
+ dao
->start_row
,
683 to_row
+ dao
->start_row
);
685 colrow_autofit (dao
->sheet
, &r
, FALSE
,
686 FALSE
, dao
->autofit_noshrink
, FALSE
,
691 dao_autofit_rows (data_analysis_output_t
*dao
)
693 dao_autofit_these_rows (dao
, 0, dao
->rows
- 1);
704 * @style: (transfer full):
706 * Applies a partial style to the given region.
710 dao_set_style (data_analysis_output_t
*dao
, int col1
, int row1
,
711 int col2
, int row2
, GnmStyle
*mstyle
)
715 range_init (&r
, col1
, row1
, col2
, row2
);
717 if (!adjust_range (dao
, &r
)) {
718 gnm_style_unref (mstyle
);
722 sheet_style_apply_range (dao
->sheet
, &r
, mstyle
);
733 * sets the given cell range to bold
738 dao_set_bold (data_analysis_output_t
*dao
, int col1
, int row1
,
741 GnmStyle
*mstyle
= gnm_style_new ();
743 gnm_style_set_font_bold (mstyle
, TRUE
);
745 dao_set_style (dao
, col1
, row1
, col2
, row2
, mstyle
);
756 * sets the given cell range to italic
761 dao_set_italic (data_analysis_output_t
*dao
, int col1
, int row1
,
764 GnmStyle
*mstyle
= gnm_style_new ();
766 gnm_style_set_font_italic (mstyle
, TRUE
);
767 dao_set_style (dao
, col1
, row1
, col2
, row2
, mstyle
);
778 * set the given cell range to percent format
783 dao_set_percent (data_analysis_output_t
*dao
, int col1
, int row1
,
786 GnmStyle
*mstyle
= gnm_style_new ();
787 gnm_style_set_format (mstyle
, go_format_default_percentage ());
788 dao_set_style (dao
, col1
, row1
, col2
, row2
, mstyle
);
799 * set the given cell range to date format
804 dao_set_date (data_analysis_output_t
*dao
, int col1
, int row1
,
807 GnmStyle
*mstyle
= gnm_style_new ();
808 gnm_style_set_format (mstyle
, go_format_default_date ());
809 dao_set_style (dao
, col1
, row1
, col2
, row2
, mstyle
);
821 * set the given cell range to given format
826 dao_set_format (data_analysis_output_t
*dao
, int col1
, int row1
,
832 fmt
= go_format_new_from_XL (format
);
833 if (go_format_is_invalid (fmt
)) {
834 g_warning ("Ignoring invalid format [%s]", format
);
836 GnmStyle
*mstyle
= gnm_style_new ();
837 gnm_style_set_format (mstyle
, fmt
);
838 dao_set_style (dao
, col1
, row1
, col2
, row2
, mstyle
);
840 go_format_unref (fmt
);
852 * set the given cell range to given background and text colors
857 dao_set_colors (data_analysis_output_t
*dao
, int col1
, int row1
,
859 GnmColor
*fore
, GnmColor
*back
)
863 mstyle
= gnm_style_new ();
865 gnm_style_set_font_color (mstyle
, fore
);
867 gnm_style_set_back_color (mstyle
, back
);
868 gnm_style_set_pattern (mstyle
, 1);
870 dao_set_style (dao
, col1
, row1
, col2
, row2
, mstyle
);
881 * set the given horizontal and vertical alignment to a cell range
886 dao_set_align (data_analysis_output_t
*dao
, int col1
, int row1
,
888 GnmHAlign align_h
, GnmVAlign align_v
)
892 mstyle
= gnm_style_new ();
893 gnm_style_set_align_h (mstyle
, align_h
);
894 gnm_style_set_align_v (mstyle
, align_v
);
895 dao_set_style (dao
, col1
, row1
, col2
, row2
, mstyle
);
910 dao_set_border (data_analysis_output_t
*dao
, int col1
, int row1
,
912 GnmStyleElement elem
, GnmStyleBorderType border
,
914 GnmStyleBorderOrientation orientation
)
918 mstyle
= gnm_style_new ();
919 gnm_style_set_border (mstyle
, elem
,
920 gnm_style_border_fetch (border
,
923 dao_set_style (dao
, col1
, row1
, col2
, row2
, mstyle
);
929 * dao_get_colrow_state_list:
931 * @is_cols: %TRUE for columns, %FALSE for rows.
934 * Returns: (transfer full):
937 dao_get_colrow_state_list (data_analysis_output_t
*dao
, gboolean is_cols
)
941 case NewWorkbookOutput
:
945 return colrow_get_states
946 (dao
->sheet
, is_cols
, dao
->start_col
,
947 dao
->start_col
+ dao
->cols
- 1);
949 return colrow_get_states
950 (dao
->sheet
, is_cols
, dao
->start_row
,
951 dao
->start_row
+ dao
->rows
- 1);
958 * dao_set_colrow_state_list:
960 * @is_cols: %TRUE for columns, %FALSE for rows.
965 dao_set_colrow_state_list (data_analysis_output_t
*dao
, gboolean is_cols
,
966 ColRowStateList
*list
)
968 g_return_if_fail (list
);
970 if (dao
->type
== RangeOutput
)
971 colrow_set_states (dao
->sheet
, is_cols
,
972 is_cols
? dao
->start_col
: dao
->start_row
,
977 dao_append_date (GString
*buf
)
985 g_date_set_time_t (&date
, now
);
986 g_date_to_struct_tm (&date
, &tm_s
);
987 tm_s
.tm_sec
= now
% 60;
988 tm_s
.tm_min
= (now
/ 60) % 60;
989 tm_s
.tm_hour
= (now
/ 3600) % 24;
990 tmp
= asctime (&tm_s
);
991 g_string_append (buf
, tmp
);
997 * @toolname: name of the tool, like Solver or Risk simulation
1001 * Writes the titles of a report.
1005 dao_write_header (data_analysis_output_t
*dao
, const gchar
*toolname
,
1006 const gchar
*title
, Sheet
*sheet
)
1011 buf
= g_string_new (NULL
);
1012 g_string_append_printf (buf
, "%s %s %s %s",
1013 _("Gnumeric "), toolname
, VERSION
, title
);
1014 dao_set_cell (dao
, 0, 0, buf
->str
);
1015 g_string_free (buf
, FALSE
);
1017 buf
= g_string_new (NULL
);
1018 uri
= go_doc_get_uri (GO_DOC (sheet
->workbook
));
1019 g_string_append_printf (buf
, "%s [%s]%s", _("Worksheet:"),
1021 sheet
->name_quoted
);
1022 dao_set_cell (dao
, 0, 1, buf
->str
);
1023 g_string_free (buf
, FALSE
);
1025 buf
= g_string_new (NULL
);
1026 g_string_append (buf
, _("Report Created: "));
1027 dao_append_date (buf
);
1028 dao_set_cell (dao
, 0, 2, buf
->str
);
1029 g_string_free (buf
, FALSE
);
1031 dao_set_bold (dao
, 0, 0, 0, 2);
1036 dao_find_name (Sheet
*sheet
, int col
, int row
)
1038 static char *str
= NULL
;
1039 const char *col_str
= "";
1040 const char *row_str
= "";
1043 for (col_n
= col
- 1; col_n
>= 0; col_n
--) {
1044 GnmCell
*cell
= sheet_cell_get (sheet
, col_n
, row
);
1045 if (cell
&& !VALUE_IS_NUMBER (cell
->value
)) {
1046 col_str
= value_peek_string (cell
->value
);
1051 for (row_n
= row
- 1; row_n
>= 0; row_n
--) {
1052 GnmCell
*cell
= sheet_cell_get (sheet
, col
, row_n
);
1053 if (cell
&& !VALUE_IS_NUMBER (cell
->value
)) {
1054 row_str
= value_peek_string (cell
->value
);
1059 if (*col_str
|| *row_str
) {
1060 str
= g_new (char, strlen (col_str
) + strlen (row_str
) + 2);
1063 sprintf (str
, "%s %s", col_str
, row_str
);
1065 sprintf (str
, "%s", row_str
);
1067 const char *tmp
= cell_coord_name (col
, row
);
1069 str
= g_new (char, strlen (tmp
) + 1);
1077 dao_put_formulas (data_analysis_output_t
*dao
)
1079 g_return_val_if_fail (dao
!= NULL
, FALSE
);
1080 return dao
->put_formulas
;
1084 cb_convert_to_value (GnmCellIter
const *iter
, G_GNUC_UNUSED gpointer user
)
1086 GnmCell
*cell
= iter
->cell
;
1087 if (!cell
|| !gnm_cell_has_expr (cell
))
1090 gnm_cell_eval (cell
);
1092 if (gnm_expr_top_is_array_elem (cell
->base
.texpr
, NULL
, NULL
))
1095 gnm_cell_convert_expr_to_value (cell
);
1101 dao_convert_to_values (data_analysis_output_t
*dao
)
1103 if (dao
->put_formulas
)
1106 sheet_foreach_cell_in_region (dao
->sheet
, CELL_ITER_IGNORE_BLANK
,
1107 dao
->start_col
, dao
->start_row
,
1108 dao
->start_col
+ dao
->cols
- 1,
1109 dao
->start_row
+ dao
->rows
- 1,
1110 cb_convert_to_value
,
1115 dao_redraw_respan (data_analysis_output_t
*dao
)
1119 range_init (&r
, dao
->start_col
, dao
->start_row
,
1120 dao
->start_col
+ dao
->cols
- 1,
1121 dao
->start_row
+ dao
->rows
- 1);
1122 sheet_range_calc_spans (dao
->sheet
, &r
,
1123 GNM_SPANCALC_RESIZE
| GNM_SPANCALC_RE_RENDER
);
1124 sheet_region_queue_recalc (dao
->sheet
, &r
);
1125 dao_convert_to_values (dao
);
1126 sheet_redraw_range (dao
->sheet
, &r
);
1130 static GnmExpr
const *
1131 dao_get_cellref_full (data_analysis_output_t
*dao
, int x
, int y
, Sheet
*sheet
)
1135 r
.col
= x
+ dao
->start_col
+ dao
->offset_col
;
1136 r
.col_relative
= FALSE
;
1137 r
.row
= y
+ dao
->start_row
+ dao
->offset_row
;
1138 r
.row_relative
= FALSE
;
1139 return gnm_expr_new_cellref (&r
);
1143 dao_get_cellref (data_analysis_output_t
*dao
, int x
, int y
)
1145 return dao_get_cellref_full (dao
, x
, y
, NULL
);
1148 static GnmExpr
const *
1149 dao_get_rangeref_full (data_analysis_output_t
*dao
, int ax
, int ay
, int bx
, int by
, Sheet
*sheet
)
1156 ar
.col
= ax
+ dao
->start_col
+ dao
->offset_col
;
1157 ar
.col_relative
= FALSE
;
1158 ar
.row
= ay
+ dao
->start_row
+ dao
->offset_row
;
1159 ar
.row_relative
= FALSE
;
1162 br
.col
= bx
+ dao
->start_col
+ dao
->offset_col
;
1163 br
.col_relative
= FALSE
;
1164 br
.row
= by
+ dao
->start_row
+ dao
->offset_row
;
1165 br
.row_relative
= FALSE
;
1167 v
= value_new_cellrange (&ar
, &br
, 0, 0);
1168 return gnm_expr_new_constant (v
);
1172 dao_get_rangeref (data_analysis_output_t
*dao
, int ax
, int ay
, int bx
, int by
)
1174 return dao_get_rangeref_full (dao
, ax
, ay
, bx
, by
, NULL
);
1178 dao_set_sheet_object (data_analysis_output_t
*dao
, int col
, int row
, SheetObject
* so
)
1180 SheetObjectAnchor anchor
;
1183 g_return_if_fail (so
!= NULL
);
1186 g_object_unref (so
);
1190 range_init (&anchor_r
, dao
->start_col
+ col
, dao
->start_row
+ row
,
1191 dao
->start_col
+ ((dao
->cols
< 5) ? dao
->cols
: 5),
1192 dao
->start_row
+ ((dao
->rows
< 20) ? dao
->rows
: 20));
1194 sheet_object_anchor_init (&anchor
, &anchor_r
, NULL
, GOD_ANCHOR_DIR_UNKNOWN
,
1195 GNM_SO_ANCHOR_TWO_CELLS
);
1196 sheet_object_set_anchor (so
, &anchor
);
1197 sheet_object_set_sheet (so
, dao
->sheet
);
1199 dao
->sos
= g_slist_prepend (dao
->sos
, so
);
1203 * dao_go_data_vector:
1210 * Returns: (transfer full):
1213 dao_go_data_vector (data_analysis_output_t
*dao
, int ax
, int ay
, int bx
, int by
)
1215 return gnm_go_data_vector_new_expr (dao
->sheet
, gnm_expr_top_new (dao_get_rangeref_full (dao
, ax
, ay
, bx
, by
, dao
->sheet
)));
1222 * Returns: (element-type GObject) (transfer full):
1225 dao_surrender_so (data_analysis_output_t
*dao
)
1227 GSList
*l
= dao
->sos
;
1234 dao_set_omit_so (data_analysis_output_t
*dao
, gboolean omit
)
1236 dao
->omit_so
= omit
;
1242 dao_set_merge (data_analysis_output_t
*dao
, int col1
, int row1
,
1247 range_init (&r
, col1
, row1
, col2
, row2
);
1248 if (adjust_range (dao
, &r
))
1249 gnm_sheet_merge_add (dao
->sheet
, &r
, TRUE
, NULL
);