Ejemplo n.º 1
0
static void
cb_dialog_goto_selection_changed (GtkTreeSelection *the_selection, GotoState *state)
{
	GtkTreeIter  iter;
	GtkTreeModel *model;
	Sheet        *sheet;
	GnmNamedExpr *name;

	if (gtk_tree_selection_get_selected (the_selection, &model, &iter)) {
		gtk_tree_model_get (model, &iter,
				    SHEET_POINTER, &sheet,
				    EXPRESSION, &name,
				    -1);
		if (name && gnm_expr_top_is_rangeref (name->texpr)) {
			GnmParsePos pp;
			char *where_to;

			if (NULL == sheet)
				sheet = wb_control_cur_sheet ( GNM_WBC (state->wbcg));

			parse_pos_init_sheet (&pp, sheet);
			where_to = expr_name_as_string  (name, &pp, gnm_conventions_default);
			if (wb_control_parse_and_jump (GNM_WBC (state->wbcg), where_to))
				gtk_entry_set_text (state->goto_text,
						    where_to);
			g_free (where_to);
			return;
		}
		if (sheet)
			wb_view_sheet_focus (
				wb_control_view (GNM_WBC (state->wbcg)), sheet);
	}
}
Ejemplo n.º 2
0
void
dialog_workbook_attr (WBCGtk *wbcg)
{
	GtkBuilder   *gui;
	AttrState    *state;

	g_return_if_fail (wbcg != NULL);

	if (gnm_dialog_raise_if_exists (wbcg, WORKBOOK_ATTRIBUTE_KEY))
		return;

	gui = gnm_gtk_builder_load ("res:ui/workbook-attr.ui", NULL, GO_CMD_CONTEXT (wbcg));
        if (gui == NULL)
                return;

	/* Initialize */
	state = g_new (AttrState, 1);
	state->gui = gui;
	state->wbcg = wbcg;
	state->wbv  = wb_control_view (GNM_WBC (wbcg));
	state->wb   = wb_control_get_workbook (GNM_WBC (wbcg));

	attr_dialog_impl (state);

	/* Select the same page the last invocation used */
	attr_dialog_select_page (state, attr_dialog_page);
}
Ejemplo n.º 3
0
void
dialog_data_table (WBCGtk *wbcg)
{
	GnmDialogDataTable *state;
	GnmRange const	*r;
	GnmRange	 input_range;
	SheetView	*sv;
	Sheet		*sheet;

	g_return_if_fail (wbcg != NULL);

	if (wbc_gtk_get_guru (wbcg) ||
	    gnm_dialog_raise_if_exists (wbcg, DIALOG_DATA_TABLE_KEY))
		return;

	sv = wb_control_cur_sheet_view (GNM_WBC (wbcg));
	r = selection_first_range (sv, GO_CMD_CONTEXT (wbcg), _("Create Data Table"));
	if (NULL == r)
		return;
	if (range_width	(r) <= 1 || range_height (r) <= 1) {
		GError *msg = g_error_new (go_error_invalid(), 0,
			_("The selection must have more than 1 column and row to create a Data Table."));
		go_cmd_context_error (GO_CMD_CONTEXT (wbcg), msg);
		g_error_free (msg);
		return;
	}
	input_range = *r;
	input_range.start.col++;
	input_range.start.row++;
	sheet = sv_sheet (sv);
	if (sheet_range_splits_region (sheet, &input_range, NULL,
				       GO_CMD_CONTEXT (wbcg), _("Data Table")))
		return;
	if (cmd_cell_range_is_locked_effective
	    (sheet, &input_range, GNM_WBC (wbcg),
					   _("Data Table")))
		return;


	state = g_new0 (GnmDialogDataTable, 1);
	state->wbcg  = wbcg;
	state->sheet = sheet;
	state->input_range = input_range;
	if (data_table_init (state, wbcg)) {
		go_gtk_notice_dialog (wbcg_toplevel (wbcg), GTK_MESSAGE_ERROR,
			_("Could not create the Data Table definition dialog."));
		g_free (state);
	}
}
Ejemplo n.º 4
0
/**
 * wbcg_insert_object:
 * @wbcg: #WBCGtk *
 * @so: The object the needs to be placed
 *
 * Takes a newly created #SheetObject that has not yet been realized and
 * prepares to place it on the sheet.
 *
 * NOTE : Absorbs a reference to the object.
 **/
void
wbcg_insert_object (WBCGtk *wbcg, SheetObject *so)
{
	int i, npages;
	SheetControlGUI *scg;

	g_return_if_fail (GNM_IS_WBC_GTK (wbcg));
	g_return_if_fail (GNM_IS_SO (so));

	wbcg_insert_object_clear (wbcg);

	npages = wbcg_get_n_scg (wbcg);
	for (i = 0; i < npages; i++) {
		if (NULL != (scg = wbcg_get_nth_scg (wbcg, i))) {
			scg_object_unselect (scg, NULL);
			scg_cursor_visible (scg, FALSE);
			scg_set_display_cursor (scg);
			sc_unant (GNM_SC (scg));
		}
	}
	/* we can't set wbcg->new_object before now because if one sheet has a
	 * selected object, the new object will be destroyed by the loop
	 * above. See #669648. */
	wbcg->new_object = so;
	wb_control_update_action_sensitivity (GNM_WBC (wbcg));
}
Ejemplo n.º 5
0
/**
 * dialog_advanced_filter:
 * @wbcg:
 * @sheet:
 *
 * Show the dialog (guru).
 *
 **/
void
dialog_advanced_filter (WBCGtk *wbcg)
{
        AdvancedFilterState *state;
	WorkbookControl *wbc;

	g_return_if_fail (wbcg != NULL);

	wbc = GNM_WBC (wbcg);

	/* Only pop up one copy per workbook */
	if (gnm_dialog_raise_if_exists (wbcg, ADVANCED_FILTER_KEY))
		return;

	state = g_new (AdvancedFilterState, 1);

	if (dialog_tool_init (state, wbcg, wb_control_cur_sheet (wbc),
			      GNUMERIC_HELP_LINK_ADVANCED_FILTER,
			      "advanced-filter.ui", "Filter",
			      _("Could not create the Advanced Filter dialog."),
			      ADVANCED_FILTER_KEY,
			      G_CALLBACK (advanced_filter_ok_clicked_cb), NULL,
			      G_CALLBACK (advanced_filter_update_sensitivity_cb),
			      0))
		return;

	gnm_dao_set_inplace (GNM_DAO (state->gdao), _("Filter _in-place"));
	gnm_dao_set_put (GNM_DAO (state->gdao), FALSE, FALSE);
	advanced_filter_update_sensitivity_cb (NULL, state);
	tool_load_selection ((GenericToolState *)state, TRUE);

        return;
}
Ejemplo n.º 6
0
void
dialog_goto_cell (WBCGtk *wbcg)
{
	GotoState* state;
	GtkBuilder *gui;

	g_return_if_fail (wbcg != NULL);

	if (gnm_dialog_raise_if_exists (wbcg, GOTO_KEY))
		return;
	gui = gnm_gtk_builder_load ("goto.ui", NULL, GO_CMD_CONTEXT (wbcg));
        if (gui == NULL)
                return;

	state = g_new (GotoState, 1);
	state->wbcg   = wbcg;
	state->wb     = wb_control_get_workbook (GNM_WBC (wbcg));
	state->gui    = gui;
        state->dialog = go_gtk_builder_get_widget (state->gui, "goto_dialog");

	if (dialog_goto_init (state)) {
		go_gtk_notice_dialog (wbcg_toplevel (wbcg), GTK_MESSAGE_ERROR,
				 _("Could not create the goto dialog."));
		g_free (state);
		return;
	}

	gnm_keyed_dialog (state->wbcg, GTK_WINDOW (state->dialog),
			       GOTO_KEY);

	gtk_widget_show_all (state->dialog);
}
Ejemplo n.º 7
0
static void
dialog_goto_load_selection (GotoState *state)
{
	SheetView *sv = wb_control_cur_sheet_view
		(GNM_WBC (state->wbcg));
	GnmRange const *first = selection_first_range (sv, NULL, NULL);

	if (first != NULL) {
		gint rows = range_height (first);
		gint cols = range_width (first);
		GnmConventionsOut out;
		GString *str = g_string_new (NULL);
		GnmParsePos pp;
		GnmRangeRef rr;

		out.accum = str;
		out.pp = parse_pos_init_sheet (&pp, sv->sheet);
		out.convs = sheet_get_conventions (sv->sheet);
		gnm_cellref_init (&rr.a, NULL, first->start.col,
				  first->start.row, TRUE);
		gnm_cellref_init (&rr.b, NULL, first->start.col,
				  first->start.row, TRUE);
		rangeref_as_string (&out, &rr);
		gtk_entry_set_text (state->goto_text, str->str);
		gtk_editable_select_region (GTK_EDITABLE (state->goto_text),
					    0, -1);
		g_string_free (str, TRUE);
		cb_dialog_goto_update_sensitivity (NULL, state);
		gtk_spin_button_set_value (state->spin_rows, rows);
		gtk_spin_button_set_value (state->spin_cols, cols);
	} else
		cb_dialog_goto_update_sensitivity (NULL, state);

}
Ejemplo n.º 8
0
static void
wbcg_edit_attach_guru_main (WBCGtk *wbcg, GtkWidget *guru)
{
	WorkbookControl *wbc = GNM_WBC (wbcg);

	g_return_if_fail (guru != NULL);
	g_return_if_fail (GNM_IS_WBC_GTK (wbcg));
	g_return_if_fail (wbcg->edit_line.guru == NULL);

	/* Make sure we don't have anything anted.
	 * this protects against two anted regions showing up
	 */
	gnm_app_clipboard_unant ();

	/* don't set end 'End' mode when a dialog comes up */
	wbcg_set_end_mode (wbcg, FALSE);

	wbcg->edit_line.guru = guru;
	gtk_editable_set_editable (GTK_EDITABLE (wbcg_get_entry (wbcg)), FALSE);
	wb_control_update_action_sensitivity (wbc);
	wb_control_menu_state_update (wbc, MS_GURU_MENU_ITEMS);

	g_signal_connect_object (guru, "destroy",
		G_CALLBACK (wbc_gtk_detach_guru), wbcg, G_CONNECT_SWAPPED);
}
Ejemplo n.º 9
0
/**
 * random_cor_tool_ok_clicked_cb:
 * @button:
 * @state:
 *
 * Retrieve the information from the dialog and call the appropriate tool.
 * Note that we assume that the ok_button is only active if the entry fields
 * contain sensible data.
 **/
static void
random_cor_tool_ok_clicked_cb (GtkWidget *button, RandomCorToolState *state)
{
	data_analysis_output_t  *dao;
	tools_data_random_cor_t  *data;
	gint err;

	data = g_new0 (tools_data_random_cor_t, 1);

	dao  = parse_output ((GnmGenericToolState *)state, NULL);
	err = entry_to_int (GTK_ENTRY (state->count_entry), &data->count, FALSE);
	data->matrix = gnm_expr_entry_parse_as_value
		(GNM_EXPR_ENTRY (state->base.input_entry),
		 state->base.sheet);

	data->variables = data->matrix->v_range.cell.b.row -
		data->matrix->v_range.cell.a.row + 1;

	data->matrix_type = gnm_gui_group_value
		(state->base.gui, matrix_group);


	if (!cmd_analysis_tool (GNM_WBC (state->base.wbcg),
				state->base.sheet,
				dao, data, tool_random_cor_engine, TRUE) &&
	    (button == state->base.ok_button))
		gtk_widget_destroy (state->base.dialog);
}
Ejemplo n.º 10
0
static void
solver_add_scenario (SolverState *state, GnmSolverResult *res, gchar const *name)
{
	GnmSolverParameters *param = state->sheet->solver_parameters;
	GnmValue const *vinput;
	GnmScenario *sc;
	GnmSheetRange sr;
	WorkbookControl *wbc = GNM_WBC (state->wbcg);

	vinput = gnm_solver_param_get_input (param);
	gnm_sheet_range_from_value (&sr, vinput);

	sc = gnm_sheet_scenario_new (param->sheet, name);
	switch (res->quality) {
	case GNM_SOLVER_RESULT_OPTIMAL:
		gnm_scenario_set_comment
			(sc, _("Optimal solution created by solver.\n"));
		break;
	case GNM_SOLVER_RESULT_FEASIBLE:
		gnm_scenario_set_comment
			(sc, _("Feasible solution created by solver.\n"));
		break;
	default:
		break;
	}
	gnm_scenario_add_area (sc, &sr);

	cmd_scenario_add (wbc, sc, sc->sheet);
}
Ejemplo n.º 11
0
static void
cb_append_clicked (G_GNUC_UNUSED GtkWidget *ignore, SheetManager *state)
{
	WorkbookSheetState *old_state;
	WorkbookControl *wbc = GNM_WBC (state->wbcg);
	Workbook *wb = wb_control_get_workbook (wbc);
	GtkTreeIter iter;
	Sheet *sheet, *old_sheet;

	workbook_signals_block (state);

	old_state = workbook_sheet_state_new (wb);
	old_sheet = workbook_sheet_by_index (wb, 0);
	workbook_sheet_add (wb, -1,
			    gnm_sheet_get_max_cols (old_sheet),
			    gnm_sheet_get_max_rows (old_sheet));
	cmd_reorganize_sheets (wbc, old_state, NULL);
	update_undo (state, wbc);

	workbook_signals_unblock (state);

	sheet = workbook_sheet_by_index (wb, workbook_sheet_count (wb) - 1);

	g_signal_handler_block (state->model, state->model_row_insertion_listener);
	gtk_list_store_append (state->model, &iter);
	g_signal_handler_unblock (state->model, state->model_row_insertion_listener);

	set_sheet_info_at_iter (state, &iter, sheet);

	cb_selection_changed (NULL, state);
}
Ejemplo n.º 12
0
static void
dialog_sheet_order_changed (SheetManager *state)
{
	WorkbookControl *wbc = GNM_WBC (state->wbcg);
	Workbook *wb = wb_control_get_workbook (wbc);
	WorkbookSheetState *old_state;
	GtkTreeIter this_iter;
	gint n = 0, changes = 0;

	workbook_signals_block (state);

	old_state = workbook_sheet_state_new (wb);
	while (gtk_tree_model_iter_nth_child  (GTK_TREE_MODEL (state->model),
					       &this_iter, NULL, n)) {
		Sheet *this_sheet;
		gtk_tree_model_get (GTK_TREE_MODEL (state->model), &this_iter,
				    SHEET_POINTER, &this_sheet,
				    -1);
		if (this_sheet->index_in_wb != n) {
			changes++;
			workbook_sheet_move (this_sheet, n - this_sheet->index_in_wb);
		}
		n++;
	}

	if (changes > 0) {
		cmd_reorganize_sheets (wbc, old_state, NULL);
		update_undo (state, wbc);
	} else
		workbook_sheet_state_free (old_state);

	workbook_signals_unblock (state);
}
Ejemplo n.º 13
0
static gboolean
fcombo_activate (SheetObject *so, GtkTreeView *list, WBCGtk *wbcg,
		 G_GNUC_UNUSED gboolean button)
{
	GnmFilterCombo *fcombo = GNM_FILTER_COMBO (so);
	GtkTreeIter     iter;

	if (gtk_tree_selection_get_selected (gtk_tree_view_get_selection (list), NULL, &iter)) {
		GnmFilterCondition *cond = NULL;
		gboolean  set_condition = TRUE;
		GnmValue *v;
		int	  field_num, type;

		gtk_tree_model_get (gtk_tree_view_get_model (list), &iter,
				    2, &type, 3, &v,
				    -1);

		field_num = gnm_filter_combo_index (fcombo);
		switch (type) {
		case  0:
			cond = gnm_filter_condition_new_single (
				GNM_FILTER_OP_EQUAL, v);
			break;
		case  1: /* unfilter */
			cond = NULL;
			break;
		case  2: /* Custom */
			set_condition = FALSE;
			dialog_auto_filter (wbcg, fcombo->filter, field_num,
					    TRUE, fcombo->cond);
			break;
		case  3:
			cond = gnm_filter_condition_new_single (
				GNM_FILTER_OP_BLANKS, NULL);
			break;
		case  4:
			cond = gnm_filter_condition_new_single (
				GNM_FILTER_OP_NON_BLANKS, NULL);
			break;
		case 10: /* Top 10 */
			set_condition = FALSE;
			dialog_auto_filter (wbcg, fcombo->filter, field_num,
					    FALSE, fcombo->cond);
			break;
		default:
			set_condition = FALSE;
			g_warning ("Unknown type %d", type);
		}

		if (set_condition)
			cmd_autofilter_set_condition
				(GNM_WBC (wbcg),
				 fcombo->filter, field_num, cond);
	}
	return TRUE;
}
Ejemplo n.º 14
0
void
gnm_dao_load_range (GnmDao *gdao, GnmRange const *range)
{
	g_return_if_fail (gdao != NULL);

	gnm_expr_entry_load_from_range
		(gdao->output_entry,
		 wb_control_cur_sheet (GNM_WBC (gdao->wbcg)),
		 range);
}
Ejemplo n.º 15
0
static void
cb_undo_clicked (G_GNUC_UNUSED GtkWidget *ignore, SheetManager *state)
{
	WorkbookControl *wbc = GNM_WBC (state->wbcg);
	Workbook *wb = wb_control_get_workbook (wbc);

	command_undo (wbc);
	gtk_widget_set_sensitive (state->undo_btn, wb->undo_commands != NULL);

	populate_sheet_list (state);
}
Ejemplo n.º 16
0
static void
cb_data_table_response (GtkWidget *dialog, gint response_id, GnmDialogDataTable *state)
{
	if (response_id == GTK_RESPONSE_HELP)
		return;
	if (response_id == GTK_RESPONSE_OK)
		cmd_create_data_table (GNM_WBC (state->wbcg),
			state->sheet, &state->input_range,
			gnm_expr_entry_get_text	(state->col_entry),
			gnm_expr_entry_get_text (state->row_entry));
	gtk_widget_destroy (dialog);
}
Ejemplo n.º 17
0
static void
workbook_signals_unblock (SheetManager *state)
{
	WorkbookControl *wbc = GNM_WBC (state->wbcg);
	Workbook *wb = wb_control_get_workbook (wbc);

	g_signal_handler_unblock (G_OBJECT (wb),
				state->sheet_order_changed_listener);
	g_signal_handler_unblock (G_OBJECT (wb),
				state->sheet_added_listener);
	g_signal_handler_unblock (G_OBJECT (wb),
				state->sheet_deleted_listener);
}
Ejemplo n.º 18
0
static void
cb_color_changed_back (G_GNUC_UNUSED GOComboColor *go_combo_color,
		       GOColor color, G_GNUC_UNUSED gboolean custom,
		       G_GNUC_UNUSED gboolean by_user,
		       G_GNUC_UNUSED gboolean is_default,
		       SheetManager *state)
{
	GList *selected_rows, *l;
	GtkTreeSelection  *selection = gtk_tree_view_get_selection (state->sheet_list);
	WorkbookSheetState *old_state;
	WorkbookControl *wbc = GNM_WBC (state->wbcg);
	Workbook *wb = wb_control_get_workbook (wbc);
	GdkRGBA gdk_color;
	GdkRGBA *p_gdk_color;
	GnmColor *gnm_color;

	g_return_if_fail (selection != NULL);

	selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);

	p_gdk_color = (color == 0) ? NULL : go_color_to_gdk_rgba (color, &gdk_color);
	gnm_color = (color == 0) ? NULL : gnm_color_new_gdk (&gdk_color);

	old_state = workbook_sheet_state_new (wb);

	for (l = selected_rows; l != NULL; l = l->next) {
		Sheet *this_sheet;
		GtkTreeIter sel_iter;
		GtkTreePath *path = l->data;

		gtk_tree_model_get_iter (GTK_TREE_MODEL (state->model), &sel_iter, path);
		gtk_tree_model_get (GTK_TREE_MODEL (state->model), &sel_iter,
				    SHEET_POINTER, &this_sheet,
				    -1);
		if (color_equal (p_gdk_color, this_sheet->tab_color))
			continue;

		gtk_list_store_set (state->model, &sel_iter,
				    BACKGROUND_COLOUR, p_gdk_color,
				    -1);
		g_object_set (this_sheet,
			      "tab-background", gnm_color,
			      NULL);
	}

	style_color_unref (gnm_color);
	cmd_reorganize_sheets (wbc, old_state, NULL);
	update_undo (state, wbc);

	g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);
}
Ejemplo n.º 19
0
static void
cb_dialog_row_height_apply_clicked (G_GNUC_UNUSED GtkWidget *button,
				    RowHeightState *state)
{
	gint value = gtk_spin_button_get_value_as_int (state->spin);
	int size_pixels = (int)(value * state->sheet->last_zoom_factor_used + 0.5);
	gboolean use_default = gtk_toggle_button_get_active
		(GTK_TOGGLE_BUTTON (state->default_check));

	if (state->set_default_value) {
		double points = value * 72./gnm_app_display_dpi_get (TRUE);
		cmd_colrow_std_size (GNM_WBC (state->wbcg),
				     state->sheet, FALSE, points);
		dialog_row_height_load_value (state);
	} else {
		if (use_default)
			size_pixels = 0;

		workbook_cmd_resize_selected_colrow (GNM_WBC (state->wbcg),
			state->sheet, FALSE, size_pixels);
		dialog_row_height_load_value (state);
	}
}
Ejemplo n.º 20
0
static void
cb_dialog_goto_go_clicked (G_GNUC_UNUSED GtkWidget *button,
			   GotoState *state)
{
	GnmEvalPos ep;
	GnmRangeRef range;
	gint cols = gtk_spin_button_get_value_as_int (state->spin_cols);
	gint rows = gtk_spin_button_get_value_as_int (state->spin_rows);
	GnmValue *val = dialog_goto_get_val (state);
	Sheet *sheet = wb_control_cur_sheet (GNM_WBC (state->wbcg));

	if (val == NULL)
		return;

	val->v_range.cell.b.row = val->v_range.cell.a.row + (rows - 1);
	val->v_range.cell.b.col = val->v_range.cell.a.col + (cols - 1);
	eval_pos_init_sheet (&ep, sheet);
	gnm_cellref_make_abs (&range.a, &val->v_range.cell.a, &ep);
	gnm_cellref_make_abs (&range.b, &val->v_range.cell.b, &ep);
	value_release (val);

	wb_control_jump (GNM_WBC (state->wbcg), sheet, &range);
	return;
}
Ejemplo n.º 21
0
static void
cb_entry_cursor_pos (WBCGtk *wbcg)
{
	gint start, end, target_pos_in_chars, target_pos_in_bytes;
	GtkEditable *entry = GTK_EDITABLE (wbcg_get_entry (wbcg));
	char const *str = gtk_entry_get_text (GTK_ENTRY (entry));
	int edit_pos = gtk_editable_get_position (entry);

	if (str[0] == 0)
		return;

	if (edit_pos != gtk_entry_get_text_length (GTK_ENTRY (entry))) {
		/* The cursor is no longer at the end.  */
		wbcg->auto_completing = FALSE;
	}

	if (!wbcg->edit_line.full_content)
		return;

	/* 1) Use first selected character if there is a selection
	 * 2) Use the character just before the edit pos if it exists
	 * 3) Use the first character */
	if (gtk_editable_get_selection_bounds (entry, &start, &end))
		target_pos_in_chars = start;
	else {
		target_pos_in_chars = edit_pos;
		if (target_pos_in_chars > 0)
			target_pos_in_chars--;
	}

	target_pos_in_bytes = g_utf8_offset_to_pointer (str, target_pos_in_chars) - str;

	/* Make bold/italic/etc buttons show the right thing.  */
	{
		GnmStyle *style = gnm_style_new ();
		GSList *ptr, *attrs = attrs_at_byte (wbcg->edit_line.full_content, target_pos_in_bytes);
		for (ptr = attrs; ptr != NULL ; ptr = ptr->next) {
			PangoAttribute *attr = ptr->data;
			gnm_style_set_from_pango_attribute (style, attr);
			pango_attribute_destroy (attr);
		}
		wb_control_style_feedback (GNM_WBC (wbcg), style);
		gnm_style_unref (style);
		g_slist_free (attrs);
	}

	set_cur_fmt (wbcg, target_pos_in_bytes);
}
Ejemplo n.º 22
0
static void
cb_entry_changed (G_GNUC_UNUSED GtkEntry *entry, WBCGtk *wbcg)
{
	char const *text;
	int text_len;
	WorkbookView *wbv = wb_control_view (GNM_WBC (wbcg));

	text = gtk_entry_get_text (wbcg_get_entry (wbcg));
	text_len = strlen (text);

	if (text_len > wbcg->auto_max_size)
		wbcg->auto_max_size = text_len;

	if (wbv->do_auto_completion && wbcg->auto_completing)
		gnm_complete_start (GNM_COMPLETE (wbcg->auto_complete), text);
}
Ejemplo n.º 23
0
static void
cb_duplicate_clicked (G_GNUC_UNUSED GtkWidget *ignore,
		      SheetManager *state)
{
	GtkTreeIter sel_iter, iter;
	GtkTreeSelection  *selection = gtk_tree_view_get_selection (state->sheet_list);
	GList *selected_rows;
	WorkbookSheetState *old_state;
	int index;
	WorkbookControl *wbc = GNM_WBC (state->wbcg);
	Workbook *wb = wb_control_get_workbook (wbc);
	Sheet *new_sheet, *this_sheet;

	g_return_if_fail (selection != NULL);
	g_return_if_fail (gtk_tree_selection_count_selected_rows (selection) == 1);

	selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);
	gtk_tree_model_get_iter (GTK_TREE_MODEL (state->model),
				 &sel_iter, (GtkTreePath *) selected_rows->data);
	g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);

	gtk_tree_model_get (GTK_TREE_MODEL (state->model), &sel_iter,
			    SHEET_POINTER, &this_sheet,
			    -1);

	workbook_signals_block (state);

	old_state = workbook_sheet_state_new (wb);
	index = this_sheet->index_in_wb;
	new_sheet = sheet_dup (this_sheet);
	workbook_sheet_attach_at_pos (wb, new_sheet, index + 1);
	g_signal_emit_by_name (G_OBJECT (wb), "sheet_added", 0);
	cmd_reorganize_sheets (wbc, old_state, NULL);
	update_undo (state, wbc);

	workbook_signals_unblock (state);

	g_signal_handler_block (state->model, state->model_row_insertion_listener);
	gtk_list_store_insert_after (state->model, &iter, &sel_iter);
	g_signal_handler_unblock (state->model, state->model_row_insertion_listener);

	set_sheet_info_at_iter (state, &iter, new_sheet);
	g_object_unref (new_sheet);

	cb_selection_changed (NULL, state);
}
Ejemplo n.º 24
0
static void
cb_toggled_lock (G_GNUC_UNUSED GtkCellRendererToggle *cell,
		 gchar                 *path_string,
		 gpointer               data)
{
	SheetManager *state = data;
	GtkTreeModel *model = GTK_TREE_MODEL (state->model);
	GtkTreeIter iter;
	GtkTreePath *path = gtk_tree_path_new_from_string (path_string);
	gboolean is_locked = TRUE;
	Sheet *this_sheet = NULL;
	WorkbookSheetState *old_state = NULL;
	WorkbookControl *wbc = GNM_WBC (state->wbcg);
	Workbook *wb = wb_control_get_workbook (wbc);

	if (gtk_tree_model_get_iter (model, &iter, path)) {
		gtk_tree_model_get (model, &iter,
				    SHEET_LOCKED, &is_locked,
				    SHEET_POINTER, &this_sheet,
				    -1);

		if (is_locked) {
			gtk_list_store_set
				(GTK_LIST_STORE (model), &iter, SHEET_LOCKED,
				 FALSE, SHEET_LOCK_IMAGE,
				 state->image_padlock_no, -1);
		} else {
			gtk_list_store_set
				(GTK_LIST_STORE (model), &iter, SHEET_LOCKED,
				 TRUE, SHEET_LOCK_IMAGE,
				 state->image_padlock, -1);
		}
	} else {
		g_warning ("Did not get a valid iterator");
		gtk_tree_path_free (path);
		return;
	}
	gtk_tree_path_free (path);

	old_state = workbook_sheet_state_new (wb);
	g_object_set (this_sheet,
		      "protected", !is_locked,
		      NULL);
	cmd_reorganize_sheets (wbc, old_state, this_sheet);
	update_undo (state, wbc);
}
Ejemplo n.º 25
0
gboolean
dialog_autosave_prompt (WBCGtk *wbcg)
{
	char const *uri   = go_doc_get_uri (
		wb_control_get_doc (GNM_WBC (wbcg)));
	GtkWidget *dialog = gtk_message_dialog_new (wbcg_toplevel (wbcg),
					 GTK_DIALOG_DESTROY_WITH_PARENT,
					 GTK_MESSAGE_QUESTION,
					 GTK_BUTTONS_YES_NO,
					 _("Do you want to save the workbook %s?"),
					 uri);
	gint result = gtk_dialog_run (GTK_DIALOG (dialog));

	gtk_widget_destroy (dialog);

	return result == GTK_RESPONSE_YES;
}
Ejemplo n.º 26
0
static void
cb_delete_clicked (G_GNUC_UNUSED GtkWidget *ignore,
		   SheetManager *state)
{
	GtkTreeSelection  *selection = gtk_tree_view_get_selection (state->sheet_list);
	GList *selected_rows, *l;
	WorkbookSheetState *old_state;
	WorkbookControl *wbc = GNM_WBC (state->wbcg);
	Workbook *wb = wb_control_get_workbook (wbc);

	g_return_if_fail (selection != NULL);

	selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);

	for (l = selected_rows; l != NULL; l = l->next)
		l->data = gtk_tree_row_reference_new (GTK_TREE_MODEL (state->model),
						      (GtkTreePath *) l->data);
	workbook_signals_block (state);
	old_state = workbook_sheet_state_new (wb);

	for (l = selected_rows; l != NULL; l = l->next) {
		GtkTreeRowReference *ref = l->data;
		if (gtk_tree_row_reference_valid (ref)) {
			GtkTreePath *path = gtk_tree_row_reference_get_path (ref);
			GtkTreeIter sel_iter;
			Sheet *sheet;

			gtk_tree_model_get_iter (GTK_TREE_MODEL (state->model), &sel_iter, path);
			gtk_tree_path_free (path);
			gtk_tree_model_get (GTK_TREE_MODEL (state->model), &sel_iter,
					    SHEET_POINTER, &sheet,
					    -1);
			gtk_list_store_remove (state->model, &sel_iter);
			workbook_sheet_delete (sheet);
		}
	}

	cmd_reorganize_sheets (wbc, old_state, NULL);
	update_undo (state, wbc);
	workbook_signals_unblock (state);

	populate_sheet_list (state);
	cb_name_edited (NULL, NULL, NULL, state);

	g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_row_reference_free);
}
Ejemplo n.º 27
0
static GnmValue *
dialog_goto_get_val (GotoState *state)
{
	char const *text = gtk_entry_get_text (state->goto_text);
	Sheet *sheet = wb_control_cur_sheet (GNM_WBC (state->wbcg));
	GnmValue *val = value_new_cellrange_str (sheet, text);

	if (val == NULL) {
		GnmParsePos pp;
		GnmNamedExpr *nexpr = expr_name_lookup
			(parse_pos_init_sheet (&pp, sheet), text);
		if (nexpr != NULL && !expr_name_is_placeholder (nexpr)) {
			val = gnm_expr_top_get_range (nexpr->texpr);
		}
	}
	return val;
}
Ejemplo n.º 28
0
static void
cb_dialog_so_styled_response (GtkWidget *dialog,
			      gint response_id, DialogSOStyled *state)
{
	if (response_id == GTK_RESPONSE_HELP)
		return;
	if (response_id == GTK_RESPONSE_OK) {
		GSList *new_props = go_object_properties_collect (state->so);
		force_new_style (state->so);
		cmd_generic (GNM_WBC (state->wbcg),
			     _("Format Object"),
			     make_undo (state->so, state->orig_props),
			     make_undo (state->so, new_props));
		state->orig_props = NULL;
	}
	gtk_widget_destroy (dialog);
}
Ejemplo n.º 29
0
static void
sort_asc_desc (SheetManager *state, gboolean asc)
{
	WorkbookSheetState *old_state;
	WorkbookControl *wbc = GNM_WBC (state->wbcg);
	Workbook *wb = wb_control_get_workbook (wbc);
	GSList *l = NULL, *l_tmp;
	gint n = 0;

	gtk_tree_model_foreach (GTK_TREE_MODEL (state->model), gtmff_asc, &l);

	if (!asc)
		l = g_slist_reverse (l);

	workbook_signals_block (state);

	old_state = workbook_sheet_state_new (wb);

	for (l_tmp = l; l_tmp != NULL; l_tmp = l_tmp->next) {
		gtmff_sort_t *ptr = l_tmp->data;
		GtkTreeIter iter;
		Sheet *sheet;

		gtk_tree_model_iter_nth_child  (GTK_TREE_MODEL (state->model),
						&iter, NULL, ptr->i);
		g_free (ptr->key);
		g_free (ptr);
		l_tmp->data = NULL;

		gtk_tree_model_get (GTK_TREE_MODEL (state->model), &iter,
				    SHEET_POINTER, &sheet,
				    -1);
		workbook_sheet_move (sheet, n - sheet->index_in_wb);
		n++;
	}
	g_slist_free (l);

	/* Now we change the list store  */
	dialog_sheet_order_update_sheet_order (state);

	cmd_reorganize_sheets (wbc, old_state, NULL);
	update_undo (state, wbc);

	workbook_signals_unblock (state);
}
Ejemplo n.º 30
0
static void
cb_add_clicked (G_GNUC_UNUSED GtkWidget *ignore, SheetManager *state)
{
	GtkTreeIter sel_iter, iter;
	GtkTreeSelection  *selection = gtk_tree_view_get_selection (state->sheet_list);
	GList *selected_rows;
	int index = -1;
	WorkbookSheetState *old_state;
	WorkbookControl *wbc = GNM_WBC (state->wbcg);
	Workbook *wb = wb_control_get_workbook (wbc);
	Sheet *sheet, *old_sheet = NULL;

	g_return_if_fail (selection != NULL);
	g_return_if_fail (gtk_tree_selection_count_selected_rows (selection) == 1);

	selected_rows = gtk_tree_selection_get_selected_rows (selection, NULL);
	gtk_tree_model_get_iter (GTK_TREE_MODEL (state->model),
				 &sel_iter, (GtkTreePath *) selected_rows->data);
	g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);

	gtk_tree_model_get (GTK_TREE_MODEL (state->model), &sel_iter,
			    SHEET_POINTER, &old_sheet,
			    -1);
	index = old_sheet->index_in_wb;

	workbook_signals_block (state);

	old_state = workbook_sheet_state_new (wb);
	workbook_sheet_add (wb, index,
			    gnm_sheet_get_max_cols (old_sheet),
			    gnm_sheet_get_max_rows (old_sheet));
	cmd_reorganize_sheets (wbc, old_state, NULL);
	update_undo (state, wbc);

	workbook_signals_unblock (state);

	g_signal_handler_block (state->model, state->model_row_insertion_listener);
	sheet = workbook_sheet_by_index (wb, index);
	gtk_list_store_insert_before (state->model, &iter, &sel_iter);
	g_signal_handler_unblock (state->model, state->model_row_insertion_listener);

	set_sheet_info_at_iter (state, &iter, sheet);

	cb_selection_changed (NULL, state);
}