2 * dialog-row-height.c: Sets the magnification factor
5 * Andreas J. Guelzow <aguelzow@taliesin.ca>
7 * (c) Copyright 2002 Andreas J. Guelzow <aguelzow@taliesin.ca>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, see <https://www.gnu.org/licenses/>.
22 #include <gnumeric-config.h>
23 #include <glib/gi18n-lib.h>
25 #include <dialogs/dialogs.h>
26 #include <dialogs/help.h>
30 #include <workbook-control.h>
34 #include <sheet-view.h>
35 #include <application.h>
36 #include <workbook-cmd-format.h>
39 #define ROW_HEIGHT_DIALOG_KEY "row-height-dialog"
48 GtkWidget
*apply_button
;
49 GtkWidget
*cancel_button
;
50 GtkWidget
*default_check
;
51 GtkWidget
*description
;
55 gboolean set_default_value
;
58 gboolean orig_is_default
;
59 gboolean orig_some_default
;
60 gboolean orig_all_equal
;
65 dialog_row_height_update_points (RowHeightState
*state
)
67 gint value
= gtk_spin_button_get_value_as_int (state
->spin
);
68 double size_points
= value
* 72./gnm_app_display_dpi_get (TRUE
);
71 pts
= g_strdup_printf ("%.2f",size_points
);
72 gtk_label_set_text (GTK_LABEL (state
->points
), pts
);
77 dialog_row_height_button_sensitivity (RowHeightState
*state
)
79 gint value
= gtk_spin_button_get_value_as_int (state
->spin
);
80 gboolean use_default
= gtk_toggle_button_get_active
81 (GTK_TOGGLE_BUTTON (state
->default_check
));
82 gboolean changed_info
;
84 if (state
->set_default_value
) {
85 changed_info
= (state
->orig_value
!= value
);
87 changed_info
= (((!state
->orig_all_equal
|| (state
->orig_value
!= value
)
88 || state
->orig_some_default
) && !use_default
)
89 || (use_default
&& !state
->orig_is_default
));
92 gtk_widget_set_sensitive (state
->ok_button
, changed_info
);
93 gtk_widget_set_sensitive (state
->apply_button
, changed_info
);
95 dialog_row_height_update_points (state
);
99 cb_dialog_row_height_destroy (RowHeightState
*state
)
101 if (state
->gui
!= NULL
)
102 g_object_unref (state
->gui
);
107 cb_dialog_row_height_cancel_clicked (G_GNUC_UNUSED GtkWidget
*button
,
108 RowHeightState
*state
)
110 gtk_widget_destroy (state
->dialog
);
115 dialog_row_height_set_value (gint value
, RowHeightState
*state
)
117 gint adj_value
= value
/state
->sheet
->last_zoom_factor_used
+ 0.5;
118 gtk_spin_button_set_value (state
->spin
, adj_value
);
123 dialog_row_height_load_value (RowHeightState
*state
)
127 state
->orig_is_default
= TRUE
;
128 state
->orig_some_default
= FALSE
;
129 state
->orig_all_equal
= TRUE
;
131 state
->adjusting
= TRUE
;
132 if (state
->set_default_value
) {
133 value
= sheet_row_get_default_size_pixels (state
->sheet
);
135 for (l
= state
->sv
->selections
; l
; l
= l
->next
){
136 GnmRange
*ss
= l
->data
;
139 for (row
= ss
->start
.row
; row
<= ss
->end
.row
; row
++){
140 ColRowInfo
const *ri
= sheet_row_get_info (state
->sheet
, row
);
142 state
->orig_is_default
= FALSE
;
144 state
->orig_some_default
= TRUE
;
146 value
= ri
->size_pixels
;
147 else if (value
!= ri
->size_pixels
){
148 /* Values differ, so let the user enter the data */
149 state
->orig_all_equal
= FALSE
;
153 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (state
->default_check
),
154 state
->orig_is_default
);
156 state
->orig_value
= dialog_row_height_set_value (value
, state
);
157 dialog_row_height_button_sensitivity (state
);
158 state
->adjusting
= FALSE
;
162 cb_dialog_row_height_value_changed (G_GNUC_UNUSED GtkSpinButton
*spinbutton
,
163 RowHeightState
*state
)
165 if (!state
->adjusting
) {
166 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (state
->default_check
), FALSE
);
167 dialog_row_height_button_sensitivity (state
);
172 cb_dialog_row_height_default_check_toggled (GtkToggleButton
*togglebutton
, RowHeightState
*state
)
174 if (!state
->adjusting
) {
175 if (gtk_toggle_button_get_active (togglebutton
)) {
176 state
->adjusting
= TRUE
;
177 dialog_row_height_set_value (sheet_row_get_default_size_pixels (state
->sheet
),
179 state
->adjusting
= FALSE
;
181 dialog_row_height_button_sensitivity (state
);
186 cb_dialog_row_height_apply_clicked (G_GNUC_UNUSED GtkWidget
*button
,
187 RowHeightState
*state
)
189 gint value
= gtk_spin_button_get_value_as_int (state
->spin
);
190 int size_pixels
= (int)(value
* state
->sheet
->last_zoom_factor_used
+ 0.5);
191 gboolean use_default
= gtk_toggle_button_get_active
192 (GTK_TOGGLE_BUTTON (state
->default_check
));
194 if (state
->set_default_value
) {
195 double points
= value
* 72./gnm_app_display_dpi_get (TRUE
);
196 cmd_colrow_std_size (GNM_WBC (state
->wbcg
),
197 state
->sheet
, FALSE
, points
);
198 dialog_row_height_load_value (state
);
203 workbook_cmd_resize_selected_colrow (GNM_WBC (state
->wbcg
),
204 state
->sheet
, FALSE
, size_pixels
);
205 dialog_row_height_load_value (state
);
210 cb_dialog_row_height_ok_clicked (GtkWidget
*button
, RowHeightState
*state
)
212 cb_dialog_row_height_apply_clicked (button
, state
);
213 gtk_widget_destroy (state
->dialog
);
218 dialog_row_height_set_mode (gboolean set_default
, RowHeightState
*state
)
220 state
->set_default_value
= set_default
;
223 gtk_widget_hide (state
->default_check
);
224 gtk_label_set_text (GTK_LABEL (state
->description
),
225 _("Set standard/default row height"));
228 char *name
= g_markup_escape_text (state
->sheet
->name_unquoted
, -1);
229 gtk_widget_show (state
->default_check
);
230 text
= g_strdup_printf (_("Set row height of selection on "
231 "<span style='italic' weight='bold'>%s</span>"),
233 gtk_label_set_markup (GTK_LABEL (state
->description
), text
);
241 dialog_row_height (WBCGtk
*wbcg
, gboolean use_default
)
243 RowHeightState
*state
;
245 g_return_if_fail (wbcg
!= NULL
);
247 if (gnm_dialog_raise_if_exists (wbcg
, ROW_HEIGHT_DIALOG_KEY
))
250 state
= g_new (RowHeightState
, 1);
252 state
->sv
= wb_control_cur_sheet_view (GNM_WBC (wbcg
));
253 state
->sheet
= sv_sheet (state
->sv
);
254 state
->adjusting
= FALSE
;
255 state
->gui
= gnm_gtk_builder_load ("res:ui/row-height.ui", NULL
, GO_CMD_CONTEXT (wbcg
));
256 g_return_if_fail (state
->gui
!= NULL
);
258 state
->dialog
= go_gtk_builder_get_widget (state
->gui
, "dialog");
260 state
->description
= GTK_WIDGET (go_gtk_builder_get_widget (state
->gui
, "description"));
261 state
->points
= GTK_WIDGET (go_gtk_builder_get_widget (state
->gui
, "pts-label"));
263 state
->spin
= GTK_SPIN_BUTTON (go_gtk_builder_get_widget (state
->gui
, "spin"));
264 gtk_adjustment_set_lower (gtk_spin_button_get_adjustment (state
->spin
),
265 GNM_ROW_MARGIN
+ GNM_ROW_MARGIN
+ 1);
266 g_signal_connect (G_OBJECT (state
->spin
),
268 G_CALLBACK (cb_dialog_row_height_value_changed
), state
);
270 state
->default_check
= GTK_WIDGET (go_gtk_builder_get_widget (state
->gui
, "default_check"));
271 g_signal_connect (G_OBJECT (state
->default_check
),
273 G_CALLBACK (cb_dialog_row_height_default_check_toggled
), state
);
275 state
->ok_button
= go_gtk_builder_get_widget (state
->gui
, "ok_button");
276 g_signal_connect (G_OBJECT (state
->ok_button
),
278 G_CALLBACK (cb_dialog_row_height_ok_clicked
), state
);
279 state
->apply_button
= go_gtk_builder_get_widget (state
->gui
, "apply_button");
280 g_signal_connect (G_OBJECT (state
->apply_button
),
282 G_CALLBACK (cb_dialog_row_height_apply_clicked
), state
);
284 state
->cancel_button
= go_gtk_builder_get_widget (state
->gui
, "cancel_button");
285 g_signal_connect (G_OBJECT (state
->cancel_button
),
287 G_CALLBACK (cb_dialog_row_height_cancel_clicked
), state
);
289 gnm_init_help_button (
290 go_gtk_builder_get_widget (state
->gui
, "help_button"),
291 GNUMERIC_HELP_LINK_ROW_HEIGHT
);
292 g_object_set_data_full (G_OBJECT (state
->dialog
),
293 "state", state
, (GDestroyNotify
) cb_dialog_row_height_destroy
);
295 gnm_dialog_setup_destroy_handlers (GTK_DIALOG (state
->dialog
),
297 GNM_DIALOG_DESTROY_CURRENT_SHEET_REMOVED
);
299 dialog_row_height_set_mode (use_default
, state
);
300 dialog_row_height_load_value (state
);
302 wbc_gtk_attach_guru (state
->wbcg
, state
->dialog
);
303 gnm_keyed_dialog (wbcg
, GTK_WINDOW (state
->dialog
),
304 ROW_HEIGHT_DIALOG_KEY
);
305 gtk_widget_show (state
->dialog
);