Add HildonAppMenu::changed signal
[hildon] / hildon / 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 *family;
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             family = g_value_get_string (value);
369             g_return_if_fail (family != NULL);
370             for(i = 0; i < priv->n_families; i++)
371             {
372                 if (strcmp (family, pango_font_family_get_name (priv->families[i]))
373                         == 0)
374                 {
375                     gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cbx_font_type), i);
376                     break;
377                 }
378             }
379             break;
380
381         case PROP_FAMILY_SET:
382             b = g_value_get_boolean (value);
383             if(!b)
384                 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cbx_font_type), -1);
385             break;
386
387         case PROP_SIZE:
388             size = g_value_get_int (value);
389             for(i = 0; i < G_N_ELEMENTS (font_sizes); i++)
390             {
391                 if(size == font_sizes[i])
392                 {
393                     gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cbx_font_size), i);
394                     break;
395                 }
396             }
397             break;
398
399         case PROP_SIZE_SET:
400             b = g_value_get_boolean (value);
401             if(!b)
402                 gtk_combo_box_set_active (GTK_COMBO_BOX (priv->cbx_font_size), -1);
403             break;
404
405         case PROP_COLOR:
406             color = (GdkColor *) g_value_get_boxed (value);
407             if(color != NULL)
408                 hildon_color_button_set_color (HILDON_COLOR_BUTTON
409                         (priv->font_color_button),
410                         color);
411             else
412                 hildon_color_button_set_color (HILDON_COLOR_BUTTON
413                         (priv->font_color_button),
414                         &black);
415             break;
416
417         case PROP_COLOR_SET:
418             priv->color_set = g_value_get_boolean (value);
419             if(! priv->color_set)
420             {
421                 /* set color to black, but block our signal handler */
422                 g_signal_handler_block ((gpointer) priv->font_color_button,
423                         priv->color_modified_signal_handler);
424
425                 hildon_color_button_set_color (HILDON_COLOR_BUTTON
426                         (priv->font_color_button), 
427                         &black);
428
429                 g_signal_handler_unblock ((gpointer) priv->font_color_button,
430                         priv->color_modified_signal_handler);
431             }
432             break;
433
434         case PROP_BOLD:
435             /* this call will make sure that we dont get extra clicked signal */
436             gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON(priv->chk_bold), FALSE);
437             gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(priv->chk_bold), g_value_get_boolean (value));
438             break;
439
440         case PROP_BOLD_SET:
441             gtk_toggle_button_set_inconsistent (GTK_TOGGLE_BUTTON (priv->chk_bold),! g_value_get_boolean(value));
442             break;
443
444         case PROP_ITALIC:
445             gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(priv->chk_italic),
446                     FALSE);
447             gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->chk_italic),
448                     g_value_get_boolean(value));
449             break;
450
451         case PROP_ITALIC_SET:
452             gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(priv->chk_italic),
453                     !g_value_get_boolean(value));
454             break;
455
456         case PROP_UNDERLINE:
457             gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON
458                     (priv->chk_underline),
459                     FALSE);
460             gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->chk_underline),
461                     g_value_get_boolean(value));
462             break;
463
464         case PROP_UNDERLINE_SET:
465             gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON(priv->chk_underline),
466                     !g_value_get_boolean(value));
467             break;
468
469         case PROP_STRIKETHROUGH:
470             gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON
471                     (priv->chk_strikethrough),
472                     FALSE);
473             gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(priv->chk_strikethrough),
474                     g_value_get_boolean(value));
475             break;
476
477         case PROP_STRIKETHROUGH_SET:
478             gtk_toggle_button_set_inconsistent(GTK_TOGGLE_BUTTON
479                     (priv->chk_strikethrough),
480                     !g_value_get_boolean(value));
481             break;
482
483         case PROP_POSITION:
484             i = g_value_get_int(value);
485             if( i == 1 )
486                 gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_positioning), 1);
487             else if(i == -1)
488                 gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_positioning), 2);
489             else
490                 gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_positioning), 0);
491             break;
492
493         case PROP_FONT_SCALING:
494             priv->font_scaling = g_value_get_double(value);
495             break;
496
497         case PROP_POSITION_SET:
498             b = g_value_get_boolean(value);
499             if(!b)
500                 gtk_combo_box_set_active(GTK_COMBO_BOX(priv->cbx_positioning), -1);
501             break;
502
503         case PROP_PREVIEW_TEXT:
504             hildon_font_selection_dialog_set_preview_text(
505                     HILDON_FONT_SELECTION_DIALOG(object),
506                     g_value_get_string(value));
507             break;
508
509         default:
510             G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
511             break;
512     }
513 }
514
515 static void
516 hildon_font_selection_dialog_class_init         (HildonFontSelectionDialogClass *klass)
517 {
518     GObjectClass *gobject_class;
519
520     parent_class = g_type_class_peek_parent (klass);
521     gobject_class = G_OBJECT_CLASS (klass);
522
523     gobject_class->finalize         = hildon_font_selection_dialog_finalize;
524     gobject_class->get_property     = hildon_font_selection_dialog_get_property;
525     gobject_class->set_property     = hildon_font_selection_dialog_set_property;
526
527     /* Install properties to the class */
528
529     /**
530      * HildonFontSelectionDialog:family:
531      *
532      * Font family used.
533      */
534     g_object_class_install_property (gobject_class, PROP_FAMILY,
535             g_param_spec_string ("family",
536                 "Font family", "String defines"
537                 " the font family", "Sans",
538                 G_PARAM_READWRITE));
539
540     /**
541      * HildonFontSelectionDialog:family-set:
542      *
543      * Is font family set or inconsistent.
544      */
545     g_object_class_install_property (gobject_class, PROP_FAMILY_SET,
546             g_param_spec_boolean ("family-set",
547                 "family inconsistent state",
548                 "Whether the family property"
549                 " is inconsistent", FALSE,
550                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
551
552     /**
553      * HildonFontSelectionDialog:size:
554      *
555      * Font size.
556      */
557     g_object_class_install_property (gobject_class, PROP_SIZE,
558             g_param_spec_int ("size",
559                 "Font size",
560                 "Font size in Pt",
561                 6, 32, 16,
562                 G_PARAM_READWRITE));
563
564     /**
565      * HildonFontSelectionDialog:size-set:
566      *
567      * Is font size set or inconsistent.
568      */
569     g_object_class_install_property (gobject_class, PROP_SIZE_SET,
570             g_param_spec_boolean ("size-set",
571                 "size inconsistent state",
572                 "Whether the size property"
573                 " is inconsistent", FALSE,
574                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
575
576     /**
577      * HildonFontSelectionDialog:color:
578      *
579      * GdkColor for the text.
580      */
581     g_object_class_install_property (gobject_class, PROP_COLOR,
582             g_param_spec_boxed ("color",
583                 "text color",
584                 "gdk color for the text",
585                 GDK_TYPE_COLOR,
586                 G_PARAM_READWRITE));
587
588     /**
589      * HildonFontSelectionDialog:color-set:
590      *
591      * Is font color set or inconsistent.
592      */
593     g_object_class_install_property (gobject_class, PROP_COLOR_SET,
594             g_param_spec_boolean ("color-set",
595                 "color inconsistent state",
596                 "Whether the color property"
597                 " is inconsistent", FALSE,
598                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
599
600     /**
601      * HildonFontSelectionDialog:color-set:
602      *
603      * Is font set as bold.
604      */
605     g_object_class_install_property (gobject_class, PROP_BOLD,
606             g_param_spec_boolean ("bold",
607                 "text weight",
608                 "Whether the text is bold",
609                 FALSE,
610                 G_PARAM_READWRITE));
611
612     /**
613      * HildonFontSelectionDialog:color-set:
614      *
615      * Is font bold status set or inconsistent.
616      */
617     g_object_class_install_property (gobject_class, PROP_BOLD_SET,
618             g_param_spec_boolean ("bold-set",
619                 "bold inconsistent state",
620                 "Whether the bold"
621                 " is inconsistent", FALSE,
622                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
623
624     /**
625      * HildonFontSelectionDialog:italic:
626      *
627      * Is font set as italic.
628      */
629     g_object_class_install_property (gobject_class, PROP_ITALIC,
630             g_param_spec_boolean ("italic",
631                 "text style",
632                 "Whether the text is italic",
633                 FALSE,
634                 G_PARAM_READWRITE));
635
636     /**
637      * HildonFontSelectionDialog:italic-set:
638      *
639      * Is font italic status set or inconsistent.
640      */
641     g_object_class_install_property (gobject_class, PROP_ITALIC_SET,
642             g_param_spec_boolean ("italic-set",
643                 "italic inconsistent state",
644                 "Whether the italic"
645                 " is inconsistent", FALSE,
646                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
647
648     /**
649      * HildonFontSelectionDialog:underline:
650      *
651      * Is the font underlined.
652      */
653     g_object_class_install_property (gobject_class, PROP_UNDERLINE,
654             g_param_spec_boolean ("underline",
655                 "text underline",
656                 "Whether the text is underlined",
657                 FALSE,
658                 G_PARAM_READWRITE));
659
660     /**
661      * HildonFontSelectionDialog:underline:
662      *
663      * Is font underline status set or inconsistent.
664      */
665     g_object_class_install_property (gobject_class, PROP_UNDERLINE_SET,
666             g_param_spec_boolean ("underline-set",
667                 "underline inconsistent state",
668                 "Whether the underline"
669                 " is inconsistent", FALSE,
670                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
671
672     /**
673      * HildonFontSelectionDialog:strikethrough:
674      *
675      * Is the font striken-through.
676      */
677     g_object_class_install_property (gobject_class, PROP_STRIKETHROUGH,
678             g_param_spec_boolean ("strikethrough",
679                 "strikethroughed text",
680                 "Whether the text is strikethroughed",
681                 FALSE,
682                 G_PARAM_READWRITE));
683
684     /**
685      * HildonFontSelectionDialog:strikethrough-set:
686      *
687      * Is the font strikenthrough status set.
688      */
689     g_object_class_install_property (gobject_class, PROP_STRIKETHROUGH_SET,
690             g_param_spec_boolean ("strikethrough-set",
691                 "strikethrough inconsistent state",
692                 "Whether the strikethrough"
693                 " is inconsistent", FALSE,
694                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
695
696     /**
697      * HildonFontSelectionDialog:position:
698      *
699      * The font positioning versus baseline.
700      */
701     g_object_class_install_property (gobject_class, PROP_POSITION,
702             g_param_spec_int ("position",
703                 "Font position",
704                 "Font position super or subscript",
705                 -1, 1, 0,
706                 G_PARAM_READWRITE));
707
708     /**
709      * HildonFontSelectionDialog:position-set:
710      *
711      * Is the font positioning set.
712      */
713     g_object_class_install_property (gobject_class, PROP_POSITION_SET,
714             g_param_spec_boolean ("position-set",
715                 "position inconsistent state",
716                 "Whether the position"
717                 " is inconsistent", FALSE,
718                 G_PARAM_READWRITE | G_PARAM_CONSTRUCT));
719
720     /**
721      * HildonFontSelectionDialog:font-scaling:
722      *
723      * The font scaling factor applied to the preview dialog.
724      */
725     g_object_class_install_property (gobject_class, PROP_FONT_SCALING,
726             g_param_spec_double ("font-scaling",
727                 "Font scaling",
728                 "Font scaling for the preview dialog",
729                 0, 10, 1,
730                 G_PARAM_READWRITE));
731
732     /**
733      * HildonFontSelectionDialog:preview-text:
734      *
735      * The text used for the preview dialog.
736      *
737      * Deprecated: this property is unused since hildon 2.2
738      */
739     g_object_class_install_property (gobject_class, PROP_PREVIEW_TEXT,
740             g_param_spec_string("preview-text",
741                 "Preview Text", 
742                 "the text in preview dialog, which does" 
743                 "not include the reference text",
744                 "",
745                 G_PARAM_READWRITE));
746
747     g_type_class_add_private (klass, 
748             sizeof (struct _HildonFontSelectionDialogPrivate));
749 }
750
751 static void 
752 hildon_font_selection_dialog_init               (HildonFontSelectionDialog *fontseldiag)
753 {
754     HildonFontSelectionDialogPrivate *priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fontseldiag);
755     /* GtkWidget *preview_button; */
756
757     g_assert (priv);
758     priv->notebook = GTK_NOTEBOOK (gtk_notebook_new ());
759
760     hildon_font_selection_dialog_construct_notebook (fontseldiag);
761
762     gtk_box_pack_start (GTK_BOX (GTK_DIALOG (fontseldiag)->vbox),
763             GTK_WIDGET (priv->notebook), TRUE, TRUE, 0);
764
765     /* Add dialog buttons */
766     gtk_dialog_add_button (GTK_DIALOG (fontseldiag),
767             _("wdgt_bd_done"),
768             GTK_RESPONSE_OK);
769
770 #if 0
771     preview_button = gtk_button_new_with_label (_("ecdg_bd_font_dialog_preview"));
772     gtk_box_pack_start (GTK_BOX(GTK_DIALOG (fontseldiag)->action_area),
773             preview_button, FALSE, TRUE, 0);
774
775     g_signal_connect_swapped (preview_button, "clicked",
776             G_CALLBACK
777             (hildon_font_selection_dialog_show_preview),
778             fontseldiag);
779     gtk_widget_show(preview_button);
780 #endif
781
782     /*Set default preview text*/
783     priv->preview_text = g_strdup (_("ecdg_fi_preview_font_preview_text"));
784
785     gtk_window_set_title (GTK_WINDOW (fontseldiag), _("ecdg_ti_font"));
786     /*here is the line to make sure that notebook has the default focus*/
787     gtk_container_set_focus_child (GTK_CONTAINER (GTK_DIALOG (fontseldiag)->vbox),
788             GTK_WIDGET (priv->notebook));
789 }
790
791 static void 
792 hildon_font_selection_dialog_construct_notebook (HildonFontSelectionDialog *fontsel)
793 {
794     gint i;
795     GtkWidget *vbox_tab[3];
796     GtkWidget *font_color_box;
797     GtkWidget *caption_control;
798     GtkSizeGroup *group;
799
800     HildonFontSelectionDialogPrivate *priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fontsel);
801     g_assert (priv);
802
803     for (i = 0; i < 3; i++)
804         vbox_tab[i] = gtk_vbox_new (TRUE, 0);
805
806     group = GTK_SIZE_GROUP (gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL));
807
808     /* Build the first page of the GtkNotebook: font style */
809     priv->cbx_font_type = gtk_combo_box_new_text ();
810     hildon_font_selection_dialog_show_available_fonts (fontsel);
811     caption_control = hildon_caption_new (group,
812             _("ecdg_fi_font_font"),
813             priv->cbx_font_type,
814             NULL,
815             HILDON_CAPTION_OPTIONAL);
816
817     gtk_box_pack_start (GTK_BOX (vbox_tab[0]), caption_control, FALSE, FALSE, 0);
818
819     priv->cbx_font_size = gtk_combo_box_new_text ();
820     hildon_font_selection_dialog_show_available_sizes (priv);
821     caption_control = hildon_caption_new (group,
822             _("ecdg_fi_font_size"),
823             priv->cbx_font_size,
824             NULL,
825             HILDON_CAPTION_OPTIONAL);
826
827     gtk_box_pack_start (GTK_BOX (vbox_tab[0]), caption_control, FALSE, FALSE, 0);
828
829     font_color_box = gtk_hbox_new (FALSE, 0);
830     priv->font_color_button = hildon_color_button_new ();
831     priv->color_set = FALSE;
832     priv->font_scaling = 1.0;
833     priv->color_modified_signal_handler = 
834         g_signal_connect (G_OBJECT (priv->font_color_button), "notify::color",
835                 G_CALLBACK (color_modified_cb), (gpointer) priv);
836
837     gtk_box_pack_start (GTK_BOX (font_color_box), priv->font_color_button, FALSE, FALSE, 0);
838
839     caption_control =
840         hildon_caption_new (group, _("ecdg_fi_font_colour_selector"),
841                 font_color_box,
842                 NULL, HILDON_CAPTION_OPTIONAL);
843
844     gtk_box_pack_start (GTK_BOX (vbox_tab[0]), caption_control, FALSE, FALSE, 0);
845
846     /* Build the second page of the GtkNotebook: font formatting */ 
847     priv->chk_bold = gtk_check_button_new ();
848     caption_control = hildon_caption_new (group,
849             _("ecdg_fi_font_bold"),
850             priv->chk_bold,
851             NULL,
852             HILDON_CAPTION_OPTIONAL);
853
854     gtk_box_pack_start (GTK_BOX (vbox_tab[1]), caption_control, FALSE, FALSE, 0);
855     g_signal_connect (G_OBJECT (priv->chk_bold), "clicked", 
856             G_CALLBACK(toggle_clicked), NULL);
857
858     priv->chk_italic = gtk_check_button_new ();
859     caption_control = hildon_caption_new (group, _("ecdg_fi_font_italic"),
860                 priv->chk_italic,
861                 NULL, HILDON_CAPTION_OPTIONAL);
862
863     gtk_box_pack_start (GTK_BOX (vbox_tab[1]), caption_control, FALSE, FALSE, 0);
864     g_signal_connect(G_OBJECT(priv->chk_italic), "clicked", 
865             G_CALLBACK(toggle_clicked), NULL);
866
867     priv->chk_underline = gtk_check_button_new();
868     caption_control =
869         hildon_caption_new (group, _("ecdg_fi_font_underline"),
870                 priv->chk_underline, NULL,
871                 HILDON_CAPTION_OPTIONAL);
872
873     gtk_box_pack_start (GTK_BOX (vbox_tab[1]), caption_control, FALSE, FALSE, 0);
874     g_signal_connect (G_OBJECT(priv->chk_underline), "clicked", 
875             G_CALLBACK (toggle_clicked), NULL);
876
877     /* Build the third page of the GtkNotebook: other font properties */
878     priv->chk_strikethrough = gtk_check_button_new ();
879     caption_control = hildon_caption_new(group, _("ecdg_fi_font_strikethrough"),
880                 priv->chk_strikethrough, NULL,
881                 HILDON_CAPTION_OPTIONAL);
882
883     gtk_box_pack_start (GTK_BOX (vbox_tab[2]), caption_control, FALSE, FALSE, 0);
884     g_signal_connect (G_OBJECT(priv->chk_strikethrough), "clicked", 
885             G_CALLBACK (toggle_clicked), NULL);
886
887     priv->cbx_positioning = gtk_combo_box_new_text ();
888     hildon_font_selection_dialog_show_available_positionings (priv);
889     caption_control =
890         hildon_caption_new(group, _("ecdg_fi_font_special"),
891                 priv->cbx_positioning, NULL,
892                 HILDON_CAPTION_OPTIONAL);
893
894     g_object_unref (group);
895
896     gtk_box_pack_start (GTK_BOX (vbox_tab[2]), caption_control, FALSE, FALSE, 0);
897
898     /* Populate notebook */
899     gtk_notebook_insert_page (priv->notebook, vbox_tab[0], NULL, 0);
900     gtk_notebook_insert_page (priv->notebook, vbox_tab[1], NULL, 1);
901     gtk_notebook_insert_page (priv->notebook, vbox_tab[2], NULL, 2);
902
903     gtk_notebook_set_tab_label_text (priv->notebook, vbox_tab[0],
904             _("ecdg_ti_font_dialog_style"));
905     gtk_notebook_set_tab_label_text (priv->notebook, vbox_tab[1],
906             _("ecdg_ti_font_dialog_format"));
907     gtk_notebook_set_tab_label_text (priv->notebook, vbox_tab[2],
908             _("ecdg_ti_font_dialog_other"));
909
910     gtk_widget_show_all (GTK_WIDGET (priv->notebook));
911 }
912
913 static void 
914 color_modified_cb                               (HildonColorButton *button, 
915                                                  GParamSpec *pspec, 
916                                                  gpointer fsd_priv)
917 {
918     HildonFontSelectionDialogPrivate *priv = (HildonFontSelectionDialogPrivate *) fsd_priv;
919     g_assert (priv);
920
921     priv->color_set = TRUE;
922 }
923
924 static void 
925 hildon_font_selection_dialog_finalize           (GObject *object)
926 {
927     HildonFontSelectionDialogPrivate *priv;
928     HildonFontSelectionDialog *fontsel;
929
930     g_assert (HILDON_IS_FONT_SELECTION_DIALOG (object));
931     fontsel = HILDON_FONT_SELECTION_DIALOG (object);
932
933     priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fontsel);
934     g_assert (priv);
935
936     if (priv->preview_text != NULL) {
937         g_free (priv->preview_text);
938         priv->preview_text = NULL;
939     }
940
941     if (priv->families != NULL) {
942         g_free (priv->families);
943         priv->families = NULL;
944     }
945
946     if (G_OBJECT_CLASS (parent_class)->finalize)
947         G_OBJECT_CLASS (parent_class)->finalize (object);
948 }
949
950 static int 
951 cmp_families                                    (const void *a, 
952                                                  const void *b)
953 {
954     const char *a_name =
955         pango_font_family_get_name (* (PangoFontFamily **) a);
956
957     const char *b_name =
958         pango_font_family_get_name (* (PangoFontFamily **) b);
959
960     return g_utf8_collate (a_name, b_name);
961 }
962
963 #if 0
964 /* Exits the preview dialog with GTK_RESPONSE_CANCEL if Esc key
965  * was pressed 
966  * FIXME This should be handled automatically */
967 static gboolean
968 hildon_font_selection_dialog_preview_key_press  (GtkWidget *widget,
969                                                  GdkEventKey *event,
970                                                  gpointer unused)
971 {
972     g_assert (widget);
973     g_assert (event);
974
975     if (event->keyval == GDK_Escape)
976     {
977         gtk_dialog_response (GTK_DIALOG (widget), GTK_RESPONSE_CANCEL);
978         return TRUE;
979     }
980
981     return FALSE;
982 }
983
984 static void
985 add_preview_text_attr                           (PangoAttrList *list, 
986                                                  PangoAttribute *attr, 
987                                                  guint start, 
988                                                  guint len)
989 {
990     attr->start_index = start;
991     attr->end_index = start + len;
992     pango_attr_list_insert (list, attr);
993 }
994
995 static PangoAttrList*
996 hildon_font_selection_dialog_create_attrlist    (HildonFontSelectionDialog *fontsel, 
997                                                  guint start_index, 
998                                                  guint len)
999 {
1000     PangoAttrList *list;
1001     PangoAttribute *attr;
1002     gint size, position;
1003     gboolean family_set, size_set, color_set, bold, bold_set,
1004              italic, italic_set, underline, underline_set,
1005              strikethrough, strikethrough_set, position_set;
1006     GdkColor *color = NULL;
1007     gchar *family = NULL;
1008     gdouble font_scaling = 1.0;
1009
1010     list = pango_attr_list_new ();
1011
1012     g_object_get (G_OBJECT (fontsel),
1013             "family", &family, "family-set", &family_set,
1014             "size", &size, "size-set", &size_set,
1015             "color", &color, "color-set", &color_set,
1016             "bold", &bold, "bold-set", &bold_set,
1017             "italic", &italic, "italic-set", &italic_set,
1018             "underline", &underline, "underline-set", &underline_set,
1019             "strikethrough", &strikethrough, "strikethrough-set", 
1020             &strikethrough_set, "position", &position, 
1021             "position-set", &position_set, 
1022             "font-scaling", &font_scaling,
1023             NULL);
1024
1025     /* family */
1026     if (family_set)
1027     {
1028         attr = pango_attr_family_new (family);
1029         add_preview_text_attr (list, attr, start_index, len);
1030     }
1031     g_free (family);
1032
1033     /* size */
1034     if (size_set)
1035     {
1036         attr = pango_attr_size_new (size * PANGO_SCALE);
1037         add_preview_text_attr (list, attr, start_index, len);
1038     }
1039
1040     /*color*/
1041     if (color_set)
1042     {
1043         attr = pango_attr_foreground_new (color->red, color->green, color->blue);
1044         add_preview_text_attr (list, attr, start_index, len);
1045     }
1046
1047     if (color != NULL)
1048         gdk_color_free (color);
1049
1050     /*weight*/
1051     if (bold_set)
1052     {
1053         if (bold)
1054             attr = pango_attr_weight_new (PANGO_WEIGHT_BOLD);
1055         else
1056             attr = pango_attr_weight_new (PANGO_WEIGHT_NORMAL);
1057
1058         add_preview_text_attr(list, attr, start_index, len);
1059     }
1060
1061     /* style */
1062     if (italic_set)
1063     {
1064         if (italic)
1065             attr = pango_attr_style_new (PANGO_STYLE_ITALIC);
1066         else
1067             attr = pango_attr_style_new (PANGO_STYLE_NORMAL);
1068
1069         add_preview_text_attr(list, attr, start_index, len);
1070     }
1071
1072     /* underline */
1073     if (underline_set)
1074     {
1075         if (underline)
1076             attr = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE);
1077         else
1078             attr = pango_attr_underline_new (PANGO_UNDERLINE_NONE);
1079
1080         add_preview_text_attr(list, attr, start_index, len);
1081     }
1082
1083     /* strikethrough */
1084     if (strikethrough_set)
1085     {
1086         if (strikethrough)
1087             attr = pango_attr_strikethrough_new (TRUE);
1088         else
1089             attr = pango_attr_strikethrough_new (FALSE);
1090
1091         add_preview_text_attr(list, attr, start_index, len);
1092     }
1093
1094     /* position */
1095     if (position_set)
1096     {
1097         switch (position)
1098         {
1099             case 1: /*super*/
1100                 attr = pango_attr_rise_new (SUPERSCRIPT_RISE);
1101                 break;
1102             case -1: /*sub*/
1103                 attr = pango_attr_rise_new (SUBSCRIPT_LOW);
1104                 break;
1105             default: /*normal*/
1106                 attr = pango_attr_rise_new (0);
1107                 break;
1108         }
1109
1110         add_preview_text_attr (list, attr, start_index, len);
1111     }
1112
1113     /* font scaling for preview */
1114     if (font_scaling)
1115     {
1116         attr = pango_attr_scale_new(font_scaling);
1117         add_preview_text_attr(list, attr, 0, len + start_index);
1118     }
1119
1120     return list;
1121 }
1122
1123 static void
1124 hildon_font_selection_dialog_show_preview       (HildonFontSelectionDialog *fontsel)
1125 {
1126     HildonFontSelectionDialogPrivate *priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fontsel);
1127     gint size;
1128     gboolean family_set, size_set;
1129     PangoAttribute *attr;
1130     PangoAttrList *list;
1131     GtkWidget *preview_dialog;
1132     GtkWidget *preview_label;
1133     gchar *str = NULL;
1134     gboolean position_set = FALSE;
1135     gint position = 0;
1136     gboolean show_ref = FALSE;
1137
1138     g_assert (priv);
1139
1140     g_object_get (G_OBJECT (fontsel), "position-set", &position_set, NULL);
1141
1142     if (position_set) {
1143         g_object_get (G_OBJECT (fontsel), "position", &position, NULL);
1144         if (position == 1 || position == -1)
1145             show_ref = TRUE;
1146     }
1147
1148     /* preview dialog init */
1149     preview_dialog =
1150         gtk_dialog_new_with_buttons (_("ecdg_ti_preview_font"), NULL,
1151                 GTK_DIALOG_MODAL |
1152                 GTK_DIALOG_DESTROY_WITH_PARENT |
1153                 GTK_DIALOG_NO_SEPARATOR,
1154                 _("wdgt_bd_done"),
1155                 GTK_RESPONSE_ACCEPT,
1156                 NULL);
1157
1158     str = (show_ref) ? g_strconcat (_("ecdg_fi_preview_font_preview_reference"), priv->preview_text, 0) :
1159         g_strdup (priv->preview_text);
1160
1161     preview_label = gtk_label_new (str);
1162     gtk_label_set_line_wrap (GTK_LABEL(preview_label), TRUE);
1163
1164     if (str) 
1165         g_free (str);
1166
1167     str = NULL;
1168
1169     /* set keypress handler (ESC hardkey) */
1170     g_signal_connect (G_OBJECT (preview_dialog), "key-press-event",
1171             G_CALLBACK(hildon_font_selection_dialog_preview_key_press),
1172             NULL);
1173
1174     /* Set the font */
1175     list = (show_ref) ? hildon_font_selection_dialog_create_attrlist (fontsel, 
1176             strlen (_("ecdg_fi_preview_font_preview_reference")),
1177             strlen (priv->preview_text)) :
1178         hildon_font_selection_dialog_create_attrlist (fontsel, 0, strlen(priv->preview_text));
1179
1180     g_object_get (G_OBJECT (fontsel), "family", &str, "family-set",
1181             &family_set, "size", &size, "size-set", &size_set,
1182             NULL);
1183
1184     /* A smallish hack to add scrollbar when font size is really big */
1185
1186     if (size_set && size > 24) {
1187         GtkScrolledWindow *scrolled = GTK_SCROLLED_WINDOW (gtk_scrolled_window_new (NULL, NULL));
1188         gtk_scrolled_window_set_policy (scrolled, GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
1189         gtk_scrolled_window_add_with_viewport (scrolled, GTK_WIDGET (preview_label));
1190         gtk_container_add (GTK_CONTAINER (GTK_DIALOG(preview_dialog)->vbox), GTK_WIDGET (scrolled));
1191         gtk_widget_set_size_request (GTK_WIDGET (scrolled), -1, 400);
1192     } else 
1193         gtk_container_add (GTK_CONTAINER (GTK_DIALOG(preview_dialog)->vbox), GTK_WIDGET (preview_label));
1194
1195     /* make reference text to have the same fontface and size */
1196     if (family_set)
1197     {
1198         attr = pango_attr_family_new (str);
1199         add_preview_text_attr (list, attr, 0, strlen (_("ecdg_fi_preview_font_preview_reference")));
1200     }
1201     if (str != NULL)
1202         g_free (str);
1203
1204     str = NULL;
1205
1206     /* size */
1207     if (size_set)
1208     {
1209         attr = pango_attr_size_new (size * PANGO_SCALE);
1210         add_preview_text_attr (list, attr, 0, strlen (_("ecdg_fi_preview_font_preview_reference")));
1211     }
1212
1213     gtk_label_set_attributes (GTK_LABEL (preview_label), list);
1214     pango_attr_list_unref (list);
1215
1216     /*And show the dialog*/
1217     gtk_window_set_transient_for (GTK_WINDOW (preview_dialog), 
1218             GTK_WINDOW (fontsel));
1219
1220     gtk_widget_show_all (preview_dialog);
1221     gtk_dialog_set_default_response (GTK_DIALOG (preview_dialog), GTK_RESPONSE_OK);
1222     
1223     GtkBox *action_area = (GtkBox *) GTK_DIALOG (preview_dialog)->action_area;
1224     GtkWidget *button = ((GtkBoxChild *) ((GSList *) action_area->children)->data)->widget;
1225     gtk_widget_grab_focus (button);
1226
1227     gtk_dialog_run (GTK_DIALOG (preview_dialog));
1228     gtk_widget_destroy (preview_dialog);
1229 }
1230 #endif
1231
1232 static gboolean 
1233 is_internal_font                                (const gchar * name)
1234 {
1235     /* FIXME Extremally BAD BAD BAD way of doing things */
1236
1237     return strcmp(name, "DeviceSymbols") == 0
1238         || strcmp(name, "Nokia Smiley" ) == 0
1239         || strcmp(name, "NewCourier" ) == 0
1240         || strcmp(name, "NewTimes" ) == 0
1241         || strcmp(name, "SwissA" ) == 0
1242         || strcmp(name, "Nokia Sans"   ) == 0
1243         || strcmp(name, "Nokia Sans Cn") == 0;
1244 }
1245
1246 static void 
1247 filter_out_internal_fonts                       (PangoFontFamily **families, 
1248                                                  int *n_families)
1249 {
1250     int i;
1251     int n; /* counts valid fonts */
1252     const gchar * name = NULL;
1253
1254     for(i = 0, n = 0; i < * n_families; i++){
1255
1256         name = pango_font_family_get_name (families[i]);
1257
1258         if(!is_internal_font(name))
1259         {
1260
1261             if (i!=n){ /* there are filtered out families */
1262                 families[n] = families[i]; /* shift the current family */
1263             }
1264
1265             n++; /* count one more valid */
1266         }
1267     } /* foreach font family */
1268
1269     *n_families = n;  
1270 }
1271
1272 static void
1273 hildon_font_selection_dialog_show_available_fonts (HildonFontSelectionDialog *fontsel)
1274
1275 {
1276     gint i;
1277
1278     HildonFontSelectionDialogPrivate *priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fontsel);
1279     g_assert (priv);
1280
1281     pango_context_list_families (gtk_widget_get_pango_context
1282             (GTK_WIDGET (fontsel)), &priv->families,
1283             &priv->n_families);
1284
1285     filter_out_internal_fonts (priv->families, &priv->n_families);
1286
1287     qsort (priv->families, priv->n_families, sizeof(PangoFontFamily *), cmp_families);
1288
1289     for (i = 0; i < priv->n_families; i++) 
1290     {
1291         const gchar *name = pango_font_family_get_name (priv->families[i]);
1292         gtk_combo_box_append_text (GTK_COMBO_BOX (priv->cbx_font_type), name);
1293     }
1294 }
1295
1296 static void
1297 hildon_font_selection_dialog_show_available_positionings (HildonFontSelectionDialogPrivate *priv)
1298 {
1299     gtk_combo_box_append_text (GTK_COMBO_BOX (priv->cbx_positioning), _("ecdg_va_font_printpos_1"));
1300     gtk_combo_box_append_text (GTK_COMBO_BOX (priv->cbx_positioning), _("ecdg_va_font_printpos_2"));
1301     gtk_combo_box_append_text (GTK_COMBO_BOX (priv->cbx_positioning), _("ecdg_va_font_printpos_3"));
1302 }
1303
1304 /* Loads the sizes from a pre-allocated table */
1305 static void
1306 hildon_font_selection_dialog_show_available_sizes (HildonFontSelectionDialogPrivate *priv)
1307 {
1308     gchar *size_str;
1309     gint i;
1310
1311     g_assert (priv);
1312
1313     for (i = 0; i < G_N_ELEMENTS (font_sizes); i++) 
1314     {
1315         size_str = g_strdup_printf ("%i%s",
1316                 font_sizes[i],
1317                 _("ecdg_va_font_size_trailer"));
1318
1319         gtk_combo_box_append_text (GTK_COMBO_BOX (priv->cbx_font_size), size_str);
1320         g_free (size_str);
1321     }
1322 }
1323
1324 static void
1325 toggle_clicked                                  (GtkButton *button, 
1326                                                  gpointer unused)
1327 {
1328     GtkToggleButton *t_b = GTK_TOGGLE_BUTTON (button);
1329
1330     /* we have to remove the inconsistent state ourselves */
1331     if (gtk_toggle_button_get_inconsistent (t_b))
1332     {
1333         gtk_toggle_button_set_inconsistent (t_b, FALSE);
1334         gtk_toggle_button_set_active (t_b, FALSE);
1335     }
1336 }
1337
1338 /**
1339  * hildon_font_selection_dialog_new:
1340  * @parent: the parent window
1341  * @title: the title of font selection dialog
1342  *
1343  * If NULL is passed for title, then default title
1344  * "Font" will be used.
1345  *
1346  * Returns: a new #HildonFontSelectionDialog
1347  */
1348 GtkWidget*
1349 hildon_font_selection_dialog_new                (GtkWindow *parent,
1350                                                  const gchar *title)
1351 {
1352     HildonFontSelectionDialog *fontseldiag;
1353
1354     fontseldiag = g_object_new (HILDON_TYPE_FONT_SELECTION_DIALOG,
1355             "has-separator", FALSE, NULL);
1356
1357     if (title)
1358         gtk_window_set_title (GTK_WINDOW (fontseldiag), title);
1359
1360     if (parent)
1361         gtk_window_set_transient_for (GTK_WINDOW (fontseldiag), parent);
1362
1363     return GTK_WIDGET (fontseldiag);
1364 }
1365
1366 /**
1367  * hildon_font_selection_dialog_get_preview_text:
1368  * @fsd: the font selection dialog
1369  *
1370  * Gets the text in preview dialog, which does not include the
1371  * reference text. The returned string must be freed by the user.
1372  * Please note that since hildon 2.2, the preview has been discontinued,
1373  * so this setting has no effect.
1374  *
1375  * Returns: a string pointer
1376  */
1377 gchar*
1378 hildon_font_selection_dialog_get_preview_text   (HildonFontSelectionDialog * fsd)
1379 {
1380     /* FIXME Return a const pointer? */
1381     HildonFontSelectionDialogPrivate *priv;
1382
1383     g_return_val_if_fail (HILDON_IS_FONT_SELECTION_DIALOG (fsd), NULL);
1384         
1385     priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fsd);
1386     g_assert (priv);
1387
1388     return g_strdup (priv->preview_text);
1389 }
1390
1391 /**
1392  * hildon_font_selection_dialog_set_preview_text:
1393  * @fsd: the font selection dialog
1394  * @text: the text to be displayed in the preview dialog
1395  *
1396  * The default preview text is
1397  * "The quick brown fox jumped over the lazy dogs". Please note that since
1398  * hildon 2.2, the preview has been discontinued, so this setting has no effect.
1399  *
1400  */
1401 void
1402 hildon_font_selection_dialog_set_preview_text   (HildonFontSelectionDialog *fsd, 
1403                                                  const gchar * text)
1404 {
1405     HildonFontSelectionDialogPrivate *priv = NULL;
1406
1407     g_return_if_fail (HILDON_IS_FONT_SELECTION_DIALOG (fsd));
1408     g_return_if_fail (text);
1409
1410     priv = HILDON_FONT_SELECTION_DIALOG_GET_PRIVATE (fsd);
1411     g_assert (priv);
1412
1413     g_free (priv->preview_text);
1414     priv->preview_text = g_strdup (text);
1415     g_object_notify (G_OBJECT (fsd), "preview-text");
1416 }
1417