2 * dialog-insert-cells.c: Insert a number of cells.
5 * Miguel de Icaza (miguel@gnu.org)
6 * Copyright (C) Andreas J. Guelzow (aguelzow@taliesin.ca)
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, see <https://www.gnu.org/licenses/>.
21 #include <gnumeric-config.h>
22 #include <glib/gi18n-lib.h>
28 #include <selection.h>
31 #include <sheet-view.h>
36 #include <command-context.h>
40 #define INSERT_CELL_DIALOG_KEY "insert-cells-dialog"
46 GtkWidget
*cancel_button
;
53 cb_insert_cell_destroy (InsertCellState
*state
)
55 if (state
->gui
!= NULL
)
56 g_object_unref (state
->gui
);
61 cb_insert_cell_ok_clicked (G_GNUC_UNUSED GtkWidget
*button
,
62 InsertCellState
*state
)
64 WorkbookControl
*wbc
= GNM_WBC (state
->wbcg
);
69 radio_0
= go_gtk_builder_get_widget (state
->gui
, "radio_0");
70 g_return_if_fail (radio_0
!= NULL
);
72 i
= gnm_gtk_radio_group_get_selected
73 (gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_0
)));
75 cols
= state
->sel
->end
.col
- state
->sel
->start
.col
+ 1;
76 rows
= state
->sel
->end
.row
- state
->sel
->start
.row
+ 1;
80 cmd_shift_rows (wbc
, state
->sheet
,
81 state
->sel
->start
.col
,
82 state
->sel
->start
.row
,
83 state
->sel
->end
.row
, cols
);
86 cmd_shift_cols (wbc
, state
->sheet
,
87 state
->sel
->start
.col
,
89 state
->sel
->start
.row
, rows
);
92 cmd_insert_rows (wbc
, state
->sheet
,
93 state
->sel
->start
.row
, rows
);
96 cmd_insert_cols (wbc
, state
->sheet
,
97 state
->sel
->start
.col
, cols
);
100 gtk_widget_destroy (state
->dialog
);
104 cb_insert_cell_cancel_clicked (G_GNUC_UNUSED GtkWidget
*button
,
105 InsertCellState
*state
)
107 gtk_widget_destroy (state
->dialog
);
112 dialog_insert_cells (WBCGtk
*wbcg
)
115 InsertCellState
*state
;
116 WorkbookControl
*wbc
= GNM_WBC (wbcg
);
117 SheetView
*sv
= wb_control_cur_sheet_view (wbc
);
118 Sheet
*sheet
= sv_sheet (sv
);
122 g_return_if_fail (wbcg
!= NULL
);
124 if (!(sel
= selection_first_range (sv
, GO_CMD_CONTEXT (wbc
), _("Insert"))))
126 cols
= sel
->end
.col
- sel
->start
.col
+ 1;
127 rows
= sel
->end
.row
- sel
->start
.row
+ 1;
129 if (range_is_full (sel
, sheet
, FALSE
)) {
130 cmd_insert_cols (wbc
, sheet
, sel
->start
.col
, cols
);
133 if (range_is_full (sel
, sheet
, TRUE
)) {
134 cmd_insert_rows (wbc
, sheet
, sel
->start
.row
, rows
);
138 if (gnm_dialog_raise_if_exists (wbcg
, INSERT_CELL_DIALOG_KEY
))
141 gui
= gnm_gtk_builder_load ("res:ui/insert-cells.ui", NULL
, GO_CMD_CONTEXT (wbcg
));
145 state
= g_new (InsertCellState
, 1);
148 state
->sheet
= sv_sheet (sv
);
150 state
->dialog
= go_gtk_builder_get_widget (state
->gui
, "Insert_cells");
151 if (state
->dialog
== NULL
) {
152 go_gtk_notice_dialog (wbcg_toplevel (wbcg
), GTK_MESSAGE_ERROR
,
153 _("Could not create the Insert Cell dialog."));
158 gnm_dialog_setup_destroy_handlers (GTK_DIALOG (state
->dialog
),
160 GNM_DIALOG_DESTROY_CURRENT_SHEET_REMOVED
);
162 state
->ok_button
= go_gtk_builder_get_widget (state
->gui
, "okbutton");
163 g_signal_connect (G_OBJECT (state
->ok_button
),
165 G_CALLBACK (cb_insert_cell_ok_clicked
), state
);
167 state
->cancel_button
= go_gtk_builder_get_widget (state
->gui
, "cancelbutton");
168 g_signal_connect (G_OBJECT (state
->cancel_button
),
170 G_CALLBACK (cb_insert_cell_cancel_clicked
), state
);
172 gnm_init_help_button (
173 go_gtk_builder_get_widget (state
->gui
, "helpbutton"),
174 GNUMERIC_HELP_LINK_INSERT_CELS
);
175 gtk_toggle_button_set_active
176 (GTK_TOGGLE_BUTTON (go_gtk_builder_get_widget
177 (state
->gui
, cols
< rows
178 ? "radio_0" : "radio_1")),
181 wbc_gtk_attach_guru (state
->wbcg
, state
->dialog
);
182 g_object_set_data_full (G_OBJECT (state
->dialog
),
183 "state", state
, (GDestroyNotify
) cb_insert_cell_destroy
);
185 gnm_keyed_dialog (wbcg
, GTK_WINDOW (state
->dialog
),
186 INSERT_CELL_DIALOG_KEY
);
187 gtk_widget_show (state
->dialog
);