Ejemplo n.º 1
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.º 2
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.º 3
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);
}
Ejemplo n.º 4
0
/* Add all of the sheets to the sheet_list */
static void
populate_sheet_list (SheetManager *state)
{
	GtkTreeSelection  *selection;
	GtkTreeIter iter;
	WorkbookControl *wbc = GNM_WBC (state->wbcg);
	Workbook *wb = wb_control_get_workbook (wbc);
	Sheet *cur_sheet = wb_control_cur_sheet (wbc);
	int i, n = workbook_sheet_count (wb);
	GtkTreePath *sel_path = NULL;

	selection = gtk_tree_view_get_selection (state->sheet_list);

	g_signal_handler_block (selection, state->model_selection_changed_listener);
	if (state->model_row_insertion_listener)
		g_signal_handler_block (state->model, state->model_row_insertion_listener);

	gtk_list_store_clear (state->model);
	gtk_label_set_text (GTK_LABEL (state->warning), "");

	for (i = 0 ; i < n ; i++) {
		Sheet *sheet = workbook_sheet_by_index (wb, i);

		gtk_list_store_append (state->model, &iter);
		set_sheet_info_at_iter (state, &iter, sheet);

		if (sheet == cur_sheet)
			sel_path = gtk_tree_model_get_path (GTK_TREE_MODEL (state->model),
							    &iter);
	}

	if (sel_path) {
		gtk_tree_selection_select_path (selection, sel_path);
		gtk_tree_path_free (sel_path);
	}

	if (state->model_row_insertion_listener)
		g_signal_handler_unblock (state->model, state->model_row_insertion_listener);
	g_signal_handler_unblock (selection, state->model_selection_changed_listener);

	/* Init the buttons & selection */
	cb_selection_changed (NULL, state);
}
static void
kaplan_meier_tool_update_groups_sensitivity_cb (G_GNUC_UNUSED GtkWidget *dummy,
				      KaplanMeierToolState *state)
{
	gboolean groups = gtk_toggle_button_get_active (
		GTK_TOGGLE_BUTTON (state->groups_check));
	GtkTreeSelection  *selection = gtk_tree_view_get_selection (state->groups_treeview);

	gtk_widget_set_sensitive (state->add_group_button, groups);
	gtk_widget_set_sensitive (GTK_WIDGET (state->groups_treeview), groups);

	if (groups) {
		cb_selection_changed (selection, state);
		gtk_widget_set_sensitive (state->logrank_button, TRUE);
	} else {
		gtk_tree_selection_unselect_all (selection);
		gtk_widget_set_sensitive (state->remove_group_button, FALSE);
		gtk_widget_set_sensitive (state->logrank_button, FALSE);
	}
}
Ejemplo n.º 6
0
static void
cb_item_move (SheetManager *state, gnm_iter_search_t iter_search)
{
	GtkTreeSelection  *selection = gtk_tree_view_get_selection (state->sheet_list);
	GtkTreeIter  a, b;
	GList *selected_rows;

	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),
				 &a, (GtkTreePath *) selected_rows->data);
	g_list_free_full (selected_rows, (GDestroyNotify) gtk_tree_path_free);

	b = a;
	if (!iter_search (GTK_TREE_MODEL (state->model), &b))
		return;

	gtk_list_store_swap (state->model, &a, &b);
	cb_selection_changed (NULL, state);
}
static void
dialog_kaplan_meier_tool_setup_treeview (KaplanMeierToolState *state)
{
	guint i;
	GtkCellRenderer *renderer;
	GtkWidget *scrolled = glade_xml_get_widget (state->base.gui, "groups-scrolled");
	GtkTreeSelection  *selection;

	state->groups_treeview = GTK_TREE_VIEW (glade_xml_get_widget
						(state->base.gui,
						 "groups-tree"));
	state->groups_list = gtk_list_store_new (GROUP_COLUMNS,
						 G_TYPE_STRING, G_TYPE_UINT, G_TYPE_UINT, G_TYPE_OBJECT, G_TYPE_OBJECT);
	state->groups_treeview = GTK_TREE_VIEW (gtk_tree_view_new_with_model
						(GTK_TREE_MODEL (state->groups_list)));
	selection = gtk_tree_view_get_selection (state->groups_treeview);
	gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);

	for (i = 0; i<2; i++)
		dialog_kaplan_meier_tool_treeview_add_item (state, i);

	g_signal_connect (selection,
			  "changed",
			  G_CALLBACK (cb_selection_changed), state);

	renderer = gtk_cell_renderer_text_new ();
	g_object_set (G_OBJECT (renderer),
		      "editable", TRUE,
		      NULL);
	gtk_tree_view_insert_column_with_attributes (state->groups_treeview,
						     -1, _("Group"),
						     renderer,
						     "text", GROUP_NAME,
						     NULL);
	g_signal_connect (G_OBJECT (renderer), "edited",
			  G_CALLBACK (cb_group_name_edited), state);

	renderer = gtk_cell_renderer_spin_new ();

	g_object_set (G_OBJECT (renderer), "editable", TRUE, "xalign", 1.0,
		      "digits", 0, NULL);
	g_signal_connect (G_OBJECT (renderer), "edited",
			  G_CALLBACK (cb_change_from), state);
	gtk_tree_view_insert_column_with_attributes (state->groups_treeview,
						     -1, _("From"),
						     renderer,
						     "text", GROUP_FROM,
						     "adjustment", GROUP_ADJUSTMENT_FROM,
						     NULL);

	renderer = gtk_cell_renderer_spin_new ();
	g_object_set (G_OBJECT (renderer), "editable", TRUE, "xalign", 1.0,
		      "digits", 0, NULL);
	g_signal_connect (G_OBJECT (renderer), "edited",
			  G_CALLBACK (cb_change_to), state);
	gtk_tree_view_insert_column_with_attributes (state->groups_treeview,
						     -1, _("To"),
						     renderer,
						     "text", GROUP_TO,
						     "adjustment", GROUP_ADJUSTMENT_TO,
						     NULL);

	gtk_container_add (GTK_CONTAINER (scrolled), GTK_WIDGET (state->groups_treeview));

	cb_selection_changed (selection, state);
}
Ejemplo n.º 8
0
static void
dialog_sheet_order_update_sheet_order (SheetManager *state)
{
	GtkTreeIter iter;
	Workbook *wb = wb_control_get_workbook (GNM_WBC (state->wbcg));
	int i, n_sheets, n_children;
	GtkTreeModel *model = GTK_TREE_MODEL (state->model);
	GtkTreeSelection *sel = gtk_tree_view_get_selection (state->sheet_list);

	n_sheets = workbook_sheet_count (wb);
	n_children = gtk_tree_model_iter_n_children (model, NULL);

	if (n_sheets != n_children) {
	  /* This signal also occurs when sheets are added or deleted. We handle this */
	  /* when those signals arrive.                                               */
	  return;
	}

	for (i = 0; i < n_sheets; i++) {
		gchar *name, *new_name;
		gboolean is_locked;
		gboolean is_visible;
		gboolean is_rtl;
		GdkRGBA *back, *fore;
		Sheet *sheet_wb = workbook_sheet_by_index (wb, i);
		Sheet *sheet_model;
		gboolean selected;
		int j, row_max, col_max;

		for (j = i; j < n_children; j++) {
			if (!gtk_tree_model_iter_nth_child (model, &iter,
							    NULL, j))
				break;
			gtk_tree_model_get (model, &iter, SHEET_POINTER,
					    &sheet_model, -1);
			if (sheet_model == sheet_wb)
				break;
		}
		if (j == i)
			continue;

		if (!gtk_tree_model_iter_nth_child (model, &iter, NULL, j))
			break;
		selected = gtk_tree_selection_iter_is_selected (sel, &iter);
		gtk_tree_model_get (model, &iter,
				    SHEET_LOCKED, &is_locked,
				    SHEET_VISIBLE, &is_visible,
				    SHEET_ROW_MAX, &row_max,
				    SHEET_COL_MAX, &col_max,
				    SHEET_NAME, &name,
				    SHEET_NEW_NAME, &new_name,
				    SHEET_POINTER, &sheet_model,
				    BACKGROUND_COLOUR, &back,
				    FOREGROUND_COLOUR, &fore,
				    SHEET_DIRECTION, &is_rtl,
				    -1);
		gtk_list_store_remove (state->model, &iter);
		g_signal_handler_block (state->model, state->model_row_insertion_listener);
		gtk_list_store_insert (state->model, &iter, i);
		g_signal_handler_unblock (state->model, state->model_row_insertion_listener);
		gtk_list_store_set (state->model, &iter,
				    SHEET_LOCKED, is_locked,
				    SHEET_LOCK_IMAGE, is_locked ?
				    state->image_padlock : state->image_padlock_no,
				    SHEET_VISIBLE, is_visible,
				    SHEET_VISIBLE_IMAGE, is_visible ?
				    state->image_visible : NULL,
				    SHEET_ROW_MAX, row_max,
				    SHEET_COL_MAX, col_max,
				    SHEET_NAME, name,
				    SHEET_NEW_NAME, new_name,
				    SHEET_POINTER, sheet_model,
				    BACKGROUND_COLOUR, back,
				    FOREGROUND_COLOUR, fore,
				    SHEET_DIRECTION, is_rtl,
				    SHEET_DIRECTION_IMAGE,
					    is_rtl ? state->image_rtl : state->image_ltr,
				    -1);
		if (back)
			gdk_rgba_free (back);
		if (fore)
			gdk_rgba_free (fore);
		g_free (name);
		g_free (new_name);
		if (selected)
			gtk_tree_selection_select_iter (sel, &iter);
	}

	cb_selection_changed (NULL, state);
}