1.12.39
[gnumeric.git] / src / wbc-gtk-actions.c
blob8f6525d5c5a16718ee42995446e78e07a81c6602
1 /* vim: set sw=8: -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
3 /*
4 * wbcg-actions.c: The callbacks and tables for all the menus and stock toolbars
6 * Copyright (C) 2003-2006 Jody Goldberg (jody@gnome.org)
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) version 3.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
21 * USA
24 #include <gnumeric-config.h>
25 #include "gnumeric.h"
27 #include "libgnumeric.h"
28 #include "application.h"
29 #include "gnm-commands-slicer.h"
30 #include "commands.h"
31 #include "clipboard.h"
32 #include "selection.h"
33 #include "search.h"
34 #include "ranges.h"
35 #include "cell.h"
36 #include "stf.h"
37 #include "value.h"
38 #include "gnm-format.h"
39 #include "sheet.h"
40 #include "sort.h"
41 #include "sheet-merge.h"
42 #include "sheet-filter.h"
43 #include "sheet-utils.h"
44 #include "sheet-style.h"
45 #include "style-border.h"
46 #include "style-color.h"
47 #include "tools/filter.h"
48 #include "sheet-control-gui-priv.h"
49 #include "sheet-view.h"
50 #include "cmd-edit.h"
51 #include "workbook.h"
52 #include "workbook-view.h"
53 #include "wbc-gtk-impl.h"
54 #include "workbook-cmd-format.h"
55 #include "dialogs/dialogs.h"
56 #include "sheet-object-image.h"
57 #include "sheet-object-widget.h"
58 #include "gnm-so-filled.h"
59 #include "gnm-so-line.h"
60 #include "sheet-object-graph.h"
61 #include "sheet-object-component.h"
62 #include "gui-util.h"
63 #include "gui-file.h"
64 #include "gnumeric-conf.h"
65 #include "expr.h"
66 #include "print.h"
67 #include "print-info.h"
68 #include "gnm-pane-impl.h"
69 #include "gutils.h"
70 #include "widgets/gnm-fontbutton.h"
72 #include <goffice/goffice.h>
73 #include <goffice/component/goffice-component.h>
75 #include <gtk/gtk.h>
76 #include <glib/gi18n-lib.h>
77 #include <gsf/gsf-input.h>
78 #include <string.h>
79 #include <glib/gstdio.h>
80 #include <errno.h>
82 static gboolean
83 cb_cleanup_sendto (gpointer path)
85 char *dir = g_path_get_dirname (path);
87 g_unlink (path);
88 g_free (path); /* the attachment */
90 g_rmdir (dir);
91 g_free (dir); /* the tempdir */
93 return FALSE;
97 static GNM_ACTION_DEF (cb_file_new)
99 GdkScreen *screen = gtk_window_get_screen (wbcg_toplevel (wbcg));
100 Workbook *wb = workbook_new_with_sheets
101 (gnm_conf_get_core_workbook_n_sheet ());
102 WBCGtk *new_wbcg = wbc_gtk_new (NULL, wb, screen, NULL);
103 wbcg_copy_toolbar_visibility (new_wbcg, wbcg);
106 static GNM_ACTION_DEF (cb_file_open) { gui_file_open (wbcg, GNM_FILE_OPEN_STYLE_OPEN, NULL); }
107 static GNM_ACTION_DEF (cb_file_save) { gui_file_save (wbcg, wb_control_view (GNM_WBC (wbcg))); }
108 static GNM_ACTION_DEF (cb_file_save_as) { gui_file_save_as
109 (wbcg, wb_control_view (GNM_WBC (wbcg)),
110 GNM_FILE_SAVE_AS_STYLE_SAVE, NULL); }
112 static GNM_ACTION_DEF (cb_file_sendto) {
113 WorkbookControl *wbc = GNM_WBC (wbcg);
114 WorkbookView *wbv = wb_control_view (wbc);
115 GOCmdContext *gcc = GO_CMD_CONTEXT (wbcg);
116 gboolean problem = FALSE;
117 GOIOContext *io_context;
118 Workbook *wb;
119 GOFileSaver *fs;
121 wb = wb_control_get_workbook (wbc);
122 g_object_ref (wb);
123 fs = workbook_get_file_saver (wb);
124 if (fs == NULL)
125 fs = go_file_saver_get_default ();
127 io_context = go_io_context_new (gcc);
128 if (fs != NULL) {
129 char *template, *full_name, *uri;
130 char *basename = g_path_get_basename (go_doc_get_uri (GO_DOC (wb)));
132 template = g_build_filename (g_get_tmp_dir (),
133 ".gnm-sendto-XXXXXX", NULL);
134 problem = (g_mkdtemp_full (template, 0600) == NULL);
136 if (problem) {
137 g_free (template);
138 goto out;
141 full_name = g_build_filename (template, basename, NULL);
142 g_free (basename);
143 uri = go_filename_to_uri (full_name);
145 wb_view_save_to_uri (wbv, fs, uri, io_context);
147 if (go_io_error_occurred (io_context) ||
148 go_io_warning_occurred (io_context))
149 go_io_error_display (io_context);
151 if (go_io_error_occurred (io_context)) {
152 problem = TRUE;
153 } else {
154 /* mutt does not handle urls with no destination
155 * so pick something to arbitrary */
156 GError *err;
157 GdkScreen *screen = gtk_window_get_screen (wbcg_toplevel (wbcg));
158 char *url, *tmp = go_url_encode (full_name, 0);
159 url = g_strdup_printf ("mailto:someone?attach=%s", tmp);
160 g_free (tmp);
162 err = go_gtk_url_show (url, screen);
164 if (err != NULL) {
165 go_cmd_context_error (GO_CMD_CONTEXT (io_context), err);
166 g_error_free (err);
167 go_io_error_display (io_context);
168 problem = TRUE;
171 g_free (template);
172 g_free (uri);
174 if (problem) {
175 cb_cleanup_sendto (full_name);
176 } else {
178 * We wait a while before we clean up to ensure the file is
179 * loaded by the mailer.
181 g_timeout_add (1000 * 10, cb_cleanup_sendto, full_name);
183 } else {
184 go_cmd_context_error_export (GO_CMD_CONTEXT (io_context),
185 _("Default file saver is not available."));
186 go_io_error_display (io_context);
187 problem = TRUE;
190 out:
191 g_object_unref (io_context);
192 g_object_unref (wb);
194 /* What do we do with "problem"? */
197 static GNM_ACTION_DEF (cb_file_page_setup)
199 dialog_printer_setup (wbcg, wbcg_cur_sheet (wbcg));
202 static GNM_ACTION_DEF (cb_file_print_area_set)
204 Sheet *sheet = wbcg_cur_sheet (wbcg);
205 SheetView *sv = sheet_get_view (sheet, wb_control_view (GNM_WBC (wbcg)));
206 GnmParsePos pp;
207 char *message;
208 char * selection;
209 GnmRange const *r = selection_first_range (sv,
210 GO_CMD_CONTEXT (wbcg), _("Set Print Area"));
211 if (r != NULL) {
212 parse_pos_init_sheet (&pp, sheet);
213 selection = undo_range_name (sheet, r);
214 message = g_strdup_printf (_("Set Print Area to %s"), selection);
215 cmd_define_name (GNM_WBC (wbcg), "Print_Area", &pp,
216 gnm_expr_top_new_constant
217 (value_new_cellrange_r (NULL, r)),
218 message);
219 g_free (selection);
220 g_free (message);
224 static GNM_ACTION_DEF (cb_file_print_area_clear)
226 GnmParsePos pp;
227 Sheet *sheet = wbcg_cur_sheet (wbcg);
229 parse_pos_init_sheet (&pp, sheet);
230 cmd_define_name (GNM_WBC (wbcg), "Print_Area", &pp,
231 gnm_expr_top_new_constant
232 (value_new_error_REF (NULL)),
233 _("Clear Print Area"));
236 static GNM_ACTION_DEF (cb_file_print_area_show)
238 Sheet *sheet = wbcg_cur_sheet (wbcg);
239 GnmRange *r = sheet_get_nominal_printarea (sheet);
241 if (r != NULL) {
242 SheetView *sv = sheet_get_view (sheet,
243 wb_control_view (GNM_WBC (wbcg)));
244 wb_control_sheet_focus (GNM_WBC (wbcg), sheet);
245 sv_selection_reset (sv);
246 sv_selection_add_range (sv, r);
247 sv_make_cell_visible (sv, r->start.col, r->start.row, FALSE);
248 g_free (r);
252 static GNM_ACTION_DEF (cb_file_print_area_toggle_col)
254 cmd_page_break_toggle (GNM_WBC (wbcg),
255 wbcg_cur_sheet (wbcg),
256 TRUE);
258 static GNM_ACTION_DEF (cb_file_print_area_toggle_row)
260 cmd_page_break_toggle (GNM_WBC (wbcg),
261 wbcg_cur_sheet (wbcg),
262 FALSE);
265 static GNM_ACTION_DEF (cb_file_print_area_clear_pagebreaks)
267 cmd_page_breaks_clear (GNM_WBC (wbcg), wbcg_cur_sheet (wbcg));
270 static GNM_ACTION_DEF (cb_file_print)
272 gnm_print_sheet (GNM_WBC (wbcg),
273 wbcg_cur_sheet (wbcg), FALSE, GNM_PRINT_SAVED_INFO, NULL);
276 static GNM_ACTION_DEF (cb_file_print_preview)
278 gnm_print_sheet (GNM_WBC (wbcg),
279 wbcg_cur_sheet (wbcg), TRUE, GNM_PRINT_ACTIVE_SHEET, NULL);
282 static GNM_ACTION_DEF (cb_doc_meta_data) { dialog_doc_metadata_new (wbcg, 0); }
283 static GNM_ACTION_DEF (cb_file_preferences) { dialog_preferences (wbcg, NULL); }
284 static GNM_ACTION_DEF (cb_file_history_full) { dialog_recent_used (wbcg); }
285 static GNM_ACTION_DEF (cb_file_close) { wbc_gtk_close (wbcg); }
287 static GNM_ACTION_DEF (cb_file_quit)
289 /* If we are still loading initial files, short circuit */
290 if (!initial_workbook_open_complete) {
291 initial_workbook_open_complete = TRUE;
292 return;
295 /* If we were editing when the quit request came in abort the edit. */
296 wbcg_edit_finish (wbcg, WBC_EDIT_REJECT, NULL);
298 dialog_quit (wbcg);
301 /****************************************************************************/
303 static GNM_ACTION_DEF (cb_edit_clear_all)
305 cmd_selection_clear (GNM_WBC (wbcg),
306 CLEAR_VALUES | CLEAR_FORMATS | CLEAR_OBJECTS | CLEAR_COMMENTS);
309 static GNM_ACTION_DEF (cb_edit_clear_formats)
310 { cmd_selection_clear (GNM_WBC (wbcg), CLEAR_FORMATS); }
311 static GNM_ACTION_DEF (cb_edit_clear_comments)
312 { cmd_selection_clear (GNM_WBC (wbcg), CLEAR_COMMENTS); }
313 static GNM_ACTION_DEF (cb_edit_clear_content)
314 { cmd_selection_clear (GNM_WBC (wbcg), CLEAR_VALUES); }
315 static GNM_ACTION_DEF (cb_edit_clear_all_filtered)
317 cmd_selection_clear (GNM_WBC (wbcg),
318 CLEAR_VALUES | CLEAR_FORMATS | CLEAR_OBJECTS | CLEAR_COMMENTS | CLEAR_FILTERED_ONLY);
321 static GNM_ACTION_DEF (cb_edit_clear_formats_filtered)
322 { cmd_selection_clear (GNM_WBC (wbcg), CLEAR_FORMATS | CLEAR_FILTERED_ONLY); }
323 static GNM_ACTION_DEF (cb_edit_clear_comments_filtered)
324 { cmd_selection_clear (GNM_WBC (wbcg), CLEAR_COMMENTS | CLEAR_FILTERED_ONLY); }
325 static GNM_ACTION_DEF (cb_edit_clear_content_filtered)
326 { cmd_selection_clear (GNM_WBC (wbcg), CLEAR_VALUES | CLEAR_FILTERED_ONLY); }
328 static GNM_ACTION_DEF (cb_edit_delete_rows)
330 WorkbookControl *wbc = GNM_WBC (wbcg);
331 SheetView *sv = wb_control_cur_sheet_view (wbc);
332 Sheet *sheet = wb_control_cur_sheet (wbc);
333 GnmRange const *sel;
334 int rows;
336 if (!(sel = selection_first_range (sv, GO_CMD_CONTEXT (wbc), _("Delete"))))
337 return;
338 rows = range_height (sel);
340 cmd_delete_rows (wbc, sheet, sel->start.row, rows);
342 static GNM_ACTION_DEF (cb_edit_delete_columns)
344 WorkbookControl *wbc = GNM_WBC (wbcg);
345 SheetView *sv = wb_control_cur_sheet_view (wbc);
346 Sheet *sheet = wb_control_cur_sheet (wbc);
347 GnmRange const *sel;
348 int cols;
350 if (!(sel = selection_first_range (sv, GO_CMD_CONTEXT (wbc), _("Delete"))))
351 return;
352 cols = range_width (sel);
354 cmd_delete_cols (wbc, sheet, sel->start.col, cols);
357 static GNM_ACTION_DEF (cb_edit_delete_cells)
359 dialog_delete_cells (wbcg);
361 static GNM_ACTION_DEF (cb_edit_delete_links)
363 SheetControlGUI *scg = wbcg_cur_scg (wbcg);
364 GnmStyle *style = gnm_style_new ();
365 GSList *l;
366 int n_links = 0;
367 gchar const *format;
368 gchar *name;
369 WorkbookControl *wbc = GNM_WBC (wbcg);
370 Sheet *sheet = wb_control_cur_sheet (wbc);
372 for (l = scg_view (scg)->selections; l != NULL; l = l->next) {
373 GnmRange const *r = l->data;
374 GnmStyleList *styles;
376 styles = sheet_style_collect_hlinks (sheet, r);
377 n_links += g_slist_length (styles);
378 style_list_free (styles);
380 format = ngettext ("Remove %d Link", "Remove %d Links", n_links);
381 name = g_strdup_printf (format, n_links);
382 gnm_style_set_hlink (style, NULL);
383 cmd_selection_format (wbc, style, NULL, name);
384 g_free (name);
387 static GNM_ACTION_DEF (cb_edit_select_all)
389 scg_select_all (wbcg_cur_scg (wbcg));
391 static GNM_ACTION_DEF (cb_edit_select_row)
393 sv_select_cur_row (wb_control_cur_sheet_view (GNM_WBC (wbcg)));
395 static GNM_ACTION_DEF (cb_edit_select_col)
397 sv_select_cur_col (wb_control_cur_sheet_view (GNM_WBC (wbcg)));
399 static GNM_ACTION_DEF (cb_edit_select_array)
401 sv_select_cur_array (wb_control_cur_sheet_view (GNM_WBC (wbcg)));
403 static GNM_ACTION_DEF (cb_edit_select_depends)
405 sv_select_cur_depends (wb_control_cur_sheet_view (GNM_WBC (wbcg)));
407 static GNM_ACTION_DEF (cb_edit_select_inputs)
409 sv_select_cur_inputs (wb_control_cur_sheet_view (GNM_WBC (wbcg)));
411 static GNM_ACTION_DEF (cb_edit_select_object)
413 scg_object_select_next (wbcg_cur_scg (wbcg), FALSE);
416 static GNM_ACTION_DEF (cb_edit_cut)
418 if (!wbcg_is_editing (wbcg)) {
419 SheetControlGUI *scg = wbcg_cur_scg (wbcg);
420 WorkbookControl *wbc = GNM_WBC (wbcg);
421 SheetView *sv = wb_control_cur_sheet_view (wbc);
422 if (scg != NULL && scg->selected_objects != NULL)
423 gnm_app_clipboard_cut_copy_obj (wbc, TRUE, sv,
424 go_hash_keys (scg->selected_objects));
425 else
426 sv_selection_cut (sv, wbc);
427 } else
428 gtk_editable_cut_clipboard (GTK_EDITABLE (wbcg_get_entry (wbcg)));
431 static GNM_ACTION_DEF (cb_edit_copy)
433 if (!wbcg_is_editing (wbcg)) {
434 SheetControlGUI *scg = wbcg_cur_scg (wbcg);
435 WorkbookControl *wbc = GNM_WBC (wbcg);
436 SheetView *sv = wb_control_cur_sheet_view (wbc);
437 if (scg != NULL && scg->selected_objects != NULL)
438 gnm_app_clipboard_cut_copy_obj (wbc, FALSE, sv,
439 go_hash_keys (scg->selected_objects));
440 else
441 sv_selection_copy (sv, wbc);
442 } else
443 gtk_editable_copy_clipboard (GTK_EDITABLE (wbcg_get_entry (wbcg)));
446 static GNM_ACTION_DEF (cb_edit_paste)
448 if (!wbcg_is_editing (wbcg)) {
449 WorkbookControl *wbc = GNM_WBC (wbcg);
450 SheetView *sv = wb_control_cur_sheet_view (wbc);
451 cmd_paste_to_selection (wbc, sv, PASTE_DEFAULT);
452 } else
453 gtk_editable_paste_clipboard (GTK_EDITABLE (wbcg_get_entry (wbcg)));
456 static GNM_ACTION_DEF (cb_edit_paste_special)
458 dialog_paste_special (wbcg);
461 static GNM_ACTION_DEF (cb_sheet_remove)
463 SheetControlGUI *scg = wbcg_cur_scg (wbcg);
464 if (scg)
465 scg_delete_sheet_if_possible (scg);
468 static void
469 common_cell_goto (WBCGtk *wbcg, Sheet *sheet, GnmCellPos const *pos)
471 SheetView *sv;
472 WorkbookView *wbv;
474 if (!sheet_is_visible (sheet))
475 return;
477 wbv = wb_control_view (GNM_WBC (wbcg));
478 sv = sheet_get_view (sheet, wbv);
479 wb_view_sheet_focus (wbv, sheet);
480 sv_selection_set (sv, pos,
481 pos->col, pos->row,
482 pos->col, pos->row);
483 sv_make_cell_visible (sv, pos->col, pos->row, FALSE);
486 static int
487 cb_edit_search_replace_query (GnmSearchReplaceQuery q, GnmSearchReplace *sr, ...)
489 int res;
490 va_list pvar;
491 WBCGtk *wbcg = sr->user_data;
493 va_start (pvar, sr);
495 switch (q) {
496 case GNM_SRQ_FAIL: {
497 GnmCell *cell = va_arg (pvar, GnmCell *);
498 char const *old_text = va_arg (pvar, char const *);
499 char const *new_text = va_arg (pvar, char const *);
500 char *err = g_strdup_printf
501 (_("In cell %s, the current contents\n"
502 " %s\n"
503 "would have been replaced by\n"
504 " %s\n"
505 "which is invalid.\n\n"
506 "The replace has been aborted "
507 "and nothing has been changed."),
508 cell_name (cell),
509 old_text,
510 new_text);
512 go_gtk_notice_dialog (wbcg_toplevel (wbcg), GTK_MESSAGE_ERROR,
513 "%s", err);
514 g_free (err);
515 res = GTK_RESPONSE_NO;
516 break;
519 case GNM_SRQ_QUERY: {
520 GnmCell *cell = va_arg (pvar, GnmCell *);
521 char const *old_text = va_arg (pvar, char const *);
522 char const *new_text = va_arg (pvar, char const *);
523 Sheet *sheet = cell->base.sheet;
524 char *pos_name = g_strconcat (sheet->name_unquoted, "!",
525 cell_name (cell), NULL);
527 common_cell_goto (wbcg, sheet, &cell->pos);
529 res = dialog_search_replace_query (wbcg, sr, pos_name,
530 old_text, new_text);
531 g_free (pos_name);
532 break;
535 case GNM_SRQ_QUERY_COMMENT: {
536 Sheet *sheet = va_arg (pvar, Sheet *);
537 GnmCellPos *cp = va_arg (pvar, GnmCellPos *);
538 char const *old_text = va_arg (pvar, char const *);
539 char const *new_text = va_arg (pvar, char const *);
540 char *pos_name = g_strdup_printf (_("Comment in cell %s!%s"),
541 sheet->name_unquoted,
542 cellpos_as_string (cp));
543 common_cell_goto (wbcg, sheet, cp);
545 res = dialog_search_replace_query (wbcg, sr, pos_name,
546 old_text, new_text);
547 g_free (pos_name);
548 break;
551 default:
552 /* Shouldn't really happen. */
553 res = GTK_RESPONSE_CANCEL;
556 va_end (pvar);
557 return res;
560 static gboolean
561 cb_edit_search_replace_action (WBCGtk *wbcg,
562 GnmSearchReplace *sr)
564 WorkbookControl *wbc = GNM_WBC (wbcg);
566 sr->query_func = cb_edit_search_replace_query;
567 sr->user_data = wbcg;
569 return cmd_search_replace (wbc, sr);
573 static GNM_ACTION_DEF (cb_edit_search_replace) { dialog_search_replace (wbcg, cb_edit_search_replace_action); }
574 static GNM_ACTION_DEF (cb_edit_search) { dialog_search (wbcg); }
576 static GNM_ACTION_DEF (cb_edit_fill_autofill)
578 WorkbookControl *wbc = GNM_WBC (wbcg);
579 SheetView *sv = wb_control_cur_sheet_view (wbc);
580 Sheet *sheet = wb_control_cur_sheet (wbc);
582 GnmRange const *total = selection_first_range (sv, GO_CMD_CONTEXT (wbc), _("Autofill"));
583 if (total) {
584 GnmRange src = *total;
585 gboolean do_loop;
586 GSList *merges, *ptr;
588 if (sheet_range_trim (sheet, &src, TRUE, TRUE))
589 return; /* Region totally empty */
591 /* trim is a bit overzealous, it forgets about merges */
592 do {
593 do_loop = FALSE;
594 merges = gnm_sheet_merge_get_overlap (sheet, &src);
595 for (ptr = merges ; ptr != NULL ; ptr = ptr->next) {
596 GnmRange const *r = ptr->data;
597 if (src.end.col < r->end.col) {
598 src.end.col = r->end.col;
599 do_loop = TRUE;
601 if (src.end.row < r->end.row) {
602 src.end.row = r->end.row;
603 do_loop = TRUE;
606 } while (do_loop);
608 /* Make it autofill in only one direction */
609 if ((total->end.col - src.end.col) >=
610 (total->end.row - src.end.row))
611 src.end.row = total->end.row;
612 else
613 src.end.col = total->end.col;
615 cmd_autofill (wbc, sheet, FALSE,
616 total->start.col, total->start.row,
617 src.end.col - total->start.col + 1,
618 src.end.row - total->start.row + 1,
619 total->end.col, total->end.row,
620 FALSE);
624 static GNM_ACTION_DEF (cb_edit_fill_series)
626 dialog_fill_series (wbcg);
629 static GNM_ACTION_DEF (cb_edit_goto_top)
631 wb_control_navigate_to_cell (GNM_WBC (wbcg), navigator_top);
633 static GNM_ACTION_DEF (cb_edit_goto_bottom)
635 wb_control_navigate_to_cell (GNM_WBC (wbcg), navigator_bottom);
637 static GNM_ACTION_DEF (cb_edit_goto_first)
639 wb_control_navigate_to_cell (GNM_WBC (wbcg), navigator_first);
641 static GNM_ACTION_DEF (cb_edit_goto_last)
643 wb_control_navigate_to_cell (GNM_WBC (wbcg), navigator_last);
645 static GNM_ACTION_DEF (cb_edit_goto)
647 dialog_goto_cell (wbcg);
649 static GNM_ACTION_DEF (cb_edit_goto_cell_indicator)
651 if (GNM_IS_WBC_GTK (wbcg))
652 wbcg_focus_current_cell_indicator (WBC_GTK (wbcg));
655 static GNM_ACTION_DEF (cb_edit_recalc)
657 /* TODO :
658 * f9 - do any necessary calculations across all sheets
659 * shift-f9 - do any necessary calcs on current sheet only
660 * ctrl-alt-f9 - force a full recalc across all sheets
661 * ctrl-alt-shift-f9 - a full-monty super recalc
663 workbook_recalc_all (wb_control_get_workbook (GNM_WBC (wbcg)));
666 static GNM_ACTION_DEF (cb_repeat) { command_repeat (GNM_WBC (wbcg)); }
668 /****************************************************************************/
670 static GNM_ACTION_DEF (cb_direction)
672 Sheet *sheet = wb_control_cur_sheet (GNM_WBC (wbcg));
673 cmd_toggle_rtl (GNM_WBC (wbcg), sheet);
676 static GNM_ACTION_DEF (cb_view_zoom_in)
678 Sheet *sheet = wb_control_cur_sheet (GNM_WBC (wbcg));
679 int zoom = (int)(sheet->last_zoom_factor_used * 100. + .5) - 10;
680 if ((zoom % 15) != 0)
681 zoom = 15 * (int)(zoom/15);
682 zoom += 15;
683 if (zoom <= 390)
684 cmd_zoom (GNM_WBC (wbcg), g_slist_append (NULL, sheet),
685 (double) (zoom + 10) / 100);
687 static GNM_ACTION_DEF (cb_view_zoom_out)
689 Sheet *sheet = wb_control_cur_sheet (GNM_WBC (wbcg));
690 int zoom = (int)(sheet->last_zoom_factor_used * 100. + .5) - 10;
691 if ((zoom % 15) != 0)
692 zoom = 15 * (int)(zoom/15);
693 else
694 zoom -= 15;
695 if (0 <= zoom)
696 cmd_zoom (GNM_WBC (wbcg), g_slist_append (NULL, sheet),
697 (double) (zoom + 10) / 100);
700 static GNM_ACTION_DEF (cb_view_fullscreen)
702 if (wbcg->is_fullscreen)
703 gtk_window_unfullscreen (wbcg_toplevel (wbcg));
704 else
705 gtk_window_fullscreen (wbcg_toplevel (wbcg));
708 static GNM_ACTION_DEF (cb_view_zoom) { dialog_zoom (wbcg, wbcg_cur_sheet (wbcg)); }
709 static GNM_ACTION_DEF (cb_view_new) { dialog_new_view (wbcg); }
710 static GNM_ACTION_DEF (cb_view_freeze_panes)
712 WorkbookControl *wbc = GNM_WBC (wbcg);
713 SheetView *sv = wb_control_cur_sheet_view (wbc);
714 SheetControlGUI *scg = wbcg_cur_scg (wbcg);
716 scg_mode_edit (scg);
717 if (scg->active_panes == 1) {
718 gboolean center = FALSE;
719 GnmPane const *pane = scg_pane (scg, 0);
720 GnmCellPos frozen_tl, unfrozen_tl;
722 frozen_tl = pane->first;
723 unfrozen_tl = sv->edit_pos;
725 if (unfrozen_tl.row == 0 && unfrozen_tl.col == 0) {
726 GnmRange const *first = selection_first_range (sv, NULL, NULL);
727 Sheet *sheet = sv_sheet (sv);
728 gboolean full_rows = range_is_full (first, sheet, TRUE);
729 gboolean full_cols = range_is_full (first, sheet, FALSE);
730 if (!full_rows || !full_cols) {
731 if (!full_rows && !full_cols) {
732 unfrozen_tl.row = first->end.row + 1;
733 unfrozen_tl.col = first->end.col + 1;
734 } else if (full_rows) {
735 unfrozen_tl.row = first->end.row + 1;
736 unfrozen_tl.col = 0;
737 } else {
738 unfrozen_tl.row = 0;
739 unfrozen_tl.col = first->end.col + 1;
744 /* If edit pos is out of visible range */
745 if (unfrozen_tl.col < pane->first.col ||
746 unfrozen_tl.col > pane->last_visible.col ||
747 unfrozen_tl.row < pane->first.row ||
748 unfrozen_tl.row > pane->last_visible.row)
749 center = TRUE;
751 if (unfrozen_tl.col == pane->first.col) {
752 /* or edit pos is in top left visible cell */
753 if (unfrozen_tl.row == pane->first.row)
754 center = TRUE;
755 else
756 unfrozen_tl.col = frozen_tl.col = 0;
757 } else if (unfrozen_tl.row == pane->first.row)
758 unfrozen_tl.row = frozen_tl.row = 0;
760 if (center) {
761 unfrozen_tl.col = (pane->first.col +
762 pane->last_visible.col) / 2;
763 unfrozen_tl.row = (pane->first.row +
764 pane->last_visible.row) / 2;
767 g_return_if_fail (unfrozen_tl.col > frozen_tl.col ||
768 unfrozen_tl.row > frozen_tl.row);
770 sv_freeze_panes (sv, &frozen_tl, &unfrozen_tl);
771 } else
772 sv_freeze_panes (sv, NULL, NULL);
775 /****************************************************************************/
777 static void
778 insert_date_time_common (WBCGtk *wbcg, gboolean do_date, gboolean do_time)
780 if (wbcg_edit_start (wbcg, FALSE, FALSE)) {
781 WorkbookControl *wbc = GNM_WBC (wbcg);
782 SheetView *sv = wb_control_cur_sheet_view (wbc);
783 Sheet *sheet = sv_sheet (sv);
784 GnmCell const *cell = sheet_cell_fetch (sheet,
785 sv->edit_pos.col,
786 sv->edit_pos.row);
787 GODateConventions const *date_conv =
788 workbook_date_conv (sheet->workbook);
789 GnmValue *v = value_new_float
790 (go_date_timet_to_serial_raw (time (NULL), date_conv));
791 char *txt;
792 char *dtxt = NULL;
793 char *ttxt = NULL;
795 if (do_date) {
796 GOFormat *fmt = gnm_format_for_date_editing (cell);
797 dtxt = format_value (fmt, v, -1, date_conv);
798 go_format_unref (fmt);
801 if (do_time) {
802 GOFormat const *fmt = go_format_default_time ();
803 ttxt = format_value (fmt, v, -1, date_conv);
806 if (do_date && do_time) {
807 txt = g_strconcat (dtxt, " ", ttxt, NULL);
808 g_free (dtxt);
809 g_free (ttxt);
810 } else if (do_date)
811 txt = dtxt;
812 else
813 txt = ttxt;
815 wb_control_edit_line_set (wbc, txt);
817 value_release (v);
818 g_free (txt);
824 static GNM_ACTION_DEF (cb_insert_current_date_time)
826 insert_date_time_common (wbcg, TRUE, TRUE);
828 static GNM_ACTION_DEF (cb_insert_current_date)
830 insert_date_time_common (wbcg, TRUE, FALSE);
833 static GNM_ACTION_DEF (cb_insert_current_time)
835 insert_date_time_common (wbcg, FALSE, TRUE);
838 static GNM_ACTION_DEF (cb_define_name)
840 dialog_define_names (wbcg);
842 static GNM_ACTION_DEF (cb_paste_names)
844 dialog_paste_names (wbcg);
847 static GNM_ACTION_DEF (cb_insert_rows)
849 WorkbookControl *wbc = GNM_WBC (wbcg);
850 Sheet *sheet = wb_control_cur_sheet (wbc);
851 SheetView *sv = wb_control_cur_sheet_view (wbc);
852 GnmRange const *sel;
854 /* TODO : No need to check simplicty. XL applies for each non-discrete
855 * selected region, (use selection_apply). Arrays and Merged regions
856 * are permitted.
858 if (!(sel = selection_first_range (sv, GO_CMD_CONTEXT (wbc), _("Insert rows"))))
859 return;
860 cmd_insert_rows (wbc, sheet, sel->start.row, range_height (sel));
863 static GNM_ACTION_DEF (cb_insert_cols)
865 WorkbookControl *wbc = GNM_WBC (wbcg);
866 Sheet *sheet = wb_control_cur_sheet (wbc);
867 SheetView *sv = wb_control_cur_sheet_view (wbc);
868 GnmRange const *sel;
870 /* TODO : No need to check simplicty. XL applies for each non-discrete
871 * selected region, (use selection_apply). Arrays and Merged regions
872 * are permitted.
874 if (!(sel = selection_first_range (sv, GO_CMD_CONTEXT (wbc),
875 _("Insert columns"))))
876 return;
877 cmd_insert_cols (wbc, sheet, sel->start.col, range_width (sel));
880 static GNM_ACTION_DEF (cb_insert_cells) { dialog_insert_cells (wbcg); }
882 static GNM_ACTION_DEF (cb_insert_comment)
884 WorkbookControl *wbc = GNM_WBC (wbcg);
885 Sheet *sheet = wb_control_cur_sheet (wbc);
886 SheetView *sv = wb_control_cur_sheet_view (wbc);
887 dialog_cell_comment (wbcg, sheet, &sv->edit_pos);
890 /****************************************************************************/
892 static GNM_ACTION_DEF (cb_sheet_name)
894 WorkbookControl *wbc = GNM_WBC (wbcg);
895 Sheet *sheet = wb_control_cur_sheet (wbc);
896 dialog_sheet_rename (wbcg, sheet);
899 static GNM_ACTION_DEF (cb_sheet_order) { dialog_sheet_order (wbcg); }
900 static GNM_ACTION_DEF (cb_sheet_resize) { dialog_sheet_resize (wbcg); }
901 static GNM_ACTION_DEF (cb_format_cells) { dialog_cell_format (wbcg, FD_CURRENT, 0); }
902 static GNM_ACTION_DEF (cb_format_cells_cond) { dialog_cell_format_cond (wbcg); }
903 static GNM_ACTION_DEF (cb_autoformat) { dialog_autoformat (wbcg); }
904 static GNM_ACTION_DEF (cb_workbook_attr) { dialog_workbook_attr (wbcg); }
905 static GNM_ACTION_DEF (cb_tools_plugins) { dialog_plugin_manager (wbcg); }
906 static GNM_ACTION_DEF (cb_tools_autocorrect) { dialog_preferences (wbcg, "Auto Correct"); }
907 static GNM_ACTION_DEF (cb_tools_auto_save) { dialog_autosave (wbcg); }
908 static GNM_ACTION_DEF (cb_tools_goal_seek) { dialog_goal_seek (wbcg, wbcg_cur_sheet (wbcg)); }
909 static GNM_ACTION_DEF (cb_tools_tabulate) { dialog_tabulate (wbcg, wbcg_cur_sheet (wbcg)); }
910 static GNM_ACTION_DEF (cb_tools_merge) { dialog_merge (wbcg); }
912 static GNM_ACTION_DEF (cb_tools_solver) { dialog_solver (wbcg, wbcg_cur_sheet (wbcg)); }
914 static GNM_ACTION_DEF (cb_tools_scenario_add) { dialog_scenario_add (wbcg); }
915 static GNM_ACTION_DEF (cb_tools_scenarios) { dialog_scenarios (wbcg); }
916 static GNM_ACTION_DEF (cb_tools_simulation) { dialog_simulation (wbcg, wbcg_cur_sheet (wbcg)); }
917 static GNM_ACTION_DEF (cb_tools_anova_one_factor) { dialog_anova_single_factor_tool (wbcg, wbcg_cur_sheet (wbcg)); }
918 static GNM_ACTION_DEF (cb_tools_anova_two_factor) { dialog_anova_two_factor_tool (wbcg, wbcg_cur_sheet (wbcg)); }
919 static GNM_ACTION_DEF (cb_tools_chi_square_independence) { dialog_chi_square_tool (wbcg, wbcg_cur_sheet (wbcg), TRUE); }
920 static GNM_ACTION_DEF (cb_tools_chi_square_homogeneity) { dialog_chi_square_tool (wbcg, wbcg_cur_sheet (wbcg), FALSE); }
921 static GNM_ACTION_DEF (cb_tools_correlation) { dialog_correlation_tool (wbcg, wbcg_cur_sheet (wbcg)); }
922 static GNM_ACTION_DEF (cb_tools_covariance) { dialog_covariance_tool (wbcg, wbcg_cur_sheet (wbcg)); }
923 static GNM_ACTION_DEF (cb_tools_desc_statistics) { dialog_descriptive_stat_tool (wbcg, wbcg_cur_sheet (wbcg)); }
924 static GNM_ACTION_DEF (cb_tools_exp_smoothing) { dialog_exp_smoothing_tool (wbcg, wbcg_cur_sheet (wbcg)); }
925 static GNM_ACTION_DEF (cb_tools_average) { dialog_average_tool (wbcg, wbcg_cur_sheet (wbcg)); }
926 static GNM_ACTION_DEF (cb_tools_fourier) { dialog_fourier_tool (wbcg, wbcg_cur_sheet (wbcg)); }
927 static GNM_ACTION_DEF (cb_tools_frequency) { dialog_frequency_tool (wbcg, wbcg_cur_sheet (wbcg)); }
928 static GNM_ACTION_DEF (cb_tools_histogram) { dialog_histogram_tool (wbcg, wbcg_cur_sheet (wbcg)); }
929 static GNM_ACTION_DEF (cb_tools_kaplan_meier) { dialog_kaplan_meier_tool (wbcg, wbcg_cur_sheet (wbcg)); }
930 static GNM_ACTION_DEF (cb_tools_normality_tests){ dialog_normality_tool (wbcg, wbcg_cur_sheet (wbcg)); }
931 static GNM_ACTION_DEF (cb_tools_one_mean_test) { dialog_one_mean_test_tool (wbcg, wbcg_cur_sheet (wbcg)); }
932 static GNM_ACTION_DEF (cb_tools_principal_components) { dialog_principal_components_tool (wbcg, wbcg_cur_sheet (wbcg)); }
933 static GNM_ACTION_DEF (cb_tools_ranking) { dialog_ranking_tool (wbcg, wbcg_cur_sheet (wbcg)); }
934 static GNM_ACTION_DEF (cb_tools_regression) { dialog_regression_tool (wbcg, wbcg_cur_sheet (wbcg)); }
935 static GNM_ACTION_DEF (cb_tools_sampling) { dialog_sampling_tool (wbcg, wbcg_cur_sheet (wbcg)); }
936 static GNM_ACTION_DEF (cb_tools_sign_test_one_median) { dialog_sign_test_tool (wbcg, wbcg_cur_sheet (wbcg), SIGNTEST); }
937 static GNM_ACTION_DEF (cb_tools_sign_test_two_medians) { dialog_sign_test_two_tool (wbcg, wbcg_cur_sheet (wbcg), SIGNTEST); }
938 static GNM_ACTION_DEF (cb_tools_wilcoxon_signed_rank_one_median) { dialog_sign_test_tool (wbcg, wbcg_cur_sheet (wbcg), SIGNTEST_WILCOXON); }
939 static GNM_ACTION_DEF (cb_tools_wilcoxon_signed_rank_two_medians) { dialog_sign_test_two_tool (wbcg, wbcg_cur_sheet (wbcg), SIGNTEST_WILCOXON); }
940 static GNM_ACTION_DEF (cb_tools_wilcoxon_mann_whitney) { dialog_wilcoxon_m_w_tool (wbcg, wbcg_cur_sheet (wbcg)); }
941 static GNM_ACTION_DEF (cb_tools_ttest_paired) { dialog_ttest_tool (wbcg, wbcg_cur_sheet (wbcg), TTEST_PAIRED); }
942 static GNM_ACTION_DEF (cb_tools_ttest_equal_var) { dialog_ttest_tool (wbcg, wbcg_cur_sheet (wbcg), TTEST_UNPAIRED_EQUALVARIANCES); }
943 static GNM_ACTION_DEF (cb_tools_ttest_unequal_var) { dialog_ttest_tool (wbcg, wbcg_cur_sheet (wbcg), TTEST_UNPAIRED_UNEQUALVARIANCES); }
944 static GNM_ACTION_DEF (cb_tools_ztest) { dialog_ttest_tool (wbcg, wbcg_cur_sheet (wbcg), TTEST_ZTEST); }
945 static GNM_ACTION_DEF (cb_tools_ftest) { dialog_ftest_tool (wbcg, wbcg_cur_sheet (wbcg)); }
946 static GNM_ACTION_DEF (cb_tools_random_generator_uncorrelated) { dialog_random_tool (wbcg, wbcg_cur_sheet (wbcg)); }
947 static GNM_ACTION_DEF (cb_tools_random_generator_correlated) { dialog_random_cor_tool (wbcg, wbcg_cur_sheet (wbcg)); }
948 static GNM_ACTION_DEF (cb_data_sort) { dialog_cell_sort (wbcg); }
949 static GNM_ACTION_DEF (cb_data_shuffle) { dialog_shuffle (wbcg); }
950 static GNM_ACTION_DEF (cb_data_import_text) { gui_file_open
951 (wbcg, GNM_FILE_OPEN_STYLE_IMPORT, "Gnumeric_stf:stf_assistant"); }
952 static GNM_ACTION_DEF (cb_data_import_other) { gui_file_open
953 (wbcg, GNM_FILE_OPEN_STYLE_IMPORT, NULL); }
955 static GNM_ACTION_DEF (cb_auto_filter) { cmd_autofilter_add_remove (GNM_WBC (wbcg)); }
956 static GNM_ACTION_DEF (cb_show_all) { filter_show_all (GNM_WBC (wbcg)); }
957 static GNM_ACTION_DEF (cb_data_filter) { dialog_advanced_filter (wbcg); }
958 static GNM_ACTION_DEF (cb_data_validate) { dialog_cell_format (wbcg, FD_VALIDATION,
959 (1 << FD_VALIDATION) | (1 << FD_INPUT_MSG)); }
960 static GNM_ACTION_DEF (cb_data_text_to_columns) { stf_text_to_columns (GNM_WBC (wbcg), GO_CMD_CONTEXT (wbcg)); }
961 static GNM_ACTION_DEF (cb_data_consolidate) { dialog_consolidate (wbcg); }
962 static GNM_ACTION_DEF (cb_data_table) { dialog_data_table (wbcg); }
963 static GNM_ACTION_DEF (cb_data_slicer_create) { dialog_data_slicer (wbcg, TRUE); }
964 static GNM_ACTION_DEF (cb_data_slicer_refresh) { cmd_slicer_refresh (GNM_WBC (wbcg)); }
965 static GNM_ACTION_DEF (cb_data_slicer_edit) { dialog_data_slicer (wbcg, FALSE); }
966 static GNM_ACTION_DEF (cb_data_export) { gui_file_save_as
967 (wbcg, wb_control_view (GNM_WBC (wbcg)),
968 GNM_FILE_SAVE_AS_STYLE_EXPORT, NULL); }
969 static GNM_ACTION_DEF (cb_data_export_text) { gui_file_save_as
970 (wbcg, wb_control_view (GNM_WBC (wbcg)),
971 GNM_FILE_SAVE_AS_STYLE_EXPORT, "Gnumeric_stf:stf_assistant"); }
972 static GNM_ACTION_DEF (cb_data_export_csv) { gui_file_save_as
973 (wbcg, wb_control_view (GNM_WBC (wbcg)),
974 GNM_FILE_SAVE_AS_STYLE_EXPORT, "Gnumeric_stf:stf_csv"); }
975 static GNM_ACTION_DEF (cb_data_export_repeat) { gui_file_export_repeat (wbcg); }
977 static void
978 hide_show_detail_real (WBCGtk *wbcg, gboolean is_cols, gboolean show)
980 WorkbookControl *wbc = GNM_WBC (wbcg);
981 SheetView *sv = wb_control_cur_sheet_view (wbc);
982 char const *operation = show ? _("Show Detail") : _("Hide Detail");
983 GnmRange const *r = selection_first_range (sv, GO_CMD_CONTEXT (wbc),
984 operation);
986 /* This operation can only be performed on a whole existing group */
987 if (sheet_colrow_can_group (sv_sheet (sv), r, is_cols)) {
988 go_cmd_context_error_invalid (GO_CMD_CONTEXT (wbc), operation,
989 _("can only be performed on an existing group"));
990 return;
993 cmd_selection_colrow_hide (wbc, is_cols, show);
996 static void
997 hide_show_detail (WBCGtk *wbcg, gboolean show)
999 WorkbookControl *wbc = GNM_WBC (wbcg);
1000 SheetView *sv = wb_control_cur_sheet_view (wbc);
1001 Sheet const *sheet = sv_sheet (sv);
1002 char const *operation = show ? _("Show Detail") : _("Hide Detail");
1003 GnmRange const *r = selection_first_range (sv,
1004 GO_CMD_CONTEXT (wbc), operation);
1005 gboolean is_cols;
1007 /* We only operate on a single selection */
1008 if (r == NULL)
1009 return;
1011 /* Do we need to ask the user what he/she wants to group/ungroup? */
1012 if (range_is_full (r, sheet, TRUE) ^ range_is_full (r, sheet, FALSE))
1013 is_cols = !range_is_full (r, sheet, TRUE);
1014 else {
1015 dialog_col_row (wbcg, operation,
1016 (ColRowCallback_t) hide_show_detail_real,
1017 GINT_TO_POINTER (show));
1018 return;
1021 hide_show_detail_real (wbcg, is_cols, show);
1024 static void
1025 group_ungroup_colrow (WBCGtk *wbcg, gboolean group)
1027 WorkbookControl *wbc = GNM_WBC (wbcg);
1028 SheetView *sv = wb_control_cur_sheet_view (wbc);
1029 Sheet const *sheet = sv_sheet (sv);
1030 char const *operation = group ? _("Group") : _("Ungroup");
1031 GnmRange const *r = selection_first_range (sv,
1032 GO_CMD_CONTEXT (wbc), operation);
1033 gboolean is_cols;
1035 /* We only operate on a single selection */
1036 if (r == NULL)
1037 return;
1039 /* Do we need to ask the user what he/she wants to group/ungroup? */
1040 if (range_is_full (r, sheet, TRUE) ^ range_is_full (r, sheet, FALSE))
1041 is_cols = !range_is_full (r, sheet, TRUE);
1042 else {
1043 dialog_col_row (wbcg, operation,
1044 (ColRowCallback_t) cmd_selection_group,
1045 GINT_TO_POINTER (group));
1046 return;
1049 cmd_selection_group (wbc, is_cols, group);
1052 static GNM_ACTION_DEF (cb_data_hide_detail) { hide_show_detail (wbcg, FALSE); }
1053 static GNM_ACTION_DEF (cb_data_show_detail) { hide_show_detail (wbcg, TRUE); }
1054 static GNM_ACTION_DEF (cb_data_group) { group_ungroup_colrow (wbcg, TRUE); }
1055 static GNM_ACTION_DEF (cb_data_ungroup) { group_ungroup_colrow (wbcg, FALSE); }
1057 static GNM_ACTION_DEF (cb_help_function) { dialog_function_select_help (wbcg); }
1058 static GNM_ACTION_DEF (cb_help_docs)
1060 char *argv[] = { NULL, NULL, NULL };
1061 GError *err = NULL;
1063 #ifndef G_OS_WIN32
1064 argv[0] = (char *)"yelp";
1065 argv[1] = (char *)"help:gnumeric";
1066 g_spawn_async (NULL, argv, NULL,
1067 G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL
1068 | G_SPAWN_STDERR_TO_DEV_NULL,
1069 NULL, NULL, NULL, &err);
1070 #else
1071 /* TODO : Should really start in same directory as the gspawn-* helpers
1072 * are installed in case they are not in the path */
1073 argv[0] = (char *)"hh";
1074 argv[1] = g_build_filename (gnm_sys_data_dir (), "doc", "C",
1075 "gnumeric.chm", NULL);
1076 g_spawn_async (NULL, argv, NULL,
1077 G_SPAWN_SEARCH_PATH | G_SPAWN_STDOUT_TO_DEV_NULL
1078 | G_SPAWN_STDERR_TO_DEV_NULL,
1079 NULL, NULL, NULL, &err);
1080 g_free (argv[1]);
1081 #endif
1082 if (NULL != err) {
1083 GOErrorInfo *ei = go_error_info_new_printf
1084 (_("Unable to start the help browser (%s).\n"
1085 "The system error message is: \n\n%s"),
1086 argv[0], err->message);
1087 go_cmd_context_error_info (GO_CMD_CONTEXT (wbcg), ei);
1088 g_error_free (err);
1089 g_free (ei);
1093 static void
1094 show_url (WBCGtk *wbcg, const char *url)
1096 GError *err;
1097 GdkScreen *screen;
1099 screen = gtk_window_get_screen (wbcg_toplevel (wbcg));
1100 err = go_gtk_url_show (url, screen);
1101 if (err != NULL) {
1102 go_cmd_context_error (GO_CMD_CONTEXT (wbcg), err);
1103 g_error_free (err);
1108 static GNM_ACTION_DEF (cb_help_web)
1110 show_url (wbcg, "http://www.gnumeric.org/");
1113 static GNM_ACTION_DEF (cb_help_irc)
1115 show_url (wbcg, "irc://irc.gnome.org/gnumeric");
1118 static GNM_ACTION_DEF (cb_help_bug)
1120 show_url (wbcg, "http://bugzilla.gnome.org/enter_bug.cgi?product=Gnumeric");
1123 static GNM_ACTION_DEF (cb_help_about) { dialog_about (wbcg); }
1125 static GNM_ACTION_DEF (cb_autosum)
1127 GtkEntry *entry;
1128 gchar const *txt;
1130 if (wbcg_is_editing (wbcg))
1131 return;
1133 entry = wbcg_get_entry (wbcg);
1134 txt = gtk_entry_get_text (entry);
1135 if (strncmp (txt, "=sum(", 5)) {
1136 if (!wbcg_edit_start (wbcg, TRUE, TRUE))
1137 return; /* attempt to edit failed */
1138 gtk_entry_set_text (entry, "=sum()");
1139 gtk_editable_set_position (GTK_EDITABLE (entry), 5);
1140 } else {
1141 if (!wbcg_edit_start (wbcg, FALSE, TRUE))
1142 return; /* attempt to edit failed */
1145 * FIXME : This is crap!
1146 * When the function druid is more complete use that.
1148 gtk_editable_set_position (GTK_EDITABLE (entry),
1149 gtk_entry_get_text_length (entry)-1);
1153 static GNM_ACTION_DEF (cb_insert_image)
1155 char *uri = go_gtk_select_image (wbcg_toplevel (wbcg), NULL);
1157 if (uri) {
1158 GError *err = NULL;
1159 GsfInput *input = go_file_open (uri, &err);
1161 if (input != NULL) {
1162 unsigned len = gsf_input_size (input);
1163 guint8 const *data = gsf_input_read (input, len, NULL);
1164 SheetObjectImage *soi = g_object_new (GNM_SO_IMAGE_TYPE, NULL);
1165 sheet_object_image_set_image (soi, "", data, len);
1166 wbcg_insert_object (wbcg, GNM_SO (soi));
1167 g_object_unref (input);
1168 } else
1169 go_cmd_context_error (GO_CMD_CONTEXT (wbcg), err);
1171 g_free (uri);
1175 static GNM_ACTION_DEF (cb_insert_hyperlink) { dialog_hyperlink (wbcg, GNM_SC (wbcg_cur_scg (wbcg))); }
1176 static GNM_ACTION_DEF (cb_formula_guru) { dialog_formula_guru (wbcg, NULL); }
1177 static GNM_ACTION_DEF (cb_insert_sort_ascending) { workbook_cmd_wrap_sort (GNM_WBC (wbcg), 1);}
1178 static GNM_ACTION_DEF (cb_insert_sort_descending){ workbook_cmd_wrap_sort (GNM_WBC (wbcg), 0);}
1180 static void
1181 sort_by_rows (WBCGtk *wbcg, gboolean descending)
1183 SheetView *sv;
1184 GnmRange *sel;
1185 GnmRange tmp_ns ={{0,0},{0,0}}, tmp_s ={{0,0},{0,0}};
1186 GnmSortData *data;
1187 GnmSortClause *clause;
1188 int numclause, i;
1189 GSList *l;
1190 int cnt_singletons = 0, cnt_non_singletons = 0;
1191 gboolean top_to_bottom = TRUE;
1192 gboolean not_acceptable = FALSE;
1194 g_return_if_fail (GNM_IS_WBC_GTK (wbcg));
1196 sv = wb_control_cur_sheet_view (GNM_WBC (wbcg));
1197 for (l = sv->selections; l != NULL; l = l->next) {
1198 GnmRange const *r = l->data;
1199 if (range_is_singleton (r)) {
1200 cnt_singletons++;
1201 tmp_s = *r;
1202 } else {
1203 cnt_non_singletons++;
1204 tmp_ns = *r;
1208 not_acceptable = (cnt_non_singletons > 1 ||
1209 (cnt_non_singletons == 0 && cnt_singletons > 1));
1211 if (!not_acceptable && cnt_singletons > 0 && cnt_non_singletons == 1) {
1212 gboolean first = TRUE;
1213 for (l = sv->selections; l != NULL; l = l->next) {
1214 GnmRange const *r = l->data;
1215 gboolean t_b = FALSE, l_r = FALSE;
1217 if (!range_is_singleton (r))
1218 continue;
1219 t_b = r->start.col >= tmp_ns.start.col &&
1220 r->end.col <= tmp_ns.end.col;
1221 l_r = r->start.row >= tmp_ns.start.row &&
1222 r->end.row <= tmp_ns.end.row;
1223 if (!t_b && !l_r) {
1224 not_acceptable = TRUE;
1225 break;
1227 if (!t_b || !l_r) {
1228 if (first) {
1229 first = FALSE;
1230 top_to_bottom = t_b;
1231 } else {
1232 if ((top_to_bottom && !t_b) ||
1233 (!top_to_bottom && !l_r)) {
1234 not_acceptable = TRUE;
1235 break;
1242 if (not_acceptable) {
1243 GError *msg = g_error_new (go_error_invalid(), 0,
1244 _("%s does not support multiple ranges"),
1245 _("Sort"));
1246 go_cmd_context_error (GO_CMD_CONTEXT (wbcg), msg);
1247 g_error_free (msg);
1248 return;
1251 if (cnt_singletons == 1 && cnt_non_singletons == 0) {
1252 Sheet *sheet = sv_sheet (sv);
1254 sel = g_new0 (GnmRange, 1);
1255 range_init_full_sheet (sel, sheet);
1256 sel->start.row = tmp_s.start.row;
1257 range_clip_to_finite (sel, sheet);
1258 numclause = 1;
1259 clause = g_new0 (GnmSortClause, 1);
1260 clause[0].offset = tmp_s.start.col - sel->start.col;
1261 clause[0].asc = descending;
1262 clause[0].cs = gnm_conf_get_core_sort_default_by_case ();
1263 clause[0].val = TRUE;
1264 } else if (cnt_singletons == 0) {
1265 sel = gnm_range_dup (&tmp_ns);
1266 range_clip_to_finite (sel, sv_sheet (sv));
1268 numclause = range_width (sel);
1269 clause = g_new0 (GnmSortClause, numclause);
1270 for (i = 0; i < numclause; i++) {
1271 clause[i].offset = i;
1272 clause[i].asc = descending;
1273 clause[i].cs = gnm_conf_get_core_sort_default_by_case ();
1274 clause[i].val = TRUE;
1276 } else /* cnt_singletons > 0 && cnt_non_singletons == 1*/ {
1277 sel = gnm_range_dup (&tmp_ns);
1278 range_clip_to_finite (sel, sv_sheet (sv));
1279 numclause = cnt_singletons;
1280 clause = g_new0 (GnmSortClause, numclause);
1281 i = numclause - 1;
1282 for (l = sv->selections; l != NULL; l = l->next) {
1283 GnmRange const *r = l->data;
1284 if (!range_is_singleton (r))
1285 continue;
1286 if (i >= 0) {
1287 clause[i].offset = (top_to_bottom) ?
1288 r->start.col - sel->start.col
1289 : r->start.row - sel->start.row;
1290 clause[i].asc = descending;
1291 clause[i].cs = gnm_conf_get_core_sort_default_by_case ();
1292 clause[i].val = TRUE;
1294 i--;
1298 data = g_new (GnmSortData, 1);
1299 data->sheet = sv_sheet (sv);
1300 data->range = sel;
1301 data->num_clause = numclause;
1302 data->clauses = clause;
1303 data->locale = NULL;
1305 data->retain_formats = gnm_conf_get_core_sort_default_retain_formats ();
1307 /* Hard code sorting by row. I would prefer not to, but user testing
1308 * indicates
1309 * - that the button should always does the same things
1310 * - that the icon matches the behavior
1311 * - XL does this.
1314 /* Note that if the user specified rows by singleton selection we switch */
1315 /* to column sorting */
1316 data->top = top_to_bottom;
1318 if (sheet_range_has_heading (data->sheet, data->range, data->top, FALSE))
1319 data->range->start.row += 1;
1321 cmd_sort (GNM_WBC (wbcg), data);
1323 static GNM_ACTION_DEF (cb_sort_ascending) { sort_by_rows (wbcg, FALSE); }
1324 static GNM_ACTION_DEF (cb_sort_descending) { sort_by_rows (wbcg, TRUE); }
1326 static void
1327 cb_add_graph (GogGraph *graph, gpointer wbcg)
1329 GnmGraphDataClosure *data = (GnmGraphDataClosure *) g_object_get_data (G_OBJECT (graph), "data-closure");
1330 if (data) {
1331 if (data->new_sheet) {
1332 WorkbookControl *wbc = GNM_WBC (wbcg);
1333 Sheet *sheet = wb_control_cur_sheet (wbc);
1334 WorkbookSheetState *old_state = workbook_sheet_state_new (wb_control_get_workbook (wbc));
1335 Sheet *new_sheet = workbook_sheet_add_with_type (
1336 wb_control_get_workbook (wbc),
1337 GNM_SHEET_OBJECT, -1,
1338 gnm_sheet_get_max_cols (sheet),
1339 gnm_sheet_get_max_rows (sheet));
1340 SheetObject *sog = sheet_object_graph_new (graph);
1341 print_info_set_paper_orientation (new_sheet->print_info, GTK_PAGE_ORIENTATION_LANDSCAPE);
1342 sheet_object_set_sheet (sog, new_sheet);
1343 wb_view_sheet_focus (wb_control_view (wbc), new_sheet);
1344 cmd_reorganize_sheets (wbc, old_state, sheet);
1345 g_object_unref (sog);
1346 return;
1349 wbcg_insert_object (WBC_GTK (wbcg), sheet_object_graph_new (graph));
1352 static GNM_ACTION_DEF (cb_launch_chart_guru)
1354 GClosure *closure = g_cclosure_new (G_CALLBACK (cb_add_graph),
1355 wbcg, NULL);
1356 sheet_object_graph_guru (wbcg, NULL, closure);
1357 g_closure_sink (closure);
1360 static void
1361 cb_add_component_new (GOComponent *component, gpointer wbcg)
1363 wbcg_insert_object (WBC_GTK (wbcg), sheet_object_component_new (component));
1366 static void
1367 component_changed_cb (GOComponent *component, gpointer data)
1369 cb_add_component_new (component, data);
1372 static GNM_ACTION_DEF (cb_launch_go_component_new)
1374 gchar const *mime_type;
1375 gint result;
1376 GtkWidget *dialog = go_component_mime_dialog_new ();
1377 result = gtk_dialog_run (GTK_DIALOG (dialog));
1378 if (result == GTK_RESPONSE_OK) {
1379 mime_type = go_component_mime_dialog_get_mime_type ((GOComponentMimeDialog *) dialog);
1380 if (mime_type) {
1381 GtkWindow *win;
1382 GOComponent *component = go_component_new_by_mime_type (mime_type);
1383 if (component) {
1384 g_signal_connect (G_OBJECT (component), "changed", G_CALLBACK (component_changed_cb), wbcg);
1385 win = go_component_edit (component);
1386 gtk_window_set_transient_for (win, GTK_WINDOW (wbcg_toplevel (wbcg)));
1387 g_object_set_data_full (G_OBJECT (win), "component", component, g_object_unref);
1391 gtk_widget_destroy (dialog);
1394 static GNM_ACTION_DEF (cb_launch_go_component_from_file)
1396 GtkWidget *dlg = gtk_file_chooser_dialog_new (_("Choose object file"),
1397 GTK_WINDOW (wbcg_toplevel (wbcg)),
1398 GTK_FILE_CHOOSER_ACTION_OPEN,
1399 GNM_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1400 GNM_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1401 NULL);
1402 go_components_add_filter (GTK_FILE_CHOOSER (dlg));
1403 if (gtk_dialog_run (GTK_DIALOG (dlg)) == GTK_RESPONSE_ACCEPT) {
1404 char *uri = gtk_file_chooser_get_uri (GTK_FILE_CHOOSER (dlg));
1405 GOComponent *component;
1406 component = go_component_new_from_uri (uri);
1407 g_free (uri);
1408 if (component) {
1409 wbcg_insert_object (WBC_GTK (wbcg), sheet_object_component_new (component));
1410 g_object_unref (component);
1413 gtk_widget_destroy (dlg);
1416 static void
1417 create_object (WBCGtk *wbcg, GType t,
1418 char const *first_property_name,
1419 ...)
1421 va_list args;
1422 va_start (args, first_property_name);
1423 wbcg_insert_object (wbcg, (SheetObject *)
1424 g_object_new_valist (t, first_property_name, args));
1425 va_end (args);
1428 static GNM_ACTION_DEF (cmd_create_frame)
1429 { create_object (wbcg, sheet_widget_frame_get_type(), NULL); }
1430 static GNM_ACTION_DEF (cmd_create_button)
1431 { create_object (wbcg, sheet_widget_button_get_type(), NULL); }
1432 static GNM_ACTION_DEF (cmd_create_radiobutton)
1433 { create_object (wbcg, sheet_widget_radio_button_get_type(), NULL); }
1434 static GNM_ACTION_DEF (cmd_create_scrollbar)
1435 { create_object (wbcg, sheet_widget_scrollbar_get_type(), NULL); }
1436 static GNM_ACTION_DEF (cmd_create_slider)
1437 { create_object (wbcg, sheet_widget_slider_get_type(), NULL); }
1438 static GNM_ACTION_DEF (cmd_create_spinbutton)
1439 { create_object (wbcg, sheet_widget_spinbutton_get_type(), NULL); }
1440 static GNM_ACTION_DEF (cmd_create_checkbox)
1441 { create_object (wbcg, sheet_widget_checkbox_get_type(), NULL); }
1442 static GNM_ACTION_DEF (cmd_create_list)
1443 { create_object (wbcg, sheet_widget_list_get_type(), NULL); }
1444 static GNM_ACTION_DEF (cmd_create_combo)
1445 { create_object (wbcg, sheet_widget_combo_get_type(), NULL); }
1446 static GNM_ACTION_DEF (cmd_create_line)
1447 { create_object (wbcg, GNM_SO_LINE_TYPE, NULL); }
1448 static GNM_ACTION_DEF (cmd_create_arrow) {
1449 GOArrow arrow;
1450 go_arrow_init_kite (&arrow, 8., 10., 3.);
1451 create_object (wbcg, GNM_SO_LINE_TYPE, "end-arrow", &arrow, NULL);
1453 static GNM_ACTION_DEF (cmd_create_rectangle)
1454 { create_object (wbcg, GNM_SO_FILLED_TYPE, NULL); }
1455 static GNM_ACTION_DEF (cmd_create_ellipse)
1456 { create_object (wbcg, GNM_SO_FILLED_TYPE, "is-oval", TRUE, NULL); }
1458 /*****************************************************************************/
1459 static void
1460 wbcg_set_selection_halign (WBCGtk *wbcg, GnmHAlign halign)
1462 WorkbookControl *wbc = GNM_WBC (wbcg);
1463 WorkbookView *wb_view;
1464 GnmStyle *style;
1466 if (wbcg->updating_ui)
1467 return;
1469 /* This is a toggle button. If we are already enabled
1470 * then revert to general */
1471 wb_view = wb_control_view (wbc);
1472 if (gnm_style_get_align_h (wb_view->current_style) == halign)
1473 halign = GNM_HALIGN_GENERAL;
1475 style = gnm_style_new ();
1476 gnm_style_set_align_h (style, halign);
1477 cmd_selection_format (wbc, style, NULL, _("Set Horizontal Alignment"));
1479 static GNM_ACTION_DEF (cb_align_left)
1480 { wbcg_set_selection_halign (wbcg, GNM_HALIGN_LEFT); }
1481 static GNM_ACTION_DEF (cb_align_right)
1482 { wbcg_set_selection_halign (wbcg, GNM_HALIGN_RIGHT); }
1483 static GNM_ACTION_DEF (cb_align_center)
1484 { wbcg_set_selection_halign (wbcg, GNM_HALIGN_CENTER); }
1485 static GNM_ACTION_DEF (cb_center_across_selection)
1486 { wbcg_set_selection_halign (wbcg, GNM_HALIGN_CENTER_ACROSS_SELECTION); }
1488 /*****************************************************************************/
1490 static void
1491 wbcg_set_selection_valign (WBCGtk *wbcg, GnmVAlign valign)
1493 WorkbookControl *wbc = GNM_WBC (wbcg);
1494 WorkbookView *wb_view;
1495 GnmStyle *style;
1497 if (wbcg->updating_ui)
1498 return;
1500 /* This is a toggle button. If we are already enabled
1501 * then revert to general */
1502 wb_view = wb_control_view (wbc);
1503 if (gnm_style_get_align_v (wb_view->current_style) == valign) {
1504 if (valign == GNM_VALIGN_BOTTOM)
1505 return;
1506 valign = GNM_VALIGN_BOTTOM;
1509 style = gnm_style_new ();
1510 gnm_style_set_align_v (style, valign);
1511 cmd_selection_format (wbc, style, NULL, _("Set Vertical Alignment"));
1513 static GNM_ACTION_DEF (cb_align_top)
1514 { wbcg_set_selection_valign (wbcg, GNM_VALIGN_TOP); }
1515 static GNM_ACTION_DEF (cb_align_vcenter)
1516 { wbcg_set_selection_valign (wbcg, GNM_VALIGN_CENTER); }
1517 static GNM_ACTION_DEF (cb_align_bottom)
1518 { wbcg_set_selection_valign (wbcg, GNM_VALIGN_BOTTOM); }
1520 /*****************************************************************************/
1522 static GNM_ACTION_DEF (cb_merge_and_center)
1524 WorkbookControl *wbc = GNM_WBC (wbcg);
1525 GSList *range_list = selection_get_ranges (
1526 wb_control_cur_sheet_view (wbc), FALSE);
1527 cmd_merge_cells (wbc, wb_control_cur_sheet (wbc), range_list, TRUE);
1528 range_fragment_free (range_list);
1531 static GNM_ACTION_DEF (cb_merge_cells)
1533 WorkbookControl *wbc = GNM_WBC (wbcg);
1534 GSList *range_list = selection_get_ranges (
1535 wb_control_cur_sheet_view (wbc), FALSE);
1536 cmd_merge_cells (wbc, wb_control_cur_sheet (wbc), range_list, FALSE);
1537 range_fragment_free (range_list);
1540 static GNM_ACTION_DEF (cb_unmerge_cells)
1542 WorkbookControl *wbc = GNM_WBC (wbcg);
1543 GSList *range_list = selection_get_ranges (
1544 wb_control_cur_sheet_view (wbc), FALSE);
1545 cmd_unmerge_cells (wbc, wb_control_cur_sheet (wbc), range_list);
1546 range_fragment_free (range_list);
1549 static GNM_ACTION_DEF (cb_view_statusbar)
1551 wbcg_toggle_visibility (wbcg, GTK_TOGGLE_ACTION (a));
1554 /*****************************************************************************/
1556 static void
1557 toggle_font_attr (WBCGtk *wbcg, GtkToggleAction *act,
1558 GnmStyleElement t, unsigned true_val, unsigned false_val)
1560 WorkbookControl *wbc = GNM_WBC (wbcg);
1561 GnmStyle *new_style;
1562 unsigned val;
1564 /* If the user did not initiate this action ignore it.
1565 * This happens whenever the ui updates and the current cell makes a
1566 * change to the toolbar indicators.
1568 if (wbcg->updating_ui)
1569 return;
1571 val = gtk_toggle_action_get_active (act) ? true_val : false_val;
1572 if (wbcg_is_editing (wbcg)) {
1573 PangoAttribute *attr = NULL;
1574 switch (t) {
1575 default :
1576 case MSTYLE_FONT_BOLD:
1577 attr = pango_attr_weight_new (val ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL);
1578 break;
1579 case MSTYLE_FONT_ITALIC:
1580 attr = pango_attr_style_new (val ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL);
1581 break;
1582 case MSTYLE_FONT_UNDERLINE:
1583 attr = pango_attr_underline_new
1584 (gnm_translate_underline_to_pango (val));
1585 break;
1586 case MSTYLE_FONT_STRIKETHROUGH:
1587 attr = pango_attr_strikethrough_new (val);
1588 break;
1589 case MSTYLE_FONT_SCRIPT:
1590 switch (val) {
1591 default:
1592 case GO_FONT_SCRIPT_STANDARD:
1593 wbcg_edit_add_markup
1594 (wbcg, go_pango_attr_superscript_new (FALSE));
1595 attr = go_pango_attr_subscript_new (FALSE);
1596 break;
1597 case GO_FONT_SCRIPT_SUPER:
1598 attr = go_pango_attr_superscript_new (TRUE);
1599 break;
1600 case GO_FONT_SCRIPT_SUB:
1601 attr = go_pango_attr_subscript_new (TRUE);
1602 break;
1604 break;
1606 wbcg_edit_add_markup (wbcg, attr);
1607 return;
1610 new_style = gnm_style_new ();
1611 switch (t) {
1612 default :
1613 case MSTYLE_FONT_BOLD: gnm_style_set_font_bold (new_style, val); break;
1614 case MSTYLE_FONT_ITALIC: gnm_style_set_font_italic (new_style, val); break;
1615 case MSTYLE_FONT_UNDERLINE: gnm_style_set_font_uline (new_style, val); break;
1616 case MSTYLE_FONT_STRIKETHROUGH: gnm_style_set_font_strike (new_style, val); break;
1617 case MSTYLE_FONT_SCRIPT: gnm_style_set_font_script (new_style, val); break;
1620 cmd_selection_format_toggle_font_style (wbc, new_style, t);
1623 static void cb_font_bold (GtkToggleAction *act, WBCGtk *wbcg)
1624 { toggle_font_attr (wbcg, act, MSTYLE_FONT_BOLD, TRUE, FALSE); }
1625 static void cb_font_italic (GtkToggleAction *act, WBCGtk *wbcg)
1626 { toggle_font_attr (wbcg, act, MSTYLE_FONT_ITALIC, TRUE, FALSE); }
1627 static void cb_font_underline (GtkToggleAction *act, WBCGtk *wbcg)
1628 { toggle_font_attr (wbcg, act, MSTYLE_FONT_UNDERLINE, UNDERLINE_SINGLE, UNDERLINE_NONE); }
1629 static void cb_font_double_underline (GtkToggleAction *act, WBCGtk *wbcg)
1630 { toggle_font_attr (wbcg, act, MSTYLE_FONT_UNDERLINE, UNDERLINE_DOUBLE, UNDERLINE_NONE); }
1631 static void cb_font_underline_low (GtkToggleAction *act, WBCGtk *wbcg)
1632 { toggle_font_attr (wbcg, act, MSTYLE_FONT_UNDERLINE, UNDERLINE_SINGLE_LOW, UNDERLINE_NONE); }
1633 static void cb_font_double_underline_low (GtkToggleAction *act, WBCGtk *wbcg)
1634 { toggle_font_attr (wbcg, act, MSTYLE_FONT_UNDERLINE, UNDERLINE_DOUBLE_LOW, UNDERLINE_NONE); }
1635 static void cb_font_strikethrough (GtkToggleAction *act, WBCGtk *wbcg)
1636 { toggle_font_attr (wbcg, act, MSTYLE_FONT_STRIKETHROUGH, TRUE, FALSE); }
1637 static void cb_font_subscript (GtkToggleAction *act, WBCGtk *wbcg)
1638 { toggle_font_attr (wbcg, act, MSTYLE_FONT_SCRIPT, GO_FONT_SCRIPT_SUB, GO_FONT_SCRIPT_STANDARD); }
1639 static void cb_font_superscript (GtkToggleAction *act, WBCGtk *wbcg)
1640 { toggle_font_attr (wbcg, act, MSTYLE_FONT_SCRIPT, GO_FONT_SCRIPT_SUPER, GO_FONT_SCRIPT_STANDARD); }
1642 static void
1643 apply_number_format (WBCGtk *wbcg,
1644 GOFormat *format,
1645 char const *descriptor)
1647 GnmStyle *mstyle = gnm_style_new ();
1648 gnm_style_set_format (mstyle, format);
1649 cmd_selection_format (GNM_WBC (wbcg), mstyle, NULL, descriptor);
1652 static GNM_ACTION_DEF (cb_format_as_general)
1654 apply_number_format (wbcg,
1655 go_format_general (),
1656 _("Format as General"));
1659 static GNM_ACTION_DEF (cb_format_as_number)
1661 GOFormat *fmt = go_format_new_from_XL ("0");
1662 apply_number_format (wbcg, fmt, _("Format as Number"));
1663 go_format_unref (fmt);
1666 static GNM_ACTION_DEF (cb_format_as_currency)
1668 GOFormatDetails *details = go_format_details_new (GO_FORMAT_CURRENCY);
1669 GString *str = g_string_new (NULL);
1670 GOFormat *fmt;
1672 details->currency = go_format_locale_currency ();
1673 details->num_decimals = 2;
1674 go_format_generate_str (str, details);
1675 go_format_details_free (details);
1677 fmt = go_format_new_from_XL (str->str);
1678 g_string_free (str, TRUE);
1679 apply_number_format (wbcg, fmt, _("Format as Currency"));
1680 go_format_unref (fmt);
1683 static GNM_ACTION_DEF (cb_format_as_accounting)
1685 apply_number_format (wbcg,
1686 go_format_default_accounting (),
1687 _("Format as Accounting"));
1690 static GNM_ACTION_DEF (cb_format_as_percentage)
1692 GOFormat *fmt = go_format_new_from_XL ("0%");
1693 apply_number_format (wbcg, fmt, _("Format as Percentage"));
1694 go_format_unref (fmt);
1697 static GNM_ACTION_DEF (cb_format_as_scientific)
1699 GOFormat *fmt = go_format_new_from_XL ("0.00E+00");
1700 apply_number_format (wbcg, fmt, _("Format as Percentage"));
1701 go_format_unref (fmt);
1704 static GNM_ACTION_DEF (cb_format_as_time)
1706 apply_number_format (wbcg,
1707 go_format_default_time (),
1708 _("Format as Time"));
1711 static GNM_ACTION_DEF (cb_format_as_date)
1713 apply_number_format (wbcg,
1714 go_format_default_date (),
1715 _("Format as Date"));
1718 /* Adds borders to all the selected regions on the sheet.
1719 * FIXME: This is a little more simplistic then it should be, it always
1720 * removes and/or overwrites any borders. What we should do is
1721 * 1) When adding -> don't add a border if the border is thicker than 'THIN'
1722 * 2) When removing -> don't remove unless the border is 'THIN'
1724 static void
1725 mutate_borders (WBCGtk *wbcg, gboolean add)
1727 GnmBorder *borders [GNM_STYLE_BORDER_EDGE_MAX];
1728 int i;
1730 for (i = GNM_STYLE_BORDER_TOP; i < GNM_STYLE_BORDER_EDGE_MAX; ++i)
1731 if (i <= GNM_STYLE_BORDER_RIGHT)
1732 borders[i] = gnm_style_border_fetch (
1733 add ? GNM_STYLE_BORDER_THIN : GNM_STYLE_BORDER_NONE,
1734 style_color_black (), gnm_style_border_get_orientation (i));
1735 else
1736 borders[i] = NULL;
1738 cmd_selection_format (GNM_WBC (wbcg), NULL, borders,
1739 add ? _("Add Borders") : _("Remove borders"));
1742 static GNM_ACTION_DEF (cb_format_add_borders) { mutate_borders (wbcg, TRUE); }
1743 static GNM_ACTION_DEF (cb_format_clear_borders) { mutate_borders (wbcg, FALSE); }
1745 static void
1746 modify_format (WBCGtk *wbcg,
1747 GOFormat *(*format_modify_fn) (GOFormat const *format),
1748 char const *descriptor)
1750 WorkbookControl *wbc = GNM_WBC (wbcg);
1751 WorkbookView const *wbv;
1752 GOFormat *new_fmt;
1754 wbv = wb_control_view (wbc);
1755 g_return_if_fail (wbv != NULL);
1756 g_return_if_fail (wbv->current_style != NULL);
1758 new_fmt = (*format_modify_fn) (gnm_style_get_format (wbv->current_style));
1759 if (new_fmt != NULL) {
1760 GnmStyle *style = gnm_style_new ();
1761 gnm_style_set_format (style, new_fmt);
1762 cmd_selection_format (wbc, style, NULL, descriptor);
1763 go_format_unref (new_fmt);
1767 static GnmValue *
1768 cb_calc_decs (GnmCellIter const *iter, gpointer user)
1770 int *pdecs = user;
1771 int decs = 0;
1772 GnmCell *cell = iter->cell;
1773 char *text;
1774 const char *p;
1775 GString const *dec = go_locale_get_decimal ();
1777 if (!cell || !cell->value || !VALUE_IS_NUMBER (cell->value))
1778 return NULL;
1781 * If we are displaying an equation, we don't want to look into
1782 * the rendered text.
1784 if (gnm_cell_has_expr (cell) && cell->base.sheet->display_formulas)
1785 return NULL;
1787 text = gnm_cell_get_rendered_text (cell);
1788 p = strstr (text, dec->str);
1789 if (p) {
1790 p += dec->len;
1792 while (g_ascii_isdigit (*p))
1793 decs++, p++;
1796 *pdecs = MAX (*pdecs, decs);
1798 g_free (text);
1800 return NULL;
1803 static void
1804 inc_dec (WBCGtk *wbcg,
1805 int dir,
1806 GOFormat *(*format_modify_fn) (GOFormat const *format),
1807 char const *descriptor)
1809 WorkbookControl *wbc = GNM_WBC (wbcg);
1810 WorkbookView *wbv = wb_control_view (wbc);
1811 GOFormat const *fmt = gnm_style_get_format (wbv->current_style);
1812 SheetView *sv;
1813 GOFormat *new_fmt;
1814 GnmStyle *style;
1815 GSList *l;
1816 int decs = -2;
1817 GString *new_fmt_str;
1819 if (!go_format_is_general (fmt)) {
1820 modify_format (wbcg, format_modify_fn, descriptor);
1821 return;
1824 sv = wb_view_cur_sheet_view (wbv);
1825 if (!sv)
1826 return;
1828 for (l = sv->selections; l ; l = l->next) {
1829 GnmRange const *r = l->data;
1830 sheet_foreach_cell_in_range (sv_sheet (sv),
1831 CELL_ITER_IGNORE_BLANK |
1832 CELL_ITER_IGNORE_HIDDEN,
1833 r->start.col, r->start.row,
1834 r->end.col, r->end.row,
1835 cb_calc_decs,
1836 &decs);
1839 new_fmt_str = g_string_new ("0");
1840 if (decs + dir > 0) {
1841 g_string_append_c (new_fmt_str, '.');
1842 go_string_append_c_n (new_fmt_str, '0', decs + dir);
1844 new_fmt = go_format_new_from_XL (new_fmt_str->str);
1845 g_string_free (new_fmt_str, TRUE);
1847 style = gnm_style_new ();
1848 gnm_style_set_format (style, new_fmt);
1849 cmd_selection_format (wbc, style, NULL, descriptor);
1850 go_format_unref (new_fmt);
1853 static GNM_ACTION_DEF (cb_format_inc_precision)
1854 { inc_dec (wbcg, 1,
1855 &go_format_inc_precision, _("Increase precision")); }
1856 static GNM_ACTION_DEF (cb_format_dec_precision)
1857 { inc_dec (wbcg, -1,
1858 &go_format_dec_precision, _("Decrease precision")); }
1859 static GNM_ACTION_DEF (cb_format_with_thousands)
1860 { modify_format (wbcg, &go_format_toggle_1000sep, _("Toggle thousands separator")); }
1862 static GNM_ACTION_DEF (cb_format_dec_indent) { workbook_cmd_dec_indent (GNM_WBC (wbcg)); }
1863 static GNM_ACTION_DEF (cb_format_inc_indent) { workbook_cmd_inc_indent (GNM_WBC (wbcg)); }
1865 static GNM_ACTION_DEF (cb_copydown)
1867 WorkbookControl *wbc = GNM_WBC (wbcg);
1868 cmd_copyrel (wbc, 0, -1, _("Copy down"));
1871 static GNM_ACTION_DEF (cb_copyright)
1873 WorkbookControl *wbc = GNM_WBC (wbcg);
1874 /* xgettext: copy from the cell to the left into current cell --
1875 this has nothing whatsoever to do with copyright. */
1876 cmd_copyrel (wbc, -1, 0, _("Copy right"));
1879 static GNM_ACTION_DEF (cb_format_cells_auto_fit_height)
1881 WorkbookControl *wbc = GNM_WBC (wbcg);
1882 workbook_cmd_autofit_selection
1883 (wbc, wb_control_cur_sheet (wbc), FALSE);
1886 static GNM_ACTION_DEF (cb_format_cells_auto_fit_width)
1888 WorkbookControl *wbc = GNM_WBC (wbcg);
1889 workbook_cmd_autofit_selection
1890 (wbc, wb_control_cur_sheet (wbc), TRUE);
1893 static GNM_ACTION_DEF (cb_format_column_auto_fit)
1895 WorkbookControl *wbc = GNM_WBC (wbcg);
1896 workbook_cmd_resize_selected_colrow (wbc,
1897 wb_control_cur_sheet (wbc), TRUE, -1);
1899 static GNM_ACTION_DEF (cb_set_column_width)
1901 dialog_col_width (wbcg, FALSE);
1903 static GNM_ACTION_DEF (cb_format_column_std_width)
1905 dialog_col_width (wbcg, TRUE);
1907 static GNM_ACTION_DEF (cb_format_column_hide)
1909 cmd_selection_colrow_hide (GNM_WBC (wbcg), TRUE, FALSE);
1911 static GNM_ACTION_DEF (cb_format_column_unhide)
1913 cmd_selection_colrow_hide (GNM_WBC (wbcg), TRUE, TRUE);
1916 static GNM_ACTION_DEF (cb_format_row_auto_fit)
1918 WorkbookControl *wbc = GNM_WBC (wbcg);
1919 workbook_cmd_resize_selected_colrow (wbc,
1920 wb_control_cur_sheet (wbc), FALSE, -1);
1922 static GNM_ACTION_DEF (cb_set_row_height)
1924 dialog_row_height (wbcg, FALSE);
1926 static GNM_ACTION_DEF (cb_format_row_std_height)
1928 dialog_row_height (wbcg, TRUE);
1930 static GNM_ACTION_DEF (cb_format_row_hide)
1932 cmd_selection_colrow_hide (GNM_WBC (wbcg), FALSE, FALSE);
1934 static GNM_ACTION_DEF (cb_format_row_unhide)
1936 cmd_selection_colrow_hide (GNM_WBC (wbcg), FALSE, TRUE);
1939 static GNM_ACTION_DEF (cb_file_menu)
1941 wbc_gtk_load_templates (wbcg);
1944 static GNM_ACTION_DEF (cb_insert_menu)
1946 GtkAction *action = wbcg_find_action (wbcg, "MenuInsertObject");
1947 SheetControlGUI *scg = wbcg_cur_scg (wbcg);
1948 gtk_action_set_sensitive (action, go_components_get_mime_types () != NULL && scg && scg_sheet (scg)->sheet_type == GNM_SHEET_DATA);
1951 #define TOGGLE_HANDLER(flag,property) \
1952 static GNM_ACTION_DEF (cb_sheet_pref_ ## flag ) \
1954 g_return_if_fail (GNM_IS_WBC_GTK (wbcg)); \
1956 if (!wbcg->updating_ui) { \
1957 Sheet *sheet = wbcg_cur_sheet (wbcg); \
1958 go_object_toggle (sheet, property); \
1959 sheet_update (sheet); \
1963 TOGGLE_HANDLER (display_formulas, "display-formulas")
1964 TOGGLE_HANDLER (hide_zero, "display-zeros")
1965 TOGGLE_HANDLER (hide_grid, "display-grid")
1966 TOGGLE_HANDLER (hide_col_header, "display-column-header")
1967 TOGGLE_HANDLER (hide_row_header, "display-row-header")
1968 TOGGLE_HANDLER (display_outlines, "display-outlines")
1969 TOGGLE_HANDLER (outline_symbols_below, "display-outlines-below")
1970 TOGGLE_HANDLER (outline_symbols_right, "display-outlines-right")
1971 TOGGLE_HANDLER (use_r1c1, "use-r1c1")
1973 /* Actions that are always sensitive */
1974 static GnmActionEntry const permanent_actions[] = {
1975 { .name = "MenuFile",
1976 .label = N_("_File"),
1977 .callback = G_CALLBACK (cb_file_menu)
1979 { .name = "MenuFileNewFromTemplate",
1980 .icon = "document-new",
1981 .label = N_("New From Template")
1983 { .name = "FileNew",
1984 .icon = "document-new",
1985 .label = N_("_New"),
1986 .accelerator = "<control>n",
1987 .tooltip = N_("Create a new workbook"),
1988 .callback = G_CALLBACK (cb_file_new)
1990 { .name = "FileOpen",
1991 .icon = "document-open",
1992 .label = GNM_N_STOCK_OPEN,
1993 .label_context = GNM_STOCK_LABEL_CONTEXT,
1994 .accelerator = "<control>o",
1995 .tooltip = N_("Open a file"),
1996 .callback = G_CALLBACK (cb_file_open)
1998 { .name = "FileSave",
1999 .icon = "document-save",
2000 .label = GNM_N_STOCK_SAVE,
2001 .label_context = GNM_STOCK_LABEL_CONTEXT,
2002 .accelerator = "<control>s",
2003 .tooltip = N_("Save the current workbook"),
2004 .callback = G_CALLBACK (cb_file_save)
2006 { .name = "FileSaveAs",
2007 .icon = "document-save-as",
2008 .label = GNM_N_STOCK_SAVE_AS,
2009 .label_context = GNM_STOCK_LABEL_CONTEXT,
2010 .accelerator = "<control><shift>s",
2011 .tooltip = N_("Save the current workbook with a different name"),
2012 .callback = G_CALLBACK (cb_file_save_as)
2014 { .name = "FileSend",
2015 .icon = "gnumeric-link-email",
2016 .label = N_("Sen_d To..."),
2017 .tooltip = N_("Send the current file via email"),
2018 .callback = G_CALLBACK (cb_file_sendto)
2020 { .name = "FilePageSetup",
2021 .icon = "document-page-setup",
2022 .label = N_("Page Set_up..."),
2023 .tooltip = N_("Setup the page settings for your current printer"),
2024 .callback = G_CALLBACK (cb_file_page_setup)
2026 { .name = "FilePrintPreview",
2027 .icon = "document-print-preview",
2028 .label = N_("Print Pre_view"),
2029 .tooltip = N_("Print preview"),
2030 .callback = G_CALLBACK (cb_file_print_preview)
2032 { .name = "FilePrint",
2033 .icon = "document-print",
2034 .label = N_("Print"),
2035 .accelerator = "<control>p",
2036 .tooltip = N_("Print the current file"),
2037 .callback = G_CALLBACK (cb_file_print)
2039 { .name = "FilePrintArea",
2040 .label = N_("Print Area & Breaks")
2042 { .name = "FileHistoryFull",
2043 .label = N_("Full _History..."),
2044 .tooltip = N_("Access previously used file"),
2045 .callback = G_CALLBACK (cb_file_history_full)
2047 { .name = "FileClose",
2048 .icon = "window-close",
2049 .label = N_("_Close"),
2050 .accelerator = "<control>w",
2051 .tooltip = N_("Close the current file"),
2052 .callback = G_CALLBACK (cb_file_close)
2054 { .name = "FileQuit",
2055 .icon = "application-exit",
2056 .label = N_("_Quit"),
2057 .accelerator = "<control>q",
2058 .tooltip = N_("Quit the application"),
2059 .callback = G_CALLBACK (cb_file_quit)
2061 /* ---------------------------------------- */
2062 { .name = "MenuEdit",
2063 .label = N_("_Edit")
2065 { .name = "MenuEditClear",
2066 .icon = "edit-clear",
2067 .label = N_("C_lear")
2069 { .name = "MenuEditDelete",
2070 .icon = "edit-delete",
2071 .label = N_("_Delete")
2073 { .name = "MenuEditItems",
2074 .label = N_("_Modify")
2076 { .name = "MenuEditSheet",
2077 .label = N_("S_heet")
2079 { .name = "MenuEditSelect",
2080 .label = N_("_Select")
2083 { .name = "EditCopy",
2084 .icon = "edit-copy",
2085 .label = N_("_Copy"),
2086 .accelerator = "<control>c",
2087 .tooltip = N_("Copy the selection"),
2088 .callback = G_CALLBACK (cb_edit_copy)
2091 /* ---------------------------------------- */
2092 { .name = "MenuView",
2093 .label = N_("_View")
2095 { .name = "MenuViewWindows",
2096 .label = N_("_Windows")
2098 { .name = "MenuViewToolbars",
2099 .label = N_("_Toolbars")
2101 /* ---------------------------------------- */
2102 { .name = "MenuInsert",
2103 .label = N_("_Insert"),
2104 .callback = G_CALLBACK (cb_insert_menu)
2106 { .name = "MenuInsertObject",
2107 .label = N_("_Object")
2109 { .name = "MenuInsertSpecial",
2110 .label = N_("S_pecial")
2112 { .name = "MenuInsertFormulaWrap",
2113 .icon = "gnumeric-formulaguru",
2114 .label = N_("Func_tion Wrapper")
2116 { .name = "InsertNames",
2117 .label = N_("_Name..."),
2118 .accelerator = "F3",
2119 .tooltip = N_("Insert a defined name"),
2120 .callback = G_CALLBACK (cb_paste_names)
2122 /* ---------------------------------------- */
2123 { .name = "MenuFormat",
2124 .label = N_("F_ormat")
2126 { .name = "MenuFormatCells",
2127 .label = N_("_Cells")
2129 { .name = "MenuFormatText",
2130 .label = N_("_Text")
2132 { .name = "MenuFormatTextUnderline",
2133 .label = N_("_Underline")
2135 { .name = "MenuFormatColumn",
2136 .label = N_("C_olumn")
2138 { .name = "MenuFormatRow",
2139 .label = N_("_Row")
2141 { .name = "MenuFormatSheet",
2142 .label = N_("_Sheet")
2144 /* ---------------------------------------- */
2145 { .name = "MenuTools",
2146 .label = N_("_Tools")
2148 { .name = "MenuToolsScenarios",
2149 .label = N_("Sce_narios")
2151 /* ---------------------------------------- */
2152 { .name = "MenuStatistics",
2153 .label = N_("_Statistics")
2155 { .name = "MenuStatisticsDescriptive",
2156 .label = N_("_Descriptive Statistics")
2158 { .name = "MenuToolFrequencies",
2159 .label = N_("Fre_quency Tables")
2161 { .name = "MenuStatisticsTimeSeries",
2162 .label = N_("De_pendent Observations")
2164 { .name = "MenuToolForecast",
2165 .label = N_("F_orecast")
2167 { .name = "MenuStatisticsOneSample",
2168 .label = N_("_One Sample Tests")
2170 { .name = "MenuToolOneMedian",
2171 .label = N_("Claims About a Me_dian")
2173 { .name = "MenuStatisticsTwoSamples",
2174 .label = N_("_Two Sample Tests")
2176 { .name = "MenuToolTwoMedians",
2177 .label = N_("Claims About Two Me_dians")
2179 { .name = "MenuToolTTest",
2180 .label = N_("Claims About Two _Means")
2182 { .name = "MenuStatisticsMultipleSamples",
2183 .label = N_("_Multiple Sample Tests")
2185 { .name = "MenuANOVA",
2186 .label = N_("_ANOVA")
2188 { .name = "MenuContingencyTests",
2189 .label = N_("Contin_gency Table")
2191 /* ---------------------------------------- */
2192 { .name = "MenuData",
2193 .label = N_("_Data")
2195 { .name = "MenuFilter",
2196 .label = N_("_Filter")
2198 { .name = "MenuEditFill",
2199 .label = N_("F_ill")
2201 { .name = "MenuRandomGenerator",
2202 .label = N_("_Random Generators")
2204 { .name = "MenuOutline",
2205 .label = N_("_Group and Outline")
2207 { .name = "MenuExternalData",
2208 .label = N_("Import _Data")
2210 { .name = "MenuExportData",
2211 .label = N_("E_xport Data")
2213 { .name = "MenuSlicer",
2214 .label = N_("Data S_licer")
2216 /* ---------------------------------------- */
2217 { .name = "MenuHelp",
2218 .label = N_("_Help")
2221 { .name = "HelpDocs",
2222 .icon = "help-browser",
2223 .label = N_("_Contents"),
2224 .accelerator = "F1",
2225 .tooltip = N_("Open a viewer for Gnumeric's documentation"),
2226 .callback = G_CALLBACK (cb_help_docs)
2228 { .name = "HelpFunctions",
2229 .icon = "gnumeric-formulaguru",
2230 .label = N_("_Functions"),
2231 .tooltip = N_("Functions help"),
2232 .callback = G_CALLBACK (cb_help_function)
2234 { .name = "HelpWeb",
2235 .label = N_("Gnumeric on the _Web"),
2236 .tooltip = N_("Browse to Gnumeric's website"),
2237 .callback = G_CALLBACK (cb_help_web)
2239 { .name = "HelpIRC",
2240 .label = N_("_Live Assistance"),
2241 .tooltip = N_("See if anyone is available to answer questions"),
2242 .callback = G_CALLBACK (cb_help_irc)
2244 { .name = "HelpBug",
2245 .label = N_("Report a _Problem"),
2246 .tooltip = N_("Report problem"),
2247 .callback = G_CALLBACK (cb_help_bug)
2249 { .name = "HelpAbout",
2250 .icon = "help-about",
2251 .label = N_("_About"),
2252 .tooltip = N_("About this application"),
2253 .callback = G_CALLBACK (cb_help_about)
2257 /* actions that are sensitive only in data sheets */
2258 static GnmActionEntry const data_only_actions[] = {
2259 { .name = "EditCut",
2260 .icon = "edit-cut",
2261 .label = N_("Cu_t"),
2262 .accelerator = "<control>x",
2263 .tooltip = N_("Cut the selection"),
2264 .callback = G_CALLBACK (cb_edit_cut)
2266 { .name = "EditPaste",
2267 .icon = "edit-paste",
2268 .label = N_("_Paste"),
2269 .accelerator = "<control>v",
2270 .tooltip = N_("Paste the clipboard"),
2271 .callback = G_CALLBACK (cb_edit_paste)
2275 #define FULLSCREEN_ACCEL "F11"
2277 static GnmActionEntry const semi_permanent_actions[] = {
2278 /* Edit -> Sheet */
2279 { .name = "SheetReorder",
2280 .label = N_("_Manage Sheets..."),
2281 .tooltip = N_("Manage the sheets in this workbook"),
2282 .callback = G_CALLBACK (cb_sheet_order)
2284 { .name = "InsertSheet",
2285 .label = N_("_Insert"),
2286 .tooltip = N_("Insert a new sheet"),
2287 .callback = G_CALLBACK (wbcg_insert_sheet)
2289 /* ICK A DUPLICATE : we have no way to override a label on one proxy */
2290 { .name = "SheetInsert",
2291 .label = N_("_Sheet"),
2292 .tooltip = N_("Insert a new sheet"),
2293 .callback = G_CALLBACK (wbcg_insert_sheet)
2295 { .name = "InsertSheetAtEnd",
2296 .label = N_("_Append"),
2297 .tooltip = N_("Append a new sheet"),
2298 .callback = G_CALLBACK (wbcg_append_sheet)
2300 { .name = "EditDuplicateSheet",
2301 .label = N_("_Duplicate"),
2302 .tooltip = N_("Make a copy of the current sheet"),
2303 .callback = G_CALLBACK (wbcg_clone_sheet)
2305 { .name = "SheetRemove",
2306 .label = N_("_Remove"),
2307 .tooltip = N_("Irrevocably remove an entire sheet"),
2308 .callback = G_CALLBACK (cb_sheet_remove)
2310 { .name = "SheetChangeName",
2311 .label = N_("Re_name..."),
2312 .tooltip = N_("Rename the current sheet"),
2313 .callback = G_CALLBACK (cb_sheet_name)
2315 { .name = "SheetResize",
2316 .label = N_("Resize..."),
2317 .tooltip = N_("Change the size of the current sheet"),
2318 .callback = G_CALLBACK (cb_sheet_resize)
2321 /* View */
2322 { .name = "ViewNew",
2323 .icon = "document-new",
2324 .label = N_("_New View..."),
2325 .tooltip = N_("Create a new view of the workbook"),
2326 .callback = G_CALLBACK (cb_view_new)
2329 /* Format */
2330 { .name = "FormatWorkbook",
2331 .icon = "document-properties",
2332 .label = N_("View _Properties..."),
2333 .tooltip = N_("Modify the view properties"),
2334 .callback = G_CALLBACK (cb_workbook_attr)
2337 { .name = "ViewStatusbar",
2338 .toggle = TRUE,
2339 .label = N_("View _Statusbar"),
2340 .tooltip = N_("Toggle visibility of statusbar"),
2341 .callback = G_CALLBACK (cb_view_statusbar),
2342 .is_active = TRUE
2345 { .name = "ViewFullScreen",
2346 .toggle = TRUE,
2347 .icon = "view-fullscreen",
2348 .label = N_("F_ull Screen"),
2349 .accelerator = FULLSCREEN_ACCEL,
2350 .tooltip = N_("Switch to or from full screen mode"),
2351 .callback = G_CALLBACK (cb_view_fullscreen)
2355 #define ZOOM_IN_ACCEL NULL
2356 #define ZOOM_OUT_ACCEL NULL
2358 static GnmActionEntry const actions[] = {
2359 /* File */
2360 { .name = "FileMetaData",
2361 .icon = "document-properties",
2362 .label = N_("Document Proper_ties..."),
2363 .tooltip = N_("Edit document properties"),
2364 .callback = G_CALLBACK (cb_doc_meta_data)
2367 /* File->PrintArea */
2368 { .name = "FilePrintAreaSet",
2369 .label = N_("Set Print Area"),
2370 .tooltip = N_("Use the current selection as print area"),
2371 .callback = G_CALLBACK (cb_file_print_area_set)
2373 { .name = "FilePrintAreaClear",
2374 .label = N_("Clear Print Area"),
2375 .tooltip = N_("Undefine the print area"),
2376 .callback = G_CALLBACK (cb_file_print_area_clear)
2378 { .name = "FilePrintAreaShow",
2379 .label = N_("Show Print Area"),
2380 .tooltip = N_("Select the print area"),
2381 .callback = G_CALLBACK (cb_file_print_area_show)
2383 { .name = "FilePrintAreaToggleColPageBreak",
2384 .label = N_("Set Column Page Break"),
2385 .tooltip = N_("Split the page to the left of this column"),
2386 .callback = G_CALLBACK (cb_file_print_area_toggle_col)
2388 { .name = "FilePrintAreaToggleRowPageBreak",
2389 .label = N_("Set Row Page Break"),
2390 .tooltip = N_("Split the page above this row"),
2391 .callback = G_CALLBACK (cb_file_print_area_toggle_row)
2393 { .name = "FilePrintAreaClearAllPageBreak",
2394 .label = N_("Clear All Page Breaks"),
2395 .tooltip = N_("Remove all manual pagebreaks from this sheet"),
2396 .callback = G_CALLBACK (cb_file_print_area_clear_pagebreaks)
2399 /* Edit -> Clear */
2400 { .name = "EditClearAll",
2401 .icon = "edit-clear",
2402 .label = N_("_All"),
2403 .tooltip = N_("Clear the selected cells' formats, comments, and contents"),
2404 .callback = G_CALLBACK (cb_edit_clear_all)
2406 { .name = "EditClearFormats",
2407 .label = N_("_Formats & Hyperlinks"),
2408 .tooltip = N_("Clear the selected cells' formats and hyperlinks"),
2409 .callback = G_CALLBACK (cb_edit_clear_formats)
2411 { .name = "EditClearComments",
2412 .icon = "gnumeric-comment-delete",
2413 .label = N_("Co_mments"),
2414 .tooltip = N_("Delete the selected cells' comments"),
2415 .callback = G_CALLBACK (cb_edit_clear_comments)
2417 { .name = "EditClearContent",
2418 .icon = "edit-clear",
2419 .label = N_("_Contents"),
2420 .tooltip = N_("Clear the selected cells' contents"),
2421 .callback = G_CALLBACK (cb_edit_clear_content)
2423 { .name = "EditClearAllFiltered",
2424 .icon = "edit-clear",
2425 .label = N_("A_ll Filtered Rows"),
2426 .tooltip = N_("Clear the selected cells' formats, comments, and contents in the filtered rows"),
2427 .callback = G_CALLBACK (cb_edit_clear_all_filtered)
2429 { .name = "EditClearFormatsFiltered",
2430 .label = N_("F_ormats & Hyperlinks in Filtered Rows"),
2431 .tooltip = N_("Clear the selected cells' formats and hyperlinks in the filtered rows"),
2432 .callback = G_CALLBACK (cb_edit_clear_formats_filtered)
2434 { .name = "EditClearCommentsFiltered",
2435 .icon = "gnumeric-comment-delete",
2436 .label = N_("Comme_nts in Filtered Rows"),
2437 .tooltip = N_("Delete the selected cells' comments in the filtered rows"),
2438 .callback = G_CALLBACK (cb_edit_clear_comments_filtered)
2440 { .name = "EditClearContentFiltered",
2441 .icon = "edit-clear",
2442 .label = N_("Content_s of Filtered Rows"),
2443 .tooltip = N_("Clear the selected cells' contents in the filtered rows"),
2444 .callback = G_CALLBACK (cb_edit_clear_content_filtered)
2447 /* Edit -> Delete */
2448 /*Translators: Delete "Rows"*/
2449 { .name = "EditDeleteRows",
2450 .icon = "gnumeric-row-delete",
2451 .label = N_("_Rows"),
2452 .tooltip = N_("Delete the row(s) containing the selected cells"),
2453 .callback = G_CALLBACK (cb_edit_delete_rows)
2455 /*Translators: Delete "Columns"*/
2456 { .name = "EditDeleteColumns",
2457 .icon = "gnumeric-column-delete",
2458 .label = N_("_Columns"),
2459 .tooltip = N_("Delete the column(s) containing the selected cells"),
2460 .callback = G_CALLBACK (cb_edit_delete_columns)
2462 { .name = "EditDeleteCells",
2463 .label = N_("C_ells..."),
2464 .accelerator = "<control>minus",
2465 .tooltip = N_("Delete the selected cells, shifting others into their place"),
2466 .callback = G_CALLBACK (cb_edit_delete_cells)
2468 { .name = "EditClearHyperlinks",
2469 .icon = "gnumeric-link-delete",
2470 .label = N_("_Hyperlinks"),
2471 .tooltip = N_("Delete the selected cells' hyperlinks"),
2472 .callback = G_CALLBACK (cb_edit_delete_links)
2474 /* A duplicate that should not go into the menus, used only for the accelerator */
2475 { .name = "EditDeleteCellsXL",
2476 .label = N_("C_ells..."),
2477 .accelerator = "<control>KP_Subtract",
2478 .tooltip = N_("Delete the selected cells, shifting others into their place"),
2479 .callback = G_CALLBACK (cb_edit_delete_cells)
2482 /* Edit -> Select */
2484 /* Note : The accelerators involving space are just for display
2485 * purposes. We actually handle this in
2486 * gnm-pane.c:gnm_pane_key_mode_sheet
2487 * with the rest of the key movement and rangeselection.
2488 * Otherwise input methods would steal them */
2489 { .name = "EditSelectAll",
2490 .label = N_("_All"),
2491 .accelerator = "<control><shift>space",
2492 .tooltip = N_("Select all cells in the spreadsheet"),
2493 .callback = G_CALLBACK (cb_edit_select_all)
2495 { .name = "EditSelectColumn",
2496 .label = N_("_Column"),
2497 .accelerator = "<control>space",
2498 .tooltip = N_("Select an entire column"),
2499 .callback = G_CALLBACK (cb_edit_select_col)
2501 { .name = "EditSelectRow",
2502 .label = N_("_Row"),
2503 .accelerator = "<shift>space",
2504 .tooltip = N_("Select an entire row"),
2505 .callback = G_CALLBACK (cb_edit_select_row)
2508 { .name = "EditSelectArray",
2509 .label = N_("Arra_y"),
2510 .accelerator = "<control>slash",
2511 .tooltip = N_("Select an array of cells"),
2512 .callback = G_CALLBACK (cb_edit_select_array)
2514 { .name = "EditSelectDepends",
2515 .label = N_("_Depends"),
2516 .accelerator = "<control>bracketright",
2517 .tooltip = N_("Select all the cells that depend on the current edit cell"),
2518 .callback = G_CALLBACK (cb_edit_select_depends)
2520 { .name = "EditSelectInputs",
2521 .label = N_("_Inputs"),
2522 .accelerator = "<control>bracketleft",
2523 .tooltip = N_("Select all the cells are used by the current edit cell"),
2524 .callback = G_CALLBACK (cb_edit_select_inputs)
2527 { .name = "EditSelectObject",
2528 .label = N_("Next _Object"),
2529 .accelerator = "<control>Tab",
2530 .tooltip = N_("Select the next sheet object"),
2531 .callback = G_CALLBACK (cb_edit_select_object)
2534 { .name = "EditGotoTop",
2535 .icon = "go-top",
2536 .label = N_("Go to Top"),
2537 .tooltip = N_("Go to the top of the data"),
2538 .callback = G_CALLBACK (cb_edit_goto_top)
2540 { .name = "EditGotoBottom",
2541 .icon = "go-bottom",
2542 .label = N_("Go to Bottom"),
2543 .tooltip = N_("Go to the bottom of the data"),
2544 .callback = G_CALLBACK (cb_edit_goto_bottom)
2546 { .name = "EditGotoFirst",
2547 .icon = "go-first",
2548 .label = N_("Go to First"),
2549 .tooltip = N_("Go to the first data cell"),
2550 .callback = G_CALLBACK (cb_edit_goto_first)
2552 { .name = "EditGotoLast",
2553 .icon = "go-last",
2554 .label = N_("Go to Last"),
2555 .tooltip = N_("Go to the last data cell"),
2556 .callback = G_CALLBACK (cb_edit_goto_last)
2558 { .name = "EditGoto",
2559 .icon = "go-jump",
2560 .label = N_("_Go to Cell..."),
2561 .accelerator = "<control>g",
2562 .tooltip = N_("Jump to a specified cell"),
2563 .callback = G_CALLBACK (cb_edit_goto)
2565 /* This is a navigational aid that is not supposed to appear */
2566 /* in the menu */
2567 { .name = "EditGotoCellIndicator",
2568 .label = N_("Go to Current Cell Indicator"),
2569 .accelerator = "<shift><control>g",
2570 .tooltip = N_("Go to Current Cell Indicator"),
2571 .callback = G_CALLBACK (cb_edit_goto_cell_indicator)
2574 /* Edit */
2575 { .name = "Repeat",
2576 .label = N_("Repeat"),
2577 .accelerator = "F4",
2578 .tooltip = N_("Repeat the previous action"),
2579 .callback = G_CALLBACK (cb_repeat)
2581 { .name = "EditPasteSpecial",
2582 .icon = "edit-paste",
2583 .label = N_("P_aste Special..."),
2584 .accelerator = "<shift><control>v",
2585 .tooltip = N_("Paste with optional filters and transformations"),
2586 .callback = G_CALLBACK (cb_edit_paste_special)
2589 { .name = "EditComment",
2590 .icon = "gnumeric-comment-edit",
2591 .label = N_("Co_mment..."),
2592 .tooltip = N_("Edit the selected cell's comment"),
2593 .callback = G_CALLBACK (cb_insert_comment)
2595 { .name = "EditHyperlink",
2596 .icon = "gnumeric-link-edit",
2597 .label = N_("Hyper_link..."),
2598 .accelerator = "<control>K",
2599 .tooltip = N_("Edit the selected cell's hyperlink"),
2600 .callback = G_CALLBACK (cb_insert_hyperlink)
2602 #if 0
2603 { .name = "EditGenerateName",
2604 .label = N_("_Auto generate names..."),
2605 .tooltip = N_("Use the current selection to create names"),
2606 .callback = G_CALLBACK (cb_auto_generate__named_expr)
2608 #endif
2610 { .name = "EditFind",
2611 .icon = "edit-find",
2612 .label = N_("S_earch..."),
2613 .accelerator = "<control>f",
2614 .tooltip = N_("Search for something"),
2615 .callback = G_CALLBACK (cb_edit_search)
2617 { .name = "EditReplace",
2618 .icon = "edit-find-replace",
2619 .label = N_("Search _& Replace..."),
2620 .accelerator = "<control>h",
2621 .tooltip = N_("Search for something and replace it with something else"),
2622 .callback = G_CALLBACK (cb_edit_search_replace)
2625 { .name = "EditRecalc",
2626 .label = N_("Recalculate"),
2627 .accelerator = "F9",
2628 .tooltip = N_("Recalculate the spreadsheet"),
2629 .callback = G_CALLBACK (cb_edit_recalc)
2632 { .name = "EditPreferences",
2633 .icon = "preferences-system",
2634 .label = N_("Preferences..."),
2635 .tooltip = N_("Change Gnumeric Preferences"),
2636 .callback = G_CALLBACK (cb_file_preferences)
2639 /* View */
2640 { .name = "ViewFreezeThawPanes",
2641 .label = N_("_Freeze Panes"),
2642 .tooltip = N_("Freeze the top left of the sheet"),
2643 .callback = G_CALLBACK (cb_view_freeze_panes)
2645 { .name = "ViewZoom",
2646 .icon = "zoom-fit-best", /* dubious */
2647 .label = N_("_Zoom..."),
2648 .tooltip = N_("Zoom the spreadsheet in or out"),
2649 .callback = G_CALLBACK (cb_view_zoom)
2651 { .name = "ViewZoomIn",
2652 .icon = "zoom-in",
2653 .label = N_("Zoom _In"),
2654 .accelerator = ZOOM_IN_ACCEL,
2655 .tooltip = N_("Increase the zoom to make things larger"),
2656 .callback = G_CALLBACK (cb_view_zoom_in)
2658 { .name = "ViewZoomOut",
2659 .icon = "zoom-out",
2660 .label = N_("Zoom _Out"),
2661 .accelerator = ZOOM_OUT_ACCEL,
2662 .tooltip = N_("Decrease the zoom to make things smaller"),
2663 .callback = G_CALLBACK (cb_view_zoom_out)
2666 /* Insert */
2667 { .name = "InsertCells",
2668 .label = N_("C_ells..."),
2669 .accelerator = "<control>plus",
2670 .tooltip = N_("Insert new cells"),
2671 .callback = G_CALLBACK (cb_insert_cells)
2673 /* A duplicate that should not go into the menus, used only for the accelerator */
2674 { .name = "InsertCellsXL",
2675 .label = N_("C_ells..."),
2676 .accelerator = "<control>KP_Add",
2677 .tooltip = N_("Insert new cells"),
2678 .callback = G_CALLBACK (cb_insert_cells)
2680 /*Translators: Insert "Columns"*/
2681 { .name = "InsertColumns",
2682 .icon = "gnumeric-column-add",
2683 .label = N_("_Columns"),
2684 .tooltip = N_("Insert new columns"),
2685 .callback = G_CALLBACK (cb_insert_cols)
2687 /*Translators: Insert "Rows"*/
2688 { .name = "InsertRows",
2689 .icon = "gnumeric-row-add",
2690 .label = N_("_Rows"),
2691 .tooltip = N_("Insert new rows"),
2692 .callback = G_CALLBACK (cb_insert_rows)
2695 { .name = "ChartGuru",
2696 .icon = "gnumeric-graphguru",
2697 .label = N_("C_hart..."),
2698 .tooltip = N_("Insert a Chart"),
2699 .callback = G_CALLBACK (cb_launch_chart_guru)
2701 { .name = "NewGOComponent",
2702 .icon = "New Goffice_Component",
2703 .label = N_("_New..."),
2704 .tooltip = N_("Insert a new Goffice component object"),
2705 .callback = G_CALLBACK (cb_launch_go_component_new)
2707 { .name = "GOComponentFromFile",
2708 .icon = "New Goffice_Component from a file",
2709 .label = N_("_From File..."),
2710 .tooltip = N_("Insert a new Goffice component object from a file"),
2711 .callback = G_CALLBACK (cb_launch_go_component_from_file)
2713 { .name = "InsertImage",
2714 .icon = "insert-image",
2715 .label = N_("_Image..."),
2716 .tooltip = N_("Insert an image"),
2717 .callback = G_CALLBACK (cb_insert_image)
2720 { .name = "InsertComment",
2721 .icon = "gnumeric-comment-add",
2722 .label = N_("Co_mment..."),
2723 .tooltip = N_("Insert a comment"),
2724 .callback = G_CALLBACK (cb_insert_comment)
2726 { .name = "InsertHyperlink",
2727 .icon = "gnumeric-link-add",
2728 .label = N_("Hyper_link..."),
2729 .accelerator = "<control>K",
2730 .tooltip = N_("Insert a Hyperlink"),
2731 .callback = G_CALLBACK (cb_insert_hyperlink)
2733 { .name = "InsertSortDecreasing",
2734 .icon = "view-sort-descending",
2735 .label = N_("Sort (_Descending)"),
2736 .tooltip = N_("Wrap with SORT (descending)"),
2737 .callback = G_CALLBACK (cb_insert_sort_descending)
2739 { .name = "InsertSortIncreasing",
2740 .icon = "view-sort-ascending",
2741 .label = N_("Sort (_Ascending)"),
2742 .tooltip = N_("Wrap with SORT (ascending)"),
2743 .callback = G_CALLBACK (cb_insert_sort_ascending)
2746 /* Insert -> Special */
2747 { .name = "InsertCurrentDate",
2748 .label = N_("Current _Date"),
2749 .accelerator = "<control>semicolon",
2750 .tooltip = N_("Insert the current date into the selected cell(s)"),
2751 .callback = G_CALLBACK (cb_insert_current_date)
2754 { .name = "InsertCurrentTime",
2755 .label = N_("Current _Time"),
2756 .accelerator = "<control>colon",
2757 .tooltip = N_("Insert the current time into the selected cell(s)"),
2758 .callback = G_CALLBACK (cb_insert_current_time)
2761 { .name = "InsertCurrentDateTime",
2762 .label = N_("Current D_ate and Time"),
2763 .accelerator = "<control>period",
2764 .tooltip = N_("Insert the current date and time into the selected cell(s)"),
2765 .callback = G_CALLBACK (cb_insert_current_date_time)
2768 /* Insert -> Name */
2769 { .name = "EditNames",
2770 .label = N_("_Names..."),
2771 .accelerator = "<control>F3",
2772 .tooltip = N_("Edit defined names for expressions"),
2773 .callback = G_CALLBACK (cb_define_name)
2776 /* Format */
2777 { .name = "FormatAuto",
2778 .label = N_("_Autoformat..."),
2779 .tooltip = N_("Format a region of cells according to a pre-defined template"),
2780 .callback = G_CALLBACK (cb_autoformat)
2782 { .name = "SheetDirection",
2783 .icon = "format-text-direction-ltr",
2784 .label = N_("Direction"),
2785 .tooltip = N_("Toggle sheet direction, left-to-right vs right-to-left"),
2786 .callback = G_CALLBACK (cb_direction)
2789 /* Format -> Cells */
2790 { .name = "FormatCells",
2791 .label = N_("_Format..."),
2792 .accelerator = "<control>1",
2793 .tooltip = N_("Modify the formatting of the selected cells"),
2794 .callback = G_CALLBACK (cb_format_cells)
2796 { .name = "FormatCellsCond",
2797 .label = N_("_Conditional Formatting..."),
2798 .tooltip = N_("Modify the conditional formatting of the selected cells"),
2799 .callback = G_CALLBACK (cb_format_cells_cond)
2801 { .name = "FormatCellsFitHeight",
2802 .icon = "gnumeric-row-size",
2803 .label = N_("Auto Fit _Height"),
2804 .tooltip = N_("Ensure rows are just tall enough to display content of selection"),
2805 .callback = G_CALLBACK (cb_format_cells_auto_fit_height)
2807 { .name = "FormatCellsFitWidth",
2808 .icon = "gnumeric-column-size",
2809 .label = N_("Auto Fit _Width"),
2810 .tooltip = N_("Ensure columns are just wide enough to display content of selection"),
2811 .callback = G_CALLBACK (cb_format_cells_auto_fit_width)
2815 /* Format -> Col */
2816 { .name = "ColumnSize",
2817 .icon = "gnumeric-column-size",
2818 .label = N_("_Width..."),
2819 .tooltip = N_("Change width of the selected columns"),
2820 .callback = G_CALLBACK (cb_set_column_width)
2822 { .name = "ColumnAutoSize",
2823 .icon = "gnumeric-column-size",
2824 .label = N_("_Auto Fit Width"),
2825 .tooltip = N_("Ensure columns are just wide enough to display their content"),
2826 .callback = G_CALLBACK (cb_format_column_auto_fit)
2828 { .name = "ColumnHide",
2829 .icon = "gnumeric-column-hide",
2830 .label = N_("_Hide"),
2831 .accelerator = "<control>0",
2832 .tooltip = N_("Hide the selected columns"),
2833 .callback = G_CALLBACK (cb_format_column_hide)
2835 { .name = "ColumnUnhide",
2836 .icon = "gnumeric-column-unhide",
2837 .label = N_("_Unhide"),
2838 .accelerator = "<control>parenright",
2839 .tooltip = N_("Make any hidden columns in the selection visible"),
2840 .callback = G_CALLBACK (cb_format_column_unhide)
2842 { .name = "ColumnDefaultSize",
2843 .icon = "gnumeric-column-size",
2844 .label = N_("_Standard Width"),
2845 .tooltip = N_("Change the default column width"),
2846 .callback = G_CALLBACK (cb_format_column_std_width)
2849 /* Format -> Row */
2850 { .name = "RowSize",
2851 .icon = "gnumeric-row-size",
2852 .label = N_("H_eight..."),
2853 .tooltip = N_("Change height of the selected rows"),
2854 .callback = G_CALLBACK (cb_set_row_height)
2856 { .name = "RowAutoSize",
2857 .icon = "gnumeric-row-size",
2858 .label = N_("_Auto Fit Height"),
2859 .tooltip = N_("Ensure rows are just tall enough to display their content"),
2860 .callback = G_CALLBACK (cb_format_row_auto_fit)
2862 { .name = "RowHide",
2863 .icon = "gnumeric-row-hide",
2864 .label = N_("_Hide"),
2865 .accelerator = "<control>9",
2866 .tooltip = N_("Hide the selected rows"),
2867 .callback = G_CALLBACK (cb_format_row_hide)
2869 { .name = "RowUnhide",
2870 .icon = "gnumeric-row-unhide",
2871 .label = N_("_Unhide"),
2872 .accelerator = "<control>parenleft",
2873 .tooltip = N_("Make any hidden rows in the selection visible"),
2874 .callback = G_CALLBACK (cb_format_row_unhide)
2876 { .name = "RowDefaultSize",
2877 .icon = "gnumeric-row-size",
2878 .label = N_("_Standard Height"),
2879 .tooltip = N_("Change the default row height"),
2880 .callback = G_CALLBACK (cb_format_row_std_height)
2883 /* Tools */
2884 { .name = "ToolsPlugins",
2885 .label = N_("_Plug-ins..."),
2886 .tooltip = N_("Manage available plugin modules"),
2887 .callback = G_CALLBACK (cb_tools_plugins)
2889 { .name = "ToolsAutoCorrect",
2890 .label = N_("Auto _Correct..."),
2891 .tooltip = N_("Automatically perform simple spell checking"),
2892 .callback = G_CALLBACK (cb_tools_autocorrect)
2894 { .name = "ToolsAutoSave",
2895 .label = N_("_Auto Save..."),
2896 .tooltip = N_("Automatically save the current document at regular intervals"),
2897 .callback = G_CALLBACK (cb_tools_auto_save)
2899 { .name = "ToolsGoalSeek",
2900 .label = N_("_Goal Seek..."),
2901 .tooltip = N_("Iteratively recalculate to find a target value"),
2902 .callback = G_CALLBACK (cb_tools_goal_seek)
2904 { .name = "ToolsSolver",
2905 .label = N_("_Solver..."),
2906 .tooltip = N_("Iteratively recalculate with constraints to approach a target value"),
2907 .callback = G_CALLBACK (cb_tools_solver)
2909 { .name = "ToolsSimulation",
2910 .label = N_("Si_mulation..."),
2911 .tooltip = N_("Test decision alternatives by using Monte Carlo "
2912 "simulation to find out probable outputs and risks related to them"),
2913 .callback = G_CALLBACK (cb_tools_simulation)
2916 /* Tools -> Scenarios */
2917 { .name = "ToolsScenarios",
2918 .label = N_("_View..."),
2919 .tooltip = N_("View, delete and report different scenarios"),
2920 .callback = G_CALLBACK (cb_tools_scenarios)
2922 { .name = "ToolsScenarioAdd",
2923 .label = N_("_Add..."),
2924 .tooltip = N_("Add a new scenario"),
2925 .callback = G_CALLBACK (cb_tools_scenario_add)
2928 /* Statistics */
2930 { .name = "ToolsSampling",
2931 .label = N_("_Sampling..."),
2932 .tooltip = N_("Periodic and random samples"),
2933 .callback = G_CALLBACK (cb_tools_sampling)
2936 /* Statistics -> Descriptive*/
2938 { .name = "ToolsCorrelation",
2939 .label = N_("_Correlation..."),
2940 .tooltip = N_("Pearson Correlation"),
2941 .callback = G_CALLBACK (cb_tools_correlation)
2943 { .name = "ToolsCovariance",
2944 .label = N_("Co_variance..."),
2945 .tooltip = N_("Covariance"),
2946 .callback = G_CALLBACK (cb_tools_covariance)
2948 { .name = "ToolsDescStatistics",
2949 .label = N_("_Descriptive Statistics..."),
2950 .tooltip = N_("Various summary statistics"),
2951 .callback = G_CALLBACK (cb_tools_desc_statistics)
2954 /* Statistics -> Descriptive -> Frequencies */
2956 { .name = "ToolsFrequency",
2957 .label = N_("Fre_quency Tables..."),
2958 .tooltip = N_("Frequency tables for non-numeric data"),
2959 .callback = G_CALLBACK (cb_tools_frequency)
2961 { .name = "ToolsHistogram",
2962 .label = N_("_Histogram..."),
2963 .tooltip = N_("Various frequency tables for numeric data"),
2964 .callback = G_CALLBACK (cb_tools_histogram)
2966 { .name = "ToolsRanking",
2967 .label = N_("Ranks And _Percentiles..."),
2968 .tooltip = N_("Ranks, placements and percentiles"),
2969 .callback = G_CALLBACK (cb_tools_ranking)
2972 /* Statistics -> DependentObservations */
2974 { .name = "ToolsFourier",
2975 .label = N_("_Fourier Analysis..."),
2976 .tooltip = N_("Fourier Analysis"),
2977 .callback = G_CALLBACK (cb_tools_fourier)
2979 { .name = "ToolsPrincipalComponents",
2980 .label =
2981 N_("Principal Components Analysis..."),
2982 .tooltip = N_("Principal Components Analysis"),
2983 .callback = G_CALLBACK (cb_tools_principal_components)
2985 /* Statistics -> DependentObservations -> Forecast*/
2987 { .name = "ToolsExpSmoothing",
2988 .label = N_("_Exponential Smoothing..."),
2989 .tooltip = N_("Exponential smoothing..."),
2990 .callback = G_CALLBACK (cb_tools_exp_smoothing)
2992 { .name = "ToolsAverage",
2993 .label = N_("_Moving Average..."),
2994 .tooltip = N_("Moving average..."),
2995 .callback = G_CALLBACK (cb_tools_average)
2997 { .name = "ToolsRegression",
2998 .label = N_("_Regression..."),
2999 .tooltip = N_("Regression Analysis"),
3000 .callback = G_CALLBACK (cb_tools_regression)
3002 { .name = "ToolsKaplanMeier",
3003 .label = N_("_Kaplan-Meier Estimates..."),
3004 .tooltip = N_("Creation of Kaplan-Meier Survival Curves"),
3005 .callback = G_CALLBACK (cb_tools_kaplan_meier)
3008 /* Statistics -> OneSample */
3010 { .name = "ToolsNormalityTests",
3011 .label = N_("_Normality Tests..."),
3012 .tooltip = N_("Testing a sample for normality"),
3013 .callback = G_CALLBACK (cb_tools_normality_tests)
3015 { .name = "ToolsOneMeanTest",
3016 .label = N_("Claims About a _Mean..."),
3017 .tooltip = N_("Testing the value of a mean"),
3018 .callback = G_CALLBACK (cb_tools_one_mean_test)
3021 /* Statistics -> OneSample -> OneMedian*/
3023 { .name = "ToolsOneMedianSignTest",
3024 .label = N_("_Sign Test..."),
3025 .tooltip = N_("Testing the value of a median"),
3026 .callback = G_CALLBACK (cb_tools_sign_test_one_median)
3028 { .name = "ToolsOneMedianWilcoxonSignedRank",
3029 .label = N_("_Wilcoxon Signed Rank Test..."),
3030 .tooltip = N_("Testing the value of a median"),
3031 .callback = G_CALLBACK (cb_tools_wilcoxon_signed_rank_one_median)
3034 /* Statistics -> TwoSamples */
3036 { .name = "ToolsFTest",
3037 .label = N_("Claims About Two _Variances"),
3038 .tooltip = N_("Comparing two population variances"),
3039 .callback = G_CALLBACK (cb_tools_ftest)
3042 /* Statistics -> TwoSamples -> Two Means*/
3044 { .name = "ToolTTestPaired",
3045 .label = N_("_Paired Samples..."),
3046 .tooltip = N_("Comparing two population means for two paired samples"),
3047 .callback = G_CALLBACK (cb_tools_ttest_paired)
3050 { .name = "ToolTTestEqualVar",
3051 .label = N_("Unpaired Samples, _Equal Variances..."),
3052 .tooltip = N_("Comparing two population means for two unpaired samples from populations with equal variances"),
3053 .callback = G_CALLBACK (cb_tools_ttest_equal_var)
3056 { .name = "ToolTTestUnequalVar",
3057 .label = N_("Unpaired Samples, _Unequal Variances..."),
3058 .tooltip = N_("Comparing two population means for two unpaired samples from populations with unequal variances"),
3059 .callback = G_CALLBACK (cb_tools_ttest_unequal_var)
3062 { .name = "ToolZTest",
3063 .label = N_("Unpaired Samples, _Known Variances..."),
3064 .tooltip = N_("Comparing two population means from populations with known variances"),
3065 .callback = G_CALLBACK (cb_tools_ztest)
3068 /* Statistics -> TwoSamples -> Two Medians*/
3070 { .name = "ToolsTwoMedianSignTest",
3071 .label = N_("_Sign Test..."),
3072 .tooltip = N_("Comparing the values of two medians of paired observations"),
3073 .callback = G_CALLBACK (cb_tools_sign_test_two_medians)
3075 { .name = "ToolsTwoMedianWilcoxonSignedRank",
3076 .label = N_("_Wilcoxon Signed Rank Test..."),
3077 .tooltip = N_("Comparing the values of two medians of paired observations"),
3078 .callback = G_CALLBACK (cb_tools_wilcoxon_signed_rank_two_medians)
3080 { .name = "ToolsTwoMedianWilcoxonMannWhitney",
3081 .label = N_("Wilcoxon-_Mann-Whitney Test..."),
3082 .tooltip = N_("Comparing the values of two medians of unpaired observations"),
3083 .callback = G_CALLBACK (cb_tools_wilcoxon_mann_whitney)
3086 /* Statistics -> MultipleSamples */
3088 /* Statistics -> MultipleSamples -> ANOVA*/
3090 { .name = "ToolsANOVAoneFactor",
3091 .label = N_("_One Factor..."),
3092 .tooltip = N_("One Factor Analysis of Variance..."),
3093 .callback = G_CALLBACK (cb_tools_anova_one_factor)
3095 { .name = "ToolsANOVAtwoFactor",
3096 .label = N_("_Two Factor..."),
3097 .tooltip = N_("Two Factor Analysis of Variance..."),
3098 .callback = G_CALLBACK (cb_tools_anova_two_factor)
3101 /* Statistics -> MultipleSamples -> ContingencyTable*/
3103 { .name = "ToolsHomogeneity",
3104 .label = N_("Test of _Homogeneity..."),
3105 .tooltip = N_("Chi Squared Test of Homogeneity..."),
3106 .callback = G_CALLBACK (cb_tools_chi_square_homogeneity)
3108 { .name = "ToolsIndependence",
3109 .label = N_("Test of _Independence..."),
3110 .tooltip = N_("Chi Squared Test of Independence..."),
3111 .callback = G_CALLBACK (cb_tools_chi_square_independence)
3114 /* Data */
3115 { .name = "DataSort",
3116 .icon = "view-sort-ascending",
3117 .label = N_("_Sort..."),
3118 .tooltip = N_("Sort the selected region"),
3119 .callback = G_CALLBACK (cb_data_sort)
3121 { .name = "DataShuffle",
3122 .label = N_("Sh_uffle..."),
3123 .tooltip = N_("Shuffle cells, rows or columns"),
3124 .callback = G_CALLBACK (cb_data_shuffle)
3126 { .name = "DataValidate",
3127 .label = N_("_Validate..."),
3128 .tooltip = N_("Validate input with preset criteria"),
3129 .callback = G_CALLBACK (cb_data_validate)
3131 { .name = "DataTextToColumns",
3132 .label = N_("T_ext to Columns..."),
3133 .tooltip = N_("Parse the text in the selection into data"),
3134 .callback = G_CALLBACK (cb_data_text_to_columns)
3136 { .name = "DataConsolidate",
3137 .label = N_("_Consolidate..."),
3138 .tooltip = N_("Consolidate regions using a function"),
3139 .callback = G_CALLBACK (cb_data_consolidate)
3141 { .name = "DataTable",
3142 .label = N_("_Table..."),
3143 .tooltip = N_("Create a Data Table to evaluate a function with multiple inputs"),
3144 .callback = G_CALLBACK (cb_data_table)
3146 { .name = "DataExport",
3147 .label = N_("E_xport into Other Format..."),
3148 .tooltip = N_("Export the current workbook or sheet"),
3149 .callback = G_CALLBACK (cb_data_export)
3151 { .name = "DataExportText",
3152 .label = N_("Export as _Text File..."),
3153 .tooltip = N_("Export the current sheet as a text file"),
3154 .callback = G_CALLBACK (cb_data_export_text)
3156 { .name = "DataExportCSV",
3157 .label = N_("Export as _CSV File..."),
3158 .tooltip = N_("Export the current sheet as a csv file"),
3159 .callback = G_CALLBACK (cb_data_export_csv)
3161 { .name = "DataExportRepeat",
3162 .label = N_("Repeat Export"),
3163 .accelerator = "<control>E",
3164 .tooltip = N_("Repeat the last data export"),
3165 .callback = G_CALLBACK (cb_data_export_repeat)
3168 /* Data -> Fill */
3169 { .name = "EditFillAutofill",
3170 .label = N_("Auto_fill"),
3171 .tooltip = N_("Automatically fill the current selection"),
3172 .callback = G_CALLBACK (cb_edit_fill_autofill)
3174 { .name = "ToolsMerge",
3175 .label = N_("_Merge..."),
3176 .tooltip = N_("Merges columnar data into a sheet creating duplicate sheets for each row"),
3177 .callback = G_CALLBACK (cb_tools_merge)
3179 { .name = "ToolsTabulate",
3180 .label = N_("_Tabulate Dependency..."),
3181 .tooltip = N_("Make a table of a cell's value as a function of other cells"),
3182 .callback = G_CALLBACK (cb_tools_tabulate)
3184 { .name = "EditFillSeries",
3185 .label = N_("_Series..."),
3186 .tooltip = N_("Fill according to a linear or exponential series"),
3187 .callback = G_CALLBACK (cb_edit_fill_series)
3189 { .name = "RandomGeneratorUncorrelated",
3190 .label = N_("_Uncorrelated..."),
3191 .tooltip = N_("Generate random numbers of a selection of distributions"),
3192 .callback = G_CALLBACK (cb_tools_random_generator_uncorrelated)
3194 { .name = "RandomGeneratorCorrelated",
3195 .label = N_("_Correlated..."),
3196 .tooltip = N_("Generate variates for correlated normal distributed random variables"),
3197 .callback = G_CALLBACK (cb_tools_random_generator_correlated)
3199 { .name = "CopyDown",
3200 .label = N_("Fill Downwards"),
3201 .accelerator = "<control>D",
3202 .tooltip = N_("Copy the content from the top row to the cells below"),
3203 .callback = G_CALLBACK (cb_copydown)
3205 { .name = "CopyRight",
3206 .label = N_("Fill to Right"),
3207 .accelerator = "<control>R",
3208 .tooltip = N_("Copy the content from the left column to the cells on the right"),
3209 .callback = G_CALLBACK (cb_copyright)
3213 /* Data -> Outline */
3214 { .name = "DataOutlineHideDetail",
3215 .icon = "gnumeric-detail-hide",
3216 .label = N_("_Hide Detail"),
3217 .tooltip = N_("Collapse an outline group"),
3218 .callback = G_CALLBACK (cb_data_hide_detail)
3220 { .name = "DataOutlineShowDetail",
3221 .icon = "gnumeric-detail-show",
3222 .label = N_("_Show Detail"),
3223 .tooltip = N_("Uncollapse an outline group"),
3224 .callback = G_CALLBACK (cb_data_show_detail)
3226 { .name = "DataOutlineGroup",
3227 .icon = "gnumeric-group",
3228 .label = N_("_Group..."),
3229 .accelerator = "<shift><alt>Right",
3230 .tooltip = N_("Add an outline group"),
3231 .callback = G_CALLBACK (cb_data_group)
3233 { .name = "DataOutlineUngroup",
3234 .icon = "gnumeric-ungroup",
3235 .label = N_("_Ungroup..."),
3236 .accelerator = "<shift><alt>Left",
3237 .tooltip = N_("Remove an outline group"),
3238 .callback = G_CALLBACK (cb_data_ungroup)
3241 /* Data -> Filter */
3242 { .name = "DataAutoFilter",
3243 .icon = "gnumeric-autofilter",
3244 .label = N_("Add _Auto Filter"),
3245 .tooltip = N_("Add or remove a filter"),
3246 .callback = G_CALLBACK (cb_auto_filter)
3248 { .name = "DataFilterShowAll",
3249 .label = N_("_Clear Advanced Filter"),
3250 .tooltip = N_("Show all rows hidden by an advanced filter"),
3251 .callback = G_CALLBACK (cb_show_all)
3253 { .name = "DataFilterAdvancedfilter",
3254 .label = N_("Advanced _Filter..."),
3255 .tooltip = N_("Filter data with given criteria"),
3256 .callback = G_CALLBACK (cb_data_filter)
3258 /* Data -> External */
3259 { .name = "DataImportText",
3260 .label = N_("Import _Text File..."),
3261 .tooltip = N_("Import data from a text file"),
3262 .callback = G_CALLBACK (cb_data_import_text)
3264 { .name = "DataImportOther",
3265 .label = N_("Import _Other File..."),
3266 .tooltip = N_("Import data from a file"),
3267 .callback = G_CALLBACK (cb_data_import_other)
3270 /* Data -> Data Slicer */
3271 /* label and tip are context dependent, see wbcg_menu_state_update */
3272 { .name = "DataSlicer",
3273 .label = N_("Add _Data Slicer"),
3274 .tooltip = N_("Create a data slicer"),
3275 .callback = G_CALLBACK (cb_data_slicer_create)
3277 { .name = "DataSlicerRefresh",
3278 .label = N_("_Refresh"),
3279 .tooltip = N_("Regenerate a data slicer from the source data"),
3280 .callback = G_CALLBACK (cb_data_slicer_refresh)
3282 { .name = "DataSlicerEdit",
3283 .label = N_("_Edit Data Slicer..."),
3284 .tooltip = N_("Adjust a data slicer"),
3285 .callback = G_CALLBACK (cb_data_slicer_edit)
3288 /* Standard Toolbar */
3289 { .name = "AutoSum",
3290 .icon = "gnumeric-autosum",
3291 .label = N_("Sum"),
3292 .accelerator = "<alt>equal",
3293 .tooltip = N_("Sum into the current cell"),
3294 .callback = G_CALLBACK (cb_autosum)
3296 { .name = "InsertFormula",
3297 .icon = "gnumeric-formulaguru",
3298 .label = N_("_Function..."),
3299 .tooltip = N_("Edit a function in the current cell"),
3300 .callback = G_CALLBACK (cb_formula_guru)
3303 { .name = "SortAscending",
3304 .icon = "view-sort-ascending",
3305 .label = N_("Sort Ascending"),
3306 .tooltip = N_("Sort the selected region in ascending order based on the first column selected"),
3307 .callback = G_CALLBACK (cb_sort_ascending)
3309 { .name = "SortDescending",
3310 .icon = "view-sort-descending",
3311 .label = N_("Sort Descending"),
3312 .tooltip = N_("Sort the selected region in descending order based on the first column selected"),
3313 .callback = G_CALLBACK (cb_sort_descending)
3316 /* Object Toolbar */
3317 { .name = "CreateFrame",
3318 .icon = "gnumeric-object-frame",
3319 .label = N_("Frame"),
3320 .tooltip = N_("Create a frame"),
3321 .callback = G_CALLBACK (cmd_create_frame)
3323 { .name = "CreateCheckbox",
3324 .icon = "gnumeric-object-checkbox",
3325 .label = N_("Checkbox"),
3326 .tooltip = N_("Create a checkbox"),
3327 .callback = G_CALLBACK (cmd_create_checkbox)
3329 { .name = "CreateScrollbar",
3330 .icon = "gnumeric-object-scrollbar",
3331 .label = N_("Scrollbar"),
3332 .tooltip = N_("Create a scrollbar"),
3333 .callback = G_CALLBACK (cmd_create_scrollbar)
3335 { .name = "CreateSlider",
3336 .icon = "gnumeric-object-slider",
3337 .label = N_("Slider"),
3338 .tooltip = N_("Create a slider"),
3339 .callback = G_CALLBACK (cmd_create_slider)
3341 { .name = "CreateSpinButton",
3342 .icon = "gnumeric-object-spinbutton",
3343 .label = N_("SpinButton"),
3344 .tooltip = N_("Create a spin button"),
3345 .callback = G_CALLBACK (cmd_create_spinbutton)
3347 { .name = "CreateList",
3348 .icon = "gnumeric-object-list",
3349 .label = N_("List"),
3350 .tooltip = N_("Create a list"),
3351 .callback = G_CALLBACK (cmd_create_list)
3353 { .name = "CreateCombo",
3354 .icon = "gnumeric-object-combo",
3355 .label = N_("Combo Box"),
3356 .tooltip = N_("Create a combo box"),
3357 .callback = G_CALLBACK (cmd_create_combo)
3359 { .name = "CreateLine",
3360 .icon = "gnumeric-object-line",
3361 .label = N_("Line"),
3362 .tooltip = N_("Create a line object"),
3363 .callback = G_CALLBACK (cmd_create_line)
3365 { .name = "CreateArrow",
3366 .icon = "gnumeric-object-arrow",
3367 .label = N_("Arrow"),
3368 .tooltip = N_("Create an arrow object"),
3369 .callback = G_CALLBACK (cmd_create_arrow)
3371 { .name = "CreateRectangle",
3372 .icon = "gnumeric-object-rectangle",
3373 .label = N_("Rectangle"),
3374 .tooltip = N_("Create a rectangle object"),
3375 .callback = G_CALLBACK (cmd_create_rectangle)
3377 { .name = "CreateEllipse",
3378 .icon = "gnumeric-object-ellipse",
3379 .label = N_("Ellipse"),
3380 .tooltip = N_("Create an ellipse object"),
3381 .callback = G_CALLBACK (cmd_create_ellipse)
3383 { .name = "CreateButton",
3384 .icon = "gnumeric-object-button",
3385 .label = N_("Button"),
3386 .tooltip = N_("Create a button"),
3387 .callback = G_CALLBACK (cmd_create_button)
3389 { .name = "CreateRadioButton",
3390 .icon = "gnumeric-object-radiobutton",
3391 .label = N_("RadioButton"),
3392 .tooltip = N_("Create a radio button"),
3393 .callback = G_CALLBACK (cmd_create_radiobutton)
3396 /* Format toolbar */
3397 { .name = "FormatMergeCells",
3398 .icon = "gnumeric-cells-merge",
3399 .label = N_("Merge"),
3400 .tooltip = N_("Merge a range of cells"),
3401 .callback = G_CALLBACK (cb_merge_cells)
3403 { .name = "FormatUnmergeCells",
3404 .icon = "gnumeric-cells-split",
3405 .label = N_("Unmerge"),
3406 .tooltip = N_("Split merged ranges of cells"),
3407 .callback = G_CALLBACK (cb_unmerge_cells)
3410 { .name = "FormatAsGeneral",
3411 .label = N_("General"),
3412 .accelerator = "<control>asciitilde",
3413 .tooltip = N_("Format the selection as General"),
3414 .callback = G_CALLBACK (cb_format_as_general)
3416 { .name = "FormatAsNumber",
3417 .label = N_("Number"),
3418 .accelerator = "<control>exclam",
3419 .tooltip = N_("Format the selection as numbers"),
3420 .callback = G_CALLBACK (cb_format_as_number)
3422 { .name = "FormatAsCurrency",
3423 .label = N_("Currency"),
3424 .accelerator = "<control>dollar",
3425 .tooltip = N_("Format the selection as currency"),
3426 .callback = G_CALLBACK (cb_format_as_currency)
3428 { .name = "FormatAsAccounting",
3429 .icon = "gnumeric-format-accounting",
3430 .label = N_("Accounting"),
3431 .tooltip = N_("Format the selection as accounting"),
3432 .callback = G_CALLBACK (cb_format_as_accounting)
3434 { .name = "FormatAsPercentage",
3435 .icon = "gnumeric-format-percentage",
3436 .label = N_("Percentage"),
3437 .accelerator = "<control>percent",
3438 .tooltip = N_("Format the selection as percentage"),
3439 .callback = G_CALLBACK (cb_format_as_percentage)
3441 { .name = "FormatAsScientific",
3442 .label = N_("Scientific"),
3443 .accelerator = "<control>asciicircum",
3444 .tooltip = N_("Format the selection as scientific"),
3445 .callback = G_CALLBACK (cb_format_as_scientific)
3447 { .name = "FormatAsDate",
3448 .label = N_("Date"),
3449 .accelerator = "<control>numbersign",
3450 .tooltip = N_("Format the selection as date"),
3451 .callback = G_CALLBACK (cb_format_as_date)
3453 { .name = "FormatAsTime",
3454 .label = N_("Time"),
3455 .accelerator = "<control>at",
3456 .tooltip = N_("Format the selection as time"),
3457 .callback = G_CALLBACK (cb_format_as_time)
3459 { .name = "FormatAddBorders",
3460 .label = N_("AddBorders"),
3461 .accelerator = "<control>ampersand",
3462 .tooltip = N_("Add a border around the selection"),
3463 .callback = G_CALLBACK (cb_format_add_borders)
3465 { .name = "FormatClearBorders",
3466 .label = N_("ClearBorders"),
3467 .accelerator = "<control>underscore",
3468 .tooltip = N_("Clear the border around the selection"),
3469 .callback = G_CALLBACK (cb_format_clear_borders)
3472 { .name = "FormatWithThousands",
3473 .icon = "gnumeric-format-thousand-separator",
3474 .label = N_("Thousands Separator"),
3475 .tooltip = N_("Set the format of the selected cells to include a thousands separator"),
3476 .callback = G_CALLBACK (cb_format_with_thousands)
3478 { .name = "FormatIncreasePrecision",
3479 .icon = "gnumeric-format-precision-increase",
3480 .label = N_("Increase Precision"),
3481 .tooltip = N_("Increase the number of decimals displayed"),
3482 .callback = G_CALLBACK (cb_format_inc_precision)
3484 { .name = "FormatDecreasePrecision",
3485 .icon = "gnumeric-format-precision-decrease",
3486 .label = N_("Decrease Precision"),
3487 .tooltip = N_("Decrease the number of decimals displayed"),
3488 .callback = G_CALLBACK (cb_format_dec_precision)
3491 /* Gtk marks these accelerators as invalid because they use Tab
3492 * enable them manually in gnm-pane.c */
3493 { .name = "FormatDecreaseIndent",
3494 .icon = "format-indent-less",
3495 .accelerator = "<control><alt><shift>Tab",
3496 .tooltip = N_("Decrease the indent, and align the contents to the left"),
3497 .callback = G_CALLBACK (cb_format_dec_indent)
3499 { .name = "FormatIncreaseIndent",
3500 .icon = "format-indent-more",
3501 .accelerator = "<control><alt>Tab",
3502 .tooltip = N_("Increase the indent, and align the contents to the left"),
3503 .callback = G_CALLBACK (cb_format_inc_indent)
3506 /* ---------------------------------------- */
3508 { .name = "SheetDisplayOutlines",
3509 .toggle = TRUE,
3510 .label = N_("Display _Outlines"),
3511 .accelerator = "<control>8",
3512 .tooltip = N_("Toggle whether or not to display outline groups"),
3513 .callback = G_CALLBACK (cb_sheet_pref_display_outlines)
3515 { .name = "SheetOutlineBelow",
3516 .toggle = TRUE,
3517 .label = N_("Outlines _Below"),
3518 .tooltip = N_("Toggle whether to display row outlines on top or bottom"),
3519 .callback = G_CALLBACK (cb_sheet_pref_outline_symbols_below)
3521 { .name = "SheetOutlineRight",
3522 .toggle = TRUE,
3523 .label = N_("Outlines _Right"),
3524 .tooltip = N_("Toggle whether to display column outlines on the left or right"),
3525 .callback = G_CALLBACK (cb_sheet_pref_outline_symbols_right)
3527 { .name = "SheetDisplayFormulas",
3528 .toggle = TRUE,
3529 .icon = "gnumeric-formulaguru",
3530 .label = N_("Display _Formul\303\246"),
3531 .accelerator = "<control>quoteleft",
3532 .tooltip = N_("Display the value of a formula or the formula itself"),
3533 .callback = G_CALLBACK (cb_sheet_pref_display_formulas)
3535 { .name = "SheetHideZeros",
3536 .toggle = TRUE,
3537 .label = N_("_Hide Zeros"),
3538 .tooltip = N_("Toggle whether or not to display zeros as blanks"),
3539 .callback = G_CALLBACK (cb_sheet_pref_hide_zero)
3541 { .name = "SheetHideGridlines",
3542 .toggle = TRUE,
3543 .label = N_("Hide _Gridlines"),
3544 .tooltip = N_("Toggle whether or not to display gridlines"),
3545 .callback = G_CALLBACK (cb_sheet_pref_hide_grid)
3547 { .name = "SheetHideColHeader",
3548 .toggle = TRUE,
3549 .label = N_("Hide _Column Headers"),
3550 .tooltip = N_("Toggle whether or not to display column headers"),
3551 .callback = G_CALLBACK (cb_sheet_pref_hide_col_header)
3553 { .name = "SheetHideRowHeader",
3554 .toggle = TRUE,
3555 .label = N_("Hide _Row Headers"),
3556 .tooltip = N_("Toggle whether or not to display row headers"),
3557 .callback = G_CALLBACK (cb_sheet_pref_hide_row_header)
3560 /* TODO : Make this a sub menu when we have more convention types */
3561 { .name = "SheetUseR1C1",
3562 .toggle = TRUE,
3563 .label = N_("Use R1C1 N_otation "),
3564 .tooltip = N_("Display addresses as R1C1 or A1"),
3565 .callback = G_CALLBACK (cb_sheet_pref_use_r1c1)
3568 { .name = "AlignLeft",
3569 .toggle = TRUE,
3570 .icon = "format-justify-left",
3571 .label = N_("_Left Align"),
3572 .tooltip = N_("Align left"),
3573 .callback = G_CALLBACK (cb_align_left)
3575 { .name = "AlignCenter",
3576 .toggle = TRUE,
3577 .icon = "format-justify-center",
3578 .label = N_("_Center"),
3579 .tooltip = N_("Center horizontally"),
3580 .callback = G_CALLBACK (cb_align_center)
3582 { .name = "AlignRight",
3583 .toggle = TRUE,
3584 .icon = "format-justify-right",
3585 .label = N_("_Right Align"),
3586 .tooltip = N_("Align right"),
3587 .callback = G_CALLBACK (cb_align_right)
3589 { .name = "CenterAcrossSelection",
3590 .toggle = TRUE,
3591 .icon = "gnumeric-center-across-selection",
3592 .label = N_("_Center Across Selection"),
3593 .tooltip = N_("Center horizontally across the selection"),
3594 .callback = G_CALLBACK (cb_center_across_selection)
3596 { .name = "MergeAndCenter",
3597 .toggle = TRUE,
3598 .label = N_("_Merge and Center"),
3599 .tooltip = N_("Merge the selection into 1 cell, and center horizontally."),
3600 .callback = G_CALLBACK (cb_merge_and_center)
3602 #warning "Add justify"
3603 #warning "h/v distributed?"
3605 #warning "Get vertical alignment icons"
3606 { .name = "AlignTop",
3607 .toggle = TRUE,
3608 .label = N_("Align _Top"),
3609 .tooltip = N_("Align Top"),
3610 .callback = G_CALLBACK (cb_align_top)
3612 { .name = "AlignVCenter",
3613 .toggle = TRUE,
3614 .label = N_("_Vertically Center"),
3615 .tooltip = N_("Vertically Center"),
3616 .callback = G_CALLBACK (cb_align_vcenter)
3618 { .name = "AlignBottom",
3619 .toggle = TRUE,
3620 .label = N_("Align _Bottom"),
3621 .tooltip = N_("Align Bottom"),
3622 .callback = G_CALLBACK (cb_align_bottom)
3626 static GnmActionEntry const font_actions[] = {
3627 { .name = "FontBold",
3628 .toggle = TRUE,
3629 .icon = "format-text-bold",
3630 .label = N_("_Bold"),
3631 .accelerator = "<control>b", /* ALSO "<control>2" */
3632 .tooltip = N_("Bold"),
3633 .callback = G_CALLBACK (cb_font_bold),
3634 .is_active = FALSE },
3635 { .name = "FontItalic",
3636 .toggle = TRUE,
3637 .icon = "format-text-italic",
3638 .label = N_("_Italic"),
3639 .accelerator = "<control>i", /* ALSO "<control>3" */
3640 .tooltip = N_("Italic"),
3641 .callback = G_CALLBACK (cb_font_italic),
3642 .is_active = FALSE },
3643 { .name = "FontUnderline",
3644 .toggle = TRUE,
3645 .icon = "format-text-underline",
3646 .label = N_("_Underline"),
3647 .accelerator = "<control>u", /* ALSO "<control>4" */
3648 .tooltip = N_("Underline"),
3649 .callback = G_CALLBACK (cb_font_underline),
3650 .is_active = FALSE },
3651 { .name = "FontDoubleUnderline",
3652 .toggle = TRUE,
3653 .icon = "stock_text_underlined-double", /* from icon theme */
3654 .label = N_("_Double Underline"),
3655 .accelerator = "<control><shift>d",
3656 .tooltip = N_("Double Underline"),
3657 .callback = G_CALLBACK (cb_font_double_underline),
3658 .is_active = FALSE },
3659 { .name = "FontSingleLowUnderline",
3660 .toggle = TRUE,
3661 .label = N_("_Single Low Underline"),
3662 .accelerator = "<control><shift>l",
3663 .tooltip = N_("Single Low Underline"),
3664 .callback = G_CALLBACK (cb_font_underline_low),
3665 .is_active = FALSE },
3666 { .name = "FontDoubleLowUnderline",
3667 .toggle = TRUE,
3668 .label = N_("Double _Low Underline"),
3669 .tooltip = N_("Double Low Underline"),
3670 .callback = G_CALLBACK (cb_font_double_underline_low),
3671 .is_active = FALSE },
3672 { .name = "FontStrikeThrough",
3673 .toggle = TRUE,
3674 .icon = "format-text-strikethrough",
3675 .label = N_("_Strikethrough"),
3676 .accelerator = "<control>5",
3677 .tooltip = N_("Strikethrough"),
3678 .callback = G_CALLBACK (cb_font_strikethrough),
3679 .is_active = FALSE },
3680 { .name = "FontSuperscript",
3681 .toggle = TRUE,
3682 .icon = "gnumeric-superscript",
3683 .label = N_("Su_perscript"),
3684 .accelerator = "<control>asciicircum",
3685 .tooltip = N_("Superscript"),
3686 .callback = G_CALLBACK (cb_font_superscript),
3687 .is_active = FALSE },
3688 { .name = "FontSubscript",
3689 .toggle = TRUE,
3690 .icon = "gnumeric-subscript",
3691 .label = N_("Subscrip_t"),
3692 .accelerator = "<control>underscore",
3693 .tooltip = N_("Subscript"),
3694 .callback = G_CALLBACK (cb_font_subscript), .is_active = FALSE }
3697 /****************************************************************************/
3699 static GOActionComboPixmapsElement const halignment_combo_info[] = {
3700 { N_("Align left"), "format-justify-left", GNM_HALIGN_LEFT },
3701 { N_("Center horizontally"), "format-justify-center", GNM_HALIGN_CENTER },
3702 { N_("Align right"), "format-justify-right", GNM_HALIGN_RIGHT },
3703 { N_("Fill horizontally"), "gnumeric-format-halign-fill", GNM_HALIGN_FILL },
3704 { N_("Justify horizontally"), "format-justify-fill", GNM_HALIGN_JUSTIFY },
3705 { N_("Distributed"), "gnumeric-format-halign-distributed", GNM_HALIGN_DISTRIBUTED },
3706 { N_("Center horizontally across the selection"),
3707 "gnumeric-center-across-selection", GNM_HALIGN_CENTER_ACROSS_SELECTION },
3708 { N_("Align numbers right, and text left"),
3709 "gnumeric-format-halign-general", GNM_HALIGN_GENERAL },
3710 { NULL, NULL }
3712 static GOActionComboPixmapsElement const valignment_combo_info[] = {
3713 { N_("Align top"), "gnumeric-format-valign-top", GNM_VALIGN_TOP },
3714 { N_("Center vertically"), "gnumeric-format-valign-center", GNM_VALIGN_CENTER },
3715 { N_("Align bottom"), "gnumeric-format-valign-bottom", GNM_VALIGN_BOTTOM },
3716 { N_("Justify"), "gnumeric-format-valign-justify", GNM_VALIGN_JUSTIFY },
3717 { N_("Align distributed"), "gnumeric-format-valign-distributed", GNM_VALIGN_DISTRIBUTED },
3718 { NULL, NULL}
3721 static void
3722 cb_halignment_activated (GOActionComboPixmaps *a, WBCGtk *wbcg)
3724 wbcg_set_selection_halign (wbcg,
3725 go_action_combo_pixmaps_get_selected (a, NULL));
3727 static void
3728 cb_valignment_activated (GOActionComboPixmaps *a, WBCGtk *wbcg)
3730 wbcg_set_selection_valign (wbcg,
3731 go_action_combo_pixmaps_get_selected (a, NULL));
3734 static void
3735 wbc_gtk_init_alignments (WBCGtk *wbcg)
3737 wbcg->halignment = go_action_combo_pixmaps_new ("HAlignmentSelector",
3738 halignment_combo_info, 3, 1);
3739 g_object_set (G_OBJECT (wbcg->halignment),
3740 "label", _("Horizontal Alignment"),
3741 "tooltip", _("Horizontal Alignment"),
3742 NULL);
3743 g_signal_connect (G_OBJECT (wbcg->halignment),
3744 "activate",
3745 G_CALLBACK (cb_halignment_activated), wbcg);
3746 gnm_action_group_add_action (wbcg->actions, GTK_ACTION (wbcg->halignment));
3748 wbcg->valignment = go_action_combo_pixmaps_new ("VAlignmentSelector",
3749 valignment_combo_info, 1, 3);
3750 g_object_set (G_OBJECT (wbcg->valignment),
3751 "label", _("Vertical Alignment"),
3752 "tooltip", _("Vertical Alignment"),
3753 NULL);
3754 g_signal_connect (G_OBJECT (wbcg->valignment),
3755 "activate",
3756 G_CALLBACK (cb_valignment_activated), wbcg);
3757 gnm_action_group_add_action (wbcg->actions, GTK_ACTION (wbcg->valignment));
3760 /****************************************************************************/
3762 static void
3763 cb_custom_color_created (GOActionComboColor *caction, GtkWidget *dialog, WBCGtk *wbcg)
3765 wbc_gtk_attach_guru (wbcg, dialog);
3766 wbcg_set_transient (wbcg, GTK_WINDOW (dialog));
3769 static void
3770 cb_fore_color_changed (GOActionComboColor *a, WBCGtk *wbcg)
3772 WorkbookControl *wbc = GNM_WBC (wbcg);
3773 GnmStyle *mstyle;
3774 GOColor c;
3775 gboolean is_default;
3777 if (wbcg->updating_ui)
3778 return;
3779 c = go_action_combo_color_get_color (a, &is_default);
3781 if (wbcg_is_editing (wbcg)) {
3782 wbcg_edit_add_markup (wbcg, go_color_to_pango (c, TRUE));
3783 return;
3786 mstyle = gnm_style_new ();
3787 gnm_style_set_font_color (mstyle, is_default
3788 ? style_color_auto_font ()
3789 : gnm_color_new_go (c));
3790 cmd_selection_format (wbc, mstyle, NULL, _("Set Foreground Color"));
3793 static void
3794 wbc_gtk_init_color_fore (WBCGtk *gtk)
3796 GnmColor *sc_auto_font = style_color_auto_font ();
3797 GOColor default_color = sc_auto_font->go_color;
3798 style_color_unref (sc_auto_font);
3800 gtk->fore_color = go_action_combo_color_new ("ColorFore", "gnumeric-font",
3801 _("Automatic"), default_color, NULL); /* set group to view */
3802 go_action_combo_color_set_allow_alpha (gtk->fore_color, TRUE);
3803 g_object_set (G_OBJECT (gtk->fore_color),
3804 "label", _("Foreground"),
3805 "tooltip", _("Foreground"),
3806 NULL);
3807 g_signal_connect (G_OBJECT (gtk->fore_color),
3808 "combo-activate",
3809 G_CALLBACK (cb_fore_color_changed), gtk);
3810 g_signal_connect (G_OBJECT (gtk->fore_color),
3811 "display-custom-dialog",
3812 G_CALLBACK (cb_custom_color_created), gtk);
3813 gnm_action_group_add_action (gtk->font_actions,
3814 GTK_ACTION (gtk->fore_color));
3817 static void
3818 cb_back_color_changed (GOActionComboColor *a, WBCGtk *wbcg)
3820 WorkbookControl *wbc = GNM_WBC (wbcg);
3821 GnmStyle *mstyle;
3822 GOColor c;
3823 gboolean is_default;
3825 if (wbcg->updating_ui)
3826 return;
3828 c = go_action_combo_color_get_color (a, &is_default);
3830 mstyle = gnm_style_new ();
3831 if (!is_default) {
3832 /* We need to have a pattern of at least solid to draw a background colour */
3833 if (!gnm_style_is_element_set (mstyle, MSTYLE_PATTERN) ||
3834 gnm_style_get_pattern (mstyle) < 1)
3835 gnm_style_set_pattern (mstyle, 1);
3837 gnm_style_set_back_color (mstyle, gnm_color_new_go (c));
3838 } else
3839 gnm_style_set_pattern (mstyle, 0); /* Set background to NONE */
3840 cmd_selection_format (wbc, mstyle, NULL, _("Set Background Color"));
3843 static void
3844 wbc_gtk_init_color_back (WBCGtk *gtk)
3846 gtk->back_color = go_action_combo_color_new ("ColorBack", "gnumeric-bucket",
3847 _("Clear Background"), 0, NULL);
3848 g_object_set (G_OBJECT (gtk->back_color),
3849 "label", _("Background"),
3850 "tooltip", _("Background"),
3851 NULL);
3852 g_object_connect (G_OBJECT (gtk->back_color),
3853 "signal::combo-activate", G_CALLBACK (cb_back_color_changed), gtk,
3854 "signal::display-custom-dialog", G_CALLBACK (cb_custom_color_created), gtk,
3855 NULL);
3856 gnm_action_group_add_action (gtk->actions, GTK_ACTION (gtk->back_color));
3859 /****************************************************************************/
3861 static GOActionComboPixmapsElement const border_combo_info[] = {
3862 { N_("Left"), "gnumeric-format-border-left", 11 },
3863 { N_("Clear Borders"), "gnumeric-format-border-none", 12 },
3864 { N_("Right"), "gnumeric-format-border-right", 13 },
3866 { N_("All Borders"), "gnumeric-format-border-all", 21 },
3867 { N_("Outside Borders"), "gnumeric-format-border-outside", 22 },
3868 { N_("Thick Outside Borders"), "gnumeric-format-border-thick-outside", 23 },
3870 { N_("Bottom"), "gnumeric-format-border-bottom", 31 },
3871 { N_("Double Bottom"), "gnumeric-format-border-double-bottom", 32 },
3872 { N_("Thick Bottom"), "gnumeric-format-border-thick-bottom", 33 },
3874 { N_("Top and Bottom"), "gnumeric-format-border-top-n-bottom", 41 },
3875 { N_("Top and Double Bottom"), "gnumeric-format-border-top-n-double-bottom", 42 },
3876 { N_("Top and Thick Bottom"), "gnumeric-format-border-top-n-thick-bottom", 43 },
3878 { NULL, NULL}
3881 static void
3882 cb_border_activated (GOActionComboPixmaps *a, WorkbookControl *wbc)
3884 Sheet *sheet = wb_control_cur_sheet (wbc);
3885 GnmBorder *borders[GNM_STYLE_BORDER_EDGE_MAX];
3886 int i;
3887 int index = go_action_combo_pixmaps_get_selected (a, NULL);
3889 /* Init the list */
3890 for (i = GNM_STYLE_BORDER_TOP; i < GNM_STYLE_BORDER_EDGE_MAX; i++)
3891 borders[i] = NULL;
3893 switch (index) {
3894 case 11 : /* left */
3895 borders[GNM_STYLE_BORDER_LEFT] = gnm_style_border_fetch (GNM_STYLE_BORDER_THIN,
3896 sheet_style_get_auto_pattern_color (sheet),
3897 gnm_style_border_get_orientation (GNM_STYLE_BORDER_LEFT));
3898 break;
3900 case 12 : /* none */
3901 for (i = GNM_STYLE_BORDER_TOP; i < GNM_STYLE_BORDER_EDGE_MAX; i++)
3902 borders[i] = gnm_style_border_ref (gnm_style_border_none ());
3903 break;
3905 case 13 : /* right */
3906 borders[GNM_STYLE_BORDER_RIGHT] = gnm_style_border_fetch (GNM_STYLE_BORDER_THIN,
3907 sheet_style_get_auto_pattern_color (sheet),
3908 gnm_style_border_get_orientation (GNM_STYLE_BORDER_RIGHT));
3909 break;
3911 case 21 : /* all */
3912 for (i = GNM_STYLE_BORDER_HORIZ; i <= GNM_STYLE_BORDER_VERT; ++i)
3913 borders[i] = gnm_style_border_fetch (GNM_STYLE_BORDER_THIN,
3914 sheet_style_get_auto_pattern_color (sheet),
3915 gnm_style_border_get_orientation (i));
3916 /* fall through */
3918 case 22 : /* outside */
3919 for (i = GNM_STYLE_BORDER_TOP; i <= GNM_STYLE_BORDER_RIGHT; ++i)
3920 borders[i] = gnm_style_border_fetch (GNM_STYLE_BORDER_THIN,
3921 sheet_style_get_auto_pattern_color (sheet),
3922 gnm_style_border_get_orientation (i));
3923 break;
3925 case 23 : /* thick_outside */
3926 for (i = GNM_STYLE_BORDER_TOP; i <= GNM_STYLE_BORDER_RIGHT; ++i)
3927 borders[i] = gnm_style_border_fetch (GNM_STYLE_BORDER_THICK,
3928 sheet_style_get_auto_pattern_color (sheet),
3929 gnm_style_border_get_orientation (i));
3930 break;
3932 case 41 : /* top_n_bottom */
3933 case 42 : /* top_n_double_bottom */
3934 case 43 : /* top_n_thick_bottom */
3935 borders[GNM_STYLE_BORDER_TOP] = gnm_style_border_fetch (GNM_STYLE_BORDER_THIN,
3936 sheet_style_get_auto_pattern_color (sheet),
3937 gnm_style_border_get_orientation (GNM_STYLE_BORDER_TOP));
3938 /* Fall through */
3940 case 31 : /* bottom */
3941 case 32 : /* double_bottom */
3942 case 33 : /* thick_bottom */
3944 int const tmp = index % 10;
3945 GnmStyleBorderType const t =
3946 (tmp == 1) ? GNM_STYLE_BORDER_THIN :
3947 (tmp == 2) ? GNM_STYLE_BORDER_DOUBLE
3948 : GNM_STYLE_BORDER_THICK;
3950 borders[GNM_STYLE_BORDER_BOTTOM] = gnm_style_border_fetch (t,
3951 sheet_style_get_auto_pattern_color (sheet),
3952 gnm_style_border_get_orientation (GNM_STYLE_BORDER_BOTTOM));
3953 break;
3956 default :
3957 g_warning ("Unknown border preset selected (%d)", index);
3958 return;
3961 cmd_selection_format (wbc, NULL, borders, _("Set Borders"));
3964 static void
3965 wbc_gtk_init_borders (WBCGtk *wbcg)
3967 wbcg->borders = go_action_combo_pixmaps_new ("BorderSelector", border_combo_info, 3, 4);
3968 g_object_set (G_OBJECT (wbcg->borders),
3969 "label", _("Borders"),
3970 "tooltip", _("Borders"),
3971 NULL);
3972 #if 0
3973 go_combo_pixmaps_select (wbcg->borders, 1); /* default to none */
3974 #endif
3975 g_signal_connect (G_OBJECT (wbcg->borders),
3976 "combo-activate",
3977 G_CALLBACK (cb_border_activated), wbcg);
3978 gnm_action_group_add_action (wbcg->actions, GTK_ACTION (wbcg->borders));
3981 /****************************************************************************/
3983 static void
3984 cb_chain_sensitivity (GtkAction *src, G_GNUC_UNUSED GParamSpec *pspec,
3985 GtkAction *action)
3987 gboolean old_val = gtk_action_get_sensitive (action);
3988 gboolean new_val = gtk_action_get_sensitive (src);
3989 if ((new_val != 0) == (old_val != 0))
3990 return;
3991 if (new_val)
3992 gtk_action_connect_accelerator (action);
3993 else
3994 gtk_action_disconnect_accelerator (action);
3995 g_object_set (action, "sensitive", new_val, NULL);
3999 static void
4000 create_undo_redo (GOActionComboStack **haction, char const *hname,
4001 GCallback hcb,
4002 GtkAction **vaction, char const *vname,
4003 GCallback vcb,
4004 WBCGtk *gtk,
4005 char const *tooltip,
4006 char const *icon_name,
4007 char const *accel, const char *alt_accel)
4009 *haction = g_object_new
4010 (go_action_combo_stack_get_type (),
4011 "name", hname,
4012 "tooltip", tooltip,
4013 "icon-name", icon_name,
4014 "sensitive", FALSE,
4015 "visible-vertical", FALSE,
4016 NULL);
4017 gtk_action_group_add_action_with_accel
4018 (gtk->semi_permanent_actions,
4019 GTK_ACTION (*haction),
4020 accel);
4021 g_signal_connect (G_OBJECT (*haction), "activate", hcb, gtk);
4023 *vaction = g_object_new
4024 (GTK_TYPE_ACTION,
4025 "name", vname,
4026 "tooltip", tooltip,
4027 "icon-name", icon_name,
4028 "sensitive", FALSE,
4029 "visible-horizontal", FALSE,
4030 NULL);
4031 gtk_action_group_add_action_with_accel
4032 (gtk->semi_permanent_actions,
4033 GTK_ACTION (*vaction),
4034 alt_accel);
4035 g_signal_connect_swapped (G_OBJECT (*vaction), "activate", vcb, gtk);
4037 g_signal_connect (G_OBJECT (*haction), "notify::sensitive",
4038 G_CALLBACK (cb_chain_sensitivity), *vaction);
4042 static void
4043 cb_undo_activated (GOActionComboStack *a, WorkbookControl *wbc)
4045 unsigned n = workbook_find_command (wb_control_get_workbook (wbc), TRUE,
4046 go_action_combo_stack_selection (a));
4047 while (n-- > 0)
4048 command_undo (wbc);
4051 static void
4052 cb_redo_activated (GOActionComboStack *a, WorkbookControl *wbc)
4054 unsigned n = workbook_find_command (wb_control_get_workbook (wbc), FALSE,
4055 go_action_combo_stack_selection (a));
4056 while (n-- > 0)
4057 command_redo (wbc);
4060 static void
4061 wbc_gtk_init_undo_redo (WBCGtk *gtk)
4063 create_undo_redo (
4064 &gtk->redo_haction, "Redo", G_CALLBACK (cb_redo_activated),
4065 &gtk->redo_vaction, "VRedo", G_CALLBACK (command_redo),
4066 gtk, _("Redo the undone action"),
4067 "edit-redo", "<control>y", "<control><shift>z");
4068 create_undo_redo (
4069 &gtk->undo_haction, "Undo", G_CALLBACK (cb_undo_activated),
4070 &gtk->undo_vaction, "VUndo", G_CALLBACK (command_undo),
4071 gtk, _("Undo the last action"),
4072 "edit-undo", "<control>z", NULL);
4075 /****************************************************************************/
4077 static GNM_ACTION_DEF (cb_zoom_activated)
4079 WorkbookControl *wbc = (WorkbookControl *)wbcg;
4080 Sheet *sheet = wb_control_cur_sheet (wbc);
4081 char const *new_zoom;
4082 int factor;
4083 char *end;
4085 if (sheet == NULL || wbcg->updating_ui || wbcg->snotebook == NULL)
4086 return;
4088 new_zoom = go_action_combo_text_get_entry (wbcg->zoom_haction);
4090 errno = 0; /* strtol sets errno, but does not clear it. */
4091 factor = strtol (new_zoom, &end, 10);
4092 if (new_zoom != end && errno != ERANGE && factor == (gnm_float)factor)
4093 /* The GSList of sheet passed to cmd_zoom will be freed by cmd_zoom,
4094 * and the sheet will force an update of the zoom combo to keep the
4095 * display consistent
4097 cmd_zoom (wbc, g_slist_append (NULL, sheet), factor / 100.);
4100 static GNM_ACTION_DEF (cb_vzoom_activated)
4102 dialog_zoom (wbcg, wbcg_cur_sheet (wbcg));
4105 static void
4106 wbc_gtk_init_zoom (WBCGtk *wbcg)
4108 #warning TODO : Add zoom to selection
4109 static char const * const preset_zoom [] = {
4110 "200%",
4111 "150%",
4112 "100%",
4113 "75%",
4114 "50%",
4115 "25%",
4116 NULL
4118 int i;
4120 /* ----- horizontal ----- */
4122 wbcg->zoom_haction =
4123 g_object_new (go_action_combo_text_get_type (),
4124 "name", "Zoom",
4125 "label", _("_Zoom"),
4126 "visible-vertical", FALSE,
4127 "tooltip", _("Zoom"),
4128 "stock-id", "zoom-in",
4129 NULL);
4130 go_action_combo_text_set_width (wbcg->zoom_haction, "10000%");
4131 for (i = 0; preset_zoom[i] != NULL ; ++i)
4132 go_action_combo_text_add_item (wbcg->zoom_haction,
4133 preset_zoom[i]);
4135 g_signal_connect (G_OBJECT (wbcg->zoom_haction),
4136 "activate",
4137 G_CALLBACK (cb_zoom_activated), wbcg);
4138 gnm_action_group_add_action (wbcg->actions,
4139 GTK_ACTION (wbcg->zoom_haction));
4141 /* ----- vertical ----- */
4143 wbcg->zoom_vaction =
4144 g_object_new (GTK_TYPE_ACTION,
4145 "name", "VZoom",
4146 "tooltip", _("Zoom"),
4147 "icon-name", "zoom-in",
4148 "visible-horizontal", FALSE,
4149 NULL);
4150 g_signal_connect (G_OBJECT (wbcg->zoom_vaction),
4151 "activate",
4152 G_CALLBACK (cb_vzoom_activated), wbcg);
4153 gnm_action_group_add_action (wbcg->actions,
4154 GTK_ACTION (wbcg->zoom_vaction));
4156 /* ----- chain ----- */
4158 g_signal_connect (G_OBJECT (wbcg->zoom_haction), "notify::sensitive",
4159 G_CALLBACK (cb_chain_sensitivity), wbcg->zoom_vaction);
4162 /****************************************************************************/
4164 typedef struct { GtkAction base; } GnmFontAction;
4165 typedef struct { GtkActionClass base; } GnmFontActionClass;
4167 static PangoFontDescription *
4168 gnm_font_action_get_font_desc (GtkAction *act)
4170 PangoFontDescription *desc =
4171 g_object_get_data (G_OBJECT (act), "font-data");
4172 return desc;
4175 void
4176 wbcg_font_action_set_font_desc (GtkAction *act, PangoFontDescription *desc)
4178 PangoFontDescription *old_desc;
4179 GSList *p;
4181 old_desc = g_object_get_data (G_OBJECT (act), "font-data");
4182 if (!old_desc) {
4183 old_desc = pango_font_description_new ();
4184 g_object_set_data_full (G_OBJECT (act),
4185 "font-data", old_desc,
4186 (GDestroyNotify)pango_font_description_free);
4188 pango_font_description_merge (old_desc, desc, TRUE);
4190 for (p = gtk_action_get_proxies (act); p; p = p->next) {
4191 GtkWidget *w = p->data;
4192 GtkWidget *child;
4193 GtkFontChooser *chooser;
4195 if (!GTK_IS_BIN (w))
4196 continue;
4198 child = gtk_bin_get_child (GTK_BIN (w));
4199 if (!GTK_IS_FONT_CHOOSER (child))
4200 continue;
4202 chooser = GTK_FONT_CHOOSER (child);
4203 gtk_font_chooser_set_font_desc (chooser, old_desc);
4207 static void
4208 cb_font_set (GtkFontChooser *chooser, GtkAction *act)
4210 PangoFontDescription *desc = gtk_font_chooser_get_font_desc (chooser);
4211 wbcg_font_action_set_font_desc (act, desc);
4212 pango_font_description_free (desc);
4213 gtk_action_activate (act);
4216 static void
4217 cb_font_button_screen_changed (GtkWidget *widget)
4219 /* Doesn't look right */
4220 #if 0
4221 GdkScreen *screen = gtk_widget_get_screen (widget);
4223 if (screen) {
4224 int w = gnm_widget_measure_string (widget,
4225 "XXMonospace | 99XX");
4226 gtk_widget_set_size_request (widget, w, -1);
4228 #endif
4231 /* Filter to ignore non-scalable fonts. */
4232 static gboolean
4233 cb_font_filter (G_GNUC_UNUSED const PangoFontFamily *family,
4234 const PangoFontFace *face_,
4235 gpointer user)
4237 PangoFontFace *face = (PangoFontFace*)face_;
4238 int n_sizes;
4239 int *sizes = NULL;
4240 static int debug = -1;
4242 pango_font_face_list_sizes (face, &sizes, &n_sizes);
4243 g_free (sizes);
4245 if (debug == -1)
4246 debug = gnm_debug_flag ("fonts");
4248 if (n_sizes > 0 && debug) {
4249 PangoFontDescription *desc = pango_font_face_describe (face);
4250 char *s = pango_font_description_to_string (desc);
4251 g_printerr ("Ignoring bitmap face %s\n", s);
4252 g_free (s);
4253 pango_font_description_free (desc);
4256 return n_sizes == 0;
4259 static GtkWidget *
4260 gnm_font_action_create_tool_item (GtkAction *action)
4262 GtkWidget *item = g_object_new
4263 (GTK_TYPE_TOOL_ITEM,
4264 NULL);
4265 GtkWidget *but = g_object_new
4266 (gnm_font_button_get_type(),
4267 "dialog-type", GO_TYPE_FONT_SEL_DIALOG,
4268 "show-preview-entry", TRUE,
4269 "show-style", FALSE,
4270 "relief", gtk_tool_item_get_relief_style (GTK_TOOL_ITEM (item)),
4271 "focus-on-click", FALSE,
4272 NULL);
4273 if (0) gtk_font_chooser_set_filter_func (GTK_FONT_CHOOSER (but),
4274 cb_font_filter,
4275 NULL,
4276 NULL);
4277 gtk_widget_show_all (but);
4278 gtk_container_add (GTK_CONTAINER (item), but);
4279 g_signal_connect (but,
4280 "font-set", G_CALLBACK (cb_font_set),
4281 action);
4282 g_signal_connect (but,
4283 "screen-changed",
4284 G_CALLBACK (cb_font_button_screen_changed),
4285 action);
4286 return item;
4289 static void
4290 gnm_font_action_class_init (GObjectClass *gobject_class)
4292 GtkActionClass *act = GTK_ACTION_CLASS (gobject_class);
4294 act->toolbar_item_type = GTK_TYPE_MENU_TOOL_BUTTON;
4295 act->create_tool_item = gnm_font_action_create_tool_item;
4298 static
4299 GSF_CLASS (GnmFontAction, gnm_font_action,
4300 gnm_font_action_class_init, NULL, GTK_TYPE_ACTION)
4301 #if 0
4303 #endif
4304 #define GNM_FONT_ACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), gnm_font_action_get_type(), GnmFontAction))
4306 static void
4307 cb_font_changed (GtkAction *act, WBCGtk *gtk)
4309 PangoFontDescription *desc = gnm_font_action_get_font_desc (act);
4310 const char *family = pango_font_description_get_family (desc);
4311 int size = pango_font_description_get_size (desc);
4314 * Ignore events during destruction. This is an attempt at avoiding
4315 * https://bugzilla.redhat.com/show_bug.cgi?id=803904 for which we
4316 * blame gtk.
4318 if (gtk->snotebook == NULL)
4319 return;
4321 if (wbcg_is_editing (WBC_GTK (gtk))) {
4322 wbcg_edit_add_markup (WBC_GTK (gtk),
4323 pango_attr_family_new (family));
4324 wbcg_edit_add_markup (WBC_GTK (gtk),
4325 pango_attr_size_new (size));
4326 } else {
4327 GnmStyle *style = gnm_style_new ();
4328 char *font_name = pango_font_description_to_string (desc);
4329 char *title = g_strdup_printf (_("Setting Font %s"), font_name);
4330 g_free (font_name);
4332 gnm_style_set_font_name (style, family);
4333 gnm_style_set_font_size (style, size / (double)PANGO_SCALE);
4335 cmd_selection_format (GNM_WBC (gtk), style, NULL, title);
4336 g_free (title);
4340 static void
4341 cb_font_name_vaction_response (GtkDialog *dialog,
4342 gint response_id,
4343 GtkAction *act)
4345 WBCGtk *wbcg = g_object_get_data (G_OBJECT (act), "wbcg");
4347 if (response_id == GTK_RESPONSE_OK) {
4348 PangoFontDescription *desc = gtk_font_chooser_get_font_desc
4349 (GTK_FONT_CHOOSER (dialog));
4350 wbcg_font_action_set_font_desc (act, desc);
4351 pango_font_description_free (desc);
4352 cb_font_changed (act, wbcg);
4355 gtk_widget_destroy (GTK_WIDGET (dialog));
4359 static void
4360 cb_font_name_vaction_clicked (GtkAction *act, WBCGtk *wbcg)
4362 GtkFontChooser *font_dialog;
4363 const char *key = "font-name-dialog";
4365 if (gnm_dialog_raise_if_exists (wbcg, key))
4366 return;
4368 font_dialog = g_object_new (GO_TYPE_FONT_SEL_DIALOG, NULL);
4369 gtk_font_chooser_set_font_desc (font_dialog,
4370 gnm_font_action_get_font_desc (act));
4371 g_signal_connect (font_dialog, "response",
4372 G_CALLBACK (cb_font_name_vaction_response),
4373 act);
4375 gtk_window_present (GTK_WINDOW (font_dialog));
4377 gnm_keyed_dialog (wbcg, GTK_WINDOW (font_dialog), key);
4380 static GtkAction *
4381 wbc_gtk_init_font_name (WBCGtk *gtk, gboolean horiz)
4383 GtkAction *act = g_object_new
4384 (horiz ? gnm_font_action_get_type () : GTK_TYPE_ACTION,
4385 "visible-vertical", !horiz,
4386 "visible-horizontal", horiz,
4387 "name", (horiz ? "FontName" : "VFontName"),
4388 "tooltip", _("Change font"),
4389 "icon-name", "gnumeric-font",
4390 NULL);
4392 g_object_set_data (G_OBJECT (act), "wbcg", gtk);
4394 g_signal_connect (G_OBJECT (act),
4395 "activate",
4396 (horiz
4397 ? G_CALLBACK (cb_font_changed)
4398 : G_CALLBACK (cb_font_name_vaction_clicked)),
4399 gtk);
4401 gnm_action_group_add_action (gtk->font_actions, act);
4403 return act;
4406 /****************************************************************************/
4408 static void
4409 list_actions (GtkActionGroup *group)
4411 GList *actions, *l;
4413 if (!group)
4414 return;
4416 actions = gtk_action_group_list_actions (group);
4417 for (l = actions; l; l = l->next) {
4418 GtkAction *act = l->data;
4419 const char *name = gtk_action_get_name (act);
4420 g_printerr ("Action %s\n", name);
4423 g_list_free (actions);
4426 void
4427 wbc_gtk_init_actions (WBCGtk *wbcg)
4429 static struct {
4430 char const *name;
4431 gboolean is_font;
4432 unsigned offset;
4433 } const toggles[] = {
4434 { "FontBold", TRUE, G_STRUCT_OFFSET (WBCGtk, font.bold) },
4435 { "FontItalic", TRUE, G_STRUCT_OFFSET (WBCGtk, font.italic) },
4436 { "FontUnderline", TRUE, G_STRUCT_OFFSET (WBCGtk, font.underline) },
4437 { "FontDoubleUnderline", TRUE, G_STRUCT_OFFSET (WBCGtk, font.d_underline) },
4438 { "FontSingleLowUnderline",TRUE, G_STRUCT_OFFSET (WBCGtk, font.sl_underline) },
4439 { "FontDoubleLowUnderline",TRUE, G_STRUCT_OFFSET (WBCGtk, font.dl_underline) },
4440 { "FontSuperscript", TRUE, G_STRUCT_OFFSET (WBCGtk, font.superscript) },
4441 { "FontSubscript", TRUE, G_STRUCT_OFFSET (WBCGtk, font.subscript) },
4442 { "FontStrikeThrough", TRUE, G_STRUCT_OFFSET (WBCGtk, font.strikethrough) },
4444 { "AlignLeft", FALSE, G_STRUCT_OFFSET (WBCGtk, h_align.left) },
4445 { "AlignCenter", FALSE, G_STRUCT_OFFSET (WBCGtk, h_align.center) },
4446 { "AlignRight", FALSE, G_STRUCT_OFFSET (WBCGtk, h_align.right) },
4447 { "CenterAcrossSelection", FALSE, G_STRUCT_OFFSET (WBCGtk, h_align.center_across_selection) },
4448 { "AlignTop", FALSE, G_STRUCT_OFFSET (WBCGtk, v_align.top) },
4449 { "AlignVCenter", FALSE, G_STRUCT_OFFSET (WBCGtk, v_align.center) },
4450 { "AlignBottom", FALSE, G_STRUCT_OFFSET (WBCGtk, v_align.bottom) }
4452 unsigned i;
4454 wbcg->permanent_actions = gtk_action_group_new ("PermanentActions");
4455 wbcg->actions = gtk_action_group_new ("Actions");
4456 wbcg->font_actions = gtk_action_group_new ("FontActions");
4457 wbcg->data_only_actions = gtk_action_group_new ("DataOnlyActions");
4458 wbcg->semi_permanent_actions = gtk_action_group_new ("SemiPermanentActions");
4460 gnm_action_group_add_actions (wbcg->permanent_actions,
4461 permanent_actions, G_N_ELEMENTS (permanent_actions), wbcg);
4462 gnm_action_group_add_actions (wbcg->actions,
4463 actions, G_N_ELEMENTS (actions), wbcg);
4464 gnm_action_group_add_actions (wbcg->font_actions,
4465 font_actions, G_N_ELEMENTS (font_actions), wbcg);
4466 gnm_action_group_add_actions (wbcg->data_only_actions,
4467 data_only_actions, G_N_ELEMENTS (data_only_actions), wbcg);
4468 gnm_action_group_add_actions (wbcg->semi_permanent_actions,
4469 semi_permanent_actions, G_N_ELEMENTS (semi_permanent_actions), wbcg);
4471 wbc_gtk_init_alignments (wbcg);
4472 wbc_gtk_init_color_fore (wbcg);
4473 wbc_gtk_init_color_back (wbcg);
4474 wbc_gtk_init_borders (wbcg);
4475 wbc_gtk_init_undo_redo (wbcg);
4476 wbc_gtk_init_zoom (wbcg);
4477 wbcg->font_name_haction = wbc_gtk_init_font_name (wbcg, TRUE);
4478 wbcg->font_name_vaction = wbc_gtk_init_font_name (wbcg, FALSE);
4480 for (i = G_N_ELEMENTS (toggles); i-- > 0 ; ) {
4481 GtkAction *act = wbcg_find_action (wbcg, toggles[i].name);
4482 G_STRUCT_MEMBER (GtkToggleAction *, wbcg, toggles[i].offset) =
4483 (GtkToggleAction*) (act);
4486 if (gnm_debug_flag ("actions")) {
4487 list_actions (wbcg->permanent_actions);
4488 list_actions (wbcg->actions);
4489 list_actions (wbcg->font_actions);
4490 list_actions (wbcg->data_only_actions);
4491 list_actions (wbcg->semi_permanent_actions);
4492 list_actions (wbcg->file_history.actions);
4493 list_actions (wbcg->toolbar.actions);
4494 list_actions (wbcg->windows.actions);
4495 list_actions (wbcg->templates.actions);