static void draw_function_marker (GnmItemGrid *ig, GnmCell const *cell, cairo_t *cr, double x, double y, double w, double h, int const dir) { int size = ig->function_marker_size; if (cell == NULL || !gnm_cell_has_expr (cell)) return; cairo_save (cr); cairo_new_path (cr); cairo_rectangle (cr, x, y, w+1, h+1); cairo_clip (cr); cairo_new_path (cr); if (dir > 0) { cairo_move_to (cr, x, y); cairo_line_to (cr, x + size, y); cairo_arc (cr, x, y, size, 0., M_PI / 2.); } else { cairo_move_to (cr, x + w, y); cairo_line_to (cr, x + w, y + size); cairo_arc (cr, x + w, y, size, M_PI/2., M_PI); } cairo_close_path (cr); gdk_cairo_set_source_rgba (cr, &ig->function_marker_color); cairo_fill_preserve (cr); gdk_cairo_set_source_rgba (cr, &ig->function_marker_border_color); cairo_set_line_width (cr, 0.5); cairo_stroke (cr); cairo_restore (cr); }
static GnmValue * cb_clipboard_prepend_cell (GnmCellIter const *iter, GnmCellRegion *cr) { GnmRange a; GnmCellCopy *copy = gnm_cell_copy_new (cr, iter->pp.eval.col - cr->base.col, iter->pp.eval.row - cr->base.row); copy->val = value_dup (iter->cell->value); if (gnm_cell_has_expr (iter->cell)) { gnm_expr_top_ref (copy->texpr = iter->cell->base.texpr); /* Check for array division */ if (!cr->not_as_contents && gnm_cell_array_bound (iter->cell, &a) && (a.start.col < cr->base.col || a.start.row < cr->base.row || a.end.col >= (cr->base.col + cr->cols) || a.end.row >= (cr->base.row + cr->rows))) cr->not_as_contents = TRUE; } else copy->texpr = NULL; return NULL; }
static gboolean cell_has_expr_or_number_or_blank (GnmCell const * cell) { return (gnm_cell_is_empty (cell) || (cell != NULL && gnm_cell_is_number (cell)) || (cell != NULL && gnm_cell_has_expr (cell))); }
static void paste_cell_with_operation (Sheet *dst_sheet, int target_col, int target_row, GnmExprRelocateInfo const *rinfo, GnmCellCopy const *src, int paste_flags) { GnmCell *dst; GnmExprOp op; if (src->texpr == NULL && !VALUE_IS_EMPTY (src->val) && !VALUE_IS_NUMBER (src->val)) return; dst = sheet_cell_fetch (dst_sheet, target_col, target_row); if (!cell_has_expr_or_number_or_blank (dst)) return; op = paste_op_to_expr_op (paste_flags); /* FIXME : This does not handle arrays, linked cells, ranges, etc. */ if ((paste_flags & PASTE_CONTENTS) && (NULL != src->texpr || gnm_cell_has_expr (dst))) { GnmExpr const *old_expr = contents_as_expr (dst->base.texpr, dst->value); GnmExpr const *copied_expr = contents_as_expr (src->texpr, src->val); GnmExprTop const *res = gnm_expr_top_new (gnm_expr_new_binary (old_expr, op, copied_expr)); GnmExprTop const *relo = gnm_expr_top_relocate (res, rinfo, FALSE); if (relo) { gnm_cell_set_expr (dst, relo); gnm_expr_top_unref (relo); } else gnm_cell_set_expr (dst, res); gnm_expr_top_unref (res); } else { GnmValue *value; GnmEvalPos pos; GnmExpr const *expr = gnm_expr_new_binary ( gnm_expr_new_constant (value_dup (dst->value)), op, gnm_expr_new_constant (value_dup (src->val))); GnmExprTop const *texpr = gnm_expr_top_new (expr); eval_pos_init_cell (&pos, dst); pos.dep = NULL; /* no dynamic deps */ value = gnm_expr_top_eval (texpr, &pos, GNM_EXPR_EVAL_SCALAR_NON_EMPTY); gnm_expr_top_unref (texpr); gnm_cell_set_value (dst, value); } }
/** * sv_select_cur_inputs : * @sv: The sheet * * Select all cells that are direct potential inputs to the * current cell. **/ void sv_select_cur_inputs (SheetView *sv) { GnmCell *cell; GSList *ranges, *ptr; GnmEvalPos ep; g_return_if_fail (IS_SHEET_VIEW (sv)); cell = sheet_cell_get (sv->sheet, sv->edit_pos.col, sv->edit_pos.row); if (cell == NULL || !gnm_cell_has_expr (cell)) return; ranges = gnm_expr_top_get_ranges (cell->base.texpr); if (ranges == NULL) return; ep.eval = sv->edit_pos; ep.sheet = sv->sheet; ep.dep = NULL; sv_selection_reset (sv); for (ptr = ranges ; ptr != NULL ; ptr = ptr->next) { GnmValue *v = ptr->data; GnmRangeRef const *r = value_get_rangeref (v); #warning "FIXME: What do we do in these 3D cases?" if (r->a.sheet != r->b.sheet) continue; if (r->a.sheet != NULL && r->a.sheet != sv->sheet) continue; sv_selection_add_full (sv, gnm_cellref_get_col (&r->a, &ep), gnm_cellref_get_row (&r->a, &ep), gnm_cellref_get_col (&r->a, &ep), gnm_cellref_get_row (&r->a, &ep), gnm_cellref_get_col (&r->b, &ep), gnm_cellref_get_row (&r->b, &ep)); value_release (v); } g_slist_free (ranges); sheet_update (sv->sheet); }
/** * cellspan_is_empty : * * Utility to ensure that a cell is completely empty. * - no spans * - no merged regions * - no content * * No need to check for merged cells here. We have already bounded the search region * using adjacent merged cells. * * We could probably have done the same thing with the span regions too, but * the current representation is not well suited to that type of search * returns TRUE if the cell is empty. */ static inline gboolean cellspan_is_empty (int col, GnmCell const *ok_span_cell) { CellSpanInfo const *span = row_span_get (ok_span_cell->row_info, col); GnmCell const *tmp; if (span != NULL && span->cell != ok_span_cell) return FALSE; tmp = sheet_cell_get (ok_span_cell->base.sheet, col, ok_span_cell->pos.row); /* FIXME : cannot use gnm_cell_is_empty until expressions can span. * because cells with expressions start out with value Empty * existing spans continue to flow through, but never get removed * because we don't respan expression results. */ return (tmp == NULL || tmp->value == NULL || (VALUE_IS_EMPTY (tmp->value) && !gnm_cell_has_expr(tmp))); }
/** * gnm_style_default_halign: * @style: * @c: * * Select the appropriate horizontal alignment depending on the style and cell * value. */ GnmHAlign gnm_style_default_halign (GnmStyle const *style, GnmCell const *c) { GnmHAlign align = gnm_style_get_align_h (style); GnmValue *v; if (align != GNM_HALIGN_GENERAL) return align; g_return_val_if_fail (c != NULL, GNM_HALIGN_RIGHT); if (c->base.sheet && c->base.sheet->display_formulas && gnm_cell_has_expr (c)) return GNM_HALIGN_LEFT; for (v = c->value; v != NULL ; ) switch (v->v_any.type) { case VALUE_BOOLEAN: case VALUE_ERROR: return GNM_HALIGN_CENTER; case VALUE_FLOAT: { double a = gnm_style_get_rotation (style); if (a > 0 && a < 180) return GNM_HALIGN_LEFT; return GNM_HALIGN_RIGHT; } case VALUE_ARRAY: /* Tail recurse into the array */ if (v->v_array.x > 0 && v->v_array.y > 0) { v = v->v_array.vals [0][0]; continue; } default: if (gnm_style_get_rotation (style) > 180) return GNM_HALIGN_RIGHT; return GNM_HALIGN_LEFT; } return GNM_HALIGN_RIGHT; }
static GnmValue * cb_get_content (GnmCellIter const *iter, GsfOutput *buf) { GnmCell *cell; if (NULL != (cell = iter->cell)) { char *tmp; if (gnm_cell_has_expr (cell)) tmp = gnm_expr_top_as_string (cell->base.texpr, &iter->pp, iter->pp.sheet->convs); else if (VALUE_FMT (cell->value) != NULL) tmp = format_value (NULL, cell->value, -1, workbook_date_conv (iter->pp.wb)); else tmp = value_get_as_string (cell->value); gsf_output_write (buf, strlen (tmp), tmp); g_free (tmp); } gsf_output_write (buf, 1, "\n"); return NULL; }
static void tabulate_ok_clicked (G_GNUC_UNUSED GtkWidget *widget, DialogState *dd) { GtkDialog *dialog = dd->dialog; GnmCell *resultcell; int dims = 0; int row; gboolean with_coordinates; GnmTabulateInfo *data; /* we might get the 4 below from the positon of some of the widgets inside the grid */ int nrows = 4; GnmCell **cells; gnm_float *minima, *maxima, *steps; cells = g_new (GnmCell *, nrows); minima = g_new (gnm_float, nrows); maxima = g_new (gnm_float, nrows); steps = g_new (gnm_float, nrows); for (row = 1; row < nrows; row++) { GtkEntry *e_w; GnmExprEntry *w = GNM_EXPR_ENTRY (gtk_grid_get_child_at (dd->grid, COL_CELL, row + 1)); if (!w || gnm_expr_entry_is_blank (w)) continue; cells[dims] = single_cell (dd->sheet, w); if (!cells[dims]) { go_gtk_notice_dialog (GTK_WINDOW (dd->dialog), GTK_MESSAGE_ERROR, _("You should introduce a single valid cell as dependency cell")); gnm_expr_entry_grab_focus (GNM_EXPR_ENTRY (w), TRUE); goto error; } if (gnm_cell_has_expr (cells[dims])) { go_gtk_notice_dialog (GTK_WINDOW (dd->dialog), GTK_MESSAGE_ERROR, _("The dependency cells should not contain an expression")); gnm_expr_entry_grab_focus (GNM_EXPR_ENTRY (w), TRUE); goto error; } if (get_grid_float_entry (dd->grid, row, COL_MIN, cells[dims], &(minima[dims]), &e_w, FALSE, 0.0)) { go_gtk_notice_dialog (GTK_WINDOW (dd->dialog), GTK_MESSAGE_ERROR, _("You should introduce a valid number as minimum")); focus_on_entry (e_w); goto error; } if (get_grid_float_entry (dd->grid, row, COL_MAX, cells[dims], &(maxima[dims]), &e_w, FALSE, 0.0)) { go_gtk_notice_dialog (GTK_WINDOW (dd->dialog), GTK_MESSAGE_ERROR, _("You should introduce a valid number as maximum")); focus_on_entry (e_w); goto error; } if (maxima[dims] < minima[dims]) { go_gtk_notice_dialog (GTK_WINDOW (dd->dialog), GTK_MESSAGE_ERROR, _("The maximum value should be bigger than the minimum")); focus_on_entry (e_w); goto error; } if (get_grid_float_entry (dd->grid, row, COL_STEP, cells[dims], &(steps[dims]), &e_w, TRUE, 1.0)) { go_gtk_notice_dialog (GTK_WINDOW (dd->dialog), GTK_MESSAGE_ERROR, _("You should introduce a valid number as step size")); focus_on_entry (e_w); goto error; } if (steps[dims] <= 0) { go_gtk_notice_dialog (GTK_WINDOW (dd->dialog), GTK_MESSAGE_ERROR, _("The step size should be positive")); focus_on_entry (e_w); goto error; } dims++; } if (dims == 0) { go_gtk_notice_dialog (GTK_WINDOW (dd->dialog), GTK_MESSAGE_ERROR, _("You should introduce one or more dependency cells")); goto error; } { resultcell = single_cell (dd->sheet, dd->resultrangetext); if (!resultcell) { go_gtk_notice_dialog (GTK_WINDOW (dd->dialog), GTK_MESSAGE_ERROR, _("You should introduce a single valid cell as result cell")); gnm_expr_entry_grab_focus (dd->resultrangetext, TRUE); goto error; } if (!gnm_cell_has_expr (resultcell)) { go_gtk_notice_dialog (GTK_WINDOW (dd->dialog), GTK_MESSAGE_ERROR, _("The target cell should contain an expression")); gnm_expr_entry_grab_focus (dd->resultrangetext, TRUE); goto error; } } { int i = gnm_gui_group_value (dd->gui, mode_group); with_coordinates = (i == -1) ? TRUE : (gboolean)i; } data = g_new (GnmTabulateInfo, 1); data->target = resultcell; data->dims = dims; data->cells = cells; data->minima = minima; data->maxima = maxima; data->steps = steps; data->with_coordinates = with_coordinates; if (!cmd_tabulate (GNM_WBC (dd->wbcg), data)) { gtk_widget_destroy (GTK_WIDGET (dialog)); return; } g_free (data); error: g_free (minima); g_free (maxima); g_free (steps); g_free (cells); }
static void search_get_value (gint row, gint column, gpointer _dd, GValue *value) { DialogState *dd = (DialogState *)_dd; GnumericLazyList *ll = GNUMERIC_LAZY_LIST (gtk_tree_view_get_model (dd->matches_table)); GnmSearchFilterResult *item = g_ptr_array_index (dd->matches, row); GnmCell *cell; GnmComment *comment; if (item->locus == GNM_SRL_COMMENT) { cell = NULL; comment = sheet_get_comment (item->ep.sheet, &item->ep.eval); } else { cell = sheet_cell_get (item->ep.sheet, item->ep.eval.col, item->ep.eval.row); comment = NULL; } g_value_init (value, ll->column_headers[column]); #if 0 g_print ("col=%d,row=%d\n", column, row); #endif switch (column) { case COL_SHEET: g_value_set_string (value, item->ep.sheet->name_unquoted); return; case COL_CELL: g_value_set_string (value, cellpos_as_string (&item->ep.eval)); return; case COL_TYPE: switch (item->locus) { case GNM_SRL_COMMENT: g_value_set_static_string (value, _("Comment")); return; case GNM_SRL_VALUE: g_value_set_static_string (value, _("Result")); return; case GNM_SRL_CONTENTS: { GnmValue *v = cell ? cell->value : NULL; char const *type; gboolean is_expr = cell && gnm_cell_has_expr (cell); gboolean is_value = !is_expr && !gnm_cell_is_empty (cell) && v; if (!cell) type = _("Deleted"); else if (is_expr) type = _("Expression"); else if (is_value && VALUE_IS_STRING (v)) type = _("String"); else if (is_value && VALUE_IS_FLOAT (v)) type = _("Number"); else type = _("Other value"); g_value_set_static_string (value, type); return; } #ifndef DEBUG_SWITCH_ENUM default: g_assert_not_reached (); #endif } case COL_CONTENTS: switch (item->locus) { case GNM_SRL_COMMENT: if (comment) g_value_set_string (value, cell_comment_text_get (comment)); else g_value_set_static_string (value, _("Deleted")); return; case GNM_SRL_VALUE: if (cell && cell->value) g_value_take_string (value, value_get_as_string (cell->value)); else g_value_set_static_string (value, _("Deleted")); return; case GNM_SRL_CONTENTS: if (cell) g_value_take_string (value, gnm_cell_get_entered_text (cell)); else g_value_set_static_string (value, _("Deleted")); return; #ifndef DEBUG_SWITCH_ENUM default: g_assert_not_reached (); #endif } #ifndef DEBUG_SWITCH_ENUM default: g_assert_not_reached (); #endif } }
/** * 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; }
/** * cb_dialog_apply_clicked: * @button: * @state: * * Close (destroy) the dialog **/ static void cb_dialog_apply_clicked (G_GNUC_UNUSED GtkWidget *button, GoalSeekState *state) { char *status_str; GoalSeekStatus status; GnmValue *target; GnmRangeRef const *r; GOFormat *format; if (state->warning_dialog != NULL) gtk_widget_destroy (state->warning_dialog); /* set up source */ target = gnm_expr_entry_parse_as_value (state->set_cell_entry, state->sheet); if (target == NULL) { go_gtk_notice_nonmodal_dialog (GTK_WINDOW(state->dialog), &(state->warning_dialog), GTK_MESSAGE_ERROR, _("You should introduce a valid cell " "name in 'Set Cell:'!")); gnm_expr_entry_grab_focus (state->set_cell_entry, TRUE); return; } r = &target->v_range.cell; state->set_cell = sheet_cell_get (r->a.sheet, r->a.col, r->a.row); value_release (target); if (state->set_cell == NULL || !gnm_cell_has_expr (state->set_cell)) { go_gtk_notice_nonmodal_dialog (GTK_WINDOW(state->dialog), &(state->warning_dialog), GTK_MESSAGE_ERROR, _("The cell named in 'Set Cell:' " "must contain a formula!")); gnm_expr_entry_grab_focus (state->set_cell_entry, TRUE); return; } /* set up source */ target = gnm_expr_entry_parse_as_value (state->change_cell_entry, state->sheet); if (target == NULL) { go_gtk_notice_nonmodal_dialog (GTK_WINDOW(state->dialog), &(state->warning_dialog), GTK_MESSAGE_ERROR, _("You should introduce a valid cell " "name in 'By Changing Cell:'!")); gnm_expr_entry_grab_focus (state->change_cell_entry, TRUE); return; } r = &target->v_range.cell; state->change_cell = sheet_cell_fetch (r->a.sheet, r->a.col, r->a.row); value_release (target); if (gnm_cell_has_expr (state->change_cell)) { go_gtk_notice_nonmodal_dialog (GTK_WINDOW(state->dialog), &(state->warning_dialog), GTK_MESSAGE_ERROR, _("The cell named in 'By changing cell' " "must not contain a formula.")); gnm_expr_entry_grab_focus (state->change_cell_entry, TRUE); return; } format = gnm_style_get_format (gnm_cell_get_style (state->set_cell)); if (entry_to_float_with_format (GTK_ENTRY(state->to_value_entry), &state->target_value, TRUE, format)){ go_gtk_notice_nonmodal_dialog (GTK_WINDOW(state->dialog), &(state->warning_dialog), GTK_MESSAGE_ERROR, _("The value given in 'To Value:' " "is not valid.")); focus_on_entry (GTK_ENTRY(state->to_value_entry)); return; } format = gnm_style_get_format (gnm_cell_get_style (state->change_cell)); if (entry_to_float_with_format (GTK_ENTRY(state->at_least_entry), &state->xmin, TRUE, format)) { state->xmin = -max_range_val; gtk_entry_set_text (GTK_ENTRY (state->at_least_entry), ""); } if (entry_to_float_with_format (GTK_ENTRY(state->at_most_entry), &state->xmax, TRUE, format)) { state->xmax = +max_range_val; gtk_entry_set_text (GTK_ENTRY (state->at_most_entry), ""); } if ((state->old_cell != NULL) && (state->old_value != NULL)) { sheet_cell_set_value (state->old_cell, state->old_value); workbook_recalc (state->wb); state->old_value = NULL; } state->old_cell = state->change_cell; state->old_value = value_dup (state->change_cell->value); status = gnumeric_goal_seek (state); switch (status) { case GOAL_SEEK_OK: { const char *actual_str; const char *solution_str; GOFormat *format = go_format_general (); GnmValue *error_value = value_new_float (state->target_value - value_get_as_float (state->set_cell->value)); char *target_str = format_value (format, error_value, NULL, -1, workbook_date_conv (state->wb)); gtk_label_set_text (GTK_LABEL (state->target_value_label), target_str); g_free (target_str); value_release (error_value); status_str = g_strdup_printf (_("Goal seeking with cell %s found a solution."), cell_name (state->set_cell)); gtk_label_set_text (GTK_LABEL (state->result_label), status_str); g_free (status_str); /* FIXME? Do a format? */ actual_str = state->set_cell->value ? value_peek_string (state->set_cell->value) : ""; gtk_label_set_text (GTK_LABEL (state->current_value_label), actual_str); solution_str = state->change_cell->value ? value_peek_string (state->change_cell->value) : ""; gtk_label_set_text (GTK_LABEL (state->solution_label), solution_str); break; } default: status_str = g_strdup_printf (_("Goal seeking with cell %s did not find a solution."), cell_name (state->set_cell)); gtk_label_set_text (GTK_LABEL (state->result_label), status_str); g_free (status_str); gtk_label_set_text (GTK_LABEL (state->current_value_label), ""); gtk_label_set_text (GTK_LABEL (state->solution_label), ""); gtk_label_set_text (GTK_LABEL (state->target_value_label), ""); break; } state->cancelled = FALSE; gtk_widget_show (state->result_table); return; }
int gnumeric_sheet_get_cell(GnumericSheetPtr sheet, int x, int y, GSheetCellPtr cell) { gsheetcell_zero(cell); GnmValue const *value = sheet_cell_get_value((Sheet*)sheet,x,y); if (value==NULL) return 0; if (value->type == VALUE_EMPTY) return 0; GnmCell const *gcell = sheet_cell_get((Sheet*)sheet,x,y); if (gcell) { if (gnm_cell_has_expr (gcell)) { if (gcell->base.texpr->expr) { const GnmExpr *expr = gcell->base.texpr->expr; if (expr) { if (expr->oper==GNM_EXPR_OP_FUNCALL) { if (expr->func.func) { const char *name = expr->func.func->name; if (name) { if (strcasecmp(name,"hyperlink")==0) { // Hyperlink. Take url part. char *url = NULL; char *txt = NULL; if (expr->func.argc==2) { const GnmExpr *expr0 = expr->func.argv[0]; if (expr0) { if (expr0->oper == GNM_EXPR_OP_CONSTANT) { url = value_get_as_string(expr0->constant.value); } } const GnmExpr *expr1 = expr->func.argv[1]; if (expr1) { if (expr1->oper == GNM_EXPR_OP_CONSTANT) { txt = value_get_as_string(expr1->constant.value); } } } if (url&&txt) { if (strcasecmp(url,txt)==0) { cell->all = url; cell->url = g_strdup(url); cell->txt = g_strdup(url); cell->is_url = 1; return 0; } cell->all = g_strconcat("[",url,"|",txt,"]",NULL); cell->url = url; cell->txt = txt; cell->is_url = 1; return 0; } else { if (url) g_free(url); if (txt) g_free(txt); } } } } } } } //return gnm_cell_get_entered_text(cell); } } GnmStyle const *style = sheet_style_get((Sheet*)sheet,x,y); GnmHLink* hlink = gnm_style_get_hlink (style); const guchar* hlink_target = NULL; if (hlink && IS_GNM_HLINK_URL (hlink)) { hlink_target = gnm_hlink_get_target (hlink); if (hlink_target) { //char *str = value_get_as_string(value); //if (!str) return str; //const char *str2 = " "; //char *result = g_strconcat(str,str2,hlink_target); //g_free(str); //return result; cell->is_url = 1; cell->all = g_strdup(hlink_target); cell->url = g_strdup(hlink_target); cell->txt = g_strdup(hlink_target); return 0; } } cell->all = value_get_as_string(value); return 0; }