[gnumeric] Add initial dialog for changing sheet sizes.
- From: Morten Welinder <mortenw src gnome org>
- To: svn-commits-list gnome org
- Subject: [gnumeric] Add initial dialog for changing sheet sizes.
- Date: Mon, 20 Apr 2009 14:02:19 -0400 (EDT)
commit 302cd1036228b763045c31d8c267a7e374d5155e
Author: Morten Welinder <terra gnome org>
Date: Mon Apr 20 13:48:59 2009 -0400
Add initial dialog for changing sheet sizes.
---
src/dialogs/Makefile.am | 2 +
src/dialogs/dialog-sheet-resize.c | 199 +++++++++++++++++++++++++++
src/dialogs/dialogs.h | 1 +
src/dialogs/sheet-resize.glade | 269 +++++++++++++++++++++++++++++++++++++
src/wbc-gtk.c | 3 +
5 files changed, 474 insertions(+), 0 deletions(-)
diff --git a/src/dialogs/Makefile.am b/src/dialogs/Makefile.am
index 304c050..c1303de 100644
--- a/src/dialogs/Makefile.am
+++ b/src/dialogs/Makefile.am
@@ -62,6 +62,7 @@ base_files = \
dialog-search.c \
dialog-search-replace.c \
dialog-sheet-order.c \
+ dialog-sheet-resize.c \
dialog-shuffle.c \
dialog-simulation.c \
dialog-so-list.c \
@@ -143,6 +144,7 @@ glade_DATA = \
search.glade \
search-replace.glade \
sheet-order.glade \
+ sheet-resize.glade \
shuffle.glade \
so-checkbox.glade \
so-frame.glade \
diff --git a/src/dialogs/dialog-sheet-resize.c b/src/dialogs/dialog-sheet-resize.c
new file mode 100644
index 0000000..df5986a
--- /dev/null
+++ b/src/dialogs/dialog-sheet-resize.c
@@ -0,0 +1,199 @@
+/*
+ * dialog-sheet-resize.c: Dialog to resize current or all sheets.
+ *
+ * Author:
+ * Morten Welinder <terra gnome org>
+ *
+ * (C) Copyright 2009 Morten Welinder <terra gnome org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <gnumeric-config.h>
+#include <glib/gi18n-lib.h>
+#include <gnumeric.h>
+#include "dialogs.h"
+#include "help.h"
+
+#include <gui-util.h>
+#include <wbc-gtk.h>
+#include <workbook-view.h>
+#include <workbook.h>
+#include <sheet.h>
+
+#define RESIZE_DIALOG_KEY "sheet-resize-dialog"
+
+typedef struct {
+ WBCGtk *wbcg;
+ Sheet *sheet;
+ GtkWidget *dialog;
+ GladeXML *gui;
+ GtkWidget *columns_scale, *rows_scale;
+ GtkWidget *columns_label, *rows_label;
+ GtkWidget *ok_button, *cancel_button;
+ GtkWidget *all_sheets_button;
+} ResizeState;
+
+static void
+get_sizes (ResizeState *state, int *cols, int *rows)
+{
+ GtkAdjustment *adj;
+
+ adj = gtk_range_get_adjustment (GTK_RANGE (state->columns_scale));
+ *cols = 1 << (int)adj->value;
+
+ adj = gtk_range_get_adjustment (GTK_RANGE (state->rows_scale));
+ *rows = 1 << (int)adj->value;
+}
+
+static void
+set_count (GtkWidget *l, int count)
+{
+ char *text;
+
+ if (count >= (1 << 20))
+ text = g_strdup_printf ("%dM", count >> 20);
+ else
+ text = g_strdup_printf ("%d", count);
+ gtk_label_set_text (GTK_LABEL (l), text);
+ g_free (text);
+}
+
+static void
+cb_scale_changed (ResizeState *state)
+{
+ int cols, rows;
+ get_sizes (state, &cols, &rows);
+ set_count (state->columns_label, cols);
+ set_count (state->rows_label, rows);
+ gtk_widget_set_sensitive (state->ok_button,
+ gnm_sheet_valid_size (cols, rows));
+}
+
+static void
+init_scale (GtkWidget *scale, int N)
+{
+ GtkAdjustment *adj = gtk_range_get_adjustment (GTK_RANGE (scale));
+ int l2 = 0;
+
+ while (N > 1)
+ N >>= 1, l2++;
+
+ g_object_set (G_OBJECT (adj), "value", (double)l2, NULL);
+}
+
+static void
+cb_destroy (ResizeState *state)
+{
+ if (state->gui != NULL)
+ g_object_unref (G_OBJECT (state->gui));
+
+ g_free (state);
+}
+
+static void
+cb_ok_clicked (ResizeState *state)
+{
+ GList *sheets, *l;
+ GSList *changed_sheets = NULL;
+ Workbook *wb;
+ gboolean all_sheets;
+ int cols, rows;
+
+ get_sizes (state, &cols, &rows);
+ all_sheets = gtk_toggle_button_get_active
+ (GTK_TOGGLE_BUTTON (state->all_sheets_button));
+
+ wb = wb_control_get_workbook (WORKBOOK_CONTROL (state->wbcg));
+ sheets = workbook_sheets (wb);
+ for (l = sheets; l; l = l->next) {
+ Sheet *this_sheet = l->data;
+
+ if (!all_sheets && this_sheet != state->sheet)
+ continue;
+
+ if (cols == gnm_sheet_get_max_cols (this_sheet) &&
+ rows == gnm_sheet_get_max_rows (this_sheet))
+ continue;
+
+ changed_sheets = g_slist_prepend (changed_sheets, this_sheet);
+ }
+ g_list_free (sheets);
+
+ if (changed_sheets) {
+ g_warning ("Changing sheet size is not implemented yet.");
+ }
+
+ gtk_widget_destroy (state->dialog);
+}
+
+void
+dialog_sheet_resize (WBCGtk *wbcg)
+{
+ GladeXML *gui;
+ ResizeState *state;
+
+ if (gnumeric_dialog_raise_if_exists (wbcg, RESIZE_DIALOG_KEY))
+ return;
+ gui = gnm_glade_xml_new (GO_CMD_CONTEXT (wbcg),
+ "sheet-resize.glade", NULL, NULL);
+ if (gui == NULL)
+ return;
+
+ state = g_new (ResizeState, 1);
+ state->wbcg = wbcg;
+ state->gui = gui;
+ state->dialog = glade_xml_get_widget (state->gui, "Resize");
+ state->sheet = wbcg_cur_sheet (wbcg);
+ g_return_if_fail (state->dialog != NULL);
+
+ state->columns_scale = glade_xml_get_widget (state->gui, "columns_scale");
+ state->columns_label = glade_xml_get_widget (state->gui, "columns_label");
+ state->rows_scale = glade_xml_get_widget (state->gui, "rows_scale");
+ state->rows_label = glade_xml_get_widget (state->gui, "rows_label");
+ state->all_sheets_button = glade_xml_get_widget (state->gui, "all_sheets_button");
+ state->ok_button = glade_xml_get_widget (state->gui, "ok_button");
+ state->cancel_button = glade_xml_get_widget (state->gui, "cancel_button");
+
+ g_signal_connect_swapped (G_OBJECT (state->columns_scale),
+ "value-changed", G_CALLBACK (cb_scale_changed),
+ state);
+ init_scale (state->columns_scale, gnm_sheet_get_max_cols (state->sheet));
+
+ g_signal_connect_swapped (G_OBJECT (state->rows_scale),
+ "value-changed", G_CALLBACK (cb_scale_changed),
+ state);
+ init_scale (state->rows_scale, gnm_sheet_get_max_rows (state->sheet));
+
+ g_signal_connect_swapped (G_OBJECT (state->cancel_button),
+ "clicked", G_CALLBACK (gtk_widget_destroy),
+ state->dialog);
+
+ g_signal_connect_swapped (G_OBJECT (state->ok_button),
+ "clicked", G_CALLBACK (cb_ok_clicked),
+ state);
+
+ gnm_dialog_setup_destroy_handlers (GTK_DIALOG (state->dialog), wbcg,
+ GNM_DIALOG_DESTROY_SHEET_REMOVED);
+
+ gnumeric_keyed_dialog (wbcg, GTK_WINDOW (state->dialog),
+ RESIZE_DIALOG_KEY);
+
+ g_object_set_data_full (G_OBJECT (state->dialog),
+ "state", state,
+ (GDestroyNotify) cb_destroy);
+
+ gtk_widget_show (state->dialog);
+}
diff --git a/src/dialogs/dialogs.h b/src/dialogs/dialogs.h
index 752cb6b..63d0e4c 100644
--- a/src/dialogs/dialogs.h
+++ b/src/dialogs/dialogs.h
@@ -51,6 +51,7 @@ gboolean dialog_autosave_prompt (WBCGtk *wbcg);
void dialog_autoformat (WBCGtk *wbcg);
void dialog_consolidate (WBCGtk *wbcg);
void dialog_sheet_order (WBCGtk *wbcg);
+void dialog_sheet_resize (WBCGtk *wbcg);
void dialog_row_height (WBCGtk *wbcg, gboolean set_default);
void dialog_fill_series (WBCGtk *wbcg);
void dialog_col_width (WBCGtk *wbcg, gboolean set_default);
diff --git a/src/dialogs/sheet-resize.glade b/src/dialogs/sheet-resize.glade
new file mode 100644
index 0000000..d2a6978
--- /dev/null
+++ b/src/dialogs/sheet-resize.glade
@@ -0,0 +1,269 @@
+<?xml version="1.0" standalone="no"?> <!--*- mode: xml -*-->
+<!DOCTYPE glade-interface SYSTEM "http://glade.gnome.org/glade-2.0.dtd">
+
+<glade-interface>
+
+<widget class="GtkDialog" id="Resize">
+ <property name="border_width">5</property>
+ <property name="title" translatable="yes">Resize Sheet</property>
+ <property name="type">GTK_WINDOW_TOPLEVEL</property>
+ <property name="window_position">GTK_WIN_POS_NONE</property>
+ <property name="modal">False</property>
+ <property name="resizable">True</property>
+ <property name="destroy_with_parent">False</property>
+ <property name="decorated">True</property>
+ <property name="skip_taskbar_hint">False</property>
+ <property name="skip_pager_hint">False</property>
+ <property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
+ <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
+ <property name="focus_on_map">True</property>
+ <property name="urgency_hint">False</property>
+ <property name="has_separator">False</property>
+
+ <child internal-child="vbox">
+ <widget class="GtkVBox" id="dialog-vbox1">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">2</property>
+
+ <child internal-child="action_area">
+ <widget class="GtkHButtonBox" id="dialog-action_area1">
+ <property name="visible">True</property>
+ <property name="layout_style">GTK_BUTTONBOX_END</property>
+
+ <child>
+ <widget class="GtkButton" id="ok_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label">gtk-ok</property>
+ <property name="use_stock">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ <property name="response_id">0</property>
+ </widget>
+ </child>
+
+ <child>
+ <widget class="GtkButton" id="cancel_button">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="label">gtk-cancel</property>
+ <property name="use_stock">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ <property name="response_id">0</property>
+ </widget>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">True</property>
+ <property name="pack_type">GTK_PACK_END</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkVBox" id="vbox1">
+ <property name="visible">True</property>
+ <property name="homogeneous">False</property>
+ <property name="spacing">0</property>
+
+ <child>
+ <widget class="GtkTable" id="table1">
+ <property name="visible">True</property>
+ <property name="n_rows">2</property>
+ <property name="n_columns">3</property>
+ <property name="homogeneous">False</property>
+ <property name="row_spacing">0</property>
+ <property name="column_spacing">0</property>
+
+ <child>
+ <widget class="GtkLabel" id="columns_label">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">xxxxx</property>
+ <property name="use_underline">False</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_RIGHT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+ <property name="width_chars">8</property>
+ <property name="single_line_mode">False</property>
+ <property name="angle">0</property>
+ </widget>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="right_attach">1</property>
+ <property name="top_attach">0</property>
+ <property name="bottom_attach">1</property>
+ <property name="x_options">fill</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="rows_label">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">yyyyy</property>
+ <property name="use_underline">False</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_RIGHT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+ <property name="width_chars">8</property>
+ <property name="single_line_mode">False</property>
+ <property name="angle">0</property>
+ </widget>
+ <packing>
+ <property name="left_attach">0</property>
+ <property name="right_attach">1</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">fill</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="label4">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Columns</property>
+ <property name="use_underline">False</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+ <property name="width_chars">-1</property>
+ <property name="single_line_mode">False</property>
+ <property name="angle">0</property>
+ </widget>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">0</property>
+ <property name="bottom_attach">1</property>
+ <property name="x_options">fill</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkLabel" id="label5">
+ <property name="visible">True</property>
+ <property name="label" translatable="yes">Rows</property>
+ <property name="use_underline">False</property>
+ <property name="use_markup">False</property>
+ <property name="justify">GTK_JUSTIFY_LEFT</property>
+ <property name="wrap">False</property>
+ <property name="selectable">False</property>
+ <property name="xalign">0</property>
+ <property name="yalign">0.5</property>
+ <property name="xpad">0</property>
+ <property name="ypad">0</property>
+ <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+ <property name="width_chars">-1</property>
+ <property name="single_line_mode">False</property>
+ <property name="angle">0</property>
+ </widget>
+ <packing>
+ <property name="left_attach">1</property>
+ <property name="right_attach">2</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="x_options">fill</property>
+ <property name="y_options"></property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkHScale" id="columns_scale">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="draw_value">False</property>
+ <property name="value_pos">GTK_POS_TOP</property>
+ <property name="digits">0</property>
+ <property name="update_policy">GTK_UPDATE_CONTINUOUS</property>
+ <property name="inverted">False</property>
+ <property name="adjustment">7 7 13 1 1 1</property>
+ </widget>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="right_attach">3</property>
+ <property name="top_attach">0</property>
+ <property name="bottom_attach">1</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkHScale" id="rows_scale">
+ <property name="visible">True</property>
+ <property name="can_focus">True</property>
+ <property name="draw_value">False</property>
+ <property name="value_pos">GTK_POS_TOP</property>
+ <property name="digits">0</property>
+ <property name="update_policy">GTK_UPDATE_CONTINUOUS</property>
+ <property name="inverted">False</property>
+ <property name="adjustment">7 7 24 1 1 1</property>
+ </widget>
+ <packing>
+ <property name="left_attach">2</property>
+ <property name="right_attach">3</property>
+ <property name="top_attach">1</property>
+ <property name="bottom_attach">2</property>
+ <property name="y_options">fill</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+
+ <child>
+ <widget class="GtkCheckButton" id="all_sheets_button">
+ <property name="visible">True</property>
+ <property name="tooltip" translatable="yes">Check this to apply the new size to all sheets in the workbook</property>
+ <property name="can_focus">True</property>
+ <property name="label" translatable="yes">Apply change to all sheets</property>
+ <property name="use_underline">True</property>
+ <property name="relief">GTK_RELIEF_NORMAL</property>
+ <property name="focus_on_click">True</property>
+ <property name="active">True</property>
+ <property name="inconsistent">False</property>
+ <property name="draw_indicator">True</property>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">False</property>
+ <property name="fill">False</property>
+ </packing>
+ </child>
+ </widget>
+ <packing>
+ <property name="padding">0</property>
+ <property name="expand">True</property>
+ <property name="fill">True</property>
+ </packing>
+ </child>
+ </widget>
+ </child>
+</widget>
+
+</glade-interface>
diff --git a/src/wbc-gtk.c b/src/wbc-gtk.c
index d1f7c16..719688b 100644
--- a/src/wbc-gtk.c
+++ b/src/wbc-gtk.c
@@ -452,6 +452,8 @@ static void cb_sheets_insert (SheetControlGUI *scg) { wbcg_insert_sheet (NULL, s
static void cb_sheets_add (SheetControlGUI *scg) { wbcg_append_sheet (NULL, scg->wbcg); }
static void cb_sheets_clone (SheetControlGUI *scg) { wbcg_clone_sheet (NULL, scg->wbcg); }
static void cb_sheets_rename (SheetControlGUI *scg) { editable_label_start_editing (EDITABLE_LABEL(scg->label)); }
+static void cb_sheets_resize (SheetControlGUI *scg) { dialog_sheet_resize (scg->wbcg); }
+
static gint
cb_by_scg_sheet_name (gconstpointer a_, gconstpointer b_)
@@ -481,6 +483,7 @@ sheet_menu_label_run (SheetControlGUI *scg, GdkEventButton *event)
{ N_("Duplicate"), &cb_sheets_clone, FALSE, 0 },
{ N_("Remove"), &scg_delete_sheet_if_possible, TRUE, 0 },
{ N_("Rename"), &cb_sheets_rename, FALSE, 0 },
+ { N_("Resize..."), &cb_sheets_resize, FALSE, 0 },
{ N_("Select"), NULL, FALSE, 1 },
{ N_("Select (sorted)"), NULL, FALSE, 2 }
};
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]