6d773217eb437bc085e292e22093c5aaf9fdd69b
[hildon] / src / hildon-font-selection-dialog.c
1 /*
2  * This file is a part of hildon
3  *
4  * Copyright (C) 2005, 2006 Nokia Corporation, all rights reserved.
5  *
6  * Contact: Michael Dominic Kostrzewa <michael.kostrzewa@nokia.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation; version 2.1 of
11  * the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  *
23  */
24
25 /**
26  * SECTION:hildon-font-selection-dialog
27  * @short_description: A widget used to allow users to select a font 
28  * with certain properties.
29  *
30  * Font selection can be made using this widget. Users can select font name, 
31  * size, style, etc. Users can also preview text in the selected font.
32  */
33
34 #undef                                          HILDON_DISABLE_DEPRECATED
35
36 #ifdef                                          HAVE_CONFIG_H
37 #include                                        <config.h>
38 #endif
39
40 #include                                        <libintl.h>
41 #include                                        <stdlib.h>
42 #include                                        <string.h>
43
44 #include                                        <glib.h>
45 #include                                        <gdk/gdkkeysyms.h>
46
47 #include                                        "hildon-font-selection-dialog.h"
48 #include                                        "hildon-caption.h"
49 #include                                        "hildon-color-button.h"
50 #include                                        "hildon-font-selection-dialog-private.h"
51
52 /* These are what we use as the standard font sizes, for the size list */
53
54 static const guint16                            font_sizes[] = 
55 {
56   6, 8, 10, 12, 16, 24, 32
57 };
58
59 enum
60 {
61     PROP_0,
62     PROP_FAMILY,
63     PROP_FAMILY_SET,
64     PROP_SIZE,
65     PROP_SIZE_SET,
66     PROP_COLOR,
67     PROP_COLOR_SET,
68     PROP_BOLD,
69     PROP_BOLD_SET,
70     PROP_ITALIC,
71     PROP_ITALIC_SET,
72     PROP_UNDERLINE,
73     PROP_UNDERLINE_SET,
74     PROP_STRIKETHROUGH,
75     PROP_STRIKETHROUGH_SET,
76     PROP_POSITION,
77     PROP_POSITION_SET,
78     PROP_PREVIEW_TEXT,
79     PROP_FONT_SCALING
80 };
81
82 /* combo box active row indicator -2--inconsistent, -1--undefined 
83  * please make sure that you use settings_init settings_apply
84  * and settings_destroy, dont even try to touch this structure 
85  * without using the three above interface functions, of course
86  * if you know what you are doing, do as you please ;-)*/
87 typedef struct
88 {
89     HildonFontSelectionDialog *fsd;             /* pointer to our font selection dialog */
90
91     gint family;                                /* combo box indicator */
92     gint size;                                  /* combo box indicator */
93     GdkColor *color;                            /* free after read the setting */
94     gboolean color_inconsist;
95     gint weight;                                /* bit mask */
96     gint style;                                 /* bit mask */
97     gint underline;                             /* bit mask */
98     gint strikethrough;                         /* bit mask */
99     gint position;                              /* combo box indicator */
100
101 }                                               HildonFontSelectionDialogSettings;
102
103 static gboolean
104 hildon_font_selection_dialog_preview_key_press  (GtkWidget *widget,
105                                                  GdkEventKey *event,
106                                                  gpointer unused);
107
108 static int
109 cmp_families                                    (const void *a, 
110                                                  const void *b);
111
112 static void   
113 hildon_font_selection_dialog_show_preview       (HildonFontSelectionDialog *fontsel);
114
115 static PangoAttrList*
116 hildon_font_selection_dialog_create_attrlist    (HildonFontSelectionDialog *fontsel, 
117                                                  guint start_index,
118                                                  guint len);
119
120 static void   
121 hildon_font_selection_dialog_show_available_positionings (HildonFontSelectionDialogPrivate *priv);
122
123 static void   
124 hildon_font_selection_dialog_show_available_fonts (HildonFontSelectionDialog *fontsel);
125
126 static void   
127 hildon_font_selection_dialog_show_available_sizes (HildonFontSelectionDialogPrivate *priv);
128
129 static void   
130 hildon_font_selection_dialog_class_init         (HildonFontSelectionDialogClass *klass);
131
132 static void   
133 hildon_font_selection_dialog_init               (HildonFontSelectionDialog *fontseldiag);
134
135 static void   
136 hildon_font_selection_dialog_finalize           (GObject *object);
137
138 static void   
139 hildon_font_selection_dialog_construct_notebook (HildonFontSelectionDialog *fontsel);
140
141 static void   
142 color_modified_cb                               (HildonColorButton *button,
143                                                  GParamSpec *pspec,
144                                                  gpointer fsd_priv);
145
146 static void   
147 add_preview_text_attr                           (PangoAttrList *list, 
148                                                  PangoAttribute *attr, 
149                                                  guint start, 
150                                                  guint len);
151
152 static void   
153 toggle_clicked                                  (GtkButton *button, 
154                                                  gpointer unused);
155
156 static GtkDialogClass*                          parent_class = NULL;
157
158 #define                                         _(String) dgettext("hildon-libs", String)
159
160 #define                                         SUPERSCRIPT_RISE 3333
161
162 #define                                         SUBSCRIPT_LOW -3333
163
164 #define                                         ON_BIT  0x01
165
166 #define                                         OFF_BIT 0x02
167
168 /**
169  * hildon_font_selection_dialog_get_type:
170  *
171  * Initializes and returns the type of a hildon font selection dialog
172  *
173  * @Returns: GType of #HildonFontSelectionDialog
174  */
175 GType G_GNUC_CONST
176 hildon_font_selection_dialog_get_type           (void)
177 {
178     static GType font_selection_dialog_type = 0;
179
180     if (! font_selection_dialog_type) {
181         static const GTypeInfo fontsel_diag_info = {
182             sizeof(HildonFontSelectionDialogClass),
183             NULL,       /* base_init */
184             NULL,       /* base_finalize */
185             (GClassInitFunc) hildon_font_selection_dialog_class_init,
186             NULL,       /* class_finalize */
187             NULL,       /* class_data */
188             sizeof(HildonFontSelectionDialog),
189             0,  /* n_preallocs */
190             (GInstanceInitFunc) hildon_font_selection_dialog_init,
191         };
192
193         font_selection_dialog_type =
194             g_type_register_static (GTK_TYPE_DIALOG,
195                     "HildonFontSelectionDialog",
196                     &fontsel_diag_info, 0);
197     }
198
199     return font_selection_dialog_type;
200 }
201
202 static void
203 hildon_font_selection_dialog_get_property       (GObject *object,
204                                                  guint prop_id,
205                                                  GValue *value,
206                                                  GParamSpec *pspec)
207 {
208     gint i;
209     GdkColor color;
210
211     HildonFontSelectionDialogPrivate *priv =
212         HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE(object);
213
214     g_assert (priv);
215
216     switch (prop_id)
217     {
218         case PROP_FAMILY:
219             i = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->cbx_font_type));
220             if(i >= 0 && i < priv->n_families)
221                 g_value_set_string(value, 
222                         pango_font_family_get_name (priv->families[i]));
223             else
224                 g_value_set_string (value, "Sans");
225                 /* FIXME Bad hardcoding here */
226             break;
227
228         case PROP_FAMILY_SET:
229             i = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->cbx_font_type));
230             if(i >= 0 && i < priv->n_families)
231                 g_value_set_boolean (value, TRUE);
232             else
233                 g_value_set_boolean (value, FALSE);
234             break;
235
236         case PROP_SIZE:
237             i = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->cbx_font_size));
238             if(i >= 0 && i < G_N_ELEMENTS (font_sizes))
239                 g_value_set_int (value, font_sizes[i]);
240             else
241                 g_value_set_int (value, 16);
242             break;
243
244         case PROP_SIZE_SET:
245             i = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->cbx_font_size));
246             if(i >= 0 && i < G_N_ELEMENTS (font_sizes))
247                 g_value_set_boolean (value, TRUE);
248             else
249                 g_value_set_boolean (value, FALSE);
250             break;
251
252         case PROP_COLOR:
253             hildon_color_button_get_color
254                 (HILDON_COLOR_BUTTON (priv->font_color_button), &color);
255             g_value_set_boxed (value, (gconstpointer) &color);
256             break;
257
258         case PROP_COLOR_SET:
259             g_value_set_boolean (value, priv->color_set);
260             break;
261
262         case PROP_BOLD:
263             g_value_set_boolean (value, 
264                     gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (priv->chk_bold)));
265             break;
266
267         case PROP_BOLD_SET:
268             g_value_set_boolean (value,
269                     ! gtk_toggle_button_get_inconsistent
270                     (GTK_TOGGLE_BUTTON (priv->chk_bold)));
271             break;
272
273         case PROP_ITALIC:
274             g_value_set_boolean (value, 
275                     gtk_toggle_button_get_active
276                     (GTK_TOGGLE_BUTTON (priv->chk_italic)));
277             break;
278
279         case PROP_ITALIC_SET:
280             g_value_set_boolean (value,
281                     ! gtk_toggle_button_get_inconsistent
282                     (GTK_TOGGLE_BUTTON (priv->chk_italic)));
283             break;
284
285         case PROP_UNDERLINE:
286             g_value_set_boolean (value, 
287                     gtk_toggle_button_get_active
288                     (GTK_TOGGLE_BUTTON (priv->chk_underline)));
289             break;
290
291         case PROP_UNDERLINE_SET:
292             g_value_set_boolean (value,
293                     ! gtk_toggle_button_get_inconsistent
294                     (GTK_TOGGLE_BUTTON (priv->chk_underline)));
295             break;
296
297         case PROP_STRIKETHROUGH:
298             g_value_set_boolean(value, 
299                     gtk_toggle_button_get_active
300                     (GTK_TOGGLE_BUTTON (priv->chk_strikethrough)));
301             break;
302
303         case PROP_STRIKETHROUGH_SET:
304             g_value_set_boolean(value,
305                     ! gtk_toggle_button_get_inconsistent
306                     (GTK_TOGGLE_BUTTON (priv->chk_strikethrough)));
307             break;
308
309         case PROP_POSITION:
310             i = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->cbx_positioning));
311             if(i == 1) /* super */
312                 g_value_set_int (value, 1);
313             else if(i == 2)/* sub */
314                 g_value_set_int (value, -1);
315             else
316                 g_value_set_int (value, 0);
317             break;
318
319         case PROP_FONT_SCALING:
320             g_value_set_double (value, priv->font_scaling);
321             break;
322
323         case PROP_POSITION_SET:
324             i = gtk_combo_box_get_active (GTK_COMBO_BOX (priv->cbx_positioning));
325             if(i >= 0 && i < 3)
326                 g_value_set_boolean (value, TRUE);
327             else
328                 g_value_set_boolean (value, FALSE);
329             break;
330
331         case PROP_PREVIEW_TEXT:
332             g_value_set_string (value,
333                     hildon_font_selection_dialog_get_preview_text (HILDON_FONT_SELECTION_DIALOG (object)));
334             break;
335
336         default:
337             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
338             break;
339     }
340 }
341
342 static void 
343 hildon_font_selection_dialog_set_property       (GObject *object,
344                                                  guint prop_id,
345                                                  const GValue *value,
346                                                  GParamSpec *pspec)
347 {
348     gint i, size;
349     const gchar *str;
350     gboolean b;
351     GdkColor *color = NULL;
352     GdkColor black;
353
354     HildonFontSelectionDialogPrivate *priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (object);
355     g_assert (priv);
356
357     black.red = black.green = black.blue = 0;
358
359     switch (prop_id)
360     {
361         case PROP_FAMILY:
362             str = g_value_get_string (value);
363             for(i = 0; i < priv->n_families; i++)
364             {
365                 if (strcmp (str, pango_font_family_get_name (priv->families[i]))
366                         == 0)
367                 {
368                     gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cbx_font_type), i);
369                     break;
370                 }
371             }
372             break;
373
374         case PROP_FAMILY_SET:
375             b = g_value_get_boolean (value);
376             if(!b)
377                 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cbx_font_type), -1);
378             break;
379
380         case PROP_SIZE:
381             size = g_value_get_int (value);
382             for(i = 0; i < G_N_ELEMENTS (font_sizes); i++)
383             {
384                 if(size == font_sizes[i])
385                 {
386                     gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cbx_font_size), i);
387                     break;
388                 }
389             }
390             break;
391
392         case PROP_SIZE_SET:
393             b = g_value_get_boolean (value);
394             if(!b)
395                 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cbx_font_size), -1);
396             break;
397
398         case PROP_COLOR:
399             color = (GdkColor *) g_value_get_boxed (value);
400             if(color != NULL)
401                 hildon_color_button_set_color (HILDON_COLOR_BUTTON
402                         (priv->font_color_button),
403                         color);
404             else
405                 hildon_color_button_set_color (HILDON_COLOR_BUTTON
406                         (priv->font_color_button),
407                         &black);
408             break;
409
410         case PROP_COLOR_SET:
411             priv->color_set = g_value_get_boolean (value);
412             if(! priv->color_set)
413             {
414                 /* set color to black, but block our signal handler */
415                 g_signal_handler_block ((gpointer) priv->font_color_button,
416                         priv->color_modified_signal_handler);
417
418                 hildon_color_button_set_color (HILDON_COLOR_BUTTON
419                         (priv->font_color_button), 
420                         &black);
421
422                 g_signal_handler_unblock ((gpointer) priv->font_color_button,
423                         priv->color_modified_signal_handler);
424             }
425             break;
426
427         case PROP_BOLD:
428             /* this call will make sure that we dont get extra clicked signal */
429             gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON(priv->chk_bold), FALSE);
430             gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(priv->chk_bold), g_value_get_boolean (value));
431             break;
432
433         case PROP_BOLD_SET:
434             gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (priv->chk_bold),! g_value_get_boolean(value));
435             break;
436
437         case PROP_ITALIC:
438             gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(priv->chk_italic),
439                     FALSE);
440             gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->chk_italic),
441                     g_value_get_boolean(value));
442             break;
443
444         case PROP_ITALIC_SET:
445             gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(priv->chk_italic),
446                     !g_value_get_boolean(value));
447             break;
448
449         case PROP_UNDERLINE:
450             gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON
451                     (priv->chk_underline),
452                     FALSE);
453             gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->chk_underline),
454                     g_value_get_boolean(value));
455             break;
456
457         case PROP_UNDERLINE_SET:
458             gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(priv->chk_underline),
459                     !g_value_get_boolean(value));
460             break;
461
462         case PROP_STRIKETHROUGH:
463             gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON
464                     (priv->chk_strikethrough),
465                     FALSE);
466             gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->chk_strikethrough),
467                     g_value_get_boolean(value));
468             break;
469
470         case PROP_STRIKETHROUGH_SET:
471             gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON
472                     (priv->chk_strikethrough),
473                     !g_value_get_boolean(value));
474             break;
475
476         case PROP_POSITION:
477             i = g_value_get_int(value);
478             if( i == 1 )
479                 gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_positioning), 1);
480             else if(i == -1)
481                 gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_positioning), 2);
482             else
483                 gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_positioning), 0);
484             break;
485
486         case PROP_FONT_SCALING:
487             priv->font_scaling = g_value_get_double(value);
488             break;
489
490         case PROP_POSITION_SET:
491             b = g_value_get_boolean(value);
492             if(!b)
493                 gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_positioning), -1);
494             break;
495
496         case PROP_PREVIEW_TEXT:
497             hildon_font_selection_dialog_set_preview_text(
498                     HILDON_FONT_SELECTION_DIALOG(object),
499                     g_value_get_string(value));
500             break;
501
502         default:
503             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
504             break;
505     }
506 }
507
508 static void
509 hildon_font_selection_dialog_class_init         (HildonFontSelectionDialogClass *klass)
510 {
511     GObjectClass *gobject_class;
512
513     parent_class = g_type_class_peek_parent (klass);
514     gobject_class = G_OBJECT_CLASS (klass);
515
516     gobject_class->finalize         = hildon_font_selection_dialog_finalize;
517     gobject_class->get_property     = hildon_font_selection_dialog_get_property;
518     gobject_class->set_property     = hildon_font_selection_dialog_set_property;
519
520     /* Install properties to the class */
521
522     /**
523      * HildonFontSelectionDialog:family:
524      *
525      * Font family used.
526      */
527     g_object_class_install_property (gobject_class, PROP_FAMILY,
528             g_param_spec_string ("family",
529                 "Font family", "String defines"
530                 " the font family", "Sans",
531                 G_PARAM_READWRITE));
532
533     /**
534      * HildonFontSelectionDialog:family-set:
535      *
536      * Is font family set or inconsistent.
537      */
538     g_object_class_install_property (gobject_class, PROP_FAMILY_SET,
539             g_param_spec_boolean ("family-set",
540                 "family inconsistent state",
541                 "Whether the family property"
542                 " is inconsistent", FALSE,
543                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
544
545     /**
546      * HildonFontSelectionDialog:size:
547      *
548      * Font size.
549      */
550     g_object_class_install_property (gobject_class, PROP_SIZE,
551             g_param_spec_int ("size",
552                 "Font size",
553                 "Font size in Pt",
554                 6, 32, 16,
555                 G_PARAM_READWRITE));
556
557     /**
558      * HildonFontSelectionDialog:size-set:
559      *
560      * Is font size set or inconsistent.
561      */
562     g_object_class_install_property (gobject_class, PROP_SIZE_SET,
563             g_param_spec_boolean ("size-set",
564                 "size inconsistent state",
565                 "Whether the size property"
566                 " is inconsistent", FALSE,
567                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
568
569     /**
570      * HildonFontSelectionDialog:color:
571      *
572      * GdkColor for the text.
573      */
574     g_object_class_install_property (gobject_class, PROP_COLOR,
575             g_param_spec_boxed ("color",
576                 "text color",
577                 "gdk color for the text",
578                 GDK_TYPE_COLOR,
579                 G_PARAM_READWRITE));
580
581     /**
582      * HildonFontSelectionDialog:color-set:
583      *
584      * Is font color set or inconsistent.
585      */
586     g_object_class_install_property (gobject_class, PROP_COLOR_SET,
587             g_param_spec_boolean ("color-set",
588                 "color inconsistent state",
589                 "Whether the color property"
590                 " is inconsistent", FALSE,
591                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
592
593     /**
594      * HildonFontSelectionDialog:color-set:
595      *
596      * Is font set as bold.
597      */
598     g_object_class_install_property (gobject_class, PROP_BOLD,
599             g_param_spec_boolean ("bold",
600                 "text weight",
601                 "Whether the text is bold",
602                 FALSE,
603                 G_PARAM_READWRITE));
604
605     /**
606      * HildonFontSelectionDialog:color-set:
607      *
608      * Is font bold status set or inconsistent.
609      */
610     g_object_class_install_property (gobject_class, PROP_BOLD_SET,
611             g_param_spec_boolean ("bold-set",
612                 "bold inconsistent state",
613                 "Whether the bold"
614                 " is inconsistent", FALSE,
615                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
616
617     /**
618      * HildonFontSelectionDialog:italic:
619      *
620      * Is font set as italic.
621      */
622     g_object_class_install_property (gobject_class, PROP_ITALIC,
623             g_param_spec_boolean ("italic",
624                 "text style",
625                 "Whether the text is italic",
626                 FALSE,
627                 G_PARAM_READWRITE));
628
629     /**
630      * HildonFontSelectionDialog:italic-set:
631      *
632      * Is font italic status set or inconsistent.
633      */
634     g_object_class_install_property (gobject_class, PROP_ITALIC_SET,
635             g_param_spec_boolean ("italic-set",
636                 "italic inconsistent state",
637                 "Whether the italic"
638                 " is inconsistent", FALSE,
639                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
640
641     /**
642      * HildonFontSelectionDialog:underline:
643      *
644      * Is the font underlined.
645      */
646     g_object_class_install_property (gobject_class, PROP_UNDERLINE,
647             g_param_spec_boolean ("underline",
648                 "text underline",
649                 "Whether the text is underlined",
650                 FALSE,
651                 G_PARAM_READWRITE));
652
653     /**
654      * HildonFontSelectionDialog:underline:
655      *
656      * Is font underline status set or inconsistent.
657      */
658     g_object_class_install_property (gobject_class, PROP_UNDERLINE_SET,
659             g_param_spec_boolean ("underline-set",
660                 "underline inconsistent state",
661                 "Whether the underline"
662                 " is inconsistent", FALSE,
663                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
664
665     /**
666      * HildonFontSelectionDialog:strikethrough:
667      *
668      * Is the font striken-through.
669      */
670     g_object_class_install_property (gobject_class, PROP_STRIKETHROUGH,
671             g_param_spec_boolean ("strikethrough",
672                 "strikethroughed text",
673                 "Whether the text is strikethroughed",
674                 FALSE,
675                 G_PARAM_READWRITE));
676
677     /**
678      * HildonFontSelectionDialog:strikethrough-set:
679      *
680      * Is the font strikenthrough status set.
681      */
682     g_object_class_install_property (gobject_class, PROP_STRIKETHROUGH_SET,
683             g_param_spec_boolean ("strikethrough-set",
684                 "strikethrough inconsistent state",
685                 "Whether the strikethrough"
686                 " is inconsistent", FALSE,
687                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
688
689     /**
690      * HildonFontSelectionDialog:position:
691      *
692      * The font positioning versus baseline.
693      */
694     g_object_class_install_property (gobject_class, PROP_POSITION,
695             g_param_spec_int ("position",
696                 "Font position",
697                 "Font position super or subscript",
698                 -1, 1, 0,
699                 G_PARAM_READWRITE));
700
701     /**
702      * HildonFontSelectionDialog:position-set:
703      *
704      * Is the font positioning set.
705      */
706     g_object_class_install_property (gobject_class, PROP_POSITION_SET,
707             g_param_spec_boolean ("position-set",
708                 "position inconsistent state",
709                 "Whether the position"
710                 " is inconsistent", FALSE,
711                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
712
713     /**
714      * HildonFontSelectionDialog:font-scaling:
715      *
716      * The font scaling factor applied to the preview dialog.
717      */
718     g_object_class_install_property (gobject_class, PROP_FONT_SCALING,
719             g_param_spec_double ("font-scaling",
720                 "Font scaling",
721                 "Font scaling for the preview dialog",
722                 0, 10, 1,
723                 G_PARAM_READWRITE));
724
725     /**
726      * HildonFontSelectionDialog:preview-text:
727      *
728      * The text used for the preview dialog.
729      */
730     g_object_class_install_property (gobject_class, PROP_PREVIEW_TEXT,
731             g_param_spec_string("preview-text",
732                 "Preview Text", 
733                 "the text in preview dialog, which does" 
734                 "not include the reference text",
735                 "",
736                 G_PARAM_READWRITE));
737
738     g_type_class_add_private (klass, 
739             sizeof (struct _HildonFontSelectionDialogPrivate));
740 }
741
742 static void 
743 hildon_font_selection_dialog_init               (HildonFontSelectionDialog *fontseldiag)
744 {
745     HildonFontSelectionDialogPrivate *priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fontseldiag);
746     GtkWidget *preview_button;
747
748     g_assert (priv);
749     priv->notebook = GTK_NOTEBOOK (gtk_notebook_new ());
750
751     hildon_font_selection_dialog_construct_notebook (fontseldiag);
752
753     gtk_box_pack_start (GTK_BOX (GTK_DIALOG (fontseldiag)->vbox),
754             GTK_WIDGET (priv->notebook), TRUE, TRUE, 0);
755
756     /* Add dialog buttons */
757     gtk_dialog_add_button (GTK_DIALOG (fontseldiag),
758             _("ecdg_bd_font_dialog_ok"),
759             GTK_RESPONSE_OK);
760
761     preview_button = gtk_button_new_with_label (_("ecdg_bd_font_dialog_preview"));
762     gtk_box_pack_start (GTK_BOX(GTK_DIALOG (fontseldiag)->action_area), 
763             preview_button, FALSE, TRUE, 0);
764
765     g_signal_connect_swapped (preview_button, "clicked",
766             G_CALLBACK
767             (hildon_font_selection_dialog_show_preview),
768             fontseldiag);
769     gtk_widget_show(preview_button);
770
771     /*Set default preview text*/
772     priv->preview_text = g_strdup (_("ecdg_fi_preview_font_preview_text"));
773
774     gtk_window_set_title (GTK_WINDOW (fontseldiag), _("ecdg_ti_font"));
775     /*here is the line to make sure that notebook has the default focus*/
776     gtk_container_set_focus_child (GTK_CONTAINER (GTK_DIALOG (fontseldiag)->vbox),
777             GTK_WIDGET (priv->notebook));
778 }
779
780 static void 
781 hildon_font_selection_dialog_construct_notebook (HildonFontSelectionDialog *fontsel)
782 {
783     gint i;
784     GtkWidget *vbox_tab[3];
785     GtkWidget *font_color_box;
786     GtkWidget *caption_control;
787     GtkSizeGroup *group;
788
789     HildonFontSelectionDialogPrivate *priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fontsel);
790     g_assert (priv);
791
792     for (i = 0; i < 3; i++)
793         vbox_tab[i] = gtk_vbox_new (TRUE, 0);
794
795     group = GTK_SIZE_GROUP (gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL));
796
797     /* Build the first page of the GtkNotebook: font style */
798     priv->cbx_font_type = gtk_combo_box_new_text ();
799     hildon_font_selection_dialog_show_available_fonts (fontsel);
800     caption_control = hildon_caption_new (group,
801             _("ecdg_fi_font_font"),
802             priv->cbx_font_type,
803             NULL,
804             HILDON_CAPTION_OPTIONAL);
805
806     gtk_box_pack_start (GTK_BOX (vbox_tab[0]), caption_control, FALSE, FALSE, 0);
807
808     priv->cbx_font_size = gtk_combo_box_new_text ();
809     hildon_font_selection_dialog_show_available_sizes (priv);
810     caption_control = hildon_caption_new (group,
811             _("ecdg_fi_font_size"),
812             priv->cbx_font_size,
813             NULL,
814             HILDON_CAPTION_OPTIONAL);
815
816     gtk_box_pack_start (GTK_BOX (vbox_tab[0]), caption_control, FALSE, FALSE, 0);
817
818     font_color_box = gtk_hbox_new (FALSE, 0);
819     priv->font_color_button = hildon_color_button_new ();
820     priv->color_set = FALSE;
821     priv->font_scaling = 1.0;
822     priv->color_modified_signal_handler = 
823         g_signal_connect (G_OBJECT (priv->font_color_button), "notify::color",
824                 G_CALLBACK (color_modified_cb), (gpointer) priv);
825
826     gtk_box_pack_start (GTK_BOX (font_color_box), priv->font_color_button, FALSE, FALSE, 0);
827
828     caption_control =
829         hildon_caption_new (group, _("ecdg_fi_font_colour_selector"),
830                 font_color_box,
831                 NULL, HILDON_CAPTION_OPTIONAL);
832
833     gtk_box_pack_start (GTK_BOX (vbox_tab[0]), caption_control, FALSE, FALSE, 0);
834
835     /* Build the second page of the GtkNotebook: font formatting */ 
836     priv->chk_bold = gtk_check_button_new ();
837     caption_control = hildon_caption_new (group,
838             _("ecdg_fi_font_bold"),
839             priv->chk_bold,
840             NULL,
841             HILDON_CAPTION_OPTIONAL);
842
843     gtk_box_pack_start (GTK_BOX (vbox_tab[1]), caption_control, FALSE, FALSE, 0);
844     g_signal_connect (G_OBJECT (priv->chk_bold), "clicked", 
845             G_CALLBACK(toggle_clicked), NULL);
846
847     priv->chk_italic = gtk_check_button_new ();
848     caption_control = hildon_caption_new (group, _("ecdg_fi_font_italic"),
849                 priv->chk_italic,
850                 NULL, HILDON_CAPTION_OPTIONAL);
851
852     gtk_box_pack_start (GTK_BOX (vbox_tab[1]), caption_control, FALSE, FALSE, 0);
853     g_signal_connect(G_OBJECT(priv->chk_italic), "clicked", 
854             G_CALLBACK(toggle_clicked), NULL);
855
856     priv->chk_underline = gtk_check_button_new();
857     caption_control =
858         hildon_caption_new (group, _("ecdg_fi_font_underline"),
859                 priv->chk_underline, NULL,
860                 HILDON_CAPTION_OPTIONAL);
861
862     gtk_box_pack_start (GTK_BOX (vbox_tab[1]), caption_control, FALSE, FALSE, 0);
863     g_signal_connect (G_OBJECT(priv->chk_underline), "clicked", 
864             G_CALLBACK (toggle_clicked), NULL);
865
866     /* Build the third page of the GtkNotebook: other font properties */
867     priv->chk_strikethrough = gtk_check_button_new ();
868     caption_control = hildon_caption_new(group, _("ecdg_fi_font_strikethrough"),
869                 priv->chk_strikethrough, NULL,
870                 HILDON_CAPTION_OPTIONAL);
871
872     gtk_box_pack_start (GTK_BOX (vbox_tab[2]), caption_control, FALSE, FALSE, 0);
873     g_signal_connect (G_OBJECT(priv->chk_strikethrough), "clicked", 
874             G_CALLBACK (toggle_clicked), NULL);
875
876     priv->cbx_positioning = gtk_combo_box_new_text ();
877     hildon_font_selection_dialog_show_available_positionings (priv);
878     caption_control =
879         hildon_caption_new(group, _("ecdg_fi_font_special"),
880                 priv->cbx_positioning, NULL,
881                 HILDON_CAPTION_OPTIONAL);
882
883     g_object_unref (group);
884
885     gtk_box_pack_start (GTK_BOX (vbox_tab[2]), caption_control, FALSE, FALSE, 0);
886
887     /* Populate notebook */
888     gtk_notebook_insert_page (priv->notebook, vbox_tab[0], NULL, 0);
889     gtk_notebook_insert_page (priv->notebook, vbox_tab[1], NULL, 1);
890     gtk_notebook_insert_page (priv->notebook, vbox_tab[2], NULL, 2);
891
892     gtk_notebook_set_tab_label_text (priv->notebook, vbox_tab[0],
893             _("ecdg_ti_font_dialog_style"));
894     gtk_notebook_set_tab_label_text (priv->notebook, vbox_tab[1],
895             _("ecdg_ti_font_dialog_format"));
896     gtk_notebook_set_tab_label_text (priv->notebook, vbox_tab[2],
897             _("ecdg_ti_font_dialog_other"));
898
899     gtk_widget_show_all (GTK_WIDGET (priv->notebook));
900 }
901
902 static void 
903 color_modified_cb                               (HildonColorButton *button, 
904                                                  GParamSpec *pspec, 
905                                                  gpointer fsd_priv)
906 {
907     HildonFontSelectionDialogPrivate *priv = (HildonFontSelectionDialogPrivate *) fsd_priv;
908     g_assert (priv);
909
910     priv->color_set = TRUE;
911 }
912
913 static void 
914 hildon_font_selection_dialog_finalize           (GObject *object)
915 {
916     HildonFontSelectionDialogPrivate *priv;
917     HildonFontSelectionDialog *fontsel;
918
919     g_assert (HILDON_IS_FONT_SELECTION_DIALOG (object));
920     fontsel = HILDON_FONT_SELECTION_DIALOG (object);
921
922     priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fontsel);
923     g_assert (priv);
924
925     if (priv->preview_text != NULL) {
926         g_free (priv->preview_text);
927         priv->preview_text = NULL;
928     }
929
930     if (priv->families != NULL) {
931         g_free (priv->families);
932         priv->families = NULL;
933     }
934
935     if (G_OBJECT_CLASS (parent_class)->finalize)
936         G_OBJECT_CLASS (parent_class)->finalize (object);
937 }
938
939 static int 
940 cmp_families                                    (const void *a, 
941                                                  const void *b)
942 {
943     const char *a_name =
944         pango_font_family_get_name (* (PangoFontFamily **) a);
945
946     const char *b_name =
947         pango_font_family_get_name (* (PangoFontFamily **) b);
948
949     return g_utf8_collate (a_name, b_name);
950 }
951
952 /* Exits the preview dialog with GTK_RESPONSE_CANCEL if Esc key
953  * was pressed 
954  * FIXME This should be handled automatically */
955 static gboolean
956 hildon_font_selection_dialog_preview_key_press  (GtkWidget *widget,
957                                                  GdkEventKey *event,
958                                                  gpointer unused)
959 {
960     g_assert (widget);
961     g_assert (event);
962
963     if (event->keyval == GDK_Escape)
964     {
965         gtk_dialog_response (GTK_DIALOG (widget), GTK_RESPONSE_CANCEL);
966         return TRUE;
967     }
968
969     return FALSE;
970 }
971
972 static void
973 add_preview_text_attr                           (PangoAttrList *list, 
974                                                  PangoAttribute *attr, 
975                                                  guint start, 
976                                                  guint len)
977 {
978     attr->start_index = start;
979     attr->end_index = start + len;
980     pango_attr_list_insert (list, attr);
981 }
982
983 static PangoAttrList*
984 hildon_font_selection_dialog_create_attrlist    (HildonFontSelectionDialog *fontsel, 
985                                                  guint start_index, 
986                                                  guint len)
987 {
988     PangoAttrList *list;
989     PangoAttribute *attr;
990     gint size, position;
991     gboolean family_set, size_set, color_set, bold, bold_set,
992              italic, italic_set, underline, underline_set,
993              strikethrough, strikethrough_set, position_set;
994     GdkColor *color = NULL;
995     gchar *family = NULL;
996     gdouble font_scaling = 1.0;
997
998     list = pango_attr_list_new ();
999
1000     g_object_get (G_OBJECT (fontsel),
1001             "family", &family, "family-set", &family_set,
1002             "size", &size, "size-set", &size_set,
1003             "color", &color, "color-set", &color_set,
1004             "bold", &bold, "bold-set", &bold_set,
1005             "italic", &italic, "italic-set", &italic_set,
1006             "underline", &underline, "underline-set", &underline_set,
1007             "strikethrough", &strikethrough, "strikethrough-set", 
1008             &strikethrough_set, "position", &position, 
1009             "position-set", &position_set, 
1010             "font-scaling", &font_scaling,
1011             NULL);
1012
1013     /* family */
1014     if (family_set)
1015     {
1016         attr = pango_attr_family_new (family);
1017         add_preview_text_attr (list, attr, start_index, len);
1018     }
1019     g_free (family);
1020
1021     /* size */
1022     if (size_set)
1023     {
1024         attr = pango_attr_size_new (size * PANGO_SCALE);
1025         add_preview_text_attr (list, attr, start_index, len);
1026     }
1027
1028     /*color*/
1029     if (color_set)
1030     {
1031         attr = pango_attr_foreground_new (color->red, color->green, color->blue);
1032         add_preview_text_attr (list, attr, start_index, len);
1033     }
1034
1035     if (color != NULL)
1036         gdk_color_free (color);
1037
1038     /*weight*/
1039     if (bold_set)
1040     {
1041         if (bold)
1042             attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
1043         else
1044             attr = pango_attr_weight_new (PANGO_WEIGHT_NORMAL);
1045
1046         add_preview_text_attr(list, attr, start_index, len);
1047     }
1048
1049     /* style */
1050     if (italic_set)
1051     {
1052         if (italic)
1053             attr = pango_attr_style_new (PANGO_STYLE_ITALIC);
1054         else
1055             attr = pango_attr_style_new (PANGO_STYLE_NORMAL);
1056
1057         add_preview_text_attr(list, attr, start_index, len);
1058     }
1059
1060     /* underline */
1061     if (underline_set)
1062     {
1063         if (underline)
1064             attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
1065         else
1066             attr = pango_attr_underline_new (PANGO_UNDERLINE_NONE);
1067
1068         add_preview_text_attr(list, attr, start_index, len);
1069     }
1070
1071     /* strikethrough */
1072     if (strikethrough_set)
1073     {
1074         if (strikethrough)
1075             attr = pango_attr_strikethrough_new (TRUE);
1076         else
1077             attr = pango_attr_strikethrough_new (FALSE);
1078
1079         add_preview_text_attr(list, attr, start_index, len);
1080     }
1081
1082     /* position */
1083     if (position_set)
1084     {
1085         switch (position)
1086         {
1087             case 1: /*super*/
1088                 attr = pango_attr_rise_new (SUPERSCRIPT_RISE);
1089                 break;
1090             case -1: /*sub*/
1091                 attr = pango_attr_rise_new (SUBSCRIPT_LOW);
1092                 break;
1093             default: /*normal*/
1094                 attr = pango_attr_rise_new (0);
1095                 break;
1096         }
1097
1098         add_preview_text_attr (list, attr, start_index, len);
1099     }
1100
1101     /* font scaling for preview */
1102     if (font_scaling)
1103     {
1104         attr = pango_attr_scale_new(font_scaling);
1105         add_preview_text_attr(list, attr, 0, len + start_index);
1106     }
1107
1108     return list;
1109 }
1110
1111 static void
1112 hildon_font_selection_dialog_show_preview       (HildonFontSelectionDialog *fontsel)
1113 {
1114     HildonFontSelectionDialogPrivate *priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fontsel);
1115     gint size;
1116     gboolean family_set, size_set;
1117     PangoAttribute *attr;
1118     PangoAttrList *list;
1119     GtkWidget *preview_dialog;
1120     GtkWidget *preview_label;
1121     gchar *str = NULL;
1122     gboolean position_set = FALSE;
1123     gint position = 0;
1124     gboolean show_ref = FALSE;
1125
1126     g_assert (priv);
1127
1128     g_object_get (G_OBJECT (fontsel), "position-set", &position_set, NULL);
1129
1130     if (position_set) {
1131         g_object_get (G_OBJECT (fontsel), "position", &position, NULL);
1132         if (position == 1 || position == -1)
1133             show_ref = TRUE;
1134     }
1135
1136     /* preview dialog init */
1137     preview_dialog =
1138         gtk_dialog_new_with_buttons (_("ecdg_ti_preview_font"), NULL,
1139                 GTK_DIALOG_MODAL |
1140                 GTK_DIALOG_DESTROY_WITH_PARENT |
1141                 GTK_DIALOG_NO_SEPARATOR,
1142                 _("ecdg_bd_font_dialog_ok"),
1143                 GTK_RESPONSE_ACCEPT,
1144                 NULL);
1145
1146     str = (show_ref) ? g_strconcat (_("ecdg_fi_preview_font_preview_reference"), priv->preview_text, 0) :
1147         g_strdup (priv->preview_text);
1148
1149     preview_label = gtk_label_new (str);
1150     gtk_label_set_line_wrap (GTK_LABEL(preview_label), TRUE);
1151
1152     if (str) 
1153         g_free (str);
1154
1155     str = NULL;
1156
1157     /* set keypress handler (ESC hardkey) */
1158     g_signal_connect (G_OBJECT (preview_dialog), "key-press-event",
1159             G_CALLBACK(hildon_font_selection_dialog_preview_key_press),
1160             NULL);
1161
1162     /* Set the font */
1163     list = (show_ref) ? hildon_font_selection_dialog_create_attrlist (fontsel, 
1164             strlen (_("ecdg_fi_preview_font_preview_reference")),
1165             strlen (priv->preview_text)) :
1166         hildon_font_selection_dialog_create_attrlist (fontsel, 0, strlen(priv->preview_text));
1167
1168     g_object_get (G_OBJECT (fontsel), "family", &str, "family-set",
1169             &family_set, "size", &size, "size-set", &size_set,
1170             NULL);
1171
1172     /* A smallish hack to add scrollbar when font size is really big */
1173
1174     if (size_set && size > 24) {
1175         GtkScrolledWindow *scrolled = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
1176         gtk_scrolled_window_set_policy (scrolled, GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1177         gtk_scrolled_window_add_with_viewport (scrolled, GTK_WIDGET (preview_label));
1178         gtk_container_add (GTK_CONTAINER (GTK_DIALOG(preview_dialog)->vbox), GTK_WIDGET (scrolled));
1179         gtk_widget_set_size_request (GTK_WIDGET (scrolled), -1, 400);
1180     } else 
1181         gtk_container_add (GTK_CONTAINER (GTK_DIALOG(preview_dialog)->vbox), GTK_WIDGET (preview_label));
1182
1183     /* make reference text to have the same fontface and size */
1184     if (family_set)
1185     {
1186         attr = pango_attr_family_new (str);
1187         add_preview_text_attr (list, attr, 0, strlen (_("ecdg_fi_preview_font_preview_reference")));
1188     }
1189     if (str != NULL)
1190         g_free (str);
1191
1192     str = NULL;
1193
1194     /* size */
1195     if (size_set)
1196     {
1197         attr = pango_attr_size_new (size * PANGO_SCALE);
1198         add_preview_text_attr (list, attr, 0, strlen (_("ecdg_fi_preview_font_preview_reference")));
1199     }
1200
1201     gtk_label_set_attributes (GTK_LABEL (preview_label), list);
1202     pango_attr_list_unref (list);
1203
1204     /*And show the dialog*/
1205     gtk_window_set_transient_for (GTK_WINDOW (preview_dialog), 
1206             GTK_WINDOW (fontsel));
1207
1208     gtk_widget_show_all (preview_dialog);
1209     gtk_dialog_set_default_response (GTK_DIALOG (preview_dialog), GTK_RESPONSE_OK);
1210     
1211     GtkBox *action_area = (GtkBox *) GTK_DIALOG (preview_dialog)->action_area;
1212     GtkWidget *button = ((GtkBoxChild *) ((GSList *) action_area->children)->data)->widget;
1213     gtk_widget_grab_focus (button);
1214
1215     gtk_dialog_run (GTK_DIALOG (preview_dialog));
1216     gtk_widget_destroy (preview_dialog);
1217 }
1218
1219 static gboolean 
1220 is_internal_font                                (const gchar * name)
1221 {
1222     /* FIXME Extremally BAD BAD BAD way of doing things */
1223
1224     return strcmp(name, "DeviceSymbols") == 0
1225         || strcmp(name, "Nokia Smiley" ) == 0
1226         || strcmp(name, "NewCourier" ) == 0
1227         || strcmp(name, "NewTimes" ) == 0
1228         || strcmp(name, "SwissA" ) == 0
1229         || strcmp(name, "Nokia Sans"   ) == 0
1230         || strcmp(name, "Nokia Sans Cn") == 0;
1231 }
1232
1233 static void 
1234 filter_out_internal_fonts                       (PangoFontFamily **families, 
1235                                                  int *n_families)
1236 {
1237     int i;
1238     int n; /* counts valid fonts */
1239     const gchar * name = NULL;
1240
1241     for(i = 0, n = 0; i < * n_families; i++){
1242
1243         name = pango_font_family_get_name (families[i]);
1244
1245         if(!is_internal_font(name))
1246         {
1247
1248             if (i!=n){ /* there are filtered out families */
1249                 families[n] = families[i]; /* shift the current family */
1250             }
1251
1252             n++; /* count one more valid */
1253         }
1254     } /* foreach font family */
1255
1256     *n_families = n;  
1257 }
1258
1259 static void
1260 hildon_font_selection_dialog_show_available_fonts (HildonFontSelectionDialog *fontsel)
1261
1262 {
1263     gint i;
1264
1265     HildonFontSelectionDialogPrivate *priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fontsel);
1266     g_assert (priv);
1267
1268     pango_context_list_families (gtk_widget_get_pango_context
1269             (GTK_WIDGET (fontsel)), &priv->families,
1270             &priv->n_families);
1271
1272     filter_out_internal_fonts (priv->families, &priv->n_families);
1273
1274     qsort (priv->families, priv->n_families, sizeof(PangoFontFamily *), cmp_families);
1275
1276     for (i = 0; i < priv->n_families; i++) 
1277     {
1278         const gchar *name = pango_font_family_get_name (priv->families[i]);
1279         gtk_combo_box_append_text (GTK_COMBO_BOX (priv->cbx_font_type), name);
1280     }
1281 }
1282
1283 static void
1284 hildon_font_selection_dialog_show_available_positionings (HildonFontSelectionDialogPrivate *priv)
1285 {
1286     gtk_combo_box_append_text (GTK_COMBO_BOX (priv->cbx_positioning), _("ecdg_va_font_printpos_1"));
1287     gtk_combo_box_append_text (GTK_COMBO_BOX (priv->cbx_positioning), _("ecdg_va_font_printpos_2"));
1288     gtk_combo_box_append_text (GTK_COMBO_BOX (priv->cbx_positioning), _("ecdg_va_font_printpos_3"));
1289 }
1290
1291 /* Loads the sizes from a pre-allocated table */
1292 static void
1293 hildon_font_selection_dialog_show_available_sizes (HildonFontSelectionDialogPrivate *priv)
1294 {
1295     gchar *size_str;
1296     gint i;
1297
1298     g_assert (priv);
1299
1300     for (i = 0; i < G_N_ELEMENTS (font_sizes); i++) 
1301     {
1302         size_str = g_strdup_printf ("%i%s",
1303                 font_sizes[i],
1304                 _("ecdg_va_font_size_trailer"));
1305
1306         gtk_combo_box_append_text (GTK_COMBO_BOX (priv->cbx_font_size), size_str);
1307         g_free (size_str);
1308     }
1309 }
1310
1311 static void
1312 toggle_clicked                                  (GtkButton *button, 
1313                                                  gpointer unused)
1314 {
1315     GtkToggleButton *t_b = GTK_TOGGLE_BUTTON (button);
1316
1317     /* we have to remove the inconsistent state ourselves */
1318     if (gtk_toggle_button_get_inconsistent (t_b))
1319     {
1320         gtk_toggle_button_set_inconsistent (t_b, FALSE);
1321         gtk_toggle_button_set_active (t_b, FALSE);
1322     }
1323 }
1324
1325 /**
1326  * hildon_font_selection_dialog_new:
1327  * @parent: the parent window
1328  * @title: the title of font selection dialog
1329  *
1330  * If NULL is passed for title, then default title
1331  * "Font" will be used.
1332  *
1333  * Returns: a new #HildonFontSelectionDialog
1334  */
1335 GtkWidget*
1336 hildon_font_selection_dialog_new                (GtkWindow *parent,
1337                                                  const gchar *title)
1338 {
1339     HildonFontSelectionDialog *fontseldiag;
1340
1341     fontseldiag = g_object_new (HILDON_TYPE_FONT_SELECTION_DIALOG,
1342             "has-separator", FALSE, NULL);
1343
1344     if (title)
1345         gtk_window_set_title (GTK_WINDOW (fontseldiag), title);
1346
1347     if (parent)
1348         gtk_window_set_transient_for (GTK_WINDOW (fontseldiag), parent);
1349
1350     return GTK_WIDGET (fontseldiag);
1351 }
1352
1353 /**
1354  * hildon_font_selection_dialog_get_preview_text:
1355  * @fsd: the font selection dialog
1356  *
1357  * Gets the text in preview dialog, which does not include the 
1358  * reference text. The returned string must be freed by the user.
1359  *
1360  * Returns: a string pointer
1361  */
1362 gchar*
1363 hildon_font_selection_dialog_get_preview_text   (HildonFontSelectionDialog * fsd)
1364 {
1365     /* FIXME Return a const pointer? */
1366     HildonFontSelectionDialogPrivate *priv;
1367
1368     g_return_val_if_fail (HILDON_IS_FONT_SELECTION_DIALOG (fsd), FALSE);
1369         
1370     priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fsd);
1371     g_assert (priv);
1372
1373     return g_strdup (priv->preview_text);
1374 }
1375
1376 /**
1377  * hildon_font_selection_dialog_set_preview_text:
1378  * @fsd: the font selection dialog
1379  * @text: the text to be displayed in the preview dialog
1380  *
1381  * The default preview text is
1382  * "The quick brown fox jumped over the lazy dogs"
1383  */
1384 void
1385 hildon_font_selection_dialog_set_preview_text   (HildonFontSelectionDialog *fsd, 
1386                                                  const gchar * text)
1387 {
1388     HildonFontSelectionDialogPrivate *priv = NULL;
1389
1390     g_return_if_fail (HILDON_IS_FONT_SELECTION_DIALOG (fsd));
1391     g_return_if_fail (text);
1392
1393     priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fsd);
1394     g_assert (priv);
1395
1396     g_free (priv->preview_text);
1397     priv->preview_text = g_strdup (text);
1398     g_object_notify (G_OBJECT (fsd), "preview-text");
1399 }
1400