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