Tweak default stylesheet
[colloquium.git] / src / stylesheet.c
1 /*
2  * stylesheet.c
3  *
4  * Colloquium - A tiny presentation program
5  *
6  * Copyright (c) 2011 Thomas White <taw@bitwiz.org.uk>
7  *
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 3 of the License, or
11  * (at your option) any later version.
12  *
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.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <stdlib.h>
29 #include <string.h>
30 #include <gtk/gtk.h>
31 #include <assert.h>
32 #include <libconfig.h>
33
34 #include "presentation.h"
35 #include "stylesheet.h"
36 #include "objects.h"
37
38
39 struct _stylesheetwindow
40 {
41         struct presentation *p;  /* Presentation to update when user alters
42                                   * something in this window */
43         GtkWidget           *window;
44         StyleSheet          *ss; /* Style sheet this window corresponds to */
45
46         GtkWidget           *text_font;
47         GtkWidget           *text_colour;
48
49         GtkWidget           *margin_left;
50         GtkWidget           *margin_right;
51         GtkWidget           *margin_top;
52         GtkWidget           *margin_bottom;
53         GtkWidget           *offset_x;
54         GtkWidget           *offset_y;
55         GtkWidget           *halign;
56         GtkWidget           *valign;
57         GtkWidget           *max_width;
58         GtkWidget           *use_max;
59
60         struct style        *cur_style;
61 };
62
63
64 static void text_font_set_sig(GtkFontButton *widget,
65                               struct _stylesheetwindow *s)
66 {
67         const gchar *font;
68
69         font = gtk_font_button_get_font_name(widget);
70         free(s->cur_style->font);
71         s->cur_style->font = strdup(font);
72
73         notify_style_update(s->p, s->cur_style);
74 }
75
76
77 static void text_colour_set_sig(GtkColorButton *widget,
78                               struct _stylesheetwindow *s)
79 {
80         GdkColor col;
81         guint16 al;
82
83         gtk_color_button_get_color(widget, &col);
84         free(s->cur_style->colour);
85         s->cur_style->colour = gdk_color_to_string(&col);
86         al = gtk_color_button_get_alpha(widget);
87         s->cur_style->alpha = (double)al / 65535.0;
88
89         notify_style_update(s->p, s->cur_style);
90 }
91
92
93 static void margin_left_changed_sig(GtkSpinButton *spin,
94                                     struct _stylesheetwindow *s)
95 {
96         s->cur_style->margin_left = gtk_spin_button_get_value(spin);
97         notify_style_update(s->p, s->cur_style);
98 }
99
100
101 static void margin_right_changed_sig(GtkSpinButton *spin,
102                                      struct _stylesheetwindow *s)
103 {
104         s->cur_style->margin_right = gtk_spin_button_get_value(spin);
105         notify_style_update(s->p, s->cur_style);
106 }
107
108
109 static void margin_top_changed_sig(GtkSpinButton *spin,
110                                    struct _stylesheetwindow *s)
111 {
112         s->cur_style->margin_top = gtk_spin_button_get_value(spin);
113         notify_style_update(s->p, s->cur_style);
114 }
115
116
117 static void margin_bottom_changed_sig(GtkSpinButton *spin,
118                                       struct _stylesheetwindow *s)
119 {
120         s->cur_style->margin_bottom = gtk_spin_button_get_value(spin);
121         notify_style_update(s->p, s->cur_style);
122 }
123
124
125 static void offset_x_changed_sig(GtkSpinButton *spin,
126                                  struct _stylesheetwindow *s)
127 {
128         s->cur_style->offset_x = gtk_spin_button_get_value(spin);
129         notify_style_update(s->p, s->cur_style);
130 }
131
132
133 static void offset_y_changed_sig(GtkSpinButton *spin,
134                                  struct _stylesheetwindow *s)
135 {
136         s->cur_style->offset_y = gtk_spin_button_get_value(spin);
137         notify_style_update(s->p, s->cur_style);
138 }
139
140
141 static void halign_changed_sig(GtkComboBox *combo,
142                                  struct _stylesheetwindow *s)
143 {
144         s->cur_style->halign = gtk_combo_box_get_active(combo);
145         notify_style_update(s->p, s->cur_style);
146 }
147
148
149 static void valign_changed_sig(GtkComboBox *combo,
150                                  struct _stylesheetwindow *s)
151 {
152         s->cur_style->valign = gtk_combo_box_get_active(combo);
153         notify_style_update(s->p, s->cur_style);
154 }
155
156
157 static void max_changed_sig(GtkSpinButton *spin,
158                             struct _stylesheetwindow *s)
159 {
160         s->cur_style->max_width = gtk_spin_button_get_value(spin);
161         notify_style_update(s->p, s->cur_style);
162 }
163
164
165 static void use_max_toggled_sig(GtkToggleButton *combo,
166                                  struct _stylesheetwindow *s)
167 {
168         int v;
169
170         v = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(s->use_max));
171         s->cur_style->use_max_width = v;
172         gtk_widget_set_sensitive(s->max_width,
173                                  s->cur_style->use_max_width);
174         notify_style_update(s->p, s->cur_style);
175 }
176
177
178 static void style_changed_sig(GtkComboBox *combo,
179                                struct _stylesheetwindow *s)
180 {
181         int n;
182         GdkColor col;
183
184         n = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
185         s->cur_style = s->ss->styles[n];
186
187         if ( n == 0 ) {
188                 gtk_widget_set_sensitive(s->offset_x, FALSE);
189                 gtk_widget_set_sensitive(s->offset_y, FALSE);
190                 gtk_widget_set_sensitive(s->use_max, FALSE);
191                 gtk_widget_set_sensitive(s->max_width, FALSE);
192                 gtk_widget_set_sensitive(s->halign, FALSE);
193                 gtk_widget_set_sensitive(s->valign, FALSE);
194         } else {
195                 gtk_widget_set_sensitive(s->offset_x, TRUE);
196                 gtk_widget_set_sensitive(s->offset_y, TRUE);
197                 gtk_widget_set_sensitive(s->use_max, TRUE);
198                 gtk_widget_set_sensitive(s->max_width, TRUE);
199                 gtk_widget_set_sensitive(s->halign, TRUE);
200                 gtk_widget_set_sensitive(s->valign, TRUE);
201         }
202
203         gtk_spin_button_set_value(GTK_SPIN_BUTTON(s->margin_left),
204                                   s->cur_style->margin_left);
205         gtk_spin_button_set_value(GTK_SPIN_BUTTON(s->margin_right),
206                                   s->cur_style->margin_right);
207         gtk_spin_button_set_value(GTK_SPIN_BUTTON(s->margin_bottom),
208                                   s->cur_style->margin_bottom);
209         gtk_spin_button_set_value(GTK_SPIN_BUTTON(s->margin_top),
210                                   s->cur_style->margin_top);
211
212         gtk_spin_button_set_value(GTK_SPIN_BUTTON(s->offset_x),
213                                   s->cur_style->offset_x);
214         gtk_spin_button_set_value(GTK_SPIN_BUTTON(s->offset_y),
215                                   s->cur_style->offset_y);
216
217         gtk_combo_box_set_active(GTK_COMBO_BOX(s->halign),
218                                  s->cur_style->halign);
219         gtk_combo_box_set_active(GTK_COMBO_BOX(s->valign),
220                                  s->cur_style->valign);
221
222         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(s->use_max),
223                                      s->cur_style->use_max_width);
224         gtk_widget_set_sensitive(s->max_width, s->cur_style->use_max_width);
225
226         gtk_spin_button_set_value(GTK_SPIN_BUTTON(s->max_width),
227                                   s->cur_style->max_width);
228
229         n = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
230         s->cur_style = s->ss->styles[n];
231
232         gtk_font_button_set_font_name(GTK_FONT_BUTTON(s->text_font),
233                                       s->cur_style->font);
234
235         gdk_color_parse(s->cur_style->colour, &col);
236         gtk_color_button_set_color(GTK_COLOR_BUTTON(s->text_colour), &col);
237 }
238
239
240 static void do_layout(struct _stylesheetwindow *s, GtkWidget *b)
241 {
242         GtkWidget *table;
243         GtkWidget *line;
244         GtkWidget *label;
245         GtkWidget *combo;
246         GtkWidget *box;
247         GtkWidget *vbox;
248         int i;
249
250         box = gtk_hbox_new(FALSE, 5);
251         gtk_box_pack_start(GTK_BOX(b), box, FALSE, FALSE, 5);
252         label = gtk_label_new("Style:");
253         gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
254         gtk_box_pack_start(GTK_BOX(box), label, FALSE, FALSE, 0);
255         combo = gtk_combo_box_new_text();
256         for ( i=0; i<s->ss->n_styles; i++ ) {
257                 gtk_combo_box_append_text(GTK_COMBO_BOX(combo),
258                                           s->ss->styles[i]->name);
259         }
260         gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
261         g_signal_connect(G_OBJECT(combo), "changed",
262                          G_CALLBACK(style_changed_sig), s);
263         gtk_box_pack_start(GTK_BOX(box), combo, TRUE, TRUE, 0);
264
265         line = gtk_hseparator_new();
266         gtk_box_pack_start(GTK_BOX(b), line, FALSE, FALSE, 5);
267
268         box = gtk_hbox_new(TRUE, 30);
269         gtk_box_pack_start(GTK_BOX(b), box, FALSE, FALSE, 5);
270
271         vbox = gtk_vbox_new(FALSE, 0);
272         gtk_box_pack_start(GTK_BOX(box), vbox, FALSE, FALSE, 0);
273         label = gtk_label_new("Margins:");
274         gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
275         gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 5);
276         table = gtk_table_new(3, 3, TRUE);
277         gtk_table_set_row_spacings(GTK_TABLE(table), 5.0);
278         gtk_table_set_col_spacings(GTK_TABLE(table), 5.0);
279         gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
280
281         /* Left */
282         s->margin_left = gtk_spin_button_new_with_range(0.0, 1024.0, 1.0);
283         gtk_table_attach_defaults(GTK_TABLE(table), s->margin_left,
284                                   0, 1, 1, 2);
285         g_signal_connect(G_OBJECT(s->margin_left), "value-changed",
286                          G_CALLBACK(margin_left_changed_sig), s);
287
288         /* Up */
289         s->margin_top = gtk_spin_button_new_with_range(0.0, 1024.0, 1.0);
290         gtk_table_attach_defaults(GTK_TABLE(table), s->margin_top,
291                                   1, 2, 0, 1);
292         g_signal_connect(G_OBJECT(s->margin_top), "value-changed",
293                          G_CALLBACK(margin_top_changed_sig), s);
294
295         /* Right */
296         s->margin_right = gtk_spin_button_new_with_range(0.0, 1024.0, 1.0);
297         gtk_table_attach_defaults(GTK_TABLE(table), s->margin_right,
298                                   2, 3, 1, 2);
299         g_signal_connect(G_OBJECT(s->margin_right), "value-changed",
300                          G_CALLBACK(margin_right_changed_sig), s);
301
302         /* Down */
303         s->margin_bottom = gtk_spin_button_new_with_range(0.0, 1024.0, 1.0);
304         gtk_table_attach_defaults(GTK_TABLE(table), s->margin_bottom,
305                                   1, 2, 2, 3);
306         g_signal_connect(G_OBJECT(s->margin_bottom), "value-changed",
307                          G_CALLBACK(margin_bottom_changed_sig), s);
308
309         vbox = gtk_vbox_new(FALSE, 0);
310         gtk_box_pack_start(GTK_BOX(box), vbox, FALSE, FALSE, 0);
311         label = gtk_label_new("Offset from centre:");
312         gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
313         gtk_box_pack_start(GTK_BOX(vbox), label, FALSE, FALSE, 5);
314         table = gtk_table_new(2, 2, TRUE);
315         gtk_table_set_row_spacings(GTK_TABLE(table), 5.0);
316         gtk_table_set_col_spacings(GTK_TABLE(table), 5.0);
317         gtk_box_pack_start(GTK_BOX(vbox), table, TRUE, TRUE, 0);
318
319         /* Up */
320         label = gtk_label_new("Upwards:");
321         gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
322         s->offset_y = gtk_spin_button_new_with_range(-s->p->slide_height,
323                                                      +s->p->slide_height, 1.0);
324         gtk_table_attach_defaults(GTK_TABLE(table), s->offset_y, 1, 2, 0, 1);
325         g_signal_connect(G_OBJECT(s->offset_y), "value-changed",
326                          G_CALLBACK(offset_y_changed_sig), s);
327
328         /* Right */
329         label = gtk_label_new("Across:");
330         gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
331         s->offset_x = gtk_spin_button_new_with_range(-s->p->slide_width,
332                                                      +s->p->slide_width, 1.0);
333         gtk_table_attach_defaults(GTK_TABLE(table), s->offset_x, 1, 2, 1, 2);
334         g_signal_connect(G_OBJECT(s->offset_x), "value-changed",
335                          G_CALLBACK(offset_x_changed_sig), s);
336
337         table = gtk_table_new(3, 2, TRUE);
338         gtk_table_set_row_spacings(GTK_TABLE(table), 5.0);
339         gtk_table_set_col_spacings(GTK_TABLE(table), 5.0);
340         gtk_box_pack_start(GTK_BOX(b), table, FALSE, FALSE, 5);
341         label = gtk_label_new("Horizontal alignment:");
342         gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
343         gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 0, 1);
344         s->halign = gtk_combo_box_new_text();
345         gtk_table_attach_defaults(GTK_TABLE(table), s->halign, 1, 2, 0, 1);
346         gtk_combo_box_append_text(GTK_COMBO_BOX(s->halign), "Left");
347         gtk_combo_box_append_text(GTK_COMBO_BOX(s->halign), "Centre");
348         gtk_combo_box_append_text(GTK_COMBO_BOX(s->halign), "Right");
349         g_signal_connect(G_OBJECT(s->halign), "changed",
350                          G_CALLBACK(halign_changed_sig), s);
351
352         label = gtk_label_new("Vertical alignment:");
353         gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
354         gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 1, 2);
355         s->valign = gtk_combo_box_new_text();
356         gtk_table_attach_defaults(GTK_TABLE(table), s->valign, 1, 2, 1, 2);
357         gtk_combo_box_append_text(GTK_COMBO_BOX(s->valign), "Top");
358         gtk_combo_box_append_text(GTK_COMBO_BOX(s->valign), "Centre");
359         gtk_combo_box_append_text(GTK_COMBO_BOX(s->valign), "Bottom");
360         g_signal_connect(G_OBJECT(s->valign), "changed",
361                          G_CALLBACK(valign_changed_sig), s);
362
363         label = gtk_label_new("Maximum width:");
364         gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
365         gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 2, 3);
366         box = gtk_hbox_new(FALSE, 5.0);
367         gtk_table_attach_defaults(GTK_TABLE(table), box, 1, 2, 2, 3);
368         s->use_max = gtk_check_button_new();
369         gtk_box_pack_start(GTK_BOX(box), s->use_max, FALSE, FALSE, 0);
370         s->max_width = gtk_spin_button_new_with_range(0.0, 1024.0, 1.0);
371         gtk_box_pack_start(GTK_BOX(box), s->max_width, FALSE, FALSE, 0);
372         g_signal_connect(G_OBJECT(s->use_max), "toggled",
373                          G_CALLBACK(use_max_toggled_sig), s);
374         g_signal_connect(G_OBJECT(s->max_width), "value-changed",
375                          G_CALLBACK(max_changed_sig), s);
376
377         /* Font/colour stuff */
378         label = gtk_label_new("Font:");
379         gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
380         gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 3, 4);
381         s->text_font = gtk_font_button_new_with_font("Sans 12");
382         box = gtk_hbox_new(FALSE, 0);
383         gtk_table_attach_defaults(GTK_TABLE(table), box, 1, 2, 3, 4);
384         gtk_box_pack_start(GTK_BOX(box), s->text_font, FALSE, FALSE, 0);
385         g_signal_connect(G_OBJECT(s->text_font), "font-set",
386                          G_CALLBACK(text_font_set_sig), s);
387
388         label = gtk_label_new("Colour:");
389         gtk_misc_set_alignment(GTK_MISC(label), 1.0, 0.5);
390         gtk_table_attach_defaults(GTK_TABLE(table), label, 0, 1, 4, 5);
391         s->text_colour = gtk_color_button_new();
392         box = gtk_hbox_new(FALSE, 0);
393         gtk_table_attach_defaults(GTK_TABLE(table), box, 1, 2, 4, 5);
394         gtk_box_pack_start(GTK_BOX(box), s->text_colour, FALSE, FALSE, 0);
395         g_signal_connect(G_OBJECT(s->text_colour), "color-set",
396                          G_CALLBACK(text_colour_set_sig), s);
397
398         /* Force first update */
399         style_changed_sig(GTK_COMBO_BOX(combo), s);
400 }
401
402
403
404 static gint destroy_stylesheet_sig(GtkWidget *w, struct _stylesheetwindow *s)
405 {
406         s->p->stylesheetwindow = NULL;
407         free(s);
408         return FALSE;
409 }
410
411
412 static struct style *new_style(StyleSheet *ss, const char *name)
413 {
414         struct style *sty;
415         int n;
416         struct style **styles_new;
417
418         sty = malloc(sizeof(*sty));
419         if ( sty == NULL ) return NULL;
420
421         sty->name = strdup(name);
422
423         n = ss->n_styles;
424         styles_new = realloc(ss->styles, (n+1)*sizeof(sty));
425         if ( styles_new == NULL ) {
426                 free(sty->name);
427                 free(sty);
428                 return NULL;
429         }
430         ss->styles = styles_new;
431         ss->styles[n] = sty;
432         ss->n_styles = n+1;
433
434         return sty;
435 }
436
437
438 static void default_stylesheet(StyleSheet *ss)
439 {
440         struct style *sty;
441
442         /* Default style must be first */
443         sty = new_style(ss, "Default");
444         sty->font = strdup("Sans 18");
445         sty->colour = strdup("#000000000000");  /* Black */
446         sty->alpha = 1.0;
447         sty->margin_left = 20.0;
448         sty->margin_right = 20.0;
449         sty->margin_top = 20.0;
450         sty->margin_bottom = 20.0;
451         sty->halign = J_CENTER;  /* Ignored */
452         sty->valign = V_CENTER;  /* Ignored */
453         sty->offset_x = 0.0;  /* Ignored */
454         sty->offset_y = 0.0;  /* Ignored */
455
456         sty = new_style(ss, "Slide title");
457         sty->font = strdup("Sans 40");
458         sty->colour = strdup("#000000000000");  /* Black */
459         sty->alpha = 1.0;
460         sty->margin_left = 20.0;
461         sty->margin_right = 20.0;
462         sty->margin_top = 20.0;
463         sty->margin_bottom = 20.0;
464         sty->halign = J_CENTER;
465         sty->valign = V_TOP;
466         sty->offset_x = 0.0;
467         sty->offset_y = 0.0;  /* irrelevant */
468
469         sty = new_style(ss, "Slide credit");
470         sty->font = strdup("Sans 14");
471         sty->colour = strdup("#000000000000");  /* Black */
472         sty->alpha = 1.0;
473         sty->margin_left = 20.0;
474         sty->margin_right = 20.0;
475         sty->margin_top = 20.0;
476         sty->margin_bottom = 35.0;
477         sty->halign = J_RIGHT;
478         sty->valign = V_BOTTOM;
479         sty->offset_x = 0.0;
480         sty->offset_y = 0.0;
481
482         sty = new_style(ss, "Slide date");
483         sty->font = strdup("Sans 12");
484         sty->colour = strdup("#999999999999");  /* Grey */
485         sty->alpha = 1.0;
486         sty->margin_left = 600.0;
487         sty->margin_right = 100.0;
488         sty->margin_top = 745.0;
489         sty->margin_bottom = 5.0;
490         sty->halign = J_RIGHT;
491         sty->valign = V_BOTTOM;
492         sty->offset_x = 0.0;
493         sty->offset_y = 0.0;
494
495         sty = new_style(ss, "Slide number");
496         sty->font = strdup("Sans 12");
497         sty->colour = strdup("#999999999999");  /* Grey */
498         sty->alpha = 1.0;
499         sty->margin_left = 600.0;
500         sty->margin_right = 5.0;
501         sty->margin_top = 745.0;
502         sty->margin_bottom = 5.0;
503         sty->halign = J_RIGHT;
504         sty->valign = V_BOTTOM;
505         sty->offset_x = 0.0;
506         sty->offset_y = 0.0;
507
508         sty = new_style(ss, "Presentation title on slide");
509         sty->font = strdup("Sans 12");
510         sty->colour = strdup("#999999999999");  /* Grey */
511         sty->alpha = 1.0;
512         sty->margin_left = 5.0;
513         sty->margin_right = 600.0;
514         sty->margin_top = 745.0;
515         sty->margin_bottom = 5.0;
516         sty->halign = J_LEFT;
517         sty->valign = V_BOTTOM;
518         sty->offset_x = 0.0;
519         sty->offset_y = 0.0;
520
521         sty = new_style(ss, "Presentation title");
522         sty->font = strdup("Sans 50");
523         sty->colour = strdup("#000000000000");  /* Black */
524         sty->alpha = 1.0;
525         sty->margin_left = 20.0;
526         sty->margin_right = 20.0;
527         sty->margin_top = 20.0;
528         sty->margin_bottom = 20.0;
529         sty->halign = J_CENTER;
530         sty->valign = V_CENTER;
531         sty->offset_x = -200.0;
532         sty->offset_y = +300.0;
533
534         sty = new_style(ss, "Presentation author");
535         sty->font = strdup("Sans 30");
536         sty->colour = strdup("#000000000000");  /* Black */
537         sty->alpha = 1.0;
538         sty->margin_left = 20.0;
539         sty->margin_right = 20.0;
540         sty->margin_top = 20.0;
541         sty->margin_bottom = 20.0;
542         sty->halign = J_CENTER;
543         sty->valign = V_CENTER;
544         sty->offset_x = +200.0;
545         sty->offset_y = -300.0;
546
547         sty = new_style(ss, "Presentation date");
548         sty->font = strdup("Sans 30");
549         sty->colour = strdup("#000000000000");  /* Black */
550         sty->alpha = 1.0;
551         sty->margin_left = 20.0;
552         sty->margin_right = 20.0;
553         sty->margin_top = 20.0;
554         sty->margin_bottom = 20.0;
555         sty->halign = J_CENTER;
556         sty->valign = V_CENTER;
557         sty->offset_x = +200.0;
558         sty->offset_y = -300.0;
559 }
560
561
562 StyleSheet *new_stylesheet()
563 {
564         StyleSheet *ss;
565
566         ss = calloc(1, sizeof(struct _stylesheet));
567         if ( ss == NULL ) return NULL;
568
569         ss->n_styles = 0;
570         ss->styles = NULL;
571         default_stylesheet(ss);
572
573         return ss;
574 }
575
576
577 void save_stylesheet(StyleSheet *ss, const char *filename)
578 {
579         config_t config;
580
581         config_init(&config);
582
583         if ( config_write_file(&config, filename) == CONFIG_FALSE ) {
584                 printf("Couldn't save style sheet to '%s'\n", filename);
585         }
586         config_destroy(&config);
587 }
588
589
590 StyleSheet *load_stylesheet(const char *filename)
591 {
592         StyleSheet *ss;
593         config_t config;
594
595         ss = new_stylesheet();
596         if ( ss == NULL ) return NULL;
597
598         config_init(&config);
599         if ( config_read_file(&config, filename) != CONFIG_TRUE ) {
600                 printf("Style sheet parse error: %s at line %i.\n",
601                         config_error_text(&config),
602                         config_error_line(&config));
603                 config_destroy(&config);
604                 default_stylesheet(ss);
605                 return ss;
606         }
607
608
609
610         config_destroy(&config);
611
612         return ss;
613 }
614
615
616 StylesheetWindow *open_stylesheet(struct presentation *p)
617 {
618         struct _stylesheetwindow *s;
619         GtkWidget *nb;
620         GtkWidget *text_box;
621         GtkWidget *background_box;
622
623         s = malloc(sizeof(*s));
624         if ( s == NULL ) return NULL;
625
626         s->p = p;
627         s->ss = p->ss;
628         s->cur_style = NULL;
629         s->cur_style = NULL;
630
631         s->window = gtk_dialog_new_with_buttons("Stylesheet",
632                                            GTK_WINDOW(p->window), 0,
633                                            GTK_STOCK_CLOSE, GTK_RESPONSE_ACCEPT,
634                                            NULL);
635         gtk_dialog_set_has_separator(GTK_DIALOG(s->window), FALSE);
636
637         nb = gtk_notebook_new();
638         gtk_notebook_set_tab_pos(GTK_NOTEBOOK(nb), GTK_POS_TOP);
639         gtk_box_pack_start(GTK_BOX(GTK_DIALOG(s->window)->vbox), nb,
640                            TRUE, TRUE, 0);
641
642         text_box = gtk_vbox_new(FALSE, 0);
643         gtk_container_set_border_width(GTK_CONTAINER(text_box), 12);
644         gtk_notebook_append_page(GTK_NOTEBOOK(nb), text_box,
645                                  gtk_label_new("Styles"));
646         do_layout(s, text_box);
647
648         background_box = gtk_vbox_new(FALSE, 0);
649         gtk_container_set_border_width(GTK_CONTAINER(background_box), 12);
650         gtk_notebook_append_page(GTK_NOTEBOOK(nb), background_box,
651                                  gtk_label_new("Background"));
652
653         g_signal_connect(G_OBJECT(s->window), "destroy",
654                          G_CALLBACK(destroy_stylesheet_sig), s);
655         g_signal_connect(G_OBJECT(s->window), "response",
656                          G_CALLBACK(gtk_widget_destroy), NULL);
657
658         gtk_widget_show_all(s->window);
659
660         return s;
661 }
662
663
664 struct style *find_style(StyleSheet *ss, const char *name)
665 {
666         int i;
667         for ( i=0; i<ss->n_styles; i++ ) {
668                 if ( strcmp(ss->styles[i]->name, name) == 0 ) {
669                         return ss->styles[i];
670                 }
671         }
672
673         return NULL;
674 }