1 /*
2  * e-html-editor-table-dialog.h
3  *
4  * Copyright (C) 2012 Dan Vrátil <dvratil@redhat.com>
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) version 3.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with the program; if not, see <http://www.gnu.org/licenses/>
18  *
19  */
20 
21 #include "evolution-config.h"
22 
23 #include "e-html-editor-table-dialog.h"
24 
25 #include <glib/gi18n-lib.h>
26 
27 #include "e-color-combo.h"
28 #include "e-dialog-widgets.h"
29 #include "e-image-chooser-dialog.h"
30 #include "e-misc-utils.h"
31 
32 #define E_HTML_EDITOR_TABLE_DIALOG_GET_PRIVATE(obj) \
33 	(G_TYPE_INSTANCE_GET_PRIVATE \
34 	((obj), E_TYPE_HTML_EDITOR_TABLE_DIALOG, EHTMLEditorTableDialogPrivate))
35 
36 struct _EHTMLEditorTableDialogPrivate {
37 	GtkWidget *rows_edit;
38 	GtkWidget *columns_edit;
39 
40 	GtkWidget *width_edit;
41 	GtkWidget *width_units;
42 	GtkWidget *width_check;
43 
44 	GtkWidget *spacing_edit;
45 	GtkWidget *padding_edit;
46 	GtkWidget *border_edit;
47 
48 	GtkWidget *alignment_combo;
49 
50 	GtkWidget *background_color_picker;
51 	GtkWidget *background_image_chooser;
52 
53 	GtkWidget *remove_image_button;
54 };
55 
56 static GdkRGBA transparent = { 0, 0, 0, 0 };
57 
58 G_DEFINE_TYPE (
59 	EHTMLEditorTableDialog,
60 	e_html_editor_table_dialog,
61 	E_TYPE_HTML_EDITOR_DIALOG);
62 
63 static void
html_editor_table_dialog_set_row_count(EHTMLEditorTableDialog * dialog)64 html_editor_table_dialog_set_row_count (EHTMLEditorTableDialog *dialog)
65 {
66 	EHTMLEditor *editor;
67 	EContentEditor *cnt_editor;
68 
69 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
70 	cnt_editor = e_html_editor_get_content_editor (editor);
71 
72 	e_content_editor_table_set_row_count (
73 		cnt_editor,
74 		gtk_spin_button_get_value (
75 			GTK_SPIN_BUTTON (dialog->priv->rows_edit)));
76 }
77 
78 static void
html_editor_table_dialog_get_row_count(EHTMLEditorTableDialog * dialog)79 html_editor_table_dialog_get_row_count (EHTMLEditorTableDialog *dialog)
80 {
81 	EHTMLEditor *editor;
82 	EContentEditor *cnt_editor;
83 
84 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
85 	cnt_editor = e_html_editor_get_content_editor (editor);
86 
87 	gtk_spin_button_set_value (
88 		GTK_SPIN_BUTTON (dialog->priv->rows_edit),
89 		e_content_editor_table_get_row_count (cnt_editor));
90 }
91 
92 static void
html_editor_table_dialog_set_column_count(EHTMLEditorTableDialog * dialog)93 html_editor_table_dialog_set_column_count (EHTMLEditorTableDialog *dialog)
94 {
95 	EHTMLEditor *editor;
96 	EContentEditor *cnt_editor;
97 
98 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
99 	cnt_editor = e_html_editor_get_content_editor (editor);
100 
101 	e_content_editor_table_set_column_count (
102 		cnt_editor,
103 		gtk_spin_button_get_value (
104 			GTK_SPIN_BUTTON (dialog->priv->columns_edit)));
105 }
106 
107 static void
html_editor_table_dialog_get_column_count(EHTMLEditorTableDialog * dialog)108 html_editor_table_dialog_get_column_count (EHTMLEditorTableDialog *dialog)
109 {
110 	EHTMLEditor *editor;
111 	EContentEditor *cnt_editor;
112 
113 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
114 	cnt_editor = e_html_editor_get_content_editor (editor);
115 
116 	gtk_spin_button_set_value (
117 		GTK_SPIN_BUTTON (dialog->priv->columns_edit),
118 		e_content_editor_table_get_column_count (cnt_editor));
119 }
120 
121 static void
html_editor_table_dialog_set_width(EHTMLEditorTableDialog * dialog)122 html_editor_table_dialog_set_width (EHTMLEditorTableDialog *dialog)
123 {
124 	EHTMLEditor *editor;
125 	EContentEditor *cnt_editor;
126 
127 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
128 	cnt_editor = e_html_editor_get_content_editor (editor);
129 
130 	if (gtk_toggle_button_get_active (
131 			GTK_TOGGLE_BUTTON (dialog->priv->width_check))) {
132 
133 		e_content_editor_table_set_width (
134 			cnt_editor,
135 			gtk_spin_button_get_value_as_int (
136 				GTK_SPIN_BUTTON (dialog->priv->width_edit)),
137 			(gtk_combo_box_get_active (
138 				GTK_COMBO_BOX (dialog->priv->width_units)) == 0) ?
139 					E_CONTENT_EDITOR_UNIT_PIXEL :
140 					E_CONTENT_EDITOR_UNIT_PERCENTAGE);
141 
142 		gtk_widget_set_sensitive (dialog->priv->width_edit, TRUE);
143 		gtk_widget_set_sensitive (dialog->priv->width_units, TRUE);
144 	} else {
145 		e_content_editor_table_set_width (
146 			cnt_editor, 0, E_CONTENT_EDITOR_UNIT_AUTO);
147 
148 		gtk_widget_set_sensitive (dialog->priv->width_edit, FALSE);
149 		gtk_widget_set_sensitive (dialog->priv->width_units, FALSE);
150 	}
151 }
152 
153 static void
html_editor_table_dialog_width_units_changed(GtkWidget * widget,EHTMLEditorTableDialog * dialog)154 html_editor_table_dialog_width_units_changed (GtkWidget *widget,
155                                               EHTMLEditorTableDialog *dialog)
156 {
157 	if (gtk_combo_box_get_active (GTK_COMBO_BOX (dialog->priv->width_units)) == 0) {
158 		gtk_spin_button_set_range (
159 			GTK_SPIN_BUTTON (dialog->priv->width_edit), 0, G_MAXUINT);
160 	} else
161 		gtk_spin_button_set_range (
162 			GTK_SPIN_BUTTON (dialog->priv->width_edit), 0, 100);
163 
164 	html_editor_table_dialog_set_width (dialog);
165 }
166 
167 static void
html_editor_table_dialog_get_width(EHTMLEditorTableDialog * dialog)168 html_editor_table_dialog_get_width (EHTMLEditorTableDialog *dialog)
169 {
170 	EHTMLEditor *editor;
171 	EContentEditor *cnt_editor;
172 	EContentEditorUnit unit;
173 	gint width;
174 
175 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
176 	cnt_editor = e_html_editor_get_content_editor (editor);
177 
178 	width = e_content_editor_table_get_width (cnt_editor, &unit);
179 
180 	gtk_toggle_button_set_active (
181 		GTK_TOGGLE_BUTTON (dialog->priv->width_check),
182 		unit != E_CONTENT_EDITOR_UNIT_AUTO);
183 	gtk_spin_button_set_value (
184 		GTK_SPIN_BUTTON (dialog->priv->width_edit),
185 		unit == E_CONTENT_EDITOR_UNIT_AUTO ? 100 : width);
186 	gtk_combo_box_set_active_id (
187 		GTK_COMBO_BOX (dialog->priv->width_units),
188 		unit == E_CONTENT_EDITOR_UNIT_PIXEL ? "units-px" : "units-percent");
189 }
190 
191 static void
html_editor_table_dialog_set_alignment(EHTMLEditorTableDialog * dialog)192 html_editor_table_dialog_set_alignment (EHTMLEditorTableDialog *dialog)
193 {
194 	EHTMLEditor *editor;
195 	EContentEditor *cnt_editor;
196 
197 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
198 	cnt_editor = e_html_editor_get_content_editor (editor);
199 
200 	e_content_editor_table_set_align (
201 		cnt_editor,
202 		gtk_combo_box_get_active_id (
203 			GTK_COMBO_BOX (dialog->priv->alignment_combo)));
204 }
205 
206 static void
html_editor_table_dialog_get_alignment(EHTMLEditorTableDialog * dialog)207 html_editor_table_dialog_get_alignment (EHTMLEditorTableDialog *dialog)
208 {
209 	EHTMLEditor *editor;
210 	EContentEditor *cnt_editor;
211 	gchar *value;
212 
213 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
214 	cnt_editor = e_html_editor_get_content_editor (editor);
215 
216 	value = e_content_editor_table_get_align (cnt_editor);
217 	gtk_combo_box_set_active_id (GTK_COMBO_BOX (dialog->priv->alignment_combo),
218 		value && *value ? value : "left");
219 	g_free (value);
220 }
221 
222 static void
html_editor_table_dialog_set_padding(EHTMLEditorTableDialog * dialog)223 html_editor_table_dialog_set_padding (EHTMLEditorTableDialog *dialog)
224 {
225 	EHTMLEditor *editor;
226 	EContentEditor *cnt_editor;
227 
228 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
229 	cnt_editor = e_html_editor_get_content_editor (editor);
230 
231 	e_content_editor_table_set_padding (
232 		cnt_editor,
233 		gtk_spin_button_get_value_as_int (
234 			GTK_SPIN_BUTTON (dialog->priv->padding_edit)));
235 }
236 
237 static void
html_editor_table_dialog_get_padding(EHTMLEditorTableDialog * dialog)238 html_editor_table_dialog_get_padding (EHTMLEditorTableDialog *dialog)
239 {
240 	EHTMLEditor *editor;
241 	EContentEditor *cnt_editor;
242 
243 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
244 	cnt_editor = e_html_editor_get_content_editor (editor);
245 
246 	gtk_spin_button_set_value (
247 		GTK_SPIN_BUTTON (dialog->priv->padding_edit),
248 		e_content_editor_table_get_padding (cnt_editor));
249 }
250 
251 static void
html_editor_table_dialog_set_spacing(EHTMLEditorTableDialog * dialog)252 html_editor_table_dialog_set_spacing (EHTMLEditorTableDialog *dialog)
253 {
254 	EHTMLEditor *editor;
255 	EContentEditor *cnt_editor;
256 
257 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
258 	cnt_editor = e_html_editor_get_content_editor (editor);
259 
260 	e_content_editor_table_set_spacing (
261 		cnt_editor,
262 		gtk_spin_button_get_value_as_int (
263 			GTK_SPIN_BUTTON (dialog->priv->spacing_edit)));
264 }
265 
266 static void
html_editor_table_dialog_get_spacing(EHTMLEditorTableDialog * dialog)267 html_editor_table_dialog_get_spacing (EHTMLEditorTableDialog *dialog)
268 {
269 	EHTMLEditor *editor;
270 	EContentEditor *cnt_editor;
271 
272 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
273 	cnt_editor = e_html_editor_get_content_editor (editor);
274 
275 	gtk_spin_button_set_value (
276 		GTK_SPIN_BUTTON (dialog->priv->spacing_edit),
277 		e_content_editor_table_get_spacing (cnt_editor));
278 }
279 
280 static void
html_editor_table_dialog_set_border(EHTMLEditorTableDialog * dialog)281 html_editor_table_dialog_set_border (EHTMLEditorTableDialog *dialog)
282 {
283 	EHTMLEditor *editor;
284 	EContentEditor *cnt_editor;
285 
286 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
287 	cnt_editor = e_html_editor_get_content_editor (editor);
288 
289 	e_content_editor_table_set_border (
290 		cnt_editor,
291 		gtk_spin_button_get_value_as_int (
292 			GTK_SPIN_BUTTON (dialog->priv->border_edit)));
293 }
294 
295 static void
html_editor_table_dialog_get_border(EHTMLEditorTableDialog * dialog)296 html_editor_table_dialog_get_border (EHTMLEditorTableDialog *dialog)
297 {
298 	EHTMLEditor *editor;
299 	EContentEditor *cnt_editor;
300 
301 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
302 	cnt_editor = e_html_editor_get_content_editor (editor);
303 
304 	gtk_spin_button_set_value (
305 		GTK_SPIN_BUTTON (dialog->priv->border_edit),
306 		e_content_editor_table_get_border (cnt_editor));
307 }
308 
309 static void
html_editor_table_dialog_set_background_color(EHTMLEditorTableDialog * dialog)310 html_editor_table_dialog_set_background_color (EHTMLEditorTableDialog *dialog)
311 {
312 	EHTMLEditor *editor;
313 	EContentEditor *cnt_editor;
314 	GdkRGBA rgba;
315 
316 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
317 	cnt_editor = e_html_editor_get_content_editor (editor);
318 
319 	e_color_combo_get_current_color (
320 		E_COLOR_COMBO (dialog->priv->background_color_picker), &rgba);
321 	e_content_editor_table_set_background_color (cnt_editor, &rgba);
322 }
323 
324 static void
html_editor_table_dialog_get_background_color(EHTMLEditorTableDialog * dialog)325 html_editor_table_dialog_get_background_color (EHTMLEditorTableDialog *dialog)
326 {
327 	EHTMLEditor *editor;
328 	EContentEditor *cnt_editor;
329 	GdkRGBA rgba;
330 
331 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
332 	cnt_editor = e_html_editor_get_content_editor (editor);
333 
334 	e_content_editor_table_get_background_color (cnt_editor, &rgba);
335 	e_color_combo_set_current_color (
336 		E_COLOR_COMBO (dialog->priv->background_color_picker), &rgba);
337 }
338 
339 static void
html_editor_table_dialog_set_background_image(EHTMLEditorTableDialog * dialog)340 html_editor_table_dialog_set_background_image (EHTMLEditorTableDialog *dialog)
341 {
342 	EHTMLEditor *editor;
343 	EContentEditor *cnt_editor;
344 	gchar *uri;
345 
346 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
347 	cnt_editor = e_html_editor_get_content_editor (editor);
348 
349 	uri = gtk_file_chooser_get_uri (
350 		GTK_FILE_CHOOSER (dialog->priv->background_image_chooser));
351 
352 	e_content_editor_table_set_background_image_uri (cnt_editor, uri);
353 
354 	gtk_widget_set_sensitive (dialog->priv->remove_image_button, uri && *uri);
355 
356 	g_free (uri);
357 }
358 
359 static void
html_editor_table_dialog_get_background_image(EHTMLEditorTableDialog * dialog)360 html_editor_table_dialog_get_background_image (EHTMLEditorTableDialog *dialog)
361 {
362 	EHTMLEditor *editor;
363 	EContentEditor *cnt_editor;
364 	gchar *uri;
365 
366 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
367 	cnt_editor = e_html_editor_get_content_editor (editor);
368 
369 	uri = e_content_editor_table_get_background_image_uri (cnt_editor);
370 	if (uri && *uri)
371 		gtk_file_chooser_set_uri (
372 			GTK_FILE_CHOOSER (dialog->priv->background_image_chooser), uri);
373 	else
374 		gtk_file_chooser_unselect_all (
375 			GTK_FILE_CHOOSER (dialog->priv->background_image_chooser));
376 
377 	g_free (uri);
378 }
379 
380 static void
html_editor_table_dialog_get_values(EHTMLEditorTableDialog * dialog)381 html_editor_table_dialog_get_values (EHTMLEditorTableDialog *dialog)
382 {
383 	html_editor_table_dialog_get_row_count (dialog);
384 	html_editor_table_dialog_get_column_count (dialog);
385 	html_editor_table_dialog_get_width (dialog);
386 	html_editor_table_dialog_get_alignment (dialog);
387 	html_editor_table_dialog_get_spacing (dialog);
388 	html_editor_table_dialog_get_padding (dialog);
389 	html_editor_table_dialog_get_border (dialog);
390 	html_editor_table_dialog_get_background_color (dialog);
391 	html_editor_table_dialog_get_background_image (dialog);
392 }
393 
394 static void
html_editor_table_dialog_reset_values(EHTMLEditorTableDialog * dialog)395 html_editor_table_dialog_reset_values (EHTMLEditorTableDialog *dialog)
396 {
397 	gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->rows_edit), 3);
398 	gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->columns_edit), 3);
399 	gtk_combo_box_set_active_id (GTK_COMBO_BOX (dialog->priv->alignment_combo), "left");
400 
401 	gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (dialog->priv->width_check), TRUE);
402 	gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->width_edit), 100);
403 	gtk_combo_box_set_active_id (GTK_COMBO_BOX (dialog->priv->width_units), "units-percent");
404 
405 	gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->spacing_edit), 2);
406 	gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->padding_edit), 1);
407 	gtk_spin_button_set_value (GTK_SPIN_BUTTON (dialog->priv->border_edit), 1);
408 
409 	e_color_combo_set_current_color (E_COLOR_COMBO (dialog->priv->background_color_picker), &transparent);
410 
411 	gtk_file_chooser_unselect_all (GTK_FILE_CHOOSER (dialog->priv->background_image_chooser));
412 
413 	html_editor_table_dialog_set_row_count (dialog);
414 	html_editor_table_dialog_set_column_count (dialog);
415 	html_editor_table_dialog_set_width (dialog);
416 	html_editor_table_dialog_set_alignment (dialog);
417 	html_editor_table_dialog_set_spacing (dialog);
418 	html_editor_table_dialog_set_padding (dialog);
419 	html_editor_table_dialog_set_border (dialog);
420 	html_editor_table_dialog_set_background_color (dialog);
421 	html_editor_table_dialog_set_background_image (dialog);
422 }
423 
424 static void
html_editor_table_dialog_show(GtkWidget * widget)425 html_editor_table_dialog_show (GtkWidget *widget)
426 {
427 	EHTMLEditorTableDialog *dialog;
428 	EHTMLEditor *editor;
429 	EContentEditor *cnt_editor;
430 
431 	dialog = E_HTML_EDITOR_TABLE_DIALOG (widget);
432 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
433 	cnt_editor = e_html_editor_get_content_editor (editor);
434 
435 	e_content_editor_on_dialog_open (cnt_editor, E_CONTENT_EDITOR_DIALOG_TABLE);
436 
437 	if (!e_content_editor_table_get_row_count (cnt_editor))
438 		html_editor_table_dialog_reset_values (dialog);
439 	else
440 		html_editor_table_dialog_get_values (dialog);
441 
442 	/* Chain up to parent implementation */
443 	GTK_WIDGET_CLASS (e_html_editor_table_dialog_parent_class)->show (widget);
444 }
445 
446 static void
html_editor_table_dialog_remove_image(EHTMLEditorTableDialog * dialog)447 html_editor_table_dialog_remove_image (EHTMLEditorTableDialog *dialog)
448 {
449 	EHTMLEditor *editor;
450 	EContentEditor *cnt_editor;
451 
452 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
453 	cnt_editor = e_html_editor_get_content_editor (editor);
454 
455 	e_content_editor_table_set_background_image_uri (cnt_editor, NULL);
456 
457 	gtk_file_chooser_unselect_all (
458 		GTK_FILE_CHOOSER (dialog->priv->background_image_chooser));
459 
460 	gtk_widget_set_sensitive (dialog->priv->remove_image_button, FALSE);
461 }
462 
463 static void
html_editor_table_dialog_hide(GtkWidget * widget)464 html_editor_table_dialog_hide (GtkWidget *widget)
465 {
466 	EHTMLEditorTableDialog *dialog;
467 	EHTMLEditor *editor;
468 	EContentEditor *cnt_editor;
469 
470 	dialog = E_HTML_EDITOR_TABLE_DIALOG (widget);
471 	editor = e_html_editor_dialog_get_editor (E_HTML_EDITOR_DIALOG (dialog));
472 	cnt_editor = e_html_editor_get_content_editor (editor);
473 
474 	e_content_editor_on_dialog_close (cnt_editor, E_CONTENT_EDITOR_DIALOG_TABLE);
475 
476 	GTK_WIDGET_CLASS (e_html_editor_table_dialog_parent_class)->hide (widget);
477 }
478 
479 static void
e_html_editor_table_dialog_class_init(EHTMLEditorTableDialogClass * class)480 e_html_editor_table_dialog_class_init (EHTMLEditorTableDialogClass *class)
481 {
482 	GtkWidgetClass *widget_class;
483 
484 	g_type_class_add_private (class, sizeof (EHTMLEditorTableDialogPrivate));
485 
486 	widget_class = GTK_WIDGET_CLASS (class);
487 	widget_class->show = html_editor_table_dialog_show;
488 	widget_class->hide = html_editor_table_dialog_hide;
489 }
490 
491 static void
e_html_editor_table_dialog_init(EHTMLEditorTableDialog * dialog)492 e_html_editor_table_dialog_init (EHTMLEditorTableDialog *dialog)
493 {
494 	GtkBox *box;
495 	GtkGrid *main_layout, *grid;
496 	GtkWidget *widget;
497 	GtkFileFilter *file_filter;
498 
499 	dialog->priv = E_HTML_EDITOR_TABLE_DIALOG_GET_PRIVATE (dialog);
500 
501 	main_layout = e_html_editor_dialog_get_container (E_HTML_EDITOR_DIALOG (dialog));
502 
503 	/* == General == */
504 	widget = gtk_label_new ("");
505 	gtk_label_set_markup (GTK_LABEL (widget), _("<b>General</b>"));
506 	gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
507 	gtk_grid_attach (main_layout, widget, 0, 0, 1, 1);
508 
509 	grid = GTK_GRID (gtk_grid_new ());
510 	gtk_grid_set_row_spacing (grid, 5);
511 	gtk_grid_set_column_spacing (grid, 5);
512 	gtk_grid_attach (main_layout, GTK_WIDGET (grid), 0, 1, 1, 1);
513 	gtk_widget_set_margin_left (GTK_WIDGET (grid), 10);
514 
515 	/* Rows */
516 	widget = gtk_image_new_from_icon_name ("stock_select-row", GTK_ICON_SIZE_BUTTON);
517 	gtk_grid_attach (grid, widget, 0, 0, 1, 1);
518 
519 	widget = gtk_spin_button_new_with_range (1, G_MAXINT, 1);
520 	gtk_spin_button_set_digits (GTK_SPIN_BUTTON (widget), 0);
521 	gtk_grid_attach (grid, widget, 2, 0, 1, 1);
522 	g_signal_connect_swapped (
523 		widget, "value-changed",
524 		G_CALLBACK (html_editor_table_dialog_set_row_count), dialog);
525 	dialog->priv->rows_edit = widget;
526 
527 	widget = gtk_label_new_with_mnemonic (_("_Rows:"));
528 	gtk_label_set_justify (GTK_LABEL (widget), GTK_JUSTIFY_RIGHT);
529 	gtk_label_set_mnemonic_widget (GTK_LABEL (widget), dialog->priv->rows_edit);
530 	gtk_grid_attach (grid, widget, 1, 0, 1, 1);
531 
532 	/* Columns */
533 	widget = gtk_image_new_from_icon_name ("stock_select-column", GTK_ICON_SIZE_BUTTON);
534 	gtk_grid_attach (grid, widget, 3, 0, 1, 1);
535 
536 	widget = gtk_spin_button_new_with_range (1, G_MAXINT, 1);
537 	gtk_spin_button_set_digits (GTK_SPIN_BUTTON (widget), 0);
538 	gtk_grid_attach (grid, widget, 5, 0, 1, 1);
539 	g_signal_connect_swapped (
540 		widget, "value-changed",
541 		G_CALLBACK (html_editor_table_dialog_set_column_count), dialog);
542 	dialog->priv->columns_edit = widget;
543 
544 	widget = gtk_label_new_with_mnemonic (_("C_olumns:"));
545 	gtk_label_set_justify (GTK_LABEL (widget), GTK_JUSTIFY_RIGHT);
546 	gtk_label_set_mnemonic_widget (GTK_LABEL (widget), dialog->priv->columns_edit);
547 	gtk_grid_attach (grid, widget, 4, 0, 1, 1);
548 
549 	/* == Layout == */
550 	widget = gtk_label_new ("");
551 	gtk_label_set_markup (GTK_LABEL (widget), _("<b>Layout</b>"));
552 	gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
553 	gtk_grid_attach (main_layout, widget, 0, 2, 1, 1);
554 
555 	grid = GTK_GRID (gtk_grid_new ());
556 	gtk_grid_set_row_spacing (grid, 5);
557 	gtk_grid_set_column_spacing (grid, 5);
558 	gtk_grid_attach (main_layout, GTK_WIDGET (grid), 0, 3, 1, 1);
559 	gtk_widget_set_margin_left (GTK_WIDGET (grid), 10);
560 
561 	/* Width */
562 	widget = gtk_check_button_new_with_mnemonic (_("_Width:"));
563 	gtk_grid_attach (grid, widget, 0, 0, 1, 1);
564 	g_signal_connect_swapped (
565 		widget, "toggled",
566 		G_CALLBACK (html_editor_table_dialog_set_width), dialog);
567 	dialog->priv->width_check = widget;
568 
569 	widget = gtk_spin_button_new_with_range (1, 100, 1);
570 	gtk_spin_button_set_digits (GTK_SPIN_BUTTON (widget), 0);
571 	gtk_grid_attach (grid, widget, 1, 0, 1, 1);
572 	g_signal_connect_swapped (
573 		widget, "value-changed",
574 		G_CALLBACK (html_editor_table_dialog_set_width), dialog);
575 	dialog->priv->width_edit = widget;
576 
577 	widget = gtk_combo_box_text_new ();
578 	gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), "units-px", "px");
579 	gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), "units-percent", "%");
580 	gtk_grid_attach (grid, widget, 2, 0, 1, 1);
581 	g_signal_connect (
582 		widget, "changed",
583 		G_CALLBACK (html_editor_table_dialog_width_units_changed), dialog);
584 	dialog->priv->width_units = widget;
585 
586 	/* Spacing */
587 	widget = gtk_spin_button_new_with_range (0, G_MAXINT, 1);
588 	gtk_spin_button_set_digits (GTK_SPIN_BUTTON (widget), 0);
589 	gtk_grid_attach (grid, widget, 5, 0, 1, 1);
590 	g_signal_connect_swapped (
591 		widget, "value-changed",
592 		G_CALLBACK (html_editor_table_dialog_set_spacing), dialog);
593 	dialog->priv->spacing_edit = widget;
594 
595 	widget = gtk_label_new_with_mnemonic (_("_Spacing:"));
596 	gtk_label_set_justify (GTK_LABEL (widget), GTK_JUSTIFY_RIGHT);
597 	gtk_label_set_mnemonic_widget (GTK_LABEL (widget), dialog->priv->spacing_edit);
598 	gtk_grid_attach (grid, widget, 4, 0, 1, 1);
599 
600 	widget = gtk_label_new ("px");
601 	gtk_grid_attach (grid, widget, 6, 0, 1, 1);
602 
603 	/* Padding */
604 	widget = gtk_spin_button_new_with_range (0, G_MAXINT, 1);
605 	gtk_spin_button_set_digits (GTK_SPIN_BUTTON (widget), 0);
606 	gtk_grid_attach (grid, widget, 5, 1, 1, 1);
607 	g_signal_connect_swapped (
608 		widget, "value-changed",
609 		G_CALLBACK (html_editor_table_dialog_set_padding), dialog);
610 	dialog->priv->padding_edit = widget;
611 
612 	widget = gtk_label_new_with_mnemonic (_("_Padding:"));
613 	gtk_label_set_justify (GTK_LABEL (widget), GTK_JUSTIFY_RIGHT);
614 	gtk_label_set_mnemonic_widget (GTK_LABEL (widget), dialog->priv->padding_edit);
615 	gtk_grid_attach (grid, widget, 4, 1, 1, 1);
616 
617 	widget = gtk_label_new ("px");
618 	gtk_grid_attach (grid, widget, 6, 1, 1, 1);
619 
620 	/* Border */
621 	widget = gtk_spin_button_new_with_range (0, G_MAXINT, 1);
622 	gtk_spin_button_set_digits (GTK_SPIN_BUTTON (widget), 0);
623 	gtk_grid_attach (grid, widget, 5, 2, 1, 1);
624 	g_signal_connect_swapped (
625 		widget, "value-changed",
626 		G_CALLBACK (html_editor_table_dialog_set_border), dialog);
627 	dialog->priv->border_edit = widget;
628 
629 	widget = gtk_label_new_with_mnemonic (_("_Border:"));
630 	gtk_label_set_justify (GTK_LABEL (widget), GTK_JUSTIFY_RIGHT);
631 	gtk_label_set_mnemonic_widget (GTK_LABEL (widget), dialog->priv->border_edit);
632 	gtk_grid_attach (grid, widget, 4, 2, 1, 1);
633 
634 	widget = gtk_label_new ("px");
635 	gtk_grid_attach (grid, widget, 6, 2, 1, 1);
636 
637 	/* Alignment */
638 	widget = gtk_combo_box_text_new ();
639 	gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), "left", _("Left"));
640 	gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), "center", _("Center"));
641 	gtk_combo_box_text_append (GTK_COMBO_BOX_TEXT (widget), "right", _("Right"));
642 	gtk_grid_attach (grid, widget, 1, 1, 2, 1);
643 	g_signal_connect_swapped (
644 		widget, "changed",
645 		G_CALLBACK (html_editor_table_dialog_set_alignment), dialog);
646 	dialog->priv->alignment_combo = widget;
647 
648 	widget = gtk_label_new_with_mnemonic (_("_Alignment:"));
649 	gtk_label_set_justify (GTK_LABEL (widget), GTK_JUSTIFY_RIGHT);
650 	gtk_label_set_mnemonic_widget (GTK_LABEL (widget), dialog->priv->alignment_combo);
651 	gtk_grid_attach (grid, widget, 0, 1, 1, 1);
652 
653 	/* == Background == */
654 	widget = gtk_label_new ("");
655 	gtk_label_set_markup (GTK_LABEL (widget), _("<b>Background</b>"));
656 	gtk_misc_set_alignment (GTK_MISC (widget), 0, 0.5);
657 	gtk_grid_attach (main_layout, widget, 0, 4, 1, 1);
658 
659 	grid = GTK_GRID (gtk_grid_new ());
660 	gtk_grid_set_row_spacing (grid, 5);
661 	gtk_grid_set_column_spacing (grid, 5);
662 	gtk_grid_attach (main_layout, GTK_WIDGET (grid), 0, 5, 1, 1);
663 	gtk_widget_set_margin_left (GTK_WIDGET (grid), 10);
664 
665 	/* Color */
666 	widget = e_color_combo_new ();
667 	e_color_combo_set_default_color (E_COLOR_COMBO (widget), &transparent);
668 	e_color_combo_set_default_label (E_COLOR_COMBO (widget), _("Transparent"));
669 	gtk_widget_set_hexpand (widget, TRUE);
670 	gtk_grid_attach (grid, widget, 1, 0, 1, 1);
671 	g_signal_connect_swapped (
672 		widget, "notify::current-color",
673 		G_CALLBACK (html_editor_table_dialog_set_background_color), dialog);
674 	dialog->priv->background_color_picker = widget;
675 
676 	widget = gtk_label_new_with_mnemonic (_("_Color:"));
677 	gtk_label_set_justify (GTK_LABEL (widget), GTK_JUSTIFY_RIGHT);
678 	gtk_label_set_mnemonic_widget (
679 		GTK_LABEL (widget), dialog->priv->background_color_picker);
680 	gtk_grid_attach (grid, widget, 0, 0, 1, 1);
681 
682 	file_filter = gtk_file_filter_new ();
683 	gtk_file_filter_set_name (file_filter, _("Images"));
684 	gtk_file_filter_add_mime_type (file_filter, "image/*");
685 
686 	/* Image */
687 	if (e_util_is_running_flatpak ()) {
688 		widget = gtk_file_chooser_button_new (_("Choose Background Image"), GTK_FILE_CHOOSER_ACTION_OPEN);
689 	} else {
690 		GtkWidget *image_chooser_dialog;
691 
692 		image_chooser_dialog = e_image_chooser_dialog_new (
693 				_("Choose Background Image"),
694 				GTK_WINDOW (dialog));
695 
696 		widget = gtk_file_chooser_button_new_with_dialog (image_chooser_dialog);
697 	}
698 
699 	gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (widget), file_filter);
700 	gtk_widget_set_hexpand (widget, TRUE);
701 	gtk_grid_attach (grid, widget, 1, 1, 1, 1);
702 	g_signal_connect_swapped (
703 		widget, "file-set",
704 		G_CALLBACK (html_editor_table_dialog_set_background_image), dialog);
705 	dialog->priv->background_image_chooser = widget;
706 
707 	widget =gtk_label_new_with_mnemonic (_("Image:"));
708 	gtk_label_set_justify (GTK_LABEL (widget), GTK_JUSTIFY_RIGHT);
709 	gtk_label_set_mnemonic_widget (
710 		GTK_LABEL (widget), dialog->priv->background_image_chooser);
711 	gtk_grid_attach (grid, widget, 0, 1, 1, 1);
712 
713 	box = e_html_editor_dialog_get_button_box (E_HTML_EDITOR_DIALOG (dialog));
714 	widget = e_dialog_button_new_with_icon (NULL, _("_Remove image"));
715 	g_signal_connect_swapped (
716 		widget, "clicked",
717 		G_CALLBACK (html_editor_table_dialog_remove_image), dialog);
718 	dialog->priv->remove_image_button = widget;
719 
720 	gtk_widget_set_sensitive (dialog->priv->remove_image_button, FALSE);
721 	gtk_box_pack_start (box, widget, FALSE, FALSE, 5);
722 	gtk_box_reorder_child (box, widget, 0);
723 
724 	gtk_widget_show_all (GTK_WIDGET (main_layout));
725 }
726 
727 GtkWidget *
e_html_editor_table_dialog_new(EHTMLEditor * editor)728 e_html_editor_table_dialog_new (EHTMLEditor *editor)
729 {
730 	return GTK_WIDGET (
731 		g_object_new (
732 			E_TYPE_HTML_EDITOR_TABLE_DIALOG,
733 			"editor", editor,
734 			"title", _("Table Properties"),
735 			NULL));
736 }
737