static void gnm_so_path_prep_sax_parser (SheetObject *so, GsfXMLIn *xin, xmlChar const **attrs, G_GNUC_UNUSED GnmConventions const *convs) { static GsfXMLInNode const dtd[] = { GSF_XML_IN_NODE (SOPATH, SOPATH, -1, "SheetObjectPath", GSF_XML_NO_CONTENT, NULL, NULL), GSF_XML_IN_NODE (SOPATH, PATH, -1, "Path", GSF_XML_NO_CONTENT, &sop_sax_path, NULL), GSF_XML_IN_NODE (SOPATH, STYLE, -1, "Style", GSF_XML_NO_CONTENT, &sop_sax_style, NULL), GSF_XML_IN_NODE_END }; static GsfXMLInDoc *doc = NULL; GnmSOPath *sop = GNM_SO_PATH(so); if (NULL == doc) { doc = gsf_xml_in_doc_new (dtd, NULL); gnm_xml_in_doc_dispose_on_exit (&doc); } gsf_xml_in_push_state (xin, doc, NULL, NULL, attrs); for (; attrs != NULL && attrs[0] && attrs[1] ; attrs += 2) if (attr_eq (attrs[0], "Label")) g_object_set (G_OBJECT (sop), "text", attrs[1], NULL); else if (attr_eq (attrs[0], "LabelFormat")) { GOFormat * fmt = go_format_new_from_XL (attrs[1]); if (go_format_is_markup (fmt)) g_object_set (G_OBJECT (sop), "markup", go_format_get_markup (fmt), NULL); go_format_unref (fmt); } else if (attr_eq (attrs[0], "Path")) { GOPath *path = go_path_new_from_svg (attrs[1]); if (path) { g_object_set (G_OBJECT (sop), "path", path, NULL); go_path_free (path); } } }
static void html_write_cell_content (GsfOutput *output, GnmCell *cell, GnmStyle const *style, char *formatted_string) { gsf_output_puts (output, "\""); if (style != NULL) { if (gnm_style_get_font_italic (style)) gsf_output_puts (output, "<i>"); if (gnm_style_get_font_bold (style)) gsf_output_puts (output, "<b>"); if (gnm_style_get_font_uline (style) != UNDERLINE_NONE) gsf_output_puts (output, "<u>"); if (font_is_monospaced (style)) gsf_output_puts (output, "<tt>"); if (gnm_style_get_font_strike (style)) gsf_output_puts (output, "<strike>"); switch (gnm_style_get_font_script (style)) { case GO_FONT_SCRIPT_SUB: gsf_output_puts (output, "<sub>"); break; case GO_FONT_SCRIPT_SUPER: gsf_output_puts (output, "<sup>"); break; default: break; } } if (cell != NULL) { const PangoAttrList * markup = NULL; if ((cell->value->type == VALUE_STRING) && (VALUE_FMT (cell->value) != NULL) && go_format_is_markup (VALUE_FMT (cell->value))) markup = go_format_get_markup (VALUE_FMT (cell->value)); if (markup != NULL) { GString *str = g_string_new (""); value_get_as_gstring (cell->value, str, NULL); html_new_markup (output, markup, str->str); g_string_free (str, TRUE); } else { html_print_encoded (output, formatted_string); } } if (style != NULL) { if (gnm_style_get_font_strike (style)) gsf_output_puts (output, "</strike>"); switch (gnm_style_get_font_script (style)) { case GO_FONT_SCRIPT_SUB: gsf_output_puts (output, "</sub>"); break; case GO_FONT_SCRIPT_SUPER: gsf_output_puts (output, "</sup>"); break; default: break; } if (font_is_monospaced (style)) gsf_output_puts (output, "</tt>"); if (gnm_style_get_font_uline (style) != UNDERLINE_NONE) gsf_output_puts (output, "</u>"); if (gnm_style_get_font_bold (style)) gsf_output_puts (output, "</b>"); if (gnm_style_get_font_italic (style)) gsf_output_puts (output, "</i>"); } gsf_output_puts (output, "\","); }
static void html_write_cell_content (GsfOutput *output, GnmCell *cell, GnmStyle const *style, html_version_t version) { guint r = 0; guint g = 0; guint b = 0; char *rendered_string; gboolean hidden = gnm_style_get_contents_hidden (style); GnmHLink* hlink = gnm_style_get_hlink (style); const guchar* hlink_target = NULL; if (hlink && GNM_IS_HLINK_URL (hlink)) { hlink_target = gnm_hlink_get_target (hlink); } if (version == HTML32 && hidden) gsf_output_puts (output, "<!-- 'HIDDEN DATA' -->"); else { if (style != NULL) { if (gnm_style_get_font_italic (style)) gsf_output_puts (output, "<i>"); if (gnm_style_get_font_bold (style)) gsf_output_puts (output, "<b>"); if (gnm_style_get_font_uline (style) != UNDERLINE_NONE) gsf_output_puts (output, "<u>"); if (font_is_monospaced (style)) gsf_output_puts (output, "<tt>"); if (gnm_style_get_font_strike (style)) { if (version == HTML32) gsf_output_puts (output, "<strike>"); else gsf_output_puts (output, "<span style=\"text-decoration: line-through;\">"); } switch (gnm_style_get_font_script (style)) { case GO_FONT_SCRIPT_SUB: gsf_output_puts (output, "<sub>"); break; case GO_FONT_SCRIPT_SUPER: gsf_output_puts (output, "<sup>"); break; default: break; } } if (hlink_target) gsf_output_printf (output, "<a href=\"%s\">", hlink_target); if (cell != NULL) { const PangoAttrList * markup = NULL; if (style != NULL && version != HTML40) { html_get_text_color (cell, style, &r, &g, &b); if (r > 0 || g > 0 || b > 0) gsf_output_printf (output, "<font color=\"#%02X%02X%02X\">", r, g, b); } if (VALUE_IS_STRING (cell->value) && (VALUE_FMT (cell->value) != NULL) && go_format_is_markup (VALUE_FMT (cell->value))) markup = go_format_get_markup (VALUE_FMT (cell->value)); if (markup != NULL) { GString *str = g_string_new (""); value_get_as_gstring (cell->value, str, NULL); html_new_markup (output, markup, str->str, version); g_string_free (str, TRUE); } else { rendered_string = gnm_cell_get_rendered_text (cell); html_print_encoded (output, rendered_string); g_free (rendered_string); } } if (r > 0 || g > 0 || b > 0) gsf_output_puts (output, "</font>"); if (hlink_target) gsf_output_puts (output, "</a>"); if (style != NULL) { if (gnm_style_get_font_strike (style)) { if (version == HTML32) gsf_output_puts (output, "</strike>"); else gsf_output_puts (output, "</span>"); } switch (gnm_style_get_font_script (style)) { case GO_FONT_SCRIPT_SUB: gsf_output_puts (output, "</sub>"); break; case GO_FONT_SCRIPT_SUPER: gsf_output_puts (output, "</sup>"); break; default: break; } if (font_is_monospaced (style)) gsf_output_puts (output, "</tt>"); if (gnm_style_get_font_uline (style) != UNDERLINE_NONE) gsf_output_puts (output, "</u>"); if (gnm_style_get_font_bold (style)) gsf_output_puts (output, "</b>"); if (gnm_style_get_font_italic (style)) gsf_output_puts (output, "</i>"); } } }
/** * wbcg_edit_start: * @wbcg: The workbook to be edited. * @blankp: If true, erase current cell contents first. If false, leave the * contents alone. * @cursorp: If true, create an editing cursor in the current sheet. (If * false, the text will be editing in the edit box above the sheet, * but this is not handled by this function.) * * Initiate editing of a cell in the sheet. Note that we have two modes of * editing: * 1) in-cell editing when you just start typing, and * 2) above sheet editing when you hit F2. * * Returns TRUE if we did indeed start editing. Returns FALSE if the * cell-to-be-edited was locked. */ gboolean wbcg_edit_start (WBCGtk *wbcg, gboolean blankp, gboolean cursorp) { /* We could save this, but the situation is rare, if confusing. */ static gboolean warn_on_text_format = TRUE; SheetView *sv; SheetControlGUI *scg; GnmCell *cell; char *text = NULL; int col, row; WorkbookView *wbv; int cursor_pos = -1; g_return_val_if_fail (GNM_IS_WBC_GTK (wbcg), FALSE); if (wbcg_is_editing (wbcg)) return TRUE; /* Avoid recursion, and do not begin editing if a guru is up */ if (wbcg->inside_editing || wbc_gtk_get_guru (wbcg) != NULL) return TRUE; wbcg->inside_editing = TRUE; wbv = wb_control_view (GNM_WBC (wbcg)); sv = wb_control_cur_sheet_view (GNM_WBC (wbcg)); scg = wbcg_cur_scg (wbcg); col = sv->edit_pos.col; row = sv->edit_pos.row; /* don't edit a locked cell */ /* TODO : extend this to disable edits that cannot succeed * like editing a single cell of an array. I think we have enough * information if we look at the selection. */ if (wb_view_is_protected (wbv, TRUE) && gnm_style_get_contents_locked (sheet_style_get (sv->sheet, col, row))) { char *pos = g_strdup_printf ( _("%s!%s is locked"), sv->sheet->name_quoted, cell_coord_name (col, row)); go_cmd_context_error_invalid (GO_CMD_CONTEXT (wbcg), pos, wb_view_is_protected (wbv, FALSE) ? _("Unprotect the workbook to enable editing.") : _("Unprotect the sheet to enable editing.")); wbcg->inside_editing = FALSE; g_free (pos); return FALSE; } cell = sheet_cell_get (sv->sheet, col, row); if (cell && warn_on_text_format && go_format_is_text (gnm_cell_get_format (cell)) && (gnm_cell_has_expr (cell) || !VALUE_IS_STRING (cell->value))) { gint res; /* Using GtkResponseType would yield a warning on the switch */ GtkWidget *check; GtkWidget *align; GtkWidget *d = gnm_message_dialog_create (wbcg_toplevel (wbcg), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_WARNING, _("You are about to edit a cell with \"text\" format."), _("The cell does not currently contain text, though, so if " "you go on editing then the contents will be turned into " "text.")); gtk_dialog_add_button (GTK_DIALOG (d), GTK_STOCK_EDIT, GTK_RESPONSE_OK); go_gtk_dialog_add_button (GTK_DIALOG (d), _("Remove format"), GTK_STOCK_REMOVE, GNM_RESPONSE_REMOVE); gtk_dialog_add_button (GTK_DIALOG (d), GNM_STOCK_CANCEL, GTK_RESPONSE_CANCEL); gtk_dialog_set_default_response (GTK_DIALOG (d), GTK_RESPONSE_CANCEL); check = gtk_check_button_new_with_label (_("Show this dialog next time.")); g_signal_connect (check, "toggled", G_CALLBACK (cb_warn_toggled), &warn_on_text_format); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (check), TRUE); align = gtk_alignment_new (0.5, 0.5, 0, 0); gtk_container_add (GTK_CONTAINER (align), check); gtk_widget_show_all (align); gtk_box_pack_end (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (d))), align, TRUE, TRUE, 0); res = go_gtk_dialog_run (GTK_DIALOG (d), wbcg_toplevel (wbcg)); switch (res) { case GNM_RESPONSE_REMOVE: { GnmStyle *style = gnm_style_new (); gnm_style_set_format (style, go_format_general ()); if (!cmd_selection_format (GNM_WBC (wbcg), style, NULL, NULL)) break; /* Fall through. */ } default: case GTK_RESPONSE_CANCEL: wbcg->inside_editing = FALSE; return FALSE; case GTK_RESPONSE_OK: break; } } gnm_app_clipboard_unant (); if (blankp) gtk_entry_set_text (wbcg_get_entry (wbcg), ""); else if (cell != NULL) { gboolean quoted = FALSE; text = gnm_cell_get_text_for_editing (cell, sv->sheet, "ed, &cursor_pos); if (text) gtk_entry_set_text (wbcg_get_entry (wbcg), text); if (cell->value != NULL) { GOFormat const *fmt = VALUE_FMT (cell->value); if (fmt != NULL && go_format_is_markup (fmt)) { PangoAttrList *markup = pango_attr_list_copy ((PangoAttrList *)go_format_get_markup (fmt)); if (quoted) go_pango_attr_list_open_hole (markup, 0, 1); wbcg_edit_init_markup (wbcg, markup); } } } gnm_expr_entry_set_scg (wbcg->edit_line.entry, scg); gnm_expr_entry_set_flags (wbcg->edit_line.entry, GNM_EE_SHEET_OPTIONAL | GNM_EE_FORMULA_ONLY, GNM_EE_SINGLE_RANGE | GNM_EE_SHEET_OPTIONAL | GNM_EE_FORMULA_ONLY | GNM_EE_FORCE_REL_REF | GNM_EE_FORCE_ABS_REF); scg_edit_start (scg); /* Redraw the cell contents in case there was a span */ sheet_redraw_region (sv->sheet, col, row, col, row); if (cursorp && /* autocompletion code will not work in the edit line */ wbv->do_auto_completion && (text == NULL || g_unichar_isalpha (g_utf8_get_char (text)))) { wbcg->auto_complete = gnm_complete_sheet_new ( sv->sheet, col, row, workbook_edit_complete_notify, wbcg); wbcg->auto_completing = TRUE; wbcg->auto_max_size = 0; } else wbcg->auto_complete = NULL; /* Give the focus to the edit line */ if (!cursorp) gtk_window_set_focus (wbcg_toplevel (wbcg), (GtkWidget *) wbcg_get_entry (wbcg)); wbcg->editing = TRUE; wbcg->editing_sheet = sv->sheet; wbcg->editing_cell = cell; /* If this assert fails, it means editing was not shut down * properly before */ g_return_val_if_fail (wbcg->edit_line.signal_changed == 0, TRUE); wbcg->edit_line.signal_changed = g_signal_connect ( G_OBJECT (wbcg_get_entry (wbcg)), "changed", G_CALLBACK (cb_entry_changed), wbcg); wbcg->edit_line.signal_insert = g_signal_connect ( G_OBJECT (wbcg_get_entry (wbcg)), "insert-text", G_CALLBACK (cb_entry_insert_text), wbcg); wbcg->edit_line.signal_delete = g_signal_connect ( G_OBJECT (wbcg_get_entry (wbcg)), "delete-text", G_CALLBACK (cb_entry_delete_text), wbcg); wbcg->edit_line.signal_cursor_pos = g_signal_connect_swapped ( G_OBJECT (wbcg_get_entry (wbcg)), "notify::cursor-position", G_CALLBACK (cb_entry_cursor_pos), wbcg); wbcg->edit_line.signal_selection_bound = g_signal_connect_swapped ( G_OBJECT (wbcg_get_entry (wbcg)), "notify::selection-bound", G_CALLBACK (cb_entry_cursor_pos), wbcg); g_free (text); wb_control_update_action_sensitivity (GNM_WBC (wbcg)); wbcg->inside_editing = FALSE; gtk_editable_set_position (GTK_EDITABLE (wbcg_get_entry (wbcg)), cursor_pos); return TRUE; }